@clappr/hlsjs-playback 0.6.0 → 1.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.
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@clappr/core'), require('hls.js')) :
3
3
  typeof define === 'function' && define.amd ? define(['@clappr/core', 'hls.js'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HlsjsPlayback = factory(global.Clappr, global.Hls));
5
- }(this, (function (core, HLSJS) { 'use strict';
5
+ })(this, (function (core, HLSJS) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
@@ -10,65 +10,49 @@
10
10
 
11
11
  function ownKeys(object, enumerableOnly) {
12
12
  var keys = Object.keys(object);
13
-
14
13
  if (Object.getOwnPropertySymbols) {
15
14
  var symbols = Object.getOwnPropertySymbols(object);
16
-
17
- if (enumerableOnly) {
18
- symbols = symbols.filter(function (sym) {
19
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
20
- });
21
- }
22
-
23
- keys.push.apply(keys, symbols);
15
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
16
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
17
+ })), keys.push.apply(keys, symbols);
24
18
  }
25
-
26
19
  return keys;
27
20
  }
28
-
29
21
  function _objectSpread2(target) {
30
22
  for (var i = 1; i < arguments.length; i++) {
31
- var source = arguments[i] != null ? arguments[i] : {};
32
-
33
- if (i % 2) {
34
- ownKeys(Object(source), true).forEach(function (key) {
35
- _defineProperty(target, key, source[key]);
36
- });
37
- } else if (Object.getOwnPropertyDescriptors) {
38
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
39
- } else {
40
- ownKeys(Object(source)).forEach(function (key) {
41
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
42
- });
43
- }
23
+ var source = null != arguments[i] ? arguments[i] : {};
24
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
25
+ _defineProperty(target, key, source[key]);
26
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
27
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
28
+ });
44
29
  }
45
-
46
30
  return target;
47
31
  }
48
-
49
32
  function _classCallCheck(instance, Constructor) {
50
33
  if (!(instance instanceof Constructor)) {
51
34
  throw new TypeError("Cannot call a class as a function");
52
35
  }
53
36
  }
54
-
55
37
  function _defineProperties(target, props) {
56
38
  for (var i = 0; i < props.length; i++) {
57
39
  var descriptor = props[i];
58
40
  descriptor.enumerable = descriptor.enumerable || false;
59
41
  descriptor.configurable = true;
60
42
  if ("value" in descriptor) descriptor.writable = true;
61
- Object.defineProperty(target, descriptor.key, descriptor);
43
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
62
44
  }
63
45
  }
64
-
65
46
  function _createClass(Constructor, protoProps, staticProps) {
66
47
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
67
48
  if (staticProps) _defineProperties(Constructor, staticProps);
49
+ Object.defineProperty(Constructor, "prototype", {
50
+ writable: false
51
+ });
68
52
  return Constructor;
69
53
  }
70
-
71
54
  function _defineProperty(obj, key, value) {
55
+ key = _toPropertyKey(key);
72
56
  if (key in obj) {
73
57
  Object.defineProperty(obj, key, {
74
58
  value: value,
@@ -79,15 +63,12 @@
79
63
  } else {
80
64
  obj[key] = value;
81
65
  }
82
-
83
66
  return obj;
84
67
  }
85
-
86
68
  function _inherits(subClass, superClass) {
87
69
  if (typeof superClass !== "function" && superClass !== null) {
88
70
  throw new TypeError("Super expression must either be null or a function");
89
71
  }
90
-
91
72
  subClass.prototype = Object.create(superClass && superClass.prototype, {
92
73
  constructor: {
93
74
  value: subClass,
@@ -95,30 +76,28 @@
95
76
  configurable: true
96
77
  }
97
78
  });
79
+ Object.defineProperty(subClass, "prototype", {
80
+ writable: false
81
+ });
98
82
  if (superClass) _setPrototypeOf(subClass, superClass);
99
83
  }
100
-
101
84
  function _getPrototypeOf(o) {
102
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
85
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
103
86
  return o.__proto__ || Object.getPrototypeOf(o);
104
87
  };
105
88
  return _getPrototypeOf(o);
106
89
  }
107
-
108
90
  function _setPrototypeOf(o, p) {
109
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
91
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
110
92
  o.__proto__ = p;
111
93
  return o;
112
94
  };
113
-
114
95
  return _setPrototypeOf(o, p);
115
96
  }
116
-
117
97
  function _isNativeReflectConstruct() {
118
98
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
119
99
  if (Reflect.construct.sham) return false;
120
100
  if (typeof Proxy === "function") return true;
121
-
122
101
  try {
123
102
  Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
124
103
  return true;
@@ -126,84 +105,66 @@
126
105
  return false;
127
106
  }
128
107
  }
129
-
130
108
  function _assertThisInitialized(self) {
131
109
  if (self === void 0) {
132
110
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
133
111
  }
134
-
135
112
  return self;
136
113
  }
