Expand | ||
---|---|---|
| ||
|
...
Our customers often need to communicate between applications on a BrightSign player, or between a BrightSign player and the outside world. This can be done using various protocols: HTTP, serial, and UDP are the most popular. You can write applications in either BrightScript or JavaScript to create this functionality. If you choose to write your application in JavaScript, you will need Node.js® to implement features such as hosting a web server in JavaScript.
BrightSign makes a Node.js endpoint available so that our partners can use Node.js modules and features.
BrightSign Node.js Implementation
BrightSign players support the Node.js runtime environment, which runs on the same V8 JavaScript engine used by Chromium. The Node.js® and Chromium instances share a single JavaScript execution context, so JavaScript applications can access both Node.js modules and DOM objects at the same time. BrightSign firmware pushes Node.js events to the Chromium event loop, ensuring that JavaScript applications receive Node.js and DOM events seamlessly.
...
Node.js is not enabled for iframes or Web Workers.
Enabling Node.js
Node.js object functionality is available in BrightAuthor:connected when users specify Node.js items in Presentation Settings. Node.js objects are not available in BrightAuthor.
...
If you are using a BrightAuthor plugin to enable Node.js, you will need to set other desired parameters in the plugin, rather than 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.
Cross-Domain Security
Chromium has default security measures for preventing cross-site scripting attacks: If the URL for the roHtmlWidget instance is a remote domain, JavaScript applications from that domain cannot make HTTP requests to other domains; on the other hand, if the URL points to local storage, requests to other, remote domains are acceptable.
...
Code Block |
---|
r=CreateObject("roRectangle", 0,0,1920,1080) is = { port: 3000 } config = { nodejs_enabled: true inspector_server: is brightsign_js_objects_enabled: true url: "http://www.mysitehere.com" security_params: {websecurity: false} } h=CreateObject("roHtmlWidget", r, config) h.Show() |
Web Storage
If you want to use JavaScript storage applications, you will need to specify a storage_path
and storage_quota
when initializaing the roHtmlWidget:
...
Code Block |
---|
r=CreateObject("roRectangle", 0,0,1920,1080) is = { port: 3000 } config = { nodejs_enabled: true inspector_server: is brightsign_js_objects_enabled: true url: "file:///sd:/nodehello.html" storage_path: "SD:" storage_quota: 1073741824 } h=CreateObject("roHtmlWidget", r, config) h.Show() |
JQuery
JQuery® requires a workaround to operate correctly with Node.js (see this page for an example). This workaround requires modifying the content, so if you don't have control over the webpage enabling node in your HTML widget, this can cause an intractable problem. You should only enable Node.js if you are planning to use it (for example with our JavaScript APIs).
See also HTML Best Practices.
Node SerialPort
The BrightSign player provides JavaScript serial port bindings for the Node SerialPort package. These bindings can be used using with the @brightsign/serialport API:
...
Also see our reference implementation on GitHub.
Reloading Node.js Enabled Web Applications
Any customer application that uses @brightsign objects, and some of the "BS" objects, will throw a JavaScript exception when reloaded in BrightSignOS 8.0 to 8.4 (even though it may have worked in OS 7.x and earlier) due to limitations with native modules in Node 10. This problem will be fixed in OS 8.5 and above, which ships with Node 14.x. You can also disable Node.js (and @brightsign objects) if you don’t need it..
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.
...
The majority of Node.js modules contain JavaScript code only. However, some modules contain binary code. When a module containing binary parts is installed using "npm install", the binary parts are compiled for the local platform (usually Intel x64), and this code will not run on a BrightSign player. Currently, the BrightSign Node.js implementation is limited to JavaScript code only.
WebPack
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.
...
View file | ||
---|---|---|
|
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:
...
Code Block | ||
---|---|---|
| ||
module.paths.push("/storage/sd/") module.paths.push("/storage/ssd/") module.paths.push("/storage/usb1/") |
Debugging Applications
When Node.js modules are enabled, they become visible from the Chromium remote inspector, allowing you to debug applications. The console.log works like a normal web application: Output is redirected to both stderr and the remote inspector.
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.
...
This example is specific to BrightSign players and requires node.js runtime, enabled by use of the roHtmlWidgetnodejs_enabled
flag, to write files to disk.
Node.js Examples
GitHub contains a Node.js-starter-project. This project was originally created for BrightAuthor but can also be used with BrightAuthor:connected.
...