forked from ddrilling/AsbCloudServer
39 lines
1.2 KiB
C#
39 lines
1.2 KiB
C#
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using AsbCloudApp.Services;
|
||
|
using AsbCloudWebApi.Options.Notifications;
|
||
|
using AsbCloudWebApi.SignalR.ConnectionManager;
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.Extensions.Options;
|
||
|
|
||
|
namespace AsbCloudWebApi.SignalR;
|
||
|
|
||
|
[Authorize]
|
||
|
public class NotificationHub : BaseHub
|
||
|
{
|
||
|
private readonly IConnectionManager connectionManager;
|
||
|
private readonly INotificationService notificationService;
|
||
|
private readonly NotificationsOptionsSignalR notificationsOptionsSignalR;
|
||
|
|
||
|
public NotificationHub(IConnectionManager connectionManager,
|
||
|
INotificationService notificationService,
|
||
|
IOptions<NotificationsOptionsSignalR> notificationsOptionsSignalR)
|
||
|
{
|
||
|
this.connectionManager = connectionManager;
|
||
|
this.notificationService = notificationService;
|
||
|
this.notificationsOptionsSignalR = notificationsOptionsSignalR.Value;
|
||
|
}
|
||
|
|
||
|
public async Task OnConnected(int idUser)
|
||
|
{
|
||
|
string connectionId = Context.ConnectionId;
|
||
|
|
||
|
connectionManager.AddConnection(idUser.ToString(), connectionId);
|
||
|
|
||
|
await notificationService.ResendNotificationAsync(idUser,
|
||
|
notificationsOptionsSignalR.IdTransport,
|
||
|
CancellationToken.None);
|
||
|
|
||
|
await base.OnConnectedAsync();
|
||
|
}
|
||
|
}
|