From 67221bdf2e942c6e29d6f81721f68e3499173ba6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Wed, 11 Nov 2020 13:16:26 -0500
Subject: [PATCH] jamiaccount: do not stay on calling

If the request is sent by SIP, we should follow status of the call,
also when the SIP connection is closed, the callback for sending a
request will be called twice. Once for sending the request, the
second time to delete the dummy call.

Change-Id: I29e5f6d96b2b9fa240b7b120f88840c9256b6919
---
 src/jamidht/jamiaccount.cpp | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp
index da953ee842..8a46a10347 100644
--- a/src/jamidht/jamiaccount.cpp
+++ b/src/jamidht/jamiaccount.cpp
@@ -548,6 +548,14 @@ JamiAccount::startOutgoingCall(const std::shared_ptr<SIPCall>& call, const std::
             dev_call->setIPToIP(true);
             dev_call->setSecure(isTlsEnabled());
             dev_call->setState(Call::ConnectionState::TRYING);
+            call->addStateListener(
+                [w = weak(), deviceId](Call::CallState, Call::ConnectionState state, int) {
+                    if (state != Call::ConnectionState::PROGRESSING
+                        and state != Call::ConnectionState::TRYING) {
+                        if (auto shared = w.lock())
+                            shared->callConnectionClosed(deviceId, true);
+                    }
+                });
             call->addSubCall(*dev_call);
             {
                 std::lock_guard<std::mutex> lk(pendingCallsMutex_);
@@ -3519,8 +3527,14 @@ JamiAccount::callConnectionClosed(const DeviceId& deviceId, bool eraseDummy)
         std::lock_guard<std::mutex> lk(onConnectionClosedMtx_);
         auto it = onConnectionClosed_.find(deviceId);
         if (it != onConnectionClosed_.end()) {
-            cb = std::move(it->second);
-            onConnectionClosed_.erase(it);
+            if (eraseDummy) {
+                cb = std::move(it->second);
+                onConnectionClosed_.erase(it);
+            } else {
+                // In this case a new subcall is created and the callback
+                // will be re-called once with eraseDummy = true
+                cb = it->second;
+            }
         }
     }
     if (cb)
-- 
GitLab