mirror of
https://github.com/amark/gun.git
synced 2025-06-07 22:56:42 +00:00
fix long streaming timeout/expiry issue, update examples
This commit is contained in:
parent
2cb414cbde
commit
ad3ecf68c3
@ -9,14 +9,9 @@
|
|||||||
<script>
|
<script>
|
||||||
var gun = Gun(location.origin + '/gun');
|
var gun = Gun(location.origin + '/gun');
|
||||||
|
|
||||||
var to, paste = gun.get('test').get('paste').on(function(data){
|
|
||||||
$('textarea').val(data);
|
|
||||||
})
|
|
||||||
|
|
||||||
$('textarea').on('input change blur keyup mouseup touchend', function(){
|
$('textarea').on('input change blur keyup mouseup touchend', function(){
|
||||||
clearTimeout(to); // debounce
|
gun.get('test').get('paste').put($('textarea').val())
|
||||||
to = setTimeout(function(){
|
});
|
||||||
paste.put($('textarea').val());
|
|
||||||
}, 100);
|
gun.get('test').get('paste').on(data => $('textarea').val(data))
|
||||||
})
|
|
||||||
</script>
|
</script>
|
@ -60,7 +60,7 @@ $('#add').on('submit', function(event){
|
|||||||
if(!(event.what = what.value)){ return err.innerText = "No description!" }
|
if(!(event.what = what.value)){ return err.innerText = "No description!" }
|
||||||
if(!(event.where = where.value)){ return err.innerText = "No location!" }
|
if(!(event.where = where.value)){ return err.innerText = "No location!" }
|
||||||
var day = gun.get(name+now(event.when));
|
var day = gun.get(name+now(event.when));
|
||||||
day.get(id.value || Gun.text.random(9)).put(event);
|
day.get(id.value || String.random(9)).put(event);
|
||||||
what.value = where.value = id.value = err.innerText = '';
|
what.value = where.value = id.value = err.innerText = '';
|
||||||
go.value = 'add';
|
go.value = 'add';
|
||||||
schedule(event.when);
|
schedule(event.when);
|
||||||
|
@ -10,12 +10,12 @@
|
|||||||
</center>
|
</center>
|
||||||
|
|
||||||
<script src="../jquery.js"></script>
|
<script src="../jquery.js"></script>
|
||||||
|
<script src="../../../gun/lib/yson.js"></script>
|
||||||
<script src="../../../gun/gun.js"></script>
|
<script src="../../../gun/gun.js"></script>
|
||||||
<script src="../../../gun/lib/upload.js"></script>
|
<script src="../../../gun/lib/upload.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var gun = Gun(location.origin + '/gun');
|
var gun = Gun('http://localhost:8765/gun');
|
||||||
|
|
||||||
$('html').upload(function resize(eve, up){
|
$('html').upload(function resize(eve, up){
|
||||||
if(up){ return up.shrink(eve, resize, 1024) }
|
if(up){ return up.shrink(eve, resize, 1024) }
|
||||||
var b64 = (eve.base64 || ((eve.event || eve).target || eve).result || eve);
|
var b64 = (eve.base64 || ((eve.event || eve).target || eve).result || eve);
|
||||||
|
3
gun.js
3
gun.js
@ -1369,6 +1369,7 @@
|
|||||||
if(peer === meta.via){ return false } // don't send back to self.
|
if(peer === meta.via){ return false } // don't send back to self.
|
||||||
if((tmp = meta.yo) && (tmp[peer.url] || tmp[peer.pid] || tmp[peer.id]) /*&& !o*/){ return false }
|
if((tmp = meta.yo) && (tmp[peer.url] || tmp[peer.pid] || tmp[peer.id]) /*&& !o*/){ return false }
|
||||||
console.STAT && console.STAT(S, ((DBG||meta).yp = +new Date) - (meta.y || S), 'say prep');
|
console.STAT && console.STAT(S, ((DBG||meta).yp = +new Date) - (meta.y || S), 'say prep');
|
||||||
|
ack && dup_track(ack); // streaming long responses needs to keep alive the ack.
|
||||||
if(peer.batch){
|
if(peer.batch){
|
||||||
peer.tail = (tmp = peer.tail || 0) + raw.length;
|
peer.tail = (tmp = peer.tail || 0) + raw.length;
|
||||||
if(peer.tail <= opt.pack){
|
if(peer.tail <= opt.pack){
|
||||||
@ -1598,7 +1599,7 @@
|
|||||||
var opt = root.opt, graph = root.graph, acks = [], disk, to;
|
var opt = root.opt, graph = root.graph, acks = [], disk, to;
|
||||||
if(false === opt.localStorage){ return }
|
if(false === opt.localStorage){ return }
|
||||||
opt.prefix = opt.file || 'gun/';
|
opt.prefix = opt.file || 'gun/';
|
||||||
try{ disk = lg[opt.prefix] = lg[opt.prefix] || JSON.parse(store.getItem(opt.prefix)) || {};
|
try{ disk = lg[opt.prefix] = lg[opt.prefix] || JSON.parse(store.getItem(opt.prefix)) || {}; // TODO: Perf! This will block, should we care, since limited to 5MB anyways?
|
||||||
}catch(e){ disk = lg[opt.prefix] = {}; }
|
}catch(e){ disk = lg[opt.prefix] = {}; }
|
||||||
|
|
||||||
root.on('get', function(msg){
|
root.on('get', function(msg){
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
var yson = {}, u, sI = setTimeout.turn || (typeof setImmediate != ''+u && setImmediate) || setTimeout;
|
var yson = {}, u, sI = setTimeout.turn || (typeof setImmediate != ''+u && setImmediate) || setTimeout;
|
||||||
|
|
||||||
yson.parseAsync = function(text, done, revive, M){
|
yson.parseAsync = function(text, done, revive, M){
|
||||||
//try{done(u, JSON.parse(text, revive))}catch(e){console.log('%',e);done(e)}return;
|
|
||||||
//console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
|
|
||||||
if('string' != typeof text){ try{ done(u,JSON.parse(text)) }catch(e){ done(e) } return }
|
if('string' != typeof text){ try{ done(u,JSON.parse(text)) }catch(e){ done(e) } return }
|
||||||
var ctx = {i: 0, text: text, done: done, l: text.length, up: []};
|
var ctx = {i: 0, text: text, done: done, l: text.length, up: []};
|
||||||
//M = 1024 * 1024 * 100;
|
//M = 1024 * 1024 * 100;
|
||||||
|
@ -72,7 +72,7 @@ describe("Put ACK", function(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(port, " connect to ", peers);
|
console.log(port, " connect to ", peers);
|
||||||
var gun = Gun({file: env.i+'data', peers: peers, web: server});
|
var gun = Gun({file: env.i+'data', peers: peers, web: server, axe: false}); // not working with axe currently!
|
||||||
server.listen(port, function(){
|
server.listen(port, function(){
|
||||||
test.done();
|
test.done();
|
||||||
});
|
});
|
||||||
@ -119,8 +119,8 @@ describe("Put ACK", function(){
|
|||||||
ref.hear = ref.hear || [];
|
ref.hear = ref.hear || [];
|
||||||
var hear = ref._.root.opt.mesh.hear;
|
var hear = ref._.root.opt.mesh.hear;
|
||||||
ref._.root.opt.mesh.hear = function(raw, peer){
|
ref._.root.opt.mesh.hear = function(raw, peer){
|
||||||
var msg = Gun.obj.ify(raw);
|
|
||||||
console.log('hear:', msg);
|
console.log('hear:', msg);
|
||||||
|
var msg = JSON.parse(raw);
|
||||||
hear(raw, peer);
|
hear(raw, peer);
|
||||||
ref.hear.push(msg);
|
ref.hear.push(msg);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ describe("Put ACK", function(){
|
|||||||
var yes = say(raw, peer);
|
var yes = say(raw, peer);
|
||||||
if(yes === false){ return }
|
if(yes === false){ return }
|
||||||
console.log("say:", msg, yes);
|
console.log("say:", msg, yes);
|
||||||
(ref.say || (ref.say = [])).push(Gun.obj.ify(msg));
|
(ref.say || (ref.say = [])).push(JSON.parse(msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {acks: config.servers});
|
}, {acks: config.servers});
|
||||||
@ -154,7 +154,7 @@ describe("Put ACK", function(){
|
|||||||
ref.hear = ref.hear || [];
|
ref.hear = ref.hear || [];
|
||||||
var hear = ref._.root.opt.mesh.hear;
|
var hear = ref._.root.opt.mesh.hear;
|
||||||
ref._.root.opt.mesh.hear = function(raw, peer){
|
ref._.root.opt.mesh.hear = function(raw, peer){
|
||||||
var msg = Gun.obj.ify(raw);
|
var msg = JSON.parse(raw);
|
||||||
console.log('hear:', msg);
|
console.log('hear:', msg);
|
||||||
hear(raw, peer);
|
hear(raw, peer);
|
||||||
ref.hear.push(msg);
|
ref.hear.push(msg);
|
||||||
|
@ -3,7 +3,7 @@ var config = {
|
|||||||
port: 8765,
|
port: 8765,
|
||||||
servers: 1,
|
servers: 1,
|
||||||
browsers: 2, //3,
|
browsers: 2, //3,
|
||||||
each: 10000,
|
each: 100000,
|
||||||
wait: 1,
|
wait: 1,
|
||||||
route: {
|
route: {
|
||||||
'/': __dirname + '/index.html',
|
'/': __dirname + '/index.html',
|
||||||
@ -104,7 +104,7 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.servers +"
|
|||||||
});
|
});
|
||||||
|
|
||||||
it(config.browsers +" browser(s) have joined!", function(){
|
it(config.browsers +" browser(s) have joined!", function(){
|
||||||
console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
|
require('./util/open').web(config.browsers, "http://"+ config.IP +":"+ config.port); //console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
|
||||||
return browsers.atLeast(config.browsers);
|
return browsers.atLeast(config.browsers);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -127,15 +127,17 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.servers +"
|
|||||||
it("Carl Create Chats", function(){
|
it("Carl Create Chats", function(){
|
||||||
return carl.run(function(test){
|
return carl.run(function(test){
|
||||||
console.log("I AM CARL");
|
console.log("I AM CARL");
|
||||||
|
$('body').append("<div>CPU turns stacked: <u></u> <button onclick='this.innerText = Math.random();'>Can you click me?</button><input id='msg' style='width:100%;'><b></b></div>");
|
||||||
test.async();
|
test.async();
|
||||||
var rand = String.random || Gun.text.random;
|
var rand = String.random || Gun.text.random;
|
||||||
var i = test.props.each, chat = {}, S = Gun.state();
|
var i = test.props.each, chat = {}, S = Gun.state();
|
||||||
while(i--){
|
while(i--){
|
||||||
Gun.state.ify(chat, rand(9), S, rand(200), 'chat');
|
Gun.state.ify(chat, i+'-'+rand(9), S, rand(200), 'chat');
|
||||||
}
|
}
|
||||||
//window.chat = chat;
|
//window.chat = chat;
|
||||||
gun._.graph.chat = chat;
|
gun._.graph.chat = chat;
|
||||||
console.log(JSON.stringify(chat,null,2));
|
//console.log(JSON.stringify(chat,null,2));
|
||||||
|
setInterval(function(){ $('u').text(setTimeout.turn.s.length) },1000);
|
||||||
test.done();
|
test.done();
|
||||||
}, config);
|
}, config);
|
||||||
});
|
});
|
||||||
@ -155,7 +157,8 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.servers +"
|
|||||||
I = ++i;
|
I = ++i;
|
||||||
//console.log(i, "chat:",k,v);
|
//console.log(i, "chat:",k,v);
|
||||||
if(i === t){
|
if(i === t){
|
||||||
$('b').text("seconds from start to end: " + ((+new Date - SS)/1000));
|
console.log(tmp = "seconds from start to end: " + (tmp = ((+new Date - SS)/1000)) + ", roughly " + (t/tmp) + "ops/sec.");
|
||||||
|
$('b').text(tmp);
|
||||||
setTimeout(function(){ test.done() },100);
|
setTimeout(function(){ test.done() },100);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -171,7 +174,7 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.servers +"
|
|||||||
|
|
||||||
after("Everything shut down.", function(){
|
after("Everything shut down.", function(){
|
||||||
// which is to shut down all the browsers.
|
// which is to shut down all the browsers.
|
||||||
browsers.run(function(){
|
require('./util/open').cleanup() || browsers.run(function(){
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
location.reload();
|
location.reload();
|
||||||
}, 15 * 1000);
|
}, 15 * 1000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user