diff --git a/src/components/RecordButton/RecordButton.tsx b/src/components/RecordButton/RecordButton.tsx index 77c07e5..1e4fd59 100644 --- a/src/components/RecordButton/RecordButton.tsx +++ b/src/components/RecordButton/RecordButton.tsx @@ -261,6 +261,23 @@ function RecordButton({ }; }, []); + const stopRecording = React.useCallback(() => { + if (timerRef.current) { + clearInterval(timerRef.current); + } + + if ( + mediaRecorderRef.current && + mediaRecorderRef.current.state !== 'inactive' + ) { + mediaRecorderRef.current.stop(); + } + + if (streamRef.current) { + streamRef.current.getTracks().forEach((track) => track.stop()); + } + }, []); + const startRecording = React.useCallback(async () => { if (disabled || isRecording || isProcessing) return; @@ -327,23 +344,6 @@ function RecordButton({ stopRecording, ]); - const stopRecording = React.useCallback(() => { - if (timerRef.current) { - clearInterval(timerRef.current); - } - - if ( - mediaRecorderRef.current && - mediaRecorderRef.current.state !== 'inactive' - ) { - mediaRecorderRef.current.stop(); - } - - if (streamRef.current) { - streamRef.current.getTracks().forEach((track) => track.stop()); - } - }, []); - const handleClick = React.useCallback(() => { if (isRecording) { stopRecording();