示例#1
0
        public override async Task OnConnectedAsync()
        {
            var room = _roomController.GetRoomName();

            if (room == null)
            {
                await _roomController.DisconnectFromRoomAsync();

                throw new UserIsNotInTheRoomException();
            }

            Context.User.AddIdentity(new ClaimsIdentity(new[] { new Claim("room", room), }));

            await _roomController.AddToRoomAsync(room, Context.ConnectionId);

            await Groups.AddToGroupAsync(Context.ConnectionId, room);

            await Clients.Group(room).SendAsync("UserConnected", Context.User.Identity.Name);
        }
示例#2
0
        public async Task <IActionResult> Get()
        {
            await _roomController.DisconnectFromRoomAsync();

            return(Ok());
        }