Skip to content

Commit

Permalink
fix: improve fullscreen detection
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Apr 21, 2022
1 parent 43a222b commit 28f6ba4
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const resolveAddress = async () => {
return getAddressWithIframe();
};

let interval: ReturnType<typeof setTimeout>;
let interval: ReturnType<typeof setTimeout> | undefined;
let api: SteelSeriesApi;

const reloadApi = async () => {
Expand Down Expand Up @@ -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;
}
});

Expand Down

0 comments on commit 28f6ba4

Please sign in to comment.