Skip to content

Commit 2067680

Browse files
committed
Fix listeners id
1 parent d1f5c80 commit 2067680

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/microphone/MicrophoneProvider.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useCallback, useEffect, useMemo, type PropsWithChildren } from 'react';
2+
import { v4 as uuidv4 } from 'uuid';
23
import { MicrophoneContext } from './context';
34
import { useMicrophoneDevice } from './hooks/useMicrophoneDevice';
45
import { 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

Comments
 (0)