diff --git a/website/client/js/services/pusherService.js b/website/client/js/services/pusherService.js index c4e387dbc3..a8eec49a66 100644 --- a/website/client/js/services/pusherService.js +++ b/website/client/js/services/pusherService.js @@ -13,14 +13,17 @@ 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, reconnecting) { - 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 +43,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); @@ -130,11 +132,8 @@ 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, true); - } + connectToPusher(partyId, true); }; $(document).on('mousemove keydown mousedown touchstart', awaitActivity); @@ -153,22 +152,23 @@ angular.module('habitrpg') partyId = user && $rootScope.user.party && $rootScope.user.party._id; if (!partyId) return; + // 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, true); - } - }, 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, true); + // } + // }, Math.floor(Math.random() * 501) + 100); + // } + // }); }); return api;