public override async Task OnDisconnectedAsync(Exception exception) { string connectionId = Context.ConnectionId; string groupName = ConnectionObserver.GetCurrentGroupName(connectionId); ConnectionObserver.ConnectionStates.Remove(Context.ConnectionId); if (groupName != null) { var playersList = ConnectionObserver.GetPlayersList(groupName); await Clients.Group(groupName).RefreshPlayersList(playersList); } await base.OnDisconnectedAsync(exception); }
public async Task DisconnectFromGame([GameCode] string gameCode) { int.TryParse(Context.Items[KeyConstants.GameCode] as string, out int gameId); _logger.LogInformation($"Connection:{Context.ConnectionId} is leaving group {gameCode}"); await Groups.RemoveFromGroupAsync(Context.ConnectionId, gameCode); await Clients.GroupExcept(gameCode, Context.ConnectionId).SendMessage($"Player {Context.User.Identity.Name} has left.", MessageType.Warning); string connectionId = Context.ConnectionId; string groupName = ConnectionObserver.GetCurrentGroupName(connectionId); ConnectionObserver.ConnectionStates.Remove(Context.ConnectionId); if (groupName != null) { var playersList = ConnectionObserver.GetPlayersList(groupName); await Clients.Group(groupName).RefreshPlayersList(playersList); } }