Only close pc

This commit is contained in:
Nick Mowen 2023-10-22 11:27:35 -06:00
parent 6866edef76
commit 96d07c6066

View File

@ -56,8 +56,8 @@ export default function WebRtcPlayer({ camera, width, height }) {
} }
} }
const connect = useCallback(async (ws) => { const connect = useCallback(async (ws, aPc) => {
const pc = await PeerConnection('video+audio'); const pc = await aPc;
ws.addEventListener('open', () => { ws.addEventListener('open', () => {
pc.addEventListener('icecandidate', (ev) => { pc.addEventListener('icecandidate', (ev) => {
@ -82,21 +82,18 @@ export default function WebRtcPlayer({ camera, width, height }) {
pc.setRemoteDescription({ type: 'answer', sdp: msg.value }); pc.setRemoteDescription({ type: 'answer', sdp: msg.value });
} }
}); });
}, []);
ws.addEventListener('close', () => {
pc.close();
})
}, [PeerConnection]);
useEffect(() => { useEffect(() => {
const url = `${baseUrl.replace(/^http/, 'ws')}live/webrtc/api/ws?src=${camera}`; const url = `${baseUrl.replace(/^http/, 'ws')}live/webrtc/api/ws?src=${camera}`;
const ws = new WebSocket(url); const ws = new WebSocket(url);
connect(ws); const aPc = PeerConnection('video+audio');
connect(ws, aPc);
return () => { return async () => {
ws.close(); (await aPc).close();
} }
}, [camera, connect]); }, [camera, connect, PeerConnection]);
return ( return (
<div> <div>