Compare commits

..

5 Commits

Author SHA1 Message Date
736240b978 1.0.93 2019-11-09 12:23:34 +01:00
73f4600c2a fix(core): update 2019-11-09 12:23:33 +01:00
40beec1166 1.0.92 2019-11-07 01:02:03 +01:00
f8690fef50 1.0.91 2019-11-07 00:59:46 +01:00
972ddbf327 fix(core): update 2019-11-07 00:59:45 +01:00
5 changed files with 59 additions and 44 deletions

51
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.90",
"version": "1.0.93",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -353,9 +353,9 @@
}
},
"@pushrocks/smartsocket": {
"version": "1.1.51",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.51.tgz",
"integrity": "sha512-oZXFOJsk9XJ9ZBxlcglpsIwuYGDuS9a/BLC2amOJ8bP0g+dWzTlOvlvSu9eiSaw/+gVc0i7jGQZPPDcZNqY8Iw==",
"version": "1.1.58",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.58.tgz",
"integrity": "sha512-ncwkZo5wsDgD4ps8euNN+krGfh1hHDibmiL1NeGxFb0a06NnMEhCj5f4pHizo64Z7BudQ6wjqGVizPfy779jtg==",
"requires": {
"@apiglobal/typedrequest-interfaces": "^1.0.7",
"@pushrocks/lik": "^3.0.11",
@ -364,27 +364,12 @@
"@pushrocks/smarthash": "^2.0.6",
"@pushrocks/smartlog": "^2.0.21",
"@pushrocks/smartpromise": "^3.0.6",
"@types/shortid": "0.0.29",
"@pushrocks/smartrx": "^2.0.5",
"@pushrocks/smartunique": "^3.0.1",
"@types/socket.io": "^2.1.4",
"@types/socket.io-client": "^1.4.32",
"shortid": "^2.2.15",
"socket.io": "^2.3.0",
"socket.io-client": "^2.3.0"
},
"dependencies": {
"nanoid": {
"version": "2.1.6",
"resolved": "https://verdaccio.lossless.one/nanoid/-/nanoid-2.1.6.tgz",
"integrity": "sha512-2NDzpiuEy3+H0AVtdt8LoFi7PnqkOnIzYmJQp7xsEU6VexLluHQwKREuiz57XaQC5006seIadPrIZJhyS2n7aw=="
},
"shortid": {
"version": "2.2.15",
"resolved": "https://verdaccio.lossless.one/shortid/-/shortid-2.2.15.tgz",
"integrity": "sha512-5EaCy2mx2Jgc/Fdn9uuDuNIIfWBpzY4XIlhoqtXF6qsf+/+SGZ+FxDdX/ZsMZiWupIWNqAEmiNY4RC+LSmCeOw==",
"requires": {
"nanoid": "^2.1.0"
}
}
}
},
"@pushrocks/smarttime": {
@ -553,9 +538,9 @@
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
},
"@types/node": {
"version": "12.12.5",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.5.tgz",
"integrity": "sha512-KEjODidV4XYUlJBF3XdjSH5FWoMCtO0utnhtdLf1AgeuZLOrRbvmU/gaRCVg7ZaQDjVf3l84egiY0mRNe5xE4A=="
"version": "12.12.6",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.6.tgz",
"integrity": "sha512-FjsYUPzEJdGXjwKqSpE0/9QEh6kzhTAeObA54rn6j3rR4C/mzpI9L0KNfoeASSPMMdxIsoJuCLDWcM/rVjIsSA=="
},
"@types/range-parser": {
"version": "1.2.3",
@ -972,9 +957,9 @@
}
},
"commander": {
"version": "2.20.0",
"resolved": "https://verdaccio.lossless.one/commander/-/commander-2.20.0.tgz",
"integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==",
"version": "2.20.3",
"resolved": "https://verdaccio.lossless.one/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true
},
"component-bind": {
@ -1475,9 +1460,9 @@
}
},
"glob": {
"version": "7.1.3",
"resolved": "https://verdaccio.lossless.one/glob/-/glob-7.1.3.tgz",
"integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==",
"version": "7.1.6",
"resolved": "https://verdaccio.lossless.one/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
@ -2754,9 +2739,9 @@
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
},
"tslint": {
"version": "5.20.0",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.0.tgz",
"integrity": "sha512-2vqIvkMHbnx8acMogAERQ/IuINOq6DFqgF8/VDvhEkBqQh/x6SP0Y+OHnKth9/ZcHQSroOZwUQSN18v8KKF0/g==",
"version": "5.20.1",
"resolved": "https://verdaccio.lossless.one/tslint/-/tslint-5.20.1.tgz",
"integrity": "sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.0.0",

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartuniverse",
"version": "1.0.90",
"version": "1.0.93",
"private": false,
"description": "messaging service for your micro services",
"main": "dist/index.js",
@ -17,8 +17,8 @@
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.12.5",
"tslint": "^5.20.0",
"@types/node": "^12.12.6",
"tslint": "^5.20.1",
"tslint-config-prettier": "^1.18.0"
},
"peerDependencies": {
@ -35,7 +35,7 @@
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.42",
"@pushrocks/smartrx": "^2.0.5",
"@pushrocks/smartsocket": "^1.1.51",
"@pushrocks/smartsocket": "^1.1.58",
"@pushrocks/smarttime": "^3.0.12",
"@pushrocks/smartunique": "^3.0.1"
},

