From b6531a8b5d7459edd028086dc1e7201ebb304139 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Thu, 22 Jun 2017 10:27:09 -0400 Subject: [PATCH] =?UTF-8?q?If=20two=20users=20call=20each=20other=20at=20t?= =?UTF-8?q?he=20same=20time,=20ensure=20they=20both=20see=20=E2=80=9Cbusy?= =?UTF-8?q?=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- Signal/src/call/CallService.swift | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Signal/src/call/CallService.swift b/Signal/src/call/CallService.swift index 2d6fd4274..39467ea6c 100644 --- a/Signal/src/call/CallService.swift +++ b/Signal/src/call/CallService.swift @@ -497,14 +497,27 @@ protocol CallServiceObserver: class { handleLocalBusyCall(newCall, thread: thread) - if self.call?.remotePhoneNumber == newCall.remotePhoneNumber { - // If we're receiving a new call offer from the user we think we have a call with, terminate - // our current call to get back to a known good state. If they call back, we'll be ready. + 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 we're receiving a new call offer from the user we already think we have a call with, + // terminate our current call to get back to a known good state. If they call back, we'll + // be ready. // // TODO: Auto-accept this incoming call if our current call was either a) outgoing or // b) ever connected. There will be a bit of complexity around making sure that two - // parties that call each other at the same time end up connected. - terminateCall() + // parties that call each other at + + switch self.call!.state { + case .idle, .dialing, .remoteRinging: + // If both users are trying to call each other at the same time, + // both should see busy. + handleRemoteBusy(thread:self.call!.thread) + case .answering, .localRinging, .connected, .localFailure, .localHangup, .remoteHangup, .remoteBusy: + // If one user calls another while the other has a "vestigial" call with + // that same user, fail the old call. + terminateCall() + } } return