[Glitch] Guard against undefined AudioContext in useAudioContext hook

Port 61fdcf33303f9be249fbec4f576153bde2c9048b to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Federico Rao 2026-06-12 16:05:57 +02:00 committed by Claire
parent 81aaac4779
commit 61237253dc

View File

@ -18,7 +18,7 @@ export const useAudioContext = ({ audioElementRef }: AudioContextOptions) => {
const gainNodeRef = useRef<GainNode>();
useEffect(() => {
if (!audioElementRef.current) {
if (!audioElementRef.current || typeof AudioContext === 'undefined') {
return;
}
@ -43,13 +43,17 @@ export const useAudioContext = ({ audioElementRef }: AudioContextOptions) => {
}, [audioElementRef]);
const playAudio = useCallback(() => {
void audioElementRef.current?.play();
void audioContextRef.current?.resume();
if (audioContextRef.current && audioElementRef.current) {
void audioElementRef.current.play();
void audioContextRef.current.resume();
}
}, [audioElementRef]);
const pauseAudio = useCallback(() => {
audioElementRef.current?.pause();
void audioContextRef.current?.suspend();
if (audioContextRef.current && audioElementRef.current) {
audioElementRef.current.pause();
void audioContextRef.current.suspend();
}
}, [audioElementRef]);
return {