Skip to content

Commit e69c558

Browse files
committed
fix: ts issues
1 parent c39975d commit e69c558

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

package/native-package/src/optionalDependencies/Sound.tsx

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
import type {
2-
AVPlaybackStatusToSet,
3-
PlaybackStatus,
4-
SoundReturnType,
5-
} from 'stream-chat-react-native-core';
1+
import type { PlaybackStatus, SoundReturnType } from 'stream-chat-react-native-core';
62

7-
let LegacyAudioRecorderPlayer;
8-
let createNitroSound;
3+
type InitialPlaybackStatus = {
4+
positionMillis?: number;
5+
progressUpdateIntervalMillis?: number;
6+
rate?: number;
7+
};
8+
9+
type LegacyAudioRecorderPlayerConstructor = new () => NativePlaybackInstance;
10+
11+
let LegacyAudioRecorderPlayer: LegacyAudioRecorderPlayerConstructor | undefined;
12+
let createNitroSound: (() => NativePlaybackInstance) | undefined;
913

1014
try {
1115
({ createSound: createNitroSound } = require('react-native-nitro-sound'));
@@ -62,14 +66,14 @@ const createPlaybackInstance = (): NativePlaybackInstance | null => {
6266
const createPlaybackStatus = ({
6367
didJustFinish = false,
6468
durationMillis,
65-
error = null,
69+
error = '',
6670
isLoaded,
6771
isPlaying,
6872
positionMillis,
6973
}: {
7074
didJustFinish?: boolean;
7175
durationMillis: number;
72-
error?: string | null;
76+
error?: string;
7377
isLoaded: boolean;
7478
isPlaying: boolean;
7579
positionMillis: number;
@@ -91,12 +95,12 @@ const createPlaybackStatus = ({
9195

9296
class NativeAudioSoundAdapter implements SoundReturnType {
9397
testID = 'native-audio-sound';
98+
onPlaybackStatusUpdate?: (playbackStatus: PlaybackStatus) => void;
9499
private playbackInstance: NativePlaybackInstance | null;
95100
private sourceUri?: string;
96-
private onPlaybackStatusUpdate?: (playbackStatus: PlaybackStatus) => void;
97101
private isDisposed = false;
98102
private isLoaded = false;
99-
private isPlaying = false;
103+
private playing = false;
100104
private durationMillis = 0;
101105
private positionMillis = 0;
102106
private playbackRate = 1;
@@ -109,7 +113,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
109113
onPlaybackStatusUpdate,
110114
}: {
111115
source?: { uri: string };
112-
initialStatus?: Partial<AVPlaybackStatusToSet>;
116+
initialStatus?: InitialPlaybackStatus;
113117
onPlaybackStatusUpdate?: (playbackStatus: PlaybackStatus) => void;
114118
}) {
115119
this.playbackInstance = createPlaybackInstance();
@@ -125,18 +129,18 @@ class NativeAudioSoundAdapter implements SoundReturnType {
125129

126130
private emitPlaybackStatus({
127131
didJustFinish = false,
128-
error = null,
132+
error = '',
129133
}: {
130134
didJustFinish?: boolean;
131-
error?: string | null;
135+
error?: string;
132136
} = {}) {
133137
this.onPlaybackStatusUpdate?.(
134138
createPlaybackStatus({
135139
didJustFinish,
136140
durationMillis: this.durationMillis,
137141
error,
138142
isLoaded: this.isLoaded,
139-
isPlaying: this.isPlaying,
143+
isPlaying: this.playing,
140144
positionMillis: this.positionMillis,
141145
}),
142146
);
@@ -172,17 +176,19 @@ class NativeAudioSoundAdapter implements SoundReturnType {
172176
}
173177
}
174178

175-
private handlePlaybackProgress = ({ currentPosition, duration, isFinished }: NativePlaybackMeta) => {
179+
private handlePlaybackProgress = ({
180+
currentPosition,
181+
duration,
182+
isFinished,
183+
}: NativePlaybackMeta) => {
176184
this.positionMillis = currentPosition ?? this.positionMillis;
177185
this.durationMillis = duration ?? this.durationMillis;
178186

179187
const didJustFinish =
180-
isFinished === true &&
181-
this.durationMillis > 0 &&
182-
this.positionMillis >= this.durationMillis;
188+
isFinished === true && this.durationMillis > 0 && this.positionMillis >= this.durationMillis;
183189

184190
if (didJustFinish) {
185-
this.isPlaying = false;
191+
this.playing = false;
186192
}
187193

188194
this.emitPlaybackStatus({ didJustFinish });
@@ -191,7 +197,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
191197
private handlePlaybackEnd = ({ currentPosition, duration }: NativePlaybackEndMeta) => {
192198
this.positionMillis = currentPosition ?? this.positionMillis;
193199
this.durationMillis = duration ?? this.durationMillis;
194-
this.isPlaying = false;
200+
this.playing = false;
195201
this.emitPlaybackStatus({ didJustFinish: true });
196202
};
197203

@@ -229,7 +235,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
229235
return;
230236
}
231237

232-
this.isPlaying = true;
238+
this.playing = true;
233239
this.emitPlaybackStatus();
234240
};
235241

@@ -243,7 +249,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
243249
}
244250

245251
await this.playbackInstance.pausePlayer();
246-
this.isPlaying = false;
252+
this.playing = false;
247253
this.emitPlaybackStatus();
248254
};
249255

@@ -274,7 +280,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
274280

275281
// Some Android backends resume playback as a side effect of changing speed.
276282
// Preserve the previous paused state explicitly so rate changes stay silent.
277-
if (!this.isPlaying) {
283+
if (!this.playing) {
278284
await this.playbackInstance.pausePlayer();
279285
this.emitPlaybackStatus();
280286
}
@@ -294,7 +300,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
294300

295301
await this.playbackInstance.stopPlayer();
296302
this.isLoaded = false;
297-
this.isPlaying = false;
303+
this.playing = false;
298304
this.positionMillis = 0;
299305
this.emitPlaybackStatus();
300306
};
@@ -315,7 +321,7 @@ class NativeAudioSoundAdapter implements SoundReturnType {
315321
this.detachListeners();
316322
this.playbackInstance?.dispose?.();
317323
this.isLoaded = false;
318-
this.isPlaying = false;
324+
this.playing = false;
319325
this.isDisposed = true;
320326
};
321327
}
@@ -324,7 +330,7 @@ const initializeSound =
324330
createNitroSound || LegacyAudioRecorderPlayer
325331
? (
326332
source?: { uri: string },
327-
initialStatus?: Partial<AVPlaybackStatusToSet>,
333+
initialStatus?: InitialPlaybackStatus,
328334
onPlaybackStatusUpdate?: (playbackStatus: PlaybackStatus) => void,
329335
) => {
330336
if (!source?.uri) {

package/src/components/ProgressControl/WaveProgressBar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback, useEffect, useMemo, useState } from 'react';
22
import { StyleSheet, View } from 'react-native';
3-
import type { StyleProp, ViewStyle } from 'react-native';
3+
import type { ColorValue, StyleProp, ViewStyle } from 'react-native';
44
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
55
import Animated, { runOnJS, useAnimatedStyle, useSharedValue } from 'react-native-reanimated';
66

@@ -58,7 +58,7 @@ const clampProgress = (progress: number) => {
5858
};
5959

6060
type WaveformBarsProps = {
61-
color: string;
61+
color: ColorValue;
6262
heights: number[];
6363
waveformStyle?: StyleProp<ViewStyle>;
6464
};

0 commit comments

Comments
 (0)