nodeca / tabex

Cross-tab message bus for browsers.
http://nodeca.github.io/tabex/
MIT License
219 stars 19 forks source link

No way to cleanup the tabex. #16

Open Kukunin opened 7 years ago

Kukunin commented 7 years ago

There is a situation, where tab should be 'disconnected' pragmatically, while page is still loaded. In such case tab shouldn't become a master tab. In this case it'd cool to have some cleanup method: client.disconnect() or so.

Currently, it's possible to workaround with __router__.__destroy__() method, but __router__ has intervals as well, so it still will try to achieve master tab.

puzrin commented 6 years ago

Sorry for silence. Could you clarify and split things by priority?

Kukunin commented 6 years ago

Currently, it's not a blocker for me, so the prioritization is up to you.

I worked around it with the following code:

  cleanupMutex: function() {
    if (this.mutex.__router__.__iframe__) {
      return this.mutex.__router__.__iframe__.remove();
    }
    this.mutex.__router__.__check_master__ = function() {};
    this.mutex.__router__.__destroy__();
    return this.mutex = null;
  }

this.mutex is an instance of tabex's Client.

Kukunin commented 6 years ago

I found a bug in my workaround. If you destroyed the router once, you can reestablish it, because of caching here https://github.com/nodeca/tabex/blob/master/lib/index.js#L38. It will pick the destroyed router instead of creating new one