Lint infodisplay code too

This commit is contained in:
Henri Bergius 2017-11-28 22:30:37 +01:00
parent 03aed11262
commit d07e88192b
3 changed files with 43 additions and 40 deletions

View file

@ -10,7 +10,8 @@
"customElements": false, "customElements": false,
"document": false, "document": false,
"fetch": false, "fetch": false,
"Plotly": false "Plotly": false,
"window": false
}, },
"settings": { "settings": {
"import/parser": "babel-eslint" "import/parser": "babel-eslint"

View file

@ -1,57 +1,59 @@
var msgflo = window.infodisplay.msgflo; const { msgflo } = window.infodisplay;
var timeout = null; let timeout = null;
var getRotationUrl = function (urls, current) { function getRotationUrl(urls, current) {
var newUrl = urls[Math.floor(Math.random() * urls.length)]; const newUrl = urls[Math.floor(Math.random() * urls.length)];
if (newUrl === current && urls.length > 1) { if (newUrl === current && urls.length > 1) {
// Flip the coin again // Flip the coin again
return getRotationUrl(urls, current); return getRotationUrl(urls, current);
} }
return newUrl; return newUrl;
}; }
var DisplayParticipant = function (broker, role, defaultUrls, timer) { function DisplayParticipant(broker, role, defaultUrls, timer) {
var urls = defaultUrls; let urls = defaultUrls;
var def = { let participant;
const def = {
component: 'msgflo-browser/infodisplay', component: 'msgflo-browser/infodisplay',
label: 'Browser-based information display', label: 'Browser-based information display',
icon: 'television', icon: 'television',
inports: [ inports: [
{ {
id: 'open', id: 'open',
type: 'string' type: 'string',
},
{
id: 'urls',
type: 'array'
}
],
outports: [
{
id: 'opened',
type: 'string'
}, },
{ {
id: 'urls', id: 'urls',
type: 'array', type: 'array',
hidden: true },
} ],
] outports: [
{
id: 'opened',
type: 'string',
},
{
id: 'urls',
type: 'array',
hidden: true,
},
],
}; };
var process = function (inport, indata, callback) { const process = (inport, indata, callback) => {
var current = document.getElementById('current'); const current = document.getElementById('current');
var next = document.getElementById('next'); const next = document.getElementById('next');
if (inport === 'urls') { if (inport === 'urls') {
// Update URL listing // Update URL listing
urls = indata; urls = indata;
return callback('urls', null, urls); callback('urls', null, urls);
} }
next.onerror = function (err) { next.onerror = (err) => {
next.onload = null; next.onload = null;
next.onerror = null; next.onerror = null;
participant.send('open', getRotationUrl(urls, indata)); participant.send('open', getRotationUrl(urls, indata));
} callback('open', err);
next.onload = function () { };
next.onload = () => {
next.onload = null; next.onload = null;
next.onerror = null; next.onerror = null;
// Cross-fade // Cross-fade
@ -60,31 +62,31 @@ var DisplayParticipant = function (broker, role, defaultUrls, timer) {
if (timeout) { if (timeout) {
clearTimeout(timeout); clearTimeout(timeout);
} }
timeout = setTimeout(function () { timeout = setTimeout(() => {
participant.send('open', getRotationUrl(urls, indata)); participant.send('open', getRotationUrl(urls, indata));
}, timer); }, timer);
return callback('opened', null, next.getAttribute('src')); callback('opened', null, next.getAttribute('src'));
}; };
next.setAttribute('src', indata); next.setAttribute('src', indata);
// Rotate internal URLs list // Rotate internal URLs list
}; };
var client = new msgflo.mqtt.Client(broker, {}); const client = new msgflo.mqtt.Client(broker, {});
var participant = new msgflo.participant.Participant(client, def, process, role); participant = new msgflo.participant.Participant(client, def, process, role);
return participant; return participant;
} }
window.addEventListener('load', function () { window.addEventListener('load', () => {
var params = msgflo.options({ const params = msgflo.options({
broker: 'mqtt://c-beam.cbrp3.c-base.org:1882', broker: 'mqtt://c-beam.cbrp3.c-base.org:1882',
role: 'infodisplay', role: 'infodisplay',
urls: [ urls: [
'http://c-beam.cbrp3.c-base.org/he1display', 'http://c-beam.cbrp3.c-base.org/he1display',
'https://c-base.org' 'https://c-base.org',
], ],
timer: 120000, timer: 120000,
}); });
var p = DisplayParticipant(params.broker, params.role, params.urls, params.timer); const p = DisplayParticipant(params.broker, params.role, params.urls, params.timer);
p.start(function (err) { p.start((err) => {
if (err) { if (err) {
console.error(err); console.error(err);
return; return;

View file

@ -5,7 +5,7 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "webpack", "build": "webpack",
"pretest": "eslint lib/*.js elements/*.js index.js", "pretest": "eslint lib/*.js elements/*.js infodisplay/*.js index.js",
"start": "http-server . -p 3000 -s", "start": "http-server . -p 3000 -s",
"test": "npm run pretest" "test": "npm run pretest"
}, },