App
The global app
variable is always available within the app scripting runtime.
Properties
.instanceId
: String
The instance ID of the current app. Every app has its own unique ID that is shared across all clients and the server.
.version
: String
The version of the app instance. This number is incremented whenever the app is modified which includes but is not limited to updating scripts and models.
.state
: Object
A plain old javascript object that you can use to store state in. The servers state object is sent to all new clients that connect in their initial snapshot, allowing clients to initialize correctly, eg in the right position/mode.
.{...Node}
Inherits all Node properties
Methods
.on(name, callback)
Subscribes to custom networked app events and engine update events like update
, fixedUpdate
and lateUpdate
.
Custom networked events are received when a different client/server sends an event with app.send(event, data)
.
IMPORTANT: Only subscribe to update events when they are needed. The engine is optimized to completely skip over large amounts of apps that don’t need to receive update events.
.off(name, callback)
Unsubscribes from custom events and update events.
IMPORTANT: Be sure to unsubscribe from update events when they are not needed. The engine is optimized to completely skip over large amounts of apps that don’t need to receive update events.
.send(name, data, skipNetworkId)
Sends an event across the network.
If the caller is on the client, the event is sent to the server. The third argument skipNetworkId
is a no-op here.
If the caller is on the server, the event is sent to all clients, with the skipNetworkId
argument allowing you to skip sending to one specific client.
.get(nodeId)
: Node
Finds and returns any node with the matching ID from the model the app is using. If your model is made with blender, this is the object “name”.
NOTE: Blender GLTF exporter renames objects in some cases, eg by removing spaces. Best practice is to simply name everything in UpperCamelCase with no other characters.
.create(nodeName)
: Node
Creates and returns a node of the specified name.
.control(options)
: Control
TODO: provides control to a client to respond to inputs and move the camera etc
.configure(fields)
Configures custom UI for your app. See Props for more info.