File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed
components/MessageInput/hooks Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -27,9 +27,12 @@ export const useAudioRecorder = ({
2727 * side only. Meant to be used as a pure function (during unmounting for instance)
2828 * hence this approach.
2929 */
30- const stopVoiceRecording = useCallback ( async ( ) => {
31- await audioRecorderManager . stopRecording ( ) ;
32- } , [ audioRecorderManager ] ) ;
30+ const stopVoiceRecording = useCallback (
31+ async ( withDelete ?: boolean ) => {
32+ await audioRecorderManager . stopRecording ( withDelete ) ;
33+ } ,
34+ [ audioRecorderManager ] ,
35+ ) ;
3336
3437 // This effect stop the player from playing and stops audio recording on
3538 // the audio SDK side on unmount.
@@ -60,9 +63,8 @@ export const useAudioRecorder = ({
6063 * Function to delete voice recording.
6164 */
6265 const deleteVoiceRecording = useCallback ( async ( ) => {
63- await stopVoiceRecording ( ) ;
64- audioRecorderManager . reset ( ) ;
65- } , [ audioRecorderManager , stopVoiceRecording ] ) ;
66+ await stopVoiceRecording ( true ) ;
67+ } , [ stopVoiceRecording ] ) ;
6668
6769 /**
6870 * Function to upload or send voice recording.
Original file line number Diff line number Diff line change @@ -139,7 +139,7 @@ export class AudioRecorderManager {
139139 return accessGranted ;
140140 }
141141
142- async stopRecording ( ) {
142+ async stopRecording ( withDelete : boolean = false ) {
143143 if ( ! NativeHandlers . Audio ) {
144144 return ;
145145 }
@@ -157,7 +157,12 @@ export class AudioRecorderManager {
157157 } catch {
158158 // Best effort cleanup, native implementation may already be stopped.
159159 }
160- this . state . partialNext ( { isStarting : false , status : 'stopped' } ) ;
160+
161+ if ( withDelete ) {
162+ this . reset ( ) ;
163+ } else {
164+ this . state . partialNext ( { isStarting : false , status : 'stopped' } ) ;
165+ }
161166 }
162167
163168 set micLocked ( value : boolean ) {
You can’t perform that action at this time.
0 commit comments