| 11 | } |
| 12 | |
| 13 | function initGame(websocket) { |
| 14 | websocket.addEventListener("open", () => { |
| 15 | // Send an "init" event according to who is connecting. |
| 16 | const params = new URLSearchParams(window.location.search); |
| 17 | let event = { type: "init" }; |
| 18 | if (params.has("join")) { |
| 19 | // Second player joins an existing game. |
| 20 | event.join = params.get("join"); |
| 21 | } else if (params.has("watch")) { |
| 22 | // Spectator watches an existing game. |
| 23 | event.watch = params.get("watch"); |
| 24 | } else { |
| 25 | // First player starts a new game. |
| 26 | } |
| 27 | websocket.send(JSON.stringify(event)); |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | function showMessage(message) { |
| 32 | window.setTimeout(() => window.alert(message), 50); |