From 28f6ba4362c961c7cd555918cb9be6376fa2b3e5 Mon Sep 17 00:00:00 2001 From: meskill <8974488+meskill@users.noreply.github.com> Date: Thu, 21 Apr 2022 13:29:55 +0000 Subject: [PATCH] fix: improve fullscreen detection --- src/handler.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/handler.ts b/src/handler.ts index bc0dd5c..468de23 100755 --- a/src/handler.ts +++ b/src/handler.ts @@ -37,7 +37,7 @@ const resolveAddress = async () => { return getAddressWithIframe(); }; -let interval: ReturnType; +let interval: ReturnType | undefined; let api: SteelSeriesApi; const reloadApi = async () => { @@ -66,16 +66,20 @@ const sendFullscreen = () => { return sendEvent(() => api.send('game_event', createFullScreenEvent())); }; -document.addEventListener('fullscreenchange', async () => { - if (document.fullscreenElement) { +window.addEventListener('resize', async () => { + const isFullscreen = !!document.fullscreenElement; + const isInProgress = typeof interval !== 'undefined'; + + if (isFullscreen && !isInProgress) { sendFullscreen(); interval = setInterval(() => { sendFullscreen(); }, FULLSCREEN_BACKGROUND_FETCH_INTERNAL); - } else { + } else if (!isFullscreen && isInProgress) { clearInterval(interval); sendEvent(() => api.send('stop_game', { game: GAME_NAME })); + interval = undefined; } });