@ -137,10 +137,20 @@ struct AudioSource: Hashable {
// ` p u l s e D u r a t i o n ` i s t h e s m a l l p a u s e b e t w e e n t h e t w o v i b r a t i o n s i n t h e p a i r .
private let pulseDuration = 0.2
static private let sharedAudioSession = CallAudioSession ( )
var audioSession : CallAudioSession {
return type ( of : self ) . sharedAudioSession
}
// MARK: - I n i t i a l i z e r s
init ( handleRinging : Bool ) {
self . handleRinging = handleRinging
super . init ( )
// C o n f i g u r e a u d i o s e s s i o n s o w e d o n ' t p r o m p t u s e r w i t h R e c o r d p e r m i s s i o n u n t i l c a l l i s c o n n e c t e d .
audioSession . configure ( )
}
// MARK: - C a l l O b s e r v e r
@ -152,7 +162,14 @@ struct AudioSource: Hashable {
internal func muteDidChange ( call : SignalCall , isMuted : Bool ) {
AssertIsOnMainThread ( )
Logger . verbose ( " \( TAG ) in \( #function ) is no-op " )
ensureProperAudioSession ( call : call )
}
internal func holdDidChange ( call : SignalCall , isOnHold : Bool ) {
AssertIsOnMainThread ( )
ensureProperAudioSession ( call : call )
}
internal func audioSourceDidChange ( call : SignalCall , audioSource : AudioSource ? ) {
@ -219,7 +236,7 @@ struct AudioSource: Hashable {
try session . setPreferredInput ( call . audioSource ? . portDescription )
}
if call . isSpeakerphoneEnabled || ( call . hasLocalVideo && call . state != . connected ) {
if call . isSpeakerphoneEnabled || ( call . hasLocalVideo && call . state != . connected ) {
// W e w a n t c o n s i s t e n t r i n g e r - v o l u m e b e t w e e n s p e a k e r - p h o n e a n d v i d e o c h a t .
// B u t b e c a u s e u s i n g V i d e o C h a t m o d e h a s n o t i c e a b l y h i g h e r o u t p u t g a i n , w e t r e a t
// v i d e o c h a t l i k e s p e a k e r p h o n e m o d e u n t i l t h e c a l l i s c o n n e c t e d .
@ -232,6 +249,12 @@ struct AudioSource: Hashable {
} catch {
owsFail ( " \( TAG ) failed setting audio source with error: \( error ) isSpeakerPhoneEnabled: \( call . isSpeakerphoneEnabled ) " )
}
if call . state = = . connected , ! call . isOnHold {
audioSession . isRTCAudioEnabled = true
} else {
audioSession . isRTCAudioEnabled = false
}
}
// MARK: - S e r v i c e a c t i o n h a n d l e r s
@ -290,7 +313,6 @@ struct AudioSource: Hashable {
Logger . debug ( " \( TAG ) \( #function ) " )
AssertIsOnMainThread ( )
// F I X M E i f y o u t o g g l e d s p e a k e r p h o n e b e f o r e t h i s p o i n t , t h e o u t g o i n g r i n g d o e s n o t p l a y t h r o u g h s p e a k e r . W h y ?
self . play ( sound : Sound . outgoingRing )
}