Room
Index
Properties
clients
readonlyid
Unique ID of this room
maxClients
Number of clients that may connect to this room.
Methods
broadcast
Sends a message to everyone in this room.
Type parameters
- T = string | number
- T2 = string | number | object | Buffer
Parameters
event: T
Unique identifier for this event. See onMessage for more info about event identifiers.
data: T2
Data that will be broadcasted.
Returns void
cleanup
Called before this room is closed.
Returns void
isFull
Checks if this room is full. You might override this method to account for seats reserved by whatever matchmaker you’re using.
Returns boolean
trueif room is full
onClientAuth
Authenticates the client. If this method throws an exception, authentication will fail with exception message.
Parameters
client: NetworkClient
Client to authenticate
authString: string
The authentication string passed from client
Returns void
onClientJoined
Called when a client joins the room
Parameters
client: NetworkClient
Returns void
onClientLeft
Called when a client leaves the room
Parameters
client: NetworkClient
Returns void
onMessage
Registers a handler for
eventParameters
event: string | number
Unique identifier for this event.
Using a
stringfor event ids is not recommended as it makes the network packet considerably bigger (2 bytes for length and an extra 2 bytes for every character in string).You may use any number from 0 to 255.
handler: MessageHandler
The MessageHandler function that will be called when this event is received.
Returns void
processEvents
Processes all queued events. This method should be called every tick, preferably before ticking game logic.
Returns void
send
Sends a message to a specific client
Type parameters
- T = string | number
- T2 = string | number | object | Buffer
Parameters
client: NetworkClient
NetworkClient that will receive the message
event: T
Unique identifier for this event. See onMessage for more info about event identifiers.
data: T2
Data that will be sent to this client.
Returns void
A map of clients. Key is the id.