Data Connectors
Data Connectors are defined in the CMS attached to a DataSet which has been marked as “real time”. Real time DataSets can be scheduled to players via the Schedule page.
Data Connectors persist across layout changes and changes to the schedule loop.
In a nutshell, the CMS is used to create the data structure definition, describe how it should be collected on the player and set when that should happen. The Player then runs the data connector, saves data to a local database and makes that available to widgets that need it.
We have a hello world that uses the User-Defined Javascript example to follow along.

The purpose of a data connector is to define JavaScript which will run on the Player, fetch data from a data source and make it available to widgets via xiboIC, or set schedule criteria.
The flow of data is described below:

While the data connector is running, it uses as helper class called xiboDC inform the player of a change in data or criteria. In both cases the player notifies interested parties of the change.
To be notified of new data, Widgets must register their interest in data changes and can then process those as needed. Widgets use xiboIC to getData once notified or as they need to.
Initialisation
JavaScript in a Data Connector needs to define a window function called onInit which will be called when the JavaScript engine is ready.
The JavaScript features available are player dependent and if you know that you will be using the Data Connector on older hardware, you should find out which web engine is available and code accordingly.
Parameters
All Data Connectors have their parent dataSetId available as a window parameter. This can be used to set data for that dataSetId and update any Elements using it.
During scheduling is it possible to provide additional parameters in HTTP query format, e.g. param1=one¶m2=two. These parameters are also made available as window parameters inside the Data Connector.
Real time data
Data Connectors are responsible for connecting to a 3rd party data source, retrieving data and deciding when to pass that on.
Retrieving data
Connecting to the 3rd party and retrieving data is left to the Data Connector developer.
For HTTP requests a utility function called xiboDC.makeRequest() is available with the following method signature. This request will be passed to the player to handle in native code.
You can use any JavaScript supported by your player’s web engine.
In due course we will be adding platform specific functionality for consuming data from Serial Ports, known sensor vendors, etc. If you have other use cases please let us know.
Setting data
Once data has been collected, Data Connectors can set it on the player and choose whether to notify widgets. This is accomplished in two steps.
Set data
To set data, Data Connectors can use xiboDC.setData() with the following method signature. Once set, data is available to any widgets running locally on the player. It is not available externally to the player.
Setting data happens asynchronously and therefore a done handler is provided.
Data should always be set as a string to avoid any differences between player types when data is retrieved.
If you are using the core “Real time data” widget with Elements or a core template, the data key you need to update is the window.dataSetId.
Example - Incrementing a timer:
In this example our Data Connector will initialise a counter at 0 and then update it once per second. Each time the counter updates, all interested widgets are notified, which is explained in the next section.
Notify
At an appropriate time, the Data Connector can notify all interested parties that data has been updated. This is done using xiboDC.notifyHost() with the following method signature.
Usually the data key used to notify will be the same as the data key used to set data, as shown in the timer example above.
The data key does not have to be the same as the data key of the setData operation, for example if you want to group multiple data keys together in one notification you could give another name for your widget to respond to.
If you are using the core “Real time data” widget with Elements or a core template, the data key listened for is the window.dataSetId.
Testing
Data Connectors can be tested in the CMS using the “View Data Connector” page accessible via the row menu for its parent DataSet.
The Data Connector JavaScript is provided to the left, and a tabbed live view provided to the right, with the following tabs:
Test Params: A field to enter test params which will be made available to the Data Connector
Logs: Captured console logs
DataSet Data: A table representation of data whose data key matches the DataSet ID
Other Data: A JSON representation of data whose data key does not match the DataSet ID
Schedule Criteria: A table showing schedule criteria and their TTL
Display on a Layout
Data from a Data Connector can be displayed on the player via:
Embedded widget
HTML package widget
Real time data widget
Embedded / HTML widget
Widgets use xiboIC to be notified of changes to data and to request data for rendering. As with data supplied by the CMS, the widget is responsible for parsing, formatting and displaying it.
To work with real time data a widget must implement two functions:
xiboIC.getData()xiboIC.registerNotifyDataListener()
Get Data
Widgets can call xiboIC.getData() to retrieve data for a data key. Retrieval is asynchronous so a done callback function should be supplied to handle the data retrieved.
The done function will receive a status and a value. The value will be the stored data for that data key and will always be a string.
Notifications
Xibo has a notification listener in place which should be used to get an update when data changes. Widgets should avoid polling and redrawing.
To receive an update, the xiboIC.registerNotifyDataListener() should be called and given a single callback. Only one callback per widget is allowed.
Real time data Widget
Xibo's DataSet widget is capable of displaying Real Time data from a Data Connector. Choose the DataSet which holds your Data Connector and it will be automatically enabled for real time.
Testing
To test a real time data widget open it in the layout editor or preview with the Data Connector page open in another tab. Data collected by the Data Connector page will be shared across tabs and provided to the widget in the same way as it would in the player.
Changes on either side require a tab refresh.
Last updated
Was this helpful?

