react-visual-audio-recorder
Advanced tools
Comparing version
{ | ||
"name": "react-visual-audio-recorder", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -9,2 +9,3 @@ /* eslint-disable react-hooks/exhaustive-deps */ | ||
const [pause, setPause] = useState(false); | ||
const [audioRecorderStatus, setAudioRecorderStatus] = useState("stopped"); | ||
const visualizerRef = useRef(null); | ||
@@ -48,13 +49,20 @@ const { mimeType, ext } = useMemo(() => { | ||
useEffect(() => { | ||
const status = pause && record ? "pause" : !pause && record ? "recording" : "stopped"; | ||
if (handleStatus) | ||
handleStatus(pause && record ? "pause" : !pause && record ? "recording" : "stopped"); | ||
handleStatus(status); | ||
setAudioRecorderStatus(status); | ||
}, [pause, record]); | ||
function startRecording() { | ||
onStartRecording().then(() => { | ||
setRecord(true); | ||
}); | ||
if (audioRecorderStatus === "stopped") | ||
onStartRecording(); | ||
else if (audioRecorderStatus === "pause") | ||
onResumeRecording(); | ||
setPause(false); | ||
setRecord(true); | ||
} | ||
function stopRecording() { | ||
if (["recording", "pause"].indexOf(audioRecorderStatus) !== -1) | ||
onStopRecording(); | ||
setRecord(false); | ||
onStopRecording(); | ||
setPause(false); | ||
} | ||
@@ -71,4 +79,8 @@ function resetRecording() { | ||
function resumeRecording() { | ||
if (audioRecorderStatus === "stopped") | ||
onStartRecording(); | ||
else if (audioRecorderStatus === "pause") | ||
onResumeRecording(); | ||
setRecord(true); | ||
setPause(false); | ||
onResumeRecording(); | ||
} | ||
@@ -75,0 +87,0 @@ useImperativeHandle(ref, () => ({ |
@@ -68,2 +68,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}); | ||
mediaRecorderInstance.addEventListener("error", (event) => { | ||
console.error("ReactVisualAudioRecorder", event); | ||
}); | ||
audioCtx.resume().then(() => { | ||
@@ -171,3 +174,5 @@ const sourceNode = audioCtx.createMediaStreamSource(mediaStream); | ||
function startRecording() { | ||
return mediaRecorderApi.then((api) => api.mediaRecorder.start(10)); | ||
return mediaRecorderApi.then((api) => { | ||
api.mediaRecorder.start(10); | ||
}); | ||
} | ||
@@ -174,0 +179,0 @@ useEffect(() => { |
27783
2.66%498
3.53%