public async Task AddClient(HubCallerContext context, IStreamHub client)
        {
            lock (_clientsLock)
            {
                clients.Add(context.ConnectionId, new ClientInfo()
                {
                    Client  = client,
                    Context = context
                });
            }

            await _hub.Groups.AddToGroupAsync(context.ConnectionId, channelId);

            if (streamRunning)
            {
                await SendPlayEvent(context.ConnectionId);
            }
        }
Exemple #2
0
        public async Task <bool> RegisterClient(string channelId, HubCallerContext context, IStreamHub client)
        {
            _log.Information("[{0}] Registering client on channel [{1}]", context.ConnectionId, channelId);
            //TODO CHECK IF WE CAN ACCEPT {channelid}

            if (isShuttingDown)
            {
                _log.Information("[{0}] Couldn't register client on channel [{1}], system are shutting down", context.ConnectionId, channelId);
                return(false);
            }

            var isNewWorker = false;

            lock (_workersLock)
            {
                if (!workers.ContainsKey(channelId))
                {
                    isNewWorker = true;
                    var worker = _streamWorkerFactory.CreateWorker(channelId);
                    workers.Add(channelId, worker);
                }
            }

            await workers[channelId].AddClient(context, client);

            if (isNewWorker)
            {
                _ = workers[channelId].StartStream();
            }

            return(true);
        }