From 5e21544a819fad58bb3d0e53b0677e5af6211e41 Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Sat, 10 Dec 2022 06:53:56 -0500 Subject: [PATCH] new universal plugin configuration object --- plugins/artnet/main.js | 24 +++++++++++++----------- plugins/eos/main.js | 31 +++++++++++++++++-------------- plugins/pjlink/main.js | 31 +++++++++++++++++-------------- plugins/qlab/main.js | 31 ++++++++++++++++++++++--------- plugins/sacn/main.js | 29 ++++++++++++++++------------- plugins/watchout/main.js | 27 +++++++++++++++------------ plugins/x32/main.js | 29 ++++++++++++++++------------- plugins/xair/main.js | 29 ++++++++++++++++------------- src/device.js | 18 +++++++++++++----- src/plugins.js | 30 +++++++++++++++++++++++------- src/search.js | 10 +++++----- src/view.js | 33 +++++++++++++++++++++++++++++++-- 12 files changed, 204 insertions(+), 118 deletions(-) diff --git a/plugins/artnet/main.js b/plugins/artnet/main.js index eded517..e897d7a 100644 --- a/plugins/artnet/main.js +++ b/plugins/artnet/main.js @@ -1,16 +1,18 @@ const _ = require('lodash'); -exports.defaultName = "Art-Net"; -exports.connectionType = 'UDPsocket'; -exports.heartbeatInterval = 10000; - -exports.searchOptions = { - type: 'UDPsocket', - searchBuffer: Buffer.from([0x00]), - devicePort: 6454, - listenPort: 6454, - validateResponse (msg, info, devices) { - return msg.toString('utf8', 0, 7) === "Art-Net"; +exports.config = { + defaultName: "Art-Net", + connectionType: "UDPsocket", + heartbeatInterval: 10000, + searchOptions: { + type: 'UDPsocket', + searchBuffer: Buffer.from([0x00]), + devicePort: 6454, + listenPort: 6454, + mayChangePort: false, + validateResponse (msg, info, devices) { + return msg.toString('utf8', 0, 7) === "Art-Net"; + } } }; diff --git a/plugins/eos/main.js b/plugins/eos/main.js index 67877e6..e9a9f64 100644 --- a/plugins/eos/main.js +++ b/plugins/eos/main.js @@ -3,20 +3,23 @@ const fs = require('fs'); const path = require('path'); const Cue = require('./cue'); -exports.defaultName = 'ETC Eos'; -exports.connectionType = 'osc'; -exports.searchOptions = { - type: 'TCPport', - searchBuffer: Buffer.from( - '\xc0/eos/ping\x00\x00\x2c\x00\x00\x00\xc0', - 'ascii' - ), - testPort: 3032, - validateResponse(msg, info) { - return msg.toString().indexOf('/eos/out'); - }, -}; -exports.defaultPort = 3032; +exports.config = { + defaultName: "ETC Eos", + connectionType: "osc", + defaultPort: 3032, + mayChangePort: false, + searchOptions: { + type: 'TCPport', + searchBuffer: Buffer.from( + '\xc0/eos/ping\x00\x00\x2c\x00\x00\x00\xc0', + 'ascii' + ), + testPort: 3032, + validateResponse(msg, info) { + return msg.toString().indexOf('/eos/out'); + } + } +} exports.ready = function ready(_device) { const device = _device; diff --git a/plugins/pjlink/main.js b/plugins/pjlink/main.js index 1d1f4b4..69f8406 100644 --- a/plugins/pjlink/main.js +++ b/plugins/pjlink/main.js @@ -1,19 +1,22 @@ const md5 = require('md5'); -exports.defaultName = 'PJLink Projector'; -exports.connectionType = 'TCPsocket'; -exports.heartbeatInterval = 5000; -exports.heartbeatTimeout = 15000; -exports.searchOptions = { - type: 'UDPsocket', - searchBuffer: Buffer.from([0x25, 0x32, 0x53, 0x52, 0x43, 0x48, 0x0d]), - devicePort: 4352, - listenPort: 4352, - validateResponse (msg, info) { - return msg.toString().indexOf('%2ACKN=') >= 0; - }, -}; -exports.defaultPort = 4352; +exports.config = { + defaultName: 'PJLink Projector', + connectionType: "TCPsocket", + heartbeatInterval: 5000, + heartbeatTimeout: 15000, + defaultPort: 4352, + mayChangePort: false, + searchOptions: { + type: 'UDPsocket', + searchBuffer: Buffer.from([0x25, 0x32, 0x53, 0x52, 0x43, 0x48, 0x0d]), + devicePort: 4352, + listenPort: 4352, + validateResponse (msg, info) { + return msg.toString().indexOf('%2ACKN=') >= 0; + } + } +} exports.ready = function ready(device) { // Power status query diff --git a/plugins/qlab/main.js b/plugins/qlab/main.js index 8521b25..92ebd12 100644 --- a/plugins/qlab/main.js +++ b/plugins/qlab/main.js @@ -2,6 +2,27 @@ const _ = require('lodash'); const fs = require('fs'); const path = require('path'); +exports.config = { + defaultName: "QLab", + connectionType: "osc", + heartbeatInterval: 50, + heartbeatTimeout: 2000, + mayChangePort: true, + searchOptions: { + type: 'Bonjour', + bonjourName: 'qlab', + }, + fields: [{ + key: "passcode", + label: "Pass", + type: "textinput", + value: "5353", + action: function(device){ + device.send('/workspaces'); + } + }] +} + let lastElapsedUpdate = Date.now(); let interval = 5; let heartbeatCount = 0; @@ -16,14 +37,6 @@ const cueTemplate = _.template(fs.readFileSync(path.join(__dirname, `cue.ejs`))) const tileTemplate = _.template(fs.readFileSync(path.join(__dirname, `tile.ejs`))); const cartTemplate = _.template(fs.readFileSync(path.join(__dirname, `cart.ejs`))); -exports.defaultName = 'QLab'; -exports.connectionType = 'osc'; -exports.heartbeatInterval = 50; -exports.heartbeatTimeout = 2000; -exports.searchOptions = { - type: 'Bonjour', - bonjourName: 'qlab', -}; exports.ready = function ready(device) { device.send(`/version`); @@ -54,7 +67,7 @@ exports.data = function data(_device, oscData) { cueLists: {}, cues: {} } - device.send(`/workspace/${wksp.uniqueID}/connect`); + device.send(`/workspace/${wksp.uniqueID}/connect`, device.fields.passcode); }); }else if(match(oscAddressParts, ["reply", "workspace", "*", "connect"])){ diff --git a/plugins/sacn/main.js b/plugins/sacn/main.js index 488d2cf..dfa31b3 100644 --- a/plugins/sacn/main.js +++ b/plugins/sacn/main.js @@ -1,18 +1,21 @@ const _ = require('lodash'); -exports.defaultName = 'sACN'; -exports.connectionType = 'multicast'; -exports.defaultPort = 5568; -exports.heartbeatInterval = 5000; -exports.searchOptions = { - type: "multicast", - address: getMulticastGroup(1), - port: 5568, - validateResponse (msg, info) { - return msg.toString('utf8', 4, 13) === "ASC-E1.17"; - }, -}; -exports.defaultPort = 5568; +exports.config = { + defaultName: "sACN", + connectionType: "multicast", + defaultPort: 5568, + heartbeatInterval: 5000, + defaultPort: 5568, + mayChangePort: false, + searchOptions: { + type: "multicast", + address: getMulticastGroup(1), + port: 5568, + validateResponse (msg, info) { + return msg.toString('utf8', 4, 13) === "ASC-E1.17"; + } + } +} exports.ready = function ready(device) { diff --git a/plugins/watchout/main.js b/plugins/watchout/main.js index f80ad4a..896784d 100644 --- a/plugins/watchout/main.js +++ b/plugins/watchout/main.js @@ -1,15 +1,18 @@ -exports.defaultName = 'Dataton Watchout'; -exports.connectionType = 'TCPsocket'; -exports.heartbeatInterval = 500; -exports.searchOptions = { - type: 'TCPport', - searchBuffer: Buffer.from('authenticate 1\n', 'ascii'), - testPort: 3040, - validateResponse (msg, info) { - return msg.toString().substring(0, 5) === 'Ready'; - }, -}; -exports.defaultPort = 3040; +exports.config = { + defaultName: "Dataton Watchout", + connectionType: "TCPsocket", + heartbeatInterval: 500, + defaultPort: 3040, + mayChangePort: false, + searchOptions: { + type: 'TCPport', + searchBuffer: Buffer.from('authenticate 1\n', 'ascii'), + testPort: 3040, + validateResponse (msg, info) { + return msg.toString().substring(0, 5) === 'Ready'; + } + } +} exports.ready = function ready(device) { device.send('authenticate 1\n'); diff --git a/plugins/x32/main.js b/plugins/x32/main.js index 020fadc..700a961 100644 --- a/plugins/x32/main.js +++ b/plugins/x32/main.js @@ -1,16 +1,19 @@ -exports.defaultName = 'X32 Mixer'; -exports.connectionType = 'osc-udp'; -exports.heartbeatInterval = 9000; -exports.searchOptions = { - type: 'UDPsocket', - searchBuffer: Buffer.from([0x2f, 0x78, 0x69, 0x6e, 0x66, 0x6f]), - devicePort: 10023, - listenPort: 0, - validateResponse(msg, info) { - return msg.toString().indexOf('/xinfo') === 0; - }, -}; -exports.defaultPort = 10023; +exports.config = { + defaultName: "X32 Mixer", + connectionType: "osc-udp", + heartbeatInterval: 9000, + defaultPort: 10023, + mayChangePort: false, + searchOptions: { + type: 'UDPsocket', + searchBuffer: Buffer.from([0x2f, 0x78, 0x69, 0x6e, 0x66, 0x6f]), + devicePort: 10023, + listenPort: 0, + validateResponse(msg, info) { + return msg.toString().indexOf('/xinfo') === 0; + } + } +} exports.ready = function ready(device) { const d = device; diff --git a/plugins/xair/main.js b/plugins/xair/main.js index 152dd84..25e70d4 100644 --- a/plugins/xair/main.js +++ b/plugins/xair/main.js @@ -1,16 +1,19 @@ -exports.defaultName = 'X Air Mixer'; -exports.connectionType = 'UDPsocket'; -exports.heartbeatInterval = 10000; -exports.searchOptions = { - type: 'UDPsocket', - searchBuffer: Buffer.from([0x2f, 0x78, 0x69, 0x6e, 0x66, 0x6f]), - devicePort: 10024, - listenPort: 0, - validateResponse(msg, info) { - return msg.toString().indexOf('/xinfo') === 0; - }, -}; -exports.defaultPort = 10024; +exports.config = { + defaultName: "X Air Mixer", + connectionType: "UDPsocket", + heartbeatInterval: 10000, + defaultPort: 10024, + mayChangePort: false, + searchOptions: { + type: 'UDPsocket', + searchBuffer: Buffer.from([0x2f, 0x78, 0x69, 0x6e, 0x66, 0x6f]), + devicePort: 10024, + listenPort: 0, + validateResponse(msg, info) { + return msg.toString().indexOf('/xinfo') === 0; + } + } +} exports.ready = function ready(device) { const d = device; diff --git a/src/device.js b/src/device.js index 7ad45e7..17c4f17 100644 --- a/src/device.js +++ b/src/device.js @@ -49,6 +49,7 @@ function registerDevice(newDevice) { port: newDevice.port, addresses: newDevice.addresses, data: {}, + fields: {}, pinIndex: false, lastDrawn: 0, lastHeartbeat: 0, @@ -65,6 +66,13 @@ function registerDevice(newDevice) { }, }; + if(PLUGINS.all[newDevice.type].config.fields){ + PLUGINS.all[newDevice.type].config.fields.forEach(field => { + devices[id].fields[field.key] = field.value; + }); + } + + VIEW.addDeviceToList(devices[id]); initDeviceConnection(id); return true; @@ -89,8 +97,8 @@ function initDeviceConnection(id) { const { type } = devices[id]; const plugins = PLUGINS.all; - if (plugins[type].connectionType.includes('osc')) { - if (plugins[type].connectionType.includes('udp')) { + if (plugins[type].config.connectionType.includes('osc')) { + if (plugins[type].config.connectionType.includes('udp')) { device.connection = new osc.UDPPort({ localAddress: '0.0.0.0', remoteAddress: device.addresses[0], @@ -125,7 +133,7 @@ function initDeviceConnection(id) { device.connection.send({ address, args }); }; device.plugin = plugins[type]; - } else if (plugins[type].connectionType === 'TCPsocket') { + } else if (plugins[type].config.connectionType === 'TCPsocket') { device.connection = new net.Socket(); device.connection.connect( @@ -155,7 +163,7 @@ function initDeviceConnection(id) { // log("SOCK OUT", data); device.connection.write(data); }; - } else if (plugins[type].connectionType === 'UDPsocket') { + } else if (plugins[type].config.connectionType === 'UDPsocket') { device.connection = udp.createSocket('udp4'); device.connection.bind({ port: plugins[type].defaultPort }, () => { @@ -177,7 +185,7 @@ function initDeviceConnection(id) { } ); }; - } else if (plugins[type].connectionType === 'multicast') { + } else if (plugins[type].config.connectionType === 'multicast') { device.connection = udp.createSocket('udp4'); device.connection.bind(device.port, () => { diff --git a/src/plugins.js b/src/plugins.js index 794fcd6..24e2305 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -47,17 +47,33 @@ module.exports.init = function init(callback) { ); - if (p.heartbeatTimeout === undefined || p.heartbeatTimeout < 50) { - if(p.heartbeatInterval){ - p.heartbeatTimeout = p.heartbeatInterval * 1.5; + //if (p.heartbeatTimeout === undefined || p.heartbeatTimeout < 50) { + if(p.config.heartbeatTimeout){ + p.heartbeatTimeout = p.config.heartbeatInterval * 1.5; }else{ p.heartbeatTimeout = 10000; } - } + //} - if (p.heartbeatInterval === undefined || p.heartbeatInterval < 50) { - p.heartbeatInterval = 5000; - } + if(p.config.heartbeatInterval){ + p.heartbeatInterval = Math.max(50, p.config.heartbeatInterval); + }else{ + p.heartbeatInterval = 5000; + } + + // p.fields = {}; + // if(p.config.fields){ + // p.config.fields.forEach(field => { + // p.fields[field.key] = field.value; + // }); + // } + + + + + // if (p.heartbeatInterval === undefined || p.heartbeatInterval < 50) { + // p.heartbeatInterval = 5000; + // } } }); diff --git a/src/search.js b/src/search.js index 955355a..3da3671 100644 --- a/src/search.js +++ b/src/search.js @@ -60,21 +60,21 @@ function searchAll() { const plugin = PLUGINS.all[p]; try { - const t = plugin.searchOptions.type; + const t = plugin.config.searchOptions.type; if(t === 'TCPport'){ if (TCPFlag) { - searchTCP(p, plugin); + searchTCP(p, plugin.config); } }else if(t === 'Bonjour'){ - searchBonjour(p, plugin); + searchBonjour(p, plugin.config); }else if(t === 'UDPsocket'){ - searchUDP(p, plugin); + searchUDP(p, plugin.config); }else if(t === 'multicast'){ - searchMulticast(p, plugin); + searchMulticast(p, plugin.config); } diff --git a/src/view.js b/src/view.js index 9d3613f..935f7ef 100644 --- a/src/view.js +++ b/src/view.js @@ -197,6 +197,35 @@ function switchDevice(id) { document.getElementById('device-settings-port').value = activeDevice.port || ''; document.getElementById('device-settings-pin').checked = activeDevice.pinIndex; + if(activeDevice.plugin.config.mayChangePort){ + document.getElementById('device-settings-port').disabled = false; + }else{ + document.getElementById('device-settings-port').disabled = true; + } + + document.getElementById('device-settings-fields').innerHTML = ""; + + if(activeDevice.plugin.config.fields){ + let fields = activeDevice.plugin.config.fields; + + fields.forEach(field => { + let $elem = document.createElement("input"); + $elem.type = "text"; + $elem.value = activeDevice.fields[field.key] || field.value; + $elem.name = field.key; + $elem.onchange = function(e){ + activeDevice.fields[field.key] = $elem.value; + field.action(activeDevice); + } + + if(field.type=="textinput"){ + let rowHTML =`${field.label}:`; + document.getElementById('device-settings-fields').insertAdjacentHTML("beforeend", rowHTML); + document.getElementById(field.key).appendChild($elem); + } + }); + } + ipcRenderer.send('enableDeviceDropdown', ''); ipcRenderer.send('setDevicePin', !DEVICE.all[id].pinIndex === false); }; @@ -303,8 +332,8 @@ function populatePluginLists() { Object.keys(PLUGINS.all).forEach((pluginType) => { const plugin = PLUGINS.all[pluginType]; - addSelect += ``; - typeSelect += ``; + addSelect += ``; + typeSelect += ``; }); document.getElementById('device-settings-plugin-dropdown').innerHTML = typeSelect;