From 1701e16dc0ebe4c14a99b23fa2a0c34202bb65c7 Mon Sep 17 00:00:00 2001 From: sparks-alec Date: Mon, 14 Feb 2022 03:38:36 -0500 Subject: [PATCH] more efficient UDP connections --- src/device.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/device.js b/src/device.js index 26215c2..4eef3ad 100644 --- a/src/device.js +++ b/src/device.js @@ -151,7 +151,7 @@ initDeviceConnection = function (id) { } else if (plugins[type].connectionType == 'UDPsocket') { device.connection = udp.createSocket('udp4'); - device.connection.bind(() => { + device.connection.bind({port: plugins[type].defaultPort}, () => { plugins[type].ready(device); device.connection.on('message', (msg, info) => { @@ -165,6 +165,21 @@ initDeviceConnection = function (id) { // console.log(err); }); }; + + + } else if (plugins[type].connectionType == 'multicast') { + device.connection = udp.createSocket('udp4'); + + device.connection.bind(device.port, () => { + plugins[type].ready(device); + + device.connection.on('message', (msg, info) => { + plugins[type].data(device, msg); + infoUpdate(device, 'status', 'ok'); + }); + }); + + device.send = function (data) {}; }