@clappr/hlsjs-playback 3.0.3 → 3.1.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.
@@ -1,158 +1,38 @@
1
- import { Utils, Events, Playback, Log, PlayerError, HTML5Video } from '@clappr/core';
2
- import HLSJS from 'hls.js';
3
-
4
- function _arrayLikeToArray(r, a) {
5
- (null == a || a > r.length) && (a = r.length);
6
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
7
- return n;
8
- }
9
- function _arrayWithoutHoles(r) {
10
- if (Array.isArray(r)) return _arrayLikeToArray(r);
11
- }
12
- function _assertThisInitialized(e) {
13
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
14
- return e;
15
- }
16
- function _callSuper(t, o, e) {
17
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
18
- }
19
- function _classCallCheck(a, n) {
20
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
21
- }
22
- function _defineProperties(e, r) {
23
- for (var t = 0; t < r.length; t++) {
24
- var o = r[t];
25
- o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
26
- }
27
- }
28
- function _createClass(e, r, t) {
29
- return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
30
- writable: false
31
- }), e;
32
- }
33
- function _defineProperty(e, r, t) {
34
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
35
- value: t,
36
- enumerable: true,
37
- configurable: true,
38
- writable: true
39
- }) : e[r] = t, e;
40
- }
41
- function _get() {
42
- return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
43
- var p = _superPropBase(e, t);
44
- if (p) {
45
- var n = Object.getOwnPropertyDescriptor(p, t);
46
- return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
47
- }
48
- }, _get.apply(null, arguments);
49
- }
50
- function _getPrototypeOf(t) {
51
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
52
- return t.__proto__ || Object.getPrototypeOf(t);
53
- }, _getPrototypeOf(t);
54
- }
55
- function _inherits(t, e) {
56
- if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
57
- t.prototype = Object.create(e && e.prototype, {
58
- constructor: {
59
- value: t,
60
- writable: true,
61
- configurable: true
62
- }
63
- }), Object.defineProperty(t, "prototype", {
64
- writable: false
65
- }), e && _setPrototypeOf(t, e);
66
- }
67
- function _isNativeReflectConstruct() {
68
- try {
69
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
70
- } catch (t) {}
71
- return (_isNativeReflectConstruct = function () {
72
- return !!t;
73
- })();
74
- }
75
- function _iterableToArray(r) {
76
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
77
- }
78
- function _nonIterableSpread() {
79
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
80
- }
81
- function ownKeys(e, r) {
82
- var t = Object.keys(e);
83
- if (Object.getOwnPropertySymbols) {
84
- var o = Object.getOwnPropertySymbols(e);
85
- r && (o = o.filter(function (r) {
86
- return Object.getOwnPropertyDescriptor(e, r).enumerable;
87
- })), t.push.apply(t, o);
88
- }
89
- return t;
90
- }
91
- function _objectSpread2(e) {
92
- for (var r = 1; r < arguments.length; r++) {
93
- var t = null != arguments[r] ? arguments[r] : {};
94
- r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
95
- _defineProperty(e, r, t[r]);
96
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
97
- Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
98
- });
99
- }
100
- return e;
101
- }
102
- function _possibleConstructorReturn(t, e) {
103
- if (e && ("object" == typeof e || "function" == typeof e)) return e;
104
- if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
105
- return _assertThisInitialized(t);
106
- }
107
- function _setPrototypeOf(t, e) {
108
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
109
- return t.__proto__ = e, t;
110
- }, _setPrototypeOf(t, e);
111
- }
112
- function _superPropBase(t, o) {
113
- for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
114
- return t;
115
- }
116
- function _superPropGet(t, o, e, r) {
117
- var p = _get(_getPrototypeOf(t.prototype ), o, e);
118
- return 2 & r && "function" == typeof p ? function (t) {
119
- return p.apply(e, t);
120
- } : p;
121
- }
122
- function _toConsumableArray(r) {
123
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
124
- }
125
- function _toPrimitive(t, r) {
126
- if ("object" != typeof t || !t) return t;
127
- var e = t[Symbol.toPrimitive];
128
- if (void 0 !== e) {
129
- var i = e.call(t, r);
130
- if ("object" != typeof i) return i;
131
- throw new TypeError("@@toPrimitive must return a primitive value.");
132
- }
133
- return (String )(t);
134
- }
135
- function _toPropertyKey(t) {
136
- var i = _toPrimitive(t, "string");
137
- return "symbol" == typeof i ? i : i + "";
138
- }
139
- function _unsupportedIterableToArray(r, a) {
140
- if (r) {
141
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
142
- var t = {}.toString.call(r).slice(8, -1);
143
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
144
- }
145
- }
146
-
147
- if (!HLSJS) {
148
- throw new Error('@clappr/hlsjs-playback requires hls.js (^1) to be loaded before it');
149
- }
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
3
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
6
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
7
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
11
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
12
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
13
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
14
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
15
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
17
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
18
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
19
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
20
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
21
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
22
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
23
+ function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); }
24
+ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; }
25
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
26
+ import { Events, HTML5Video, Log, Playback, PlayerError, Utils } from "@clappr/core";
27
+ import HLSJS from "hls.js";
28
+ //#region src/hls.js
29
+ if (!HLSJS) throw new Error("@clappr/hlsjs-playback requires hls.js (^1) to be loaded before it");
150
30
  var now = Utils.now,
