From 01b5b3dc1aba39aef0065e2172d5af2ee6ab4e47 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Thu, 20 Jan 2022 17:14:11 +0100 Subject: [PATCH] fix(core): update --- ts/smartsocket.classes.smartsocketclient.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ts/smartsocket.classes.smartsocketclient.ts b/ts/smartsocket.classes.smartsocketclient.ts index d698be2..cb3fe1d 100644 --- a/ts/smartsocket.classes.smartsocketclient.ts +++ b/ts/smartsocket.classes.smartsocketclient.ts @@ -184,28 +184,37 @@ export class SmartsocketClient { return done.promise; } + private disconnectRunning = false; + /** * disconnect from the server */ public async disconnect(useAutoconnectSetting = false) { - if (this.eventStatus === 'disconnecting') { + if (this.disconnectRunning) { return; } + this.disconnectRunning = true; this.updateStatus('disconnecting'); this.tagStoreSubscription?.unsubscribe(); if (this.socketConnection) { await this.socketConnection.disconnect(); this.socketConnection = undefined; 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}`); this.remoteShortId = null; if (this.autoReconnect && useAutoconnectSetting && this.eventStatus !== 'connecting') { this.updateStatus('connecting'); - this.tryDebouncedReconnect(); - } else if (this.eventStatus === 'connected') { - this.updateStatus('disconnected'); + await this.tryDebouncedReconnect(); + this.disconnectRunning = false; + } else { + this.disconnectRunning = false; } }