diff --git a/inc/PeerConnectionManager.h b/inc/PeerConnectionManager.h index 0f57d133..ed2a67e6 100755 --- a/inc/PeerConnectionManager.h +++ b/inc/PeerConnectionManager.h @@ -318,7 +318,7 @@ class PeerConnectionManager { }; public: - PeerConnectionManager(const std::list & 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 & 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(); diff --git a/src/PeerConnectionManager.cpp b/src/PeerConnectionManager.cpp index f51aedb2..638ee220 100755 --- a/src/PeerConnectionManager.cpp +++ b/src/PeerConnectionManager.cpp @@ -223,7 +223,7 @@ std::string getParam(const char *queryString, const char *paramName) { /* --------------------------------------------------------------------------- ** Constructor ** -------------------------------------------------------------------------*/ -PeerConnectionManager::PeerConnectionManager(const std::list &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 &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()), @@ -253,27 +253,27 @@ PeerConnectionManager::PeerConnectionManager(const std::list &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(),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(),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(),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(),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(),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"); @@ -281,7 +281,7 @@ PeerConnectionManager::PeerConnectionManager(const std::list &iceSe return std::make_tuple(200, std::map(),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"); @@ -291,46 +291,46 @@ PeerConnectionManager::PeerConnectionManager(const std::list &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(),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(),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(),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(),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(),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(),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(),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(), 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()) { @@ -339,7 +339,7 @@ PeerConnectionManager::PeerConnectionManager(const std::list &iceSe Json::Value answer(rtc::LogMessage::GetLogToDebug()); return std::make_tuple(200, std::map(), 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); diff --git a/src/main.cpp b/src/main.cpp index e3c6e2c3..ab542122 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; @@ -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) { @@ -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; @@ -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;