|
|
@ -58,7 +58,7 @@ protocol PeerConnectionClientDelegate: class {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Fired whenever the local video track become active or inactive.
|
|
|
|
* Fired whenever the local video track become active or inactive.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocalVideoTrack videoTrack: RTCVideoTrack?, captureSession: AVCaptureSession?)
|
|
|
|
func peerConnectionClient(_ peerconnectionClient: PeerConnectionClient, didUpdateLocalVideoCaptureSession captureSession: AVCaptureSession?)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Fired whenever the remote video track become active or inactive.
|
|
|
|
* Fired whenever the remote video track become active or inactive.
|
|
|
@ -235,12 +235,12 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
private var videoCaptureController: VideoCaptureController?
|
|
|
|
private var videoCaptureController: VideoCaptureController?
|
|
|
|
private var videoCaptureSession: AVCaptureSession?
|
|
|
|
private var videoCaptureSession: AVCaptureSession?
|
|
|
|
private var videoSender: RTCRtpSender?
|
|
|
|
private var videoSender: RTCRtpSender?
|
|
|
|
private var localVideoTrack: RTCVideoTrack?
|
|
|
|
|
|
|
|
private var localVideoSource: RTCVideoSource?
|
|
|
|
private var localVideoSource: RTCVideoSource?
|
|
|
|
|
|
|
|
|
|
|
|
// RTCVideoTrack is fragile and prone to throwing exceptions and/or
|
|
|
|
// RTCVideoTrack is fragile and prone to throwing exceptions and/or
|
|
|
|
// causing deadlock in its destructor. Therefore we take great care
|
|
|
|
// causing deadlock in its destructor. Therefore we take great care
|
|
|
|
// with this property.
|
|
|
|
// with this property.
|
|
|
|
|
|
|
|
private var localVideoTrack: RTCVideoTrack?
|
|
|
|
private var remoteVideoTrack: RTCVideoTrack?
|
|
|
|
private var remoteVideoTrack: RTCVideoTrack?
|
|
|
|
private var cameraConstraints: RTCMediaConstraints
|
|
|
|
private var cameraConstraints: RTCMediaConstraints
|
|
|
|
|
|
|
|
|
|
|
@ -347,7 +347,6 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
|
|
|
|
|
|
|
|
let localVideoTrack = factory.videoTrack(with: videoSource, trackId: Identifiers.videoTrack.rawValue)
|
|
|
|
let localVideoTrack = factory.videoTrack(with: videoSource, trackId: Identifiers.videoTrack.rawValue)
|
|
|
|
self.localVideoTrack = localVideoTrack
|
|
|
|
self.localVideoTrack = localVideoTrack
|
|
|
|
|
|
|
|
|
|
|
|
self.videoCaptureController = VideoCaptureController(capturer: capturer, settingsDelegate: self)
|
|
|
|
self.videoCaptureController = VideoCaptureController(capturer: capturer, settingsDelegate: self)
|
|
|
|
|
|
|
|
|
|
|
|
// Disable by default until call is connected.
|
|
|
|
// Disable by default until call is connected.
|
|
|
@ -385,14 +384,12 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
guard let strongSelf = proxyCopy.get() else { return }
|
|
|
|
guard let strongSelf = proxyCopy.get() else { return }
|
|
|
|
|
|
|
|
|
|
|
|
// Should these really be guards? Don't we want to pass nil when it's been disabled?
|
|
|
|
// Should these really be guards? Don't we want to pass nil when it's been disabled?
|
|
|
|
guard let localVideoTrack = strongSelf.localVideoTrack else { return }
|
|
|
|
|
|
|
|
guard let videoCaptureSession = strongSelf.videoCaptureSession else { return }
|
|
|
|
guard let videoCaptureSession = strongSelf.videoCaptureSession else { return }
|
|
|
|
guard let strongDelegate = strongSelf.delegate else { return }
|
|
|
|
guard let strongDelegate = strongSelf.delegate else { return }
|
|
|
|
|
|
|
|
|
|
|
|
let videoTrack = enabled ? localVideoTrack : nil
|
|
|
|
|
|
|
|
let captureSession = enabled ? videoCaptureSession : nil
|
|
|
|
let captureSession = enabled ? videoCaptureSession : nil
|
|
|
|
|
|
|
|
|
|
|
|
strongDelegate.peerConnectionClient(strongSelf, didUpdateLocalVideoTrack: videoTrack, captureSession: captureSession)
|
|
|
|
strongDelegate.peerConnectionClient(strongSelf, didUpdateLocalVideoCaptureSession: captureSession)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
|
PeerConnectionClient.signalingQueue.async {
|
|
|
@ -401,29 +398,24 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
|
|
|
|
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard let localVideoTrack = strongSelf.localVideoTrack else {
|
|
|
|
|
|
|
|
|
|
|
|
guard let videoCaptureController = strongSelf.videoCaptureController else {
|
|
|
|
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// guard let videoCaptureSession = strongSelf.videoCaptureSession else {
|
|
|
|
|
|
|
|
// Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
|
|
|
|
// return
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let videoCaptureController = strongSelf.videoCaptureController else {
|
|
|
|
guard let localVideoTrack = strongSelf.localVideoTrack else {
|
|
|
|
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
Logger.debug("\(strongSelf.logTag) \(#function) Ignoring obsolete event in terminated client")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
localVideoTrack.isEnabled = enabled
|
|
|
|
localVideoTrack.isEnabled = enabled
|
|
|
|
|
|
|
|
|
|
|
|
if enabled {
|
|
|
|
if enabled {
|
|
|
|
Logger.debug("\(strongSelf.logTag) in \(#function) starting videoCaptureSession")
|
|
|
|
Logger.debug("\(strongSelf.logTag) in \(#function) starting video capture")
|
|
|
|
videoCaptureController.startCapture()
|
|
|
|
videoCaptureController.startCapture()
|
|
|
|
// videoCaptureSession.startRunning()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Logger.debug("\(strongSelf.logTag) in \(#function) stopping videoCaptureSession")
|
|
|
|
Logger.debug("\(strongSelf.logTag) in \(#function) stopping video capture")
|
|
|
|
videoCaptureController.stopCapture()
|
|
|
|
videoCaptureController.stopCapture()
|
|
|
|
// videoCaptureSession.stopRunning()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DispatchQueue.main.async(execute: completion)
|
|
|
|
DispatchQueue.main.async(execute: completion)
|
|
|
|