Subscribe for Notifications
This builds on the first project by adding an option to subscribe for title playback notifications.

Notifications make it easy for your controller to always know the current state of the titles that it manages.
To implement, use the scheduleCommand
API call.
scheduleCommand
is a general purpose API that supports a wide range of commands. In fact, even the scheduleAction
call can be made through scheduleCommand
.
It takes three parameters: the command name, a JavaScript object with all the parameters, and a JavaScript object with optional variable settings. Note that the last app in the tour, JSON Command Tester, provides a way to try all the commands and it documents all of the parameters for each.
scheduler.scheduleCommand('subscribe', { input: inputName, events: 'play, data' }, {});
In this case, the command is “subscribe.” The parameter “input” instructs it to subscribe to all titles connected to this input, and the parameter “events” sets which behaviors to notify: “play” for playback status and “data” for changes in variables.
To receive notifications, you must also respond to onNotify
events from the scheduler.
// Once subcriptions are enabled, listen for onNotify callbacks.
scheduler.onNotify.connect((notification) => {
// Convert the payload string into a Javascript object.
let jsonReply = JSON.parse(notification);
// And then use the object to inform the state...
});
\
Last updated