diff --git a/.changeset/selfish-moles-develop.md b/.changeset/selfish-moles-develop.md new file mode 100644 index 0000000000..2a088cb94c --- /dev/null +++ b/.changeset/selfish-moles-develop.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Update to protocol 13 with LeaveRequest Action diff --git a/src/api/SignalClient.ts b/src/api/SignalClient.ts index 0dad49d63f..4dac4f886f 100644 --- a/src/api/SignalClient.ts +++ b/src/api/SignalClient.ts @@ -6,6 +6,7 @@ import { DisconnectReason, JoinResponse, LeaveRequest, + LeaveRequest_Action, MuteTrackRequest, ParticipantInfo, Ping, @@ -596,8 +597,9 @@ export class SignalClient { return this.sendRequest({ case: 'leave', value: new LeaveRequest({ - canReconnect: false, reason: DisconnectReason.CLIENT_INITIATED, + // server doesn't process this field, keeping it here to indicate the intent of a full disconnect + action: LeaveRequest_Action.DISCONNECT, }), }); } diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 334e86e392..5179d76c61 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -9,6 +9,7 @@ import { DisconnectReason, type JoinResponse, type LeaveRequest, + LeaveRequest_Action, ParticipantInfo, ReconnectReason, type ReconnectResponse, @@ -504,16 +505,28 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit this.handleDisconnect('signal', ReconnectReason.RR_SIGNAL_DISCONNECTED); }; - this.client.onLeave = (leave?: LeaveRequest) => { - if (leave?.canReconnect) { - this.fullReconnectOnNext = true; - // reconnect immediately instead of waiting for next attempt - this.handleDisconnect(leaveReconnect); - } else { - this.emit(EngineEvent.Disconnected, leave?.reason); - this.close(); - } + this.client.onLeave = (leave: LeaveRequest) => { this.log.debug('client leave request', { ...this.logContext, reason: leave?.reason }); + if (leave.regions && this.regionUrlProvider) { + this.log.debug('updating regions', this.logContext); + this.regionUrlProvider.setServerReportedRegions(leave.regions); + } + switch (leave.action) { + case LeaveRequest_Action.DISCONNECT: + this.emit(EngineEvent.Disconnected, leave?.reason); + this.close(); + break; + case LeaveRequest_Action.RECONNECT: + this.fullReconnectOnNext = true; + // reconnect immediately instead of waiting for next attempt + this.handleDisconnect(leaveReconnect); + break; + case LeaveRequest_Action.RESUME: + // reconnect immediately instead of waiting for next attempt + this.handleDisconnect(leaveReconnect); + default: + break; + } }; } diff --git a/src/room/RegionUrlProvider.ts b/src/room/RegionUrlProvider.ts index 676ef608f6..cf80e3f900 100644 --- a/src/room/RegionUrlProvider.ts +++ b/src/room/RegionUrlProvider.ts @@ -75,6 +75,11 @@ export class RegionUrlProvider { ); } } + + setServerReportedRegions(regions: RegionSettings) { + this.regionSettings = regions; + this.lastUpdateAt = Date.now(); + } } function getCloudConfigUrl(serverUrl: URL) { diff --git a/src/room/Room.ts b/src/room/Room.ts index b5e5d47226..02287c7696 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -4,6 +4,7 @@ import { DisconnectReason, JoinResponse, LeaveRequest, + LeaveRequest_Action, ParticipantInfo, ParticipantInfo_State, ParticipantPermission, @@ -859,7 +860,7 @@ class Room extends (EventEmitter as new () => TypedEmitter) onLeave( new LeaveRequest({ reason: DisconnectReason.CLIENT_INITIATED, - canReconnect: true, + action: LeaveRequest_Action.RECONNECT, }), ); } diff --git a/src/version.ts b/src/version.ts index 8d87ab28a5..5b54e04f5e 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,4 +1,4 @@ import { version as v } from '../package.json'; export const version = v; -export const protocolVersion = 12; +export const protocolVersion = 13;