52 lines
1.8 KiB
C#
52 lines
1.8 KiB
C#
using Microsoft.AspNetCore.SignalR;
|
|
|
|
namespace ControlCenter.Api.Hubs;
|
|
|
|
/// <summary>
|
|
/// SignalR hub for broadcasting agent status updates to connected clients.
|
|
///
|
|
/// <para>
|
|
/// Clients connect to this hub at the <c>/hub</c> endpoint to receive
|
|
/// real-time agent state changes. A background service subscribes to
|
|
/// OpenClaw Gateway events and pushes them through this hub.
|
|
/// </para>
|
|
///
|
|
/// <para>
|
|
/// Architecture note: This hub bridges OpenClaw Gateway events to SignalR clients.
|
|
/// The full typed client interface and extension methods will be added in a
|
|
/// subsequent task (CUB-55).
|
|
/// </para>
|
|
/// </summary>
|
|
public class AgentStatusHub : Hub
|
|
{
|
|
private readonly ILogger<AgentStatusHub> _logger;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AgentStatusHub"/> class.
|
|
/// </summary>
|
|
/// <param name="logger">Logger for diagnostic output.</param>
|
|
public AgentStatusHub(ILogger<AgentStatusHub> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Overrides <see cref="Hub.OnConnectedAsync"/> to log new connections.
|
|
/// </summary>
|
|
public override Task OnConnectedAsync()
|
|
{
|
|
_logger.LogDebug("Client connected: {ConnectionId}", Context.ConnectionId);
|
|
return base.OnConnectedAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Overrides <see cref="Hub.OnDisconnectedAsync"/> to log disconnections.
|
|
/// SignalR automatically removes disconnected connections from all groups.
|
|
/// </summary>
|
|
/// <param name="exception">Exception that caused the disconnection, if any.</param>
|
|
public override Task OnDisconnectedAsync(Exception? exception)
|
|
{
|
|
_logger.LogDebug("Client disconnected: {ConnectionId}", Context.ConnectionId);
|
|
return base.OnDisconnectedAsync(exception);
|
|
}
|
|
} |