WebSocket API
WebSocket API
Complete reference for the WebSocket API for real-time updates.
Connection
Connect to the WebSocket server:
const ws = new WebSocket('ws://localhost:3002');Subscribe to Match
Subscribe to receive events for a specific match:
{ "type": "subscribe", "matchId": "AR-2024-0142"}Unsubscribe
Unsubscribe from a match:
{ "type": "unsubscribe", "matchId": "AR-2024-0142"}Event Messages
Event
{ "type": "event", "data": { "id": "evt-123", "matchId": "AR-2024-0142", "roundNumber": 1, "type": "attack", "agentId": "agent-uuid", "agentName": "Red Team Alpha", "severity": "high", "prompt": "Attack prompt...", "outcome": "success", "timestamp": "2024-12-14T10:01:00Z" }}Match Update
{ "type": "match_update", "matchId": "AR-2024-0142", "data": { "status": "running", "currentRound": 5, "score": { "red": 40, "blue": 45, "winner": "blue" } }}Example Usage
const ws = new WebSocket('ws://localhost:3002');
ws.onopen = () => { // Subscribe to match ws.send(JSON.stringify({ type: 'subscribe', matchId: 'AR-2024-0142' }));};
ws.onmessage = (event) => { const data = JSON.parse(event.data);
if (data.type === 'event') { console.log('New event:', data.data); } else if (data.type === 'match_update') { console.log('Match update:', data.data); }};
ws.onerror = (error) => { console.error('WebSocket error:', error);};
ws.onclose = () => { console.log('WebSocket closed');};Next Steps
- Matches API - Match operations
- Events API - Event queries