Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix voice broadcast recording (#9617)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 authored and Amy Walker committed Nov 28, 2022
1 parent 3b0e99b commit edbd48a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/voice-broadcast/audio/VoiceBroadcastRecorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class VoiceBroadcastRecorder
const chunk = this.extractChunk();
this.currentChunkLength = 0;
this.previousChunkEndTimePosition = 0;
this.headers = new Uint8Array(0);
return chunk;
}

Expand Down
51 changes: 34 additions & 17 deletions test/voice-broadcast/audio/VoiceBroadcastRecorder-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,27 @@ describe("VoiceBroadcastRecorder", () => {
let voiceBroadcastRecorder: VoiceBroadcastRecorder;
let onChunkRecorded: (chunk: ChunkRecordedPayload) => void;

const itShouldNotEmitAChunkRecordedEvent = () => {
it("should not emit a ChunkRecorded event", () => {
const simulateFirstChunk = (): void => {
voiceRecording.onDataAvailable(headers1);
voiceRecording.onDataAvailable(headers2);
// set recorder seconds to something greater than the test chunk length of 30
// @ts-ignore
voiceRecording.recorderSeconds = 42;
voiceRecording.onDataAvailable(chunk1);
};

const expectOnFirstChunkRecorded = (): void => {
expect(onChunkRecorded).toHaveBeenNthCalledWith(
1,
{
buffer: concat(headers1, headers2, chunk1),
length: 42,
},
);
};

const itShouldNotEmitAChunkRecordedEvent = (): void => {
it("should not emit a ChunkRecorded event", (): void => {
expect(voiceRecording.emit).not.toHaveBeenCalledWith(
VoiceBroadcastRecorderEvent.ChunkRecorded,
expect.anything(),
Expand Down Expand Up @@ -163,7 +182,7 @@ describe("VoiceBroadcastRecorder", () => {

itShouldNotEmitAChunkRecordedEvent();

describe("stop", () => {
describe("and calling stop", () => {
let stopPayload: ChunkRecordedPayload;

beforeEach(async () => {
Expand All @@ -176,18 +195,22 @@ describe("VoiceBroadcastRecorder", () => {
length: 23,
});
});

describe("and calling start again and receiving some data", () => {
beforeEach(() => {
simulateFirstChunk();
});

it("should emit the ChunkRecorded event for the first chunk", () => {
expectOnFirstChunkRecorded();
});
});
});
});

describe("when some chunks have been received", () => {
beforeEach(() => {
// simulate first chunk
voiceRecording.onDataAvailable(headers1);
voiceRecording.onDataAvailable(headers2);
// set recorder seconds to something greater than the test chunk length of 30
// @ts-ignore
voiceRecording.recorderSeconds = 42;
voiceRecording.onDataAvailable(chunk1);
simulateFirstChunk();

// simulate a second chunk
voiceRecording.onDataAvailable(chunk2a);
Expand All @@ -198,13 +221,7 @@ describe("VoiceBroadcastRecorder", () => {
});

it("should emit ChunkRecorded events", () => {
expect(onChunkRecorded).toHaveBeenNthCalledWith(
1,
{
buffer: concat(headers1, headers2, chunk1),
length: 42,
},
);
expectOnFirstChunkRecorded();

expect(onChunkRecorded).toHaveBeenNthCalledWith(
2,
Expand Down

0 comments on commit edbd48a

Please sign in to comment.