From ababf93e2bca5989b8b1aebfedc1aab6c7aba65b Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Sun, 8 Jan 2023 23:11:07 -0500 Subject: [PATCH] bugfix basically everything about heartbeats --- plugins/qlab/main.js | 20 +++++++++++++++++--- src/device.js | 8 +++++++- src/plugins.js | 12 ++---------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/plugins/qlab/main.js b/plugins/qlab/main.js index 8990841..87ec286 100644 --- a/plugins/qlab/main.js +++ b/plugins/qlab/main.js @@ -7,8 +7,8 @@ exports.config = { connectionType: 'osc', defaultPort: 53000, mayChangePort: true, - heartbeatInterval: 500, - heartbeatTimeout: 5000, + heartbeatInterval: 100, + heartbeatTimeout: 9000, searchOptions: { type: 'Bonjour', bonjourName: 'qlab', @@ -303,7 +303,12 @@ exports.data = function data(_device, oscData) { } } else if (match(oscAddressParts, ['update', 'workspace', '*', 'disconnect'])) { delete device.data.workspaces[oscAddressParts[2]]; + if (Object.keys(device.data.workspaces).length === 0) { + device.data.permission = 'no workspaces'; + } device.draw(); + } else if (match(oscAddressParts, ['reply', 'thump'])) { + // intermittent connection check even if nothing's happening } else { // console.log(address) } @@ -392,7 +397,16 @@ exports.heartbeat = function heartbeat(device) { interval = 1; } - if (heartbeatCount % interval === 0) { + if (heartbeatCount % 20 === 0 && device.data.workspaces && Object.keys(device.data.workspaces).length === 0) { + device.send(`/version`); + device.send('/workspaces'); + } + + if (heartbeatCount % 50 === 0) { + device.send(`/thump`); + } + + if (heartbeatCount % interval === 0 && device.data.workspaces && Object.keys(device.data.workspaces).length > 0) { device.send(`/cue_id/active/preWaitElapsed`); device.send(`/cue_id/active/actionElapsed`); device.send(`/cue_id/active/postWaitElapsed`); diff --git a/src/device.js b/src/device.js index 6fe846b..14406cc 100644 --- a/src/device.js +++ b/src/device.js @@ -44,7 +44,9 @@ function registerDevice(newDevice, discoveryMethod) { pinIndex: false, lastDrawn: 0, lastHeartbeat: 0, + lastMessage: 0, heartbeatInterval: PLUGINS.all[newDevice.type].heartbeatInterval, + heartbeatTimeout: PLUGINS.all[newDevice.type].heartbeatTimeout, draw() { VIEW.draw(this); }, @@ -168,6 +170,7 @@ function initDeviceConnection(id) { device.connection.on('message', (msg, info) => { plugins[type].data(device, msg); + device.lastMessage = Date.now(); infoUpdate(device, 'status', 'ok'); }); }); @@ -185,6 +188,7 @@ function initDeviceConnection(id) { device.connection.on('message', (msg, info) => { plugins[type].data(device, msg); + device.lastMessage = Date.now(); infoUpdate(device, 'status', 'ok'); }); }); @@ -204,7 +208,9 @@ module.exports.deleteActive = function deleteActive() { ); if (choice) { - device.connection.destroy(); + if (device.plugin.connectionType === 'TCPsocket') { + device.connection.destroy(); + } VIEW.removeDeviceFromList(device); delete devices[device.id]; SAVESLOTS.removeDevice(device); diff --git a/src/plugins.js b/src/plugins.js index 1535499..b57166f 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -35,17 +35,9 @@ module.exports.init = function init(callback) { plugin.info = _.template(fs.readFileSync(path.join(pluginDirectoryPath, `/${pluginDir}/info.html`), 'utf8')); - if (plugin.config.heartbeatTimeout) { - plugin.heartbeatTimeout = plugin.config.heartbeatInterval * 1.5; - } else { - plugin.heartbeatTimeout = 10000; - } + plugin.heartbeatTimeout = plugin.config.heartbeatTimeout; + plugin.heartbeatInterval = plugin.config.heartbeatInterval; - if (plugin.config.heartbeatInterval) { - plugin.heartbeatInterval = Math.max(50, plugin.config.heartbeatInterval); - } else { - plugin.heartbeatInterval = 5000; - } console.log(`${pluginDir} loaded`); } });