Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use ES6 classes instead of videojs.extend #93

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/js/components/QualityOption.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module.exports = function(videojs) {
* @class QualityOption
* @extends videojs.MenuItem
*/
return videojs.extend(MenuItem, {
return class QualityOption extends MenuItem {

/**
* @inheritdoc
*/
constructor: function(player, options) {
constructor(player, options) {
var source = options.source;

if (!_.isObject(source)) {
Expand All @@ -27,18 +27,17 @@ module.exports = function(videojs) {
label: source.label,
}, options);

MenuItem.call(this, player, options);
super(player, options);

this.source = source;
},
}

/**
* @inheritdoc
*/
handleClick: function(event) {
MenuItem.prototype.handleClick.call(this, event);
handleClick(event) {
super.handleClick(event);
this.player().trigger(events.QUALITY_REQUESTED, this.source);
},

});
}
};
};
28 changes: 13 additions & 15 deletions src/js/components/QualitySelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@ var _ = require('underscore'),

module.exports = function(videojs) {
var MenuButton = videojs.getComponent('MenuButton'),
QualityOption = qualityOptionFactory(videojs),
QualitySelector;
QualityOption = qualityOptionFactory(videojs);

/**
* A component for changing video resolutions
*
* @class QualitySelector
* @extends videojs.Button
*/
QualitySelector = videojs.extend(MenuButton, {
class QualitySelector extends MenuButton {

/**
* @inheritdoc
*/
constructor: function(player, options) {
MenuButton.call(this, player, options);
constructor(player, options) {
super(player, options);

// Update interface instantly so the user's change is acknowledged
player.on(events.QUALITY_REQUESTED, function(event, newSource) {
Expand Down Expand Up @@ -50,14 +49,14 @@ module.exports = function(videojs) {
}.bind(this));

this.controlText('Open quality selector menu');
},
}

/**
* Updates the source that is selected in the menu
*
* @param source {object} player source to display as selected
*/
setSelectedSource: function(source) {
setSelectedSource(source) {
var src = (source ? source.src : undefined);

if (this.selectedSrc !== src) {
Expand All @@ -66,12 +65,12 @@ module.exports = function(videojs) {
item.selected(item.source.src === src);
});
}
},
}

/**
* @inheritdoc
*/
createItems: function() {
createItems() {
var player = this.player(),
sources = player.currentSources();

Expand All @@ -85,16 +84,15 @@ module.exports = function(videojs) {
selected: source.src === this.selectedSrc,
});
}.bind(this));
},
}

/**
* @inheritdoc
*/
buildWrapperCSSClass: function() {
return 'vjs-quality-selector ' + MenuButton.prototype.buildWrapperCSSClass.call(this);
},

});
buildWrapperCSSClass() {
return 'vjs-quality-selector ' + super.buildWrapperCSSClass();
}
}

videojs.registerComponent('QualitySelector', QualitySelector);

Expand Down