Reduce variable scope pollution with const/let

This commit is contained in:
Sam Schloegel
2022-01-05 21:20:35 -05:00
parent 35340b86db
commit 9c16c9c220
13 changed files with 130 additions and 130 deletions
+8 -8
View File
@@ -22,8 +22,8 @@ exports.ready = function (device) {
};
exports.data = function (device, osc) {
var address = osc.address;
var p = osc.address.split('/');
const address = osc.address;
const p = osc.address.split('/');
p.shift();
if (p[1] == 'out' && p[2] == 'show' && p[3] == 'name') {
@@ -31,7 +31,7 @@ exports.data = function (device, osc) {
device.data.cuelists = {};
this.deviceInfoUpdate(device, 'defaultName', osc.args[0]);
} else if (osc.address == '/eos/out/get/cuelist/count') {
for (var i = 0; i < osc.args[0]; i++) {
for (let i = 0; i < osc.args[0]; i++) {
device.send(`/eos/get/cuelist/index/${i}`);
}
} else if (
@@ -48,7 +48,7 @@ exports.data = function (device, osc) {
p[3] == 'cue' &&
p[5] == 'count'
) {
for (var i = 0; i < osc.args[0]; i++) {
for (let i = 0; i < osc.args[0]; i++) {
device.send(`'/eos/get/cue/${p[4]}/index/${i}`);
}
} else if (
@@ -119,10 +119,10 @@ exports.data = function (device, osc) {
device.data.activeCue = p[5];
device.draw();
} else if (p[1] == 'out' && p[2] == 'notify' && p[3] == 'cue') {
var cueList = p[4];
var listIndex = p[6];
var listCount = p[7];
var cueNumber = osc.args[1];
const cueList = p[4];
const listIndex = p[6];
const listCount = p[7];
const cueNumber = osc.args[1];
device.send(`/eos/get/cue/${cueList}/${cueNumber}`);
// console.log("SENT /eos/get/cue/"+cueList+"/"+cueNumber);
+5 -5
View File
@@ -1,3 +1,5 @@
const md5 = require('md5');
exports.defaultName = 'PJLink Projector';
exports.connectionType = 'TCPsocket';
exports.heartbeatInterval = 5000;
@@ -16,13 +18,11 @@ exports.ready = function (device) {
// Power status query
// device.send("%1POWR ?\r");
};
var password = false;
let password = false;
exports.data = function (device, message) {
this.deviceInfoUpdate(device, 'status', 'ok');
var msg = message.toString();
const md5 = require('md5');
const msg = message.toString();
if (msg.substring(0, 8) == 'PJLINK 1') {
password = md5(`${msg.substring(9, 17)}JBMIAProjectorLink`);
@@ -63,7 +63,7 @@ exports.data = function (device, message) {
};
function processPJLink(device, str, that) {
var arr = str.split('%');
const arr = str.split('%');
for (var key in arr) {
var split = arr[key].split('=');
var key = split[0];
+16 -16
View File
@@ -10,8 +10,8 @@ exports.ready = function (device) {
};
exports.data = function (device, osc) {
var address = osc.address;
var p = osc.address.split('/');
const address = osc.address;
const p = osc.address.split('/');
p.shift();
// console.log(address)
@@ -19,7 +19,7 @@ exports.data = function (device, osc) {
if (osc.address == '/reply/workspaces') {
const d = JSON.parse(osc.args[0]).data;
device.data.workspaces = {};
for (var i = 0; i < d.length; i++) {
for (let i = 0; i < d.length; i++) {
device.data.workspaces[d[i].uniqueID] = {
displayName: d[i].displayName,
selectionIsPlayhead: true,
@@ -33,14 +33,14 @@ exports.data = function (device, osc) {
device.send(`/workspace/${d[i].uniqueID}/selectionIsPlayhead`);
}
} else if (p[1] == 'workspace' && p[3] == 'cueLists') {
var workspace = p[2];
var d = JSON.parse(osc.args[0]).data;
const workspace = p[2];
const d = JSON.parse(osc.args[0]).data;
device.data.workspaces[workspace].cueLists = {};
device.data.workspaces[workspace].allCues = {};
device.data.workspaces[workspace].allCuesOrdered = [];
device.data.lastCueInGroup = {};
for (var i in d) {
for (let i in d) {
device.data.workspaces[workspace].cueLists[d[i].uniqueID] = d[i];
device.data.workspaces[workspace].cueLists[d[i].uniqueID].cues =
d[i].cues;
@@ -48,11 +48,11 @@ exports.data = function (device, osc) {
getMoreCueInfo(d[i], []);
function getMoreCueInfo(group, groups_arg) {
var groups = JSON.parse(JSON.stringify(groups_arg));
const groups = JSON.parse(JSON.stringify(groups_arg));
groups.push(group.uniqueID);
for (var cueIndex in group.cues) {
var cue = group.cues[cueIndex];
for (let cueIndex in group.cues) {
const cue = group.cues[cueIndex];
// console.log(cue)
device.data.lastCueInGroup[group.uniqueID] = cue;
@@ -99,19 +99,19 @@ exports.data = function (device, osc) {
// response to /cue/playbackPosition/uniqueID
device.data.playbackPosition = JSON.parse(osc.args[0]).data;
} else if (p[3] == 'mode') {
var cueID = p[2];
var mode = JSON.parse(osc.args[0]).data;
var workspaceID = JSON.parse(osc.args[0]).workspace_id;
const cueID = p[2];
const mode = JSON.parse(osc.args[0]).data;
const workspaceID = JSON.parse(osc.args[0]).workspace_id;
device.data.workspaces[workspaceID].allCues[cueID].mode = mode;
} else if (p[3] == 'valuesForKeys') {
this.deviceInfoUpdate(device, 'status', 'ok');
var d = JSON.parse(osc.args[0]);
const d = JSON.parse(osc.args[0]);
var cueID = p[2];
var workspace = d.workspace_id;
var cueList = d.data.parent;
const cueID = p[2];
const workspace = d.workspace_id;
const cueList = d.data.parent;
device.data.workspaces[workspace].allCues[cueID].mode = d.data.mode;
device.data.workspaces[workspace].allCues[cueID].preWait = d.data.preWait;
+3 -3
View File
@@ -16,15 +16,15 @@ exports.ready = function (device) {
};
exports.data = function (device, message) {
var msg = message.toString();
const msg = message.toString();
if (msg.substring(0, 5) == 'Ready') {
device.send('getStatus\n');
}
if (msg.substring(0, 5) == 'Reply') {
var arr = msg.split(' ');
const arr = msg.split(' ');
device.data.showName = '';
var i = 0;
let i = 0;
while (arr[i][arr[i].length - 1] != '"') {
i++;
device.data.showName += `${arr[i]} `;
+11 -11
View File
@@ -33,7 +33,7 @@ exports.ready = function (device) {
exports.data = function (device, buf) {
this.deviceInfoUpdate(device, 'status', 'ok');
var msg = buf.toString().split('\u0000\u0000');
const msg = buf.toString().split('\u0000\u0000');
if (msg[0] == '/xinfo') {
this.deviceInfoUpdate(device, 'defaultName', msg[4]);
@@ -45,7 +45,7 @@ exports.data = function (device, buf) {
device.send(Buffer.from('/lr/mix/fader\u0000\u0000\u0000\u0000'));
device.send(Buffer.from('/lr/mix/on\u0000\u0000\u0000\u0000'));
for (var i = 0; i <= 32; i++) {
for (let i = 0; i <= 32; i++) {
device.send(
Buffer.from(
`/ch/${i
@@ -58,8 +58,8 @@ exports.data = function (device, buf) {
} else if (msg[0] == '/meters/0') {
// console.log(msg)
} else if (msg[0].indexOf('/mix/fader') >= 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
if (addr[0] == 'ch') {
device.data.channelFaders[channel - 1] = buf.readFloatBE(24);
@@ -75,8 +75,8 @@ exports.data = function (device, buf) {
device.draw();
} else if (msg[0].indexOf('/mix/on') >= 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
if (addr[0] == 'ch') {
device.data.channelMutes[channel - 1] = buf[23];
@@ -88,16 +88,16 @@ exports.data = function (device, buf) {
Buffer.from(`/ch/${addr[1]}/mix/fader\u0000\u0000\u0000\u0000`)
);
} else if (msg[0].indexOf('/config/name') > 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
device.data.channelNames[channel - 1] = msg[2];
device.draw();
device.send(
Buffer.from(`/ch/${addr[1]}/config/color\u0000\u0000\u0000\u0000`)
);
} else if (msg[0].indexOf('/config/color') > 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
device.data.channelColors[channel - 1] = buf.readInt8(27);
device.draw();
device.send(Buffer.from(`/ch/${addr[1]}/mix/on\u0000\u0000\u0000\u0000`));
@@ -112,7 +112,7 @@ exports.heartbeat = function (device) {
};
function parseAddress(msg) {
var addr = msg.split('/');
const addr = msg.split('/');
addr.shift();
return addr;
}
+11 -11
View File
@@ -33,7 +33,7 @@ exports.ready = function (device) {
exports.data = function (device, buf) {
this.deviceInfoUpdate(device, 'status', 'ok');
var msg = buf.toString().split('\u0000');
const msg = buf.toString().split('\u0000');
if (msg[0] == '/xinfo') {
if (msg[7].length > 0) {
@@ -50,7 +50,7 @@ exports.data = function (device, buf) {
device.send(Buffer.from('/lr/mix/fader\u0000\u0000\u0000\u0000'));
device.send(Buffer.from('/lr/mix/on\u0000\u0000\u0000\u0000'));
for (var i = 0; i <= 32; i++) {
for (let i = 0; i <= 32; i++) {
device.send(
Buffer.from(
`/ch/${i
@@ -63,8 +63,8 @@ exports.data = function (device, buf) {
} else if (msg[0] == '/meters/0') {
// console.log(msg)
} else if (msg[0].indexOf('/mix/fader') >= 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
if (addr[0] == 'ch') {
device.data.channelFaders[channel - 1] = buf.readFloatBE(24);
@@ -80,8 +80,8 @@ exports.data = function (device, buf) {
device.draw();
} else if (msg[0].indexOf('/mix/on') >= 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
if (addr[0] == 'ch') {
device.data.channelMutes[channel - 1] = buf[23];
@@ -93,16 +93,16 @@ exports.data = function (device, buf) {
Buffer.from(`/ch/${addr[1]}/mix/fader\u0000\u0000\u0000\u0000`)
);
} else if (msg[0].indexOf('/config/name') > 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
device.data.channelNames[channel - 1] = msg[4];
device.draw();
device.send(
Buffer.from(`/ch/${addr[1]}/config/color\u0000\u0000\u0000\u0000`)
);
} else if (msg[0].indexOf('/config/color') > 0) {
var addr = parseAddress(msg[0]);
var channel = Number(addr[1]);
const addr = parseAddress(msg[0]);
const channel = Number(addr[1]);
device.data.channelColors[channel - 1] = buf.readInt8(27);
device.draw();
device.send(Buffer.from(`/ch/${addr[1]}/mix/on\u0000\u0000\u0000\u0000`));
@@ -117,7 +117,7 @@ exports.heartbeat = function (device) {
};
function parseAddress(msg) {
var addr = msg.split('/');
const addr = msg.split('/');
addr.shift();
return addr;
}