Cantabile Class
Represents a connection to Cantabile.
class Cantabile extends EventEmitter<any> {
constructor(options: string | Object);
set autoConnectEndPoints(value: boolean);
get autoConnectEndPoints(): boolean;
get options(): Object;
get state(): string;
connect(): Promise<void>;
disconnect(): void;
send(obj: object): void;
request(message: object): Promise<object>;
waitForConnected(): Promise<void>;
get host(): string;
get socketUrl(): string;
get song(): Song;
get setList(): SetList;
get songStates(): SongStates;
get keyRanges(): KeyRanges;
get showNotes(): ShowNotes;
get variables(): Variables;
get onscreenKeyboard(): OnscreenKeyboard;
get commands(): Commands;
get transport(): Transport;
get application(): Application;
get engine(): Engine;
get bindings(): Bindings;
}
#Constructors
#constructor()
Creates a new Cantabile network session
constructor(options: string | Object);
-
options.hostthe host to connect to (defaults to browser url, or localhost:35007) -
options.autoConnectif true automatically initiates connection -
options.autoConnectEndPointsif true automatically connects end point objects when accessed -
options.maxListenersset the max event listeners for this object (if supported)
#Properties
#application
Gets the Application object
get application(): Application;
#autoConnectEndPoints
Controls whether the sub-object end points are automatically connected when first accessed.
get autoConnectEndPoints(): boolean;
set autoConnectEndPoints(value: boolean);
#bindings
Gets the Bindings object
get bindings(): Bindings;
#commands
Gets the Commands object
get commands(): Commands;
#engine
Gets the Engine object
get engine(): Engine;
#host
The host URL
get host(): string;
#keyRanges
Gets the KeyRanges object
get keyRanges(): KeyRanges;
#onscreenKeyboard
Gets the OnscreenKeyboard object
get onscreenKeyboard(): OnscreenKeyboard;
#options
Gets the resolved options object used to construct this object
get options(): Object;
#setList
Gets the SetList object
get setList(): SetList;
#showNotes
Gets the ShowNotes object
get showNotes(): ShowNotes;
#socketUrl
The base socket url
get socketUrl(): string;
#song
Gets the Song object
get song(): Song;
#songStates
Gets the SongStates object
get songStates(): SongStates;
#state
The current connection state, either "connecting", "connected" or "disconnected"
get state(): string;
#transport
Gets the Transport object
get transport(): Transport;
#variables
Gets the Variables object
get variables(): Variables;
#Methods
#connect()
Initiate connection and retry if fails until success
connect(): Promise<void>;
#disconnect()
Disconnect and stop retries
disconnect(): void;
#request()
Stringify an object as a JSON message, send it to the server and returns a promise which will resolve to the result.
request(message: object): Promise<object>;
messageThe message object to send
#send()
Stringify an object as a JSON message and send it to the server
send(obj: object): void;
objThe object to send
#waitForConnected()
Returns a promise that will be resolved when connected
waitForConnected(): Promise<void>;
Example
let C = new Cantabile();
await C.waitForConnected();
#Events
#'connected' Event
Fired when entering the connected state
cantabile.on('connected', () => { });
#'connecting' Event
Fired when entering the connecting state
cantabile.on('connecting', () => { });
#'disconnected' Event
Fired when entering the disconnected state
cantabile.on('disconnected', () => { });
#'stateChanged' Event
Fired when the connection state of the session changes
cantabile.on('stateChanged', (newState: ConnectionState) => { });
newStateThe new connection state of the session