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

Function initGame

example/tutorial/step3/main.js:13–29  ·  view source on GitHub ↗
(websocket)

Source from the content-addressed store, hash-verified

11}
12
13function 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
31function showMessage(message) {
32 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…