Skip to content

Commit 8c2ebaf

Browse files
committedMar 27, 2024
refactor: remove transcoding
1 parent 1cdb3ab commit 8c2ebaf

File tree

3 files changed

+4
-205
lines changed

3 files changed

+4
-205
lines changed
 

‎src/components/MessageInput/VoiceRecorder/AudioRecorder.tsx

+1-8
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ import { AudioRecordingInProgress } from './AudioRecordingInProgress';
1212
import { useMessageInputContext } from '../../../context';
1313
import { MediaRecordingState } from '../hooks/useMediaRecorder';
1414
import { AttachmentUploadState } from '../types';
15-
import { LoadState } from '../hooks/useTranscoding';
1615

1716
export const AudioRecorder = () => {
1817
const {
1918
voiceRecordingController: {
2019
cancelRecording,
2120
completeRecording,
22-
isTranscoding,
2321
pauseRecording,
2422
recordingState,
2523
resumeRecording,
2624
stopRecording,
27-
transcoderLoadState,
2825
voiceRecording,
2926
},
3027
} = useMessageInputContext();
@@ -75,11 +72,7 @@ export const AudioRecorder = () => {
7572
disabled={isUploadingFile}
7673
onClick={completeRecording}
7774
>
78-
{isUploadingFile || isTranscoding || transcoderLoadState === LoadState.LOADING ? (
79-
<LoadingIndicatorIcon />
80-
) : (
81-
<SendIconV2 />
82-
)}
75+
{isUploadingFile ? <LoadingIndicatorIcon /> : <SendIconV2 />}
8376
</button>
8477
) : (
8578
<button className='str-chat__audio_recorder__stop-button' onClick={stopRecording}>

‎src/components/MessageInput/hooks/useMediaRecorder.ts

+3-20
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import type { SendFileAPIResponse } from 'stream-chat';
2727
import type { VoiceRecordingAttachment } from '../types';
2828
import type { MessageInputReducerAction } from './useMessageInputState';
2929
import type { DefaultStreamChatGenerics } from '../../../types';
30-
import { LoadState, useTranscoding } from './useTranscoding';
3130

3231
const MAX_FREQUENCY_AMPLITUDE = 255 as const;
3332

@@ -52,7 +51,6 @@ export type AudioRecordingConfig = {
5251
samplingFrequency: number;
5352
audioBitsPerSecond?: number;
5453
handleNotGrantedPermission?: PermissionNotGrantedHandler;
55-
transcodeToMimeType?: string;
5654
};
5755

5856
export type CustomAudioRecordingConfig = Partial<AudioRecordingConfig>;
@@ -79,7 +77,6 @@ const DEFAULT_CONFIG: {
7977
mimeType: RECORDED_MIME_TYPE_BY_BROWSER.audio.others,
8078
sampleCount: 100,
8179
samplingFrequency: 60,
82-
// transcodeToMimeType: 'audio/mp4;codecs=mp4a.40.2',
8380
},
8481
} as const;
8582

@@ -100,7 +97,6 @@ export type AudioRecordingController = {
10097
amplitudes: number[];
10198
cancelRecording: () => void;
10299
completeRecording: () => void;
103-
isTranscoding: boolean;
104100
pauseRecording: () => void;
105101
resumeRecording: () => void;
106102
startRecording: () => void;
@@ -111,7 +107,6 @@ export type AudioRecordingController = {
111107
mediaRecorder?: MediaRecorder;
112108
permissionState?: PermissionState;
113109
recordingState?: MediaRecordingState;
114-
transcoderLoadState?: LoadState;
115110
voiceRecording?: VoiceRecordingAttachment;
116111
};
117112

@@ -182,7 +177,6 @@ export const useMediaRecorder = <
182177
generateRecordingTitle,
183178
handleNotGrantedPermission,
184179
mimeType,
185-
transcodeToMimeType,
186180
} = audioRecordingConfig;
187181
const mediaType = useMemo(() => getRecordedMediaTypeFromMimeType(mimeType), [mimeType]);
188182

@@ -201,11 +195,6 @@ export const useMediaRecorder = <
201195
onError,
202196
});
203197

204-
const { isTranscoding, transcode, transcoderLoadState } = useTranscoding({
205-
onError,
206-
transcodeToMimeType,
207-
});
208-
209198
const stopCollectingAudioData = useCallback(() => {
210199
clearInterval(samplingInterval.current);
211200
}, []);
@@ -250,13 +239,9 @@ export const useMediaRecorder = <
250239

251240
const initialBlob = new Blob(recordedData.current, { type: mimeType });
252241

253-
const makeVoiceRecording = async (blob: Blob) => {
242+
const makeVoiceRecording = (blob: Blob) => {
254243
if (recordingUri.current) URL.revokeObjectURL(recordingUri.current);
255-
let finalBlob = blob;
256-
if (transcode) {
257-
const transcodedBlob = await transcode(finalBlob);
258-
if (transcodedBlob) finalBlob = transcodedBlob;
259-
}
244+
const finalBlob = blob;
260245
const uri = URL.createObjectURL(finalBlob);
261246
recordingUri.current = uri;
262247
const title = generateRecordingTitle(finalBlob.type);
@@ -295,7 +280,7 @@ export const useMediaRecorder = <
295280
makeVoiceRecording(initialBlob);
296281
}
297282
},
298-
[generateRecordingTitle, mimeType, onError, transcode],
283+
[generateRecordingTitle, mimeType, onError],
299284
);
300285

301286
const handleErrorEvent = useCallback(
@@ -536,15 +521,13 @@ export const useMediaRecorder = <
536521
cancelRecording,
537522
completeRecording,
538523
error,
539-
isTranscoding,
540524
mediaRecorder: mediaRecorder.current,
541525
pauseRecording,
542526
permissionState,
543527
recordingState,
544528
resumeRecording,
545529
startRecording,
546530
stopRecording,
547-
transcoderLoadState,
548531
uploadRecording,
549532
voiceRecording,
550533
};

‎src/components/MessageInput/hooks/useTranscoding.ts

-177
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.