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

Commit cfba1b0

Browse files
authored
Broadcast time left should never be negative (#10070)
1 parent 27bd04a commit cfba1b0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/voice-broadcast/models/VoiceBroadcastPlayback.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,9 @@ export class VoiceBroadcastPlayback
441441
}
442442

443443
public get timeLeftSeconds(): number {
444-
return Math.round(this.durationSeconds) - this.timeSeconds;
444+
// Sometimes the meta data and the audio files are a little bit out of sync.
445+
// Be sure it never returns a negative value.
446+
return Math.max(0, Math.round(this.durationSeconds) - this.timeSeconds);
445447
}
446448

447449
public async skipTo(timeSeconds: number): Promise<void> {

test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,20 @@ describe("VoiceBroadcastPlayback", () => {
525525

526526
it("should update the time", () => {
527527
expect(playback.timeSeconds).toBe(11);
528+
expect(playback.timeLeftSeconds).toBe(2);
529+
});
530+
});
531+
532+
describe("and the chunk playback progresses across the actual time", () => {
533+
// This can be the case if the meta data is out of sync with the actual audio data.
534+
535+
beforeEach(() => {
536+
chunk1Playback.clockInfo.liveData.update([15]);
537+
});
538+
539+
it("should update the time", () => {
540+
expect(playback.timeSeconds).toBe(15);
541+
expect(playback.timeLeftSeconds).toBe(0);
528542
});
529543
});
530544

0 commit comments

Comments
 (0)