diff --git a/plugins/sacn/main.js b/plugins/sacn/main.js index ee860aa..b1754ac 100644 --- a/plugins/sacn/main.js +++ b/plugins/sacn/main.js @@ -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; }); diff --git a/src/device.js b/src/device.js index b9b1616..6ae0446 100644 --- a/src/device.js +++ b/src/device.js @@ -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]; diff --git a/src/search.js b/src/search.js index b478057..3d94c0f 100644 --- a/src/search.js +++ b/src/search.js @@ -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); + } }); }