diff --git a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift index 9fc7bd3de..0ae8b5a1b 100644 --- a/Sources/LiveKit/Core/Room+SignalClientDelegate.swift +++ b/Sources/LiveKit/Core/Room+SignalClientDelegate.swift @@ -301,7 +301,7 @@ extension Room: SignalClientDelegate { } } - func signalClient(_: SignalClient, didReceiveIceCandidate iceCandidate: LKRTCIceCandidate, target: Livekit_SignalTarget) async { + func signalClient(_: SignalClient, didReceiveIceCandidate iceCandidate: IceCandidate, target: Livekit_SignalTarget) async { guard let transport = target == .subscriber ? _state.subscriber : _state.publisher else { log("Failed to add ice candidate, transport is nil for target: \(target)", .error) return diff --git a/Sources/LiveKit/Core/SignalClient.swift b/Sources/LiveKit/Core/SignalClient.swift index a693a4ed3..c6f7cd456 100644 --- a/Sources/LiveKit/Core/SignalClient.swift +++ b/Sources/LiveKit/Core/SignalClient.swift @@ -289,7 +289,7 @@ private extension SignalClient { return } - _delegate.notifyDetached { await $0.signalClient(self, didReceiveIceCandidate: rtcCandidate, target: trickle.target) } + _delegate.notifyDetached { await $0.signalClient(self, didReceiveIceCandidate: rtcCandidate.toLKType(), target: trickle.target) } case let .update(update): _delegate.notifyDetached { await $0.signalClient(self, didUpdateParticipants: update.participants) } diff --git a/Sources/LiveKit/Core/Transport.swift b/Sources/LiveKit/Core/Transport.swift index 8705803f2..87fcb458a 100644 --- a/Sources/LiveKit/Core/Transport.swift +++ b/Sources/LiveKit/Core/Transport.swift @@ -64,11 +64,11 @@ actor Transport: NSObject, Loggable { // forbid direct access to PeerConnection private let _pc: LKRTCPeerConnection - private lazy var _iceCandidatesQueue = QueueActor(onProcess: { [weak self] iceCandidate in + private lazy var _iceCandidatesQueue = QueueActor(onProcess: { [weak self] iceCandidate in guard let self else { return } do { - try await self._pc.add(iceCandidate) + try await self._pc.add(iceCandidate.toRTCType()) } catch { self.log("Failed to add(iceCandidate:) with error: \(error)", .error) } @@ -114,7 +114,7 @@ actor Transport: NSObject, Loggable { _isRestartingIce = true } - func add(iceCandidate candidate: LKRTCIceCandidate) async throws { + func add(iceCandidate candidate: IceCandidate) async throws { await _iceCandidatesQueue.process(candidate, if: remoteDescription != nil && !_isRestartingIce) } diff --git a/Sources/LiveKit/Protocols/SignalClientDelegate.swift b/Sources/LiveKit/Protocols/SignalClientDelegate.swift index bd97afcd1..038807150 100644 --- a/Sources/LiveKit/Protocols/SignalClientDelegate.swift +++ b/Sources/LiveKit/Protocols/SignalClientDelegate.swift @@ -27,7 +27,7 @@ protocol SignalClientDelegate: AnyObject { func signalClient(_ signalClient: SignalClient, didReceiveConnectResponse connectResponse: SignalClient.ConnectResponse) async func signalClient(_ signalClient: SignalClient, didReceiveAnswer answer: LKRTCSessionDescription) async func signalClient(_ signalClient: SignalClient, didReceiveOffer offer: LKRTCSessionDescription) async - func signalClient(_ signalClient: SignalClient, didReceiveIceCandidate iceCandidate: LKRTCIceCandidate, target: Livekit_SignalTarget) async + func signalClient(_ signalClient: SignalClient, didReceiveIceCandidate iceCandidate: IceCandidate, target: Livekit_SignalTarget) async func signalClient(_ signalClient: SignalClient, didUnpublishLocalTrack localTrack: Livekit_TrackUnpublishedResponse) async func signalClient(_ signalClient: SignalClient, didUpdateParticipants participants: [Livekit_ParticipantInfo]) async func signalClient(_ signalClient: SignalClient, didUpdateRoom room: Livekit_Room) async diff --git a/Sources/LiveKit/Types/IceCandidate.swift b/Sources/LiveKit/Types/IceCandidate.swift index 8d9bdf9bc..9518a0056 100644 --- a/Sources/LiveKit/Types/IceCandidate.swift +++ b/Sources/LiveKit/Types/IceCandidate.swift @@ -20,7 +20,7 @@ internal import LiveKitWebRTC @_implementationOnly import LiveKitWebRTC #endif -struct IceCandidate: Codable { +struct IceCandidate: Codable, Sendable { let sdp: String let sdpMLineIndex: Int32 let sdpMid: String? @@ -41,9 +41,7 @@ struct IceCandidate: Codable { extension LKRTCIceCandidate { func toLKType() -> IceCandidate { - IceCandidate(sdp: sdp, - sdpMLineIndex: sdpMLineIndex, - sdpMid: sdpMid) + IceCandidate(sdp: sdp, sdpMLineIndex: sdpMLineIndex, sdpMid: sdpMid) } convenience init(fromJsonString string: String) throws { @@ -59,3 +57,9 @@ extension LKRTCIceCandidate { sdpMid: iceCandidate.sdpMid) } } + +extension IceCandidate { + func toRTCType() -> LKRTCIceCandidate { + LKRTCIceCandidate(sdp: sdp, sdpMLineIndex: sdpMLineIndex, sdpMid: sdpMid) + } +}