From 62c3254b6ba165817afa84bfbce02c7c1c7d1c04 Mon Sep 17 00:00:00 2001 From: Santhosh Vaiyapuri Date: Thu, 31 Aug 2023 10:39:56 +0200 Subject: [PATCH] chore(react-native): document about why we do media stream cleanup --- .../src/hooks/internal/useCallMediaStreamCleanup.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/react-native-sdk/src/hooks/internal/useCallMediaStreamCleanup.ts b/packages/react-native-sdk/src/hooks/internal/useCallMediaStreamCleanup.ts index 8a9066e971..ee22ea26a0 100644 --- a/packages/react-native-sdk/src/hooks/internal/useCallMediaStreamCleanup.ts +++ b/packages/react-native-sdk/src/hooks/internal/useCallMediaStreamCleanup.ts @@ -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(); @@ -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); } };