151
31
  listContainsIgnoreCase = Utils.listContainsIgnoreCase;
152
32
  var AUTO = -1;
153
33
  var DEFAULT_RECOVER_ATTEMPTS = 16;
154
- Events.register('PLAYBACK_FRAGMENT_CHANGED');
155
- Events.register('PLAYBACK_FRAGMENT_PARSING_METADATA');
34
+ Events.register("PLAYBACK_FRAGMENT_CHANGED");
35
+ Events.register("PLAYBACK_FRAGMENT_PARSING_METADATA");
156
36
  var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
157
37
  function HlsjsPlayback() {
158
38
  var _this;
@@ -161,10 +41,10 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
161
41
  args[_key] = arguments[_key];
162
42
  }
163
43
  _this = _callSuper(this, HlsjsPlayback, [].concat(args));
164
- _this.options.hlsPlayback = _objectSpread2(_objectSpread2({}, _this.defaultOptions), _this.options.hlsPlayback);
44
+ _this.options.hlsPlayback = _objectSpread(_objectSpread({}, _this.defaultOptions), _this.options.hlsPlayback);
165
45
  _this._timeUpdateThrottleDelay = 200;
166
- _this._timeUpdateFiringRate = 0.2;
167
- _this._durationChangeMinOffset = 0.5;
46
+ _this._timeUpdateFiringRate = .2;
47
+ _this._durationChangeMinOffset = .5;
168
48
  _this._setInitialState();
169
49
  return _this;
170
50
  }
