mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-14 17:22:54 -07:00
Fixed signlar
This commit is contained in:
parent
f16b33c437
commit
15d34e0aaf
8 changed files with 71 additions and 41 deletions
39
src/Ombi.Hubs/NotificationHub.cs
Normal file
39
src/Ombi.Hubs/NotificationHub.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Xml;
|
||||
|
||||
namespace Ombi.Hubs
|
||||
{
|
||||
public class NotificationHub : Hub
|
||||
{
|
||||
public static ConcurrentDictionary<string, string> UsersOnline = new ConcurrentDictionary<string, string>();
|
||||
|
||||
public override Task OnConnectedAsync()
|
||||
{
|
||||
var identity = (ClaimsIdentity) Context.User.Identity;
|
||||
var userIdClaim = identity.Claims.FirstOrDefault(x => x.Type.Equals("Id", StringComparison.InvariantCultureIgnoreCase));
|
||||
if (userIdClaim == null)
|
||||
{
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
UsersOnline.TryAdd(Context.ConnectionId, userIdClaim.Value);
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
public override Task OnDisconnectedAsync(Exception exception)
|
||||
{
|
||||
UsersOnline.TryRemove(Context.ConnectionId, out _);
|
||||
return base.OnDisconnectedAsync(exception);
|
||||
}
|
||||
|
||||
public Task Notification(string data)
|
||||
{
|
||||
return Clients.All.SendAsync("Notification", data);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue