CUB-53: add SignalR hub registration and configuration
This commit is contained in:
52
backend/Hubs/AgentStatusHub.cs
Normal file
52
backend/Hubs/AgentStatusHub.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user