推流鉴权事件支持是否允许转rtsp/rtmp、hls 、mp4

This commit is contained in:
xiongziliang
2019-09-10 11:06:31 +08:00
parent 15539bc27e
commit e67894a085
10 changed files with 92 additions and 38 deletions

View File

@@ -581,7 +581,12 @@ void installWebApi() {
////////////以下是注册的Hook API////////////
API_REGIST(hook,on_publish,{
//开始推流事件
throw SuccessException();
//转换成rtsp或rtmp
val["enableRtxp"] = true;
//转换hls
val["enableHls"] = true;
//不录制mp4
val["enableMP4"] = false;
});
API_REGIST(hook,on_play,{

View File

@@ -195,7 +195,7 @@ void installWebHook(){
NoticeCenter::Instance().addListener(nullptr,Broadcast::kBroadcastMediaPublish,[](BroadcastMediaPublishArgs){
if(!hook_enable || args._param_strs == hook_adminparams || hook_publish.empty() || sender.get_peer_ip() == "127.0.0.1"){
invoker("");
invoker("",true, true,false);
return;
}
//异步执行该hook api防止阻塞NoticeCenter
@@ -205,7 +205,23 @@ void installWebHook(){
body["id"] = sender.getIdentifier();
//执行hook
do_http_hook(hook_publish,body,[invoker](const Value &obj,const string &err){
invoker(err);
if(err.empty()){
//推流鉴权成功
bool enableRtxp = true;
bool enableHls = true;
bool enableMP4 = false;
//加try catch目的是兼容之前的hook接口用户可以不传递enableRtxp、enableHls、enableMP4参数
try { enableRtxp = obj["enableRtxp"].asBool(); } catch (...) {}
try { enableHls = obj["enableHls"].asBool(); } catch (...) {}
try { enableMP4 = obj["enableMP4"].asBool(); } catch (...) {}
invoker(err,enableRtxp,enableHls,enableMP4);
}else{
//推流鉴权失败
invoker(err,false, false, false);
}
});
});