diff --git a/Sources/LiveKit/Participant/LocalParticipant.swift b/Sources/LiveKit/Participant/LocalParticipant.swift index 9262b2b8a..bd403c905 100644 --- a/Sources/LiveKit/Participant/LocalParticipant.swift +++ b/Sources/LiveKit/Participant/LocalParticipant.swift @@ -464,7 +464,7 @@ extension LocalParticipant { .map { publication in Livekit_TrackPublishedResponse.with { $0.cid = publication.track!.mediaTrack.trackId - if let info = publication.latestInfo { + if let info = publication._state.latestInfo { $0.track = info } } diff --git a/Sources/LiveKit/Participant/RemoteParticipant.swift b/Sources/LiveKit/Participant/RemoteParticipant.swift index 01a517c21..3a0099c6b 100644 --- a/Sources/LiveKit/Participant/RemoteParticipant.swift +++ b/Sources/LiveKit/Participant/RemoteParticipant.swift @@ -123,7 +123,6 @@ public class RemoteParticipant: Participant { publication.set(track: track) publication.set(subscriptionAllowed: true) - track._state.mutate { $0.sid = publication.sid } assert(room.engine.subscriber != nil, "Subscriber is nil") if let transport = room.engine.subscriber { diff --git a/Sources/LiveKit/Track/Track.swift b/Sources/LiveKit/Track/Track.swift index 88fa5e1b0..37fb492a7 100644 --- a/Sources/LiveKit/Track/Track.swift +++ b/Sources/LiveKit/Track/Track.swift @@ -164,6 +164,10 @@ public class Track: NSObject, Loggable { guard let self = self else { return } + if oldState.dimensions != newState.dimensions { + log("Track.dimensions \(String(describing: oldState.dimensions)) -> \(String(describing: newState.dimensions))") + } + self.delegates.notify { if let delegateInternal = $0 as? TrackDelegateInternal { delegateInternal.track(self, didMutateState: newState, oldState: oldState) diff --git a/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift b/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift index b7d147975..80630b6bc 100644 --- a/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift +++ b/Sources/LiveKit/TrackPublications/RemoteTrackPublication.swift @@ -132,6 +132,12 @@ public class RemoteTrackPublication: TrackPublication { if let newValue = newValue { + // Copy meta-data to track + newValue._state.mutate { + $0.sid = sid + $0.dimensions = $0.dimensions == nil ? dimensions : $0.dimensions + } + // reset track settings, track is initially disabled only if adaptive stream and is a video track resetTrackSettings() diff --git a/Sources/LiveKit/TrackPublications/TrackPublication.swift b/Sources/LiveKit/TrackPublications/TrackPublication.swift index 78623061f..84b1d9e4e 100644 --- a/Sources/LiveKit/TrackPublications/TrackPublication.swift +++ b/Sources/LiveKit/TrackPublications/TrackPublication.swift @@ -68,7 +68,6 @@ public class TrackPublication: NSObject, ObservableObject, Loggable { /// Reference to the ``Participant`` this publication belongs to. internal weak var participant: Participant? - internal private(set) var latestInfo: Livekit_TrackInfo? internal struct State: Equatable, Hashable { let sid: Sid @@ -93,6 +92,8 @@ public class TrackPublication: NSObject, ObservableObject, Loggable { var preferSubscribed: Bool? var metadataMuted: Bool = false var encryptionType: EncryptionType = .none + + var latestInfo: Livekit_TrackInfo? } internal var _state: StateSync @@ -107,7 +108,12 @@ public class TrackPublication: NSObject, ObservableObject, Loggable { source: info.source.toLKType(), name: info.name, mimeType: info.mimeType, - encryptionType: info.encryption.toLKType() + simulcasted: info.simulcast, + dimensions: info.type == .video ? Dimensions(width: Int32(info.width), height: Int32(info.height)) : nil, + encryptionType: info.encryption.toLKType(), + + // store the whole info + latestInfo: info )) self.participant = participant @@ -115,7 +121,6 @@ public class TrackPublication: NSObject, ObservableObject, Loggable { super.init() self.set(track: track) - updateFromInfo(info: info) // listen for events from Track track?.add(delegate: self) @@ -162,20 +167,15 @@ public class TrackPublication: NSObject, ObservableObject, Loggable { internal func updateFromInfo(info: Livekit_TrackInfo) { _state.mutate { - // only muted and name can conceivably update $0.name = info.name $0.simulcasted = info.simulcast $0.mimeType = info.mimeType + $0.dimensions = info.type == .video ? Dimensions(width: Int32(info.width), height: Int32(info.height)) : nil - // only for video - if info.type == .video { - $0.dimensions = Dimensions(width: Int32(info.width), - height: Int32(info.height)) - } + // store the whole info + $0.latestInfo = info } - - self.latestInfo = info } @discardableResult