Fixed signlar

This commit is contained in:
Jamie Rees 2019-04-23 10:31:35 +01:00
parent f16b33c437
commit 15d34e0aaf
8 changed files with 71 additions and 41 deletions

View 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);
}
}
}