using System; using System.Threading; using System.Threading.Tasks; using AsbCloudApp.Data; using AsbCloudApp.Services.Notifications; using AsbCloudWebApi.SignalR.ConnectionManager; using Microsoft.AspNetCore.Authorization; namespace AsbCloudWebApi.SignalR; [Authorize] public class NotificationHub : BaseHub { private readonly IConnectionManager connectionManager; private readonly INotificationService notificationService; public NotificationHub(IConnectionManager connectionManager, INotificationService notificationService) { this.connectionManager = connectionManager; this.notificationService = notificationService; } public async Task OnConnected(int idUser) { try { string connectionId = Context.ConnectionId; connectionManager.AddConnection(idUser, connectionId); await notificationService.ResendNotificationAsync(idUser, NotificationTransport.SignalR, CancellationToken.None); await base.OnConnectedAsync(); } catch (Exception e) { Console.WriteLine(e); } } public Task OnDisconnected(int idUser) { connectionManager.RemoveConnection(idUser); return base.OnDisconnectedAsync(null); } }