-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathplugin.js
More file actions
97 lines (83 loc) · 2.61 KB
/
plugin.js
File metadata and controls
97 lines (83 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import videojs from 'video.js';
import './quality-menu-button.js';
import {version as VERSION} from '../package.json';
// Default options for the plugin.
const defaults = {
sdBitrateLimit: 2000000,
useResolutionLabels: true,
resolutionLabelBitrates: false,
defaultResolution: 'none',
measureShortEdge: false
};
/**
* Function to invoke when the player is ready.
*
* This is a great place for your plugin to initialize itself. When this
* function is called, the player will have its DOM and child components
* in place.
*
* @function onPlayerReady
* @param {Player} player
* A Video.js player.
* @param {Object} [options={}]
* An object of options left to the plugin author to define.
* @return {Function} disposal function for re initialization
*/
const onPlayerReady = (player, options) => {
player.addClass('vjs-quality-menu');
const controlBar = player.getChild('controlBar');
const button = controlBar.addChild(
'QualityMenuButton',
options,
controlBar.children_.length - 2
);
return function() {
player.removeClass('vjs-quality-menu');
controlBar.removeChild(button);
button.dispose();
};
};
/**
* Main entry point for the plugin
*
* @function initPlugin
* @param {Player} player a reference to a videojs Player instance
* @param {Object} [options] an object with plugin options
*/
const initPlugin = function(player, options) {
if (typeof player.qualityLevels !== 'undefined') {
// call qualityLevels to initialize it in case it hasnt been initialized yet
player.qualityLevels();
let disposeFn = () => {};
player.ready(() => {
disposeFn = onPlayerReady(player, options);
player.on('loadstart', () => {
disposeFn();
disposeFn = onPlayerReady(player, options);
});
});
// reinitialization is no-op for now
player.qualityMenu = () => {};
player.qualityMenu.VERSION = VERSION;
}
};
/**
* A video.js plugin.
*
* In the plugin function, the value of `this` is a video.js `Player`
* instance. You cannot rely on the player being in a "ready" state here,
* depending on how the plugin is invoked. This may or may not be important
* to you; if not, remove the wait for "ready"!
*
* @function qualityMenu
* @param {Object} [options={}]
* An object of options left to the plugin author to define.
*/
const qualityMenu = function(options) {
initPlugin(this, videojs.obj.merge(defaults, options));
};
// Register the plugin with video.js.
videojs.registerPlugin('qualityMenu', qualityMenu);
// Include the version number.
qualityMenu.VERSION = VERSION;
export default qualityMenu;