GameRoom class
This class is used to communicate with the game server and sync the game state
Signature:
export declare class GameRoom<S extends BaseRoomState, RM = any, CM = any>
Remarks
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the GameRoom
class.
Properties
Property |
Modifiers |
Type |
Description |
---|---|---|---|
|
string |
Returns the host url of the server | |
|
Interpolator |
Returns the instance that is used to interpolate the players' states | |
|
boolean | ||
|
boolean |
Returns true if the client is the host of the game room, the host is the player that created the room | |
|
string |
Returns the last error message if any | |
Record<string, any> | |||
|
Promise<void> |
Returns a promise that resolves when the client is connected to the server, and the initial state is synced | |
Use this to configure the options for the remote player avatars | |||
|
string |
Returns the room id of the game server | |
|
string |
Returns the session id of the client that is assigned by the server | |
|
S |
Returns the current state of the room, the game state is regularly updated by the server and synced with the clients cf BaseRoomState for common properties on the state; the game server can add custom properties to the state that are specific to the game | |
|
"disconnected" | "connecting" | "connected" |
Returns the status of the connection; possible values are: "disconnected", "connecting", "connected" | |
|
boolean |
Returns true if the room state is initially synced with the server | |
|
number |
Returns the tick rate of the server, this is the number of times the server sends a state update per second |
Methods
Method |
Modifiers |
Description |
---|---|---|
Returns the instance that is used to sync the players' states | ||
Disconnects the client from the server | ||
listen to connect events, this is fired when the client is connected to the server, but not necessarily synced | ||
listen to disconnect events, this is fired when the client is disconnected from the server | ||
listen to incoming messages from the server | ||
listen to player joined events, this is fired whenever a new player joins the game room | ||
listen to player left events, this is fired whenever a player leaves the game room | ||
listen to game start notifications from the server | ||
listen to state events, this is fired whenever the client receives a state update from the server as defined by the tick rate | ||
listen to game stop notifications from the server | ||
listen to sync events, this is fired when the client is connected to the server and the initial state is synced | ||
Sends a request to the server to start the game | ||
Sends a message to the server, the data type is specific to the game For example |