First cut

This commit is contained in:
khalid@traclabs.com
2026-04-18 15:22:12 -05:00
commit 270e088c15
21 changed files with 6663 additions and 0 deletions

24
ws/broadcast.js Normal file
View File

@@ -0,0 +1,24 @@
// Central registry of all active WebSocket connections.
// Fastify-websocket exposes individual socket objects; we collect them here
// so any part of the server can broadcast without importing fastify itself.
/** @type {Set<import('ws').WebSocket>} */
const clients = new Set();
export function registerClient(socket) {
clients.add(socket);
socket.on('close', () => clients.delete(socket));
}
/**
* Broadcast a job update to every connected client.
* @param {object} payload Plain object — will be JSON-serialised.
*/
export function broadcast(payload) {
const msg = JSON.stringify(payload);
for (const ws of clients) {
if (ws.readyState === 1 /* OPEN */) {
ws.send(msg);
}
}
}