Skip to content

Commit

Permalink
fix #689
Browse files Browse the repository at this point in the history
  • Loading branch information
mpromonet committed Apr 25, 2024
1 parent 02fe6c7 commit 5be2290
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion inc/PeerConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class PeerConnectionManager {
};

public:
PeerConnectionManager(const std::list<std::string> & iceServerList, const Json::Value & config, webrtc::AudioDeviceModule::AudioLayer audioLayer, const std::string& publishFilter, const std::string& webrtcUdpPortRange, bool useNullCodec, bool usePlanB, int maxpc, webrtc::PeerConnectionInterface::IceTransportsType transportType);
PeerConnectionManager(const std::list<std::string> & iceServerList, const Json::Value & config, webrtc::AudioDeviceModule::AudioLayer audioLayer, const std::string& publishFilter, const std::string& webrtcUdpPortRange, bool useNullCodec, bool usePlanB, int maxpc, webrtc::PeerConnectionInterface::IceTransportsType transportType, const std::string & basePath);
virtual ~PeerConnectionManager();

bool InitializePeerConnection();
Expand Down
36 changes: 18 additions & 18 deletions src/PeerConnectionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ std::string getParam(const char *queryString, const char *paramName) {
/* ---------------------------------------------------------------------------
** Constructor
** -------------------------------------------------------------------------*/
PeerConnectionManager::PeerConnectionManager(const std::list<std::string> &iceServerList, const Json::Value & config, const webrtc::AudioDeviceModule::AudioLayer audioLayer, const std::string &publishFilter, const std::string & webrtcUdpPortRange, bool useNullCodec, bool usePlanB, int maxpc, webrtc::PeerConnectionInterface::IceTransportsType transportType)
PeerConnectionManager::PeerConnectionManager(const std::list<std::string> &iceServerList, const Json::Value & config, const webrtc::AudioDeviceModule::AudioLayer audioLayer, const std::string &publishFilter, const std::string & webrtcUdpPortRange, bool useNullCodec, bool usePlanB, int maxpc, webrtc::PeerConnectionInterface::IceTransportsType transportType, const std::string & basePath)
: m_signalingThread(rtc::Thread::Create()),
m_workerThread(rtc::Thread::Create()),
m_audioDecoderfactory(webrtc::CreateBuiltinAudioDecoderFactory()),
Expand Down Expand Up @@ -253,35 +253,35 @@ PeerConnectionManager::PeerConnectionManager(const std::list<std::string> &iceSe
m_videoaudiomap = getV4l2AlsaMap();

// register api in http server
m_func["/api/getMediaList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getMediaList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getMediaList());
};

m_func["/api/getVideoDeviceList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getVideoDeviceList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getVideoDeviceList());
};

m_func["/api/getAudioDeviceList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getAudioDeviceList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getAudioDeviceList());
};

m_func["/api/getAudioPlayoutList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getAudioPlayoutList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getAudioPlayoutList());
};

m_func["/api/getIceServers"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getIceServers"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getIceServers(req_info->remote_addr));
};

m_func["/api/call"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/call"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
std::string url = getParam(req_info->query_string, "url");
std::string audiourl = getParam(req_info->query_string, "audiourl");
std::string options = getParam(req_info->query_string, "options");
return std::make_tuple(200, std::map<std::string,std::string>(),this->call(peerid, url, audiourl, options, in));
};

m_func["/api/whep"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/whep"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
std::string videourl = getParam(req_info->query_string, "url");
std::string audiourl = getParam(req_info->query_string, "audiourl");
Expand All @@ -291,46 +291,46 @@ PeerConnectionManager::PeerConnectionManager(const std::list<std::string> &iceSe
return this->whep(req_info->request_method, url, peerid, videourl, audiourl, options, in);
};

m_func["/api/hangup"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/hangup"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
return std::make_tuple(200, std::map<std::string,std::string>(),this->hangUp(peerid));
};

m_func["/api/createOffer"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/createOffer"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
std::string url = getParam(req_info->query_string, "url");
std::string audiourl = getParam(req_info->query_string, "audiourl");
std::string options = getParam(req_info->query_string, "options");
return std::make_tuple(200, std::map<std::string,std::string>(),this->createOffer(peerid, url, audiourl, options));
};
m_func["/api/setAnswer"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/setAnswer"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
return std::make_tuple(200, std::map<std::string,std::string>(),this->setAnswer(peerid, in));
};

m_func["/api/getIceCandidate"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getIceCandidate"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
return std::make_tuple(200, std::map<std::string,std::string>(),this->getIceCandidateList(peerid));
};

m_func["/api/addIceCandidate"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/addIceCandidate"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string peerid = getParam(req_info->query_string, "peerid");
return std::make_tuple(200, std::map<std::string,std::string>(),this->addIceCandidate(peerid, in));
};

m_func["/api/getPeerConnectionList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getPeerConnectionList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getPeerConnectionList());
};

m_func["/api/getStreamList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/getStreamList"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
return std::make_tuple(200, std::map<std::string,std::string>(),this->getStreamList());
};

m_func["/api/version"] = [](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/version"] = [](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
Json::Value answer(VERSION);
return std::make_tuple(200, std::map<std::string,std::string>(), answer);
};
m_func["/api/log"] = [](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/log"] = [](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
std::string loglevel = getParam(req_info->query_string, "level");
if (!loglevel.empty())
{
Expand All @@ -339,7 +339,7 @@ PeerConnectionManager::PeerConnectionManager(const std::list<std::string> &iceSe
Json::Value answer(rtc::LogMessage::GetLogToDebug());
return std::make_tuple(200, std::map<std::string,std::string>(), answer);
};
m_func["/api/help"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
m_func[basePath + "/api/help"] = [this](const struct mg_request_info *req_info, const Json::Value &in) -> HttpServerRequestHandler::httpFunctionReturn {
Json::Value answer(Json::ValueType::arrayValue);
for (auto it : m_func) {
answer.append(it.first);
Expand Down
7 changes: 5 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int main(int argc, char* argv[])
std::string localWebrtcUdpPortRange = "0:65535";
int logLevel = rtc::LS_NONE;
const char* webroot = "./html";
std::string basePath;
std::string sslCertificate;
webrtc::AudioDeviceModule::AudioLayer audioLayer = webrtc::AudioDeviceModule::kPlatformDefaultAudio;
std::string nbthreads;
Expand Down Expand Up @@ -98,7 +99,7 @@ int main(int argc, char* argv[])

std::string streamName;
int c = 0;
while ((c = getopt (argc, argv, "hVv::C:" "c:H:w:N:A:D:Xm:I:" "T::t:S::s::R:W:" "a::q:ob" "n:u:U:")) != -1)
while ((c = getopt (argc, argv, "hVv::C:" "c:H:w:N:A:D:XB:" "m:I:" "T::t:S::s::R:W:" "a::q:ob" "n:u:U:")) != -1)
{
switch (c)
{
Expand All @@ -109,6 +110,8 @@ int main(int argc, char* argv[])
case 'A': passwdFile = optarg; break;
case 'D': authDomain = optarg; break;
case 'X': disableXframeOptions = true; break;
case 'B': basePath = optarg; break;

case 'm': maxpc = atoi(optarg); break;
case 'I': transportType = (webrtc::PeerConnectionInterface::IceTransportsType)atoi(optarg);break;

Expand Down Expand Up @@ -224,7 +227,7 @@ int main(int argc, char* argv[])
// init trials fields
webrtc::field_trial::InitFieldTrialsFromString(webrtcTrialsFields.c_str());

webRtcServer = new PeerConnectionManager(iceServerList, config["urls"], audioLayer, publishFilter, localWebrtcUdpPortRange, useNullCodec, usePlanB, maxpc, transportType);
webRtcServer = new PeerConnectionManager(iceServerList, config["urls"], audioLayer, publishFilter, localWebrtcUdpPortRange, useNullCodec, usePlanB, maxpc, transportType, basePath);
if (!webRtcServer->InitializePeerConnection())
{
std::cout << "Cannot Initialize WebRTC server" << std::endl;
Expand Down

0 comments on commit 5be2290

Please sign in to comment.