fix(presence): relay presence-leave messages and clean up listener on disconnect

- Server now relays presence-leave alongside presence messages for immediate peer removal
- Overlay properly unsubscribes leave listener on disconnectedCallback

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-03-25 16:42:49 -07:00
parent 2f8ce08e3c
commit 1c338529bf
2 changed files with 3 additions and 2 deletions

View File

@ -3451,10 +3451,10 @@ const server = Bun.serve<WSData>({
}
} else if (msg.type === "ping") {
ws.send(JSON.stringify({ type: "pong", timestamp: msg.timestamp }));
} else if (msg.type === "presence") {
} else if (msg.type === "presence" || msg.type === "presence-leave") {
const clients = communityClients.get(communitySlug);
if (clients) {
const presenceMsg = JSON.stringify({ type: "presence", peerId, ...msg });
const presenceMsg = JSON.stringify({ ...msg, peerId });
for (const [clientPeerId, client] of clients) {
if (clientPeerId !== peerId && client.readyState === WebSocket.OPEN) {
client.send(presenceMsg);

View File

@ -106,6 +106,7 @@ export class RStackCollabOverlay extends HTMLElement {
window.removeEventListener('rspace-doc-subscribe', this.#onDocSubscribe);
this.#unsubAwareness?.();
this.#unsubPresence?.();
this.#unsubLeave?.();
this.#stopMouseTracking();
this.#stopFocusTracking();
}