mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-04 09:03:09 +08:00
Add datachannel c apis and callbacks(#3328)
增加datachannel数据收发的回调通知 #3326,和控制datachannel回显的开关 --------- Co-authored-by: xiongziliang <771730766@qq.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "Http/HttpClient.h"
|
||||
#include "Rtsp/RtspSession.h"
|
||||
#include "webrtc/WebRtcTransport.h"
|
||||
|
||||
using namespace toolkit;
|
||||
using namespace mediakit;
|
||||
@@ -497,4 +498,22 @@ API_EXPORT void API_CALL mk_auth_invoker_clone_release(const mk_auth_invoker ctx
|
||||
assert(ctx);
|
||||
Broadcast::AuthInvoker *invoker = (Broadcast::AuthInvoker *)ctx;
|
||||
delete invoker;
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////WebRtcTransport/////////////////////////////////////////////
|
||||
API_EXPORT void API_CALL mk_rtc_sendDatachannel(const mk_rtc_transport ctx, uint16_t streamId, uint32_t ppid, const char *msg, size_t len) {
|
||||
#ifdef ENABLE_WEBRTC
|
||||
assert(ctx && msg);
|
||||
WebRtcTransport *transport = (WebRtcTransport *)ctx;
|
||||
std::string msg_str(msg, len);
|
||||
std::weak_ptr<WebRtcTransport> weak_trans = transport->shared_from_this();
|
||||
transport->getPoller()->async([streamId, ppid, msg_str, weak_trans]() {
|
||||
// 切换线程后再操作
|
||||
if (auto trans = weak_trans.lock()) {
|
||||
trans->sendDatachannel(streamId, ppid, msg_str.c_str(), msg_str.size());
|
||||
}
|
||||
});
|
||||
#else
|
||||
WarnL << "未启用webrtc功能, 编译时请开启ENABLE_WEBRTC";
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user