Skip to content

Commit

Permalink
[Recorder] Add backstops for if cursor departs button (#3077)
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Apr 25, 2024
1 parent 576733e commit bf97594
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Pronunciations/AudioRecorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ export default function AudioRecorder(props: RecorderProps): ReactElement {
const recorder = useContext(RecorderContext);
const { t } = useTranslation();

function startRecording(): void {
async function startRecording(): Promise<void> {
// Prevent starting a recording before a previous one is finished.
await stopRecording();

recorder.startRecording();
}

async function stopRecording(): Promise<void> {
// Prevent triggering this function if no recording is active.
if (!recorder.isRecording()) {
return;
}

if (props.onClick) {
props.onClick();
}
Expand Down
4 changes: 4 additions & 0 deletions src/components/Pronunciations/Recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default class Recorder {
.catch((err) => this.onError(err));
}

isRecording(): boolean {
return this.recordRTC?.getState() === "recording";
}

startRecording(): void {
this.recordRTC?.reset();
this.recordRTC?.startRecording();
Expand Down
1 change: 1 addition & 0 deletions src/components/Pronunciations/RecorderIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function RecorderIcon(props: RecorderIconProps): ReactElement {
aria-label="record"
disabled={props.disabled}
id={recordButtonId}
onBlur={toggleIsRecordingToFalse}
onPointerDown={toggleIsRecordingToTrue}
onPointerUp={toggleIsRecordingToFalse}
onTouchEnd={handleTouchEnd}
Expand Down

0 comments on commit bf97594

Please sign in to comment.