JavaScript API


The BrightSign API for JavaScript allows you to interface with the BrightSign player firmware to configure the player, retrieve system data, and interface with peripheral devices. This API allows for operation of a digital signage platform–including playback, scheduling, diagnostics, and network configuration–using HTML/JavaScript, without the need for extensive coding in BrightScript.

This API replaces the BrightScript JavaScript objects–though these objects are still offered for backwards-compatibility purposes. Unlike the legacy BrightScript JavaScript objects, there is no one-to-one relationship between BrightScript objects and objects in the new JavaScript API: Many BrightScript functions (e.g. HTTP server and file storage capabilities) are not exposed in the new API because JavaScript and Node.js® expose standardized, popular equivalents.

Enabling the JavaScript API

The BrightSign API for JavaScript is implemented with the Node.js module, which is included with the Chromium engine on the player. To use the BrightSign API with an roHtmlWidget instance, you must enable Node.js when creating the widget:





In the above example, Node.js is enabled by including the nodejs_enabled:true entry in the associative array that is passed during creation of the roHtmlWidget instance.

Loading BrightSign Modules

The BrightSign API does not exist in the global (window) namespace of the JavaScript runtime. Instead, like Node.js objects, BrightSign modules are loaded using the require() function (i.e. require("@brightsign/<module_name>")). BrightSign modules are actually part of the firmware, but in terms of usage, they are identical to other Node.js modules.

var NetworkConfigClass = require("@brightsign/networkconfiguration");   // Call the class constructor for the networkconfiguration object.
var wifi = new NetworkConfigClass("ethernet"); 							// Create an instance of the networkconfiguration class.

Synchronous and Asynchronous Methods

BrightSign modules contain both synchronous and asynchronous methods. Synchronous methods return an object that can be used immediately, while asynchronous methods return a Promise object, which will itself return the object data when the operation is resolved. Scripts must handle these delayed returns (typically using the .then() and .catch() methods available on the Promise object).

var NetworkConfigClass = require("@brightsign/networkconfiguration");
var wifi = new NetworkConfigClass("wlan0"); 
wifi.scan().then(											 // Call the Scan() method, which returns a promise.
		function(data){console.log(JSON.stringify(data));}) // The resolve/success case, which prints the scan results 
		function(data){console.log(JSON.stringify(data));}) // The reject/failure case, which prints the failure reason