Skip to content

Commit abf3df2

Browse files
committed
Stop recording
1 parent eaf79dd commit abf3df2

File tree

1 file changed

+7
-2
lines changed
  • vim--ai-scribe--react/src/components/organisms/ai-scribe-demo

1 file changed

+7
-2
lines changed

vim--ai-scribe--react/src/components/organisms/ai-scribe-demo/useRecorder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useState, useEffect } from "react";
33
import { useVimOsContext } from "@/providers/VimOSContext";
44

55
export const useRecorder = () => {
6+
const [stream, setStream] = useState<MediaStream | null>(null);
67
const [isPaused, setIsPaused] = useState(false);
78
const [isRecording, setIsRecording] = useState(false);
89
const [recordingTime, setRecordingTime] = useState(0);
@@ -20,7 +21,8 @@ export const useRecorder = () => {
2021

2122
const simulateRecording = useCallback(async () => {
2223
try {
23-
await navigator.mediaDevices.getUserMedia({ audio: true });
24+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
25+
setStream(stream);
2426
// Show the VimOS microphone badge to indicate active recording
2527
vimOS?.hub?.microphoneBadge?.show?.();
2628
setIsRecording(true);
@@ -34,12 +36,15 @@ export const useRecorder = () => {
3436
}, [vimOS]);
3537

3638
const stopRecording = useCallback(() => {
39+
if (stream) {
40+
stream.getTracks().forEach((track) => track.stop());
41+
}
3742
setIsRecording(false);
3843
setIsPaused(false);
3944
setRecordingTime(0);
4045
// Hide the VimOS microphone badge when recording stops
4146
vimOS?.hub?.microphoneBadge?.hide?.();
42-
}, [vimOS]);
47+
}, [vimOS, stream]);
4348

4449
return {
4550
isPaused,

0 commit comments

Comments
 (0)