Merge branch 'mkirk/calling-edgecases'

pull/1/head
Michael Kirk 8 years ago
commit bb22adbeba

@ -137,9 +137,8 @@ struct AudioSource: Hashable {
// `pulseDuration` is the small pause between the two vibrations in the pair.
private let pulseDuration = 0.2
static private let sharedAudioSession = CallAudioSession()
var audioSession: CallAudioSession {
return type(of: self).sharedAudioSession
return CallAudioSession.shared
}
// MARK: - Initializers
@ -249,12 +248,6 @@ struct AudioSource: Hashable {
} catch {
owsFail("\(TAG) failed setting audio source with error: \(error) isSpeakerPhoneEnabled: \(call.isSpeakerphoneEnabled)")
}
if call.state == .connected, !call.isOnHold {
audioSession.isRTCAudioEnabled = true
} else {
audioSession.isRTCAudioEnabled = false
}
}
// MARK: - Service action handlers

@ -17,6 +17,11 @@ import WebRTC
class CallAudioSession {
let TAG = "[CallAudioSession]"
// Force singleton access
static let shared = CallAudioSession()
private init() {}
/**
* The private class that manages AVAudioSession for WebRTC
*/
@ -33,7 +38,7 @@ class CallAudioSession {
/**
* Because we useManualAudio with our RTCAudioSession, we have to start/stop the recording audio session ourselves.
* Else, we start recording before the next call is ringing.
* See header for details on manual audio.
*/
var isRTCAudioEnabled: Bool {
get {

@ -991,8 +991,10 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread()
guard let currentCall = self.call else {
OWSProdError(OWSAnalyticsEvents.callServiceCallMissing(), file: #file, function: #function, line: #line)
handleFailedCall(failedCall: call, error: CallError.assertionError(description: "\(TAG) ignoring \(#function) since there is no current call"))
Logger.info("\(TAG) in \(#function), but no current call. Other party hung up just before us.")
// terminating the call might be redundant, but it shouldn't hurt.
terminateCall()
return
}
@ -1578,7 +1580,7 @@ protocol CallServiceObserver: class {
self.peerConnectionClient?.setLocalVideoEnabled(enabled: shouldHaveLocalVideoTrack)
let message = DataChannelMessage.forVideoStreamingStatus(callId: call.signalingId, enabled: shouldHaveLocalVideoTrack)
peerConnectionClient.sendDataChannelMessage(data: message.asData(), description: "videoStreamingStatus")
peerConnectionClient.sendDataChannelMessage(data: message.asData(), description: "videoStreamingStatus", isCritical: false)
}
// MARK: - Observers

@ -81,6 +81,7 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
return
}
CallAudioSession.shared.isRTCAudioEnabled = true
self.callService.handleAnswerCall(call)
}
@ -113,7 +114,8 @@ class NonCallKitCallUIAdaptee: CallUIAdaptee {
func recipientAcceptedCall(_ call: SignalCall) {
AssertIsOnMainThread()
// no-op
CallAudioSession.shared.isRTCAudioEnabled = true
}
func localHangupCall(_ call: SignalCall) {

@ -359,7 +359,11 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
}
Logger.verbose("\(self.TAG) setting local session description: \(sessionDescription)")
self.peerConnection.setLocalDescription(sessionDescription.rtcSessionDescription,
completionHandler: { _ in
completionHandler: { error in
guard error == nil else {
reject(error!)
return
}
fulfill()
})
}
@ -387,7 +391,11 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
}
Logger.verbose("\(self.TAG) setting remote description: \(sessionDescription)")
self.peerConnection.setRemoteDescription(sessionDescription,
completionHandler: { _ in
completionHandler: { error in
guard error == nil else {
reject(error!)
return
}
fulfill()
})
}
@ -501,7 +509,15 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
// MARK: - Data Channel
public func sendDataChannelMessage(data: Data, description: String, isCritical: Bool = false) {
// should only be accessed on PeerConnectionClient.signalingQueue
var pendingDataChannelMessages: [PendingDataChannelMessage] = []
struct PendingDataChannelMessage {
let data: Data
let description: String
let isCritical: Bool
}
public func sendDataChannelMessage(data: Data, description: String, isCritical: Bool) {
AssertIsOnMainThread()
PeerConnectionClient.signalingQueue.async {
@ -511,7 +527,12 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
}
guard let dataChannel = self.dataChannel else {
Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel: \(description)")
if isCritical {
Logger.info("\(self.TAG) in \(#function) enqueuing critical data channel message for after we have a dataChannel: \(description)")
self.pendingDataChannelMessages.append(PendingDataChannelMessage(data: data, description: description, isCritical: isCritical))
} else {
Logger.error("\(self.TAG) in \(#function) ignoring sending \(data) for nil dataChannel: \(description)")
}
return
}
@ -697,6 +718,16 @@ class PeerConnectionClient: NSObject, RTCPeerConnectionDelegate, RTCDataChannelD
assert(self.dataChannel == nil)
self.dataChannel = dataChannel
dataChannel.delegate = self
let pendingMessages = self.pendingDataChannelMessages
self.pendingDataChannelMessages = []
DispatchQueue.main.async { [weak self] in
guard let strongSelf = self else { return }
pendingMessages.forEach { message in
strongSelf.sendDataChannelMessage(data: message.data, description: message.description, isCritical: message.isCritical)
}
}
}
}

@ -341,17 +341,14 @@ final class CallKitCallUIAdaptee: NSObject, CallUIAdaptee, CXProviderDelegate {
Logger.debug("\(TAG) Received \(#function)")
// Audio Session is managed by CallAudioService, which observes changes on the
// SignalCall directly.
CallAudioSession.shared.isRTCAudioEnabled = true
}
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
AssertIsOnMainThread()
Logger.debug("\(TAG) Received \(#function)")
// Audio Session is managed by CallAudioService, which observes changes on the
// SignalCall directly.
CallAudioSession.shared.isRTCAudioEnabled = false
}
// MARK: - Util

Loading…
Cancel
Save