| 50 | } |
| 51 | |
| 52 | function sendMoves(board, websocket) { |
| 53 | // Don't send moves for a spectator watching a game. |
| 54 | const params = new URLSearchParams(window.location.search); |
| 55 | if (params.has("watch")) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | // When clicking a column, send a "play" event for a move in that column. |
| 60 | board.addEventListener("click", ({ target }) => { |
| 61 | const column = target.dataset.column; |
| 62 | // Ignore clicks outside a column. |
| 63 | if (column === undefined) { |
| 64 | return; |
| 65 | } |
| 66 | const event = { |
| 67 | type: "play", |
| 68 | column: parseInt(column, 10), |
| 69 | }; |
| 70 | websocket.send(JSON.stringify(event)); |
| 71 | }); |
| 72 | } |
| 73 | |
| 74 | window.addEventListener("DOMContentLoaded", () => { |
| 75 | // Initialize the UI. |