@ -130,8 +130,6 @@ protocol CallServiceObserver: class {
}
}
// T O D O c o d e c l e a n u p : m o v e t h r e a d i n t o S i g n a l C a l l ? O r r e f a c t o r m e s s a g e S e n d e r t o t a k e S i g n a l R e c i p i e n t i d e n t i f i e r .
var thread : TSContactThread ?
var call : SignalCall ? {
didSet {
AssertIsOnMainThread ( )
@ -142,7 +140,7 @@ protocol CallServiceObserver: class {
updateIsVideoEnabled ( )
updateLockTimerEnabling ( )
Logger . debug ( " \( self . TAG ) .call setter: \( oldValue != nil ) -> \( call != nil ) \( String ( describing : call ) ) " )
Logger . debug ( " \( self . TAG ) .call setter: \( oldValue ? . debugString as Optional ) -> \( call ? . debugString as Optional ) " )
for observer in observers {
observer . value ? . didUpdateCall ( call : call )
@ -161,9 +159,6 @@ protocol CallServiceObserver: class {
var sendIceUpdatesImmediately = true
var pendingIceUpdateMessages = [ OWSCallIceUpdateMessage ] ( )
// e n s u r e t h e i n c o m i n g c a l l p r o m i s e i s n ' t d e a l l o c ' d p r e m a t u r e l y
var incomingCallPromise : Promise < Void > ?
// U s e d t o c o o r d i n a t e p r o m i s e s a c r o s s d e l e g a t e m e t h o d s
var fulfillCallConnectedPromise : ( ( ) -> Void ) ?
@ -265,18 +260,15 @@ protocol CallServiceObserver: class {
self . call = call
let thread = TSContactThread . getOrCreateThread ( contactId : call . remotePhoneNumber )
self . thread = thread
sendIceUpdatesImmediately = false
pendingIceUpdateMessages = [ ]
let callRecord = TSCall ( timestamp : NSDate . ows_millisecondTimeStamp ( ) , withCallNumber : call . remotePhoneNumber , callType : RPRecentCallTypeOutgoingIncomplete , in : thread)
let callRecord = TSCall ( timestamp : NSDate . ows_millisecondTimeStamp ( ) , withCallNumber : call . remotePhoneNumber , callType : RPRecentCallTypeOutgoingIncomplete , in : call. thread)
callRecord . save ( )
call . callRecord = callRecord
return getIceServers ( ) . then { iceServers -> Promise < HardenedRTCSessionDescription > in
Logger . debug ( " \( self . TAG ) got ice servers: \( iceServers ) ")
let promise = getIceServers ( ) . then { iceServers -> Promise < HardenedRTCSessionDescription > in
Logger . debug ( " \( self . TAG ) got ice servers: \( iceServers ) for call: \( call . debugString ) ")
guard self . call = = call else {
throw CallError . obsoleteCall ( description : " obsolete call in \( #function ) " )
@ -291,7 +283,7 @@ protocol CallServiceObserver: class {
let useTurnOnly = Environment . getCurrent ( ) . preferences . doCallsHideIPAddress ( )
let peerConnectionClient = PeerConnectionClient ( iceServers : iceServers , delegate : self , callDirection : . outgoing , useTurnOnly : useTurnOnly )
Logger . debug ( " \( self . TAG ) setting peerConnectionClient in \( #function ) ")
Logger . debug ( " \( self . TAG ) setting peerConnectionClient in \( #function ) for call: \( call . debugString ) ")
self . peerConnectionClient = peerConnectionClient
return peerConnectionClient . createOffer ( )
@ -306,7 +298,7 @@ protocol CallServiceObserver: class {
return peerConnectionClient . setLocalSessionDescription ( sessionDescription ) . then {
let offerMessage = OWSCallOfferMessage ( callId : call . signalingId , sessionDescription : sessionDescription . sdp )
let callMessage = OWSOutgoingCallMessage ( thread : thread, offerMessage : offerMessage )
let callMessage = OWSOutgoingCallMessage ( thread : call. thread, offerMessage : offerMessage )
return self . messageSender . sendCallMessage ( callMessage )
}
} . then {
@ -326,10 +318,10 @@ protocol CallServiceObserver: class {
return race ( timeout , callConnectedPromise )
} . then {
Logger . info ( self . call = = call
? " \( self . TAG ) outgoing call connected ."
: " \( self . TAG ) obsolete outgoing call connected ." )
? " \( self . TAG ) outgoing call connected : \( call . debugString ) ."
: " \( self . TAG ) obsolete outgoing call connected : \( call . debugString ) ." )
} . catch { error in
Logger . error ( " \( self . TAG ) placing call failed with error: \( error ) " )
Logger . error ( " \( self . TAG ) placing call \( call . debugString ) failed with error: \( error ) " )
if let callError = error as ? CallError {
self . handleFailedCall ( failedCall : call , error : callError )
@ -338,22 +330,24 @@ protocol CallServiceObserver: class {
self . handleFailedCall ( failedCall : call , error : externalError )
}
}
promise . retainUntilComplete ( )
return promise
}
/* *
* Called by the call initiator after receiving a CallAnswer from the callee .
*/
public func handleReceivedAnswer ( thread : TSContactThread , callId : UInt64 , sessionDescription : String ) {
Logger . info ( " \( TAG ) received call answer for call: \( callId ) thread: \( thread ) " )
Logger . info ( " \( TAG ) received call answer for call: \( callId ) thread: \( thread . contactIdentifier ( ) ) " )
AssertIsOnMainThread ( )
guard let call = self . call else {
Logger . warn ( " \( self . TAG ) ignoring obsolete call in \( #function ) " )
Logger . warn ( " \( self . TAG ) ignoring obsolete call : \( callId ) in \( #function ) " )
return
}
guard call . signalingId = = callId else {
Logger . warn ( " \( self . TAG ) ignoring obsolete call in \( #function ) " )
Logger . warn ( " \( self . TAG ) ignoring obsolete call : \( callId ) in \( #function ) " )
return
}
@ -417,7 +411,7 @@ 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 ) thread: \( thread ) " )
Logger . info ( " \( TAG ) \( #function ) for call: \( call . debugString ) thread: \( thread . contactIdentifier ( ) ) " )
AssertIsOnMainThread ( )
let busyMessage = OWSCallBusyMessage ( callId : call . signalingId )
@ -432,7 +426,7 @@ protocol CallServiceObserver: class {
* The callee was already in another call .
*/
public func handleRemoteBusy ( thread : TSContactThread ) {
Logger . info ( " \( TAG ) \( #function ) for thread: \( thread ) " )
Logger . info ( " \( TAG ) \( #function ) for thread: \( thread . contactIdentifier ( ) ) " )
AssertIsOnMainThread ( )
guard let call = self . call else {
@ -457,14 +451,14 @@ protocol CallServiceObserver: class {
public func handleReceivedOffer ( thread : TSContactThread , callId : UInt64 , sessionDescription callerSessionDescription : String ) {
AssertIsOnMainThread ( )
Logger . info ( " \( TAG ) receivedCallOffer for thread: \( thread ) " )
let newCall = SignalCall . incomingCall ( localId : UUID ( ) , remotePhoneNumber : thread . contactIdentifier ( ) , signalingId : callId )
Logger . info ( " \( TAG ) receivedCallOffer: \( newCall . debugString ) " )
let untrustedIdentity = OWSIdentityManager . shared ( ) . untrustedIdentityForSending ( toRecipientId : thread . contactIdentifier ( ) )
guard untrustedIdentity = = nil else {
Logger . warn ( " \( TAG ) missed a call due to untrusted identity " )
Logger . warn ( " \( TAG ) missed a call due to untrusted identity : \( newCall . debugString ) " )
let callerName = self . contactsManager . displayName ( forPhoneIdentifier : thread . contactIdentifier ( ) )
@ -494,16 +488,15 @@ protocol CallServiceObserver: class {
guard self . call = = nil else {
// 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 for thread: \( thread ) but we're already in call: \( call ! ) " )
Logger . info ( " \( TAG ) receivedCallOffer : \( newCall . debugString ) but we're already in call: \( call ! . debugString ) " )
handleLocalBusyCall ( newCall , thread : thread )
return
}
Logger . info ( " \( TAG ) starting new call: \( newCall ) " )
Logger . info ( " \( TAG ) starting new call: \( newCall . debugString ) " )
self . thread = thread
self . call = newCall
let backgroundTask = UIApplication . shared . beginBackgroundTask {
@ -517,7 +510,7 @@ protocol CallServiceObserver: class {
}
}
incomingCallPromise = firstly {
let incomingCallPromise = firstly {
return getIceServers ( )
} . then { ( iceServers : [ RTCIceServer ] ) -> Promise < HardenedRTCSessionDescription > in
// F I X M E f o r f i r s t t i m e c a l l r e c i p i e n t s I t h i n k w e ' l l s e e m i c / c a m e r a p e r m i s s i o n r e q u e s t s h e r e ,
@ -533,7 +526,7 @@ protocol CallServiceObserver: class {
let useTurnOnly = unknownCaller || Environment . getCurrent ( ) . preferences . doCallsHideIPAddress ( )
Logger . debug ( " \( self . self . TAG ) setting peerConnectionClient in \( #function ) " )
Logger . debug ( " \( self . TAG ) setting peerConnectionClient in \( #function ) for: \( newCall . debugString ) " )
let peerConnectionClient = PeerConnectionClient ( iceServers : iceServers , delegate : self , callDirection : . incoming , useTurnOnly : useTurnOnly )
self . peerConnectionClient = peerConnectionClient
@ -546,7 +539,7 @@ protocol CallServiceObserver: class {
guard self . call = = newCall else {
throw CallError . obsoleteCall ( description : " negotiateSessionDescription() response for obsolete call " )
}
Logger . debug ( " \( self . TAG ) set the remote description " )
Logger . debug ( " \( self . TAG ) set the remote description for: \( newCall . debugString ) " )
let answerMessage = OWSCallAnswerMessage ( callId : newCall . signalingId , sessionDescription : negotiatedSessionDescription . sdp )
let callAnswerMessage = OWSOutgoingCallMessage ( thread : thread , answerMessage : answerMessage )
@ -556,7 +549,7 @@ protocol CallServiceObserver: class {
guard self . call = = newCall else {
throw CallError . obsoleteCall ( description : " sendCallMessage() response for obsolete call " )
}
Logger . debug ( " \( self . TAG ) successfully sent callAnswerMessage " )
Logger . debug ( " \( self . TAG ) successfully sent callAnswerMessage for: \( newCall . debugString ) " )
let ( promise , fulfill , _ ) = Promise < Void > . pending ( )
@ -571,11 +564,11 @@ protocol CallServiceObserver: class {
return race ( promise , timeout )
} . then {
Logger . info ( self . call = = newCall
? " \( self . TAG ) incoming call connected ."
: " \( self . TAG ) obsolete incoming call connected ." )
? " \( self . TAG ) incoming call connected : \( newCall . debugString ) ."
: " \( self . TAG ) obsolete incoming call connected : \( newCall . debugString ) ." )
} . catch { error in
guard self . call = = newCall else {
Logger . debug ( " \( self . TAG ) error for obsolete call: \( error ) " )
Logger . debug ( " \( self . TAG ) error : \( error ) for obsolete call: \( newCall . debugString ) . " )
return
}
if let callError = error as ? CallError {
@ -588,6 +581,7 @@ protocol CallServiceObserver: class {
Logger . debug ( " \( self . TAG ) ending background task awaiting inbound call connection " )
UIApplication . shared . endBackgroundTask ( backgroundTask )
}
incomingCallPromise . retainUntilComplete ( )
}
/* *
@ -597,28 +591,23 @@ protocol CallServiceObserver: class {
AssertIsOnMainThread ( )
Logger . info ( " \( TAG ) called \( #function ) " )
guard let currentThread = self . thread else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) since there is no current thread. Call already ended? " )
return
}
guard thread . contactIdentifier ( ) = = currentThread . contactIdentifier ( ) else {
guard let call = self . call else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) since there is no current thread. Call already ended? " )
return
}
guard let call = self . call else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) since there is no current thread . Call already ended?" )
guard call . signalingId = = callId else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) due to callId mismatch . Call already ended?" )
return
}
guard call. signalingId = = callId else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) since there is no current thread . Call already ended?" )
guard thread. contactIdentifier ( ) = = call . thread . contactIdentifier ( ) else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) due to thread mismatch . Call already ended?" )
return
}
guard let peerConnectionClient = self . peerConnectionClient else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) since there is no current thread . Call already ended?" )
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) since there is no current peerConnectionClient . Call already ended?" )
return
}
@ -646,18 +635,11 @@ protocol CallServiceObserver: class {
return
}
guard let thread = self . thread else {
// T h i s w i l l o n l y b e c a l l e d f o r t h e c u r r e n t p e e r C o n n e c t i o n C l i e n t , s o
// f a i l t h e c u r r e n t c a l l .
handleFailedCurrentCall ( error : . assertionError ( description : " ignoring local ice candidate, because there was no current TSContactThread. " ) )
return
}
let iceUpdateMessage = OWSCallIceUpdateMessage ( callId : call . signalingId , sdp : iceCandidate . sdp , sdpMLineIndex : iceCandidate . sdpMLineIndex , sdpMid : iceCandidate . sdpMid )
if self . sendIceUpdatesImmediately {
Logger . info ( " \( TAG ) in \( #function ) . Sending immediately. " )
let callMessage = OWSOutgoingCallMessage ( thread : thread, iceUpdateMessage : iceUpdateMessage )
let callMessage = OWSOutgoingCallMessage ( thread : call . thread , iceUpdateMessage : iceUpdateMessage )
let sendPromise = self . messageSender . sendCallMessage ( callMessage )
sendPromise . retainUntilComplete ( )
} else {
@ -679,8 +661,6 @@ protocol CallServiceObserver: class {
private func handleIceConnected ( ) {
AssertIsOnMainThread ( )
Logger . debug ( " \( TAG ) in \( #function ) " )
guard let call = self . call else {
// T h i s w i l l o n l y b e c a l l e d f o r t h e c u r r e n t p e e r C o n n e c t i o n C l i e n t , s o
// f a i l t h e c u r r e n t c a l l .
@ -688,25 +668,20 @@ protocol CallServiceObserver: class {
return
}
guard let thread = self . thread else {
// T h i s w i l l o n l y b e c a l l e d f o r t h e c u r r e n t p e e r C o n n e c t i o n C l i e n t , s o
// f a i l t h e c u r r e n t c a l l .
handleFailedCurrentCall ( error : . assertionError ( description : " \( TAG ) ignoring \( #function ) since there is no current thread. " ) )
return
}
Logger . info ( " \( TAG ) in \( #function ) : \( call . debugString ) . " )
switch call . state {
case . dialing :
call . state = . remoteRinging
case . answering :
call . state = . localRinging
self . callUIAdapter . reportIncomingCall ( call , thread : thread)
self . callUIAdapter . reportIncomingCall ( call , thread : call. thread)
case . remoteRinging :
Logger . info ( " \( TAG ) call alread ing ringing. Ignoring \( #function ) " )
Logger . info ( " \( TAG ) call alread y ringing. Ignoring \( #function ) : \( call . debugString ) . " )
case . connected :
Logger . info ( " \( TAG ) Call reconnected \( #function ) ")
Logger . info ( " \( TAG ) Call reconnected \( #function ) : \( call . debugString ) . ")
default :
Logger . debug ( " \( TAG ) unexpected call state for \( #function ) : \( call . state ) ")
Logger . debug ( " \( TAG ) unexpected call state for \( #function ) : \( call . state ) : \( call . debugString ) . ")
}
}
@ -717,20 +692,21 @@ protocol CallServiceObserver: class {
Logger . debug ( " \( TAG ) in \( #function ) " )
AssertIsOnMainThread ( )
guard thread . contactIdentifier ( ) = = self . thread ? . contactIdentifier ( ) else {
// T h i s c a n s a f e l y b e i g n o r e d .
// W e d o n ' t w a n t t o f a i l t h e c u r r e n t c a l l b e c a u s e a n o l d c a l l w a s s l o w t o s e n d u s t h e h a n g u p m e s s a g e .
Logger . warn ( " \( TAG ) ignoring hangup for thread: \( thread ) which is not the current thread: \( String ( describing : self . thread ) ) " )
guard let call = self . call else {
// T h i s m a y h a p p e n i f w e h a n g u p s l i g h t l y b e f o r e t h e y h a n g u p .
handleFailedCurrentCall ( error : . assertionError ( description : " \( TAG ) call was unexpectedly nil in \( #function ) " ) )
return
}
guard let call = self . call else {
// T h i s sh o u l d n e v e r h a p p e n ; r e t u r n t o a k n o w n g o o d s t a t e .
assertionFailure ( " \( TAG ) call was unexpectedly nil in \( #function ) " )
handleFailedCurrentCall( error : . assertionError ( description : " \( TAG ) call was unexpectedly nil in \( #function ) " ) )
guard thread . contactIdentifier ( ) = = call . thread . contactIdentifier ( ) else {
// T h i s ca n s a f e l y b e i g n o r e d .
// W e d o n ' t w a n t t o f a i l t h e c u r r e n t c a l l b e c a u s e a n o l d c a l l w a s s l o w t o s e n d u s t h e h a n g u p m e s s a g e .
Logger. warn ( " \( TAG ) ignoring hangup for thread: \( thread . contactIdentifier ( ) ) which is not the current call: \( call . debugString ) " )
return
}
Logger . info ( " \( TAG ) in \( #function ) : \( call . debugString ) . " )
switch call . state {
case . idle , . dialing , . answering , . localRinging , . localFailure , . remoteBusy , . remoteRinging :
handleMissedCall ( call , thread : thread )
@ -791,17 +767,14 @@ protocol CallServiceObserver: class {
return
}
guard let thread = self . thread else {
handleFailedCall ( failedCall : call , error : . assertionError ( description : " \( TAG ) ignoring \( #function ) for call other than current call " ) )
return
}
guard let peerConnectionClient = self . peerConnectionClient else {
handleFailedCall ( failedCall : call , error : . assertionError ( description : " \( TAG ) missing peerconnection client in \( #function ) " ) )
return
}
let callRecord = TSCall ( timestamp : NSDate . ows_millisecondTimeStamp ( ) , withCallNumber : call . remotePhoneNumber , callType : RPRecentCallTypeIncomingIncomplete , in : thread )
Logger . info ( " \( TAG ) in \( #function ) : \( call . debugString ) . " )
let callRecord = TSCall ( timestamp : NSDate . ows_millisecondTimeStamp ( ) , withCallNumber : call . remotePhoneNumber , callType : RPRecentCallTypeIncomingIncomplete , in : call . thread )
callRecord . save ( )
call . callRecord = callRecord
@ -824,6 +797,8 @@ protocol CallServiceObserver: class {
return
}
Logger . info ( " \( TAG ) handleConnectedCall: \( call . debugString ) . " )
assert ( self . fulfillCallConnectedPromise != nil )
// c a n c e l c o n n e c t i o n t i m e o u t
self . fulfillCallConnectedPromise ? ( )
@ -870,7 +845,7 @@ protocol CallServiceObserver: class {
public func handleDeclineCall ( _ call : SignalCall ) {
AssertIsOnMainThread ( )
Logger . info ( " \( TAG ) in \( #function ) ")
Logger . info ( " \( TAG ) in \( #function ) : \( call . debugString ) . ")
// C u r r e n t l y w e j u s t h a n d l e t h i s a s a h a n g u p . B u t w e c o u l d o f f e r m o r e d e s c r i p t i v e a c t i o n . e . g . D a t a C h a n n e l m e s s a g e
handleLocalHungupCall ( call )
@ -899,10 +874,7 @@ protocol CallServiceObserver: class {
return
}
guard let thread = self . thread else {
handleFailedCall ( failedCall : call , error : . assertionError ( description : " \( TAG ) missing thread in \( #function ) " ) )
return
}
Logger . info ( " \( TAG ) in \( #function ) : \( call . debugString ) . " )
call . state = . localHangup
@ -916,11 +888,11 @@ protocol CallServiceObserver: class {
// I f t h e c a l l h a s n ' t s t a r t e d y e t , w e d o n ' t h a v e a d a t a c h a n n e l t o c o m m u n i c a t e t h e h a n g u p . U s e S i g n a l S e r v i c e M e s s a g e .
let hangupMessage = OWSCallHangupMessage ( callId : call . signalingId )
let callMessage = OWSOutgoingCallMessage ( thread : thread, hangupMessage : hangupMessage )
let callMessage = OWSOutgoingCallMessage ( thread : call. thread, hangupMessage : hangupMessage )
let sendPromise = self . messageSender . sendCallMessage ( callMessage ) . then {
Logger . debug ( " \( self . TAG ) successfully sent hangup call message to \( thread) " )
Logger . debug ( " \( self . TAG ) successfully sent hangup call message to \( call. thread. contactIdentifier ( ) ) " )
} . catch { error in
Logger . error ( " \( self . TAG ) failed to send hangup call message to \( thread) with error: \( error ) " )
Logger . error ( " \( self . TAG ) failed to send hangup call message to \( call. thread. contactIdentifier ( ) ) with error: \( error ) " )
}
sendPromise . retainUntilComplete ( )
@ -1035,7 +1007,7 @@ protocol CallServiceObserver: class {
}
if message . hasConnected ( ) {
Logger . debug ( " \( TAG ) remote participant sent Connected via data channel " )
Logger . debug ( " \( TAG ) remote participant sent Connected via data channel : \( call . debugString ) . " )
let connected = message . connected !
@ -1050,7 +1022,7 @@ protocol CallServiceObserver: class {
handleConnectedCall ( call )
} else if message . hasHangup ( ) {
Logger . debug ( " \( TAG ) remote participant sent Hangup via data channel " )
Logger . debug ( " \( TAG ) remote participant sent Hangup via data channel : \( call . debugString ) . " )
let hangup = message . hangup !
@ -1061,20 +1033,13 @@ protocol CallServiceObserver: class {
return
}
guard let thread = self . thread else {
// T h i s s h o u l d n e v e r h a p p e n ; r e t u r n t o a k n o w n g o o d s t a t e .
assertionFailure ( " \( TAG ) current contact thread is unexpectedly nil when receiving hangup DataChannelMessage " )
handleFailedCurrentCall ( error : . assertionError ( description : " \( TAG ) current contact thread is unexpectedly nil when receiving hangup DataChannelMessage " ) )
return
}
handleRemoteHangup ( thread : thread )
handleRemoteHangup ( thread : call . thread )
} else if message . hasVideoStreamingStatus ( ) {
Logger . debug ( " \( TAG ) remote participant sent VideoStreamingStatus via data channel " )
Logger . debug ( " \( TAG ) remote participant sent VideoStreamingStatus via data channel: \( call . debugString ) . " )
self . isRemoteVideoEnabled = message . videoStreamingStatus . enabled ( )
} else {
Logger . info ( " \( TAG ) received unknown or empty DataChannelMessage " )
Logger . info ( " \( TAG ) received unknown or empty DataChannelMessage: \( call . debugString ) . " )
}
}
@ -1198,7 +1163,10 @@ protocol CallServiceObserver: class {
// t h a t w e w a n t t o t e r m i n a t e t h e c u r r e n t c a l l ( i f a n y ) i n o r d e r t o
// r e t u r n t o a k n o w n g o o d s t a t e .
public func handleFailedCurrentCall ( error : CallError ) {
handleFailedCall ( failedCall : self . call , error : error , forceTerminate : true )
Logger . debug ( " \( TAG ) in \( #function ) " )
// R e t u r n t o a k n o w n g o o d s t a t e b y e n d i n g t h e c u r r e n t c a l l , i f a n y .
handleFailedCall ( failedCall : self . call , error : error )
}
// T h i s m e t h o d s h o u l d b e c a l l e d w h e n a f a t a l e r r o r o c c u r r e d f o r a c a l l .
@ -1206,26 +1174,24 @@ protocol CallServiceObserver: class {
// * I f w e k n o w w h i c h c a l l i t w a s , w e s h o u l d u p d a t e t h a t c a l l ' s s t a t e
// t o r e f l e c t t h e e r r o r .
// * I F F t h a t c a l l i s t h e c u r r e n t c a l l , w e w a n t t o t e r m i n a t e i t .
public func handleFailedCall ( failedCall : SignalCall ? , error : CallError , forceTerminate : Bool = false ) {
public func handleFailedCall ( failedCall : SignalCall ? , error : CallError ) {
AssertIsOnMainThread ( )
Logger . error ( " \( TAG ) call failed with error: \( error ) " )
guard let failedCall = failedCall else {
Logger . debug ( " \( TAG ) in \( #function ) ignoring obsolete call. " )
return
}
if let failedCall = failedCall {
// 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
self . callUIAdapter . failCall ( failedCall , error : error )
// 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
self . callUIAdapter . failCall ( failedCall , error : error )
// O n l y t e r m i n a t e t h e c u r r e n t c a l l i f t h e e r r o r p e r t a i n s t o t h e c u r r e n t c a l l .
guard failedCall = = self . call else {
Logger . debug ( " \( TAG ) in \( #function ) ignoring obsolete call: \( failedCall . debugString ) . " )
return
}
// O n l y t e r m i n a t e t h e c u r r e n t c a l l i f t h e e r r o r p e r t a i n s t o t h e c u r r e n t c a l l ,
// o r i f w e ' r e t r y i n g t o r e t u r n t o a k n o w n g o o d s t a t e .
let shouldTerminate = forceTerminate || failedCall = = self . call
guard shouldTerminate else {
Logger . debug ( " \( TAG ) in \( #function ) ignoring obsolete call. " )
return
Logger . error ( " \( TAG ) call: \( failedCall . debugString ) failed with error: \( error ) " )
} else {
Logger . error ( " \( TAG ) unknown call failed with error: \( error ) " )
}
// O n l y t e r m i n a t e t h e c a l l i f i t i s t h e c u r r e n t c a l l .
@ -1251,11 +1217,10 @@ protocol CallServiceObserver: class {
call ? . removeAllObservers ( )
call = nil
thread = nil
incomingCallPromise = nil
sendIceUpdatesImmediately = true
Logger . info ( " \( TAG ) clearing pendingIceUpdateMessages " )
pendingIceUpdateMessages = [ ]
fulfillCallConnectedPromise = nil
}
// MARK: - C a l l O b s e r v e r