Skip to content

Commit

Permalink
fix: added comments and solution from pr with device-change
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Dec 10, 2024
1 parent 4c671ab commit d8b96ab
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/components/production-line/use-rtc-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const useRtcConnection = ({
sessionId,
callId,
}: TRtcConnectionOptions) => {
// TODO rtcPeerConnectionRef-solution depends on how we handle device changes
const rtcPeerConnectionRef = useRef<RTCPeerConnection | null>(null);
const [, dispatch] = useGlobalState();
const [connectionState, setConnectionState] =
Expand Down Expand Up @@ -301,9 +302,11 @@ 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"
Expand Down Expand Up @@ -374,16 +377,23 @@ export const useRtcConnection = ({
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(() => {
if (
!rtcPeerConnectionRef.current ||
rtcPeerConnectionRef.current.connectionState === "closed"
) {
rtcPeerConnectionRef.current = new RTCPeerConnection();
}
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 @@ -443,7 +453,7 @@ export const useRtcConnection = ({
onNegotiationNeeded
);
};
}, [rtcPeerConnectionRef]);
}, [connection]);

return { connectionState, audioElements };
};

0 comments on commit d8b96ab

Please sign in to comment.