From bb0a1d364c585524acb0390fe6ec377ca9032866 Mon Sep 17 00:00:00 2001 From: holzgeist Date: Wed, 24 Jan 2024 17:38:24 +0100 Subject: [PATCH] Fix state handling issue in SignalClient (#1004) * Fix state handling issue in SignalClient * Create tall-files-shop.md --------- Co-authored-by: lukasIO --- .changeset/tall-files-shop.md | 5 +++++ src/api/SignalClient.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changeset/tall-files-shop.md diff --git a/.changeset/tall-files-shop.md b/.changeset/tall-files-shop.md new file mode 100644 index 0000000000..9e35d107f4 --- /dev/null +++ b/.changeset/tall-files-shop.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Fix state handling issue in SignalClient diff --git a/src/api/SignalClient.ts b/src/api/SignalClient.ts index 045b9affb6..3c6bc9a315 100644 --- a/src/api/SignalClient.ts +++ b/src/api/SignalClient.ts @@ -272,7 +272,7 @@ export class SignalClient { abortSignal?.addEventListener('abort', abortHandler); this.log.debug(`connecting to ${url + params}`, this.logContext); if (this.ws) { - await this.close(); + await this.close(false); } this.ws = new WebSocket(url + params); this.ws.binaryType = 'arraybuffer'; @@ -421,10 +421,12 @@ export class SignalClient { this.onClose = undefined; }; - async close() { + async close(updateState: boolean = true) { const unlock = await this.closingLock.lock(); try { - this.state = SignalConnectionState.DISCONNECTING; + if (updateState) { + this.state = SignalConnectionState.DISCONNECTING; + } if (this.ws) { this.ws.onmessage = null; this.ws.onopen = null; @@ -449,7 +451,9 @@ export class SignalClient { this.ws = undefined; } } finally { - this.state = SignalConnectionState.DISCONNECTED; + if (updateState) { + this.state = SignalConnectionState.DISCONNECTED; + } this.clearPingInterval(); unlock(); }