38 lines
904 B
C#
38 lines
904 B
C#
using System.Net.WebSockets;
|
|
|
|
namespace MauMau_Server.Websockets;
|
|
|
|
public class WebsocketManager : IWebsocketManager
|
|
{
|
|
private static readonly Dictionary<string, WebSocket> Connections = new();
|
|
|
|
public string AddConnection(WebSocket socket)
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
Connections.Add(id, socket);
|
|
return id;
|
|
}
|
|
|
|
public WebSocket GetConnection(string id)
|
|
{
|
|
return Connections[id];
|
|
}
|
|
|
|
public Dictionary<string, WebSocket> GetAllConnections()
|
|
{
|
|
return Connections;
|
|
}
|
|
|
|
public void RemoveConnection(string id)
|
|
{
|
|
Connections.Remove(id);
|
|
}
|
|
}
|
|
|
|
public interface IWebsocketManager
|
|
{
|
|
public string AddConnection(WebSocket socket);
|
|
public WebSocket GetConnection(string id);
|
|
public Dictionary<string, WebSocket> GetAllConnections();
|
|
public void RemoveConnection(string id);
|
|
} |