Skip to content

Commit

Permalink
Fix initial Track.dimensions (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie authored Oct 20, 2023
1 parent 510af17 commit 0b78389
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Sources/LiveKit/Participant/LocalParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
1 change: 0 additions & 1 deletion Sources/LiveKit/Participant/RemoteParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveKit/Track/Track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
22 changes: 11 additions & 11 deletions Sources/LiveKit/TrackPublications/TrackPublication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<State>
Expand All @@ -107,15 +108,19 @@ 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

super.init()

self.set(track: track)
updateFromInfo(info: info)

// listen for events from Track
track?.add(delegate: self)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0b78389

Please sign in to comment.