11import { useCallback , useEffect , useMemo , type PropsWithChildren } from 'react' ;
2+ import { v4 as uuidv4 } from 'uuid' ;
23import { MicrophoneContext } from './context' ;
34import { useMicrophoneDevice } from './hooks/useMicrophoneDevice' ;
45import { microphoneDispatcher } from './types' ;
@@ -56,7 +57,7 @@ export function MicrophoneProvider({ children, ...useMicrophoneProps }: PropsWit
5657 } , [ isRecording , micStop ] ) ;
5758
5859 const addDataListener = useCallback ( ( listener : MicrophoneDataHandler ) => {
59- const id = `kortexa-microphone-data-${ Date . now ( ) } ` ;
60+ const id = `kortexa-microphone-data-${ uuidv4 ( ) } ` ;
6061 microphoneDispatcher . addListener ( 'data' , { id, listener } ) ;
6162 return id ;
6263 } , [ ] ) ;
@@ -66,7 +67,7 @@ export function MicrophoneProvider({ children, ...useMicrophoneProps }: PropsWit
6667 } , [ ] ) ;
6768
6869 const addStartListener = useCallback ( ( listener : ( ) => void | Promise < void > ) => {
69- const id = `kortexa-microphone-start-${ Date . now ( ) } ` ;
70+ const id = `kortexa-microphone-start-${ uuidv4 ( ) } ` ;
7071 microphoneDispatcher . addListener ( 'start' , { id, listener } ) ;
7172 return id ;
7273 } , [ ] ) ;
@@ -76,7 +77,7 @@ export function MicrophoneProvider({ children, ...useMicrophoneProps }: PropsWit
7677 } , [ ] ) ;
7778
7879 const addStopListener = useCallback ( ( listener : ( ) => void ) => {
79- const id = `kortexa-microphone-stop-${ Date . now ( ) } ` ;
80+ const id = `kortexa-microphone-stop-${ uuidv4 ( ) } ` ;
8081 microphoneDispatcher . addListener ( 'stop' , { id, listener } ) ;
8182 return id ;
8283 } , [ ] ) ;
@@ -86,7 +87,7 @@ export function MicrophoneProvider({ children, ...useMicrophoneProps }: PropsWit
8687 } , [ ] ) ;
8788
8889 const addErrorListener = useCallback ( ( listener : ( error ?: string ) => void ) => {
89- const id = `kortexa-microphone-error-${ Date . now ( ) } ` ;
90+ const id = `kortexa-microphone-error-${ uuidv4 ( ) } ` ;
9091 microphoneDispatcher . addListener ( 'error' , { id, listener } ) ;
9192 return id ;
9293 } , [ ] ) ;
@@ -133,4 +134,4 @@ export function MicrophoneProvider({ children, ...useMicrophoneProps }: PropsWit
133134 { children }
134135 </ MicrophoneContext . Provider >
135136 ) ;
136- }
137+ }
0 commit comments