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.
Files changed (226) hide show
  1. package/.eslintignore +4 -0
  2. package/.snyk +19 -0
  3. package/.travis.yml +8 -0
  4. package/CHANGELOG.md +329 -0
  5. package/LICENSE +21 -0
  6. package/README.md +87 -0
  7. package/dist/cld-video-player.css +2110 -0
  8. package/dist/cld-video-player.js +5249 -0
  9. package/dist/cld-video-player.light.css +1766 -0
  10. package/dist/cld-video-player.light.js +1399 -0
  11. package/dist/cld-video-player.light.min.css +1 -0
  12. package/dist/cld-video-player.light.min.js +2 -0
  13. package/dist/cld-video-player.light.min.js.LICENSE.txt +23 -0
  14. package/dist/cld-video-player.min.css +1 -0
  15. package/dist/cld-video-player.min.js +2 -0
  16. package/dist/cld-video-player.min.js.LICENSE.txt +26 -0
  17. package/dist/fonts/cloudinary_icon_for_black_bg.svg +69 -0
  18. package/dist/fonts/cloudinary_icon_for_white_bg.svg +69 -0
  19. package/docs/360.html +102 -0
  20. package/docs/_template.html +93 -0
  21. package/docs/adaptive-streaming.html +297 -0
  22. package/docs/analytics.html +140 -0
  23. package/docs/api.html +302 -0
  24. package/docs/audio.html +136 -0
  25. package/docs/autoplay-fallback.html +138 -0
  26. package/docs/autoplay-on-scroll.html +107 -0
  27. package/docs/codec-fallback.html +158 -0
  28. package/docs/colors.html +135 -0
  29. package/docs/components.html +284 -0
  30. package/docs/custom-cld-errors.html +134 -0
  31. package/docs/floating-player.html +98 -0
  32. package/docs/fluid.html +117 -0
  33. package/docs/force-hls-subtitles-ios.html +159 -0
  34. package/docs/index.html +83 -0
  35. package/docs/interaction-area.html +398 -0
  36. package/docs/live-customer.html +128 -0
  37. package/docs/multiple-players.html +125 -0
  38. package/docs/playlist-by-tag-cap.html +182 -0
  39. package/docs/playlist-by-tag.html +133 -0
  40. package/docs/playlist.html +133 -0
  41. package/docs/poster.html +155 -0
  42. package/docs/raw-url.html +104 -0
  43. package/docs/recommendations.html +155 -0
  44. package/docs/scripts.js +156 -0
  45. package/docs/seek-thumbs.html +90 -0
  46. package/docs/shoppable.html +335 -0
  47. package/docs/subtitles-and-captions.html +267 -0
  48. package/docs/transformations.html +171 -0
  49. package/docs/ui-config.html +108 -0
  50. package/docs/vast-vpaid.html +149 -0
  51. package/env.example.js +6 -0
  52. package/env.js +6 -0
  53. package/jest-puppeteer.config.js +14 -0
  54. package/jest.config.js +196 -0
  55. package/package.json +99 -0
  56. package/sandbox.config.json +3 -0
  57. package/setupJest.js +1 -0
  58. package/src/assets/fonts/VideoJS.svg +120 -0
  59. package/src/assets/fonts/VideoJS.ttf +0 -0
  60. package/src/assets/fonts/VideoJS.woff +0 -0
  61. package/src/assets/fonts/icons.json +120 -0
  62. package/src/assets/icons/cloudinary_icon_for_black_bg.svg +69 -0
  63. package/src/assets/icons/cloudinary_icon_for_white_bg.svg +69 -0
  64. package/src/assets/icons/cloudinary_logo_for_dark_bg.svg +188 -0
  65. package/src/assets/icons/cloudinary_logo_for_white_bg.svg +188 -0
  66. package/src/assets/icons/info-circle.svg +17 -0
  67. package/src/assets/styles/ads-label.scss +16 -0
  68. package/src/assets/styles/components/interaction-areas.scss +158 -0
  69. package/src/assets/styles/components/playlist.scss +213 -0
  70. package/src/assets/styles/components/themedButton.scss +48 -0
  71. package/src/assets/styles/components/thumbnail.scss +94 -0
  72. package/src/assets/styles/components/title-bar.scss +67 -0
  73. package/src/assets/styles/components/triangle-volume-bar.scss +52 -0
  74. package/src/assets/styles/icons.scss +257 -0
  75. package/src/assets/styles/main.scss +324 -0
  76. package/src/assets/styles/mixins/aspect-ratio.scss +16 -0
  77. package/src/assets/styles/mixins/disable-transition.scss +3 -0
  78. package/src/assets/styles/mixins/mixins.scss +5 -0
  79. package/src/assets/styles/mixins/skin.scss +64 -0
  80. package/src/assets/styles/variables.scss +2 -0
  81. package/src/assets/styles/videojs-ima.scss +252 -0
  82. package/src/components/component-utils.js +20 -0
  83. package/src/components/index.js +21 -0
  84. package/src/components/interaction-area/interaction-area.const.js +30 -0
  85. package/src/components/interaction-area/interaction-area.service.js +223 -0
  86. package/src/components/interaction-area/interaction-area.utils.js +236 -0
  87. package/src/components/jumpButtons/jump-10-minus.js +21 -0
  88. package/src/components/jumpButtons/jump-10-plus.js +20 -0
  89. package/src/components/logoButton/logo-button.const.js +3 -0
  90. package/src/components/logoButton/logo-button.js +30 -0
  91. package/src/components/logoButton/logo-button.scss +15 -0
  92. package/src/components/playlist/components/playlist-button.js +34 -0
  93. package/src/components/playlist/components/playlist-next-button.js +18 -0
  94. package/src/components/playlist/components/playlist-previous-button.js +18 -0
  95. package/src/components/playlist/components/playlist.js +5 -0
  96. package/src/components/playlist/components/playlist.scss +15 -0
  97. package/src/components/playlist/components/upcoming-video-overlay.js +149 -0
  98. package/src/components/playlist/components/upcoming-video-overlay.scss +86 -0
  99. package/src/components/playlist/layout/playlist-layout-custom.js +21 -0
  100. package/src/components/playlist/layout/playlist-layout-horizontal.js +16 -0
  101. package/src/components/playlist/layout/playlist-layout-vertical.js +19 -0
  102. package/src/components/playlist/layout/playlist-layout.js +110 -0
  103. package/src/components/playlist/panel/playlist-panel-item.js +86 -0
  104. package/src/components/playlist/panel/playlist-panel.js +92 -0
  105. package/src/components/playlist/playlist-widget.js +119 -0
  106. package/src/components/playlist/playlist.const.js +14 -0
  107. package/src/components/playlist/playlist.js +413 -0
  108. package/src/components/playlist/thumbnail/thumbnail.js +69 -0
  109. package/src/components/progress-control-events-blocker/progress-control-events-blocker.js +17 -0
  110. package/src/components/qualitySelector/quality-selector.scss +10 -0
  111. package/src/components/qualitySelector/qualitySelector.js +152 -0
  112. package/src/components/recommendations-overlay/index.js +3 -0
  113. package/src/components/recommendations-overlay/recommendations-overlay-content.js +57 -0
  114. package/src/components/recommendations-overlay/recommendations-overlay-hide-button.js +18 -0
  115. package/src/components/recommendations-overlay/recommendations-overlay-item.js +35 -0
  116. package/src/components/recommendations-overlay/recommendations-overlay-primary-item.js +81 -0
  117. package/src/components/recommendations-overlay/recommendations-overlay-secondary-item.js +48 -0
  118. package/src/components/recommendations-overlay/recommendations-overlay-secondary-items-container.js +35 -0
  119. package/src/components/recommendations-overlay/recommendations-overlay.js +94 -0
  120. package/src/components/recommendations-overlay/recommendations-overlay.scss +182 -0
  121. package/src/components/shoppable-bar/layout/bar-layout.js +111 -0
  122. package/src/components/shoppable-bar/layout/shoppable-panel-toggle.js +64 -0
  123. package/src/components/shoppable-bar/layout/shoppable-products-overlay.js +87 -0
  124. package/src/components/shoppable-bar/panel/shoppable-panel-item.js +105 -0
  125. package/src/components/shoppable-bar/panel/shoppable-panel.js +172 -0
  126. package/src/components/shoppable-bar/shoppable-post-widget.js +110 -0
  127. package/src/components/shoppable-bar/shoppable-widget.const.js +52 -0
  128. package/src/components/shoppable-bar/shoppable-widget.js +111 -0
  129. package/src/components/shoppable-bar/shoppable-widget.scss +359 -0
  130. package/src/components/themeButton/themedButton.const.js +3 -0
  131. package/src/components/themeButton/themedButton.js +25 -0
  132. package/src/components/title-bar/title-bar.js +79 -0
  133. package/src/config/defaults.js +25 -0
  134. package/src/extended-events.js +228 -0
  135. package/src/index.js +18 -0
  136. package/src/mixins/eventable.js +54 -0
  137. package/src/mixins/playlistable.js +106 -0
  138. package/src/plugins/analytics/index.js +245 -0
  139. package/src/plugins/autoplay-on-scroll/index.js +86 -0
  140. package/src/plugins/cloudinary/common.js +216 -0
  141. package/src/plugins/cloudinary/event-handler-registry.js +46 -0
  142. package/src/plugins/cloudinary/index.js +345 -0
  143. package/src/plugins/cloudinary/models/audio-source/audio-source.const.js +11 -0
  144. package/src/plugins/cloudinary/models/audio-source/audio-source.js +82 -0
  145. package/src/plugins/cloudinary/models/base-source.js +107 -0
  146. package/src/plugins/cloudinary/models/image-source.js +26 -0
  147. package/src/plugins/cloudinary/models/video-source/video-source.const.js +32 -0
  148. package/src/plugins/cloudinary/models/video-source/video-source.js +239 -0
  149. package/src/plugins/cloudinary/models/video-source/video-source.utils.js +57 -0
  150. package/src/plugins/colors/index.js +303 -0
  151. package/src/plugins/context-menu/components/context-menu-item.js +12 -0
  152. package/src/plugins/context-menu/components/context-menu.js +63 -0
  153. package/src/plugins/context-menu/context-menu.scss +30 -0
  154. package/src/plugins/context-menu/contextMenuContent.js +53 -0
  155. package/src/plugins/context-menu/index.js +134 -0
  156. package/src/plugins/dash/index.js +26 -0
  157. package/src/plugins/dash/setup-audio-tracks.js +112 -0
  158. package/src/plugins/dash/setup-text-tracks.js +195 -0
  159. package/src/plugins/dash/videojs-dash.js +372 -0
  160. package/src/plugins/floating-player/floating-player.scss +74 -0
  161. package/src/plugins/floating-player/index.js +129 -0
  162. package/src/plugins/ima/index.js +1775 -0
  163. package/src/plugins/index.js +31 -0
  164. package/src/plugins/interactive-plugin/index.js +10 -0
  165. package/src/plugins/videojs-http-source-selector/components/SourceMenuButton.js +98 -0
  166. package/src/plugins/videojs-http-source-selector/components/SourceMenuItem.js +52 -0
  167. package/src/plugins/videojs-http-source-selector/plugin.js +82 -0
  168. package/src/plugins/videojs-http-source-selector/plugin.scss +9 -0
  169. package/src/plugins/vtt-thumbnails/index.js +526 -0
  170. package/src/plugins/vtt-thumbnails/vtt-thumbnails.scss +29 -0
  171. package/src/utils/api.js +32 -0
  172. package/src/utils/apply-with-props.js +32 -0
  173. package/src/utils/array.js +22 -0
  174. package/src/utils/assign.js +27 -0
  175. package/src/utils/attributes-normalizer.js +72 -0
  176. package/src/utils/cloudinary.js +165 -0
  177. package/src/utils/css-prefix.js +43 -0
  178. package/src/utils/dom.js +74 -0
  179. package/src/utils/find.js +28 -0
  180. package/src/utils/fontFace.js +25 -0
  181. package/src/utils/groupBy.js +12 -0
  182. package/src/utils/index.js +29 -0
  183. package/src/utils/matches.js +11 -0
  184. package/src/utils/mixin.js +5 -0
  185. package/src/utils/object.js +26 -0
  186. package/src/utils/playButton.js +9 -0
  187. package/src/utils/positioning.js +78 -0
  188. package/src/utils/querystring.js +12 -0
  189. package/src/utils/slicing.js +21 -0
  190. package/src/utils/string.js +15 -0
  191. package/src/utils/throttle.js +30 -0
  192. package/src/utils/time.js +77 -0
  193. package/src/utils/type-inference.js +35 -0
  194. package/src/validators/validators-functions.js +48 -0
  195. package/src/validators/validators-types.js +78 -0
  196. package/src/validators/validators.js +110 -0
  197. package/src/video-player.const.js +68 -0
  198. package/src/video-player.js +761 -0
  199. package/src/video-player.utils.js +123 -0
  200. package/test/adaptive-streaming.test.js +38 -0
  201. package/test/ads.test.js +35 -0
  202. package/test/analytics.test.js +111 -0
  203. package/test/api.test.js +111 -0
  204. package/test/autoplay.scroll.test.js +23 -0
  205. package/test/basic-ui.test.js +59 -0
  206. package/test/colors.test.js +58 -0
  207. package/test/components.test.js +21 -0
  208. package/test/custom-error.test.js +24 -0
  209. package/test/fluid.test.js +36 -0
  210. package/test/isValidConfig.test.js +224 -0
  211. package/test/mocks/cloudinary-core-mock.js +0 -0
  212. package/test/mocks/styleMock.js +1 -0
  213. package/test/multiplayer.test.js +25 -0
  214. package/test/playlist.test.js +60 -0
  215. package/test/puppeteer/vp-env.js +19 -0
  216. package/test/recommendations.test.js +38 -0
  217. package/test/title-bar.test.js +28 -0
  218. package/test/ui-conf.test.js +49 -0
  219. package/test/unit/cloudinaryConfig.test.js +22 -0
  220. package/test/unit/cloudinaryUtils.test.js +53 -0
  221. package/test/unit/utils.test.js +27 -0
  222. package/test/unit/videoSource.test.js +454 -0
  223. package/tsconfig.json +15 -0
  224. package/types/video-player-tests.js +12 -0
  225. package/types/video-player-tests.ts +31 -0
  226. package/types/video-player.d.ts +570 -0
