ravnur-player-public 3.4.3 → 3.4.4

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 (260) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.js +206 -0
  3. package/.flowconfig +3 -0
  4. package/.vscode/extensions.json +7 -0
  5. package/.vscode/launch.json +37 -0
  6. package/.vscode/settings.json +4 -0
  7. package/README-Private.md +54 -0
  8. package/babel.config.js +28 -0
  9. package/bitbucket-pipelines.yml +61 -0
  10. package/cert.pem +23 -0
  11. package/demo/BaseM.mp4 +0 -0
  12. package/demo/HD.mp4 +0 -0
  13. package/demo/annotations.json +50 -0
  14. package/demo/annotations_ge.json +50 -0
  15. package/demo/base.mp3 +0 -0
  16. package/demo/cc_2125en.vtt +4958 -0
  17. package/demo/cc_en.vtt +171 -0
  18. package/demo/cc_ge.vtt +178 -0
  19. package/demo/chapters_en.vtt +38 -0
  20. package/demo/chapters_ge.vtt +5 -0
  21. package/demo/chapters_ge1.json +23 -0
  22. package/demo/hls/audio/stereo/en/128kbit.m3u8 +912 -0
  23. package/demo/hls/audio/stereo/none/128kbit.m3u8 +912 -0
  24. package/demo/hls/audio/surround/en/320kbit.m3u8 +912 -0
  25. package/demo/hls/playlist.m3u8 +31 -0
  26. package/demo/hls/video/10000kbit.m3u8 +894 -0
  27. package/demo/hls/video/1100kbit.m3u8 +894 -0
  28. package/demo/hls/video/1500kbit.m3u8 +894 -0
  29. package/demo/hls/video/250kbit.m3u8 +894 -0
  30. package/demo/hls/video/4000kbit.m3u8 +894 -0
  31. package/demo/hls/video/500kbit.m3u8 +894 -0
  32. package/demo/hls/video/6000kbit.m3u8 +894 -0
  33. package/demo/hls/video/800kbit.m3u8 +894 -0
  34. package/demo/hls.js +5 -0
  35. package/demo/hls.js.map +1 -0
  36. package/demo/hls.min.js +2 -0
  37. package/demo/hls.min.js.map +1 -0
  38. package/demo/playlist.m3u8 +31 -0
  39. package/demo/ravnur-flash-audio.swf +0 -0
  40. package/demo/ravnur-flash-video-hls.swf +0 -0
  41. package/demo/ravnur-flash-video.swf +0 -0
  42. package/demo/shaka/shaka-player.foo.debug.d.ts +4532 -0
  43. package/demo/shaka/shaka-player.foo.debug.externs.js +3886 -0
  44. package/demo/shaka/shaka-player.foo.debug.js +1746 -0
  45. package/demo/shaka/shaka-player.foo.debug.map +8 -0
  46. package/demo/shaka/wrapper.js +7 -0
  47. package/demo/test.html +458 -0
  48. package/dist/RavnurMediaPlayer.min.js +1 -1
  49. package/dist/cdn/RavnurMediaPlayer.min.js +1 -1
  50. package/jest.config.js +4 -0
  51. package/key.pem +27 -0
  52. package/lib/es5.js +344 -0
  53. package/lib/images/Spinner-small.gif +0 -0
  54. package/lib/images/close.png +0 -0
  55. package/lib/images/ic_check_box_black_24dp_1x.png +0 -0
  56. package/lib/images/ic_check_box_outline_blank_black_24dp_1x.png +0 -0
  57. package/lib/images/ic_chevron_left_white_24dp_1x.png +0 -0
  58. package/lib/images/ic_chevron_right_white_24dp_1x.png +0 -0
  59. package/lib/images/ic_closed_caption_white_24dp_1x.png +0 -0
  60. package/lib/images/ic_fast_forward_white_24dp_1x.png +0 -0
  61. package/lib/images/ic_fast_rewind_white_24dp_1x.png +0 -0
  62. package/lib/images/ic_fullscreen_exit_white_24dp_1x.png +0 -0
  63. package/lib/images/ic_fullscreen_white_24dp_1x.png +0 -0
  64. package/lib/images/ic_hd_white_24dp_1x.png +0 -0
  65. package/lib/images/ic_keyboard_arrow_left_black_24dp_1x.png +0 -0
  66. package/lib/images/ic_keyboard_arrow_right_black_24dp_1x.png +0 -0
  67. package/lib/images/ic_pause_white_24dp_1x.png +0 -0
  68. package/lib/images/ic_photo_white_24dp_1x.png +0 -0
  69. package/lib/images/ic_play_arrow_white_24dp_1x.png +0 -0
  70. package/lib/images/ic_refresh_white_24dp_1x.png +0 -0
  71. package/lib/images/ic_settings_white_24dp_1x.png +0 -0
  72. package/lib/images/ic_skip_next_white_24dp_1x.png +0 -0
  73. package/lib/images/ic_skip_previous_white_24dp_1x.png +0 -0
  74. package/lib/images/ic_toc_white_24dp_1x.png +0 -0
  75. package/lib/images/ic_volume_off_white_24dp_1x.png +0 -0
  76. package/lib/images/ic_volume_up_white_24dp_1x.png +0 -0
  77. package/lib/player4ie8.css +225 -0
  78. package/package.json +3 -7
  79. package/server.js +29 -0
  80. package/src/config/cc.js +56 -0
  81. package/src/config/i18n.js +101 -0
  82. package/src/config/options.js +123 -0
  83. package/src/config/playlist.js +9 -0
  84. package/src/config/source.js +23 -0
  85. package/src/config/statuses.js +8 -0
  86. package/src/config/styles.js +16 -0
  87. package/src/entity.js +27 -0
  88. package/src/events.js +5 -0
  89. package/src/extensions/annotations.js +142 -0
  90. package/src/extensions/audio-tarcks.js +115 -0
  91. package/src/extensions/backward.js +45 -0
  92. package/src/extensions/base.js +73 -0
  93. package/src/extensions/bottom-next.js +50 -0
  94. package/src/extensions/bottom-prev.js +50 -0
  95. package/src/extensions/buffering.js +78 -0
  96. package/src/extensions/c2pa.js +350 -0
  97. package/src/extensions/caption-search.js +230 -0
  98. package/src/extensions/cc.js +874 -0
  99. package/src/extensions/crawl.js +118 -0
  100. package/src/extensions/download.js +411 -0
  101. package/src/extensions/error.js +47 -0
  102. package/src/extensions/forward.js +44 -0
  103. package/src/extensions/fullscreen.js +84 -0
  104. package/src/extensions/help.js +201 -0
  105. package/src/extensions/helpers/FileSaver.js +157 -0
  106. package/src/extensions/helpers/clickOpener.js +180 -0
  107. package/src/extensions/helpers/opener.js +30 -0
  108. package/src/extensions/helpers/openerHeightChecker.js +13 -0
  109. package/src/extensions/helpers/popover.js +33 -0
  110. package/src/extensions/helpers/popoverPosition.js +30 -0
  111. package/src/extensions/helpers/scrollIntoView.js +9 -0
  112. package/src/extensions/helpers/storage.js +20 -0
  113. package/src/extensions/helpers/textContent.js +6 -0
  114. package/src/extensions/helpers/timeCodeToSeconds.js +44 -0
  115. package/src/extensions/helpers/transport.js +43 -0
  116. package/src/extensions/helpers/vtt-loader.js +42 -0
  117. package/src/extensions/index.js +87 -0
  118. package/src/extensions/live.js +76 -0
  119. package/src/extensions/mux.js +57 -0
  120. package/src/extensions/next-frame.js +44 -0
  121. package/src/extensions/next.js +48 -0
  122. package/src/extensions/placeholder.js +241 -0
  123. package/src/extensions/play.js +102 -0
  124. package/src/extensions/poster.js +47 -0
  125. package/src/extensions/prev-frame.js +44 -0
  126. package/src/extensions/prev.js +48 -0
  127. package/src/extensions/progress.js +465 -0
  128. package/src/extensions/resizer.js +37 -0
  129. package/src/extensions/settings.js +367 -0
  130. package/src/extensions/theater.js +56 -0
  131. package/src/extensions/title.js +38 -0
  132. package/src/extensions/toc.js +334 -0
  133. package/src/extensions/volume.js +196 -0
  134. package/src/flash/FlashPlugin.js +301 -0
  135. package/src/flash/MediaElement.js +361 -0
  136. package/src/flash/plugins.js +32 -0
  137. package/src/flash-detector.js +66 -0
  138. package/src/helpers/$t.js +10 -0
  139. package/src/helpers/binder.js +11 -0
  140. package/src/helpers/isAndroid.js +5 -0
  141. package/src/helpers/isBlackBerry.js +5 -0
  142. package/src/helpers/isCanvasSupported.js +6 -0
  143. package/src/helpers/isIE.js +21 -0
  144. package/src/helpers/isMobile.js +10 -0
  145. package/src/helpers/isWindows.js +5 -0
  146. package/src/helpers/isWindowsPhone.js +5 -0
  147. package/src/helpers/isiOS.js +5 -0
  148. package/src/html5media.js +19 -0
  149. package/src/index.js +2 -0
  150. package/src/logger.js +31 -0
  151. package/src/microevent.js +65 -0
  152. package/src/normalize-options.js +139 -0
  153. package/src/player.js +864 -0
  154. package/src/players/base.js +209 -0
  155. package/src/players/flash.js +172 -0
  156. package/src/players/hls.js +278 -0
  157. package/src/players/html.js +205 -0
  158. package/src/players/index.js +59 -0
  159. package/src/players/shaka.js +219 -0
  160. package/src/playlist.js +362 -0
  161. package/src/screenfull.js +121 -0
  162. package/src/state.js +474 -0
  163. package/src/static/es5.js +344 -0
  164. package/src/static/images/Spinner-small.gif +0 -0
  165. package/src/static/images/close.png +0 -0
  166. package/src/static/images/ic_check_box_black_24dp_1x.png +0 -0
  167. package/src/static/images/ic_check_box_outline_blank_black_24dp_1x.png +0 -0
  168. package/src/static/images/ic_chevron_left_white_24dp_1x.png +0 -0
  169. package/src/static/images/ic_chevron_right_white_24dp_1x.png +0 -0
  170. package/src/static/images/ic_closed_caption_white_24dp_1x.png +0 -0
  171. package/src/static/images/ic_fast_forward_white_24dp_1x.png +0 -0
  172. package/src/static/images/ic_fast_rewind_white_24dp_1x.png +0 -0
  173. package/src/static/images/ic_fullscreen_exit_white_24dp_1x.png +0 -0
  174. package/src/static/images/ic_fullscreen_white_24dp_1x.png +0 -0
  175. package/src/static/images/ic_hd_white_24dp_1x.png +0 -0
  176. package/src/static/images/ic_keyboard_arrow_left_black_24dp_1x.png +0 -0
  177. package/src/static/images/ic_keyboard_arrow_right_black_24dp_1x.png +0 -0
  178. package/src/static/images/ic_pause_white_24dp_1x.png +0 -0
  179. package/src/static/images/ic_play_arrow_white_24dp_1x.png +0 -0
  180. package/src/static/images/ic_refresh_white_24dp_1x.png +0 -0
  181. package/src/static/images/ic_settings_white_24dp_1x.png +0 -0
  182. package/src/static/images/ic_skip_next_white_24dp_1x.png +0 -0
  183. package/src/static/images/ic_skip_previous_white_24dp_1x.png +0 -0
  184. package/src/static/images/ic_toc_white_24dp_1x.png +0 -0
  185. package/src/static/images/ic_volume_off_white_24dp_1x.png +0 -0
  186. package/src/static/images/ic_volume_up_white_24dp_1x.png +0 -0
  187. package/src/static/player4ie8.css +225 -0
  188. package/src/styles/bplaylist.css.js +124 -0
  189. package/src/styles/index.js +1966 -0
  190. package/src/styles/playlist.css.js +84 -0
  191. package/src/styles/rplaylist.css.js +98 -0
  192. package/src/svgs.js +111 -0
  193. package/src/types/Logger.js +10 -0
  194. package/src/types/Options.js +179 -0
  195. package/src/types/Playlist.js +3 -0
  196. package/src/types/Source.js +28 -0
  197. package/src/types/State.js +46 -0
  198. package/src/types/Styles.js +11 -0
  199. package/src/types/TimeData.js +8 -0
  200. package/src/types/Translation.js +69 -0
  201. package/src/utils/absolutizeUrl.js +9 -0
  202. package/src/utils/addClass.js +9 -0
  203. package/src/utils/addEvent.js +31 -0
  204. package/src/utils/addProperty.js +65 -0
  205. package/src/utils/appendChild.js +14 -0
  206. package/src/utils/buff2hex.js +5 -0
  207. package/src/utils/contains.js +33 -0
  208. package/src/utils/createElement.js +24 -0
  209. package/src/utils/each.js +34 -0
  210. package/src/utils/escapeHTML.js +8 -0
  211. package/src/utils/existy.js +4 -0
  212. package/src/utils/extend.js +17 -0
  213. package/src/utils/filter.js +16 -0
  214. package/src/utils/find.js +11 -0
  215. package/src/utils/findIndex.js +20 -0
  216. package/src/utils/first.js +5 -0
  217. package/src/utils/get.js +19 -0
  218. package/src/utils/has.js +5 -0
  219. package/src/utils/hasClass.js +6 -0
  220. package/src/utils/head.js +11 -0
  221. package/src/utils/inRange.js +16 -0
  222. package/src/utils/index.js +73 -0
  223. package/src/utils/isArray.js +4 -0
  224. package/src/utils/isBoolean.js +3 -0
  225. package/src/utils/isElement.js +7 -0
  226. package/src/utils/isEmpty.js +6 -0
  227. package/src/utils/isEqual.js +33 -0
  228. package/src/utils/isEqualBuffer.js +13 -0
  229. package/src/utils/isFunction.js +3 -0
  230. package/src/utils/isNotEmpty.js +5 -0
  231. package/src/utils/isObject.js +5 -0
  232. package/src/utils/isString.js +9 -0
  233. package/src/utils/last.js +4 -0
  234. package/src/utils/map.js +11 -0
  235. package/src/utils/negate.js +8 -0
  236. package/src/utils/noop.js +1 -0
  237. package/src/utils/notExisty.js +5 -0
  238. package/src/utils/reduce.js +8 -0
  239. package/src/utils/remove.js +7 -0
  240. package/src/utils/removeClass.js +8 -0
  241. package/src/utils/removeEvent.js +7 -0
  242. package/src/utils/toArray.js +7 -0
  243. package/src/utils/toggleClass.js +16 -0
  244. package/src/utils/uidGenerator.js +8 -0
  245. package/src/utils/upperFirst.js +4 -0
  246. package/tests/extensions/__snapshots__/download.spec.js.snap +226 -0
  247. package/tests/extensions/__snapshots__/fullscreen.spec.js.snap +30 -0
  248. package/tests/extensions/__snapshots__/title.spec.js.snap +16 -0
  249. package/tests/extensions/download.spec.js +111 -0
  250. package/tests/extensions/fullscreen.spec.js +56 -0
  251. package/tests/extensions/title.spec.js +35 -0
  252. package/tests/mocks/assets/BaseM.mp4 +0 -0
  253. package/tests/mocks/assets/hls.min.js +5 -0
  254. package/tests/mocks/assets/styleMock.js +1 -0
  255. package/tests/mocks/base-player-options.js +47 -0
  256. package/tests/mocks/sources.js +58 -0
  257. package/tests/mocks/timedata/cc_en.vtt +171 -0
  258. package/tests/mocks/timedata/cc_ge.vtt +178 -0
  259. package/tests/utils/wait.js +1 -0
  260. package/webpack.config.js +78 -0
