Class: State

xebra.js v1.2.5 - Documentation

State

new State(options)

State instances wrap the state sync and connection with the Max backend.

Name Type Description
options Object
Name Type Default Description
auto_connect Boolean true

Whether to autoconnect on startup

hostname String

The host of the Xebra backend

port Number

The port of the Xebra backend

secure Boolean false

Whether to use a secure WS connection or not (ws vs wss)

reconnect Boolean true

Whether to try auto-reconnecting after the connection closed

reconnect_attempts Number 5

The amount of retries before considering it a failure

reconnect_timeout Number 1000

Timeout between reconnects in ms

supported_objects Array.<string>

List of objects to include in the state

Members

connectionState:number

readonly

Returns the current connection state.

See:

hostname:string

readonly

Hostname of the Max WebSocket.

isMotionEnabled:boolean

readonly

Returns whether motion tracking is currently enabled/disabled.

isStateLoaded:boolean

readonly

Returns whether the initial state has been received from Max and loaded.

name:string

Name of the current xebra connection. For some Max objects, like mira.motion and mira.multitouch, multiple xebra clients (connected via Xebra.js or the Mira iOS app) can send events to the same object. This name property will be appended to these events, so that the events can be routed in Max.

port:number

readonly

Returns the port number of the Max WebSocket.

uuid:string

readonly

UUID associated with this state.

wsUrl:string

readonly

WebSocket connection URL.

Methods

close()

Closes the Xebra connection and resets the state.

connect()

Connects to the Xebra server. If auto_connect : true is passed to State on.

createResource():Resource

Create a Resource, which can be used to retrieve image data from the Max search path.

Returns:
Type Description
Resource

getChannelNames():Array.<string>

Returns a list of the names of all mira.channel objects in all patchers

Returns:
Type Description
Array.<string>

getObjectById(id):ObjectNode|null

Returns the object speficied by the given id.

Name Type Description
id Xebra.NodeId

The id of the object

Returns:
Type Description
ObjectNode | null the object or null if not known

getObjectsByScriptingName():Array.<ObjectNode>

Returns a list of node objects with the given scripting name (the Max attribute 'varname').

Returns:
Type Description
Array.<ObjectNode>

getPatcherById(id):PatcherNode|null

Returns the patcher speficied by the given id.

Name Type Description
id Xebra.NodeId

The id of the patcher

Returns:
Type Description
PatcherNode | null the patcher or null if not known

getPatchers():Array.<PatcherNode>

Returns a list of available patchers.

Returns:
Type Description
Array.<PatcherNode>

sendMessageToChannel(channel, message)

Send an arbitrary message to the named channel. The type of the message will be coerced to a Max type in the Max application by mira.channel

Name Type Description
channel String

The name of the mira.channel objects that should receive this message

message Number | String | Array.<(Number|String)> | Object

the message to send

sendMotionData(motionType, motionX, motionY, motionZ, timestamp)

Send mira.motion updates to parameters on the root node.

Name Type Description
motionType string

The type of motion

motionX number
motionY number
motionZ number
timestamp number
See:
Throws:

Will throw an error when motion is currently disabled on the instance of State.

Events

State.event:channel_message_received

This event is emitted when a message is sent to a mira.channel object

Name Type Description
channel String

The name of the channel where the message was received

message Number | String | Array.<(Number|String)> | Object

The message received from Max

State.event:connection_changed

This event is emitted when the state of the web socket connection to the Max patch (ConnectionState) changes.

State.event:frame_added

This event is emitted when a frame is added in Max.

Name Type Description
object FrameNode

The added frame

State.event:frame_changed

This event is emitted when a parameter of a frame is changed. This change can come from Max or when the value of the parameter is set directly.

Name Type Description
frame FrameNode

The changed frame

param ParamNode

The parameter node

State.event:frame_removed

This event is emitted when a frame is removed from Max.

Name Type Description
object FrameNode

The removed frame

State.event:loaded

This event is emitted when the entire Max state has been loaded. At this point, all frame_added, object_added, and patcher_added events will have fired, and all of their parameters will have been loaded. This is analogous to $(document).ready() in jQuery.

State.event:motion_disabled

This event is emitted when the last mira.motion object is removed from Max. This event is not emitted when xebra first connects to Max, and there are no mira.motion objects in Max.

State.event:motion_enabled

This event is emitted when there is at least one mira.motion object in Max.

State.event:object_added

This event is emitted when an object is added in Max.

Name Type Description
object ObjectNode

The added object

State.event:object_changed

This event is emitted when a parameter of an object is changed. This change can come from Max or when the value of the parameter is set directly.

Name Type Description
object ObjectNode

The changed object

param ParamNode

The parameter node

State.event:object_removed

This event is emitted when an object is removed from Max.

Name Type Description
object ObjectNode

The removed object

State.event:patcher_added

This event is emitted when a patcher is added in Max.

Name Type Description
object PatcherNode

The added patcher

State.event:patcher_changed

This event is emitted when a parameter of a patcher is changed. This change can come from Max or when the value of the parameter is set directly.

Name Type Description
patcher PatcherNode

The changed patcher

param ParamNode

The parameter node

State.event:patcher_removed

This event is emitted when a patcher is removed from Max.

Name Type Description
object PatcherNode

The removed patcher

State.event:reset

This event is emitted when the web socket connection is persistently interrupted to the point that the xebra state and Max state fall out of sync. In this case, xebra will attempt to reset and rebuild the state, which fires this event. This should happen very infrequently. A state#loaded event will fire when this event fires.