Skip to content

Commit

Permalink
Update videojs (tested 5-7). Update Play, Seek, Pause Event (#30)
Browse files Browse the repository at this point in the history
* Update videojs dep, play event resets secondsToLoad on ended

* Add GitHub Pull Request Template

* Greater than 5.20.5

* Update lock

Co-authored-by: spodlecki <spodlecki@skintertainment.com>
  • Loading branch information
spodlecki and spodlecki authored Mar 21, 2022
1 parent 04ef396 commit fc42db7
Show file tree
Hide file tree
Showing 13 changed files with 713 additions and 747 deletions.
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

7 changes: 7 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## PR Description, what changed?

- List out changes

## Steps for testing

- List out any testing steps
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ node_modules/
dist/
docs/api/
test/dist/
.eslintcache
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v17.2.0
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v17.2.0
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ before_script:
env:
- VJS=5
- VJS=6
- VJS=7
addons:
firefox: latest
apt:
Expand Down
10 changes: 10 additions & 0 deletions examples/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
log(e.type, data);
});

player.on('error', function(e) {
log(e.type, { message: e.message });
});

player.on('tracking:play', function(e, data) {
log(e.type, data);
});

player.on('tracking:pause', function(e, data) {
log(e.type, data);
});
Expand Down Expand Up @@ -71,4 +79,6 @@
player.on('tracking:seek', function(e, data) {
log(e.type, data);
});

log('videojs', { version: videojs.VERSION });
}(window, window.videojs));
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@
"test/"
],
"dependencies": {
"global": "^4.3.2",
"video.js": "^7.0.0"
"video.js": ">=5.20.5"
},
"devDependencies": {
"babel-plugin-external-helpers": "^6.22.0",
Expand Down
10 changes: 9 additions & 1 deletion src/tracking/pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const PauseTracking = function(config) {
let pauseCount = 0;
let timer = null;
let locked = false;

const reset = function(e) {
if (timer) {
clearTimeout(timer);
Expand All @@ -25,11 +26,18 @@ const PauseTracking = function(config) {
locked = false;
};

const isSeeking = function() {
return (
typeof (player.seeking) === 'function' && player.seeking() ||
typeof (player.scrubbing) === 'function' && player.scrubbing()
);
};

player.on('dispose', reset);
player.on('loadstart', reset);
player.on('ended', reset);
player.on('pause', function() {
if (player.scrubbing() || locked) {
if (isSeeking() || locked) {
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/tracking/performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ const PerformanceTracking = function(config) {
if (totalDuration > 0) {
trigger();
}

reset();
});

player.on('ended', triggerAndReset);
player.on('dispose', triggerAndReset);
player.on('timeupdate', function() {
Expand Down
9 changes: 5 additions & 4 deletions src/tracking/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/

const PlayTracking = function(config) {
let firstplay = false;
let hasBeenTriggered = false;
let loadstart = 0;
let loadend = 0;
let secondsToLoad = 0;

const reset = function() {
firstplay = false;
hasBeenTriggered = false;
loadstart = 0;
loadend = 0;
secondsToLoad = 0;
Expand All @@ -40,14 +40,15 @@ const PlayTracking = function(config) {
};

const onPlaying = () => {
if (!firstplay) {
firstplay = true;
if (!hasBeenTriggered) {
hasBeenTriggered = true;
this.trigger('tracking:firstplay', {
secondsToLoad: +(secondsToLoad.toFixed(3))
});
}
};

this.on('ended', reset);
this.on('dispose', reset);
this.on('loadstart', onLoadStart);
this.on('loadeddata', onLoadedData);
Expand Down
12 changes: 2 additions & 10 deletions src/tracking/seek.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,15 @@
const SeekTracking = function(config) {
const player = this;
let seekCount = 0;
let locked = true;

const reset = function() {
seekCount = 0;
locked = true;
};

player.on('dispose', reset);
player.on('loadstart', reset);
player.on('ended', reset);
player.on('play', () => {
locked = false;
});
player.on('pause', function() {
if (locked || !player.scrubbing()) {
return;
}

player.on('seeking', function() {
const curTime = +player.currentTime().toFixed(0);

seekCount++;
Expand Down
Loading

0 comments on commit fc42db7

Please # to comment.