Skip to content

Commit 4dec01b

Browse files
committed
Fix video progress event becoming out of sync on pause/play (close #1038)
1 parent 0b7f5dc commit 4dec01b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-plugin-media-tracking",
5+
"comment": "Fix video progress event becoming out of sync on pause/play (#1038)",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-media-tracking"
10+
}

plugins/browser-plugin-media-tracking/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ function setPercentageBoundTimeouts(el: HTMLAudioElement | HTMLVideoElement, con
216216
if (0 < timeUntilBoundaryEvent) {
217217
conf.progress!.boundaryTimeoutIds.push(
218218
setTimeout(
219-
() => waitAnyRemainingTimeAfterTimeout(el, timeUntilBoundaryEvent, boundary, conf),
219+
() => waitAnyRemainingTimeAfterTimeout(el, absoluteBoundaryTimeMs, boundary, conf),
220220
timeUntilBoundaryEvent
221221
)
222222
);
@@ -229,13 +229,13 @@ function setPercentageBoundTimeouts(el: HTMLAudioElement | HTMLVideoElement, con
229229

230230
function waitAnyRemainingTimeAfterTimeout(
231231
el: HTMLAudioElement | HTMLVideoElement,
232-
timeUntilBoundaryEvent: number,
232+
absoluteBoundaryTimeMs: number,
233233
boundary: number,
234234
conf: TrackingOptions
235235
) {
236-
if (el.currentTime * 1000 < timeUntilBoundaryEvent) {
237-
setTimeout(function () {
238-
waitAnyRemainingTimeAfterTimeout(el, timeUntilBoundaryEvent, boundary, conf);
236+
if (el.currentTime * 1000 < absoluteBoundaryTimeMs) {
237+
setTimeout(() => {
238+
waitAnyRemainingTimeAfterTimeout(el, absoluteBoundaryTimeMs, boundary, conf);
239239
}, 10);
240240
} else {
241241
mediaPlayerEvent(SnowplowEvent.PERCENTPROGRESS, el, conf, { boundary: boundary });

0 commit comments

Comments
 (0)