v0.10.0

Class: Table

Represents a game table with players, seats, and game state.

✅ Attribute Support

The Table class manages a group of players and seats for a specific game. It emits various events to notify other components about changes in the table state.

This class is responsible for:

  • Managing player connections and disconnections
  • Handling player messages and commands
  • Distributing game events to all players
  • Maintaining the game state and rules

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Table(eventBus, totalSeats, maxSeatsPerPlayer, id?, gameId?, options?): Table

Parameters

Name Type
eventBus EventBus
totalSeats number
maxSeatsPerPlayer number
id? string
gameId? string
options TableOptions

Returns

Table

Properties

id

Readonly id: string

Methods

addHandToSeat

addHandToSeat(«destructured»): boolean

Adds a hand to a seat. Emits TABLE_EVENTS.SEAT_HAND_ADDED when a hand is added to a seat.

Parameters

Name Type
«destructured» Object
› handId string
› seatIndex number

Returns

boolean

True if the hand was added, false if no seat exists.


addPlayer

addPlayer(player): boolean

Adds a player to the table. Emits TABLE_EVENTS.PLAYER_JOINED when a player joins the table.

Parameters

Name Type Description
player Object The player to add.
player.player Player -

Returns

boolean

True if the player was added, false if the player is already at a table.


broadcastMessage

broadcastMessage(message): void

Broadcasts a message to all players at the table.

Parameters

Name Type Description
message Object The message to broadcast.
message.message unknown -

Returns

void


broadcastTableState

broadcastTableState(): void

Broadcasts the current table state to all players at the table. This includes all game-specific state and is only meant for players at this table. Broadcasts a TABLE_EVENTS.STATE_UPDATED event that can be used by other components.

Returns

void


clearAllHands

clearAllHands(): void

Clears all hands at the table. Emits TABLE_EVENTS.SEATS_HANDS_CLEARED when all hands are cleared.

Returns

void


clearHandAtSeat

clearHandAtSeat(«destructured»): boolean

Clears a hand at a specific seat. Emits TABLE_EVENTS.SEAT_HAND_CLEARED when a hand is cleared.

Parameters

Name Type Default value
«destructured» Object undefined
› handId? string 'main'
› seatIndex number undefined

Returns

boolean

True if the hand was cleared, false if no seat exists.


createDeck

createDeck(numberOfDecks?): void

Creates a new deck for the table. Emits TABLE_EVENTS.DECK_CREATED when the deck is created.

Parameters

Name Type Default value Description
numberOfDecks Object {} The number of decks to create.
numberOfDecks.numberOfDecks? number 1 -

Returns

void


dealCardToHand

dealCardToHand(hand): boolean

Deals a card to a hand. Emits TABLE_EVENTS.CARD_DEALT when a card is dealt.

Parameters

Name Type Description
hand Object - The hand to deal the card to.
hand.hand Hand -

Returns

boolean

True if the card was dealt, false if no seat or hand exists.


dealCardToSeat

dealCardToSeat(«destructured»): boolean

Deals a card to a seat. Emits TABLE_EVENTS.CARD_DEALT when a card is dealt.

Parameters

Name Type Default value
«destructured» Object undefined
› handId? string 'main'
› isVisible? boolean true
› seatIndex number undefined

Returns

boolean

True if the card was dealt, false if no deck exists.


destroy

destroy(): void

Destroys the table by safely unbinding all event listeners to prevent severe memory leaks.

Returns

void


drawCard

drawCard(isVisible?): null | Card

Draws a card from the deck. Emits TABLE_EVENTS.DECK_CARD_DRAWN when a card is drawn.

Parameters

Name Type Default value Description
isVisible Object {} Whether the card should be visible to the player.
isVisible.isVisible? boolean true -

Returns

null | Card

The drawn card or null if no deck exists.


getAllHandsAtSeat

getAllHandsAtSeat(seatIndex): null | Map<string, Hand>

Gets all hands at a specific seat.

Parameters

Name Type Description
seatIndex Object The index of the seat to get the hands from.
seatIndex.seatIndex number -

Returns

null | Map<string, Hand>

A map of hand IDs to hand objects or null if no seat exists.


getAttribute

getAttribute(key): unknown

Gets an attribute from the table.

Parameters

Name Type Description
key Object The key of the attribute to get.
key.key string -

Returns

unknown

The value of the attribute or null if the attribute does not exist.


getAttributes

getAttributes(): Record<string, unknown>

Gets all attributes from the table.

Returns

Record<string, unknown>

An object containing all attributes.


getDeck

getDeck(): null | Deck

Gets the current deck.

Returns

null | Deck

The deck object or null if no deck has been created.


getHandAtSeat

getHandAtSeat(«destructured»): null | Hand

Gets a hand at a specific seat.

Parameters

Name Type Default value
«destructured» Object undefined
› handId? string 'main'
› seatIndex number undefined

Returns

null | Hand

The hand object or null if no hand exists.


getPlayerAtSeat

getPlayerAtSeat(seatIndex): null | Player

Gets the player at a specific seat.

Parameters

Name Type Description
seatIndex Object The index of the seat to get the player from.
seatIndex.seatIndex number -

Returns

null | Player

