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-07-02 10:05:51 +08:00
|
|
|
|
|
|
|
|
public Task SendAsync(string method, object? payload, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return _hubContext.Clients.All.SendAsync(method, payload ?? new { }, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task BroadcastHikvisionAlarmAsync(AlarmRecord record, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return _hubContext.Clients.All.SendAsync("HikvisionAlarmReceived", record, cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task BroadcastHikvisionCameraStatusAsync(HikvisionCameraStatus status, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
return _hubContext.Clients.All.SendAsync("HikvisionCameraStatusChanged", status, cancellationToken);
|
|
|
|
|
}
|
2026-06-02 10:30:05 +08:00
|
|
|
}
|
|
|
|
|
|