Define variables before use

This commit is contained in:
Sam Schloegel
2022-01-05 21:27:38 -05:00
parent 9c16c9c220
commit 0e97bd6abc
7 changed files with 172 additions and 173 deletions
+1 -1
View File
@@ -237,7 +237,6 @@ infoUpdate = function (device, param, value) {
};
module.exports.infoUpdate = infoUpdate;
setInterval(heartbeat, 100);
function heartbeat() {
for (let i in devices) {
const device = devices[i];
@@ -257,3 +256,4 @@ function heartbeat() {
}
}
}
setInterval(heartbeat, 100);
+23 -23
View File
@@ -13,6 +13,29 @@ const PLUGINS = require('./plugins.js');
let searching = false;
let allServers = false;
// from local-devices library
function getServers() {
const interfaces = os.networkInterfaces();
const result = [];
for (const key in interfaces) {
const addresses = interfaces[key];
for (let i = addresses.length; i--; ) {
const address = addresses[i];
if (address.family === 'IPv4' && !address.internal) {
const subnet = ip.subnet(address.address, address.netmask);
let current = ip.toLong(subnet.firstAddress);
const last = ip.toLong(subnet.lastAddress) - 1;
while (current++ < last) result.push(ip.fromLong(current));
}
}
}
return result;
}
const searchSockets = [];
searchAll = function () {
if (searching) {
return true;
@@ -166,27 +189,6 @@ TCPtest = function (ip, pluginType, plugin) {
});
};
// from local-devices library
function getServers() {
const interfaces = os.networkInterfaces();
const result = [];
for (const key in interfaces) {
const addresses = interfaces[key];
for (let i = addresses.length; i--; ) {
const address = addresses[i];
if (address.family === 'IPv4' && !address.internal) {
const subnet = ip.subnet(address.address, address.netmask);
let current = ip.toLong(subnet.firstAddress);
const last = ip.toLong(subnet.lastAddress) - 1;
while (current++ < last) result.push(ip.fromLong(current));
}
}
}
return result;
}
findOnlineDevices = function () {
const allInterfaces = os.networkInterfaces();
const validInterfaces = [];
@@ -287,8 +289,6 @@ const xAirMessage = Buffer.from([0x2f, 0x78, 0x69, 0x6e, 0x66, 0x6f]);
const serverUDP = dgram.createSocket('udp4');
const serverUDP2 = dgram.createSocket('udp4');
const searchSockets = [];
newSearchUDP = function (pluginType, plugin) {
const i = searchSockets.push(dgram.createSocket('udp4')) - 1;
searchSockets[i].bind(plugin.searchOptions.listenPort, () => {