From 5946ea881f085c84f65a5df9fa80fc4e020a8083 Mon Sep 17 00:00:00 2001 From: hyrious Date: Tue, 15 Nov 2022 18:51:17 +0800 Subject: [PATCH] fix(flat-components): test audio memory leak (#1773) --- .../src/components/DeviceTestPage/SpeakerTest/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/flat-components/src/components/DeviceTestPage/SpeakerTest/index.tsx b/packages/flat-components/src/components/DeviceTestPage/SpeakerTest/index.tsx index d707695dc2d..e81f3847579 100644 --- a/packages/flat-components/src/components/DeviceTestPage/SpeakerTest/index.tsx +++ b/packages/flat-components/src/components/DeviceTestPage/SpeakerTest/index.tsx @@ -3,7 +3,7 @@ import stopSVG from "../icons/stop.svg"; import "./style.less"; import { Button } from "antd"; -import React, { useRef, useState } from "react"; +import React, { useEffect, useRef, useState } from "react"; import { Device } from "../constants"; import { DeviceTestSelect } from "../DeviceTestSelect"; import { useTranslate } from "@netless/flat-i18n"; @@ -30,6 +30,8 @@ export const SpeakerTest: React.FC = ({ const [isPlaying, setIsPlaying] = useState(false); const audioRef = useRef(null); + useEffect(() => () => audioRef.current?.pause(), []); + const togglePlay = (): void => { isPlaying ? audioRef.current?.pause() : audioRef.current?.play(); setIsPlaying(!isPlaying);