MCPcopy Index your code
hub / github.com/python-websockets/websockets / initGame

Function initGame

example/tutorial/step2/main.js:3–19  ·  view source on GitHub ↗
(websocket)

Source from the content-addressed store, hash-verified

1import { createBoard, playMove } from "./connect4.js";
2
3function initGame(websocket) {
4 websocket.addEventListener("open", () => {
5 // Send an "init" event according to who is connecting.
6 const params = new URLSearchParams(window.location.search);
7 let event = { type: "init" };
8 if (params.has("join")) {
9 // Second player joins an existing game.
10 event.join = params.get("join");
11 } else if (params.has("watch")) {
12 // Spectator watches an existing game.
13 event.watch = params.get("watch");
14 } else {
15 // First player starts a new game.
16 }
17 websocket.send(JSON.stringify(event));
18 });
19}
20
21function showMessage(message) {
22 window.setTimeout(() => window.alert(message), 50);

Callers 1

main.jsFile · 0.70

Calls 2

getMethod · 0.45
sendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…