From 24eaaf68fb40e06b22121445f69bc731efbe23b2 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 8 Apr 2023 21:28:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E6=94=AF=E6=8C=81webrtc=20wh?= =?UTF-8?q?ip/whep(=E6=8E=A8=E6=8B=89=E6=B5=81)=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit whip推流地址: /index/api/whip?app=live&stream=test whep拉流地址: /index/api/whep?app=live&stream=test --- server/WebApi.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 20ce4a88..e99bcb76 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1615,6 +1615,29 @@ void installWebApi() { } }); }); + + static auto whip_whep_func = [](const char *type, API_ARGS_STRING_ASYNC) { + auto offer = allArgs.getArgs(); + CHECK(!offer.empty(), "http body(webrtc offer sdp) is empty"); + + WebRtcPluginManager::Instance().getAnswerSdp(*(static_cast(&sender)), type, + WebRtcArgsImp(allArgs, sender.getIdentifier()), + [invoker, offer, headerOut](const WebRtcInterface &exchanger) mutable { + // 设置跨域 + headerOut["Access-Control-Allow-Origin"] = "*"; + try { + // 设置返回类型 + headerOut["Content-Type"] = "application/sdp"; + invoker(201, headerOut, const_cast(exchanger).getAnswerSdp(offer)); + } catch (std::exception &ex) { + headerOut["Content-Type"] = "text/plain"; + invoker(406, headerOut, ex.what()); + } + }); + }; + + api_regist("/index/api/whip", [](API_ARGS_STRING_ASYNC) { whip_whep_func("push", API_ARGS_VALUE, invoker); }); + api_regist("/index/api/whep", [](API_ARGS_STRING_ASYNC) { whip_whep_func("play", API_ARGS_VALUE, invoker); }); #endif #if defined(ENABLE_VERSION)