2023-07-10 16:59:11 +05:00
|
|
|
using System.Collections.Concurrent;
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.SignalR.ConnectionManager;
|
|
|
|
|
|
|
|
public class ConnectionManager : IConnectionManager
|
|
|
|
{
|
2023-07-11 19:07:57 +05:00
|
|
|
private readonly ConcurrentDictionary<int, string> _connections = new();
|
2023-07-10 16:59:11 +05:00
|
|
|
|
2023-07-11 19:07:57 +05:00
|
|
|
public void AddConnection(int userId,
|
2023-07-10 16:59:11 +05:00
|
|
|
string connectionId)
|
|
|
|
{
|
|
|
|
_connections.TryAdd(userId, connectionId);
|
|
|
|
}
|
|
|
|
|
2023-07-11 19:07:57 +05:00
|
|
|
public void RemoveConnection(int userId)
|
2023-07-10 16:59:11 +05:00
|
|
|
{
|
|
|
|
_connections.TryRemove(userId, out _);
|
|
|
|
}
|
|
|
|
|
2023-07-11 19:07:57 +05:00
|
|
|
public string? GetConnectionIdByUserId(int userId)
|
2023-07-10 16:59:11 +05:00
|
|
|
{
|
2023-07-11 19:07:57 +05:00
|
|
|
_connections.TryGetValue(userId, out var connectionId);
|
2023-07-10 16:59:11 +05:00
|
|
|
return connectionId;
|
|
|
|
}
|
|
|
|
}
|