@ -77,8 +77,8 @@ enum CallError: Error {
case timeout ( description : String )
}
// FI X M E T O D O d o w e n e e d t o t i m e o u t ?
fileprivate let timeoutSeconds = 6 0
// Sh 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
fileprivate let connectingTimeoutSeconds = 12 0
// 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 {
@ -298,7 +298,7 @@ protocol CallServiceObserver: class {
return getIceServers ( ) . then { iceServers -> Promise < HardenedRTCSessionDescription > in
Logger . debug ( " \( self . TAG ) got ice servers: \( iceServers ) " )
let peerConnectionClient = PeerConnectionClient ( iceServers : iceServers , delegate : self , call Type : . outgoing )
let peerConnectionClient = PeerConnectionClient ( iceServers : iceServers , delegate : self , call Direction : . outgoing )
assert ( self . peerConnectionClient = = nil , " Unexpected PeerConnectionClient instance " )
Logger . debug ( " \( self . TAG ) setting peerConnectionClient in \( #function ) " )
@ -311,6 +311,17 @@ protocol CallServiceObserver: class {
let callMessage = OWSOutgoingCallMessage ( thread : thread , offerMessage : offerMessage )
return self . messageSender . sendCallMessage ( callMessage )
}
} . then {
let ( callConnectedPromise , fulfill , _ ) = Promise < Void > . pending ( )
self . fulfillCallConnectedPromise = fulfill
// 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
// 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
throw CallError . timeout ( description : " timed out waiting to receive call answer " )
}
return race ( timeout , callConnectedPromise )
} . catch { error in
Logger . error ( " \( self . TAG ) placing call failed with error: \( error ) " )
@ -456,7 +467,7 @@ protocol CallServiceObserver: class {
}
assert ( self . peerConnectionClient = = nil , " Unexpected PeerConnectionClient instance " )
Logger . debug ( " \( self . self . TAG ) setting peerConnectionClient in \( #function ) " )
self . peerConnectionClient = PeerConnectionClient ( iceServers : iceServers , delegate : self , call Type : . incoming )
self . peerConnectionClient = PeerConnectionClient ( iceServers : iceServers , delegate : self , call Direction : . incoming )
let offerSessionDescription = RTCSessionDescription ( type : . offer , sdp : callerSessionDescription )
let constraints = RTCMediaConstraints ( mandatoryConstraints : nil , optionalConstraints : nil )
@ -481,7 +492,7 @@ protocol CallServiceObserver: class {
let ( promise , fulfill , _ ) = Promise < Void > . pending ( )
let timeout : Promise < Void > = after ( interval : TimeInterval ( timeoutSeconds) ) . then { ( ) -> Void in
let timeout : Promise < Void > = after ( interval : TimeInterval ( connec tingT imeoutSeconds) ) . 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
throw CallError . timeout ( description : " timed out waiting for call to connect " )
}