Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(CMCD): Only report ltc if playing; round to int #8011

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Jürgen Kartnaller <kartnaller@lovelysystems.com>
Justin Swaney <justin.mark.swaney@gmail.com>
Konstantin Grushetsky <github@grushetsky.net>
Leandro Ribeiro Moreira <leandro.ribeiro.moreira@gmail.com>
Leo Antunes <leo@costela.net>
Loïc Raux <loicraux@gmail.com>
Lucas Gabriel Sánchez <unkiwii@gmail.com>
Martin Stark <martin.stark@eyevinn.se>
Expand Down
5 changes: 3 additions & 2 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -5863,12 +5863,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
* is playing.
*/
getLiveLatency() {
if (!this.video_) {
if (!this.video_ || !this.video_.currentTime) {
return null;
}
const now = this.getPresentationStartTimeAsDate().getTime() +
this.video_.currentTime * 1000;
return Date.now() - now;

return Math.floor(Date.now() - now);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions test/player_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2925,21 +2925,34 @@ describe('Player', () => {

// Load the player with the live manifest.
await player.load(fakeManifestUri, null, fakeMimeType);

video.currentTime = 10; // Simulate that we're 10 seconds into playback.
});

it('returns null if video element does not exist', async () => {
video.currentTime = 10; // Simulate that we're 10 seconds into playback.
await player.detach();
const latency = player.getLiveLatency();
expect(latency).toBeNull();
});

it('returns null if no position defined yet', () => {
video.currentTime = 0;
const latency = player.getLiveLatency();
expect(latency).toBeNull();
});

it('returns correct latency when video is playing', () => {
video.currentTime = 10; // Simulate that we're 10 seconds into playback.
Date.now = () => 2000 * 1000;
const latency = player.getLiveLatency();
expect(latency).toBe(990000);
});

it('returns integer latency also when Date.now returns float', () => {
video.currentTime = 10; // Simulate that we're 10 seconds into playback.
Date.now = () => 2000 * 1000.3;
const latency = player.getLiveLatency();
expect(latency).toBe(990600);
});
});

describe('getStats', () => {
Expand Down