The GameRoomClient class extends the BaseClient and provides functionality for interacting with a game room server. It manages the state of the game room, handles WebSocket events, and provides methods for creating, joining, and managing game rooms and seats.

Hierarchy

  • BaseClient
    • GameRoomClient

Implements

Constructors

Properties

client: IClient
gameId: undefined | number

The ID of the current game room.

gamePassword: undefined | string

The password for the current game room, if applicable.

signalConnections: SignalConnection[] = []
store: Store<GameRoomState>

The Redux-like store that manages the state of the game room.

userInfo: undefined | UserInfo

Information about the current user.

Methods

  • Parameters

    • connection: SignalConnection

    Returns SignalConnection

  • Creates a new game room.

    Parameters

    • game: string

      The id of the game.

    • options: GameOptions

      The options for the game room.

    Returns Promise<[number, undefined | string]>

    A promise that resolves to a tuple containing the game room ID and password.

  • Retrieves the current state of the game room from server.

    Returns Promise<GameRoomData>

    A promise that resolves to the game room state data.

  • Checks if the current user currecntly occupies a specific seat.

    Parameters

    • index: number

      The index of the seat to check.

    Returns boolean

    true if the user can occupy the seat, otherwise false.

  • Checks if a specific seat is empty.

    Parameters

    • index: number

      The index of the seat to check.

    Returns boolean

    true if the seat is empty, otherwise false.

  • Joins an existing game room.

    Parameters

    • gameId: number

      The ID of the game room to join.

    • Optionalpassword: string

      The password for the game room, if required.

    Returns Promise<number>

    A promise that resolves to the game room ID.

  • Leaves a specific seat in the game room.

    Parameters

    • seat: number

      The index of the seat to leave.

    Returns Promise<void>

  • Parameters

    • method: () => void

    Returns SignalConnection

  • Parameters

    • method: () => void

    Returns SignalConnection

  • Parameters

    • name: string
    • method: (...args: any[]) => void

    Returns void

  • Reconnects the client to the server and reinitializes the game room state.

    Parameters

    • token: undefined | string

      The authorization token for the user.

    Returns Promise<void>

  • Starts the client by connecting to the server and authorizing the user.

    Parameters

    • token: undefined | string

      The authorization token for the user.

    Returns Promise<boolean>

    A promise that resolves to true if the client started successfully, otherwise false.

  • Takes the first available seat in the game room.

    Returns Promise<number>

    A promise that resolves to the index of the seat taken.

  • Takes a specific seat in the game room.

    Parameters

    • seat: number

      The index of the seat to take.

    Returns Promise<void>