Initial prettify

This commit is contained in:
Sam Schloegel
2022-01-03 10:51:25 -05:00
parent 551d29da60
commit c5691b56c9
26 changed files with 2602 additions and 2545 deletions
+219 -224
View File
@@ -2,117 +2,113 @@ const { ipcRenderer } = require('electron');
let netmask = require('netmask').Netmask;
let dgram = require('dgram');
let bonjour = require('bonjour')();
let net = require("net");
let os = require("os");
let ip = require("ip");
let DEVICE = require("./device.js");
let SEARCH = require("./search.js");
let PLUGINS = require("./plugins.js");
let net = require('net');
let os = require('os');
let ip = require('ip');
let DEVICE = require('./device.js');
let SEARCH = require('./search.js');
let PLUGINS = require('./plugins.js');
var searching = false;
var allServers = false;
searchAll = function(){
if(searching){
return true;
}
searching = true;
ipcRenderer.send("disableSearchAll", "");
document.getElementById("search-button").style.opacity = 0.2;
//console.clear();
searchAll = function () {
if (searching) {
return true;
}
searching = true;
ipcRenderer.send('disableSearchAll', '');
document.getElementById('search-button').style.opacity = 0.2;
//console.clear();
for(var i in DEVICE.all){
DEVICE.infoUpdate(DEVICE.all[i], "status", "refresh");
}
for (var i in DEVICE.all) {
DEVICE.infoUpdate(DEVICE.all[i], 'status', 'refresh');
}
console.log("Searching...")
console.log('Searching...');
//findOnlineDevices();
allServers = getServers();
var 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.'
);
TCPFlag = false;
}
//findOnlineDevices();
allServers = getServers();
var 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.")
TCPFlag = false;
}
console.log(PLUGINS);
console.log(PLUGINS)
for (var p in PLUGINS.all) {
var plugin = PLUGINS.all[p];
console.log(p);
try {
switch (plugin.searchOptions.type) {
case 'TCPport':
if (TCPFlag) {
newSearchTCP(p, plugin);
}
break;
case 'Bonjour':
newSearchBonjour(p, plugin);
break;
case 'UDPsocket':
newSearchUDP(p, plugin);
break;
}
} catch (err) {
console.error('Unable to search for plugin ' + p);
}
}
for(var p in PLUGINS.all){
var plugin = PLUGINS.all[p];
console.log(p)
try{
switch(plugin.searchOptions.type){
case "TCPport":
if(TCPFlag){
newSearchTCP(p, plugin);
}
break;
case "Bonjour":
newSearchBonjour(p, plugin)
break;
case "UDPsocket":
newSearchUDP(p, plugin)
break;
}
}catch(err){
console.error("Unable to search for plugin "+p)
}
}
//searchBonjour();
//searchTCP();
//searchUDP();
//searchBonjour();
//searchTCP();
//searchUDP();
setTimeout(function () {
searching = false;
document.getElementById('search-button').style.opacity = '';
setTimeout(function(){
searching = false;
document.getElementById("search-button").style.opacity = "";
for (var i = 0; i < searchSockets.length; i++) {
try {
searchSockets[i].close();
} catch (err) {}
}
for(var i=0; i<searchSockets.length; i++){
try{searchSockets[i].close();}catch(err){}
}
ipcRenderer.send("enableSearchAll", "");
}, 5000)
}
ipcRenderer.send('enableSearchAll', '');
}, 5000);
};
module.exports.searchAll = searchAll;
// ____ _
// | _ \ (_)
// | |_) | ___ _ __ _ ___ _ _ _ __
// | _ < / _ \| '_ \| |/ _ \| | | | '__|
// | |_) | (_) | | | | | (_) | |_| | |
// |____/ \___/|_| |_| |\___/ \__,_|_|
// _/ |
// |__/
newSearchBonjour = function (pluginType, plugin) {
bonjour.find({ type: plugin.searchOptions.bonjourName }, function (e) {
console.log(pluginType);
var validAddresses = [];
for (var i in e.addresses) {
if (e.addresses[i].indexOf(':') == -1) {
validAddresses.push(e.addresses[i]);
}
}
// ____ _
// | _ \ (_)
// | |_) | ___ _ __ _ ___ _ _ _ __
// | _ < / _ \| '_ \| |/ _ \| | | | '__|
// | |_) | (_) | | | | | (_) | |_| | |
// |____/ \___/|_| |_| |\___/ \__,_|_|
// _/ |
// |__/
newSearchBonjour = function(pluginType, plugin){
bonjour.find({type: plugin.searchOptions.bonjourName}, function(e){
console.log(pluginType)
var validAddresses = [];
for(var i in e.addresses){
if(e.addresses[i].indexOf(":")==-1){
validAddresses.push(e.addresses[i])
}
}
DEVICE.registerDevice({
type: pluginType,
defaultName: e.name,
port: e.port,
addresses: validAddresses
})
});
}
DEVICE.registerDevice({
type: pluginType,
defaultName: e.name,
port: e.port,
addresses: validAddresses,
});
});
};
// searchBonjour = function(){
// bonjour.find({type: "qlab"}, function(e){
@@ -129,68 +125,65 @@ newSearchBonjour = function(pluginType, plugin){
// })
// });
// }
// _______ _____ _____
// |__ __/ ____| __ \
// | | | | | |__) |
// | | | | | ___/
// | | | |____| |
// |_| \_____|_|
newSearchTCP = function (pluginType, plugin) {
for (var i = 0; i < allServers.length; i++) {
TCPtest(allServers[i], pluginType, plugin);
}
};
// _______ _____ _____
// |__ __/ ____| __ \
// | | | | | |__) |
// | | | | | ___/
// | | | |____| |
// |_| \_____|_|
newSearchTCP = function(pluginType, plugin){
for(var i=0; i<allServers.length; i++){
TCPtest(allServers[i], pluginType, plugin);
}
}
TCPtest = function(ip, pluginType, plugin){
var client = net.createConnection(plugin.searchOptions.testPort, ip, function(){
client.write(plugin.searchOptions.searchBuffer);
// DEVICE.registerDevice({
// type: pluginType,
// defaultName: plugin.defaultName,
// port: plugin.defaultPort,
// addresses: [ip]
// })
});
client.on('data', (data) => {
if(plugin.searchOptions.validateResponse(data)){
DEVICE.registerDevice({
type: pluginType,
defaultName: plugin.defaultName,
port: plugin.defaultPort,
addresses: [ip]
})
}
client.end();
});
client.on("error", function(err){
//no device here
});
}
TCPtest = function (ip, pluginType, plugin) {
var client = net.createConnection(
plugin.searchOptions.testPort,
ip,
function () {
client.write(plugin.searchOptions.searchBuffer);
// DEVICE.registerDevice({
// type: pluginType,
// defaultName: plugin.defaultName,
// port: plugin.defaultPort,
// addresses: [ip]
// })
}
);
client.on('data', (data) => {
if (plugin.searchOptions.validateResponse(data)) {
DEVICE.registerDevice({
type: pluginType,
defaultName: plugin.defaultName,
port: plugin.defaultPort,
addresses: [ip],
});
}
client.end();
});
client.on('error', function (err) {
//no device here
});
};
// from local-devices library
function getServers () {
var interfaces = os.networkInterfaces()
var result = []
function getServers() {
var interfaces = os.networkInterfaces();
var result = [];
for (var key in interfaces) {
var addresses = interfaces[key]
for (var i = addresses.length; i--;) {
var address = addresses[i]
var addresses = interfaces[key];
for (var i = addresses.length; i--; ) {
var 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
while (current++ < last) result.push(ip.fromLong(current))
var subnet = ip.subnet(address.address, address.netmask);
var current = ip.toLong(subnet.firstAddress);
var last = ip.toLong(subnet.lastAddress) - 1;
while (current++ < last) result.push(ip.fromLong(current));
}
}
}
@@ -198,39 +191,38 @@ function getServers () {
return result;
}
findOnlineDevices = function () {
var allInterfaces = require('os').networkInterfaces();
var validInterfaces = [];
for (var i in allInterfaces) {
for (var j = 0; j < allInterfaces[i].length; j++) {
var iface = allInterfaces[i][j];
if (
iface.family == 'IPv4' &&
iface.internal == false &&
iface.address.split('.')[0] != '169'
) {
validInterfaces.push(iface);
}
}
}
findOnlineDevices = function(){
var allInterfaces = require('os').networkInterfaces();
var validInterfaces = [];
for(var i in allInterfaces){
for(var j=0; j<allInterfaces[i].length; j++){
var iface = allInterfaces[i][j];
if(iface.family=="IPv4" && iface.internal==false && iface.address.split(".")[0]!="169"){
validInterfaces.push(iface);
}
}
}
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(var j=Number(f[2]); j<=Number(l[2]); j++){
cur[2] = j;
for(var k = Number(f[3]); k<Number(l[3]); k++){
cur[3] = k;
allIPs.push(cur[0]+"."+cur[1]+"."+cur[2]+"."+cur[3]);
}
}
}
}
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 (var j = Number(f[2]); j <= Number(l[2]); j++) {
cur[2] = j;
for (var k = Number(f[3]); k < Number(l[3]); k++) {
cur[3] = k;
allIPs.push(cur[0] + '.' + cur[1] + '.' + cur[2] + '.' + cur[3]);
}
}
}
};
// window.searchTCP = function(){
// var allInterfaces = require('os').networkInterfaces();
@@ -287,15 +279,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');
@@ -303,41 +293,53 @@ var serverUDP2 = dgram.createSocket('udp4');
var searchSockets = [];
newSearchUDP = function (pluginType, plugin) {
var i = searchSockets.push(dgram.createSocket('udp4')) - 1;
searchSockets[i].bind(plugin.searchOptions.listenPort, function () {
searchSockets[i].send(
plugin.searchOptions.searchBuffer,
plugin.searchOptions.devicePort,
'255.255.255.255',
(err) => {
//console.log(err)
}
);
setTimeout(function () {
searchSockets[i].send(
plugin.searchOptions.searchBuffer,
plugin.searchOptions.devicePort,
'255.255.255.255',
(err) => {
//console.log(err)
}
);
}, 100);
setTimeout(function () {
searchSockets[i].send(
plugin.searchOptions.searchBuffer,
plugin.searchOptions.devicePort,
'255.255.255.255',
(err) => {
//console.log(err)
}
);
}, 400);
newSearchUDP = function(pluginType, plugin){
var i = searchSockets.push(dgram.createSocket('udp4'))-1;
searchSockets[i].bind(plugin.searchOptions.listenPort, function(){
searchSockets[i].send(plugin.searchOptions.searchBuffer, plugin.searchOptions.devicePort, '255.255.255.255', (err) => {
//console.log(err)
});
setTimeout(function(){
searchSockets[i].send(plugin.searchOptions.searchBuffer, plugin.searchOptions.devicePort, '255.255.255.255', (err) => {
//console.log(err)
});
}, 100);
setTimeout(function(){
searchSockets[i].send(plugin.searchOptions.searchBuffer, plugin.searchOptions.devicePort, '255.255.255.255', (err) => {
//console.log(err)
});
}, 400);
searchSockets[i].on('message',function(msg,info){
if(plugin.searchOptions.validateResponse(msg, info)){
DEVICE.registerDevice({
type: pluginType,
defaultName: plugin.defaultName,
port: plugin.defaultPort,
addresses: [info.address]
})
}
});
});
searchSockets[i].on('listening', function(){
searchSockets[i].setBroadcast(true);
});
}
searchSockets[i].on('message', function (msg, info) {
if (plugin.searchOptions.validateResponse(msg, info)) {
DEVICE.registerDevice({
type: pluginType,
defaultName: plugin.defaultName,
port: plugin.defaultPort,
addresses: [info.address],
});
}
});
});
searchSockets[i].on('listening', function () {
searchSockets[i].setBroadcast(true);
});
};
// searchUDP = function(){
@@ -362,7 +364,6 @@ newSearchUDP = function(pluginType, plugin){
// dgramPJLink.setBroadcast(true);
// });
// dgramXAir = dgram.createSocket('udp4');
// dgramXAir.bind(function(){
// dgramXAir.send(xAirMessage, 10024, '255.255.255.255', (err) => {
@@ -389,11 +390,5 @@ newSearchUDP = function(pluginType, plugin){
// dgramXAir.on('listening', function(){
// dgramXAir.setBroadcast(true);
// });
// }