Skip to content
Merged
Changes from 2 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
16 changes: 12 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,16 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
);
}

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

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