Skip to content

Commit

Permalink
Use Sendable IceCandidate internally
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Sep 10, 2024
1 parent 1644910 commit f0fc362
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/SignalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
6 changes: 3 additions & 3 deletions Sources/LiveKit/Core/Transport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ actor Transport: NSObject, Loggable {
// forbid direct access to PeerConnection
private let _pc: LKRTCPeerConnection

private lazy var _iceCandidatesQueue = QueueActor<LKRTCIceCandidate>(onProcess: { [weak self] iceCandidate in
private lazy var _iceCandidatesQueue = QueueActor<IceCandidate>(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)
}
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Protocols/SignalClientDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions Sources/LiveKit/Types/IceCandidate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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 {
Expand All @@ -59,3 +57,9 @@ extension LKRTCIceCandidate {
sdpMid: iceCandidate.sdpMid)
}
}

extension IceCandidate {
func toRTCType() -> LKRTCIceCandidate {
LKRTCIceCandidate(sdp: sdp, sdpMLineIndex: sdpMLineIndex, sdpMid: sdpMid)
}
}

0 comments on commit f0fc362

Please sign in to comment.