Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't disconnect room before retrying new regions #910

Merged
merged 3 commits into from
Oct 26, 2023
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/unlucky-nails-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Don't disconnect room before retrying new regions
9 changes: 6 additions & 3 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
error instanceof ConnectionError &&
(error.status === 401 || error.reason === ConnectionErrorReason.Cancelled)
) {
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
reject(error);
return;
}
Expand All @@ -462,9 +463,11 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
);
await connectFn(resolve, reject, nextUrl);
} else {
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
reject(e);
}
} else {
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
reject(e);
}
}
Expand Down Expand Up @@ -593,8 +596,8 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
this.setupLocalParticipantEvents();
this.emit(RoomEvent.SignalConnected);
} catch (err) {
await this.engine.close();
this.recreateEngine();
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
const resultingError = new ConnectionError(`could not establish signal connection`);
if (err instanceof Error) {
resultingError.message = `${resultingError.message}: ${err.message}`;
Expand All @@ -608,8 +611,8 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
}

if (abortController.signal.aborted) {
await this.engine.close();
this.recreateEngine();
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
throw new ConnectionError(`Connection attempt aborted`);
}

Expand All @@ -619,8 +622,8 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
abortController,
);
} catch (e) {
await this.engine.close();
this.recreateEngine();
this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
throw e;
}

Expand Down
Loading