Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: start audio recorder timer if already recording #2453

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@

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

const { mediaRecorder } = recorder;

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

Check warning on line 58 in src/components/MediaRecorder/AudioRecorder/AudioRecordingInProgress.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/MediaRecorder/AudioRecorder/AudioRecordingInProgress.tsx#L58

Added line #L58 was not covered by tests
}

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 @@
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;

Check warning on line 21 in src/components/MessageInput/hooks/useTimeElapsed.ts

View check run for this annotation

Codecov / codecov/patch

src/components/MessageInput/hooks/useTimeElapsed.ts#L21

Added line #L21 was not covered by tests
}, []);

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

Check warning on line 26 in src/components/MessageInput/hooks/useTimeElapsed.ts

View check run for this annotation

Codecov / codecov/patch

src/components/MessageInput/hooks/useTimeElapsed.ts#L26

Added line #L26 was not covered by tests
return () => {
stopCounter();
};
}, [startOnMount, stopCounter]);
}, [startCounter, startOnMount, stopCounter]);

return {
secondsElapsed,
Expand Down
Loading