Skip to content

Commit

Permalink
chore: add latency estimate to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Sep 28, 2024
1 parent f6a4f79 commit 57c0553
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 57c0553

Please sign in to comment.