Example #1
0
        /// <summary>
        /// Create a Router.
        /// </summary>
        public async Task <Router?> CreateRouterAsync(RouterOptions routerOptions)
        {
            if (_closed)
            {
                return(null);
            }

            await _closeLock.WaitAsync();

            try
            {
                if (_closed)
                {
                    return(null);
                }

                _logger.LogDebug("CreateRouterAsync()");

                // This may throw.
                var rtpCapabilities = ORTC.GenerateRouterRtpCapabilities(routerOptions.MediaCodecs);

                var @internal = new { RouterId = Guid.NewGuid().ToString() };

                await _channel.RequestAsync(MethodId.WORKER_CREATE_ROUTER, @internal);

                var router = new Router(_loggerFactory, @internal.RouterId, rtpCapabilities, _channel, _payloadChannel, AppData);

                lock (_routersLock)
                {
                    _routers.Add(router);
                }

                router.On("@close", _ =>
                {
                    lock (_routersLock)
                    {
                        _routers.Remove(router);
                    }
                    return(Task.CompletedTask);
                });

                // Emit observer event.
                Observer.Emit("newrouter", router);

                return(router);
            }
            finally
            {
                _closeLock.Set();
            }
        }
Example #2
0
        /// <summary>
        /// Create a Router.
        /// </summary>
        public async Task <Router> CreateRouter(RouterOptions routerOptions)
        {
            _logger.LogDebug("CreateRouter()");

            // This may throw.
            var rtpCapabilities = ORTC.GenerateRouterRtpCapabilities(routerOptions.MediaCodecs);

            var @internal = new { RouterId = Guid.NewGuid().ToString() };

            await _channel.RequestAsync(MethodId.WORKER_CREATE_ROUTER, @internal);

            var router = new Router(_loggerFactory, @internal.RouterId, rtpCapabilities, _channel, AppData);

            _routers.Add(router);

            router.On("@close", _ => _routers.Remove(router));

            // Emit observer event.
            Observer.Emit("newrouter", router);

            return(router);
        }