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

Function receiveMoves

example/tutorial/step3/main.js:35–60  ·  view source on GitHub ↗
(board, websocket)

Source from the content-addressed store, hash-verified

33}
34
35function receiveMoves(board, websocket) {
36 websocket.addEventListener("message", ({ data }) => {
37 const event = JSON.parse(data);
38 switch (event.type) {
39 case "init":
40 // Create links for inviting the second player and spectators.
41 document.querySelector(".join").href = "?join=" + event.join;
42 document.querySelector(".watch").href = "?watch=" + event.watch;
43 break;
44 case "play":
45 // Update the UI with the move.
46 playMove(board, event.player, event.column, event.row);
47 break;
48 case "win":
49 showMessage(`Player ${event.player} wins!`);
50 // No further messages are expected; close the WebSocket connection.
51 websocket.close(1000);
52 break;
53 case "error":
54 showMessage(event.message);
55 break;
56 default:
57 throw new Error(`Unsupported event type: ${event.type}.`);
58 }
59 });
60}
61
62function sendMoves(board, websocket) {
63 // 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…