Skip to content

Commit 03a6a5f

Browse files
Merge 9ab910d into 01c8d2b
2 parents 01c8d2b + 9ab910d commit 03a6a5f

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

tinyphone/phone.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,5 +531,32 @@ namespace tp {
531531
return true;
532532
}
533533

534-
}
534+
bool TinyPhone::Join(SIPCall* call, SIPCall* call_to_join) {
535+
try {
536+
call_to_join->UnHoldCall();
537+
} catch(...) {
538+
PJ_LOG(3, (__FILENAME__, "TinyPhone::Join UnHoldCall Error"));
539+
return false;
540+
}
541+
542+
AudioMedia aud_med, aud_med2;
543+
try {
544+
aud_med = call->getAudioMedia(-1);
545+
aud_med2 = call_to_join->getAudioMedia(-1);
546+
} catch(...) {
547+
PJ_LOG(3, (__FILENAME__, "TinyPhone::Join getAudioMedia Error"));
548+
return false;
549+
}
550+
551+
try {
552+
// start bidirectional audio
553+
aud_med.startTransmit(aud_med2);
554+
aud_med2.startTransmit(aud_med);
555+
} catch(...) {
556+
PJ_LOG(3, (__FILENAME__, "TinyPhone::Join startTransmit Error"));
557+
return false;
558+
}
535559

560+
return true;
561+
}
562+
}

tinyphone/server.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,44 @@ void TinyPhoneHttpServer::Start() {
591591
return tp::response(200, response);
592592
}
593593
});
594-
594+
595+
CROW_ROUTE(app, "/calls/<int>/join/<int>")
596+
.methods("POST"_method)
597+
([&phone](int call_id, int call_to_join_id) {
598+
pj_thread_auto_register();
599+
600+
SIPCall* call = phone.CallById(call_id);
601+
SIPCall* call_to_join = phone.CallById(call_to_join_id);
602+
603+
if (call == nullptr) {
604+
return tp::response(400, {
605+
{ "message", "Current Call Not Found" },
606+
{ "call_id" , call_id }
607+
});
608+
}
609+
else if (call_to_join == nullptr) {
610+
return tp::response(400, {
611+
{ "message", "Call To Join Not Found" },
612+
{ "call_id" , call_to_join_id }
613+
});
614+
}
615+
else if (call->HoldState() == +HoldStatus::LOCAL_HOLD) {
616+
response["message"] = "Bad Request, CallOnHold Currently";
617+
response["status"] = "400";
618+
return tp::response(400, response);
619+
}
620+
else {
621+
json response = {
622+
{ "message", "Calls Join Triggered" },
623+
{ "call_id" , call_id },
624+
{ "call_id_ToJoin" , call_to_join_id },
625+
{ "response", phone.Join(call, call_to_join) }
626+
};
627+
628+
return tp::response(200, response);
629+
}
630+
});
631+
595632
CROW_ROUTE(app, "/calls/<int>/transfer")
596633
.methods("POST"_method)
597634
([&phone](const crow::request& req, int call_id) {

0 commit comments

Comments
 (0)