Expand | ||
---|---|---|
| ||
|
...
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 integrated Node.js implementation in OS 8.2.x and OS 8.3.x is based on Node v10. For further documentation and usage information, consult the Node.js 10.0.0 API documentation.
...
Node.js is enabled for individual roHtmlWidget instances by including the nodejs_enabled:true
entry in the initialization parameters of the roHtmlWidget object.
Example:
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" } h=CreateObject("roHtmlWidget", r, config) h.Show() |
...
If you want to reference other domains in remote applications, set the websecurity
parameter to false
when initalizing the roHtmlWidget, as shown below:
Example:
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() |
...
If you want to use JavaScript storage applications, you will need to specify a storage_path
and storage_quota
when initializaing the roHtmlWidget:
Example:
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
...
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:
Code Block |
---|
const SerialPort = require('@serialport/stream');
const BrightSignBinding = require('@brightsign/serialport');
SerialPort.Binding = BrightSignBinding; |
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 BrightSign OS 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..
...
To use webpack®, you will need to place your Node.js entry-point function in a separate file (e.g. "index.js"), rather than as inline HTML. This file will contain the references to other JavaScript files and Node.js modules:
Example index.js:
Code Block | ||
---|---|---|
| ||
var myutils = require('./utilities'); // My utilities.js var moment = require('moment'); // A node module function main() { myutils.foo(); moment.now(); //... } |
The JavaScript file containing the Node.js entry point can then be referenced in the HTML file:
Example HTML:
Code Block | ||
---|---|---|
| ||
<script src='./index.js'></script> |
...
We recommend using the process.chdir()
call at the beginning of the script to change the process path:
Example:
Code Block | ||
---|---|---|
| ||
var process = require("process"); process.chdir("/storage/sd"); |
Alternatively, if you have modules located on multiple storage drives, you can append multiple search paths to a module:
Example:
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.
...
Another example is the script below, which initializes an HTTP server on the BrightSign player at port 8000. When a client (for example, 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.
Example:
Code Block |
---|
<html> <script> function displayMessage() { // Load the http module to create an http server. var http = require('http'); // Configure our HTTP server to respond with Hello World to all requests. var server = http.createServer(function (request, response) { var device_info = new BSDeviceInfo(); response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Device Information:\n" + device_info.model + "\n" + device_info.bootVersion + "\n"); var ip = request.connection.remoteAddress; document.getElementById("Ip").innerHTML+="Server responded to: "+ ip + "<br>"; console.log("Server responded to request from " + ip); }); // Listen on port 8000, IP defaults to 127.0.0.1 server.listen(8000); // Display it on brightsign browser var os = require('os'); var interfaces = os.networkInterfaces(); var addresses = []; for (var k in interfaces) { for (var k2 in interfaces[k]) { var address = interfaces[k][k2]; if (address.family === 'IPv4' && !address.internal) { addresses.push(address.address); } } } var message = "Server running at: " + addresses[0] + ":8000<br>"; document.getElementById("Ip").innerHTML+= message; // Print message on console console.log(message); } </script> <body style="background-color:red" onload="displayMessage()"> <div id = "Ip" style="font-size:60px; text-align:center;"> </div> </body> </html> |
...