From b5ad2d73789164ebd2c6380aefed9506c374a5d5 Mon Sep 17 00:00:00 2001 From: Dom Needham <=> Date: Tue, 12 Sep 2023 09:24:11 +0100 Subject: [PATCH 1/2] Fix not diplaying video when audio is present --- src/components/WebRTCView/WebRTCView.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/WebRTCView/WebRTCView.tsx b/src/components/WebRTCView/WebRTCView.tsx index d6abe43..6e9bc42 100644 --- a/src/components/WebRTCView/WebRTCView.tsx +++ b/src/components/WebRTCView/WebRTCView.tsx @@ -35,8 +35,8 @@ export const WebRTCView = ({cameraName}: WebRTCViewProps) => { const [isConnected, setIsConnected] = React.useState(false); const [retryAttempts, setRetryAttempts] = React.useState(0); const [shouldRetry, setShouldRetry] = React.useState(false); - const [remoteStream, setRemoteStream] = React.useState( - null, + const [remoteStream, setRemoteStream] = React.useState( + new MediaStream(undefined), ); const [localStream, setLocalStream] = React.useState( null, @@ -63,9 +63,7 @@ export const WebRTCView = ({cameraName}: WebRTCViewProps) => { const track = event?.track; if (track) { setIsConnected(true); - const remoteMediaStream = new MediaStream(undefined); - remoteMediaStream.addTrack(track); - setRemoteStream(remoteMediaStream); + remoteStream.addTrack(track); } }; @@ -169,6 +167,7 @@ export const WebRTCView = ({cameraName}: WebRTCViewProps) => { if (!isWsOpen) { throw 'Websocket not open yet'; } + const pc = peerConnection; const ws = wsRef.current; @@ -200,6 +199,7 @@ export const WebRTCView = ({cameraName}: WebRTCViewProps) => { throw new Error('Could not connect'); } } + setRetryAttempts(0); // we no longer want to listen to connected state change events @@ -237,7 +237,7 @@ export const WebRTCView = ({cameraName}: WebRTCViewProps) => { return ( - Unable to load streme for {cameraName} + Unable to load stream for {cameraName} Date: Tue, 12 Sep 2023 13:21:46 +0100 Subject: [PATCH 2/2] Fix lint --- src/components/WebRTCView/WebRTCView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/WebRTCView/WebRTCView.tsx b/src/components/WebRTCView/WebRTCView.tsx index 6e9bc42..8f41126 100644 --- a/src/components/WebRTCView/WebRTCView.tsx +++ b/src/components/WebRTCView/WebRTCView.tsx @@ -64,6 +64,7 @@ export const WebRTCView = ({cameraName}: WebRTCViewProps) => { if (track) { setIsConnected(true); remoteStream.addTrack(track); + setRemoteStream(remoteStream); } };