add multicast on all NICs

This commit is contained in:
sparks-alec
2023-01-04 22:44:01 -05:00
parent e0eb2cfaaf
commit c5f79f5a50
3 changed files with 33 additions and 12 deletions
+8 -4
View File
@@ -22,9 +22,15 @@ exports.ready = function ready(device) {
d.data.source = 'Unknown Source';
d.data.orderedUniverses = [];
const networkInterfaces = d.getNetworkInterfaces();
// device.draw();
for (let i = 1; i <= 16; i++) {
d.connection.addMembership(getMulticastGroup(i));
for (let j = 0; j < Object.keys(networkInterfaces).length; j++) {
const networkInterfaceID = Object.keys(networkInterfaces)[j];
const networkInterface = networkInterfaces[networkInterfaceID];
d.connection.addMembership(getMulticastGroup(i), networkInterface[0].address);
}
}
};
@@ -108,9 +114,7 @@ exports.update = function update(_device, doc, updateType, updateData) {
} else if (updateType === 'elementCache') {
device.data.orderedUniverses.forEach((universeIndex) => {
for (let i = 0; i < 512; i++) {
device.data.universes[universeIndex].slotElems[i] = doc.getElementById(
`${universeIndex}-${i}`
);
device.data.universes[universeIndex].slotElems[i] = doc.getElementById(`${universeIndex}-${i}`);
}
device.data.universes[universeIndex].slotElemsSet = true;
});
+4
View File
@@ -7,6 +7,7 @@ const _ = require('lodash');
const PLUGINS = require('./plugins.js');
const VIEW = require('./view.js');
const SAVESLOTS = require('./saveSlots.js');
const SEARCH = require('./search.js');
const devices = {};
module.exports.all = devices;
@@ -63,6 +64,9 @@ function registerDevice(newDevice) {
this.draw();
}
},
getNetworkInterfaces() {
return SEARCH.getNetworkInterfaces();
},
};
devices[id].plugin = PLUGINS.all[newDevice.type];
+21 -8
View File
@@ -10,11 +10,12 @@ const PLUGINS = require('./plugins.js');
let searching = false;
let allServers = false;
const validInterfaces = {};
let validInterfaces = {};
function getServers() {
const interfaces = os.networkInterfaces();
const result = [];
validInterfaces = {};
Object.keys(interfaces).forEach((key) => {
const addresses = interfaces[key];
@@ -39,6 +40,11 @@ function getServers() {
});
return result;
}
function getNetworkInterfaces() {
getServers();
return validInterfaces;
}
module.exports.getNetworkInterfaces = getNetworkInterfaces;
const searchSockets = [];
function searchAll() {
@@ -183,16 +189,23 @@ function searchMulticast(pluginType, pluginConfig) {
const socket = dgram.createSocket('udp4');
socket.on('message', (msg, info) => {
if (pluginConfig.searchOptions.validateResponse(msg, info)) {
socket.close();
DEVICE.registerDevice({
type: pluginType,
defaultName: pluginConfig.defaultName,
port: pluginConfig.defaultPort,
addresses: [info.address],
socket.close(() => {
DEVICE.registerDevice({
type: pluginType,
defaultName: pluginConfig.defaultName,
port: pluginConfig.defaultPort,
addresses: [info.address],
});
});
}
});
socket.bind(pluginConfig.searchOptions.port, () => {
socket.addMembership(pluginConfig.searchOptions.address);
for (let i = 0; i < Object.keys(validInterfaces).length; i++) {
const interfaceID = Object.keys(validInterfaces)[i];
const interfaceObj = validInterfaces[interfaceID];
socket.addMembership(pluginConfig.searchOptions.address, interfaceObj[0].address);
}
});
}