39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
|
|
using Microsoft.AspNetCore.SignalR;
|
||
|
|
|
||
|
|
namespace NexusRMM.Api.Hubs;
|
||
|
|
|
||
|
|
public class RmmHub : Hub<IRmmHubClient>
|
||
|
|
{
|
||
|
|
private readonly ILogger<RmmHub> _logger;
|
||
|
|
|
||
|
|
public RmmHub(ILogger<RmmHub> logger)
|
||
|
|
{
|
||
|
|
_logger = logger;
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>Frontend tritt der Gruppe für einen bestimmten Agent bei</summary>
|
||
|
|
public async Task JoinAgentGroup(string agentId)
|
||
|
|
{
|
||
|
|
await Groups.AddToGroupAsync(Context.ConnectionId, $"agent-{agentId}");
|
||
|
|
_logger.LogDebug("Client {ConnectionId} joined group agent-{AgentId}", Context.ConnectionId, agentId);
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>Frontend verlässt die Gruppe für einen Agent</summary>
|
||
|
|
public async Task LeaveAgentGroup(string agentId)
|
||
|
|
{
|
||
|
|
await Groups.RemoveFromGroupAsync(Context.ConnectionId, $"agent-{agentId}");
|
||
|
|
}
|
||
|
|
|
||
|
|
public override async Task OnConnectedAsync()
|
||
|
|
{
|
||
|
|
_logger.LogInformation("SignalR client connected: {ConnectionId}", Context.ConnectionId);
|
||
|
|
await base.OnConnectedAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
public override async Task OnDisconnectedAsync(Exception? exception)
|
||
|
|
{
|
||
|
|
_logger.LogInformation("SignalR client disconnected: {ConnectionId}", Context.ConnectionId);
|
||
|
|
await base.OnDisconnectedAsync(exception);
|
||
|
|
}
|
||
|
|
}
|