Like NW.js and Electron, BrightSign does not use sandboxing. Instead, it launches the render process with a Node.js user and storage group, which has write permissions for local storage and read permissions for the entire file system. It also can access networking interfaces and use privileged ports.
The BrightSign Node.js implementation is concurrent with Node.js version 10.0.0. For further documentation and usage information, consult the Node.js 10.0.0 API documentation.
Node.js is not enabled for iframes or Web Workers.
Node.js currently cannot be enabled via BrightAuthor; it must be enabled in the BrightScript autorun. Node.js is enabled for individual roHtmlWidget instances by including the
nodejs_enabled:true entry in the initialization parameters of the roHtmlWidget object.
If you are using a BrightAuthor plugin to enable Node.js, you will need to set other desired parameters in the plugin, rather with an HTML5 state. For example, if you want to enable the mouse cursor, you will need to set
mouse_enabled:true during the roHtmlWidget initialization, rather than checking the box in the HTML5 state.
If you have firmware version 6.2.x installed, you will first need to enable multi-process mode for Chromium before creating the roHtmlWidget instance (this step is not required for firmware versions 7.0.x and later). Using BrightScript, add the
mp entry to the
html section of the player registry and set its value to
If you want to reference other domains in remote applications, set the
websecurity parameter to
false when initalizing the roHtmlWidget, as shown below:
storage_quota when initializaing the roHtmlWidget:
JQuery requires a workaround to operate correctly with Node.js. See here for an example.
Reloading a Node.js Instance
Packaging and Delivering Node.js Applications
To deploy your Node.js application to a BrightSign player, run "npm install" on your computer. This will create the
node_modules directory. Copy this directory to the SD card along with the rest of the application.
When initialized, the BrightSign Node.js implementation seeks to the
node_modules directory relative to the loaded HTML file. Like a standard Node.js application, it then loads all modules contained in the
The node_modules directory associated with a Node.js application may contain hundreds or thousands of unnecessary files. The webpack bundler allows you to reduce the node_modules directory to a manageable size.
To use webpack, attach
main() to the window object so that it can be found from the HTML file:
To build your bundle, run the following npm steps on your computer:
Now you can publish the index.html and bundle.js files; there's no need to publish the
node_modules directory. See the sample webpack configuration below for more information.
Device Storage Paths
To load Node.js modules and read/write files, you must first define the root directory of the device storage. The following are common root directories:
We reccomend using the
process.chdir() call at the beginning of the script to change the process path:
Alternatively, if you have modules located on multiple storage drives, you can append multiple search paths to a module:
When Node.js modules are enabled, they become visible from the Chromium remote inspector, allowing you to debug applications in a standard way. The console.log works like a normal web application: Output is redirected to both stderr and the remote inspector.
The port number of the inspector is determined when the roHtmlWidget is initialized (see the BrightScript example above). To access the inspector, navigate to the IP address of the player, along with the specified port, using a desktop browser.
Downloading Large Files
If your application uses the XMLHttpRequest object to download a large file (100-200MB, depending on the player model), the player will run out of memory and the download operation will fail. The XMLHttpRequest object first downloads the whole file into memory, then creates a blob object of equal size, so memory requirements for a download are effectively double that of the file size.
The following script initializes an HTTP server on the BrightSign player at port 8000. When a client (e.g. a desktop browser) connects to the server, it will send the model number and boot version of the player to the client. The script also displays the IP address of the connected client on the screen attached to the player.
Built-in modules, such as "os" and "http", can be initialized using the
require() method. If the
nodejs_enabled:true entry is not included when initializing the roHtmlWidget object (as shown above), the
require() method will not be available.