diff --git a/web/src/components/player/WebRTCPlayer.tsx b/web/src/components/player/WebRTCPlayer.tsx index 147af43ea..d78c7dd80 100644 --- a/web/src/components/player/WebRTCPlayer.tsx +++ b/web/src/components/player/WebRTCPlayer.tsx @@ -52,6 +52,7 @@ export default function WebRtcPlayer({ // camera states const pcRef = useRef(undefined); + const wsRef = useRef(null); const videoRef = useRef(null); const [bufferTimeout, setBufferTimeout] = useState(); const videoLoadTimeoutRef = useRef(undefined); @@ -129,7 +130,8 @@ export default function WebRtcPlayer({ } pcRef.current = await aPc; - const ws = new WebSocket(wsURL); + wsRef.current = new WebSocket(wsURL); + const ws = wsRef.current; ws.addEventListener("open", () => { pcRef.current?.addEventListener("icecandidate", (ev) => { @@ -183,6 +185,10 @@ export default function WebRtcPlayer({ connect(aPc); return () => { + if (wsRef.current) { + wsRef.current.close(); + wsRef.current = null; + } if (pcRef.current) { pcRef.current.close(); pcRef.current = undefined;