Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/containers/AudioPlayer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useEffect, useRef, useState } from 'react';
import { InteractionManager, View } from 'react-native';
import { type AVPlaybackStatus } from 'expo-av';
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
import { useSharedValue } from 'react-native-reanimated';
import { useNavigation } from '@react-navigation/native';

import { type AVPlaybackStatus } from '../../lib/methods/helpers/expoAvShim';
import { useTheme } from '../../theme';
import styles from './styles';
import Seek from './Seek';
Expand Down Expand Up @@ -128,7 +128,7 @@
});
return () => task.cancel();
}
}, [fileUri, isDownloaded]);

Check warning on line 131 in app/containers/AudioPlayer/index.tsx

View workflow job for this annotation

GitHub Actions / format

React Hook useEffect has missing dependencies: 'msgId', 'onPlaybackStatusUpdate', 'playbackSpeed', and 'rid'. Either include them or remove the dependency array

useEffect(() => {
if (paused) {
Expand All @@ -151,7 +151,7 @@
unsubscribeFocus();
unsubscribeBlur();
};
}, [navigation]);

Check warning on line 154 in app/containers/AudioPlayer/index.tsx

View workflow job for this annotation

GitHub Actions / format

React Hook useEffect has a missing dependency: 'onPlaybackStatusUpdate'. Either include it or remove the dependency array

