Archived
fix(realtime): isolate notification failures
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user