Example #1
0
        private async Task handleWebSocket(WebSocket webSocket)
        {
            _clients.Add(webSocket);
            var buffer = new byte[1024];

            while (true)
            {
                var result = await webSocket.ReceiveAsync(buffer, CancellationToken.None);

                if (result.MessageType == WebSocketMessageType.Close)
                {
                    break;
                }
                else if (result.MessageType == WebSocketMessageType.Text)
                {
                    string message = Encoding.UTF8.GetString(buffer, 0, result.Count);
                    if (message == "channels")
                    {
                        // Send the client updates on all of our channels
                        var activeChannels = _streamManager.GetChannels();
                        foreach (var channel in activeChannels)
                        {
                            sendChannelUpdate(webSocket, channel);
                        }
                    }
                }
            }

            _clients.Remove(webSocket);
        }
Example #2
0
        public IActionResult Index()
        {
            var pageModel = new HomeViewModel()
            {
                Channels = _streamManager.GetChannels(),
            };

            return(View(pageModel));
        }