diff --git a/Sources/LiveKit/Protocols/TrackDelegate.swift b/Sources/LiveKit/Protocols/TrackDelegate.swift index 90b3e6381..b1636f1b4 100644 --- a/Sources/LiveKit/Protocols/TrackDelegate.swift +++ b/Sources/LiveKit/Protocols/TrackDelegate.swift @@ -22,19 +22,7 @@ import Foundation public protocol TrackDelegate: AnyObject { /// Dimensions of the video track has updated @objc(track:didUpdateDimensions:) optional - func track(_ track: VideoTrack, didUpdate dimensions: Dimensions?) - - /// A ``VideoView`` was attached to the ``VideoTrack`` - @objc optional - func track(_ track: VideoTrack, didAttach videoView: VideoView) - - /// A ``VideoView`` was detached from the ``VideoTrack`` - @objc optional - func track(_ track: VideoTrack, didDetach videoView: VideoView) - - /// ``Track/isMuted`` has updated. - @objc(track:didUpdateMuted:shouldSendSignal:) optional - func track(_ track: Track, didUpdate muted: Bool, shouldSendSignal: Bool) + func track(_ track: VideoTrack, didUpdateDimensions dimensions: Dimensions?) /// Statistics for the track has been generated (v2). @objc(track:didUpdateStatistics:simulcastStatistics:) optional @@ -42,6 +30,9 @@ public protocol TrackDelegate: AnyObject { } protocol TrackDelegateInternal: TrackDelegate { + /// Notify RemoteTrackPublication to send isMuted state to server. + func track(_ track: Track, didUpdateIsMuted isMuted: Bool, shouldSendSignal: Bool) + /// Used to report track state mutation to TrackPublication if attached. func track(_ track: Track, didMutateState newState: Track.State, oldState: Track.State) } diff --git a/Sources/LiveKit/Track/Track.swift b/Sources/LiveKit/Track/Track.swift index 8806c8d91..9ced2dc72 100644 --- a/Sources/LiveKit/Track/Track.swift +++ b/Sources/LiveKit/Track/Track.swift @@ -280,8 +280,10 @@ public class Track: NSObject, Loggable { } if _notify { - delegates.notify(label: { "track.didUpdate muted: \(newValue)" }) { - $0.track?(self, didUpdate: newValue, shouldSendSignal: shouldSendSignal) + delegates.notify(label: { "track.didUpdateIsMuted: \(newValue)" }) { delegate in + if let delegate = delegate as? TrackDelegateInternal { + delegate.track(self, didUpdateIsMuted: newValue, shouldSendSignal: shouldSendSignal) + } } } } @@ -320,8 +322,8 @@ extension Track { _state.mutate { $0.dimensions = newValue } guard let videoTrack = self as? VideoTrack else { return true } - delegates.notify(label: { "track.didUpdate dimensions: \(newValue == nil ? "nil" : String(describing: newValue))" }) { - $0.track?(videoTrack, didUpdate: newValue) + delegates.notify(label: { "track.didUpdateDimensions: \(newValue == nil ? "nil" : String(describing: newValue))" }) { + $0.track?(videoTrack, didUpdateDimensions: newValue) } return true diff --git a/Sources/LiveKit/TrackPublications/TrackPublication.swift b/Sources/LiveKit/TrackPublications/TrackPublication.swift index 6b59dbfeb..b0d616e03 100644 --- a/Sources/LiveKit/TrackPublications/TrackPublication.swift +++ b/Sources/LiveKit/TrackPublications/TrackPublication.swift @@ -205,18 +205,18 @@ extension TrackPublication: TrackDelegateInternal { } } - public func track(_: Track, didUpdate muted: Bool, shouldSendSignal: Bool) { - log("isMuted: \(muted) shouldSendSignal: \(shouldSendSignal)") + public func track(_: Track, didUpdateIsMuted isMuted: Bool, shouldSendSignal: Bool) { + log("isMuted: \(isMuted) shouldSendSignal: \(shouldSendSignal)") Task { let participant = try await requireParticipant() if shouldSendSignal { - try await participant.room.engine.signalClient.sendMuteTrack(trackSid: sid, muted: muted) + try await participant.room.engine.signalClient.sendMuteTrack(trackSid: sid, muted: isMuted) } participant.delegates.notify { - $0.participant?(participant, didUpdatePublication: self, isMuted: muted) + $0.participant?(participant, didUpdatePublication: self, isMuted: isMuted) } participant.room.delegates.notify { $0.room?(participant.room, participant: participant, didUpdatePublication: self, isMuted: self.isMuted) diff --git a/Sources/LiveKit/Views/VideoView.swift b/Sources/LiveKit/Views/VideoView.swift index 7cf2691a7..f88014f41 100644 --- a/Sources/LiveKit/Views/VideoView.swift +++ b/Sources/LiveKit/Views/VideoView.swift @@ -239,12 +239,6 @@ public class VideoView: NativeView, Loggable { if let localTrack = track as? LocalVideoTrack { localTrack.capturer.remove(delegate: self) } - - // notify detach - track.delegates.notify(label: { "track.didDetach videoView: \(self)" }) { [weak self, weak track] delegate in - guard let self, let track else { return } - delegate.track?(track, didDetach: self) - } } // set new track @@ -265,12 +259,6 @@ public class VideoView: NativeView, Loggable { if let localTrack = track as? LocalVideoTrack { localTrack.capturer.add(delegate: self) } - - // notify attach - track.delegates.notify(label: { "track.didAttach videoView: \(self)" }) { [weak self, weak track] delegate in - guard let self, let track else { return } - delegate.track?(track, didAttach: self) - } } }