ShoehiveClient
Defined in: client/client.ts:385
A connection to a Shoehive server. Games types join() and act().
Type Parameters
Section titled “Type Parameters”Games extends readonly AnyGame[] = readonly AnyGame[]
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ShoehiveClient<
Games>(options):ShoehiveClient<Games>
Defined in: client/client.ts:406
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”ShoehiveClient<Games>
Properties
Section titled “Properties”clockOffset
Section titled “clockOffset”clockOffset:
number=0
Defined in: client/client.ts:390
Milliseconds to add to Date.now() to get server time (for countdowns).
player
Section titled “player”player: {
guest:boolean;id:string;name:string; } |null=null
Defined in: client/client.ts:388
The current player, after the first successful hello.
status
Section titled “status”status:
ConnectionStatus='idle'
Defined in: client/client.ts:386
Methods
Section titled “Methods”close()
Section titled “close()”close():
void
Defined in: client/client.ts:434
Closes the connection for good. Pending requests reject with CLIENT_CLOSED.
Returns
Section titled “Returns”void
connect()
Section titled “connect()”connect():
Promise<Welcome>
Defined in: client/client.ts:426
Opens the connection (done automatically unless autoConnect: false).
Returns
Section titled “Returns”Promise<Welcome>
createAndJoin()
Section titled “createAndJoin()”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.
Type Parameters
Section titled “Type Parameters”K extends string
G extends AnyGame = GameById<Games, K>
Parameters
Section titled “Parameters”K
options?
Section titled “options?”__namedParameters?
Section titled “__namedParameters?”boolean = true
Returns
Section titled “Returns”Promise<TableHandle<G>>
createTable()
Section titled “createTable()”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).
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
options?
Section titled “options?”GameOptionsInput<GameById<Games, K>>
Returns
Section titled “Returns”Promise<string>
join()
Section titled “join()”join<
G>(tableId,options?):Promise<TableHandle<G>>
Defined in: client/client.ts:505
Joins a table and waits for its first snapshot.
Type Parameters
Section titled “Type Parameters”G extends AnyGame = Games[number]
Parameters
Section titled “Parameters”tableId
Section titled “tableId”string
options?
Section titled “options?”"player" | "spectator"
Returns
Section titled “Returns”Promise<TableHandle<G>>
lobby()
Section titled “lobby()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”filter?
Section titled “filter?”Returns
Section titled “Returns”Promise<LobbyHandle>
onStatus()
Section titled “onStatus()”onStatus(
listener): () =>void
Defined in: client/client.ts:420
Called on every status change, and when player changes (for example a rename).
Parameters
Section titled “Parameters”listener
Section titled “listener”Listener<ConnectionStatus>
Returns
Section titled “Returns”() => void
ping()
Section titled “ping()”ping():
Promise<number>
Defined in: client/client.ts:549
Round-trip time in ms; also refreshes the server clock offset.
Returns
Section titled “Returns”Promise<number>
rename()
Section titled “rename()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<string>
request()
Section titled “request()”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.
Parameters
Section titled “Parameters”string
fields?
Section titled “fields?”Record<string, unknown> = {}
Returns
Section titled “Returns”Promise<Json | undefined>
serverNow()
Section titled “serverNow()”serverNow():
number
Defined in: client/client.ts:414
Server time now, corrected by the measured clock offset.
Returns
Section titled “Returns”number
table()
Section titled “table()”table<
G>(tableId):TableHandle<G> |undefined
Defined in: client/client.ts:544
A table this client has joined, if any.
Type Parameters
Section titled “Type Parameters”G extends AnyGame = Games[number]
Parameters
Section titled “Parameters”tableId
Section titled “tableId”string
Returns
Section titled “Returns”TableHandle<G> | undefined
