codexmobile-relay / server /app-sockets.js
Codex
deploy: CodexMobile Relay
90f0300
Raw
History Blame Contribute Delete
345 Bytes
export const sockets = new Set();
export function broadcast(payload) {
const serialized = JSON.stringify(payload);
for (const socket of sockets) {
if (socket.readyState === socket.OPEN) {
socket.send(serialized);
}
}
}
export function addBrowserSocket(ws) {
sockets.add(ws);
ws.on('close', () => sockets.delete(ws));
}