public async Task Combine(string roomCode, int role) { await Groups.AddToGroupAsync(Context.ConnectionId, roomCode); var room = _roomService.FindRoom(roomCode); var userName = Context.User.FindFirst(ClaimTypes.Name).Value; var userId = int.Parse(Context.User.FindFirst("UserId").Value); if (room == null) { room = new PokingRoom(roomCode, new User(userName, userId, "standBy", (Role)role, 0), "waiting"); _roomService.Add(room); var users = room.GetUsers(); await Clients.Caller.SendAsync("joinRoom", new { users, roomState = room.State, currentStoryPoint = room.CurrentStoryPoint }); } else { room.AddUser(new User(userName, int.Parse(Context.User.FindFirst("UserId").Value), "standBy", (Role)role, 0)); var users = room.GetUsers(); await Clients.GroupExcept(roomCode, Context.ConnectionId).SendAsync("newUserConnected", new { name = userName, id = userId, status = "standBy", point = 0, role }); await Clients.Caller.SendAsync("joinRoom", new { users, roomState = room.State, currentStoryPoint = room.CurrentStoryPoint }); await Clients.Caller.SendAsync("currentStoryChanged", new { id = room.CurrentStoryId }); } }
public void Add(PokingRoom newRoom) { Rooms.Add(newRoom); }