The websocket handle the ping / pong

This commit is contained in:
2025-07-29 17:14:35 +08:00
parent 4246fea03f
commit 05c6410550
3 changed files with 26 additions and 3 deletions

View File

@@ -109,6 +109,20 @@ public class WebSocketService
WebSocket socket
)
{
if (packet.Type == WebSocketPacketType.Ping)
{
await socket.SendAsync(
new ArraySegment<byte>(new WebSocketPacket
{
Type = WebSocketPacketType.Pong
}.ToBytes()),
WebSocketMessageType.Binary,
true,
CancellationToken.None
);
return;
}
if (_handlerMap.TryGetValue(packet.Type, out var handler))
{
await handler.HandleAsync(currentUser, deviceId, packet, socket, this);
@@ -176,4 +190,4 @@ public class WebSocketService
CancellationToken.None
);
}
}
}