Websocket Subscriptions#
Subscriptions allow data to be pushed to the web client whenever there is a change within the project.
JavaScript#
subscribe_timeline_status#
Subscribe to changes in timeline status.
subscribe_timeline_status(callback)
The callback
is called each time a timeline changes state on the controller. Each time it is passed an object with the following attributes:
Attribute |
Value Type |
Description |
Value Example |
---|---|---|---|
|
integer |
Timeline number |
|
|
string |
The new state of the timeline: |
|
|
boolean |
Whether the timeline is currently affecting the output of any fixtures in the project. |
|
|
integer |
Current time position of the timeline playback, in milliseconds |
|
For example:
Query.subscribe_timeline_status(t => {
alert(t.num + ": " + t.state)
})
subscribe_scene_status#
Subscribe to changes in scene status.
subscribe_scene_status(callback)
The callback
is called each time a scene changes state on the controller. Each time it is passed an object with the following attributes:
Attribute |
Value Type |
Description |
Value Example |
---|---|---|---|
|
integer |
Scene number |
|
|
string |
The new state of the scene: |
|
|
boolean |
Whether the scene is currently affecting the output of any fixtures in the project. |
|
For example:
Query.subscribe_scene_status(s => {
alert(s.num + ": " + s.state)
})
subscribe_group_status#
Subscribe to changes in group level, as set by the Master Intensity action.
subscribe_group_status(callback)
The callback
is called each time the group master level changes on the controller. Each time it is passed an object with the following attributes:
Attribute |
Value Type |
Description |
Value Example |
---|---|---|---|
|
integer |
Group number |
|
|
string |
Group name |
|
|
integer |
New master intensity level of the group: 0-255 |
|
For example:
Query.subscribe_group_status(g => {
alert(g.num + ": " + g.level)
})
subscribe_remote_device_status#
Subscribe to changes in remote device online/offline status.
subscribe_remote_device_status(callback)
The callback
is called each time the remote device online/offline status changes. Each time it is passed an object with the following attributes:
Attribute |
Value Type |
Description |
Value Example |
---|---|---|---|
|
integer |
Remote device number |
|
|
string |
Type of remote device: |
|
|
boolean |
New online state of the remote device |
|
|
string |
Remove device serial number |
|
For example:
Query.subscribe_remote_device_status(r => {
alert(r.num + ": " + (r.online ? "online" : "offline"))
})
subscribe_beacon#
Subscribe to changes in the device beacon.
subscribe_beacon(callback)
The callback
is called each time the controller beacon status changes. Each time it is passed an object with the following attributes:
Attribute |
Value Type |
Description |
Value Example |
---|---|---|---|
|
boolean |
New beacon status |
|
For example:
Query.subscribe_beacon(b => {
alert(b.on ? "Beacon turned on" : "Beacon turned off")
})
subscribe_lua#
The receiver for the push_to_web()
Lua function.
subscribe_lua(callback)
The callback
is called each time a script on the controller calls the push_to_web()
function. Each time it is passed an object with a single attribute - the name or key string passed as the first argument to push_to_web()
. The value of this attribute is the second argument passed to push_to_web()
, converted to a string.
For example, if a project needs to send a touch slider level to the web interface, it might have the following in a trigger Lua script:
level = getMySliderLevel() -- user-defined function to get the current slider level
push_to_web("slider_level", level) -- invoke callbacks on subscribers
If level
is equal to e.g. 56 then the object passed the JavaScript callback will be:
{
"slider_level": "56"
}
And the subscription could be setup as follows:
Query.subscribe_lua(l => {
key = Object.keys(l)[0] // "slider_level" in the above example
value = l.key // "56" in the above example
alert(key + ": " + value)
})