@gcorevideo/player 0.0.1

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 (192) hide show
  1. package/assets/icons/new/arrow-left.svg +5 -0
  2. package/assets/icons/new/arrow-right.svg +5 -0
  3. package/assets/icons/new/check.svg +5 -0
  4. package/assets/icons/new/close.svg +12 -0
  5. package/assets/icons/new/full.svg +8 -0
  6. package/assets/icons/new/fullscreen-off.svg +14 -0
  7. package/assets/icons/new/fullscreen-on.svg +14 -0
  8. package/assets/icons/new/gear-hd.svg +16 -0
  9. package/assets/icons/new/gear.svg +12 -0
  10. package/assets/icons/new/hd.svg +8 -0
  11. package/assets/icons/new/pause.svg +5 -0
  12. package/assets/icons/new/pip.svg +5 -0
  13. package/assets/icons/new/play.svg +10 -0
  14. package/assets/icons/new/replayleft.svg +5 -0
  15. package/assets/icons/new/replayright.svg +5 -0
  16. package/assets/icons/new/speed.svg +5 -0
  17. package/assets/icons/new/stats.svg +3 -0
  18. package/assets/icons/new/stop.svg +3 -0
  19. package/assets/icons/new/subtitles-off.svg +5 -0
  20. package/assets/icons/new/subtitles-on.svg +6 -0
  21. package/assets/icons/new/volume-max.svg +5 -0
  22. package/assets/icons/new/volume-min.svg +5 -0
  23. package/assets/icons/new/volume-off.svg +5 -0
  24. package/assets/icons/old/cardboard.svg +4 -0
  25. package/assets/icons/old/close-share.svg +13 -0
  26. package/assets/icons/old/close.svg +13 -0
  27. package/assets/icons/old/fb.svg +13 -0
  28. package/assets/icons/old/fullscreen.svg +12 -0
  29. package/assets/icons/old/language.svg +1 -0
  30. package/assets/icons/old/pause.svg +12 -0
  31. package/assets/icons/old/play.svg +12 -0
  32. package/assets/icons/old/quality-arrow.svg +13 -0
  33. package/assets/icons/old/reload.svg +4 -0
  34. package/assets/icons/old/share.svg +13 -0
  35. package/assets/icons/old/sound-off.svg +15 -0
  36. package/assets/icons/old/sound-on.svg +15 -0
  37. package/assets/icons/old/streams.svg +3 -0
  38. package/assets/icons/old/twitter.svg +13 -0
  39. package/assets/icons/old/wn.svg +15 -0
  40. package/assets/icons/standard/01-play.svg +3 -0
  41. package/assets/icons/standard/02-pause.svg +3 -0
  42. package/assets/icons/standard/03-stop.svg +3 -0
  43. package/assets/icons/standard/04-volume.svg +3 -0
  44. package/assets/icons/standard/05-mute.svg +3 -0
  45. package/assets/icons/standard/06-expand.svg +3 -0
  46. package/assets/icons/standard/07-shrink.svg +3 -0
  47. package/assets/icons/standard/08-hd.svg +3 -0
  48. package/assets/icons/standard/09-cc.svg +8 -0
  49. package/assets/icons/standard/10-reload.svg +4 -0
  50. package/assets/style/main.scss +50 -0
  51. package/assets/style/theme.scss +42 -0
  52. package/assets/style/variables.scss +7 -0
  53. package/dist/DashPlayback-6wKK0_pL.js +666 -0
  54. package/dist/DashPlayback-8U6_s4Jc.js +666 -0
  55. package/dist/DashPlayback-BeZz7mN9.js +663 -0
  56. package/dist/DashPlayback-CRdja67F.js +667 -0
  57. package/dist/DashPlayback-D0df6zGg.js +663 -0
  58. package/dist/DashPlayback-D7egS-CZ.js +664 -0
  59. package/dist/DashPlayback-DH5lZMRR.js +663 -0
  60. package/dist/DashPlayback-DZfIc9sK.js +665 -0
  61. package/dist/DashPlayback-VhCxbQhn.js +666 -0
  62. package/dist/HlsPlayback-Avwy8-0O.js +749 -0
  63. package/dist/index.css +125 -0
  64. package/dist/index.js +467 -0
  65. package/lib/Player.d.ts +50 -0
  66. package/lib/Player.d.ts.map +1 -0
  67. package/lib/Player.js +310 -0
  68. package/lib/backend.d.ts +3 -0
  69. package/lib/backend.d.ts.map +1 -0
  70. package/lib/backend.js +10 -0
  71. package/lib/constants.d.ts +19 -0
  72. package/lib/constants.d.ts.map +1 -0
  73. package/lib/constants.js +18 -0
  74. package/lib/index.d.ts +10 -0
  75. package/lib/index.d.ts.map +1 -0
  76. package/lib/index.js +9 -0
  77. package/lib/internal.types.d.ts +105 -0
  78. package/lib/internal.types.d.ts.map +1 -0
  79. package/lib/internal.types.js +1 -0
  80. package/lib/playback.types.d.ts +13 -0
  81. package/lib/playback.types.d.ts.map +1 -0
  82. package/lib/playback.types.js +1 -0
  83. package/lib/plugins/audio-selector/AudioSelector.d.ts +48 -0
  84. package/lib/plugins/audio-selector/AudioSelector.d.ts.map +1 -0
  85. package/lib/plugins/audio-selector/AudioSelector.js +282 -0
  86. package/lib/plugins/big-mute-button/BigMuteButton.d.ts +33 -0
  87. package/lib/plugins/big-mute-button/BigMuteButton.d.ts.map +1 -0
  88. package/lib/plugins/big-mute-button/BigMuteButton.js +148 -0
  89. package/lib/plugins/bottom-gear/BottomGear.d.ts +30 -0
  90. package/lib/plugins/bottom-gear/BottomGear.d.ts.map +1 -0
  91. package/lib/plugins/bottom-gear/BottomGear.js +103 -0
  92. package/lib/plugins/click-to-pause/ClickToPause.d.ts +16 -0
  93. package/lib/plugins/click-to-pause/ClickToPause.d.ts.map +1 -0
  94. package/lib/plugins/click-to-pause/ClickToPause.js +73 -0
  95. package/lib/plugins/dash-playback/DashPlayback.d.ts +81 -0
  96. package/lib/plugins/dash-playback/DashPlayback.d.ts.map +1 -0
  97. package/lib/plugins/dash-playback/DashPlayback.js +658 -0
  98. package/lib/plugins/dash-plugin/DashPlayback.d.ts +86 -0
  99. package/lib/plugins/dash-plugin/DashPlayback.d.ts.map +1 -0
  100. package/lib/plugins/dash-plugin/DashPlayback.js +659 -0
  101. package/lib/plugins/disable-controls/DisableControls.d.ts +15 -0
  102. package/lib/plugins/disable-controls/DisableControls.d.ts.map +1 -0
  103. package/lib/plugins/disable-controls/DisableControls.js +69 -0
  104. package/lib/plugins/dvr-controls/DVRControls.d.ts +27 -0
  105. package/lib/plugins/dvr-controls/DVRControls.d.ts.map +1 -0
  106. package/lib/plugins/dvr-controls/DVRControls.js +110 -0
  107. package/lib/plugins/hls-playback/HlsPlayback.d.ts +102 -0
  108. package/lib/plugins/hls-playback/HlsPlayback.d.ts.map +1 -0
  109. package/lib/plugins/hls-playback/HlsPlayback.js +747 -0
  110. package/lib/plugins/level-selector/LevelSelector.d.ts +48 -0
  111. package/lib/plugins/level-selector/LevelSelector.d.ts.map +1 -0
  112. package/lib/plugins/level-selector/LevelSelector.js +287 -0
  113. package/lib/plugins/media-control/MediaControl.d.ts +186 -0
  114. package/lib/plugins/media-control/MediaControl.d.ts.map +1 -0
  115. package/lib/plugins/media-control/MediaControl.js +1000 -0
  116. package/lib/plugins/poster/Poster.d.ts +41 -0
  117. package/lib/plugins/poster/Poster.d.ts.map +1 -0
  118. package/lib/plugins/poster/Poster.js +186 -0
  119. package/lib/trace/LogTracer.d.ts +12 -0
  120. package/lib/trace/LogTracer.d.ts.map +1 -0
  121. package/lib/trace/LogTracer.js +17 -0
  122. package/lib/trace/SentryTracer.d.ts +11 -0
  123. package/lib/trace/SentryTracer.d.ts.map +1 -0
  124. package/lib/trace/SentryTracer.js +18 -0
  125. package/lib/trace/Tracer.d.ts +13 -0
  126. package/lib/trace/Tracer.d.ts.map +1 -0
  127. package/lib/trace/Tracer.js +15 -0
  128. package/lib/trace/index.d.ts +18 -0
  129. package/lib/trace/index.d.ts.map +1 -0
  130. package/lib/trace/index.js +27 -0
  131. package/lib/trace/types.d.ts +8 -0
  132. package/lib/trace/types.d.ts.map +1 -0
  133. package/lib/trace/types.js +1 -0
  134. package/lib/types.d.ts +82 -0
  135. package/lib/types.d.ts.map +1 -0
  136. package/lib/types.js +1 -0
  137. package/lib/utils/Logger.d.ts +23 -0
  138. package/lib/utils/Logger.d.ts.map +1 -0
  139. package/lib/utils/Logger.js +81 -0
  140. package/lib/utils/canAutoplay.d.ts +6 -0
  141. package/lib/utils/canAutoplay.d.ts.map +1 -0
  142. package/lib/utils/canAutoplay.js +30 -0
  143. package/lib/utils/errors.d.ts +2 -0
  144. package/lib/utils/errors.d.ts.map +1 -0
  145. package/lib/utils/errors.js +6 -0
  146. package/lib/utils/queryParams.d.ts +2 -0
  147. package/lib/utils/queryParams.d.ts.map +1 -0
  148. package/lib/utils/queryParams.js +4 -0
  149. package/lib/utils/scripts-load.d.ts +2 -0
  150. package/lib/utils/scripts-load.d.ts.map +1 -0
  151. package/lib/utils/scripts-load.js +20 -0
  152. package/lib/utils/types.d.ts +4 -0
  153. package/lib/utils/types.d.ts.map +1 -0
  154. package/lib/utils/types.js +1 -0
  155. package/lib/utils/utils.d.ts +7 -0
  156. package/lib/utils/utils.d.ts.map +1 -0
  157. package/lib/utils/utils.js +57 -0
  158. package/package.json +57 -0
  159. package/rollup.config.js +34 -0
  160. package/src/Player.ts +390 -0
  161. package/src/backend.ts +12 -0
  162. package/src/constants.ts +17 -0
  163. package/src/index.ts +9 -0
  164. package/src/internal.types.ts +126 -0
  165. package/src/playback.types.ts +15 -0
  166. package/src/plugins/dash-playback/DashPlayback.ts +808 -0
  167. package/src/plugins/dash-playback/_DashPlayback.js +688 -0
  168. package/src/plugins/hls-playback/HlsPlayback.ts +909 -0
  169. package/src/plugins/hls-playback/hls.js +706 -0
  170. package/src/trace/LogTracer.ts +23 -0
  171. package/src/trace/SentryTracer.ts +18 -0
  172. package/src/trace/Tracer.ts +27 -0
  173. package/src/trace/index.ts +32 -0
  174. package/src/trace/types.ts +7 -0
  175. package/src/types.ts +100 -0
  176. package/src/typings/@clappr/core/error_mixin.d.ts +15 -0
  177. package/src/typings/@clappr/core/events.d.ts +7 -0
  178. package/src/typings/@clappr/core/html5_video.d.ts +28 -0
  179. package/src/typings/@clappr/core/playback.d.ts +5 -0
  180. package/src/typings/@clappr/core/player.d.ts +83 -0
  181. package/src/typings/@clappr/plugins.d.ts +29 -0
  182. package/src/typings/clappr-zepto.xd.xts +44 -0
  183. package/src/typings/globals.d.ts +8 -0
  184. package/src/utils/Logger.ts +107 -0
  185. package/src/utils/canAutoplay.ts +39 -0
  186. package/src/utils/errors.ts +6 -0
  187. package/src/utils/queryParams.ts +5 -0
  188. package/src/utils/scripts-load.ts +26 -0
  189. package/src/utils/types.ts +5 -0
  190. package/src/utils/utils.ts +64 -0
  191. package/tsconfig.json +43 -0
  192. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,659 @@
