Commit 6b621d42 by xiongziliang

优化接口

parent 7823d2c1
......@@ -38,11 +38,12 @@ using namespace mediakit;
namespace API {
typedef enum {
InvalidArgs = -300,
SqlFailed = -200,
AuthFailed = -100,
OtherFailed = -1,
Success = 0
Exception = -400,//代码抛异常
InvalidArgs = -300,//参数不合法
SqlFailed = -200,//sql执行失败
AuthFailed = -100,//鉴权失败
OtherFailed = -1,//业务代码执行失败,
Success = 0//执行成功
} ApiErr;
#define API_FIELD "api."
......@@ -208,7 +209,7 @@ static inline void addHttpListener(){
}
#endif// ENABLE_MYSQL
catch (std::exception &ex) {
val["code"] = API::OtherFailed;
val["code"] = API::Exception;
val["msg"] = ex.what();
invoker("200 OK", headerOut, val.toStyledString());
}
......@@ -448,9 +449,11 @@ void installWebApi() {
bool flag = src->close(allArgs["force"].as<bool>());
val["result"] = flag ? 0 : -1;
val["msg"] = flag ? "success" : "close failed";
val["code"] = API::OtherFailed;
}else{
val["result"] = -2;
val["msg"] = "can not find the stream";
val["code"] = API::OtherFailed;
}
});
......@@ -726,21 +729,25 @@ void installWebApi() {
api_regist1("/index/api/startRecord",[](API_ARGS1){
CHECK_SECRET();
CHECK_ARGS("type","vhost","app","stream");
val["result"] = Recorder::startRecord((Recorder::type) allArgs["type"].as<int>(),
auto result = Recorder::startRecord((Recorder::type) allArgs["type"].as<int>(),
allArgs["vhost"],
allArgs["app"],
allArgs["stream"],
allArgs["customized_path"]);
val["result"] = result;
val["code"] = result ? API::Success : API::OtherFailed;
});
// 停止录制hls或MP4
api_regist1("/index/api/stopRecord",[](API_ARGS1){
CHECK_SECRET();
CHECK_ARGS("type","vhost","app","stream");
val["result"] = Recorder::stopRecord((Recorder::type) allArgs["type"].as<int>(),
auto result = Recorder::stopRecord((Recorder::type) allArgs["type"].as<int>(),
allArgs["vhost"],
allArgs["app"],
allArgs["stream"]);
val["result"] = result;
val["code"] = result ? API::Success : API::OtherFailed;
});
// 获取hls或MP4录制状态
......@@ -803,12 +810,10 @@ void installWebApi() {
api_regist1("/index/hook/on_play",[](API_ARGS1){
//开始播放事件
throw SuccessException();
});
api_regist1("/index/hook/on_flow_report",[](API_ARGS1){
//流量统计hook api
throw SuccessException();
});
api_regist1("/index/hook/on_rtsp_realm",[](API_ARGS1){
......@@ -828,7 +833,6 @@ void installWebApi() {
api_regist1("/index/hook/on_stream_changed",[](API_ARGS1){
//媒体注册或反注册事件
throw SuccessException();
});
......@@ -891,12 +895,10 @@ void installWebApi() {
api_regist1("/index/hook/on_record_mp4",[](API_ARGS1){
//录制mp4分片完毕事件
throw SuccessException();
});
api_regist1("/index/hook/on_shell_login",[](API_ARGS1){
//shell登录调试事件
throw SuccessException();
});
api_regist1("/index/hook/on_stream_none_reader",[](API_ARGS1){
......@@ -932,7 +934,6 @@ void installWebApi() {
api_regist1("/index/hook/on_server_started",[](API_ARGS1){
//服务器重启报告
throw SuccessException();
});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论