fix(core): update
This commit is contained in:
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user