@clappr/hlsjs-playback 1.2.0 → 1.4.0

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,73 +2,57 @@
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
 
9
9
  var HLSJS__default = /*#__PURE__*/_interopDefaultLegacy(HLSJS);
10
10
 
11
- function ownKeys(object, enumerableOnly) {
12
- var keys = Object.keys(object);
13
-
11
+ function ownKeys(e, r) {
12
+ var t = Object.keys(e);
14
13
  if (Object.getOwnPropertySymbols) {
15
- 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);
14
+ var o = Object.getOwnPropertySymbols(e);
15
+ r && (o = o.filter(function (r) {
16
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
17
+ })), t.push.apply(t, o);
24
18
  }
25
-
26
- return keys;
19
+ return t;
27
20
  }
28
-
29
- function _objectSpread2(target) {
30
- 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
- }
21
+ function _objectSpread2(e) {
22
+ for (var r = 1; r < arguments.length; r++) {
23
+ var t = null != arguments[r] ? arguments[r] : {};
24
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
25
+ _defineProperty(e, r, t[r]);
26
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
27
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
28
+ });
44
29
  }
45
-
46
- return target;
30
+ return e;
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,48 +173,49 @@
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
- listContainsIgnoreCase = core.Utils.listContainsIgnoreCase;
200
+ listContainsIgnoreCase = core.Utils.listContainsIgnoreCase;
230
201
  var AUTO = -1;
231
202
  var DEFAULT_RECOVER_ATTEMPTS = 16;
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
214
  _this = _super.call.apply(_super, [this].concat(args));
250
215
  _this.options.hlsPlayback = _objectSpread2(_objectSpread2({}, _this.defaultOptions), _this.options.hlsPlayback);
251
-
252
216
  _this._setInitialState();
253
-
254
217
  return _this;
255
218
  }
