Skip to content

Commit

Permalink
Fix state handling issue in SignalClient (#1004)
Browse files Browse the repository at this point in the history
* Fix state handling issue in SignalClient

* Create tall-files-shop.md

---------

Co-authored-by: lukasIO <[email protected]>
  • Loading branch information
holzgeist and lukasIO authored Jan 24, 2024
1 parent 24a8d6e commit bb0a1d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-files-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Fix state handling issue in SignalClient
12 changes: 8 additions & 4 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -449,7 +451,9 @@ export class SignalClient {
this.ws = undefined;
}
} finally {
this.state = SignalConnectionState.DISCONNECTED;
if (updateState) {
this.state = SignalConnectionState.DISCONNECTED;
}
this.clearPingInterval();
unlock();
}
Expand Down

0 comments on commit bb0a1d3

Please sign in to comment.