Skip to content

Commit

Permalink
fix: removed peerconnection-changes from use-rtcconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Dec 13, 2024
1 parent 356c761 commit 5132efe
Showing 1 changed file with 6 additions and 36 deletions.
42 changes: 6 additions & 36 deletions src/components/production-line/use-rtc-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,9 @@ export const useRtcConnection = ({
sessionId,
callId,
}: TRtcConnectionOptions) => {
// TODO rtcPeerConnectionRef-solution depends on how we handle device changes
const rtcPeerConnectionRef = useRef<RTCPeerConnection | null>(null);
const [rtcPeerConnection] = useState<RTCPeerConnection>(
() => new RTCPeerConnection()
);
const [, dispatch] = useGlobalState();
const [connectionState, setConnectionState] =
useState<RTCPeerConnectionState | null>(null);
Expand All @@ -273,8 +274,7 @@ export const useRtcConnection = ({
// eslint-disable-next-line no-param-reassign
el.srcObject = null;
});
setAudioElements([]); // Reset state
}, []);
}, [audioElementsRef]);

// Teardown
useEffect(
Expand Down Expand Up @@ -302,20 +302,6 @@ export const useRtcConnection = ({

console.log("Setting up RTC Peer Connection");

// TODO Solution depends on how we handle device changes
// Clean up existing audio elements before reconnecting
cleanUpAudio();

// TODO Solution depends on how we handle device changes
if (
!rtcPeerConnectionRef.current ||
rtcPeerConnectionRef.current.connectionState === "closed"
) {
rtcPeerConnectionRef.current = new RTCPeerConnection();
}

const rtcPeerConnection = rtcPeerConnectionRef.current;

const onConnectionStateChange = () => {
setConnectionState(rtcPeerConnection.connectionState);
};
Expand Down Expand Up @@ -370,30 +356,14 @@ export const useRtcConnection = ({
inputAudioStream,
sessionId,
joinProductionOptions,
rtcPeerConnectionRef,
cleanUpAudio,
rtcPeerConnection,
dispatch,
noStreamError,
callId,
]);

// TODO Solution depends on how we handle device changes
const connection = rtcPeerConnectionRef.current
? rtcPeerConnectionRef.current.connectionState
: null;

// Debug hook for logging RTC events TODO remove
useEffect(() => {
const rtcPeerConnection = rtcPeerConnectionRef.current;

if (!rtcPeerConnection) {
return () => {
console.log(
"Exited debug hook for logging RTC events early, no rtcPeerConnection"
);
};
}

const onIceGathering = () =>
console.log("ice gathering:", rtcPeerConnection.iceGatheringState);
const onIceConnection = () =>
Expand Down Expand Up @@ -453,7 +423,7 @@ export const useRtcConnection = ({
onNegotiationNeeded
);
};
}, [connection]);
}, [rtcPeerConnection]);

return { connectionState, audioElements };
};

0 comments on commit 5132efe

Please sign in to comment.