Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-lamps-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Signal leave on failed connection attempts if signalling is connected
14 changes: 10 additions & 4 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
`Initial connection failed with ConnectionError: ${error.message}. Retrying with another region: ${nextUrl}`,
this.logContext,
);
this.recreateEngine();
this.recreateEngine(true);
await connectFn(resolve, reject, nextUrl);
} else {
this.handleDisconnect(
Expand Down Expand Up @@ -866,7 +866,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
) {
this.log.info('Reconnection attempt replaced by new connection attempt', this.logContext);
// make sure we close and recreate the existing engine in order to get rid of any potentially ongoing reconnection attempts
this.recreateEngine();
this.recreateEngine(true);
} else {
// create engine if previously disconnected
this.maybeCreateEngine();
Expand Down Expand Up @@ -1380,8 +1380,14 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
);
}

private recreateEngine() {
this.engine?.close();
private recreateEngine(sendLeave?: boolean) {
const oldEngine = this.engine;

if (sendLeave && oldEngine && !oldEngine.client.isDisconnected) {
oldEngine.client.sendLeave().finally(() => oldEngine.close());
} else {
oldEngine?.close();
}
/* @ts-ignore */
this.engine = undefined;
this.isResuming = false;
Expand Down
Loading