useEffect(() => {
const audioFocusedEventHandler = (audioFocused: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Audio } from 'expo-av';
import { useContext, type ReactElement } from 'react';
import { Alert } from 'react-native';
import { PermissionStatus } from 'expo-camera';

import { Audio } from '../../../../lib/methods/helpers/expoAvShim';
import i18n from '../../../../i18n';
import { useAppSelector } from '../../../../lib/hooks/useAppSelector';
import { openAppSettings } from '../../../../lib/methods/helpers/openAppSettings';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { forwardRef, useImperativeHandle, useState } from 'react';
import { type FontVariant, Text } from 'react-native';
import { type Audio } from 'expo-av';

import { type Audio } from '../../../../lib/methods/helpers/expoAvShim';
import sharedStyles from '../../../../views/Styles';
import { useTheme } from '../../../../theme';
import { formatTime } from './utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { View, Text } from 'react-native';
import { useEffect, useRef, useState, type ReactElement } from 'react';
import { Audio } from 'expo-av';
import { getInfoAsync } from 'expo-file-system/legacy';
import { useKeepAwake } from 'expo-keep-awake';
import { shallowEqual } from 'react-redux';

import { Audio } from '../../../../lib/methods/helpers/expoAvShim';
import { useTheme } from '../../../../theme';
import { BaseButton } from '../Buttons';
import { CustomIcon } from '../../../CustomIcon';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jest.mock('../../lib/services/voip/getPeerAutocompleteOptions', () => ({
jest.mock('../../lib/services/voip/navigateToCallRoom', () => ({
navigateToCallRoom: jest.fn().mockResolvedValue(undefined)
}));
// playCallEndedSound → expo-av → Audio.Sound constructor not present in this test boundary.
// playCallEndedSound → Audio.Sound constructor from the expo-av shim not present in this test boundary.
jest.mock('../../lib/services/voip/playCallEndedSound', () => ({
playCallEndedSound: jest.fn()
}));
Expand Down
3 changes: 2 additions & 1 deletion app/containers/Ringer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Audio } from 'expo-av';
import { useEffect, useRef, memo } from 'react';

import { Audio } from '../../lib/methods/helpers/expoAvShim';

export enum ERingerSounds {
DIALTONE = 'dialtone',
RINGTONE = 'ringtone'
Expand Down
9 changes: 7 additions & 2 deletions app/lib/constants/audio.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { Audio, type AudioMode, InterruptionModeAndroid, InterruptionModeIOS } from 'expo-av';
import { type RecordingOptions } from 'expo-av/build/Audio';
import {
Audio,
type AudioMode,
InterruptionModeAndroid,
InterruptionModeIOS,
type RecordingOptions
} from '../methods/helpers/expoAvShim';

export const RECORDING_EXTENSION = '.aac';
export const RECORDING_SETTINGS: RecordingOptions = {
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/AudioManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type AVPlaybackStatus, Audio } from 'expo-av';
import { Q } from '@nozbe/watermelondb';

import { type AVPlaybackStatus, Audio } from './helpers/expoAvShim';
import dayjs from '../dayjs';
import { getMessageById } from '../database/services/Message';
import database from '../database';
Expand Down
220 changes: 220 additions & 0 deletions app/lib/methods/helpers/expoAvShim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import { Component } from 'react';

/**
* Dark stub for `expo-av`, dropped in Expo SDK 55. Reproduces the subset of its
* surface this app uses as typed no-ops: audio/video playback and recording
* are intentionally disabled, not migrated to expo-audio/expo-video.
*/

export type AVPlaybackStatus =
| { isLoaded: false; error?: string }
| {
isLoaded: true;
isPlaying: boolean;
didJustFinish: boolean;
durationMillis?: number;
positionMillis: number;
rate: number;
shouldCorrectPitch: boolean;
volume: number;
isMuted: boolean;
isLooping: boolean;
};

export enum InterruptionModeIOS {
MixWithOthers = 0,
DoNotMix = 1,
DuckOthers = 2
}

export enum InterruptionModeAndroid {
DoNotMix = 1,
DuckOthers = 2
}

export interface AudioMode {
allowsRecordingIOS: boolean;
interruptionModeIOS: InterruptionModeIOS;
playsInSilentModeIOS: boolean;
staysActiveInBackground: boolean;
interruptionModeAndroid: InterruptionModeAndroid;
shouldDuckAndroid: boolean;
playThroughEarpieceAndroid: boolean;
}

export interface RecordingOptionsAndroid {
extension: string;
outputFormat: number;
audioEncoder: number;
sampleRate?: number;
numberOfChannels?: number;
bitRate?: number;
}

export interface RecordingOptionsIOS {
extension: string;
outputFormat?: string | number;
audioQuality: number;
sampleRate: number;
numberOfChannels: number;
bitRate: number;
}

export interface RecordingOptions {
isMeteringEnabled?: boolean;
keepAudioActiveHint?: boolean;
android: RecordingOptionsAndroid;
ios: RecordingOptionsIOS;
web: Record<string, unknown>;
}

export enum ResizeMode {
CONTAIN = 'contain',
COVER = 'cover',
STRETCH = 'stretch'
}

const RESOLVED_PLAYBACK_STATUS: AVPlaybackStatus = {
isLoaded: true,
isPlaying: false,
didJustFinish: false,
positionMillis: 0,
rate: 1,
shouldCorrectPitch: false,
volume: 1,
isMuted: false,
isLooping: false
};

const NOOP_PERMISSION_RESPONSE = { granted: false, status: 'undetermined', canAskAgain: true };

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace Audio {
export class Sound {
static createAsync(_source: unknown, _initialStatus?: unknown): Promise<{ sound: Sound; status: AVPlaybackStatus }> {
return Promise.resolve({ sound: new Sound(), status: RESOLVED_PLAYBACK_STATUS });
}

playAsync(): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

pauseAsync(): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

stopAsync(): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

unloadAsync(): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

loadAsync(_source: unknown): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

setPositionAsync(_millis: number): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

setRateAsync(_rate: number, _shouldCorrectPitch?: boolean): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

setIsLoopingAsync(_isLooping: boolean): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

setOnPlaybackStatusUpdate(_callback: ((status: AVPlaybackStatus) => void) | null): void {}
}

export interface RecordingStatus {
canRecord: boolean;
isRecording: boolean;
isDoneRecording: boolean;
durationMillis: number;
metering?: number;
uri?: string | null;
}

export class Recording {
prepareToRecordAsync(_options?: RecordingOptions): Promise<RecordingStatus> {
return Promise.resolve({ canRecord: true, isRecording: false, isDoneRecording: false, durationMillis: 0 });
}

setOnRecordingStatusUpdate(_callback: ((status: RecordingStatus) => void) | null): void {}

startAsync(): Promise<RecordingStatus> {
return Promise.resolve({ canRecord: true, isRecording: true, isDoneRecording: false, durationMillis: 0 });
}

stopAndUnloadAsync(): Promise<RecordingStatus> {
return Promise.resolve({ canRecord: false, isRecording: false, isDoneRecording: true, durationMillis: 0 });
}

getURI(): string | null {
return null;
}
}

export const setAudioModeAsync = (_mode: Partial<AudioMode>): Promise<void> => Promise.resolve();

export const AndroidOutputFormat = { AAC_ADTS: 6 } as const;
export const AndroidAudioEncoder = { AAC: 3 } as const;
export const IOSAudioQuality = { MEDIUM: 0x40 } as const;
export const IOSOutputFormat = { MPEG4AAC: 'aac ' } as const;

export const RecordingOptionsPresets: Record<string, RecordingOptions> = {
LOW_QUALITY: {
android: {
extension: '.3gp',
outputFormat: AndroidOutputFormat.AAC_ADTS,
audioEncoder: AndroidAudioEncoder.AAC,
sampleRate: 44100,
numberOfChannels: 2,
bitRate: 128000
},
ios: {
extension: '.caf',
audioQuality: IOSAudioQuality.MEDIUM,
outputFormat: IOSOutputFormat.MPEG4AAC,
sampleRate: 44100,
numberOfChannels: 2,
bitRate: 128000
},
web: {}
}
};

export const requestPermissionsAsync = (): Promise<{ granted: boolean; status: string; canAskAgain: boolean }> =>
Promise.resolve({ ...NOOP_PERMISSION_RESPONSE });

export const getPermissionsAsync = (): Promise<{ granted: boolean; status: string; canAskAgain: boolean }> =>
Promise.resolve({ ...NOOP_PERMISSION_RESPONSE });
}

interface VideoProps {
source?: unknown;
rate?: number;
volume?: number;
isMuted?: boolean;
resizeMode?: ResizeMode;
shouldPlay?: boolean;
isLooping?: boolean;
style?: unknown;
useNativeControls?: boolean;
onLoad?: (status: AVPlaybackStatus) => void;
onError?: (error: string) => void;
}

export class Video extends Component<VideoProps> {
stopAsync(): Promise<AVPlaybackStatus> {
return Promise.resolve(RESOLVED_PLAYBACK_STATUS);
}

render() {
return null;
}
}
4 changes: 2 additions & 2 deletions app/lib/services/voip/playCallEndedSound.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jest.mock('../../methods/helpers/log', () => ({
default: (...args: unknown[]) => mockLog(...args)
}));

// Mock expo-av at the test boundary, matching the style used in the VoIP services directory.
// Mock the expo-av shim at the test boundary, matching the style used in the VoIP services directory.
const mockLoadAsync = jest.fn(() => Promise.resolve());
const mockPlayAsync = jest.fn(() => Promise.resolve());
const mockUnloadAsync = jest.fn(() => Promise.resolve());
Expand All @@ -24,7 +24,7 @@ const mockSoundInstance = {
setOnPlaybackStatusUpdate: mockSetOnPlaybackStatusUpdate
};

jest.mock('expo-av', () => ({
jest.mock('../../methods/helpers/expoAvShim', () => ({
Audio: {
Sound: jest.fn(() => mockSoundInstance)
}
Expand Down
3 changes: 1 addition & 2 deletions app/lib/services/voip/playCallEndedSound.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Audio } from 'expo-av';

import { Audio } from '../../methods/helpers/expoAvShim';
import log from '../../methods/helpers/log';

// Module-scoped state so it survives React tree unmounts and is safe to call
Expand Down
2 changes: 1 addition & 1 deletion app/views/AttachmentView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jest.mock('react-native-safe-area-context', () => ({
useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 })
}));

jest.mock('expo-av', () => ({
jest.mock('../lib/methods/helpers/expoAvShim', () => ({
ResizeMode: { CONTAIN: 'contain' },
Video: () => null
}));
Expand Down
2 changes: 1 addition & 1 deletion app/views/AttachmentView.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CameraRoll } from '@react-native-camera-roll/camera-roll';
import { useHeaderHeight } from '@react-navigation/elements';
import { ResizeMode, Video } from 'expo-av';
import { useCallback, useLayoutEffect, useRef, useState, type Dispatch, type SetStateAction, type ReactElement } from 'react';
import { PermissionsAndroid, useWindowDimensions, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { shallowEqual } from 'react-redux';
import * as FileSystem from 'expo-file-system/legacy';

import { ResizeMode, Video } from '../lib/methods/helpers/expoAvShim';
import { isImageBase64 } from '../lib/methods/isImageBase64';
import RCActivityIndicator from '../containers/ActivityIndicator';
import AltTextLabel from '../containers/AltTextLabel';
Expand Down
3 changes: 2 additions & 1 deletion app/views/CallView/components/Dialpad/DialpadContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContext, type ReactNode, useContext, useEffect, useRef } from 'react';
import { Audio, InterruptionModeAndroid, InterruptionModeIOS } from 'expo-av';

import { Audio, InterruptionModeAndroid, InterruptionModeIOS } from '../../../../lib/methods/helpers/expoAvShim';

const DTMF_ASSETS: Record<string, ReturnType<typeof require>> = {
'0': require('../../../../containers/Ringer/dtmf/digit-0.mp3'),
Expand Down
2 changes: 1 addition & 1 deletion app/views/CallView/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ describe('CallView outgoing ringback', () => {
(Platform as { OS: string }).OS = 'ios';
});

it('does not call native ringback (expo-av Ringer handles iOS)', () => {
it('does not call native ringback (Ringer component handles iOS)', () => {
setStoreState({ callState: 'ringing', direction: 'outgoing' });
render(
<Wrapper>
Expand Down
4 changes: 2 additions & 2 deletions app/views/CallView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ReactElement, useEffect } from 'react';
import { Audio, InterruptionModeIOS } from 'expo-av';

import { Audio, InterruptionModeIOS } from '../../lib/methods/helpers/expoAvShim';
import { useCallStore } from '../../lib/services/voip/useCallStore';
import CallerInfo from './components/CallerInfo';
import { styles } from './styles';
Expand Down Expand Up @@ -51,7 +51,7 @@ const CallView = (): ReactElement | null => {
const showRingback = callState === 'ringing' && direction === 'outgoing';

// Android plays ringback natively (USAGE_VOICE_COMMUNICATION) so it follows the active comm
// device and toggleSpeaker actually reroutes it. iOS keeps expo-av Ringer (CallKit-managed).
// device and toggleSpeaker actually reroutes it. iOS keeps the Ringer component (CallKit-managed).
useEffect(() => {
if (isIOS || !showRingback) return;
NativeVoipModule.startRingback().catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion app/views/ShareView/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { memo, useState } from 'react';
import { Video, ResizeMode } from 'expo-av';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { ScrollView, StyleSheet, Text, useWindowDimensions, View } from 'react-native';
import prettyBytes from 'pretty-bytes';
import { useHeaderHeight } from '@react-navigation/elements';

import { Video, ResizeMode } from '../../lib/methods/helpers/expoAvShim';
import { CustomIcon, type TIconsName } from '../../containers/CustomIcon';
import { ImageViewer } from '../../containers/ImageViewer';
import sharedStyles from '../Styles';
Expand Down
Loading
Loading