Skip to content

Commit bd3fedb

Browse files
Merge d525141 into 01c8d2b
2 parents 01c8d2b + d525141 commit bd3fedb

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ The softphone exposes the following resources on port `6060`.
134134
<td>Break specified <code>call_id</code> out of conference</td>
135135
</tr>
136136
<tr>
137+
<td><code>/calls/{call_id}/join/{call_to_join_id}</code></td>
138+
<td>POST</td>
139+
<td></td>
140+
<td>Merges the current call (<code>call_id</code>) with another running call (<code>call_to_join_id</code>)</td>
141+
</tr>
142+
<tr>
137143
<td><code>/calls/{call_id}/transfer</code></td>
138144
<td>POST</td>
139145
<td>

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/phone.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ namespace tp {
122122

123123
bool Conference(SIPCall* call);
124124
bool BreakConference(SIPCall* call);
125+
126+
bool Join(SIPCall* call, SIPCall* call_to_join);
125127

126128
void HangupAllCalls();
127129

tinyphone/server.cpp

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,51 @@ 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+
{ "call_to_join_id" , call_to_join_id },
608+
});
609+
}
610+
else if (call_to_join == nullptr) {
611+
return tp::response(400, {
612+
{ "message", "Call To Join Not Found" },
613+
{ "call_id" , call_id },
614+
{ "call_to_join_id" , call_to_join_id }
615+
});
616+
}
617+
else if (call->HoldState() == +HoldStatus::LOCAL_HOLD) {
618+
json response = {
619+
{ "message", "Bad Request, CallOnHold Currently" },
620+
{ "call_id" , call_id },
621+
{ "call_to_join_id" , call_to_join_id },
622+
{ "status", "400" }
623+
};
624+
625+
return tp::response(400, response);
626+
}
627+
else {
628+
json response = {
629+
{ "message", "Calls Join Triggered" },
630+
{ "call_id" , call_id },
631+
{ "call_to_join_id" , call_to_join_id },
632+
{ "response", phone.Join(call, call_to_join) }
633+
};
634+
635+
return tp::response(200, response);
636+
}
637+
});
638+
595639
CROW_ROUTE(app, "/calls/<int>/transfer")
596640
.methods("POST"_method)
597641
([&phone](const crow::request& req, int call_id) {

0 commit comments

Comments
 (0)