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

Commit 7df973d

Browse files
Fix ongoing broadcast recording after connection error (#9974)
Co-authored-by: Andy Balaam <[email protected]>
1 parent 533b250 commit 7df973d

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/voice-broadcast/audio/VoiceBroadcastRecorder.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ export class VoiceBroadcastRecorder
6565
this.voiceRecording.liveData.onUpdate((data: IRecordingUpdate) => {
6666
this.setCurrentChunkLength(data.timeSeconds - this.previousChunkEndTimePosition);
6767
});
68-
return;
6968
}
7069

7170
/**
7271
* Stops the recording and returns the remaining chunk (if any).
7372
*/
7473
public async stop(): Promise<Optional<ChunkRecordedPayload>> {
75-
await this.voiceRecording.stop();
74+
try {
75+
await this.voiceRecording.stop();
76+
} catch {
77+
// Ignore if the recording raises any error.
78+
}
79+
7680
// forget about that call, so that we can stop it again later
7781
Singleflight.forgetAllFor(this.voiceRecording);
7882
const chunk = this.extractChunk();

src/voice-broadcast/models/VoiceBroadcastRecording.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class VoiceBroadcastRecording
333333
* It sets the connection error state and stops the recorder.
334334
*/
335335
private async onConnectionError(): Promise<void> {
336-
await this.stopRecorder();
336+
await this.stopRecorder(false);
337337
this.setState("connection_error");
338338
}
339339

@@ -418,14 +418,14 @@ export class VoiceBroadcastRecording
418418
}
419419
}
420420

421-
private async stopRecorder(): Promise<void> {
421+
private async stopRecorder(emit = true): Promise<void> {
422422
if (!this.recorder) {
423423
return;
424424
}
425425

426426
try {
427427
const lastChunk = await this.recorder.stop();
428-
if (lastChunk) {
428+
if (lastChunk && emit) {
429429
await this.onChunkRecorded(lastChunk);
430430
}
431431
} catch (err) {

test/voice-broadcast/audio/VoiceBroadcastRecorder-test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,22 @@ describe("VoiceBroadcastRecorder", () => {
205205
});
206206
});
207207
});
208+
209+
describe("and calling stop() with recording.stop error)", () => {
210+
let stopPayload: ChunkRecordedPayload;
211+
212+
beforeEach(async () => {
213+
mocked(voiceRecording.stop).mockRejectedValue("Error");
214+
stopPayload = await voiceBroadcastRecorder.stop();
215+
});
216+
217+
it("should return the remaining chunk", () => {
218+
expect(stopPayload).toEqual({
219+
buffer: concat(headers1, headers2, chunk1),
220+
length: 23,
221+
});
222+
});
223+
});
208224
});
209225

210226
describe("when some chunks have been received", () => {

0 commit comments

Comments
 (0)