Skip to content
Open
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
1 change: 1 addition & 0 deletions .changes/room-moved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="added" "Handle Room moved event"
40 changes: 40 additions & 0 deletions Sources/LiveKit/Core/Room+SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,46 @@ extension Room: SignalClientDelegate {
}
}

func signalClient(_: SignalClient, didReceiveRoomMoved response: Livekit_RoomMovedResponse) async {
log("didReceiveRoomMoved to room: \(response.hasRoom ? response.room.name : "unknown")")

Comment on lines +138 to +140
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to update the room's token to Livekit_RoomMovedResponse.token.

// Update room info if available
if response.hasRoom {
_state.mutate {
$0.metadata = response.room.metadata
$0.isRecording = response.room.activeRecording
$0.numParticipants = Int(response.room.numParticipants)
$0.numPublishers = Int(response.room.numPublishers)
}
Comment on lines +143 to +148
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other fields like sid / name / maxParticipants / creationTime etc. could be missing ?

}

// Disconnect all remote participants
let participantsToDisconnect = Array(_state.remoteParticipants.values)
for participant in participantsToDisconnect {
guard let identity = participant.identity else { continue }
await participant.unpublishAll(notify: false)
_state.mutate { $0.remoteParticipants.removeValue(forKey: identity) }
}

// Emit room moved event with new room name
if response.hasRoom {
delegates.notify(label: { "room.didMoveToRoomNamed \(response.room.name)" }) {
$0.room?(self, didMoveToRoomNamed: response.room.name)
}
}

// Re-add participants
var participantsToAdd: [Livekit_ParticipantInfo] = []
if response.hasParticipant {
participantsToAdd.append(response.participant)
}
participantsToAdd.append(contentsOf: response.otherParticipants)

for info in participantsToAdd {
_state.mutate { $0.updateRemoteParticipant(info: info, room: self) }
}
Comment on lines +166 to +175
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not well documented, but response.participant appears to be a LocalParticipant. We should probably call localParticipant.updateInfo instead. (I’m not sure if any of the info actually changes, though.)

}

func signalClient(_: SignalClient, didUpdateSpeakers speakers: [Livekit_SpeakerInfo]) async {
let activeSpeakers = _state.mutate { state -> [Participant] in
var lastSpeakers = state.activeSpeakers.reduce(into: [Sid: Participant]()) { $0[$1.sid] = $1 }
Expand Down
3 changes: 3 additions & 0 deletions Sources/LiveKit/Core/SignalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ private extension SignalClient {
case let .roomUpdate(update):
_delegate.notifyDetached { await $0.signalClient(self, didUpdateRoom: update.room) }

case let .roomMoved(response):
_delegate.notifyDetached { await $0.signalClient(self, didReceiveRoomMoved: response) }

case let .trackPublished(trackPublished):
log("[publish] resolving completer for cid: \(trackPublished.cid)")
// Complete
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveKit/Protocols/RoomDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public protocol RoomDelegate: AnyObject, Sendable {
@objc optional
func room(_ room: Room, didUpdateIsRecording isRecording: Bool)

/// Room was moved to a different server.
@objc optional
func room(_ room: Room, didMoveToRoomNamed roomName: String)

// MARK: - Participant Management

/// A ``RemoteParticipant`` joined the room.
Expand Down
1 change: 1 addition & 0 deletions Sources/LiveKit/Protocols/SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ protocol SignalClientDelegate: AnyObject, Sendable {
func signalClient(_ signalClient: SignalClient, didUpdateRemoteMute trackSid: Track.Sid, muted: Bool) async
func signalClient(_ signalClient: SignalClient, didUpdateTrackStreamStates streamStates: [Livekit_StreamStateInfo]) async
func signalClient(_ signalClient: SignalClient, didUpdateSubscribedCodecs codecs: [Livekit_SubscribedCodec], qualities: [Livekit_SubscribedQuality], forTrackSid sid: String) async
func signalClient(_ signalClient: SignalClient, didReceiveRoomMoved response: Livekit_RoomMovedResponse) async
func signalClient(_ signalClient: SignalClient, didUpdateSubscriptionPermission permission: Livekit_SubscriptionPermissionUpdate) async
func signalClient(_ signalClient: SignalClient, didUpdateToken token: String) async
func signalClient(_ signalClient: SignalClient, didReceiveLeave canReconnect: Bool, reason: Livekit_DisconnectReason) async
Expand Down
Loading