You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.9 KiB
67 lines
1.9 KiB
using AX.WebDrillServer.Middlewares.Jwts; |
|
using Microsoft.AspNetCore.Authorization; |
|
using Microsoft.AspNetCore.SignalR; |
|
using System.Security.Claims; |
|
|
|
namespace AX.WebDrillServer.Hubs |
|
{ |
|
[Authorize] |
|
public class NotificationHub : Hub<INotificationClient> |
|
{ |
|
private readonly ILogger<NotificationHub> _logger; |
|
|
|
public NotificationHub( |
|
ILogger<NotificationHub> logger |
|
) |
|
{ |
|
_logger = logger; |
|
} |
|
|
|
#if !RELEASE |
|
|
|
public async Task SendMessage(string message) |
|
{ |
|
var userId = Context.UserIdentifier; |
|
var userName = Context.User?.FindFirstValue(JwtClaimTypes.Name); |
|
_logger.LogInformation("{message}", message); |
|
//await Clients.All.ReceiveNotification(userName ?? userId, message); |
|
} |
|
|
|
public Task CallA(string message, int i) |
|
{ |
|
return Task.CompletedTask; |
|
} |
|
|
|
#endif |
|
|
|
public override async Task OnConnectedAsync() |
|
{ |
|
try |
|
{ |
|
var userId = Context.UserIdentifier; |
|
var userName = Context.User?.FindFirstValue(JwtClaimTypes.Name); |
|
_logger.LogInformation("[{userId}][{name}] connected", userId, userName); |
|
await base.OnConnectedAsync(); |
|
} |
|
catch (Exception) |
|
{ |
|
throw; |
|
} |
|
} |
|
|
|
public override async Task OnDisconnectedAsync(Exception? exception) |
|
{ |
|
try |
|
{ |
|
var userId = Context.UserIdentifier; |
|
var userName = Context.User?.FindFirstValue(JwtClaimTypes.Name); |
|
_logger.LogInformation("[{userId}][{name}] disconnected", userId, userName); |
|
await base.OnDisconnectedAsync(exception); |
|
} |
|
catch (Exception) |
|
{ |
|
throw; |
|
} |
|
} |
|
} |
|
} |