137
-
138
114
  function _possibleConstructorReturn(self, call) {
139
115
  if (call && (typeof call === "object" || typeof call === "function")) {
140
116
  return call;
117
+ } else if (call !== void 0) {
118
+ throw new TypeError("Derived constructors may only return object or undefined");
141
119
  }
142
-
143
120
  return _assertThisInitialized(self);
144
121
  }
145
-
146
122
  function _createSuper(Derived) {
147
123
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
148
-
149
124
  return function _createSuperInternal() {
150
125
  var Super = _getPrototypeOf(Derived),
151
- result;
152
-
126
+ result;
153
127
  if (hasNativeReflectConstruct) {
154
128
  var NewTarget = _getPrototypeOf(this).constructor;
155
-
156
129
  result = Reflect.construct(Super, arguments, NewTarget);
157
130
  } else {
158
131
  result = Super.apply(this, arguments);
159
132
  }
160
-
161
133
  return _possibleConstructorReturn(this, result);
162
134
  };
163
135
  }
164
-
165
136
  function _superPropBase(object, property) {
166
137
  while (!Object.prototype.hasOwnProperty.call(object, property)) {
167
138
  object = _getPrototypeOf(object);
168
139
  if (object === null) break;
169
140
  }
170
-
171
141
  return object;
172
142
  }
