amark / gun

An open source cybersecurity protocol for syncing decentralized graph data.
https://gun.eco/docs
Other
18.13k stars 1.17k forks source link

Request : global event on connection #213

Closed Stefdv closed 7 years ago

Stefdv commented 8 years ago

It would be helpfull if there was a event we can hook into when a peer is connected or disconnected . usecase:

I made a 'monkey-patch' inside the gun.js file for my specific project. gun.js:

ws.onerror = function(e){ 
                /* Stefdv */
                //var re;
                gun.get('systems').val(function(s){
                    Object.keys(s).forEach(function(sys){
                        re = new RegExp(sys, 'g');
                        if(e.srcElement.url.match(re)){
                            gun.get('systems').path(sys).put('off')
                        }
                    });
                });
            };
            return true;
        }
ws.onopen = function(o){ 
                r.back = 2; 
                r.ws(opt, cb) 
                /** Stefdv **/
                //var re;
                gun.get('systems').val(function(s){
                    Object.keys(s).forEach(function(sys){
                        re = new RegExp(sys, 'g');
                        if(opt.base.match(re)){gun.get('systems').path(sys).put('on')}
                  });
                });
            };
Stefdv commented 8 years ago

might be related to https://github.com/amark/gun/issues/180

amark commented 7 years ago

I still believe that what is discussed in https://github.com/amark/gun/issues/180 is the "right way" to deal with it.

I closed that issue, so I'm gonna close this issue too. However I'm still open to discussion on it, so please just reopen this issue if it is important for you. :) You've been so helpful with everything, so I really do appreciate/respect your input.