Skip to content

Commit 2beb99a

Browse files
authored
fix bug for e2ee. (#248)
* fix bug for e2ee. * Set server injection frame trailer from joinResponse. * nil check. * fix log.
1 parent 9266fe7 commit 2beb99a

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

Sources/LiveKit/Core/Room+SignalClientDelegate.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ extension Room: SignalClientDelegate {
4545

4646
log("server version: \(joinResponse.serverVersion), region: \(joinResponse.serverRegion)", .info)
4747

48+
if self.e2eeManager != nil && !joinResponse.sifTrailer.isEmpty {
49+
self.e2eeManager?.keyProvider().setSifTrailer(trailer: joinResponse.sifTrailer)
50+
}
51+
4852
_state.mutate {
4953
$0.sid = joinResponse.room.sid
5054
$0.name = joinResponse.room.name

Sources/LiveKit/E2EE/E2EEManager.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public class E2EEManager: NSObject, ObservableObject, Loggable {
4949
self.log("E2EEManager::setup: local participant \(self.room!.localParticipant!.identity) track \(publication.sid) encryptionType is none, skip")
5050
return
5151
}
52+
if publication.track?.rtpSender == nil {
53+
self.log("E2EEManager::setup: publication.track?.rtpSender is nil, skip to create FrameCryptor!")
54+
return
55+
}
5256
let fc = addRtpSender(sender: publication.track!.rtpSender!, participantId: self.room!.localParticipant!.identity, trackSid: publication.sid)
5357
trackPublications[fc] = publication
5458
})
@@ -59,6 +63,10 @@ public class E2EEManager: NSObject, ObservableObject, Loggable {
5963
self.log("E2EEManager::setup: remote participant \(participant.identity) track \(publication.sid) encryptionType is none, skip")
6064
return
6165
}
66+
if publication.track?.rtpReceiver == nil {
67+
self.log("E2EEManager::setup: publication.track?.rtpReceiver is nil, skip to create FrameCryptor!")
68+
return
69+
}
6270
let fc = addRtpReceiver(receiver: publication.track!.rtpReceiver!, participantId: participant.identity, trackSid: publication.sid)
6371
trackPublications[fc] = publication
6472
})
@@ -112,7 +120,6 @@ extension E2EEManager: RTCFrameCryptorDelegate {
112120
if self.room == nil {
113121
self.log("frameCryptor didStateChangeWithParticipantId \(participantId) with state \(state.rawValue) room is nil")
114122
return
115-
116123
}
117124
self.room?.delegates.notify { delegate in
118125
delegate.room?(self.room!, publication: publication!, didUpdateE2EEState: state.toLKType())
@@ -127,7 +134,11 @@ extension E2EEManager: RoomDelegate {
127134
self.log("E2EEManager::RoomDelegate: local participant \(localParticipant.identity) track \(publication.sid) encryptionType is none, skip")
128135
return
129136
}
130-
let fc = addRtpSender(sender: localParticipant.rtpSender!, participantId: localParticipant.identity, trackSid: publication.sid)
137+
if publication.track?.rtpSender == nil {
138+
self.log("E2EEManager::RoomDelegate: publication.track?.rtpSender is nil, skip to create FrameCryptor!")
139+
return
140+
}
141+
let fc = addRtpSender(sender: publication.track!.rtpSender!, participantId: localParticipant.identity, trackSid: publication.sid)
131142
trackPublications[fc] = publication
132143
}
133144

@@ -150,7 +161,11 @@ extension E2EEManager: RoomDelegate {
150161
self.log("E2EEManager::RoomDelegate: remote participant \(participant.identity) track \(publication.sid) encryptionType is none, skip")
151162
return
152163
}
153-
let fc = addRtpReceiver(receiver: participant.rtpReceiver!, participantId: participant.identity, trackSid: publication.sid)
164+
if publication.track?.rtpReceiver == nil {
165+
self.log("E2EEManager::RoomDelegate: publication.track?.rtpReceiver is nil, skip to create FrameCryptor!")
166+
return
167+
}
168+
let fc = addRtpReceiver(receiver: publication.track!.rtpReceiver!, participantId: participant.identity, trackSid: publication.sid)
154169
trackPublications[fc] = publication
155170
}
156171

Sources/LiveKit/E2EE/KeyProvider.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,8 @@ public class BaseKeyProvider: Loggable {
104104

105105
return rtcKeyProvider?.exportKey(participantId!, with: index ?? 0)
106106
}
107+
108+
public func setSifTrailer(trailer: Data) {
109+
rtcKeyProvider?.setSifTrailer(trailer)
110+
}
107111
}

Sources/LiveKit/Participant/LocalParticipant.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ public class LocalParticipant: Participant {
3434
private var allParticipantsAllowed: Bool = true
3535
private var trackPermissions: [ParticipantTrackPermission] = []
3636

37-
@objc var rtpSender: RTCRtpSender?
38-
3937
internal convenience init(from info: Livekit_ParticipantInfo,
4038
room: Room) {
4139

@@ -148,7 +146,6 @@ public class LocalParticipant: Participant {
148146
}
149147
}.then(on: queue) { params -> Promise<(RTCRtpTransceiver, trackInfo: Livekit_TrackInfo)> in
150148
self.log("[publish] added transceiver: \(params.trackInfo)...")
151-
self.rtpSender = params.transceiver.sender
152149
return track.onPublish().then(on: self.queue) { _ in params }
153150
}.then(on: queue) { (transceiver, trackInfo) -> LocalTrackPublication in
154151

Sources/LiveKit/Participant/RemoteParticipant.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import Promises
2121
@objc
2222
public class RemoteParticipant: Participant {
2323

24-
@objc
25-
public var rtpReceiver: RTCRtpReceiver?
26-
2724
internal init(sid: Sid,
2825
info: Livekit_ParticipantInfo?,
2926
room: Room) {
@@ -124,8 +121,6 @@ public class RemoteParticipant: Participant {
124121
return Promise(error)
125122
}
126123

127-
self.rtpReceiver = rtpReceiver
128-
129124
publication.set(track: track)
130125
publication.set(subscriptionAllowed: true)
131126
track._state.mutate { $0.sid = publication.sid }

0 commit comments

Comments
 (0)