using Microsoft.AspNetCore.SignalR; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace CPRNIMS.Domain.UIServices.Updater { public class NotificationHub : Hub { // This method can be called by clients public async Task SendMessage(string user, string message) { // Broadcast the message to all connected clients await Clients.All.SendAsync("ReceiveMessage", user, message); } // This method can be used to send updates to specific groups public async Task JoinGroup(string groupName) { await Groups.AddToGroupAsync(Context.ConnectionId, groupName); } // Send message to a specific group public async Task SendMessageToGroup(string groupName, string user, string message) { await Clients.Group(groupName).SendAsync("ReceiveMessage", user, message); } // Called when a new connection is established public override async Task OnConnectedAsync() { await Clients.All.SendAsync("UserConnected", Context.ConnectionId); await base.OnConnectedAsync(); } // Called when a connection is terminated public override async Task OnDisconnectedAsync(Exception exception) { await Clients.All.SendAsync("UserDisconnected", Context.ConnectionId); await base.OnDisconnectedAsync(exception); } } }