@@ -172,13 +52,13 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
172
52
  return _createClass(HlsjsPlayback, [{
173
53
  key: "name",
174
54
  get: function get() {
175
- return 'hls';
55
+ return "hls";
176
56
  }
177
57
  }, {
178
58
  key: "supportedVersion",
179
59
  get: function get() {
180
60
  return {
181
- min: "0.16.3"
61
+ min: "0.17.1"
182
62
  };
183
63
  }
184
64
  }, {
@@ -189,20 +69,12 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
189
69
  }, {
190
70
  key: "currentLevel",
191
71
  get: function get() {
192
- if (this._currentLevel === null || this._currentLevel === undefined) {
193
- return AUTO;
194
- } else {
195
- return this._currentLevel;
196
- } // 0 is a valid level ID
72
+ if (this._currentLevel === null || this._currentLevel === void 0) return AUTO;else return this._currentLevel;
197
73
  },
198
74
  set: function set(id) {
199
75
  this._currentLevel = id;
200
76
  this.trigger(Events.PLAYBACK_LEVEL_SWITCH_START);
201
- if (this.options.playback.hlsUseNextLevel) {
202
- this._hls.nextLevel = this._currentLevel;
203
- } else {
204
- this._hls.currentLevel = this._currentLevel;
205
- }
77
+ if (this.options.playback.hlsUseNextLevel) this._hls.nextLevel = this._currentLevel;else this._hls.currentLevel = this._currentLevel;
206
78
  }
207
79
  }, {
208
80
  key: "isReady",
@@ -227,9 +99,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
227
99
  }, {
228
100
  key: "_startTime",
229
101
  get: function get() {
230
- if (this._playbackType === Playback.LIVE && this._playlistType !== 'EVENT') {
231
- return this._extrapolatedStartTime;
232
- }
102
+ if (this._playbackType === Playback.LIVE && this._playlistType !== "EVENT") return this._extrapolatedStartTime;
233
103
  return this._playableRegionStartTime;
234
104
  }
235
105
  }, {
@@ -237,24 +107,15 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
237
107
  get: function get() {
238
108
  return now();
239
109
  }
240
-
241
- // the time in the video element which should represent the start of the sliding window
242
- // extrapolated to increase in real time (instead of jumping as the early segments are removed)
243
110
  }, {
244
111
  key: "_extrapolatedStartTime",
245
112
  get: function get() {
246
- if (!this._localStartTimeCorrelation) {
247
- return this._playableRegionStartTime;
248
- }
113
+ if (!this._localStartTimeCorrelation) return this._playableRegionStartTime;
249
114
  var corr = this._localStartTimeCorrelation;
250
115
  var timePassed = this._now - corr.local;
251
- var extrapolatedWindowStartTime = (corr.remote + timePassed) / 1000;
252
- // cap at the end of the extrapolated window duration
116
+ var extrapolatedWindowStartTime = (corr.remote + timePassed) / 1e3;
253
117
  return Math.min(extrapolatedWindowStartTime, this._playableRegionStartTime + this._extrapolatedWindowDuration);
254
118
  }
255
-
256
- // the time in the video element which should represent the end of the content
257
- // extrapolated to increase in real time (instead of jumping as segments are added)
258
119
  }, {
259
120
  key: "_extrapolatedEndTime",
260
121
  get: function get() {
@@ -262,7 +123,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
262
123
  if (!this._localEndTimeCorrelation) return actualEndTime;
263
124
  var correlation = this._localEndTimeCorrelation;
264
125
  var timePassed = this._now - correlation.local;
265
- var extrapolatedEndTime = (correlation.remote + timePassed) / 1000;
126
+ var extrapolatedEndTime = (correlation.remote + timePassed) / 1e3;
266
127
  return Math.max(actualEndTime - this._extrapolatedWindowDuration, Math.min(extrapolatedEndTime, actualEndTime));
267
128
  }
268
129
  }, {
@@ -270,30 +131,10 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
270
131
  get: function get() {
271
132
  return this._extrapolatedEndTime - this._startTime;
272
133
  }
273
-
274
- // Returns the duration (seconds) of the window that the extrapolated start time is allowed
275
- // to move in before being capped.
276
- // The extrapolated start time should never reach the cap at the end of the window as the
277
- // window should slide as chunks are removed from the start.
278
- // This also applies to the extrapolated end time in the same way.
279
- //
280
- // If chunks aren't being removed for some reason that the start time will reach and remain fixed at
281
- // playableRegionStartTime + extrapolatedWindowDuration
282
- //
283
- // <-- window duration -->
284
- // I.e playableRegionStartTime |-----------------------|
285
- // | --> . . .
286
- // . --> | --> . .
287
- // . . --> | --> .
288
- // . . . --> |
289
- // . . . .
290
- // extrapolatedStartTime
291
134
  }, {
292
135
  key: "_extrapolatedWindowDuration",
293
136
  get: function get() {
294
- if (this._segmentTargetDuration === null) {
295
- return 0;
296
- }
137
+ if (this._segmentTargetDuration === null) return 0;
297
138
  return this._extrapolatedWindowNumSegments * this._segmentTargetDuration;
298
139
  }
299
140
  }, {
@@ -322,22 +163,14 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
322
163
  key: "currentTimestamp",
323
164
  get: function get() {
324
165
  if (!this._currentFragment) return null;
325
- var startTime = this._currentFragment.programDateTime;
326
- var playbackTime = this.el.currentTime;
327
- var playTimeOffSet = playbackTime - this._currentFragment.start;
328
- var currentTimestampInMs = startTime + playTimeOffSet * 1000;
329
- return currentTimestampInMs / 1000;
166
+ return (this._currentFragment.programDateTime + (this.el.currentTime - this._currentFragment.start) * 1e3) / 1e3;
330
167
  }
331
168
  }, {
332
169
  key: "_setInitialState",
333
170
  value: function _setInitialState() {
334
171
  var _this$options$hlsReco;
335
- this._minDvrSize = typeof this.options.hlsMinimumDvrSize === 'undefined' ? 60 : this.options.hlsMinimumDvrSize;
336
- // The size of the start time extrapolation window measured as a multiple of segments.
337
- // Should be 2 or higher, or 0 to disable. Should only need to be increased above 2 if more than one segment is
338
- // removed from the start of the playlist at a time. E.g if the playlist is cached for 10 seconds and new chunks are
339
- // added/removed every 5.
340
- this._extrapolatedWindowNumSegments = !this.options.playback || typeof this.options.playback.extrapolatedWindowNumSegments === 'undefined' ? 2 : this.options.playback.extrapolatedWindowNumSegments;
172
+ this._minDvrSize = typeof this.options.hlsMinimumDvrSize === "undefined" ? 60 : this.options.hlsMinimumDvrSize;
173
+ this._extrapolatedWindowNumSegments = !this.options.playback || typeof this.options.playback.extrapolatedWindowNumSegments === "undefined" ? 2 : this.options.playback.extrapolatedWindowNumSegments;
341
174
  this._playbackType = Playback.VOD;
342
175
  this._lastTimeUpdate = {
343
176
  current: 0,
@@ -346,32 +179,13 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
346
179
  };
347
180
  this._lastTimeUpdateFiredTime = 0;
348
181
  this._lastDuration = null;
349
- // for hls streams which have dvr with a sliding window,
350
- // the content at the start of the playlist is removed as new
351
- // content is appended at the end.
352
- // this means the actual playable start time will increase as the
353
- // start content is deleted
354
- // For streams with dvr where the entire recording is kept from the
355
- // beginning this should stay as 0
356
182
  this._playableRegionStartTime = 0;
357
- // {local, remote} remote is the time in the video element that should represent 0
358
- // local is the system time when the 'remote' measurment took place
359
183
  this._localStartTimeCorrelation = null;
360
- // {local, remote} remote is the time in the video element that should represents the end
361
- // local is the system time when the 'remote' measurment took place
362
184
  this._localEndTimeCorrelation = null;
363
- // if content is removed from the beginning then this empty area should
364
- // be ignored. "playableRegionDuration" excludes the empty area
365
185
  this._playableRegionDuration = 0;
366
- // #EXT-X-PROGRAM-DATE-TIME
367
186
  this._programDateTime = 0;
368
- // true when the actual duration is longer than hlsjs's live sync point
369
- // when this is false playableRegionDuration will be the actual duration
370
- // when this is true playableRegionDuration will exclude the time after the sync point
371
187
  this._durationExcludesAfterLiveSyncPoint = false;
372
- // #EXT-X-TARGETDURATION
373
188
  this._segmentTargetDuration = null;
374
- // #EXT-X-PLAYLIST-TYPE
375
189
  this._playlistType = null;
376
190
  this._recoverAttemptsRemaining = (_this$options$hlsReco = this.options.hlsRecoverAttempts) !== null && _this$options$hlsReco !== void 0 ? _this$options$hlsReco : DEFAULT_RECOVER_ATTEMPTS;
377
191
  }
@@ -397,7 +211,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
397
211
  }, {
398
212
  key: "_createHLSInstance",
399
213
  value: function _createHLSInstance() {
400
- var config = _objectSpread2({}, this.options.playback.hlsjsConfig);
214
+ var config = _objectSpread({}, this.options.playback.hlsjsConfig);
401
215
  this._hls = new HLSJS(config);
402
216
  }
403
217
  }, {
@@ -455,7 +269,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
455
269
  var _this3 = this;
456
270
  this.customListeners.forEach(function (item) {
457
271
  var requestedEventName = item.eventName;
458
- var typeOfListener = item.once ? 'once' : 'on';
272
+ var typeOfListener = item.once ? "once" : "on";
459
273
  requestedEventName && _this3._hls["".concat(typeOfListener)](requestedEventName, item.callback);
460
274
  });
461
275
  }
@@ -503,7 +317,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
503
317
  this._hls.recoverMediaError();
504
318
  this.play();
505
319
  } else {
506
- Log.error('hlsjs: failed to recover', {
320
+ Log.error("hlsjs: failed to recover", {
507
321
  evt: evt,
508
322
  data: data
509
323
  });
@@ -513,9 +327,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
513
327
  this.stop();
514
328
  }
515
329
  }
516
-
517
- // override
518
- // this playback manages the src on the video element itself
519
330
  }, {
520
331
  key: "_setupSrc",
521
332
  value: function _setupSrc(srcUrl) {}
@@ -541,18 +352,11 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
541
352
  value: function getProgramDateTime() {
542
353
  return this._programDateTime;
543
354
  }
544
-
545
- // the duration on the video element itself should not be used
546
- // as this does not necesarily represent the duration of the stream
547
- // https://github.com/clappr/clappr/issues/668#issuecomment-157036678
548
355
  }, {
549
356
  key: "getDuration",
550
357
  value: function getDuration() {
551
358
  return this._duration;
552
359
  }
553
-
554
- // the frame rate should be retrieved from the HLS.js level information
555
- // as it is not necessarily exposed directly by the video element
556
360
  }, {
557
361
  key: "getFrameRate",
558
362
  value: function getFrameRate() {
@@ -565,15 +369,8 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
565
369
  }, {
566
370
  key: "getCurrentTime",
567
371
  value: function getCurrentTime() {
568
- // e.g. can be < 0 if user pauses near the start
569
- // eventually they will then be kicked to the end by hlsjs if they run out of buffer
570
- // before the official start time
571
372
  return Math.max(0, this.el.currentTime - this._startTime);
572
373
  }
573
-
574
- // the time that "0" now represents relative to when playback started
575
- // for a stream with a sliding window this will increase as content is
576
- // removed from the beginning
577
374
  }, {
578
375
  key: "getStartTimeOffset",
579
376
  value: function getStartTimeOffset() {
@@ -588,7 +385,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
588
385
  key: "seek",
589
386
  value: function seek(time) {
590
387
  if (time < 0) {
591
- Log.warn('Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.');
388
+ Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.");
592
389
  time = this.getDuration();
593
390
  }
594
391
  time += this._startTime;
@@ -602,13 +399,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
602
399
  }, {
603
400
  key: "_updateSettings",
604
401
  value: function _updateSettings() {
605
- if (this._playbackType === Playback.VOD) {
606
- this.settings.left = ['playpause', 'position', 'duration'];
607
- } else if (this.dvrEnabled) {
608
- this.settings.left = ['playpause'];
609
- } else {
610
- this.settings.left = ['playstop'];
611
- }
402
+ if (this._playbackType === Playback.VOD) this.settings.left = ["playpause", "position", "duration"];else if (this.dvrEnabled) this.settings.left = ["playpause"];else this.settings.left = ["playstop"];
612
403
  this.settings.seekEnabled = this.isSeekEnabled();
613
404
  this.trigger(Events.PLAYBACK_SETTINGSUPDATE);
614
405
  }
@@ -622,23 +413,18 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
622
413
  };
623
414
  var formattedError;
624
415
  if (data.response) error.description += ", response: ".concat(JSON.stringify(data.response));
625
- // only report/handle errors if they are fatal
626
- // hlsjs should automatically handle non fatal errors
627
416
  if (data.fatal) {
628
417
  if (this._recoverAttemptsRemaining > 0) {
629
418
  this._recoverAttemptsRemaining -= 1;
630
419
  switch (data.type) {
631
420
  case HLSJS.ErrorTypes.NETWORK_ERROR:
632
421
  switch (data.details) {
633
- // The following network errors cannot be recovered with HLS.startLoad()
634
- // For more details, see https://github.com/video-dev/hls.js/blob/master/doc/design.md#error-detection-and-handling
635
- // For "level load" fatal errors, see https://github.com/video-dev/hls.js/issues/1138
636
422
  case HLSJS.ErrorDetails.MANIFEST_LOAD_ERROR:
637
423
  case HLSJS.ErrorDetails.MANIFEST_LOAD_TIMEOUT:
638
424
  case HLSJS.ErrorDetails.MANIFEST_PARSING_ERROR:
639
425
  case HLSJS.ErrorDetails.LEVEL_LOAD_ERROR:
640
426
  case HLSJS.ErrorDetails.LEVEL_LOAD_TIMEOUT:
641
- Log.error('hlsjs: unrecoverable network fatal error.', {
427
+ Log.error("hlsjs: unrecoverable network fatal error.", {
642
428
  evt: evt,
643
429
  data: data
644
430
  });
@@ -647,17 +433,16 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
647
433
  this.stop();
648
434
  break;
649
435
  default:
650
- Log.warn('hlsjs: trying to recover from network error.', {
436
+ Log.warn("hlsjs: trying to recover from network error.", {
651
437
  evt: evt,
652
438
  data: data
653
439
  });
654
440
  error.level = PlayerError.Levels.WARN;
655
441
  this._hls.startLoad();
656
- break;
657
442
  }
658
443
  break;
659
444
  case HLSJS.ErrorTypes.MEDIA_ERROR:
660
- Log.warn('hlsjs: trying to recover from media error.', {
445
+ Log.warn("hlsjs: trying to recover from media error.", {
661
446
  evt: evt,
662
447
  data: data
663
448
  });
@@ -665,17 +450,16 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
665
450
  this._recover(evt, data, error);
666
451
  break;
667
452
  default:
668
- Log.error('hlsjs: could not recover from error.', {
453
+ Log.error("hlsjs: could not recover from error.", {
669
454
  evt: evt,
670
455
  data: data
671
456
  });
672
457
  formattedError = this.createError(error);
673
458
  this.trigger(Events.PLAYBACK_ERROR, formattedError);
674
459
  this.stop();
675
- break;
676
460
  }
677
461
  } else {
678
- Log.error('hlsjs: could not recover from error after maximum number of attempts.', {
462
+ Log.error("hlsjs: could not recover from error after maximum number of attempts.", {
679
463
  evt: evt,
680
464
  data: data
681
465
  });
@@ -684,12 +468,8 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
684
468
  this.stop();
685
469
  }
686
470
  } else {
687
- // Transforms HLSJS.ErrorDetails.KEY_LOAD_ERROR non-fatal error to
688
- // playback fatal error if triggerFatalErrorOnResourceDenied playback
689
- // option is set. HLSJS.ErrorTypes.KEY_SYSTEM_ERROR are fatal errors
690
- // and therefore already handled.
691
471
  if (this.options.playback.triggerFatalErrorOnResourceDenied && this._keyIsDenied(data)) {
692
- Log.error('hlsjs: could not load decrypt key.', {
472
+ Log.error("hlsjs: could not load decrypt key.", {
693
473
  evt: evt,
694
474
  data: data
695
475
  });
@@ -699,10 +479,11 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
699
479
  return;
700
480
  }
701
481
  error.level = PlayerError.Levels.WARN;
702
- Log.warn('hlsjs: non-fatal error occurred', {
482
+ Log.warn("hlsjs: non-fatal error occurred", {
703
483
  evt: evt,
704
484
  data: data
705
485
  });
486
+ this.trigger(Events.PLAYBACK_WARNING, error, this.name);
706
487
  }
707
488
  }
708
489
  }, {
@@ -718,8 +499,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
718
499
  total: this.getDuration(),
719
500
  firstFragDateTime: this.getProgramDateTime()
720
501
  };
721
- var shouldThrottle = this._shouldThrottleTimeUpdate(update);
722
- if (shouldThrottle) return;
502
+ if (this._shouldThrottleTimeUpdate(update)) return;
723
503
  this._lastTimeUpdate = update;
724
504
  this._lastTimeUpdateFiredTime = this._now;
725
505
  this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name);
@@ -738,8 +518,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
738
518
  key: "_onDurationChange",
739
519
  value: function _onDurationChange() {
740
520
  var duration = this.getDuration();
741
- var isSameDuration = Math.abs(this._lastDuration - duration) < this._durationChangeMinOffset;
742
- if (isSameDuration) return;
521
+ if (Math.abs(this._lastDuration - duration) < this._durationChangeMinOffset) return;
743
522
  this._lastDuration = duration;
744
523
  _superPropGet(HlsjsPlayback, "_onDurationChange", this, 3)([]);
745
524
  }
@@ -751,13 +530,10 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
751
530
  var bufferedPos = 0;
752
531
  for (var i = 0; i < this.el.buffered.length; i++) {
753
532
  buffered = [].concat(_toConsumableArray(buffered), [{
754
- // for a stream with sliding window dvr something that is buffered my slide off the start of the timeline
755
533
  start: Math.max(0, this.el.buffered.start(i) - this._playableRegionStartTime),
756
534
  end: Math.max(0, this.el.buffered.end(i) - this._playableRegionStartTime)
757
535
  }]);
758
- if (this.el.currentTime >= buffered[i].start && this.el.currentTime <= buffered[i].end) {
759
- bufferedPos = i;
760
- }
536
+ if (this.el.currentTime >= buffered[i].start && this.el.currentTime <= buffered[i].end) bufferedPos = i;
761
537
  }
762
538
  var progress = {
763
539
  start: buffered[bufferedPos].start,
@@ -806,10 +582,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
806
582
  value: function _updatePlaybackType(evt, data) {
807
583
  this._playbackType = data.details.live ? Playback.LIVE : Playback.VOD;
808
584
  this._onLevelUpdated(evt, data);
809
- // Live stream subtitle tracks detection hack (may not immediately available)
810
- if (this._ccTracksUpdated && this._playbackType === Playback.LIVE && this.hasClosedCaptionsTracks) {
811
- this._onSubtitleLoaded();
812
- }
585
+ if (this._ccTracksUpdated && this._playbackType === Playback.LIVE && this.hasClosedCaptionsTracks) this._onSubtitleLoaded();
813
586
  }
814
587
  }, {
815
588
  key: "_fillLevels",
@@ -818,7 +591,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
818
591
  return {
819
592
  id: index,
820
593
  level: level,
821
- label: "".concat(level.bitrate / 1000, "Kbps")
594
+ label: "".concat(level.bitrate / 1e3, "Kbps")
822
595
  };
823
596
  });
824
597
  this.trigger(Events.PLAYBACK_LEVELS_AVAILABLE, this._levels);
@@ -834,111 +607,62 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
834
607
  var previousPlayableRegionStartTime = this._playableRegionStartTime;
835
608
  var previousPlayableRegionDuration = this._playableRegionDuration;
836
609
  if (fragments.length === 0) return;
837
- // #EXT-X-PROGRAM-DATE-TIME
838
- if (fragments[0].rawProgramDateTime) {
839
- this._programDateTime = fragments[0].rawProgramDateTime;
840
- }
610
+ if (fragments[0].rawProgramDateTime) this._programDateTime = fragments[0].rawProgramDateTime;
841
611
  if (this._playableRegionStartTime !== fragments[0].start) {
842
612
  startTimeChanged = true;
843
613
  this._playableRegionStartTime = fragments[0].start;
844
614
  }
845
615
  if (startTimeChanged) {
846
- if (!this._localStartTimeCorrelation) {
847
- // set the correlation to map to middle of the extrapolation window
848
- this._localStartTimeCorrelation = {
849
- local: this._now,
850
- remote: (fragments[0].start + this._extrapolatedWindowDuration / 2) * 1000
851
- };
852
- } else {
853
- // check if the correlation still works
616
+ if (!this._localStartTimeCorrelation) this._localStartTimeCorrelation = {
617
+ local: this._now,
618
+ remote: (fragments[0].start + this._extrapolatedWindowDuration / 2) * 1e3
619
+ };else {
854
620
  var corr = this._localStartTimeCorrelation;
855
621
  var timePassed = this._now - corr.local;
856
- // this should point to a time within the extrapolation window
857
- var startTime = (corr.remote + timePassed) / 1000;
858
- if (startTime < fragments[0].start) {
859
- // our start time is now earlier than the first chunk
860
- // (maybe the chunk was removed early)
861
- // reset correlation so that it sits at the beginning of the first available chunk
862
- this._localStartTimeCorrelation = {
863
- local: this._now,
864
- remote: fragments[0].start * 1000
865
- };
866
- } else if (startTime > previousPlayableRegionStartTime + this._extrapolatedWindowDuration) {
867
- // start time was past the end of the old extrapolation window (so would have been capped)
868
- // see if now that time would be inside the window, and if it would be set the correlation
869
- // so that it resumes from the time it was at at the end of the old window
870
- // update the correlation so that the time starts counting again from the value it's on now
871
- this._localStartTimeCorrelation = {
872
- local: this._now,
873
- remote: Math.max(fragments[0].start, previousPlayableRegionStartTime + this._extrapolatedWindowDuration) * 1000
874
- };
875
- }
622
+ var startTime = (corr.remote + timePassed) / 1e3;
623
+ if (startTime < fragments[0].start) this._localStartTimeCorrelation = {
624
+ local: this._now,
625
+ remote: fragments[0].start * 1e3
626
+ };else if (startTime > previousPlayableRegionStartTime + this._extrapolatedWindowDuration) this._localStartTimeCorrelation = {
627
+ local: this._now,
628
+ remote: Math.max(fragments[0].start, previousPlayableRegionStartTime + this._extrapolatedWindowDuration) * 1e3
629
+ };
876
630
  }
877
631
  }
878
632
  var newDuration = data.details.totalduration;
879
- // if it's a live stream then shorten the duration to remove access
880
- // to the area after hlsjs's live sync point
881
- // seeks to areas after this point sometimes have issues
882
633
  if (this._playbackType === Playback.LIVE) {
883
- var fragmentTargetDuration = data.details.targetduration;
884
- var hlsjsConfig = this.options.playback.hlsjsConfig || {};
885
- var liveSyncDurationCount = hlsjsConfig.liveSyncDurationCount || HLSJS.DefaultConfig.liveSyncDurationCount;
886
- var hiddenAreaDuration = fragmentTargetDuration * liveSyncDurationCount;
634
+ var hiddenAreaDuration = data.details.targetduration * ((this.options.playback.hlsjsConfig || {}).liveSyncDurationCount || HLSJS.DefaultConfig.liveSyncDurationCount);
887
635
  if (hiddenAreaDuration <= newDuration) {
888
636
  newDuration -= hiddenAreaDuration;
889
637
  this._durationExcludesAfterLiveSyncPoint = true;
890
- } else {
891
- this._durationExcludesAfterLiveSyncPoint = false;
892
- }
638
+ } else this._durationExcludesAfterLiveSyncPoint = false;
893
639
  }
894
640
  if (newDuration !== this._playableRegionDuration) {
895
641
  durationChanged = true;
896
642
  this._playableRegionDuration = newDuration;
897
643
  }
898
- // Note the end time is not the playableRegionDuration
899
- // The end time will always increase even if content is removed from the beginning
900
644
  var endTime = fragments[0].start + newDuration;
901
645
  var previousEndTime = previousPlayableRegionStartTime + previousPlayableRegionDuration;
902
- var endTimeChanged = endTime !== previousEndTime;
903
- if (endTimeChanged) {
904
- if (!this._localEndTimeCorrelation) {
905
- // set the correlation to map to the end
906
- this._localEndTimeCorrelation = {
907
- local: this._now,
908
- remote: endTime * 1000
909
- };
910
- } else {
911
- // check if the correlation still works
646
+ if (endTime !== previousEndTime) {
647
+ if (!this._localEndTimeCorrelation) this._localEndTimeCorrelation = {
648
+ local: this._now,
649
+ remote: endTime * 1e3
650
+ };else {
912
651
  var _corr = this._localEndTimeCorrelation;
913
652
  var _timePassed = this._now - _corr.local;
914
- // this should point to a time within the extrapolation window from the end
915
- var extrapolatedEndTime = (_corr.remote + _timePassed) / 1000;
916
- if (extrapolatedEndTime > endTime) {
917
- this._localEndTimeCorrelation = {
918
- local: this._now,
919
- remote: endTime * 1000
920
- };
921
- } else if (extrapolatedEndTime < endTime - this._extrapolatedWindowDuration) {
922
- // our extrapolated end time is now earlier than the extrapolation window from the actual end time
923
- // (maybe a chunk became available early)
924
- // reset correlation so that it sits at the beginning of the extrapolation window from the end time
925
- this._localEndTimeCorrelation = {
926
- local: this._now,
927
- remote: (endTime - this._extrapolatedWindowDuration) * 1000
928
- };
929
- } else if (extrapolatedEndTime > previousEndTime) {
930
- // end time was past the old end time (so would have been capped)
931
- // set the correlation so that it resumes from the time it was at at the end of the old window
932
- this._localEndTimeCorrelation = {
933
- local: this._now,
934
- remote: previousEndTime * 1000
935
- };
936
- }
653
+ var extrapolatedEndTime = (_corr.remote + _timePassed) / 1e3;
654
+ if (extrapolatedEndTime > endTime) this._localEndTimeCorrelation = {
655
+ local: this._now,
656
+ remote: endTime * 1e3
657
+ };else if (extrapolatedEndTime < endTime - this._extrapolatedWindowDuration) this._localEndTimeCorrelation = {
658
+ local: this._now,
659
+ remote: (endTime - this._extrapolatedWindowDuration) * 1e3
660
+ };else if (extrapolatedEndTime > previousEndTime) this._localEndTimeCorrelation = {
661
+ local: this._now,
662
+ remote: previousEndTime * 1e3
663
+ };
937
664
  }
938
665
  }
939
-
940
- // now that the values have been updated call any methods that use on them so they get the updated values
941
- // immediately
942
666
  durationChanged && this._onDurationChange();
943
667
  startTimeChanged && this._onProgress();
944
668
  }
@@ -961,8 +685,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
961
685
  }, {
962
686
  key: "_onSubtitleLoaded",
963
687
  value: function _onSubtitleLoaded() {
964
- // This event may be triggered multiple times
965
- // Setup CC only once (disable CC by default)
966
688
  if (!this._ccIsSetup) {
967
689
  this.trigger(Events.PLAYBACK_SUBTITLE_AVAILABLE);
968
690
  var trackId = this._playbackType === Playback.LIVE ? -1 : this.closedCaptionsTrackId;
@@ -978,8 +700,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
978
700
  this.trigger(Events.PLAYBACK_LEVEL_SWITCH, data);
979
701
  var currentLevel = this._hls.levels[data.level];
980
702
  if (currentLevel) {
981
- // TODO should highDefinition be private and maybe have a read only accessor if it's used somewhere
982
- this.highDefinition = currentLevel.height >= 720 || currentLevel.bitrate / 1000 >= 2000;
703
+ this.highDefinition = currentLevel.height >= 720 || currentLevel.bitrate / 1e3 >= 2e3;
983
704
  this.trigger(Events.PLAYBACK_HIGHDEFINITIONUPDATE, this.highDefinition);
984
705
  this.trigger(Events.PLAYBACK_BITRATE, {
985
706
  height: currentLevel.height,
@@ -993,10 +714,6 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
993
714
  }, {
994
715
  key: "dvrEnabled",
995
716
  get: function get() {
996
- // enabled when:
997
- // - the duration does not include content after hlsjs's live sync point
998
- // - the playable region duration is longer than the configured duration to enable dvr after
999
- // - the playback type is LIVE.
1000
717
  return this._durationExcludesAfterLiveSyncPoint && this._duration >= this._minDvrSize && this.getPlaybackType() === Playback.LIVE;
1001
718
  }
1002
719
  }, {
@@ -1017,10 +734,11 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
1017
734
  }]);
1018
735
  }(HTML5Video);
1019
736
  HlsjsPlayback.canPlay = function (resource, mimeType) {
1020
- var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || [];
1021
- var isHls = resourceParts.length > 1 && resourceParts[1].toLowerCase() === 'm3u8' || listContainsIgnoreCase(mimeType, ['application/vnd.apple.mpegurl', 'application/x-mpegURL']);
737
+ var resourceParts = resource.split("?")[0].match(/.*\.(.*)$/) || [];
738
+ var isHls = resourceParts.length > 1 && resourceParts[1].toLowerCase() === "m3u8" || listContainsIgnoreCase(mimeType, ["application/vnd.apple.mpegurl", "application/x-mpegURL"]);
1022
739
  return !!(HLSJS.isSupported() && isHls);
1023
740
  };
1024
-
741
+ //#endregion
1025
742
  export { HlsjsPlayback as default };
1026
- //# sourceMappingURL=hlsjs-playback.esm.js.map
743
+
744
+ //# sourceMappingURL=hlsjs-playback.esm.js.map