From 7f4f40a1e5d49f2e5c4eb2a07319579bd3be4097 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Tue, 24 Mar 2026 21:52:51 +0100 Subject: [PATCH] feat(ws): add wsSendAll utility for multi-instance broadcast --- packages/web/src/hooks/useWebSocket.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/web/src/hooks/useWebSocket.ts b/packages/web/src/hooks/useWebSocket.ts index a5e17e4a..a709b0f8 100644 --- a/packages/web/src/hooks/useWebSocket.ts +++ b/packages/web/src/hooks/useWebSocket.ts @@ -1067,6 +1067,15 @@ export function wsSend(event: ClientEvent, origin: string = HOME_ORIGIN): void { } } +/** Send an event to ALL connected WebSocket instances (home + remotes). */ +export function wsSendAll(event: ClientEvent): void { + for (const [_origin, conn] of connections) { + if (conn.ws && conn.ws.readyState === WebSocket.OPEN) { + conn.ws.send(JSON.stringify(event)); + } + } +} + /** * Hook to initialize the home WebSocket connection. Should only be called ONCE * from the top-level layout component (AppLayout). Other components should