-
Notifications
You must be signed in to change notification settings - Fork 4
Room API
Josh Feinsilber edited this page Jul 12, 2019
·
2 revisions
Rooms are where you interact with the game once you are in it! A room on the client links up with a room on the server!
Called when the Room is created on the server
room.onCreate.add(() => console.log('Room created!'))
Called when successfully joining a room
room.onJoin.add(() => console.log('Room joined!'))
Called when a new message from the server is sent. Takes in two arguments:
key | type | optional |
---|---|---|
action | string | false |
data | any | true |
Example
room.onMessage.add((action: string, data?: any) => {
if (action === "NEW_ALERT") {
alert(data)
}
})
Called when you leave a room, either by being kicked or getting disconnected
room.onLeave.add(() => console.log('Left the room!'))
Called when there is an error joining or creating the room. Includes an argument containing the error.
room.onError.add((e) => console.log('Error with the room!', e))
You can clear the listeners from any event by running event.clear()
-- for example: client.onLeave.clear()
Sends a message back up to the room on the server. Takes two arguments:
key | type | required |
---|---|---|
action | string | true |
data | any | false |
Example
room.send("NEW_CHAT_MESSAGE", "Hi there!")