@ -79,7 +79,7 @@ enum CallError: Error {
}
// S h o u l d b e r o u g h l y s y n c e d w i t h A n d r o i d c l i e n t f o r c o n s i s t e n c y
private let connectingTimeoutSeconds = 120
private let connectingTimeoutSeconds : TimeInterval = 120
// A l l O b s e r v e r m e t h o d s w i l l b e i n v o k e d f r o m t h e m a i n t h r e a d .
protocol CallServiceObserver : class {
@ -338,7 +338,7 @@ protocol CallServiceObserver: class {
self . rejectCallConnectedPromise = reject
// D o n ' t l e t t h e o u t g o i n g c a l l r i n g f o r e v e r . W e d o n ' t s u p p o r t i n b o u n d r i n g i n g f o r e v e r a n y w a y .
let timeout : Promise < Void > = after ( interval : TimeInterval( connectingTimeoutSeconds) ) . then { ( ) -> Void in
let timeout : Promise < Void > = after ( interval : connectingTimeoutSeconds) . then { ( ) -> Void in
// r e j e c t i n g a p r o m i s e b y t h r o w i n g i s s a f e l y a n o - o p i f t h e p r o m i s e h a s a l r e a d y b e e n f u l f i l l e d
OWSProdInfo ( OWSAnalyticsEvents . callServiceErrorTimeoutWhileConnectingOutgoing ( ) , file : #file , function : #function , line : #line )
throw CallError . timeout ( description : " timed out waiting to receive call answer " )
@ -441,7 +441,7 @@ protocol CallServiceObserver: class {
/* *
* User didn ' t answer incoming call
*/
public func handleMissedCall ( _ call : SignalCall , thread : TSContactThread ) {
public func handleMissedCall ( _ call : SignalCall ) {
AssertIsOnMainThread ( )
// I n s e r t m i s s e d c a l l r e c o r d
@ -451,9 +451,9 @@ protocol CallServiceObserver: class {
}
} else {
call . callRecord = TSCall ( timestamp : NSDate . ows_millisecondTimeStamp ( ) ,
withCallNumber : thread. contactIdentifier ( ) ,
withCallNumber : call. thread. contactIdentifier ( ) ,
callType : RPRecentCallTypeMissed ,
in : thread)
in : call. thread)
}
assert ( call . callRecord != nil )
@ -465,16 +465,16 @@ protocol CallServiceObserver: class {
/* *
* Received a call while already in another call .
*/
private func handleLocalBusyCall ( _ call : SignalCall , thread : TSContactThread ) {
Logger . info ( " \( TAG ) \( #function ) for call: \( call . identifiersForLogs ) thread: \( thread. contactIdentifier ( ) ) " )
private func handleLocalBusyCall ( _ call : SignalCall ) {
Logger . info ( " \( TAG ) \( #function ) for call: \( call . identifiersForLogs ) thread: \( call. thread. contactIdentifier ( ) ) " )
AssertIsOnMainThread ( )
let busyMessage = OWSCallBusyMessage ( callId : call . signalingId )
let callMessage = OWSOutgoingCallMessage ( thread : thread, busyMessage : busyMessage )
let callMessage = OWSOutgoingCallMessage ( thread : call. thread, busyMessage : busyMessage )
let sendPromise = messageSender . sendPromise ( message : callMessage )
sendPromise . retainUntilComplete ( )
handleMissedCall ( call , thread : thread )
handleMissedCall ( call )
}
/* *
@ -551,7 +551,7 @@ protocol CallServiceObserver: class {
// T O D O o n i O S 1 0 + w e c a n u s e C a l l K i t t o s w a p c a l l s r a t h e r t h a n j u s t r e t u r n i n g b u s y i m m e d i a t e l y .
Logger . info ( " \( TAG ) receivedCallOffer: \( newCall . identifiersForLogs ) but we're already in call: \( existingCall . identifiersForLogs ) " )
handleLocalBusyCall ( newCall , thread : thread )
handleLocalBusyCall ( newCall )
if existingCall . remotePhoneNumber = = newCall . remotePhoneNumber {
Logger . info ( " \( TAG ) handling call from current call user as remote busy.: \( newCall . identifiersForLogs ) but we're already in call: \( existingCall . identifiersForLogs ) " )
@ -642,7 +642,7 @@ protocol CallServiceObserver: class {
let ( promise , fulfill , reject ) = Promise < Void > . pending ( )
let timeout : Promise < Void > = after ( interval : TimeInterval( connectingTimeoutSeconds) ) . then { ( ) -> Void in
let timeout : Promise < Void > = after ( interval : connectingTimeoutSeconds) . then { ( ) -> Void in
// r e j e c t i n g a p r o m i s e b y t h r o w i n g i s s a f e l y a n o - o p i f t h e p r o m i s e h a s a l r e a d y b e e n f u l f i l l e d
OWSProdInfo ( OWSAnalyticsEvents . callServiceErrorTimeoutWhileConnectingIncoming ( ) , file : #file , function : #function , line : #line )
throw CallError . timeout ( description : " timed out waiting for call to connect " )
@ -824,7 +824,7 @@ protocol CallServiceObserver: class {
switch call . state {
case . idle , . dialing , . answering , . localRinging , . localFailure , . remoteBusy , . remoteRinging :
handleMissedCall ( call , thread : thread )
handleMissedCall ( call )
case . connected , . localHangup , . remoteHangup :
Logger . info ( " \( TAG ) call is finished. " )
}
@ -1403,6 +1403,14 @@ protocol CallServiceObserver: class {
}
if let failedCall = failedCall {
if failedCall . state = = . answering {
assert ( failedCall . callRecord = = nil )
// c a l l f a i l e d b e f o r e a n y c a l l r e c o r d c o u l d b e c r e a t e d , m a k e o n e n o w .
handleMissedCall ( failedCall )
}
assert ( failedCall . callRecord != nil )
// I t ' s e s s e n t i a l t o s e t c a l l . s t a t e b e f o r e t e r m i n a t e C a l l , b e c a u s e t e r m i n a t e C a l l n i l s s e l f . c a l l
failedCall . error = error
failedCall . state = . localFailure