mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00

TODO: 1) if the peer change the id, will lost the subscribes. Workaround for this is set the pid (unique) in: Gun(pid: 'mypeerid', peers:[...]) 2) If the superpeer die, the subscribes will be lost. Each peer must resubscribe all souls.
30 lines
931 B
JavaScript
30 lines
931 B
JavaScript
;(function(){
|
|
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
|
|
var Rad = (Gun.window||{}).Radix || require('./radix');
|
|
function input(msg){
|
|
var at = this.as, to = this.to, peer = (msg.mesh||empty).via;
|
|
var get = msg.get, soul, key;
|
|
if(!peer || !get){ return to.next(msg) }
|
|
console.log("super", msg);
|
|
if(soul = get['#']){
|
|
if(key = get['.']){
|
|
|
|
} else {
|
|
|
|
}
|
|
subscribe(soul, peer, msg);
|
|
}
|
|
to.next(msg);
|
|
}
|
|
/// Store the subscribes
|
|
Gun.subscribe = {}; /// TODO: use Rad instead of plain object?
|
|
function subscribe(soul, peer, msg) {
|
|
if (!peer.id) { console.log('super jump peer without id: ', peer, msg); return; } /// TODO: this occurs in first subscription. Use peer reference or peer.wire.id?
|
|
Gun.subscribe[soul] = Gun.subscribe[soul] || {};
|
|
Gun.subscribe[soul][peer.id] = 1;
|
|
}
|
|
var empty = {}, u;
|
|
if(Gun.window){ return }
|
|
try{module.exports = input}catch(e){}
|
|
}());
|