Skip to content

Commit 10fd51f

Browse files
committed
eslint fix and api align
1 parent 062be8f commit 10fd51f

File tree

6 files changed

+41
-46
lines changed

6 files changed

+41
-46
lines changed

app/containers/AudioPlayer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { InteractionManager, View } from 'react-native';
33
import { activateKeepAwake, deactivateKeepAwake } from 'expo-keep-awake';
44
import { useSharedValue } from 'react-native-reanimated';
55
import { useNavigation } from '@react-navigation/native';
6-
import { AudioStatus } from 'expo-audio';
6+
import type { AudioStatus } from 'expo-audio';
77

88
import { useTheme } from '../../theme';
99
import styles from './styles';

app/containers/MessageComposer/components/RecordAudio/Duration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { forwardRef, useImperativeHandle } from 'react';
22
import { type FontVariant, Text } from 'react-native';
3-
import { RecorderState } from 'expo-audio';
3+
import type { RecorderState } from 'expo-audio';
44

55
import sharedStyles from '../../../../views/Styles';
66
import { useTheme } from '../../../../theme';

app/containers/MessageComposer/components/RecordAudio/RecordAudio.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ export const RecordAudio = (): ReactElement | null => {
3939
const permissionToUpload = useCanUploadFile(rid);
4040
useKeepAwake();
4141

42+
async function doRecording() {
43+
// await setAudioModeAsync({
44+
// playsInSilentMode: true,
45+
// allowsRecording: true,
46+
// });
47+
48+
await audioRecorder.prepareToRecordAsync();
49+
await audioRecorder.record();
50+
}
51+
4252
useEffect(() => {
4353
try {
44-
async function doRecording() {
45-
// await setAudioModeAsync({
46-
// playsInSilentMode: true,
47-
// allowsRecording: true,
48-
// });
49-
50-
await audioRecorder.prepareToRecordAsync();
51-
await audioRecorder.record();
52-
}
53-
5454
doRecording();
5555
} catch (e) {
5656
console.log(e);
@@ -71,7 +71,7 @@ export const RecordAudio = (): ReactElement | null => {
7171
durationRef.current.onRecordingStatusUpdate(recorderState);
7272
}, [recorderState]);
7373

74-
const cancelRecording = async () => {
74+
const cancelRecording = () => {
7575
try {
7676
audioRecorder.stop();
7777
} catch {
@@ -81,7 +81,7 @@ export const RecordAudio = (): ReactElement | null => {
8181
}
8282
};
8383

84-
const goReview = async () => {
84+
const goReview = () => {
8585
try {
8686
audioRecorder.stop();
8787
setStatus('reviewing');

app/containers/Ringer/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Audio } from 'expo-av';
1+
import { createAudioPlayer } from 'expo-audio';
22
import React, { useEffect, useRef } from 'react';
33

44
export enum ERingerSounds {
@@ -7,15 +7,15 @@ export enum ERingerSounds {
77
}
88

99
const Ringer = React.memo(({ ringer }: { ringer: ERingerSounds }) => {
10-
const sound = useRef(new Audio.Sound());
10+
const player = useRef(createAudioPlayer());
1111

1212
useEffect(() => {
13-
const loadAndPlay = async () => {
13+
const loadAndPlay = () => {
1414
try {
1515
const soundFile = ringer === ERingerSounds.DIALTONE ? require(`./dialtone.mp3`) : require(`./ringtone.mp3`);
16-
await sound.current.loadAsync(soundFile);
17-
await sound.current.playAsync();
18-
await sound.current.setIsLoopingAsync(true);
16+
player.current.replace(soundFile);
17+
player.current.loop = true;
18+
player.current.play();
1919
} catch (error) {
2020
console.error('Error loading sound:', error);
2121
}
@@ -24,7 +24,7 @@ const Ringer = React.memo(({ ringer }: { ringer: ERingerSounds }) => {
2424
loadAndPlay();
2525

2626
return () => {
27-
sound.current?.unloadAsync();
27+
player.current?.release();
2828
};
2929
}, []);
3030

app/lib/constants/audio.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Audio, AudioMode, InterruptionModeAndroid, InterruptionModeIOS } from 'expo-av';
21
import { type RecordingOptions } from 'expo-audio';
32

43
export const RECORDING_EXTENSION = '.aac';
@@ -21,13 +20,3 @@ export const RECORDING_SETTINGS: RecordingOptions = {
2120
extension: RECORDING_EXTENSION,
2221
sampleRate: 44100
2322
};
24-
25-
export const AUDIO_MODE: AudioMode = {
26-
allowsRecordingIOS: false,
27-
playsInSilentModeIOS: true,
28-
staysActiveInBackground: true,
29-
shouldDuckAndroid: true,
30-
playThroughEarpieceAndroid: false,
31-
interruptionModeIOS: InterruptionModeIOS.DoNotMix,
32-
interruptionModeAndroid: InterruptionModeAndroid.DoNotMix
33-
};

app/lib/methods/AudioManager.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createAudioPlayer, AudioPlayer, AudioStatus } from 'expo-audio';
1+
import { createAudioPlayer, type AudioPlayer, type AudioStatus } from 'expo-audio';
22
import { Q } from '@nozbe/watermelondb';
33

44
import dayjs from '../dayjs';
@@ -9,9 +9,9 @@ import { type TMessageModel } from '../../definitions';
99
import { emitter } from './helpers';
1010

1111
function createAudioManager() {
12-
let audioQueue: { [audioKey: string]: AudioPlayer } = {};
12+
const audioQueue: { [audioKey: string]: AudioPlayer } = {};
1313
let audioPlaying = '';
14-
let audiosRendered = new Set<string>();
14+
const audiosRendered = new Set<string>();
1515

1616
function getAudioKey({ msgId, rid, uri }: { msgId?: string; rid: string; uri: string }) {
1717
return `${msgId}-${rid}-${uri}`;
@@ -25,7 +25,7 @@ function createAudioManager() {
2525
audiosRendered.delete(audioKey);
2626
}
2727

28-
async function loadAudio({ msgId, rid, uri }: { rid: string; msgId?: string; uri: string }): Promise<string> {
28+
function loadAudio({ msgId, rid, uri }: { rid: string; msgId?: string; uri: string }): string {
2929
const audioKey = getAudioKey({ msgId, rid, uri });
3030
addAudioRendered(audioKey);
3131
if (audioQueue[audioKey]) return audioKey;
@@ -35,28 +35,30 @@ function createAudioManager() {
3535
return audioKey;
3636
}
3737

38-
async function playAudio(audioKey: string) {
39-
if (audioPlaying) await pauseAudio();
38+
function playAudio(audioKey: string) {
39+
if (audioPlaying) pauseAudio();
4040
audioQueue[audioKey]?.play();
4141
audioPlaying = audioKey;
4242
emitter.emit('audioFocused', audioKey);
4343
}
4444

45-
async function pauseAudio() {
45+
function pauseAudio() {
4646
if (audioPlaying) {
4747
audioQueue[audioPlaying]?.pause();
4848
audioPlaying = '';
4949
}
5050
}
5151

52-
async function setPositionAsync(audioKey: string, time: number) {
52+
function setPositionAsync(audioKey: string, time: number) {
5353
audioQueue[audioKey]?.seekTo(time);
5454
}
5555

56-
async function setRateAsync(audioKey: string, value = 1.0) {
56+
function setRateAsync(audioKey: string, value = 1.0) {
5757
try {
5858
audioQueue[audioKey]?.setPlaybackRate(value);
59-
} catch {}
59+
} catch {
60+
// Ignore errors when setting playback rate
61+
}
6062
}
6163

6264
function onPlaybackStatusUpdate(audioKey: string, status: AudioStatus, callback: (status: AudioStatus) => void) {
@@ -79,7 +81,9 @@ function createAudioManager() {
7981
audioPlaying = '';
8082
emitter.emit('audioFocused', '');
8183
await playNextAudioInSequence(audioKey);
82-
} catch {}
84+
} catch {
85+
// Ignore errors during cleanup
86+
}
8387
}
8488
}
8589

@@ -117,7 +121,7 @@ function createAudioManager() {
117121
if (nextMessage && nextMessage.attachments) {
118122
const nextAudioInSeqKey = getNextAudioKey({ message: nextMessage, rid });
119123
if (nextAudioInSeqKey && audioQueue[nextAudioInSeqKey] && audiosRendered.has(nextAudioInSeqKey)) {
120-
await playAudio(nextAudioInSeqKey);
124+
playAudio(nextAudioInSeqKey);
121125
}
122126
}
123127
}
@@ -128,8 +132,10 @@ function createAudioManager() {
128132
const roomAudioKeysLoaded = Object.keys(audioQueue).filter(audioKey => regExp.test(audioKey));
129133
const roomAudiosLoaded = roomAudioKeysLoaded.map(key => audioQueue[key]);
130134
try {
131-
await Promise.all(roomAudiosLoaded.map(async audio => audio?.release()));
132-
} catch {}
135+
await Promise.all(roomAudiosLoaded.map(audio => audio?.release()));
136+
} catch (error) {
137+
console.log(error);
138+
}
133139
roomAudioKeysLoaded.forEach(key => delete audioQueue[key]);
134140
audioPlaying = '';
135141
}

0 commit comments

Comments
 (0)