Skip to content

Instantly share code, notes, and snippets.

@gak4u
Created January 14, 2023 02:33
Show Gist options
  • Save gak4u/d89c299fbb4e8f7c9ca008f9f2359d52 to your computer and use it in GitHub Desktop.
Save gak4u/d89c299fbb4e8f7c9ca008f9f2359d52 to your computer and use it in GitHub Desktop.
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;(t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Hls=e()}}(function(){return(function e(t,r,i){function n(s,o){if(!r[s]){if(!t[s]){var l="function"==typeof require&&require;if(!o&&l)return l(s,!0);if(a)return a(s,!0);var u=Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=r[s]={exports:{}};t[s][0].call(d.exports,function(e){var r;return n(t[s][1][e]||e)},d,d.exports,e,t,r,i)}return r[s].exports}for(var a="function"==typeof require&&require,s=0;s<i.length;s++)n(i[s]);return n})({1:[function(e,t,r){function i(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function a(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._maxListeners=void 0,i.defaultMaxListeners=10,i.prototype.setMaxListeners=function(e){var t;if("number"!=typeof(t=e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},i.prototype.emit=function(e){var t,r,i,o,l,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||a(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(s(r=this._events[e]))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),r.apply(this,o)}else if(a(r))for(o=Array.prototype.slice.call(arguments,1),i=(u=r.slice()).length,l=0;i>l;l++)u[l].apply(this,o);return!0},i.prototype.addListener=function(e,t){var r;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?a(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,a(this._events[e])&&!this._events[e].warned&&(r=s(this._maxListeners)?i.defaultMaxListeners:this._maxListeners)&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.trace),this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},i.prototype.removeListener=function(e,t){var r,i,s,o;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(s=(r=this._events[e]).length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(a(r)){for(o=s;o-- >0;)if(r[o]===t||r[o].listener&&r[o].listener===t){i=o;break}if(0>i)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},i.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n(r=this._events[e]))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},i.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},i.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},i.listenerCount=function(e,t){return e.listenerCount(t)}},{}],2:[function(e,t,r){var i=arguments[3],n=arguments[4],a=arguments[5],s=JSON.stringify;t.exports=function(e){for(var t,r=Object.keys(a),o=0,l=r.length;l>o;o++){var u=r[o],d=a[u].exports;if(d===e||d.default===e){t=u;break}}if(!t){t=Math.floor(4294967296*Math.random()).toString(16);for(var f={},o=0,l=r.length;l>o;o++){var u=r[o];f[u]=u}n[t]=[Function(["require","module","exports"],"("+e+")(self)"),f]}var h=Math.floor(4294967296*Math.random()).toString(16),c={};c[t]=t,n[h]=[Function(["require"],"var f = require("+s(t)+");(f.default ? f.default : f)(self);"),c];var v="("+i+")({"+Object.keys(n).map(function(e){return s(e)+":["+n[e][0]+","+s(n[e][1])+"]"}).join(",")+"},{},["+s(h)+"])",g=window.URL||window.webkitURL||window.mozURL||window.msURL;return new Worker(g.createObjectURL(new Blob([v],{type:"text/javascript"})))}},{}],3:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=function(e){function t(e){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t);var r=function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.FRAG_LOAD_PROGRESS));return r.lastfetchlevel=0,r._autoLevelCapping=-1,r._nextAutoLevel=-1,r}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){l.default.prototype.destroy.call(this)}},{key:"onFragLoadProgress",value:function(e){var t=e.stats;void 0===t.aborted&&1===e.frag.loadCounter&&(this.lastfetchduration=(performance.now()-t.trequest)/1e3,this.lastfetchlevel=e.frag.level,this.lastbw=8*t.loaded/this.lastfetchduration)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping=e}},{key:"nextAutoLevel",get:function(){var e,t,r,i=this.lastbw,n=this.hls;if(r=-1===this._autoLevelCapping?n.levels.length-1:this._autoLevelCapping,-1!==this._nextAutoLevel){var a=Math.min(this._nextAutoLevel,r);if(a!==this.lastfetchlevel)return a;this._nextAutoLevel=-1}for(t=0;r>=t;t++)if((e=t<=this.lastfetchlevel?.8*i:.7*i)<n.levels[t].bitrate)return Math.max(0,t-1);return t-1},set:function(e){this._nextAutoLevel=e}}]),t}(l.default);r.default=u},{"../event-handler":20,"../events":21}],4:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=e("../utils/logger"),d=e("../errors"),f=function(e){function t(e){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t);var r=function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.MEDIA_ATTACHING,s.default.MEDIA_DETACHING,s.default.BUFFER_RESET,s.default.BUFFER_APPENDING,s.default.BUFFER_CODECS,s.default.BUFFER_EOS,s.default.BUFFER_FLUSHING));return r.onsbue=r.onSBUpdateEnd.bind(r),r.onsbe=r.onSBUpdateError.bind(r),r}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){l.default.prototype.destroy.call(this)}},{key:"onMediaAttaching",value:function(e){var t=this.media=e.media,r=this.mediaSource=new MediaSource;this.onmso=this.onMediaSourceOpen.bind(this),this.onmse=this.onMediaSourceEnded.bind(this),this.onmsc=this.onMediaSourceClose.bind(this),r.addEventListener("sourceopen",this.onmso),r.addEventListener("sourceended",this.onmse),r.addEventListener("sourceclose",this.onmsc),t.src=URL.createObjectURL(r)}},{key:"onMediaDetaching",value:function(){var e=this.mediaSource;if(e){if("open"===e.readyState)try{e.endOfStream()}catch(t){u.logger.warn("onMediaDetaching:"+t.message+" while calling endOfStream")}e.removeEventListener("sourceopen",this.onmso),e.removeEventListener("sourceended",this.onmse),e.removeEventListener("sourceclose",this.onmsc),this.media.src="",this.media.removeAttribute("src"),this.mediaSource=null,this.media=null,this.pendingTracks=null,this.sourceBuffer=null}this.onmso=this.onmse=this.onmsc=null,this.hls.trigger(s.default.MEDIA_DETACHED)}},{key:"onMediaSourceOpen",value:function(){u.logger.log("media source opened"),this.hls.trigger(s.default.MEDIA_ATTACHED,{media:this.media}),this.mediaSource.removeEventListener("sourceopen",this.onmso);var e=this.pendingTracks;e&&(this.onBufferCodecs(e),this.pendingTracks=null,this.doAppending())}},{key:"onMediaSourceClose",value:function(){u.logger.log("media source closed")}},{key:"onMediaSourceEnded",value:function(){u.logger.log("media source ended")}},{key:"onSBUpdateEnd",value:function(){this._needsFlush&&this.doFlush(),this._needsEos&&this.onBufferEos(),this.hls.trigger(s.default.BUFFER_APPENDED),this.doAppending()}},{key:"onSBUpdateError",value:function(e){u.logger.error("sourceBuffer error:"+e),this.hls.trigger(s.default.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1})}},{key:"onBufferReset",value:function(){var e=this.sourceBuffer;if(e){for(var t in e){var r=e[t];try{this.mediaSource.removeSourceBuffer(r),r.removeEventListener("updateend",this.onsbue),r.removeEventListener("error",this.onsbe)}catch(i){}}this.sourceBuffer=null}this.flushRange=[],this.appended=0}},{key:"onBufferCodecs",value:function(e){var t,r,i,n,a;if(!this.media)return void(this.pendingTracks=e);if(!this.sourceBuffer){var s={},o=this.mediaSource;for(r in e)n=(i=e[r]).levelCodec||i.codec,a=i.container+";codecs="+n,u.logger.log("creating sourceBuffer with mimeType:"+a),(t=s[r]=o.addSourceBuffer(a)).addEventListener("updateend",this.onsbue),t.addEventListener("error",this.onsbe);this.sourceBuffer=s}}},{key:"onBufferAppending",value:function(e){this.segments?this.segments.push(e):this.segments=[e],this.doAppending()}},{key:"onBufferAppendFail",value:function(e){u.logger.error("sourceBuffer error:"+e.event),this.hls.trigger(s.default.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.BUFFER_APPENDING_ERROR,fatal:!1,frag:this.fragCurrent})}},{key:"onBufferEos",value:function(){var e=this.sourceBuffer,t=this.mediaSource;t&&"open"===t.readyState&&(e.audio&&e.audio.updating||e.video&&e.video.updating?this._needsEos=!0:(u.logger.log("all media data available, signal endOfStream() to MediaSource and stop loading fragment"),t.endOfStream(),this._needsEos=!1))}},{key:"onBufferFlushing",value:function(e){this.flushRange.push({start:e.startOffset,end:e.endOffset}),this.flushBufferCounter=0,this.doFlush()}},{key:"doFlush",value:function(){for(;this.flushRange.length;){var e=this.flushRange[0];if(!this.flushBuffer(e.start,e.end))return void(this._needsFlush=!0);this.flushRange.shift(),this.flushBufferCounter=0}if(0===this.flushRange.length){this._needsFlush=!1;var t=0,r=this.sourceBuffer;if(r)for(var i in r)t+=r[i].buffered.length;this.appended=t,this.hls.trigger(s.default.BUFFER_FLUSHED)}}},{key:"doAppending",value:function(){var e=this.hls,t=this.sourceBuffer,r=this.segments;if(t){if(this.media.error)return r=[],void u.logger.error("trying to append although a media error occured, flush segment and abort");for(var i in t)if(t[i].updating)return;if(r.length){var n=r.shift();try{t[n.type].appendBuffer(n.data),this.appendError=0,this.appended++}catch(a){u.logger.error("error while trying to append buffer:"+a.message),r.unshift(n);var o={type:d.ErrorTypes.MEDIA_ERROR};if(22!==a.code){if(this.appendError?this.appendError++:this.appendError=1,o.details=d.ErrorDetails.BUFFER_APPEND_ERROR,o.frag=this.fragCurrent,this.appendError>e.config.appendErrorMaxRetry)return u.logger.log("fail "+e.config.appendErrorMaxRetry+" times to append segment in sourceBuffer"),r=[],o.fatal=!0,void e.trigger(s.default.ERROR,o);o.fatal=!1,e.trigger(s.default.ERROR,o)}else r=[],o.details=d.ErrorDetails.BUFFER_FULL_ERROR,e.trigger(s.default.ERROR,o)}}}}},{key:"flushBuffer",value:function(e,t){var r,i,n,a,s,o;if(this.flushBufferCounter<this.appended&&this.sourceBuffer)for(var l in this.sourceBuffer){if((r=this.sourceBuffer[l]).updating)return u.logger.warn("cannot flush, sb updating in progress"),!1;for(i=0;i<r.buffered.length;i++)if(n=r.buffered.start(i),a=r.buffered.end(i),-1!==navigator.userAgent.toLowerCase().indexOf("firefox")&&t===Number.POSITIVE_INFINITY?(s=e,o=t):(s=Math.max(n,e),o=Math.min(a,t)),Math.min(o,a)-s>.5)return this.flushBufferCounter++,u.logger.log("flush "+l+" ["+s+","+o+"], of ["+n+","+a+"], pos:"+this.media.currentTime),r.remove(s,o),!1}else u.logger.warn("abort flushing too many retries");return u.logger.log("buffer flushed"),!0}}]),t}(l.default);r.default=f},{"../errors":19,"../event-handler":20,"../events":21,"../utils/logger":34}],5:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=e("../utils/logger"),d=e("../errors"),f=function(e){function t(e){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t);var r=function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.MANIFEST_LOADED,s.default.LEVEL_LOADED,s.default.ERROR));return r.ontick=r.tick.bind(r),r._manualLevel=r._autoLevelCapping=-1,r}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){this.timer&&clearInterval(this.timer),this._manualLevel=-1}},{key:"startLoad",value:function(){this.canload=!0,this.timer&&this.tick()}},{key:"stopLoad",value:function(){this.canload=!1}},{key:"onManifestLoaded",value:function(e){var t,r,i=[],n=[],a={},o=!1,l=!1,f=this.hls;if(e.levels.forEach(function(e){e.videoCodec&&(o=!0),e.audioCodec&&(l=!0);var t=a[e.bitrate];void 0===t?(a[e.bitrate]=i.length,e.url=[e.url],e.urlId=0,i.push(e)):i[t].url.push(e.url)}),o&&l?i.forEach(function(e){e.videoCodec&&n.push(e)}):n=i,(n=n.filter(function(e){var t,r,i=e.audioCodec,n=e.videoCodec;return(!i||(t=i,MediaSource.isTypeSupported("audio/mp4;codecs="+t)))&&(!n||(r=n,MediaSource.isTypeSupported("video/mp4;codecs="+r)))})).length){for(t=n[0].bitrate,n.sort(function(e,t){return e.bitrate-t.bitrate}),this._levels=n,r=0;r<n.length;r++)if(n[r].bitrate===t){this._firstLevel=r,u.logger.log("manifest loaded,"+n.length+" level(s) found, first bitrate:"+t);break}f.trigger(s.default.MANIFEST_PARSED,{levels:this._levels,firstLevel:this._firstLevel,stats:e.stats})}else f.trigger(s.default.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:f.url,reason:"no level with compatible codecs found in manifest"})}},{key:"setLevelInternal",value:function(e){if(e>=0&&e<this._levels.length){this.timer&&(clearInterval(this.timer),this.timer=null),this._level=e,u.logger.log("switching to level "+e),this.hls.trigger(s.default.LEVEL_SWITCH,{level:e});var t=this._levels[e];if(void 0===t.details||!0===t.details.live){u.logger.log("(re)loading playlist for level "+e);var r=t.urlId;this.hls.trigger(s.default.LEVEL_LOADING,{url:t.url[r],level:e,id:r})}}else this.hls.trigger(s.default.ERROR,{type:d.ErrorTypes.OTHER_ERROR,details:d.ErrorDetails.LEVEL_SWITCH_ERROR,level:e,fatal:!1,reason:"invalid level idx"})}},{key:"onError",value:function(e){if(!e.fatal){var t,r,i=e.details,n=this.hls;switch(i){case d.ErrorDetails.FRAG_LOAD_ERROR:case d.ErrorDetails.FRAG_LOAD_TIMEOUT:case d.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case d.ErrorDetails.KEY_LOAD_ERROR:case d.ErrorDetails.KEY_LOAD_TIMEOUT:t=e.frag.level;break;case d.ErrorDetails.LEVEL_LOAD_ERROR:case d.ErrorDetails.LEVEL_LOAD_TIMEOUT:t=e.level}void 0!==t&&((r=this._levels[t]).urlId<r.url.length-1?(r.urlId++,r.details=void 0,u.logger.warn("level controller,"+i+" for level "+t+": switching to redundant stream id "+r.urlId)):-1===this._manualLevel&&t?(u.logger.warn("level controller,"+i+": emergency switch-down for next fragment"),n.abrController.nextAutoLevel=0):r&&r.details&&r.details.live?u.logger.warn("level controller,"+i+" on live stream, discard"):i!==d.ErrorDetails.FRAG_LOAD_ERROR&&i!==d.ErrorDetails.FRAG_LOAD_TIMEOUT&&(u.logger.error("cannot recover "+i+" error"),this._level=void 0,this.timer&&(clearInterval(this.timer),this.timer=null),e.fatal=!0,n.trigger(event,e)))}}},{key:"onLevelLoaded",value:function(e){e.details.live&&!this.timer&&(this.timer=setInterval(this.ontick,1e3*e.details.targetduration)),!e.details.live&&this.timer&&(clearInterval(this.timer),this.timer=null)}},{key:"tick",value:function(){var e=this._level;if(void 0!==e&&this.canload){var t=this._levels[e],r=t.urlId;this.hls.trigger(s.default.LEVEL_LOADING,{url:t.url[r],level:e,id:r})}}},{key:"levels",get:function(){return this._levels}},{key:"level",get:function(){return this._level},set:function(e){(this._level!==e||void 0===this._levels[e].details)&&this.setLevelInternal(e)}},{key:"manualLevel",get:function(){return this._manualLevel},set:function(e){this._manualLevel=e,-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){return void 0===this._startLevel?this._firstLevel:this._startLevel},set:function(e){this._startLevel=e}},{key:"nextLoadLevel",get:function(){return -1!==this._manualLevel?this._manualLevel:this.hls.abrController.nextAutoLevel},set:function(e){this.level=e,-1===this._manualLevel&&(this.hls.abrController.nextAutoLevel=e)}}]),t}(l.default);r.default=f},{"../errors":19,"../event-handler":20,"../events":21,"../utils/logger":34}],6:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../demux/demuxer"),s=i(a),o=e("../events"),l=i(o),u=e("../event-handler"),d=i(u),f=e("../utils/logger"),h=e("../utils/binary-search"),c=i(h),v=e("../helper/level-helper"),g=i(v),p=e("../errors"),$={STOPPED:"STOPPED",STARTING:"STARTING",IDLE:"IDLE",PAUSED:"PAUSED",KEY_LOADING:"KEY_LOADING",FRAG_LOADING:"FRAG_LOADING",FRAG_LOADING_WAITING_RETRY:"FRAG_LOADING_WAITING_RETRY",WAITING_LEVEL:"WAITING_LEVEL",PARSING:"PARSING",PARSED:"PARSED",ENDED:"ENDED",ERROR:"ERROR"},y=function(e){function t(e){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t);var r=function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,l.default.MEDIA_ATTACHED,l.default.MEDIA_DETACHING,l.default.MANIFEST_LOADING,l.default.MANIFEST_PARSED,l.default.LEVEL_LOADED,l.default.KEY_LOADED,l.default.FRAG_LOADED,l.default.FRAG_PARSING_INIT_SEGMENT,l.default.FRAG_PARSING_DATA,l.default.FRAG_PARSED,l.default.ERROR,l.default.BUFFER_APPENDED,l.default.BUFFER_FLUSHED));return r.config=e.config,r.audioCodecSwap=!1,r.ticks=0,r.ontick=r.tick.bind(r),r}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){this.stopLoad(),this.timer&&(clearInterval(this.timer),this.timer=null),d.default.prototype.destroy.call(this),this.state=$.STOPPED}},{key:"startLoad",value:function(){var e=arguments.length<=0||void 0===arguments[0]?0:arguments[0];if(this.levels){var t=this.media,r=this.lastCurrentTime;this.stopLoad(),this.demuxer=new s.default(this.hls),this.timer||(this.timer=setInterval(this.ontick,100)),this.level=-1,this.fragLoadError=0,t&&r?(f.logger.log("configure startPosition @"+r),this.lastPaused||(f.logger.log("resuming video"),t.play()),this.state=$.IDLE):(this.lastCurrentTime=this.startPosition?this.startPosition:e,this.state=$.STARTING),this.nextLoadPosition=this.startPosition=this.lastCurrentTime,this.tick()}else f.logger.warn("cannot start loading as manifest not parsed yet"),this.state=$.STOPPED}},{key:"stopLoad",value:function(){var e=this.fragCurrent;e&&(e.loader&&e.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.demuxer&&(this.demuxer.destroy(),this.demuxer=null),this.state=$.STOPPED}},{key:"tick",value:function(){this.ticks++,1===this.ticks&&(this.doTick(),this.ticks>1&&setTimeout(this.tick,1),this.ticks=0)}},{key:"doTick",value:function(){var e,t,r,i=this,n=this.hls,a=n.config;switch(this.state){case $.ERROR:case $.PAUSED:break;case $.STARTING:this.startLevel=n.startLevel,-1===this.startLevel&&(this.startLevel=0,this.fragBitrateTest=!0),this.level=n.nextLoadLevel=this.startLevel,this.state=$.WAITING_LEVEL,this.loadedmetadata=!1;break;case $.IDLE:if(!this.media&&(this.startFragRequested||!a.startFragPrefetch))break;e=this.loadedmetadata?this.media.currentTime:this.nextLoadPosition,t=!1===this.startFragRequested?this.startLevel:n.nextLoadLevel;var s,o=this.bufferInfo(e,a.maxBufferHole),u=o.len,d=o.end,h=this.fragPrevious;if((s=this.levels[t].hasOwnProperty("bitrate")?Math.min(s=Math.max(8*a.maxBufferSize/this.levels[t].bitrate,a.maxBufferLength),a.maxMaxBufferLength):a.maxBufferLength)>u){if(n.nextLoadLevel=t,this.level=t,void 0===(r=this.levels[t].details)||r.live&&this.levelLastLoaded!==t){this.state=$.WAITING_LEVEL;break}var v,g,y=r.fragments,m=y.length,E=y[0].start,_=y[m-1].start+y[m-1].duration,b=void 0;if(r.live){if(d<Math.max(E,_-(void 0!==a.liveMaxLatencyDuration?a.liveMaxLatencyDuration:a.liveMaxLatencyDurationCount*r.targetduration))){var R=void 0!==a.liveSyncDuration?a.liveSyncDuration:a.liveSyncDurationCount*r.targetduration;this.seekAfterBuffered=E+Math.max(0,r.totalduration-R),f.logger.log("buffer end: "+d+" is located too far from the end of live sliding playlist, media position will be reseted to: "+this.seekAfterBuffered.toFixed(3)),d=this.seekAfterBuffered}if(this.startFragRequested&&!r.PTSKnown){if(h){var L=h.sn+1;L>=r.startSN&&L<=r.endSN&&(b=y[L-r.startSN],f.logger.log("live playlist, switching playlist, load frag with next SN: "+b.sn))}b||(b=y[Math.min(m-1,Math.round(m/2))],f.logger.log("live playlist, switching playlist, unknown, load middle frag : "+b.sn))}}else E>d&&(b=y[0]);if(b||(v=void 0,g=a.maxFragLookUpTolerance,_>d?(d>_-g&&(g=0),v=c.default.search(y,function(e){return e.start+e.duration-g<=d?1:e.start-g>d?-1:0})):v=y[m-1],v&&(b=v,E=v.start,h&&b.level===h.level&&b.sn===h.sn&&(b.sn<r.endSN?(b=y[b.sn+1-r.startSN],f.logger.log("SN just loaded, load next one: "+b.sn)):(r.live||(i.hls.trigger(l.default.BUFFER_EOS),i.state=$.ENDED),b=null)))),b){if(null!=b.decryptdata.uri&&null==b.decryptdata.key)f.logger.log("Loading key for "+b.sn+" of ["+r.startSN+" ,"+r.endSN+"],level "+t),this.state=$.KEY_LOADING,n.trigger(l.default.KEY_LOADING,{frag:b});else{if(f.logger.log("Loading "+b.sn+" of ["+r.startSN+" ,"+r.endSN+"],level "+t+", currentTime:"+e+",bufferEnd:"+d.toFixed(3)),b.autoLevel=n.autoLevelEnabled,this.levels.length>1&&(b.expectedLen=Math.round(b.duration*this.levels[t].bitrate/8),b.trequest=performance.now()),void 0!==this.fragLoadIdx?this.fragLoadIdx++:this.fragLoadIdx=0,b.loadCounter){b.loadCounter++;var A=a.fragLoadingLoopThreshold;if(b.loadCounter>A&&Math.abs(this.fragLoadIdx-b.loadIdx)<A)return void n.trigger(l.default.ERROR,{type:p.ErrorTypes.MEDIA_ERROR,details:p.ErrorDetails.FRAG_LOOP_LOADING_ERROR,fatal:!1,frag:b})}else b.loadCounter=1;b.loadIdx=this.fragLoadIdx,this.fragCurrent=b,this.startFragRequested=!0,n.trigger(l.default.FRAG_LOADING,{frag:b}),this.state=$.FRAG_LOADING}}}break;case $.WAITING_LEVEL:(t=this.levels[this.level])&&t.details&&(this.state=$.IDLE);break;case $.FRAG_LOADING:var k=this.media,S=this.fragCurrent;if(k&&(!k.paused||!1===this.loadedmetadata)&&S.autoLevel&&this.level&&this.levels.length>1){var T=performance.now()-S.trequest;if(T>500*S.duration){var D=Math.max(1,1e3*S.loaded/T);S.expectedLen<S.loaded&&(S.expectedLen=S.loaded),e=k.currentTime;var P=(S.expectedLen-S.loaded)/D,w=this.bufferInfo(e,a.maxBufferHole).end-e;if(w<2*S.duration&&P>w){var x=void 0,O=void 0;for(O=this.level-1;O>=0&&(x=S.duration*this.levels[O].bitrate/(6.4*D),f.logger.log("fragLoadedDelay/bufferStarvationDelay/fragLevelNextLoadedDelay["+O+"] :"+P.toFixed(1)+"/"+w.toFixed(1)+"/"+x.toFixed(1)),!(w>x));O--);P>x&&(O=Math.max(0,O),n.nextLoadLevel=O,f.logger.warn("loading too slow, abort fragment loading and switch to level "+O),S.loader.abort(),n.trigger(l.default.FRAG_LOAD_EMERGENCY_ABORTED,{frag:S}),this.state=$.IDLE)}}}break;case $.FRAG_LOADING_WAITING_RETRY:var I=performance.now(),C=this.retryDate,F=this.media,N=F&&F.seeking;(!C||I>=C||N)&&(f.logger.log("mediaController: retryDate reached, switch back to IDLE state"),this.state=$.IDLE);case $.PARSING:case $.PARSED:case $.ENDED:}this._checkBuffer(),this._checkFragmentChanged()}},{key:"bufferInfo",value:function(e,t){var r=this.media;if(r){var i,n=r.buffered,a=[];for(i=0;i<n.length;i++)a.push({start:n.start(i),end:n.end(i)});return this.bufferedInfo(a,e,t)}return{len:0,start:0,end:0,nextStart:void 0}}},{key:"bufferedInfo",value:function(e,t,r){var i,n,a,s,o,l=[];for(e.sort(function(e,t){var r;return e.start-t.start||t.end-e.end}),o=0;o<e.length;o++){var u=l.length;if(u){var d=l[u-1].end;e[o].start-d<r?e[o].end>d&&(l[u-1].end=e[o].end):l.push(e[o])}else l.push(e[o])}for(o=0,i=0,n=a=t;o<l.length;o++){var f=l[o].start,h=l[o].end;if(t+r>=f&&h>t)n=f,i=(a=h)-t;else if(f>t+r){s=f;break}}return{len:i,start:n,end:a,nextStart:s}}},{key:"getBufferRange",value:function(e){var t,r,i=this.bufferRange;if(i){for(t=i.length-1;t>=0;t--)if(e>=(r=i[t]).start&&e<=r.end)return r}return null}},{key:"followingBufferRange",value:function(e){return e?this.getBufferRange(e.end+.5):null}},{key:"isBuffered",value:function(e){for(var t=this.media,r=t.buffered,i=0;i<r.length;i++)if(e>=r.start(i)&&e<=r.end(i))return!0;return!1}},{key:"_checkFragmentChanged",value:function(){var e,t,r=this.media;if(r&&!1===r.seeking&&((t=r.currentTime)>r.playbackRate*this.lastCurrentTime&&(this.lastCurrentTime=t),this.isBuffered(t)?e=this.getBufferRange(t):this.isBuffered(t+.1)&&(e=this.getBufferRange(t+.1)),e)){var i=e.frag;i!==this.fragPlaying&&(this.fragPlaying=i,this.hls.trigger(l.default.FRAG_CHANGED,{frag:i}))}}},{key:"immediateLevelSwitch",value:function(){f.logger.log("immediateLevelSwitch"),this.immediateSwitch||(this.immediateSwitch=!0,this.previouslyPaused=this.media.paused,this.media.pause());var e=this.fragCurrent;e&&e.loader&&e.loader.abort(),this.fragCurrent=null,this.hls.trigger(l.default.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY}),this.state=$.PAUSED,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold,this.tick()}},{key:"immediateLevelSwitchEnd",value:function(){this.immediateSwitch=!1,this.media.currentTime-=1e-4,this.previouslyPaused||this.media.play()}},{key:"nextLevelSwitch",value:function(){var e,t,r;if((t=this.getBufferRange(this.media.currentTime))&&t.start>1&&(this.hls.trigger(l.default.BUFFER_FLUSHING,{startOffset:0,endOffset:t.start-1}),this.state=$.PAUSED),this.media.paused)e=0;else{var i=this.hls.nextLoadLevel,n=this.levels[i],a=this.fragLastKbps;e=a&&this.fragCurrent?this.fragCurrent.duration*n.bitrate/(1e3*a)+1:0}if((r=this.getBufferRange(this.media.currentTime+e))&&(r=this.followingBufferRange(r))){this.hls.trigger(l.default.BUFFER_FLUSHING,{startOffset:r.start,endOffset:Number.POSITIVE_INFINITY}),this.state=$.PAUSED;var s=this.fragCurrent;s&&s.loader&&s.loader.abort(),this.fragCurrent=null,this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold}}},{key:"onMediaAttached",value:function(e){var t=this.media=e.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),this.onvended=this.onMediaEnded.bind(this),t.addEventListener("seeking",this.onvseeking),t.addEventListener("seeked",this.onvseeked),t.addEventListener("ended",this.onvended),this.levels&&this.config.autoStartLoad&&this.startLoad()}},{key:"onMediaDetaching",value:function(){var e=this.media;e&&e.ended&&(f.logger.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0);var t=this.levels;t&&t.forEach(function(e){e.details&&e.details.fragments.forEach(function(e){e.loadCounter=void 0})}),e&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("seeked",this.onvseeked),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvseeked=this.onvended=null),this.media=null,this.loadedmetadata=!1,this.stopLoad()}},{key:"onMediaSeeking",value:function(){if(this.state===$.FRAG_LOADING){if(0===this.bufferInfo(this.media.currentTime,this.config.maxBufferHole).len){f.logger.log("seeking outside of buffer while fragment load in progress, cancel fragment load");var e=this.fragCurrent;e&&(e.loader&&e.loader.abort(),this.fragCurrent=null),this.fragPrevious=null,this.state=$.IDLE}}else this.state===$.ENDED&&(this.state=$.IDLE);this.media&&(this.lastCurrentTime=this.media.currentTime),void 0!==this.fragLoadIdx&&(this.fragLoadIdx+=2*this.config.fragLoadingLoopThreshold),this.tick()}},{key:"onMediaSeeked",value:function(){this.tick()}},{key:"onMediaEnded",value:function(){f.logger.log("media ended"),this.startPosition=this.lastCurrentTime=0}},{key:"onManifestLoading",value:function(){f.logger.log("trigger BUFFER_RESET"),this.hls.trigger(l.default.BUFFER_RESET),this.bufferRange=[],this.stalled=!1}},{key:"onManifestParsed",value:function(e){var t,r=!1,i=!1;e.levels.forEach(function(e){(t=e.audioCodec)&&(-1!==t.indexOf("mp4a.40.2")&&(r=!0),-1!==t.indexOf("mp4a.40.5")&&(i=!0))}),this.audioCodecSwitch=r&&i,this.audioCodecSwitch&&f.logger.log("both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=e.levels,this.startLevelLoaded=!1,this.startFragRequested=!1,this.config.autoStartLoad&&this.startLoad()}},{key:"onLevelLoaded",value:function(e){var t=e.details,r=e.level,i=this.levels[r],n=t.totalduration,a=0;if(f.logger.log("level "+r+" loaded ["+t.startSN+","+t.endSN+"],duration:"+n),this.levelLastLoaded=r,t.live){var s=i.details;s?(g.default.mergeDetails(s,t),a=t.fragments[0].start,t.PTSKnown?f.logger.log("live playlist sliding:"+a.toFixed(3)):f.logger.log("live playlist - outdated PTS, unknown sliding")):(t.PTSKnown=!1,f.logger.log("live playlist - first load, unknown sliding"))}else t.PTSKnown=!1;if(i.details=t,this.hls.trigger(l.default.LEVEL_UPDATED,{details:t,level:r}),!1===this.startFragRequested){if(t.live){var o=void 0!==this.config.liveSyncDuration?this.config.liveSyncDuration:this.config.liveSyncDurationCount*t.targetduration;this.startPosition=Math.max(0,a+n-o)}this.nextLoadPosition=this.startPosition}this.state===$.WAITING_LEVEL&&(this.state=$.IDLE),this.tick()}},{key:"onKeyLoaded",value:function(){this.state===$.KEY_LOADING&&(this.state=$.IDLE,this.tick())}},{key:"onFragLoaded",value:function(e){var t=this.fragCurrent;if(this.state===$.FRAG_LOADING&&t&&e.frag.level===t.level&&e.frag.sn===t.sn){if(!0===this.fragBitrateTest)this.state=$.IDLE,this.fragBitrateTest=!1,e.stats.tparsed=e.stats.tbuffered=performance.now(),this.hls.trigger(l.default.FRAG_BUFFERED,{stats:e.stats,frag:t});else{this.state=$.PARSING,this.stats=e.stats;var r=this.levels[this.level],i=r.details,n=i.totalduration,a=t.start,s=t.level,o=t.sn,u=r.audioCodec||this.config.defaultAudioCodec;this.audioCodecSwap&&(f.logger.log("swapping playlist audio codec"),void 0===u&&(u=this.lastAudioCodec),u&&(u=-1!==u.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5")),this.pendingAppending=0,f.logger.log("Demuxing "+o+" of ["+i.startSN+" ,"+i.endSN+"],level "+s),this.demuxer.push(e.payload,u,r.videoCodec,a,t.cc,s,o,n,t.decryptdata)}}this.fragLoadError=0}},{key:"onFragParsingInitSegment",value:function(e){if(this.state===$.PARSING){var t,r,i=e.tracks;if(r=i.audio){var n=this.levels[this.level].audioCodec,a=navigator.userAgent.toLowerCase();n&&this.audioCodecSwap&&(f.logger.log("swapping playlist audio codec"),n=-1!==n.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),this.audioCodecSwitch&&1!==r.metadata.channelCount&&-1===a.indexOf("firefox")&&(n="mp4a.40.5"),-1!==a.indexOf("android")&&(n="mp4a.40.2",f.logger.log("Android: force audio codec to"+n)),r.levelCodec=n}if((r=i.video)&&(r.levelCodec=this.levels[this.level].videoCodec),e.unique){var s={codec:"",levelCodec:""};for(t in e.tracks)r=i[t],s.container=r.container,s.codec&&(s.codec+=",",s.levelCodec+=","),r.codec&&(s.codec+=r.codec),r.levelCodec&&(s.levelCodec+=r.levelCodec);i={audiovideo:s}}for(t in this.hls.trigger(l.default.BUFFER_CODECS,i),i){r=i[t],f.logger.log("track:"+t+",container:"+r.container+",codecs[level/parsed]=["+r.levelCodec+"/"+r.codec+"]");var o=r.initSegment;o&&(this.pendingAppending++,this.hls.trigger(l.default.BUFFER_APPENDING,{type:t,data:o}))}this.tick()}}},{key:"onFragParsingData",value:function(e){var t=this;if(this.state===$.PARSING){this.tparse2=Date.now();var r=this.levels[this.level],i=this.fragCurrent;f.logger.log("parsed "+e.type+",PTS:["+e.startPTS.toFixed(3)+","+e.endPTS.toFixed(3)+"],DTS:["+e.startDTS.toFixed(3)+"/"+e.endDTS.toFixed(3)+"],nb:"+e.nb);var n=g.default.updateFragPTS(r.details,i.sn,e.startPTS,e.endPTS),a=this.hls;a.trigger(l.default.LEVEL_PTS_UPDATED,{details:r.details,level:this.level,drift:n}),[e.data1,e.data2].forEach(function(r){r&&(t.pendingAppending++,a.trigger(l.default.BUFFER_APPENDING,{type:e.type,data:r}))}),this.nextLoadPosition=e.endPTS,this.bufferRange.push({type:e.type,start:e.startPTS,end:e.endPTS,frag:i}),this.tick()}else f.logger.warn("not in PARSING state but "+this.state+", ignoring FRAG_PARSING_DATA event")}},{key:"onFragParsed",value:function(){this.state===$.PARSING&&(this.stats.tparsed=performance.now(),this.state=$.PARSED,this._checkAppendedParsed())}},{key:"onBufferAppended",value:function(){switch(this.state){case $.PARSING:case $.PARSED:this.pendingAppending--,this._checkAppendedParsed()}}},{key:"_checkAppendedParsed",value:function(){if(this.state===$.PARSED&&0===this.pendingAppending){var e=this.fragCurrent,t=this.stats;e&&(this.fragPrevious=e,t.tbuffered=performance.now(),this.fragLastKbps=Math.round(8*t.length/(t.tbuffered-t.tfirst)),this.hls.trigger(l.default.FRAG_BUFFERED,{stats:t,frag:e}),f.logger.log("media buffered : "+this.timeRangesToString(this.media.buffered)),this.state=$.IDLE),this.tick()}}},{key:"onError",value:function(e){switch(e.details){case p.ErrorDetails.FRAG_LOAD_ERROR:case p.ErrorDetails.FRAG_LOAD_TIMEOUT:if(!e.fatal){var t=this.fragLoadError;if(t?t++:t=1,t<=this.config.fragLoadingMaxRetry){this.fragLoadError=t,e.frag.loadCounter=0;var r=Math.min(Math.pow(2,t-1)*this.config.fragLoadingRetryDelay,64e3);f.logger.warn("mediaController: frag loading failed, retry in "+r+" ms"),this.retryDate=performance.now()+r,this.state=$.FRAG_LOADING_WAITING_RETRY}else f.logger.error("mediaController: "+e.details+" reaches max retry, redispatch as fatal ..."),e.fatal=!0,this.hls.trigger(l.default.ERROR,e),this.state=$.ERROR}break;case p.ErrorDetails.FRAG_LOOP_LOADING_ERROR:case p.ErrorDetails.LEVEL_LOAD_ERROR:case p.ErrorDetails.LEVEL_LOAD_TIMEOUT:case p.ErrorDetails.KEY_LOAD_ERROR:case p.ErrorDetails.KEY_LOAD_TIMEOUT:f.logger.warn("mediaController: "+e.details+" while loading frag,switch to "+(e.fatal?"ERROR":"IDLE")+" state ..."),this.state=e.fatal?$.ERROR:$.IDLE;break;case p.ErrorDetails.BUFFER_FULL_ERROR:this.config.maxMaxBufferLength/=2,f.logger.warn("reduce max buffer length to "+this.config.maxMaxBufferLength+"s and trigger a nextLevelSwitch to flush old buffer and fix QuotaExceededError"),this.nextLevelSwitch()}}},{key:"_checkBuffer",value:function(){var e=this.media;if(e){var t=e.readyState;if(t){var r,i,n=this.seekAfterBuffered;n?e.duration>=n&&(r=n,this.seekAfterBuffered=void 0):(i=e.currentTime,!this.loadedmetadata&&e.buffered.length&&(this.loadedmetadata=!0,i||i===this.startPosition||(r=this.startPosition))),r&&(i=r,f.logger.log("target seek position:"+r));var a=this.bufferInfo(i,0),s=!(e.paused||e.ended||e.seeking||2>t),o=.4,u=i>e.playbackRate*this.lastCurrentTime;if(this.stalled&&u&&(this.stalled=!1,f.logger.log("playback not stuck anymore @"+i)),a.len<=o){if(u||!s?o=0:this.stalled||(f.logger.log("playback seems stuck @"+i),this.hls.trigger(l.default.ERROR,{type:p.ErrorTypes.MEDIA_ERROR,details:p.ErrorDetails.BUFFER_STALLED_ERROR,fatal:!1}),this.stalled=!0),a.len<=o){var d=a.nextStart,h=d-i;d&&h<this.config.maxSeekHole&&h>0&&!e.seeking&&(f.logger.log("adjust currentTime from "+e.currentTime+" to next buffered @ "+d),e.currentTime=d,this.hls.trigger(l.default.ERROR,{type:p.ErrorTypes.MEDIA_ERROR,details:p.ErrorDetails.BUFFER_SEEK_OVER_HOLE,fatal:!1}))}}else r&&e.currentTime!==r&&(f.logger.log("adjust currentTime from "+e.currentTime+" to "+r),e.currentTime=r)}}}},{key:"onBufferFlushed",value:function(){var e,t,r=[];for(t=0;t<this.bufferRange.length;t++)e=this.bufferRange[t],this.isBuffered((e.start+e.end)/2)&&r.push(e);this.bufferRange=r,this.immediateSwitch&&this.immediateLevelSwitchEnd(),this.state=$.IDLE,this.fragPrevious=null}},{key:"swapAudioCodec",value:function(){this.audioCodecSwap=!this.audioCodecSwap}},{key:"timeRangesToString",value:function(e){for(var t="",r=e.length,i=0;r>i;i++)t+="["+e.start(i)+","+e.end(i)+"]";return t}},{key:"currentLevel",get:function(){if(this.media){var e=this.getBufferRange(this.media.currentTime);if(e)return e.frag.level}return -1}},{key:"nextBufferRange",get:function(){return this.media?this.followingBufferRange(this.getBufferRange(this.media.currentTime)):null}},{key:"nextLevel",get:function(){var e=this.nextBufferRange;return e?e.frag.level:-1}}]),t}(d.default);r.default=y},{"../demux/demuxer":15,"../errors":19,"../event-handler":20,"../events":21,"../helper/level-helper":22,"../utils/binary-search":32,"../utils/logger":34}],7:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=e("../utils/cea-708-interpreter"),d=i(u),f=function(e){function t(e){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t);var r=function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.MEDIA_ATTACHING,s.default.MEDIA_DETACHING,s.default.FRAG_PARSING_USERDATA,s.default.MANIFEST_LOADING,s.default.FRAG_LOADED));return r.hls=e,r.config=e.config,r.config.enableCEA708Captions&&(r.cea708Interpreter=new d.default),r}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){l.default.prototype.destroy.call(this)}},{key:"onMediaAttaching",value:function(e){var t=this.media=e.media;this.cea708Interpreter.attach(t)}},{key:"onMediaDetaching",value:function(){this.cea708Interpreter.detach()}},{key:"onManifestLoading",value:function(){this.lastPts=Number.POSITIVE_INFINITY}},{key:"onFragLoaded",value:function(e){var t=e.frag.start;t<=this.lastPts&&this.cea708Interpreter.clear(),this.lastPts=t}},{key:"onFragParsingUserdata",value:function(e){for(var t=0;t<e.samples.length;t++)this.cea708Interpreter.push(e.samples[t].pts,e.samples[t].bytes)}}]),t}(l.default);r.default=f},{"../event-handler":20,"../events":21,"../utils/cea-708-interpreter":33}],8:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this._tables=[[[],[],[],[],[]],[[],[],[],[],[]]],this._precompute();var r,i,n,a,s,o=this._tables[0][4],l=this._tables[1],u=t.length,d=1;if(4!==u&&6!==u&&8!==u)throw Error("Invalid aes key size="+u);for(a=t.slice(0),s=[],this._key=[a,s],r=u;4*u+28>r;r++)n=a[r-1],(r%u==0||8===u&&r%u==4)&&(n=o[n>>>24]<<24^o[n>>16&255]<<16^o[n>>8&255]<<8^o[255&n],r%u==0&&(n=n<<8^n>>>24^d<<24,d=d<<1^283*(d>>7))),a[r]=a[r-u]^n;for(i=0;r;i++,r--)n=a[3&i?r:r-4],4>=r||4>i?s[i]=n:s[i]=l[0][o[n>>>24]]^l[1][o[n>>16&255]]^l[2][o[n>>8&255]]^l[3][o[255&n]]}return i(e,[{key:"_precompute",value:function(){var e,t,r,i,n,a,s,o,l,u=this._tables[0],d=this._tables[1],f=u[4],h=d[4],c=[],v=[];for(e=0;256>e;e++)v[(c[e]=e<<1^283*(e>>7))^e]=e;for(t=r=0;!f[t];t^=i||1,r=v[r]||1)for(s=(s=r^r<<1^r<<2^r<<3^r<<4)>>8^255&s^99,f[t]=s,h[s]=t,l=16843009*(a=c[n=c[i=c[t]]])^65537*n^257*i^16843008*t,o=257*c[s]^16843008*s,e=0;4>e;e++)u[e][t]=o=o<<24^o>>>8,d[e][s]=l=l<<24^l>>>8;for(e=0;5>e;e++)u[e]=u[e].slice(0),d[e]=d[e].slice(0)}},{key:"decrypt",value:function(e,t,r,i,n,a){var s,o,l,u,d=this._key[1],f=e^d[0],h=i^d[1],c=r^d[2],v=t^d[3],g=d.length/4-2,p=4,$=this._tables[1],y=$[0],m=$[1],E=$[2],_=$[3],b=$[4];for(u=0;g>u;u++)s=y[f>>>24]^m[h>>16&255]^E[c>>8&255]^_[255&v]^d[p],o=y[h>>>24]^m[c>>16&255]^E[v>>8&255]^_[255&f]^d[p+1],l=y[c>>>24]^m[v>>16&255]^E[f>>8&255]^_[255&h]^d[p+2],v=y[v>>>24]^m[f>>16&255]^E[h>>8&255]^_[255&c]^d[p+3],p+=4,f=s,h=o,c=l;for(u=0;4>u;u++)n[(3&-u)+a]=b[f>>>24]<<24^b[h>>16&255]<<16^b[c>>8&255]<<8^b[255&v]^d[p++],s=f,f=h,h=c,c=v,v=s}}]),e}();r.default=n},{}],9:[function(e,t,r){"use strict";var i,n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=(i=e("./aes"))&&i.__esModule?i:{default:i},s=function(){function e(t,r){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.key=t,this.iv=r}return n(e,[{key:"ntoh",value:function(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24}},{key:"doDecrypt",value:function(e,t,r){var i,n,s,o,l,u,d,f,h,c=new Int32Array(e.buffer,e.byteOffset,e.byteLength>>2),v=new a.default(Array.prototype.slice.call(t)),g=new Uint8Array(e.byteLength),p=new Int32Array(g.buffer);for(i=~~r[0],n=~~r[1],s=~~r[2],o=~~r[3],h=0;h<c.length;h+=4)l=~~this.ntoh(c[h]),u=~~this.ntoh(c[h+1]),d=~~this.ntoh(c[h+2]),f=~~this.ntoh(c[h+3]),v.decrypt(l,u,d,f,p,h),p[h]=this.ntoh(p[h]^i),p[h+1]=this.ntoh(p[h+1]^n),p[h+2]=this.ntoh(p[h+2]^s),p[h+3]=this.ntoh(p[h+3]^o),i=l,n=u,s=d,o=f;return g}},{key:"localDecrypt",value:function(e,t,r,i){var n=this.doDecrypt(e,t,r);i.set(n,e.byteOffset)}},{key:"decrypt",value:function(e){var t=new Int32Array(e),r=new Uint8Array(e.byteLength),i=0,n=this.key,a=this.iv;for(this.localDecrypt(t.subarray(i,i+32e3),n,a,r),i=32e3;i<t.length;i+=32e3)a=new Uint32Array([this.ntoh(t[i-4]),this.ntoh(t[i-3]),this.ntoh(t[i-2]),this.ntoh(t[i-1])]),this.localDecrypt(t.subarray(i,i+32e3),n,a,r);return r}}]),e}();r.default=s},{"./aes":8}],10:[function(e,t,r){"use strict";var i,n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=(i=e("./aes128-decrypter"))&&i.__esModule?i:{default:i},s=e("../errors"),o=e("../utils/logger"),l=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.hls=t;try{var r=window?window.crypto:crypto;this.subtle=r.subtle||r.webkitSubtle,this.disableWebCrypto=!this.subtle}catch(i){this.disableWebCrypto=!0}}return n(e,[{key:"destroy",value:function(){}},{key:"decrypt",value:function(e,t,r,i){this.disableWebCrypto&&this.hls.config.enableSoftwareAES?this.decryptBySoftware(e,t,r,i):this.decryptByWebCrypto(e,t,r,i)}},{key:"decryptByWebCrypto",value:function(e,t,r,i){var n=this;o.logger.log("decrypting by WebCrypto API"),this.subtle.importKey("raw",t,{name:"AES-CBC",length:128},!1,["decrypt"]).then(function(a){n.subtle.decrypt({name:"AES-CBC",iv:r.buffer},a,e).then(i).catch(function(a){n.onWebCryptoError(a,e,t,r,i)})}).catch(function(a){n.onWebCryptoError(a,e,t,r,i)})}},{key:"decryptBySoftware",value:function(e,t,r,i){o.logger.log("decrypting by JavaScript Implementation");var n=new DataView(t.buffer),s=new Uint32Array([n.getUint32(0),n.getUint32(4),n.getUint32(8),n.getUint32(12)]);n=new DataView(r.buffer);var l=new Uint32Array([n.getUint32(0),n.getUint32(4),n.getUint32(8),n.getUint32(12)]),u=new a.default(s,l);i(u.decrypt(e).buffer)}},{key:"onWebCryptoError",value:function(e,t,r,i,n){this.hls.config.enableSoftwareAES?(o.logger.log("disabling to use WebCrypto API"),this.disableWebCrypto=!0,this.decryptBySoftware(t,r,i,n)):(o.logger.error("decrypting error : "+e.message),this.hls.trigger(Event.ERROR,{type:s.ErrorTypes.MEDIA_ERROR,details:s.ErrorDetails.FRAG_DECRYPT_ERROR,fatal:!0,reason:e.message}))}}]),e}();r.default=l},{"../errors":19,"../utils/logger":34,"./aes128-decrypter":9}],11:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("./adts"),s=i(a),o=e("../utils/logger"),l=e("../demux/id3"),u=i(l),d=function(){function e(t,r){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.observer=t,this.remuxerClass=r,this.remuxer=new this.remuxerClass(t),this._aacTrack={container:"audio/adts",type:"audio",id:-1,sequenceNumber:0,samples:[],len:0}}return n(e,[{key:"push",value:function(e,t,r,i,n,a,l,d){var f,h,c,v,g,p,$,y,m,E=this._aacTrack,_=new u.default(e),b=90*_.timeStamp;for(g=_.length,y=e.length;y-1>g&&(255!==e[g]||240!=(240&e[g+1]));g++);for(E.audiosamplerate||(f=s.default.getAudioConfig(this.observer,e,g,t),E.config=f.config,E.audiosamplerate=f.samplerate,E.channelCount=f.channelCount,E.codec=f.codec,E.timescale=f.samplerate,E.duration=f.samplerate*d,o.logger.log("parsed codec:"+E.codec+",rate:"+f.samplerate+",nb channel:"+f.channelCount)),v=0,c=9216e4/E.audiosamplerate;y>g+5&&(p=1&e[g+1]?7:9,h=(3&e[g+3])<<11|e[g+4]<<3|(224&e[g+5])>>>5,(h-=p)>0&&y>=g+p+h);)for($=b+v*c,m={unit:e.subarray(g+p,g+p+h),pts:$,dts:$},E.samples.push(m),E.len+=h,g+=h+p,v++;y-1>g&&(255!==e[g]||240!=(240&e[g+1]));g++);this.remuxer.remux(this._aacTrack,{samples:[]},{samples:[{pts:b,dts:b,unit:_.payload}]},{samples:[]},i)}},{key:"destroy",value:function(){}}],[{key:"probe",value:function(e){var t,r,i=new u.default(e);if(i.hasTimeStamp){for(t=i.length,r=e.length;r-1>t;t++)if(255===e[t]&&240==(240&e[t+1]))return!0}return!1}}]),e}();r.default=d},{"../demux/id3":17,"../utils/logger":34,"./adts":12}],12:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=e("../utils/logger"),a=e("../errors"),s=function(){function e(){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,e)}return i(e,null,[{key:"getAudioConfig",value:function(e,t,r,i){var s,o,l,u,d,f=navigator.userAgent.toLowerCase(),h=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];return s=((192&t[r+2])>>>6)+1,(o=(60&t[r+2])>>>2)>h.length-1?void e.trigger(Event.ERROR,{type:a.ErrorTypes.MEDIA_ERROR,details:a.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"invalid ADTS sampling index:"+o}):(u=(1&t[r+2])<<2,u|=(192&t[r+3])>>>6,n.logger.log("manifest codec:"+i+",ADTS data:type:"+s+",sampleingIndex:"+o+"["+h[o]+"Hz],channelConfig:"+u),-1!==f.indexOf("firefox")?o>=6?(s=5,d=[,,,,],l=o-3):(s=2,d=[,,],l=o):-1!==f.indexOf("android")?(s=2,d=[,,],l=o):(s=5,d=[,,,,],i&&(-1!==i.indexOf("mp4a.40.29")||-1!==i.indexOf("mp4a.40.5"))||!i&&o>=6?l=o-3:((i&&-1!==i.indexOf("mp4a.40.2")&&o>=6&&1===u||!i&&1===u)&&(s=2,d=[,,]),l=o)),d[0]=s<<3,d[0]|=(14&o)>>1,d[1]|=(1&o)<<7,d[1]|=u<<3,5===s&&(d[1]|=(14&l)>>1,d[2]=(1&l)<<7,d[2]|=8,d[3]=0),{config:d,samplerate:h[o],channelCount:u,codec:"mp4a.40."+s})}}]),e}();r.default=s},{"../errors":19,"../utils/logger":34}],13:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../errors"),l=e("../demux/aacdemuxer"),u=i(l),d=e("../demux/tsdemuxer"),f=i(d),h=e("../remux/mp4-remuxer"),c=i(h),v=e("../remux/passthrough-remuxer"),g=i(v),p=function(){function e(t,r){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.hls=t,this.typeSupported=r}return n(e,[{key:"destroy",value:function(){var e=this.demuxer;e&&e.destroy()}},{key:"push",value:function(e,t,r,i,n,a,l,d){var h=this.demuxer;if(!h){var v=this.hls;if(f.default.probe(e))h=!0===this.typeSupported.mp2t?new f.default(v,g.default):new f.default(v,c.default);else{if(!u.default.probe(e))return void v.trigger(s.default.ERROR,{type:o.ErrorTypes.MEDIA_ERROR,details:o.ErrorDetails.FRAG_PARSING_ERROR,fatal:!0,reason:"no demux matching with content found"});h=new u.default(v,c.default)}this.demuxer=h}h.push(e,t,r,i,n,a,l,d)}}]),e}();r.default=p},{"../demux/aacdemuxer":11,"../demux/tsdemuxer":18,"../errors":19,"../events":21,"../remux/mp4-remuxer":29,"../remux/passthrough-remuxer":30}],14:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(r,"__esModule",{value:!0});var n=e("../demux/demuxer-inline"),a=i(n),s=e("../events"),o=i(s),l=e("events"),u=i(l),d=function(e){var t=new u.default;t.trigger=function(e){for(var r=arguments.length,i=Array(r>1?r-1:0),n=1;r>n;n++)i[n-1]=arguments[n];t.emit.apply(t,[e,e].concat(i))},t.off=function(e){for(var r=arguments.length,i=Array(r>1?r-1:0),n=1;r>n;n++)i[n-1]=arguments[n];t.removeListener.apply(t,[e].concat(i))},e.addEventListener("message",function(r){var i=r.data;switch(i.cmd){case"init":e.demuxer=new a.default(t,i.typeSupported);break;case"demux":e.demuxer.push(new Uint8Array(i.data),i.audioCodec,i.videoCodec,i.timeOffset,i.cc,i.level,i.sn,i.duration)}}),t.on(o.default.FRAG_PARSING_INIT_SEGMENT,function(t,r){e.postMessage({event:t,tracks:r.tracks,unique:r.unique})}),t.on(o.default.FRAG_PARSING_DATA,function(t,r){var i={event:t,type:r.type,startPTS:r.startPTS,endPTS:r.endPTS,startDTS:r.startDTS,endDTS:r.endDTS,data1:r.data1.buffer,data2:r.data2.buffer,nb:r.nb};e.postMessage(i,[i.data1,i.data2])}),t.on(o.default.FRAG_PARSED,function(t){e.postMessage({event:t})}),t.on(o.default.ERROR,function(t,r){e.postMessage({event:t,data:r})}),t.on(o.default.FRAG_PARSING_METADATA,function(t,r){var i={event:t,samples:r.samples};e.postMessage(i)}),t.on(o.default.FRAG_PARSING_USERDATA,function(t,r){var i={event:t,samples:r.samples};e.postMessage(i)})};r.default=d},{"../demux/demuxer-inline":13,"../events":21,events:1}],15:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../demux/demuxer-inline"),l=i(o),u=e("../demux/demuxer-worker"),d=i(u),f=e("../utils/logger"),h=e("../crypt/decrypter"),c=i(h),v=function(){function t(r){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,t),this.hls=r;var i={mp4:MediaSource.isTypeSupported("video/mp4"),mp2t:r.config.enableMP2TPassThrough&&MediaSource.isTypeSupported("video/mp2t")};if(r.config.enableWorker&&"undefined"!=typeof Worker){f.logger.log("demuxing in webworker");try{var n=e("webworkify");this.w=n(d.default),this.onwmsg=this.onWorkerMessage.bind(this),this.w.addEventListener("message",this.onwmsg),this.w.postMessage({cmd:"init",typeSupported:i})}catch(a){f.logger.error("error while initializing DemuxerWorker, fallback on DemuxerInline"),this.demuxer=new l.default(r,i)}}else this.demuxer=new l.default(r,i);this.demuxInitialized=!0}return n(t,[{key:"destroy",value:function(){this.w?(this.w.removeEventListener("message",this.onwmsg),this.w.terminate(),this.w=null):(this.demuxer.destroy(),this.demuxer=null),this.decrypter&&(this.decrypter.destroy(),this.decrypter=null)}},{key:"pushDecrypted",value:function(e,t,r,i,n,a,s,o){this.w?this.w.postMessage({cmd:"demux",data:e,audioCodec:t,videoCodec:r,timeOffset:i,cc:n,level:a,sn:s,duration:o},[e]):this.demuxer.push(new Uint8Array(e),t,r,i,n,a,s,o)}},{key:"push",value:function(e,t,r,i,n,a,s,o,l){if(e.byteLength>0&&null!=l&&null!=l.key&&"AES-128"===l.method){null==this.decrypter&&(this.decrypter=new c.default(this.hls));var u=this;this.decrypter.decrypt(e,l.key,l.iv,function(e){u.pushDecrypted(e,t,r,i,n,a,s,o)})}else this.pushDecrypted(e,t,r,i,n,a,s,o)}},{key:"onWorkerMessage",value:function(e){var t=e.data;switch(t.event){case s.default.FRAG_PARSING_INIT_SEGMENT:var r={};r.tracks=t.tracks,r.unique=t.unique,this.hls.trigger(s.default.FRAG_PARSING_INIT_SEGMENT,r);break;case s.default.FRAG_PARSING_DATA:this.hls.trigger(s.default.FRAG_PARSING_DATA,{data1:new Uint8Array(t.data1),data2:new Uint8Array(t.data2),startPTS:t.startPTS,endPTS:t.endPTS,startDTS:t.startDTS,endDTS:t.endDTS,type:t.type,nb:t.nb});break;case s.default.FRAG_PARSING_METADATA:this.hls.trigger(s.default.FRAG_PARSING_METADATA,{samples:t.samples});break;case s.default.FRAG_PARSING_USERDATA:this.hls.trigger(s.default.FRAG_PARSING_USERDATA,{samples:t.samples});break;default:this.hls.trigger(t.event,t.data)}}}]),t}();r.default=v},{"../crypt/decrypter":10,"../demux/demuxer-inline":13,"../demux/demuxer-worker":14,"../events":21,"../utils/logger":34,webworkify:2}],16:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=e("../utils/logger"),a=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.data=t,this.bytesAvailable=this.data.byteLength,this.word=0,this.bitsAvailable=0}return i(e,[{key:"loadWord",value:function(){var e=this.data.byteLength-this.bytesAvailable,t=new Uint8Array(4),r=Math.min(4,this.bytesAvailable);if(0===r)throw Error("no bytes available");t.set(this.data.subarray(e,e+r)),this.word=new DataView(t.buffer).getUint32(0),this.bitsAvailable=8*r,this.bytesAvailable-=r}},{key:"skipBits",value:function(e){var t;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)}},{key:"readBits",value:function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;return e>32&&n.logger.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0?this.word<<=t:this.bytesAvailable>0&&this.loadWord(),(t=e-t)>0?r<<t|this.readBits(t):r}},{key:"skipLZ",value: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()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}},{key:"skipScalingList",value:function(e){var t,r,i=8,n=8;for(t=0;e>t;t++)0!==n&&(n=(i+(r=this.readEG())+256)%256),i=0===n?i:n}},{key:"readSPS",value:function(){var e,t,r,i,n,a,s,o,l,u=0,d=0,f=0,h=0,c=1;if(this.readUByte(),e=this.readUByte(),t=this.readBits(5),this.skipBits(3),r=this.readUByte(),this.skipUEG(),100===e||110===e||122===e||244===e||44===e||83===e||86===e||118===e||128===e){var v=this.readUEG();if(3===v&&this.skipBits(1),this.skipUEG(),this.skipUEG(),this.skipBits(1),this.readBoolean())for(o=3!==v?8:12,l=0;o>l;l++)this.readBoolean()&&(6>l?this.skipScalingList(16):this.skipScalingList(64))}this.skipUEG();var g=this.readUEG();if(0===g)this.readUEG();else if(1===g)for(this.skipBits(1),this.skipEG(),this.skipEG(),i=this.readUEG(),l=0;i>l;l++)this.skipEG();if(this.skipUEG(),this.skipBits(1),n=this.readUEG(),a=this.readUEG(),0===(s=this.readBits(1))&&this.skipBits(1),this.skipBits(1),this.readBoolean()&&(u=this.readUEG(),d=this.readUEG(),f=this.readUEG(),h=this.readUEG()),this.readBoolean()&&this.readBoolean()){var p=void 0,$=this.readUByte();switch($){case 1:p=[1,1];break;case 2:p=[12,11];break;case 3:p=[10,11];break;case 4:p=[16,11];break;case 5:p=[40,33];break;case 6:p=[24,11];break;case 7:p=[20,11];break;case 8:p=[32,11];break;case 9:p=[80,33];break;case 10:p=[18,11];break;case 11:p=[15,11];break;case 12:p=[64,33];break;case 13:p=[160,99];break;case 14:p=[4,3];break;case 15:p=[3,2];break;case 16:p=[2,1];break;case 255:p=[this.readUByte()<<8|this.readUByte(),this.readUByte()<<8|this.readUByte()]}p&&(c=p[0]/p[1])}return{width:Math.ceil((16*(n+1)-2*u-2*d)*c),height:(2-s)*(a+1)*16-(s?2:4)*(f+h)}}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}}]),e}();r.default=a},{"../utils/logger":34}],17:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=e("../utils/logger"),a=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this._hasTimeStamp=!1;for(var r,i,a,s,o,l,u,d,f=0;;)if(u=this.readUTF(t,f,3),f+=3,"ID3"===u)f+=3,r=127&t[f++],i=127&t[f++],o=(r<<21)+(i<<14)+((a=127&t[f++])<<7)+(s=127&t[f++]),l=f+o,this._parseID3Frames(t,f,l),f=l;else{if("3DI"!==u)return f-=3,void((d=f)&&(this.hasTimeStamp||n.logger.warn("ID3 tag found, but no timestamp"),this._length=d,this._payload=t.subarray(0,d)));f+=7,n.logger.log("3DI footer found, end: "+f)}}return i(e,[{key:"readUTF",value:function(e,t,r){var i="",n=t,a=t+r;do i+=String.fromCharCode(e[n++]);while(a>n);return i}},{key:"_parseID3Frames",value:function(e,t,r){for(var i,a,s,o,l;r>=t+8;)if(i=this.readUTF(e,t,4),t+=4,a=e[t++]<<24+e[t++]<<16+e[t++]<<8+e[t++],o=e[t++]<<8+e[t++],s=t,"PRIV"===i&&"com.apple.streaming.transportStreamTimestamp"===this.readUTF(e,t,44)){t+=44,t+=4;var u=1&e[t++];this._hasTimeStamp=!0,l=((e[t++]<<23)+(e[t++]<<15)+(e[t++]<<7)+e[t++])/45,u&&(l+=47721858.84),l=Math.round(l),n.logger.trace("ID3 timestamp found: "+l),this._timeStamp=l}}},{key:"hasTimeStamp",get:function(){return this._hasTimeStamp}},{key:"timeStamp",get:function(){return this._timeStamp}},{key:"length",get:function(){return this._length}},{key:"payload",get:function(){return this._payload}}]),e}();r.default=a},{"../utils/logger":34}],18:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("./adts"),s=i(a),o=e("../events"),l=i(o),u=e("./exp-golomb"),d=i(u),f=e("../utils/logger"),h=e("../errors"),c=function(){function e(t,r){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.observer=t,this.remuxerClass=r,this.lastCC=0,this.remuxer=new this.remuxerClass(t)}return n(e,[{key:"switchLevel",value:function(){this.pmtParsed=!1,this._pmtId=-1,this.lastAacPTS=null,this.aacOverFlow=null,this._avcTrack={container:"video/mp2t",type:"video",id:-1,sequenceNumber:0,samples:[],len:0,nbNalu:0},this._aacTrack={container:"video/mp2t",type:"audio",id:-1,sequenceNumber:0,samples:[],len:0},this._id3Track={type:"id3",id:-1,sequenceNumber:0,samples:[],len:0},this._txtTrack={type:"text",id:-1,sequenceNumber:0,samples:[],len:0},this.remuxer.switchLevel()}},{key:"insertDiscontinuity",value:function(){this.switchLevel(),this.remuxer.insertDiscontinuity()}},{key:"push",value:function(e,t,r,i,n,a,s,o){var u,d,c,v,g,p,$,y,m=e.length,E=this.remuxer.passthrough;this.audioCodec=t,this.videoCodec=r,this.timeOffset=i,this._duration=o,this.contiguous=!1,n!==this.lastCC?(f.logger.log("discontinuity detected"),this.insertDiscontinuity(),this.lastCC=n):a!==this.lastLevel?(f.logger.log("level switch detected"),this.switchLevel(),this.lastLevel=a):s===this.lastSN+1&&(this.contiguous=!0),this.lastSN=s,this.contiguous||(this.aacOverFlow=null);var _=this.pmtParsed,b=this._avcTrack.id,R=this._aacTrack.id,L=this._id3Track.id;for(m-=m%188,v=0;m>v;v+=188)if(71===e[v]){if(g=!!(64&e[v+1]),p=((31&e[v+1])<<8)+e[v+2],($=(48&e[v+3])>>4)>1){if((y=v+5+e[v+4])===v+188)continue}else y=v+4;if(_){if(p===b){if(g){if(u&&(this._parseAVCPES(this._parsePES(u)),E&&this._avcTrack.codec&&(-1===R||this._aacTrack.codec)))return void this.remux(e);u={data:[],size:0}}u&&(u.data.push(e.subarray(y,v+188)),u.size+=v+188-y)}else if(p===R){if(g){if(d&&(this._parseAACPES(this._parsePES(d)),E&&this._aacTrack.codec&&(-1===b||this._avcTrack.codec)))return void this.remux(e);d={data:[],size:0}}d&&(d.data.push(e.subarray(y,v+188)),d.size+=v+188-y)}else p===L&&(g&&(c&&this._parseID3PES(this._parsePES(c)),c={data:[],size:0}),c&&(c.data.push(e.subarray(y,v+188)),c.size+=v+188-y))}else g&&(y+=e[y]+1),0===p?this._parsePAT(e,y):p===this._pmtId&&(this._parsePMT(e,y),_=this.pmtParsed=!0,b=this._avcTrack.id,R=this._aacTrack.id,L=this._id3Track.id)}else this.observer.trigger(l.default.ERROR,{type:h.ErrorTypes.MEDIA_ERROR,details:h.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"TS packet did not start with 0x47"});u&&this._parseAVCPES(this._parsePES(u)),d&&this._parseAACPES(this._parsePES(d)),c&&this._parseID3PES(this._parsePES(c)),this.remux(null)}},{key:"remux",value:function(e){this.remuxer.remux(this._aacTrack,this._avcTrack,this._id3Track,this._txtTrack,this.timeOffset,this.contiguous,e)}},{key:"destroy",value:function(){this.switchLevel(),this._initPTS=this._initDTS=void 0,this._duration=0}},{key:"_parsePAT",value:function(e,t){this._pmtId=(31&e[t+10])<<8|e[t+11]}},{key:"_parsePMT",value:function(e,t){var r,i,n,a;for(r=(15&e[t+1])<<8|e[t+2],i=t+3+r-4,n=(15&e[t+10])<<8|e[t+11],t+=12+n;i>t;){switch(a=(31&e[t+1])<<8|e[t+2],e[t]){case 15:this._aacTrack.id=a;break;case 21:this._id3Track.id=a;break;case 27:this._avcTrack.id=a;break;default:f.logger.log("unkown stream type:"+e[t])}t+=((15&e[t+3])<<8|e[t+4])+5}}},{key:"_parsePES",value:function(e){var t,r,i,n,a,s,o,l,u,d=0,f=e.data;if(1===(i=((t=f[0])[0]<<16)+(t[1]<<8)+t[2])){for(n=(t[4]<<8)+t[5],192&(r=t[7])&&((o=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2)>4294967295&&(o-=8589934592),64&r?(l=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2)>4294967295&&(l-=8589934592):l=o),u=(a=t[8])+9,e.size-=u,s=new Uint8Array(e.size);f.length;){var h=(t=f.shift()).byteLength;if(u){if(u>h){u-=h;continue}t=t.subarray(u),h-=u,u=0}s.set(t,d),d+=h}return{data:s,pts:o,dts:l,len:n}}return null}},{key:"_parseAVCPES",value:function(e){var t,r,i,n,a=this,s=this._avcTrack,o=s.samples,l=this._parseAVCNALu(e.data),u=[],h=!1,c=0;if(0===l.length&&o.length>0){var v=o[o.length-1],g=v.units.units[v.units.units.length-1],p=new Uint8Array(g.data.byteLength+e.data.byteLength);p.set(g.data,0),p.set(e.data,g.data.byteLength),g.data=p,v.units.length+=e.data.byteLength,s.len+=e.data.byteLength}e.data=null;var $="";l.forEach(function(r){switch(r.type){case 1:i=!0;break;case 5:i=!0,h=!0;break;case 6:if(i=!0,(t=new d.default(r.data)).readUByte(),4===t.readUByte()){var o=0;do o=t.readUByte();while(255===o);if(181===t.readUByte()&&49===t.readUShort()&&1195456820===t.readUInt()&&3===t.readUByte()){var l=t.readUByte(),f=t.readUByte(),v=31&l,g=[l,f];for(n=0;v>n;n++)g.push(t.readUByte()),g.push(t.readUByte()),g.push(t.readUByte());a._txtTrack.samples.push({type:3,pts:e.pts,bytes:g})}}break;case 7:if(i=!0,!s.sps){var p=(t=new d.default(r.data)).readSPS();s.width=p.width,s.height=p.height,s.sps=[r.data],s.timescale=a.remuxer.timescale,s.duration=a.remuxer.timescale*a._duration;var y=r.data.subarray(1,4),m="avc1.";for(n=0;3>n;n++){var E=y[n].toString(16);E.length<2&&(E="0"+E),m+=E}s.codec=m}break;case 8:i=!0,s.pps||(s.pps=[r.data]);break;case 9:i=!1;break;default:i=!1,$+="unknown NAL "+r.type+" "}i&&(u.push(r),c+=r.data.byteLength)}),$.length&&f.logger.log($),u.length&&(!0===h||s.sps)&&(r={units:{units:u,length:c},pts:e.pts,dts:e.dts,key:h},o.push(r),s.len+=c,s.nbNalu+=u.length)}},{key:"_parseAVCNALu",value:function(e){for(var t,r,i,n,a,s,o=0,l=e.byteLength,u=0,d=[];l>o;)switch(t=e[o++],u){case 0:0===t&&(u=1);break;case 1:u=0===t?2:0;break;case 2:case 3:if(0===t)u=3;else if(1===t&&l>o){if(n=31&e[o],a)i={data:e.subarray(a,o-u-1),type:s},d.push(i);else if(r=o-u-1){var f=this._avcTrack,h=f.samples;if(h.length){var c=h[h.length-1],v=c.units.units,g=v[v.length-1],p=new Uint8Array(g.data.byteLength+r);p.set(g.data,0),p.set(e.subarray(0,r),g.data.byteLength),g.data=p,c.units.length+=r,f.len+=r}}a=o,s=n,u=0}else u=0}return a&&(i={data:e.subarray(a,l),type:s},d.push(i)),d}},{key:"_parseAACPES",value:function(e){var t,r,i,n,a,o,u,d,c,v,g,p=this._aacTrack,$=e.data,y=e.pts,m=this._duration,E=this.audioCodec,_=this.aacOverFlow,b=this.lastAacPTS;if(_){var R=new Uint8Array(_.byteLength+$.byteLength);R.set(_,0),R.set($,_.byteLength),$=R}for(u=0,v=$.length;v-1>u&&(255!==$[u]||240!=(240&$[u+1]));u++);if(!u||(v-1>u?(t="AAC PES did not start with ADTS header,offset:"+u,r=!1):(t="no ADTS header found in AAC PES",r=!0),this.observer.trigger(l.default.ERROR,{type:h.ErrorTypes.MEDIA_ERROR,details:h.ErrorDetails.FRAG_PARSING_ERROR,fatal:r,reason:t}),!r)){if(p.audiosamplerate||(i=s.default.getAudioConfig(this.observer,$,u,E),p.config=i.config,p.audiosamplerate=i.samplerate,p.channelCount=i.channelCount,p.codec=i.codec,p.timescale=i.samplerate,p.duration=i.samplerate*m,f.logger.log("parsed codec:"+p.codec+",rate:"+i.samplerate+",nb channel:"+i.channelCount)),o=0,a=9216e4/p.audiosamplerate,_&&b){var L=b+a;Math.abs(L-y)>1&&(f.logger.log("AAC: align PTS for overlapping frames by "+Math.round((L-y)/90)),y=L)}for(;v>u+5&&(d=1&$[u+1]?7:9,n=(3&$[u+3])<<11|$[u+4]<<3|(224&$[u+5])>>>5,(n-=d)>0&&v>=u+d+n);)for(c=y+o*a,g={unit:$.subarray(u+d,u+d+n),pts:c,dts:c},p.samples.push(g),p.len+=n,u+=n+d,o++;v-1>u&&(255!==$[u]||240!=(240&$[u+1]));u++);_=v>u?$.subarray(u,v):null,this.aacOverFlow=_,this.lastAacPTS=c}}},{key:"_parseID3PES",value:function(e){this._id3Track.samples.push(e)}}],[{key:"probe",value:function(e){return e.length>=564&&71===e[0]&&71===e[188]&&71===e[376]}}]),e}();r.default=c},{"../errors":19,"../events":21,"../utils/logger":34,"./adts":12,"./exp-golomb":16}],19:[function(e,t,r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.ErrorTypes={NETWORK_ERROR:"networkError",MEDIA_ERROR:"mediaError",OTHER_ERROR:"otherError"},r.ErrorDetails={MANIFEST_LOAD_ERROR:"manifestLoadError",MANIFEST_LOAD_TIMEOUT:"manifestLoadTimeOut",MANIFEST_PARSING_ERROR:"manifestParsingError",MANIFEST_INCOMPATIBLE_CODECS_ERROR:"manifestIncompatibleCodecsError",LEVEL_LOAD_ERROR:"levelLoadError",LEVEL_LOAD_TIMEOUT:"levelLoadTimeOut",LEVEL_SWITCH_ERROR:"levelSwitchError",FRAG_LOAD_ERROR:"fragLoadError",FRAG_LOOP_LOADING_ERROR:"fragLoopLoadingError",FRAG_LOAD_TIMEOUT:"fragLoadTimeOut",FRAG_DECRYPT_ERROR:"fragDecryptError",FRAG_PARSING_ERROR:"fragParsingError",KEY_LOAD_ERROR:"keyLoadError",KEY_LOAD_TIMEOUT:"keyLoadTimeOut",BUFFER_APPEND_ERROR:"bufferAppendError",BUFFER_APPENDING_ERROR:"bufferAppendingError",BUFFER_STALLED_ERROR:"bufferStalledError",BUFFER_FULL_ERROR:"bufferFullError",BUFFER_SEEK_OVER_HOLE:"bufferSeekOverHole"}},{}],20:[function(e,t,r){"use strict";var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.hls=t,this.onEvent=this.onEvent.bind(this);for(var r=arguments.length,i=Array(r>1?r-1:0),n=1;r>n;n++)i[n-1]=arguments[n];this.handledEvents=i,this.useGenericHandler=!0,this.registerListeners()}return n(e,[{key:"destroy",value:function(){this.unregisterListeners()}},{key:"isEventHandler",value:function(){return"object"===i(this.handledEvents)&&this.handledEvents.length&&"function"==typeof this.onEvent}},{key:"registerListeners",value:function(){this.isEventHandler()&&this.handledEvents.forEach((function(e){if("hlsEventGeneric"===e)throw Error("Forbidden event name: "+e);this.hls.on(e,this.onEvent)}).bind(this))}},{key:"unregisterListeners",value:function(){this.isEventHandler()&&this.handledEvents.forEach((function(e){this.hls.off(e,this.onEvent)}).bind(this))}},{key:"onEvent",value:function(e,t){this.onEventGeneric(e,t)}},{key:"onEventGeneric",value:function(e,t){(function(e,t){var r="on"+e.replace("hls","");if("function"!=typeof this[r])throw Error("Event "+e+" has no generic handler in this "+this.constructor.name+" class (tried "+r+")");return this[r].bind(this,t)}).call(this,e,t).call()}}]),e}();r.default=a},{}],21:[function(e,t,r){"use strict";t.exports={MEDIA_ATTACHING:"hlsMediaAttaching",MEDIA_ATTACHED:"hlsMediaAttached",MEDIA_DETACHING:"hlsMediaDetaching",MEDIA_DETACHED:"hlsMediaDetached",BUFFER_RESET:"hlsBufferReset",BUFFER_CODECS:"hlsBufferCodecs",BUFFER_APPENDING:"hlsBufferAppending",BUFFER_APPENDED:"hlsBufferAppended",BUFFER_EOS:"hlsBufferEos",BUFFER_FLUSHING:"hlsBufferFlushing",BUFFER_FLUSHED:"hlsBufferFlushed",MANIFEST_LOADING:"hlsManifestLoading",MANIFEST_LOADED:"hlsManifestLoaded",MANIFEST_PARSED:"hlsManifestParsed",LEVEL_LOADING:"hlsLevelLoading",LEVEL_LOADED:"hlsLevelLoaded",LEVEL_UPDATED:"hlsLevelUpdated",LEVEL_PTS_UPDATED:"hlsLevelPtsUpdated",LEVEL_SWITCH:"hlsLevelSwitch",FRAG_LOADING:"hlsFragLoading",FRAG_LOAD_PROGRESS:"hlsFragLoadProgress",FRAG_LOAD_EMERGENCY_ABORTED:"hlsFragLoadEmergencyAborted",FRAG_LOADED:"hlsFragLoaded",FRAG_PARSING_INIT_SEGMENT:"hlsFragParsingInitSegment",FRAG_PARSING_USERDATA:"hlsFragParsingUserdata",FRAG_PARSING_METADATA:"hlsFragParsingMetadata",FRAG_PARSING_DATA:"hlsFragParsingData",FRAG_PARSED:"hlsFragParsed",FRAG_BUFFERED:"hlsFragBuffered",FRAG_CHANGED:"hlsFragChanged",FPS_DROP:"hlsFpsDrop",ERROR:"hlsError",DESTROYING:"hlsDestroying",KEY_LOADING:"hlsKeyLoading",KEY_LOADED:"hlsKeyLoaded"}},{}],22:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=e("../utils/logger"),a=function(){function e(){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,e)}return i(e,null,[{key:"mergeDetails",value:function(t,r){var i,a=Math.max(t.startSN,r.startSN)-r.startSN,s=Math.min(t.endSN,r.endSN)-r.startSN,o=r.startSN-t.startSN,l=t.fragments,u=r.fragments,d=0;if(a>s)return void(r.PTSKnown=!1);for(var f=a;s>=f;f++){var h=l[o+f],c=u[f];d=h.cc-c.cc,isNaN(h.startPTS)||(c.start=c.startPTS=h.startPTS,c.endPTS=h.endPTS,c.duration=h.duration,i=c)}if(d)for(n.logger.log("discontinuity sliding from playlist, take drift into account"),f=0;f<u.length;f++)u[f].cc+=d;if(i)e.updateFragPTS(r,i.sn,i.startPTS,i.endPTS);else{var v=l[o].start;for(f=0;f<u.length;f++)u[f].start+=v}r.PTSKnown=t.PTSKnown}},{key:"updateFragPTS",value:function(t,r,i,n){if(r<t.startSN||r>t.endSN)return 0;a=r-t.startSN,isNaN((o=(s=t.fragments)[a]).startPTS)||(i=Math.min(i,o.startPTS),n=Math.max(n,o.endPTS));var a,s,o,l,u=i-o.start;for(o.start=o.startPTS=i,o.endPTS=n,o.duration=n-i,l=a;l>0;l--)e.updatePTS(s,l,l-1);for(l=a;l<s.length-1;l++)e.updatePTS(s,l,l+1);return t.PTSKnown=!0,u}},{key:"updatePTS",value:function(e,t,r){var i=e[t],a=e[r],s=a.startPTS;isNaN(s)?r>t?a.start=i.start+i.duration:a.start=i.start-a.duration:r>t?(i.duration=s-i.start,i.duration<0&&n.logger.error("negative duration computed for frag "+i.sn+",level "+i.level+", there should be some duration drift between playlist and fragment!")):(a.duration=i.start-s,a.duration<0&&n.logger.error("negative duration computed for frag "+a.sn+",level "+a.level+", there should be some duration drift between playlist and fragment!"))}}]),e}();r.default=a},{"../utils/logger":34}],23:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("./events"),s=i(a),o=e("./errors"),l=e("./loader/playlist-loader"),u=i(l),d=e("./loader/fragment-loader"),f=i(d),h=e("./controller/abr-controller"),c=i(h),v=e("./controller/buffer-controller"),g=i(v),p=e("./controller/stream-controller"),$=i(p),y=e("./controller/level-controller"),m=i(y),E=e("./controller/timeline-controller"),_=i(E),b=e("./utils/logger"),R=e("./utils/xhr-loader"),L=i(R),A=e("events"),k=i(A),S=e("./loader/key-loader"),T=i(S),D=function(){function e(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,e);var r=e.DefaultConfig;if((t.liveSyncDurationCount||t.liveMaxLatencyDurationCount)&&(t.liveSyncDuration||t.liveMaxLatencyDuration))throw Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");for(var i in r)i in t||(t[i]=r[i]);if(void 0!==t.liveMaxLatencyDurationCount&&t.liveMaxLatencyDurationCount<=t.liveSyncDurationCount)throw Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be gt "liveSyncDurationCount"');if(void 0!==t.liveMaxLatencyDuration&&(t.liveMaxLatencyDuration<=t.liveSyncDuration||void 0===t.liveSyncDuration))throw Error('Illegal hls.js config: "liveMaxLatencyDuration" must be gt "liveSyncDuration"');(0,b.enableLogs)(t.debug),this.config=t;var n=this.observer=new k.default;n.trigger=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),i=1;t>i;i++)r[i-1]=arguments[i];n.emit.apply(n,[e,e].concat(r))},n.off=function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),i=1;t>i;i++)r[i-1]=arguments[i];n.removeListener.apply(n,[e].concat(r))},this.on=n.on.bind(n),this.off=n.off.bind(n),this.trigger=n.trigger.bind(n),this.playlistLoader=new u.default(this),this.fragmentLoader=new f.default(this),this.levelController=new m.default(this),this.abrController=new t.abrController(this),this.bufferController=new t.bufferController(this),this.streamController=new t.streamController(this),this.timelineController=new t.timelineController(this),this.keyLoader=new T.default(this)}return n(e,null,[{key:"isSupported",value:function(){return window.MediaSource&&window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"')}},{key:"Events",get:function(){return s.default}},{key:"ErrorTypes",get:function(){return o.ErrorTypes}},{key:"ErrorDetails",get:function(){return o.ErrorDetails}},{key:"DefaultConfig",get:function(){return e.defaultConfig||(e.defaultConfig={autoStartLoad:!0,debug:!1,maxBufferLength:30,maxBufferSize:6e7,maxBufferHole:.5,maxSeekHole:2,maxFragLookUpTolerance:.2,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxMaxBufferLength:600,enableWorker:!0,enableSoftwareAES:!0,manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingLoopThreshold:3,startFragPrefetch:!1,appendErrorMaxRetry:3,loader:L.default,fLoader:void 0,pLoader:void 0,abrController:c.default,bufferController:g.default,streamController:$.default,timelineController:_.default,enableCEA708Captions:!0,enableMP2TPassThrough:!1}),e.defaultConfig},set:function(t){e.defaultConfig=t}}]),n(e,[{key:"destroy",value:function(){b.logger.log("destroy"),this.trigger(s.default.DESTROYING),this.detachMedia(),this.playlistLoader.destroy(),this.fragmentLoader.destroy(),this.levelController.destroy(),this.bufferController.destroy(),this.streamController.destroy(),this.timelineController.destroy(),this.keyLoader.destroy(),this.url=null,this.observer.removeAllListeners()}},{key:"attachMedia",value:function(e){b.logger.log("attachMedia"),this.media=e,this.trigger(s.default.MEDIA_ATTACHING,{media:e})}},{key:"detachMedia",value:function(){b.logger.log("detachMedia"),this.trigger(s.default.MEDIA_DETACHING),this.media=null}},{key:"loadSource",value:function(e){b.logger.log("loadSource:"+e),this.url=e,this.trigger(s.default.MANIFEST_LOADING,{url:e})}},{key:"startLoad",value:function(){var e=arguments.length<=0||void 0===arguments[0]?0:arguments[0];b.logger.log("startLoad"),this.levelController.startLoad(),this.streamController.startLoad(e)}},{key:"stopLoad",value:function(){b.logger.log("stopLoad"),this.levelController.stopLoad(),this.streamController.stopLoad()}},{key:"swapAudioCodec",value:function(){b.logger.log("swapAudioCodec"),this.streamController.swapAudioCodec()}},{key:"recoverMediaError",value:function(){b.logger.log("recoverMediaError");var e=this.media;this.detachMedia(),this.attachMedia(e)}},{key:"levels",get:function(){return this.levelController.levels}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(e){b.logger.log("set currentLevel:"+e),this.loadLevel=e,this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(e){b.logger.log("set nextLevel:"+e),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(e){b.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 this.levelController.firstLevel},set:function(e){b.logger.log("set firstLevel:"+e),this.levelController.firstLevel=e}},{key:"startLevel",get:function(){return this.levelController.startLevel},set:function(e){b.logger.log("set startLevel:"+e),this.levelController.startLevel=e}},{key:"autoLevelCapping",get:function(){return this.abrController.autoLevelCapping},set:function(e){b.logger.log("set autoLevelCapping:"+e),this.abrController.autoLevelCapping=e}},{key:"autoLevelEnabled",get:function(){return -1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}}]),e}();r.default=D},{"./controller/abr-controller":3,"./controller/buffer-controller":4,"./controller/level-controller":5,"./controller/stream-controller":6,"./controller/timeline-controller":7,"./errors":19,"./events":21,"./loader/fragment-loader":25,"./loader/key-loader":26,"./loader/playlist-loader":27,"./utils/logger":34,"./utils/xhr-loader":36,events:1}],24:[function(e,t,r){"use strict";t.exports=e("./hls.js").default},{"./hls.js":23}],25:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=e("../errors"),d=function(e){function t(e){return function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t),function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.FRAG_LOADING))}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),l.default.prototype.destroy.call(this)}},{key:"onFragLoading",value:function(e){var t=e.frag;this.frag=t,this.frag.loaded=0;var r=this.hls.config;t.loader=this.loader=void 0!==r.fLoader?new r.fLoader(r):new r.loader(r),this.loader.load(t.url,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),r.fragLoadingTimeOut,1,0,this.loadprogress.bind(this),t)}},{key:"loadsuccess",value:function(e,t){var r=e.currentTarget.response;t.length=r.byteLength,this.frag.loader=void 0,this.hls.trigger(s.default.FRAG_LOADED,{payload:r,frag:this.frag,stats:t})}},{key:"loaderror",value:function(e){this.loader&&this.loader.abort(),this.hls.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:u.ErrorDetails.FRAG_LOAD_ERROR,fatal:!1,frag:this.frag,response:e})}},{key:"loadtimeout",value:function(){this.loader&&this.loader.abort(),this.hls.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:u.ErrorDetails.FRAG_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(e,t){this.frag.loaded=t.loaded,this.hls.trigger(s.default.FRAG_LOAD_PROGRESS,{frag:this.frag,stats:t})}}]),t}(l.default);r.default=d},{"../errors":19,"../event-handler":20,"../events":21}],26:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=e("../errors"),d=function(e){function t(e){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t);var r=function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.KEY_LOADING));return r.decryptkey=null,r.decrypturl=null,r}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),l.default.prototype.destroy.call(this)}},{key:"onKeyLoading",value:function(e){var t=this.frag=e.frag,r=t.decryptdata,i=r.uri;if(i!==this.decrypturl||null===this.decryptkey){var n=this.hls.config;t.loader=this.loader=new n.loader(n),this.decrypturl=i,this.decryptkey=null,t.loader.load(i,"arraybuffer",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),n.fragLoadingTimeOut,n.fragLoadingMaxRetry,n.fragLoadingRetryDelay,this.loadprogress.bind(this),t)}else this.decryptkey&&(r.key=this.decryptkey,this.hls.trigger(s.default.KEY_LOADED,{frag:t}))}},{key:"loadsuccess",value:function(e){var t=this.frag;this.decryptkey=t.decryptdata.key=new Uint8Array(e.currentTarget.response),t.loader=void 0,this.hls.trigger(s.default.KEY_LOADED,{frag:t})}},{key:"loaderror",value:function(e){this.loader&&this.loader.abort(),this.hls.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:u.ErrorDetails.KEY_LOAD_ERROR,fatal:!1,frag:this.frag,response:e})}},{key:"loadtimeout",value:function(){this.loader&&this.loader.abort(),this.hls.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:u.ErrorDetails.KEY_LOAD_TIMEOUT,fatal:!1,frag:this.frag})}},{key:"loadprogress",value:function(){}}]),t}(l.default);r.default=d},{"../errors":19,"../event-handler":20,"../events":21}],27:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../event-handler"),l=i(o),u=e("../errors"),d=e("../utils/url"),f=i(d),h=e("../utils/attr-list"),c=i(h),v=function(e){function t(e){return function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,t),function e(t,r){if(!t)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return r&&("object"==typeof r||"function"==typeof r)?r:t}(this,Object.getPrototypeOf(t).call(this,e,s.default.MANIFEST_LOADING,s.default.LEVEL_LOADING))}return function e(t,r){if("function"!=typeof r&&null!==r)throw TypeError("Super expression must either be null or a function, not "+typeof r);t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(t,r):t.__proto__=r)}(t,e),n(t,[{key:"destroy",value:function(){this.loader&&(this.loader.destroy(),this.loader=null),this.url=this.id=null,l.default.prototype.destroy.call(this)}},{key:"onManifestLoading",value:function(e){this.load(e.url,null)}},{key:"onLevelLoading",value:function(e){this.load(e.url,e.level,e.id)}},{key:"load",value:function(e,t,r){var i,n,a,s=this.hls.config;this.url=e,this.id=t,this.id2=r,null===this.id?(i=s.manifestLoadingMaxRetry,n=s.manifestLoadingTimeOut,a=s.manifestLoadingRetryDelay):(i=s.levelLoadingMaxRetry,n=s.levelLoadingTimeOut,a=s.levelLoadingRetryDelay),this.loader=void 0!==s.pLoader?new s.pLoader(s):new s.loader(s),this.loader.load(e,"",this.loadsuccess.bind(this),this.loaderror.bind(this),this.loadtimeout.bind(this),n,i,a)}},{key:"resolve",value:function(e,t){return f.default.buildAbsoluteURL(t,e)}},{key:"parseMasterPlaylist",value:function(e,t){for(var r=[],i=void 0,n=/#EXT-X-STREAM-INF:([^\n\r]*)[\r\n]+([^\r\n]+)/g;null!=(i=n.exec(e));){var a={},s=a.attrs=new c.default(i[1]);a.url=this.resolve(i[2],t);var o=s.decimalResolution("RESOLUTION");o&&(a.width=o.width,a.height=o.height),a.bitrate=s.decimalInteger("BANDWIDTH"),a.name=s.NAME;var l=s.CODECS;if(l){l=l.split(",");for(var u=0;u<l.length;u++){var d=l[u];-1!==d.indexOf("avc1")?a.videoCodec=this.avc1toavcoti(d):a.audioCodec=d}}r.push(a)}return r}},{key:"avc1toavcoti",value:function(e){var t,r=e.split(".");return r.length>2?(t=r.shift()+".",t+=parseInt(r.shift()).toString(16),t+=("000"+parseInt(r.shift()).toString(16)).substr(-4)):t=e,t}},{key:"cloneObj",value:function(e){return JSON.parse(JSON.stringify(e))}},{key:"parseLevelPlaylist",value:function(e,t,r){var i,n,a,s,o=0,l=0,u={url:t,fragments:[],live:!0,startSN:0},d={method:null,key:null,iv:null,uri:null},f=0,h=null,v=null;for(n=/(?:#EXT-X-(MEDIA-SEQUENCE):(\d+))|(?:#EXT-X-(TARGETDURATION):(\d+))|(?:#EXT-X-(KEY):(.*))|(?:#EXT(INF):([\d\.]+)[^\r\n]*([\r\n]+[^#|\r\n]+)?)|(?:#EXT-X-(BYTERANGE):([\d]+[@[\d]*)]*[\r\n]+([^#|\r\n]+)?|(?:#EXT-X-(ENDLIST))|(?:#EXT-X-(DIS)CONTINUITY))|(?:#EXT-X-(PROGRAM-DATE-TIME):(.*))/g;null!==(i=n.exec(e));)switch(i.shift(),(i=i.filter(function(e){return void 0!==e}))[0]){case"MEDIA-SEQUENCE":o=u.startSN=parseInt(i[1]);break;case"TARGETDURATION":u.targetduration=parseFloat(i[1]);break;case"ENDLIST":u.live=!1;break;case"DIS":f++;break;case"BYTERANGE":var g=i[1].split("@");s=1===g.length?a:parseInt(g[1]),a=parseInt(g[0])+s,v&&!v.url&&(v.byteRangeStartOffset=s,v.byteRangeEndOffset=a,v.url=this.resolve(i[2],t));break;case"INF":var p=parseFloat(i[1]);if(!isNaN(p)){var $,y=o++;if(d.method&&d.uri&&!d.iv){$=this.cloneObj(d);for(var m=new Uint8Array(16),E=12;16>E;E++)m[E]=y>>8*(15-E)&255;$.iv=m}else $=d;v={url:i[2]?this.resolve(i[2],t):null,duration:p,start:l,sn:y,level:r,cc:f,byteRangeStartOffset:s,byteRangeEndOffset:a,decryptdata:$,programDateTime:h},u.fragments.push(v),l+=p,s=null,h=null}break;case"KEY":var _=i[1],b=new c.default(_),R=b.enumeratedString("METHOD"),L=b.URI,A=b.hexadecimalInteger("IV");R&&(d={method:null,key:null,iv:null,uri:null},L&&"AES-128"===R&&(d.method=R,d.uri=this.resolve(L,t),d.key=null,d.iv=A));break;case"PROGRAM-DATE-TIME":h=new Date(Date.parse(i[1]))}return v&&!v.url&&(u.fragments.pop(),l-=v.duration),u.totalduration=l,u.endSN=o-1,u}},{key:"loadsuccess",value:function(e,t){var r,i=e.currentTarget,n=i.responseText,a=i.responseURL,o=this.id,l=this.id2,d=this.hls;if(void 0===a&&(a=this.url),t.tload=performance.now(),t.mtime=new Date(i.getResponseHeader("Last-Modified")),0===n.indexOf("#EXTM3U")){if(n.indexOf("#EXTINF:")>0){if(null===this.id)d.trigger(s.default.MANIFEST_LOADED,{levels:[{url:a}],url:a,stats:t});else{var f=this.parseLevelPlaylist(n,a,o);t.tparsed=performance.now(),d.trigger(s.default.LEVEL_LOADED,{details:f,level:o,id:l,stats:t})}}else(r=this.parseMasterPlaylist(n,a)).length?d.trigger(s.default.MANIFEST_LOADED,{levels:r,url:a,stats:t}):d.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:u.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:a,reason:"no level found in manifest"})}else d.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:u.ErrorDetails.MANIFEST_PARSING_ERROR,fatal:!0,url:a,reason:"no EXTM3U delimiter"})}},{key:"loaderror",value:function(e){var t,r;null===this.id?(t=u.ErrorDetails.MANIFEST_LOAD_ERROR,r=!0):(t=u.ErrorDetails.LEVEL_LOAD_ERROR,r=!1),this.loader&&this.loader.abort(),this.hls.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:t,fatal:r,url:this.url,loader:this.loader,response:e.currentTarget,level:this.id,id:this.id2})}},{key:"loadtimeout",value:function(){var e,t;null===this.id?(e=u.ErrorDetails.MANIFEST_LOAD_TIMEOUT,t=!0):(e=u.ErrorDetails.LEVEL_LOAD_TIMEOUT,t=!1),this.loader&&this.loader.abort(),this.hls.trigger(s.default.ERROR,{type:u.ErrorTypes.NETWORK_ERROR,details:e,fatal:t,url:this.url,loader:this.loader,level:this.id,id:this.id2})}}]),t}(l.default);r.default=v},{"../errors":19,"../event-handler":20,"../events":21,"../utils/attr-list":31,"../utils/url":35}],28:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,e)}return i(e,null,[{key:"init",value:function(){for(t in e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);var t,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]),i=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:i};var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),a=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=a,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 s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),l=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,l,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,n))}},{key:"box",value:function(e){for(var t,r=Array.prototype.slice.call(arguments,1),i=8,n=r.length,a=n;n--;)i+=r[n].byteLength;for((t=new Uint8Array(i))[0]=i>>24&255,t[1]=i>>16&255,t[2]=i>>8&255,t[3]=255&i,t.set(e,4),n=0,i=8;a>n;n++)t.set(r[n],i),i+=r[n].byteLength;return t}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}},{key:"mdhd",value:function(t,r){return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,r>>24,r>>16&255,r>>8&255,255&r,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value: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))}},{key:"moof",value:function(t,r,i){return e.box(e.types.moof,e.mfhd(t),e.traf(i,r))}},{key:"moov",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(i).concat(e.mvex(t)))}},{key:"mvex",value:function(t){for(var r=t.length,i=[];r--;)i[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(i))}},{key:"mvhd",value:function(t,r){var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,t>>24&255,t>>16&255,t>>8&255,255&t,r>>24&255,r>>16&255,r>>8&255,255&r,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,i)}},{key:"sdtp",value:function(t){var r,i,n=t.samples||[],a=new Uint8Array(4+n.length);for(i=0;i<n.length;i++)r=n[i].flags,a[i+4]=r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy;return e.box(e.types.sdtp,a)}},{key:"stbl",value: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))}},{key:"avc1",value:function(t){var r,i,n,a=[],s=[];for(r=0;r<t.sps.length;r++)n=(i=t.sps[r]).byteLength,a.push(n>>>8&255),a.push(255&n),a=a.concat(Array.prototype.slice.call(i));for(r=0;r<t.pps.length;r++)n=(i=t.pps[r]).byteLength,s.push(n>>>8&255),s.push(255&n),s=s.concat(Array.prototype.slice.call(i));var o=e.box(e.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|t.sps.length].concat(a).concat([t.pps.length]).concat(s))),l=t.width,u=t.height;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,l>>8&255,255&l,u>>8&255,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]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value: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]))}},{key:"mp4a",value:function(t){var r=t.audiosamplerate;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,r>>8&255,255&r,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"stsd",value:function(t){return"audio"===t.type?e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){var r=t.id,i=t.duration,n=t.width,a=t.height;return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i,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,n>>8&255,255&n,0,0,a>>8&255,255&a,0,0]))}},{key:"traf",value:function(t,r){var i=e.sdtp(t),n=t.id;return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,n>>24,n>>16&255,n>>8&255,255&n])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),e.trun(t,i.length+16+16+8+16+8+8),i)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(t,r){var i,n,a,s,o,l,u=t.samples||[],d=u.length,f=12+16*d,h=new Uint8Array(f);for(r+=8+f,h.set([0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),i=0;d>i;i++)a=(n=u[i]).duration,s=n.size,o=n.flags,l=n.cts,h.set([a>>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,l>>>24&255,l>>>16&255,l>>>8&255,255&l],12+16*i);return e.box(e.types.trun,h)}},{key:"initSegment",value:function(t){e.types||e.init();var r,i=e.moov(t);return(r=new Uint8Array(e.FTYP.byteLength+i.byteLength)).set(e.FTYP),r.set(i,e.FTYP.byteLength),r}}]),e}();r.default=n},{}],29:[function(e,t,r){"use strict";function i(e){return e&&e.__esModule?e:{default:e}}var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=e("../events"),s=i(a),o=e("../utils/logger"),l=e("../remux/mp4-generator"),u=i(l),d=e("../errors"),f=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.observer=t,this.ISGenerated=!1,this.PES2MP4SCALEFACTOR=4,this.PES_TIMESCALE=9e4,this.MP4_TIMESCALE=this.PES_TIMESCALE/this.PES2MP4SCALEFACTOR}return n(e,[{key:"destroy",value:function(){}},{key:"insertDiscontinuity",value:function(){this._initPTS=this._initDTS=this.nextAacPts=this.nextAvcDts=void 0}},{key:"switchLevel",value:function(){this.ISGenerated=!1}},{key:"remux",value:function(e,t,r,i,n,a){this.ISGenerated||this.generateIS(e,t,n),t.samples.length&&this.remuxVideo(t,n,a),e.samples.length&&this.remuxAudio(e,n,a),r.samples.length&&this.remuxID3(r,n),i.samples.length&&this.remuxText(i,n),this.observer.trigger(s.default.FRAG_PARSED)}},{key:"generateIS",value:function(e,t,r){var i,n,a=this.observer,o=e.samples,l=t.samples,f=this.PES_TIMESCALE,h={},c=void 0===this._initPTS;c&&(i=n=1/0),e.config&&o.length&&(h.audio={container:"audio/mp4",codec:e.codec,initSegment:u.default.initSegment([e]),metadata:{channelCount:e.channelCount}},c&&(i=n=o[0].pts-f*r)),t.sps&&t.pps&&l.length&&(h.video={container:"video/mp4",codec:t.codec,initSegment:u.default.initSegment([t]),metadata:{width:t.width,height:t.height}},c&&(i=Math.min(i,l[0].pts-f*r),n=Math.min(n,l[0].dts-f*r))),Object.keys(h)?(a.trigger(s.default.FRAG_PARSING_INIT_SEGMENT,{tracks:h,unique:!1}),this.ISGenerated=!0,c&&(this._initPTS=i,this._initDTS=n)):a.trigger(s.default.ERROR,{type:d.ErrorTypes.MEDIA_ERROR,details:d.ErrorDetails.FRAG_PARSING_ERROR,fatal:!1,reason:"no audio/video samples found"})}},{key:"remuxVideo",value:function(e,t,r){var i,n,a,l,d,f,h,c,v,g,p,$,y,m,E,_=8,b=this.PES_TIMESCALE,R=this.PES2MP4SCALEFACTOR,L=[];for(f=new Uint8Array(e.len+4*e.nbNalu+8),(i=new DataView(f.buffer)).setUint32(0,f.byteLength),f.set(u.default.types.mdat,4);e.samples.length;){for(n=e.samples.shift(),l=0;n.units.units.length;)d=n.units.units.shift(),i.setUint32(_,d.data.byteLength),_+=4,f.set(d.data,_),_+=d.data.byteLength,l+=4+d.data.byteLength;if($=Math.min(p=n.pts-this._initDTS,$=n.dts-this._initDTS),void 0!==g){y=this._PTSNormalize(p,g);var A=((m=this._PTSNormalize($,g))-g)/R;0>=A&&(o.logger.log("invalid sample duration at PTS/DTS: "+n.pts+"/"+n.dts+":"+A),A=1),a.duration=A}else{var k,S=this.nextAvcDts;y=this._PTSNormalize(p,S),k=Math.round(((m=this._PTSNormalize($,S))-S)/90),(r||600>Math.abs(k))&&k&&(k>1?o.logger.log("AVC:"+k+" ms hole between fragments detected,filling it"):-1>k&&o.logger.log("AVC:"+-k+" ms overlapping between fragments detected"),y=Math.max(y-k,m=S),o.logger.log("Video/PTS/DTS adjusted: "+y+"/"+m+",delta:"+k)),c=Math.max(0,y),v=Math.max(0,m)}E=(a={size:l,duration:0,cts:(y-m)/R,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0}}).flags,!0===n.key?(E.dependsOn=2,E.isNonSync=0):(E.dependsOn=1,E.isNonSync=1),L.push(a),g=m}var T=0;L.length>=2&&(T=L[L.length-2].duration,a.duration=T),this.nextAvcDts=m+T*R,e.len=0,e.nbNalu=0,L.length&&navigator.userAgent.toLowerCase().indexOf("chrome")>-1&&((E=L[0].flags).dependsOn=2,E.isNonSync=0),e.samples=L,h=u.default.moof(e.sequenceNumber++,v/R,e),e.samples=[],this.observer.trigger(s.default.FRAG_PARSING_DATA,{data1:h,data2:f,startPTS:c/b,endPTS:(y+R*T)/b,startDTS:v/b,endDTS:this.nextAvcDts/b,type:"video",nb:L.length})}},{key:"remuxAudio",value:function(e,t,r){var i,n,a,l,d,f,h,c,v,g,p,$,y,m=8,E=this.PES_TIMESCALE,_=E/e.timescale,b=[],R=[];for(e.samples.sort(function(e,t){return e.pts-t.pts}),R=e.samples;R.length;){if(l=(n=R.shift()).unit,g=n.pts-this._initDTS,p=n.dts-this._initDTS,void 0!==v)$=this._PTSNormalize(g,v),y=this._PTSNormalize(p,v),a.duration=(y-v)/_,Math.abs(a.duration-1024)>10&&o.logger.log("invalid AAC sample duration at PTS "+Math.round(g/90)+",should be 1024,found :"+Math.round(a.duration)),a.duration=1024,y=1024*_+v;else{var L,A=this.nextAacPts;if($=this._PTSNormalize(g,A),y=this._PTSNormalize(p,A),L=Math.round(1e3*($-A)/E),(r||600>Math.abs(L))&&L){if(L>0)o.logger.log(L+" ms hole between AAC samples detected,filling it");else if(-12>L){o.logger.log(-L+" ms overlapping between AAC samples detected, drop frame"),e.len-=l.byteLength;continue}$=y=A}if(h=Math.max(0,$),c=Math.max(0,y),!(e.len>0))return;d=new Uint8Array(e.len+8),(i=new DataView(d.buffer)).setUint32(0,d.byteLength),d.set(u.default.types.mdat,4)}d.set(l,m),m+=l.byteLength,a={size:l.byteLength,cts:0,duration:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},b.push(a),v=y}var k=0,S=b.length;S>=2&&(k=b[S-2].duration,a.duration=k),S&&(this.nextAacPts=$+_*k,e.len=0,e.samples=b,f=u.default.moof(e.sequenceNumber++,c/_,e),e.samples=[],this.observer.trigger(s.default.FRAG_PARSING_DATA,{data1:f,data2:d,startPTS:h/E,endPTS:this.nextAacPts/E,startDTS:c/E,endDTS:(y+_*k)/E,type:"audio",nb:S}))}},{key:"remuxID3",value:function(e,t){var r,i=e.samples.length;if(i){for(var n=0;i>n;n++)(r=e.samples[n]).pts=(r.pts-this._initPTS)/this.PES_TIMESCALE,r.dts=(r.dts-this._initDTS)/this.PES_TIMESCALE;this.observer.trigger(s.default.FRAG_PARSING_METADATA,{samples:e.samples})}e.samples=[]}},{key:"remuxText",value:function(e,t){e.samples.sort(function(e,t){return e.pts-t.pts});var r,i=e.samples.length;if(i){for(var n=0;i>n;n++)(r=e.samples[n]).pts=(r.pts-this._initPTS)/this.PES_TIMESCALE;this.observer.trigger(s.default.FRAG_PARSING_USERDATA,{samples:e.samples})}e.samples=[]}},{key:"_PTSNormalize",value:function(e,t){var r;if(void 0===t)return e;for(r=e>t?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=r;return e}},{key:"passthrough",get:function(){return!1}},{key:"timescale",get:function(){return this.MP4_TIMESCALE}}]),e}();r.default=f},{"../errors":19,"../events":21,"../remux/mp4-generator":28,"../utils/logger":34}],30:[function(e,t,r){"use strict";var i,n=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var a=(i=e("../events"))&&i.__esModule?i:{default:i},s=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),this.observer=t,this.ISGenerated=!1}return n(e,[{key:"destroy",value:function(){}},{key:"insertDiscontinuity",value:function(){}},{key:"switchLevel",value:function(){this.ISGenerated=!1}},{key:"remux",value:function(e,t,r,i,n,s){var o=this.observer;if(!this.ISGenerated){var l={tracks:{},unique:!0},u=t,d=u.codec;d&&(l.tracks.video={container:u.container,codec:d,metadata:{width:u.width,height:u.height}}),(d=(u=e).codec)&&(l.tracks.audio={container:u.container,codec:d,metadata:{channelCount:u.channelCount}}),this.ISGenerated=!0,o.trigger(a.default.FRAG_PARSING_INIT_SEGMENT,l)}o.trigger(a.default.FRAG_PARSING_DATA,{data1:s,startPTS:n,startDTS:n,type:"audiovideo",nb:1})}},{key:"passthrough",get:function(){return!0}},{key:"timescale",get:function(){return 0}}]),e}();r.default=s},{"../events":21}],31:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(t){for(var r in function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,e),"string"==typeof t&&(t=e.parseAttrList(t)),t)t.hasOwnProperty(r)&&(this[r]=t[r])}return i(e,[{key:"decimalInteger",value:function(e){var t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t}},{key:"hexadecimalInteger",value: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),i=0;i<t.length/2;i++)r[i]=parseInt(t.slice(2*i,2*i+2),16);return r}return null}},{key:"hexadecimalIntegerAsNumber",value:function(e){var t=parseInt(this[e],16);return t>Number.MAX_SAFE_INTEGER?1/0:t}},{key:"decimalFloatingPoint",value:function(e){return parseFloat(this[e])}},{key:"enumeratedString",value:function(e){return this[e]}},{key:"decimalResolution",value:function(e){var t=/^(\d+)x(\d+)$/.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}}}],[{key:"parseAttrList",value:function(e){for(var t,r=/\s*(.+?)\s*=((?:\".*?\")|.*?)(?:,|$)/g,i={};null!==(t=r.exec(e));){var n=t[2];0===n.indexOf('"')&&n.lastIndexOf('"')===n.length-1&&(n=n.slice(1,-1)),i[t[1]]=n}return i}}]),e}();r.default=n},{}],32:[function(e,t,r){"use strict";t.exports={search:function(e,t){for(var r=0,i=e.length-1,n=null,a=null;i>=r;){var s=t(a=e[n=(r+i)/2|0]);if(s>0)r=n+1;else{if(!(0>s))return a;i=n-1}}return null}}},{}],33:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=function(){function e(){!function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")}(this,e)}return i(e,[{key:"attach",value:function(e){this.media=e,this.display=[],this.memory=[]}},{key:"detach",value:function(){this.clear()}},{key:"destroy",value:function(){}},{key:"_createCue",value:function(){var e=window.VTTCue||window.TextTrackCue,t=this.cue=new e(-1,-1,"");t.text="",t.pauseOnExit=!1,t.startTime=Number.MAX_VALUE,t.endTime=Number.MAX_VALUE,this.memory.push(t)}},{key:"clear",value:function(){var e=this._textTrack;if(e&&e.cues)for(;e.cues.length>0;)e.removeCue(e.cues[0])}},{key:"push",value:function(e,t){this.cue||this._createCue();for(var r,i,n,a,s,o=31&t[0],l=2,u=0;o>u;u++)if(r=t[l++],i=127&t[l++],n=127&t[l++],a=0!=(4&r),s=3&r,(0!==i||0!==n)&&a&&0===s){if(32&i||64&i)this.cue.text+=this._fromCharCode(i)+this._fromCharCode(n);else if((17===i||25===i)&&n>=48&&63>=n)switch(n){case 48:this.cue.text+="\xae";break;case 49:this.cue.text+="\xb0";break;case 50:this.cue.text+="\xbd";break;case 51:this.cue.text+="\xbf";break;case 52:this.cue.text+="™";break;case 53:this.cue.text+="\xa2";break;case 54:this.cue.text+="";break;case 55:this.cue.text+="\xa3";break;case 56:this.cue.text+="♪";break;case 57:this.cue.text+=" ";break;case 58:this.cue.text+="\xe8";break;case 59:this.cue.text+="\xe2";break;case 60:this.cue.text+="\xea";break;case 61:this.cue.text+="\xee";break;case 62:this.cue.text+="\xf4";break;case 63:this.cue.text+="\xfb"}if(1,(20===i||28===i)&&n>=32&&47>=n)switch(n){case 32:case 41:case 44:this._clearActiveCues(e);break;case 33:this.cue.text=this.cue.text.substr(0,this.cue.text.length-1);break;case 34:case 35:case 36:case 37:case 38:case 39:case 40:case 42:case 43:case 45:break;case 46:this._text="";break;case 47:this._flipMemory(e)}1}}},{key:"_fromCharCode",value:function(e){switch(e){case 42:case 2:return"\xe1";case 2:return"\xe9";case 4:return"\xed";case 5:return"\xf3";case 6:return"\xfa";case 3:return"\xe7";case 4:return"\xf7";case 5:return"\xd1";case 6:return"\xf1";case 7:return"█";default:return String.fromCharCode(e)}}},{key:"_flipMemory",value:function(e){this._clearActiveCues(e),this._flushCaptions(e)}},{key:"_flushCaptions",value:function(e){this._has708||(this._textTrack=this.media.addTextTrack("captions","English","en"),this._has708=!0);var t=!0,r=!1,i=void 0;try{for(var n,a=this.memory[Symbol.iterator]();!(t=(n=a.next()).done);t=!0){var s=n.value;s.startTime=e,this._textTrack.addCue(s),this.display.push(s)}}catch(o){r=!0,i=o}finally{try{!t&&a.return&&a.return()}finally{if(r)throw i}}this.memory=[],this.cue=null}},{key:"_clearActiveCues",value:function(e){var t=!0,r=!1,i=void 0;try{for(var n,a=this.display[Symbol.iterator]();!(t=(n=a.next()).done);t=!0)n.value.endTime=e}catch(s){r=!0,i=s}finally{try{!t&&a.return&&a.return()}finally{if(r)throw i}}this.display=[]}},{key:"_clearBufferedCues",value:function(){}}]),e}();r.default=n},{}],34:[function(e,t,r){"use strict";function i(){}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};Object.defineProperty(r,"__esModule",{value:!0});var a={trace:i,debug:i,log:i,warn:i,info:i,error:i},s=a;r.enableLogs=function(e){if(!0===e||"object"===(void 0===e?"undefined":n(e))){(function e(t){for(var r=arguments.length,n=Array(r>1?r-1:0),a=1;r>a;a++)n[a-1]=arguments[a];n.forEach(function(e){var r,n;s[e]=t[e]?t[e].bind(t):(r=e,(n=window.console[r])?function(){for(var e,t,i=arguments.length,a=Array(i),s=0;i>s;s++)a[s]=arguments[s];a[0]&&(a[0]=(e=r,t="["+e+"] > "+(t=a[0]))),n.apply(window.console,a)}:i)})})(e,"debug","log","info","warn","error");try{s.log()}catch(t){s=a}}else s=a},r.logger=s},{}],35:[function(e,t,r){"use strict";var i={buildAbsoluteURL:function(e,t){if(t=t.trim(),/^[a-z]+:/i.test(t))return t;var r=null,n=null,a=/^([^#]*)(.*)$/.exec(t);a&&(n=a[2],t=a[1]);var s=/^([^\?]*)(.*)$/.exec(t);s&&(r=s[2],t=s[1]);var o=/^([^#]*)(.*)$/.exec(e);o&&(e=o[1]);var l=/^([^\?]*)(.*)$/.exec(e);l&&(e=l[1]);var u=/^((([a-z]+):)?\/\/[a-z0-9\.\-_~]+(:[0-9]+)?\/)(.*)$/i.exec(e),d=u[3],f=u[1],h=u[5],c=null;return c=/^\/\//.test(t)?d+"://"+i.buildAbsolutePath("",t.substring(2)):/^\//.test(t)?f+i.buildAbsolutePath("",t.substring(1)):i.buildAbsolutePath(f+h,t),r&&(c+=r),n&&(c+=n),c},buildAbsolutePath:function(e,t){for(var r,i,n="",a=e.replace(/[^\/]*$/,t.replace(/(\/|^)(?:\.?\/+)+/g,"$1")),s=0;(i=a.indexOf("/../",s))>-1;s=i+r)r=/^\/(?:\.\.\/)*/.exec(a.slice(i))[0].length,n=(n+a.substring(s,i)).replace(RegExp("(?:\\/+[^\\/]*){0,"+(r-1)/3+"}$"),"/");return n+a.substr(s)}};t.exports=i},{}],36:[function(e,t,r){"use strict";var i=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}();Object.defineProperty(r,"__esModule",{value:!0});var n=e("../utils/logger"),a=function(){function e(t){(function e(t,r){if(!(t instanceof r))throw TypeError("Cannot call a class as a function")})(this,e),t&&t.xhrSetup&&(this.xhrSetup=t.xhrSetup)}return i(e,[{key:"destroy",value:function(){this.abort(),this.loader=null}},{key:"abort",value:function(){var e=this.loader,t=this.timeoutHandle;e&&4!==e.readyState&&(this.stats.aborted=!0,e.abort()),t&&window.clearTimeout(t)}},{key:"load",value:function(e,t,r,i,n,a,s,o){var l=arguments.length<=8||void 0===arguments[8]?null:arguments[8],u=arguments.length<=9||void 0===arguments[9]?null:arguments[9];this.url=e,!u||isNaN(u.byteRangeStartOffset)||isNaN(u.byteRangeEndOffset)||(this.byteRange=u.byteRangeStartOffset+"-"+(u.byteRangeEndOffset-1)),this.responseType=t,this.onSuccess=r,this.onProgress=l,this.onTimeout=n,this.onError=i,this.stats={trequest:performance.now(),retry:0},this.timeout=a,this.maxRetry=s,this.retryDelay=o,this.loadInternal()}},{key:"loadInternal",value:function(){var e;(e="undefined"!=typeof XDomainRequest?this.loader=new XDomainRequest:this.loader=new XMLHttpRequest).onloadend=this.loadend.bind(this),e.onprogress=this.loadprogress.bind(this),e.open("GET",this.url,!0),this.byteRange&&e.setRequestHeader("Range","bytes="+this.byteRange),e.responseType=this.responseType,this.stats.tfirst=null,this.stats.loaded=0,this.xhrSetup&&this.xhrSetup(e,this.url),this.timeoutHandle=window.setTimeout(this.loadtimeout.bind(this),this.timeout),e.send()}},{key:"loadend",value:function(e){var t=e.currentTarget.status,r=this.stats;r.aborted||(t>=200&&300>t?(window.clearTimeout(this.timeoutHandle),r.tload=performance.now(),this.onSuccess(e,r)):r.retry<this.maxRetry?(n.logger.warn(t+" while loading "+this.url+", retrying in "+this.retryDelay+"..."),this.destroy(),window.setTimeout(this.loadInternal.bind(this),this.retryDelay),this.retryDelay=Math.min(2*this.retryDelay,64e3),r.retry++):(window.clearTimeout(this.timeoutHandle),n.logger.error(t+" while loading "+this.url),this.onError(e)))}},{key:"loadtimeout",value:function(e){n.logger.warn("timeout while loading "+this.url),this.onTimeout(e,this.stats)}},{key:"loadprogress",value:function(e){var t=this.stats;null===t.tfirst&&(t.tfirst=performance.now()),t.loaded=e.loaded,this.onProgress&&this.onProgress(e,t)}}]),e}();r.default=a},{"../utils/logger":34}]},{},[24])(24)});var url="https://d12dpwmt43e4qp.cloudfront.net/stream/hls/stream.m3u8";document.loadVideo=e=>{var t=document.getElementById(e);if(Hls.isSupported()){var r=new Hls({debug:!0});r.loadSource(url),r.attachMedia(t),r.on(Hls.Events.MEDIA_ATTACHED,function(){t.muted=!0,t.play()})}else t.canPlayType("application/vnd.apple.mpegurl")&&(t.src=url,t.addEventListener("canplay",function(){t.play()}))};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment