Skip to content

Commit

Permalink
Safe RTCFrameCryptor initialization (#396)
Browse files Browse the repository at this point in the history
Uses new WebRTC build with `RTCFrameCryptor` improvements.
  • Loading branch information
hiroshihorie authored Jun 5, 2024
1 parent c8f72de commit 2061e8a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
],
dependencies: [
// LK-Prefixed Dynamic WebRTC XCFramework
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "114.5735.18"),
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "114.5735.19"),
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.26.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4"),
// Only used for DocC generation
Expand Down
40 changes: 22 additions & 18 deletions Sources/LiveKit/E2EE/E2EEManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ public class E2EEManager: NSObject, ObservableObject, Loggable {
return
}

let frameCryptor = DispatchQueue.liveKitWebRTC.sync {
let result = LKRTCFrameCryptor(factory: Engine.peerConnectionFactory,
rtpSender: sender,
participantId: participantIdentity.stringValue,
algorithm: RTCCyrptorAlgorithm.aesGcm,
keyProvider: e2eeOptions.keyProvider.rtcKeyProvider)

result.delegate = delegateAdapter
return result
guard let frameCryptor = DispatchQueue.liveKitWebRTC.sync(execute: {
LKRTCFrameCryptor(factory: Engine.peerConnectionFactory,
rtpSender: sender,
participantId: participantIdentity.stringValue,
algorithm: .aesGcm,
keyProvider: e2eeOptions.keyProvider.rtcKeyProvider)
}) else {
log("frameCryptor is nil, skipping creating frame cryptor...", .warning)
return
}

frameCryptor.delegate = delegateAdapter

return _state.mutate {
$0.frameCryptors[[participantIdentity: publication.sid]] = frameCryptor
$0.trackPublications[frameCryptor] = publication
Expand All @@ -138,17 +140,19 @@ public class E2EEManager: NSObject, ObservableObject, Loggable {
return
}

let frameCryptor = DispatchQueue.liveKitWebRTC.sync {
let result = LKRTCFrameCryptor(factory: Engine.peerConnectionFactory,
rtpReceiver: receiver,
participantId: participantIdentity.stringValue,
algorithm: RTCCyrptorAlgorithm.aesGcm,
keyProvider: e2eeOptions.keyProvider.rtcKeyProvider)

result.delegate = delegateAdapter
return result
guard let frameCryptor = DispatchQueue.liveKitWebRTC.sync(execute: {
LKRTCFrameCryptor(factory: Engine.peerConnectionFactory,
rtpReceiver: receiver,
participantId: participantIdentity.stringValue,
algorithm: .aesGcm,
keyProvider: e2eeOptions.keyProvider.rtcKeyProvider)
}) else {
log("frameCryptor is nil, skipping creating frame cryptor...", .warning)
return
}

frameCryptor.delegate = delegateAdapter

return _state.mutate {
$0.frameCryptors[[participantIdentity: publication.sid]] = frameCryptor
$0.trackPublications[frameCryptor] = publication
Expand Down

0 comments on commit 2061e8a

Please sign in to comment.