|
|
@ -54,8 +54,14 @@ import Foundation
|
|
|
|
|
|
|
|
|
|
|
|
private func ensureIsEnabled(call: SignalCall) {
|
|
|
|
private func ensureIsEnabled(call: SignalCall) {
|
|
|
|
// Auto-enable speakerphone when local video is enabled.
|
|
|
|
// Auto-enable speakerphone when local video is enabled.
|
|
|
|
if call.isSpeakerphoneEnabled || call.hasLocalVideo {
|
|
|
|
if call.hasLocalVideo {
|
|
|
|
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord, options: .defaultToSpeaker)
|
|
|
|
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
|
|
|
|
|
|
|
|
mode: AVAudioSessionModeVideoChat,
|
|
|
|
|
|
|
|
options: .defaultToSpeaker)
|
|
|
|
|
|
|
|
} else if call.isSpeakerphoneEnabled {
|
|
|
|
|
|
|
|
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord,
|
|
|
|
|
|
|
|
mode: AVAudioSessionModeVoiceChat,
|
|
|
|
|
|
|
|
options: .defaultToSpeaker)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord)
|
|
|
|
setAudioSession(category: AVAudioSessionCategoryPlayAndRecord)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -178,11 +184,17 @@ import Foundation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: - AVAudioSession Helpers
|
|
|
|
private func setAudioSession(category: String,
|
|
|
|
|
|
|
|
mode: String,
|
|
|
|
private func setAudioSession(category: String, options: AVAudioSessionCategoryOptions) {
|
|
|
|
options: AVAudioSessionCategoryOptions) {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
try AVAudioSession.sharedInstance().setCategory(category, with: options)
|
|
|
|
if #available(iOS 10.0, *) {
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: options)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
AVAudioSession.sharedInstance().setCategory(category, with: options)
|
|
|
|
|
|
|
|
}
|
|
|
|
Logger.debug("\(self.TAG) set category: \(category) options: \(options)")
|
|
|
|
Logger.debug("\(self.TAG) set category: \(category) options: \(options)")
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
let message = "\(self.TAG) in \(#function) failed to set category: \(category) with error: \(error)"
|
|
|
|
let message = "\(self.TAG) in \(#function) failed to set category: \(category) with error: \(error)"
|
|
|
@ -192,13 +204,8 @@ import Foundation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private func setAudioSession(category: String) {
|
|
|
|
private func setAudioSession(category: String) {
|
|
|
|
do {
|
|
|
|
setAudioSession(category:category,
|
|
|
|
try AVAudioSession.sharedInstance().setCategory(category)
|
|
|
|
mode:AVAudioSessionModeVoiceChat,
|
|
|
|
Logger.debug("\(self.TAG) set category: \(category)")
|
|
|
|
options:AVAudioSessionCategoryOptions(rawValue: 0))
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
let message = "\(self.TAG) in \(#function) failed to set category: \(category) with error: \(error)"
|
|
|
|
|
|
|
|
assertionFailure(message)
|
|
|
|
|
|
|
|
Logger.error(message)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|