From 82bc41654608089d2751f66dc9e47cbe2644e8a8 Mon Sep 17 00:00:00 2001 From: Johnny Date: Fri, 21 Apr 2023 20:23:26 +0800 Subject: [PATCH] add exchangeSdp --- api/source/mk_common.cpp | 2 +- server/WebApi.cpp | 4 ++-- webrtc/WebRtcTransport.cpp | 4 ++++ webrtc/WebRtcTransport.h | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/source/mk_common.cpp b/api/source/mk_common.cpp index 0430e685..1604af61 100644 --- a/api/source/mk_common.cpp +++ b/api/source/mk_common.cpp @@ -308,7 +308,7 @@ API_EXPORT void API_CALL mk_webrtc_get_answer_sdp2(void *user_data, on_user_data WebRtcPluginManager::Instance().getAnswerSdp(*session, type, WebRtcArgsUrl(url), [offer_str, session, ptr, cb](const WebRtcInterface &exchanger) mutable { try { - auto sdp_answer = const_cast(exchanger).getAnswerSdp(offer_str); + auto sdp_answer = exchangeSdp(exchanger, offer_str); cb(ptr.get(), sdp_answer.data(), nullptr); } catch (std::exception &ex) { cb(ptr.get(), nullptr, ex.what()); diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 18056a10..89abf584 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1604,7 +1604,7 @@ void installWebApi() { headerOut["Access-Control-Allow-Origin"] = "*"; try { - val["sdp"] = const_cast(exchanger).getAnswerSdp(offer); + val["sdp"] = exchangeSdp(exchanger, offer); val["id"] = exchanger.getIdentifier(); val["type"] = "answer"; invoker(200, headerOut, val.toStyledString()); @@ -1628,7 +1628,7 @@ void installWebApi() { try { // 设置返回类型 headerOut["Content-Type"] = "application/sdp"; - invoker(201, headerOut, const_cast(exchanger).getAnswerSdp(offer)); + invoker(201, headerOut, exchangeSdp(exchanger, offer)); } catch (std::exception &ex) { headerOut["Content-Type"] = "text/plain"; invoker(406, headerOut, ex.what()); diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 347f870c..dae2f533 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -1131,6 +1131,10 @@ void WebRtcPluginManager::registerPlugin(const string &type, Plugin cb) { _map_creator[type] = std::move(cb); } +std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& offer) { + return const_cast(exchanger).getAnswerSdp(offer); +} + void WebRtcPluginManager::getAnswerSdp(Session &sender, const string &type, const WebRtcArgs &args, const onCreateRtc &cb) { lock_guard lck(_mtx_creator); auto it = _map_creator.find(type); diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index dfae8012..eb33b090 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -43,6 +43,8 @@ public: virtual const std::string &getIdentifier() const = 0; }; +std::string exchangeSdp(const WebRtcInterface &exchanger, const std::string& offer); + class WebRtcException : public WebRtcInterface { public: WebRtcException(const SockException &ex) : _ex(ex) {};