@UrTurn/client
Fields
client.events EventEmitter
client.events.on('onStateChanged', (newRoomState: RoomState) => {})
- Calls the callback anytime the current RoomState changes for the room
Methods
client.makeMove(move: Move)
- Move is any JSON serializable object
- returns
Promise<MoveResult>if the move is accepted
client.getLocalPlayer()
- returns the local player object
info
You can tell if the local player is a spectator or a regular player if they are not in the players list. This will help you display a different view if the game is in spectator mode.
client.getRoomState()
- returns the current
RoomState
client.now()
- returns the milliseconds from epoch (equivalent to
Date.now())
tip
client.now() is clocked synced with our servers. You should rely on this for timing mechanisms over the built in Date.now() because the local user clock can be off by seconds or even minutes!
Types
MoveResult
errorErrorobject if an error occurredundefinedif no error ocurred
successtrueif successful (no error ocurred)undefinedif an error occurred
Example:
// successful move
{
"success": true
}
// error occurred
{
"error": {
"name": "invalid move",
"message": "player billy made an invalid move, it wasn't their turn
}
}