The RoomDelegate protocol receives room events as well as participant events.
The thread which the delegate will be called on is not guaranteed to be the main thread. If you will perform any UI update from the delegate, ensure the execution is from the main thread.
Usage
class MyViewController: UIViewController, RoomDelegate {
func setupRoom() {
let room = Room()
room.add(delegate: self)
}
func room(_ room: Room, localParticipant: LocalParticipant, didPublish publication: LocalTrackPublication) {
DispatchQueue.main.async {
// Update UI on main thread
self.localVideoView.isHidden = false
}
}
}
Connection Events
room(_:didUpdateConnectionState:from:)
Called when the room’s connection state has updated.This method is not called for ReconnectMode.quick. Use room(_:didStartReconnectWithMode:) and room(_:didCompleteReconnectWithMode:) instead.
func room(_ room: Room, didUpdateConnectionState connectionState: ConnectionState, from oldConnectionState: ConnectionState)
Successfully connected to the room.func roomDidConnect(_ room: Room)
Previously connected to room but re-attempting to connect due to network issues.Not called for ReconnectMode.quick.
func roomIsReconnecting(_ room: Room)
Successfully re-connected to the room.Not called for ReconnectMode.quick.
func roomDidReconnect(_ room: Room)
room(_:didStartReconnectWithMode:)
Reconnection started with the specified mode.func room(_ room: Room, didStartReconnectWithMode reconnectMode: ReconnectMode)
room(_:didCompleteReconnectWithMode:)
Reconnection completed successfully.func room(_ room: Room, didCompleteReconnectWithMode reconnectMode: ReconnectMode)
room(_:didUpdateReconnectMode:)
Room reconnect mode has updated.func room(_ room: Room, didUpdateReconnectMode reconnectMode: ReconnectMode)
room(_:didFailToConnectWithError:)
Could not connect to the room. Only triggered when the initial connect attempt fails.func room(_ room: Room, didFailToConnectWithError error: LiveKitError?)
room(_:didDisconnectWithError:)
Client disconnected from the room unexpectedly after a successful connection.func room(_ room: Room, didDisconnectWithError error: LiveKitError?)
Room State Updates
room(_:didUpdateMetadata:)
Room metadata has updated.func room(_ room: Room, didUpdateMetadata metadata: String?)
room(_:didUpdateIsRecording:)
Room recording state has updated.func room(_ room: Room, didUpdateIsRecording isRecording: Bool)
room(_:didMoveToRoomNamed:)
The local participant was moved to a different room.func room(_ room: Room, didMoveToRoomNamed roomName: String)
Participant Management
room(_:participantDidConnect:)
A remote participant joined the room.func room(_ room: Room, participantDidConnect participant: RemoteParticipant)
room(_:participantDidDisconnect:)
A remote participant left the room.func room(_ room: Room, participantDidDisconnect participant: RemoteParticipant)
room(_:didUpdateSpeakingParticipants:)
Active speakers in the room have updated.func room(_ room: Room, didUpdateSpeakingParticipants participants: [Participant])
room(_:participant:didUpdateMetadata:)
Participant metadata has updated.func room(_ room: Room, participant: Participant, didUpdateMetadata metadata: String?)
room(_:participant:didUpdateName:)
Participant name has updated.func room(_ room: Room, participant: Participant, didUpdateName name: String)
room(_:participant:didUpdateState:)
Participant state has updated.func room(_ room: Room, participant: Participant, didUpdateState state: ParticipantState)
room(_:participant:didUpdateConnectionQuality:)
Participant connection quality has updated.func room(_ room: Room, participant: Participant, didUpdateConnectionQuality quality: ConnectionQuality)
room(_:participant:didUpdatePermissions:)
Participant permissions have updated.func room(_ room: Room, participant: Participant, didUpdatePermissions permissions: ParticipantPermissions)
room(_:participant:didUpdateAttributes:)
Participant attributes have updated.func room(_ room: Room, participant: Participant, didUpdateAttributes attributes: [String: String])
Track Publications
room(_:participant:didPublishTrack:)
A participant has published a track.Available for both local and remote participants.func room(_ room: Room, participant: LocalParticipant, didPublishTrack publication: LocalTrackPublication)
func room(_ room: Room, participant: RemoteParticipant, didPublishTrack publication: RemoteTrackPublication)
room(_:participant:didUnpublishTrack:)
A participant has unpublished a track.Available for both local and remote participants.func room(_ room: Room, participant: LocalParticipant, didUnpublishTrack publication: LocalTrackPublication)
func room(_ room: Room, participant: RemoteParticipant, didUnpublishTrack publication: RemoteTrackPublication)
room(_:participant:remoteDidSubscribeTrack:)
Fired when the first remote participant has subscribed to the local participant’s track.func room(_ room: Room, participant: LocalParticipant, remoteDidSubscribeTrack publication: LocalTrackPublication)
room(_:participant:didSubscribeTrack:)
The local participant subscribed to a remote track.func room(_ room: Room, participant: RemoteParticipant, didSubscribeTrack publication: RemoteTrackPublication)
room(_:participant:didUnsubscribeTrack:)
The local participant unsubscribed from a remote track.func room(_ room: Room, participant: RemoteParticipant, didUnsubscribeTrack publication: RemoteTrackPublication)
room(_:participant:didFailToSubscribeTrackWithSid:error:)
Failed to subscribe to a track.func room(_ room: Room, participant: RemoteParticipant, didFailToSubscribeTrackWithSid trackSid: Track.Sid, error: LiveKitError)
room(_:participant:trackPublication:didUpdateIsMuted:)
Track muted state has updated.func room(_ room: Room, participant: Participant, trackPublication: TrackPublication, didUpdateIsMuted isMuted: Bool)
room(_:participant:trackPublication:didUpdateStreamState:)
Track stream state has updated.func room(_ room: Room, participant: RemoteParticipant, trackPublication: RemoteTrackPublication, didUpdateStreamState streamState: StreamState)
Data and Encryption
room(_:participant:didReceiveData:forTopic:encryptionType:)
Received data from a remote participant or server.participant will be nil if the data was broadcast from the server.func room(_ room: Room, participant: RemoteParticipant?, didReceiveData data: Data, forTopic topic: String, encryptionType: EncryptionType)
room(_:didFailToDecryptDataWithEror:)
Failed to decrypt a data packet when encryption is enabled.func room(_ room: Room, didFailToDecryptDataWithEror error: LiveKitError)
room(_:trackPublication:didUpdateE2EEState:)
End-to-end encryption state for a track has updated.func room(_ room: Room, trackPublication: TrackPublication, didUpdateE2EEState state: E2EEState)
room(_:participant:trackPublication:didReceiveTranscriptionSegments:)
Received transcription segments for a track.func room(_ room: Room, participant: Participant, trackPublication: TrackPublication, didReceiveTranscriptionSegments segments: [TranscriptionSegment])