From 6c19367716c8aeaf84b97ac4be3364c50c29b1ca Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Fri, 12 Sep 2025 07:26:10 +0000 Subject: [PATCH] enhanced vodia switcher to add more caching and care about the browser visibility --- public/assets/js/xinon-vodia-identity.js | 310 ++++++++++++----------- 1 file changed, 169 insertions(+), 141 deletions(-) diff --git a/public/assets/js/xinon-vodia-identity.js b/public/assets/js/xinon-vodia-identity.js index a65dcf2a3..90dff78a3 100644 --- a/public/assets/js/xinon-vodia-identity.js +++ b/public/assets/js/xinon-vodia-identity.js @@ -38,12 +38,13 @@ document.body.insertAdjacentHTML('beforeend', ` `); class VodiaIdentitySwitcher { + // --- Configuration --- API_BASE_URL = window.baseurl || '/'; - POLLING_INTERVAL_MS = 60000; - CACHE_DURATION_MS = 60000; + CACHE_DURATION_MS = 60000; // 60 seconds + LOCK_TIMEOUT_MS = 5000; // 5 seconds for a request to complete + CACHE_KEY = 'vodiaIdentityCache'; - LOADING_CACHE_KEY = 'vodiaIdentityCache_loading'; - LOADING_TIMEOUT_MS = 2000; + LOCK_KEY = 'vodiaIdentityCache_lock'; TEXT = { checking: "Prüfe...", @@ -52,52 +53,41 @@ class VodiaIdentitySwitcher { ownExtension: "Eigene Nummer", customIdentity: "Andere Nummer", noActiveCall: "Kein aktiver Anruf gefunden.", - lookupError: "Fehler bei der Anrufabfrage." + lookupError: "Fehler bei der Anrufabfrage.", + fetchError: "Fehler" }; - pollingTimer = null; + // --- State --- elements = {}; templates = {}; constructor(parentElement) { if (!parentElement) return; - - this.templates.main = document.getElementById('vodia-identity-template'); - this.templates.listItem = document.getElementById('vodia-list-item-template'); - - if (!this.templates.main || !this.templates.listItem) { - return console.error("Vodia Switcher Error: Required HTML