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

Function receiveMoves

example/tutorial/step2/main.js:25–50  ·  view source on GitHub ↗
(board, websocket)

Source from the content-addressed store, hash-verified

23}
24
25function receiveMoves(board, websocket) {
26 websocket.addEventListener("message", ({ data }) => {
27 const event = JSON.parse(data);
28 switch (event.type) {
29 case "init":
30 // Create links for inviting the second player and spectators.
31 document.querySelector(".join").href = "?join=" + event.join;
32 document.querySelector(".watch").href = "?watch=" + event.watch;
33 break;
34 case "play":
35 // Update the UI with the move.
36 playMove(board, event.player, event.column, event.row);
37 break;
38 case "win":
39 showMessage(`Player ${event.player} wins!`);
40 // No further messages are expected; close the WebSocket connection.
41 websocket.close(1000);
42 break;
43 case "error":
44 showMessage(event.message);
45 break;
46 default:
47 throw new Error(`Unsupported event type: ${event.type}.`);
48 }
49 });
50}
51
52function sendMoves(board, websocket) {
53 // Don't send moves for a spectator watching a game.

Callers 1

main.jsFile · 0.70

Calls 4

playMoveFunction · 0.90
showMessageFunction · 0.70
parseMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…