(ws, msg, context = '')
| 78 | } |
| 79 | |
| 80 | function sendWs(ws, msg, context = '') { |
| 81 | if (!ws || ws.readyState !== WebSocket.OPEN) return false; |
| 82 | ws.send(JSON.stringify(msg)); |
| 83 | if (msg.type === 'status' || msg.type === 'transcript_ready' || msg.type === 'replay_done' || msg.type === 'turn_state') { |
| 84 | const extra = []; |
| 85 | if (msg.sessionId !== undefined) extra.push(`session=${msg.sessionId ?? 'null'}`); |
| 86 | if (msg.lastSeq !== undefined) extra.push(`lastSeq=${msg.lastSeq}`); |
| 87 | if (msg.resumed !== undefined) extra.push(`resumed=${msg.resumed}`); |
| 88 | if (msg.phase !== undefined) extra.push(`phase=${msg.phase}`); |
| 89 | if (msg.version !== undefined) extra.push(`version=${msg.version}`); |
| 90 | log(`Send ${msg.type}${context ? ` (${context})` : ''} -> ${wsLabel(ws)}${extra.length ? ` ${extra.join(' ')}` : ''}`); |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | function broadcast(msg) { |
| 96 | if (!state.wss) return; |
no test coverage detected