Activate audio at the proper time

// FREEBIE
This commit is contained in:
Michael Kirk 2017-11-20 12:07:31 -05:00
parent 81f097c1f5
commit 30b50e1489
4 changed files with 12 additions and 15 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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) {

View File

@ -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