Skip to content

Commit

Permalink
Merge 27b7f3c into 721a5a2
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster authored Dec 4, 2020
2 parents 721a5a2 + 27b7f3c commit bf9dd29
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,19 @@ The softphone exposes the following resources on port `6060`.
<td>UnHold call with specified <code>call_id</code></td>
</tr>
<tr>
<td><code>/calls/{call_id}/transfer</code></td>
<td>POST</td>
<td>
<pre lang="json">
{
"uri": "sip-uri",
}
</pre>
</td>
<td>transfer <code>call_id</code> to specified <code>uri</code></td>
</tr>
<tr>
<tr>
<td><code>/calls/{call_id}/hangup</code></td>
<td>POST</td>
<td></td>
Expand Down
4 changes: 4 additions & 0 deletions tinyphone/call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ namespace tp {
}
}

void SIPCall::onCallTransferStatus(OnCallTransferStatusParam &prm){
PJ_LOG(3, (__FILENAME__, "Call [%d] onCallTransferStatus Status Update : %s", getId(), prm.reason.c_str()));
}

tp::HoldStatus SIPCall::HoldState() {
auto call_info = getInfo();
if (call_info.state == PJSIP_INV_STATE_CONFIRMED) {
Expand Down
1 change: 1 addition & 0 deletions tinyphone/call.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace tp {

virtual void onCallState(OnCallStateParam &prm);
virtual void onCallMediaState(OnCallMediaStateParam &prm);
virtual void onCallTransferStatus(OnCallTransferStatusParam &prm);
virtual bool HoldCall();
virtual bool UnHoldCall();
virtual tp::HoldStatus HoldState();
Expand Down
45 changes: 45 additions & 0 deletions tinyphone/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,51 @@ void TinyPhoneHttpServer::Start() {
return tp::response(202, response);
}
});

CROW_ROUTE(app, "/calls/<int>/transfer")
.methods("POST"_method)
([&phone](const crow::request& req, int call_id) {
pj_thread_auto_register();

std::string refer_uri;
try {
json j = json::parse(req.body);
j.at("uri").get_to(refer_uri);
} catch (...) {
return tp::response(400, {
{ "message", "Bad request payload." },
});
}

SIPCall* call = phone.CallById(call_id);
if (call == nullptr) {
return tp::response(400, {
{ "message", "Call Not Found" },
{"call_id" , call_id}
});
}

auto sip_uri = tp::GetSIPURI(refer_uri, call->getAccount()->domain);
CROW_LOG_INFO << "Transfer Request to " << sip_uri ;

try {
CallOpParam prm;
call->xfer(sip_uri, &prm);
string account_name = call->getAccount()->Name();
json response = {
{ "message", "Transfering Call"},
{ "call_id", call->getId() },
{ "sid", call->getInfo().callIdString },
{ "dest", refer_uri },
{ "account", account_name }
};
return tp::response(202, response);
}
catch (pj::Error& e) {
CROW_LOG_ERROR << "Exception catched : " << e.reason;
return tp::response(500, DEFAULT_HTTP_SERVER_ERROR_REPONSE);
}
});

CROW_ROUTE(app, "/calls/<int>/dtmf/<string>")
.methods("POST"_method)
Expand Down

0 comments on commit bf9dd29

Please sign in to comment.