fix(core): update

This commit is contained in:
Philipp Kunz 2019-11-09 12:23:33 +01:00
parent 40beec1166
commit 73f4600c2a
4 changed files with 39 additions and 16 deletions

12
package-lock.json generated
View File

@ -353,9 +353,9 @@
} }
}, },
"@pushrocks/smartsocket": { "@pushrocks/smartsocket": {
"version": "1.1.54", "version": "1.1.58",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.54.tgz", "resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartsocket/-/smartsocket-1.1.58.tgz",
"integrity": "sha512-3AFSNAamPWAmyyLdwN0errc7y0yZcREil69MtKoUbzJZWVMBWW03daiupc3BgMZDqqD82SqSlyStSh62OBUPnw==", "integrity": "sha512-ncwkZo5wsDgD4ps8euNN+krGfh1hHDibmiL1NeGxFb0a06NnMEhCj5f4pHizo64Z7BudQ6wjqGVizPfy779jtg==",
"requires": { "requires": {
"@apiglobal/typedrequest-interfaces": "^1.0.7", "@apiglobal/typedrequest-interfaces": "^1.0.7",
"@pushrocks/lik": "^3.0.11", "@pushrocks/lik": "^3.0.11",
@ -1234,7 +1234,7 @@
}, },
"esutils": { "esutils": {
"version": "2.0.3", "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==", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
"dev": true "dev": true
}, },
@ -1941,7 +1941,7 @@
}, },
"minimist": { "minimist": {
"version": "0.0.8", "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=", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true "dev": true
}, },
@ -2341,7 +2341,7 @@
}, },
"resolve": { "resolve": {
"version": "1.12.0", "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==", "integrity": "sha512-B/dOmuoAik5bKcD6s6nXDCjzUKnaDvdkRyAk6rsmsKLipWj4797iothd7jmmUhWTfinVMU+wc56rYKsit2Qy4w==",
"dev": true, "dev": true,
"requires": { "requires": {

View File

@ -35,7 +35,7 @@
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartrequest": "^1.1.42", "@pushrocks/smartrequest": "^1.1.42",
"@pushrocks/smartrx": "^2.0.5", "@pushrocks/smartrx": "^2.0.5",
"@pushrocks/smartsocket": "^1.1.54", "@pushrocks/smartsocket": "^1.1.58",
"@pushrocks/smarttime": "^3.0.12", "@pushrocks/smarttime": "^3.0.12",
"@pushrocks/smartunique": "^3.0.1" "@pushrocks/smartunique": "^3.0.1"
}, },

View File

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

@ -106,23 +106,29 @@ export class UniverseConnection {
public failedToJoinChannels: UniverseChannel[] = []; public failedToJoinChannels: UniverseChannel[] = [];
/** /**
* terminates the connection * disconnect the connection
*/ */
public async terminateUniverseConnection() { public async disconnect(reason: 'upstreamevent' | 'triggered' = 'triggered') {
await this.socketConnection.disconnect(); if (reason === 'triggered') {
await this.socketConnection.disconnect();
}
this.universeRef.universeCache.connectionMap.remove(this); this.universeRef.universeCache.connectionMap.remove(this);
this.terminatedDeferred.resolve(); this.terminatedDeferred.resolve();
} }
constructor(optionsArg: { constructor(optionsArg: {
universe: Universe, universe: Universe;
socketConnection: plugins.smartsocket.SocketConnection; socketConnection: plugins.smartsocket.SocketConnection;
authenticationRequests: Array<interfaces.ISocketRequest_SubscribeChannel['request']>; authenticationRequests: Array<interfaces.ISocketRequest_SubscribeChannel['request']>;
}) { }) {
this.authenticationRequests = optionsArg.authenticationRequests; this.authenticationRequests = optionsArg.authenticationRequests;
this.socketConnection = optionsArg.socketConnection; this.socketConnection = optionsArg.socketConnection;
this.socketConnection.eventSubject.subscribe(async(event) => { this.socketConnection.eventSubject.subscribe(async eventArg => {
await this.terminateUniverseConnection(); switch (eventArg) {
case 'disconnected':
await this.disconnect('upstreamevent');
break;
}
}); });
} }
} }