HEX
Server: LiteSpeed
System: Linux server257.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: salhiscp (12590)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /home/salhiscp/salhab360photos.com/wp-content/plugins/fwdevp/content/java/hls.js
/* HLS/JS */
"undefined"!=typeof window&&function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hls=t():e.Hls=t()}(this,()=>(()=>{function e(a){var n=r[a];if(void 0!==n)return n.exports;var s=r[a]={exports:{}};return t[a].call(s.exports,s,s.exports,e),s.exports}var t={"./src/config.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,a)}return r}function s(e){for(var t=1,r;t<arguments.length;t++)r=null==arguments[t]?{}:arguments[t],t%2?n(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))});return e}function i(e,t,r){return t=o(t),t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e){var t=d(e,"string");return"symbol"==typeof t?t:t+""}function d(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function l(e,t){if((t.liveSyncDurationCount||t.liveMaxLatencyDurationCount)&&(t.liveSyncDuration||t.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==t.liveMaxLatencyDurationCount&&(void 0===t.liveSyncDurationCount||t.liveMaxLatencyDurationCount<=t.liveSyncDurationCount))throw new Error("Illegal hls.js config: \"liveMaxLatencyDurationCount\" must be greater than \"liveSyncDurationCount\"");if(void 0!==t.liveMaxLatencyDuration&&(void 0===t.liveSyncDuration||t.liveMaxLatencyDuration<=t.liveSyncDuration))throw new Error("Illegal hls.js config: \"liveMaxLatencyDuration\" must be greater than \"liveSyncDuration\"");return a({},e,t)}function u(e){var t=e.loader;if(t!==D["default"]&&t!==L["default"])A.logger.log("[config]: Custom loader detected, cannot enable progressive streaming"),e.progressive=!1;else{var r=(0,D.fetchSupported)();r&&(e.loader=D["default"],e.progressive=!0,e.enableSoftwareAES=!0,A.logger.log("[config]: Progressive streaming enabled, using FetchLoader"))}}r.r(t),r.d(t,{enableStreamingMode:()=>u,hlsDefaultConfig:()=>R,mergeConfig:()=>l});var c=r("./src/controller/abr-controller.ts"),g=r("./src/controller/audio-stream-controller.ts"),f=r("./src/controller/audio-track-controller.ts"),m=r("./src/controller/subtitle-stream-controller.ts"),p=r("./src/controller/subtitle-track-controller.ts"),y=r("./src/controller/buffer-controller.ts"),E=r("./src/controller/timeline-controller.ts"),T=r("./src/controller/cap-level-controller.ts"),h=r("./src/controller/fps-controller.ts"),S=r("./src/controller/eme-controller.ts"),v=r("./src/controller/cmcd-controller.ts"),L=r("./src/utils/xhr-loader.ts"),D=r("./src/utils/fetch-loader.ts"),k=r("./src/utils/cues.ts"),I=r("./src/utils/mediakeys-helper.ts"),A=r("./src/utils/logger.ts"),R=s(s({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,maxBufferSize:60000000,maxBufferHole:.1,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,maxFragLookUpTolerance:.25,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxLiveSyncPlaybackRate:1,liveDurationInfinity:!1,liveBackBufferLength:null,maxMaxBufferLength:600,enableWorker:!0,enableSoftwareAES:!0,manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,startLevel:void 0,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,loader:L["default"],fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:c["default"],bufferController:y["default"],capLevelController:T["default"],fpsController:h["default"],stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystems:{},drmSystemOptions:{},requestMediaKeySystemAccessFunc:I.requestMediaKeySystemAccess,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0},function(){return{cueHandler:k["default"],enableWebVTT:!0,enableIMSC1:!0,enableCEA708Captions:!0,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}}()),{},{subtitleStreamController:m.SubtitleStreamController,subtitleTrackController:p["default"],timelineController:E.TimelineController,audioStreamController:g["default"],audioTrackController:f["default"],emeController:S["default"],cmcdController:v["default"]})},"./src/controller/abr-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{default:()=>m});var o=r("./src/polyfills/number.ts"),d=r("./src/utils/ewma-bandwidth-estimator.ts"),l=r("./src/events.ts"),u=r("./src/errors.ts"),c=r("./src/types/loader.ts"),g=r("./src/utils/logger.ts"),f=function(){function e(e){this.hls=void 0,this.lastLoadedFragLevel=0,this._nextAutoLevel=-1,this.timer=void 0,this.onCheck=this._abandonRulesCheck.bind(this),this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this.hls=e;var t=e.config;this.bwEstimator=new d["default"](t.abrEwmaSlowVoD,t.abrEwmaFastVoD,t.abrEwmaDefaultEstimate),this.registerListeners()}var t=e.prototype;return t.registerListeners=function(){var e=this.hls;e.on(l.Events.FRAG_LOADING,this.onFragLoading,this),e.on(l.Events.FRAG_LOADED,this.onFragLoaded,this),e.on(l.Events.FRAG_BUFFERED,this.onFragBuffered,this),e.on(l.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.on(l.Events.ERROR,this.onError,this)},t.unregisterListeners=function(){var e=this.hls;e.off(l.Events.FRAG_LOADING,this.onFragLoading,this),e.off(l.Events.FRAG_LOADED,this.onFragLoaded,this),e.off(l.Events.FRAG_BUFFERED,this.onFragBuffered,this),e.off(l.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.off(l.Events.ERROR,this.onError,this)},t.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this.onCheck=null,this.fragCurrent=this.partCurrent=null},t.onFragLoading=function(e,t){var r=t.frag;if(r.type===c.PlaylistLevelType.MAIN&&!this.timer){var a;this.fragCurrent=r,this.partCurrent=null==(a=t.part)?null:a,this.timer=self.setInterval(this.onCheck,100)}},t.onLevelLoaded=function(e,t){var r=this.hls.config;t.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)},t._abandonRulesCheck=function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls,a=r.autoLevelEnabled,n=r.media;if(e&&n){var s=t?t.stats:e.stats,i=t?t.duration:e.duration;if(s.aborted||s.loaded&&s.loaded===s.total||0===e.level)return this.clearTimer(),void(this._nextAutoLevel=-1);if(a&&!n.paused&&n.playbackRate&&n.readyState){var d=r.mainForwardBufferInfo;if(null!==d){var u=performance.now()-s.loading.start,c=Math.abs(n.playbackRate);if(!(u<=500*i/c)){var f=s.loaded&&s.loading.first,m=this.bwEstimator.getEstimate(),p=r.levels,y=r.minAutoLevel,E=p[e.level],T=s.total||Math.max(s.loaded,Math.round(i*E.maxBitrate/8)),h=f?1e3*s.loaded/u:0,S=h?(T-s.loaded)/h:8*T/m,v=d.len/c;if(!(S<=v)){var L=Number.POSITIVE_INFINITY,D;for(D=e.level-1;D>y;D--){var k=p[D].maxBitrate;if(L=h?i*k/(8*.8*h):i*k/m,L<v)break}L>=S||(g.logger.warn("Fragment "+e.sn+(t?" part "+t.index:"")+" of level "+e.level+" is loading too slowly and will cause an underbuffer; aborting and switching to level "+D+"\n      Current BW estimate: "+((0,o.isFiniteNumber)(m)?(m/1024).toFixed(3):"Unknown")+" Kb/s\n      Estimated load time for current fragment: "+S.toFixed(3)+" s\n      Estimated load time for the next fragment: "+L.toFixed(3)+" s\n      Time to underbuffer: "+v.toFixed(3)+" s"),r.nextLoadLevel=D,f&&this.bwEstimator.sample(u,s.loaded),this.clearTimer(),(e.loader||e.keyLoader)&&(this.fragCurrent=this.partCurrent=null,e.abortRequests()),r.trigger(l.Events.FRAG_LOAD_EMERGENCY_ABORTED,{frag:e,part:t,stats:s}))}}}}}},t.onFragLoaded=function(e,t){var r=t.frag,a=t.part;if(r.type===c.PlaylistLevelType.MAIN&&(0,o.isFiniteNumber)(r.sn)){var n=a?a.stats:r.stats,s=a?a.duration:r.duration;if(this.clearTimer(),this.lastLoadedFragLevel=r.level,this._nextAutoLevel=-1,this.hls.config.abrMaxWithRealBitrate){var i=this.hls.levels[r.level],d=(i.loaded?i.loaded.bytes:0)+n.loaded,u=(i.loaded?i.loaded.duration:0)+s;i.loaded={bytes:d,duration:u},i.realBitrate=Math.round(8*d/u)}if(r.bitrateTest){var g={stats:n,frag:r,part:a,id:r.type};this.onFragBuffered(l.Events.FRAG_BUFFERED,g)}}},t.onFragBuffered=function(e,t){var r=t.frag,a=t.part,n=a?a.stats:r.stats;if(!n.aborted&&r.type===c.PlaylistLevelType.MAIN&&"initSegment"!==r.sn){var s=n.parsing.end-n.loading.start;this.bwEstimator.sample(s,n.loaded),n.bwEstimate=this.bwEstimator.getEstimate(),this.bitrateTestDelay=r.bitrateTest?s/1e3:0}},t.onError=function(e,t){var r;if((null===(r=t.frag)||void 0===r?void 0:r.type)===c.PlaylistLevelType.MAIN){if(t.type===u.ErrorTypes.KEY_SYSTEM_ERROR)return void this.clearTimer();switch(t.details){case u.ErrorDetails.FRAG_LOAD_ERROR:case u.ErrorDetails.FRAG_LOAD_TIMEOUT:case u.ErrorDetails.KEY_LOAD_ERROR:case u.ErrorDetails.KEY_LOAD_TIMEOUT:this.clearTimer();break;default:}}},t.clearTimer=function(){self.clearInterval(this.timer),this.timer=void 0},t.getNextABRAutoLevel=function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls,a=r.maxAutoLevel,n=r.config,s=r.minAutoLevel,i=r.media,o=t?t.duration:e?e.duration:0,d=i&&0!==i.playbackRate?Math.abs(i.playbackRate):1,l=this.bwEstimator?this.bwEstimator.getEstimate():n.abrEwmaDefaultEstimate,u=r.mainForwardBufferInfo,c=(u?u.len:0)/d,f=this.findBestLevel(l,s,a,c,n.abrBandWidthFactor,n.abrBandWidthUpFactor);if(0<=f)return f;g.logger.trace((c?"rebuffering expected":"buffer is empty")+", finding optimal quality level");var m=o?Math.min(o,n.maxStarvationDelay):n.maxStarvationDelay,p=n.abrBandWidthFactor,y=n.abrBandWidthUpFactor;if(!c){var E=this.bitrateTestDelay;if(E){var T=o?Math.min(o,n.maxLoadingDelay):n.maxLoadingDelay;m=T-E,g.logger.trace("bitrate test took "+Math.round(1e3*E)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*m)+" ms"),p=y=1}}return f=this.findBestLevel(l,s,a,c+m,p,y),Math.max(f,0)},t.findBestLevel=function(e,t,r,a,n,s){for(var d=this.fragCurrent,l=this.partCurrent,u=this.lastLoadedFragLevel,c=this.hls.levels,f=c[u],m=!!(null!==f&&void 0!==f&&null!==(T=f.details)&&void 0!==T&&T.live),p=null===f||void 0===f?void 0:f.codecSet,y=l?l.duration:d?d.duration:0,E=r,T,h;E>=t;E--)if(h=c[E],h&&(!p||h.codecSet===p)){var S=h.details,v=(l?null===S||void 0===S?void 0:S.partTarget:null===S||void 0===S?void 0:S.averagetargetduration)||y,L=void 0;L=E<=u?n*e:s*e;var D=c[E].maxBitrate,k=D*v/L;if(g.logger.trace("level/adjustedbw/bitrate/avgDuration/maxFetchDuration/fetchDuration: "+E+"/"+Math.round(L)+"/"+D+"/"+v+"/"+a+"/"+k),L>D&&(0===k||!(0,o.isFiniteNumber)(k)||m&&!this.bitrateTestDelay||k<a))return E}return-1},n(e,[{key:"nextAutoLevel",get:function(){var e=this._nextAutoLevel,t=this.bwEstimator;if(-1!==e&&!t.canEstimate())return e;var r=this.getNextABRAutoLevel();return-1!==e&&this.hls.levels[r].loadError?e:(-1!==e&&(r=Math.min(e,r)),r)},set:function(e){this._nextAutoLevel=e}}]),e}();const m=f},"./src/controller/audio-stream-controller.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,s(e,t)}function s(e,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},s(e,t)}r.r(t),r.d(t,{default:()=>v});var i=r("./src/polyfills/number.ts"),o=r("./src/controller/base-stream-controller.ts"),d=r("./src/events.ts"),l=r("./src/utils/buffer-helper.ts"),u=r("./src/controller/fragment-tracker.ts"),c=r("./src/types/level.ts"),g=r("./src/types/loader.ts"),f=r("./src/loader/fragment.ts"),m=r("./src/demux/chunk-cache.ts"),p=r("./src/demux/transmuxer-interface.ts"),y=r("./src/types/transmuxer.ts"),E=r("./src/controller/fragment-finders.ts"),T=r("./src/utils/discontinuities.ts"),h=r("./src/errors.ts"),S=function(e){function t(t,r,a){var n;return n=e.call(this,t,r,a,"[audio-stream-controller]")||this,n.videoBuffer=null,n.videoTrackCC=-1,n.waitingVideoCC=-1,n.audioSwitch=!1,n.trackId=-1,n.waitingData=null,n.mainDetails=null,n.bufferFlushed=!1,n.cachedTrackLoadedData=null,n._registerListeners(),n}n(t,e);var r=t.prototype;return r.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},r._registerListeners=function(){var e=this.hls;e.on(d.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(d.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(d.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(d.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.on(d.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),e.on(d.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(d.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.on(d.Events.ERROR,this.onError,this),e.on(d.Events.BUFFER_RESET,this.onBufferReset,this),e.on(d.Events.BUFFER_CREATED,this.onBufferCreated,this),e.on(d.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(d.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),e.on(d.Events.FRAG_BUFFERED,this.onFragBuffered,this)},r._unregisterListeners=function(){var e=this.hls;e.off(d.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(d.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(d.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(d.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.off(d.Events.AUDIO_TRACKS_UPDATED,this.onAudioTracksUpdated,this),e.off(d.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(d.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.off(d.Events.ERROR,this.onError,this),e.off(d.Events.BUFFER_RESET,this.onBufferReset,this),e.off(d.Events.BUFFER_CREATED,this.onBufferCreated,this),e.off(d.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(d.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),e.off(d.Events.FRAG_BUFFERED,this.onFragBuffered,this)},r.onInitPtsFound=function(e,t){var r=t.frag,a=t.id,n=t.initPTS;if("main"===a){var s=r.cc;this.initPTS[r.cc]=n,this.log("InitPTS for cc: "+s+" found from main: "+n),this.videoTrackCC=s,this.state===o.State.WAITING_INIT_PTS&&this.tick()}},r.startLoad=function(e){if(!this.levels)return this.startPosition=e,void(this.state=o.State.STOPPED);var t=this.lastCurrentTime;this.stopLoad(),this.setInterval(100),this.fragLoadError=0,0<t&&-1===e?(this.log("Override startPosition with lastCurrentTime @"+t.toFixed(3)),e=t,this.state=o.State.IDLE):(this.loadedmetadata=!1,this.state=o.State.WAITING_TRACK),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()},r.doTick=function(){switch(this.state){case o.State.IDLE:this.doTickIdle();break;case o.State.WAITING_TRACK:{var t=this.levels,r=this.trackId,a=null===t||void 0===t||null===(n=t[r])||void 0===n?void 0:n.details,n;if(a){if(this.waitForCdnTuneIn(a))break;this.state=o.State.WAITING_INIT_PTS}break}case o.State.FRAG_LOADING_WAITING_RETRY:{var s=performance.now(),i=this.retryDate,d;(!i||s>=i||null!==(d=this.media)&&void 0!==d&&d.seeking)&&(this.log("RetryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.trackId),this.state=o.State.IDLE);break}case o.State.WAITING_INIT_PTS:{var u=this.waitingData;if(u){var c=u.frag,g=u.part,f=u.cache,m=u.complete;if(void 0!==this.initPTS[c.cc]){this.waitingData=null,this.waitingVideoCC=-1,this.state=o.State.FRAG_LOADING;var p=f.flush(),y={frag:c,part:g,payload:p,networkDetails:null};this._handleFragmentLoadProgress(y),m&&e.prototype._handleFragmentLoadComplete.call(this,y)}else if(this.videoTrackCC!==this.waitingVideoCC)this.log("Waiting fragment cc ("+c.cc+") cancelled because video is at cc "+this.videoTrackCC),this.clearWaitingFragment();else{var T=this.getLoadPosition(),h=l.BufferHelper.bufferInfo(this.mediaBuffer,T,this.config.maxBufferHole),S=(0,E.fragmentWithinToleranceTest)(h.end,this.config.maxFragLookUpTolerance,c);0>S&&(this.log("Waiting fragment cc ("+c.cc+") @ "+c.start+" cancelled because another fragment at "+h.end+" is needed"),this.clearWaitingFragment())}}else this.state=o.State.IDLE}}this.onTickEnd()},r.clearWaitingFragment=function(){var e=this.waitingData;e&&(this.fragmentTracker.removeFragment(e.frag),this.waitingData=null,this.waitingVideoCC=-1,this.state=o.State.IDLE)},r.resetLoadingState=function(){this.clearWaitingFragment(),e.prototype.resetLoadingState.call(this)},r.onTickEnd=function(){var e=this.media;e&&e.readyState&&(this.lastCurrentTime=e.currentTime)},r.doTickIdle=function(){var e=this.hls,t=this.levels,r=this.media,a=this.trackId,n=e.config;if(t&&t[a]&&(r||!this.startFragRequested&&n.startFragPrefetch)){var s=t[a],i=s.details;if(!i||i.live&&this.levelLastLoaded!==a||this.waitForCdnTuneIn(i))return void(this.state=o.State.WAITING_TRACK);var l=this.mediaBuffer?this.mediaBuffer:this.media;this.bufferFlushed&&l&&(this.bufferFlushed=!1,this.afterBufferFlushed(l,f.ElementaryStreamTypes.AUDIO,g.PlaylistLevelType.AUDIO));var u=this.getFwdBufferInfo(l,g.PlaylistLevelType.AUDIO);if(null!==u){var c=this.audioSwitch;if(!c&&this._streamEnded(u,i))return e.trigger(d.Events.BUFFER_EOS,{type:"audio"}),void(this.state=o.State.ENDED);var m=this.getFwdBufferInfo(this.videoBuffer?this.videoBuffer:this.media,g.PlaylistLevelType.MAIN),p=u.len,y=this.getMaxBufferLength(null===m||void 0===m?void 0:m.len);if(!(p>=y)||c){var E=i.fragments,T=E[0].start,h=u.end;if(c&&r){var S=this.getLoadPosition();h=S,i.PTSKnown&&S<T&&(u.end>T||u.nextStart)&&(this.log("Alt audio track ahead of main track, seek to start of alt audio track"),r.currentTime=T+.05)}if(!(m&&h>m.end+i.targetduration)&&(m&&m.len||!u.len)){var v=this.getNextFragment(h,i);return v?void this.loadFragment(v,i,h):void(this.bufferFlushed=!0)}}}}},r.getMaxBufferLength=function(t){var r=e.prototype.getMaxBufferLength.call(this);return t?Math.max(r,t):r},r.onMediaDetaching=function(){this.videoBuffer=null,e.prototype.onMediaDetaching.call(this)},r.onAudioTracksUpdated=function(e,t){var r=t.audioTracks;this.resetTransmuxer(),this.levels=r.map(function(e){return new c.Level(e)})},r.onAudioTrackSwitching=function(e,t){var r=!!t.url;this.trackId=t.id;var a=this.fragCurrent;a&&a.abortRequests(),this.fragCurrent=null,this.clearWaitingFragment(),r?this.setInterval(100):this.resetTransmuxer(),r?(this.audioSwitch=!0,this.state=o.State.IDLE):this.state=o.State.STOPPED,this.tick()},r.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments(),this.startPosition=this.lastCurrentTime=0,this.bufferFlushed=!1},r.onLevelLoaded=function(e,t){this.mainDetails=t.details,null!==this.cachedTrackLoadedData&&(this.hls.trigger(d.Events.AUDIO_TRACK_LOADED,this.cachedTrackLoadedData),this.cachedTrackLoadedData=null)},r.onAudioTrackLoaded=function(e,t){var r;if(null==this.mainDetails)return void(this.cachedTrackLoadedData=t);var a=this.levels,n=t.details,s=t.id;if(!a)return void this.warn("Audio tracks were reset while loading level "+s);this.log("Track "+s+" loaded ["+n.startSN+","+n.endSN+"],duration:"+n.totalduration);var i=a[s],d=0;if(n.live||null!==(r=i.details)&&void 0!==r&&r.live){var l=this.mainDetails;if(n.fragments[0]||(n.deltaUpdateFailed=!0),n.deltaUpdateFailed||!l)return;!i.details&&n.hasProgramDateTime&&l.hasProgramDateTime?((0,T.alignMediaPlaylistByPDT)(n,l),d=n.fragments[0].start):d=this.alignPlaylists(n,i.details)}i.details=n,this.levelLastLoaded=s,this.startFragRequested||!this.mainDetails&&n.live||this.setStartPosition(i.details,d),this.state!==o.State.WAITING_TRACK||this.waitForCdnTuneIn(n)||(this.state=o.State.IDLE),this.tick()},r._handleFragmentLoadProgress=function(e){var t=e.frag,r=e.part,a=e.payload,n=this.config,s=this.trackId,i=this.levels,d;if(!i)return void this.warn("Audio tracks were reset while fragment load was in progress. Fragment "+t.sn+" of level "+t.level+" will not be buffered");var l=i[s];console.assert(l,"Audio track is defined on fragment load progress");var u=l.details;console.assert(u,"Audio track details are defined on fragment load progress");var c=n.defaultAudioCodec||l.audioCodec||"mp4a.40.2",f=this.transmuxer;f||(f=this.transmuxer=new p["default"](this.hls,g.PlaylistLevelType.AUDIO,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)));var E=this.initPTS[t.cc],T=null===(d=t.initSegment)||void 0===d?void 0:d.data;if(void 0!==E){var h=r?r.index:-1,S=new y.ChunkMetadata(t.level,t.sn,t.stats.chunkCount,a.byteLength,h,-1!==h);f.push(a,T,c,"",t,r,u.totalduration,!1,S,E)}else{this.log("Unknown video PTS for cc "+t.cc+", waiting for video PTS before demuxing audio frag "+t.sn+" of ["+u.startSN+" ,"+u.endSN+"],track "+s);var v=this.waitingData=this.waitingData||{frag:t,part:r,cache:new m["default"],complete:!1},L=v.cache;L.push(new Uint8Array(a)),this.waitingVideoCC=this.videoTrackCC,this.state=o.State.WAITING_INIT_PTS}},r._handleFragmentLoadComplete=function(t){return this.waitingData?void(this.waitingData.complete=!0):void e.prototype._handleFragmentLoadComplete.call(this,t)},r.onBufferReset=function(){this.mediaBuffer=this.videoBuffer=null,this.loadedmetadata=!1},r.onBufferCreated=function(e,t){var r=t.tracks.audio;r&&(this.mediaBuffer=r.buffer||null),t.tracks.video&&(this.videoBuffer=t.tracks.video.buffer||null)},r.onFragBuffered=function(e,t){var r=t.frag,a=t.part;if(r.type!==g.PlaylistLevelType.AUDIO){if(!this.loadedmetadata&&r.type===g.PlaylistLevelType.MAIN){var n;null!==(n=this.videoBuffer||this.media)&&void 0!==n&&n.buffered.length&&(this.loadedmetadata=!0)}return}return this.fragContextChanged(r)?void this.warn("Fragment "+r.sn+(a?" p: "+a.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state+", audioSwitch: "+this.audioSwitch):void("initSegment"!==r.sn&&(this.fragPrevious=r,this.audioSwitch&&(this.audioSwitch=!1,this.hls.trigger(d.Events.AUDIO_TRACK_SWITCHED,{id:this.trackId}))),this.fragBufferedComplete(r,a))},r.onError=function(t,r){if(r.type===h.ErrorTypes.KEY_SYSTEM_ERROR)return void this.onFragmentOrKeyLoadError(g.PlaylistLevelType.AUDIO,r);switch(r.details){case h.ErrorDetails.FRAG_LOAD_ERROR:case h.ErrorDetails.FRAG_LOAD_TIMEOUT:case h.ErrorDetails.FRAG_PARSING_ERROR:case h.ErrorDetails.KEY_LOAD_ERROR:case h.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(g.PlaylistLevelType.AUDIO,r);break;case h.ErrorDetails.AUDIO_TRACK_LOAD_ERROR:case h.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:this.state!==o.State.ERROR&&this.state!==o.State.STOPPED&&(this.state=r.fatal?o.State.ERROR:o.State.IDLE,this.warn(r.details+" while loading frag, switching to "+this.state+" state"));break;case h.ErrorDetails.BUFFER_FULL_ERROR:if("audio"===r.parent&&(this.state===o.State.PARSING||this.state===o.State.PARSED)){var a=!0,n=this.getFwdBufferInfo(this.mediaBuffer,g.PlaylistLevelType.AUDIO);n&&.5<n.len&&(a=!this.reduceMaxBufferLength(n.len)),a&&(this.warn("Buffer full error also media.currentTime is not buffered, flush audio buffer"),this.fragCurrent=null,e.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.resetLoadingState()}break;default:}},r.onBufferFlushed=function(e,t){var r=t.type;r===f.ElementaryStreamTypes.AUDIO&&(this.bufferFlushed=!0,this.state===o.State.ENDED&&(this.state=o.State.IDLE))},r._handleTransmuxComplete=function(e){var t=this.hls,r=e.remuxResult,n=e.chunkMeta,s=this.getCurrentContext(n),i;if(!s)return this.warn("The loading context changed while buffering fragment "+n.sn+" of level "+n.level+". This chunk will not be buffered."),void this.resetStartWhenNotLoaded(n.level);var l=s.frag,u=s.part,c=s.level.details,g=r.audio,m=r.text,p=r.id3,y=r.initSegment;if(!this.fragContextChanged(l)&&c){if(this.state=o.State.PARSING,this.audioSwitch&&g&&this.completeAudioSwitch(),null!==y&&void 0!==y&&y.tracks&&(this._bufferInitSegment(y.tracks,l,n),t.trigger(d.Events.FRAG_PARSING_INIT_SEGMENT,{frag:l,id:"audio",tracks:y.tracks})),g){var E=g.startPTS,T=g.endPTS,h=g.startDTS,S=g.endDTS;u&&(u.elementaryStreams[f.ElementaryStreamTypes.AUDIO]={startPTS:E,endPTS:T,startDTS:h,endDTS:S}),l.setElementaryStreamInfo(f.ElementaryStreamTypes.AUDIO,E,T,h,S),this.bufferFragmentData(g,l,u,n)}if(null!==p&&void 0!==p&&null!==(i=p.samples)&&void 0!==i&&i.length){var v=a({id:"audio",frag:l,details:c},p);t.trigger(d.Events.FRAG_PARSING_METADATA,v)}if(m){var L=a({id:"audio",frag:l,details:c},m);t.trigger(d.Events.FRAG_PARSING_USERDATA,L)}}},r._bufferInitSegment=function(e,t,r){if(this.state===o.State.PARSING){e.video&&delete e.video;var a=e.audio;if(a){a.levelCodec=a.codec,a.id="audio",this.log("Init audio buffer, container:"+a.container+", codecs[parsed]=["+a.codec+"]"),this.hls.trigger(d.Events.BUFFER_CODECS,e);var n=a.initSegment;if(null!==n&&void 0!==n&&n.byteLength){var s={type:"audio",frag:t,part:null,chunkMeta:r,parent:t.type,data:n};this.hls.trigger(d.Events.BUFFER_APPENDING,s)}this.tick()}}},r.loadFragment=function(t,r,a){var n=this.fragmentTracker.getState(t);this.fragCurrent=t,(this.audioSwitch||n===u.FragmentState.NOT_LOADED||n===u.FragmentState.PARTIAL)&&("initSegment"===t.sn?this._loadInitSegment(t,r):r.live&&!(0,i.isFiniteNumber)(this.initPTS[t.cc])?(this.log("Waiting for video PTS in continuity counter "+t.cc+" of live stream before loading audio fragment "+t.sn+" of level "+this.trackId),this.state=o.State.WAITING_INIT_PTS):(this.startFragRequested=!0,e.prototype.loadFragment.call(this,t,r,a)))},r.completeAudioSwitch=function(){var t=this.hls,r=this.media,a=this.trackId;r&&(this.log("Switching audio track : flushing all audio"),e.prototype.flushMainBuffer.call(this,0,Number.POSITIVE_INFINITY,"audio")),this.audioSwitch=!1,t.trigger(d.Events.AUDIO_TRACK_SWITCHED,{id:a})},t}(o["default"]);const v=S},"./src/controller/audio-track-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}r.r(t),r.d(t,{default:()=>m});var l=r("./src/events.ts"),u=r("./src/errors.ts"),c=r("./src/controller/base-playlist-controller.ts"),g=r("./src/types/loader.ts"),f=function(e){function t(t){var r;return r=e.call(this,t,"[audio-track-controller]")||this,r.tracks=[],r.groupId=null,r.tracksInGroup=[],r.trackId=-1,r.trackName="",r.selectDefaultTrack=!0,r.registerListeners(),r}o(t,e);var r=t.prototype;return r.registerListeners=function(){var e=this.hls;e.on(l.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(l.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.on(l.Events.LEVEL_LOADING,this.onLevelLoading,this),e.on(l.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(l.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.on(l.Events.ERROR,this.onError,this)},r.unregisterListeners=function(){var e=this.hls;e.off(l.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(l.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.off(l.Events.LEVEL_LOADING,this.onLevelLoading,this),e.off(l.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(l.Events.AUDIO_TRACK_LOADED,this.onAudioTrackLoaded,this),e.off(l.Events.ERROR,this.onError,this)},r.destroy=function(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,e.prototype.destroy.call(this)},r.onManifestLoading=function(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.trackName="",this.selectDefaultTrack=!0},r.onManifestParsed=function(e,t){this.tracks=t.audioTracks||[]},r.onAudioTrackLoaded=function(e,t){var r=t.id,a=t.details,n=this.tracksInGroup[r];if(!n)return void this.warn("Invalid audio track id "+r);var s=n.details;n.details=t.details,this.log("audioTrack "+r+" loaded ["+a.startSN+"-"+a.endSN+"]"),r===this.trackId&&(this.retryCount=0,this.playlistLoaded(r,t,s))},r.onLevelLoading=function(e,t){this.switchLevel(t.level)},r.onLevelSwitching=function(e,t){this.switchLevel(t.level)},r.switchLevel=function(e){var t=this.hls.levels[e];if(null!==t&&void 0!==t&&t.audioGroupIds){var r=t.audioGroupIds[t.urlId];if(this.groupId!==r){this.groupId=r;var a=this.tracks.filter(function(e){return!r||e.groupId===r});this.selectDefaultTrack&&!a.some(function(e){return e.default})&&(this.selectDefaultTrack=!1),this.tracksInGroup=a;this.log("Updating audio tracks, "+a.length+" track(s) found in \""+r+"\" group-id"),this.hls.trigger(l.Events.AUDIO_TRACKS_UPDATED,{audioTracks:a}),this.selectInitialTrack()}}},r.onError=function(t,r){e.prototype.onError.call(this,t,r),r.fatal||!r.context||r.context.type===g.PlaylistContextType.AUDIO_TRACK&&r.context.id===this.trackId&&r.context.groupId===this.groupId&&this.retryLoadingOrFail(r)},r.setAudioTrack=function(e){var t=this.tracksInGroup;if(0>e||e>=t.length)return void this.warn("Invalid id passed to audio-track controller");this.clearTimer();var r=t[this.trackId];this.log("Now switching to audio-track index "+e);var a=t[e],n=a.id,s=a.groupId,i=void 0===s?"":s,o=a.name,d=a.type,u=a.url;if(this.trackId=e,this.trackName=o,this.selectDefaultTrack=!1,this.hls.trigger(l.Events.AUDIO_TRACK_SWITCHING,{id:n,groupId:i,name:o,type:d,url:u}),!a.details||a.details.live){var c=this.switchParams(a.url,null===r||void 0===r?void 0:r.details);this.loadPlaylist(c)}},r.selectInitialTrack=function(){var e=this.tracksInGroup;console.assert(e.length,"Initial audio track should be selected when tracks are known");var t=this.trackName,r=this.findTrackId(t)||this.findTrackId();-1===r?(this.warn("No track found for running audio group-ID: "+this.groupId),this.hls.trigger(l.Events.ERROR,{type:u.ErrorTypes.MEDIA_ERROR,details:u.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,fatal:!0})):this.setAudioTrack(r)},r.findTrackId=function(e){for(var t=this.tracksInGroup,r=0,a;r<t.length;r++)if(a=t[r],(!this.selectDefaultTrack||a.default)&&(!e||e===a.name))return a.id;return-1},r.loadPlaylist=function(t){e.prototype.loadPlaylist.call(this);var r=this.tracksInGroup[this.trackId];if(this.shouldLoadTrack(r)){var a=r.id,n=r.groupId,s=r.url;if(t)try{s=t.addDirectives(s)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: "+e)}this.log("loading audio-track playlist for id: "+a),this.clearTimer(),this.hls.trigger(l.Events.AUDIO_TRACK_LOADING,{url:s,id:a,groupId:n,deliveryDirectives:t||null})}},n(t,[{key:"audioTracks",get:function(){return this.tracksInGroup}},{key:"audioTrack",get:function(){return this.trackId},set:function(e){this.selectDefaultTrack=!1,this.setAudioTrack(e)}}]),t}(c["default"]);const m=f},"./src/controller/base-playlist-controller.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>o});var a=r("./src/types/level.ts"),n=r("./src/controller/level-helper.ts"),s=r("./src/utils/logger.ts"),i=r("./src/errors.ts"),o=function(){function e(e,t){this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.retryCount=0,this.log=void 0,this.warn=void 0,this.log=s.logger.log.bind(s.logger,t+":"),this.warn=s.logger.warn.bind(s.logger,t+":"),this.hls=e}var t=e.prototype;return t.destroy=function(){this.clearTimer(),this.hls=this.log=this.warn=null},t.onError=function(e,t){t.fatal&&(t.type===i.ErrorTypes.NETWORK_ERROR||t.type===i.ErrorTypes.KEY_SYSTEM_ERROR)&&this.stopLoad()},t.clearTimer=function(){clearTimeout(this.timer),this.timer=-1},t.startLoad=function(){this.canLoad=!0,this.retryCount=0,this.requestScheduled=-1,this.loadPlaylist()},t.stopLoad=function(){this.canLoad=!1,this.clearTimer()},t.switchParams=function(e,t){var r=null===t||void 0===t?void 0:t.renditionReports;if(r)for(var n=0;n<r.length;n++){var o=r[n],d=void 0;try{d=new self.URL(o.URI,t.url).href}catch(e){s.logger.warn("Could not construct new URL for Rendition Report: "+e),d=o.URI||""}if(d===e.slice(-d.length)){var l=parseInt(o["LAST-MSN"])||(null===t||void 0===t?void 0:t.lastPartSn),u=parseInt(o["LAST-PART"])||(null===t||void 0===t?void 0:t.lastPartIndex);if(this.hls.config.lowLatencyMode){var c=Math.min(t.age-t.partTarget,t.targetduration);0<=u&&c>t.partTarget&&(u+=1)}return new a.HlsUrlParameters(l,0<=u?u:void 0,a.HlsSkip.No)}}},t.loadPlaylist=function(){-1===this.requestScheduled&&(this.requestScheduled=self.performance.now())},t.shouldLoadTrack=function(e){return this.canLoad&&e&&!!e.url&&(!e.details||e.details.live)},t.playlistLoaded=function(e,t,r){var a=this,s=t.details,i=t.stats,o=self.performance.now(),d=i.loading.first?Math.max(0,o-i.loading.first):0;if(s.advancedDateTime=Date.now()-d,s.live||null!==r&&void 0!==r&&r.live){if(s.reloaded(r),r&&this.log("live playlist "+e+" "+(s.advanced?"REFRESHED "+s.lastPartSn+"-"+s.lastPartIndex:"MISSED")),r&&0<s.fragments.length&&(0,n.mergeDetails)(r,s),!this.canLoad||!s.live)return;var l=void 0,u=void 0,c;if(s.canBlockReload&&s.endSN&&s.advanced){var g=this.hls.config.lowLatencyMode,f=s.lastPartSn,m=s.endSN,p=s.lastPartIndex,y=f===m,E=g?0:p;-1!==p?(l=y?m+1:f,u=y?E:p+1):l=m+1;var T=s.age,h=T+s.ageHeader,S=Math.min(h-s.partTarget,1.5*s.targetduration);if(0<S){if(r&&S>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+r.tuneInGoal+" to: "+S+" with playlist age: "+s.age),S=0;else{var v=Math.floor(S/s.targetduration);if(l+=v,void 0!==u){var L=Math.round(S%s.targetduration/s.partTarget);u+=L}this.log("CDN Tune-in age: "+s.ageHeader+"s last advanced "+T.toFixed(2)+"s goal: "+S+" skip sn "+v+" to part "+u)}s.tuneInGoal=S}if(c=this.getDeliveryDirectives(s,t.deliveryDirectives,l,u),g||!y)return void this.loadPlaylist(c)}else c=this.getDeliveryDirectives(s,t.deliveryDirectives,l,u);var D=this.hls.mainForwardBufferInfo,k=D?D.end-D.len:0,I=1e3*(s.edge-k),A=(0,n.computeReloadInterval)(s,I);s.updated?o>this.requestScheduled+A&&(this.requestScheduled=i.loading.start):this.requestScheduled=-1,this.requestScheduled=void 0!==l&&s.canBlockReload?i.loading.first+A-(1e3*s.partTarget||1e3):(-1===this.requestScheduled?o:this.requestScheduled)+A;var R=this.requestScheduled-o;R=Math.max(0,R),this.log("reload live playlist "+e+" in "+Math.round(R)+" ms"),this.timer=self.setTimeout(function(){return a.loadPlaylist(c)},R)}else this.clearTimer()},t.getDeliveryDirectives=function(e,t,r,n){var s=(0,a.getSkipValue)(e,r);return null!==t&&void 0!==t&&t.skip&&e.deltaUpdateFailed&&(r=t.msn,n=t.part,s=a.HlsSkip.No),new a.HlsUrlParameters(r,n,s)},t.retryLoadingOrFail=function(e){var t=this,r=this.hls.config,a=this.retryCount<r.levelLoadingMaxRetry;if(a){var n;if(this.requestScheduled=-1,this.retryCount++,-1<e.details.indexOf("LoadTimeOut")&&null!==(n=e.context)&&void 0!==n&&n.deliveryDirectives)this.warn("retry playlist loading #"+this.retryCount+" after \""+e.details+"\""),this.loadPlaylist();else{var s=Math.min(Math.pow(2,this.retryCount)*r.levelLoadingRetryDelay,r.levelLoadingMaxRetryTimeout);this.timer=self.setTimeout(function(){return t.loadPlaylist()},s),this.warn("retry playlist loading #"+this.retryCount+" in "+s+" ms after \""+e.details+"\"")}}else this.warn("cannot recover from error \""+e.details+"\""),this.clearTimer(),e.fatal=!0;return a},e}()},"./src/controller/base-stream-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,l(e,t)}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}r.r(t),r.d(t,{State:()=>A,default:()=>R});var u=r("./src/polyfills/number.ts"),c=r("./src/task-loop.ts"),g=r("./src/controller/fragment-tracker.ts"),f=r("./src/utils/buffer-helper.ts"),m=r("./src/utils/logger.ts"),p=r("./src/events.ts"),y=r("./src/errors.ts"),E=r("./src/types/transmuxer.ts"),T=r("./src/utils/mp4-tools.ts"),h=r("./src/utils/discontinuities.ts"),S=r("./src/controller/fragment-finders.ts"),v=r("./src/controller/level-helper.ts"),L=r("./src/loader/fragment-loader.ts"),D=r("./src/crypt/decrypter.ts"),k=r("./src/utils/time-ranges.ts"),I=r("./src/types/loader.ts"),A={STOPPED:"STOPPED",IDLE:"IDLE",KEY_LOADING:"KEY_LOADING",FRAG_LOADING:"FRAG_LOADING",FRAG_LOADING_WAITING_RETRY:"FRAG_LOADING_WAITING_RETRY",WAITING_TRACK:"WAITING_TRACK",PARSING:"PARSING",PARSED:"PARSED",ENDED:"ENDED",ERROR:"ERROR",WAITING_INIT_PTS:"WAITING_INIT_PTS",WAITING_LEVEL:"WAITING_LEVEL"},R=function(e){function t(t,r,a,n){var s;return s=e.call(this)||this,s.hls=void 0,s.fragPrevious=null,s.fragCurrent=null,s.fragmentTracker=void 0,s.transmuxer=null,s._state=A.STOPPED,s.media=null,s.mediaBuffer=null,s.config=void 0,s.bitrateTest=!1,s.lastCurrentTime=0,s.nextLoadPosition=0,s.startPosition=0,s.loadedmetadata=!1,s.fragLoadError=0,s.retryDate=0,s.levels=null,s.fragmentLoader=void 0,s.keyLoader=void 0,s.levelLastLoaded=null,s.startFragRequested=!1,s.decrypter=void 0,s.initPTS=[],s.onvseeking=null,s.onvended=null,s.logPrefix="",s.log=void 0,s.warn=void 0,s.logPrefix=n,s.log=m.logger.log.bind(m.logger,n+":"),s.warn=m.logger.warn.bind(m.logger,n+":"),s.hls=t,s.fragmentLoader=new L["default"](t.config),s.keyLoader=a,s.fragmentTracker=r,s.config=t.config,s.decrypter=new D["default"](t.config),t.on(p.Events.LEVEL_SWITCHING,s.onLevelSwitching,o(s)),s}d(t,e);var r=t.prototype;return r.doTick=function(){this.onTickEnd()},r.onTickEnd=function(){},r.startLoad=function(){},r.stopLoad=function(){this.fragmentLoader.abort(),this.keyLoader.abort();var e=this.fragCurrent;e&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=A.STOPPED},r._streamEnded=function(e,t){if(t.live||e.nextStart||!e.end||!this.media)return!1;var r=t.partList;if(null!==r&&void 0!==r&&r.length){var a=r[r.length-1],n=f.BufferHelper.isBuffered(this.media,a.start+a.duration/2);return n}var s=t.fragments[t.fragments.length-1].type;return this.fragmentTracker.isEndListAppended(s)},r.getLevelDetails=function(){if(this.levels&&null!==this.levelLastLoaded){var e;return null===(e=this.levels[this.levelLastLoaded])||void 0===e?void 0:e.details}},r.onMediaAttached=function(e,t){var r=this.media=this.mediaBuffer=t.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),r.addEventListener("seeking",this.onvseeking),r.addEventListener("ended",this.onvended);var a=this.config;this.levels&&a.autoStartLoad&&this.state===A.STOPPED&&this.startLoad(a.startPosition)},r.onMediaDetaching=function(){var e=this.media;null!==e&&void 0!==e&&e.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),e&&this.onvseeking&&this.onvended&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.keyLoader&&this.keyLoader.detach(),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()},r.onMediaSeeking=function(){var e=this.config,t=this.fragCurrent,r=this.media,a=this.mediaBuffer,n=this.state,s=r?r.currentTime:0,i=f.BufferHelper.bufferInfo(a?a:r,s,e.maxBufferHole);if(this.log("media seeking to "+((0,u.isFiniteNumber)(s)?s.toFixed(3):s)+", state: "+n),this.state===A.ENDED)this.resetLoadingState();else if(t){var o=e.maxFragLookUpTolerance,d=t.start-o,l=t.start+t.duration+o;if(!i.len||l<i.start||d>i.end){var c=s>l;(s<d||c)&&(c&&t.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),t.abortRequests()),this.resetLoadingState())}}r&&(this.lastCurrentTime=s),this.loadedmetadata||i.len||(this.nextLoadPosition=this.startPosition=s),this.tickImmediate()},r.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},r.onLevelSwitching=function(){this.fragLoadError=0},r.onHandlerDestroying=function(){this.stopLoad(),e.prototype.onHandlerDestroying.call(this)},r.onHandlerDestroyed=function(){this.state=A.STOPPED,this.hls.off(p.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),this.fragmentLoader&&this.fragmentLoader.destroy(),this.keyLoader&&this.keyLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.keyLoader=this.fragmentLoader=this.fragmentTracker=null,e.prototype.onHandlerDestroyed.call(this)},r.loadFragment=function(e,t,r){this._loadFragForPlayback(e,t,r)},r._loadFragForPlayback=function(e,t,r){var a=this;this._doFragLoad(e,t,r,function(t){return a.fragContextChanged(e)?(a.warn("Fragment "+e.sn+(t.part?" p: "+t.part.index:"")+" of level "+e.level+" was dropped during download."),void a.fragmentTracker.removeFragment(e)):void(e.stats.chunkCount++,a._handleFragmentLoadProgress(t))}).then(function(t){if(t){a.fragLoadError=0;var r=a.state;return a.fragContextChanged(e)?void(r!==A.FRAG_LOADING&&(a.fragCurrent||r!==A.PARSING)||(a.fragmentTracker.removeFragment(e),a.state=A.IDLE)):void("payload"in t&&(a.log("Loaded fragment "+e.sn+" of level "+e.level),a.hls.trigger(p.Events.FRAG_LOADED,t)),a._handleFragmentLoadComplete(t))}}).catch(function(t){a.state===A.STOPPED||a.state===A.ERROR||(a.warn(t),a.resetFragmentLoading(e))})},r.flushMainBuffer=function(e,t,r){if(void 0===r&&(r=null),!!(e-t)){var a={startOffset:e,endOffset:t,type:r};this.fragLoadError=0,this.hls.trigger(p.Events.BUFFER_FLUSHING,a)}},r._loadInitSegment=function(e,t){var r=this;this._doFragLoad(e,t).then(function(t){if(!t||r.fragContextChanged(e)||!r.levels)throw new Error("init load aborted");return t}).then(function(t){var a=r.hls,n=t.payload,s=e.decryptdata;if(n&&0<n.byteLength&&s&&s.key&&s.iv&&"AES-128"===s.method){var i=self.performance.now();return r.decrypter.decrypt(new Uint8Array(n),s.key.buffer,s.iv.buffer).then(function(r){var n=self.performance.now();return a.trigger(p.Events.FRAG_DECRYPTED,{frag:e,payload:r,stats:{tstart:i,tdecrypt:n}}),t.payload=r,t})}return t}).then(function(t){var a=r.fragCurrent,n=r.hls,s=r.levels;if(!s)throw new Error("init load aborted, missing levels");var i=s[e.level].details;console.assert(i,"Level details are defined when init segment is loaded");var o=e.stats;r.state=A.IDLE,r.fragLoadError=0,e.data=new Uint8Array(t.payload),o.parsing.start=o.buffering.start=self.performance.now(),o.parsing.end=o.buffering.end=self.performance.now(),t.frag===a&&n.trigger(p.Events.FRAG_BUFFERED,{stats:o,frag:a,part:null,id:e.type}),r.tick()}).catch(function(t){r.state===A.STOPPED||r.state===A.ERROR||(r.warn(t),r.resetFragmentLoading(e))})},r.fragContextChanged=function(e){var t=this.fragCurrent;return!e||!t||e.level!==t.level||e.sn!==t.sn||e.urlId!==t.urlId},r.fragBufferedComplete=function(e,t){var r=this.mediaBuffer?this.mediaBuffer:this.media,a,n,s,i;this.log("Buffered "+e.type+" sn: "+e.sn+(t?" part: "+t.index:"")+" of "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+e.level+" (frag:["+(null==(a=e.startPTS)?NaN:a).toFixed(3)+"-"+(null==(n=e.endPTS)?NaN:n).toFixed(3)+"] > buffer:"+(r?k["default"].toString(f.BufferHelper.getBuffered(r)):"(detached)")+")"),this.state=A.IDLE,r&&(!this.loadedmetadata&&e.type==I.PlaylistLevelType.MAIN&&r.buffered.length&&(null===(s=this.fragCurrent)||void 0===s?void 0:s.sn)===(null===(i=this.fragPrevious)||void 0===i?void 0:i.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())},r.seekToStartPos=function(){},r._handleFragmentLoadComplete=function(e){var t=this.transmuxer;if(t){var r=e.frag,a=e.part,n=e.partsLoaded,s=!n||0===n.length||n.some(function(e){return!e}),i=new E.ChunkMetadata(r.level,r.sn,r.stats.chunkCount+1,0,a?a.index:-1,!s);t.flush(i)}},r._handleFragmentLoadProgress=function(){},r._doFragLoad=function(e,t,r,a){var n=this,s;if(void 0===r&&(r=null),!this.levels)throw new Error("frag load aborted, missing levels");var i=null;if(e.encrypted&&!(null!==(s=e.decryptdata)&&void 0!==s&&s.key)?(this.log("Loading key for "+e.sn+" of ["+t.startSN+"-"+t.endSN+"], "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+e.level),this.state=A.KEY_LOADING,this.fragCurrent=e,i=this.keyLoader.load(e).then(function(e){if(!n.fragContextChanged(e.frag))return n.hls.trigger(p.Events.KEY_LOADED,e),n.state===A.KEY_LOADING&&(n.state=A.IDLE),e}),this.hls.trigger(p.Events.KEY_LOADING,{frag:e}),this.throwIfFragContextChanged("KEY_LOADING")):!e.encrypted&&t.encryptedFragments.length&&this.keyLoader.loadClear(e,t.encryptedFragments),r=Math.max(e.start,r||0),this.config.lowLatencyMode&&t){var o=t.partList;if(o&&a){r>e.end&&t.fragmentHint&&(e=t.fragmentHint);var d=this.getNextPart(o,e,r);if(-1<d){var l=o[d];return this.log("Loading part sn: "+e.sn+" p: "+l.index+" cc: "+e.cc+" of playlist ["+t.startSN+"-"+t.endSN+"] parts [0-"+d+"-"+(o.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+e.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=l.start+l.duration,this.state=A.FRAG_LOADING,this.hls.trigger(p.Events.FRAG_LOADING,{frag:e,part:o[d],targetBufferTime:r}),this.throwIfFragContextChanged("FRAG_LOADING parts"),i?i.then(function(t){return!t||n.fragContextChanged(t.frag)?null:n.doFragPartsLoad(e,o,d,a)}).catch(function(e){return n.handleFragLoadError(e)}):this.doFragPartsLoad(e,o,d,a).catch(function(e){return n.handleFragLoadError(e)})}if(!e.url||this.loadedEndOfParts(o,r))return Promise.resolve(null)}}this.log("Loading fragment "+e.sn+" cc: "+e.cc+" "+(t?"of ["+t.startSN+"-"+t.endSN+"] ":"")+("[stream-controller]"===this.logPrefix?"level":"track")+": "+e.level+", target: "+parseFloat(r.toFixed(3))),(0,u.isFiniteNumber)(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=A.FRAG_LOADING,this.hls.trigger(p.Events.FRAG_LOADING,{frag:e,targetBufferTime:r}),this.throwIfFragContextChanged("FRAG_LOADING");var c=this.config.progressive;return c&&i?i.then(function(t){return!t||n.fragContextChanged(null===t||void 0===t?void 0:t.frag)?null:n.fragmentLoader.load(e,a)}).catch(function(e){return n.handleFragLoadError(e)}):Promise.all([this.fragmentLoader.load(e,c?a:void 0),i]).then(function(e){var t=e[0];return!c&&t&&a&&a(t),t}).catch(function(e){return n.handleFragLoadError(e)})},r.throwIfFragContextChanged=function(e){if(null===this.fragCurrent)throw new Error("frag load aborted, context changed in "+e)},r.doFragPartsLoad=function(e,t,r,a){var n=this;return new Promise(function(s,i){var o=[];(function r(d){var l=t[d];n.fragmentLoader.loadPart(e,l,a).then(function(a){o[l.index]=a;var i=a.part;n.hls.trigger(p.Events.FRAG_LOADED,a);var u=t[d+1];return u&&u.fragment===e?void r(d+1):s({frag:e,part:i,partsLoaded:o})}).catch(i)})(r)})},r.handleFragLoadError=function(e){if("data"in e){var t=e.data;e.data&&t.details===y.ErrorDetails.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(p.Events.ERROR,t)}else this.hls.trigger(p.Events.ERROR,{type:y.ErrorTypes.OTHER_ERROR,details:y.ErrorDetails.INTERNAL_EXCEPTION,err:e,fatal:!0});return null},r._handleTransmuxerFlush=function(e){var t=this.getCurrentContext(e);if(!t||this.state!==A.PARSING)return void(this.fragCurrent||this.state===A.STOPPED||this.state===A.ERROR||(this.state=A.IDLE));var r=t.frag,a=t.part,n=t.level,s=self.performance.now();r.stats.parsing.end=s,a&&(a.stats.parsing.end=s),this.updateLevelTiming(r,a,n,e.partial)},r.getCurrentContext=function(e){var t=this.levels,r=e.level,a=e.sn,n=e.part;if(!t||!t[r])return this.warn("Levels object was unset while buffering fragment "+a+" of level "+r+". The current chunk will not be buffered."),null;var s=t[r],i=-1<n?(0,v.getPartWith)(s,a,n):null,o=i?i.fragment:(0,v.getFragmentWithSN)(s,a,this.fragCurrent);return o?{frag:o,part:i,level:s}:null},r.bufferFragmentData=function(e,t,r,a){if(e&&this.state===A.PARSING){var n=e.data1,s=e.data2,i=n;if(n&&s&&(i=(0,T.appendUint8Array)(n,s)),i&&i.length){var o={type:e.type,frag:t,part:r,chunkMeta:a,parent:t.type,data:i};this.hls.trigger(p.Events.BUFFER_APPENDING,o),e.dropped&&e.independent&&!r&&this.flushBufferGap(t)}}},r.flushBufferGap=function(e){var t=this.media;if(t){if(!f.BufferHelper.isBuffered(t,t.currentTime))return void this.flushMainBuffer(0,e.start);var r=t.currentTime,a=f.BufferHelper.bufferInfo(t,r,0),n=e.duration,s=Math.min(2*this.config.maxFragLookUpTolerance,.25*n),i=Math.max(Math.min(e.start-s,a.end-s),r+s);e.start-i>s&&this.flushMainBuffer(i,e.start)}},r.getFwdBufferInfo=function(e,t){var r=this.config,a=this.getLoadPosition();if(!(0,u.isFiniteNumber)(a))return null;var n=f.BufferHelper.bufferInfo(e,a,r.maxBufferHole);if(0===n.len&&void 0!==n.nextStart){var s=this.fragmentTracker.getBufferedFrag(a,t);if(s&&n.nextStart<s.end)return f.BufferHelper.bufferInfo(e,a,Math.max(n.nextStart,r.maxBufferHole))}return n},r.getMaxBufferLength=function(e){var t=this.config,r;return r=e?Math.max(8*t.maxBufferSize/e,t.maxBufferLength):t.maxBufferLength,Math.min(r,t.maxMaxBufferLength)},r.reduceMaxBufferLength=function(e){var t=this.config,r=e||t.maxBufferLength;return!!(t.maxMaxBufferLength>=r)&&(t.maxMaxBufferLength/=2,this.warn("Reduce max buffer length to "+t.maxMaxBufferLength+"s"),!0)},r.getNextFragment=function(e,t){var r=t.fragments,a=r.length;if(!a)return null;var n=this.config,s=r[0].start,i;if(t.live){var o=n.initialLiveManifestSize;if(a<o)return this.warn("Not enough fragments to start playback (have: "+a+", need: "+o+")"),null;t.PTSKnown||this.startFragRequested||-1!==this.startPosition||(i=this.getInitialLiveFragment(t,r),this.startPosition=i?this.hls.liveSyncPosition||i.start:e)}else e<=s&&(i=r[0]);if(!i){var d=n.lowLatencyMode?t.partEnd:t.fragmentEnd;i=this.getFragmentAtPosition(e,d,t)}return this.mapToInitFragWhenRequired(i)},r.mapToInitFragWhenRequired=function(e){return null===e||void 0===e||!e.initSegment||null!==e&&void 0!==e&&e.initSegment.data||this.bitrateTest?e:e.initSegment},r.getNextPart=function(e,t,r){for(var a=-1,n=!1,s=!0,o=0,d=e.length,l,u;o<d&&(l=e[o],s=s&&!l.independent,!(-1<a&&r<l.start));o++)u=l.loaded,u?a=-1:(n||l.independent||s)&&l.fragment===t&&(a=o),n=u;return a},r.loadedEndOfParts=function(e,t){var r=e[e.length-1];return r&&t>r.start&&r.loaded},r.getInitialLiveFragment=function(e,t){var r=this.fragPrevious,a=null;if(!r){var n=this.hls.liveSyncPosition;null!==n&&(a=this.getFragmentAtPosition(n,this.bitrateTest?e.fragmentEnd:e.edge,e))}else if(e.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+r.programDateTime),a=(0,S.findFragmentByPDT)(t,r.endProgramDateTime,this.config.maxFragLookUpTolerance)),!a){var s=r.sn+1;if(s>=e.startSN&&s<=e.endSN){var i=t[s-e.startSN];r.cc===i.cc&&(a=i,this.log("Live playlist, switching playlist, load frag with next SN: "+a.sn))}a||(a=(0,S.findFragWithCC)(t,r.cc),a&&this.log("Live playlist, switching playlist, load frag with same CC: "+a.sn))}return a},r.getFragmentAtPosition=function(e,t,r){var a=this.config,n=this.fragPrevious,s=r.fragments,i=r.endSN,o=r.fragmentHint,d=a.maxFragLookUpTolerance,l=!!(a.lowLatencyMode&&r.partList&&o);l&&o&&!this.bitrateTest&&(s=s.concat(o),i=o.sn);var u;if(e<t){var c=e>t-d?0:d;u=(0,S.findFragmentByPTS)(n,s,e,c)}else u=s[s.length-1];if(u){var f=u.sn-r.startSN;if(this.fragmentTracker.getState(u)===g.FragmentState.OK&&(n=u),n&&u.sn===n.sn&&!l){var m=n&&u.level===n.level;if(m){var p=s[f+1];u.sn<i&&this.fragmentTracker.getState(p)!==g.FragmentState.OK?(this.log("SN "+u.sn+" just loaded, load next one: "+p.sn),u=p):u=null}}}return u},r.synchronizeToLiveEdge=function(e){var t=this.config,r=this.media;if(r){var a=this.hls.liveSyncPosition,n=r.currentTime,s=e.fragments[0].start,i=e.edge,o=n>=s-t.maxFragLookUpTolerance&&n<=i;if(null!==a&&r.duration>a&&(n<a||!o)){var d=void 0===t.liveMaxLatencyDuration?t.liveMaxLatencyDurationCount*e.targetduration:t.liveMaxLatencyDuration;(!o&&4>r.readyState||n<i-d)&&(!this.loadedmetadata&&(this.nextLoadPosition=a),r.readyState&&(this.warn("Playback: "+n.toFixed(3)+" is located too far from the end of live sliding playlist: "+i+", reset currentTime to : "+a.toFixed(3)),r.currentTime=a))}}},r.alignPlaylists=function(e,t){var r=this.levels,a=this.levelLastLoaded,n=this.fragPrevious,s=null===a?null:r[a],i=e.fragments.length;if(!i)return this.warn("No fragments in live playlist"),0;var o=e.fragments[0].start,d=e.alignedSliding&&(0,u.isFiniteNumber)(o);if(!t||!d&&!o){(0,h.alignStream)(n,s,e);var l=e.fragments[0].start;return this.log("Live playlist sliding: "+l.toFixed(2)+" start-sn: "+(t?t.startSN:"na")+"->"+e.startSN+" prev-sn: "+(n?n.sn:"na")+" fragments: "+i),l}return o},r.waitForCdnTuneIn=function(e){return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,3*e.partTarget)},r.setStartPosition=function(e,t){var r=this.startPosition;if(r<t&&(r=-1),-1===r||-1===this.lastCurrentTime){var a=e.startTimeOffset;(0,u.isFiniteNumber)(a)?(r=t+a,0>a&&(r+=e.totalduration),r=Math.min(Math.max(t,r),t+e.totalduration),this.log("Start time offset "+a+" found in playlist, adjust startPosition to "+r),this.startPosition=r):e.live?r=this.hls.liveSyncPosition||t:this.startPosition=r=0,this.lastCurrentTime=r}this.nextLoadPosition=r},r.getLoadPosition=function(){var e=this.media,t=0;return this.loadedmetadata&&e?t=e.currentTime:this.nextLoadPosition&&(t=this.nextLoadPosition),t},r.handleFragLoadAborted=function(e,t){this.transmuxer&&"initSegment"!==e.sn&&e.stats.aborted&&(this.warn("Fragment "+e.sn+(t?" part"+t.index:"")+" of level "+e.level+" was aborted"),this.resetFragmentLoading(e))},r.resetFragmentLoading=function(e){this.fragCurrent&&(this.fragContextChanged(e)||this.state===A.FRAG_LOADING_WAITING_RETRY)||(this.state=A.IDLE)},r.onFragmentOrKeyLoadError=function(e,t){if(t.fatal)return this.stopLoad(),void(this.state=A.ERROR);var r=this.config;if(t.chunkMeta){var a=this.getCurrentContext(t.chunkMeta);a&&(t.frag=a.frag,t.levelRetry=!0,this.fragLoadError=r.fragLoadingMaxRetry)}var n=t.frag;if(n&&n.type===e){var s=this.fragCurrent;if(console.assert(s&&n.sn===s.sn&&n.level===s.level&&n.urlId===s.urlId,"Frag load error must match current frag to retry"),this.fragLoadError+1<=r.fragLoadingMaxRetry){this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition);var i=Math.min(Math.pow(2,this.fragLoadError)*r.fragLoadingRetryDelay,r.fragLoadingMaxRetryTimeout);this.warn("Fragment "+n.sn+" of "+e+" "+n.level+" failed to load, retrying in "+i+"ms"),this.retryDate=self.performance.now()+i,this.fragLoadError++,this.state=A.FRAG_LOADING_WAITING_RETRY}else t.levelRetry?(e===I.PlaylistLevelType.AUDIO&&(this.fragCurrent=null),this.fragLoadError=0,this.state=A.IDLE):(m.logger.error(t.details+" reaches max retry, redispatch as fatal ..."),t.fatal=!0,this.hls.stopLoad(),this.state=A.ERROR)}},r.afterBufferFlushed=function(e,t,r){if(e){var a=f.BufferHelper.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,a,r),this.state===A.ENDED&&this.resetLoadingState()}},r.resetLoadingState=function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=A.IDLE},r.resetStartWhenNotLoaded=function(e){if(!this.loadedmetadata){this.startFragRequested=!1;var t=this.levels?this.levels[e].details:null;null!==t&&void 0!==t&&t.live?(this.startPosition=-1,this.setStartPosition(t,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}},r.updateLevelTiming=function(e,t,r,a){var n=this,s=r.details;console.assert(!!s,"level.details must be defined");var i=Object.keys(e.elementaryStreams).reduce(function(t,i){var o=e.elementaryStreams[i];if(o){var d=o.endPTS-o.startPTS;if(0>=d)return n.warn("Could not parse fragment "+e.sn+" "+i+" duration reliably ("+d+")"),t||!1;var l=a?0:(0,v.updateFragPTSDTS)(s,e,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return n.hls.trigger(p.Events.LEVEL_PTS_UPDATED,{details:s,level:r,drift:l,type:i,frag:e,start:o.startPTS,end:o.endPTS}),!0}return t},!1);i||(this.warn("Found no media in fragment "+e.sn+" of level "+r.id+" resetting transmuxer to fallback to playlist timing"),this.resetTransmuxer()),this.state=A.PARSED,this.hls.trigger(p.Events.FRAG_PARSED,{frag:e,part:t})},r.resetTransmuxer=function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)},n(t,[{key:"state",get:function(){return this._state},set:function(e){var t=this._state;t!==e&&(this._state=e,this.log(t+"->"+e))}}]),t}(c["default"])},"./src/controller/buffer-controller.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>f});var a=r("./src/polyfills/number.ts"),n=r("./src/events.ts"),s=r("./src/utils/logger.ts"),i=r("./src/errors.ts"),o=r("./src/utils/buffer-helper.ts"),d=r("./src/utils/mediasource-helper.ts"),l=r("./src/loader/fragment.ts"),u=r("./src/controller/buffer-operation-queue.ts"),c=(0,d.getMediaSource)(),g=/([ha]vc.)(?:\.[^.,]+)+/,f=function(){function e(e){var t=this;this.details=null,this._objectUrl=null,this.operationQueue=void 0,this.listeners=void 0,this.hls=void 0,this.bufferCodecEventsExpected=0,this._bufferCodecEventsTotal=0,this.media=null,this.mediaSource=null,this.lastMpegAudioChunk=null,this.appendError=0,this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this._onMediaSourceOpen=function(){var e=t.media,r=t.mediaSource;s.logger.log("[buffer-controller]: Media source opened"),e&&(e.removeEventListener("emptied",t._onMediaEmptied),t.updateMediaElementDuration(),t.hls.trigger(n.Events.MEDIA_ATTACHED,{media:e})),r&&r.removeEventListener("sourceopen",t._onMediaSourceOpen),t.checkPendingTracks()},this._onMediaSourceClose=function(){s.logger.log("[buffer-controller]: Media source closed")},this._onMediaSourceEnded=function(){s.logger.log("[buffer-controller]: Media source ended")},this._onMediaEmptied=function(){var e=t.media,r=t._objectUrl;e&&e.src!==r&&s.logger.error("Media element src was set while attaching MediaSource ("+r+" > "+e.src+")")},this.hls=e,this._initSourceBuffer(),this.registerListeners()}var t=e.prototype;return t.hasSourceTypes=function(){return 0<this.getSourceBufferTypes().length||0<Object.keys(this.pendingTracks).length},t.destroy=function(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null},t.registerListeners=function(){var e=this.hls;e.on(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(n.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.on(n.Events.BUFFER_RESET,this.onBufferReset,this),e.on(n.Events.BUFFER_APPENDING,this.onBufferAppending,this),e.on(n.Events.BUFFER_CODECS,this.onBufferCodecs,this),e.on(n.Events.BUFFER_EOS,this.onBufferEos,this),e.on(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(n.Events.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(n.Events.FRAG_PARSED,this.onFragParsed,this),e.on(n.Events.FRAG_CHANGED,this.onFragChanged,this)},t.unregisterListeners=function(){var e=this.hls;e.off(n.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(n.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(n.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.off(n.Events.BUFFER_RESET,this.onBufferReset,this),e.off(n.Events.BUFFER_APPENDING,this.onBufferAppending,this),e.off(n.Events.BUFFER_CODECS,this.onBufferCodecs,this),e.off(n.Events.BUFFER_EOS,this.onBufferEos,this),e.off(n.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(n.Events.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(n.Events.FRAG_PARSED,this.onFragParsed,this),e.off(n.Events.FRAG_CHANGED,this.onFragChanged,this)},t._initSourceBuffer=function(){this.sourceBuffer={},this.operationQueue=new u["default"](this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.lastMpegAudioChunk=null},t.onManifestParsed=function(e,t){var r=2;(!t.audio||t.video)&&t.altAudio||(r=1),this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=r,this.details=null,s.logger.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},t.onMediaAttaching=function(e,t){var r=this.media=t.media;if(r&&c){var a=this.mediaSource=new c;a.addEventListener("sourceopen",this._onMediaSourceOpen),a.addEventListener("sourceended",this._onMediaSourceEnded),a.addEventListener("sourceclose",this._onMediaSourceClose),r.src=self.URL.createObjectURL(a),this._objectUrl=r.src,r.addEventListener("emptied",this._onMediaEmptied)}},t.onMediaDetaching=function(){var e=this.media,t=this.mediaSource,r=this._objectUrl;if(t){if(s.logger.log("[buffer-controller]: media source detaching"),"open"===t.readyState)try{t.endOfStream()}catch(e){s.logger.warn("[buffer-controller]: onMediaDetaching: "+e.message+" while calling endOfStream")}this.onBufferReset(),t.removeEventListener("sourceopen",this._onMediaSourceOpen),t.removeEventListener("sourceended",this._onMediaSourceEnded),t.removeEventListener("sourceclose",this._onMediaSourceClose),e&&(e.removeEventListener("emptied",this._onMediaEmptied),r&&self.URL.revokeObjectURL(r),e.src===r?(e.removeAttribute("src"),e.load()):s.logger.warn("[buffer-controller]: media.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={}}this.hls.trigger(n.Events.MEDIA_DETACHED,void 0)},t.onBufferReset=function(){var e=this;this.getSourceBufferTypes().forEach(function(t){var r=e.sourceBuffer[t];try{r&&(e.removeBufferListeners(t),e.mediaSource&&e.mediaSource.removeSourceBuffer(r),e.sourceBuffer[t]=void 0)}catch(e){s.logger.warn("[buffer-controller]: Failed to reset the "+t+" buffer",e)}}),this._initSourceBuffer()},t.onBufferCodecs=function(e,t){var r=this,a=this.getSourceBufferTypes().length;Object.keys(t).forEach(function(e){if(a){var n=r.tracks[e];if(n&&"function"==typeof n.buffer.changeType){var i=t[e],o=i.id,d=i.codec,l=i.levelCodec,u=i.container,c=i.metadata,f=(n.levelCodec||n.codec).replace(g,"$1"),m=(l||d).replace(g,"$1");if(f!==m){r.appendChangeType(e,u+";codecs="+(l||d)),s.logger.log("[buffer-controller]: switching codec "+f+" to "+m),r.tracks[e]={buffer:n.buffer,codec:d,container:u,levelCodec:l,metadata:c,id:o}}}}else r.pendingTracks[e]=t[e]}),a||(this.bufferCodecEventsExpected=Math.max(this.bufferCodecEventsExpected-1,0),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks())},t.appendChangeType=function(t,r){var a=this,n=this.operationQueue;n.append({execute:function(){var e=a.sourceBuffer[t];e&&(s.logger.log("[buffer-controller]: changing "+t+" sourceBuffer type to "+r),e.changeType(r)),n.shiftAndExecuteNext(t)},onStart:function(){},onComplete:function(){},onError:function(r){s.logger.warn("[buffer-controller]: Failed to change "+t+" SourceBuffer type",r)}},t)},t.onBufferAppending=function(e,t){var r=this,a=this.hls,d=this.operationQueue,l=this.tracks,u=t.data,c=t.type,g=t.frag,f=t.part,m=t.chunkMeta,p=m.buffering[c],y=self.performance.now();p.start=y;var E=g.stats.buffering,T=f?f.stats.buffering:null;0===E.start&&(E.start=y),T&&0===T.start&&(T.start=y);var h=l.audio,S=!1;"audio"===c&&"audio/mpeg"===(null===h||void 0===h?void 0:h.container)&&(S=!this.lastMpegAudioChunk||1===m.id||this.lastMpegAudioChunk.sn!==m.sn,this.lastMpegAudioChunk=m);var v=g.start;d.append({execute:function(){if(p.executeStart=self.performance.now(),S){var e=r.sourceBuffer[c];if(e){var t=v-e.timestampOffset;.1<=Math.abs(t)&&(s.logger.log("[buffer-controller]: Updating audio SourceBuffer timestampOffset to "+v+" (delta: "+t+") sn: "+g.sn+")"),e.timestampOffset=v)}}r.appendExecutor(u,c)},onStart:function(){},onComplete:function(){var e=self.performance.now();p.executeEnd=p.end=e,0===E.first&&(E.first=e),T&&0===T.first&&(T.first=e);var t=r.sourceBuffer,a={};for(var s in t)a[s]=o.BufferHelper.getBuffered(t[s]);r.appendError=0,r.hls.trigger(n.Events.BUFFER_APPENDED,{type:c,frag:g,part:f,chunkMeta:m,parent:g.type,timeRanges:a})},onError:function(e){s.logger.error("[buffer-controller]: Error encountered while trying to append to the "+c+" SourceBuffer",e);var t={type:i.ErrorTypes.MEDIA_ERROR,parent:g.type,details:i.ErrorDetails.BUFFER_APPEND_ERROR,err:e,fatal:!1};e.code===DOMException.QUOTA_EXCEEDED_ERR?t.details=i.ErrorDetails.BUFFER_FULL_ERROR:(r.appendError++,t.details=i.ErrorDetails.BUFFER_APPEND_ERROR,r.appendError>a.config.appendErrorMaxRetry&&(s.logger.error("[buffer-controller]: Failed "+a.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),t.fatal=!0,a.stopLoad())),a.trigger(n.Events.ERROR,t)}},c)},t.onBufferFlushing=function(e,t){var r=this,a=this.operationQueue,i=function(a){return{execute:r.removeExecutor.bind(r,a,t.startOffset,t.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(n.Events.BUFFER_FLUSHED,{type:a})},onError:function(t){s.logger.warn("[buffer-controller]: Failed to remove from "+a+" SourceBuffer",t)}}};t.type?a.append(i(t.type),t.type):this.getSourceBufferTypes().forEach(function(e){a.append(i(e),e)})},t.onFragParsed=function(e,t){var r=this,a=t.frag,i=t.part,o=[],d=i?i.elementaryStreams:a.elementaryStreams;d[l.ElementaryStreamTypes.AUDIOVIDEO]?o.push("audiovideo"):(d[l.ElementaryStreamTypes.AUDIO]&&o.push("audio"),d[l.ElementaryStreamTypes.VIDEO]&&o.push("video"));0===o.length&&s.logger.warn("Fragments must have at least one ElementaryStreamType set. type: "+a.type+" level: "+a.level+" sn: "+a.sn),this.blockBuffers(function(){var e=self.performance.now();a.stats.buffering.end=e,i&&(i.stats.buffering.end=e);var t=i?i.stats:a.stats;r.hls.trigger(n.Events.FRAG_BUFFERED,{frag:a,part:i,stats:t,id:a.type})},o)},t.onFragChanged=function(){this.flushBackBuffer()},t.onBufferEos=function(e,t){var r=this,a=this.getSourceBufferTypes().reduce(function(e,a){var n=r.sourceBuffer[a];return n&&(!t.type||t.type===a)&&(n.ending=!0,!n.ended&&(n.ended=!0,s.logger.log("[buffer-controller]: "+a+" sourceBuffer now EOS"))),e&&(!n||n.ended)},!0);a&&(s.logger.log("[buffer-controller]: Queueing mediaSource.endOfStream()"),this.blockBuffers(function(){r.getSourceBufferTypes().forEach(function(e){var t=r.sourceBuffer[e];t&&(t.ending=!1)});var e=r.mediaSource;return e&&"open"===e.readyState?void(s.logger.log("[buffer-controller]: Calling mediaSource.endOfStream()"),e.endOfStream()):void(e&&s.logger.info("[buffer-controller]: Could not call mediaSource.endOfStream(). mediaSource.readyState: "+e.readyState))}))},t.onLevelUpdated=function(e,t){var r=t.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())},t.flushBackBuffer=function(){var e=this.hls,t=this.details,r=this.media,i=this.sourceBuffer;if(r&&null!==t){var d=this.getSourceBufferTypes();if(d.length){var l=t.live&&null!==e.config.liveBackBufferLength?e.config.liveBackBufferLength:e.config.backBufferLength;if((0,a.isFiniteNumber)(l)&&!(0>l)){var u=r.currentTime,c=t.levelTargetDuration,g=Math.max(l,c),f=Math.floor(u/c)*c-g;d.forEach(function(r){var a=i[r];if(a){var d=o.BufferHelper.getBuffered(a);if(0<d.length&&f>d.start(0)){if(e.trigger(n.Events.BACK_BUFFER_REACHED,{bufferEnd:f}),t.live)e.trigger(n.Events.LIVE_BACK_BUFFER_REACHED,{bufferEnd:f});else if(a.ended&&d.end(d.length-1)-u<2*c)return void s.logger.info("[buffer-controller]: Cannot flush "+r+" back buffer while SourceBuffer is in ended state");e.trigger(n.Events.BUFFER_FLUSHING,{startOffset:0,endOffset:f,type:r})}}})}}}},t.updateMediaElementDuration=function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var e=this.details,t=this.hls,r=this.media,n=this.mediaSource,i=e.fragments[0].start+e.totalduration,o=r.duration,d=(0,a.isFiniteNumber)(n.duration)?n.duration:0;e.live&&t.config.liveDurationInfinity?(s.logger.log("[buffer-controller]: Media Source duration is set to Infinity"),n.duration=1/0,this.updateSeekableRange(e)):(i>d&&i>o||!(0,a.isFiniteNumber)(o))&&(s.logger.log("[buffer-controller]: Updating Media Source duration to "+i.toFixed(3)),n.duration=i)}},t.updateSeekableRange=function(e){var t=this.mediaSource,r=e.fragments,a=r.length;if(a&&e.live&&null!==t&&void 0!==t&&t.setLiveSeekableRange){var n=Math.max(0,r[0].start),s=Math.max(n,n+e.totalduration);t.setLiveSeekableRange(n,s)}},t.checkPendingTracks=function(){var e=this.bufferCodecEventsExpected,t=this.operationQueue,r=this.pendingTracks,a=Object.keys(r).length;if(a&&!e||2===a){this.createSourceBuffers(r),this.pendingTracks={};var s=this.getSourceBufferTypes();if(0===s.length)return void this.hls.trigger(n.Events.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,reason:"could not create source buffer for media codec(s)"});s.forEach(function(e){t.executeNext(e)})}},t.createSourceBuffers=function(e){var t=this.sourceBuffer,r=this.mediaSource;if(!r)throw Error("createSourceBuffers called when mediaSource was null");var a=0;for(var o in e)if(!t[o]){var d=e[o];if(!d)throw Error("source buffer exists for track "+o+", however track does not");var l=d.levelCodec||d.codec,u=d.container+";codecs="+l;s.logger.log("[buffer-controller]: creating sourceBuffer("+u+")");try{var c=t[o]=r.addSourceBuffer(u),g=o;this.addBufferListener(g,"updatestart",this._onSBUpdateStart),this.addBufferListener(g,"updateend",this._onSBUpdateEnd),this.addBufferListener(g,"error",this._onSBUpdateError),this.tracks[o]={buffer:c,codec:l,container:d.container,levelCodec:d.levelCodec,metadata:d.metadata,id:d.id},a++}catch(e){s.logger.error("[buffer-controller]: error while trying to add sourceBuffer: "+e.message),this.hls.trigger(n.Events.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:e,mimeType:u})}}a&&this.hls.trigger(n.Events.BUFFER_CREATED,{tracks:this.tracks})},t._onSBUpdateStart=function(e){var t=this.operationQueue,r=t.current(e);r.onStart()},t._onSBUpdateEnd=function(e){var t=this.operationQueue,r=t.current(e);r.onComplete(),t.shiftAndExecuteNext(e)},t._onSBUpdateError=function(e,t){s.logger.error("[buffer-controller]: "+e+" SourceBuffer error",t),this.hls.trigger(n.Events.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1});var r=this.operationQueue.current(e);r&&r.onError(t)},t.removeExecutor=function(e,t,r){var n=this.media,i=this.mediaSource,o=this.operationQueue,d=this.sourceBuffer,l=d[e];if(!n||!i||!l)return s.logger.warn("[buffer-controller]: Attempting to remove from the "+e+" SourceBuffer, but it does not exist"),void o.shiftAndExecuteNext(e);var u=(0,a.isFiniteNumber)(n.duration)?n.duration:1/0,c=(0,a.isFiniteNumber)(i.duration)?i.duration:1/0,g=Math.max(0,t),f=Math.min(r,u,c);f>g&&!l.ending?(l.ended=!1,s.logger.log("[buffer-controller]: Removing ["+g+","+f+"] from the "+e+" SourceBuffer"),console.assert(!l.updating,e+" sourceBuffer must not be updating"),l.remove(g,f)):o.shiftAndExecuteNext(e)},t.appendExecutor=function(e,t){var r=this.operationQueue,a=this.sourceBuffer,n=a[t];return n?void(n.ended=!1,console.assert(!n.updating,t+" sourceBuffer must not be updating"),n.appendBuffer(e)):(s.logger.warn("[buffer-controller]: Attempting to append to the "+t+" SourceBuffer, but it does not exist"),void r.shiftAndExecuteNext(t))},t.blockBuffers=function(e,t){var r=this;if(void 0===t&&(t=this.getSourceBufferTypes()),!t.length)return s.logger.log("[buffer-controller]: Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(e);var a=this.operationQueue,n=t.map(function(e){return a.appendBlocker(e)});Promise.all(n).then(function(){e(),t.forEach(function(e){var t=r.sourceBuffer[e];t&&t.updating||a.shiftAndExecuteNext(e)})})},t.getSourceBufferTypes=function(){return Object.keys(this.sourceBuffer)},t.addBufferListener=function(e,t,r){var a=this.sourceBuffer[e];if(a){var n=r.bind(this,e);this.listeners[e].push({event:t,listener:n}),a.addEventListener(t,n)}},t.removeBufferListeners=function(e){var t=this.sourceBuffer[e];t&&this.listeners[e].forEach(function(e){t.removeEventListener(e.event,e.listener)})},e}()},"./src/controller/buffer-operation-queue.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>n});var a=r("./src/utils/logger.ts"),n=function(){function e(e){this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=e}var t=e.prototype;return t.append=function(e,t){var r=this.queues[t];r.push(e),1===r.length&&this.buffers[t]&&this.executeNext(t)},t.insertAbort=function(e,t){var r=this.queues[t];r.unshift(e),this.executeNext(t)},t.appendBlocker=function(e){var t=new Promise(function(e){a=e}),r={execute:a,onStart:function(){},onComplete:function(){},onError:function(){}},a;return this.append(r,e),t},t.executeNext=function(t){var r=this.buffers,n=this.queues,s=r[t],i=n[t];if(i.length){var o=i[0];try{o.execute()}catch(r){a.logger.warn("[buffer-operation-queue]: Unhandled exception executing the current operation"),o.onError(r),s&&s.updating||(i.shift(),this.executeNext(t))}}},t.shiftAndExecuteNext=function(e){this.queues[e].shift(),this.executeNext(e)},t.current=function(e){return this.queues[e][0]},e}()},"./src/controller/cap-level-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{default:()=>l});var o=r("./src/events.ts"),d=function(){function e(e){this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.hls=void 0,this.streamController=void 0,this.clientRect=void 0,this.hls=e,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.destroy=function(){this.unregisterListener(),this.hls.config.capLevelToPlayerSize&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null},t.registerListeners=function(){var e=this.hls;e.on(o.Events.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.on(o.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(o.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.on(o.Events.BUFFER_CODECS,this.onBufferCodecs,this),e.on(o.Events.MEDIA_DETACHING,this.onMediaDetaching,this)},t.unregisterListener=function(){var e=this.hls;e.off(o.Events.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.off(o.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(o.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.off(o.Events.BUFFER_CODECS,this.onBufferCodecs,this),e.off(o.Events.MEDIA_DETACHING,this.onMediaDetaching,this)},t.onFpsDropLevelCapping=function(t,r){e.isLevelAllowed(r.droppedLevel,this.restrictedLevels)&&this.restrictedLevels.push(r.droppedLevel)},t.onMediaAttaching=function(e,t){this.media=t.media instanceof HTMLVideoElement?t.media:null,this.clientRect=null},t.onManifestParsed=function(e,t){var r=this.hls;this.restrictedLevels=[],this.firstLevel=t.firstLevel,r.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onBufferCodecs=function(e,t){var r=this.hls;r.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onMediaDetaching=function(){this.stopCapping()},t.detectPlayerSize=function(){if(this.media&&0<this.mediaHeight&&0<this.mediaWidth){var e=this.hls.levels;if(e.length){var t=this.hls;t.autoLevelCapping=this.getMaxLevel(e.length-1),t.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}},t.getMaxLevel=function(t){var r=this,a=this.hls.levels;if(!a.length)return-1;var n=a.filter(function(a,n){return e.isLevelAllowed(n,r.restrictedLevels)&&n<=t});return this.clientRect=null,e.getMaxLevelByMediaSize(n,this.mediaWidth,this.mediaHeight)},t.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,this.hls.firstLevel=this.getMaxLevel(this.firstLevel),self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},t.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)},t.getDimensions=function(){if(this.clientRect)return this.clientRect;var e=this.media,t={width:0,height:0};if(e){var r=e.getBoundingClientRect();t.width=r.width,t.height=r.height,t.width||t.height||(t.width=r.right-r.left||e.width||0,t.height=r.bottom-r.top||e.height||0)}return this.clientRect=t,t},e.isLevelAllowed=function(e,t){return void 0===t&&(t=[]),-1===t.indexOf(e)},e.getMaxLevelByMediaSize=function(e,t,r){if(!e||!e.length)return-1;for(var a=function(e,t){return!t||e.width!==t.width||e.height!==t.height},n=e.length-1,s=0,o;s<e.length;s+=1)if(o=e[s],(o.width>=t||o.height>=r)&&a(o,e[s+1])){n=s;break}return n},n(e,[{key:"mediaWidth",get:function(){return this.getDimensions().width*this.contentScaleFactor}},{key:"mediaHeight",get:function(){return this.getDimensions().height*this.contentScaleFactor}},{key:"contentScaleFactor",get:function(){var e=1;if(!this.hls.config.ignoreDevicePixelRatio)try{e=self.devicePixelRatio}catch(t){}return e}}]),e}();const l=d},"./src/controller/cmcd-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=d(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var a=0;return function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function d(e,t){if(e){if("string"==typeof e)return l(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(e,t):void 0}}function l(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,a=Array(t);r<t;r++)a[r]=e[r];return a}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},u.apply(this,arguments)}r.r(t),r.d(t,{default:()=>p});var c=r("./src/events.ts"),g=r("./src/types/cmcd.ts"),f=r("./src/utils/buffer-helper.ts"),m=r("./src/utils/logger.ts"),p=function(){function e(t){var r=this;this.hls=void 0,this.config=void 0,this.media=void 0,this.sid=void 0,this.cid=void 0,this.useHeaders=!1,this.initialized=!1,this.starved=!1,this.buffering=!0,this.audioBuffer=void 0,this.videoBuffer=void 0,this.onWaiting=function(){r.initialized&&(r.starved=!0),r.buffering=!0},this.onPlaying=function(){r.initialized||(r.initialized=!0),r.buffering=!1},this.applyPlaylistData=function(e){try{r.apply(e,{ot:g.CMCDObjectType.MANIFEST,su:!r.initialized})}catch(e){m.logger.warn("Could not generate manifest CMCD data.",e)}},this.applyFragmentData=function(e){try{var t=e.frag,a=r.hls.levels[t.level],n=r.getObjectType(t),s={d:1e3*t.duration,ot:n};(n===g.CMCDObjectType.VIDEO||n===g.CMCDObjectType.AUDIO||n==g.CMCDObjectType.MUXED)&&(s.br=a.bitrate/1e3,s.tb=r.getTopBandwidth(n)/1e3,s.bl=r.getBufferLength(n)),r.apply(e,s)}catch(e){m.logger.warn("Could not generate segment CMCD data.",e)}},this.hls=t;var a=this.config=t.config,n=a.cmcd;null!=n&&(a.pLoader=this.createPlaylistLoader(),a.fLoader=this.createFragmentLoader(),this.sid=n.sessionId||e.uuid(),this.cid=n.contentId,this.useHeaders=!0===n.useHeaders,this.registerListeners())}var t=e.prototype;return t.registerListeners=function(){var e=this.hls;e.on(c.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(c.Events.MEDIA_DETACHED,this.onMediaDetached,this),e.on(c.Events.BUFFER_CREATED,this.onBufferCreated,this)},t.unregisterListeners=function(){var e=this.hls;e.off(c.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(c.Events.MEDIA_DETACHED,this.onMediaDetached,this),e.off(c.Events.BUFFER_CREATED,this.onBufferCreated,this),this.onMediaDetached()},t.destroy=function(){this.unregisterListeners(),this.hls=this.config=this.audioBuffer=this.videoBuffer=null},t.onMediaAttached=function(e,t){this.media=t.media,this.media.addEventListener("waiting",this.onWaiting),this.media.addEventListener("playing",this.onPlaying)},t.onMediaDetached=function(){this.media&&(this.media.removeEventListener("waiting",this.onWaiting),this.media.removeEventListener("playing",this.onPlaying),this.media=null)},t.onBufferCreated=function(e,t){var r,a;this.audioBuffer=null===(r=t.tracks.audio)||void 0===r?void 0:r.buffer,this.videoBuffer=null===(a=t.tracks.video)||void 0===a?void 0:a.buffer},t.createData=function(){var e;return{v:g.CMCDVersion,sf:g.CMCDStreamingFormat.HLS,sid:this.sid,cid:this.cid,pr:null===(e=this.media)||void 0===e?void 0:e.playbackRate,mtp:this.hls.bandwidthEstimate/1e3}},t.apply=function(t,r){void 0===r&&(r={}),u(r,this.createData());var a=r.ot===g.CMCDObjectType.INIT||r.ot===g.CMCDObjectType.VIDEO||r.ot===g.CMCDObjectType.MUXED;if(this.starved&&a&&(r.bs=!0,r.su=!0,this.starved=!1),null==r.su&&(r.su=this.buffering),this.useHeaders){var n=e.toHeaders(r);if(!Object.keys(n).length)return;t.headers||(t.headers={}),u(t.headers,n)}else{var s=e.toQuery(r);if(!s)return;t.url=e.appendQueryToUri(t.url,s)}},t.getObjectType=function(e){var t=e.type;return"subtitle"===t?g.CMCDObjectType.TIMED_TEXT:"initSegment"===e.sn?g.CMCDObjectType.INIT:"audio"===t?g.CMCDObjectType.AUDIO:"main"===t?this.hls.audioTracks.length?g.CMCDObjectType.VIDEO:g.CMCDObjectType.MUXED:void 0},t.getTopBandwidth=function(e){var t=0,r=this.hls,a;if(e===g.CMCDObjectType.AUDIO)a=r.audioTracks;else{var n=r.maxAutoLevel,s=-1<n?n+1:r.levels.length;a=r.levels.slice(0,s)}for(var i=o(a),d,l;!(d=i()).done;)l=d.value,l.bitrate>t&&(t=l.bitrate);return 0<t?t:NaN},t.getBufferLength=function(e){var t=this.hls.media,r=e===g.CMCDObjectType.AUDIO?this.audioBuffer:this.videoBuffer;if(!r||!t)return NaN;var a=f.BufferHelper.bufferInfo(r,t.currentTime,this.config.maxBufferHole);return 1e3*a.len},t.createPlaylistLoader=function(){var e=this.config.pLoader,t=this.applyPlaylistData,r=e||this.config.loader;return function(){function e(e){this.loader=void 0,this.loader=new r(e)}var a=e.prototype;return a.destroy=function(){this.loader.destroy()},a.abort=function(){this.loader.abort()},a.load=function(e,r,a){t(e),this.loader.load(e,r,a)},n(e,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),e}()},t.createFragmentLoader=function(){var e=this.config.fLoader,t=this.applyFragmentData,r=e||this.config.loader;return function(){function e(e){this.loader=void 0,this.loader=new r(e)}var a=e.prototype;return a.destroy=function(){this.loader.destroy()},a.abort=function(){this.loader.abort()},a.load=function(e,r,a){t(e),this.loader.load(e,r,a)},n(e,[{key:"stats",get:function(){return this.loader.stats}},{key:"context",get:function(){return this.loader.context}}]),e}()},e.uuid=function e(){var t=URL.createObjectURL(new Blob),e=t.toString();return URL.revokeObjectURL(t),e.slice(e.lastIndexOf("/")+1)},e.serialize=function(e){for(var t=[],r=function(e){return!Number.isNaN(e)&&null!=e&&""!==e&&!1!==e},a=function(e){return Math.round(e)},n=function(e){return 100*a(e/100)},s=function(e){return encodeURIComponent(e)},i={br:a,d:a,bl:n,dl:n,mtp:n,nor:s,rtp:n,tb:a},d=Object.keys(e||{}).sort(),l=o(d),u;!(u=l()).done;){var c=u.value,g=e[c];if(r(g)&&("v"!==c||1!==g)&&("pr"!=c||1!==g)){var f=i[c];f&&(g=f(g));var m=typeof g,p=void 0;p="ot"===c||"sf"===c||"st"===c?c+"="+g:"boolean"===m?c:"number"===m?c+"="+g:c+"="+JSON.stringify(g),t.push(p)}}return t.join(",")},e.toHeaders=function(t){for(var r=Object.keys(t),a={},n=["Object","Request","Session","Status"],s=[{},{},{},{}],o={br:0,d:0,ot:0,tb:0,bl:1,dl:1,mtp:1,nor:1,nrr:1,su:1,cid:2,pr:2,sf:2,sid:2,st:2,v:2,bs:3,rtp:3},d=0,l=r;d<l.length;d++){var u=l[d],c=null==o[u]?1:o[u];s[c][u]=t[u]}for(var g=0,f;g<s.length;g++)f=e.serialize(s[g]),f&&(a["CMCD-"+n[g]]=f);return a},e.toQuery=function(t){return"CMCD="+encodeURIComponent(e.serialize(t))},e.appendQueryToUri=function(e,t){if(!t)return e;var r=e.includes("?")?"&":"?";return""+e+r+t},e}()},"./src/controller/eme-controller.ts":(e,t,r)=>{"use strict";function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function n(e){var t="function"==typeof Map?new Map:void 0;return n=function(e){function r(){return s(e,arguments,l(this).constructor)}if(null===e||!o(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof t){if(t.has(e))return t.get(e);t.set(e,r)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},n(e)}function s(){return s=i()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var a=Function.bind.apply(e,n),s=new a;return r&&d(s,r.prototype),s},s.apply(null,arguments)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function o(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}r.r(t),r.d(t,{default:()=>D});var u=r("./src/events.ts"),c=r("./src/errors.ts"),g=r("./src/utils/logger.ts"),f=r("./src/utils/mediakeys-helper.ts"),m=r("./src/utils/keysystem-util.ts"),p=r("./src/utils/numeric-encoding-utils.ts"),y=r("./src/loader/level-key.ts"),E=r("./src/utils/hex.ts"),T=r("./src/utils/mp4-tools.ts"),h=r("./node_modules/eventemitter3/index.js"),S=r.n(h),v=function(){function e(t){this.hls=void 0,this.config=void 0,this.media=null,this.keyFormatPromise=null,this.keySystemAccessPromises={},this._requestLicenseFailureCount=0,this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},this.setMediaKeysQueue=e.CDMCleanupPromise?[e.CDMCleanupPromise]:[],this.onMediaEncrypted=this._onMediaEncrypted.bind(this),this.onWaitingForKey=this._onWaitingForKey.bind(this),this.debug=g.logger.debug.bind(g.logger,"[eme]"),this.log=g.logger.log.bind(g.logger,"[eme]"),this.warn=g.logger.warn.bind(g.logger,"[eme]"),this.error=g.logger.error.bind(g.logger,"[eme]"),this.hls=t,this.config=t.config,this.registerListeners()}var t=e.prototype;return t.destroy=function(){this.unregisterListeners(),this.onMediaDetached(),this.hls=this.onMediaEncrypted=this.onWaitingForKey=this.keyIdToKeySessionPromise=null},t.registerListeners=function(){this.hls.on(u.Events.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(u.Events.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.on(u.Events.MANIFEST_LOADED,this.onManifestLoaded,this)},t.unregisterListeners=function(){this.hls.off(u.Events.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(u.Events.MEDIA_DETACHED,this.onMediaDetached,this),this.hls.off(u.Events.MANIFEST_LOADED,this.onManifestLoaded,this)},t.getLicenseServerUrl=function(e){var t=this.config,r=t.drmSystems,a=t.widevineLicenseUrl,n=r[e];if(n)return n.licenseUrl;if(e===f.KeySystems.WIDEVINE&&a)return a;throw new Error("no license server URL configured for key-system \""+e+"\"")},t.getServerCertificateUrl=function(e){var t=this.config.drmSystems,r=t[e];return r?r.serverCertificateUrl:void this.log("No Server Certificate in config.drmSystems[\""+e+"\"]")},t.attemptKeySystemAccess=function(e){var t=this,r=this.hls.levels,a=function(e,t,r){return!!e&&r.indexOf(e)===t},n=r.map(function(e){return e.audioCodec}).filter(a),s=r.map(function(e){return e.videoCodec}).filter(a);return 0===n.length+s.length&&s.push("avc1.42e01e"),new Promise(function(r,a){(function e(i){var o=i.shift();t.getMediaKeysPromise(o,n,s).then(function(e){return r({keySystem:o,mediaKeys:e})}).catch(function(t){i.length?e(i):t instanceof L?a(t):a(new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_NO_ACCESS,error:t,fatal:!0},t.message))})})(e)})},t.requestMediaKeySystemAccess=function(e,t){var r=this.config.requestMediaKeySystemAccessFunc;if("function"!=typeof r){var a="Configured requestMediaKeySystemAccess is not a function "+r;return null===f.requestMediaKeySystemAccess&&"http:"===self.location.protocol&&(a="navigator.requestMediaKeySystemAccess is not available over insecure protocol "+location.protocol),Promise.reject(new Error(a))}return r(e,t)},t.getMediaKeysPromise=function(e,t,r){var a=this,n=(0,f.getSupportedMediaKeySystemConfigurations)(e,t,r,this.config.drmSystemOptions),s=this.keySystemAccessPromises[e],i=null===s||void 0===s?void 0:s.keySystemAccess;if(!i){this.log("Requesting encrypted media \""+e+"\" key-system access with config: "+JSON.stringify(n)),i=this.requestMediaKeySystemAccess(e,n);var o=this.keySystemAccessPromises[e]={keySystemAccess:i};return i.catch(function(t){a.log("Failed to obtain access to key-system \""+e+"\": "+t)}),i.then(function(t){a.log("Access for key-system \""+t.keySystem+"\" obtained");var r=a.fetchServerCertificate(e);return a.log("Create media-keys for \""+e+"\""),o.mediaKeys=t.createMediaKeys().then(function(t){return a.log("Media-keys created for \""+e+"\""),r.then(function(r){return r?a.setMediaKeysServerCertificate(t,e,r):t})}),o.mediaKeys.catch(function(t){a.error("Failed to create media-keys for \""+e+"\"}: "+t)}),o.mediaKeys})}return i.then(function(){return s.mediaKeys})},t.createMediaKeySessionContext=function(e){var t=e.decryptdata,r=e.keySystem,a=e.mediaKeys;console.assert(!!a,"mediaKeys is defined"),this.log("Creating key-system session \""+r+"\" keyId: "+E["default"].hexDump(t.keyId||[]));var n=a.createSession(),s={decryptdata:t,keySystem:r,mediaKeys:a,mediaKeysSession:n,keyStatus:"status-pending"};return this.mediaKeySessions.push(s),s},t.renewKeySession=function(e){var t=e.decryptdata;if(t.pssh){var r=this.createMediaKeySessionContext(e),a=this.getKeyIdString(t);this.keyIdToKeySessionPromise[a]=this.generateRequestWithPreferredKeySession(r,"cenc",t.pssh,"expired")}else this.warn("Could not renew expired session. Missing pssh initData.");this.removeSession(e)},t.getKeyIdString=function(e){if(!e)throw new Error("Could not read keyId of undefined decryptdata");if(null===e.keyId)throw new Error("keyId is null");return E["default"].hexDump(e.keyId)},t.updateKeySession=function(e,t){var r=e.mediaKeysSession,a;return this.log("Updating key-session \""+r.sessionId+"\" for keyID "+E["default"].hexDump((null===(a=e.decryptdata)||void 0===a?void 0:a.keyId)||[])+"\n      } (data length: "+(t?t.byteLength:t)+")"),r.update(t)},t.selectKeySystemFormat=function(e){var t=Object.keys(e.levelkeys||{});return this.keyFormatPromise||(this.log("Selecting key-system from fragment (sn: "+e.sn+" "+e.type+": "+e.level+") key formats "+t.join(", ")),this.keyFormatPromise=this.getKeyFormatPromise(t)),this.keyFormatPromise},t.getKeyFormatPromise=function(e){var t=this;return new Promise(function(r,a){var n=(0,f.getKeySystemsForConfig)(t.config),s=e.map(f.keySystemFormatToKeySystemDomain).filter(function(e){return!!e&&-1!==n.indexOf(e)});return t.getKeySystemSelectionPromise(s).then(function(e){var t=e.keySystem,n=(0,f.keySystemDomainToKeySystemFormat)(t);n?r(n):a(new Error("Unable to find format for key-system \""+t+"\""))}).catch(a)})},t.loadKey=function(e){var t=this,r=e.keyInfo.decryptdata,a=this.getKeyIdString(r),n="(keyId: "+a+" format: \""+r.keyFormat+"\" method: "+r.method+" uri: "+r.uri+")";this.log("Starting session for key "+n);var s=this.keyIdToKeySessionPromise[a];return s||(s=this.keyIdToKeySessionPromise[a]=this.getKeySystemForKeyPromise(r).then(function(a){var s=a.keySystem,i=a.mediaKeys;return t.throwIfDestroyed(),t.log("Handle encrypted media sn: "+e.frag.sn+" "+e.frag.type+": "+e.frag.level+" using key "+n),t.attemptSetMediaKeys(s,i).then(function(){t.throwIfDestroyed();var e=t.createMediaKeySessionContext({keySystem:s,mediaKeys:i,decryptdata:r});return t.generateRequestWithPreferredKeySession(e,"cenc",r.pssh,"playlist-key")})}),s.catch(function(e){return t.handleError(e)})),s},t.throwIfDestroyed=function(e){if(void 0===e&&(e="Invalid state"),!this.hls)throw new Error("invalid state")},t.handleError=function(e){this.hls&&(this.error(e.message),e instanceof L?this.hls.trigger(u.Events.ERROR,e.data):this.hls.trigger(u.Events.ERROR,{type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_NO_KEYS,error:e,fatal:!0}))},t.getKeySystemForKeyPromise=function(e){var t=this.getKeyIdString(e),r=this.keyIdToKeySessionPromise[t];if(!r){var a=(0,f.keySystemFormatToKeySystemDomain)(e.keyFormat),n=a?[a]:(0,f.getKeySystemsForConfig)(this.config);return this.attemptKeySystemAccess(n)}return r},t.getKeySystemSelectionPromise=function(e){if(e.length||(e=(0,f.getKeySystemsForConfig)(this.config)),0===e.length)throw new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_NO_CONFIGURED_LICENSE,fatal:!0},"Missing key-system license configuration options "+JSON.stringify({drmSystems:this.config.drmSystems}));return this.attemptKeySystemAccess(e)},t._onMediaEncrypted=function(e){var t=this,r=e.initDataType,a=e.initData;if(this.debug("\""+e.type+"\" event: init data type: \""+r+"\""),null!==a){var n,s;if("sinf"===r&&this.config.drmSystems[f.KeySystems.FAIRPLAY]){var o=(0,T.bin2str)(new Uint8Array(a));try{var d=(0,p.base64Decode)(JSON.parse(o).sinf),l=(0,T.parseSinf)(new Uint8Array(d));if(!l)return;n=l.subarray(8,24),s=f.KeySystems.FAIRPLAY}catch(e){return void this.warn("Failed to parse sinf \"encrypted\" event message initData")}}else{var u=(0,T.parsePssh)(a);if(null===u)return;0===u.version&&u.systemId===f.KeySystemIds.WIDEVINE&&u.data&&(n=u.data.subarray(8,24)),s=(0,f.keySystemIdToKeySystemDomain)(u.systemId)}if(s&&n){for(var c=E["default"].hexDump(n),g=this.keyIdToKeySessionPromise,m=this.mediaKeySessions,h=g[c],S=function(e){var s=m[e],i=s.decryptdata;if(i.pssh||!i.keyId)return"continue";var o=E["default"].hexDump(i.keyId);if(c===o||-1!==i.uri.replace(/-/g,"").indexOf(c))return h=g[o],delete g[o],i.pssh=new Uint8Array(a),i.keyId=n,h=g[c]=h.then(function(){return t.generateRequestWithPreferredKeySession(s,r,a,"encrypted-event-key-match")}),"break"},v=0,L;v<m.length&&(L=S(v),"continue"===L||"break"!==L);v++);h||(h=g[c]=this.getKeySystemSelectionPromise([s]).then(function(e){var s=e.keySystem,i=e.mediaKeys,o;t.throwIfDestroyed();var d=new y.LevelKey("ISO-23001-7",c,null==(o=(0,f.keySystemDomainToKeySystemFormat)(s))?"":o);return d.pssh=new Uint8Array(a),d.keyId=n,t.attemptSetMediaKeys(s,i).then(function(){t.throwIfDestroyed();var e=t.createMediaKeySessionContext({decryptdata:d,keySystem:s,mediaKeys:i});return t.generateRequestWithPreferredKeySession(e,r,a,"encrypted-event-no-match")})})),h.catch(function(e){return t.handleError(e)})}}},t._onWaitingForKey=function(e){this.log("\""+e.type+"\" event")},t.attemptSetMediaKeys=function(e,t){var r=this,a=this.setMediaKeysQueue.slice();this.log("Setting media-keys for \""+e+"\"");var n=Promise.all(a).then(function(){if(!r.media)throw new Error("Attempted to set mediaKeys without media element attached");return r.media.setMediaKeys(t)});return this.setMediaKeysQueue.push(n),n.then(function(){r.log("Media-keys set for \""+e+"\""),a.push(n),r.setMediaKeysQueue=r.setMediaKeysQueue.filter(function(e){return-1===a.indexOf(e)})})},t.generateRequestWithPreferredKeySession=function(e,t,r,a){var n=this,s=null===(i=this.config.drmSystems)||void 0===i||null===(o=i[e.keySystem])||void 0===o?void 0:o.generateRequest,i,o;if(s)try{var d=s.call(this.hls,t,r,e);if(!d)throw new Error("Invalid response from configured generateRequest filter");t=d.initDataType,r=e.decryptdata.pssh=d.initData?new Uint8Array(d.initData):null}catch(e){var l;if(this.warn(e.message),null!==(l=this.hls)&&void 0!==l&&l.config.debug)throw e}if(null===r)return this.log("Skipping key-session request for \""+a+"\" (no initData)"),Promise.resolve(e);var u=this.getKeyIdString(e.decryptdata);this.log("Generating key-session request for \""+a+"\": "+u+" (init data type: "+t+" length: "+(r?r.byteLength:null)+")");var g=new(S());e.mediaKeysSession.onmessage=function(t){var r=e.mediaKeysSession;if(!r)return void g.emit("error",new Error("invalid state"));var a=t.messageType,s=t.message;n.log("\""+a+"\" message event for session \""+r.sessionId+"\" message size: "+s.byteLength),"license-request"===a||"license-renewal"===a?n.renewLicense(e,s).catch(function(e){n.handleError(e),g.emit("error",e)}):"license-release"===a?e.keySystem===f.KeySystems.FAIRPLAY&&(n.updateKeySession(e,(0,m.strToUtf8array)("acknowledged")),n.removeSession(e)):n.warn("unhandled media key message type \""+a+"\"")},e.mediaKeysSession.onkeystatuseschange=function(){var t=e.mediaKeysSession;if(!t)return void g.emit("error",new Error("invalid state"));n.onKeyStatusChange(e);var r=e.keyStatus;g.emit("keyStatus",r),"expired"===r&&(n.warn(e.keySystem+" expired for key "+u),n.renewKeySession(e))};var p=new Promise(function(e,t){g.on("error",t),g.on("keyStatus",function(r){r.startsWith("usable")?e():"output-restricted"===r?t(new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED,fatal:!1},"HDCP level output restricted")):"internal-error"===r?t(new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_STATUS_INTERNAL_ERROR,fatal:!0},"key status changed to \""+r+"\"")):"expired"===r?t(new Error("key expired while generating request")):n.warn("unhandled key status change \""+r+"\"")})});return e.mediaKeysSession.generateRequest(t,r).then(function(){var t;n.log("Request generated for key-session \""+(null===(t=e.mediaKeysSession)||void 0===t?void 0:t.sessionId)+"\" keyId: "+u)}).catch(function(e){throw new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_NO_SESSION,error:e,fatal:!1},"Error generating key-session request: "+e)}).then(function(){return p}).catch(function(t){throw g.removeAllListeners(),n.removeSession(e),t}).then(function(){return g.removeAllListeners(),e})},t.onKeyStatusChange=function(e){var t=this;e.mediaKeysSession.keyStatuses.forEach(function(r,a){t.log("key status change \""+r+"\" for keyStatuses keyId: "+E["default"].hexDump("buffer"in a?new Uint8Array(a.buffer,a.byteOffset,a.byteLength):new Uint8Array(a))+" session keyId: "+E["default"].hexDump(new Uint8Array(e.decryptdata.keyId||[]))+" uri: "+e.decryptdata.uri),e.keyStatus=r})},t.fetchServerCertificate=function(e){var t=this;return new Promise(function(r,a){var n=t.getServerCertificateUrl(e);if(!n)return r();t.log("Fetching serverCertificate for \""+e+"\"");var s=new XMLHttpRequest;s.open("GET",n,!0),s.responseType="arraybuffer",s.onreadystatechange=function(){s.readyState===XMLHttpRequest.DONE&&(200===s.status?r(s.response):a(new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED,fatal:!0,networkDetails:s},"\""+e+"\" certificate request XHR failed ("+n+"). Status: "+s.status+" ("+s.statusText+")")))},s.send()})},t.setMediaKeysServerCertificate=function(e,t,r){var a=this;return new Promise(function(n,s){e.setServerCertificate(r).then(function(s){a.log("setServerCertificate "+(s?"success":"not supported by CDM")+" ("+(null===r||void 0===r?void 0:r.byteLength)+") on \""+t+"\""),n(e)}).catch(function(e){s(new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED,error:e,fatal:!0},e.message))})})},t.renewLicense=function(e,t){var r=this;return this.requestLicense(e,new Uint8Array(t)).then(function(t){return r.updateKeySession(e,new Uint8Array(t)).catch(function(e){throw new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_SESSION_UPDATE_FAILED,error:e,fatal:!0},e.message)})})},t.setupLicenseXHR=function(e,t,r,a){var n=this,s=this.config.licenseXhrSetup;return s?Promise.resolve().then(function(){if(!r.decryptdata)throw new Error("Key removed");return s.call(n.hls,e,t,r,a)}).catch(function(i){if(!r.decryptdata)throw i;return e.open("POST",t,!0),s.call(n.hls,e,t,r,a)}).then(function(r){e.readyState||e.open("POST",t,!0);var n=r?r:a;return{xhr:e,licenseChallenge:n}}):(e.open("POST",t,!0),Promise.resolve({xhr:e,licenseChallenge:a}))},t.requestLicense=function(e,t){var r=this;return new Promise(function(a,n){var s=r.getLicenseServerUrl(e.keySystem);r.log("Sending license request to URL: "+s);var i=new XMLHttpRequest;i.responseType="arraybuffer",i.onreadystatechange=function(){if(!r.hls||!e.mediaKeysSession)return n(new Error("invalid state"));if(4===i.readyState)if(200===i.status){r._requestLicenseFailureCount=0;var o=i.response;r.log("License received "+(o instanceof ArrayBuffer?o.byteLength:o));var d=r.config.licenseResponseCallback;if(d)try{o=d.call(r.hls,i,s,e)}catch(e){r.error(e)}a(o)}else if(r._requestLicenseFailureCount++,3<r._requestLicenseFailureCount||400<=i.status&&500>i.status)n(new L({type:c.ErrorTypes.KEY_SYSTEM_ERROR,details:c.ErrorDetails.KEY_SYSTEM_LICENSE_REQUEST_FAILED,fatal:!0,networkDetails:i},"License Request XHR failed ("+s+"). Status: "+i.status+" ("+i.statusText+")"));else{var l=3-r._requestLicenseFailureCount+1;r.warn("Retrying license request, "+l+" attempts left"),r.requestLicense(e,t).then(a,n)}},e.licenseXhr&&e.licenseXhr.readyState!==XMLHttpRequest.DONE&&e.licenseXhr.abort(),e.licenseXhr=i,r.setupLicenseXHR(i,s,e,t).then(function(e){var t=e.xhr,r=e.licenseChallenge;t.send(r)})})},t.onMediaAttached=function(e,t){if(this.config.emeEnabled){var r=t.media;this.media=r,r.addEventListener("encrypted",this.onMediaEncrypted),r.addEventListener("waitingforkey",this.onWaitingForKey)}},t.onMediaDetached=function(){var t=this,r=this.media,a=this.mediaKeySessions;r&&(r.removeEventListener("encrypted",this.onMediaEncrypted),r.removeEventListener("waitingforkey",this.onWaitingForKey),this.media=null),this._requestLicenseFailureCount=0,this.setMediaKeysQueue=[],this.mediaKeySessions=[],this.keyIdToKeySessionPromise={},y.LevelKey.clearKeyUriToKeyIdMap();var n=a.length;e.CDMCleanupPromise=Promise.all(a.map(function(e){return t.removeSession(e)}).concat(null===r||void 0===r?void 0:r.setMediaKeys(null).catch(function(e){t.log("Could not clear media keys: "+e+". media.src: "+(null===r||void 0===r?void 0:r.src))}))).then(function(){n&&(t.log("finished closing key sessions and clearing media keys"),a.length=0)}).catch(function(e){t.log("Could not close sessions and clear media keys: "+e+". media.src: "+(null===r||void 0===r?void 0:r.src))})},t.onManifestLoaded=function(e,t){var r=t.sessionKeys;if(r&&this.config.emeEnabled&&!this.keyFormatPromise){var a=r.reduce(function(e,t){return-1===e.indexOf(t.keyFormat)&&e.push(t.keyFormat),e},[]);this.log("Selecting key-system from session-keys "+a.join(", ")),this.keyFormatPromise=this.getKeyFormatPromise(a)}},t.removeSession=function(e){var t=this,r=e.mediaKeysSession,a=e.licenseXhr;if(r){this.log("Remove licenses and keys and close session "+r.sessionId),r.onmessage=null,r.onkeystatuseschange=null,a&&a.readyState!==XMLHttpRequest.DONE&&a.abort(),e.mediaKeysSession=e.decryptdata=e.licenseXhr=void 0;var n=this.mediaKeySessions.indexOf(e);return-1<n&&this.mediaKeySessions.splice(n,1),r.remove().catch(function(e){t.log("Could not remove session: "+e)}).then(function(){return r.close()}).catch(function(e){t.log("Could not close session: "+e)})}},e}();v.CDMCleanupPromise=void 0;var L=function(e){function t(t,r){var a;return a=e.call(this,r)||this,a.data=void 0,a.data=t,t.err=t.error,a}return a(t,e),t}(n(Error));const D=v},"./src/controller/fps-controller.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>i});var a=r("./src/events.ts"),n=r("./src/utils/logger.ts"),s=function(){function e(e){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=e,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.registerListeners=function(){this.hls.on(a.Events.MEDIA_ATTACHING,this.onMediaAttaching,this)},t.unregisterListeners=function(){this.hls.off(a.Events.MEDIA_ATTACHING,this.onMediaAttaching)},t.destroy=function(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null},t.onMediaAttaching=function(e,t){var r=this.hls.config;if(r.capLevelOnFPSDrop){var a=t.media instanceof self.HTMLVideoElement?t.media:null;this.media=a,a&&"function"==typeof a.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),r.fpsDroppedMonitoringPeriod)}},t.checkFPS=function(e,t,r){var s=performance.now();if(t){if(this.lastTime){var i=s-this.lastTime,o=r-this.lastDroppedFrames,d=t-this.lastDecodedFrames,l=this.hls;if(l.trigger(a.Events.FPS_DROP,{currentDropped:o,currentDecoded:d,totalDroppedFrames:r}),0<1e3*o/i&&o>l.config.fpsDroppedMonitoringThreshold*d){var u=l.currentLevel;n.logger.warn("drop FPS ratio greater than max allowed value for currentLevel: "+u),0<u&&(-1===l.autoLevelCapping||l.autoLevelCapping>=u)&&(--u,l.trigger(a.Events.FPS_DROP_LEVEL_CAPPING,{level:u,droppedLevel:l.currentLevel}),l.autoLevelCapping=u,this.streamController.nextLevelSwitch())}}this.lastTime=s,this.lastDroppedFrames=r,this.lastDecodedFrames=t}},t.checkFPSInterval=function(){var e=this.media;if(e)if(this.isVideoPlaybackQualityAvailable){var t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)},e}();const i=s},"./src/controller/fragment-finders.ts":(e,t,r)=>{"use strict";function a(e,t,r){if(null===t||!Array.isArray(e)||!e.length||!(0,d.isFiniteNumber)(t))return null;var a=e[0].programDateTime;if(t<(a||0))return null;var n=e[e.length-1].endProgramDateTime;if(t>=(n||0))return null;r=r||0;for(var s=0,o;s<e.length;++s)if(o=e[s],i(t,r,o))return o;return null}function n(e,t,r,a){void 0===r&&(r=0),void 0===a&&(a=0);var n=null;if(e?n=t[e.sn-t[0].sn+1]||null:0===r&&0===t[0].start&&(n=t[0]),n&&0===s(r,a,n))return n;var i=l["default"].search(t,s.bind(null,r,a));return i&&(i!==e||!n)?i:n}function s(e,t,r){if(void 0===e&&(e=0),void 0===t&&(t=0),r.start<=e&&r.start+r.duration>e)return 0;var a=Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return r.start+r.duration-a<=e?1:r.start-a>e&&r.start?-1:0}function i(e,t,r){var a=1e3*Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0)),n=r.endProgramDateTime||0;return n-a>e}function o(e,t){return l["default"].search(e,function(e){return e.cc<t?1:e.cc>t?-1:0})}r.r(t),r.d(t,{findFragWithCC:()=>o,findFragmentByPDT:()=>a,findFragmentByPTS:()=>n,fragmentWithinToleranceTest:()=>s,pdtWithinToleranceTest:()=>i});var d=r("./src/polyfills/number.ts"),l=r("./src/utils/binary-search.ts")},"./src/controller/fragment-tracker.ts":(e,t,r)=>{"use strict";function a(e){var t,r;return e.buffered&&((null===(t=e.range.video)||void 0===t?void 0:t.partial)||(null===(r=e.range.audio)||void 0===r?void 0:r.partial))}function n(e){return e.type+"_"+e.level+"_"+e.urlId+"_"+e.sn}r.r(t),r.d(t,{FragmentState:()=>d,FragmentTracker:()=>l});var s=r("./src/events.ts"),o=r("./src/types/loader.ts"),d;(function(e){e.NOT_LOADED="NOT_LOADED",e.APPENDING="APPENDING",e.PARTIAL="PARTIAL",e.OK="OK"})(d||(d={}));var l=function(){function e(e){this.activeFragment=null,this.activeParts=null,this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hls=e,this._registerListeners()}var t=e.prototype;return t._registerListeners=function(){var e=this.hls;e.on(s.Events.BUFFER_APPENDED,this.onBufferAppended,this),e.on(s.Events.FRAG_BUFFERED,this.onFragBuffered,this),e.on(s.Events.FRAG_LOADED,this.onFragLoaded,this)},t._unregisterListeners=function(){var e=this.hls;e.off(s.Events.BUFFER_APPENDED,this.onBufferAppended,this),e.off(s.Events.FRAG_BUFFERED,this.onFragBuffered,this),e.off(s.Events.FRAG_LOADED,this.onFragLoaded,this)},t.destroy=function(){this._unregisterListeners(),this.fragments=this.endListFragments=this.timeRanges=this.activeFragment=this.activeParts=null},t.getAppendedFrag=function(e,t){if(t===o.PlaylistLevelType.MAIN){var r=this.activeFragment,a=this.activeParts;if(!r)return null;if(a)for(var n=a.length;n--;){var s=a[n],d=s?s.end:r.appendedPTS;if(s.start<=e&&void 0!==d&&e<=d)return 9<n&&(this.activeParts=a.slice(n-9)),s}else if(r.start<=e&&void 0!==r.appendedPTS&&e<=r.appendedPTS)return r}return this.getBufferedFrag(e,t)},t.getBufferedFrag=function(e,t){for(var r=this.fragments,a=Object.keys(r),n=a.length,s;n--;)if(s=r[a[n]],(null===s||void 0===s?void 0:s.body.type)===t&&s.buffered){var o=s.body;if(o.start<=e&&e<=o.end)return o}return null},t.detectEvictedFragments=function(e,t,r){var a=this;this.timeRanges&&(this.timeRanges[e]=t),Object.keys(this.fragments).forEach(function(n){var s=a.fragments[n];if(s){if(!s.buffered&&!s.loaded)return void(s.body.type===r&&a.removeFragment(s.body));var i=s.range[e];i&&i.time.some(function(e){var r=!a.isTimeBuffered(e.startPTS,e.endPTS,t);return r&&a.removeFragment(s.body),r})}})},t.detectPartialFragments=function(e){var t=this,r=this.timeRanges,a=e.frag,s=e.part;if(r&&"initSegment"!==a.sn){var i=n(a),o=this.fragments[i];o&&(Object.keys(r).forEach(function(e){var n=a.elementaryStreams[e];if(n){var i=r[e],d=null!==s||!0===n.partial;o.range[e]=t.getBufferedTimes(a,s,d,i)}}),o.loaded=null,Object.keys(o.range).length?(o.buffered=!0,o.body.endList&&(this.endListFragments[o.body.type]=o)):this.removeFragment(o.body))}},t.fragBuffered=function(e){var t=n(e),r=this.fragments[t];r&&(r.loaded=null,r.buffered=!0)},t.getBufferedTimes=function(e,t,r,a){for(var n={time:[],partial:r},s=t?t.start:e.start,o=t?t.end:e.end,d=e.minEndPTS||o,l=e.maxStartPTS||s,u=0;u<a.length;u++){var c=a.start(u)-this.bufferPadding,g=a.end(u)+this.bufferPadding;if(l>=c&&d<=g){n.time.push({startPTS:Math.max(s,a.start(u)),endPTS:Math.min(o,a.end(u))});break}else if(s<g&&o>c)n.partial=!0,n.time.push({startPTS:Math.max(s,a.start(u)),endPTS:Math.min(o,a.end(u))});else if(o<=c)break}return n},t.getPartialFragment=function(e){var t=null,r=0,n=this.bufferPadding,s=this.fragments,i,o,d;return Object.keys(s).forEach(function(l){var u=s[l];!u||a(u)&&(o=u.body.start-n,d=u.body.end+n,e>=o&&e<=d&&(i=Math.min(e-o,d-e),r<=i&&(t=u.body,r=i)))}),t},t.isEndListAppended=function(e){var t=this.endListFragments[e];return void 0!==t&&(t.buffered||a(t))},t.getState=function(e){var t=n(e),r=this.fragments[t];return r?r.buffered?a(r)?d.PARTIAL:d.OK:d.APPENDING:d.NOT_LOADED},t.isTimeBuffered=function(e,t,r){for(var a=0,n,s;a<r.length;a++){if(n=r.start(a)-this.bufferPadding,s=r.end(a)+this.bufferPadding,e>=n&&t<=s)return!0;if(t<=n)return!1}return!1},t.onFragLoaded=function(e,t){var r=t.frag,a=t.part;if(!("initSegment"===r.sn||r.bitrateTest||a)){var s=n(r);this.fragments[s]={body:r,loaded:t,buffered:!1,range:Object.create(null)}}},t.onBufferAppended=function(e,t){var r=this,a=t.frag,n=t.part,s=t.timeRanges;if(a.type===o.PlaylistLevelType.MAIN)if(this.activeFragment!==a&&(this.activeFragment=a,a.appendedPTS=void 0),n){var i=this.activeParts;i||(this.activeParts=i=[]),i.push(n)}else this.activeParts=null;this.timeRanges=s,Object.keys(s).forEach(function(e){var t=s[e];if(r.detectEvictedFragments(e,t),!n&&a.type===o.PlaylistLevelType.MAIN){var d=a.elementaryStreams[e];if(!d)return;for(var l=0,u;l<t.length;l++)u=t.end(l),a.appendedPTS=u<=d.endPTS&&u>d.startPTS?Math.max(u,a.appendedPTS||0):d.endPTS}})},t.onFragBuffered=function(e,t){this.detectPartialFragments(t)},t.hasFragment=function(e){var t=n(e);return!!this.fragments[t]},t.removeFragmentsInRange=function(e,t,r){var a=this;Object.keys(this.fragments).forEach(function(n){var s=a.fragments[n];if(s&&s.buffered){var i=s.body;i.type===r&&i.start<t&&i.end>e&&a.removeFragment(i)}})},t.removeFragment=function(e){var t=n(e);e.stats.loaded=0,e.clearElementaryStreamInfo(),e.appendedPTS=void 0,delete this.fragments[t],e.endList&&delete this.endListFragments[e.type]},t.removeAllFragments=function(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activeFragment=null,this.activeParts=null},e}()},"./src/controller/gap-controller.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{MAX_START_GAP_JUMP:()=>d,SKIP_BUFFER_HOLE_STEP_SECONDS:()=>l,SKIP_BUFFER_RANGE_START:()=>u,STALL_MINIMUM_DURATION_MS:()=>o,default:()=>c});var a=r("./src/utils/buffer-helper.ts"),n=r("./src/errors.ts"),s=r("./src/events.ts"),i=r("./src/utils/logger.ts"),o=250,d=2,l=.1,u=.05,c=function(){function e(e,t,r,a){this.config=void 0,this.media=null,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=e,this.media=t,this.fragmentTracker=r,this.hls=a}var t=e.prototype;return t.destroy=function(){this.media=null,this.hls=this.fragmentTracker=null},t.poll=function(e,t){var r=this.config,n=this.media,s=this.stalled;if(null!==n){var o=n.currentTime,d=n.seeking,l=this.seeking&&!d,u=!this.seeking&&d;if(this.seeking=d,o!==e){if(this.moved=!0,null!==s){if(this.stallReported){var c=self.performance.now()-s;i.logger.warn("playback not stuck anymore @"+o+", after "+Math.round(c)+"ms"),this.stallReported=!1}this.stalled=null,this.nudgeRetry=0}return}if((u||l)&&(this.stalled=null),(!n.paused||d)&&!n.ended&&0!==n.playbackRate&&a.BufferHelper.getBuffered(n).length){var g=a.BufferHelper.bufferInfo(n,o,0),f=0<g.len,m=g.nextStart||0;if(f||m){if(d){var p=2<g.len,y=!m||t&&t.start<=o||2<m-o&&!this.fragmentTracker.getPartialFragment(o);if(p||y)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var E=Math.max(m,g.start||0)-o,T=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,h=null===T||void 0===T||null===(v=T.details)||void 0===v?void 0:v.live,S=h?2*T.details.targetduration:2,v;if(0<E&&E<=S)return void this._trySkipBufferHole(null)}var L=self.performance.now();if(null===s)return void(this.stalled=L);var D=L-s;if(!(!d&&250<=D&&(this._reportStall(g),!this.media))){var k=a.BufferHelper.bufferInfo(n,o,r.maxBufferHole);this._tryFixBufferStall(k,D)}}}}},t._tryFixBufferStall=function(e,t){var r=this.config,a=this.fragmentTracker,n=this.media;if(null!==n){var s=n.currentTime,o=a.getPartialFragment(s);if(o){var d=this._trySkipBufferHole(o);if(d||!this.media)return}e.len>r.maxBufferHole&&t>1e3*r.highBufferWatchdogPeriod&&(i.logger.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}},t._reportStall=function(e){var t=this.hls,r=this.media,a=this.stallReported;!a&&r&&(this.stallReported=!0,i.logger.warn("Playback stalling at @"+r.currentTime+" due to low buffer ("+JSON.stringify(e)+")"),t.trigger(s.Events.ERROR,{type:n.ErrorTypes.MEDIA_ERROR,details:n.ErrorDetails.BUFFER_STALLED_ERROR,fatal:!1,buffer:e.len}))},t._trySkipBufferHole=function(e){var t=this.config,r=this.hls,o=this.media;if(null===o)return 0;for(var d=o.currentTime,c=0,g=a.BufferHelper.getBuffered(o),f=0,m;f<g.length;f++){if(m=g.start(f),d+t.maxBufferHole>=c&&d<m){var p=Math.max(m+u,o.currentTime+l);return i.logger.warn("skipping hole, adjusting currentTime from "+d+" to "+p),this.moved=!0,this.stalled=null,o.currentTime=p,e&&r.trigger(s.Events.ERROR,{type:n.ErrorTypes.MEDIA_ERROR,details:n.ErrorDetails.BUFFER_SEEK_OVER_HOLE,fatal:!1,reason:"fragment loaded with buffer holes, seeking from "+d+" to "+p,frag:e}),p}c=g.end(f)}return 0},t._tryNudgeBuffer=function(){var e=this.config,t=this.hls,r=this.media,a=this.nudgeRetry;if(null!==r){var o=r.currentTime;if(this.nudgeRetry++,a<e.nudgeMaxRetry){var d=o+(a+1)*e.nudgeOffset;i.logger.warn("Nudging 'currentTime' from "+o+" to "+d),r.currentTime=d,t.trigger(s.Events.ERROR,{type:n.ErrorTypes.MEDIA_ERROR,details:n.ErrorDetails.BUFFER_NUDGE_ON_STALL,fatal:!1})}else i.logger.error("Playhead still not moving while enough data buffered @"+o+" after "+e.nudgeMaxRetry+" nudges"),t.trigger(s.Events.ERROR,{type:n.ErrorTypes.MEDIA_ERROR,details:n.ErrorDetails.BUFFER_STALLED_ERROR,fatal:!0})}},e}()},"./src/controller/id3-track-controller.ts":(e,t,r)=>{"use strict";function a(){return self.WebKitDataCue||self.VTTCue||self.TextTrackCue}function n(e,t){return e.getTime()/1e3-t}function s(e){return Uint8Array.from(e.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer}r.r(t),r.d(t,{default:()=>p});var o=r("./src/polyfills/number.ts"),d=r("./src/events.ts"),l=r("./src/utils/texttrack-utils.ts"),u=r("./src/demux/id3.ts"),c=r("./src/loader/date-range.ts"),g=r("./src/types/demuxer.ts"),f=function(){var e=a();try{new e(0,Number.POSITIVE_INFINITY,"")}catch(t){return Number.MAX_VALUE}return Number.POSITIVE_INFINITY}(),m=function(){function e(e){this.hls=void 0,this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=e,this._registerListeners()}var t=e.prototype;return t.destroy=function(){this._unregisterListeners(),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=null},t._registerListeners=function(){var e=this.hls;e.on(d.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(d.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(d.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(d.Events.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.on(d.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(d.Events.LEVEL_UPDATED,this.onLevelUpdated,this)},t._unregisterListeners=function(){var e=this.hls;e.off(d.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(d.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(d.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(d.Events.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.off(d.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(d.Events.LEVEL_UPDATED,this.onLevelUpdated,this)},t.onMediaAttached=function(e,t){this.media=t.media},t.onMediaDetaching=function(){this.id3Track&&((0,l.clearCurrentCues)(this.id3Track),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={})},t.onManifestLoading=function(){this.dateRangeCuesAppended={}},t.createTrack=function(e){var t=this.getID3Track(e.textTracks);return t.mode="hidden",t},t.getID3Track=function(e){if(this.media){for(var t=0,r;t<e.length;t++)if(r=e[t],"metadata"===r.kind&&"id3"===r.label)return(0,l.sendAddTrackEvent)(r,this.media),r;return this.media.addTextTrack("metadata","id3")}},t.onFragParsingMetadata=function(e,t){if(this.media){var r=this.hls.config,n=r.enableEmsgMetadataCues,s=r.enableID3MetadataCues;if(n||s){var o=t.samples;this.id3Track||(this.id3Track=this.createTrack(this.media));for(var d=a(),l=0,c;l<o.length;l++)if(c=o[l].type,(c!==g.MetadataSchema.emsg||n)&&s){var m=u.getID3Frames(o[l].data);if(m){var p=o[l].pts,y=p+o[l].duration;y>f&&(y=f);var E=y-p;0>=E&&(y=p+.25);for(var T=0,h;T<m.length;T++)if(h=m[T],!u.isTimeStampFrame(h)){this.updateId3CueEnds(p);var S=new d(p,y,"");S.value=h,c&&(S.type=c),this.id3Track.addCue(S)}}}}}},t.updateId3CueEnds=function(e){var t=null===(r=this.id3Track)||void 0===r?void 0:r.cues,r;if(t)for(var a=t.length,n;a--;)n=t[a],n.startTime<e&&n.endTime===f&&(n.endTime=e)},t.onBufferFlushing=function(e,t){var r=t.startOffset,a=t.endOffset,n=t.type,s=this.id3Track,i=this.hls;if(i){var o=i.config,d=o.enableEmsgMetadataCues,u=o.enableID3MetadataCues;if(s&&(d||u)){var c;c="audio"===n?function(e){return e.type===g.MetadataSchema.audioId3&&u}:"video"===n?function(e){return e.type===g.MetadataSchema.emsg&&d}:function(e){return e.type===g.MetadataSchema.audioId3&&u||e.type===g.MetadataSchema.emsg&&d},(0,l.removeCuesInRange)(s,r,a,c)}}},t.onLevelUpdated=function(e,t){var r=this,d=t.details;if(this.media&&d.hasProgramDateTime&&this.hls.config.enableDateRangeMetadataCues){var l=this.dateRangeCuesAppended,u=this.id3Track,m=d.dateRanges,p=Object.keys(m);if(u)for(var y=Object.keys(l).filter(function(e){return!p.includes(e)}),E=function(e){var t=y[e];Object.keys(l[t].cues).forEach(function(e){u.removeCue(l[t].cues[e])}),delete l[t]},T=y.length;T--;)E(T);var h=d.fragments[d.fragments.length-1];if(0!==p.length&&(0,o.isFiniteNumber)(null===h||void 0===h?void 0:h.programDateTime)){this.id3Track||(this.id3Track=this.createTrack(this.media));for(var S=h.programDateTime/1e3-h.start,v=a(),L=function(e){var t=p[e],a=m[t],i=l[t],o=(null===i||void 0===i?void 0:i.cues)||{},d=(null===i||void 0===i?void 0:i.durationKnown)||!1,u=n(a.startDate,S),y=f,E=a.endDate;if(E)y=n(E,S),d=!0;else if(a.endOnNext&&!d){var T=p.reduce(function(e,t){var r=m[t];return r.class===a.class&&r.id!==t&&r.startDate>a.startDate&&e.push(r),e},[]).sort(function(e,t){return e.startDate.getTime()-t.startDate.getTime()})[0];T&&(y=n(T.startDate,S),d=!0)}for(var h=Object.keys(a.attr),L=0,D;L<h.length;L++)if(D=h[L],D!==c.DateRangeAttribute.ID&&D!==c.DateRangeAttribute.CLASS&&D!==c.DateRangeAttribute.START_DATE&&D!==c.DateRangeAttribute.DURATION&&D!==c.DateRangeAttribute.END_DATE&&D!==c.DateRangeAttribute.END_ON_NEXT){var k=o[D];if(k)d&&!i.durationKnown&&(k.endTime=y);else{var I=a.attr[D];k=new v(u,y,""),(D===c.DateRangeAttribute.SCTE35_OUT||D===c.DateRangeAttribute.SCTE35_IN)&&(I=s(I)),k.value={key:D,data:I},k.type=g.MetadataSchema.dateRange,r.id3Track.addCue(k),o[D]=k}}l[t]={cues:o,dateRange:a,durationKnown:d}},D=0;D<p.length;D++)L(D)}}},e}();const p=m},"./src/controller/latency-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{default:()=>u});var o=r("./src/errors.ts"),d=r("./src/events.ts"),l=r("./src/utils/logger.ts"),u=function(){function e(e){var t=this;this.hls=void 0,this.config=void 0,this.media=null,this.levelDetails=null,this.currentTime=0,this.stallCount=0,this._latency=null,this.timeupdateHandler=function(){return t.timeupdate()},this.hls=e,this.config=e.config,this.registerListeners()}var t=e.prototype;return t.destroy=function(){this.unregisterListeners(),this.onMediaDetaching(),this.levelDetails=null,this.hls=this.timeupdateHandler=null},t.registerListeners=function(){this.hls.on(d.Events.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(d.Events.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.on(d.Events.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(d.Events.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.on(d.Events.ERROR,this.onError,this)},t.unregisterListeners=function(){this.hls.off(d.Events.MEDIA_ATTACHED,this.onMediaAttached),this.hls.off(d.Events.MEDIA_DETACHING,this.onMediaDetaching),this.hls.off(d.Events.MANIFEST_LOADING,this.onManifestLoading),this.hls.off(d.Events.LEVEL_UPDATED,this.onLevelUpdated),this.hls.off(d.Events.ERROR,this.onError)},t.onMediaAttached=function(e,t){this.media=t.media,this.media.addEventListener("timeupdate",this.timeupdateHandler)},t.onMediaDetaching=function(){this.media&&(this.media.removeEventListener("timeupdate",this.timeupdateHandler),this.media=null)},t.onManifestLoading=function(){this.levelDetails=null,this._latency=null,this.stallCount=0},t.onLevelUpdated=function(e,t){var r=t.details;this.levelDetails=r,r.advanced&&this.timeupdate(),!r.live&&this.media&&this.media.removeEventListener("timeupdate",this.timeupdateHandler)},t.onError=function(e,t){t.details!==o.ErrorDetails.BUFFER_STALLED_ERROR||(this.stallCount++,l.logger.warn("[playback-rate-controller]: Stall detected, adjusting target latency"))},t.timeupdate=function(){var e=this.media,t=this.levelDetails;if(e&&t){this.currentTime=e.currentTime;var r=this.computeLatency();if(null!==r){this._latency=r;var a=this.config,n=a.lowLatencyMode,s=a.maxLiveSyncPlaybackRate;if(n&&1!==s){var i=this.targetLatency;if(null!==i){var o=r-i,d=Math.min(this.maxLatency,i+t.targetduration);if(t.live&&o<d&&.05<o&&1<this.forwardBufferLength){var l=Math.min(2,Math.max(1,s)),u=Math.round(20*(2/(1+Math.exp(-.75*o-this.edgeStalled))))/20;e.playbackRate=Math.min(l,Math.max(1,u))}else 1!==e.playbackRate&&0!==e.playbackRate&&(e.playbackRate=1)}}}}},t.estimateLiveEdge=function(){var e=this.levelDetails;return null===e?null:e.edge+e.age},t.computeLatency=function(){var e=this.estimateLiveEdge();return null===e?null:e-this.currentTime},n(e,[{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var e=this.config,t=this.levelDetails;return void 0===e.liveMaxLatencyDuration?t?e.liveMaxLatencyDurationCount*t.targetduration:0:e.liveMaxLatencyDuration}},{key:"targetLatency",get:function(){var e=this.levelDetails;if(null===e)return null;var t=e.holdBack,r=e.partHoldBack,a=e.targetduration,n=this.config,s=n.liveSyncDuration,i=n.liveSyncDurationCount,o=n.lowLatencyMode,d=this.hls.userConfig,l=o?r||t:t;(d.liveSyncDuration||d.liveSyncDurationCount||0===l)&&(l=void 0===s?i*a:s);return l+Math.min(1*this.stallCount,a)}},{key:"liveSyncPosition",get:function(){var e=this.estimateLiveEdge(),t=this.targetLatency,r=this.levelDetails;if(null===e||null===t||null===r)return null;var a=r.edge,n=e-t-this.edgeStalled,s=a-r.totalduration,i=a-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(s,n),i)}},{key:"drift",get:function(){var e=this.levelDetails;return null===e?1:e.drift}},{key:"edgeStalled",get:function(){var e=this.levelDetails;if(null===e)return 0;var t=3*(this.config.lowLatencyMode&&e.partTarget||e.targetduration);return Math.max(e.age-t,0)}},{key:"forwardBufferLength",get:function(){var e=this.media,t=this.levelDetails;if(!e||!t)return 0;var r=e.buffered.length;return(r?e.buffered.end(r-1):t.edge)-this.currentTime}}]),e}()},"./src/controller/level-controller.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,o(a.key),a)}function s(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e){var t=d(e,"string");return"symbol"==typeof t?t:t+""}function d(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function l(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,u(e,t)}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}r.r(t),r.d(t,{default:()=>h});var c=r("./src/types/level.ts"),g=r("./src/events.ts"),f=r("./src/errors.ts"),m=r("./src/utils/codecs.ts"),p=r("./src/controller/level-helper.ts"),y=r("./src/controller/base-playlist-controller.ts"),E=r("./src/types/loader.ts"),T=/chrome|firefox/.test(navigator.userAgent.toLowerCase()),h=function(e){function t(t){var r;return r=e.call(this,t,"[level-controller]")||this,r._levels=[],r._firstLevel=-1,r._startLevel=void 0,r.currentLevelIndex=-1,r.manualLevelIndex=-1,r.onParsedComplete=void 0,r._registerListeners(),r}l(t,e);var r=t.prototype;return r._registerListeners=function(){var e=this.hls;e.on(g.Events.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(g.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.on(g.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.on(g.Events.FRAG_LOADED,this.onFragLoaded,this),e.on(g.Events.ERROR,this.onError,this)},r._unregisterListeners=function(){var e=this.hls;e.off(g.Events.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(g.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.off(g.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.off(g.Events.FRAG_LOADED,this.onFragLoaded,this),e.off(g.Events.ERROR,this.onError,this)},r.destroy=function(){this._unregisterListeners(),this.manualLevelIndex=-1,this._levels.length=0,e.prototype.destroy.call(this)},r.startLoad=function(){var t=this._levels;t.forEach(function(e){e.loadError=0}),e.prototype.startLoad.call(this)},r.onManifestLoaded=function(e,t){var r=[],a=[],n=[],s={},o=!1,d=!1,l=!1,u,y;if(t.levels.forEach(function(e){var t=e.attrs;o=o||!!(e.width&&e.height),d=d||!!e.videoCodec,l=l||!!e.audioCodec,T&&e.audioCodec&&-1!==e.audioCodec.indexOf("mp4a.40.34")&&(e.audioCodec=void 0);var a=e.bitrate+"-"+e.attrs.RESOLUTION+"-"+e.attrs.CODECS;y=s[a],y?y.url.push(e.url):(y=new c.Level(e),s[a]=y,r.push(y)),t&&(t.AUDIO&&(0,p.addGroupId)(y,"audio",t.AUDIO),t.SUBTITLES&&(0,p.addGroupId)(y,"text",t.SUBTITLES))}),(o||d)&&l&&(r=r.filter(function(e){var t=e.videoCodec,r=e.width,a=e.height;return!!t||!!(r&&a)})),r=r.filter(function(e){var t=e.audioCodec,r=e.videoCodec;return(!t||(0,m.isCodecSupportedInMp4)(t,"audio"))&&(!r||(0,m.isCodecSupportedInMp4)(r,"video"))}),t.audioTracks&&(a=t.audioTracks.filter(function(e){return!e.audioCodec||(0,m.isCodecSupportedInMp4)(e.audioCodec,"audio")}),(0,p.assignTrackIdsByGroup)(a)),t.subtitles&&(n=t.subtitles,(0,p.assignTrackIdsByGroup)(n)),0<r.length){u=r[0].bitrate,r.sort(function(e,t){return e.attrs["HDCP-LEVEL"]===t.attrs["HDCP-LEVEL"]?e.bitrate===t.bitrate?e.attrs.SCORE===t.attrs.SCORE?o&&e.height!==t.height?e.height-t.height:0:e.attrs.decimalFloatingPoint("SCORE")-t.attrs.decimalFloatingPoint("SCORE"):e.bitrate-t.bitrate:(e.attrs["HDCP-LEVEL"]||"")>(t.attrs["HDCP-LEVEL"]||"")?1:-1}),this._levels=r;for(var E=0;E<r.length;E++)if(r[E].bitrate===u){this._firstLevel=E,this.log("manifest loaded, "+r.length+" level(s) found, first bitrate: "+u);break}var h=l&&!d,S={levels:r,audioTracks:a,subtitleTracks:n,sessionData:t.sessionData,sessionKeys:t.sessionKeys,firstLevel:this._firstLevel,stats:t.stats,audio:l,video:d,altAudio:!h&&a.some(function(e){return!!e.url})};this.hls.trigger(g.Events.MANIFEST_PARSED,S),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else this.hls.trigger(g.Events.ERROR,{type:f.ErrorTypes.MEDIA_ERROR,details:f.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:t.url,reason:"no level with compatible codecs found in manifest"})},r.onError=function(t,r){var a,n;if(e.prototype.onError.call(this,t,r),!r.fatal){var s=r.context,i=this._levels[this.currentLevelIndex];if(s&&(s.type===E.PlaylistContextType.AUDIO_TRACK&&i.audioGroupIds&&s.groupId===i.audioGroupIds[i.urlId]||s.type===E.PlaylistContextType.SUBTITLE_TRACK&&i.textGroupIds&&s.groupId===i.textGroupIds[i.urlId]))return void this.redundantFailover(this.currentLevelIndex);var o=!1,d=!0,l;switch(r.details){case f.ErrorDetails.FRAG_LOAD_ERROR:case f.ErrorDetails.FRAG_LOAD_TIMEOUT:case f.ErrorDetails.KEY_LOAD_ERROR:case f.ErrorDetails.KEY_LOAD_TIMEOUT:if(r.frag){var u=r.frag.type===E.PlaylistLevelType.MAIN?r.frag.level:this.currentLevelIndex,g=this._levels[u];g?(g.fragmentError++,g.fragmentError>this.hls.config.fragLoadingMaxRetry&&(l=u)):l=u}break;case f.ErrorDetails.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:{var m=i.attrs["HDCP-LEVEL"];m&&(this.hls.maxHdcpLevel=c.HdcpLevels[c.HdcpLevels.indexOf(m)-1],this.warn("Restricting playback to HDCP-LEVEL of \""+this.hls.maxHdcpLevel+"\" or lower"))}case f.ErrorDetails.FRAG_PARSING_ERROR:case f.ErrorDetails.KEY_SYSTEM_NO_SESSION:l=(null===(a=r.frag)||void 0===a?void 0:a.type)===E.PlaylistLevelType.MAIN?r.frag.level:this.currentLevelIndex,r.levelRetry=!1;break;case f.ErrorDetails.LEVEL_LOAD_ERROR:case f.ErrorDetails.LEVEL_LOAD_TIMEOUT:s&&(s.deliveryDirectives&&(d=!1),l=s.level),o=!0;break;case f.ErrorDetails.REMUX_ALLOC_ERROR:l=null==(n=r.level)?this.currentLevelIndex:n,o=!0;}void 0!==l&&this.recoverLevel(r,l,o,d)}},r.recoverLevel=function(e,t,r,a){var n=e.details,s=this._levels[t];if(s.loadError++,r){var o=this.retryLoadingOrFail(e);if(o)e.levelRetry=!0;else return void(this.currentLevelIndex=-1)}if(a){var d=s.url.length;if(1<d&&s.loadError<d)e.levelRetry=!0,this.redundantFailover(t);else if(-1===this.manualLevelIndex){for(var l=-1,u=this._levels,c=u.length,g;c--;)if(g=(c+this.currentLevelIndex)%u.length,g!==this.currentLevelIndex&&0===u[g].loadError){l=g;break}-1<l&&this.currentLevelIndex!==l?(this.warn(n+": switch to "+l),e.levelRetry=!0,this.hls.nextAutoLevel=l):!1===e.levelRetry&&(e.fatal=!0)}}},r.redundantFailover=function(e){var t=this._levels[e],r=t.url.length;if(1<r){var a=(t.urlId+1)%r;this.warn("Switching to redundant URL-id "+a),this._levels.forEach(function(e){e.urlId=a}),this.level=e}},r.onFragLoaded=function(e,t){var r=t.frag;if(void 0!==r&&r.type===E.PlaylistLevelType.MAIN){var a=this._levels[r.level];void 0!==a&&(a.fragmentError=0,a.loadError=0)}},r.onLevelLoaded=function(e,t){var r=t.level,a=t.details,n=this._levels[r],s;if(!n){var i;return this.warn("Invalid level index "+r),void(null!==(i=t.deliveryDirectives)&&void 0!==i&&i.skip&&(a.deltaUpdateFailed=!0))}r===this.currentLevelIndex?(0===n.fragmentError&&(n.loadError=0,this.retryCount=0),this.playlistLoaded(r,t,n.details)):null!==(s=t.deliveryDirectives)&&void 0!==s&&s.skip&&(a.deltaUpdateFailed=!0)},r.onAudioTrackSwitched=function(e,t){var r=this.hls.levels[this.currentLevelIndex];if(r&&r.audioGroupIds){for(var a=-1,n=this.hls.audioTracks[t.id].groupId,s=0;s<r.audioGroupIds.length;s++)if(r.audioGroupIds[s]===n){a=s;break}a!==r.urlId&&(r.urlId=a,this.startLoad())}},r.loadPlaylist=function(t){e.prototype.loadPlaylist.call(this);var r=this.currentLevelIndex,a=this._levels[r];if(this.canLoad&&a&&0<a.url.length){var n=a.urlId,s=a.url[n];if(t)try{s=t.addDirectives(s)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: "+e)}this.log("Attempt loading level index "+r+(void 0===(null===t||void 0===t?void 0:t.msn)?"":" at sn "+t.msn+" part "+t.part)+" with URL-id "+n+" "+s),this.clearTimer(),this.hls.trigger(g.Events.LEVEL_LOADING,{url:s,level:r,id:n,deliveryDirectives:t||null})}},r.removeLevel=function(e,t){var r=function(e,r){return r!==t},a=this._levels.filter(function(a,n){return n!==e||!!(1<a.url.length&&void 0!==t)&&(a.url=a.url.filter(r),a.audioGroupIds&&(a.audioGroupIds=a.audioGroupIds.filter(r)),a.textGroupIds&&(a.textGroupIds=a.textGroupIds.filter(r)),a.urlId=0,!0)}).map(function(e,t){var r=e.details;return null!==r&&void 0!==r&&r.fragments&&r.fragments.forEach(function(e){e.level=t}),e});this._levels=a,this.hls.trigger(g.Events.LEVELS_UPDATED,{levels:a})},s(t,[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(e){var t=this._levels,r;if(0!==t.length&&!(this.currentLevelIndex===e&&null!==(r=t[e])&&void 0!==r&&r.details)){if(0>e||e>=t.length){var n=0>e;if(this.hls.trigger(g.Events.ERROR,{type:f.ErrorTypes.OTHER_ERROR,details:f.ErrorDetails.LEVEL_SWITCH_ERROR,level:e,fatal:n,reason:"invalid level idx"}),n)return;e=Math.min(e,t.length-1)}this.clearTimer();var s=this.currentLevelIndex,i=t[s],o=t[e];this.log("switching to level "+e+" from "+s),this.currentLevelIndex=e;var d=a({},o,{level:e,maxBitrate:o.maxBitrate,uri:o.uri,urlId:o.urlId});delete d._urlId,this.hls.trigger(g.Events.LEVEL_SWITCHING,d);var l=o.details;if(!l||l.live){var u=this.switchParams(o.uri,null===i||void 0===i?void 0:i.details);this.loadPlaylist(u)}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(e){this.manualLevelIndex=e,void 0===this._startLevel&&(this._startLevel=e),-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var e=this.hls.config.startLevel;return void 0===e?this._firstLevel:e}return this._startLevel},set:function(e){this._startLevel=e}},{key:"nextLoadLevel",get:function(){return-1===this.manualLevelIndex?this.hls.nextAutoLevel:this.manualLevelIndex},set:function(e){this.level=e,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=e)}}]),t}(y["default"])},"./src/controller/level-helper.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t,r){"audio"===t?(e.audioGroupIds||(e.audioGroupIds=[]),e.audioGroupIds.push(r)):"text"===t?(e.textGroupIds||(e.textGroupIds=[]),e.textGroupIds.push(r)):void 0}function s(e){var t={};e.forEach(function(e){var r=e.groupId||"";e.id=t[r]=t[r]||0,t[r]++})}function i(e,t,r){var a=e[t],n=e[r];o(a,n)}function o(e,t){var r=t.startPTS;if((0,T.isFiniteNumber)(r)){var a=0,n;t.sn>e.sn?(a=r-e.start,n=e):(a=e.start-r,n=t),n.duration!==a&&(n.duration=a)}else if(t.sn>e.sn){var s=e.cc===t.cc;t.start=s&&e.minEndPTS?e.start+(e.minEndPTS-e.start):e.start+e.duration}else t.start=Math.max(e.start-t.duration,0)}function d(e,t,r,a,n,s){var d=a-r;0>=d&&(h.logger.warn("Fragment should have a positive duration",t),a=r+t.duration,s=n+t.duration);var l=r,u=a,c=t.startPTS,g=t.endPTS;if((0,T.isFiniteNumber)(c)){var f=Math.abs(c-r);t.deltaPTS=(0,T.isFiniteNumber)(t.deltaPTS)?Math.max(f,t.deltaPTS):f,l=Math.max(r,c),r=Math.min(r,c),n=Math.min(n,t.startDTS),u=Math.min(a,g),a=Math.max(a,g),s=Math.max(s,t.endDTS)}t.duration=a-r;var m=r-t.start;t.start=t.startPTS=r,t.maxStartPTS=l,t.startDTS=n,t.endPTS=a,t.minEndPTS=u,t.endDTS=s;var p=t.sn;if(!e||p<e.startSN||p>e.endSN)return 0;var y=p-e.startSN,E=e.fragments,S;for(E[y]=t,S=y;0<S;S--)o(E[S],E[S-1]);for(S=y;S<E.length-1;S++)o(E[S],E[S+1]);return e.fragmentHint&&o(E[E.length-1],e.fragmentHint),e.PTSKnown=e.alignedSliding=!0,m}function l(e,t){for(var r=null,a=e.fragments,n=a.length-1,s;0<=n;n--)if(s=a[n].initSegment,s){r=s;break}e.fragmentHint&&delete e.fragmentHint.endPTS;var o=0,l;if(g(e,t,function(e,a){e.relurl&&(o=e.cc-a.cc),(0,T.isFiniteNumber)(e.startPTS)&&(0,T.isFiniteNumber)(e.endPTS)&&(a.start=a.startPTS=e.startPTS,a.startDTS=e.startDTS,a.appendedPTS=e.appendedPTS,a.maxStartPTS=e.maxStartPTS,a.endPTS=e.endPTS,a.endDTS=e.endDTS,a.minEndPTS=e.minEndPTS,a.duration=e.endPTS-e.startPTS,a.duration&&(l=a),t.PTSKnown=t.alignedSliding=!0),a.elementaryStreams=e.elementaryStreams,a.loader=e.loader,a.stats=e.stats,a.urlId=e.urlId,e.initSegment&&(a.initSegment=e.initSegment,r=e.initSegment)}),r){var m=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments;m.forEach(function(e){var t;e.initSegment&&e.initSegment.relurl!==(null===(t=r)||void 0===t?void 0:t.relurl)||(e.initSegment=r)})}if(t.skippedSegments)if(t.deltaUpdateFailed=t.fragments.some(function(e){return!e}),t.deltaUpdateFailed){h.logger.warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(var p=t.skippedSegments;p--;)t.fragments.shift();t.startSN=t.fragments[0].sn,t.startCC=t.fragments[0].cc}else t.canSkipDateRanges&&(t.dateRanges=u(e.dateRanges,t.dateRanges,t.recentlyRemovedDateranges));var y=t.fragments;if(o){h.logger.warn("discontinuity sliding from playlist, take drift into account");for(var E=0;E<y.length;E++)y[E].cc+=o}t.skippedSegments&&(t.startCC=t.fragments[0].cc),c(e.partList,t.partList,function(e,t){t.elementaryStreams=e.elementaryStreams,t.stats=e.stats}),l?d(t,l,l.startPTS,l.endPTS,l.startDTS,l.endDTS):f(e,t),y.length&&(t.totalduration=t.edge-y[0].start),t.driftStartTime=e.driftStartTime,t.driftStart=e.driftStart;var S=t.advancedDateTime;if(t.advanced&&S){var v=t.edge;t.driftStart||(t.driftStartTime=S,t.driftStart=v),t.driftEndTime=S,t.driftEnd=v}else t.driftEndTime=e.driftEndTime,t.driftEnd=e.driftEnd,t.advancedDateTime=e.advancedDateTime}function u(e,t,r){var n=a({},e);return r&&r.forEach(function(e){delete n[e]}),Object.keys(t).forEach(function(e){var r=new S.DateRange(t[e].attr,n[e]);r.isValid?n[e]=r:h.logger.warn("Ignoring invalid Playlist Delta Update DATERANGE tag: \""+JSON.stringify(t[e].attr)+"\"")}),n}function c(e,t,r){if(e&&t)for(var a=0,n=0,s=e.length;n<=s;n++){var o=e[n],d=t[n+a];o&&d&&o.index===d.index&&o.fragment.sn===d.fragment.sn?r(o,d):a--}}function g(e,t,r){for(var a=t.skippedSegments,n=Math.max(e.startSN,t.startSN)-t.startSN,s=(e.fragmentHint?1:0)+(a?t.endSN:Math.min(e.endSN,t.endSN))-t.startSN,o=t.startSN-e.startSN,d=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments,l=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments,u=n;u<=s;u++){var c=l[o+u],g=d[u];a&&!g&&u<a&&(g=t.fragments[u]=c),c&&g&&r(c,g)}}function f(e,t){var r=t.startSN+t.skippedSegments-e.startSN,a=e.fragments;0>r||r>=a.length||m(t,a[r].start)}function m(e,t){if(t){for(var r=e.fragments,a=e.skippedSegments;a<r.length;a++)r[a].start+=t;e.fragmentHint&&(e.fragmentHint.start+=t)}}function p(e,t){void 0===t&&(t=1/0);var r=1e3*e.targetduration;if(e.updated){var a=e.fragments;if(a.length&&4*r>t){var n=1e3*a[a.length-1].duration;n<r&&(r=n)}}else r/=2;return Math.round(r)}function y(e,t,r){if(!e||!e.details)return null;var a=e.details,n=a.fragments[t-a.startSN];return n?n:(n=a.fragmentHint,n&&n.sn===t?n:t<a.startSN&&r&&r.sn===t?r:null)}function E(e,t,r){if(!e||!e.details)return null;var a=e.details.partList;if(a)for(var n=a.length,s;n--;)if(s=a[n],s.index===r&&s.fragment.sn===t)return s;return null}r.r(t),r.d(t,{addGroupId:()=>n,addSliding:()=>m,adjustSliding:()=>f,assignTrackIdsByGroup:()=>s,computeReloadInterval:()=>p,getFragmentWithSN:()=>y,getPartWith:()=>E,mapFragmentIntersection:()=>g,mapPartIntersection:()=>c,mergeDetails:()=>l,updateFragPTSDTS:()=>d,updatePTS:()=>i});var T=r("./src/polyfills/number.ts"),h=r("./src/utils/logger.ts"),S=r("./src/loader/date-range.ts")},"./src/controller/stream-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}r.r(t),r.d(t,{default:()=>v});var l=r("./src/polyfills/number.ts"),u=r("./src/controller/base-stream-controller.ts"),c=r("./src/is-supported.ts"),g=r("./src/events.ts"),f=r("./src/utils/buffer-helper.ts"),m=r("./src/controller/fragment-tracker.ts"),p=r("./src/types/loader.ts"),y=r("./src/loader/fragment.ts"),E=r("./src/demux/transmuxer-interface.ts"),T=r("./src/types/transmuxer.ts"),h=r("./src/controller/gap-controller.ts"),S=r("./src/errors.ts"),v=function(e){function t(t,r,a){var n;return n=e.call(this,t,r,a,"[stream-controller]")||this,n.audioCodecSwap=!1,n.gapController=null,n.level=-1,n._forceStartLoad=!1,n.altAudio=!1,n.audioOnly=!1,n.fragPlaying=null,n.onvplaying=null,n.onvseeked=null,n.fragLastKbps=0,n.couldBacktrack=!1,n.backtrackFragment=null,n.audioCodecSwitch=!1,n.videoBuffer=null,n._registerListeners(),n}o(t,e);var r=t.prototype;return r._registerListeners=function(){var e=this.hls;e.on(g.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(g.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(g.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(g.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.on(g.Events.LEVEL_LOADING,this.onLevelLoading,this),e.on(g.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.on(g.Events.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.on(g.Events.ERROR,this.onError,this),e.on(g.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(g.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.on(g.Events.BUFFER_CREATED,this.onBufferCreated,this),e.on(g.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(g.Events.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(g.Events.FRAG_BUFFERED,this.onFragBuffered,this)},r._unregisterListeners=function(){var e=this.hls;e.off(g.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(g.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(g.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(g.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.off(g.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.off(g.Events.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.off(g.Events.ERROR,this.onError,this),e.off(g.Events.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(g.Events.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.off(g.Events.BUFFER_CREATED,this.onBufferCreated,this),e.off(g.Events.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(g.Events.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(g.Events.FRAG_BUFFERED,this.onFragBuffered,this)},r.onHandlerDestroying=function(){this._unregisterListeners(),this.onMediaDetaching()},r.startLoad=function(e){if(this.levels){var t=this.lastCurrentTime,r=this.hls;if(this.stopLoad(),this.setInterval(100),this.level=-1,this.fragLoadError=0,!this.startFragRequested){var a=r.startLevel;-1===a&&(r.config.testBandwidth&&1<this.levels.length?(a=0,this.bitrateTest=!0):a=r.nextAutoLevel),this.level=r.nextLoadLevel=a,this.loadedmetadata=!1}0<t&&-1===e&&(this.log("Override startPosition with lastCurrentTime @"+t.toFixed(3)),e=t),this.state=u.State.IDLE,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}else this._forceStartLoad=!0,this.state=u.State.STOPPED},r.stopLoad=function(){this._forceStartLoad=!1,e.prototype.stopLoad.call(this)},r.doTick=function(){switch(this.state){case u.State.IDLE:this.doTickIdle();break;case u.State.WAITING_LEVEL:{var e=this.levels,t=this.level,r=null===e||void 0===e||null===(a=e[t])||void 0===a?void 0:a.details,a;if(r&&(!r.live||this.levelLastLoaded===this.level)){if(this.waitForCdnTuneIn(r))break;this.state=u.State.IDLE;break}break}case u.State.FRAG_LOADING_WAITING_RETRY:{var n=self.performance.now(),s=this.retryDate,i;(!s||n>=s||null!==(i=this.media)&&void 0!==i&&i.seeking)&&(this.log("retryDate reached, switch back to IDLE state"),this.resetStartWhenNotLoaded(this.level),this.state=u.State.IDLE)}break;default:}this.onTickEnd()},r.onTickEnd=function(){e.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},r.doTickIdle=function(){var e=this.hls,t=this.levelLastLoaded,r=this.levels,a=this.media,n=e.config,s=e.nextLoadLevel;if(null!==t&&(a||!this.startFragRequested&&n.startFragPrefetch)&&!(this.altAudio&&this.audioOnly)&&r&&r[s]){var i=r[s],o=this.getMainFwdBufferInfo();if(null!==o){var d=this.getLevelDetails();if(d&&this._streamEnded(o,d)){var l={};return this.altAudio&&(l.type="video"),this.hls.trigger(g.Events.BUFFER_EOS,l),void(this.state=u.State.ENDED)}this.level=e.nextLoadLevel=s;var c=i.details;if(!c||this.state===u.State.WAITING_LEVEL||c.live&&this.levelLastLoaded!==s)return this.level=s,void(this.state=u.State.WAITING_LEVEL);var f=o.len,E=this.getMaxBufferLength(i.maxBitrate);if(!(f>=E)){this.backtrackFragment&&this.backtrackFragment.start>o.end&&(this.backtrackFragment=null);var T=this.backtrackFragment?this.backtrackFragment.start:o.end,h=this.getNextFragment(T,c);if(this.couldBacktrack&&!this.fragPrevious&&h&&"initSegment"!==h.sn&&this.fragmentTracker.getState(h)!==m.FragmentState.OK){var S=(null==(D=this.backtrackFragment)?h:D).sn,v=S-c.startSN,L=c.fragments[v-1],D;L&&h.cc===L.cc&&(h=L,this.fragmentTracker.removeFragment(L))}else this.backtrackFragment&&o.len&&(this.backtrackFragment=null);if(h&&this.fragmentTracker.getState(h)===m.FragmentState.OK&&this.nextLoadPosition>T){var k=this.audioOnly&&!this.altAudio?y.ElementaryStreamTypes.AUDIO:y.ElementaryStreamTypes.VIDEO,I=(k===y.ElementaryStreamTypes.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;I&&this.afterBufferFlushed(I,k,p.PlaylistLevelType.MAIN),h=this.getNextFragment(this.nextLoadPosition,c)}h&&(h.initSegment&&!h.initSegment.data&&!this.bitrateTest&&(h=h.initSegment),this.loadFragment(h,c,T))}}}},r.loadFragment=function(t,r,a){var n=this.fragmentTracker.getState(t),s;this.fragCurrent=t,n===m.FragmentState.NOT_LOADED?"initSegment"===t.sn?this._loadInitSegment(t,r):this.bitrateTest?(this.log("Fragment "+t.sn+" of level "+t.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(t,r)):(this.startFragRequested=!0,e.prototype.loadFragment.call(this,t,r,a)):n===m.FragmentState.APPENDING?this.reduceMaxBufferLength(t.duration)&&this.fragmentTracker.removeFragment(t):0===(null===(s=this.media)||void 0===s?void 0:s.buffered.length)&&this.fragmentTracker.removeAllFragments()},r.getAppendedFrag=function(e){var t=this.fragmentTracker.getAppendedFrag(e,p.PlaylistLevelType.MAIN);return t&&"fragment"in t?t.fragment:t},r.getBufferedFrag=function(e){return this.fragmentTracker.getBufferedFrag(e,p.PlaylistLevelType.MAIN)},r.followingBufferedFrag=function(e){return e?this.getBufferedFrag(e.end+.5):null},r.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.nextLevelSwitch=function(){var e=this.levels,t=this.media;if(null!==t&&void 0!==t&&t.readyState){var r=this.getAppendedFrag(t.currentTime),a;if(r&&1<r.start&&this.flushMainBuffer(0,r.start-1),!t.paused&&e){var n=this.hls.nextLoadLevel,s=e[n],i=this.fragLastKbps;a=i&&this.fragCurrent?this.fragCurrent.duration*s.maxBitrate/(1e3*i)+1:0}else a=0;var o=this.getBufferedFrag(t.currentTime+a);if(o){var d=this.followingBufferedFrag(o);if(d){this.abortCurrentFrag();var l=d.maxStartPTS?d.maxStartPTS:d.start,u=d.duration,c=Math.max(o.end,l+Math.min(Math.max(u-this.config.maxFragLookUpTolerance,.5*u),.75*u));this.flushMainBuffer(c,Number.POSITIVE_INFINITY)}}}},r.abortCurrentFrag=function(){var e=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,e&&e.abortRequests(),this.state){case u.State.KEY_LOADING:case u.State.FRAG_LOADING:case u.State.FRAG_LOADING_WAITING_RETRY:case u.State.PARSING:case u.State.PARSED:this.state=u.State.IDLE;}this.nextLoadPosition=this.getLoadPosition()},r.flushMainBuffer=function(t,r){e.prototype.flushMainBuffer.call(this,t,r,this.altAudio?"video":null)},r.onMediaAttached=function(t,r){e.prototype.onMediaAttached.call(this,t,r);var a=r.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),a.addEventListener("playing",this.onvplaying),a.addEventListener("seeked",this.onvseeked),this.gapController=new h["default"](this.config,a,this.fragmentTracker,this.hls)},r.onMediaDetaching=function(){var t=this.media;t&&this.onvplaying&&this.onvseeked&&(t.removeEventListener("playing",this.onvplaying),t.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),e.prototype.onMediaDetaching.call(this)},r.onMediaPlaying=function(){this.tick()},r.onMediaSeeked=function(){var e=this.media,t=e?e.currentTime:null;(0,l.isFiniteNumber)(t)&&this.log("Media seeked to "+t.toFixed(3)),this.tick()},r.onManifestLoading=function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(g.Events.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=0,this.fragPlaying=null,this.backtrackFragment=null},r.onManifestParsed=function(e,t){var r=!1,a=!1,n;t.levels.forEach(function(e){n=e.audioCodec,n&&(-1!==n.indexOf("mp4a.40.2")&&(r=!0),-1!==n.indexOf("mp4a.40.5")&&(a=!0))}),this.audioCodecSwitch=r&&a&&!(0,c.changeTypeSupported)(),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=t.levels,this.startFragRequested=!1},r.onLevelLoading=function(e,t){var r=this.levels;if(r&&this.state===u.State.IDLE){var a=r[t.level];(!a.details||a.details.live&&this.levelLastLoaded!==t.level||this.waitForCdnTuneIn(a.details))&&(this.state=u.State.WAITING_LEVEL)}},r.onLevelLoaded=function(e,t){var r=this.levels,a=t.level,n=t.details,s=n.totalduration,i;if(!r)return void this.warn("Levels were reset while loading level "+a);this.log("Level "+a+" loaded ["+n.startSN+","+n.endSN+"], cc ["+n.startCC+", "+n.endCC+"] duration:"+s);var o=this.fragCurrent;o&&(this.state===u.State.FRAG_LOADING||this.state===u.State.FRAG_LOADING_WAITING_RETRY)&&o.level!==t.level&&o.loader&&(this.state=u.State.IDLE,this.backtrackFragment=null,o.abortRequests());var d=r[a],l=0;if(n.live||null!==(i=d.details)&&void 0!==i&&i.live){if(n.fragments[0]||(n.deltaUpdateFailed=!0),n.deltaUpdateFailed)return;l=this.alignPlaylists(n,d.details)}if(d.details=n,this.levelLastLoaded=a,this.hls.trigger(g.Events.LEVEL_UPDATED,{details:n,level:a}),this.state===u.State.WAITING_LEVEL){if(this.waitForCdnTuneIn(n))return;this.state=u.State.IDLE}this.startFragRequested?n.live&&this.synchronizeToLiveEdge(n):this.setStartPosition(n,l),this.tick()},r._handleFragmentLoadProgress=function(e){var t=e.frag,r=e.part,a=e.payload,n=this.levels,s;if(!n)return void this.warn("Levels were reset while fragment load was in progress. Fragment "+t.sn+" of level "+t.level+" will not be buffered");var i=n[t.level],o=i.details;if(!o)return void this.warn("Dropping fragment "+t.sn+" of level "+t.level+" after level details were reset");var d=i.videoCodec,l=o.PTSKnown||!o.live,u=null===(s=t.initSegment)||void 0===s?void 0:s.data,c=this._getAudioCodec(i),g=this.transmuxer=this.transmuxer||new E["default"](this.hls,p.PlaylistLevelType.MAIN,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),f=r?r.index:-1,m=new T.ChunkMetadata(t.level,t.sn,t.stats.chunkCount,a.byteLength,f,-1!==f),y=this.initPTS[t.cc];g.push(a,u,c,d,t,r,o.totalduration,l,m,y)},r.onAudioTrackSwitching=function(e,t){var r=this.altAudio,a=!!t.url,n=t.id;if(!a){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var s=this.fragCurrent;s&&(this.log("Switching to main audio track, cancel main fragment load"),s.abortRequests()),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var i=this.hls;r&&i.trigger(g.Events.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:"audio"}),i.trigger(g.Events.AUDIO_TRACK_SWITCHED,{id:n})}},r.onAudioTrackSwitched=function(e,t){var r=t.id,a=!!this.hls.audioTracks[r].url;if(a){var n=this.videoBuffer;n&&this.mediaBuffer!==n&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=n)}this.altAudio=a,this.tick()},r.onBufferCreated=function(e,t){var r=t.tracks,a=!1,n,s;for(var i in r){var o=r[i];if("main"!==o.id)a=!0;else if(s=i,n=o,"video"===i){var d=r[i];d&&(this.videoBuffer=d.buffer)}}a&&n?(this.log("Alternate track found, use "+s+".buffered to schedule main fragment loading"),this.mediaBuffer=n.buffer):this.mediaBuffer=this.media},r.onFragBuffered=function(e,t){var r=t.frag,a=t.part;if(!(r&&r.type!==p.PlaylistLevelType.MAIN)){if(this.fragContextChanged(r))return this.warn("Fragment "+r.sn+(a?" p: "+a.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state),void(this.state===u.State.PARSED&&(this.state=u.State.IDLE));var n=a?a.stats:r.stats;this.fragLastKbps=Math.round(8*n.total/(n.buffering.end-n.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,a)}},r.onError=function(e,t){if(t.type===S.ErrorTypes.KEY_SYSTEM_ERROR)return void this.onFragmentOrKeyLoadError(p.PlaylistLevelType.MAIN,t);switch(t.details){case S.ErrorDetails.FRAG_LOAD_ERROR:case S.ErrorDetails.FRAG_LOAD_TIMEOUT:case S.ErrorDetails.FRAG_PARSING_ERROR:case S.ErrorDetails.KEY_LOAD_ERROR:case S.ErrorDetails.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(p.PlaylistLevelType.MAIN,t);break;case S.ErrorDetails.LEVEL_LOAD_ERROR:case S.ErrorDetails.LEVEL_LOAD_TIMEOUT:this.state!==u.State.ERROR&&(t.fatal?(this.warn(""+t.details),this.state=u.State.ERROR):!t.levelRetry&&this.state===u.State.WAITING_LEVEL&&(this.state=u.State.IDLE));break;case S.ErrorDetails.BUFFER_FULL_ERROR:if("main"===t.parent&&(this.state===u.State.PARSING||this.state===u.State.PARSED)){var r=!0,a=this.getFwdBufferInfo(this.media,p.PlaylistLevelType.MAIN);a&&.5<a.len&&(r=!this.reduceMaxBufferLength(a.len)),r&&(this.warn("buffer full error also media.currentTime is not buffered, flush main"),this.immediateLevelSwitch()),this.resetLoadingState()}break;default:}},r.checkBuffer=function(){var e=this.media,t=this.gapController;if(e&&t&&e.readyState){if(this.loadedmetadata||!f.BufferHelper.getBuffered(e).length){var r=this.state===u.State.IDLE?null:this.fragCurrent;t.poll(this.lastCurrentTime,r)}this.lastCurrentTime=e.currentTime}},r.onFragLoadEmergencyAborted=function(){this.state=u.State.IDLE,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},r.onBufferFlushed=function(e,t){var r=t.type;if(r!==y.ElementaryStreamTypes.AUDIO||this.audioOnly&&!this.altAudio){var a=(r===y.ElementaryStreamTypes.VIDEO?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(a,r,p.PlaylistLevelType.MAIN)}},r.onLevelsUpdated=function(e,t){this.levels=t.levels},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r.seekToStartPos=function(){var e=this.media;if(e){var t=e.currentTime,r=this.startPosition;if(0<=r&&t<r){if(e.seeking)return void this.log("could not seek to "+r+", already seeking at "+t);var a=f.BufferHelper.getBuffered(e),n=a.length?a.start(0):0,s=n-r;0<s&&(s<this.config.maxBufferHole||s<this.config.maxFragLookUpTolerance)&&(this.log("adjusting start position by "+s+" to match buffer start"),r+=s,this.startPosition=r),this.log("seek to target start position "+r+" from current time "+t),e.currentTime=r}}},r._getAudioCodec=function(e){var t=this.config.defaultAudioCodec||e.audioCodec;return this.audioCodecSwap&&t&&(this.log("Swapping audio codec"),t=-1===t.indexOf("mp4a.40.5")?"mp4a.40.5":"mp4a.40.2"),t},r._loadBitrateTestFrag=function(e,t){var r=this;e.bitrateTest=!0,this._doFragLoad(e,t).then(function(t){var a=r.hls;if(t&&!r.fragContextChanged(e)){r.fragLoadError=0,r.state=u.State.IDLE,r.startFragRequested=!1,r.bitrateTest=!1;var n=e.stats;n.parsing.start=n.parsing.end=n.buffering.start=n.buffering.end=self.performance.now(),a.trigger(g.Events.FRAG_LOADED,t),e.bitrateTest=!1}})},r._handleTransmuxComplete=function(e){var t=this.hls,r=e.remuxResult,a=e.chunkMeta,n=this.getCurrentContext(a),s;if(!n)return this.warn("The loading context changed while buffering fragment "+a.sn+" of level "+a.level+". This chunk will not be buffered."),void this.resetStartWhenNotLoaded(a.level);var i=n.frag,o=n.part,d=n.level,c=r.video,f=r.text,m=r.id3,p=r.initSegment,E=d.details,T=this.altAudio?void 0:r.audio;if(!this.fragContextChanged(i)){if(this.state=u.State.PARSING,p){p.tracks&&(this._bufferInitSegment(d,p.tracks,i,a),t.trigger(g.Events.FRAG_PARSING_INIT_SEGMENT,{frag:i,id:"main",tracks:p.tracks}));var h=p.initPTS,S=p.timescale;(0,l.isFiniteNumber)(h)&&(this.initPTS[i.cc]=h,t.trigger(g.Events.INIT_PTS_FOUND,{frag:i,id:"main",initPTS:h,timescale:S}))}if(c&&!1!==r.independent){if(E){var v=c.startPTS,L=c.endPTS,D=c.startDTS,k=c.endDTS;if(o)o.elementaryStreams[c.type]={startPTS:v,endPTS:L,startDTS:D,endDTS:k};else if(c.firstKeyFrame&&c.independent&&1===a.id&&(this.couldBacktrack=!0),c.dropped&&c.independent){var I=this.getMainFwdBufferInfo(),A=(I?I.end:this.getLoadPosition())+this.config.maxBufferHole,R=c.firstKeyFramePTS?c.firstKeyFramePTS:v;if(A<R-this.config.maxBufferHole)return void this.backtrack(i);i.setElementaryStreamInfo(c.type,i.start,L,i.start,k,!0)}i.setElementaryStreamInfo(c.type,v,L,D,k),this.backtrackFragment&&(this.backtrackFragment=i),this.bufferFragmentData(c,i,o,a)}}else if(!1===r.independent)return void this.backtrack(i);if(T){var b=T.startPTS,C=T.endPTS,_=T.startDTS,x=T.endDTS;o&&(o.elementaryStreams[y.ElementaryStreamTypes.AUDIO]={startPTS:b,endPTS:C,startDTS:_,endDTS:x}),i.setElementaryStreamInfo(y.ElementaryStreamTypes.AUDIO,b,C,_,x),this.bufferFragmentData(T,i,o,a)}if(E&&null!==m&&void 0!==m&&null!==(s=m.samples)&&void 0!==s&&s.length){var P={id:"main",frag:i,details:E,samples:m.samples};t.trigger(g.Events.FRAG_PARSING_METADATA,P)}if(E&&f){var F={id:"main",frag:i,details:E,samples:f.samples};t.trigger(g.Events.FRAG_PARSING_USERDATA,F)}}},r._bufferInitSegment=function(e,t,r,a){var n=this;if(this.state===u.State.PARSING){this.audioOnly=!!t.audio&&!t.video,this.altAudio&&!this.audioOnly&&delete t.audio;var s=t.audio,i=t.video,o=t.audiovideo;if(s){var d=e.audioCodec,l=navigator.userAgent.toLowerCase();this.audioCodecSwitch&&(d&&(-1===d.indexOf("mp4a.40.5")?d="mp4a.40.5":d="mp4a.40.2"),1!==s.metadata.channelCount&&-1===l.indexOf("firefox")&&(d="mp4a.40.5")),-1!==l.indexOf("android")&&"audio/mpeg"!==s.container&&(d="mp4a.40.2",this.log("Android: force audio codec to "+d)),e.audioCodec&&e.audioCodec!==d&&this.log("Swapping manifest audio codec \""+e.audioCodec+"\" for \""+d+"\""),s.levelCodec=d,s.id="main",this.log("Init audio buffer, container:"+s.container+", codecs[selected/level/parsed]=["+(d||"")+"/"+(e.audioCodec||"")+"/"+s.codec+"]")}i&&(i.levelCodec=e.videoCodec,i.id="main",this.log("Init video buffer, container:"+i.container+", codecs[level/parsed]=["+(e.videoCodec||"")+"/"+i.codec+"]")),o&&this.log("Init audiovideo buffer, container:"+o.container+", codecs[level/parsed]=["+(e.attrs.CODECS||"")+"/"+o.codec+"]"),this.hls.trigger(g.Events.BUFFER_CODECS,t),Object.keys(t).forEach(function(e){var s=t[e],i=s.initSegment;null!==i&&void 0!==i&&i.byteLength&&n.hls.trigger(g.Events.BUFFER_APPENDING,{type:e,data:i,frag:r,part:null,chunkMeta:a,parent:r.type})}),this.tick()}},r.getMainFwdBufferInfo=function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,p.PlaylistLevelType.MAIN)},r.backtrack=function(e){this.couldBacktrack=!0,this.backtrackFragment=e,this.resetTransmuxer(),this.flushBufferGap(e),this.fragmentTracker.removeFragment(e),this.fragPrevious=null,this.nextLoadPosition=e.start,this.state=u.State.IDLE},r.checkFragmentChanged=function(){var e=this.media,t=null;if(e&&1<e.readyState&&!1===e.seeking){var r=e.currentTime;if(f.BufferHelper.isBuffered(e,r)?t=this.getAppendedFrag(r):f.BufferHelper.isBuffered(e,r+.1)&&(t=this.getAppendedFrag(r+.1)),t){this.backtrackFragment=null;var a=this.fragPlaying,n=t.level;a&&t.sn===a.sn&&a.level===n&&t.urlId===a.urlId||(this.fragPlaying=t,this.hls.trigger(g.Events.FRAG_CHANGED,{frag:t}),(!a||a.level!==n)&&this.hls.trigger(g.Events.LEVEL_SWITCHED,{level:n}))}}},n(t,[{key:"nextLevel",get:function(){var e=this.nextBufferedFrag;return e?e.level:-1}},{key:"currentFrag",get:function(){var e=this.media;return e?this.fragPlaying||this.getAppendedFrag(e.currentTime):null}},{key:"currentProgramDateTime",get:function(){var e=this.media;if(e){var t=e.currentTime,r=this.currentFrag;if(r&&(0,l.isFiniteNumber)(t)&&(0,l.isFiniteNumber)(r.programDateTime)){var a=r.programDateTime+1e3*(t-r.start);return new Date(a)}}return null}},{key:"currentLevel",get:function(){var e=this.currentFrag;return e?e.level:-1}},{key:"nextBufferedFrag",get:function(){var e=this.currentFrag;return e?this.followingBufferedFrag(e):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}]),t}(u["default"])},"./src/controller/subtitle-stream-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}r.r(t),r.d(t,{SubtitleStreamController:()=>T});var l=r("./src/events.ts"),u=r("./src/utils/buffer-helper.ts"),c=r("./src/controller/fragment-finders.ts"),g=r("./src/utils/discontinuities.ts"),f=r("./src/controller/level-helper.ts"),m=r("./src/controller/fragment-tracker.ts"),p=r("./src/controller/base-stream-controller.ts"),y=r("./src/types/loader.ts"),E=r("./src/types/level.ts"),T=function(e){function t(t,r,a){var n;return n=e.call(this,t,r,a,"[subtitle-stream-controller]")||this,n.levels=[],n.currentTrackId=-1,n.tracksBuffered=[],n.mainDetails=null,n._registerListeners(),n}o(t,e);var r=t.prototype;return r.onHandlerDestroying=function(){this._unregisterListeners(),this.mainDetails=null},r._registerListeners=function(){var e=this.hls;e.on(l.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(l.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(l.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(l.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.on(l.Events.ERROR,this.onError,this),e.on(l.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.on(l.Events.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),e.on(l.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.on(l.Events.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),e.on(l.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(l.Events.FRAG_BUFFERED,this.onFragBuffered,this)},r._unregisterListeners=function(){var e=this.hls;e.off(l.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(l.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(l.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(l.Events.LEVEL_LOADED,this.onLevelLoaded,this),e.off(l.Events.ERROR,this.onError,this),e.off(l.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.off(l.Events.SUBTITLE_TRACK_SWITCH,this.onSubtitleTrackSwitch,this),e.off(l.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.off(l.Events.SUBTITLE_FRAG_PROCESSED,this.onSubtitleFragProcessed,this),e.off(l.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(l.Events.FRAG_BUFFERED,this.onFragBuffered,this)},r.startLoad=function(e){this.stopLoad(),this.state=p.State.IDLE,this.setInterval(500),this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()},r.onManifestLoading=function(){this.mainDetails=null,this.fragmentTracker.removeAllFragments()},r.onLevelLoaded=function(e,t){this.mainDetails=t.details},r.onSubtitleFragProcessed=function(e,t){var r=t.frag,a=t.success;if(this.fragPrevious=r,this.state=p.State.IDLE,!!a){var n=this.tracksBuffered[this.currentTrackId];if(n){for(var s=r.start,o=0,d;o<n.length;o++)if(s>=n[o].start&&s<=n[o].end){d=n[o];break}var l=r.start+r.duration;d?d.end=l:(d={start:s,end:l},n.push(d)),this.fragmentTracker.fragBuffered(r)}}},r.onBufferFlushing=function(e,t){var r=t.startOffset,a=t.endOffset;if(0===r&&a!==Number.POSITIVE_INFINITY){var n=this.currentTrackId,s=this.levels;if(!s.length||!s[n]||!s[n].details)return;var i=s[n].details,o=i.targetduration,d=a-o;if(0>=d)return;t.endOffsetSubtitles=Math.max(0,d),this.tracksBuffered.forEach(function(e){for(var t=0;t<e.length;){if(e[t].end<=d){e.shift();continue}else if(e[t].start<d)e[t].start=d;else break;t++}}),this.fragmentTracker.removeFragmentsInRange(r,d,y.PlaylistLevelType.SUBTITLE)}},r.onFragBuffered=function(e,t){if(!this.loadedmetadata&&t.frag.type===y.PlaylistLevelType.MAIN){var r;null!==(r=this.media)&&void 0!==r&&r.buffered.length&&(this.loadedmetadata=!0)}},r.onError=function(e,t){var r=t.frag;r&&r.type===y.PlaylistLevelType.SUBTITLE&&(this.fragCurrent&&this.fragCurrent.abortRequests(),this.state=p.State.IDLE)},r.onSubtitleTracksUpdated=function(e,t){var r=this,a=t.subtitleTracks;this.tracksBuffered=[],this.levels=a.map(function(e){return new E.Level(e)}),this.fragmentTracker.removeAllFragments(),this.fragPrevious=null,this.levels.forEach(function(e){r.tracksBuffered[e.id]=[]}),this.mediaBuffer=null},r.onSubtitleTrackSwitch=function(e,t){if(this.currentTrackId=t.id,!this.levels.length||-1===this.currentTrackId)return void this.clearInterval();var r=this.levels[this.currentTrackId];this.mediaBuffer=null!==r&&void 0!==r&&r.details?this.mediaBufferTimeRanges:null,r&&this.setInterval(500)},r.onSubtitleTrackLoaded=function(e,t){var r=t.details,a=t.id,n=this.currentTrackId,s=this.levels,i;if(s.length){var o=s[n];if(!(a>=s.length)&&a===n&&o){this.mediaBuffer=this.mediaBufferTimeRanges;var d=0;if(r.live||null!==(i=o.details)&&void 0!==i&&i.live){var l=this.mainDetails;if(r.deltaUpdateFailed||!l)return;var u=l.fragments[0];o.details?(d=this.alignPlaylists(r,o.details),0===d&&u&&(d=u.start,(0,f.addSliding)(r,d))):r.hasProgramDateTime&&l.hasProgramDateTime?((0,g.alignMediaPlaylistByPDT)(r,l),d=r.fragments[0].start):u&&(d=u.start,(0,f.addSliding)(r,d))}if(o.details=r,this.levelLastLoaded=a,this.startFragRequested||!this.mainDetails&&r.live||this.setStartPosition(o.details,d),this.tick(),r.live&&!this.fragCurrent&&this.media&&this.state===p.State.IDLE){var m=(0,c.findFragmentByPTS)(null,r.fragments,this.media.currentTime,0);m||(this.warn("Subtitle playlist not aligned with playback"),o.details=void 0)}}}},r._handleFragmentLoadComplete=function(e){var t=this,r=e.frag,a=e.payload,n=r.decryptdata,s=this.hls;if(!this.fragContextChanged(r)&&a&&0<a.byteLength&&n&&n.key&&n.iv&&"AES-128"===n.method){var i=performance.now();this.decrypter.decrypt(new Uint8Array(a),n.key.buffer,n.iv.buffer).then(function(e){var t=performance.now();s.trigger(l.Events.FRAG_DECRYPTED,{frag:r,payload:e,stats:{tstart:i,tdecrypt:t}})}).catch(function(e){t.warn(e.name+": "+e.message),t.state=p.State.IDLE})}},r.doTick=function(){if(!this.media)return void(this.state=p.State.IDLE);if(this.state===p.State.IDLE){var e=this.currentTrackId,t=this.levels;if(!t.length||!t[e]||!t[e].details)return;var r=t[e].details,a=r.targetduration,n=this.config,s=this.getLoadPosition(),i=u.BufferHelper.bufferedInfo(this.tracksBuffered[this.currentTrackId]||[],s-a,n.maxBufferHole),o=i.end,d=i.len,l=this.getFwdBufferInfo(this.media,y.PlaylistLevelType.MAIN),g=this.getMaxBufferLength(null===l||void 0===l?void 0:l.len)+a;if(d>g)return;console.assert(r,"Subtitle track details are defined on idle subtitle stream controller tick");var f=r.fragments,E=f.length,T=r.edge,h=null,S=this.fragPrevious;if(o<T){var v=n.maxFragLookUpTolerance;h=(0,c.findFragmentByPTS)(S,f,Math.max(f[0].start,o),v),!h&&S&&S.start<f[0].start&&(h=f[0])}else h=f[E-1];if(!h)return;h=this.mapToInitFragWhenRequired(h),this.fragmentTracker.getState(h)===m.FragmentState.NOT_LOADED&&this.loadFragment(h,r,o)}},r.getMaxBufferLength=function(t){var r=e.prototype.getMaxBufferLength.call(this);return t?Math.max(r,t):r},r.loadFragment=function(t,r,a){this.fragCurrent=t,"initSegment"===t.sn?this._loadInitSegment(t,r):(this.startFragRequested=!0,e.prototype.loadFragment.call(this,t,r,a))},n(t,[{key:"mediaBufferTimeRanges",get:function(){return new h(this.tracksBuffered[this.currentTrackId]||[])}}]),t}(p["default"]),h=function(e){this.buffered=void 0;var t=function(t,r,a){if(r>>>=0,r>a-1)throw new DOMException("Failed to execute '"+t+"' on 'TimeRanges': The index provided ("+r+") is greater than the maximum bound ("+a+")");return e[r][t]};this.buffered={get length(){return e.length},end:function(r){return t("end",r,e.length)},start:function(r){return t("start",r,e.length)}}}},"./src/controller/subtitle-track-controller.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function l(e){for(var t=[],r=0,a;r<e.length;r++)a=e[r],"subtitles"===a.kind&&a.label&&t.push(e[r]);return t}r.r(t),r.d(t,{default:()=>p});var u=r("./src/events.ts"),c=r("./src/utils/texttrack-utils.ts"),g=r("./src/controller/base-playlist-controller.ts"),f=r("./src/types/loader.ts"),m=function(e){function t(t){var r;return r=e.call(this,t,"[subtitle-track-controller]")||this,r.media=null,r.tracks=[],r.groupId=null,r.tracksInGroup=[],r.trackId=-1,r.selectDefaultTrack=!0,r.queuedDefaultTrack=-1,r.trackChangeListener=function(){return r.onTextTracksChanged()},r.asyncPollTrackChange=function(){return r.pollTrackChange(0)},r.useTextTrackPolling=!1,r.subtitlePollingInterval=-1,r._subtitleDisplay=!0,r.registerListeners(),r}o(t,e);var r=t.prototype;return r.destroy=function(){this.unregisterListeners(),this.tracks.length=0,this.tracksInGroup.length=0,this.trackChangeListener=this.asyncPollTrackChange=null,e.prototype.destroy.call(this)},r.registerListeners=function(){var e=this.hls;e.on(u.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(u.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(u.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(u.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.on(u.Events.LEVEL_LOADING,this.onLevelLoading,this),e.on(u.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(u.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.on(u.Events.ERROR,this.onError,this)},r.unregisterListeners=function(){var e=this.hls;e.off(u.Events.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(u.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(u.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(u.Events.MANIFEST_PARSED,this.onManifestParsed,this),e.off(u.Events.LEVEL_LOADING,this.onLevelLoading,this),e.off(u.Events.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(u.Events.SUBTITLE_TRACK_LOADED,this.onSubtitleTrackLoaded,this),e.off(u.Events.ERROR,this.onError,this)},r.onMediaAttached=function(e,t){this.media=t.media,this.media&&(-1<this.queuedDefaultTrack&&(this.subtitleTrack=this.queuedDefaultTrack,this.queuedDefaultTrack=-1),this.useTextTrackPolling=!(this.media.textTracks&&"onchange"in this.media.textTracks),this.useTextTrackPolling?this.pollTrackChange(500):this.media.textTracks.addEventListener("change",this.asyncPollTrackChange))},r.pollTrackChange=function(e){self.clearInterval(this.subtitlePollingInterval),this.subtitlePollingInterval=self.setInterval(this.trackChangeListener,e)},r.onMediaDetaching=function(){if(this.media){self.clearInterval(this.subtitlePollingInterval),this.useTextTrackPolling||this.media.textTracks.removeEventListener("change",this.asyncPollTrackChange),-1<this.trackId&&(this.queuedDefaultTrack=this.trackId);var e=l(this.media.textTracks);e.forEach(function(e){(0,c.clearCurrentCues)(e)}),this.subtitleTrack=-1,this.media=null}},r.onManifestLoading=function(){this.tracks=[],this.groupId=null,this.tracksInGroup=[],this.trackId=-1,this.selectDefaultTrack=!0},r.onManifestParsed=function(e,t){this.tracks=t.subtitleTracks},r.onSubtitleTrackLoaded=function(e,t){var r=t.id,a=t.details,n=this.trackId,s=this.tracksInGroup[n];if(!s)return void this.warn("Invalid subtitle track id "+r);var i=s.details;s.details=t.details,this.log("subtitle track "+r+" loaded ["+a.startSN+"-"+a.endSN+"]"),r===this.trackId&&(this.retryCount=0,this.playlistLoaded(r,t,i))},r.onLevelLoading=function(e,t){this.switchLevel(t.level)},r.onLevelSwitching=function(e,t){this.switchLevel(t.level)},r.switchLevel=function(e){var t=this.hls.levels[e];if(null!==t&&void 0!==t&&t.textGroupIds){var r=t.textGroupIds[t.urlId];if(this.groupId!==r){var a=this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0,n=this.tracks.filter(function(e){return!r||e.groupId===r});this.tracksInGroup=n;var s=this.findTrackId(null===a||void 0===a?void 0:a.name)||this.findTrackId();this.groupId=r;this.log("Updating subtitle tracks, "+n.length+" track(s) found in \""+r+"\" group-id"),this.hls.trigger(u.Events.SUBTITLE_TRACKS_UPDATED,{subtitleTracks:n}),-1!==s&&this.setSubtitleTrack(s,a)}}},r.findTrackId=function(e){for(var t=this.tracksInGroup,r=0,a;r<t.length;r++)if(a=t[r],(!this.selectDefaultTrack||a.default)&&(!e||e===a.name))return a.id;return-1},r.onError=function(t,r){e.prototype.onError.call(this,t,r),r.fatal||!r.context||r.context.type===f.PlaylistContextType.SUBTITLE_TRACK&&r.context.id===this.trackId&&r.context.groupId===this.groupId&&this.retryLoadingOrFail(r)},r.loadPlaylist=function(t){e.prototype.loadPlaylist.call(this);var r=this.tracksInGroup[this.trackId];if(this.shouldLoadTrack(r)){var a=r.id,n=r.groupId,s=r.url;if(t)try{s=t.addDirectives(s)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: "+e)}this.log("Loading subtitle playlist for id "+a),this.hls.trigger(u.Events.SUBTITLE_TRACK_LOADING,{url:s,id:a,groupId:n,deliveryDirectives:t||null})}},r.toggleTrackModes=function(e){var t=this,r=this.media,a=this.trackId;if(r){var n=l(r.textTracks),s=n.filter(function(e){return e.groupId===t.groupId});if(-1===e)[].slice.call(n).forEach(function(e){e.mode="disabled"});else{var i=s[a];i&&(i.mode="disabled")}var o=s[e];o&&(o.mode=this.subtitleDisplay?"showing":"hidden")}},r.setSubtitleTrack=function(e,t){var r=this.tracksInGroup,a;if(!this.media)return void(this.queuedDefaultTrack=e);if(this.trackId!==e&&this.toggleTrackModes(e),!(this.trackId===e&&(-1===e||null!==(a=r[e])&&void 0!==a&&a.details)||-1>e||e>=r.length)){this.clearTimer();var n=r[e];if(this.log("Switching to subtitle track "+e),this.trackId=e,n){var s=n.id,i=n.groupId,o=void 0===i?"":i,d=n.name,l=n.type,c=n.url;this.hls.trigger(u.Events.SUBTITLE_TRACK_SWITCH,{id:s,groupId:o,name:d,type:l,url:c});var g=this.switchParams(n.url,null===t||void 0===t?void 0:t.details);this.loadPlaylist(g)}else this.hls.trigger(u.Events.SUBTITLE_TRACK_SWITCH,{id:e})}},r.onTextTracksChanged=function(){if(this.useTextTrackPolling||self.clearInterval(this.subtitlePollingInterval),this.media&&this.hls.config.renderTextTracksNatively){for(var e=-1,t=l(this.media.textTracks),r=0;r<t.length;r++)if("hidden"===t[r].mode)e=r;else if("showing"===t[r].mode){e=r;break}this.subtitleTrack!==e&&(this.subtitleTrack=e)}},n(t,[{key:"subtitleDisplay",get:function(){return this._subtitleDisplay},set:function(e){this._subtitleDisplay=e,-1<this.trackId&&this.toggleTrackModes(this.trackId)}},{key:"subtitleTracks",get:function(){return this.tracksInGroup}},{key:"subtitleTrack",get:function(){return this.trackId},set:function(e){this.selectDefaultTrack=!1;var t=this.tracksInGroup?this.tracksInGroup[this.trackId]:void 0;this.setSubtitleTrack(e,t)}}]),t}(g["default"]);const p=m},"./src/controller/timeline-controller.ts":(e,t,r)=>{"use strict";function a(e,t){return e&&e.label===t.name&&!(e.textTrack1||e.textTrack2)}function n(e,t,r,a){return Math.min(t,a)-Math.max(e,r)}function s(){return{ccOffset:0,presentationOffset:0,0:{start:0,prevCC:-1,new:!0}}}r.r(t),r.d(t,{TimelineController:()=>y});var i=r("./src/polyfills/number.ts"),o=r("./src/events.ts"),d=r("./src/utils/cea-608-parser.ts"),l=r("./src/utils/output-filter.ts"),u=r("./src/utils/webvtt-parser.ts"),c=r("./src/utils/texttrack-utils.ts"),g=r("./src/utils/imsc1-ttml-parser.ts"),f=r("./src/utils/mp4-tools.ts"),m=r("./src/types/loader.ts"),p=r("./src/utils/logger.ts"),y=function(){function e(e){if(this.hls=void 0,this.media=null,this.config=void 0,this.enabled=!0,this.Cues=void 0,this.textTracks=[],this.tracks=[],this.initPTS=[],this.timescale=[],this.unparsedVttFrags=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.cea608Parser1=void 0,this.cea608Parser2=void 0,this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs=s(),this.captionsProperties=void 0,this.hls=e,this.config=e.config,this.Cues=e.config.cueHandler,this.captionsProperties={textTrack1:{label:this.config.captionsTextTrack1Label,languageCode:this.config.captionsTextTrack1LanguageCode},textTrack2:{label:this.config.captionsTextTrack2Label,languageCode:this.config.captionsTextTrack2LanguageCode},textTrack3:{label:this.config.captionsTextTrack3Label,languageCode:this.config.captionsTextTrack3LanguageCode},textTrack4:{label:this.config.captionsTextTrack4Label,languageCode:this.config.captionsTextTrack4LanguageCode}},this.config.enableCEA708Captions){var t=new l["default"](this,"textTrack1"),r=new l["default"](this,"textTrack2"),a=new l["default"](this,"textTrack3"),n=new l["default"](this,"textTrack4");this.cea608Parser1=new d["default"](1,t,r),this.cea608Parser2=new d["default"](3,a,n)}e.on(o.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(o.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(o.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(o.Events.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(o.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.on(o.Events.FRAG_LOADING,this.onFragLoading,this),e.on(o.Events.FRAG_LOADED,this.onFragLoaded,this),e.on(o.Events.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),e.on(o.Events.FRAG_DECRYPTED,this.onFragDecrypted,this),e.on(o.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),e.on(o.Events.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),e.on(o.Events.BUFFER_FLUSHING,this.onBufferFlushing,this)}var t=e.prototype;return t.destroy=function(){var e=this.hls;e.off(o.Events.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(o.Events.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(o.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(o.Events.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(o.Events.SUBTITLE_TRACKS_UPDATED,this.onSubtitleTracksUpdated,this),e.off(o.Events.FRAG_LOADING,this.onFragLoading,this),e.off(o.Events.FRAG_LOADED,this.onFragLoaded,this),e.off(o.Events.FRAG_PARSING_USERDATA,this.onFragParsingUserdata,this),e.off(o.Events.FRAG_DECRYPTED,this.onFragDecrypted,this),e.off(o.Events.INIT_PTS_FOUND,this.onInitPtsFound,this),e.off(o.Events.SUBTITLE_TRACKS_CLEARED,this.onSubtitleTracksCleared,this),e.off(o.Events.BUFFER_FLUSHING,this.onBufferFlushing,this),this.hls=this.config=this.cea608Parser1=this.cea608Parser2=null},t.addCues=function(e,t,r,a,s){for(var d=!1,l=s.length;l--;){var u=s[l],c=n(u[0],u[1],t,r);if(0<=c&&(u[0]=Math.min(u[0],t),u[1]=Math.max(u[1],r),d=!0,.5<c/(r-t)))return}if(d||s.push([t,r]),this.config.renderTextTracksNatively){var g=this.captionsTracks[e];this.Cues.newCue(g,t,r,a)}else{var f=this.Cues.newCue(null,t,r,a);this.hls.trigger(o.Events.CUES_PARSED,{type:"captions",cues:f,track:e})}},t.onInitPtsFound=function(e,t){var r=this,a=t.frag,n=t.id,s=t.initPTS,i=t.timescale,d=this.unparsedVttFrags;"main"===n&&(this.initPTS[a.cc]=s,this.timescale[a.cc]=i),d.length&&(this.unparsedVttFrags=[],d.forEach(function(e){r.onFragLoaded(o.Events.FRAG_LOADED,e)}))},t.getExistingTrack=function(e){var t=this.media;if(t)for(var r=0,a;r<t.textTracks.length;r++)if(a=t.textTracks[r],a[e])return a;return null},t.createCaptionsTrack=function(e){this.config.renderTextTracksNatively?this.createNativeTrack(e):this.createNonNativeTrack(e)},t.createNativeTrack=function(e){if(!this.captionsTracks[e]){var t=this.captionsProperties,r=this.captionsTracks,a=this.media,n=t[e],s=n.label,i=n.languageCode,o=this.getExistingTrack(e);if(!o){var d=this.createTextTrack("captions",s,i);d&&(d[e]=!0,r[e]=d)}else r[e]=o,(0,c.clearCurrentCues)(r[e]),(0,c.sendAddTrackEvent)(r[e],a)}},t.createNonNativeTrack=function(e){if(!this.nonNativeCaptionsTracks[e]){var t=this.captionsProperties[e];if(t){var r=t.label,a={_id:e,label:r,kind:"captions",default:!!t.media&&!!t.media.default,closedCaptions:t.media};this.nonNativeCaptionsTracks[e]=a,this.hls.trigger(o.Events.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:[a]})}}},t.createTextTrack=function(e,t,r){var a=this.media;return a?a.addTextTrack(e,t,r):void 0},t.onMediaAttaching=function(e,t){this.media=t.media,this._cleanTracks()},t.onMediaDetaching=function(){var e=this.captionsTracks;Object.keys(e).forEach(function(t){(0,c.clearCurrentCues)(e[t]),delete e[t]}),this.nonNativeCaptionsTracks={}},t.onManifestLoading=function(){this.lastSn=-1,this.lastPartIndex=-1,this.prevCC=-1,this.vttCCs=s(),this._cleanTracks(),this.tracks=[],this.captionsTracks={},this.nonNativeCaptionsTracks={},this.textTracks=[],this.unparsedVttFrags=this.unparsedVttFrags||[],this.initPTS=[],this.timescale=[],this.cea608Parser1&&this.cea608Parser2&&(this.cea608Parser1.reset(),this.cea608Parser2.reset())},t._cleanTracks=function(){var e=this.media;if(e){var t=e.textTracks;if(t)for(var r=0;r<t.length;r++)(0,c.clearCurrentCues)(t[r])}},t.onSubtitleTracksUpdated=function(e,t){var r=this;this.textTracks=[];var n=t.subtitleTracks||[],s=n.some(function(e){return e.textCodec===g.IMSC1_CODEC});if(this.config.enableWebVTT||s&&this.config.enableIMSC1){var i=this.tracks&&n&&this.tracks.length===n.length;if(this.tracks=n||[],this.config.renderTextTracksNatively){var d=this.media?this.media.textTracks:[];this.tracks.forEach(function(e,t){var n;if(t<d.length){for(var s=null,o=0;o<d.length;o++)if(a(d[o],e)){s=d[o];break}s&&(n=s)}if(n)(0,c.clearCurrentCues)(n);else{var l=r._captionsOrSubtitlesFromCharacteristics(e);n=r.createTextTrack(l,e.name,e.lang),n&&(n.mode="disabled")}n&&(n.groupId=e.groupId,r.textTracks.push(n))})}else if(!i&&this.tracks&&this.tracks.length){var l=this.tracks.map(function(e){return{label:e.name,kind:e.type.toLowerCase(),default:e.default,subtitleTrack:e}});this.hls.trigger(o.Events.NON_NATIVE_TEXT_TRACKS_FOUND,{tracks:l})}}},t._captionsOrSubtitlesFromCharacteristics=function(e){var t;if(null!==(t=e.attrs)&&void 0!==t&&t.CHARACTERISTICS){var r=/transcribes-spoken-dialog/gi.test(e.attrs.CHARACTERISTICS),a=/describes-music-and-sound/gi.test(e.attrs.CHARACTERISTICS);if(r&&a)return"captions"}return"subtitles"},t.onManifestLoaded=function(e,t){var r=this;this.config.enableCEA708Captions&&t.captions&&t.captions.forEach(function(e){var t=/(?:CC|SERVICE)([1-4])/.exec(e.instreamId);if(t){var a="textTrack"+t[1],n=r.captionsProperties[a];n&&(n.label=e.name,e.lang&&(n.languageCode=e.lang),n.media=e)}})},t.closedCaptionsForLevel=function(e){var t=this.hls.levels[e.level];return null===t||void 0===t?void 0:t.attrs["CLOSED-CAPTIONS"]},t.onFragLoading=function(e,t){var r=this.cea608Parser1,a=this.cea608Parser2,n=this.lastSn,s=this.lastPartIndex;if(this.enabled&&r&&a&&t.frag.type===m.PlaylistLevelType.MAIN){var i=t.frag.sn,o=null==(d=null===t||void 0===t||null===(l=t.part)||void 0===l?void 0:l.index)?-1:d,d,l;i===n+1||i===n&&o===s+1||(r.reset(),a.reset()),this.lastSn=i,this.lastPartIndex=o}},t.onFragLoaded=function(e,t){var r=t.frag,a=t.payload,n=this.initPTS,s=this.unparsedVttFrags;if(r.type===m.PlaylistLevelType.SUBTITLE)if(a.byteLength){if(!(0,i.isFiniteNumber)(n[r.cc]))return s.push(t),void(n.length&&this.hls.trigger(o.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Missing initial subtitle PTS")}));var d=r.decryptdata,l=("stats"in t);if(null==d||!d.encrypted||l){var u=this.tracks[r.level],c=this.vttCCs;c[r.cc]||(c[r.cc]={start:r.start,prevCC:this.prevCC,new:!0},this.prevCC=r.cc),u&&u.textCodec===g.IMSC1_CODEC?this._parseIMSC1(r,a):this._parseVTTs(r,a,c)}}else this.hls.trigger(o.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:r,error:new Error("Empty subtitle payload")})},t._parseIMSC1=function(e,t){var r=this,a=this.hls;(0,g.parseIMSC1)(t,this.initPTS[e.cc],this.timescale[e.cc],function(t){r._appendCues(t,e.level),a.trigger(o.Events.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:e})},function(t){p.logger.log("Failed to parse IMSC1: "+t),a.trigger(o.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:e,error:t})})},t._parseVTTs=function(e,t,r){var a=this,n=this.hls,s=null!==(i=e.initSegment)&&void 0!==i&&i.data?(0,f.appendUint8Array)(e.initSegment.data,new Uint8Array(t)):t,i;(0,u.parseWebVTT)(s,this.initPTS[e.cc],this.timescale[e.cc],r,e.cc,e.start,function(t){a._appendCues(t,e.level),n.trigger(o.Events.SUBTITLE_FRAG_PROCESSED,{success:!0,frag:e})},function(r){a._fallbackToIMSC1(e,t),p.logger.log("Failed to parse VTT cue: "+r),n.trigger(o.Events.SUBTITLE_FRAG_PROCESSED,{success:!1,frag:e,error:r})})},t._fallbackToIMSC1=function(e,t){var r=this,a=this.tracks[e.level];a.textCodec||(0,g.parseIMSC1)(t,this.initPTS[e.cc],this.timescale[e.cc],function(){a.textCodec=g.IMSC1_CODEC,r._parseIMSC1(e,t)},function(){a.textCodec="wvtt"})},t._appendCues=function(e,t){var r=this.hls;if(this.config.renderTextTracksNatively){var a=this.textTracks[t];if(!a||"disabled"===a.mode)return;e.forEach(function(e){return(0,c.addCueToTrack)(a,e)})}else{var n=this.tracks[t];if(!n)return;var s=n.default?"default":"subtitles"+t;r.trigger(o.Events.CUES_PARSED,{type:"subtitles",cues:e,track:s})}},t.onFragDecrypted=function(e,t){var r=t.frag;if(r.type===m.PlaylistLevelType.SUBTITLE){if(!(0,i.isFiniteNumber)(this.initPTS[r.cc]))return void this.unparsedVttFrags.push(t);this.onFragLoaded(o.Events.FRAG_LOADED,t)}},t.onSubtitleTracksCleared=function(){this.tracks=[],this.captionsTracks={}},t.onFragParsingUserdata=function(e,t){var r=this.cea608Parser1,a=this.cea608Parser2;if(this.enabled&&r&&a){var n=t.frag,s=t.samples;if(n.type!==m.PlaylistLevelType.MAIN||"NONE"!==this.closedCaptionsForLevel(n))for(var o=0,d;o<s.length;o++)if(d=s[o].bytes,d){var l=this.extractCea608Data(d);r.addData(s[o].pts,l[0]),a.addData(s[o].pts,l[1])}}},t.onBufferFlushing=function(e,t){var r=t.startOffset,a=t.endOffset,n=t.endOffsetSubtitles,s=t.type,i=this.media;if(i&&!(i.currentTime<a)){if(!s||"video"===s){var o=this.captionsTracks;Object.keys(o).forEach(function(e){return(0,c.removeCuesInRange)(o[e],r,a)})}if(this.config.renderTextTracksNatively&&0===r&&void 0!==n){var d=this.textTracks;Object.keys(d).forEach(function(e){return(0,c.removeCuesInRange)(d[e],r,n)})}}},t.extractCea608Data=function(e){for(var t=[[],[]],r=31&e[0],a=2,n=0;n<r;n++){var s=e[a++],i=127&e[a++],o=127&e[a++];if(0!==i||0!==o){if(0!=(4&s)){var d=3&s;(0==d||1===d)&&(t[d].push(i),t[d].push(o))}}}return t},e}()},"./src/crypt/aes-crypto.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});var a=function(){function e(e,t){this.subtle=void 0,this.aesIV=void 0,this.subtle=e,this.aesIV=t}var t=e.prototype;return t.decrypt=function(e,t){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},t,e)},e}()},"./src/crypt/aes-decryptor.ts":(e,t,r)=>{"use strict";function a(e){var t=e.byteLength,r=t&&new DataView(e.buffer).getUint8(t-1);return r?(0,n.sliceUint8)(e,0,t-r):e}r.r(t),r.d(t,{default:()=>s,removePadding:()=>a});var n=r("./src/utils/typed-array.ts"),s=function(){function e(){this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}var t=e.prototype;return t.uint8ArrayToUint32Array_=function(e){for(var t=new DataView(e),r=new Uint32Array(4),a=0;4>a;a++)r[a]=t.getUint32(4*a);return r},t.initTable=function(){var e=this.sBox,r=this.invSBox,a=this.subMix,n=a[0],s=a[1],o=a[2],l=a[3],u=this.invSubMix,c=u[0],g=u[1],f=u[2],m=u[3],p=new Uint32Array(256),d=0,y=0,E=0;for(E=0;256>E;E++)p[E]=128>E?E<<1:283^E<<1;for(E=0;256>E;E++){var T=y^y<<1^y<<2^y<<3^y<<4;T=99^(T>>>8^255&T),e[d]=T,r[T]=d;var h=p[d],S=p[h],v=p[S],L=257*p[T]^16843008*T;n[d]=L<<24|L>>>8,s[d]=L<<16|L>>>16,o[d]=L<<8|L>>>24,l[d]=L,L=16843009*v^65537*S^257*h^16843008*d,c[T]=L<<24|L>>>8,g[T]=L<<16|L>>>16,f[T]=L<<8|L>>>24,m[T]=L,d?(d=h^p[p[p[v^h]]],y^=p[p[y]]):d=y=1}},t.expandKey=function(e){for(var r=this.uint8ArrayToUint32Array_(e),a=!0,n=0;n<r.length&&a;)a=r[n]===this.key[n],n++;if(!a){this.key=r;var s=this.keySize=r.length;if(4!==s&&6!==s&&8!==s)throw new Error("Invalid aes key size="+s);var i=this.ksRows=4*(s+6+1),o=this.keySchedule=new Uint32Array(i),d=this.invKeySchedule=new Uint32Array(i),l=this.sBox,u=this.rcon,c=this.invSubMix,g=c[0],f=c[1],m=c[2],p=c[3],y,E,T,h;for(y=0;y<i;y++){if(y<s){T=o[y]=r[y];continue}h=T,0==y%s?(h=h<<8|h>>>24,h=l[h>>>24]<<24|l[255&h>>>16]<<16|l[255&h>>>8]<<8|l[255&h],h^=u[0|y/s]<<24):6<s&&4==y%s&&(h=l[h>>>24]<<24|l[255&h>>>16]<<16|l[255&h>>>8]<<8|l[255&h]),o[y]=T=(o[y-s]^h)>>>0}for(E=0;E<i;E++)y=i-E,h=3&E?o[y]:o[y-4],d[E]=4>E||4>=y?h:g[l[h>>>24]]^f[l[255&h>>>16]]^m[l[255&h>>>8]]^p[l[255&h]],d[E]>>>=0}},t.networkToHostOrderSwap=function(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24},t.decrypt=function(e,t,r){for(var a=this.keySize+6,n=this.invKeySchedule,s=this.invSBox,o=this.invSubMix,d=o[0],l=o[1],u=o[2],c=o[3],g=this.uint8ArrayToUint32Array_(r),f=g[0],m=g[1],p=g[2],y=g[3],E=new Int32Array(e),T=new Int32Array(E.length),h=this.networkToHostOrderSwap,S,v,L,D,k,I,A,R,b,C,_,x,P,F;t<E.length;){for(b=h(E[t]),C=h(E[t+1]),_=h(E[t+2]),x=h(E[t+3]),k=b^n[0],I=x^n[1],A=_^n[2],R=C^n[3],P=4,F=1;F<a;F++)S=d[k>>>24]^l[255&I>>16]^u[255&A>>8]^c[255&R]^n[P],v=d[I>>>24]^l[255&A>>16]^u[255&R>>8]^c[255&k]^n[P+1],L=d[A>>>24]^l[255&R>>16]^u[255&k>>8]^c[255&I]^n[P+2],D=d[R>>>24]^l[255&k>>16]^u[255&I>>8]^c[255&A]^n[P+3],k=S,I=v,A=L,R=D,P+=4;S=s[k>>>24]<<24^s[255&I>>16]<<16^s[255&A>>8]<<8^s[255&R]^n[P],v=s[I>>>24]<<24^s[255&A>>16]<<16^s[255&R>>8]<<8^s[255&k]^n[P+1],L=s[A>>>24]<<24^s[255&R>>16]<<16^s[255&k>>8]<<8^s[255&I]^n[P+2],D=s[R>>>24]<<24^s[255&k>>16]<<16^s[255&I>>8]<<8^s[255&A]^n[P+3],T[t]=h(S^f),T[t+1]=h(D^m),T[t+2]=h(L^p),T[t+3]=h(v^y),f=b,m=C,p=_,y=x,t+=4}return T.buffer},e}()},"./src/crypt/decrypter.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>l});var a=r("./src/crypt/aes-crypto.ts"),n=r("./src/crypt/fast-aes-key.ts"),s=r("./src/crypt/aes-decryptor.ts"),i=r("./src/utils/logger.ts"),o=r("./src/utils/mp4-tools.ts"),d=r("./src/utils/typed-array.ts"),l=function(){function e(e,t){var r=void 0===t?{}:t,a=r.removePKCS7Padding,n=void 0===a||a;if(this.logEnabled=!0,this.removePKCS7Padding=void 0,this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null,this.useSoftware=void 0,this.useSoftware=e.enableSoftwareAES,this.removePKCS7Padding=n,n)try{var s=self.crypto;s&&(this.subtle=s.subtle||s.webkitSubtle)}catch(t){}null===this.subtle&&(this.useSoftware=!0)}var t=e.prototype;return t.destroy=function(){this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null},t.isSync=function(){return this.useSoftware},t.flush=function(){var e=this.currentResult,t=this.remainderData;if(!e||t)return this.reset(),null;var r=new Uint8Array(e);return this.reset(),this.removePKCS7Padding?(0,s.removePadding)(r):r},t.reset=function(){this.currentResult=null,this.currentIV=null,this.remainderData=null,this.softwareDecrypter&&(this.softwareDecrypter=null)},t.decrypt=function(e,t,r){var a=this;return this.useSoftware?new Promise(function(n,s){a.softwareDecrypt(new Uint8Array(e),t,r);var i=a.flush();i?n(i.buffer):s(new Error("[softwareDecrypt] Failed to decrypt data"))}):this.webCryptoDecrypt(new Uint8Array(e),t,r)},t.softwareDecrypt=function(e,t,r){var a=this.currentIV,n=this.currentResult,i=this.remainderData;this.logOnce("JS AES decrypt"),i&&(e=(0,o.appendUint8Array)(i,e),this.remainderData=null);var l=this.getValidChunk(e);if(!l.length)return null;a&&(r=a);var u=this.softwareDecrypter;u||(u=this.softwareDecrypter=new s["default"]),u.expandKey(t);var c=n;return this.currentResult=u.decrypt(l.buffer,0,r),this.currentIV=(0,d.sliceUint8)(l,-16).buffer,c?c:null},t.webCryptoDecrypt=function(e,t,r){var s=this,o=this.subtle;return this.key===t&&this.fastAesKey||(this.key=t,this.fastAesKey=new n["default"](o,t)),this.fastAesKey.expandKey().then(function(t){if(!o)return Promise.reject(new Error("web crypto not initialized"));s.logOnce("WebCrypto AES decrypt");var n=new a["default"](o,new Uint8Array(r));return n.decrypt(e.buffer,t)}).catch(function(a){return i.logger.warn("[decrypter]: WebCrypto Error, disable WebCrypto API, "+a.name+": "+a.message),s.onWebCryptoError(e,t,r)})},t.onWebCryptoError=function(e,t,r){this.useSoftware=!0,this.logEnabled=!0,this.softwareDecrypt(e,t,r);var a=this.flush();if(a)return a.buffer;throw new Error("WebCrypto and softwareDecrypt: failed to decrypt data")},t.getValidChunk=function(e){var t=e,r=e.length-e.length%16;return r!==e.length&&(t=(0,d.sliceUint8)(e,0,r),this.remainderData=(0,d.sliceUint8)(e,r)),t},t.logOnce=function(e){this.logEnabled&&(i.logger.log("[decrypter]: "+e),this.logEnabled=!1)},e}()},"./src/crypt/fast-aes-key.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});var a=function(){function e(e,t){this.subtle=void 0,this.key=void 0,this.subtle=e,this.key=t}var t=e.prototype;return t.expandKey=function(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])},e}()},"./src/demux/aacdemuxer.ts":(e,t,r)=>{"use strict";function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,n(e,t)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}r.r(t),r.d(t,{default:()=>u});var s=r("./src/demux/base-audio-demuxer.ts"),i=r("./src/demux/adts.ts"),o=r("./src/utils/logger.ts"),d=r("./src/demux/id3.ts"),l=function(e){function t(t,r){var a;return a=e.call(this)||this,a.observer=void 0,a.config=void 0,a.observer=t,a.config=r,a}a(t,e);var r=t.prototype;return r.resetInitSegment=function(t,r,a,n){e.prototype.resetInitSegment.call(this,t,r,a,n),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},t.probe=function(e){if(!e)return!1;for(var t=d.getID3Data(e,0)||[],r=t.length,a=e.length;r<a;r++)if(i.probe(e,r))return o.logger.log("ADTS sync word found !"),!0;return!1},r.canParse=function(e,t){return i.canParse(e,t)},r.appendFrame=function(e,t,r){i.initTrackConfig(e,this.observer,t,r,e.manifestCodec);var a=i.appendFrame(e,t,r,this.basePTS,this.frameIndex);if(a&&0===a.missing)return a},t}(s["default"]);const u=l},"./src/demux/adts.ts":(e,t,r)=>{"use strict";function a(e,t,r,a){var n=navigator.userAgent.toLowerCase(),s=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],i,o,d,l;i=((192&t[r+2])>>>6)+1;var u=(60&t[r+2])>>>2;return u>s.length-1?void e.trigger(E.Events.ERROR,{type:y.ErrorTypes.MEDIA_ERROR,details:y.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+u}):(d=(1&t[r+2])<<2,d|=(192&t[r+3])>>>6,p.logger.log("manifest codec:"+a+", ADTS type:"+i+", samplingIndex:"+u),/firefox/i.test(n)?6<=u?(i=5,l=[,,,,],o=u-3):(i=2,l=[,,],o=u):-1===n.indexOf("android")?(i=5,l=[,,,,],a&&(-1!==a.indexOf("mp4a.40.29")||-1!==a.indexOf("mp4a.40.5"))||!a&&6<=u?o=u-3:((a&&-1!==a.indexOf("mp4a.40.2")&&(6<=u&&1===d||/vivaldi/i.test(n))||!a&&1===d)&&(i=2,l=[,,]),o=u)):(i=2,l=[,,],o=u),l[0]=i<<3,l[0]|=(14&u)>>1,l[1]|=(1&u)<<7,l[1]|=d<<3,5===i&&(l[1]|=(14&o)>>1,l[2]=(1&o)<<7,l[2]|=8,l[3]=0),{config:l,samplerate:s[u],channelCount:d,codec:"mp4a.40."+i,manifestCodec:a})}function n(e,t){return 255===e[t]&&240==(246&e[t+1])}function s(e,t){return 1&e[t+1]?7:9}function i(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function o(e,t){return t+5<e.length}function d(e,t){return t+1<e.length&&n(e,t)}function l(e,t){return o(e,t)&&n(e,t)&&i(e,t)<=e.length-t}function u(e,t){if(d(e,t)){var r=s(e,t);if(t+r>=e.length)return!1;var a=i(e,t);if(a<=r)return!1;var n=t+a;return n===e.length||d(e,n)}return!1}function c(e,t,r,n,s){if(!e.samplerate){var i=a(t,r,n,s);if(!i)return;e.config=i.config,e.samplerate=i.samplerate,e.channelCount=i.channelCount,e.codec=i.codec,e.manifestCodec=i.manifestCodec,p.logger.log("parsed codec:"+e.codec+", rate:"+i.samplerate+", channels:"+i.channelCount)}}function g(e){return 92160000/e}function f(e,t){var r=s(e,t);if(t+r<=e.length){var a=i(e,t)-r;if(0<a)return{headerLength:r,frameLength:a}}}function m(e,t,r,a,n){var s=g(e.samplerate),i=a+n*s,o=f(t,r),d;if(o){var l=o.frameLength,u=o.headerLength,c=u+l,m=Math.max(0,r+c-t.length);m?(d=new Uint8Array(c-u),d.set(t.subarray(r+u,t.length),0)):d=t.subarray(r+u,r+c);var p={unit:d,pts:i};return m||e.samples.push(p),{sample:p,length:c,missing:m}}var y=t.length-r;d=new Uint8Array(y),d.set(t.subarray(r,t.length),0);var E={unit:d,pts:i};return{sample:E,length:y,missing:-1}}r.r(t),r.d(t,{appendFrame:()=>m,canGetFrameLength:()=>o,canParse:()=>l,getAudioConfig:()=>a,getFrameDuration:()=>g,getFullFrameLength:()=>i,getHeaderLength:()=>s,initTrackConfig:()=>c,isHeader:()=>d,isHeaderPattern:()=>n,parseFrameHeader:()=>f,probe:()=>u});var p=r("./src/utils/logger.ts"),y=r("./src/errors.ts"),E=r("./src/events.ts")},"./src/demux/base-audio-demuxer.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>c,initPTSFn:()=>u});var a=r("./src/polyfills/number.ts"),n=r("./src/demux/id3.ts"),s=r("./src/types/demuxer.ts"),i=r("./src/demux/dummy-demuxed-track.ts"),o=r("./src/utils/mp4-tools.ts"),d=r("./src/utils/typed-array.ts"),l=function(){function e(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}var t=e.prototype;return t.resetInitSegment=function(){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}},t.resetTimeStamp=function(e){this.initPTS=e,this.resetContiguity()},t.resetContiguity=function(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0},t.canParse=function(){return!1},t.appendFrame=function(){},t.demux=function(e,t){this.cachedData&&(e=(0,o.appendUint8Array)(this.cachedData,e),this.cachedData=null);var r=n.getID3Data(e,0),l=r?r.length:0,c=this._audioTrack,g=this._id3Track,f=r?n.getTimeStamp(r):void 0,m=e.length,p;for((null===this.basePTS||0===this.frameIndex&&(0,a.isFiniteNumber)(f))&&(this.basePTS=u(f,t,this.initPTS),this.lastPTS=this.basePTS),null===this.lastPTS&&(this.lastPTS=this.basePTS),r&&0<r.length&&g.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:r,type:s.MetadataSchema.audioId3,duration:Number.POSITIVE_INFINITY});l<m;){if(this.canParse(e,l)){var y=this.appendFrame(c,e,l);y?(this.frameIndex++,this.lastPTS=y.sample.pts,l+=y.length,p=l):l=m}else n.canParse(e,l)?(r=n.getID3Data(e,l),g.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:r,type:s.MetadataSchema.audioId3,duration:Number.POSITIVE_INFINITY}),l+=r.length,p=l):l++;if(l===m&&p!==m){var E=(0,d.sliceUint8)(e,p);this.cachedData=this.cachedData?(0,o.appendUint8Array)(this.cachedData,E):E}}return{audioTrack:c,videoTrack:(0,i.dummyTrack)(),id3Track:g,textTrack:(0,i.dummyTrack)()}},t.demuxSampleAes=function(){return Promise.reject(new Error("["+this+"] This demuxer does not support Sample-AES decryption"))},t.flush=function(){var e=this.cachedData;return e&&(this.cachedData=null,this.demux(e,0)),{audioTrack:this._audioTrack,videoTrack:(0,i.dummyTrack)(),id3Track:this._id3Track,textTrack:(0,i.dummyTrack)()}},t.destroy=function(){},e}(),u=function(e,t,r){return(0,a.isFiniteNumber)(e)?90*e:9e4*t+(r||0)};const c=l},"./src/demux/chunk-cache.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=new Uint8Array(t),a=0,n=0,s;n<e.length;n++)s=e[n],r.set(s,a),a+=s.length;return r}r.r(t),r.d(t,{default:()=>n});var n=function(){function e(){this.chunks=[],this.dataLength=0}var t=e.prototype;return t.push=function(e){this.chunks.push(e),this.dataLength+=e.length},t.flush=function(){var e=this.chunks,t=this.dataLength,r;return e.length?(r=1===e.length?e[0]:a(e,t),this.reset(),r):new Uint8Array(0)},t.reset=function(){this.chunks.length=0,this.dataLength=0},e}()},"./src/demux/dummy-demuxed-track.ts":(e,t,r)=>{"use strict";function a(e,t){return void 0===e&&(e=""),void 0===t&&(t=9e4),{type:e,id:-1,pid:-1,inputTimeScale:t,sequenceNumber:-1,samples:[],dropped:0}}r.r(t),r.d(t,{dummyTrack:()=>a})},"./src/demux/exp-golomb.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>s});var a=r("./src/utils/logger.ts"),n=function(){function e(e){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=e,this.bytesAvailable=e.byteLength,this.word=0,this.bitsAvailable=0}var t=e.prototype;return t.loadWord=function(){var e=this.data,t=this.bytesAvailable,r=e.byteLength-t,a=new Uint8Array(4),n=Math.min(4,t);if(0===n)throw new Error("no bytes available");a.set(e.subarray(r,r+n)),this.word=new DataView(a.buffer).getUint32(0),this.bitsAvailable=8*n,this.bytesAvailable-=n},t.skipBits=function(e){var t;e=Math.min(e,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,t=e>>3,e-=t<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)},t.readBits=function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(32<e&&a.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,0<this.bitsAvailable)this.word<<=t;else if(0<this.bytesAvailable)this.loadWord();else throw new Error("no bits available");return t=e-t,0<t&&this.bitsAvailable?r<<t|this.readBits(t):r},t.skipLZ=function(){var e;for(e=0;e<this.bitsAvailable;++e)if(0!=(this.word&2147483648>>>e))return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()},t.skipUEG=function(){this.skipBits(1+this.skipLZ())},t.skipEG=function(){this.skipBits(1+this.skipLZ())},t.readUEG=function(){var e=this.skipLZ();return this.readBits(e+1)-1},t.readEG=function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)},t.readBoolean=function(){return 1===this.readBits(1)},t.readUByte=function(){return this.readBits(8)},t.readUShort=function(){return this.readBits(16)},t.readUInt=function(){return this.readBits(32)},t.skipScalingList=function(e){for(var t=8,r=8,a=0,n;a<e;a++)0!==r&&(n=this.readEG(),r=(t+n+256)%256),t=0===r?t:r},t.readSPS=function(){var e=0,t=0,r=0,a=0,n=this.readUByte.bind(this),s=this.readBits.bind(this),o=this.readUEG.bind(this),d=this.readBoolean.bind(this),l=this.skipBits.bind(this),u=this.skipEG.bind(this),c=this.skipUEG.bind(this),g=this.skipScalingList.bind(this),f,m,p;n();var y=n();if(s(5),l(3),n(),c(),100===y||110===y||122===y||244===y||44===y||83===y||86===y||118===y||128===y){var E=o();if(3===E&&l(1),c(),c(),l(1),d())for(m=3===E?12:8,p=0;p<m;p++)d()&&(6>p?g(16):g(64))}c();var T=o();if(0===T)o();else if(1===T)for(l(1),u(),u(),f=o(),p=0;p<f;p++)u();c(),l(1);var h=o(),S=o(),v=s(1);0===v&&l(1),l(1),d()&&(e=o(),t=o(),r=o(),a=o());var L=[1,1];if(d()&&d()){var D=n();switch(D){case 1:L=[1,1];break;case 2:L=[12,11];break;case 3:L=[10,11];break;case 4:L=[16,11];break;case 5:L=[40,33];break;case 6:L=[24,11];break;case 7:L=[20,11];break;case 8:L=[32,11];break;case 9:L=[80,33];break;case 10:L=[18,11];break;case 11:L=[15,11];break;case 12:L=[64,33];break;case 13:L=[160,99];break;case 14:L=[4,3];break;case 15:L=[3,2];break;case 16:L=[2,1];break;case 255:{L=[n()<<8|n(),n()<<8|n()];break}}}return{width:Math.ceil(16*(h+1)-2*e-2*t),height:16*((2-v)*(S+1))-(v?2:4)*(r+a),pixelRatio:L}},t.readSliceType=function(){return this.readUByte(),this.readUEG(),this.readUEG()},e}();const s=n},"./src/demux/id3.ts":(e,t,r)=>{"use strict";function a(){return S||"undefined"==typeof self.TextDecoder||(S=new self.TextDecoder("utf-8")),S}r.r(t),r.d(t,{canParse:()=>d,decodeFrame:()=>f,getID3Data:()=>i,getID3Frames:()=>g,getTimeStamp:()=>l,isFooter:()=>s,isHeader:()=>n,isTimeStampFrame:()=>u,testables:()=>h,utf8ArrayToStr:()=>T});var n=function(e,t){return!!(t+10<=e.length&&73===e[t]&&68===e[t+1]&&51===e[t+2]&&255>e[t+3]&&255>e[t+4]&&128>e[t+6]&&128>e[t+7]&&128>e[t+8]&&128>e[t+9])},s=function(e,t){return!!(t+10<=e.length&&51===e[t]&&68===e[t+1]&&73===e[t+2]&&255>e[t+3]&&255>e[t+4]&&128>e[t+6]&&128>e[t+7]&&128>e[t+8]&&128>e[t+9])},i=function(e,t){for(var r=t,a=0;n(e,t);){a+=10;var i=o(e,t+6);a+=i,s(e,t+10)&&(a+=10),t+=a}return 0<a?e.subarray(r,r+a):void 0},o=function(e,t){var r=0;return r=(127&e[t])<<21,r|=(127&e[t+1])<<14,r|=(127&e[t+2])<<7,r|=127&e[t+3],r},d=function(e,t){return n(e,t)&&o(e,t+6)+10<=e.length-t},l=function(e){for(var t=g(e),r=0,a;r<t.length;r++)if(a=t[r],u(a))return E(a)},u=function(e){return e&&"PRIV"===e.key&&"com.apple.streaming.transportStreamTimestamp"===e.info},c=function(e){var t=String.fromCharCode(e[0],e[1],e[2],e[3]),r=o(e,4);return{type:t,size:r,data:e.subarray(10,10+r)}},g=function(e){for(var t=0,r=[],a;n(e,t);){a=o(e,t+6),t+=10;for(var i=t+a;t+8<i;){var d=c(e.subarray(t)),l=f(d);l&&r.push(l),t+=d.size+10}s(e,t)&&(t+=10)}return r},f=function(e){return"PRIV"===e.type?m(e):"W"===e.type[0]?y(e):p(e)},m=function(e){if(!(2>e.size)){var t=T(e.data,!0),r=new Uint8Array(e.data.subarray(t.length+1));return{key:e.type,info:t,data:r.buffer}}},p=function(e){if(!(2>e.size)){if("TXXX"===e.type){var t=1,r=T(e.data.subarray(t),!0);t+=r.length+1;var a=T(e.data.subarray(t));return{key:e.type,info:r,data:a}}var n=T(e.data.subarray(1));return{key:e.type,data:n}}},y=function(e){if("WXXX"===e.type){if(2>e.size)return;var t=1,r=T(e.data.subarray(t),!0);t+=r.length+1;var a=T(e.data.subarray(t));return{key:e.type,info:r,data:a}}var n=T(e.data);return{key:e.type,data:n}},E=function(e){if(8===e.data.byteLength){var t=new Uint8Array(e.data),r=1&t[3],a=(t[4]<<23)+(t[5]<<15)+(t[6]<<7)+t[7];return a/=45,r&&(a+=47721858.84),Math.round(a)}},T=function(e,t){void 0===t&&(t=!1);var r=a();if(r){var n=r.decode(e);if(t){var s=n.indexOf("\0");return-1===s?n:n.substring(0,s)}return n.replace(/\0/g,"")}for(var o=e.length,d="",l=0,u,g,f;l<o;){if(u=e[l++],0===u&&t)return d;if(0!==u&&3!==u)switch(u>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:d+=String.fromCharCode(u);break;case 12:case 13:g=e[l++],d+=String.fromCharCode((31&u)<<6|63&g);break;case 14:g=e[l++],f=e[l++],d+=String.fromCharCode((15&u)<<12|(63&g)<<6|(63&f)<<0);break;default:}}return d},h={decodeTextFrame:p},S},"./src/demux/mp3demuxer.ts":(e,t,r)=>{"use strict";function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,n(e,t)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}r.r(t),r.d(t,{default:()=>u});var s=r("./src/demux/base-audio-demuxer.ts"),i=r("./src/demux/id3.ts"),o=r("./src/utils/logger.ts"),d=r("./src/demux/mpegaudio.ts"),l=function(e){function t(){return e.apply(this,arguments)||this}a(t,e);var r=t.prototype;return r.resetInitSegment=function(t,r,a,n){e.prototype.resetInitSegment.call(this,t,r,a,n),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:n,inputTimeScale:9e4,dropped:0}},t.probe=function(e){if(!e)return!1;for(var t=i.getID3Data(e,0)||[],r=t.length,a=e.length;r<a;r++)if(d.probe(e,r))return o.logger.log("MPEG Audio sync word found !"),!0;return!1},r.canParse=function(e,t){return d.canParse(e,t)},r.appendFrame=function(e,t,r){return null===this.basePTS?void 0:d.appendFrame(e,t,r,this.basePTS,this.frameIndex)},t}(s["default"]);const u=l},"./src/demux/mp4demuxer.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>d});var a=r("./src/polyfills/number.ts"),n=r("./src/types/demuxer.ts"),s=r("./src/utils/mp4-tools.ts"),i=r("./src/demux/dummy-demuxed-track.ts"),o=function(){function e(e,t){this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=t}var t=e.prototype;return t.resetTimeStamp=function(){},t.resetInitSegment=function(e,t,r,a){var n=this.videoTrack=(0,i.dummyTrack)("video",1),o=this.audioTrack=(0,i.dummyTrack)("audio",1),d=this.txtTrack=(0,i.dummyTrack)("text",1);if(this.id3Track=(0,i.dummyTrack)("id3",1),this.timeOffset=0,e&&e.byteLength){var l=(0,s.parseInitSegment)(e);if(l.video){var u=l.video,c=u.id,g=u.timescale,f=u.codec;n.id=c,n.timescale=d.timescale=g,n.codec=f}if(l.audio){var m=l.audio,p=m.id,y=m.timescale,E=m.codec;o.id=p,o.timescale=y,o.codec=E}d.id=s.RemuxerTrackIdConfig.text,n.sampleDuration=0,n.duration=o.duration=a}},t.resetContiguity=function(){},e.probe=function(e){return e=16384<e.length?e.subarray(0,16384):e,0<(0,s.findBox)(e,["moof"]).length},t.demux=function(e,t){this.timeOffset=t;var r=e,a=this.videoTrack,n=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=(0,s.appendUint8Array)(this.remainderData,e));var i=(0,s.segmentValidRange)(r);this.remainderData=i.remainder,a.samples=i.valid||new Uint8Array}else a.samples=r;var o=this.extractID3Track(a,t);return n.samples=(0,s.parseSamples)(t,a),{videoTrack:a,audioTrack:this.audioTrack,id3Track:o,textTrack:this.txtTrack}},t.flush=function(){var e=this.timeOffset,t=this.videoTrack,r=this.txtTrack;t.samples=this.remainderData||new Uint8Array,this.remainderData=null;var a=this.extractID3Track(t,this.timeOffset);return r.samples=(0,s.parseSamples)(e,t),{videoTrack:t,audioTrack:(0,i.dummyTrack)(),id3Track:a,textTrack:(0,i.dummyTrack)()}},t.extractID3Track=function(e,t){var r=this.id3Track;if(e.samples.length){var i=(0,s.findBox)(e.samples,["emsg"]);i&&i.forEach(function(e){var i=(0,s.parseEmsg)(e);if(/\/emsg[-/]ID3/i.test(i.schemeIdUri)){var o=(0,a.isFiniteNumber)(i.presentationTime)?i.presentationTime/i.timeScale:t+i.presentationTimeDelta/i.timeScale,d=4294967295===i.eventDuration?Number.POSITIVE_INFINITY:i.eventDuration/i.timeScale;.001>=d&&(d=Number.POSITIVE_INFINITY);var l=i.payload;r.samples.push({data:l,len:l.byteLength,dts:o,pts:o,type:n.MetadataSchema.emsg,duration:d})}})}return r},t.demuxSampleAes=function(){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},t.destroy=function(){},e}();const d=o},"./src/demux/mpegaudio.ts":(e,t,r)=>{"use strict";function a(e,t,r,a,s){if(!(r+24>t.length)){var i=n(t,r);if(i&&r+i.frameLength<=t.length){var o=9e4*i.samplesPerFrame/i.sampleRate,d=a+s*o,l={unit:t.subarray(r,r+i.frameLength),pts:d,dts:d};return e.config=[],e.channelCount=i.channelCount,e.samplerate=i.sampleRate,e.samples.push(l),{sample:l,length:i.frameLength,missing:0}}}}function n(e,t){var r=3&e[t+1]>>3,a=3&e[t+1]>>1,n=15&e[t+2]>>4,s=3&e[t+2]>>2;if(1!=r&&0!==n&&15!==n&&3!==s){var i=1&e[t+2]>>1,o=e[t+3]>>6,d=3===r?3-a:3===a?3:4,m=1e3*u[14*d+n-1],p=3===r?0:2===r?1:2,y=c[3*p+s],E=3===o?1:2,T=g[r][a],h=f[a],S=Math.floor(T*m/y+i)*h;if(null===l){var v=navigator.userAgent||"",L=v.match(/Chrome\/(\d+)/i);l=L?parseInt(L[1]):0}var D=!!l&&87>=l;return D&&2===a&&224e3<=m&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:y,channelCount:E,frameLength:S,samplesPerFrame:8*T*h}}}function s(e,t){return 255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}function i(e,t){return t+1<e.length&&s(e,t)}function o(e,t){return s(e,t)&&4<=e.length-t}function d(e,t){if(t+1<e.length&&s(e,t)){var r=n(e,t),a=4;null!==r&&void 0!==r&&r.frameLength&&(a=r.frameLength);var o=t+a;return o===e.length||i(e,o)}return!1}r.r(t),r.d(t,{appendFrame:()=>a,canParse:()=>o,isHeader:()=>i,isHeaderPattern:()=>s,parseHeader:()=>n,probe:()=>d});var l=null,u=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],c=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],g=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],f=[0,1,1,4]},"./src/demux/sample-aes.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>i});var a=r("./src/crypt/decrypter.ts"),n=r("./src/utils/mp4-tools.ts"),s=function(){function e(e,t,r){this.keyData=void 0,this.decrypter=void 0,this.keyData=r,this.decrypter=new a["default"](t,{removePKCS7Padding:!1})}var t=e.prototype;return t.decryptBuffer=function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer)},t.decryptAacSample=function(e,t,r){var a=this,n=e[t].unit;if(!(16>=n.length)){var s=n.subarray(16,n.length-n.length%16),i=s.buffer.slice(s.byteOffset,s.byteOffset+s.length);this.decryptBuffer(i).then(function(s){var i=new Uint8Array(s);n.set(i,16),a.decrypter.isSync()||a.decryptAacSamples(e,t+1,r)})}},t.decryptAacSamples=function(e,t,r){for(;;t++){if(t>=e.length)return void r();if(!(32>e[t].unit.length)&&(this.decryptAacSample(e,t,r),!this.decrypter.isSync()))return}},t.getAvcEncryptedData=function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),a=0,n=32;n<e.length-16;n+=160,a+=16)r.set(e.subarray(n,n+16),a);return r},t.getAvcDecryptedUnit=function(e,t){for(var r=new Uint8Array(t),a=0,n=32;n<e.length-16;n+=160,a+=16)e.set(r.subarray(a,a+16),n);return e},t.decryptAvcSample=function(e,t,r,a,s){var i=this,o=(0,n.discardEPB)(s.data),d=this.getAvcEncryptedData(o);this.decryptBuffer(d.buffer).then(function(n){s.data=i.getAvcDecryptedUnit(o,n),i.decrypter.isSync()||i.decryptAvcSamples(e,t,r+1,a)})},t.decryptAvcSamples=function(e,t,r,a){if(e instanceof Uint8Array)throw new Error("Cannot decrypt samples of type Uint8Array");for(;;t++,r=0){if(t>=e.length)return void a();for(var n=e[t].units;;r++){if(r>=n.length)break;var s=n[r];if(!(48>=s.data.length||1!==s.type&&5!==s.type)&&(this.decryptAvcSample(e,t,r,a,s),!this.decrypter.isSync()))return}}},e}();const i=s},"./src/demux/transmuxer-interface.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>g});var a=r("./src/demux/webworkify-webpack.js"),n=r("./src/events.ts"),s=r("./src/demux/transmuxer.ts"),i=r("./src/utils/logger.ts"),o=r("./src/errors.ts"),d=r("./src/utils/mediasource-helper.ts"),l=r("./node_modules/eventemitter3/index.js"),u=r.n(l),c=(0,d.getMediaSource)()||{isTypeSupported:function(){return!1}},g=function(){function e(e,t,r,d){var u=this;this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.useWorker=void 0,this.worker=void 0,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0;var g=e.config;this.hls=e,this.id=t,this.useWorker=!!g.enableWorker,this.onTransmuxComplete=r,this.onFlush=d;var f=function(e,t){t=t||{},t.frag=u.frag,t.id=u.id,u.hls.trigger(e,t)};this.observer=new l.EventEmitter,this.observer.on(n.Events.FRAG_DECRYPTED,f),this.observer.on(n.Events.ERROR,f);var m={mp4:c.isTypeSupported("video/mp4"),mpeg:c.isTypeSupported("audio/mpeg"),mp3:c.isTypeSupported("audio/mp4; codecs=\"mp3\"")},p=navigator.vendor;if(this.useWorker&&"undefined"!=typeof Worker){i.logger.log("demuxing in webworker");var y;try{y=this.worker=(0,a["default"])("./src/demux/transmuxer-worker.ts"),this.onwmsg=this.onWorkerMessage.bind(this),y.addEventListener("message",this.onwmsg),y.onerror=function(e){u.useWorker=!1,i.logger.warn("Exception in webworker, fallback to inline"),u.hls.trigger(n.Events.ERROR,{type:o.ErrorTypes.OTHER_ERROR,details:o.ErrorDetails.INTERNAL_EXCEPTION,fatal:!1,event:"demuxerWorker",error:new Error(e.message+"  ("+e.filename+":"+e.lineno+")")})},y.postMessage({cmd:"init",typeSupported:m,vendor:p,id:t,config:JSON.stringify(g)})}catch(e){i.logger.warn("Error in worker:",e),i.logger.error("Error while initializing DemuxerWorker, fallback to inline"),y&&self.URL.revokeObjectURL(y.objectURL),this.transmuxer=new s["default"](this.observer,m,g,p,t),this.worker=null}}else this.transmuxer=new s["default"](this.observer,m,g,p,t)}var t=e.prototype;return t.destroy=function(){var e=this.worker;if(e)e.removeEventListener("message",this.onwmsg),e.terminate(),this.worker=null,this.onwmsg=void 0;else{var t=this.transmuxer;t&&(t.destroy(),this.transmuxer=null)}var r=this.observer;r&&r.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null},t.push=function(e,t,r,a,n,o,d,l,u,c){var g=this,f,m;u.transmuxing.start=self.performance.now();var p=this.transmuxer,y=this.worker,E=o?o.start:n.start,T=n.decryptdata,h=this.frag,S=!(h&&n.cc===h.cc),v=!(h&&u.level===h.level),L=h?u.sn-h.sn:-1,D=this.part?u.part-this.part.index:-1,k=0===L&&1<u.id&&u.id===(null===h||void 0===h?void 0:h.stats.chunkCount),I=!v&&(1===L||0===L&&(1===D||k&&0>=D)),A=self.performance.now();(v||L||0===n.stats.parsing.start)&&(n.stats.parsing.start=A),o&&(D||!I)&&(o.stats.parsing.start=A);var R=!(h&&(null===(f=n.initSegment)||void 0===f?void 0:f.url)===(null===(m=h.initSegment)||void 0===m?void 0:m.url)),b=new s.TransmuxState(S,I,l,v,E,R);if(!I||S||R){i.logger.log("[transmuxer-interface, "+n.type+"]: Starting new transmux session for sn: "+u.sn+" p: "+u.part+" level: "+u.level+" id: "+u.id+"\n        discontinuity: "+S+"\n        trackSwitch: "+v+"\n        contiguous: "+I+"\n        accurateTimeOffset: "+l+"\n        timeOffset: "+E+"\n        initSegmentChange: "+R);var C=new s.TransmuxConfig(r,a,t,d,c);this.configureTransmuxer(C)}if(this.frag=n,this.part=o,y)y.postMessage({cmd:"demux",data:e,decryptdata:T,chunkMeta:u,state:b},e instanceof ArrayBuffer?[e]:[]);else if(p){var _=p.push(e,T,u,b);(0,s.isPromise)(_)?(p.async=!0,_.then(function(e){g.handleTransmuxComplete(e)}).catch(function(e){g.transmuxerError(e,u,"transmuxer-interface push error")})):(p.async=!1,this.handleTransmuxComplete(_))}},t.flush=function(e){var t=this;e.transmuxing.start=self.performance.now();var r=this.transmuxer,a=this.worker;if(a)1,a.postMessage({cmd:"flush",chunkMeta:e});else if(r){var n=r.flush(e),i=(0,s.isPromise)(n);i||r.async?(!(0,s.isPromise)(n)&&(n=Promise.resolve(n)),n.then(function(r){t.handleFlushResult(r,e)}).catch(function(r){t.transmuxerError(r,e,"transmuxer-interface flush error")})):this.handleFlushResult(n,e)}},t.transmuxerError=function(e,t,r){this.hls&&this.hls.trigger(n.Events.ERROR,{type:o.ErrorTypes.MEDIA_ERROR,details:o.ErrorDetails.FRAG_PARSING_ERROR,chunkMeta:t,fatal:!1,error:e,err:e,reason:r})},t.handleFlushResult=function(e,t){var r=this;e.forEach(function(e){r.handleTransmuxComplete(e)}),this.onFlush(t)},t.onWorkerMessage=function(e){var t=e.data,r=this.hls;switch(t.event){case"init":{self.URL.revokeObjectURL(this.worker.objectURL);break}case"transmuxComplete":{this.handleTransmuxComplete(t.data);break}case"flush":{this.onFlush(t.data);break}case"workerLog":i.logger[t.data.logType]&&i.logger[t.data.logType](t.data.message);break;default:{t.data=t.data||{},t.data.frag=this.frag,t.data.id=this.id,r.trigger(t.event,t.data);break}}},t.configureTransmuxer=function(e){var t=this.worker,r=this.transmuxer;t?t.postMessage({cmd:"configure",config:e}):r&&r.configure(e)},t.handleTransmuxComplete=function(e){e.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(e)},e}()},"./src/demux/transmuxer-worker.ts":(e,t,r)=>{"use strict";function a(e){var t=new c.EventEmitter,r=function(t,r){e.postMessage({event:t,data:r})};t.on(l.Events.FRAG_DECRYPTED,r),t.on(l.Events.ERROR,r);var a=function(){var e=function(e){u.logger[e]=function(t){r("workerLog",{logType:e,message:t})}};for(var t in u.logger)e(t)};e.addEventListener("message",function(s){var o=s.data;switch(o.cmd){case"init":{var c=JSON.parse(o.config);e.transmuxer=new d["default"](t,o.typeSupported,c,o.vendor,o.id),(0,u.enableLogs)(c.debug,o.id),a(),r("init",null);break}case"configure":{e.transmuxer.configure(o.config);break}case"demux":{var g=e.transmuxer.push(o.data,o.decryptdata,o.chunkMeta,o.state);(0,d.isPromise)(g)?(e.transmuxer.async=!0,g.then(function(t){n(e,t)}).catch(function(e){r(l.Events.ERROR,{type:f.ErrorTypes.MEDIA_ERROR,details:f.ErrorDetails.FRAG_PARSING_ERROR,chunkMeta:o.chunkMeta,fatal:!1,error:e,err:e,reason:"transmuxer-worker push error"})})):(e.transmuxer.async=!1,n(e,g));break}case"flush":{var m=o.chunkMeta,p=e.transmuxer.flush(m),y=(0,d.isPromise)(p);y||e.transmuxer.async?(!(0,d.isPromise)(p)&&(p=Promise.resolve(p)),p.then(function(t){i(e,t,m)}).catch(function(e){r(l.Events.ERROR,{type:f.ErrorTypes.MEDIA_ERROR,details:f.ErrorDetails.FRAG_PARSING_ERROR,chunkMeta:o.chunkMeta,fatal:!1,error:e,err:e,reason:"transmuxer-worker flush error"})})):i(e,p,m);break}default:}})}function n(e,t){if(o(t.remuxResult))return!1;var r=[],a=t.remuxResult,n=a.audio,i=a.video;return n&&s(r,n),i&&s(r,i),e.postMessage({event:"transmuxComplete",data:t},r),!0}function s(e,t){t.data1&&e.push(t.data1.buffer),t.data2&&e.push(t.data2.buffer)}function i(e,t,r){var a=t.reduce(function(t,r){return n(e,r)||t},!1);a||e.postMessage({event:"transmuxComplete",data:t[0]}),e.postMessage({event:"flush",data:r})}function o(e){return!e.audio&&!e.video&&!e.text&&!e.id3&&!e.initSegment}r.r(t),r.d(t,{default:()=>a});var d=r("./src/demux/transmuxer.ts"),l=r("./src/events.ts"),u=r("./src/utils/logger.ts"),c=r("./node_modules/eventemitter3/index.js"),g=r.n(c),f=r("./src/errors.ts")},"./src/demux/transmuxer.ts":(e,t,r)=>{"use strict";function a(e,t){var r=null;return 0<e.byteLength&&null!=t&&null!=t.key&&null!==t.iv&&null!=t.method&&(r=t),r}function n(e){return"then"in e&&e.then instanceof Function}r.r(t),r.d(t,{TransmuxConfig:()=>h,TransmuxState:()=>S,default:()=>E,isPromise:()=>n});var s=r("./src/events.ts"),i=r("./src/errors.ts"),o=r("./src/crypt/decrypter.ts"),d=r("./src/demux/aacdemuxer.ts"),l=r("./src/demux/mp4demuxer.ts"),u=r("./src/demux/tsdemuxer.ts"),c=r("./src/demux/mp3demuxer.ts"),g=r("./src/remux/mp4-remuxer.ts"),f=r("./src/remux/passthrough-remuxer.ts"),m=r("./src/utils/logger.ts"),p;try{p=self.performance.now.bind(self.performance)}catch(e){m.logger.debug("Unable to use Performance API on this environment"),p=self.Date.now}var y=[{demux:l["default"],remux:f["default"]},{demux:u["default"],remux:g["default"]},{demux:d["default"],remux:g["default"]},{demux:c["default"],remux:g["default"]}],E=function(){function e(e,t,r,a,n){this.async=!1,this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=e,this.typeSupported=t,this.config=r,this.vendor=a,this.id=n}var t=e.prototype;return t.configure=function(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()},t.push=function(e,t,r,n){var s=this,i=r.transmuxing;i.executeStart=p();var o=new Uint8Array(e),d=this.currentTransmuxState,l=this.transmuxConfig;n&&(this.currentTransmuxState=n);var u=n||d,c=u.contiguous,g=u.discontinuity,f=u.trackSwitch,m=u.accurateTimeOffset,y=u.timeOffset,E=u.initSegmentChange,h=l.audioCodec,S=l.videoCodec,v=l.defaultInitPts,L=l.duration,D=l.initSegmentData,k=a(o,t);if(k&&"AES-128"===k.method){var I=this.getDecrypter();if(I.isSync()){var A=I.softwareDecrypt(o,k.key.buffer,k.iv.buffer),R=-1<r.part;if(R&&(A=I.flush()),!A)return i.executeEnd=p(),T(r);o=new Uint8Array(A)}else return this.decryptionPromise=I.webCryptoDecrypt(o,k.key.buffer,k.iv.buffer).then(function(e){var t=s.push(e,null,r);return s.decryptionPromise=null,t}),this.decryptionPromise}var b=this.needsProbing(g,f);b&&this.configureTransmuxer(o),(g||f||E||b)&&this.resetInitSegment(D,h,S,L,t),(g||E||b)&&this.resetInitialTimestamp(v),c||this.resetContiguity();var C=this.transmux(o,k,y,m,r),_=this.currentTransmuxState;return _.contiguous=!0,_.discontinuity=!1,_.trackSwitch=!1,i.executeEnd=p(),C},t.flush=function(e){var t=this,r=e.transmuxing;r.executeStart=p();var a=this.decrypter,o=this.currentTransmuxState,d=this.decryptionPromise;if(d)return d.then(function(){return t.flush(e)});var l=[],u=o.timeOffset;if(a){var c=a.flush();c&&l.push(this.push(c,null,e))}var g=this.demuxer,f=this.remuxer;if(!g||!f)return this.observer.emit(s.Events.ERROR,s.Events.ERROR,{type:i.ErrorTypes.MEDIA_ERROR,details:i.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"}),r.executeEnd=p(),[T(e)];var m=g.flush(u);return n(m)?m.then(function(r){return t.flushRemux(l,r,e),l}):(this.flushRemux(l,m,e),l)},t.flushRemux=function(e,t,r){var a=t.audioTrack,n=t.videoTrack,s=t.id3Track,i=t.textTrack,o=this.currentTransmuxState,d=o.accurateTimeOffset,l=o.timeOffset;m.logger.log("[transmuxer.ts]: Flushed fragment "+r.sn+(-1<r.part?" p: "+r.part:"")+" of level "+r.level);var u=this.remuxer.remux(a,n,s,i,l,d,!0,this.id);e.push({remuxResult:u,chunkMeta:r}),r.transmuxing.executeEnd=p()},t.resetInitialTimestamp=function(e){var t=this.demuxer,r=this.remuxer;t&&r&&(t.resetTimeStamp(e),r.resetTimeStamp(e))},t.resetContiguity=function(){var e=this.demuxer,t=this.remuxer;e&&t&&(e.resetContiguity(),t.resetNextTimestamp())},t.resetInitSegment=function(e,t,r,a,n){var s=this.demuxer,i=this.remuxer;s&&i&&(s.resetInitSegment(e,t,r,a),i.resetInitSegment(e,t,r,n))},t.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},t.transmux=function(e,t,r,a,n){var s;return s=t&&"SAMPLE-AES"===t.method?this.transmuxSampleAes(e,t,r,a,n):this.transmuxUnencrypted(e,r,a,n),s},t.transmuxUnencrypted=function(e,t,r,a){var n=this.demuxer.demux(e,t,!1,!this.config.progressive),s=n.audioTrack,i=n.videoTrack,o=n.id3Track,d=n.textTrack,l=this.remuxer.remux(s,i,o,d,t,r,!1,this.id);return{remuxResult:l,chunkMeta:a}},t.transmuxSampleAes=function(e,t,r,a,n){var s=this;return this.demuxer.demuxSampleAes(e,t,r).then(function(e){var t=s.remuxer.remux(e.audioTrack,e.videoTrack,e.id3Track,e.textTrack,r,a,!1,s.id);return{remuxResult:t,chunkMeta:n}})},t.configureTransmuxer=function(e){for(var t=this.config,r=this.observer,a=this.typeSupported,n=this.vendor,s=0,o=y.length,d;s<o;s++)if(y[s].demux.probe(e)){d=y[s];break}d||(m.logger.warn("Failed to find demuxer by probing frag, treating as mp4 passthrough"),d={demux:l["default"],remux:f["default"]});var u=this.demuxer,c=this.remuxer,g=d.remux,p=d.demux;c&&c instanceof g||(this.remuxer=new g(r,t,a,n)),u&&u instanceof p||(this.demuxer=new p(r,t,a),this.probe=p.probe)},t.needsProbing=function(e,t){return!this.demuxer||!this.remuxer||e||t},t.getDecrypter=function(){var e=this.decrypter;return e||(e=this.decrypter=new o["default"](this.config)),e},e}(),T=function(e){return{remuxResult:{},chunkMeta:e}},h=function(e,t,r,a,n){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=e,this.videoCodec=t,this.initSegmentData=r,this.duration=a,this.defaultInitPts=n},S=function(e,t,r,a,n,s){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=e,this.contiguous=t,this.accurateTimeOffset=r,this.trackSwitch=a,this.timeOffset=n,this.initSegmentChange=s}},"./src/demux/tsdemuxer.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t,r,a){return{key:e,frame:!1,pts:t,dts:r,units:[],debug:a,length:0}}function s(e,t){return((31&e[t+1])<<8)+e[t+2]}function i(e,t){return(31&e[t+10])<<8|e[t+11]}function o(e,t,r,a){var n={audio:-1,avc:-1,id3:-1,segmentCodec:"aac"},i=(15&e[t+1])<<8|e[t+2],o=t+3+i-4,d=(15&e[t+10])<<8|e[t+11];for(t+=12+d;t<o;){var l=s(e,t);switch(e[t]){case 207:if(!a){y.logger.log("ADTS AAC with AES-128-CBC frame encryption found in unencrypted stream");break}case 15:-1===n.audio&&(n.audio=l);break;case 21:-1===n.id3&&(n.id3=l);break;case 219:if(!a){y.logger.log("H.264 with AES-128-CBC slice encryption found in unencrypted stream");break}case 27:-1===n.avc&&(n.avc=l);break;case 3:case 4:!0!==r.mpeg&&!0!==r.mp3?y.logger.log("MPEG audio found, not supported in this browser"):-1===n.audio&&(n.audio=l,n.segmentCodec="mp3");break;case 36:y.logger.warn("Unsupported HEVC stream type found");break;default:}t+=((15&e[t+3])<<8|e[t+4])+5}return n}function d(e){var t=0,r=e.data,a,n,s,o,d;if(!e||0===e.size)return null;for(;19>r[0].length&&1<r.length;){var l=new Uint8Array(r[0].length+r[1].length);l.set(r[0]),l.set(r[1],r[0].length),r[0]=l,r.splice(1,1)}a=r[0];var u=(a[0]<<16)+(a[1]<<8)+a[2];if(1===u){if(n=(a[4]<<8)+a[5],n&&n>e.size-6)return null;var c=a[7];192&c&&(o=536870912*(14&a[9])+4194304*(255&a[10])+16384*(254&a[11])+128*(255&a[12])+(254&a[13])/2,64&c?(d=536870912*(14&a[14])+4194304*(255&a[15])+16384*(254&a[16])+128*(255&a[17])+(254&a[18])/2,5400000<o-d&&(y.logger.warn(Math.round((o-d)/9e4)+"s delta between PTS and DTS, align them"),o=d)):d=o),s=a[8];var g=s+9;if(e.size<=g)return null;e.size-=g;for(var f=new Uint8Array(e.size),m=0,p=r.length;m<p;m++){a=r[m];var E=a.byteLength;if(g)if(g>E){g-=E;continue}else a=a.subarray(g),E-=g,g=0;f.set(a,t),t+=E}return n&&(n-=s+3),{data:f,pts:o,dts:d,len:n}}return null}function l(e,t){if(e.units.length&&e.frame){if(void 0===e.pts){var r=t.samples,a=r.length;if(a){var n=r[a-1];e.pts=n.pts,e.dts=n.dts}else return void t.dropped++}t.samples.push(e)}e.debug.length&&y.logger.log(e.pts+"/"+e.dts+":"+e.debug)}r.r(t),r.d(t,{default:()=>S});var u=r("./src/demux/adts.ts"),c=r("./src/demux/mpegaudio.ts"),g=r("./src/demux/exp-golomb.ts"),f=r("./src/demux/sample-aes.ts"),m=r("./src/events.ts"),p=r("./src/utils/mp4-tools.ts"),y=r("./src/utils/logger.ts"),E=r("./src/errors.ts"),T=r("./src/types/demuxer.ts"),h=function(){function e(e,t,r){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._avcTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.observer=e,this.config=t,this.typeSupported=r}e.probe=function(t){var r=e.syncOffset(t);return 0<r&&y.logger.warn("MPEG2-TS detected but first sync word found @ offset "+r),-1!==r},e.syncOffset=function(e){for(var t=e.length,r=Math.min(940,e.length-188)+1,a=0;a<r;){for(var n=!1,o=a;o<t&&71===e[o];o+=188)if(n||0!==s(e,o)||(n=!0),n&&o+188>r)return a;a++}return-1},e.createTrack=function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:p.RemuxerTrackIdConfig[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}};var t=e.prototype;return t.resetInitSegment=function(t,r,a,n){this.pmtParsed=!1,this._pmtId=-1,this._avcTrack=e.createTrack("video"),this._audioTrack=e.createTrack("audio",n),this._id3Track=e.createTrack("id3"),this._txtTrack=e.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.avcSample=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=a,this._duration=n},t.resetTimeStamp=function(){},t.resetContiguity=function(){var e=this._audioTrack,t=this._avcTrack,r=this._id3Track;e&&(e.pesData=null),t&&(t.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.avcSample=null,this.remainderData=null},t.demux=function(t,r,a,n){void 0===a&&(a=!1),void 0===n&&(n=!1),a||(this.sampleAes=null);var l=this._avcTrack,u=this._audioTrack,c=this._id3Track,g=this._txtTrack,f=l.pid,T=l.pesData,h=u.pid,S=c.pid,v=u.pesData,L=c.pesData,D=null,k=this.pmtParsed,I=this._pmtId,A=t.length,R;if(this.remainderData&&(t=(0,p.appendUint8Array)(this.remainderData,t),A=t.length,this.remainderData=null),188>A&&!n)return this.remainderData=t,{audioTrack:u,videoTrack:l,id3Track:c,textTrack:g};var b=Math.max(0,e.syncOffset(t));A-=(A-b)%188,A<t.byteLength&&!n&&(this.remainderData=new Uint8Array(t.buffer,A,t.buffer.byteLength-A));for(var C=0,_=b;_<A;_+=188)if(71===t[_]){var x=!!(64&t[_+1]),P=s(t,_),F=(48&t[_+3])>>4,O=void 0;if(!(1<F))O=_+4;else if(O=_+5+t[_+4],O===_+188)continue;switch(P){case f:x&&(T&&(R=d(T))&&this.parseAVCPES(l,g,R,!1),T={data:[],size:0}),T&&(T.data.push(t.subarray(O,_+188)),T.size+=_+188-O);break;case h:if(x){if(v&&(R=d(v)))switch(u.segmentCodec){case"aac":this.parseAACPES(u,R);break;case"mp3":this.parseMPEGPES(u,R);}v={data:[],size:0}}v&&(v.data.push(t.subarray(O,_+188)),v.size+=_+188-O);break;case S:x&&(L&&(R=d(L))&&this.parseID3PES(c,R),L={data:[],size:0}),L&&(L.data.push(t.subarray(O,_+188)),L.size+=_+188-O);break;case 0:x&&(O+=t[O]+1),I=this._pmtId=i(t,O);break;case I:{x&&(O+=t[O]+1);var N=o(t,O,this.typeSupported,a);f=N.avc,0<f&&(l.pid=f),h=N.audio,0<h&&(u.pid=h,u.segmentCodec=N.segmentCodec),S=N.id3,0<S&&(c.pid=S),null===D||k||(y.logger.warn("MPEG-TS PMT found at "+_+" after unknown PID '"+D+"'. Backtracking to sync byte @"+b+" to parse all TS packets."),D=null,_=b-188),k=this.pmtParsed=!0;break}case 17:case 8191:break;default:D=P;}}else C++;0<C&&this.observer.emit(m.Events.ERROR,m.Events.ERROR,{type:E.ErrorTypes.MEDIA_ERROR,details:E.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"Found "+C+" TS packet/s that do not start with 0x47"}),l.pesData=T,u.pesData=v,c.pesData=L;var w={audioTrack:u,videoTrack:l,id3Track:c,textTrack:g};return n&&this.extractRemainingSamples(w),w},t.flush=function(){var e=this.remainderData;this.remainderData=null;var t;return t=e?this.demux(e,-1,!1,!0):{videoTrack:this._avcTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(t),this.sampleAes?this.decrypt(t,this.sampleAes):t},t.extractRemainingSamples=function(e){var t=e.audioTrack,r=e.videoTrack,a=e.id3Track,n=e.textTrack,s=r.pesData,i=t.pesData,o=a.pesData,l;if(s&&(l=d(s))?(this.parseAVCPES(r,n,l,!0),r.pesData=null):r.pesData=s,i&&(l=d(i))){switch(t.segmentCodec){case"aac":this.parseAACPES(t,l);break;case"mp3":this.parseMPEGPES(t,l);}t.pesData=null}else null!==i&&void 0!==i&&i.size&&y.logger.log("last AAC PES packet truncated,might overlap between fragments"),t.pesData=i;o&&(l=d(o))?(this.parseID3PES(a,l),a.pesData=null):a.pesData=o},t.demuxSampleAes=function(e,t,r){var a=this.demux(e,r,!0,!this.config.progressive),n=this.sampleAes=new f["default"](this.observer,this.config,t);return this.decrypt(a,n)},t.decrypt=function(e,t){return new Promise(function(r){var a=e.audioTrack,n=e.videoTrack;a.samples&&"aac"===a.segmentCodec?t.decryptAacSamples(a.samples,0,function(){n.samples?t.decryptAvcSamples(n.samples,0,0,function(){r(e)}):r(e)}):n.samples&&t.decryptAvcSamples(n.samples,0,0,function(){r(e)})})},t.destroy=function(){this._duration=0},t.parseAVCPES=function(e,t,r,a){var s=this,i=this.parseAVCNALu(e,r.data),o=this.avcSample,d=!1,u;r.data=null,o&&i.length&&!e.audFound&&(l(o,e),o=this.avcSample=n(!1,r.pts,r.dts,"")),i.forEach(function(a){switch(a.type){case 1:{u=!0,o||(o=s.avcSample=n(!0,r.pts,r.dts,"")),!1,o.frame=!0;var c=a.data;if(d&&4<c.length){var f=new g["default"](c).readSliceType();(2===f||4===f||7===f||9===f)&&(o.key=!0)}break}case 5:u=!0,o||(o=s.avcSample=n(!0,r.pts,r.dts,"")),!1,o.key=!0,o.frame=!0;break;case 6:{u=!0,!1,(0,p.parseSEIMessageFromNALu)(a.data,1,r.pts,t.samples);break}case 7:if(u=!0,d=!0,!1,!e.sps){var m=new g["default"](a.data),y=m.readSPS();e.width=y.width,e.height=y.height,e.pixelRatio=y.pixelRatio,e.sps=[a.data],e.duration=s._duration;for(var E=a.data.subarray(1,4),T="avc1.",S=0,v;3>S;S++)v=E[S].toString(16),2>v.length&&(v="0"+v),T+=v;e.codec=T}break;case 8:u=!0,!1,e.pps||(e.pps=[a.data]);break;case 9:u=!1,e.audFound=!0,o&&l(o,e),o=s.avcSample=n(!1,r.pts,r.dts,"");break;case 12:u=!0;break;default:u=!1,o&&(o.debug+="unknown NAL "+a.type+" ");}if(o&&u){var L=o.units;L.push(a)}}),a&&o&&(l(o,e),this.avcSample=null)},t.getLastNalUnit=function(e){var t=this.avcSample,r,a;if(t&&0!==t.units.length||(t=e[e.length-1]),null!==(r=t)&&void 0!==r&&r.units){var n=t.units;a=n[n.length-1]}return a},t.parseAVCNALu=function(e,t){var r=t.byteLength,a=e.naluState||0,n=a,s=[],o=0,d=-1,l=0,u,c,g;for(-1===a&&(d=0,l=31&t[0],a=0,o=1);o<r;){if(u=t[o++],!a){a=u?0:1;continue}if(1===a){a=u?0:2;continue}if(!u)a=3;else if(1===u){if(0<=d){var f={data:t.subarray(d,o-a-1),type:l};s.push(f)}else{var m=this.getLastNalUnit(e.samples);if(m&&(n&&o<=4-n&&m.state&&(m.data=m.data.subarray(0,m.data.byteLength-n)),c=o-a-1,0<c)){var p=new Uint8Array(m.data.byteLength+c);p.set(m.data,0),p.set(t.subarray(0,c),m.data.byteLength),m.data=p,m.state=0}}o<r?(g=31&t[o],d=o,l=g,a=0):a=-1}else a=0}if(0<=d&&0<=a){var y={data:t.subarray(d,r),type:l,state:a};s.push(y)}if(0===s.length){var E=this.getLastNalUnit(e.samples);if(E){var T=new Uint8Array(E.data.byteLength+t.byteLength);T.set(E.data,0),T.set(t,E.data.byteLength),E.data=T}}return e.naluState=a,s},t.parseAACPES=function(e,t){var r=0,a=this.aacOverFlow,n=t.data;if(a){this.aacOverFlow=null;var s=a.missing,i=a.sample.unit.byteLength;if(-1===s){var o=new Uint8Array(i+n.byteLength);o.set(a.sample.unit,0),o.set(n,i),n=o}else{a.sample.unit.set(n.subarray(0,s),i-s),e.samples.push(a.sample),r=a.missing}}var d,l;for(d=r,l=n.length;d<l-1&&!u.isHeader(n,d);d++);if(d!==r){var c,g;if(d<l-1?(c="AAC PES did not start with ADTS header,offset:"+d,g=!1):(c="no ADTS header found in AAC PES",g=!0),y.logger.warn("parsing error:"+c),this.observer.emit(m.Events.ERROR,m.Events.ERROR,{type:E.ErrorTypes.MEDIA_ERROR,details:E.ErrorDetails.FRAG_PARSING_ERROR,fatal:g,reason:c}),g)return}u.initTrackConfig(e,this.observer,n,d,this.audioCodec);var f;if(void 0!==t.pts)f=t.pts;else if(a){var p=u.getFrameDuration(e.samplerate);f=a.sample.pts+p}else return void y.logger.warn("[tsdemuxer]: AAC PES unknown PTS");for(var T=0,h;d<l;)if(h=u.appendFrame(e,n,d,f,T),d+=h.length,!h.missing)for(T++;d<l-1&&!u.isHeader(n,d);d++);else{this.aacOverFlow=h;break}},t.parseMPEGPES=function(e,t){var r=t.data,a=r.length,n=0,s=0,i=t.pts;if(void 0===i)return void y.logger.warn("[tsdemuxer]: MPEG PES unknown PTS");for(;s<a;)if(c.isHeader(r,s)){var o=c.appendFrame(e,r,s,i,n);if(o)s+=o.length,n++;else break}else s++},t.parseID3PES=function(e,t){if(void 0===t.pts)return void y.logger.warn("[tsdemuxer]: ID3 PES unknown PTS");var r=a({},t,{type:this._avcTrack?T.MetadataSchema.emsg:T.MetadataSchema.audioId3,duration:Number.POSITIVE_INFINITY});e.samples.push(r)},e}();const S=h},"./src/demux/webworkify-webpack.js":(e,t,r)=>{"use strict";function a(e){return(e+"").replace(/[.?*+^$[\]\\(){}|-]/g,"\\$&")}function n(e){return!isNaN(1*e)}function s(e,t,s){var o={};o[s]=[];var d=t.toString().replace(/^"[^"]+"/,"function"),l=d.match(/^function\s?\w*\(\w+,\s*\w+,\s*(\w+)\)/)||d.match(/^\(\w+,\s*\w+,\s*(\w+)\)\s?\=\s?\>/);if(!l)return o;for(var u=l[1],c=new RegExp("(\\\\n|\\W)"+a(u)+"\\(\\s*(/\\*.*?\\*/)?\\s*.*?([\\.|\\-|\\+|\\w|/|@]+).*?\\)","g"),g;g=c.exec(d);)"dll-reference"!==g[3]&&o[s].push(g[3]);for(c=new RegExp("\\("+a(u)+"\\(\"(dll-reference\\s([\\.|\\-|\\+|\\w|/|@]+))\"\\)\\)\\(\\s*(/\\*.*?\\*/)?\\s*.*?([\\.|\\-|\\+|\\w|/|@]+).*?\\)","g");g=c.exec(d);)e[g[2]]||(o[s].push(g[1]),e[g[2]]=r(g[1]).m),o[g[2]]=o[g[2]]||[],o[g[2]].push(g[4]);for(var f=Object.keys(o),m=0;m<f.length;m++)for(var p=0;p<o[f[m]].length;p++)n(o[f[m]][p])&&(o[f[m]][p]=1*o[f[m]][p]);return o}function o(e){var t=Object.keys(e);return t.reduce(function(t,r){return t||0<e[r].length},!1)}function d(e,t){for(var r={main:[t]},a={main:[]},n={main:{}};o(r);)for(var d=Object.keys(r),l=0;l<d.length;l++){var u=d[l],c=r[u],g=c.pop();if(n[u]=n[u]||{},!n[u][g]&&e[u][g]){n[u][g]=!0,a[u]=a[u]||[],a[u].push(g);for(var f=s(e,e[u][g],u),m=Object.keys(f),p=0;p<m.length;p++)r[m[p]]=r[m[p]]||[],r[m[p]]=r[m[p]].concat(f[m[p]])}}return a}function l(e,t,r,a){var n=e[a].map(function(e){return"\""+e+"\": "+t[a][e].toString().replace(/^"[^"]+"/,"function")}).join(",");return c[0]+"{"+n+"}"+c[1]+"\""+r+"\""+c[2]}function u(e,t){t=t||{};var a={main:r.m},n=t.all?{main:Object.keys(a.main)}:d(a,e),s="";Object.keys(n).filter(function(e){return"main"!==e}).forEach(function(e){for(var t=0;n[e][t];)t++;n[e].push(t),a[e][t]="(function(module, exports, __webpack_require__) { module.exports = __webpack_require__; })",s+="var "+e+" = ("+l(n,a,t,modules)+")();\n"}),s+="new (("+l(n,a,e,"main")+")())(self);";var i=new window.Blob([s],{type:"text/javascript"}),o=window.URL||window.webkitURL||window.mozURL||window.msURL,u=o.createObjectURL(i),c=new window.Worker(u);return c.objectURL=u,c}r.r(t),r.d(t,{default:()=>u});var c=function(){var e=ENTRY_MODULE,t={},r=function r(a){var n=t[a];if(void 0!==n)return n.exports;var s=t[a]={exports:{}};return e[a].call(s.exports,s,s.exports,r),s.exports};r.m=e,function(){r.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return r.d(t,{a:t}),t}}(),function(){r.d=function(e,t){for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})}}(),function(){r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}}(),function(){r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}}();var a=r(ENTRY_MODULE);return a.default||a}.toString().split("ENTRY_MODULE")},"./src/errors.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{ErrorDetails:()=>n,ErrorTypes:()=>a});var a;(function(e){e.NETWORK_ERROR="networkError",e.MEDIA_ERROR="mediaError",e.KEY_SYSTEM_ERROR="keySystemError",e.MUX_ERROR="muxError",e.OTHER_ERROR="otherError"})(a||(a={}));var n;(function(e){e.KEY_SYSTEM_NO_KEYS="keySystemNoKeys",e.KEY_SYSTEM_NO_ACCESS="keySystemNoAccess",e.KEY_SYSTEM_NO_SESSION="keySystemNoSession",e.KEY_SYSTEM_NO_CONFIGURED_LICENSE="keySystemNoConfiguredLicense",e.KEY_SYSTEM_LICENSE_REQUEST_FAILED="keySystemLicenseRequestFailed",e.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED="keySystemServerCertificateRequestFailed",e.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED="keySystemServerCertificateUpdateFailed",e.KEY_SYSTEM_SESSION_UPDATE_FAILED="keySystemSessionUpdateFailed",e.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED="keySystemStatusOutputRestricted",e.KEY_SYSTEM_STATUS_INTERNAL_ERROR="keySystemStatusInternalError",e.MANIFEST_LOAD_ERROR="manifestLoadError",e.MANIFEST_LOAD_TIMEOUT="manifestLoadTimeOut",e.MANIFEST_PARSING_ERROR="manifestParsingError",e.MANIFEST_INCOMPATIBLE_CODECS_ERROR="manifestIncompatibleCodecsError",e.LEVEL_EMPTY_ERROR="levelEmptyError",e.LEVEL_LOAD_ERROR="levelLoadError",e.LEVEL_LOAD_TIMEOUT="levelLoadTimeOut",e.LEVEL_SWITCH_ERROR="levelSwitchError",e.AUDIO_TRACK_LOAD_ERROR="audioTrackLoadError",e.AUDIO_TRACK_LOAD_TIMEOUT="audioTrackLoadTimeOut",e.SUBTITLE_LOAD_ERROR="subtitleTrackLoadError",e.SUBTITLE_TRACK_LOAD_TIMEOUT="subtitleTrackLoadTimeOut",e.FRAG_LOAD_ERROR="fragLoadError",e.FRAG_LOAD_TIMEOUT="fragLoadTimeOut",e.FRAG_DECRYPT_ERROR="fragDecryptError",e.FRAG_PARSING_ERROR="fragParsingError",e.REMUX_ALLOC_ERROR="remuxAllocError",e.KEY_LOAD_ERROR="keyLoadError",e.KEY_LOAD_TIMEOUT="keyLoadTimeOut",e.BUFFER_ADD_CODEC_ERROR="bufferAddCodecError",e.BUFFER_INCOMPATIBLE_CODECS_ERROR="bufferIncompatibleCodecsError",e.BUFFER_APPEND_ERROR="bufferAppendError",e.BUFFER_APPENDING_ERROR="bufferAppendingError",e.BUFFER_STALLED_ERROR="bufferStalledError",e.BUFFER_FULL_ERROR="bufferFullError",e.BUFFER_SEEK_OVER_HOLE="bufferSeekOverHole",e.BUFFER_NUDGE_ON_STALL="bufferNudgeOnStall",e.INTERNAL_EXCEPTION="internalException",e.INTERNAL_ABORTED="aborted",e.UNKNOWN="unknown"})(n||(n={}))},"./src/events.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{Events:()=>a});var a;(function(e){e.MEDIA_ATTACHING="hlsMediaAttaching",e.MEDIA_ATTACHED="hlsMediaAttached",e.MEDIA_DETACHING="hlsMediaDetaching",e.MEDIA_DETACHED="hlsMediaDetached",e.BUFFER_RESET="hlsBufferReset",e.BUFFER_CODECS="hlsBufferCodecs",e.BUFFER_CREATED="hlsBufferCreated",e.BUFFER_APPENDING="hlsBufferAppending",e.BUFFER_APPENDED="hlsBufferAppended",e.BUFFER_EOS="hlsBufferEos",e.BUFFER_FLUSHING="hlsBufferFlushing",e.BUFFER_FLUSHED="hlsBufferFlushed",e.MANIFEST_LOADING="hlsManifestLoading",e.MANIFEST_LOADED="hlsManifestLoaded",e.MANIFEST_PARSED="hlsManifestParsed",e.LEVEL_SWITCHING="hlsLevelSwitching",e.LEVEL_SWITCHED="hlsLevelSwitched",e.LEVEL_LOADING="hlsLevelLoading",e.LEVEL_LOADED="hlsLevelLoaded",e.LEVEL_UPDATED="hlsLevelUpdated",e.LEVEL_PTS_UPDATED="hlsLevelPtsUpdated",e.LEVELS_UPDATED="hlsLevelsUpdated",e.AUDIO_TRACKS_UPDATED="hlsAudioTracksUpdated",e.AUDIO_TRACK_SWITCHING="hlsAudioTrackSwitching",e.AUDIO_TRACK_SWITCHED="hlsAudioTrackSwitched",e.AUDIO_TRACK_LOADING="hlsAudioTrackLoading",e.AUDIO_TRACK_LOADED="hlsAudioTrackLoaded",e.SUBTITLE_TRACKS_UPDATED="hlsSubtitleTracksUpdated",e.SUBTITLE_TRACKS_CLEARED="hlsSubtitleTracksCleared",e.SUBTITLE_TRACK_SWITCH="hlsSubtitleTrackSwitch",e.SUBTITLE_TRACK_LOADING="hlsSubtitleTrackLoading",e.SUBTITLE_TRACK_LOADED="hlsSubtitleTrackLoaded",e.SUBTITLE_FRAG_PROCESSED="hlsSubtitleFragProcessed",e.CUES_PARSED="hlsCuesParsed",e.NON_NATIVE_TEXT_TRACKS_FOUND="hlsNonNativeTextTracksFound",e.INIT_PTS_FOUND="hlsInitPtsFound",e.FRAG_LOADING="hlsFragLoading",e.FRAG_LOAD_EMERGENCY_ABORTED="hlsFragLoadEmergencyAborted",e.FRAG_LOADED="hlsFragLoaded",e.FRAG_DECRYPTED="hlsFragDecrypted",e.FRAG_PARSING_INIT_SEGMENT="hlsFragParsingInitSegment",e.FRAG_PARSING_USERDATA="hlsFragParsingUserdata",e.FRAG_PARSING_METADATA="hlsFragParsingMetadata",e.FRAG_PARSED="hlsFragParsed",e.FRAG_BUFFERED="hlsFragBuffered",e.FRAG_CHANGED="hlsFragChanged",e.FPS_DROP="hlsFpsDrop",e.FPS_DROP_LEVEL_CAPPING="hlsFpsDropLevelCapping",e.ERROR="hlsError",e.DESTROYING="hlsDestroying",e.KEY_LOADING="hlsKeyLoading",e.KEY_LOADED="hlsKeyLoaded",e.LIVE_BACK_BUFFER_REACHED="hlsLiveBackBufferReached",e.BACK_BUFFER_REACHED="hlsBackBufferReached"})(a||(a={}))},"./src/hls.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{default:()=>k});var o=r("./node_modules/url-toolkit/src/url-toolkit.js"),d=r.n(o),l=r("./src/loader/playlist-loader.ts"),u=r("./src/controller/id3-track-controller.ts"),c=r("./src/controller/latency-controller.ts"),g=r("./src/controller/level-controller.ts"),f=r("./src/controller/fragment-tracker.ts"),m=r("./src/loader/key-loader.ts"),p=r("./src/controller/stream-controller.ts"),y=r("./src/is-supported.ts"),E=r("./src/utils/logger.ts"),T=r("./src/config.ts"),h=r("./node_modules/eventemitter3/index.js"),S=r.n(h),v=r("./src/events.ts"),L=r("./src/errors.ts"),D=r("./src/types/level.ts"),k=function(){function e(t){void 0===t&&(t={}),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this._emitter=new h.EventEmitter,this._autoLevelCapping=void 0,this._maxHdcpLevel=null,this.abrController=void 0,this.bufferController=void 0,this.capLevelController=void 0,this.latencyController=void 0,this.levelController=void 0,this.streamController=void 0,this.audioTrackController=void 0,this.subtitleTrackController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this.url=null;var r=this.config=(0,T.mergeConfig)(e.DefaultConfig,t);this.userConfig=t,(0,E.enableLogs)(r.debug,"Hls instance"),this._autoLevelCapping=-1,r.progressive&&(0,T.enableStreamingMode)(r);var a=r.abrController,n=r.bufferController,s=r.capLevelController,i=r.fpsController,o=this.abrController=new a(this),d=this.bufferController=new n(this),y=this.capLevelController=new s(this),S=new i(this),v=new l["default"](this),L=new u["default"](this),D=this.levelController=new g["default"](this),k=new f.FragmentTracker(this),I=new m["default"](this.config),A=this.streamController=new p["default"](this,k,I);y.setStreamController(A),S.setStreamController(A);var R=[v,D,A];this.networkControllers=R;var b=[o,d,y,S,L,k];this.audioTrackController=this.createController(r.audioTrackController,R);var C=r.audioStreamController;C&&R.push(new C(this,k,I)),this.subtitleTrackController=this.createController(r.subtitleTrackController,R);var _=r.subtitleStreamController;_&&R.push(new _(this,k,I)),this.createController(r.timelineController,b),I.emeController=this.emeController=this.createController(r.emeController,b),this.cmcdController=this.createController(r.cmcdController,b),this.latencyController=this.createController(c["default"],b),this.coreComponents=b}e.isSupported=function(){return(0,y.isSupported)()};var t=e.prototype;return t.createController=function(e,t){if(e){var r=new e(this);return t&&t.push(r),r}return null},t.on=function(e,t,r){void 0===r&&(r=this),this._emitter.on(e,t,r)},t.once=function(e,t,r){void 0===r&&(r=this),this._emitter.once(e,t,r)},t.removeAllListeners=function(e){this._emitter.removeAllListeners(e)},t.off=function(e,t,r,a){void 0===r&&(r=this),this._emitter.off(e,t,r,a)},t.listeners=function(e){return this._emitter.listeners(e)},t.emit=function(e,t,r){return this._emitter.emit(e,t,r)},t.trigger=function(t,r){if(this.config.debug)return this.emit(t,t,r);try{return this.emit(t,t,r)}catch(r){E.logger.error("An internal error happened while handling event "+t+". Error message: \""+r.message+"\". Here is a stacktrace:",r),this.trigger(v.Events.ERROR,{type:L.ErrorTypes.OTHER_ERROR,details:L.ErrorDetails.INTERNAL_EXCEPTION,fatal:!1,event:t,error:r})}return!1},t.listenerCount=function(e){return this._emitter.listenerCount(e)},t.destroy=function(){E.logger.log("destroy"),this.trigger(v.Events.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach(function(e){return e.destroy()}),this.networkControllers.length=0,this.coreComponents.forEach(function(e){return e.destroy()}),this.coreComponents.length=0},t.attachMedia=function(e){E.logger.log("attachMedia"),this._media=e,this.trigger(v.Events.MEDIA_ATTACHING,{media:e})},t.detachMedia=function(){E.logger.log("detachMedia"),this.trigger(v.Events.MEDIA_DETACHING,void 0),this._media=null},t.loadSource=function(e){this.stopLoad();var t=this.media,r=this.url,a=this.url=o.buildAbsoluteURL(self.location.href,e,{alwaysNormalize:!0});E.logger.log("loadSource:"+a),t&&r&&r!==a&&this.bufferController.hasSourceTypes()&&(this.detachMedia(),this.attachMedia(t)),this.trigger(v.Events.MANIFEST_LOADING,{url:e})},t.startLoad=function(e){void 0===e&&(e=-1),E.logger.log("startLoad("+e+")"),this.networkControllers.forEach(function(t){t.startLoad(e)})},t.stopLoad=function(){E.logger.log("stopLoad"),this.networkControllers.forEach(function(e){e.stopLoad()})},t.swapAudioCodec=function(){E.logger.log("swapAudioCodec"),this.streamController.swapAudioCodec()},t.recoverMediaError=function(){E.logger.log("recoverMediaError");var e=this._media;this.detachMedia(),e&&this.attachMedia(e)},t.removeLevel=function(e,t){void 0===t&&(t=0),this.levelController.removeLevel(e,t)},n(e,[{key:"levels",get:function(){var e=this.levelController.levels;return e?e:[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(e){E.logger.log("set currentLevel:"+e),this.loadLevel=e,this.abrController.clearTimer(),this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(e){E.logger.log("set nextLevel:"+e),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(e){E.logger.log("set loadLevel:"+e),this.levelController.manualLevel=e}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(e){this.levelController.nextLoadLevel=e}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(e){E.logger.log("set firstLevel:"+e),this.levelController.firstLevel=e}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(e){E.logger.log("set startLevel:"+e),-1!==e&&(e=Math.max(e,this.minAutoLevel)),this.levelController.startLevel=e}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(e){var t=!!e;t!==this.config.capLevelToPlayerSize&&(t?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=t)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping!==e&&(E.logger.log("set autoLevelCapping:"+e),this._autoLevelCapping=e)}},{key:"bandwidthEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimate():NaN}},{key:"maxHdcpLevel",get:function(){return this._maxHdcpLevel},set:function(e){-1<D.HdcpLevels.indexOf(e)&&(this._maxHdcpLevel=e)}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var e=this.levels,t=this.config.minAutoBitrate;if(!e)return 0;for(var r=e.length,a=0;a<r;a++)if(e[a].maxBitrate>=t)return a;return 0}},{key:"maxAutoLevel",get:function(){var e=this.levels,t=this.autoLevelCapping,r=this.maxHdcpLevel,a;if(a=-1===t&&e&&e.length?e.length-1:t,r)for(var n=a,s;n--;)if(s=e[n].attrs["HDCP-LEVEL"],s&&s<=r)return n;return a}},{key:"nextAutoLevel",get:function(){return Math.min(Math.max(this.abrController.nextAutoLevel,this.minAutoLevel),this.maxAutoLevel)},set:function(e){this.abrController.nextAutoLevel=Math.max(this.minAutoLevel,e)}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"mainForwardBufferInfo",get:function(){return this.streamController.getMainFwdBufferInfo()}},{key:"audioTracks",get:function(){var e=this.audioTrackController;return e?e.audioTracks:[]}},{key:"audioTrack",get:function(){var e=this.audioTrackController;return e?e.audioTrack:-1},set:function(e){var t=this.audioTrackController;t&&(t.audioTrack=e)}},{key:"subtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTrack:-1},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var e=this.subtitleTrackController;return!!e&&e.subtitleDisplay},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(e){this.config.lowLatencyMode=e}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}}],[{key:"version",get:function(){return"1.3.4"}},{key:"Events",get:function(){return v.Events}},{key:"ErrorTypes",get:function(){return L.ErrorTypes}},{key:"ErrorDetails",get:function(){return L.ErrorDetails}},{key:"DefaultConfig",get:function(){return e.defaultConfig?e.defaultConfig:T.hlsDefaultConfig},set:function(t){e.defaultConfig=t}}]),e}();k.defaultConfig=void 0},"./src/is-supported.ts":(e,t,r)=>{"use strict";function a(){return self.SourceBuffer||self.WebKitSourceBuffer}function n(){var e=(0,i.getMediaSource)();if(!e)return!1;var t=a(),r=e&&"function"==typeof e.isTypeSupported&&e.isTypeSupported("video/mp4; codecs=\"avc1.42E01E,mp4a.40.2\""),n=!t||t.prototype&&"function"==typeof t.prototype.appendBuffer&&"function"==typeof t.prototype.remove;return!!r&&!!n}function s(){var e=a(),t;return"function"==typeof(null===e||void 0===e||null===(t=e.prototype)||void 0===t?void 0:t.changeType)}r.r(t),r.d(t,{changeTypeSupported:()=>s,isSupported:()=>n});var i=r("./src/utils/mediasource-helper.ts")},"./src/loader/date-range.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,o(a.key),a)}function s(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e){var t=d(e,"string");return"symbol"==typeof t?t:t+""}function d(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{DateRange:()=>f,DateRangeAttribute:()=>g});var l=r("./src/polyfills/number.ts"),u=r("./src/utils/attr-list.ts"),c=r("./src/utils/logger.ts"),g;(function(e){e.ID="ID",e.CLASS="CLASS",e.START_DATE="START-DATE",e.DURATION="DURATION",e.END_DATE="END-DATE",e.END_ON_NEXT="END-ON-NEXT",e.PLANNED_DURATION="PLANNED-DURATION",e.SCTE35_OUT="SCTE35-OUT",e.SCTE35_IN="SCTE35-IN"})(g||(g={}));var f=function(){function e(e,t){if(this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,t){var r=t.attr;for(var n in r)if(Object.prototype.hasOwnProperty.call(e,n)&&e[n]!==r[n]){c.logger.warn("DATERANGE tag attribute: \""+n+"\" does not match for tags with ID: \""+e.ID+"\""),this._badValueForSameId=n;break}e=a(new u.AttrList({}),r,e)}if(this.attr=e,this._startDate=new Date(e[g.START_DATE]),g.END_DATE in this.attr){var s=new Date(this.attr[g.END_DATE]);(0,l.isFiniteNumber)(s.getTime())&&(this._endDate=s)}}return s(e,[{key:"id",get:function(){return this.attr.ID}},{key:"class",get:function(){return this.attr.CLASS}},{key:"startDate",get:function(){return this._startDate}},{key:"endDate",get:function(){if(this._endDate)return this._endDate;var e=this.duration;return null===e?null:new Date(this._startDate.getTime()+1e3*e)}},{key:"duration",get:function(){if(g.DURATION in this.attr){var e=this.attr.decimalFloatingPoint(g.DURATION);if((0,l.isFiniteNumber)(e))return e}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}},{key:"plannedDuration",get:function(){return g.PLANNED_DURATION in this.attr?this.attr.decimalFloatingPoint(g.PLANNED_DURATION):null}},{key:"endOnNext",get:function(){return this.attr.bool(g.END_ON_NEXT)}},{key:"isValid",get:function(){return!!this.id&&!this._badValueForSameId&&(0,l.isFiniteNumber)(this.startDate.getTime())&&(null===this.duration||0<=this.duration)&&(!this.endOnNext||!!this.class)}}]),e}()},"./src/loader/fragment-loader.ts":(e,t,r)=>{"use strict";function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function n(e){var t="function"==typeof Map?new Map:void 0;return n=function(e){function r(){return s(e,arguments,l(this).constructor)}if(null===e||!o(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof t){if(t.has(e))return t.get(e);t.set(e,r)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},n(e)}function s(){return s=i()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var a=Function.bind.apply(e,n),s=new a;return r&&d(s,r.prototype),s},s.apply(null,arguments)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function o(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function u(e,t){void 0===t&&(t=null);var r=t||e,a={frag:e,part:t,responseType:"arraybuffer",url:r.url,headers:{},rangeStart:0,rangeEnd:0},n=r.byteRangeStartOffset,s=r.byteRangeEndOffset;if((0,c.isFiniteNumber)(n)&&(0,c.isFiniteNumber)(s)){var i=n,o=s,d;if("initSegment"===e.sn&&"AES-128"===(null===(d=e.decryptdata)||void 0===d?void 0:d.method)){var l=s-n;l%16&&(o=s+(16-l%16)),0!==n&&(a.resetIV=!0,i=n-16)}a.rangeStart=i,a.rangeEnd=o}return a}r.r(t),r.d(t,{LoadError:()=>p,default:()=>m});var c=r("./src/polyfills/number.ts"),g=r("./src/errors.ts"),f=Math.pow(2,17),m=function(){function e(e){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=e}var t=e.prototype;return t.destroy=function(){this.loader&&(this.loader.destroy(),this.loader=null)},t.abort=function(){this.loader&&this.loader.abort()},t.load=function(e,t){var r=this,a=e.url;if(!a)return Promise.reject(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:e,networkDetails:null},"Fragment does not have a "+(a?"part list":"url")));this.abort();var n=this.config,s=n.fLoader,i=n.loader;return new Promise(function(a,o){r.loader&&r.loader.destroy();var d=r.loader=e.loader=s?new s(n):new i(n),l=u(e),c={timeout:n.fragLoadingTimeOut,maxRetry:0,retryDelay:0,maxRetryDelay:n.fragLoadingMaxRetryTimeout,highWaterMark:"initSegment"===e.sn?1/0:131072};e.stats=d.stats,d.load(l,c,{onSuccess:function(t,n,s,i){r.resetLoader(e,d);var o=t.data;s.resetIV&&e.decryptdata&&(e.decryptdata.iv=new Uint8Array(o.slice(0,16)),o=o.slice(16)),a({frag:e,part:null,payload:o,networkDetails:i})},onError:function(t,a,n){r.resetLoader(e,d),o(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:e,response:t,networkDetails:n}))},onAbort:function(t,a,n){r.resetLoader(e,d),o(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.INTERNAL_ABORTED,fatal:!1,frag:e,networkDetails:n}))},onTimeout:function(t,a,n){r.resetLoader(e,d),o(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,networkDetails:n}))},onProgress:function(r,a,n,s){t&&t({frag:e,part:null,payload:n,networkDetails:s})}})})},t.loadPart=function(e,t,r){var a=this;this.abort();var n=this.config,s=n.fLoader,i=n.loader;return new Promise(function(o,d){a.loader&&a.loader.destroy();var l=a.loader=e.loader=s?new s(n):new i(n),c=u(e,t),f={timeout:n.fragLoadingTimeOut,maxRetry:0,retryDelay:0,maxRetryDelay:n.fragLoadingMaxRetryTimeout,highWaterMark:131072};t.stats=l.stats,l.load(c,f,{onSuccess:function(n,s,i,d){a.resetLoader(e,l),a.updateStatsFromPart(e,t);var u={frag:e,part:t,payload:n.data,networkDetails:d};r(u),o(u)},onError:function(r,n,s){a.resetLoader(e,l),d(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:e,part:t,response:r,networkDetails:s}))},onAbort:function(r,n,s){e.stats.aborted=t.stats.aborted,a.resetLoader(e,l),d(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.INTERNAL_ABORTED,fatal:!1,frag:e,part:t,networkDetails:s}))},onTimeout:function(r,n,s){a.resetLoader(e,l),d(new p({type:g.ErrorTypes.NETWORK_ERROR,details:g.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,part:t,networkDetails:s}))}})})},t.updateStatsFromPart=function(e,t){var r=e.stats,a=t.stats,n=a.total;if(r.loaded+=a.loaded,n){var s=Math.round(e.duration/t.duration),i=Math.min(Math.round(r.loaded/n),s),o=(s-i)*Math.round(r.loaded/i);r.total=r.loaded+o}else r.total=Math.max(r.loaded,r.total);var d=r.loading,l=a.loading;d.start?d.first+=l.first-l.start:(d.start=l.start,d.first=l.first),d.end=l.end},t.resetLoader=function(e,t){e.loader=null,this.loader===t&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),t.destroy()},e}(),p=function(e){function t(t){for(var r=arguments.length,a=Array(1<r?r-1:0),n=1,s;n<r;n++)a[n-1]=arguments[n];return s=e.call.apply(e,[this].concat(a))||this,s.data=void 0,s.data=t,s}return a(t,e),t}(n(Error))},"./src/loader/fragment.ts":(e,t,r)=>{"use strict";function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,n(e,t)}function n(e,t){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},n(e,t)}function s(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,o(a.key),a)}function i(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e){var t=d(e,"string");return"symbol"==typeof t?t:t+""}function d(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{BaseSegment:()=>m,ElementaryStreamTypes:()=>f,Fragment:()=>p,Part:()=>y});var l=r("./src/polyfills/number.ts"),u=r("./node_modules/url-toolkit/src/url-toolkit.js"),c=r.n(u),g=r("./src/loader/load-stats.ts"),f;(function(e){e.AUDIO="audio",e.VIDEO="video",e.AUDIOVIDEO="audiovideo"})(f||(f={}));var m=function(){function e(e){var t;this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams=(t={},t[f.AUDIO]=null,t[f.VIDEO]=null,t[f.AUDIOVIDEO]=null,t),this.baseurl=e}var t=e.prototype;return t.setByteRange=function(e,t){var r=e.split("@",2),a=[];a[0]=1===r.length?t?t.byteRangeEndOffset:0:parseInt(r[1]),a[1]=parseInt(r[0])+a[0],this._byteRange=a},i(e,[{key:"byteRange",get:function(){return this._byteRange?this._byteRange:[]}},{key:"byteRangeStartOffset",get:function(){return this.byteRange[0]}},{key:"byteRangeEndOffset",get:function(){return this.byteRange[1]}},{key:"url",get:function(){return!this._url&&this.baseurl&&this.relurl&&(this._url=(0,u.buildAbsoluteURL)(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""},set:function(e){this._url=e}}]),e}(),p=function(e){function t(t,r){var a;return a=e.call(this,r)||this,a._decryptdata=null,a.rawProgramDateTime=null,a.programDateTime=null,a.tagList=[],a.duration=0,a.sn=0,a.levelkeys=void 0,a.type=void 0,a.loader=null,a.keyLoader=null,a.level=-1,a.cc=0,a.startPTS=void 0,a.endPTS=void 0,a.appendedPTS=void 0,a.startDTS=void 0,a.endDTS=void 0,a.start=0,a.deltaPTS=void 0,a.maxStartPTS=void 0,a.minEndPTS=void 0,a.stats=new g.LoadStats,a.urlId=0,a.data=void 0,a.bitrateTest=!1,a.title=null,a.initSegment=null,a.endList=void 0,a.type=t,a}a(t,e);var r=t.prototype;return r.setKeyFormat=function(e){if(this.levelkeys){var t=this.levelkeys[e];t&&!this._decryptdata&&(this._decryptdata=t.getDecryptData(this.sn))}},r.abortRequests=function(){var e,t;null===(e=this.loader)||void 0===e?void 0:e.abort(),null===(t=this.keyLoader)||void 0===t?void 0:t.abort()},r.setElementaryStreamInfo=function(e,t,r,a,n,s){void 0===s&&(s=!1);var i=this.elementaryStreams,o=i[e];return o?void(o.startPTS=Math.min(o.startPTS,t),o.endPTS=Math.max(o.endPTS,r),o.startDTS=Math.min(o.startDTS,a),o.endDTS=Math.max(o.endDTS,n)):void(i[e]={startPTS:t,endPTS:r,startDTS:a,endDTS:n,partial:s})},r.clearElementaryStreamInfo=function(){var e=this.elementaryStreams;e[f.AUDIO]=null,e[f.VIDEO]=null,e[f.AUDIOVIDEO]=null},i(t,[{key:"decryptdata",get:function(){var e=this.levelkeys;if(!e&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){var t=this.levelkeys.identity;if(t)this._decryptdata=t.getDecryptData(this.sn);else{var r=Object.keys(this.levelkeys);if(1===r.length)return this._decryptdata=this.levelkeys[r[0]].getDecryptData(this.sn)}}return this._decryptdata}},{key:"end",get:function(){return this.start+this.duration}},{key:"endProgramDateTime",get:function(){if(null===this.programDateTime)return null;if(!(0,l.isFiniteNumber)(this.programDateTime))return null;var e=(0,l.isFiniteNumber)(this.duration)?this.duration:0;return this.programDateTime+1e3*e}},{key:"encrypted",get:function(){var e;if(null!==(e=this._decryptdata)&&void 0!==e&&e.encrypted)return!0;if(this.levelkeys){var t=Object.keys(this.levelkeys),r=t.length;if(1<r||1===r&&this.levelkeys[t[0]].encrypted)return!0}return!1}}]),t}(m),y=function(e){function t(t,r,a,n,s){var i;i=e.call(this,a)||this,i.fragOffset=0,i.duration=0,i.gap=!1,i.independent=!1,i.relurl=void 0,i.fragment=void 0,i.index=void 0,i.stats=new g.LoadStats,i.duration=t.decimalFloatingPoint("DURATION"),i.gap=t.bool("GAP"),i.independent=t.bool("INDEPENDENT"),i.relurl=t.enumeratedString("URI"),i.fragment=r,i.index=n;var o=t.enumeratedString("BYTERANGE");return o&&i.setByteRange(o,s),s&&(i.fragOffset=s.fragOffset+s.duration),i}return a(t,e),i(t,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var e=this.elementaryStreams;return!!(e.audio||e.video||e.audiovideo)}}]),t}(m)},"./src/loader/key-loader.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>s});var a=r("./src/errors.ts"),n=r("./src/loader/fragment-loader.ts"),s=function(){function e(e){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=e}var t=e.prototype;return t.abort=function(){for(var e in this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e].loader;t&&t.abort()}},t.detach=function(){for(var e in this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e];(t.mediaKeySessionContext||t.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[e]}},t.destroy=function(){for(var e in this.detach(),this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e].loader;t&&t.destroy()}this.keyUriToKeyInfo={}},t.createKeyLoadError=function(e,t,r){return void 0===t&&(t=a.ErrorDetails.KEY_LOAD_ERROR),new n.LoadError({type:a.ErrorTypes.NETWORK_ERROR,details:t,fatal:!1,frag:e,networkDetails:r})},t.loadClear=function(e,t){var r=this;if(this.emeController&&this.config.emeEnabled)for(var a=e.sn,n=e.cc,s=function(e){var s=t[e];if(n<=s.cc&&("initSegment"===a||a<s.sn))return r.emeController.selectKeySystemFormat(s).then(function(e){s.setKeyFormat(e)}),"break"},o=0,d;o<t.length&&(d=s(o),"break"!==d);o++);},t.load=function(e){var t=this;return!e.decryptdata&&e.encrypted&&this.emeController?this.emeController.selectKeySystemFormat(e).then(function(r){return t.loadInternal(e,r)}):this.loadInternal(e)},t.loadInternal=function(e,t){var r,n;t&&e.setKeyFormat(t);var s=e.decryptdata;if(!s){var i=t?"Expected frag.decryptdata to be defined after setting format "+t:"Missing decryption data on fragment in onKeyLoading";return Promise.reject(this.createKeyLoadError(e,a.ErrorDetails.KEY_LOAD_ERROR,null,i))}var o=s.uri;if(!o)return Promise.reject(this.createKeyLoadError(e,a.ErrorDetails.KEY_LOAD_ERROR,null,"Invalid key URI: \""+o+"\""));var d=this.keyUriToKeyInfo[o];if(null!==(r=d)&&void 0!==r&&r.decryptdata.key)return s.key=d.decryptdata.key,Promise.resolve({frag:e,keyInfo:d});if(null!==(n=d)&&void 0!==n&&n.keyLoadPromise){var l;switch(null===(l=d.mediaKeySessionContext)||void 0===l?void 0:l.keyStatus){case void 0:case"status-pending":case"usable":case"usable-in-future":return d.keyLoadPromise.then(function(t){return s.key=t.keyInfo.decryptdata.key,{frag:e,keyInfo:d}});}}switch(d=this.keyUriToKeyInfo[o]={decryptdata:s,keyLoadPromise:null,loader:null,mediaKeySessionContext:null},s.method){case"ISO-23001-7":case"SAMPLE-AES":case"SAMPLE-AES-CENC":case"SAMPLE-AES-CTR":return"identity"===s.keyFormat?this.loadKeyHTTP(d,e):this.loadKeyEME(d,e);case"AES-128":return this.loadKeyHTTP(d,e);default:return Promise.reject(this.createKeyLoadError(e,a.ErrorDetails.KEY_LOAD_ERROR,null,"Key supplied with unsupported METHOD: \""+s.method+"\""));}},t.loadKeyEME=function(e,t){var r={frag:t,keyInfo:e};if(this.emeController&&this.config.emeEnabled){var a=this.emeController.loadKey(r);if(a)return(e.keyLoadPromise=a.then(function(t){return e.mediaKeySessionContext=t,r})).catch(function(t){throw e.keyLoadPromise=null,t})}return Promise.resolve(r)},t.loadKeyHTTP=function(e,t){var r=this,n=this.config,s=n.loader,i=new s(n);return t.keyLoader=e.loader=i,e.keyLoadPromise=new Promise(function(s,o){var d={keyInfo:e,frag:t,responseType:"arraybuffer",url:e.decryptdata.uri},l={timeout:n.fragLoadingTimeOut,maxRetry:0,retryDelay:n.fragLoadingRetryDelay,maxRetryDelay:n.fragLoadingMaxRetryTimeout,highWaterMark:0};i.load(d,l,{onSuccess:function(e,t,n,i){var d=n.frag,l=n.keyInfo,u=n.url;return d.decryptdata&&l===r.keyUriToKeyInfo[u]?void(l.decryptdata.key=d.decryptdata.key=new Uint8Array(e.data),d.keyLoader=null,l.loader=null,s({frag:d,keyInfo:l})):o(r.createKeyLoadError(d,a.ErrorDetails.KEY_LOAD_ERROR,i,"after key load, decryptdata unset or changed"))},onError:function(e,n,s){r.resetLoader(n),o(r.createKeyLoadError(t,a.ErrorDetails.KEY_LOAD_ERROR,s))},onTimeout:function(e,n,s){r.resetLoader(n),o(r.createKeyLoadError(t,a.ErrorDetails.KEY_LOAD_TIMEOUT,s))},onAbort:function(e,n,s){r.resetLoader(n),o(r.createKeyLoadError(t,a.ErrorDetails.INTERNAL_ABORTED,s))}})})},t.resetLoader=function(e){var t=e.frag,r=e.keyInfo,a=e.url,n=r.loader;t.keyLoader===n&&(t.keyLoader=null,r.loader=null),delete this.keyUriToKeyInfo[a],n&&n.destroy()},e}()},"./src/loader/level-details.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}r.r(t),r.d(t,{LevelDetails:()=>d});var o=r("./src/polyfills/number.ts"),d=function(){function e(e){this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.live=!0,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.availabilityDelay=void 0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=e}var t=e.prototype;return t.reloaded=function(e){if(!e)return this.advanced=!0,void(this.updated=!0);var t=this.lastPartSn-e.lastPartSn,r=this.lastPartIndex-e.lastPartIndex;this.updated=this.endSN!==e.endSN||!!r||!!t,this.advanced=this.endSN>e.endSN||0<t||0===t&&0<r,this.misses=this.updated||this.advanced?Math.floor(.6*e.misses):e.misses+1,this.availabilityDelay=e.availabilityDelay},n(e,[{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&(0,o.isFiniteNumber)(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||10}},{key:"drift",get:function(){var e=this.driftEndTime-this.driftStartTime;if(0<e){var t=this.driftEnd-this.driftStart;return 1e3*t/e}return 1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var e;return null!==(e=this.partList)&&void 0!==e&&e.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var e;return null!==(e=this.fragments)&&void 0!==e&&e.length?this.fragments[this.fragments.length-1].end:0}},{key:"age",get:function(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}},{key:"lastPartIndex",get:function(){var e;return null!==(e=this.partList)&&void 0!==e&&e.length?this.partList[this.partList.length-1].index:-1}},{key:"lastPartSn",get:function(){var e;return null!==(e=this.partList)&&void 0!==e&&e.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}]),e}()},"./src/loader/level-key.ts":(e,t,r)=>{"use strict";function a(e){for(var t=new Uint8Array(16),r=12;16>r;r++)t[r]=255&e>>8*(15-r);return t}r.r(t),r.d(t,{LevelKey:()=>u});var n=r("./src/utils/keysystem-util.ts"),s=r("./src/utils/mediakeys-helper.ts"),i=r("./src/utils/mp4-tools.ts"),o=r("./src/utils/logger.ts"),d=r("./src/utils/numeric-encoding-utils.ts"),l={},u=function(){function e(e,t,r,a,n){void 0===a&&(a=[1]),void 0===n&&(n=null),this.uri=void 0,this.method=void 0,this.keyFormat=void 0,this.keyFormatVersions=void 0,this.encrypted=void 0,this.isCommonEncryption=void 0,this.iv=null,this.key=null,this.keyId=null,this.pssh=null,this.method=e,this.uri=t,this.keyFormat=r,this.keyFormatVersions=a,this.iv=n,this.encrypted=!!e&&"NONE"!==e,this.isCommonEncryption=this.encrypted&&"AES-128"!==e}e.clearKeyUriToKeyIdMap=function(){l={}};var t=e.prototype;return t.isSupported=function(){if(this.method){if("AES-128"===this.method||"NONE"===this.method)return!0;switch(this.keyFormat){case"identity":return"SAMPLE-AES"===this.method;case s.KeySystemFormats.FAIRPLAY:case s.KeySystemFormats.WIDEVINE:case s.KeySystemFormats.PLAYREADY:case s.KeySystemFormats.CLEARKEY:return-1!==["ISO-23001-7","SAMPLE-AES","SAMPLE-AES-CENC","SAMPLE-AES-CTR"].indexOf(this.method);}}return!1},t.getDecryptData=function(t){if(!this.encrypted||!this.uri)return null;if("AES-128"===this.method&&this.uri&&!this.iv){"number"!=typeof t&&("AES-128"===this.method&&!this.iv&&o.logger.warn("missing IV for initialization segment with method=\""+this.method+"\" - compliance issue"),t=0);var r=a(t),u=new e(this.method,this.uri,"identity",this.keyFormatVersions,r);return u}var c=(0,n.convertDataUriToArrayBytes)(this.uri);if(c)switch(this.keyFormat){case s.KeySystemFormats.WIDEVINE:this.pssh=c,22<=c.length&&(this.keyId=c.subarray(c.length-22,c.length-6));break;case s.KeySystemFormats.PLAYREADY:{var g=new Uint8Array([154,4,240,121,152,64,66,134,171,146,230,91,224,136,95,149]);this.pssh=(0,i.mp4pssh)(g,null,c);var f=new Uint16Array(c.buffer,c.byteOffset,c.byteLength/2),m=String.fromCharCode.apply(null,Array.from(f)),p=m.substring(m.indexOf("<"),m.length),y=new DOMParser,E=y.parseFromString(p,"text/xml"),T=E.getElementsByTagName("KID")[0];if(T){var h=T.childNodes[0]?T.childNodes[0].nodeValue:T.getAttribute("VALUE");if(h){var S=(0,d.base64Decode)(h).subarray(0,16);(0,n.changeEndianness)(S),this.keyId=S}}break}default:{var v=c.subarray(0,16);if(16!==v.length){var L=new Uint8Array(16);L.set(v,16-v.length),v=L}this.keyId=v;break}}if(!this.keyId||16!==this.keyId.byteLength){var D=l[this.uri];if(!D){var k=Object.keys(l).length%Number.MAX_SAFE_INTEGER;D=new Uint8Array(16);var I=new DataView(D.buffer,12,4);I.setUint32(0,k),l[this.uri]=D}this.keyId=D}return this},e}()},"./src/loader/load-stats.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{LoadStats:()=>a});var a=function(){this.aborted=!1,this.loaded=0,this.retry=0,this.total=0,this.chunkCount=0,this.bwEstimate=0,this.loading={start:0,first:0,end:0},this.parsing={start:0,end:0},this.buffering={start:0,first:0,end:0}}},"./src/loader/m3u8-parser.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t){var r=new T.AttrList(e),a=null==(d=r.enumeratedString("METHOD"))?"":d,n=r.URI,s=r.hexadecimalInteger("IV"),i=r.enumeratedString("KEYFORMATVERSIONS"),o=null==(l=r.enumeratedString("KEYFORMAT"))?"identity":l,d,l;n&&r.IV&&!s&&h.logger.error("Invalid IV: "+r.IV);var u=n?I.resolve(n,t):"",c=(i?i:"1").split("/").map(Number).filter(Number.isFinite);return new E.LevelKey(a,u,o,c,s)}function s(e,t){["video","audio","text"].forEach(function(r){var a=e.filter(function(e){return(0,S.isCodecType)(e,r)});if(a.length){var n=a.filter(function(e){return 0===e.lastIndexOf("avc1",0)||0===e.lastIndexOf("mp4a",0)});t[r+"Codec"]=0<n.length?n[0]:a[0],e=e.filter(function(e){return-1===a.indexOf(e)})}}),t.unknownCodecs=e}function i(e,t,r){var a=t[r];a&&(e[r]=a)}function o(e,t){for(var r=e[t],a=t,n;a--;){if(n=e[a],!n)return;n.programDateTime=r.programDateTime-1e3*n.duration,r=n}}function d(e,t){e.rawProgramDateTime?e.programDateTime=Date.parse(e.rawProgramDateTime):null!==t&&void 0!==t&&t.programDateTime&&(e.programDateTime=t.endProgramDateTime),(0,c.isFiniteNumber)(e.programDateTime)||(e.programDateTime=null,e.rawProgramDateTime=null)}function l(e,t,r,a){e.relurl=t.URI,t.BYTERANGE&&e.setByteRange(t.BYTERANGE),e.level=r,e.sn="initSegment",a&&(e.levelkeys=a),e.initSegment=null}function u(e,t,r){e.levelkeys=t;var a=r.encryptedFragments;(!a.length||a[a.length-1].levelkeys!==t)&&Object.keys(t).some(function(e){return t[e].isCommonEncryption})&&a.push(e)}r.r(t),r.d(t,{default:()=>I});var c=r("./src/polyfills/number.ts"),g=r("./node_modules/url-toolkit/src/url-toolkit.js"),f=r.n(g),m=r("./src/loader/date-range.ts"),p=r("./src/loader/fragment.ts"),y=r("./src/loader/level-details.ts"),E=r("./src/loader/level-key.ts"),T=r("./src/utils/attr-list.ts"),h=r("./src/utils/logger.ts"),S=r("./src/utils/codecs.ts"),v=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-SESSION-DATA:([^\r\n]*)[\r\n]+|#EXT-X-SESSION-KEY:([^\n\r]*)[\r\n]+/g,L=/#EXT-X-MEDIA:(.*)/g,D=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[\S ]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),k=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),I=function(){function e(){}return e.findGroup=function(e,t){for(var r=0,a;r<e.length;r++)if(a=e[r],a.id===t)return a},e.convertAVC1ToAVCOTI=function(e){var t=e.split(".");if(2<t.length){var r=t.shift()+".";return r+=parseInt(t.shift()).toString(16),r+=("000"+parseInt(t.shift()).toString(16)).slice(-4),r}return e},e.resolve=function(e,t){return(0,g.buildAbsoluteURL)(t,e,{alwaysNormalize:!0})},e.parseMasterPlaylist=function(t,r){var a=[],i=[],o={},d=[],l=!1;v.lastIndex=0;for(var u;null!=(u=v.exec(t));)if(u[1]){var c=new T.AttrList(u[1]),g={attrs:c,bitrate:c.decimalInteger("AVERAGE-BANDWIDTH")||c.decimalInteger("BANDWIDTH"),name:c.NAME,url:e.resolve(u[2],r)},f=c.decimalResolution("RESOLUTION"),m;f&&(g.width=f.width,g.height=f.height),s((c.CODECS||"").split(/[ ,]+/).filter(function(e){return e}),g),g.videoCodec&&-1!==g.videoCodec.indexOf("avc1")&&(g.videoCodec=e.convertAVC1ToAVCOTI(g.videoCodec)),null!==(m=g.unknownCodecs)&&void 0!==m&&m.length||i.push(g),a.push(g)}else if(u[3]){var p=new T.AttrList(u[3]);p["DATA-ID"]&&(l=!0,o[p["DATA-ID"]]=p)}else if(u[4]){var y=u[4],E=n(y,r);E.encrypted&&E.isSupported()?d.push(E):h.logger.warn("[Keys] Ignoring invalid EXT-X-SESSION-KEY tag: \""+y+"\"")}var S=0<i.length&&i.length<a.length;return{levels:S?i:a,sessionData:l?o:null,sessionKeys:d.length?d:null}},e.parseMasterPlaylistMedia=function(t,r,a,n){void 0===n&&(n=[]);var s=[],o=0,d;for(L.lastIndex=0;null!==(d=L.exec(t));){var l=new T.AttrList(d[1]);if(l.TYPE===a){var u={attrs:l,bitrate:0,id:o++,groupId:l["GROUP-ID"],instreamId:l["INSTREAM-ID"],name:l.NAME||l.LANGUAGE||"",type:a,default:l.bool("DEFAULT"),autoselect:l.bool("AUTOSELECT"),forced:l.bool("FORCED"),lang:l.LANGUAGE,url:l.URI?e.resolve(l.URI,r):""};if(n.length){var c=e.findGroup(n,u.groupId)||n[0];i(u,c,"audioCodec"),i(u,c,"textCodec")}s.push(u)}}return s},e.parseLevelPlaylist=function(e,t,r,s,g){var f=new y.LevelDetails(t),E=f.fragments,S=null,v=0,L=0,I=0,A=0,R=null,b=new p.Fragment(s,t),C=-1,_=!1,x,P,F;for(D.lastIndex=0,f.m3u8=e;null!==(x=D.exec(e));){_&&(_=!1,b=new p.Fragment(s,t),b.start=I,b.sn=v,b.cc=A,b.level=r,S&&(b.initSegment=S,b.rawProgramDateTime=S.rawProgramDateTime,S.rawProgramDateTime=null));var O=x[1];if(O){b.duration=parseFloat(O);var N=(" "+x[2]).slice(1);b.title=N||null,b.tagList.push(N?["INF",O,N]:["INF",O])}else if(x[3])(0,c.isFiniteNumber)(b.duration)&&(b.start=I,F&&u(b,F,f),b.sn=v,b.level=r,b.cc=A,b.urlId=g,E.push(b),b.relurl=(" "+x[3]).slice(1),d(b,R),R=b,I+=b.duration,v++,L=0,_=!0);else if(x[4]){var w=(" "+x[4]).slice(1);R?b.setByteRange(w,R):b.setByteRange(w)}else if(x[5])b.rawProgramDateTime=(" "+x[5]).slice(1),b.tagList.push(["PROGRAM-DATE-TIME",b.rawProgramDateTime]),-1===C&&(C=E.length);else{if(x=x[0].match(k),!x){h.logger.warn("No matches on slow regex match for level playlist!");continue}for(P=1;P<x.length&&"undefined"==typeof x[P];P++);var M=(" "+x[P]).slice(1),B=(" "+x[P+1]).slice(1),U=x[P+2]?(" "+x[P+2]).slice(1):"";switch(M){case"PLAYLIST-TYPE":f.type=B.toUpperCase();break;case"MEDIA-SEQUENCE":v=f.startSN=parseInt(B);break;case"SKIP":{var G=new T.AttrList(B),K=G.decimalInteger("SKIPPED-SEGMENTS");if((0,c.isFiniteNumber)(K)){f.skippedSegments=K;for(var H=K;H--;)E.unshift(null);v+=K}var V=G.enumeratedString("RECENTLY-REMOVED-DATERANGES");V&&(f.recentlyRemovedDateranges=V.split("\t"));break}case"TARGETDURATION":f.targetduration=parseFloat(B);break;case"VERSION":f.version=parseInt(B);break;case"EXTM3U":break;case"ENDLIST":f.live=!1;break;case"#":(B||U)&&b.tagList.push(U?[B,U]:[B]);break;case"DISCONTINUITY":A++,b.tagList.push(["DIS"]);break;case"GAP":b.tagList.push([M]);break;case"BITRATE":b.tagList.push([M,B]);break;case"DATERANGE":{var Y=new T.AttrList(B),W=new m.DateRange(Y,f.dateRanges[Y.ID]);W.isValid||f.skippedSegments?f.dateRanges[W.id]=W:h.logger.warn("Ignoring invalid DATERANGE tag: \""+B+"\""),b.tagList.push(["EXT-X-DATERANGE",B]);break}case"DISCONTINUITY-SEQUENCE":A=parseInt(B);break;case"KEY":{var q=n(B,t);if(q.isSupported()){if("NONE"===q.method){F=void 0;break}F||(F={}),F[q.keyFormat]&&(F=a({},F)),F[q.keyFormat]=q}else h.logger.warn("[Keys] Ignoring invalid EXT-X-KEY tag: \""+B+"\"");break}case"START":{var j=new T.AttrList(B),z=j.decimalFloatingPoint("TIME-OFFSET");(0,c.isFiniteNumber)(z)&&(f.startTimeOffset=z);break}case"MAP":{var X=new T.AttrList(B);if(b.duration){var Q=new p.Fragment(s,t);l(Q,X,r,F),S=Q,b.initSegment=S,S.rawProgramDateTime&&!b.rawProgramDateTime&&(b.rawProgramDateTime=S.rawProgramDateTime)}else l(b,X,r,F),S=b,_=!0;break}case"SERVER-CONTROL":{var Z=new T.AttrList(B);f.canBlockReload=Z.bool("CAN-BLOCK-RELOAD"),f.canSkipUntil=Z.optionalFloat("CAN-SKIP-UNTIL",0),f.canSkipDateRanges=0<f.canSkipUntil&&Z.bool("CAN-SKIP-DATERANGES"),f.partHoldBack=Z.optionalFloat("PART-HOLD-BACK",0),f.holdBack=Z.optionalFloat("HOLD-BACK",0);break}case"PART-INF":{var $=new T.AttrList(B);f.partTarget=$.decimalFloatingPoint("PART-TARGET");break}case"PART":{var J=f.partList;J||(J=f.partList=[]);var ee=0<L?J[J.length-1]:void 0,te=L++,re=new p.Part(new T.AttrList(B),b,t,te,ee);J.push(re),b.duration+=re.duration;break}case"PRELOAD-HINT":{var ae=new T.AttrList(B);f.preloadHint=ae;break}case"RENDITION-REPORT":{var ne=new T.AttrList(B);f.renditionReports=f.renditionReports||[],f.renditionReports.push(ne);break}default:h.logger.warn("line parsed but not handled: "+x);}}}R&&!R.relurl?(E.pop(),I-=R.duration,f.partList&&(f.fragmentHint=R)):f.partList&&(d(b,R),b.cc=A,f.fragmentHint=b,F&&u(b,F,f));var se=E.length,ie=E[0],oe=E[se-1];if(I+=f.skippedSegments*f.targetduration,0<I&&se&&oe){f.averagetargetduration=I/se;var de=oe.sn;f.endSN="initSegment"===de?0:de,f.live||(oe.endList=!0),ie&&(f.startCC=ie.cc)}else f.endSN=0,f.startCC=0;return f.fragmentHint&&(I+=f.fragmentHint.duration),f.totalduration=I,f.endCC=A,0<C&&o(E,C),f},e}()},"./src/loader/playlist-loader.ts":(e,t,r)=>{"use strict";function a(e){var t=e.type;return t===u.PlaylistContextType.AUDIO_TRACK?u.PlaylistLevelType.AUDIO:t===u.PlaylistContextType.SUBTITLE_TRACK?u.PlaylistLevelType.SUBTITLE:u.PlaylistLevelType.MAIN}function n(e,t){var r=e.url;return(void 0===r||0===r.indexOf("data:"))&&(r=t.url),r}r.r(t),r.d(t,{default:()=>f});var s=r("./src/polyfills/number.ts"),i=r("./src/events.ts"),o=r("./src/errors.ts"),d=r("./src/utils/logger.ts"),l=r("./src/loader/m3u8-parser.ts"),u=r("./src/types/loader.ts"),c=r("./src/utils/attr-list.ts"),g=function(){function e(e){this.hls=void 0,this.loaders=Object.create(null),this.hls=e,this.registerListeners()}var t=e.prototype;return t.startLoad=function(){},t.stopLoad=function(){this.destroyInternalLoaders()},t.registerListeners=function(){var e=this.hls;e.on(i.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.on(i.Events.LEVEL_LOADING,this.onLevelLoading,this),e.on(i.Events.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.on(i.Events.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},t.unregisterListeners=function(){var e=this.hls;e.off(i.Events.MANIFEST_LOADING,this.onManifestLoading,this),e.off(i.Events.LEVEL_LOADING,this.onLevelLoading,this),e.off(i.Events.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.off(i.Events.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},t.createInternalLoader=function(e){var t=this.hls.config,r=t.pLoader,a=t.loader,n=new(r||a)(t);return e.loader=n,this.loaders[e.type]=n,n},t.getInternalLoader=function(e){return this.loaders[e.type]},t.resetInternalLoader=function(e){this.loaders[e]&&delete this.loaders[e]},t.destroyInternalLoaders=function(){for(var e in this.loaders){var t=this.loaders[e];t&&t.destroy(),this.resetInternalLoader(e)}},t.destroy=function(){this.unregisterListeners(),this.destroyInternalLoaders()},t.onManifestLoading=function(e,t){var r=t.url;this.load({id:null,groupId:null,level:0,responseType:"text",type:u.PlaylistContextType.MANIFEST,url:r,deliveryDirectives:null})},t.onLevelLoading=function(e,t){var r=t.id,a=t.level,n=t.url,s=t.deliveryDirectives;this.load({id:r,groupId:null,level:a,responseType:"text",type:u.PlaylistContextType.LEVEL,url:n,deliveryDirectives:s})},t.onAudioTrackLoading=function(e,t){var r=t.id,a=t.groupId,n=t.url,s=t.deliveryDirectives;this.load({id:r,groupId:a,level:null,responseType:"text",type:u.PlaylistContextType.AUDIO_TRACK,url:n,deliveryDirectives:s})},t.onSubtitleTrackLoading=function(e,t){var r=t.id,a=t.groupId,n=t.url,s=t.deliveryDirectives;this.load({id:r,groupId:a,level:null,responseType:"text",type:u.PlaylistContextType.SUBTITLE_TRACK,url:n,deliveryDirectives:s})},t.load=function(e){var t=this.hls.config,r=this.getInternalLoader(e),a;if(r){var n=r.context;if(n&&n.url===e.url)return void d.logger.trace("[playlist-loader]: playlist request ongoing");d.logger.log("[playlist-loader]: aborting previous loader for type: "+e.type),r.abort()}var s,i,o,l;switch(e.type){case u.PlaylistContextType.MANIFEST:s=t.manifestLoadingMaxRetry,i=t.manifestLoadingTimeOut,o=t.manifestLoadingRetryDelay,l=t.manifestLoadingMaxRetryTimeout;break;case u.PlaylistContextType.LEVEL:case u.PlaylistContextType.AUDIO_TRACK:case u.PlaylistContextType.SUBTITLE_TRACK:s=0,i=t.levelLoadingTimeOut;break;default:s=t.levelLoadingMaxRetry,i=t.levelLoadingTimeOut,o=t.levelLoadingRetryDelay,l=t.levelLoadingMaxRetryTimeout;}if(r=this.createInternalLoader(e),null!==(a=e.deliveryDirectives)&&void 0!==a&&a.part){var c;if(e.type===u.PlaylistContextType.LEVEL&&null!==e.level?c=this.hls.levels[e.level].details:e.type===u.PlaylistContextType.AUDIO_TRACK&&null!==e.id?c=this.hls.audioTracks[e.id].details:e.type===u.PlaylistContextType.SUBTITLE_TRACK&&null!==e.id&&(c=this.hls.subtitleTracks[e.id].details),c){var g=c.partTarget,f=c.targetduration;g&&f&&(i=Math.min(1e3*Math.max(3*g,.8*f),i))}}var m={timeout:i,maxRetry:s,retryDelay:o,maxRetryDelay:l,highWaterMark:0},p={onSuccess:this.loadsuccess.bind(this),onError:this.loaderror.bind(this),onTimeout:this.loadtimeout.bind(this)};r.load(e,m,p)},t.loadsuccess=function(e,t,r,a){void 0===a&&(a=null),this.resetInternalLoader(r.type);var n=e.data;return 0===n.indexOf("#EXTM3U")?void(t.parsing.start=performance.now(),0<n.indexOf("#EXTINF:")||0<n.indexOf("#EXT-X-TARGETDURATION:")?this.handleTrackOrLevelPlaylist(e,t,r,a):this.handleMasterPlaylist(e,t,r,a)):void this.handleManifestParsingError(e,r,"no EXTM3U delimiter",a)},t.loaderror=function(e,t,r){void 0===r&&(r=null),this.handleNetworkError(t,r,!1,e)},t.loadtimeout=function(e,t,r){void 0===r&&(r=null),this.handleNetworkError(t,r,!0)},t.handleMasterPlaylist=function(e,t,r,a){var s=this.hls,o=e.data,u=n(e,r),g=l["default"].parseMasterPlaylist(o,u),f=g.levels,m=g.sessionData,p=g.sessionKeys;if(!f.length)return void this.handleManifestParsingError(e,r,"no level found in manifest",a);var y=f.map(function(e){return{id:e.attrs.AUDIO,audioCodec:e.audioCodec}}),E=f.map(function(e){return{id:e.attrs.SUBTITLES,textCodec:e.textCodec}}),T=l["default"].parseMasterPlaylistMedia(o,u,"AUDIO",y),h=l["default"].parseMasterPlaylistMedia(o,u,"SUBTITLES",E),S=l["default"].parseMasterPlaylistMedia(o,u,"CLOSED-CAPTIONS");if(T.length){var v=T.some(function(e){return!e.url});v||!f[0].audioCodec||f[0].attrs.AUDIO||(d.logger.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),T.unshift({type:"main",name:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new c.AttrList({}),bitrate:0,url:""}))}s.trigger(i.Events.MANIFEST_LOADED,{levels:f,audioTracks:T,subtitles:h,captions:S,url:u,stats:t,networkDetails:a,sessionData:m,sessionKeys:p})},t.handleTrackOrLevelPlaylist=function(e,t,r,d){var g=this.hls,f=r.id,m=r.level,p=r.type,y=n(e,r),E=(0,s.isFiniteNumber)(f)?f:0,T=(0,s.isFiniteNumber)(m)?m:E,h=a(r),S=l["default"].parseLevelPlaylist(e.data,y,T,h,E);if(!S.fragments.length)return void g.trigger(i.Events.ERROR,{type:o.ErrorTypes.NETWORK_ERROR,details:o.ErrorDetails.LEVEL_EMPTY_ERROR,fatal:!1,url:y,reason:"no fragments found in level",level:"number"==typeof r.level?r.level:void 0});if(p===u.PlaylistContextType.MANIFEST){var v={attrs:new c.AttrList({}),bitrate:0,details:S,name:"",url:y};g.trigger(i.Events.MANIFEST_LOADED,{levels:[v],audioTracks:[],url:y,stats:t,networkDetails:d,sessionData:null,sessionKeys:null})}t.parsing.end=performance.now(),r.levelDetails=S,this.handlePlaylistLoaded(e,t,r,d)},t.handleManifestParsingError=function(e,t,r,a){this.hls.trigger(i.Events.ERROR,{type:o.ErrorTypes.NETWORK_ERROR,details:o.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:t.type===u.PlaylistContextType.MANIFEST,url:e.url,reason:r,response:e,context:t,networkDetails:a})},t.handleNetworkError=function(e,t,r,a){void 0===r&&(r=!1),d.logger.warn("[playlist-loader]: A network "+(r?"timeout":"error")+" occurred while loading "+e.type+" level: "+e.level+" id: "+e.id+" group-id: \""+e.groupId+"\"");var n=o.ErrorDetails.UNKNOWN,s=!1,l=this.getInternalLoader(e);switch(e.type){case u.PlaylistContextType.MANIFEST:n=r?o.ErrorDetails.MANIFEST_LOAD_TIMEOUT:o.ErrorDetails.MANIFEST_LOAD_ERROR,s=!0;break;case u.PlaylistContextType.LEVEL:n=r?o.ErrorDetails.LEVEL_LOAD_TIMEOUT:o.ErrorDetails.LEVEL_LOAD_ERROR,s=!1;break;case u.PlaylistContextType.AUDIO_TRACK:n=r?o.ErrorDetails.AUDIO_TRACK_LOAD_TIMEOUT:o.ErrorDetails.AUDIO_TRACK_LOAD_ERROR,s=!1;break;case u.PlaylistContextType.SUBTITLE_TRACK:n=r?o.ErrorDetails.SUBTITLE_TRACK_LOAD_TIMEOUT:o.ErrorDetails.SUBTITLE_LOAD_ERROR,s=!1;}l&&this.resetInternalLoader(e.type);var c={type:o.ErrorTypes.NETWORK_ERROR,details:n,fatal:s,url:e.url,loader:l,context:e,networkDetails:t};a&&(c.response=a),this.hls.trigger(i.Events.ERROR,c)},t.handlePlaylistLoaded=function(e,t,r,a){var n=r.type,s=r.level,o=r.id,d=r.groupId,l=r.loader,c=r.levelDetails,g=r.deliveryDirectives;return null!==c&&void 0!==c&&c.targetduration?void(l&&(c.live&&(l.getCacheAge&&(c.ageHeader=l.getCacheAge()||0),(!l.getCacheAge||isNaN(c.ageHeader))&&(c.ageHeader=0)),n===u.PlaylistContextType.MANIFEST||n===u.PlaylistContextType.LEVEL?this.hls.trigger(i.Events.LEVEL_LOADED,{details:c,level:s||0,id:o||0,stats:t,networkDetails:a,deliveryDirectives:g}):n===u.PlaylistContextType.AUDIO_TRACK?this.hls.trigger(i.Events.AUDIO_TRACK_LOADED,{details:c,id:o||0,groupId:d||"",stats:t,networkDetails:a,deliveryDirectives:g}):n===u.PlaylistContextType.SUBTITLE_TRACK?this.hls.trigger(i.Events.SUBTITLE_TRACK_LOADED,{details:c,id:o||0,groupId:d||"",stats:t,networkDetails:a,deliveryDirectives:g}):void 0)):void this.handleManifestParsingError(e,r,"invalid target duration",a)},e}();const f=g},"./src/polyfills/number.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{MAX_SAFE_INTEGER:()=>n,isFiniteNumber:()=>a});var a=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},n=Number.MAX_SAFE_INTEGER||9007199254740991},"./src/remux/aac-helper.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>n});var a=function(){function e(){}return e.getSilentFrame=function(e,t){switch(e){case"mp4a.40.2":if(1===t)return new Uint8Array([0,200,0,128,35,128]);if(2===t)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224]);break;default:if(1===t)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);}},e}();const n=a},"./src/remux/mp4-generator.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>s});var a=Math.pow(2,32)-1,n=function(){function e(){}return e.init=function(){e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],mvex:[],mvhd:[],pasp:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]};for(var t in e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),a=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);e.HDLR_TYPES={video:r,audio:a};var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),s=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=s,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var i=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),d=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,i,d,i,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,n))},e.box=function(e){for(var t=8,r=arguments.length,a=Array(1<r?r-1:0),n=1;n<r;n++)a[n-1]=arguments[n];for(var s=a.length,o=s;s--;)t+=a[s].byteLength;var d=new Uint8Array(t);for(d[0]=255&t>>24,d[1]=255&t>>16,d[2]=255&t>>8,d[3]=255&t,d.set(e,4),(s=0,t=8);s<o;s++)d.set(a[s],t),t+=a[s].byteLength;return d},e.hdlr=function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])},e.mdat=function(t){return e.box(e.types.mdat,t)},e.mdhd=function(t,r){r*=t;var a=Math.floor(r/4294967296),n=Math.floor(r%4294967296);return e.box(e.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,255&t>>24,255&t>>16,255&t>>8,255&t,a>>24,255&a>>16,255&a>>8,255&a,n>>24,255&n>>16,255&n>>8,255&n,85,196,0,0]))},e.mdia=function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))},e.mfhd=function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,255&t>>16,255&t>>8,255&t]))},e.minf=function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))},e.moof=function(t,r,a){return e.box(e.types.moof,e.mfhd(t),e.traf(a,r))},e.moov=function(t){for(var r=t.length,a=[];r--;)a[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(a).concat(e.mvex(t)))},e.mvex=function(t){for(var r=t.length,a=[];r--;)a[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(a))},e.mvhd=function(t,r){r*=t;var a=Math.floor(r/4294967296),n=Math.floor(r%4294967296),s=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,255&t>>24,255&t>>16,255&t>>8,255&t,a>>24,255&a>>16,255&a>>8,255&a,n>>24,255&n>>16,255&n>>8,255&n,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return e.box(e.types.mvhd,s)},e.sdtp=function(t){var r=t.samples||[],a=new Uint8Array(4+r.length),n,s;for(n=0;n<r.length;n++)s=r[n].flags,a[n+4]=s.dependsOn<<4|s.isDependedOn<<2|s.hasRedundancy;return e.box(e.types.sdtp,a)},e.stbl=function(t){return e.box(e.types.stbl,e.stsd(t),e.box(e.types.stts,e.STTS),e.box(e.types.stsc,e.STSC),e.box(e.types.stsz,e.STSZ),e.box(e.types.stco,e.STCO))},e.avc1=function(t){var r=[],a=[],n,s,o;for(n=0;n<t.sps.length;n++)s=t.sps[n],o=s.byteLength,r.push(255&o>>>8),r.push(255&o),r=r.concat(Array.prototype.slice.call(s));for(n=0;n<t.pps.length;n++)s=t.pps[n],o=s.byteLength,a.push(255&o>>>8),a.push(255&o),a=a.concat(Array.prototype.slice.call(s));var d=e.box(e.types.avcC,new Uint8Array([1,r[3],r[4],r[5],255,224|t.sps.length].concat(r).concat([t.pps.length]).concat(a))),l=t.width,u=t.height,c=t.pixelRatio[0],g=t.pixelRatio[1];return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255&l>>8,255&l,255&u>>8,255&u,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),d,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])),e.box(e.types.pasp,new Uint8Array([c>>24,255&c>>16,255&c>>8,255&c,g>>24,255&g>>16,255&g>>8,255&g])))},e.esds=function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))},e.mp4a=function(t){var r=t.samplerate;return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,255&r>>8,255&r,0,0]),e.box(e.types.esds,e.esds(t)))},e.mp3=function(t){var r=t.samplerate;return e.box(e.types[".mp3"],new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,255&r>>8,255&r,0,0]))},e.stsd=function(t){return"audio"===t.type?"mp3"===t.segmentCodec&&"mp3"===t.codec?e.box(e.types.stsd,e.STSD,e.mp3(t)):e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))},e.tkhd=function(t){var r=t.id,a=t.duration*t.timescale,n=t.width,s=t.height,i=Math.floor(a/4294967296),o=Math.floor(a%4294967296);return e.box(e.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,255&r>>24,255&r>>16,255&r>>8,255&r,0,0,0,0,i>>24,255&i>>16,255&i>>8,255&i,o>>24,255&o>>16,255&o>>8,255&o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,255&n>>8,255&n,0,0,255&s>>8,255&s,0,0]))},e.traf=function(t,r){var a=e.sdtp(t),n=t.id,s=Math.floor(r/4294967296),i=Math.floor(r%4294967296);return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,n>>24,255&n>>16,255&n>>8,255&n])),e.box(e.types.tfdt,new Uint8Array([1,0,0,0,s>>24,255&s>>16,255&s>>8,255&s,i>>24,255&i>>16,255&i>>8,255&i])),e.trun(t,a.length+16+20+8+16+8+8),a)},e.trak=function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))},e.trex=function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,255&r>>16,255&r>>8,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},e.trun=function(t,r){var a=t.samples||[],n=a.length,s=12+16*n,o=new Uint8Array(s),d,l,u,c,g,f;for(r+=8+s,o.set(["video"===t.type?1:0,0,15,1,255&n>>>24,255&n>>>16,255&n>>>8,255&n,255&r>>>24,255&r>>>16,255&r>>>8,255&r],0),d=0;d<n;d++)l=a[d],u=l.duration,c=l.size,g=l.flags,f=l.cts,o.set([255&u>>>24,255&u>>>16,255&u>>>8,255&u,255&c>>>24,255&c>>>16,255&c>>>8,255&c,g.isLeading<<2|g.dependsOn,g.isDependedOn<<6|g.hasRedundancy<<4|g.paddingValue<<1|g.isNonSync,61440&g.degradPrio,15&g.degradPrio,255&f>>>24,255&f>>>16,255&f>>>8,255&f],12+16*d);return e.box(e.types.trun,o)},e.initSegment=function(t){e.types||e.init();var r=e.moov(t),a=new Uint8Array(e.FTYP.byteLength+r.byteLength);return a.set(e.FTYP),a.set(r,e.FTYP.byteLength),a},e}();n.types=void 0,n.HDLR_TYPES=void 0,n.STTS=void 0,n.STSC=void 0,n.STCO=void 0,n.STSZ=void 0,n.VMHD=void 0,n.SMHD=void 0,n.STSD=void 0,n.FTYP=void 0,n.DINF=void 0;const s=n},"./src/remux/mp4-remuxer.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t){var r;if(null===t)return e;for(r=t<e?-8589934592:8589934592;4294967296<Math.abs(e-t);)e+=r;return e}function s(e){for(var t=0;t<e.length;t++)if(e[t].key)return t;return-1}function i(e,t,r,a){var s=e.samples.length;if(s){for(var i=e.inputTimeScale,o=0,d;o<s;o++)d=e.samples[o],d.pts=n(d.pts-r,t*i)/i,d.dts=n(d.dts-a,t*i)/i;var l=e.samples;return e.samples=[],{samples:l}}}function o(e,t,r){var a=e.samples.length;if(a){for(var s=e.inputTimeScale,i=0,o;i<a;i++)o=e.samples[i],o.pts=n(o.pts-r,t*s)/s;e.samples.sort(function(e,t){return e.pts-t.pts});var d=e.samples;return e.samples=[],{samples:d}}}r.r(t),r.d(t,{default:()=>T,flushTextTrackMetadataCueSamples:()=>i,flushTextTrackUserdataCueSamples:()=>o,normalizePts:()=>n});var d=r("./src/polyfills/number.ts"),l=r("./src/remux/aac-helper.ts"),u=r("./src/remux/mp4-generator.ts"),c=r("./src/events.ts"),g=r("./src/errors.ts"),f=r("./src/utils/logger.ts"),m=r("./src/types/loader.ts"),p=r("./src/utils/timescale-conversion.ts"),y=null,E=null,T=function(){function e(e,t,r,a){if(void 0===a&&(a=""),this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=void 0,this._initDTS=void 0,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.observer=e,this.config=t,this.typeSupported=r,this.ISGenerated=!1,null===y){var n=navigator.userAgent||"",s=n.match(/Chrome\/(\d+)/i);y=s?parseInt(s[1]):0}if(null===E){var i=navigator.userAgent.match(/Safari\/(\d+)/i);E=i?parseInt(i[1]):0}}var t=e.prototype;return t.destroy=function(){},t.resetTimeStamp=function(e){f.logger.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e},t.resetNextTimestamp=function(){f.logger.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},t.resetInitSegment=function(){f.logger.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1},t.getVideoStartPts=function(e){var t=!1,r=e.reduce(function(e,r){var a=r.pts-e;return-4294967296>a?(t=!0,n(e,r.pts)):0<a?e:r.pts},e[0].pts);return t&&f.logger.debug("PTS rollover detected"),r},t.remux=function(e,t,r,a,d,l,u,c){var g=d,p=d,y=-1<e.pid,E=-1<t.pid,T=t.samples.length,h=0<e.samples.length,S=u&&0<T||1<T,v=(!y||h)&&(!E||S)||this.ISGenerated||u,L,D,k,I,A,R;if(v){this.ISGenerated||(k=this.generateIS(e,t,d));var b=this.isVideoContiguous,C=-1,_;if(S&&(C=s(t.samples),!b&&this.config.forceKeyFrameOnDiscontinuity))if(R=!0,0<C){f.logger.warn("[mp4-remuxer]: Dropped "+C+" out of "+T+" video samples due to a missing keyframe");var x=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(C),t.dropped+=C,p+=(t.samples[0].pts-x)/t.inputTimeScale,_=p}else-1===C&&(f.logger.warn("[mp4-remuxer]: No keyframe found out of "+T+" video samples"),R=!1);if(this.ISGenerated){if(h&&S){var P=this.getVideoStartPts(t.samples),F=n(e.samples[0].pts,P)-P,O=F/t.inputTimeScale;g+=Math.max(0,O),p+=Math.max(0,-O)}if(!h)S&&(L=this.remuxVideo(t,p,b,0));else if(e.samplerate||(f.logger.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),k=this.generateIS(e,t,d)),D=this.remuxAudio(e,g,this.isAudioContiguous,l,E||S||c===m.PlaylistLevelType.AUDIO?p:void 0),S){var N=D?D.endPTS-D.startPTS:0;t.inputTimeScale||(f.logger.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),k=this.generateIS(e,t,d)),L=this.remuxVideo(t,p,b,N)}L&&(L.firstKeyFrame=C,L.independent=-1!==C,L.firstKeyFramePTS=_)}}return this.ISGenerated&&(r.samples.length&&(A=i(r,d,this._initPTS,this._initDTS)),a.samples.length&&(I=o(a,d,this._initPTS))),{audio:D,video:L,initSegment:k,independent:R,text:I,id3:A}},t.generateIS=function(e,t,r){var a=e.samples,s=t.samples,i=this.typeSupported,o={},l=!(0,d.isFiniteNumber)(this._initPTS),c="audio/mp4",g,f,m;if(l&&(g=f=1/0),e.config&&a.length){switch(e.timescale=e.samplerate,e.segmentCodec){case"mp3":i.mpeg?(c="audio/mpeg",e.codec=""):i.mp3&&(e.codec="mp3");}o.audio={id:"audio",container:c,codec:e.codec,initSegment:"mp3"===e.segmentCodec&&i.mpeg?new Uint8Array(0):u["default"].initSegment([e]),metadata:{channelCount:e.channelCount}},l&&(m=e.inputTimeScale,g=f=a[0].pts-Math.round(m*r))}if(t.sps&&t.pps&&s.length&&(t.timescale=t.inputTimeScale,o.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:u["default"].initSegment([t]),metadata:{width:t.width,height:t.height}},l)){m=t.inputTimeScale;var p=this.getVideoStartPts(s),y=Math.round(m*r);f=Math.min(f,n(s[0].dts,p)-y),g=Math.min(g,p-y)}return Object.keys(o).length?(this.ISGenerated=!0,l&&(this._initPTS=g,this._initDTS=f),{tracks:o,initPTS:g,timescale:m}):void 0},t.remuxVideo=function(e,t,r,s){var o=e.inputTimeScale,d=e.samples,l=[],m=d.length,T=this._initPTS,S=this.nextAvcDts,v=8,L=this.videoSampleDuration,D=Number.POSITIVE_INFINITY,k=Number.NEGATIVE_INFINITY,I=!1,A,R;if(!r||null===S){var b=d[0].pts-n(d[0].dts,d[0].pts);S=t*o-b}for(var C=0,_;C<m;C++)_=d[C],_.pts=n(_.pts-T,S),_.dts=n(_.dts-T,S),_.dts<d[0<C?C-1:C].dts&&(I=!0);I&&d.sort(function(e,t){var r=e.dts-t.dts,a=e.pts-t.pts;return r||a}),A=d[0].dts,R=d[d.length-1].dts;var x=R-A,P=x?Math.round(x/(m-1)):L||e.inputTimeScale/30;if(r){var F=A-S,O=F>P,N=-1>F;if((O||N)&&(O?f.logger.warn("AVC: "+(0,p.toMsFromMpegTsClock)(F,!0)+" ms ("+F+"dts) hole between fragments detected, filling it"):f.logger.warn("AVC: "+(0,p.toMsFromMpegTsClock)(-F,!0)+" ms ("+F+"dts) overlapping between fragments detected"),!N||S>d[0].pts)){A=S;var w=d[0].pts-F;d[0].dts=A,d[0].pts=w,f.logger.log("Video: First PTS/DTS adjusted: "+(0,p.toMsFromMpegTsClock)(w,!0)+"/"+(0,p.toMsFromMpegTsClock)(A,!0)+", delta: "+(0,p.toMsFromMpegTsClock)(F,!0)+" ms")}}A=Math.max(0,A);for(var M=0,B=0,U=0;U<m;U++){for(var G=d[U],K=G.units,H=K.length,V=0,Y=0;Y<H;Y++)V+=K[Y].data.length;B+=V,M+=H,G.length=V,G.dts=Math.max(G.dts,A),D=Math.min(G.pts,D),k=Math.max(G.pts,k)}R=d[m-1].dts;var W=B+4*M+8,q;try{q=new Uint8Array(W)}catch(e){return void this.observer.emit(c.Events.ERROR,c.Events.ERROR,{type:g.ErrorTypes.MUX_ERROR,details:g.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:W,reason:"fail allocating video mdat "+W})}var z=new DataView(q.buffer);z.setUint32(0,W),q.set(u["default"].types.mdat,4);for(var X=!1,Q=Number.POSITIVE_INFINITY,Z=Number.POSITIVE_INFINITY,$=Number.NEGATIVE_INFINITY,J=Number.NEGATIVE_INFINITY,ee=0;ee<m;ee++){for(var te=d[ee],re=te.units,ae=0,ne=0,se=re.length;ne<se;ne++){var ie=re[ne],oe=ie.data,de=ie.data.byteLength;z.setUint32(v,de),v+=4,q.set(oe,v),v+=de,ae+=4+de}var le=void 0;if(ee<m-1)L=d[ee+1].dts-te.dts,le=d[ee+1].pts-te.pts;else{var ue=this.config,ce=0<ee?te.dts-d[ee-1].dts:P;if(le=0<ee?te.pts-d[ee-1].pts:P,ue.stretchShortVideoTrack&&null!==this.nextAudioPts){var ge=Math.floor(ue.maxBufferHole*o),fe=(s?D+s*o:this.nextAudioPts)-te.pts;fe>ge?(L=fe-ce,0>L?L=ce:X=!0,f.logger.log("[mp4-remuxer]: It is approximately "+fe/90+" ms to the next segment; using duration "+L/90+" ms for the last video frame.")):L=ce}else L=ce}var me=Math.round(te.pts-te.dts);Q=Math.min(Q,L),$=Math.max($,L),Z=Math.min(Z,le),J=Math.max(J,le),l.push(new h(te.key,L,ae,me))}if(l.length)if(y){if(70>y){var pe=l[0].flags;pe.dependsOn=2,pe.isNonSync=0}}else if(E&&J-Z<$-Q&&.025>P/$&&0===l[0].cts){f.logger.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");for(var ye=A,Ee=0,Te=l.length;Ee<Te;Ee++){var he=ye+l[Ee].duration,Se=ye+l[Ee].cts;if(Ee<Te-1){var ve=he+l[Ee+1].cts;l[Ee].duration=ve-Se}else l[Ee].duration=Ee?l[Ee-1].duration:P;l[Ee].cts=0,ye=he}}console.assert(null!==L,"mp4SampleDuration must be computed"),L=X||!L?P:L,this.nextAvcDts=S=R+L,this.videoSampleDuration=L,this.isVideoContiguous=!0;var Le=u["default"].moof(e.sequenceNumber++,A,a({},e,{samples:l})),De={data1:Le,data2:q,startPTS:D/o,endPTS:(k+L)/o,startDTS:A/o,endDTS:S/o,type:"video",hasAudio:!1,hasVideo:!0,nb:l.length,dropped:e.dropped};return e.samples=[],e.dropped=0,console.assert(q.length,"MDAT length must not be zero"),De},t.remuxAudio=function(e,t,r,s,o){var d=e.inputTimeScale,m=e.samplerate?e.samplerate:d,p=d/m,y="aac"===e.segmentCodec?1024:1152,E=y*p,T=this._initPTS,S="mp3"===e.segmentCodec&&this.typeSupported.mpeg,v=[],L=void 0!==o,D=e.samples,k=S?0:8,I=this.nextAudioPts||-1,A=t*d;if(this.isAudioContiguous=r=r||D.length&&0<I&&(s&&9e3>Math.abs(A-I)||Math.abs(n(D[0].pts-T,A)-I)<20*E),D.forEach(function(e){e.pts=n(e.pts-T,A)}),!r||0>I){if(D=D.filter(function(e){return 0<=e.pts}),!D.length)return;I=0===o?0:s&&!L?Math.max(0,A):D[0].pts}if("aac"===e.segmentCodec)for(var R=this.config.maxAudioFramesDrift,b=0,C=I;b<D.length;b++){var _=D[b],x=_.pts,P=x-C,F=Math.abs(1e3*P/d);if(P<=-R*E&&L)0===b&&(f.logger.warn("Audio frame @ "+(x/d).toFixed(3)+"s overlaps nextAudioPts by "+Math.round(1e3*P/d)+" ms."),this.nextAudioPts=I=C=x);else if(P>=R*E&&10000>F&&L){var O=Math.round(P/E);C=x-O*E,0>C&&(O--,C+=E),0===b&&(this.nextAudioPts=I=C),f.logger.warn("[mp4-remuxer]: Injecting "+O+" audio frame @ "+(C/d).toFixed(3)+"s due to "+Math.round(1e3*P/d)+" ms gap.");for(var N=0;N<O;N++){var w=Math.max(C,0),M=l["default"].getSilentFrame(e.manifestCodec||e.codec,e.channelCount);M||(f.logger.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),M=_.unit.subarray()),D.splice(b,0,{unit:M,pts:w}),C+=E,b++}}_.pts=C,C+=E}for(var B=null,U=null,G=0,K=D.length,H;K--;)G+=D[K].unit.byteLength;for(var V=0,Y=D.length;V<Y;V++){var W=D[V],q=W.unit,z=W.pts;if(null!==U){var X=v[V-1];X.duration=Math.round((z-U)/p)}else if(r&&"aac"===e.segmentCodec&&(z=I),B=z,0<G){G+=k;try{H=new Uint8Array(G)}catch(e){return void this.observer.emit(c.Events.ERROR,c.Events.ERROR,{type:g.ErrorTypes.MUX_ERROR,details:g.ErrorDetails.REMUX_ALLOC_ERROR,fatal:!1,bytes:G,reason:"fail allocating audio mdat "+G})}if(!S){var Q=new DataView(H.buffer);Q.setUint32(0,G),H.set(u["default"].types.mdat,4)}}else return;H.set(q,k);var Z=q.byteLength;k+=Z,v.push(new h(!0,y,Z,0)),U=z}var $=v.length;if($){var J=v[v.length-1];this.nextAudioPts=I=U+p*J.duration;var ee=S?new Uint8Array(0):u["default"].moof(e.sequenceNumber++,B/p,a({},e,{samples:v}));e.samples=[];var te=B/d,re=I/d,ae={data1:ee,data2:H,startPTS:te,endPTS:re,startDTS:te,endDTS:re,type:"audio",hasAudio:!0,hasVideo:!1,nb:$};return this.isAudioContiguous=!0,console.assert(H.length,"MDAT length must not be zero"),ae}},t.remuxEmptyAudio=function(e,t,r,a){var n=e.inputTimeScale,s=e.samplerate?e.samplerate:n,o=this.nextAudioPts,d=(null===o?a.startDTS*n:o)+this._initDTS,u=a.endDTS*n+this._initDTS,c=1024*(n/s),g=Math.ceil((u-d)/c),m=l["default"].getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(f.logger.warn("[mp4-remuxer]: remux empty Audio"),!m)return void f.logger.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec");for(var p=[],y=0,E;y<g;y++)E=d+y*c,p.push({unit:m,pts:E,dts:E});return e.samples=p,this.remuxAudio(e,t,r,!1)},e}(),h=function(e,t,r,a){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=t,this.size=r,this.cts=a,this.flags=new S(e)},S=function(e){this.isLeading=0,this.isDependedOn=0,this.hasRedundancy=0,this.degradPrio=0,this.dependsOn=1,this.isNonSync=1,this.dependsOn=e?2:1,this.isNonSync=e?0:1}},"./src/remux/passthrough-remuxer.ts":(e,t,r)=>{"use strict";function a(e,t){var r=null===e||void 0===e?void 0:e.codec;return r&&4<r.length?r:"hvc1"===r||"hev1"===r?"hvc1.1.c.L120.90":"av01"===r?"av01.0.04M.08":"avc1"===r||t===o.ElementaryStreamTypes.VIDEO?"avc1.42e01e":"mp4a.40.5"}r.r(t),r.d(t,{default:()=>u});var n=r("./src/polyfills/number.ts"),s=r("./src/remux/mp4-remuxer.ts"),i=r("./src/utils/mp4-tools.ts"),o=r("./src/loader/fragment.ts"),d=r("./src/utils/logger.ts"),l=function(){function e(){this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=void 0,this.initTracks=void 0,this.lastEndTime=null}var t=e.prototype;return t.destroy=function(){},t.resetTimeStamp=function(e){this.initPTS=e,this.lastEndTime=null},t.resetNextTimestamp=function(){this.lastEndTime=null},t.resetInitSegment=function(e,t,r,a){this.audioCodec=t,this.videoCodec=r,this.generateInitSegment((0,i.patchEncyptionData)(e,a)),this.emitInitSegment=!0},t.generateInitSegment=function(e){var t=this.audioCodec,r=this.videoCodec;if(!e||!e.byteLength)return this.initTracks=void 0,void(this.initData=void 0);var n=this.initData=(0,i.parseInitSegment)(e);t||(t=a(n.audio,o.ElementaryStreamTypes.AUDIO)),r||(r=a(n.video,o.ElementaryStreamTypes.VIDEO));var s={};n.audio&&n.video?s.audiovideo={container:"video/mp4",codec:t+","+r,initSegment:e,id:"main"}:n.audio?s.audio={container:"audio/mp4",codec:t,initSegment:e,id:"audio"}:n.video?s.video={container:"video/mp4",codec:r,initSegment:e,id:"main"}:d.logger.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=s},t.remux=function(e,t,r,a,o){var l=this.initPTS,u=this.lastEndTime,c={audio:void 0,video:void 0,text:a,id3:r,initSegment:void 0},g;(0,n.isFiniteNumber)(u)||(u=this.lastEndTime=o||0);var f=t.samples;if(!f||!f.length)return c;var m={initPTS:void 0,timescale:1},p=this.initData;if(p&&p.length||(this.generateInitSegment(f),p=this.initData),!p||!p.length)return d.logger.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),c;this.emitInitSegment&&(m.tracks=this.initTracks,this.emitInitSegment=!1);var y=(0,i.getStartDTS)(p,f);(0,n.isFiniteNumber)(l)||(this.initPTS=m.initPTS=l=y-o);var E=(0,i.getDuration)(f,p),T=e?y-l:u,h=T+E;(0,i.offsetStartDTS)(p,f,l),0<E?this.lastEndTime=h:(d.logger.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var S=!!p.audio,v=!!p.video,L="";S&&(L+="audio"),v&&(L+="video");var D={data1:f,startPTS:T,startDTS:T,endPTS:h,endDTS:h,type:L,hasAudio:S,hasVideo:v,nb:1,dropped:0};c.audio="audio"===D.type?D:void 0,c.video="audio"===D.type?void 0:D,c.initSegment=m;var k=null==(g=this.initPTS)?0:g;return c.id3=(0,s.flushTextTrackMetadataCueSamples)(r,o,k,k),a.samples.length&&(c.text=(0,s.flushTextTrackUserdataCueSamples)(a,o,k)),c},e}();const u=l},"./src/task-loop.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});var a=function(){function e(){this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}var t=e.prototype;return t.destroy=function(){this.onHandlerDestroying(),this.onHandlerDestroyed()},t.onHandlerDestroying=function(){this.clearNextTick(),this.clearInterval()},t.onHandlerDestroyed=function(){},t.hasInterval=function(){return!!this._tickInterval},t.hasNextTick=function(){return!!this._tickTimer},t.setInterval=function(e){return!this._tickInterval&&(this._tickInterval=self.setInterval(this._boundTick,e),!0)},t.clearInterval=function(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)},t.clearNextTick=function(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)},t.tick=function(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),1<this._tickCallCount&&this.tickImmediate(),this._tickCallCount=0)},t.tickImmediate=function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)},t.doTick=function(){},e}()},"./src/types/cmcd.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{CMCDObjectType:()=>n,CMCDStreamType:()=>i,CMCDStreamingFormat:()=>s,CMCDVersion:()=>a});var a=1,n;(function(e){e.MANIFEST="m",e.AUDIO="a",e.VIDEO="v",e.MUXED="av",e.INIT="i",e.CAPTION="c",e.TIMED_TEXT="tt",e.KEY="k",e.OTHER="o"})(n||(n={}));var s;(function(e){e.DASH="d",e.HLS="h",e.SMOOTH="s",e.OTHER="o"})(s||(s={}));var i;(function(e){e.VOD="v",e.LIVE="l"})(i||(i={}))},"./src/types/demuxer.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{MetadataSchema:()=>a});var a;(function(e){e.audioId3="org.id3",e.dateRange="com.apple.quicktime.HLS",e.emsg="https://aomedia.org/emsg/ID3"})(a||(a={}))},"./src/types/level.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=0,a;r<t.length;r++)a=t[r],a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,s(a.key),a)}function n(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e){var t=i(e,"string");return"symbol"==typeof t?t:t+""}function i(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var a=r.call(e,t||"default");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function o(e,t){var r=e.canSkipUntil,a=e.canSkipDateRanges,n=e.endSN,s=void 0===t?0:t-n;return r&&s<r?a?l.v2:l.Yes:l.No}r.r(t),r.d(t,{HdcpLevels:()=>d,HlsSkip:()=>l,HlsUrlParameters:()=>u,Level:()=>c,getSkipValue:()=>o});var d=["NONE","TYPE-0","TYPE-1","TYPE-2",null],l;(function(e){e.No="",e.Yes="YES",e.v2="v2"})(l||(l={}));var u=function(){function e(e,t,r){this.msn=void 0,this.part=void 0,this.skip=void 0,this.msn=e,this.part=t,this.skip=r}var t=e.prototype;return t.addDirectives=function(e){var t=new self.URL(e);return void 0!==this.msn&&t.searchParams.set("_HLS_msn",this.msn.toString()),void 0!==this.part&&t.searchParams.set("_HLS_part",this.part.toString()),this.skip&&t.searchParams.set("_HLS_skip",this.skip),t.href},e}(),c=function(){function e(e){this.attrs=void 0,this.audioCodec=void 0,this.bitrate=void 0,this.codecSet=void 0,this.height=void 0,this.id=void 0,this.name=void 0,this.videoCodec=void 0,this.width=void 0,this.unknownCodecs=void 0,this.audioGroupIds=void 0,this.details=void 0,this.fragmentError=0,this.loadError=0,this.loaded=void 0,this.realBitrate=0,this.textGroupIds=void 0,this.url=void 0,this._urlId=0,this.url=[e.url],this.attrs=e.attrs,this.bitrate=e.bitrate,e.details&&(this.details=e.details),this.id=e.id||0,this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.audioCodec=e.audioCodec,this.videoCodec=e.videoCodec,this.unknownCodecs=e.unknownCodecs,this.codecSet=[e.videoCodec,e.audioCodec].filter(function(e){return e}).join(",").replace(/\.[^.,]+/g,"")}return n(e,[{key:"maxBitrate",get:function(){return Math.max(this.realBitrate,this.bitrate)}},{key:"uri",get:function(){return this.url[this._urlId]||""}},{key:"urlId",get:function(){return this._urlId},set:function(e){var t=e%this.url.length;this._urlId!==t&&(this.details=void 0,this._urlId=t)}}]),e}()},"./src/types/loader.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{PlaylistContextType:()=>a,PlaylistLevelType:()=>n});var a;(function(e){e.MANIFEST="manifest",e.LEVEL="level",e.AUDIO_TRACK="audioTrack",e.SUBTITLE_TRACK="subtitleTrack"})(a||(a={}));var n;(function(e){e.MAIN="main",e.AUDIO="audio",e.SUBTITLE="subtitle"})(n||(n={}))},"./src/types/transmuxer.ts":(e,t,r)=>{"use strict";function a(){return{start:0,executeStart:0,executeEnd:0,end:0}}r.r(t),r.d(t,{ChunkMetadata:()=>n});var n=function(e,t,r,n,s,i){void 0===n&&(n=0),void 0===s&&(s=-1),void 0===i&&(i=!1),this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing=a(),this.buffering={audio:a(),video:a(),audiovideo:a()},this.level=e,this.sn=t,this.id=r,this.size=n,this.part=s,this.partial=i}},"./src/utils/attr-list.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{AttrList:()=>n});var a=/\s*(.+?)\s*=((?:\".*?\")|.*?)(?:,|$)/g,n=function(){function e(t){for(var r in"string"==typeof t&&(t=e.parseAttrList(t)),t)t.hasOwnProperty(r)&&(this[r]=t[r])}var t=e.prototype;return t.decimalInteger=function(e){var t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t},t.hexadecimalInteger=function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),a=0;a<t.length/2;a++)r[a]=parseInt(t.slice(2*a,2*a+2),16);return r}return null},t.hexadecimalIntegerAsNumber=function(e){var t=parseInt(this[e],16);return t>Number.MAX_SAFE_INTEGER?1/0:t},t.decimalFloatingPoint=function(e){return parseFloat(this[e])},t.optionalFloat=function(e,t){var r=this[e];return r?parseFloat(r):t},t.enumeratedString=function(e){return this[e]},t.bool=function(e){return"YES"===this[e]},t.decimalResolution=function(e){var t=/^(\d+)x(\d+)$/.exec(this[e]);return null===t?void 0:{width:parseInt(t[1],10),height:parseInt(t[2],10)}},e.parseAttrList=function(e){var t={},r;for(a.lastIndex=0;null!==(r=a.exec(e));){var n=r[2];0===n.indexOf("\"")&&n.lastIndexOf("\"")===n.length-1&&(n=n.slice(1,-1)),t[r[1]]=n}return t},e}()},"./src/utils/binary-search.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});const a={search:function(e,t){for(var r=0,a=e.length-1,n=null,s=null;r<=a;){n=0|(r+a)/2,s=e[n];var i=t(s);if(0<i)r=n+1;else if(0>i)a=n-1;else return s}return null}}},"./src/utils/buffer-helper.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{BufferHelper:()=>s});var a=r("./src/utils/logger.ts"),n={length:0,start:function(){return 0},end:function(){return 0}},s=function(){function e(){}return e.isBuffered=function(t,r){try{if(t)for(var a=e.getBuffered(t),n=0;n<a.length;n++)if(r>=a.start(n)&&r<=a.end(n))return!0}catch(e){}return!1},e.bufferInfo=function(t,r,a){try{if(t){var n=e.getBuffered(t),s=[],o;for(o=0;o<n.length;o++)s.push({start:n.start(o),end:n.end(o)});return this.bufferedInfo(s,r,a)}}catch(e){}return{len:0,start:r,end:r,nextStart:void 0}},e.bufferedInfo=function(e,t,r){t=Math.max(0,t),e.sort(function(e,t){var r=e.start-t.start;return r?r:t.end-e.end});var a=[];if(r){for(var n=0,s;n<e.length;n++)if(s=a.length,s){var o=a[s-1].end;e[n].start-o<r?e[n].end>o&&(a[s-1].end=e[n].end):a.push(e[n])}else a.push(e[n]);}else a=e;for(var d=0,l=t,u=t,c=0,g;c<a.length;c++){var f=a[c].start,m=a[c].end;if(t+r>=f&&t<m)l=f,u=m,d=u-t;else if(t+r<f){g=f;break}}return{len:d,start:l||0,end:u||0,nextStart:g}},e.getBuffered=function(e){try{return e.buffered}catch(t){return a.logger.log("failed to get media.buffered",t),n}},e}()},"./src/utils/cea-608-parser.ts":(e,t,r)=>{"use strict";function n(e,t,r){r.a=e,r.b=t}function s(e,t,r){return r.a===e&&r.b===t}function o(){return{a:null,b:null}}r.r(t),r.d(t,{CaptionScreen:()=>L,Row:()=>v,default:()=>I});var d=r("./src/utils/logger.ts"),l={42:225,92:233,94:237,95:243,96:250,123:231,124:247,125:209,126:241,127:9608,128:174,129:176,130:189,131:191,132:8482,133:162,134:163,135:9834,136:224,137:32,138:232,139:226,140:234,141:238,142:244,143:251,144:193,145:201,146:211,147:218,148:220,149:252,150:8216,151:161,152:42,153:8217,154:9473,155:169,156:8480,157:8226,158:8220,159:8221,160:192,161:194,162:199,163:200,164:202,165:203,166:235,167:206,168:207,169:239,170:212,171:217,172:249,173:219,174:171,175:187,176:195,177:227,178:205,179:204,180:236,181:210,182:242,183:213,184:245,185:123,186:125,187:92,188:94,189:95,190:124,191:8764,192:196,193:228,194:214,195:246,196:223,197:165,198:164,199:9475,200:197,201:229,202:216,203:248,204:9487,205:9491,206:9495,207:9499},u=function(e){var t=e;return l.hasOwnProperty(e)&&(t=l[e]),String.fromCharCode(t)},c={17:1,18:3,21:5,22:7,23:9,16:11,19:12,20:14},g={17:2,18:4,21:6,22:8,23:10,19:13,20:15},f={25:1,26:3,29:5,30:7,31:9,24:11,27:12,28:14},m={25:2,26:4,29:6,30:8,31:10,27:13,28:15},p=["white","green","blue","cyan","red","yellow","magenta","black","transparent"],y;(function(e){e[e.ERROR=0]="ERROR",e[e.TEXT=1]="TEXT",e[e.WARNING=2]="WARNING",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e[e.DATA=3]="DATA"})(y||(y={}));var E=function(){function e(){this.time=null,this.verboseLevel=y.ERROR}var t=e.prototype;return t.log=function(e,t){if(this.verboseLevel>=e){var r="function"==typeof t?t():t;d.logger.log(this.time+" ["+e+"] "+r)}},e}(),T=function(e){for(var t=[],r=0;r<e.length;r++)t.push(e[r].toString(16));return t},h=function(){function e(e,t,r,a,n){this.foreground=void 0,this.underline=void 0,this.italics=void 0,this.background=void 0,this.flash=void 0,this.foreground=e||"white",this.underline=t||!1,this.italics=r||!1,this.background=a||"black",this.flash=n||!1}var t=e.prototype;return t.reset=function(){this.foreground="white",this.underline=!1,this.italics=!1,this.background="black",this.flash=!1},t.setStyles=function(e){for(var t=["foreground","underline","italics","background","flash"],r=0,a;r<t.length;r++)a=t[r],e.hasOwnProperty(a)&&(this[a]=e[a])},t.isDefault=function(){return"white"===this.foreground&&!this.underline&&!this.italics&&"black"===this.background&&!this.flash},t.equals=function(e){return this.foreground===e.foreground&&this.underline===e.underline&&this.italics===e.italics&&this.background===e.background&&this.flash===e.flash},t.copy=function(e){this.foreground=e.foreground,this.underline=e.underline,this.italics=e.italics,this.background=e.background,this.flash=e.flash},t.toString=function(){return"color="+this.foreground+", underline="+this.underline+", italics="+this.italics+", background="+this.background+", flash="+this.flash},e}(),S=function(){function e(e,t,r,a,n,s){this.uchar=void 0,this.penState=void 0,this.uchar=e||" ",this.penState=new h(t,r,a,n,s)}var t=e.prototype;return t.reset=function(){this.uchar=" ",this.penState.reset()},t.setChar=function(e,t){this.uchar=e,this.penState.copy(t)},t.setPenState=function(e){this.penState.copy(e)},t.equals=function(e){return this.uchar===e.uchar&&this.penState.equals(e.penState)},t.copy=function(e){this.uchar=e.uchar,this.penState.copy(e.penState)},t.isEmpty=function(){return" "===this.uchar&&this.penState.isDefault()},e}(),v=function(){function e(e){this.chars=void 0,this.pos=void 0,this.currPenState=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chars=[];for(var t=0;100>t;t++)this.chars.push(new S);this.logger=e,this.pos=0,this.currPenState=new h}var t=e.prototype;return t.equals=function(e){for(var t=!0,r=0;100>r;r++)if(!this.chars[r].equals(e.chars[r])){t=!1;break}return t},t.copy=function(e){for(var t=0;100>t;t++)this.chars[t].copy(e.chars[t])},t.isEmpty=function(){for(var e=!0,t=0;100>t;t++)if(!this.chars[t].isEmpty()){e=!1;break}return e},t.setCursor=function(e){this.pos!==e&&(this.pos=e),0>this.pos?(this.logger.log(y.DEBUG,"Negative cursor position "+this.pos),this.pos=0):100<this.pos&&(this.logger.log(y.DEBUG,"Too large cursor position "+this.pos),this.pos=100)},t.moveCursor=function(e){var t=this.pos+e;if(1<e)for(var r=this.pos+1;r<t+1;r++)this.chars[r].setPenState(this.currPenState);this.setCursor(t)},t.backSpace=function(){this.moveCursor(-1),this.chars[this.pos].setChar(" ",this.currPenState)},t.insertChar=function(e){var t=this;144<=e&&this.backSpace();var r=u(e);return 100<=this.pos?void this.logger.log(y.ERROR,function(){return"Cannot insert "+e.toString(16)+" ("+r+") at position "+t.pos+". Skipping it!"}):void(this.chars[this.pos].setChar(r,this.currPenState),this.moveCursor(1))},t.clearFromPos=function(e){var t;for(t=e;100>t;t++)this.chars[t].reset()},t.clear=function(){this.clearFromPos(0),this.pos=0,this.currPenState.reset()},t.clearToEndOfRow=function(){this.clearFromPos(this.pos)},t.getTextString=function(){for(var e=[],t=!0,r=0,a;100>r;r++)a=this.chars[r].uchar," "!==a&&(t=!1),e.push(a);return t?"":e.join("")},t.setPenStyles=function(e){this.currPenState.setStyles(e);var t=this.chars[this.pos];t.setPenState(this.currPenState)},e}(),L=function(){function e(e){this.rows=void 0,this.currRow=void 0,this.nrRollUpRows=void 0,this.lastOutputScreen=void 0,this.logger=void 0,this.rows=[];for(var t=0;15>t;t++)this.rows.push(new v(e));this.logger=e,this.currRow=14,this.nrRollUpRows=null,this.lastOutputScreen=null,this.reset()}var t=e.prototype;return t.reset=function(){for(var e=0;15>e;e++)this.rows[e].clear();this.currRow=14},t.equals=function(e){for(var t=!0,r=0;15>r;r++)if(!this.rows[r].equals(e.rows[r])){t=!1;break}return t},t.copy=function(e){for(var t=0;15>t;t++)this.rows[t].copy(e.rows[t])},t.isEmpty=function(){for(var e=!0,t=0;15>t;t++)if(!this.rows[t].isEmpty()){e=!1;break}return e},t.backSpace=function(){var e=this.rows[this.currRow];e.backSpace()},t.clearToEndOfRow=function(){var e=this.rows[this.currRow];e.clearToEndOfRow()},t.insertChar=function(e){var t=this.rows[this.currRow];t.insertChar(e)},t.setPen=function(e){var t=this.rows[this.currRow];t.setPenStyles(e)},t.moveCursor=function(e){var t=this.rows[this.currRow];t.moveCursor(e)},t.setCursor=function(e){this.logger.log(y.INFO,"setCursor: "+e);var t=this.rows[this.currRow];t.setCursor(e)},t.setPAC=function(e){this.logger.log(y.INFO,function(){return"pacData = "+JSON.stringify(e)});var t=e.row-1;if(this.nrRollUpRows&&t<this.nrRollUpRows-1&&(t=this.nrRollUpRows-1),this.nrRollUpRows&&this.currRow!==t){for(var r=0;15>r;r++)this.rows[r].clear();var a=this.currRow+1-this.nrRollUpRows,n=this.lastOutputScreen;if(n){var s=n.rows[a].cueStartTime,o=this.logger.time;if(s&&null!==o&&s<o)for(var d=0;d<this.nrRollUpRows;d++)this.rows[t-this.nrRollUpRows+d+1].copy(n.rows[a+d])}}this.currRow=t;var l=this.rows[this.currRow];if(null!==e.indent){var u=e.indent,c=Math.max(u-1,0);l.setCursor(e.indent),e.color=l.chars[c].penState.foreground}var g={foreground:e.color,underline:e.underline,italics:e.italics,background:"black",flash:!1};this.setPen(g)},t.setBkgData=function(e){this.logger.log(y.INFO,function(){return"bkgData = "+JSON.stringify(e)}),this.backSpace(),this.setPen(e),this.insertChar(32)},t.setRollUpRows=function(e){this.nrRollUpRows=e},t.rollUp=function(){var e=this;if(null===this.nrRollUpRows)return void this.logger.log(y.DEBUG,"roll_up but nrRollUpRows not set yet");this.logger.log(y.TEXT,function(){return e.getDisplayText()});var t=this.currRow+1-this.nrRollUpRows,r=this.rows.splice(t,1)[0];r.clear(),this.rows.splice(this.currRow,0,r),this.logger.log(y.INFO,"Rolling up")},t.getDisplayText=function(e){e=e||!1;for(var t=[],r="",a=-1,n=0,s;15>n;n++)s=this.rows[n].getTextString(),s&&(a=n+1,e?t.push("Row "+a+": '"+s+"'"):t.push(s.trim()));return 0<t.length&&(e?r="["+t.join(" | ")+"]":r=t.join("\n")),r},t.getTextAndFormat=function(){return this.rows},e}(),D=function(){function e(e,t,r){this.chNr=void 0,this.outputFilter=void 0,this.mode=void 0,this.verbose=void 0,this.displayedMemory=void 0,this.nonDisplayedMemory=void 0,this.lastOutputScreen=void 0,this.currRollUpRow=void 0,this.writeScreen=void 0,this.cueStartTime=void 0,this.logger=void 0,this.chNr=e,this.outputFilter=t,this.mode=null,this.verbose=0,this.displayedMemory=new L(r),this.nonDisplayedMemory=new L(r),this.lastOutputScreen=new L(r),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null,this.logger=r}var t=e.prototype;return t.reset=function(){this.mode=null,this.displayedMemory.reset(),this.nonDisplayedMemory.reset(),this.lastOutputScreen.reset(),this.outputFilter.reset(),this.currRollUpRow=this.displayedMemory.rows[14],this.writeScreen=this.displayedMemory,this.mode=null,this.cueStartTime=null},t.getHandler=function(){return this.outputFilter},t.setHandler=function(e){this.outputFilter=e},t.setPAC=function(e){this.writeScreen.setPAC(e)},t.setBkgData=function(e){this.writeScreen.setBkgData(e)},t.setMode=function(e){e===this.mode||(this.mode=e,this.logger.log(y.INFO,function(){return"MODE="+e}),"MODE_POP-ON"===this.mode?this.writeScreen=this.nonDisplayedMemory:(this.writeScreen=this.displayedMemory,this.writeScreen.reset()),"MODE_ROLL-UP"!==this.mode&&(this.displayedMemory.nrRollUpRows=null,this.nonDisplayedMemory.nrRollUpRows=null),this.mode=e)},t.insertChars=function(e){for(var t=this,r=0;r<e.length;r++)this.writeScreen.insertChar(e[r]);var a=this.writeScreen===this.displayedMemory?"DISP":"NON_DISP";this.logger.log(y.INFO,function(){return a+": "+t.writeScreen.getDisplayText(!0)}),("MODE_PAINT-ON"===this.mode||"MODE_ROLL-UP"===this.mode)&&(this.logger.log(y.TEXT,function(){return"DISPLAYED: "+t.displayedMemory.getDisplayText(!0)}),this.outputDataUpdate())},t.ccRCL=function(){this.logger.log(y.INFO,"RCL - Resume Caption Loading"),this.setMode("MODE_POP-ON")},t.ccBS=function(){this.logger.log(y.INFO,"BS - BackSpace"),"MODE_TEXT"===this.mode||(this.writeScreen.backSpace(),this.writeScreen===this.displayedMemory&&this.outputDataUpdate())},t.ccAOF=function(){},t.ccAON=function(){},t.ccDER=function(){this.logger.log(y.INFO,"DER- Delete to End of Row"),this.writeScreen.clearToEndOfRow(),this.outputDataUpdate()},t.ccRU=function(e){this.logger.log(y.INFO,"RU("+e+") - Roll Up"),this.writeScreen=this.displayedMemory,this.setMode("MODE_ROLL-UP"),this.writeScreen.setRollUpRows(e)},t.ccFON=function(){this.logger.log(y.INFO,"FON - Flash On"),this.writeScreen.setPen({flash:!0})},t.ccRDC=function(){this.logger.log(y.INFO,"RDC - Resume Direct Captioning"),this.setMode("MODE_PAINT-ON")},t.ccTR=function(){this.logger.log(y.INFO,"TR"),this.setMode("MODE_TEXT")},t.ccRTD=function(){this.logger.log(y.INFO,"RTD"),this.setMode("MODE_TEXT")},t.ccEDM=function(){this.logger.log(y.INFO,"EDM - Erase Displayed Memory"),this.displayedMemory.reset(),this.outputDataUpdate(!0)},t.ccCR=function(){this.logger.log(y.INFO,"CR - Carriage Return"),this.writeScreen.rollUp(),this.outputDataUpdate(!0)},t.ccENM=function(){this.logger.log(y.INFO,"ENM - Erase Non-displayed Memory"),this.nonDisplayedMemory.reset()},t.ccEOC=function(){var e=this;if(this.logger.log(y.INFO,"EOC - End Of Caption"),"MODE_POP-ON"===this.mode){var t=this.displayedMemory;this.displayedMemory=this.nonDisplayedMemory,this.nonDisplayedMemory=t,this.writeScreen=this.nonDisplayedMemory,this.logger.log(y.TEXT,function(){return"DISP: "+e.displayedMemory.getDisplayText()})}this.outputDataUpdate(!0)},t.ccTO=function(e){this.logger.log(y.INFO,"TO("+e+") - Tab Offset"),this.writeScreen.moveCursor(e)},t.ccMIDROW=function(e){var t={flash:!1,underline:1==e%2,italics:46<=e};if(!t.italics){var r=Math.floor(e/2)-16;t.foreground=["white","green","blue","cyan","red","yellow","magenta"][r]}else t.foreground="white";this.logger.log(y.INFO,"MIDROW: "+JSON.stringify(t)),this.writeScreen.setPen(t)},t.outputDataUpdate=function(e){void 0===e&&(e=!1);var t=this.logger.time;null===t||this.outputFilter&&(null!==this.cueStartTime||this.displayedMemory.isEmpty()?!this.displayedMemory.equals(this.lastOutputScreen)&&(this.outputFilter.newCue(this.cueStartTime,t,this.lastOutputScreen),e&&this.outputFilter.dispatchCue&&this.outputFilter.dispatchCue(),this.cueStartTime=this.displayedMemory.isEmpty()?null:t):this.cueStartTime=t,this.lastOutputScreen.copy(this.displayedMemory))},t.cueSplitAtTime=function(e){this.outputFilter&&!this.displayedMemory.isEmpty()&&(this.outputFilter.newCue&&this.outputFilter.newCue(this.cueStartTime,e,this.displayedMemory),this.cueStartTime=e)},e}(),k=function(){function e(e,t,r){this.channels=void 0,this.currentChannel=0,this.cmdHistory=void 0,this.logger=void 0;var a=new E;this.channels=[null,new D(e,t,a),new D(e+1,r,a)],this.cmdHistory=o(),this.logger=a}var t=e.prototype;return t.getHandler=function(e){return this.channels[e].getHandler()},t.setHandler=function(e,t){this.channels[e].setHandler(t)},t.addData=function(e,t){var r=!1,n,s,o;this.logger.time=e;for(var d=0;d<t.length;d+=2){if(s=127&t[d],o=127&t[d+1],0===s&&0===o)continue;else this.logger.log(y.DATA,"["+T([t[d],t[d+1]])+"] -> ("+T([s,o])+")");if(n=this.parseCmd(s,o),n||(n=this.parseMidrow(s,o)),n||(n=this.parsePAC(s,o)),n||(n=this.parseBackgroundAttributes(s,o)),!n&&(r=this.parseChars(s,o),r)){var l=this.currentChannel;if(l&&0<l){var u=this.channels[l];u.insertChars(r)}else this.logger.log(y.WARNING,"No channel found yet. TEXT-MODE?")}n||r||this.logger.log(y.WARNING,"Couldn't parse cleaned data "+T([s,o])+" orig: "+T([t[d],t[d+1]]))}},t.parseCmd=function(e,t){var r=this.cmdHistory;if(!((20===e||28===e||21===e||29===e)&&32<=t&&47>=t||(23===e||31===e)&&33<=t&&35>=t))return!1;if(s(e,t,r))return n(null,null,r),this.logger.log(y.DEBUG,"Repeated command ("+T([e,t])+") is dropped"),!0;var a=20===e||21===e||23===e?1:2,i=this.channels[a];return 20===e||21===e||28===e||29===e?32===t?i.ccRCL():33===t?i.ccBS():34===t?i.ccAOF():35===t?i.ccAON():36===t?i.ccDER():37===t?i.ccRU(2):38===t?i.ccRU(3):39===t?i.ccRU(4):40===t?i.ccFON():41===t?i.ccRDC():42===t?i.ccTR():43===t?i.ccRTD():44===t?i.ccEDM():45===t?i.ccCR():46===t?i.ccENM():47==t&&i.ccEOC():i.ccTO(t-32),n(e,t,r),this.currentChannel=a,!0},t.parseMidrow=function(e,t){var r=0;if((17===e||25===e)&&32<=t&&47>=t){if(r=17===e?1:2,r!==this.currentChannel)return this.logger.log(y.ERROR,"Mismatch channel in midrow parsing"),!1;var a=this.channels[r];return!!a&&(a.ccMIDROW(t),this.logger.log(y.DEBUG,"MIDROW ("+T([e,t])+")"),!0)}return!1},t.parsePAC=function(e,t){var r=this.cmdHistory,a;if(!((17<=e&&23>=e||25<=e&&31>=e)&&64<=t&&127>=t||(16===e||24===e)&&64<=t&&95>=t))return!1;if(s(e,t,r))return n(null,null,r),!0;var i=23>=e?1:2;a=64<=t&&95>=t?1===i?c[e]:f[e]:1===i?g[e]:m[e];var o=this.channels[i];return!!o&&(o.setPAC(this.interpretPAC(a,t)),n(e,t,r),this.currentChannel=i,!0)},t.interpretPAC=function(e,t){var r={color:null,italics:!1,indent:null,underline:!1,row:e},a;return a=95<t?t-96:t-64,r.underline=1==(1&a),13>=a?r.color=["white","green","blue","cyan","red","yellow","magenta","white"][Math.floor(a/2)]:15>=a?(r.italics=!0,r.color="white"):r.indent=4*Math.floor((a-16)/2),r},t.parseChars=function(e,t){var r=null,a=null,s;if(25<=e?(s=2,a=e-8):(s=1,a=e),17<=a&&19>=a){var i;i=17===a?t+80:18===a?t+112:t+144,this.logger.log(y.INFO,"Special char '"+u(i)+"' in channel "+s),r=[i]}else 32<=e&&127>=e&&(r=0===t?[e]:[e,t]);if(r){var o=T(r);this.logger.log(y.DEBUG,"Char codes =  "+o.join(",")),n(e,t,this.cmdHistory)}return r},t.parseBackgroundAttributes=function(e,t){if(!((16===e||24===e)&&32<=t&&47>=t||(23===e||31===e)&&45<=t&&47>=t))return!1;var r={},a;16===e||24===e?(a=Math.floor((t-32)/2),r.background=p[a],1==t%2&&(r.background+="_semi")):45===t?r.background="transparent":(r.foreground="black",47==t&&(r.underline=!0));var s=23>=e?1:2,i=this.channels[s];return i.setBkgData(r),n(e,t,this.cmdHistory),!0},t.reset=function(){for(var e=0,t;e<Object.keys(this.channels).length;e++)t=this.channels[e],t&&t.reset();this.cmdHistory=o()},t.cueSplitAtTime=function(e){for(var t=0,r;t<this.channels.length;t++)r=this.channels[t],r&&r.cueSplitAtTime(e)},e}();const I=k},"./src/utils/codecs.ts":(e,t,r)=>{"use strict";function a(e,t){var r=s[t];return!!r&&!0===r[e.slice(0,4)]}function n(e,t){return MediaSource.isTypeSupported((t||"video")+"/mp4;codecs=\""+e+"\"")}r.r(t),r.d(t,{isCodecSupportedInMp4:()=>n,isCodecType:()=>a});var s={audio:{a3ds:!0,"ac-3":!0,"ac-4":!0,alac:!0,alaw:!0,dra1:!0,"dts+":!0,"dts-":!0,dtsc:!0,dtse:!0,dtsh:!0,"ec-3":!0,enca:!0,g719:!0,g726:!0,m4ae:!0,mha1:!0,mha2:!0,mhm1:!0,mhm2:!0,mlpa:!0,mp4a:!0,"raw ":!0,Opus:!0,opus:!0,samr:!0,sawb:!0,sawp:!0,sevc:!0,sqcp:!0,ssmv:!0,twos:!0,ulaw:!0},video:{avc1:!0,avc2:!0,avc3:!0,avc4:!0,avcp:!0,av01:!0,drac:!0,dva1:!0,dvav:!0,dvh1:!0,dvhe:!0,encv:!0,hev1:!0,hvc1:!0,mjp2:!0,mp4v:!0,mvc1:!0,mvc2:!0,mvc3:!0,mvc4:!0,resv:!0,rv60:!0,s263:!0,svc1:!0,svc2:!0,"vc-1":!0,vp08:!0,vp09:!0},text:{stpp:!0,wvtt:!0}}},"./src/utils/cues.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>i});var a=r("./src/utils/vttparser.ts"),n=r("./src/utils/webvtt-parser.ts"),s=r("./src/utils/texttrack-utils.ts");const i={newCue:function(e,t,i,o){for(var d=[],l=self.VTTCue||self.TextTrackCue,u=0,g,f,m,p,y;u<o.rows.length;u++)if(g=o.rows[u],m=!0,p=0,y="",!g.isEmpty()){for(var E=0;E<g.chars.length;E++)/\s/.test(g.chars[E].uchar)&&m?p++:(y+=g.chars[E].uchar,m=!1);g.cueStartTime=t,t===i&&(i+=1e-4),16<=p?p--:p++;var T=(0,a.fixLineBreaks)(y.trim()),h=(0,n.generateCueId)(t,i,T);e&&e.cues&&e.cues.getCueById(h)||(f=new l(t,i,T),f.id=h,f.line=u+1,f.align="left",f.position=10+Math.min(80,10*Math.floor(8*p/32)),d.push(f))}return e&&d.length&&(d.sort(function(e,t){return"auto"===e.line||"auto"===t.line?0:8<e.line&&8<t.line?t.line-e.line:e.line-t.line}),d.forEach(function(t){return(0,s.addCueToTrack)(e,t)})),d}}},"./src/utils/discontinuities.ts":(e,t,r)=>{"use strict";function a(e,t){for(var r=null,a=0,n=e.length,s;a<n;a++)if(s=e[a],s&&s.cc===t){r=s;break}return r}function n(e,t,r){return!!(t.details&&(r.endCC>r.startCC||e&&e.cc<r.startCC))}function s(e,t,r){void 0===r&&(r=0);var n=e.fragments,s=t.fragments;if(!s.length||!n.length)return void m.logger.log("No fragments to align");var i=a(n,s[0].cc);return i&&(!i||i.startPTS)?i:void m.logger.log("No frag in previous level to align on")}function o(e,t){if(e){var r=e.start+t;e.start=e.startPTS=r,e.endPTS=r+e.duration}}function d(e,t){for(var r=t.fragments,a=0,n=r.length;a<n;a++)o(r[a],e);t.fragmentHint&&o(t.fragmentHint,e),t.alignedSliding=!0}function l(e,t,r){t&&(u(e,r,t),!r.alignedSliding&&t.details&&c(r,t.details),!r.alignedSliding&&t.details&&!r.skippedSegments&&(0,p.adjustSliding)(t.details,r))}function u(e,t,r){if(n(e,r,t)){var a=s(r.details,t);a&&(0,f.isFiniteNumber)(a.start)&&(m.logger.log("Adjusting PTS using last level due to CC increase within current level "+t.url),d(a.start,t))}}function c(e,t){if(t.fragments.length&&e.hasProgramDateTime&&t.hasProgramDateTime){var r=t.fragments[0].programDateTime,a=e.fragments[0].programDateTime,n=(a-r)/1e3+t.fragments[0].start;n&&(0,f.isFiniteNumber)(n)&&(m.logger.log("Adjusting PTS using programDateTime delta "+(a-r)+"ms, sliding:"+n.toFixed(3)+" "+e.url+" "),d(n,e))}}function g(e,t){if(e.hasProgramDateTime&&t.hasProgramDateTime){var r=e.fragments,n=t.fragments;if(r.length&&n.length){var s=Math.round(n.length/2)-1,i=n[s],o=a(r,i.cc)||r[Math.round(r.length/2)-1],l=i.programDateTime,u=o.programDateTime;if(null!==l&&null!==u){var c=(u-l)/1e3-(o.start-i.start);d(c,e)}}}}r.r(t),r.d(t,{adjustSlidingStart:()=>d,alignMediaPlaylistByPDT:()=>g,alignPDT:()=>c,alignStream:()=>l,findDiscontinuousReferenceFrag:()=>s,findFirstFragWithCC:()=>a,shouldAlignOnDiscontinuities:()=>n});var f=r("./src/polyfills/number.ts"),m=r("./src/utils/logger.ts"),p=r("./src/controller/level-helper.ts")},"./src/utils/ewma-bandwidth-estimator.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>s});var a=r("./src/utils/ewma.ts"),n=function(){function e(e,t,r){this.defaultEstimate_=void 0,this.minWeight_=void 0,this.minDelayMs_=void 0,this.slow_=void 0,this.fast_=void 0,this.defaultEstimate_=r,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new a["default"](e),this.fast_=new a["default"](t)}var t=e.prototype;return t.update=function(e,t){var r=this.slow_,n=this.fast_;this.slow_.halfLife!==e&&(this.slow_=new a["default"](e,r.getEstimate(),r.getTotalWeight())),this.fast_.halfLife!==t&&(this.fast_=new a["default"](t,n.getEstimate(),n.getTotalWeight()))},t.sample=function(e,t){e=Math.max(e,this.minDelayMs_);var r=e/1e3,a=8*t/r;this.fast_.sample(r,a),this.slow_.sample(r,a)},t.canEstimate=function(){var e=this.fast_;return e&&e.getTotalWeight()>=this.minWeight_},t.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},t.destroy=function(){},e}();const s=n},"./src/utils/ewma.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>n});var a=function(){function e(e,t,r){void 0===t&&(t=0),void 0===r&&(r=0),this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=e,this.alpha_=e?Math.exp(Math.log(.5)/e):0,this.estimate_=t,this.totalWeight_=r}var t=e.prototype;return t.sample=function(e,t){var r=Math.pow(this.alpha_,e);this.estimate_=t*(1-r)+r*this.estimate_,this.totalWeight_+=e},t.getTotalWeight=function(){return this.totalWeight_},t.getEstimate=function(){if(this.alpha_){var e=1-Math.pow(this.alpha_,this.totalWeight_);if(e)return this.estimate_/e}return this.estimate_},e}();const n=a},"./src/utils/fetch-loader.ts":(e,t,r)=>{"use strict";function a(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,d(e,t)}function n(e){var t="function"==typeof Map?new Map:void 0;return n=function(e){function r(){return s(e,arguments,l(this).constructor)}if(null===e||!o(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof t){if(t.has(e))return t.get(e);t.set(e,r)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),d(r,e)},n(e)}function s(){return s=i()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var a=Function.bind.apply(e,n),s=new a;return r&&d(s,r.prototype),s},s.apply(null,arguments)}function i(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function o(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},u.apply(this,arguments)}function c(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(t){}return!1}function g(e,t){var r={method:"GET",mode:"cors",credentials:"same-origin",signal:t,headers:new self.Headers(u({},e.headers))};return e.rangeEnd&&r.headers.set("Range","bytes="+e.rangeStart+"-"+(e.rangeEnd-1+"")),r}function f(e,t){return new self.Request(e.url,t)}r.r(t),r.d(t,{default:()=>h,fetchSupported:()=>c});var m=r("./src/polyfills/number.ts"),p=r("./src/loader/load-stats.ts"),y=r("./src/demux/chunk-cache.ts"),E=function(){function e(e){this.fetchSetup=void 0,this.requestTimeout=void 0,this.request=void 0,this.response=void 0,this.controller=void 0,this.context=void 0,this.config=null,this.callbacks=null,this.stats=void 0,this.loader=null,this.fetchSetup=e.fetchSetup||f,this.controller=new self.AbortController,this.stats=new p.LoadStats}var t=e.prototype;return t.destroy=function(){this.loader=this.callbacks=null,this.abortInternal()},t.abortInternal=function(){var e=this.response;e&&e.ok||(this.stats.aborted=!0,this.controller.abort())},t.abort=function(){var e;this.abortInternal(),null!==(e=this.callbacks)&&void 0!==e&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.response)},t.load=function(e,t,r){var a=this,n=this.stats;if(n.loading.start)throw new Error("Loader can only be used once.");n.loading.start=self.performance.now();var s=g(e,this.controller.signal),i=r.onProgress,o="arraybuffer"===e.responseType,d=o?"byteLength":"length";this.context=e,this.config=t,this.callbacks=r,this.request=this.fetchSetup(e,s),self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(function(){a.abortInternal(),r.onTimeout(n,e,a.response)},t.timeout),self.fetch(this.request).then(function(r){if(a.response=a.loader=r,!r.ok){var s=r.status,d=r.statusText;throw new T(d||"fetch, bad network response",s,r)}return n.loading.first=Math.max(self.performance.now(),n.loading.start),n.total=parseInt(r.headers.get("Content-Length")||"0"),i&&(0,m.isFiniteNumber)(t.highWaterMark)?a.loadProgressively(r,n,e,t.highWaterMark,i):o?r.arrayBuffer():r.text()}).then(function(s){var o=a.response;self.clearTimeout(a.requestTimeout),n.loading.end=Math.max(self.performance.now(),n.loading.first);var l=s[d];l&&(n.loaded=n.total=l);var u={url:o.url,data:s};i&&!(0,m.isFiniteNumber)(t.highWaterMark)&&i(n,e,s,o),r.onSuccess(u,n,e,o)}).catch(function(t){if(self.clearTimeout(a.requestTimeout),!n.aborted){var s=t?t.code||0:0,i=t?t.message:null;r.onError({code:s,text:i},e,t?t.details:null)}})},t.getCacheAge=function(){var e=null;if(this.response){var t=this.response.headers.get("age");e=t?parseFloat(t):null}return e},t.loadProgressively=function(e,t,r,a,n){void 0===a&&(a=0);var s=new y["default"],i=e.body.getReader();return function o(){return i.read().then(function(i){if(i.done)return s.dataLength&&n(t,r,s.flush(),e),Promise.resolve(new ArrayBuffer(0));var d=i.value,l=d.length;return t.loaded+=l,l<a||s.dataLength?(s.push(d),s.dataLength>=a&&n(t,r,s.flush(),e)):n(t,r,d,e),o()}).catch(function(){return Promise.reject()})}()},e}(),T=function(e){function t(t,r,a){var n;return n=e.call(this,t)||this,n.code=void 0,n.details=void 0,n.code=r,n.details=a,n}return a(t,e),t}(n(Error));const h=E},"./src/utils/hex.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});const a={hexDump:function(e){for(var t="",r=0,a;r<e.length;r++)a=e[r].toString(16),2>a.length&&(a="0"+a),t+=a;return t}}},"./src/utils/imsc1-ttml-parser.ts":(e,t,r)=>{"use strict";function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1,r;t<arguments.length;t++)for(var a in r=arguments[t],r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e},a.apply(this,arguments)}function n(e,t,r,a,n){var i=(0,p.findBox)(new Uint8Array(e),["mdat"]);if(0===i.length)return void n(new Error("Could not parse IMSC1 mdat"));var o=i.map(function(e){return(0,T.utf8ArrayToStr)(e)}),d=(0,h.toTimescaleFromScale)(t,1,r);try{o.forEach(function(e){return a(s(e,d))})}catch(e){n(e)}}function s(e,t){var r=new DOMParser,n=r.parseFromString(e,"text/xml"),s=n.getElementsByTagName("tt")[0];if(!s)throw new Error("Invalid ttml");var u={frameRate:30,subFrameRate:1,frameRateMultiplier:0,tickRate:0},f=Object.keys(u).reduce(function(e,t){return e[t]=s.getAttribute("ttp:"+t)||u[t],e},{}),m="preserve"!==s.getAttribute("xml:space"),p=o(i(s,"styling","style")),y=o(i(s,"layout","region")),T=i(s,"body","[begin]");return[].map.call(T,function(e){var r=d(e,m);if(!r||!e.hasAttribute("begin"))return null;var n=g(e.getAttribute("begin"),f),s=g(e.getAttribute("dur"),f),i=g(e.getAttribute("end"),f);if(null===n)throw c(e);if(null===i){if(null===s)throw c(e);i=n+s}var o=new E["default"](n-t,i-t,r);o.id=(0,S.generateCueId)(o.startTime,o.endTime,o.text);var u=y[e.getAttribute("region")],T=p[e.getAttribute("style")],h=l(u,T,p),v=h.textAlign;if(v){var L=k[v];L&&(o.lineAlign=L),o.align=v}return a(o,h),o}).filter(function(e){return null!==e})}function i(e,t,r){var a=e.getElementsByTagName(t)[0];return a?[].slice.call(a.querySelectorAll(r)):[]}function o(e){return e.reduce(function(e,t){var r=t.getAttribute("xml:id");return r&&(e[r]=t),e},{})}function d(e,t){return[].slice.call(e.childNodes).reduce(function(e,r,a){var n;return"br"===r.nodeName&&a?e+"\n":null!==(n=r.childNodes)&&void 0!==n&&n.length?d(r,t):t?e+r.textContent.trim().replace(/\s+/g," "):e+r.textContent},"")}function l(e,t,r){var a=null,n=null!==e&&void 0!==e&&e.hasAttribute("style")?e.getAttribute("style"):null;return n&&r.hasOwnProperty(n)&&(a=r[n]),["displayAlign","textAlign","color","backgroundColor","fontSize","fontFamily"].reduce(function(r,n){var s=u(t,"http://www.w3.org/ns/ttml#styling",n)||u(e,"http://www.w3.org/ns/ttml#styling",n)||u(a,"http://www.w3.org/ns/ttml#styling",n);return s&&(r[n]=s),r},{})}function u(e,t,r){return e?e.hasAttributeNS(t,r)?e.getAttributeNS(t,r):null:null}function c(e){return new Error("Could not parse ttml timestamp "+e)}function g(e,t){if(!e)return null;var r=(0,y.parseTimeStamp)(e);return null===r&&(L.test(e)?r=f(e,t):D.test(e)&&(r=m(e,t))),r}function f(e,t){var r=L.exec(e),a=(0|r[4])+(0|r[5])/t.subFrameRate;return 3600*(0|r[1])+60*(0|r[2])+(0|r[3])+a/t.frameRate}function m(e,t){var r=D.exec(e),a=+r[1],n=r[2];return"h"===n?3600*a:"m"===n?60*a:"ms"===n?1e3*a:"f"===n?a/t.frameRate:"t"===n?a/t.tickRate:a}r.r(t),r.d(t,{IMSC1_CODEC:()=>v,parseIMSC1:()=>n});var p=r("./src/utils/mp4-tools.ts"),y=r("./src/utils/vttparser.ts"),E=r("./src/utils/vttcue.ts"),T=r("./src/demux/id3.ts"),h=r("./src/utils/timescale-conversion.ts"),S=r("./src/utils/webvtt-parser.ts"),v="stpp.ttml.im1t",L=/^(\d{2,}):(\d{2}):(\d{2}):(\d{2})\.?(\d+)?$/,D=/^(\d*(?:\.\d*)?)(h|m|s|ms|f|t)$/,k={left:"start",center:"center",right:"end",start:"start",end:"end"}},"./src/utils/keysystem-util.ts":(e,t,r)=>{"use strict";function a(e){var t=i(e).subarray(0,16),r=new Uint8Array(16);return r.set(t,16-t.length),r}function n(e){var t=function(e,t,r){var a=e[t];e[t]=e[r],e[r]=a};t(e,0,3),t(e,1,2),t(e,4,5),t(e,6,7)}function s(e){var t=e.split(":"),r=null;if("data"===t[0]&&2===t.length){var n=t[1].split(";"),s=n[n.length-1].split(",");if(2===s.length){var i="base64"===s[0],d=s[1];i?(n.splice(-1,1),r=(0,o.base64Decode)(d)):r=a(d)}}return r}function i(e){return Uint8Array.from(unescape(encodeURIComponent(e)),function(e){return e.charCodeAt(0)})}r.r(t),r.d(t,{changeEndianness:()=>n,convertDataUriToArrayBytes:()=>s,strToUtf8array:()=>i});var o=r("./src/utils/numeric-encoding-utils.ts")},"./src/utils/logger.ts":(e,t,r)=>{"use strict";function a(e){var t=self.console[e];return t?t.bind(self.console,"["+e+"] >"):i}function n(e){for(var t=arguments.length,r=Array(1<t?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];r.forEach(function(t){d[t]=e[t]?e[t].bind(e):a(t)})}function s(e,t){if(self.console&&!0===e||"object"==typeof e){n(e,"debug","log","info","warn","error");try{d.log("Debug logs enabled for \""+t+"\"")}catch(t){d=o}}else d=o}r.r(t),r.d(t,{enableLogs:()=>s,logger:()=>l});var i=function(){},o={trace:i,debug:i,log:i,warn:i,info:i,error:i},d=o,l=d},"./src/utils/mediakeys-helper.ts":(e,t,r)=>{"use strict";function a(e){return e===u.FAIRPLAY?l.FAIRPLAY:e===u.PLAYREADY?l.PLAYREADY:e===u.WIDEVINE?l.WIDEVINE:e===u.CLEARKEY?l.CLEARKEY:void 0}function n(e){if(e===c.WIDEVINE)return l.WIDEVINE}function s(e){return e===l.FAIRPLAY?u.FAIRPLAY:e===l.PLAYREADY?u.PLAYREADY:e===l.WIDEVINE?u.WIDEVINE:e===l.CLEARKEY?u.CLEARKEY:void 0}function i(e){var t=e.drmSystems,r=e.widevineLicenseUrl,a=t?[l.FAIRPLAY,l.WIDEVINE,l.PLAYREADY,l.CLEARKEY].filter(function(e){return!!t[e]}):[];return!a[l.WIDEVINE]&&r&&a.push(l.WIDEVINE),a}function o(e,t,r,a){var n;switch(e){case l.FAIRPLAY:n=["cenc","sinf"];break;case l.WIDEVINE:case l.PLAYREADY:n=["cenc"];break;case l.CLEARKEY:n=["cenc","keyids"];break;default:throw new Error("Unknown key-system: "+e);}return d(n,t,r,a)}function d(e,t,r,a){var n={initDataTypes:e,persistentState:a.persistentState||"not-allowed",distinctiveIdentifier:a.distinctiveIdentifier||"not-allowed",sessionTypes:a.sessionTypes||[a.sessionType||"temporary"],audioCapabilities:t.map(function(e){return{contentType:"audio/mp4; codecs=\""+e+"\"",robustness:a.audioRobustness||"",encryptionScheme:a.audioEncryptionScheme||null}}),videoCapabilities:r.map(function(e){return{contentType:"video/mp4; codecs=\""+e+"\"",robustness:a.videoRobustness||"",encryptionScheme:a.videoEncryptionScheme||null}})};return[n]}r.r(t),r.d(t,{KeySystemFormats:()=>u,KeySystemIds:()=>c,KeySystems:()=>l,getKeySystemsForConfig:()=>i,getSupportedMediaKeySystemConfigurations:()=>o,keySystemDomainToKeySystemFormat:()=>s,keySystemFormatToKeySystemDomain:()=>a,keySystemIdToKeySystemDomain:()=>n,requestMediaKeySystemAccess:()=>g});var l;(function(e){e.CLEARKEY="org.w3.clearkey",e.FAIRPLAY="com.apple.fps",e.PLAYREADY="com.microsoft.playready",e.WIDEVINE="com.widevine.alpha"})(l||(l={}));var u;(function(e){e.CLEARKEY="org.w3.clearkey",e.FAIRPLAY="com.apple.streamingkeydelivery",e.PLAYREADY="com.microsoft.playready",e.WIDEVINE="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"})(u||(u={}));var c;(function(e){e.WIDEVINE="edef8ba979d64acea3c827dcd51d21ed"})(c||(c={}));var g=function(){return"undefined"!=typeof self&&self.navigator&&self.navigator.requestMediaKeySystemAccess?self.navigator.requestMediaKeySystemAccess.bind(self.navigator):null}()},"./src/utils/mediasource-helper.ts":(e,t,r)=>{"use strict";function a(){return self.MediaSource||self.WebKitMediaSource}r.r(t),r.d(t,{getMediaSource:()=>a})},"./src/utils/mp4-tools.ts":(e,t,r)=>{"use strict";function a(e){return String.fromCharCode.apply(null,e)}function n(e,t){var r=e[t]<<8|e[t+1];return 0>r?65536+r:r}function s(e,t){var r=i(e,t);return 0>r?4294967296+r:r}function i(e,t){return e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function o(e,t,r){e[t]=r>>24,e[t+1]=255&r>>16,e[t+2]=255&r>>8,e[t+3]=255&r}function d(e,t){var r=[];if(!t.length)return r;for(var n=e.byteLength,o=0;o<n;){var l=s(e,o),u=a(e.subarray(o+4,o+8)),c=1<l?o+l:n;if(u===t[0])if(1===t.length)r.push(e.subarray(o+8,c));else{var g=d(e.subarray(o+8,c),t.slice(1));g.length&&O.apply(r,g)}o=c}return r}function l(e){var t=[],r=e[0],a=8,o=s(e,a);a+=4;a+=0===r?8:16,a+=2;var d=e.length+0,l=n(e,a);a+=2;for(var u=0;u<l;u++){var c=a,g=s(e,c);c+=4;var f=2147483647&g;if(1===(2147483648&g)>>>31)return console.warn("SIDX has hierarchical references (not supported)"),null;var m=s(e,c);c+=4,t.push({referenceSize:f,subsegmentDuration:m,info:{duration:m/o,start:d,end:d+f-1}}),d+=f,c+=4,a=c}return{earliestPresentationTime:0,timescale:o,version:r,referencesCount:l,references:t}}function u(e){for(var t=[],r=d(e,["moov","trak"]),n=0;n<r.length;n++){var o=r[n],l=d(o,["tkhd"])[0];if(l){var u=l[0],c=0===u?12:20,g=s(l,c),f=d(o,["mdia","mdhd"])[0];if(f){u=f[0],c=0===u?12:20;var m=s(f,c),p=d(o,["mdia","hdlr"])[0];if(p){var y=a(p.subarray(8,12)),E={soun:b.ElementaryStreamTypes.AUDIO,vide:b.ElementaryStreamTypes.VIDEO}[y];if(E){var T=d(o,["mdia","minf","stbl","stsd"])[0],h=void 0;T&&(h=a(T.subarray(12,16))),t[g]={timescale:m,type:E},t[E]={timescale:m,id:g,codec:h}}}}}}var S=d(e,["moov","mvex","trex"]);return S.forEach(function(e){var r=s(e,4),a=t[r];a&&(a.default={duration:s(e,12),flags:s(e,20)})}),t}function c(e,t){if(!e||!t)return e;var r=t.keyId;if(r&&t.isCommonEncryption){var a=d(e,["moov","trak"]);a.forEach(function(e){var t=d(e,["mdia","minf","stbl","stsd"])[0],a=t.subarray(8),n=d(a,["enca"]),s=0<n.length;s||(n=d(a,["encv"])),n.forEach(function(e){var t=s?e.subarray(28):e.subarray(78),a=d(t,["sinf"]);a.forEach(function(e){var t=g(e);if(t){var a=t.subarray(8,24);a.some(function(e){return 0!==e})||(x.logger.log("[eme] Patching keyId in 'enc"+(s?"a":"v")+">sinf>>tenc' box: "+P["default"].hexDump(a)+" -> "+P["default"].hexDump(r)),t.set(r,8))}})})})}return e}function g(e){var t=d(e,["schm"])[0];if(t){var r=a(t.subarray(4,8));if("cbcs"===r||"cenc"===r)return d(e,["schi","tenc"])[0]}return x.logger.error("[eme] missing 'schm' box"),null}function f(e,t){return d(t,["moof","traf"]).reduce(function(t,r){var a=d(r,["tfdt"])[0],n=a[0],i=d(r,["tfhd"]).reduce(function(t,r){var i=s(r,4),o=e[i];if(o){var d=s(a,4);1===n&&(d*=Math.pow(2,32),d+=s(a,8));var l=o.timescale||9e4,u=d/l;if(isFinite(u)&&(null===t||u<t))return u}return t},null);return null!==i&&isFinite(i)&&(null===t||i<t)?i:t},null)||0}function m(e,t){for(var r=0,a=0,n=0,o=d(e,["moof","traf"]),u=0;u<o.length;u++){var c=o[u],g=d(c,["tfhd"])[0],f=s(g,4),m=t[f];if(m){var y=m.default,E=s(g,0)|(null===y||void 0===y?void 0:y.flags),T=null===y||void 0===y?void 0:y.duration;8&E&&(2&E?T=s(g,12):T=s(g,8));for(var h=m.timescale||9e4,S=d(c,["trun"]),v=0;v<S.length;v++){if(r=p(S[v]),!r&&T){var L=s(S[v],4);r=T*L}m.type===b.ElementaryStreamTypes.VIDEO?a+=r/h:m.type===b.ElementaryStreamTypes.AUDIO&&(n+=r/h)}}}if(0===a&&0===n){for(var D=0,k=d(e,["sidx"]),I=0,A;I<k.length;I++)A=l(k[I]),null!==A&&void 0!==A&&A.references&&(D+=A.references.reduce(function(e,t){return e+t.info.duration||0},0));return D}return a?a:n}function p(e){var t=s(e,0),r=8;1&t&&(r+=4),4&t&&(r+=4);for(var a=0,n=s(e,4),o=0;o<n;o++){if(256&t){var d=s(e,r);a+=d,r+=4}512&t&&(r+=4),1024&t&&(r+=4),2048&t&&(r+=4)}return a}function y(e,t,r){d(t,["moof","traf"]).forEach(function(t){d(t,["tfhd"]).forEach(function(a){var n=s(a,4),i=e[n];if(i){var l=i.timescale||9e4;d(t,["tfdt"]).forEach(function(e){var t=e[0],a=s(e,4);if(0===t)a-=r*l,a=Math.max(a,0),o(e,4,a);else{a*=Math.pow(2,32),a+=s(e,8),a-=r*l,a=Math.max(a,0);var n=Math.floor(a/4294967296),i=Math.floor(a%4294967296);o(e,4,n),o(e,8,i)}})}})})}function E(e){var t={valid:null,remainder:null},r=d(e,["moof"]);if(!r)return t;if(2>r.length)return t.remainder=e,t;var a=r[r.length-1];return t.valid=(0,C.sliceUint8)(e,0,a.byteOffset-8),t.remainder=(0,C.sliceUint8)(e,a.byteOffset-8),t}function T(e,t){var r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}function h(e,t){var r=[],a=t.samples,n=t.timescale,o=t.id,l=!1,u=d(a,["moof"]);return u.map(function(u){var c=u.byteOffset-8,g=d(u,["traf"]);g.map(function(u){var g=d(u,["tfdt"]).map(function(e){var t=e[0],r=s(e,4);return 1===t&&(r*=Math.pow(2,32),r+=s(e,8)),r/n})[0];return void 0!==g&&(e=g),d(u,["tfhd"]).map(function(g){var f=s(g,4),m=16777215&s(g,0),p=0,y=0,E=8;f===o&&(0!=(1&m)&&(E+=8),0!=(2&m)&&(E+=4),0!=(8&m)&&(p=s(g,E),E+=4),0!=(16&m)&&(y=s(g,E),E+=4),0!=(32&m)&&(E+=4),"video"===t.type&&(l=S(t.codec)),d(u,["trun"]).map(function(o){var d=o[0],u=16777215&s(o,0),g=0,f=0,m=0,E=0,T=s(o,4),h=8;0!=(1&u)&&(g=s(o,h),h+=4),0!=(4&u)&&(h+=4);for(var S=g+c,D=0;D<T;D++){if(0!=(256&u)?(f=s(o,h),h+=4):f=p,0!=(512&u)?(m=s(o,h),h+=4):m=y,0!=(1024&u)&&(h+=4),0!=(2048&u)&&(E=0===d?s(o,h):i(o,h),h+=4),t.type===b.ElementaryStreamTypes.VIDEO)for(var k=0,I;k<m;){if(I=s(a,S),S+=4,v(l,a[S])){var A=a.subarray(S,S+I);L(A,l?2:1,e+E/n,r)}S+=I,k+=I+4}e+=f/n}}))})})}),r}function S(e){if(!e)return!1;var t=e.indexOf("."),r=0>t?e:e.substring(0,t);return"hvc1"===r||"hev1"===r||"dvh1"===r||"dvhe"===r}function v(e,t){if(e){var r=63&t>>1;return 39==r||40===r}return 6==(31&t)}function L(e,t,r,a){var o=D(e),d=0;d+=t;for(var l=0,u=0,c=!1,g=0;d<o.length;){l=0;do{if(d>=o.length)break;g=o[d++],l+=g}while(255===g);u=0;do{if(d>=o.length)break;g=o[d++],u+=g}while(255===g);var f=o.length-d;if(!c&&4===l&&d<o.length){c=!0;var m=o[d++];if(181===m){var p=n(o,d);if(d+=2,49===p){var y=s(o,d);if(d+=4,1195456820===y){var E=o[d++];if(3===E){var T=o[d++],h=64&T,S=h?2+3*(31&T):0,v=new Uint8Array(S);if(h){v[0]=T;for(var L=1;L<S;L++)v[L]=o[d++]}a.push({type:E,payloadType:l,pts:r,bytes:v})}}}}}else if(5===l&&u<f){if(c=!0,16<u){for(var k=[],I=0,A;16>I;I++)A=o[d++].toString(16),k.push(1==A.length?"0"+A:A),(3==I||5===I||7===I||9===I)&&k.push("-");for(var R=u-16,C=new Uint8Array(R),x=0;x<R;x++)C[x]=o[d++];a.push({payloadType:l,pts:r,uuid:k.join(""),userData:(0,_.utf8ArrayToStr)(C),userDataBytes:C})}}else if(u<f)d+=u;else if(u>f)break}}function D(e){for(var t=e.byteLength,r=[],a=1;a<t-2;)0===e[a]&&0===e[a+1]&&3===e[a+2]?(r.push(a+2),a+=2):a++;if(0===r.length)return e;var n=t-r.length,s=new Uint8Array(n),o=0;for(a=0;a<n;o++,a++)o===r[0]&&(o++,r.shift()),s[a]=e[o];return s}function k(e){var t=e[0],r="",n="",i=0,o=0,d=0,l=0,u=0,c=0;if(0===t){for(;"\0"!==a(e.subarray(c,c+1));)r+=a(e.subarray(c,c+1)),c+=1;for(r+=a(e.subarray(c,c+1)),c+=1;"\0"!==a(e.subarray(c,c+1));)n+=a(e.subarray(c,c+1)),c+=1;n+=a(e.subarray(c,c+1)),c+=1,i=s(e,12),o=s(e,16),l=s(e,20),u=s(e,24),c=28}else if(1===t){c+=4,i=s(e,c),c+=4;var g=s(e,c);c+=4;var f=s(e,c);for(c+=4,d=Math.pow(2,32)*g+f,Number.isSafeInteger(d)||(d=Number.MAX_SAFE_INTEGER,console.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),l=s(e,c),c+=4,u=s(e,c),c+=4;"\0"!==a(e.subarray(c,c+1));)r+=a(e.subarray(c,c+1)),c+=1;for(r+=a(e.subarray(c,c+1)),c+=1;"\0"!==a(e.subarray(c,c+1));)n+=a(e.subarray(c,c+1)),c+=1;n+=a(e.subarray(c,c+1)),c+=1}var m=e.subarray(c,e.byteLength);return{schemeIdUri:r,value:n,timeScale:i,presentationTime:d,presentationTimeDelta:o,eventDuration:l,id:u,payload:m}}function I(e){for(var t=arguments.length,r=Array(1<t?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];for(var n=r.length,s=8,o=n;o--;)s+=r[o].byteLength;var d=new Uint8Array(s);for(d[0]=255&s>>24,d[1]=255&s>>16,d[2]=255&s>>8,d[3]=255&s,d.set(e,4),(o=0,s=8);o<n;o++)d.set(r[o],s),s+=r[o].byteLength;return d}function A(e,t,r){if(16!==e.byteLength)throw new RangeError("Invalid system id");var a,n;if(t){a=1,n=new Uint8Array(16*t.length);for(var s=0,i;s<t.length;s++){if(i=t[s],16!==i.byteLength)throw new RangeError("Invalid key");n.set(i,16*s)}}else a=0,n=new Uint8Array;var o;0<a?(o=new Uint8Array(4),0<t.length&&new DataView(o.buffer).setUint32(0,t.length,!1)):o=new Uint8Array;var d=new Uint8Array(4);return r&&0<r.byteLength&&new DataView(d.buffer).setUint32(0,r.byteLength,!1),I([112,115,115,104],new Uint8Array([a,0,0,0]),e,o,n,d,r||new Uint8Array)}function R(e){if(!(e instanceof ArrayBuffer)||32>e.byteLength)return null;var t={version:0,systemId:"",kids:null,data:null},r=new DataView(e),a=r.getUint32(0);if(e.byteLength!==a&&44<a)return null;var n=r.getUint32(4);if(1886614376!==n)return null;if(t.version=r.getUint32(8)>>>24,1<t.version)return null;t.systemId=P["default"].hexDump(new Uint8Array(e,12,16));var s=r.getUint32(28);if(0===t.version){if(a-32<s)return null;t.data=new Uint8Array(e,32,s)}else if(1===t.version){t.kids=[];for(var o=0;o<s;o++)t.kids.push(new Uint8Array(e,32+16*o,16))}return t}r.r(t),r.d(t,{RemuxerTrackIdConfig:()=>N,appendUint8Array:()=>T,bin2str:()=>a,computeRawDurationFromSamples:()=>p,discardEPB:()=>D,findBox:()=>d,getDuration:()=>m,getStartDTS:()=>f,mp4Box:()=>I,mp4pssh:()=>A,offsetStartDTS:()=>y,parseEmsg:()=>k,parseInitSegment:()=>u,parsePssh:()=>R,parseSEIMessageFromNALu:()=>L,parseSamples:()=>h,parseSegmentIndex:()=>l,parseSinf:()=>g,patchEncyptionData:()=>c,readSint32:()=>i,readUint16:()=>n,readUint32:()=>s,segmentValidRange:()=>E,writeUint32:()=>o});var b=r("./src/loader/fragment.ts"),C=r("./src/utils/typed-array.ts"),_=r("./src/demux/id3.ts"),x=r("./src/utils/logger.ts"),P=r("./src/utils/hex.ts"),F=Math.pow(2,32)-1,O=[].push,N={video:1,audio:2,id3:3,text:4}},"./src/utils/numeric-encoding-utils.ts":(e,t,r)=>{"use strict";function a(e){return e.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function n(e){return btoa(e)}function s(e){return atob(e)}function i(e){return btoa(String.fromCharCode.apply(String,e))}function o(e){return a(i(e))}function d(e){return Uint8Array.from(atob(e),function(e){return e.charCodeAt(0)})}r.r(t),r.d(t,{base64Decode:()=>d,base64DecodeToStr:()=>s,base64Encode:()=>i,base64ToBase64Url:()=>a,base64UrlEncode:()=>o,strToBase64Encode:()=>n})},"./src/utils/output-filter.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});var a=function(){function e(e,t){this.timelineController=void 0,this.cueRanges=[],this.trackName=void 0,this.startTime=null,this.endTime=null,this.screen=null,this.timelineController=e,this.trackName=t}var t=e.prototype;return t.dispatchCue=function(){null===this.startTime||(this.timelineController.addCues(this.trackName,this.startTime,this.endTime,this.screen,this.cueRanges),this.startTime=null)},t.newCue=function(e,t,r){(null===this.startTime||this.startTime>e)&&(this.startTime=e),this.endTime=t,this.screen=r,this.timelineController.createCaptionsTrack(this.trackName)},t.reset=function(){this.cueRanges=[],this.startTime=null},e}()},"./src/utils/texttrack-utils.ts":(e,t,r)=>{"use strict";function a(e,t){var r;try{r=new Event("addtrack")}catch(e){r=document.createEvent("Event"),r.initEvent("addtrack",!1,!1)}r.track=e,t.dispatchEvent(r)}function n(e,t){var r=e.mode;if("disabled"===r&&(e.mode="hidden"),e.cues&&!e.cues.getCueById(t.id))try{if(e.addCue(t),!e.cues.getCueById(t.id))throw new Error("addCue is failed for: "+t)}catch(r){l.logger.debug("[texttrack-utils]: "+r);var a=new self.TextTrackCue(t.startTime,t.endTime,t.text);a.id=t.id,e.addCue(a)}"disabled"===r&&(e.mode=r)}function s(e){var t=e.mode;if("disabled"===t&&(e.mode="hidden"),e.cues)for(var r=e.cues.length;r--;)e.removeCue(e.cues[r]);"disabled"===t&&(e.mode=t)}function i(e,t,r,a){var n=e.mode;if("disabled"===n&&(e.mode="hidden"),e.cues&&0<e.cues.length)for(var s=d(e.cues,t,r),o=0;o<s.length;o++)(!a||a(s[o]))&&e.removeCue(s[o]);"disabled"===n&&(e.mode=n)}function o(e,t){if(t<e[0].startTime)return 0;var r=e.length-1;if(t>e[r].endTime)return-1;for(var a=0,n=r,s;a<=n;)if(s=Math.floor((n+a)/2),t<e[s].startTime)n=s-1;else if(t>e[s].startTime&&a<r)a=s+1;else return s;return e[a].startTime-t<t-e[n].startTime?a:n}function d(e,t,r){var a=[],n=o(e,t);if(-1<n)for(var s=n,d=e.length,l;s<d;s++)if(l=e[s],l.startTime>=t&&l.endTime<=r)a.push(l);else if(l.startTime>r)return a;return a}r.r(t),r.d(t,{addCueToTrack:()=>n,clearCurrentCues:()=>s,getCuesInRange:()=>d,removeCuesInRange:()=>i,sendAddTrackEvent:()=>a});var l=r("./src/utils/logger.ts")},"./src/utils/time-ranges.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});const a={toString:function(e){for(var t="",r=e.length,a=0;a<r;a++)t+="["+e.start(a).toFixed(3)+"-"+e.end(a).toFixed(3)+"]";return t}}},"./src/utils/timescale-conversion.ts":(e,t,r)=>{"use strict";function a(e,t,r,a){void 0===r&&(r=1),void 0===a&&(a=!1);var n=e*t*r;return a?Math.round(n):n}function n(e,t,r,n){return void 0===r&&(r=1),void 0===n&&(n=!1),a(e,t,1/r,n)}function s(e,t){return void 0===t&&(t=!1),a(e,1e3,1/90000,t)}function i(e,t){return void 0===t&&(t=1),a(e,90000,1/t)}r.r(t),r.d(t,{toMpegTsClockFromTimescale:()=>i,toMsFromMpegTsClock:()=>s,toTimescaleFromBase:()=>a,toTimescaleFromScale:()=>n})},"./src/utils/typed-array.ts":(e,t,r)=>{"use strict";function a(e,t,r){return Uint8Array.prototype.slice?e.slice(t,r):new Uint8Array(Array.prototype.slice.call(e,t,r))}r.r(t),r.d(t,{sliceUint8:()=>a})},"./src/utils/vttcue.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>a});const a=function(){function e(e,t){if("string"!=typeof t)return!1;if(!Array.isArray(e))return!1;var r=t.toLowerCase();return!!~e.indexOf(r)&&r}function t(t){return e(s,t)}function r(t){return e(i,t)}function a(e){for(var t=arguments.length,r=Array(1<t?t-1:0),a=1;a<t;a++)r[a-1]=arguments[a];for(var n=1,s;n<arguments.length;n++)for(var o in s=arguments[n],s)e[o]=s[o];return e}function n(e,n,s){var i=this,o={enumerable:!0};i.hasBeenReset=!1;var d="",l=!1,u=e,c=n,g=s,f=null,m="",p=!0,y="auto",E="start",T=50,h="middle",S=50,v="middle";Object.defineProperty(i,"id",a({},o,{get:function(){return d},set:function(e){d=""+e}})),Object.defineProperty(i,"pauseOnExit",a({},o,{get:function(){return l},set:function(e){l=!!e}})),Object.defineProperty(i,"startTime",a({},o,{get:function(){return u},set:function(e){if("number"!=typeof e)throw new TypeError("Start time must be set to a number.");u=e,this.hasBeenReset=!0}})),Object.defineProperty(i,"endTime",a({},o,{get:function(){return c},set:function(e){if("number"!=typeof e)throw new TypeError("End time must be set to a number.");c=e,this.hasBeenReset=!0}})),Object.defineProperty(i,"text",a({},o,{get:function(){return g},set:function(e){g=""+e,this.hasBeenReset=!0}})),Object.defineProperty(i,"region",a({},o,{get:function(){return f},set:function(e){f=e,this.hasBeenReset=!0}})),Object.defineProperty(i,"vertical",a({},o,{get:function(){return m},set:function(e){var r=t(e);if(!1===r)throw new SyntaxError("An invalid or illegal string was specified.");m=r,this.hasBeenReset=!0}})),Object.defineProperty(i,"snapToLines",a({},o,{get:function(){return p},set:function(e){p=!!e,this.hasBeenReset=!0}})),Object.defineProperty(i,"line",a({},o,{get:function(){return y},set:function(e){if("number"!=typeof e&&"auto"!==e)throw new SyntaxError("An invalid number or illegal string was specified.");y=e,this.hasBeenReset=!0}})),Object.defineProperty(i,"lineAlign",a({},o,{get:function(){return E},set:function(e){var t=r(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");E=t,this.hasBeenReset=!0}})),Object.defineProperty(i,"position",a({},o,{get:function(){return T},set:function(e){if(0>e||100<e)throw new Error("Position must be between 0 and 100.");T=e,this.hasBeenReset=!0}})),Object.defineProperty(i,"positionAlign",a({},o,{get:function(){return h},set:function(e){var t=r(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");h=t,this.hasBeenReset=!0}})),Object.defineProperty(i,"size",a({},o,{get:function(){return S},set:function(e){if(0>e||100<e)throw new Error("Size must be between 0 and 100.");S=e,this.hasBeenReset=!0}})),Object.defineProperty(i,"align",a({},o,{get:function(){return v},set:function(e){var t=r(e);if(!t)throw new SyntaxError("An invalid or illegal string was specified.");v=t,this.hasBeenReset=!0}})),i.displayState=void 0}if("undefined"!=typeof self&&self.VTTCue)return self.VTTCue;var s=["","lr","rl"],i=["start","middle","end","left","right"];return n.prototype.getCueAsHTML=function(){var e=self.WebVTT;return e.convertCueToDOMTree(self,this.text)},n}()},"./src/utils/vttparser.ts":(e,t,r)=>{"use strict";function a(e){function t(e,t,r,a){return 3600*(0|e)+60*(0|t)+(0|r)+parseFloat(a||0)}var r=e.match(/^(?:(\d+):)?(\d{2}):(\d{2})(\.\d+)?/);return r?59<parseFloat(r[2])?t(r[2],r[3],0,r[4]):t(r[1],r[2],r[3],r[4]):null}function n(e,t,r,a){var n=a?e.split(a):[e];for(var s in n)if("string"==typeof n[s]){var i=n[s].split(r);if(2===i.length){var o=i[0],d=i[1];t(o,d)}}}function s(e,t,r){function s(){var t=a(e);if(null===t)throw new Error("Malformed timestamp: "+d);return e=e.replace(/^[^\sa-zA-Z-]+/,""),t}function i(e,t){var a=new l;n(e,function(e,t){var n;switch(e){case"region":for(var s=r.length-1;0<=s;s--)if(r[s].id===t){a.set(e,r[s].region);break}break;case"vertical":a.alt(e,t,["rl","lr"]);break;case"line":n=t.split(","),a.integer(e,n[0]),a.percent(e,n[0])&&a.set("snapToLines",!1),a.alt(e,n[0],["auto"]),2===n.length&&a.alt("lineAlign",n[1],["start",c,"end"]);break;case"position":n=t.split(","),a.percent(e,n[0]),2===n.length&&a.alt("positionAlign",n[1],["start",c,"end","line-left","line-right","auto"]);break;case"size":a.percent(e,t);break;case"align":a.alt(e,t,["start",c,"end","left","right"]);}},/:/,/\s/),t.region=a.get("region",null),t.vertical=a.get("vertical","");var s=a.get("line","auto");"auto"===s&&-1===u.line&&(s=-1),t.line=s,t.lineAlign=a.get("lineAlign","start"),t.snapToLines=a.get("snapToLines",!0),t.size=a.get("size",100),t.align=a.get("align",c);var i=a.get("position","auto");"auto"===i&&50===u.position&&(i="start"===t.align||"left"===t.align?0:"end"===t.align||"right"===t.align?100:50),t.position=i}function o(){e=e.replace(/^\s+/,"")}var d=e;if(o(),t.startTime=s(),o(),"-->"!==e.slice(0,3))throw new Error("Malformed time stamp (time stamps must be separated by '-->'): "+d);e=e.slice(3),o(),t.endTime=s(),o(),i(e,t)}function i(e){return e.replace(/<br(?: \/)?>/gi,"\n")}r.r(t),r.d(t,{VTTParser:()=>g,fixLineBreaks:()=>i,parseTimeStamp:()=>a});var o=r("./src/utils/vttcue.ts"),d=function(){function e(){}var t=e.prototype;return t.decode=function(e){if(!e)return"";if("string"!=typeof e)throw new Error("Error - expected string data.");return decodeURIComponent(encodeURIComponent(e))},e}(),l=function(){function e(){this.values=Object.create(null)}var t=e.prototype;return t.set=function(e,t){this.get(e)||""===t||(this.values[e]=t)},t.get=function(e,t,r){return r?this.has(e)?this.values[e]:t[r]:this.has(e)?this.values[e]:t},t.has=function(e){return e in this.values},t.alt=function(e,t,r){for(var a=0;a<r.length;++a)if(t===r[a]){this.set(e,t);break}},t.integer=function(e,t){/^-?\d+$/.test(t)&&this.set(e,parseInt(t,10))},t.percent=function e(t,r){if(/^([\d]{1,3})(\.[\d]*)?%$/.test(r)){var e=parseFloat(r);if(0<=e&&100>=e)return this.set(t,e),!0}return!1},e}(),u=new o["default"](0,0,""),c="middle"===u.align?"middle":"center",g=function(){function e(){this.state="INITIAL",this.buffer="",this.decoder=new d,this.regionList=[],this.cue=null,this.oncue=void 0,this.onparsingerror=void 0,this.onflush=void 0}var t=e.prototype;return t.parse=function(e){function t(){var e=a.buffer,t=0;for(e=i(e);t<e.length&&"\r"!==e[t]&&"\n"!==e[t];)++t;var r=e.slice(0,t);return"\r"===e[t]&&++t,"\n"===e[t]&&++t,a.buffer=e.slice(t),r}function r(e){n(e,function(){},/:/)}var a=this;e&&(a.buffer+=a.decoder.decode(e,{stream:!0}));try{var d="";if("INITIAL"===a.state){if(!/\r\n|\n/.test(a.buffer))return this;d=t();var l=d.match(/^()?WEBVTT([ \t].*)?$/);if(!l||!l[0])throw new Error("Malformed WebVTT signature.");a.state="HEADER"}for(var u=!1;a.buffer;){if(!/\r\n|\n/.test(a.buffer))return this;switch(u?u=!1:d=t(),a.state){case"HEADER":/:/.test(d)?r(d):!d&&(a.state="ID");continue;case"NOTE":d||(a.state="ID");continue;case"ID":if(/^NOTE($|[ \t])/.test(d)){a.state="NOTE";break}if(!d)continue;if(a.cue=new o["default"](0,0,""),a.state="CUE",-1===d.indexOf("-->")){a.cue.id=d;continue}case"CUE":if(!a.cue){a.state="BADCUE";continue}try{s(d,a.cue,a.regionList)}catch(t){a.cue=null,a.state="BADCUE";continue}a.state="CUETEXT";continue;case"CUETEXT":{var c=-1!==d.indexOf("-->");if(!d||c&&(u=!0)){a.oncue&&a.cue&&a.oncue(a.cue),a.cue=null,a.state="ID";continue}if(null===a.cue)continue;a.cue.text&&(a.cue.text+="\n"),a.cue.text+=d}continue;case"BADCUE":d||(a.state="ID");}}}catch(t){"CUETEXT"===a.state&&a.cue&&a.oncue&&a.oncue(a.cue),a.cue=null,a.state="INITIAL"===a.state?"BADWEBVTT":"BADCUE"}return this},t.flush=function(){var t=this;try{if((t.cue||"HEADER"===t.state)&&(t.buffer+="\n\n",t.parse()),"INITIAL"===t.state||"BADWEBVTT"===t.state)throw new Error("Malformed WebVTT signature.")}catch(r){t.onparsingerror&&t.onparsingerror(r)}return t.onflush&&t.onflush(),this},e}()},"./src/utils/webvtt-parser.ts":(e,t,r)=>{"use strict";function a(e,t,r){return f(e.toString())+f(t.toString())+f(r)}function n(e,t,r,n,s,f,p,y){var E=new i.VTTParser,T=(0,o.utf8ArrayToStr)(new Uint8Array(e)).trim().replace(u,"\n").split("\n"),h=[],S=(0,d.toMpegTsClockFromTimescale)(t,r),v="00:00.000",L=0,D=0,k=!0,I;E.oncue=function(e){var t=n[s],r=n.ccOffset,i=(L-S)/9e4;null!==t&&void 0!==t&&t.new&&(void 0===D?m(n,s,i):r=n.ccOffset=t.start),i&&(r=i-n.presentationOffset);var o=e.endTime-e.startTime,d=(0,l.normalizePts)(9e4*(e.startTime+r-D),9e4*f)/9e4;e.startTime=Math.max(d,0),e.endTime=Math.max(d+o,0);var u=e.text.trim();e.text=decodeURIComponent(encodeURIComponent(u)),e.id||(e.id=a(e.startTime,e.endTime,u)),0<e.endTime&&h.push(e)},E.onparsingerror=function(e){I=e},E.onflush=function(){return I?void y(I):void p(h)},T.forEach(function(e){if(k){if(c(e,"X-TIMESTAMP-MAP=")){k=!1,e.slice(16).split(",").forEach(function(e){c(e,"LOCAL:")?v=e.slice(6):c(e,"MPEGTS:")&&(L=parseInt(e.slice(7)))});try{D=g(v)/1e3}catch(e){I=e}return}""===e&&(k=!1)}E.parse(e+"\n")}),E.flush()}r.r(t),r.d(t,{generateCueId:()=>a,parseWebVTT:()=>n});var s=r("./src/polyfills/number.ts"),i=r("./src/utils/vttparser.ts"),o=r("./src/demux/id3.ts"),d=r("./src/utils/timescale-conversion.ts"),l=r("./src/remux/mp4-remuxer.ts"),u=/\r\n|\n\r|\n|\r/g,c=function(e,t,r){return void 0===r&&(r=0),e.slice(r,r+t.length)===t},g=function(e){var t=parseInt(e.slice(-3)),r=parseInt(e.slice(-6,-4)),a=parseInt(e.slice(-9,-7)),n=9<e.length?parseInt(e.substring(0,e.indexOf(":"))):0;if(!(0,s.isFiniteNumber)(t)||!(0,s.isFiniteNumber)(r)||!(0,s.isFiniteNumber)(a)||!(0,s.isFiniteNumber)(n))throw Error("Malformed X-TIMESTAMP-MAP: Local:"+e);return t+=1e3*r,t+=60000*a,t+=3600000*n,t},f=function e(t){for(var e=5381,r=t.length;r;)e=33*e^t.charCodeAt(--r);return(e>>>0).toString()},m=function(e,t,r){var a=e[t],n=e[a.prevCC];if(!n||!n.new&&a.new)return e.ccOffset=e.presentationOffset=a.start,void(a.new=!1);for(;null!==(s=n)&&void 0!==s&&s.new;){var s;e.ccOffset+=a.start-n.start,a.new=!1,a=n,n=e[a.prevCC]}e.presentationOffset=r}},"./src/utils/xhr-loader.ts":(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>i});var a=r("./src/utils/logger.ts"),n=r("./src/loader/load-stats.ts"),s=function(){function e(e){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=void 0,this.loader=null,this.stats=void 0,this.xhrSetup=e?e.xhrSetup:null,this.stats=new n.LoadStats,this.retryDelay=0}var t=e.prototype;return t.destroy=function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null},t.abortInternal=function(){var e=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),e&&(e.onreadystatechange=null,e.onprogress=null,4!==e.readyState&&(this.stats.aborted=!0,e.abort()))},t.abort=function(){var e;this.abortInternal(),null!==(e=this.callbacks)&&void 0!==e&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)},t.load=function(e,t,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=e,this.config=t,this.callbacks=r,this.retryDelay=t.retryDelay,this.loadInternal()},t.loadInternal=function(){var e=this.config,t=this.context;if(e){var r=this.loader=new self.XMLHttpRequest,a=this.stats;a.loading.first=0,a.loaded=0;var n=this.xhrSetup;try{if(n)try{n(r,t.url)}catch(a){r.open("GET",t.url,!0),n(r,t.url)}r.readyState||r.open("GET",t.url,!0);var s=this.context.headers;if(s)for(var i in s)r.setRequestHeader(i,s[i])}catch(a){return void this.callbacks.onError({code:r.status,text:a.message},t,r)}t.rangeEnd&&r.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),r.onreadystatechange=this.readystatechange.bind(this),r.onprogress=this.loadprogress.bind(this),r.responseType=t.responseType,self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),e.timeout),r.send()}},t.readystatechange=function(){var e=this.context,t=this.loader,r=this.stats;if(e&&t){var n=t.readyState,s=this.config;if(!r.aborted&&2<=n)if(self.clearTimeout(this.requestTimeout),0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start)),4===n){t.onreadystatechange=null,t.onprogress=null;var i=t.status,o="arraybuffer"===t.responseType;if(200<=i&&300>i&&(o&&t.response||null!==t.responseText)){r.loading.end=Math.max(self.performance.now(),r.loading.first);var d,l;if(o?(d=t.response,l=d.byteLength):(d=t.responseText,l=d.length),r.loaded=r.total=l,!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,e,d,t),!this.callbacks)return;var c={url:t.responseURL,data:d};this.callbacks.onSuccess(c,r,e,t)}else r.retry>=s.maxRetry||400<=i&&499>i?(a.logger.error(i+" while loading "+e.url),this.callbacks.onError({code:i,text:t.statusText},e,t)):(a.logger.warn(i+" while loading "+e.url+", retrying in "+this.retryDelay+"..."),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,s.maxRetryDelay),r.retry++)}else self.clearTimeout(this.requestTimeout),this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),s.timeout)}},t.loadtimeout=function(){a.logger.warn("timeout while loading "+this.context.url);var e=this.callbacks;e&&(this.abortInternal(),e.onTimeout(this.stats,this.context,this.loader))},t.loadprogress=function(e){var t=this.stats;t.loaded=e.loaded,e.lengthComputable&&(t.total=e.total)},t.getCacheAge=function(){var e=null;if(this.loader&&/^age:\s*[\d.]+\s*$/m.test(this.loader.getAllResponseHeaders())){var t=this.loader.getResponseHeader("age");e=t?parseFloat(t):null}return e},e}();const i=s},"./node_modules/eventemitter3/index.js":e=>{"use strict";function t(){}function r(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function a(e,t,a,n,s){if("function"!=typeof a)throw new TypeError("The listener must be a function");var i=new r(a,n||e,s),d=o?o+t:t;return e._events[d]?e._events[d].fn?e._events[d]=[e._events[d],i]:e._events[d].push(i):(e._events[d]=i,e._eventsCount++),e}function n(e,r){0==--e._eventsCount?e._events=new t:delete e._events[r]}function s(){this._events=new t,this._eventsCount=0}var i=Object.prototype.hasOwnProperty,o="~";Object.create&&(t.prototype=Object.create(null),!new t().__proto__&&(o=!1)),s.prototype.eventNames=function(){var e=[],t,r;if(0===this._eventsCount)return e;for(r in t=this._events)i.call(t,r)&&e.push(o?r.slice(1):r);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},s.prototype.listeners=function(e){var t=o?o+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var a=0,n=r.length,s=Array(n);a<n;a++)s[a]=r[a].fn;return s},s.prototype.listenerCount=function(e){var t=o?o+e:e,r=this._events[t];return r?r.fn?1:r.length:0},s.prototype.emit=function(e,t,r,a,n,s){var d=o?o+e:e;if(!this._events[d])return!1;var l=this._events[d],u=arguments.length,c,g;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),u){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,r),!0;case 4:return l.fn.call(l.context,t,r,a),!0;case 5:return l.fn.call(l.context,t,r,a,n),!0;case 6:return l.fn.call(l.context,t,r,a,n,s),!0;}for(g=1,c=Array(u-1);g<u;g++)c[g-1]=arguments[g];l.fn.apply(l.context,c)}else{var f=l.length,m;for(g=0;g<f;g++)switch(l[g].once&&this.removeListener(e,l[g].fn,void 0,!0),u){case 1:l[g].fn.call(l[g].context);break;case 2:l[g].fn.call(l[g].context,t);break;case 3:l[g].fn.call(l[g].context,t,r);break;case 4:l[g].fn.call(l[g].context,t,r,a);break;default:if(!c)for(m=1,c=Array(u-1);m<u;m++)c[m-1]=arguments[m];l[g].fn.apply(l[g].context,c);}}return!0},s.prototype.on=function(e,t,r){return a(this,e,t,r,!1)},s.prototype.once=function(e,t,r){return a(this,e,t,r,!0)},s.prototype.removeListener=function(e,t,r,a){var s=o?o+e:e;if(!this._events[s])return this;if(!t)return n(this,s),this;var d=this._events[s];if(d.fn)d.fn!==t||a&&!d.once||r&&d.context!==r||n(this,s);else{for(var l=0,u=[],c=d.length;l<c;l++)(d[l].fn!==t||a&&!d[l].once||r&&d[l].context!==r)&&u.push(d[l]);u.length?this._events[s]=1===u.length?u[0]:u:n(this,s)}return this},s.prototype.removeAllListeners=function(e){var r;return e?(r=o?o+e:e,this._events[r]&&n(this,r)):(this._events=new t,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=o,s.EventEmitter=s,e.exports=s},"./node_modules/url-toolkit/src/url-toolkit.js":function(e){(function(){var t={buildAbsoluteURL:function(e,r,a){if(a=a||{},e=e.trim(),r=r.trim(),!r){if(!a.alwaysNormalize)return e;var n=t.parseURL(e);if(!n)throw new Error("Error trying to parse base URL.");return n.path=t.normalizePath(n.path),t.buildURLFromParts(n)}var s=t.parseURL(r);if(!s)throw new Error("Error trying to parse relative URL.");if(s.scheme)return a.alwaysNormalize?(s.path=t.normalizePath(s.path),t.buildURLFromParts(s)):r;var i=t.parseURL(e);if(!i)throw new Error("Error trying to parse base URL.");if(!i.netLoc&&i.path&&"/"!==i.path[0]){var o=/^(?=([^\/?#]*))\1([^]*)$/.exec(i.path);i.netLoc=o[1],i.path=o[2]}i.netLoc&&!i.path&&(i.path="/");var d={scheme:i.scheme,netLoc:s.netLoc,path:null,params:s.params,query:s.query,fragment:s.fragment};if(!s.netLoc&&(d.netLoc=i.netLoc,"/"!==s.path[0]))if(!s.path)d.path=i.path,s.params||(d.params=i.params,!s.query&&(d.query=i.query));else{var l=i.path,u=l.substring(0,l.lastIndexOf("/")+1)+s.path;d.path=t.normalizePath(u)}return null===d.path&&(d.path=a.alwaysNormalize?t.normalizePath(s.path):s.path),t.buildURLFromParts(d)},parseURL:function(e){var t=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(/(?:\/|^)\.(?=\/)/g,"");e.length!==(e=e.replace(/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}};e.exports=t})(this)}},r={};e.m=t,(()=>{e.n=t=>{var r=t&&t.__esModule?()=>t["default"]:()=>t;return e.d(r,{a:r}),r}})(),(()=>{e.d=(t,r)=>{for(var a in r)e.o(r,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:r[a]})}})(),(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var a=e("./src/hls.ts");return a=a["default"],a})());

FWDEVPRegisterHLSError =  function(_s){
	_s.hlsJS.on(Hls.Events.ERROR, function(event,data) {
					
		_s.HLSError_str;
		switch(data.details) {
			case Hls.ErrorDetails.MANIFEST_LOAD_ERROR:
				try {
				 	_s.HLSError_str ="cannot load <a href=\"" + data.context.url + "\">" + url + "</a><br>HTTP response code:" + data.response.code + " <br>" + data.response.text;
					if(data.response.code === 0) {
					 _s.HLSError_str += "this might be a CORS issue, consider installing <a href=\"https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi\">Allow-Control-Allow-Origin</a> Chrome Extension";
					}
				}catch(err) {
				  _s.HLSError_str = "cannot load " + _s.videoSourcePath_str;
				  console.log(err);
				}
			break;
				default:
				 _s.HLSError_str = undefined;
				console.log(data.details);
			break;
		}
		
		if(_s.HLSError_str){
			if(console) console.log(_s.HLSError_str);
			if(_s.HLSError_str == 'bufferStalledError' || _s.HLSError_str == 'bufferSeekOverHole' ||  _s.HLSError_str == 'fragParsingError'){
				_s.HLSError_str =  undefined;
				return;
			}
			_s.info_do.allowToRemove_bl = false;
			_s.videoScreenErrorHandler({'text':_s.HLSError_str})
		}
	});
}