bugfix basically everything about heartbeats

This commit is contained in:
sparks-alec
2023-01-08 23:11:07 -05:00
parent 185b360d8a
commit ababf93e2b
3 changed files with 26 additions and 14 deletions
+7 -1
View File
@@ -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);
+2 -10
View File
@@ -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`);
}
});