Skip to content

ShoehiveClient

Defined in: client/client.ts:385

A connection to a Shoehive server. Games types join() and act().

Games extends readonly AnyGame[] = readonly AnyGame[]

new ShoehiveClient<Games>(options): ShoehiveClient<Games>

Defined in: client/client.ts:406

ClientOptions

ShoehiveClient<Games>

clockOffset: number = 0

Defined in: client/client.ts:390

Milliseconds to add to Date.now() to get server time (for countdowns).


player: { guest: boolean; id: string; name: string; } | null = null

Defined in: client/client.ts:388

The current player, after the first successful hello.


status: ConnectionStatus = 'idle'

Defined in: client/client.ts:386

close(): void

Defined in: client/client.ts:434

Closes the connection for good. Pending requests reject with CLIENT_CLOSED.

void


connect(): Promise<Welcome>

Defined in: client/client.ts:426

Opens the connection (done automatically unless autoConnect: false).

Promise<Welcome>


createAndJoin<K, G>(game, options?, __namedParameters?): Promise<TableHandle<G>>

Defined in: client/client.ts:532

Creates a table, joins it and takes a seat. The handle is typed by the game id.

K extends string

G extends AnyGame = GameById<Games, K>

K

GameOptionsInput<G>

boolean = true

Promise<TableHandle<G>>


createTable<K>(game, options?): Promise<string>

Defined in: client/client.ts:491

Creates a table and returns its id. Does not join it. options is typed by the game's options schema (the server validates it).

K extends string

K

GameOptionsInput<GameById<Games, K>>

Promise<string>


join<G>(tableId, options?): Promise<TableHandle<G>>

Defined in: client/client.ts:505

Joins a table and waits for its first snapshot.

G extends AnyGame = Games[number]

string

"player" | "spectator"

Promise<TableHandle<G>>


lobby(options?): Promise<LobbyHandle>

Defined in: client/client.ts:448

Subscribes to the lobby. A filter narrows the tables listed (every game is always listed). There is one lobby subscription per client: calling again with a different filter switches it, and every holder of the handle sees the new filter.

LobbyFilter

Promise<LobbyHandle>


onStatus(listener): () => void

Defined in: client/client.ts:420

Called on every status change, and when player changes (for example a rename).

Listener<ConnectionStatus>

() => void


ping(): Promise<number>

Defined in: client/client.ts:549

Round-trip time in ms; also refreshes the server clock offset.

Promise<number>


rename(name): Promise<string>

Defined in: client/client.ts:475

Changes this guest's display name, on every seat it holds too. Resolves the name used.

string

Promise<string>


request(t, fields?): Promise<Json | undefined>

Defined in: client/client.ts:575

Sends a protocol request and resolves with its result. Rejects with a ShoehiveError carrying the server's code. Low level: prefer the typed methods.

string

Record<string, unknown> = {}

Promise<Json | undefined>


serverNow(): number

Defined in: client/client.ts:414

Server time now, corrected by the measured clock offset.

number


table<G>(tableId): TableHandle<G> | undefined

Defined in: client/client.ts:544

A table this client has joined, if any.

G extends AnyGame = Games[number]

string

TableHandle<G> | undefined