fix(core): update
This commit is contained in:
parent
29c0c8dc23
commit
043d795013
@ -84,12 +84,6 @@ export class ClientUniverse {
|
|||||||
...messageArg
|
...messageArg
|
||||||
};
|
};
|
||||||
// TODO: User websocket connection if available
|
// TODO: User websocket connection if available
|
||||||
const response = await plugins.smartrequest.postJson(
|
|
||||||
`${this.options.serverAddress}/sendmessage`,
|
|
||||||
{
|
|
||||||
requestBody
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public close() {
|
public close() {
|
||||||
|
@ -2,6 +2,8 @@ import * as plugins from './smartuniverse.plugins';
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* a cache for clients
|
* a cache for clients
|
||||||
|
* keeps track of which messages have already been received
|
||||||
|
* good for deduplication in mesh environments
|
||||||
*/
|
*/
|
||||||
export class ClientUniverseCache {
|
export class ClientUniverseCache {
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import { UniverseCache, UniverseChannel, UniverseMessage } from './';
|
|||||||
import * as paths from './smartuniverse.paths';
|
import * as paths from './smartuniverse.paths';
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
import { UniverseConnectionManager } from './smartuniverse.classes.universeconnectionmanager';
|
||||||
|
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||||
|
|
||||||
export interface ISmartUniverseConstructorOptions {
|
export interface ISmartUniverseConstructorOptions {
|
||||||
messageExpiryInMilliseconds: number;
|
messageExpiryInMilliseconds: number;
|
||||||
@ -17,29 +19,11 @@ export interface ISmartUniverseConstructorOptions {
|
|||||||
export class Universe {
|
export class Universe {
|
||||||
// subinstances
|
// subinstances
|
||||||
public universeCache: UniverseCache;
|
public universeCache: UniverseCache;
|
||||||
|
public universeConnectionManager: UniverseConnectionManager;
|
||||||
|
|
||||||
// options
|
// options
|
||||||
private options: ISmartUniverseConstructorOptions;
|
private options: ISmartUniverseConstructorOptions;
|
||||||
|
|
||||||
/**
|
|
||||||
* stores the version of the universe server running
|
|
||||||
* this is done since the version is exposed through the api and multiple fs actions are avoided this way.
|
|
||||||
*/
|
|
||||||
private universeVersionStore: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get the currently running version of smartuniverse
|
|
||||||
*/
|
|
||||||
public get universeVersion() {
|
|
||||||
if (this.universeVersionStore) {
|
|
||||||
return this.universeVersionStore;
|
|
||||||
} else {
|
|
||||||
const packageJson = plugins.smartfile.fs.toObjectSync(paths.packageJson);
|
|
||||||
this.universeVersionStore = packageJson.version;
|
|
||||||
return this.universeVersionStore;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the smartexpress server used
|
* the smartexpress server used
|
||||||
*/
|
*/
|
||||||
@ -53,6 +37,26 @@ export class Universe {
|
|||||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
this.universeCache = new UniverseCache(this.options.messageExpiryInMilliseconds);
|
this.universeCache = new UniverseCache(this.options.messageExpiryInMilliseconds);
|
||||||
|
this.universeConnectionManager = new UniverseConnectionManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stores the version of the universe server running
|
||||||
|
* this is done since the version is exposed through the api and multiple fs actions are avoided this way.
|
||||||
|
*/
|
||||||
|
private universeVersionStore: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the currently running version of smartuniverse
|
||||||
|
*/
|
||||||
|
public getUniverseVersion() {
|
||||||
|
if (this.universeVersionStore) {
|
||||||
|
return this.universeVersionStore;
|
||||||
|
} else {
|
||||||
|
const packageJson = plugins.smartfile.fs.toObjectSync(paths.packageJson);
|
||||||
|
this.universeVersionStore = packageJson.version;
|
||||||
|
return this.universeVersionStore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,18 +80,6 @@ export class Universe {
|
|||||||
port: portArg
|
port: portArg
|
||||||
});
|
});
|
||||||
|
|
||||||
// lets create the http request route
|
|
||||||
this.smartexpressServer.addRoute(
|
|
||||||
'/sendmessage',
|
|
||||||
new Handler('POST', async (req, res) => {
|
|
||||||
const universeMessageInstance: UniverseMessage = new UniverseMessage(req.body);
|
|
||||||
this.universeCache.addMessage(universeMessageInstance);
|
|
||||||
|
|
||||||
res.status(200);
|
|
||||||
res.end();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
// add websocket upgrade
|
// add websocket upgrade
|
||||||
this.smartsocket = new plugins.smartsocket.Smartsocket({});
|
this.smartsocket = new plugins.smartsocket.Smartsocket({});
|
||||||
|
|
||||||
@ -103,8 +95,11 @@ export class Universe {
|
|||||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||||
allowedRoles: [ClientRole],
|
allowedRoles: [ClientRole],
|
||||||
funcName: 'channelSubscription',
|
funcName: 'channelSubscription',
|
||||||
funcDef: () => {
|
funcDef: (data) => {
|
||||||
} // TODO: implement an action upon connection of clients
|
(() => {
|
||||||
|
this.universeConnectionManager
|
||||||
|
})()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// add smartsocket to the running smartexpress app
|
// add smartsocket to the running smartexpress app
|
||||||
|
@ -4,7 +4,7 @@ import { UniverseChannel } from './smartuniverse.classes.universechannel';
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* represents a subscription into a specific topic
|
* represents a connection to the universe
|
||||||
*/
|
*/
|
||||||
export class UniverseConnection {
|
export class UniverseConnection {
|
||||||
/**
|
/**
|
8
ts/smartuniverse.classes.universeconnectionmanager.ts
Normal file
8
ts/smartuniverse.classes.universeconnectionmanager.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* manages connections to a universe
|
||||||
|
*/
|
||||||
|
export class UniverseConnectionManager {
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user