Fix voice broadcast recording (#9617)
parent
d71a72e27c
commit
55921e4888
|
@ -80,6 +80,7 @@ export class VoiceBroadcastRecorder
|
||||||
const chunk = this.extractChunk();
|
const chunk = this.extractChunk();
|
||||||
this.currentChunkLength = 0;
|
this.currentChunkLength = 0;
|
||||||
this.previousChunkEndTimePosition = 0;
|
this.previousChunkEndTimePosition = 0;
|
||||||
|
this.headers = new Uint8Array(0);
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,8 +76,27 @@ describe("VoiceBroadcastRecorder", () => {
|
||||||
let voiceBroadcastRecorder: VoiceBroadcastRecorder;
|
let voiceBroadcastRecorder: VoiceBroadcastRecorder;
|
||||||
let onChunkRecorded: (chunk: ChunkRecordedPayload) => void;
|
let onChunkRecorded: (chunk: ChunkRecordedPayload) => void;
|
||||||
|
|
||||||
const itShouldNotEmitAChunkRecordedEvent = () => {
|
const simulateFirstChunk = (): void => {
|
||||||
it("should not emit a ChunkRecorded event", () => {
|
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(
|
expect(voiceRecording.emit).not.toHaveBeenCalledWith(
|
||||||
VoiceBroadcastRecorderEvent.ChunkRecorded,
|
VoiceBroadcastRecorderEvent.ChunkRecorded,
|
||||||
expect.anything(),
|
expect.anything(),
|
||||||
|
@ -163,7 +182,7 @@ describe("VoiceBroadcastRecorder", () => {
|
||||||
|
|
||||||
itShouldNotEmitAChunkRecordedEvent();
|
itShouldNotEmitAChunkRecordedEvent();
|
||||||
|
|
||||||
describe("stop", () => {
|
describe("and calling stop", () => {
|
||||||
let stopPayload: ChunkRecordedPayload;
|
let stopPayload: ChunkRecordedPayload;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
@ -176,18 +195,22 @@ describe("VoiceBroadcastRecorder", () => {
|
||||||
length: 23,
|
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", () => {
|
describe("when some chunks have been received", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// simulate first chunk
|
simulateFirstChunk();
|
||||||
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);
|
|
||||||
|
|
||||||
// simulate a second chunk
|
// simulate a second chunk
|
||||||
voiceRecording.onDataAvailable(chunk2a);
|
voiceRecording.onDataAvailable(chunk2a);
|
||||||
|
@ -198,13 +221,7 @@ describe("VoiceBroadcastRecorder", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should emit ChunkRecorded events", () => {
|
it("should emit ChunkRecorded events", () => {
|
||||||
expect(onChunkRecorded).toHaveBeenNthCalledWith(
|
expectOnFirstChunkRecorded();
|
||||||
1,
|
|
||||||
{
|
|
||||||
buffer: concat(headers1, headers2, chunk1),
|
|
||||||
length: 42,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(onChunkRecorded).toHaveBeenNthCalledWith(
|
expect(onChunkRecorded).toHaveBeenNthCalledWith(
|
||||||
2,
|
2,
|
||||||
|
|
Loading…
Reference in New Issue