Skip to content

Commit

Permalink
Merge 357706c into 01c8d2b
Browse files Browse the repository at this point in the history
  • Loading branch information
pdesaulniers-vertisoft committed Nov 24, 2023
2 parents 01c8d2b + 357706c commit 524b2d5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
29 changes: 28 additions & 1 deletion tinyphone/phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,5 +531,32 @@ namespace tp {
return true;
}

}
bool TinyPhone::Join(SIPCall* call, SIPCall* call_to_join) {
try {
call_to_join->UnHoldCall();
} catch(...) {
PJ_LOG(3, (__FILENAME__, "TinyPhone::Join UnHoldCall Error"));
return false;
}

AudioMedia aud_med, aud_med2;
try {
aud_med = call->getAudioMedia(-1);
aud_med2 = call_to_join->getAudioMedia(-1);
} catch(...) {
PJ_LOG(3, (__FILENAME__, "TinyPhone::Join getAudioMedia Error"));
return false;
}

try {
// start bidirectional audio
aud_med.startTransmit(aud_med2);
aud_med2.startTransmit(aud_med);
} catch(...) {
PJ_LOG(3, (__FILENAME__, "TinyPhone::Join startTransmit Error"));
return false;
}

return true;
}
}
2 changes: 2 additions & 0 deletions tinyphone/phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ namespace tp {

bool Conference(SIPCall* call);
bool BreakConference(SIPCall* call);

bool Join(SIPCall* call, SIPCall* call_to_join);

void HangupAllCalls();

Expand Down
39 changes: 38 additions & 1 deletion tinyphone/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,44 @@ void TinyPhoneHttpServer::Start() {
return tp::response(200, response);
}
});


CROW_ROUTE(app, "/calls/<int>/join/<int>")
.methods("POST"_method)
([&phone](int call_id, int call_to_join_id) {
pj_thread_auto_register();

SIPCall* call = phone.CallById(call_id);
SIPCall* call_to_join = phone.CallById(call_to_join_id);

if (call == nullptr) {
return tp::response(400, {
{ "message", "Current Call Not Found" },
{ "call_id" , call_id }
});
}
else if (call_to_join == nullptr) {
return tp::response(400, {
{ "message", "Call To Join Not Found" },
{ "call_id" , call_to_join_id }
});
}
else if (call->HoldState() == +HoldStatus::LOCAL_HOLD) {
response["message"] = "Bad Request, CallOnHold Currently";
response["status"] = "400";
return tp::response(400, response);
}
else {
json response = {
{ "message", "Calls Join Triggered" },
{ "call_id" , call_id },
{ "call_id_ToJoin" , call_to_join_id },
{ "response", phone.Join(call, call_to_join) }
};

return tp::response(200, response);
}
});

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

0 comments on commit 524b2d5

Please sign in to comment.