Skip to content

Commit

Permalink
fix(rn-sdk): fixes the camera status on app restore from background (#…
Browse files Browse the repository at this point in the history
…1641)

## Overview

[Liner
issue](https://linear.app/stream/issue/RN-97/camera-automatically-turns-on-when-restoring-app-from-background)

Steps to reproduce:
During a call user disables camera and puts the app in background mode.
When opens the app the camera is enabled (instead of disabled as
previously set by the user)

**The fix:** 
Allow the `resume()` method to enable the camera only if camera was
previously disable due to AppState.
  • Loading branch information
kristian-mkd authored Jan 17, 2025
1 parent 84b3c19 commit 0ff2506
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const isAndroid8OrAbove = Platform.OS === 'android' && Platform.Version >= 26;
export const AppStateListener = () => {
const call = useCall();
const appState = useRef(AppState.currentState);
const cameraDisabledByAppState = useRef<boolean>(false);

// on mount: set initial PiP mode and listen to PiP events
useEffect(() => {
Expand Down Expand Up @@ -67,7 +68,10 @@ export const AppStateListener = () => {
call?.camera?.enable();
});
} else {
call?.camera?.resume();
if (cameraDisabledByAppState.current) {
call?.camera?.resume();
cameraDisabledByAppState.current = false;
}
}
appState.current = nextAppState;
} else if (
Expand All @@ -79,6 +83,7 @@ export const AppStateListener = () => {
// in PiP mode, we don't want to disable the camera
const disableCameraIfNeeded = () => {
if (call?.camera?.state.status === 'enabled') {
cameraDisabledByAppState.current = true;
call?.camera?.disable();
}
};
Expand Down Expand Up @@ -108,6 +113,7 @@ export const AppStateListener = () => {
// shouldDisableIOSLocalVideoOnBackgroundRef is false, if local video is enabled on PiP
if (shouldDisableIOSLocalVideoOnBackgroundRef.current) {
if (call?.camera?.state.status === 'enabled') {
cameraDisabledByAppState.current = true;
call?.camera?.disable();
}
}
Expand Down

0 comments on commit 0ff2506

Please sign in to comment.