> For the complete documentation index, see [llms.txt](https://developers.newbluefx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.newbluefx.com/api-examples/sample-controllers-tour/02-subscribe-for-notifications.md).

# Subscribe for Notifications

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

<figure><img src="https://2284285836-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXkMvk0MrY3BcyplZ0pf7%2Fuploads%2FTnFq9ENN98zHENymUBiW%2Fdownload-2.png?alt=media&amp;token=781d6797-198f-479c-bd4c-a5bad2edd234" alt=""><figcaption></figcaption></figure>

Notifications make it easy for your controller to always know the current state of the titles that it manages.

To implement, use the [`scheduleCommand`](/captivate-api/javascript-api-reference/using-the-servicehandler/schedulecommand-method.md) 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](/api-examples/json-command-tester.md), provides a way to try all the commands and it documents all of the parameters for each.

```javascript
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`](/captivate-api/javascript-api-reference/using-the-servicehandler/signals.md) events from the scheduler.

```javascript
// 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...
});
```

\\


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.newbluefx.com/api-examples/sample-controllers-tour/02-subscribe-for-notifications.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
