diff --git a/src/manager.cpp b/src/manager.cpp index d2adddece072975eb96bda2087139abf62dcc03c..35c17e6eb4b31d1fd3c957236f0ad1628ad533a3 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