Skip to content

Commit

Permalink
πŸ› [Frontend] Fix: Unique session id (#6335)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Sep 10, 2024
1 parent a3b8340 commit 891312a
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,30 @@ qx.Class.define("osparc.utils.Utils", {
}
},

// Function that creates a unique tabId even for duplicated tabs
getClientSessionID: function() {
// https://stackoverflow.com/questions/11896160/any-way-to-identify-browser-tab-in-javascript
const clientSessionID = sessionStorage.getItem("clientsessionid") ? sessionStorage.getItem("clientsessionid") : osparc.utils.Utils.uuidV4();
sessionStorage.setItem("clientsessionid", clientSessionID);
return clientSessionID;
const getUniqueSessionId = () => {
const uuid = osparc.utils.Utils.uuidV4();
// Set window.name. This property is persistent on window reloads, but it doesn't get copied in a duplicated tab
window.name = uuid;
sessionStorage.setItem("clientsessionid", uuid);
return uuid;
};

let uniqueSessionId = sessionStorage.getItem("clientsessionid");
if (uniqueSessionId) {
// Check if the tab was duplicated
// window.name is one of the few things it doesn't get copied, but persists on window reload
if (window.name !== uniqueSessionId) {
// Tab has been duplicated, generate a new uniqueId for the duplicated tab
uniqueSessionId = getUniqueSessionId();
}
} else {
// If no tabId exists in sessionStorage, generate one
uniqueSessionId = getUniqueSessionId();
}

return uniqueSessionId;
},

getFreeDistanceToWindowEdges: function(layoutItem) {
Expand Down

0 comments on commit 891312a

Please sign in to comment.