@@ -0,0 +1,118 @@
1
+ import StateEntity from "../state";
2
+ import BaseExtension from "./base";
3
+ import BaseController from '../players/base';
4
+ import { createElement } from "../utils";
5
+
6
+ import type { Player$ExtensionOptions } from '../types/Options';
7
+
8
+ const CN = 'rmp-ext-crawl';
9
+ const CN_TEXT = `${CN}__text`;
10
+
11
+ export default class CrawlExtension extends BaseExtension {
12
+ $crawl;
13
+ $intervalId;
14
+
15
+ constructor(
16
+ player: BaseController,
17
+ state: StateEntity,
18
+ options: Player$ExtensionOptions,
19
+ ) {
20
+ super(player, state, options, []);
21
+ this.logger.debug('crawl:extensions:creating');
22
+ this.render();
23
+ this.logger.debug('crawl:extensions:created');
24
+
25
+ options.bus.on('fullscreenchanging', () => {
26
+ setTimeout(() => this.refresh(this.options.crawl, this.options.showCrawl), 100);
27
+ });
28
+
29
+ options.bus.on('resizeplayer', () => {
30
+ setTimeout(() => this.refresh(this.options.crawl, this.options.showCrawl), 100);
31
+ });
32
+ }
33
+
34
+ startAnimation(interval: number = 100) {
35
+ if (this.$intervalId) {
36
+ return;
37
+ }
38
+
39
+ const crawlTextElement = document.getElementById('crawlText');
40
+ const containerWidth = document.querySelector('.rmp-ext-crawl').offsetWidth;
41
+ const textWidth = crawlTextElement.offsetWidth;
42
+
43
+ let currentPosition = containerWidth;
44
+
45
+ const crawl = () => {
46
+ currentPosition--;
47
+
48
+ if (currentPosition < -textWidth) {
49
+ currentPosition = containerWidth;
50
+ }
51
+
52
+ crawlTextElement.style.transform = `translateX(${currentPosition}px)`;
53
+ };
54
+
55
+ this.$intervalId = setInterval(crawl, interval);
56
+ }
57
+
58
+ render() {
59
+ this.$crawl = createElement('div', { class: CN, 'data-testid': 'crawl' });
60
+ const content = createElement('div', {
61
+ id: 'crawlText', class: CN_TEXT, title: this.options.crawl, tabindex: 0
62
+ }, this.$crawl);
63
+
64
+ content.innerHTML = clearHtml(this.options.crawl.text) || '';
65
+
66
+ this.$crawl.style.color = this.options.crawl.textColor;
67
+ this.$crawl.style.backgroundColor = this.options.crawl.backgroundColor;
68
+
69
+ this.toggle(this.options.showCrawl);
70
+
71
+ setTimeout(() => this.startAnimation(this.options.crawl.speed));
72
+ }
73
+
74
+ getOuter() {
75
+ return this.$crawl;
76
+ }
77
+
78
+ toggle(visibility: boolean) {
79
+ if (visibility) {
80
+ this.$crawl.style.display = 'block';
81
+ } else {
82
+ this.$crawl.style.display = 'none';
83
+ }
84
+ }
85
+
86
+ refresh(crawl, visibility) {
87
+ if (!this.$crawl) return;
88
+
89
+ const crawlText = document.getElementById('crawlText');
90
+ crawlText.innerHTML = clearHtml(crawl.text) || '';
91
+ this.$crawl.style.color = crawl.textColor;
92
+ this.$crawl.style.backgroundColor = crawl.backgroundColor;
93
+ clearInterval(this.$intervalId);
94
+ this.$intervalId = null;
95
+ this.toggle(visibility);
96
+
97
+ if (visibility) {
98
+ this.startAnimation(crawl.speed);
99
+ }
100
+ }
101
+
102
+ destroy() {
103
+ super.destroy();
104
+ if (this.$crawl) {
105
+ const parent = this.$crawl.parentNode;
106
+ parent.removeChild(this.$crawl);
107
+ this.$crawl = null;
108
+ clearInterval(this.$intervalId);
109
+ this.$intervalId = null;
110
+ }
111
+ }
112
+ }
113
+
114
+ function clearHtml(html) {
115
+ let clearedHtml = html.replace(/(\r\n|\n|\r)/gm, '');
116
+ // remove br tags
117
+ return clearedHtml.replace(/<br\s*[\/]?>/gi, '');
118
+ }
@@ -0,0 +1,411 @@
1
+ import BaseExtension from './base';
2
+
3
+ import {
4
+ createElement,
5
+ addClass,
6
+ isEmpty,
7
+ each,
8
+ toArray,
9
+ removeClass,
10
+ last
11
+ } from '../utils';
12
+
13
+ import opener from './helpers/clickOpener';
14
+ import openerHeightChecker from './helpers/openerHeightChecker';
15
+ import popover from './helpers/popover';
16
+ import { secondsToTime } from './helpers/timeCodeToSeconds';
17
+ import {
18
+ UNAPPROVED_TIMEDATA_STATUS,
19
+ TRANSLATABLE_TIMEDATA_STATUS
20
+ } from '../config/statuses';
21
+
22
+ import createSvg, { DOWNLOAD, BACK, NEXT } from '../svgs';
23
+ import loadVTT from './helpers/vtt-loader';
24
+ import load from './helpers/transport';
25
+ import { saveAs } from './helpers/FileSaver';
26
+
27
+ const CN = 'rmp-ext-download';
28
+ const BUTTON_CN = `${CN}__button`;
29
+ const SELECTOR_CN = `${CN}__selector`;
30
+ const SELECTOR_OPEN_CN = `${SELECTOR_CN}--open`;
31
+ const SELECTOR_SHOW_ADDITIONAL_CN = `${SELECTOR_CN}--additional`;
32
+ const MORE_CN = `${CN}__more`;
33
+
34
+ const MAIN_STEP_CN = `${CN}__main-step`;
35
+ const ADDITIONAL_STEP_CN = `${CN}__additional-step`;
36
+
37
+ const BACK_BTN_CN = `${CN}__back`;
38
+
39
+ const DOWNLOADCC_CN = `${CN}__download-cc`;
40
+
41
+ export default class DownloadExtension extends BaseExtension {
42
+ constructor(player, state, options) {
43
+ super(player, state, options);
44
+ this.logger.debug('download:extension:creating');
45
+
46
+ this.render();
47
+ this.init();
48
+
49
+ this.logger.debug('download:extension:created');
50
+ }
51
+
52
+ render() {
53
+ /** @type {HTMLMediaElement} */
54
+ this.$el = createElement('span', { class: CN, 'data-testid': 'download' });
55
+
56
+ this.$button = createElement(
57
+ 'button',
58
+ { type: 'button', class: BUTTON_CN },
59
+ this.$el
60
+ );
61
+
62
+ this.$selector = createElement('div', { class: SELECTOR_CN }, this.$el);
63
+ this.$link = createElement(
64
+ 'a',
65
+ { style: 'display: none;' },
66
+ this.$selector
67
+ );
68
+
69
+ this.$mainStep = createElement(
70
+ 'div',
71
+ { class: MAIN_STEP_CN },
72
+ this.$selector
73
+ );
74
+
75
+ if (this.options.showDownloadVideo) {
76
+ this.$video = createElement(
77
+ 'button',
78
+ { type: 'button', class: DOWNLOADCC_CN },
79
+ this.$mainStep
80
+ );
81
+
82
+ const text = createElement('span', {}, this.$video);
83
+ text.textContent = this.$t('video-drm');
84
+ addClass(this.$video, MORE_CN);
85
+
86
+ _createMore(this.$video);
87
+ }
88
+
89
+ if (this.options.showDownloadCC) {
90
+ this.$cc = createElement(
91
+ 'button',
92
+ { type: 'button', class: DOWNLOADCC_CN },
93
+ this.$mainStep
94
+ );
95
+
96
+ const ccText = createElement('span', {}, this.$cc);
97
+ ccText.textContent = this.$t('cc');
98
+ addClass(this.$cc, MORE_CN);
99
+
100
+ _createMore(this.$cc);
101
+
102
+ this.$transcript = createElement(
103
+ 'button',
104
+ { type: 'button', class: DOWNLOADCC_CN },
105
+ this.$mainStep
106
+ );
107
+
108
+ const transcriptText = createElement('span', {}, this.$transcript);
109
+ transcriptText.textContent = this.$t('transcript');
110
+ addClass(this.$transcript, MORE_CN);
111
+
112
+ _createMore(this.$transcript);
113
+ }
114
+
115
+ if (this.options.downloadVideoURL) {
116
+ this.$mp4 = createElement(
117
+ 'button',
118
+ { type: 'button', class: DOWNLOADCC_CN },
119
+ this.$mainStep
120
+ );
121
+ const mp4 = createElement('span', {}, this.$mp4);
122
+ mp4.textContent = this.$t('video-drm');
123
+ }
124
+
125
+ this.$svg = createSvg(this.$button, DOWNLOAD);
126
+ this.$spinner = createElement('img', {
127
+ src: '/images/Spinner-small.gif',
128
+ height: '26',
129
+ width: '26'
130
+ });
131
+
132
+ this.$additionalStep = createElement(
133
+ 'div',
134
+ { class: ADDITIONAL_STEP_CN },
135
+ this.$selector
136
+ );
137
+
138
+ this.$back = createElement(
139
+ 'button',
140
+ { type: 'button', class: BACK_BTN_CN },
141
+ this.$additionalStep
142
+ );
143
+ const $backSpan = createElement('span', { class: 'arrow' }, this.$back);
144
+ createSvg($backSpan, BACK);
145
+
146
+ this.$backText = createElement('span', {}, this.$back);
147
+
148
+ this.$additional = createElement('div', { class: 'tab-content' }, this.$additionalStep);
149
+ }
150
+
151
+ init() {
152
+ const $button = this.$button,
153
+ $selector = this.$selector,
154
+ reposition = false,
155
+ closeOnClick = false;
156
+ const options = this.options;
157
+ opener(this, {
158
+ $button,
159
+ $selector,
160
+ SELECTOR_OPEN_CN,
161
+ reposition,
162
+ closeOnClick,
163
+ firstFocusItemSelector: `.${DOWNLOADCC_CN}`,
164
+ toMainFn: this._toMain.bind(this)
165
+ });
166
+ popover(this, { $button, text: this.$t('download') });
167
+
168
+ if (isEmpty(options.downloadCCLanguages) && !options.showDownloadCC && !options.downloadVideoURL) {
169
+ this.addEvent(this.$el, 'click', this.downloadDRMVideo.bind(this, null));
170
+ return;
171
+ }
172
+
173
+ if (options.downloadVideoURL) {
174
+ this.addEvent(this.$mp4, 'click', this.performClick.bind(this, options.downloadVideoURL));
175
+ }
176
+
177
+ this.addEvent(this.$back, 'click', () => this._toMain());
178
+
179
+ if (options.showDownloadVideo) {
180
+ this.addEvent(this.$video, 'click', (e) => {
181
+ e.preventDefault();
182
+ e.stopPropagation();
183
+ this._toAdditional(this.$t('video-drm'));
184
+ this._renderVideos();
185
+ });
186
+ }
187
+
188
+ if (options.showDownloadCC) {
189
+ this.addEvent(this.$transcript, 'click', (e) => {
190
+ e.preventDefault();
191
+ e.stopPropagation();
192
+ this._toAdditional(this.$t('transcript'));
193
+ this._renderTranscripts();
194
+ });
195
+
196
+ this.addEvent(this.$cc, 'click', (e) => {
197
+ e.preventDefault();
198
+ e.stopPropagation();
199
+ this._toAdditional(this.$t('cc'));
200
+ this._renderClosedCaptions();
201
+ });
202
+ }
203
+ }
204
+
205
+ downloadDRMVideo(ccLanguage) {
206
+ let url = this.options.downloadURL;
207
+ if (ccLanguage !== null) {
208
+ url += '?ccLang=' + ccLanguage;
209
+ }
210
+
211
+ this.bus.emit('downloadRequested', url, this.performClick.bind(this));
212
+ this.$button.removeChild(this.$svg);
213
+ this.$button.appendChild(this.$spinner);
214
+ }
215
+
216
+ downloadTranscript(cc) {
217
+ const filename = `transcript__${cc.srclang}.txt`;
218
+ if (cc.type === 'json') {
219
+ load({
220
+ url: cc.src,
221
+ success: (resp) =>
222
+ this.prepareTranscriptForDownload(JSON.parse(resp.data), filename)
223
+ });
224
+ } else {
225
+ loadVTT(cc.src, (m) => this.prepareTranscriptForDownload(m, filename));
226
+ }
227
+ }
228
+
229
+ prepareTranscriptForDownload(segments, filename) {
230
+ const { text } = segments.reduce(
231
+ ({ prevSegmentTime, text }, segment) => {
232
+ if (prevSegmentTime > 0 && segment.from >= prevSegmentTime + 0.1) {
233
+ text += '\r\n';
234
+ }
235
+ const segmentText = segment.text
236
+ .replace(/(\r?\n|\r)$/, '')
237
+ .replace(/<br\s*\/?>/gm, '\r\n');
238
+ text = text + segmentText + '\r\n';
239
+ return { prevSegmentTime: segment.to, text };
240
+ },
241
+ { text: '', prevSegmentTime: 0 }
242
+ );
243
+
244
+ var blob = new Blob([text], {
245
+ type: 'text/plain;charset=utf-8'
246
+ });
247
+
248
+ saveAs(blob, filename);
249
+ }
250
+
251
+ downloadCC(cc) {
252
+ const filename = `captions__${cc.srclang}.vtt`;
253
+ if (cc.type === 'json') {
254
+ load({
255
+ url: cc.src,
256
+ success: (resp) =>
257
+ this.prepareCCForDownload(JSON.parse(resp.data), filename)
258
+ });
259
+ } else {
260
+ load({
261
+ url: cc.src,
262
+ success: (resp) => {
263
+ var blob = new Blob([resp.data], {
264
+ type: 'text/plain;charset=utf-8'
265
+ });
266
+
267
+ saveAs(blob, filename);
268
+ }
269
+ });
270
+ }
271
+ }
272
+
273
+ prepareCCForDownload(segments, filename) {
274
+ const text = segments.reduce((memo, segment) => {
275
+ if (!memo) {
276
+ memo += 'WEBVTT\r\n';
277
+ }
278
+ memo += '\r\n';
279
+ memo +=
280
+ secondsToTime(segment.from, false, true) +
281
+ ' --> ' +
282
+ secondsToTime(segment.to, false, true);
283
+ memo += '\r\n';
284
+ memo += segment.text;
285
+ memo += '\r\n';
286
+ return memo;
287
+ }, '');
288
+
289
+ var blob = new Blob([text], {
290
+ type: 'text/plain;charset=utf-8'
291
+ });
292
+
293
+ saveAs(blob, filename);
294
+ }
295
+
296
+ getElement() {
297
+ return this.$el;
298
+ }
299
+
300
+ destroy() {
301
+ super.destroy();
302
+
303
+ const parent = this.$el.parentNode;
304
+ parent.removeChild(this.$el);
305
+ this.$el = null;
306
+ }
307
+
308
+ performClick(url) {
309
+ var link = document.createElement('a', {href: url, target: '_blank'});
310
+ link.href = url;
311
+ link.target = '_blank';
312
+ link.className = 'rmp-ext-download-hidden';
313
+ link.download = last(url.split('/')) || 'video.mp4';
314
+ document.body.appendChild(link);
315
+ link.click();
316
+ // document.body.removeChild(link);
317
+
318
+ try {
319
+ this.$button.removeChild(this.$spinner);
320
+ this.$button.appendChild(this.$svg);
321
+ } catch (e) {
322
+ // noop
323
+ }
324
+ }
325
+
326
+ _toMain() {
327
+ removeClass(this.$selector, SELECTOR_SHOW_ADDITIONAL_CN);
328
+ openerHeightChecker(this.player, this.$mainStep);
329
+
330
+ // Accessability: Focus on first item of main page
331
+ const mainStepItems = document.querySelectorAll(`.${MAIN_STEP_CN} > .${DOWNLOADCC_CN}`);
332
+ if (mainStepItems[0]) mainStepItems[0].focus();
333
+ }
334
+
335
+ _toAdditional(text) {
336
+ const items = toArray(this.$additional.childNodes);
337
+ each(items, (btn) => this.$additional.removeChild(btn));
338
+ addClass(this.$selector, SELECTOR_SHOW_ADDITIONAL_CN);
339
+ this.$backText.textContent = text;
340
+
341
+ openerHeightChecker(this.player, this.$additionalStep);
342
+
343
+ // Accessability: focus on the first item
344
+ this.$back.focus();
345
+ }
346
+
347
+ _renderVideos() {
348
+ const btn = createElement(
349
+ 'button',
350
+ { type: 'button', class: DOWNLOADCC_CN },
351
+ this.$additional
352
+ );
353
+
354
+ this.addEvent(btn, 'click', () => this.downloadDRMVideo(null));
355
+ const text = createElement('span', {}, btn);
356
+ text.textContent = this.$t('video-only');
357
+
358
+ each(this.options.downloadCCLanguages, (c) => {
359
+ const btn = createElement(
360
+ 'button',
361
+ { type: 'button', class: DOWNLOADCC_CN },
362
+ this.$additional
363
+ );
364
+
365
+ this.addEvent(btn, 'click', () => this.downloadDRMVideo(c.code));
366
+ const text = createElement('span', {}, btn);
367
+ text.textContent = `${this.$t('video-and')} ${c.label} CC`;
368
+ });
369
+ }
370
+
371
+ _renderTranscripts() {
372
+ each(this.options.cc.filter(isApprovedCC), (cc) => {
373
+ const btn = createElement(
374
+ 'button',
375
+ { type: 'button', class: DOWNLOADCC_CN },
376
+ this.$additional
377
+ );
378
+
379
+ this.addEvent(btn, 'click', () => this.downloadTranscript(cc));
380
+ const text = createElement('span', {}, btn);
381
+ text.textContent = cc.label;
382
+ });
383
+ }
384
+
385
+ _renderClosedCaptions() {
386
+ each(this.options.cc.filter(isApprovedCC), (cc) => {
387
+ const btn = createElement(
388
+ 'button',
389
+ { type: 'button', class: DOWNLOADCC_CN },
390
+ this.$additional
391
+ );
392
+
393
+ this.addEvent(btn, 'click', () => this.downloadCC(cc));
394
+ const text = createElement('span', {}, btn);
395
+ text.textContent = cc.label;
396
+ });
397
+ }
398
+ }
399
+
400
+ function _createMore($parent) {
401
+ const span = createElement('span', { class: 'arrow' }, $parent);
402
+ createSvg(span, NEXT);
403
+ return span;
404
+ }
405
+
406
+ function isApprovedCC(cc) {
407
+ return (
408
+ cc.state !== UNAPPROVED_TIMEDATA_STATUS &&
409
+ cc.state !== TRANSLATABLE_TIMEDATA_STATUS
410
+ );
411
+ }
@@ -0,0 +1,47 @@
1
+ import BaseExtension from './base';
2
+
3
+ import { createElement, removeClass } from '../utils';
4
+ import createSvg, { ERROR } from '../svgs';
5
+
6
+ const CN = 'rmp-ext-error';
7
+ const HIDDEN_CN = `${CN}--hidden`;
8
+ const ERROR_CONTENT = `${CN}__content`;
9
+
10
+ export default class ErrorExtension extends BaseExtension {
11
+ constructor(player, state, options) {
12
+ super(player, state, options, ['error']);
13
+ this.logger.debug('error:extension:creating');
14
+
15
+ this.onError = this.onError.bind(this);
16
+
17
+ this.render();
18
+
19
+ this.logger.debug('error:extension:created');
20
+ }
21
+
22
+ render() {
23
+ this.$outer = createElement('div', { class: `${CN} ${HIDDEN_CN}`, tabindex: -1 });
24
+ createSvg(this.$outer, ERROR, { class: 'error', width: 800, height: 800, viewBox: '0 0 16 16' });
25
+ const error = createElement('div', { class: ERROR_CONTENT }, this.$outer);
26
+ error.textContent = this.$t('error');
27
+ this.logger.debug('error:extension:rendered');
28
+ }
29
+
30
+ onError() {
31
+ this.logger.debug('error:extension:onError');
32
+ removeClass(this.$outer, HIDDEN_CN);
33
+ }
34
+
35
+ getOuter() {
36
+ return this.$outer;
37
+ }
38
+
39
+ destroy() {
40
+ super.destroy();
41
+ if (this.$outer) {
42
+ const parent = this.$outer.parentNode;
43
+ parent.removeChild(this.$outer);
44
+ this.$outer = null;
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,44 @@
1
+ import BaseExtension from './base';
2
+
3
+ import createElement from '../utils/createElement';
4
+
5
+ import popover from './helpers/popover';
6
+ import createSvg, { FORWARD } from '../svgs';
7
+
8
+ const CN = 'rmp-ext-forward';
9
+
10
+ export default class ForwardExtension extends BaseExtension {
11
+ constructor(player, state, options) {
12
+ super(player, state, options);
13
+ this.logger.debug('forward:extension:creating');
14
+
15
+ this.render();
16
+ this.addEvent(this.$el, 'click', this.forward.bind(this));
17
+
18
+ this.logger.debug('forward:extension:created');
19
+ }
20
+
21
+ render() {
22
+ /** @type {HTMLMediaElement} */
23
+ this.$el = createElement('button', { type: 'button', class: CN });
24
+ setTimeout(() => popover(this, { $button: this.$el, text: this.$t('forward') }) );
25
+ createSvg(this.$el, FORWARD);
26
+ }
27
+
28
+ forward() {
29
+ this.player.setCurrentTime(this.player.getCurrentTime() + this.options.skipDelta);
30
+ this.bus.emit('heartbeatextensions');
31
+ }
32
+
33
+ getElement() {
34
+ return this.$el;
35
+ }
36
+
37
+ destroy() {
38
+ super.destroy();
39
+
40
+ const parent = this.$el.parentNode;
41
+ parent.removeChild(this.$el);
42
+ this.$el = null;
43
+ }
44
+ }
@@ -0,0 +1,84 @@
1
+ // @flow
2
+ import BaseExtension from './base';
3
+
4
+ import BaseController from '../players/base';
5
+ import StateEntity from '../state';
6
+
7
+ import { createElement, toggleClass } from '../utils';
8
+
9
+ import popover from './helpers/popover';
10
+ import createSvg, { FULLSCREEN, EXIT_FULLSCREEN } from '../svgs';
11
+
12
+ import type { Player$ExtensionOptions } from '../types/Options';
13
+ import type { Player$State } from '../types/State';
14
+
15
+ const CN = 'rmp-ext-fullscreen';
16
+ const EXIT_CN = `${CN}--exit`;
17
+
18
+ const ESC_CODE = 27;
19
+
20
+ export default class FullScreenExtension extends BaseExtension {
21
+ $el: HTMLElement
22
+
23
+ constructor(player: BaseController, state: StateEntity, options: Player$ExtensionOptions) {
24
+ super(player, state, options, ['statechanged']);
25
+ this.logger.debug('fullscreen:extension:creating');
26
+
27
+ this.render();
28
+
29
+ this.addEvent(this.$el, 'click', this.toggle.bind(this));
30
+ this.addEvent(document, 'keyup', this.onKeyup.bind(this));
31
+
32
+ if (!!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform)) {
33
+ this.addEvent(window, 'resize', this.onResize.bind(this));
34
+ }
35
+
36
+ toggleClass(this.$el, EXIT_CN, this.state.isFullScreen());
37
+
38
+ this.logger.debug('fullscreen:extension:created');
39
+ }
40
+
41
+ render() {
42
+ /** @type {HTMLMediaElement} */
43
+ this.$el = createElement('button', { type: 'button', class: CN, 'data-testid': 'fullscreen' });
44
+
45
+ createSvg(this.$el, FULLSCREEN, { class: 'fullscreen-icon'});
46
+ createSvg(this.$el, EXIT_FULLSCREEN, { class: 'exit-fullscreen-icon'});
47
+
48
+ const text = () => this.$t(this.state.isFullScreen() ? 'exit-fullscreen' : 'fullscreen');
49
+ setTimeout(() => popover(this, { $button: this.$el, text }) );
50
+ }
51
+
52
+ onResize() {
53
+ if (this.state.isFullScreen()) {
54
+ this.bus.emit('fullscreenchanging', true);
55
+ }
56
+ }
57
+
58
+ onKeyup(e: KeyboardEvent) {
59
+ if (e.keyCode === ESC_CODE) {
60
+ this.bus.emit('fullscreenchanging', false);
61
+ }
62
+ }
63
+
64
+ onStatechanged(state: Player$State) {
65
+ toggleClass(this.$el, EXIT_CN, state.isFullScreen);
66
+ }
67
+
68
+ toggle() {
69
+ this.bus.emit('fullscreenchanging');
70
+ }
71
+
72
+ getElement() {
73
+ return this.$el;
74
+ }
75
+
76
+ destroy() {
77
+ super.destroy();
78
+ const parent = this.$el.parentNode;
79
+ if (parent instanceof HTMLElement) {
80
+ parent.removeChild(this.$el);
81
+ }
82
+ // this.$el = null;
83
+ }
84
+ }