Use IHubContext for delayed slip completion
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
Avoid ObjectDisposedException when sending SignalR updates after the 30-second delay by accessing clients through IHubContext instead of the disposed hub instance. Signed-off-by: Tim Krampitz <Tim.Krampitz@live.com>
This commit is contained in:
@@ -14,12 +14,18 @@ public class GameHub : Hub
|
||||
private readonly IGameService _gameService;
|
||||
private readonly IDbContextFactory<SlipItInDbContext> _contextFactory;
|
||||
private readonly ILogger<GameHub> _logger;
|
||||
private readonly IHubContext<GameHub> _hubContext;
|
||||
|
||||
public GameHub(IGameService gameService, IDbContextFactory<SlipItInDbContext> contextFactory, ILogger<GameHub> logger)
|
||||
public GameHub(
|
||||
IGameService gameService,
|
||||
IDbContextFactory<SlipItInDbContext> contextFactory,
|
||||
ILogger<GameHub> logger,
|
||||
IHubContext<GameHub> hubContext)
|
||||
{
|
||||
_gameService = gameService;
|
||||
_contextFactory = contextFactory;
|
||||
_logger = logger;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -260,10 +266,10 @@ public class GameHub : Hub
|
||||
var targetP = await db.Players.FindAsync(playerId);
|
||||
if (targetP?.ConnectionId != null)
|
||||
{
|
||||
await Clients.Client(targetP.ConnectionId).SendAsync("PlayerHandUpdated", updatedHand);
|
||||
await _hubContext.Clients.Client(targetP.ConnectionId).SendAsync("PlayerHandUpdated", updatedHand);
|
||||
}
|
||||
|
||||
await Clients.Group(game.LobbyCode).SendAsync("GameStateUpdated", updatedGameState);
|
||||
await _hubContext.Clients.Group(game.LobbyCode).SendAsync("GameStateUpdated", updatedGameState);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user