Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/helpers/recordingValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { isEmptyRecording } from "./recordingGuard.js";
// Decide whether a finished MediaRecorder session carries real audio before we
// hand it to the transcription backend. A fast tap can flush only the container
// header, or deliver no chunks at all, which crashes FFmpeg. See issue #871.
export function evaluateFinishedRecording({ blobSize, receivedAudioData } = {}) {
export function evaluateFinishedRecording(params = {}) {
const { blobSize, receivedAudioData } =
params && typeof params === "object" ? params : {};
if (!receivedAudioData) {
return { usable: false, reason: "no-audio-data" };
}
Expand Down
6 changes: 5 additions & 1 deletion test/helpers/recordingValidation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ test("rejects 255 bytes (just under the threshold)", async () => {
});
});

test("treats missing / undefined args as unusable (defensive, does not throw)", async () => {
test("treats missing / undefined / null args as unusable (defensive, does not throw)", async () => {
const { evaluateFinishedRecording } = await load();
assert.deepEqual(evaluateFinishedRecording(), { usable: false, reason: "no-audio-data" });
assert.deepEqual(evaluateFinishedRecording(null), { usable: false, reason: "no-audio-data" });
assert.deepEqual(evaluateFinishedRecording(undefined), { usable: false, reason: "no-audio-data" });
assert.deepEqual(evaluateFinishedRecording({}), { usable: false, reason: "no-audio-data" });
assert.deepEqual(evaluateFinishedRecording("invalid"), { usable: false, reason: "no-audio-data" });
assert.deepEqual(evaluateFinishedRecording(123), { usable: false, reason: "no-audio-data" });
assert.deepEqual(evaluateFinishedRecording({ receivedAudioData: true }), {
usable: false,
reason: "empty-container",
Expand Down
Loading