C API和WebHook未找到流回调添加直接关闭机制 (#1948)

This commit is contained in:
huangxiuqi 2022-09-09 10:55:35 +08:00 committed by GitHub
parent 7f86299c80
commit 258a4dd166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View File

@ -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

View File

@ -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();
}
}
});

View File

@ -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;
}
/**

View File

@ -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) {