@@ -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 = () => {