fix(realtime): isolate notification failures

This commit is contained in:
Federico Jaramillo Martinez
2026-07-17 23:58:56 +02:00
parent 45f068ef05
commit 1f13bab58a
7 changed files with 187 additions and 24 deletions
+13 -5
View File
@@ -34,9 +34,7 @@ export class SessionEventHub {
const seq = (this.seqBySession.get(sessionId) ?? 0) + 1;
this.seqBySession.set(sessionId, seq);
const payload = JSON.stringify({ ...projectBrowserSessionEvent(event), seq });
for (const socket of this.socketsBySession.get(sessionId) ?? []) {
if (socket.readyState === socket.OPEN) socket.send(payload);
}
this.sendToSockets(this.socketsBySession.get(sessionId), payload);
}
/**
@@ -55,8 +53,18 @@ export class SessionEventHub {
publishRealtime(event: RealtimeEvent): void {
const payload = JSON.stringify(event);
for (const socket of this.globalSockets) {
if (socket.readyState === socket.OPEN) socket.send(payload);
this.sendToSockets(this.globalSockets, payload);
}
private sendToSockets(sockets: Set<RealtimeSocket> | undefined, payload: string): void {
if (sockets === undefined) return;
for (const socket of sockets) {
if (socket.readyState !== socket.OPEN) continue;
try {
socket.send(payload);
} catch {
sockets.delete(socket);
}
}
}
}