Interface: RoomClientOptions<View>
Defined in: client/index.ts:86
What a RoomClient reports and how it connects. Every option has a default.
Type Parameters
| Type Parameter |
|---|
View |
Properties
| Property | Type | Description | Defined in |
|---|---|---|---|
token? | TokenSource | Supplies the join token, instead of putting one in the URL. It is called before every connection attempt (the first, every reconnect, and when the room hands the player to another room) with the id of the room being connected to, and what it returns is sent as the token query parameter, where tokenAuth reads it. Use it whenever tokens expire: a token in the URL is fixed for the life of the client, so once it has run out the client can no longer reconnect. Return the token you have while it is still good and fetch a new one when it is not. If this throws, the attempt counts as failed (onStatus gets connecting with the reason token_failed) and is tried again like any other. | client/index.ts:120 |
reconnect? | boolean | Reconnect after an unexpected close. Defaults to true. | client/index.ts:124 |
binary? | boolean | Ask the room for its patches in binary. Off by default, and better left off in a browser or in Node: there the connection is compressed, and binary frames are a few percent smaller than JSON ones at best, and not readable in the developer tools. It is for a client whose WebSocket is not compressed, and here so that the format has a client to be tested with. A room that does not know the format sends JSON, which is read as always. | client/index.ts:134 |
pingIntervalMs? | number | Keepalive interval in milliseconds. Defaults to 25 seconds; 0 disables it. A connection that goes a whole interval without answering is taken for dead and replaced. | client/index.ts:140 |
Methods
onState()?
onState?(state, seq): void;Defined in: client/index.ts:92
The state changed, or was received for the first time after (re)connecting. Every call gets a new object; parts that did not change are the same objects as before, so they can be compared by reference.
Parameters
| Parameter | Type |
|---|---|
state | View |
seq | number |
Returns
void
onPresence()?
onPresence?(players): void;Defined in: client/index.ts:94
Someone joined, dropped or came back.
Parameters
| Parameter | Type |
|---|---|
players | Player[] |
Returns
void
onMessage()?
onMessage?(message): void;Defined in: client/index.ts:96
A message the room sent with send or broadcast.
Parameters
| Parameter | Type |
|---|---|
message | unknown |
Returns
void
onStatus()?
onStatus?(status, detail?): void;Defined in: client/index.ts:105
closed carries the close code and reason, e.g. when the room was full or the seat was removed. So does connecting when it follows a connection that was lost or never opened: it is called again for every failed attempt. A client that keeps failing this way while the network is fine is being turned away before it reaches the room, most often because the join token in its URL has expired: see token.
Parameters
| Parameter | Type |
|---|---|
status | ConnectionStatus |
detail? | CloseDetail |
Returns
void
onMoved()?
onMoved?(roomId): void;Defined in: client/index.ts:122
The room handed this player to another room, and the client is now connecting there.
Parameters
| Parameter | Type |
|---|---|
roomId | string |
Returns
void