Skip to content

Commit

Permalink
fix: camera not enabled on foreground notifications (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshvai authored Nov 1, 2024
1 parent 6beaa0b commit 67c920a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/client/src/devices/InputMediaDeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export abstract class InputMediaDeviceManager<
* Starts stream.
*/
async enable() {
this.state.prevStatus = this.state.optimisticStatus;
if (this.state.optimisticStatus === 'enabled') {
return;
}

this.state.setPendingStatus('enabled');

await withCancellation(this.statusChangeConcurrencyTag, async (signal) => {
Expand All @@ -97,7 +97,7 @@ export abstract class InputMediaDeviceManager<
* @param {boolean} [forceStop=false] when true, stops the tracks regardless of the state.disableMode
*/
async disable(forceStop: boolean = false) {
this.state.prevStatus = this.state.status;
this.state.prevStatus = this.state.optimisticStatus;
if (!forceStop && this.state.optimisticStatus === 'disabled') {
return;
}
Expand Down Expand Up @@ -131,7 +131,7 @@ export abstract class InputMediaDeviceManager<
async resume() {
if (
this.state.prevStatus === 'enabled' &&
this.state.status === 'disabled'
this.state.status !== 'enabled'
) {
await this.enable();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,29 @@ describe('InputMediaDeviceManager.test', () => {
expect(manager.enable).toHaveBeenCalledOnce();
});

it(`should resume if enable was cancelled due to disable call`, async () => {
vi.spyOn(manager, 'enable');

manager.enable();

expect(manager.enable).toHaveBeenCalledOnce();

// enable was not awaited so cancelled by disabled
await manager.disable();

manager.resume();

expect(manager.enable).toBeCalledTimes(2);

// this disable is not awaited, but will cancel the enable anyway
// so resume must work here too
manager.disable();

manager.resume();

expect(manager.enable).toBeCalledTimes(3);
});

it('should provide default constraints to `getStream` method', () => {
manager.setDefaultConstraints({
echoCancellation: true,
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"intl-pluralrules": "2.0.1",
"lodash.merge": "^4.6.2",
"react-native-url-polyfill": "1.3.0",
"rxjs": "~7.8.1",
"text-encoding-polyfill": "0.6.7"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-sdk/src/contexts/ThemeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import React, {
useMemo,
} from 'react';

import merge from 'lodash/merge';
import merge from 'lodash.merge';

import { defaultTheme, Theme } from '../theme/theme';

Expand Down
12 changes: 10 additions & 2 deletions packages/react-native-sdk/src/providers/StreamCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ const AppStateListener = () => {
// in Android, we need to check if we are in PiP mode
// in PiP mode, we don't want to disable the camera
NativeModules?.StreamVideoReactNative?.isInPiPMode().then(
async (isInPiP: boolean | null | undefined) => {
(isInPiP: boolean | null | undefined) => {
if (!isInPiP) {
await call?.camera?.disable();
const currentState = appState.current;
if (currentState === 'active') {
// this is to handle the case that the app became active as soon as it went to background
// in this case, we dont want to disable the camera
// this happens on foreground push notifications
return;
}
call?.camera?.disable();
}
}
);
} else {
// shouldDisableIOSLocalVideoOnBackgroundRef is false, if local video is enabled on PiP
if (shouldDisableIOSLocalVideoOnBackgroundRef.current) {
call?.camera?.disable();
}
Expand Down
17 changes: 9 additions & 8 deletions sample-apps/react-native/dogfood/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ PODS:
- React-Core
- react-native-netinfo (11.3.0):
- React-Core
- react-native-safe-area-context (4.8.2):
- react-native-safe-area-context (4.10.5):
- React-Core
- react-native-video (6.0.0-beta.5):
- React-Core
Expand Down Expand Up @@ -1126,15 +1126,16 @@ PODS:
- React-Core
- RNReactNativeHapticFeedback (2.0.3):
- React-Core
- RNReanimated (3.7.0):
- RNReanimated (3.10.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- ReactCommon/turbomodule/core
- RNScreens (3.29.0):
- RNScreens (3.31.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- React-RCTImage
- RNSVG (13.9.0):
- React-Core
- RNVoipPushNotification (3.3.2):
Expand All @@ -1148,7 +1149,7 @@ PODS:
- stream-react-native-webrtc (124.0.0-rc.1):
- JitsiWebRTC (~> 124.0.0)
- React-Core
- stream-video-react-native (1.1.4):
- stream-video-react-native (1.2.7):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1439,7 +1440,7 @@ SPEC CHECKSUMS:
react-native-image-resizer: d9fb629a867335bdc13230ac2a58702bb8c8828f
react-native-mmkv: 7da5e18e55c04a9af9a7e0ab9792a1e8d33765a1
react-native-netinfo: 299dad906cdbf3b67bcc6f693c807f98bdd127cc
react-native-safe-area-context: 0ee144a6170530ccc37a0fd9388e28d06f516a89
react-native-safe-area-context: a240ad4b683349e48b1d51fed1611138d1bdad97
react-native-video: df7d8a4c8568ed4a31b28e6cd2bfa4a98b186e36
React-nativeconfig: ca8b90c736cf3be019cb332ca42d93dd95b32e05
React-NativeModulesApple: 1fdffcce7772e274baeab33a1900f45feba86cbd
Expand Down Expand Up @@ -1472,14 +1473,14 @@ SPEC CHECKSUMS:
RNNotifee: f3c01b391dd8e98e67f539f9a35a9cbcd3bae744
RNPermissions: 4d64d2c763b20e5db08dfb8f1ef541f95c0d28c1
RNReactNativeHapticFeedback: afa5bf2794aecbb2dba2525329253da0d66656df
RNReanimated: ea7e98bf4f1167ca3cd3c348604d34dc4294e848
RNScreens: 2b73f5eb2ac5d94fbd61fa4be0bfebd345716825
RNReanimated: 8cd12e58bbedca2b0b62a3c3872d3629fc2e1583
RNScreens: 35f3344904f6bba888c0e61532278436e275de3c
RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315
RNVoipPushNotification: 543e18f83089134a35e7f1d2eba4c8b1f7776b08
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
stream-io-video-filters-react-native: 8c345e6adf5164646696d45f9962c4199b2fe3b9
stream-react-native-webrtc: 1380525629fae21f4894535189573fb4ddb7984a
stream-video-react-native: 25880e3ff2889deca42fba87f6fa0c434fc6e5fa
stream-video-react-native: 7948f9d3bfd695f46d90f7d05b982b31b0c304a8
TOCropViewController: 80b8985ad794298fb69d3341de183f33d1853654
Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312

Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8072,6 +8072,7 @@ __metadata:
react-native-voip-push-notification: 3.3.1
react-test-renderer: ^18.2.0
rimraf: ^5.0.7
rxjs: ~7.8.1
text-encoding-polyfill: 0.6.7
ts-jest: ^29.1.5
ts-node: ^10.9.2
Expand Down

0 comments on commit 67c920a

Please sign in to comment.