@ -96,19 +96,21 @@ import AVFoundation
if call . state = = . localRinging {
if call . state = = . localRinging {
// S o l o A m b i e n t p l a y s t h r o u g h s p e a k e r , b u t r e s p e c t s s i l e n t s w i t c h
// S o l o A m b i e n t p l a y s t h r o u g h s p e a k e r , b u t r e s p e c t s s i l e n t s w i t c h
setAudioSession ( category : AVAudioSessionCategorySoloAmbient )
setAudioSession ( category : AVAudioSessionCategorySoloAmbient ,
mode : AVAudioSessionModeDefault )
} else if call . hasLocalVideo {
} else if call . hasLocalVideo {
// A u t o - e n a b l e s p e a k e r p h o n e w h e n l o c a l v i d e o i s e n a b l e d .
// A u t o - e n a b l e s p e a k e r p h o n e w h e n l o c a l v i d e o i s e n a b l e d .
setAudioSession ( category : AVAudioSessionCategoryPlayAndRecord ,
setAudioSession ( category : AVAudioSessionCategoryPlayAndRecord ,
mode : AVAudioSessionModeVideoChat ,
mode : AVAudioSessionModeVideoChat ,
options : .defaultToSpeaker )
options : [ .defaultToSpeaker , . allowBluetooth ] )
} else if call . isSpeakerphoneEnabled {
} else if call . isSpeakerphoneEnabled {
setAudioSession ( category : AVAudioSessionCategoryPlayAndRecord ,
setAudioSession ( category : AVAudioSessionCategoryPlayAndRecord ,
mode : AVAudioSessionModeVoiceChat ,
mode : AVAudioSessionModeVoiceChat ,
options : .defaultToSpeaker )
options : [ .defaultToSpeaker , . allowBluetooth ] )
} else {
} else {
setAudioSession ( category : AVAudioSessionCategoryPlayAndRecord ,
setAudioSession ( category : AVAudioSessionCategoryPlayAndRecord ,
mode : AVAudioSessionModeVoiceChat )
mode : AVAudioSessionModeVoiceChat ,
options : [ . allowBluetooth ] )
}
}
}
}
@ -315,19 +317,46 @@ import AVFoundation
let session = AVAudioSession . sharedInstance ( )
let session = AVAudioSession . sharedInstance ( )
do {
do {
if #available ( iOS 10.0 , * ) , let mode = mode {
if #available ( iOS 10.0 , * ) , let mode = mode {
if session . category = = category , session . mode = = mode , session . categoryOptions = = options {
let oldCategory = session . category
Logger . debug ( " \( self . TAG ) in \( #function ) ignoring no-op " )
let oldMode = session . mode
let oldOptions = session . categoryOptions
if oldCategory = = category , oldMode = = mode , oldOptions = = options {
Logger . debug ( " \( self . TAG ) in \( #function ) doing nothing, since audio session is unchanged. " )
return
return
}
}
if oldCategory != category {
Logger . debug ( " \( self . TAG ) audio session changed category: \( oldCategory ) -> \( category ) " )
}
if oldMode != mode {
Logger . debug ( " \( self . TAG ) audio session changed mode: \( oldMode ) -> \( mode ) " )
}
if oldOptions != options {
Logger . debug ( " \( self . TAG ) audio session changed category: \( oldOptions ) -> \( options ) " )
}
Logger . debug ( " \( self . TAG ) setting new category: \( category ) mode: \( mode ) options: \( options ) " )
try session . setCategory ( category , mode : mode , options : options )
try session . setCategory ( category , mode : mode , options : options )
Logger . debug ( " \( self . TAG ) set category: \( category ) mode: \( mode ) options: \( options ) " )
} else {
} else {
let oldCategory = session . category
let oldOptions = session . categoryOptions
if session . category = = category , session . categoryOptions = = options {
if session . category = = category , session . categoryOptions = = options {
Logger . debug ( " \( self . TAG ) in \( #function ) ignoring no-op " )
Logger . debug ( " \( self . TAG ) in \( #function ) doing nothing, since audio session is unchanged. " )
return
return
}
}
if oldCategory != category {
Logger . debug ( " \( self . TAG ) audio session changed category: \( oldCategory ) -> \( category ) " )
}
if oldOptions != options {
Logger . debug ( " \( self . TAG ) audio session changed category: \( oldOptions ) -> \( options ) " )
}
Logger . debug ( " \( self . TAG ) setting new category: \( category ) options: \( options ) " )
try session . setCategory ( category , with : options )
try session . setCategory ( category , with : options )
Logger . debug ( " \( self . TAG ) set category: \( category ) options: \( options ) " )
}
}
} catch {
} catch {
let message = " \( self . TAG ) in \( #function ) failed to set category: \( category ) mode: \( String ( describing : mode ) ) , options: \( options ) with error: \( error ) "
let message = " \( self . TAG ) in \( #function ) failed to set category: \( category ) mode: \( String ( describing : mode ) ) , options: \( options ) with error: \( error ) "