Variables
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.
Table of Contents
Methods
close
()
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
()
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
Resolves a variable pattern string into a final display string
Returns:
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
Returns a promise that will be resolved when this end point is opened
Returns:
Example:
let C = new CantabileApi();
C.application.open();
await C.application.untilOpen();
Starts watching a pattern string for changes
Parameters:
-
pattern
StringThe string pattern to watch
-
[callback]
Function optionalOptional 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();