Skip to content

Commit

Permalink
fix property name trackPublications
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Dec 6, 2023
1 parent 5bf6799 commit c25ce2d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Engine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ extension Engine {

let autoSubscribe = _state.connectOptions.autoSubscribe
let trackSids = room._state.remoteParticipants.values.flatMap { participant in
participant._state.tracks.values
participant._state.trackPublications.values
.filter { $0.subscribed != autoSubscribe }
.map(\.sid)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+EngineDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extension Room: EngineDelegate {

func engine(_: Engine, didRemove track: LKRTCMediaStreamTrack) {
// find the publication
guard let publication = _state.remoteParticipants.values.map(\._state.tracks.values).joined()
guard let publication = _state.remoteParticipants.values.map(\._state.trackPublications.values).joined()
.first(where: { $0.sid == track.trackId }) else { return }
publication.set(track: nil)
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/LiveKit/Core/Room+SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension Room: SignalClientDelegate {
func signalClient(_: SignalClient, didUpdateRemoteMute trackSid: String, muted: Bool) {
log("trackSid: \(trackSid) muted: \(muted)")

guard let publication = localParticipant._state.tracks[trackSid] as? LocalTrackPublication else {
guard let publication = localParticipant._state.trackPublications[trackSid] as? LocalTrackPublication else {
// publication was not found but the delegate was handled
return
}
Expand Down Expand Up @@ -185,7 +185,7 @@ extension Room: SignalClientDelegate {
// Try to find RemoteParticipant
guard let participant = _state.remoteParticipants[update.participantSid] else { continue }
// Try to find RemoteTrackPublication
guard let trackPublication = participant._state.tracks[update.trackSid] as? RemoteTrackPublication else { continue }
guard let trackPublication = participant._state.trackPublications[update.trackSid] as? RemoteTrackPublication else { continue }
// Update streamState (and notify)
trackPublication._state.mutate { $0.streamState = update.state.toLKType() }
}
Expand Down Expand Up @@ -240,7 +240,7 @@ extension Room: SignalClientDelegate {
func signalClient(_: SignalClient, didUnpublishLocalTrack localTrack: Livekit_TrackUnpublishedResponse) {
log()

guard let publication = localParticipant._state.tracks[localTrack.trackSid] as? LocalTrackPublication else {
guard let publication = localParticipant._state.trackPublications[localTrack.trackSid] as? LocalTrackPublication else {
log("track publication not found", .warning)
return
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ extension Room {

// create an array of RemoteTrackPublication
let remoteTrackPublications = _state.remoteParticipants.values.map {
$0._state.tracks.values.compactMap { $0 as? RemoteTrackPublication }
$0._state.trackPublications.values.compactMap { $0 as? RemoteTrackPublication }
}.joined()

// reset track settings for all RemoteTrackPublication
Expand Down
4 changes: 2 additions & 2 deletions Sources/LiveKit/E2EE/E2EEManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class E2EEManager: NSObject, ObservableObject, Loggable {
}
self.room = room
self.room?.delegates.add(delegate: self)
self.room?.localParticipant.tracksPublications.values.forEach { (publication: TrackPublication) in
self.room?.localParticipant.trackPublications.values.forEach { (publication: TrackPublication) in
if publication.encryptionType == EncryptionType.none {
self.log("E2EEManager::setup: local participant \(self.room!.localParticipant.sid) track \(publication.sid) encryptionType is none, skip")
return
Expand All @@ -77,7 +77,7 @@ public class E2EEManager: NSObject, ObservableObject, Loggable {
}

self.room?.remoteParticipants.values.forEach { (participant: RemoteParticipant) in
participant.tracksPublications.values.forEach { (publication: TrackPublication) in
participant.trackPublications.values.forEach { (publication: TrackPublication) in
if publication.encryptionType == EncryptionType.none {
self.log("E2EEManager::setup: remote participant \(participant.sid) track \(publication.sid) encryptionType is none, skip")
return
Expand Down
12 changes: 6 additions & 6 deletions Sources/LiveKit/Participant/LocalParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class LocalParticipant: Participant {
}

func getTrackPublication(sid: Sid) -> LocalTrackPublication? {
_state.tracks[sid] as? LocalTrackPublication
_state.trackPublications[sid] as? LocalTrackPublication
}

@objc
Expand All @@ -50,7 +50,7 @@ public class LocalParticipant: Participant {
throw EngineError.state(message: "Publisher is nil")
}

guard _state.tracks.values.first(where: { $0.track === track }) == nil else {
guard _state.trackPublications.values.first(where: { $0.track === track }) == nil else {
throw TrackError.publish(message: "This track has already been published.")
}

Expand Down Expand Up @@ -240,7 +240,7 @@ public class LocalParticipant: Participant {
@objc
override public func unpublishAll(notify _notify: Bool = true) async {
// Build a list of Publications
let publications = _state.tracks.values.compactMap { $0 as? LocalTrackPublication }
let publications = _state.trackPublications.values.compactMap { $0 as? LocalTrackPublication }
for publication in publications {
do {
try await unpublish(publication: publication, notify: _notify)
Expand All @@ -267,7 +267,7 @@ public class LocalParticipant: Participant {
let engine = room.engine

// Remove the publication
_state.mutate { $0.tracks.removeValue(forKey: publication.sid) }
_state.mutate { $0.trackPublications.removeValue(forKey: publication.sid) }

// If track is nil, only notify unpublish and return
guard let track = publication.track as? LocalTrack else {
Expand Down Expand Up @@ -416,7 +416,7 @@ public class LocalParticipant: Participant {

extension LocalParticipant {
func publishedTracksInfo() -> [Livekit_TrackPublishedResponse] {
_state.tracks.values.filter { $0.track != nil }
_state.trackPublications.values.filter { $0.track != nil }
.map { publication in
Livekit_TrackPublishedResponse.with {
$0.cid = publication.track!.mediaTrack.trackId
Expand All @@ -428,7 +428,7 @@ extension LocalParticipant {
}

func republishTracks() async throws {
let mediaTracks = _state.tracks.values.map { $0.track as? LocalTrack }.compactMap { $0 }
let mediaTracks = _state.trackPublications.values.map { $0.track as? LocalTrack }.compactMap { $0 }

await unpublishAll()

Expand Down
16 changes: 8 additions & 8 deletions Sources/LiveKit/Participant/Participant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ public class Participant: NSObject, ObservableObject, Loggable {
public var joinedAt: Date? { _state.joinedAt }

@objc
public var tracksPublications: [Sid: TrackPublication] { _state.tracks }
public var trackPublications: [Sid: TrackPublication] { _state.trackPublications }

@objc
public var audioTracks: [TrackPublication] {
_state.tracks.values.filter { $0.kind == .audio }
_state.trackPublications.values.filter { $0.kind == .audio }
}

@objc
public var videoTracks: [TrackPublication] {
_state.tracks.values.filter { $0.kind == .video }
_state.trackPublications.values.filter { $0.kind == .video }
}

var info: Livekit_ParticipantInfo?
Expand All @@ -82,7 +82,7 @@ public class Participant: NSObject, ObservableObject, Loggable {
var joinedAt: Date?
var connectionQuality: ConnectionQuality = .unknown
var permissions = ParticipantPermissions()
var tracks = [String: TrackPublication]()
var trackPublications = [Sid: TrackPublication]()
}

var _state: StateSync<State>
Expand Down Expand Up @@ -161,7 +161,7 @@ public class Participant: NSObject, ObservableObject, Loggable {
}

func add(publication: TrackPublication) {
_state.mutate { $0.tracks[publication.sid] = publication }
_state.mutate { $0.trackPublications[publication.sid] = publication }
publication.track?._state.mutate { $0.sid = publication.sid }
}

Expand Down Expand Up @@ -207,19 +207,19 @@ public extension Participant {
}

internal func getTrackPublication(name: String) -> TrackPublication? {
_state.tracks.values.first(where: { $0.name == name })
_state.trackPublications.values.first(where: { $0.name == name })
}

/// find the first publication matching `source` or any compatible.
internal func getTrackPublication(source: Track.Source) -> TrackPublication? {
// if source is unknown return nil
guard source != .unknown else { return nil }
// try to find a Publication with matching source
if let result = _state.tracks.values.first(where: { $0.source == source }) {
if let result = _state.trackPublications.values.first(where: { $0.source == source }) {
return result
}
// try to find a compatible Publication
if let result = _state.tracks.values.filter({ $0.source == .unknown }).first(where: {
if let result = _state.trackPublications.values.filter({ $0.source == .unknown }).first(where: {
(source == .microphone && $0.kind == .audio) ||
(source == .camera && $0.kind == .video && $0.name != Track.screenShareVideoName) ||
(source == .screenShareVideo && $0.kind == .video && $0.name == Track.screenShareVideoName) ||
Expand Down
10 changes: 5 additions & 5 deletions Sources/LiveKit/Participant/RemoteParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class RemoteParticipant: Participant {
}

func getTrackPublication(sid: Sid) -> RemoteTrackPublication? {
_state.tracks[sid] as? RemoteTrackPublication
_state.trackPublications[sid] as? RemoteTrackPublication
}

override func updateFromInfo(info: Livekit_ParticipantInfo) {
Expand Down Expand Up @@ -67,7 +67,7 @@ public class RemoteParticipant: Participant {
}
}

let unpublishRemoteTrackPublications = _state.tracks.values
let unpublishRemoteTrackPublications = _state.trackPublications.values
.filter { validTrackPublications[$0.sid] == nil }
.compactMap { $0 as? RemoteTrackPublication }

Expand All @@ -86,7 +86,7 @@ public class RemoteParticipant: Participant {
let track: Track

guard let publication = getTrackPublication(sid: sid) else {
log("Could not subscribe to mediaTrack \(sid), unable to locate track publication. existing sids: (\(_state.tracks.keys.joined(separator: ", ")))", .error)
log("Could not subscribe to mediaTrack \(sid), unable to locate track publication. existing sids: (\(_state.trackPublications.keys.joined(separator: ", ")))", .error)
let error = TrackError.state(message: "Could not find published track with sid: \(sid)")
delegates.notify(label: { "participant.didFailToSubscribe trackSid: \(sid)" }) {
$0.participant?(self, didFailToSubscribe: sid, error: error)
Expand Down Expand Up @@ -149,7 +149,7 @@ public class RemoteParticipant: Participant {

override public func unpublishAll(notify _notify: Bool = true) async {
// Build a list of Publications
let publications = _state.tracks.values.compactMap { $0 as? RemoteTrackPublication }
let publications = _state.trackPublications.values.compactMap { $0 as? RemoteTrackPublication }
for publication in publications {
do {
try await unpublish(publication: publication, notify: _notify)
Expand All @@ -171,7 +171,7 @@ public class RemoteParticipant: Participant {
}

// Remove the publication
_state.mutate { $0.tracks.removeValue(forKey: publication.sid) }
_state.mutate { $0.trackPublications.removeValue(forKey: publication.sid) }

// Continue if the publication has a track
guard let track = publication.track else {
Expand Down

0 comments on commit c25ce2d

Please sign in to comment.