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