Web:Components:Viewer:Sub-Components: Fixed memory leak
This commit is contained in:
parent
029a568076
commit
70c47a9708
@ -422,6 +422,17 @@ export default function ViewerPlayer(props) {
|
||||
const [currentVolume, setCurrentVolume] = React.useState(stateVolume);
|
||||
const [globalTimer, setGlobalTimer] = React.useState(null);
|
||||
const speedIcons = [<Icon05x />, <Icon1x />, <Icon15x />, <Icon2x />];
|
||||
|
||||
const unmountedRef = React.useRef(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
unmountedRef.current = false;
|
||||
|
||||
return () => {
|
||||
unmountedRef.current = true;
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handlers = useSwipeable({
|
||||
onSwiping: (e) => {
|
||||
const [width, height, left, top] = getVideoPosition(videoRef.current);
|
||||
@ -833,14 +844,22 @@ export default function ViewerPlayer(props) {
|
||||
|
||||
React.useEffect(() => {
|
||||
if (videoRef && videoRef.current) {
|
||||
videoRef.current.addEventListener("error", (event) => {
|
||||
const onError = (event) => {
|
||||
if (unmountedRef.current) return;
|
||||
|
||||
setIsError(true);
|
||||
return dispatch(
|
||||
createAction(ACTION_TYPES.update, {
|
||||
loadingError: true,
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
videoRef.current.addEventListener("error", onError);
|
||||
|
||||
return () => {
|
||||
videoRef.current?.removeEventListener("error", onError);
|
||||
};
|
||||
}
|
||||
}, [videoRef.current]);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user