173
-
174
- function _get(target, property, receiver) {
143
+ function _get() {
175
144
  if (typeof Reflect !== "undefined" && Reflect.get) {
176
- _get = Reflect.get;
145
+ _get = Reflect.get.bind();
177
146
  } else {
178
147
  _get = function _get(target, property, receiver) {
179
148
  var base = _superPropBase(target, property);
180
-
181
149
  if (!base) return;
182
150
  var desc = Object.getOwnPropertyDescriptor(base, property);
183
-
184
151
  if (desc.get) {
185
- return desc.get.call(receiver);
152
+ return desc.get.call(arguments.length < 3 ? target : receiver);
186
153
  }
187
-
188
154
  return desc.value;
189
155
  };
190
156
  }
191
-
192
- return _get(target, property, receiver || target);
157
+ return _get.apply(this, arguments);
193
158
  }
194
-
195
159
  function _toConsumableArray(arr) {
196
160
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
197
161
  }
198
-
199
162
  function _arrayWithoutHoles(arr) {
200
163
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
201
164
  }
202
-
203
165
  function _iterableToArray(iter) {
204
166
  if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
205
167
  }
206
-
207
168
  function _unsupportedIterableToArray(o, minLen) {
208
169
  if (!o) return;
209
170
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -212,87 +173,90 @@
212
173
  if (n === "Map" || n === "Set") return Array.from(o);
213
174
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
214
175
  }
215
-
216
176
  function _arrayLikeToArray(arr, len) {
217
177
  if (len == null || len > arr.length) len = arr.length;
218
-
219
178
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
220
-
221
179
  return arr2;
222
180
  }
223
-
224
181
  function _nonIterableSpread() {
225
182
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
226
183
  }
184
+ function _toPrimitive(input, hint) {
185
+ if (typeof input !== "object" || input === null) return input;
186
+ var prim = input[Symbol.toPrimitive];
187
+ if (prim !== undefined) {
188
+ var res = prim.call(input, hint || "default");
189
+ if (typeof res !== "object") return res;
190
+ throw new TypeError("@@toPrimitive must return a primitive value.");
191
+ }
192
+ return (hint === "string" ? String : Number)(input);
193
+ }
194
+ function _toPropertyKey(arg) {
195
+ var key = _toPrimitive(arg, "string");
196
+ return typeof key === "symbol" ? key : String(key);
197
+ }
227
198
 
228
199
  var now = core.Utils.now,
229
- assign = core.Utils.assign,
230
- listContainsIgnoreCase = core.Utils.listContainsIgnoreCase;
200
+ assign = core.Utils.assign,
201
+ listContainsIgnoreCase = core.Utils.listContainsIgnoreCase;
231
202
  var AUTO = -1;
232
203
  core.Events.register('PLAYBACK_FRAGMENT_CHANGED');
233
204
  core.Events.register('PLAYBACK_FRAGMENT_PARSING_METADATA');
234
-
235
205
  var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
236
206
  _inherits(HlsjsPlayback, _HTML5Video);
237
-
238
207
  var _super = _createSuper(HlsjsPlayback);
239
-
240
208
  function HlsjsPlayback() {
241
209
  var _this;
242
-
243
210
  _classCallCheck(this, HlsjsPlayback);
244
-
245
211
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
246
212
  args[_key] = arguments[_key];
247
213
  }
248
-
249
- _this = _super.call.apply(_super, [this].concat(args)); // backwards compatibility (TODO: remove on 0.3.0)
250
-
214
+ _this = _super.call.apply(_super, [this].concat(args));
215
+ // backwards compatibility (TODO: remove on 0.3.0)
251
216
  _this.options.playback = _objectSpread2(_objectSpread2({}, _this.options), _this.options.playback);
252
217
  _this.options.hlsPlayback = _objectSpread2(_objectSpread2({}, _this.defaultOptions), _this.options.hlsPlayback);
253
- _this._minDvrSize = typeof _this.options.hlsMinimumDvrSize === 'undefined' ? 60 : _this.options.hlsMinimumDvrSize; // The size of the start time extrapolation window measured as a multiple of segments.
218
+ _this._minDvrSize = typeof _this.options.hlsMinimumDvrSize === 'undefined' ? 60 : _this.options.hlsMinimumDvrSize;
219
+ // The size of the start time extrapolation window measured as a multiple of segments.
254
220
  // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
255
221
  // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
256
222
  // added/removed every 5.
257
-
258
223
  _this._extrapolatedWindowNumSegments = !_this.options.playback || typeof _this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : _this.options.playback.extrapolatedWindowNumSegments;
259
224
  _this._playbackType = core.Playback.VOD;
260
225
  _this._lastTimeUpdate = {
261
226
  current: 0,
262
227
  total: 0
263
228
  };
264
- _this._lastDuration = null; // for hls streams which have dvr with a sliding window,
229
+ _this._lastDuration = null;
230
+ // for hls streams which have dvr with a sliding window,
265
231
  // the content at the start of the playlist is removed as new
266
232
  // content is appended at the end.
267
233
  // this means the actual playable start time will increase as the
268
234
  // start content is deleted
269
235
  // For streams with dvr where the entire recording is kept from the
270
236
  // beginning this should stay as 0
271
-
272
- _this._playableRegionStartTime = 0; // {local, remote} remote is the time in the video element that should represent 0
237
+ _this._playableRegionStartTime = 0;
238
+ // {local, remote} remote is the time in the video element that should represent 0
273
239
  // local is the system time when the 'remote' measurment took place
274
-
275
- _this._localStartTimeCorrelation = null; // {local, remote} remote is the time in the video element that should represents the end
240
+ _this._localStartTimeCorrelation = null;
241
+ // {local, remote} remote is the time in the video element that should represents the end
276
242
  // local is the system time when the 'remote' measurment took place
277
-
278
- _this._localEndTimeCorrelation = null; // if content is removed from the beginning then this empty area should
243
+ _this._localEndTimeCorrelation = null;
244
+ // if content is removed from the beginning then this empty area should
279
245
  // be ignored. "playableRegionDuration" excludes the empty area
280
-
281
- _this._playableRegionDuration = 0; // #EXT-X-PROGRAM-DATE-TIME
282
-
283
- _this._programDateTime = 0; // true when the actual duration is longer than hlsjs's live sync point
246
+ _this._playableRegionDuration = 0;
247
+ // #EXT-X-PROGRAM-DATE-TIME
248
+ _this._programDateTime = 0;
249
+ // true when the actual duration is longer than hlsjs's live sync point
284
250
  // when this is false playableRegionDuration will be the actual duration
285
251
  // when this is true playableRegionDuration will exclude the time after the sync point
286
-
287
- _this._durationExcludesAfterLiveSyncPoint = false; // #EXT-X-TARGETDURATION
288
-
289
- _this._segmentTargetDuration = null; // #EXT-X-PLAYLIST-TYPE
290
-
252
+ _this._durationExcludesAfterLiveSyncPoint = false;
253
+ // #EXT-X-TARGETDURATION
254
+ _this._segmentTargetDuration = null;
255
+ // #EXT-X-PLAYLIST-TYPE
291
256
  _this._playlistType = null;
292
257
  _this._recoverAttemptsRemaining = _this.options.hlsRecoverAttempts || 16;
293
258
  return _this;
294
259
  }
