Update bye.js

This commit is contained in:
Mark Nadal 2019-09-19 05:00:28 -07:00 committed by GitHub
parent 14f6ba098a
commit 93cd24caa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,24 +1,22 @@
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun'); var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
Gun.on('opt', function(root){ Gun.on('create', function(root){
this.to.next(root); this.to.next(root);
if(root.once){ return } var mesh = root.opt.mesh;
root.on('in', function(msg){ if(!mesh){ return }
//Msg did not have a peer property saved before, so nothing ever went further mesh.hear['bye'] = function(msg, peer){
if(!msg._ || !msg.BYE){ return this.to.next(msg) } (peer.byes = peer.byes || []).push(msg.bye);
var peer = msg._.via; }
(peer.bye = peer.bye || []).push(msg.BYE);
})
root.on('bye', function(peer){ root.on('bye', function(peer){
this.to.next(peer); this.to.next(peer);
if(!peer.bye){ return } if(!peer.byes){ return }
var gun = root.gun; var gun = root.$;
Gun.obj.map(peer.bye, function(data){ Gun.obj.map(peer.byes, function(data){
Gun.obj.map(data, function(put, soul){ Gun.obj.map(data, function(put, soul){
gun.get(soul).put(put); gun.get(soul).put(put);
}); });
}); });
peer.bye = []; peer.byes = [];
}); });
}); });
@ -30,7 +28,7 @@ Gun.chain.bye = function(){
var tmp = data; var tmp = data;
(data = {})[at.get] = tmp; (data = {})[at.get] = tmp;
}); });
root.on('out', {BYE: data}); root.on('out', {bye: data});
return gun; return gun;
} }
return bye; return bye;