Skip to content

Commit

Permalink
Merge branch 'release-v11'
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela committed Jul 22, 2024
2 parents 2947302 + 836917e commit 42d08b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ export const AudioRecordingInProgress = () => {

useEffect(() => {
if (!recorder?.mediaRecorder) return;

const { mediaRecorder } = recorder;

if (mediaRecorder.state === 'recording') {
startCounter();
}

mediaRecorder.addEventListener('start', startCounter);
mediaRecorder.addEventListener('resume', startCounter);
mediaRecorder.addEventListener('stop', stopCounter);
Expand Down
8 changes: 4 additions & 4 deletions src/components/MessageInput/hooks/useTimeElapsed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ export const useTimeElapsed = ({ startOnMount }: UseTimeElapsedParams = {}) => {
const updateInterval = useRef<ReturnType<typeof setInterval>>();

const startCounter = useCallback(() => {
if (updateInterval.current) return;
updateInterval.current = setInterval(() => {
setSecondsElapsed((prev) => prev + 1);
}, 1000);
}, []);

const stopCounter = useCallback(() => {
clearInterval(updateInterval.current);
updateInterval.current = undefined;
}, []);

useEffect(() => {
if (!startOnMount) return;
updateInterval.current = setInterval(() => {
setSecondsElapsed((prev) => prev + 1);
}, 1000);
startCounter();
return () => {
stopCounter();
};
}, [startOnMount, stopCounter]);
}, [startCounter, startOnMount, stopCounter]);

return {
secondsElapsed,
Expand Down

0 comments on commit 42d08b7

Please sign in to comment.