diff --git a/Sources/LiveKit/Core/Room+EngineDelegate.swift b/Sources/LiveKit/Core/Room+EngineDelegate.swift index c7cf77b67..7e38369d2 100644 --- a/Sources/LiveKit/Core/Room+EngineDelegate.swift +++ b/Sources/LiveKit/Core/Room+EngineDelegate.swift @@ -40,7 +40,7 @@ extension Room: EngineDelegate { } delegates.notify(label: { "room.didUpdate connectionState: \(state.connectionState) oldValue: \(oldState.connectionState)" }) { - $0.room?(self, didUpdateConnectionState: state.connectionState, oldConnectionState: oldState.connectionState) + $0.room?(self, didUpdateConnectionState: state.connectionState, from: oldState.connectionState) } // Individual connectionState delegates @@ -166,13 +166,13 @@ extension Room: EngineDelegate { guard let self else { return } self.delegates.notify(label: { "room.didReceive data: \(packet.payload)" }) { - $0.room?(self, participant: participant, didReceiveData: packet.payload, topic: packet.topic) + $0.room?(self, participant: participant, didReceiveData: packet.payload, forTopic: packet.topic) } if let participant { participant.delegates.notify(label: { "participant.didReceive data: \(packet.payload)" }) { [weak participant] delegate in guard let participant else { return } - delegate.participant?(participant, didReceiveData: packet.payload, topic: packet.topic) + delegate.participant?(participant, didReceiveData: packet.payload, forTopic: packet.topic) } } } diff --git a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift index 5430832ef..9dda42729 100644 --- a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift +++ b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift @@ -235,8 +235,8 @@ extension Room: SignalClientDelegate { engine.executeIfConnected { [weak self] in guard let self else { return } - self.delegates.notify(label: { "room.participantDidJoin participant: \(participant)" }) { - $0.room?(self, participantDidJoin: participant) + self.delegates.notify(label: { "room.remoteParticipantDidConnect: \(participant)" }) { + $0.room?(self, participantDidConnect: participant) } } } diff --git a/Sources/LiveKit/E2EE/E2EEManager.swift b/Sources/LiveKit/E2EE/E2EEManager.swift index 6be66ca83..eca0722ee 100644 --- a/Sources/LiveKit/E2EE/E2EEManager.swift +++ b/Sources/LiveKit/E2EE/E2EEManager.swift @@ -176,7 +176,7 @@ extension E2EEManager { log("frameCryptor didStateChangeWithParticipantId \(participantId) with state \(state.rawValue)") room.delegates.notify { delegate in - delegate.room?(room, publication: publication, didUpdateE2EEState: state.toLKType()) + delegate.room?(room, track: publication, didUpdateE2EEState: state.toLKType()) } } } diff --git a/Sources/LiveKit/Participant/LocalParticipant.swift b/Sources/LiveKit/Participant/LocalParticipant.swift index 0d1e91ad1..6f35bf66b 100644 --- a/Sources/LiveKit/Participant/LocalParticipant.swift +++ b/Sources/LiveKit/Participant/LocalParticipant.swift @@ -214,10 +214,10 @@ public class LocalParticipant: Participant { // Notify didPublish delegates.notify(label: { "localParticipant.didPublish \(publication)" }) { - $0.localParticipant?(self, didPublishPublication: publication) + $0.participant?(self, didPublishTrack: publication) } room.delegates.notify(label: { "localParticipant.didPublish \(publication)" }) { - $0.room?(self.room, localParticipant: self, didPublishPublication: publication) + $0.room?(self.room, participant: self, didPublishTrack: publication) } log("[publish] success \(publication)", .info) @@ -266,10 +266,10 @@ public class LocalParticipant: Participant { func _notifyDidUnpublish() async { guard _notify else { return } delegates.notify(label: { "localParticipant.didUnpublish \(publication)" }) { - $0.localParticipant?(self, didUnpublishPublication: publication) + $0.participant?(self, didUnpublishTrack: publication) } room.delegates.notify(label: { "room.didUnpublish \(publication)" }) { - $0.room?(self.room, localParticipant: self, didUnpublishPublication: publication) + $0.room?(self.room, participant: self, didUnpublishTrack: publication) } } diff --git a/Sources/LiveKit/Participant/RemoteParticipant.swift b/Sources/LiveKit/Participant/RemoteParticipant.swift index 6d4b87336..df03e4a56 100644 --- a/Sources/LiveKit/Participant/RemoteParticipant.swift +++ b/Sources/LiveKit/Participant/RemoteParticipant.swift @@ -59,10 +59,10 @@ public class RemoteParticipant: Participant { for publication in newTrackPublications.values { self.delegates.notify(label: { "participant.didPublish \(publication)" }) { - $0.participant?(self, didPublishPublication: publication) + $0.participant?(self, didPublishTrack: publication) } self.room.delegates.notify(label: { "room.didPublish \(publication)" }) { - $0.room?(self.room, participant: self, didPublishPublication: publication) + $0.room?(self.room, participant: self, didPublishTrack: publication) } } } @@ -89,10 +89,10 @@ public class RemoteParticipant: Participant { log("Could not subscribe to mediaTrack \(sid), unable to locate track publication. existing sids: (\(_state.trackPublications.keys.joined(separator: ", ")))", .error) let error = LiveKitError(.invalidState, message: "Could not find published track with sid: \(sid)") delegates.notify(label: { "participant.didFailToSubscribe trackSid: \(sid)" }) { - $0.participant?(self, didFailToSubscribe: sid, error: error) + $0.participant?(self, didFailToSubscribeTrack: sid, withError: error) } room.delegates.notify(label: { "room.didFailToSubscribe trackSid: \(sid)" }) { - $0.room?(self.room, participant: self, didFailToSubscribe: sid, error: error) + $0.room?(self.room, participant: self, didFailToSubscribeTrack: sid, withError: error) } throw error } @@ -111,10 +111,10 @@ public class RemoteParticipant: Participant { default: let error = LiveKitError(.invalidState, message: "Unsupported type: \(rtcTrack.kind.description)") delegates.notify(label: { "participant.didFailToSubscribe trackSid: \(sid)" }) { - $0.participant?(self, didFailToSubscribe: sid, error: error) + $0.participant?(self, didFailToSubscribeTrack: sid, withError: error) } room.delegates.notify(label: { "room.didFailToSubscribe trackSid: \(sid)" }) { - $0.room?(self.room, participant: self, didFailToSubscribe: sid, error: error) + $0.room?(self.room, participant: self, didFailToSubscribeTrack: sid, withError: error) } throw error } @@ -132,18 +132,18 @@ public class RemoteParticipant: Participant { try await track.start() delegates.notify(label: { "participant.didSubscribe \(publication)" }) { - $0.participant?(self, didSubscribePublication: publication) + $0.participant?(self, didSubscribeTrack: publication) } room.delegates.notify(label: { "room.didSubscribe \(publication)" }) { - $0.room?(self.room, participant: self, didSubscribePublication: publication) + $0.room?(self.room, participant: self, didSubscribeTrack: publication) } } override func cleanUp(notify _notify: Bool = true) async { await super.cleanUp(notify: _notify) - room.delegates.notify(label: { "room.participantDidLeave" }) { - $0.room?(self.room, participantDidLeave: self) + room.delegates.notify(label: { "room.remoteParticipantDidDisconnect:" }) { + $0.room?(self.room, participantDidDisconnect: self) } } @@ -163,10 +163,10 @@ public class RemoteParticipant: Participant { func _notifyUnpublish() async { guard _notify else { return } delegates.notify(label: { "participant.didUnpublish \(publication)" }) { - $0.participant?(self, didUnpublishPublication: publication) + $0.participant?(self, didUnpublishTrack: publication) } room.delegates.notify(label: { "room.didUnpublish \(publication)" }) { - $0.room?(self.room, participant: self, didUnpublishPublication: publication) + $0.room?(self.room, participant: self, didUnpublishTrack: publication) } } @@ -183,10 +183,10 @@ public class RemoteParticipant: Participant { if _notify { // Notify unsubscribe delegates.notify(label: { "participant.didUnsubscribe \(publication)" }) { - $0.participant?(self, didUnsubscribePublication: publication) + $0.participant?(self, didUnsubscribeTrack: publication) } room.delegates.notify(label: { "room.didUnsubscribe \(publication)" }) { - $0.room?(self.room, participant: self, didUnsubscribePublication: publication) + $0.room?(self.room, participant: self, didUnsubscribeTrack: publication) } } diff --git a/Sources/LiveKit/Protocols/ParticipantDelegate.swift b/Sources/LiveKit/Protocols/ParticipantDelegate.swift index 64dc46e76..79ff30880 100644 --- a/Sources/LiveKit/Protocols/ParticipantDelegate.swift +++ b/Sources/LiveKit/Protocols/ParticipantDelegate.swift @@ -30,25 +30,25 @@ public protocol ParticipantDelegate: AnyObject { /// A ``Participant``'s metadata has updated. /// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``. - @objc(participant:didUpdateMetadata:) optional + @objc optional func participant(_ participant: Participant, didUpdateMetadata metadata: String?) /// A ``Participant``'s name has updated. /// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``. - @objc(participant:didUpdateName:) optional + @objc optional func participant(_ participant: Participant, didUpdateName name: String?) /// The isSpeaking status of a ``Participant`` has changed. /// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``. - @objc(participant:didUpdateSpeaking:) optional + @objc optional func participant(_ participant: Participant, didUpdateIsSpeaking isSpeaking: Bool) /// The connection quality of a ``Participant`` has updated. /// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``. - @objc(participant:didUpdateConnectionQuality:) optional + @objc optional func participant(_ participant: Participant, didUpdateConnectionQuality connectionQuality: ConnectionQuality) - @objc(participant:didUpdatePermissions:) optional + @objc optional func participant(_ participant: Participant, didUpdatePermissions permissions: ParticipantPermissions) // MARK: - TrackPublication @@ -59,60 +59,60 @@ public protocol ParticipantDelegate: AnyObject { /// or if the server has requested the participant to be muted. /// /// `participant` Can be a ``LocalParticipant`` or a ``RemoteParticipant``. - @objc(participant:publication:didUpdateMuted:) optional - func participant(_ participant: Participant, didUpdatePublication publication: TrackPublication, isMuted: Bool) + @objc optional + func participant(_ participant: Participant, track: TrackPublication, didUpdateIsMuted isMuted: Bool) // MARK: - LocalTrackPublication /// The ``LocalParticipant`` has published a ``LocalTrackPublication``. - @objc(localParticipant:didPublish:) optional - func localParticipant(_ participant: LocalParticipant, didPublishPublication publication: LocalTrackPublication) + @objc(localParticipant:didPublishTrack:) optional + func participant(_ participant: LocalParticipant, didPublishTrack publication: LocalTrackPublication) /// The ``LocalParticipant`` has unpublished a ``LocalTrackPublication``. - @objc(localParticipant:didUnpublish:) optional - func localParticipant(_ participant: LocalParticipant, didUnpublishPublication publication: LocalTrackPublication) + @objc(localParticipant:didUnpublishTrack:) optional + func participant(_ participant: LocalParticipant, didUnpublishTrack publication: LocalTrackPublication) // MARK: - RemoteTrackPublication /// When a new ``RemoteTrackPublication`` is published to ``Room`` after the ``LocalParticipant`` has joined. /// /// This delegate method will not be called for tracks that are already published. - @objc(remoteParticipant:didPublish:) optional - func participant(_ participant: RemoteParticipant, didPublishPublication publication: RemoteTrackPublication) + @objc(remoteParticipant:didPublishTrack:) optional + func participant(_ participant: RemoteParticipant, didPublishTrack publication: RemoteTrackPublication) /// The ``RemoteParticipant`` has unpublished a ``RemoteTrackPublication``. - @objc(remoteParticipant:didUnpublish:) optional - func participant(_ participant: RemoteParticipant, didUnpublishPublication publication: RemoteTrackPublication) + @objc(remoteParticipant:didUnpublishTrack:) optional + func participant(_ participant: RemoteParticipant, didUnpublishTrack publication: RemoteTrackPublication) /// The ``LocalParticipant`` has subscribed to a new ``RemoteTrackPublication``. /// /// This event will always fire as long as new tracks are ready for use. - @objc(participant:didSubscribe:) optional - func participant(_ participant: RemoteParticipant, didSubscribePublication publication: RemoteTrackPublication) + @objc optional + func participant(_ participant: RemoteParticipant, didSubscribeTrack publication: RemoteTrackPublication) /// Unsubscribed from a ``RemoteTrackPublication`` and is no longer available. /// /// Clients should listen to this event and handle cleanup. - @objc(participant:didUnsubscribePublication:) optional - func participant(_ participant: RemoteParticipant, didUnsubscribePublication publication: RemoteTrackPublication) + @objc optional + func participant(_ participant: RemoteParticipant, didUnsubscribeTrack publication: RemoteTrackPublication) /// Could not subscribe to a track. /// /// This is an error state, the subscription can be retried. - @objc(participant:didFailToSubscribeTrackWithSid:error:) optional - func participant(_ participant: RemoteParticipant, didFailToSubscribe trackSid: String, error: LiveKitError) + @objc optional + func participant(_ participant: RemoteParticipant, didFailToSubscribeTrack trackSid: String, withError error: LiveKitError) /// ``TrackPublication/streamState`` has updated for the ``RemoteTrackPublication``. - @objc(participant:publication:didUpdateStreamState:) optional - func participant(_ participant: RemoteParticipant, didUpdatePublication publication: RemoteTrackPublication, streamState: StreamState) + @objc optional + func participant(_ participant: RemoteParticipant, track: RemoteTrackPublication, didUpdateStreamState streamState: StreamState) /// ``RemoteTrackPublication/isSubscriptionAllowed`` has updated for the ``RemoteTrackPublication``. - @objc(participant:publication:didUpdateCanSubscribe:) optional - func participant(_ participant: RemoteParticipant, didUpdatePublication publication: RemoteTrackPublication, isSubscriptionAllowed: Bool) + @objc optional + func participant(_ participant: RemoteParticipant, track: RemoteTrackPublication, didUpdateIsSubscriptionAllowed isSubscriptionAllowed: Bool) // MARK: - Data /// Data was received from a ``RemoteParticipant``. - @objc(participant:didReceiveData:topic:) optional - func participant(_ participant: RemoteParticipant, didReceiveData data: Data, topic: String) + @objc optional + func participant(_ participant: RemoteParticipant, didReceiveData data: Data, forTopic topic: String) } diff --git a/Sources/LiveKit/Protocols/RoomDelegate.swift b/Sources/LiveKit/Protocols/RoomDelegate.swift index c4bd91bc2..b8fae38ff 100644 --- a/Sources/LiveKit/Protocols/RoomDelegate.swift +++ b/Sources/LiveKit/Protocols/RoomDelegate.swift @@ -33,130 +33,121 @@ import Foundation /// See the source code of [Swift Example App](https://github.com/livekit/client-example-swift) for more examples. @objc public protocol RoomDelegate: AnyObject { - // MARK: - Room + // MARK: - Connection Events - @objc(room:didUpdateConnectionState:oldConnectionState:) optional - func room(_ room: Room, didUpdateConnectionState connectionState: ConnectionState, oldConnectionState: ConnectionState) + /// ``Room/connectionState`` has updated. + @objc optional + func room(_ room: Room, didUpdateConnectionState connectionState: ConnectionState, from oldConnectionState: ConnectionState) /// Successfully connected to the room. - @objc(roomDidConnect:) optional + @objc optional func roomDidConnect(_ room: Room) - /// Successfully re-connected to the room. - @objc(roomIsReconnecting:) optional + /// Previously connected to room but re-attempting to connect due to network issues. + @objc optional func roomIsReconnecting(_ room: Room) /// Successfully re-connected to the room. - @objc(roomDidReconnect:) optional + @objc optional func roomDidReconnect(_ room: Room) /// Could not connect to the room. Only triggered when the initial connect attempt fails. - @objc(room:didFailToConnectWithError:) optional + @objc optional func room(_ room: Room, didFailToConnectWithError error: LiveKitError?) /// Client disconnected from the room unexpectedly after a successful connection. - @objc(room:didDisconnectWithError:) optional + @objc optional func room(_ room: Room, didDisconnectWithError error: LiveKitError?) - /// ``Room``'s id has been updated after a successful connection. - @objc(room:didUpdateRoomId:) optional + // MARK: - Room State Updates + + /// ``Room/sid`` has updated. + @objc optional func room(_ room: Room, didUpdateRoomId roomId: String) - /// ``Room``'s metadata has been updated. - @objc(room:didUpdateMetadata:) optional + /// ``Room/metadata`` has updated. + @objc optional func room(_ room: Room, didUpdateMetadata metadata: String?) - /// ``Room``'s recording state has been updated. - @objc(room:didUpdateIsRecording:) optional + /// ``Room/isRecording`` has updated. + @objc optional func room(_ room: Room, didUpdateIsRecording isRecording: Bool) - // MARK: - Participant + // MARK: - Participant Management - /// When a ``RemoteParticipant`` joins after the ``LocalParticipant``. - /// It will not emit events for participants that are already in the room. - @objc(room:participantDidJoin:) optional - func room(_ room: Room, participantDidJoin participant: RemoteParticipant) + /// A ``RemoteParticipant`` joined the room. + @objc optional + func room(_ room: Room, participantDidConnect participant: RemoteParticipant) - /// When a ``RemoteParticipant`` leaves after the ``LocalParticipant`` has joined. - @objc(room:participantDidLeave:) optional - func room(_ room: Room, participantDidLeave participant: RemoteParticipant) + /// A ``RemoteParticipant`` left the room. + @objc optional + func room(_ room: Room, participantDidDisconnect participant: RemoteParticipant) - /// Active speakers changed. - /// - /// List of speakers are ordered by their ``Participant/audioLevel``, loudest speakers first. - /// This will include the ``LocalParticipant`` too. - @objc(room:didUpdateSpeakingParticipants:) optional + /// Speakers in the room has updated. + @objc optional func room(_ room: Room, didUpdateSpeakingParticipants participants: [Participant]) - /// Same with ``ParticipantDelegate/participant(_:didUpdateMetadata:)``. - @objc(room:participant:didUpdateMetadata:) optional + /// ``Participant/metadata`` has updated. + @objc optional func room(_ room: Room, participant: Participant, didUpdateMetadata: String?) - /// Same with ``ParticipantDelegate/participant(_:didUpdateName:)``. - @objc(room:participant:didUpdateName:) optional + /// ``Participant/name`` has updated. + @objc optional func room(_ room: Room, participant: Participant, didUpdateName: String?) - /// Same with ``ParticipantDelegate/participant(_:didUpdateConnectionQuality:)``. - @objc(room:participant:didUpdateConnectionQuality:) optional - func room(_ room: Room, participant: Participant, didUpdateConnectionQuality connectionQuality: ConnectionQuality) - - /// Same with ``ParticipantDelegate/participant(_:didUpdatePublication:isMuted:)``. - @objc(room:participant:publication:didUpdateIsMuted:) optional - func room(_ room: Room, participant: Participant, didUpdatePublication publication: TrackPublication, isMuted: Bool) + /// ``Participant/connectionQuality`` has updated. + @objc optional + func room(_ room: Room, participant: Participant, didUpdateConnectionQuality quality: ConnectionQuality) - @objc(room:participant:didUpdatePermissions:) optional + /// ``Participant/permissions`` has updated. + @objc optional func room(_ room: Room, participant: Participant, didUpdatePermissions permissions: ParticipantPermissions) - // MARK: - LocalTrackPublication + // MARK: - Track Publications - /// Same with ``ParticipantDelegate/localParticipant(_:didPublishPublication:)``. - @objc(room:localParticipant:didPublishPublication:) optional - func room(_ room: Room, localParticipant: LocalParticipant, didPublishPublication publication: LocalTrackPublication) + /// The ``LocalParticipant`` has published a ``LocalTrack``. + @objc(room:localParticipant:didPublishTrack:) optional + func room(_ room: Room, participant: LocalParticipant, didPublishTrack publication: LocalTrackPublication) - /// Same with ``ParticipantDelegate/localParticipant(_:didUnpublishPublication:)``. - @objc(room:localParticipant:didUnpublishPublication:) optional - func room(_ room: Room, localParticipant: LocalParticipant, didUnpublishPublication publication: LocalTrackPublication) + /// A ``RemoteParticipant`` has published a ``RemoteTrack``. + @objc(room:remoteParticipant:didPublishTrack:) optional + func room(_ room: Room, participant: RemoteParticipant, didPublishTrack publication: RemoteTrackPublication) - // MARK: - RemoteTrackPublication + /// The ``LocalParticipant`` has un-published a ``LocalTrack``. + @objc(room:localParticipant:didUnpublishTrack:) optional + func room(_ room: Room, participant: LocalParticipant, didUnpublishTrack publication: LocalTrackPublication) - /// Same with ``ParticipantDelegate/participant(_:didPublishPublication:)``. - @objc(room:participant:didPublishPublication:) optional - func room(_ room: Room, participant: RemoteParticipant, didPublishPublication publication: RemoteTrackPublication) + /// A ``RemoteParticipant`` has un-published a ``RemoteTrack``. + @objc(room:remoteParticipant:didUnpublishTrack:) optional + func room(_ room: Room, participant: RemoteParticipant, didUnpublishTrack publication: RemoteTrackPublication) - /// Same with ``ParticipantDelegate/participant(_:didUnpublishPublication:)``. - @objc(room:participant:didUnpublishPublication:) optional - func room(_ room: Room, participant: RemoteParticipant, didUnpublishPublication publication: RemoteTrackPublication) + @objc optional + func room(_ room: Room, participant: RemoteParticipant, didSubscribeTrack publication: RemoteTrackPublication) - /// Same with ``ParticipantDelegate/participant(_:didSubscribePublication:)``. - @objc(room:participant:didSubscribePublication:) optional - func room(_ room: Room, participant: RemoteParticipant, didSubscribePublication publication: RemoteTrackPublication) + @objc optional + func room(_ room: Room, participant: RemoteParticipant, didUnsubscribeTrack publication: RemoteTrackPublication) - /// Same with ``ParticipantDelegate/participant(_:didUnsubscribePublication:)``. - @objc(room:publication:didUnsubscribePublication:) optional - func room(_ room: Room, participant: RemoteParticipant, didUnsubscribePublication publication: RemoteTrackPublication) + @objc optional + func room(_ room: Room, participant: RemoteParticipant, didFailToSubscribeTrack: String, withError error: LiveKitError) - /// Same with ``ParticipantDelegate/participant(_:didUpdatePublication:streamState:)``. - @objc(room:participant:publication:didUpdateStreamState:) optional - func room(_ room: Room, participant: RemoteParticipant, didUpdatePublication publication: RemoteTrackPublication, streamState: StreamState) + // MARK: - Data and Encryption - /// Same with ``ParticipantDelegate/participant(_:didUpdatePublication:isSubscriptionAllowed:)``. + /// Received data from from a user or server. `participant` will be nil if broadcasted from server. @objc optional - func room(_ room: Room, participant: RemoteParticipant, didUpdatePublication publication: RemoteTrackPublication, isSubscriptionAllowed: Bool) + func room(_ room: Room, participant: RemoteParticipant?, didReceiveData data: Data, forTopic topic: String) - /// Same with ``ParticipantDelegate/participant(_:didFailToSubscribe:error:)``. @objc optional - func room(_ room: Room, participant: RemoteParticipant, didFailToSubscribe trackSid: String, error: LiveKitError) - - // MARK: - Data + func room(_ room: Room, track: TrackPublication, didUpdateE2EEState state: E2EEState) - /// Same with ``ParticipantDelegate/participant(_:didReceiveData:topic:)`` - /// participant could be nil if data was sent by server api. - @objc(room:participant:didReceiveData:topic:) optional - func room(_ room: Room, participant: RemoteParticipant?, didReceiveData data: Data, topic: String) + /// ``TrackPublication/isMuted`` has updated. + @objc optional + func room(_ room: Room, participant: Participant, track: TrackPublication, didUpdateIsMuted isMuted: Bool) - // MARK: - E2EE + /// ``TrackPublication/streamState`` has updated. + @objc optional + func room(_ room: Room, participant: RemoteParticipant, track: RemoteTrackPublication, didUpdateStreamState streamState: StreamState) - /// ``Room``'e2ee state has been updated. - @objc(room:publication:didUpdateE2EEState:) optional - func room(_ room: Room, publication: TrackPublication, didUpdateE2EEState e2eeState: E2EEState) + /// ``RemoteTrackPublication/isSubscriptionAllowed`` has updated. + @objc optional + func room(_ room: Room, participant: RemoteParticipant, track: RemoteTrackPublication, didUpdateIsSubscriptionAllowed isSubscriptionAllowed: Bool) } diff --git a/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift b/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift index b5bc202eb..ae90f9627 100644 --- a/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift +++ b/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift @@ -142,12 +142,12 @@ public class RemoteTrackPublication: TrackPublication { notify: false) } - if let oldValue, newValue == nil, let participant = participant as? RemoteParticipant { + if oldValue != nil, newValue == nil, let participant = participant as? RemoteParticipant { participant.delegates.notify(label: { "participant.didUnsubscribe \(self)" }) { - $0.participant?(participant, didUnsubscribePublication: self) + $0.participant?(participant, didUnsubscribeTrack: self) } participant.room.delegates.notify(label: { "room.didUnsubscribe \(self)" }) { - $0.room?(participant.room, participant: participant, didUnsubscribePublication: self) + $0.room?(participant.room, participant: participant, didUnsubscribeTrack: self) } } } @@ -194,10 +194,10 @@ extension RemoteTrackPublication { // if track exists, track will emit the following events if track == nil { participant.delegates.notify(label: { "participant.didUpdatePublication isMuted: \(newValue)" }) { - $0.participant?(participant, didUpdatePublication: self, isMuted: newValue) + $0.participant?(participant, track: self, didUpdateIsMuted: newValue) } participant.room.delegates.notify(label: { "room.didUpdatePublication isMuted: \(newValue)" }) { - $0.room?(participant.room, participant: participant, didUpdatePublication: self, isMuted: newValue) + $0.room?(participant.room, participant: participant, track: self, didUpdateIsMuted: newValue) } } } @@ -208,10 +208,10 @@ extension RemoteTrackPublication { guard let participant = participant as? RemoteParticipant else { return } participant.delegates.notify(label: { "participant.didUpdate permission: \(newValue)" }) { - $0.participant?(participant, didUpdatePublication: self, isSubscriptionAllowed: newValue) + $0.participant?(participant, track: self, didUpdateIsSubscriptionAllowed: newValue) } participant.room.delegates.notify(label: { "room.didUpdate permission: \(newValue)" }) { - $0.room?(participant.room, participant: participant, didUpdatePublication: self, isSubscriptionAllowed: newValue) + $0.room?(participant.room, participant: participant, track: self, didUpdateIsSubscriptionAllowed: newValue) } } } diff --git a/Sources/LiveKit/TrackPublications/TrackPublication.swift b/Sources/LiveKit/TrackPublications/TrackPublication.swift index 8aa7e8ef0..cb3fd3269 100644 --- a/Sources/LiveKit/TrackPublications/TrackPublication.swift +++ b/Sources/LiveKit/TrackPublications/TrackPublication.swift @@ -132,10 +132,10 @@ public class TrackPublication: NSObject, ObservableObject, Loggable { if newState.streamState != oldState.streamState { if let participant = self.participant as? RemoteParticipant, let trackPublication = self as? RemoteTrackPublication { participant.delegates.notify(label: { "participant.didUpdate \(trackPublication) streamState: \(newState.streamState)" }) { - $0.participant?(participant, didUpdatePublication: trackPublication, streamState: newState.streamState) + $0.participant?(participant, track: trackPublication, didUpdateStreamState: newState.streamState) } participant.room.delegates.notify(label: { "room.didUpdate \(trackPublication) streamState: \(newState.streamState)" }) { - $0.room?(participant.room, participant: participant, didUpdatePublication: trackPublication, streamState: newState.streamState) + $0.room?(participant.room, participant: participant, track: trackPublication, didUpdateStreamState: newState.streamState) } } } @@ -216,10 +216,10 @@ extension TrackPublication: TrackDelegateInternal { } participant.delegates.notify { - $0.participant?(participant, didUpdatePublication: self, isMuted: isMuted) + $0.participant?(participant, track: self, didUpdateIsMuted: isMuted) } participant.room.delegates.notify { - $0.room?(participant.room, participant: participant, didUpdatePublication: self, isMuted: self.isMuted) + $0.room?(participant.room, participant: participant, track: self, didUpdateIsMuted: self.isMuted) } // TrackPublication.isMuted is a computed property depending on Track.isMuted