Skip to content

NVR with realtime local object detection for IP cameras

fix: WebSocket connection leaked on WebRTC player cleanup (#22473)

ryzendigoe80da2b2971c
diff --git a/web/src/components/player/WebRTCPlayer.tsx b/web/src/components/player/WebRTCPlayer.tsx
index 147af43ea0..d78c7dd807 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<RTCPeerConnection | undefined>(undefined);
+ const wsRef = useRef<WebSocket | null>(null);
const videoRef = useRef<HTMLVideoElement | null>(null);
const [bufferTimeout, setBufferTimeout] = useState<NodeJS.Timeout>();
const videoLoadTimeoutRef = useRef<NodeJS.Timeout>(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;