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": {
"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": {

View File

@ -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"
},

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

@ -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<interfaces.ISocketRequest_SubscribeChannel['request']>;
}) {
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;
}
});
}
}