@playkit-js/playkit-js-hls 1.32.5 → 1.32.6
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 +1 -6
- package/dist/playkit-hls.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,12 +2,7 @@
|
|
|
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.32.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Bug Fixes
|
|
9
|
-
|
|
10
|
-
* **FEC-13212:** upgrade HLS.JS from v1.3.5 to v1.4.8 ([a1c4870](https://github.com/kaltura/playkit-js-hls/commit/a1c4870))
|
|
5
|
+
### 1.32.6 (2023-07-26)
|
|
11
6
|
|
|
12
7
|
|
|
13
8
|
|
package/dist/playkit-hls.js
CHANGED
|
@@ -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 s=r[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,t),s.l=!0,s.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 s in e)t.d(i,s,function(r){return e[r]}.bind(null,s));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 u})),t.d(r,"NAME",(function(){return p}));var i=t(0),s=t(1),a=t.n(s),o=t(2);const n={[a.a.ErrorDetails.MANIFEST_LOAD_ERROR]:{category:i.Error.Category.MANIFEST,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT]:{category:i.Error.Category.MANIFEST,code:i.Error.Code.TIMEOUT},[a.a.ErrorDetails.MANIFEST_PARSING_ERROR]:{category:i.Error.Category.MANIFEST,code:i.Error.Code.HLSJS_CANNOT_PARSE},[a.a.ErrorDetails.LEVEL_LOAD_ERROR]:{category:i.Error.Category.NETWORK,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.LEVEL_LOAD_TIMEOUT]:{category:i.Error.Category.NETWORK,code:i.Error.Code.TIMEOUT},[a.a.ErrorDetails.LEVEL_SWITCH_ERROR]:{category:i.Error.Category.PLAYER,code:i.Error.Code.BITRATE_SWITCH_ISSUE},[a.a.ErrorDetails.FRAG_LOAD_ERROR]:{category:i.Error.Category.NETWORK,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.FRAG_LOOP_LOADING_ERROR]:{category:i.Error.Category.NETWORK,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.FRAG_LOAD_TIMEOUT]:{category:i.Error.Category.NETWORK,code:i.Error.Code.TIMEOUT},[a.a.ErrorDetails.FRAG_PARSING_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_FRAG_PARSING_ERROR},[a.a.ErrorDetails.BUFFER_APPEND_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_BUFFER_APPEND_ISSUE},[a.a.ErrorDetails.BUFFER_APPENDING_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_BUFFER_APPENDING_ISSUE},[a.a.ErrorDetails.BUFFER_STALLED_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_BUFFER_STALLED_ERROR}};class l extends a.a.DefaultConfig.loader{constructor(e){super(e),e&&e.readystatechange&&(this.readystatechange=e.readystatechange)}loadInternal(){let e,r=this.context;e=this.loader=new XMLHttpRequest;let t=this.stats;t.tfirst=0,t.loaded=0;const i=this.xhrSetup;let s;try{if(i)try{s=i(e,r.url,r)}catch(t){e.open("GET",r.url,!0),s=i(e,r.url,r)}e.readyState||e.open("GET",r.url,!0)}catch(e){s=Promise.reject(e)}s=s||Promise.resolve(),s.then(()=>{r.rangeEnd&&e.setRequestHeader("Range","bytes="+r.rangeStart+"-"+(r.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=r.responseType,this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),this.config.timeout),e.send()}).catch(t=>{this.callbacks.onError({code:e.status,text:t.message},r,e)})}}class d extends l{constructor(e){super(e);const r=this.load.bind(this),t=d.redirectExternalStreamsHandler;this.load=(e,s,a)=>{const o=e.url;"manifest"===e.type?i.Utils.Http.jsonp(o,t,{timeout:d.redirectExternalStreamsTimeout}).then(t=>{e.url=t,r(e,s,a)}).catch(()=>r(e,s,a)):r(e,s,a)}}}var c,h,_;function E(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}c=d,_=(e,r)=>r,(h=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(h="redirectExternalStreamsHandler"))in c?Object.defineProperty(c,h,{value:_,enumerable:!0,configurable:!0,writable:!0}):c[h]=_;class g extends i.BaseMediaSourceAdapter{static createAdapter(e,r,t){let s=i.Utils.Object.copyDeep(o);if(i.Utils.Object.hasPropertyPath(t,"sources.options")){const e=t.sources.options;s.forceRedirectExternalStreams=e.forceRedirectExternalStreams,s.redirectExternalStreamsHandler=e.redirectExternalStreamsHandler,s.redirectExternalStreamsTimeout=e.redirectExternalStreamsTimeout,d.redirectExternalStreamsHandler=s.redirectExternalStreamsHandler,d.redirectExternalStreamsTimeout=s.redirectExternalStreamsTimeout}if(i.Utils.Object.hasPropertyPath(t,"sources.startTime")){i.Utils.Object.getPropertyPath(t,"sources.startTime")>-1&&(s.hlsConfig.startPosition=t.sources.startTime)}if(i.Utils.Object.hasPropertyPath(t,"text.useNativeTextTrack")&&(s.subtitleDisplay=i.Utils.Object.getPropertyPath(t,"text.useNativeTextTrack")),i.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedFramesInterval")&&(s.hlsConfig.fpsDroppedFramesInterval=t.abr.fpsDroppedFramesInterval),i.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedMonitoringThreshold")&&(s.hlsConfig.fpsDroppedMonitoringThreshold=t.abr.fpsDroppedMonitoringThreshold),i.Utils.Object.hasPropertyPath(t,"abr.capLevelOnFPSDrop")&&(g._logger.debug("capLevelOnFPSDrop = ",t.abr.capLevelOnFPSDrop),s.hlsConfig.capLevelOnFPSDrop=t.abr.capLevelOnFPSDrop),i.Utils.Object.hasPropertyPath(t,"text")&&(s.hlsConfig.enableCEA708Captions=t.text.enableCEA708Captions,s.hlsConfig.captionsTextTrack1Label=t.text.captionsTextTrack1Label,s.hlsConfig.captionsTextTrack1LanguageCode=t.text.captionsTextTrack1LanguageCode,s.hlsConfig.captionsTextTrack2Label=t.text.captionsTextTrack2Label,s.hlsConfig.captionsTextTrack2LanguageCode=t.text.captionsTextTrack2LanguageCode),i.Utils.Object.hasPropertyPath(t,"abr")){const e=t.abr;"boolean"==typeof e.enabled&&(s.abr.enabled=e.enabled),"boolean"==typeof e.capLevelToPlayerSize&&(s.hlsConfig.capLevelToPlayerSize=e.capLevelToPlayerSize),e.defaultBandwidthEstimate&&(s.hlsConfig.abrEwmaDefaultEstimate=e.defaultBandwidthEstimate),e.restrictions&&i.Utils.Object.createPropertyPath(s,"abr.restrictions",e.restrictions)}return i.Utils.Object.hasPropertyPath(t,"streaming.lowLatencyMode")&&(s.hlsConfig.lowLatencyMode=i.Utils.Object.getPropertyPath(t,"streaming.lowLatencyMode")),i.Utils.Object.hasPropertyPath(t,"playback.options.html5.hls")&&i.Utils.Object.mergeDeep(s.hlsConfig,t.playback.options.html5.hls),s.network=t.network,new this(e,r,s)}static canPlayType(e){let r="string"==typeof e&&(g._hlsMimeTypes.includes(e.toLowerCase())&&g.isMSESupported());return g._logger.debug("canPlayType result for mimeType:"+e+" is "+r.toString()),r}static canPlayDrm(){return g._logger.warn("canPlayDrm result is false"),!1}static isSupported(){let e=a.a.isSupported();return g._logger.debug("isSupported:"+e),e}constructor(e,r,t){g._logger.debug("Creating adapter. Hls version: "+a.a.version),super(e,r,t),E(this,"_hlsjsLib",a.a),E(this,"_triedReloadWithRedirect",!1),E(this,"_playerTracks",[]),E(this,"_startTime",0),E(this,"_requestFilterError",!1),E(this,"_responseFilterError",!1),E(this,"_nativeTextTracksMap",{}),E(this,"_lastLoadedFragSN",-1),E(this,"_sameFragSNLoadedCount",0),E(this,"_adapterEventsBindings",{[a.a.Events.ERROR]:(e,r)=>this._onError(r),[a.a.Events.MANIFEST_LOADED]:(e,r)=>this._onManifestLoaded(r),[a.a.Events.LEVEL_SWITCHED]:(e,r)=>this._onLevelSwitched(e,r),[a.a.Events.AUDIO_TRACK_SWITCHED]:(e,r)=>this._onAudioTrackSwitched(e,r),[a.a.Events.FPS_DROP]:(e,r)=>this._onFpsDrop(r),[a.a.Events.FRAG_PARSING_METADATA]:(e,r)=>this._onFragParsingMetadata(r),[a.a.Events.FRAG_LOADED]:(e,r)=>this._onFragLoaded(r),[a.a.Events.MEDIA_ATTACHED]:()=>this._onMediaAttached(),[a.a.Events.LEVEL_LOADED]:(e,r)=>this._onLevelLoaded(e,r)}),E(this,"_onLevelLoaded",(e,r)=>{if(this.isLive()){const{details:{endSN:e}}=r;if(this._lastLoadedFragSN===e){if(this._sameFragSNLoadedCount++,g._logger.debug(`Same frag SN. Count is: ${this._sameFragSNLoadedCount}, Max is: ${this._config.network.maxStaleLevelReloads}`),this._sameFragSNLoadedCount>=this._config.network.maxStaleLevelReloads){g._logger.error("Same frag loading reached max count");const r=new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.NETWORK,i.Error.Code.LIVE_MANIFEST_REFRESH_ERROR,{fragSN:e});return this._trigger(i.EventType.ERROR,r),this.destroy()}g._logger.debug("Last frag SN is: "+e)}else this._sameFragSNLoadedCount=0;this._lastLoadedFragSN=e}}),this._config=i.Utils.Object.mergeDeep({},o,this._config),this._init()}_init(){this._config.forceRedirectExternalStreams&&(this._config.hlsConfig.pLoader=d),this._maybeSetFilters(),this._hls=new a.a(this._config.hlsConfig),this._capabilities.fpsControl=!0,this._hls.subtitleDisplay=this._config.subtitleDisplay,this._addBindings()}_maybeSetFilters(){if("function"==typeof i.Utils.Object.getPropertyPath(this._config,"network.requestFilter")&&(g._logger.debug("Register request filter"),i.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:l,xhrSetup:(e,r,t)=>{let s;const a={url:r,body:null,headers:{}};try{"manifest"===t.type&&(s=this._config.network.requestFilter(i.RequestType.MANIFEST,a)),t.frag&&"subtitle"!==t.frag.type&&(s=this._config.network.requestFilter(i.RequestType.SEGMENT,a))}catch(e){s=Promise.reject(e)}return s=s||Promise.resolve(a),s.then(r=>{t.url=r.url,e.open("GET",r.url,!0),Object.entries(r.headers).forEach(r=>{e.setRequestHeader(...r)}),"boolean"==typeof r.withCredentials&&(e.withCredentials=r.withCredentials)}).catch(e=>{throw this._requestFilterError=!0,e})}})),"function"==typeof i.Utils.Object.getPropertyPath(this._config,"network.responseFilter")){const e=this;g._logger.debug("Register response filter"),i.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:l,readystatechange:function(r){let t=r.currentTarget,s=t.readyState,a=this.stats,o=this.context,n=this.config;if(!a.aborted&&s>=2){window.clearTimeout(this.requestTimeout);const{loading:r}=a;if(0===r.first&&(r.first=Math.max(performance.now(),r.start)),4===s){let s=t.status;if(s>=200&&s<300){let n,l;r.end=Math.max(a.tfirst,performance.now()),"arraybuffer"===o.responseType?(n=t.response,l=n.byteLength):(n=t.responseText,l=n.length),a.loaded=a.total=l;const d={url:t.responseURL,originalUrl:o.url,data:n,headers:i.Utils.Http.convertHeadersToDictionary(t.getAllResponseHeaders())};let c;try{"manifest"===o.type&&(c=e._config.network.responseFilter(i.RequestType.MANIFEST,d)),o.frag&&"subtitle"!==o.frag.type&&(c=e._config.network.responseFilter(i.RequestType.SEGMENT,d))}catch(e){c=Promise.reject(e)}return c=c||Promise.resolve(d),c.then(e=>{this.callbacks.onSuccess(e,a,o,t)}).catch(r=>{e._responseFilterError=!0,this.callbacks.onError({code:s,text:r.message},o,t)})}a.retry>=n.maxRetry||s>=400&&s<499?(g._logger.error(`${s} while loading ${o.url}`),this.callbacks.onError({code:s,text:t.statusText},o,t)):(g._logger.warn(`${s} while loading ${o.url}, retrying in ${this.retryDelay}...`),this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,n.maxRetryDelay),a.retry++)}else this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),n.timeout)}}})}}_addBindings(){this._mediaAttachedPromise=new Promise(e=>this._onMediaAttached=e);for(const[e,r]of Object.entries(this._adapterEventsBindings))this._hls.on(e,r);this._onRecoveredCallback=()=>this._onRecovered(),this._onAddTrack=this._onAddTrack.bind(this),this._eventManager.listen(this._videoElement,"addtrack",this._onAddTrack),this._videoElement.textTracks.onaddtrack=this._onAddTrack}_onFpsDrop(e){this._trigger(i.EventType.FPS_DROP,e)}_onFragParsingMetadata(e){var r;this._trigger("hlsFragParsingMetadata",e);const t=Array.from(null==(r=this._videoElement)?void 0:r.textTracks).find(e=>"id3"===e.label),s=Array.from((null==t?void 0:t.cues)||[]),a=[];null==e||e.samples.forEach(e=>{const r=i.Utils.binarySearch(s,r=>r.startTime-e.pts);if(r){const e=Object(i.createTimedMetadata)(r);a.push(e)}}),a.length&&this._trigger(i.EventType.TIMED_METADATA_ADDED,{cues:a})}_onAddTrack(e){if(!this._hls.subtitleTracks.length){const r=this._parseCEATextTrack(e.track);r&&(g._logger.debug("A CEA 608/708 caption has been found",r),this._playerTracks.push(r),this._trigger(i.EventType.TRACKS_CHANGED,{tracks:this._playerTracks}))}}attachMediaSource(){this._hls||(this._videoElement&&this._videoElement.src&&(i.Utils.Dom.setAttribute(this._videoElement,"src",""),i.Utils.Dom.removeAttribute(this._videoElement,"src")),this._init())}detachMediaSource(){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 i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,"media detached while loading")),this._loadPromiseHandlers=null,this._loadPromise=null,this._hls=null)}handleMediaError(e){return e.code===e.MEDIA_ERR_DECODE&&(g._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(a.a.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR))}load(e){return this._loadPromise||(this._startTime=e,this._loadPromise=new Promise((e,r)=>{this._loadPromiseHandlers={resolve:e,reject:r},this._loadInternal()})),this._loadPromise}_loadInternal(){var e;this._hls&&this._sourceObj&&this._sourceObj.url?(this._hls.loadSource(this._sourceObj.url),this._hls.attachMedia(this._videoElement),this._trigger(i.EventType.ABR_MODE_CHANGED,{mode:this.isAdaptiveBitrateEnabled()?"auto":"manual"})):null==(e=this._loadPromiseHandlers)||e.reject(new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,"no url provided"))}_reloadWithDirectManifest(){this._triedReloadWithRedirect=!0,this._reset(),this._config.hlsConfig.pLoader=d,this._hls=new a.a(this._config.hlsConfig),this._addBindings(),this._loadInternal()}destroy(){return new Promise((e,r)=>{super.destroy().then(()=>{var r;g._logger.debug("destroy"),this._playerTracks=[],this._nativeTextTracksMap={},this._sameFragSNLoadedCount=0,this._lastLoadedFragSN=-1,null==(r=this._loadPromiseHandlers)||r.reject(new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,"The adapter has been destroyed while loading")),this._loadPromiseHandlers=null,this._loadPromise=null,this._reset(),e()},()=>r())})}_reset(){this._removeBindings(),this._requestFilterError=!1,this._responseFilterError=!1,this._hls.detachMedia(),this._hls.destroy()}_parseTracks(){const e=this._parseAudioTracks(this._hls.audioTracks||[]),r=this._parseVideoTracks(this._hls.levels||[]),t=this._parseTextTracks(this._hls.subtitleTracks||[]);return e.concat(r).concat(t)}_parseAudioTracks(e){let r=[];for(let t=0;t<e.length;t++){let s={id:e[t].id,active:this._hls.audioTrack===e[t].id,label:e[t].name,language:e[t].lang,index:t};r.push(new i.AudioTrack(s))}return r}_parseVideoTracks(e){let r=[];for(let t=0;t<e.length;t++){let s={active:this._hls.startLevel===t,bandwidth:e[t].bitrate,width:e[t].width,height:e[t].height,language:"",index:t};r.push(new i.VideoTrack(s))}return r}_parseTextTracks(e){let r=[];for(const t of e){let e={id:t.id,active:!1,default:t.default,label:t.name,kind:t.type.toLowerCase(),language:t.lang};r.push(new i.TextTrack(e))}return r}_parseCEATextTrack(e){let r=null;if("captions"===e.kind){const t={id:e.id,active:"showing"===e.mode,label:e.label,kind:e.kind,language:e.language};r=new i.TextTrack(t),this._nativeTextTracksMap[r.index]=e}return r}selectAudioTrack(e){e instanceof i.AudioTrack&&!e.active&&this._hls.audioTracks&&(this._hls.audioTrack=e.id)}selectVideoTrack(e){e instanceof i.VideoTrack&&(!e.active||this.isAdaptiveBitrateEnabled())&&this._hls.levels&&(this.isAdaptiveBitrateEnabled()&&this._trigger(i.EventType.ABR_MODE_CHANGED,{mode:"manual"}),this._hls.currentLevel=e.index)}selectTextTrack(e){e instanceof i.TextTrack&&!e.active&&this._hls&&(this._hls.subtitleTracks.length?(this._hls.subtitleTrack=e.id,this._notifyTrackChanged(e)):this._selectNativeTextTrack(e))}_selectNativeTextTrack(e){const r=this._nativeTextTracksMap[e.index];r&&(this.disableNativeTextTracks(),r.mode=this._config.subtitleDisplay?"showing":"hidden",this._notifyTrackChanged(e))}_notifyTrackChanged(e){this._onTrackChanged(e)}hideTextTrack(){this._hls&&(this._hls.subtitleTracks.length?this._hls.subtitleTrack=-1:this.disableNativeTextTracks())}enableAdaptiveBitrate(){this.isAdaptiveBitrateEnabled()||(this._trigger(i.EventType.ABR_MODE_CHANGED,{mode:"auto"}),this._hls.nextLevel=-1)}isAdaptiveBitrateEnabled(){return!!this._hls&&this._hls.autoLevelEnabled}applyABRRestriction(e){i.Utils.Object.createPropertyPath(this._config,"abr.restrictions",e),this._hls.capLevelToPlayerSize||this._maybeApplyAbrRestrictions(e)}_getLevelDetails(){const 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:{}}_getLiveEdge(){try{let 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,e>0?e:this._videoElement.duration}catch(e){return g._logger.debug("Live edge calculation failed, fall back to duration"),this._videoElement.duration}}seekToLiveEdge(){try{this._videoElement.currentTime=this._getLiveEdge()}catch(e){return}}getSegmentDuration(){const e=i.Utils.Object.getPropertyPath(this._hls,"streamController.fragCurrent");return e?e.duration:0}get liveDuration(){return this._getLiveEdge()+this.getSegmentDuration()}isLive(){try{return!!this._getLevelDetails().live}catch(e){return!1}}_onManifestLoaded(e){g._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(()=>{var e;null==(e=this._loadPromiseHandlers)||e.resolve({tracks:this._playerTracks}),this._loadPromiseHandlers=null});const{loading:r}=e.stats,t=r.end-r.start;this._trigger(i.EventType.MANIFEST_LOADED,{miliSeconds:t})}_maybeApplyAbrRestrictions(e){const r=this._playerTracks.filter(e=>e instanceof i.VideoTrack),t=Object(i.filterTracksByRestriction)(r,e);if(t.length){const e=t[0],r=t.pop();this._hls.config.minAutoBitrate=e.bandwidth,this._hls.autoLevelCapping=r.index;const i=t.some(e=>e.active);this.isAdaptiveBitrateEnabled()||i||this.selectVideoTrack(e)}else g._logger.warn("Invalid restrictions, there are not tracks within the restriction range")}_onLevelSwitched(e,r){let t=this._playerTracks.find(e=>e instanceof i.VideoTrack&&e.index===r.level);this._onTrackChanged(t)}_onAudioTrackSwitched(e,r){let t=this._playerTracks.find(e=>e instanceof i.AudioTrack&&e.id===r.id);this._onTrackChanged(t),this._handleWaitingUponAudioTrackSwitch()}_handleWaitingUponAudioTrackSwitch(){if(["IE","Edge"].includes(i.Env.browser.name)){const e=()=>{this._trigger(i.EventType.PLAYING)};this._eventManager.listenOnce(this._videoElement,i.EventType.TIME_UPDATE,e)}}_getErrorDataObject(e){let r={};switch(r.name=e.details,r.name){case a.a.ErrorDetails.MANIFEST_LOAD_ERROR:case a.a.ErrorDetails.LEVEL_LOAD_ERROR:case a.a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:r.url=e.url,r.responseCode=e.response?e.response.code:null;break;case a.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case a.a.ErrorDetails.LEVEL_LOAD_TIMEOUT:case a.a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:r.url=e.url;break;case a.a.ErrorDetails.MANIFEST_PARSING_ERROR:r.url=e.url,r.reason=e.reason;break;case a.a.ErrorDetails.LEVEL_SWITCH_ERROR:r.level=e.level,r.reason=e.reason;break;case a.a.ErrorDetails.FRAG_LOAD_ERROR:r.fragUrl=e.frag?e.frag.url:null,r.responseCode=e.response?e.response.code:null;break;case a.a.ErrorDetails.FRAG_LOAD_TIMEOUT:r.fragUrl=e.frag?e.frag.url:null;break;case a.a.ErrorDetails.FRAG_DECRYPT_ERROR:case a.a.ErrorDetails.FRAG_PARSING_ERROR:r.reason=e.reason;break;case a.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 a.a.ErrorDetails.KEY_LOAD_TIMEOUT:r.fragDecryptedDataUri=e.frag&&e.frag.decryptdata?e.frag.decryptdata.uri:null;break;case a.a.ErrorDetails.BUFFER_ADD_CODEC_ERROR:r.mimeType=e.mimeType,r.errorMsg=e.err?e.err.message:null;break;case a.a.ErrorDetails.BUFFER_STALLED_ERROR:r.buffer=e.buffer}return(this._requestFilterError||this._responseFilterError)&&(r.reason=e.response.text),r}_onError(e){const r=e.type,t=e.details,s=e.fatal;let o=this._getErrorDataObject(e);if(s){let e;switch(r){case a.a.ErrorTypes.NETWORK_ERROR:{let r;r=this._requestFilterError?i.Error.Code.REQUEST_FILTER_ERROR:this._responseFilterError?i.Error.Code.RESPONSE_FILTER_ERROR:i.Error.Code.HTTP_ERROR,![a.a.ErrorDetails.MANIFEST_LOAD_ERROR,a.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT].includes(t)||this._triedReloadWithRedirect||this._config.forceRedirectExternalStreams||this._requestFilterError||this._responseFilterError?e=new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.NETWORK,r,o):(e=new i.Error(i.Error.Severity.RECOVERABLE,i.Error.Category.NETWORK,r,o),this._reloadWithDirectManifest())}break;case a.a.ErrorTypes.MEDIA_ERROR:e=this._handleMediaError(t)?new i.Error(i.Error.Severity.RECOVERABLE,i.Error.Category.MEDIA,i.Error.Code.HLS_FATAL_MEDIA_ERROR,o):new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.MEDIA,i.Error.Code.HLS_FATAL_MEDIA_ERROR,o);break;default:e=new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,o)}if(this._trigger(i.EventType.ERROR,e),e&&e.severity===i.Error.Severity.CRITICAL){var l;if(this._loadPromiseHandlers)null==(l=this._loadPromiseHandlers)||l.reject(e),this._loadPromiseHandlers=null,this._loadPromise=null;this.destroy()}}else{const{category:e,code:r}=this._requestFilterError||this._responseFilterError?{category:i.Error.Category.NETWORK,code:this._requestFilterError?i.Error.Code.REQUEST_FILTER_ERROR:i.Error.Code.RESPONSE_FILTER_ERROR}:n[t]||{category:0,code:0};g._logger.warn(new i.Error(i.Error.Severity.RECOVERABLE,e,r,o))}this._requestFilterError=!1,this._responseFilterError=!1}_handleMediaError(e){g._logger.error("_handleMediaError mediaErrorName:",e);const r=performance.now();let t=!0;return e===a.a.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR?(g._logger.error("recover aborted due to: MANIFEST_INCOMPATIBLE_CODECS_ERROR"),t=!1):this._checkTimeDeltaHasPassed(r,this._recoverDecodingErrorDate,this._config.recoverDecodingErrorDelay)?(this._eventManager.listen(this._videoElement,i.EventType.LOADED_METADATA,this._onRecoveredCallback),g._logger.debug("try to recover using: _recoverDecodingError()"),this._recoverDecodingError()):this._checkTimeDeltaHasPassed(r,this._recoverSwapAudioCodecDate,this._config.recoverSwapAudioCodecDelay)?(this._eventManager.listen(this._videoElement,i.EventType.LOADED_METADATA,this._onRecoveredCallback),g._logger.debug("try to recover using: _recoverSwapAudioCodec()"),this._recoverSwapAudioCodec()):(g._logger.error("cannot recover, last media error recovery failed error: ",e),t=!1),t}_onRecovered(){this._trigger(i.EventType.MEDIA_RECOVERED),this._videoElement.removeEventListener(i.EventType.LOADED_METADATA,this._onRecoveredCallback)}_checkTimeDeltaHasPassed(e,r,t){return!r||e-r>t}_recoverDecodingError(){this._recoverDecodingErrorDate=performance.now(),g._logger.warn("try to recover media Error"),this._hls.recoverMediaError()}_recoverSwapAudioCodec(){this._recoverSwapAudioCodecDate=performance.now(),g._logger.warn("try to swap Audio Codec and recover media Error"),this._hls.swapAudioCodec(),this._hls.recoverMediaError()}_removeBindings(){for(const[e,r]of Object.entries(this._adapterEventsBindings))this._hls.off(e,r);this._videoElement.textTracks.onaddtrack=null,this._onRecoveredCallback=null,this._eventManager&&this._eventManager.removeAll()}getStartTimeOfDvrWindow(){if(!this.isLive())return 0;try{const e=this._hls.levels[this._hls.nextLoadLevel].details,r=e.fragments,t=r.length,i=r[0].start+r[0].duration,s=r[t-1].start+r[t-1].duration,a=void 0!==this._hls.config.liveMaxLatencyDuration?this._hls.config.liveMaxLatencyDuration:this._hls.config.liveMaxLatencyDurationCount*e.targetduration;return Math.max(i-this._hls.config.maxFragLookUpTolerance,s-a)}catch(e){return g._logger.debug("Unable obtain the start of DVR window"),0}}_onFragLoaded(e){if(i.Utils.Object.hasPropertyPath(e,"frag.stats.loading")){const{stats:r}=e.frag,t=r.loading.end-r.loading.start;this._trigger(i.EventType.FRAG_LOADED,{miliSeconds:t,bytes:r.loaded,url:e.frag.url})}}get targetBuffer(){let 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),e):NaN}_getLiveTargetBuffer(){return this._hls.config.liveSyncDuration?this._hls.config.liveSyncDuration:this._hls.config.liveSyncDurationCount*this._getLevelDetails().targetduration}}E(g,"id","HlsAdapter"),E(g,"_logger",i.BaseMediaSourceAdapter.getLogger(g.id)),E(g,"_hlsMimeTypes",["application/x-mpegurl","application/vnd.apple.mpegurl","audio/mpegurl","audio/x-mpegurl","video/x-mpegurl","video/mpegurl","application/mpegurl"]);const u="1.32.5",p="@playkit-js/playkit-js-hls";r.default=g;g.isSupported()&&Object(i.registerMediaSourceAdapter)(g)}])}));
|
|
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 s=r[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,t),s.l=!0,s.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 s in e)t.d(i,s,function(r){return e[r]}.bind(null,s));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 u})),t.d(r,"NAME",(function(){return p}));var i=t(0),s=t(1),a=t.n(s),o=t(2);const n={[a.a.ErrorDetails.MANIFEST_LOAD_ERROR]:{category:i.Error.Category.MANIFEST,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT]:{category:i.Error.Category.MANIFEST,code:i.Error.Code.TIMEOUT},[a.a.ErrorDetails.MANIFEST_PARSING_ERROR]:{category:i.Error.Category.MANIFEST,code:i.Error.Code.HLSJS_CANNOT_PARSE},[a.a.ErrorDetails.LEVEL_LOAD_ERROR]:{category:i.Error.Category.NETWORK,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.LEVEL_LOAD_TIMEOUT]:{category:i.Error.Category.NETWORK,code:i.Error.Code.TIMEOUT},[a.a.ErrorDetails.LEVEL_SWITCH_ERROR]:{category:i.Error.Category.PLAYER,code:i.Error.Code.BITRATE_SWITCH_ISSUE},[a.a.ErrorDetails.FRAG_LOAD_ERROR]:{category:i.Error.Category.NETWORK,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.FRAG_LOOP_LOADING_ERROR]:{category:i.Error.Category.NETWORK,code:i.Error.Code.HTTP_ERROR},[a.a.ErrorDetails.FRAG_LOAD_TIMEOUT]:{category:i.Error.Category.NETWORK,code:i.Error.Code.TIMEOUT},[a.a.ErrorDetails.FRAG_PARSING_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_FRAG_PARSING_ERROR},[a.a.ErrorDetails.BUFFER_APPEND_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_BUFFER_APPEND_ISSUE},[a.a.ErrorDetails.BUFFER_APPENDING_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_BUFFER_APPENDING_ISSUE},[a.a.ErrorDetails.BUFFER_STALLED_ERROR]:{category:i.Error.Category.MEDIA,code:i.Error.Code.HLS_BUFFER_STALLED_ERROR}};class l extends a.a.DefaultConfig.loader{constructor(e){super(e),e&&e.readystatechange&&(this.readystatechange=e.readystatechange)}loadInternal(){let e,r=this.context;e=this.loader=new XMLHttpRequest;let t=this.stats;t.tfirst=0,t.loaded=0;const i=this.xhrSetup;let s;try{if(i)try{s=i(e,r.url,r)}catch(t){e.open("GET",r.url,!0),s=i(e,r.url,r)}e.readyState||e.open("GET",r.url,!0)}catch(e){s=Promise.reject(e)}s=s||Promise.resolve(),s.then(()=>{r.rangeEnd&&e.setRequestHeader("Range","bytes="+r.rangeStart+"-"+(r.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=r.responseType,this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),this.config.timeout),e.send()}).catch(t=>{this.callbacks.onError({code:e.status,text:t.message},r,e)})}}class d extends l{constructor(e){super(e);const r=this.load.bind(this),t=d.redirectExternalStreamsHandler;this.load=(e,s,a)=>{const o=e.url;"manifest"===e.type?i.Utils.Http.jsonp(o,t,{timeout:d.redirectExternalStreamsTimeout}).then(t=>{e.url=t,r(e,s,a)}).catch(()=>r(e,s,a)):r(e,s,a)}}}var c,h,_;function E(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}c=d,_=(e,r)=>r,(h=function(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,r||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}(h="redirectExternalStreamsHandler"))in c?Object.defineProperty(c,h,{value:_,enumerable:!0,configurable:!0,writable:!0}):c[h]=_;class g extends i.BaseMediaSourceAdapter{static createAdapter(e,r,t){let s=i.Utils.Object.copyDeep(o);if(i.Utils.Object.hasPropertyPath(t,"sources.options")){const e=t.sources.options;s.forceRedirectExternalStreams=e.forceRedirectExternalStreams,s.redirectExternalStreamsHandler=e.redirectExternalStreamsHandler,s.redirectExternalStreamsTimeout=e.redirectExternalStreamsTimeout,d.redirectExternalStreamsHandler=s.redirectExternalStreamsHandler,d.redirectExternalStreamsTimeout=s.redirectExternalStreamsTimeout}if(i.Utils.Object.hasPropertyPath(t,"sources.startTime")){i.Utils.Object.getPropertyPath(t,"sources.startTime")>-1&&(s.hlsConfig.startPosition=t.sources.startTime)}if(i.Utils.Object.hasPropertyPath(t,"text.useNativeTextTrack")&&(s.subtitleDisplay=i.Utils.Object.getPropertyPath(t,"text.useNativeTextTrack")),i.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedFramesInterval")&&(s.hlsConfig.fpsDroppedFramesInterval=t.abr.fpsDroppedFramesInterval),i.Utils.Object.hasPropertyPath(t,"abr.fpsDroppedMonitoringThreshold")&&(s.hlsConfig.fpsDroppedMonitoringThreshold=t.abr.fpsDroppedMonitoringThreshold),i.Utils.Object.hasPropertyPath(t,"abr.capLevelOnFPSDrop")&&(g._logger.debug("capLevelOnFPSDrop = ",t.abr.capLevelOnFPSDrop),s.hlsConfig.capLevelOnFPSDrop=t.abr.capLevelOnFPSDrop),i.Utils.Object.hasPropertyPath(t,"text")&&(s.hlsConfig.enableCEA708Captions=t.text.enableCEA708Captions,s.hlsConfig.captionsTextTrack1Label=t.text.captionsTextTrack1Label,s.hlsConfig.captionsTextTrack1LanguageCode=t.text.captionsTextTrack1LanguageCode,s.hlsConfig.captionsTextTrack2Label=t.text.captionsTextTrack2Label,s.hlsConfig.captionsTextTrack2LanguageCode=t.text.captionsTextTrack2LanguageCode),i.Utils.Object.hasPropertyPath(t,"abr")){const e=t.abr;"boolean"==typeof e.enabled&&(s.abr.enabled=e.enabled),"boolean"==typeof e.capLevelToPlayerSize&&(s.hlsConfig.capLevelToPlayerSize=e.capLevelToPlayerSize),e.defaultBandwidthEstimate&&(s.hlsConfig.abrEwmaDefaultEstimate=e.defaultBandwidthEstimate),e.restrictions&&i.Utils.Object.createPropertyPath(s,"abr.restrictions",e.restrictions)}return i.Utils.Object.hasPropertyPath(t,"streaming.lowLatencyMode")&&(s.hlsConfig.lowLatencyMode=i.Utils.Object.getPropertyPath(t,"streaming.lowLatencyMode")),i.Utils.Object.hasPropertyPath(t,"playback.options.html5.hls")&&i.Utils.Object.mergeDeep(s.hlsConfig,t.playback.options.html5.hls),s.network=t.network,new this(e,r,s)}static canPlayType(e){let r="string"==typeof e&&(g._hlsMimeTypes.includes(e.toLowerCase())&&g.isMSESupported());return g._logger.debug("canPlayType result for mimeType:"+e+" is "+r.toString()),r}static canPlayDrm(){return g._logger.warn("canPlayDrm result is false"),!1}static isSupported(){let e=a.a.isSupported();return g._logger.debug("isSupported:"+e),e}constructor(e,r,t){g._logger.debug("Creating adapter. Hls version: "+a.a.version),super(e,r,t),E(this,"_hlsjsLib",a.a),E(this,"_triedReloadWithRedirect",!1),E(this,"_playerTracks",[]),E(this,"_startTime",0),E(this,"_requestFilterError",!1),E(this,"_responseFilterError",!1),E(this,"_nativeTextTracksMap",{}),E(this,"_lastLoadedFragSN",-1),E(this,"_sameFragSNLoadedCount",0),E(this,"_adapterEventsBindings",{[a.a.Events.ERROR]:(e,r)=>this._onError(r),[a.a.Events.MANIFEST_LOADED]:(e,r)=>this._onManifestLoaded(r),[a.a.Events.LEVEL_SWITCHED]:(e,r)=>this._onLevelSwitched(e,r),[a.a.Events.AUDIO_TRACK_SWITCHED]:(e,r)=>this._onAudioTrackSwitched(e,r),[a.a.Events.FPS_DROP]:(e,r)=>this._onFpsDrop(r),[a.a.Events.FRAG_PARSING_METADATA]:(e,r)=>this._onFragParsingMetadata(r),[a.a.Events.FRAG_LOADED]:(e,r)=>this._onFragLoaded(r),[a.a.Events.MEDIA_ATTACHED]:()=>this._onMediaAttached(),[a.a.Events.LEVEL_LOADED]:(e,r)=>this._onLevelLoaded(e,r)}),E(this,"_onLevelLoaded",(e,r)=>{if(this.isLive()){const{details:{endSN:e}}=r;if(this._lastLoadedFragSN===e){if(this._sameFragSNLoadedCount++,g._logger.debug(`Same frag SN. Count is: ${this._sameFragSNLoadedCount}, Max is: ${this._config.network.maxStaleLevelReloads}`),this._sameFragSNLoadedCount>=this._config.network.maxStaleLevelReloads){g._logger.error("Same frag loading reached max count");const r=new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.NETWORK,i.Error.Code.LIVE_MANIFEST_REFRESH_ERROR,{fragSN:e});return this._trigger(i.EventType.ERROR,r),this.destroy()}g._logger.debug("Last frag SN is: "+e)}else this._sameFragSNLoadedCount=0;this._lastLoadedFragSN=e}}),this._config=i.Utils.Object.mergeDeep({},o,this._config),this._init()}_init(){this._config.forceRedirectExternalStreams&&(this._config.hlsConfig.pLoader=d),this._maybeSetFilters(),this._hls=new a.a(this._config.hlsConfig),this._capabilities.fpsControl=!0,this._hls.subtitleDisplay=this._config.subtitleDisplay,this._addBindings()}_maybeSetFilters(){if("function"==typeof i.Utils.Object.getPropertyPath(this._config,"network.requestFilter")&&(g._logger.debug("Register request filter"),i.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:l,xhrSetup:(e,r,t)=>{let s;const a={url:r,body:null,headers:{}};try{"manifest"===t.type&&(s=this._config.network.requestFilter(i.RequestType.MANIFEST,a)),t.frag&&"subtitle"!==t.frag.type&&(s=this._config.network.requestFilter(i.RequestType.SEGMENT,a))}catch(e){s=Promise.reject(e)}return s=s||Promise.resolve(a),s.then(r=>{t.url=r.url,e.open("GET",r.url,!0),Object.entries(r.headers).forEach(r=>{e.setRequestHeader(...r)}),"boolean"==typeof r.withCredentials&&(e.withCredentials=r.withCredentials)}).catch(e=>{throw this._requestFilterError=!0,e})}})),"function"==typeof i.Utils.Object.getPropertyPath(this._config,"network.responseFilter")){const e=this;g._logger.debug("Register response filter"),i.Utils.Object.mergeDeep(this._config.hlsConfig,{loader:l,readystatechange:function(r){let t=r.currentTarget,s=t.readyState,a=this.stats,o=this.context,n=this.config;if(!a.aborted&&s>=2){window.clearTimeout(this.requestTimeout);const{loading:r}=a;if(0===r.first&&(r.first=Math.max(performance.now(),r.start)),4===s){let s=t.status;if(s>=200&&s<300){let n,l;r.end=Math.max(a.tfirst,performance.now()),"arraybuffer"===o.responseType?(n=t.response,l=n.byteLength):(n=t.responseText,l=n.length),a.loaded=a.total=l;const d={url:t.responseURL,originalUrl:o.url,data:n,headers:i.Utils.Http.convertHeadersToDictionary(t.getAllResponseHeaders())};let c;try{"manifest"===o.type&&(c=e._config.network.responseFilter(i.RequestType.MANIFEST,d)),o.frag&&"subtitle"!==o.frag.type&&(c=e._config.network.responseFilter(i.RequestType.SEGMENT,d))}catch(e){c=Promise.reject(e)}return c=c||Promise.resolve(d),c.then(e=>{this.callbacks.onSuccess(e,a,o,t)}).catch(r=>{e._responseFilterError=!0,this.callbacks.onError({code:s,text:r.message},o,t)})}a.retry>=n.maxRetry||s>=400&&s<499?(g._logger.error(`${s} while loading ${o.url}`),this.callbacks.onError({code:s,text:t.statusText},o,t)):(g._logger.warn(`${s} while loading ${o.url}, retrying in ${this.retryDelay}...`),this.destroy(),this.retryTimeout=window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,n.maxRetryDelay),a.retry++)}else this.requestTimeout=window.setTimeout(this.loadtimeout.bind(this),n.timeout)}}})}}_addBindings(){this._mediaAttachedPromise=new Promise(e=>this._onMediaAttached=e);for(const[e,r]of Object.entries(this._adapterEventsBindings))this._hls.on(e,r);this._onRecoveredCallback=()=>this._onRecovered(),this._onAddTrack=this._onAddTrack.bind(this),this._eventManager.listen(this._videoElement,"addtrack",this._onAddTrack),this._videoElement.textTracks.onaddtrack=this._onAddTrack}_onFpsDrop(e){this._trigger(i.EventType.FPS_DROP,e)}_onFragParsingMetadata(e){var r;this._trigger("hlsFragParsingMetadata",e);const t=Array.from(null==(r=this._videoElement)?void 0:r.textTracks).find(e=>"id3"===e.label),s=Array.from((null==t?void 0:t.cues)||[]),a=[];null==e||e.samples.forEach(e=>{const r=i.Utils.binarySearch(s,r=>r.startTime-e.pts);if(r){const e=Object(i.createTimedMetadata)(r);a.push(e)}}),a.length&&this._trigger(i.EventType.TIMED_METADATA_ADDED,{cues:a})}_onAddTrack(e){if(!this._hls.subtitleTracks.length){const r=this._parseCEATextTrack(e.track);r&&(g._logger.debug("A CEA 608/708 caption has been found",r),this._playerTracks.push(r),this._trigger(i.EventType.TRACKS_CHANGED,{tracks:this._playerTracks}))}}attachMediaSource(){this._hls||(this._videoElement&&this._videoElement.src&&(i.Utils.Dom.setAttribute(this._videoElement,"src",""),i.Utils.Dom.removeAttribute(this._videoElement,"src")),this._init())}detachMediaSource(){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 i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,"media detached while loading")),this._loadPromiseHandlers=null,this._loadPromise=null,this._hls=null)}handleMediaError(e){return e.code===e.MEDIA_ERR_DECODE&&(g._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(a.a.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR))}load(e){return this._loadPromise||(this._startTime=e,this._loadPromise=new Promise((e,r)=>{this._loadPromiseHandlers={resolve:e,reject:r},this._loadInternal()})),this._loadPromise}_loadInternal(){var e;this._hls&&this._sourceObj&&this._sourceObj.url?(this._hls.loadSource(this._sourceObj.url),this._hls.attachMedia(this._videoElement),this._trigger(i.EventType.ABR_MODE_CHANGED,{mode:this.isAdaptiveBitrateEnabled()?"auto":"manual"})):null==(e=this._loadPromiseHandlers)||e.reject(new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,"no url provided"))}_reloadWithDirectManifest(){this._triedReloadWithRedirect=!0,this._reset(),this._config.hlsConfig.pLoader=d,this._hls=new a.a(this._config.hlsConfig),this._addBindings(),this._loadInternal()}destroy(){return new Promise((e,r)=>{super.destroy().then(()=>{var r;g._logger.debug("destroy"),this._playerTracks=[],this._nativeTextTracksMap={},this._sameFragSNLoadedCount=0,this._lastLoadedFragSN=-1,null==(r=this._loadPromiseHandlers)||r.reject(new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,"The adapter has been destroyed while loading")),this._loadPromiseHandlers=null,this._loadPromise=null,this._reset(),e()},()=>r())})}_reset(){this._removeBindings(),this._requestFilterError=!1,this._responseFilterError=!1,this._hls.detachMedia(),this._hls.destroy()}_parseTracks(){const e=this._parseAudioTracks(this._hls.audioTracks||[]),r=this._parseVideoTracks(this._hls.levels||[]),t=this._parseTextTracks(this._hls.subtitleTracks||[]);return e.concat(r).concat(t)}_parseAudioTracks(e){let r=[];for(let t=0;t<e.length;t++){let s={id:e[t].id,active:this._hls.audioTrack===e[t].id,label:e[t].name,language:e[t].lang,index:t};r.push(new i.AudioTrack(s))}return r}_parseVideoTracks(e){let r=[];for(let t=0;t<e.length;t++){let s={active:this._hls.startLevel===t,bandwidth:e[t].bitrate,width:e[t].width,height:e[t].height,language:"",index:t};r.push(new i.VideoTrack(s))}return r}_parseTextTracks(e){let r=[];for(const t of e){let e={id:t.id,active:!1,default:t.default,label:t.name,kind:t.type.toLowerCase(),language:t.lang};r.push(new i.TextTrack(e))}return r}_parseCEATextTrack(e){let r=null;if("captions"===e.kind){const t={id:e.id,active:"showing"===e.mode,label:e.label,kind:e.kind,language:e.language};r=new i.TextTrack(t),this._nativeTextTracksMap[r.index]=e}return r}selectAudioTrack(e){e instanceof i.AudioTrack&&!e.active&&this._hls.audioTracks&&(this._hls.audioTrack=e.id)}selectVideoTrack(e){e instanceof i.VideoTrack&&(!e.active||this.isAdaptiveBitrateEnabled())&&this._hls.levels&&(this.isAdaptiveBitrateEnabled()&&this._trigger(i.EventType.ABR_MODE_CHANGED,{mode:"manual"}),this._hls.currentLevel=e.index)}selectTextTrack(e){e instanceof i.TextTrack&&!e.active&&this._hls&&(this._hls.subtitleTracks.length?(this._hls.subtitleTrack=e.id,this._notifyTrackChanged(e)):this._selectNativeTextTrack(e))}_selectNativeTextTrack(e){const r=this._nativeTextTracksMap[e.index];r&&(this.disableNativeTextTracks(),r.mode=this._config.subtitleDisplay?"showing":"hidden",this._notifyTrackChanged(e))}_notifyTrackChanged(e){this._onTrackChanged(e)}hideTextTrack(){this._hls&&(this._hls.subtitleTracks.length?this._hls.subtitleTrack=-1:this.disableNativeTextTracks())}enableAdaptiveBitrate(){this.isAdaptiveBitrateEnabled()||(this._trigger(i.EventType.ABR_MODE_CHANGED,{mode:"auto"}),this._hls.nextLevel=-1)}isAdaptiveBitrateEnabled(){return!!this._hls&&this._hls.autoLevelEnabled}applyABRRestriction(e){i.Utils.Object.createPropertyPath(this._config,"abr.restrictions",e),this._hls.capLevelToPlayerSize||this._maybeApplyAbrRestrictions(e)}_getLevelDetails(){const 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:{}}_getLiveEdge(){try{let 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,e>0?e:this._videoElement.duration}catch(e){return g._logger.debug("Live edge calculation failed, fall back to duration"),this._videoElement.duration}}seekToLiveEdge(){try{this._videoElement.currentTime=this._getLiveEdge()}catch(e){return}}getSegmentDuration(){const e=i.Utils.Object.getPropertyPath(this._hls,"streamController.fragCurrent");return e?e.duration:0}get liveDuration(){return this._getLiveEdge()+this.getSegmentDuration()}isLive(){try{return!!this._getLevelDetails().live}catch(e){return!1}}_onManifestLoaded(e){g._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(()=>{var e;null==(e=this._loadPromiseHandlers)||e.resolve({tracks:this._playerTracks}),this._loadPromiseHandlers=null});const{loading:r}=e.stats,t=r.end-r.start;this._trigger(i.EventType.MANIFEST_LOADED,{miliSeconds:t})}_maybeApplyAbrRestrictions(e){const r=this._playerTracks.filter(e=>e instanceof i.VideoTrack),t=Object(i.filterTracksByRestriction)(r,e);if(t.length){const e=t[0],r=t.pop();this._hls.config.minAutoBitrate=e.bandwidth,this._hls.autoLevelCapping=r.index;const i=t.some(e=>e.active);this.isAdaptiveBitrateEnabled()||i||this.selectVideoTrack(e)}else g._logger.warn("Invalid restrictions, there are not tracks within the restriction range")}_onLevelSwitched(e,r){let t=this._playerTracks.find(e=>e instanceof i.VideoTrack&&e.index===r.level);this._onTrackChanged(t)}_onAudioTrackSwitched(e,r){let t=this._playerTracks.find(e=>e instanceof i.AudioTrack&&e.id===r.id);this._onTrackChanged(t),this._handleWaitingUponAudioTrackSwitch()}_handleWaitingUponAudioTrackSwitch(){if(["IE","Edge"].includes(i.Env.browser.name)){const e=()=>{this._trigger(i.EventType.PLAYING)};this._eventManager.listenOnce(this._videoElement,i.EventType.TIME_UPDATE,e)}}_getErrorDataObject(e){let r={};switch(r.name=e.details,r.name){case a.a.ErrorDetails.MANIFEST_LOAD_ERROR:case a.a.ErrorDetails.LEVEL_LOAD_ERROR:case a.a.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:r.url=e.url,r.responseCode=e.response?e.response.code:null;break;case a.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT:case a.a.ErrorDetails.LEVEL_LOAD_TIMEOUT:case a.a.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:r.url=e.url;break;case a.a.ErrorDetails.MANIFEST_PARSING_ERROR:r.url=e.url,r.reason=e.reason;break;case a.a.ErrorDetails.LEVEL_SWITCH_ERROR:r.level=e.level,r.reason=e.reason;break;case a.a.ErrorDetails.FRAG_LOAD_ERROR:r.fragUrl=e.frag?e.frag.url:null,r.responseCode=e.response?e.response.code:null;break;case a.a.ErrorDetails.FRAG_LOAD_TIMEOUT:r.fragUrl=e.frag?e.frag.url:null;break;case a.a.ErrorDetails.FRAG_DECRYPT_ERROR:case a.a.ErrorDetails.FRAG_PARSING_ERROR:r.reason=e.reason;break;case a.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 a.a.ErrorDetails.KEY_LOAD_TIMEOUT:r.fragDecryptedDataUri=e.frag&&e.frag.decryptdata?e.frag.decryptdata.uri:null;break;case a.a.ErrorDetails.BUFFER_ADD_CODEC_ERROR:r.mimeType=e.mimeType,r.errorMsg=e.err?e.err.message:null;break;case a.a.ErrorDetails.BUFFER_STALLED_ERROR:r.buffer=e.buffer}return(this._requestFilterError||this._responseFilterError)&&(r.reason=e.response.text),r}_onError(e){const r=e.type,t=e.details,s=e.fatal;let o=this._getErrorDataObject(e);if(s){let e;switch(r){case a.a.ErrorTypes.NETWORK_ERROR:{let r;r=this._requestFilterError?i.Error.Code.REQUEST_FILTER_ERROR:this._responseFilterError?i.Error.Code.RESPONSE_FILTER_ERROR:i.Error.Code.HTTP_ERROR,![a.a.ErrorDetails.MANIFEST_LOAD_ERROR,a.a.ErrorDetails.MANIFEST_LOAD_TIMEOUT].includes(t)||this._triedReloadWithRedirect||this._config.forceRedirectExternalStreams||this._requestFilterError||this._responseFilterError?e=new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.NETWORK,r,o):(e=new i.Error(i.Error.Severity.RECOVERABLE,i.Error.Category.NETWORK,r,o),this._reloadWithDirectManifest())}break;case a.a.ErrorTypes.MEDIA_ERROR:e=this._handleMediaError(t)?new i.Error(i.Error.Severity.RECOVERABLE,i.Error.Category.MEDIA,i.Error.Code.HLS_FATAL_MEDIA_ERROR,o):new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.MEDIA,i.Error.Code.HLS_FATAL_MEDIA_ERROR,o);break;default:e=new i.Error(i.Error.Severity.CRITICAL,i.Error.Category.PLAYER,i.Error.Code.HLS_FATAL_MEDIA_ERROR,o)}if(this._trigger(i.EventType.ERROR,e),e&&e.severity===i.Error.Severity.CRITICAL){var l;if(this._loadPromiseHandlers)null==(l=this._loadPromiseHandlers)||l.reject(e),this._loadPromiseHandlers=null,this._loadPromise=null;this.destroy()}}else{const{category:e,code:r}=this._requestFilterError||this._responseFilterError?{category:i.Error.Category.NETWORK,code:this._requestFilterError?i.Error.Code.REQUEST_FILTER_ERROR:i.Error.Code.RESPONSE_FILTER_ERROR}:n[t]||{category:0,code:0};g._logger.warn(new i.Error(i.Error.Severity.RECOVERABLE,e,r,o))}this._requestFilterError=!1,this._responseFilterError=!1}_handleMediaError(e){g._logger.error("_handleMediaError mediaErrorName:",e);const r=performance.now();let t=!0;return e===a.a.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR?(g._logger.error("recover aborted due to: MANIFEST_INCOMPATIBLE_CODECS_ERROR"),t=!1):this._checkTimeDeltaHasPassed(r,this._recoverDecodingErrorDate,this._config.recoverDecodingErrorDelay)?(this._eventManager.listen(this._videoElement,i.EventType.LOADED_METADATA,this._onRecoveredCallback),g._logger.debug("try to recover using: _recoverDecodingError()"),this._recoverDecodingError()):this._checkTimeDeltaHasPassed(r,this._recoverSwapAudioCodecDate,this._config.recoverSwapAudioCodecDelay)?(this._eventManager.listen(this._videoElement,i.EventType.LOADED_METADATA,this._onRecoveredCallback),g._logger.debug("try to recover using: _recoverSwapAudioCodec()"),this._recoverSwapAudioCodec()):(g._logger.error("cannot recover, last media error recovery failed error: ",e),t=!1),t}_onRecovered(){this._trigger(i.EventType.MEDIA_RECOVERED),this._videoElement.removeEventListener(i.EventType.LOADED_METADATA,this._onRecoveredCallback)}_checkTimeDeltaHasPassed(e,r,t){return!r||e-r>t}_recoverDecodingError(){this._recoverDecodingErrorDate=performance.now(),g._logger.warn("try to recover media Error"),this._hls.recoverMediaError()}_recoverSwapAudioCodec(){this._recoverSwapAudioCodecDate=performance.now(),g._logger.warn("try to swap Audio Codec and recover media Error"),this._hls.swapAudioCodec(),this._hls.recoverMediaError()}_removeBindings(){for(const[e,r]of Object.entries(this._adapterEventsBindings))this._hls.off(e,r);this._videoElement.textTracks.onaddtrack=null,this._onRecoveredCallback=null,this._eventManager&&this._eventManager.removeAll()}getStartTimeOfDvrWindow(){if(!this.isLive())return 0;try{const e=this._hls.levels[this._hls.nextLoadLevel].details,r=e.fragments,t=r.length,i=r[0].start+r[0].duration,s=r[t-1].start+r[t-1].duration,a=void 0!==this._hls.config.liveMaxLatencyDuration?this._hls.config.liveMaxLatencyDuration:this._hls.config.liveMaxLatencyDurationCount*e.targetduration;return Math.max(i-this._hls.config.maxFragLookUpTolerance,s-a)}catch(e){return g._logger.debug("Unable obtain the start of DVR window"),0}}_onFragLoaded(e){if(i.Utils.Object.hasPropertyPath(e,"frag.stats.loading")){const{stats:r}=e.frag,t=r.loading.end-r.loading.start;this._trigger(i.EventType.FRAG_LOADED,{miliSeconds:t,bytes:r.loaded,url:e.frag.url})}}get targetBuffer(){let 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),e):NaN}_getLiveTargetBuffer(){return this._hls.config.liveSyncDuration?this._hls.config.liveSyncDuration:this._hls.config.liveSyncDurationCount*this._getLevelDetails().targetduration}}E(g,"id","HlsAdapter"),E(g,"_logger",i.BaseMediaSourceAdapter.getLogger(g.id)),E(g,"_hlsMimeTypes",["application/x-mpegurl","application/vnd.apple.mpegurl","audio/mpegurl","audio/x-mpegurl","video/x-mpegurl","video/mpegurl","application/mpegurl"]);const u="1.32.6",p="@playkit-js/playkit-js-hls";r.default=g;g.isSupported()&&Object(i.registerMediaSourceAdapter)(g)}])}));
|
|
2
2
|
//# sourceMappingURL=playkit-hls.js.map
|