use new api configure audio session

This commit is contained in:
Danmei Chen 2021-03-23 12:36:59 +01:00
parent 7f436ecf40
commit b5df5110d3
2 changed files with 2 additions and 13 deletions

View file

@ -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!")

View file

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