mirror of
https://github.com/stagehacks/Cue-View.git
synced 2026-08-03 04:47:47 +00:00
add search for sending udp direct to IPs for ATEM
This commit is contained in:
@@ -3,15 +3,17 @@ exports.config = {
|
||||
connectionType: 'atem',
|
||||
defaultPort: 9910,
|
||||
mayChangePort: false,
|
||||
// heartbeatInterval: 5000,
|
||||
// heartbeatTimeout: 20000,
|
||||
searchOptions: {
|
||||
// TODO: actually populate search options
|
||||
type: 'UDPsocket',
|
||||
searchBuffer: Buffer.from('', 'ascii'),
|
||||
testPort: 9910,
|
||||
type: 'UDPScan',
|
||||
searchBuffer: Buffer.from([
|
||||
0x10, 0x14, 0x53, 0xab, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00,
|
||||
]),
|
||||
listenPort: 0,
|
||||
devicePort: 9910,
|
||||
validateResponse(msg, info) {
|
||||
return true;
|
||||
// This is a tad bit hacky but works from what I can see.
|
||||
return Buffer.compare(msg.slice(0, 4), Buffer.from([16, 20, 83, 171])) === 0;
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@ const net = require('net');
|
||||
const os = require('os');
|
||||
const ip = require('ip');
|
||||
|
||||
const { Netmask } = require('netmask');
|
||||
const DEVICE = require('./device.js');
|
||||
const PLUGINS = require('./plugins.js');
|
||||
|
||||
@@ -91,6 +92,8 @@ function searchAll() {
|
||||
searchUDP(pluginType, plugin.config);
|
||||
} else if (searchType === 'multicast') {
|
||||
searchMulticast(pluginType, plugin.config);
|
||||
} else if (searchType === 'UDPScan') {
|
||||
searchUDPScan(pluginType, plugin.config);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(`Unable to search for plugin ${pluginType}`);
|
||||
@@ -167,6 +170,36 @@ function TCPtest(ipAddr, pluginType, pluginConfig) {
|
||||
});
|
||||
}
|
||||
|
||||
function searchUDPScan(pluginType, pluginConfig) {
|
||||
for (let i = 0; i < Object.keys(validInterfaces).length; i++) {
|
||||
const interfaceID = Object.keys(validInterfaces)[i];
|
||||
const interfaceObj = validInterfaces[interfaceID];
|
||||
interfaceObj.forEach((netInterface) => {
|
||||
const udpSocket = dgram.createSocket('udp4');
|
||||
udpSocket.bind(pluginConfig.searchOptions.listenPort, netInterface.address);
|
||||
|
||||
udpSocket.on('message', (msg, info) => {
|
||||
if (pluginConfig.searchOptions.validateResponse(msg, info, DEVICE.all)) {
|
||||
udpSocket.close();
|
||||
DEVICE.registerDevice(
|
||||
{
|
||||
type: pluginType,
|
||||
defaultName: pluginConfig.defaultName,
|
||||
port: pluginConfig.defaultPort,
|
||||
addresses: [info.address],
|
||||
},
|
||||
'fromSearch'
|
||||
);
|
||||
}
|
||||
});
|
||||
const interfaceBlock = new Netmask(netInterface.cidr);
|
||||
interfaceBlock.forEach((address, long, index) => {
|
||||
udpSocket.send(pluginConfig.searchOptions.searchBuffer, pluginConfig.searchOptions.devicePort, address);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function searchUDP(pluginType, pluginConfig) {
|
||||
for (let i = 0; i < Object.keys(validInterfaces).length; i++) {
|
||||
const interfaceID = Object.keys(validInterfaces)[i];
|
||||
|
||||
Reference in New Issue
Block a user