From 30b50e1489d3532d6c4840f7d3ad467dcdbb76bb Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 20 Nov 2017 12:07:31 -0500 Subject: [PATCH] Activate audio at the proper time // FREEBIE --- Signal/src/call/CallAudioService.swift | 9 +-------- Signal/src/call/CallAudioSession.swift | 7 ++++++- Signal/src/call/NonCallKitCallUIAdaptee.swift | 4 +++- Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift | 7 ++----- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Signal/src/call/CallAudioService.swift b/Signal/src/call/CallAudioService.swift index ccd30874c..1585befbc 100644 --- a/Signal/src/call/CallAudioService.swift +++ b/Signal/src/call/CallAudioService.swift @@ -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 diff --git a/Signal/src/call/CallAudioSession.swift b/Signal/src/call/CallAudioSession.swift index 36b35614f..4d5d9c9bb 100644 --- a/Signal/src/call/CallAudioSession.swift +++ b/Signal/src/call/CallAudioSession.swift @@ -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 { diff --git a/Signal/src/call/NonCallKitCallUIAdaptee.swift b/Signal/src/call/NonCallKitCallUIAdaptee.swift index a05adf41f..cf225e255 100644 --- a/Signal/src/call/NonCallKitCallUIAdaptee.swift +++ b/Signal/src/call/NonCallKitCallUIAdaptee.swift @@ -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) { diff --git a/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift b/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift index 528ab0c7e..83a9fa41b 100644 --- a/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift +++ b/Signal/src/call/Speakerbox/CallKitCallUIAdaptee.swift @@ -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