Esempio n. 1
0
 internal RtmpServer(RtmpServerOptions options, WebSocketOptions webSocketOptions)
 {
     _options          = options;
     _listener         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     _listener.NoDelay = true;
     _listener.Bind(options.RtmpEndPoint);
     _listener.Listen(128);
     _webSocketOptions = webSocketOptions;
     if (webSocketOptions != null)
     {
         _webSocketServer = new WebSocketServer($"{(options.Cert == null ? "ws" : "wss")}://{webSocketOptions.BindEndPoint.ToString()}");
     }
 }
        public RtmpServer Build()
        {
            _options         = _options ?? new RtmpServerOptions();
            _options.Startup = _startup;
            var types = Assembly.GetCallingAssembly().GetTypes();

            var registerInternalControllers = true;

            _websocketOptions._serverOptions = _options;
            foreach (var type in types)
            {
                var neverRegister = type.GetCustomAttribute <NeverRegisterAttribute>();
                if (neverRegister != null)
                {
                    continue;
                }

                if (typeof(NetStream).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    _options.RegisterStream(type);
                }
                else if (typeof(RtmpController).IsAssignableFrom(type) && !type.IsAbstract)
                {
                    _options.RegisterController(type);
                }

                if (typeof(LivingController).IsAssignableFrom(type))
                {
                    registerInternalControllers = false;
                }
                if (_useWebSocket)
                {
                    if (typeof(WebSocketController).IsAssignableFrom(type) && !type.IsAbstract)
                    {
                        _websocketOptions.RegisterController(type);
                    }
                    if (typeof(WebSocketPlayController).IsAssignableFrom(type))
                    {
                        registerInternalControllers = false;
                    }
                }
            }

            if (registerInternalControllers)
            {
                _options.RegisterController <LivingController>();
                _options.RegisterStream <LivingStream>();
                _options.RegisterStream <RecordStream>();
                _options.RegisterController <RecordController>();
                if (_useWebSocket)
                {
                    _websocketOptions.RegisterController <WebSocketPlayController>();
                }
            }

            if (_useSsl)
            {
                _options.Cert = _cert;
            }
            _options.CleanupRpcRegistration();
            _options.BuildContainer();
            var ret = new RtmpServer(_options, _websocketOptions);

            return(ret);
        }
 public RtmpServerBuilder UseHarmonic(Action <RtmpServerOptions> config)
 {
     _options = new RtmpServerOptions();
     config(_options);
     return(this);
 }
Esempio n. 4
0
 /// <summary>
 /// 验证用户用和密码
 /// </summary>
 /// <param name="conf"></param>
 /// <returns></returns>
 public RtmpServerBuilder BackIOPipeLine(Func <string, IOPipeLine, bool> tmp)
 {
     _options = _options ?? new RtmpServerOptions();
     _options.BackIOPipeLine = tmp;
     return(this);
 }
Esempio n. 5
0
 /// <summary>
 /// 验证用户用和密码
 /// </summary>
 /// <param name="conf"></param>
 /// <returns></returns>
 public RtmpServerBuilder CheckNameAndPwd(Func <string, string, bool> func)
 {
     _options          = _options ?? new RtmpServerOptions();
     _options.CheckPwd = func;
     return(this);
 }