import { useCallback, useSyncExternalStore } from 'react'; import { backgroundAudioController } from '../lib/backgroundAudioController'; export function useGlobalAudioMute() { const subscribe = useCallback( (listener: () => void) => backgroundAudioController.subscribe(listener), [], ); const isMuted = useSyncExternalStore( subscribe, () => backgroundAudioController.isMuted(), () => true, ); const setMuted = useCallback((muted: boolean) => { backgroundAudioController.setMuted(muted); }, []); const toggleMuted = useCallback(() => { backgroundAudioController.toggleMuted(); }, []); return { isMuted, setMuted, toggleMuted }; } export default useGlobalAudioMute;