Show:
Extends EndPoint

Provides access to Cantabile's internal variables by allowing a pattern string to be expanded into a final display string.

Access this object via the variables property.

Methods

close ()

Inherited from EndPoint: EndPoint.js:55

Closes the end point and stops listening for events.

This method no longer needs to be explicitly called as end points are now automatically closed when the last event listener is removed.

open ()

Inherited from EndPoint: EndPoint.js:35

Opens this end point and starts listening for events.

This method no longer needs to be explicitly called as end points are now automatically opened when the first event listener is attached.

Use this method to keep the end point open even when no event listeners are attached.

resolve () Promise | String

Defined in Variables.js:125

Resolves a variable pattern string into a final display string

Returns:

Promise | String:

A promise to provide the resolved string

Example:

let C = new CantabileApi();
console.log(await C.variables.resolve("Song: $(SongTitle)"));
let C = new CantabileApi();
C.variables.resolve("Song: $(SongTitle)").then(r => console.log(r)));
untilOpen () Promise

Inherited from EndPoint: EndPoint.js:137

Returns a promise that will be resolved when this end point is opened

Returns:

Promise

Example:

let C = new CantabileApi();
   C.application.open();
await C.application.untilOpen();
watch
(
  • pattern
  • callback
)
PatternWatcher

Defined in Variables.js:166

Starts watching a pattern string for changes

Parameters:

  • pattern String

    The string pattern to watch

  • [callback] Function optional

    Optional callback function to be called when the resolved display string changes.

    The callback function has the form function(resolved, source) where resolved is the resolved display string and source is the PatternWatcher instance.

Returns:

Example:

Using a callback function:

let C = new CantabileApi();

// Watch a string pattern using a callback function
C.variables.watch("Song: $(SongTitle)", function(resolved) {
    console.log(resolved);
})

   // The "variables" end point must be opened before callbacks will happen
C.variables.open();

Using the PatternWatcher class and events:

let C = new CantabileApi();
let watcher = C.variables.watch("Song: $(SongTitle)");
watcher.on('changed', function(resolved) {
    console.log(resolved);
});

   // The "variables" end point must be opened before callbacks will happen
C.variables.open();

/// later, stop listening
watcher.unwatch();