Understanding Signals
The Captivate backend exposes a variety of “signals” that you can connect to for getting instant updates from the Captivate backend.
Signals
connecting
To connect to one of these signals, call the connect method (i.e. scheduler.[SIGNALNAME].connect) on the desired signal and provide a callback that will handle the signal data. Signal data will be different for each signal and is specified in the list below.
disconnecting
Signals expose a disconnect method you can use to disconnect your callback from a signal, but our library makes it easier for you by returning a "canceler" function that you can use to disconnect your callback from the signal. Using the canceler function allows you to use an anonymous function for the callback and still be able to disconnect it from the signal later.
const canceler = SeriviceHandler.scheduler.onNotify(() => {
console.log('we got a notification!!');
});
// ... some time later
canceler(); // all cleaned upNote: If you call the connect method with an anonymous function, you must use the returned canceler function. There won't be a way to call disconnect with the same function in the future because it was anonymous.
The most useful of all the signals is onNotify since it allows you to receive updates whenever a title’s play status or data variables change. Use this in combination with a subscribe command according to the example below.
onNotify- Calls the callback with a JSON-encoded string of notification data.Includes data requested from a previous
subscribecommand.Includes all commands passing through the command bus.
newCommandXML- Calls the callback with an XML document that represents the last command executed in the system.messageIn- When another controller calls themessageOutmethod, the connected function will be called with three arguments:from,to,datawheredatais the JSON-encoded data from the message.redirected- Informs when the HTML page in the Data Controller is redirected (rarely used).serverPortChanged- When server ports were changed (rarely used).settingsChanged- The connected function will be called with theinputNameas the first argument whenever any controller settings are saved. If you get this, you should check to see if theinputNamematches your controller and then maybe request the latest settings usingloadSettings. NOTE: Beware of creating infinite loops.variablesChanged- The function you connect will be called with theinputNameas the first argument (or"all"if an input name was not specified in the update command) and a map of changed variables as the second argument.This function doesn’t work entirely as expected. It was originally designed to keep controller UI in sync with the true state of the Captivate system, but it only reports controller variable changes made through API calls. Remember that editing a variable value from the program UI (Live Data panel, Values Grid, etc) directly affects the graphic variable and therefore doesn’t trigger this callback. If you want to keep track of graphic variable updates, you should
subscribeto thedataevent.
Example:
Full Notification Example with Subscription
To make full use of the onNotify signal, you need to also understand the subscribe command, so this example shows how to do that
Example:
A Note About Notification Senders
The sender name you specify in the subscribe command creates a subscription object in the Captivate backend. You can modify it by adding or removing event subscriptions as you wish. This can also be useful in your message handling code to make sure you are only paying attention to messages that come from the sender you are interested in. However, the tight coupling of sender and notification messages only happens with the External API connection methods.
The WebSocket API, for legacy reasons, currently sends all notification messages to all WebSocket clients regardless of what sender they have subscribed to and it does this for every inter-process message whether the target input can be found or not. Since the other API connection methods are more selective with their message passing, the WebSocket API might move in that direction in future releases. Therefore, for your controllers, it’s good practice to specify a sender name for all subscribe operations, and to have your notification handler discard all messages that don’t come from that sender.
Last updated