实现思路
先拨通第一个号码,再桥接到另一个号码
核心代码
// 初始化一个handle,用于标识到FreeSWITCH的Socket连接
esl_handle_t handle = {{ 0 }};
// std::string ip = ...;
// int port = ...;
// std::string password = ...;
// 连接服务器,如果成功 handle 就代表连接成功了
esl_status_t status = esl_connect(&handle, ip, port, NULL, password);
// 错误处理
// ...
// std::string gatewayName = ...
// std::string tel1 = ...
// std::string tel2 = ...
// 这里为核心命令,即 originate number1 &bridge(number2)
// tel1 和 tel2 即为要互联的两个电话号码
std::ostringstream oss;
oss << "api originate sofia/gateway/" << gatewayName << "/" << tel1
<< " &bridge(sofia/gateway/" << gatewayName << "/" << tel2 << ")\n\n";
esl_send_recv(&handle, oss.str().c_str());
// 错误处理
// ...
// 断开连接
esl_disconnect(&handle);