mirror of
https://github.com/stagehacks/Cue-View.git
synced 2026-08-15 02:33:38 +00:00
Reduce variable scope pollution with const/let
This commit is contained in:
+19
-19
@@ -8,7 +8,7 @@ const PLUGINS = require('./plugins.js');
|
||||
const VIEW = require('./view.js');
|
||||
const SAVESLOTS = require('./saveSlots.js');
|
||||
|
||||
var devices = {};
|
||||
const devices = {};
|
||||
module.exports.all = devices;
|
||||
|
||||
registerDevice = function (newDevice) {
|
||||
@@ -19,14 +19,14 @@ registerDevice = function (newDevice) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var initElements = document.getElementsByClassName('init');
|
||||
for (var i = 0; i < initElements.length; i++) {
|
||||
const initElements = document.getElementsByClassName('init');
|
||||
for (let i = 0; i < initElements.length; i++) {
|
||||
initElements[i].style.display = 'none';
|
||||
}
|
||||
|
||||
// only register device if it hasn't already been added
|
||||
if (newDevice.addresses.length > 0) {
|
||||
for (var i in devices) {
|
||||
for (let i in devices) {
|
||||
if (
|
||||
devices[i].type == newDevice.type &&
|
||||
JSON.stringify(devices[i].addresses) ==
|
||||
@@ -41,9 +41,9 @@ registerDevice = function (newDevice) {
|
||||
|
||||
// console.log("Registered new "+newDevice.type)
|
||||
|
||||
var id = newDevice.id || uuid();
|
||||
const id = newDevice.id || uuid();
|
||||
devices[id] = {
|
||||
id: id,
|
||||
id,
|
||||
status: 'new',
|
||||
type: newDevice.type,
|
||||
displayName: newDevice.displayName,
|
||||
@@ -70,7 +70,7 @@ registerDevice = function (newDevice) {
|
||||
module.exports.registerDevice = registerDevice;
|
||||
|
||||
initDeviceConnection = function (id) {
|
||||
var device = devices[id];
|
||||
const device = devices[id];
|
||||
|
||||
infoUpdate(device, 'status', 'new');
|
||||
|
||||
@@ -82,8 +82,8 @@ initDeviceConnection = function (id) {
|
||||
device.connection.close();
|
||||
} catch (err) {}
|
||||
|
||||
const type = devices[id].type;
|
||||
var plugins = PLUGINS.all;
|
||||
const { type } = devices[id];
|
||||
const plugins = PLUGINS.all;
|
||||
|
||||
if (plugins[type].connectionType == 'osc') {
|
||||
device.connection = new osc.TCPSocketPort({
|
||||
@@ -159,8 +159,8 @@ initDeviceConnection = function (id) {
|
||||
module.exports.initDeviceConnection = initDeviceConnection;
|
||||
|
||||
module.exports.deleteActive = function () {
|
||||
var device = VIEW.getActiveDevice();
|
||||
var choice = confirm(
|
||||
const device = VIEW.getActiveDevice();
|
||||
const choice = confirm(
|
||||
`Are you sure you want to delete ${device.type} device "${
|
||||
device.displayName || device.defaultName
|
||||
}"?`
|
||||
@@ -176,7 +176,7 @@ module.exports.deleteActive = function () {
|
||||
};
|
||||
|
||||
module.exports.changeActiveType = function (newType) {
|
||||
var device = VIEW.getActiveDevice();
|
||||
const device = VIEW.getActiveDevice();
|
||||
device.type = newType;
|
||||
|
||||
initDeviceConnection(device.id);
|
||||
@@ -185,7 +185,7 @@ module.exports.changeActiveType = function (newType) {
|
||||
};
|
||||
|
||||
module.exports.changeActiveIP = function (newIP) {
|
||||
var device = VIEW.getActiveDevice();
|
||||
const device = VIEW.getActiveDevice();
|
||||
device.addresses[0] = newIP;
|
||||
initDeviceConnection(device.id);
|
||||
VIEW.draw(device);
|
||||
@@ -193,7 +193,7 @@ module.exports.changeActiveIP = function (newIP) {
|
||||
};
|
||||
|
||||
module.exports.changeActivePort = function (newPort) {
|
||||
var device = VIEW.getActiveDevice();
|
||||
const device = VIEW.getActiveDevice();
|
||||
device.port = newPort;
|
||||
|
||||
initDeviceConnection(device.id);
|
||||
@@ -202,14 +202,14 @@ module.exports.changeActivePort = function (newPort) {
|
||||
};
|
||||
|
||||
module.exports.changeActiveName = function (newName) {
|
||||
var device = VIEW.getActiveDevice();
|
||||
const device = VIEW.getActiveDevice();
|
||||
device.displayName = newName;
|
||||
infoUpdate(device, 'displayName', newName);
|
||||
VIEW.draw(device);
|
||||
SAVESLOTS.saveAll();
|
||||
};
|
||||
module.exports.changeActivePinIndex = function (newPin) {
|
||||
var device = VIEW.getActiveDevice();
|
||||
const device = VIEW.getActiveDevice();
|
||||
device.pinIndex = newPin;
|
||||
VIEW.draw(device);
|
||||
SAVESLOTS.saveAll();
|
||||
@@ -219,7 +219,7 @@ module.exports.changePinIndex = function (device, newPin) {
|
||||
// SAVESLOTS.saveAll();
|
||||
};
|
||||
module.exports.refreshActive = function () {
|
||||
var device = VIEW.getActiveDevice();
|
||||
const device = VIEW.getActiveDevice();
|
||||
if (device == undefined) {
|
||||
return true;
|
||||
}
|
||||
@@ -239,8 +239,8 @@ module.exports.infoUpdate = infoUpdate;
|
||||
|
||||
setInterval(heartbeat, 100);
|
||||
function heartbeat() {
|
||||
for (var i in devices) {
|
||||
var device = devices[i];
|
||||
for (let i in devices) {
|
||||
const device = devices[i];
|
||||
if (Date.now() >= device.lastHeartbeat + device.heartbeatInterval) {
|
||||
if (device.status == 'broken') {
|
||||
initDeviceConnection(i);
|
||||
|
||||
+3
-3
@@ -2,15 +2,15 @@ const fs = require('fs');
|
||||
const DEVICE = require('./device.js');
|
||||
const VIEW = require('./view.js');
|
||||
|
||||
var allPlugins = {};
|
||||
const allPlugins = {};
|
||||
module.exports.all = allPlugins;
|
||||
|
||||
module.exports.init = function (callback) {
|
||||
console.log(`Loading plugin files... ${__dirname}/../plugins`);
|
||||
|
||||
fs.readdir(`${__dirname}/../plugins`, (err, files) => {
|
||||
for (var i in files) {
|
||||
var plugin = files[i];
|
||||
for (let i in files) {
|
||||
const plugin = files[i];
|
||||
|
||||
if (plugin[0] != '.') {
|
||||
console.log(`${i} ${plugin}`);
|
||||
|
||||
+12
-12
@@ -1,16 +1,16 @@
|
||||
const VIEW = require('./view.js');
|
||||
const DEVICE = require('./device.js');
|
||||
|
||||
var activeSlot = false;
|
||||
var savedSlots = [[], [], [], []];
|
||||
var savedDevices = [];
|
||||
let activeSlot = false;
|
||||
let savedSlots = [[], [], [], []];
|
||||
let savedDevices = [];
|
||||
|
||||
var storedSlots = localStorage.getItem('savedSlots');
|
||||
const storedSlots = localStorage.getItem('savedSlots');
|
||||
if (storedSlots) {
|
||||
savedSlots = JSON.parse(storedSlots);
|
||||
}
|
||||
|
||||
var storedDevices = localStorage.getItem('savedDevices');
|
||||
const storedDevices = localStorage.getItem('savedDevices');
|
||||
if (storedDevices) {
|
||||
savedDevices = JSON.parse(storedDevices);
|
||||
}
|
||||
@@ -25,9 +25,9 @@ loadSlot = function (slotIndex) {
|
||||
VIEW.resetPinned();
|
||||
|
||||
for (var d in savedSlots[slotIndex]) {
|
||||
var savedDevice = savedSlots[slotIndex][d];
|
||||
const savedDevice = savedSlots[slotIndex][d];
|
||||
for (var d in DEVICE.all) {
|
||||
var device = DEVICE.all[d];
|
||||
const device = DEVICE.all[d];
|
||||
// if(device.addresses[0] == savedDevice.addresses[0] && device.type == savedDevice.type){
|
||||
if (device.id == savedDevice.id) {
|
||||
VIEW.pinDevice(device);
|
||||
@@ -49,7 +49,7 @@ module.exports.loadDevices = function () {
|
||||
console.log(`Loading ${savedDevices.length} saved devices...`);
|
||||
console.log(savedDevices);
|
||||
|
||||
for (var i = 0; i < savedDevices.length; i++) {
|
||||
for (let i = 0; i < savedDevices.length; i++) {
|
||||
DEVICE.registerDevice({
|
||||
type: savedDevices[i].type,
|
||||
displayName: savedDevices[i].displayName,
|
||||
@@ -63,10 +63,10 @@ module.exports.loadDevices = function () {
|
||||
|
||||
module.exports.saveAll = function () {
|
||||
console.log('Saving...');
|
||||
var currentPins = VIEW.getPinnedDevices();
|
||||
const currentPins = VIEW.getPinnedDevices();
|
||||
|
||||
savedSlots[activeSlot] = [];
|
||||
for (var i = 0; i < currentPins.length; i++) {
|
||||
for (let i = 0; i < currentPins.length; i++) {
|
||||
savedSlots[activeSlot][i] = {
|
||||
addresses: currentPins[i].addresses,
|
||||
type: currentPins[i].type,
|
||||
@@ -96,9 +96,9 @@ module.exports.saveAll = function () {
|
||||
};
|
||||
|
||||
module.exports.deleteFromSlots = function (device) {
|
||||
for (var i = 1; i <= 3; i++) {
|
||||
for (let i = 1; i <= 3; i++) {
|
||||
console.log(savedSlots);
|
||||
for (var j = 0; j < savedSlots[i].length; j++) {
|
||||
for (let j = 0; j < savedSlots[i].length; j++) {
|
||||
if (savedSlots[i][j].id == device.id) {
|
||||
delete savedSlots[i][j];
|
||||
}
|
||||
|
||||
+36
-36
@@ -10,8 +10,8 @@ const DEVICE = require('./device.js');
|
||||
// const SEARCH = require('./search.js');
|
||||
const PLUGINS = require('./plugins.js');
|
||||
|
||||
var searching = false;
|
||||
var allServers = false;
|
||||
let searching = false;
|
||||
let allServers = false;
|
||||
|
||||
searchAll = function () {
|
||||
if (searching) {
|
||||
@@ -22,7 +22,7 @@ searchAll = function () {
|
||||
document.getElementById('search-button').style.opacity = 0.2;
|
||||
// console.clear();
|
||||
|
||||
for (var i in DEVICE.all) {
|
||||
for (let i in DEVICE.all) {
|
||||
DEVICE.infoUpdate(DEVICE.all[i], 'status', 'refresh');
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ searchAll = function () {
|
||||
|
||||
// findOnlineDevices();
|
||||
allServers = getServers();
|
||||
var TCPFlag = true;
|
||||
let TCPFlag = true;
|
||||
if (allServers.length > 2046) {
|
||||
alert(
|
||||
'Unable to search for TCP devices - subnet too large!\n\nCue View requires subnet 255.255.248.0 (/21) or smaller.'
|
||||
@@ -40,8 +40,8 @@ searchAll = function () {
|
||||
|
||||
console.log(PLUGINS);
|
||||
|
||||
for (var p in PLUGINS.all) {
|
||||
var plugin = PLUGINS.all[p];
|
||||
for (let p in PLUGINS.all) {
|
||||
const plugin = PLUGINS.all[p];
|
||||
console.log(p);
|
||||
try {
|
||||
switch (plugin.searchOptions.type) {
|
||||
@@ -70,7 +70,7 @@ searchAll = function () {
|
||||
searching = false;
|
||||
document.getElementById('search-button').style.opacity = '';
|
||||
|
||||
for (var i = 0; i < searchSockets.length; i++) {
|
||||
for (let i = 0; i < searchSockets.length; i++) {
|
||||
try {
|
||||
searchSockets[i].close();
|
||||
} catch (err) {}
|
||||
@@ -94,8 +94,8 @@ newSearchBonjour = function (pluginType, plugin) {
|
||||
bonjour.find({ type: plugin.searchOptions.bonjourName }, (e) => {
|
||||
console.log(pluginType);
|
||||
|
||||
var validAddresses = [];
|
||||
for (var i in e.addresses) {
|
||||
const validAddresses = [];
|
||||
for (let i in e.addresses) {
|
||||
if (e.addresses[i].indexOf(':') == -1) {
|
||||
validAddresses.push(e.addresses[i]);
|
||||
}
|
||||
@@ -135,13 +135,13 @@ newSearchBonjour = function (pluginType, plugin) {
|
||||
// |_| \_____|_|
|
||||
|
||||
newSearchTCP = function (pluginType, plugin) {
|
||||
for (var i = 0; i < allServers.length; i++) {
|
||||
for (let i = 0; i < allServers.length; i++) {
|
||||
TCPtest(allServers[i], pluginType, plugin);
|
||||
}
|
||||
};
|
||||
|
||||
TCPtest = function (ip, pluginType, plugin) {
|
||||
var client = net.createConnection(plugin.searchOptions.testPort, ip, () => {
|
||||
const client = net.createConnection(plugin.searchOptions.testPort, ip, () => {
|
||||
client.write(plugin.searchOptions.searchBuffer);
|
||||
// DEVICE.registerDevice({
|
||||
// type: pluginType,
|
||||
@@ -168,17 +168,17 @@ TCPtest = function (ip, pluginType, plugin) {
|
||||
|
||||
// from local-devices library
|
||||
function getServers() {
|
||||
var interfaces = os.networkInterfaces();
|
||||
var result = [];
|
||||
const interfaces = os.networkInterfaces();
|
||||
const result = [];
|
||||
|
||||
for (var key in interfaces) {
|
||||
var addresses = interfaces[key];
|
||||
for (var i = addresses.length; i--; ) {
|
||||
var address = addresses[i];
|
||||
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) {
|
||||
var subnet = ip.subnet(address.address, address.netmask);
|
||||
var current = ip.toLong(subnet.firstAddress);
|
||||
var last = ip.toLong(subnet.lastAddress) - 1;
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -188,11 +188,11 @@ function getServers() {
|
||||
}
|
||||
|
||||
findOnlineDevices = function () {
|
||||
var allInterfaces = os.networkInterfaces();
|
||||
var validInterfaces = [];
|
||||
for (var i in allInterfaces) {
|
||||
for (var j = 0; j < allInterfaces[i].length; j++) {
|
||||
var iface = allInterfaces[i][j];
|
||||
const allInterfaces = os.networkInterfaces();
|
||||
const validInterfaces = [];
|
||||
for (let i in allInterfaces) {
|
||||
for (let j = 0; j < allInterfaces[i].length; j++) {
|
||||
const iface = allInterfaces[i][j];
|
||||
|
||||
if (
|
||||
iface.family == 'IPv4' &&
|
||||
@@ -204,15 +204,15 @@ findOnlineDevices = function () {
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < validInterfaces.length; i++) {
|
||||
var block = new Netmask(validInterfaces[i].cidr);
|
||||
var f = block.first.split('.');
|
||||
var l = block.last.split('.');
|
||||
var cur = [f[0], f[1], f[2], f[3]];
|
||||
for (let i = 0; i < validInterfaces.length; i++) {
|
||||
const block = new Netmask(validInterfaces[i].cidr);
|
||||
const f = block.first.split('.');
|
||||
const l = block.last.split('.');
|
||||
const cur = [f[0], f[1], f[2], f[3]];
|
||||
|
||||
for (var j = Number(f[2]); j <= Number(l[2]); j++) {
|
||||
for (let j = Number(f[2]); j <= Number(l[2]); j++) {
|
||||
cur[2] = j;
|
||||
for (var k = Number(f[3]); k < Number(l[3]); k++) {
|
||||
for (let k = Number(f[3]); k < Number(l[3]); k++) {
|
||||
cur[3] = k;
|
||||
allIPs.push(`${cur[0]}.${cur[1]}.${cur[2]}.${cur[3]}`);
|
||||
}
|
||||
@@ -284,13 +284,13 @@ findOnlineDevices = function () {
|
||||
|
||||
const pjLinkMessage = Buffer.from([0x25, 0x32, 0x53, 0x52, 0x43, 0x48, 0x0d]);
|
||||
const xAirMessage = Buffer.from([0x2f, 0x78, 0x69, 0x6e, 0x66, 0x6f]);
|
||||
var serverUDP = dgram.createSocket('udp4');
|
||||
var serverUDP2 = dgram.createSocket('udp4');
|
||||
const serverUDP = dgram.createSocket('udp4');
|
||||
const serverUDP2 = dgram.createSocket('udp4');
|
||||
|
||||
var searchSockets = [];
|
||||
const searchSockets = [];
|
||||
|
||||
newSearchUDP = function (pluginType, plugin) {
|
||||
var i = searchSockets.push(dgram.createSocket('udp4')) - 1;
|
||||
const i = searchSockets.push(dgram.createSocket('udp4')) - 1;
|
||||
searchSockets[i].bind(plugin.searchOptions.listenPort, () => {
|
||||
searchSockets[i].send(
|
||||
plugin.searchOptions.searchBuffer,
|
||||
|
||||
+4
-4
@@ -3,7 +3,7 @@ const DEVICE = require('./device.js');
|
||||
const PLUGINS = require('./plugins.js');
|
||||
// const _ = require('lodash/function');
|
||||
|
||||
var pinnedDevices = [];
|
||||
const pinnedDevices = [];
|
||||
module.exports.pinnedDevices = pinnedDevices;
|
||||
let activeDevice = false;
|
||||
|
||||
@@ -14,8 +14,8 @@ module.exports.init = function () {
|
||||
drawDeviceInterface = function (id) {
|
||||
// console.log("DRAW")
|
||||
|
||||
var $deviceDrawArea = document.getElementById(`device-${id}-draw-area`);
|
||||
var $devicePinned = document.getElementById(`device-${id}-pinned`);
|
||||
const $deviceDrawArea = document.getElementById(`device-${id}-draw-area`);
|
||||
const $devicePinned = document.getElementById(`device-${id}-pinned`);
|
||||
|
||||
if ($deviceDrawArea == null) {
|
||||
return true;
|
||||
@@ -23,7 +23,7 @@ drawDeviceInterface = function (id) {
|
||||
|
||||
d = DEVICE.all[id];
|
||||
|
||||
var str = '<html><head>';
|
||||
let str = '<html><head>';
|
||||
if (d.status == 'ok') {
|
||||
str +=
|
||||
"<link href='./plugins/" +
|
||||
|
||||
Reference in New Issue
Block a user