diff --git a/src/call/call-listener.h b/src/call/call-listener.h index 02c9f05dd..82f837989 100644 --- a/src/call/call-listener.h +++ b/src/call/call-listener.h @@ -34,6 +34,7 @@ public: virtual void onCallSetReleased () = 0; virtual void onCallSetTerminated () = 0; virtual void onCallStateChanged (LinphoneCallState state, const std::string &message) = 0; + virtual void onCheckForAcceptation () = 0; virtual void onIncomingCallStarted () = 0; virtual void onIncomingCallToBeAdded () = 0; diff --git a/src/call/call-p.h b/src/call/call-p.h index 29b4236ba..9f2ebabdd 100644 --- a/src/call/call-p.h +++ b/src/call/call-p.h @@ -60,6 +60,7 @@ private: void onCallSetReleased () override; void onCallSetTerminated () override; void onCallStateChanged (LinphoneCallState state, const std::string &message) override; + void onCheckForAcceptation () override; void onIncomingCallStarted () override; void onIncomingCallToBeAdded () override; void onEncryptionChanged (bool activated, const std::string &authToken) override; diff --git a/src/call/call.cpp b/src/call/call.cpp index 994be2887..7aefd00c5 100644 --- a/src/call/call.cpp +++ b/src/call/call.cpp @@ -142,6 +142,27 @@ void CallPrivate::onCallStateChanged (LinphoneCallState state, const string &mes linphone_call_notify_state_changed(lcall, state, message.c_str()); } +void CallPrivate::onCheckForAcceptation () { + bctbx_list_t *copy = bctbx_list_copy(linphone_core_get_calls(core)); + for (bctbx_list_t *it = copy; it != nullptr; it = bctbx_list_next(it)) { + LinphoneCall *call = reinterpret_cast(bctbx_list_get_data(it)); + if (call == lcall) continue; + switch (linphone_call_get_state(call)) { + case LinphoneCallOutgoingInit: + case LinphoneCallOutgoingProgress: + case LinphoneCallOutgoingRinging: + case LinphoneCallOutgoingEarlyMedia: + lInfo() << "Already existing call [" << call << "] in state [" << linphone_call_state_to_string(linphone_call_get_state(call)) + << "], canceling it before accepting new call [" << lcall << "]"; + linphone_call_terminate(call); + break; + default: + break; /* Nothing to do */ + } + } + bctbx_list_free(copy); +} + void CallPrivate::onIncomingCallStarted () { if (lcall) linphone_core_notify_incoming_call(core, lcall); diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 4a40d509c..99463295a 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -107,6 +107,11 @@ void Conference::onCallSessionStateChanged (const CallSession &session, Linphone callListener->onCallStateChanged(state, message); } +void Conference::onCheckForAcceptation (const CallSession &session) { + if (callListener) + callListener->onCheckForAcceptation(); +} + void Conference::onIncomingCallSessionStarted (const CallSession &session) { if (callListener) callListener->onIncomingCallStarted(); diff --git a/src/conference/conference.h b/src/conference/conference.h index 583a770c2..b1a1f4fee 100644 --- a/src/conference/conference.h +++ b/src/conference/conference.h @@ -64,6 +64,7 @@ private: void onCallSessionSetReleased (const CallSession &session) override; void onCallSessionSetTerminated (const CallSession &session) override; void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) override; + void onCheckForAcceptation (const CallSession &session) override; void onIncomingCallSessionStarted (const CallSession &session) override; void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) override; void onStatsUpdated (const LinphoneCallStats *stats) override; diff --git a/src/conference/session/call-session-listener.h b/src/conference/session/call-session-listener.h index 228820a29..e5dd8d8ca 100644 --- a/src/conference/session/call-session-listener.h +++ b/src/conference/session/call-session-listener.h @@ -33,6 +33,7 @@ public: virtual void onCallSessionSetReleased (const CallSession &session) = 0; virtual void onCallSessionSetTerminated (const CallSession &session) = 0; virtual void onCallSessionStateChanged (const CallSession &session, LinphoneCallState state, const std::string &message) = 0; + virtual void onCheckForAcceptation (const CallSession &session) = 0; virtual void onIncomingCallSessionStarted (const CallSession &session) = 0; virtual void onEncryptionChanged (const CallSession &session, bool activated, const std::string &authToken) = 0; diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp index 91d1edb9b..392c632ca 100644 --- a/src/conference/session/call-session.cpp +++ b/src/conference/session/call-session.cpp @@ -451,25 +451,8 @@ LinphoneStatus CallSessionPrivate::checkForAcceptation () const { lError() << "checkForAcceptation() CallSession [" << q << "] is in state [" << linphone_call_state_to_string(state) << "], operation not permitted"; return -1; } - bctbx_list_t *copy = bctbx_list_copy(linphone_core_get_calls(core)); - for (bctbx_list_t *it = copy; it != nullptr; it = bctbx_list_next(it)) { - LinphoneCall *call = reinterpret_cast(bctbx_list_get_data(it)); - shared_ptr session = L_GET_PRIVATE_FROM_C_OBJECT(call)->getActiveSession(); - if (session.get() == q) continue; - switch (session->getState()) { - case LinphoneCallOutgoingInit: - case LinphoneCallOutgoingProgress: - case LinphoneCallOutgoingRinging: - case LinphoneCallOutgoingEarlyMedia: - lInfo() << "Already existing CallSession [" << session << "] in state [" << linphone_call_state_to_string(session->getState()) - << "], canceling it before accepting new CallSession [" << q << "]"; - session->terminate(); - break; - default: - break; /* Nothing to do */ - } - } - bctbx_list_free(copy); + if (listener) + listener->onCheckForAcceptation(*q); /* Check if this call is supposed to replace an already running one */ SalOp *replaced = sal_call_get_replaces(op); @@ -822,14 +805,14 @@ void CallSession::startIncomingNotification () { call->bg_task_id=sal_begin_background_task("liblinphone call notification", NULL, NULL); #endif if (d->deferIncomingNotification) { - lInfo() << "Defer ringing"; + lInfo() << "Defer incoming notification"; return; } if (d->listener) d->listener->onIncomingCallSessionStarted(*this); - d->setState(LinphoneCallIncomingReceived, "Incoming call"); + d->setState(LinphoneCallIncomingReceived, "Incoming CallSession"); /* From now on, the application is aware of the call and supposed to take background task or already submitted notification to the user. * We can then drop our background task. */