App
The global app
variable is always available within the app scripting runtime.
Properties
Section titled “Properties”.instanceId
: String
Section titled “.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
Section titled “.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
Section titled “.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}
Section titled “.{...Node}”Inherits all Node properties
Methods
Section titled “Methods”.on(name, callback)
Section titled “.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)
Section titled “.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.
app.emit(key, value)
Section titled “app.emit(key, value)”Emits/signals a key,value to all apps or the world.
.send(name, data, skipNetworkId)
Section titled “.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
Section titled “.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
Section titled “.create(nodeName): Node”Creates and returns a node of the specified name.
.control(options)
: Control
Section titled “.control(options): Control”TODO: provides control to a client to respond to inputs and move the camera etc
.configure(fields)
Section titled “.configure(fields)”Configures custom UI for your app. See Props for more info.