From b5df5110d37ce6b1e58fb2699a94df8f3baa288f Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Tue, 23 Mar 2021 12:36:59 +0100 Subject: [PATCH] use new api configure audio session --- Classes/CallManager.swift | 12 ------------ Classes/ProviderDelegate.swift | 3 ++- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Classes/CallManager.swift b/Classes/CallManager.swift index 420c7fe1e..6f1162f6f 100644 --- a/Classes/CallManager.swift +++ b/Classes/CallManager.swift @@ -332,18 +332,6 @@ import AVFoundation providerDelegate.uuids.removeAll() } - // To be removed. - static func configAudioSession(audioSession: AVAudioSession) { - do { - try audioSession.setCategory(AVAudioSession.Category.playAndRecord, mode: AVAudioSession.Mode.voiceChat, options: AVAudioSession.CategoryOptions(rawValue: AVAudioSession.CategoryOptions.allowBluetooth.rawValue | AVAudioSession.CategoryOptions.allowBluetoothA2DP.rawValue)) - try audioSession.setMode(AVAudioSession.Mode.voiceChat) - try audioSession.setPreferredSampleRate(48000.0) - try AVAudioSession.sharedInstance().setActive(true, options: []) - } catch { - Log.directLog(BCTBX_LOG_WARNING, text: "CallKit: Unable to config audio session because : \(error)") - } - } - @objc func terminateCall(call: OpaquePointer?) { if (call == nil) { Log.directLog(BCTBX_LOG_ERROR, text: "Can not terminate null call!") diff --git a/Classes/ProviderDelegate.swift b/Classes/ProviderDelegate.swift index 1b7fdd467..c57a005af 100644 --- a/Classes/ProviderDelegate.swift +++ b/Classes/ProviderDelegate.swift @@ -174,9 +174,9 @@ extension ProviderDelegate: CXProviderDelegate { Log.directLog(BCTBX_LOG_MESSAGE, text: "CallKit: answer call with call-id: \(String(describing: callId)) and UUID: \(uuid.description).") let call = CallManager.instance().callByCallId(callId: callId) + CallManager.instance().lc?.configureAudioSession() if (call == nil || call?.state != Call.State.IncomingReceived) { // The application is not yet registered or the call is not yet received, mark the call as accepted. The audio session must be configured here. - CallManager.configAudioSession(audioSession: AVAudioSession.sharedInstance()) callInfo?.accepted = true callInfos.updateValue(callInfo!, forKey: uuid) CallManager.instance().providerDelegate.endCallNotExist(uuid: uuid, timeout: .now() + 10) @@ -242,6 +242,7 @@ extension ProviderDelegate: CXProviderDelegate { action.fail() } + CallManager.instance().lc?.configureAudioSession() try CallManager.instance().doCall(addr: addr!, isSas: callInfo?.sasEnabled ?? false) } catch { Log.directLog(BCTBX_LOG_ERROR, text: "CallKit: Call started failed because \(error)")