websocket-game-lobby (main) doxdox documentation

Simple API for building games using WebSockets.

# addEventListener(type, callback)

Add a new event callback method for an existing or new event type.

Parameters

Name Types Description
type - An event type.
callback - An asynchronous callback method used to make edits directly to a data source.

# avatar()

Avatar ID or URL of the player.

# createGame()

private method

Creates a game. > NOTE: Calling this function will also run any events with the type createGame.

# createPlayer(gameId, name, avatar)

private method

Creates a player in a game. Player will be assigned as admin if they are the first in the game. > NOTE: Calling this function will also run any events with the type createPlayer.

Parameters

Name Types Description
gameId - A UUID representing the game to create a player for.
name - Optional name for player.
avatar - Optional avatar ID or URL for player.

# createSpectator(gameId)

private method

Creates a spectator in a game. > NOTE: Calling this function will also run any events with the type createSpectator.

Parameters

Name Types Description
gameId - A UUID representing the game to create a spectator for.

# createTurn(gameId)

private method

Creates a new turn in a game. > NOTE: Calling this function will also run any events with the type createTurn.

Parameters

Name Types Description
gameId - A UUID representing the game in which to create a turn.

# currentTurn(gameId)

Find the current turn in a game using a UUID.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.

# custom()

A custom object for storing application specific data.

# custom()

A custom object for storing application specific data.

# custom()

A custom object for storing application specific data.

# custom()

A custom object for storing application specific data.

# editCurrentTurn(gameId, callback)

Edit current turn data.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
callback - An asynchronous callback method used to make edits directly to the current turn and other data sources.

# editGame(gameId, callback)

Edit game data.

Parameters

Name Types Description
gameId - A UUID representing the game to edit.
callback - An asynchronous callback method used to make edits directly to the game and other data sources.

# editPlayer(gameId, playerId, callback)

Edit player data.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
playerId - A UUID representing the player to edit.
callback - An asynchronous callback method used to make edits directly to the player and other data sources.

# editSpectator(gameId, spectatorId, callback)

Edit player data.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
spectatorId - A UUID representing the spectator to edit.
callback - An asynchronous callback method used to make edits directly to the spectator and other data sources.

# editTurn(gameId, turnId, callback)

Edit turn data.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
turnId - A UUID representing the turn to edit.
callback - An asynchronous callback method used to make edits directly to the turn and other data sources.

# endCurrentTurn(gameId)

Ends current turn and creates a new turn in a game. > NOTE: Calling this function will also run any events with the type endCurrentTurn.

Parameters

Name Types Description
gameId - A UUID representing the game in which to end the current turn.

# endGame(gameId)

private method

End game.

Parameters

Name Types Description
gameId - A UUID representing the game to end.

# findGame(gameId)

Find a game using a UUID.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.

# findGameWithCode(gameCode)

Find a game using a game code.

Parameters

Name Types Description
gameCode - A unique four letter game code representing the game to look up.

# findPlayer(gameId, playerId)

Find player in a game using a UUID.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
playerId - A UUID representing the player to look up.

# findSpectator(gameId, spectatorId)

Find spectator in a game using a UUID.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
spectatorId - A UUID representing the spectator to look up.

# findTurn(gameId, turnId)

Find turn in a game using a UUID.

Parameters

Name Types Description
gameId - A UUID representing the game to look up.
turnId - A UUID representing the turn to look up.

# game()

Reference to the active game.

# gameCode()

A unique four letter game code representing a game.

# gameCode()

A unique four letter game code representing a game.

# gameId()

A UUID representing a game.

# gameId()

A UUID representing a game.

# gameId()

A UUID representing a game.

# gameId()

A UUID representing a game.

# gameId()

A UUID representing a game.

# index()

Turn number. This value auto-increments.

# isAdmin()

A flag indicating if the player is the admin. This is true if they are the first player to join the game.

# leaveGame(gameId, playerId)

private method

Leave game. > NOTE: Calling this function will also run any events with the type leaveGame.

Parameters

Name Types Description
gameId - A UUID representing the game to leave.
playerId - A UUID representing the player or spectator to leave.

# name()

Name of the player.

# name()

Name of the spectator.

# player()

Reference to the active player.

# playerId()

A UUID representing a player.

# playerId()

A UUID representing a player or spectator.

# players()

An array of active players.

# removeAllEventListeners()

Remove all existing event callback methods.

# removeEventListener(type, callback)

Remove an existing event callback method.

Parameters

Name Types Description
type - An event type.
callback - Reference to an asynchronous callback method used to make edits directly to a data source.

# setup()

private method

Run setup on datastore.

# spectator()

Reference to the active spectator.

# spectatorId()

A UUID representing a spectator.

# spectators()

An array of active spectators.

# started()

A flag indicating if the game has started.

# startGame(gameId)

private method

Start game. > NOTE: Calling this function will also run any events with the type startGame.

Parameters

Name Types Description
gameId - A UUID representing the game to start.

# tore(type, data, datastore)

private method

Run all existing event callback methods for a specific event type.

Parameters

Name Types Description
type - An event type.
data - Data specific to the event type.
datastore - Reference to the current datastore.

# toreEvents()

Types to be used with event listeners attached to {@link DataStore} objects.

# turn()

Reference to the active turn.

# turnId()

A UUID representing a turn.

# turns()

An array of all of turns taken in the game.