From e901d1e1cd76648731c4663e366ea941baa2abc1 Mon Sep 17 00:00:00 2001 From: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com> Date: Mon, 18 Dec 2023 15:53:19 +0900 Subject: [PATCH] refactor internal delegates --- Sources/LiveKit/Core/Engine+SignalClientDelegate.swift | 2 +- Sources/LiveKit/Core/Engine+TransportDelegate.swift | 8 ++++---- Sources/LiveKit/Core/Room+SignalClientDelegate.swift | 5 ++++- Sources/LiveKit/Core/SignalClient.swift | 7 +++---- Sources/LiveKit/Core/Transport.swift | 8 ++++---- Sources/LiveKit/Protocols/SignalClientDelegate.swift | 4 +--- Sources/LiveKit/Protocols/TransportDelegate.swift | 10 +++++----- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Sources/LiveKit/Core/Engine+SignalClientDelegate.swift b/Sources/LiveKit/Core/Engine+SignalClientDelegate.swift index 6671bd406..904698b91 100644 --- a/Sources/LiveKit/Core/Engine+SignalClientDelegate.swift +++ b/Sources/LiveKit/Core/Engine+SignalClientDelegate.swift @@ -96,7 +96,7 @@ extension Engine: SignalClientDelegate { func signalClient(_: SignalClient, didUpdateConnectionQuality _: [Livekit_ConnectionQualityInfo]) {} func signalClient(_: SignalClient, didUpdateRemoteMute _: String, muted _: Bool) {} func signalClient(_: SignalClient, didUpdateTrackStreamStates _: [Livekit_StreamStateInfo]) {} - func signalClient(_: SignalClient, didUpdateTrack _: String, subscribedQualities _: [Livekit_SubscribedQuality], subscribedCodecs _: [Livekit_SubscribedCodec]) {} + func signalClient(_: SignalClient, didUpdateSubscribedCodecs _: [Livekit_SubscribedCodec], qualities _: [Livekit_SubscribedQuality], forTrackSid _: String) {} func signalClient(_: SignalClient, didUpdateSubscriptionPermission _: Livekit_SubscriptionPermissionUpdate) {} func signalClient(_: SignalClient, didReceiveLeave _: Bool, reason _: Livekit_DisconnectReason) {} } diff --git a/Sources/LiveKit/Core/Engine+TransportDelegate.swift b/Sources/LiveKit/Core/Engine+TransportDelegate.swift index f3754b79c..0ca3dd27c 100644 --- a/Sources/LiveKit/Core/Engine+TransportDelegate.swift +++ b/Sources/LiveKit/Core/Engine+TransportDelegate.swift @@ -19,7 +19,7 @@ import Foundation @_implementationOnly import WebRTC extension Engine: TransportDelegate { - func transport(_ transport: Transport, didUpdate pcState: RTCPeerConnectionState) { + func transport(_ transport: Transport, didUpdateState pcState: RTCPeerConnectionState) { log("target: \(transport.target), state: \(pcState)") // primary connected @@ -43,7 +43,7 @@ extension Engine: TransportDelegate { } } - func transport(_ transport: Transport, didGenerate iceCandidate: LKRTCIceCandidate) { + func transport(_ transport: Transport, didGenerateIceCandidate iceCandidate: LKRTCIceCandidate) { log("didGenerate iceCandidate") Task { try await signalClient.sendCandidate(candidate: iceCandidate, target: transport.target) @@ -64,13 +64,13 @@ extension Engine: TransportDelegate { } } - func transport(_ transport: Transport, didRemove track: LKRTCMediaStreamTrack) { + func transport(_ transport: Transport, didRemoveTrack track: LKRTCMediaStreamTrack) { if transport.target == .subscriber { notify { $0.engine(self, didRemoveTrack: track) } } } - func transport(_ transport: Transport, didOpen dataChannel: LKRTCDataChannel) { + func transport(_ transport: Transport, didOpenDataChannel dataChannel: LKRTCDataChannel) { log("Server opened data channel \(dataChannel.label)(\(dataChannel.readyState))") Task { diff --git a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift index 7c4fbca2a..d88f6f542 100644 --- a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift +++ b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift @@ -33,7 +33,10 @@ extension Room: SignalClientDelegate { } } - func signalClient(_: SignalClient, didUpdateTrack trackSid: String, subscribedQualities qualities: [Livekit_SubscribedQuality], subscribedCodecs codecs: [Livekit_SubscribedCodec]) { + func signalClient(_: SignalClient, didUpdateSubscribedCodecs codecs: [Livekit_SubscribedCodec], + qualities: [Livekit_SubscribedQuality], + forTrackSid trackSid: String) + { log("[Publish/Backup] Qualities: \(qualities.map { String(describing: $0) }.joined(separator: ", ")), Codecs: \(codecs.map { String(describing: $0) }.joined(separator: ", "))") guard let publication = localParticipant.getTrackPublication(sid: trackSid) else { diff --git a/Sources/LiveKit/Core/SignalClient.swift b/Sources/LiveKit/Core/SignalClient.swift index 85df3d21e..794ff637e 100644 --- a/Sources/LiveKit/Core/SignalClient.swift +++ b/Sources/LiveKit/Core/SignalClient.swift @@ -290,10 +290,9 @@ private extension SignalClient { notify { $0.signalClient(self, didUpdateTrackStreamStates: states.streamStates) } case let .subscribedQualityUpdate(update): - notify { $0.signalClient(self, - didUpdateTrack: update.trackSid, - subscribedQualities: update.subscribedQualities, - subscribedCodecs: update.subscribedCodecs) } + notify { $0.signalClient(self, didUpdateSubscribedCodecs: update.subscribedCodecs, + qualities: update.subscribedQualities, + forTrackSid: update.trackSid) } case let .subscriptionPermissionUpdate(permissionUpdate): notify { $0.signalClient(self, didUpdateSubscriptionPermission: permissionUpdate) } diff --git a/Sources/LiveKit/Core/Transport.swift b/Sources/LiveKit/Core/Transport.swift index 08734e9fd..7d275755d 100644 --- a/Sources/LiveKit/Core/Transport.swift +++ b/Sources/LiveKit/Core/Transport.swift @@ -196,14 +196,14 @@ extension Transport { extension Transport: LKRTCPeerConnectionDelegate { func peerConnection(_: LKRTCPeerConnection, didChange state: RTCPeerConnectionState) { log("did update state \(state) for \(target)") - notify { $0.transport(self, didUpdate: state) } + notify { $0.transport(self, didUpdateState: state) } } func peerConnection(_: LKRTCPeerConnection, didGenerate candidate: LKRTCIceCandidate) { log("Did generate ice candidates \(candidate) for \(target)") - notify { $0.transport(self, didGenerate: candidate) } + notify { $0.transport(self, didGenerateIceCandidate: candidate) } } func peerConnectionShouldNegotiate(_: LKRTCPeerConnection) { @@ -233,12 +233,12 @@ extension Transport: LKRTCPeerConnectionDelegate { } log("didRemove track: \(track.trackId)") - notify { $0.transport(self, didRemove: track) } + notify { $0.transport(self, didRemoveTrack: track) } } func peerConnection(_: LKRTCPeerConnection, didOpen dataChannel: LKRTCDataChannel) { log("Received data channel \(dataChannel.label) for \(target)") - notify { $0.transport(self, didOpen: dataChannel) } + notify { $0.transport(self, didOpenDataChannel: dataChannel) } } func peerConnection(_: LKRTCPeerConnection, didChange _: RTCIceConnectionState) {} diff --git a/Sources/LiveKit/Protocols/SignalClientDelegate.swift b/Sources/LiveKit/Protocols/SignalClientDelegate.swift index 531615091..890aef427 100644 --- a/Sources/LiveKit/Protocols/SignalClientDelegate.swift +++ b/Sources/LiveKit/Protocols/SignalClientDelegate.swift @@ -32,9 +32,7 @@ protocol SignalClientDelegate: AnyObject { func signalClient(_ signalClient: SignalClient, didUpdateConnectionQuality connectionQuality: [Livekit_ConnectionQualityInfo]) func signalClient(_ signalClient: SignalClient, didUpdateRemoteMute trackSid: String, muted: Bool) func signalClient(_ signalClient: SignalClient, didUpdateTrackStreamStates streamStates: [Livekit_StreamStateInfo]) - func signalClient(_ signalClient: SignalClient, didUpdateTrack trackSid: String, - subscribedQualities qualities: [Livekit_SubscribedQuality], - subscribedCodecs codecs: [Livekit_SubscribedCodec]) + func signalClient(_ signalClient: SignalClient, didUpdateSubscribedCodecs codecs: [Livekit_SubscribedCodec], qualities: [Livekit_SubscribedQuality], forTrackSid sid: String) func signalClient(_ signalClient: SignalClient, didUpdateSubscriptionPermission permission: Livekit_SubscriptionPermissionUpdate) func signalClient(_ signalClient: SignalClient, didUpdateToken token: String) func signalClient(_ signalClient: SignalClient, didReceiveLeave canReconnect: Bool, reason: Livekit_DisconnectReason) diff --git a/Sources/LiveKit/Protocols/TransportDelegate.swift b/Sources/LiveKit/Protocols/TransportDelegate.swift index a5299f393..7e1024150 100644 --- a/Sources/LiveKit/Protocols/TransportDelegate.swift +++ b/Sources/LiveKit/Protocols/TransportDelegate.swift @@ -19,10 +19,10 @@ import Foundation @_implementationOnly import WebRTC protocol TransportDelegate: AnyObject { - func transport(_ transport: Transport, didUpdate state: RTCPeerConnectionState) - func transport(_ transport: Transport, didGenerate iceCandidate: LKRTCIceCandidate) - func transport(_ transport: Transport, didOpen dataChannel: LKRTCDataChannel) - func transport(_ transport: Transport, didAddTrack: LKRTCMediaStreamTrack, rtpReceiver: LKRTCRtpReceiver, streams: [LKRTCMediaStream]) - func transport(_ transport: Transport, didRemove track: LKRTCMediaStreamTrack) + func transport(_ transport: Transport, didUpdateState state: RTCPeerConnectionState) + func transport(_ transport: Transport, didGenerateIceCandidate iceCandidate: LKRTCIceCandidate) + func transport(_ transport: Transport, didOpenDataChannel dataChannel: LKRTCDataChannel) + func transport(_ transport: Transport, didAddTrack track: LKRTCMediaStreamTrack, rtpReceiver: LKRTCRtpReceiver, streams: [LKRTCMediaStream]) + func transport(_ transport: Transport, didRemoveTrack track: LKRTCMediaStreamTrack) func transportShouldNegotiate(_ transport: Transport) }