on_play回调添加状态码,可选择返回未授权或未找到状态码
This commit is contained in:
parent
4a51d6b488
commit
16886b9de5
|
|
@ -311,9 +311,13 @@ typedef void* mk_auth_invoker;
|
|||
|
||||
/**
|
||||
* 执行Broadcast::AuthInvoker
|
||||
* @param err_code 响应状态码,当err_msg参数不为空时生效
|
||||
* 200 返回成功响应
|
||||
* 401 返回未授权响应
|
||||
* 404 返回未找到流响应
|
||||
* @param err_msg 为空或null则代表鉴权成功
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_auth_invoker_do(const mk_auth_invoker ctx, const char *err_msg);
|
||||
API_EXPORT void API_CALL mk_auth_invoker_do(const mk_auth_invoker ctx, int err_code, const char *err_msg);
|
||||
|
||||
/**
|
||||
* 克隆mk_auth_invoker对象,通过克隆对象为堆对象,可以实现跨线程异步执行mk_auth_invoker_do
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||
(mk_http_access_path_invoker)&invoker,
|
||||
(mk_sock_info)&sender);
|
||||
} else{
|
||||
invoker("","",0);
|
||||
invoker(200, "","",0);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||
(mk_auth_invoker) &invoker,
|
||||
(mk_sock_info) &sender);
|
||||
}else{
|
||||
invoker("");
|
||||
invoker(200, "");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -125,7 +125,7 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){
|
|||
(mk_auth_invoker) &invoker,
|
||||
(mk_sock_info) &sender);
|
||||
}else{
|
||||
invoker("");
|
||||
invoker(200, "");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -344,7 +344,8 @@ API_EXPORT void API_CALL mk_http_access_path_invoker_do(const mk_http_access_pat
|
|||
int cookie_life_second){
|
||||
assert(ctx);
|
||||
HttpSession::HttpAccessPathInvoker *invoker = (HttpSession::HttpAccessPathInvoker *)ctx;
|
||||
(*invoker)(err_msg ? err_msg : "",
|
||||
(*invoker)(401,
|
||||
err_msg ? err_msg : "",
|
||||
access_path? access_path : "",
|
||||
cookie_life_second);
|
||||
}
|
||||
|
|
@ -428,10 +429,10 @@ API_EXPORT void API_CALL mk_publish_auth_invoker_clone_release(const mk_publish_
|
|||
}
|
||||
|
||||
///////////////////////////////////////////Broadcast::AuthInvoker/////////////////////////////////////////////
|
||||
API_EXPORT void API_CALL mk_auth_invoker_do(const mk_auth_invoker ctx, const char *err_msg){
|
||||
API_EXPORT void API_CALL mk_auth_invoker_do(const mk_auth_invoker ctx, int err_code, const char *err_msg){
|
||||
assert(ctx);
|
||||
Broadcast::AuthInvoker *invoker = (Broadcast::AuthInvoker *)ctx;
|
||||
(*invoker)(err_msg ? err_msg : "");
|
||||
(*invoker)(err_code, err_msg ? err_msg : "");
|
||||
}
|
||||
|
||||
API_EXPORT mk_auth_invoker API_CALL mk_auth_invoker_clone(const mk_auth_invoker ctx){
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ void API_CALL on_mk_media_play(const mk_media_info url_info,
|
|||
mk_media_info_get_params(url_info));
|
||||
|
||||
//允许播放
|
||||
mk_auth_invoker_do(invoker, NULL);
|
||||
mk_auth_invoker_do(invoker, 200, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -427,7 +427,7 @@ void API_CALL on_mk_shell_login(const char *user_name,
|
|||
mk_sock_info_peer_port(sender),
|
||||
user_name, passwd);
|
||||
//允许登录shell
|
||||
mk_auth_invoker_do(invoker, NULL);
|
||||
mk_auth_invoker_do(invoker, 200, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ void installWebHook(){
|
|||
NoticeCenter::Instance().addListener(&web_hook_tag,Broadcast::kBroadcastMediaPlayed,[](BroadcastMediaPlayedArgs){
|
||||
GET_CONFIG(string,hook_play,Hook::kOnPlay);
|
||||
if(!hook_enable || args._param_strs == hook_adminparams || hook_play.empty() || sender.get_peer_ip() == "127.0.0.1"){
|
||||
invoker("");
|
||||
invoker(200, "");
|
||||
return;
|
||||
}
|
||||
auto body = make_json(args);
|
||||
|
|
@ -343,7 +343,11 @@ void installWebHook(){
|
|||
body["id"] = sender.getIdentifier();
|
||||
//执行hook
|
||||
do_http_hook(hook_play,body,[invoker](const Value &obj,const string &err){
|
||||
invoker(err);
|
||||
if (!err.empty()) {
|
||||
invoker(401, err);
|
||||
return;
|
||||
}
|
||||
invoker(obj["err_code"].asInt(), obj["err"].asString());
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -524,7 +528,7 @@ void installWebHook(){
|
|||
NoticeCenter::Instance().addListener(&web_hook_tag,Broadcast::kBroadcastShellLogin,[](BroadcastShellLoginArgs){
|
||||
GET_CONFIG(string,hook_shell_login,Hook::kOnShellLogin);
|
||||
if(!hook_enable || hook_shell_login.empty() || sender.get_peer_ip() == "127.0.0.1"){
|
||||
invoker("");
|
||||
invoker(200, "");
|
||||
return;
|
||||
}
|
||||
ArgsType body;
|
||||
|
|
@ -536,7 +540,7 @@ void installWebHook(){
|
|||
|
||||
//执行hook
|
||||
do_http_hook(hook_shell_login,body, [invoker](const Value &,const string &err){
|
||||
invoker(err);
|
||||
invoker(401, err);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -609,13 +613,13 @@ void installWebHook(){
|
|||
GET_CONFIG(string,hook_http_access,Hook::kOnHttpAccess);
|
||||
if(sender.get_peer_ip() == "127.0.0.1" || parser.Params() == hook_adminparams){
|
||||
//如果是本机或超级管理员访问,那么不做访问鉴权;权限有效期1个小时
|
||||
invoker("","",60 * 60);
|
||||
invoker(200, "","",60 * 60);
|
||||
return;
|
||||
}
|
||||
if(!hook_enable || hook_http_access.empty()){
|
||||
//未开启http文件访问鉴权,那么允许访问,但是每次访问都要鉴权;
|
||||
//因为后续随时都可能开启鉴权(重载配置文件后可能重新开启鉴权)
|
||||
invoker("","",0);
|
||||
invoker(200, "","",0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -633,13 +637,13 @@ void installWebHook(){
|
|||
do_http_hook(hook_http_access,body, [invoker](const Value &obj,const string &err){
|
||||
if(!err.empty()){
|
||||
//如果接口访问失败,那么仅限本次没有访问http服务器的权限
|
||||
invoker(err,"",0);
|
||||
invoker(401, err,"",0);
|
||||
return;
|
||||
}
|
||||
//err参数代表不能访问的原因,空则代表可以访问
|
||||
//path参数是该客户端能访问或被禁止的顶端目录,如果path为空字符串,则表述为当前目录
|
||||
//second参数规定该cookie超时时间,如果second为0,本次鉴权结果不缓存
|
||||
invoker(obj["err"].asString(),obj["path"].asString(),obj["second"].asInt());
|
||||
invoker(401, obj["err"].asString(),obj["path"].asString(),obj["second"].asInt());
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -80,8 +80,12 @@ extern const std::string kBroadcastMediaPublish;
|
|||
const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker, SockInfo &sender
|
||||
|
||||
// 播放鉴权结果回调对象
|
||||
// code 响应状态码,当err参数不为空时生效
|
||||
// 200返回成功响应
|
||||
// 401返回未授权响应
|
||||
// 404返回未找到流响应
|
||||
// 如果err为空则代表鉴权成功
|
||||
using AuthInvoker = std::function<void(const std::string &err)>;
|
||||
using AuthInvoker = std::function<void(int code, const std::string &err)>;
|
||||
|
||||
// 播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权
|
||||
extern const std::string kBroadcastMediaPlayed;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ class HttpCookieAttachment {
|
|||
public:
|
||||
//cookie生效作用域,本cookie只对该目录下的文件生效
|
||||
string _path;
|
||||
//上次鉴权失败Code
|
||||
int _err_code = 401;
|
||||
//上次鉴权失败信息,为空则上次鉴权成功
|
||||
string _err_msg;
|
||||
//hls直播时的其他一些信息,主要用于播放器个数计数以及流量计数
|
||||
|
|
@ -182,14 +184,14 @@ static bool makeFolderMenu(const string &httpPath, const string &strFullPath, st
|
|||
//拦截hls的播放请求
|
||||
static bool emitHlsPlayed(const Parser &parser, const MediaInfo &media_info, const HttpSession::HttpAccessPathInvoker &invoker,TcpSession &sender){
|
||||
//访问的hls.m3u8结尾,我们转换成kBroadcastMediaPlayed事件
|
||||
Broadcast::AuthInvoker auth_invoker = [invoker](const string &err) {
|
||||
Broadcast::AuthInvoker auth_invoker = [invoker](int code, const string &err) {
|
||||
//cookie有效期为kHlsCookieSecond
|
||||
invoker(err, "", kHlsCookieSecond);
|
||||
invoker(code, err, "", kHlsCookieSecond);
|
||||
};
|
||||
bool flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, media_info, auth_invoker, static_cast<SockInfo &>(sender));
|
||||
if (!flag) {
|
||||
//未开启鉴权,那么允许播放
|
||||
auth_invoker("");
|
||||
auth_invoker(200, "");
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
|
@ -236,7 +238,7 @@ public:
|
|||
* 5、触发kBroadcastHttpAccess事件
|
||||
*/
|
||||
static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaInfo &media_info, bool is_dir,
|
||||
const function<void(const string &err_msg, const HttpServerCookie::Ptr &cookie)> &callback) {
|
||||
const function<void(int code, const string &err_msg, const HttpServerCookie::Ptr &cookie)> &callback) {
|
||||
//获取用户唯一id
|
||||
auto uid = parser.Params();
|
||||
auto path = parser.Url();
|
||||
|
|
@ -262,13 +264,13 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
|||
cookie->updateTime();
|
||||
update_cookie = true;
|
||||
}
|
||||
callback("", update_cookie ? cookie : nullptr);
|
||||
callback(attach._err_code, "", update_cookie ? cookie : nullptr);
|
||||
return;
|
||||
}
|
||||
//上次鉴权失败,但是如果url参数发生变更,那么也重新鉴权下
|
||||
if (parser.Params().empty() || parser.Params() == cookie->getUid()) {
|
||||
//url参数未变,或者本来就没有url参数,那么判断本次请求为重复请求,无访问权限
|
||||
callback(attach._err_msg, update_cookie ? cookie : nullptr);
|
||||
callback(attach._err_code, attach._err_msg, update_cookie ? cookie : nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -287,7 +289,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
|||
|
||||
//该用户从来未获取过cookie,这个时候我们广播是否允许该用户访问该http目录
|
||||
HttpSession::HttpAccessPathInvoker accessPathInvoker = [callback, uid, path, is_dir, is_hls, media_info, info]
|
||||
(const string &err_msg, const string &cookie_path_in, int life_second) {
|
||||
(int code, const string &err_msg, const string &cookie_path_in, int life_second) {
|
||||
HttpServerCookie::Ptr cookie;
|
||||
if (life_second) {
|
||||
//本次鉴权设置了有效期,我们把鉴权结果缓存在cookie中
|
||||
|
|
@ -301,14 +303,15 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
|||
//记录用户能访问的路径
|
||||
attach->_path = cookie_path;
|
||||
//记录能否访问
|
||||
attach->_err_code = code;
|
||||
attach->_err_msg = err_msg;
|
||||
if (is_hls) {
|
||||
// hls相关信息
|
||||
attach->_hls_data = std::make_shared<HlsCookieData>(media_info, info);
|
||||
}
|
||||
callback(err_msg, HttpCookieManager::Instance().addCookie(kCookieName, uid, life_second, attach));
|
||||
callback(code, err_msg, HttpCookieManager::Instance().addCookie(kCookieName, uid, life_second, attach));
|
||||
} else {
|
||||
callback(err_msg, nullptr);
|
||||
callback(code, err_msg, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -322,7 +325,7 @@ static void canAccessPath(TcpSession &sender, const Parser &parser, const MediaI
|
|||
bool flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastHttpAccess, parser, path, is_dir, accessPathInvoker, static_cast<SockInfo &>(sender));
|
||||
if (!flag) {
|
||||
//此事件无人监听,我们默认都有权限访问
|
||||
callback("", nullptr);
|
||||
callback(200, "", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -367,7 +370,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
|||
|
||||
weak_ptr<TcpSession> weakSession = sender.shared_from_this();
|
||||
//判断是否有权限访问该文件
|
||||
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession](const string &err_msg, const HttpServerCookie::Ptr &cookie) {
|
||||
canAccessPath(sender, parser, media_info, false, [cb, file_path, parser, is_hls, media_info, weakSession](int code, const string &err_msg, const HttpServerCookie::Ptr &cookie) {
|
||||
auto strongSession = weakSession.lock();
|
||||
if (!strongSession) {
|
||||
// http客户端已经断开,不需要回复
|
||||
|
|
@ -379,7 +382,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
|||
if (cookie) {
|
||||
headerOut["Set-Cookie"] = cookie->getCookie(cookie->getAttach<HttpCookieAttachment>()._path);
|
||||
}
|
||||
cb(401, "text/html", headerOut, std::make_shared<HttpStringBody>(err_msg));
|
||||
cb(code, "text/html", headerOut, std::make_shared<HttpStringBody>(err_msg));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -505,7 +508,7 @@ void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const Htt
|
|||
return;
|
||||
}
|
||||
//判断是否有权限访问该目录
|
||||
canAccessPath(sender, parser, media_info, true, [strMenu, cb](const string &err_msg, const HttpServerCookie::Ptr &cookie) mutable{
|
||||
canAccessPath(sender, parser, media_info, true, [strMenu, cb](int code, const string &err_msg, const HttpServerCookie::Ptr &cookie) mutable{
|
||||
if (!err_msg.empty()) {
|
||||
strMenu = err_msg;
|
||||
}
|
||||
|
|
@ -513,7 +516,7 @@ void HttpFileManager::onAccessPath(TcpSession &sender, Parser &parser, const Htt
|
|||
if (cookie) {
|
||||
headerOut["Set-Cookie"] = cookie->getCookie(cookie->getAttach<HttpCookieAttachment>()._path);
|
||||
}
|
||||
cb(err_msg.empty() ? 200 : 401, "text/html", headerOut, std::make_shared<HttpStringBody>(strMenu));
|
||||
cb(err_msg.empty() ? 200 : code, "text/html", headerOut, std::make_shared<HttpStringBody>(strMenu));
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
|
|||
weak_ptr<HttpSession> weak_self = dynamic_pointer_cast<HttpSession>(shared_from_this());
|
||||
|
||||
//鉴权结果回调
|
||||
auto onRes = [cb, weak_self, close_flag](const string &err) {
|
||||
auto onRes = [cb, weak_self, close_flag](int code, const string &err) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
//本对象已经销毁
|
||||
|
|
@ -220,7 +220,7 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
|
|||
|
||||
if (!err.empty()) {
|
||||
//播放鉴权失败
|
||||
strong_self->sendResponse(401, close_flag, nullptr, KeyValue(), std::make_shared<HttpStringBody>(err));
|
||||
strong_self->sendResponse(code, close_flag, nullptr, KeyValue(), std::make_shared<HttpStringBody>(err));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -242,16 +242,16 @@ bool HttpSession::checkLiveStream(const string &schema, const string &url_suffi
|
|||
});
|
||||
};
|
||||
|
||||
Broadcast::AuthInvoker invoker = [weak_self, onRes](const string &err) {
|
||||
Broadcast::AuthInvoker invoker = [weak_self, onRes](int code, const string &err) {
|
||||
if (auto strong_self = weak_self.lock()) {
|
||||
strong_self->async([onRes, err]() { onRes(err); });
|
||||
strong_self->async([onRes, code, err]() { onRes(code, err); });
|
||||
}
|
||||
};
|
||||
|
||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _mediaInfo, invoker, static_cast<SockInfo &>(*this));
|
||||
if (!flag) {
|
||||
//该事件无人监听,默认不鉴权
|
||||
onRes("");
|
||||
onRes(200, "");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,11 +33,12 @@ public:
|
|||
typedef HttpResponseInvokerImp HttpResponseInvoker;
|
||||
friend class AsyncSender;
|
||||
/**
|
||||
* @param code 鉴权未通过时返回的状态码
|
||||
* @param errMsg 如果为空,则代表鉴权通过,否则为错误提示
|
||||
* @param accessPath 运行或禁止访问的根目录
|
||||
* @param cookieLifeSecond 鉴权cookie有效期
|
||||
**/
|
||||
typedef std::function<void(const std::string &errMsg,const std::string &accessPath, int cookieLifeSecond)> HttpAccessPathInvoker;
|
||||
typedef std::function<void(int code, const std::string &errMsg, const std::string &accessPath, int cookieLifeSecond)> HttpAccessPathInvoker;
|
||||
|
||||
HttpSession(const toolkit::Socket::Ptr &pSock);
|
||||
~HttpSession() override;
|
||||
|
|
|
|||
|
|
@ -332,7 +332,7 @@ void RtmpSession::sendPlayResponse(const string &err, const RtmpMediaSource::Ptr
|
|||
setSocketFlags();
|
||||
}
|
||||
|
||||
void RtmpSession::doPlayResponse(const string &err,const std::function<void(bool)> &cb){
|
||||
void RtmpSession::doPlayResponse(int code, const string &err,const std::function<void(bool)> &cb){
|
||||
if(!err.empty()){
|
||||
//鉴权失败,直接返回播放失败
|
||||
sendPlayResponse(err, nullptr);
|
||||
|
|
@ -361,24 +361,24 @@ void RtmpSession::doPlay(AMFDecoder &dec){
|
|||
DebugP(strong_self.get()) << "play 回复时间:" << ticker->elapsedTime() << "ms";
|
||||
}
|
||||
}));
|
||||
Broadcast::AuthInvoker invoker = [weak_self,token](const string &err){
|
||||
Broadcast::AuthInvoker invoker = [weak_self,token](int code, const string &err){
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return;
|
||||
}
|
||||
strong_self->async([weak_self, err, token]() {
|
||||
strong_self->async([weak_self, code, err, token]() {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return;
|
||||
}
|
||||
strong_self->doPlayResponse(err, [token](bool) {});
|
||||
strong_self->doPlayResponse(code, err, [token](bool) {});
|
||||
});
|
||||
};
|
||||
|
||||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _media_info, invoker, static_cast<SockInfo &>(*this));
|
||||
if(!flag){
|
||||
//该事件无人监听,默认不鉴权
|
||||
doPlayResponse("",[token](bool){});
|
||||
doPlayResponse(200, "",[token](bool){});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ private:
|
|||
void onCmd_play(AMFDecoder &dec);
|
||||
void onCmd_play2(AMFDecoder &dec);
|
||||
void doPlay(AMFDecoder &dec);
|
||||
void doPlayResponse(const std::string &err,const std::function<void(bool)> &cb);
|
||||
void doPlayResponse(int code, const std::string &err,const std::function<void(bool)> &cb);
|
||||
void sendPlayResponse(const std::string &err,const RtmpMediaSource::Ptr &src);
|
||||
|
||||
void onCmd_seek(AMFDecoder &dec);
|
||||
|
|
|
|||
|
|
@ -328,27 +328,33 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
|
|||
void RtspSession::emitOnPlay(){
|
||||
weak_ptr<RtspSession> weak_self = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||
//url鉴权回调
|
||||
auto onRes = [weak_self](const string &err) {
|
||||
auto onRes = [weak_self](int code, const string &err) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return;
|
||||
}
|
||||
if (!err.empty()) {
|
||||
//播放url鉴权失败
|
||||
strong_self->sendRtspResponse("401 Unauthorized", {"Content-Type", "text/plain"}, err);
|
||||
strong_self->shutdown(SockException(Err_shutdown, StrPrinter << "401 Unauthorized:" << err));
|
||||
if (code == 404) {
|
||||
strong_self->sendRtspResponse("404 NotFound", {"Content-Type", "text/plain"}, err);
|
||||
strong_self->shutdown(SockException(Err_shutdown, StrPrinter << "404 NotFound:" << err));
|
||||
} else {
|
||||
strong_self->sendRtspResponse("401 Unauthorized", {"Content-Type", "text/plain"}, err);
|
||||
strong_self->shutdown(SockException(Err_shutdown, StrPrinter << "401 Unauthorized:" << err));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
strong_self->onAuthSuccess();
|
||||
};
|
||||
|
||||
Broadcast::AuthInvoker invoker = [weak_self, onRes](const string &err) {
|
||||
Broadcast::AuthInvoker invoker = [weak_self, onRes](int code, const string &err) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return;
|
||||
}
|
||||
strong_self->async([onRes, err, weak_self]() {
|
||||
onRes(err);
|
||||
strong_self->async([onRes, code, err, weak_self]() {
|
||||
onRes(code, err);
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -356,7 +362,7 @@ void RtspSession::emitOnPlay(){
|
|||
auto flag = _emit_on_play ? false : NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, _media_info, invoker, static_cast<SockInfo &>(*this));
|
||||
if (!flag) {
|
||||
//该事件无人监听,默认不鉴权
|
||||
onRes("");
|
||||
onRes(200, "");
|
||||
}
|
||||
//已经鉴权过了
|
||||
_emit_on_play = true;
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ inline void ShellSession::pleaseInputPasswd() {
|
|||
};
|
||||
|
||||
weak_ptr<ShellSession> weakSelf = dynamic_pointer_cast<ShellSession>(shared_from_this());
|
||||
Broadcast::AuthInvoker invoker = [weakSelf,onAuth](const string &errMessage){
|
||||
Broadcast::AuthInvoker invoker = [weakSelf,onAuth](int code, const string &errMessage){
|
||||
auto strongSelf = weakSelf.lock();
|
||||
if(!strongSelf){
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ void SrtTransportImp::emitOnPublish() {
|
|||
|
||||
void SrtTransportImp::emitOnPlay() {
|
||||
std::weak_ptr<SrtTransportImp> weak_self = static_pointer_cast<SrtTransportImp>(shared_from_this());
|
||||
Broadcast::AuthInvoker invoker = [weak_self](const string &err) {
|
||||
Broadcast::AuthInvoker invoker = [weak_self](int code, const string &err) {
|
||||
auto strong_self = weak_self.lock();
|
||||
if (!strong_self) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -143,14 +143,14 @@ void initEventListener() {
|
|||
//监听rtsp/rtsps/rtmp/http-flv播放事件,返回结果告知是否有播放权限(rtsp通过kBroadcastOnRtspAuth或此事件都可以实现鉴权)
|
||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastMediaPlayed, [](BroadcastMediaPlayedArgs) {
|
||||
DebugL << "播放鉴权:" << args.getUrl() << " " << args._param_strs;
|
||||
invoker("");//鉴权成功
|
||||
invoker(200, "");//鉴权成功
|
||||
//invoker("this is auth failed message");//鉴权失败
|
||||
});
|
||||
|
||||
//shell登录事件,通过shell可以登录进服务器执行一些命令
|
||||
NoticeCenter::Instance().addListener(nullptr, Broadcast::kBroadcastShellLogin, [](BroadcastShellLoginArgs) {
|
||||
DebugL << "shell login:" << user_name << " " << passwd;
|
||||
invoker("");//鉴权成功
|
||||
invoker(200, "");//鉴权成功
|
||||
//invoker("this is auth failed message");//鉴权失败
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1185,7 +1185,7 @@ void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
|||
void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
|
||||
MediaInfo info(args["url"]);
|
||||
auto session_ptr = sender.shared_from_this();
|
||||
Broadcast::AuthInvoker invoker = [cb, info, session_ptr](const string &err) mutable {
|
||||
Broadcast::AuthInvoker invoker = [cb, info, session_ptr](int code, const string &err) mutable {
|
||||
if (!err.empty()) {
|
||||
cb(WebRtcException(SockException(Err_other, err)));
|
||||
return;
|
||||
|
|
@ -1210,7 +1210,7 @@ void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
|
|||
auto flag = NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastMediaPlayed, info, invoker, static_cast<SockInfo &>(sender));
|
||||
if (!flag) {
|
||||
// 该事件无人监听,默认不鉴权
|
||||
invoker("");
|
||||
invoker(200, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue