xonecas.io
8058
Ir

irvc / commit d0e6dd0

fix: do not remake the websocket on wake() right away

Now it sends a ping to see if the connection is healthy

xonecas2026-10-16 d0e6dd04ddce2a7fcfae1fb75b03b38b3f4d5b2d parent 68ddbd2

1 file changed

web/src/lib/presence.ts+9−2
@@ -85,12 +85,19 @@ export function usePresence(onEvent: (ev: WSEvent) => void, onOpen: () => void)
8585 }
8686 }, PING);
8787
88+ // wake runs when the tab becomes visible again or the network returns. A
89+ // healthy socket only gets a liveness probe; tearing it down would force a
90+ // reconnect (and a roster resync) for no reason. A socket that is not OPEN
91+ // is dropped, and an OPEN one is dropped by the heartbeat if the probe goes
92+ // unanswered.
8893 const wake = () => {
8994 if (closed) return;
9095 window.clearTimeout(reconnecting);
9196 retry = 0;
92- if (socket.current) drop();
93- else open();
97+ const ws = socket.current;
98+ if (!ws) return open();
99+ if (ws.readyState === WebSocket.OPEN) return ws.send('{"type":"ping"}');
100+ drop();
94101 };
95102
96103 const onVisibility = () => {