From 7d374037ee2f41636f022a724019f862503e0449 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 27 Jul 2025 19:42:08 -0500 Subject: [PATCH] Play dog whistle sine wave to make persistent notification display on Android --- public/sine.mp3 | Bin 0 -> 120748 bytes src/hooks/useKeepAlive.ts | 138 ++++++++++++++++++++++---------------- 2 files changed, 80 insertions(+), 58 deletions(-) create mode 100644 public/sine.mp3 diff --git a/public/sine.mp3 b/public/sine.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..77c8b97a65c52173b4cff852ee033ed932848904 GIT binary patch literal 120748 zcmeHweUw$zmFIc&Dq2BNG{sj}2-O9>I)h1D4k5%r^U7Bsh}d9aH4xeb(TuFHx*OAK zS7s$E_Z9>rER@a!{94IWAs?Ak95JhUnxyH@t063P%m)Y}vS_<>Sj1N#meB&KSM~0m zeeUy9U${?UKixqI(Vo_+3TegE_42mYo1SBGAF`8S7; zzIx*1segOx^zR4HoqzBB3zsTY>~GnUTkcpe`_FD@ZLR->_md_z&#Zsx7Lj{X{*H@Z zx~}Lo{QvR^qy6}Tu6p$Jb^maU`5&JB{C_qY?-#EP{o|?gqie(sTkoCnLaQ8#=iYsH zXl(xcrImMKZ2nS!4*{0K2T&<@R}28K-i8Cuw6wI$IDkjSmxg@4v$ONT`FP-G=l#w| z=O+AGT$K}7iJrzq^>sotf4uEqKQy23`op#3e|d%3X|`_38`ms+_~6`25OCZoeP}!dO;%xS{b*^x+J^&oe8N1a{+ac-)6ru8mcegH`({oBYvTaezvvxn zA5=?6iu8m0OvM}>*3NB zfSuUKb6U3)n;XQyMPvWSYVY@)kiTcmBZU*zm#gsB&>sfQf-wp(h&Mgq-%@8N>srOt z2JD2FXIH!Nk1L|3&FyJ!rEtu87*>OIcrbEH7@crvP~0+{oAl2@Ojs^jUPn>O?yI9; zY-kZz891;<2L?N_GwVsQHPU%h4D5b3wtq6;*n_Wpu4s8Fs~@ph$Z@*e*jF8o<6UX0 z8ZcVeJMM`J3JiR(dI+FY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nz<ltA>M*CP%zi5?(xg@T$Ho_}bH^#pLTr?=2$b7!W z9FpS;BexoTa^TwP7d2rSvh^2WCniWj=YAi++TkR->LBOmyG*8)f*uIAOPb|&Nwsv& z5yHw2f8CbaUg|gI^Wi|)4FBkc3G?~V4G>I>6Wc9GtHUve$Xno-aJ^lwx7&k;DA(KN zdb?5%xZdtC+Blq_kNJFd8h5U@%lY|iPBbQlJvxLA(2sDL=&QUT3o!%p`NC+Ge%vm_ zDagKA_{Q|Ra=+yN0iUl;Y-kou*0(Bu4imw~tKv9cy8*`l-Dh~m`eAG1m6zpn&;P@k zPfuvbf2U4NKmF#Z{^ojX^7kiS`s{|k`jgUIzx?FS>YL^mpXh38y>{oPKeQ%2|4*AP z&8!pXM{Zv6)aE~))l$6pr#9Xjufx#|m!2BG;l3Ldwmwk*-pWVO;oQ99?r{ezlW&-E z#q&S>?$-9rxbq8d{pJ(7{2w*%gY}ayFMRA912Fd57tVbB<-Hijf74B;ckTV;-#)qVtBVGw zW7l%uEROTRi;sQd*qy)M{^`#*M5Trbh3*x1+!i_Un)-Reb?@)}J9pf)^YeLsSL-K? zwjBa9KOr~yb3)Xahwhu(c%-4$oBX@~dl+p#^nrQB$NT2~e8%6S-TAqVrl|jS{T2Tg DUEW)j literal 0 HcmV?d00001 diff --git a/src/hooks/useKeepAlive.ts b/src/hooks/useKeepAlive.ts index fde4143e..47e0d10e 100644 --- a/src/hooks/useKeepAlive.ts +++ b/src/hooks/useKeepAlive.ts @@ -12,7 +12,7 @@ interface UseKeepAliveOptions { } /** - * Hook to keep the tab alive using a silent sine wave and Media Session API. + * Hook to keep the tab alive using a silent audio element and Media Session API. * This prevents the browser from throttling the tab when the user locks their phone * or navigates away, allowing AI processing to continue in the background. */ @@ -22,50 +22,29 @@ export function useKeepAlive({ artist, artwork = [] }: UseKeepAliveOptions) { - const audioContextRef = useRef(null); - const oscillatorRef = useRef(null); - const gainNodeRef = useRef(null); + const audioElementRef = useRef(null); const isActiveRef = useRef(false); const startKeepAlive = useCallback(async () => { if (isActiveRef.current || !enabled) return; try { - // Create audio context - const AudioContextClass = window.AudioContext || (window as typeof window & { webkitAudioContext?: typeof AudioContext }).webkitAudioContext; - if (!AudioContextClass) { - throw new Error('AudioContext not supported'); - } - audioContextRef.current = new AudioContextClass(); - const audioContext = audioContextRef.current; + // Create audio element and add it to the DOM + audioElementRef.current = document.createElement('audio'); + const audio = audioElementRef.current; - // Resume audio context if suspended (required for user interaction) - if (audioContext.state === 'suspended') { - await audioContext.resume(); - } + // Configure audio element to use the provided audio file + audio.src = '/sine.mp3'; + audio.loop = true; + audio.volume = 0.01; // Very low volume but not completely muted + audio.preload = 'auto'; + audio.style.display = 'none'; // Hide the audio element + audio.setAttribute('aria-hidden', 'true'); // Hide from screen readers - // Create oscillator for silent sine wave - oscillatorRef.current = audioContext.createOscillator(); - gainNodeRef.current = audioContext.createGain(); + // Add to DOM (required for proper media session support) + document.body.appendChild(audio); - const oscillator = oscillatorRef.current; - const gainNode = gainNodeRef.current; - - // Configure oscillator - oscillator.type = 'sine'; - oscillator.frequency.setValueAtTime(20000, audioContext.currentTime); // 20kHz - above human hearing range - - // Set volume to nearly silent but not completely muted - gainNode.gain.setValueAtTime(0.001, audioContext.currentTime); - - // Connect nodes - oscillator.connect(gainNode); - gainNode.connect(audioContext.destination); - - // Start oscillator - oscillator.start(); - - // Set up Media Session API + // Set up Media Session API before playing if ('mediaSession' in navigator) { navigator.mediaSession.metadata = new MediaMetadata({ title, @@ -73,25 +52,72 @@ export function useKeepAlive({ artwork }); - // Set playback state - navigator.mediaSession.playbackState = 'playing'; - // Handle media session actions navigator.mediaSession.setActionHandler('play', () => { - // Already playing, do nothing + if (audioElementRef.current) { + audioElementRef.current.play().catch(console.error); + } }); navigator.mediaSession.setActionHandler('pause', () => { - stopKeepAlive(); + if (audioElementRef.current) { + audioElementRef.current.pause(); + audioElementRef.current.currentTime = 0; + audioElementRef.current.src = ''; + audioElementRef.current.load(); + + // Remove from DOM + if (audioElementRef.current.parentNode) { + audioElementRef.current.parentNode.removeChild(audioElementRef.current); + } + + audioElementRef.current = null; + } + if ('mediaSession' in navigator) { + navigator.mediaSession.metadata = null; + navigator.mediaSession.playbackState = 'none'; + navigator.mediaSession.setActionHandler('play', null); + navigator.mediaSession.setActionHandler('pause', null); + navigator.mediaSession.setActionHandler('stop', null); + } + isActiveRef.current = false; }); navigator.mediaSession.setActionHandler('stop', () => { - stopKeepAlive(); + if (audioElementRef.current) { + audioElementRef.current.pause(); + audioElementRef.current.currentTime = 0; + audioElementRef.current.src = ''; + audioElementRef.current.load(); + + // Remove from DOM + if (audioElementRef.current.parentNode) { + audioElementRef.current.parentNode.removeChild(audioElementRef.current); + } + + audioElementRef.current = null; + } + if ('mediaSession' in navigator) { + navigator.mediaSession.metadata = null; + navigator.mediaSession.playbackState = 'none'; + navigator.mediaSession.setActionHandler('play', null); + navigator.mediaSession.setActionHandler('pause', null); + navigator.mediaSession.setActionHandler('stop', null); + } + isActiveRef.current = false; }); } + // Start playing + await audio.play(); + + // Set playback state after successful play + if ('mediaSession' in navigator) { + navigator.mediaSession.playbackState = 'playing'; + } + isActiveRef.current = true; - console.log('Keep-alive started with silent audio and media session'); + console.log('Keep-alive started with silent audio element and media session'); } catch (error) { console.error('Failed to start keep-alive:', error); } @@ -101,23 +127,19 @@ export function useKeepAlive({ if (!isActiveRef.current) return; try { - // Stop oscillator - if (oscillatorRef.current) { - oscillatorRef.current.stop(); - oscillatorRef.current.disconnect(); - oscillatorRef.current = null; - } + // Stop and cleanup audio element + if (audioElementRef.current) { + audioElementRef.current.pause(); + audioElementRef.current.currentTime = 0; + audioElementRef.current.src = ''; + audioElementRef.current.load(); // Reset the audio element - // Disconnect gain node - if (gainNodeRef.current) { - gainNodeRef.current.disconnect(); - gainNodeRef.current = null; - } + // Remove from DOM + if (audioElementRef.current.parentNode) { + audioElementRef.current.parentNode.removeChild(audioElementRef.current); + } - // Close audio context - if (audioContextRef.current) { - audioContextRef.current.close(); - audioContextRef.current = null; + audioElementRef.current = null; } // Clear media session