UNPKG

cdnbye

Version:

Let your viewers become your unlimitedly scalable CDN.

1 lines 486 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Hls=t():e.Hls=t()}(this,(()=>(()=>{"use strict";var e={648:e=>{var t,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n="object"===("undefined"==typeof Reflect?"undefined":r(Reflect))?Reflect:null,i=n&&"function"==typeof n.apply?n.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var a=Number.isNaN||function(e){return e!=e};function s(){s.init.call(this)}e.exports=s,e.exports.once=function(e,t){return new Promise((function(r,n){function i(r){e.removeListener(t,a),n(r)}function a(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}p(e,t,a,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&p(e,"error",t,r)}(e,i,{once:!0})}))},s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var o=10;function l(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+(void 0===e?"undefined":r(e)))}function u(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function d(e,t,r,n){var i,a,s,o;if(l(r),void 0===(a=e._events)?(a=e._events=Object.create(null),e._eventsCount=0):(void 0!==a.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),a=e._events),s=a[t]),void 0===s)s=a[t]=r,++e._eventsCount;else if("function"==typeof s?s=a[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),(i=u(e))>0&&s.length>i&&!s.warned){s.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=s.length,o=d,console&&console.warn&&console.warn(o)}return e}function c(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function f(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=c.bind(n);return i.listener=r,n.wrapFn=i,i}function h(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):v(i,i.length)}function g(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function v(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function p(e,t,n,i){if("function"==typeof e.on)i.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+(void 0===e?"undefined":r(e)));e.addEventListener(t,(function r(a){i.once&&e.removeEventListener(t,r),n(a)}))}}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||a(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),s.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||a(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,a=this._events;if(void 0!==a)n=n&&void 0===a.error;else if(!n)return!1;if(n){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var l=a[e];if(void 0===l)return!1;if("function"==typeof l)i(l,this,t);else{var u=l.length,d=v(l,u);for(r=0;r<u;++r)i(d[r],this,t)}return!0},s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)},s.prototype.once=function(e,t){return l(t),this.on(e,f(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,f(this,e,t)),this},s.prototype.removeListener=function(e,t){var r,n,i,a,s;if(l(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,a=r.length-1;a>=0;a--)if(r[a]===t||r[a].listener===t){s=r[a].listener,i=a;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,s||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,a=Object.keys(r);for(n=0;n<a.length;++n)"removeListener"!==(i=a[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},s.prototype.listeners=function(e){return h(this,e,!0)},s.prototype.rawListeners=function(e){return h(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):g.call(e,t)},s.prototype.listenerCount=g,s.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},696:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},r(e,t)};function n(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function i(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,a=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return s}var a=function(e,t){this.target=t,this.type=e},s=function(e){function t(t,r){var n=e.call(this,"error",r)||this;return n.message=t.message,n.error=t,n}return n(t,e),t}(a),o=function(e){function t(t,r,n){void 0===t&&(t=1e3),void 0===r&&(r="");var i=e.call(this,"close",n)||this;return i.wasClean=!0,i.code=t,i.reason=r,i}return n(t,e),t}(a),l=function(){if("undefined"!=typeof WebSocket)return WebSocket},u={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+4e3*Math.random(),minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0,startClosed:!1,debug:!1},d=function(){function e(e,t,r){var n=this;void 0===r&&(r={}),this._listeners={error:[],message:[],open:[],close:[]},this._retryCount=-1,this._shouldReconnect=!0,this._connectLock=!1,this._binaryType="blob",this._closeCalled=!1,this._messageQueue=[],this.onclose=null,this.onerror=null,this.onmessage=null,this.onopen=null,this._handleOpen=function(e){n._debug("open event");var t=n._options.minUptime,r=void 0===t?u.minUptime:t;clearTimeout(n._connectTimeout),n._uptimeTimeout=setTimeout((function(){return n._acceptOpen()}),r),n._ws.binaryType=n._binaryType,n._messageQueue.forEach((function(e){return n._ws.send(e)})),n._messageQueue=[],n.onopen&&n.onopen(e),n._listeners.open.forEach((function(t){return n._callEventListener(e,t)}))},this._handleMessage=function(e){n._debug("message event"),n.onmessage&&n.onmessage(e),n._listeners.message.forEach((function(t){return n._callEventListener(e,t)}))},this._handleError=function(e){n._debug("error event",e.message),n._disconnect(void 0,"TIMEOUT"===e.message?"timeout":void 0),n.onerror&&n.onerror(e),n._debug("exec error listeners"),n._listeners.error.forEach((function(t){return n._callEventListener(e,t)})),n._connect()},this._handleClose=function(e){n._debug("close event"),n._clearTimeouts(),n._shouldReconnect&&n._connect(),n.onclose&&n.onclose(e),n._listeners.close.forEach((function(t){return n._callEventListener(e,t)}))},this._url=e,this._protocols=t,this._options=r,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}return Object.defineProperty(e,"CONNECTING",{get:function(){return 0},enumerable:!0,configurable:!0}),Object.defineProperty(e,"OPEN",{get:function(){return 1},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSING",{get:function(){return 2},enumerable:!0,configurable:!0}),Object.defineProperty(e,"CLOSED",{get:function(){return 3},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CONNECTING",{get:function(){return e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"OPEN",{get:function(){return e.OPEN},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSING",{get:function(){return e.CLOSING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CLOSED",{get:function(){return e.CLOSED},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"binaryType",{get:function(){return this._ws?this._ws.binaryType:this._binaryType},set:function(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"retryCount",{get:function(){return Math.max(this._retryCount,0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"bufferedAmount",{get:function(){return this._messageQueue.reduce((function(e,t){return"string"==typeof t?e+=t.length:t instanceof Blob?e+=t.size:e+=t.byteLength,e}),0)+(this._ws?this._ws.bufferedAmount:0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"extensions",{get:function(){return this._ws?this._ws.extensions:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"protocol",{get:function(){return this._ws?this._ws.protocol:""},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"readyState",{get:function(){return this._ws?this._ws.readyState:this._options.startClosed?e.CLOSED:e.CONNECTING},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"url",{get:function(){return this._ws?this._ws.url:""},enumerable:!0,configurable:!0}),e.prototype.close=function(e,t){void 0===e&&(e=1e3),this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),this._ws?this._ws.readyState!==this.CLOSED?this._ws.close(e,t):this._debug("close: already closed"):this._debug("close enqueued: no ws instance")},e.prototype.reconnect=function(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,this._ws&&this._ws.readyState!==this.CLOSED?(this._disconnect(e,t),this._connect()):this._connect()},e.prototype.send=function(e){if(this._ws&&this._ws.readyState===this.OPEN)this._debug("send",e),this._ws.send(e);else{var t=this._options.maxEnqueuedMessages,r=void 0===t?u.maxEnqueuedMessages:t;this._messageQueue.length<r&&(this._debug("enqueue",e),this._messageQueue.push(e))}},e.prototype.addEventListener=function(e,t){this._listeners[e]&&this._listeners[e].push(t)},e.prototype.dispatchEvent=function(e){var t,r,n=this._listeners[e.type];if(n)try{for(var i=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(n),a=i.next();!a.done;a=i.next()){var s=a.value;this._callEventListener(e,s)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}return!0},e.prototype.removeEventListener=function(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter((function(e){return e!==t})))},e.prototype._debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._options.debug&&console.log.apply(console,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(i(arguments[t]));return e}(["RWS>"],e))},e.prototype._getNextDelay=function(){var e=this._options,t=e.reconnectionDelayGrowFactor,r=void 0===t?u.reconnectionDelayGrowFactor:t,n=e.minReconnectionDelay,i=void 0===n?u.minReconnectionDelay:n,a=e.maxReconnectionDelay,s=void 0===a?u.maxReconnectionDelay:a,o=0;return this._retryCount>0&&(o=i*Math.pow(r,this._retryCount-1))>s&&(o=s),this._debug("next delay",o),o},e.prototype._wait=function(){var e=this;return new Promise((function(t){setTimeout(t,e._getNextDelay())}))},e.prototype._getNextUrl=function(e){if("string"==typeof e)return Promise.resolve(e);if("function"==typeof e){var t=e();if("string"==typeof t)return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")},e.prototype._connect=function(){var e=this;if(!this._connectLock&&this._shouldReconnect){this._connectLock=!0;var t=this._options,r=t.maxRetries,n=void 0===r?u.maxRetries:r,i=t.connectionTimeout,a=void 0===i?u.connectionTimeout:i,s=t.WebSocket,o=void 0===s?l():s;if(this._retryCount>=n)this._debug("max retries reached",this._retryCount,">=",n);else{if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),void 0===(d=o)||!d||2!==d.CLOSING)throw Error("No valid WebSocket class provided");var d;this._wait().then((function(){return e._getNextUrl(e._url)})).then((function(t){e._closeCalled||(e._debug("connect",{url:t,protocols:e._protocols}),e._ws=e._protocols?new o(t,e._protocols):new o(t),e._ws.binaryType=e._binaryType,e._connectLock=!1,e._addListeners(),e._connectTimeout=setTimeout((function(){return e._handleTimeout()}),a))}))}}},e.prototype._handleTimeout=function(){this._debug("timeout event"),this._handleError(new s(Error("TIMEOUT"),this))},e.prototype._disconnect=function(e,t){if(void 0===e&&(e=1e3),this._clearTimeouts(),this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new o(e,t,this))}catch(e){}}},e.prototype._acceptOpen=function(){this._debug("accept open"),this._retryCount=0},e.prototype._callEventListener=function(e,t){"handleEvent"in t?t.handleEvent(e):t(e)},e.prototype._removeListeners=function(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))},e.prototype._addListeners=function(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))},e.prototype._clearTimeouts=function(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)},e}();t.default=d,e.exports=t.default},299:(e,t,r)=>{var n;e=r.nmd(e);var i,a,s,o,l,u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};i=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,a=/^(?=([^\/?#]*))\1([^]*)$/,s=/(?:\/|^)\.(?=\/)/g,o=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,l={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var n=l.parseURL(e);if(!n)throw new Error("Error trying to parse base URL.");return n.path=l.normalizePath(n.path),l.buildURLFromParts(n)}var i=l.parseURL(t);if(!i)throw new Error("Error trying to parse relative URL.");if(i.scheme)return r.alwaysNormalize?(i.path=l.normalizePath(i.path),l.buildURLFromParts(i)):t;var s=l.parseURL(e);if(!s)throw new Error("Error trying to parse base URL.");if(!s.netLoc&&s.path&&"/"!==s.path[0]){var o=a.exec(s.path);s.netLoc=o[1],s.path=o[2]}s.netLoc&&!s.path&&(s.path="/");var u={scheme:s.scheme,netLoc:i.netLoc,path:null,params:i.params,query:i.query,fragment:i.fragment};if(!i.netLoc&&(u.netLoc=s.netLoc,"/"!==i.path[0]))if(i.path){var d=s.path,c=d.substring(0,d.lastIndexOf("/")+1)+i.path;u.path=l.normalizePath(c)}else u.path=s.path,i.params||(u.params=s.params,i.query||(u.query=s.query));return null===u.path&&(u.path=r.alwaysNormalize?l.normalizePath(i.path):i.path),l.buildURLFromParts(u)},parseURL:function(e){var t=i.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(s,"");e.length!==(e=e.replace(o,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},"object"===u(t)&&"object"===u(e)?e.exports=l:void 0===(n=function(){return l}.apply(t,[]))||(e.exports=n)},322:(e,t,r)=>{var n,i,a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};!function s(o){var l;l=function(){function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{};n%2?e(Object(i),!0).forEach((function(e){var n,a,s;n=t,a=e,s=i[e],(a=r(a))in n?Object.defineProperty(n,a,{value:s,enumerable:!0,configurable:!0,writable:!0}):n[a]=s})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):e(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function r(e){var t=function(e,t){if("object"!=(void 0===e?"undefined":a(e))||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=(void 0===n?"undefined":a(n)))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==(void 0===t?"undefined":a(t))?t:String(t)}function n(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,r(i.key),i)}}function i(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(){return l=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},l.apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,c(e,t)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}function c(e,t){return c=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},c(e,t)}function f(e,t,r){return f=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&c(i,r.prototype),i},f.apply(null,arguments)}function h(e){var t="function"==typeof Map?new Map:void 0;return h=function(e){if(null===e||!function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return f(e,arguments,d(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),c(r,e)},h(e)}function g(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var v={exports:{}};!function(e,t){var r,n,i,a,s;r=/^(?=((?:[a-zA-Z0-9+\-.]+:)?))\1(?=((?:\/\/[^\/?#]*)?))\2(?=((?:(?:[^?#\/]*\/)*[^;?#\/]*)?))\3((?:;[^?#]*)?)(\?[^#]*)?(#[^]*)?$/,n=/^(?=([^\/?#]*))\1([^]*)$/,i=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,s={buildAbsoluteURL:function(e,t,r){if(r=r||{},e=e.trim(),!(t=t.trim())){if(!r.alwaysNormalize)return e;var i=s.parseURL(e);if(!i)throw new Error("Error trying to parse base URL.");return i.path=s.normalizePath(i.path),s.buildURLFromParts(i)}var a=s.parseURL(t);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=s.normalizePath(a.path),s.buildURLFromParts(a)):t;var o=s.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");if(!o.netLoc&&o.path&&"/"!==o.path[0]){var l=n.exec(o.path);o.netLoc=l[1],o.path=l[2]}o.netLoc&&!o.path&&(o.path="/");var u={scheme:o.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(u.netLoc=o.netLoc,"/"!==a.path[0]))if(a.path){var d=o.path,c=d.substring(0,d.lastIndexOf("/")+1)+a.path;u.path=s.normalizePath(c)}else u.path=o.path,a.params||(u.params=o.params,a.query||(u.query=o.query));return null===u.path&&(u.path=r.alwaysNormalize?s.normalizePath(a.path):a.path),s.buildURLFromParts(u)},parseURL:function(e){var t=r.exec(e);return t?{scheme:t[1]||"",netLoc:t[2]||"",path:t[3]||"",params:t[4]||"",query:t[5]||"",fragment:t[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(i,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=s}(v);var p=v.exports,m=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},y=Number.isSafeInteger||function(e){return"number"==typeof e&&Math.abs(e)<=b},b=Number.MAX_SAFE_INTEGER||9007199254740991,E=function(e){return e.MEDIA_ATTACHING="hlsMediaAttaching",e.MEDIA_ATTACHED="hlsMediaAttached",e.MEDIA_DETACHING="hlsMediaDetaching",e.MEDIA_DETACHED="hlsMediaDetached",e.BUFFER_RESET="hlsBufferReset",e.BUFFER_CODECS="hlsBufferCodecs",e.BUFFER_CREATED="hlsBufferCreated",e.BUFFER_APPENDING="hlsBufferAppending",e.BUFFER_APPENDED="hlsBufferAppended",e.BUFFER_EOS="hlsBufferEos",e.BUFFER_FLUSHING="hlsBufferFlushing",e.BUFFER_FLUSHED="hlsBufferFlushed",e.MANIFEST_LOADING="hlsManifestLoading",e.MANIFEST_LOADED="hlsManifestLoaded",e.MANIFEST_PARSED="hlsManifestParsed",e.LEVEL_SWITCHING="hlsLevelSwitching",e.LEVEL_SWITCHED="hlsLevelSwitched",e.LEVEL_LOADING="hlsLevelLoading",e.LEVEL_LOADED="hlsLevelLoaded",e.LEVEL_UPDATED="hlsLevelUpdated",e.LEVEL_PTS_UPDATED="hlsLevelPtsUpdated",e.LEVELS_UPDATED="hlsLevelsUpdated",e.AUDIO_TRACKS_UPDATED="hlsAudioTracksUpdated",e.AUDIO_TRACK_SWITCHING="hlsAudioTrackSwitching",e.AUDIO_TRACK_SWITCHED="hlsAudioTrackSwitched",e.AUDIO_TRACK_LOADING="hlsAudioTrackLoading",e.AUDIO_TRACK_LOADED="hlsAudioTrackLoaded",e.SUBTITLE_TRACKS_UPDATED="hlsSubtitleTracksUpdated",e.SUBTITLE_TRACKS_CLEARED="hlsSubtitleTracksCleared",e.SUBTITLE_TRACK_SWITCH="hlsSubtitleTrackSwitch",e.SUBTITLE_TRACK_LOADING="hlsSubtitleTrackLoading",e.SUBTITLE_TRACK_LOADED="hlsSubtitleTrackLoaded",e.SUBTITLE_FRAG_PROCESSED="hlsSubtitleFragProcessed",e.CUES_PARSED="hlsCuesParsed",e.NON_NATIVE_TEXT_TRACKS_FOUND="hlsNonNativeTextTracksFound",e.INIT_PTS_FOUND="hlsInitPtsFound",e.FRAG_LOADING="hlsFragLoading",e.FRAG_LOAD_EMERGENCY_ABORTED="hlsFragLoadEmergencyAborted",e.FRAG_LOADED="hlsFragLoaded",e.FRAG_DECRYPTED="hlsFragDecrypted",e.FRAG_PARSING_INIT_SEGMENT="hlsFragParsingInitSegment",e.FRAG_PARSING_USERDATA="hlsFragParsingUserdata",e.FRAG_PARSING_METADATA="hlsFragParsingMetadata",e.FRAG_PARSED="hlsFragParsed",e.FRAG_BUFFERED="hlsFragBuffered",e.FRAG_CHANGED="hlsFragChanged",e.FPS_DROP="hlsFpsDrop",e.FPS_DROP_LEVEL_CAPPING="hlsFpsDropLevelCapping",e.MAX_AUTO_LEVEL_UPDATED="hlsMaxAutoLevelUpdated",e.ERROR="hlsError",e.DESTROYING="hlsDestroying",e.KEY_LOADING="hlsKeyLoading",e.KEY_LOADED="hlsKeyLoaded",e.LIVE_BACK_BUFFER_REACHED="hlsLiveBackBufferReached",e.BACK_BUFFER_REACHED="hlsBackBufferReached",e.STEERING_MANIFEST_LOADED="hlsSteeringManifestLoaded",e}({}),S=function(e){return e.NETWORK_ERROR="networkError",e.MEDIA_ERROR="mediaError",e.KEY_SYSTEM_ERROR="keySystemError",e.MUX_ERROR="muxError",e.OTHER_ERROR="otherError",e}({}),_=function(e){return e.KEY_SYSTEM_NO_KEYS="keySystemNoKeys",e.KEY_SYSTEM_NO_ACCESS="keySystemNoAccess",e.KEY_SYSTEM_NO_SESSION="keySystemNoSession",e.KEY_SYSTEM_NO_CONFIGURED_LICENSE="keySystemNoConfiguredLicense",e.KEY_SYSTEM_LICENSE_REQUEST_FAILED="keySystemLicenseRequestFailed",e.KEY_SYSTEM_SERVER_CERTIFICATE_REQUEST_FAILED="keySystemServerCertificateRequestFailed",e.KEY_SYSTEM_SERVER_CERTIFICATE_UPDATE_FAILED="keySystemServerCertificateUpdateFailed",e.KEY_SYSTEM_SESSION_UPDATE_FAILED="keySystemSessionUpdateFailed",e.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED="keySystemStatusOutputRestricted",e.KEY_SYSTEM_STATUS_INTERNAL_ERROR="keySystemStatusInternalError",e.MANIFEST_LOAD_ERROR="manifestLoadError",e.MANIFEST_LOAD_TIMEOUT="manifestLoadTimeOut",e.MANIFEST_PARSING_ERROR="manifestParsingError",e.MANIFEST_INCOMPATIBLE_CODECS_ERROR="manifestIncompatibleCodecsError",e.LEVEL_EMPTY_ERROR="levelEmptyError",e.LEVEL_LOAD_ERROR="levelLoadError",e.LEVEL_LOAD_TIMEOUT="levelLoadTimeOut",e.LEVEL_PARSING_ERROR="levelParsingError",e.LEVEL_SWITCH_ERROR="levelSwitchError",e.AUDIO_TRACK_LOAD_ERROR="audioTrackLoadError",e.AUDIO_TRACK_LOAD_TIMEOUT="audioTrackLoadTimeOut",e.SUBTITLE_LOAD_ERROR="subtitleTrackLoadError",e.SUBTITLE_TRACK_LOAD_TIMEOUT="subtitleTrackLoadTimeOut",e.FRAG_LOAD_ERROR="fragLoadError",e.FRAG_LOAD_TIMEOUT="fragLoadTimeOut",e.FRAG_DECRYPT_ERROR="fragDecryptError",e.FRAG_PARSING_ERROR="fragParsingError",e.FRAG_GAP="fragGap",e.REMUX_ALLOC_ERROR="remuxAllocError",e.KEY_LOAD_ERROR="keyLoadError",e.KEY_LOAD_TIMEOUT="keyLoadTimeOut",e.BUFFER_ADD_CODEC_ERROR="bufferAddCodecError",e.BUFFER_INCOMPATIBLE_CODECS_ERROR="bufferIncompatibleCodecsError",e.BUFFER_APPEND_ERROR="bufferAppendError",e.BUFFER_APPENDING_ERROR="bufferAppendingError",e.BUFFER_STALLED_ERROR="bufferStalledError",e.BUFFER_FULL_ERROR="bufferFullError",e.BUFFER_SEEK_OVER_HOLE="bufferSeekOverHole",e.BUFFER_NUDGE_ON_STALL="bufferNudgeOnStall",e.INTERNAL_EXCEPTION="internalException",e.INTERNAL_ABORTED="aborted",e.UNKNOWN="unknown",e}({}),T=function(){},L={trace:T,debug:T,log:T,warn:T,info:T,error:T},P=L;function w(e,t){if("object"==("undefined"==typeof console?"undefined":a(console))&&!0===e||"object"==(void 0===e?"undefined":a(e))){!function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];r.forEach((function(t){P[t]=e[t]?e[t].bind(e):function(e){var t=self.console[e];return t?t.bind(self.console,"["+e+"] >"):T}(t)}))}(e,"debug","log","info","warn","error");try{P.log('Debug logs enabled for "'+t+'" in hls.js version 1.5.11')}catch(e){P=L}}else P=L}var R=P,A=/^(\d+)x(\d+)$/,k=/(.+?)=(".*?"|.*?)(?:,|$)/g,C=function(){function e(t){"string"==typeof t&&(t=e.parseAttrList(t)),l(this,t)}var t=e.prototype;return t.decimalInteger=function(e){var t=parseInt(this[e],10);return t>Number.MAX_SAFE_INTEGER?1/0:t},t.hexadecimalInteger=function(e){if(this[e]){var t=(this[e]||"0x").slice(2);t=(1&t.length?"0":"")+t;for(var r=new Uint8Array(t.length/2),n=0;n<t.length/2;n++)r[n]=parseInt(t.slice(2*n,2*n+2),16);return r}return null},t.hexadecimalIntegerAsNumber=function(e){var t=parseInt(this[e],16);return t>Number.MAX_SAFE_INTEGER?1/0:t},t.decimalFloatingPoint=function(e){return parseFloat(this[e])},t.optionalFloat=function(e,t){var r=this[e];return r?parseFloat(r):t},t.enumeratedString=function(e){return this[e]},t.bool=function(e){return"YES"===this[e]},t.decimalResolution=function(e){var t=A.exec(this[e]);if(null!==t)return{width:parseInt(t[1],10),height:parseInt(t[2],10)}},e.parseAttrList=function(e){var t,r={};for(k.lastIndex=0;null!==(t=k.exec(e));){var n=t[2];0===n.indexOf('"')&&n.lastIndexOf('"')===n.length-1&&(n=n.slice(1,-1)),r[t[1].trim()]=n}return r},i(e,[{key:"clientAttrs",get:function(){return Object.keys(this).filter((function(e){return"X-"===e.substring(0,2)}))}}]),e}();function D(e){return"SCTE35-OUT"===e||"SCTE35-IN"===e}var I=function(){function e(e,t){if(this.attr=void 0,this._startDate=void 0,this._endDate=void 0,this._badValueForSameId=void 0,t){var r=t.attr;for(var n in r)if(Object.prototype.hasOwnProperty.call(e,n)&&e[n]!==r[n]){R.warn('DATERANGE tag attribute: "'+n+'" does not match for tags with ID: "'+e.ID+'"'),this._badValueForSameId=n;break}e=l(new C({}),r,e)}if(this.attr=e,this._startDate=new Date(e["START-DATE"]),"END-DATE"in this.attr){var i=new Date(this.attr["END-DATE"]);m(i.getTime())&&(this._endDate=i)}}return i(e,[{key:"id",get:function(){return this.attr.ID}},{key:"class",get:function(){return this.attr.CLASS}},{key:"startDate",get:function(){return this._startDate}},{key:"endDate",get:function(){if(this._endDate)return this._endDate;var e=this.duration;return null!==e?new Date(this._startDate.getTime()+1e3*e):null}},{key:"duration",get:function(){if("DURATION"in this.attr){var e=this.attr.decimalFloatingPoint("DURATION");if(m(e))return e}else if(this._endDate)return(this._endDate.getTime()-this._startDate.getTime())/1e3;return null}},{key:"plannedDuration",get:function(){return"PLANNED-DURATION"in this.attr?this.attr.decimalFloatingPoint("PLANNED-DURATION"):null}},{key:"endOnNext",get:function(){return this.attr.bool("END-ON-NEXT")}},{key:"isValid",get:function(){return!!this.id&&!this._badValueForSameId&&m(this.startDate.getTime())&&(null===this.duration||this.duration>=0)&&(!this.endOnNext||!!this.class)}}]),e}(),x=function(){this.aborted=!1,this.loaded=0,this.retry=0,this.total=0,this.chunkCount=0,this.bwEstimate=0,this.loading={start:0,first:0,end:0},this.parsing={start:0,end:0},this.buffering={start:0,first:0,end:0}},O="audio",M="video",F="audiovideo",N=function(){function e(e){var t;this._byteRange=null,this._url=null,this.baseurl=void 0,this.relurl=void 0,this.elementaryStreams=((t={})[O]=null,t[M]=null,t[F]=null,t),this.baseurl=e}return e.prototype.setByteRange=function(e,t){var r,n=e.split("@",2);r=1===n.length?(null==t?void 0:t.byteRangeEndOffset)||0:parseInt(n[1]),this._byteRange=[r,parseInt(n[0])+r]},i(e,[{key:"byteRange",get:function(){return this._byteRange?this._byteRange:[]}},{key:"byteRangeStartOffset",get:function(){return this.byteRange[0]}},{key:"byteRangeEndOffset",get:function(){return this.byteRange[1]}},{key:"url",get:function(){return!this._url&&this.baseurl&&this.relurl&&(this._url=p.buildAbsoluteURL(this.baseurl,this.relurl,{alwaysNormalize:!0})),this._url||""},set:function(e){this._url=e}}]),e}(),B=function(e){function t(t,r){var n;return(n=e.call(this,r)||this)._decryptdata=null,n.rawProgramDateTime=null,n.programDateTime=null,n.tagList=[],n.duration=0,n.sn=0,n.levelkeys=void 0,n.type=void 0,n.loader=null,n.keyLoader=null,n.level=-1,n.cc=0,n.startPTS=void 0,n.endPTS=void 0,n.startDTS=void 0,n.endDTS=void 0,n.start=0,n.deltaPTS=void 0,n.maxStartPTS=void 0,n.minEndPTS=void 0,n.stats=new x,n.data=void 0,n.bitrateTest=!1,n.title=null,n.initSegment=null,n.endList=void 0,n.gap=void 0,n.urlId=0,n.type=t,n}u(t,e);var r=t.prototype;return r.setKeyFormat=function(e){if(this.levelkeys){var t=this.levelkeys[e];t&&!this._decryptdata&&(this._decryptdata=t.getDecryptData(this.sn))}},r.abortRequests=function(){var e,t;null==(e=this.loader)||e.abort(),null==(t=this.keyLoader)||t.abort()},r.setElementaryStreamInfo=function(e,t,r,n,i,a){void 0===a&&(a=!1);var s=this.elementaryStreams,o=s[e];o?(o.startPTS=Math.min(o.startPTS,t),o.endPTS=Math.max(o.endPTS,r),o.startDTS=Math.min(o.startDTS,n),o.endDTS=Math.max(o.endDTS,i)):s[e]={startPTS:t,endPTS:r,startDTS:n,endDTS:i,partial:a}},r.clearElementaryStreamInfo=function(){var e=this.elementaryStreams;e[O]=null,e[M]=null,e[F]=null},i(t,[{key:"decryptdata",get:function(){if(!this.levelkeys&&!this._decryptdata)return null;if(!this._decryptdata&&this.levelkeys&&!this.levelkeys.NONE){var e=this.levelkeys.identity;if(e)this._decryptdata=e.getDecryptData(this.sn);else{var t=Object.keys(this.levelkeys);if(1===t.length)return this._decryptdata=this.levelkeys[t[0]].getDecryptData(this.sn)}}return this._decryptdata}},{key:"end",get:function(){return this.start+this.duration}},{key:"endProgramDateTime",get:function(){if(null===this.programDateTime)return null;if(!m(this.programDateTime))return null;var e=m(this.duration)?this.duration:0;return this.programDateTime+1e3*e}},{key:"encrypted",get:function(){var e;if(null!=(e=this._decryptdata)&&e.encrypted)return!0;if(this.levelkeys){var t=Object.keys(this.levelkeys),r=t.length;if(r>1||1===r&&this.levelkeys[t[0]].encrypted)return!0}return!1}}]),t}(N),U=function(e){function t(t,r,n,i,a){var s;(s=e.call(this,n)||this).fragOffset=0,s.duration=0,s.gap=!1,s.independent=!1,s.relurl=void 0,s.fragment=void 0,s.index=void 0,s.stats=new x,s.duration=t.decimalFloatingPoint("DURATION"),s.gap=t.bool("GAP"),s.independent=t.bool("INDEPENDENT"),s.relurl=t.enumeratedString("URI"),s.fragment=r,s.index=i;var o=t.enumeratedString("BYTERANGE");return o&&s.setByteRange(o,a),a&&(s.fragOffset=a.fragOffset+a.duration),s}return u(t,e),i(t,[{key:"start",get:function(){return this.fragment.start+this.fragOffset}},{key:"end",get:function(){return this.start+this.duration}},{key:"loaded",get:function(){var e=this.elementaryStreams;return!!(e.audio||e.video||e.audiovideo)}}]),t}(N),G=function(){function e(e){this.PTSKnown=!1,this.alignedSliding=!1,this.averagetargetduration=void 0,this.endCC=0,this.endSN=0,this.fragments=void 0,this.fragmentHint=void 0,this.partList=null,this.dateRanges=void 0,this.live=!0,this.ageHeader=0,this.advancedDateTime=void 0,this.updated=!0,this.advanced=!0,this.availabilityDelay=void 0,this.misses=0,this.startCC=0,this.startSN=0,this.startTimeOffset=null,this.targetduration=0,this.totalduration=0,this.type=null,this.url=void 0,this.m3u8="",this.version=null,this.canBlockReload=!1,this.canSkipUntil=0,this.canSkipDateRanges=!1,this.skippedSegments=0,this.recentlyRemovedDateranges=void 0,this.partHoldBack=0,this.holdBack=0,this.partTarget=0,this.preloadHint=void 0,this.renditionReports=void 0,this.tuneInGoal=0,this.deltaUpdateFailed=void 0,this.driftStartTime=0,this.driftEndTime=0,this.driftStart=0,this.driftEnd=0,this.encryptedFragments=void 0,this.playlistParsingError=null,this.variableList=null,this.hasVariableRefs=!1,this.fragments=[],this.encryptedFragments=[],this.dateRanges={},this.url=e}return e.prototype.reloaded=function(e){if(!e)return this.advanced=!0,void(this.updated=!0);var t=this.lastPartSn-e.lastPartSn,r=this.lastPartIndex-e.lastPartIndex;this.updated=this.endSN!==e.endSN||!!r||!!t||!this.live,this.advanced=this.endSN>e.endSN||t>0||0===t&&r>0,this.updated||this.advanced?this.misses=Math.floor(.6*e.misses):this.misses=e.misses+1,this.availabilityDelay=e.availabilityDelay},i(e,[{key:"hasProgramDateTime",get:function(){return!!this.fragments.length&&m(this.fragments[this.fragments.length-1].programDateTime)}},{key:"levelTargetDuration",get:function(){return this.averagetargetduration||this.targetduration||10}},{key:"drift",get:function(){var e=this.driftEndTime-this.driftStartTime;return e>0?1e3*(this.driftEnd-this.driftStart)/e:1}},{key:"edge",get:function(){return this.partEnd||this.fragmentEnd}},{key:"partEnd",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].end:this.fragmentEnd}},{key:"fragmentEnd",get:function(){var e;return null!=(e=this.fragments)&&e.length?this.fragments[this.fragments.length-1].end:0}},{key:"age",get:function(){return this.advancedDateTime?Math.max(Date.now()-this.advancedDateTime,0)/1e3:0}},{key:"lastPartIndex",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].index:-1}},{key:"lastPartSn",get:function(){var e;return null!=(e=this.partList)&&e.length?this.partList[this.partList.length-1].fragment.sn:this.endSN}}]),e}(),j=g(void 0);function H(e,t,r){return Uint8Array.prototype.slice?e.slice(t,r):new Uint8Array(Array.prototype.slice.call(e,t,r))}var q,V=function(e,t){return t+10<=e.length&&73===e[t]&&68===e[t+1]&&51===e[t+2]&&e[t+3]<255&&e[t+4]<255&&e[t+6]<128&&e[t+7]<128&&e[t+8]<128&&e[t+9]<128},W=function(e,t){return t+10<=e.length&&51===e[t]&&68===e[t+1]&&73===e[t+2]&&e[t+3]<255&&e[t+4]<255&&e[t+6]<128&&e[t+7]<128&&e[t+8]<128&&e[t+9]<128},K=function(e,t){for(var r=t,n=0;V(e,t);)n+=10,n+=z(e,t+6),W(e,t+10)&&(n+=10),t+=n;if(n>0)return e.subarray(r,r+n)},z=function(e,t){var r=0;return r=(127&e[t])<<21,r|=(127&e[t+1])<<14,(r|=(127&e[t+2])<<7)|127&e[t+3]},Y=function(e,t){return V(e,t)&&z(e,t+6)+10<=e.length-t},X=function(e){for(var t=Z(e),r=0;r<t.length;r++){var n=t[r];if(J(n))return ne(n)}},J=function(e){return e&&"PRIV"===e.key&&"com.apple.streaming.transportStreamTimestamp"===e.info},Q=function(e){var t=String.fromCharCode(e[0],e[1],e[2],e[3]),r=z(e,4);return{type:t,size:r,data:e.subarray(10,10+r)}},Z=function(e){for(var t=0,r=[];V(e,t);){for(var n=z(e,t+6),i=(t+=10)+n;t+8<i;){var a=Q(e.subarray(t)),s=$(a);s&&r.push(s),t+=a.size+10}W(e,t)&&(t+=10)}return r},$=function(e){return"PRIV"===e.type?ee(e):"W"===e.type[0]?re(e):te(e)},ee=function(e){if(!(e.size<2)){var t=ie(e.data,!0),r=new Uint8Array(e.data.subarray(t.length+1));return{key:e.type,info:t,data:r.buffer}}},te=function(e){if(!(e.size<2)){if("TXXX"===e.type){var t=1,r=ie(e.data.subarray(t),!0);t+=r.length+1;var n=ie(e.data.subarray(t));return{key:e.type,info:r,data:n}}var i=ie(e.data.subarray(1));return{key:e.type,data:i}}},re=function(e){if("WXXX"===e.type){if(e.size<2)return;var t=1,r=ie(e.data.subarray(t),!0);t+=r.length+1;var n=ie(e.data.subarray(t));return{key:e.type,info:r,data:n}}var i=ie(e.data);return{key:e.type,data:i}},ne=function(e){if(8===e.data.byteLength){var t=new Uint8Array(e.data),r=1&t[3],n=(t[4]<<23)+(t[5]<<15)+(t[6]<<7)+t[7];return n/=45,r&&(n+=47721858.84),Math.round(n)}},ie=function(e,t){void 0===t&&(t=!1);var r=function(){if(!navigator.userAgent.includes("PlayStation 4"))return q||void 0===self.TextDecoder||(q=new self.TextDecoder("utf-8")),q}();if(r){var n=r.decode(e);if(t){var i=n.indexOf("\0");return-1!==i?n.substring(0,i):n}return n.replace(/\0/g,"")}for(var a,s,o,l=e.length,u="",d=0;d<l;){if(0===(a=e[d++])&&t)return u;if(0!==a&&3!==a)switch(a>>4){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:u+=String.fromCharCode(a);break;case 12:case 13:s=e[d++],u+=String.fromCharCode((31&a)<<6|63&s);break;case 14:s=e[d++],o=e[d++],u+=String.fromCharCode((15&a)<<12|(63&s)<<6|63&o)}}return u};var ae=function(e){for(var t="",r=0;r<e.length;r++){var n=e[r].toString(16);n.length<2&&(n="0"+n),t+=n}return t},se=Math.pow(2,32)-1,oe=[].push,le={video:1,audio:2,id3:3,text:4};function ue(e){return String.fromCharCode.apply(null,e)}function de(e,t){var r=e[t]<<8|e[t+1];return r<0?65536+r:r}function ce(e,t){var r=he(e,t);return r<0?4294967296+r:r}function fe(e,t){var r=ce(e,t);return(r*=Math.pow(2,32))+ce(e,t+4)}function he(e,t){return e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function ge(e,t,r){e[t]=r>>24,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=255&r}function ve(e,t){var r=[];if(!t.length)return r;for(var n=e.byteLength,i=0;i<n;){var a=ce(e,i),s=a>1?i+a:n;if(ue(e.subarray(i+4,i+8))===t[0])if(1===t.length)r.push(e.subarray(i+8,s));else{var o=ve(e.subarray(i+8,s),t.slice(1));o.length&&oe.apply(r,o)}i=s}return r}function pe(e){var t=[],r=e[0],n=8,i=ce(e,n);n+=4;var a=0,s=0;0===r?(a=ce(e,n),s=ce(e,n+4),n+=8):(a=fe(e,n),s=fe(e,n+8),n+=16),n+=2;var o=e.length+s,l=de(e,n);n+=2;for(var u=0;u<l;u++){var d=n,c=ce(e,d);d+=4;var f=2147483647&c;if(1==(2147483648&c)>>>31)return R.warn("SIDX has hierarchical references (not supported)"),null;var h=ce(e,d);d+=4,t.push({referenceSize:f,subsegmentDuration:h,info:{duration:h/i,start:o,end:o+f-1}}),o+=f,n=d+=4}return{earliestPresentationTime:a,timescale:i,version:r,referencesCount:l,references:t}}function me(e){for(var r=[],n=ve(e,["moov","trak"]),i=0;i<n.length;i++){var a=n[i],s=ve(a,["tkhd"])[0];if(s){var o=s[0],l=ce(s,0===o?12:20),u=ve(a,["mdia","mdhd"])[0];if(u){var d=ce(u,0===(o=u[0])?12:20),c=ve(a,["mdia","hdlr"])[0];if(c){var f=ue(c.subarray(8,12)),h={soun:O,vide:M}[f];if(h){var g=ye(ve(a,["mdia","minf","stbl","stsd"])[0]);r[l]={timescale:d,type:h},r[h]=t({timescale:d,id:l},g)}}}}}return ve(e,["moov","mvex","trex"]).forEach((function(e){var t=ce(e,4),n=r[t];n&&(n.default={duration:ce(e,12),flags:ce(e,20)})})),r}function ye(e){var t=e.subarray(8),r=t.subarray(86),n=ue(t.subarray(4,8)),i=n,a="enca"===n||"encv"===n;if(a){var s=ve(t,[n])[0];ve(s.subarray("enca"===n?28:78),["sinf"]).forEach((function(e){var t=ve(e,["schm"])[0];if(t){var r=ue(t.subarray(4,8));if("cbcs"===r||"cenc"===r){var n=ve(e,["frma"])[0];n&&(i=ue(n))}}}))}switch(i){case"avc1":case"avc2":case"avc3":case"avc4":var o=ve(r,["avcC"])[0];i+="."+Ee(o[1])+Ee(o[2])+Ee(o[3]);break;case"mp4a":var l=ve(t,[n])[0],u=ve(l.subarray(28),["esds"])[0];if(u&&u.length>12){var d=4;if(3!==u[d++])break;d=be(u,d),d+=2;var c=u[d++];if(128&c&&(d+=2),64&c&&(d+=u[d++]),4!==u[d++])break;d=be(u,d);var f=u[d++];if(64!==f)break;if(i+="."+Ee(f),d+=12,5!==u[d++])break;d=be(u,d);var h=u[d++],g=(248&h)>>3;31===g&&(g+=1+((7&h)<<3)+((224&u[d])>>5)),i+="."+g}break;case"hvc1":case"hev1":var v=ve(r,["hvcC"])[0],p=v[1],m=["","A","B","C"][p>>6],y=31&p,b=ce(v,2),E=(32&p)>>5?"H":"L",S=v[12],_=v.subarray(6,12);i+="."+m+y,i+="."+b.toString(16).toUpperCase(),i+="."+E+S;for(var T="",L=_.length;L--;){var P=_[L];(P||T)&&(T="."+P.toString(16).toUpperCase()+T)}i+=T;break;case"dvh1":case"dvhe":var w=ve(r,["dvcC"])[0],R=w[2]>>1&127,A=w[2]<<5&32|w[3]>>3&31;i+="."+Se(R)+"."+Se(A);break;case"vp09":var k=ve(r,["vpcC"])[0],C=k[4],D=k[5],I=k[6]>>4&15;i+="."+Se(C)+"."+Se(D)+"."+Se(I);break;case"av01":var x=ve(r,["av1C"])[0],O=x[1]>>>5,M=31&x[1],F=x[2]>>>7?"H":"M",N=(64&x[2])>>6,B=(32&x[2])>>5,U=2===O&&N?B?12:10:N?10:8,G=(16&x[2])>>4,j=(8&x[2])>>3,H=(4&x[2])>>2,q=3&x[2];i+="."+O+"."+Se(M)+F+"."+Se(U)+"."+G+"."+j+H+q+"."+Se(1)+"."+Se(1)+"."+Se(1)+".0"}return{codec:i,encrypted:a}}function be(e,t){for(var r=t+5;128&e[t++]&&t<r;);return t}function Ee(e){return("0"+e.toString(16).toUpperCase()).slice(-2)}function Se(e){return(e<10?"0":"")+e}function _e(e){var t=ce(e,0),r=8;1&t&&(r+=4),4&t&&(r+=4);for(var n=0,i=ce(e,4),a=0;a<i;a++)256&t&&(n+=ce(e,r),r+=4),512&t&&(r+=4),1024&t&&(r+=4),2048&t&&(r+=4);return n}function Te(e,t){var r=new Uint8Array(e.length+t.length);return r.set(e),r.set(t,e.length),r}function Le(e,t){var r=[],n=t.samples,i=t.timescale,a=t.id,s=!1;return ve(n,["moof"]).map((function(o){var l=o.byteOffset-8;ve(o,["traf"]).map((function(o){var u=ve(o,["tfdt"]).map((function(e){var t=e[0],r=ce(e,4);return 1===t&&(r*=Math.pow(2,32),r+=ce(e,8)),r/i}))[0];return void 0!==u&&(e=u),ve(o,["tfhd"]).map((function(u){var d=ce(u,4),c=16777215&ce(u,0),f=0,h=!!(16&c),g=0,v=!!(32&c),p=8;d===a&&(!!(1&c)&&(p+=8),!!(2&c)&&(p+=4),!!(8&c)&&(f=ce(u,p),p+=4),h&&(g=ce(u,p),p+=4),v&&(p+=4),"video"===t.type&&(s=function(e){if(!e)return!1;var t=e.indexOf("."),r=t<0?e:e.substring(0,t);return"hvc1"===r||"hev1"===r||"dvh1"===r||"dvhe"===r}(t.codec)),ve(o,["trun"]).map((function(a){var o=a[0],u=16777215&ce(a,0),d=!!(1&u),c=0,h=!!(4&u),v=!!(256&u),p=0,m=!!(512&u),y=0,b=!!(1024&u),E=!!(2048&u),S=0,_=ce(a,4),T=8;d&&(c=ce(a,T),T+=4),h&&(T+=4);for(var L=c+l,P=0;P<_;P++){if(v?(p=ce(a,T),T+=4):p=f,m?(y=ce(a,T),T+=4):y=g,b&&(T+=4),E&&(S=0===o?ce(a,T):he(a,T),T+=4),t.type===M)for(var w=0;w<y;){var R=ce(n,L);Pe(s,n[L+=4])&&we(n.subarray(L,L+R),s?2:1,e+S/i,r),L+=R,w+=R+4}e+=p/i}})))}))}))})),r}function Pe(e,t){if(e){var r=t>>1&63;return 39===r||40===r}return 6==(31&t)}function we(e,t,r,n){var i=Re(e),a=0;a+=t;for(var s=0,o=0,l=0;a<i.length;){s=0;do{if(a>=i.length)break;s+=l=i[a++]}while(255===l);o=0;do{if(a>=i.length)break;o+=l=i[a++]}while(255===l);var u=i.length-a,d=a;if(o<u)a+=o;else if(o>u){R.error("Malformed SEI payload. "+o+" is too small, only "+u+" bytes left to parse.");break}if(4===s){if(181===i[d++]){var c=de(i,d);if(d+=2,49===c){var f=ce(i,d);if(d+=4,1195456820===f){var h=i[d++];if(3===h){var g=i[d++],v=64&g,p=v?2+3*(31&g):0,m=new Uint8Array(p);if(v){m[0]=g;for(var y=1;y<p;y++)m[y]=i[d++]}n.push({type:h,payloadType:s,pts:r,bytes:m})}}}}}else if(5===s&&o>16){for(var b=[],E=0;E<16;E++){var S=i[d++].toString(16);b.push(1==S.length?"0"+S:S),3!==E&&5!==E&&7!==E&&9!==E||b.push("-")}for(var _=o-16,T=new Uint8Array(_),L=0;L<_;L++)T[L]=i[d++];n.push({payloadType:s,pts:r,uuid:b.join(""),userData:ie(T),userDataBytes:T})}}}function Re(e){for(var t=e.byteLength,r=[],n=1;n<t-2;)0===e[n]&&0===e[n+1]&&3===e[n+2]?(r.push(n+2),n+=2):n++;if(0===r.length)return e;var i=t-r.length,a=new Uint8Array(i),s=0;for(n=0;n<i;s++,n++)s===r[0]&&(s++,r.shift()),a[n]=e[s];return a}var Ae=function(){function e(e,t,r,n,i){void 0===n&&(n=[1]),void 0===i&&(i=null),this.uri=void 0,this.method=void 0,this.keyFormat=void 0,this.keyFormatVersions=void 0,this.encrypted=void 0,this.isCommonEncryption=void 0,this.iv=null,this.key=null,this.keyId=null,this.pssh=null,this.method=e,this.uri=t,this.keyFormat=r,this.keyFormatVersions=n,this.iv=i,this.encrypted=!!e&&"NONE"!==e,this.isCommonEncryption=this.encrypted&&"AES-128"!==e}e.clearKeyUriToKeyIdMap=function(){};var t=e.prototype;return t.isSupported=function(){if(this.method){if("AES-128"===this.method||"NONE"===this.method)return!0;if("identity"===this.keyFormat)return"SAMPLE-AES"===this.method}return!1},t.getDecryptData=function(t){if(!this.encrypted||!this.uri)return null;if("AES-128"===this.method&&this.uri&&!this.iv){"number"!=typeof t&&("AES-128"!==this.method||this.iv||R.warn('missing IV for initialization segment with method="'+this.method+'" - compliance issue'),t=0);var r=function(e){for(var t=new Uint8Array(16),r=12;r<16;r++)t[r]=e>>8*(15-r)&255;return t}(t);return new e(this.method,this.uri,"identity",this.keyFormatVersions,r)}return this},e}();function ke(e){if(void 0===e&&(e=!0),"undefined"!=typeof self)return(e||!self.MediaSource)&&self.ManagedMediaSource||self.MediaSource||self.WebKitMediaSource}var Ce={audio:{a3ds:1,"ac-3":.95,"ac-4":1,alac:.9,alaw:1,dra1:1,"dts+":1,"dts-":1,dtsc:1,dtse:1,dtsh:1,"ec-3":.9,enca:1,fLaC:.9,flac:.9,FLAC:.9,g719:1,g726:1,m4ae:1,mha1:1,mha2:1,mhm1:1,mhm2:1,mlpa:1,mp4a:1,"raw ":1,Opus:1,opus:1,samr:1,sawb:1,sawp:1,sevc:1,sqcp:1,ssmv:1,twos:1,ulaw:1},video:{avc1:1,avc2:1,avc3:1,avc4:1,avcp:1,av01:.8,drac:1,dva1:1,dvav:1,dvh1:.7,dvhe:.7,encv:1,hev1:.75,hvc1:.75,mjp2:1,mp4v:1,mvc1:1,mvc2:1,mvc3:1,mvc4:1,resv:1,rv60:1,s263:1,svc1:1,svc2:1,"vc-1":1,vp08:1,vp09:.9},text:{stpp:1,wvtt:1}};function De(e,t,r){return void 0===r&&(r=!0),!e.split(",").some((function(e){return!Ie(e,t,r)}))}function Ie(e,t,r){var n;void 0===r&&(r=!0);var i=ke(r);return null!=(n=null==i?void 0:i.isTypeSupported(xe(e,t)))&&n}function xe(e,t){return t+'/mp4;codecs="'+e+'"'}function Oe(e){if(e){var t=e.substring(0,4);return Ce.video[t]}return 2}function Me(e){return e.split(",").reduce((function(e,t){var r=Ce.video[t];return r?(2*r+e)/(e?3:2):(Ce.audio[t]+e)/(e?2:1)}),0)}var Fe={},Ne=/flac|opus/i;function Be(e,t){return void 0===t&&(t=!0),e.replace(Ne,(function(e){return function(e,t){if(void 0===t&&(t=!0),Fe[e])return Fe[e];for(var r={flac:["flac","fLaC","FLAC"],opus:["opus","Opus"]}[e],n=0;n<r.length;n++)if(Ie(r[n],"audio",t))return Fe[e]=r[n],r[n];return e}(e.toLowerCase(),t)}))}function Ue(e,t){return e&&"mp4a"!==e?e:t?t.split(",")[0]:t}var Ge=/#EXT-X-STREAM-INF:([^\r\n]*)(?:[\r\n](?:#[^\r\n]*)?)*([^\r\n]+)|#EXT-X-(SESSION-DATA|SESSION-KEY|DEFINE|CONTENT-STEERING|START):([^\r\n]*)[\r\n]+/g,je=/#EXT-X-MEDIA:(.*)/g,He=/^#EXT(?:INF|-X-TARGETDURATION):/m,qe=new RegExp([/#EXTINF:\s*(\d*(?:\.\d+)?)(?:,(.*)\s+)?/.source,/(?!#) *(\S[^\r\n]*)/.source,/#EXT-X-BYTERANGE:*(.+)/.source,/#EXT-X-PROGRAM-DATE-TIME:(.+)/.source,/#.*/.source].join("|"),"g"),Ve=new RegExp([/#(EXTM3U)/.source,/#EXT-X-(DATERANGE|DEFINE|KEY|MAP|PART|PART-INF|PLAYLIST-TYPE|PRELOAD-HINT|RENDITION-REPORT|SERVER-CONTROL|SKIP|START):(.+)/.source,/#EXT-X-(BITRATE|DISCONTINUITY-SEQUENCE|MEDIA-SEQUENCE|TARGETDURATION|VERSION): *(\d+)/.source,/#EXT-X-(DISCONTINUITY|ENDLIST|GAP|INDEPENDENT-SEGMENTS)/.source,/(#)([^:]*):(.*)/.source,/(#)(.*)(?:.*)\r?\n?/.source].join("|")),We=function(){function e(){}return e.findGroup=function(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.id===t)return n}},e.resolve=function(e,t){return p.buildAbsoluteURL(t,e,{alwaysNormalize:!0})},e.isMediaPlaylist=function(e){return He.test(e)},e.parseMasterPlaylist=function(t,r){var n,i={contentSteering:null,levels:[],playlistParsingError:null,sessionData:null,sessionKeys:null,startTimeOffset:null,variableList:null,hasVariableRefs:!1},a=[];for(Ge.lastIndex=0;null!=(n=Ge.exec(t));)if(n[1]){var s,o=new C(n[1]),l=n[2],u={attrs:o,bitrate:o.decimalInteger("BANDWIDTH")||o.decimalInteger("AVERAGE-BANDWIDTH"),name:o.NAME,url:e.resolve(l,r)},d=o.decimalResolution("RESOLUTION");d&&(u.width=d.width,u.height=d.height),Ye(o.CODECS,u),null!=(s=u.unknownCodecs)&&s.length||a.push(u),i.levels.push(u)}else if(n[3]){var c=n[3],f=n[4];switch(c){case"SESSION-DATA":var h=new C(f),g=h["DATA-ID"];g&&(null===i.sessionData&&(i.sessionData={}),i.sessionData[g]=h);break;case"SESSION-KEY":var v=Ke(f,r);v.encrypted&&v.isSupported()?(null===i.sessionKeys&&(i.sessionKeys=[]),i.sessionKeys.push(v)):R.warn('[Keys] Ignoring invalid EXT-X-SESSION-KEY tag: "'+f+'"');break;case"DEFINE":break;case"CONTENT-STEERING":var p=new C(f);i.contentSteering={uri:e.resolve(p["SERVER-URI"],r),pathwayId:p["PATHWAY-ID"]||"."};break;case"START":i.startTimeOffset=ze(f)}}var m=a.length>0&&a.length<i.levels.length;return i.levels=m?a:i.levels,0===i.levels.length&&(i.playlistParsingError=new Error("no levels found in manifest")),i},e.parseMasterPlaylistMedia=function(t,r,n){var i,a={},s=n.levels,o={AUDIO:s.map((function(e){return{id:e.attrs.AUDIO,audioCodec:e.audioCodec}})),SUBTITLES:s.map((function(e){return{id:e.attrs.SUBTITLES,textCodec:e.textCodec}})),"CLOSED-CAPTIONS":[]},l=0;for(je.lastIndex=0;null!==(i=je.exec(t));){var u=new C(i[1]),d=u.TYPE;if(d){var c=o[d],f=a[d]||[];a[d]=f;var h=u.LANGUAGE,g=u["ASSOC-LANGUAGE"],v=u.CHANNELS,p=u.CHARACTERISTICS,m=u["INSTREAM-ID"],y={attrs:u,bitrate:0,id:l++,groupId:u["GROUP-ID"]||"",name:u.NAME||h||"",type:d,default:u.bool("DEFAULT"),autoselect:u.bool("AUTOSELECT"),forced:u.bool("FORCED"),lang:h,url:u.URI?e.resolve(u.URI,r):""};if(g&&(y.assocLang=g),v&&(y.channels=v),p&&(y.characteristics=p),m&&(y.instreamId=m),null!=c&&c.length){var b=e.findGroup(c,y.groupId)||c[0];Xe(y,b,"audioCodec"),Xe(y,b,"textCodec")}f.push(y)}}return a},e.parseLevelPlaylist=function(e,t,r,n,i,a){var s,o,u,d=new G(t),c=d.fragments,f=null,h=0,g=0,v=0,p=0,y=null,b=new B(n,t),E=-1,S=!1,_=null;for(qe.lastIndex=0,d.m3u8=e,d.hasVariableRefs=!1;null!==(s=qe.exec(e));){S&&(S=!1,(b=new B(n,t)).start=v,b.sn=h,b.cc=p,b.level=r,f&&(b.initSegment=f,b.rawProgramDateTime=f.rawProgramDateTime,f.rawProgramDateTime=null,_&&(b.setByteRange(_),_=null)));var T=s[1];if(T){b.duration=parseFloat(T);var L=(" "+s[2]).slice(1);b.title=L||null,b.tagList.push(L?["INF",T,L]:["INF",T])}else if(s[3]){if(m(b.duration)){b.start=v,u&&Ze(b,u,d),b.sn=h,b.level=r,b.cc=p,c.push(b);var P=(" "+s[3]).slice(1);b.relurl=P,Je(b,y),y=b,v+=b.duration,h++,g=0,S=!0}}else if(s[4]){var w=(" "+s[4]).slice(1);y?b.setByteRange(w,y):b.setByteRange(w)}else if(s[5])b.rawProgramDateTime=(" "+s[5]).slice(1),b.tagList.push(["PROGRAM-DATE-TIME",b.rawProgramDateTime]),-1===E&&(E=c.length);else{if(!(s=s[0].match(Ve))){R.warn("No matches on slow regex match for level playlist!");continue}for(o=1;o<s.length&&void 0===s[o];o++);var A=(" "+s[o]).slice(1),k=(" "+s[o+1]).slice(1),D=s[o+2]?(" "+s[o+2]).slice(1):"";switch(A){case"PLAYLIST-TYPE":d.type=k.toUpperCase();break;case"MEDIA-SEQUENCE":h=d.startSN=parseInt(k);break;case"SKIP":var x=new C(k),O=x.decimalInteger("SKIPPED-SEGMENTS");if(m(O)){d.skippedSegments=O;for(var M=O;M--;)c.unshift(null);h+=O}var F=x.enumeratedString("RECENTLY-REMOVED-DATERANGES");F&&(d.recentlyRemovedDateranges=F.split("\t"));break;case"TARGETDURATION":d.targetduration=Math.max(parseInt(k),1);break;case"VERSION":d.version=parseInt(k);break;case"INDEPENDENT-SEGMENTS":case"EXTM3U":case"DEFINE":break;case"ENDLIST":d.live=!1;break;case"#":(k||D)&&b.tagList.push(D?[k,D]:[k]);break;case"DISCONTINUITY":p++,b.tagList.push(["DIS"]);break;case"GAP":b.gap=!0,b.tagList.push([A]);break;case"BITRATE":b.tagList.push([A,k]);break;case"DATERANGE":var N=new C(k),j=new I(N,d.dateRanges[N.ID]);j.isValid||d.skippedSegments?d.dateRanges[j.id]=j:R.warn('Ignoring invalid DATERANGE tag: "'+k+'"'),b.tagList.push(["EXT-X-DATERANGE",k]);break;case"DISCONTINUITY-SEQUENCE":p=parseInt(k);break;case"KEY":var H=Ke(k,t);if(H.isSupported()){if("NONE"===H.method){u=void 0;break}u||(u={}),u[H.keyFormat]&&(u=l({},u)),u[H.keyFormat]=H}else R.warn('[Keys] Ignoring invalid EXT-X-KEY tag: "'+k+'"');break;case"START":d.startTimeOffset=ze(k);break;case"MAP":var q=new C(k);if(b.duration){var V=new B(n,t);Qe(V,q,r,u),f=V,b.initSegment=f,f.rawProgramDateTime&&!b.rawProgramDateTime&&(b.rawProgramDateTime=f.rawProgramDateTime)}else{var W=b.byteRangeEndOffset;if(W){var K=b.byteRangeStartOffset;_=W-K+"@"+K}else _=null;Qe(b,q,r,u),f=b,S=!0}break;case"SERVER-CONTROL":var z=new C(k);d.canBlockReload=z.bool("CAN-BLOCK-RELOAD"),d.canSkipUntil=z.optionalFloat("CAN-SKIP-UNTIL",0),d.canSkipDateRanges=d.canSkipUntil>0&&z.bool("CAN-SKIP-DATERANGES"),d.partHoldBack=z.optionalFloat("PART-HOLD-BACK",0),d.holdBack=z.optionalFloat("HOLD-BACK",0);break;case"PART-INF":var Y=new C(k);d.partTarget=Y.decimalFloatingPoint("PART-TARGET");break;case"PART":var X=d.partList;X||(X=d.partList=[]);var J=g>0?X[X.length-1]:void 0,Q=g++,Z=new C(k),$=new U(Z,b,t,Q,J);X.push($),b.duration+=$.duration;break;case"PRELOAD-HINT":var ee=new C(k);d.preloadHint=ee;break;case"RENDITION-REPORT":var te=new C(k);d.renditionReports=d.renditionReports||[],d.renditionReports.push(te);break;default:R.warn("line parsed but not handled: "+s)}}}y&&!y.relurl?(c.pop(),v-=y.duration,d.partList&&(d.fragmentHint=y)):d.partList&&(Je(b,y),b.cc=p,d.fragmentHint=b,u&&Ze(b,u,d));var re=c.length,ne=c[0],ie=c[re-1];if((v+=d.skippedSegments*d.targetduration)>0&&re&&ie){d.averagetargetduration=v/re;var ae=ie.sn;d.endSN="initSegment"!==ae?ae:0,d.live||(ie.endList=!0),ne&&(d.startCC=ne.cc)}else d.endSN=0,d.startCC=0;return d.fragmentHint&&(v+=d.fragmentHint.duration),d.totalduration=v,d.endCC=p,E>0&&function(e,t){for(var r=e[t],n=t;n--;){var i=e[n];if(!i)return;i.programDateTime=r.programDateTime-1e3*i.duration,r=i}}(c,E),d},e}();function Ke(e,t,r){var n,i,a=new C(e),s=null!=(n=a.METHOD)?n:"",o=a.URI,l=a.hexadecimalInteger("IV"),u=a.KEYFORMATVERSIONS,d=null!=(i=a.KEYFORMAT)?i:"identity";o&&a.IV&&!l&&R.error("Invalid IV: "+a.IV);var c=o?We.resolve(o,t):"",f=(u||"1").split("/").map(Number).filter(Number.isFinite);return new Ae(s,c,d,f,l)}function ze(e){var t=new C(e).decimalFloatingPoint("TIME-OFFSET");return m(t)?t:null}function Ye(e,t){var r=(e||"").split(/[ ,]+/).filter((function(e){return e}));["video","audio","text"].forEach((function(e){var n=r.filter((function(t){return function(e,t){var r=Ce[t];return!!r&&!!r[e.slice(0,4)]}(t,e)}));n.length&&(t[e+"Codec"]=n.join(","),r=r.filter((function(e){return-1===n.indexOf(e)})))})),t.unknownCodecs=r}function Xe(e,t,r){var n=t[r];n&&(e[r]=n)}function Je(e,t){e.rawProgramDateTime?e.programDateTime=Date.parse(e.rawProgramDateTime):null!=t&&t.programDateTime&&(e.programDateTime=t.endProgramDateTime),m(e.programDateTime)||(e.programDateTime=null,e.rawProgramDateTime=null)}function Qe(e,t,r,n){e.relurl=t.URI,t.BYTERANGE&&e.setByteRange(t.BYTERANGE),e.level=r,e.sn="initSegment",n&&(e.levelkeys=n),e.initSegment=null}function Ze(e,t,r){e.levelkeys=t;var n=r.encryptedFragments;n.length&&n[n.length-1].levelkeys===t||!Object.keys(t).some((function(e){return t[e].isCommonEncryption}))||n.push(e)}var $e="manifest",et="level",tt="audioTrack",rt="subtitleTrack",nt="main",it="audio",at="subtitle";function st(e){switch(e.type){case tt:return it;case rt:return at;default:return nt}}function ot(e,t){var r=e.url;return void 0!==r&&0!==r.indexOf("data:")||(r=t.url),r}var lt=function(){function e(e){this.hls=void 0,this.loaders=Object.create(null),this.variableList=null,this.hls=e,this.registerListeners()}var r=e.prototype;return r.startLoad=function(e){},r.stopLoad=function(){this.destroyInternalLoaders()},r.registerListeners=function(){var e=this.hls;e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.LEVEL_LOADING,this.onLevelLoading,this),e.on(E.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.on(E.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},r.unregisterListeners=function(){var e=this.hls;e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.LEVEL_LOADING,this.onLevelLoading,this),e.off(E.AUDIO_TRACK_LOADING,this.onAudioTrackLoading,this),e.off(E.SUBTITLE_TRACK_LOADING,this.onSubtitleTrackLoading,this)},r.createInternalLoader=function(e){var t=this.hls.config,r=t.pLoader,n=t.loader,i=new(r||n)(t);return this.loaders[e.type]=i,i},r.getInternalLoader=function(e){return this.loaders[e.type]},r.resetInternalLoader=function(e){this.loaders[e]&&delete this.loaders[e]},r.destroyInternalLoaders=function(){for(var e in this.loaders){var t=this.loaders[e];t&&t.destroy(),this.resetInternalLoader(e)}},r.destroy=function(){this.variableList=null,this.unregisterListeners(),this.destroyInternalLoaders()},r.onManifestLoading=function(e,t){var r=t.url;this.variableList=null,this.load({id:null,level:0,responseType:"text",type:$e,url:r,deliveryDirectives:null})},r.onLevelLoading=function(e,t){var r=t.id,n=t.level,i=t.pathwayId,a=t.url,s=t.deliveryDirectives;this.load({id:r,level:n,pathwayId:i,responseType:"text",type:et,url:a,deliveryDirectives:s})},r.onAudioTrackLoading=function(e,t){var r=t.id,n=t.groupId,i=t.url,a=t.deliveryDirectives;this.load({id:r,groupId:n,level:null,responseType:"text",type:tt,url:i,deliveryDirectives:a})},r.onSubtitleTrackLoading=function(e,t){var r=t.id,n=t.groupId,i=t.url,a=t.deliveryDirectives;this.load({id:r,groupId:n,level:null,responseType:"text",type:rt,url:i,deliveryDirectives:a})},r.load=function(e){var t,r,n,i=this,a=this.hls.config,s=this.getInternalLoader(e);if(s){var o=s.context;if(o&&o.url===e.url&&o.level===e.level)return void R.trace("[playlist-loader]: playlist request ongoing");R.log("[playlist-loader]: aborting previous loader for type: "+e.type),s.abort()}if(r=e.type===$e?a.manifestLoadPolicy.default:l({},a.playlistLoadPolicy.default,{timeoutRetry:null,errorRetry:null}),s=this.createInternalLoader(e),m(null==(t=e.deliveryDirectives)?void 0:t.part)&&(e.type===et&&null!==e.level?n=this.hls.levels[e.level].details:e.type===tt&&null!==e.id?n=this.hls.audioTracks[e.id].details:e.type===rt&&null!==e.id&&(n=this.hls.subtitleTracks[e.id].details),n)){var u=n.partTarget,d=n.targetduration;if(u&&d){var c=1e3*Math.max(3*u,.8*d);r=l({},r,{maxTimeToFirstByteMs:Math.min(c,r.maxTimeToFirstByteMs),maxLoadTimeMs:Math.min(c,r.maxTimeToFirstByteMs)})}}var f=r.errorRetry||r.timeoutRetry||{},h={loadPolicy:r,timeout:r.maxLoadTimeMs,maxRetry:f.maxNumRetry||0,retryDelay:f.retryDelayMs||0,maxRetryDelay:f.maxRetryDelayMs||0},g={onSuccess:function(e,t,r,n){var a=i.getInternalLoader(r);i.resetInternalLoader(r.type);var s=e.data;0===s.indexOf("#EXTM3U")?(t.parsing.start=performance.now(),We.isMediaPlaylist(s)?i.handleTrackOrLevelPlaylist(e,t,r,n||null,a):i.handleMasterPlaylist(e,t,r,n)):i.handleManifestParsingError(e,r,new Error("no EXTM3U delimiter"),n||null,t)},onError:function(e,t,r,n){i.handleNetworkError(t,r,!1,e,n)},onTimeout:function(e,t,r){i.handleNetworkError(t,r,!0,void 0,e)}};s.load(e,h,g)},r.handleMasterPlaylist=function(e,t,r,n){var i=this.hls,a=e.data,s=ot(e,r),o=We.parseMasterPlaylist(a,s);if(o.playlistParsingError)this.handleManifestParsingError(e,r,o.playlistParsingError,n,t);else{var l=o.contentSteering,u=o.levels,d=o.sessionData,c=o.sessionKeys,f=o.startTimeOffset,h=o.variableList;this.variableList=h;var g=We.parseMasterPlaylistMedia(a,s,o),v=g.AUDIO,p=void 0===v?[]:v,m=g.SUBTITLES,y=g["CLOSED-CAPTIONS"];p.length&&(p.some((function(e){return!e.url}))||!u[0].audioCodec||u[0].attrs.AUDIO||(R.log("[playlist-loader]: audio codec signaled in quality level, but no embedded audio track signaled, create one"),p.unshift({type:"main",name:"main",groupId:"main",default:!1,autoselect:!1,forced:!1,id:-1,attrs:new C({}),bitrate:0,url:""}))),i.trigger(E.MANIFEST_LOADED,{levels:u,audioTracks:p,subtitles:m,captions:y,contentSteering:l,url:s,stats:t,networkDetails:n,sessionData:d,sessionKeys:c,startTimeOffset:f,variableList:h})}},r.handleTrackOrLevelPlaylist=function(e,t,r,n,i){var a=this.hls,s=r.id,o=r.level,l=r.type,u=ot(e,r),d=m(o)?o:m(s)?s:0,c=st(r),f=We.parseLevelPlaylist(e.data,u,d,c,0,this.variableList);if(l===$e){var h={attrs:new C({}),bitrate:0,details:f,name:"",url:u};a.trigger(E.MANIFEST_LOADED,{levels:[h],audioTracks:[],url:u,stats:t,networkDetails:n,sessionData:null,sessionKeys:null,contentSteering:null,startTimeOffset:null,variableList:null})}t.parsing.end=performance.now(),r.levelDetails=f,this.handlePlaylistLoaded(f,e,t,r,n,i)},r.handleManifestParsingError=function(e,t,r,n,i){this.hls.trigger(E.ERROR,{type:S.NETWORK_ERROR,details:_.MANIFEST_PARSING_ERROR,fatal:t.type===$e,url:e.url,err:r,error:r,reason:r.message,response:e,context:t,networkDetails:n,stats:i})},r.handleNetworkError=function(e,r,n,i,a){void 0===n&&(n=!1);var s="A network "+(n?"timeout":"error"+(i?" (status "+i.code+")":""))+" occurred while loading "+e.type;e.type===et?s+=": "+e.level+" id: "+e.id:e.type!==tt&&e.type!==rt||(s+=" id: "+e.id+' group-id: "'+e.groupId+'"');var o=new Error(s);R.warn("[playlist-loader]: "+s);var l=_.UNKNOWN,u=!1,d=this.getInternalLoader(e);switch(e.type){case $e:l=n?_.MANIFEST_LOAD_TIMEOUT:_.MANIFEST_LOAD_ERROR,u=!0;break;case et:l=n?_.LEVEL_LOAD_TIMEOUT:_.LEVEL_LOAD_ERROR,u=!1;break;case tt:l=n?_.AUDIO_TRACK_LOAD_TIMEOUT:_.AUDIO_TRACK_LOAD_ERROR,u=!1;break;case rt:l=n?_.SUBTITLE_TRACK_LOAD_TIMEOUT:_.SUBTITLE_LOAD_ERROR,u=!1}d&&this.resetInternalLoader(e.type);var c={type:S.NETWORK_ERROR,details:l,fatal:u,url:e.url,loader:d,context:e,error:o,networkDetails:r,stats:a};if(i){var f=(null==r?void 0:r.url)||e.url;c.response=t({url:f,data:void 0},i)}this.hls.trigger(E.ERROR,c)},r.handlePlaylistLoaded=function(e,t,r,n,i,a){var s=this.hls,o=n.type,l=n.level,u=n.id,d=n.groupId,c=n.deliveryDirectives,f=ot(t,n),h=st(n),g="number"==typeof n.level&&h===nt?l:void 0;if(e.fragments.length){e.targetduration||(e.playlistParsingError=new Error("Missing Target Duration"));var v=e.playlistParsingError;if(v)s.trigger(E.ERROR,{type:S.NETWORK_ERROR,details:_.LEVEL_PARSING_ERROR,fatal:!1,url:f,error:v,reason:v.message,response:t,context:n,level:g,parent:h,networkDetails:i,stats:r});else switch(e.live&&a&&(a.getCacheAge&&(e.ageHeader=a.getCacheAge()||0),a.getCacheAge&&!isNaN(e.ageHeader)||(e.ageHeader=0)),o){case $e:case et:s.trigger(E.LEVEL_LOADED,{details:e,level:g||0,id:u||0,stats:r,networkDetails:i,deliveryDirectives:c});break;case tt:s.trigger(E.AUDIO_TRACK_LOADED,{details:e,id:u||0,groupId:d||"",stats:r,networkDetails:i,deliveryDirectives:c});break;case rt:s.trigger(E.SUBTITLE_TRACK_LOADED,{details:e,id:u||0,groupId:d||"",stats:r,networkDetails:i,deliveryDirectives:c})}}else{var p=new Error("No Segments found in Playlist");s.trigger(E.ERROR,{type:S.NETWORK_ERROR,details:_.LEVEL_EMPTY_ERROR,fatal:!1,url:f,error:p,reason:p.message,response:t,context:n,level:g,parent:h,networkDetails:i,stats:r})}},e}();function ut(e,t){var r;try{r=new Event("addtrack")}catch(e){(r=document.createEvent("Event")).initEvent("addtrack",!1,!1)}r.track=e,t.dispatchEvent(r)}var dt="org.id3",ct="https://aomedia.org/emsg/ID3";function ft(){if("undefined"!=typeof self)return self.VTTCue||self.TextTrackCue}function ht(e,r,n,i,a){var s=new e(r,n,"");try{s.value=i,a&&(s.type=a)}catch(o){s=new e(r,n,JSON.stringify(a?t({type:a},i):i))}return s}var gt=function(){var e=ft();try{e&&new e(0,Number.POSITIVE_INFINITY,"")}catch(e){return Number.MAX_VALUE}return Number.POSITIVE_INFINITY}();function vt(e,t){return e.getTime()/1e3-t}var pt=function(){function e(e){this.hls=void 0,this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=e,this._registerListeners()}var t=e.prototype;return t.destroy=function(){this._unregisterListeners(),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={},this.hls=null},t._registerListeners=function(){var e=this.hls;e.on(E.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(E.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.on(E.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(E.LEVEL_UPDATED,this.onLevelUpdated,this)},t._unregisterListeners=function(){var e=this.hls;e.off(E.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(E.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.FRAG_PARSING_METADATA,this.onFragParsingMetadata,this),e.off(E.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(E.LEVEL_UPDATED,this.onLevelUpdated,this)},t.onMediaAttached=function(e,t){this.media=t.media},t.onMediaDetaching=function(){this.id3Track&&(function(e){var t=e.mode;if("disabled"===t&&(e.mode="hidden"),e.cues)for(var r=e.cues.length;r--;)e.removeCue(e.cues[r]);"disabled"===t&&(e.mode=t)}(this.id3Track),this.id3Track=null,this.media=null,this.dateRangeCuesAppended={})},t.onManifestLoading=function(){this.dateRangeCuesAppended={}},t.createTrack=function(e){var t=this.getID3Track(e.textTracks);return t.mode="hidden",t},t.getID3Track=function(e){if(this.media){for(var t=0;t<e.length;t++){var r=e[t];if("metadata"===r.kind&&"id3"===r.label)return ut(r,this.media),r}return this.media.addTextTrack("metadata","id3")}},t.onFragParsingMetadata=function(e,t){if(this.media){var r=this.hls.config,n=r.enableEmsgMetadataCues,i=r.enableID3MetadataCues;if(n||i){var a=t.samples;this.id3Track||(this.id3Track=this.createTrack(this.media));var s=ft();if(s)for(var o=0;o<a.length;o++){var l=a[o].type;if((l!==ct||n)&&i){var u=Z(a[o].data);if(u){var d=a[o].pts,c=d+a[o].duration;c>gt&&(c=gt),c-d<=0&&(c=d+.25);for(var f=0;f<u.length;f++){var h=u[f];if(!J(h)){this.updateId3CueEnds(d,l);var g=ht(s,d,c,h,l);g&&this.id3Track.addCue(g)}}}}}}}},t.updateId3CueEnds=function(e,t){var r,n=null==(r=this.id3Track)?void 0:r.cues;if(n)for(var i=n.length;i--;){var a=n[i];a.type===t&&a.startTime<e&&a.endTime===gt&&(a.endTime=e)}},t.onBufferFlushing=function(e,t){var r=t.startOffset,n=t.endOffset,i=t.type,a=this.id3Track,s=this.hls;if(s){var o=s.config,l=o.enableEmsgMetadataCues,u=o.enableID3MetadataCues;a&&(l||u)&&function(e,t,r,n){var i=e.mode;if("disabled"===i&&(e.mode="hidden"),e.cues&&e.cues.length>0)for(var a=function(e,t,r){var n=[],i=function(e,t){if(t<e[0].startTime)return 0;var r=e.length-1;if(t>e[r].endTime)return-1;for(var n=0,i=r;n<=i;){var a=Math.floor((i+n)/2);if(t<e[a].startTime)i=a-1;else{if(!(t>e[a].startTime&&n<r))return a;n=a+1}}return e[n].startTime-t<t-e[i].startTime?n:i}(e,t);if(i>-1)for(var a=i,s=e.length;a<s;a++){var o=e[a];if(o.startTime>=t&&o.endTime<=r)n.push(o);else if(o.startTime>r)return n}return n}(e.cues,t,r),s=0;s<a.length;s++)n&&!n(a[s])||e.removeCue(a[s]);"disabled"===i&&(e.mode=i)}(a,r,n,"audio"===i?function(e){return e.type===dt&&u}:"video"===i?function(e){return e.type===ct&&l}:function(e){return e.type===dt&&u||e.type===ct&&l})}},t.onLevelUpdated=function(e,t){var r=this,n=t.details;if(this.media&&n.hasProgramDateTime&&this.hls.config.enableDateRangeMetadataCues){var i=this.dateRangeCuesAppended,a=this.id3Track,s=n.dateRanges,o=Object.keys(s);if(a)for(var l=Object.keys(i).filter((function(e){return!o.includes(e)})),u=function(){var e=l[d];Object.keys(i[e].cues).forEach((function(t){a.removeCue(i[e].cues[t])})),delete i[e]},d=l.length;d--;)u();var c=n.fragments[n.fragments.length-1];if(0!==o.length&&m(null==c?void 0:c.programDateTime)){this.id3Track||(this.id3Track=this.createTrack(this.media));for(var f=c.programDateTime/1e3-c.start,h=ft(),g=function(){var e=o[v],t=s[e],n=vt(t.startDate,f),a=i[e],l=(null==a?void 0:a.cues)||{},u=(null==a?void 0:a.durationKnown)||!1,d=gt,c=t.endDate;if(c)d=vt(c,f),u=!0;else if(t.endOnNext&&!u){var g=o.reduce((function(e,r){if(r!==t.id){var n=s[r];if(n.class===t.class&&n.startDate>t.startDate&&(!e||t.startDate<e.startDate))return n}return e}),null);g&&(d=vt(g.startDate,f),u=!0)}for(var p,m,y=Object.keys(t.attr),b=0;b<y.length;b++){var E=y[b];if("ID"!==(m=E)&&"CLASS"!==m&&"START-DATE"!==m&&"DURATION"!==m&&"END-DATE"!==m&&"END-ON-NEXT"!==m){var S=l[E];if(S)u&&!a.durationKnown&&(S.endTime=d);else if(h){var _=t.attr[E];D(E)&&(p=_,_=Uint8Array.from(p.replace(/^0x/,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" ")).buffer);var T=ht(h,n,d,{key:E,data:_},"com.apple.quicktime.HLS");T&&(T.id=e,r.id3Track.addCue(T),l[E]=T)}}}i[e]={cues:l,dateRange:t,durationKnown:u}},v=0;v<o.length;v++)g()}}},e}(),mt=function(){function e(e){var t=this;this.hls=void 0,this.config=void 0,this.media=null,this.levelDetails=null,this.currentTime=0,this.stallCount=0,this._latency=null,this.timeupdateHandler=function(){return t.timeupdate()},this.hls=e,this.config=e.config,this.registerListeners()}var t=e.prototype;return t.destroy=function(){this.unregisterListeners(),this.onMediaDetaching(),this.levelDetails=null,this.hls=this.timeupdateHandler=null},t.registerListeners=function(){this.hls.on(E.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.on(E.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.on(E.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.on(E.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.on(E.ERROR,this.onError,this)},t.unregisterListeners=function(){this.hls.off(E.MEDIA_ATTACHED,this.onMediaAttached,this),this.hls.off(E.MEDIA_DETACHING,this.onMediaDetaching,this),this.hls.off(E.MANIFEST_LOADING,this.onManifestLoading,this),this.hls.off(E.LEVEL_UPDATED,this.onLevelUpdated,this),this.hls.off(E.ERROR,this.onError,this)},t.onMediaAttached=function(e,t){this.media=t.media,this.media.addEventListener("timeupdate",this.timeupdateHandler)},t.onMediaDetaching=function(){this.media&&(this.media.removeEventListener("timeupdate",this.timeupdateHandler),this.media=null)},t.onManifestLoading=function(){this.levelDetails=null,this._latency=null,this.stallCount=0},t.onLevelUpdated=function(e,t){var r=t.details;this.levelDetails=r,r.advanced&&this.timeupdate(),!r.live&&this.media&&this.media.removeEventListener("timeupdate",this.timeupdateHandler)},t.onError=function(e,t){var r;t.details===_.BUFFER_STALLED_ERROR&&(this.stallCount++,null!=(r=this.levelDetails)&&r.live&&R.warn("[playback-rate-controller]: Stall detected, adjusting target latency"))},t.timeupdate=function(){var e=this.media,t=this.levelDetails;if(e&&t){this.currentTime=e.currentTime;var r=this.computeLatency();if(null!==r){this._latency=r;var n=this.config,i=n.lowLatencyMode,a=n.maxLiveSyncPlaybackRate;if(i&&1!==a&&t.live){var s=this.targetLatency;if(null!==s){var o=r-s;if(o<Math.min(this.maxLatency,s+t.targetduration)&&o>.05&&this.forwardBufferLength>1){var l=Math.min(2,Math.max(1,a)),u=Math.round(2/(1+Math.exp(-.75*o-this.edgeStalled))*20)/20;e.playbackRate=Math.min(l,Math.max(1,u))}else 1!==e.playbackRate&&0!==e.playbackRate&&(e.playbackRate=1)}}}}},t.estimateLiveEdge=function(){var e=this.levelDetails;return null===e?null:e.edge+e.age},t.computeLatency=function(){var e=this.estimateLiveEdge();return null===e?null:e-this.currentTime},i(e,[{key:"latency",get:function(){return this._latency||0}},{key:"maxLatency",get:function(){var e=this.config,t=this.levelDetails;return void 0!==e.liveMaxLatencyDuration?e.liveMaxLatencyDuration:t?e.liveMaxLatencyDurationCount*t.targetduration:0}},{key:"targetLatency",get:function(){var e=this.levelDetails;if(null===e)return null;var t=e.holdBack,r=e.partHoldBack,n=e.targetduration,i=this.config,a=i.liveSyncDuration,s=i.liveSyncDurationCount,o=i.lowLatencyMode,l=this.hls.userConfig,u=o&&r||t;(l.liveSyncDuration||l.liveSyncDurationCount||0===u)&&(u=void 0!==a?a:s*n);var d=n;return u+Math.min(1*this.stallCount,d)}},{key:"liveSyncPosition",get:function(){var e=this.estimateLiveEdge(),t=this.targetLatency,r=this.levelDetails;if(null===e||null===t||null===r)return null;var n=r.edge,i=e-t-this.edgeStalled,a=n-r.totalduration,s=n-(this.config.lowLatencyMode&&r.partTarget||r.targetduration);return Math.min(Math.max(a,i),s)}},{key:"drift",get:function(){var e=this.levelDetails;return null===e?1:e.drift}},{key:"edgeStalled",get:function(){var e=this.levelDetails;if(null===e)return 0;var t=3*(this.config.lowLatencyMode&&e.partTarget||e.targetduration);return Math.max(e.age-t,0)}},{key:"forwardBufferLength",get:function(){var e=this.media,t=this.levelDetails;if(!e||!t)return 0;var r=e.buffered.length;return(r?e.buffered.end(r-1):t.edge)-this.currentTime}}]),e}(),yt=["NONE","TYPE-0","TYPE-1",null],bt=["SDR","PQ","HLG"];function Et(e){var t=e.canSkipUntil,r=e.canSkipDateRanges,n=e.age;return t&&n<t/2?r?"v2":"YES":""}var St=function(){function e(e,t,r){this.msn=void 0,this.part=void 0,this.skip=void 0,this.msn=e,this.part=t,this.skip=r}return e.prototype.addDirectives=function(e){var t=new self.URL(e);return void 0!==this.msn&&t.searchParams.set("_HLS_msn",this.msn.toString()),void 0!==this.part&&t.searchParams.set("_HLS_part",this.part.toString()),this.skip&&t.searchParams.set("_HLS_skip",this.skip),t.href},e}(),_t=function(){function e(e){this._attrs=void 0,this.audioCodec=void 0,this.bitrate=void 0,this.codecSet=void 0,this.url=void 0,this.frameRate=void 0,this.height=void 0,this.id=void 0,this.name=void 0,this.videoCodec=void 0,this.width=void 0,this.details=void 0,this.fragmentError=0,this.loadError=0,this.loaded=void 0,this.realBitrate=0,this.supportedPromise=void 0,this.supportedResult=void 0,this._avgBitrate=0,this._audioGroups=void 0,this._subtitleGroups=void 0,this._urlId=0,this.url=[e.url],this._attrs=[e.attrs],this.bitrate=e.bitrate,e.details&&(this.details=e.details),this.id=e.id||0,this.name=e.name,this.width=e.width||0,this.height=e.height||0,this.frameRate=e.attrs.optionalFloat("FRAME-RATE",0),this._avgBitrate=e.attrs.decimalInteger("AVERAGE-BANDWIDTH"),this.audioCodec=e.audioCodec,this.videoCodec=e.videoCodec,this.codecSet=[e.videoCodec,e.audioCodec].filter((function(e){return!!e})).map((function(e){return e.substring(0,4)})).join(","),this.addGroupId("audio",e.attrs.AUDIO),this.addGroupId("text",e.attrs.SUBTITLES)}var t=e.prototype;return t.hasAudioGroup=function(e){return Tt(this._audioGroups,e)},t.hasSubtitleGroup=function(e){return Tt(this._subtitleGroups,e)},t.addGroupId=function(e,t){if(t)if("audio"===e){var r=this._audioGroups;r||(r=this._audioGroups=[]),-1===r.indexOf(t)&&r.push(t)}else if("text"===e){var n=this._subtitleGroups;n||(n=this._subtitleGroups=[]),-1===n.indexOf(t)&&n.push(t)}},t.addFallback=function(){},i(e,[{key:"maxBitrate",get:function(){return Math.max(this.realBitrate,this.bitrate)}},{key:"averageBitrate",get:function(){return this._avgBitrate||this.realBitrate||this.bitrate}},{key:"attrs",get:function(){return this._attrs[0]}},{key:"codecs",get:function(){return this.attrs.CODECS||""}},{key:"pathwayId",get:function(){return this.attrs["PATHWAY-ID"]||"."}},{key:"videoRange",get:function(){return this.attrs["VIDEO-RANGE"]||"SDR"}},{key:"score",get:function(){return this.attrs.optionalFloat("SCORE",0)}},{key:"uri",get:function(){return this.url[0]||""}},{key:"audioGroups",get:function(){return this._audioGroups}},{key:"subtitleGroups",get:function(){return this._subtitleGroups}},{key:"urlId",get:function(){return 0},set:function(e){}},{key:"audioGroupIds",get:function(){return this.audioGroups?[this.audioGroupId]:void 0}},{key:"textGroupIds",get:function(){return this.subtitleGroups?[this.textGroupId]:void 0}},{key:"audioGroupId",get:function(){var e;return null==(e=this.audioGroups)?void 0:e[0]}},{key:"textGroupId",get:function(){var e;return null==(e=this.subtitleGroups)?void 0:e[0]}}]),e}();function Tt(e,t){return!(!t||!e)&&-1!==e.indexOf(t)}function Lt(e,t){var r=t.startPTS;if(m(r)){var n,i=0;t.sn>e.sn?(i=r-e.start,n=e):(i=e.start-r,n=t),n.duration!==i&&(n.duration=i)}else t.sn>e.sn?e.cc===t.cc&&e.minEndPTS?t.start=e.start+(e.minEndPTS-e.start):t.start=e.start+e.duration:t.start=Math.max(e.start-t.duration,0)}function Pt(e,t,r,n,i,a){n-r<=0&&(R.warn("Fragment should have a positive duration",t),n=r+t.duration,a=i+t.duration);var s=r,o=n,l=t.startPTS,u=t.endPTS;if(m(l)){var d=Math.abs(l-r);m(t.deltaPTS)?t.deltaPTS=Math.max(d,t.deltaPTS):t.deltaPTS=d,s=Math.max(r,l),r=Math.min(r,l),i=Math.min(i,t.startDTS),o=Math.min(n,u),n=Math.max(n,u),a=Math.max(a,t.endDTS)}var c=r-t.start;0!==t.start&&(t.start=r),t.duration=n-t.start,t.startPTS=r,t.maxStartPTS=s,t.startDTS=i,t.endPTS=n,t.minEndPTS=o,t.endDTS=a;var f,h=t.sn;if(!e||h<e.startSN||h>e.endSN)return 0;var g=h-e.startSN,v=e.fragments;for(v[g]=t,f=g;f>0;f--)Lt(v[f],v[f-1]);for(f=g;f<v.length-1;f++)Lt(v[f],v[f+1]);return e.fragmentHint&&Lt(v[v.length-1],e.fragmentHint),e.PTSKnown=e.alignedSliding=!0,c}function wt(e,t){for(var r=null,n=e.fragments,i=n.length-1;i>=0;i--){var a=n[i].initSegment;if(a){r=a;break}}e.fragmentHint&&delete e.fragmentHint.endPTS;var s,o,u,d,c,f=0;if(function(e,t,r){for(var n=t.skippedSegments,i=Math.max(e.startSN,t.startSN)-t.startSN,a=(e.fragmentHint?1:0)+(n?t.endSN:Math.min(e.endSN,t.endSN))-t.startSN,s=t.startSN-e.startSN,o=t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments,l=e.fragmentHint?e.fragments.concat(e.fragmentHint):e.fragments,u=i;u<=a;u++){var d=l[s+u],c=o[u];n&&!c&&u<n&&(c=t.fragments[u]=d),d&&c&&r(d,c)}}(e,t,(function(e,n){e.relurl&&(f=e.cc-n.cc),m(e.startPTS)&&m(e.endPTS)&&(n.start=n.startPTS=e.startPTS,n.startDTS=e.startDTS,n.maxStartPTS=e.maxStartPTS,n.endPTS=e.endPTS,n.endDTS=e.endDTS,n.minEndPTS=e.minEndPTS,n.duration=e.endPTS-e.startPTS,n.duration&&(s=n),t.PTSKnown=t.alignedSliding=!0),n.elementaryStreams=e.elementaryStreams,n.loader=e.loader,n.stats=e.stats,e.initSegment&&(n.initSegment=e.initSegment,r=e.initSegment)})),r&&(t.fragmentHint?t.fragments.concat(t.fragmentHint):t.fragments).forEach((function(e){var t;!e||e.initSegment&&e.initSegment.relurl!==(null==(t=r)?void 0:t.relurl)||(e.initSegment=r)})),t.skippedSegments)if(t.deltaUpdateFailed=t.fragments.some((function(e){return!e})),t.deltaUpdateFailed){R.warn("[level-helper] Previous playlist missing segments skipped in delta playlist");for(var h=t.skippedSegments;h--;)t.fragments.shift();t.startSN=t.fragments[0].sn,t.startCC=t.fragments[0].cc}else t.canSkipDateRanges&&(t.dateRanges=(o=e.dateRanges,u=t.dateRanges,d=t.recentlyRemovedDateranges,c=l({},o),d&&d.forEach((function(e){delete c[e]})),Object.keys(u).forEach((function(e){var t=new I(u[e].attr,c[e]);t.isValid?c[e]=t:R.warn('Ignoring invalid Playlist Delta Update DATERANGE tag: "'+JSON.stringify(u[e].attr)+'"')})),c));var g=t.fragments;if(f){R.warn("discontinuity sliding from playlist, take drift into account");for(var v=0;v<g.length;v++)g[v].cc+=f}t.skippedSegments&&(t.startCC=t.fragments[0].cc),function(e,t,r){if(e&&t)for(var n=0,i=0,a=e.length;i<=a;i++){var s=e[i],o=t[i+n];s&&o&&s.index===o.index&&s.fragment.sn===o.fragment.sn?r(s,o):n--}}(e.partList,t.partList,(function(e,t){t.elementaryStreams=e.elementaryStreams,t.stats=e.stats})),s?Pt(t,s,s.startPTS,s.endPTS,s.startDTS,s.endDTS):Rt(e,t),g.length&&(t.totalduration=t.edge-g[0].start),t.driftStartTime=e.driftStartTime,t.driftStart=e.driftStart;var p=t.advancedDateTime;if(t.advanced&&p){var y=t.edge;t.driftStart||(t.driftStartTime=p,t.driftStart=y),t.driftEndTime=p,t.driftEnd=y}else t.driftEndTime=e.driftEndTime,t.driftEnd=e.driftEnd,t.advancedDateTime=e.advancedDateTime}function Rt(e,t){var r=t.startSN+t.skippedSegments-e.startSN,n=e.fragments;r<0||r>=n.length||function(e,t){if(t){for(var r=e.fragments,n=e.skippedSegments;n<r.length;n++)r[n].start+=t;e.fragmentHint&&(e.fragmentHint.start+=t)}}(t,n[r].start)}function At(e,t,r){var n;return null!=e&&e.details?kt(null==(n=e.details)?void 0:n.partList,t,r):null}function kt(e,t,r){if(e)for(var n=e.length;n--;){var i=e[n];if(i.index===r&&i.fragment.sn===t)return i}return null}function Ct(e){e.forEach((function(e,t){var r=e.details;null!=r&&r.fragments&&r.fragments.forEach((function(e){e.level=t}))}))}function Dt(e){switch(e.details){case _.FRAG_LOAD_TIMEOUT:case _.KEY_LOAD_TIMEOUT:case _.LEVEL_LOAD_TIMEOUT:case _.MANIFEST_LOAD_TIMEOUT:return!0}return!1}function It(e,t){var r=Dt(t);return e.default[(r?"timeout":"error")+"Retry"]}function xt(e,t){var r="linear"===e.backoff?1:Math.pow(2,t);return Math.min(r*e.retryDelayMs,e.maxRetryDelayMs)}function Ot(e){return t(t({},e),{errorRetry:null,timeoutRetry:null})}function Mt(e,t,r,n){if(!e)return!1;var i=null==n?void 0:n.code,a=t<e.maxNumRetry&&(function(e){return 0===e&&!1===navigator.onLine||!!e&&(e<400||e>499)}(i)||!!r);return e.shouldRetry?e.shouldRetry(e,t,r,n,a):a}var Ft=function(e,t){for(var r=0,n=e.length-1,i=null,a=null;r<=n;){var s=t(a=e[i=(r+n)/2|0]);if(s>0)r=i+1;else{if(!(s<0))return a;n=i-1}}return null};function Nt(e,t,r,n,i){void 0===r&&(r=0),void 0===n&&(n=0),void 0===i&&(i=.005);var a=null;if(e){a=t[e.sn-t[0].sn+1]||null;var s=e.endDTS-r;s>0&&s<15e-7&&(r+=15e-7)}else 0===r&&0===t[0].start&&(a=t[0]);if(a&&((!e||e.level===a.level)&&0===Bt(r,n,a)||function(e,t,r){if(t&&0===t.start&&t.level<e.level&&(t.endPTS||0)>0){var n=t.tagList.reduce((function(e,t){return"INF"===t[0]&&(e+=parseFloat(t[1])),e}),r);return e.start<=n}return!1}(a,e,Math.min(i,n))))return a;var o=Ft(t,Bt.bind(null,r,n));return!o||o===e&&a?a:o}function Bt(e,t,r){if(void 0===e&&(e=0),void 0===t&&(t=0),r.start<=e&&r.start+r.duration>e)return 0;var n=Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return r.start+r.duration-n<=e?1:r.start-n>e&&r.start?-1:0}function Ut(e,t,r){var n=1e3*Math.min(t,r.duration+(r.deltaPTS?r.deltaPTS:0));return(r.endProgramDateTime||0)-n>e}var Gt=function(){function e(e){this.hls=void 0,this.playlistError=0,this.penalizedRenditions={},this.log=void 0,this.warn=void 0,this.error=void 0,this.hls=e,this.log=R.log.bind(R,"[info]:"),this.warn=R.warn.bind(R,"[warning]:"),this.error=R.error.bind(R,"[error]:"),this.registerListeners()}var t=e.prototype;return t.registerListeners=function(){var e=this.hls;e.on(E.ERROR,this.onError,this),e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.LEVEL_UPDATED,this.onLevelUpdated,this)},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(E.ERROR,this.onError,this),e.off(E.ERROR,this.onErrorOut,this),e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.LEVEL_UPDATED,this.onLevelUpdated,this))},t.destroy=function(){this.unregisterListeners(),this.hls=null,this.penalizedRenditions={}},t.startLoad=function(e){},t.stopLoad=function(){this.playlistError=0},t.getVariantLevelIndex=function(e){return(null==e?void 0:e.type)===nt?e.level:this.hls.loadLevel},t.onManifestLoading=function(){this.playlistError=0,this.penalizedRenditions={}},t.onLevelUpdated=function(){this.playlistError=0},t.onError=function(e,t){var r,n;if(!t.fatal){var i=this.hls,a=t.context;switch(t.details){case _.FRAG_LOAD_ERROR:case _.FRAG_LOAD_TIMEOUT:case _.KEY_LOAD_ERROR:case _.KEY_LOAD_TIMEOUT:return void(t.errorAction=this.getFragRetryOrSwitchAction(t));case _.FRAG_PARSING_ERROR:if(null!=(r=t.frag)&&r.gap)return void(t.errorAction={action:0,flags:0});case _.FRAG_GAP:case _.FRAG_DECRYPT_ERROR:return t.errorAction=this.getFragRetryOrSwitchAction(t),void(t.errorAction.action=2);case _.LEVEL_EMPTY_ERROR:case _.LEVEL_PARSING_ERROR:var s,o,l=t.parent===nt?t.level:i.loadLevel;return void(t.details===_.LEVEL_EMPTY_ERROR&&null!=(s=t.context)&&null!=(o=s.levelDetails)&&o.live?t.errorAction=this.getPlaylistRetryOrSwitchAction(t,l):(t.levelRetry=!1,t.errorAction=this.getLevelSwitchAction(t,l)));case _.LEVEL_LOAD_ERROR:case _.LEVEL_LOAD_TIMEOUT:return void("number"==typeof(null==a?void 0:a.level)&&(t.errorAction=this.getPlaylistRetryOrSwitchAction(t,a.level)));case _.AUDIO_TRACK_LOAD_ERROR:case _.AUDIO_TRACK_LOAD_TIMEOUT:case _.SUBTITLE_LOAD_ERROR:case _.SUBTITLE_TRACK_LOAD_TIMEOUT:if(a){var u=i.levels[i.loadLevel];if(u&&(a.type===tt&&u.hasAudioGroup(a.groupId)||a.type===rt&&u.hasSubtitleGroup(a.groupId)))return t.errorAction=this.getPlaylistRetryOrSwitchAction(t,i.loadLevel),t.errorAction.action=2,void(t.errorAction.flags=1)}return;case _.KEY_SYSTEM_STATUS_OUTPUT_RESTRICTED:var d=i.levels[i.loadLevel],c=null==d?void 0:d.attrs["HDCP-LEVEL"];return void(c?t.errorAction={action:2,flags:2,hdcpLevel:c}:this.keySystemError(t));case _.BUFFER_ADD_CODEC_ERROR:case _.REMUX_ALLOC_ERROR:case _.BUFFER_APPEND_ERROR:return void(t.errorAction=this.getLevelSwitchAction(t,null!=(n=t.level)?n:i.loadLevel));case _.INTERNAL_EXCEPTION:case _.BUFFER_APPENDING_ERROR:case _.BUFFER_FULL_ERROR:case _.LEVEL_SWITCH_ERROR:case _.BUFFER_STALLED_ERROR:case _.BUFFER_SEEK_OVER_HOLE:case _.BUFFER_NUDGE_ON_STALL:return void(t.errorAction={action:0,flags:0})}t.type===S.KEY_SYSTEM_ERROR&&this.keySystemError(t)}},t.keySystemError=function(e){var t=this.getVariantLevelIndex(e.frag);e.levelRetry=!1,e.errorAction=this.getLevelSwitchAction(e,t)},t.getPlaylistRetryOrSwitchAction=function(e,t){var r=It(this.hls.config.playlistLoadPolicy,e),n=this.playlistError++;if(Mt(r,n,Dt(e),e.response))return{action:5,flags:0,retryConfig:r,retryCount:n};var i=this.getLevelSwitchAction(e,t);return r&&(i.retryConfig=r,i.retryCount=n),i},t.getFragRetryOrSwitchAction=function(e){var t=this.hls,r=this.getVariantLevelIndex(e.frag),n=t.levels[r],i=t.config,a=i.fragLoadPolicy,s=i.keyLoadPolicy,o=It(e.details.startsWith("key")?s:a,e),l=t.levels.reduce((function(e,t){return e+t.fragmentError}),0);if(n&&(e.details!==_.FRAG_GAP&&n.fragmentError++,Mt(o,l,Dt(e),e.response)))return{action:5,flags:0,retryConfig:o,retryCount:l};var u=this.getLevelSwitchAction(e,r);return o&&(u.retryConfig=o,u.retryCount=l),u},t.getLevelSwitchAction=function(e,t){var r=this.hls;null==t&&(t=r.loadLevel);var n=this.hls.levels[t];if(n){var i,a,s=e.details;n.loadError++,s===_.BUFFER_APPEND_ERROR&&n.fragmentError++;var o=-1,l=r.levels,u=r.loadLevel,d=r.minAutoLevel,c=r.maxAutoLevel;r.autoLevelEnabled||(r.loadLevel=-1);for(var f,h=null==(i=e.frag)?void 0:i.type,g=(h===it&&s===_.FRAG_PARSING_ERROR||"audio"===e.sourceBufferName&&(s===_.BUFFER_ADD_CODEC_ERROR||s===_.BUFFER_APPEND_ERROR))&&l.some((function(e){var t=e.audioCodec;return n.audioCodec!==t})),v="video"===e.sourceBufferName&&(s===_.BUFFER_ADD_CODEC_ERROR||s===_.BUFFER_APPEND_ERROR)&&l.some((function(e){var t=e.codecSet,r=e.audioCodec;return n.codecSet!==t&&n.audioCodec===r})),p=null!=(a=e.context)?a:{},m=p.type,y=p.groupId,b=function(){var t=(E+u)%l.length;if(t!==u&&t>=d&&t<=c&&0===l[t].loadError){var r,i,a=l[t];if(s===_.FRAG_GAP&&h===nt&&e.frag){var f=l[t].details;if(f){var p=Nt(e.frag,f.fragments,e.frag.start);if(null!=p&&p.gap)return 0}}else{if(m===tt&&a.hasAudioGroup(y)||m===rt&&a.hasSubtitleGroup(y))return 0;if(h===it&&null!=(r=n.audioGroups)&&r.some((function(e){return a.hasAudioGroup(e)}))||h===at&&null!=(i=n.subtitleGroups)&&i.some((function(e){return a.hasSubtitleGroup(e)}))||g&&n.audioCodec===a.audioCodec||!g&&n.audioCodec!==a.audioCodec||v&&n.codecSet===a.codecSet)return 0}return o=t,1}},E=l.length;E--&&(0===(f=b())||1!==f););if(o>-1&&r.loadLevel!==o)return e.levelRetry=!0,this.playlistError=0,{action:2,flags:0,nextAutoLevel:o}}return{action:2,flags:1}},t.onErrorOut=function(e,t){var r;switch(null==(r=t.errorAction)?void 0:r.action){case 0:break;case 2:this.sendAlternateToPenaltyBox(t),t.errorAction.resolved||t.details===_.FRAG_GAP?/MediaSource readyState: ended/.test(t.error.message)&&(this.warn('MediaSource ended after "'+t.sourceBufferName+'" sourceBuffer append error. Attempting to recover from media error.'),this.hls.recoverMediaError()):t.fatal=!0}t.fatal&&this.hls.stopLoad()},t.sendAlternateToPenaltyBox=function(e){var t=this.hls,r=e.errorAction;if(r){var n=r.flags,i=r.hdcpLevel,a=r.nextAutoLevel;switch(n){case 0:this.switchLevel(e,a);break;case 2:i&&(t.maxHdcpLevel=yt[yt.indexOf(i)-1],r.resolved=!0),this.warn('Restricting playback to HDCP-LEVEL of "'+t.maxHdcpLevel+'" or lower')}r.resolved||this.switchLevel(e,a)}},t.switchLevel=function(e,t){void 0!==t&&e.errorAction&&(this.warn("switching to level "+t+" after "+e.details),this.hls.nextAutoLevel=t,e.errorAction.resolved=!0,this.hls.nextLoadLevel=this.hls.nextAutoLevel)},e}(),jt=function(){function e(e,t){this.hls=void 0,this.timer=-1,this.requestScheduled=-1,this.canLoad=!1,this.log=void 0,this.warn=void 0,this.log=R.log.bind(R,t+":"),this.warn=R.warn.bind(R,t+":"),this.hls=e}var t=e.prototype;return t.destroy=function(){this.clearTimer(),this.hls=this.log=this.warn=null},t.clearTimer=function(){-1!==this.timer&&(self.clearTimeout(this.timer),this.timer=-1)},t.startLoad=function(){this.canLoad=!0,this.requestScheduled=-1,this.loadPlaylist()},t.stopLoad=function(){this.canLoad=!1,this.clearTimer()},t.switchParams=function(e,t,r){var n=null==t?void 0:t.renditionReports;if(n){for(var i=-1,a=0;a<n.length;a++){var s=n[a],o=void 0;try{o=new self.URL(s.URI,t.url).href}catch(e){R.warn("Could not construct new URL for Rendition Report: "+e),o=s.URI||""}if(o===e){i=a;break}o===e.substring(0,o.length)&&(i=a)}if(-1!==i){var l=n[i],u=parseInt(l["LAST-MSN"])||(null==t?void 0:t.lastPartSn),d=parseInt(l["LAST-PART"])||(null==t?void 0:t.lastPartIndex);if(this.hls.config.lowLatencyMode){var c=Math.min(t.age-t.partTarget,t.targetduration);d>=0&&c>t.partTarget&&(d+=1)}var f=r&&Et(r);return new St(u,d>=0?d:void 0,f)}}},t.loadPlaylist=function(e){-1===this.requestScheduled&&(this.requestScheduled=self.performance.now())},t.shouldLoadPlaylist=function(e){return this.canLoad&&!!e&&!!e.url&&(!e.details||e.details.live)},t.shouldReloadPlaylist=function(e){return-1===this.timer&&-1===this.requestScheduled&&this.shouldLoadPlaylist(e)},t.playlistLoaded=function(e,t,r){var n=this,i=t.details,a=t.stats,s=self.performance.now(),o=a.loading.first?Math.max(0,s-a.loading.first):0;if(i.advancedDateTime=Date.now()-o,i.live||null!=r&&r.live){if(i.reloaded(r),r&&this.log("live playlist "+e+" "+(i.advanced?"REFRESHED "+i.lastPartSn+"-"+i.lastPartIndex:i.updated?"UPDATED":"MISSED")),r&&i.fragments.length>0&&wt(r,i),!this.canLoad||!i.live)return;var l,u=void 0,d=void 0;if(i.canBlockReload&&i.endSN&&i.advanced){var c=this.hls.config.lowLatencyMode,f=i.lastPartSn,h=i.endSN,g=i.lastPartIndex,v=f===h;-1!==g?(u=v?h+1:f,d=v?c?0:g:g+1):u=h+1;var p=i.age,m=p+i.ageHeader,y=Math.min(m-i.partTarget,1.5*i.targetduration);if(y>0){if(r&&y>r.tuneInGoal)this.warn("CDN Tune-in goal increased from: "+r.tuneInGoal+" to: "+y+" with playlist age: "+i.age),y=0;else{var b=Math.floor(y/i.targetduration);u+=b,void 0!==d&&(d+=Math.round(y%i.targetduration/i.partTarget)),this.log("CDN Tune-in age: "+i.ageHeader+"s last advanced "+p.toFixed(2)+"s goal: "+y+" skip sn "+b+" to part "+d)}i.tuneInGoal=y}if(l=this.getDeliveryDirectives(i,t.deliveryDirectives,u,d),c||!v)return void this.loadPlaylist(l)}else(i.canBlockReload||i.canSkipUntil)&&(l=this.getDeliveryDirectives(i,t.deliveryDirectives,u,d));var E=this.hls.mainForwardBufferInfo,S=E?E.end-E.len:0,_=function(e,t){void 0===t&&(t=1/0);var r=1e3*e.targetduration;if(e.updated){var n=e.fragments;if(n.length&&4*r>t){var i=1e3*n[n.length-1].duration;i<r&&(r=i)}}else r/=2;return Math.round(r)}(i,1e3*(i.edge-S));i.updated&&s>this.requestScheduled+_&&(this.requestScheduled=a.loading.start),void 0!==u&&i.canBlockReload?this.requestScheduled=a.loading.first+_-(1e3*i.partTarget||1e3):-1===this.requestScheduled||this.requestScheduled+_<s?this.requestScheduled=s:this.requestScheduled-s<=0&&(this.requestScheduled+=_);var T=this.requestScheduled-s;T=Math.max(0,T),this.log("reload live playlist "+e+" in "+Math.round(T)+" ms"),this.timer=self.setTimeout((function(){return n.loadPlaylist(l)}),T)}else this.clearTimer()},t.getDeliveryDirectives=function(e,t,r,n){var i=Et(e);return null!=t&&t.skip&&e.deltaUpdateFailed&&(r=t.msn,n=t.part,i=""),new St(r,n,i)},t.checkRetry=function(e){var t=this,r=e.details,n=Dt(e),i=e.errorAction,a=i||{},s=a.action,o=a.retryCount,l=void 0===o?0:o,u=a.retryConfig,d=!!i&&!!u&&(5===s||!i.resolved&&2===s);if(d){var c;if(this.requestScheduled=-1,l>=u.maxNumRetry)return!1;if(n&&null!=(c=e.context)&&c.deliveryDirectives)this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" without delivery-directives'),this.loadPlaylist();else{var f=xt(u,l);this.timer=self.setTimeout((function(){return t.loadPlaylist()}),f),this.warn("Retrying playlist loading "+(l+1)+"/"+u.maxNumRetry+' after "'+r+'" in '+f+"ms")}e.levelRetry=!0,i.resolved=!0}return d},e}(),Ht=function(){function e(e,t,r){void 0===t&&(t=0),void 0===r&&(r=0),this.halfLife=void 0,this.alpha_=void 0,this.estimate_=void 0,this.totalWeight_=void 0,this.halfLife=e,this.alpha_=e?Math.exp(Math.log(.5)/e):0,this.estimate_=t,this.totalWeight_=r}var t=e.prototype;return t.sample=function(e,t){var r=Math.pow(this.alpha_,e);this.estimate_=t*(1-r)+r*this.estimate_,this.totalWeight_+=e},t.getTotalWeight=function(){return this.totalWeight_},t.getEstimate=function(){if(this.alpha_){var e=1-Math.pow(this.alpha_,this.totalWeight_);if(e)return this.estimate_/e}return this.estimate_},e}(),qt=function(){function e(e,t,r,n){void 0===n&&(n=100),this.defaultEstimate_=void 0,this.minWeight_=void 0,this.minDelayMs_=void 0,this.slow_=void 0,this.fast_=void 0,this.defaultTTFB_=void 0,this.ttfb_=void 0,this.defaultEstimate_=r,this.minWeight_=.001,this.minDelayMs_=50,this.slow_=new Ht(e),this.fast_=new Ht(t),this.defaultTTFB_=n,this.ttfb_=new Ht(e)}var t=e.prototype;return t.update=function(e,t){var r=this.slow_,n=this.fast_,i=this.ttfb_;r.halfLife!==e&&(this.slow_=new Ht(e,r.getEstimate(),r.getTotalWeight())),n.halfLife!==t&&(this.fast_=new Ht(t,n.getEstimate(),n.getTotalWeight())),i.halfLife!==e&&(this.ttfb_=new Ht(e,i.getEstimate(),i.getTotalWeight()))},t.sample=function(e,t){var r=(e=Math.max(e,this.minDelayMs_))/1e3,n=8*t/r;this.fast_.sample(r,n),this.slow_.sample(r,n)},t.sampleTTFB=function(e){var t=e/1e3,r=Math.sqrt(2)*Math.exp(-Math.pow(t,2)/2);this.ttfb_.sample(r,Math.max(e,5))},t.canEstimate=function(){return this.fast_.getTotalWeight()>=this.minWeight_},t.getEstimate=function(){return this.canEstimate()?Math.min(this.fast_.getEstimate(),this.slow_.getEstimate()):this.defaultEstimate_},t.getEstimateTTFB=function(){return this.ttfb_.getTotalWeight()>=this.minWeight_?this.ttfb_.getEstimate():this.defaultTTFB_},t.destroy=function(){},e}();function Vt(e,t){R.log('[abr] start candidates with "'+e+'" ignored because '+t)}var Wt=function(){function e(e){var t=this;this.hls=void 0,this.lastLevelLoadSec=0,this.lastLoadedFragLevel=-1,this.firstSelection=-1,this._nextAutoLevel=-1,this.nextAutoLevelKey="",this.audioTracksByGroup=null,this.codecTiers=null,this.timer=-1,this.fragCurrent=null,this.partCurrent=null,this.bitrateTestDelay=0,this.bwEstimator=void 0,this._abandonRulesCheck=function(){var e=t.fragCurrent,r=t.partCurrent,n=t.hls,i=n.autoLevelEnabled,a=n.media;if(e&&a){var s=performance.now(),o=r?r.stats:e.stats,l=r?r.duration:e.duration,u=s-o.loading.start,d=n.minAutoLevel;if(o.aborted||o.loaded&&o.loaded===o.total||e.level<=d)return t.clearTimer(),void(t._nextAutoLevel=-1);if(i&&!a.paused&&a.playbackRate&&a.readyState){var c=n.mainForwardBufferInfo;if(null!==c){var f=t.bwEstimator.getEstimateTTFB(),h=Math.abs(a.playbackRate);if(!(u<=Math.max(f,l/(2*h)*1e3))){var g=c.len/h,v=o.loading.first?o.loading.first-o.loading.start:-1,p=o.loaded&&v>-1,y=t.getBwEstimate(),b=n.levels,S=b[e.level],_=o.total||Math.max(o.loaded,Math.round(l*S.averageBitrate/8)),T=p?u-v:u;T<1&&p&&(T=Math.min(u,8*o.loaded/y));var L=p?1e3*o.loaded/T:0,P=L?(_-o.loaded)/L:8*_/y+f/1e3;if(!(P<=g)){var w,A=L?8*L:y,k=Number.POSITIVE_INFINITY;for(w=e.level-1;w>d;w--){var C=b[w].maxBitrate;if((k=t.getTimeToLoadFrag(f/1e3,A,l*C,!b[w].details))<g)break}if(!(k>=P||k>10*l)){n.nextLoadLevel=n.nextAutoLevel=w,p?t.bwEstimator.sample(u-Math.min(f,v),o.loaded):t.bwEstimator.sampleTTFB(u);var D=b[w].maxBitrate;t.getBwEstimate()*t.hls.config.abrBandWidthUpFactor>D&&t.resetEstimator(D),t.clearTimer(),R.warn("[abr] Fragment "+e.sn+(r?" part "+r.index:"")+" of level "+e.level+" is loading too slowly;\n      Time to underbuffer: "+g.toFixed(3)+" s\n      Estimated load time for current fragment: "+P.toFixed(3)+" s\n      Estimated load time for down switch fragment: "+k.toFixed(3)+" s\n      TTFB estimate: "+(0|v)+" ms\n      Current BW estimate: "+(m(y)?0|y:"Unknown")+" bps\n      New BW estimate: "+(0|t.getBwEstimate())+" bps\n      Switching to level "+w+" @ "+(0|D)+" bps"),n.trigger(E.FRAG_LOAD_EMERGENCY_ABORTED,{frag:e,part:r,stats:o})}}}}}}},this.hls=e,this.bwEstimator=this.initEstimator(),this.registerListeners()}var t=e.prototype;return t.resetEstimator=function(e){e&&(R.log("setting initial bwe to "+e),this.hls.config.abrEwmaDefaultEstimate=e),this.firstSelection=-1,this.bwEstimator=this.initEstimator()},t.initEstimator=function(){var e=this.hls.config;return new qt(e.abrEwmaSlowVoD,e.abrEwmaFastVoD,e.abrEwmaDefaultEstimate)},t.registerListeners=function(){var e=this.hls;e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.FRAG_LOADING,this.onFragLoading,this),e.on(E.FRAG_LOADED,this.onFragLoaded,this),e.on(E.FRAG_BUFFERED,this.onFragBuffered,this),e.on(E.LEVEL_SWITCHING,this.onLevelSwitching,this),e.on(E.LEVEL_LOADED,this.onLevelLoaded,this),e.on(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(E.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.on(E.ERROR,this.onError,this)},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.FRAG_LOADING,this.onFragLoading,this),e.off(E.FRAG_LOADED,this.onFragLoaded,this),e.off(E.FRAG_BUFFERED,this.onFragBuffered,this),e.off(E.LEVEL_SWITCHING,this.onLevelSwitching,this),e.off(E.LEVEL_LOADED,this.onLevelLoaded,this),e.off(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(E.MAX_AUTO_LEVEL_UPDATED,this.onMaxAutoLevelUpdated,this),e.off(E.ERROR,this.onError,this))},t.destroy=function(){this.unregisterListeners(),this.clearTimer(),this.hls=this._abandonRulesCheck=null,this.fragCurrent=this.partCurrent=null},t.onManifestLoading=function(e,t){this.lastLoadedFragLevel=-1,this.firstSelection=-1,this.lastLevelLoadSec=0,this.fragCurrent=this.partCurrent=null,this.onLevelsUpdated(),this.clearTimer()},t.onLevelsUpdated=function(){this.lastLoadedFragLevel>-1&&this.fragCurrent&&(this.lastLoadedFragLevel=this.fragCurrent.level),this._nextAutoLevel=-1,this.onMaxAutoLevelUpdated(),this.codecTiers=null,this.audioTracksByGroup=null},t.onMaxAutoLevelUpdated=function(){this.firstSelection=-1,this.nextAutoLevelKey=""},t.onFragLoading=function(e,t){var r,n=t.frag;this.ignoreFragment(n)||(n.bitrateTest||(this.fragCurrent=n,this.partCurrent=null!=(r=t.part)?r:null),this.clearTimer(),this.timer=self.setInterval(this._abandonRulesCheck,100))},t.onLevelSwitching=function(e,t){this.clearTimer()},t.onError=function(e,t){if(!t.fatal)switch(t.details){case _.BUFFER_ADD_CODEC_ERROR:case _.BUFFER_APPEND_ERROR:this.lastLoadedFragLevel=-1,this.firstSelection=-1;break;case _.FRAG_LOAD_TIMEOUT:var r=t.frag,n=this.fragCurrent,i=this.partCurrent;if(r&&n&&r.sn===n.sn&&r.level===n.level){var a=performance.now(),s=i?i.stats:r.stats,o=a-s.loading.start,l=s.loading.first?s.loading.first-s.loading.start:-1;if(s.loaded&&l>-1){var u=this.bwEstimator.getEstimateTTFB();this.bwEstimator.sample(o-Math.min(u,l),s.loaded)}else this.bwEstimator.sampleTTFB(o)}}},t.getTimeToLoadFrag=function(e,t,r,n){return e+r/t+(n?this.lastLevelLoadSec:0)},t.onLevelLoaded=function(e,t){var r=this.hls.config,n=t.stats.loading,i=n.end-n.start;m(i)&&(this.lastLevelLoadSec=i/1e3),t.details.live?this.bwEstimator.update(r.abrEwmaSlowLive,r.abrEwmaFastLive):this.bwEstimator.update(r.abrEwmaSlowVoD,r.abrEwmaFastVoD)},t.onFragLoaded=function(e,t){var r=t.frag,n=t.part,i=n?n.stats:r.stats;if(r.type===nt&&this.bwEstimator.sampleTTFB(i.loading.first-i.loading.start),!this.ignoreFragment(r)){if(this.clearTimer(),r.level===this._nextAutoLevel&&(this._nextAutoLevel=-1),this.firstSelection=-1,this.hls.config.abrMaxWithRealBitrate){var a=n?n.duration:r.duration,s=this.hls.levels[r.level],o=(s.loaded?s.loaded.bytes:0)+i.loaded,l=(s.loaded?s.loaded.duration:0)+a;s.loaded={bytes:o,duration:l},s.realBitrate=Math.round(8*o/l)}if(r.bitrateTest){var u={stats:i,frag:r,part:n,id:r.type};this.onFragBuffered(E.FRAG_BUFFERED,u),r.bitrateTest=!1}else this.lastLoadedFragLevel=r.level}},t.onFragBuffered=function(e,t){var r=t.frag,n=t.part,i=null!=n&&n.stats.loaded?n.stats:r.stats;if(!i.aborted&&!this.ignoreFragment(r)){var a=i.parsing.end-i.loading.start-Math.min(i.loading.first-i.loading.start,this.bwEstimator.getEstimateTTFB());this.bwEstimator.sample(a,i.loaded),i.bwEstimate=this.getBwEstimate(),r.bitrateTest?this.bitrateTestDelay=a/1e3:this.bitrateTestDelay=0}},t.ignoreFragment=function(e){return e.type!==nt||"initSegment"===e.sn},t.clearTimer=function(){this.timer>-1&&(self.clearInterval(this.timer),this.timer=-1)},t.getAutoLevelKey=function(){return this.getBwEstimate()+"_"+this.getStarvationDelay().toFixed(2)},t.getNextABRAutoLevel=function(){var e=this.fragCurrent,t=this.partCurrent,r=this.hls,n=r.maxAutoLevel,i=r.config,a=r.minAutoLevel,s=t?t.duration:e?e.duration:0,o=this.getBwEstimate(),l=this.getStarvationDelay(),u=i.abrBandWidthFactor,d=i.abrBandWidthUpFactor;if(l){var c=this.findBestLevel(o,a,n,l,0,u,d);if(c>=0)return c}var f=s?Math.min(s,i.maxStarvationDelay):i.maxStarvationDelay;if(!l){var h=this.bitrateTestDelay;h&&(f=(s?Math.min(s,i.maxLoadingDelay):i.maxLoadingDelay)-h,R.info("[abr] bitrate test took "+Math.round(1e3*h)+"ms, set first fragment max fetchDuration to "+Math.round(1e3*f)+" ms"),u=d=1)}var g=this.findBestLevel(o,a,n,l,f,u,d);if(R.info("[abr] "+(l?"rebuffering expected":"buffer is empty")+", optimal quality level "+g),g>-1)return g;var v=r.levels[a],p=r.levels[r.loadLevel];return(null==v?void 0:v.bitrate)<(null==p?void 0:p.bitrate)?a:r.loadLevel},t.getStarvationDelay=function(){var e=this.hls,t=e.media;if(!t)return 1/0;var r=t&&0!==t.playbackRate?Math.abs(t.playbackRate):1,n=e.mainForwardBufferInfo;return(n?n.len:0)/r},t.getBwEstimate=function(){return this.bwEstimator.canEstimate()?this.bwEstimator.getEstimate():this.hls.config.abrEwmaDefaultEstimate},t.findBestLevel=function(e,t,r,n,i,a,s){var o,l=this,u=n+i,d=this.lastLoadedFragLevel,c=-1===d?this.hls.firstLevel:d,f=this.fragCurrent,h=this.partCurrent,g=this.hls,v=g.levels,p=g.allAudioTracks,y=g.loadLevel,b=g.config;if(1===v.length)return 0;var E,S=v[c],_=!(null==S||null==(o=S.details)||!o.live),T=-1===y||-1===d,L="SDR",P=(null==S?void 0:S.frameRate)||0,w=b.audioPreference,A=b.videoPreference;if(this.audioTracksByGroup||(this.audioTracksByGroup=function(e){return e.reduce((function(e,t){var r=e.groups[t.groupId];r||(r=e.groups[t.groupId]={tracks:[],channels:{2:0},hasDefault:!1,hasAutoSelect:!1}),r.tracks.push(t);var n=t.channels||"2";return r.channels[n]=(r.channels[n]||0)+1,r.hasDefault=r.hasDefault||t.default,r.hasAutoSelect=r.hasAutoSelect||t.autoselect,r.hasDefault&&(e.hasDefaultAudio=!0),r.hasAutoSelect&&(e.hasAutoSelectAudio=!0),e}),{hasDefaultAudio:!1,hasAutoSelectAudio:!1,groups:{}})}(p)),T){if(-1!==this.firstSelection)return this.firstSelection;var k=this.codecTiers||(this.codecTiers=function(e,t,r,n){return e.slice(r,n+1).reduce((function(e,t){if(!t.codecSet)return e;var r=t.audioGroups,n=e[t.codecSet];n||(e[t.codecSet]=n={minBitrate:1/0,minHeight:1/0,minFramerate:1/0,maxScore:0,videoRanges:{SDR:0},channels:{2:0},hasDefaultAudio:!r,fragmentError:0}),n.minBitrate=Math.min(n.minBitrate,t.bitrate);var i=Math.min(t.height,t.width);return n.minHeight=Math.min(n.minHeight,i),n.minFramerate=Math.min(n.minFramerate,t.frameRate),n.maxScore=Math.max(n.maxScore,t.score),n.fragmentError+=t.fragmentError,n.videoRanges[t.videoRange]=(n.videoRanges[t.videoRange]||0)+1,e}),{})}(v,0,t,r)),C=function(e,t,r,n,i){for(var a=Object.keys(e),s=null==n?void 0:n.channels,o=null==n?void 0:n.audioCodec,l=s&&2===parseInt(s),u=!0,d=!1,c=1/0,f=1/0,h=1/0,g=0,v=[],p=function(e,t){var r=!1,n=[];return e&&(r="SDR"!==e,n=[e]),t&&(n=t.allowedVideoRanges||bt.slice(0),n=(r=void 0!==t.preferHDR?t.preferHDR:function(){if("function"==typeof matchMedia){var e=matchMedia("(dynamic-range: high)"),t=matchMedia("bad query");if(e.media!==t.media)return!0===e.matches}return!1}())?n.filter((function(e){return"SDR"!==e})):["SDR"]),{preferHDR:r,allowedVideoRanges:n}}(t,i),y=p.preferHDR,b=p.allowedVideoRanges,E=function(){var t=e[a[S]];u=t.channels[2]>0,c=Math.min(c,t.minHeight),f=Math.min(f,t.minFramerate),h=Math.min(h,t.minBitrate);var r=b.filter((function(e){return t.videoRanges[e]>0}));r.length>0&&(d=!0,v=r)},S=a.length;S--;)E();c=m(c)?c:0,f=m(f)?f:0;var _=Math.max(1080,c),T=Math.max(30,f);return h=m(h)?h:r,r=Math.max(h,r),d||(t=void 0,v=[]),{codecSet:a.reduce((function(t,n){var i=e[n];if(n===t)return t;if(i.minBitrate>r)return Vt(n,"min bitrate of "+i.minBitrate+" > current estimate of "+r),t;if(!i.hasDefaultAudio)return Vt(n,"no renditions with default or auto-select sound found"),t;if(o&&n.indexOf(o.substring(0,4))%5!=0)return Vt(n,'audio codec preference "'+o+'" not found'),t;if(s&&!l){if(!i.channels[s])return Vt(n,"no renditions with "+s+" channel sound found (channels options: "+Object.keys(i.channels)+")"),t}else if((!o||l)&&u&&0===i.channels[2])return Vt(n,"no renditions with stereo sound found"),t;return i.minHeight>_?(Vt(n,"min resolution of "+i.minHeight+" > maximum of "+_),t):i.minFramerate>T?(Vt(n,"min framerate of "+i.minFramerate+" > maximum of "+T),t):v.some((function(e){return i.videoRanges[e]>0}))?i.maxScore<g?(Vt(n,"max score of "+i.maxScore+" < selected max of "+g),t):t&&(Me(n)>=Me(t)||i.fragmentError>e[t].fragmentError)?t:(g=i.maxScore,n):(Vt(n,"no variants with VIDEO-RANGE of "+JSON.stringify(v)+" found"),t)}),void 0),videoRanges:v,preferHDR:y,minFramerate:f,minBitrate:h}}(k,L,e,w,A),D=C.codecSet,I=C.videoRanges,x=C.minFramerate,O=C.minBitrate,M=C.preferHDR;E=D,L=M?I[I.length-1]:I[0],P=x,e=Math.max(e,O),R.log("[abr] picked start tier "+JSON.stringify(C))}else E=null==S?void 0:S.codecSet,L=null==S?void 0:S.videoRange;for(var F,N=h?h.duration:f?f.duration:0,B=this.bwEstimator.getEstimateTTFB()/1e3,U=[],G=function(){var t,o=v[j],f=j>c;if(!o)return 0;if(E&&o.codecSet!==E||L&&o.videoRange!==L||f&&P>o.frameRate||!f&&P>0&&P<o.frameRate||o.supportedResult&&(null==(t=o.supportedResult.decodingInfoResults)||!t[0].smooth))return U.push(j),0;var g,p=o.details,b=(h?null==p?void 0:p.partTarget:null==p?void 0:p.averagetargetduration)||N;g=f?s*e:a*e;var w=N&&n>=2*N&&0===i?v[j].averageBitrate:v[j].maxBitrate,A=l.getTimeToLoadFrag(B,g,w*b,void 0===p);if(g>=w&&(j===d||0===o.loadError&&0===o.fragmentError)&&(A<=B||!m(A)||_&&!l.bitrateTestDelay||A<u)){var k=l.forcedAutoLevel;return j===y||-1!==k&&k===y||(U.length&&R.trace("[abr] Skipped level(s) "+U.join(",")+" of "+r+' max with CODECS and VIDEO-RANGE:"'+v[U[0]].codecs+'" '+v[U[0]].videoRange+'; not compatible with "'+S.codecs+'" '+L),R.info("[abr] switch candidate:"+c+"->"+j+" adjustedbw("+Math.round(g)+")-bitrate="+Math.round(g-w)+" ttfb:"+B.toFixed(1)+" avgDuration:"+b.toFixed(1)+" maxFetchDuration:"+u.toFixed(1)+" fetchDuration:"+A.toFixed(1)+" firstSelection:"+T+" codecSet:"+E+" videoRange:"+L+" hls.loadLevel:"+y)),T&&(l.firstSelection=j),{v:j}}},j=r;j>=t;j--)if(0!==(F=G())&&F)return F.v;return-1},i(e,[{key:"firstAutoLevel",get:function(){var e=this.hls,t=e.maxAutoLevel,r=e.minAutoLevel,n=this.getBwEstimate(),i=this.hls.config.maxStarvationDelay,a=this.findBestLevel(n,r,t,0,i,1,1);if(a>-1)return a;var s=this.hls.firstLevel,o=Math.min(Math.max(s,r),t);return R.warn("[abr] Could not find best starting auto level. Defaulting to first in playlist "+s+" clamped to "+o),o}},{key:"forcedAutoLevel",get:function(){return this.nextAutoLevelKey?-1:this._nextAutoLevel}},{key:"nextAutoLevel",get:function(){var e=this.forcedAutoLevel,t=this.bwEstimator.canEstimate(),r=this.lastLoadedFragLevel>-1;if(!(-1===e||t&&r&&this.nextAutoLevelKey!==this.getAutoLevelKey()))return e;var n=t&&r?this.getNextABRAutoLevel():this.firstAutoLevel;if(-1!==e){var i=this.hls.levels;if(i.length>Math.max(e,n)&&i[e].loadError<=i[n].loadError)return e}return this._nextAutoLevel=n,this.nextAutoLevelKey=this.getAutoLevelKey(),n},set:function(e){var t=this.hls,r=t.maxAutoLevel,n=t.minAutoLevel,i=Math.min(Math.max(e,n),r);this._nextAutoLevel!==i&&(this.nextAutoLevelKey="",this._nextAutoLevel=i)}}]),e}(),Kt={length:0,start:function(){return 0},end:function(){return 0}},zt=function(){function e(){}return e.isBuffered=function(t,r){try{if(t)for(var n=e.getBuffered(t),i=0;i<n.length;i++)if(r>=n.start(i)&&r<=n.end(i))return!0}catch(e){}return!1},e.bufferInfo=function(t,r,n){try{if(t){var i,a=e.getBuffered(t),s=[];for(i=0;i<a.length;i++)s.push({start:a.start(i),end:a.end(i)});return this.bufferedInfo(s,r,n)}}catch(e){}return{len:0,start:r,end:r,nextStart:void 0}},e.bufferedInfo=function(e,t,r){t=Math.max(0,t),e.sort((function(e,t){return e.start-t.start||t.end-e.end}));var n=[];if(r)for(var i=0;i<e.length;i++){var a=n.length;if(a){var s=n[a-1].end;e[i].start-s<r?e[i].end>s&&(n[a-1].end=e[i].end):n.push(e[i])}else n.push(e[i])}else n=e;for(var o,l=0,u=t,d=t,c=0;c<n.length;c++){var f=n[c].start,h=n[c].end;if(t+r>=f&&t<h)u=f,l=(d=h)-t;else if(t+r<f){o=f;break}}return{len:l,start:u||0,end:d||0,nextStart:o}},e.getBuffered=function(e){try{return e.buffered}catch(e){return R.log("failed to get media.buffered",e),Kt}},e}(),Yt=function(){function e(e){this.buffers=void 0,this.queues={video:[],audio:[],audiovideo:[]},this.buffers=e}var t=e.prototype;return t.append=function(e,t,r){var n=this.queues[t];n.push(e),1!==n.length||r||this.executeNext(t)},t.insertAbort=function(e,t){this.queues[t].unshift(e),this.executeNext(t)},t.appendBlocker=function(e){var t,r=new Promise((function(e){t=e})),n={execute:t,onStart:function(){},onComplete:function(){},onError:function(){}};return this.append(n,e),r},t.executeNext=function(e){var t=this.queues[e];if(t.length){var r=t[0];try{r.execute()}catch(t){R.warn('[buffer-operation-queue]: Exception executing "'+e+'" SourceBuffer operation: '+t),r.onError(t);var n=this.buffers[e];null!=n&&n.updating||this.shiftAndExecuteNext(e)}}},t.shiftAndExecuteNext=function(e){this.queues[e].shift(),this.executeNext(e)},t.current=function(e){return this.queues[e][0]},e}(),Xt=/(avc[1234]|hvc1|hev1|dvh[1e]|vp09|av01)(?:\.[^.,]+)+/,Jt=function(){function e(e){var t=this;this.details=null,this._objectUrl=null,this.operationQueue=void 0,this.listeners=void 0,this.hls=void 0,this.bufferCodecEventsExpected=0,this._bufferCodecEventsTotal=0,this.media=null,this.mediaSource=null,this.lastMpegAudioChunk=null,this.appendSource=void 0,this.appendErrors={audio:0,video:0,audiovideo:0},this.tracks={},this.pendingTracks={},this.sourceBuffer=void 0,this.log=void 0,this.warn=void 0,this.error=void 0,this._onEndStreaming=function(e){t.hls&&t.hls.pauseBuffering()},this._onStartStreaming=function(e){t.hls&&t.hls.resumeBuffering()},this._onMediaSourceOpen=function(){var e=t.media,r=t.mediaSource;t.log("Media source opened"),e&&(e.removeEventListener("emptied",t._onMediaEmptied),t.updateMediaElementDuration(),t.hls.trigger(E.MEDIA_ATTACHED,{media:e,mediaSource:r})),r&&r.removeEventListener("sourceopen",t._onMediaSourceOpen),t.checkPendingTracks()},this._onMediaSourceClose=function(){t.log("Media source closed")},this._onMediaSourceEnded=function(){t.log("Media source ended")},this._onMediaEmptied=function(){var e=t.mediaSrc,r=t._objectUrl;e!==r&&R.error("Media element src was set while attaching MediaSource ("+r+" > "+e+")")},this.hls=e;var r,n="[buffer-controller]";this.appendSource=(r=ke(e.config.preferManagedMediaSource),"undefined"!=typeof self&&r===self.ManagedMediaSource),this.log=R.log.bind(R,n),this.warn=R.warn.bind(R,n),this.error=R.error.bind(R,n),this._initSourceBuffer(),this.registerListeners()}var t=e.prototype;return t.hasSourceTypes=function(){return this.getSourceBufferTypes().length>0||Object.keys(this.pendingTracks).length>0},t.destroy=function(){this.unregisterListeners(),this.details=null,this.lastMpegAudioChunk=null,this.hls=null},t.registerListeners=function(){var e=this.hls;e.on(E.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(E.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.MANIFEST_PARSED,this.onManifestParsed,this),e.on(E.BUFFER_RESET,this.onBufferReset,this),e.on(E.BUFFER_APPENDING,this.onBufferAppending,this),e.on(E.BUFFER_CODECS,this.onBufferCodecs,this),e.on(E.BUFFER_EOS,this.onBufferEos,this),e.on(E.BUFFER_FLUSHING,this.onBufferFlushing,this),e.on(E.LEVEL_UPDATED,this.onLevelUpdated,this),e.on(E.FRAG_PARSED,this.onFragParsed,this),e.on(E.FRAG_CHANGED,this.onFragChanged,this)},t.unregisterListeners=function(){var e=this.hls;e.off(E.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(E.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.MANIFEST_PARSED,this.onManifestParsed,this),e.off(E.BUFFER_RESET,this.onBufferReset,this),e.off(E.BUFFER_APPENDING,this.onBufferAppending,this),e.off(E.BUFFER_CODECS,this.onBufferCodecs,this),e.off(E.BUFFER_EOS,this.onBufferEos,this),e.off(E.BUFFER_FLUSHING,this.onBufferFlushing,this),e.off(E.LEVEL_UPDATED,this.onLevelUpdated,this),e.off(E.FRAG_PARSED,this.onFragParsed,this),e.off(E.FRAG_CHANGED,this.onFragChanged,this)},t._initSourceBuffer=function(){this.sourceBuffer={},this.operationQueue=new Yt(this.sourceBuffer),this.listeners={audio:[],video:[],audiovideo:[]},this.appendErrors={audio:0,video:0,audiovideo:0},this.lastMpegAudioChunk=null},t.onManifestLoading=function(){this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=0,this.details=null},t.onManifestParsed=function(e,t){t.audio&&!t.video||t.altAudio,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal=1,this.log(this.bufferCodecEventsExpected+" bufferCodec event(s) expected")},t.onMediaAttaching=function(e,t){var r=this.media=t.media,n=ke(this.appendSource);if(r&&n){var i,a=this.mediaSource=new n;this.log("created media source: "+(null==(i=a.constructor)?void 0:i.name)),a.addEventListener("sourceopen",this._onMediaSourceOpen),a.addEventListener("sourceended",this._onMediaSourceEnded),a.addEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(a.addEventListener("startstreaming",this._onStartStreaming),a.addEventListener("endstreaming",this._onEndStreaming));var s=this._objectUrl=self.URL.createObjectURL(a);if(this.appendSource)try{r.removeAttribute("src");var o=self.ManagedMediaSource;r.disableRemotePlayback=r.disableRemotePlayback||o&&a instanceof o,Qt(r),function(e,t){var r=self.document.createElement("source");r.type="video/mp4",r.src=t,e.appendChild(r)}(r,s),r.load()}catch(e){r.src=s}else r.src=s;r.addEventListener("emptied",this._onMediaEmptied)}},t.onMediaDetaching=function(){var e=this.media,t=this.mediaSource,r=this._objectUrl;if(t){if(this.log("media source detaching"),"open"===t.readyState)try{t.endOfStream()}catch(e){this.warn("onMediaDetaching: "+e.message+" while calling endOfStream")}this.onBufferReset(),t.removeEventListener("sourceopen",this._onMediaSourceOpen),t.removeEventListener("sourceended",this._onMediaSourceEnded),t.removeEventListener("sourceclose",this._onMediaSourceClose),this.appendSource&&(t.removeEventListener("startstreaming",this._onStartStreaming),t.removeEventListener("endstreaming",this._onEndStreaming)),e&&(e.removeEventListener("emptied",this._onMediaEmptied),r&&self.URL.revokeObjectURL(r),this.mediaSrc===r?(e.removeAttribute("src"),this.appendSource&&Qt(e),e.load()):this.warn("media|source.src was changed by a third party - skip cleanup")),this.mediaSource=null,this.media=null,this._objectUrl=null,this.bufferCodecEventsExpected=this._bufferCodecEventsTotal,this.pendingTracks={},this.tracks={}}this.hls.trigger(E.MEDIA_DETACHED,void 0)},t.onBufferReset=function(){var e=this;this.getSourceBufferTypes().forEach((function(t){e.resetBuffer(t)})),this._initSourceBuffer()},t.resetBuffer=function(e){var t=this.sourceBuffer[e];try{var r;t&&(this.removeBufferListeners(e),this.sourceBuffer[e]=void 0,null!=(r=this.mediaSource)&&r.sourceBuffers.length&&this.mediaSource.removeSourceBuffer(t))}catch(t){this.warn("onBufferReset "+e,t)}},t.onBufferCodecs=function(e,t){var r=this,n=this.getSourceBufferTypes().length,i=Object.keys(t);if(i.forEach((function(e){if(n){var i=r.tracks[e];if(i&&"function"==typeof i.buffer.changeType){var a,s=t[e],o=s.id,l=s.codec,u=s.levelCodec,d=s.container,c=s.metadata,f=Ue(i.codec,i.levelCodec),h=null==f?void 0:f.replace(Xt,"$1"),g=Ue(l,u),v=null==(a=g)?void 0:a.replace(Xt,"$1");if(g&&h!==v){"audio"===e.slice(0,5)&&(g=Be(g,r.appendSource));var p=d+";codecs="+g;r.appendChangeType(e,p),r.log("switching codec "+f+" to "+g),r.tracks[e]={buffer:i.buffer,codec:l,container:d,levelCodec:u,metadata:c,id:o}}}}else r.pendingTracks[e]=t[e]})),!n){var a=Math.max(this.bufferCodecEventsExpected-1,0);this.bufferCodecEventsExpected!==a&&(this.log(a+" bufferCodec event(s) expected "+i.join(",")),this.bufferCodecEventsExpected=a),this.mediaSource&&"open"===this.mediaSource.readyState&&this.checkPendingTracks()}},t.appendChangeType=function(e,t){var r=this,n=this.operationQueue,i={execute:function(){var i=r.sourceBuffer[e];i&&(r.log("changing "+e+" sourceBuffer type to "+t),i.changeType(t)),n.shiftAndExecuteNext(e)},onStart:function(){},onComplete:function(){},onError:function(t){r.warn("Failed to change "+e+" SourceBuffer type",t)}};n.append(i,e,!!this.pendingTracks[e])},t.onBufferAppending=function(e,t){var r=this,n=this.hls,i=this.operationQueue,a=this.tracks,s=t.data,o=t.type,l=t.frag,u=t.part,d=t.chunkMeta,c=d.buffering[o],f=self.performance.now();c.start=f;var h=l.stats.buffering,g=u?u.stats.buffering:null;0===h.start&&(h.start=f),g&&0===g.start&&(g.start=f);var v=a.audio,p=!1;"audio"===o&&"audio/mpeg"===(null==v?void 0:v.container)&&(p=!this.lastMpegAudioChunk||1===d.id||this.lastMpegAudioChunk.sn!==d.sn,this.lastMpegAudioChunk=d);var m=l.start,y={execute:function(){if(c.executeStart=self.performance.now(),p){var e=r.sourceBuffer[o];if(e){var t=m-e.timestampOffset;Math.abs(t)>=.1&&(r.log("Updating audio SourceBuffer timestampOffset to "+m+" (delta: "+t+") sn: "+l.sn+")"),e.timestampOffset=m)}}r.appendExecutor(s,o)},onStart:function(){},onComplete:function(){var e=self.performance.now();c.executeEnd=c.end=e,0===h.first&&(h.first=e),g&&0===g.first&&(g.first=e);var t=r.sourceBuffer,n={};for(var i in t)n[i]=zt.getBuffered(t[i]);r.appendErrors[o]=0,"audio"===o||"video"===o?r.appendErrors.audiovideo=0:(r.appendErrors.audio=0,r.appendErrors.video=0),r.hls.trigger(E.BUFFER_APPENDED,{type:o,frag:l,part:u,chunkMeta:d,parent:l.type,timeRanges:n})},onError:function(e){var t={type:S.MEDIA_ERROR,parent:l.type,details:_.BUFFER_APPEND_ERROR,sourceBufferName:o,frag:l,part:u,chunkMeta:d,error:e,err:e,fatal:!1};if(e.code===DOMException.QUOTA_EXCEEDED_ERR)t.details=_.BUFFER_FULL_ERROR;else{var i=++r.appendErrors[o];t.details=_.BUFFER_APPEND_ERROR,r.warn("Failed "+i+"/"+n.config.appendErrorMaxRetry+' times to append segment in "'+o+'" sourceBuffer'),i>=n.config.appendErrorMaxRetry&&(t.fatal=!0)}n.trigger(E.ERROR,t)}};i.append(y,o,!!this.pendingTracks[o])},t.onBufferFlushing=function(e,t){var r=this,n=this.operationQueue,i=function(e){return{execute:r.removeExecutor.bind(r,e,t.startOffset,t.endOffset),onStart:function(){},onComplete:function(){r.hls.trigger(E.BUFFER_FLUSHED,{type:e})},onError:function(t){r.warn("Failed to remove from "+e+" SourceBuffer",t)}}};t.type?n.append(i(t.type),t.type):this.getSourceBufferTypes().forEach((function(e){n.append(i(e),e)}))},t.onFragParsed=function(e,t){var r=this,n=t.frag,i=t.part,a=[],s=i?i.elementaryStreams:n.elementaryStreams;s[F]?a.push("audiovideo"):(s[O]&&a.push("audio"),s[M]&&a.push("video")),0===a.length&&this.warn("Fragments must have at least one ElementaryStreamType set. type: "+n.type+" level: "+n.level+" sn: "+n.sn),this.blockBuffers((function(){var e=self.performance.now();n.stats.buffering.end=e,i&&(i.stats.buffering.end=e);var t=i?i.stats:n.stats;r.hls.trigger(E.FRAG_BUFFERED,{frag:n,part:i,stats:t,id:n.type})}),a)},t.onFragChanged=function(e,t){this.trimBuffers()},t.onBufferEos=function(e,t){var r=this;this.getSourceBufferTypes().reduce((function(e,n){var i=r.sourceBuffer[n];return!i||t.type&&t.type!==n||(i.ending=!0,i.ended||(i.ended=!0,r.log(n+" sourceBuffer now EOS"))),e&&!(i&&!i.ended)}),!0)&&(this.log("Queueing mediaSource.endOfStream()"),this.blockBuffers((function(){r.getSourceBufferTypes().forEach((function(e){var t=r.sourceBuffer[e];t&&(t.ending=!1)}));var e=r.mediaSource;e&&"open"===e.readyState?(r.log("Calling mediaSource.endOfStream()"),e.endOfStream()):e&&r.log("Could not call mediaSource.endOfStream(). mediaSource.readyState: "+e.readyState)})))},t.onLevelUpdated=function(e,t){var r=t.details;r.fragments.length&&(this.details=r,this.getSourceBufferTypes().length?this.blockBuffers(this.updateMediaElementDuration.bind(this)):this.updateMediaElementDuration())},t.trimBuffers=function(){var e=this.hls,t=this.details,r=this.media;if(r&&null!==t&&this.getSourceBufferTypes().length){var n=e.config,i=r.currentTime,a=t.levelTargetDuration,s=t.live&&null!==n.liveBackBufferLength?n.liveBackBufferLength:n.backBufferLength;if(m(s)&&s>0){var o=Math.max(s,a),l=Math.floor(i/a)*a-o;this.flushBackBuffer(i,a,l)}if(m(n.frontBufferFlushThreshold)&&n.frontBufferFlushThreshold>0){var u=Math.max(n.maxBufferLength,n.frontBufferFlushThreshold),d=Math.max(u,a),c=Math.floor(i/a)*a+d;this.flushFrontBuffer(i,a,c)}}},t.flushBackBuffer=function(e,t,r){var n=this,i=this.details,a=this.sourceBuffer;this.getSourceBufferTypes().forEach((function(s){var o=a[s];if(o){var l=zt.getBuffered(o);if(l.length>0&&r>l.start(0)){if(n.hls.trigger(E.BACK_BUFFER_REACHED,{bufferEnd:r}),null!=i&&i.live)n.hls.trigger(E.LIVE_BACK_BUFFER_REACHED,{bufferEnd:r});else if(o.ended&&l.end(l.length-1)-e<2*t)return void n.log("Cannot flush "+s+" back buffer while SourceBuffer is in ended state");n.hls.trigger(E.BUFFER_FLUSHING,{startOffset:0,endOffset:r,type:s})}}}))},t.flushFrontBuffer=function(e,t,r){var n=this,i=this.sourceBuffer;this.getSourceBufferTypes().forEach((function(a){var s=i[a];if(s){var o=zt.getBuffered(s),l=o.length;if(l<2)return;var u=o.start(l-1),d=o.end(l-1);if(r>u||e>=u&&e<=d)return;if(s.ended&&e-d<2*t)return void n.log("Cannot flush "+a+" front buffer while SourceBuffer is in ended state");n.hls.trigger(E.BUFFER_FLUSHING,{startOffset:u,endOffset:1/0,type:a})}}))},t.updateMediaElementDuration=function(){if(this.details&&this.media&&this.mediaSource&&"open"===this.mediaSource.readyState){var e=this.details,t=this.hls,r=this.media,n=this.mediaSource,i=e.fragments[0].start+e.totalduration,a=r.duration,s=m(n.duration)?n.duration:0;e.live&&t.config.liveDurationInfinity?(n.duration=1/0,this.updateSeekableRange(e)):(i>s&&i>a||!m(a))&&(this.log("Updating Media Source duration to "+i.toFixed(3)),n.duration=i)}},t.updateSeekableRange=function(e){var t=this.mediaSource,r=e.fragments;if(r.length&&e.live&&null!=t&&t.setLiveSeekableRange){var n=Math.max(0,r[0].start),i=Math.max(n,n+e.totalduration);this.log("Media Source duration is set to "+t.duration+". Setting seekable range to "+n+"-"+i+"."),t.setLiveSeekableRange(n,i)}},t.checkPendingTracks=function(){var e=this.bufferCodecEventsExpected,t=this.operationQueue,r=this.pendingTracks,n=Object.keys(r).length;if(n&&(!e||2===n||"audiovideo"in r)){this.createSourceBuffers(r),this.pendingTracks={};var i=this.getSourceBufferTypes();if(i.length)this.hls.trigger(E.BUFFER_CREATED,{tracks:this.tracks}),i.forEach((function(e){t.executeNext(e)}));else{var a=new Error("could not create source buffer for media codec(s)");this.hls.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_INCOMPATIBLE_CODECS_ERROR,fatal:!0,error:a,reason:a.message})}}},t.createSourceBuffers=function(e){var t=this,r=this.sourceBuffer,n=this.mediaSource;if(!n)throw Error("createSourceBuffers called when mediaSource was null");var i=function(i){if(!r[i]){var a,s=e[i];if(!s)throw Error("source buffer exists for track "+i+", however track does not");var o=-1===(null==(a=s.levelCodec)?void 0:a.indexOf(","))?s.levelCodec:s.codec;o&&"audio"===i.slice(0,5)&&(o=Be(o,t.appendSource));var l=s.container+";codecs="+o;t.log("creating sourceBuffer("+l+")");try{var u=r[i]=n.addSourceBuffer(l),d=i;t.addBufferListener(d,"updatestart",t._onSBUpdateStart),t.addBufferListener(d,"updateend",t._onSBUpdateEnd),t.addBufferListener(d,"error",t._onSBUpdateError),t.appendSource&&t.addBufferListener(d,"bufferedchange",(function(e,r){var n=r.removedRanges;null!=n&&n.length&&t.hls.trigger(E.BUFFER_FLUSHED,{type:i})})),t.tracks[i]={buffer:u,codec:o,container:s.container,levelCodec:s.levelCodec,metadata:s.metadata,id:s.id}}catch(e){t.error("error while trying to add sourceBuffer: "+e.message),t.hls.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_ADD_CODEC_ERROR,fatal:!1,error:e,sourceBufferName:i,mimeType:l})}}};for(var a in e)i(a)},t._onSBUpdateStart=function(e){this.operationQueue.current(e).onStart()},t._onSBUpdateEnd=function(e){var t;if("closed"!==(null==(t=this.mediaSource)?void 0:t.readyState)){var r=this.operationQueue;r.current(e).onComplete(),r.shiftAndExecuteNext(e)}else this.resetBuffer(e)},t._onSBUpdateError=function(e,t){var r,n=new Error(e+" SourceBuffer error. MediaSource readyState: "+(null==(r=this.mediaSource)?void 0:r.readyState));this.error(""+n,t),this.hls.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_APPENDING_ERROR,sourceBufferName:e,error:n,fatal:!1});var i=this.operationQueue.current(e);i&&i.onError(n)},t.removeExecutor=function(e,t,r){var n=this.media,i=this.mediaSource,a=this.operationQueue,s=this.sourceBuffer[e];if(!n||!i||!s)return this.warn("Attempting to remove from the "+e+" SourceBuffer, but it does not exist"),void a.shiftAndExecuteNext(e);var o=m(n.duration)?n.duration:1/0,l=m(i.duration)?i.duration:1/0,u=Math.max(0,t),d=Math.min(r,o,l);d>u&&(!s.ending||s.ended)?(s.ended=!1,this.log("Removing ["+u+","+d+"] from the "+e+" SourceBuffer"),s.remove(u,d)):a.shiftAndExecuteNext(e)},t.appendExecutor=function(e,t){var r=this.sourceBuffer[t];if(r)r.ended=!1,r.appendBuffer(e);else if(!this.pendingTracks[t])throw new Error("Attempting to append to the "+t+" SourceBuffer, but it does not exist")},t.blockBuffers=function(e,t){var r=this;if(void 0===t&&(t=this.getSourceBufferTypes()),!t.length)return this.log("Blocking operation requested, but no SourceBuffers exist"),void Promise.resolve().then(e);var n=this.operationQueue,i=t.map((function(e){return n.appendBlocker(e)}));Promise.all(i).then((function(){e(),t.forEach((function(e){var t=r.sourceBuffer[e];null!=t&&t.updating||n.shiftAndExecuteNext(e)}))}))},t.getSourceBufferTypes=function(){return Object.keys(this.sourceBuffer)},t.addBufferListener=function(e,t,r){var n=this.sourceBuffer[e];if(n){var i=r.bind(this,e);this.listeners[e].push({event:t,listener:i}),n.addEventListener(t,i)}},t.removeBufferListeners=function(e){var t=this.sourceBuffer[e];t&&this.listeners[e].forEach((function(e){t.removeEventListener(e.event,e.listener)}))},i(e,[{key:"mediaSrc",get:function(){var e,t=(null==(e=this.media)?void 0:e.firstChild)||this.media;return null==t?void 0:t.src}}]),e}();function Qt(e){var t=e.querySelectorAll("source");[].slice.call(t).forEach((function(t){e.removeChild(t)}))}var Zt=function(){function e(e){this.hls=void 0,this.autoLevelCapping=void 0,this.firstLevel=void 0,this.media=void 0,this.restrictedLevels=void 0,this.timer=void 0,this.clientRect=void 0,this.streamController=void 0,this.hls=e,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.firstLevel=-1,this.media=null,this.restrictedLevels=[],this.timer=void 0,this.clientRect=null,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.destroy=function(){this.hls&&this.unregisterListener(),this.timer&&this.stopCapping(),this.media=null,this.clientRect=null,this.hls=this.streamController=null},t.registerListeners=function(){var e=this.hls;e.on(E.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.on(E.MEDIA_ATTACHING,this.onMediaAttaching,this),e.on(E.MANIFEST_PARSED,this.onManifestParsed,this),e.on(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(E.BUFFER_CODECS,this.onBufferCodecs,this),e.on(E.MEDIA_DETACHING,this.onMediaDetaching,this)},t.unregisterListener=function(){var e=this.hls;e.off(E.FPS_DROP_LEVEL_CAPPING,this.onFpsDropLevelCapping,this),e.off(E.MEDIA_ATTACHING,this.onMediaAttaching,this),e.off(E.MANIFEST_PARSED,this.onManifestParsed,this),e.off(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(E.BUFFER_CODECS,this.onBufferCodecs,this),e.off(E.MEDIA_DETACHING,this.onMediaDetaching,this)},t.onFpsDropLevelCapping=function(e,t){var r=this.hls.levels[t.droppedLevel];this.isLevelAllowed(r)&&this.restrictedLevels.push({bitrate:r.bitrate,height:r.height,width:r.width})},t.onMediaAttaching=function(e,t){this.media=t.media instanceof HTMLVideoElement?t.media:null,this.clientRect=null,this.timer&&this.hls.levels.length&&this.detectPlayerSize()},t.onManifestParsed=function(e,t){var r=this.hls;this.restrictedLevels=[],this.firstLevel=t.firstLevel,r.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onLevelsUpdated=function(e,t){this.timer&&m(this.autoLevelCapping)&&this.detectPlayerSize()},t.onBufferCodecs=function(e,t){this.hls.config.capLevelToPlayerSize&&t.video&&this.startCapping()},t.onMediaDetaching=function(){this.stopCapping()},t.detectPlayerSize=function(){if(this.media){if(this.mediaHeight<=0||this.mediaWidth<=0)return void(this.clientRect=null);var e=this.hls.levels;if(e.length){var t=this.hls,r=this.getMaxLevel(e.length-1);r!==this.autoLevelCapping&&R.log("Setting autoLevelCapping to "+r+": "+e[r].height+"p@"+e[r].bitrate+" for media "+this.mediaWidth+"x"+this.mediaHeight),t.autoLevelCapping=r,t.autoLevelCapping>this.autoLevelCapping&&this.streamController&&this.streamController.nextLevelSwitch(),this.autoLevelCapping=t.autoLevelCapping}}},t.getMaxLevel=function(t){var r=this,n=this.hls.levels;if(!n.length)return-1;var i=n.filter((function(e,n){return r.isLevelAllowed(e)&&n<=t}));return this.clientRect=null,e.getMaxLevelByMediaSize(i,this.mediaWidth,this.mediaHeight)},t.startCapping=function(){this.timer||(this.autoLevelCapping=Number.POSITIVE_INFINITY,self.clearInterval(this.timer),this.timer=self.setInterval(this.detectPlayerSize.bind(this),1e3),this.detectPlayerSize())},t.stopCapping=function(){this.restrictedLevels=[],this.firstLevel=-1,this.autoLevelCapping=Number.POSITIVE_INFINITY,this.timer&&(self.clearInterval(this.timer),this.timer=void 0)},t.getDimensions=function(){if(this.clientRect)return this.clientRect;var e=this.media,t={width:0,height:0};if(e){var r=e.getBoundingClientRect();t.width=r.width,t.height=r.height,t.width||t.height||(t.width=r.right-r.left||e.width||0,t.height=r.bottom-r.top||e.height||0)}return this.clientRect=t,t},t.isLevelAllowed=function(e){return!this.restrictedLevels.some((function(t){return e.bitrate===t.bitrate&&e.width===t.width&&e.height===t.height}))},e.getMaxLevelByMediaSize=function(e,t,r){if(null==e||!e.length)return-1;for(var n,i,a=e.length-1,s=Math.max(t,r),o=0;o<e.length;o+=1){var l=e[o];if((l.width>=s||l.height>=s)&&(n=l,!(i=e[o+1])||n.width!==i.width||n.height!==i.height)){a=o;break}}return a},i(e,[{key:"mediaWidth",get:function(){return this.getDimensions().width*this.contentScaleFactor}},{key:"mediaHeight",get:function(){return this.getDimensions().height*this.contentScaleFactor}},{key:"contentScaleFactor",get:function(){var e=1;if(!this.hls.config.ignoreDevicePixelRatio)try{e=self.devicePixelRatio}catch(e){}return e}}]),e}(),$t=function(){function e(e){this.hls=void 0,this.isVideoPlaybackQualityAvailable=!1,this.timer=void 0,this.media=null,this.lastTime=void 0,this.lastDroppedFrames=0,this.lastDecodedFrames=0,this.streamController=void 0,this.hls=e,this.registerListeners()}var t=e.prototype;return t.setStreamController=function(e){this.streamController=e},t.registerListeners=function(){this.hls.on(E.MEDIA_ATTACHING,this.onMediaAttaching,this)},t.unregisterListeners=function(){this.hls.off(E.MEDIA_ATTACHING,this.onMediaAttaching,this)},t.destroy=function(){this.timer&&clearInterval(this.timer),this.unregisterListeners(),this.isVideoPlaybackQualityAvailable=!1,this.media=null},t.onMediaAttaching=function(e,t){var r=this.hls.config;if(r.capLevelOnFPSDrop){var n=t.media instanceof self.HTMLVideoElement?t.media:null;this.media=n,n&&"function"==typeof n.getVideoPlaybackQuality&&(this.isVideoPlaybackQualityAvailable=!0),self.clearInterval(this.timer),this.timer=self.setInterval(this.checkFPSInterval.bind(this),r.fpsDroppedMonitoringPeriod)}},t.checkFPS=function(e,t,r){var n=performance.now();if(t){if(this.lastTime){var i=n-this.lastTime,a=r-this.lastDroppedFrames,s=t-this.lastDecodedFrames,o=1e3*a/i,l=this.hls;if(l.trigger(E.FPS_DROP,{currentDropped:a,currentDecoded:s,totalDroppedFrames:r}),o>0&&a>l.config.fpsDroppedMonitoringThreshold*s){var u=l.currentLevel;R.warn("drop FPS ratio greater than max allowed value for currentLevel: "+u),u>0&&(-1===l.autoLevelCapping||l.autoLevelCapping>=u)&&(u-=1,l.trigger(E.FPS_DROP_LEVEL_CAPPING,{level:u,droppedLevel:l.currentLevel}),l.autoLevelCapping=u,this.streamController.nextLevelSwitch())}}this.lastTime=n,this.lastDroppedFrames=r,this.lastDecodedFrames=t}},t.checkFPSInterval=function(){var e=this.media;if(e)if(this.isVideoPlaybackQualityAvailable){var t=e.getVideoPlaybackQuality();this.checkFPS(e,t.totalVideoFrames,t.droppedVideoFrames)}else this.checkFPS(e,e.webkitDecodedFrameCount,e.webkitDroppedFrameCount)},e}(),er=function(){function e(e){this.hls=void 0,this.log=void 0,this.loader=null,this.uri=null,this.pathwayId=".",this.pathwayPriority=null,this.timeToLoad=300,this.reloadTimer=-1,this.updated=0,this.started=!1,this.enabled=!0,this.levels=null,this.audioTracks=null,this.subtitleTracks=null,this.penalizedPathways={},this.hls=e,this.log=R.log.bind(R,"[content-steering]:"),this.registerListeners()}var t=e.prototype;return t.registerListeners=function(){var e=this.hls;e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(E.MANIFEST_PARSED,this.onManifestParsed,this),e.on(E.ERROR,this.onError,this)},t.unregisterListeners=function(){var e=this.hls;e&&(e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(E.MANIFEST_PARSED,this.onManifestParsed,this),e.off(E.ERROR,this.onError,this))},t.startLoad=function(){if(this.started=!0,this.clearTimeout(),this.enabled&&this.uri){if(this.updated){var e=1e3*this.timeToLoad-(performance.now()-this.updated);if(e>0)return void this.scheduleRefresh(this.uri,e)}this.loadSteeringManifest(this.uri)}},t.stopLoad=function(){this.started=!1,this.loader&&(this.loader.destroy(),this.loader=null),this.clearTimeout()},t.clearTimeout=function(){-1!==this.reloadTimer&&(self.clearTimeout(this.reloadTimer),this.reloadTimer=-1)},t.destroy=function(){this.unregisterListeners(),this.stopLoad(),this.hls=null,this.levels=this.audioTracks=this.subtitleTracks=null},t.removeLevel=function(e){var t=this.levels;t&&(this.levels=t.filter((function(t){return t!==e})))},t.onManifestLoading=function(){this.stopLoad(),this.enabled=!0,this.timeToLoad=300,this.updated=0,this.uri=null,this.pathwayId=".",this.levels=this.audioTracks=this.subtitleTracks=null},t.onManifestLoaded=function(e,t){var r=t.contentSteering;null!==r&&(this.pathwayId=r.pathwayId,this.uri=r.uri,this.started&&this.startLoad())},t.onManifestParsed=function(e,t){this.audioTracks=t.audioTracks,this.subtitleTracks=t.subtitleTracks},t.onError=function(e,t){var r=t.errorAction;if(2===(null==r?void 0:r.action)&&1===r.flags){var n=this.levels,i=this.pathwayPriority,a=this.pathwayId;if(t.context){var s=t.context,o=s.groupId,l=s.pathwayId,u=s.type;o&&n?a=this.getPathwayForGroupId(o,u,a):l&&(a=l)}a in this.penalizedPathways||(this.penalizedPathways[a]=performance.now()),!i&&n&&(i=n.reduce((function(e,t){return-1===e.indexOf(t.pathwayId)&&e.push(t.pathwayId),e}),[])),i&&i.length>1&&(this.updatePathwayPriority(i),r.resolved=this.pathwayId!==a),r.resolved||R.warn("Could not resolve "+t.details+' ("'+t.error.message+'") with content-steering for Pathway: '+a+" levels: "+(n?n.length:n)+" priorities: "+JSON.stringify(i)+" penalized: "+JSON.stringify(this.penalizedPathways))}},t.filterParsedLevels=function(e){this.levels=e;var t=this.getLevelsForPathway(this.pathwayId);if(0===t.length){var r=e[0].pathwayId;this.log("No levels found in Pathway "+this.pathwayId+'. Setting initial Pathway to "'+r+'"'),t=this.getLevelsForPathway(r),this.pathwayId=r}return t.length!==e.length?(this.log("Found "+t.length+"/"+e.length+' levels in Pathway "'+this.pathwayId+'"'),t):e},t.getLevelsForPathway=function(e){return null===this.levels?[]:this.levels.filter((function(t){return e===t.pathwayId}))},t.updatePathwayPriority=function(e){var t;this.pathwayPriority=e;var r=this.penalizedPathways,n=performance.now();Object.keys(r).forEach((function(e){n-r[e]>3e5&&delete r[e]}));for(var i=0;i<e.length;i++){var a=e[i];if(!(a in r)){if(a===this.pathwayId)return;var s=this.hls.nextLoadLevel,o=this.hls.levels[s];if((t=this.getLevelsForPathway(a)).length>0){this.log('Setting Pathway to "'+a+'"'),this.pathwayId=a,Ct(t),this.hls.trigger(E.LEVELS_UPDATED,{levels:t});var l=this.hls.levels[s];o&&l&&this.levels&&(l.attrs["STABLE-VARIANT-ID"]!==o.attrs["STABLE-VARIANT-ID"]&&l.bitrate!==o.bitrate&&this.log("Unstable Pathways change from bitrate "+o.bitrate+" to "+l.bitrate),this.hls.nextLoadLevel=s);break}}}},t.getPathwayForGroupId=function(e,t,r){for(var n=this.getLevelsForPathway(r).concat(this.levels||[]),i=0;i<n.length;i++)if(t===tt&&n[i].hasAudioGroup(e)||t===rt&&n[i].hasSubtitleGroup(e))return n[i].pathwayId;return r},t.clonePathways=function(e){var t=this,r=this.levels;if(r){var n={},i={};e.forEach((function(e){var a=e.ID,s=e["BASE-ID"],o=e["URI-REPLACEMENT"];if(!r.some((function(e){return e.pathwayId===a}))){var l=t.getLevelsForPathway(s).map((function(e){var t=new C(e.attrs);t["PATHWAY-ID"]=a;var r=t.AUDIO&&t.AUDIO+"_clone_"+a,s=t.SUBTITLES&&t.SUBTITLES+"_clone_"+a;r&&(n[t.AUDIO]=r,t.AUDIO=r),s&&(i[t.SUBTITLES]=s,t.SUBTITLES=s);var l=rr(e.uri,t["STABLE-VARIANT-ID"],"PER-VARIANT-URIS",o),u=new _t({attrs:t,audioCodec:e.audioCodec,bitrate:e.bitrate,height:e.height,name:e.name,url:l,videoCodec:e.videoCodec,width:e.width});if(e.audioGroups)for(var d=1;d<e.audioGroups.length;d++)u.addGroupId("audio",e.audioGroups[d]+"_clone_"+a);if(e.subtitleGroups)for(var c=1;c<e.subtitleGroups.length;c++)u.addGroupId("text",e.subtitleGroups[c]+"_clone_"+a);return u}));r.push.apply(r,l),tr(t.audioTracks,n,o,a),tr(t.subtitleTracks,i,o,a)}}))}},t.loadSteeringManifest=function(e){var t,r=this,n=this.hls.config,i=n.loader;this.loader&&this.loader.destroy(),this.loader=new i(n);try{t=new self.URL(e)}catch(t){return this.enabled=!1,void this.log("Failed to parse Steering Manifest URI: "+e)}if("data:"!==t.protocol){var a=0|(this.hls.bandwidthEstimate||n.abrEwmaDefaultEstimate);t.searchParams.set("_HLS_pathway",this.pathwayId),t.searchParams.set("_HLS_throughput",""+a)}var s={responseType:"json",url:t.href},o=n.steeringManifestLoadPolicy.default,l=o.errorRetry||o.timeoutRetry||{},u={loadPolicy:o,timeout:o.maxLoadTimeMs,maxRetry:l.maxNumRetry||0,retryDelay:l.retryDelayMs||0,maxRetryDelay:l.maxRetryDelayMs||0},d={onSuccess:function(e,n,i,a){r.log('Loaded steering manifest: "'+t+'"');var s=e.data;if(1===s.VERSION){r.updated=performance.now(),r.timeToLoad=s.TTL;var o=s["RELOAD-URI"],l=s["PATHWAY-CLONES"],u=s["PATHWAY-PRIORITY"];if(o)try{r.uri=new self.URL(o,t).href}catch(e){return r.enabled=!1,void r.log("Failed to parse Steering Manifest RELOAD-URI: "+o)}r.scheduleRefresh(r.uri||i.url),l&&r.clonePathways(l);var d={steeringManifest:s,url:t.toString()};r.hls.trigger(E.STEERING_MANIFEST_LOADED,d),u&&r.updatePathwayPriority(u)}else r.log("Steering VERSION "+s.VERSION+" not supported!")},onError:function(e,t,n,i){if(r.log("Error loading steering manifest: "+e.code+" "+e.text+" ("+t.url+")"),r.stopLoad(),410===e.code)return r.enabled=!1,void r.log("Steering manifest "+t.url+" no longer available");var a=1e3*r.timeToLoad;if(429!==e.code)r.scheduleRefresh(r.uri||t.url,a);else{var s=r.loader;if("function"==typeof(null==s?void 0:s.getResponseHeader)){var o=s.getResponseHeader("Retry-After");o&&(a=1e3*parseFloat(o))}r.log("Steering manifest "+t.url+" rate limited")}},onTimeout:function(e,t,n){r.log("Timeout loading steering manifest ("+t.url+")"),r.scheduleRefresh(r.uri||t.url)}};this.log("Requesting steering manifest: "+t),this.loader.load(s,u,d)},t.scheduleRefresh=function(e,t){var r=this;void 0===t&&(t=1e3*this.timeToLoad),this.clearTimeout(),this.reloadTimer=self.setTimeout((function(){var t,n=null==(t=r.hls)?void 0:t.media;!n||n.ended?r.scheduleRefresh(e,1e3*r.timeToLoad):r.loadSteeringManifest(e)}),t)},e}();function tr(e,t,r,n){e&&Object.keys(t).forEach((function(i){var a=e.filter((function(e){return e.groupId===i})).map((function(e){var a=l({},e);return a.details=void 0,a.attrs=new C(a.attrs),a.url=a.attrs.URI=rr(e.url,e.attrs["STABLE-RENDITION-ID"],"PER-RENDITION-URIS",r),a.groupId=a.attrs["GROUP-ID"]=t[i],a.attrs["PATHWAY-ID"]=n,a}));e.push.apply(e,a)}))}function rr(e,t,r,n){var i,a=n.HOST,s=n.PARAMS,o=n[r];t&&(i=null==o?void 0:o[t])&&(e=i);var l=new self.URL(e);return a&&!i&&(l.host=a),s&&Object.keys(s).sort().forEach((function(e){e&&l.searchParams.set(e,s[e])})),l.href}var nr=/^age:\s*[\d.]+\s*$/im,ir=function(){function e(e){this.xhrSetup=void 0,this.requestTimeout=void 0,this.retryTimeout=void 0,this.retryDelay=void 0,this.config=null,this.callbacks=null,this.context=null,this.loader=null,this.stats=void 0,this.xhrSetup=e&&e.xhrSetup||null,this.stats=new x,this.retryDelay=0}var t=e.prototype;return t.destroy=function(){this.callbacks=null,this.abortInternal(),this.loader=null,this.config=null,this.context=null,this.xhrSetup=null},t.abortInternal=function(){var e=this.loader;self.clearTimeout(this.requestTimeout),self.clearTimeout(this.retryTimeout),e&&(e.onreadystatechange=null,e.onprogress=null,4!==e.readyState&&(this.stats.aborted=!0,e.abort()))},t.abort=function(){var e;this.abortInternal(),null!=(e=this.callbacks)&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.loader)},t.load=function(e,t,r){if(this.stats.loading.start)throw new Error("Loader can only be used once.");this.stats.loading.start=self.performance.now(),this.context=e,this.config=t,this.callbacks=r,this.loadInternal()},t.loadInternal=function(){var e=this,t=this.config,r=this.context;if(t&&r){var n=this.loader=new self.XMLHttpRequest,i=this.stats;i.loading.first=0,i.loaded=0,i.aborted=!1;var a=this.xhrSetup;a?Promise.resolve().then((function(){if(e.loader===n&&!e.stats.aborted)return a(n,r.url)})).catch((function(t){if(e.loader===n&&!e.stats.aborted)return n.open("GET",r.url,!0),a(n,r.url)})).then((function(){e.loader!==n||e.stats.aborted||e.openAndSendXhr(n,r,t)})).catch((function(t){e.callbacks.onError({code:n.status,text:t.message},r,n,i)})):this.openAndSendXhr(n,r,t)}},t.openAndSendXhr=function(e,t,r){e.readyState||e.open("GET",t.url,!0);var n=t.headers,i=r.loadPolicy,a=i.maxTimeToFirstByteMs,s=i.maxLoadTimeMs;if(n)for(var o in n)e.setRequestHeader(o,n[o]);t.rangeEnd&&e.setRequestHeader("Range","bytes="+t.rangeStart+"-"+(t.rangeEnd-1)),e.onreadystatechange=this.readystatechange.bind(this),e.onprogress=this.loadprogress.bind(this),e.responseType=t.responseType,self.clearTimeout(this.requestTimeout),r.timeout=a&&m(a)?a:s,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),r.timeout),e.send()},t.readystatechange=function(){var e=this.context,t=this.loader,r=this.stats;if(e&&t){var n=t.readyState,i=this.config;if(!r.aborted&&n>=2&&(0===r.loading.first&&(r.loading.first=Math.max(self.performance.now(),r.loading.start),i.timeout!==i.loadPolicy.maxLoadTimeMs&&(self.clearTimeout(this.requestTimeout),i.timeout=i.loadPolicy.maxLoadTimeMs,this.requestTimeout=self.setTimeout(this.loadtimeout.bind(this),i.loadPolicy.maxLoadTimeMs-(r.loading.first-r.loading.start)))),4===n)){self.clearTimeout(this.requestTimeout),t.onreadystatechange=null,t.onprogress=null;var a=t.status,s="text"!==t.responseType;if(a>=200&&a<300&&(s&&t.response||null!==t.responseText)){r.loading.end=Math.max(self.performance.now(),r.loading.first);var o=s?t.response:t.responseText,l="arraybuffer"===t.responseType?o.byteLength:o.length;if(r.loaded=r.total=l,r.bwEstimate=8e3*r.total/(r.loading.end-r.loading.first),!this.callbacks)return;var u=this.callbacks.onProgress;if(u&&u(r,e,o,t),!this.callbacks)return;var d={url:t.responseURL,data:o,code:a};this.callbacks.onSuccess(d,r,e,t)}else{var c=i.loadPolicy.errorRetry;Mt(c,r.retry,!1,{url:e.url,data:void 0,code:a})?this.retry(c):(R.error(a+" while loading "+e.url),this.callbacks.onError({code:a,text:t.statusText},e,t,r))}}}},t.loadtimeout=function(){if(this.config){var e=this.config.loadPolicy.timeoutRetry;if(Mt(e,this.stats.retry,!0))this.retry(e);else{var t;R.warn("timeout while loading "+(null==(t=this.context)?void 0:t.url));var r=this.callbacks;r&&(this.abortInternal(),r.onTimeout(this.stats,this.context,this.loader))}}},t.retry=function(e){var t=this.context,r=this.stats;this.retryDelay=xt(e,r.retry),r.retry++,R.warn((status?"HTTP Status "+status:"Timeout")+" while loading "+(null==t?void 0:t.url)+", retrying "+r.retry+"/"+e.maxNumRetry+" in "+this.retryDelay+"ms"),this.abortInternal(),this.loader=null,self.clearTimeout(this.retryTimeout),this.retryTimeout=self.setTimeout(this.loadInternal.bind(this),this.retryDelay)},t.loadprogress=function(e){var t=this.stats;t.loaded=e.loaded,e.lengthComputable&&(t.total=e.total)},t.getCacheAge=function(){var e=null;if(this.loader&&nr.test(this.loader.getAllResponseHeaders())){var t=this.loader.getResponseHeader("age");e=t?parseFloat(t):null}return e},t.getResponseHeader=function(e){return this.loader&&new RegExp("^"+e+":\\s*[\\d.]+\\s*$","im").test(this.loader.getAllResponseHeaders())?this.loader.getResponseHeader(e):null},e}(),ar=function(){function e(){this.chunks=[],this.dataLength=0}var t=e.prototype;return t.push=function(e){this.chunks.push(e),this.dataLength+=e.length},t.flush=function(){var e,t=this.chunks,r=this.dataLength;return t.length?(e=1===t.length?t[0]:function(e,t){for(var r=new Uint8Array(t),n=0,i=0;i<e.length;i++){var a=e[i];r.set(a,n),n+=a.length}return r}(t,r),this.reset(),e):new Uint8Array(0)},t.reset=function(){this.chunks.length=0,this.dataLength=0},e}(),sr=/(\d+)-(\d+)\/(\d+)/,or=function(){function e(e){this.fetchSetup=void 0,this.requestTimeout=void 0,this.request=null,this.response=null,this.controller=void 0,this.context=null,this.config=null,this.callbacks=null,this.stats=void 0,this.loader=null,this.fetchSetup=e.fetchSetup||lr,this.controller=new self.AbortController,this.stats=new x}var t=e.prototype;return t.destroy=function(){this.loader=this.callbacks=this.context=this.config=this.request=null,this.abortInternal(),this.response=null,this.fetchSetup=this.controller=this.stats=null},t.abortInternal=function(){this.controller&&!this.stats.loading.end&&(this.stats.aborted=!0,this.controller.abort())},t.abort=function(){var e;this.abortInternal(),null!=(e=this.callbacks)&&e.onAbort&&this.callbacks.onAbort(this.stats,this.context,this.response)},t.load=function(e,t,r){var n=this,i=this.stats;if(i.loading.start)throw new Error("Loader can only be used once.");i.loading.start=self.performance.now();var a=function(e,t){var r={method:"GET",mode:"cors",credentials:"same-origin",signal:t,headers:new self.Headers(l({},e.headers))};return e.rangeEnd&&r.headers.set("Range","bytes="+e.rangeStart+"-"+String(e.rangeEnd-1)),r}(e,this.controller.signal),s=r.onProgress,o="arraybuffer"===e.responseType,u=o?"byteLength":"length",d=t.loadPolicy,c=d.maxTimeToFirstByteMs,f=d.maxLoadTimeMs;this.context=e,this.config=t,this.callbacks=r,this.request=this.fetchSetup(e,a),self.clearTimeout(this.requestTimeout),t.timeout=c&&m(c)?c:f,this.requestTimeout=self.setTimeout((function(){n.abortInternal(),r.onTimeout(i,e,n.response)}),t.timeout),self.fetch(this.request).then((function(a){n.response=n.loader=a;var l=Math.max(self.performance.now(),i.loading.start);if(self.clearTimeout(n.requestTimeout),t.timeout=f,n.requestTimeout=self.setTimeout((function(){n.abortInternal(),r.onTimeout(i,e,n.response)}),f-(l-i.loading.start)),!a.ok){var u=a.status,d=a.statusText;throw new dr(d||"fetch, bad network response",u,a)}return i.loading.first=l,i.total=function(e){var t=e.get("Content-Range");if(t){var r=function(e){var t=sr.exec(e);if(t)return parseInt(t[2])-parseInt(t[1])+1}(t);if(m(r))return r}var n=e.get("Content-Length");if(n)return parseInt(n)}(a.headers)||i.total,s&&m(t.highWaterMark)?n.loadProgressively(a,i,e,t.highWaterMark,s):o?a.arrayBuffer():"json"===e.responseType?a.json():a.text()})).then((function(a){var o=n.response;if(!o)throw new Error("loader destroyed");self.clearTimeout(n.requestTimeout),i.loading.end=Math.max(self.performance.now(),i.loading.first);var l=a[u];l&&(i.loaded=i.total=l);var d={url:o.url,data:a,code:o.status};s&&!m(t.highWaterMark)&&s(i,e,a,o),r.onSuccess(d,i,e,o)})).catch((function(t){if(self.clearTimeout(n.requestTimeout),!i.aborted){var a=t&&t.code||0,s=t?t.message:null;r.onError({code:a,text:s},e,t?t.details:null,i)}}))},t.getCacheAge=function(){var e=null;if(this.response){var t=this.response.headers.get("age");e=t?parseFloat(t):null}return e},t.getResponseHeader=function(e){return this.response?this.response.headers.get(e):null},t.loadProgressively=function(e,t,r,n,i){void 0===n&&(n=0);var a=new ar,s=e.body.getReader();return function o(){return s.read().then((function(s){if(s.done)return a.dataLength&&i(t,r,a.flush(),e),Promise.resolve(new ArrayBuffer(0));var l=s.value,u=l.length;return t.loaded+=u,u<n||a.dataLength?(a.push(l),a.dataLength>=n&&i(t,r,a.flush(),e)):i(t,r,l,e),o()})).catch((function(){return Promise.reject()}))}()},e}();function lr(e,t){return new self.Request(e.url,t)}var ur,dr=function(e){function t(t,r,n){var i;return(i=e.call(this,t)||this).code=void 0,i.details=void 0,i.code=r,i.details=n,i}return u(t,e),t}(h(Error)),cr=t(t({autoStartLoad:!0,startPosition:-1,defaultAudioCodec:void 0,debug:!1,capLevelOnFPSDrop:!1,capLevelToPlayerSize:!1,ignoreDevicePixelRatio:!1,preferManagedMediaSource:!0,initialLiveManifestSize:1,maxBufferLength:30,backBufferLength:1/0,frontBufferFlushThreshold:1/0,maxBufferSize:6e7,maxBufferHole:.1,highBufferWatchdogPeriod:2,nudgeOffset:.1,nudgeMaxRetry:3,maxFragLookUpTolerance:.25,liveSyncDurationCount:3,liveMaxLatencyDurationCount:1/0,liveSyncDuration:void 0,liveMaxLatencyDuration:void 0,maxLiveSyncPlaybackRate:1,liveDurationInfinity:!1,liveBackBufferLength:null,maxMaxBufferLength:600,enableWorker:!0,workerPath:null,enableSoftwareAES:!0,startLevel:void 0,startFragPrefetch:!1,fpsDroppedMonitoringPeriod:5e3,fpsDroppedMonitoringThreshold:.2,appendErrorMaxRetry:3,loader:ir,fLoader:void 0,pLoader:void 0,xhrSetup:void 0,licenseXhrSetup:void 0,licenseResponseCallback:void 0,abrController:Wt,bufferController:Jt,capLevelController:Zt,errorController:Gt,fpsController:$t,stretchShortVideoTrack:!1,maxAudioFramesDrift:1,forceKeyFrameOnDiscontinuity:!0,abrEwmaFastLive:3,abrEwmaSlowLive:9,abrEwmaFastVoD:3,abrEwmaSlowVoD:9,abrEwmaDefaultEstimate:5e5,abrEwmaDefaultEstimateMax:5e6,abrBandWidthFactor:.95,abrBandWidthUpFactor:.7,abrMaxWithRealBitrate:!1,maxStarvationDelay:4,maxLoadingDelay:4,minAutoBitrate:0,emeEnabled:!1,widevineLicenseUrl:void 0,drmSystems:{},drmSystemOptions:{},requestMediaKeySystemAccessFunc:null,testBandwidth:!0,progressive:!1,lowLatencyMode:!0,cmcd:void 0,enableDateRangeMetadataCues:!0,enableEmsgMetadataCues:!0,enableID3MetadataCues:!0,useMediaCapabilities:!1,certLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:null,errorRetry:null}},keyLoadPolicy:{default:{maxTimeToFirstByteMs:8e3,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"},errorRetry:{maxNumRetry:8,retryDelayMs:1e3,maxRetryDelayMs:2e4,backoff:"linear"}}},manifestLoadPolicy:{default:{maxTimeToFirstByteMs:1/0,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},playlistLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:2,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},fragLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:12e4,timeoutRetry:{maxNumRetry:4,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:6,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},steeringManifestLoadPolicy:{default:{maxTimeToFirstByteMs:1e4,maxLoadTimeMs:2e4,timeoutRetry:{maxNumRetry:2,retryDelayMs:0,maxRetryDelayMs:0},errorRetry:{maxNumRetry:1,retryDelayMs:1e3,maxRetryDelayMs:8e3}}},manifestLoadingTimeOut:1e4,manifestLoadingMaxRetry:1,manifestLoadingRetryDelay:1e3,manifestLoadingMaxRetryTimeout:64e3,levelLoadingTimeOut:1e4,levelLoadingMaxRetry:4,levelLoadingRetryDelay:1e3,levelLoadingMaxRetryTimeout:64e3,fragLoadingTimeOut:2e4,fragLoadingMaxRetry:6,fragLoadingRetryDelay:1e3,fragLoadingMaxRetryTimeout:64e3},{cueHandler:j,enableWebVTT:!1,enableIMSC1:!1,enableCEA708Captions:!1,captionsTextTrack1Label:"English",captionsTextTrack1LanguageCode:"en",captionsTextTrack2Label:"Spanish",captionsTextTrack2LanguageCode:"es",captionsTextTrack3Label:"Unknown CC",captionsTextTrack3LanguageCode:"",captionsTextTrack4Label:"Unknown CC",captionsTextTrack4LanguageCode:"",renderTextTracksNatively:!0}),{},{subtitleStreamController:void 0,subtitleTrackController:void 0,timelineController:void 0,audioStreamController:void 0,audioTrackController:void 0,emeController:void 0,cmcdController:void 0,contentSteeringController:er});function fr(e){return e&&"object"==(void 0===e?"undefined":a(e))?Array.isArray(e)?e.map(fr):Object.keys(e).reduce((function(t,r){return t[r]=fr(e[r]),t}),{}):e}var hr=function(e){function t(t,r){var n;return(n=e.call(this,t,"[level-controller]")||this)._levels=[],n._firstLevel=-1,n._maxAutoLevel=-1,n._startLevel=void 0,n.currentLevel=null,n.currentLevelIndex=-1,n.manualLevelIndex=-1,n.steering=void 0,n.onParsedComplete=void 0,n.steering=r,n._registerListeners(),n}u(t,e);var r=t.prototype;return r._registerListeners=function(){var e=this.hls;e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.MANIFEST_LOADED,this.onManifestLoaded,this),e.on(E.LEVEL_LOADED,this.onLevelLoaded,this),e.on(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(E.FRAG_BUFFERED,this.onFragBuffered,this),e.on(E.ERROR,this.onError,this)},r._unregisterListeners=function(){var e=this.hls;e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.MANIFEST_LOADED,this.onManifestLoaded,this),e.off(E.LEVEL_LOADED,this.onLevelLoaded,this),e.off(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(E.FRAG_BUFFERED,this.onFragBuffered,this),e.off(E.ERROR,this.onError,this)},r.destroy=function(){this._unregisterListeners(),this.steering=null,this.resetLevels(),e.prototype.destroy.call(this)},r.stopLoad=function(){this._levels.forEach((function(e){e.loadError=0,e.fragmentError=0})),e.prototype.stopLoad.call(this)},r.resetLevels=function(){this._startLevel=void 0,this.manualLevelIndex=-1,this.currentLevelIndex=-1,this.currentLevel=null,this._levels=[],this._maxAutoLevel=-1},r.onManifestLoading=function(e,t){this.resetLevels()},r.onManifestLoaded=function(e,t){var r=this.hls.config.preferManagedMediaSource,n=[],i={},a={},s=!1,o=!1,l=!1;t.levels.forEach((function(e){var t,u,d=e.attrs,c=e.audioCodec,f=e.videoCodec;-1!==(null==(t=c)?void 0:t.indexOf("mp4a.40.34"))&&(ur||(ur=/chrome|firefox/i.test(navigator.userAgent)),ur&&(e.audioCodec=c=void 0)),c&&(e.audioCodec=c=Be(c,r)),0===(null==(u=f)?void 0:u.indexOf("avc1"))&&(f=e.videoCodec=function(e){var t=e.split(".");if(t.length>2){var r=t.shift()+".";return(r+=parseInt(t.shift()).toString(16))+("000"+parseInt(t.shift()).toString(16)).slice(-4)}return e}(f));var h=e.width,g=e.height,v=e.unknownCodecs;if(s||(s=!(!h||!g)),o||(o=!!f),l||(l=!!c),!(null!=v&&v.length||c&&!De(c,"audio",r)||f&&!De(f,"video",r))){var p=d.CODECS,m=d["FRAME-RATE"],y=d["HDCP-LEVEL"],b=d["PATHWAY-ID"],E=d.RESOLUTION,S=d["VIDEO-RANGE"],_=(b||".")+"-"+e.bitrate+"-"+E+"-"+m+"-"+p+"-"+S+"-"+y;if(i[_])if(i[_].uri===e.url||e.attrs["PATHWAY-ID"])i[_].addGroupId("audio",d.AUDIO),i[_].addGroupId("text",d.SUBTITLES);else{var T=a[_]+=1;e.attrs["PATHWAY-ID"]=new Array(T+1).join(".");var L=new _t(e);i[_]=L,n.push(L)}else{var P=new _t(e);i[_]=P,a[_]=1,n.push(P)}}})),this.filterAndSortMediaOptions(n,t,s,o,l)},r.filterAndSortMediaOptions=function(e,t,r,n,i){var a=this,s=[],o=[],l=e;if((r||n)&&i&&(l=l.filter((function(e){var t,r=e.videoCodec,n=e.videoRange,i=e.width,a=e.height;return(!!r||!(!i||!a))&&!!(t=n)&&bt.indexOf(t)>-1}))),0!==l.length){if(t.audioTracks){var u=this.hls.config.preferManagedMediaSource;gr(s=t.audioTracks.filter((function(e){return!e.audioCodec||De(e.audioCodec,"audio",u)})))}t.subtitles&&gr(o=t.subtitles);var d=l.slice(0);l.sort((function(e,t){if(e.attrs["HDCP-LEVEL"]!==t.attrs["HDCP-LEVEL"])return(e.attrs["HDCP-LEVEL"]||"")>(t.attrs["HDCP-LEVEL"]||"")?1:-1;if(r&&e.height!==t.height)return e.height-t.height;if(e.frameRate!==t.frameRate)return e.frameRate-t.frameRate;if(e.videoRange!==t.videoRange)return bt.indexOf(e.videoRange)-bt.indexOf(t.videoRange);if(e.videoCodec!==t.videoCodec){var n=Oe(e.videoCodec),i=Oe(t.videoCodec);if(n!==i)return i-n}if(e.uri===t.uri&&e.codecSet!==t.codecSet){var a=Me(e.codecSet),s=Me(t.codecSet);if(a!==s)return s-a}return e.averageBitrate!==t.averageBitrate?e.averageBitrate-t.averageBitrate:0}));var c=d[0];if(this.steering&&(l=this.steering.filterParsedLevels(l)).length!==d.length)for(var f=0;f<d.length;f++)if(d[f].pathwayId===l[0].pathwayId){c=d[f];break}this._levels=l;for(var h=0;h<l.length;h++)if(l[h]===c){var g;this._firstLevel=h;var v=c.bitrate,p=this.hls.bandwidthEstimate;if(this.log("manifest loaded, "+l.length+" level(s) found, first bitrate: "+v),void 0===(null==(g=this.hls.userConfig)?void 0:g.abrEwmaDefaultEstimate)){var m=Math.min(v,this.hls.config.abrEwmaDefaultEstimateMax);m>p&&p===cr.abrEwmaDefaultEstimate&&(this.hls.bandwidthEstimate=m)}break}var y=i&&!n,b={levels:l,audioTracks:s,subtitleTracks:o,sessionData:t.sessionData,sessionKeys:t.sessionKeys,firstLevel:this._firstLevel,stats:t.stats,audio:i,video:n,altAudio:!y&&s.some((function(e){return!!e.url}))};this.hls.trigger(E.MANIFEST_PARSED,b),(this.hls.config.autoStartLoad||this.hls.forceStartLoad)&&this.hls.startLoad(this.hls.config.startPosition)}else Promise.resolve().then((function(){if(a.hls){t.levels.length&&a.warn("One or more CODECS in variant not supported: "+JSON.stringify(t.levels[0].attrs));var e=new Error("no level with compatible codecs found in manifest");a.hls.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.MANIFEST_INCOMPATIBLE_CODECS_ERROR,fatal:!0,url:t.url,error:e,reason:e.message})}}))},r.onError=function(e,t){!t.fatal&&t.context&&t.context.type===et&&t.context.level===this.level&&this.checkRetry(t)},r.onFragBuffered=function(e,t){var r=t.frag;if(void 0!==r&&r.type===nt){var n=r.elementaryStreams;if(!Object.keys(n).some((function(e){return!!n[e]})))return;var i=this._levels[r.level];null!=i&&i.loadError&&(this.log("Resetting level error count of "+i.loadError+" on frag buffered"),i.loadError=0)}},r.onLevelLoaded=function(e,t){var r,n,i=t.level,a=t.details,s=this._levels[i];if(!s)return this.warn("Invalid level index "+i),void(null!=(n=t.deliveryDirectives)&&n.skip&&(a.deltaUpdateFailed=!0));i===this.currentLevelIndex?(0===s.fragmentError&&(s.loadError=0),this.playlistLoaded(i,t,s.details)):null!=(r=t.deliveryDirectives)&&r.skip&&(a.deltaUpdateFailed=!0)},r.loadPlaylist=function(t){e.prototype.loadPlaylist.call(this);var r=this.currentLevelIndex,n=this.currentLevel;if(n&&this.shouldLoadPlaylist(n)){var i=n.uri;if(t)try{i=t.addDirectives(i)}catch(e){this.warn("Could not construct new URL with HLS Delivery Directives: "+e)}var a=n.attrs["PATHWAY-ID"];this.log("Loading level index "+r+(void 0!==(null==t?void 0:t.msn)?" at sn "+t.msn+" part "+t.part:"")+" with"+(a?" Pathway "+a:"")+" "+i),this.clearTimer(),this.hls.trigger(E.LEVEL_LOADING,{url:i,level:r,pathwayId:n.attrs["PATHWAY-ID"],id:0,deliveryDirectives:t||null})}},r.removeLevel=function(e){var t,r=this,n=this._levels.filter((function(t,n){return n!==e||(r.steering&&r.steering.removeLevel(t),t===r.currentLevel&&(r.currentLevel=null,r.currentLevelIndex=-1,t.details&&t.details.fragments.forEach((function(e){return e.level=-1}))),!1)}));Ct(n),this._levels=n,this.currentLevelIndex>-1&&null!=(t=this.currentLevel)&&t.details&&(this.currentLevelIndex=this.currentLevel.details.fragments[0].level),this.hls.trigger(E.LEVELS_UPDATED,{levels:n})},r.onLevelsUpdated=function(e,t){var r=t.levels;this._levels=r},r.checkMaxAutoUpdated=function(){var e=this.hls,t=e.autoLevelCapping,r=e.maxAutoLevel,n=e.maxHdcpLevel;this._maxAutoLevel!==r&&(this._maxAutoLevel=r,this.hls.trigger(E.MAX_AUTO_LEVEL_UPDATED,{autoLevelCapping:t,levels:this.levels,maxAutoLevel:r,minAutoLevel:this.hls.minAutoLevel,maxHdcpLevel:n}))},i(t,[{key:"levels",get:function(){return 0===this._levels.length?null:this._levels}},{key:"level",get:function(){return this.currentLevelIndex},set:function(e){var t=this._levels;if(0!==t.length){if(e<0||e>=t.length){var r=new Error("invalid level idx"),n=e<0;if(this.hls.trigger(E.ERROR,{type:S.OTHER_ERROR,details:_.LEVEL_SWITCH_ERROR,level:e,fatal:n,error:r,reason:r.message}),n)return;e=Math.min(e,t.length-1)}var i=this.currentLevelIndex,a=this.currentLevel,s=a?a.attrs["PATHWAY-ID"]:void 0,o=t[e],l=o.attrs["PATHWAY-ID"];if(this.currentLevelIndex=e,this.currentLevel=o,i!==e||!o.details||!a||s!==l){this.log("Switching to level "+e+" ("+(o.height?o.height+"p ":"")+(o.videoRange?o.videoRange+" ":"")+(o.codecSet?o.codecSet+" ":"")+"@"+o.bitrate+")"+(l?" with Pathway "+l:"")+" from level "+i+(s?" with Pathway "+s:""));var u={level:e,attrs:o.attrs,details:o.details,bitrate:o.bitrate,averageBitrate:o.averageBitrate,maxBitrate:o.maxBitrate,realBitrate:o.realBitrate,width:o.width,height:o.height,codecSet:o.codecSet,audioCodec:o.audioCodec,videoCodec:o.videoCodec,audioGroups:o.audioGroups,subtitleGroups:o.subtitleGroups,loaded:o.loaded,loadError:o.loadError,fragmentError:o.fragmentError,name:o.name,id:o.id,uri:o.uri,url:o.url,urlId:0,audioGroupIds:o.audioGroupIds,textGroupIds:o.textGroupIds};this.hls.trigger(E.LEVEL_SWITCHING,u);var d=o.details;if(!d||d.live){var c=this.switchParams(o.uri,null==a?void 0:a.details,d);this.loadPlaylist(c)}}}}},{key:"manualLevel",get:function(){return this.manualLevelIndex},set:function(e){this.manualLevelIndex=e,void 0===this._startLevel&&(this._startLevel=e),-1!==e&&(this.level=e)}},{key:"firstLevel",get:function(){return this._firstLevel},set:function(e){this._firstLevel=e}},{key:"startLevel",get:function(){if(void 0===this._startLevel){var e=this.hls.config.startLevel;return void 0!==e?e:this.hls.firstAutoLevel}return this._startLevel},set:function(e){this._startLevel=e}},{key:"nextLoadLevel",get:function(){return-1!==this.manualLevelIndex?this.manualLevelIndex:this.hls.nextAutoLevel},set:function(e){this.level=e,-1===this.manualLevelIndex&&(this.hls.nextAutoLevel=e)}}]),t}(jt);function gr(e){var t={};e.forEach((function(e){var r=e.groupId||"";e.id=t[r]=t[r]||0,t[r]++}))}var vr="NOT_LOADED",pr="APPENDING",mr="PARTIAL",yr="OK",br=function(){function e(e){this.activePartLists=Object.create(null),this.endListFragments=Object.create(null),this.fragments=Object.create(null),this.timeRanges=Object.create(null),this.bufferPadding=.2,this.hls=void 0,this.hasGaps=!1,this.hls=e,this._registerListeners()}var t=e.prototype;return t._registerListeners=function(){var e=this.hls;e.on(E.BUFFER_APPENDED,this.onBufferAppended,this),e.on(E.FRAG_BUFFERED,this.onFragBuffered,this),e.on(E.FRAG_LOADED,this.onFragLoaded,this)},t._unregisterListeners=function(){var e=this.hls;e.off(E.BUFFER_APPENDED,this.onBufferAppended,this),e.off(E.FRAG_BUFFERED,this.onFragBuffered,this),e.off(E.FRAG_LOADED,this.onFragLoaded,this)},t.destroy=function(){this._unregisterListeners(),this.fragments=this.activePartLists=this.endListFragments=this.timeRanges=null},t.getAppendedFrag=function(e,t){var r=this.activePartLists[t];if(r)for(var n=r.length;n--;){var i=r[n];if(!i)break;var a=i.end;if(i.start<=e&&null!==a&&e<=a)return i}return this.getBufferedFrag(e,t)},t.getBufferedFrag=function(e,t){for(var r=this.fragments,n=Object.keys(r),i=n.length;i--;){var a=r[n[i]];if((null==a?void 0:a.body.type)===t&&a.buffered){var s=a.body;if(s.start<=e&&e<=s.end)return s}}return null},t.detectEvictedFragments=function(e,t,r,n){var i=this;this.timeRanges&&(this.timeRanges[e]=t);var a=(null==n?void 0:n.fragment.sn)||-1;Object.keys(this.fragments).forEach((function(n){var s=i.fragments[n];if(s&&!(a>=s.body.sn))if(s.buffered||s.loaded){var o=s.range[e];o&&o.time.some((function(e){var r=!i.isTimeBuffered(e.startPTS,e.endPTS,t);return r&&i.removeFragment(s.body),r}))}else s.body.type===r&&i.removeFragment(s.body)}))},t.detectPartialFragments=function(e){var t=this,r=this.timeRanges,n=e.frag,i=e.part;if(r&&"initSegment"!==n.sn){var a=Sr(n),s=this.fragments[a];if(!(!s||s.buffered&&n.gap)){var o=!n.relurl;Object.keys(r).forEach((function(e){var a=n.elementaryStreams[e];if(a){var l=r[e],u=o||!0===a.partial;s.range[e]=t.getBufferedTimes(n,i,u,l)}})),s.loaded=null,Object.keys(s.range).length?(s.buffered=!0,(s.body.endList=n.endList||s.body.endList)&&(this.endListFragments[s.body.type]=s),Er(s)||this.removeParts(n.sn-1,n.type)):this.removeFragment(s.body)}}},t.removeParts=function(e,t){var r=this.activePartLists[t];r&&(this.activePartLists[t]=r.filter((function(t){return t.fragment.sn>=e})))},t.fragBuffered=function(e,t){var r=Sr(e),n=this.fragments[r];!n&&t&&(n=this.fragments[r]={body:e,appendedPTS:null,loaded:null,buffered:!1,range:Object.create(null)},e.gap&&(this.hasGaps=!0)),n&&(n.loaded=null,n.buffered=!0)},t.getBufferedTimes=function(e,t,r,n){for(var i={time:[],partial:r},a=e.start,s=e.end,o=e.minEndPTS||s,l=e.maxStartPTS||a,u=0;u<n.length;u++){var d=n.start(u)-this.bufferPadding,c=n.end(u)+this.bufferPadding;if(l>=d&&o<=c){i.time.push({startPTS:Math.max(a,n.start(u)),endPTS:Math.min(s,n.end(u))});break}if(a<c&&s>d){var f=Math.max(a,n.start(u)),h=Math.min(s,n.end(u));h>f&&(i.partial=!0,i.time.push({startPTS:f,endPTS:h}))}else if(s<=d)break}return i},t.getPartialFragment=function(e){var t,r,n,i=null,a=0,s=this.bufferPadding,o=this.fragments;return Object.keys(o).forEach((function(l){var u=o[l];u&&Er(u)&&(r=u.body.start-s,n=u.body.end+s,e>=r&&e<=n&&(t=Math.min(e-r,n-e),a<=t&&(i=u.body,a=t)))})),i},t.isEndListAppended=function(e){var t=this.endListFragments[e];return void 0!==t&&(t.buffered||Er(t))},t.getState=function(e){var t=Sr(e),r=this.fragments[t];return r?r.buffered?Er(r)?mr:yr:pr:vr},t.isTimeBuffered=function(e,t,r){for(var n,i,a=0;a<r.length;a++){if(n=r.start(a)-this.bufferPadding,i=r.end(a)+this.bufferPadding,e>=n&&t<=i)return!0;if(t<=n)return!1}return!1},t.onFragLoaded=function(e,t){var r=t.frag,n=t.part;if("initSegment"!==r.sn&&!r.bitrateTest){var i=n?null:t,a=Sr(r);this.fragments[a]={body:r,appendedPTS:null,loaded:i,buffered:!1,range:Object.create(null)}}},t.onBufferAppended=function(e,t){var r=this,n=t.frag,i=t.part,a=t.timeRanges;if("initSegment"!==n.sn){var s=n.type;if(i){var o=this.activePartLists[s];o||(this.activePartLists[s]=o=[]),o.push(i)}this.timeRanges=a,Object.keys(a).forEach((function(e){var t=a[e];r.detectEvictedFragments(e,t,s,i)}))}},t.onFragBuffered=function(e,t){this.detectPartialFragments(t)},t.hasFragment=function(e){var t=Sr(e);return!!this.fragments[t]},t.hasParts=function(e){var t;return!(null==(t=this.activePartLists[e])||!t.length)},t.removeFragmentsInRange=function(e,t,r,n,i){var a=this;n&&!this.hasGaps||Object.keys(this.fragments).forEach((function(s){var o=a.fragments[s];if(o){var l=o.body;l.type!==r||n&&!l.gap||l.start<t&&l.end>e&&(o.buffered||i)&&a.removeFragment(l)}}))},t.removeFragment=function(e){var t=Sr(e);e.stats.loaded=0,e.clearElementaryStreamInfo();var r=this.activePartLists[e.type];if(r){var n=e.sn;this.activePartLists[e.type]=r.filter((function(e){return e.fragment.sn!==n}))}delete this.fragments[t],e.endList&&delete this.endListFragments[e.type]},t.removeAllFragments=function(){this.fragments=Object.create(null),this.endListFragments=Object.create(null),this.activePartLists=Object.create(null),this.hasGaps=!1},e}();function Er(e){var t,r,n;return e.buffered&&(e.body.gap||(null==(t=e.range.video)?void 0:t.partial)||(null==(r=e.range.audio)?void 0:r.partial)||(null==(n=e.range.audiovideo)?void 0:n.partial))}function Sr(e){return e.type+"_"+e.level+"_"+e.sn}var _r=Math.pow(2,17),Tr=function(){function e(e){this.config=void 0,this.loader=null,this.partLoadTimeout=-1,this.config=e}var r=e.prototype;return r.destroy=function(){this.loader&&(this.loader.destroy(),this.loader=null)},r.abort=function(){this.loader&&this.loader.abort()},r.load=function(e,r){var n=this,i=e.url;if(!i)return Promise.reject(new wr({type:S.NETWORK_ERROR,details:_.FRAG_LOAD_ERROR,fatal:!1,frag:e,error:new Error("Fragment does not have a "+(i?"part list":"url")),networkDetails:null}));this.abort();var a=this.config,s=a.fLoader,o=a.loader;return new Promise((function(l,u){if(n.loader&&n.loader.destroy(),e.gap){if(e.tagList.some((function(e){return"GAP"===e[0]})))return void u(Pr(e));e.gap=!1}var d=n.loader=e.loader=s?new s(a):new o(a),c=Lr(e),f=Ot(a.fragLoadPolicy.default),h={loadPolicy:f,timeout:f.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:"initSegment"===e.sn?1/0:_r};e.stats=d.stats,d.load(c,h,{onSuccess:function(t,r,i,a){n.resetLoader(e,d);var s=t.data;i.resetIV&&e.decryptdata&&(e.decryptdata.iv=new Uint8Array(s.slice(0,16)),s=s.slice(16)),l({frag:e,part:null,payload:s,networkDetails:a})},onError:function(r,a,s,o){n.resetLoader(e,d),u(new wr({type:S.NETWORK_ERROR,details:_.FRAG_LOAD_ERROR,fatal:!1,frag:e,response:t({url:i,data:void 0},r),error:new Error("HTTP Error "+r.code+" "+r.text),networkDetails:s,stats:o}))},onAbort:function(t,r,i){n.resetLoader(e,d),u(new wr({type:S.NETWORK_ERROR,details:_.INTERNAL_ABORTED,fatal:!1,frag:e,error:new Error("Aborted"),networkDetails:i,stats:t}))},onTimeout:function(t,r,i){n.resetLoader(e,d),u(new wr({type:S.NETWORK_ERROR,details:_.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,error:new Error("Timeout after "+h.timeout+"ms"),networkDetails:i,stats:t}))},onProgress:function(t,n,i,a){r&&r({frag:e,part:null,payload:i,networkDetails:a})}})}))},r.loadPart=function(e,r,n){var i=this;this.abort();var a=this.config,s=a.fLoader,o=a.loader;return new Promise((function(l,u){if(i.loader&&i.loader.destroy(),e.gap||r.gap)u(Pr(e,r));else{var d=i.loader=e.loader=s?new s(a):new o(a),c=Lr(e,r),f=Ot(a.fragLoadPolicy.default),h={loadPolicy:f,timeout:f.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0,highWaterMark:_r};r.stats=d.stats,d.load(c,h,{onSuccess:function(t,a,s,o){i.resetLoader(e,d),i.updateStatsFromPart(e,r);var u={frag:e,part:r,payload:t.data,networkDetails:o};n(u),l(u)},onError:function(n,a,s,o){i.resetLoader(e,d),u(new wr({type:S.NETWORK_ERROR,details:_.FRAG_LOAD_ERROR,fatal:!1,frag:e,part:r,response:t({url:c.url,data:void 0},n),error:new Error("HTTP Error "+n.code+" "+n.text),networkDetails:s,stats:o}))},onAbort:function(t,n,a){e.stats.aborted=r.stats.aborted,i.resetLoader(e,d),u(new wr({type:S.NETWORK_ERROR,details:_.INTERNAL_ABORTED,fatal:!1,frag:e,part:r,error:new Error("Aborted"),networkDetails:a,stats:t}))},onTimeout:function(t,n,a){i.resetLoader(e,d),u(new wr({type:S.NETWORK_ERROR,details:_.FRAG_LOAD_TIMEOUT,fatal:!1,frag:e,part:r,error:new Error("Timeout after "+h.timeout+"ms"),networkDetails:a,stats:t}))}})}}))},r.updateStatsFromPart=function(e,t){var r=e.stats,n=t.stats,i=n.total;if(r.loaded+=n.loaded,i){var a=Math.round(e.duration/t.duration),s=Math.min(Math.round(r.loaded/i),a),o=(a-s)*Math.round(r.loaded/s);r.total=r.loaded+o}else r.total=Math.max(r.loaded,r.total);var l=r.loading,u=n.loading;l.start?l.first+=u.first-u.start:(l.start=u.start,l.first=u.first),l.end=u.end},r.resetLoader=function(e,t){e.loader=null,this.loader===t&&(self.clearTimeout(this.partLoadTimeout),this.loader=null),t.destroy()},e}();function Lr(e,t){void 0===t&&(t=null);var r=t||e,n={frag:e,part:t,responseType:"arraybuffer",url:r.url,headers:{},rangeStart:0,rangeEnd:0},i=r.byteRangeStartOffset,a=r.byteRangeEndOffset;if(m(i)&&m(a)){var s,o=i,l=a;if("initSegment"===e.sn&&"AES-128"===(null==(s=e.decryptdata)?void 0:s.method)){var u=a-i;u%16&&(l=a+(16-u%16)),0!==i&&(n.resetIV=!0,o=i-16)}n.rangeStart=o,n.rangeEnd=l}return n}function Pr(e,t){var r=new Error("GAP "+(e.gap?"tag":"attribute")+" found"),n={type:S.MEDIA_ERROR,details:_.FRAG_GAP,fatal:!1,frag:e,error:r,networkDetails:null};return t&&(n.part=t),(t||e).stats.aborted=!0,new wr(n)}var wr=function(e){function t(t){var r;return(r=e.call(this,t.error.message)||this).data=void 0,r.data=t,r}return u(t,e),t}(h(Error)),Rr=function(){function e(e){this.config=void 0,this.keyUriToKeyInfo={},this.emeController=null,this.config=e}var r=e.prototype;return r.abort=function(e){for(var t in this.keyUriToKeyInfo){var r=this.keyUriToKeyInfo[t].loader;if(r){var n;if(e&&e!==(null==(n=r.context)?void 0:n.frag.type))return;r.abort()}}},r.detach=function(){for(var e in this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e];(t.mediaKeySessionContext||t.decryptdata.isCommonEncryption)&&delete this.keyUriToKeyInfo[e]}},r.destroy=function(){for(var e in this.detach(),this.keyUriToKeyInfo){var t=this.keyUriToKeyInfo[e].loader;t&&t.destroy()}this.keyUriToKeyInfo={}},r.createKeyLoadError=function(e,t,r,n,i){return void 0===t&&(t=_.KEY_LOAD_ERROR),new wr({type:S.NETWORK_ERROR,details:t,fatal:!1,frag:e,response:i,error:r,networkDetails:n})},r.loadClear=function(e,t){var r=this;if(this.emeController&&this.config.emeEnabled)for(var n=e.sn,i=e.cc,a=function(){var e=t[s];if(i<=e.cc&&("initSegment"===n||"initSegment"===e.sn||n<e.sn))return r.emeController.selectKeySystemFormat(e).then((function(t){e.setKeyFormat(t)})),1},s=0;s<t.length&&!a();s++);},r.load=function(e){var t=this;return!e.decryptdata&&e.encrypted&&this.emeController?this.emeController.selectKeySystemFormat(e).then((function(r){return t.loadInternal(e,r)})):this.loadInternal(e)},r.loadInternal=function(e,t){var r,n;t&&e.setKeyFormat(t);var i=e.decryptdata;if(!i){var a=new Error(t?"Expected frag.decryptdata to be defined after setting format "+t:"Missing decryption data on fragment in onKeyLoading");return Promise.reject(this.createKeyLoadError(e,_.KEY_LOAD_ERROR,a))}var s=i.uri;if(!s)return Promise.reject(this.createKeyLoadError(e,_.KEY_LOAD_ERROR,new Error('Invalid key URI: "'+s+'"')));var o,l=this.keyUriToKeyInfo[s];if(null!=(r=l)&&r.decryptdata.key)return i.key=l.decryptdata.key,Promise.resolve({frag:e,keyInfo:l});if(null!=(n=l)&&n.keyLoadPromise)switch(null==(o=l.mediaKeySessionContext)?void 0:o.keyStatus){case void 0:case"status-pending":case"usable":case"usable-in-future":return l.keyLoadPromise.then((function(t){return i.key=t.keyInfo.decryptdata.key,{frag:e,keyInfo:l}}))}switch(l=this.keyUriToKeyInfo[s]={decryptdata:i,keyLoadPromise:null,loader:null,mediaKeySessionContext:null},i.method){case"ISO-23001-7":case"SAMPLE-AES":case"SAMPLE-AES-CENC":case"SAMPLE-AES-CTR":return"identity"===i.keyFormat?this.loadKeyHTTP(l,e):this.loadKeyEME(l,e);case"AES-128":return this.loadKeyHTTP(l,e);default:return Promise.reject(this.createKeyLoadError(e,_.KEY_LOAD_ERROR,new Error('Key supplied with unsupported METHOD: "'+i.method+'"')))}},r.loadKeyEME=function(e,t){var r={frag:t,keyInfo:e};if(this.emeController&&this.config.emeEnabled){var n=this.emeController.loadKey(r);if(n)return(e.keyLoadPromise=n.then((function(t){return e.mediaKeySessionContext=t,r}))).catch((function(t){throw e.keyLoadPromise=null,t}))}return Promise.resolve(r)},r.loadKeyHTTP=function(e,r){var n=this,i=this.config,a=new(0,i.loader)(i);return r.keyLoader=e.loader=a,e.keyLoadPromise=new Promise((function(s,o){var l={keyInfo:e,frag:r,responseType:"arraybuffer",url:e.decryptdata.uri},u=i.keyLoadPolicy.default,d={loadPolicy:u,timeout:u.maxLoadTimeMs,maxRetry:0,retryDelay:0,maxRetryDelay:0},c={onSuccess:function(e,t,r,i){var a=r.frag,l=r.keyInfo,u=r.url;if(!a.decryptdata||l!==n.keyUriToKeyInfo[u])return o(n.createKeyLoadError(a,_.KEY_LOAD_ERROR,new Error("after key load, decryptdata unset or changed"),i));l.decryptdata.key=a.decryptdata.key=new Uint8Array(e.data),a.keyLoader=null,l.loader=null,s({frag:a,keyInfo:l})},onError:function(e,i,a,s){n.resetLoader(i),o(n.createKeyLoadError(r,_.KEY_LOAD_ERROR,new Error("HTTP Error "+e.code+" loading key "+e.text),a,t({url:l.url,data:void 0},e)))},onTimeout:function(e,t,i){n.resetLoader(t),o(n.createKeyLoadError(r,_.KEY_LOAD_TIMEOUT,new Error("key loading timed out"),i))},onAbort:function(e,t,i){n.resetLoader(t),o(n.createKeyLoadError(r,_.INTERNAL_ABORTED,new Error("key loading aborted"),i))}};a.load(l,d,c)}))},r.resetLoader=function(e){var t=e.frag,r=e.keyInfo,n=e.url,i=r.loader;t.keyLoader===i&&(t.keyLoader=null,r.loader=null),delete this.keyUriToKeyInfo[n],i&&i.destroy()},e}(),Ar=function(){function e(){this._boundTick=void 0,this._tickTimer=null,this._tickInterval=null,this._tickCallCount=0,this._boundTick=this.tick.bind(this)}var t=e.prototype;return t.destroy=function(){this.onHandlerDestroying(),this.onHandlerDestroyed()},t.onHandlerDestroying=function(){this.clearNextTick(),this.clearInterval()},t.onHandlerDestroyed=function(){},t.hasInterval=function(){return!!this._tickInterval},t.hasNextTick=function(){return!!this._tickTimer},t.setInterval=function(e){return!this._tickInterval&&(this._tickCallCount=0,this._tickInterval=self.setInterval(this._boundTick,e),!0)},t.clearInterval=function(){return!!this._tickInterval&&(self.clearInterval(this._tickInterval),this._tickInterval=null,!0)},t.clearNextTick=function(){return!!this._tickTimer&&(self.clearTimeout(this._tickTimer),this._tickTimer=null,!0)},t.tick=function(){this._tickCallCount++,1===this._tickCallCount&&(this.doTick(),this._tickCallCount>1&&this.tickImmediate(),this._tickCallCount=0)},t.tickImmediate=function(){this.clearNextTick(),this._tickTimer=self.setTimeout(this._boundTick,0)},t.doTick=function(){},e}(),kr=function(e,t,r,n,i,a){void 0===n&&(n=0),void 0===i&&(i=-1),void 0===a&&(a=!1),this.level=void 0,this.sn=void 0,this.part=void 0,this.id=void 0,this.size=void 0,this.partial=void 0,this.transmuxing={start:0,executeStart:0,executeEnd:0,end:0},this.buffering={audio:{start:0,executeStart:0,executeEnd:0,end:0},video:{start:0,executeStart:0,executeEnd:0,end:0},audiovideo:{start:0,executeStart:0,executeEnd:0,end:0}},this.level=e,this.sn=t,this.id=r,this.size=n,this.part=i,this.partial=a};function Cr(e,t){for(var r=0,n=e.length;r<n;r++){var i;if((null==(i=e[r])?void 0:i.cc)===t)return e[r]}return null}function Dr(e,t){if(e){var r=e.start+t;e.start=e.startPTS=r,e.endPTS=r+e.duration}}function Ir(e,t){for(var r=t.fragments,n=0,i=r.length;n<i;n++)Dr(r[n],e);t.fragmentHint&&Dr(t.fragmentHint,e),t.alignedSliding=!0}var xr=function(){function e(e,t){this.subtle=void 0,this.aesIV=void 0,this.subtle=e,this.aesIV=t}return e.prototype.decrypt=function(e,t){return this.subtle.decrypt({name:"AES-CBC",iv:this.aesIV},t,e)},e}(),Or=function(){function e(e,t){this.subtle=void 0,this.key=void 0,this.subtle=e,this.key=t}return e.prototype.expandKey=function(){return this.subtle.importKey("raw",this.key,{name:"AES-CBC"},!1,["encrypt","decrypt"])},e}(),Mr=function(){function e(){this.rcon=[0,1,2,4,8,16,32,64,128,27,54],this.subMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.invSubMix=[new Uint32Array(256),new Uint32Array(256),new Uint32Array(256),new Uint32Array(256)],this.sBox=new Uint32Array(256),this.invSBox=new Uint32Array(256),this.key=new Uint32Array(0),this.ksRows=0,this.keySize=0,this.keySchedule=void 0,this.invKeySchedule=void 0,this.initTable()}var t=e.prototype;return t.uint8ArrayToUint32Array_=function(e){for(var t=new DataView(e),r=new Uint32Array(4),n=0;n<4;n++)r[n]=t.getUint32(4*n);return r},t.initTable=function(){var e=this.sBox,t=this.invSBox,r=this.subMix,n=r[0],i=r[1],a=r[2],s=r[3],o=this.invSubMix,l=o[0],u=o[1],d=o[2],c=o[3],f=new Uint32Array(256),h=0,g=0,v=0;for(v=0;v<256;v++)f[v]=v<128?v<<1:v<<1^283;for(v=0;v<256;v++){var p=g^g<<1^g<<2^g<<3^g<<4;p=p>>>8^255&p^99,e[h]=p,t[p]=h;var m=f[h],y=f[m],b=f[y],E=257*f[p]^16843008*p;n[h]=E<<24|E>>>8,i[h]=E<<16|E>>>16,a[h]=E<<8|E>>>24,s[h]=E,E=16843009*b^65537*y^257*m^16843008*h,l[p]=E<<24|E>>>8,u[p]=E<<16|E>>>16,d[p]=E<<8|E>>>24,c[p]=E,h?(h=m^f[f[f[b^m]]],g^=f[f[g]]):h=g=1}},t.expandKey=function(e){for(var t=this.uint8ArrayToUint32Array_(e),r=!0,n=0;n<t.length&&r;)r=t[n]===this.key[n],n++;if(!r){this.key=t;var i=this.keySize=t.length;if(4!==i&&6!==i&&8!==i)throw new Error("Invalid aes key size="+i);var a,s,o,l,u=this.ksRows=4*(i+6+1),d=this.keySchedule=new Uint32Array(u),c=this.invKeySchedule=new Uint32Array(u),f=this.sBox,h=this.rcon,g=this.invSubMix,v=g[0],p=g[1],m=g[2],y=g[3];for(a=0;a<u;a++)a<i?o=d[a]=t[a]:(l=o,a%i==0?(l=f[(l=l<<8|l>>>24)>>>24]<<24|f[l>>>16&255]<<16|f[l>>>8&255]<<8|f[255&l],l^=h[a/i|0]<<24):i>6&&a%i==4&&(l=f[l>>>24]<<24|f[l>>>16&255]<<16|f[l>>>8&255]<<8|f[255&l]),d[a]=o=(d[a-i]^l)>>>0);for(s=0;s<u;s++)a=u-s,l=3&s?d[a]:d[a-4],c[s]=s<4||a<=4?l:v[f[l>>>24]]^p[f[l>>>16&255]]^m[f[l>>>8&255]]^y[f[255&l]],c[s]=c[s]>>>0}},t.networkToHostOrderSwap=function(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24},t.decrypt=function(e,t,r){for(var n,i,a,s,o,l,u,d,c,f,h,g,v,p,m=this.keySize+6,y=this.invKeySchedule,b=this.invSBox,E=this.invSubMix,S=E[0],_=E[1],T=E[2],L=E[3],P=this.uint8ArrayToUint32Array_(r),w=P[0],R=P[1],A=P[2],k=P[3],C=new Int32Array(e),D=new Int32Array(C.length),I=this.networkToHostOrderSwap;t<C.length;){for(c=I(C[t]),f=I(C[t+1]),h=I(C[t+2]),g=I(C[t+3]),o=c^y[0],l=g^y[1],u=h^y[2],d=f^y[3],v=4,p=1;p<m;p++)n=S[o>>>24]^_[l>>16&255]^T[u>>8&255]^L[255&d]^y[v],i=S[l>>>24]^_[u>>16&255]^T[d>>8&255]^L[255&o]^y[v+1],a=S[u>>>24]^_[d>>16&255]^T[o>>8&255]^L[255&l]^y[v+2],s=S[d>>>24]^_[o>>16&255]^T[l>>8&255]^L[255&u]^y[v+3],o=n,l=i,u=a,d=s,v+=4;n=b[o>>>24]<<24^b[l>>16&255]<<16^b[u>>8&255]<<8^b[255&d]^y[v],i=b[l>>>24]<<24^b[u>>16&255]<<16^b[d>>8&255]<<8^b[255&o]^y[v+1],a=b[u>>>24]<<24^b[d>>16&255]<<16^b[o>>8&255]<<8^b[255&l]^y[v+2],s=b[d>>>24]<<24^b[o>>16&255]<<16^b[l>>8&255]<<8^b[255&u]^y[v+3],D[t]=I(n^w),D[t+1]=I(s^R),D[t+2]=I(a^A),D[t+3]=I(i^k),w=c,R=f,A=h,k=g,t+=4}return D.buffer},e}(),Fr=function(){function e(e,t){var r=(void 0===t?{}:t).removePKCS7Padding,n=void 0===r||r;if(this.logEnabled=!0,this.removePKCS7Padding=void 0,this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null,this.useSoftware=void 0,this.useSoftware=e.enableSoftwareAES,this.removePKCS7Padding=n,n)try{var i=self.crypto;i&&(this.subtle=i.subtle||i.webkitSubtle)}catch(e){}this.useSoftware=!this.subtle}var t=e.prototype;return t.destroy=function(){this.subtle=null,this.softwareDecrypter=null,this.key=null,this.fastAesKey=null,this.remainderData=null,this.currentIV=null,this.currentResult=null},t.isSync=function(){return this.useSoftware},t.flush=function(){var e=this.currentResult,t=this.remainderData;if(!e||t)return this.reset(),null;var r,n,i,a=new Uint8Array(e);return this.reset(),this.removePKCS7Padding?(i=(n=(r=a).byteLength)&&new DataView(r.buffer).getUint8(n-1))?H(r,0,n-i):r:a},t.reset=function(){this.currentResult=null,this.currentIV=null,this.remainderData=null,this.softwareDecrypter&&(this.softwareDecrypter=null)},t.decrypt=function(e,t,r){var n=this;return this.useSoftware?new Promise((function(i,a){n.softwareDecrypt(new Uint8Array(e),t,r);var s=n.flush();s?i(s.buffer):a(new Error("[softwareDecrypt] Failed to decrypt data"))})):this.webCryptoDecrypt(new Uint8Array(e),t,r)},t.softwareDecrypt=function(e,t,r){var n=this.currentIV,i=this.currentResult,a=this.remainderData;this.logOnce("JS AES decrypt"),a&&(e=Te(a,e),this.remainderData=null);var s=this.getValidChunk(e);if(!s.length)return null;n&&(r=n);var o=this.softwareDecrypter;o||(o=this.softwareDecrypter=new Mr),o.expandKey(t);var l=i;return this.currentResult=o.decrypt(s.buffer,0,r),this.currentIV=H(s,-16).buffer,l||null},t.webCryptoDecrypt=function(e,t,r){var n=this;if(this.key!==t||!this.fastAesKey){if(!this.subtle)return Promise.resolve(this.onWebCryptoError(e,t,r));this.key=t,this.fastAesKey=new Or(this.subtle,t)}return this.fastAesKey.expandKey().then((function(t){return n.subtle?(n.logOnce("WebCrypto AES decrypt"),new xr(n.subtle,new Uint8Array(r)).decrypt(e.buffer,t)):Promise.reject(new Error("web crypto not initialized"))})).catch((function(i){return R.warn("[decrypter]: WebCrypto Error, disable WebCrypto API, "+i.name+": "+i.message),n.onWebCryptoError(e,t,r)}))},t.onWebCryptoError=function(e,t,r){this.useSoftware=!0,this.logEnabled=!0,this.softwareDecrypt(e,t,r);var n=this.flush();if(n)return n.buffer;throw new Error("WebCrypto and softwareDecrypt: failed to decrypt data")},t.getValidChunk=function(e){var t=e,r=e.length-e.length%16;return r!==e.length&&(t=H(e,0,r),this.remainderData=H(e,r)),t},t.logOnce=function(e){this.logEnabled&&(R.log("[decrypter]: "+e),this.logEnabled=!1)},e}(),Nr="STOPPED",Br="IDLE",Ur="KEY_LOADING",Gr="FRAG_LOADING",jr="FRAG_LOADING_WAITING_RETRY",Hr="PARSING",qr="PARSED",Vr="ENDED",Wr="ERROR",Kr="WAITING_LEVEL",zr=function(e){function t(t,r,n,i,a){var s;return(s=e.call(this)||this).hls=void 0,s.fragPrevious=null,s.fragCurrent=null,s.fragmentTracker=void 0,s.transmuxer=null,s._state=Nr,s.playlistType=void 0,s.media=null,s.mediaBuffer=null,s.config=void 0,s.bitrateTest=!1,s.lastCurrentTime=0,s.nextLoadPosition=0,s.startPosition=0,s.startTimeOffset=null,s.loadedmetadata=!1,s.retryDate=0,s.levels=null,s.fragmentLoader=void 0,s.keyLoader=void 0,s.levelLastLoaded=null,s.startFragRequested=!1,s.decrypter=void 0,s.initPTS=[],s.onvseeking=null,s.onvended=null,s.logPrefix="",s.log=void 0,s.warn=void 0,s.playlistType=a,s.logPrefix=i,s.log=R.log.bind(R,i+":"),s.warn=R.warn.bind(R,i+":"),s.hls=t,s.fragmentLoader=new Tr(t.config),s.keyLoader=n,s.fragmentTracker=r,s.config=t.config,s.decrypter=new Fr(t.config),t.on(E.MANIFEST_LOADED,s.onManifestLoaded,function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(s)),s}u(t,e);var r=t.prototype;return r.doTick=function(){this.onTickEnd()},r.onTickEnd=function(){},r.startLoad=function(e){},r.stopLoad=function(){this.fragmentLoader.abort(),this.keyLoader.abort(this.playlistType);var e=this.fragCurrent;null!=e&&e.loader&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.resetTransmuxer(),this.fragCurrent=null,this.fragPrevious=null,this.clearInterval(),this.clearNextTick(),this.state=Nr},r._streamEnded=function(e,t){if(t.live||e.nextStart||!e.end||!this.media)return!1;var r=t.partList;if(null!=r&&r.length){var n=r[r.length-1];return zt.isBuffered(this.media,n.start+n.duration/2)}var i=t.fragments[t.fragments.length-1].type;return this.fragmentTracker.isEndListAppended(i)},r.getLevelDetails=function(){var e;if(this.levels&&null!==this.levelLastLoaded)return null==(e=this.levelLastLoaded)?void 0:e.details},r.onMediaAttached=function(e,t){var r=this.media=this.mediaBuffer=t.media;this.onvseeking=this.onMediaSeeking.bind(this),this.onvended=this.onMediaEnded.bind(this),r.addEventListener("seeking",this.onvseeking),r.addEventListener("ended",this.onvended);var n=this.config;this.levels&&n.autoStartLoad&&this.state===Nr&&this.startLoad(n.startPosition)},r.onMediaDetaching=function(){var e=this.media;null!=e&&e.ended&&(this.log("MSE detaching and video ended, reset startPosition"),this.startPosition=this.lastCurrentTime=0),e&&this.onvseeking&&this.onvended&&(e.removeEventListener("seeking",this.onvseeking),e.removeEventListener("ended",this.onvended),this.onvseeking=this.onvended=null),this.keyLoader&&this.keyLoader.detach(),this.media=this.mediaBuffer=null,this.loadedmetadata=!1,this.fragmentTracker.removeAllFragments(),this.stopLoad()},r.onMediaSeeking=function(){var e=this.config,t=this.fragCurrent,r=this.media,n=this.mediaBuffer,i=this.state,a=r?r.currentTime:0,s=zt.bufferInfo(n||r,a,e.maxBufferHole);if(this.log("media seeking to "+(m(a)?a.toFixed(3):a)+", state: "+i),this.state===Vr)this.resetLoadingState();else if(t){var o=e.maxFragLookUpTolerance,l=t.start-o,u=t.start+t.duration+o;if(!s.len||u<s.start||l>s.end){var d=a>u;(a<l||d)&&(d&&t.loader&&(this.log("seeking outside of buffer while fragment load in progress, cancel fragment load"),t.abortRequests(),this.resetLoadingState()),this.fragPrevious=null)}}r&&(this.fragmentTracker.removeFragmentsInRange(a,1/0,this.playlistType,!0),this.lastCurrentTime=a),this.loadedmetadata||s.len||(this.nextLoadPosition=this.startPosition=a),this.tickImmediate()},r.onMediaEnded=function(){this.startPosition=this.lastCurrentTime=0},r.onManifestLoaded=function(e,t){this.startTimeOffset=t.startTimeOffset,this.initPTS=[]},r.onHandlerDestroying=function(){this.hls.off(E.MANIFEST_LOADED,this.onManifestLoaded,this),this.stopLoad(),e.prototype.onHandlerDestroying.call(this),this.hls=null},r.onHandlerDestroyed=function(){this.state=Nr,this.fragmentLoader&&this.fragmentLoader.destroy(),this.keyLoader&&this.keyLoader.destroy(),this.decrypter&&this.decrypter.destroy(),this.hls=this.log=this.warn=this.decrypter=this.keyLoader=this.fragmentLoader=this.fragmentTracker=null,e.prototype.onHandlerDestroyed.call(this)},r.loadFragment=function(e,t,r){this._loadFragForPlayback(e,t,r)},r._loadFragForPlayback=function(e,t,r){var n=this;this._doFragLoad(e,t,r,(function(t){if(n.fragContextChanged(e))return n.warn("Fragment "+e.sn+(t.part?" p: "+t.part.index:"")+" of level "+e.level+" was dropped during download."),void n.fragmentTracker.removeFragment(e);e.stats.chunkCount++,n._handleFragmentLoadProgress(t)})).then((function(t){if(t){var r=n.state;n.fragContextChanged(e)?(r===Gr||!n.fragCurrent&&r===Hr)&&(n.fragmentTracker.removeFragment(e),n.state=Br):("payload"in t&&(n.log("Loaded fragment "+e.sn+" of level "+e.level),n.hls.trigger(E.FRAG_LOADED,t)),n._handleFragmentLoadComplete(t))}})).catch((function(t){n.state!==Nr&&n.state!==Wr&&(n.warn("Frag error: "+((null==t?void 0:t.message)||t)),n.resetFragmentLoading(e))}))},r.clearTrackerIfNeeded=function(e){var t,r=this.fragmentTracker;if(r.getState(e)===pr){var n=e.type,i=this.getFwdBufferInfo(this.mediaBuffer,n),a=Math.max(e.duration,i?i.len:this.config.maxBufferLength),s=this.backtrackFragment;(1==(s?e.sn-s.sn:0)||this.reduceMaxBufferLength(a))&&r.removeFragment(e)}else 0===(null==(t=this.mediaBuffer)?void 0:t.buffered.length)?r.removeAllFragments():r.hasParts(e.type)&&(r.detectPartialFragments({frag:e,part:null,stats:e.stats,id:e.type}),r.getState(e)===mr&&r.removeFragment(e))},r.checkLiveUpdate=function(e){if(e.updated&&!e.live){var t=e.fragments[e.fragments.length-1];this.fragmentTracker.detectPartialFragments({frag:t,part:null,stats:t.stats,id:t.type})}e.fragments[0]||(e.deltaUpdateFailed=!0)},r.flushMainBuffer=function(e,t,r){if(void 0===r&&(r=null),e-t){var n={startOffset:e,endOffset:t,type:r};this.hls.trigger(E.BUFFER_FLUSHING,n)}},r._loadInitSegment=function(e,t){var r=this;this._doFragLoad(e,t).then((function(t){if(!t||r.fragContextChanged(e)||!r.levels)throw new Error("init load aborted");return t})).then((function(t){var n=r.hls,i=t.payload,a=e.decryptdata;if(i&&i.byteLength>0&&null!=a&&a.key&&a.iv&&"AES-128"===a.method){var s=self.performance.now();return r.decrypter.decrypt(new Uint8Array(i),a.key.buffer,a.iv.buffer).catch((function(t){throw n.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_DECRYPT_ERROR,fatal:!1,error:t,reason:t.message,frag:e}),t})).then((function(i){var a=self.performance.now();return n.trigger(E.FRAG_DECRYPTED,{frag:e,payload:i,stats:{tstart:s,tdecrypt:a}}),t.payload=i,r.completeInitSegmentLoad(t)}))}return r.completeInitSegmentLoad(t)})).catch((function(t){r.state!==Nr&&r.state!==Wr&&(r.warn(t),r.resetFragmentLoading(e))}))},r.completeInitSegmentLoad=function(e){if(!this.levels)throw new Error("init load aborted, missing levels");var t=e.frag.stats;this.state=Br,e.frag.data=new Uint8Array(e.payload),t.parsing.start=t.buffering.start=self.performance.now(),t.parsing.end=t.buffering.end=self.performance.now(),this.tick()},r.fragContextChanged=function(e){var t=this.fragCurrent;return!e||!t||e.sn!==t.sn||e.level!==t.level},r.fragBufferedComplete=function(e,t){var r,n,i,a,s=this.mediaBuffer?this.mediaBuffer:this.media;if(this.log("Buffered "+e.type+" sn: "+e.sn+(t?" part: "+t.index:"")+" of "+(this.playlistType===nt?"level":"track")+" "+e.level+" (frag:["+(null!=(r=e.startPTS)?r:NaN).toFixed(3)+"-"+(null!=(n=e.endPTS)?n:NaN).toFixed(3)+"] > buffer:"+(s?function(e){for(var t="",r=e.length,n=0;n<r;n++)t+="["+e.start(n).toFixed(3)+"-"+e.end(n).toFixed(3)+"]";return t}(zt.getBuffered(s)):"(detached)")+")"),"initSegment"!==e.sn){var o;if(e.type!==at){var l=e.elementaryStreams;if(!Object.keys(l).some((function(e){return!!l[e]})))return void(this.state=Br)}var u=null==(o=this.levels)?void 0:o[e.level];null!=u&&u.fragmentError&&(this.log("Resetting level fragment error count of "+u.fragmentError+" on frag buffered"),u.fragmentError=0)}this.state=Br,s&&(!this.loadedmetadata&&e.type==nt&&s.buffered.length&&(null==(i=this.fragCurrent)?void 0:i.sn)===(null==(a=this.fragPrevious)?void 0:a.sn)&&(this.loadedmetadata=!0,this.seekToStartPos()),this.tick())},r.seekToStartPos=function(){},r._handleFragmentLoadComplete=function(e){var t=this.transmuxer;if(t){var r=e.frag,n=e.part,i=e.partsLoaded,a=!i||0===i.length||i.some((function(e){return!e})),s=new kr(r.level,r.sn,r.stats.chunkCount+1,0,n?n.index:-1,!a);t.flush(s)}},r._handleFragmentLoadProgress=function(e){},r._doFragLoad=function(e,t,r,n){var i,a=this;void 0===r&&(r=null);var s=null==t?void 0:t.details;if(!this.levels||!s)throw new Error("frag load aborted, missing level"+(s?"":" detail")+"s");var o=null;if(!e.encrypted||null!=(i=e.decryptdata)&&i.key?!e.encrypted&&s.encryptedFragments.length&&this.keyLoader.loadClear(e,s.encryptedFragments):(this.log("Loading key for "+e.sn+" of ["+s.startSN+"-"+s.endSN+"], "+("[stream-controller]"===this.logPrefix?"level":"track")+" "+e.level),this.state=Ur,this.fragCurrent=e,o=this.keyLoader.load(e).then((function(e){if(!a.fragContextChanged(e.frag))return a.hls.trigger(E.KEY_LOADED,e),a.state===Ur&&(a.state=Br),e})),this.hls.trigger(E.KEY_LOADING,{frag:e}),null===this.fragCurrent&&(o=Promise.reject(new Error("frag load aborted, context changed in KEY_LOADING")))),r=Math.max(e.start,r||0),this.config.lowLatencyMode&&"initSegment"!==e.sn){var l=s.partList;if(l&&n){r>e.end&&s.fragmentHint&&(e=s.fragmentHint);var u=this.getNextPart(l,e,r);if(u>-1){var d,c=l[u];return this.log("Loading part sn: "+e.sn+" p: "+c.index+" cc: "+e.cc+" of playlist ["+s.startSN+"-"+s.endSN+"] parts [0-"+u+"-"+(l.length-1)+"] "+("[stream-controller]"===this.logPrefix?"level":"track")+": "+e.level+", target: "+parseFloat(r.toFixed(3))),this.nextLoadPosition=c.start+c.duration,this.state=Gr,d=o?o.then((function(r){return!r||a.fragContextChanged(r.frag)?null:a.doFragPartsLoad(e,c,t,n)})).catch((function(e){return a.handleFragLoadError(e)})):this.doFragPartsLoad(e,c,t,n).catch((function(e){return a.handleFragLoadError(e)})),this.hls.trigger(E.FRAG_LOADING,{frag:e,part:c,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING parts")):d}if(!e.url||this.loadedEndOfParts(l,r))return Promise.resolve(null)}}this.log("Loading fragment "+e.sn+" cc: "+e.cc+" "+(s?"of ["+s.startSN+"-"+s.endSN+"] ":"")+("[stream-controller]"===this.logPrefix?"level":"track")+": "+e.level+", target: "+parseFloat(r.toFixed(3))),m(e.sn)&&!this.bitrateTest&&(this.nextLoadPosition=e.start+e.duration),this.state=Gr;var f,h=this.config.progressive;return f=h&&o?o.then((function(t){return!t||a.fragContextChanged(null==t?void 0:t.frag)?null:a.fragmentLoader.load(e,n)})).catch((function(e){return a.handleFragLoadError(e)})):Promise.all([this.fragmentLoader.load(e,h?n:void 0),o]).then((function(e){var t=e[0];return!h&&t&&n&&n(t),t})).catch((function(e){return a.handleFragLoadError(e)})),this.hls.trigger(E.FRAG_LOADING,{frag:e,targetBufferTime:r}),null===this.fragCurrent?Promise.reject(new Error("frag load aborted, context changed in FRAG_LOADING")):f},r.doFragPartsLoad=function(e,t,r,n){var i=this;return new Promise((function(a,s){var o,l=[],u=null==(o=r.details)?void 0:o.partList;!function t(o){i.fragmentLoader.loadPart(e,o,n).then((function(n){l[o.index]=n;var s=n.part;i.hls.trigger(E.FRAG_LOADED,n);var d=At(r,e.sn,o.index+1)||kt(u,e.sn,o.index+1);if(!d)return a({frag:e,part:s,partsLoaded:l});t(d)})).catch(s)}(t)}))},r.handleFragLoadError=function(e){if("data"in e){var t=e.data;e.data&&t.details===_.INTERNAL_ABORTED?this.handleFragLoadAborted(t.frag,t.part):this.hls.trigger(E.ERROR,t)}else this.hls.trigger(E.ERROR,{type:S.OTHER_ERROR,details:_.INTERNAL_EXCEPTION,err:e,error:e,fatal:!0});return null},r._handleTransmuxerFlush=function(e){var t=this.getCurrentContext(e);if(t&&this.state===Hr){var r=t.frag,n=t.part,i=t.level,a=self.performance.now();r.stats.parsing.end=a,n&&(n.stats.parsing.end=a),this.updateLevelTiming(r,n,i,e.partial)}else this.fragCurrent||this.state===Nr||this.state===Wr||(this.state=Br)},r.getCurrentContext=function(e){var t=this.levels,r=this.fragCurrent,n=e.level,i=e.sn,a=e.part;if(null==t||!t[n])return this.warn("Levels object was unset while buffering fragment "+i+" of level "+n+". The current chunk will not be buffered."),null;var s=t[n],o=a>-1?At(s,i,a):null,l=o?o.fragment:function(e,t,r){if(null==e||!e.details)return null;var n=e.details,i=n.fragments[t-n.startSN];return i||((i=n.fragmentHint)&&i.sn===t?i:t<n.startSN&&r&&r.sn===t?r:null)}(s,i,r);return l?(r&&r!==l&&(l.stats=r.stats),{frag:l,part:o,level:s}):null},r.bufferFragmentData=function(e,t,r,n,i){var a;if(e&&this.state===Hr){var s=e.data1,o=e.data2,l=s;if(s&&o&&(l=Te(s,o)),null!=(a=l)&&a.length){var u={type:e.type,frag:t,part:r,chunkMeta:n,parent:t.type,data:l};if(this.hls.trigger(E.BUFFER_APPENDING,u),e.dropped&&e.independent&&!r){if(i)return;this.flushBufferGap(t)}}}},r.flushBufferGap=function(e){var t=this.media;if(t)if(zt.isBuffered(t,t.currentTime)){var r=t.currentTime,n=zt.bufferInfo(t,r,0),i=e.duration,a=Math.min(2*this.config.maxFragLookUpTolerance,.25*i),s=Math.max(Math.min(e.start-a,n.end-a),r+a);e.start-s>a&&this.flushMainBuffer(s,e.start)}else this.flushMainBuffer(0,e.start)},r.getFwdBufferInfo=function(e,t){var r=this.getLoadPosition();return m(r)?this.getFwdBufferInfoAtPos(e,r,t):null},r.getFwdBufferInfoAtPos=function(e,t,r){var n=this.config.maxBufferHole,i=zt.bufferInfo(e,t,n);if(0===i.len&&void 0!==i.nextStart){var a=this.fragmentTracker.getBufferedFrag(t,r);if(a&&i.nextStart<a.end)return zt.bufferInfo(e,t,Math.max(i.nextStart,n))}return i},r.getMaxBufferLength=function(e){var t,r=this.config;return t=e?Math.max(8*r.maxBufferSize/e,r.maxBufferLength):r.maxBufferLength,Math.min(t,r.maxMaxBufferLength)},r.reduceMaxBufferLength=function(e){var t=this.config,r=e||t.maxBufferLength,n=t.maxMaxBufferLength/2;return n>=r&&(t.maxMaxBufferLength=n,this.warn("Reduce max buffer length to "+n+"s"),!0)},r.getAppendedFrag=function(e,t){var r=this.fragmentTracker.getAppendedFrag(e,nt);return r&&"fragment"in r?r.fragment:r},r.getNextFragment=function(e,t){var r=t.fragments,n=r.length;if(!n)return null;var i,a=this.config,s=r[0].start;if(t.live){var o=a.initialLiveManifestSize;if(n<o)return this.warn("Not enough fragments to start playback (have: "+n+", need: "+o+")"),null;(!t.PTSKnown&&!this.startFragRequested&&-1===this.startPosition||e<s)&&(i=this.getInitialLiveFragment(t,r),this.startPosition=this.nextLoadPosition=i?this.hls.liveSyncPosition||i.start:e)}else e<=s&&(i=r[0]);if(!i){var l=a.lowLatencyMode?t.partEnd:t.fragmentEnd;i=this.getFragmentAtPosition(e,l,t)}return this.mapToInitFragWhenRequired(i)},r.isLoopLoading=function(e,t){var r=this.fragmentTracker.getState(e);return(r===yr||r===mr&&!!e.gap)&&this.nextLoadPosition>t},r.getNextFragmentLoopLoading=function(e,t,r,n,i){var a=e.gap,s=this.getNextFragment(this.nextLoadPosition,t);if(null===s)return s;if(e=s,a&&e&&!e.gap&&r.nextStart){var o=this.getFwdBufferInfoAtPos(this.mediaBuffer?this.mediaBuffer:this.media,r.nextStart,n);if(null!==o&&r.len+o.len>=i)return this.log('buffer full after gaps in "'+n+'" playlist starting at sn: '+e.sn),null}return e},r.mapToInitFragWhenRequired=function(e){return null==e||!e.initSegment||null!=e&&e.initSegment.data||this.bitrateTest?e:e.initSegment},r.getNextPart=function(e,t,r){for(var n=-1,i=!1,a=!0,s=0,o=e.length;s<o;s++){var l=e[s];if(a=a&&!l.independent,n>-1&&r<l.start)break;var u=l.loaded;u?n=-1:(i||l.independent||a)&&l.fragment===t&&(n=s),i=u}return n},r.loadedEndOfParts=function(e,t){var r=e[e.length-1];return r&&t>r.start&&r.loaded},r.getInitialLiveFragment=function(e,t){var r=this.fragPrevious,n=null;if(r){if(e.hasProgramDateTime&&(this.log("Live playlist, switching playlist, load frag with same PDT: "+r.programDateTime),n=function(e,t,r){if(null===t||!Array.isArray(e)||!e.length||!m(t))return null;if(t<(e[0].programDateTime||0))return null;if(t>=(e[e.length-1].endProgramDateTime||0))return null;r=r||0;for(var n=0;n<e.length;++n){var i=e[n];if(Ut(t,r,i))return i}return null}(t,r.endProgramDateTime,this.config.maxFragLookUpTolerance)),!n){var i=r.sn+1;if(i>=e.startSN&&i<=e.endSN){var a=t[i-e.startSN];r.cc===a.cc&&(n=a,this.log("Live playlist, switching playlist, load frag with next SN: "+n.sn))}n||(n=function(e,t){return Ft(e,(function(e){return e.cc<t?1:e.cc>t?-1:0}))}(t,r.cc),n&&this.log("Live playlist, switching playlist, load frag with same CC: "+n.sn))}}else{var s=this.hls.liveSyncPosition;null!==s&&(n=this.getFragmentAtPosition(s,this.bitrateTest?e.fragmentEnd:e.edge,e))}return n},r.getFragmentAtPosition=function(e,t,r){var n,i=this.config,a=this.fragPrevious,s=r.fragments,o=r.endSN,l=r.fragmentHint,u=i.maxFragLookUpTolerance,d=r.partList,c=!!(i.lowLatencyMode&&null!=d&&d.length&&l);if(c&&l&&!this.bitrateTest&&(s=s.concat(l),o=l.sn),n=e<t?Nt(a,s,e,e>t-u?0:u):s[s.length-1]){var f=n.sn-r.startSN,h=this.fragmentTracker.getState(n);if((h===yr||h===mr&&n.gap)&&(a=n),a&&n.sn===a.sn&&(!c||d[0].fragment.sn>n.sn)&&a&&n.level===a.level){var g=s[f+1];n=n.sn<o&&this.fragmentTracker.getState(g)!==yr?g:null}}return n},r.synchronizeToLiveEdge=function(e){var t=this.config,r=this.media;if(r){var n=this.hls.liveSyncPosition,i=r.currentTime,a=e.fragments[0].start,s=e.edge,o=i>=a-t.maxFragLookUpTolerance&&i<=s;if(null!==n&&r.duration>n&&(i<n||!o)){var l=void 0!==t.liveMaxLatencyDuration?t.liveMaxLatencyDuration:t.liveMaxLatencyDurationCount*e.targetduration;(!o&&r.readyState<4||i<s-l)&&(this.loadedmetadata||(this.nextLoadPosition=n),r.readyState&&(this.warn("Playback: "+i.toFixed(3)+" is located too far from the end of live sliding playlist: "+s+", reset currentTime to : "+n.toFixed(3)),r.currentTime=n))}}},r.alignPlaylists=function(e,t,r){var n=e.fragments.length;if(!n)return this.warn("No fragments in live playlist"),0;var i=e.fragments[0].start,a=!t,s=e.alignedSliding&&m(i);if(a||!s&&!i){var o=this.fragPrevious;!function(e,t,r){t&&(function(e,t,r){if(function(e,t,r){return!(!t||!(r.endCC>r.startCC||e&&e.cc<r.startCC))}(e,r,t)){var n=function(e,t){var r=e.fragments,n=t.fragments;if(n.length&&r.length){var i=Cr(r,n[0].cc);if(i&&(!i||i.startPTS))return i;R.log("No frag in previous level to align on")}else R.log("No fragments to align")}(r,t);n&&m(n.start)&&(R.log("Adjusting PTS using last level due to CC increase within current level "+t.url),Ir(n.start,t))}}(e,r,t),!r.alignedSliding&&t&&function(e,t){if(e.hasProgramDateTime&&t.hasProgramDateTime){var r,n,i=e.fragments,a=t.fragments;if(i.length&&a.length){var s=Math.min(t.endCC,e.endCC);t.startCC<s&&e.startCC<s&&(r=Cr(a,s),n=Cr(i,s)),r&&n||(n=Cr(i,(r=a[Math.floor(a.length/2)]).cc)||i[Math.floor(i.length/2)]);var o=r.programDateTime,l=n.programDateTime;o&&l&&Ir((l-o)/1e3-(n.start-r.start),e)}}}(r,t),r.alignedSliding||!t||r.skippedSegments||Rt(t,r))}(o,r,e);var l=e.fragments[0].start;return this.log("Live playlist sliding: "+l.toFixed(2)+" start-sn: "+(t?t.startSN:"na")+"->"+e.startSN+" prev-sn: "+(o?o.sn:"na")+" fragments: "+n),l}return i},r.waitForCdnTuneIn=function(e){return e.live&&e.canBlockReload&&e.partTarget&&e.tuneInGoal>Math.max(e.partHoldBack,3*e.partTarget)},r.setStartPosition=function(e,t){var r=this.startPosition;if(r<t&&(r=-1),-1===r||-1===this.lastCurrentTime){var n=null!==this.startTimeOffset,i=n?this.startTimeOffset:e.startTimeOffset;null!==i&&m(i)?(r=t+i,i<0&&(r+=e.totalduration),r=Math.min(Math.max(t,r),t+e.totalduration),this.log("Start time offset "+i+" found in "+(n?"multivariant":"media")+" playlist, adjust startPosition to "+r),this.startPosition=r):e.live?r=this.hls.liveSyncPosition||t:this.startPosition=r=0,this.lastCurrentTime=r}this.nextLoadPosition=r},r.getLoadPosition=function(){var e=this.media,t=0;return this.loadedmetadata&&e?t=e.currentTime:this.nextLoadPosition&&(t=this.nextLoadPosition),t},r.handleFragLoadAborted=function(e,t){this.transmuxer&&"initSegment"!==e.sn&&e.stats.aborted&&(this.warn("Fragment "+e.sn+(t?" part "+t.index:"")+" of level "+e.level+" was aborted"),this.resetFragmentLoading(e))},r.resetFragmentLoading=function(e){this.fragCurrent&&(this.fragContextChanged(e)||this.state===jr)||(this.state=Br)},r.onFragmentOrKeyLoadError=function(e,t){if(t.chunkMeta&&!t.frag){var r=this.getCurrentContext(t.chunkMeta);r&&(t.frag=r.frag)}var n=t.frag;if(n&&n.type===e&&this.levels)if(this.fragContextChanged(n)){var i;this.warn("Frag load error must match current frag to retry "+n.url+" > "+(null==(i=this.fragCurrent)?void 0:i.url))}else{var a=t.details===_.FRAG_GAP;a&&this.fragmentTracker.fragBuffered(n,!0);var s=t.errorAction,o=s||{},l=o.action,u=o.retryCount,d=void 0===u?0:u,c=o.retryConfig;if(s&&5===l&&c){this.resetStartWhenNotLoaded(this.levelLastLoaded);var f=xt(c,d);this.warn("Fragment "+n.sn+" of "+e+" "+n.level+" errored with "+t.details+", retrying loading "+(d+1)+"/"+c.maxNumRetry+" in "+f+"ms"),s.resolved=!0,this.retryDate=self.performance.now()+f,this.state=jr}else if(c&&s){if(this.resetFragmentErrors(e),!(d<c.maxNumRetry))return void R.warn(t.details+" reached or exceeded max retry ("+d+")");a||3===l||(s.resolved=!0)}else 2===(null==s?void 0:s.action)?this.state=Kr:this.state=Wr;this.tickImmediate()}},r.reduceLengthAndFlushBuffer=function(e){if(this.state===Hr||this.state===qr){var t=e.parent,r=this.getFwdBufferInfo(this.mediaBuffer,t),n=r&&r.len>.5;n&&this.reduceMaxBufferLength(r.len);var i=!n;return i&&this.warn("Buffer full error while media.currentTime is not buffered, flush "+t+" buffer"),e.frag&&(this.fragmentTracker.removeFragment(e.frag),this.nextLoadPosition=e.frag.start),this.resetLoadingState(),i}return!1},r.resetFragmentErrors=function(e){e===it&&(this.fragCurrent=null),this.loadedmetadata||(this.startFragRequested=!1),this.state!==Nr&&(this.state=Br)},r.afterBufferFlushed=function(e,t,r){if(e){var n=zt.getBuffered(e);this.fragmentTracker.detectEvictedFragments(t,n,r),this.state===Vr&&this.resetLoadingState()}},r.resetLoadingState=function(){this.log("Reset loading state"),this.fragCurrent=null,this.fragPrevious=null,this.state=Br},r.resetStartWhenNotLoaded=function(e){if(!this.loadedmetadata){this.startFragRequested=!1;var t=e?e.details:null;null!=t&&t.live?(this.startPosition=-1,this.setStartPosition(t,0),this.resetLoadingState()):this.nextLoadPosition=this.startPosition}},r.resetWhenMissingContext=function(e){this.warn("The loading context changed while buffering fragment "+e.sn+" of level "+e.level+". This chunk will not be buffered."),this.removeUnbufferedFrags(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState()},r.removeUnbufferedFrags=function(e){void 0===e&&(e=0),this.fragmentTracker.removeFragmentsInRange(e,1/0,this.playlistType,!1,!0)},r.updateLevelTiming=function(e,t,r,n){var i,a=this,s=r.details;if(s){if(!Object.keys(e.elementaryStreams).reduce((function(t,i){var o=e.elementaryStreams[i];if(o){var l=o.endPTS-o.startPTS;if(l<=0)return a.warn("Could not parse fragment "+e.sn+" "+i+" duration reliably ("+l+")"),t||!1;var u=n?0:Pt(s,e,o.startPTS,o.endPTS,o.startDTS,o.endDTS);return a.hls.trigger(E.LEVEL_PTS_UPDATED,{details:s,level:r,drift:u,type:i,frag:e,start:o.startPTS,end:o.endPTS}),!0}return t}),!1)&&null===(null==(i=this.transmuxer)?void 0:i.error)){var o=new Error("Found no media in fragment "+e.sn+" of level "+e.level+" resetting transmuxer to fallback to playlist timing");if(0===r.fragmentError&&(r.fragmentError++,e.gap=!0,this.fragmentTracker.removeFragment(e),this.fragmentTracker.fragBuffered(e,!0)),this.warn(o.message),this.hls.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,fatal:!1,error:o,frag:e,reason:"Found no media in msn "+e.sn+' of level "'+r.url+'"'}),!this.hls)return;this.resetTransmuxer()}this.state=qr,this.hls.trigger(E.FRAG_PARSED,{frag:e,part:t})}else this.warn("level.details undefined")},r.resetTransmuxer=function(){this.transmuxer&&(this.transmuxer.destroy(),this.transmuxer=null)},r.recoverWorkerError=function(e){"demuxerWorker"===e.event&&(this.fragmentTracker.removeAllFragments(),this.resetTransmuxer(),this.resetStartWhenNotLoaded(this.levelLastLoaded),this.resetLoadingState())},i(t,[{key:"state",get:function(){return this._state},set:function(e){var t=this._state;t!==e&&(this._state=e,this.log(t+"->"+e))}}]),t}(Ar);function Yr(){return self.SourceBuffer||self.WebKitSourceBuffer}function Xr(){if(!ke())return!1;var e=Yr();return!e||e.prototype&&"function"==typeof e.prototype.appendBuffer&&"function"==typeof e.prototype.remove}function Jr(e,t){return void 0===e&&(e=""),void 0===t&&(t=9e4),{type:e,id:-1,pid:-1,inputTimeScale:t,sequenceNumber:-1,samples:[],dropped:0}}var Qr=function(){function e(){this._audioTrack=void 0,this._id3Track=void 0,this.frameIndex=0,this.cachedData=null,this.basePTS=null,this.initPTS=null,this.lastPTS=null}var t=e.prototype;return t.resetInitSegment=function(e,t,r,n){this._id3Track={type:"id3",id:3,pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0}},t.resetTimeStamp=function(e){this.initPTS=e,this.resetContiguity()},t.resetContiguity=function(){this.basePTS=null,this.lastPTS=null,this.frameIndex=0},t.canParse=function(e,t){return!1},t.appendFrame=function(e,t,r){},t.demux=function(e,t){this.cachedData&&(e=Te(this.cachedData,e),this.cachedData=null);var r,n=K(e,0),i=n?n.length:0,a=this._audioTrack,s=this._id3Track,o=n?X(n):void 0,l=e.length;for((null===this.basePTS||0===this.frameIndex&&m(o))&&(this.basePTS=Zr(o,t,this.initPTS),this.lastPTS=this.basePTS),null===this.lastPTS&&(this.lastPTS=this.basePTS),n&&n.length>0&&s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:n,type:dt,duration:Number.POSITIVE_INFINITY});i<l;){if(this.canParse(e,i)){var u=this.appendFrame(a,e,i);u?(this.frameIndex++,this.lastPTS=u.sample.pts,r=i+=u.length):i=l}else Y(e,i)?(n=K(e,i),s.samples.push({pts:this.lastPTS,dts:this.lastPTS,data:n,type:dt,duration:Number.POSITIVE_INFINITY}),r=i+=n.length):i++;if(i===l&&r!==l){var d=H(e,r);this.cachedData?this.cachedData=Te(this.cachedData,d):this.cachedData=d}}return{audioTrack:a,videoTrack:Jr(),id3Track:s,textTrack:Jr()}},t.demuxSampleAes=function(e,t,r){return Promise.reject(new Error("["+this+"] This demuxer does not support Sample-AES decryption"))},t.flush=function(e){var t=this.cachedData;return t&&(this.cachedData=null,this.demux(t,0)),{audioTrack:this._audioTrack,videoTrack:Jr(),id3Track:this._id3Track,textTrack:Jr()}},t.destroy=function(){},e}(),Zr=function(e,t,r){return m(e)?90*e:9e4*t+(r?9e4*r.baseTime/r.timescale:0)};function $r(e,t){return 255===e[t]&&240==(246&e[t+1])}function en(e,t){return 1&e[t+1]?7:9}function tn(e,t){return(3&e[t+3])<<11|e[t+4]<<3|(224&e[t+5])>>>5}function rn(e,t){return t+1<e.length&&$r(e,t)}function nn(e,t){if(rn(e,t)){var r=en(e,t);if(t+r>=e.length)return!1;var n=tn(e,t);if(n<=r)return!1;var i=t+n;return i===e.length||rn(e,i)}return!1}function an(e,t,r,n,i){if(!e.samplerate){var a=function(e,t,r,n){var i,a,s,o,l=navigator.userAgent.toLowerCase(),u=n,d=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350];i=1+((192&t[r+2])>>>6);var c=(60&t[r+2])>>>2;if(!(c>d.length-1))return s=(1&t[r+2])<<2,s|=(192&t[r+3])>>>6,R.log("manifest codec:"+n+", ADTS type:"+i+", samplingIndex:"+c),/firefox/i.test(l)?c>=6?(i=5,o=new Array(4),a=c-3):(i=2,o=new Array(2),a=c):-1!==l.indexOf("android")?(i=2,o=new Array(2),a=c):(i=5,o=new Array(4),n&&(-1!==n.indexOf("mp4a.40.29")||-1!==n.indexOf("mp4a.40.5"))||!n&&c>=6?a=c-3:((n&&-1!==n.indexOf("mp4a.40.2")&&(c>=6&&1===s||/vivaldi/i.test(l))||!n&&1===s)&&(i=2,o=new Array(2)),a=c)),o[0]=i<<3,o[0]|=(14&c)>>1,o[1]|=(1&c)<<7,o[1]|=s<<3,5===i&&(o[1]|=(14&a)>>1,o[2]=(1&a)<<7,o[2]|=8,o[3]=0),{config:o,samplerate:d[c],channelCount:s,codec:"mp4a.40."+i,manifestCodec:u};var f=new Error("invalid ADTS sampling index:"+c);e.emit(E.ERROR,E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,fatal:!0,error:f,reason:f.message})}(t,r,n,i);if(!a)return;e.config=a.config,e.samplerate=a.samplerate,e.channelCount=a.channelCount,e.codec=a.codec,e.manifestCodec=a.manifestCodec,R.log("parsed codec:"+e.codec+", rate:"+a.samplerate+", channels:"+a.channelCount)}}function sn(e){return 9216e4/e}function on(e,t,r,n,i){var a,s=n+i*sn(e.samplerate),o=function(e,t){var r=en(e,t);if(t+r<=e.length){var n=tn(e,t)-r;if(n>0)return{headerLength:r,frameLength:n}}}(t,r);if(o){var l=o.frameLength,u=o.headerLength,d=u+l,c=Math.max(0,r+d-t.length);c?(a=new Uint8Array(d-u)).set(t.subarray(r+u,t.length),0):a=t.subarray(r+u,r+d);var f={unit:a,pts:s};return c||e.samples.push(f),{sample:f,length:d,missing:c}}var h=t.length-r;return(a=new Uint8Array(h)).set(t.subarray(r,t.length),0),{sample:{unit:a,pts:s},length:h,missing:-1}}var ln=null,un=[32,64,96,128,160,192,224,256,288,320,352,384,416,448,32,48,56,64,80,96,112,128,160,192,224,256,320,384,32,40,48,56,64,80,96,112,128,160,192,224,256,320,32,48,56,64,80,96,112,128,144,160,176,192,224,256,8,16,24,32,40,48,56,64,80,96,112,128,144,160],dn=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],cn=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],fn=[0,1,1,4];function hn(e,t,r,n,i){if(!(r+24>t.length)){var a=gn(t,r);if(a&&r+a.frameLength<=t.length){var s=n+i*(9e4*a.samplesPerFrame/a.sampleRate),o={unit:t.subarray(r,r+a.frameLength),pts:s,dts:s};return e.config=[],e.channelCount=a.channelCount,e.samplerate=a.sampleRate,e.samples.push(o),{sample:o,length:a.frameLength,missing:0}}}}function gn(e,t){var r=e[t+1]>>3&3,n=e[t+1]>>1&3,i=e[t+2]>>4&15,a=e[t+2]>>2&3;if(1!==r&&0!==i&&15!==i&&3!==a){var s=e[t+2]>>1&1,o=e[t+3]>>6,l=1e3*un[14*(3===r?3-n:3===n?3:4)+i-1],u=dn[3*(3===r?0:2===r?1:2)+a],d=3===o?1:2,c=cn[r][n],f=fn[n],h=8*c*f,g=Math.floor(c*l/u+s)*f;if(null===ln){var v=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);ln=v?parseInt(v[1]):0}return!!ln&&ln<=87&&2===n&&l>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:u,channelCount:d,frameLength:g,samplesPerFrame:h}}}function vn(e,t){return!(255!==e[t]||224&~e[t+1]||!(6&e[t+1]))}function pn(e,t){return t+1<e.length&&vn(e,t)}function mn(e,t){if(t+1<e.length&&vn(e,t)){var r=gn(e,t),n=4;null!=r&&r.frameLength&&(n=r.frameLength);var i=t+n;return i===e.length||pn(e,i)}return!1}var yn=function(e){function t(t,r){var n;return(n=e.call(this)||this).observer=void 0,n.config=void 0,n.observer=t,n.config=r,n}u(t,e);var r=t.prototype;return r.resetInitSegment=function(t,r,n,i){e.prototype.resetInitSegment.call(this,t,r,n,i),this._audioTrack={container:"audio/adts",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"aac",samples:[],manifestCodec:r,duration:i,inputTimeScale:9e4,dropped:0}},t.probe=function(e){if(!e)return!1;var t=K(e,0),r=(null==t?void 0:t.length)||0;if(mn(e,r))return!1;for(var n=e.length;r<n;r++)if(nn(e,r))return R.log("ADTS sync word found !"),!0;return!1},r.canParse=function(e,t){return function(e,t){return function(e,t){return t+5<e.length}(e,t)&&$r(e,t)&&tn(e,t)<=e.length-t}(e,t)},r.appendFrame=function(e,t,r){an(e,this.observer,t,r,e.manifestCodec);var n=on(e,t,r,this.basePTS,this.frameIndex);if(n&&0===n.missing)return n},t}(Qr),bn=/\/emsg[-/]ID3/i,En=function(){function e(e,t){this.remainderData=null,this.timeOffset=0,this.config=void 0,this.videoTrack=void 0,this.audioTrack=void 0,this.id3Track=void 0,this.txtTrack=void 0,this.config=t}var t=e.prototype;return t.resetTimeStamp=function(){},t.resetInitSegment=function(e,t,r,n){var i=this.videoTrack=Jr("video",1),a=this.audioTrack=Jr("audio",1),s=this.txtTrack=Jr("text",1);if(this.id3Track=Jr("id3",1),this.timeOffset=0,null!=e&&e.byteLength){var o=me(e);if(o.video){var l=o.video,u=l.id,d=l.timescale,c=l.codec;i.id=u,i.timescale=s.timescale=d,i.codec=c}if(o.audio){var f=o.audio,h=f.id,g=f.timescale,v=f.codec;a.id=h,a.timescale=g,a.codec=v}s.id=le.text,i.sampleDuration=0,i.duration=a.duration=n}},t.resetContiguity=function(){this.remainderData=null},e.probe=function(e){return function(e){for(var t=e.byteLength,r=0;r<t;){var n=ce(e,r);if(n>8&&109===e[r+4]&&111===e[r+5]&&111===e[r+6]&&102===e[r+7])return!0;r=n>1?r+n:t}return!1}(e)},t.demux=function(e,t){this.timeOffset=t;var r=e,n=this.videoTrack,i=this.txtTrack;if(this.config.progressive){this.remainderData&&(r=Te(this.remainderData,e));var a=function(e){var t={valid:null,remainder:null},r=ve(e,["moof"]);if(r.length<2)return t.remainder=e,t;var n=r[r.length-1];return t.valid=H(e,0,n.byteOffset-8),t.remainder=H(e,n.byteOffset-8),t}(r);this.remainderData=a.remainder,n.samples=a.valid||new Uint8Array}else n.samples=r;var s=this.extractID3Track(n,t);return i.samples=Le(t,n),{videoTrack:n,audioTrack:this.audioTrack,id3Track:s,textTrack:this.txtTrack}},t.flush=function(){var e=this.timeOffset,t=this.videoTrack,r=this.txtTrack;t.samples=this.remainderData||new Uint8Array,this.remainderData=null;var n=this.extractID3Track(t,this.timeOffset);return r.samples=Le(e,t),{videoTrack:t,audioTrack:Jr(),id3Track:n,textTrack:Jr()}},t.extractID3Track=function(e,t){var r=this.id3Track;if(e.samples.length){var n=ve(e.samples,["emsg"]);n&&n.forEach((function(e){var n=function(e){var t=e[0],r="",n="",i=0,a=0,s=0,o=0,l=0,u=0;if(0===t){for(;"\0"!==ue(e.subarray(u,u+1));)r+=ue(e.subarray(u,u+1)),u+=1;for(r+=ue(e.subarray(u,u+1)),u+=1;"\0"!==ue(e.subarray(u,u+1));)n+=ue(e.subarray(u,u+1)),u+=1;n+=ue(e.subarray(u,u+1)),u+=1,i=ce(e,12),a=ce(e,16),o=ce(e,20),l=ce(e,24),u=28}else if(1===t){i=ce(e,u+=4);var d=ce(e,u+=4),c=ce(e,u+=4);for(u+=4,s=Math.pow(2,32)*d+c,y(s)||(s=Number.MAX_SAFE_INTEGER,R.warn("Presentation time exceeds safe integer limit and wrapped to max safe integer in parsing emsg box")),o=ce(e,u),l=ce(e,u+=4),u+=4;"\0"!==ue(e.subarray(u,u+1));)r+=ue(e.subarray(u,u+1)),u+=1;for(r+=ue(e.subarray(u,u+1)),u+=1;"\0"!==ue(e.subarray(u,u+1));)n+=ue(e.subarray(u,u+1)),u+=1;n+=ue(e.subarray(u,u+1)),u+=1}return{schemeIdUri:r,value:n,timeScale:i,presentationTime:s,presentationTimeDelta:a,eventDuration:o,id:l,payload:e.subarray(u,e.byteLength)}}(e);if(bn.test(n.schemeIdUri)){var i=m(n.presentationTime)?n.presentationTime/n.timeScale:t+n.presentationTimeDelta/n.timeScale,a=4294967295===n.eventDuration?Number.POSITIVE_INFINITY:n.eventDuration/n.timeScale;a<=.001&&(a=Number.POSITIVE_INFINITY);var s=n.payload;r.samples.push({data:s,len:s.byteLength,dts:i,pts:i,type:ct,duration:a})}}))}return r},t.demuxSampleAes=function(e,t,r){return Promise.reject(new Error("The MP4 demuxer does not support SAMPLE-AES decryption"))},t.destroy=function(){},e}(),Sn=function(){function e(){this.VideoSample=null}var t=e.prototype;return t.createVideoSample=function(e,t,r,n){return{key:e,frame:!1,pts:t,dts:r,units:[],debug:n,length:0}},t.getLastNalUnit=function(e){var t,r,n=this.VideoSample;if(n&&0!==n.units.length||(n=e[e.length-1]),null!=(t=n)&&t.units){var i=n.units;r=i[i.length-1]}return r},t.pushAccessUnit=function(e,t){if(e.units.length&&e.frame){if(void 0===e.pts){var r=t.samples,n=r.length;if(!n)return void t.dropped++;var i=r[n-1];e.pts=i.pts,e.dts=i.dts}t.samples.push(e)}e.debug.length&&R.log(e.pts+"/"+e.dts+":"+e.debug)},e}(),_n=function(){function e(e){this.data=void 0,this.bytesAvailable=void 0,this.word=void 0,this.bitsAvailable=void 0,this.data=e,this.bytesAvailable=e.byteLength,this.word=0,this.bitsAvailable=0}var t=e.prototype;return t.loadWord=function(){var e=this.data,t=this.bytesAvailable,r=e.byteLength-t,n=new Uint8Array(4),i=Math.min(4,t);if(0===i)throw new Error("no bytes available");n.set(e.subarray(r,r+i)),this.word=new DataView(n.buffer).getUint32(0),this.bitsAvailable=8*i,this.bytesAvailable-=i},t.skipBits=function(e){var t;e=Math.min(e,8*this.bytesAvailable+this.bitsAvailable),this.bitsAvailable>e?(this.word<<=e,this.bitsAvailable-=e):(e-=this.bitsAvailable,e-=(t=e>>3)<<3,this.bytesAvailable-=t,this.loadWord(),this.word<<=e,this.bitsAvailable-=e)},t.readBits=function(e){var t=Math.min(this.bitsAvailable,e),r=this.word>>>32-t;if(e>32&&R.error("Cannot read more than 32 bits at a time"),this.bitsAvailable-=t,this.bitsAvailable>0)this.word<<=t;else{if(!(this.bytesAvailable>0))throw new Error("no bits available");this.loadWord()}return(t=e-t)>0&&this.bitsAvailable?r<<t|this.readBits(t):r},t.skipLZ=function(){var e;for(e=0;e<this.bitsAvailable;++e)if(this.word&2147483648>>>e)return this.word<<=e,this.bitsAvailable-=e,e;return this.loadWord(),e+this.skipLZ()},t.skipUEG=function(){this.skipBits(1+this.skipLZ())},t.skipEG=function(){this.skipBits(1+this.skipLZ())},t.readUEG=function(){var e=this.skipLZ();return this.readBits(e+1)-1},t.readEG=function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)},t.readBoolean=function(){return 1===this.readBits(1)},t.readUByte=function(){return this.readBits(8)},t.readUShort=function(){return this.readBits(16)},t.readUInt=function(){return this.readBits(32)},t.skipScalingList=function(e){for(var t=8,r=8,n=0;n<e;n++)0!==r&&(r=(t+this.readEG()+256)%256),t=0===r?t:r},t.readSPS=function(){var e,t,r,n=0,i=0,a=0,s=0,o=this.readUByte.bind(this),l=this.readBits.bind(this),u=this.readUEG.bind(this),d=this.readBoolean.bind(this),c=this.skipBits.bind(this),f=this.skipEG.bind(this),h=this.skipUEG.bind(this),g=this.skipScalingList.bind(this);o();var v=o();if(l(5),c(3),o(),h(),100===v||110===v||122===v||244===v||44===v||83===v||86===v||118===v||128===v){var p=u();if(3===p&&c(1),h(),h(),c(1),d())for(t=3!==p?8:12,r=0;r<t;r++)d()&&g(r<6?16:64)}h();var m=u();if(0===m)u();else if(1===m)for(c(1),f(),f(),e=u(),r=0;r<e;r++)f();h(),c(1);var y=u(),b=u(),E=l(1);0===E&&c(1),c(1),d()&&(n=u(),i=u(),a=u(),s=u());var S=[1,1];if(d()&&d())switch(o()){case 1:S=[1,1];break;case 2:S=[12,11];break;case 3:S=[10,11];break;case 4:S=[16,11];break;case 5:S=[40,33];break;case 6:S=[24,11];break;case 7:S=[20,11];break;case 8:S=[32,11];break;case 9:S=[80,33];break;case 10:S=[18,11];break;case 11:S=[15,11];break;case 12:S=[64,33];break;case 13:S=[160,99];break;case 14:S=[4,3];break;case 15:S=[3,2];break;case 16:S=[2,1];break;case 255:S=[o()<<8|o(),o()<<8|o()]}return{width:Math.ceil(16*(y+1)-2*n-2*i),height:(2-E)*(b+1)*16-(E?2:4)*(a+s),pixelRatio:S}},t.readSliceType=function(){return this.readUByte(),this.readUEG(),this.readUEG()},e}(),Tn=function(e){function t(){return e.apply(this,arguments)||this}u(t,e);var r=t.prototype;return r.parseAVCPES=function(e,t,r,n,i){var a,s=this,o=this.parseAVCNALu(e,r.data),l=this.VideoSample,u=!1;r.data=null,l&&o.length&&!e.audFound&&(this.pushAccessUnit(l,e),l=this.VideoSample=this.createVideoSample(!1,r.pts,r.dts,"")),o.forEach((function(n){var o;switch(n.type){case 1:var d=!1;a=!0;var c,f=n.data;if(u&&f.length>4){var h=new _n(f).readSliceType();2!==h&&4!==h&&7!==h&&9!==h||(d=!0)}d&&null!=(c=l)&&c.frame&&!l.key&&(s.pushAccessUnit(l,e),l=s.VideoSample=null),l||(l=s.VideoSample=s.createVideoSample(!0,r.pts,r.dts,"")),l.frame=!0,l.key=d;break;case 5:a=!0,null!=(o=l)&&o.frame&&!l.key&&(s.pushAccessUnit(l,e),l=s.VideoSample=null),l||(l=s.VideoSample=s.createVideoSample(!0,r.pts,r.dts,"")),l.key=!0,l.frame=!0;break;case 6:a=!0,we(n.data,1,r.pts,t.samples);break;case 7:var g,v;a=!0,u=!0;var p=n.data,m=new _n(p).readSPS();if(!e.sps||e.width!==m.width||e.height!==m.height||(null==(g=e.pixelRatio)?void 0:g[0])!==m.pixelRatio[0]||(null==(v=e.pixelRatio)?void 0:v[1])!==m.pixelRatio[1]){e.width=m.width,e.height=m.height,e.pixelRatio=m.pixelRatio,e.sps=[p],e.duration=i;for(var y=p.subarray(1,4),b="avc1.",E=0;E<3;E++){var S=y[E].toString(16);S.length<2&&(S="0"+S),b+=S}e.codec=b}break;case 8:a=!0,e.pps=[n.data];break;case 9:a=!0,e.audFound=!0,l&&s.pushAccessUnit(l,e),l=s.VideoSample=s.createVideoSample(!1,r.pts,r.dts,"");break;case 12:a=!0;break;default:a=!1,l&&(l.debug+="unknown NAL "+n.type+" ")}l&&a&&l.units.push(n)})),n&&l&&(this.pushAccessUnit(l,e),this.VideoSample=null)},r.parseAVCNALu=function(e,t){var r,n,i=t.byteLength,a=e.naluState||0,s=a,o=[],l=0,u=-1,d=0;for(-1===a&&(u=0,d=31&t[0],a=0,l=1);l<i;)if(r=t[l++],a)if(1!==a)if(r)if(1===r){if(n=l-a-1,u>=0){var c={data:t.subarray(u,n),type:d};o.push(c)}else{var f=this.getLastNalUnit(e.samples);f&&(s&&l<=4-s&&f.state&&(f.data=f.data.subarray(0,f.data.byteLength-s)),n>0&&(f.data=Te(f.data,t.subarray(0,n)),f.state=0))}l<i?(u=l,d=31&t[l],a=0):a=-1}else a=0;else a=3;else a=r?0:2;else a=r?0:1;if(u>=0&&a>=0){var h={data:t.subarray(u,i),type:d,state:a};o.push(h)}if(0===o.length){var g=this.getLastNalUnit(e.samples);g&&(g.data=Te(g.data,t))}return e.naluState=a,o},t}(Sn),Ln=function(){function e(e,t,r){this.keyData=void 0,this.decrypter=void 0,this.keyData=r,this.decrypter=new Fr(t,{removePKCS7Padding:!1})}var t=e.prototype;return t.decryptBuffer=function(e){return this.decrypter.decrypt(e,this.keyData.key.buffer,this.keyData.iv.buffer)},t.decryptAacSample=function(e,t,r){var n=this,i=e[t].unit;if(!(i.length<=16)){var a=i.subarray(16,i.length-i.length%16),s=a.buffer.slice(a.byteOffset,a.byteOffset+a.length);this.decryptBuffer(s).then((function(a){var s=new Uint8Array(a);i.set(s,16),n.decrypter.isSync()||n.decryptAacSamples(e,t+1,r)}))}},t.decryptAacSamples=function(e,t,r){for(;;t++){if(t>=e.length)return void r();if(!(e[t].unit.length<32||(this.decryptAacSample(e,t,r),this.decrypter.isSync())))return}},t.getAvcEncryptedData=function(e){for(var t=16*Math.floor((e.length-48)/160)+16,r=new Int8Array(t),n=0,i=32;i<e.length-16;i+=160,n+=16)r.set(e.subarray(i,i+16),n);return r},t.getAvcDecryptedUnit=function(e,t){for(var r=new Uint8Array(t),n=0,i=32;i<e.length-16;i+=160,n+=16)e.set(r.subarray(n,n+16),i);return e},t.decryptAvcSample=function(e,t,r,n,i){var a=this,s=Re(i.data),o=this.getAvcEncryptedData(s);this.decryptBuffer(o.buffer).then((function(o){i.data=a.getAvcDecryptedUnit(s,o),a.decrypter.isSync()||a.decryptAvcSamples(e,t,r+1,n)}))},t.decryptAvcSamples=function(e,t,r,n){if(e instanceof Uint8Array)throw new Error("Cannot decrypt samples of type Uint8Array");for(;;t++,r=0){if(t>=e.length)return void n();for(var i=e[t].units;!(r>=i.length);r++){var a=i[r];if(!(a.data.length<=48||1!==a.type&&5!==a.type||(this.decryptAvcSample(e,t,r,n,a),this.decrypter.isSync())))return}}},e}(),Pn=188,wn=function(){function e(e,t,r){this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.sampleAes=null,this.pmtParsed=!1,this.audioCodec=void 0,this.videoCodec=void 0,this._duration=0,this._pmtId=-1,this._videoTrack=void 0,this._audioTrack=void 0,this._id3Track=void 0,this._txtTrack=void 0,this.aacOverFlow=null,this.remainderData=null,this.videoParser=void 0,this.observer=e,this.config=t,this.typeSupported=r,this.videoParser=new Tn}e.probe=function(t){var r=e.syncOffset(t);return r>0&&R.warn("MPEG2-TS detected but first sync word found @ offset "+r),-1!==r},e.syncOffset=function(e){for(var t=e.length,r=Math.min(940,t-Pn)+1,n=0;n<r;){for(var i=!1,a=-1,s=0,o=n;o<t;o+=Pn){if(71!==e[o]||t-o!==Pn&&71!==e[o+Pn]){if(s)return-1;break}if(s++,-1===a&&0!==(a=o)&&(r=Math.min(a+18612,e.length-Pn)+1),i||(i=0===Rn(e,o)),i&&s>1&&(0===a&&s>2||o+Pn>r))return a}n++}return-1},e.createTrack=function(e,t){return{container:"video"===e||"audio"===e?"video/mp2t":void 0,type:e,id:le[e],pid:-1,inputTimeScale:9e4,sequenceNumber:0,samples:[],dropped:0,duration:"audio"===e?t:void 0}};var t=e.prototype;return t.resetInitSegment=function(t,r,n,i){this.pmtParsed=!1,this._pmtId=-1,this._videoTrack=e.createTrack("video"),this._audioTrack=e.createTrack("audio",i),this._id3Track=e.createTrack("id3"),this._txtTrack=e.createTrack("text"),this._audioTrack.segmentCodec="aac",this.aacOverFlow=null,this.remainderData=null,this.audioCodec=r,this.videoCodec=n,this._duration=i},t.resetTimeStamp=function(){},t.resetContiguity=function(){var e=this._audioTrack,t=this._videoTrack,r=this._id3Track;e&&(e.pesData=null),t&&(t.pesData=null),r&&(r.pesData=null),this.aacOverFlow=null,this.remainderData=null},t.demux=function(t,r,n,i){var a;void 0===n&&(n=!1),void 0===i&&(i=!1),n||(this.sampleAes=null);var s=this._videoTrack,o=this._audioTrack,l=this._id3Track,u=this._txtTrack,d=s.pid,c=s.pesData,f=o.pid,h=l.pid,g=o.pesData,v=l.pesData,p=null,m=this.pmtParsed,y=this._pmtId,b=t.length;if(this.remainderData&&(b=(t=Te(this.remainderData,t)).length,this.remainderData=null),b<Pn&&!i)return this.remainderData=t,{audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};var E=Math.max(0,e.syncOffset(t));(b-=(b-E)%Pn)<t.byteLength&&!i&&(this.remainderData=new Uint8Array(t.buffer,b,t.buffer.byteLength-b));for(var S=0,_=E;_<b;_+=Pn)if(71===t[_]){var T=!!(64&t[_+1]),L=Rn(t,_),P=void 0;if((48&t[_+3])>>4>1){if((P=_+5+t[_+4])===_+Pn)continue}else P=_+4;switch(L){case d:T&&(c&&(a=In(c))&&this.videoParser.parseAVCPES(s,u,a,!1,this._duration),c={data:[],size:0}),c&&(c.data.push(t.subarray(P,_+Pn)),c.size+=_+Pn-P);break;case f:if(T){if(g&&(a=In(g)))switch(o.segmentCodec){case"aac":this.parseAACPES(o,a);break;case"mp3":this.parseMPEGPES(o,a)}g={data:[],size:0}}g&&(g.data.push(t.subarray(P,_+Pn)),g.size+=_+Pn-P);break;case h:T&&(v&&(a=In(v))&&this.parseID3PES(l,a),v={data:[],size:0}),v&&(v.data.push(t.subarray(P,_+Pn)),v.size+=_+Pn-P);break;case 0:T&&(P+=t[P]+1),y=this._pmtId=An(t,P);break;case y:T&&(P+=t[P]+1);var w=kn(t,P,this.typeSupported,n,this.observer);(d=w.videoPid)>0&&(s.pid=d,s.segmentCodec=w.segmentVideoCodec),(f=w.audioPid)>0&&(o.pid=f,o.segmentCodec=w.segmentAudioCodec),(h=w.id3Pid)>0&&(l.pid=h),null===p||m||(R.warn("MPEG-TS PMT found at "+_+" after unknown PID '"+p+"'. Backtracking to sync byte @"+E+" to parse all TS packets."),p=null,_=E-188),m=this.pmtParsed=!0;break;case 17:case 8191:break;default:p=L}}else S++;S>0&&Cn(this.observer,new Error("Found "+S+" TS packet/s that do not start with 0x47")),s.pesData=c,o.pesData=g,l.pesData=v;var A={audioTrack:o,videoTrack:s,id3Track:l,textTrack:u};return i&&this.extractRemainingSamples(A),A},t.flush=function(){var e,t=this.remainderData;return this.remainderData=null,e=t?this.demux(t,-1,!1,!0):{videoTrack:this._videoTrack,audioTrack:this._audioTrack,id3Track:this._id3Track,textTrack:this._txtTrack},this.extractRemainingSamples(e),this.sampleAes?this.decrypt(e,this.sampleAes):e},t.extractRemainingSamples=function(e){var t,r=e.audioTrack,n=e.videoTrack,i=e.id3Track,a=e.textTrack,s=n.pesData,o=r.pesData,l=i.pesData;if(s&&(t=In(s))?(this.videoParser.parseAVCPES(n,a,t,!0,this._duration),n.pesData=null):n.pesData=s,o&&(t=In(o))){switch(r.segmentCodec){case"aac":this.parseAACPES(r,t);break;case"mp3":this.parseMPEGPES(r,t)}r.pesData=null}else null!=o&&o.size&&R.log("last AAC PES packet truncated,might overlap between fragments"),r.pesData=o;l&&(t=In(l))?(this.parseID3PES(i,t),i.pesData=null):i.pesData=l},t.demuxSampleAes=function(e,t,r){var n=this.demux(e,r,!0,!this.config.progressive),i=this.sampleAes=new Ln(this.observer,this.config,t);return this.decrypt(n,i)},t.decrypt=function(e,t){return new Promise((function(r){var n=e.audioTrack,i=e.videoTrack;n.samples&&"aac"===n.segmentCodec?t.decryptAacSamples(n.samples,0,(function(){i.samples?t.decryptAvcSamples(i.samples,0,0,(function(){r(e)})):r(e)})):i.samples&&t.decryptAvcSamples(i.samples,0,0,(function(){r(e)}))}))},t.destroy=function(){this._duration=0},t.parseAACPES=function(e,t){var r,n,i,a=0,s=this.aacOverFlow,o=t.data;if(s){this.aacOverFlow=null;var l=s.missing,u=s.sample.unit.byteLength;if(-1===l)o=Te(s.sample.unit,o);else{var d=u-l;s.sample.unit.set(o.subarray(0,l),d),e.samples.push(s.sample),a=s.missing}}for(r=a,n=o.length;r<n-1&&!rn(o,r);r++);if(r!==a){var c,f=r<n-1;if(c=f?"AAC PES did not start with ADTS header,offset:"+r:"No ADTS header found in AAC PES",Cn(this.observer,new Error(c),f),!f)return}if(an(e,this.observer,o,r,this.audioCodec),void 0!==t.pts)i=t.pts;else{if(!s)return void R.warn("[tsdemuxer]: AAC PES unknown PTS");var h=sn(e.samplerate);i=s.sample.pts+h}for(var g,v=0;r<n;){if(r+=(g=on(e,o,r,i,v)).length,g.missing){this.aacOverFlow=g;break}for(v++;r<n-1&&!rn(o,r);r++);}},t.parseMPEGPES=function(e,t){var r=t.data,n=r.length,i=0,a=0,s=t.pts;if(void 0!==s)for(;a<n;)if(pn(r,a)){var o=hn(e,r,a,s,i);if(!o)break;a+=o.length,i++}else a++;else R.warn("[tsdemuxer]: MPEG PES unknown PTS")},t.parseAC3PES=function(e,t){},t.parseID3PES=function(e,t){if(void 0!==t.pts){var r=l({},t,{type:this._videoTrack?ct:dt,duration:Number.POSITIVE_INFINITY});e.samples.push(r)}else R.warn("[tsdemuxer]: ID3 PES unknown PTS")},e}();function Rn(e,t){return((31&e[t+1])<<8)+e[t+2]}function An(e,t){return(31&e[t+10])<<8|e[t+11]}function kn(e,t,r,n,i){var a={audioPid:-1,videoPid:-1,id3Pid:-1,segmentVideoCodec:"avc",segmentAudioCodec:"aac"},s=t+3+((15&e[t+1])<<8|e[t+2])-4;for(t+=12+((15&e[t+10])<<8|e[t+11]);t<s;){var o=Rn(e,t),l=(15&e[t+3])<<8|e[t+4];switch(e[t]){case 207:if(!n){Dn("ADTS AAC");break}case 15:-1===a.audioPid&&(a.audioPid=o);break;case 21:-1===a.id3Pid&&(a.id3Pid=o);break;case 219:if(!n){Dn("H.264");break}case 27:-1===a.videoPid&&(a.videoPid=o,a.segmentVideoCodec="avc");break;case 3:case 4:r.mpeg||r.mp3?-1===a.audioPid&&(a.audioPid=o,a.segmentAudioCodec="mp3"):R.log("MPEG audio found, not supported in this browser");break;case 193:if(!n){Dn("AC-3");break}case 129:R.warn("AC-3 in M2TS support not included in build");break;case 6:if(-1===a.audioPid&&l>0)for(var u=t+5,d=l;d>2;){106===e[u]&&R.warn("AC-3 in M2TS support not included in build");var c=e[u+1]+2;u+=c,d-=c}break;case 194:case 135:return Cn(i,new Error("Unsupported EC-3 in M2TS found")),a;case 36:return Cn(i,new Error("Unsupported HEVC in M2TS found")),a}t+=l+5}return a}function Cn(e,t,r){R.warn("parsing error: "+t.message),e.emit(E.ERROR,E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,fatal:!1,levelRetry:r,error:t,reason:t.message})}function Dn(e){R.log(e+" with AES-128-CBC encryption found in unencrypted stream")}function In(e){var t,r,n,i,a,s=0,o=e.data;if(!e||0===e.size)return null;for(;o[0].length<19&&o.length>1;)o[0]=Te(o[0],o[1]),o.splice(1,1);if(1===((t=o[0])[0]<<16)+(t[1]<<8)+t[2]){if((r=(t[4]<<8)+t[5])&&r>e.size-6)return null;var l=t[7];192&l&&(i=536870912*(14&t[9])+4194304*(255&t[10])+16384*(254&t[11])+128*(255&t[12])+(254&t[13])/2,64&l?i-(a=536870912*(14&t[14])+4194304*(255&t[15])+16384*(254&t[16])+128*(255&t[17])+(254&t[18])/2)>54e5&&(R.warn(Math.round((i-a)/9e4)+"s delta between PTS and DTS, align them"),i=a):a=i);var u=(n=t[8])+9;if(e.size<=u)return null;e.size-=u;for(var d=new Uint8Array(e.size),c=0,f=o.length;c<f;c++){var h=(t=o[c]).byteLength;if(u){if(u>h){u-=h;continue}t=t.subarray(u),h-=u,u=0}d.set(t,s),s+=h}return r&&(r-=n+3),{data:d,pts:i,dts:a,len:r}}return null}var xn=function(e){function t(){return e.apply(this,arguments)||this}u(t,e);var r=t.prototype;return r.resetInitSegment=function(t,r,n,i){e.prototype.resetInitSegment.call(this,t,r,n,i),this._audioTrack={container:"audio/mpeg",type:"audio",id:2,pid:-1,sequenceNumber:0,segmentCodec:"mp3",samples:[],manifestCodec:r,duration:i,inputTimeScale:9e4,dropped:0}},t.probe=function(e){if(!e)return!1;var t=K(e,0),r=(null==t?void 0:t.length)||0;if(t&&11===e[r]&&119===e[r+1]&&void 0!==X(t)&&function(e,t){var r=0,n=5;t+=n;for(var i=new Uint32Array(1),a=new Uint32Array(1),s=new Uint8Array(1);n>0;){s[0]=e[t];var o=Math.min(n,8),l=8-o;a[0]=4278190080>>>24+l<<l,i[0]=(s[0]&a[0])>>l,r=r?r<<o|i[0]:i[0],t+=1,n-=o}return r}(e,r)<=16)return!1;for(var n=e.length;r<n;r++)if(mn(e,r))return R.log("MPEG Audio sync word found !"),!0;return!1},r.canParse=function(e,t){return function(e,t){return vn(e,t)&&4<=e.length-t}(e,t)},r.appendFrame=function(e,t,r){if(null!==this.basePTS)return hn(e,t,r,this.basePTS,this.frameIndex)},t}(Qr),On=function(){function e(){}return e.getSilentFrame=function(e,t){if("mp4a.40.2"===e){if(1===t)return new Uint8Array([0,200,0,128,35,128]);if(2===t)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,56]);if(6===t)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,130,48,4,153,0,33,144,2,0,178,0,32,8,224])}else{if(1===t)return new Uint8Array([1,64,34,128,163,78,230,128,186,8,0,0,0,28,6,241,193,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(2===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94]);if(3===t)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}},e}(),Mn=Math.pow(2,32)-1,Fn=function(){function e(){}return e.init=function(){var t;for(t in e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],".mp3":[],dac3:[],"ac-3":[],mvex:[],mvhd:[],pasp:[],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 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]),n=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:n};var i=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,i))},e.box=function(e){for(var t=8,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];for(var a=n.length,s=a;a--;)t+=n[a].byteLength;var o=new Uint8Array(t);for(o[0]=t>>24&255,o[1]=t>>16&255,o[2]=t>>8&255,o[3]=255&t,o.set(e,4),a=0,t=8;a<s;a++)o.set(n[a],t),t+=n[a].byteLength;return o},e.hdlr=function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])},e.mdat=function(t){return e.box(e.types.mdat,t)},e.mdhd=function(t,r){r*=t;var n=Math.floor(r/(Mn+1)),i=Math.floor(r%(Mn+1));return e.box(e.types.mdhd,new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,n>>24,n>>16&255,n>>8&255,255&n,i>>24,i>>16&255,i>>8&255,255&i,85,196,0,0]))},e.mdia=function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))},e.mfhd=function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))},e.minf=function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))},e.moof=function(t,r,n){return e.box(e.types.moof,e.mfhd(t),e.traf(n,r))},e.moov=function(t){for(var r=t.length,n=[];r--;)n[r]=e.trak(t[r]);return e.box.apply(null,[e.types.moov,e.mvhd(t[0].timescale,t[0].duration)].concat(n).concat(e.mvex(t)))},e.mvex=function(t){for(var r=t.length,n=[];r--;)n[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(n))},e.mvhd=function(t,r){r*=t;var n=Math.floor(r/(Mn+1)),i=Math.floor(r%(Mn+1)),a=new Uint8Array([1,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,n>>24,n>>16&255,n>>8&255,255&n,i>>24,i>>16&255,i>>8&255,255&i,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,a)},e.sdtp=function(t){var r,n,i=t.samples||[],a=new Uint8Array(4+i.length);for(r=0;r<i.length;r++)n=i[r].flags,a[r+4]=n.dependsOn<<4|n.isDependedOn<<2|n.hasRedundancy;return e.box(e.types.sdtp,a)},e.stbl=function(t){return e.box(e.types.stbl,e.stsd(t),e.box(e.types.stts,e.STTS),e.box(e.types.stsc,e.STSC),e.box(e.types.stsz,e.STSZ),e.box(e.types.stco,e.STCO))},e.avc1=function(t){var r,n,i,a=[],s=[];for(r=0;r<t.sps.length;r++)i=(n=t.sps[r]).byteLength,a.push(i>>>8&255),a.push(255&i),a=a.concat(Array.prototype.slice.call(n));for(r=0;r<t.pps.length;r++)i=(n=t.pps[r]).byteLength,s.push(i>>>8&255),s.push(255&i),s=s.concat(Array.prototype.slice.call(n));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,d=t.pixelRatio[0],c=t.pixelRatio[1];return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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])),e.box(e.types.pasp,new Uint8Array([d>>24,d>>16&255,d>>8&255,255&d,c>>24,c>>16&255,c>>8&255,255&c])))},e.esds=function(e){var t=e.config.length;return new Uint8Array([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5].concat([t]).concat(e.config).concat([6,1,2]))},e.audioStsd=function(e){var t=e.samplerate;return new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,e.channelCount,0,16,0,0,0,0,t>>8&255,255&t,0,0])},e.mp4a=function(t){return e.box(e.types.mp4a,e.audioStsd(t),e.box(e.types.esds,e.esds(t)))},e.mp3=function(t){return e.box(e.types[".mp3"],e.audioStsd(t))},e.ac3=function(t){return e.box(e.types["ac-3"],e.audioStsd(t),e.box(e.types.dac3,t.config))},e.stsd=function(t){return"audio"===t.type?"mp3"===t.segmentCodec&&"mp3"===t.codec?e.box(e.types.stsd,e.STSD,e.mp3(t)):"ac3"===t.segmentCodec?e.box(e.types.stsd,e.STSD,e.ac3(t)):e.box(e.types.stsd,e.STSD,e.mp4a(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))},e.tkhd=function(t){var r=t.id,n=t.duration*t.timescale,i=t.width,a=t.height,s=Math.floor(n/(Mn+1)),o=Math.floor(n%(Mn+1));return e.box(e.types.tkhd,new Uint8Array([1,0,0,7,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,3,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,s>>24,s>>16&255,s>>8&255,255&s,o>>24,o>>16&255,o>>8&255,255&o,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,i>>8&255,255&i,0,0,a>>8&255,255&a,0,0]))},e.traf=function(t,r){var n=e.sdtp(t),i=t.id,a=Math.floor(r/(Mn+1)),s=Math.floor(r%(Mn+1));return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),e.box(e.types.tfdt,new Uint8Array([1,0,0,0,a>>24,a>>16&255,a>>8&255,255&a,s>>24,s>>16&255,s>>8&255,255&s])),e.trun(t,n.length+16+20+8+16+8+8),n)},e.trak=function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))},e.trex=function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))},e.trun=function(t,r){var n,i,a,s,o,l,u=t.samples||[],d=u.length,c=12+16*d,f=new Uint8Array(c);for(r+=8+c,f.set(["video"===t.type?1: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),n=0;n<d;n++)a=(i=u[n]).duration,s=i.size,o=i.flags,l=i.cts,f.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*n);return e.box(e.types.trun,f)},e.initSegment=function(t){e.types||e.init();var r=e.moov(t);return Te(e.FTYP,r)},e}();function Nn(e,t){return void 0===t&&(t=!1),function(e,t,r,n){void 0===r&&(r=1),void 0===n&&(n=!1);var i=1e3*e*r;return n?Math.round(i):i}(e,0,1/9e4,t)}Fn.types=void 0,Fn.HDLR_TYPES=void 0,Fn.STTS=void 0,Fn.STSC=void 0,Fn.STCO=void 0,Fn.STSZ=void 0,Fn.VMHD=void 0,Fn.SMHD=void 0,Fn.STSD=void 0,Fn.FTYP=void 0,Fn.DINF=void 0;var Bn=null,Un=null,Gn=function(){function e(e,t,r,n){if(this.observer=void 0,this.config=void 0,this.typeSupported=void 0,this.ISGenerated=!1,this._initPTS=null,this._initDTS=null,this.nextAvcDts=null,this.nextAudioPts=null,this.videoSampleDuration=null,this.isAudioContiguous=!1,this.isVideoContiguous=!1,this.videoTrackConfig=void 0,this.observer=e,this.config=t,this.typeSupported=r,this.ISGenerated=!1,null===Bn){var i=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);Bn=i?parseInt(i[1]):0}if(null===Un){var a=navigator.userAgent.match(/Safari\/(\d+)/i);Un=a?parseInt(a[1]):0}}var t=e.prototype;return t.destroy=function(){this.config=this.videoTrackConfig=this._initPTS=this._initDTS=null},t.resetTimeStamp=function(e){R.log("[mp4-remuxer]: initPTS & initDTS reset"),this._initPTS=this._initDTS=e},t.resetNextTimestamp=function(){R.log("[mp4-remuxer]: reset next timestamp"),this.isVideoContiguous=!1,this.isAudioContiguous=!1},t.resetInitSegment=function(){R.log("[mp4-remuxer]: ISGenerated flag reset"),this.ISGenerated=!1,this.videoTrackConfig=void 0},t.getVideoStartPts=function(e){var t=!1,r=e.reduce((function(e,r){var n=r.pts-e;return n<-4294967296?(t=!0,jn(e,r.pts)):n>0?e:r.pts}),e[0].pts);return t&&R.debug("PTS rollover detected"),r},t.remux=function(e,t,r,n,i,a,s,o){var l,u,d,c,f,h,g=i,v=i,p=e.pid>-1,m=t.pid>-1,y=t.samples.length,b=e.samples.length>0,E=s&&y>0||y>1;if((!p||b)&&(!m||E)||this.ISGenerated||s){if(this.ISGenerated){var S,_,T,L,P=this.videoTrackConfig;!P||t.width===P.width&&t.height===P.height&&(null==(S=t.pixelRatio)?void 0:S[0])===(null==(_=P.pixelRatio)?void 0:_[0])&&(null==(T=t.pixelRatio)?void 0:T[1])===(null==(L=P.pixelRatio)?void 0:L[1])||this.resetInitSegment()}else d=this.generateIS(e,t,i,a);var w,A=this.isVideoContiguous,k=-1;if(E&&(k=function(e){for(var t=0;t<e.length;t++)if(e[t].key)return t;return-1}(t.samples),!A&&this.config.forceKeyFrameOnDiscontinuity))if(h=!0,k>0){R.warn("[mp4-remuxer]: Dropped "+k+" out of "+y+" video samples due to a missing keyframe");var C=this.getVideoStartPts(t.samples);t.samples=t.samples.slice(k),t.dropped+=k,w=v+=(t.samples[0].pts-C)/t.inputTimeScale}else-1===k&&(R.warn("[mp4-remuxer]: No keyframe found out of "+y+" video samples"),h=!1);if(this.ISGenerated){if(b&&E){var D=this.getVideoStartPts(t.samples),I=(jn(e.samples[0].pts,D)-D)/t.inputTimeScale;g+=Math.max(0,I),v+=Math.max(0,-I)}if(b){if(e.samplerate||(R.warn("[mp4-remuxer]: regenerate InitSegment as audio detected"),d=this.generateIS(e,t,i,a)),u=this.remuxAudio(e,g,this.isAudioContiguous,a,m||E||o===it?v:void 0),E){var x=u?u.endPTS-u.startPTS:0;t.inputTimeScale||(R.warn("[mp4-remuxer]: regenerate InitSegment as video detected"),d=this.generateIS(e,t,i,a)),l=this.remuxVideo(t,v,A,x)}}else E&&(l=this.remuxVideo(t,v,A,0));l&&(l.firstKeyFrame=k,l.independent=-1!==k,l.firstKeyFramePTS=w)}}return this.ISGenerated&&this._initPTS&&this._initDTS&&(r.samples.length&&(f=Hn(r,i,this._initPTS,this._initDTS)),n.samples.length&&(c=qn(n,i,this._initPTS))),{audio:u,video:l,initSegment:d,independent:h,text:c,id3:f}},t.generateIS=function(e,t,r,n){var i,a,s,o=e.samples,l=t.samples,u=this.typeSupported,d={},c=this._initPTS,f=!c||n,h="audio/mp4";if(f&&(i=a=1/0),e.config&&o.length){switch(e.timescale=e.samplerate,e.segmentCodec){case"mp3":u.mpeg?(h="audio/mpeg",e.codec=""):u.mp3&&(e.codec="mp3");break;case"ac3":e.codec="ac-3"}d.audio={id:"audio",container:h,codec:e.codec,initSegment:"mp3"===e.segmentCodec&&u.mpeg?new Uint8Array(0):Fn.initSegment([e]),metadata:{channelCount:e.channelCount}},f&&(s=e.inputTimeScale,c&&s===c.timescale?f=!1:i=a=o[0].pts-Math.round(s*r))}if(t.sps&&t.pps&&l.length){if(t.timescale=t.inputTimeScale,d.video={id:"main",container:"video/mp4",codec:t.codec,initSegment:Fn.initSegment([t]),metadata:{width:t.width,height:t.height}},f)if(s=t.inputTimeScale,c&&s===c.timescale)f=!1;else{var g=this.getVideoStartPts(l),v=Math.round(s*r);a=Math.min(a,jn(l[0].dts,g)-v),i=Math.min(i,g-v)}this.videoTrackConfig={width:t.width,height:t.height,pixelRatio:t.pixelRatio}}if(Object.keys(d).length)return this.ISGenerated=!0,f?(this._initPTS={baseTime:i,timescale:s},this._initDTS={baseTime:a,timescale:s}):i=s=void 0,{tracks:d,initPTS:i,timescale:s}},t.remuxVideo=function(e,t,r,n){var i,a,s=e.inputTimeScale,o=e.samples,u=[],d=o.length,c=this._initPTS,f=this.nextAvcDts,h=8,g=this.videoSampleDuration,v=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,m=!1;if(!r||null===f){var y=t*s,b=o[0].pts-jn(o[0].dts,o[0].pts);Bn&&null!==f&&Math.abs(y-b-f)<15e3?r=!0:f=y-b}for(var T=c.baseTime*s/c.timescale,L=0;L<d;L++){var P=o[L];P.pts=jn(P.pts-T,f),P.dts=jn(P.dts-T,f),P.dts<o[L>0?L-1:L].dts&&(m=!0)}m&&o.sort((function(e,t){var r=e.dts-t.dts,n=e.pts-t.pts;return r||n})),i=o[0].dts;var w=o[o.length-1].dts-i,A=w?Math.round(w/(d-1)):g||e.inputTimeScale/30;if(r){var k=i-f,C=k>A,D=k<-1;if((C||D)&&(C?R.warn("AVC: "+Nn(k,!0)+" ms ("+k+"dts) hole between fragments detected at "+t.toFixed(3)):R.warn("AVC: "+Nn(-k,!0)+" ms ("+k+"dts) overlapping between fragments detected at "+t.toFixed(3)),!D||f>=o[0].pts||Bn)){i=f;var I=o[0].pts-k;if(C)o[0].dts=i,o[0].pts=I;else for(var x=0;x<o.length&&!(o[x].dts>I);x++)o[x].dts-=k,o[x].pts-=k;R.log("Video: Initial PTS/DTS adjusted: "+Nn(I,!0)+"/"+Nn(i,!0)+", delta: "+Nn(k,!0)+" ms")}}for(var O=0,M=0,F=i=Math.max(0,i),N=0;N<d;N++){for(var B=o[N],U=B.units,G=U.length,j=0,H=0;H<G;H++)j+=U[H].data.length;M+=j,O+=G,B.length=j,B.dts<F?(B.dts=F,F+=A/4|0||1):F=B.dts,v=Math.min(B.pts,v),p=Math.max(B.pts,p)}a=o[d-1].dts;var q,V=M+4*O+8;try{q=new Uint8Array(V)}catch(e){return void this.observer.emit(E.ERROR,E.ERROR,{type:S.MUX_ERROR,details:_.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:V,reason:"fail allocating video mdat "+V})}var W=new DataView(q.buffer);W.setUint32(0,V),q.set(Fn.types.mdat,4);for(var K=!1,z=Number.POSITIVE_INFINITY,Y=Number.POSITIVE_INFINITY,X=Number.NEGATIVE_INFINITY,J=Number.NEGATIVE_INFINITY,Q=0;Q<d;Q++){for(var Z=o[Q],$=Z.units,ee=0,te=0,re=$.length;te<re;te++){var ne=$[te],ie=ne.data,ae=ne.data.byteLength;W.setUint32(h,ae),h+=4,q.set(ie,h),h+=ae,ee+=4+ae}var se=void 0;if(Q<d-1)g=o[Q+1].dts-Z.dts,se=o[Q+1].pts-Z.pts;else{var oe=this.config,le=Q>0?Z.dts-o[Q-1].dts:A;if(se=Q>0?Z.pts-o[Q-1].pts:A,oe.stretchShortVideoTrack&&null!==this.nextAudioPts){var ue=Math.floor(oe.maxBufferHole*s),de=(n?v+n*s:this.nextAudioPts)-Z.pts;de>ue?((g=de-le)<0?g=le:K=!0,R.log("[mp4-remuxer]: It is approximately "+de/90+" ms to the next segment; using duration "+g/90+" ms for the last video frame.")):g=le}else g=le}var ce=Math.round(Z.pts-Z.dts);z=Math.min(z,g),X=Math.max(X,g),Y=Math.min(Y,se),J=Math.max(J,se),u.push(new Vn(Z.key,g,ee,ce))}if(u.length)if(Bn){if(Bn<70){var fe=u[0].flags;fe.dependsOn=2,fe.isNonSync=0}}else if(Un&&J-Y<X-z&&A/X<.025&&0===u[0].cts){R.warn("Found irregular gaps in sample duration. Using PTS instead of DTS to determine MP4 sample duration.");for(var he=i,ge=0,ve=u.length;ge<ve;ge++){var pe=he+u[ge].duration,me=he+u[ge].cts;if(ge<ve-1){var ye=pe+u[ge+1].cts;u[ge].duration=ye-me}else u[ge].duration=ge?u[ge-1].duration:A;u[ge].cts=0,he=pe}}g=K||!g?A:g,this.nextAvcDts=f=a+g,this.videoSampleDuration=g,this.isVideoContiguous=!0;var be={data1:Fn.moof(e.sequenceNumber++,i,l({},e,{samples:u})),data2:q,startPTS:v/s,endPTS:(p+g)/s,startDTS:i/s,endDTS:f/s,type:"video",hasAudio:!1,hasVideo:!0,nb:u.length,dropped:e.dropped};return e.samples=[],e.dropped=0,be},t.getSamplesPerFrame=function(e){switch(e.segmentCodec){case"mp3":return 1152;case"ac3":return 1536;default:return 1024}},t.remuxAudio=function(e,t,r,n,i){var a=e.inputTimeScale,s=a/(e.samplerate?e.samplerate:a),o=this.getSamplesPerFrame(e),u=o*s,d=this._initPTS,c="mp3"===e.segmentCodec&&this.typeSupported.mpeg,f=[],h=void 0!==i,g=e.samples,v=c?0:8,p=this.nextAudioPts||-1,m=t*a,y=d.baseTime*a/d.timescale;if(this.isAudioContiguous=r=r||g.length&&p>0&&(n&&Math.abs(m-p)<9e3||Math.abs(jn(g[0].pts-y,m)-p)<20*u),g.forEach((function(e){e.pts=jn(e.pts-y,m)})),!r||p<0){if(g=g.filter((function(e){return e.pts>=0})),!g.length)return;p=0===i?0:n&&!h?Math.max(0,m):g[0].pts}if("aac"===e.segmentCodec)for(var b=this.config.maxAudioFramesDrift,T=0,L=p;T<g.length;T++){var P=g[T],w=P.pts,A=w-L,k=Math.abs(1e3*A/a);if(A<=-b*u&&h)0===T&&(R.warn("Audio frame @ "+(w/a).toFixed(3)+"s overlaps nextAudioPts by "+Math.round(1e3*A/a)+" ms."),this.nextAudioPts=p=L=w);else if(A>=b*u&&k<1e4&&h){var C=Math.round(A/u);(L=w-C*u)<0&&(C--,L+=u),0===T&&(this.nextAudioPts=p=L),R.warn("[mp4-remuxer]: Injecting "+C+" audio frame @ "+(L/a).toFixed(3)+"s due to "+Math.round(1e3*A/a)+" ms gap.");for(var D=0;D<C;D++){var I=Math.max(L,0),x=On.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);x||(R.log("[mp4-remuxer]: Unable to get silent frame for given audio codec; duplicating last frame instead."),x=P.unit.subarray()),g.splice(T,0,{unit:x,pts:I}),L+=u,T++}}P.pts=L,L+=u}for(var O,M=null,F=null,N=0,B=g.length;B--;)N+=g[B].unit.byteLength;for(var U=0,G=g.length;U<G;U++){var j=g[U],H=j.unit,q=j.pts;if(null!==F)f[U-1].duration=Math.round((q-F)/s);else{if(r&&"aac"===e.segmentCodec&&(q=p),M=q,!(N>0))return;N+=v;try{O=new Uint8Array(N)}catch(e){return void this.observer.emit(E.ERROR,E.ERROR,{type:S.MUX_ERROR,details:_.REMUX_ALLOC_ERROR,fatal:!1,error:e,bytes:N,reason:"fail allocating audio mdat "+N})}c||(new DataView(O.buffer).setUint32(0,N),O.set(Fn.types.mdat,4))}O.set(H,v);var V=H.byteLength;v+=V,f.push(new Vn(!0,o,V,0)),F=q}var W=f.length;if(W){var K=f[f.length-1];this.nextAudioPts=p=F+s*K.duration;var z=c?new Uint8Array(0):Fn.moof(e.sequenceNumber++,M/s,l({},e,{samples:f}));e.samples=[];var Y=M/a,X=p/a,J={data1:z,data2:O,startPTS:Y,endPTS:X,startDTS:Y,endDTS:X,type:"audio",hasAudio:!0,hasVideo:!1,nb:W};return this.isAudioContiguous=!0,J}},t.remuxEmptyAudio=function(e,t,r,n){var i=e.inputTimeScale,a=i/(e.samplerate?e.samplerate:i),s=this.nextAudioPts,o=this._initDTS,l=9e4*o.baseTime/o.timescale,u=(null!==s?s:n.startDTS*i)+l,d=n.endDTS*i+l,c=1024*a,f=Math.ceil((d-u)/c),h=On.getSilentFrame(e.manifestCodec||e.codec,e.channelCount);if(R.warn("[mp4-remuxer]: remux empty Audio"),h){for(var g=[],v=0;v<f;v++){var p=u+v*c;g.push({unit:h,pts:p,dts:p})}return e.samples=g,this.remuxAudio(e,t,r,!1)}R.trace("[mp4-remuxer]: Unable to remuxEmptyAudio since we were unable to get a silent frame for given audio codec")},e}();function jn(e,t){var r;if(null===t)return e;for(r=t<e?-8589934592:8589934592;Math.abs(e-t)>4294967296;)e+=r;return e}function Hn(e,t,r,n){var i=e.samples.length;if(i){for(var a=e.inputTimeScale,s=0;s<i;s++){var o=e.samples[s];o.pts=jn(o.pts-r.baseTime*a/r.timescale,t*a)/a,o.dts=jn(o.dts-n.baseTime*a/n.timescale,t*a)/a}var l=e.samples;return e.samples=[],{samples:l}}}function qn(e,t,r){var n=e.samples.length;if(n){for(var i=e.inputTimeScale,a=0;a<n;a++){var s=e.samples[a];s.pts=jn(s.pts-r.baseTime*i/r.timescale,t*i)/i}e.samples.sort((function(e,t){return e.pts-t.pts}));var o=e.samples;return e.samples=[],{samples:o}}}var Vn=function(e,t,r,n){this.size=void 0,this.duration=void 0,this.cts=void 0,this.flags=void 0,this.duration=t,this.size=r,this.cts=n,this.flags={isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:e?2:1,isNonSync:e?0:1}},Wn=function(){function e(){this.emitInitSegment=!1,this.audioCodec=void 0,this.videoCodec=void 0,this.initData=void 0,this.initPTS=null,this.initTracks=void 0,this.lastEndTime=null}var t=e.prototype;return t.destroy=function(){},t.resetTimeStamp=function(e){this.initPTS=e,this.lastEndTime=null},t.resetNextTimestamp=function(){this.lastEndTime=null},t.resetInitSegment=function(e,t,r,n){this.audioCodec=t,this.videoCodec=r,this.generateInitSegment(function(e,t){if(!e||!t)return e;var r=t.keyId;return r&&t.isCommonEncryption&&ve(e,["moov","trak"]).forEach((function(e){var t=ve(e,["mdia","minf","stbl","stsd"])[0].subarray(8),n=ve(t,["enca"]),i=n.length>0;i||(n=ve(t,["encv"])),n.forEach((function(e){ve(i?e.subarray(28):e.subarray(78),["sinf"]).forEach((function(e){var t=function(e){var t=ve(e,["schm"])[0];if(t){var r=ue(t.subarray(4,8));if("cbcs"===r||"cenc"===r)return ve(e,["schi","tenc"])[0]}return R.error("[eme] missing 'schm' box"),null}(e);if(t){var n=t.subarray(8,24);n.some((function(e){return 0!==e}))||(R.log("[eme] Patching keyId in 'enc"+(i?"a":"v")+">sinf>>tenc' box: "+ae(n)+" -> "+ae(r)),t.set(r,8))}}))}))})),e}(e,n)),this.emitInitSegment=!0},t.generateInitSegment=function(e){var t=this.audioCodec,r=this.videoCodec;if(null==e||!e.byteLength)return this.initTracks=void 0,void(this.initData=void 0);var n=this.initData=me(e);n.audio&&(t=Kn(n.audio,O)),n.video&&(r=Kn(n.video,M));var i={};n.audio&&n.video?i.audiovideo={container:"video/mp4",codec:t+","+r,initSegment:e,id:"main"}:n.audio?i.audio={container:"audio/mp4",codec:t,initSegment:e,id:"audio"}:n.video?i.video={container:"video/mp4",codec:r,initSegment:e,id:"main"}:R.warn("[passthrough-remuxer.ts]: initSegment does not contain moov or trak boxes."),this.initTracks=i},t.remux=function(e,t,r,n,i,a){var s,o,l=this.initPTS,u=this.lastEndTime,d={audio:void 0,video:void 0,text:n,id3:r,initSegment:void 0};m(u)||(u=this.lastEndTime=i||0);var c=t.samples;if(null==c||!c.length)return d;var f={initPTS:void 0,timescale:1},h=this.initData;if(null!=(s=h)&&s.length||(this.generateInitSegment(c),h=this.initData),null==(o=h)||!o.length)return R.warn("[passthrough-remuxer.ts]: Failed to generate initSegment."),d;this.emitInitSegment&&(f.tracks=this.initTracks,this.emitInitSegment=!1);var g=function(e,t){for(var r=0,n=0,i=0,a=ve(e,["moof","traf"]),s=0;s<a.length;s++){var o=a[s],l=ve(o,["tfhd"])[0],u=t[ce(l,4)];if(u){var d=u.default,c=ce(l,0)|(null==d?void 0:d.flags),f=null==d?void 0:d.duration;8&c&&(f=ce(l,2&c?12:8));for(var h=u.timescale||9e4,g=ve(o,["trun"]),v=0;v<g.length;v++)!(r=_e(g[v]))&&f&&(r=f*ce(g[v],4)),u.type===M?n+=r/h:u.type===O&&(i+=r/h)}}if(0===n&&0===i){for(var p=1/0,y=0,b=0,E=ve(e,["sidx"]),S=0;S<E.length;S++){var _=pe(E[S]);if(null!=_&&_.references){p=Math.min(p,_.earliestPresentationTime/_.timescale);var T=_.references.reduce((function(e,t){return e+t.info.duration||0}),0);b=(y=Math.max(y,T+_.earliestPresentationTime/_.timescale))-p}}if(b&&m(b))return b}return n||i}(c,h),v=function(e,t){return ve(t,["moof","traf"]).reduce((function(t,r){var n=ve(r,["tfdt"])[0],i=n[0],a=ve(r,["tfhd"]).reduce((function(t,r){var a=ce(r,4),s=e[a];if(s){var o=ce(n,4);if(1===i){if(o===se)return R.warn("[mp4-demuxer]: Ignoring assumed invalid signed 64-bit track fragment decode time"),t;o*=se+1,o+=ce(n,8)}var l=o/(s.timescale||9e4);if(m(l)&&(null===t||l<t))return l}return t}),null);return null!==a&&m(a)&&(null===t||a<t)?a:t}),null)}(h,c),p=null===v?i:v;(function(e,t,r,n){if(null===e)return!0;var i=Math.max(n,1),a=t-e.baseTime/e.timescale;return Math.abs(a-r)>i}(l,p,i,g)||f.timescale!==l.timescale&&a)&&(f.initPTS=p-i,l&&1===l.timescale&&R.warn("Adjusting initPTS by "+(f.initPTS-l.baseTime)),this.initPTS=l={baseTime:f.initPTS,timescale:1});var y=e?p-l.baseTime/l.timescale:u,b=y+g;!function(e,t,r){ve(t,["moof","traf"]).forEach((function(t){ve(t,["tfhd"]).forEach((function(n){var i=ce(n,4),a=e[i];if(a){var s=a.timescale||9e4;ve(t,["tfdt"]).forEach((function(e){var t=e[0],n=r*s;if(n){var i=ce(e,4);if(0===t)i-=n,ge(e,4,i=Math.max(i,0));else{i*=Math.pow(2,32),i+=ce(e,8),i-=n,i=Math.max(i,0);var a=Math.floor(i/(se+1)),o=Math.floor(i%(se+1));ge(e,4,a),ge(e,8,o)}}}))}}))}))}(h,c,l.baseTime/l.timescale),g>0?this.lastEndTime=b:(R.warn("Duration parsed from mp4 should be greater than zero"),this.resetNextTimestamp());var E=!!h.audio,S=!!h.video,_="";E&&(_+="audio"),S&&(_+="video");var T={data1:c,startPTS:y,startDTS:y,endPTS:b,endDTS:b,type:_,hasAudio:E,hasVideo:S,nb:1,dropped:0};return d.audio="audio"===T.type?T:void 0,d.video="audio"!==T.type?T:void 0,d.initSegment=f,d.id3=Hn(r,i,l,l),n.samples.length&&(d.text=qn(n,i,l)),d},e}();function Kn(e,t){var r=null==e?void 0:e.codec;if(r&&r.length>4)return r;if(t===O){if("ec-3"===r||"ac-3"===r||"alac"===r)return r;if("fLaC"===r||"Opus"===r)return Be(r,!1);var n="mp4a.40.5";return R.info('Parsed audio codec "'+r+'" or audio object type not handled. Using "'+n+'"'),n}return R.warn('Unhandled video codec "'+r+'"'),"hvc1"===r||"hev1"===r?"hvc1.1.6.L120.90":"av01"===r?"av01.0.04M.08":"avc1.42e01e"}var zn,Yn="undefined"!=typeof self?self:void 0;try{zn=self.performance.now.bind(self.performance)}catch(e){R.debug("Unable to use Performance API on this environment"),zn=null==Yn?void 0:Yn.Date.now}var Xn=[{demux:En,remux:Wn},{demux:wn,remux:Gn},{demux:yn,remux:Gn},{demux:xn,remux:Gn}],Jn=function(){function e(e,t,r,n,i){this.async=!1,this.observer=void 0,this.typeSupported=void 0,this.config=void 0,this.vendor=void 0,this.id=void 0,this.demuxer=void 0,this.remuxer=void 0,this.decrypter=void 0,this.probe=void 0,this.decryptionPromise=null,this.transmuxConfig=void 0,this.currentTransmuxState=void 0,this.observer=e,this.typeSupported=t,this.config=r,this.vendor=n,this.id=i}var t=e.prototype;return t.configure=function(e){this.transmuxConfig=e,this.decrypter&&this.decrypter.reset()},t.push=function(e,t,r,n){var i=this,a=r.transmuxing;a.executeStart=zn();var s=new Uint8Array(e),o=this.currentTransmuxState,l=this.transmuxConfig;n&&(this.currentTransmuxState=n);var u=n||o,d=u.contiguous,c=u.discontinuity,f=u.trackSwitch,h=u.accurateTimeOffset,g=u.timeOffset,v=u.initSegmentChange,p=l.audioCodec,m=l.videoCodec,y=l.defaultInitPts,b=l.duration,T=l.initSegmentData,L=function(e,t){var r=null;return e.byteLength>0&&null!=(null==t?void 0:t.key)&&null!==t.iv&&null!=t.method&&(r=t),r}(s,t);if(L&&"AES-128"===L.method){var P=this.getDecrypter();if(!P.isSync())return this.decryptionPromise=P.webCryptoDecrypt(s,L.key.buffer,L.iv.buffer).then((function(e){var t=i.push(e,null,r);return i.decryptionPromise=null,t})),this.decryptionPromise;var w=P.softwareDecrypt(s,L.key.buffer,L.iv.buffer);if(r.part>-1&&(w=P.flush()),!w)return a.executeEnd=zn(),Qn(r);s=new Uint8Array(w)}var A=this.needsProbing(c,f);if(A){var k=this.configureTransmuxer(s);if(k)return R.warn("[transmuxer] "+k.message),this.observer.emit(E.ERROR,E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,fatal:!1,error:k,reason:k.message}),a.executeEnd=zn(),Qn(r)}(c||f||v||A)&&this.resetInitSegment(T,p,m,b,t),(c||v||A)&&this.resetInitialTimestamp(y),d||this.resetContiguity();var C=this.transmux(s,L,g,h,r),D=this.currentTransmuxState;return D.contiguous=!0,D.discontinuity=!1,D.trackSwitch=!1,a.executeEnd=zn(),C},t.flush=function(e){var t=this,r=e.transmuxing;r.executeStart=zn();var n=this.decrypter,i=this.currentTransmuxState,a=this.decryptionPromise;if(a)return a.then((function(){return t.flush(e)}));var s=[],o=i.timeOffset;if(n){var l=n.flush();l&&s.push(this.push(l,null,e))}var u=this.demuxer,d=this.remuxer;if(!u||!d)return r.executeEnd=zn(),[Qn(e)];var c=u.flush(o);return Zn(c)?c.then((function(r){return t.flushRemux(s,r,e),s})):(this.flushRemux(s,c,e),s)},t.flushRemux=function(e,t,r){var n=t.audioTrack,i=t.videoTrack,a=t.id3Track,s=t.textTrack,o=this.currentTransmuxState,l=o.accurateTimeOffset,u=o.timeOffset;R.log("[transmuxer.ts]: Flushed fragment "+r.sn+(r.part>-1?" p: "+r.part:"")+" of level "+r.level);var d=this.remuxer.remux(n,i,a,s,u,l,!0,this.id);e.push({remuxResult:d,chunkMeta:r}),r.transmuxing.executeEnd=zn()},t.resetInitialTimestamp=function(e){var t=this.demuxer,r=this.remuxer;t&&r&&(t.resetTimeStamp(e),r.resetTimeStamp(e))},t.resetContiguity=function(){var e=this.demuxer,t=this.remuxer;e&&t&&(e.resetContiguity(),t.resetNextTimestamp())},t.resetInitSegment=function(e,t,r,n,i){var a=this.demuxer,s=this.remuxer;a&&s&&(a.resetInitSegment(e,t,r,n),s.resetInitSegment(e,t,r,i))},t.destroy=function(){this.demuxer&&(this.demuxer.destroy(),this.demuxer=void 0),this.remuxer&&(this.remuxer.destroy(),this.remuxer=void 0)},t.transmux=function(e,t,r,n,i){return t&&"SAMPLE-AES"===t.method?this.transmuxSampleAes(e,t,r,n,i):this.transmuxUnencrypted(e,r,n,i)},t.transmuxUnencrypted=function(e,t,r,n){var i=this.demuxer.demux(e,t,!1,!this.config.progressive),a=i.audioTrack,s=i.videoTrack,o=i.id3Track,l=i.textTrack;return{remuxResult:this.remuxer.remux(a,s,o,l,t,r,!1,this.id),chunkMeta:n}},t.transmuxSampleAes=function(e,t,r,n,i){var a=this;return this.demuxer.demuxSampleAes(e,t,r).then((function(e){return{remuxResult:a.remuxer.remux(e.audioTrack,e.videoTrack,e.id3Track,e.textTrack,r,n,!1,a.id),chunkMeta:i}}))},t.configureTransmuxer=function(e){for(var t,r=this.config,n=this.observer,i=this.typeSupported,a=this.vendor,s=0,o=Xn.length;s<o;s++){var l;if(null!=(l=Xn[s].demux)&&l.probe(e)){t=Xn[s];break}}if(!t)return new Error("Failed to find demuxer by probing fragment data");var u=this.demuxer,d=this.remuxer,c=t.remux,f=t.demux;d&&d instanceof c||(this.remuxer=new c(n,r,i,a)),u&&u instanceof f||(this.demuxer=new f(n,r,i),this.probe=f.probe)},t.needsProbing=function(e,t){return!this.demuxer||!this.remuxer||e||t},t.getDecrypter=function(){var e=this.decrypter;return e||(e=this.decrypter=new Fr(this.config)),e},e}(),Qn=function(e){return{remuxResult:{},chunkMeta:e}};function Zn(e){return"then"in e&&e.then instanceof Function}var $n=function(e,t,r,n,i){this.audioCodec=void 0,this.videoCodec=void 0,this.initSegmentData=void 0,this.duration=void 0,this.defaultInitPts=void 0,this.audioCodec=e,this.videoCodec=t,this.initSegmentData=r,this.duration=n,this.defaultInitPts=i||null},ei=function(e,t,r,n,i,a){this.discontinuity=void 0,this.contiguous=void 0,this.accurateTimeOffset=void 0,this.trackSwitch=void 0,this.timeOffset=void 0,this.initSegmentChange=void 0,this.discontinuity=e,this.contiguous=t,this.accurateTimeOffset=r,this.trackSwitch=n,this.timeOffset=i,this.initSegmentChange=a},ti={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function i(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function a(e,t,n,a,s){if("function"!=typeof n)throw new TypeError("The listener must be a function");var o=new i(n,a||e,s),l=r?r+t:t;return e._events[l]?e._events[l].fn?e._events[l]=[e._events[l],o]:e._events[l].push(o):(e._events[l]=o,e._eventsCount++),e}function s(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function o(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),o.prototype.eventNames=function(){var e,n,i=[];if(0===this._eventsCount)return i;for(n in e=this._events)t.call(e,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},o.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,s=new Array(a);i<a;i++)s[i]=n[i].fn;return s},o.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},o.prototype.emit=function(e,t,n,i,a,s){var o=r?r+e:e;if(!this._events[o])return!1;var l,u,d=this._events[o],c=arguments.length;if(d.fn){switch(d.once&&this.removeListener(e,d.fn,void 0,!0),c){case 1:return d.fn.call(d.context),!0;case 2:return d.fn.call(d.context,t),!0;case 3:return d.fn.call(d.context,t,n),!0;case 4:return d.fn.call(d.context,t,n,i),!0;case 5:return d.fn.call(d.context,t,n,i,a),!0;case 6:return d.fn.call(d.context,t,n,i,a,s),!0}for(u=1,l=new Array(c-1);u<c;u++)l[u-1]=arguments[u];d.fn.apply(d.context,l)}else{var f,h=d.length;for(u=0;u<h;u++)switch(d[u].once&&this.removeListener(e,d[u].fn,void 0,!0),c){case 1:d[u].fn.call(d[u].context);break;case 2:d[u].fn.call(d[u].context,t);break;case 3:d[u].fn.call(d[u].context,t,n);break;case 4:d[u].fn.call(d[u].context,t,n,i);break;default:if(!l)for(f=1,l=new Array(c-1);f<c;f++)l[f-1]=arguments[f];d[u].fn.apply(d[u].context,l)}}return!0},o.prototype.on=function(e,t,r){return a(this,e,t,r,!1)},o.prototype.once=function(e,t,r){return a(this,e,t,r,!0)},o.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn!==t||i&&!o.once||n&&o.context!==n||s(this,a);else{for(var l=0,u=[],d=o.length;l<d;l++)(o[l].fn!==t||i&&!o[l].once||n&&o[l].context!==n)&&u.push(o[l]);u.length?this._events[a]=1===u.length?u[0]:u:s(this,a)}return this},o.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new n,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=r,o.EventEmitter=o,e.exports=o}(ti);var ri=g(ti.exports);function ni(e,t){if(!((r=t.remuxResult).audio||r.video||r.text||r.id3||r.initSegment))return!1;var r,n=[],i=t.remuxResult,a=i.audio,s=i.video;return a&&ii(n,a),s&&ii(n,s),e.postMessage({event:"transmuxComplete",data:t},n),!0}function ii(e,t){t.data1&&e.push(t.data1.buffer),t.data2&&e.push(t.data2.buffer)}function ai(e,t,r){t.reduce((function(t,r){return ni(e,r)||t}),!1)||e.postMessage({event:"transmuxComplete",data:t[0]}),e.postMessage({event:"flush",data:r})}void 0!==o&&o&&function(e){var t=new ri,r=function(t,r){e.postMessage({event:t,data:r})};t.on(E.FRAG_DECRYPTED,r),t.on(E.ERROR,r);e.addEventListener("message",(function(n){var i=n.data;switch(i.cmd){case"init":var a=JSON.parse(i.config);e.transmuxer=new Jn(t,i.typeSupported,a,"",i.id),w(a.debug,i.id),function(){var e=function(e){R[e]=function(t){r("workerLog",{logType:e,message:t})}};for(var t in R)e(t)}(),r("init",null);break;case"configure":e.transmuxer.configure(i.config);break;case"demux":var s=e.transmuxer.push(i.data,i.decryptdata,i.chunkMeta,i.state);Zn(s)?(e.transmuxer.async=!0,s.then((function(t){ni(e,t)})).catch((function(e){r(E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,chunkMeta:i.chunkMeta,fatal:!1,error:e,err:e,reason:"transmuxer-worker push error"})}))):(e.transmuxer.async=!1,ni(e,s));break;case"flush":var o=i.chunkMeta,l=e.transmuxer.flush(o);Zn(l)||e.transmuxer.async?(Zn(l)||(l=Promise.resolve(l)),l.then((function(t){ai(e,t,o)})).catch((function(e){r(E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,chunkMeta:i.chunkMeta,fatal:!1,error:e,err:e,reason:"transmuxer-worker flush error"})}))):ai(e,l,o)}}))}(self);var si=function(){function e(e,t,r,n){var i=this;this.error=null,this.hls=void 0,this.id=void 0,this.observer=void 0,this.frag=null,this.part=null,this.useWorker=void 0,this.workerContext=null,this.onwmsg=void 0,this.transmuxer=null,this.onTransmuxComplete=void 0,this.onFlush=void 0;var a=e.config;this.hls=e,this.id=t,this.useWorker=!!a.enableWorker,this.onTransmuxComplete=r,this.onFlush=n;var o=function(e,t){(t=t||{}).frag=i.frag,t.id=i.id,e===E.ERROR&&(i.error=t.error),i.hls.trigger(e,t)};this.observer=new ri,this.observer.on(E.FRAG_DECRYPTED,o),this.observer.on(E.ERROR,o);var l,u,d,c,f=ke(a.preferManagedMediaSource)||{isTypeSupported:function(){return!1}},h={mpeg:f.isTypeSupported("audio/mpeg"),mp3:f.isTypeSupported('audio/mp4; codecs="mp3"'),ac3:!1};if(!this.useWorker||"undefined"==typeof Worker||(a.workerPath,0))this.transmuxer=new Jn(this.observer,h,a,"",t);else try{a.workerPath?(R.log("loading Web Worker "+a.workerPath+' for "'+t+'"'),this.workerContext=(d=a.workerPath,c=new self.URL(d,self.location.href).href,{worker:new self.Worker(c),scriptURL:c})):(R.log('injecting Web Worker for "'+t+'"'),this.workerContext=(l=new self.Blob(["var exports={};var module={exports:exports};function define(f){f()};define.amd=true;("+s.toString()+")(true);"],{type:"text/javascript"}),u=self.URL.createObjectURL(l),{worker:new self.Worker(u),objectURL:u})),this.onwmsg=function(e){return i.onWorkerMessage(e)};var g=this.workerContext.worker;g.addEventListener("message",this.onwmsg),g.onerror=function(e){var r=new Error(e.message+"  ("+e.filename+":"+e.lineno+")");a.enableWorker=!1,R.warn('Error in "'+t+'" Web Worker, fallback to inline'),i.hls.trigger(E.ERROR,{type:S.OTHER_ERROR,details:_.INTERNAL_EXCEPTION,fatal:!1,event:"demuxerWorker",error:r})},g.postMessage({cmd:"init",typeSupported:h,vendor:"",id:t,config:JSON.stringify(a)})}catch(e){R.warn('Error setting up "'+t+'" Web Worker, fallback to inline',e),this.resetWorker(),this.error=null,this.transmuxer=new Jn(this.observer,h,a,"",t)}}var t=e.prototype;return t.resetWorker=function(){if(this.workerContext){var e=this.workerContext,t=e.worker,r=e.objectURL;r&&self.URL.revokeObjectURL(r),t.removeEventListener("message",this.onwmsg),t.onerror=null,t.terminate(),this.workerContext=null}},t.destroy=function(){if(this.workerContext)this.resetWorker(),this.onwmsg=void 0;else{var e=this.transmuxer;e&&(e.destroy(),this.transmuxer=null)}var t=this.observer;t&&t.removeAllListeners(),this.frag=null,this.observer=null,this.hls=null},t.push=function(e,t,r,n,i,a,s,o,l,u){var d,c,f=this;l.transmuxing.start=self.performance.now();var h=this.transmuxer,g=a?a.start:i.start,v=i.decryptdata,p=this.frag,m=!(p&&i.cc===p.cc),y=!(p&&l.level===p.level),b=p?l.sn-p.sn:-1,E=this.part?l.part-this.part.index:-1,S=0===b&&l.id>1&&l.id===(null==p?void 0:p.stats.chunkCount),_=!y&&(1===b||0===b&&(1===E||S&&E<=0)),T=self.performance.now();(y||b||0===i.stats.parsing.start)&&(i.stats.parsing.start=T),!a||!E&&_||(a.stats.parsing.start=T);var L=!(p&&(null==(d=i.initSegment)?void 0:d.url)===(null==(c=p.initSegment)?void 0:c.url)),P=new ei(m,_,o,y,g,L);if(!_||m||L){R.log("[transmuxer-interface, "+i.type+"]: Starting new transmux session for sn: "+l.sn+" p: "+l.part+" level: "+l.level+" id: "+l.id+"\n        discontinuity: "+m+"\n        trackSwitch: "+y+"\n        contiguous: "+_+"\n        accurateTimeOffset: "+o+"\n        timeOffset: "+g+"\n        initSegmentChange: "+L);var w=new $n(r,n,t,s,u);this.configureTransmuxer(w)}if(this.frag=i,this.part=a,this.workerContext)this.workerContext.worker.postMessage({cmd:"demux",data:e,decryptdata:v,chunkMeta:l,state:P},e instanceof ArrayBuffer?[e]:[]);else if(h){var A=h.push(e,v,l,P);Zn(A)?(h.async=!0,A.then((function(e){f.handleTransmuxComplete(e)})).catch((function(e){f.transmuxerError(e,l,"transmuxer-interface push error")}))):(h.async=!1,this.handleTransmuxComplete(A))}},t.flush=function(e){var t=this;e.transmuxing.start=self.performance.now();var r=this.transmuxer;if(this.workerContext)this.workerContext.worker.postMessage({cmd:"flush",chunkMeta:e});else if(r){var n=r.flush(e);Zn(n)||r.async?(Zn(n)||(n=Promise.resolve(n)),n.then((function(r){t.handleFlushResult(r,e)})).catch((function(r){t.transmuxerError(r,e,"transmuxer-interface flush error")}))):this.handleFlushResult(n,e)}},t.transmuxerError=function(e,t,r){this.hls&&(this.error=e,this.hls.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.FRAG_PARSING_ERROR,chunkMeta:t,frag:this.frag||void 0,fatal:!1,error:e,err:e,reason:r}))},t.handleFlushResult=function(e,t){var r=this;e.forEach((function(e){r.handleTransmuxComplete(e)})),this.onFlush(t)},t.onWorkerMessage=function(e){var t=e.data;if(null!=t&&t.event){var r=this.hls;if(this.hls)switch(t.event){case"init":var n,i=null==(n=this.workerContext)?void 0:n.objectURL;i&&self.URL.revokeObjectURL(i);break;case"transmuxComplete":this.handleTransmuxComplete(t.data);break;case"flush":this.onFlush(t.data);break;case"workerLog":R[t.data.logType]&&R[t.data.logType](t.data.message);break;default:t.data=t.data||{},t.data.frag=this.frag,t.data.id=this.id,r.trigger(t.event,t.data)}}else R.warn("worker message received with no "+(t?"event name":"data"))},t.configureTransmuxer=function(e){var t=this.transmuxer;this.workerContext?this.workerContext.worker.postMessage({cmd:"configure",config:e}):t&&t.configure(e)},t.handleTransmuxComplete=function(e){e.chunkMeta.transmuxing.end=self.performance.now(),this.onTransmuxComplete(e)},e}(),oi=function(){function e(e,t,r,n){this.config=void 0,this.media=null,this.fragmentTracker=void 0,this.hls=void 0,this.nudgeRetry=0,this.stallReported=!1,this.stalled=null,this.moved=!1,this.seeking=!1,this.config=e,this.media=t,this.fragmentTracker=r,this.hls=n}var t=e.prototype;return t.destroy=function(){this.media=null,this.hls=this.fragmentTracker=null},t.poll=function(e,t){var r=this.config,n=this.media,i=this.stalled;if(null!==n){var a=n.currentTime,s=n.seeking,o=this.seeking&&!s,l=!this.seeking&&s;if(this.seeking=s,a===e)if(l||o)this.stalled=null;else if(n.paused&&!s||n.ended||0===n.playbackRate||!zt.getBuffered(n).length)this.nudgeRetry=0;else{var u=zt.bufferInfo(n,a,0),d=u.nextStart||0;if(s){var c=u.len>2,f=!d||t&&t.start<=a||d-a>2&&!this.fragmentTracker.getPartialFragment(a);if(c||f)return;this.moved=!1}if(!this.moved&&null!==this.stalled){var h;if(!(u.len>0||d))return;var g=Math.max(d,u.start||0)-a,v=this.hls.levels?this.hls.levels[this.hls.currentLevel]:null,p=(null==v||null==(h=v.details)?void 0:h.live)?2*v.details.targetduration:2,m=this.fragmentTracker.getPartialFragment(a);if(g>0&&(g<=p||m))return void(n.paused||this._trySkipBufferHole(m))}var y=self.performance.now();if(null!==i){var b=y-i;if(s||!(b>=250)||(this._reportStall(u),this.media)){var E=zt.bufferInfo(n,a,r.maxBufferHole);this._tryFixBufferStall(E,b)}}else this.stalled=y}else if(this.moved=!0,s||(this.nudgeRetry=0),null!==i){if(this.stallReported){var S=self.performance.now()-i;R.warn("playback not stuck anymore @"+a+", after "+Math.round(S)+"ms"),this.stallReported=!1}this.stalled=null}}},t._tryFixBufferStall=function(e,t){var r=this.config,n=this.fragmentTracker,i=this.media;if(null!==i){var a=i.currentTime,s=n.getPartialFragment(a);if(s&&(this._trySkipBufferHole(s)||!this.media))return;(e.len>r.maxBufferHole||e.nextStart&&e.nextStart-a<r.maxBufferHole)&&t>1e3*r.highBufferWatchdogPeriod&&(R.warn("Trying to nudge playhead over buffer-hole"),this.stalled=null,this._tryNudgeBuffer())}},t._reportStall=function(e){var t=this.hls,r=this.media;if(!this.stallReported&&r){this.stallReported=!0;var n=new Error("Playback stalling at @"+r.currentTime+" due to low buffer ("+JSON.stringify(e)+")");R.warn(n.message),t.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_STALLED_ERROR,fatal:!1,error:n,buffer:e.len})}},t._trySkipBufferHole=function(e){var t=this.config,r=this.hls,n=this.media;if(null===n)return 0;var i=n.currentTime,a=zt.bufferInfo(n,i,0),s=i<a.start?a.start:a.nextStart;if(s){var o=a.len<=t.maxBufferHole,l=a.len>0&&a.len<1&&n.readyState<3,u=s-i;if(u>0&&(o||l)){if(u>t.maxBufferHole){var d=this.fragmentTracker,c=!1;if(0===i){var f=d.getAppendedFrag(0,nt);f&&s<f.end&&(c=!0)}if(!c){var h=e||d.getAppendedFrag(i,nt);if(h){for(var g=!1,v=h.end;v<s;){var p=d.getPartialFragment(v);if(!p){g=!0;break}v+=p.duration}if(g)return 0}}}var m=Math.max(s+.05,i+.1);if(R.warn("skipping hole, adjusting currentTime from "+i+" to "+m),this.moved=!0,this.stalled=null,n.currentTime=m,e&&!e.gap){var y=new Error("fragment loaded with buffer holes, seeking from "+i+" to "+m);r.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_SEEK_OVER_HOLE,fatal:!1,error:y,reason:y.message,frag:e})}return m}}return 0},t._tryNudgeBuffer=function(){var e=this.config,t=this.hls,r=this.media,n=this.nudgeRetry;if(null!==r){var i=r.currentTime;if(this.nudgeRetry++,n<e.nudgeMaxRetry){var a=i+(n+1)*e.nudgeOffset,s=new Error("Nudging 'currentTime' from "+i+" to "+a);R.warn(s.message),r.currentTime=a,t.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_NUDGE_ON_STALL,error:s,fatal:!1})}else{var o=new Error("Playhead still not moving while enough data buffered @"+i+" after "+e.nudgeMaxRetry+" nudges");R.error(o.message),t.trigger(E.ERROR,{type:S.MEDIA_ERROR,details:_.BUFFER_STALLED_ERROR,error:o,fatal:!0})}}},e}(),li=function(e){function t(t,r,n){var i;return(i=e.call(this,t,r,n,"[stream-controller]",nt)||this).audioCodecSwap=!1,i.gapController=null,i.level=-1,i._forceStartLoad=!1,i.altAudio=!1,i.audioOnly=!1,i.fragPlaying=null,i.onvplaying=null,i.onvseeked=null,i.fragLastKbps=0,i.couldBacktrack=!1,i.backtrackFragment=null,i.audioCodecSwitch=!1,i.videoBuffer=null,i._registerListeners(),i}u(t,e);var r=t.prototype;return r._registerListeners=function(){var e=this.hls;e.on(E.MEDIA_ATTACHED,this.onMediaAttached,this),e.on(E.MEDIA_DETACHING,this.onMediaDetaching,this),e.on(E.MANIFEST_LOADING,this.onManifestLoading,this),e.on(E.MANIFEST_PARSED,this.onManifestParsed,this),e.on(E.LEVEL_LOADING,this.onLevelLoading,this),e.on(E.LEVEL_LOADED,this.onLevelLoaded,this),e.on(E.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.on(E.ERROR,this.onError,this),e.on(E.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.on(E.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.on(E.BUFFER_CREATED,this.onBufferCreated,this),e.on(E.BUFFER_FLUSHED,this.onBufferFlushed,this),e.on(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.on(E.FRAG_BUFFERED,this.onFragBuffered,this)},r._unregisterListeners=function(){var e=this.hls;e.off(E.MEDIA_ATTACHED,this.onMediaAttached,this),e.off(E.MEDIA_DETACHING,this.onMediaDetaching,this),e.off(E.MANIFEST_LOADING,this.onManifestLoading,this),e.off(E.MANIFEST_PARSED,this.onManifestParsed,this),e.off(E.LEVEL_LOADED,this.onLevelLoaded,this),e.off(E.FRAG_LOAD_EMERGENCY_ABORTED,this.onFragLoadEmergencyAborted,this),e.off(E.ERROR,this.onError,this),e.off(E.AUDIO_TRACK_SWITCHING,this.onAudioTrackSwitching,this),e.off(E.AUDIO_TRACK_SWITCHED,this.onAudioTrackSwitched,this),e.off(E.BUFFER_CREATED,this.onBufferCreated,this),e.off(E.BUFFER_FLUSHED,this.onBufferFlushed,this),e.off(E.LEVELS_UPDATED,this.onLevelsUpdated,this),e.off(E.FRAG_BUFFERED,this.onFragBuffered,this)},r.onHandlerDestroying=function(){this._unregisterListeners(),e.prototype.onHandlerDestroying.call(this)},r.startLoad=function(e){if(this.levels){var t=this.lastCurrentTime,r=this.hls;if(this.stopLoad(),this.setInterval(100),this.level=-1,!this.startFragRequested){var n=r.startLevel;-1===n&&(r.config.testBandwidth&&this.levels.length>1?(n=0,this.bitrateTest=!0):n=r.firstAutoLevel),r.nextLoadLevel=n,this.level=r.loadLevel,this.loadedmetadata=!1}t>0&&-1===e&&(this.log("Override startPosition with lastCurrentTime @"+t.toFixed(3)),e=t),this.state=Br,this.nextLoadPosition=this.startPosition=this.lastCurrentTime=e,this.tick()}else this._forceStartLoad=!0,this.state=Nr},r.stopLoad=function(){this._forceStartLoad=!1,e.prototype.stopLoad.call(this)},r.doTick=function(){switch(this.state){case Kr:var e=this.levels,t=this.level,r=null==e?void 0:e[t],n=null==r?void 0:r.details;if(n&&(!n.live||this.levelLastLoaded===r)){if(this.waitForCdnTuneIn(n))break;this.state=Br;break}if(this.hls.nextLoadLevel!==this.level){this.state=Br;break}break;case jr:var i,a=self.performance.now(),s=this.retryDate;if(!s||a>=s||null!=(i=this.media)&&i.seeking){var o=this.levels,l=this.level,u=null==o?void 0:o[l];this.resetStartWhenNotLoaded(u||null),this.state=Br}}this.state===Br&&this.doTickIdle(),this.onTickEnd()},r.onTickEnd=function(){e.prototype.onTickEnd.call(this),this.checkBuffer(),this.checkFragmentChanged()},r.doTickIdle=function(){var e=this.hls,t=this.levelLastLoaded,r=this.levels,n=this.media;if(null!==t&&(n||!this.startFragRequested&&e.config.startFragPrefetch)&&(!this.altAudio||!this.audioOnly)){var i=e.nextLoadLevel;if(null!=r&&r[i]){var a=r[i],s=this.getMainFwdBufferInfo();if(null!==s){var o=this.getLevelDetails();if(o&&this._streamEnded(s,o)){var l={};return this.altAudio&&(l.type="video"),this.hls.trigger(E.BUFFER_EOS,l),void(this.state=Vr)}e.loadLevel!==i&&-1===e.manualLevel&&this.log("Adapting to level "+i+" from level "+this.level),this.level=e.nextLoadLevel=i;var u=a.details;if(!u||this.state===Kr||u.live&&this.levelLastLoaded!==a)return this.level=i,void(this.state=Kr);var d=s.len,c=this.getMaxBufferLength(a.maxBitrate);if(!(d>=c)){this.backtrackFragment&&this.backtrackFragment.start>s.end&&(this.backtrackFragment=null);var f=this.backtrackFragment?this.backtrackFragment.start:s.end,h=this.getNextFragment(f,u);if(this.couldBacktrack&&!this.fragPrevious&&h&&"initSegment"!==h.sn&&this.fragmentTracker.getState(h)!==yr){var g,v=(null!=(g=this.backtrackFragment)?g:h).sn-u.startSN,p=u.fragments[v-1];p&&h.cc===p.cc&&(h=p,this.fragmentTracker.removeFragment(p))}else this.backtrackFragment&&s.len&&(this.backtrackFragment=null);if(h&&this.isLoopLoading(h,f)){if(!h.gap){var m=this.audioOnly&&!this.altAudio?O:M,y=(m===M?this.videoBuffer:this.mediaBuffer)||this.media;y&&this.afterBufferFlushed(y,m,nt)}h=this.getNextFragmentLoopLoading(h,u,s,nt,c)}h&&(!h.initSegment||h.initSegment.data||this.bitrateTest||(h=h.initSegment),this.loadFragment(h,a,f))}}}}},r.loadFragment=function(t,r,n){var i=this.fragmentTracker.getState(t);this.fragCurrent=t,i===vr||i===mr?"initSegment"===t.sn?this._loadInitSegment(t,r):this.bitrateTest?(this.log("Fragment "+t.sn+" of level "+t.level+" is being downloaded to test bitrate and will not be buffered"),this._loadBitrateTestFrag(t,r)):(this.startFragRequested=!0,e.prototype.loadFragment.call(this,t,r,n)):this.clearTrackerIfNeeded(t)},r.getBufferedFrag=function(e){return this.fragmentTracker.getBufferedFrag(e,nt)},r.followingBufferedFrag=function(e){return e?this.getBufferedFrag(e.end+.5):null},r.immediateLevelSwitch=function(){this.abortCurrentFrag(),this.flushMainBuffer(0,Number.POSITIVE_INFINITY)},r.nextLevelSwitch=function(){var e=this.levels,t=this.media;if(null!=t&&t.readyState){var r,n=this.getAppendedFrag(t.currentTime);n&&n.start>1&&this.flushMainBuffer(0,n.start-1);var i=this.getLevelDetails();if(null!=i&&i.live){var a=this.getMainFwdBufferInfo();if(!a||a.len<2*i.targetduration)return}if(!t.paused&&e){var s=e[this.hls.nextLoadLevel],o=this.fragLastKbps;r=o&&this.fragCurrent?this.fragCurrent.duration*s.maxBitrate/(1e3*o)+1:0}else r=0;var l=this.getBufferedFrag(t.currentTime+r);if(l){var u=this.followingBufferedFrag(l);if(u){this.abortCurrentFrag();var d=u.maxStartPTS?u.maxStartPTS:u.start,c=u.duration,f=Math.max(l.end,d+Math.min(Math.max(c-this.config.maxFragLookUpTolerance,c*(this.couldBacktrack?.5:.125)),c*(this.couldBacktrack?.75:.25)));this.flushMainBuffer(f,Number.POSITIVE_INFINITY)}}}},r.abortCurrentFrag=function(){var e=this.fragCurrent;switch(this.fragCurrent=null,this.backtrackFragment=null,e&&(e.abortRequests(),this.fragmentTracker.removeFragment(e)),this.state){case Ur:case Gr:case jr:case Hr:case qr:this.state=Br}this.nextLoadPosition=this.getLoadPosition()},r.flushMainBuffer=function(t,r){e.prototype.flushMainBuffer.call(this,t,r,this.altAudio?"video":null)},r.onMediaAttached=function(t,r){e.prototype.onMediaAttached.call(this,t,r);var n=r.media;this.onvplaying=this.onMediaPlaying.bind(this),this.onvseeked=this.onMediaSeeked.bind(this),n.addEventListener("playing",this.onvplaying),n.addEventListener("seeked",this.onvseeked),this.gapController=new oi(this.config,n,this.fragmentTracker,this.hls)},r.onMediaDetaching=function(){var t=this.media;t&&this.onvplaying&&this.onvseeked&&(t.removeEventListener("playing",this.onvplaying),t.removeEventListener("seeked",this.onvseeked),this.onvplaying=this.onvseeked=null,this.videoBuffer=null),this.fragPlaying=null,this.gapController&&(this.gapController.destroy(),this.gapController=null),e.prototype.onMediaDetaching.call(this)},r.onMediaPlaying=function(){this.tick()},r.onMediaSeeked=function(){var e=this.media,t=e?e.currentTime:null;m(t)&&this.log("Media seeked to "+t.toFixed(3));var r=this.getMainFwdBufferInfo();null!==r&&0!==r.len?this.tick():this.warn('Main forward buffer length on "seeked" event '+(r?r.len:"empty")+")")},r.onManifestLoading=function(){this.log("Trigger BUFFER_RESET"),this.hls.trigger(E.BUFFER_RESET,void 0),this.fragmentTracker.removeAllFragments(),this.couldBacktrack=!1,this.startPosition=this.lastCurrentTime=this.fragLastKbps=0,this.levels=this.fragPlaying=this.backtrackFragment=this.levelLastLoaded=null,this.altAudio=this.audioOnly=this.startFragRequested=!1},r.onManifestParsed=function(e,t){var r,n,i=!1,a=!1;t.levels.forEach((function(e){var t=e.audioCodec;t&&(i=i||-1!==t.indexOf("mp4a.40.2"),a=a||-1!==t.indexOf("mp4a.40.5"))})),this.audioCodecSwitch=i&&a&&!("function"==typeof(null==(n=Yr())||null==(r=n.prototype)?void 0:r.changeType)),this.audioCodecSwitch&&this.log("Both AAC/HE-AAC audio found in levels; declaring level codec as HE-AAC"),this.levels=t.levels,this.startFragRequested=!1},r.onLevelLoading=function(e,t){var r=this.levels;if(r&&this.state===Br){var n=r[t.level];(!n.details||n.details.live&&this.levelLastLoaded!==n||this.waitForCdnTuneIn(n.details))&&(this.state=Kr)}},r.onLevelLoaded=function(e,t){var r,n=this.levels,i=t.level,a=t.details,s=a.totalduration;if(n){this.log("Level "+i+" loaded ["+a.startSN+","+a.endSN+"]"+(a.lastPartSn?"[part-"+a.lastPartSn+"-"+a.lastPartIndex+"]":"")+", cc ["+a.startCC+", "+a.endCC+"] duration:"+s);var o=n[i],l=this.fragCurrent;!l||this.state!==Gr&&this.state!==jr||l.level!==t.level&&l.loader&&this.abortCurrentFrag();var u=0;if(a.live||null!=(r=o.details)&&r.live){var d;if(this.checkLiveUpdate(a),a.deltaUpdateFailed)return;u=this.alignPlaylists(a,o.details,null==(d=this.levelLastLoaded)?void 0:d.details)}if(o.details=a,this.levelLastLoaded=o,this.hls.trigger(E.LEVEL_UPDATED,{details:a,level:i}),this.state===Kr){if(this.waitForCdnTuneIn(a))return;this.state=Br}this.startFragRequested?a.live&&this.synchronizeToLiveEdge(a):this.setStartPosition(a,u),this.tick()}else this.warn("Levels were reset while loading level "+i)},r._handleFragmentLoadProgress=function(e){var t,r=e.frag,n=e.part,i=e.payload,a=this.levels;if(a){var s=a[r.level],o=s.details;if(!o)return this.warn("Dropping fragment "+r.sn+" of level "+r.level+" after level details were reset"),void this.fragmentTracker.removeFragment(r);var l=s.videoCodec,u=o.PTSKnown||!o.live,d=null==(t=r.initSegment)?void 0:t.data,c=this._getAudioCodec(s),f=this.transmuxer=this.transmuxer||new si(this.hls,nt,this._handleTransmuxComplete.bind(this),this._handleTransmuxerFlush.bind(this)),h=n?n.index:-1,g=-1!==h,v=new kr(r.level,r.sn,r.stats.chunkCount,i.byteLength,h,g),p=this.initPTS[r.cc];f.push(i,d,c,l,r,n,o.totalduration,u,v,p)}else this.warn("Levels were reset while fragment load was in progress. Fragment "+r.sn+" of level "+r.level+" will not be buffered")},r.onAudioTrackSwitching=function(e,t){var r=this.altAudio;if(!t.url){if(this.mediaBuffer!==this.media){this.log("Switching on main audio, use media.buffered to schedule main fragment loading"),this.mediaBuffer=this.media;var n=this.fragCurrent;n&&(this.log("Switching to main audio track, cancel main fragment load"),n.abortRequests(),this.fragmentTracker.removeFragment(n)),this.resetTransmuxer(),this.resetLoadingState()}else this.audioOnly&&this.resetTransmuxer();var i=this.hls;r&&(i.trigger(E.BUFFER_FLUSHING,{startOffset:0,endOffset:Number.POSITIVE_INFINITY,type:null}),this.fragmentTracker.removeAllFragments()),i.trigger(E.AUDIO_TRACK_SWITCHED,t)}},r.onAudioTrackSwitched=function(e,t){var r=t.id,n=!!this.hls.audioTracks[r].url;if(n){var i=this.videoBuffer;i&&this.mediaBuffer!==i&&(this.log("Switching on alternate audio, use video.buffered to schedule main fragment loading"),this.mediaBuffer=i)}this.altAudio=n,this.tick()},r.onBufferCreated=function(e,t){var r,n,i=t.tracks,a=!1;for(var s in i){var o=i[s];if("main"===o.id){if(n=s,r=o,"video"===s){var l=i[s];l&&(this.videoBuffer=l.buffer)}}else a=!0}a&&r?(this.log("Alternate track found, use "+n+".buffered to schedule main fragment loading"),this.mediaBuffer=r.buffer):this.mediaBuffer=this.media},r.onFragBuffered=function(e,t){var r=t.frag,n=t.part;if(!r||r.type===nt){if(this.fragContextChanged(r))return this.warn("Fragment "+r.sn+(n?" p: "+n.index:"")+" of level "+r.level+" finished buffering, but was aborted. state: "+this.state),void(this.state===qr&&(this.state=Br));var i=n?n.stats:r.stats;this.fragLastKbps=Math.round(8*i.total/(i.buffering.end-i.loading.first)),"initSegment"!==r.sn&&(this.fragPrevious=r),this.fragBufferedComplete(r,n)}},r.onError=function(e,t){var r;if(t.fatal)this.state=Wr;else switch(t.details){case _.FRAG_GAP:case _.FRAG_PARSING_ERROR:case _.FRAG_DECRYPT_ERROR:case _.FRAG_LOAD_ERROR:case _.FRAG_LOAD_TIMEOUT:case _.KEY_LOAD_ERROR:case _.KEY_LOAD_TIMEOUT:this.onFragmentOrKeyLoadError(nt,t);break;case _.LEVEL_LOAD_ERROR:case _.LEVEL_LOAD_TIMEOUT:case _.LEVEL_PARSING_ERROR:t.levelRetry||this.state!==Kr||(null==(r=t.context)?void 0:r.type)!==et||(this.state=Br);break;case _.BUFFER_APPEND_ERROR:case _.BUFFER_FULL_ERROR:if(!t.parent||"main"!==t.parent)return;if(t.details===_.BUFFER_APPEND_ERROR)return void this.resetLoadingState();this.reduceLengthAndFlushBuffer(t)&&this.flushMainBuffer(0,Number.POSITIVE_INFINITY);break;case _.INTERNAL_EXCEPTION:this.recoverWorkerError(t)}},r.checkBuffer=function(){var e=this.media,t=this.gapController;if(e&&t&&e.readyState){if(this.loadedmetadata||!zt.getBuffered(e).length){var r=this.state!==Br?this.fragCurrent:null;t.poll(this.lastCurrentTime,r)}this.lastCurrentTime=e.currentTime}},r.onFragLoadEmergencyAborted=function(){this.state=Br,this.loadedmetadata||(this.startFragRequested=!1,this.nextLoadPosition=this.startPosition),this.tickImmediate()},r.onBufferFlushed=function(e,t){var r=t.type;if(r!==O||this.audioOnly&&!this.altAudio){var n=(r===M?this.videoBuffer:this.mediaBuffer)||this.media;this.afterBufferFlushed(n,r,nt),this.tick()}},r.onLevelsUpdated=function(e,t){this.level>-1&&this.fragCurrent&&(this.level=this.fragCurrent.level),this.levels=t.levels},r.swapAudioCodec=function(){this.audioCodecSwap=!this.audioCodecSwap},r.seekToStartPos=function(){var e=this.media;if(e){var t=e.currentTime,r=this.startPosition;if(r>=0&&t<r){if(e.seeking)return void this.log("could not seek to "+r+", already seeking at "+t);var n=zt.getBuffered(e),i=(n.length?n.start(0):0)-r;i>0&&(i<this.config.maxBufferHole||i<this.config.maxFragLookUpTolerance)&&(this.log("adjusting start position by "+i+" to match buffer start"),r+=i,this.startPosition=r),this.log("seek to target start position "+r+" from current time "+t),e.currentTime=r}}},r._getAudioCodec=function(e){var t=this.config.defaultAudioCodec||e.audioCodec;return this.audioCodecSwap&&t&&(this.log("Swapping audio codec"),t=-1!==t.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5"),t},r._loadBitrateTestFrag=function(e,t){var r=this;e.bitrateTest=!0,this._doFragLoad(e,t).then((function(n){var i=r.hls;if(n&&!r.fragContextChanged(e)){t.fragmentError=0,r.state=Br,r.startFragRequested=!1,r.bitrateTest=!1;var a=e.stats;a.parsing.start=a.parsing.end=a.buffering.start=a.buffering.end=self.performance.now(),i.trigger(E.FRAG_LOADED,n),e.bitrateTest=!1}}))},r._handleTransmuxComplete=function(e){var t,r="main",n=this.hls,i=e.remuxResult,a=e.chunkMeta,s=this.getCurrentContext(a);if(s){var o=s.frag,l=s.part,u=s.level,d=i.video,c=i.text,f=i.id3,h=i.initSegment,g=u.details,v=this.altAudio?void 0:i.audio;if(this.fragContextChanged(o))this.fragmentTracker.removeFragment(o);else{if(this.state=Hr,h){if(null!=h&&h.tracks){var p=o.initSegment||o;this._bufferInitSegment(u,h.tracks,p,a),n.trigger(E.FRAG_PARSING_INIT_SEGMENT,{frag:p,id:r,tracks:h.tracks})}var y=h.initPTS,b=h.timescale;m(y)&&(this.initPTS[o.cc]={baseTime:y,timescale:b},n.trigger(E.INIT_PTS_FOUND,{frag:o,id:r,initPTS:y,timescale:b}))}if(d&&g&&"initSegment"!==o.sn){var S=g.fragments[o.sn-1-g.startSN],_=o.sn===g.startSN,T=!S||o.cc>S.cc;if(!1!==i.independent){var L=d.startPTS,P=d.endPTS,w=d.startDTS,R=d.endDTS;if(l)l.elementaryStreams[d.type]={startPTS:L,endPTS:P,startDTS:w,endDTS:R};else if(d.firstKeyFrame&&d.independent&&1===a.id&&!T&&(this.couldBacktrack=!0),d.dropped&&d.independent){var A=this.getMainFwdBufferInfo(),k=(A?A.end:this.getLoadPosition())+this.config.maxBufferHole,C=d.firstKeyFramePTS?d.firstKeyFramePTS:L;if(!_&&k<C-this.config.maxBufferHole&&!T)return void this.backtrack(o);T&&(o.gap=!0),o.setElementaryStreamInfo(d.type,o.start,P,o.start,R,!0)}else _&&L>2&&(o.gap=!0);o.setElementaryStreamInfo(d.type,L,P,w,R),this.backtrackFragment&&(this.backtrackFragment=o),this.bufferFragmentData(d,o,l,a,_||T)}else{if(!_&&!T)return void this.backtrack(o);o.gap=!0}}if(v){var D=v.startPTS,I=v.endPTS,x=v.startDTS,M=v.endDTS;l&&(l.elementaryStreams[O]={startPTS:D,endPTS:I,startDTS:x,endDTS:M}),o.setElementaryStreamInfo(O,D,I,x,M),this.bufferFragmentData(v,o,l,a)}if(g&&null!=f&&null!=(t=f.samples)&&t.length){var F={id:r,frag:o,details:g,samples:f.samples};n.trigger(E.FRAG_PARSING_METADATA,F)}if(g&&c){var N={id:r,frag:o,details:g,samples:c.samples};n.trigger(E.FRAG_PARSING_USERDATA,N)}}}else this.resetWhenMissingContext(a)},r._bufferInitSegment=function(e,t,r,n){var i=this;if(this.state===Hr){this.audioOnly=!!t.audio&&!t.video,this.altAudio&&!this.audioOnly&&delete t.audio;var a=t.audio,s=t.video,o=t.audiovideo;if(a){var l=e.audioCodec,u=navigator.userAgent.toLowerCase();if(this.audioCodecSwitch){l&&(l=-1!==l.indexOf("mp4a.40.5")?"mp4a.40.2":"mp4a.40.5");var d=a.metadata;d&&"channelCount"in d&&1!==(d.channelCount||1)&&-1===u.indexOf("firefox")&&(l="mp4a.40.5")}l&&-1!==l.indexOf("mp4a.40.5")&&-1!==u.indexOf("android")&&"audio/mpeg"!==a.container&&(l="mp4a.40.2",this.log("Android: force audio codec to "+l)),e.audioCodec&&e.audioCodec!==l&&this.log('Swapping manifest audio codec "'+e.audioCodec+'" for "'+l+'"'),a.levelCodec=l,a.id="main",this.log("Init audio buffer, container:"+a.container+", codecs[selected/level/parsed]=["+(l||"")+"/"+(e.audioCodec||"")+"/"+a.codec+"]")}s&&(s.levelCodec=e.videoCodec,s.id="main",this.log("Init video buffer, container:"+s.container+", codecs[level/parsed]=["+(e.videoCodec||"")+"/"+s.codec+"]")),o&&this.log("Init audiovideo buffer, container:"+o.container+", codecs[level/parsed]=["+e.codecs+"/"+o.codec+"]"),this.hls.trigger(E.BUFFER_CODECS,t),Object.keys(t).forEach((function(e){var a=t[e].initSegment;null!=a&&a.byteLength&&i.hls.trigger(E.BUFFER_APPENDING,{type:e,data:a,frag:r,part:null,chunkMeta:n,parent:r.type})})),this.tickImmediate()}},r.getMainFwdBufferInfo=function(){return this.getFwdBufferInfo(this.mediaBuffer?this.mediaBuffer:this.media,nt)},r.backtrack=function(e){this.couldBacktrack=!0,this.backtrackFragment=e,this.resetTransmuxer(),this.flushBufferGap(e),this.fragmentTracker.removeFragment(e),this.fragPrevious=null,this.nextLoadPosition=e.start,this.state=Br},r.checkFragmentChanged=function(){var e=this.media,t=null;if(e&&e.readyState>1&&!1===e.seeking){var r=e.currentTime;if(zt.isBuffered(e,r)?t=this.getAppendedFrag(r):zt.isBuffered(e,r+.1)&&(t=this.getAppendedFrag(r+.1)),t){this.backtrackFragment=null;var n=this.fragPlaying,i=t.level;n&&t.sn===n.sn&&n.level===i||(this.fragPlaying=t,this.hls.trigger(E.FRAG_CHANGED,{frag:t}),n&&n.level===i||this.hls.trigger(E.LEVEL_SWITCHED,{level:i}))}}},i(t,[{key:"nextLevel",get:function(){var e=this.nextBufferedFrag;return e?e.level:-1}},{key:"currentFrag",get:function(){var e=this.media;return e?this.fragPlaying||this.getAppendedFrag(e.currentTime):null}},{key:"currentProgramDateTime",get:function(){var e=this.media;if(e){var t=e.currentTime,r=this.currentFrag;if(r&&m(t)&&m(r.programDateTime)){var n=r.programDateTime+1e3*(t-r.start);return new Date(n)}}return null}},{key:"currentLevel",get:function(){var e=this.currentFrag;return e?e.level:-1}},{key:"nextBufferedFrag",get:function(){var e=this.currentFrag;return e?this.followingBufferedFrag(e):null}},{key:"forceStartLoad",get:function(){return this._forceStartLoad}}]),t}(zr),ui=function(){function e(r){void 0===r&&(r={}),this.config=void 0,this.userConfig=void 0,this.coreComponents=void 0,this.networkControllers=void 0,this.started=!1,this._emitter=new ri,this._autoLevelCapping=-1,this._maxHdcpLevel=null,this.abrController=void 0,this.bufferController=void 0,this.capLevelController=void 0,this.latencyController=void 0,this.levelController=void 0,this.streamController=void 0,this.audioTrackController=void 0,this.subtitleTrackController=void 0,this.emeController=void 0,this.cmcdController=void 0,this._media=null,this.url=null,this.triggeringException=void 0,w(r.debug||!1,"Hls instance");var n=this.config=function(e,r){if((r.liveSyncDurationCount||r.liveMaxLatencyDurationCount)&&(r.liveSyncDuration||r.liveMaxLatencyDuration))throw new Error("Illegal hls.js config: don't mix up liveSyncDurationCount/liveMaxLatencyDurationCount and liveSyncDuration/liveMaxLatencyDuration");if(void 0!==r.liveMaxLatencyDurationCount&&(void 0===r.liveSyncDurationCount||r.liveMaxLatencyDurationCount<=r.liveSyncDurationCount))throw new Error('Illegal hls.js config: "liveMaxLatencyDurationCount" must be greater than "liveSyncDurationCount"');if(void 0!==r.liveMaxLatencyDuration&&(void 0===r.liveSyncDuration||r.liveMaxLatencyDuration<=r.liveSyncDuration))throw new Error('Illegal hls.js config: "liveMaxLatencyDuration" must be greater than "liveSyncDuration"');var n=fr(e),i=["TimeOut","MaxRetry","RetryDelay","MaxRetryTimeout"];return["manifest","level","frag"].forEach((function(e){var t=("level"===e?"playlist":e)+"LoadPolicy",a=void 0===r[t],s=[];i.forEach((function(i){var o=e+"Loading"+i,l=r[o];if(void 0!==l&&a){s.push(o);var u=n[t].default;switch(r[t]={default:u},i){case"TimeOut":u.maxLoadTimeMs=l,u.maxTimeToFirstByteMs=l;break;case"MaxRetry":u.errorRetry.maxNumRetry=l,u.timeoutRetry.maxNumRetry=l;break;case"RetryDelay":u.errorRetry.retryDelayMs=l,u.timeoutRetry.retryDelayMs=l;break;case"MaxRetryTimeout":u.errorRetry.maxRetryDelayMs=l,u.timeoutRetry.maxRetryDelayMs=l}}})),s.length&&R.warn('hls.js config: "'+s.join('", "')+'" setting(s) are deprecated, use "'+t+'": '+JSON.stringify(r[t]))})),t(t({},n),r)}(e.DefaultConfig,r);this.userConfig=r,n.progressive&&function(e){var t=e.loader;t!==or&&t!==ir?(R.log("[config]: Custom loader detected, cannot enable progressive streaming"),e.progressive=!1):function(){if(self.fetch&&self.AbortController&&self.ReadableStream&&self.Request)try{return new self.ReadableStream({}),!0}catch(e){}return!1}()&&(e.loader=or,e.progressive=!0,e.enableSoftwareAES=!0,R.log("[config]: Progressive streaming enabled, using FetchLoader"))}(n);var i=n.abrController,a=n.bufferController,s=n.capLevelController,o=n.errorController,l=n.fpsController,u=new o(this),d=this.abrController=new i(this),c=this.bufferController=new a(this),f=this.capLevelController=new s(this),h=new l(this),g=new lt(this),v=new pt(this),p=n.contentSteeringController,m=p?new p(this):null,y=this.levelController=new hr(this,m),b=new br(this),S=new Rr(this.config),_=this.streamController=new li(this,b,S);f.setStreamController(_),h.setStreamController(_);var T=[g,y,_];m&&T.splice(1,0,m),this.networkControllers=T;var L=[d,c,f,h,v,b];this.audioTrackController=this.createController(n.audioTrackController,T);var P=n.audioStreamController;P&&T.push(new P(this,b,S)),this.subtitleTrackController=this.createController(n.subtitleTrackController,T);var A=n.subtitleStreamController;A&&T.push(new A(this,b,S)),this.createController(n.timelineController,L),S.emeController=this.emeController=this.createController(n.emeController,L),this.cmcdController=this.createController(n.cmcdController,L),this.latencyController=this.createController(mt,L),this.coreComponents=L,T.push(u);var k=u.onErrorOut;"function"==typeof k&&this.on(E.ERROR,k,u)}e.isMSESupported=function(){return Xr()},e.isSupported=function(){return function(){if(!Xr())return!1;var e=ke();return"function"==typeof(null==e?void 0:e.isTypeSupported)&&(["avc1.42E01E,mp4a.40.2","av01.0.01M.08","vp09.00.50.08"].some((function(t){return e.isTypeSupported(xe(t,"video"))}))||["mp4a.40.2","fLaC"].some((function(t){return e.isTypeSupported(xe(t,"audio"))})))}()},e.getMediaSource=function(){return ke()};var r=e.prototype;return r.createController=function(e,t){if(e){var r=new e(this);return t&&t.push(r),r}return null},r.on=function(e,t,r){void 0===r&&(r=this),this._emitter.on(e,t,r)},r.once=function(e,t,r){void 0===r&&(r=this),this._emitter.once(e,t,r)},r.removeAllListeners=function(e){this._emitter.removeAllListeners(e)},r.off=function(e,t,r,n){void 0===r&&(r=this),this._emitter.off(e,t,r,n)},r.listeners=function(e){return this._emitter.listeners(e)},r.emit=function(e,t,r){return this._emitter.emit(e,t,r)},r.trigger=function(e,t){if(this.config.debug)return this.emit(e,e,t);try{return this.emit(e,e,t)}catch(t){if(R.error("An internal error happened while handling event "+e+'. Error message: "'+t.message+'". Here is a stacktrace:',t),!this.triggeringException){this.triggeringException=!0;var r=e===E.ERROR;this.trigger(E.ERROR,{type:S.OTHER_ERROR,details:_.INTERNAL_EXCEPTION,fatal:r,event:e,error:t}),this.triggeringException=!1}}return!1},r.listenerCount=function(e){return this._emitter.listenerCount(e)},r.destroy=function(){R.log("destroy"),this.trigger(E.DESTROYING,void 0),this.detachMedia(),this.removeAllListeners(),this._autoLevelCapping=-1,this.url=null,this.networkControllers.forEach((function(e){return e.destroy()})),this.networkControllers.length=0,this.coreComponents.forEach((function(e){return e.destroy()})),this.coreComponents.length=0;var e=this.config;e.xhrSetup=e.fetchSetup=void 0,this.userConfig=null},r.attachMedia=function(e){R.log("attachMedia"),this._media=e,this.trigger(E.MEDIA_ATTACHING,{media:e})},r.detachMedia=function(){R.log("detachMedia"),this.trigger(E.MEDIA_DETACHING,void 0),this._media=null},r.loadSource=function(e){this.stopLoad();var t=this.media,r=this.url,n=this.url=p.buildAbsoluteURL(self.location.href,e,{alwaysNormalize:!0});this._autoLevelCapping=-1,this._maxHdcpLevel=null,R.log("loadSource:"+n),t&&r&&(r!==n||this.bufferController.hasSourceTypes())&&(this.detachMedia(),this.attachMedia(t)),this.trigger(E.MANIFEST_LOADING,{url:e})},r.startLoad=function(e){void 0===e&&(e=-1),R.log("startLoad("+e+")"),this.started=!0,this.networkControllers.forEach((function(t){t.startLoad(e)}))},r.stopLoad=function(){R.log("stopLoad"),this.started=!1,this.networkControllers.forEach((function(e){e.stopLoad()}))},r.resumeBuffering=function(){this.started&&this.networkControllers.forEach((function(e){"fragmentLoader"in e&&e.startLoad(-1)}))},r.pauseBuffering=function(){this.networkControllers.forEach((function(e){"fragmentLoader"in e&&e.stopLoad()}))},r.swapAudioCodec=function(){R.log("swapAudioCodec"),this.streamController.swapAudioCodec()},r.recoverMediaError=function(){R.log("recoverMediaError");var e=this._media;this.detachMedia(),e&&this.attachMedia(e)},r.removeLevel=function(e){this.levelController.removeLevel(e)},r.setAudioOption=function(e){var t;return null==(t=this.audioTrackController)?void 0:t.setAudioOption(e)},r.setSubtitleOption=function(e){var t;return null==(t=this.subtitleTrackController)||t.setSubtitleOption(e),null},i(e,[{key:"levels",get:function(){return this.levelController.levels||[]}},{key:"currentLevel",get:function(){return this.streamController.currentLevel},set:function(e){R.log("set currentLevel:"+e),this.levelController.manualLevel=e,this.streamController.immediateLevelSwitch()}},{key:"nextLevel",get:function(){return this.streamController.nextLevel},set:function(e){R.log("set nextLevel:"+e),this.levelController.manualLevel=e,this.streamController.nextLevelSwitch()}},{key:"loadLevel",get:function(){return this.levelController.level},set:function(e){R.log("set loadLevel:"+e),this.levelController.manualLevel=e}},{key:"nextLoadLevel",get:function(){return this.levelController.nextLoadLevel},set:function(e){this.levelController.nextLoadLevel=e}},{key:"firstLevel",get:function(){return Math.max(this.levelController.firstLevel,this.minAutoLevel)},set:function(e){R.log("set firstLevel:"+e),this.levelController.firstLevel=e}},{key:"startLevel",get:function(){var e=this.levelController.startLevel;return-1===e&&this.abrController.forcedAutoLevel>-1?this.abrController.forcedAutoLevel:e},set:function(e){R.log("set startLevel:"+e),-1!==e&&(e=Math.max(e,this.minAutoLevel)),this.levelController.startLevel=e}},{key:"capLevelToPlayerSize",get:function(){return this.config.capLevelToPlayerSize},set:function(e){var t=!!e;t!==this.config.capLevelToPlayerSize&&(t?this.capLevelController.startCapping():(this.capLevelController.stopCapping(),this.autoLevelCapping=-1,this.streamController.nextLevelSwitch()),this.config.capLevelToPlayerSize=t)}},{key:"autoLevelCapping",get:function(){return this._autoLevelCapping},set:function(e){this._autoLevelCapping!==e&&(R.log("set autoLevelCapping:"+e),this._autoLevelCapping=e,this.levelController.checkMaxAutoUpdated())}},{key:"bandwidthEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimate():NaN},set:function(e){this.abrController.resetEstimator(e)}},{key:"ttfbEstimate",get:function(){var e=this.abrController.bwEstimator;return e?e.getEstimateTTFB():NaN}},{key:"maxHdcpLevel",get:function(){return this._maxHdcpLevel},set:function(e){(function(e){return yt.indexOf(e)>-1})(e)&&this._maxHdcpLevel!==e&&(this._maxHdcpLevel=e,this.levelController.checkMaxAutoUpdated())}},{key:"autoLevelEnabled",get:function(){return-1===this.levelController.manualLevel}},{key:"manualLevel",get:function(){return this.levelController.manualLevel}},{key:"minAutoLevel",get:function(){var e=this.levels,t=this.config.minAutoBitrate;if(!e)return 0;for(var r=e.length,n=0;n<r;n++)if(e[n].maxBitrate>=t)return n;return 0}},{key:"maxAutoLevel",get:function(){var e,t=this.levels,r=this.autoLevelCapping,n=this.maxHdcpLevel;if(e=-1===r&&null!=t&&t.length?t.length-1:r,n)for(var i=e;i--;){var a=t[i].attrs["HDCP-LEVEL"];if(a&&a<=n)return i}return e}},{key:"firstAutoLevel",get:function(){return this.abrController.firstAutoLevel}},{key:"nextAutoLevel",get:function(){return this.abrController.nextAutoLevel},set:function(e){this.abrController.nextAutoLevel=e}},{key:"playingDate",get:function(){return this.streamController.currentProgramDateTime}},{key:"mainForwardBufferInfo",get:function(){return this.streamController.getMainFwdBufferInfo()}},{key:"allAudioTracks",get:function(){var e=this.audioTrackController;return e?e.allAudioTracks:[]}},{key:"audioTracks",get:function(){var e=this.audioTrackController;return e?e.audioTracks:[]}},{key:"audioTrack",get:function(){var e=this.audioTrackController;return e?e.audioTrack:-1},set:function(e){var t=this.audioTrackController;t&&(t.audioTrack=e)}},{key:"allSubtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.allSubtitleTracks:[]}},{key:"subtitleTracks",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTracks:[]}},{key:"subtitleTrack",get:function(){var e=this.subtitleTrackController;return e?e.subtitleTrack:-1},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleTrack=e)}},{key:"media",get:function(){return this._media}},{key:"subtitleDisplay",get:function(){var e=this.subtitleTrackController;return!!e&&e.subtitleDisplay},set:function(e){var t=this.subtitleTrackController;t&&(t.subtitleDisplay=e)}},{key:"lowLatencyMode",get:function(){return this.config.lowLatencyMode},set:function(e){this.config.lowLatencyMode=e}},{key:"liveSyncPosition",get:function(){return this.latencyController.liveSyncPosition}},{key:"latency",get:function(){return this.latencyController.latency}},{key:"maxLatency",get:function(){return this.latencyController.maxLatency}},{key:"targetLatency",get:function(){return this.latencyController.targetLatency}},{key:"drift",get:function(){return this.latencyController.drift}},{key:"forceStartLoad",get:function(){return this.streamController.forceStartLoad}}],[{key:"version",get:function(){return"1.5.11"}},{key:"Events",get:function(){return E}},{key:"ErrorTypes",get:function(){return S}},{key:"ErrorDetails",get:function(){return _}},{key:"DefaultConfig",get:function(){return e.defaultConfig?e.defaultConfig:cr},set:function(t){e.defaultConfig=t}}]),e}();return ui.defaultConfig=void 0,ui},"object"==a(t)?e.exports=l():void 0===(i="function"==typeof(n=l)?n.call(t,r,t,e):n)||(e.exports=i)}(!1)},117:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.proxyIdentifier=void 0,t.parseRangeHeader=function(e){if(!e)return{};var t=e.trim().toLowerCase();if(!t.startsWith("bytes="))throw new Error("unit-must-be-bytes",{normalizedRangeHeader:t});if(t.includes(","))throw new Error("single-range-only",{normalizedRangeHeader:t});var r=/(\d*)-(\d*)/.exec(t);if(!r||!r[1]&&!r[2])throw new Error("invalid-range-values",{normalizedRangeHeader:t});return{start:""===r[1]?0:Number(r[1]),end:""===r[2]?void 0:Number(r[2])}},t.getUrlSuffix=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:".",r=n.parseURL(e);return r.path.substring(r.path.lastIndexOf(t)+1)},t.copyHeaders=i,t.makeHeadersWithRange=function(e,t){var r=i(e);t&&r.set("Range",t);return r},t.makeHeadersWithRangeOnly=function(e){var t=new Headers;e&&t.set("range",e);return t};var n=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r(299));t.proxyIdentifier="__PROXY_IDENTIFIER__";function i(e){return new Headers(e)}},99:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],n=!0,i=!1,a=void 0;try{for(var s,o=e[Symbol.iterator]();!(n=(s=o.next()).done)&&(r.push(s.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{!n&&o.return&&o.return()}finally{if(i)throw a}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=o(r(540)),s=o(r(9));function o(e){return e&&e.__esModule?e:{default:e}}var l=function(e){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r));return n.requestingMap=new s.default,n.bitset=new Set,n.bitCounts=new Map,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,[{key:"handshakePeer",value:function(e){this._setupDC(e);var t=this.engine.fetcher.announceInfo,r=t.asn,n=t.country;e.sendMetaData(Array.from(this.bitset),this.sequential,this.peersNum,{asn:r,country:n},this.isMobileNet)}},{key:"handleMetaData",value:function(e,t){var r=this;t.field&&(e.bitset=new Set(t.field),t.field.forEach((function(e){r.bitset.has(e)||r._increBitCounts(e)})),this.addPeer(e),this.downloadOnly&&this.chokePeerRequest(e))}},{key:"peersHas",value:function(e){return this.bitCounts.has(e)}},{key:"_decreBitCounts",value:function(e){if(this.bitCounts.has(e)){var t=this.bitCounts.get(e);1===t?this.bitCounts.delete(e):this.bitCounts.set(e,t-1)}}},{key:"_increBitCounts",value:function(e){if(this.bitCounts.has(e)){var t=this.bitCounts.get(e);this.bitCounts.set(e,t+1)}else this.bitCounts.set(e,1)}},{key:"reportDCTraffic",value:function(e,t,r){if(this.engine.fetcher){var n=this.engine.fetcher,i=t;this.bitset.has(e)||n.reportDCTraffic(i,r)}}},{key:"cleanRequestingMap",value:function(e){var t=this.peerManager.getPeer(e),r=!0,i=!1,a=void 0;try{for(var s,o=this.requestingMap.internalMap[Symbol.iterator]();!(r=(s=o.next()).done);r=!0){var l=n(s.value,2),u=l[0],d=l[1];d&&d.includes(e)&&(this.logger.info("delete "+u+" in requestingMap"),this.requestingMap.delete(u),this._decreBitCounts(u),t&&t.bitset.delete(u))}}catch(e){i=!0,a=e}finally{try{!r&&o.return&&o.return()}finally{if(i)throw a}}}},{key:"getPeerLoadedMore",value:function(e){if(!this.requestingMap.has(e))return null;var t=this.requestingMap.getAllPeerIds(e);if(0===t.length)return null;var r=this.peerManager.getPeer(t[0]);if(!r)return null;if(t.length>1)for(var n=1;n<t.length;n++){var i=this.peerManager.getPeer(t[n]);i&&i.bufArr.length>r.bufArr.length&&(r=i)}return r}}]),t}(a.default);t.default=l,e.exports=t.default},183:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r={wsMaxRetries:10,p2pEnabled:!0,wifiOnly:!1,memoryCacheLimit:{pc:419430400,mobile:104857600},dcDownloadTimeout:25,logLevel:"error",tag:"",webRTCConfig:{},token:void 0,appName:void 0,appId:void 0,prefetchNum:4,showSlogan:!0,trickleICE:!0,announceLocation:"eu",trackerZone:void 0,geoIpPreflight:!0,ICEPreflight:!0,useDiskCache:!0,startFromSegmentOffset:0,getStats:function(e,t,r){},getPeerId:function(e){},getPeersInfo:function(e){}};t.default=r,e.exports=t.default},745:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),s=g(r(648)),o=g(r(708)),l=g(r(299)),u=r(408),d=g(r(89)),c=g(r(524)),f=g(r(429)),h=g(r(816));function g(e){return e&&e.__esModule?e:{default:e}}function v(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var p="nllL",m="d3NzJ",y="==",b="TNBLy9z",E="aWduY",S="mNvbQ",_="WwuY2RuY",T=(v(n={},h.default.EXCEPTION,"onException"),v(n,"serverConnected","onServerConnected"),v(n,"peerId","getPeerId"),v(n,"p2pDownloaded","onP2pDownloaded"),v(n,"p2pUploaded","onP2pUploaded"),v(n,"httpDownloaded","onHttpDownloaded"),v(n,"peers","getPeersInfo"),n),L=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));if(r.p2pEnabled=!(!1===e.p2pEnabled||"0"===(0,u.getQueryParam)("_p2p")),e.tag&&e.tag.length>20)throw new Error("Tag is too long");if(e.appName&&e.appName.length>30)throw new Error("appName is too long");if(e.appId&&e.appId.length>30)throw new Error("appId is too long");if(e.token&&e.token.length>20)throw new Error("Token is too long");return r.segmentLoadCount=0,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),a(t,[{key:"initLogger",value:function(){var e=this.config;e.showSlogan&&"en"===(0,u.navLang)()&&console.log("%cLet the browsers become your unlimitedly scalable CDN!\n%c"+(0,u.getHomeUrl)(),"color: dodgerblue; padding:20px 0; font-size: x-large","font-size: medium; padding-bottom:15px");var t=new o.default(e.logLevel);return e.logger=this.logger=t,t}},{key:"getExtraForStats",value:function(){return{}}},{key:"getExtraForPeersRequest",value:function(){var e={};return e.num_want=this._getNumWant(),e}},{key:"_getNumWant",value:function(){var e=this.tracker;if(e.scheduler){var t=e.scheduler.peersNum;return t>0&&e.maxConnsActive-t>0?e.maxConnsActive-t:void 0}}},{key:"makeChannelId",value:function(e,t){if(!e||"string"!=typeof e){var r="token is required while using customized channelId!";throw console.error(r),new Error(r)}return(0,u.isFunction)(t)?function(r,n){return e+"-"+t(r,n)}:function(){return e+"-"+t}}},{key:"makeSignalId",value:function(){var e="",t=this.config,r=decodeURIComponent(self.atob(m+b+E+_+p+S+y));t.signalConfig&&(t.wsSignalerAddr=t.signalConfig);var n=t.wsSignalerAddr;if(n){var a=void 0;"object"===(void 0===n?"undefined":i(n))?(n.main||(n.main=r),a=n.main):"string"==typeof n&&(a=n,t.wsSignalerAddr={main:a}),a===r&&(a=void 0),a&&!t.wsSignalerAddr.backup&&(e=l.default.parseURL(a).netLoc.substr(2))}else t.wsSignalerAddr={main:r,byDefault:!0};return e}},{key:"setupWindowListeners",value:function(e){var t=this,r=["iPad","iPhone"].indexOf(navigator.platform)>=0?"pagehide":"beforeunload",n=function e(){t.fetcher&&t.fetcher.postStatsWithBeacon(),t.p2pEnabled&&t.disableP2P(),self.removeEventListener(r,e)};e?self.removeEventListener(r,n):self.addEventListener(r,n)}},{key:"destroy",value:function(){this.disableP2P(!0),this.removeAllListeners(),this.setupWindowListeners(!0)}},{key:"enableP2P",value:function(){return this.p2pEnabled?null:(this.logger&&this.logger.info("enable P2P"),this.config.p2pEnabled=this.p2pEnabled=!0,this.browserInfo?(this._init(this.channel,this.browserInfo),this):null)}},{key:"determineHttpLoadTime",value:function(e,t){var r=3.5;return t<=2?r=1:t<=3?r=1.5:t<=4?r=2:t<=6?r=2.5:t<=8&&(r=3),r}},{key:"emitEvent",value:function(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];this.emit.apply(this,[e].concat(r));var i,a=T[e];a&&(0,u.isFunction)(this.config[a])&&(i=this.config)[a].apply(i,r)}},{key:"commonBrowserInfo",get:function(){var e=c.default.getPlatform(),t=c.default.getNetType()||"wifi";this.netType=t;var r=this.config.wsSignalerAddr||{},n=r.main,i=r.backup;return{signal:r.byDefault?void 0:n,signal2:i,device:e,netType:t,player:(0,f.default)()||void 0}}},{key:"isMobileNet",get:function(){return"wifi"!==this.netType&&"ethernet"!==this.netType}},{key:"version",get:function(){return t.version}}],[{key:"isSupported",value:function(){var e=(0,u.getBrowserRTC)();return!(!e||void 0===e.RTCPeerConnection.prototype.createDataChannel)}},{key:"TrackerZone",get:function(){return{EU:"eu",HK:"hk",USA:"us"}}}]),t}(s.default);L.version="1.22.1",L.protocolVersion=d.default.VERSION,t.default=L,e.exports=t.default},816:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default={DC_SIGNAL:"SIGNAL",DC_SIGNAL_BATCH:"SIGNAL_BATCH",DC_OPEN:"OPEN",DC_REQUEST:"REQUEST",DC_PIECE_NOT_FOUND:"PIECE_NOT_FOUND",DC_PIECE_ABORT:"PIECE_ABORT",DC_PIECE_CANCEL:"PIECE_CANCEL",DC_CLOSE:"CLOSE",DC_DISCONNECT:"DISCONNECT",DC_RESPONSE:"RESPONSE",DC_ERROR:"ERROR",DC_PIECE:"PIECE",DC_PIECE_DATA:"PIECE_DATA",DC_TIMEOUT:"TIMEOUT",DC_PIECE_ACK:"PIECE_ACK",DC_METADATA:"METADATA",DC_PLAT_ANDROID:"ANDROID",DC_PLAT_IOS:"IOS",DC_PLAT_WEB:"WEB",DC_CHOKE:"CHOKE",DC_UNCHOKE:"UNCHOKE",DC_HAVE:"HAVE",DC_HAVE_REVERSE:"HAVE_REVERSE",DC_LOST:"LOST",DC_GET_PEERS:"GET_PEERS",DC_PEERS:"PEERS",DC_STATS:"STATS",DC_PEER_SIGNAL:"PEER_SIGNAL",DC_PLAYLIST:"PLAYLIST",BM_LOST:"lost",BM_ADDED_SEG_:"BM_ADDED_SEG_",BM_ADDED_SN_:"BM_ADDED_SN_",BM_SEG_ADDED:"BM_SEG_ADDED",BM_FATAL_ERROR:"BM_FATAL_ERROR",FRAG_CHANGED:"FRAG_CHANGED",FRAG_LOADED:"FRAG_LOADED",FRAG_LOADING:"FRAG_LOADING",RESTART_P2P:"RESTART_P2P",EXCEPTION:"exception",SYN_OUTPUT:"SYN_OUTPUT",SYN_ERROR:"SYN_ERROR",SYN_PROGRESS:"SYN_PROGRESS",MEDIA_REBUFFER:"MEDIA_REBUFFER"},e.exports=t.default},911:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(408),s=u(r(648)),o=u(r(824)),l=r(921);function u(e){return e&&e.__esModule?e:{default:e}}function d(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var c=65536;function f(e){return e.replace(/a=ice-options:trickle\s\n/g,"")}var h=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=d(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));r.channelName=e.initiator?e.channelName:null,r.initiator=e.initiator||!1,r.channelConfig=e.channelConfig||t.channelConfig,r.channelNegotiated=r.channelConfig.negotiated,r.config=Object.assign({},t.config,e.config),r.offerOptions=e.offerOptions||{},r.answerOptions=e.answerOptions||{},r.sdpTransform=e.sdpTransform||function(e){return e},r.trickle=void 0===e.trickle||e.trickle,r.allowHalfTrickle=void 0!==e.allowHalfTrickle&&e.allowHalfTrickle,r.iceCompleteTimeout=e.iceCompleteTimeout||5e3,r.destroyed=!1,r.destroying=!1,r._connected=!1,r.remoteAddress=void 0,r.remoteFamily=void 0,r.remotePort=void 0,r.localAddress=void 0,r.localFamily=void 0,r.localPort=void 0,r._wrtc=e.wrtc&&"object"===n(e.wrtc)?e.wrtc:(0,a.getBrowserRTC)(),r._pcReady=!1,r._channelReady=!1,r._iceComplete=!1,r._iceCompleteTimer=null,r._channel=null,r._pendingCandidates=[],r._pendingData=[],r._isNegotiating=!1,r._firstNegotiation=!0,r._batchedNegotiation=!1,r._queuedNegotiation=!1,r._senderMap=new Map,r._closingInterval=null,r._chunk=null,r._cb=null,r._interval=null;try{r._pc=new r._wrtc.RTCPeerConnection(r.config)}catch(e){return(0,o.default)((function(){return r.destroy(e)})),d(r)}return r._pc.oniceconnectionstatechange=function(){r._onIceStateChange()},r._pc.onicegatheringstatechange=function(){r._onIceStateChange()},r._pc.onconnectionstatechange=function(){r._onConnectionStateChange()},r._pc.onsignalingstatechange=function(){r._onSignalingStateChange()},r._pc.onicecandidate=function(e){r._onIceCandidate(e)},r.initiator||r.channelNegotiated?r._setupData({channel:r._pc.createDataChannel(r.channelName,r.channelConfig)}):r._pc.ondatachannel=function(e){r._setupData(e)},r._needsNegotiation(),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,[{key:"signal",value:function(e){var t=this;if(!this.destroyed&&this._pc){if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e={}}if(e.renegotiate&&this.initiator&&this._needsNegotiation(),e.candidate)if(this._pc.remoteDescription&&this._pc.remoteDescription.type)try{this._addIceCandidate(e.candidate)}catch(e){}else this._pendingCandidates.push(e.candidate);e.sdp&&this._pc.setRemoteDescription(new this._wrtc.RTCSessionDescription(e)).then((function(){t.destroyed||(t._pendingCandidates.forEach((function(e){try{t._addIceCandidate(e)}catch(e){}})),t._pendingCandidates=[],"offer"===t._pc.remoteDescription.type&&t._createAnswer())})).catch((function(e){t.destroy(e)})),e.sdp||e.candidate||e.renegotiate||e.transceiverRequest||this.destroy(new Error("signal() called with invalid signal data"))}}},{key:"_addIceCandidate",value:function(e){var t=this,r=new this._wrtc.RTCIceCandidate(e);this._pc.addIceCandidate(r).catch((function(e){var n;!r.address||r.address.endsWith(".local")?(n="Ignoring unsupported ICE candidate.",console.warn(n)):t.destroy(e)}))}},{key:"send",value:function(e){"string"==typeof e?RTCDataChannel.prototype.send.toString().includes("[native code]")&&this._channel.send(e):this._channel.send(e)}},{key:"_needsNegotiation",value:function(){var e=this;this._batchedNegotiation||(this._batchedNegotiation=!0,(0,o.default)((function(){e._batchedNegotiation=!1,!e.initiator&&e._firstNegotiation||e.negotiate(),e._firstNegotiation=!1})))}},{key:"negotiate",value:function(){var e=this;this.initiator?this._isNegotiating?this._queuedNegotiation=!0:setTimeout((function(){e._createOffer()}),0):this._isNegotiating?this._queuedNegotiation=!0:this.emit("signal",{type:"renegotiate",renegotiate:!0}),this._isNegotiating=!0}},{key:"destroy",value:function(e){this._destroy(e)}},{key:"_destroy",value:function(e){var t=this;this.destroyed||this.destroying||(this.destroying=!0,(0,o.default)((function(){if(t.destroyed=!0,t.destroying=!1,t._connected=!1,t._pcReady=!1,t._channelReady=!1,t._senderMap=null,clearInterval(t._closingInterval),t._closingInterval=null,clearInterval(t._interval),t._interval=null,t._chunk=null,t._cb=null,t._channel){try{t._channel.close()}catch(e){}t._channel.onmessage=null,t._channel.onopen=null,t._channel.onclose=null,t._channel.onerror=null}if(t._pc){try{t._pc.close()}catch(e){}t._pc.oniceconnectionstatechange=null,t._pc.onicegatheringstatechange=null,t._pc.onsignalingstatechange=null,t._pc.onicecandidate=null,t._pc.ondatachannel=null}t._pc=null,t._channel=null,e&&t.emit("error",e),t.emit("close")})))}},{key:"_setupData",value:function(e){var t=this;if(!e.channel)return this.destroy(new Error("Data channel event is missing `channel` property"));this._channel=e.channel,this._channel.binaryType="arraybuffer","number"==typeof this._channel.bufferedAmountLowThreshold&&(this._channel.bufferedAmountLowThreshold=c),this.channelName=this._channel.label,this._channel.onmessage=function(e){t._onChannelMessage(e)},this._channel.onbufferedamountlow=function(){t._onChannelBufferedAmountLow()},this._channel.onopen=function(){t._onChannelOpen()},this._channel.onclose=function(){t._onChannelClose()},this._channel.onerror=function(e){t.destroy(e)};var r=!1;this._closingInterval=setInterval((function(){t._channel&&"closing"===t._channel.readyState?(r&&t._onChannelClose(),r=!0):r=!1}),5e3)}},{key:"write",value:function(e,t){if(this.destroyed)return t(new Error("cannot write after peer is destroyed"));if(this._connected){try{this.send(e)}catch(e){return this.destroy(e)}this.isBufferedAmountHigh?this._cb=t:t(null)}else this._chunk=e,this._cb=t}},{key:"_startIceCompleteTimeout",value:function(){var e=this;this.destroyed||this._iceCompleteTimer||(this._iceCompleteTimer=setTimeout((function(){e._iceComplete||(e._iceComplete=!0,e.emit("iceTimeout"),e.emit("_iceComplete"))}),this.iceCompleteTimeout))}},{key:"_createOffer",value:function(){var e=this;this.destroyed||this._pc.createOffer(this.offerOptions).then((function(t){if(!e.destroyed){e.trickle||e.allowHalfTrickle||(t.sdp=f(t.sdp)),t.sdp=e.sdpTransform(t.sdp);var r=function(){if(!e.destroyed){var r=e._pc.localDescription||t;e.emit("signal",{type:r.type,sdp:r.sdp})}};e._pc.setLocalDescription(t).then((function(){e.destroyed||(e.trickle||e._iceComplete?r():e.once("_iceComplete",r))})).catch((function(t){e.destroy(t)}))}})).catch((function(t){e.destroy(t)}))}},{key:"_createAnswer",value:function(){var e=this;this.destroyed||this._pc.createAnswer(this.answerOptions).then((function(t){if(!e.destroyed){e.trickle||e.allowHalfTrickle||(t.sdp=f(t.sdp)),t.sdp=e.sdpTransform(t.sdp);var r=function(){if(!e.destroyed){var r=e._pc.localDescription||t;e.emit("signal",{type:r.type,sdp:r.sdp})}};e._pc.setLocalDescription(t).then((function(){e.destroyed||(e.trickle||e._iceComplete?r():e.once("_iceComplete",r))})).catch((function(t){e.destroy(t)}))}})).catch((function(t){e.destroy(t)}))}},{key:"_onConnectionStateChange",value:function(){this.destroyed||"failed"===this._pc.connectionState&&this.destroy(new Error("Connection failed."))}},{key:"_onIceStateChange",value:function(){if(!this.destroyed){var e=this._pc.iceConnectionState,t=this._pc.iceGatheringState;this.emit("iceStateChange",e,t),"connected"!==e&&"completed"!==e||(this._pcReady=!0,this._maybeReady()),"failed"===e&&this.destroy(new Error("Ice connection failed.")),"closed"===e&&this.destroy(new Error("Ice connection closed."))}}},{key:"getStats",value:function(e){var t=this,r=function(e){return"[object Array]"===Object.prototype.toString.call(e.values)&&e.values.forEach((function(t){Object.assign(e,t)})),e};0===this._pc.getStats.length?this._pc.getStats().then((function(t){var n=[];t.forEach((function(e){n.push(r(e))})),e(null,n)}),(function(t){return e(t)})):this._pc.getStats.length>0?this._pc.getStats((function(n){if(!t.destroyed){var i=[];n.result().forEach((function(e){var t={};e.names().forEach((function(r){t[r]=e.stat(r)})),t.id=e.id,t.type=e.type,t.timestamp=e.timestamp,i.push(r(t))})),e(null,i)}}),(function(t){return e(t)})):e(null,[])}},{key:"_maybeReady",value:function(){var e=this;if(!this._connected&&!this._connecting&&this._pcReady&&this._channelReady){this._connecting=!0;!function t(){e.destroyed||e.getStats((function(r,n){if(!e.destroyed){r&&(n=[]);var i={},a={},s={},o=!1;n.forEach((function(e){"remotecandidate"!==e.type&&"remote-candidate"!==e.type||(i[e.id]=e),"localcandidate"!==e.type&&"local-candidate"!==e.type||(a[e.id]=e),"candidatepair"!==e.type&&"candidate-pair"!==e.type||(s[e.id]=e)}));var l=function(t){o=!0;var r=a[t.localCandidateId];r&&(r.ip||r.address)?(e.localAddress=r.ip||r.address,e.localPort=Number(r.port)):r&&r.ipAddress?(e.localAddress=r.ipAddress,e.localPort=Number(r.portNumber)):"string"==typeof t.googLocalAddress&&(r=t.googLocalAddress.split(":"),e.localAddress=r[0],e.localPort=Number(r[1])),e.localAddress&&(e.localFamily=e.localAddress.includes(":")?"IPv6":"IPv4");var n=i[t.remoteCandidateId];n&&(n.ip||n.address)?(e.remoteAddress=n.ip||n.address,e.remotePort=Number(n.port)):n&&n.ipAddress?(e.remoteAddress=n.ipAddress,e.remotePort=Number(n.portNumber)):"string"==typeof t.googRemoteAddress&&(n=t.googRemoteAddress.split(":"),e.remoteAddress=n[0],e.remotePort=Number(n[1])),e.remoteAddress&&(e.remoteFamily=e.remoteAddress.includes(":")?"IPv6":"IPv4")};if(n.forEach((function(e){"transport"===e.type&&e.selectedCandidatePairId&&l(s[e.selectedCandidatePairId]),("googCandidatePair"===e.type&&"true"===e.googActiveConnection||("candidatepair"===e.type||"candidate-pair"===e.type)&&e.selected)&&l(e)})),o||Object.keys(s).length&&!Object.keys(a).length){if(e._connecting=!1,e._connected=!0,e._chunk){try{e.send(e._chunk)}catch(r){return e.destroy(r)}e._chunk=null;var u=e._cb;e._cb=null,u(null)}"number"!=typeof e._channel.bufferedAmountLowThreshold&&(e._interval=setInterval((function(){return e._onInterval()}),150),e._interval.unref&&e._interval.unref()),e.emit("connect");var d=!0,c=!1,f=void 0;try{for(var h,g=e._pendingData[Symbol.iterator]();!(d=(h=g.next()).done);d=!0){var v=h.value;e.emit("data",v)}}catch(r){c=!0,f=r}finally{try{!d&&g.return&&g.return()}finally{if(c)throw f}}e._pendingData=[]}else setTimeout(t,100)}}))}()}}},{key:"_onInterval",value:function(){!this._cb||!this._channel||this._channel.bufferedAmount>c||this._onChannelBufferedAmountLow()}},{key:"_onSignalingStateChange",value:function(){this.destroyed||("stable"===this._pc.signalingState&&(this._isNegotiating=!1,this._queuedNegotiation?(this._queuedNegotiation=!1,this._needsNegotiation()):this.emit("negotiated")),this.emit("signalingStateChange",this._pc.signalingState))}},{key:"_onIceCandidate",value:function(e){this.destroyed||(e.candidate&&this.trickle?this.emit("signal",{type:"candidate",candidate:{candidate:e.candidate.candidate,sdpMLineIndex:e.candidate.sdpMLineIndex,sdpMid:e.candidate.sdpMid}}):e.candidate||this._iceComplete||(this._iceComplete=!0,this.emit("_iceComplete")),e.candidate&&this._startIceCompleteTimeout())}},{key:"_onChannelMessage",value:function(e){if(!this.destroyed){var t=e.data;t instanceof ArrayBuffer&&(t=l.Buffer.from(t)),this._connected?this.emit("data",t):this._pendingData.length<10&&this._pendingData.push(t)}}},{key:"_onChannelBufferedAmountLow",value:function(){if(!this.destroyed&&this._cb){var e=this._cb;this._cb=null,e(null)}}},{key:"_onChannelOpen",value:function(){this._connected||this.destroyed||(this._channelReady=!0,this._maybeReady())}},{key:"_onChannelClose",value:function(){this.destroyed||this.destroy()}},{key:"bufferSize",get:function(){return this._channel&&this._channel.bufferedAmount||0}},{key:"connected",get:function(){return this._connected&&"open"===this._channel.readyState}},{key:"isBufferedAmountHigh",get:function(){return this._channel.bufferedAmount>c}}]),t}(s.default);h.config={iceServers:[{urls:["stun:stun.l.google.com:19302","stun:global.stun.twilio.com:3478"]}],sdpSemantics:"unified-plan"},h.channelConfig={},t.default=h,e.exports=t.default},831:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var i=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.peerMap=new Map}return r(e,[{key:"isEmpty",value:function(){return 0===this.peerMap.size}},{key:"size",value:function(){return this.peerMap.size}},{key:"clear",value:function(){this.peerMap.clear()}},{key:"getPeers",value:function(){return[].concat(n(this.peerMap.values()))}},{key:"getPeerValues",value:function(){return this.peerMap.values()}},{key:"hasPeer",value:function(e){return this.peerMap.has(e)}},{key:"addPeer",value:function(e,t){this.peerMap.set(e,t)}},{key:"getPeerIds",value:function(){return[].concat(n(this.peerMap.keys()))}},{key:"removePeer",value:function(e){this.peerMap.delete(e)}},{key:"getPeersOrderByWeight",value:function(){var e=this.getAvailablePeers();return e.sort((function(e,t){return 0===t.weight?1:0===e.weight?-1:t.weight-e.weight})),e}},{key:"getPeer",value:function(e){return this.peerMap.get(e)}},{key:"getAvailablePeers",value:function(){return this.getPeers().filter((function(e){return e.isAvailableUrgently}))}}]),e}();t.default=i,e.exports=t.default},468:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(297),s=(n=a)&&n.__esModule?n:{default:n};var o=function(){function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:10;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.engine=t,this.config=r,this.trickle=r.trickleICE,this.poolSize=n,this.pool=[],r.ICEPreflight&&this.reset(),this.trickle=!1}return i(e,[{key:"reset",value:function(){this.destroy();for(var e=0;e<this.poolSize;e++)this.pool.push(this._createPeer())}},{key:"_createPeer",value:function(){return new s.default(this.engine,void 0,void 0,!0,this.config,{trickle:this.trickle})}},{key:"getPeer",value:function(){if(0===this.pool.length)return this._createPeer();var e=this.pool.shift();return this.pool.length<5&&this.pool.push(this._createPeer()),e}},{key:"destroy",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,i=this.pool[Symbol.iterator]();!(e=(n=i.next()).done);e=!0){n.value.destroy(!0)}}catch(e){t=!0,r=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw r}}this.pool=[]}},{key:"available",get:function(){return 0!==this.pool.length&&this.pool[0].signalMsgs.length>0}}]),e}();t.default=o,e.exports=t.default},89:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=f(r(911)),s=f(r(648)),o=f(r(816)),l=r(408),u=f(r(308)),d=f(r(524)),c=r(921);function f(e){return e&&e.__esModule?e:{default:e}}var h=function(e){function t(e,r,i,a,s){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var u=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));u.channel=e.fetcher.channelId,u.logger=e.logger,u.config=s,u.isInitiator=a,u.options=o,u.intermediator=o.intermediator||null,u.signalMsgs=[],u.assignPeerId(r,i),u.platform="unknown",u.super=!1,u.mobile=!1,u.mobileWeb=!1,u.mobileNet=!1,u.connected=!1,u.msgQueue=[],u.miss=0,u.notifySet=new Set,u.bufArr=[],u.packetSize=l.DEFAULT_PACKET_SIZE,u.sendReqQueue=[],u.downloading=!1,u.uploading=!1,u.choked=!1,u.streamListeners=[],u.pieceMsg={},u.datasToSend=[],u.bytesUploaded=0,u.dataWriting=!1,u.timeSendRequest=0,u.timeReceivePiece=0,u.timeSendPiece=0,u.weight=0,u.peersConnected=1,u.uploadSpeed=0,u.currentLevel=0,u.currentPos=0,u.useBackupSignal=!1,u.gotPeersTS=0,u.webRTCConfig={};var d=u.options.stuns;if(d&&d.length>0){var c=[];d.forEach((function(e){u.logger.info("use stun "+e),c.push({urls:e})})),u.webRTCConfig.iceServers=c}return u.config.webRTCConfig&&(u.webRTCConfig=n({},u.config.webRTCConfig,u.webRTCConfig)),u.playlistMap=new Map,u._initPeerChannel(),u.notFatalClosed=!1,u.startSN=Number.MAX_SAFE_INTEGER,u.endSN=-1,u._loadedBytes=0,u}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,null,[{key:"defaultPacketSize",get:function(){return l.DEFAULT_PACKET_SIZE}},{key:"VERSION",get:function(){return"5"}}]),i(t,[{key:"assignPeerId",value:function(e,t){var r=this;this.remotePeerId=t,this.channelId=this.isInitiator?e+"-"+t:t+"-"+e,t&&(this.timeJoin=(0,l.getCurrentTs)(),this.dataExchangeTs=this.timeJoin,this.gotStatsTs=this.timeJoin,this._startTimer()),setTimeout((function(){r.signalMsgs.length>0&&r.emit(o.default.DC_SIGNAL_BATCH,r.signalMsgs)}),0)}},{key:"_startTimer",value:function(){var e=this;this.connTimeout=setTimeout((function(){e.logger.warn("dc "+e.channelId+" connection timeout"),e.emit(o.default.DC_TIMEOUT)}),15e3)}},{key:"cancelDownload",value:function(e,t,r){return!(!r||!this.downloading)&&(!(this.bufSN>e)&&(!(this.streamListeners.length>0)&&(this.logger.info("cancel download "+r+" to "+this.remotePeerId+" remain packets "+this.remainAttachments),this.timeReceivePiece=0,this.sendJson({event:o.default.DC_PIECE_CANCEL,sn:e,level:t,seg_id:r}))))}},{key:"addStreamListener",value:function(e,t,r){this.streamListeners.push({handler:r,peerId:t})}},{key:"removeStreamListener",value:function(e){this.streamListeners=this.streamListeners.filter((function(t){return t.peerId!==e||(t.handler(void 0,void 0,!0,"aborted by cancel"),!1)}))}},{key:"_initPeerChannel",value:function(){var e=this,t=new a.default({initiator:this.isInitiator,trickle:this.options.trickle||!1,config:this.webRTCConfig});this._datachannel=t,t.on("error",(function(t){var r=!0;(e.connected||e.notFatalClosed)&&(r=!1),e.emit(o.default.DC_ERROR,r)})),t.on("signal",(function(t){!e.useBackupSignal&&e.signalMsgs.length<10&&e.signalMsgs.push(t),e.emit(o.default.DC_SIGNAL,t)}));t.on("connect",(function(){for(e.logger.info("datachannel CONNECTED from "+(e.intermediator?"peer":"server")+" to "+e.remotePeerId),e.connected=!0,clearTimeout(e.connTimeout),e.signalMsgs=[],e.emit(o.default.DC_OPEN);e.msgQueue.length>0;){var t=e.msgQueue.shift();e.emit(t.event,t)}})),t.on("data",(function(t){var r=e.logger;if("string"==typeof t){var n=JSON.parse(t);if(!n)return void r.error("dc received string is null");if(!e.connected)return void e.msgQueue.push(n);var i=n.event,a=void 0;switch(a=i!==o.default.DC_PLAYLIST&&i!==o.default.DC_PEER_SIGNAL?"string: "+t:"event: "+i,r.debug("datachannel receive "+a+" from "+e.remotePeerId),i){case o.default.DC_HAVE:if(e.emit(n.event,n),!n.sn)return;e.config.live||(n.sn<e.startSN&&(e.startSN=n.sn),n.sn>e.endSN&&(e.endSN=n.sn));break;case o.default.DC_PIECE:e.downloading=!0,e.dataExchangeTs=(0,l.getCurrentTs)(),e.timeReceivePiece=performance.now(),e.pieceMsg=n,e._prepareForBinary(n.attachments,n.seg_id,n.sn,n.size),e.emit(n.event,n);break;case o.default.DC_PIECE_CANCEL:r.info("send queue "+e.datasToSend.length+", uploading "+e.uploading),e.emit(n.event,n),e.sendMsgPieceAbort("transfer canceled",n.seg_id);break;case o.default.DC_PIECE_NOT_FOUND:e._sendNextReq()||(e.downloading=!1),e.emit(n.event,n);break;case o.default.DC_REQUEST:e._handleRequestMsg(n);break;case o.default.DC_PIECE_ACK:e._handlePieceAck(n.seg_id,n.size,n.miss);break;case o.default.DC_STATS:e._handleStats(n);break;case o.default.DC_PLAYLIST:e.config.sharePlaylist&&e._handlePlaylist(n);break;case o.default.DC_METADATA:e._handleMetadata(n);break;case o.default.DC_PIECE_ABORT:e.downloading&&(e._notifyDownloadListenersAbort("aborted by upstream peer"),e.emit(o.default.DC_PIECE_ABORT,n)),e.downloading=!1;break;case o.default.DC_CHOKE:r.info("choke peer "+e.remotePeerId),e.choked=!0;break;case o.default.DC_UNCHOKE:r.info("unchoke peer "+e.remotePeerId),e.choked=!1;break;case o.default.DC_CLOSE:e.emit(n.event,n.fatal||!1);break;default:e.emit(n.event,n)}}else{if(!t)return void r.error("datachannel on data is undefined!");if(!e.downloading)return void r.warn("peer "+e.remotePeerId+" not downloading, data size "+t.byteLength+" pieceMsg "+JSON.stringify(e.pieceMsg));e._handleBinaryMsg(t)}})),t.once("close",(function(){e.emit(o.default.DC_CLOSE,!1)})),t.on("iceStateChange",(function(t,r){e.connected&&"disconnected"===t&&(e.logger.warn(e.remotePeerId+" disconnected"),e.emit(o.default.DC_DISCONNECT))}))}},{key:"sendJson",value:function(e){if(!this.remotePeerId)return!1;e.event!==o.default.DC_PLAYLIST&&e.event!==o.default.DC_PEER_SIGNAL?this.logger.debug("dc bufferSize "+this._datachannel.bufferSize+" send "+JSON.stringify(e)+" to "+this.remotePeerId):this.logger.debug("dc send event "+e.event+" to "+this.remotePeerId);var t=JSON.stringify(e);return t.length>l.DEFAULT_PACKET_SIZE?(this.logger.error("string to send is too large"),!1):this.send(t,!1)}},{key:"send",value:function(e){return!(arguments.length>1&&void 0!==arguments[1])||arguments[1]?(this.datasToSend.push(e),this.dataWriting||this._sendDataSync(),!0):this.sendImmediately(e)}},{key:"_sendDataSync",value:function(){var e=this;if(this._datachannel.connected&&0!==this.datasToSend.length){this.dataWriting=!0;var t=this.datasToSend.shift();t?("string"!=typeof t&&(this.bytesUploaded+=t.byteLength),this._datachannel.write(t,(function(t){if(t)return e.dataWriting=!1,e.logger.warn(t.message),void e.emit(o.default.DC_ERROR,!1);e._sendDataSync()}))):this.logger.error("sendDataSync data is undefined!")}else this.dataWriting=!1}},{key:"sendImmediately",value:function(e){if(this._datachannel.connected)try{return this._datachannel.send(e),!0}catch(e){this.logger.warn("datachannel "+this.channelId+" send data failed, close it"),this.emit(o.default.DC_ERROR,!1)}return!1}},{key:"sendMsgHave",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=r.reverse||void 0;delete r.reverse,this.sendJson(n({event:i?o.default.DC_HAVE_REVERSE:o.default.DC_HAVE,sn:e,seg_id:t},r))}},{key:"sendPieceNotFound",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.uploading=!1,this.sendJson(n({event:o.default.DC_PIECE_NOT_FOUND,seg_id:t||void 0,sn:e},r))}},{key:"sendPeers",value:function(e){this.sendJson({event:o.default.DC_PEERS,peers:e})}},{key:"sendPeersRequest",value:function(){this.sendJson({event:o.default.DC_GET_PEERS})}},{key:"sendMsgStats",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n({event:o.default.DC_STATS,total_conns:e},t);this.sendJson(r)}},{key:"sendMsgPlaylist",value:function(e,t,r){var n=this.playlistMap.get(e);if(!(n&&n.seq>=r)){var i={event:o.default.DC_PLAYLIST,url:e,data:t,seq:r};this.playlistMap.set(e,{data:t,seq:r}),this.sendJson(i)}}},{key:"sendMsgSignal",value:function(e,t,r){return this.sendJson({event:o.default.DC_PEER_SIGNAL,action:"signal",to_peer_id:e,from_peer_id:t,data:r})}},{key:"sendMsgSignalReject",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]&&arguments[3];return this.sendJson({event:o.default.DC_PEER_SIGNAL,action:"reject",to_peer_id:e,from_peer_id:t,reason:r,fatal:n})}},{key:"sendMetaData",value:function(e,t,r,n){var i=arguments.length>4&&void 0!==arguments[4]&&arguments[4];this.isInitiator&&(this.timeSendRequest=performance.now()),this.sendJson({event:o.default.DC_METADATA,field:e,platform:o.default.DC_PLAT_WEB,mobile:!!d.default.isMobile(),mobile_net:i,channel:this.channel,version:"1.22.1",sequential:t,peers:r,region:n})}},{key:"sendPartialBuffer",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};this.sendMsgPiece(e,r);for(var n=0;n<t.length;n++)this.send(t[n])}},{key:"sendMsgPiece",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.uploading){this.datasToSend=[],this.bytesUploaded=0,e.ext||(e.ext={}),e.ext.from&&t.from&&(t.from=e.ext.from+"->"+t.from),t.incompletes&&e.ext.incompletes&&(t.incompletes+=e.ext.incompletes),t=Object.assign({},e.ext,t);var r=n({},e,{ext:t});this.sendJson(r)}}},{key:"sendBuffer",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},i=n.reverse||void 0;if(delete n.reverse,r){var a=r.byteLength,s=0,l=0;a%this.packetSize==0?l=a/this.packetSize:(l=Math.floor(a/this.packetSize)+1,s=a%this.packetSize);var u={event:o.default.DC_PIECE,attachments:l,seg_id:t,sn:e,level:n.level,size:a,reverse:i};delete n.level,this.sendMsgPiece(u,n);var d=function(e,t,r,n){var i=[];if(n){for(var a=void 0,s=0;s<r-1;s++)a=e.slice(s*t,(s+1)*t),i.push(a);a=e.slice(e.byteLength-n,e.byteLength),i.push(a)}else for(var o=void 0,l=0;l<r;l++)o=e.slice(l*t,(l+1)*t),i.push(o);return i}(r,this.packetSize,l,s);this._sendBufferArray(d,i),this.uploading=!1,this.timeSendPiece=performance.now()}else this.logger.error("sendBuffer payload is undefined!")}},{key:"requestDataById",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a=n({event:o.default.DC_REQUEST,seg_id:e,sn:t},i,{urgent:r});this.downloading?(this.logger.info(this.remotePeerId+" add req "+e+" in queue"),r?this.sendReqQueue.unshift(a):this.sendReqQueue.push(a)):this._realRequestData(a)}},{key:"requestDataBySN",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=n({event:o.default.DC_REQUEST,sn:e},r,{urgent:t});this.downloading?(this.logger.info("add req "+e+" in queue"),t?this.sendReqQueue.unshift(i):this.sendReqQueue.push(i)):this._realRequestData(i)}},{key:"_sendBufferArray",value:function(e){for(var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1]?e.reverse():e,r=0;r<t.length;r++)this.send(t[r])}},{key:"_realRequestData",value:function(e){this.sendJson(e),this.timeSendRequest=performance.now(),this.downloading=!0}},{key:"shouldWaitForRemain",value:function(e){return 0!==this.bufArrSize&&(0!==this.timeReceivePiece&&this.currentLoadSpeed()>=this.minRequiredSpeed(e))}},{key:"close",value:function(e){e||(this.notFatalClosed=!0),this.emit(o.default.DC_CLOSE,e)}},{key:"receiveSignal",value:function(e){e&&this._datachannel.signal(e)}},{key:"_notifyDownloadListenersAbort",value:function(e){var t=!0,r=!1,n=void 0;try{for(var i,a=this.streamListeners[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){(0,i.value.handler)(void 0,void 0,!0,e)}}catch(e){r=!0,n=e}finally{try{!t&&a.return&&a.return()}finally{if(r)throw n}}this.streamListeners=[]}},{key:"destroy",value:function(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.logger.info("destroy datachannel "+this.channelId),clearTimeout(this.chokeTimer),clearTimeout(this.connTimeout),this._notifyDownloadListenersAbort("upstream peer is closed");var t={event:o.default.DC_CLOSE,fatal:e};this.sendJson(t),this._datachannel.removeAllListeners(),this.removeAllListeners(),this._datachannel.destroy()}},{key:"_handleBinaryMsg",value:function(e){var t=this.pieceMsg,r=t.attachments,n=t.reverse;this.listenerCount(o.default.DC_RESPONSE)>0&&this.bufArr.push(e),this._loadedBytes+=e.byteLength,this.remainAttachments--;var i=n?this.remainAttachments+1:r-this.remainAttachments,a=0===this.remainAttachments;if(this.emit(o.default.DC_PIECE_DATA,this.bufSN,this.segId,e,i,a,this.pieceMsg),this.streamListeners.length>0){var s=!0,l=!1,u=void 0;try{for(var d,c=this.streamListeners[Symbol.iterator]();!(s=(d=c.next()).done);s=!0){(0,d.value.handler)(this.bufSN,this.segId,!1,e,a)}}catch(e){l=!0,u=e}finally{try{!s&&c.return&&c.return()}finally{if(l)throw u}}}if(a){if(this.streamListeners=[],this.timeSendRequest>0)if(this.super)this.weight=1;else{var f=this.expectedSize/(performance.now()-this.timeSendRequest);this.weight=this.weight>0?.6*this.weight+.4*f:f}this.sendJson({event:o.default.DC_PIECE_ACK,seg_id:this.segId,size:this.expectedSize,miss:this.miss||void 0}),this.timeSendRequest=0,this.timeReceivePiece=0,this._sendNextReq()||(this.downloading=!1),this._handleBinaryData(n)}}},{key:"_sendNextReq",value:function(){if(this.sendReqQueue.length>0){var e=this.sendReqQueue.shift();return this.logger.info("get msg from sendReqQueue "+JSON.stringify(e)),this._realRequestData(e),!0}return!1}},{key:"_handlePlaylist",value:function(e){var t=e.url,r=e.data,n=e.seq;this.playlistMap.set(t,{data:r,seq:n})}},{key:"getLatestPlaylist",value:function(e,t){if(!this.playlistMap.has(e))return null;var r=this.playlistMap.get(e);return r.seq<=t||r.seq>t+2?null:r}},{key:"_handleMetadata",value:function(e){var t=this.logger;if(this.isInitiator){var r=performance.now()-this.timeSendRequest;r>0&&(this.weight=1e5/r,t.info("handle Metadata from "+this.remotePeerId+" initial weight "+this.weight)),this.timeSendRequest=0}var n=e.channel;if(this.channel!==n)return t.error("peer channel "+n+" not matched!"),void this.emit(o.default.DC_ERROR,!0);if(e.super){t.info("got super peer "+this.remotePeerId),this.super=!0;var i=this.config.token;if(i&&e.token!==i)return t.warn("super peer token "+e.token+" not matched!"),void this.emit(o.default.DC_ERROR,!0)}switch(e.region&&(this.region=e.region),e.platform){case o.default.DC_PLAT_ANDROID:this.platform=o.default.DC_PLAT_ANDROID;break;case o.default.DC_PLAT_IOS:this.platform=o.default.DC_PLAT_IOS;break;case o.default.DC_PLAT_WEB:this.platform=o.default.DC_PLAT_WEB}if(this.mobile=e.mobile||!1,this.mobileNet=e.mobile_net||!1,this.mobileWeb=this.mobile&&this.platform===o.default.DC_PLAT_WEB||!1,this.sequential=e.sequential,t.info(this.remotePeerId+" platform "+this.platform+" sequential "+this.sequential),e.peers&&(this.peersConnected+=e.peers,t.info(this.remotePeerId+" now has "+this.peersConnected+" peers")),this.emit(o.default.DC_METADATA,e),e.field&&!this.config.live&&e.sequential){var a=e.field;if(Array.isArray(a))this._handleField(a);else for(var s in a)this._handleField(a[s])}}},{key:"_handleField",value:function(e){var t=this;e.forEach((function(e){e>=0&&(e<t.startSN&&(t.startSN=e),e>t.endSN&&(t.endSN=e))}))}},{key:"_handleStats",value:function(e){this.gotStatsTs=(0,l.getCurrentTs)();var t=e.total_conns;t>0&&this.peersConnected!==t&&(this.peersConnected=t,this.logger.info(this.remotePeerId+" now has "+this.peersConnected+" peers")),e.level&&(this.currentLevel=e.level),e.pos&&(this.currentPos=e.pos)}},{key:"_handleRequestMsg",value:function(e){if(this.dataExchangeTs=(0,l.getCurrentTs)(),this.uploading)return this.logger.warn(this.remotePeerId+" is uploading when receive request"),void this.sendPieceNotFound(e.sn,e.seg_id,{level:e.level});this.uploading=!0,this.emit(o.default.DC_REQUEST,e)}},{key:"_handlePieceAck",value:function(e,t,r){0!==this.timeSendPiece&&(this.uploadSpeed=Math.round(t/(performance.now()-this.timeSendPiece)*2),this.timeSendPiece=0,this.logger.info(this.remotePeerId+" uploadSpeed is "+this.uploadSpeed)),r>0&&this.logger.warn("peer "+this.remotePeerId+" miss "+r),this.bytesUploaded>0&&this.emit(o.default.DC_PIECE_ACK,{seg_id:e,size:t})}},{key:"_prepareForBinary",value:function(e,t,r,n){this.bufArr=[],this._loadedBytes=0,this.remainAttachments=e,this.segId=t,this.bufSN=r,this.expectedSize=n}},{key:"_handleBinaryData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.listenerCount(o.default.DC_RESPONSE)>0){e&&this.bufArr.reverse();var t=c.Buffer.concat(this.bufArr),r=t.byteLength;if(r===this.expectedSize){var n=t.buffer,i=new u.default(this.bufSN,this.segId,n,this.remotePeerId,this.pieceMsg.level);this.emit(o.default.DC_RESPONSE,i,this.weight)}else this.logger.error(this.segId+" expectedSize "+this.expectedSize+" != byteLength "+r)}this.bufArr=[]}},{key:"checkIfNeedChoke",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],r=this.logger,n=performance.now()-this.timeSendRequest;if((t||!(n<1500))&&(this.miss++,r.info(this.remotePeerId+" miss "+this.miss),this.miss>2&&!this.choked)){this.choked=!0;var i=30*this.miss;i<=150?(r.warn("datachannel "+this.channelId+" is choked"),this.chokeTimer=setTimeout((function(){e.choked=!1,r.warn("datachannel "+e.channelId+" is unchoked")}),1e3*i)):r.warn("datachannel "+this.channelId+" is choked permanently")}}},{key:"loadtimeout",value:function(){var e=this.logger,t=this.pieceMsg;return e.warn("timeout while downloading from "+this.remotePeerId+", "+this.bufArrSize+" of "+t.attachments+" packets loaded"),this.checkIfNeedChoke(),!0}},{key:"sendMsgPieceAbort",value:function(e,t){if(arguments.length>2&&void 0!==arguments[2]&&arguments[2]||this.uploading||0!==this.datasToSend.length){this.uploading=!1,this.datasToSend=[],this._handlePieceAck(t,this.bytesUploaded,0),this.bytesUploaded=0;var r={event:o.default.DC_PIECE_ABORT,reason:e};return this.sendJson(r)}}},{key:"loadedBytes",value:function(){return this._loadedBytes}},{key:"currentLoadSpeed",value:function(){return 0===this.timeReceivePiece?0:this.loadedBytes()/(performance.now()-this.timeReceivePiece)}},{key:"minRequiredSpeed",value:function(e){return(this.pieceMsg.size-this.loadedBytes())/e}},{key:"isAvailable",get:function(){return this.downloadNum<2&&!this.choked}},{key:"isAvailableUrgently",get:function(){return!this.downloading&&!this.choked}},{key:"downloadNum",get:function(){return this.downloading?this.sendReqQueue.length+1:0}},{key:"bufArrSize",get:function(){return this.downloading?this.pieceMsg.attachments-this.remainAttachments:0}}]),t}(s.default);t.default=h,e.exports=t.default},9:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var n=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.internalMap=new Map}return r(e,[{key:"has",value:function(e){return this.internalMap.has(e)}},{key:"set",value:function(e,t){if(this.internalMap.has(e)){var r=this.internalMap.get(e);if(r&&!r.includes(t))return void r.push(t)}this.internalMap.set(e,[t])}},{key:"setPeerUnknown",value:function(e){this.internalMap.set(e,null)}},{key:"checkIfPeerUnknown",value:function(e){return this.internalMap.has(e)&&!this.internalMap.get(e)}},{key:"getAllPeerIds",value:function(e){var t=this.internalMap.get(e);return t||[]}},{key:"get",value:function(e){return this.getOnePeerId(e)}},{key:"getOnePeerId",value:function(e){if(this.internalMap.has(e)&&this.internalMap.get(e))return this.internalMap.get(e)[0];return null}},{key:"delete",value:function(e){this.internalMap.delete(e)}},{key:"clear",value:function(){this.internalMap.clear()}}]),e}();t.default=n,e.exports=t.default},540:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=l(r(648)),a=l(r(816)),s=l(r(831)),o=r(408);function l(e){return e&&e.__esModule?e:{default:e}}var u=Symbol("shareOnly"),d=function(e){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.engine=e,n.config=r,n.logger=e.logger,n.bufMgr=null,n.peerManager=new s.default,n.fragLoading=!1,n._setupEngine&&n._setupEngine(),n.startCheckConnsTimer(),n.dcDownloadTimeout=r.dcDownloadTimeout,n[u]=!1,n.downloadOnly=!1,n.loadedPeerNum=0,n.minConns=5,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"startCheckConnsTimer",value:function(){var e=this;this.checkConnsTimer=setInterval((function(){e.logger.info("start check conns");var t=e.getStatsForPeer(),r=e.peersNum,n=(0,o.getCurrentTs)();e.getPeers().forEach((function(i){r>e.minConns+1&&(n-i.dataExchangeTs>120||n-i.gotStatsTs>=83)?(e.logger.warn("close dead peer "+i.remotePeerId+" level "+i.currentLevel),i.close(!1),r--):i.connected&&i.sendMsgStats(r,t)}))}),4e4)}},{key:"getStatsForPeer",value:function(){return{}}},{key:"_handlePieceAborted",value:function(){}},{key:"requestPeers",value:function(){var e=(0,o.getCurrentTs)(),t=0,r=!0,n=!1,i=void 0;try{for(var a,s=this.getPeers()[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var l=a.value;l.mobileNet||l.super||(e-l.gotPeersTS<60?this.logger.warn(l.remotePeerId+" just got peers, ignored"):(l.sendPeersRequest(),l.gotPeersTS=e,t++))}}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}return t}},{key:"chokePeerRequest",value:function(e){var t={event:a.default.DC_CHOKE};e?e.sendJson(t):this._broadcastToPeers(t)}},{key:"unchokePeerRequest",value:function(e){var t={event:a.default.DC_UNCHOKE};e?e.sendJson(t):this._broadcastToPeers(t)}},{key:"stopRequestFromPeers",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,i=this.getPeers()[Symbol.iterator]();!(e=(n=i.next()).done);e=!0){n.value.choked=!0}}catch(e){t=!0,r=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw r}}}},{key:"resumeRequestFromPeers",value:function(){var e=!0,t=!1,r=void 0;try{for(var n,i=this.getPeers()[Symbol.iterator]();!(e=(n=i.next()).done);e=!0){n.value.choked=!1}}catch(e){t=!0,r=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw r}}}},{key:"setShareOnly",value:function(){this[u]=!0}},{key:"deletePeer",value:function(e){e.downloading&&this._handlePieceAborted(e.remotePeerId),this.peerManager.hasPeer(e.remotePeerId)&&this.peerManager.removePeer(e.remotePeerId),this._peersStats(this.peerManager.getPeerIds())}},{key:"getPeers",value:function(){return[].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(this.peerManager.getPeerValues()))}},{key:"addPeer",value:function(e){var t=this.logger;this.peerManager.addPeer(e.remotePeerId,e),this[u]&&(e.choked=!0);var r=this.peerManager.getPeerIds();this._peersStats(r);var n=e.region||{},i=n.asn,a=n.country;t.info("add peer "+e.remotePeerId+" country "+(a||"")+" asn "+(i||"")+", now has "+r.length+" peers")}},{key:"hasPeer",value:function(e){return this.peerManager.hasPeer(e)}},{key:"getIdlePeer",value:function(){return this.peerManager.getAvailablePeers()}},{key:"onBufferManagerSegAdded",value:function(e){}},{key:"_broadcastLost",value:function(e,t,r,n){this.config.live||this._broadcastToPeers({event:a.default.DC_LOST,sn:e,seg_id:t||void 0,level:r},n)}},{key:"destroy",value:function(){var e=this.logger;this.peersNum>0&&this.peerManager.clear(),this.removeAllListeners(),clearInterval(this.checkConnsTimer),clearTimeout(this.checkTimer),e.warn("destroy BtScheduler")}},{key:"notifyPeersLoaded",value:function(e){}},{key:"_setupDC",value:function(e){var t=this,r=this.logger;e.on(a.default.DC_PIECE_ACK,(function(n){n.size&&(t.engine.fetcher.reportUploaded(n.size),r.info("uploaded "+n.seg_id+" size "+n.size+" to "+e.remotePeerId))})).on(a.default.DC_PIECE_ABORT,(function(n){r.warn("peer "+e.remotePeerId+" download aborted, reason "+n.reason),t._handlePieceAborted(e.remotePeerId)})).on(a.default.DC_DISCONNECT,(function(){t.peersNum>=t.minConns&&(t.logger.warn("close disconnected peer "+e.remotePeerId),e.close(!1))}))}},{key:"_broadcastToPeers",value:function(e,t){var r=!0,n=!1,i=void 0;try{for(var a,s=this.getPeers()[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var o=a.value;t&&o===t||o.sendJson(e)}}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}}},{key:"_peersStats",value:function(e){this.engine.emitEvent("peers",e);var t=this.engine.config.getPeersInfo;(0,o.isFunction)(t)&&t(e)}},{key:"startCheckPeersTimer",value:function(){var e=this;this.logger.info("startCheckPeersTimer");this.checkTimer=setTimeout((function t(){e.checkPeers();var r=1e3*(0,o.calCheckPeersDelay)(e.loadedPeerNum);e.loadedPeerNum=0,e.checkTimer=setTimeout(t,r)}),2e4)}},{key:"removeStreamListener",value:function(e,t){var r=this.requestingMap.get(e);if(r)r.removeStreamListener(t);else{var n=this.segmentBuilderMap.get(e);n&&n.removeStreamListener(t)}}},{key:"setTargetPeersFromGroup",value:function(e,t,r,n){if(e.hasReversePeer){if((r=t.concat(r)).length>0)return this.targetPeers.forwardPeer=r[0],!0}else if(e.hasForwardPeer&&(n=t.concat(n)).length>0)return this.targetPeers.reversePeer=n[0],!0;return t.length>0?(e.hasForwardBuffer?this.targetPeers.reversePeer=t[0]:this.targetPeers.forwardPeer=t[0],!0):(this.targetPeers=(0,o.getBestTargetPair)(t,r,n),this.targetPeers.some((function(e){return!!e})))}},{key:"isMobileNet",get:function(){return this.engine.isMobileNet}},{key:"hasPeers",get:function(){return this.peersNum>0}},{key:"peersNum",get:function(){return this.peerManager.size()}},{key:"hasIdlePeers",get:function(){var e=this.logger,t=this.getIdlePeer().length;if(e.info("peers: "+this.peersNum+" idle peers: "+t),t<this.peersNum){var r=this.peerManager.getPeers(),n=r.filter((function(e){return e.downloading}));e.warn("downloading: "+n.length+" choked: "+r.filter((function(e){return e.choked})).length);var i=!0,a=!1,s=void 0;try{for(var o,l=n[Symbol.iterator]();!(i=(o=l.next()).done);i=!0){var u=o.value;e.warn(u.remotePeerId+" loading "+u.segId+" remains "+u.remainAttachments+" total "+u.pieceMsg.attachments)}}catch(e){a=!0,s=e}finally{try{!i&&l.return&&l.return()}finally{if(a)throw s}}}return t>0}},{key:"bufferManager",set:function(e){var t=this;this.bufMgr=e,e.on(a.default.BM_LOST,(function(e){var r=e.sn,n=e.segId,i=e.next,a=e.level;t._broadcastLost(r,n,a),t.onBufferManagerLost(r,n,i,a)})).on(a.default.BM_SEG_ADDED,(function(e){t.onBufferManagerSegAdded(e)}))}}]),t}(i.default);t.default=d,e.exports=t.default},555:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=o(r(648)),a=o(r(816)),s=o(r(524));function o(e){return e&&e.__esModule?e:{default:e}}function l(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var u=function(e){function t(e,r){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var i=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));i.isSequential=n,i.logger=r.logger;var a=e.browserInfo.device;return i.maxBufSize=a===s.default.device.PC_WEB||a===s.default.device.PC_NATIVE?r.memoryCacheLimit.pc:r.memoryCacheLimit.mobile,r.live&&(i.maxBufSize=36700160),i._segPool=new Map,i._currBufSize=0,i.id2Sn=new Map,i.overflowed=!1,i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"hasSegOfId",value:function(e){if(this.isSequential){var t=this.id2Sn.get(e);return this._segPool.has(t)}return this._segPool.has(e)}},{key:"hasSegOfSN",value:function(e){return!!this.isSequential&&this._segPool.has(e)}},{key:"_calSegPoolSize",value:function(){var e=0;return this._segPool.forEach((function(t){e+=t.size})),e}},{key:"putSeg",value:function(e){if(this._currBufSize>=1.5*this.maxBufSize&&(this._currBufSize=this._calSegPoolSize(),this._currBufSize>=1.5*this.maxBufSize&&(this.clear(),this.overflowed=!1)),this.isSequential){if(this._segPool.has(e.sn))return;this._addSequentialSeg(e)}else{if(this._segPool.has(e.segId))return;this._addUnsequentialSeg(e)}}},{key:"_addSequentialSeg",value:function(e){var t=this.logger,r=e.segId,n=e.sn,i=e.size;this.id2Sn.set(r,n),this._segPool.set(n,e),this._currBufSize+=parseInt(i);var s=this._segPool.size;if(this.emit(""+a.default.BM_ADDED_SN_+e.sn,e),this.emit(a.default.BM_SEG_ADDED,e),!(this._currBufSize<this.maxBufSize||s<=5)){var o=Array.from(this._segPool.keys()).sort((function(e,t){return e-t})),l=0;do{if(l++>10){console.error("too much loops in SegmentCache");break}var u=o.shift();if(void 0!==u){var d=o[0],c=this._segPool.get(u);if(c){var f=c.size;this._currBufSize-=parseInt(f),this._segPool.delete(u),this.id2Sn.delete(c.segId),t.info("pop seg "+u+" size "+f+" currBufSize "+this._currBufSize),this.overflowed||(this.overflowed=!0),this.emit(a.default.BM_LOST,{sn:u,segId:c.segId,next:d,level:c.level})}else t.error("lastSeg not found")}else t.error("lastSN not found")}while(this._currBufSize>=this.maxBufSize&&this._segPool.size>5)}}},{key:"_addUnsequentialSeg",value:function(e){var t=this.logger,r=e.segId,n=e.size;this._segPool.set(r,e),this._currBufSize+=parseInt(n),this.emit(""+a.default.BM_ADDED_SEG_+e.segId,e),this.emit(a.default.BM_SEG_ADDED,e);for(var i=0;this._currBufSize>=this.maxBufSize&&this._segPool.size>5;){if(i++>10){console.error("too much loops in SegmentCache");break}var s=[].concat(l(this._segPool.values())).shift(),o=s.segId,u=s.size;this._currBufSize-=parseInt(u),t.info("pop seg "+o+" size "+u),this._segPool.delete(o),this.overflowed||(this.overflowed=!0),this.emit(a.default.BM_LOST,{sn:-1,segId:o,level:s.level})}}},{key:"getSegById",value:function(e){if(this.isSequential){var t=this.id2Sn.get(e);return this._segPool.get(t)}return this._segPool.get(e)}},{key:"getSegIdBySN",value:function(e){var t=this._segPool.get(e);return t?t.segId:null}},{key:"getSegBySN",value:function(e){if(this.isSequential)return this._segPool.get(e);throw new Error("fatal error in SegmentCache")}},{key:"clear",value:function(){this.logger.warn("clear segment cache"),this._segPool.clear(),this.id2Sn.clear(),this._currBufSize=0}},{key:"destroy",value:function(){this.clear(),this.removeAllListeners()}},{key:"currBufSize",get:function(){return this._currBufSize}}]),t}(i.default);t.default=u,e.exports=t.default},308:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var n=function(){function e(t,r,n,i){var a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.sn=t,this.segId=r,this.data=n,this.fromPeerId=i,this.level=a||0}return r(e,[{key:"size",get:function(){return this.data.byteLength}},{key:"isSequential",get:function(){return this.sn>=0}}],[{key:"fromSegment",value:function(t){var r=new e(t.sn,t.segId,t.data,t.fromPeerId,t.level);return r.from=t.from,r}}]),e}();t.default=n,e.exports=t.default},578:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=h(r(648)),s=h(r(431)),o=h(r(299)),l=h(r(816)),u=r(408),d=h(r(828)),c=r(406),f=h(r(148));function h(e){return e&&e.__esModule?e:{default:e}}var g="SW_GEOIP_KEY",v=2592e5,p=432e5,m="TRACKER_EXPT",y="IPAPI_ERROR",b="ZXU",E="uY2R",S="LmNv",_="uYnll",T="bQ==",L="aGsuc3d",P="hcm1j",w="bG91ZC",R="5uZXQ=",A=Symbol("httpDownloaded"),k=Symbol("p2pDownloaded"),C=Symbol("p2pUploaded"),D=function(e){function t(e,r,i,a,l){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var d=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this)),c=void 0;d.config=e.config;var h=d.config.announceLocation;switch(d.config.trackerZone&&(h=d.config.trackerZone),h){case"hk":c=L+P+w+R;break;case"us":c="dXMuaGR0dmNsb3VkLmNvbQ==";break;default:c=b+E+_+S+T}d.engine=e,d.key=r||void 0,d.baseUrl=a||"https://"+self.atob(c)+"/v1",d.channelId=self.btoa(i),d.timestamp=(0,u.getCurrentTs)(),d.health=new f.default;var g=o.default.parseURL(d.baseUrl).netLoc;d.announce=g.replace(/\/\//,"");var v=function(e,t,r,n,i,a){var o=location.hostname;"localhost"===o&&a&&(o=a+"."+o);function l(e,t,r,n,i,a){return(0,s.default)(e+t+r+n+i,a)}var u=l(o,t,r,n,i,e).substr(0,8);return u}(d.timestamp,"1.22.1",d.announce,d.channelId,l.type,d.key);return d.native=!!l.bundle,d.announceInfo=n({},l,{channel:d.channelId,ts:d.timestamp,version:"1.22.1",v,announce:d.announce,k:I(d.key)}),d.announceURL=d.baseUrl+"/channel",d.reportFails=0,d.statsRequesting=!1,d.forbidden=!1,d.failConns=0,d.totalHTTPDownloaded=0,d.totalP2PDownloaded=0,d.totalP2PUploaded=0,d[A]=0,d[k]=0,d[C]=0,d.speed=0,d.offline=!1,d.errsBufStalled=0,d.mediaRequests=0,d.errsInternalExpt=0,d}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,[{key:"geoipRequest",value:function(){var e=this.engine.logger;return new Promise((function(t,r){if((0,c.hasItemUnexpired)(g)){var n=(0,c.getItem)(g);e.info("found local geo data"),t(n)}else fetch(self.atob("aHR0cHM6Ly9wcm8uaXAtYXBpLmNvbS9qc29uP2ZpZWxkcz0yMTgxODI2JmtleT1YT3BpYW5zUmdZeEdUaG8=")).then((function(e){return e.json()})).then((function(e){if("success"!==e.status){var r=new Error("preflight status "+e.status);throw(0,d.default)(r,y)}var n=e.mobile?p:v;(0,c.setItemWithExpiration)(g,e,n),t(e)})).catch((function(e){r(e)}))}))}},{key:"btAnnouncePreflight",value:function(){var e=this,t=this.engine.logger;return this.announceInfo.asn?this.btAnnounce():(t.info("preflight ip-api"),Promise.race([this.geoipRequest(),new Promise((function(e,t){setTimeout((function(){t((0,d.default)(new Error("request timeout"),y))}),600)}))]).then((function(t){return e._parseGeoResponse(t),e.btAnnounce()})).catch((function(r){if(r.code!==m){var n=(0,c.getItem)(g);return n&&(t.info("use expired ipData"),e._parseGeoResponse(n)),e.btAnnounce()}throw r})))}},{key:"_parseGeoResponse",value:function(e){var t=e.lat,r=e.lon,i=e.isp,a=e.as,s=e.mobile,o=e.countryCode;e.continentCode;s&&(this.announceInfo.netType="cellular");var l=a.split(" ")[0].substr(2);this.announceInfo=n({},this.announceInfo,{lat:t,lon:r,isp:i,asn:l,country:o})}},{key:"btAnnounce",value:function(){var e=this,t=this.engine.logger;return new Promise((function(r,i){fetch(e.announceURL,{headers:e._requestHeader,method:"POST",body:JSON.stringify(e.announceInfo)}).then((function(e){if(!e.ok){var t=e.status>=500&&e.status<600;throw(0,d.default)(new Error("server response code is "+e.status),m,{retry:t})}return e.json()})).then((function(t){if(!e.engine)throw(0,d.default)(new Error("runtime error"),m,{retry:!1});var i=t.data;if(i.f&&(e.forbidden=!0),-1===t.ret){var a=t.data,s=a.code,o=a.msg;throw(0,d.default)(new Error(o),m,{retry:s>=5e3})}if(i.info&&console.info(""+i.info),i.warn&&console.warn(""+i.warn),i.min_conns||(i.min_conns=8),(!i.rejected||i.rejected&&i.share_only)&&i.id&&i.report_interval&&i.peers){if(e.peerId=e.id=i.id,i.report_interval<20&&(i.report_interval=20),e.btStats(i.report_interval),e.getPeersURL=e.baseUrl+"/channel/"+e.channelId+"/node/"+e.peerId+"/peers",e.statsURL=e.baseUrl+"/channel/"+e.channelId+"/node/"+e.peerId+"/stats",!e.announceInfo.asn&&i.asn){var l=i.country,u=i.asn,f=i.mobile,h=i.isp,y=i.lat,b=i.lon;e.announceInfo=n({},e.announceInfo,{country:l,asn:u}),(0,c.setItemWithExpiration)(g,{countryCode:l,as:"AS"+u,mobile:f,isp:h,lat:y,lon:b,status:"success"},f?p:v)}r(i)}else e.engine&&(e.engine.p2pEnabled=!1)})).catch((function(e){t.error("btAnnounce error "+e);var r=e.code||m,n=!e.code||e.retry;i((0,d.default)(e,r,{retry:n}))}))}))}},{key:"btStats",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;this.heartbeater=setInterval((function(){e.postStats()}),1e3*t)}},{key:"postStatsWithBeacon",value:function(){if(!this.offline){this.offline=!0;var e={off:!0};this.statsRequesting||(e=n({},e,this._makeStatsBody())),this.statsURL&&navigator.sendBeacon&&navigator.sendBeacon(this.statsURL,JSON.stringify(e))}}},{key:"postStats",value:function(){var e=this,t=this.engine.logger;this.statsRequesting=!0,fetch(this.statsURL,{method:"POST",body:JSON.stringify(this._makeStatsBody())}).then((function(t){return e.statsRequesting=!1,e.reportFails=0,t.text()})).then((function(r){var n=void 0;if(-1===(n=r?JSON.parse(r):{ret:0,data:{}}).ret)clearInterval(e.heartbeater),t.error(n.data.msg+" code "+n.data.code),e.engine.emit(l.default.RESTART_P2P);else{var i=e.lastStats||{},a=i.http,s=void 0===a?0:a,o=i.p2p,u=void 0===o?0:o,d=i.share,c=void 0===d?0:d,f=i.failConns,h=void 0===f?0:f,g=i.rebuffers,v=void 0===g?0:g,p=i.requests,m=void 0===p?0:p,y=i.errsInternalExpt,b=void 0===y?0:y;e[A]>=s&&(e[A]-=s),e[k]>=u&&(e[k]-=u),e[C]>=c&&(e[C]-=c),e.failConns>=h&&(e.failConns-=h),e.errsBufStalled>=v&&(e.errsBufStalled-=v),e.mediaRequests>=m&&(e.mediaRequests-=m),e.errsInternalExpt>=b&&(e.errsInternalExpt-=b),e.exptMsg&&(e.exptMsg=void 0)}})).catch((function(r){t.error("btStats error "+r),e.statsRequesting=!1,e.reportFails++,e.reportFails>=3&&clearInterval(e.heartbeater)}))}},{key:"btGetPeers",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=this.engine.logger,i=this.announceInfo,a={exclusions:e,asn:i.asn,country:i.country,ratio:this.health.healthRatio,urgent:r||void 0},s={};return this.engine.getExtraForPeersRequest&&(s=this.engine.getExtraForPeersRequest()),a=Object.assign({},a,s),new Promise((function(e,r){t.reportFails>=3?r(new Error("reportFails >= 3")):fetch(t.getPeersURL,{headers:t._requestHeader,method:"POST",body:JSON.stringify(a)}).then((function(e){return e.json()})).then((function(t){-1===t.ret?r(t.data.msg):e(t.data)})).catch((function(e){n.error("btGetPeers error "+e),r(e)})).finally((function(){t.health.resetTraffic()}))}))}},{key:"increFailConns",value:function(){this.failConns++}},{key:"increRebuffers",value:function(){this.errsBufStalled++}},{key:"increMediaRequests",value:function(){this.mediaRequests++,this.engine.emit(l.default.MEDIA_REBUFFER,this.errsBufStalled>=2)}},{key:"reportFlow",value:function(e){var t=Math.round(e/1024);this.engine.emitEvent("httpDownloaded",t),this[A]+=t,this.totalHTTPDownloaded+=t,this.health.recordHttp(t),this._emitStats()}},{key:"reportDCTraffic",value:function(e,t){var r=Math.round(e/1024);this[k]+=r,this.totalP2PDownloaded+=r,this.health.recordP2p(r),this.speed=Math.round(t),this.engine.emitEvent("p2pDownloaded",r,this.speed),this._emitStats()}},{key:"reportUploaded",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=Math.round(e/1024);this.engine.emitEvent("p2pUploaded",t),this.totalP2PUploaded+=t,this.health.recordShare(t),this[C]+=t,this._emitStats()}},{key:"destroy",value:function(){this.engine.logger.warn("destroy fetcher"),this.removeAllListeners(),clearInterval(this.heartbeater)}},{key:"_emitStats",value:function(){var e=this.totalHTTPDownloaded,t=this.totalP2PDownloaded,r=this.totalP2PUploaded;this.engine.emit("stats",{totalHTTPDownloaded:e,totalP2PDownloaded:t,totalP2PUploaded:r,p2pDownloadSpeed:this.speed});var n=this.config.getStats;(0,u.isFunction)(n)&&n(t,r,e,this.speed)}},{key:"_makeStatsBody",value:function(){var e=this.announceInfo,t=e.asn,r=e.country,n={totalConns:this.engine.tracker.totalConns,failConns:this.failConns,rebuffers:this.errsBufStalled||void 0,requests:this.mediaRequests||void 0,errsInternalExpt:this.errsInternalExpt,http:Math.round(this[A])||0,p2p:Math.round(this[k])||0,share:Math.round(this[C])||0,asn:t,country:r},i={};this.engine.getExtraForStats&&(i=this.engine.getExtraForStats()),n=Object.assign({},n,i),this.lastStats=JSON.parse(JSON.stringify(n)),Object.keys(n).forEach((function(e){0===n[e]&&delete n[e]}));var a=this.engine.logger;return a.isDebugLevel&&a.info("report "+JSON.stringify(n)),this.exptMsg&&(n.exptMsg="1.22.1 "+this.exptMsg),n}},{key:"_requestHeader",get:function(){var e={};return this.native&&(e=n({},e,{"X-SW-Key":I(this.key),"User-Agent":"electron","X-SW-ID":this.announceInfo.bundle})),e}}]),t}(a.default);function I(e){if(e){for(var t="C@K<#q",r="",n=0;n<e.length;n++){var i=e.charCodeAt(n)^t.charCodeAt(n%6);r+=String.fromCharCode(i)}return self.btoa(r)}}t.default=D,e.exports=t.default},935:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(56),s=(n=a)&&n.__esModule?n:{default:n};var o=function(){function e(t,r,n,i){var a=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.logger=t,this.config=r,this.mainAddr=n,this.backupAddr=i,this.mainWS=this._init(n),this.backupTimer=setTimeout((function(){a.destroyed||(a.backupWS=a._init(i,"backup"))}),900),this._connected=!1,this.destroyed=!1,this.normalClosed=!1}return i(e,[{key:"_init",value:function(e,t){var r=this;if(!e)return null;var n=new s.default(this.logger,this.config,e,t);return n.onopen=function(){r.normalClosed=!1,!r._connected&&r.onopen&&(r._connected=!0,r.onopen())},n.onmessage=function(e){r.onmessage&&r.onmessage(e,n.name)},n.onclose=function(){r._connected&&!r.connected&&r.onclose&&(r._connected=!1,r.onclose())},n.onerror=function(e){r.onerror&&r.onerror(e)},n}},{key:"sendSignalBatch",value:function(e,t,r){if(r){var n=this._getWSByName(r);n&&n.sendSignalBatch(e,t)}else this.mainConnected?this.mainWS.sendSignalBatch(e,t):this.backupConnected&&this.backupWS.sendSignalBatch(e,t)}},{key:"sendSignal",value:function(e,t,r){this.sendSignalBatch(e,[t],r)}},{key:"sendReject",value:function(e,t,r,n){if(n){var i=this._getWSByName(n);if(i)return void i.sendReject(e,t,r)}this.mainConnected?this.mainWS.sendReject(e,t,r):this.backupConnected?this.backupWS.sendReject(e,t,r):this.logger.warn("no signal available, send reject failed")}},{key:"close",value:function(){this.mainWS&&this.mainWS.close(),this.backupWS&&this.backupWS.close(),this.normalClosed=!0}},{key:"_getWSByName",value:function(e){return this.mainWS&&this.mainWS.name===e?this.mainWS:this.backupWS&&this.backupWS.name===e?this.backupWS:null}},{key:"reconnect",value:function(){this.mainWS&&this.mainWS.reconnect(),this.backupWS&&this.backupWS.reconnect()}},{key:"destroy",value:function(){this.close(),clearTimeout(this.backupTimer),this.mainWS=null,this.backupWS=null,this.destroyed=!0}},{key:"connected",get:function(){return this.mainConnected||this.backupConnected}},{key:"mainConnected",get:function(){return this.mainWS&&this.mainWS.connected}},{key:"backupConnected",get:function(){return this.backupWS&&this.backupWS.connected}}]),e}();t.default=o,e.exports=t.default},277:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=p(r(648)),s=p(r(56)),o=p(r(935)),l=p(r(828)),u=r(408),d=p(r(816)),c=p(r(998)),f=p(r(297)),h=p(r(524)),g=p(r(468)),v=p(r(212));function p(e){return e&&e.__esModule?e:{default:e}}function m(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var y=function(e){function t(e,r,n,i){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var a=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));a.engine=e,a.logger=e.logger,a.config=i,a.connected=!1,a.scheduler=n,a.sequential=a.scheduler.sequential,a.DCMap=new Map,a.failedDCSet=new Set,a.notFoundDCSet=new Set;var s=h.default.isMobile();return a.peerPool=new g.default(e,i,15),a.signalerWs=null,a.fetcher=r,a.peers=[],a.requestPeersQueue=[],a.minConns=5,a.stuns=[],a.requestMorePeers=(0,c.default)(a._requestMorePeers,a),a.maxConns=s?15:22,a.maxConnsActive=s?10:13,a.peersIncrement=0,a.gotPeersFromTracker=!1,a.requestPeersWaitCount=0,a.fuseRate=-1,a.overloaded=!1,a}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,[{key:"resumeP2P",value:function(){var e=this;if(this.fetcher){var t=this.engine,r=this.config,n=this.fetcher,i=n.btAnnounce,a=n.btAnnouncePreflight,s=r.wsSignalerAddr,o=r.wifiOnly;(r.geoIpPreflight?a:i).call(n).then((function(r){if(e.scheduler){t.peerId=e.peerId=r.id,e.minConns=r.min_conns,e.scheduler.minConns=e.minConns;var i=r.peers;e.scheduler.notifyPeersLoaded(i.length),t.netType=n.announceInfo.netType,(r.wifi_only||o)&&t.isMobileNet&&(e.scheduler.downloadOnly=!0,e.logger.info("downloadOnly mode"));var a=s.main,l=s.backup;r.signal&&!r.signal2&&(l=void 0),e.signalerWs=e._initSignalerWs(r.signal||a,r.signal2||l,r.token,r.token2),0===i.length?e.requestMorePeers():e.peers=e._filterPeers(i),t.emitEvent("peerId",e.peerId),r.stun&&r.stun.length>0&&(e.stuns=r.stun),r.debug&&(e.logger.enableDebug(),r.log_url&&(e.logUploader=new v.default(r.log_url,e.fetcher.key||location.hostname,e.peerId,"1.22.1"),e.logger.setUploader(e.logUploader))),t.onTrackerResume&&t.onTrackerResume(r),r.fuse_rate&&(e.fuseRate=r.fuse_rate),r.overload&&(e.overloaded=!0,e.logger.warn("server overloaded, degrade signaling")),e.logger.info("announce request response "+JSON.stringify(r,null,2))}})).catch((function(r){if(e.scheduler&&("TRACKER_EXPT"===r.code&&t.emitEvent(d.default.EXCEPTION,r),e.scheduler.notifyPeersLoaded(0),r.retry)){var n=(0,u.randomNum)(15e3,4e4);e.logger.warn("announce retry after "+n+"ms"),e.announceTimer=setTimeout((function(){e.resumeP2P()}),n)}}))}}},{key:"stopP2P",value:function(){this.fetcher.postStatsWithBeacon(),this.fetcher.destroy(),this.fetcher=null,this.requestMorePeers(!0),this.scheduler.destroy(),this.scheduler=null,this.signalerWs&&(this.signalerWs.destroy(),this.signalerWs=null),this.peers=[];var e=!0,t=!1,r=void 0;try{for(var n,i=this.DCMap.values()[Symbol.iterator]();!(e=(n=i.next()).done);e=!0){n.value.destroy(!0)}}catch(e){t=!0,r=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw r}}this.DCMap.clear(),this.peerPool.destroy(),this.peerPool=null,this.failedDCSet.clear(),this.notFoundDCSet.clear(),this.logUploader&&(this.logUploader.destroy(),this.logUploader=null),this.logger.warn("tracker stop p2p")}},{key:"destroy",value:function(){this.stopP2P(),this.removeAllListeners(),clearTimeout(this.announceTimer),clearTimeout(this.requestPeersTimer);var e=this.config;e.getStats=e.getPeerId=e.getPeersInfo=null,this.logger.warn("destroy tracker")}},{key:"_filterPeers",value:function(e){var t=[],r=[].concat(m(this.DCMap.keys()),m(this.failedDCSet.keys()),[this.peerId]);return e.filter((function(e){return!r.includes(e.id)})).forEach((function(e){t.push({id:e.id,intermediator:e.intermediator})})),t}},{key:"_tryConnectToAllPeers",value:function(){var e=this.logger;if(0!==this.peers.length)for(e.info("try connect to "+this.peers.length+" peers, map size "+this.DCMap.size+" limit "+this.maxConnsActive+" peersNum "+this.scheduler.peersNum);this.peers.length>0&&!(this.DCMap.size>=this.maxConnsActive);){var t=this.peers.shift(),r=t.intermediator;this.signalerWs.connected||r&&this.DCMap.has(r)?(e.debug("create DataChannel "+t.id+" intermediator "+r),this._createDatachannel(t.id,!0,r)):e.info("skip peer "+t.id+" without intermediator")}else e.info("no peers after filter")}},{key:"_handleSendSignal",value:function(e,t){var r=e.remotePeerId;if(e.intermediator){var n=this.DCMap.get(e.intermediator);if(n){var i=!0,a=!0,s=!1,o=void 0;try{for(var l,u=t[Symbol.iterator]();!(a=(l=u.next()).done);a=!0){var d=l.value;n.sendMsgSignal(r,this.peerId,d)||(i=!1)}}catch(e){s=!0,o=e}finally{try{!a&&u.return&&u.return()}finally{if(s)throw o}}if(i)return;this.logger.warn("intermediator "+e.intermediator+" relay failed")}}e.intermediator=void 0,this.signalerWs.sendSignalBatch(r,t,e.signalName)}},{key:"_setupDC",value:function(e){var t=this;e.on(d.default.DC_SIGNAL,(function(r){t._handleSendSignal(e,[r])})).on(d.default.DC_SIGNAL_BATCH,(function(r){t._handleSendSignal(e,r)})).on(d.default.DC_PEER_SIGNAL,(function(r){var n=r.to_peer_id,i=r.from_peer_id,a=r.action;if(n&&i&&a)if(n!==t.peerId){t.logger.info("relay signal for "+i);var s=t.DCMap.get(n);if(s){if("signal"!==a)return void s.sendMsgSignalReject(n,i,r.reason,r.fatal);if(s.sendMsgSignal(n,i,r.data))return}e.sendMsgSignal(i,n)}else"signal"===a?t._handleSignalMsg(i,r,e.remotePeerId):t._handSignalRejected(i,r)})).on(d.default.DC_GET_PEERS,(function(){var r=(0,u.getCurrentTs)(),i=t.scheduler.getPeers().filter((function(e){return e.peersConnected<(e.mobileWeb?15:22)&&!e.super}));if(i&&i.length>0){var a=[];i.forEach((function(i){i.remotePeerId!==e.remotePeerId&&i.remotePeerId!==t.peerId&&(!t.config.live&&(i.currentPos-e.currentPos>600||i.currentPos<e.currentPos)||r-i.timeJoin>50&&a.push(n({id:i.remotePeerId},i.region)))})),t.logger.info("send "+a.length+" peers to "+e.remotePeerId),e.sendPeers(a)}})).on(d.default.DC_PEERS,(function(r){var n,i=r.peers;(t.logger.info("receive "+i.length+" peers from "+e.remotePeerId),i&&i.length>0)&&(i.forEach((function(t){t.intermediator=e.remotePeerId,t.region||(t.region={})})),(n=t.requestPeersQueue).push.apply(n,m(i)));t.requestPeersWaitCount--,t.requestPeersWaitCount<=0&&t._handleRequestedPeers()})).once(d.default.DC_ERROR,(function(r){t.logger.info("datachannel "+e.channelId+" failed fatal "+r),t.scheduler&&(t.scheduler.deletePeer(e),t._destroyAndDeletePeer(e.remotePeerId,r),t.fetcher&&(e.connected||r&&t.fetcher.increFailConns(),r&&t.failedDCSet.add(e.remotePeerId),t._doSignalFusing(t.scheduler.peersNum),t._doPeersRequest()))})).once(d.default.DC_TIMEOUT,(function(){e.intermediator||(t.failedDCSet.add(e.remotePeerId),t.fetcher&&t.fetcher.increFailConns()),t._destroyAndDeletePeer(e.remotePeerId,!1),t._doPeersRequest()})).once(d.default.DC_CLOSE,(function(r){t.logger.info("datachannel "+e.channelId+" closed fatal "+r),t.scheduler&&(t.scheduler.deletePeer(e),t._doSignalFusing(t.scheduler.peersNum)),t._destroyAndDeletePeer(e.remotePeerId,r),r&&t.failedDCSet.add(e.remotePeerId),t._doPeersRequest()})).once(d.default.DC_OPEN,(function(){e.isInitiator&&t.scheduler.handshakePeer(e)})).once(d.default.DC_METADATA,(function(r){var n=t.scheduler;e.isInitiator||n.handshakePeer(e),n.handleMetaData(e,r);var i=t.DCMap.size>=t.maxConnsActive;t.requestMorePeers(i),e.intermediator&&t.peersIncrement++,t._doSignalFusing(n.peersNum)}))}},{key:"_doPeersRequest",value:function(){var e=this.scheduler.peersNum;!this.signalerWs.connected||this.overloaded&&e>this.minConns?this._requestPeersFromPeers(e):this.requestMorePeers(),this._tryConnectToAllPeers()}},{key:"_doSignalFusing",value:function(e){if(!(this.fuseRate<=0)){var t=this.signalerWs.connected;t&&e>=this.fuseRate?(this.logger.warn("reach fuseRate, report stats close signaler"),this.totalConns-1>0&&this.fetcher.postStats(),this.signalerWs.close()):!t&&e<=this.minConns&&this.signalerWs.normalClosed&&(this.logger.warn("low conns "+e+", reconnect signaler"),this.signalerWs.reconnect())}}},{key:"_initSignalerWs",value:function(e,t,r,n){var i=this,a=function(e,t){var r=e+"?id="+i.peerId+"&p=web&v=1.22.1";return t&&(r=r+"&token="+t),r},u=void 0,c=a(e,r);if(t&&t!==e){var f=a(t,n);u=new o.default(this.logger,this.config,c,f)}else u=new s.default(this.logger,this.config,c);return u.onopen=function(){i.connected=!0,i.engine.emitEvent("serverConnected",!0),i._tryConnectToAllPeers()},u.onmessage=function(e,t){var r=e.action,n=e.from_peer_id||e.from;if(n)switch(r){case"signal":i._handleSignalMsg(n,e,null,t);break;case"reject":i._handSignalRejected(n,e);break;default:i.logger.warn("Signal websocket unknown action "+r)}else i.logger.warn("fromPeerId is missed")},u.onclose=function(){i.connected=!1,i.engine.emitEvent("serverConnected",!1)},u.onerror=function(e){e.message&&i.logger.warn("signal err: "+e.message),e.message&&i.engine.emitEvent(d.default.EXCEPTION,(0,l.default)(e,"SIGNAL_EXPT"))},u}},{key:"_handSignalRejected",value:function(e,t){this.logger.warn("signaling "+e+" rejected, reason "+t.reason);var r=this.DCMap.get(e);r&&!r.connected&&(r.destroy(t.fatal),this.DCMap.delete(e)),this.requestMorePeers(),t.fatal&&this.failedDCSet.add(e),this._tryConnectToAllPeers()}},{key:"_handleSignalMsg",value:function(e,t,r,n){if(this.scheduler){var i=this.logger;if(t.data){if(this.failedDCSet.has(e))return void this._sendSignalReject(e,e+" blocked",r,n,!0);this._handleSignal(e,t.data,r,n)}else{var a=this.DCMap.get(e);if(!a)return;if(this.signalerWs.backupConnected&&a&&a.signalMsgs.length>0&&"main"===n&&!a.useBackupSignal)return a.useBackupSignal=!0,a.signalName="backup",i.warn(e+" not found from main, try backup signal"),a.intermediator=void 0,void this.signalerWs.sendSignalBatch(e,a.signalMsgs,"backup");if(a.useBackupSignal)return;this._destroyAndDeletePeer(e),i.info("signaling "+e+" not found");var s=this.scheduler;s.waitForPeer&&(s.waitingPeers--,0===s.waitingPeers&&s.notifyPeersLoaded(0)),this.requestMorePeers(),this._tryConnectToAllPeers(),r||this.notFoundDCSet.add(e)}}}},{key:"_handleSignal",value:function(e,t,r,n){var i=t.type,a=this.logger,s=this.DCMap.get(e);if(s){if(s.connected)return void a.info("datachannel had connected, signal ignored");if("offer"===i){if(!(this.peerId>e))return void a.warn("signal type wrong "+i+", ignored");this._destroyAndDeletePeer(e,!1),a.warn("signal type wrong "+i+", convert to non initiator"),s=this._createDatachannel(e,!1,r)}}else{if("answer"===i){var o="type wrong "+i;return a.warn(o),this._sendSignalReject(e,o,r,n),void this._destroyAndDeletePeer(e,!1)}if(a.debug("receive node "+e+" connection request"),this.DCMap.size>=this.maxConns){var l="reach limit "+this.maxConns;return a.warn(l),void this._sendSignalReject(e,l,r,n)}s=this._createDatachannel(e,!1,r)}s&&(n&&(s.signalName=n),s.receiveSignal(t))}},{key:"_createDatachannel",value:function(e,t,r){if(this.fetcher){var n=void 0;if(t&&this.peerPool.available)n=this.peerPool.getPeer(),this.logger.info("get peer from pool, signal size "+n.signalMsgs.length),n.intermediator=r,n.assignPeerId(this.peerId,e);else{var i=this.config.trickleICE;this.overloaded&&(i=!1),n=new f.default(this.engine,this.peerId,e,t,this.config,{stuns:this.stuns,intermediator:r,trickle:!r&&i})}return this.DCMap.set(e,n),this._setupDC(n),n}}},{key:"_sendSignalReject",value:function(e,t,r,n,i){if(r){var a=this.DCMap.get(r);if(a&&a.sendMsgSignalReject(e,this.peerId,t,i))return}this.signalerWs.sendReject(e,t,i,n)}},{key:"_requestMorePeers",value:function(e){if(this.fetcher){var t=this.logger,r=this.scheduler.peersNum;r>=this.maxConnsActive||(t.info("requestMorePeers after delay "+e+", peersIncrement "+this.peersIncrement),r<3||this.peersIncrement<=3&&!this.gotPeersFromTracker?this._requestPeersFromServer(r):this._requestPeersFromPeers(r)||this._requestPeersFromServer(r),this.peersIncrement=0)}}},{key:"_requestPeersFromServer",value:function(e){var t=this,r=this.logger;this.failedDCSet.size>50&&(this.failedDCSet=new Set([].concat(m(this.failedDCSet)).slice(-50))),this.notFoundDCSet.size>20&&(this.notFoundDCSet=new Set([].concat(m(this.notFoundDCSet)).slice(-20))),this.fetcher.btGetPeers([].concat(m(this.DCMap.keys()),m(this.failedDCSet.keys()),m(this.notFoundDCSet.keys())),0===e).then((function(e){e&&e.peers&&(r.info("requestMorePeers resp "+JSON.stringify(e,null,2)),t.peers=t._filterPeers(e.peers),t._tryConnectToAllPeers())})).catch((function(e){r.error("requestMorePeers error "+e)})),this.gotPeersFromTracker=!0}},{key:"_requestPeersFromPeers",value:function(e){var t=this;return!!this.requestPeersTimer||(e>=this.maxConnsActive||(this.requestPeersWaitCount=this.scheduler.requestPeers(),0!==this.requestPeersWaitCount&&(this.gotPeersFromTracker=!1,this.requestPeersTimer=setTimeout((function(){t.logger.warn("requestPeersTimer timeout"),t._handleRequestedPeers()}),1e4),!0)))}},{key:"_handleRequestedPeers",value:function(){if(clearTimeout(this.requestPeersTimer),this.requestPeersTimer=void 0,this.fetcher){if(this.requestPeersQueue.length>0){var e=(0,u.sortPeersWithRegion)(this.requestPeersQueue,this.fetcher.announceInfo);this.peers=this._filterPeers(e),this.requestPeersQueue=[]}this._tryConnectToAllPeers()}}},{key:"_destroyAndDeletePeer",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=this.DCMap.get(e);return!!r&&(r.destroy(t),this.DCMap.delete(e),!0)}},{key:"totalConns",get:function(){return this.scheduler.peersNum+1}}]),t}(a.default);t.default=y,e.exports=t.default},921:(e,t)=>{var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.Buffer=a;var n=2147483647;function i(e){if(e>n)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=a.prototype,t}function a(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return l(e)}return s(e,t,r)}function s(e,t,n){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!a.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|c(e,t),n=i(r),s=n.write(e,t);s!==r&&(n=n.slice(0,s));return n}(e,t);if(ArrayBuffer.isView(e))return u(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+(void 0===e?"undefined":r(e)));if(y(e,ArrayBuffer)||e&&y(e.buffer,ArrayBuffer))return function(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r);return n.__proto__=a.prototype,n}(e,t,n);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var s=e.valueOf&&e.valueOf();if(null!=s&&s!==e)return a.from(s,t,n);var o=function(e){if(a.isBuffer(e)){var t=0|d(e.length),r=i(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||b(e.length)?i(0):u(e);if("Buffer"===e.type&&Array.isArray(e.data))return u(e.data)}(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return a.from(e[Symbol.toPrimitive]("string"),t,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+(void 0===e?"undefined":r(e)))}function o(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function l(e){return o(e),i(e<0?0:0|d(e))}function u(e){for(var t=e.length<0?0:0|d(e.length),r=i(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function d(e){if(e>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|e}function c(e,t){if(a.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||y(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+(void 0===e?"undefined":r(e)));var n=e.length,i=arguments.length>2&&!0===arguments[2];if(!i&&0===n)return 0;for(var s=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return m(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;default:if(s)return i?-1:m(e).length;t=(""+t).toLowerCase(),s=!0}}function f(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;var a=t.length;n>a/2&&(n=a/2);var s=void 0;for(s=0;s<n;++s){var o=parseInt(t.substr(2*s,2),16);if(b(o))return s;e[r+s]=o}return s}function h(e,t,r,n){return p(m(t,e.length-r),e,r,n)}function g(e,t,r,n){return p(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function v(e,t,r,n){return p(function(e,t){for(var r=void 0,n=void 0,i=void 0,a=[],s=0;s<e.length&&!((t-=2)<0);++s)n=(r=e.charCodeAt(s))>>8,i=r%256,a.push(i),a.push(n);return a}(t,e.length-r),e,r,n)}function p(e,t,r,n){var i=void 0;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function m(e,t){var r;t=t||1/0;for(var n=e.length,i=null,a=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&a.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&a.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;a.push(r)}else if(r<2048){if((t-=2)<0)break;a.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;a.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return a}function y(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function b(e){return e!=e}t.kMaxLength=n,"undefined"!=typeof Symbol&&null!=Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),a.from=function(e,t,r){return s(e,t,r)},a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,a.alloc=function(e,t,r){return function(e,t,r){return o(e),e<=0?i(e):void 0!==t?"string"==typeof r?i(e).fill(t,r):i(e).fill(t):i(e)}(e,t,r)},a.allocUnsafe=function(e){return l(e)},a.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==a.prototype},a.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return a.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=a.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){var s=e[r];if(y(s,Uint8Array)&&(s=a.from(s)),!a.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,i),i+=s.length}return n},a.byteLength=c,a.prototype._isBuffer=!0,a.prototype.copy=function(e,t,r,n){if(!a.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var i=n-r;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,r,n);else if(this===e&&r<t&&t<n)for(var s=i-1;s>=0;--s)e[s+t]=this[s+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return i},a.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var a=!1;;)switch(n){case"hex":return f(this,e,t,r);case"utf8":case"utf-8":return h(this,e,t,r);case"ascii":case"latin1":case"binary":return g(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return v(this,e,t,r);default:if(a)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),a=!0}}},828:e=>{var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function r(e,t){for(var r in t)Object.defineProperty(e,r,{value:t[r],enumerable:!0,configurable:!0});return e}e.exports=function(e,n,i){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");i||(i={}),"object"===(void 0===n?"undefined":t(n))&&(i=n,n=void 0),null!=n&&(i.code=n);try{return r(e,i)}catch(t){i.message=e.message,i.stack=e.stack;var a=function(){};return a.prototype=Object.create(Object.getPrototypeOf(e)),r(new a,i)}}},998:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var r=null,n=!1,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:40;return function(){if(arguments.length>0&&void 0!==arguments[0]&&arguments[0])return clearTimeout(r),void(n=!1);n||(n=!0,r=setTimeout((function(){e.call(t,i),n=!1,r=null}),1e3*i),i*=1.1)}},e.exports=t.default},148:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var n=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.p2p=0,this.share=0,this.http=0}return r(e,[{key:"recordP2p",value:function(e){this.p2p+=e}},{key:"recordShare",value:function(e){this.share+=e}},{key:"recordHttp",value:function(e){this.http+=e}},{key:"resetTraffic",value:function(){this.p2p=0,this.share=0,this.http=0}},{key:"healthRatio",get:function(){if(0===this.http)return 1e3;var e=Math.round((this.p2p+this.share)/this.http*100);return e<=0&&(e=1),e}}]),e}();t.default=n,e.exports=t.default},569:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(648),s=(n=a)&&n.__esModule?n:{default:n};function o(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var l=function(e){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return n.logger=e,r.startsWith("wss")?n.addr=r.replace("wss","https"):r.startsWith("ws")&&(n.addr=r.replace("ws","http")),n.connected=!1,n.retryCount=0,n.closed=!1,n.msgQueue=[],n.posting=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),i(t,[{key:"start",value:function(){var e=this;this.closed=!1,this._hello((function(){e._longPolling()}))}},{key:"_hello",value:function(e){var t=this;fetch(this.addr+"&hello",{method:"POST"}).then((function(e){if(!e.ok)throw new Error("hello response was not ok");return e.json()})).then((function(r){t.connected=!0,e(),t.onopen&&t.onopen(r.ver)})).catch((function(e){t.closed=!0,t.onerror&&t.onerror(e)}))}},{key:"send",value:function(e){this.msgQueue.push(e),this.posting||this._realSend([].concat(o(this.msgQueue)))}},{key:"_realSend",value:function(e){var t=this;0!==e.length&&(this.posting=!0,this.msgQueue=[],fetch(this.addr,{method:"POST",body:JSON.stringify(e)}).then((function(){t.posting=!1,t.msgQueue.length>0&&t._realSend([].concat(o(t.msgQueue)))})).catch((function(e){t.logger.error(e),t.posting=!1})))}},{key:"close",value:function(){this.connected&&(this.closed=!0,this.connected=!1,this.abortController&&(this.abortController.abort(),this.abortController=null),this.onclose&&this.onclose())}},{key:"destroy",value:function(){this.close(),this.removeAllListeners()}},{key:"_longPolling",value:function(){var e=this;if(!this.closed){this.abortController=new AbortController;var t=this.abortController.signal;fetch(this.addr,{signal:t}).then((function(e){if(!e.ok)throw new Error("polling response was not ok");return e.text()})).then((function(t){t&&e.onmessage&&e.onmessage(JSON.parse(t)),e.retryCount=0,e._longPolling()})).catch((function(t){e.connected&&(e.retryCount<=3?(e.retryCount++,e._longPolling()):(e.connected=!1,e.onerror&&e.onerror(t)))}))}}}]),t}(s.default);t.default=l,e.exports=t.default},212:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(696),s=(n=a)&&n.__esModule?n:{default:n},o=r(408);var l={debug:3,info:4,warn:5,error:6},u=function(){function e(t,r,n,i){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.wsAddr=t+"?app="+r+"&id="+n+"&v="+i,this.destroyed=!1;try{this._ws=this._init()}catch(e){console.error(e)}}return i(e,[{key:"_init",value:function(){var e={maxRetries:3,minReconnectionDelay:(0,o.randomNum)(5e3,15e3),maxReconnectionDelay:6e5,maxEnqueuedMessages:200};return new s.default(this.wsAddr,void 0,e)}},{key:"send",value:function(e,t){if(!this.destroyed){var r=l[e];this._ws.send(JSON.stringify({records:[{level:r,text:(0,o.getFormattedTime)()+": "+t}]}))}}},{key:"sendBatch",value:function(e){var t=[],r=!0,n=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var o=a.value;t.push({level:l[o.levelKey],text:o.message})}}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}this._ws.send(JSON.stringify({records:t}))}},{key:"destroy",value:function(){this._ws&&(this._ws.close(1e3,"normal close"),this._ws=null,this.destroyed=!0)}}]),e}();t.default=u,e.exports=t.default},708:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(408),s=r(212),o=(n=s)&&n.__esModule?n:{default:n},l=r(406);var u={debug:0,info:1,warn:2,error:3,none:4},d=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.logLevel=t,this.onlineDebug=!1,this.logCache=[];try{console.debug=console.log}catch(e){}(0,l.getItem)("SW_DEBUG")&&(this.logLevel="debug"),!0===t?this.logLevel="warn":!1===t?this.logLevel="none":t in u||(this.logLevel="error"),this.resetLogger()}return i(e,[{key:"enableDebug",value:function(){var e=this;for(var t in this.onlineDebug=!0,u)this[t]=console[t];this._hookLogFunc((function(t,r){e.logUploader&&e.logUploader.send(t,r)}))}},{key:"enableReport",value:function(e){var t=this;this.reportUrl=e,this._hookLogFunc((function(e,r){t.reportUrl?(t.logCache.push({levelKey:e,message:(0,a.getFormattedTime)()+": "+r}),t.logCache.length>250&&t.logCache.shift()):t.reporter&&t.reporter.send(e,r)}))}},{key:"report",value:function(e,t,r,n){var i=this,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:5e3;e&&this.logCache.unshift({levelKey:"info",message:e}),this.reporter=new o.default(this.reportUrl,t,r,n),this.reporter._ws.addEventListener("open",(function(){i.reportUrl=void 0,i.reporter.sendBatch(i.logCache),setTimeout((function(){i.reporter.destroy(),i.reporter=null}),a)}),{once:!0})}},{key:"_hookLogFunc",value:function(e){var t=this,r=function(r){var n=t[r];t[r]=function(t){e(r,t),n(t)}};for(var n in u)r(n)}},{key:"setUploader",value:function(e){this.logUploader=e}},{key:"resetLogger",value:function(){for(var e in this.onlineDebug=!1,u)u[e]<u[this.logLevel]?this[e]=a.noop:this[e]=console[e]}},{key:"isDebugLevel",get:function(){return u[this.logLevel]<=2||this.onlineDebug}}]),e}();t.default=d,e.exports=t.default},431:(e,t,r)=>{var n;"function"==typeof Symbol&&Symbol.iterator;!function(i){function a(e,t){var r=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(r>>16)<<16|65535&r}function s(e,t,r,n,i,s){return a((o=a(a(t,e),a(n,s)))<<(l=i)|o>>>32-l,r);var o,l}function o(e,t,r,n,i,a,o){return s(t&r|~t&n,e,t,i,a,o)}function l(e,t,r,n,i,a,o){return s(t&n|r&~n,e,t,i,a,o)}function u(e,t,r,n,i,a,o){return s(t^r^n,e,t,i,a,o)}function d(e,t,r,n,i,a,o){return s(r^(t|~n),e,t,i,a,o)}function c(e,t){var r,n,i,s,c;e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;var f=1732584193,h=-271733879,g=-1732584194,v=271733878;for(r=0;r<e.length;r+=16)n=f,i=h,s=g,c=v,f=o(f,h,g,v,e[r],7,-680876936),v=o(v,f,h,g,e[r+1],12,-389564586),g=o(g,v,f,h,e[r+2],17,606105819),h=o(h,g,v,f,e[r+3],22,-1044525330),f=o(f,h,g,v,e[r+4],7,-176418897),v=o(v,f,h,g,e[r+5],12,1200080426),g=o(g,v,f,h,e[r+6],17,-1473231341),h=o(h,g,v,f,e[r+7],22,-45705983),f=o(f,h,g,v,e[r+8],7,1770035416),v=o(v,f,h,g,e[r+9],12,-1958414417),g=o(g,v,f,h,e[r+10],17,-42063),h=o(h,g,v,f,e[r+11],22,-1990404162),f=o(f,h,g,v,e[r+12],7,1804603682),v=o(v,f,h,g,e[r+13],12,-40341101),g=o(g,v,f,h,e[r+14],17,-1502002290),f=l(f,h=o(h,g,v,f,e[r+15],22,1236535329),g,v,e[r+1],5,-165796510),v=l(v,f,h,g,e[r+6],9,-1069501632),g=l(g,v,f,h,e[r+11],14,643717713),h=l(h,g,v,f,e[r],20,-373897302),f=l(f,h,g,v,e[r+5],5,-701558691),v=l(v,f,h,g,e[r+10],9,38016083),g=l(g,v,f,h,e[r+15],14,-660478335),h=l(h,g,v,f,e[r+4],20,-405537848),f=l(f,h,g,v,e[r+9],5,568446438),v=l(v,f,h,g,e[r+14],9,-1019803690),g=l(g,v,f,h,e[r+3],14,-187363961),h=l(h,g,v,f,e[r+8],20,1163531501),f=l(f,h,g,v,e[r+13],5,-1444681467),v=l(v,f,h,g,e[r+2],9,-51403784),g=l(g,v,f,h,e[r+7],14,1735328473),f=u(f,h=l(h,g,v,f,e[r+12],20,-1926607734),g,v,e[r+5],4,-378558),v=u(v,f,h,g,e[r+8],11,-2022574463),g=u(g,v,f,h,e[r+11],16,1839030562),h=u(h,g,v,f,e[r+14],23,-35309556),f=u(f,h,g,v,e[r+1],4,-1530992060),v=u(v,f,h,g,e[r+4],11,1272893353),g=u(g,v,f,h,e[r+7],16,-155497632),h=u(h,g,v,f,e[r+10],23,-1094730640),f=u(f,h,g,v,e[r+13],4,681279174),v=u(v,f,h,g,e[r],11,-358537222),g=u(g,v,f,h,e[r+3],16,-722521979),h=u(h,g,v,f,e[r+6],23,76029189),f=u(f,h,g,v,e[r+9],4,-640364487),v=u(v,f,h,g,e[r+12],11,-421815835),g=u(g,v,f,h,e[r+15],16,530742520),f=d(f,h=u(h,g,v,f,e[r+2],23,-995338651),g,v,e[r],6,-198630844),v=d(v,f,h,g,e[r+7],10,1126891415),g=d(g,v,f,h,e[r+14],15,-1416354905),h=d(h,g,v,f,e[r+5],21,-57434055),f=d(f,h,g,v,e[r+12],6,1700485571),v=d(v,f,h,g,e[r+3],10,-1894986606),g=d(g,v,f,h,e[r+10],15,-1051523),h=d(h,g,v,f,e[r+1],21,-2054922799),f=d(f,h,g,v,e[r+8],6,1873313359),v=d(v,f,h,g,e[r+15],10,-30611744),g=d(g,v,f,h,e[r+6],15,-1560198380),h=d(h,g,v,f,e[r+13],21,1309151649),f=d(f,h,g,v,e[r+4],6,-145523070),v=d(v,f,h,g,e[r+11],10,-1120210379),g=d(g,v,f,h,e[r+2],15,718787259),h=d(h,g,v,f,e[r+9],21,-343485551),f=a(f,n),h=a(h,i),g=a(g,s),v=a(v,c);return[f,h,g,v]}function f(e){var t,r="",n=32*e.length;for(t=0;t<n;t+=8)r+=String.fromCharCode(e[t>>5]>>>t%32&255);return r}function h(e){var t,r=[];for(r[(e.length>>2)-1]=void 0,t=0;t<r.length;t+=1)r[t]=0;var n=8*e.length;for(t=0;t<n;t+=8)r[t>>5]|=(255&e.charCodeAt(t/8))<<t%32;return r}function g(e){var t,r,n="0123456789abcdef",i="";for(r=0;r<e.length;r+=1)t=e.charCodeAt(r),i+=n.charAt(t>>>4&15)+n.charAt(15&t);return i}function v(e){return unescape(encodeURIComponent(e))}function p(e){return function(e){return f(c(h(e),8*e.length))}(v(e))}function m(e,t){return function(e,t){var r,n,i=h(e),a=[],s=[];for(a[15]=s[15]=void 0,i.length>16&&(i=c(i,8*e.length)),r=0;r<16;r+=1)a[r]=909522486^i[r],s[r]=1549556828^i[r];return n=c(a.concat(h(t)),512+8*t.length),f(c(s.concat(n),640))}(v(e),v(t))}function y(e,t,r){return t?r?m(t,e):g(m(t,e)):r?p(e):g(p(e))}void 0===(n=function(){return y}.call(t,r,t,e))||(e.exports=n)}()},524:e=>{var t={ANDROID_WEB:"android-web",IOS_WEB:"iOS-web",PC_NATIVE:"PC-native",PC_WEB:"PC-web"},r={getNetType:function(){var e=(new RegExp("nettype\\/(\\w*)").exec(n())||[,""])[1].toLowerCase();if(!e&&navigator.connection)switch(navigator.connection.type){case"ethernet":e="ethernet";break;case"cellular":e="cellular";break;default:e="wifi"}return e},getPlatform:function(){return r.isAndroid()?t.ANDROID_WEB:r.isIOS()||r.isIpad()?t.IOS_WEB:r.isElectron()?t.PC_NATIVE:t.PC_WEB},isX5:function(){return this.isAndroid()&&/\s(TBS|X5Core)\/[\w\.\-]+/i.test(n())},isPC:function(){return!a(i("os "))&&!a(i("android[/ ]"))},isIOS:function(){return a(i("os "))},isIpad:function(){return navigator.userAgent.match(/(iPad)/)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1},isAndroid:function(){return a(i("android[/ ]"))},isIOSSafari:function(){return this.isIOS()&&this.isSafari()},isIpadSafari:function(){return this.isIpad()&&this.isSafari()},isElectron:function(){return/electron/i.test(n())},isMobile:function(){return r.isAndroid()||r.isIOS()},isSafari:function(){return/^((?!chrome|android).)*safari/i.test(n())},isFirefox:function(){return/firefox/i.test(n())},isChrome:function(){return/chrome/i.test(n())},isLocalHost:function(){return"localhost"===location.hostname},device:t,getBrowser:function(){return r.isX5()?"X5":r.isChrome()?"Chrome":r.isFirefox()?"Firefox":r.isIpadSafari()?"iPad-Safari":r.isIOSSafari()?"iPhone-Safari":r.isSafari()?"Mac-Safari":"Unknown"}};function n(){return navigator.userAgent.toLowerCase()}function i(e){return""+(new RegExp(e+"(\\d+((\\.|_)\\d+)*)").exec(n())||[,0])[1]||void 0}function a(e){return parseFloat((e||"").replace(/\_/g,"."))||0}e.exports=r},429:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){var e=void 0;for(var t in r)if(self[t]){e=r[t];break}return e};var r={DPlayer:"dplayer",CBPlayer:"cbplayer",jwplayer:"jwplayer",videojs:"videojs",Clappr:"clappr",ckplayer:"ckplayer",MediaElementPlayer:"mediaelement",MediaElement:"mediaelement",TcPlayer:"tcplayer",flowplayer:"flowplayer",Chimee:"chimee",ChimeePlayer:"chimee",HlsJsPlayer:"xgplayer",fluidPlayer:"fluidplayer",OpenPlayer:"openplayer",Plyr:"plyr",Playerjs:"playerjs",Aliplayer:"aliplayer",shaka:"shakaplayer",RadiantMP:"rmp",bitmovin:"bitmovin"};e.exports=t.default},824:e=>{var t=void 0;e.exports="function"==typeof queueMicrotask?queueMicrotask.bind(globalThis):function(e){return(t||(t=Promise.resolve())).then(e).catch((function(e){return setTimeout((function(){throw e}),0)}))}},406:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=t.setItem=function(e,t){"object"===(void 0===t?"undefined":r(t))&&(t=JSON.stringify(t)),localStorage.setItem(e,t)};t.hasItemUnexpired=function(e){var t=localStorage.getItem(e);try{var r=JSON.parse(t);return!(!r.duration||!r.startTime)&&Date.now()-r.startTime<r.duration}catch(e){return!1}},t.getItem=function(e){var t=localStorage.getItem(e);try{var r=JSON.parse(t);return r.value?r.value:r}catch(e){return t}},t.removeItem=function(e){localStorage.removeItem(e)},t.removeAllItem=function(){localStorage.clear()},t.setItemWithExpiration=function(e,t,r){var i={value:t,duration:r,startTime:Date.now()};n(e,i)}},408:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.randomTargetPair=t.EmptyClass=t.DEFAULT_PACKET_SIZE=t.HEADER_SW_PROXY=void 0,t.noop=function(){return!0},t.getQueryParam=function(e){return new URL(location.href).searchParams.get(e)},t.getQueryParamOfUrl=function(e,t){return new URL(e).searchParams.get(t)},t.appendQueryParamOfUrl=u,t.removeUrlParameter=function(e,t){var r=new URL(e);return r.searchParams.delete(t),r.href},t.getAndRemoveQueryParamOfUrl=function(e,t){var r=new URL(e);if(r.searchParams.get(t))return r.searchParams.delete(t),r.href;return""},t.updateQueryStringParam=function(e,t,r){var n=new RegExp("([?&])"+t+"=.*?(&|$)","i"),i=-1!==e.indexOf("?")?"&":"?";return e.match(n)?e.replace(n,"$1"+t+"="+r+"$2"):e+i+t+"="+r},t.getCurrentTs=function(){return Date.parse(new Date)/1e3},t.randomNum=d,t.calCheckPeersDelay=function(e){return 0===e?o:.5*e+1.67},t.performRangeRequest=function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:2e3,a=arguments.length>4&&void 0!==arguments[4]&&arguments[4],s=new XMLHttpRequest,o=e;a&&(o=u(e,i.proxyIdentifier,!0));return t=t||"bytes=0-0",new Promise((function(i,a){s.open("GET",o,!0),s.responseType="arraybuffer",s.timeout=n,s.onreadystatechange=function(e){if(4===s.readyState){var r=s.status;206===r||200===r&&t?i(s.response):a("status "+r+" url "+o+" range "+t)}},s.onerror=function(e){a("request error")},s.ontimeout=function(e){a("timeout")},s.setRequestHeader("Range",t),r&&r(s,e),s.send()}))},t.navLang=function(){return"zh-CN"===(navigator.language||navigator.userLanguage)?"cn":"en"},t.dontWaitFor=function(e){e.then((function(){}))},t.timeout=function(e){return new Promise((function(t){return setTimeout(t,e)}))},t.timeoutReject=function(e,t){return new Promise((function(r,n){return setTimeout((function(){n(t)}),e)}))},t.getBrowserRTC=function(){if("undefined"==typeof self)return null;var e={RTCPeerConnection:self.RTCPeerConnection||self.mozRTCPeerConnection||self.webkitRTCPeerConnection,RTCSessionDescription:self.RTCSessionDescription||self.mozRTCSessionDescription||self.webkitRTCSessionDescription,RTCIceCandidate:self.RTCIceCandidate||self.mozRTCIceCandidate||self.webkitRTCIceCandidate};return e.RTCPeerConnection&&e.RTCPeerConnection.prototype?e:null},t.copyBuffer=function(e){var t=n.Buffer.from(e),r=new n.Buffer(e.byteLength);return t.copy(r),r},t.getMaxSequence=function(e){var t=e.split("\n"),r=0,n=0,i=!0,a=!1,s=void 0;try{for(var o,l=t[Symbol.iterator]();!(i=(o=l.next()).done);i=!0){var u=o.value,d=/^#EXT-X-MEDIA-SEQUENCE:?(\-?[0-9.]*)?/.exec(u);if(d&&d[1]){r=parseInt(d[1],10);break}}}catch(e){a=!0,s=e}finally{try{!i&&l.return&&l.return()}finally{if(a)throw s}}var c=!0,f=!1,h=void 0;try{for(var g,v=t[Symbol.iterator]();!(c=(g=v.next()).done);c=!0){g.value.startsWith("#EXTINF")&&n++}}catch(e){f=!0,h=e}finally{try{!c&&v.return&&v.return()}finally{if(f)throw h}}return r+n-1},t.isHttps=function(){return location.protocol.startsWith("https")},t.isInteger=function(e){return"number"==typeof e&&e%1==0},t.getHomeUrl=function(){return self.atob("aHR0cHM6Ly9zd2FybWNsb3VkLm5ldA==")},t.splitBytes=function(e,t){for(var r=e.byteLength-t,i=[],a=t,s=Math.floor(r/l),o=r%l,u=0;u<s;u++){var d=(0,n.Buffer)(l);e.copy(d,0,a,a+l),i.push(d),a+=l}if(o>0){var c=(0,n.Buffer)(o);e.copy(c,0,a,a+o),i.push(c)}return i},t.getAvailableMemory=function(){var e=performance.memory;return e?e.jsHeapSizeLimit-e.usedJSHeapSize:-1},t.trimMap=function(e,t,r){if(e.size<=t)return;var n=[].concat(s(e.keys()));do{var i=n.shift();r&&r(e.get(i)),e.delete(i)}while(e.size>t)},t.trimSet=function(e,t){if(e.size<=t)return;var r=[].concat(s(e.values()));do{e.delete(r.shift())}while(e.size>t)},t.isArrayBuffer=function(e){return e instanceof ArrayBuffer&&0!==e.byteLength},t.getRangeFromRangeStr=function(e){if(!e)return{};var t=(e=e.substring(6)).split("-");if(2!==t.length)return{};var r=Number(t[0]),n=t[1]?Number(t[1]):-1;return{rangeStart:r,rangeEnd:n>=0?n+1:void 0}},t.compareVersions=function(e,t){for(var r=e.split("."),n=t.split("."),i=0;i<Math.max(r.length,n.length);i++){var a=parseInt(r[i]||0),s=parseInt(n[i]||0);if(a<s)return-1;if(a>s)return 1}return 0},t.swRegisterPromise=function(e){return new Promise((function(t,r){var n=e.installing||e.waiting||e.active,i=function r(){return"activated"===n.state&&(n.removeEventListener("statechange",r),t(e),!0)};i()||n.addEventListener("statechange",i)}))},t.isConstructor=function(e){try{new e}catch(e){return!1}return!0},t.proxyKeepalive=function(e){return new Promise((function(t,r){fetch(e+"/keepalive/").then((function(e){if(e.ok)return e.text();throw new Error("keepalive failed")})).then((function(e){if(""!==e.trim())throw new Error("not valid keepalive response");t()})).catch((function(e){r(e)}))}))},t.getNetUrl=function(e){return e.split("?")[0]},t.getUrlSuffix=function(e){var t=a.parseURL(e),r=t.path.substring(t.path.lastIndexOf(".")+1);r.endsWith("/")&&(r=r.substring(0,r.length-1));return r},t.getFormattedTime=function(){var e=new Date,t=e.getHours(),r=e.getMinutes(),n=e.getSeconds(),i=e.getMilliseconds();return t.toString().padStart(2,"0")+":"+r.toString().padStart(2,"0")+":"+n.toString().padStart(2,"0")+"."+i},t.sortPeersWithRegion=function(e,t){var r=[],n=new Set,i=!0,a=!1,s=void 0;try{for(var o,l=e[Symbol.iterator]();!(i=(o=l.next()).done);i=!0){var u=o.value;n.has(u.id)||(n.add(u.id),r.push(u))}}catch(e){a=!0,s=e}finally{try{!i&&l.return&&l.return()}finally{if(a)throw s}}var d=t.asn,c=t.country;if(!d||!c||r.length<2)return r;var f=r.filter((function(e){return!e.asn&&!e.country})),h=r.filter((function(e){return e.country===c&&e.asn!==d})),g=r.filter((function(e){return e.asn===d&&e.country===c})),v=r.filter((function(e){return!f.includes(e)&&!g.includes(e)&&!h.includes(e)}));return g.concat(h).concat(f).concat(v)},t.isFunction=function(e){return e&&"function"==typeof e},t.streamFromUpstream=function(e,t,r,n,i,a){e.sendPartialBuffer(r,n,{from:i,incompletes:a}),n.length<r.attachments?function(e,t,r){e.addStreamListener(r,t.remotePeerId,(function(e,r,n,i,a){n?t.sendMsgPieceAbort(i,r,!0):t.uploading&&t.send(i),a&&(t.uploading=!1)}))}(t,e,!!r.reverse):e.uploading=!1},t.getBestTargetPair=function(e,t,r){if(1===e.length)return t.length>=1&&r.length>=1?t[0].weight>r[0].weight?[t[0],e[0]]:[e[0],r[0]]:t.length>=1?[t[0],e[0]]:r.length>=1?[e[0],r[0]]:c(e[0]);return[t.length>=1?t[0]:null,r.length>=1?r[0]:null]};var n=r(921),i=r(117),a=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(r(299));function s(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}t.HEADER_SW_PROXY="__sw_proxy__";var o=3,l=t.DEFAULT_PACKET_SIZE=64e3;function u(e,t,r){var n=new URL(e);return n.searchParams.append(t,r),n.href}function d(e,t){return parseInt(Math.random()*(t-e+1)+e,10)}t.EmptyClass=function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)};var c=t.randomTargetPair=function(e){return 0===d(0,1)?[null,e]:[e,null]}},56:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=o(r(696)),a=r(408),s=o(r(569));function o(e){return e&&e.__esModule?e:{default:e}}var l=function(){function e(t,r,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"main";!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.logger=t,this.config=r,this.wsAddr=n,this.serverVersion=0,this.pingInterval=95e3,this.name=i,this.normalClosed=!1,this.lastSendTs=performance.now(),this.pollingClient=new s.default(t,n);try{this._ws=this._init()}catch(e){t.error(e),this._startPolling()}}return n(e,[{key:"_init",value:function(){var e=this,t={maxRetries:this.config.wsMaxRetries,minReconnectionDelay:(0,a.randomNum)(1e4,6e4),maxReconnectionDelay:6e5,maxEnqueuedMessages:20,connectionTimeout:7e3},r=new i.default(this.wsAddr,void 0,t);return r.addEventListener("open",(function(){e.logger.info("signal "+e.name+" "+e.wsAddr+" connection opened"),e.normalClosed=!1,e.pollingClient.connected?e.pollingClient.close():e.onopen&&e.onopen(),e._startPing(e.pingInterval)})),r.push=r.send,r.send=function(t){e.lastSendTs=performance.now();var n=JSON.stringify(t);r.push(n)},r.addEventListener("message",(function(t){var r=t.data,n=JSON.parse(r),i=n.action;if("pong"!==i){if("ver"!==i)return"close"===i?(e.logger.warn("server close signal "+e.name+" reason "+n.reason),void e.close()):void(e.onmessage&&e.onmessage(n,e.name));e.serverVersion=n.ver}else clearTimeout(e.pongTimer)})),r.addEventListener("close",(function(t){e.logger.warn("signal "+e.name+" "+e.wsAddr+" closed "+t.code+" "+t.reason),t.code>=5e3||t.code<4e3?(e.onclose&&e.onclose(),e._stopPing()):e.close()})),r.addEventListener("error",(function(t){e._stopPing(),e.onerror&&e.onerror(t),e._startPolling()})),r}},{key:"_startPolling",value:function(){this.pollingClient.connected||(this.logger.info("start polling"),this.pollingClient.start(),this._setupPolling(this.pollingClient))}},{key:"sendSignal",value:function(e,t){var r={action:"signal",to_peer_id:e,data:t};this._send(r)}},{key:"sendSignalBatch",value:function(e,t){if(this.batchSupported&&t.length>1)this._send({action:"signals",to_peer_id:e,data:t});else{var r=!0,n=!1,i=void 0;try{for(var a,s=t[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var o=a.value;this.sendSignal(e,o)}}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}}}},{key:"sendReject",value:function(e,t,r){var n={action:"reject",to_peer_id:e,reason:t,fatal:r};this._send(n)}},{key:"_send",value:function(e){this.pollingClient.connected?this.pollingClient.send(e):this._ws&&this._ws.send(e)}},{key:"_startPing",value:function(e){var t=this;this.connected&&(this.pingTimer=setTimeout((function(){var e=95e3-(performance.now()-t.lastSendTs);if(e>=0)return t._startPing(e);t._ws&&t._ws.push(JSON.stringify({action:"ping"})),t.serverVersion>=22&&t._waitForPong(),t._startPing(t.pingInterval)}),e))}},{key:"_waitForPong",value:function(){var e=this;this.pongTimer=setTimeout((function(){e.logger.warn("signal "+e.name+" wait for pong timeout, reconnect"),e.close(),e.reconnect()}),15e3)}},{key:"_stopPing",value:function(){clearTimeout(this.pingTimer),clearTimeout(this.pongTimer)}},{key:"close",value:function(){var e=this;this.logger.info("close signal "+this.name),this._stopPing(),e._ws&&e._ws.close(1e3,"normal close"),this.pollingClient.close(),this.normalClosed=!0}},{key:"reconnect",value:function(){this._ws&&(this.logger.info("reconnect signal "+this.name),this._ws.reconnect())}},{key:"destroy",value:function(){this.close(),this._ws=null,this.pollingClient.destroy()}},{key:"_setupPolling",value:function(e){var t=this;e.onopen=function(e){e&&(t.serverVersion=e),t.logger.info("polling opened"),t.onopen&&t.onopen()},e.onerror=function(e){t._connected||t.onerror&&t.onerror(e)},e.onclose=function(){t._connected||t.onclose&&t.onclose()},e.onmessage=function(e){if(t.onmessage){var r=!0,n=!1,i=void 0;try{for(var a,s=e[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var o=a.value;t.onmessage(o,t.name)}}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}}}}},{key:"batchSupported",get:function(){return this.serverVersion>=50}},{key:"connected",get:function(){return!!this.pollingClient.connected||this._connected}},{key:"_connected",get:function(){return!!this._ws&&this._ws.readyState===i.default.OPEN}}]),e}();t.default=l,e.exports=t.default},680:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=r(183);var s=i({},((n=a)&&n.__esModule?n:{default:n}).default,{p2pBlackList:["aac","mp3","vtt","webvtt","key"],scheduledBySegId:!1,simultaneousTargetPeers:2,maxSubscribeLevel:3,live:!0,waitForPeer:!1,waitForPeerTimeout:4.5,httpLoadTime:2.5,sharePlaylist:!1,useHttpRange:!0});s.validateSegment=function(e,t){return!0},t.default=s,e.exports=t.default},327:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n,i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a=r(816),s=(n=a)&&n.__esModule?n:{default:n};t.default=i({},s.default,{SCH_DCHAVE:"SCH_DCHAVE",DC_SUBSCRIBE:"SUBSCRIBE",DC_UNSUBSCRIBE:"UNSUBSCRIBE",DC_SUBSCRIBE_ACCEPT:"SUBSCRIBE_ACCEPT",DC_SUBSCRIBE_REJECT:"SUBSCRIBE_REJECT",DC_SUBSCRIBE_LEVEL:"SUBSCRIBE_LEVEL"}),e.exports=t.default},788:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=c(r(648)),a=r(389),s=c(r(308)),o=c(r(91)),l=c(r(824)),u=c(r(327)),d=r(408);function c(e){return e&&e.__esModule?e:{default:e}}var f=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));r.logger=e.logger;var n=window.__p2p_loader__,i=n.scheduler,s=n.fetcher,l=n.p2pBlackList,u=n.isHlsV0;return r.isHlsV0=u,r.bufMgr=e.bufMgr,r.xhrLoader=new e.loader(e),r.p2pEnabled=e.p2pEnabled,r.isLive=e.live,r.scheduler=i,r.fetcher=s,r.segmentId=e.segmentId,r.blockTypes=l,r.forbidden=s.forbidden,r.multiBitrate=r.scheduler instanceof o.default,r.stats=r.xhrLoader.stats||(0,a.createLoadStats)(),r.waitTimer=null,r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"destroy",value:function(){this.xhrLoader.destroy()}},{key:"abort",value:function(){this.xhrLoader.abort()}},{key:"load",value:function(e,t,r){var n=this,i=this.logger,s=this.scheduler,o=e.frag;this.isHlsV0||(o.stats=this.stats);var c=e.frag.segId;if(!c){var f=void 0;e.rangeEnd&&(f="bytes="+e.rangeStart+"-"+(e.rangeEnd-1)),c=e.frag.segId=this.segmentId(String(o.level),o.sn,o.url,f)}if(!o.url||(0,a.isBlockType)(o.url,this.blockTypes))return i.info("HTTP load blockType "+o.url),e.frag.loadByHTTP=!0,this.xhrLoader.load(e,t,r);if(!this.forbidden)if(this.fetcher.increMediaRequests(),t.maxRetry=2,this.p2pEnabled&&this.bufMgr.hasSegOfId(c)){i.info("bufMgr found seg sn "+o.sn+" segId "+c);var h=this.bufMgr.getSegById(c),g=(0,d.copyBuffer)(h.data),v=new Uint8Array(g).buffer,p={url:e.url,data:v};(0,a.updateLoadStats)(this.stats,h.size),o.loaded=h.size,o.loadByP2P=!0,e.frag.fromPeerId=h.fromPeerId,(0,l.default)((function(){!n.isHlsV0&&r.onProgress&&r.onProgress(n.stats,e,p.data),r.onSuccess(p,n.stats,e)}))}else if(this.p2pEnabled&&s.hasAndSetTargetPeer(this.multiBitrate?o.segId:o.sn))this.loadFragByP2p(e,t,r,c);else{var m=s.mBufferedDuration;if(i.info("fragLoader load "+c+" at "+o.sn+" level "+o.level+" buffered "+m),this.isLive&&s.hasIdlePeers&&m>6.5&&s.shouldWaitForNextSeg()){var y=m-6.5;y>5.5&&(y=5.5);var b=function i(a){c===a&&(s.off(u.default.SCH_DCHAVE,i),clearTimeout(n.waitTimer),s.hasAndSetTargetPeer(n.multiBitrate?o.segId:o.sn)?n.loadFragByP2p(e,t,r,c):n.loadFragByHttp(e,t,r,c))};i.info("wait peer have for "+y+"s"),s.on(u.default.SCH_DCHAVE,b),this.waitTimer=setTimeout((function(){s.notifyAllPeers(o.sn,c),n.loadFragByHttp(e,t,r,c),s.off(u.default.SCH_DCHAVE,b)}),1e3*y)}else this.loadFragByHttp(e,t,r,c)}}},{key:"loadFragByHttp",value:function(e,t,r,n){var i=this;this.scheduler.isReceiver=!1;var a=this.logger,o=e.frag;if(this.isHlsV0){var l=r.onSuccess;r.onSuccess=function(e,t,r){if(!i.bufMgr.hasSegOfId(n)){var u=(0,d.copyBuffer)(e.data),c=new s.default(o.sn,n,u,i.fetcher.peerId);i.bufMgr.putSeg(c)}i.fetcher.reportFlow(t.total);var f=t.tload-t.trequest;a.info("HTTP loaded "+n+" time "+f+"ms"),l(e,t,r)}}else if(r.onProgress){var u=r.onProgress;r.onProgress=function(e,t,r){if(!i.bufMgr.hasSegOfId(n)){var l=(0,d.copyBuffer)(r),c=new s.default(o.sn,n,l,i.fetcher.peerId);i.bufMgr.putSeg(c)}i.fetcher.reportFlow(e.total),o.loaded=e.total;var f=e.loading.end-e.loading.start;a.info("HTTP loaded "+n+" time "+f+"ms"),u(e,t,r)}}e.frag.loadByHTTP=!0,this.xhrLoader.load(e,t,r)}},{key:"loadFragByP2p",value:function(e,t,r,n){var i=this,a=this.logger,o=e.frag;this.scheduler.load(e,t,r);var l=r.onSuccess,u=r.onTimeout;r.onTimeout=function(e,s){a.warn("P2P timeout switched to HTTP load "+o.relurl+" at "+o.sn),r.onSuccess=l,i.loadFragByHttp(s,t,r,n),r.onTimeout=u},r.onSuccess=function(e,t,u){if(!i.bufMgr.hasSegOfId(n)){var c=(0,d.copyBuffer)(e.data),f=new s.default(o.sn,n,c,o.fromPeerId||i.fetcher.peerId);i.bufMgr.putSeg(f)}o.loadByP2P||i.fetcher.reportFlow(t.total),o.loaded=t.loaded,a.info((o.loadByP2P?"P2P":"HTTP")+" loaded segment id "+n),!i.isHlsV0&&r.onProgress&&r.onProgress(t,u,e.data),l(e,t,u)}}}]),t}(i.default);t.default=f,e.exports=t.default},91:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=function e(t,r,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,r);if(void 0===i){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(n):void 0},a=d(r(308)),s=d(r(327)),o=d(r(461)),l=r(389),u=r(408);function d(e){return e&&e.__esModule?e:{default:e}}function c(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var f=function(e){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r));return n.logger.info("use IdScheduler"),n.sequential=!1,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"load",value:function(e,t,r){this.isReceiver=!0;var n=this.logger;this.context=e;var i=e.frag,a=i.segId,s=i.sn;this.callbacks=r,this.stats=(0,l.createLoadStats)(),this.criticalSeg={sn:s,segId:a,targetPeers:[].concat(c(this.targetPeers.map((function(e){return e.remotePeerId}))))};var o=this.mBufferedDuration-this.config.httpLoadTime;o>this.dcDownloadTimeout&&(o=this.dcDownloadTimeout);var u=!0,d=!1,f=void 0;try{for(var h,g=this.targetPeers[Symbol.iterator]();!(u=(h=g.next()).done);u=!0){var v=h.value;v.downloading||(n.info("request criticalSeg segId "+a+" at "+s+" from "+v.remotePeerId+" timeout "+o),v.requestDataById(a,s,!0)),this.requestingMap.set(a,v.remotePeerId)}}catch(e){d=!0,f=e}finally{try{!u&&g.return&&g.return()}finally{if(d)throw f}}this.criticaltimeouter=setTimeout(this.criticaltimeout.bind(this,!0),1e3*o),this.targetPeers=[]}},{key:"onBufferManagerLost",value:function(e,t,r){this.bitset.delete(t),this.bitCounts.delete(t)}},{key:"destroy",value:function(){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"destroy",this).call(this),this.logger.warn("destroy IdScheduler")}},{key:"_setupDC",value:function(e){var r=this;i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_setupDC",this).call(this,e);var n=this.logger,o=this.config;e.on(s.default.DC_HAVE,(function(t){if(t.seg_id&&e.bitset){var n=t.seg_id;e.bitset.has(n)||(e.bitset.add(n),r.bitset.has(n)||r._increBitCounts(n)),o.live&&(0,u.trimSet)(e.bitset,20),r.emit(s.default.SCH_DCHAVE,t.seg_id)}})).on(s.default.DC_LOST,(function(t){if(t.seg_id&&e.bitset){var n=t.seg_id;e.bitset.has(n)&&(e.bitset.delete(n),r._decreBitCounts(n))}})).on(s.default.DC_PIECE,(function(e){e.ext&&e.ext.incompletes>=2||r.notifyAllPeers(e.sn,e.seg_id)})).on(s.default.DC_PIECE_NOT_FOUND,(function(t){var i=t.seg_id;r.criticalSeg&&r.criticalSeg.segId===i&&(1===r.criticalSeg.targetPeers.length?(clearTimeout(r.criticaltimeouter),n.info("DC_PIECE_NOT_FOUND"),r.criticalSeg=null,r.callbacks.onTimeout(r.stats,r.context,null)):r.criticalSeg.targetPeers=r.criticalSeg.targetPeers.filter((function(t){return t!==e.remotePeerId}))),e.bitset.delete(i),r.requestingMap.delete(i),r._decreBitCounts(i),e.checkIfNeedChoke(!0)})).on(s.default.DC_RESPONSE,(function(s,o){var l=s.segId,u=s.sn,d=s.data,c=r.criticalSeg&&r.criticalSeg.segId===l;if(r.config.validateSegment(l,d))if(r.notifyAllPeers(u,l),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"reportDCTraffic",r).call(r,l,s.size,o),c){n.info("receive criticalSeg seg_id "+l),clearTimeout(r.criticaltimeouter),r.criticaltimeouter=null,e.miss=0;var f=r.stats;f.tfirst=f.loading.first=Math.max(f.trequest,performance.now()),f.tload=f.loading.end=f.tfirst,f.loaded=f.total=d.byteLength,r.criticalSeg=null;var h=r.context.frag;h.fromPeerId=e.remotePeerId,h.loadByP2P=!0,r.callbacks.onSuccess({data:d},f,r.context)}else{if(r.bitset.has(l))return;var g=new a.default(u,l,d,e.remotePeerId);r.bufMgr.putSeg(g),r.updateLoaded(l)}else n.warn("segment "+l+" validate failed"),c&&(clearTimeout(r.criticaltimeouter),r.criticaltimeout());r.requestingMap.delete(l)})).on(s.default.DC_REQUEST,(function(t){r.isUploader=!0;var i=t.seg_id,a=null;if(r.requestingMap.has(i)&&(a=r.getPeerLoadedMore(i)),r.bufMgr.hasSegOfId(i)){n.info("found seg from bufMgr");var o=r.bufMgr.getSegById(i);e.sendBuffer(o.sn,o.segId,o.data)}else a&&a.downloading&&a.pieceMsg.seg_id===i?(n.info("target had partial buffer, wait for remain"),e.sendPartialBuffer(a.pieceMsg,a.bufArr,{from:"WaitForPartial",incompletes:1}),function(t,r){t.addStreamListener(!1,r.remotePeerId,(function(t,n,i,a,s){i?r.sendMsgPieceAbort(a,n,!0):r.send(a),s&&(e.uploading=!1)}))}(a,e)):(n.info("peer request "+i+" wait for seg"),r.bufMgr.once(""+s.default.BM_ADDED_SEG_+i,(function(r){r?(n.info("peer request notify seg "+i),e.sendBuffer(r.sn,r.segId,r.data)):e.sendPieceNotFound(t.sn,i)})))}))}},{key:"_setupEngine",value:function(){var e=this;this.engine.on(s.default.FRAG_LOADING,(function(t,r,n){e.loadingSegId=r,e.isHlsV0&&n&&e.notifyAllPeers(t,r)})).on(s.default.FRAG_LOADED,(function(t,r,n,i,a){r&&(!e.isHlsV0&&a&&e.notifyAllPeers(t,r),e.updateLoaded(r))}))}}]),t}(o.default);t.default=f,e.exports=t.default},461:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=function e(t,r,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,r);if(void 0===i){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(n):void 0},a=u(r(99)),s=u(r(327)),o=r(408),l=r(921);function u(e){return e&&e.__esModule?e:{default:e}}var d=function(e){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r));return n.targetPeers=[],n.mBufferedDuration=0,n.loadingSegId="",n.allowP2pLimit=r.httpLoadTime+2,n.playlistInfo=new Map,n.subscribeMode=!1,n.subscribeLevel=0,n.subscribers=[],n.subscribeParent=null,n.subscriberEdgeSN=0,n.isUploader=!1,n.isReceiver=!1,n.isHlsV0=r.isHlsV0,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"hasAndSetTargetPeer",value:function(e){var t=this.logger,r=this.config;if(this.criticalSeg&&t.warn("scheduler still loading "+JSON.stringify(this.criticalSeg)),this.waitForPeer){if(this.peersHas(e)){var n=!0,i=!1,a=void 0;try{for(var s,o=this.peerManager.getAvailablePeers()[Symbol.iterator]();!(n=(s=o.next()).done);n=!0){var l=s.value;if(l.bitset.has(e))return t.info("found "+e+" from peer "+l.remotePeerId),this.targetPeers.push(l),!0}}catch(e){i=!0,a=e}finally{try{!n&&o.return&&o.return()}finally{if(i)throw a}}}return 0!==this.waitingPeers&&this.waitingPeers===this.peersNum?(t.info("all connected no need wait"),!1):(t.warn("wait for peer to load "+e),this.requestingMap.setPeerUnknown(e),!0)}var u=this.bufferedDuration;if(this.subscribeMode){var d=this.subscribeParent,c=d.remotePeerId;return d.bitset.has(e)?d.downloading?this._searchAvailablePeers(e):(t.info("found "+e+" from parent "+c),this.targetPeers.push(this.subscribeParent),!0):!(u<=3.5)&&(t.info("under subscribe to "+c),this.requestingMap.set(e,c),!0)}if(u<=this.allowP2pLimit)return!1;if(this.requestingMap.has(e)){var f=this.requestingMap.getOnePeerId(e),h=this.peerManager.getPeer(f);return h?!(performance.now()-h.timeSendRequest>3e3&&!h.shouldWaitForRemain(1e3*(u-r.httpLoadTime)))||!!this._searchAvailablePeers(e,1)&&(t.warn(f+" prefetch timeout at "+e),this.targetPeers.push(h),this.requestingMap.delete(e),!0):this._searchAvailablePeers(e)}return this._searchAvailablePeers(e)}},{key:"_searchAvailablePeers",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5;if(!this.hasIdlePeers||!this.peersHas(e))return!1;var r=0,n=!0,i=!1,a=void 0;try{for(var s,o=this.peerManager.getPeersOrderByWeight()[Symbol.iterator]();!(n=(s=o.next()).done);n=!0){var l=s.value;if(l.bitset.has(e)&&(this.logger.info("found "+e+" from peer "+l.remotePeerId),this.targetPeers.push(l),++r===t||r===this.config.simultaneousTargetPeers))return!0}}catch(e){i=!0,a=e}finally{try{!n&&o.return&&o.return()}finally{if(i)throw a}}return this.targetPeers.length>0}},{key:"notifyAllPeers",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if(!this.downloadOnly){var n=this.config.live,i=t;if(this.sequential&&(i=e),!this.bitset.has(i)){var a=!0,s=!1,l=void 0;try{for(var u,d=this.getPeers()[Symbol.iterator]();!(a=(u=d.next()).done);a=!0){var c=u.value;if(!c.notifySet.has(i)&&!c.bitset.has(i)){if(n&&(this.subscribers.includes(c.remotePeerId)||this.subscribeParent&&c.remotePeerId===this.subscribeParent.remotePeerId))continue;if(!r.includes(c.remotePeerId)&&(c.sendMsgHave(e,t),c.notifySet.add(i),n)){if(this.sequential){var f=e-20;f>0&&c.notifySet.delete(f)}else(0,o.trimSet)(c.notifySet,20)}}}}catch(e){s=!0,l=e}finally{try{!a&&d.return&&d.return()}finally{if(s)throw l}}}}}},{key:"updateLoaded",value:function(e){this.bitset.has(e)||(this.bitset.add(e),this.bitCounts.has(e)&&this.bitCounts.delete(e))}},{key:"deletePeer",value:function(e){var r=this;this.peerManager.hasPeer(e.remotePeerId)&&e.bitset.forEach((function(e){r._decreBitCounts(e)})),this.cleanRequestingMap(e.remotePeerId),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deletePeer",this).call(this,e)}},{key:"_setupDC",value:function(e){var r=this;i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_setupDC",this).call(this,e);this.logger;e.on(s.default.DC_PIECE,(function(e){r.criticalSeg&&r.criticalSeg.segId===e.seg_id&&(r.stats.tfirst=Math.max(performance.now(),r.stats.trequest))})).on(s.default.DC_PIECE_DATA,(function(t,n,i,a,s){1===a&&e.pieceMsg.ext&&e.pieceMsg.ext.incompletes>=2&&r.notifyAllPeers(t,n)}))}},{key:"loadRemainBufferByHttp",value:function(e,r){var n=this,a=this.context.frag.url,s=this.config.xhrSetup,u=l.Buffer.concat(e.bufArr);i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"reportDCTraffic",this).call(this,r,u.byteLength,0);var d="bytes=";if(this.context.rangeEnd){var c=Number(this.context.rangeStart),f=Number(this.context.rangeEnd);d=""+d+(c+u.byteLength)+"-"+(f-1)}else d=""+d+u.byteLength+"-";this.logger.info("continue download from "+a+" range: "+d),(0,o.performRangeRequest)(a,d,s).then((function(t){var r=l.Buffer.from(t);n.engine.fetcher.reportFlow(r.byteLength);var i=l.Buffer.concat([u,r]),a=new Uint8Array(i).buffer,s=n.stats;s.tfirst=s.loading.first=Math.max(s.trequest,performance.now()),s.tload=s.loading.end=s.tfirst,s.loaded=s.total=i.byteLength;var o=n.context.frag;o.fromPeerId=e.remotePeerId,o.loadByP2P=!0,n.callbacks.onSuccess({data:a},s,n.context)})).catch((function(e){n.logger.error("http partial download error "+e),n.callbacks.onTimeout(n.stats,n.context,null)}))}},{key:"broadcastPlaylist",value:function(e,t){if(this.config.live){var r=(0,o.getMaxSequence)(t),n=!0,i=!1,a=void 0;try{for(var s,l=this.getPeers()[Symbol.iterator]();!(n=(s=l.next()).done);n=!0){s.value.sendMsgPlaylist(e,t,r)}}catch(e){i=!0,a=e}finally{try{!n&&l.return&&l.return()}finally{if(i)throw a}}this.playlistInfo.set(e,{seq:r})}}},{key:"getPlaylistFromPeer",value:function(e){if(!this.config.live)return null;var t=this.playlistInfo.get(e).seq,r=!0,n=!1,i=void 0;try{for(var a,s=this.getPeers()[Symbol.iterator]();!(r=(a=s.next()).done);r=!0){var o=a.value.getLatestPlaylist(e,t);if(o)return o}}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}return null}},{key:"_handlePieceAborted",value:function(e){this.criticalSeg&&this.criticalSeg.targetPeers.includes(e)?1===this.criticalSeg.targetPeers.length?(clearTimeout(this.criticaltimeouter),this.criticaltimeout(),this.cleanRequestingMap(e)):this.criticalSeg.targetPeers=this.criticalSeg.targetPeers.filter((function(t){return t!==e})):this.cleanRequestingMap(e)}},{key:"criticaltimeout",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.logger,r=this.config;if(this.waitForPeer&&(this.waitForPeer=!1),this.criticalSeg){var n=this.criticalSeg.sn,i=this.criticalSeg.segId;this.sequential&&(i=n),t.info("critical request sn "+i+" timeout");var a=void 0;this.subscribeMode?a=this.subscribeParent:this.requestingMap.has(i)&&(a=this.getPeerLoadedMore(i));var s=!1;if(a&&(s=!a.loadtimeout()),s)t.info("p2p download completed");else{var o=1e3*r.httpLoadTime-500;if(e&&a&&a.shouldWaitForRemain(o))return t.info("wait for peer load remain of "+n),void(this.criticaltimeouter=setTimeout(this.criticaltimeout.bind(this),o+200));r.httpRangeSupported&&a&&a.bufArr.length>0&&a.segId===this.criticalSeg.segId?this.loadRemainBufferByHttp(a,i):this.callbacks.onTimeout(this.stats,this.context,null),this.requestingMap.delete(i),r.live&&a&&a.resetContinuousHits(),this.subscribeParent&&this._unsubscribe("subscribe timeout for "+n),this.criticalSeg=null,this.criticaltimeouter=null}}}},{key:"shouldWaitForNextSeg",value:function(){var e=void 0;return e=!(this.subscribers.length>0||this.isUploader)&&(!!this.isReceiver||(0,o.randomNum)(0,100)>20),this.isReceiver=this.isUploader=!1,e}},{key:"getStatsForPeer",value:function(){var e=this.subscribers,t=e.length>0?e.length:void 0,r=this.engine.currentLevel,n=this.engine.media.currentTime;return{children:t,pos:this.config.live?void 0:Math.round(n),level:r}}},{key:"bufferedDuration",get:function(){for(var e=this.engine.media,t=0,r=e.currentTime,n=e.buffered,i=n.length-1;i>=0;i--)if(r>=n.start(i)&&r<=n.end(i)){t=n.end(i)-r;break}return this.logger.info("bufferedDuration "+t),this.mBufferedDuration=t,t>0?t:0}}]),t}(a.default);t.default=d,e.exports=t.default},39:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=function e(t,r,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,r);if(void 0===i){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(n):void 0},a=c(r(308)),s=c(r(327)),o=c(r(461)),l=c(r(140)),u=r(389),d=c(r(824));function c(e){return e&&e.__esModule?e:{default:e}}function f(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}var h=function(e){function t(e,r){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var n=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r));return n.logger.info("use SnScheduler"),n.sequential=!0,n.currPlaySN=0,n.currLostSN=-1,n.nextLostSN=-1,n.config.live?n.maxPrefetchCount=3:(n.maxPrefetchCount=150,n.startCheckPeersTimer()),n.waitForPeer=r.waitForPeer||!1,n.waitingPeers=0,n.waitForPeer&&(n.waitForPeerTimer=setTimeout((function(){n.waitForPeer=!1}),1e3*(r.waitForPeerTimeout+2))),n.estimatedSize=1e6,n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"notifySubscribeLevel",value:function(){var e=this;this.subscribers.forEach((function(t){var r=e.peerManager.getPeer(t);r&&r.sendSubscribeLevel(e.subscribeLevel)}))}},{key:"updatePlaySN",value:function(e){this.currPlaySN=e}},{key:"checkPeers",value:function(){var e=this.logger,t=this.config,r=t.live;if(!this.waitForPeer&&0!==this.bitCounts.size&&!(!r&&this.nextLostSN>=0&&this.nextLostSN>=this.currPlaySN-10)&&this.hasPeers)if(this.mBufferedDuration<this.allowP2pLimit)e.info("low buffer time, skip prefetch");else{var n=this.peerManager.getPeersOrderByWeight();if(0!==n.length){var i=[],a=t.prefetchNum,s=t.endSN,o=t.startSN;r&&(a=1);var l=0,u=r?this.loadingSN+1:this.loadingSN+2;if(!r)if(this.loadingSN>=s&&!this.bufMgr.overflowed)u=o;else{var d=Math.min.apply(Math,f(n.filter((function(e){return e.endSN>=u})).map((function(e){return e?e.startSN:1/0}))));if(!isFinite(d))return;u<d&&(u=d)}for(;i.length<a&&i.length<n.length&&l<this.maxPrefetchCount;){if(!r&&u>s)return;if(this.bitset.has(u))u++;else{if(u!==this.loadingSN&&this.bitCounts.has(u)&&!this.requestingMap.has(u)){var c=!0,h=!1,g=void 0;try{for(var v,p=n[Symbol.iterator]();!(c=(v=p.next()).done);c=!0){var m=v.value;if(!i.includes(m)&&m.bitset.has(u)){m.requestDataBySN(u,!1),e.info("request prefetch "+u+" from peer "+m.remotePeerId+" downloadNum "+m.downloadNum),i.push(m),this.requestingMap.set(u,m.remotePeerId);break}}}catch(e){h=!0,g=e}finally{try{!c&&p.return&&p.return()}finally{if(h)throw g}}}l++,u++}}this.loadedPeerNum=i.length}}}},{key:"addPeer",value:function(e){if(i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"addPeer",this).call(this,e),this.waitForPeer&&this.criticalSeg){var r=this.criticalSeg.segId,n=this.criticalSeg.sn,a=e.remotePeerId,s=this.requestingMap;s.checkIfPeerUnknown(n)&&(e.bitset.has(n)?(this.logger.info("found initial seg "+n+" from peer "+a),s.set(n,a),e.requestDataById(r,n,!0)):this.waitingPeers===this.peersNum&&this.criticaltimeout())}}},{key:"deletePeer",value:function(e){if(i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"deletePeer",this).call(this,e),this.subscribeMode&&e.remotePeerId===this.subscribeParent.remotePeerId){var r="subscribe parent is leaved";this.logger.warn(r),this._unsubscribe(r),this.criticaltimeout()}}},{key:"load",value:function(e,t,r){this.isReceiver=!0;var n=this.logger,i=this.config;this.context=e;var a=e.frag,s=a.segId,o=a.sn;this.callbacks=r,this.stats=(0,u.createLoadStats)(),this.criticalSeg={sn:o,segId:s},this.targetPeers.length>0?this.criticalSeg.targetPeers=[].concat(f(this.targetPeers.map((function(e){return e.remotePeerId})))):this.criticalSeg.targetPeers=[].concat(f(this.requestingMap.getAllPeerIds(o)));var l=this.mBufferedDuration-i.httpLoadTime;if(this.waitForPeer?l=i.waitForPeerTimeout:l>this.dcDownloadTimeout&&(l=this.dcDownloadTimeout),this.requestingMap.has(o))n.info("wait for criticalSeg segId "+s+" at "+o+" timeout "+l);else{var d=!0,c=!1,h=void 0;try{for(var g,v=this.targetPeers[Symbol.iterator]();!(d=(g=v.next()).done);d=!0){var p=g.value;p.downloading||(n.info("request criticalSeg segId "+s+" at "+o+" from "+p.remotePeerId+" timeout "+l),p.requestDataById(s,o,!0)),this.requestingMap.set(o,p.remotePeerId)}}catch(e){c=!0,h=e}finally{try{!d&&v.return&&v.return()}finally{if(c)throw h}}}this.criticaltimeouter=setTimeout(this.criticaltimeout.bind(this,!0),1e3*l),this.targetPeers=[]}},{key:"onBufferManagerSegAdded",value:function(e){this._sendSegmentToSubscribers(e)}},{key:"onBufferManagerLost",value:function(e,t,r){this.currLostSN=e,r&&(this.nextLostSN=r),this.bitset.delete(e),this.bitCounts.delete(e)}},{key:"destroy",value:function(){i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"destroy",this).call(this),clearTimeout(this.waitForPeerTimer),this.logger.warn("destroy SnScheduler")}},{key:"_setupDC",value:function(e){var r=this;i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"_setupDC",this).call(this,e);var n=this.logger,o=this.config;e.on(s.default.DC_HAVE,(function(t){if(t.sn&&e.bitset&&t.sn&&t.sn>=0){var n=t.sn;if(e.bitset.has(n)||(e.bitset.add(n),r.bitset.has(n)||r._increBitCounts(n)),o.live){var i=n-20;i>0&&e.bitset.delete(i)}r.emit(s.default.SCH_DCHAVE,t.seg_id),(0,d.default)((function(){!o.live||r.criticalSeg||r.subscribeMode||r.checkPeers()}))}})).on(s.default.DC_LOST,(function(t){if(t.sn&&e.bitset){var n=t.sn;e.bitset.has(n)&&(e.bitset.delete(n),r._decreBitCounts(n))}})).on(s.default.DC_PIECE,(function(t){r.subscribers.length>0&&t.sn>r.subscriberEdgeSN&&(r._sendPieceToSubscribers(t.sn,t.seg_id,!1,!1,t),e.addStreamListener(!1,void 0,(function(e,t,n,i,a){n?r._sendPieceToSubscribers(e,t,!1,!0,i):r._sendPieceToSubscribers(e,t,!0,!1,i,a)})),r.subscriberEdgeSN=t.sn),t.ext&&t.ext.incompletes>=2||r.notifyAllPeers(t.sn,t.seg_id)})).on(s.default.DC_PIECE_NOT_FOUND,(function(t){var i=t.sn;r.criticalSeg&&r.criticalSeg.sn===i&&(1===r.criticalSeg.targetPeers.length?(clearTimeout(r.criticaltimeouter),n.info("DC_PIECE_NOT_FOUND "+i),r.criticalSeg=null,r.callbacks.onTimeout(r.stats,r.context,null)):r.criticalSeg.targetPeers=r.criticalSeg.targetPeers.filter((function(t){return t!==e.remotePeerId}))),e.bitset.delete(i),o.live&&e.resetContinuousHits(),r.requestingMap.delete(i),r._decreBitCounts(i),e.checkIfNeedChoke(!0)})).on(s.default.DC_RESPONSE,(function(s,o){var l=r.config,u=s.segId,d=s.sn,c=s.data,f=r.criticalSeg&&r.criticalSeg.segId===u;if(l.validateSegment(u,c))if(r.notifyAllPeers(d,u),i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"reportDCTraffic",r).call(r,d,s.size,o),f){n.info("receive criticalSeg seg_id "+u),clearTimeout(r.criticaltimeouter),r.criticaltimeouter=null,e.miss=0;var h=r.stats;h.tfirst=h.loading.first=Math.max(h.trequest,performance.now()),h.tload=h.loading.end=h.tfirst,h.loaded=h.total=c.byteLength,r.criticalSeg=null;var g=r.context.frag;g.fromPeerId=e.remotePeerId,g.loadByP2P=!0,r.callbacks.onSuccess({data:c,url:r.context.url},h,r.context),e.increContinuousHits(),l.maxSubscribeLevel&&l.live&&!r.subscribeMode&&e.continuousHits>7&&e.sendSubscribe()}else{if(r.bitset.has(d))return;var v=new a.default(d,u,c,e.remotePeerId);r.bufMgr.putSeg(v),r.updateLoaded(d)}else n.warn("segment "+u+" validate failed"),f&&(clearTimeout(r.criticaltimeouter),r.criticaltimeout());r.requestingMap.delete(d),!l.live||r.criticalSeg||r.subscribeMode||r.checkPeers()})).on(s.default.DC_REQUEST,(function(t){var i=t.sn;r.isUploader=!0,r.subscribers.includes(e.remotePeerId)&&(e.subscribeEdgeSN=i);var a=t.seg_id;a||(a=r.bufMgr.getSegIdBySN(i));var o=null;if(r.requestingMap.has(i)?o=r.getPeerLoadedMore(i):r.subscribeMode&&(o=r.subscribeParent),r.bufMgr.hasSegOfId(a)){n.info("found seg from bufMgr");var l=r.bufMgr.getSegById(a);e.sendBuffer(l.sn,l.segId,l.data,{from:"SegmentFromCache"})}else o&&o.downloading&&o.pieceMsg.sn===i?(n.info("target had "+o.bufArr.length+" packets, wait for remain from upstream "+o.remotePeerId),e.sendPartialBuffer(o.pieceMsg,o.bufArr,{from:"WaitForPartial",incompletes:1}),function(e,t){e.addStreamListener(!1,t.remotePeerId,(function(e,r,n,i,a){n?t.sendMsgPieceAbort(i,r,!0):t.send(i),a&&(t.uploading=!1)}))}(o,e)):i>=r.loadingSN?(n.info("peer request "+i+" wait for seg"),r.bufMgr.once(""+s.default.BM_ADDED_SN_+i,(function(t){t?(n.info("peer request notify seg "+t.sn),e.sendBuffer(t.sn,t.segId,t.data,{from:"NotifySegment"})):e.sendPieceNotFound(i,a)}))):e.sendPieceNotFound(i,a)})).on(s.default.DC_SUBSCRIBE,(function(){if(r.config.live){var t=r.subscribers.length,i=r.config.maxSubscribeLevel;if(0===i)e.sendSubscribeReject("subscribe disabled");else if(t>=25)e.sendSubscribeReject("too many subscribers");else if(r.subscribeLevel>=i)e.sendSubscribeReject("subscribe level reach "+r.subscribeLevel);else if(r.subscribers.indexOf(e.remotePeerId)>=0)e.sendSubscribeReject("subscriber already exist");else{if(t>=2){var a=[];if(r.subscribers.forEach((function(e){var t=r.peerManager.getPeer(e).uploadSpeed;t&&a.push(t)})),!l.default.evaluatePeersSpeed(a,r.estimatedSize))return void e.sendSubscribeReject("Insufficient upload capability")}r.subscribers.push(e.remotePeerId),n.info("subscribers add "+e.remotePeerId),e.sendSubscribeAccept(r.subscribeLevel)}}})).on(s.default.DC_UNSUBSCRIBE,(function(t){var i=r.subscribers.indexOf(e.remotePeerId);-1!==i&&(n.info("subscribers remove "+e.remotePeerId+" reason "+t.reason),r.subscribers.splice(i,1))})).on(s.default.DC_SUBSCRIBE_ACCEPT,(function(t){if(!r.subscribeMode){var n=t.level||0;r.subscribeMode=!0,r.subscribeLevel=n+1,r.subscribeParent=e,r.notifySubscribeLevel()}})).on(s.default.DC_SUBSCRIBE_REJECT,(function(t){n.warn("subscribe rejected, reason "+t.reason),e.resetContinuousHits()})).on(s.default.DC_SUBSCRIBE_LEVEL,(function(e){if(r.subscribeMode){var t=e.level||0;r.subscribeLevel=t+1,n.info("set subscribe level to "+r.subscribeLevel),r.notifySubscribeLevel()}}))}},{key:"_setupEngine",value:function(){var e=this;this.engine.on(s.default.FRAG_LOADING,(function(t,r,n){e.loadingSN=t,e.loadingSegId=r,e.isHlsV0&&n&&e.notifyAllPeers(t,r)})).on(s.default.FRAG_LOADED,(function(t,r,n,i,a){e.config.live&&(e.estimatedSize=n),!e.isHlsV0&&a&&e.notifyAllPeers(t,r),e.updateLoaded(t)})).on(s.default.FRAG_CHANGED,(function(t,r){e.updatePlaySN(t)}))}},{key:"notifyPeersLoaded",value:function(e){this.logger.info("notifyPeersLoaded "+e),this.waitForPeer&&(0===e?this.criticaltimeout():this.waitingPeers=e)}},{key:"_unsubscribe",value:function(e){this.logger.warn("unsubscribe to "+this.subscribeParent.remotePeerId),this.subscribeParent.sendUnsubscribe(e),this.subscribeParent=null,this.subscribeLevel=0,this.subscribeMode=!1,this.notifySubscribeLevel()}},{key:"_sendSegmentToSubscribers",value:function(e){var t=this,r=e.sn,n=e.segId,i=e.data;this.subscribers=this.subscribers.filter((function(e){var a=t.peerManager.getPeer(e);return a?(a.uploading||a.bitset.has(r)||(t.logger.info("send seg "+n+" to subscriber "+e),a.uploading=!0,a.sendBuffer(r,n,i,{from:"SegmentToSubscribers"}),a.bitset.add(r)),!0):(t.logger.info("subscribers remove "+e),!1)}))}},{key:"_sendPieceToSubscribers",value:function(e,t,r,n,i,a){var s=this;this.subscribers=this.subscribers.filter((function(o){var l=s.peerManager.getPeer(o);if(l){if(r&&e===l.pieceMsg.sn)l.send(i),a&&(l.uploading=!1,l.bitset.add(e));else if(!r)if(n)l.sendMsgPieceAbort(i,t,!0);else{if(l.uploading||e<=l.subscribeEdgeSN)return!0;l.subscribeEdgeSN=e,l.uploading=!0,l.pieceMsg=i,s.logger.info("downstream msg "+JSON.stringify(i)+" to subscriber "+o),l.sendMsgPiece(i,{from:"PieceToSubscribers",incompletes:1})}return!0}return s.logger.info("subscribers remove "+o),!1}))}}]),t}(o.default);t.default=h,e.exports=t.default},478:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},i=function e(t,r,n){null===t&&(t=Function.prototype);var i=Object.getOwnPropertyDescriptor(t,r);if(void 0===i){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,n)}if("value"in i)return i.value;var s=i.get;return void 0!==s?s.call(n):void 0},a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),s=_(r(299)),o=_(r(680)),l=_(r(788)),u=_(r(946)),d=_(r(277)),c=_(r(555)),f=_(r(327)),h=_(r(89)),g=_(r(578)),v=_(r(745)),p=_(r(828)),m=r(524),y=r(408),b=r(389),E=_(r(39)),S=_(r(91));function _(e){return e&&e.__esModule?e:{default:e}}if(window){if(window.p2ploadedHls)throw new Error("You are loading the p2p library multiple times. Please load it only once.");window.p2ploadedHls=!0}var T=function(e){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var i=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,r));i.config=Object.assign({},o.default,r),i.rangeTested=!1,i.lastLevel=0,i.hlsjs=e,i.config.waitForPeer&&(i.config.trickleICE=!0),i.HLSEvents=e.constructor.Events,i.config.isHlsV0="0"===e.constructor.version.split(".")[0],i.config.xhrSetup=e.config.xhrSetup;var a=i.config,l=a.token,u=a.channelId,d=a.segmentId,c=function(e){var t=s.default.parseURL(e);return""+(t.netLoc.substr(2)+t.path.substring(0,t.path.lastIndexOf(".")))},f=function(e,t,r,n){var i=r.split("?")[0];return i.startsWith("http")&&(i=i.split("://")[1]),n?i+"|"+n:""+i};u&&(c=i.makeChannelId(l,u),d||(f=function(e,t,r,n){return e+"-"+t})),d||(i.config.segmentId=f),e.config.segmentId=i.config.segmentId;var g=i.makeSignalId();e.on(i.HLSEvents.LEVEL_LOADED,(function t(r,a){var s=i.config,o=a.details,l=o.live;s.live=i.hlsjs.config.live=l,i.browserInfo=n({},i.commonBrowserInfo,{abr:i.multiBitrate||void 0,tag:s.tag||void 0,live:l,type:"hls"}),i.channel=c(e.url)+"|"+g+"["+h.default.VERSION+"]",i.browserInfo.device===m.device.PC_NATIVE&&(i.browserInfo=n({},i.browserInfo,{app:s.appName,bundle:s.appId}));var u=i.initLogger();i.hlsjs.config.logger=u,u.info("channel "+i.channel),l||(s.startSN=o.startSN,s.endSN=o.endSN,u.info("startSN "+o.startSN+" endSN "+o.endSN)),i.eventListened=!1,i._init(i.channel,i.browserInfo),e.off(i.HLSEvents.LEVEL_LOADED,t)}));return e.on(i.HLSEvents.MANIFEST_PARSED,(function t(r,n){var a=n.levels.length;i.multiBitrate=a>1,e.off(i.HLSEvents.MANIFEST_PARSED,t)})),i}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),a(t,null,[{key:"Events",get:function(){return f.default}}]),a(t,[{key:"_init",value:function(e,t){if(this.p2pEnabled){var r=this.multiBitrate||this.config.scheduledBySegId;this.hlsjs.config.p2pEnabled=this.p2pEnabled,this.hlsjs.config.sharePlaylist=this.config.sharePlaylist,this.bufMgr=new c.default(this,this.config,!r),this.hlsjs.config.bufMgr=this.bufMgr,this.media=this.hlsjs.media;var n=new g.default(this,this.config.token,encodeURIComponent(e),this.config.announce||"",t);this.fetcher=n;var i=void 0;i=r?new S.default(this,this.config):new E.default(this,this.config),this.tracker=new d.default(this,n,i,this.config),i.bufferManager=this.bufMgr,this.hlsjs.config.fLoader=l.default,this.config.sharePlaylist&&(this.hlsjs.config.pLoader=u.default),window.__p2p_loader__={scheduler:this.tracker.scheduler,fetcher:n,p2pBlackList:this.config.p2pBlackList,isHlsV0:this.config.isHlsV0},this.trackerTried=!1,this.eventListened||(this.hlsjs.on(this.HLSEvents.FRAG_LOADING,this._onFragLoading.bind(this)),this.hlsjs.on(this.HLSEvents.FRAG_LOADED,this._onFragLoaded.bind(this)),this.hlsjs.on(this.HLSEvents.FRAG_CHANGED,this._onFragChanged.bind(this)),this.hlsjs.on(this.HLSEvents.ERROR,this._onHlsError.bind(this)),this.eventListened=!0),this.setupWindowListeners(),this.trackerTried||this.tracker.connected||!this.config.p2pEnabled||(this.tracker.resumeP2P(),this.trackerTried=!0)}}},{key:"_onFragLoading",value:function(e,t){var r=t.frag,n=r.sn,i=r.segId;if(!(0,b.isBlockType)(r.url,this.config.p2pBlackList)){if(this.logger.debug("loading frag "+n),!i){var a=void 0;r._byteRange&&(a="bytes="+r._byteRange[0]+"-"+r._byteRange[1]);var s=r.url;i=t.frag.segId=this.config.segmentId(String(r.level),r.sn,s,a)}this.emit(f.default.FRAG_LOADING,n,i,t.frag.loadByHTTP)}}},{key:"_onFragLoaded",value:function(e,t){var r=t.frag,n=r.sn,i=r.level,a=r.segId,s=r.loaded,o=r.duration,l=this.config,u=this.logger;(0,b.isBlockType)(t.frag.url,l.p2pBlackList)||(this.emit(f.default.FRAG_LOADED,n,a,s,o,t.frag.loadByHTTP,i),!this.rangeTested&&l.useHttpRange&&((0,y.performRangeRequest)(t.frag.url,"bytes=0-0",l.xhrSetup).then((function(){l.httpRangeSupported=!0,u.info("http range is supported"),l.httpLoadTime-=1.5,l.httpLoadTime<1.5&&(l.httpLoadTime=1.5),l.simultaneousTargetPeers=1})).catch((function(){l.httpRangeSupported=!1,u.warn("http range is not supported")})),this.rangeTested=!0))}},{key:"_onFragChanged",value:function(e,t){if(!(0,b.isBlockType)(t.frag.url,this.config.p2pBlackList)){this.logger.debug("frag changed: "+t.frag.sn);var r=t.frag,n=r.sn,i=r.duration;this.emit(f.default.FRAG_CHANGED,n,i)}}},{key:"_onHlsError",value:function(e,t){var r=this.logger;t.fatal?r.error(t.type+" details "+t.details+" reason "+t.reason):r.warn(t.type+" details "+t.details+" reason "+t.reason);var n=this.hlsjs.constructor.ErrorDetails;switch(t.details){case n.BUFFER_STALLED_ERROR:this.fetcher&&this.fetcher.increRebuffers();break;case n.BUFFER_INCOMPATIBLE_CODECS_ERROR:case n.BUFFER_ADD_CODEC_ERROR:case n.FRAG_PARSING_ERROR:case n.BUFFER_APPENDING_ERROR:case n.BUFFER_APPEND_ERROR:this.fetcher&&(this.fetcher.exptMsg=t.details+" "+t.err+" fatal "+t.fatal+" ua "+navigator.userAgent);break;case n.INTERNAL_EXCEPTION:t.error||(t.error={}),this.fetcher&&(this.fetcher.errsInternalExpt++,this.fetcher.exptMsg=t.error.message+" event "+t.event+" ua "+navigator.userAgent),r.error("INTERNAL_EXCEPTION event "+t.event+" err "+t.error.message),this.emit(f.default.EXCEPTION,(0,p.default)(t.error,"HLSJS_EXPT"))}}},{key:"getExtraForStats",value:function(){var e=i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getExtraForStats",this).call(this);return this.config.live||(e.pos=Math.round(this.media.currentTime)),this.multiBitrate&&this.currentLevel!==this.lastLevel&&(e.level=this.currentLevel+"",this.lastLevel=this.currentLevel),e}},{key:"getExtraForPeersRequest",value:function(){var e=i(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getExtraForPeersRequest",this).call(this);return this.multiBitrate&&(e.level=this.currentLevel+""),e}},{key:"disableP2P",value:function(){this.logger&&this.logger.warn("disable P2P"),this.p2pEnabled&&(this.p2pEnabled=!1,this.config.p2pEnabled=this.hlsjs.config.p2pEnabled=this.p2pEnabled,this.tracker&&(this.tracker.stopP2P(),this.tracker={},this.fetcher=null,this.bufMgr.destroy(),this.bufMgr=null,this.hlsjs.config.fLoader=this.hlsjs.config.pLoader=this.hlsjs.constructor.DefaultConfig.loader))}},{key:"currentLevel",get:function(){var e=this.hlsjs.currentLevel;return e>=0?e:0}}]),t}(v.default);window&&(window.P2pEngine=window.P2pEngineHls=window.P2PEngineHls=T),t.default=T,e.exports=t.default},715:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=s(r(478)),a=s(r(322));function s(e){return e&&e.__esModule?e:{default:e}}var o={maxBufferLength:8},l={maxBufferLength:40},u=function(e){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=e.p2pConfig||{},n=!1===r.live?l:o,s=JSON.parse(JSON.stringify(n));for(var u in s.liveSyncDurationCount=10,s.maxBufferSize=0,s.enableWorker=!1,e)"p2pConfig"!==u&&(s[u]=e[u]);var d=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,s));return d._restartEvent=function(){d.restartP2P()},i.default.isSupported()&&(d._p2pEngine=new i.default(d,r),d._p2pEngine.on(i.default.Events.RESTART_P2P,d._restartEvent)),d.on(a.default.Events.DESTROYING,(function(){d._p2pEngine&&(d._p2pEngine.removeListener(i.default.Events.RESTART_P2P,d._restartEvent),d._p2pEngine.destroy(),d._p2pEngine.hlsjs=null,d._p2pEngine=null)})),d}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,null,[{key:"P2PEvents",get:function(){return i.default.Events}}]),n(t,[{key:"enableP2P",value:function(){this._p2pEngine&&(this._p2pEngine=this._p2pEngine.enableP2P())}},{key:"disableP2P",value:function(){this._p2pEngine&&this._p2pEngine.disableP2P()}},{key:"restartP2P",value:function(){var e=this;this._p2pEngine&&(this._p2pEngine.disableP2P(),setTimeout((function(){e.enableP2P()}),2e3),this._p2pEngine.removeListener(i.default.Events.RESTART_P2P,this._restartEvent))}},{key:"p2pEngine",get:function(){return this._p2pEngine}}]),t}(a.default);u.engineVersion=i.default.version,u.protocolVersion=i.default.protocolVersion,u.WEBRTC_SUPPORT=i.default.isSupported(),t.default=u,e.exports=t.default},946:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=l(r(648)),a=l(r(91)),s=l(r(824)),o=r(389);function l(e){return e&&e.__esModule?e:{default:e}}var u=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var r=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));r.logger=e.logger;var n=window.__p2p_loader__.scheduler;return r.isHlsV0=e.isHlsV0,r.xhrLoader=new e.loader(e),r.p2pEnabled=e.p2pEnabled,r.scheduler=n,r.multiBitrate=r.scheduler instanceof a.default,r.stats=r.xhrLoader.stats||(0,o.createLoadStats)(),r}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"destroy",value:function(){this.xhrLoader.destroy()}},{key:"abort",value:function(){this.xhrLoader.abort()}},{key:"load",value:function(e,t,r){var n=this,i=this.logger,a=e.url,l=a.split("?")[0],u=r.onSuccess;if(r.onSuccess=function(e,t,r){n.scheduler.broadcastPlaylist(l,e.data),u(e,t,r)},this.scheduler.playlistInfo.has(l)){var d=this.scheduler.getPlaylistFromPeer(l);if(d&&d.data){var c=d.data,f=d.seq;i.info("got playlist from peer seq "+f),(0,o.updateLoadStats)(this.stats,c.length);var h={url:a,data:c};return void(0,s.default)((function(){r.onSuccess(h,n.stats,e)}))}}this.xhrLoader.load(e,t,r)}}]),t}(i.default);t.default=u,e.exports=t.default},297:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var n=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),i=s(r(89)),a=s(r(327));function s(e){return e&&e.__esModule?e:{default:e}}var o=function(e){function t(e,r,n,i,a){var s=arguments.length>5&&void 0!==arguments[5]?arguments[5]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,r,n,i,a,s));return o.continuousHits=0,o.subscribeEdgeSN=0,o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"resetContinuousHits",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.logger.info("reset "+this.remotePeerId+" continuousHits"),this.continuousHits=e}},{key:"increContinuousHits",value:function(){this.continuousHits++}},{key:"sendSubscribe",value:function(){this.sendJson({event:a.default.DC_SUBSCRIBE})}},{key:"sendUnsubscribe",value:function(e){this.resetContinuousHits(),this.sendJson({event:a.default.DC_UNSUBSCRIBE,reason:e})}},{key:"sendSubscribeReject",value:function(e){this.sendJson({event:a.default.DC_SUBSCRIBE_REJECT,reason:e})}},{key:"sendSubscribeAccept",value:function(e){this.sendJson({event:a.default.DC_SUBSCRIBE_ACCEPT,level:e})}},{key:"sendSubscribeLevel",value:function(e){this.sendJson({event:a.default.DC_SUBSCRIBE_LEVEL,level:e})}}]),t}(i.default);t.default=o,e.exports=t.default},140:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();var n=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return r(e,null,[{key:"evaluatePeersSpeed",value:function(e,t){var r=t/3500,n=r,i=1.05*r,a=0;return e.forEach((function(e){if(e){if(e<n)return!1;a+=e}})),a/e.length>=i}}]),e}();t.default=n,e.exports=t.default},389:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isBlockType=function(e,t){var r=a.default.parseURL(e),n=r.path.substring(r.path.lastIndexOf(".")+1);return-1!==t.indexOf(n)},t.createLoadStats=function(){var e=performance.now();return{trequest:e,tfirst:0,tload:0,aborted:!1,loaded:0,retry:0,total:0,chunkCount:0,bwEstimate:0,loading:{start:e,first:0,end:0},parsing:{start:0,end:0},buffering:{start:0,first:0,end:0}}},t.updateLoadStats=function(e,t){var r,n,i,a,s,o=performance.now();r=o-300,n=o-200,i=o,e.trequest=r,e.tfirst=n,e.tload=i,e.loading={first:r,start:n,end:i},a=s=t,e.loaded=a,e.total=s};var n,i=r(299),a=(n=i)&&n.__esModule?n:{default:n}}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var a=t[n]={id:n,loaded:!1,exports:{}};return e[n](a,a.exports,r),a.loaded=!0,a.exports}return r.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),r(715)})()));