| 60 | } |
| 61 | |
| 62 | function sendMoves(board, websocket) { |
| 63 | // Don't send moves for a spectator watching a game. |
| 64 | const params = new URLSearchParams(window.location.search); |
| 65 | if (params.has("watch")) { |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | // When clicking a column, send a "play" event for a move in that column. |
| 70 | board.addEventListener("click", ({ target }) => { |
| 71 | const column = target.dataset.column; |
| 72 | // Ignore clicks outside a column. |
| 73 | if (column === undefined) { |
| 74 | return; |
| 75 | } |
| 76 | const event = { |
| 77 | type: "play", |
| 78 | column: parseInt(column, 10), |
| 79 | }; |
| 80 | websocket.send(JSON.stringify(event)); |
| 81 | }); |
| 82 | } |
| 83 | |
| 84 | window.addEventListener("DOMContentLoaded", () => { |
| 85 | // Initialize the UI. |