Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
Progress (#59)
Browse files Browse the repository at this point in the history
* fuzzy thresholds

* 10%

* includes

* multispaces :(
  • Loading branch information
lc512k authored Oct 3, 2016
1 parent a7528a4 commit ccaa366
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion origami.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"supportStatus": "active",
"support": "github.com/Financial-Times/o-video/issues",
"browserFeatures": {
"required": ["fetch", "Array.prototype.find", "Object.assign"]
"required": ["fetch", "Array.prototype.find", "Array.prototype.includes", "Object.assign"]
},
"demosDefaults": {
"sass": "demos/src/main.scss",
Expand Down
15 changes: 13 additions & 2 deletions src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import Playlist from './playlist';

function eventListener(video, ev) {

// Dispatch progress event at start, 25%, 50%, 75% and 100%
// Dispatch progress event at around 25%, 50%, 75% and 100%
// If allProgress is set to true, then we send spoor events for every native video progress event (every 5 sec)
if (!video.opts.allProgress && ev.type === 'progress' && video.getProgress() % 25 !== 0) {
if (!video.opts.allProgress && ev.type === 'progress' && !shouldDispatch(video.getProgress())) {
return;
}

Expand All @@ -26,6 +26,17 @@ function eventListener(video, ev) {
document.body.dispatchEvent(event);
}

function shouldDispatch(progress) {

const relevantProgressPoints = [8, 9, 10, 11, 12,
23, 24, 25, 26, 27,
48, 49, 50, 51, 52,
73, 74, 75, 76, 77,
100];

return relevantProgressPoints.includes(progress);
}

function addEvents(video, events) {
events.forEach(event => {
video.videoEl.addEventListener(event, eventListener.bind(this, video));
Expand Down

0 comments on commit ccaa366

Please sign in to comment.