forked from ddrilling/AsbCloudServer
25 lines
638 B
C#
25 lines
638 B
C#
using System.Collections.Concurrent;
|
|
|
|
namespace AsbCloudWebApi.SignalR.Services;
|
|
|
|
public class ConnectionManagerService
|
|
{
|
|
private readonly ConcurrentDictionary<int, string> connections = new();
|
|
|
|
public void AddOrUpdateConnection(int userId, string connectionId)
|
|
{
|
|
connections.AddOrUpdate(userId, connectionId,
|
|
(key, existingConnectionId) => connectionId);
|
|
}
|
|
|
|
public void RemoveConnection(int userId)
|
|
{
|
|
connections.TryRemove(userId, out _);
|
|
}
|
|
|
|
public string? GetConnectionIdByUserId(int userId)
|
|
{
|
|
connections.TryGetValue(userId, out var connectionId);
|
|
return connectionId;
|
|
}
|
|
} |