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

chore: add latency estimate to demo #1541

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 21 additions & 0 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,26 @@
return bufferedText;
}

var estimateSegmentLatency = function(cue, currentTime) {
var playedMs = (currentTime - cue.value.start) * 1000;
var offsetDateTime = cue.value.programDateTime + playedMs;

return (Date.now() - offsetDateTime) / 1000;
};

var updateSegmentLatency = function(segmentMetadata, cue, currentTime) {
// try and estimate the segment latency if we have program date time tags.
if (cue.value.programDateTime) {
var li = document.createElement('li');
var latency = document.createElement('latency');

latency.textContent = 'Estimated segment latency: ' + estimateSegmentLatency(cue, currentTime);

li.appendChild(latency);
segmentMetadata.appendChild(li);
}
};

var setupSegmentMetadata = function(player) {
// setup segment metadata
var segmentMetadata = document.querySelector('#segment-metadata');
Expand Down Expand Up @@ -327,6 +347,7 @@
var li = document.createElement('li');
var pre = document.createElement('pre');

updateSegmentLatency(segmentMetadata, cues[j], player.currentTime());
pre.classList.add('border', 'rounded', 'p-2');
pre.textContent = text;
li.appendChild(pre);
Expand Down
Loading