1
+ // Copyright 2014 Globo.com Player authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+ import { Events, HTML5Video, Log, Playback, /* PlayerError, */ Utils } from '@clappr/core';
5
+ import assert from 'assert'; // uses Node.js's assert types
6
+ import DASHJS from 'dashjs';
7
+ import { trace } from '../../trace/index.js';
8
+ const AUTO = -1;
9
+ const { now } = Utils;
10
+ const T = "DashPlayback";
11
+ export default class DashPlayback extends HTML5Video {
12
+ _levels = null;
13
+ _currentLevel = null;
14
+ _durationExcludesAfterLiveSyncPoint = false;
15
+ _isReadyState = false;
16
+ _playableRegionDuration = 0;
17
+ _playableRegionStartTime = 0;
18
+ _playbackType = Playback.VOD;
19
+ _playlistType = null;
20
+ // #EXT-X-PROGRAM-DATE-TIME
21
+ _programDateTime = 0;
22
+ _dash = null;
23
+ _extrapolatedWindowDuration = 0;
24
+ _extrapolatedWindowNumSegments = 0;
25
+ _lastDuration = null;
26
+ _lastTimeUpdate = { current: 0, total: 0 };
27
+ _localStartTimeCorrelation = null;
28
+ _localEndTimeCorrelation = null;
29
+ _recoverAttemptsRemaining = 0;
30
+ _recoveredAudioCodecError = false;
31
+ _recoveredDecodingError = false;
32
+ startChangeQuality = false;
33
+ manifestInfo = null;
34
+ // #EXT-X-TARGETDURATION
35
+ _segmentTargetDuration = null;
36
+ _timeUpdateTimer = null;
37
+ get name() {
38
+ return 'dash';
39
+ }
40
+ get levels() {
41
+ return this._levels || [];
42
+ }
43
+ get currentLevel() {
44
+ if (this._currentLevel === null) {
45
+ return AUTO;
46
+ }
47
+ // 0 is a valid level ID
48
+ return this._currentLevel;
49
+ }
50
+ get isReady() {
51
+ return this._isReadyState;
52
+ }
53
+ set currentLevel(id) {
54
+ this._currentLevel = id;
55
+ this.trigger(Events.PLAYBACK_LEVEL_SWITCH_START);
56
+ const cfg = {
57
+ streaming: {
58
+ abr: {
59
+ autoSwitchBitrate: {
60
+ video: id === -1,
61
+ },
62
+ ABRStrategy: 'abrL2A'
63
+ }
64
+ },
65
+ };
66
+ assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to switch levels');
67
+ const dash = this._dash;
68
+ this.options.dash && dash.updateSettings({ ...this.options.dash, ...cfg });
69
+ if (id !== -1) {
70
+ this._dash.setQualityFor('video', id);
71
+ }
72
+ if (this._playbackType === Playback.VOD) {
73
+ const curr_time = this._dash.time();
74
+ this.startChangeQuality = true;
75
+ dash.seek(0);
76
+ setTimeout(() => {
77
+ dash.seek(curr_time);
78
+ dash.play();
79
+ this.startChangeQuality = false;
80
+ }, 100);
81
+ }
82
+ }
83
+ get _startTime() {
84
+ if (this._playbackType === Playback.LIVE && this._playlistType !== 'EVENT') {
85
+ return this._extrapolatedStartTime;
86
+ }
87
+ return this._playableRegionStartTime;
88
+ }
89
+ get _now() {
90
+ return now();
91
+ }
92
+ // the time in the video element which should represent the start of the sliding window
93
+ // extrapolated to increase in real time (instead of jumping as the early segments are removed)
94
+ get _extrapolatedStartTime() {
95
+ if (!this._localStartTimeCorrelation) {
96
+ return this._playableRegionStartTime;
97
+ }
98
+ const corr = this._localStartTimeCorrelation;
99
+ const timePassed = this._now - corr.local;
100
+ const extrapolatedWindowStartTime = (corr.remote + timePassed) / 1000;
101
+ // cap at the end of the extrapolated window duration
102
+ return Math.min(extrapolatedWindowStartTime, this._playableRegionStartTime + this._extrapolatedWindowDuration);
103
+ }
104
+ // the time in the video element which should represent the end of the content
105
+ // extrapolated to increase in real time (instead of jumping as segments are added)
106
+ get _extrapolatedEndTime() {
107
+ const actualEndTime = this._playableRegionStartTime + this._playableRegionDuration;
108
+ if (!this._localEndTimeCorrelation) {
109
+ return actualEndTime;
110
+ }
111
+ const corr = this._localEndTimeCorrelation;
112
+ const timePassed = this._now - corr.local;
113
+ const extrapolatedEndTime = (corr.remote + timePassed) / 1000;
114
+ return Math.max(actualEndTime - this._extrapolatedWindowDuration, Math.min(extrapolatedEndTime, actualEndTime));
115
+ }
116
+ get _duration() {
117
+ if (!this._dash) {
118
+ return null;
119
+ }
120
+ return this._dash.duration();
121
+ }
122
+ constructor(options, i18n, playerError) {
123
+ super(options, i18n, playerError);
124
+ console.log("DashPlayback constructor", { options, i18n, playerError });
125
+ // backwards compatibility (TODO: remove on 0.3.0)
126
+ // this.options.playback || (this.options.playback = this.options);
127
+ // The size of the start time extrapolation window measured as a multiple of segments.
128
+ // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
129
+ // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
130
+ // added/removed every 5.
131
+ this._extrapolatedWindowNumSegments = this.options.playback?.extrapolatedWindowNumSegments ?? 2;
132
+ if (this.options.playbackType) {
133
+ this._playbackType = this.options.playbackType;
134
+ }
135
+ // this._lastTimeUpdate = { current: 0, total: 0 };
136
+ // this._lastDuration = null;
137
+ // for hls streams which have dvr with a sliding window,
138
+ // the content at the start of the playlist is removed as new
139
+ // content is appended at the end.
140
+ // this means the actual playable start time will increase as the
141
+ // start content is deleted
142
+ // For streams with dvr where the entire recording is kept from the
143
+ // beginning this should stay as 0
144
+ // this._playableRegionStartTime = 0;
145
+ // {local, remote} remote is the time in the video element that should represent 0
146
+ // local is the system time when the 'remote' measurment took place
147
+ // this._localStartTimeCorrelation = null;
148
+ // {local, remote} remote is the time in the video element that should represents the end
149
+ // local is the system time when the 'remote' measurment took place
150
+ // this._localEndTimeCorrelation = null;
151
+ // if content is removed from the beginning then this empty area should
152
+ // be ignored. "playableRegionDuration" excludes the empty area
153
+ // this._playableRegionDuration = 0;
154
+ // #EXT-X-PROGRAM-DATE-TIME
155
+ // this._programDateTime = 0;
156
+ // this.manifestInfo = null;
157
+ // true when the actual duration is longer than hlsjs's live sync point
158
+ // when this is false playableRegionDuration will be the actual duration
159
+ // when this is true playableRegionDuration will exclude the time after the sync point
160
+ // this._durationExcludesAfterLiveSyncPoint = false;
161
+ // // #EXT-X-TARGETDURATION
162
+ // this._segmentTargetDuration = null;
163
+ // #EXT-X-PLAYLIST-TYPE
164
+ // this._playlistType = null;
165
+ if (this.options.hlsRecoverAttempts) {
166
+ this._recoverAttemptsRemaining = this.options.hlsRecoverAttempts;
167
+ }
168
+ }
169
+ _setup() {
170
+ trace(`${T} _setup`, { el: this.el });
171
+ const dash = DASHJS.MediaPlayer().create();
172
+ this._dash = dash;
173
+ this._dash.initialize();
174
+ const cfg = this.options.dash ?? {};
175
+ cfg.streaming = cfg.streaming || {};
176
+ cfg.streaming.text = cfg.streaming.text || { defaultEnabled: false };
177
+ this.options.dash && this._dash.updateSettings(cfg);
178
+ this._dash.attachView(this.el);
179
+ this._dash.setAutoPlay(false);
180
+ this._dash.attachSource(this.options.src);
181
+ this._dash.on(DASHJS.MediaPlayer.events.ERROR, this._onDASHJSSError);
182
+ this._dash.on(DASHJS.MediaPlayer.events.PLAYBACK_ERROR, this._onPlaybackError);
183
+ this._dash.on(DASHJS.MediaPlayer.events.STREAM_INITIALIZED, () => {
184
+ const bitrates = dash.getBitrateInfoListFor('video');
185
+ trace(`${T} STREAM_INITIALIZED`, { bitrates });
186
+ this._updatePlaybackType();
187
+ this._fillLevels(bitrates);
188
+ dash.on(DASHJS.MediaPlayer.events.QUALITY_CHANGE_REQUESTED, (evt) => {
189
+ // TODO
190
+ assert.ok(this._levels, 'An array of levels is required to change quality');
191
+ const newLevel = this._levels.find((level) => level.id === evt.newQuality); // TODO or simply this._levels[evt.newQuality]?
192
+ assert.ok(newLevel, 'A valid level is required to change quality');
193
+ this.onLevelSwitch(newLevel.level);
194
+ });
195
+ });
196
+ this._dash.on(DASHJS.MediaPlayer.events.METRIC_ADDED, (e) => {
197
+ // console.log(`${T} onMetricAdded`, e);
198
+ // TODO
199
+ // Listen for the first manifest request in order to update player UI
200
+ if (e.metric === 'DVRInfo') { // TODO fix typings
201
+ assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to get metrics');
202
+ const dvrInfo = this._dash.getDashMetrics().getCurrentDVRInfo('video');
203
+ // trace(`${T} onMetricAdded DVRInfo`, {metric: e.metric, dvrInfo});
204
+ if (dvrInfo) {
205
+ // Extract time info
206
+ this.manifestInfo = dvrInfo.manifestInfo;
207
+ }
208
+ }
209
+ });
210
+ this._dash.on(DASHJS.MediaPlayer.events.PLAYBACK_RATE_CHANGED, () => {
211
+ this.trigger('dash:playback-rate-changed');
212
+ });
213
+ }
214
+ render() {
215
+ this._ready();
216
+ return super.render();
217
+ }
218
+ _ready() {
219
+ this._isReadyState = true;
220
+ this.trigger(Events.PLAYBACK_READY, this.name);
221
+ }
222
+ // TODO
223
+ // _recover(evt, data, error) {
224
+ // console.warn('recover', evt, data, error);
225
+ // assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to recover');
226
+ // // TODO figure out what's going on here
227
+ // const dash = this._dash;
228
+ // if (!this._recoveredDecodingError) {
229
+ // this._recoveredDecodingError = true;
230
+ // // dash.recoverMediaError();
231
+ // } else if (!this._recoveredAudioCodecError) {
232
+ // this._recoveredAudioCodecError = true;
233
+ // // dash.swapAudioCodec();
234
+ // // dash.recoverMediaError();
235
+ // } else {
236
+ // // TODO what does it have to do with hlsjs?
237
+ // Log.error('hlsjs: failed to recover', { evt, data });
238
+ // error.level = PlayerError.Levels.FATAL;
239
+ // const formattedError = this.createError(error);
240
+ // this.trigger(Events.PLAYBACK_ERROR, formattedError);
241
+ // this.stop();
242
+ // }
243
+ // }
244
+ // override
245
+ _setupSrc() {
246
+ console.log(`${T} _setupSrc`);
247
+ // this playback manages the src on the video element itself
248
+ }
249
+ _startTimeUpdateTimer() {
250
+ this._stopTimeUpdateTimer();
251
+ this._timeUpdateTimer = setInterval(() => {
252
+ this._onDurationChange();
253
+ this._onTimeUpdate();
254
+ }, 100);
255
+ }
256
+ _stopTimeUpdateTimer() {
257
+ if (this._timeUpdateTimer) {
258
+ clearInterval(this._timeUpdateTimer);
259
+ }
260
+ }
261
+ getProgramDateTime() {
262
+ return this._programDateTime;
263
+ }
264
+ // the duration on the video element itself should not be used
265
+ // as this does not necesarily represent the duration of the stream
266
+ // https://github.com/clappr/clappr/issues/668#issuecomment-157036678
267
+ getDuration() {
268
+ assert.ok(this._duration !== null, 'A valid duration is required to get the duration');
269
+ return this._duration;
270
+ }
271
+ getCurrentTime() {
272
+ // e.g. can be < 0 if user pauses near the start
273
+ // eventually they will then be kicked to the end by hlsjs if they run out of buffer
274
+ // before the official start time
275
+ return this._dash ? this._dash.time() : 0;
276
+ }
277
+ // the time that "0" now represents relative to when playback started
278
+ // for a stream with a sliding window this will increase as content is
279
+ // removed from the beginning
280
+ getStartTimeOffset() {
281
+ return this._startTime;
282
+ }
283
+ seekPercentage(percentage) {
284
+ let seekTo = this._duration;
285
+ if (percentage > 0) {
286
+ assert.ok(this._duration !== null, 'A valid duration is required to seek by percentage');
287
+ seekTo = this._duration * (percentage / 100);
288
+ }
289
+ assert.ok(seekTo !== null, 'A valid seek time is required');
290
+ this.seek(seekTo);
291
+ }
292
+ seek(time) {
293
+ if (time < 0) {
294
+ // eslint-disable-next-line max-len
295
+ Log.warn('Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.');
296
+ time = this.getDuration();
297
+ }
298
+ this.dvrEnabled && this._updateDvr(time < this.getDuration() - 10);
299
+ assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to seek');
300
+ this._dash.seek(time);
301
+ }
302
+ seekToLivePoint() {
303
+ this.seek(this.getDuration());
304
+ }
305
+ _updateDvr(status) {
306
+ this.trigger(Events.PLAYBACK_DVR, status);
307
+ this.trigger(Events.PLAYBACK_STATS_ADD, { 'dvr': status });
308
+ }
309
+ _updateSettings() {
310
+ if (this._playbackType === Playback.VOD) {
311
+ this.settings.left = ['playpause', 'position', 'duration'];
312
+ // this.settings.left.push('playstop');
313
+ }
314
+ else if (this.dvrEnabled) {
315
+ this.settings.left = ['playpause'];
316
+ }
317
+ else {
318
+ this.settings.left = ['playstop'];
319
+ }
320
+ this.settings.seekEnabled = this.isSeekEnabled();
321
+ this.trigger(Events.PLAYBACK_SETTINGSUPDATE);
322
+ }
323
+ _onPlaybackError = (event) => {
324
+ // TODO
325
+ };
326
+ _onDASHJSSError = (event) => {
327
+ // TODO
328
+ // only report/handle errors if they are fatal
329
+ // hlsjs should automatically handle non fatal errors
330
+ this._stopTimeUpdateTimer();
331
+ if (event.error === 'capability' && event.event === 'mediasource') {
332
+ // No support for MSE
333
+ const formattedError = this.createError(event.error);
334
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
335
+ Log.error('The media cannot be played because it requires a feature ' +
336
+ 'that your browser does not support.');
337
+ }
338
+ else if (event.error === 'manifestError' && (
339
+ // Manifest type not supported
340
+ (event.event.id === 'createParser') ||
341
+ // Codec(s) not supported
342
+ (event.event.id === 'codec') ||
343
+ // No streams available to stream
344
+ (event.event.id === 'nostreams') ||
345
+ // Error creating Stream object
346
+ (event.event.id === 'nostreamscomposed') ||
347
+ // syntax error parsing the manifest
348
+ (event.event.id === 'parse') ||
349
+ // a stream has multiplexed audio+video
350
+ (event.event.id === 'multiplexedrep'))) {
351
+ // These errors have useful error messages, so we forward it on
352
+ const formattedError = this.createError(event.error);
353
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
354
+ if (event.error) {
355
+ Log.error(event.event.message);
356
+ }
357
+ }
358
+ else if (event.error === 'mediasource') {
359
+ // This error happens when dash.js fails to allocate a SourceBuffer
360
+ // OR the underlying video element throws a `MediaError`.
361
+ // If it's a buffer allocation fail, the message states which buffer
362
+ // (audio/video/text) failed allocation.
363
+ // If it's a `MediaError`, dash.js inspects the error object for
364
+ // additional information to append to the error type.
365
+ const formattedError = this.createError(event.error);
366
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
367
+ Log.error(event.event);
368
+ }
369
+ else if (event.error === 'capability' && event.event === 'encryptedmedia') {
370
+ // Browser doesn't support EME
371
+ const formattedError = this.createError(event.error);
372
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
373
+ Log.error('The media cannot be played because it requires encryption ' +
374
+ 'that your browser does not support.');
375
+ }
376
+ else if (event.error === 'key_session') {
377
+ // This block handles pretty much all errors thrown by the
378
+ // encryption subsystem
379
+ const formattedError = this.createError(event.error);
380
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
381
+ Log.error(event.event);
382
+ }
383
+ else if (event.error === 'download') {
384
+ const formattedError = this.createError(event.error);
385
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
386
+ Log.error('The media playback was aborted because too many consecutive ' +
387
+ 'download errors occurred.');
388
+ // } else if (event.error === 'mssError') {
389
+ // const formattedError = this.createError(event.error);
390
+ // this.trigger(Events.PLAYBACK_ERROR, formattedError);
391
+ // if (event.error) {
392
+ // Log.error(event.error.message);
393
+ // }
394
+ }
395
+ else {
396
+ // ignore the error
397
+ if (typeof event.error === "object") {
398
+ const formattedError = this.createError(event.error);
399
+ this.trigger(Events.PLAYBACK_ERROR, formattedError);
400
+ Log.error(event.error.message);
401
+ }
402
+ else {
403
+ Log.error(event.error);
404
+ }
405
+ return;
406
+ }
407
+ // only reset the dash player in 10ms async, so that the rest of the
408
+ // calling function finishes
409
+ setTimeout(() => {
410
+ assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to reset');
411
+ this._dash.reset();
412
+ }, 10);
413
+ };
414
+ _onTimeUpdate() {
415
+ if (this.startChangeQuality) {
416
+ return;
417
+ }
418
+ const update = {
419
+ current: this.getCurrentTime(),
420
+ total: this.getDuration(),
421
+ firstFragDateTime: this.getProgramDateTime()
422
+ };
423
+ const isSame = this._lastTimeUpdate && (update.current === this._lastTimeUpdate.current &&
424
+ update.total === this._lastTimeUpdate.total);
425
+ if (isSame) {
426
+ return;
427
+ }
428
+ this._lastTimeUpdate = update;
429
+ this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name);
430
+ }
431
+ _onDurationChange() {
432
+ const duration = this.getDuration();
433
+ if (this._lastDuration === duration) {
434
+ return;
435
+ }
436
+ this._lastDuration = duration;
437
+ super._onDurationChange();
438
+ }
439
+ get dvrEnabled() {
440
+ assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to get the DVR status');
441
+ return this._dash?.getDVRWindowSize() >= this._minDvrSize && this.getPlaybackType() === Playback.LIVE;
442
+ }
443
+ _onProgress() {
444
+ if (!this._dash) {
445
+ return;
446
+ }
447
+ let buffer = this._dash.getDashMetrics().getCurrentBufferLevel('video');
448
+ if (!buffer) {
449
+ buffer = this._dash.getDashMetrics().getCurrentBufferLevel('audio');
450
+ }
451
+ const progress = {
452
+ start: this.getCurrentTime(),
453
+ current: this.getCurrentTime() + buffer,
454
+ total: this.getDuration()
455
+ };
456
+ this.trigger(Events.PLAYBACK_PROGRESS, progress, {});
457
+ }
458
+ play() {
459
+ trace(`${T} play`, { dash: !!this._dash });
460
+ if (!this._dash) {
461
+ this._setup();
462
+ }
463
+ super.play();
464
+ this._startTimeUpdateTimer();
465
+ }
466
+ pause() {
467
+ if (!this._dash) {
468
+ return;
469
+ }
470
+ super.pause();
471
+ if (this.dvrEnabled) {
472
+ this._updateDvr(true);
473
+ }
474
+ }
475
+ stop() {
476
+ if (this._dash) {
477
+ this._stopTimeUpdateTimer();
478
+ this._dash.reset();
479
+ super.stop();
480
+ this._dash = null;
481
+ }
482
+ }
483
+ destroy() {
484
+ this._stopTimeUpdateTimer();
485
+ if (this._dash) {
486
+ this._dash.off(DASHJS.MediaPlayer.events.ERROR, this._onDASHJSSError);
487
+ this._dash.off(DASHJS.MediaPlayer.events.PLAYBACK_ERROR, this._onPlaybackError);
488
+ this._dash.off(DASHJS.MediaPlayer.events.MANIFEST_LOADED, this.getDuration);
489
+ this._dash.reset();
490
+ }
491
+ this._dash = null;
492
+ return super.destroy();
493
+ }
494
+ _updatePlaybackType() {
495
+ assert.ok(this._dash, 'An instance of dashjs MediaPlayer is required to update the playback type');
496
+ this._playbackType = this._dash.isDynamic() ? Playback.LIVE : Playback.VOD;
497
+ trace(`${T} _updatePlaybackType`, {
498
+ playbackType: this._playbackType,
499
+ });
500
+ }
501
+ _fillLevels(levels) {
502
+ // trace(`${T} _fillLevels`, {levels});
503
+ // TOOD check that levels[i].qualityIndex === i
504
+ this._levels = levels.map((level) => {
505
+ return { id: level.qualityIndex, level: level };
506
+ });
507
+ this.trigger(Events.PLAYBACK_LEVELS_AVAILABLE, this._levels);
508
+ }
509
+ // _onLevelUpdated(_: any, data) {
510
+ // this._segmentTargetDuration = data.details.targetduration;
511
+ // this._playlistType = data.details.type || null;
512
+ // let startTimeChanged = false;
513
+ // let durationChanged = false;
514
+ // const fragments = data.details.fragments;
515
+ // const previousPlayableRegionStartTime = this._playableRegionStartTime;
516
+ // const previousPlayableRegionDuration = this._playableRegionDuration;
517
+ // if (fragments.length === 0) {
518
+ // return;
519
+ // }
520
+ // // #EXT-X-PROGRAM-DATE-TIME
521
+ // if (fragments[0].rawProgramDateTime) {
522
+ // this._programDateTime = fragments[0].rawProgramDateTime;
523
+ // }
524
+ // if (this._playableRegionStartTime !== fragments[0].start) {
525
+ // startTimeChanged = true;
526
+ // this._playableRegionStartTime = fragments[0].start;
527
+ // }
528
+ // if (startTimeChanged) {
529
+ // if (!this._localStartTimeCorrelation) {
530
+ // // set the correlation to map to middle of the extrapolation window
531
+ // this._localStartTimeCorrelation = {
532
+ // local: this._now,
533
+ // remote: (fragments[0].start + (this._extrapolatedWindowDuration / 2)) * 1000
534
+ // };
535
+ // } else {
536
+ // // check if the correlation still works
537
+ // const corr = this._localStartTimeCorrelation;
538
+ // const timePassed = this._now - corr.local;
539
+ // // this should point to a time within the extrapolation window
540
+ // const startTime = (corr.remote + timePassed) / 1000;
541
+ // if (startTime < fragments[0].start) {
542
+ // // our start time is now earlier than the first chunk
543
+ // // (maybe the chunk was removed early)
544
+ // // reset correlation so that it sits at the beginning of the first available chunk
545
+ // this._localStartTimeCorrelation = {
546
+ // local: this._now,
547
+ // remote: fragments[0].start * 1000
548
+ // };
549
+ // } else if (startTime > previousPlayableRegionStartTime + this._extrapolatedWindowDuration) {
550
+ // // start time was past the end of the old extrapolation window (so would have been capped)
551
+ // // see if now that time would be inside the window, and if it would be set the correlation
552
+ // // so that it resumes from the time it was at at the end of the old window
553
+ // // update the correlation so that the time starts counting again from the value it's on now
554
+ // this._localStartTimeCorrelation = {
555
+ // local: this._now,
556
+ // remote: Math.max(
557
+ // fragments[0].start,
558
+ // previousPlayableRegionStartTime + this._extrapolatedWindowDuration
559
+ // ) * 1000
560
+ // };
561
+ // }
562
+ // }
563
+ // }
564
+ // let newDuration = data.details.totalduration;
565
+ // // if it's a live stream then shorten the duration to remove access
566
+ // // to the area after hlsjs's live sync point
567
+ // // seeks to areas after this point sometimes have issues
568
+ // if (this._playbackType === Playback.LIVE) {
569
+ // const fragmentTargetDuration = data.details.targetduration;
570
+ // const hlsjsConfig = this.options.playback.hlsjsConfig || {};
571
+ // // eslint-disable-next-line no-undef
572
+ // const liveSyncDurationCount = hlsjsConfig.liveSyncDurationCount || HLSJS.DefaultConfig.liveSyncDurationCount;
573
+ // const hiddenAreaDuration = fragmentTargetDuration * liveSyncDurationCount;
574
+ // if (hiddenAreaDuration <= newDuration) {
575
+ // newDuration -= hiddenAreaDuration;
576
+ // this._durationExcludesAfterLiveSyncPoint = true;
577
+ // } else {
578
+ // this._durationExcludesAfterLiveSyncPoint = false;
579
+ // }
580
+ // }
581
+ // if (newDuration !== this._playableRegionDuration) {
582
+ // durationChanged = true;
583
+ // this._playableRegionDuration = newDuration;
584
+ // }
585
+ // // Note the end time is not the playableRegionDuration
586
+ // // The end time will always increase even if content is removed from the beginning
587
+ // const endTime = fragments[0].start + newDuration;
588
+ // const previousEndTime = previousPlayableRegionStartTime + previousPlayableRegionDuration;
589
+ // const endTimeChanged = endTime !== previousEndTime;
590
+ // if (endTimeChanged) {
591
+ // if (!this._localEndTimeCorrelation) {
592
+ // // set the correlation to map to the end
593
+ // this._localEndTimeCorrelation = {
594
+ // local: this._now,
595
+ // remote: endTime * 1000
596
+ // };
597
+ // } else {
598
+ // // check if the correlation still works
599
+ // const corr = this._localEndTimeCorrelation;
600
+ // const timePassed = this._now - corr.local;
601
+ // // this should point to a time within the extrapolation window from the end
602
+ // const extrapolatedEndTime = (corr.remote + timePassed) / 1000;
603
+ // if (extrapolatedEndTime > endTime) {
604
+ // this._localEndTimeCorrelation = {
605
+ // local: this._now,
606
+ // remote: endTime * 1000
607
+ // };
608
+ // } else if (extrapolatedEndTime < endTime - this._extrapolatedWindowDuration) {
609
+ // // our extrapolated end time is now earlier than the extrapolation window from the actual end time
610
+ // // (maybe a chunk became available early)
611
+ // // reset correlation so that it sits at the beginning of the extrapolation window from the end time
612
+ // this._localEndTimeCorrelation = {
613
+ // local: this._now,
614
+ // remote: (endTime - this._extrapolatedWindowDuration) * 1000
615
+ // };
616
+ // } else if (extrapolatedEndTime > previousEndTime) {
617
+ // // end time was past the old end time (so would have been capped)
618
+ // // set the correlation so that it resumes from the time it was at at the end of the old window
619
+ // this._localEndTimeCorrelation = {
620
+ // local: this._now,
621
+ // remote: previousEndTime * 1000
622
+ // };
623
+ // }
624
+ // }
625
+ // }
626
+ // // now that the values have been updated call any methods that use on them so they get the updated values
627
+ // // immediately
628
+ // durationChanged && this._onDurationChange();
629
+ // startTimeChanged && this._onProgress();
630
+ // }
631
+ // _onFragmentLoaded(evt, data) {
632
+ // this.trigger(Events.PLAYBACK_FRAGMENT_LOADED, data);
633
+ // }
634
+ onLevelSwitch(currentLevel) {
635
+ trace(`${T} onLevelSwitch`, { currentLevel });
636
+ this.trigger(Events.PLAYBACK_BITRATE, {
637
+ height: currentLevel.height,
638
+ width: currentLevel.width,
639
+ bitrate: currentLevel.bitrate,
640
+ level: currentLevel.qualityIndex
641
+ });
642
+ }
643
+ getPlaybackType() {
644
+ return this._playbackType;
645
+ }
646
+ isSeekEnabled() {
647
+ return (this._playbackType === Playback.VOD || this.dvrEnabled);
648
+ }
649
+ }
650
+ DashPlayback.canPlay = function (resource, mimeType) {
651
+ console.log(`${T} canPlay resource:%s mimeType:%s`, resource, mimeType);
652
+ const resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || [];
653
+ const isDash = ((resourceParts.length > 1 && resourceParts[1].toLowerCase() === 'mpd') ||
654
+ mimeType === 'application/dash+xml' || mimeType === 'video/mp4');
655
+ const ctor = window.MediaSource || ('WebKitMediaSource' in window ? window.WebKitMediaSource : undefined);
656
+ const isSupportByBrowser = typeof ctor === 'function';
657
+ console.log(`${T} canPlay isSupportByBrowser:%s isDash:%s`, isSupportByBrowser, isDash);
658
+ return !!(isSupportByBrowser && isDash);
659
+ };
@@ -0,0 +1,15 @@
1
+ import { UICorePlugin } from '@clappr/core';
2
+ export default class DisableControls extends UICorePlugin {
3
+ get name(): string;
4
+ get container(): any;
5
+ get supportedVersion(): {
6
+ min: string;
7
+ };
8
+ bindEvents(): void;
9
+ unbindEvents(): void;
10
+ private setDisableStyles;
11
+ private onCoreReady;
12
+ private enableControls;
13
+ private disableAllControls;
14
+ }
15
+ //# sourceMappingURL=DisableControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DisableControls.d.ts","sourceRoot":"","sources":["../../../src/plugins/disable-controls/DisableControls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAU,MAAM,cAAc,CAAC;AAMpD,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,YAAY;IACvD,IAAI,IAAI,WAEP;IAED,IAAI,SAAS,QAEZ;IAED,IAAI,gBAAgB;;MAEnB;IAED,UAAU;IAcV,YAAY;IAqBZ,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,kBAAkB;CAQ3B"}