Skip to content

Commit

Permalink
chore(react-native): document about why we do media stream cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshvai committed Aug 31, 2023
1 parent a7aea90 commit 62c3254
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect, useRef } from 'react';

/**
* This hook is meant to be used in Lobby view or equivalent.
* It will cleanup the media stream on unmount if call is not meant to be joined.
*/
export const useCallMediaStreamCleanup = () => {
const call = useCall();
Expand All @@ -14,16 +15,17 @@ export const useCallMediaStreamCleanup = () => {

useEffect(() => {
return () => {
const mediaStream = callRef.current?.camera.state.mediaStream as
| MediaStream
| undefined;
if (
mediaStream &&
!(
callRef.current?.state.callingState === CallingState.JOINED ||
callRef.current?.state.callingState === CallingState.JOINING
)
) {
// we cleanup media stream only if call is not joined or joining
const mediaStream = callRef.current?.camera.state.mediaStream as
| MediaStream
| undefined;
disposeOfMediaStream(mediaStream);
}
};
Expand Down

0 comments on commit 62c3254

Please sign in to comment.