diff --git a/.changeset/unlucky-nails-fry.md b/.changeset/unlucky-nails-fry.md new file mode 100644 index 0000000000..3bb3a68a24 --- /dev/null +++ b/.changeset/unlucky-nails-fry.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Don't disconnect room before retrying new regions diff --git a/src/room/Room.ts b/src/room/Room.ts index b4688e51cf..c0ec4429b0 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -452,6 +452,7 @@ class Room extends (EventEmitter as new () => TypedEmitter) error instanceof ConnectionError && (error.status === 401 || error.reason === ConnectionErrorReason.Cancelled) ) { + this.handleDisconnect(this.options.stopLocalTrackOnUnpublish); reject(error); return; } @@ -462,9 +463,11 @@ class Room extends (EventEmitter as new () => TypedEmitter) ); await connectFn(resolve, reject, nextUrl); } else { + this.handleDisconnect(this.options.stopLocalTrackOnUnpublish); reject(e); } } else { + this.handleDisconnect(this.options.stopLocalTrackOnUnpublish); reject(e); } } @@ -593,8 +596,8 @@ class Room extends (EventEmitter as new () => TypedEmitter) 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}`; @@ -608,8 +611,8 @@ class Room extends (EventEmitter as new () => TypedEmitter) } if (abortController.signal.aborted) { + await this.engine.close(); this.recreateEngine(); - this.handleDisconnect(this.options.stopLocalTrackOnUnpublish); throw new ConnectionError(`Connection attempt aborted`); } @@ -619,8 +622,8 @@ class Room extends (EventEmitter as new () => TypedEmitter) abortController, ); } catch (e) { + await this.engine.close(); this.recreateEngine(); - this.handleDisconnect(this.options.stopLocalTrackOnUnpublish); throw e; }