2026-06-10 11:16:46 +08:00
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using YD_TrainingCompetition_Api.Competition;
|
2026-06-02 10:30:05 +08:00
|
|
|
using YD_TrainingCompetition_Api.Hubs;
|
|
|
|
|
using YD_TrainingCompetition_Api.Models;
|
|
|
|
|
|
|
|
|
|
namespace YD_TrainingCompetition_Api.Services;
|
|
|
|
|
|
|
|
|
|
public sealed class SignalRRealtimeNotifier : IRealtimeNotifier
|
|
|
|
|
{
|
|
|
|
|
private readonly IHubContext<ScoringHub> _hubContext;
|
|
|
|
|
|
|
|
|
|
public SignalRRealtimeNotifier(IHubContext<ScoringHub> hubContext)
|
|
|
|
|
{
|
|
|
|
|
_hubContext = hubContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task BroadcastTelemetryAsync(DeviceSnapshot snapshot, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return _hubContext.Clients.All.SendAsync("telemetry-updated", snapshot, cancellationToken);
|
|
|
|
|
}
|
2026-06-10 11:16:46 +08:00
|
|
|
|
|
|
|
|
public Task BroadcastCompetitionStateAsync(CompetitionSessionState state, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return _hubContext.Clients.All.SendAsync("competition-state", state, cancellationToken);
|
|
|
|
|
}
|
2026-06-02 10:30:05 +08:00
|
|
|
}
|
|
|
|
|
|