cloudinary-video-player 1.6.2-edge.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +4 -0
- package/.snyk +19 -0
- package/.travis.yml +8 -0
- package/CHANGELOG.md +329 -0
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/dist/cld-video-player.css +2110 -0
- package/dist/cld-video-player.js +5249 -0
- package/dist/cld-video-player.light.css +1766 -0
- package/dist/cld-video-player.light.js +1399 -0
- package/dist/cld-video-player.light.min.css +1 -0
- package/dist/cld-video-player.light.min.js +2 -0
- package/dist/cld-video-player.light.min.js.LICENSE.txt +23 -0
- package/dist/cld-video-player.min.css +1 -0
- package/dist/cld-video-player.min.js +2 -0
- package/dist/cld-video-player.min.js.LICENSE.txt +26 -0
- package/dist/fonts/cloudinary_icon_for_black_bg.svg +69 -0
- package/dist/fonts/cloudinary_icon_for_white_bg.svg +69 -0
- package/docs/360.html +102 -0
- package/docs/_template.html +93 -0
- package/docs/adaptive-streaming.html +297 -0
- package/docs/analytics.html +140 -0
- package/docs/api.html +302 -0
- package/docs/audio.html +136 -0
- package/docs/autoplay-fallback.html +138 -0
- package/docs/autoplay-on-scroll.html +107 -0
- package/docs/codec-fallback.html +158 -0
- package/docs/colors.html +135 -0
- package/docs/components.html +284 -0
- package/docs/custom-cld-errors.html +134 -0
- package/docs/floating-player.html +98 -0
- package/docs/fluid.html +117 -0
- package/docs/force-hls-subtitles-ios.html +159 -0
- package/docs/index.html +83 -0
- package/docs/interaction-area.html +398 -0
- package/docs/live-customer.html +128 -0
- package/docs/multiple-players.html +125 -0
- package/docs/playlist-by-tag-cap.html +182 -0
- package/docs/playlist-by-tag.html +133 -0
- package/docs/playlist.html +133 -0
- package/docs/poster.html +155 -0
- package/docs/raw-url.html +104 -0
- package/docs/recommendations.html +155 -0
- package/docs/scripts.js +156 -0
- package/docs/seek-thumbs.html +90 -0
- package/docs/shoppable.html +335 -0
- package/docs/subtitles-and-captions.html +267 -0
- package/docs/transformations.html +171 -0
- package/docs/ui-config.html +108 -0
- package/docs/vast-vpaid.html +149 -0
- package/env.example.js +6 -0
- package/env.js +6 -0
- package/jest-puppeteer.config.js +14 -0
- package/jest.config.js +196 -0
- package/package.json +99 -0
- package/sandbox.config.json +3 -0
- package/setupJest.js +1 -0
- package/src/assets/fonts/VideoJS.svg +120 -0
- package/src/assets/fonts/VideoJS.ttf +0 -0
- package/src/assets/fonts/VideoJS.woff +0 -0
- package/src/assets/fonts/icons.json +120 -0
- package/src/assets/icons/cloudinary_icon_for_black_bg.svg +69 -0
- package/src/assets/icons/cloudinary_icon_for_white_bg.svg +69 -0
- package/src/assets/icons/cloudinary_logo_for_dark_bg.svg +188 -0
- package/src/assets/icons/cloudinary_logo_for_white_bg.svg +188 -0
- package/src/assets/icons/info-circle.svg +17 -0
- package/src/assets/styles/ads-label.scss +16 -0
- package/src/assets/styles/components/interaction-areas.scss +158 -0
- package/src/assets/styles/components/playlist.scss +213 -0
- package/src/assets/styles/components/themedButton.scss +48 -0
- package/src/assets/styles/components/thumbnail.scss +94 -0
- package/src/assets/styles/components/title-bar.scss +67 -0
- package/src/assets/styles/components/triangle-volume-bar.scss +52 -0
- package/src/assets/styles/icons.scss +257 -0
- package/src/assets/styles/main.scss +324 -0
- package/src/assets/styles/mixins/aspect-ratio.scss +16 -0
- package/src/assets/styles/mixins/disable-transition.scss +3 -0
- package/src/assets/styles/mixins/mixins.scss +5 -0
- package/src/assets/styles/mixins/skin.scss +64 -0
- package/src/assets/styles/variables.scss +2 -0
- package/src/assets/styles/videojs-ima.scss +252 -0
- package/src/components/component-utils.js +20 -0
- package/src/components/index.js +21 -0
- package/src/components/interaction-area/interaction-area.const.js +30 -0
- package/src/components/interaction-area/interaction-area.service.js +223 -0
- package/src/components/interaction-area/interaction-area.utils.js +236 -0
- package/src/components/jumpButtons/jump-10-minus.js +21 -0
- package/src/components/jumpButtons/jump-10-plus.js +20 -0
- package/src/components/logoButton/logo-button.const.js +3 -0
- package/src/components/logoButton/logo-button.js +30 -0
- package/src/components/logoButton/logo-button.scss +15 -0
- package/src/components/playlist/components/playlist-button.js +34 -0
- package/src/components/playlist/components/playlist-next-button.js +18 -0
- package/src/components/playlist/components/playlist-previous-button.js +18 -0
- package/src/components/playlist/components/playlist.js +5 -0
- package/src/components/playlist/components/playlist.scss +15 -0
- package/src/components/playlist/components/upcoming-video-overlay.js +149 -0
- package/src/components/playlist/components/upcoming-video-overlay.scss +86 -0
- package/src/components/playlist/layout/playlist-layout-custom.js +21 -0
- package/src/components/playlist/layout/playlist-layout-horizontal.js +16 -0
- package/src/components/playlist/layout/playlist-layout-vertical.js +19 -0
- package/src/components/playlist/layout/playlist-layout.js +110 -0
- package/src/components/playlist/panel/playlist-panel-item.js +86 -0
- package/src/components/playlist/panel/playlist-panel.js +92 -0
- package/src/components/playlist/playlist-widget.js +119 -0
- package/src/components/playlist/playlist.const.js +14 -0
- package/src/components/playlist/playlist.js +413 -0
- package/src/components/playlist/thumbnail/thumbnail.js +69 -0
- package/src/components/progress-control-events-blocker/progress-control-events-blocker.js +17 -0
- package/src/components/qualitySelector/quality-selector.scss +10 -0
- package/src/components/qualitySelector/qualitySelector.js +152 -0
- package/src/components/recommendations-overlay/index.js +3 -0
- package/src/components/recommendations-overlay/recommendations-overlay-content.js +57 -0
- package/src/components/recommendations-overlay/recommendations-overlay-hide-button.js +18 -0
- package/src/components/recommendations-overlay/recommendations-overlay-item.js +35 -0
- package/src/components/recommendations-overlay/recommendations-overlay-primary-item.js +81 -0
- package/src/components/recommendations-overlay/recommendations-overlay-secondary-item.js +48 -0
- package/src/components/recommendations-overlay/recommendations-overlay-secondary-items-container.js +35 -0
- package/src/components/recommendations-overlay/recommendations-overlay.js +94 -0
- package/src/components/recommendations-overlay/recommendations-overlay.scss +182 -0
- package/src/components/shoppable-bar/layout/bar-layout.js +111 -0
- package/src/components/shoppable-bar/layout/shoppable-panel-toggle.js +64 -0
- package/src/components/shoppable-bar/layout/shoppable-products-overlay.js +87 -0
- package/src/components/shoppable-bar/panel/shoppable-panel-item.js +105 -0
- package/src/components/shoppable-bar/panel/shoppable-panel.js +172 -0
- package/src/components/shoppable-bar/shoppable-post-widget.js +110 -0
- package/src/components/shoppable-bar/shoppable-widget.const.js +52 -0
- package/src/components/shoppable-bar/shoppable-widget.js +111 -0
- package/src/components/shoppable-bar/shoppable-widget.scss +359 -0
- package/src/components/themeButton/themedButton.const.js +3 -0
- package/src/components/themeButton/themedButton.js +25 -0
- package/src/components/title-bar/title-bar.js +79 -0
- package/src/config/defaults.js +25 -0
- package/src/extended-events.js +228 -0
- package/src/index.js +18 -0
- package/src/mixins/eventable.js +54 -0
- package/src/mixins/playlistable.js +106 -0
- package/src/plugins/analytics/index.js +245 -0
- package/src/plugins/autoplay-on-scroll/index.js +86 -0
- package/src/plugins/cloudinary/common.js +216 -0
- package/src/plugins/cloudinary/event-handler-registry.js +46 -0
- package/src/plugins/cloudinary/index.js +345 -0
- package/src/plugins/cloudinary/models/audio-source/audio-source.const.js +11 -0
- package/src/plugins/cloudinary/models/audio-source/audio-source.js +82 -0
- package/src/plugins/cloudinary/models/base-source.js +107 -0
- package/src/plugins/cloudinary/models/image-source.js +26 -0
- package/src/plugins/cloudinary/models/video-source/video-source.const.js +32 -0
- package/src/plugins/cloudinary/models/video-source/video-source.js +239 -0
- package/src/plugins/cloudinary/models/video-source/video-source.utils.js +57 -0
- package/src/plugins/colors/index.js +303 -0
- package/src/plugins/context-menu/components/context-menu-item.js +12 -0
- package/src/plugins/context-menu/components/context-menu.js +63 -0
- package/src/plugins/context-menu/context-menu.scss +30 -0
- package/src/plugins/context-menu/contextMenuContent.js +53 -0
- package/src/plugins/context-menu/index.js +134 -0
- package/src/plugins/dash/index.js +26 -0
- package/src/plugins/dash/setup-audio-tracks.js +112 -0
- package/src/plugins/dash/setup-text-tracks.js +195 -0
- package/src/plugins/dash/videojs-dash.js +372 -0
- package/src/plugins/floating-player/floating-player.scss +74 -0
- package/src/plugins/floating-player/index.js +129 -0
- package/src/plugins/ima/index.js +1775 -0
- package/src/plugins/index.js +31 -0
- package/src/plugins/interactive-plugin/index.js +10 -0
- package/src/plugins/videojs-http-source-selector/components/SourceMenuButton.js +98 -0
- package/src/plugins/videojs-http-source-selector/components/SourceMenuItem.js +52 -0
- package/src/plugins/videojs-http-source-selector/plugin.js +82 -0
- package/src/plugins/videojs-http-source-selector/plugin.scss +9 -0
- package/src/plugins/vtt-thumbnails/index.js +526 -0
- package/src/plugins/vtt-thumbnails/vtt-thumbnails.scss +29 -0
- package/src/utils/api.js +32 -0
- package/src/utils/apply-with-props.js +32 -0
- package/src/utils/array.js +22 -0
- package/src/utils/assign.js +27 -0
- package/src/utils/attributes-normalizer.js +72 -0
- package/src/utils/cloudinary.js +165 -0
- package/src/utils/css-prefix.js +43 -0
- package/src/utils/dom.js +74 -0
- package/src/utils/find.js +28 -0
- package/src/utils/fontFace.js +25 -0
- package/src/utils/groupBy.js +12 -0
- package/src/utils/index.js +29 -0
- package/src/utils/matches.js +11 -0
- package/src/utils/mixin.js +5 -0
- package/src/utils/object.js +26 -0
- package/src/utils/playButton.js +9 -0
- package/src/utils/positioning.js +78 -0
- package/src/utils/querystring.js +12 -0
- package/src/utils/slicing.js +21 -0
- package/src/utils/string.js +15 -0
- package/src/utils/throttle.js +30 -0
- package/src/utils/time.js +77 -0
- package/src/utils/type-inference.js +35 -0
- package/src/validators/validators-functions.js +48 -0
- package/src/validators/validators-types.js +78 -0
- package/src/validators/validators.js +110 -0
- package/src/video-player.const.js +68 -0
- package/src/video-player.js +761 -0
- package/src/video-player.utils.js +123 -0
- package/test/adaptive-streaming.test.js +38 -0
- package/test/ads.test.js +35 -0
- package/test/analytics.test.js +111 -0
- package/test/api.test.js +111 -0
- package/test/autoplay.scroll.test.js +23 -0
- package/test/basic-ui.test.js +59 -0
- package/test/colors.test.js +58 -0
- package/test/components.test.js +21 -0
- package/test/custom-error.test.js +24 -0
- package/test/fluid.test.js +36 -0
- package/test/isValidConfig.test.js +224 -0
- package/test/mocks/cloudinary-core-mock.js +0 -0
- package/test/mocks/styleMock.js +1 -0
- package/test/multiplayer.test.js +25 -0
- package/test/playlist.test.js +60 -0
- package/test/puppeteer/vp-env.js +19 -0
- package/test/recommendations.test.js +38 -0
- package/test/title-bar.test.js +28 -0
- package/test/ui-conf.test.js +49 -0
- package/test/unit/cloudinaryConfig.test.js +22 -0
- package/test/unit/cloudinaryUtils.test.js +53 -0
- package/test/unit/utils.test.js +27 -0
- package/test/unit/videoSource.test.js +454 -0
- package/tsconfig.json +15 -0
- package/types/video-player-tests.js +12 -0
- package/types/video-player-tests.ts +31 -0
- package/types/video-player.d.ts +570 -0
|
@@ -0,0 +1,761 @@
|
|
|
1
|
+
import videojs from 'video.js';
|
|
2
|
+
import './components';
|
|
3
|
+
import plugins from './plugins';
|
|
4
|
+
import Utils from './utils';
|
|
5
|
+
import defaults from './config/defaults';
|
|
6
|
+
import Eventable from './mixins/eventable';
|
|
7
|
+
import ExtendedEvents from './extended-events';
|
|
8
|
+
import PlaylistWidget from './components/playlist/playlist-widget';
|
|
9
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
10
|
+
import qualitySelector from './components/qualitySelector/qualitySelector.js';
|
|
11
|
+
// #endif
|
|
12
|
+
import VideoSource from './plugins/cloudinary/models/video-source/video-source';
|
|
13
|
+
import { isFunction, isString, isPlainObject } from './utils/type-inference';
|
|
14
|
+
import {
|
|
15
|
+
extractOptions,
|
|
16
|
+
getResolveVideoElement,
|
|
17
|
+
overrideDefaultVideojsComponents
|
|
18
|
+
} from './video-player.utils';
|
|
19
|
+
import { FLOATING_TO, FLUID_CLASS_NAME } from './video-player.const';
|
|
20
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
21
|
+
import { interactionAreaService } from './components/interaction-area/interaction-area.service';
|
|
22
|
+
// #endif
|
|
23
|
+
import { isValidConfig } from './validators/validators-functions';
|
|
24
|
+
import { playerValidators, sourceValidators } from './validators/validators';
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
// Register all plugins
|
|
28
|
+
Object.keys(plugins).forEach((key) => {
|
|
29
|
+
videojs.registerPlugin(key, plugins[key]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
overrideDefaultVideojsComponents();
|
|
33
|
+
|
|
34
|
+
let _allowUsageReport = true;
|
|
35
|
+
|
|
36
|
+
class VideoPlayer extends Utils.mixin(Eventable) {
|
|
37
|
+
|
|
38
|
+
static all(selector, ...args) {
|
|
39
|
+
const nodeList = document.querySelectorAll(selector);
|
|
40
|
+
const players = [];
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < nodeList.length; i++) {
|
|
43
|
+
players.push(new VideoPlayer(nodeList[i], ...args));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return players;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static allowUsageReport(bool) {
|
|
50
|
+
if (bool === undefined) {
|
|
51
|
+
return _allowUsageReport;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_allowUsageReport = !!bool;
|
|
55
|
+
return _allowUsageReport;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static buildTextTrackObj (type, conf) {
|
|
59
|
+
return {
|
|
60
|
+
kind: type,
|
|
61
|
+
label: conf.label,
|
|
62
|
+
srclang: conf.language,
|
|
63
|
+
default: !!(conf.default),
|
|
64
|
+
src: conf.url
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
constructor(elem, initOptions, ready) {
|
|
69
|
+
super();
|
|
70
|
+
|
|
71
|
+
this._playlistWidget = null;
|
|
72
|
+
this.nbCalls = 0;
|
|
73
|
+
this._firstPlayed = false;
|
|
74
|
+
|
|
75
|
+
this.videoElement = getResolveVideoElement(elem);
|
|
76
|
+
|
|
77
|
+
this.options = extractOptions(this.videoElement, initOptions);
|
|
78
|
+
|
|
79
|
+
this._videojsOptions = this.options.videojsOptions;
|
|
80
|
+
|
|
81
|
+
// Make sure to add 'video-js' class before creating videojs instance
|
|
82
|
+
this.videoElement.classList.add('video-js');
|
|
83
|
+
|
|
84
|
+
// Handle WebFont loading
|
|
85
|
+
Utils.fontFace(this.videoElement, this.playerOptions);
|
|
86
|
+
|
|
87
|
+
// Handle play button options
|
|
88
|
+
Utils.playButton(this.videoElement, this._videojsOptions);
|
|
89
|
+
|
|
90
|
+
// Dash plugin - available in full (not light) build only
|
|
91
|
+
if (plugins.dashPlugin) {
|
|
92
|
+
plugins.dashPlugin();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.videojs = videojs(this.videoElement, this._videojsOptions);
|
|
96
|
+
|
|
97
|
+
this._isPlayerConfigValid = isValidConfig(this.options, playerValidators);
|
|
98
|
+
|
|
99
|
+
if (!this._isPlayerConfigValid) {
|
|
100
|
+
this.videojs.error('invalid player configuration');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (this._videojsOptions.muted) {
|
|
105
|
+
this.videojs.volume(0.4);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (this.playerOptions.fluid) {
|
|
109
|
+
this.fluid(this.playerOptions.fluid);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/* global google */
|
|
113
|
+
const loaded = {
|
|
114
|
+
contribAdsLoaded: isFunction(this.videojs.ads),
|
|
115
|
+
imaAdsLoaded: (typeof google === 'object' && typeof google.ima === 'object')
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
119
|
+
this.interactionArea = interactionAreaService(this, this.playerOptions, this._videojsOptions);
|
|
120
|
+
// #endif
|
|
121
|
+
|
|
122
|
+
this._setCssClasses();
|
|
123
|
+
this._initPlugins(loaded);
|
|
124
|
+
this._initPlaylistWidget();
|
|
125
|
+
this._initJumpButtons();
|
|
126
|
+
this._setVideoJsListeners(ready);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
_setVideoJsListeners(ready) {
|
|
130
|
+
|
|
131
|
+
this.videojs.on('error', () => {
|
|
132
|
+
const error = this.videojs.error();
|
|
133
|
+
if (error) {
|
|
134
|
+
const type = this._isPlayerConfigValid && this.videojs.cloudinary.currentSourceType();
|
|
135
|
+
if (error.code === 4 && (type === 'VideoSource' || type === 'AudioSource')) {
|
|
136
|
+
this.videojs.error(null);
|
|
137
|
+
Utils.handleCldError(this, this.playerOptions);
|
|
138
|
+
} else {
|
|
139
|
+
this.videojs.clearTimeout(this.reTryId);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
this.videojs.on('play', () => {
|
|
145
|
+
this.videojs.clearTimeout(this.reTryId);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
this.videojs.on('canplaythrough', () => {
|
|
149
|
+
this.videojs.clearTimeout(this.reTryId);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
this.videojs.ready(() => {
|
|
153
|
+
this._onReady();
|
|
154
|
+
|
|
155
|
+
if (ready) {
|
|
156
|
+
ready(this);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
160
|
+
this.interactionArea.init();
|
|
161
|
+
// #endif
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (this.adsEnabled && Object.keys(this.playerOptions.ads).length > 0 && typeof this.videojs.ima === 'object') {
|
|
165
|
+
if (this.playerOptions.ads.adsInPlaylist === 'first-video') {
|
|
166
|
+
this.videojs.one('sourcechanged', () => {
|
|
167
|
+
this.videojs.ima.playAd();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
} else {
|
|
171
|
+
this.videojs.on('sourcechanged', () => {
|
|
172
|
+
this.videojs.ima.playAd();
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_initPlugins (loaded) {
|
|
180
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
181
|
+
this.adsEnabled = this._initIma(loaded);
|
|
182
|
+
// #endif
|
|
183
|
+
this._initAutoplay();
|
|
184
|
+
this._initContextMenu();
|
|
185
|
+
this._initPerSrcBehaviors();
|
|
186
|
+
this._initCloudinary();
|
|
187
|
+
this._initAnalytics();
|
|
188
|
+
this._initFloatingPlayer();
|
|
189
|
+
this._initColors();
|
|
190
|
+
this._initTextTracks();
|
|
191
|
+
this._initSeekThumbs();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
_isFullScreen() {
|
|
195
|
+
return this.videojs.player().isFullscreen();
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
_initIma (loaded) {
|
|
199
|
+
if (!loaded.contribAdsLoaded || !loaded.imaAdsLoaded) {
|
|
200
|
+
if (this.playerOptions.ads) {
|
|
201
|
+
if (!loaded.contribAdsLoaded) {
|
|
202
|
+
console.log('contribAds is not loaded');
|
|
203
|
+
}
|
|
204
|
+
if (!loaded.imaAdsLoaded) {
|
|
205
|
+
console.log('imaSdk is not loaded');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (!this.playerOptions.ads) {
|
|
213
|
+
this.playerOptions.ads = {};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const opts = this.playerOptions.ads;
|
|
217
|
+
|
|
218
|
+
if (Object.keys(opts).length === 0) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.videojs.ima({
|
|
223
|
+
id: this.el().id,
|
|
224
|
+
adTagUrl: opts.adTagUrl,
|
|
225
|
+
disableFlashAds: true,
|
|
226
|
+
prerollTimeout: opts.prerollTimeout || 5000,
|
|
227
|
+
postrollTimeout: opts.postrollTimeout || 5000,
|
|
228
|
+
showCountdown: (opts.showCountdown !== false),
|
|
229
|
+
adLabel: opts.adLabel || 'Advertisement',
|
|
230
|
+
locale: opts.locale || 'en',
|
|
231
|
+
autoPlayAdBreaks: (opts.autoPlayAdBreaks !== false),
|
|
232
|
+
debug: true
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
setTextTracks (conf) {
|
|
239
|
+
// remove current text tracks
|
|
240
|
+
const currentTracks = this.videojs.remoteTextTracks();
|
|
241
|
+
if (currentTracks) {
|
|
242
|
+
for (let i = currentTracks.tracks_.length - 1; i >= 0; i--) {
|
|
243
|
+
this.videojs.removeRemoteTextTrack(currentTracks.tracks_[i]);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (conf) {
|
|
247
|
+
const tracks = Object.keys(conf);
|
|
248
|
+
const allTracks = [];
|
|
249
|
+
for (const track of tracks) {
|
|
250
|
+
if (Array.isArray(conf[track])) {
|
|
251
|
+
const trks = conf[track];
|
|
252
|
+
for (let i = 0; i < trks.length; i++) {
|
|
253
|
+
allTracks.push(VideoPlayer.buildTextTrackObj(track, trks[i]));
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
allTracks.push(VideoPlayer.buildTextTrackObj(track, conf[track]));
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Utils.filterAndAddTextTracks(allTracks, this.videojs);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
_initSeekThumbs() {
|
|
265
|
+
if (this.playerOptions.seekThumbnails) {
|
|
266
|
+
|
|
267
|
+
this.videojs.on('cldsourcechanged', (e, { source }) => {
|
|
268
|
+
// Bail if...
|
|
269
|
+
|
|
270
|
+
if (source.getType() === 'AudioSource' || // it's an audio player
|
|
271
|
+
(this.videojs && this.videojs.activePlugins_ && this.videojs.activePlugins_.vr) // It's a VR (i.e. 360) video
|
|
272
|
+
) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const cloudinaryConfig = source.cloudinaryConfig();
|
|
277
|
+
const publicId = source.publicId();
|
|
278
|
+
|
|
279
|
+
const transformations = source.transformation().toOptions();
|
|
280
|
+
|
|
281
|
+
if (transformations && transformations.streaming_profile) {
|
|
282
|
+
delete transformations.streaming_profile;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
transformations.flags = transformations.flags || [];
|
|
286
|
+
transformations.flags.push('sprite');
|
|
287
|
+
|
|
288
|
+
// build VTT url
|
|
289
|
+
const vttSrc = cloudinaryConfig.video_url(publicId + '.vtt', { transformation: transformations });
|
|
290
|
+
|
|
291
|
+
// vttThumbnails must be called differently on init and on source update.
|
|
292
|
+
if (isFunction(this.videojs.vttThumbnails)) {
|
|
293
|
+
this.videojs.vttThumbnails({ src: vttSrc });
|
|
294
|
+
} else {
|
|
295
|
+
this.videojs.vttThumbnails.src(vttSrc);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
_initColors () {
|
|
302
|
+
this.videojs.colors(this.playerOptions.colors ? { 'colors': this.playerOptions.colors } : {});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
306
|
+
_initQualitySelector() {
|
|
307
|
+
if (this._videojsOptions.controlBar && this.playerOptions.qualitySelector !== false) {
|
|
308
|
+
if (videojs.browser.IE_VERSION === null) {
|
|
309
|
+
this.videojs.httpSourceSelector({ default: 'auto' });
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
this.videojs.on('loadedmetadata', () => {
|
|
313
|
+
qualitySelector.init(this.videojs);
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Show only if more then one option available
|
|
317
|
+
this.videojs.on('loadeddata', () => {
|
|
318
|
+
qualitySelector.setVisibility(this.videojs);
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// #endif
|
|
323
|
+
|
|
324
|
+
_initTextTracks () {
|
|
325
|
+
this.videojs.on('refreshTextTracks', (e, tracks) => {
|
|
326
|
+
this.setTextTracks(tracks);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
_initPerSrcBehaviors() {
|
|
331
|
+
if (this.videojs.perSourceBehaviors) {
|
|
332
|
+
this.videojs.perSourceBehaviors();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
_initJumpButtons() {
|
|
337
|
+
if (!this.playerOptions.showJumpControls && this.videojs.controlBar) {
|
|
338
|
+
this.videojs.controlBar.removeChild('JumpForwardButton');
|
|
339
|
+
this.videojs.controlBar.removeChild('JumpBackButton');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
_initCloudinary() {
|
|
344
|
+
const opts = this.playerOptions.cloudinary;
|
|
345
|
+
opts.chainTarget = this;
|
|
346
|
+
if (opts.secure !== false) {
|
|
347
|
+
this.playerOptions.cloudinary.cloudinaryConfig.config('secure', true);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
this.videojs.cloudinary(this.playerOptions.cloudinary);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
_initAnalytics() {
|
|
354
|
+
const analyticsOpts = this.playerOptions.analytics;
|
|
355
|
+
|
|
356
|
+
if (!window.ga && analyticsOpts) {
|
|
357
|
+
console.error('Google Analytics script is missing');
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (analyticsOpts) {
|
|
362
|
+
const opts = typeof analyticsOpts === 'object' ? analyticsOpts : {};
|
|
363
|
+
this.videojs.analytics(opts);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
reTryVideo(maxNumberOfCalls, timeout) {
|
|
368
|
+
if (!this.isVideoReady()) {
|
|
369
|
+
if (this.nbCalls < maxNumberOfCalls) {
|
|
370
|
+
this.nbCalls++;
|
|
371
|
+
this.reTryId = this.videojs.setTimeout(() => this.reTryVideo(maxNumberOfCalls, timeout), timeout);
|
|
372
|
+
} else {
|
|
373
|
+
let e = new Error('Video is not ready please try later');
|
|
374
|
+
this.videojs.trigger('error', e);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
isVideoReady() {
|
|
380
|
+
const s = this.videojs.readyState();
|
|
381
|
+
if (s >= (/iPad|iPhone|iPod/.test(navigator.userAgent) ? 1 : 4)) {
|
|
382
|
+
this.nbCalls = 0;
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
_initPlaylistWidget () {
|
|
390
|
+
this.videojs.on('playlistcreated', () => {
|
|
391
|
+
|
|
392
|
+
if (this._playlistWidget) {
|
|
393
|
+
this._playlistWidget.dispose();
|
|
394
|
+
}
|
|
395
|
+
const plwOptions = this.playerOptions.playlistWidget;
|
|
396
|
+
|
|
397
|
+
if (isPlainObject(plwOptions)) {
|
|
398
|
+
if (this.playerOptions.fluid) {
|
|
399
|
+
plwOptions.fluid = true;
|
|
400
|
+
}
|
|
401
|
+
if (this.playerOptions.cloudinary.fontFace) {
|
|
402
|
+
plwOptions.fontFace = this.playerOptions.cloudinary.fontFace;
|
|
403
|
+
}
|
|
404
|
+
this._playlistWidget = new PlaylistWidget(this.videojs, plwOptions);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
playlistWidget(options) {
|
|
410
|
+
if (!options && !this._playlistWidget) {
|
|
411
|
+
return false;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (!options && this._playlistWidget) {
|
|
415
|
+
return this._playlistWidget;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (isPlainObject(options)) {
|
|
419
|
+
this._playlistWidget.options(options);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return this._playlistWidget;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
_initAutoplay() {
|
|
426
|
+
const autoplayMode = this.playerOptions.autoplayMode;
|
|
427
|
+
|
|
428
|
+
if (autoplayMode === 'on-scroll') {
|
|
429
|
+
this.videojs.autoplayOnScroll();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
_initContextMenu() {
|
|
434
|
+
if (!this.playerOptions.hideContextMenu) {
|
|
435
|
+
this.videojs.contextMenu(defaults.contextMenu);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
_initFloatingPlayer() {
|
|
440
|
+
if (this.playerOptions.floatingWhenNotVisible !== FLOATING_TO.NONE) {
|
|
441
|
+
this.videojs.floatingPlayer({ 'floatTo': this.playerOptions.floatingWhenNotVisible });
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
_setCssClasses() {
|
|
446
|
+
this.videojs.addClass(Utils.CLASS_PREFIX);
|
|
447
|
+
this.videojs.addClass(Utils.playerClassPrefix(this.videojs));
|
|
448
|
+
|
|
449
|
+
Utils.setSkinClassPrefix(this.videojs, Utils.skinClassPrefix(this.videojs));
|
|
450
|
+
|
|
451
|
+
if (videojs.browser.IE_VERSION === 11) {
|
|
452
|
+
this.videojs.addClass('cld-ie11');
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
_onReady() {
|
|
457
|
+
this._setExtendedEvents();
|
|
458
|
+
|
|
459
|
+
// Load first video (mainly to support video tag 'source' and 'public-id' attributes)
|
|
460
|
+
const source = this.playerOptions.source || this.playerOptions.publicId;
|
|
461
|
+
|
|
462
|
+
if (source) {
|
|
463
|
+
this.source(source, this.playerOptions);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
_setExtendedEvents() {
|
|
468
|
+
const events = [];
|
|
469
|
+
if (this.playerOptions.playedEventPercents) {
|
|
470
|
+
events.push({
|
|
471
|
+
type: 'percentsplayed',
|
|
472
|
+
percents: this.playerOptions.playedEventPercents
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (this.playerOptions.playedEventTimes) {
|
|
477
|
+
events.push({
|
|
478
|
+
type: 'timeplayed',
|
|
479
|
+
times: this.playerOptions.playedEventTimes
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
events.push(...['seek', 'mute', 'unmute', 'qualitychanged']);
|
|
484
|
+
|
|
485
|
+
const extendedEvents = new ExtendedEvents(this.videojs, { events });
|
|
486
|
+
|
|
487
|
+
Object.keys(extendedEvents.events).forEach((_event) => {
|
|
488
|
+
const handler = (event, data) => {
|
|
489
|
+
this.videojs.trigger({ type: _event, eventData: data });
|
|
490
|
+
};
|
|
491
|
+
extendedEvents.on(_event, handler);
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
cloudinaryConfig(config) {
|
|
496
|
+
return this.videojs.cloudinary.cloudinaryConfig(config);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
get playerOptions() {
|
|
500
|
+
return this.options.playerOptions;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
currentPublicId() {
|
|
504
|
+
return this.videojs.cloudinary.currentPublicId();
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
currentSourceUrl() {
|
|
508
|
+
return this.videojs.currentSource().src;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
currentPoster() {
|
|
512
|
+
return this.videojs.cloudinary.currentPoster();
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
source(publicId, options = {}) {
|
|
516
|
+
if (!this._isPlayerConfigValid) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const isSourceConfigValid = isValidConfig(options, sourceValidators);
|
|
521
|
+
|
|
522
|
+
if (!isSourceConfigValid) {
|
|
523
|
+
this.videojs.error('invalid source configuration');
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (publicId instanceof VideoSource) {
|
|
528
|
+
return this.videojs.cloudinary.source(publicId, options);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Interactive plugin - available in full (not light) build only
|
|
532
|
+
if (this.videojs.interactive) {
|
|
533
|
+
this.videojs.interactive(this.videojs, options);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
if (VideoPlayer.allowUsageReport()) {
|
|
537
|
+
options.usageReport = true;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
this.setTextTracks(options.textTracks);
|
|
541
|
+
// #if (!process.env.WEBPACK_BUILD_LIGHT)
|
|
542
|
+
this._initQualitySelector();
|
|
543
|
+
// #endif
|
|
544
|
+
clearTimeout(this.reTryId);
|
|
545
|
+
this.nbCalls = 0;
|
|
546
|
+
const maxTries = this.videojs.options_.maxTries || 3;
|
|
547
|
+
const videoReadyTimeout = this.videojs.options_.videoTimeout || 55000;
|
|
548
|
+
this.reTryVideo(maxTries, videoReadyTimeout);
|
|
549
|
+
return this.videojs.cloudinary.source(publicId, options);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
posterOptions(options) {
|
|
553
|
+
return this.videojs.cloudinary.posterOptions(options);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
skin(name) {
|
|
557
|
+
if (name !== undefined && isString(name)) {
|
|
558
|
+
Utils.setSkinClassPrefix(this.videojs, name);
|
|
559
|
+
|
|
560
|
+
const playlistWidget = this.playlistWidget();
|
|
561
|
+
|
|
562
|
+
if (this.playlistWidget()) {
|
|
563
|
+
playlistWidget.setSkin();
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return Utils.skinClassPrefix(this.videojs);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
playlist(sources, options = {}) {
|
|
571
|
+
return this.videojs.cloudinary.playlist(sources, options);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
playlistByTag(tag, options = {}) {
|
|
575
|
+
return this.videojs.cloudinary.playlistByTag(tag, options);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
sourcesByTag(tag, options = {}) {
|
|
579
|
+
return this.videojs.cloudinary.sourcesByTag(tag, options);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
fluid(bool) {
|
|
583
|
+
if (bool === undefined) {
|
|
584
|
+
return this.videojs.fluid();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (bool) {
|
|
588
|
+
this.videojs.addClass(FLUID_CLASS_NAME);
|
|
589
|
+
} else {
|
|
590
|
+
this.videojs.removeClass(FLUID_CLASS_NAME);
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
this.videojs.fluid(bool);
|
|
594
|
+
this.videojs.trigger('fluid', bool);
|
|
595
|
+
return this;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
play() {
|
|
599
|
+
this.playWasCalled = true;
|
|
600
|
+
this.videojs.play();
|
|
601
|
+
return this;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
stop() {
|
|
605
|
+
this.pause();
|
|
606
|
+
this.currentTime(0);
|
|
607
|
+
return this;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
playPrevious() {
|
|
611
|
+
this.playlist().playPrevious();
|
|
612
|
+
return this;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
playNext() {
|
|
616
|
+
this.playlist().playNext();
|
|
617
|
+
return this;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
transformation(trans) {
|
|
621
|
+
return this.videojs.cloudinary.transformation(trans);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
sourceTypes(types) {
|
|
625
|
+
return this.videojs.cloudinary.sourceTypes(types);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
sourceTransformation(trans) {
|
|
629
|
+
return this.videojs.cloudinary.sourceTransformation(trans);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
autoShowRecommendations(autoShow) {
|
|
633
|
+
return this.videojs.cloudinary.autoShowRecommendations(autoShow);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
duration() {
|
|
637
|
+
return this.videojs.duration();
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
height(dimension) {
|
|
641
|
+
if (!dimension) {
|
|
642
|
+
return this.videojs.height();
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
this.videojs.height(dimension);
|
|
646
|
+
|
|
647
|
+
return this;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
width(dimension) {
|
|
651
|
+
if (!dimension) {
|
|
652
|
+
return this.videojs.width();
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
this.videojs.width(dimension);
|
|
656
|
+
|
|
657
|
+
return this;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
volume(volume) {
|
|
661
|
+
if (!volume) {
|
|
662
|
+
return this.videojs.volume();
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
this.videojs.volume(volume);
|
|
666
|
+
|
|
667
|
+
return this;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
mute() {
|
|
671
|
+
if (!this.isMuted()) {
|
|
672
|
+
this.videojs.muted(true);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
unmute() {
|
|
679
|
+
if (this.isMuted()) {
|
|
680
|
+
this.videojs.muted(false);
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
return this;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
isMuted() {
|
|
687
|
+
return this.videojs.muted();
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
pause() {
|
|
691
|
+
this.videojs.pause();
|
|
692
|
+
|
|
693
|
+
return this;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
currentTime(offsetSeconds) {
|
|
697
|
+
if (!offsetSeconds && offsetSeconds !== 0) {
|
|
698
|
+
return this.videojs.currentTime();
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
this.videojs.currentTime(offsetSeconds);
|
|
702
|
+
|
|
703
|
+
return this;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
maximize() {
|
|
707
|
+
if (!this.isMaximized()) {
|
|
708
|
+
this.videojs.requestFullscreen();
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
return this;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
exitMaximize() {
|
|
715
|
+
if (this.isMaximized()) {
|
|
716
|
+
this.videojs.exitFullscreen();
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
return this;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
isMaximized() {
|
|
723
|
+
return this.videojs.isFullscreen();
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
dispose() {
|
|
727
|
+
this.videojs.dispose();
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
controls(bool) {
|
|
731
|
+
if (bool === undefined) {
|
|
732
|
+
return this.videojs.controls();
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
this.videojs.controls(bool);
|
|
736
|
+
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
ima() {
|
|
741
|
+
return {
|
|
742
|
+
playAd: this.videojs.ima.playAd
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
loop(bool) {
|
|
747
|
+
if (bool === undefined) {
|
|
748
|
+
return this.videojs.loop();
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
this.videojs.loop(bool);
|
|
752
|
+
|
|
753
|
+
return this;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
el() {
|
|
757
|
+
return this.videojs.el();
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export default VideoPlayer;
|