// helpers.js — safeSend and broadcastToUser without importing from index // (avoids circular dependency index→wsHandler→index) export function safeSend(ws, data) { if (ws.readyState === 1) ws.send(JSON.stringify(data)); } // broadcastToUser needs access to wsClients which lives in index. // We pass it as a parameter instead. export function broadcastToUser(wsClients, userId, data, excludeWs = null) { for (const [ws, c] of wsClients) if (c.userId === userId && ws !== excludeWs && ws.readyState === 1) ws.send(JSON.stringify(data)); }