From ff8b0177e4efed9838ac1a22f20fd4e28ec8342a Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Fri, 4 Jan 2019 20:41:04 +0200 Subject: [PATCH] multicast --- lib/multicast.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/multicast.js b/lib/multicast.js index aea81af3..862e6e51 100644 --- a/lib/multicast.js +++ b/lib/multicast.js @@ -47,12 +47,16 @@ Gun.on('create', function(root){ } socket.on("message", function(message, rinfo) { - var msgObj = JSON.parse(message.toString(ENC)); - if (!(msgObj.gun && msgObj.gun.port)) { return } - var peer = `http://${rinfo.address}:${msgObj.gun.port}`; - if (!root.opt.peers.hasOwnProperty(peer)) { - console.log(`peer ${peer} found via multicast`); - root.$.opt({peers: [peer]}); + try { + var msgObj = JSON.parse(message.toString(ENC)); + if (!(msgObj.gun && msgObj.gun.port)) { return } + var peer = `http://${rinfo.address}:${msgObj.gun.port}`; + if (!root.opt.peers.hasOwnProperty(peer)) { + console.log(`peer ${peer} found via multicast`); + root.$.opt({peers: [peer]}); + } + } catch (e) { + // console.error(`Received multicast from ${rinfo.address}:${rinfo.port} but failed to connect:`, e); } }); });