mirror of
https://github.com/amark/gun.git
synced 2025-06-03 20:56:43 +00:00
Update bye.js
This commit is contained in:
parent
14f6ba098a
commit
93cd24caa7
24
lib/bye.js
24
lib/bye.js
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user