0

Enable NodeJs on my BrightSign player

It should be possible to enable NodeJS according to this documentation:

http://docs.brightsign.biz/display/DOC/Node.js

The problem is that I don't really understand how this is supposed to be done. Where should I put the code that is given in the documentation? The documentation is saying that I should put the code in the player registry. But I can't find any explanation on what that is. Is it the autorun.brs?

It is also unclear what kind of functionality I can expect running NodeJs on BrightSign. Can I run a nodejs application that servers a webpage and display that webpage in my presentation on the screen I have attached to a monitor? Can I send udp messages to the nodejs app?

22 comments

  • 0
    Avatar
    Lyndon

     

    So this code would just go into a text file named autorun.brs:

     

    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()
     
     

     

     

    Yes, you can use a script to make registry changes.  If it's a standalone script you'd name it autorun.brs. 

    Yes, you could run a node.js app.

    Yes, you could send udp messages to it.

     

     

  • 1
    Avatar
    Mark van den Berg

    Hi Lydon,

    What about this part of the code, to enable node.js:

    rs = createobject("roregistrysection", "html")
    mp = rs.read("mp")
    if mp <> "1" then
        rs.write("mp","1")
        rs.flush()
        RebootSystem()
    endif
     
    Do you have to place it in a different autorun.brs and run this file first?
    Of is it also ok to place this code before:
     
    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()
     
     
    I've tried to start a node.js application, with the example file which you can find:
     
    I't will start the webinspector as expected, but the webinspector won't show any .html files.
     
    When looking in the DWS the logs says start ndex.html, and a couple of seconds later is says start about:blank.
     
    Can this be a problem with the  'node_modules directory' ? Or do you have to looking somewhere else?
     
    Is it a possiblity the place the node_modules as download in the documentation as well? So we can test a working example?
  • 0
    Avatar
    par

    It would be really great if there could be some kind of Hello World tutorial for running NodeJs on BrightSign players. A complete example with the files needed and where they should be placed. The example you have in the documentation leaves a lot to the reader to understand.

    Like Mark, I also am confused about where to put the "rs = createobject("roregistrysection", "html")..." code snippet.

    And the html code at the bottom of the page, is that the content of the nodehello.html file that is referenced in the code snippet starting up nodejs?

    Also, if I manage to start nodejs, how do I display the webpage? I was thinking that I should create a project in BrightAuthor containing a html5 widget that is pointing to localhost:8000. But then I noticed that port 3000 is defined in the example code but that is maybe nothing I need to care about since the javascript in the html code is listening to 8000?

    I found this code example https://github.com/brightsign/bs-asset-fetcher Would be really great having some steps for starting that on a BrightSign.

  • 0
    Avatar
    Lyndon

    https://www.brightsignnetwork.com/download/Scripts/node-js-test.zip

    On the sd card, you put these three files. The main autorun will delete itself, and then rename the autorun-next, which will launch the index.html file. That's all.



    you can edit the autorun-next file on the card to change the name of the file to be launched. Once it's run, there will only be one autorun.brs on the card, which is what used to be the autorun next. you can edit that and reboot for changes to be applied.


    This index.html is the note example from the docs page...

  • 0
    Avatar
    Lyndon

    when you log into port 8000 on the unit running the index.html you get:

     

    The unit's display will report the ip address and port number and the mac address of devices that connect to the server. THe only oddity is it seems the version number reported is wrong above. I'm checking on that. 

     

  • 0
    Avatar
    Mark van den Berg

    Thnaks Lyndon, working fine.

    Reported version number is the Boot version, which is corresponding to the boot version in the dws

     

     

  • 0
    Avatar
    par

    Thanks! It is working for me also.

    The only problem I have is that when logging in with ssh hangs when running this presentation. I'm pasting the output bellow.

    Should the SD card only contain the files in your zip file or should I override the config files that is created by BrightAuthor? The output bellow is from first starting the player with config files from BrightAuthor, then starting the player with a autorun.bsr containing ssh enabling code named as autorun.bsr. The ssh works after this. Then I added your files, which replaces the autorun.bsr. The red screen is displayed with an ip address. When I try to login with ssh the login freezes.

    I also can't reach the debug port when running <ip-address-of-bs-player>:3000. I get net::ERR_CONNECTION_TIMED_OUT.

     

    Output when logging in with SSH:

    brightsign@<ip-address-of-bs-player>'s password:
    BrightSign HD1023 35D68U002103 v6.2.94

    url = file:///index.html
    === BS: Received event roNetworkAttached
    === BS: Received roNetworkAttached
    === BS: Received event roHtmlWidgetEvent
    === BS: Received event roHtmlWidgetEvent
    === BS: Received load finished
    === BS: OK to show HTML, showing widget now

  • 0
    Avatar
    par

    It works pretty well. The only problem I have with the example code is that ssh stops working. It seems like it has something to do  with HandleEvents in autorun-next.bsr. If I disable the call to that function ssh starts working again. Is there something wrong with the script?

  • 0
    Avatar
    Lyndon

    par, the debug port in my example was on 2999. 

    I can't think of a good reason handleevents would break ssh. I'll check into it. I posted a version with handle disabled. I also updated the original so it's just a single autorun, not two. 

    https://www.brightsignnetwork.com/download/Scripts/node-js-test_nohandle.zip

     

    This script example doesn't use anything from brightauthor, just the script to launch your html. 

     

     

     

  • 0
    Avatar
    par

    Thanks!

    What is the purpose of the handler? I mean, when is it needed? Is it needed for touchevents or something? I just want to know what I miss if I remove it.

  • 0
    Avatar
    Rob

    Hi Lyndon,

    I'm not getting the red screen from the brightsign browser/HDMI out on my XT1143, I get a black screen with a X pointer.

    The dws logs show:

    [ 18.779] [INFO] [source file:///index.html:47]: Server RUNNING at: 192.168.0.100:8000<br>
    [ 20.564] SNTP: time.brightsignnetwork.com [184.72.42.7] rtt=21ms
    [ 20.565] Setting system clock to 1495604198.378862
    [ 20.566] NetworkTime: clock set to 2017/05/24 05:36:38.379 UTC
    [ 25.969] dhcpcd[932]: eth0: no IPv6 Routers available

    Any thoughts? Thanks!

  • 0
    Avatar
    par

    Sill looks like the HandleEvents is active in autorun.bsr in the zip file that you have attached. Maybe you have uploaded wrong zip file?

    It seem like I need the HandleEvents if I want to display a HTML widget, which I do. I get the impression that the HandleEvent subroutine is interfereing with the ssh login somehow.

  • 0
    Avatar
    joris

    Thank you Lyndon for the great example.

     

    For those who see a black screen, you'll have to call the Show() method on the HTMLWidget.

     

        gaa.htmlWidget = CreateObject("roHtmlWidget", rect, config) 'new added config object after rect 5-16-17
        gaa.htmlWidget.Show()
  • 0
    Avatar
    Dorian

    @lyndon

    https://www.brightsignnetwork.com/download/Scripts/node-js-test.zip 

    does not contain a autorun-next.brs.

    When I run the following code snippet, the Player keeps on rebooting (HD223, Firmware: 6.2.33)

    rs = createobject("roregistrysection""html")
    mp = rs.read("mp")
    if mp <> "1" then
        rs.write("mp","1")
        rs.flush()
        RebootSystem()
    endif
     
    help is much appreciated
  • 0
    Avatar
    Hopeton

    I am having the same issue as Dorian.  I did not find an autorun-next.brs file and player keeps on rebooting (HD233, Firmware: 6.2.45).  I do see the black screen with an X before it reboots.

     

  • 0
    Avatar
    Hopeton

    Upgrading to the latest firmware (https://www.brightsign.biz/downloads/xd3-series) fixes the rebooting issue for me.

  • 0
    Avatar
    Andreas Planck

    Can node.js be enabled and the player still getting content as usual (BSN or local presentation) ?

    And can i enable node.js with a plugin or do i have to modify the autorun file?

  • 0
    Avatar
    Pnorman

    I have the same question as Andreas.  Am I able to enable nodeJS and keep using bright author, or do i have to do everything via html5 to use nodejs?  I tried adding this autorun file to my project in brightauthor as a custom autorun, but it rejects it.

  • 0
    Avatar
    Lyndon

     

    Yes, you can use node with brightauthor.

    https://www.brightsignnetwork.com/download/Scripts/node_readme.zip

     

    1. The plugin I'm attaching is called "httpserver". That's the name you'll use when you add it.

    2. It assumes your files including the subfolders you get when doing npm -install will all be included in an "npm.zip" file that you'll attach to the files tab when you publish

    3. Plugin unzips everything to a /node folder on the sd card, so you'll have to adjust any file references accordingly.

     

     

     

    Plugin name: httpserver
    Extract folder: /node	- all assets from the npm.zip file go there
    Attached file: npm.zip - should contain node application and modules
    
    The node plugin creates a /node directory on the sd card. When the plugin runs, it copies the npm.zip
    file to the root and extracts it into the /node directory.
    
    It then starts the server.html file from the node directory. 


     

  • 0
    Avatar
    Thai Nguyen

    Hi Lyndon,

    I try to understand how to install NodeJs to BrightSign. 

    First step I make a autorun.brs file:

    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:/index.js"


    }
    h=CreateObject("roHtmlWidget", r, config)
    h.Show()

     

    and a index.js to write a text "Hello Word" when the client connect to port 3000:

     

    const http = require('http');

    const hostname = '192.168.1.143';
    const port = 3000;

    const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('Hello World\n');
    });

    server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
    });

     

    I copy both files directly to sd card (overwrite existing autorun.brs).

    The problem, BrightSign does not know where is my index.js. How to tell the BrightSign to run my index.js?

    (see the picture when open the client)

    I show you also my test in Windows 10 with NodeJs installed: (in this case the IP is 127.0.0.1)

    Thank you.

    Thai.

     

     

     

     

  • 0
    Avatar
    Nick Young

    @Thai Nguyen

    url: "file:///sd:/index.js"

    I think you URL needs to point to an HTML file, which itself references your index.js via a <script> HTML tag.

    If you see the example here https://docs.brightsign.biz/display/DOC/Node.js#Node.js-Node.jsExample, you'll note that the nodeJS code is in the script tag. You can either do this, or point the script tag at a separate JS file.

  • 0
    Avatar
    Thai Nguyen

    @Nick Young

    Yes, the BrightSign does not need to START Node.JS server by running Node.JS file like index.js.

     

Please sign in to leave a comment.