Commit 15b3f187 authored by Guillaume Roguez's avatar Guillaume Roguez

daemon: move peerHangup API to Call class

Refs #51555

Change-Id: I95f270779971f93601d8e9aa944993b4e011b88d
parent d356e08f
......@@ -278,6 +278,11 @@ class Call : public Recordable {
*/
virtual void offhold() = 0;
/**
* Peer Hung up a call
*/
virtual void peerHungup() = 0;
private:
bool validTransition(CallState newState);
......
......@@ -209,3 +209,13 @@ IAXCall::offhold()
Manager::instance().startAudioDriverStream();
}
void
IAXCall::peerHungup()
{
Manager::instance().getMainBuffer().unBindAll(getCallId());
session = nullptr;
link_->removeIaxCall(getCallId());
}
......@@ -94,6 +94,8 @@ class IAXCall : public Call {
void offhold();
void peerHungup();
private:
NON_COPYABLE(IAXCall);
......
......@@ -313,23 +313,6 @@ IAXVoIPLink::newOutgoingCall(const std::string& id, const std::string& toUrl, co
return call;
}
void
IAXVoIPLink::peerHungup(const std::string& id)
{
Manager::instance().getMainBuffer().unBindAll(id);
{
std::lock_guard<std::mutex> lock(iaxCallMapMutex_);
auto call = getIAXCall(id);
if (!call)
throw VoipLinkException("Could not find call");
call->session = NULL;
}
removeIaxCall(id);
}
void
IAXVoIPLink::carryingDTMFdigits(const std::string& id, char code)
{
......
......@@ -121,12 +121,6 @@ class IAXVoIPLink : public VoIPLink {
*/
virtual std::shared_ptr<Call> newOutgoingCall(const std::string& id, const std::string& toUrl, const std::string &account_id);
/**
* Peer Hungup a call
* @param id The ID of the call
*/
virtual void peerHungup(const std::string& id);
/**
* Cancel a call
* @param id The ID of the call
......
......@@ -1607,7 +1607,7 @@ void ManagerImpl::peerHungupCall(const std::string& call_id)
if (auto call = getCallFromCallID(call_id)) {
history_.addCall(call.get(), preferences.getHistoryLimit());
call->getVoIPLink()->peerHungup(call_id);
call->peerHungup();
saveHistory();
}
......
......@@ -78,6 +78,17 @@ updateSDPFromSTUN(SIPCall &call, SIPAccount &account, const SipTransport &transp
}
}
static void
stopRtpIfCurrent(SIPCall& call)
{
if (Manager::instance().isCurrentCall(call.getCallId())) {
call.getAudioRtp().stop();
#ifdef SFL_VIDEO
call.getVideoRtp().stop();
#endif
}
}
SIPCall::SIPCall(const std::string& id, Call::CallType type,
pj_caching_pool *caching_pool, const std::string &account_id) :
Call(id, type, account_id)
......@@ -229,12 +240,7 @@ SIPCall::hangup(int reason)
inv->mod_data[siplink.getMod()->id] = NULL;
// Stop all RTP streams
if (Manager::instance().isCurrentCall(getCallId())) {
getAudioRtp().stop();
#ifdef SFL_VIDEO
getVideoRtp().stop();
#endif
}
stopRtpIfCurrent(*this);
siplink.removeSipCall(getCallId());
}
......@@ -549,3 +555,26 @@ SIPCall::internalOffHold(const std::function<void()> &SDPUpdateFunc)
onhold();
}
}
void
SIPCall::peerHungup()
{
// User hangup current call. Notify peer
pjsip_tx_data *tdata = NULL;
if (pjsip_inv_end_session(inv, 404, NULL, &tdata) != PJ_SUCCESS || !tdata)
return;
if (pjsip_inv_send_msg(inv, tdata) != PJ_SUCCESS)
return;
auto& siplink = SIPVoIPLink::instance();
// Make sure user data is NULL in callbacks
inv->mod_data[siplink.getMod()->id ] = NULL;
// Stop all RTP streams
stopRtpIfCurrent(*this);
siplink.removeSipCall(getCallId());
}
......@@ -126,6 +126,8 @@ class SIPCall : public Call {
void offhold();
void peerHungup();
private:
// override of Call::createHistoryEntry
......
......@@ -1025,29 +1025,6 @@ stopRtpIfCurrent(const std::string &id, SIPCall &call)
}
}
void
SIPVoIPLink::peerHungup(const std::string& id)
{
auto call = getSipCall(id);
if (!call)
return;
// User hangup current call. Notify peer
pjsip_tx_data *tdata = NULL;
if (pjsip_inv_end_session(call->inv, 404, NULL, &tdata) != PJ_SUCCESS || !tdata)
return;
if (pjsip_inv_send_msg(call->inv, tdata) != PJ_SUCCESS)
return;
// Make sure user data is NULL in callbacks
call->inv->mod_data[mod_ua_.id ] = NULL;
stopRtpIfCurrent(id, *call);
removeSipCall(id);
}
#if HAVE_INSTANT_MESSAGING
void SIPVoIPLink::sendTextMessage(const std::string &callID,
const std::string &message,
......
......@@ -159,12 +159,6 @@ class SIPVoIPLink : public VoIPLink {
const std::string& toUrl,
const std::string &account_id);
/**
* Hang up the call
* @param id The call identifier
*/
virtual void peerHungup(const std::string& id);
/**
* Send DTMF refering to account configuration
* @param id The call identifier
......
......@@ -93,12 +93,6 @@ class VoIPLink {
*/
virtual std::vector<std::shared_ptr<Call> > getCalls(const std::string &account_id) const = 0;
/**
* Peer Hung up a call
* @param id The call identifier
*/
virtual void peerHungup(const std::string &id) = 0;
/**
* Send DTMF
* @param id The call identifier
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment