super.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. ;(function(){
  2. var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
  3. var Rad = (Gun.window||{}).Radix || require('./radix');
  4. /// Store the subscribes
  5. Gun.subs = Rad();
  6. function input(msg){
  7. var at = this.as, to = this.to, peer = (msg._||empty).via;
  8. var get = msg.get, soul, key;
  9. if(!peer || !get){ return to.next(msg) }
  10. // console.log("super", msg);
  11. if(soul = get['#']){
  12. if(key = get['.']){
  13. } else {
  14. }
  15. if (!peer.id) {console.log('[*** WARN] no peer.id %s', soul);}
  16. var subs = Gun.subs(soul) || null;
  17. var tmp = subs ? subs.split(',') : [], p = at.opt.peers;
  18. if (subs) {
  19. Gun.obj.map(subs.split(','), function(peerid) {
  20. if (peerid in p) { tmp.push(peerid); }
  21. });
  22. }
  23. if (tmp.indexOf(peer.id) === -1) { tmp.push(peer.id);}
  24. tmp = tmp.join(',');
  25. Gun.subs(soul, tmp);
  26. var dht = {};
  27. dht[soul] = tmp;
  28. at.opt.mesh.say({dht:dht}, peer);
  29. }
  30. to.next(msg);
  31. }
  32. var empty = {}, u;
  33. if(Gun.window){ return }
  34. try{module.exports = input}catch(e){}
  35. }());