Class: RoomClient<View, Command>
Defined in: client/index.ts:170
A connection to one room. Holds the latest state the server sent and reconnects on its own; after a reconnect the server sends the current state again, so there is nothing to replay.
Type Parameters
| Type Parameter | Default type |
|---|---|
View | unknown |
Command | unknown |
Constructors
Constructor
new RoomClient<View, Command>(url, options?): RoomClient<View, Command>;Defined in: client/index.ts:194
Parameters
| Parameter | Type |
|---|---|
url | string | URL |
options? | RoomClientOptions<View> |
Returns
RoomClient<View, Command>
Accessors
state
Get Signature
get state(): View | undefined;Defined in: client/index.ts:201
The latest state the room sent: this player's view. Undefined until the first one arrives.
Returns
View | undefined
seq
Get Signature
get seq(): number;Defined in: client/index.ts:206
The room's change counter for state. It goes up by one with every change.
Returns
number
tick
Get Signature
get tick(): number;Defined in: client/index.ts:211
Simulation ticks the room has run. Stays 0 in event mode.
Returns
number
tickRate
Get Signature
get tickRate(): number;Defined in: client/index.ts:216
The room's simulation rate in ticks per second; 0 in event mode.
Returns
number
you
Get Signature
get you(): string | undefined;Defined in: client/index.ts:221
This player's id, as the server knows it. Set once connected.
Returns
string | undefined
players
Get Signature
get players(): Player[];Defined in: client/index.ts:226
Everyone with a seat in the room, in join order.
Returns
Player[]
status
Get Signature
get status(): ConnectionStatus;Defined in: client/index.ts:231
Where the connection stands.
Returns
unconfirmed
Get Signature
get unconfirmed(): readonly SentCommand<Command>[];Defined in: client/index.ts:242
The commands sent with send that state does not show yet, oldest first: the room has not applied them, or has and the news is on its way. A command leaves the list in the same moment state changes to show it, or when the room refuses it. Predictor draws them over state. The array is a new one whenever it changes.
Returns
readonly SentCommand<Command>[]
Methods
on()
on<E>(event, listener): () => void;Defined in: client/index.ts:253
Listen for state, presence, message, status or moved, in addition to the on… options. Returns a function that stops listening, which suits UI frameworks:
useEffect(() => room.on("state", setState), [room]);
Type Parameters
| Type Parameter |
|---|
E extends keyof RoomClientEvents<View> |
Parameters
| Parameter | Type |
|---|---|
event | E |
listener | RoomClientEvents<View>[E] |
Returns
() => void
send()
send(command): Promise<void>;Defined in: client/index.ts:283
Send a command. Resolves once the room applied it, by which time state already reflects it: at once in event mode, and with the next tick in a room that is ticking. Rejects with CommandRejected if the room refused it or the connection dropped first.
Parameters
| Parameter | Type |
|---|---|
command | Command |
Returns
Promise<void>
leave()
leave(): Promise<void>;Defined in: client/index.ts:295
Give up the seat in this room. Resolves once the room let the player go, after which it closes the connection and status becomes closed. Rejects with CommandRejected if the room made the player stay.
Returns
Promise<void>
close()
close(): void;Defined in: client/index.ts:300
Close the connection for good, keeping the seat. No reconnect follows.
Returns
void