From a0dc5055a116e1dd700213b9140702cc56fe0698 Mon Sep 17 00:00:00 2001 From: Stephen Arra Date: Sat, 7 Sep 2024 02:52:59 -0500 Subject: [PATCH] cleanup audio context on unmount (#23) * cleanup audio context on unmount * minimize change * cr Co-authored-by: Samhir Tarif <89391183+samhirtarif@users.noreply.github.com> --------- Co-authored-by: Samhir Tarif <89391183+samhirtarif@users.noreply.github.com> --- src/LiveAudioVisualizer/LiveAudioVisualizer.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/LiveAudioVisualizer/LiveAudioVisualizer.tsx b/src/LiveAudioVisualizer/LiveAudioVisualizer.tsx index d5c6d32..d12cd09 100644 --- a/src/LiveAudioVisualizer/LiveAudioVisualizer.tsx +++ b/src/LiveAudioVisualizer/LiveAudioVisualizer.tsx @@ -131,6 +131,14 @@ const LiveAudioVisualizer: (props: Props) => ReactElement = ({ } }, [analyser, context.state]); + useEffect(() => { + return () => { + if (context.state !== "closed") { + context.close(); + } + } + }, []); + const processFrequencyData = (data: Uint8Array): void => { if (!canvasRef.current) return;