The game engine for Connect 4 using Temporal.
-
Run
npm install
to install dependencies of the project. -
Install wscat, a command line utility for interacting with a web socket server.
npm install -g wscat
- Run
temporal server start-dev
to start the Temporal server. - Run
npm run start.watch
to start the Worker. - Run
npm run wss:watch
to start the web socket server in watch mode.
Use wscat
to send commands to the websocket server. Available payloads to send to the web socket server are:
-
Start a game
{ "type": "START_GAME", "gameId": "game-123" }
-
Join a game
{"type": "JOIN_GAME","gameId":"game-123","playerName":"Nick" }
-
Make a move
{"type": "MAKE_MOVE", "gameId":"game-123", "x": 5, "y": 4, "playerId": 1}
-
Get the current game context
{ "type": "GET_GAME_CONTEXT", "workflowId": "game-123" }
For example to start a game"
-
Run
wscat -c ws://localhost:8080
from a shell. -
Paste in one of the payloads, e.g.
{ "type": "START_GAME", "gameId": "game-123" }
❯ wscat -c ws://localhost:8080 Connected (press CTRL+C to quit) > { "type": "START_GAME", "gameId": "game-123" } < {"type":"GAME_STARTED","workflowId":"game-123"} >
-
Look in the Temporal UI, http://localhost:8233/namespaces/default/workflows. Notice a new workflow has started.