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

Commit

Permalink
Broadcast time left should never be negative (#10070)
Browse files Browse the repository at this point in the history
  • Loading branch information
weeman1337 committed Feb 3, 2023
1 parent 27bd04a commit cfba1b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/voice-broadcast/models/VoiceBroadcastPlayback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,9 @@ export class VoiceBroadcastPlayback
}

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

public async skipTo(timeSeconds: number): Promise<void> {
Expand Down
14 changes: 14 additions & 0 deletions test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,20 @@ describe("VoiceBroadcastPlayback", () => {

it("should update the time", () => {
expect(playback.timeSeconds).toBe(11);
expect(playback.timeLeftSeconds).toBe(2);
});
});

describe("and the chunk playback progresses across the actual time", () => {
// This can be the case if the meta data is out of sync with the actual audio data.

beforeEach(() => {
chunk1Playback.clockInfo.liveData.update([15]);
});

it("should update the time", () => {
expect(playback.timeSeconds).toBe(15);
expect(playback.timeLeftSeconds).toBe(0);
});
});

Expand Down

0 comments on commit cfba1b0

Please sign in to comment.