@playkit-js/playkit-js-hls 1.31.0 → 1.31.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.31.1](https://github.com/kaltura/playkit-js-hls/compare/v1.31.0...v1.31.1) (2022-11-02)
6
+
7
+
8
+
5
9
  ## [1.31.0](https://github.com/kaltura/playkit-js-hls/compare/v1.30.2...v1.31.0) (2022-10-03)
6
10
 
7
11
 
@@ -1,2 +1,2 @@
1
- !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("@playkit-js/playkit-js"),require("hls.js")):"function"==typeof define&&define.amd?define("hls",["playkit-js","hls.js"],r):"object"==typeof exports?exports.hls=r(require("@playkit-js/playkit-js"),require("hls.js")):(e.playkit=e.playkit||{},e.playkit.hls=r(e.playkit.core,e.Hls))}(window,(function(e,r){return function(e){var r={};function t(i){if(r[i])return r[i].exports;var a=r[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:i})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var a in e)t.d(i,a,function(r){return e[r]}.bind(null,a));return i},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=3)}([function(r,t){r.exports=e},function(e,t){e.exports=r},function(e){e.exports=JSON.parse('{"recoverDecodingErrorDelay":3000,"recoverSwapAudioCodecDelay":3000,"abr":{"enabled":true,"restrictions":{}},"hlsConfig":{"fragLoadingMaxRetry":4,"maxMaxBufferLength":60},"network":{}}')},function(e,r,t){"use strict";t.r(r),t.d(r,"VERSION",(function(){return y})),t.d(r,"NAME",(function(){return R}));var i,a=t(0),o=t(1),n=t.n(o),s=t(2),l=((i={})[n.a.ErrorDetails.MANIFEST_LOAD_ERROR]={category:a.Error.Category.MANIFEST,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT]={category:a.Error.Category.MANIFEST,code:a.Error.Code.TIMEOUT},i[n.a.ErrorDetails.MANIFEST_PARSING_ERROR]={category:a.Error.Category.MANIFEST,code:a.Error.Code.HLSJS_CANNOT_PARSE},i[n.a.ErrorDetails.LEVEL_LOAD_ERROR]={category:a.Error.Category.NETWORK,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.LEVEL_LOAD_TIMEOUT]={category:a.Error.Category.NETWORK,code:a.Error.Code.TIMEOUT},i[n.a.ErrorDetails.LEVEL_SWITCH_ERROR]={category:a.Error.Category.PLAYER,code:a.Error.Code.BITRATE_SWITCH_ISSUE},i[n.a.ErrorDetails.FRAG_LOAD_ERROR]={category:a.Error.Category.NETWORK,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.FRAG_LOOP_LOADING_ERROR]={category:a.Error.Category.NETWORK,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.FRAG_LOAD_TIMEOUT]={category:a.Error.Category.NETWORK,code:a.Error.Code.TIMEOUT},i[n.a.ErrorDetails.FRAG_PARSING_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_FRAG_PARSING_ERROR},i[n.a.ErrorDetails.BUFFER_APPEND_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_BUFFER_APPEND_ISSUE},i[n.a.ErrorDetails.BUFFER_APPENDING_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_BUFFER_APPENDING_ISSUE},i[n.a.ErrorDetails.BUFFER_STALLED_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_BUFFER_STALLED_ERROR},i);var c=function(e){var r,t;function i(r){var t;return t=e.call(this,r)||this,r&&r.readystatechange&&(t.readystatechange=r.readystatechange),t}return t=e,(r=i).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,i.prototype.loadInternal=function(){var e,r=this,t=this.context;e=this.loader=new XMLHttpRequest;var i=this.stats;i.tfirst=0,i.loaded=0;var a,o=this.xhrSetup;try{if(o)try{a=o(e,t.url,t)}catch(r){e.open("GET",t.url,!0),a=o(e,t.url,t)}e.readyState||e.open("GET",t.url,!0)}catch(e){a=Promise.reject(e)}(a=a||Promise.resolve()).then((function(){t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=r.readystatechange.bind(r),e.onprogress=r.loadprogress.bind(r),e.responseType=t.responseType,r.requestTimeout=window.setTimeout(r.loadtimeout.bind(r),r.config.timeout),e.send()})).catch((function(i){r.callbacks.onError({code:e.status,text:i.message},t,e)}))},i}(n.a.DefaultConfig.loader);var d,h,u,_=function(e){var r,t;function i(r){var t,o=(t=e.call(this,r)||this).load.bind(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)),n=i.redirectExternalStreamsHandler;return t.load=function(e,r,t){var s=e.url;"manifest"===e.type?a.Utils.Http.jsonp(s,n,{timeout:i.redirectExternalStreamsTimeout}).then((function(i){e.url=i,o(e,r,t)})).catch((function(){return o(e,r,t)})):o(e,r,t)},t}return t=e,(r=i).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,i}(c);function E(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(!e)return;if("string"==typeof e)return g(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return g(e,r)}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}function g(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,i=new Array(r);t<r;t++)i[t]=e[t];return i}function f(e,r){for(var t=0;t<r.length;t++){var i=r[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}u=function(e,r){return r},(h="redirectExternalStreamsHandler")in(d=_)?Object.defineProperty(d,h,{value:u,enumerable:!0,configurable:!0,writable:!0}):d[h]=u;var T=function(e){var r,t;function i(r,t,o){var l,c;return i._logger.debug("Creating adapter. Hls version: "+n.a.version),v(p(c=e.call(this,r,t,o)||this),"_hlsjsLib",n.a),v(p(c),"_triedReloadWithRedirect",!1),v(p(c),"_playerTracks",[]),v(p(c),"_startTime",0),v(p(c),"_requestFilterError",!1),v(p(c),"_responseFilterError",!1),v(p(c),"_nativeTextTracksMap",{}),v(p(c),"_lastLoadedFragSN",-1),v(p(c),"_sameFragSNLoadedCount",0),v(p(c),"_adapterEventsBindings",((l={})[n.a.Events.ERROR]=function(e,r){return c._onError(r)},l[n.a.Events.MANIFEST_LOADED]=function(e,r){return c._onManifestLoaded(r)},l[n.a.Events.LEVEL_SWITCHED]=function(e,r){return c._onLevelSwitched(e,r)},l[n.a.Events.AUDIO_TRACK_SWITCHED]=function(e,r){return c._onAudioTrackSwitched(e,r)},l[n.a.Events.FPS_DROP]=function(e,r){return c._onFpsDrop(r)},l[n.a.Events.FRAG_PARSING_METADATA]=function(e,r){return c._onFragParsingMetadata(r)},l[n.a.Events.FRAG_LOADED]=function(e,r){return c._onFragLoaded(r)},l[n.a.Events.MEDIA_ATTACHED]=function(){return c._onMediaAttached()},l[n.a.Events.LEVEL_LOADED]=function(e,r){return c._onLevelLoaded(e,r)},l)),v(p(c),"_onLevelLoaded",(function(e,r){if(c.isLive()){var t=r.details.endSN;if(c._lastLoadedFragSN===t){if(c._sameFragSNLoadedCount++,i._logger.debug("Same frag SN. Count is: "+c._sameFragSNLoadedCount+", Max is: "+c._config.network.maxStaleLevelReloads),c._sameFragSNLoadedCount>=c._config.network.maxStaleLevelReloads){i._logger.error("Same frag loading reached max count");var o=new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.NETWORK,a.Error.Code.LIVE_MANIFEST_REFRESH_ERROR,{fragSN:t});return c._trigger(a.EventType.ERROR,o),c.destroy()}i._logger.debug("Last frag SN is: "+t)}else c._sameFragSNLoadedCount=0;c._lastLoadedFragSN=t}})),c._config=a.Utils.Object.mergeDeep({},s,c._config),c._init(),c}t=e,(r=i).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,i.createAdapter=function(e,r,t){var i=a.Utils.Object.copyDeep(s);if(a.Utils.Object.hasPropertyPath(t,"sources.options")){var o=t.sources.options;i.forceRedirectExternalStreams=o.forceRedirectExternalStreams,i.redirectExternalStreamsHandler=o.redirectExternalStreamsHandler,i.redirectExternalStreamsTimeout=o.redirectExternalStreamsTimeout,_.redirectExternalStreamsHandler=i.redirectExternalStreamsHandler,_.redirectExternalStreamsTimeout=i.redirectExternalStreamsTimeout}a.Utils.Object.hasPropertyPath(t,"sources.startTime")&&(a.Utils.Object.getPropertyPath(t,"sources.startTime")>-1&&(i.hlsConfig.startPosition=t.sources.startTime));if(a.Utils.Object.hasPropertyPath(t,"text.useNativeTextTrack")&&(i.subtitleDisplay=a.Utils.Object.getPropertyPath(t,"text.useNativeTextTrack")),a.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedFramesInterval")&&(i.hlsConfig.fpsDroppedFramesInterval=t.abr.fpsDroppedFramesInterval),a.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedMonitoringThreshold")&&(i.hlsConfig.fpsDroppedMonitoringThreshold=t.abr.fpsDroppedMonitoringThreshold),a.Utils.Object.hasPropertyPath(t,"abr.capLevelOnFPSDrop")&&(i.hlsConfig.capLevelOnFPSDrop=t.abr.capLevelOnFPSDrop),a.Utils.Object.hasPropertyPath(t,"text")&&(i.hlsConfig.enableCEA708Captions=t.text.enableCEA708Captions,i.hlsConfig.captionsTextTrack1Label=t.text.captionsTextTrack1Label,i.hlsConfig.captionsTextTrack1LanguageCode=t.text.captionsTextTrack1LanguageCode,i.hlsConfig.captionsTextTrack2Label=t.text.captionsTextTrack2Label,i.hlsConfig.captionsTextTrack2LanguageCode=t.text.captionsTextTrack2LanguageCode),a.Utils.Object.hasPropertyPath(t,"abr")){var n=t.abr;"boolean"==typeof n.enabled&&(i.abr.enabled=n.enabled),"boolean"==typeof n.capLevelToPlayerSize&&(i.hlsConfig.capLevelToPlayerSize=n.capLevelToPlayerSize),n.defaultBandwidthEstimate&&(i.hlsConfig.abrEwmaDefaultEstimate=n.defaultBandwidthEstimate),n.restrictions&&a.Utils.Object.createPropertyPath(i,"abr.restrictions",n.restrictions)}return a.Utils.Object.hasPropertyPath(t,"streaming.lowLatencyMode")&&(i.hlsConfig.lowLatencyMode=a.Utils.Object.getPropertyPath(t,"streaming.lowLatencyMode")),a.Utils.Object.hasPropertyPath(t,"playback.options.html5.hls")&&a.Utils.Object.mergeDeep(i.hlsConfig,t.playback.options.html5.hls),i.network=t.network,new this(e,r,i)},i.canPlayType=function(e){var r="string"==typeof e&&(i._hlsMimeTypes.includes(e.toLowerCase())&&i.isMSESupported());return i._logger.debug("canPlayType result for mimeType:"+e+" is "+r.toString()),r},i.canPlayDrm=function(){return i._logger.warn("canPlayDrm result is false"),!1},i.isSupported=function(){var e=n.a.isSupported();return i._logger.debug("isSupported:"+e),e};var o,d,h,u=i.prototype;return u._init=function(){this._config.forceRedirectExternalStreams&&(this._config.hlsConfig.pLoader=_),this._maybeSetFilters(),this._hls=new n.a(this._config.hlsConfig),this._capabilities.fpsControl=!0,this._hls.subtitleDisplay=this._config.subtitleDisplay,this._addBindings()},u._maybeSetFilters=function(){var e=this;if("function"==typeof a.Utils.Object.getPropertyPath(this._config,"network.requestFilter")&&(i._logger.debug("Register request filter"),a.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:c,xhrSetup:function(r,t,i){var o,n={url:t,body:null,headers:{}};try{"manifest"===i.type&&(o=e._config.network.requestFilter(a.RequestType.MANIFEST,n)),i.frag&&"subtitle"!==i.frag.type&&(o=e._config.network.requestFilter(a.RequestType.SEGMENT,n))}catch(e){o=Promise.reject(e)}return(o=o||Promise.resolve(n)).then((function(e){i.url=e.url,r.open("GET",e.url,!0),Object.entries(e.headers).forEach((function(e){r.setRequestHeader.apply(r,e)})),"boolean"==typeof e.withCredentials&&(r.withCredentials=e.withCredentials)})).catch((function(r){throw e._requestFilterError=!0,r}))}})),"function"==typeof a.Utils.Object.getPropertyPath(this._config,"network.responseFilter")){var r=this;i._logger.debug("Register response filter"),a.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:c,readystatechange:function(e){var t=this,o=e.currentTarget,n=o.readyState,s=this.stats,l=this.context,c=this.config;if(!s.aborted&&n>=2){window.clearTimeout(this.requestTimeout);var d=s.loading;if(0===d.first&&(d.first=Math.max(performance.now(),d.start)),4===n){var h=o.status;if(h>=200&&h<300){var u,_;d.end=Math.max(s.tfirst,performance.now()),_="arraybuffer"===l.responseType?(u=o.response).byteLength:(u=o.responseText).length,s.loaded=s.total=_;var E,g={url:o.responseURL,originalUrl:l.url,data:u,headers:a.Utils.Http.convertHeadersToDictionary(o.getAllResponseHeaders())};try{"manifest"===l.type&&(E=r._config.network.responseFilter(a.RequestType.MANIFEST,g)),l.frag&&"subtitle"!==l.frag.type&&(E=r._config.network.responseFilter(a.RequestType.SEGMENT,g))}catch(e){E=Promise.reject(e)}return(E=E||Promise.resolve(g)).then((function(e){t.callbacks.onSuccess(e,s,l,o)})).catch((function(e){r._responseFilterError=!0,t.callbacks.onError({code:h,text:e.message},l,o)}))}s.retry>=c.maxRetry||h>=400&&h<499?(i._logger.error(h+" while loading "+l.url),this.callbacks.onError({code:h,text:o.statusText},l,o)):(i._logger.warn(h+" while loading "+l.url+", retrying in "+this.retryDelay+"..."),this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,c.maxRetryDelay),s.retry++)}else this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),c.timeout)}}})}},u._addBindings=function(){var e=this;this._mediaAttachedPromise=new Promise((function(r){return e._onMediaAttached=r}));for(var r=0,t=Object.entries(this._adapterEventsBindings);r<t.length;r++){var i=t[r],a=i[0],o=i[1];this._hls.on(a,o)}this._onRecoveredCallback=function(){return e._onRecovered()},this._onAddTrack=this._onAddTrack.bind(this),this._eventManager.listen(this._videoElement,"addtrack",this._onAddTrack),this._videoElement.textTracks.onaddtrack=this._onAddTrack},u._onFpsDrop=function(e){this._trigger(a.EventType.FPS_DROP,e)},u._onFragParsingMetadata=function(e){var r;this._trigger("hlsFragParsingMetadata",e);var t=Array.from(null==(r=this._videoElement)?void 0:r.textTracks).find((function(e){return"id3"===e.label})),i=Array.from((null==t?void 0:t.cues)||[]),o=[];null==e||e.samples.forEach((function(e){var r=a.Utils.binarySearch(i,(function(r){return r.startTime-e.pts}));if(r){var t=Object(a.createTimedMetadata)(r);o.push(t)}})),o.length&&this._trigger(a.EventType.TIMED_METADATA_ADDED,{cues:o})},u._onAddTrack=function(e){if(!this._hls.subtitleTracks.length){var r=this._parseCEATextTrack(e.track);r&&(i._logger.debug("A CEA 608/708 caption has been found",r),this._playerTracks.push(r),this._trigger(a.EventType.TRACKS_CHANGED,{tracks:this._playerTracks}))}},u.attachMediaSource=function(){this._hls||(this._videoElement&&this._videoElement.src&&(a.Utils.Dom.setAttribute(this._videoElement,"src",""),a.Utils.Dom.removeAttribute(this._videoElement,"src")),this._init())},u.detachMediaSource=function(){var e;this._hls&&(0===Math.floor(this.duration-this.currentTime)?this._config.hlsConfig.startPosition=0:this.currentTime>0&&(this._config.hlsConfig.startPosition=this.currentTime),this._reset(),null==(e=this._loadPromiseHandlers)||e.reject(new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,"media detached while loading")),this._loadPromiseHandlers=null,this._loadPromise=null,this._hls=null)},u.handleMediaError=function(e){return e.code===e.MEDIA_ERR_DECODE&&(i._logger.debug("The video playback was aborted due to a corruption problem or because the video used features your browser did not support.",e.message),this._handleMediaError())},u.load=function(e){var r=this;return this._loadPromise||(this._startTime=e,this._loadPromise=new Promise((function(e,t){r._loadPromiseHandlers={resolve:e,reject:t},r._loadInternal()}))),this._loadPromise},u._loadInternal=function(){var e;this._hls&&this._sourceObj&&this._sourceObj.url?(this._hls.loadSource(this._sourceObj.url),this._hls.attachMedia(this._videoElement),this._trigger(a.EventType.ABR_MODE_CHANGED,{mode:this.isAdaptiveBitrateEnabled()?"auto":"manual"})):null==(e=this._loadPromiseHandlers)||e.reject(new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,"no url provided"))},u._reloadWithDirectManifest=function(){this._triedReloadWithRedirect=!0,this._reset(),this._config.hlsConfig.pLoader=_,this._hls=new n.a(this._config.hlsConfig),this._addBindings(),this._loadInternal()},u.destroy=function(){var r=this;return new Promise((function(t,o){e.prototype.destroy.call(r).then((function(){var e;i._logger.debug("destroy"),r._playerTracks=[],r._nativeTextTracksMap={},r._sameFragSNLoadedCount=0,r._lastLoadedFragSN=-1,null==(e=r._loadPromiseHandlers)||e.reject(new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,"The adapter has been destroyed while loading")),r._loadPromiseHandlers=null,r._loadPromise=null,r._reset(),t()}),(function(){return o()}))}))},u._reset=function(){this._removeBindings(),this._requestFilterError=!1,this._responseFilterError=!1,this._hls.detachMedia(),this._hls.destroy()},u._parseTracks=function(){var e=this._parseAudioTracks(this._hls.audioTracks||[]),r=this._parseVideoTracks(this._hls.levels||[]),t=this._parseTextTracks(this._hls.subtitleTracks||[]);return e.concat(r).concat(t)},u._parseAudioTracks=function(e){for(var r=[],t=0;t<e.length;t++){var i={id:e[t].id,active:this._hls.audioTrack===e[t].id,label:e[t].name,language:e[t].lang,index:t};r.push(new a.AudioTrack(i))}return r},u._parseVideoTracks=function(e){for(var r=[],t=0;t<e.length;t++){var i={active:this._hls.startLevel===t,bandwidth:e[t].bitrate,width:e[t].width,height:e[t].height,language:"",index:t};r.push(new a.VideoTrack(i))}return r},u._parseTextTracks=function(e){for(var r,t=[],i=E(e);!(r=i()).done;){var o=r.value,n={id:o.id,active:o.default,label:o.name,kind:o.type.toLowerCase(),language:o.lang};t.push(new a.TextTrack(n))}return t},u._parseCEATextTrack=function(e){var r=null;if("captions"===e.kind){var t={id:e.id,active:"showing"===e.mode,label:e.label,kind:e.kind,language:e.language};r=new a.TextTrack(t),this._nativeTextTracksMap[r.index]=e}return r},u.selectAudioTrack=function(e){e instanceof a.AudioTrack&&!e.active&&this._hls.audioTracks&&(this._hls.audioTrack=e.id)},u.selectVideoTrack=function(e){e instanceof a.VideoTrack&&(!e.active||this.isAdaptiveBitrateEnabled())&&this._hls.levels&&(this.isAdaptiveBitrateEnabled()&&this._trigger(a.EventType.ABR_MODE_CHANGED,{mode:"manual"}),this._hls.currentLevel=e.index)},u.selectTextTrack=function(e){e instanceof a.TextTrack&&!e.active&&this._hls&&(this._hls.subtitleTracks.length?(this._hls.subtitleTrack=e.id,this._notifyTrackChanged(e)):this._selectNativeTextTrack(e))},u._selectNativeTextTrack=function(e){var r=this._nativeTextTracksMap[e.index];r&&(this.disableNativeTextTracks(),r.mode=this._config.subtitleDisplay?"showing":"hidden",this._notifyTrackChanged(e))},u._notifyTrackChanged=function(e){this._onTrackChanged(e)},u.hideTextTrack=function(){this._hls&&(this._hls.subtitleTracks.length?this._hls.subtitleTrack=-1:this.disableNativeTextTracks())},u.enableAdaptiveBitrate=function(){this.isAdaptiveBitrateEnabled()||(this._trigger(a.EventType.ABR_MODE_CHANGED,{mode:"auto"}),this._hls.nextLevel=-1)},u.isAdaptiveBitrateEnabled=function(){return!!this._hls&&this._hls.autoLevelEnabled},u.applyABRRestriction=function(e){a.Utils.Object.createPropertyPath(this._config,"abr.restrictions",e),this._hls.capLevelToPlayerSize||this._maybeApplyAbrRestrictions(e)},u._getLevelDetails=function(){var e=this._hls.levels[this._hls.currentLevel]||this._hls.levels[this._hls.nextLevel]||this._hls.levels[this._hls.nextAutoLevel]||this._hls.levels[this._hls.nextLoadLevel];return e&&e.details?e.details:{}},u._getLiveEdge=function(){try{var e;return(e=this._hls.liveSyncPosition?this._hls.liveSyncPosition:this._hls.config.liveSyncDuration?this._videoElement.duration-this._hls.config.liveSyncDuration:this._videoElement.duration-this._hls.config.liveSyncDurationCount*this._getLevelDetails().targetduration)>0?e:this._videoElement.duration}catch(e){return i._logger.debug("Live edge calculation failed, fall back to duration"),this._videoElement.duration}},u.seekToLiveEdge=function(){try{this._videoElement.currentTime=this._getLiveEdge()}catch(e){return}},u.getSegmentDuration=function(){var e=a.Utils.Object.getPropertyPath(this._hls,"streamController.fragCurrent");return e?e.duration:0},u.isLive=function(){try{return!!this._getLevelDetails().live}catch(e){return!1}},u._onManifestLoaded=function(e){var r=this;i._logger.debug("The source has been loaded successfully"),this._hls.config.autoStartLoad||this._hls.startLoad(this._startTime),this._playerTracks=this._parseTracks(),this._config.abr.enabled||(this._hls.currentLevel=0),this._mediaAttachedPromise.then((function(){var e;null==(e=r._loadPromiseHandlers)||e.resolve({tracks:r._playerTracks}),r._loadPromiseHandlers=null}));var t=e.stats.loading,o=t.end-t.start;this._trigger(a.EventType.MANIFEST_LOADED,{miliSeconds:o})},u._maybeApplyAbrRestrictions=function(e){var r=this._playerTracks.filter((function(e){return e instanceof a.VideoTrack})),t=Object(a.filterTracksByRestriction)(r,e);if(t.length){var o=t[0],n=t.pop();this._hls.config.minAutoBitrate=o.bandwidth,this._hls.autoLevelCapping=n.index;var s=t.some((function(e){return e.active}));this.isAdaptiveBitrateEnabled()||s||this.selectVideoTrack(o)}else i._logger.warn("Invalid restrictions, there are not tracks within the restriction range")},u._onLevelSwitched=function(e,r){var t=this._playerTracks.find((function(e){return e instanceof a.VideoTrack&&e.index===r.level}));this._onTrackChanged(t)},u._onAudioTrackSwitched=function(e,r){var t=this._playerTracks.find((function(e){return e instanceof a.AudioTrack&&e.id===r.id}));this._onTrackChanged(t),this._handleWaitingUponAudioTrackSwitch()},u._handleWaitingUponAudioTrackSwitch=function(){var e=this;if(["IE","Edge"].includes(a.Env.browser.name)){this._eventManager.listenOnce(this._videoElement,a.EventType.TIME_UPDATE,(function(){e._trigger(a.EventType.PLAYING)}))}},u._getErrorDataObject=function(e){var r={};switch(r.name=e.details,r.name){case n.a.ErrorDetails.MANIFEST_LOAD_ERROR:case n.a.ErrorDetails.LEVEL_LOAD_ERROR:case n.a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:r.url=e.url,r.responseCode=e.response?e.response.code:null;break;case n.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case n.a.ErrorDetails.LEVEL_LOAD_TIMEOUT:case n.a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:r.url=e.url;break;case n.a.ErrorDetails.MANIFEST_PARSING_ERROR:r.url=e.url,r.reason=e.reason;break;case n.a.ErrorDetails.LEVEL_SWITCH_ERROR:r.level=e.level,r.reason=e.reason;break;case n.a.ErrorDetails.FRAG_LOAD_ERROR:r.fragUrl=e.frag?e.frag.url:null,r.responseCode=e.response?e.response.code:null;break;case n.a.ErrorDetails.FRAG_LOAD_TIMEOUT:r.fragUrl=e.frag?e.frag.url:null;break;case n.a.ErrorDetails.FRAG_DECRYPT_ERROR:case n.a.ErrorDetails.FRAG_PARSING_ERROR:r.reason=e.reason;break;case n.a.ErrorDetails.KEY_LOAD_ERROR:r.fragDecryptedDataUri=e.frag&&e.frag.decryptdata?e.frag.decryptdata.uri:null,r.responseCode=e.response?e.response.code:null;break;case n.a.ErrorDetails.KEY_LOAD_TIMEOUT:r.fragDecryptedDataUri=e.frag&&e.frag.decryptdata?e.frag.decryptdata.uri:null;break;case n.a.ErrorDetails.BUFFER_ADD_CODEC_ERROR:r.mimeType=e.mimeType,r.errorMsg=e.err?e.err.message:null;break;case n.a.ErrorDetails.BUFFER_STALLED_ERROR:r.buffer=e.buffer}return(this._requestFilterError||this._responseFilterError)&&(r.reason=e.response.text),r},u._onError=function(e){var r=e.type,t=e.details,o=e.fatal,s=this._getErrorDataObject(e);if(o){var c;switch(r){case n.a.ErrorTypes.NETWORK_ERROR:var d;d=this._requestFilterError?a.Error.Code.REQUEST_FILTER_ERROR:this._responseFilterError?a.Error.Code.RESPONSE_FILTER_ERROR:a.Error.Code.HTTP_ERROR,![n.a.ErrorDetails.MANIFEST_LOAD_ERROR,n.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT].includes(t)||this._triedReloadWithRedirect||this._config.forceRedirectExternalStreams||this._requestFilterError||this._responseFilterError?c=new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.NETWORK,d,s):(c=new a.Error(a.Error.Severity.RECOVERABLE,a.Error.Category.NETWORK,d,s),this._reloadWithDirectManifest());break;case n.a.ErrorTypes.MEDIA_ERROR:c=this._handleMediaError()?new a.Error(a.Error.Severity.RECOVERABLE,a.Error.Category.MEDIA,a.Error.Code.HLS_FATAL_MEDIA_ERROR,s):new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.MEDIA,a.Error.Code.HLS_FATAL_MEDIA_ERROR,s);break;default:c=new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,s)}if(this._trigger(a.EventType.ERROR,c),c&&c.severity===a.Error.Severity.CRITICAL){var h;if(this._loadPromiseHandlers)null==(h=this._loadPromiseHandlers)||h.reject(c),this._loadPromiseHandlers=null,this._loadPromise=null;this.destroy()}}else{var u=this._requestFilterError||this._responseFilterError?{category:a.Error.Category.NETWORK,code:this._requestFilterError?a.Error.Code.REQUEST_FILTER_ERROR:a.Error.Code.RESPONSE_FILTER_ERROR}:l[t]||{category:0,code:0},_=u.category,E=u.code;i._logger.warn(new a.Error(a.Error.Severity.RECOVERABLE,_,E,s))}this._requestFilterError=!1,this._responseFilterError=!1},u._handleMediaError=function(){var e=performance.now(),r=!0;return this._checkTimeDeltaHasPassed(e,this._recoverDecodingErrorDate,this._config.recoverDecodingErrorDelay)?(this._eventManager.listen(this._videoElement,a.EventType.LOADED_METADATA,this._onRecoveredCallback),this._recoverDecodingError()):this._checkTimeDeltaHasPassed(e,this._recoverSwapAudioCodecDate,this._config.recoverSwapAudioCodecDelay)?(this._eventManager.listen(this._videoElement,a.EventType.LOADED_METADATA,this._onRecoveredCallback),this._recoverSwapAudioCodec()):(r=!1,i._logger.error("cannot recover, last media error recovery failed")),r},u._onRecovered=function(){this._trigger(a.EventType.MEDIA_RECOVERED),this._videoElement.removeEventListener(a.EventType.LOADED_METADATA,this._onRecoveredCallback)},u._checkTimeDeltaHasPassed=function(e,r,t){return!r||e-r>t},u._recoverDecodingError=function(){this._recoverDecodingErrorDate=performance.now(),i._logger.warn("try to recover media Error"),this._hls.recoverMediaError()},u._recoverSwapAudioCodec=function(){this._recoverSwapAudioCodecDate=performance.now(),i._logger.warn("try to swap Audio Codec and recover media Error"),this._hls.swapAudioCodec(),this._hls.recoverMediaError()},u._removeBindings=function(){for(var e=0,r=Object.entries(this._adapterEventsBindings);e<r.length;e++){var t=r[e],i=t[0],a=t[1];this._hls.off(i,a)}this._videoElement.textTracks.onaddtrack=null,this._onRecoveredCallback=null,this._eventManager&&this._eventManager.removeAll()},u.getStartTimeOfDvrWindow=function(){if(!this.isLive())return 0;try{var e=this._hls.levels[this._hls.nextLoadLevel].details,r=e.fragments,t=r.length,a=r[0].start+r[0].duration,o=r[t-1].start+r[t-1].duration,n=void 0!==this._hls.config.liveMaxLatencyDuration?this._hls.config.liveMaxLatencyDuration:this._hls.config.liveMaxLatencyDurationCount*e.targetduration;return Math.max(a-this._hls.config.maxFragLookUpTolerance,o-n)}catch(e){return i._logger.debug("Unable obtain the start of DVR window"),0}},u._onFragLoaded=function(e){if(a.Utils.Object.hasPropertyPath(e,"frag.stats.loading")){var r=e.frag.stats,t=r.loading.end-r.loading.start;this._trigger(a.EventType.FRAG_LOADED,{miliSeconds:t,bytes:r.loaded,url:e.frag.url})}},u._getLiveTargetBuffer=function(){return this._hls.config.liveSyncDuration?this._hls.config.liveSyncDuration:this._hls.config.liveSyncDurationCount*this._getLevelDetails().targetduration},o=i,(d=[{key:"liveDuration",get:function(){return this._getLiveEdge()+this.getSegmentDuration()}},{key:"targetBuffer",get:function(){var e=NaN;return this._hls?(e=this.isLive()?this._getLiveTargetBuffer()-(this._videoElement.currentTime-this._getLiveEdge()):this._videoElement.duration-this._videoElement.currentTime,e=Math.min(e,this._hls.config.maxMaxBufferLength+this._getLevelDetails().targetduration)):NaN}}])&&f(o.prototype,d),h&&f(o,h),i}(a.BaseMediaSourceAdapter);v(T,"id","HlsAdapter"),v(T,"_logger",a.BaseMediaSourceAdapter.getLogger(T.id)),v(T,"_hlsMimeTypes",["application/x-mpegurl","application/vnd.apple.mpegurl","audio/mpegurl","audio/x-mpegurl","video/x-mpegurl","video/mpegurl","application/mpegurl"]);var y="1.31.0",R="@playkit-js/playkit-js-hls";r.default=T;T.isSupported()&&Object(a.registerMediaSourceAdapter)(T)}])}));
1
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("@playkit-js/playkit-js"),require("hls.js")):"function"==typeof define&&define.amd?define("hls",["playkit-js","hls.js"],r):"object"==typeof exports?exports.hls=r(require("@playkit-js/playkit-js"),require("hls.js")):(e.playkit=e.playkit||{},e.playkit.hls=r(e.playkit.core,e.Hls))}(window,(function(e,r){return function(e){var r={};function t(i){if(r[i])return r[i].exports;var a=r[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:i})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var a in e)t.d(i,a,function(r){return e[r]}.bind(null,a));return i},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=3)}([function(r,t){r.exports=e},function(e,t){e.exports=r},function(e){e.exports=JSON.parse('{"recoverDecodingErrorDelay":3000,"recoverSwapAudioCodecDelay":3000,"abr":{"enabled":true,"restrictions":{}},"hlsConfig":{"fragLoadingMaxRetry":4,"maxMaxBufferLength":60},"network":{}}')},function(e,r,t){"use strict";t.r(r),t.d(r,"VERSION",(function(){return y})),t.d(r,"NAME",(function(){return R}));var i,a=t(0),o=t(1),n=t.n(o),s=t(2),l=((i={})[n.a.ErrorDetails.MANIFEST_LOAD_ERROR]={category:a.Error.Category.MANIFEST,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT]={category:a.Error.Category.MANIFEST,code:a.Error.Code.TIMEOUT},i[n.a.ErrorDetails.MANIFEST_PARSING_ERROR]={category:a.Error.Category.MANIFEST,code:a.Error.Code.HLSJS_CANNOT_PARSE},i[n.a.ErrorDetails.LEVEL_LOAD_ERROR]={category:a.Error.Category.NETWORK,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.LEVEL_LOAD_TIMEOUT]={category:a.Error.Category.NETWORK,code:a.Error.Code.TIMEOUT},i[n.a.ErrorDetails.LEVEL_SWITCH_ERROR]={category:a.Error.Category.PLAYER,code:a.Error.Code.BITRATE_SWITCH_ISSUE},i[n.a.ErrorDetails.FRAG_LOAD_ERROR]={category:a.Error.Category.NETWORK,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.FRAG_LOOP_LOADING_ERROR]={category:a.Error.Category.NETWORK,code:a.Error.Code.HTTP_ERROR},i[n.a.ErrorDetails.FRAG_LOAD_TIMEOUT]={category:a.Error.Category.NETWORK,code:a.Error.Code.TIMEOUT},i[n.a.ErrorDetails.FRAG_PARSING_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_FRAG_PARSING_ERROR},i[n.a.ErrorDetails.BUFFER_APPEND_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_BUFFER_APPEND_ISSUE},i[n.a.ErrorDetails.BUFFER_APPENDING_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_BUFFER_APPENDING_ISSUE},i[n.a.ErrorDetails.BUFFER_STALLED_ERROR]={category:a.Error.Category.MEDIA,code:a.Error.Code.HLS_BUFFER_STALLED_ERROR},i);var c=function(e){var r,t;function i(r){var t;return t=e.call(this,r)||this,r&&r.readystatechange&&(t.readystatechange=r.readystatechange),t}return t=e,(r=i).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,i.prototype.loadInternal=function(){var e,r=this,t=this.context;e=this.loader=new XMLHttpRequest;var i=this.stats;i.tfirst=0,i.loaded=0;var a,o=this.xhrSetup;try{if(o)try{a=o(e,t.url,t)}catch(r){e.open("GET",t.url,!0),a=o(e,t.url,t)}e.readyState||e.open("GET",t.url,!0)}catch(e){a=Promise.reject(e)}(a=a||Promise.resolve()).then((function(){t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=r.readystatechange.bind(r),e.onprogress=r.loadprogress.bind(r),e.responseType=t.responseType,r.requestTimeout=window.setTimeout(r.loadtimeout.bind(r),r.config.timeout),e.send()})).catch((function(i){r.callbacks.onError({code:e.status,text:i.message},t,e)}))},i}(n.a.DefaultConfig.loader);var d,h,u,_=function(e){var r,t;function i(r){var t,o=(t=e.call(this,r)||this).load.bind(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(t)),n=i.redirectExternalStreamsHandler;return t.load=function(e,r,t){var s=e.url;"manifest"===e.type?a.Utils.Http.jsonp(s,n,{timeout:i.redirectExternalStreamsTimeout}).then((function(i){e.url=i,o(e,r,t)})).catch((function(){return o(e,r,t)})):o(e,r,t)},t}return t=e,(r=i).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,i}(c);function E(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(!e)return;if("string"==typeof e)return g(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return g(e,r)}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}function g(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,i=new Array(r);t<r;t++)i[t]=e[t];return i}function f(e,r){for(var t=0;t<r.length;t++){var i=r[t];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}u=function(e,r){return r},(h="redirectExternalStreamsHandler")in(d=_)?Object.defineProperty(d,h,{value:u,enumerable:!0,configurable:!0,writable:!0}):d[h]=u;var T=function(e){var r,t;function i(r,t,o){var l,c;return i._logger.debug("Creating adapter. Hls version: "+n.a.version),v(p(c=e.call(this,r,t,o)||this),"_hlsjsLib",n.a),v(p(c),"_triedReloadWithRedirect",!1),v(p(c),"_playerTracks",[]),v(p(c),"_startTime",0),v(p(c),"_requestFilterError",!1),v(p(c),"_responseFilterError",!1),v(p(c),"_nativeTextTracksMap",{}),v(p(c),"_lastLoadedFragSN",-1),v(p(c),"_sameFragSNLoadedCount",0),v(p(c),"_adapterEventsBindings",((l={})[n.a.Events.ERROR]=function(e,r){return c._onError(r)},l[n.a.Events.MANIFEST_LOADED]=function(e,r){return c._onManifestLoaded(r)},l[n.a.Events.LEVEL_SWITCHED]=function(e,r){return c._onLevelSwitched(e,r)},l[n.a.Events.AUDIO_TRACK_SWITCHED]=function(e,r){return c._onAudioTrackSwitched(e,r)},l[n.a.Events.FPS_DROP]=function(e,r){return c._onFpsDrop(r)},l[n.a.Events.FRAG_PARSING_METADATA]=function(e,r){return c._onFragParsingMetadata(r)},l[n.a.Events.FRAG_LOADED]=function(e,r){return c._onFragLoaded(r)},l[n.a.Events.MEDIA_ATTACHED]=function(){return c._onMediaAttached()},l[n.a.Events.LEVEL_LOADED]=function(e,r){return c._onLevelLoaded(e,r)},l)),v(p(c),"_onLevelLoaded",(function(e,r){if(c.isLive()){var t=r.details.endSN;if(c._lastLoadedFragSN===t){if(c._sameFragSNLoadedCount++,i._logger.debug("Same frag SN. Count is: "+c._sameFragSNLoadedCount+", Max is: "+c._config.network.maxStaleLevelReloads),c._sameFragSNLoadedCount>=c._config.network.maxStaleLevelReloads){i._logger.error("Same frag loading reached max count");var o=new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.NETWORK,a.Error.Code.LIVE_MANIFEST_REFRESH_ERROR,{fragSN:t});return c._trigger(a.EventType.ERROR,o),c.destroy()}i._logger.debug("Last frag SN is: "+t)}else c._sameFragSNLoadedCount=0;c._lastLoadedFragSN=t}})),c._config=a.Utils.Object.mergeDeep({},s,c._config),c._init(),c}t=e,(r=i).prototype=Object.create(t.prototype),r.prototype.constructor=r,r.__proto__=t,i.createAdapter=function(e,r,t){var i=a.Utils.Object.copyDeep(s);if(a.Utils.Object.hasPropertyPath(t,"sources.options")){var o=t.sources.options;i.forceRedirectExternalStreams=o.forceRedirectExternalStreams,i.redirectExternalStreamsHandler=o.redirectExternalStreamsHandler,i.redirectExternalStreamsTimeout=o.redirectExternalStreamsTimeout,_.redirectExternalStreamsHandler=i.redirectExternalStreamsHandler,_.redirectExternalStreamsTimeout=i.redirectExternalStreamsTimeout}a.Utils.Object.hasPropertyPath(t,"sources.startTime")&&(a.Utils.Object.getPropertyPath(t,"sources.startTime")>-1&&(i.hlsConfig.startPosition=t.sources.startTime));if(a.Utils.Object.hasPropertyPath(t,"text.useNativeTextTrack")&&(i.subtitleDisplay=a.Utils.Object.getPropertyPath(t,"text.useNativeTextTrack")),a.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedFramesInterval")&&(i.hlsConfig.fpsDroppedFramesInterval=t.abr.fpsDroppedFramesInterval),a.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedMonitoringThreshold")&&(i.hlsConfig.fpsDroppedMonitoringThreshold=t.abr.fpsDroppedMonitoringThreshold),a.Utils.Object.hasPropertyPath(t,"abr.capLevelOnFPSDrop")&&(i.hlsConfig.capLevelOnFPSDrop=t.abr.capLevelOnFPSDrop),a.Utils.Object.hasPropertyPath(t,"text")&&(i.hlsConfig.enableCEA708Captions=t.text.enableCEA708Captions,i.hlsConfig.captionsTextTrack1Label=t.text.captionsTextTrack1Label,i.hlsConfig.captionsTextTrack1LanguageCode=t.text.captionsTextTrack1LanguageCode,i.hlsConfig.captionsTextTrack2Label=t.text.captionsTextTrack2Label,i.hlsConfig.captionsTextTrack2LanguageCode=t.text.captionsTextTrack2LanguageCode),a.Utils.Object.hasPropertyPath(t,"abr")){var n=t.abr;"boolean"==typeof n.enabled&&(i.abr.enabled=n.enabled),"boolean"==typeof n.capLevelToPlayerSize&&(i.hlsConfig.capLevelToPlayerSize=n.capLevelToPlayerSize),n.defaultBandwidthEstimate&&(i.hlsConfig.abrEwmaDefaultEstimate=n.defaultBandwidthEstimate),n.restrictions&&a.Utils.Object.createPropertyPath(i,"abr.restrictions",n.restrictions)}return a.Utils.Object.hasPropertyPath(t,"streaming.lowLatencyMode")&&(i.hlsConfig.lowLatencyMode=a.Utils.Object.getPropertyPath(t,"streaming.lowLatencyMode")),a.Utils.Object.hasPropertyPath(t,"playback.options.html5.hls")&&a.Utils.Object.mergeDeep(i.hlsConfig,t.playback.options.html5.hls),i.network=t.network,new this(e,r,i)},i.canPlayType=function(e){var r="string"==typeof e&&(i._hlsMimeTypes.includes(e.toLowerCase())&&i.isMSESupported());return i._logger.debug("canPlayType result for mimeType:"+e+" is "+r.toString()),r},i.canPlayDrm=function(){return i._logger.warn("canPlayDrm result is false"),!1},i.isSupported=function(){var e=n.a.isSupported();return i._logger.debug("isSupported:"+e),e};var o,d,h,u=i.prototype;return u._init=function(){this._config.forceRedirectExternalStreams&&(this._config.hlsConfig.pLoader=_),this._maybeSetFilters(),this._hls=new n.a(this._config.hlsConfig),this._capabilities.fpsControl=!0,this._hls.subtitleDisplay=this._config.subtitleDisplay,this._addBindings()},u._maybeSetFilters=function(){var e=this;if("function"==typeof a.Utils.Object.getPropertyPath(this._config,"network.requestFilter")&&(i._logger.debug("Register request filter"),a.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:c,xhrSetup:function(r,t,i){var o,n={url:t,body:null,headers:{}};try{"manifest"===i.type&&(o=e._config.network.requestFilter(a.RequestType.MANIFEST,n)),i.frag&&"subtitle"!==i.frag.type&&(o=e._config.network.requestFilter(a.RequestType.SEGMENT,n))}catch(e){o=Promise.reject(e)}return(o=o||Promise.resolve(n)).then((function(e){i.url=e.url,r.open("GET",e.url,!0),Object.entries(e.headers).forEach((function(e){r.setRequestHeader.apply(r,e)})),"boolean"==typeof e.withCredentials&&(r.withCredentials=e.withCredentials)})).catch((function(r){throw e._requestFilterError=!0,r}))}})),"function"==typeof a.Utils.Object.getPropertyPath(this._config,"network.responseFilter")){var r=this;i._logger.debug("Register response filter"),a.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:c,readystatechange:function(e){var t=this,o=e.currentTarget,n=o.readyState,s=this.stats,l=this.context,c=this.config;if(!s.aborted&&n>=2){window.clearTimeout(this.requestTimeout);var d=s.loading;if(0===d.first&&(d.first=Math.max(performance.now(),d.start)),4===n){var h=o.status;if(h>=200&&h<300){var u,_;d.end=Math.max(s.tfirst,performance.now()),_="arraybuffer"===l.responseType?(u=o.response).byteLength:(u=o.responseText).length,s.loaded=s.total=_;var E,g={url:o.responseURL,originalUrl:l.url,data:u,headers:a.Utils.Http.convertHeadersToDictionary(o.getAllResponseHeaders())};try{"manifest"===l.type&&(E=r._config.network.responseFilter(a.RequestType.MANIFEST,g)),l.frag&&"subtitle"!==l.frag.type&&(E=r._config.network.responseFilter(a.RequestType.SEGMENT,g))}catch(e){E=Promise.reject(e)}return(E=E||Promise.resolve(g)).then((function(e){t.callbacks.onSuccess(e,s,l,o)})).catch((function(e){r._responseFilterError=!0,t.callbacks.onError({code:h,text:e.message},l,o)}))}s.retry>=c.maxRetry||h>=400&&h<499?(i._logger.error(h+" while loading "+l.url),this.callbacks.onError({code:h,text:o.statusText},l,o)):(i._logger.warn(h+" while loading "+l.url+", retrying in "+this.retryDelay+"..."),this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,c.maxRetryDelay),s.retry++)}else this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),c.timeout)}}})}},u._addBindings=function(){var e=this;this._mediaAttachedPromise=new Promise((function(r){return e._onMediaAttached=r}));for(var r=0,t=Object.entries(this._adapterEventsBindings);r<t.length;r++){var i=t[r],a=i[0],o=i[1];this._hls.on(a,o)}this._onRecoveredCallback=function(){return e._onRecovered()},this._onAddTrack=this._onAddTrack.bind(this),this._eventManager.listen(this._videoElement,"addtrack",this._onAddTrack),this._videoElement.textTracks.onaddtrack=this._onAddTrack},u._onFpsDrop=function(e){this._trigger(a.EventType.FPS_DROP,e)},u._onFragParsingMetadata=function(e){var r;this._trigger("hlsFragParsingMetadata",e);var t=Array.from(null==(r=this._videoElement)?void 0:r.textTracks).find((function(e){return"id3"===e.label})),i=Array.from((null==t?void 0:t.cues)||[]),o=[];null==e||e.samples.forEach((function(e){var r=a.Utils.binarySearch(i,(function(r){return r.startTime-e.pts}));if(r){var t=Object(a.createTimedMetadata)(r);o.push(t)}})),o.length&&this._trigger(a.EventType.TIMED_METADATA_ADDED,{cues:o})},u._onAddTrack=function(e){if(!this._hls.subtitleTracks.length){var r=this._parseCEATextTrack(e.track);r&&(i._logger.debug("A CEA 608/708 caption has been found",r),this._playerTracks.push(r),this._trigger(a.EventType.TRACKS_CHANGED,{tracks:this._playerTracks}))}},u.attachMediaSource=function(){this._hls||(this._videoElement&&this._videoElement.src&&(a.Utils.Dom.setAttribute(this._videoElement,"src",""),a.Utils.Dom.removeAttribute(this._videoElement,"src")),this._init())},u.detachMediaSource=function(){var e;this._hls&&(0===Math.floor(this.duration-this.currentTime)?this._config.hlsConfig.startPosition=0:this.currentTime>0&&(this._config.hlsConfig.startPosition=this.currentTime),this._reset(),null==(e=this._loadPromiseHandlers)||e.reject(new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,"media detached while loading")),this._loadPromiseHandlers=null,this._loadPromise=null,this._hls=null)},u.handleMediaError=function(e){return e.code===e.MEDIA_ERR_DECODE&&(i._logger.debug("The video playback was aborted due to a corruption problem or because the video used features your browser did not support.",e.message),this._handleMediaError())},u.load=function(e){var r=this;return this._loadPromise||(this._startTime=e,this._loadPromise=new Promise((function(e,t){r._loadPromiseHandlers={resolve:e,reject:t},r._loadInternal()}))),this._loadPromise},u._loadInternal=function(){var e;this._hls&&this._sourceObj&&this._sourceObj.url?(this._hls.loadSource(this._sourceObj.url),this._hls.attachMedia(this._videoElement),this._trigger(a.EventType.ABR_MODE_CHANGED,{mode:this.isAdaptiveBitrateEnabled()?"auto":"manual"})):null==(e=this._loadPromiseHandlers)||e.reject(new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,"no url provided"))},u._reloadWithDirectManifest=function(){this._triedReloadWithRedirect=!0,this._reset(),this._config.hlsConfig.pLoader=_,this._hls=new n.a(this._config.hlsConfig),this._addBindings(),this._loadInternal()},u.destroy=function(){var r=this;return new Promise((function(t,o){e.prototype.destroy.call(r).then((function(){var e;i._logger.debug("destroy"),r._playerTracks=[],r._nativeTextTracksMap={},r._sameFragSNLoadedCount=0,r._lastLoadedFragSN=-1,null==(e=r._loadPromiseHandlers)||e.reject(new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,"The adapter has been destroyed while loading")),r._loadPromiseHandlers=null,r._loadPromise=null,r._reset(),t()}),(function(){return o()}))}))},u._reset=function(){this._removeBindings(),this._requestFilterError=!1,this._responseFilterError=!1,this._hls.detachMedia(),this._hls.destroy()},u._parseTracks=function(){var e=this._parseAudioTracks(this._hls.audioTracks||[]),r=this._parseVideoTracks(this._hls.levels||[]),t=this._parseTextTracks(this._hls.subtitleTracks||[]);return e.concat(r).concat(t)},u._parseAudioTracks=function(e){for(var r=[],t=0;t<e.length;t++){var i={id:e[t].id,active:this._hls.audioTrack===e[t].id,label:e[t].name,language:e[t].lang,index:t};r.push(new a.AudioTrack(i))}return r},u._parseVideoTracks=function(e){for(var r=[],t=0;t<e.length;t++){var i={active:this._hls.startLevel===t,bandwidth:e[t].bitrate,width:e[t].width,height:e[t].height,language:"",index:t};r.push(new a.VideoTrack(i))}return r},u._parseTextTracks=function(e){for(var r,t=[],i=E(e);!(r=i()).done;){var o=r.value,n={id:o.id,active:o.default,label:o.name,kind:o.type.toLowerCase(),language:o.lang};t.push(new a.TextTrack(n))}return t},u._parseCEATextTrack=function(e){var r=null;if("captions"===e.kind){var t={id:e.id,active:"showing"===e.mode,label:e.label,kind:e.kind,language:e.language};r=new a.TextTrack(t),this._nativeTextTracksMap[r.index]=e}return r},u.selectAudioTrack=function(e){e instanceof a.AudioTrack&&!e.active&&this._hls.audioTracks&&(this._hls.audioTrack=e.id)},u.selectVideoTrack=function(e){e instanceof a.VideoTrack&&(!e.active||this.isAdaptiveBitrateEnabled())&&this._hls.levels&&(this.isAdaptiveBitrateEnabled()&&this._trigger(a.EventType.ABR_MODE_CHANGED,{mode:"manual"}),this._hls.currentLevel=e.index)},u.selectTextTrack=function(e){e instanceof a.TextTrack&&!e.active&&this._hls&&(this._hls.subtitleTracks.length?(this._hls.subtitleTrack=e.id,this._notifyTrackChanged(e)):this._selectNativeTextTrack(e))},u._selectNativeTextTrack=function(e){var r=this._nativeTextTracksMap[e.index];r&&(this.disableNativeTextTracks(),r.mode=this._config.subtitleDisplay?"showing":"hidden",this._notifyTrackChanged(e))},u._notifyTrackChanged=function(e){this._onTrackChanged(e)},u.hideTextTrack=function(){this._hls&&(this._hls.subtitleTracks.length?this._hls.subtitleTrack=-1:this.disableNativeTextTracks())},u.enableAdaptiveBitrate=function(){this.isAdaptiveBitrateEnabled()||(this._trigger(a.EventType.ABR_MODE_CHANGED,{mode:"auto"}),this._hls.nextLevel=-1)},u.isAdaptiveBitrateEnabled=function(){return!!this._hls&&this._hls.autoLevelEnabled},u.applyABRRestriction=function(e){a.Utils.Object.createPropertyPath(this._config,"abr.restrictions",e),this._hls.capLevelToPlayerSize||this._maybeApplyAbrRestrictions(e)},u._getLevelDetails=function(){var e=this._hls.levels[this._hls.currentLevel]||this._hls.levels[this._hls.nextLevel]||this._hls.levels[this._hls.nextAutoLevel]||this._hls.levels[this._hls.nextLoadLevel];return e&&e.details?e.details:{}},u._getLiveEdge=function(){try{var e;return(e=this._hls.liveSyncPosition?this._hls.liveSyncPosition:this._hls.config.liveSyncDuration?this._videoElement.duration-this._hls.config.liveSyncDuration:this._videoElement.duration-this._hls.config.liveSyncDurationCount*this._getLevelDetails().targetduration)>0?e:this._videoElement.duration}catch(e){return i._logger.debug("Live edge calculation failed, fall back to duration"),this._videoElement.duration}},u.seekToLiveEdge=function(){try{this._videoElement.currentTime=this._getLiveEdge()}catch(e){return}},u.getSegmentDuration=function(){var e=a.Utils.Object.getPropertyPath(this._hls,"streamController.fragCurrent");return e?e.duration:0},u.isLive=function(){try{return!!this._getLevelDetails().live}catch(e){return!1}},u._onManifestLoaded=function(e){var r=this;i._logger.debug("The source has been loaded successfully"),this._hls.config.autoStartLoad||this._hls.startLoad(this._startTime),this._playerTracks=this._parseTracks(),this._config.abr.enabled||(this._hls.currentLevel=0),this._mediaAttachedPromise.then((function(){var e;null==(e=r._loadPromiseHandlers)||e.resolve({tracks:r._playerTracks}),r._loadPromiseHandlers=null}));var t=e.stats.loading,o=t.end-t.start;this._trigger(a.EventType.MANIFEST_LOADED,{miliSeconds:o})},u._maybeApplyAbrRestrictions=function(e){var r=this._playerTracks.filter((function(e){return e instanceof a.VideoTrack})),t=Object(a.filterTracksByRestriction)(r,e);if(t.length){var o=t[0],n=t.pop();this._hls.config.minAutoBitrate=o.bandwidth,this._hls.autoLevelCapping=n.index;var s=t.some((function(e){return e.active}));this.isAdaptiveBitrateEnabled()||s||this.selectVideoTrack(o)}else i._logger.warn("Invalid restrictions, there are not tracks within the restriction range")},u._onLevelSwitched=function(e,r){var t=this._playerTracks.find((function(e){return e instanceof a.VideoTrack&&e.index===r.level}));this._onTrackChanged(t)},u._onAudioTrackSwitched=function(e,r){var t=this._playerTracks.find((function(e){return e instanceof a.AudioTrack&&e.id===r.id}));this._onTrackChanged(t),this._handleWaitingUponAudioTrackSwitch()},u._handleWaitingUponAudioTrackSwitch=function(){var e=this;if(["IE","Edge"].includes(a.Env.browser.name)){this._eventManager.listenOnce(this._videoElement,a.EventType.TIME_UPDATE,(function(){e._trigger(a.EventType.PLAYING)}))}},u._getErrorDataObject=function(e){var r={};switch(r.name=e.details,r.name){case n.a.ErrorDetails.MANIFEST_LOAD_ERROR:case n.a.ErrorDetails.LEVEL_LOAD_ERROR:case n.a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:r.url=e.url,r.responseCode=e.response?e.response.code:null;break;case n.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case n.a.ErrorDetails.LEVEL_LOAD_TIMEOUT:case n.a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:r.url=e.url;break;case n.a.ErrorDetails.MANIFEST_PARSING_ERROR:r.url=e.url,r.reason=e.reason;break;case n.a.ErrorDetails.LEVEL_SWITCH_ERROR:r.level=e.level,r.reason=e.reason;break;case n.a.ErrorDetails.FRAG_LOAD_ERROR:r.fragUrl=e.frag?e.frag.url:null,r.responseCode=e.response?e.response.code:null;break;case n.a.ErrorDetails.FRAG_LOAD_TIMEOUT:r.fragUrl=e.frag?e.frag.url:null;break;case n.a.ErrorDetails.FRAG_DECRYPT_ERROR:case n.a.ErrorDetails.FRAG_PARSING_ERROR:r.reason=e.reason;break;case n.a.ErrorDetails.KEY_LOAD_ERROR:r.fragDecryptedDataUri=e.frag&&e.frag.decryptdata?e.frag.decryptdata.uri:null,r.responseCode=e.response?e.response.code:null;break;case n.a.ErrorDetails.KEY_LOAD_TIMEOUT:r.fragDecryptedDataUri=e.frag&&e.frag.decryptdata?e.frag.decryptdata.uri:null;break;case n.a.ErrorDetails.BUFFER_ADD_CODEC_ERROR:r.mimeType=e.mimeType,r.errorMsg=e.err?e.err.message:null;break;case n.a.ErrorDetails.BUFFER_STALLED_ERROR:r.buffer=e.buffer}return(this._requestFilterError||this._responseFilterError)&&(r.reason=e.response.text),r},u._onError=function(e){var r=e.type,t=e.details,o=e.fatal,s=this._getErrorDataObject(e);if(o){var c;switch(r){case n.a.ErrorTypes.NETWORK_ERROR:var d;d=this._requestFilterError?a.Error.Code.REQUEST_FILTER_ERROR:this._responseFilterError?a.Error.Code.RESPONSE_FILTER_ERROR:a.Error.Code.HTTP_ERROR,![n.a.ErrorDetails.MANIFEST_LOAD_ERROR,n.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT].includes(t)||this._triedReloadWithRedirect||this._config.forceRedirectExternalStreams||this._requestFilterError||this._responseFilterError?c=new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.NETWORK,d,s):(c=new a.Error(a.Error.Severity.RECOVERABLE,a.Error.Category.NETWORK,d,s),this._reloadWithDirectManifest());break;case n.a.ErrorTypes.MEDIA_ERROR:c=this._handleMediaError()?new a.Error(a.Error.Severity.RECOVERABLE,a.Error.Category.MEDIA,a.Error.Code.HLS_FATAL_MEDIA_ERROR,s):new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.MEDIA,a.Error.Code.HLS_FATAL_MEDIA_ERROR,s);break;default:c=new a.Error(a.Error.Severity.CRITICAL,a.Error.Category.PLAYER,a.Error.Code.HLS_FATAL_MEDIA_ERROR,s)}if(this._trigger(a.EventType.ERROR,c),c&&c.severity===a.Error.Severity.CRITICAL){var h;if(this._loadPromiseHandlers)null==(h=this._loadPromiseHandlers)||h.reject(c),this._loadPromiseHandlers=null,this._loadPromise=null;this.destroy()}}else{var u=this._requestFilterError||this._responseFilterError?{category:a.Error.Category.NETWORK,code:this._requestFilterError?a.Error.Code.REQUEST_FILTER_ERROR:a.Error.Code.RESPONSE_FILTER_ERROR}:l[t]||{category:0,code:0},_=u.category,E=u.code;i._logger.warn(new a.Error(a.Error.Severity.RECOVERABLE,_,E,s))}this._requestFilterError=!1,this._responseFilterError=!1},u._handleMediaError=function(){var e=performance.now(),r=!0;return this._checkTimeDeltaHasPassed(e,this._recoverDecodingErrorDate,this._config.recoverDecodingErrorDelay)?(this._eventManager.listen(this._videoElement,a.EventType.LOADED_METADATA,this._onRecoveredCallback),this._recoverDecodingError()):this._checkTimeDeltaHasPassed(e,this._recoverSwapAudioCodecDate,this._config.recoverSwapAudioCodecDelay)?(this._eventManager.listen(this._videoElement,a.EventType.LOADED_METADATA,this._onRecoveredCallback),this._recoverSwapAudioCodec()):(r=!1,i._logger.error("cannot recover, last media error recovery failed")),r},u._onRecovered=function(){this._trigger(a.EventType.MEDIA_RECOVERED),this._videoElement.removeEventListener(a.EventType.LOADED_METADATA,this._onRecoveredCallback)},u._checkTimeDeltaHasPassed=function(e,r,t){return!r||e-r>t},u._recoverDecodingError=function(){this._recoverDecodingErrorDate=performance.now(),i._logger.warn("try to recover media Error"),this._hls.recoverMediaError()},u._recoverSwapAudioCodec=function(){this._recoverSwapAudioCodecDate=performance.now(),i._logger.warn("try to swap Audio Codec and recover media Error"),this._hls.swapAudioCodec(),this._hls.recoverMediaError()},u._removeBindings=function(){for(var e=0,r=Object.entries(this._adapterEventsBindings);e<r.length;e++){var t=r[e],i=t[0],a=t[1];this._hls.off(i,a)}this._videoElement.textTracks.onaddtrack=null,this._onRecoveredCallback=null,this._eventManager&&this._eventManager.removeAll()},u.getStartTimeOfDvrWindow=function(){if(!this.isLive())return 0;try{var e=this._hls.levels[this._hls.nextLoadLevel].details,r=e.fragments,t=r.length,a=r[0].start+r[0].duration,o=r[t-1].start+r[t-1].duration,n=void 0!==this._hls.config.liveMaxLatencyDuration?this._hls.config.liveMaxLatencyDuration:this._hls.config.liveMaxLatencyDurationCount*e.targetduration;return Math.max(a-this._hls.config.maxFragLookUpTolerance,o-n)}catch(e){return i._logger.debug("Unable obtain the start of DVR window"),0}},u._onFragLoaded=function(e){if(a.Utils.Object.hasPropertyPath(e,"frag.stats.loading")){var r=e.frag.stats,t=r.loading.end-r.loading.start;this._trigger(a.EventType.FRAG_LOADED,{miliSeconds:t,bytes:r.loaded,url:e.frag.url})}},u._getLiveTargetBuffer=function(){return this._hls.config.liveSyncDuration?this._hls.config.liveSyncDuration:this._hls.config.liveSyncDurationCount*this._getLevelDetails().targetduration},o=i,(d=[{key:"liveDuration",get:function(){return this._getLiveEdge()+this.getSegmentDuration()}},{key:"targetBuffer",get:function(){var e=NaN;return this._hls?(e=this.isLive()?this._getLiveTargetBuffer()-(this._videoElement.currentTime-this._getLiveEdge()):this._videoElement.duration-this._videoElement.currentTime,e=Math.min(e,this._hls.config.maxMaxBufferLength+this._getLevelDetails().targetduration)):NaN}}])&&f(o.prototype,d),h&&f(o,h),i}(a.BaseMediaSourceAdapter);v(T,"id","HlsAdapter"),v(T,"_logger",a.BaseMediaSourceAdapter.getLogger(T.id)),v(T,"_hlsMimeTypes",["application/x-mpegurl","application/vnd.apple.mpegurl","audio/mpegurl","audio/x-mpegurl","video/x-mpegurl","video/mpegurl","application/mpegurl"]);var y="1.31.1",R="@playkit-js/playkit-js-hls";r.default=T;T.isSupported()&&Object(a.registerMediaSourceAdapter)(T)}])}));
2
2
  //# sourceMappingURL=playkit-hls.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playkit-js/playkit-js-hls",
3
- "version": "1.31.0",
3
+ "version": "1.31.1",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "hls",
@@ -75,7 +75,7 @@
75
75
  "eslint-plugin-mocha-no-only": "^1.1.0",
76
76
  "eslint-plugin-prettier": "^3.1.4",
77
77
  "flow-bin": "^0.129.0",
78
- "hls.js": "1.2.3",
78
+ "hls.js": "1.2.4",
79
79
  "husky": "^4.2.5",
80
80
  "istanbul": "^0.4.5",
81
81
  "karma": "^5.1.0",