Merge pull request #936 from joedakroub/master

Fix for ES Modules when using a peer
This commit is contained in:
Mark Nadal 2020-04-24 11:50:36 -07:00 committed by GitHub
commit ff99a4639d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

8
gun.js
View File

@ -987,7 +987,7 @@
if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window } if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){} try{ if(typeof MODULE !== "undefined"){ MODULE.exports = Gun } }catch(e){}
module.exports = Gun; module.exports = Gun;
(Gun.window||'').console = (Gun.window||'').console || {log: function(){}}; (Gun.window||'').console = (Gun.window||'').console || {log: function(){}};
(C = console).only = function(i, s){ return (C.only.i && i === C.only.i && C.only.i++) && (C.log.apply(C, arguments) || s) }; (C = console).only = function(i, s){ return (C.only.i && i === C.only.i && C.only.i++) && (C.log.apply(C, arguments) || s) };
@ -2158,7 +2158,7 @@
var message, loop; var message, loop;
function each(peer){ mesh.say(message, peer) } function each(peer){ mesh.say(message, peer) }
var say = mesh.say = function(msg, peer){ var say = mesh.say = function(msg, peer){
if(this.to){ this.to.next(msg) } // compatible with middleware adapters. if(this && this.to){ this.to.next(msg) } // compatible with middleware adapters.
if(!msg){ return false } if(!msg){ return false }
var id, hash, tmp, raw; var id, hash, tmp, raw;
var DBG = msg.DBG, S; if(!peer){ S = +new Date ; DBG && (DBG.y = S) } var DBG = msg.DBG, S; if(!peer){ S = +new Date ; DBG && (DBG.y = S) }
@ -2324,7 +2324,7 @@
}); });
root.on('bye', function(peer, tmp){ root.on('bye', function(peer, tmp){
peer = opt.peers[peer.id || peer] || peer; peer = opt.peers[peer.id || peer] || peer;
this.to.next(peer); this.to.next(peer);
peer.bye? peer.bye() : (tmp = peer.wire) && tmp.close && tmp.close(); peer.bye? peer.bye() : (tmp = peer.wire) && tmp.close && tmp.close();
Type.obj.del(opt.peers, peer.id); Type.obj.del(opt.peers, peer.id);
@ -2439,4 +2439,4 @@
var noop = function(){}; var noop = function(){};
})(USE, './adapters/websocket'); })(USE, './adapters/websocket');
}()); }());