fix(core): update

This commit is contained in:
Philipp Kunz 2022-01-20 17:14:11 +01:00
parent b34d7faec2
commit 01b5b3dc1a

View File

@ -184,28 +184,37 @@ export class SmartsocketClient {
return done.promise; return done.promise;
} }
private disconnectRunning = false;
/** /**
* disconnect from the server * disconnect from the server
*/ */
public async disconnect(useAutoconnectSetting = false) { public async disconnect(useAutoconnectSetting = false) {
if (this.eventStatus === 'disconnecting') { if (this.disconnectRunning) {
return; return;
} }
this.disconnectRunning = true;
this.updateStatus('disconnecting'); this.updateStatus('disconnecting');
this.tagStoreSubscription?.unsubscribe(); this.tagStoreSubscription?.unsubscribe();
if (this.socketConnection) { if (this.socketConnection) {
await this.socketConnection.disconnect(); await this.socketConnection.disconnect();
this.socketConnection = undefined; this.socketConnection = undefined;
logger.log('ok', 'disconnected socket!'); logger.log('ok', 'disconnected socket!');
} else {
this.disconnectRunning = false;
logger.log('warn', 'tried to disconnect, without a SocketConnection');
return;
} }
logger.log('warn', `disconnected from server ${this.remoteShortId}`); logger.log('warn', `disconnected from server ${this.remoteShortId}`);
this.remoteShortId = null; this.remoteShortId = null;
if (this.autoReconnect && useAutoconnectSetting && this.eventStatus !== 'connecting') { if (this.autoReconnect && useAutoconnectSetting && this.eventStatus !== 'connecting') {
this.updateStatus('connecting'); this.updateStatus('connecting');
this.tryDebouncedReconnect(); await this.tryDebouncedReconnect();
} else if (this.eventStatus === 'connected') { this.disconnectRunning = false;
this.updateStatus('disconnected'); } else {
this.disconnectRunning = false;
} }
} }