multicast

This commit is contained in:
Martti Malmi 2019-01-04 20:41:04 +02:00
parent 996388f6b9
commit f194fa90de

View File

@ -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);
}
});
});