Skip to content

Commit edc8208

Browse files
St/expose media recorder (#42)
* Expose mediaRecorder from useAudioRecorder * Update readme.md * Update src/hooks/useAudioRecorder.ts Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent e27cb94 commit edc8208

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The hook returns the following:
5959
| **`isRecording`** | A boolean value that represents whether a recording is currently in progress |
6060
| **`isPaused`** | A boolean value that represents whether a recording in progress is paused |
6161
| **`recordingTime`** | Number of seconds that the recording has gone on. This is updated every second |
62+
| **`mediaRecorder`** | The current mediaRecorder in use. Can be undefined in case recording is not in progress |
6263

6364
### Sample usage of hook
6465

@@ -74,6 +75,7 @@ The hook returns the following:
7475
isRecording,
7576
isPaused,
7677
recordingTime,
78+
mediaRecorder
7779
} = useAudioRecorder();
7880

7981
useEffect(() => {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-audio-voice-recorder",
33
"private": false,
4-
"version": "1.1.1",
4+
"version": "1.1.3",
55
"license": "MIT",
66
"author": "",
77
"repository": {

src/hooks/useAudioRecorder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export interface recorderControls {
88
isRecording: boolean;
99
isPaused: boolean;
1010
recordingTime: number;
11+
mediaRecorder?: MediaRecorder;
1112
}
1213

1314
/**
@@ -20,12 +21,13 @@ export interface recorderControls {
2021
* @details `isRecording`: A boolean value that represents whether a recording is currently in progress
2122
* @details `isPaused`: A boolean value that represents whether a recording in progress is paused
2223
* @details `recordingTime`: Number of seconds that the recording has gone on. This is updated every second
24+
* @details `mediaRecorder`: The current mediaRecorder in use
2325
*/
2426
const useAudioRecorder: () => recorderControls = () => {
2527
const [isRecording, setIsRecording] = useState(false);
2628
const [isPaused, setIsPaused] = useState(false);
2729
const [recordingTime, setRecordingTime] = useState(0);
28-
const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder | null>();
30+
const [mediaRecorder, setMediaRecorder] = useState<MediaRecorder>();
2931
const [timerInterval, setTimerInterval] = useState<NodeJS.Timer>();
3032
const [recordingBlob, setRecordingBlob] = useState<Blob>();
3133

@@ -59,7 +61,7 @@ const useAudioRecorder: () => recorderControls = () => {
5961
recorder.addEventListener("dataavailable", (event) => {
6062
setRecordingBlob(event.data);
6163
recorder.stream.getTracks().forEach((t) => t.stop());
62-
setMediaRecorder(null);
64+
setMediaRecorder(undefined);
6365
});
6466
})
6567
.catch((err) => console.log(err));
@@ -99,6 +101,7 @@ const useAudioRecorder: () => recorderControls = () => {
99101
isRecording,
100102
isPaused,
101103
recordingTime,
104+
mediaRecorder,
102105
};
103106
};
104107

0 commit comments

Comments
 (0)