View File

@ -19,7 +19,7 @@ export interface IClientOptions {
* allows connecting to a universe server
*/
export class ClientUniverse {
public options;
public options: IClientOptions;
public smartsocketClient: plugins.smartsocket.SmartsocketClient;
public messageRxjsSubject = new plugins.smartrx.rxjs.Subject<ClientUniverseMessage<any>>();
public clientUniverseCache = new ClientUniverseCache();
@ -77,8 +77,7 @@ export class ClientUniverse {
}
public async stop() {
await this.smartsocketClient.disconnect();
this.smartsocketClient = null;
await this.disconnect('triggered');
}
/**
@ -97,6 +96,13 @@ export class ClientUniverse {
};
this.smartsocketClient = new SmartsocketClient(socketConfig);
this.smartsocketClient.eventSubject.subscribe(async eventArg => {
switch(eventArg) {
case 'disconnected':
this.disconnect('upstreamEvent');
}
});
// lets define some basic actions
/**
@ -157,4 +163,15 @@ export class ClientUniverse {
});
}
}
public async disconnect(reason: 'upstreamEvent' | 'triggered' = 'triggered', tryReconnect = false) {
if ('triggered') {
this.smartsocketClient.disconnect();
}
this.smartsocketClient = null;
if (tryReconnect) {
await plugins.smartdelay.delayForRandom(5000, 20000);
this.checkConnection();
}
}
}

View File

@ -112,6 +112,7 @@ export class Universe {
funcName: 'subscribeChannel',
funcDef: async (dataArg, socketConnectionArg) => {
const universeConnection = new UniverseConnection({
universe: this,
socketConnection: socketConnectionArg,
authenticationRequests: [dataArg]
});

View File

@ -93,6 +93,8 @@ export class UniverseConnection {
return universeConnection;
}
// INSTANCE
public universeRef: Universe;
public terminatedDeferred = plugins.smartpromise.defer();
/**
@ -100,23 +102,33 @@ export class UniverseConnection {
*/
public socketConnection: plugins.smartsocket.SocketConnection;
public authenticationRequests: Array<interfaces.ISocketRequest_SubscribeChannel['request']> = [];
public subscribedChannels: UniverseChannel[] = [];
public authenticatedChannels: UniverseChannel[] = [];
public failedToJoinChannels: UniverseChannel[] = [];
/**
* terminates the connection
* disconnect the connection
*/
public terminateConnection() {
this.socketConnection.socket.disconnect();
public async disconnect(reason: 'upstreamevent' | 'triggered' = 'triggered') {
if (reason === 'triggered') {
await this.socketConnection.disconnect();
}
this.universeRef.universeCache.connectionMap.remove(this);
this.terminatedDeferred.resolve();
}
constructor(optionsArg: {
universe: Universe;
socketConnection: plugins.smartsocket.SocketConnection;
authenticationRequests: Array<interfaces.ISocketRequest_SubscribeChannel['request']>;
}) {
this.authenticationRequests = optionsArg.authenticationRequests;
this.socketConnection = optionsArg.socketConnection;
this.socketConnection.eventSubject.subscribe(async eventArg => {
switch (eventArg) {
case 'disconnected':
await this.disconnect('upstreamevent');
break;
}
});
}
}