From 73f4600c2a6040b9f352091a16701c20e6582d31 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sat, 9 Nov 2019 12:23:33 +0100 Subject: [PATCH] fix(core): update --- package-lock.json | 12 +++++----- package.json | 2 +- ts/smartuniverse.classes.clientuniverse.ts | 23 ++++++++++++++++--- ...martuniverse.classes.universeconnection.ts | 18 ++++++++++----- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index e183f40..81640f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -353,9 +353,9 @@ } }, "@pushrocks/smartsocket": { - "version": "1.1.54", - "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.54.tgz", - "integrity": "sha512-3AFSNAamPWAmyyLdwN0errc7y0yZcREil69MtKoUbzJZWVMBWW03daiupc3BgMZDqqD82SqSlyStSh62OBUPnw==", + "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", @@ -1234,7 +1234,7 @@ }, "esutils": { "version": "2.0.3", - "resolved": "https://verdaccio.lossless.one/esutils/-/esutils-2.0.3.tgz", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, @@ -1941,7 +1941,7 @@ }, "minimist": { "version": "0.0.8", - "resolved": "https://verdaccio.lossless.one/minimist/-/minimist-0.0.8.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", "dev": true }, @@ -2341,7 +2341,7 @@ }, "resolve": { "version": "1.12.0", - "resolved": "https://verdaccio.lossless.one/resolve/-/resolve-1.12.0.tgz", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.12.0.tgz", "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==", "dev": true, "requires": { diff --git a/package.json b/package.json index 80e9783..8b9e880 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartrequest": "^1.1.42", "@pushrocks/smartrx": "^2.0.5", - "@pushrocks/smartsocket": "^1.1.54", + "@pushrocks/smartsocket": "^1.1.58", "@pushrocks/smarttime": "^3.0.12", "@pushrocks/smartunique": "^3.0.1" }, diff --git a/ts/smartuniverse.classes.clientuniverse.ts b/ts/smartuniverse.classes.clientuniverse.ts index 921b68a..54bde21 100644 --- a/ts/smartuniverse.classes.clientuniverse.ts +++ b/ts/smartuniverse.classes.clientuniverse.ts @@ -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>(); 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(); + } + } } diff --git a/ts/smartuniverse.classes.universeconnection.ts b/ts/smartuniverse.classes.universeconnection.ts index d417eb3..f4c6784 100644 --- a/ts/smartuniverse.classes.universeconnection.ts +++ b/ts/smartuniverse.classes.universeconnection.ts @@ -106,23 +106,29 @@ export class UniverseConnection { public failedToJoinChannels: UniverseChannel[] = []; /** - * terminates the connection + * disconnect the connection */ - public async terminateUniverseConnection() { - await this.socketConnection.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, + universe: Universe; socketConnection: plugins.smartsocket.SocketConnection; authenticationRequests: Array; }) { this.authenticationRequests = optionsArg.authenticationRequests; this.socketConnection = optionsArg.socketConnection; - this.socketConnection.eventSubject.subscribe(async(event) => { - await this.terminateUniverseConnection(); + this.socketConnection.eventSubject.subscribe(async eventArg => { + switch (eventArg) { + case 'disconnected': + await this.disconnect('upstreamevent'); + break; + } }); } }