From ba19f71d67a03871783c0f84b1f11ae5dfa47aa5 Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Sun, 6 Feb 2022 01:29:33 -0500 Subject: [PATCH] change templates to ejs --- src/device.js | 28 ++++++++++++++++++---------- src/plugins.js | 35 ++++++++++++++++++++++------------- src/saveSlots.js | 1 - src/view.js | 46 +++++++++++++++++++--------------------------- 4 files changed, 59 insertions(+), 51 deletions(-) diff --git a/src/device.js b/src/device.js index fe16688..5877235 100644 --- a/src/device.js +++ b/src/device.js @@ -54,13 +54,16 @@ registerDevice = function (newDevice) { lastDrawn: 0, lastHeartbeat: 0, heartbeatInterval: PLUGINS.all[newDevice.type].heartbeatInterval, - draw: debounce( - function () { - VIEW.draw(this); - }, - 30, - { leading: true, trailing: true } - ), + draw: async function(){ + VIEW.draw(this); + }, + update: function(type, data){ + if(this.drawn){ + VIEW.update(this, type, data); + }else{ + this.draw(); + } + } }; VIEW.addDeviceToList(devices[id]); @@ -68,6 +71,7 @@ registerDevice = function (newDevice) { }; module.exports.registerDevice = registerDevice; + initDeviceConnection = function (id) { const device = devices[id]; @@ -101,8 +105,12 @@ initDeviceConnection = function (id) { } }); device.connection.on('message', (message) => { - // log("OSC IN", message.address); - plugins[type].data(device, message); + try{ + plugins[type].data(device, message); + }catch(err){ + console.error("Error with plugin 'data' function"); + console.error(err) + } device.lastMessage = Date.now(); }); device.send = function (address, args) { @@ -242,7 +250,7 @@ function heartbeat() { if (Date.now() >= device.lastHeartbeat + device.heartbeatInterval) { if (device.status == 'broken') { initDeviceConnection(i); - } else if (Date.now() - device.lastMessage > 10000) { + } else if (Date.now() - device.lastMessage > device.heartbeatTimeout) { infoUpdate(device, 'status', 'broken'); } else { if (device.port != undefined && device.addresses.length > 0) { diff --git a/src/plugins.js b/src/plugins.js index 662e7c8..69131a1 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -1,7 +1,7 @@ const fs = require('fs'); -const ejs = require('ejs'); const DEVICE = require('./device.js'); const VIEW = require('./view.js'); +const _ = require('lodash'); const allPlugins = {}; module.exports.all = allPlugins; @@ -13,32 +13,41 @@ module.exports.init = function (callback) { for (let i in files) { const plugin = files[i]; - if (plugin[0] != '.') { + if (plugin[0] != '.' && plugin!= "qlab-old") { + console.log(`${i} ${plugin}`); - allPlugins[ - plugin - ] = require(`${__dirname}/../plugins/${plugin}/${plugin}.js`); + allPlugins[plugin] = require(`${__dirname}/../plugins/${plugin}/${plugin}.js`); - allPlugins[plugin].deviceInfoUpdate = function (device, param, value) { + let p = allPlugins[plugin]; + + p.deviceInfoUpdate = function (device, param, value) { DEVICE.infoUpdate(device, param, value); }; - allPlugins[plugin].draw = function (device) { + p.draw = function (device) { VIEW.draw(device); }; - allPlugins[plugin].template = ejs.compile( + p.template = _.template( fs.readFileSync( `${__dirname}/../plugins/${plugin}/${plugin}.html`, 'utf8' ) ); - if ( - allPlugins[plugin].heartbeatInterval == undefined || - allPlugins[plugin].heartbeatInterval < 50 - ) { - allPlugins[plugin].heartbeatInterval = 5000; + + + if (p.heartbeatTimeout == undefined || p.heartbeatTimeout < 50) { + if(p.heartbeatInterval){ + p.heartbeatTimeout = p.heartbeatInterval*1.5; + }else{ + p.heartbeatTimeout = 10000; + } } + + if (p.heartbeatInterval == undefined || p.heartbeatInterval < 50) { + p.heartbeatInterval = 5000; + } + } } callback(); diff --git a/src/saveSlots.js b/src/saveSlots.js index 2037652..2bf1337 100644 --- a/src/saveSlots.js +++ b/src/saveSlots.js @@ -47,7 +47,6 @@ module.exports.loadSlot = loadSlot; module.exports.loadDevices = function () { console.log(`Loading ${savedDevices.length} saved devices...`); - console.log(savedDevices); for (let i = 0; i < savedDevices.length; i++) { DEVICE.registerDevice({ diff --git a/src/view.js b/src/view.js index 5d3e13d..eca3efa 100644 --- a/src/view.js +++ b/src/view.js @@ -6,14 +6,12 @@ const PLUGINS = require('./plugins.js'); const pinnedDevices = []; module.exports.pinnedDevices = pinnedDevices; let activeDevice = false; -let drawCount = 0; module.exports.init = function () { populatePluginLists(); }; drawDeviceFrame = function (id) { - // console.log("DRAW") const $deviceDrawArea = document.getElementById(`device-${id}-draw-area`); const $devicePinned = document.getElementById(`device-${id}-pinned`); @@ -25,14 +23,7 @@ drawDeviceFrame = function (id) { d = DEVICE.all[id]; let str = ''; - if (d.status == 'ok') { - str += - ""; - } + str += ""; // scrollbar styles are inline to prevent the styles flickering in str += '