From 258a4dd1662d0994069ccbb96d57cadfb24dbc7c Mon Sep 17 00:00:00 2001 From: huangxiuqi <1417617276@qq.com> Date: Fri, 9 Sep 2022 10:55:35 +0800 Subject: [PATCH] =?UTF-8?q?C=20API=E5=92=8CWebHook=E6=9C=AA=E6=89=BE?= =?UTF-8?q?=E5=88=B0=E6=B5=81=E5=9B=9E=E8=B0=83=E6=B7=BB=E5=8A=A0=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=85=B3=E9=97=AD=E6=9C=BA=E5=88=B6=20(#1948)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_events.h | 7 ++++--- api/source/mk_events.cpp | 6 ++++-- api/tests/server.c | 5 ++++- server/WebHook.cpp | 11 ++++++++++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/api/include/mk_events.h b/api/include/mk_events.h index 2692ccd2..c628a0ec 100644 --- a/api/include/mk_events.h +++ b/api/include/mk_events.h @@ -53,8 +53,10 @@ typedef struct { * 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了 * @param url_info 播放url相关信息 * @param sender 播放客户端相关信息 + * @return 1 直接关闭 + * 0 等待流注册 */ - void (API_CALL *on_mk_media_not_found)(const mk_media_info url_info, + int (API_CALL *on_mk_media_not_found)(const mk_media_info url_info, const mk_sock_info sender); /** @@ -152,7 +154,7 @@ typedef struct { size_t total_seconds, int is_player, const mk_sock_info sender); - + /** * 日志输出广播 @@ -178,4 +180,3 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events); } #endif #endif //MK_EVENTS_H - diff --git a/api/source/mk_events.cpp b/api/source/mk_events.cpp index cd68419d..43e3362c 100644 --- a/api/source/mk_events.cpp +++ b/api/source/mk_events.cpp @@ -141,8 +141,10 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){ NoticeCenter::Instance().addListener(&s_tag,Broadcast::kBroadcastNotFoundStream,[](BroadcastNotFoundStreamArgs){ if (s_events.on_mk_media_not_found) { - s_events.on_mk_media_not_found((mk_media_info) &args, - (mk_sock_info) &sender); + if (s_events.on_mk_media_not_found((mk_media_info) &args, + (mk_sock_info) &sender)) { + closePlayer(); + } } }); diff --git a/api/tests/server.c b/api/tests/server.c index cd400fd4..9b1d713c 100644 --- a/api/tests/server.c +++ b/api/tests/server.c @@ -88,8 +88,10 @@ void API_CALL on_mk_media_play(const mk_media_info url_info, * 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了 * @param url_info 播放url相关信息 * @param sender 播放客户端相关信息 + * @return 1 直接关闭 + * 0 等待流注册 */ -void API_CALL on_mk_media_not_found(const mk_media_info url_info, +int API_CALL on_mk_media_not_found(const mk_media_info url_info, const mk_sock_info sender) { char ip[64]; log_printf(LOG_LEV, @@ -104,6 +106,7 @@ void API_CALL on_mk_media_not_found(const mk_media_info url_info, mk_media_info_get_app(url_info), mk_media_info_get_stream(url_info), mk_media_info_get_params(url_info)); + return 0; } /** diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 0bfd4fda..a59dd551 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -505,8 +505,17 @@ void installWebHook(){ body["ip"] = sender.get_peer_ip(); body["port"] = sender.get_peer_port(); body["id"] = sender.getIdentifier(); + + // Hook回复立即关闭流 + auto res_cb = [closePlayer](const Value &res, const string &err) { + bool flag = res["close"].asBool(); + if (flag) { + closePlayer(); + } + }; + //执行hook - do_http_hook(hook_stream_not_found, body, nullptr); + do_http_hook(hook_stream_not_found, body, res_cb); }); static auto getRecordInfo = [](const RecordInfo &info) {