Example #1
0
        public async Task Invoke(HttpContext context)
        {
            if (!context.WebSockets.IsWebSocketRequest)
            {
                return;
            }

            var socket = await context.WebSockets.AcceptWebSocketAsync();

            string userName = context.Request.Query["userName"];

            var channels = channelBusiness.GetAllChannels();

            foreach (var channel in channels)
            {
                await _webSocketHandler.OnConnected(socket, userName, channel);
            }

            await Receive(socket, async (result, buffer) =>
            {
                if (result.MessageType == WebSocketMessageType.Text)
                {
                    await _webSocketHandler.Receive(socket, result, buffer);
                    return;
                }
                else if (result.MessageType == WebSocketMessageType.Close)
                {
                    await _webSocketHandler.OnDisconnected(socket);
                    return;
                }
            });
        }
Example #2
0
        public JsonResult ChatChannels()
        {
            IList <string> channels = channelBusiness.GetAllChannels();

            return(Json(channels));
        }