Skip to content

chengxiaosheng/ZLMediaKit.HttpApi

Repository files navigation

ZLMediaKit.HttpApi

基于优秀的开源项目 ZLMediaKit 提供的Restful Api 实现数据请求

实现功能

  • 封装 ZLMediaKit的Restful Api接口,提供快捷访问
  • 支持配置多个MediaKit
  • 支持动态添加 MediaKit (比如通过Web Hook动态注册)

快速开始

  1. 注入服务
    services.AddZLMediaKitHttpClient(option =>
    {
        //ZLMediaKit IP地址
        option.IpAddress = "127.0.0.1";
        //ZLMediaKit Http 端口
        option.ApiPort = 80;
        //ZLMediaKit 密钥
        option.ApiSecret = "035c73f7-bb6b-4889-a715-d9eb2d1925cc";
    });

    //  -------------------------------------------------------------------------------------
	//通过Web Hook 动态注册
    private void ZLMediaKitWebHookEvents_OnServerStarted(Dtos.ServerConfig obj)
    {
        ZLHttpClientRegister.Register(new ZLMediaKitSettings
        {
            ApiPort = obj.Http.Port,
            ApiSecret = obj.Api.Secret,
            HttpSchema = HttpSchema.http,
            IpAddress = obj.ServerIp.ToString(),
            MediaServerId = obj.General.MediaServerId
        });
    }
  1. 使用
    public class Test
    {
        private readonly ZLHttpClient _zlhttpClient;
        public Test(ZLHttpClient zlhttpClient)
        {
            this._zlhttpClient = zlhttpClient
        }
		//如果您只有一个MediaKit交互,请直接使用此处的方式
        public CallTest()
        {
            _zlhttpClient.GetThreadsLoad();
            _zlhttpClient.GetWorkThreadsLoad();
            _zlhttpClient.GetServerConfig();
            _zlhttpClient.SetServerConfig();
            _zlhttpClient.RestartServer();
            _zlhttpClient.GetMediaList();
           .
           .
           .
        }
        
        //多个MediaKit 调用方式
        //就算您只有一个 MediaKit交互,也可以使用此方法,(但是在服务注册时必须填写 mediaServerId)
        public CallTest1()
        {
            _zlhttpClient.SetMediaServerId("ZLMediaKit配置文件中的,mediaServerId").GetThreadsLoad();
            _zlhttpClient.SetMediaServerId("ZLMediaKit配置文件中的,mediaServerId").GetWorkThreadsLoad();
            _zlhttpClient.SetMediaServerId("ZLMediaKit配置文件中的,mediaServerId").GetServerConfig();
            _zlhttpClient.SetMediaServerId("ZLMediaKit配置文件中的,mediaServerId").SetServerConfig();
            _zlhttpClient.SetMediaServerId("ZLMediaKit配置文件中的,mediaServerId").RestartServer();
            _zlhttpClient.SetMediaServerId("ZLMediaKit配置文件中的,mediaServerId").GetMediaList();
           .
           .
           .
        }

    }

ZLMediaKit.WebHook

基于优秀的开源项目 ZLMediaKit 提供的 Web Hook实现接收请求

实现功能

  • 接入 ZLMediaKit WebHook
  • 自定义路由路径
  • 以事件的形式访问

快速开始

  1. 注入服务
    //routePrefix 参数设定路由前缀
    //实际接口路径为 routePrefix/action
    //ps : index/hook/on_flow_report
    //routePrefix = app/index/api/test
    //ps : app/index/api/test/on_flow_report
    services.AddMediaKitWebHook(new APIRouteOptions(routePrefix : "index/hook"); 
  1. 绑定事件
   ZLMediaKitWebHookEvents.OnFlowReport += ZLMediaKitWebHookEvents_OnFlowReport;
   ZLMediaKitWebHookEvents.OnHttpAccess += ZLMediaKitWebHookEvents_OnHttpAccess;
   ZLMediaKitWebHookEvents.OnPlay += ZLMediaKitWebHookEvents_OnPlay;
   ZLMediaKitWebHookEvents.OnPublish += ZLMediaKitWebHookEvents_OnPublish;
   ZLMediaKitWebHookEvents.OnRecordMP4 += ZLMediaKitWebHookEvents_OnRecordMP4;
   ZLMediaKitWebHookEvents.OnRtspAuth += ZLMediaKitWebHookEvents_OnRtspAuth;
   ZLMediaKitWebHookEvents.OnRtspRealm += ZLMediaKitWebHookEvents_OnRtspRealm;
   ZLMediaKitWebHookEvents.OnServerStarted += ZLMediaKitWebHookEvents_OnServerStarted;
   ZLMediaKitWebHookEvents.OnShellLogin += ZLMediaKitWebHookEvents_OnShellLogin;
   ZLMediaKitWebHookEvents.OnStreamChanged += ZLMediaKitWebHookEvents_OnStreamChanged;
   ZLMediaKitWebHookEvents.OnStreamNoneReader += LMediaKitWebHookEvents_OnStreamNoneReader;
   ZLMediaKitWebHookEvents.OnStreamNotFound += LMediaKitWebHookEvents_OnStreamNotFound;

致敬

一个优秀而强大的流媒体服务器 ZLMediaKit

About

基于NetCore 的ZLMediaKit Http Api 客户端

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages