初步支持webrtc whip/whep(推拉流)协议

whip推流地址: /index/api/whip?app=live&stream=test
whep拉流地址: /index/api/whep?app=live&stream=test
This commit is contained in:
xiongziliang 2023-04-08 21:28:17 +08:00
parent c090fc3ea0
commit 24eaaf68fb

View File

@ -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<Session *>(&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<WebRtcInterface &>(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 #endif
#if defined(ENABLE_VERSION) #if defined(ENABLE_VERSION)