From 6d54f0df0989888a84a9b2c07f30c13cffb42056 Mon Sep 17 00:00:00 2001 From: Miroslav Pejic Date: Mon, 21 Oct 2024 14:38:46 +0200 Subject: [PATCH] [mirotalksfu] - improvements for mobile --- public/js/WhoAreYou.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/public/js/WhoAreYou.js b/public/js/WhoAreYou.js index 5e12de1a..227a5991 100644 --- a/public/js/WhoAreYou.js +++ b/public/js/WhoAreYou.js @@ -10,6 +10,8 @@ console.log('Settings', settings); const autoJoinRoom = false; // automatically join the guest to the meeting +const intervalTime = 5000; // check room status every 5 seconds + const presenterLoginBtn = document.getElementById('presenterLoginButton'); const guestJoinRoomBtn = document.getElementById('guestJoinRoomButton'); @@ -18,6 +20,7 @@ guestJoinRoomBtn.classList.add('disabled'); const pathParts = window.location.pathname.split('/'); const roomId = filterXSS(pathParts[pathParts.length - 1]); +let intervalId; let roomActive = false; presenterLoginBtn.onclick = () => { @@ -74,4 +77,36 @@ checkRoomStatus(roomId); mediaQuery.addEventListener('change', handleScreenResize); -setInterval(() => checkRoomStatus(roomId), 5000); // Start checking room status every 5 seconds +function startCheckingRoomStatus() { + // Function to run every 5 seconds + intervalId = setInterval(() => { + if (document.visibilityState === 'visible') { + checkRoomStatus(roomId); + } + }, intervalTime); +} + +// Fallback to setTimeout if needed for better control +function fallbackCheckRoomStatus() { + if (document.visibilityState === 'visible') { + checkRoomStatus(roomId); + } + setTimeout(fallbackCheckRoomStatus, intervalTime); +} + +// Use Page Visibility API to pause/resume the checks +document.addEventListener('visibilitychange', () => { + checkRoomStatus(roomId); + // + if (document.visibilityState === 'visible') { + console.log('Page is visible. Resuming room status checks.'); + if (!intervalId) startCheckingRoomStatus(); + } else { + console.log('Page is hidden. Pausing room status checks.'); + clearInterval(intervalId); + intervalId = null; + } +}); + +// Start checking room status when the page is first loaded +startCheckingRoomStatus();