Request/Response Examples
Example 1: Drawing and Discarding Tiles
1. Draw from Middle
Client → Server:
{
"type": "move",
"token": "new-token-123",
"userName": "Player1",
"content": {
"moveType": 8,
"timestamp": 1704067200000
}
}
Server Response:
{
"type": "gameState",
"actionState": {
"type": 8,
"actionDefinition": "DrawFromMiddle",
"actionMessage": "Tile drawn successfully"
},
"gameState": {
"turn": "player-1",
"players": [
{
"uniqueId": "player-1",
"tileBag": [
{"uniqueID": "tile-new", "number": 7, "color": 2}
]
}
],
"remainingTiles": "99"
}
}
2. Discard Tile
Client → Server:
{
"type": "move",
"token": "new-token-123",
"userName": "Player1",
"content": {
"moveType": 7,
"tile": {
"uniqueID": "tile-old",
"number": 5,
"color": 1
},
"timestamp": 1704067201000
}
}
Server Response:
{
"type": "gameState",
"actionState": {
"type": 7,
"actionDefinition": "DiscardTile",
"actionMessage": "Tile discarded"
},
"gameState": {
"turn": "player-2",
"players": [
{
"uniqueId": "player-1",
"tileBag": [],
"discardPile": [
{"uniqueID": "tile-old", "number": 5, "color": 1}
]
}
]
}
}
Example 2: Opening a Set
1. Open Set Request
Client → Server:
{
"type": "move",
"token": "new-token-123",
"userName": "Player1",
"content": {
"moveType": 10,
"tiles": [
{"uniqueID": "tile-1", "number": 1, "color": 1},
{"uniqueID": "tile-2", "number": 2, "color": 1},
{"uniqueID": "tile-3", "number": 3, "color": 1}
],
"timestamp": 1704067202000
}
}
2. Server Response
{
"type": "gameState",
"actionState": {
"type": 10,
"actionDefinition": "OpenSet",
"actionMessage": "Set opened successfully"
},
"gameState": {
"players": [
{
"uniqueId": "player-1",
"openSeries": [
[
{"uniqueID": "tile-1", "number": 1, "color": 1},
{"uniqueID": "tile-2", "number": 2, "color": 1},
{"uniqueID": "tile-3", "number": 3, "color": 1}
]
],
"seriesCount": 1,
"seriesType": "Group"
}
]
}
}
Example 3: Play Again Scenario
1. Player 1 Sends "Play Again" Request
Client → Server:
{
"type": "play_again_request",
"token": "abc123",
"userName": "Player1",
"content": {}
}
2. Server → Player 1
{
"type": "playAgainRequestSent",
"data": "Play again request sent successfully"
}
3. Server → Player 2, 3, 4
{
"type": "playAgainNotification",
"from": "player-1",
"content": {
"requestingPlayerId": "player-1",
"requestingPlayerName": "Player 1",
"expiresAt": 1704067300000,
"timeoutSeconds": 30
}
}
4. Player 2 Accepts
Client → Server:
{
"type": "play_again_response",
"token": "abc123",
"userName": "Player2",
"content": {
"accepted": true
}
}
5. Server → All Players
{
"type": "playAgainAccepted",
"data": {
"accepted": true
}
}
6. Player 3 Rejects
Client → Server:
{
"type": "play_again_response",
"token": "abc123",
"userName": "Player3",
"content": {
"accepted": false
}
}
7. Server → All Players
{
"type": "playAgainRejected",
"data": {
"accepted": false
}
}
8. Server → All Players (Final Result)
{
"type": "playAgainResult",
"data": {
"type": "playAgainResult",
"from": "player-3",
"content": {
"accepted": false,
"respondingPlayerId": "player-3",
"reason": ""
}
}
}
9. Client
onGameEnd()is called- WebSocket is closed
window.parent.postMessage({ type: 'return_lobby' })is sent- Return to lobby