Avoid possible deadlock in PeerConnectionClient.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent b7fd7d7683
commit d9bcd563b1

@ -283,11 +283,7 @@ protocol CallServiceObserver: class {
return getIceServers().then { iceServers -> Promise<HardenedRTCSessionDescription> in return getIceServers().then { iceServers -> Promise<HardenedRTCSessionDescription> in
Logger.debug("\(self.TAG) got ice servers:\(iceServers)") Logger.debug("\(self.TAG) got ice servers:\(iceServers)")
let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self) let peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callType: .Outgoing)
// When placing an outgoing call, it's our responsibility to create the DataChannel. Recipient will not have
// to do this explicitly.
peerConnectionClient.createSignalingDataChannel()
assert(self.peerConnectionClient == nil, "Unexpected PeerConnectionClient instance") assert(self.peerConnectionClient == nil, "Unexpected PeerConnectionClient instance")
Logger.debug("\(self.TAG) setting peerConnectionClient in \(#function)") Logger.debug("\(self.TAG) setting peerConnectionClient in \(#function)")
@ -439,7 +435,7 @@ protocol CallServiceObserver: class {
// even though, from the users perspective, no incoming call is yet visible. // even though, from the users perspective, no incoming call is yet visible.
assert(self.peerConnectionClient == nil, "Unexpected PeerConnectionClient instance") assert(self.peerConnectionClient == nil, "Unexpected PeerConnectionClient instance")
Logger.debug("\(self.self.TAG) setting peerConnectionClient in \(#function)") Logger.debug("\(self.self.TAG) setting peerConnectionClient in \(#function)")
self.peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self) self.peerConnectionClient = PeerConnectionClient(iceServers: iceServers, delegate: self, callType: .Incoming)
let offerSessionDescription = RTCSessionDescription(type: .offer, sdp: callerSessionDescription) let offerSessionDescription = RTCSessionDescription(type: .offer, sdp: callerSessionDescription)
let constraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil) let constraints = RTCMediaConstraints(mandatoryConstraints: nil, optionalConstraints: nil)

@ -64,6 +64,11 @@ protocol PeerConnectionClientDelegate: class {
*/ */
class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelDelegate { class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelDelegate {
enum CallType {
case Incoming
case Outgoing
}
let TAG = "[PeerConnectionClient]" let TAG = "[PeerConnectionClient]"
enum Identifiers: String { enum Identifiers: String {
case mediaStream = "ARDAMS", case mediaStream = "ARDAMS",
@ -113,7 +118,7 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
private var remoteVideoTrack: RTCVideoTrack? private var remoteVideoTrack: RTCVideoTrack?
private var cameraConstraints: RTCMediaConstraints private var cameraConstraints: RTCMediaConstraints
init(iceServers: [RTCIceServer], delegate: PeerConnectionClientDelegate) { init(iceServers: [RTCIceServer], delegate: PeerConnectionClientDelegate, callType: CallType) {
AssertIsOnMainThread() AssertIsOnMainThread()
self.iceServers = iceServers self.iceServers = iceServers
@ -139,21 +144,25 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
delegate: self) delegate: self)
createAudioSender() createAudioSender()
createVideoSender() createVideoSender()
if callType == .Outgoing {
// When placing an outgoing call, it's our responsibility to create the DataChannel.
// Recipient will not have to do this explicitly.
createSignalingDataChannel()
}
} }
// MARK: - Media Streams // MARK: - Media Streams
public func createSignalingDataChannel() { fileprivate func createSignalingDataChannel() {
AssertIsOnMainThread() AssertIsOnMainThread()
PeerConnectionClient.signalingQueue.sync { let dataChannel = peerConnection.dataChannel(forLabel: Identifiers.dataChannelSignaling.rawValue,
let dataChannel = peerConnection.dataChannel(forLabel: Identifiers.dataChannelSignaling.rawValue, configuration: RTCDataChannelConfiguration())
configuration: RTCDataChannelConfiguration()) dataChannel.delegate = self
dataChannel.delegate = self
assert(self.dataChannel == nil) assert(self.dataChannel == nil)
self.dataChannel = dataChannel self.dataChannel = dataChannel
}
} }
// MARK: Video // MARK: Video

@ -55,9 +55,8 @@ class PeerConnectionClientTest: XCTestCase {
let iceServers = [RTCIceServer]() let iceServers = [RTCIceServer]()
clientDelegate = FakePeerConnectionClientDelegate() clientDelegate = FakePeerConnectionClientDelegate()
client = PeerConnectionClient(iceServers: iceServers, delegate: clientDelegate) client = PeerConnectionClient(iceServers: iceServers, delegate: clientDelegate, callType: .Outgoing)
peerConnection = client.peerConnectionForTests() peerConnection = client.peerConnectionForTests()
client.createSignalingDataChannel()
dataChannel = client.dataChannelForTests() dataChannel = client.dataChannelForTests()
} }

Loading…
Cancel
Save