Skip to content

Commit

Permalink
fix: moved dispatch to correct position
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Apr 11, 2024
1 parent 382f406 commit acf3f9f
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/components/production-line/use-rtc-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -213,6 +199,11 @@ export const useRtcConnection = ({
rtcPeerConnection,
inputAudioStream,
});

dispatch({
type: "CONNECTED_MEDIASTREAM",
payload: inputAudioStream,
});
}

const { teardown } = establishConnection({
Expand All @@ -232,6 +223,11 @@ export const useRtcConnection = ({
onConnectionStateChange
);

dispatch({
type: "CONNECTED_MEDIASTREAM",
payload: null,
});

rtcPeerConnection.close();
};
}, [
Expand Down

0 comments on commit acf3f9f

Please sign in to comment.