Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
df45287026 | |||
b5b6ca81cf | |||
dc80e3b48d | |||
043d795013 |
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.5
|
||||
ignore: {}
|
||||
patch: {}
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartuniverse",
|
||||
"version": "1.0.46",
|
||||
"version": "1.0.48",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartuniverse",
|
||||
"version": "1.0.46",
|
||||
"version": "1.0.48",
|
||||
"private": false,
|
||||
"description": "messaging service for your micro services",
|
||||
"main": "dist/index.js",
|
||||
|
@ -84,12 +84,6 @@ export class ClientUniverse {
|
||||
...messageArg
|
||||
};
|
||||
// TODO: User websocket connection if available
|
||||
const response = await plugins.smartrequest.postJson(
|
||||
`${this.options.serverAddress}/sendmessage`,
|
||||
{
|
||||
requestBody
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public close() {
|
||||
|
@ -2,6 +2,8 @@ import * as plugins from './smartuniverse.plugins';
|
||||
|
||||
/**
|
||||
* a cache for clients
|
||||
* keeps track of which messages have already been received
|
||||
* good for deduplication in mesh environments
|
||||
*/
|
||||
export class ClientUniverseCache {
|
||||
|
||||
|
@ -6,6 +6,8 @@ import { UniverseCache, UniverseChannel, UniverseMessage } from './';
|
||||
import * as paths from './smartuniverse.paths';
|
||||
|
||||
import * as interfaces from './interfaces';
|
||||
import { UniverseConnectionManager } from './smartuniverse.classes.universeconnectionmanager';
|
||||
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||
|
||||
export interface ISmartUniverseConstructorOptions {
|
||||
messageExpiryInMilliseconds: number;
|
||||
@ -17,29 +19,11 @@ export interface ISmartUniverseConstructorOptions {
|
||||
export class Universe {
|
||||
// subinstances
|
||||
public universeCache: UniverseCache;
|
||||
public universeConnectionManager: UniverseConnectionManager;
|
||||
|
||||
// options
|
||||
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
|
||||
*/
|
||||
@ -53,6 +37,26 @@ export class Universe {
|
||||
constructor(optionsArg: ISmartUniverseConstructorOptions) {
|
||||
this.options = optionsArg;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,24 +74,12 @@ export class Universe {
|
||||
this.smartexpressServer = new plugins.smartexpress.Server({
|
||||
cors: true,
|
||||
defaultAnswer: async () => {
|
||||
return `smartuniverse server ${this.universeVersion}`;
|
||||
return `smartuniverse server ${this.getUniverseVersion()}`;
|
||||
},
|
||||
forceSsl: false,
|
||||
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
|
||||
this.smartsocket = new plugins.smartsocket.Smartsocket({});
|
||||
|
||||
@ -103,8 +95,12 @@ export class Universe {
|
||||
const SubscriptionSocketFunction = new plugins.smartsocket.SocketFunction({
|
||||
allowedRoles: [ClientRole],
|
||||
funcName: 'channelSubscription',
|
||||
funcDef: () => {
|
||||
} // TODO: implement an action upon connection of clients
|
||||
funcDef: (data) => {
|
||||
(() => {
|
||||
// TODO:
|
||||
this.universeConnectionManager.addConnection();
|
||||
})();
|
||||
}
|
||||
});
|
||||
|
||||
// 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 {
|
||||
/**
|
11
ts/smartuniverse.classes.universeconnectionmanager.ts
Normal file
11
ts/smartuniverse.classes.universeconnectionmanager.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import * as plugins from './smartuniverse.plugins';
|
||||
import { UniverseConnection } from './smartuniverse.classes.universeconnection';
|
||||
|
||||
/**
|
||||
* manages connections to a universe
|
||||
*/
|
||||
export class UniverseConnectionManager {
|
||||
public connectionMap = new plugins.lik.Objectmap<UniverseConnection>();
|
||||
|
||||
public addConnection() {}
|
||||
}
|
Reference in New Issue
Block a user