nodeca / tabex

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

How can I check browser supported? #13

Closed nicola-spb closed 7 years ago

nicola-spb commented 7 years ago

I initialize socket io on master tab but if tabex is not supported in browser then I should initialize it on every tab. How can I check browser supported? Do you have special method (like isSupported()") or something else? I was looking for the code but didn't find it.

Example:

;var app = (function ($) {

return {
        rt : {
            socket: null,
            tabClient: null,

            initWebSocket: function () {
                // init socket io
            },

            initSocket: function () {

//               if (!browserSupported) {
//                   app.rt.initWebSocket();
//               } else {

                this.tabClient = window.tabex.client();

                // Connect to messaging server when become master and kill connection if master changed
                this.tabClient.on('!sys.master', function (data) {
                    // If new master is in our tab - connect
                    if (data.node_id === data.master_id) {
                        console.log('Connect socket!');
                        if (!app.rt.socket) {
                            app.rt.initWebSocket();
                        }
                        return;
                    }

                    // If new master is in another tab - make sure to destroy zombie connection.
                    if (app.rt.socket) {
                        console.log('Disconnect socket!');
                        app.rt.socket.disconnect();
                        app.rt.socket = null;
                    }
                });

//                }
            }

If browser supported I wanna execute app.rt.initWebSocket() on master tab else on every tab.

puzrin commented 7 years ago

I think you have wrong base assumptions. "tabex not supported" means no shared localstore support or no no localstore support at all. In both cases each tab should work independently (each will behave as master).

If you know conditions when this is wrong - let me know (or close issue).

PS. Short answer is - you can't check because you don't need to do it.

nicola-spb commented 7 years ago

Thank you.