mirror of
https://github.com/amark/gun.git
synced 2025-06-30 01:42:33 +00:00
Merge pull request #241 from PsychoLlama/master
Add ability to stop broadcast
This commit is contained in:
commit
f73154c2e5
18
lib/wsp.js
18
lib/wsp.js
@ -17,7 +17,7 @@
|
|||||||
if(msg && msg.headers){ delete msg.headers['ws-rid'] }
|
if(msg && msg.headers){ delete msg.headers['ws-rid'] }
|
||||||
// TODO: BUG? ^ What if other peers want to ack? Do they use the ws-rid or a gun declared id?
|
// TODO: BUG? ^ What if other peers want to ack? Do they use the ws-rid or a gun declared id?
|
||||||
try{ws.send(Gun.text.ify(msg));
|
try{ws.send(Gun.text.ify(msg));
|
||||||
}catch(e){} // juuuust in case.
|
}catch(e){} // juuuust in case.
|
||||||
});
|
});
|
||||||
gun.wsp.wire(req, res);
|
gun.wsp.wire(req, res);
|
||||||
});
|
});
|
||||||
@ -104,7 +104,7 @@
|
|||||||
Gun.obj.del(gun.wsp.msg.debounce, id);
|
Gun.obj.del(gun.wsp.msg.debounce, id);
|
||||||
});
|
});
|
||||||
},500);
|
},500);
|
||||||
if(id = gun.wsp.msg.debounce[id]){
|
if(id = gun.wsp.msg.debounce[id]){
|
||||||
return gun.wsp.msg.debounce[id] = Gun.time.is(), id;
|
return gun.wsp.msg.debounce[id] = Gun.time.is(), id;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -113,9 +113,11 @@
|
|||||||
// all streams, technically PATCH but implemented as PUT or POST, are forwarded to other trusted peers
|
// all streams, technically PATCH but implemented as PUT or POST, are forwarded to other trusted peers
|
||||||
// except for the ones that are listed in the message as having already been sending to.
|
// except for the ones that are listed in the message as having already been sending to.
|
||||||
// all states, implemented with GET, are replied to the source that asked for it.
|
// all states, implemented with GET, are replied to the source that asked for it.
|
||||||
function flow(req, res){
|
function flow(req, res){
|
||||||
gun.wsp.on('network').emit(Gun.obj.copy(req));
|
if (!req.auth || req.headers.broadcast) {
|
||||||
if(req.headers.rid){ return } // no need to process.
|
gun.wsp.on('network').emit(Gun.obj.copy(req));
|
||||||
|
}
|
||||||
|
if(req.headers.rid){ return } // no need to process.
|
||||||
if(Gun.is.lex(req.body)){ return tran.get(req, res) }
|
if(Gun.is.lex(req.body)){ return tran.get(req, res) }
|
||||||
else { return tran.put(req, res) }
|
else { return tran.put(req, res) }
|
||||||
}
|
}
|
||||||
@ -159,7 +161,7 @@
|
|||||||
if(opt.on && opt.on.off){ opt.on.off() }
|
if(opt.on && opt.on.off){ opt.on.off() }
|
||||||
return cb({headers: reply.headers, body: (err? (err.err? err : {err: err || "Unknown error."}) : null)});
|
return cb({headers: reply.headers, body: (err? (err.err? err : {err: err || "Unknown error."}) : null)});
|
||||||
}
|
}
|
||||||
if(Gun.obj.empty(node)){
|
if(Gun.obj.empty(node)){
|
||||||
if(opt.on && opt.on.off){ opt.on.off() }
|
if(opt.on && opt.on.off){ opt.on.off() }
|
||||||
return cb({headers: reply.headers, body: node});
|
return cb({headers: reply.headers, body: node});
|
||||||
} // we're out of stuff!
|
} // we're out of stuff!
|
||||||
@ -191,7 +193,7 @@
|
|||||||
// This will give you much more fine-grain control over security, transactions, and what not.
|
// This will give you much more fine-grain control over security, transactions, and what not.
|
||||||
var reply = {headers: {'Content-Type': tran.json, rid: req.headers.id, id: gun.wsp.msg()}};
|
var reply = {headers: {'Content-Type': tran.json, rid: req.headers.id, id: gun.wsp.msg()}};
|
||||||
if(!req.body){ return cb({headers: reply.headers, body: {err: "No body"}}) }
|
if(!req.body){ return cb({headers: reply.headers, body: {err: "No body"}}) }
|
||||||
//Gun.log("\n\ntran.put ----------------->", req.body);
|
//Gun.log("\n\ntran.put ----------------->", req.body);
|
||||||
if(Gun.is.graph(req.body)){
|
if(Gun.is.graph(req.body)){
|
||||||
if(req.err = Gun.union(gun, req.body, function(err, ctx){ // TODO: BUG? Probably should give me ctx.graph
|
if(req.err = Gun.union(gun, req.body, function(err, ctx){ // TODO: BUG? Probably should give me ctx.graph
|
||||||
if(err){ return cb({headers: reply.headers, body: {err: err || "Union failed."}}) }
|
if(err){ return cb({headers: reply.headers, body: {err: err || "Union failed."}}) }
|
||||||
@ -270,4 +272,4 @@
|
|||||||
gun.__.opt.wire = driver;
|
gun.__.opt.wire = driver;
|
||||||
gun.opt({wire: driver}, true);
|
gun.opt({wire: driver}, true);
|
||||||
});
|
});
|
||||||
}({}));
|
}({}));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gun",
|
"name": "gun",
|
||||||
"version": "0.3.995",
|
"version": "0.3.996",
|
||||||
"description": "Graph engine",
|
"description": "Graph engine",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user