Skip to content

Commit

Permalink
Local track subscribed event (#467)
Browse files Browse the repository at this point in the history
Fired when the first remote participant has subscribed to the
localParticipant's track.
  • Loading branch information
hiroshihorie authored Sep 3, 2024
1 parent 949b584 commit 60057c4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Sources/LiveKit/Core/Room+SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,22 @@ extension Room: SignalClientDelegate {
// update token
_state.mutate { $0.token = token }
}

func signalClient(_: SignalClient, didSubscribeTrack trackSid: Track.Sid) async {
// Find the local track publication.
guard let track = localParticipant.trackPublications[trackSid] as? LocalTrackPublication else {
log("Could not find local track publication for subscribed event")
return
}

// Notify Room.
delegates.notify {
$0.room?(self, participant: self.localParticipant, remoteDidSubscribeTrack: track)
}

// Notify LocalParticipant.
localParticipant.delegates.notify {
$0.participant?(self.localParticipant, remoteDidSubscribeTrack: track)
}
}
}
4 changes: 2 additions & 2 deletions Sources/LiveKit/Core/SignalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ private extension SignalClient {
case .requestResponse:
log("Received requestResponse message")

case .trackSubscribed:
log("Received trackSubscribed message")
case let .trackSubscribed(trackSubscribed):
_delegate.notifyDetached { await $0.signalClient(self, didSubscribeTrack: Track.Sid(from: trackSubscribed.trackSid)) }
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveKit/Protocols/ParticipantDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public protocol ParticipantDelegate: AnyObject {
@objc(localParticipant:didUnpublishTrack:) optional
func participant(_ participant: LocalParticipant, didUnpublishTrack publication: LocalTrackPublication)

/// Fired when the first remote participant has subscribed to the localParticipant's track.
@objc(localParticipant:remoteDidSubscribeTrack:) optional
func participant(_ participant: LocalParticipant, remoteDidSubscribeTrack publication: LocalTrackPublication)

// MARK: - RemoteTrackPublication

/// When a new ``RemoteTrackPublication`` is published to ``Room`` after the ``LocalParticipant`` has joined.
Expand Down
4 changes: 4 additions & 0 deletions Sources/LiveKit/Protocols/RoomDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public protocol RoomDelegate: AnyObject {
@objc(room:localParticipant:didUnpublishTrack:) optional
func room(_ room: Room, participant: LocalParticipant, didUnpublishTrack publication: LocalTrackPublication)

/// Fired when the first remote participant has subscribed to the localParticipant's track.
@objc(room:localParticipant:remoteDidSubscribeTrack:) optional
func room(_ room: Room, participant: LocalParticipant, remoteDidSubscribeTrack publication: LocalTrackPublication)

/// A ``RemoteParticipant`` has un-published a ``RemoteTrack``.
@objc(room:remoteParticipant:didUnpublishTrack:) optional
func room(_ room: Room, participant: RemoteParticipant, didUnpublishTrack publication: RemoteTrackPublication)
Expand Down
1 change: 1 addition & 0 deletions Sources/LiveKit/Protocols/SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ protocol SignalClientDelegate: AnyObject {
func signalClient(_ signalClient: SignalClient, didUpdateSubscriptionPermission permission: Livekit_SubscriptionPermissionUpdate) async
func signalClient(_ signalClient: SignalClient, didUpdateToken token: String) async
func signalClient(_ signalClient: SignalClient, didReceiveLeave canReconnect: Bool, reason: Livekit_DisconnectReason) async
func signalClient(_ signalClient: SignalClient, didSubscribeTrack trackSid: Track.Sid) async
}

0 comments on commit 60057c4

Please sign in to comment.