295
-
296
260
  _createClass(HlsjsPlayback, [{
297
261
  key: "name",
298
262
  get: function get() {
@@ -302,7 +266,7 @@
302
266
  key: "supportedVersion",
303
267
  get: function get() {
304
268
  return {
305
- min: "0.4.18"
269
+ min: "0.4.27"
306
270
  };
307
271
  }
308
272
  }, {
@@ -335,21 +299,23 @@
335
299
  key: "_now",
336
300
  get: function get() {
337
301
  return now();
338
- } // the time in the video element which should represent the start of the sliding window
339
- // extrapolated to increase in real time (instead of jumping as the early segments are removed)
302
+ }
340
303
 
304
+ // the time in the video element which should represent the start of the sliding window
305
+ // extrapolated to increase in real time (instead of jumping as the early segments are removed)
341
306
  }, {
342
307
  key: "_extrapolatedStartTime",
343
308
  get: function get() {
344
309
  if (!this._localStartTimeCorrelation) return this._playableRegionStartTime;
345
310
  var corr = this._localStartTimeCorrelation;
346
311
  var timePassed = this._now - corr.local;
347
- var extrapolatedWindowStartTime = (corr.remote + timePassed) / 1000; // cap at the end of the extrapolated window duration
348
-
312
+ var extrapolatedWindowStartTime = (corr.remote + timePassed) / 1000;
313
+ // cap at the end of the extrapolated window duration
349
314
  return Math.min(extrapolatedWindowStartTime, this._playableRegionStartTime + this._extrapolatedWindowDuration);
350
- } // the time in the video element which should represent the end of the content
351
- // extrapolated to increase in real time (instead of jumping as segments are added)
315
+ }
352
316
 
317
+ // the time in the video element which should represent the end of the content
318
+ // extrapolated to increase in real time (instead of jumping as segments are added)
353
319
  }, {
354
320
  key: "_extrapolatedEndTime",
355
321
  get: function get() {
@@ -364,7 +330,9 @@
364
330
  key: "_duration",
365
331
  get: function get() {
366
332
  return this._extrapolatedEndTime - this._startTime;
367
- } // Returns the duration (seconds) of the window that the extrapolated start time is allowed
333
+ }
334
+
335
+ // Returns the duration (seconds) of the window that the extrapolated start time is allowed
368
336
  // to move in before being capped.
369
337
  // The extrapolated start time should never reach the cap at the end of the window as the
370
338
  // window should slide as chunks are removed from the start.
@@ -381,7 +349,6 @@
381
349
  // . . . --> |
382
350
  // . . . .
383
351
  // extrapolatedStartTime
384
-
385
352
  }, {
386
353
  key: "_extrapolatedWindowDuration",
387
354
  get: function get() {
@@ -409,66 +376,51 @@
409
376
  key: "_setup",
410
377
  value: function _setup() {
411
378
  var _this2 = this;
412
-
413
379
  this._manifestParsed = false;
414
380
  this._ccIsSetup = false;
415
381
  this._ccTracksUpdated = false;
416
382
  this._hls && this._hls.destroy();
417
- this._hls = new HLSJS__default['default'](assign({}, this.options.playback.hlsjsConfig));
418
-
419
- this._hls.once(HLSJS__default['default'].Events.MEDIA_ATTACHED, function () {
383
+ this._hls = new HLSJS__default["default"](assign({}, this.options.playback.hlsjsConfig));
384
+ this._hls.once(HLSJS__default["default"].Events.MEDIA_ATTACHED, function () {
420
385
  _this2.options.hlsPlayback.preload && _this2._hls.loadSource(_this2.options.src);
421
386
  });
422
-
423
- this._hls.on(HLSJS__default['default'].Events.MANIFEST_PARSED, function () {
387
+ this._hls.on(HLSJS__default["default"].Events.MANIFEST_PARSED, function () {
424
388
  return _this2._manifestParsed = true;
425
389
  });
426
-
427
- this._hls.on(HLSJS__default['default'].Events.LEVEL_LOADED, function (evt, data) {
390
+ this._hls.on(HLSJS__default["default"].Events.LEVEL_LOADED, function (evt, data) {
428
391
  return _this2._updatePlaybackType(evt, data);
429
392
  });
430
-
431
- this._hls.on(HLSJS__default['default'].Events.LEVEL_UPDATED, function (evt, data) {
393
+ this._hls.on(HLSJS__default["default"].Events.LEVEL_UPDATED, function (evt, data) {
432
394
  return _this2._onLevelUpdated(evt, data);
433
395
  });
434
-
435
- this._hls.on(HLSJS__default['default'].Events.LEVEL_SWITCHING, function (evt, data) {
396
+ this._hls.on(HLSJS__default["default"].Events.LEVEL_SWITCHING, function (evt, data) {
436
397
  return _this2._onLevelSwitch(evt, data);
437
398
  });
438
-
439
- this._hls.on(HLSJS__default['default'].Events.FRAG_CHANGED, function (evt, data) {
399
+ this._hls.on(HLSJS__default["default"].Events.FRAG_CHANGED, function (evt, data) {
440
400
  return _this2._onFragmentChanged(evt, data);
441
401
  });
442
-
443
- this._hls.on(HLSJS__default['default'].Events.FRAG_LOADED, function (evt, data) {
402
+ this._hls.on(HLSJS__default["default"].Events.FRAG_LOADED, function (evt, data) {
444
403
  return _this2._onFragmentLoaded(evt, data);
445
404
  });
446
-
447
- this._hls.on(HLSJS__default['default'].Events.FRAG_PARSING_METADATA, function (evt, data) {
405
+ this._hls.on(HLSJS__default["default"].Events.FRAG_PARSING_METADATA, function (evt, data) {
448
406
  return _this2._onFragmentParsingMetadata(evt, data);
449
407
  });
450
-
451
- this._hls.on(HLSJS__default['default'].Events.ERROR, function (evt, data) {
408
+ this._hls.on(HLSJS__default["default"].Events.ERROR, function (evt, data) {
452
409
  return _this2._onHLSJSError(evt, data);
453
410
  });
454
-
455
- this._hls.on(HLSJS__default['default'].Events.SUBTITLE_TRACK_LOADED, function (evt, data) {
411
+ this._hls.on(HLSJS__default["default"].Events.SUBTITLE_TRACK_LOADED, function (evt, data) {
456
412
  return _this2._onSubtitleLoaded(evt, data);
457
413
  });
458
-
459
- this._hls.on(HLSJS__default['default'].Events.SUBTITLE_TRACKS_UPDATED, function () {
414
+ this._hls.on(HLSJS__default["default"].Events.SUBTITLE_TRACKS_UPDATED, function () {
460
415
  return _this2._ccTracksUpdated = true;
461
416
  });
462
-
463
417
  this.bindCustomListeners();
464
-
465
418
  this._hls.attachMedia(this.el);
466
419
  }
467
420
  }, {
468
421
  key: "bindCustomListeners",
469
422
  value: function bindCustomListeners() {
470
423
  var _this3 = this;
471
-
472
424
  this.customListeners.forEach(function (item) {
473
425
  var requestedEventName = item.eventName;
474
426
  var typeOfListener = item.once ? 'once' : 'on';
@@ -479,7 +431,6 @@
479
431
  key: "unbindCustomListeners",
480
432
  value: function unbindCustomListeners() {
481
433
  var _this4 = this;
482
-
483
434
  this.customListeners.forEach(function (item) {
484
435
  var requestedEventName = item.eventName;
485
436
  requestedEventName && _this4._hls.off(requestedEventName, item.callback);
@@ -497,7 +448,6 @@
497
448
  key: "render",
498
449
  value: function render() {
499
450
  this._ready();
500
-
501
451
  return _get(_getPrototypeOf(HlsjsPlayback.prototype), "render", this).call(this);
502
452
  }
503
453
  }, {
@@ -513,13 +463,10 @@
513
463
  value: function _recover(evt, data, error) {
514
464
  if (!this._recoveredDecodingError) {
515
465
  this._recoveredDecodingError = true;
516
-
517
466
  this._hls.recoverMediaError();
518
467
  } else if (!this._recoveredAudioCodecError) {
519
468
  this._recoveredAudioCodecError = true;
520
-
521
469
  this._hls.swapAudioCodec();
522
-
523
470
  this._hls.recoverMediaError();
524
471
  } else {
525
472
  core.Log.error('hlsjs: failed to recover', {
@@ -531,8 +478,9 @@
531
478
  this.trigger(core.Events.PLAYBACK_ERROR, formattedError);
532
479
  this.stop();
533
480
  }
534
- } // override
481
+ }
535
482
 
483
+ // override
536
484
  }, {
537
485
  key: "_setupSrc",
538
486
  value: function _setupSrc(srcUrl) {// eslint-disable-line no-unused-vars
@@ -542,11 +490,9 @@
542
490
  key: "_startTimeUpdateTimer",
543
491
  value: function _startTimeUpdateTimer() {
544
492
  var _this5 = this;
545
-
546
493
  if (this._timeUpdateTimer) return;
547
494
  this._timeUpdateTimer = setInterval(function () {
548
495
  _this5._onDurationChange();
549
-
550
496
  _this5._onTimeUpdate();
551
497
  }, 100);
552
498
  }
@@ -561,10 +507,10 @@
561
507
  key: "getProgramDateTime",
562
508
  value: function getProgramDateTime() {
563
509
  return this._programDateTime;
564
- } // the duration on the video element itself should not be used
510
+ }
511
+ // the duration on the video element itself should not be used
565
512
  // as this does not necesarily represent the duration of the stream
566
513
  // https://github.com/clappr/clappr/issues/668#issuecomment-157036678
567
-
568
514
  }, {
569
515
  key: "getDuration",
570
516
  value: function getDuration() {
@@ -577,10 +523,11 @@
577
523
  // eventually they will then be kicked to the end by hlsjs if they run out of buffer
578
524
  // before the official start time
579
525
  return Math.max(0, this.el.currentTime - this._startTime);
580
- } // the time that "0" now represents relative to when playback started
526
+ }
527
+
528
+ // the time that "0" now represents relative to when playback started
581
529
  // for a stream with a sliding window this will increase as content is
582
530
  // removed from the beginning
583
-
584
531
  }, {
585
532
  key: "getStartTimeOffset",
586
533
  value: function getStartTimeOffset() {
@@ -599,9 +546,8 @@
599
546
  if (time < 0) {
600
547
  core.Log.warn('Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.');
601
548
  time = this.getDuration();
602
- } // assume live if time within 3 seconds of end of stream
603
-
604
-
549
+ }
550
+ // assume live if time within 3 seconds of end of stream
605
551
  this.dvrEnabled && this._updateDvr(time < this.getDuration() - 3);
606
552
  time += this._startTime;
607
553
  this.el.currentTime = time;
@@ -635,24 +581,23 @@
635
581
  raw: data
636
582
  };
637
583
  var formattedError;
638
- if (data.response) error.description += ", response: ".concat(JSON.stringify(data.response)); // only report/handle errors if they are fatal
584
+ if (data.response) error.description += ", response: ".concat(JSON.stringify(data.response));
585
+ // only report/handle errors if they are fatal
639
586
  // hlsjs should automatically handle non fatal errors
640
-
641
587
  if (data.fatal) {
642
588
  if (this._recoverAttemptsRemaining > 0) {
643
589
  this._recoverAttemptsRemaining -= 1;
644
-
645
590
  switch (data.type) {
646
- case HLSJS__default['default'].ErrorTypes.NETWORK_ERROR:
591
+ case HLSJS__default["default"].ErrorTypes.NETWORK_ERROR:
647
592
  switch (data.details) {
648
593
  // The following network errors cannot be recovered with HLS.startLoad()
649
594
  // For more details, see https://github.com/video-dev/hls.js/blob/master/doc/design.md#error-detection-and-handling
650
595
  // For "level load" fatal errors, see https://github.com/video-dev/hls.js/issues/1138
651
- case HLSJS__default['default'].ErrorDetails.MANIFEST_LOAD_ERROR:
652
- case HLSJS__default['default'].ErrorDetails.MANIFEST_LOAD_TIMEOUT:
653
- case HLSJS__default['default'].ErrorDetails.MANIFEST_PARSING_ERROR:
654
- case HLSJS__default['default'].ErrorDetails.LEVEL_LOAD_ERROR:
655
- case HLSJS__default['default'].ErrorDetails.LEVEL_LOAD_TIMEOUT:
596
+ case HLSJS__default["default"].ErrorDetails.MANIFEST_LOAD_ERROR:
597
+ case HLSJS__default["default"].ErrorDetails.MANIFEST_LOAD_TIMEOUT:
598
+ case HLSJS__default["default"].ErrorDetails.MANIFEST_PARSING_ERROR:
599
+ case HLSJS__default["default"].ErrorDetails.LEVEL_LOAD_ERROR:
600
+ case HLSJS__default["default"].ErrorDetails.LEVEL_LOAD_TIMEOUT:
656
601
  core.Log.error('hlsjs: unrecoverable network fatal error.', {
657
602
  evt: evt,
658
603
  data: data
@@ -661,32 +606,24 @@
661
606
  this.trigger(core.Events.PLAYBACK_ERROR, formattedError);
662
607
  this.stop();
663
608
  break;
664
-
665
609
  default:
666
610
  core.Log.warn('hlsjs: trying to recover from network error.', {
667
611
  evt: evt,
668
612
  data: data
669
613
  });
670
614
  error.level = core.PlayerError.Levels.WARN;
671
-
672
615
  this._hls.startLoad();
673
-
674
616
  break;
675
617
  }
676
-
677
618
  break;
678
-
679
- case HLSJS__default['default'].ErrorTypes.MEDIA_ERROR:
619
+ case HLSJS__default["default"].ErrorTypes.MEDIA_ERROR:
680
620
  core.Log.warn('hlsjs: trying to recover from media error.', {
681
621
  evt: evt,
682
622
  data: data
683
623
  });
684
624
  error.level = core.PlayerError.Levels.WARN;
685
-
686
625
  this._recover(evt, data, error);
687
-
688
626
  break;
689
-
690
627
  default:
691
628
  core.Log.error('hlsjs: could not recover from error.', {
692
629
  evt: evt,
@@ -721,7 +658,6 @@
721
658
  this.stop();
722
659
  return;
723
660
  }
724
-
725
661
  error.level = core.PlayerError.Levels.WARN;
726
662
  core.Log.warn('hlsjs: non-fatal error occurred', {
727
663
  evt: evt,
@@ -732,7 +668,7 @@
732
668
  }, {
733
669
  key: "_keyIsDenied",
734
670
  value: function _keyIsDenied(data) {
735
- return data.type === HLSJS__default['default'].ErrorTypes.NETWORK_ERROR && data.details === HLSJS__default['default'].ErrorDetails.KEY_LOAD_ERROR && data.response && data.response.code >= 400;
671
+ return data.type === HLSJS__default["default"].ErrorTypes.NETWORK_ERROR && data.details === HLSJS__default["default"].ErrorDetails.KEY_LOAD_ERROR && data.response && data.response.code >= 400;
736
672
  }
737
673
  }, {
738
674
  key: "_onTimeUpdate",
@@ -753,7 +689,6 @@
753
689
  var duration = this.getDuration();
754
690
  if (this._lastDuration === duration) return;
755
691
  this._lastDuration = duration;
756
-
757
692
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "_onDurationChange", this).call(this);
758
693
  }
759
694
  }, {
@@ -762,7 +697,6 @@
762
697
  if (!this.el.buffered.length) return;
763
698
  var buffered = [];
764
699
  var bufferedPos = 0;
765
-
766
700
  for (var i = 0; i < this.el.buffered.length; i++) {
767
701
  buffered = [].concat(_toConsumableArray(buffered), [{
768
702
  // for a stream with sliding window dvr something that is buffered my slide off the start of the timeline
@@ -771,7 +705,6 @@
771
705
  }]);
772
706
  if (this.el.currentTime >= buffered[i].start && this.el.currentTime <= buffered[i].end) bufferedPos = i;
773
707
  }
774
-
775
708
  var progress = {
776
709
  start: buffered[bufferedPos].start,
777
710
  current: buffered[bufferedPos].end,
@@ -784,9 +717,7 @@
784
717
  value: function play() {
785
718
  !this._hls && this._setup();
786
719
  !this._manifestParsed && !this.options.hlsPlayback.preload && this._hls.loadSource(this.options.src);
787
-
788
720
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "play", this).call(this);
789
-
790
721
  this._startTimeUpdateTimer();
791
722
  }
792
723
  }, {
@@ -800,12 +731,9 @@
800
731
  key: "stop",
801
732
  value: function stop() {
802
733
  this._stopTimeUpdateTimer();
803
-
804
734
  if (this._hls) {
805
735
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "stop", this).call(this);
806
-
807
736
  this._hls.destroy();
808
-
809
737
  delete this._hls;
810
738
  }
811
739
  }
@@ -813,23 +741,19 @@
813
741
  key: "destroy",
814
742
  value: function destroy() {
815
743
  this._stopTimeUpdateTimer();
816
-
817
744
  if (this._hls) {
818
745
  this._hls.destroy();
819
-
820
746
  delete this._hls;
821
747
  }
822
-
823
748
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "destroy", this).call(this);
824
749
  }
825
750
  }, {
826
751
  key: "_updatePlaybackType",
827
752
  value: function _updatePlaybackType(evt, data) {
828
753
  this._playbackType = data.details.live ? core.Playback.LIVE : core.Playback.VOD;
754
+ this._onLevelUpdated(evt, data);
829
755
 
830
- this._onLevelUpdated(evt, data); // Live stream subtitle tracks detection hack (may not immediately available)
831
-
832
-
756
+ // Live stream subtitle tracks detection hack (may not immediately available)
833
757
  if (this._ccTracksUpdated && this._playbackType === core.Playback.LIVE && this.hasClosedCaptionsTracks) this._onSubtitleLoaded();
834
758
  }
835
759
  }, {
@@ -854,15 +778,14 @@
854
778
  var fragments = data.details.fragments;
855
779
  var previousPlayableRegionStartTime = this._playableRegionStartTime;
856
780
  var previousPlayableRegionDuration = this._playableRegionDuration;
857
- if (fragments.length === 0) return; // #EXT-X-PROGRAM-DATE-TIME
781
+ if (fragments.length === 0) return;
858
782
 
783
+ // #EXT-X-PROGRAM-DATE-TIME
859
784
  if (fragments[0].rawProgramDateTime) this._programDateTime = fragments[0].rawProgramDateTime;
860
-
861
785
  if (this._playableRegionStartTime !== fragments[0].start) {
862
786
  startTimeChanged = true;
863
787
  this._playableRegionStartTime = fragments[0].start;
864
788
  }
865
-
866
789
  if (startTimeChanged) {
867
790
  if (!this._localStartTimeCorrelation) {
868
791
  // set the correlation to map to middle of the extrapolation window
@@ -873,10 +796,9 @@
873
796
  } else {
874
797
  // check if the correlation still works
875
798
  var corr = this._localStartTimeCorrelation;
876
- var timePassed = this._now - corr.local; // this should point to a time within the extrapolation window
877
-
799
+ var timePassed = this._now - corr.local;
800
+ // this should point to a time within the extrapolation window
878
801
  var startTime = (corr.remote + timePassed) / 1000;
879
-
880
802
  if (startTime < fragments[0].start) {
881
803
  // our start time is now earlier than the first chunk
882
804
  // (maybe the chunk was removed early)
@@ -897,17 +819,15 @@
897
819
  }
898
820
  }
899
821
  }
900
-
901
- var newDuration = data.details.totalduration; // if it's a live stream then shorten the duration to remove access
822
+ var newDuration = data.details.totalduration;
823
+ // if it's a live stream then shorten the duration to remove access
902
824
  // to the area after hlsjs's live sync point
903
825
  // seeks to areas after this point sometimes have issues
904
-
905
826
  if (this._playbackType === core.Playback.LIVE) {
906
827
  var fragmentTargetDuration = data.details.targetduration;
907
828
  var hlsjsConfig = this.options.playback.hlsjsConfig || {};
908
- var liveSyncDurationCount = hlsjsConfig.liveSyncDurationCount || HLSJS__default['default'].DefaultConfig.liveSyncDurationCount;
829
+ var liveSyncDurationCount = hlsjsConfig.liveSyncDurationCount || HLSJS__default["default"].DefaultConfig.liveSyncDurationCount;
909
830
  var hiddenAreaDuration = fragmentTargetDuration * liveSyncDurationCount;
910
-
911
831
  if (hiddenAreaDuration <= newDuration) {
912
832
  newDuration -= hiddenAreaDuration;
913
833
  this._durationExcludesAfterLiveSyncPoint = true;
@@ -915,18 +835,16 @@
915
835
  this._durationExcludesAfterLiveSyncPoint = false;
916
836
  }
917
837
  }
918
-
919
838
  if (newDuration !== this._playableRegionDuration) {
920
839
  durationChanged = true;
921
840
  this._playableRegionDuration = newDuration;
922
- } // Note the end time is not the playableRegionDuration
923
- // The end time will always increase even if content is removed from the beginning
924
-
841
+ }
925
842
 
843
+ // Note the end time is not the playableRegionDuration
844
+ // The end time will always increase even if content is removed from the beginning
926
845
  var endTime = fragments[0].start + newDuration;
927
846
  var previousEndTime = previousPlayableRegionStartTime + previousPlayableRegionDuration;
928
847
  var endTimeChanged = endTime !== previousEndTime;
929
-
930
848
  if (endTimeChanged) {
931
849
  if (!this._localEndTimeCorrelation) {
932
850
  // set the correlation to map to the end
@@ -937,12 +855,9 @@
937
855
  } else {
938
856
  // check if the correlation still works
939
857
  var _corr = this._localEndTimeCorrelation;
940
-
941
- var _timePassed = this._now - _corr.local; // this should point to a time within the extrapolation window from the end
942
-
943
-
858
+ var _timePassed = this._now - _corr.local;
859
+ // this should point to a time within the extrapolation window from the end
944
860
  var extrapolatedEndTime = (_corr.remote + _timePassed) / 1000;
945
-
946
861
  if (extrapolatedEndTime > endTime) {
947
862
  this._localEndTimeCorrelation = {
948
863
  local: this._now,
@@ -965,10 +880,10 @@
965
880
  };
966
881
  }
967
882
  }
968
- } // now that the values have been updated call any methods that use on them so they get the updated values
969
- // immediately
970
-
883
+ }
971
884
 
885
+ // now that the values have been updated call any methods that use on them so they get the updated values
886
+ // immediately
972
887
  durationChanged && this._onDurationChange();
973
888
  startTimeChanged && this._onProgress();
974
889
  }
@@ -1001,7 +916,6 @@
1001
916
  this.trigger(core.Events.PLAYBACK_LEVEL_SWITCH_END);
1002
917
  this.trigger(core.Events.PLAYBACK_LEVEL_SWITCH, data);
1003
918
  var currentLevel = this._hls.levels[data.level];
1004
-
1005
919
  if (currentLevel) {
1006
920
  // TODO should highDefinition be private and maybe have a read only accessor if it's used somewhere
1007
921
  this.highDefinition = currentLevel.height >= 720 || currentLevel.bitrate / 1000 >= 2000;
@@ -1037,19 +951,17 @@
1037
951
  }], [{
1038
952
  key: "HLSJS",
1039
953
  get: function get() {
1040
- return HLSJS__default['default'];
954
+ return HLSJS__default["default"];
1041
955
  }
1042
956
  }]);
1043
-
1044
957
  return HlsjsPlayback;
1045
958
  }(core.HTML5Video);
1046
-
1047
959
  HlsjsPlayback.canPlay = function (resource, mimeType) {
1048
960
  var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || [];
1049
961
  var isHls = resourceParts.length > 1 && resourceParts[1].toLowerCase() === 'm3u8' || listContainsIgnoreCase(mimeType, ['application/vnd.apple.mpegurl', 'application/x-mpegURL']);
1050
- return !!(HLSJS__default['default'].isSupported() && isHls);
962
+ return !!(HLSJS__default["default"].isSupported() && isHls);
1051
963
  };
1052
964
 
1053
965
  return HlsjsPlayback;
1054
966
 
1055
- })));
967
+ }));