@ -11,6 +11,11 @@ import PromiseKit
private let TAG = " [CallAudioService] "
private var vibrateTimer : Timer ?
private let audioManager = AppAudioManager . sharedInstance ( )
private let soundPlayer = JSQSystemSoundPlayer . shared ( ) !
enum SoundFilenames : String {
case incomingRing = " r "
}
// M a r k : V i b r a t i o n c o n f i g
private let vibrateRepeatDuration = 1.6
@ -59,9 +64,9 @@ import PromiseKit
private func handleLocalRinging ( ) {
Logger . debug ( " \( TAG ) \( #function ) " )
audioManager . setAudioEnabled ( true )
audioManager. handleInboundRing ( )
vibrateTimer = Timer . scheduledTimer ( timeInterval : vibrateRepeatDuration , target : self , selector : #selector ( vibrate ) , userInfo : nil , repeats : true )
vibrateTimer = Timer . scheduledTimer ( timeInterval : vibrateRepeatDuration , target : self , selector : #selector ( ringVibration ) , userInfo : nil , repeats : true )
soundPlayer. playSound ( withFilename : SoundFilenames . incomingRing . rawValue , fileExtension : kJSQSystemSoundTypeCAF )
}
private func handleConnected ( ) {
@ -96,18 +101,18 @@ import PromiseKit
// MARK: H e l p e r s
private func stopRinging ( ) {
// D i s a b l e s e x t e r n a l s p e a k e r u s e d f o r r i n g i n g , u n l e s s u s e r e n a b l e s s p e a k e r p h o n e .
audioManager . setDefaultAudioProfile ( )
audioManager . cancelAllAudio ( )
vibrateTimer ? . invalidate ( )
vibrateTimer = nil
soundPlayer . stopSound ( withFilename : SoundFilenames . incomingRing . rawValue )
}
public func vibrate ( ) {
AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate )
public func ringVibration ( ) {
// S i n c e a c a l l n o t i f i c a t i o n i s m o r e u r g e n t t h a n a m e s s a g e n o t i f a c t i o n , w e
// v i b r a t e t w i c e , l i k e a p u l s e , t o d i f f e r e n t i a t e f r o m a n o r m a l n o t i f i c a t i o n v i b r a t i o n .
soundPlayer . playVibrateSound ( )
DispatchQueue . default . asyncAfter ( deadline : DispatchTime . now ( ) + pulseDuration ) {
AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate )
self . soundPlayer . playVibrateSound ( )
}
}
}