mirror of
https://github.com/amark/gun.git
synced 2025-07-05 04:12:32 +00:00
of course it'll dedup cause it just called track on hear, fix
This commit is contained in:
parent
7abab818ed
commit
fd1bd507b9
@ -9,26 +9,27 @@
|
|||||||
<p>Drag & drop videos, songs, or images! <input id="upload" type="file" multiple></p>
|
<p>Drag & drop videos, songs, or images! <input id="upload" type="file" multiple></p>
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
<script src="../jquery.js"></script>
|
|
||||||
<script src="../../../gun/lib/yson.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/dom.js"></script>
|
||||||
<script src="../../../gun/lib/upload.js"></script>
|
<script src="../../../gun/lib/upload.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var gun = Gun('http://localhost:8765/gun');
|
gun = GUN(location.origin + '/gun');
|
||||||
|
|
||||||
$('html, #upload').upload(function resize(eve, up){
|
$('html, #upload').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); // which one? try all!
|
||||||
gun.get('test').get(eve.id).put(b64);
|
gun.get('test').get((eve.id+(new Date).getUTCSeconds()) % 60).put(b64); // limit uploads to 1 of 60 slots.
|
||||||
});
|
});
|
||||||
|
|
||||||
gun.get('test').map().on(function(data){
|
gun.get('test').map().on(function(data){
|
||||||
if(!data){ return }
|
if("string" != typeof data){ return }
|
||||||
var type = data.split(';')[0], ui;
|
var type = data.split(';')[0], ui;
|
||||||
if(type.indexOf('image') + 1){ ui = $("img").get(0) }
|
if(type.indexOf('image') + 1){ ui = $("img").get(0) }
|
||||||
if(type.indexOf('video') + 1){ ui = $('video').get(0) }
|
if(type.indexOf('video') + 1){ ui = $('video').get(0) }
|
||||||
if(type.indexOf('audio') + 1){ ui = $('audio').get(0) }
|
if(type.indexOf('audio') + 1){ ui = $('audio').get(0) }
|
||||||
if(!ui){ return }
|
if(!ui){ return }
|
||||||
$(ui).clone().prependTo('center').get(0).src = data;
|
$(ui).clone().prependTo('center').get(0).src = data;
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
12
gun.js
12
gun.js
@ -1393,9 +1393,6 @@
|
|||||||
!loop && dup_track(id);//.it = it(msg); // track for 9 seconds, default. Earth<->Mars would need more! // always track, maybe move this to the 'after' logic if we split function.
|
!loop && dup_track(id);//.it = it(msg); // track for 9 seconds, default. Earth<->Mars would need more! // always track, maybe move this to the 'after' logic if we split function.
|
||||||
if(msg.put && (msg.err || (dup.s[id]||'').err)){ return false } // TODO: in theory we should not be able to stun a message, but for now going to check if it can help network performance preventing invalid data to relay.
|
if(msg.put && (msg.err || (dup.s[id]||'').err)){ return false } // TODO: in theory we should not be able to stun a message, but for now going to check if it can help network performance preventing invalid data to relay.
|
||||||
if(!(hash = msg['##']) && u !== msg.put && !meta.via && ack){ mesh.hash(msg, peer); return } // TODO: Should broadcasts be hashed?
|
if(!(hash = msg['##']) && u !== msg.put && !meta.via && ack){ mesh.hash(msg, peer); return } // TODO: Should broadcasts be hashed?
|
||||||
DBG && (DBG.yh = +new Date);
|
|
||||||
if(!(raw = meta.raw)){ mesh.raw(msg, peer); return }
|
|
||||||
DBG && (DBG.yr = +new Date);
|
|
||||||
if(!peer && ack){ peer = ((tmp = dup.s[ack]) && (tmp.via || ((tmp = tmp.it) && (tmp = tmp._) && tmp.via))) || ((tmp = mesh.last) && ack === tmp['#'] && mesh.leap) } // warning! mesh.leap could be buggy! mesh last check reduces this.
|
if(!peer && ack){ peer = ((tmp = dup.s[ack]) && (tmp.via || ((tmp = tmp.it) && (tmp = tmp._) && tmp.via))) || ((tmp = mesh.last) && ack === tmp['#'] && mesh.leap) } // warning! mesh.leap could be buggy! mesh last check reduces this.
|
||||||
if(!peer && ack){ // still no peer, then ack daisy chain lost.
|
if(!peer && ack){ // still no peer, then ack daisy chain lost.
|
||||||
if(dup.s[ack]){ return } // in dups but no peer hints that this was ack to self, ignore.
|
if(dup.s[ack]){ return } // in dups but no peer hints that this was ack to self, ignore.
|
||||||
@ -1403,6 +1400,9 @@
|
|||||||
return false;
|
return false;
|
||||||
} // TODO: Temporary? If ack via trace has been lost, acks will go to all peers, which trashes browser bandwidth. Not relaying the ack will force sender to ask for ack again. Note, this is technically wrong for mesh behavior.
|
} // TODO: Temporary? If ack via trace has been lost, acks will go to all peers, which trashes browser bandwidth. Not relaying the ack will force sender to ask for ack again. Note, this is technically wrong for mesh behavior.
|
||||||
if(!peer && mesh.way){ return mesh.way(msg) }
|
if(!peer && mesh.way){ return mesh.way(msg) }
|
||||||
|
DBG && (DBG.yh = +new Date);
|
||||||
|
if(!(raw = meta.raw)){ mesh.raw(msg, peer); return }
|
||||||
|
DBG && (DBG.yr = +new Date);
|
||||||
if(!peer || !peer.id){
|
if(!peer || !peer.id){
|
||||||
if(!Object.plain(peer || opt.peers)){ return false }
|
if(!Object.plain(peer || opt.peers)){ return false }
|
||||||
var S = +new Date;
|
var S = +new Date;
|
||||||
@ -1421,7 +1421,7 @@
|
|||||||
console.STAT && console.STAT(S, +new Date - S, 'say loop');
|
console.STAT && console.STAT(S, +new Date - S, 'say loop');
|
||||||
if(!pl.length){ return }
|
if(!pl.length){ return }
|
||||||
puff(go, 0);
|
puff(go, 0);
|
||||||
dup_track(ack); // keep for later
|
ack && dup_track(ack); // keep for later
|
||||||
}());
|
}());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1431,7 +1431,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.
|
!loop && 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){
|
||||||
@ -1458,7 +1458,7 @@
|
|||||||
if('string' == typeof msg){ return msg }
|
if('string' == typeof msg){ return msg }
|
||||||
var hash = msg['##'], ack = msg['@'];
|
var hash = msg['##'], ack = msg['@'];
|
||||||
if(hash && ack){
|
if(hash && ack){
|
||||||
if(dup_check(ack+hash)){ return false } // memory & storage may ack the same thing, this dedups that. //dup_track(ack+hash);//.it = it(msg);
|
if(!meta.via && dup_check(ack+hash)){ return false } // for our own out messages, memory & storage may ack the same thing, so dedup that. Tho if via another peer, we already tracked it upon hearing, so this will always trigger false positives, so don't do that!
|
||||||
if((tmp = (dup.s[ack]||'').it) || ((tmp = mesh.last) && ack === tmp['#'])){
|
if((tmp = (dup.s[ack]||'').it) || ((tmp = mesh.last) && ack === tmp['#'])){
|
||||||
if(hash === tmp['##']){ return false } // if ask has a matching hash, acking is optional.
|
if(hash === tmp['##']){ return false } // if ask has a matching hash, acking is optional.
|
||||||
if(!tmp['##']){ tmp['##'] = hash } // if none, add our hash to ask so anyone we relay to can dedup. // NOTE: May only check against 1st ack chunk, 2nd+ won't know and still stream back to relaying peers which may then dedup. Any way to fix this wasted bandwidth? I guess force rate limiting breaking change, that asking peer has to ask for next lexical chunk.
|
if(!tmp['##']){ tmp['##'] = hash } // if none, add our hash to ask so anyone we relay to can dedup. // NOTE: May only check against 1st ack chunk, 2nd+ won't know and still stream back to relaying peers which may then dedup. Any way to fix this wasted bandwidth? I guess force rate limiting breaking change, that asking peer has to ask for next lexical chunk.
|
||||||
|
61
lib/dom.js
61
lib/dom.js
@ -1,13 +1,12 @@
|
|||||||
;(function(){ // jQuery shim
|
;(function(){ // jQuery shim
|
||||||
// u = undefined, n = null, b = boolean = true/false, n = number, t = text, l = list = array, o = object, cb = callback = function, q = CSS query, k = key, eve = event.
|
// u = undefined, n = null, b = boolean = true/false, n = number, t = text, l = list = array, o = object, cb = callback = function, q = query CSS, k = key, eve = event.
|
||||||
if(window.$){ return }
|
if(window.$){ return }
|
||||||
(($ = window.$ = function(q, tag){
|
(($ = window.$ = function(q, tag, I, u){
|
||||||
if(q instanceof $){ return q }
|
if(q instanceof $){ return q }
|
||||||
if(!(this instanceof $)){ return new $(q, tag) }
|
if(!((I = this) instanceof $)){ return new $(q, tag) }
|
||||||
this.tags = ((q && q.tags)
|
if('string' != typeof q){ return I.tags = (q = q||[]).tags || (u === q.length)? [q] : q, I }
|
||||||
|| (('string' != typeof q)? (q?[q]:[])
|
if('<' === q[0]){ return I.add(q) }
|
||||||
: (tag||document).querySelectorAll(q)));
|
return q.split(",").forEach(function(q){ I.add((tag||document).querySelectorAll(q)) }), I;
|
||||||
return this;
|
|
||||||
}).fn = $.prototype).each = function(cb){ return $.each(this.tags, cb), this }
|
}).fn = $.prototype).each = function(cb){ return $.each(this.tags, cb), this }
|
||||||
$.each = function(o, cb){ Object.keys(o).forEach(function(k){ cb(k, o[k]) }) }
|
$.each = function(o, cb){ Object.keys(o).forEach(function(k){ cb(k, o[k]) }) }
|
||||||
$.isPlainObject = function(o){
|
$.isPlainObject = function(o){
|
||||||
@ -15,6 +14,11 @@
|
|||||||
|| 'Object' === Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1]
|
|| 'Object' === Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1]
|
||||||
: false);
|
: false);
|
||||||
}
|
}
|
||||||
|
$.fn.add = function(add, tmp, u){ if(!add){ return this }
|
||||||
|
if('<' === (tmp = add)[0]){ (add = document.createElement('div')).innerHTML = tmp }
|
||||||
|
add = ('string' == typeof add)? $(add).tags : (u == add.length)? add : [].slice.call(add);
|
||||||
|
return this.tags = [].slice.call(this.tags||[]).concat(add), this;
|
||||||
|
}
|
||||||
$.fn.get = function(i, l, u){ return l = this.tags, (i === u)? l : l[i] }
|
$.fn.get = function(i, l, u){ return l = this.tags, (i === u)? l : l[i] }
|
||||||
$.fn.is = function(q, b){ return this.each(function(i, tag){ b = b || tag.matches(q) }), b }
|
$.fn.is = function(q, b){ return this.each(function(i, tag){ b = b || tag.matches(q) }), b }
|
||||||
$.fn.css = function(o){ return this.each(function(i, tag){ $.each(o, function(k,v){ tag.style[k] = v }) })}
|
$.fn.css = function(o){ return this.each(function(i, tag){ $.each(o, function(k,v){ tag.style[k] = v }) })}
|
||||||
@ -24,40 +28,33 @@
|
|||||||
$.fn.val = function(t, k, f, u){
|
$.fn.val = function(t, k, f, u){
|
||||||
t = (t === u)? '' : (f = 1) && t;
|
t = (t === u)? '' : (f = 1) && t;
|
||||||
k = k || 'value';
|
k = k || 'value';
|
||||||
this.each(function(i, tag){
|
return this.each(function(i, tag){
|
||||||
if(f){ tag[k] = t }
|
if(f){ tag[k] = t }
|
||||||
else { t += (tag[k]||'') }
|
else { t += (tag[k]||'') }
|
||||||
});
|
}), f? this : t;
|
||||||
return f? this : t;
|
|
||||||
}
|
}
|
||||||
$.fn.text = function(t){ return this.val(t, 'textContent') }
|
$.fn.text = function(t){ return this.val(t, 'textContent') }
|
||||||
$.fn.html = function(html){ return this.val(html, 'innerHTML') }
|
$.fn.html = function(html){ return this.val(html, 'innerHTML') }
|
||||||
$.fn.find = function(q){
|
$.fn.find = function(q, I, l){
|
||||||
var I = $(), l = I.tags;
|
I = $(), l = I.tags;
|
||||||
this.each(function(i, tag){
|
return this.each(function(i, tag){
|
||||||
$(q, tag).each(function(i, tag){
|
$(q, tag).each(function(i, tag){
|
||||||
if(0 > l.indexOf(tag)){ l.push(tag) }
|
if(0 > l.indexOf(tag)){ l.push(tag) }
|
||||||
});
|
});
|
||||||
});
|
}), I;
|
||||||
return I;
|
|
||||||
}
|
}
|
||||||
$.fn.add = function(add, tmp){
|
$.fn.place = function(where, on, f, op, I){ return (I = this).each(function(i, tag){ $(on).each(function(i, node){
|
||||||
if(!add){ return this }
|
|
||||||
if('<' === (tmp = add)[0]){ (add = document.createElement('div')).innerHTML = tmp }
|
|
||||||
return this.tags = [].slice.call(this.tags).concat([].slice.call($(add).tags)), this;
|
|
||||||
}
|
|
||||||
$.fn.place = function(where, on, f, op){ return this.each(function(i, tag){ $(on).each(function(i, node){
|
|
||||||
(f? tag : node)[op||'insertAdjacentElement'](({
|
(f? tag : node)[op||'insertAdjacentElement'](({
|
||||||
'-1':'beforebegin', '-0.1': 'afterbegin', '0.1':'beforeend', '1': 'afterend'
|
'-1':'beforebegin', '-0.1': 'afterbegin', '0.1':'beforeend', '1': 'afterend'
|
||||||
})[where], (f? node : tag));
|
})[where], (f? node : tag));
|
||||||
})})}
|
})})}
|
||||||
$.fn.append = function(html){ return $().add(html).place(0.1, this), this }
|
$.fn.append = function(html){ return $(html).place(0.1, this), this }
|
||||||
$.fn.appendTo = function(html){ return this.place(0.1, $().add(html)) }
|
$.fn.appendTo = function(html){ return this.place(0.1, $(html)) }
|
||||||
function rev(o){ var I = $(); I.tags = [].slice.call(o.tags).reverse(); return I }
|
function rev(o, I){ (I = $()).tags = [].slice.call(o.tags).reverse(); return I };
|
||||||
$.fn.prependTo = function(html){ return rev(this).place(-0.1, $().add(html)), this }
|
$.fn.prependTo = function(html){ return rev(this).place(-0.1, $(html)), this }
|
||||||
$.fn.prepend = function(html){ return rev($().add(html)).place(-0.1, this), this }
|
$.fn.prepend = function(html){ return rev($(html)).place(-0.1, this), this }
|
||||||
$.fn.parents = function(q, c){
|
$.fn.parents = function(q, c, I, l, p){
|
||||||
var I = $(), l = I.tags, p = 'parentElement';
|
I = $(), l = I.tags, p = 'parentElement';
|
||||||
this.each(function(i, tag){
|
this.each(function(i, tag){
|
||||||
if(c){ (c = {})[p] = tag ; tag = c }
|
if(c){ (c = {})[p] = tag ; tag = c }
|
||||||
while(tag){ if((tag = tag[p]) && $(tag).is(q)){
|
while(tag){ if((tag = tag[p]) && $(tag).is(q)){
|
||||||
@ -67,5 +64,11 @@
|
|||||||
return I;
|
return I;
|
||||||
}
|
}
|
||||||
$.fn.closest = function(q, c){ return this.parents(q, 1) }
|
$.fn.closest = function(q, c){ return this.parents(q, 1) }
|
||||||
$.fn.clone = function(b){ I = $(), l = I.tags, this.each(function(i, tag){ l.push(tag.cloneNode(true)) }), I }
|
$.fn.clone = function(b, I, l){
|
||||||
|
I = $(), l = I.tags;
|
||||||
|
this.each(function(i, tag){
|
||||||
|
l.push(tag.cloneNode(true))
|
||||||
|
});
|
||||||
|
return I;
|
||||||
|
}
|
||||||
}());
|
}());
|
@ -4,7 +4,7 @@
|
|||||||
opt = $.isPlainObject(opt)? opt : {input: opt};
|
opt = $.isPlainObject(opt)? opt : {input: opt};
|
||||||
el.on('drop', function(e){
|
el.on('drop', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
upload.drop(((e.originalEvent||{}).dataTransfer||{}).files||[], 0);
|
upload.drop(((e.originalEvent||e).dataTransfer||{}).files||[], 0);
|
||||||
}).on('dragover', function(e){
|
}).on('dragover', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user