|
|
@ -194,6 +194,10 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
guard let localVideoTrack = self.localVideoTrack else {
|
|
|
|
guard let localVideoTrack = self.localVideoTrack else {
|
|
|
|
let action = enabled ? "enable" : "disable"
|
|
|
|
let action = enabled ? "enable" : "disable"
|
|
|
|
Logger.error("\(self.TAG)) trying to \(action) videoTrack which doesn't exist")
|
|
|
|
Logger.error("\(self.TAG)) trying to \(action) videoTrack which doesn't exist")
|
|
|
@ -203,8 +207,10 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
localVideoTrack.isEnabled = enabled
|
|
|
|
localVideoTrack.isEnabled = enabled
|
|
|
|
|
|
|
|
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async { [weak self, weak localVideoTrack] in
|
|
|
|
delegate.peerConnectionClient(self, didUpdateLocal: enabled ? localVideoTrack : nil)
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
|
|
|
|
guard let strongLocalVideoTrack = localVideoTrack else { return }
|
|
|
|
|
|
|
|
delegate.peerConnectionClient(strongSelf, didUpdateLocal: enabled ? strongLocalVideoTrack : nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -238,6 +244,10 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
guard let audioTrack = self.audioTrack else {
|
|
|
|
guard let audioTrack = self.audioTrack else {
|
|
|
|
let action = enabled ? "enable" : "disable"
|
|
|
|
let action = enabled ? "enable" : "disable"
|
|
|
|
Logger.error("\(self.TAG) trying to \(action) audioTrack which doesn't exist.")
|
|
|
|
Logger.error("\(self.TAG) trying to \(action) audioTrack which doesn't exist.")
|
|
|
@ -265,10 +275,19 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
self.assertOnSignalingQueue()
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self.peerConnection.offer(for: self.defaultOfferConstraints, completionHandler: { (sdp: RTCSessionDescription?, error: Error?) in
|
|
|
|
self.peerConnection.offer(for: self.defaultOfferConstraints, completionHandler: { (sdp: RTCSessionDescription?, error: Error?) in
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
guard error == nil else {
|
|
|
|
guard error == nil else {
|
|
|
|
reject(error!)
|
|
|
|
reject(error!)
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -299,11 +318,18 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
public func setLocalSessionDescription(_ sessionDescription: HardenedRTCSessionDescription) -> Promise<Void> {
|
|
|
|
public func setLocalSessionDescription(_ sessionDescription: HardenedRTCSessionDescription) -> Promise<Void> {
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
|
|
return PromiseKit.wrap { resolve in
|
|
|
|
return Promise { fulfill, reject in
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
self.assertOnSignalingQueue()
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.verbose("\(self.TAG) setting local session description: \(sessionDescription)")
|
|
|
|
Logger.verbose("\(self.TAG) setting local session description: \(sessionDescription)")
|
|
|
|
self.peerConnection.setLocalDescription(sessionDescription.rtcSessionDescription, completionHandler:resolve)
|
|
|
|
self.peerConnection.setLocalDescription(sessionDescription.rtcSessionDescription,
|
|
|
|
|
|
|
|
completionHandler: { _ in
|
|
|
|
|
|
|
|
fulfill()
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -320,11 +346,18 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
public func setRemoteSessionDescription(_ sessionDescription: RTCSessionDescription) -> Promise<Void> {
|
|
|
|
public func setRemoteSessionDescription(_ sessionDescription: RTCSessionDescription) -> Promise<Void> {
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
|
|
return PromiseKit.wrap { resolve in
|
|
|
|
return Promise { fulfill, reject in
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
self.assertOnSignalingQueue()
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.verbose("\(self.TAG) setting remote description: \(sessionDescription)")
|
|
|
|
Logger.verbose("\(self.TAG) setting remote description: \(sessionDescription)")
|
|
|
|
self.peerConnection.setRemoteDescription(sessionDescription, completionHandler: resolve)
|
|
|
|
self.peerConnection.setRemoteDescription(sessionDescription,
|
|
|
|
|
|
|
|
completionHandler: { _ in
|
|
|
|
|
|
|
|
fulfill()
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -335,10 +368,21 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
return Promise { fulfill, reject in
|
|
|
|
return Promise { fulfill, reject in
|
|
|
|
assertOnSignalingQueue()
|
|
|
|
assertOnSignalingQueue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) negotiating answer session.")
|
|
|
|
Logger.debug("\(self.TAG) negotiating answer session.")
|
|
|
|
|
|
|
|
|
|
|
|
peerConnection.answer(for: constraints, completionHandler: { (sdp: RTCSessionDescription?, error: Error?) in
|
|
|
|
peerConnection.answer(for: constraints, completionHandler: { (sdp: RTCSessionDescription?, error: Error?) in
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
reject(NSError(domain:"Obsolete client", code:0, userInfo:nil))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
guard error == nil else {
|
|
|
|
guard error == nil else {
|
|
|
|
reject(error!)
|
|
|
|
reject(error!)
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -366,13 +410,24 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
|
|
|
|
|
|
|
|
public func addIceCandidate(_ candidate: RTCIceCandidate) {
|
|
|
|
public func addIceCandidate(_ candidate: RTCIceCandidate) {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) adding candidate")
|
|
|
|
Logger.debug("\(self.TAG) adding candidate")
|
|
|
|
self.peerConnection.add(candidate)
|
|
|
|
self.peerConnection.add(candidate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public func terminate() {
|
|
|
|
public func terminate() {
|
|
|
|
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
Logger.debug("\(TAG) in \(#function)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delegate.peerConnectionClient(self, didUpdateLocal: nil)
|
|
|
|
|
|
|
|
delegate.peerConnectionClient(self, didUpdateRemote: nil)
|
|
|
|
|
|
|
|
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
assert(self.peerConnection != nil)
|
|
|
|
self.terminateInternal()
|
|
|
|
self.terminateInternal()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -380,6 +435,8 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
private func terminateInternal() {
|
|
|
|
private func terminateInternal() {
|
|
|
|
assertOnSignalingQueue()
|
|
|
|
assertOnSignalingQueue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.debug("\(TAG) in \(#function)")
|
|
|
|
|
|
|
|
|
|
|
|
// Some notes on preventing crashes while disposing of peerConnection for video calls
|
|
|
|
// Some notes on preventing crashes while disposing of peerConnection for video calls
|
|
|
|
// from: https://groups.google.com/forum/#!searchin/discuss-webrtc/objc$20crash$20dealloc%7Csort:relevance/discuss-webrtc/7D-vk5yLjn8/rBW2D6EW4GYJ
|
|
|
|
// from: https://groups.google.com/forum/#!searchin/discuss-webrtc/objc$20crash$20dealloc%7Csort:relevance/discuss-webrtc/7D-vk5yLjn8/rBW2D6EW4GYJ
|
|
|
|
// The sequence to make it work appears to be
|
|
|
|
// The sequence to make it work appears to be
|
|
|
@ -392,16 +449,22 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
// audioTrack is a strong property because we need access to it to mute/unmute, but I was seeing it
|
|
|
|
// audioTrack is a strong property because we need access to it to mute/unmute, but I was seeing it
|
|
|
|
// become nil when it was only a weak property. So we retain it and manually nil the reference here, because
|
|
|
|
// become nil when it was only a weak property. So we retain it and manually nil the reference here, because
|
|
|
|
// we are likely to crash if we retain any peer connection properties when the peerconnection is released
|
|
|
|
// we are likely to crash if we retain any peer connection properties when the peerconnection is released
|
|
|
|
Logger.debug("\(TAG) in \(#function)")
|
|
|
|
|
|
|
|
audioTrack = nil
|
|
|
|
localVideoTrack?.isEnabled = false
|
|
|
|
localVideoTrack = nil
|
|
|
|
remoteVideoTrack?.isEnabled = false
|
|
|
|
remoteVideoTrack = nil
|
|
|
|
|
|
|
|
dataChannel = nil
|
|
|
|
dataChannel = nil
|
|
|
|
audioSender = nil
|
|
|
|
audioSender = nil
|
|
|
|
|
|
|
|
audioTrack = nil
|
|
|
|
videoSender = nil
|
|
|
|
videoSender = nil
|
|
|
|
|
|
|
|
localVideoTrack = nil
|
|
|
|
|
|
|
|
remoteVideoTrack = nil
|
|
|
|
|
|
|
|
|
|
|
|
peerConnection.delegate = nil
|
|
|
|
peerConnection.delegate = nil
|
|
|
|
peerConnection.close()
|
|
|
|
peerConnection.close()
|
|
|
|
|
|
|
|
peerConnection = nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
delegate = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - Data Channel
|
|
|
|
// MARK: - Data Channel
|
|
|
@ -410,7 +473,10 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
AssertIsOnMainThread()
|
|
|
|
|
|
|
|
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
self.assertOnSignalingQueue()
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
guard let dataChannel = self.dataChannel else {
|
|
|
|
guard let dataChannel = self.dataChannel else {
|
|
|
|
Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel")
|
|
|
|
Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel")
|
|
|
@ -438,6 +504,10 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
/** The data channel successfully received a data buffer. */
|
|
|
|
/** The data channel successfully received a data buffer. */
|
|
|
|
internal func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
|
|
|
|
internal func dataChannel(_ dataChannel: RTCDataChannel, didReceiveMessageWith buffer: RTCDataBuffer) {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) dataChannel didReceiveMessageWith buffer:\(buffer)")
|
|
|
|
Logger.debug("\(self.TAG) dataChannel didReceiveMessageWith buffer:\(buffer)")
|
|
|
|
|
|
|
|
|
|
|
|
guard let dataChannelMessage = OWSWebRTCProtosData.parse(from:buffer.data) else {
|
|
|
|
guard let dataChannelMessage = OWSWebRTCProtosData.parse(from:buffer.data) else {
|
|
|
@ -447,8 +517,9 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
delegate.peerConnectionClient(self, received: dataChannelMessage)
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
|
|
|
|
delegate.peerConnectionClient(strongSelf, received: dataChannelMessage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -469,14 +540,20 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
/** Called when media is received on a new stream from remote peer. */
|
|
|
|
/** Called when media is received on a new stream from remote peer. */
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didAdd stream: RTCMediaStream) {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) didAdd stream:\(stream) video tracks: \(stream.videoTracks.count) audio tracks: \(stream.audioTracks.count)")
|
|
|
|
Logger.debug("\(self.TAG) didAdd stream:\(stream) video tracks: \(stream.videoTracks.count) audio tracks: \(stream.audioTracks.count)")
|
|
|
|
|
|
|
|
|
|
|
|
if stream.videoTracks.count > 0 {
|
|
|
|
if stream.videoTracks.count > 0 {
|
|
|
|
self.remoteVideoTrack = stream.videoTracks[0]
|
|
|
|
self.remoteVideoTrack = stream.videoTracks[0]
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
let remoteVideoTrack = self.remoteVideoTrack
|
|
|
|
let remoteVideoTrack = self.remoteVideoTrack
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async { [weak self, weak remoteVideoTrack] in
|
|
|
|
delegate.peerConnectionClient(self, didUpdateRemote: remoteVideoTrack)
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
|
|
|
|
guard let strongRemoteVideoTrack = remoteVideoTrack else { return }
|
|
|
|
|
|
|
|
delegate.peerConnectionClient(strongSelf, didUpdateRemote: strongRemoteVideoTrack)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -496,19 +573,25 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
/** Called any time the IceConnectionState changes. */
|
|
|
|
/** Called any time the IceConnectionState changes. */
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didChange newState: RTCIceConnectionState) {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) didChange IceConnectionState:\(newState.debugDescription)")
|
|
|
|
Logger.debug("\(self.TAG) didChange IceConnectionState:\(newState.debugDescription)")
|
|
|
|
switch newState {
|
|
|
|
switch newState {
|
|
|
|
case .connected, .completed:
|
|
|
|
case .connected, .completed:
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
delegate.peerConnectionClientIceConnected(self)
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
|
|
|
|
delegate.peerConnectionClientIceConnected(strongSelf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case .failed:
|
|
|
|
case .failed:
|
|
|
|
Logger.warn("\(self.TAG) RTCIceConnection failed.")
|
|
|
|
Logger.warn("\(self.TAG) RTCIceConnection failed.")
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
delegate.peerConnectionClientIceFailed(self)
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
|
|
|
|
delegate.peerConnectionClientIceFailed(strongSelf)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case .disconnected:
|
|
|
|
case .disconnected:
|
|
|
@ -527,10 +610,15 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
/** New ice candidate has been found. */
|
|
|
|
/** New ice candidate has been found. */
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didGenerate candidate: RTCIceCandidate) {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) didGenerate IceCandidate:\(candidate.sdp)")
|
|
|
|
Logger.debug("\(self.TAG) didGenerate IceCandidate:\(candidate.sdp)")
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
if let delegate = self.delegate {
|
|
|
|
DispatchQueue.main.async {
|
|
|
|
DispatchQueue.main.async { [weak self] in
|
|
|
|
delegate.peerConnectionClient(self, addedLocalIceCandidate: candidate)
|
|
|
|
guard let strongSelf = self else { return }
|
|
|
|
|
|
|
|
delegate.peerConnectionClient(strongSelf, addedLocalIceCandidate: candidate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -544,6 +632,10 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
/** New data channel has been opened. */
|
|
|
|
/** New data channel has been opened. */
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
|
|
|
|
internal func peerConnection(_ peerConnection: RTCPeerConnection, didOpen dataChannel: RTCDataChannel) {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
|
|
|
|
guard self.peerConnection != nil else {
|
|
|
|
|
|
|
|
Logger.debug("\(self.TAG) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) didOpen dataChannel:\(dataChannel)")
|
|
|
|
Logger.debug("\(self.TAG) didOpen dataChannel:\(dataChannel)")
|
|
|
|
assert(self.dataChannel == nil)
|
|
|
|
assert(self.dataChannel == nil)
|
|
|
|
self.dataChannel = dataChannel
|
|
|
|
self.dataChannel = dataChannel
|
|
|
|