(board, websocket)
| 5 | } |
| 6 | |
| 7 | function receiveMoves(board, websocket) { |
| 8 | websocket.addEventListener("message", ({ data }) => { |
| 9 | const event = JSON.parse(data); |
| 10 | switch (event.type) { |
| 11 | case "play": |
| 12 | // Update the UI with the move. |
| 13 | playMove(board, event.player, event.column, event.row); |
| 14 | break; |
| 15 | case "win": |
| 16 | showMessage(`Player ${event.player} wins!`); |
| 17 | // No further messages are expected; close the WebSocket connection. |
| 18 | websocket.close(1000); |
| 19 | break; |
| 20 | case "error": |
| 21 | showMessage(event.message); |
| 22 | break; |
| 23 | default: |
| 24 | throw new Error(`Unsupported event type: ${event.type}.`); |
| 25 | } |
| 26 | }); |
| 27 | } |
| 28 | |
| 29 | function sendMoves(board, websocket) { |
| 30 | // When clicking a column, send a "play" event for a move in that column. |
no test coverage detected
searching dependent graphs…