256
-
257
219
  _createClass(HlsjsPlayback, [{
258
220
  key: "name",
259
221
  get: function get() {
@@ -263,7 +225,7 @@
263
225
  key: "supportedVersion",
264
226
  get: function get() {
265
227
  return {
266
- min: "0.4.18"
228
+ min: "0.8.0"
267
229
  };
268
230
  }
269
231
  }, {
@@ -306,21 +268,23 @@
306
268
  key: "_now",
307
269
  get: function get() {
308
270
  return now();
309
- } // the time in the video element which should represent the start of the sliding window
310
- // extrapolated to increase in real time (instead of jumping as the early segments are removed)
271
+ }
311
272
 
273
+ // the time in the video element which should represent the start of the sliding window
274
+ // extrapolated to increase in real time (instead of jumping as the early segments are removed)
312
275
  }, {
313
276
  key: "_extrapolatedStartTime",
314
277
  get: function get() {
315
278
  if (!this._localStartTimeCorrelation) return this._playableRegionStartTime;
316
279
  var corr = this._localStartTimeCorrelation;
317
280
  var timePassed = this._now - corr.local;
318
- var extrapolatedWindowStartTime = (corr.remote + timePassed) / 1000; // cap at the end of the extrapolated window duration
319
-
281
+ var extrapolatedWindowStartTime = (corr.remote + timePassed) / 1000;
282
+ // cap at the end of the extrapolated window duration
320
283
  return Math.min(extrapolatedWindowStartTime, this._playableRegionStartTime + this._extrapolatedWindowDuration);
321
- } // the time in the video element which should represent the end of the content
322
- // extrapolated to increase in real time (instead of jumping as segments are added)
284
+ }
323
285
 
286
+ // the time in the video element which should represent the end of the content
287
+ // extrapolated to increase in real time (instead of jumping as segments are added)
324
288
  }, {
325
289
  key: "_extrapolatedEndTime",
326
290
  get: function get() {
@@ -335,7 +299,9 @@
335
299
  key: "_duration",
336
300
  get: function get() {
337
301
  return this._extrapolatedEndTime - this._startTime;
338
- } // Returns the duration (seconds) of the window that the extrapolated start time is allowed
302
+ }
303
+
304
+ // Returns the duration (seconds) of the window that the extrapolated start time is allowed
339
305
  // to move in before being capped.
340
306
  // The extrapolated start time should never reach the cap at the end of the window as the
341
307
  // window should slide as chunks are removed from the start.
@@ -352,7 +318,6 @@
352
318
  // . . . --> |
353
319
  // . . . .
354
320
  // extrapolatedStartTime
355
-
356
321
  }, {
357
322
  key: "_extrapolatedWindowDuration",
358
323
  get: function get() {
@@ -381,47 +346,57 @@
381
346
  get: function get() {
382
347
  return this.options.src;
383
348
  }
349
+ }, {
350
+ key: "currentTimestamp",
351
+ get: function get() {
352
+ if (!this._currentFragment) return null;
353
+ var startTime = this._currentFragment.programDateTime;
354
+ var playbackTime = this.el.currentTime;
355
+ var playTimeOffSet = playbackTime - this._currentFragment.start;
356
+ var currentTimestampInMs = startTime + playTimeOffSet * 1000;
357
+ return currentTimestampInMs / 1000;
358
+ }
384
359
  }, {
385
360
  key: "_setInitialState",
386
361
  value: function _setInitialState() {
387
- 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.
362
+ this._minDvrSize = typeof this.options.hlsMinimumDvrSize === 'undefined' ? 60 : this.options.hlsMinimumDvrSize;
363
+ // The size of the start time extrapolation window measured as a multiple of segments.
388
364
  // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
389
365
  // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
390
366
  // added/removed every 5.
391
-
392
367
  this._extrapolatedWindowNumSegments = !this.options.playback || typeof this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : this.options.playback.extrapolatedWindowNumSegments;
393
368
  this._playbackType = core.Playback.VOD;
394
369
  this._lastTimeUpdate = {
395
370
  current: 0,
396
371
  total: 0
397
372
  };
398
- this._lastDuration = null; // for hls streams which have dvr with a sliding window,
373
+ this._lastDuration = null;
374
+ // for hls streams which have dvr with a sliding window,
399
375
  // the content at the start of the playlist is removed as new
400
376
  // content is appended at the end.
401
377
  // this means the actual playable start time will increase as the
402
378
  // start content is deleted
403
379
  // For streams with dvr where the entire recording is kept from the
404
380
  // beginning this should stay as 0
405
-
406
- this._playableRegionStartTime = 0; // {local, remote} remote is the time in the video element that should represent 0
381
+ this._playableRegionStartTime = 0;
382
+ // {local, remote} remote is the time in the video element that should represent 0
407
383
  // local is the system time when the 'remote' measurment took place
408
-
409
- this._localStartTimeCorrelation = null; // {local, remote} remote is the time in the video element that should represents the end
384
+ this._localStartTimeCorrelation = null;
385
+ // {local, remote} remote is the time in the video element that should represents the end
410
386
  // local is the system time when the 'remote' measurment took place
411
-
412
- this._localEndTimeCorrelation = null; // if content is removed from the beginning then this empty area should
387
+ this._localEndTimeCorrelation = null;
388
+ // if content is removed from the beginning then this empty area should
413
389
  // be ignored. "playableRegionDuration" excludes the empty area
414
-
415
- this._playableRegionDuration = 0; // #EXT-X-PROGRAM-DATE-TIME
416
-
417
- this._programDateTime = 0; // true when the actual duration is longer than hlsjs's live sync point
390
+ this._playableRegionDuration = 0;
391
+ // #EXT-X-PROGRAM-DATE-TIME
392
+ this._programDateTime = 0;
393
+ // true when the actual duration is longer than hlsjs's live sync point
418
394
  // when this is false playableRegionDuration will be the actual duration
419
395
  // when this is true playableRegionDuration will exclude the time after the sync point
420
-
421
- this._durationExcludesAfterLiveSyncPoint = false; // #EXT-X-TARGETDURATION
422
-
423
- this._segmentTargetDuration = null; // #EXT-X-PLAYLIST-TYPE
424
-
396
+ this._durationExcludesAfterLiveSyncPoint = false;
397
+ // #EXT-X-TARGETDURATION
398
+ this._segmentTargetDuration = null;
399
+ // #EXT-X-PLAYLIST-TYPE
425
400
  this._playlistType = null;
426
401
  this._recoverAttemptsRemaining = this.options.hlsRecoverAttempts || DEFAULT_RECOVER_ATTEMPTS;
427
402
  }
@@ -429,99 +404,77 @@
429
404
  key: "_setup",
430
405
  value: function _setup() {
431
406
  this._destroyHLSInstance();
432
-
433
407
  this._createHLSInstance();
434
-
435
408
  this._listenHLSEvents();
436
-
437
409
  this._attachHLSMedia();
438
410
  }
439
411
  }, {
440
412
  key: "_destroyHLSInstance",
441
413
  value: function _destroyHLSInstance() {
442
414
  if (!this._hls) return;
443
- this._manifestParsed = false;
415
+ this._manifestLoading = false;
444
416
  this._ccIsSetup = false;
445
417
  this._ccTracksUpdated = false;
446
-
447
418
  this._setInitialState();
448
-
449
419
  this._hls.destroy();
450
-
451
420
  this._hls = null;
452
421
  }
453
422
  }, {
454
423
  key: "_createHLSInstance",
455
424
  value: function _createHLSInstance() {
456
425
  var config = _objectSpread2({}, this.options.playback.hlsjsConfig);
457
-
458
- this._hls = new HLSJS__default['default'](config);
426
+ this._hls = new HLSJS__default["default"](config);
459
427
  }
460
428
  }, {
461
429
  key: "_attachHLSMedia",
462
430
  value: function _attachHLSMedia() {
463
431
  if (!this._hls) return;
464
-
465
432
  this._hls.attachMedia(this.el);
466
433
  }
467
434
  }, {
468
435
  key: "_listenHLSEvents",
469
436
  value: function _listenHLSEvents() {
470
437
  var _this2 = this;
471
-
472
438
  if (!this._hls) return;
473
-
474
- this._hls.once(HLSJS__default['default'].Events.MEDIA_ATTACHED, function () {
439
+ this._hls.once(HLSJS__default["default"].Events.MEDIA_ATTACHED, function () {
475
440
  _this2.options.hlsPlayback.preload && _this2._hls.loadSource(_this2.options.src);
476
441
  });
477
-
478
- this._hls.on(HLSJS__default['default'].Events.MANIFEST_PARSED, function () {
479
- return _this2._manifestParsed = true;
442
+ this._hls.on(HLSJS__default["default"].Events.MANIFEST_LOADING, function () {
443
+ return _this2._manifestLoading = true;
480
444
  });
481
-
482
- this._hls.on(HLSJS__default['default'].Events.LEVEL_LOADED, function (evt, data) {
445
+ this._hls.on(HLSJS__default["default"].Events.LEVEL_LOADED, function (evt, data) {
483
446
  return _this2._updatePlaybackType(evt, data);
484
447
  });
485
-
486
- this._hls.on(HLSJS__default['default'].Events.LEVEL_UPDATED, function (evt, data) {
448
+ this._hls.on(HLSJS__default["default"].Events.LEVEL_UPDATED, function (evt, data) {
487
449
  return _this2._onLevelUpdated(evt, data);
488
450
  });
489
-
490
- this._hls.on(HLSJS__default['default'].Events.LEVEL_SWITCHING, function (evt, data) {
451
+ this._hls.on(HLSJS__default["default"].Events.LEVEL_SWITCHING, function (evt, data) {
491
452
  return _this2._onLevelSwitch(evt, data);
492
453
  });
493
-
494
- this._hls.on(HLSJS__default['default'].Events.FRAG_CHANGED, function (evt, data) {
454
+ this._hls.on(HLSJS__default["default"].Events.FRAG_CHANGED, function (evt, data) {
495
455
  return _this2._onFragmentChanged(evt, data);
496
456
  });
497
-
498
- this._hls.on(HLSJS__default['default'].Events.FRAG_LOADED, function (evt, data) {
457
+ this._hls.on(HLSJS__default["default"].Events.FRAG_LOADED, function (evt, data) {
499
458
  return _this2._onFragmentLoaded(evt, data);
500
459
  });
501
-
502
- this._hls.on(HLSJS__default['default'].Events.FRAG_PARSING_METADATA, function (evt, data) {
460
+ this._hls.on(HLSJS__default["default"].Events.FRAG_PARSING_METADATA, function (evt, data) {
503
461
  return _this2._onFragmentParsingMetadata(evt, data);
504
462
  });
505
-
506
- this._hls.on(HLSJS__default['default'].Events.ERROR, function (evt, data) {
463
+ this._hls.on(HLSJS__default["default"].Events.ERROR, function (evt, data) {
507
464
  return _this2._onHLSJSError(evt, data);
508
465
  });
509
-
510
- this._hls.on(HLSJS__default['default'].Events.SUBTITLE_TRACK_LOADED, function (evt, data) {
466
+ this._hls.on(HLSJS__default["default"].Events.SUBTITLE_TRACK_LOADED, function (evt, data) {
511
467
  return _this2._onSubtitleLoaded(evt, data);
512
468
  });
513
-
514
- this._hls.on(HLSJS__default['default'].Events.SUBTITLE_TRACKS_UPDATED, function () {
469
+ this._hls.on(HLSJS__default["default"].Events.SUBTITLE_TRACKS_UPDATED, function () {
515
470
  return _this2._ccTracksUpdated = true;
516
471
  });
517
-
518
472
  this.bindCustomListeners();
519
473
  }
520
474
  }, {
521
475
  key: "bindCustomListeners",
522
476
  value: function bindCustomListeners() {
523
477
  var _this3 = this;
524
-
525
478
  this.customListeners.forEach(function (item) {
526
479
  var requestedEventName = item.eventName;
527
480
  var typeOfListener = item.once ? 'once' : 'on';
@@ -532,7 +485,6 @@
532
485
  key: "unbindCustomListeners",
533
486
  value: function unbindCustomListeners() {
534
487
  var _this4 = this;
535
-
536
488
  this.customListeners.forEach(function (item) {
537
489
  var requestedEventName = item.eventName;
538
490
  requestedEventName && _this4._hls.off(requestedEventName, item.callback);
@@ -550,7 +502,6 @@
550
502
  key: "render",
551
503
  value: function render() {
552
504
  this._ready();
553
-
554
505
  return _get(_getPrototypeOf(HlsjsPlayback.prototype), "render", this).call(this);
555
506
  }
556
507
  }, {
@@ -566,13 +517,10 @@
566
517
  value: function _recover(evt, data, error) {
567
518
  if (!this._recoveredDecodingError) {
568
519
  this._recoveredDecodingError = true;
569
-
570
520
  this._hls.recoverMediaError();
571
521
  } else if (!this._recoveredAudioCodecError) {
572
522
  this._recoveredAudioCodecError = true;
573
-
574
523
  this._hls.swapAudioCodec();
575
-
576
524
  this._hls.recoverMediaError();
577
525
  } else {
578
526
  core.Log.error('hlsjs: failed to recover', {
@@ -584,22 +532,20 @@
584
532
  this.trigger(core.Events.PLAYBACK_ERROR, formattedError);
585
533
  this.stop();
586
534
  }
587
- } // override
588
- // this playback manages the src on the video element itself
535
+ }
589
536
 
537
+ // override
538
+ // this playback manages the src on the video element itself
590
539
  }, {
591
540
  key: "_setupSrc",
592
541
  value: function _setupSrc(srcUrl) {} // eslint-disable-line no-unused-vars
593
-
594
542
  }, {
595
543
  key: "_startTimeUpdateTimer",
596
544
  value: function _startTimeUpdateTimer() {
597
545
  var _this5 = this;
598
-
599
546
  if (this._timeUpdateTimer) return;
600
547
  this._timeUpdateTimer = setInterval(function () {
601
548
  _this5._onDurationChange();
602
-
603
549
  _this5._onTimeUpdate();
604
550
  }, 100);
605
551
  }
@@ -614,10 +560,11 @@
614
560
  key: "getProgramDateTime",
615
561
  value: function getProgramDateTime() {
616
562
  return this._programDateTime;
617
- } // the duration on the video element itself should not be used
563
+ }
564
+
565
+ // the duration on the video element itself should not be used
618
566
  // as this does not necesarily represent the duration of the stream
619
567
  // https://github.com/clappr/clappr/issues/668#issuecomment-157036678
620
-
621
568
  }, {
622
569
  key: "getDuration",
623
570
  value: function getDuration() {
@@ -630,10 +577,11 @@
630
577
  // eventually they will then be kicked to the end by hlsjs if they run out of buffer
631
578
  // before the official start time
632
579
  return Math.max(0, this.el.currentTime - this._startTime);
633
- } // the time that "0" now represents relative to when playback started
580
+ }
581
+
582
+ // the time that "0" now represents relative to when playback started
634
583
  // for a stream with a sliding window this will increase as content is
635
584
  // removed from the beginning
636
-
637
585
  }, {
638
586
  key: "getStartTimeOffset",
639
587
  value: function getStartTimeOffset() {
@@ -651,9 +599,8 @@
651
599
  if (time < 0) {
652
600
  core.Log.warn('Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.');
653
601
  time = this.getDuration();
654
- } // assume live if time within 3 seconds of end of stream
655
-
656
-
602
+ }
603
+ // assume live if time within 3 seconds of end of stream
657
604
  this.dvrEnabled && this._updateDvr(time < this.getDuration() - 3);
658
605
  time += this._startTime;
659
606
  this.el.currentTime = time;
@@ -687,24 +634,23 @@
687
634
  raw: data
688
635
  };
689
636
  var formattedError;
690
- if (data.response) error.description += ", response: ".concat(JSON.stringify(data.response)); // only report/handle errors if they are fatal
637
+ if (data.response) error.description += ", response: ".concat(JSON.stringify(data.response));
638
+ // only report/handle errors if they are fatal
691
639
  // hlsjs should automatically handle non fatal errors
692
-
693
640
  if (data.fatal) {
694
641
  if (this._recoverAttemptsRemaining > 0) {
695
642
  this._recoverAttemptsRemaining -= 1;
696
-
697
643
  switch (data.type) {
698
- case HLSJS__default['default'].ErrorTypes.NETWORK_ERROR:
644
+ case HLSJS__default["default"].ErrorTypes.NETWORK_ERROR:
699
645
  switch (data.details) {
700
646
  // The following network errors cannot be recovered with HLS.startLoad()
701
647
  // For more details, see https://github.com/video-dev/hls.js/blob/master/doc/design.md#error-detection-and-handling
702
648
  // For "level load" fatal errors, see https://github.com/video-dev/hls.js/issues/1138
703
- case HLSJS__default['default'].ErrorDetails.MANIFEST_LOAD_ERROR:
704
- case HLSJS__default['default'].ErrorDetails.MANIFEST_LOAD_TIMEOUT:
705
- case HLSJS__default['default'].ErrorDetails.MANIFEST_PARSING_ERROR:
706
- case HLSJS__default['default'].ErrorDetails.LEVEL_LOAD_ERROR:
707
- case HLSJS__default['default'].ErrorDetails.LEVEL_LOAD_TIMEOUT:
649
+ case HLSJS__default["default"].ErrorDetails.MANIFEST_LOAD_ERROR:
650
+ case HLSJS__default["default"].ErrorDetails.MANIFEST_LOAD_TIMEOUT:
651
+ case HLSJS__default["default"].ErrorDetails.MANIFEST_PARSING_ERROR:
652
+ case HLSJS__default["default"].ErrorDetails.LEVEL_LOAD_ERROR:
653
+ case HLSJS__default["default"].ErrorDetails.LEVEL_LOAD_TIMEOUT:
708
654
  core.Log.error('hlsjs: unrecoverable network fatal error.', {
709
655
  evt: evt,
710
656
  data: data
@@ -713,32 +659,24 @@
713
659
  this.trigger(core.Events.PLAYBACK_ERROR, formattedError);
714
660
  this.stop();
715
661
  break;
716
-
717
662
  default:
718
663
  core.Log.warn('hlsjs: trying to recover from network error.', {
719
664
  evt: evt,
720
665
  data: data
721
666
  });
722
667
  error.level = core.PlayerError.Levels.WARN;
723
-
724
668
  this._hls.startLoad();
725
-
726
669
  break;
727
670
  }
728
-
729
671
  break;
730
-
731
- case HLSJS__default['default'].ErrorTypes.MEDIA_ERROR:
672
+ case HLSJS__default["default"].ErrorTypes.MEDIA_ERROR:
732
673
  core.Log.warn('hlsjs: trying to recover from media error.', {
733
674
  evt: evt,
734
675
  data: data
735
676
  });
736
677
  error.level = core.PlayerError.Levels.WARN;
737
-
738
678
  this._recover(evt, data, error);
739
-
740
679
  break;
741
-
742
680
  default:
743
681
  core.Log.error('hlsjs: could not recover from error.', {
744
682
  evt: evt,
@@ -773,7 +711,6 @@
773
711
  this.stop();
774
712
  return;
775
713
  }
776
-
777
714
  error.level = core.PlayerError.Levels.WARN;
778
715
  core.Log.warn('hlsjs: non-fatal error occurred', {
779
716
  evt: evt,
@@ -784,7 +721,7 @@
784
721
  }, {
785
722
  key: "_keyIsDenied",
786
723
  value: function _keyIsDenied(data) {
787
- return data.type === HLSJS__default['default'].ErrorTypes.NETWORK_ERROR && data.details === HLSJS__default['default'].ErrorDetails.KEY_LOAD_ERROR && data.response && data.response.code >= 400;
724
+ return data.type === HLSJS__default["default"].ErrorTypes.NETWORK_ERROR && data.details === HLSJS__default["default"].ErrorDetails.KEY_LOAD_ERROR && data.response && data.response.code >= 400;
788
725
  }
789
726
  }, {
790
727
  key: "_onTimeUpdate",
@@ -805,7 +742,6 @@
805
742
  var duration = this.getDuration();
806
743
  if (this._lastDuration === duration) return;
807
744
  this._lastDuration = duration;
808
-
809
745
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "_onDurationChange", this).call(this);
810
746
  }
811
747
  }, {
@@ -814,7 +750,6 @@
814
750
  if (!this.el.buffered.length) return;
815
751
  var buffered = [];
816
752
  var bufferedPos = 0;
817
-
818
753
  for (var i = 0; i < this.el.buffered.length; i++) {
819
754
  buffered = [].concat(_toConsumableArray(buffered), [{
820
755
  // for a stream with sliding window dvr something that is buffered my slide off the start of the timeline
@@ -823,7 +758,6 @@
823
758
  }]);
824
759
  if (this.el.currentTime >= buffered[i].start && this.el.currentTime <= buffered[i].end) bufferedPos = i;
825
760
  }
826
-
827
761
  var progress = {
828
762
  start: buffered[bufferedPos].start,
829
763
  current: buffered[bufferedPos].end,
@@ -835,19 +769,15 @@
835
769
  key: "load",
836
770
  value: function load(url) {
837
771
  this._stopTimeUpdateTimer();
838
-
839
772
  this.options.src = url;
840
-
841
773
  this._setup();
842
774
  }
843
775
  }, {
844
776
  key: "play",
845
777
  value: function play() {
846
778
  !this._hls && this._setup();
847
- !this._manifestParsed && !this.options.hlsPlayback.preload && this._hls.loadSource(this.options.src);
848
-
779
+ !this._manifestLoading && !this.options.hlsPlayback.preload && this._hls.loadSource(this.options.src);
849
780
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "play", this).call(this);
850
-
851
781
  this._startTimeUpdateTimer();
852
782
  }
853
783
  }, {
@@ -861,28 +791,22 @@
861
791
  key: "stop",
862
792
  value: function stop() {
863
793
  this._stopTimeUpdateTimer();
864
-
865
794
  if (this._hls) _get(_getPrototypeOf(HlsjsPlayback.prototype), "stop", this).call(this);
866
-
867
795
  this._destroyHLSInstance();
868
796
  }
869
797
  }, {
870
798
  key: "destroy",
871
799
  value: function destroy() {
872
800
  this._stopTimeUpdateTimer();
873
-
874
801
  this._destroyHLSInstance();
875
-
876
802
  _get(_getPrototypeOf(HlsjsPlayback.prototype), "destroy", this).call(this);
877
803
  }
878
804
  }, {
879
805
  key: "_updatePlaybackType",
880
806
  value: function _updatePlaybackType(evt, data) {
881
807
  this._playbackType = data.details.live ? core.Playback.LIVE : core.Playback.VOD;
882
-
883
- this._onLevelUpdated(evt, data); // Live stream subtitle tracks detection hack (may not immediately available)
884
-
885
-
808
+ this._onLevelUpdated(evt, data);
809
+ // Live stream subtitle tracks detection hack (may not immediately available)
886
810
  if (this._ccTracksUpdated && this._playbackType === core.Playback.LIVE && this.hasClosedCaptionsTracks) this._onSubtitleLoaded();
887
811
  }
888
812
  }, {
@@ -907,15 +831,13 @@
907
831
  var fragments = data.details.fragments;
908
832
  var previousPlayableRegionStartTime = this._playableRegionStartTime;
909
833
  var previousPlayableRegionDuration = this._playableRegionDuration;
910
- if (fragments.length === 0) return; // #EXT-X-PROGRAM-DATE-TIME
911
-
834
+ if (fragments.length === 0) return;
835
+ // #EXT-X-PROGRAM-DATE-TIME
912
836
  if (fragments[0].rawProgramDateTime) this._programDateTime = fragments[0].rawProgramDateTime;
913
-
914
837
  if (this._playableRegionStartTime !== fragments[0].start) {
915
838
  startTimeChanged = true;
916
839
  this._playableRegionStartTime = fragments[0].start;
917
840
  }
918
-
919
841
  if (startTimeChanged) {
920
842
  if (!this._localStartTimeCorrelation) {
921
843
  // set the correlation to map to middle of the extrapolation window
@@ -926,10 +848,9 @@
926
848
  } else {
927
849
  // check if the correlation still works
928
850
  var corr = this._localStartTimeCorrelation;
929
- var timePassed = this._now - corr.local; // this should point to a time within the extrapolation window
930
-
851
+ var timePassed = this._now - corr.local;
852
+ // this should point to a time within the extrapolation window
931
853
  var startTime = (corr.remote + timePassed) / 1000;
932
-
933
854
  if (startTime < fragments[0].start) {
934
855
  // our start time is now earlier than the first chunk
935
856
  // (maybe the chunk was removed early)
@@ -950,17 +871,15 @@
950
871
  }
951
872
  }
952
873
  }
953
-
954
- var newDuration = data.details.totalduration; // if it's a live stream then shorten the duration to remove access
874
+ var newDuration = data.details.totalduration;
875
+ // if it's a live stream then shorten the duration to remove access
955
876
  // to the area after hlsjs's live sync point
956
877
  // seeks to areas after this point sometimes have issues
957
-
958
878
  if (this._playbackType === core.Playback.LIVE) {
959
879
  var fragmentTargetDuration = data.details.targetduration;
960
880
  var hlsjsConfig = this.options.playback.hlsjsConfig || {};
961
- var liveSyncDurationCount = hlsjsConfig.liveSyncDurationCount || HLSJS__default['default'].DefaultConfig.liveSyncDurationCount;
881
+ var liveSyncDurationCount = hlsjsConfig.liveSyncDurationCount || HLSJS__default["default"].DefaultConfig.liveSyncDurationCount;
962
882
  var hiddenAreaDuration = fragmentTargetDuration * liveSyncDurationCount;
963
-
964
883
  if (hiddenAreaDuration <= newDuration) {
965
884
  newDuration -= hiddenAreaDuration;
966
885
  this._durationExcludesAfterLiveSyncPoint = true;
@@ -968,18 +887,15 @@
968
887
  this._durationExcludesAfterLiveSyncPoint = false;
969
888
  }
970
889
  }
971
-
972
890
  if (newDuration !== this._playableRegionDuration) {
973
891
  durationChanged = true;
974
892
  this._playableRegionDuration = newDuration;
975
- } // Note the end time is not the playableRegionDuration
893
+ }
894
+ // Note the end time is not the playableRegionDuration
976
895
  // The end time will always increase even if content is removed from the beginning
977
-
978
-
979
896
  var endTime = fragments[0].start + newDuration;
980
897
  var previousEndTime = previousPlayableRegionStartTime + previousPlayableRegionDuration;
981
898
  var endTimeChanged = endTime !== previousEndTime;
982
-
983
899
  if (endTimeChanged) {
984
900
  if (!this._localEndTimeCorrelation) {
985
901
  // set the correlation to map to the end
@@ -990,12 +906,9 @@
990
906
  } else {
991
907
  // check if the correlation still works
992
908
  var _corr = this._localEndTimeCorrelation;
993
-
994
- var _timePassed = this._now - _corr.local; // this should point to a time within the extrapolation window from the end
995
-
996
-
909
+ var _timePassed = this._now - _corr.local;
910
+ // this should point to a time within the extrapolation window from the end
997
911
  var extrapolatedEndTime = (_corr.remote + _timePassed) / 1000;
998
-
999
912
  if (extrapolatedEndTime > endTime) {
1000
913
  this._localEndTimeCorrelation = {
1001
914
  local: this._now,
@@ -1018,16 +931,17 @@
1018
931
  };
1019
932
  }
1020
933
  }
1021
- } // now that the values have been updated call any methods that use on them so they get the updated values
1022
- // immediately
1023
-
934
+ }
1024
935
 
936
+ // now that the values have been updated call any methods that use on them so they get the updated values
937
+ // immediately
1025
938
  durationChanged && this._onDurationChange();
1026
939
  startTimeChanged && this._onProgress();
1027
940
  }
1028
941
  }, {
1029
942
  key: "_onFragmentChanged",
1030
943
  value: function _onFragmentChanged(evt, data) {
944
+ this._currentFragment = data.frag;
1031
945
  this.trigger(core.Events.Custom.PLAYBACK_FRAGMENT_CHANGED, data);
1032
946
  }
1033
947
  }, {
@@ -1054,7 +968,6 @@
1054
968
  this.trigger(core.Events.PLAYBACK_LEVEL_SWITCH_END);
1055
969
  this.trigger(core.Events.PLAYBACK_LEVEL_SWITCH, data);
1056
970
  var currentLevel = this._hls.levels[data.level];
1057
-
1058
971
  if (currentLevel) {
1059
972
  // TODO should highDefinition be private and maybe have a read only accessor if it's used somewhere
1060
973
  this.highDefinition = currentLevel.height >= 720 || currentLevel.bitrate / 1000 >= 2000;
@@ -1090,19 +1003,17 @@
1090
1003
  }], [{
1091
1004
  key: "HLSJS",
1092
1005
  get: function get() {
1093
- return HLSJS__default['default'];
1006
+ return HLSJS__default["default"];
1094
1007
  }
1095
1008
  }]);
1096
-
1097
1009
  return HlsjsPlayback;
1098
1010
  }(core.HTML5Video);
1099
-
1100
1011
  HlsjsPlayback.canPlay = function (resource, mimeType) {
1101
1012
  var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || [];
1102
1013
  var isHls = resourceParts.length > 1 && resourceParts[1].toLowerCase() === 'm3u8' || listContainsIgnoreCase(mimeType, ['application/vnd.apple.mpegurl', 'application/x-mpegURL']);
1103
- return !!(HLSJS__default['default'].isSupported() && isHls);
1014
+ return !!(HLSJS__default["default"].isSupported() && isHls);
1104
1015
  };
1105
1016
 
1106
1017
  return HlsjsPlayback;
1107
1018
 
1108
- })));
1019
+ }));