API Version: Development

Javascript API data fetching

Non-live data

If the live data feed is to be used, this section should be skipped as it is MUCH more efficient to allow the start of the live data feed to cause the relevant data fetch to occur.
This facility is intended for applications which want to load static data only and have no need for live updates.
IPCortex.PBX.fetchData(successCB, failCB);
or as a Promise:
IPCortex.PBX.fetchData().then(resolveCB, rejectCB);

Using live data

The API does not assume that you want a live data feed. A live feed will also allow events (below) to be used. To initialise the live data feed use:
IPCortex.PBX.startFeed(successCB, failCB);
or as a Promise:
IPCortex.PBX.startFeed().then(resolveCB, rejectCB);
It can be stopped by logging out or with:

Events and listeners

Responding to events / Listeners

Most objects support at least 2 events, 'new' and 'update', which the calling application can subscribe to notifications on.
Event: new
The returned object has just been created. This listener must be added to the top-level class definition (IPCortex.Types.*class*) as the listener cannot be added to an object that does not yet exist.
IPCortex.Types.Device.addListener('new', callback);
The addListener call returns the callback on success, or null on failure.
NOTE: Adding this listener will not currently report any historically created objects.
Event: update
A change of some kind has occurred on the returned object. This listener, and all other of its kind can be added to either a specific object instance, or to the top-level class.
IPCortex.Types.Device.addListener('update', callback);
myDevice.addListener('update', myCallback);

Removing listeners

A listener will be cleaned up if an object is destroyed (eg. a dead call or closed room), but may also be removed by supplying the original parameters to the removeListener method:
IPCortex.Types.Device.removeListener('update', callback);
myDevice.removeListener('update', myCallback);
If a callback throws an error, or if it cannot be called, it will also be removed automatically.

The listener callback

The listener callback is called with a single parameter containing a reference to the 'new' or 'updated' object. It is up to the application to determine the nature of the change.