Complete reference for networking lifecycle events.
The following events are available to listen to in your components. They describe common network events that you might want to react to, such as users joining or leaving rooms, room state changes, and connection events.
Room Events
Events related to room lifecycle - joining, leaving, and state updates.
JoinedRoom
Fired when you (the local user) have joined a networked room.
this.context.beginListen(RoomEvents.JoinedRoom,({room,viewId,allowEditing,inRoom})=>{console.log("Joined room:", room);console.log("View ID:", viewId);console.log("Can edit:", allowEditing);console.log("Users in room:", inRoom);});
Event Data:
room (string) - Room ID
viewId (string) - Your unique view identifier
allowEditing (boolean) - Whether you can modify room state
inRoom (string[]) - Array of connection IDs currently in the room
Use Cases:
Initialize networking-dependent components
Show "Connected" UI state
Load user-specific data
Set up presence indicators
LeftRoom
Fired when you (the local user) have left a networked room.
Event Data:
room (string) - Room ID you just left
Use Cases:
Clean up networking resources
Show "Disconnected" UI state
Reset scene state if needed
Remove presence indicators
UserJoinedRoom
Fired when another user has joined your networked room.
Event Data:
userId (string) - Connection ID of the user who joined
Use Cases:
Spawn player avatars
Show join notifications
Update player count UI
Initialize player-specific objects
UserLeftRoom
Fired when another user has left your networked room.
Event Data:
userId (string) - Connection ID of the user who left
Use Cases:
Remove player avatars
Show leave notifications
Update player count UI
Clean up player-specific objects
RoomStateSent
Fired after all current room state has been sent to the client. This happens after you join a room.
// Listen for gained-ownership event
this.context.beginListen("gained-ownership", ({guid, owner}) => {
if (guid === this.guid) {
console.log("You now own this object");
}
});
// Listen for lost-ownership event
this.context.beginListen("lost-ownership", ({guid, owner}) => {
if (guid === this.guid) {
console.log("You no longer own this object");
}
});
// This event uses the low-level connection API
this.context.connection.beginListen("connection-start-info", ({id}) => {
console.log("Connected with ID:", id);
});
// Ping sent to server every few seconds
{
"key": "ping",
"data": {}
}
// Pong response from server
{
"key": "pong",
"data": {}
}
// Delete state for a specific object
this.context.connection.send("delete-state", {
guid: "guid_to_delete"
});
// Delete ALL room state (use with caution!)
this.context.connection.send("delete-all-state", {});