Skip to content

Commit

Permalink
feat(ui): added visibility change listener to mute sounds when the do…
Browse files Browse the repository at this point in the history
…cument is hidden
  • Loading branch information
wialy committed Mar 28, 2024
1 parent 86c3c91 commit 00051c8
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/features/sound/hooks/use-sounds/use-sounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ export const useSounds = () => {

const { isMuted } = useSoundState();

useEffect(() => {
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
Howler.mute(true);
} else {
Howler.mute(isMuted);
}
});
}, [isMuted]);

useEffect(() => {
Howler.mute(isMuted);
}, [isMuted]);
Expand Down

0 comments on commit 00051c8

Please sign in to comment.