@clappr/hlsjs-playback 3.1.0 → 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.
@@ -58,7 +58,7 @@ var HlsjsPlayback = /*#__PURE__*/function (_HTML5Video) {
58
58
  key: "supportedVersion",
59
59
  get: function get() {
60
60
  return {
61
- min: "0.17.0"
61
+ min: "0.17.1"
62
62
  };
63
63
  }
64
64
  }, {
@@ -87,7 +87,7 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
87
87
  key: "supportedVersion",
88
88
  get: function get() {
89
89
  return {
90
- min: "0.17.0"
90
+ min: "0.17.1"
91
91
  };
92
92
  }
93
93
  }, {
@@ -1 +1 @@
1
- function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}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.");}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;}}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}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;}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;}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;}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;}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}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);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}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);}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);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}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);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}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;}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);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}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);}!function(t,e){"object"==(typeof exports==="undefined"?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=e(require("@clappr/core"),require("hls.js")):"function"==typeof define&&define.amd?define(["@clappr/core","hls.js"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).HlsjsPlayback=e(t.Clappr,t.Hls);}(this,function(t,e){var i,s,r,a=Object.create,n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,h=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;if(r=null!=(i=e)?a(h(i)):{},!(e=function(t,e,i,s){if(e&&"object"==_typeof(e)||"function"==typeof e)for(var r,a=l(e),h=0,d=a.length;h<d;h++)r=a[h],_.call(t,r)||r===i||n(t,r,{get:function(t){return e[t];}.bind(null,r),enumerable:!(s=o(e,r))||s.enumerable});return t;}(!s&&i&&i.__esModule&&_.call(i,"default")?r:n(r,"default",{value:i,enumerable:!0}),i)).default)throw new Error("@clappr/hlsjs-playback requires hls.js (^1) to be loaded before it");var _t$Utils=t.Utils,d=_t$Utils.now,c=_t$Utils.listContainsIgnoreCase;t.Events.register("PLAYBACK_FRAGMENT_CHANGED"),t.Events.register("PLAYBACK_FRAGMENT_PARSING_METADATA");var u=/*#__PURE__*/function(_t$HTML5Video){function u(){var _this;_classCallCheck(this,u);for(var _len=arguments.length,t=new Array(_len),_key=0;_key<_len;_key++){t[_key]=arguments[_key];}_this=_callSuper(this,u,[].concat(t)),_this.options.hlsPlayback=_objectSpread(_objectSpread({},_this.defaultOptions),_this.options.hlsPlayback),_this._timeUpdateThrottleDelay=200,_this._timeUpdateFiringRate=.2,_this._durationChangeMinOffset=.5,_this._setInitialState();return _this;}_inherits(u,_t$HTML5Video);return _createClass(u,[{key:"name",get:function get(){return"hls";}},{key:"supportedVersion",get:function get(){return{min:"0.17.0"};}},{key:"levels",get:function get(){return this._levels||[];}},{key:"currentLevel",get:function get(){return null===this._currentLevel||void 0===this._currentLevel?-1:this._currentLevel;},set:function set(e){this._currentLevel=e,this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_START),this.options.playback.hlsUseNextLevel?this._hls.nextLevel=this._currentLevel:this._hls.currentLevel=this._currentLevel;}},{key:"isReady",get:function get(){return this._isReadyState;}},{key:"latency",get:function get(){return this._hls.latency;}},{key:"liveSyncPosition",get:function get(){return this._hls.liveSyncPosition;}},{key:"currentProgramDateTime",get:function get(){return this._hls.playingDate;}},{key:"_startTime",get:function get(){return this._playbackType===t.Playback.LIVE&&"EVENT"!==this._playlistType?this._extrapolatedStartTime:this._playableRegionStartTime;}},{key:"_now",get:function get(){return d();}},{key:"_extrapolatedStartTime",get:function get(){if(!this._localStartTimeCorrelation)return this._playableRegionStartTime;var t=this._localStartTimeCorrelation,e=this._now-t.local,i=(t.remote+e)/1e3;return Math.min(i,this._playableRegionStartTime+this._extrapolatedWindowDuration);}},{key:"_extrapolatedEndTime",get:function get(){var t=this._playableRegionStartTime+this._playableRegionDuration;if(!this._localEndTimeCorrelation)return t;var e=this._localEndTimeCorrelation,i=this._now-e.local,s=(e.remote+i)/1e3;return Math.max(t-this._extrapolatedWindowDuration,Math.min(s,t));}},{key:"_duration",get:function get(){return this._extrapolatedEndTime-this._startTime;}},{key:"_extrapolatedWindowDuration",get:function get(){return null===this._segmentTargetDuration?0:this._extrapolatedWindowNumSegments*this._segmentTargetDuration;}},{key:"bandwidthEstimate",get:function get(){return this._hls&&this._hls.bandwidthEstimate;}},{key:"defaultOptions",get:function get(){return{preload:!0};}},{key:"customListeners",get:function get(){return this.options.hlsPlayback&&this.options.hlsPlayback.customListeners||[];}},{key:"sourceMedia",get:function get(){return this.options.src;}},{key:"currentTimestamp",get:function get(){return this._currentFragment?(this._currentFragment.programDateTime+1e3*(this.el.currentTime-this._currentFragment.start))/1e3:null;}},{key:"_setInitialState",value:function _setInitialState(){var _this$options$hlsReco;this._minDvrSize=void 0===this.options.hlsMinimumDvrSize?60:this.options.hlsMinimumDvrSize,this._extrapolatedWindowNumSegments=this.options.playback&&void 0!==this.options.playback.extrapolatedWindowNumSegments?this.options.playback.extrapolatedWindowNumSegments:2,this._playbackType=t.Playback.VOD,this._lastTimeUpdate={current:0,total:0,firstFragDateTime:0},this._lastTimeUpdateFiredTime=0,this._lastDuration=null,this._playableRegionStartTime=0,this._localStartTimeCorrelation=null,this._localEndTimeCorrelation=null,this._playableRegionDuration=0,this._programDateTime=0,this._durationExcludesAfterLiveSyncPoint=!1,this._segmentTargetDuration=null,this._playlistType=null,this._recoverAttemptsRemaining=(_this$options$hlsReco=this.options.hlsRecoverAttempts)!==null&&_this$options$hlsReco!==void 0?_this$options$hlsReco:16;}},{key:"_setup",value:function _setup(){this._destroyHLSInstance(),this._createHLSInstance(),this._listenHLSEvents(),this._attachHLSMedia();}},{key:"_destroyHLSInstance",value:function _destroyHLSInstance(){this._hls&&(this._manifestLoading=!1,this._ccIsSetup=!1,this._ccTracksUpdated=!1,this._setInitialState(),this._hls.destroy(),this._hls=null);}},{key:"_createHLSInstance",value:function _createHLSInstance(){var t=_objectSpread({},this.options.playback.hlsjsConfig);this._hls=new e.default(t);}},{key:"_attachHLSMedia",value:function _attachHLSMedia(){this._hls&&this._hls.attachMedia(this.el);}},{key:"_listenHLSEvents",value:function _listenHLSEvents(){var _this2=this;this._hls&&(this._hls.once(e.default.Events.MEDIA_ATTACHED,function(){_this2.options.hlsPlayback.preload&&_this2._hls.loadSource(_this2.options.src);}),this._hls.on(e.default.Events.MANIFEST_LOADING,function(){_this2._manifestLoading=!0;}),this._hls.on(e.default.Events.LEVEL_LOADED,function(t,e){return _this2._updatePlaybackType(t,e);}),this._hls.on(e.default.Events.LEVEL_UPDATED,function(t,e){return _this2._onLevelUpdated(t,e);}),this._hls.on(e.default.Events.LEVEL_SWITCHED,function(t,e){return _this2._onLevelSwitch(t,e);}),this._hls.on(e.default.Events.FRAG_CHANGED,function(t,e){return _this2._onFragmentChanged(t,e);}),this._hls.on(e.default.Events.FRAG_LOADED,function(t,e){return _this2._onFragmentLoaded(t,e);}),this._hls.on(e.default.Events.FRAG_BUFFERED,function(t,e){return _this2._onFragmentBuffered(t,e);}),this._hls.on(e.default.Events.FRAG_PARSING_METADATA,function(t,e){return _this2._onFragmentParsingMetadata(t,e);}),this._hls.on(e.default.Events.ERROR,function(t,e){return _this2._onHLSJSError(t,e);}),this._hls.on(e.default.Events.SUBTITLE_TRACK_LOADED,function(t,e){return _this2._onSubtitleLoaded(t,e);}),this._hls.on(e.default.Events.SUBTITLE_TRACKS_UPDATED,function(){return _this2._ccTracksUpdated=!0;}),this.bindCustomListeners());}},{key:"bindCustomListeners",value:function bindCustomListeners(){var _this3=this;this.customListeners.forEach(function(t){var e=t.eventName,i=t.once?"once":"on";e&&_this3._hls["".concat(i)](e,t.callback);});}},{key:"unbindCustomListeners",value:function unbindCustomListeners(){var _this4=this;this.customListeners.forEach(function(t){var e=t.eventName;e&&_this4._hls.off(e,t.callback);});}},{key:"_onFragmentParsingMetadata",value:function _onFragmentParsingMetadata(e,i){this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA,{evt:e,data:i});}},{key:"render",value:function render(){return this._ready(),_superPropGet(u,"render",this,3)([]);}},{key:"_ready",value:function _ready(){this._isReadyState||(!this._hls&&this._setup(),this._isReadyState=!0,this.trigger(t.Events.PLAYBACK_READY,this.name));}},{key:"_recover",value:function _recover(e,i,s){if(this._recoveredDecodingError){if(this._recoveredAudioCodecError){t.Log.error("hlsjs: failed to recover",{evt:e,data:i}),s.level=t.PlayerError.Levels.FATAL;var _r=this.createError(s);this.trigger(t.Events.PLAYBACK_ERROR,_r),this.stop();}else this._recoveredAudioCodecError=!0,this._hls.swapAudioCodec(),this._hls.recoverMediaError(),this.play();}else this._recoveredDecodingError=!0,this._hls.recoverMediaError(),this.play();}},{key:"_setupSrc",value:function _setupSrc(t){}},{key:"_startTimeUpdateTimer",value:function _startTimeUpdateTimer(){var _this5=this;this._timeUpdateTimer||(this._timeUpdateTimer=setInterval(function(){_this5._onDurationChange(),_this5._onTimeUpdate();},100));}},{key:"_stopTimeUpdateTimer",value:function _stopTimeUpdateTimer(){this._timeUpdateTimer&&(clearInterval(this._timeUpdateTimer),this._timeUpdateTimer=null);}},{key:"getProgramDateTime",value:function getProgramDateTime(){return this._programDateTime;}},{key:"getDuration",value:function getDuration(){return this._duration;}},{key:"getFrameRate",value:function getFrameRate(){if(this._hls&&this._hls.levels&&this._hls.currentLevel>=0){var _t=this._hls.levels[this._hls.currentLevel];return _t&&_t.frameRate?_t.frameRate:null;}return null;}},{key:"getCurrentTime",value:function getCurrentTime(){return Math.max(0,this.el.currentTime-this._startTime);}},{key:"getStartTimeOffset",value:function getStartTimeOffset(){return this._startTime;}},{key:"seekPercentage",value:function seekPercentage(t){this.seek(this._duration*(t/100));}},{key:"seek",value:function seek(e){e<0&&(t.Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point."),e=this.getDuration()),e+=this._startTime,this.el.currentTime=e;}},{key:"seekToLivePoint",value:function seekToLivePoint(){this.seek(this.getDuration());}},{key:"_updateSettings",value:function _updateSettings(){this._playbackType===t.Playback.VOD?this.settings.left=["playpause","position","duration"]:this.dvrEnabled?this.settings.left=["playpause"]:this.settings.left=["playstop"],this.settings.seekEnabled=this.isSeekEnabled(),this.trigger(t.Events.PLAYBACK_SETTINGSUPDATE);}},{key:"_onHLSJSError",value:function _onHLSJSError(i,s){var r={code:"".concat(s.type,"_").concat(s.details),description:"".concat(this.name," error: type: ").concat(s.type,", details: ").concat(s.details),raw:s};var a;if(s.response&&(r.description+=", response: ".concat(JSON.stringify(s.response))),s.fatal){if(this._recoverAttemptsRemaining>0)switch(this._recoverAttemptsRemaining-=1,s.type){case e.default.ErrorTypes.NETWORK_ERROR:switch(s.details){case e.default.ErrorDetails.MANIFEST_LOAD_ERROR:case e.default.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case e.default.ErrorDetails.MANIFEST_PARSING_ERROR:case e.default.ErrorDetails.LEVEL_LOAD_ERROR:case e.default.ErrorDetails.LEVEL_LOAD_TIMEOUT:t.Log.error("hlsjs: unrecoverable network fatal error.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),this.stop();break;default:t.Log.warn("hlsjs: trying to recover from network error.",{evt:i,data:s}),r.level=t.PlayerError.Levels.WARN,this._hls.startLoad();}break;case e.default.ErrorTypes.MEDIA_ERROR:t.Log.warn("hlsjs: trying to recover from media error.",{evt:i,data:s}),r.level=t.PlayerError.Levels.WARN,this._recover(i,s,r);break;default:t.Log.error("hlsjs: could not recover from error.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),this.stop();}else t.Log.error("hlsjs: could not recover from error after maximum number of attempts.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),this.stop();}else{if(this.options.playback.triggerFatalErrorOnResourceDenied&&this._keyIsDenied(s))return t.Log.error("hlsjs: could not load decrypt key.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),void this.stop();r.level=t.PlayerError.Levels.WARN,t.Log.warn("hlsjs: non-fatal error occurred",{evt:i,data:s}),this.trigger(t.Events.PLAYBACK_WARNING,r,this.name);}}},{key:"_keyIsDenied",value:function _keyIsDenied(t){return t.type===e.default.ErrorTypes.NETWORK_ERROR&&t.details===e.default.ErrorDetails.KEY_LOAD_ERROR&&t.response&&t.response.code>=400;}},{key:"_onTimeUpdate",value:function _onTimeUpdate(){var e={current:this.getCurrentTime(),total:this.getDuration(),firstFragDateTime:this.getProgramDateTime()};this._shouldThrottleTimeUpdate(e)||(this._lastTimeUpdate=e,this._lastTimeUpdateFiredTime=this._now,this.trigger(t.Events.PLAYBACK_TIMEUPDATE,e,this.name));}},{key:"_shouldThrottleTimeUpdate",value:function _shouldThrottleTimeUpdate(t){var e=Math.abs(t.current-this._lastTimeUpdate.current)<this._timeUpdateFiringRate,i=Math.abs(t.total-this._lastTimeUpdate.total)<this._durationChangeMinOffset,s=t.firstFragDateTime===this._lastTimeUpdate.firstFragDateTime,r=e&&i&&s,a=this._now-this._lastTimeUpdateFiredTime<this._timeUpdateThrottleDelay;return r&&a;}},{key:"_onDurationChange",value:function _onDurationChange(){var t=this.getDuration();Math.abs(this._lastDuration-t)<this._durationChangeMinOffset||(this._lastDuration=t,_superPropGet(u,"_onDurationChange",this,3)([]));}},{key:"_onProgress",value:function _onProgress(){if(!this.el.buffered.length)return;var e=[],i=0;for(var _t2=0;_t2<this.el.buffered.length;_t2++)e=[].concat(_toConsumableArray(e),[{start:Math.max(0,this.el.buffered.start(_t2)-this._playableRegionStartTime),end:Math.max(0,this.el.buffered.end(_t2)-this._playableRegionStartTime)}]),this.el.currentTime>=e[_t2].start&&this.el.currentTime<=e[_t2].end&&(i=_t2);var s={start:e[i].start,current:e[i].end,total:this.getDuration()};this.trigger(t.Events.PLAYBACK_PROGRESS,s,e);}},{key:"load",value:function load(t){this._stopTimeUpdateTimer(),this.options.src=t,this._setup();}},{key:"play",value:function play(){!this._hls&&this._setup(),!this._manifestLoading&&!this.options.hlsPlayback.preload&&this._hls.loadSource(this.options.src),_superPropGet(u,"play",this,3)([]),this._startTimeUpdateTimer();}},{key:"pause",value:function pause(){this._hls&&this.el.pause();}},{key:"stop",value:function stop(){this._stopTimeUpdateTimer(),this._hls&&_superPropGet(u,"stop",this,3)([]),this._destroyHLSInstance();}},{key:"destroy",value:function destroy(){this._stopTimeUpdateTimer(),this._destroyHLSInstance(),_superPropGet(u,"destroy",this,3)([]);}},{key:"_updatePlaybackType",value:function _updatePlaybackType(e,i){this._playbackType=i.details.live?t.Playback.LIVE:t.Playback.VOD,this._onLevelUpdated(e,i),this._ccTracksUpdated&&this._playbackType===t.Playback.LIVE&&this.hasClosedCaptionsTracks&&this._onSubtitleLoaded();}},{key:"_fillLevels",value:function _fillLevels(){this._levels=this._hls.levels.map(function(t,e){return{id:e,level:t,label:t.bitrate/1e3+"Kbps"};}),this.trigger(t.Events.PLAYBACK_LEVELS_AVAILABLE,this._levels);}},{key:"_onLevelUpdated",value:function _onLevelUpdated(i,s){this._segmentTargetDuration=s.details.targetduration,this._playlistType=s.details.type||null;var r=!1,a=!1;var n=s.details.fragments,o=this._playableRegionStartTime,l=this._playableRegionDuration;if(0===n.length)return;if(n[0].rawProgramDateTime&&(this._programDateTime=n[0].rawProgramDateTime),this._playableRegionStartTime!==n[0].start&&(r=!0,this._playableRegionStartTime=n[0].start),r)if(this._localStartTimeCorrelation){var _t3=this._localStartTimeCorrelation,_e=this._now-_t3.local,_i=(_t3.remote+_e)/1e3;_i<n[0].start?this._localStartTimeCorrelation={local:this._now,remote:1e3*n[0].start}:_i>o+this._extrapolatedWindowDuration&&(this._localStartTimeCorrelation={local:this._now,remote:1e3*Math.max(n[0].start,o+this._extrapolatedWindowDuration)});}else this._localStartTimeCorrelation={local:this._now,remote:1e3*(n[0].start+this._extrapolatedWindowDuration/2)};var h=s.details.totalduration;if(this._playbackType===t.Playback.LIVE){var _t4=s.details.targetduration*((this.options.playback.hlsjsConfig||{}).liveSyncDurationCount||e.default.DefaultConfig.liveSyncDurationCount);_t4<=h?(h-=_t4,this._durationExcludesAfterLiveSyncPoint=!0):this._durationExcludesAfterLiveSyncPoint=!1;}h!==this._playableRegionDuration&&(a=!0,this._playableRegionDuration=h);var _=n[0].start+h,d=o+l;if(_!==d)if(this._localEndTimeCorrelation){var _t5=this._localEndTimeCorrelation,_e2=this._now-_t5.local,_i2=(_t5.remote+_e2)/1e3;_i2>_?this._localEndTimeCorrelation={local:this._now,remote:1e3*_}:_i2<_-this._extrapolatedWindowDuration?this._localEndTimeCorrelation={local:this._now,remote:1e3*(_-this._extrapolatedWindowDuration)}:_i2>d&&(this._localEndTimeCorrelation={local:this._now,remote:1e3*d});}else this._localEndTimeCorrelation={local:this._now,remote:1e3*_};a&&this._onDurationChange(),r&&this._onProgress();}},{key:"_onFragmentChanged",value:function _onFragmentChanged(e,i){this._currentFragment=i.frag,this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_CHANGED,i);}},{key:"_onFragmentLoaded",value:function _onFragmentLoaded(e,i){this.trigger(t.Events.PLAYBACK_FRAGMENT_LOADED,i);}},{key:"_onFragmentBuffered",value:function _onFragmentBuffered(e,i){this.trigger(t.Events.PLAYBACK_FRAGMENT_BUFFERED,i);}},{key:"_onSubtitleLoaded",value:function _onSubtitleLoaded(){if(!this._ccIsSetup){this.trigger(t.Events.PLAYBACK_SUBTITLE_AVAILABLE);var _e3=this._playbackType===t.Playback.LIVE?-1:this.closedCaptionsTrackId;this.closedCaptionsTrackId=_e3,this._ccIsSetup=!0;}}},{key:"_onLevelSwitch",value:function _onLevelSwitch(e,i){this.levels.length||this._fillLevels(),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_END),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH,i);var s=this._hls.levels[i.level];s&&(this.highDefinition=s.height>=720||s.bitrate/1e3>=2e3,this.trigger(t.Events.PLAYBACK_HIGHDEFINITIONUPDATE,this.highDefinition),this.trigger(t.Events.PLAYBACK_BITRATE,{height:s.height,width:s.width,bandwidth:s.bitrate,bitrate:s.bitrate,level:i.level}));}},{key:"dvrEnabled",get:function get(){return this._durationExcludesAfterLiveSyncPoint&&this._duration>=this._minDvrSize&&this.getPlaybackType()===t.Playback.LIVE;}},{key:"getPlaybackType",value:function getPlaybackType(){return this._playbackType;}},{key:"isSeekEnabled",value:function isSeekEnabled(){return this._playbackType===t.Playback.VOD||this.dvrEnabled;}}],[{key:"HLSJS",get:function get(){return e.default;}}]);}(t.HTML5Video);return u.canPlay=function(t,i){var s=t.split("?")[0].match(/.*\.(.*)$/)||[],r=s.length>1&&"m3u8"===s[1].toLowerCase()||c(i,["application/vnd.apple.mpegurl","application/x-mpegURL"]);return!(!e.default.isSupported()||!r);},u;});//# sourceMappingURL=hlsjs-playback.min.js.map
1
+ function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}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.");}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;}}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}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;}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;}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;}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;}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}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);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}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);}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);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}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);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}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;}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);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}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);}!function(t,e){"object"==(typeof exports==="undefined"?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=e(require("@clappr/core"),require("hls.js")):"function"==typeof define&&define.amd?define(["@clappr/core","hls.js"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).HlsjsPlayback=e(t.Clappr,t.Hls);}(this,function(t,e){var i,s,r,a=Object.create,n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,h=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;if(r=null!=(i=e)?a(h(i)):{},!(e=function(t,e,i,s){if(e&&"object"==_typeof(e)||"function"==typeof e)for(var r,a=l(e),h=0,d=a.length;h<d;h++)r=a[h],_.call(t,r)||r===i||n(t,r,{get:function(t){return e[t];}.bind(null,r),enumerable:!(s=o(e,r))||s.enumerable});return t;}(!s&&i&&i.__esModule&&_.call(i,"default")?r:n(r,"default",{value:i,enumerable:!0}),i)).default)throw new Error("@clappr/hlsjs-playback requires hls.js (^1) to be loaded before it");var _t$Utils=t.Utils,d=_t$Utils.now,c=_t$Utils.listContainsIgnoreCase;t.Events.register("PLAYBACK_FRAGMENT_CHANGED"),t.Events.register("PLAYBACK_FRAGMENT_PARSING_METADATA");var u=/*#__PURE__*/function(_t$HTML5Video){function u(){var _this;_classCallCheck(this,u);for(var _len=arguments.length,t=new Array(_len),_key=0;_key<_len;_key++){t[_key]=arguments[_key];}_this=_callSuper(this,u,[].concat(t)),_this.options.hlsPlayback=_objectSpread(_objectSpread({},_this.defaultOptions),_this.options.hlsPlayback),_this._timeUpdateThrottleDelay=200,_this._timeUpdateFiringRate=.2,_this._durationChangeMinOffset=.5,_this._setInitialState();return _this;}_inherits(u,_t$HTML5Video);return _createClass(u,[{key:"name",get:function get(){return"hls";}},{key:"supportedVersion",get:function get(){return{min:"0.17.1"};}},{key:"levels",get:function get(){return this._levels||[];}},{key:"currentLevel",get:function get(){return null===this._currentLevel||void 0===this._currentLevel?-1:this._currentLevel;},set:function set(e){this._currentLevel=e,this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_START),this.options.playback.hlsUseNextLevel?this._hls.nextLevel=this._currentLevel:this._hls.currentLevel=this._currentLevel;}},{key:"isReady",get:function get(){return this._isReadyState;}},{key:"latency",get:function get(){return this._hls.latency;}},{key:"liveSyncPosition",get:function get(){return this._hls.liveSyncPosition;}},{key:"currentProgramDateTime",get:function get(){return this._hls.playingDate;}},{key:"_startTime",get:function get(){return this._playbackType===t.Playback.LIVE&&"EVENT"!==this._playlistType?this._extrapolatedStartTime:this._playableRegionStartTime;}},{key:"_now",get:function get(){return d();}},{key:"_extrapolatedStartTime",get:function get(){if(!this._localStartTimeCorrelation)return this._playableRegionStartTime;var t=this._localStartTimeCorrelation,e=this._now-t.local,i=(t.remote+e)/1e3;return Math.min(i,this._playableRegionStartTime+this._extrapolatedWindowDuration);}},{key:"_extrapolatedEndTime",get:function get(){var t=this._playableRegionStartTime+this._playableRegionDuration;if(!this._localEndTimeCorrelation)return t;var e=this._localEndTimeCorrelation,i=this._now-e.local,s=(e.remote+i)/1e3;return Math.max(t-this._extrapolatedWindowDuration,Math.min(s,t));}},{key:"_duration",get:function get(){return this._extrapolatedEndTime-this._startTime;}},{key:"_extrapolatedWindowDuration",get:function get(){return null===this._segmentTargetDuration?0:this._extrapolatedWindowNumSegments*this._segmentTargetDuration;}},{key:"bandwidthEstimate",get:function get(){return this._hls&&this._hls.bandwidthEstimate;}},{key:"defaultOptions",get:function get(){return{preload:!0};}},{key:"customListeners",get:function get(){return this.options.hlsPlayback&&this.options.hlsPlayback.customListeners||[];}},{key:"sourceMedia",get:function get(){return this.options.src;}},{key:"currentTimestamp",get:function get(){return this._currentFragment?(this._currentFragment.programDateTime+1e3*(this.el.currentTime-this._currentFragment.start))/1e3:null;}},{key:"_setInitialState",value:function _setInitialState(){var _this$options$hlsReco;this._minDvrSize=void 0===this.options.hlsMinimumDvrSize?60:this.options.hlsMinimumDvrSize,this._extrapolatedWindowNumSegments=this.options.playback&&void 0!==this.options.playback.extrapolatedWindowNumSegments?this.options.playback.extrapolatedWindowNumSegments:2,this._playbackType=t.Playback.VOD,this._lastTimeUpdate={current:0,total:0,firstFragDateTime:0},this._lastTimeUpdateFiredTime=0,this._lastDuration=null,this._playableRegionStartTime=0,this._localStartTimeCorrelation=null,this._localEndTimeCorrelation=null,this._playableRegionDuration=0,this._programDateTime=0,this._durationExcludesAfterLiveSyncPoint=!1,this._segmentTargetDuration=null,this._playlistType=null,this._recoverAttemptsRemaining=(_this$options$hlsReco=this.options.hlsRecoverAttempts)!==null&&_this$options$hlsReco!==void 0?_this$options$hlsReco:16;}},{key:"_setup",value:function _setup(){this._destroyHLSInstance(),this._createHLSInstance(),this._listenHLSEvents(),this._attachHLSMedia();}},{key:"_destroyHLSInstance",value:function _destroyHLSInstance(){this._hls&&(this._manifestLoading=!1,this._ccIsSetup=!1,this._ccTracksUpdated=!1,this._setInitialState(),this._hls.destroy(),this._hls=null);}},{key:"_createHLSInstance",value:function _createHLSInstance(){var t=_objectSpread({},this.options.playback.hlsjsConfig);this._hls=new e.default(t);}},{key:"_attachHLSMedia",value:function _attachHLSMedia(){this._hls&&this._hls.attachMedia(this.el);}},{key:"_listenHLSEvents",value:function _listenHLSEvents(){var _this2=this;this._hls&&(this._hls.once(e.default.Events.MEDIA_ATTACHED,function(){_this2.options.hlsPlayback.preload&&_this2._hls.loadSource(_this2.options.src);}),this._hls.on(e.default.Events.MANIFEST_LOADING,function(){_this2._manifestLoading=!0;}),this._hls.on(e.default.Events.LEVEL_LOADED,function(t,e){return _this2._updatePlaybackType(t,e);}),this._hls.on(e.default.Events.LEVEL_UPDATED,function(t,e){return _this2._onLevelUpdated(t,e);}),this._hls.on(e.default.Events.LEVEL_SWITCHED,function(t,e){return _this2._onLevelSwitch(t,e);}),this._hls.on(e.default.Events.FRAG_CHANGED,function(t,e){return _this2._onFragmentChanged(t,e);}),this._hls.on(e.default.Events.FRAG_LOADED,function(t,e){return _this2._onFragmentLoaded(t,e);}),this._hls.on(e.default.Events.FRAG_BUFFERED,function(t,e){return _this2._onFragmentBuffered(t,e);}),this._hls.on(e.default.Events.FRAG_PARSING_METADATA,function(t,e){return _this2._onFragmentParsingMetadata(t,e);}),this._hls.on(e.default.Events.ERROR,function(t,e){return _this2._onHLSJSError(t,e);}),this._hls.on(e.default.Events.SUBTITLE_TRACK_LOADED,function(t,e){return _this2._onSubtitleLoaded(t,e);}),this._hls.on(e.default.Events.SUBTITLE_TRACKS_UPDATED,function(){return _this2._ccTracksUpdated=!0;}),this.bindCustomListeners());}},{key:"bindCustomListeners",value:function bindCustomListeners(){var _this3=this;this.customListeners.forEach(function(t){var e=t.eventName,i=t.once?"once":"on";e&&_this3._hls["".concat(i)](e,t.callback);});}},{key:"unbindCustomListeners",value:function unbindCustomListeners(){var _this4=this;this.customListeners.forEach(function(t){var e=t.eventName;e&&_this4._hls.off(e,t.callback);});}},{key:"_onFragmentParsingMetadata",value:function _onFragmentParsingMetadata(e,i){this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_PARSING_METADATA,{evt:e,data:i});}},{key:"render",value:function render(){return this._ready(),_superPropGet(u,"render",this,3)([]);}},{key:"_ready",value:function _ready(){this._isReadyState||(!this._hls&&this._setup(),this._isReadyState=!0,this.trigger(t.Events.PLAYBACK_READY,this.name));}},{key:"_recover",value:function _recover(e,i,s){if(this._recoveredDecodingError){if(this._recoveredAudioCodecError){t.Log.error("hlsjs: failed to recover",{evt:e,data:i}),s.level=t.PlayerError.Levels.FATAL;var _r=this.createError(s);this.trigger(t.Events.PLAYBACK_ERROR,_r),this.stop();}else this._recoveredAudioCodecError=!0,this._hls.swapAudioCodec(),this._hls.recoverMediaError(),this.play();}else this._recoveredDecodingError=!0,this._hls.recoverMediaError(),this.play();}},{key:"_setupSrc",value:function _setupSrc(t){}},{key:"_startTimeUpdateTimer",value:function _startTimeUpdateTimer(){var _this5=this;this._timeUpdateTimer||(this._timeUpdateTimer=setInterval(function(){_this5._onDurationChange(),_this5._onTimeUpdate();},100));}},{key:"_stopTimeUpdateTimer",value:function _stopTimeUpdateTimer(){this._timeUpdateTimer&&(clearInterval(this._timeUpdateTimer),this._timeUpdateTimer=null);}},{key:"getProgramDateTime",value:function getProgramDateTime(){return this._programDateTime;}},{key:"getDuration",value:function getDuration(){return this._duration;}},{key:"getFrameRate",value:function getFrameRate(){if(this._hls&&this._hls.levels&&this._hls.currentLevel>=0){var _t=this._hls.levels[this._hls.currentLevel];return _t&&_t.frameRate?_t.frameRate:null;}return null;}},{key:"getCurrentTime",value:function getCurrentTime(){return Math.max(0,this.el.currentTime-this._startTime);}},{key:"getStartTimeOffset",value:function getStartTimeOffset(){return this._startTime;}},{key:"seekPercentage",value:function seekPercentage(t){this.seek(this._duration*(t/100));}},{key:"seek",value:function seek(e){e<0&&(t.Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point."),e=this.getDuration()),e+=this._startTime,this.el.currentTime=e;}},{key:"seekToLivePoint",value:function seekToLivePoint(){this.seek(this.getDuration());}},{key:"_updateSettings",value:function _updateSettings(){this._playbackType===t.Playback.VOD?this.settings.left=["playpause","position","duration"]:this.dvrEnabled?this.settings.left=["playpause"]:this.settings.left=["playstop"],this.settings.seekEnabled=this.isSeekEnabled(),this.trigger(t.Events.PLAYBACK_SETTINGSUPDATE);}},{key:"_onHLSJSError",value:function _onHLSJSError(i,s){var r={code:"".concat(s.type,"_").concat(s.details),description:"".concat(this.name," error: type: ").concat(s.type,", details: ").concat(s.details),raw:s};var a;if(s.response&&(r.description+=", response: ".concat(JSON.stringify(s.response))),s.fatal){if(this._recoverAttemptsRemaining>0)switch(this._recoverAttemptsRemaining-=1,s.type){case e.default.ErrorTypes.NETWORK_ERROR:switch(s.details){case e.default.ErrorDetails.MANIFEST_LOAD_ERROR:case e.default.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case e.default.ErrorDetails.MANIFEST_PARSING_ERROR:case e.default.ErrorDetails.LEVEL_LOAD_ERROR:case e.default.ErrorDetails.LEVEL_LOAD_TIMEOUT:t.Log.error("hlsjs: unrecoverable network fatal error.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),this.stop();break;default:t.Log.warn("hlsjs: trying to recover from network error.",{evt:i,data:s}),r.level=t.PlayerError.Levels.WARN,this._hls.startLoad();}break;case e.default.ErrorTypes.MEDIA_ERROR:t.Log.warn("hlsjs: trying to recover from media error.",{evt:i,data:s}),r.level=t.PlayerError.Levels.WARN,this._recover(i,s,r);break;default:t.Log.error("hlsjs: could not recover from error.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),this.stop();}else t.Log.error("hlsjs: could not recover from error after maximum number of attempts.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),this.stop();}else{if(this.options.playback.triggerFatalErrorOnResourceDenied&&this._keyIsDenied(s))return t.Log.error("hlsjs: could not load decrypt key.",{evt:i,data:s}),a=this.createError(r),this.trigger(t.Events.PLAYBACK_ERROR,a),void this.stop();r.level=t.PlayerError.Levels.WARN,t.Log.warn("hlsjs: non-fatal error occurred",{evt:i,data:s}),this.trigger(t.Events.PLAYBACK_WARNING,r,this.name);}}},{key:"_keyIsDenied",value:function _keyIsDenied(t){return t.type===e.default.ErrorTypes.NETWORK_ERROR&&t.details===e.default.ErrorDetails.KEY_LOAD_ERROR&&t.response&&t.response.code>=400;}},{key:"_onTimeUpdate",value:function _onTimeUpdate(){var e={current:this.getCurrentTime(),total:this.getDuration(),firstFragDateTime:this.getProgramDateTime()};this._shouldThrottleTimeUpdate(e)||(this._lastTimeUpdate=e,this._lastTimeUpdateFiredTime=this._now,this.trigger(t.Events.PLAYBACK_TIMEUPDATE,e,this.name));}},{key:"_shouldThrottleTimeUpdate",value:function _shouldThrottleTimeUpdate(t){var e=Math.abs(t.current-this._lastTimeUpdate.current)<this._timeUpdateFiringRate,i=Math.abs(t.total-this._lastTimeUpdate.total)<this._durationChangeMinOffset,s=t.firstFragDateTime===this._lastTimeUpdate.firstFragDateTime,r=e&&i&&s,a=this._now-this._lastTimeUpdateFiredTime<this._timeUpdateThrottleDelay;return r&&a;}},{key:"_onDurationChange",value:function _onDurationChange(){var t=this.getDuration();Math.abs(this._lastDuration-t)<this._durationChangeMinOffset||(this._lastDuration=t,_superPropGet(u,"_onDurationChange",this,3)([]));}},{key:"_onProgress",value:function _onProgress(){if(!this.el.buffered.length)return;var e=[],i=0;for(var _t2=0;_t2<this.el.buffered.length;_t2++)e=[].concat(_toConsumableArray(e),[{start:Math.max(0,this.el.buffered.start(_t2)-this._playableRegionStartTime),end:Math.max(0,this.el.buffered.end(_t2)-this._playableRegionStartTime)}]),this.el.currentTime>=e[_t2].start&&this.el.currentTime<=e[_t2].end&&(i=_t2);var s={start:e[i].start,current:e[i].end,total:this.getDuration()};this.trigger(t.Events.PLAYBACK_PROGRESS,s,e);}},{key:"load",value:function load(t){this._stopTimeUpdateTimer(),this.options.src=t,this._setup();}},{key:"play",value:function play(){!this._hls&&this._setup(),!this._manifestLoading&&!this.options.hlsPlayback.preload&&this._hls.loadSource(this.options.src),_superPropGet(u,"play",this,3)([]),this._startTimeUpdateTimer();}},{key:"pause",value:function pause(){this._hls&&this.el.pause();}},{key:"stop",value:function stop(){this._stopTimeUpdateTimer(),this._hls&&_superPropGet(u,"stop",this,3)([]),this._destroyHLSInstance();}},{key:"destroy",value:function destroy(){this._stopTimeUpdateTimer(),this._destroyHLSInstance(),_superPropGet(u,"destroy",this,3)([]);}},{key:"_updatePlaybackType",value:function _updatePlaybackType(e,i){this._playbackType=i.details.live?t.Playback.LIVE:t.Playback.VOD,this._onLevelUpdated(e,i),this._ccTracksUpdated&&this._playbackType===t.Playback.LIVE&&this.hasClosedCaptionsTracks&&this._onSubtitleLoaded();}},{key:"_fillLevels",value:function _fillLevels(){this._levels=this._hls.levels.map(function(t,e){return{id:e,level:t,label:t.bitrate/1e3+"Kbps"};}),this.trigger(t.Events.PLAYBACK_LEVELS_AVAILABLE,this._levels);}},{key:"_onLevelUpdated",value:function _onLevelUpdated(i,s){this._segmentTargetDuration=s.details.targetduration,this._playlistType=s.details.type||null;var r=!1,a=!1;var n=s.details.fragments,o=this._playableRegionStartTime,l=this._playableRegionDuration;if(0===n.length)return;if(n[0].rawProgramDateTime&&(this._programDateTime=n[0].rawProgramDateTime),this._playableRegionStartTime!==n[0].start&&(r=!0,this._playableRegionStartTime=n[0].start),r)if(this._localStartTimeCorrelation){var _t3=this._localStartTimeCorrelation,_e=this._now-_t3.local,_i=(_t3.remote+_e)/1e3;_i<n[0].start?this._localStartTimeCorrelation={local:this._now,remote:1e3*n[0].start}:_i>o+this._extrapolatedWindowDuration&&(this._localStartTimeCorrelation={local:this._now,remote:1e3*Math.max(n[0].start,o+this._extrapolatedWindowDuration)});}else this._localStartTimeCorrelation={local:this._now,remote:1e3*(n[0].start+this._extrapolatedWindowDuration/2)};var h=s.details.totalduration;if(this._playbackType===t.Playback.LIVE){var _t4=s.details.targetduration*((this.options.playback.hlsjsConfig||{}).liveSyncDurationCount||e.default.DefaultConfig.liveSyncDurationCount);_t4<=h?(h-=_t4,this._durationExcludesAfterLiveSyncPoint=!0):this._durationExcludesAfterLiveSyncPoint=!1;}h!==this._playableRegionDuration&&(a=!0,this._playableRegionDuration=h);var _=n[0].start+h,d=o+l;if(_!==d)if(this._localEndTimeCorrelation){var _t5=this._localEndTimeCorrelation,_e2=this._now-_t5.local,_i2=(_t5.remote+_e2)/1e3;_i2>_?this._localEndTimeCorrelation={local:this._now,remote:1e3*_}:_i2<_-this._extrapolatedWindowDuration?this._localEndTimeCorrelation={local:this._now,remote:1e3*(_-this._extrapolatedWindowDuration)}:_i2>d&&(this._localEndTimeCorrelation={local:this._now,remote:1e3*d});}else this._localEndTimeCorrelation={local:this._now,remote:1e3*_};a&&this._onDurationChange(),r&&this._onProgress();}},{key:"_onFragmentChanged",value:function _onFragmentChanged(e,i){this._currentFragment=i.frag,this.trigger(t.Events.Custom.PLAYBACK_FRAGMENT_CHANGED,i);}},{key:"_onFragmentLoaded",value:function _onFragmentLoaded(e,i){this.trigger(t.Events.PLAYBACK_FRAGMENT_LOADED,i);}},{key:"_onFragmentBuffered",value:function _onFragmentBuffered(e,i){this.trigger(t.Events.PLAYBACK_FRAGMENT_BUFFERED,i);}},{key:"_onSubtitleLoaded",value:function _onSubtitleLoaded(){if(!this._ccIsSetup){this.trigger(t.Events.PLAYBACK_SUBTITLE_AVAILABLE);var _e3=this._playbackType===t.Playback.LIVE?-1:this.closedCaptionsTrackId;this.closedCaptionsTrackId=_e3,this._ccIsSetup=!0;}}},{key:"_onLevelSwitch",value:function _onLevelSwitch(e,i){this.levels.length||this._fillLevels(),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH_END),this.trigger(t.Events.PLAYBACK_LEVEL_SWITCH,i);var s=this._hls.levels[i.level];s&&(this.highDefinition=s.height>=720||s.bitrate/1e3>=2e3,this.trigger(t.Events.PLAYBACK_HIGHDEFINITIONUPDATE,this.highDefinition),this.trigger(t.Events.PLAYBACK_BITRATE,{height:s.height,width:s.width,bandwidth:s.bitrate,bitrate:s.bitrate,level:i.level}));}},{key:"dvrEnabled",get:function get(){return this._durationExcludesAfterLiveSyncPoint&&this._duration>=this._minDvrSize&&this.getPlaybackType()===t.Playback.LIVE;}},{key:"getPlaybackType",value:function getPlaybackType(){return this._playbackType;}},{key:"isSeekEnabled",value:function isSeekEnabled(){return this._playbackType===t.Playback.VOD||this.dvrEnabled;}}],[{key:"HLSJS",get:function get(){return e.default;}}]);}(t.HTML5Video);return u.canPlay=function(t,i){var s=t.split("?")[0].match(/.*\.(.*)$/)||[],r=s.length>1&&"m3u8"===s[1].toLowerCase()||c(i,["application/vnd.apple.mpegurl","application/x-mpegURL"]);return!(!e.default.isSupported()||!r);},u;});//# sourceMappingURL=hlsjs-playback.min.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clappr/hlsjs-playback",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "HLS Playback based on hls.js",
5
5
  "main": "./dist/hlsjs-playback.js",
6
6
  "module": "./dist/hlsjs-playback.esm.js",
@@ -40,7 +40,7 @@
40
40
  "hls.js": "^1"
41
41
  },
42
42
  "devDependencies": {
43
- "@clappr/core": "^0.17.0",
43
+ "@clappr/core": "^0.17.1",
44
44
  "hls.js": "^1"
45
45
  }
46
46
  }