forked from ddrilling/AsbCloudServer
25 lines
581 B
C#
25 lines
581 B
C#
|
using System.Collections.Concurrent;
|
||
|
|
||
|
namespace AsbCloudWebApi.SignalR.ConnectionManager;
|
||
|
|
||
|
public class ConnectionManager : IConnectionManager
|
||
|
{
|
||
|
private readonly ConcurrentDictionary<string, string> _connections = new();
|
||
|
|
||
|
public void AddConnection(string userId,
|
||
|
string connectionId)
|
||
|
{
|
||
|
_connections.TryAdd(userId, connectionId);
|
||
|
}
|
||
|
|
||
|
public void RemoveConnection(string userId)
|
||
|
{
|
||
|
_connections.TryRemove(userId, out _);
|
||
|
}
|
||
|
|
||
|
public string? GetConnectionIdByUserId(string userId)
|
||
|
{
|
||
|
_connections.TryGetValue(userId, out string? connectionId);
|
||
|
return connectionId;
|
||
|
}
|
||
|
}
|