diff --git a/.changeset/slimy-goats-glow.md b/.changeset/slimy-goats-glow.md new file mode 100644 index 0000000000..4f3a0f676a --- /dev/null +++ b/.changeset/slimy-goats-glow.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Perform full reconnect on leave during reconnect diff --git a/src/api/SignalClient.ts b/src/api/SignalClient.ts index f2b18a69ee..7f59c5ce91 100644 --- a/src/api/SignalClient.ts +++ b/src/api/SignalClient.ts @@ -363,7 +363,12 @@ export class SignalClient { shouldProcessMessage = true; } } else if (this.isEstablishingConnection && resp.message.case === 'leave') { - reject(new ConnectionError('Received leave request while trying to (re)connect')); + reject( + new ConnectionError( + 'Received leave request while trying to (re)connect', + ConnectionErrorReason.LeaveRequest, + ), + ); } else if (!opts.reconnect) { // non-reconnect case, should receive join response first reject( diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index bdf1ee48ff..bb13bf5d2f 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -1004,6 +1004,9 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit if (error instanceof ConnectionError && error.reason === ConnectionErrorReason.NotAllowed) { throw new UnexpectedConnectionState('could not reconnect, token might be expired'); } + if (error instanceof ConnectionError && error.reason === ConnectionErrorReason.LeaveRequest) { + throw error; + } throw new SignalReconnectError(message); } this.emit(EngineEvent.SignalResumed); diff --git a/src/room/errors.ts b/src/room/errors.ts index ba2702d4cd..7e4cd1b595 100644 --- a/src/room/errors.ts +++ b/src/room/errors.ts @@ -12,6 +12,7 @@ export const enum ConnectionErrorReason { ServerUnreachable, InternalError, Cancelled, + LeaveRequest, } export class ConnectionError extends LivekitError {