refactor: use es6 classes

Adds babel and uses es6 classes instead of class.extend
This commit is contained in:
Craig Weber 2022-07-19 12:23:30 -04:00
parent 9c44e09096
commit 03c63eae66
No known key found for this signature in database
13 changed files with 4554 additions and 550 deletions

View file

@ -1,5 +1,4 @@
{ {
"extends": "@silvermine/eslint-config/node",
"extends": "@silvermine/eslint-config/node" "parser": "babel-eslint"
} }

View file

@ -2,9 +2,6 @@
* Copyright (c) 2017 Jeremy Thomerson * Copyright (c) 2017 Jeremy Thomerson
* Licensed under the MIT license. * Licensed under the MIT license.
*/ */
'use strict';
var path = require('path'), var path = require('path'),
getCodeVersion = require('silvermine-serverless-utils/src/get-code-version'); getCodeVersion = require('silvermine-serverless-utils/src/get-code-version');
@ -52,6 +49,26 @@ module.exports = function(grunt) {
main: { main: {
src: config.js.standalone, src: config.js.standalone,
dest: config.dist.js.bundle, dest: config.dist.js.bundle,
options: {
transform: [
[
'babelify',
{
presets: [
[
'@babel/preset-env',
{
debug: true,
useBuiltIns: 'usage',
shippedProposals: true,
corejs: 3,
},
],
],
},
],
],
},
}, },
}, },

View file

@ -1,5 +1,3 @@
'use strict';
module.exports = { module.exports = {
extends: [ '@silvermine/standardization/commitlint.js' ], extends: [ '@silvermine/standardization/commitlint.js' ],
}; };

5011
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -33,9 +33,17 @@
}, },
"homepage": "https://github.com/silvermine/videojs-quality-selector#readme", "homepage": "https://github.com/silvermine/videojs-quality-selector#readme",
"devDependencies": { "devDependencies": {
"@babel/core": "7.13.16",
"@babel/preset-env": "7.13.15",
"@commitlint/cli": "8.3.5",
"@commitlint/travis-cli": "8.3.5",
"@silvermine/eslint-config": "3.0.1", "@silvermine/eslint-config": "3.0.1",
"@silvermine/standardization": "2.0.0", "@silvermine/standardization": "2.0.0",
"autoprefixer": "8.6.5", "autoprefixer": "8.6.5",
"babelify": "10.0.0",
"babel-eslint": "10.1.0",
"check-node-version": "4.0.3",
"core-js": "3.11.0",
"coveralls": "3.0.3", "coveralls": "3.0.3",
"eslint": "6.8.0", "eslint": "6.8.0",
"expect.js": "0.3.1", "expect.js": "0.3.1",
@ -62,7 +70,6 @@
"video.js": ">=6.0.0" "video.js": ">=6.0.0"
}, },
"dependencies": { "dependencies": {
"class.extend": "0.9.1",
"underscore": "1.13.1" "underscore": "1.13.1"
} }
} }

View file

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'), var _ = require('underscore'),
events = require('../events'); events = require('../events');

View file

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'), var _ = require('underscore'),
events = require('../events'), events = require('../events'),
qualityOptionFactory = require('./QualityOption'), qualityOptionFactory = require('./QualityOption'),

View file

@ -1,9 +1,5 @@
'use strict';
module.exports = { module.exports = {
QUALITY_REQUESTED: 'qualityRequested', QUALITY_REQUESTED: 'qualityRequested',
QUALITY_SELECTED: 'qualitySelected', QUALITY_SELECTED: 'qualitySelected',
PLAYER_SOURCES_CHANGED: 'playerSourcesChanged', PLAYER_SOURCES_CHANGED: 'playerSourcesChanged',
}; };

View file

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'), var _ = require('underscore'),
events = require('./events'), events = require('./events'),
qualitySelectorFactory = require('./components/QualitySelector'), qualitySelectorFactory = require('./components/QualitySelector'),

View file

@ -1,5 +1,3 @@
'use strict';
var _ = require('underscore'), var _ = require('underscore'),
events = require('../events'); events = require('../events');

View file

@ -1,3 +1 @@
'use strict';
require('./index')(); require('./index')();

View file

@ -1,17 +1,13 @@
'use strict'; class SafeSeek {
constructor(player, seekToTime) {
var Class = require('class.extend');
module.exports = Class.extend({
init: function(player, seekToTime) {
this._player = player; this._player = player;
this._seekToTime = seekToTime; this._seekToTime = seekToTime;
this._hasFinished = false; this._hasFinished = false;
this._keepThisInstanceWhenPlayerSourcesChange = false; this._keepThisInstanceWhenPlayerSourcesChange = false;
this._seekWhenSafe(); this._seekWhenSafe();
}, }
_seekWhenSafe: function() { _seekWhenSafe() {
var HAVE_FUTURE_DATA = 3; var HAVE_FUTURE_DATA = 3;
// `readyState` in Video.js is the same as the HTML5 Media element's `readyState` // `readyState` in Video.js is the same as the HTML5 Media element's `readyState`
@ -35,9 +31,9 @@ module.exports = Class.extend({
} else { } else {
this._seek(); this._seek();
} }
}, }
onPlayerSourcesChange: function() { onPlayerSourcesChange() {
if (this._keepThisInstanceWhenPlayerSourcesChange) { if (this._keepThisInstanceWhenPlayerSourcesChange) {
// By setting this to `false`, we know that if the player sources change again // By setting this to `false`, we know that if the player sources change again
// the change did not originate from a quality selection change, the new sources // the change did not originate from a quality selection change, the new sources
@ -47,9 +43,9 @@ module.exports = Class.extend({
} else { } else {
this.cancel(); this.cancel();
} }
}, }
onQualitySelectionChange: function() { onQualitySelectionChange() {
// `onPlayerSourcesChange` will cancel this pending seek unless we tell it not to. // `onPlayerSourcesChange` will cancel this pending seek unless we tell it not to.
// We need to reuse this same pending seek instance because when the player is // We need to reuse this same pending seek instance because when the player is
// paused, the `preload` attribute is set to `none`, and the user selects one // paused, the `preload` attribute is set to `none`, and the user selects one
@ -60,21 +56,23 @@ module.exports = Class.extend({
if (!this.hasFinished()) { if (!this.hasFinished()) {
this._keepThisInstanceWhenPlayerSourcesChange = true; this._keepThisInstanceWhenPlayerSourcesChange = true;
} }
}, }
_seek: function() { _seek() {
this._player.currentTime(this._seekToTime); this._player.currentTime(this._seekToTime);
this._keepThisInstanceWhenPlayerSourcesChange = false; this._keepThisInstanceWhenPlayerSourcesChange = false;
this._hasFinished = true; this._hasFinished = true;
}, }
hasFinished: function() { hasFinished() {
return this._hasFinished; return this._hasFinished;
}, }
cancel: function() { cancel() {
this._player.off('canplay', this._seekFn); this._player.off('canplay', this._seekFn);
this._keepThisInstanceWhenPlayerSourcesChange = false; this._keepThisInstanceWhenPlayerSourcesChange = false;
this._hasFinished = true; this._hasFinished = true;
}, }
}); }
module.exports = SafeSeek;

View file

@ -1,5 +1,3 @@
'use strict';
var expect = require('expect.js'); var expect = require('expect.js');
describe('Everything', function() { describe('Everything', function() {