@ -399,7 +399,7 @@ protocol CallServiceObserver: class {
}
guard call . signalingId = = callId else {
Logger . warn ( " \( self . TAG ) ignoring obsolete call: \( call Id) in \( #function ) " )
Logger . warn ( " \( self . TAG ) ignoring mismatched call: \( callId ) currentCall: \( call . signaling Id) in \( #function ) " )
return
}
@ -480,12 +480,17 @@ protocol CallServiceObserver: class {
/* *
* The callee was already in another call .
*/
public func handleRemoteBusy ( thread : TSContactThread ) {
public func handleRemoteBusy ( thread : TSContactThread , callId : UInt64 ) {
Logger . info ( " \( TAG ) \( #function ) for 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 mismatched call: \( callId ) currentCall: \( call . signalingId ) in \( #function ) " )
return
}
@ -541,13 +546,15 @@ protocol CallServiceObserver: class {
}
guard self . call = = nil else {
let existingCall = self . call !
// 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: \( call ! . identifiersForLogs ) " )
Logger . info ( " \( TAG ) receivedCallOffer: \( newCall . identifiersForLogs ) but we're already in call: \( existingCall . identifiersForLogs ) " )
handleLocalBusyCall ( newCall , thread : thread )
if self . call ! . remotePhoneNumber = = newCall . remotePhoneNumber {
Logger . info ( " \( TAG ) handling call from current call user as remote busy.: \( newCall . identifiersForLogs ) but we're already in call: \( call! . identifiersForLogs ) " )
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 ) " )
// I f w e ' r e r e c e i v i n g a n e w c a l l o f f e r f r o m t h e u s e r w e a l r e a d y t h i n k w e h a v e a c a l l w i t h ,
// t e r m i n a t e o u r c u r r e n t c a l l t o g e t b a c k t o a k n o w n g o o d s t a t e . I f t h e y c a l l b a c k , w e ' l l
@ -556,11 +563,11 @@ protocol CallServiceObserver: class {
// TODO: A u t o - a c c e p t t h i s i n c o m i n g c a l l i f o u r c u r r e n t c a l l w a s e i t h e r a ) o u t g o i n g o r
// b ) n e v e r c o n n e c t e d . T h e r e w i l l b e a b i t o f c o m p l e x i t y a r o u n d m a k i n g s u r e t h a t t w o
// p a r t i e s t h a t c a l l e a c h o t h e r a t t h e s a m e t i m e e n d u p c o n n e c t e d .
switch self . call ! . state {
switch existingCall . state {
case . idle , . dialing , . remoteRinging :
// I f b o t h u s e r s a r e t r y i n g t o c a l l e a c h o t h e r a t t h e s a m e t i m e ,
// b o t h s h o u l d s e e b u s y .
handleRemoteBusy ( thread : self . call ! . threa d)
handleRemoteBusy ( thread : existingCall . thread , callId : existingCall . signalingI d)
case . answering , . localRinging , . connected , . localFailure , . localHangup , . remoteHangup , . remoteBusy :
// I f o n e u s e r c a l l s a n o t h e r w h i l e t h e o t h e r h a s a " v e s t i g i a l " c a l l w i t h
// t h a t s a m e u s e r , f a i l t h e o l d c a l l .
@ -683,7 +690,7 @@ protocol CallServiceObserver: class {
}
guard call . signalingId = = callId else {
Logger . warn ( " ignoring remote ice update for thread: \( thread . uniqueId ) due to callId mismatch. Call already ended? " )
Logger . warn ( " \( self . TAG ) ignoring mismatched call: \( callId ) currentCall: \( call . signalingId ) in \( #function ) " )
return
}
@ -791,7 +798,7 @@ protocol CallServiceObserver: class {
/* *
* The remote client ( caller or callee ) ended the call .
*/
public func handleRemoteHangup ( thread : TSContactThread ) {
public func handleRemoteHangup ( thread : TSContactThread , callId : UInt64 ) {
Logger . debug ( " \( TAG ) in \( #function ) " )
AssertIsOnMainThread ( )
@ -801,6 +808,11 @@ protocol CallServiceObserver: class {
return
}
guard call . signalingId = = callId else {
Logger . warn ( " \( self . TAG ) ignoring mismatched call: \( callId ) currentCall: \( call . signalingId ) in \( #function ) " )
return
}
guard thread . contactIdentifier ( ) = = call . 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 .
@ -1161,7 +1173,7 @@ protocol CallServiceObserver: class {
return
}
handleRemoteHangup ( thread : call . thread )
handleRemoteHangup ( thread : call . thread , callId : hangup . id )
} else if message . hasVideoStreamingStatus ( ) {
Logger . debug ( " \( TAG ) remote participant sent VideoStreamingStatus via data channel: \( call . identifiersForLogs ) . " )