fix: send pong back to client
avoid disconnections every 2.5 minutes
This commit is contained in:
@@ -44,8 +44,12 @@ func (c *Conn) ReadPump(ctx context.Context, hub *Hub) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore keep-alive pings
|
// Respond to keep-alive pings
|
||||||
if string(data) == "ping" {
|
if string(data) == "ping" {
|
||||||
|
if err := c.ws.Write(ctx, websocket.MessageText, []byte("pong")); err != nil {
|
||||||
|
slog.Debug("websocket pong write error", "connId", c.id, "error", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,9 @@ export class PusherClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleMessage(data: string): void {
|
private handleMessage(data: string): void {
|
||||||
|
// Ignore keep-alive pong responses
|
||||||
|
if (data === "pong") return;
|
||||||
|
|
||||||
let msg: ServerMessage;
|
let msg: ServerMessage;
|
||||||
try {
|
try {
|
||||||
msg = JSON.parse(data);
|
msg = JSON.parse(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user