Files
BeReadyBackend/BeReadyBackend/Hubs/GroupHub.cs
T
2026-03-01 14:50:01 +01:00

33 lines
973 B
C#

using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Primitives;
namespace BeReadyBackend.Hubs;
public class GroupHub : Hub
{
public async Task SendProofToGroup(int groupId, string proofUrl)
{
await Clients.Group($"group-{groupId}").SendAsync("ReceiveProof", proofUrl);
}
public async Task SendMessageToGroup(int groupId, string message)
{
await Clients.Group($"group-{groupId}").SendAsync("ReceiveMessage", message);
}
public async Task StartVoteIntoGroup(int groupId)
{
await Clients.Group($"group-{groupId}").SendAsync("StartVote");
}
public override async Task OnConnectedAsync()
{
HttpContext? httpContext = Context.GetHttpContext();
if (httpContext!.Request.Query.TryGetValue("groupId", out StringValues groupId))
{
await Groups.AddToGroupAsync(Context.ConnectionId, $"group-{groupId}");
}
await base.OnConnectedAsync();
}
}