better env detection

This commit is contained in:
Martti Malmi 2019-01-23 14:28:33 +02:00
parent 5f153a4912
commit 6795ef04a8

View File

@ -3,9 +3,15 @@ var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
Gun.on('create', function(root){ Gun.on('create', function(root){
this.to.next(root); this.to.next(root);
var opt = root.opt; var opt = root.opt;
if(typeof window !== "undefined"){
return; // do nothing for now - Chrome extensions could use multicast though try {
var dgram = require("dgram");
var process = require("process");
} catch (e) {
console.log('multicast is not available');
return;
} }
if(false === opt.multicast){ return } if(false === opt.multicast){ return }
opt.multicast = opt.multicast || {}; opt.multicast = opt.multicast || {};
@ -15,9 +21,6 @@ Gun.on('create', function(root){
var DEFAULT_GUN_PORT = 8765; var DEFAULT_GUN_PORT = 8765;
var ENC = 'utf8'; var ENC = 'utf8';
var dgram = require("dgram");
var process = require("process");
socket = dgram.createSocket({ type: "udp4", reuseAddr: true }); socket = dgram.createSocket({ type: "udp4", reuseAddr: true });
socket.bind(PORT); socket.bind(PORT);