@@ -0,0 +1,413 @@
1
+ import VideoSource from 'plugins/cloudinary/models/video-source/video-source';
2
+ import { isInteger } from 'utils/type-inference';
3
+
4
+ import 'components/playlist/components/upcoming-video-overlay';
5
+ import {
6
+ DEFAULT_AUTO_ADVANCE,
7
+ DEFAULT_PRESENT_UPCOMING,
8
+ UPCOMING_VIDEO_TRANSITION
9
+ } from './playlist.const';
10
+
11
+ class Playlist {
12
+
13
+ constructor(context, sources = [], { repeat = false, autoAdvance = false, presentUpcoming = false } = {}) {
14
+ this._context = context;
15
+ this._sources = [];
16
+ this._defaultRecResolverCache = {};
17
+ this._currentIndex = null;
18
+ this._recommendationsHandler = null;
19
+ this._autoAdvance = null;
20
+ this._presentUpcoming = null;
21
+
22
+ this.resetState = () => {
23
+ this.repeat(repeat);
24
+ this.autoAdvance(autoAdvance);
25
+ this.presentUpcoming(presentUpcoming);
26
+ };
27
+
28
+ sources.forEach((source) => this.enqueue(source));
29
+
30
+ this.resetState();
31
+ }
32
+
33
+ list() {
34
+ return this._sources;
35
+ }
36
+
37
+ player() {
38
+ return this._context.player;
39
+ }
40
+
41
+ presentUpcoming(delay) {
42
+ this._presentUpcoming = this._presentUpcoming || {};
43
+
44
+ if (delay === undefined) {
45
+ return this._presentUpcoming.delay;
46
+ }
47
+
48
+ if (delay === true) {
49
+ delay = DEFAULT_PRESENT_UPCOMING;
50
+ } else if (delay === false) {
51
+ delay = false;
52
+ } else if (!isInteger(delay) || delay < 0) {
53
+ throw new Error('presentUpcoming \'delay\' must be either a boolean or a positive integer.');
54
+ }
55
+
56
+ this._presentUpcoming.delay = delay;
57
+
58
+ this._setupPresentUpcoming();
59
+
60
+ return this._presentUpcoming.delay;
61
+ }
62
+
63
+ autoAdvance(delay) {
64
+ this._autoAdvance = this._autoAdvance || {};
65
+
66
+ if (delay === undefined) {
67
+ return this._autoAdvance.delay;
68
+ }
69
+
70
+ if (delay === true) {
71
+ delay = DEFAULT_AUTO_ADVANCE;
72
+ } else if (delay === false) {
73
+ delay = false;
74
+ } else if (!isInteger(delay) || delay < 0) {
75
+ throw new Error('Auto advance \'delay\' must be either a boolean or a positive integer.');
76
+ }
77
+
78
+ this._autoAdvance.delay = delay;
79
+
80
+ this._setupAutoAdvance();
81
+
82
+ return this._autoAdvance.delay;
83
+ }
84
+
85
+ _setupAutoAdvance() {
86
+ this._resetAutoAdvance();
87
+
88
+ const delay = this._autoAdvance.delay;
89
+
90
+ if (delay === false) {
91
+ return;
92
+ }
93
+
94
+ const trigger = () => {
95
+ if (this.player().ended()) {
96
+ this._autoAdvance.timeout = setTimeout(() => {
97
+ this.playNext();
98
+ }, delay * 1000);
99
+ }
100
+ };
101
+
102
+ this._autoAdvance = { delay, trigger };
103
+
104
+ this._context.on('ended', this._autoAdvance.trigger);
105
+ }
106
+
107
+ dispose() {
108
+ this._resetAutoAdvance();
109
+ this._resetPresentUpcoming();
110
+ this._resetRecommendations();
111
+ }
112
+
113
+ _resetPresentUpcoming() {
114
+ this.player().trigger('upcomingvideohide');
115
+
116
+ if (!this._presentUpcoming) {
117
+ this._presentUpcoming = {};
118
+ }
119
+
120
+ if (this._presentUpcoming.trigger) {
121
+ this._context.off('timeupdate', this._presentUpcoming.trigger);
122
+ }
123
+
124
+ this._presentUpcoming.trigger = null;
125
+ this._presentUpcoming.showTriggered = false;
126
+ }
127
+
128
+ _setupPresentUpcoming() {
129
+ this._resetPresentUpcoming();
130
+
131
+ const delay = this._presentUpcoming.delay;
132
+
133
+ if (delay === false) {
134
+ return;
135
+ }
136
+
137
+ this._presentUpcoming.trigger = () => {
138
+ const currentTime = this.player().currentTime();
139
+ const duration = this.player().duration();
140
+
141
+ const remainingTime = duration - currentTime;
142
+
143
+ if (remainingTime < UPCOMING_VIDEO_TRANSITION + 0.5) {
144
+ if (this._presentUpcoming.showTriggered) {
145
+ this.player().trigger('upcomingvideohide');
146
+ this._presentUpcoming.showTriggered = false;
147
+ }
148
+ } else if (remainingTime <= this._presentUpcoming.delay && !this._presentUpcoming.showTriggered && !this.player().loop()) {
149
+ this.player().trigger('upcomingvideoshow');
150
+ this._presentUpcoming.showTriggered = true;
151
+ } else if (this._presentUpcoming.showTriggered && (remainingTime > this._presentUpcoming.delay || this.player().loop())) {
152
+ this.player().trigger('upcomingvideohide');
153
+ this._presentUpcoming.showTriggered = false;
154
+ }
155
+ };
156
+
157
+ this._context.on('timeupdate', this._presentUpcoming.trigger);
158
+ }
159
+
160
+ _resetAutoAdvance() {
161
+ if (!this._autoAdvance) {
162
+ this._autoAdvance = {};
163
+ }
164
+
165
+ if (this._autoAdvance.timeout) {
166
+ clearTimeout(this._autoAdvance.timeout);
167
+ }
168
+
169
+ if (this._autoAdvance.trigger) {
170
+ this._context.off('ended', this._autoAdvance.trigger);
171
+ }
172
+
173
+ this._autoAdvance.timeout = null;
174
+ this._autoAdvance.trigger = null;
175
+ }
176
+
177
+ _resetRecommendations() {
178
+ if (this._recommendationsHandler) {
179
+ this._context.off('ended', this._recommendationsHandler);
180
+ }
181
+ }
182
+
183
+ _refreshRecommendations() {
184
+ this._resetRecommendations();
185
+
186
+ this._recommendationsHandler = () => {
187
+ if (this.autoAdvance() === false && this._context.autoShowRecommendations()) {
188
+ this.player().trigger('recommendationsshow');
189
+ }
190
+ };
191
+
192
+ this._context.on('ended', this._recommendationsHandler);
193
+ }
194
+
195
+
196
+ _refreshTextTracks () {
197
+ this.player().trigger('refreshTextTracks', this.currentSource().textTracks());
198
+ }
199
+
200
+ _recommendationItemBuilder(source) {
201
+ const defaultResolver = this._defaultRecResolverCache[source.objectId];
202
+ if (source.recommendations() && (!defaultResolver || source.recommendations() !== defaultResolver)) {
203
+ return;
204
+ }
205
+
206
+ return (source) => ({ source, action: () => this.playItem(source) });
207
+ }
208
+
209
+ currentIndex(index) {
210
+ if (index === undefined) {
211
+ return this._currentIndex;
212
+ }
213
+
214
+ if (index >= this.length() || index < 0) {
215
+ throw new Error('Invalid playlist index.');
216
+ }
217
+
218
+ this._currentIndex = index;
219
+
220
+ const current = this.currentSource();
221
+
222
+ const itemBuilder = this._recommendationItemBuilder(current);
223
+
224
+ if (!current.recommendations()) {
225
+ current.recommendations(this._defaultRecommendationsResolver(current));
226
+ }
227
+
228
+ this._context.source(current, { recommendationOptions: { disableAutoShow: true, itemBuilder } });
229
+
230
+ const eventData = { playlist: this, current, next: this.next() };
231
+
232
+ this.player().trigger('playlistitemchanged', eventData);
233
+
234
+ this._refreshRecommendations();
235
+
236
+ this._refreshTextTracks();
237
+
238
+ return current;
239
+ }
240
+
241
+ _defaultRecommendationsResolver(source) {
242
+ const defaultResolver = this._defaultRecResolverCache[source.objectId];
243
+ if (defaultResolver) {
244
+ return defaultResolver;
245
+ }
246
+
247
+ this._defaultRecResolverCache[source.objectId] = () => {
248
+ let index = this.list().indexOf(source);
249
+ const items = [];
250
+
251
+ const numOfItems = Math.min(4, this.length() - 1);
252
+
253
+ while (items.length < numOfItems) {
254
+ index = this.nextIndex(index);
255
+ if (index === -1) {
256
+ break;
257
+ }
258
+
259
+ const source = this.list()[index];
260
+ items.push(source);
261
+ }
262
+
263
+ return items;
264
+ };
265
+
266
+ return this._defaultRecResolverCache[source.objectId];
267
+ }
268
+
269
+ buildSource(source, options = {}) {
270
+ return this._context.buildSource(source, options);
271
+ }
272
+
273
+ enqueue(source, options = {}) {
274
+ const src = source instanceof VideoSource ? source : this.buildSource(source, options);
275
+
276
+ this._sources.push(src);
277
+
278
+ return src;
279
+ }
280
+
281
+
282
+ playItem(item) {
283
+ let index = this.list().indexOf(item);
284
+
285
+ if (index === -1) {
286
+ throw new Error('Invalid playlist item.');
287
+ }
288
+
289
+ this.playAtIndex(index);
290
+ }
291
+
292
+ playAtIndex(index) {
293
+ this.currentIndex(index);
294
+ this.player().play();
295
+
296
+ return this.currentSource();
297
+ }
298
+
299
+ currentSource() {
300
+ return this.list()[this.currentIndex()];
301
+ }
302
+
303
+ removeAt(index) {
304
+ if (index >= this.length() || index < 0) {
305
+ throw new Error('Invalid playlist index.');
306
+ }
307
+
308
+ this._sources.splice(index, 1);
309
+
310
+ return this;
311
+ }
312
+
313
+ repeat(repeat) {
314
+ if (repeat === undefined) {
315
+ return this._repeat;
316
+ }
317
+
318
+ this._repeat = !!repeat;
319
+
320
+ return this._repeat;
321
+ }
322
+
323
+ first() {
324
+ return this.list()[0];
325
+ }
326
+
327
+ last() {
328
+ return this.list()[this.length() - 1];
329
+ }
330
+
331
+ next() {
332
+ const nextIndex = this.nextIndex();
333
+
334
+ if (nextIndex === -1) {
335
+ return null;
336
+ }
337
+
338
+ return this.list()[nextIndex];
339
+ }
340
+
341
+ nextIndex(index) {
342
+ index = index !== undefined ? index : this.currentIndex();
343
+
344
+ if (index >= this.length() || index < 0) {
345
+ throw new Error('Invalid playlist index.');
346
+ }
347
+
348
+ const isLast = index === this.length() - 1;
349
+
350
+ let nextIndex = index + 1;
351
+
352
+ if (isLast) {
353
+ if (this.repeat()) {
354
+ nextIndex = 0;
355
+ } else {
356
+ return -1;
357
+ }
358
+ }
359
+
360
+ return nextIndex;
361
+ }
362
+
363
+ previousIndex() {
364
+ if (this.isFirst()) {
365
+ return -1;
366
+ }
367
+
368
+ return this.currentIndex() - 1;
369
+ }
370
+
371
+ playFirst() {
372
+ return this.playAtIndex(0);
373
+ }
374
+
375
+ playLast() {
376
+ const lastIndex = this.list().length - 1;
377
+ return this.playAtIndex(lastIndex);
378
+ }
379
+
380
+ isLast() {
381
+ return this.currentIndex() >= this.length() - 1;
382
+ }
383
+
384
+ isFirst() {
385
+ return this.currentIndex() === 0;
386
+ }
387
+
388
+ length() {
389
+ return this.list().length;
390
+ }
391
+
392
+ playNext() {
393
+ let nextIndex = this.nextIndex();
394
+
395
+ if (nextIndex === -1) {
396
+ return null;
397
+ }
398
+
399
+ return this.playAtIndex(nextIndex);
400
+ }
401
+
402
+ playPrevious() {
403
+ let previousIndex = this.previousIndex();
404
+
405
+ if (previousIndex === -1) {
406
+ return null;
407
+ }
408
+
409
+ return this.playAtIndex(previousIndex);
410
+ }
411
+ }
412
+
413
+ export default Playlist;
@@ -0,0 +1,69 @@
1
+ import videojs from 'video.js';
2
+ import '../../../assets/styles/components/thumbnail.scss';
3
+
4
+ // Get the ClickableComponent base class from Video.js
5
+ const ClickableComponent = videojs.getComponent('ClickableComponent');
6
+
7
+ const THUMB_DEFAULT_WIDTH = 300;
8
+
9
+ const DEFAULT_OPTIONS = {
10
+ item: null,
11
+ transformation: {
12
+ width: THUMB_DEFAULT_WIDTH,
13
+ aspect_ratio: '16:9',
14
+ crop: 'pad',
15
+ background: 'black'
16
+ }
17
+ };
18
+
19
+ class Thumbnail extends ClickableComponent {
20
+
21
+ constructor(player, initOptions) {
22
+ const options = videojs.mergeOptions(DEFAULT_OPTIONS, initOptions);
23
+ super(player, options);
24
+ }
25
+
26
+ getItem() {
27
+ return this.options_.item;
28
+ }
29
+
30
+ getTitle() {
31
+ return this.getItem().info().title;
32
+ }
33
+
34
+ getDuration() {
35
+ return ' ';// this.getItem().info().title;
36
+ }
37
+
38
+ getThumbnail() {
39
+ return this.getItem().poster().url({ transformation: this.options_.transformation });
40
+ }
41
+
42
+ handleClick(e) {
43
+ e.preventDefault();
44
+ }
45
+
46
+ createControlTextEl() {
47
+ return;
48
+ }
49
+
50
+ createEl(tag = 'a') {
51
+ const el = super.createEl(tag, {
52
+ className: 'cld-thumbnail',
53
+ href: '#'
54
+ });
55
+
56
+ const img = super.createEl('img', {
57
+ className: 'cld-thumbnail-img',
58
+ src: this.getThumbnail()
59
+ });
60
+
61
+ el.appendChild(img);
62
+
63
+ el.style.backgroundImage = `url('${this.getThumbnail()}')`;
64
+
65
+ return el;
66
+ }
67
+ }
68
+
69
+ export default Thumbnail;
@@ -0,0 +1,17 @@
1
+ import videojs from 'video.js';
2
+ const Component = videojs.getComponent('Component');
3
+
4
+ class ProgressControlEventsBlocker extends Component {
5
+
6
+ constructor(player, options = {}) {
7
+ super(player, options);
8
+ }
9
+
10
+ createEl() {
11
+ return super.createEl('div', {
12
+ className: 'vjs-progress-control-events-blocker'
13
+ });
14
+ }
15
+ }
16
+
17
+ videojs.registerComponent('progressControlEventsBlocker', ProgressControlEventsBlocker);
@@ -0,0 +1,10 @@
1
+ .video-js {
2
+
3
+ .vjs-http-source-selector {
4
+
5
+ .vjs-button {
6
+ font-size: 17px;
7
+ }
8
+
9
+ }
10
+ }
@@ -0,0 +1,152 @@
1
+ import * as djs from 'dashjs';
2
+ import 'videojs-per-source-behaviors';
3
+ import 'videojs-contrib-quality-levels';
4
+ import '../../plugins/videojs-http-source-selector/plugin';
5
+ import { findIndex } from '../../utils/find';
6
+
7
+ import './quality-selector.scss';
8
+
9
+ const qualitySelector = {
10
+
11
+ init: (player) => {
12
+ // Handle DASH sources, HLS are handled internally.
13
+ if (player && player.qualityLevels && player.dash && player.dash.mediaPlayer) {
14
+ const MediaPlayer = djs.default.MediaPlayer;
15
+
16
+ player.dash.qualityLevels = player.qualityLevels();
17
+ player.dash.mediaPlayer.getAutoSwitchQualityFor = (type) => {
18
+ const dashPlayer = player.dash.mediaPlayer;
19
+ const settings = dashPlayer.getSettings();
20
+
21
+ if (settings) {
22
+ return settings.streaming.abr.autoSwitchBitrate[type];
23
+ }
24
+
25
+ return true;
26
+ };
27
+
28
+ player.dash.mediaPlayer.setAutoSwitchQualityFor = (type, val) => {
29
+ const dashPlayer = player.dash.mediaPlayer;
30
+ const upSettings = {
31
+ streaming: {
32
+ abr: {
33
+ autoSwitchBitrate: {}
34
+ }
35
+ }
36
+ };
37
+ upSettings.streaming.abr.autoSwitchBitrate[type] = val;
38
+ dashPlayer.updateSettings(upSettings);
39
+ };
40
+
41
+ // When loaded, build quality-level list.
42
+ player.dash.mediaPlayer.on(
43
+ MediaPlayer.events.PLAYBACK_METADATA_LOADED,
44
+ () => {
45
+ const videoRates = player.dash.mediaPlayer.getBitrateInfoListFor('video');
46
+ const audioRates = player.dash.mediaPlayer.getBitrateInfoListFor('audio');
47
+
48
+ if (videoRates.length > 0) {
49
+ const normalizeFactor = videoRates[videoRates.length - 1].bitrate;
50
+ player.dash.audioMapper = videoRates.map((rate) =>
51
+ Math.round((rate.bitrate / normalizeFactor) * (audioRates.length - 1))
52
+ );
53
+ videoRates.forEach((vrate) => {
54
+ player.dash.qualityLevels.addQualityLevel({
55
+ id: vrate.bitrate,
56
+ width: vrate.width,
57
+ height: vrate.height,
58
+ bandwidth: vrate.bitrate,
59
+ selected: true,
60
+ enabled: function(val) {
61
+ if (val !== undefined) {
62
+ this.selected = val;
63
+ if (val === true) {
64
+ let selectedIdx = findIndex(player.qualityLevels().levels_, (l => l.id === this.id));
65
+ player.qualityLevels().selectedIndex_ = selectedIdx;
66
+ player.qualityLevels().trigger({
67
+ type: 'change',
68
+ selectedIndex: selectedIdx
69
+ });
70
+ }
71
+ } else {
72
+ return (this.selected !== undefined ? this.selected : true);
73
+ }
74
+ }
75
+ });
76
+ });
77
+ }
78
+ }
79
+ );
80
+
81
+ // Pass qualityLevels 'change' event into the DASH player.
82
+ player.qualityLevels().on('change', (event) => {
83
+ let enabledQualities = player.dash.qualityLevels.levels_.filter(
84
+ (q) => q.enabled
85
+ );
86
+ if (enabledQualities.length === 1) {
87
+ player.dash.mediaPlayer.setQualityFor('video', event.selectedIndex);
88
+ player.dash.mediaPlayer.setQualityFor('audio', player.dash.audioMapper[event.selectedIndex]);
89
+ } else if (!player.dash.mediaPlayer.getAutoSwitchQualityFor('video')) {
90
+ player.dash.mediaPlayer.setAutoSwitchQualityFor('video', true);
91
+ player.dash.mediaPlayer.setAutoSwitchQualityFor('audio', true);
92
+ }
93
+ });
94
+
95
+ // Handle 'change' event on the DASH player
96
+ /*
97
+ player.dash.mediaPlayer.on(
98
+ MediaPlayer.events.QUALITY_CHANGE_REQUESTED,
99
+ (event) => {
100
+ if (event.mediaType === 'video') {
101
+ player.dash.qualityLevels.selectedIndex_ = event.newQuality;
102
+ player.dash.qualityLevels.trigger({
103
+ selectedIndex: event.newQuality,
104
+ type: 'change'
105
+ });
106
+ }
107
+ }
108
+ );
109
+ */
110
+ }
111
+ },
112
+
113
+ // Show selector only if more then one option available
114
+ setVisibility: (player) => {
115
+ const sourceMenuButton = player.controlBar.getChild('sourceMenuButton');
116
+ if (sourceMenuButton) {
117
+ const qualityLevels = player.qualityLevels();
118
+ if (qualityLevels && qualityLevels.length > 1) {
119
+ const levels = qualityLevels.levels_.filter((q) => q.enabled);
120
+ if (levels.length === 1) {
121
+ const idx = qualityLevels.levels_.findIndex(l => l.id === levels[0].id);
122
+ sourceMenuButton.children()[1].children()[idx].selected(true);
123
+ } else {
124
+ sourceMenuButton.children()[1].children()[0].selected(true);
125
+ sourceMenuButton.children()[1].children().forEach((item, i) => {
126
+ if (i > 0) {
127
+ item.selected(false);
128
+ }
129
+ });
130
+ }
131
+ sourceMenuButton.show();
132
+ } else {
133
+ sourceMenuButton.hide();
134
+ }
135
+
136
+ // ToDo: if there are multiple sources with same height (i.e. 720p)
137
+ // add a bitrate indicator to distinguish them.
138
+ // Labels: 720p => 1280x720 @ 3500Kbps
139
+ // sourceMenuButton.items.forEach((item) => {
140
+ // const level = qualityLevels.levels_.find(ql => ql.height + 'p' === item.options_.label);
141
+ // if (level) {
142
+ // item.el_.innerText = level.width + 'x' + level.height + (level.bitrate ? ' @ ' + (Math.round(level.bitrate / 100)) + 'Kbps' : '');
143
+ // }
144
+ // });
145
+
146
+ }
147
+
148
+ }
149
+
150
+ };
151
+
152
+ export default qualitySelector;
@@ -0,0 +1,3 @@
1
+ import RecommendationsOverlay from './recommendations-overlay';
2
+
3
+ export default RecommendationsOverlay;