♻️ Update the websocket dupe conn handle

This commit is contained in:
2025-08-08 03:06:20 +08:00
parent d0ca8db162
commit 5859483654

View File

@@ -39,6 +39,16 @@ public class WebSocketController(WebSocketService ws, ILogger<WebSocketContext>
if (!ws.TryAdd(connectionKey, webSocket, cts)) if (!ws.TryAdd(connectionKey, webSocket, cts))
{ {
await webSocket.SendAsync(
new ArraySegment<byte>(new WebSocketPacket
{
Type = "error.dupe",
ErrorMessage = "Too many connections from the same device and account."
}.ToBytes()),
WebSocketMessageType.Close,
true,
CancellationToken.None
);
await webSocket.CloseAsync( await webSocket.CloseAsync(
WebSocketCloseStatus.PolicyViolation, WebSocketCloseStatus.PolicyViolation,
"Too many connections from the same device and account.", "Too many connections from the same device and account.",