re-enable limit of 1 tab per user connected to pusher

This commit is contained in:
Matteo Pagliazzi
2016-09-08 18:51:24 +02:00
parent ef73c61e0e
commit d4dc455926

View File

@@ -13,16 +13,14 @@ angular.module('habitrpg')
pusher: undefined, pusher: undefined,
socketId: undefined, // when defined the user is connected socketId: undefined, // when defined the user is connected
}; };
// Limit of 1 connected tab is disabled for now var tabIdKey = 'habitica-active-tab';
// var tabIdKey = 'habitica-active-tab'; var tabId = Shared.uuid();
// var tabId = Shared.uuid();
function connectToPusher (partyId) { function connectToPusher (partyId) {
// Limit of 1 connected tab is disabled for now localStorage.setItem(tabIdKey, tabId);
// localStorage.setItem(tabIdKey, tabId); window.onbeforeunload = function () {
// window.onbeforeunload = function () { localStorage.removeItem(tabIdKey);
// localStorage.removeItem(tabIdKey); }
// }
api.pusher = new Pusher(window.env['PUSHER:KEY'], { api.pusher = new Pusher(window.env['PUSHER:KEY'], {
encrypted: true, encrypted: true,
@@ -113,10 +111,9 @@ angular.module('habitrpg')
var awaitActivity = function() { var awaitActivity = function() {
$(document).off('mousemove keydown mousedown touchstart', awaitActivity); $(document).off('mousemove keydown mousedown touchstart', awaitActivity);
connectToPusher(partyId); connectToPusher(partyId);
// Limit of 1 connected tab is disabled for now if (!localStorage.getItem(tabIdKey) || localStorage.getItem(tabIdKey) === tabId) {
// if (!localStorage.getItem(tabIdKey) || localStorage.getItem(tabIdKey) === tabId) { connectToPusher(partyId);
// connectToPusher(partyId); }
// }
}; };
$(document).on('mousemove keydown mousedown touchstart', awaitActivity); $(document).on('mousemove keydown mousedown touchstart', awaitActivity);
@@ -137,23 +134,22 @@ angular.module('habitrpg')
connectToPusher(partyId); connectToPusher(partyId);
// DISABLED FOR NOW
// See if another tab is already connected to Pusher // See if another tab is already connected to Pusher
// if (!localStorage.getItem(tabIdKey)) { if (!localStorage.getItem(tabIdKey)) {
// connectToPusher(partyId); connectToPusher(partyId);
// } }
// when a tab is closed, connect the next one // when a tab is closed, connect the next one
// wait between 100 and 500ms to avoid two tabs connecting at the same time // wait between 100 and 500ms to avoid two tabs connecting at the same time
// window.addEventListener('storage', function(e) { window.addEventListener('storage', function(e) {
// if (e.key === tabIdKey && e.newValue === null) { if (e.key === tabIdKey && e.newValue === null) {
// setTimeout(function () { setTimeout(function () {
// if (!localStorage.getItem(tabIdKey)) { if (!localStorage.getItem(tabIdKey)) {
// connectToPusher(partyId); connectToPusher(partyId);
// } }
// }, Math.floor(Math.random() * 501) + 100); }, Math.floor(Math.random() * 501) + 100);
// } }
// }); });
}); });
return api; return api;