Skip to content

Commit

Permalink
review remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian-mkd committed Jan 16, 2025
1 parent a1df414 commit 92e3994
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCall } from '@stream-io/video-react-bindings';
import { useEffect, useRef, useState } from 'react';
import { useEffect, useRef } from 'react';
import {
AppState,
NativeEventEmitter,
Expand All @@ -23,8 +23,7 @@ const isAndroid8OrAbove = Platform.OS === 'android' && Platform.Version >= 26;
export const AppStateListener = () => {
const call = useCall();
const appState = useRef(AppState.currentState);
const [cameraDisabledByAppState, setCameraDisabledByAppState] =
useState<boolean>(false);
const cameraDisabledByAppState = useRef<boolean>(false);

// on mount: set initial PiP mode and listen to PiP events
useEffect(() => {
Expand Down Expand Up @@ -69,9 +68,9 @@ export const AppStateListener = () => {
call?.camera?.enable();
});
} else {
if (cameraDisabledByAppState) {
if (cameraDisabledByAppState.current) {
call?.camera?.resume();
setCameraDisabledByAppState(false);
cameraDisabledByAppState.current = false;
}
}
appState.current = nextAppState;
Expand All @@ -84,7 +83,7 @@ export const AppStateListener = () => {
// in PiP mode, we don't want to disable the camera
const disableCameraIfNeeded = () => {
if (call?.camera?.state.status === 'enabled') {
setCameraDisabledByAppState(true);
cameraDisabledByAppState.current = true;
call?.camera?.disable();
}
};
Expand Down Expand Up @@ -114,7 +113,7 @@ export const AppStateListener = () => {
// shouldDisableIOSLocalVideoOnBackgroundRef is false, if local video is enabled on PiP
if (shouldDisableIOSLocalVideoOnBackgroundRef.current) {
if (call?.camera?.state.status === 'enabled') {
setCameraDisabledByAppState(true);
cameraDisabledByAppState.current = true;
call?.camera?.disable();
}
}
Expand All @@ -126,7 +125,7 @@ export const AppStateListener = () => {
return () => {
subscription.remove();
};
}, [call, cameraDisabledByAppState]);
}, [call]);

return null;
};

0 comments on commit 92e3994

Please sign in to comment.