Schafkopf-Server/Public/storage.js
2022-10-13 09:13:16 +02:00

57 lines
1.3 KiB
JavaScript

// Local storage element identifiers
const localStorageTokenId = "token";
const localStoragePlayerName = "name";
const localStorageTableId = "table";
// Can prevent loading of session token, to allow multiple players per browser
const debugMode = false
/*
* Store the player name and session token in local storage.
* Parameter name: The user name of the player
* Parameter token: The session token for the player session
*/
function storePlayerNameAndToken(name, token) {
storePlayerName(name);
storeSessionToken(token);
}
function storePlayerName(name) {
localStorage.setItem(localStoragePlayerName, name);
}
function loadPlayerName() {
return localStorage.getItem(localStoragePlayerName);
}
function deletePlayerName() {
localStorage.removeItem(localStoragePlayerName);
}
/*
* Get the last session token from local storage.
*/
function loadSessionToken() {
return localStorage.getItem(localStorageTokenId)
}
function storeSessionToken(token) {
localStorage.setItem(localStorageTokenId, token)
}
function deleteSessionToken() {
localStorage.removeItem(localStorageTokenId);
}
function storeTableId(table) {
localStorage.setItem(localStorageTableId, table);
}
function getTableId() {
return localStorage.getItem(localStorageTableId);
}
function deleteTableId() {
localStorage.removeItem(localStorageTableId);
}