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

Function receiveMoves

example/tutorial/step1/main.js:7–27  ·  view source on GitHub ↗
(board, websocket)

Source from the content-addressed store, hash-verified

5}
6
7function receiveMoves(board, websocket) {
8 websocket.addEventListener("message", ({ data }) => {
9 const event = JSON.parse(data);
10 switch (event.type) {
11 case "play":
12 // Update the UI with the move.
13 playMove(board, event.player, event.column, event.row);
14 break;
15 case "win":
16 showMessage(`Player ${event.player} wins!`);
17 // No further messages are expected; close the WebSocket connection.
18 websocket.close(1000);
19 break;
20 case "error":
21 showMessage(event.message);
22 break;
23 default:
24 throw new Error(`Unsupported event type: ${event.type}.`);
25 }
26 });
27}
28
29function sendMoves(board, websocket) {
30 // When clicking a column, send a "play" event for a move in that column.

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…