mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
disable limit of 1 tab per browser connected to pusher
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user