From 1aa43c00032d5b879ce35b6a7c091c48bcd6cef9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Thu, 12 Apr 2018 13:57:44 -0400 Subject: [PATCH] manager: auto-answer if two daemons are trying to call each other When two persons are trying to call each others, we can assume they want to talk together. So, the daemon should automatically answer. It avoids some weird case where they both see the outgoing call view, but cannot answer to the incoming call. There is several scenarios. 1. Both are trying to make a video call, in this case, the daemon with the incoming call from the higher ring_id should answer and drop its outgoing call resulting in a video call. 2. Both are trying to make an audio call, same behavior as scenario 1, resulting in an audio call. 3. One device is trying to make a video call, the other an audio call, audio call is prioritary here, and the daemon with an incoming audio only call should answer and drop the outgoing video call. Change-Id: Id1e639448243c19bf492f2d057496cab6d05de8c Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com> --- src/manager.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/manager.cpp b/src/manager.cpp index d2adddece0..35c17e6eb4 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1921,8 +1921,36 @@ Manager::incomingCall(Call &call, const std::string& accountId) emitSignal<DRing::CallSignal::IncomingCall>(accountId, callID, call.getPeerDisplayName() + " " + from); - if (pimpl_->autoAnswer_) + auto currentCall = getCurrentCall(); + if (pimpl_->autoAnswer_) { runOnMainThread([this, callID]{ answerCall(callID); }); + } else if (currentCall) { + // Test if already calling this person + if (currentCall->getAccountId() == accountId + && currentCall->getPeerNumber() == call.getPeerNumber()) { + auto device_uid = currentCall->getAccount().getUsername(); + if (device_uid.find("ring:") == 0) { + // NOTE: in case of a SIP call it's already ready to compare + device_uid = device_uid.substr(5); // after ring: + } + auto answerToCall = false; + auto downgradeToAudioOnly = currentCall->isAudioOnly() != call.isAudioOnly(); + if (downgradeToAudioOnly) + // Accept the incoming audio only + answerToCall = call.isAudioOnly(); + else + // Accept the incoming call from the higher id number + answerToCall = (device_uid.compare(call.getPeerNumber()) < 0); + + if (answerToCall) { + auto currentCallID = currentCall->getCallId(); + runOnMainThread([this, currentCallID, callID] { + answerCall(callID); + hangupCall(currentCallID); + }); + } + } + } } void -- GitLab