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(); }