Skip to content

Commit a0dc505

Browse files
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>
1 parent 4c36d75 commit a0dc505

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/LiveAudioVisualizer/LiveAudioVisualizer.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ const LiveAudioVisualizer: (props: Props) => ReactElement = ({
131131
}
132132
}, [analyser, context.state]);
133133

134+
useEffect(() => {
135+
return () => {
136+
if (context.state !== "closed") {
137+
context.close();
138+
}
139+
}
140+
}, []);
141+
134142
const processFrequencyData = (data: Uint8Array): void => {
135143
if (!canvasRef.current) return;
136144

0 commit comments

Comments
 (0)