FirstLegoLeague / fllscoring

FLL Scoring app. See Demo:
http://firstlegoleague.github.io/fllscoring/
GNU General Public License v2.0
14 stars 19 forks source link

server_modules/mhub: Add MHub support. #296

Closed poelstra closed 6 years ago

poelstra commented 6 years ago

Implements #285. Part of #245.

This is only adding a single MHub instance including configuration of host, node, user and pass. It is not actually used by anything on the server yet.

By default, connects to MHub server on localhost with no user/pass. To configure different host, node and credentials, start the server with e.g.:

npm start -- --mhubHost=wss://something:1234 --mhubNode=someNode --mhubUser=someUser --mhubPass=somePassword

To test whether the code works, I appended the following to the end of localserver.js:

var mhub = require('./server_modules/mhub');

mhub.onConnect(() => {
    mhub.subscribe('/scoring/scores/update', (m) => {
        console.log(m);
    }).catch((e) => {
        console.log('subscribe failed:', e.message);
    });
});

fileSystem.registerHook('write', 'data/scores.json', (data) => {
    mhub.publish('/scoring/scores/update').catch((e) => {
        console.log('publish failed:', e.message);
    });
    return data;
});

Then, change something in a score (e.g. Publish/Unpublish) and verify that the /scoring/scores/update message is printed on the console.

Be sure to test shutting down and restarting MHub server, to verify that it reconnects automatically, and the publish/subscribe still works after that.

coveralls commented 6 years ago

Coverage Status

Changes Unknown when pulling 2feead9e1832c1349cf19def83326bff0d5e08ec on mhub into on master.

kmeesters commented 6 years ago

Tested and verified, on Windows 10, Chrome/Firefox, Node 8.6.0, NPM 5.3.0. Mserver 0.9.1. Made the modifications to the localserver.js and messages indeed got send to MHub on publish/unpublish.