Fix Bluetooth audio in calls.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-05-15 11:08:24 -04:00
parent de1332479c
commit 7e18052c45

View file

@ -98,14 +98,15 @@ import AVFoundation
if call.hasLocalVideo {
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVideoChat,
options: .defaultToSpeaker)
options: [.defaultToSpeaker])
} else if call.isSpeakerphoneEnabled {
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVoiceChat,
options: .defaultToSpeaker)
options: [.defaultToSpeaker])
} else {
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVoiceChat)
mode: AVAudioSessionModeVoiceChat,
options: [.allowBluetooth])
}
}
@ -150,7 +151,7 @@ import AVFoundation
} else {
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVoiceChat,
options: .mixWithOthers)
options: [.mixWithOthers, .allowBluetooth])
}
// HACK: Without this async, dialing sound only plays once. I don't really understand why. Does the audioSession
@ -299,6 +300,8 @@ import AVFoundation
private func setAudioSession(category: String,
mode: String? = nil,
options: AVAudioSessionCategoryOptions = AVAudioSessionCategoryOptions(rawValue: 0)) {
assert(Thread.isMainThread)
do {
if #available(iOS 10.0, *), let mode = mode {
try AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: options)