diff --git a/website/client/js/services/pusherService.js b/website/client/js/services/pusherService.js index 041e389e95..11b1d88d0e 100644 --- a/website/client/js/services/pusherService.js +++ b/website/client/js/services/pusherService.js @@ -13,14 +13,16 @@ angular.module('habitrpg') pusher: undefined, socketId: undefined, // when defined the user is connected }; - var tabIdKey = 'habitica-active-tab'; - var tabId = Shared.uuid(); + // Limit of 1 connected tab is disabled for now + // var tabIdKey = 'habitica-active-tab'; + // var tabId = Shared.uuid(); function connectToPusher (partyId) { - localStorage.setItem(tabIdKey, tabId); - window.onbeforeunload = function () { - localStorage.removeItem(tabIdKey); - } + // Limit of 1 connected tab is disabled for now + // localStorage.setItem(tabIdKey, tabId); + // window.onbeforeunload = function () { + // localStorage.removeItem(tabIdKey); + // } api.pusher = new Pusher(window.env['PUSHER:KEY'], { encrypted: true, @@ -40,7 +42,6 @@ angular.module('habitrpg') var awaitIdle = function() { if(disconnectionTimeout) clearTimeout(disconnectionTimeout); disconnectionTimeout = setTimeout(function () { - console.log('Disconnecting from Pusher.'); $(document).off('mousemove keydown mousedown touchstart', awaitIdle); disconnectPusher(); }, DISCONNECTION_AFTER); @@ -110,15 +111,14 @@ angular.module('habitrpg') api.pusher.disconnect(); var awaitActivity = function() { - console.log('Reconnecting to Pusher.'); $(document).off('mousemove keydown mousedown touchstart', awaitActivity); - if (!localStorage.getItem(tabIdKey) || localStorage.getItem(tabIdKey) === tabId) { - connectToPusher(partyId); - } + // Limit of 1 connected tab is disabled for now + // if (!localStorage.getItem(tabIdKey) || localStorage.getItem(tabIdKey) === tabId) { + // connectToPusher(partyId); + // } }; $(document).on('mousemove keydown mousedown touchstart', awaitActivity); - }; // Setup chat channels once app is ready, only for parties for now @@ -132,24 +132,27 @@ angular.module('habitrpg') // Connect the user to Pusher and to the party's chat channel partyId = user && $rootScope.user.party && $rootScope.user.party._id; - // if (!partyId) return; + if (!partyId) return; + connectToPusher(partyId); + + // DISABLED FOR NOW // See if another tab is already connected to Pusher - if (!localStorage.getItem(tabIdKey)) { - connectToPusher(partyId); - } + // if (!localStorage.getItem(tabIdKey)) { + // connectToPusher(partyId); + // } // when a tab is closed, connect the next one // wait between 100 and 500ms to avoid two tabs connecting at the same time - window.addEventListener('storage', function(e) { - if (e.key === tabIdKey && e.newValue === null) { - setTimeout(function () { - if (!localStorage.getItem(tabIdKey)) { - connectToPusher(partyId); - } - }, Math.floor(Math.random() * 501) + 100); - } - }); + // window.addEventListener('storage', function(e) { + // if (e.key === tabIdKey && e.newValue === null) { + // setTimeout(function () { + // if (!localStorage.getItem(tabIdKey)) { + // connectToPusher(partyId); + // } + // }, Math.floor(Math.random() * 501) + 100); + // } + // }); }); return api;