@@ -34,7 +34,7 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
3434 const [ isInitializing , setIsInitializing ] = useState < boolean > ( false ) ;
3535 const [ error , setError ] = useState < string | null > ( null ) ;
3636 const [ audioLevel , setAudioLevel ] = useState < number > ( 0 ) ;
37-
37+
3838 const onAudioDataRef = useRef < ( ( pcmBuffer : Uint8Array ) => void ) | null > ( null ) ;
3939 const mountedRef = useRef < boolean > ( true ) ;
4040
@@ -53,13 +53,13 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
5353 try {
5454 const audioData = event . data ;
5555 console . log ( '[PhoneAudioRecorder] processAudioDataEvent called, data type:' , typeof audioData ) ;
56-
56+
5757 if ( typeof audioData === 'string' ) {
5858 // Base64 encoded data (native platforms) - decode using react-native-base64
5959 console . log ( '[PhoneAudioRecorder] Decoding Base64 string, length:' , audioData . length ) ;
6060 const binaryString = base64 . decode ( audioData ) ;
6161 console . log ( '[PhoneAudioRecorder] Decoded to binary string, length:' , binaryString . length ) ;
62-
62+
6363 const bytes = new Uint8Array ( binaryString . length ) ;
6464 for ( let i = 0 ; i < binaryString . length ; i ++ ) {
6565 bytes [ i ] = binaryString . charCodeAt ( i ) ;
@@ -148,10 +148,10 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
148148 intervalAnalysis : 500 , // Analysis every 500ms
149149 onAudioStream : async ( event : AudioDataEvent ) => {
150150 // EXACT payload handling from guide
151- const payload = typeof event . data === "string"
152- ? event . data
151+ const payload = typeof event . data === "string"
152+ ? event . data
153153 : Buffer . from ( event . data as unknown as ArrayBuffer ) . toString ( "base64" ) ;
154-
154+
155155 // Convert to our expected format
156156 if ( onAudioDataRef . current && mountedRef . current ) {
157157 const pcmBuffer = processAudioDataEvent ( event ) ;
@@ -163,7 +163,7 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
163163 } ;
164164
165165 const result = await startRecorderInternal ( config ) ;
166-
166+
167167 if ( ! result ) {
168168 throw new Error ( 'Failed to start recording' ) ;
169169 }
@@ -185,7 +185,7 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
185185 // Stop recording
186186 const stopRecording = useCallback ( async ( ) : Promise < void > => {
187187 console . log ( '[PhoneAudioRecorder] Stopping recording...' ) ;
188-
188+
189189 // Early return if not recording
190190 if ( ! isRecording ) {
191191 console . log ( '[PhoneAudioRecorder] Not recording, nothing to stop' ) ;
@@ -194,7 +194,7 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
194194 setStateSafe ( setIsInitializing , false ) ;
195195 return ;
196196 }
197-
197+
198198 onAudioDataRef . current = null ;
199199 setStateSafe ( setAudioLevel , 0 ) ;
200200
@@ -231,13 +231,13 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
231231 console . log ( '[PhoneAudioRecorder] Component unmounting, setting mountedRef to false' ) ;
232232 } ;
233233 } , [ ] ) ; // Empty dependency array - only runs on mount/unmount
234-
234+
235235 // Separate effect for stopping recording when needed
236236 useEffect ( ( ) => {
237237 return ( ) => {
238238 // Stop recording if active when dependencies change
239239 if ( isRecording ) {
240- stopRecorderInternal ( ) . catch ( err =>
240+ stopRecorderInternal ( ) . catch ( err =>
241241 console . error ( '[PhoneAudioRecorder] Cleanup stop error:' , err )
242242 ) ;
243243 }
@@ -252,4 +252,4 @@ export const usePhoneAudioRecorder = (): UsePhoneAudioRecorder => {
252252 startRecording,
253253 stopRecording,
254254 } ;
255- } ;
255+ } ;
0 commit comments