The player object or null if the seat is invalid.


getPlayerCount

getPlayerCount(): number

Gets the number of players at the table.

Returns

number

The number of players at the table.


getPlayerSeatCount

getPlayerSeatCount(playerId): number

Gets the number of seats a player is seated at.

Parameters

Name Type Description
playerId Object The ID of the player to get the seat count for.
playerId.playerId string -

Returns

number

The number of seats the player is seated at.


getPlayers

getPlayers(): Player[]

Gets all players at the table.

Returns

Player[]

An array of all players at the table.


getSeat

getSeat(seatIndex): null | Seat

Gets a seat at a specific index.

Parameters

Name Type Description
seatIndex Object The index of the seat to get.
seatIndex.seatIndex number -

Returns

null | Seat

The seat object or null if the index is invalid.


getSeats

getSeats(): Seat[]

Gets all seats at the table.

Returns

Seat[]

An array of all seats at the table.


getState

getState(): TableState

Gets the current state of the table.

Returns

TableState

The current state of the table.


getTableMetadata

getTableMetadata(): unknown

Gets the table metadata for lobby display. This includes only the essential information needed to display in the lobby.

Returns

unknown

The table metadata.


getTableState

getTableState(playerId?): unknown

Gets the complete table state including all attributes and game state. Modifies output arrays to reveal hidden cards strictly to their seated owner.

Parameters

Name Type Description
playerId Object An optional playerId. If matched against a seat owner, returns proprietary hidden cards.
playerId.playerId? string -

Returns

unknown

The localized complete table state.


hasAttribute

hasAttribute(key): boolean

Checks if the table has an attribute.

Parameters

Name Type Description
key Object The key of the attribute to check.
key.key string -

Returns

boolean

True if the attribute exists, false otherwise.


removeAttribute

removeAttribute(key): void

Removes an attribute from the table. Emits TABLE_EVENTS.ATTRIBUTE_CHANGED when the attribute is removed.

Parameters

Name Type Description
key Object The key of the attribute to remove.
key.key string -

Returns

void


removeHandFromSeat

removeHandFromSeat(«destructured»): boolean

Removes a hand from a seat. Emits TABLE_EVENTS.SEAT_HAND_REMOVED when a hand is removed from a seat.

Parameters

Name Type
«destructured» Object
› handId string
› seatIndex number

Returns

boolean

True if the hand was removed, false if no seat exists.


removePlayer

removePlayer(playerId): boolean

Removes a player from the table. Emits TABLE_EVENTS.PLAYER_LEFT when a player leaves the table.

Parameters

Name Type Description
playerId Object The ID of the player to remove.
playerId.playerId string -

Returns

boolean

True if the player was removed, false if the player is not at the table.


removePlayerFromSeat

removePlayerFromSeat(seatIndex): boolean

Removes a player from a seat. Emits TABLE_EVENTS.PLAYER_STOOD when a player stands up from a seat.

Parameters

Name Type Description
seatIndex Object The index of the seat to remove the player from.
seatIndex.seatIndex number -

Returns

boolean

True if the player was removed from the seat, false if the seat is invalid or no player is seated.


setAttribute

setAttribute(«destructured»): void

Sets an attribute on the table. Emits TABLE_EVENTS.ATTRIBUTE_CHANGED when the attribute is updated.

Parameters

Name Type
«destructured» Object
› key string
› value unknown

Returns

void


setAttributes

setAttributes(«destructured»): boolean

Sets multiple attributes on the table. Emits TABLE_EVENTS.ATTRIBUTES_CHANGED when any attributes are updated.

Parameters

Name Type Default value
«destructured» Object undefined
› attributes Record<string, unknown> undefined
› broadcast? boolean false

Returns

boolean

True if any attributes were changed, false otherwise.


setState

setState(state): void

Sets the state of the table. Emits TABLE_EVENTS.STATE_UPDATED when the state is updated.

Parameters

Name Type Description
state Object The new state of the table.
state.state TableState -

Returns

void


shuffleDeck

shuffleDeck(): boolean

Shuffles the current deck. Emits TABLE_EVENTS.DECK_SHUFFLED when the deck is shuffled.

Returns

boolean

True if the deck was shuffled, false if no deck exists.


sitPlayerAtSeat

sitPlayerAtSeat(«destructured»): boolean

Sits a player at a specific seat. Emits TABLE_EVENTS.PLAYER_SAT when a player sits at a seat.

Parameters

Name Type
«destructured» Object
› playerId string
› seatIndex number

Returns

boolean

True if the player was seated, false if the seat is invalid or already taken.


standPlayerUp

standPlayerUp(playerId): boolean

Makes a player stand up from all seats they occupy.

Parameters

Name Type Description
playerId Object The ID of the player to stand up.
playerId.playerId string -

Returns

boolean

True if the player was removed from at least one seat, false otherwise.


updateAttributes

updateAttributes(attributes): boolean

Updates the attributes of the table. Emits TABLE_EVENTS.ATTRIBUTES_CHANGED when any attributes are updated.

Parameters

Name Type Description
attributes Object An object containing key-value pairs of attributes to set.
attributes.attributes Record<string, unknown> -

Returns

boolean

True if any attributes were changed, false otherwise.