From acf3f9fd3862ffa1483e7fc6ed3c1e894fd0d32c Mon Sep 17 00:00:00 2001 From: malmen237 Date: Thu, 11 Apr 2024 11:10:11 +0200 Subject: [PATCH] fix: moved dispatch to correct position --- .../production-line/use-rtc-connection.ts | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/components/production-line/use-rtc-connection.ts b/src/components/production-line/use-rtc-connection.ts index 864b330f..7293f06d 100644 --- a/src/components/production-line/use-rtc-connection.ts +++ b/src/components/production-line/use-rtc-connection.ts @@ -161,28 +161,14 @@ export const useRtcConnection = ({ // Teardown useEffect( () => () => { - if (inputAudioStream !== "no-device") { - // TODO remove check-log - console.log("Dispatch of mediastream"); - dispatch({ - type: "CONNECTED_MEDIASTREAM", - payload: inputAudioStream, - }); - } audioElements.forEach((el) => { console.log("Tearing down audio element"); el.pause(); // eslint-disable-next-line no-param-reassign el.srcObject = null; - // TODO remove check-log - console.log("Remove mediastream"); - dispatch({ - type: "CONNECTED_MEDIASTREAM", - payload: null, - }); }); }, - [audioElements, dispatch, inputAudioStream] + [audioElements, dispatch] ); useEffect(() => { @@ -213,6 +199,11 @@ export const useRtcConnection = ({ rtcPeerConnection, inputAudioStream, }); + + dispatch({ + type: "CONNECTED_MEDIASTREAM", + payload: inputAudioStream, + }); } const { teardown } = establishConnection({ @@ -232,6 +223,11 @@ export const useRtcConnection = ({ onConnectionStateChange ); + dispatch({ + type: "CONNECTED_MEDIASTREAM", + payload: null, + }); + rtcPeerConnection.close(); }; }, [