@byteplus/veplayer 1.18.0-rc.8 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +161 -0
- package/index.min.js +2 -2
- package/lite.cjs +2 -2
- package/lite.d.ts +7 -0
- package/lite.esm.mjs +2 -2
- package/lite.min.js +2 -2
- package/package.json +1 -1
- package/plugin/modules/DashAbralgo.mjs +1 -1
- package/plugin/modules/XGVideo.mjs +1 -1
- package/plugin/modules/danmuMask.mjs +1 -1
- package/plugin/modules/danmujs.mjs +1 -1
- package/plugin/modules/dash.mjs +1 -1
- package/plugin/modules/flv.mjs +1 -1
- package/plugin/modules/hls.mjs +1 -1
- package/plugin/modules/hlsEncrypt.mjs +1 -1
- package/plugin/modules/hlsjs.mjs +1 -1
- package/plugin/modules/hlsjsPro.mjs +1 -1
- package/plugin/modules/mp4Encrypt.mjs +1 -1
- package/plugin/modules/preloader.mjs +1 -1
- package/plugin/modules/streamprobe.mjs +1 -1
- package/plugin/modules/vestrategy.mjs +2 -2
- package/plugin/modules/vestrategy_adapt_range.mjs +2 -2
- package/plugin/modules/vestrategy_h265.mjs +2 -2
- package/plugin/modules/vestrategy_preload.mjs +2 -2
- package/plugin/vestrategy.js +1 -1
- package/plugin/vestrategy_preload.js +1 -1
package/plugin/modules/hls.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// @byteplus/veplayer@1.18.0
|
|
1
|
+
// @byteplus/veplayer@1.18.0 Built @9/1/2026, 4:36:00 PM
|
|
2
2
|
function _iterableToArrayLimit$1(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,a,s,o=[],u=!0,c=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=a.call(r)).done)&&(o.push(n.value),o.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return o}}function ownKeys$2(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 _objectSpread2$2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys$2(Object(r),!0).forEach((function(t){_defineProperty$3(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys$2(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _regeneratorRuntime$1(){_regeneratorRuntime$1=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",o=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function c(e,t,r,i){var a=t&&t.prototype instanceof f?t:f,s=Object.create(a.prototype),o=new P(i||[]);return n(s,"_invoke",{value:b(e,r,o)}),s}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var d={};function f(){}function h(){}function p(){}var _={};u(_,a,(function(){return this}));var y=Object.getPrototypeOf,v=y&&y(y(A([])));v&&v!==t&&r.call(v,a)&&(_=v);var m=p.prototype=f.prototype=Object.create(_);function g(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){function i(n,a,s,o){var u=l(e[n],e,a);if("throw"!==u.type){var c=u.arg,d=c.value;return d&&"object"==typeof d&&r.call(d,"__await")?t.resolve(d.__await).then((function(e){i("next",e,s,o)}),(function(e){i("throw",e,s,o)})):t.resolve(d).then((function(e){c.value=e,s(c)}),(function(e){return i("throw",e,s,o)}))}o(u.arg)}var a;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){i(e,r,t,n)}))}return a=a?a.then(n,n):n()}})}function b(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var o=S(s,r);if(o){if(o===d)continue;return o}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var i=l(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,d;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function P(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function A(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:x}}function x(){return{value:void 0,done:!0}}return h.prototype=p,n(m,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:h,configurable:!0}),h.displayName=u(p,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,u(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(E.prototype),u(E.prototype,s,(function(){return this})),e.AsyncIterator=E,e.async=function(t,r,n,i,a){void 0===a&&(a=Promise);var s=new E(c(t,r,n,i),a);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},g(m),u(m,o,"Generator"),u(m,a,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=A,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var o=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(o&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var s=a?a.completion:{};return s.type=e,s.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;k(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:A(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},e}function _typeof$2(e){return(_typeof$2="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})(e)}function asyncGeneratorStep$1(e,t,r,n,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void r(e)}o.done?t(u):Promise.resolve(u).then(n,i)}function _asyncToGenerator$1(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var a=e.apply(t,r);function s(e){asyncGeneratorStep$1(a,n,i,s,o,"next",e)}function o(e){asyncGeneratorStep$1(a,n,i,s,o,"throw",e)}s(void 0)}))}}function _classCallCheck$3(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$3(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,_toPropertyKey$3(n.key),n)}}function _createClass$3(e,t,r){return t&&_defineProperties$3(e.prototype,t),r&&_defineProperties$3(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty$3(e,t,r){return(t=_toPropertyKey$3(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _inherits$2(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_setPrototypeOf$2(e,t)}function _getPrototypeOf$2(e){return(_getPrototypeOf$2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf$2(e,t){return(_setPrototypeOf$2=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct$2(){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}}function _objectWithoutPropertiesLoose$1(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}function _objectWithoutProperties$1(e,t){if(null==e)return{};var r,n,i=_objectWithoutPropertiesLoose$1(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function _assertThisInitialized$2(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn$2(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized$2(e)}function _createSuper$2(e){var t=_isNativeReflectConstruct$2();return function(){var r,n=_getPrototypeOf$2(e);if(t){var i=_getPrototypeOf$2(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return _possibleConstructorReturn$2(this,r)}}function _slicedToArray$1(e,t){return _arrayWithHoles$1(e)||_iterableToArrayLimit$1(e,t)||_unsupportedIterableToArray$3(e,t)||_nonIterableRest$1()}function _toConsumableArray$2(e){return _arrayWithoutHoles$2(e)||_iterableToArray$2(e)||_unsupportedIterableToArray$3(e)||_nonIterableSpread$2()}function _arrayWithoutHoles$2(e){if(Array.isArray(e))return _arrayLikeToArray$3(e)}function _arrayWithHoles$1(e){if(Array.isArray(e))return e}function _iterableToArray$2(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray$3(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$3(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray$3(e,t):void 0}}function _arrayLikeToArray$3(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _nonIterableSpread$2(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _nonIterableRest$1(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _toPrimitive$3(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey$3(e){var t=_toPrimitive$3(e,"string");return"symbol"==typeof t?t:String(t)}function ownKeys$1(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 _objectSpread2$1(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys$1(Object(r),!0).forEach((function(t){_defineProperty$2(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys$1(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _typeof$1(e){return(_typeof$1="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})(e)}function _classCallCheck$2(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$2(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,_toPropertyKey$2(n.key),n)}}function _createClass$2(e,t,r){return t&&_defineProperties$2(e.prototype,t),r&&_defineProperties$2(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty$2(e,t,r){return(t=_toPropertyKey$2(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _toConsumableArray$1(e){return _arrayWithoutHoles$1(e)||_iterableToArray$1(e)||_unsupportedIterableToArray$2(e)||_nonIterableSpread$1()}function _arrayWithoutHoles$1(e){if(Array.isArray(e))return _arrayLikeToArray$2(e)}function _iterableToArray$1(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray$2(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$2(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray$2(e,t):void 0}}function _arrayLikeToArray$2(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _nonIterableSpread$1(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _toPrimitive$2(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey$2(e){var t=_toPrimitive$2(e,"string");return"symbol"==typeof t?t:String(t)}function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var eventemitter3={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),u=r?r+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],o]:e._events[u].push(o):(e._events[u]=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 u,c,l=this._events[o],d=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),d){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,n),!0;case 4:return l.fn.call(l.context,t,n,i),!0;case 5:return l.fn.call(l.context,t,n,i,a),!0;case 6:return l.fn.call(l.context,t,n,i,a,s),!0}for(c=1,u=new Array(d-1);c<d;c++)u[c-1]=arguments[c];l.fn.apply(l.context,u)}else{var f,h=l.length;for(c=0;c<h;c++)switch(l[c].once&&this.removeListener(e,l[c].fn,void 0,!0),d){case 1:l[c].fn.call(l[c].context);break;case 2:l[c].fn.call(l[c].context,t);break;case 3:l[c].fn.call(l[c].context,t,n);break;case 4:l[c].fn.call(l[c].context,t,n,i);break;default:if(!u)for(f=1,u=new Array(d-1);f<d;f++)u[f-1]=arguments[f];l[c].fn.apply(l[c].context,u)}}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 u=0,c=[],l=o.length;u<l;u++)(o[u].fn!==t||i&&!o[u].once||n&&o[u].context!==n)&&c.push(o[u]);c.length?this._events[a]=1===c.length?c[0]:c: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}(eventemitter3);var eventemitter3Exports=eventemitter3.exports,EventEmitter=getDefaultExportFromCjs(eventemitter3Exports),XG_DEBUG_OPEN="undefined"!=typeof window&&window.location&&window.location.href.indexOf("xgplayerdebugger=1")>-1,STYLE={info:"color: #525252; background-color: #90ee90;",error:"color: #525252; background-color: red;",warn:"color: #525252; background-color: yellow; "},XGTAG="%c[xgplayer]",XG_DEBUG={config:{debug:XG_DEBUG_OPEN?3:0},logInfo:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];this.config.debug>=3&&(t=console).log.apply(t,[XGTAG,STYLE.info,e].concat(n))},logWarn:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];this.config.debug>=1&&(t=console).warn.apply(t,[XGTAG,STYLE.warn,e].concat(n))},logError:function(e){var t;if(!(this.config.debug<1)){for(var r=this.config.debug>=2?"trace":"error",n=arguments.length,i=new Array(n>1?n-1:0),a=1;a<n;a++)i[a-1]=arguments[a];(t=console)[r].apply(t,[XGTAG,STYLE.error,e].concat(i))}}},XgplayerTimeRange=function(){function e(t){_classCallCheck$2(this,e),this.bufferedList=t}return _createClass$2(e,[{key:"start",value:function(e){return this.bufferedList[e].start}},{key:"end",value:function(e){return this.bufferedList[e].end}},{key:"length",get:function(){return this.bufferedList.length}}]),e}(),util={};function checkIsIn(e,t){for(var r=0,n=t.length;r<n;r++)if(e.indexOf(t[r])>-1)return!0;return!1}util.createDom=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"div",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=document.createElement(e);return i.className=n,i.innerHTML=t,Object.keys(r).forEach((function(t){var n=t,a=r[t];"video"===e||"audio"===e||"live-video"===e?a&&i.setAttribute(n,a):i.setAttribute(n,a)})),i},util.createDomFromHtml=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";try{var n=document.createElement("div");n.innerHTML=e;var i=n.children;return n=null,i.length>0?(i=i[0],r&&util.addClass(i,r),t&&Object.keys(t).forEach((function(e){i.setAttribute(e,t[e])})),i):null}catch(e){return XG_DEBUG.logError("util.createDomFromHtml",e),null}},util.hasClass=function(e,t){if(!e||!t)return!1;try{return Array.prototype.some.call(e.classList,(function(e){return e===t}))}catch(n){var r=e.className&&"object"===_typeof$1(e.className)?e.getAttribute("class"):e.className;return r&&!!r.match(new RegExp("(\\s|^)"+t+"(\\s|$)"))}},util.addClass=function(e,t){if(e&&t)try{t.replace(/(^\s+|\s+$)/g,"").split(/\s+/g).forEach((function(t){t&&e.classList.add(t)}))}catch(r){util.hasClass(e,t)||(e.className&&"object"===_typeof$1(e.className)?e.setAttribute("class",e.getAttribute("class")+" "+t):e.className+=" "+t)}},util.removeClass=function(e,t){if(e&&t)try{t.replace(/(^\s+|\s+$)/g,"").split(/\s+/g).forEach((function(t){t&&e.classList.remove(t)}))}catch(r){util.hasClass(e,t)&&t.split(/\s+/g).forEach((function(t){var r=new RegExp("(\\s|^)"+t+"(\\s|$)");e.className&&"object"===_typeof$1(e.className)?e.setAttribute("class",e.getAttribute("class").replace(r," ")):e.className=e.className.replace(r," ")}))}},util.toggleClass=function(e,t){e&&t.split(/\s+/g).forEach((function(t){util.hasClass(e,t)?util.removeClass(e,t):util.addClass(e,t)}))},util.classNames=function(){for(var e=arguments,t=[],r=function(r){"String"===util.typeOf(e[r])?t.push(e[r]):"Object"===util.typeOf(e[r])&&Object.keys(e[r]).map((function(n){e[r][n]&&t.push(n)}))},n=0;n<arguments.length;n++)r(n);return t.join(" ")},util.findDom=function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:document,r=arguments.length>1?arguments[1]:void 0;try{e=t.querySelector(r)}catch(n){XG_DEBUG.logError("util.findDom",n),0===r.indexOf("#")&&(e=t.getElementById(r.slice(1)))}return e},util.getCss=function(e,t){return e.currentStyle?e.currentStyle[t]:document.defaultView.getComputedStyle(e,!1)[t]},util.padStart=function(e,t,r){for(var n=String(r),i=t>>0,a=Math.ceil(i/n.length),s=[],o=String(e);a--;)s.push(n);return s.join("").substring(0,i-o.length)+o},util.format=function(e){if(window.isNaN(e))return"";e=Math.round(e);var t=util.padStart(Math.floor(e/3600),2,0),r=util.padStart(Math.floor((e-3600*t)/60),2,0),n=util.padStart(Math.floor(e-3600*t-60*r),2,0);return("00"===t?[r,n]:[t,r,n]).join(":")},util.event=function(e){if(e.touches){var t=e.touches[0]||e.changedTouches[0];e.clientX=t.clientX||0,e.clientY=t.clientY||0,e.offsetX=t.pageX-t.target.offsetLeft,e.offsetY=t.pageY-t.target.offsetTop}e._target=e.target||e.srcElement},util.typeOf=function(e){return Object.prototype.toString.call(e).match(/([^\s.*]+)(?=]$)/g)[0]},util.deepCopy=function(e,t){if("Object"===util.typeOf(t)&&"Object"===util.typeOf(e))return Object.keys(t).forEach((function(r){"Object"!==util.typeOf(t[r])||t[r]instanceof Node?"Array"===util.typeOf(t[r])?e[r]="Array"===util.typeOf(e[r])?e[r].concat(t[r]):t[r]:e[r]=t[r]:void 0===e[r]||void 0===e[r]?e[r]=t[r]:util.deepCopy(e[r],t[r])})),e},util.deepMerge=function(e,t){return Object.keys(t).map((function(r){var n;"Array"===util.typeOf(t[r])&&"Array"===util.typeOf(e[r])?"Array"===util.typeOf(e[r])&&(n=e[r]).push.apply(n,_toConsumableArray$1(t[r])):util.typeOf(e[r])!==util.typeOf(t[r])||null===e[r]||"Object"!==util.typeOf(e[r])||t[r]instanceof window.Node?null!==t[r]&&(e[r]=t[r]):util.deepMerge(e[r],t[r])})),e},util.getBgImage=function(e){var t=(e.currentStyle||window.getComputedStyle(e,null)).backgroundImage;if(!t||"none"===t)return"";var r=document.createElement("a");return r.href=t.replace(/url\("|"\)/g,""),r.href},util.copyDom=function(e){if(e&&1===e.nodeType){var t=document.createElement(e.tagName);return Array.prototype.forEach.call(e.attributes,(function(e){t.setAttribute(e.name,e.value)})),e.innerHTML&&(t.innerHTML=e.innerHTML),t}return""},util.setInterval=function(e,t,r,n){e._interval[t]||(e._interval[t]=window.setInterval(r.bind(e),n))},util.clearInterval=function(e,t){clearInterval(e._interval[t]),e._interval[t]=null},util.setTimeout=function(e,t,r){e._timers||(e._timers=[]);var n=setTimeout((function(){t(),util.clearTimeout(e,n)}),r);return e._timers.push(n),n},util.clearTimeout=function(e,t){var r=e._timers;if("Array"===util.typeOf(r)){for(var n=0;n<r.length;n++)if(r[n]===t){r.splice(n,1),clearTimeout(t);break}}else clearTimeout(t)},util.clearAllTimers=function(e){var t=e._timers;"Array"===util.typeOf(t)&&(t.map((function(e){clearTimeout(e)})),e._timerIds=[])},util.createImgBtn=function(e,t,r,n){var i,a,s,o=util.createDom("xg-".concat(e),"",{},"xgplayer-".concat(e,"-img"));(o.style.backgroundImage='url("'.concat(t,'")'),r&&n)&&(["px","rem","em","pt","dp","vw","vh","vm","%"].every((function(e){return!(r.indexOf(e)>-1&&n.indexOf(e)>-1)||(i=parseFloat(r.slice(0,r.indexOf(e)).trim()),a=parseFloat(n.slice(0,n.indexOf(e)).trim()),s=e,!1)})),o.style.width="".concat(i).concat(s),o.style.height="".concat(a).concat(s),o.style.backgroundSize="".concat(i).concat(s," ").concat(a).concat(s),o.style.margin="start"===e?"-".concat(a/2).concat(s," auto auto -").concat(i/2).concat(s):"auto 5px auto 5px");return o},util.Hex2RGBA=function(e,t){var r=[];if(/^\#[0-9A-F]{3}$/i.test(e)){var n="#";e.replace(/[0-9A-F]/gi,(function(e){n+=e+e})),e=n}return/^#[0-9A-F]{6}$/i.test(e)?(e.replace(/[0-9A-F]{2}/gi,(function(e){r.push(parseInt(e,16))})),"rgba(".concat(r.join(","),", ").concat(t,")")):"rgba(255, 255, 255, 0.1)"},util.getFullScreenEl=function(){return document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement},util.checkIsFunction=function(e){return e&&"function"==typeof e},util.checkIsObject=function(e){return null!==e&&"object"===_typeof$1(e)},util.hide=function(e){e.style.display="none"},util.show=function(e,t){e.style.display=t||"block"},util.isUndefined=function(e){if(null==e)return!0},util.isNotNull=function(e){return!(null==e)},util.setStyleFromCsstext=function(e,t){t&&("String"===util.typeOf(t)?t.replace(/\s+/g,"").split(";").map((function(t){if(t){var r=t.split(":");r.length>1&&(e.style[r[0]]=r[1])}})):Object.keys(t).map((function(r){e.style[r]=t[r]})))},util.filterStyleFromText=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["width","height","top","left","bottom","right","position","z-index","padding","margin","transform"],r=e.style.cssText;if(!r)return{};var n=r.replace(/\s+/g,"").split(";"),i={},a={};return n.map((function(e){if(e){var r=e.split(":");r.length>1&&(checkIsIn(r[0],t)?i[r[0]]=r[1]:a[r[0]]=r[1])}})),e.setAttribute("style",""),Object.keys(a).map((function(t){e.style[t]=a[t]})),i},util.getStyleFromCsstext=function(e){var t=e.style.cssText;if(!t)return{};var r=t.replace(/\s+/g,"").split(";"),n={};return r.map((function(e){if(e){var t=e.split(":");t.length>1&&(n[t[0]]=t[1])}})),n},util.preloadImg=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};if(e){var n=new window.Image;n.onload=function(e){n=null,t&&t(e)},n.onerror=function(e){n=null,r&&r(e)},n.src=e}},util.stopPropagation=function(e){e&&e.stopPropagation()},util.scrollTop=function(){return window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop||0},util.scrollLeft=function(){return window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0},util.checkTouchSupport=function(){return"ontouchstart"in window},util.getBuffered2=function(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:.5,r=[],n=0;n<e.length;n++)r.push({start:e.start(n)<.5?0:e.start(n),end:e.end(n)});r.sort((function(e,t){var r=e.start-t.start;return r||t.end-e.end}));var i=[];if(t)for(var a=0;a<r.length;a++){var s=i.length;if(s){var o=i[s-1].end;r[a].start-o<t?r[a].end>o&&(i[s-1].end=r[a].end):i.push(r[a])}else i.push(r[a])}else i=r;return new XgplayerTimeRange(i)},util.getEventPos=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;return e.touches&&e.touches.length>0&&(e=e.touches[0]),{x:e.x/t,y:e.y/t,clientX:e.clientX/t,clientY:e.clientY/t,offsetX:e.offsetX/t,offsetY:e.offsetY/t,pageX:e.pageX/t,pageY:e.pageY/t}},util.requestAnimationFrame=function(e){var t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame;if(t)return t(e)},util.getHostFromUrl=function(e){if("String"!==util.typeOf(e))return"";var t=e.split("/"),r="";return t.length>3&&t[2]&&(r=t[2]),r},util.cancelAnimationFrame=function(e){var t=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.cancelRequestAnimationFrame;t&&t(e)},util.isMSE=function(e){return e.media&&(e=e.media),!!(e&&e instanceof HTMLMediaElement)&&(/^blob/.test(e.currentSrc)||/^blob/.test(e.src))},util.isBlob=function(e){return"string"==typeof e&&/^blob/.test(e)},util.generateSessionId=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=(new Date).getTime();try{e=parseInt(e)}catch(t){e=0}return t+=e,window.performance&&"function"==typeof window.performance.now&&(t+=parseInt(window.performance.now())),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var r=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"===e?r:3&r|8).toString(16)}))},util.createEvent=function(e){var t;return"function"==typeof window.Event?t=new Event(e):(t=document.createEvent("Event")).initEvent(e,!0,!0),t},util.adjustTimeByDuration=function(e,t,r){return t&&e&&(e>t||r&&e<t)?t:e},util.createPositionBar=function(e,t){var r=util.createDom("xg-bar","",{"data-index":-1},e);return t.appendChild(r),r},util.getTransformStyle=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{x:0,y:0,scale:1,rotate:0},t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r={scale:"".concat(e.scale||1),translate:"".concat(e.x||0,"%, ").concat(e.y||0,"%"),rotate:"".concat(e.rotate||0,"deg")};return Object.keys(r).forEach((function(e){var n=new RegExp("".concat(e,"\\([^\\(]+\\)"),"g"),i="".concat(e,"(").concat(r[e],")");n.test(t)?(n.lastIndex=-1,t=t.replace(n,i)):t+="".concat(i," ")})),t},util.convertDeg=function(e){return Math.abs(e)<=1?360*e:e%360},util.getIndexByTime=function(e,t){var r=t.length,n=-1;if(r<1)return n;if(e<=t[0].end||r<2)n=0;else if(e>t[r-1].end)n=r-1;else for(var i=1;i<r;i++)if(e>t[i-1].end&&e<=t[i].end){n=i;break}return n},util.getOffsetCurrentTime=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:-1,n=-1;if((n=r>=0&&r<t.length?r:util.getIndexByTime(e,t))<0)return-1;var i=t.length,a=t[n],s=a.start,o=a.end,u=a.cTime,c=a.offset;return e<s?u:e>=s&&e<=o?e-c:e>o&&n>=i-1?o:-1},util.getCurrentTimeByOffset=function(e,t){var r=-1;if(!t||t.length<0)return e;for(var n=0;n<t.length;n++)if(e<=t[n].duration){r=n;break}if(-1!==r){var i=t[r].start;return r-1<0?i+e:i+(e-t[r-1].duration)}return e};var version="3.0.23-rc.3",ERROR_MAP={1:5101,2:5102,3:5103,4:5104,5:5105,6:5106},Errors=_createClass$2((function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{errorType:"",errorCode:0,errorMessage:"",originError:"",ext:{},mediaError:null};_classCallCheck$2(this,e);var n=t&&t.i18n?t.i18n.ERROR_TYPES:null;if(t.media){var i=r.mediaError?r.mediaError:t.media.error||{},a=t.duration,s=t.currentTime,o=t.ended,u=t.src,c=t.currentSrc,l=t.media,d=l.readyState,f=l.networkState,h=r.errorCode||i.code;ERROR_MAP[h]&&(h=ERROR_MAP[h]);var p={playerVersion:version,currentTime:s,duration:a,ended:o,readyState:d,networkState:f,src:u||c,errorType:r.errorType,errorCode:h,message:r.errorMessage||i.message,mediaError:i,originError:r.originError?r.originError.stack:"",host:util.getHostFromUrl(u||c)};return r.ext&&Object.keys(r.ext).map((function(e){p[e]=r.ext[e]})),p}if(arguments.length>1){for(var _={playerVersion:version,domain:document.domain},y=["errorType","currentTime","duration","networkState","readyState","src","currentSrc","ended","errd","errorCode","mediaError"],v=0;v<arguments.length;v++)_[y[v]]=arguments[v];return _.ex=n?(n[arguments[0]]||{}).msg:"",_}})),ERROR="error",DESTROY="destroy",URL_CHANGE="urlchange",SWITCH_SUBTITLE="switch_subtitle";function callHandler(e,t,r){for(var n=arguments.length,i=new Array(n>3?n-3:0),a=3;a<n;a++)i[a-3]=arguments[a];var s=t.call.apply(t,[e].concat(i));r&&"function"==typeof r&&(s&&s.then?s.then((function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];r.call.apply(r,[e].concat(n))})):r.call.apply(r,[e].concat(i)))}function hook(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{pre:null,next:null};return this.__hooks||(this.__hooks={}),!this.__hooks[e]&&(this.__hooks[e]=null),function(){var n=arguments,i=this;if(r.pre)try{var a;(a=r.pre).call.apply(a,[this].concat(Array.prototype.slice.call(arguments)))}catch(t){throw t.message="[pluginName: ".concat(this.pluginName,":").concat(e,":pre error] >> ").concat(t.message),t}if(this.__hooks&&this.__hooks[e])try{var s=runHooks.apply(void 0,[this,e,t].concat(Array.prototype.slice.call(arguments)));s?s.then?s.then((function(e){!1!==e&&callHandler.apply(void 0,[i,t,r.next].concat(_toConsumableArray$1(n)))})).catch((function(e){throw e})):callHandler.apply(void 0,[this,t,r.next].concat(Array.prototype.slice.call(arguments))):void 0===s&&callHandler.apply(void 0,[this,t,r.next].concat(Array.prototype.slice.call(arguments)))}catch(t){throw t.message="[pluginName: ".concat(this.pluginName,":").concat(e,"] >> ").concat(t.message),t}else callHandler.apply(void 0,[this,t,r.next].concat(Array.prototype.slice.call(arguments)))}.bind(this)}function findHookIndex(e,t){var r=this.__hooks;if(!r||!Array.isArray(r[e]))return-1;for(var n=r[e],i=0;i<n.length;i++)if(n[i]===t)return i;return-1}function useHooks(e,t){var r=this.__hooks;if(r)return r.hasOwnProperty(e)?(Array.isArray(r[e])||(r[e]=[]),-1===findHookIndex.call(this,e,t)&&r[e].push(t),!0):(console.warn("has no supported hook which name [".concat(e,"]")),!1)}function removeHooks(e,t){var r=this.__hooks;if(r)if(Array.isArray(r[e])){var n=r[e],i=findHookIndex.call(this,e,t);-1!==i&&n.splice(i,1)}else r[e]&&(r[e]=null)}function hooksDescriptor(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];e.__hooks={},t&&t.map((function(t){e.__hooks[t]=null})),Object.defineProperty(e,"hooks",{get:function(){return e.__hooks&&Object.keys(e.__hooks).map((function(t){if(e.__hooks[t])return t}))}})}function delHooksDescriptor(e){e.__hooks=null}function runHooks(e,t,r){for(var n=arguments.length,i=new Array(n>3?n-3:0),a=3;a<n;a++)i[a-3]=arguments[a];if(e.__hooks&&Array.isArray(e.__hooks[t])){var s=e.__hooks[t],o=-1;return function e(t,r,n){for(var i=arguments.length,a=new Array(i>3?i-3:0),u=3;u<i;u++)a[u-3]=arguments[u];if(o++,0===s.length||o===s.length)return n.call.apply(n,[t,t].concat(a));var c=s[o],l=c.call.apply(c,[t,t].concat(a));return l&&l.then?l.then((function(i){return!1===i?null:e.apply(void 0,[t,r,n].concat(a))})).catch((function(e){console.warn("[runHooks]".concat(r," reject"),e.message)})):!1!==l?e.apply(void 0,[t,r,n].concat(a)):void 0}.apply(void 0,[e,t,r].concat(i))}return r.call.apply(r,[e,e].concat(i))}function showErrorMsg(e,t){XG_DEBUG.logError("[".concat(e,"] event or callback cant be undefined or null when call ").concat(t))}var BasePlugin=function(){function e(t){_classCallCheck$2(this,e),util.checkIsFunction(this.beforeCreate)&&this.beforeCreate(t),hooksDescriptor(this),this.__args=t,this.__events={},this.__onceEvents={},this.config=t.config||{},this.player=null,this.playerConfig={},this.pluginName="",this.__init(t)}return _createClass$2(e,[{key:"beforeCreate",value:function(e){}},{key:"afterCreate",value:function(){}},{key:"beforePlayerInit",value:function(){}},{key:"onPluginsReady",value:function(){}},{key:"afterPlayerInit",value:function(){}},{key:"destroy",value:function(){}},{key:"__init",value:function(e){this.player=e.player,this.playerConfig=e.player&&e.player.config,this.pluginName=e.pluginName?e.pluginName.toLowerCase():this.constructor.pluginName.toLowerCase(),this.logger=e.player&&e.player.logger}},{key:"updateLang",value:function(e){e||(e=this.lang)}},{key:"lang",get:function(){return this.player.lang}},{key:"i18n",get:function(){return this.player.i18n}},{key:"i18nKeys",get:function(){return this.player.i18nKeys}},{key:"domEventType",get:function(){var e=util.checkTouchSupport()?"touch":"mouse";return!this.playerConfig||"touch"!==this.playerConfig.domEventType&&"mouse"!==this.playerConfig.domEventType||(e=this.playerConfig.domEventType),e}},{key:"on",value:function(e,t){var r=this;e&&t&&this.player?"string"==typeof e?(this.__events[e]=t,this.player.on(e,t)):Array.isArray(e)&&e.forEach((function(e){r.__events[e]=t,r.player.on(e,t)})):showErrorMsg(this.pluginName,"plugin.on(event, callback)")}},{key:"once",value:function(e,t){var r=this;e&&t&&this.player?"string"==typeof e?(this.__onceEvents[e]=t,this.player.once(e,t)):Array.isArray(e)&&e.forEach((function(n){r.__onceEvents[n]=t,r.player.once(e,t)})):showErrorMsg(this.pluginName,"plugin.once(event, callback)")}},{key:"off",value:function(e,t){var r=this;e&&t&&this.player?"string"==typeof e?(delete this.__events[e],this.player.off(e,t)):Array.isArray(e)&&e.forEach((function(n){delete r.__events[e],r.player.off(n,t)})):showErrorMsg(this.pluginName,"plugin.off(event, callback)")}},{key:"offAll",value:function(){var e=this;["__events","__onceEvents"].forEach((function(t){Object.keys(e[t]).forEach((function(r){e[t][r]&&e.off(r,e[t][r]),r&&delete e[t][r]}))})),this.__events={},this.__onceEvents={}}},{key:"emit",value:function(e){var t;if(this.player){for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];(t=this.player).emit.apply(t,[e].concat(n))}}},{key:"emitUserAction",value:function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(this.player){var n=_objectSpread2$1(_objectSpread2$1({},r),{},{pluginName:this.pluginName});this.player.emitUserAction(e,t,n)}}},{key:"hook",value:function(e,t){return hook.call.apply(hook,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"useHooks",value:function(e,t){for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return useHooks.call.apply(useHooks,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"removeHooks",value:function(e,t){for(var r=arguments.length,n=new Array(r>2?r-2:0),i=2;i<r;i++)n[i-2]=arguments[i];return removeHooks.call.apply(removeHooks,[this].concat(Array.prototype.slice.call(arguments)))}},{key:"registerPlugin",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";if(this.player)return r&&(t.pluginName=r),this.player.registerPlugin({plugin:e,options:t})}},{key:"getPlugin",value:function(e){return this.player?this.player.getPlugin(e):null}},{key:"__destroy",value:function(){var e=this,t=this.player,r=this.pluginName;this.offAll(),util.clearAllTimers(this),util.checkIsFunction(this.destroy)&&this.destroy(),["player","playerConfig","pluginName","logger","__args","__hooks"].map((function(t){e[t]=null})),t.unRegisterPlugin(r),delHooksDescriptor(this)}}],[{key:"defineGetterOrSetter",value:function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&Object.defineProperty(e,r,t[r])}},{key:"defineMethod",value:function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&"function"==typeof t[r]&&Object.defineProperty(e,r,{configurable:!0,value:t[r]})}},{key:"defaultConfig",get:function(){return{}}},{key:"pluginName",get:function(){return"pluginName"}}]),e}();function ownKeys(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 _objectSpread2(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty$1(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _regeneratorRuntime(){_regeneratorRuntime=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",o=i.toStringTag||"@@toStringTag";function u(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{u({},"")}catch(e){u=function(e,t,r){return e[t]=r}}function c(e,t,r,i){var a=t&&t.prototype instanceof f?t:f,s=Object.create(a.prototype),o=new P(i||[]);return n(s,"_invoke",{value:b(e,r,o)}),s}function l(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var d={};function f(){}function h(){}function p(){}var _={};u(_,a,(function(){return this}));var y=Object.getPrototypeOf,v=y&&y(y(A([])));v&&v!==t&&r.call(v,a)&&(_=v);var m=p.prototype=f.prototype=Object.create(_);function g(e){["next","throw","return"].forEach((function(t){u(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){function i(n,a,s,o){var u=l(e[n],e,a);if("throw"!==u.type){var c=u.arg,d=c.value;return d&&"object"==typeof d&&r.call(d,"__await")?t.resolve(d.__await).then((function(e){i("next",e,s,o)}),(function(e){i("throw",e,s,o)})):t.resolve(d).then((function(e){c.value=e,s(c)}),(function(e){return i("throw",e,s,o)}))}o(u.arg)}var a;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){i(e,r,t,n)}))}return a=a?a.then(n,n):n()}})}function b(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return{value:void 0,done:!0}}for(r.method=i,r.arg=a;;){var s=r.delegate;if(s){var o=S(s,r);if(o){if(o===d)continue;return o}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=l(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var i=l(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,d;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function T(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function P(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(T,this),this.reset(!0)}function A(e){if(e){var t=e[a];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:x}}function x(){return{value:void 0,done:!0}}return h.prototype=p,n(m,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:h,configurable:!0}),h.displayName=u(p,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,u(e,o,"GeneratorFunction")),e.prototype=Object.create(m),e},e.awrap=function(e){return{__await:e}},g(E.prototype),u(E.prototype,s,(function(){return this})),e.AsyncIterator=E,e.async=function(t,r,n,i,a){void 0===a&&(a=Promise);var s=new E(c(t,r,n,i),a);return e.isGeneratorFunction(r)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},g(m),u(m,o,"Generator"),u(m,a,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=A,P.prototype={constructor:P,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],s=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var o=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(o&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var s=a?a.completion:{};return s.type=e,s.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;k(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:A(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},e}function _typeof(e){return(_typeof="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})(e)}function asyncGeneratorStep(e,t,r,n,i,a,s){try{var o=e[a](s),u=o.value}catch(e){return void r(e)}o.done?t(u):Promise.resolve(u).then(n,i)}function _asyncToGenerator(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var a=e.apply(t,r);function s(e){asyncGeneratorStep(a,n,i,s,o,"next",e)}function o(e){asyncGeneratorStep(a,n,i,s,o,"throw",e)}s(void 0)}))}}function _classCallCheck$1(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties$1(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,_toPropertyKey$1(n.key),n)}}function _createClass$1(e,t,r){return t&&_defineProperties$1(e.prototype,t),r&&_defineProperties$1(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty$1(e,t,r){return(t=_toPropertyKey$1(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _inherits$1(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_setPrototypeOf$1(e,t)}function _getPrototypeOf$1(e){return(_getPrototypeOf$1=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf$1(e,t){return(_setPrototypeOf$1=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct$1(){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}}function _construct(e,t,r){return(_construct=_isNativeReflectConstruct$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&&_setPrototypeOf$1(i,r.prototype),i}).apply(null,arguments)}function _isNativeFunction(e){return-1!==Function.toString.call(e).indexOf("[native code]")}function _wrapNativeSuper(e){var t="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(e){if(null===e||!_isNativeFunction(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 _construct(e,arguments,_getPrototypeOf$1(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf$1(r,e)},_wrapNativeSuper(e)}function _objectWithoutPropertiesLoose(e,t){if(null==e)return{};var r,n,i={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(i[r]=e[r]);return i}function _objectWithoutProperties(e,t){if(null==e)return{};var r,n,i=_objectWithoutPropertiesLoose(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}function _assertThisInitialized$1(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn$1(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized$1(e)}function _createSuper$1(e){var t=_isNativeReflectConstruct$1();return function(){var r,n=_getPrototypeOf$1(e);if(t){var i=_getPrototypeOf$1(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return _possibleConstructorReturn$1(this,r)}}function _superPropBase(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=_getPrototypeOf$1(e)););return e}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=_superPropBase(e,t);if(n){var i=Object.getOwnPropertyDescriptor(n,t);return i.get?i.get.call(arguments.length<3?e:r):i.value}},_get.apply(this,arguments)}function _unsupportedIterableToArray$1(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray$1(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray$1(e,t):void 0}}function _arrayLikeToArray$1(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _createForOfIteratorHelper$1(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=_unsupportedIterableToArray$1(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(o)throw a}}}}function _toPrimitive$1(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey$1(e){var t=_toPrimitive$1(e,"string");return"symbol"==typeof t?t:String(t)}var _ERR_CODE,Buffer$1=function(){function e(){_classCallCheck$1(this,e)}return _createClass$1(e,null,[{key:"start",value:function(e){return e&&e.length?1===e.length&&e.end(0)-e.start(0)<1e-6||1===e.length&&e.start(0)<0?0:e.start(0):0}},{key:"end",value:function(e){return e&&e.length?1===e.length&&e.end(0)-e.start(0)<1e-6?0:e.end(e.length-1):0}},{key:"get",value:function(e){if(e)try{return e.buffered}catch(e){}}},{key:"buffers",value:function(e,t){if(!e||!e.length)return[];for(var r=[],n=0,i=e.length;n<i;n++){var a=r.length;if(a&&t){var s=r[a-1],o=s[1];if(e.start(n)-o<=t){var u=e.end(n);u>o&&(s[1]=u)}else r.push([e.start(n),e.end(n)])}else r.push([e.start(n),e.end(n)])}return r}},{key:"totalLength",value:function(e){return e&&e.length?e.reduce((function(e,t){return e+(t[1]-t[0])}),0):0}},{key:"info",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!t||!t.length)return{start:0,end:0,buffers:[]};for(var i=0,a=0,s=0,o=0,u=0,c=0,l=0,d=e.buffers(t,n),f=0,h=d.length;f<h;f++){var p=d[f];if(r+n>=p[0]&&r<=p[1])i=p[0],a=p[1],s=f;else{if(r+n<p[0]){o=p[0],u=p[1];break}r+n>p[1]&&(c=p[0],l=p[1])}}return{start:i,end:a,index:s,buffers:d,nextStart:o,nextEnd:u,prevStart:c,prevEnd:l,currentTime:r,behind:r-i,remaining:a?a-r:0,length:e.totalLength&&e.totalLength(d)}}},{key:"isBuffered",value:function(t,r){if(t){var n=e.get(t);if(null!=n&&n.length)for(var i=0;i<n.length;i++)if(r>=n.start(i)&&r<=n.end(i))return!0}return!1}}]),e}(),isBrowser$1="undefined"!=typeof window,ERR={MANIFEST:"manifest",NETWORK:"network",NETWORK_TIMEOUT:"network_timeout",NETWORK_FORBIDDEN:"network_forbidden",NETWORK_NOTFOUND:"network_notfound",NETWROK_RANGE_NOT_SATISFIABLE:"network_range_not_satisfiable",DEMUX:"demux",REMUX:"remux",MEDIA:"media",DRM:"drm",OTHER:"other",RUNTIME:"runtime",SUB_TYPES:{FLV:"FLV",HLS:"HLS",MP4:"MP4",FMP4:"FMP4",MSE_ADD_SB:"MSE_ADD_SB",MSE_APPEND_BUFFER:"MSE_APPEND_BUFFER",MSE_OTHER:"MSE_OTHER",MSE_FULL:"MSE_FULL",MSE_CHANGE_TYPE:"MSE_CHANGE_TYPE",OPTION:"OPTION",DASH:"DASH",LICENSE:"LICENSE",CUSTOM_LICENSE:"CUSTOM_LICENSE",MSE_HIJACK:"MSE_HIJACK",EME_HIJACK:"EME_HIJACK",SIDX:"SIDX",NO_CANPLAY_ERROR:"NO_CANPLAY_ERROR",BUFFERBREAK_ERROR:"BUFFERBREAK_ERROR",WAITING_TIMEOUT_ERROR:"WAITING_TIMEOUT_ERROR",MEDIA_ERR_ABORTED:"MEDIA_ERR_ABORTED",MEDIA_ERR_NETWORK:"MEDIA_ERR_NETWORK",MEDIA_ERR_DECODE:"MEDIA_ERR_DECODE",MEDIA_ERR_SRC_NOT_SUPPORTED:"MEDIA_ERR_SRC_NOT_SUPPORTED",MEDIA_ERR_CODEC_NOT_SUPPORTED:"MEDIA_ERR_CODEC_NOT_SUPPORTED",MEDIA_ERR_URL_EMPTY:"MEDIA_ERR_URL_EMPTY"}},ERR_CODE=(_defineProperty$1(_ERR_CODE={},ERR.MANIFEST,{HLS:1100,DASH:1200}),_defineProperty$1(_ERR_CODE,ERR.NETWORK,2100),_defineProperty$1(_ERR_CODE,ERR.NETWORK_TIMEOUT,2101),_defineProperty$1(_ERR_CODE,ERR.NETWORK_FORBIDDEN,2103),_defineProperty$1(_ERR_CODE,ERR.NETWORK_NOTFOUND,2104),_defineProperty$1(_ERR_CODE,ERR.NETWROK_RANGE_NOT_SATISFIABLE,2116),_defineProperty$1(_ERR_CODE,ERR.DEMUX,{FLV:3100,HLS:3200,MP4:3300,FMP4:3400,SIDX:3410}),_defineProperty$1(_ERR_CODE,ERR.REMUX,{FMP4:4100,MP4:4200}),_defineProperty$1(_ERR_CODE,ERR.MEDIA,{MEDIA_ERR_ABORTED:5101,MEDIA_ERR_NETWORK:5102,MEDIA_ERR_DECODE:5103,MEDIA_ERR_SRC_NOT_SUPPORTED:5104,MEDIA_ERR_CODEC_NOT_SUPPORTED:5105,MEDIA_ERR_URL_EMPTY:5106,MSE_ADD_SB:5200,MSE_APPEND_BUFFER:5201,MSE_OTHER:5202,MSE_FULL:5203,MSE_HIJACK:5204,MSE_CHANGE_TYPE:5205,EME_HIJACK:5301}),_defineProperty$1(_ERR_CODE,ERR.DRM,{LICENSE:7100,CUSTOM_LICENSE:7200}),_defineProperty$1(_ERR_CODE,ERR.OTHER,8e3),_defineProperty$1(_ERR_CODE,ERR.RUNTIME,{NO_CANPLAY_ERROR:9001,BUFFERBREAK_ERROR:9002,WAITING_TIMEOUT_ERROR:9003}),_ERR_CODE),StreamingError=function(e){_inherits$1(r,_wrapNativeSuper(Error));var t=_createSuper$1(r);function r(e,n,i,a,s){var o;return _classCallCheck$1(this,r),(o=t.call(this,s||(null==i?void 0:i.message))).errorType=e===ERR.NETWORK_TIMEOUT?ERR.NETWORK:e,o.originError=i,o.ext=a,o.errorCode=ERR_CODE[e][n]||ERR_CODE[e],o.errorMessage=o.message,o.errorCode||(o.errorType=ERR.OTHER,o.errorCode=ERR_CODE[o.errorType]),o}return _createClass$1(r,null,[{key:"create",value:function(e,t,n,i,a){return e instanceof r?e:(e instanceof Error&&(n=e,e=""),e||(e=ERR.OTHER),new r(e,t,n,i,a))}},{key:"network",value:function(e){var t;return new r(null!=e&&e.isTimeout?ERR.NETWORK_TIMEOUT:ERR.NETWORK,null,e instanceof Error?e:null,{url:null==e?void 0:e.url,response:null==e?void 0:e.response,httpCode:null==e||null===(t=e.response)||void 0===t?void 0:t.status})}}]),r}(),LogCacheLevel={DEBUG:1,LOG:2,WARN:3,ERROR:4},LOG_MAX_SIZE=204800,SIMPLE_TYPE=["Boolean","Number","String","Undefined","Null","Date","Object"],Logger$2=function(){function e(t,r){_classCallCheck$1(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]"),this.logCacheLevel=(null==r?void 0:r.logCacheLevel)||3,this.logMaxSize=(null==r?void 0:r.logMaxSize)||LOG_MAX_SIZE,this.logSize=0,this.logTextArray=[]}return _createClass$1(e,[{key:"debug",value:function(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];this.logCache.apply(this,[LogCacheLevel.DEBUG].concat(n)),e.disabled||(t=console).debug.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"log",value:function(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];this.logCache.apply(this,[LogCacheLevel.LOG].concat(n)),e.disabled||(t=console).log.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"warn",value:function(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];this.logCache.apply(this,[LogCacheLevel.WARN].concat(n)),e.disabled||(t=console).warn.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"error",value:function(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];this.logCache.apply(this,[LogCacheLevel.ERROR].concat(n)),e.disabled||(t=console).error.apply(t,["[".concat(nowTime$1(),"]"),this._prefix].concat(n))}},{key:"logCache",value:function(e){if(!(e<this.logCacheLevel)){var t="";try{for(var r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];var a=n.map((function(e){return logable(e)}));t="[".concat(nowTime$1(),"]")+this._prefix+JSON.stringify(a)}catch(e){return}if(e>=this.logCacheLevel&&(this.logSize+=t.length,this.logTextArray.push(t)),this.logSize>this.logMaxSize){var s=this.logTextArray.shift();this.logSize-=s.length}}}},{key:"getLogCache",value:function(){var e=this.logTextArray.join("\n");return this.reset(),e}},{key:"reset",value:function(){this.logTextArray=[],this.logSize=0}},{key:"table",value:function(){var t;e.disabled||(console.group(this._prefix),(t=console).table.apply(t,arguments),console.groupEnd())}},{key:"setLogLevel",value:function(e){this.logCacheLevel=e}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();function nowTime$1(){return(new Date).toLocaleString()}function reduceDepth(e){if("object"!==_typeof(e))return e;var t=Object.prototype.toString.call(e).slice(8,-1);switch(t){case"Array":case"Uint8Array":case"ArrayBuffer":return t+"["+e.length+"]";case"Object":return"{}";default:return t}}function logable(e,t,r){r||(r=1),t||(t=2);var n={};if(!e||"object"!==_typeof(e))return e;var i=Object.prototype.toString.call(e).slice(8,-1);if(!SIMPLE_TYPE.includes(i))return i;if(!(r>t)){for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&(r===t?n[a]=reduceDepth(e[a]):"object"===_typeof(e[a])?n[a]=logable(e[a],t,r+1):n[a]=e[a]);return n}}function createPublicPromise(){var e,t,r=new Promise((function(r,n){e=r,t=n}));return r.used=!1,r.resolve=function(){return r.used=!0,e.apply(void 0,arguments)},r.reject=function(){return r.used=!0,t.apply(void 0,arguments)},r}function nowTime(){try{return parseInt(performance.now(),10)}catch(e){return(new Date).getTime()}}_defineProperty$1(Logger$2,"disabled",!0);var SafeJSON={stringify:function(e){try{return JSON.stringify(e)}catch(e){return""}},parse:function(e){try{return JSON.parse(e)}catch(e){return}}};function getMediaSource(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];try{return isBrowser$1?e&&"undefined"!=typeof ManagedMediaSource?ManagedMediaSource:window.MediaSource:null}catch(e){}}function isMMS(e){return/ManagedMediaSource/gi.test(Object.prototype.toString.call(e))}function getTimeRanges(e){var t=[];if(e instanceof TimeRanges)for(var r=0;r<e.length;r++)t.push({start:e.start(r),end:e.end(r)});return t}var OP_NAME={APPEND:"appendBuffer",REMOVE:"removeBuffer",UPDATE_DURATION:"updateDuration"},MSE=function(){function e(t,r){var n=this;_classCallCheck$1(this,e),_defineProperty$1(this,"media",null),_defineProperty$1(this,"mediaSource",null),_defineProperty$1(this,"_openPromise",createPublicPromise()),_defineProperty$1(this,"_queue",Object.create(null)),_defineProperty$1(this,"_sourceBuffer",Object.create(null)),_defineProperty$1(this,"_mseFullFlag",{}),_defineProperty$1(this,"_st",0),_defineProperty$1(this,"_opst",0),_defineProperty$1(this,"_logger",null),_defineProperty$1(this,"_config",null),_defineProperty$1(this,"_url",null),_defineProperty$1(this,"_onStartStreaming",(function(){n._logger.debug("startstreaming")})),_defineProperty$1(this,"_onEndStreaming",(function(){n._logger.debug("endstreaming")})),_defineProperty$1(this,"_onSBUpdateEnd",(function(e){var t=n._queue[e];if(t){var r=t[0];if((null==r?void 0:r.opName)!==OP_NAME.UPDATE_DURATION&&t.shift(),r){var i,a,s=nowTime()-n._opst;n._logger.debug("UpdateEnd(".concat(e,"/").concat(r.opName,")"),SafeJSON.stringify(getTimeRanges(null===(i=n._sourceBuffer[e])||void 0===i?void 0:i.buffered)),s,r.context),r.promise.resolve({name:r.opName,context:r.context,costtime:s});var o=null===(a=r.context)||void 0===a?void 0:a.callback;o&&"function"==typeof o&&o(r.context),n._startQueue(e)}}})),_defineProperty$1(this,"_onSBUpdateError",(function(e,t){var r=n._queue[e];if(r){var i=r[0];i&&(n._logger.error("UpdateError",e,i.opName,i.context),i.promise.reject(new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_APPEND_BUFFER,t)))}})),this._config=Object.assign(e.getDefaultConfig(),r),t&&this.bindMedia(t),this._logger=new Logger$2("MSE"),this._config.openLog&&Logger$2.enable()}var t,r,n;return _createClass$1(e,[{key:"isOpened",get:function(){var e;return"open"===(null===(e=this.mediaSource)||void 0===e?void 0:e.readyState)}},{key:"hasOpTasks",get:function(){var e=this,t=!1;return Object.keys(this._queue).forEach((function(r){var n=e._queue[r];Array.isArray(n)&&(t||(t=n.length>0))})),t}},{key:"url",get:function(){return this._url}},{key:"duration",get:function(){var e;return(null===(e=this.mediaSource)||void 0===e?void 0:e.duration)||-1}},{key:"isEnded",get:function(){return!!this.mediaSource&&"ended"===this.mediaSource.readyState}},{key:"streaming",get:function(){return!isMMS(this.mediaSource)||this.mediaSource.streaming}},{key:"isFull",value:function(t){return t?this._mseFullFlag[t]:this._mseFullFlag[e.VIDEO]}},{key:"updateDuration",value:function(e){var t=this,r=this.mediaSource&&this.mediaSource.duration>e;if(this.mediaSource&&this.mediaSource.duration>e){var n=0;if(Object.keys(this._sourceBuffer).forEach((function(e){try{n=Math.max(t.bufferEnd(e)||0,n)}catch(e){}})),e<n)return Promise.resolve()}return this._enqueueBlockingOp((function(){t.isEnded?t._logger.debug("setDuration but ended"):t.mediaSource&&(t.mediaSource.duration=e,t._logger.debug("setDuration",e))}),OP_NAME.UPDATE_DURATION,{isReduceDuration:r})}},{key:"open",value:function(){var e=this;if(this._openPromise.used&&!this.isOpened&&this.mediaSource){var t=this.mediaSource;t.addEventListener("sourceopen",(function r(){var n=nowTime()-e._st;e._logger.debug("sourceopen",n),t.removeEventListener("sourceopen",r),e._openPromise.resolve({costtime:n})})),this._openPromise=createPublicPromise()}return this._openPromise}},{key:"bindMedia",value:(n=_asyncToGenerator(_regeneratorRuntime().mark((function e(t){var r,n,i,a,s=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.mediaSource&&!this.media){e.next=3;break}return e.next=3,this.unbindMedia();case 3:if(r=getMediaSource(this._config.preferMMS),t&&r){e.next=6;break}throw new Error("Param media or MediaSource does not exist");case 6:return this.media=t,n=this.mediaSource=new r,i=isMMS(n),this._st=nowTime(),a=function e(){var r=nowTime()-s._st;s._logger.debug("sourceopen"),n.removeEventListener("sourceopen",e),URL.revokeObjectURL(t.src),s._openPromise.resolve({costtime:r})},n.addEventListener("sourceopen",a),i&&(n.addEventListener("startstreaming",this._onStartStreaming),n.addEventListener("endstreaming",this._onEndStreaming)),this._url=URL.createObjectURL(n),t.src=this._url,t.disableRemotePlayback=i,e.abrupt("return",this._openPromise);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})},{key:"unbindMedia",value:(r=_asyncToGenerator(_regeneratorRuntime().mark((function e(){var t,r,n,i=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._openPromise.used||this._openPromise.resolve(),t=this.mediaSource){if(Object.keys(this._queue).forEach((function(e){var t=i._queue[e];t&&t.forEach((function(e){var t,r;return null===(t=e.promise)||void 0===t||null===(r=t.resolve)||void 0===r?void 0:r.call(t)}))})),r=!!this.media&&this.media.readyState>=1,n="open"===t.readyState,r&&n)try{t.endOfStream()}catch(e){}Object.keys(this._sourceBuffer).forEach((function(e){try{t.removeSourceBuffer(i._sourceBuffer[e])}catch(e){}})),isMMS(t)&&(t.removeEventListener("startstreaming",this._onStartStreaming),t.removeEventListener("endstreaming",this._onEndStreaming))}if(this.media){this.media.disableRemotePlayback=!1,this.media.removeAttribute("src");try{this.media.load()}catch(e){}this.media=null}this.mediaSource=null,this._openPromise=createPublicPromise(),this._queue=Object.create(null),this._sourceBuffer=Object.create(null);case 8:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"createSource",value:function(e,t){if(!this._sourceBuffer[e]&&this.mediaSource){var r;try{r=this._sourceBuffer[e]=this.mediaSource.addSourceBuffer(t)}catch(e){throw new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_ADD_SB,e)}r.mimeType=t,r.addEventListener("updateend",this._onSBUpdateEnd.bind(this,e)),r.addEventListener("error",this._onSBUpdateError.bind(this,e))}}},{key:"changeType",value:function(e,t){var r=this,n=this._sourceBuffer[e];return this.mediaSource&&n&&n.mimeType!==t?"function"!=typeof n.changeType?Promise.reject(new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_CHANGE_TYPE,new Error("changeType is not a function"))):this._enqueueOp(e,(function(){try{n.changeType(t)}catch(e){throw new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_CHANGE_TYPE,e)}n.mimeType=t,r._onSBUpdateEnd(e)}),"changeType",{mimeType:t}):Promise.resolve()}},{key:"createOrChangeSource",value:function(e,t){return this.createSource(e,t),this.changeType(e,t)}},{key:"append",value:function(e,t,r){var n=this;return t&&t.byteLength&&this._sourceBuffer[e]?this._enqueueOp(e,(function(){var i;n.mediaSource&&!n.media.error&&(n._logger.debug("MSE APPEND START",r),n._opst=nowTime(),null===(i=n._sourceBuffer[e])||void 0===i||i.appendBuffer(t))}),OP_NAME.APPEND,r):Promise.resolve()}},{key:"remove",value:function(e,t,r,n){var i=this,a=!1;return this._mseFullFlag[e]&&(a=!0),this._enqueueOp(e,(function(){if(i.mediaSource&&!i.media.error){var a=i._sourceBuffer[e];t>=r||!a?i._onSBUpdateEnd(e):(i._opst=nowTime(),i._logger.debug("MSE REMOVE START",e,t,r,n),a.remove(t,r))}}),OP_NAME.REMOVE,n,a)}},{key:"clearBuffer",value:function(e,t){var r,n=this;return Object.keys(this._sourceBuffer).forEach((function(i){r=n.remove(i,e,t)})),r||Promise.resolve()}},{key:"clearAllBuffer",value:function(){var e,t=this;return Object.keys(this._sourceBuffer).forEach((function(r){var n=t._sourceBuffer[r];e=t.remove(r,0,Buffer$1.end(Buffer$1.get(n)))})),e}},{key:"clearOpQueues",value:function(e,t){var r;this._logger.debug("MSE clearOpQueue START");var n=this._queue[e];if(t&&n)this._queue[e]=[];else if(n&&n[e]&&!(n.length<5)){var i=[];n.forEach((function(e){e.context&&e.context.isinit&&i.push(e)})),this._queue[e]=n.slice(0,2),i.length>0&&(r=this._queue[e]).push.apply(r,i)}}},{key:"endOfStream",value:function(e){var t=this;return this.mediaSource&&"open"===this.mediaSource.readyState?this._enqueueBlockingOp((function(){var r=t.mediaSource;r&&"open"===r.readyState&&(t._logger.debug("MSE endOfStream START"),e?r.endOfStream(e):r.endOfStream())}),"endOfStream"):Promise.resolve()}},{key:"setLiveSeekableRange",value:function(e,t){var r=this.mediaSource;e<0||t<e||null==r||!r.setLiveSeekableRange||"open"!==r.readyState||r.setLiveSeekableRange(e,t)}},{key:"getSourceBuffer",value:function(e){return this._sourceBuffer[e]}},{key:"buffered",value:function(e){return Buffer$1.get(this._sourceBuffer[e])}},{key:"bufferStart",value:function(e){return Buffer$1.start(this.buffered(e))}},{key:"bufferEnd",value:function(e){return Buffer$1.end(this.buffered(e))}},{key:"_enqueueOp",value:function(e,t,r,n,i){var a=this;if(!this.mediaSource)return Promise.resolve();var s=this._queue[e]=this._queue[e]||[],o={exec:t,promise:createPublicPromise(),opName:r,context:n};return i?(s.splice(0,0,o),this._mseFullFlag[e]=!1,this._startQueue(e)):s.push(o),this.isOpened||this.isEnded?1===s.length&&this._startQueue(e):this._openPromise.then((function(){1===s.length&&a._startQueue(e)})),o.promise}},{key:"_enqueueBlockingOp",value:(t=_asyncToGenerator(_regeneratorRuntime().mark((function e(t,r,n){var i,a,s=this;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.mediaSource){e.next=2;break}return e.abrupt("return",Promise.resolve());case 2:if((i=Object.keys(this._sourceBuffer)).length){e.next=5;break}return e.abrupt("return",t());case 5:return a=[],i.forEach((function(e){var t=s._queue[e],i=createPublicPromise();a.push(i),t.push({exec:function(){i.resolve()},promise:i,opName:r,context:n}),1===t.length&&s._startQueue(e)})),e.abrupt("return",Promise.all(a).then((function(){try{return t()}finally{i.forEach((function(e){var t=s._queue[e],r=s._sourceBuffer[e];null==t||t.shift(),r&&r.updating||s._startQueue(e)}))}})));case 8:case"end":return e.stop()}}),e,this)}))),function(e,r,n){return t.apply(this,arguments)})},{key:"_startQueue",value:function(e){var t=this._queue[e];if(t){var r=t[0];if(r&&!this._mseFullFlag[e])try{r.exec()}catch(a){var n,i;if(a&&a.message&&a.message.indexOf("SourceBuffer is full")>=0)this._mseFullFlag[e]=!0,r.context&&"object"===_typeof(r.context)&&(r.context.isFull=!0),this._logger.error("[MSE error], context,",r.context," ,name,",r.opName,",err,SourceBuffer is full"),null==r||null===(n=r.promise)||void 0===n||n.reject(new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_FULL,a));else this._logger.error(a),null==r||null===(i=r.promise)||void 0===i||i.reject(a.constructor===StreamingError?a:new StreamingError(ERR.MEDIA,ERR.SUB_TYPES.MSE_OTHER,a)),t.shift(),this._startQueue(e)}}}},{key:"setTimeoffset",value:function(e,t,r){var n=this;return this._enqueueOp(e,(function(){t<0&&(t+=.001),n._sourceBuffer[e].timestampOffset=t,n._onSBUpdateEnd(e)}),"setTimeoffset",r)}},{key:"abort",value:function(e,t){var r=this;return this.isOpened?this._enqueueOp(e,(function(){r._sourceBuffer[e].abort(),r._onSBUpdateEnd(e)}),"abort",t):Promise.resolve()}}],[{key:"isSupported",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:'video/mp4; codecs="avc1.42E01E,mp4a.40.2"',t=getMediaSource(!(arguments.length>1&&void 0!==arguments[1])||arguments[1]);if(!t)return!1;try{return t.isTypeSupported(e)}catch(t){return this._logger.error(e,t),!1}}},{key:"isMMSOnly",value:function(){return"undefined"!=typeof ManagedMediaSource&&"undefined"==typeof MediaSource}},{key:"getDefaultConfig",value:function(){return{openLog:!1,preferMMS:!1}}}]),e}();_defineProperty$1(MSE,"VIDEO","video"),_defineProperty$1(MSE,"AUDIO","audio");var LoaderType={FETCH:"fetch",XHR:"xhr"},ResponseType={ARRAY_BUFFER:"arraybuffer",TEXT:"text",JSON:"json"},NetError=function(e){_inherits$1(r,_wrapNativeSuper(Error));var t=_createSuper$1(r);function r(e,n,i,a){var s;return _classCallCheck$1(this,r),_defineProperty$1(_assertThisInitialized$1(s=t.call(this,a)),"retryCount",0),_defineProperty$1(_assertThisInitialized$1(s),"isTimeout",!1),_defineProperty$1(_assertThisInitialized$1(s),"loaderType",LoaderType.FETCH),_defineProperty$1(_assertThisInitialized$1(s),"startTime",0),_defineProperty$1(_assertThisInitialized$1(s),"endTime",0),_defineProperty$1(_assertThisInitialized$1(s),"options",{}),s.url=e,s.request=n,s.response=i,s}return _createClass$1(r)}(),toString=Object.prototype.toString;function isObject(e){return null!==e&&"object"===_typeof(e)}function isPlainObject(e){if("[object Object]"!==toString.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function isDate(e){return"[object Date]"===toString.call(e)}function getRangeValue(e){if(e&&null!==e[0]&&void 0!==e[0]&&(0!==e[0]||null!==e[1]&&void 0!==e[1])){var t="bytes="+e[0]+"-";return e[1]&&(t+=e[1]),t}}function encode(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function setUrlParams(e,t){if(e){if(!t)return e;var r,n=Object.keys(t).map((function(e){if(null!=(r=t[e]))return Array.isArray(r)?e+="[]":r=[r],r.map((function(t){return isDate(t)?t=t.toISOString():isObject(t)&&(t=JSON.stringify(t)),"".concat(encode(e),"=").concat(encode(t))})).join("&")})).filter(Boolean).join("&");if(n){var i=e.indexOf("#");-1!==i&&(e=e.slice(0,i)),e+=(-1===e.indexOf("?")?"?":"&")+n}return e}}function createResponse(e,t,r,n,i,a,s,o,u,c,l){return i=null!=i?parseFloat(i):null,n=parseInt(n||"0",10),Number.isNaN(n)&&(n=0),{data:e,done:t,options:{range:u,vid:c,index:o,contentLength:n,age:i,startTime:a,firstByteTime:s,endTime:Date.now(),priOptions:l},response:r}}function calculateSpeed(e,t){return Math.round(8*e*1e3/t/1024)}var EVENT={ERROR:"error",TTFB:"core.ttfb",LOAD_START:"core.loadstart",LOAD_RESPONSE_HEADERS:"core.loadresponseheaders",LOAD_COMPLETE:"core.loadcomplete",LOAD_RETRY:"core.loadretry",SOURCEBUFFER_CREATED:"core.sourcebuffercreated",MEDIASOURCE_OPENED:"core.mediasourceopened",ANALYZE_DURATION_EXCEEDED:"core.analyzedurationexceeded",APPEND_BUFFER:"core.appendbuffer",REMOVE_BUFFER:"core.removebuffer",BUFFEREOS:"core.buffereos",KEYFRAME:"core.keyframe",CHASEFRAME:"core.chaseframe",METADATA_PARSED:"core.metadataparsed",SEI:"core.sei",SEI_IN_TIME:"core.seiintime",FLV_SCRIPT_DATA:"core.flvscriptdata",LOWDECODE:"core.lowdecode",SWITCH_URL_SUCCESS:"core.switchurlsuccess",SWITCH_URL_FAILED:"core.switchurlfailed",SPEED:"core.speed",HLS_MANIFEST_LOADED:"core.hlsmanifestloaded",HLS_LEVEL_LOADED:"core.hlslevelloaded",DEMUXED_TRACK:"core.demuxedtrack",STREAM_EXCEPTION:"core.streamexception",LARGE_AV_FIRST_FRAME_GAP_DETECT:"LARGE_AV_FIRST_FRAME_GAP_DETECT",LARGE_VIDEO_DTS_GAP_DETECT:"LARGE_VIDEO_DTS_GAP_DETECT",LARGE_AUDIO_DTS_GAP_DETECT:"LARGE_AUDIO_DTS_GAP_DETECT",AUDIO_GAP_DETECT:"AUDIO_GAP_DETECT",AUDIO_OVERLAP_DETECT:"AUDIO_OVERLAP_DETECT",MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT:"MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT",REAL_TIME_SPEED:"real_time_speed"},CACHESIZE=2097152,FetchLoader=function(e){_inherits$1(n,EventEmitter);var t,r=_createSuper$1(n);function n(){var e;return _classCallCheck$1(this,n),_defineProperty$1(_assertThisInitialized$1(e=r.call(this)),"_abortController",null),_defineProperty$1(_assertThisInitialized$1(e),"_timeoutTimer",null),_defineProperty$1(_assertThisInitialized$1(e),"_reader",null),_defineProperty$1(_assertThisInitialized$1(e),"_response",null),_defineProperty$1(_assertThisInitialized$1(e),"_aborted",!1),_defineProperty$1(_assertThisInitialized$1(e),"_index",-1),_defineProperty$1(_assertThisInitialized$1(e),"_range",null),_defineProperty$1(_assertThisInitialized$1(e),"_receivedLength",0),_defineProperty$1(_assertThisInitialized$1(e),"_running",!1),_defineProperty$1(_assertThisInitialized$1(e),"_logger",null),_defineProperty$1(_assertThisInitialized$1(e),"_vid",""),_defineProperty$1(_assertThisInitialized$1(e),"_firtstByte",0),_defineProperty$1(_assertThisInitialized$1(e),"_onProcessMinLen",0),_defineProperty$1(_assertThisInitialized$1(e),"_onCancel",null),_defineProperty$1(_assertThisInitialized$1(e),"_priOptions",null),e}return _createClass$1(n,[{key:"load",value:function(e){var t,r=this,n=e.url,i=e.vid,a=e.timeout,s=e.responseType,o=e.onProgress,u=e.index,c=e.onTimeout,l=e.onCancel,d=e.range,f=e.transformResponse,h=e.request,p=e.params,_=e.logger,y=e.method,v=e.headers,m=e.body,g=e.mode,E=e.credentials,b=e.cache,S=e.redirect,T=e.referrer,k=e.referrerPolicy,P=e.onProcessMinLen,A=e.priOptions,x=e.streamRes,w=e.firstMaxChunkSize;this._logger=_,this._aborted=!1,this._onProcessMinLen=P,this._onCancel=l,this._abortController="undefined"!=typeof AbortController&&new AbortController,this._running=!0,this._index=u,this._range=d||[0,0],this._vid=i||n,this._priOptions=A||{},this._firstMaxChunkSize=w;var C={method:y,headers:v,body:m,mode:g,credentials:E,cache:b,redirect:S,referrer:T,referrerPolicy:k,signal:null===(t=this._abortController)||void 0===t?void 0:t.signal},R=!1;clearTimeout(this._timeoutTimer),n=setUrlParams(n,p);var $=getRangeValue(d);$&&(v=h?h.headers:C.headers=C.headers||(Headers?new Headers:{}),Headers&&v instanceof Headers?v.append("Range",$):v.Range=$),a&&(this._timeoutTimer=setTimeout((function(){if(R=!0,r.cancel(),c){var e=new NetError(n,C,null,"timeout");e.isTimeout=!0,c(e,{index:r._index,range:r._range,vid:r._vid,priOptions:r._priOptions})}}),a));var D=Date.now();return this._logger.debug("[fetch load start], index,",u,",range,",d),new Promise((function(e,t){(x?new Promise((function(e){e(x)})):fetch(h||n,h?void 0:C)).then(function(){var i=_asyncToGenerator(_regeneratorRuntime().mark((function i(a){var c,l,h,p;return _regeneratorRuntime().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(clearTimeout(r._timeoutTimer),r._response=a,!r._aborted&&r._running){i.next=4;break}return i.abrupt("return");case 4:if(f&&(a=f(a,n)||a),a.ok){i.next=7;break}throw new NetError(n,C,a,"bad network response");case 7:if(c=Date.now(),s!==ResponseType.TEXT){i.next=15;break}return i.next=11,a.text();case 11:l=i.sent,r._running=!1,i.next=37;break;case 15:if(s!==ResponseType.JSON){i.next=22;break}return i.next=18,a.json();case 18:l=i.sent,r._running=!1,i.next=37;break;case 22:if(!o){i.next=29;break}return r.resolve=e,r.reject=t,r._loadChunk(a,o,D,c),i.abrupt("return");case 29:return i.next=31,a.arrayBuffer();case 31:l=i.sent,l=new Uint8Array(l),r._running=!1,h=Date.now()-D,p=calculateSpeed(l.byteLength,h),r.emit(EVENT.REAL_TIME_SPEED,{speed:p,len:l.byteLength,time:h,vid:r._vid,index:r._index,range:r._range,priOptions:r._priOptions});case 37:r._logger.debug("[fetch load end], index,",u,",range,",d),e(createResponse(l,!0,a,a.headers.get("Content-Length"),a.headers.get("age"),D,c,u,d,r._vid,r._priOptions));case 39:case"end":return i.stop()}}),i)})));return function(e){return i.apply(this,arguments)}}()).catch((function(e){var i;clearTimeout(r._timeoutTimer),r._running=!1,r._aborted&&!R||((e=e instanceof NetError?e:new NetError(n,C,null,null===(i=e)||void 0===i?void 0:i.message)).startTime=D,e.endTime=Date.now(),e.isTimeout=R,e.options={index:r._index,range:r._range,vid:r._vid,priOptions:r._priOptions},t(e))}))}))}},{key:"cancel",value:(t=_asyncToGenerator(_regeneratorRuntime().mark((function e(){return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._aborted){e.next=2;break}return e.abrupt("return");case 2:if(this._aborted=!0,this._running=!1,!this._response){e.next=14;break}if(e.prev=5,!this._reader){e.next=9;break}return e.next=9,this._reader.cancel();case 9:e.next=13;break;case 11:e.prev=11,e.t0=e.catch(5);case 13:this._response=this._reader=null;case 14:if(this._abortController){try{this._abortController.abort()}catch(e){}this._abortController=null}this._onCancel&&this._onCancel({index:this._index,range:this._range,vid:this._vid,priOptions:this._priOptions});case 16:case"end":return e.stop()}}),e,this,[[5,11]])}))),function(){return t.apply(this,arguments)})},{key:"_loadChunk",value:function(e,t,r,n){var i=this;if(!e.body||!e.body.getReader){this._running=!1;var a=new NetError(e.url,"",e,"onProgress of bad response.body.getReader");return a.options={index:this._index,range:this._range,vid:this._vid,priOptions:this._priOptions},void this.reject(a)}this._onProcessMinLen>0&&(this._cache=new Uint8Array(CACHESIZE),this._writeIdx=0);var s,o,u,c=this._reader=e.body.getReader(),l=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark((function a(){var d,f,h,p,_,y,v,m,g,E;return _regeneratorRuntime().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return o=Date.now(),a.prev=1,a.next=4,c.read();case 4:s=a.sent,u=Date.now(),a.next=13;break;case 8:return a.prev=8,a.t0=a.catch(1),u=Date.now(),i._aborted||(i._running=!1,a.t0.options={index:i._index,range:i._range,vid:i._vid,priOptions:i._priOptions},i.reject(a.t0)),a.abrupt("return");case 13:if(f=(null===(d=i._range)||void 0===d?void 0:d.length)>0?i._range[0]:0,h=f+i._receivedLength,!i._aborted){a.next=19;break}return i._running=!1,t(void 0,!1,{range:[h,h],vid:i._vid,index:i._index,startTime:o,endTime:u,st:r,firstByteTime:n,priOptions:i._priOptions},e),a.abrupt("return");case 19:p=s.value?s.value.byteLength:0,i._receivedLength+=p,i._logger.debug("【fetchLoader,onProgress call】,task,",i._range,", start,",h,", end,",f+i._receivedLength,", done,",s.done),i._onProcessMinLen>0?i._writeIdx+p>=i._onProcessMinLen||s.done?((_=new Uint8Array(i._writeIdx+p)).set(i._cache.slice(0,i._writeIdx),0),p>0&&_.set(s.value,i._writeIdx),i._writeIdx=0,i._logger.debug("【fetchLoader,onProgress enough】,done,",s.done,",len,",_.byteLength,", writeIdx,",i._writeIdx)):p>0&&i._writeIdx+p<CACHESIZE?(i._cache.set(s.value,i._writeIdx),i._writeIdx+=p,i._logger.debug("【fetchLoader,onProgress cache】,len,",p,", writeIdx,",i._writeIdx)):p>0&&(y=new Uint8Array(i._writeIdx+p+2048),i._logger.debug("【fetchLoader,onProgress extra start】,size,",i._writeIdx+p+2048,", datalen,",p,", writeIdx,",i._writeIdx),y.set(i._cache.slice(0,i._writeIdx),0),p>0&&y.set(s.value,i._writeIdx),i._writeIdx+=p,delete i._cache,i._cache=y,i._logger.debug("【fetchLoader,onProgress extra end】,len,",p,", writeIdx,",i._writeIdx)):_=s.value,(_&&_.byteLength>0||s.done)&&(i._firstMaxChunkSize&&(i._firtstByte?i._cacheData&&((m=new Uint8Array(i._cacheData.byteLength+_.byteLength)).set(i._cacheData,0),m.set(_,i._cacheData.byteLength),_=m,i._cacheData=null):(i._firtstByte++,v=_.slice(0,i._firstMaxChunkSize),i._cacheData=_.slice(i._firstMaxChunkSize),_=v)),t(_,s.done,{range:[i._range[0]+i._receivedLength-(_?_.byteLength:0),i._range[0]+i._receivedLength],vid:i._vid,index:i._index,startTime:o,endTime:u,st:r,firstByteTime:n,priOptions:i._priOptions},e)),s.done?(g=Date.now()-r,E=calculateSpeed(i._receivedLength,g),i.emit(EVENT.REAL_TIME_SPEED,{speed:E,len:i._receivedLength,time:g,vid:i._vid,index:i._index,range:i._range,priOptions:i._priOptions}),i._running=!1,i._logger.debug("[fetchLoader onProgress end],task,",i._range,",done,",s.done),i.resolve(createResponse(s,!0,e,e.headers.get("Content-Length"),e.headers.get("age"),r,n,i._index,i._range,i._vid,i._priOptions))):i._firstMaxChunkSize?setTimeout((function(){l()}),0):l();case 25:case"end":return a.stop()}}),a,null,[[1,8]])})));return function(){return a.apply(this,arguments)}}();l()}},{key:"receiveLen",get:function(){return this._receivedLength}},{key:"running",get:function(){return this._running},set:function(e){this._running=e}}],[{key:"isSupported",value:function(){return!("undefined"==typeof fetch)}}]),n}();function getConfig$1(e){return _objectSpread2({loaderType:LoaderType.FETCH,retry:0,retryDelay:0,timeout:0,request:null,onTimeout:void 0,onProgress:void 0,onRetryError:void 0,transformRequest:void 0,transformResponse:void 0,transformError:void 0,responseType:ResponseType.TEXT,range:void 0,url:"",params:void 0,method:"GET",headers:{},body:void 0,mode:void 0,credentials:void 0,cache:void 0,redirect:void 0,referrer:void 0,referrerPolicy:void 0,integrity:void 0,onProcessMinLen:0},e)}var XhrLoader=function(e){_inherits$1(r,EventEmitter);var t=_createSuper$1(r);function r(){var e;return _classCallCheck$1(this,r),_defineProperty$1(_assertThisInitialized$1(e=t.call(this)),"_xhr",null),_defineProperty$1(_assertThisInitialized$1(e),"_aborted",!1),_defineProperty$1(_assertThisInitialized$1(e),"_timeoutTimer",null),_defineProperty$1(_assertThisInitialized$1(e),"_range",null),_defineProperty$1(_assertThisInitialized$1(e),"_receivedLength",0),_defineProperty$1(_assertThisInitialized$1(e),"_url",null),_defineProperty$1(_assertThisInitialized$1(e),"_onProgress",null),_defineProperty$1(_assertThisInitialized$1(e),"_index",-1),_defineProperty$1(_assertThisInitialized$1(e),"_headers",null),_defineProperty$1(_assertThisInitialized$1(e),"_currentChunkSizeKB",384),_defineProperty$1(_assertThisInitialized$1(e),"_timeout",null),_defineProperty$1(_assertThisInitialized$1(e),"_xhr",null),_defineProperty$1(_assertThisInitialized$1(e),"_withCredentials",null),_defineProperty$1(_assertThisInitialized$1(e),"_startTime",-1),_defineProperty$1(_assertThisInitialized$1(e),"_loadCompleteResolve",null),_defineProperty$1(_assertThisInitialized$1(e),"_loadCompleteReject",null),_defineProperty$1(_assertThisInitialized$1(e),"_runing",!1),_defineProperty$1(_assertThisInitialized$1(e),"_logger",!1),_defineProperty$1(_assertThisInitialized$1(e),"_vid",""),_defineProperty$1(_assertThisInitialized$1(e),"_responseType",void 0),_defineProperty$1(_assertThisInitialized$1(e),"_credentials",void 0),_defineProperty$1(_assertThisInitialized$1(e),"_method",void 0),_defineProperty$1(_assertThisInitialized$1(e),"_transformResponse",void 0),_defineProperty$1(_assertThisInitialized$1(e),"_firstRtt",void 0),_defineProperty$1(_assertThisInitialized$1(e),"_onCancel",null),_defineProperty$1(_assertThisInitialized$1(e),"_priOptions",null),e}return _createClass$1(r,[{key:"load",value:function(e){var t=this;clearTimeout(this._timeoutTimer),this._logger=e.logger,this._range=e.range,this._onProgress=e.onProgress,this._index=e.index,this._headers=e.headers,this._withCredentials="include"===e.credentials||"same-origin"===e.credentials,this._body=e.body||null,e.method&&(this._method=e.method),this._timeout=e.timeout||null,this._runing=!0,this._vid=e.vid||e.url,this._responseType=e.responseType,this._firstRtt=-1,this._onTimeout=e.onTimeout,this._onCancel=e.onCancel,this._request=e.request,this._priOptions=e.priOptions||{},this._logger.debug("【xhrLoader task】, range",this._range),this._url=setUrlParams(e.url,e.params);var r=Date.now();return new Promise((function(e,r){t._loadCompleteResolve=e,t._loadCompleteReject=r,t._startLoad()})).catch((function(e){if(clearTimeout(t._timeoutTimer),t._runing=!1,!t._aborted)throw(e=e instanceof NetError?e:new NetError(t._url,t._request)).startTime=r,e.endTime=Date.now(),e.options={index:t._index,vid:t._vid,priOptions:t._priOptions},e}))}},{key:"_startLoad",value:function(){var e=null;if(this._responseType===ResponseType.ARRAY_BUFFER&&this._range&&this._range.length>1)if(this._onProgress){this._firstRtt=-1;var t=1024*this._currentChunkSizeKB,r=this._range[0]+this._receivedLength,n=this._range[1];t<this._range[1]-r&&(n=r+t),e=[r,n],this._logger.debug("[xhr_loader->],tast :",this._range,", SubRange, ",e)}else e=this._range,this._logger.debug("[xhr_loader->],tast :",this._range,", allRange, ",e);this._internalOpen(e)}},{key:"_internalOpen",value:function(e){var t=this;try{this._startTime=Date.now();var r=this._xhr=new XMLHttpRequest;r.open(this._method||"GET",this._url,!0),r.responseType=this._responseType,this._timeout&&(r.timeout=this._timeout),r.withCredentials=this._withCredentials,r.onload=this._onLoad.bind(this),r.onreadystatechange=this._onReadyStatechange.bind(this),r.onerror=function(e){var r,n,i;t._running=!1;var a=new NetError(t._url,t._request,null==e||null===(r=e.currentTarget)||void 0===r?void 0:r.response,"xhr.onerror.status:"+(null==e||null===(n=e.currentTarget)||void 0===n?void 0:n.status)+",statusText,"+(null==e||null===(i=e.currentTarget)||void 0===i?void 0:i.statusText));a.options={index:t._index,range:t._range,vid:t._vid,priOptions:t._priOptions},t._loadCompleteReject(a)},r.ontimeout=function(e){t.cancel();var r=new NetError(t._url,t._request,{status:408},"timeout");t._onTimeout&&(r.isTimeout=!0,t._onTimeout(r,{index:t._index,range:t._range,vid:t._vid,priOptions:t._priOptions})),r.options={index:t._index,range:t._range,vid:t._vid,priOptions:t._priOptions},t._loadCompleteReject(r)};var n=this._headers||{},i=getRangeValue(e);i&&(n.Range=i),n&&Object.keys(n).forEach((function(e){r.setRequestHeader(e,n[e])})),this._logger.debug("[xhr.send->] tast,",this._range,",load sub range, ",e),r.send(this._body)}catch(t){t.options={index:this._index,range:e,vid:this._vid,priOptions:this._priOptions},this._loadCompleteReject(t)}}},{key:"_onReadyStatechange",value:function(e){2===e.target.readyState&&this._firstRtt<0&&(this._firstRtt=Date.now())}},{key:"_onLoad",value:function(e){var t,r=e.target.status;if(r<200||r>299){var n=new NetError(this._url,null,_objectSpread2(_objectSpread2({},e.target.response),{},{status:r}),"bad response,status:"+r);return n.options={index:this._index,range:this._range,vid:this._vid,priOptions:this._priOptions},this._loadCompleteReject(n)}var i,a=null,s=!1,o=(null===(t=this._range)||void 0===t?void 0:t.length)>0?this._range[0]:0;if(this._responseType===ResponseType.ARRAY_BUFFER){var u,c=new Uint8Array(e.target.response);if(i=o+this._receivedLength,c&&c.byteLength>0){this._receivedLength+=c.byteLength;var l=Date.now()-this._startTime,d=calculateSpeed(this._receivedLength,l);this.emit(EVENT.REAL_TIME_SPEED,{speed:d,len:this._receivedLength,time:l,vid:this._vid,index:this._index,range:[i,o+this._receivedLength],priOptions:this._priOptions})}a=c,s=!((null===(u=this._range)||void 0===u?void 0:u.length)>1&&this._range[1]&&this._receivedLength<this._range[1]-this._range[0]),this._logger.debug("[xhr load done->], tast :",this._range,", start",i,"end ",o+this._receivedLength,",dataLen,",c?c.byteLength:0,",receivedLength",this._receivedLength,",index,",this._index,", done,",s)}else s=!0,a=e.target.response;var f={ok:r>=200&&r<300,status:r,statusText:this._xhr.statusText,url:this._xhr.responseURL,headers:this._getHeaders(this._xhr),body:this._xhr.response};this._transformResponse&&(f=this._transformResponse(f,this._url)||f),this._onProgress&&this._onProgress(a,s,{index:this._index,vid:this._vid,range:[i,o+this._receivedLength],startTime:this._startTime,endTime:Date.now(),priOptions:this._priOptions},f),s?(this._runing=!1,this._loadCompleteResolve&&this._loadCompleteResolve(createResponse(this._onProgress?null:a,s,f,f.headers["content-length"],f.headers.age,this._startTime,this._firstRtt,this._index,this._range,this._vid,this._priOptions))):this._startLoad()}},{key:"cancel",value:function(){if(!this._aborted)return this._aborted=!0,this._runing=!1,_get(_getPrototypeOf$1(r.prototype),"removeAllListeners",this).call(this),this._onCancel&&this._onCancel({index:this._index,range:this._range,vid:this._vid,priOptions:this._priOptions}),this._xhr?this._xhr.abort():void 0}},{key:"receiveLen",get:function(){return this._receivedLength}},{key:"running",get:function(){return this._running},set:function(e){this._running=e}},{key:"_getHeaders",value:function(e){var t,r={},n=_createForOfIteratorHelper$1(e.getAllResponseHeaders().trim().split("\r\n"));try{for(n.s();!(t=n.n()).done;){var i=t.value.split(": ");r[i[0].toLowerCase()]=i.slice(1).join(": ")}}catch(e){n.e(e)}finally{n.f()}return r}}],[{key:"isSupported",value:function(){return"undefined"!=typeof XMLHttpRequest}}]),r}(),_excluded$2=["retry","retryDelay","onRetryError","transformError"],Task=function(){function e(t,r){_classCallCheck$1(this,e),this.promise=createPublicPromise(),this.alive=!!r.onProgress,!r.logger&&(r.logger=new Logger$2("Loader")),this._loaderType=t,this._loader=t===LoaderType.FETCH&&"undefined"!=typeof fetch?new FetchLoader:new XhrLoader,this._config=r,this._retryCount=0,this._retryTimer=null,this._canceled=!1,this._retryCheckFunc=r.retryCheckFunc,this._logger=r.logger}var t;return _createClass$1(e,[{key:"exec",value:function(){var e=this,t=this._config,r=t.retry,n=t.retryDelay,i=t.onRetryError,a=t.transformError,s=_objectWithoutProperties(t,_excluded$2),o=function(){var t=_asyncToGenerator(_regeneratorRuntime().mark((function t(){var u,c,l;return _regeneratorRuntime().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,e._loader.load(s);case 3:u=t.sent,e.promise.resolve(u),t.next=27;break;case 7:if(t.prev=7,t.t0=t.catch(0),e._loader.running=!1,e._logger.debug("[task request catch err]",t.t0),!e._canceled){t.next=13;break}return t.abrupt("return");case 13:if(t.t0.loaderType=e._loaderType,t.t0.retryCount=e._retryCount,c=t.t0,a&&(c=a(c)||c),i&&e._retryCount>0&&i(c,e._retryCount,{index:s.index,vid:s.vid,range:s.range,priOptions:s.priOptions}),e._retryCount++,l=!0,e._retryCheckFunc&&(l=e._retryCheckFunc(t.t0)),!(l&&e._retryCount<=r)){t.next=26;break}return clearTimeout(e._retryTimer),e._logger.debug("[task request setTimeout],retry",e._retryCount,",retry range,",s.range),e._retryTimer=setTimeout(o,n),t.abrupt("return");case 26:e.promise.reject(c);case 27:case"end":return t.stop()}}),t,null,[[0,7]])})));return function(){return t.apply(this,arguments)}}();return o(),this.promise}},{key:"cancel",value:(t=_asyncToGenerator(_regeneratorRuntime().mark((function e(){return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return clearTimeout(this._retryTimer),this._canceled=!0,this._loader.running=!1,e.abrupt("return",this._loader.cancel());case 4:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"running",get:function(){return this._loader&&this._loader.running}},{key:"loader",get:function(){return this._loader}}]),e}();function isMediaPlaying(e){return e&&!e.paused&&!e.ended&&0!==e.playbackRate&&0!==e.readyState}function getVideoPlaybackQuality(e){if(!e)return{};if("function"==typeof e.getVideoPlaybackQuality){var t=e.getVideoPlaybackQuality();return{droppedVideoFrames:t.droppedVideoFrames||t.corruptedVideoFrames,totalVideoFrames:t.totalVideoFrames,creationTime:t.creationTime}}return{droppedVideoFrames:e.webkitDroppedFrameCount,totalVideoFrames:e.webkitDecodedFrameCount,creationTime:performance.now()}}function concatUint8Array$1(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];if((t=t.filter(Boolean)).length<2)return t[0];var n=new Uint8Array(t.reduce((function(e,t){return e+t.byteLength}),0)),i=0;return t.forEach((function(e){n.set(e,i),i+=e.byteLength})),n}function sleep(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return new Promise((function(t){return setTimeout(t,e)}))}var NetLoader=function(e){_inherits$1(n,EventEmitter);var t,r=_createSuper$1(n);function n(e){var t;return _classCallCheck$1(this,n),_defineProperty$1(_assertThisInitialized$1(t=r.call(this,e)),"type",LoaderType.FETCH),_defineProperty$1(_assertThisInitialized$1(t),"_queue",[]),_defineProperty$1(_assertThisInitialized$1(t),"_alive",[]),_defineProperty$1(_assertThisInitialized$1(t),"_currentTask",null),_defineProperty$1(_assertThisInitialized$1(t),"_finnalUrl",""),_defineProperty$1(_assertThisInitialized$1(t),"_config",void 0),t._config=getConfig$1(e),t._config.loaderType!==LoaderType.XHR&&FetchLoader.isSupported()||(t.type=LoaderType.XHR),t.log=e.logger,t}return _createClass$1(n,[{key:"isFetch",value:function(){return this.type===LoaderType.FETCH}},{key:"load",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"string"!=typeof e&&e?r=e:r.url=e||r.url||this._config.url,(r=Object.assign({},this._config,r)).params&&(r.params=Object.assign({},r.params)),r.headers&&isPlainObject(r.headers)&&(r.headers=Object.assign({},r.headers)),r.body&&isPlainObject(r.body)&&(r.body=Object.assign({},r.body)),r.transformRequest&&(r=r.transformRequest(r)||r),r.logger=this.log;var n=new Task(this.type,r);return n.loader.on(EVENT.REAL_TIME_SPEED,(function(e){t.emit(EVENT.REAL_TIME_SPEED,e)})),this._queue.push(n),1!==this._queue.length||this._currentTask&&this._currentTask.running||this._processTask(),n.promise}},{key:"cancel",value:(t=_asyncToGenerator(_regeneratorRuntime().mark((function e(){var t;return _regeneratorRuntime().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=this._queue.map((function(e){return e.cancel()})).concat(this._alive.map((function(e){return e.cancel()}))),this._currentTask&&t.push(this._currentTask.cancel()),this._queue=[],this._alive=[],e.next=6,Promise.all(t);case 6:return e.next=8,sleep();case 8:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_processTask",value:function(){var e=this;if(this._currentTask=this._queue.shift(),this._currentTask){this._currentTask.alive&&this._alive.push(this._currentTask);var t=this._currentTask.exec().catch((function(e){}));t&&"function"==typeof t.finally&&t.finally((function(){var t,r;null!==(t=e._currentTask)&&void 0!==t&&t.alive&&(null===(r=e._alive)||void 0===r?void 0:r.length)>0&&(e._alive=e._alive.filter((function(t){return t&&t!==e._currentTask}))),e._processTask()}))}}}],[{key:"isFetchSupport",value:function(){return FetchLoader.isSupported()}}]),n}(),GapService=function(){function e(){_classCallCheck$1(this,e),_defineProperty$1(this,"_prevCurrentTime",0)}return _createClass$1(e,[{key:"do",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3,r=arguments.length>2?arguments[2]:void 0,n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1;if(e){var i=e.currentTime,a=0;if(this._prevCurrentTime===i){var s=Buffer$1.info(Buffer$1.get(e),i);if(!s.buffers.length)return;r&&s.nextStart||s.nextStart&&s.nextStart-i<t?a=s.nextStart+.1:s.end&&s.end-i>n&&!e.seeking&&(a=i+.1)}this._prevCurrentTime=i,a&&i!==a&&(e.currentTime=a)}}}]),e}(),SeiService=function(){function e(t){var r=this;_classCallCheck$1(this,e),_defineProperty$1(this,"_seiSet",new Set),this.emitter=t,t.on(EVENT.SEI,(function(e){e&&r._seiSet.add(e)}))}return _createClass$1(e,[{key:"throw",value:function(e,t){var r=this;if(null!=e&&this._seiSet.size){var n=e-.2,i=e+.2,a=[];this._seiSet.forEach((function(e){e.time>=n&&e.time<=i&&a.push(e)})),a.forEach((function(e){r._seiSet.delete(e),r.emitter.emit(EVENT.SEI_IN_TIME,e)})),t&&this._seiSet.forEach((function(t){t.time<e-5&&r._seiSet.delete(t)}))}}},{key:"reset",value:function(){this._seiSet.clear()}}]),e}(),SKIP_SMALL_CHUNK=1e3,MAX_CHUNK_SAVE_SIZE=50,MAX_SEGMENT_SAVE_SIZE=3,LONGTIME_NO_RECEIVE=3e3,BandwidthService=function(){function e(t){_classCallCheck$1(this,e),_defineProperty$1(this,"_chunkSpeed",0),_defineProperty$1(this,"_chunkCache",[]),_defineProperty$1(this,"_speeds",[]),_defineProperty$1(this,"_totalSize",0),_defineProperty$1(this,"_totalCost",0),this._opts=t||{}}return _createClass$1(e,[{key:"addRecord",value:function(e,t){e&&t&&(this._speeds.push(8e3*e/t),this._speeds=this._speeds.slice(-MAX_SEGMENT_SAVE_SIZE))}},{key:"addChunkRecord",value:function(e,t){var r,n;if(e&&t&&!(e<((null===(r=this._opts)||void 0===r?void 0:r.skipChunkSize)||SKIP_SMALL_CHUNK))){this._totalSize+=e,this._totalCost+=t,this._chunkSpeed=8e3*e/t,this._chunkCache.push({size:e,duration:t,timestamp:performance.now()});var i=(null===(n=this._opts)||void 0===n?void 0:n.chunkCountForSpeed)||MAX_CHUNK_SAVE_SIZE;this._chunkCache.length>i&&(this._chunkCache=this._chunkCache.slice(-i))}}},{key:"getAvgSpeed",value:function(){var e;if(!this._chunkCache.length&&!this._speeds.length)return 0;if(this._speeds.length)return this._speeds.reduce((function(e,t){return e+t}))/this._speeds.length;var t=this._chunkCache[this._chunkCache.length-1],r=performance.now()-t.timestamp;return r>((null===(e=this._opts)||void 0===e?void 0:e.longtimeNoReceived)||LONGTIME_NO_RECEIVE)&&this._chunkCache.push({size:0,duration:r,timestamp:performance.now()}),8e3*this._chunkCache.reduce((function(e,t){return e+t.size}),0)/this._chunkCache.reduce((function(e,t){return e+t.duration}),0)}},{key:"getLatestSpeed",value:function(){return this._chunkCache.length||this._speeds.length?this._speeds.length?this._speeds[this._speeds.length-1]:this._chunkSpeed:0}},{key:"getTotalSize",value:function(){return this._totalSize}},{key:"getTotalCost",value:function(){return this._totalCost}},{key:"reset",value:function(){this._chunkCache=[],this._speeds=[],this._totalSize=0,this._totalCost=0}}]),e}(),Stats=function(){function e(t){_classCallCheck$1(this,e),_defineProperty$1(this,"encodeType",""),_defineProperty$1(this,"audioCodec",""),_defineProperty$1(this,"videoCodec",""),_defineProperty$1(this,"domain",""),_defineProperty$1(this,"fps",0),_defineProperty$1(this,"bitrate",0),_defineProperty$1(this,"width",0),_defineProperty$1(this,"height",0),_defineProperty$1(this,"samplerate",0),_defineProperty$1(this,"channelCount",0),_defineProperty$1(this,"gop",0),_defineProperty$1(this,"_bitsAccumulateSize",0),_defineProperty$1(this,"_bitsAccumulateDuration",0),_defineProperty$1(this,"_startGopId",-1),this._timescale=t}return _createClass$1(e,[{key:"getStats",value:function(){return{encodeType:this.encodeType,audioCodec:this.audioCodec,videoCodec:this.videoCodec,domain:this.domain,fps:this.fps,bitrate:this.bitrate,width:this.width,height:this.height,samplerate:this.samplerate,channelCount:this.channelCount,gop:this.gop}}},{key:"setEncodeType",value:function(e){this.encodeType=e}},{key:"setFpsFromScriptData",value:function(e){var t,r=e.data,n=null==r||null===(t=r.onMetaData)||void 0===t?void 0:t.framerate;n&&n>0&&n<100&&(this.fps=n)}},{key:"setVideoMeta",value:function(e){if(this.width=e.width,this.height=e.height,this.videoCodec=e.codec,this.encodeType=e.codecType,e.fpsNum&&e.fpsDen){var t=e.fpsNum/e.fpsDen;t>0&&t<100&&(this.fps=t)}}},{key:"setAudioMeta",value:function(e){this.audioCodec=e.codec,this.samplerate=e.sampleRate,this.channelCount=e.channelCount}},{key:"setDomain",value:function(e){this.domain=e.split("/").slice(2,3)[0]}},{key:"updateBitrate",value:function(e){var t=this;if((!this.fps||this.fps>=100)&&e.length){var r=e.reduce((function(e,t){return e+t.duration}),0)/e.length;this.fps=Math.round(this._timescale/r)}e.forEach((function(e){-1===t._startGopId&&(t._startGopId=e.gopId),e.gopId===t._startGopId&&t.gop++,t._bitsAccumulateDuration+=e.duration/(t._timescale/1e3),t._bitsAccumulateSize+=e.units.reduce((function(e,t){return e+t.length}),0),t._bitsAccumulateDuration>=1e3&&(t.bitrate=8*t._bitsAccumulateSize,t._bitsAccumulateDuration=0,t._bitsAccumulateSize=0)}))}}]),e}(),MediaStatsService=function(){function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1e3;_classCallCheck$1(this,e),_defineProperty$1(this,"_core",null),_defineProperty$1(this,"_samples",[]),this._core=t,this._timescale=r,this._stats=new Stats(r),this._bindEvents()}return _createClass$1(e,[{key:"getStats",value:function(){var e,t,r,n,i,a,s,o,u,c,l,d=(null===(e=this._core)||void 0===e?void 0:e.media)||{},f=d.currentTime,h=void 0===f?0:f,p=d.decodeFps,_=void 0===p?0:p;return _objectSpread2(_objectSpread2({},this._stats.getStats()),{},{downloadSpeed:(null===(t=this._core)||void 0===t||null===(r=t.speedInfo)||void 0===r?void 0:r.call(t).speed)||0,avgSpeed:(null===(n=this._core)||void 0===n||null===(i=n.speedInfo)||void 0===i?void 0:i.call(n).avgSpeed)||0,totalReceivedByte:(null===(a=this._core)||void 0===a||null===(s=a.speedInfo)||void 0===s?void 0:s.call(a).totalSize)||0,totalReceivedCost:(null===(o=this._core)||void 0===o||null===(u=o.speedInfo)||void 0===u?void 0:u.call(o).totalCost)||0,currentTime:h,bufferEnd:(null===(c=this._core)||void 0===c||null===(l=c.bufferInfo())||void 0===l?void 0:l.remaining)||0,decodeFps:_})}},{key:"_bindEvents",value:function(){var e=this;this._core.on(EVENT.DEMUXED_TRACK,(function(t){var r=t.videoTrack;return e._stats.updateBitrate(r.samples)})),this._core.on(EVENT.FLV_SCRIPT_DATA,(function(t){e._stats.setFpsFromScriptData(t)})),this._core.on(EVENT.METADATA_PARSED,(function(t){"video"===t.type?e._stats.setVideoMeta(t.track):e._stats.setAudioMeta(t.track)})),this._core.on(EVENT.TTFB,(function(t){e._stats.setDomain(t.responseUrl)}))}},{key:"reset",value:function(){this._samples=[],this._stats=new Stats(this._timescale)}}]),e}();function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,a,s,o=[],u=!0,c=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=a.call(r)).done)&&(o.push(n.value),o.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return o}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(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,_toPropertyKey(n.key),n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,r){return(t=_toPropertyKey(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&_setPrototypeOf(e,t)}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function _isNativeReflectConstruct(){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}}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(e)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var r,n=_getPrototypeOf(e);if(t){var i=_getPrototypeOf(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return _possibleConstructorReturn(this,r)}}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _createForOfIteratorHelper(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(o)throw a}}}}function _toPrimitive(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function _toPropertyKey(e){var t=_toPrimitive(e,"string");return"symbol"==typeof t?t:String(t)}var TrackType={VIDEO:"video",AUDIO:"audio",METADATA:"metadata"},VideoCodecType={AV1:"av1",AVC:"avc",HEVC:"hevc"},AudioCodecType={AAC:"aac",G711PCMA:"g7110a",G711PCMU:"g7110m",OPUS:"opus",MP3:"mp3"},WarningType={LARGE_AV_SHIFT:"LARGE_AV_SHIFT",LARGE_VIDEO_GAP:"LARGE_VIDEO_GAP",LARGE_VIDEO_GAP_BETWEEN_CHUNK:"LARGE_VIDEO_GAP_BETWEEN_CHUNK",LARGE_AUDIO_GAP:"LARGE_AUDIO_GAP",AUDIO_FILLED:"AUDIO_FILLED",AUDIO_DROPPED:"AUDIO_DROPPED"},VideoTrack=function(){function e(){_classCallCheck(this,e),_defineProperty(this,"id",1),_defineProperty(this,"type",TrackType.VIDEO),_defineProperty(this,"codecType",VideoCodecType.AVC),_defineProperty(this,"pid",-1),_defineProperty(this,"hvcC",void 0),_defineProperty(this,"codec",""),_defineProperty(this,"timescale",0),_defineProperty(this,"formatTimescale",0),_defineProperty(this,"sequenceNumber",0),_defineProperty(this,"baseMediaDecodeTime",0),_defineProperty(this,"baseDts",0),_defineProperty(this,"duration",0),_defineProperty(this,"warnings",[]),_defineProperty(this,"samples",[]),_defineProperty(this,"pps",[]),_defineProperty(this,"sps",[]),_defineProperty(this,"vps",[]),_defineProperty(this,"fpsNum",0),_defineProperty(this,"fpsDen",0),_defineProperty(this,"sarRatio",[]),_defineProperty(this,"width",0),_defineProperty(this,"height",0),_defineProperty(this,"nalUnitSize",4),_defineProperty(this,"present",!1),_defineProperty(this,"isVideoEncryption",!1),_defineProperty(this,"isAudioEncryption",!1),_defineProperty(this,"isVideo",!0),_defineProperty(this,"lastKeyFrameDts",0),_defineProperty(this,"kid",null),_defineProperty(this,"pssh",null),_defineProperty(this,"ext",void 0)}return _createClass(e,[{key:"reset",value:function(){this.sequenceNumber=this.width=this.height=this.fpsDen=this.fpsNum=this.duration=this.baseMediaDecodeTime=this.timescale=0,this.codec="",this.present=!1,this.pid=-1,this.pps=[],this.sps=[],this.vps=[],this.sarRatio=[],this.samples=[],this.warnings=[],this.hvcC=null}},{key:"firstDts",get:function(){return this.samples.length?this.samples[0].dts:null}},{key:"firstPts",get:function(){return this.samples.length?this.samples[0].pts:null}},{key:"samplesDuration",get:function(){if(this.samples.length>0){var e=this.samples[0],t=this.samples[this.samples.length-1];return t.dts-e.dts+t.duration}return 0}},{key:"exist",value:function(){return!!/av01/.test(this.codec)||!!(this.pps.length&&this.sps.length&&this.codec)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isVideoEncryption}}]),e}(),AudioTrack=function(){function e(){_classCallCheck(this,e),_defineProperty(this,"id",2),_defineProperty(this,"type",TrackType.AUDIO),_defineProperty(this,"codecType",AudioCodecType.AAC),_defineProperty(this,"pid",-1),_defineProperty(this,"codec",""),_defineProperty(this,"container",""),_defineProperty(this,"sequenceNumber",0),_defineProperty(this,"sampleDuration",0),_defineProperty(this,"timescale",0),_defineProperty(this,"formatTimescale",0),_defineProperty(this,"baseMediaDecodeTime",0),_defineProperty(this,"duration",0),_defineProperty(this,"warnings",[]),_defineProperty(this,"samples",[]),_defineProperty(this,"baseDts",0),_defineProperty(this,"sampleSize",16),_defineProperty(this,"sampleRate",0),_defineProperty(this,"channelCount",0),_defineProperty(this,"objectType",0),_defineProperty(this,"sampleRateIndex",0),_defineProperty(this,"parsedCodec",null),_defineProperty(this,"config",[]),_defineProperty(this,"present",!1),_defineProperty(this,"isVideoEncryption",!1),_defineProperty(this,"isAudioEncryption",!1),_defineProperty(this,"kid",null),_defineProperty(this,"ext",void 0)}return _createClass(e,[{key:"reset",value:function(){this.sequenceNumber=0,this.timescale=0,this.sampleDuration=0,this.sampleRate=0,this.channelCount=0,this.baseMediaDecodeTime=0,this.present=!1,this.pid=-1,this.codec="",this.samples=[],this.config=[],this.warnings=[]}},{key:"exist",value:function(){return!(!this.sampleRate||!this.channelCount||!this.codec&&!this.container||this.codecType!==AudioCodecType.AAC&&this.codecType!==AudioCodecType.G711PCMA&&this.codecType!==AudioCodecType.G711PCMU&&this.codecType!==AudioCodecType.OPUS&&this.codecType!==AudioCodecType.MP3)}},{key:"hasSample",value:function(){return!!this.samples.length}},{key:"isEncryption",get:function(){return this.isAudioEncryption}},{key:"firstDts",get:function(){return this.samples.length?this.samples[0].dts:null}},{key:"firstPts",get:function(){return this.samples.length?this.samples[0].pts:null}},{key:"samplesDuration",get:function(){if(this.samples.length>0){var e=this.samples[0],t=this.samples[this.samples.length-1];return t.dts-e.dts+t.duration}return 0}}]),e}(),VideoSample=function(){function e(t,r,n){_classCallCheck(this,e),_defineProperty(this,"flag",{}),_defineProperty(this,"keyframe",!1),_defineProperty(this,"gopId",0),_defineProperty(this,"duration",0),_defineProperty(this,"size",0),_defineProperty(this,"units",[]),_defineProperty(this,"chromaFormat",420),this.originPts=this.pts=t,this.originDts=this.dts=r,n&&(this.units=n)}return _createClass(e,[{key:"cts",get:function(){return this.pts-this.dts}},{key:"setToKeyframe",value:function(){this.keyframe=!0,this.flag.dependsOn=2,this.flag.isNonSyncSample=0}}]),e}(),AudioSample=_createClass((function e(t,r,n,i){_classCallCheck(this,e),_defineProperty(this,"duration",1024),_defineProperty(this,"flag",{dependsOn:2,isNonSyncSample:0}),_defineProperty(this,"keyframe",!0),this.originPts=this.pts=this.dts=t,this.data=r,this.size=r.byteLength,this.sampleOffset=i,n&&(this.duration=n)})),Sample=_createClass((function e(t,r){_classCallCheck(this,e),_defineProperty(this,"time",0),this.data=t,this.originPts=this.pts=r})),SeiSample=function(e){_inherits(r,Sample);var t=_createSuper(r);function r(){return _classCallCheck(this,r),t.apply(this,arguments)}return _createClass(r)}(),MetadataTrack=function(){function e(){_classCallCheck(this,e),_defineProperty(this,"id",3),_defineProperty(this,"type",TrackType.METADATA),_defineProperty(this,"timescale",0),_defineProperty(this,"flvScriptSamples",[]),_defineProperty(this,"seiSamples",[])}return _createClass(e,[{key:"exist",value:function(){return!(!this.flvScriptSamples.length&&!this.seiSamples.length||!this.timescale)}},{key:"reset",value:function(){this.timescale=0,this.flvScriptSamples=[],this.seiSamples=[]}},{key:"hasSample",value:function(){return!(!this.flvScriptSamples.length&&!this.seiSamples.length)}}]),e}(),Logger$1=function(){function e(t){_classCallCheck(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]")}return _createClass(e,[{key:"warn",value:function(){var t;if(!e.disabled){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];(t=console).warn.apply(t,[this._prefix].concat(n))}}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();_defineProperty(Logger$1,"disabled",!0);var isBrowser="undefined"!=typeof window,ua=isBrowser&&navigator.userAgent.toLocaleLowerCase(),isSafari=isBrowser&&/^((?!chrome|android).)*safari/.test(ua),isFirefox=isBrowser&&ua.includes("firefox"),isAndroid=isBrowser&&ua.includes("android"),AAC=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"getRateIndexByRate",value:function(t){return e.FREQ.indexOf(t)}},{key:"parseADTS",value:function(t,r){for(var n=t.length,i=0;i+2<n&&(255!==t[i]||240!=(246&t[i+1]));)i++;if(!(i>=n)){var a=i,s=[],o=(60&t[i+2])>>>2,u=e.FREQ[o];if(!u)throw new Error("Invalid sampling index: ".concat(o));for(var c,l,d=1+((192&t[i+2])>>>6),f=(1&t[i+2])<<2|(192&t[i+3])>>>6,h=e._getConfig(o,f,d),p=h.config,_=h.codec,y=0,v=e.getFrameDuration(u);i+7<n;)if(255===t[i]&&240==(246&t[i+1])){if(!(l=(3&t[i+3])<<11|t[i+4]<<3|(224&t[i+5])>>5)||n-i<l)break;c=2*(1&~t[i+1]),s.push({pts:r+y*v,data:t.subarray(i+7+c,i+l)}),y++,i+=l}else i++;return{skip:a,remaining:i>=n?void 0:t.subarray(i),frames:s,samplingFrequencyIndex:o,sampleRate:u,objectType:d,channelCount:f,codec:_,config:p,originCodec:"mp4a.40.".concat(d)}}}},{key:"parseAudioSpecificConfig",value:function(t){if(t.length){var r=t[0]>>>3,n=(7&t[0])<<1|t[1]>>>7,i=(120&t[1])>>>3,a=e.FREQ[n];if(a){var s=e._getConfig(n,i,r);return{samplingFrequencyIndex:n,sampleRate:a,objectType:r,channelCount:i,config:s.config,codec:s.codec,originCodec:"mp4a.40.".concat(r)}}}}},{key:"getFrameDuration",value:function(e){return 1024*(arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4)/e}},{key:"_getConfig",value:function(e,t,r){var n,i,a=[];return isFirefox?e>=6?(n=5,i=e-3):(n=2,i=e):isAndroid?(n=2,i=e):(n=5,i=e,e>=6?i=e-3:1===t&&(n=2,i=e)),a[0]=n<<3,a[0]|=(14&e)>>1,a[1]=(1&e)<<7,a[1]|=t<<3,5===n&&(a[1]|=(14&i)>>1,a[2]=(1&i)<<7,a[2]|=8,a[3]=0),{config:a,codec:"mp4a.40.".concat(n)}}},{key:"getSilentFrame",value: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}();function concatUint8Array(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];t=t.filter(Boolean);var n=new Uint8Array(t.reduce((function(e,t){return e+t.byteLength}),0)),i=0;return t.forEach((function(e){n.set(e,i),i+=e.byteLength})),n}_defineProperty(AAC,"FREQ",[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]);var MAX_SIZE=Math.pow(2,32);function readBig16(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<8)+(e[t+1]||0)}function readBig24(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<16)+(e[t+1]<<8)+(e[t+2]||0)}function readBig32(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+(e[t+3]||0)}function readBig64(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return readBig32(e,t)*MAX_SIZE+readBig32(e,t+4)}function getAvcCodec(e){for(var t,r="avc1.",n=0;n<3;n++)(t=e[n].toString(16)).length<2&&(t="0".concat(t)),r+=t;return r}function parse2(e){if(!Array.isArray(e)){for(var t=[],r="",n=0;n<e.length;n++)n%2&&(r=e[n-1]+e[n],t.push(parseInt(r,16)),r="");return t}return e.map((function(e){return parseInt(e,16)}))}function combineToFloat(e,t){return Number(e+"."+t)}function toDegree(e){if(e.length<5)return 0;var t=Math.hypot(e[0],e[3]),r=Math.hypot(e[1],e[4]);return 0===t||0===r?0:180*Math.atan2(e[1]/r,e[0]/t)/Math.PI}var NALu=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"parseAnnexB",value:function(e){var t=e.byteLength-1,r=0;do{if(0!==e[t])break;r++,t--}while(t>0);r>=3&&(e=e.subarray(0,t+1));for(var n=e.length,i=2,a=0;null!==e[i]&&void 0!==e[i]&&1!==e[i];)i++;if((a=++i+2)>=n)return[];for(var s=[];a<n;)switch(e[a]){case 0:if(0!==e[a-1]){a+=2;break}if(0!==e[a-2]){a++;break}if(a<n-1&&1!==e[a+1]){a++;break}i!==a-2&&s.push(e.subarray(i,a-2));do{a++}while(1!==e[a]&&a<n);a=(i=a+1)+2;break;case 1:if(0!==e[a-1]||0!==e[a-2]){a+=3;break}i!==a-2&&s.push(e.subarray(i,a-2)),a=(i=a+1)+2;break;default:a+=3}return i<n&&s.push(e.subarray(i)),s}},{key:"parseAvcC",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(!(e.length<4)){for(var r,n=e.length,i=[],a=0;a+t<n;)if(r=readBig32(e,a),3===t&&(r>>>=8),a+=t,r){if(a+r>n)break;i.push(e.subarray(a,a+r)),a+=r}return i}}},{key:"parseSEI",value:function(e,t){for(var r=e.length,n=t?2:1,i=0,a=0,s="";255===e[n];)i+=255,n++;for(i+=e[n++];255===e[n];)a+=255,n++;if(a+=e[n++],5===i&&r>n+16)for(var o=0;o<16;o++)s+=e[n].toString(16),n++;return{payload:e.subarray(n,n+a),type:i,size:a,uuid:s}}},{key:"removeEPB",value:function(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(!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}}]),e}(),ExpGolomb=function(){function e(t){if(_classCallCheck(this,e),_defineProperty(this,"_bytesAvailable",void 0),_defineProperty(this,"_bitsAvailable",0),_defineProperty(this,"_word",0),!t)throw new Error("ExpGolomb data params is required");this._data=t,this._bytesAvailable=t.byteLength,this._bytesAvailable&&this._loadWord()}return _createClass(e,[{key:"bitsAvailable",get:function(){return this._bitsAvailable}},{key:"_loadWord",value:function(){var e=this._data.byteLength-this._bytesAvailable,t=Math.min(4,this._bytesAvailable);if(0===t)throw new Error("No bytes available");var r=new Uint8Array(4);r.set(this._data.subarray(e,e+t)),this._word=new DataView(r.buffer).getUint32(0),this._bitsAvailable=8*t,this._bytesAvailable-=t}},{key:"skipBits",value:function(e){if(this._bitsAvailable>e)this._word<<=e,this._bitsAvailable-=e;else{e-=this._bitsAvailable;var t=Math.floor(e/8);e-=8*t,this._bytesAvailable-=t,this._loadWord(),this._word<<=e,this._bitsAvailable-=e}}},{key:"readBits",value:function(e){if(e>32)throw new Error("Cannot read more than 32 bits");var t=Math.min(this._bitsAvailable,e),r=this._word>>>32-t;return this._bitsAvailable-=t,this._bitsAvailable>0?this._word<<=t:this._bytesAvailable>0&&this._loadWord(),(t=e-t)>0&&this._bitsAvailable?r<<t|this.readBits(t):r}},{key:"skipLZ",value:function(){var e;for(e=0;e<this._bitsAvailable;++e)if(0!=(this._word&2147483648>>>e))return this._word<<=e,this._bitsAvailable-=e,e;return this._loadWord(),e+this.skipLZ()}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBool",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){return this.readBits(8)}},{key:"skipScalingList",value: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}}]),e}(),AVC=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"parseAVCDecoderConfigurationRecord",value:function(t){if(!(t.length<7)){for(var r,n,i=1+(3&t[4]),a=[],s=[],o=6,u=31&t[5],c=0;c<u;c++)if(n=t[o]<<8|t[o+1],o+=2,n){var l=t.subarray(o,o+n);o+=n,a.push(l),r||(r=e.parseSPS(NALu.removeEPB(l)))}var d,f=t[o];o++;for(var h=0;h<f;h++)d=t[o]<<8|t[o+1],o+=2,d&&(s.push(t.subarray(o,o+d)),o+=d);return{sps:r,spsArr:a,ppsArr:s,nalUnitSize:i}}}},{key:"parseSPS",value:function(e){var t=new ExpGolomb(e);t.readUByte();var r=t.readUByte(),n=t.readUByte(),i=t.readUByte();t.skipUEG();var a=420;if(100===r||110===r||122===r||244===r||44===r||83===r||86===r||118===r||128===r||138===r||144===r){var s=t.readUEG();if(s<=3&&(a=[0,420,422,444][s]),3===s&&t.skipBits(1),t.skipUEG(),t.skipUEG(),t.skipBits(1),t.readBool())for(var o=3!==s?8:12,u=0;u<o;u++)t.readBool()&&(u<6?t.skipScalingList(16):t.skipScalingList(64))}t.skipUEG();var c=t.readUEG();if(0===c)t.readUEG();else if(1===c){t.skipBits(1),t.skipUEG(),t.skipUEG();for(var l=t.readUEG(),d=0;d<l;d++)t.skipUEG()}t.skipUEG(),t.skipBits(1);var f=t.readUEG(),h=t.readUEG(),p=t.readBits(1);0===p&&t.skipBits(1),t.skipBits(1);var _,y,v,m,g,E=0,b=0,S=0,T=0;if(t.readBool()&&(E=t.readUEG(),b=t.readUEG(),S=t.readUEG(),T=t.readUEG()),t.readBool()){if(t.readBool())switch(t.readUByte()){case 1:_=[1,1];break;case 2:_=[12,11];break;case 3:_=[10,11];break;case 4:_=[16,11];break;case 5:_=[40,33];break;case 6:_=[24,11];break;case 7:_=[20,11];break;case 8:_=[32,11];break;case 9:_=[80,33];break;case 10:_=[18,11];break;case 11:_=[15,11];break;case 12:_=[64,33];break;case 13:_=[160,99];break;case 14:_=[4,3];break;case 15:_=[3,2];break;case 16:_=[2,1];break;case 255:_=[t.readUByte()<<8|t.readUByte(),t.readUByte()<<8|t.readUByte()]}if(t.readBool()&&t.readBool(),t.readBool()&&(t.readBits(4),t.readBool()&&t.readBits(24)),t.readBool()&&(t.readUEG(),t.readUEG()),t.readBool()){var k=t.readBits(32),P=t.readBits(32);y=t.readBool(),g=(v=P)/(m=2*k)}}return{codec:getAvcCodec(e.subarray(1,4)),profileIdc:r,profileCompatibility:n,levelIdc:i,chromaFormat:a,width:Math.ceil(16*(f+1)-2*(E+b)),height:(2-p)*(h+1)*16-(p?2:4)*(S+T),sarRatio:_,fpsNum:v,fpsDen:m,fps:g,fixedFrame:y}}}]),e}(),HEVC=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"parseHEVCDecoderConfigurationRecord",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(t.length<23)){r=r||{};for(var n,i,a,s,o,u=1+(3&t[21]),c=[],l=[],d=[],f=23,h=t[22],p=0;p<h;p++){a=63&t[f],s=t[f+1]<<8|t[f+2],f+=3;for(var _=0;_<s;_++)if(o=t[f]<<8|t[f+1],f+=2,o){switch(a){case 32:var y=t.subarray(f,f+o);n||(n=e.parseVPS(NALu.removeEPB(y),r)),d.push(y);break;case 33:var v=t.subarray(f,f+o);i||(i=e.parseSPS(NALu.removeEPB(v),r)),c.push(v);break;case 34:l.push(t.subarray(f,f+o))}f+=o}}return{hvcC:r,sps:i,spsArr:c,ppsArr:l,vpsArr:d,nalUnitSize:u}}}},{key:"parseVPS",value:function(t,r){r=r||{};var n=new ExpGolomb(t);n.readUByte(),n.readUByte(),n.readBits(12);var i=n.readBits(3);return r.numTemporalLayers=Math.max(r.numTemporalLayers||0,i+1),n.readBits(17),e._parseProfileTierLevel(n,i,r),r}},{key:"parseSPS",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r=r||{};var n=new ExpGolomb(t);n.readUByte(),n.readUByte(),n.readBits(4);var i=n.readBits(3);r.numTemporalLayers=Math.max(i+1,r.numTemporalLayers||0),r.temporalIdNested=n.readBits(1),e._parseProfileTierLevel(n,i,r),n.readUEG();var a=r.chromaFormatIdc=n.readUEG(),s=420;a<=3&&(s=[0,420,422,444][a]);var o=0;3===a&&(o=n.readBits(1));var u,c,l,d,f=n.readUEG(),h=n.readUEG(),p=n.readBits(1);(1===p&&(u=n.readUEG(),c=n.readUEG(),l=n.readUEG(),d=n.readUEG()),r.bitDepthLumaMinus8=n.readUEG(),r.bitDepthChromaMinus8=n.readUEG(),1===p)&&(f-=(1!==a&&2!==a||0!==o?1:2)*(c+u),h-=(1===a&&0===o?2:1)*(d+l));return{codec:"hev1.1.6.L93.B0",width:f,height:h,chromaFormat:s,hvcC:r}}},{key:"_parseProfileTierLevel",value:function(e,t,r){var n=r.generalTierFlag||0;r.generalProfileSpace=e.readBits(2),r.generalTierFlag=Math.max(e.readBits(1),n),r.generalProfileIdc=Math.max(e.readBits(5),r.generalProfileIdc||0),r.generalProfileCompatibilityFlags=e.readBits(32),r.generalConstraintIndicatorFlags=[e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8),e.readBits(8)];var i=e.readBits(8);n<r.generalTierFlag?r.generalLevelIdc=i:r.generalLevelIdc=Math.max(i,r.generalLevelIdc||0);var a=[],s=[];if(t>e.bitsAvailable)throw new Error("maxSubLayersMinus inavlid size ".concat(t));for(var o=0;o<t;o++)a[o]=e.readBits(1),s[o]=e.readBits(1);t>0&&e.readBits(2*(8-t));for(var u=0;u<t;u++)0!==a[u]&&(e.readBits(2),e.readBits(1),e.readBits(5),e.readBits(16),e.readBits(16),e.readBits(4),e.readBits(16),e.readBits(16),e.readBits(12)),0!==s[u]&&e.readBits(8)}}]),e}(),LARGE_AV_FIRST_FRAME_GAP=45e3,AUDIO_GAP_OVERLAP_THRESHOLD_COUNT=3,MAX_SILENT_FRAME_DURATION=9e4,AUDIO_EXCETION_LOG_EMIT_DURATION=45e4,MAX_VIDEO_FRAME_DURATION=9e4,MAX_DTS_DELTA_WITH_NEXT_CHUNK=45e3,LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD=45e4,TsFixer=function(){function e(t,r,n,i){_classCallCheck(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=n,this._baseDts=-1,this._baseVideoDts=-1,this._baseAudioDts=-1,this._baseDtsInited=!1,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=!1,this._videoTimestampBreak=!1,this._lastAudioExceptionGapDot=0,this._lastAudioExceptionOverlapDot=0,this._lastAudioExceptionLargeGapDot=0,this._needForceFixLargeGap=null==i?void 0:i.forceFixLargeGap,this._largeGapThreshold=(null==i?void 0:i.largeGapThreshold)||LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD}return _createClass(e,[{key:"fix",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];t=Math.round(9e4*t);var i=this.videoTrack,a=this.audioTrack,s=i.samples,o=a.samples;if(s.length||o.length){var u=s[0],c=o[0],l=0;if(s.length&&o.length&&(l=u.dts-c.pts),this._baseDtsInited||this._calculateBaseDts(this.audioTrack,this.videoTrack),r&&(this._calculateBaseDts(this.audioTrack,this.videoTrack),this._baseDts-=t,this._baseAudioDts-=t,this._baseVideoDts-=t),!n){this._videoNextDts=l>0?t+l:t,this._audioNextPts=l>0?t:t-l,this._needForceFixLargeGap&&(this._videoNextDts=0,this._audioNextPts=0);var d=u?u.dts-this._baseDts-this._videoNextDts:0,f=c?c.pts-this._baseDts-this._audioNextPts:0;Math.abs(d||f)>MAX_VIDEO_FRAME_DURATION&&(this._calculateBaseDts(this.audioTrack,this.videoTrack),this._baseDts-=t)}if(this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(a),this._fixVideo(i),this.metadataTrack.exist()){var h=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/h}))}i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].dts),a.samples.length&&(a.baseMediaDecodeTime=a.samples[0].pts*a.timescale/9e4)}}},{key:"_fixVideo",value:function(e){var t=this,r=e.samples;if(r.length){if(r.forEach((function(e){e.dts-=t._needForceFixLargeGap?t._baseVideoDts:t._baseDts,e.pts-=t._needForceFixLargeGap?t._baseVideoDts:t._baseDts})),void 0===this._videoNextDts){var n=r[0];this._videoNextDts=n.dts}var i,a,s=r.length,o=0,u=r[0],c=r[1],l=this._videoNextDts-u.dts;if(Math.abs(l)>MAX_DTS_DELTA_WITH_NEXT_CHUNK)if(e.warnings.push({type:WarningType.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts/90,firstSampleDts:u.dts/90,nextSampleDts:((null===(i=r[1])||void 0===i?void 0:i.dts)||0)/90,sampleDuration:l/90}),u.dts+=l,u.pts+=l,c&&Math.abs(c.dts-u.dts)>MAX_VIDEO_FRAME_DURATION)this._videoTimestampBreak=!0,r.forEach((function(e,t){0!==t&&(e.dts+=l,e.pts+=l)}));else for(var d=1;d<=s-1;d++){var f,h=null===(f=r[d])||void 0===f?void 0:f.dts,p=r[d-1].dts;h&&h-p<0&&(r[d].dts+=l,r[d].pts+=l)}if(e.fpsNum&&e.fpsDen&&(a=e.timescale*(e.fpsDen/e.fpsNum)),a<900&&(a=0),!a){var _=e.samples[0],y=e.samples[1];a=1===s?9e3:Math.floor(y.dts-_.dts)}for(var v=0;v<s;v++){var m=r[v].dts,g=r[v+1];if((o=v<s-1?g.dts-m:r[v-1]?Math.min(m-r[v-1].dts,a):a)>MAX_VIDEO_FRAME_DURATION||o<0){this._videoTimestampBreak=!0,o=this._audioTimestampBreak?a:Math.max(o,2700);var E=this._audioNextPts||0;g&&g.dts>E&&(o=a),e.warnings.push({type:WarningType.LARGE_VIDEO_GAP,time:m/e.timescale,dts:m,originDts:r[v].originDts,nextDts:this._videoNextDts,sampleDuration:o,refSampleDuration:a})}r[v].duration=o,this._videoNextDts+=o}}}},{key:"_fixAudio",value:function(e){var t=this,r=e.samples;if(r.length)if(e.codecType!==AudioCodecType.MP3)r.forEach((function(e){e.pts-=t._needForceFixLargeGap?t._baseAudioDts:t._baseDts,e.dts=e.pts})),this._doFixAudioInternal(e,r,9e4);else{this.lastAudioSample&&r.unshift(this.lastAudioSample);for(var n=0;n<r.length;n++){var i=r[n];if(!r[n+1])break;i.duration=r[n+1].pts-i.pts,i.pts-=this._baseDts,i.dts=i.pts}this.lastAudioSample=r.pop()}}},{key:"_calculateBaseDts",value:function(e,t){var r=e.samples,n=t.samples;if(!r.length&&!n.length)return!1;var i=1/0,a=1/0;r.length&&(e.baseDts=i=r[0].pts,this._baseAudioDts=i),n.length&&(t.baseDts=a=n[0].dts,this._baseVideoDts=a),this._baseDts=Math.min(i,a);var s=a-i,o=!1;return Number.isFinite(s)&&Math.abs(s)>LARGE_AV_FIRST_FRAME_GAP&&t.warnings.push({type:WarningType.LARGE_AV_SHIFT,videoBaseDts:a,audioBasePts:i,baseDts:this._baseDts,delta:s}),Number.isFinite(s)&&Math.abs(s)>this._largeGapThreshold*MAX_SILENT_FRAME_DURATION&&(o=!0),this._baseDtsInited||(o&&this._needForceFixLargeGap?this._needForceFixLargeGap=!0:this._needForceFixLargeGap=!1),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){if(this._baseDtsInited&&this._videoTimestampBreak&&this._audioTimestampBreak){if(!this._calculateBaseDts(this.audioTrack,this.videoTrack))return;this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts),this._audioLastSample=null,this._videoLastSample=null,this._videoTimestampBreak=!1,this._audioTimestampBreak=!1}}},{key:"_doFixAudioInternal",value:function(e,t,r){e.sampleDuration||(e.sampleDuration=AAC.getFrameDuration(e.timescale,r));var n=e.sampleDuration;if(void 0===this._audioNextPts){var i=t[0];this._audioNextPts=i.pts}for(var a=0;a<t.length;a++){var s=this._audioNextPts,o=t[a],u=o.pts-s;if(!this._audioTimestampBreak&&u>=AUDIO_GAP_OVERLAP_THRESHOLD_COUNT*n&&u<=MAX_SILENT_FRAME_DURATION&&!isSafari){var c=AAC.getSilentFrame(e.parsedCodec||e.codec,e.channelCount)||t[0].data.subarray(),l=Math.floor(u/n);Math.abs(o.pts-this._lastAudioExceptionGapDot)>AUDIO_EXCETION_LOG_EMIT_DURATION&&(this._lastAudioExceptionGapDot=o.pts),e.warnings.push({type:WarningType.AUDIO_FILLED,pts:o.pts/90,originPts:o.originPts,count:l,nextPts:s/90,refSampleDuration:n});for(var d=0;d<l;d++){var f=new AudioSample(Math.floor(s),c);f.originPts=Math.floor(this._baseDts+s),t.splice(a,0,f),this._audioNextPts+=n,a++}a--}else u<=-AUDIO_GAP_OVERLAP_THRESHOLD_COUNT*n&&u>=-1*MAX_SILENT_FRAME_DURATION?(Math.abs(o.pts-this._lastAudioExceptionOverlapDot)>AUDIO_EXCETION_LOG_EMIT_DURATION&&(this._lastAudioExceptionOverlapDot=o.pts,e.warnings.push({type:WarningType.AUDIO_DROPPED,pts:o.pts/90,originPts:o.originPts,nextPts:s/90,refSampleDuration:n})),t.splice(a,1),a--):(Math.abs(u)>=MAX_SILENT_FRAME_DURATION&&(this._audioTimestampBreak=!0,Math.abs(o.pts-this._lastAudioExceptionLargeGapDot)>AUDIO_EXCETION_LOG_EMIT_DURATION&&(this._lastAudioExceptionLargeGapDot=o.pts,e.warnings.push({type:WarningType.LARGE_AUDIO_GAP,time:o.pts/1e3,pts:o.pts/90,originPts:o.originPts,nextPts:s/90,sampleDuration:u,refSampleDuration:n}))),o.dts=o.pts=s,this._audioNextPts+=n)}}}]),e}(),BitratesMap=[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],FREQ=[44100,48e3,32e3,22050,24e3,16e3,11025,12e3,8e3],SamplesCoefficients=[[0,72,144,12],[0,0,0,0],[0,72,144,12],[0,144,144,12]],BytesInSlot=[0,1,1,4],chromeVersion=null,MPEG=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"isHeader",value:function(e,t){return t+1<e.length&&255===e[t]&&224==(224&e[t+1])&&0!=(6&e[t+1])}},{key:"appendFrame",value:function(t,r,n,i,a){if(!(n+24>r.length)){var s=e.parseHeader(r,n);if(s&&n+s.frameLength<=r.length){var o=i+a*(9e4*s.samplesPerFrame/s.sampleRate),u={data:r.subarray(n,n+s.frameLength),pts:o,dts:o};return u.size=u.data.byteLength,t.config=[],t.channelCount=s.channelCount,t.sampleRate=s.sampleRate,isFirefox?t.codec="mp3":t.container="audio/mpeg",t.samples.push(u),{length:s.frameLength}}}}},{key:"parseHeader",value:function(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,u=1e3*BitratesMap[14*(3===r?3-n:3===n?3:4)+i-1],c=FREQ[3*(3===r?0:2===r?1:2)+a],l=3===o?1:2,d=SamplesCoefficients[r][n],f=BytesInSlot[n],h=8*d*f,p=Math.floor(d*u/c+s)*f;if(null===chromeVersion){var _=(navigator.userAgent||"").match(/Chrome\/(\d+)/i);chromeVersion=_?parseInt(_[1]):0}return!!chromeVersion&&chromeVersion<=87&&2===n&&u>=224e3&&0===o&&(e[t+3]=128|e[t+3]),{sampleRate:c,channelCount:l,frameLength:p,samplesPerFrame:h}}}}]),e}(),logger$4=new Logger$1("TsDemuxer"),TsDemuxer=function(){function e(t,r,n){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};_classCallCheck(this,e),_defineProperty(this,"_pmtId",-1),_defineProperty(this,"_remainingPacketData",null),_defineProperty(this,"_videoPesData",[]),_defineProperty(this,"_audioPesData",[]),_defineProperty(this,"_gopId",0),this.videoTrack=t||new VideoTrack,this.audioTrack=r||new AudioTrack,this.metadataTrack=n||new MetadataTrack,this._fixer=new TsFixer(this.videoTrack,this.audioTrack,this.metadataTrack,i)}return _createClass(e,[{key:"demux",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=this.audioTrack,i=this.videoTrack,a=this.metadataTrack;t&&(this._pmtId=-1,i.reset(),n.reset(),a.reset()),!r||t?(this._remainingPacketData=null,this._videoPesData=[],this._audioPesData=[]):(i.samples=[],n.samples=[],a.seiSamples=[],i.warnings=[],n.warnings=[],this._remainingPacketData&&(e=concatUint8Array(this._remainingPacketData,e),this._remainingPacketData=null));var s=e.length,o=s%188;o&&(this._remainingPacketData=e.subarray(s-o),s-=o);for(var u=i.pid,c=n.pid,l=0;l<s;l+=188){if(71!==e[l])throw new Error("TS packet did not start with 0x47");var d=!!(64&e[l+1]),f=((31&e[l+1])<<8)+e[l+2],h=void 0;if((48&e[l+3])>>4>1){if((h=l+5+e[l+4])===l+188)continue}else h=l+4;switch(f){case 0:d&&(h+=e[h]+1),this._pmtId=(31&e[h+10])<<8|e[h+11];break;case this._pmtId:d&&(h+=e[h]+1);var p=h+3+((15&e[h+1])<<8|e[h+2])-4;for(h+=12+((15&e[h+10])<<8|e[h+11]);h<p;){var _=(31&e[h+1])<<8|e[h+2];switch(e[h]){case 15:n.pid=c=_;break;case 3:case 4:-1===n.pid&&(n.pid=c=_,n.codecType=AudioCodecType.MP3);break;case 27:if(-1!==u)break;i.codecType=VideoCodecType.AVC,i.pid=u=_;break;case 36:if(-1!==u)break;i.codecType=VideoCodecType.HEVC,i.pid=u=_;break;default:logger$4.warn("Unsupported stream. type: ".concat(e[h],", pid: ").concat(_))}h+=5+((15&e[h+3])<<8|e[h+4])}break;case u:d&&this._videoPesData.length&&this._parseVideoData(),this._videoPesData.push(e.subarray(h,l+188));break;case c:d&&this._audioPesData.length&&this._parseAudioData(),this._audioPesData.push(e.subarray(h,l+188));break;case 17:case 8191:break;default:logger$4.warn("Unknown pid: ".concat(f))}}return this._parseVideoData(),this._parseAudioData(),n.formatTimescale=i.formatTimescale=i.timescale=a.timescale=9e4,n.timescale=n.sampleRate||0,{videoTrack:i,audioTrack:n,metadataTrack:a}}},{key:"fix",value:function(e,t,r){return this._fixer.fix(e,t,r),{videoTrack:this.videoTrack,audioTrack:this.audioTrack,metadataTrack:this.metadataTrack}}},{key:"demuxAndFix",value:function(e,t,r,n){return this.demux(e,t,r),this.fix(n,t,r)}},{key:"_parseVideoData",value:function(){if(this._videoPesData.length){var t=e._parsePES(concatUint8Array.apply(void 0,_toConsumableArray(this._videoPesData)));if(t){var r=NALu.parseAnnexB(t.data);r?this._createVideoSample(r,t.pts,t.dts):logger$4.warn("Cannot parse avc units",t),this._videoPesData=[]}else logger$4.warn("Cannot parse video pes",this._videoPesData)}}},{key:"_createVideoSample",value:function(e,t,r){var n=this;if(e.length){var i=this.videoTrack,a=i.codecType===VideoCodecType.HEVC,s=new VideoSample(t,r);e.forEach((function(e){var r=a?e[0]>>>1&63:31&e[0];switch(r){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!a&&5!==r||a&&5===r)break;s.setToKeyframe(),n._gopId++;break;case 6:case 39:case 40:if(!a&&6!==r||a&&6===r)break;return void n.metadataTrack.seiSamples.push(new SeiSample(NALu.parseSEI(NALu.removeEPB(e),a),t));case 32:if(!a)break;if(!i.vps.length){var o=HEVC.parseVPS(NALu.removeEPB(e),i.hvcC);i.hvcC=i.hvcC||o,i.vps=[e]}break;case 7:case 33:if(!a&&7!==r||a&&7===r)break;if(!i.sps.length){var u=NALu.removeEPB(e),c=a?HEVC.parseSPS(u,i.hvcC):AVC.parseSPS(u);i.sps=[e],i.hvcC=i.hvcC||c.hvcC,i.codec=c.codec,i.width=c.width,i.height=c.height,i.sarRatio=c.sarRatio,i.fpsNum=c.fpsNum,i.fpsDen=c.fpsDen}break;case 8:case 34:if(!a&&8!==r||a&&8===r)break;i.pps.length||(i.pps=[e]);break;case 9:case 35:break;case 38:if(a){for(var l=!1,d=2;d<e.byteLength;d++)if(255===e[d]){l=!0;break}if(!l)return}}s.units.push(e)})),s.gopId=this._gopId,this._pushVideoSample(i,s)}}},{key:"_pushVideoSample",value:function(e,t){if(t.units.length)if(null===t.pts||void 0===t.pts){logger$4.warn("Video sample no pts",t);var r=e.samples[e.samples.length-1];r?(t.pts=r.pts,t.dts=r.dts):logger$4.warn("Drop video sample",t)}else e.samples.push(t)}},{key:"_parseAudioData",value:function(){if(this._audioPesData.length){var t=e._parsePES(concatUint8Array.apply(void 0,_toConsumableArray(this._audioPesData)));if(t){switch(this.audioTrack.codecType){case AudioCodecType.AAC:this._parseAacData(t);break;case AudioCodecType.MP3:this._parseMPEG(t)}this._audioPesData=[]}else logger$4.warn("Cannot parse audio pes",this._audioPesData)}}},{key:"_parseAacData",value:function(e){var t=this.audioTrack,r=e.pts;if(null==r){if(logger$4.warn("AAC pes not pts",t),!t.samples.length||!t.sampleRate)return;r=t.samples[t.samples.length-1].pts+AAC.getFrameDuration(t.sampleRate)}var n,i=AAC.parseADTS(e.data,r);i?(t.codec=i.codec,t.channelCount=i.channelCount,t.sampleRate=i.sampleRate,t.objectType=i.objectType,t.sampleRateIndex=i.samplingFrequencyIndex,t.config=i.config,t.parsedCodec=i.originCodec,(n=t.samples).push.apply(n,_toConsumableArray(i.frames.map((function(e){return new AudioSample(e.pts,e.data)})))),i.skip&&logger$4.warn("Skip aac adts ".concat(i.skip," bits")),i.remaining&&logger$4.warn("Remaining aac adts ".concat(i.remaining," bits"))):logger$4.warn("Cannot parse aac adts",e)}},{key:"_parseMPEG",value:function(e){var t=e.data,r=t.length,n=0,i=0,a=e.pts;if(void 0!==a)for(;i<r;)if(MPEG.isHeader(t,i)){var s=MPEG.appendFrame(this.audioTrack,t,i,a,n);if(!s)break;i+=s.length,n++}else i++;else logger$4.warn("[tsdemuxer]: MPEG PES unknown PTS")}}],[{key:"probe",value:function(e){return!!e.length&&(71===e[0]&&71===e[188]&&71===e[376])}},{key:"_parsePES",value:function(e){var t=e[8];if(!(null==t||e.length<t+9)&&1===(e[0]<<16|e[1]<<8|e[2])){var r=(e[4]<<8)+e[5];if(!(r&&r>e.length-6)){var n,i,a=e[7];return 192&a&&(n=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&a?n-(i=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(n=i):i=n),{data:e.subarray(9+t),pts:n,dts:i}}}}}]),e}(),ByteReader=function(){function e(t,r,n){_classCallCheck(this,e),this.dv=new DataView(t),this.start=this.offset=r||this.dv.byteOffset,this.end=n?this.start+n:this.start+this.dv.byteLength}return _createClass(e,[{key:"buffer",get:function(){return this.dv.buffer}},{key:"unreadLength",get:function(){return Math.max(this.end-this.offset,0)}},{key:"size",get:function(){return this.end-this.start}},{key:"readFloat",value:function(e){var t=0;switch(e){case 4:t=this.dv.getFloat32(this.offset);break;case 8:t=this.dv.getFloat64(this.offset);break;default:throw new Error("read ".concat(e,"-byte float is not supported"))}return this.offset+=e,t}},{key:"back",value:function(e){this.offset-=e}},{key:"skip",value:function(e){this.offset+=e}},{key:"readInt",value:function(e){var t=this.offset;switch(this.offset+=e,e){case 1:return this.dv.getInt8(t);case 2:return this.dv.getInt16(t);case 4:return this.dv.getInt32(t);default:throw new Error("read ".concat(e,"-byte integers is not supported"))}}},{key:"read",value:function(e){var t=this.offset;switch(this.offset+=e,e){case 1:return this.dv.getUint8(t);case 2:return this.dv.getUint16(t);case 3:return(this.dv.getUint16(t)<<8)+this.dv.getUint8(t+2);case 4:return this.dv.getUint32(t);default:return this.back(e-4),this.read(e-4)+this.dv.getUint32(t)*Math.pow(256,e-4)}}},{key:"write",value:function(e,t){var r=this.offset;switch(this.offset+=e,e){case 1:return this.dv.setUint8(r,t);case 2:return this.dv.setUint16(r,t);case 3:return this.dv.setUint8(r,t>>>16),this.dv.setUint16(r+1,65535&t);case 4:return this.dv.setUint32(r,t);default:throw new Error("write ".concat(e,"-byte integers is not supported"))}}},{key:"readToBuffer",value:function(e){var t;return t=this.offset||e?this.dv.buffer.slice(this.offset,e?this.offset+e:this.end):this.dv.buffer,this.offset+=t.byteLength,t}},{key:"readToUint8",value:function(e){var t=new Uint8Array(this.dv.buffer,this.offset,e||this.unreadLength);return this.offset+=t.byteLength,t}},{key:"readString",value:function(e){for(var t=0,r="";t<e;t++)r+=String.fromCharCode(this.dv.getUint8(this.offset)),this.offset++;return r}}],[{key:"fromUint8",value:function(t){return new e(t.buffer,t.byteOffset,t.byteLength)}},{key:"concatUint8s",value:function(e){var t=new Uint8Array(e.reduce((function(e,t){return e+t.byteLength}),0)),r=0;return e.forEach((function(e){t.set(e,r),r+=e.byteLength})),t}},{key:"concatUint8",value:function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return this.concatUint8s(t)}}]),e}(),BitReader=function(){function e(t,r){_classCallCheck(this,e),this.offset=0,this.val=t,this.size=r}return _createClass(e,[{key:"skip",value:function(e){this.offset+=e}},{key:"read",value:function(e){var t=this.size-this.offset-e;if(t>=0){var r=0,n=0;if(this.offset+=e,this.size>31){for(;n<e;n++)r+=Math.pow(2,n);return this.val/Math.pow(2,t)&r}for(;n<e;n++)r+=1<<n;return this.val>>>t&r}throw new Error("the number of the read operation exceeds the total length limit of bits")}}],[{key:"fromByte",value:function(t,r){return new e(t.read(r),r<<3)}}]),e}(),MP4Parser=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"findBox",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=[];if(!t)return i;for(var a=0,s="",o=0;t.length>7;){if(a=readBig32(t),s=String.fromCharCode.apply(null,t.subarray(4,8)),o=8,1===a?(a=readBig64(t,8),o+=8):a||(a=t.length),!r[0]||s===r[0]){var u=t.subarray(0,a);if(!(r.length<2))return e.findBox(u.subarray(o),r.slice(1),n+o);i.push({start:n,size:a,headerSize:o,type:s,data:u})}n+=a,t=t.subarray(a)}return i}},{key:"tfhd",value:function(e){return parseBox(e,!0,(function(e,t){e.trackId=readBig32(t);var r=4,n=1&e.flags,i=2&e.flags,a=8&e.flags,s=16&e.flags,o=32&e.flags;n&&(r+=4,e.baseDataOffset=readBig32(t,r),r+=4),i&&(e.sampleDescriptionIndex=readBig32(t,r),r+=4),a&&(e.defaultSampleDuration=readBig32(t,r),r+=4),s&&(e.defaultSampleSize=readBig32(t,r),r+=4),o&&(e.defaultSampleFlags=readBig32(t,r))}))}},{key:"sidx",value:function(e){return parseBox(e,!0,(function(e,t){var r=0;e.reference_ID=readBig32(t,r),r+=4,e.timescale=readBig32(t,r),r+=4,0===e.version?(e.earliest_presentation_time=readBig32(t,r),r+=4,e.first_offset=readBig32(t,r),r+=4):(e.earliest_presentation_time=readBig64(t,r),r+=8,e.first_offset=readBig64(t,r),r+=8),r+=2,e.references=[];var n=readBig16(t,r);r+=2;for(var i=0;i<n;i++){var a={};e.references.push(a);var s=readBig32(t,r);r+=4,a.reference_type=s>>31&1,a.referenced_size=2147483647&s,a.subsegment_duration=readBig32(t,r),s=readBig32(t,r+=4),r+=4,a.starts_with_SAP=s>>31&1,a.SAP_type=s>>28&7,a.SAP_delta_time=268435455&s}}))}},{key:"moov",value:function(t){return parseBox(t,!1,(function(t,r,n){t.mvhd=e.mvhd(e.findBox(r,["mvhd"],n)[0]),t.trak=e.findBox(r,["trak"],n).map((function(t){return e.trak(t)})),t.pssh=e.pssh(e.findBox(r,["pssh"],n)[0])}))}},{key:"mvhd",value:function(e){return parseBox(e,!0,(function(e,t){var r=0;1===e.version?(e.timescale=readBig32(t,16),e.duration=readBig64(t,20),r+=28):(e.timescale=readBig32(t,8),e.duration=readBig32(t,12),r+=16),e.nextTrackId=readBig32(t,r+76)}))}},{key:"trak",value:function(t){return parseBox(t,!1,(function(t,r,n){t.tkhd=e.tkhd(e.findBox(r,["tkhd"],n)[0]),t.mdia=e.mdia(e.findBox(r,["mdia"],n)[0])}))}},{key:"tkhd",value:function(e){return parseBox(e,!0,(function(e,t){var r=ByteReader.fromUint8(t);1===e.version?(r.read(8),r.read(8),e.trackId=r.read(4),r.read(4),e.duration=r.read(8)):(r.read(4),r.read(4),e.trackId=r.read(4),r.read(4),e.duration=r.read(4)),r.skip(16),e.matrix=[];for(var n=0;n<36;n++)e.matrix.push(r.read(1));r.back(36);for(var i,a=[],s=0;s<3;s++)a.push(combineToFloat(r.readInt(2),r.readInt(2))),a.push(combineToFloat(r.readInt(2),r.readInt(2))),i=r.readInt(4),a.push(combineToFloat(i>>30,1073741823&i));e.rotation=toDegree(a),e.width=r.read(4),e.height=r.read(4)}))}},{key:"mdia",value:function(t){return parseBox(t,!1,(function(t,r,n){t.mdhd=e.mdhd(e.findBox(r,["mdhd"],n)[0]),t.hdlr=e.hdlr(e.findBox(r,["hdlr"],n)[0]),t.minf=e.minf(e.findBox(r,["minf"],n)[0])}))}},{key:"mdhd",value:function(e){return parseBox(e,!0,(function(e,t){var r=0;1===e.version?(e.timescale=readBig32(t,16),e.duration=readBig64(t,20),r+=28):(e.timescale=readBig32(t,8),e.duration=readBig32(t,12),r+=16);var n=readBig16(t,r);e.language=String.fromCharCode(96+(n>>10&31),96+(n>>5&31),96+(31&n))}))}},{key:"hdlr",value:function(e){return parseBox(e,!0,(function(e,t){0===e.version&&(e.handlerType=String.fromCharCode.apply(null,t.subarray(4,8)))}))}},{key:"minf",value:function(t){return parseBox(t,!1,(function(t,r,n){t.vmhd=e.vmhd(e.findBox(r,["vmhd"],n)[0]),t.smhd=e.smhd(e.findBox(r,["smhd"],n)[0]),t.stbl=e.stbl(e.findBox(r,["stbl"],n)[0])}))}},{key:"vmhd",value:function(e){return parseBox(e,!0,(function(e,t){e.graphicsmode=readBig16(t),e.opcolor=[readBig16(t,2),readBig16(t,4),readBig16(t,6)]}))}},{key:"smhd",value:function(e){return parseBox(e,!0,(function(e,t){e.balance=readBig16(t)}))}},{key:"stbl",value:function(t){return parseBox(t,!1,(function(t,r,n){var i,a,s;t.stsd=e.stsd(e.findBox(r,["stsd"],n)[0]),t.stts=e.stts(e.findBox(r,["stts"],n)[0]),t.ctts=e.ctts(e.findBox(r,["ctts"],n)[0]),t.stsc=e.stsc(e.findBox(r,["stsc"],n)[0]),t.stsz=e.stsz(e.findBox(r,["stsz"],n)[0]),t.stco=e.stco(e.findBox(r,["stco"],n)[0]),t.stco||(t.co64=e.co64(e.findBox(r,["co64"],n)[0]),t.stco=t.co64);var o=null===(i=t.stsd.entries[0])||void 0===i||null===(a=i.sinf)||void 0===a||null===(s=a.schi)||void 0===s?void 0:s.tenc.default_IV_size;t.stss=e.stss(e.findBox(r,["stss"],n)[0]),t.senc=e.senc(e.findBox(r,["senc"],n)[0],o)}))}},{key:"senc",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8;return parseBox(e,!0,(function(e,r){var n=0,i=readBig32(r,n);n+=4,e.samples=[];for(var a=0;a<i;a++){for(var s={InitializationVector:[]},o=0;o<t;o++)s.InitializationVector[o]=r[n+o];if(n+=t,2&e.flags){s.subsamples=[];var u=readBig16(r,n);n+=2;for(var c=0;c<u;c++){var l={};l.BytesOfClearData=readBig16(r,n),n+=2,l.BytesOfProtectedData=readBig32(r,n),n+=4,s.subsamples.push(l)}}e.samples.push(s)}}))}},{key:"pssh",value:function(e){return parseBox(e,!0,(function(e,t){for(var r=[],n=[],i=0,a=0;a<16;a++)n.push(toHex(t[i+a]));if(i+=16,e.version>0){var s=readBig32(t,i);i+=4;for(var o=0;o<(""+s).length;o++)for(var u=0;u<16;u++){var c=t[i];i+=1,r.push(toHex(c))}}var l=readBig32(t,i);e.data_size=l,i+=4,e.kid=r,e.system_id=n,e.buffer=t}))}},{key:"stsd",value:function(t){return parseBox(t,!0,(function(t,r,n){t.entryCount=readBig32(r),t.entries=e.findBox(r.subarray(4),[],n+4).map((function(t){switch(t.type){case"av01":return e.av01(t);case"avc1":case"avc2":case"avc3":case"avc4":return e.avc1(t);case"hvc1":case"hev1":return e.hvc1(t);case"mp4a":return e.mp4a(t);case"alaw":case"ulaw":return e.alaw(t);case"enca":return parseBox(t,!1,(function(t,r,n){t.channelCount=readBig16(r,16),t.samplesize=readBig16(r,18),t.sampleRate=readBig32(r,24)/65536,r=r.subarray(28),t.sinf=e.sinf(e.findBox(r,["sinf"],n)[0]),t.esds=e.esds(e.findBox(r,["esds"],n)[0])}));case"encv":return parseBox(t,!1,(function(t,r,n){t.width=readBig16(r,24),t.height=readBig16(r,26),t.horizresolution=readBig32(r,28),t.vertresolution=readBig32(r,32),r=r.subarray(78),t.sinf=e.sinf(e.findBox(r,["sinf"],n)[0]),t.avcC=e.avcC(e.findBox(r,["avcC"],n)[0]),t.hvcC=e.hvcC(e.findBox(r,["hvcC"],n)[0]),t.pasp=e.pasp(e.findBox(r,["pasp"],n)[0])}))}})).filter(Boolean)}))}},{key:"tenc",value:function(e){return parseBox(e,!1,(function(e,t){var r=6;e.default_IsEncrypted=t[r],r+=1,e.default_IV_size=t[r],r+=1,e.default_KID=[];for(var n=0;n<16;n++)e.default_KID.push(toHex(t[r])),r+=1}))}},{key:"schi",value:function(t){return parseBox(t,!1,(function(t,r,n){t.tenc=e.tenc(e.findBox(r,["tenc"],n)[0])}))}},{key:"sinf",value:function(t){return parseBox(t,!1,(function(t,r,n){t.schi=e.schi(e.findBox(r,["schi"],n)[0]),t.frma=e.frma(e.findBox(r,["frma"],n)[0])}))}},{key:"frma",value:function(e){return parseBox(e,!1,(function(e,t){e.data_format="";for(var r=0;r<4;r++)e.data_format+=String.fromCharCode(t[r])}))}},{key:"colr",value:function(e){return parseBox(e,!1,(function(t,r){var n=ByteReader.fromUint8(r);t.data=e.data,t.colorType=n.readString(4),"nclx"===t.colorType?(t.colorPrimaries=n.read(2),t.transferCharacteristics=n.read(2),t.matrixCoefficients=n.read(2),t.fullRangeFlag=n.read(1)>>7):"rICC"!==t.colorType&&"prof"!==t.colorType||(t.iccProfile=r.readToUint8())}))}},{key:"av01",value:function(t){return parseBox(t,!1,(function(t,r,n){var i=parseVisualSampleEntry(t,r),a=r.subarray(i);n+=i,t.av1C=e.av1C(e.findBox(a,["av1C"],n)[0]),t.colr=e.colr(e.findBox(a,["colr"],n)[0])}))}},{key:"av1C",value:function(e){return parseBox(e,!1,(function(t,r){t.data=e.data;var n,i=ByteReader.fromUint8(r),a=BitReader.fromByte(i,4);t.marker=a.read(1),t.version=a.read(7),t.seqProfile=a.read(3),t.seqLevelIdx0=a.read(5),t.seqTier0=a.read(1),t.highBitdepth=a.read(1),t.twelveBit=a.read(1),t.monochrome=a.read(1),t.chromaSubsamplingX=a.read(1),t.chromaSubsamplingY=a.read(1),t.chromaSamplePosition=a.read(2),t.reserved=a.read(3),t.initialPresentationDelayPresent=a.read(1),t.initialPresentationDelayPresent?t.initialPresentationDelayMinusOne=a.read(4):t.initialPresentationDelayMinusOne=0,t.configOBUs=i.readToUint8(),2===t.seqLevelIdx0&&1===t.highBitdepth?n=1===t.twelveBit?"12":"10":t.seqProfile<=2&&(n=1===t.highBitdepth?"10":"08"),t.codec=["av01",t.seqProfile,(t.seqLevelIdx0<10?"0"+t.seqLevelIdx0:t.seqLevelIdx0)+(t.seqTier0?"H":"M"),n].join(".")}))}},{key:"avc1",value:function(t){return parseBox(t,!1,(function(t,r,n){var i=parseVisualSampleEntry(t,r),a=r.subarray(i);n+=i,t.avcC=e.avcC(e.findBox(a,["avcC"],n)[0]),t.pasp=e.pasp(e.findBox(a,["pasp"],n)[0])}))}},{key:"avcC",value:function(e){return parseBox(e,!1,(function(t,r){t.data=e.data,t.configurationVersion=r[0],t.AVCProfileIndication=r[1],t.profileCompatibility=r[2],t.AVCLevelIndication=r[3],t.codec=getAvcCodec([r[1],r[2],r[3]]),t.lengthSizeMinusOne=3&r[4],t.spsLength=31&r[5],t.sps=[];for(var n=6,i=0;i<t.spsLength;i++){var a=readBig16(r,n);n+=2,t.sps.push(r.subarray(n,n+a)),n+=a}t.ppsLength=r[n],n+=1,t.pps=[];for(var s=0;s<t.ppsLength;s++){var o=readBig16(r,n);n+=2,t.pps.push(r.subarray(n,n+=o)),n+=o}}))}},{key:"hvc1",value:function(t){return parseBox(t,!1,(function(t,r,n){var i=parseVisualSampleEntry(t,r),a=r.subarray(i);n+=i,t.hvcC=e.hvcC(e.findBox(a,["hvcC"],n)[0]),t.pasp=e.pasp(e.findBox(a,["pasp"],n)[0])}))}},{key:"hvcC",value:function(e){return parseBox(e,!1,(function(t,r){t.data=e.data,t.codec="hev1.1.6.L93.B0",t.configurationVersion=r[0];var n=r[1];t.generalProfileSpace=n>>6,t.generalTierFlag=(32&n)>>5,t.generalProfileIdc=31&n,t.generalProfileCompatibility=readBig32(r,2),t.generalConstraintIndicatorFlags=r.subarray(6,12),t.generalLevelIdc=r[12],t.avgFrameRate=readBig16(r,19),t.numOfArrays=r[22],t.vps=[],t.sps=[],t.pps=[];for(var i=23,a=0,s=0,o=0,u=0;u<t.numOfArrays;u++){a=63&r[i],s=readBig16(r,i+1),i+=3;for(var c,l=[],d=0;d<s;d++)o=readBig16(r,i),i+=2,l.push(r.subarray(i,i+o)),i+=o;if(32===a)(c=t.vps).push.apply(c,l);else if(33===a){var f;(f=t.sps).push.apply(f,l)}else if(34===a){var h;(h=t.pps).push.apply(h,l)}}}))}},{key:"pasp",value:function(e){return parseBox(e,!1,(function(e,t){e.hSpacing=readBig32(t),e.vSpacing=readBig32(t,4)}))}},{key:"mp4a",value:function(t){return parseBox(t,!1,(function(t,r,n){var i=parseAudioSampleEntry(t,r);t.esds=e.esds(e.findBox(r.subarray(i),["esds"],n+i)[0])}))}},{key:"esds",value:function(e){return parseBox(e,!0,(function(e,t){e.codec="mp4a.";for(var r=0,n=0,i=0,a=0;t.length;){for(a=t[r=0],n=t[r+1],r+=2;128&n;)i=(127&n)<<7,n=t[r],r+=1;if(i+=127&n,3===a)t=t.subarray(r+3);else{if(4!==a){if(5===a){var s=e.config=t.subarray(r,r+i),o=(248&s[0])>>3;if(31===o&&s.length>=2&&(o=32+((7&s[0])<<3)+((224&s[1])>>5)),e.objectType=o,e.codec+=o.toString(16),/^mp4a/gi.test(e.codec)&&s.length>=2){var u=(7&s[0])<<1|(128&s[1])>>7;e.samplingFrequencyIndex=u,u<AAC.FREQ.length&&(e.sampleRate=AAC.FREQ[u])}return void("."===e.codec[e.codec.length-1]&&(e.codec=e.codec.substring(0,e.codec.length-1)))}return void("."===e.codec[e.codec.length-1]&&(e.codec=e.codec.substring(0,e.codec.length-1)))}e.codec+=(t[r].toString(16)+".").padStart(3,"0"),t=t.subarray(r+13)}}}))}},{key:"alaw",value:function(e){return parseBox(e,!1,(function(e,t){parseAudioSampleEntry(e,t)}))}},{key:"stts",value:function(e){return parseBox(e,!0,(function(e,t){for(var r=readBig32(t),n=[],i=4,a=0;a<r;a++)n.push({count:readBig32(t,i),delta:readBig32(t,i+4)}),i+=8;e.entryCount=r,e.entries=n}))}},{key:"ctts",value:function(e){return parseBox(e,!0,(function(e,t){var r=readBig32(t),n=[],i=4;if(1===e.version)for(var a=0;a<r;a++)n.push({count:readBig32(t,i),offset:readBig32(t,i+4)}),i+=8;else for(var s=0;s<r;s++)n.push({count:readBig32(t,i),offset:-(1+~readBig32(t,i+4))}),i+=8;e.entryCount=r,e.entries=n}))}},{key:"stsc",value:function(e){return parseBox(e,!0,(function(e,t){for(var r=readBig32(t),n=[],i=4,a=0;a<r;a++)n.push({firstChunk:readBig32(t,i),samplesPerChunk:readBig32(t,i+4),sampleDescriptionIndex:readBig32(t,i+8)}),i+=12;e.entryCount=r,e.entries=n}))}},{key:"stsz",value:function(e){return parseBox(e,!0,(function(e,t){var r=readBig32(t),n=readBig32(t,4),i=[];if(!r)for(var a=8,s=0;s<n;s++)i.push(readBig32(t,a)),a+=4;e.sampleSize=r,e.sampleCount=n,e.entrySizes=i}))}},{key:"stco",value:function(e){return parseBox(e,!0,(function(e,t){for(var r=readBig32(t),n=[],i=4,a=0;a<r;a++)n.push(readBig32(t,i)),i+=4;e.entryCount=r,e.entries=n}))}},{key:"co64",value:function(e){return parseBox(e,!0,(function(e,t){for(var r=readBig32(t),n=[],i=4,a=0;a<r;a++)n.push(readBig64(t,i)),i+=8;e.entryCount=r,e.entries=n}))}},{key:"stss",value:function(e){return parseBox(e,!0,(function(e,t){for(var r=readBig32(t),n=[],i=4,a=0;a<r;a++)n.push(readBig32(t,i)),i+=4;e.entryCount=r,e.entries=n}))}},{key:"moof",value:function(t){return parseBox(t,!1,(function(t,r,n){t.mfhd=e.mfhd(e.findBox(r,["mfhd"],n)[0]),t.traf=e.findBox(r,["traf"],n).map((function(t){return e.traf(t)}))}))}},{key:"mfhd",value:function(e){return parseBox(e,!0,(function(e,t){e.sequenceNumber=readBig32(t)}))}},{key:"traf",value:function(t){return parseBox(t,!1,(function(t,r,n){t.tfhd=e.tfhd(e.findBox(r,["tfhd"],n)[0]),t.tfdt=e.tfdt(e.findBox(r,["tfdt"],n)[0]),t.trun=e.trun(e.findBox(r,["trun"],n)[0])}))}},{key:"trun",value:function(e){return parseBox(e,!0,(function(e,t){var r=e.version,n=e.flags,i=t.length,a=e.sampleCount=readBig32(t),s=4;if(i>s&&1&n&&(e.dataOffset=-(1+~readBig32(t,s)),s+=4),i>s&&4&n&&(e.firstSampleFlags=readBig32(t,s),s+=4),e.samples=[],i>s)for(var o,u=0;u<a;u++)o={},256&n&&(o.duration=readBig32(t,s),s+=4),512&n&&(o.size=readBig32(t,s),s+=4),1024&n&&(o.flags=readBig32(t,s),s+=4),2048&n&&(o.cts=r?-(1+~readBig32(t,s+4)):readBig32(t,s),s+=4),e.samples.push(o)}))}},{key:"tfdt",value:function(e){return parseBox(e,!0,(function(e,t){1===e.version?e.baseMediaDecodeTime=readBig64(t):e.baseMediaDecodeTime=readBig32(t)}))}},{key:"probe",value:function(t){return!!e.findBox(t,["ftyp"])}},{key:"parseSampleFlags",value:function(e){return{isLeading:(12&e[0])>>>2,dependsOn:3&e[0],isDependedOn:(192&e[1])>>>6,hasRedundancy:(48&e[1])>>>4,paddingValue:(14&e[1])>>>1,isNonSyncSample:1&e[1],degradationPriority:e[2]<<8|e[3]}}},{key:"moovToTrack",value:function(e,t,r){var n,i,a=e.trak;if(a&&a.length){var s=a.find((function(e){var t,r;return"vide"===(null===(t=e.mdia)||void 0===t||null===(r=t.hdlr)||void 0===r?void 0:r.handlerType)})),o=a.find((function(e){var t,r;return"soun"===(null===(t=e.mdia)||void 0===t||null===(r=t.hdlr)||void 0===r?void 0:r.handlerType)}));if(s&&t){var u,c,l,d,f,h,p,_=t,y=null===(u=s.tkhd)||void 0===u?void 0:u.trackId;null!=y&&(_.id=s.tkhd.trackId),_.tkhdDuration=s.tkhd.duration,_.mvhdDurtion=e.mvhd.duration,_.mvhdTimecale=e.mvhd.timescale,_.timescale=_.formatTimescale=s.mdia.mdhd.timescale,_.duration=s.mdia.mdhd.duration||_.mvhdDurtion/_.mvhdTimecale*_.timescale,_.rotation=s.tkhd.rotation,_.matrix=s.tkhd.matrix;var v,m,g,E,b,S,T,k,P=s.mdia.minf.stbl.stsd.entries[0];if(_.width=P.width,_.height=P.height,P.pasp&&(_.sarRatio=[P.pasp.hSpacing,P.pasp.vSpacing]),P.av1C)_.codecType=VideoCodecType.AV1,_.codec=P.av1C.codec,_.av1C=P.av1C.data,P.colr&&(_.colr=P.colr.data);else if(P.hvcC)_.codecType=VideoCodecType.HEVC,_.codec=P.hvcC.codec,_.vps=P.hvcC.vps,_.sps=P.hvcC.sps,_.pps=P.hvcC.pps,_.hvcC=P.hvcC.data;else{if(!P.avcC)throw new Error("unknown video stsd entry");_.codec=P.avcC.codec,_.sps=P.avcC.sps,_.pps=P.avcC.pps}if(_.present=!0,_.ext={},_.ext.stss=null===(c=s.mdia)||void 0===c||null===(l=c.minf)||void 0===l||null===(d=l.stbl)||void 0===d?void 0:d.stss,_.ext.ctts=null===(f=s.mdia)||void 0===f||null===(h=f.minf)||void 0===h||null===(p=h.stbl)||void 0===p?void 0:p.ctts,P&&"encv"===P.type)_.isVideoEncryption=!0,P.default_KID=null===(v=P.sinf)||void 0===v||null===(m=v.schi)||void 0===m?void 0:m.tenc.default_KID,P.default_IsEncrypted=null===(g=P.sinf)||void 0===g||null===(E=g.schi)||void 0===E?void 0:E.tenc.default_IsEncrypted,P.default_IV_size=null===(b=P.sinf)||void 0===b||null===(S=b.schi)||void 0===S?void 0:S.tenc.default_IV_size,_.videoSenc=s.mdia.minf.stbl.senc&&s.mdia.minf.stbl.senc.samples,P.data_format=null===(T=P.sinf)||void 0===T||null===(k=T.frma)||void 0===k?void 0:k.data_format,_.useEME=e.useEME,_.kidValue=e.kidValue,_.pssh=e.pssh,_.encv=P}if(o&&r){var A,x,w,C,R,$,D,O,I,L=r,M=null===(A=o.tkhd)||void 0===A?void 0:A.trackId;null!=M&&(L.id=o.tkhd.trackId),L.tkhdDuration=o.tkhd.duration,L.mvhdDurtion=e.mvhd.duration,L.mvhdTimecale=e.mvhd.timescale,L.timescale=L.formatTimescale=o.mdia.mdhd.timescale,L.duration=o.mdia.mdhd.duration||L.mvhdDurtion/L.mvhdTimecale*L.timescale;var B,U,N,F,j,V,G,z,H=o.mdia.minf.stbl.stsd.entries[0];switch(L.sampleSize=H.sampleSize,L.sampleRate=getAudioSampleRate(H),L.channelCount=H.channelCount,L.present=!0,H.type){case"alaw":L.codecType=L.codec=AudioCodecType.G711PCMA,L.sampleRate=8e3;break;case"ulaw":L.codecType=L.codec=AudioCodecType.G711PCMU,L.sampleRate=8e3;break;default:L.sampleDuration=AAC.getFrameDuration(L.sampleRate,L.timescale),L.sampleRateIndex=AAC.getRateIndexByRate(L.sampleRate),L.objectType=(null===(n=H.esds)||void 0===n?void 0:n.objectType)||2,H.esds&&(L.config=Array.from(H.esds.config)),L.codec=(null===(i=H.esds)||void 0===i?void 0:i.codec)||"mp4a.40.2"}if(L.sampleDuration=AAC.getFrameDuration(L.sampleRate,L.timescale),L.objectType=(null===(x=H.esds)||void 0===x?void 0:x.objectType)||2,H.esds&&(H.esds.config?L.config=Array.from(H.esds.config):console.warn("esds config is null")),L.codec=(null===(w=H.esds)||void 0===w?void 0:w.codec)||"mp4a.40.2",L.sampleRateIndex=AAC.getRateIndexByRate(L.sampleRate),L.ext={},L.ext.stss=null===(C=o.mdia)||void 0===C||null===(R=C.minf)||void 0===R||null===($=R.stbl)||void 0===$?void 0:$.stss,L.ext.ctts=null===(D=o.mdia)||void 0===D||null===(O=D.minf)||void 0===O||null===(I=O.stbl)||void 0===I?void 0:I.ctts,L.present=!0,H&&"enca"===H.type)L.isAudioEncryption=!0,H.data_format=null===(B=H.sinf)||void 0===B||null===(U=B.frma)||void 0===U?void 0:U.data_format,H.default_KID=null===(N=H.sinf)||void 0===N||null===(F=N.schi)||void 0===F?void 0:F.tenc.default_KID,H.default_IsEncrypted=null===(j=H.sinf)||void 0===j||null===(V=j.schi)||void 0===V?void 0:V.tenc.default_IsEncrypted,H.default_IV_size=null===(G=H.sinf)||void 0===G||null===(z=G.schi)||void 0===z?void 0:z.tenc.default_IV_size,L.audioSenc=o.mdia.minf.stbl.senc&&o.mdia.minf.stbl.senc.samples,L.useEME=e.useEME,L.kidValue=e.kidValue,L.enca=H}if(r&&(r.isVideoEncryption=!!t&&t.isVideoEncryption),t&&(t.isAudioEncryption=!!r&&r.isAudioEncryption),null!=t&&t.encv||null!=r&&r.enca){var X,K,W=null==t||null===(X=t.encv)||void 0===X?void 0:X.default_KID,Y=null==r||null===(K=r.enca)||void 0===K?void 0:K.default_KID,q=W||Y?(W||Y).join(""):null;t&&(t.kid=q),r&&(r.kid=q)}return t&&(t.flags=3841),r&&(r.flags=1793),{videoTrack:t,audioTrack:r}}}},{key:"evaluateDefaultDuration",value:function(e,t,r){var n,i=null==t||null===(n=t.samples)||void 0===n?void 0:n.length;return i?1024*i/t.timescale*e.timescale/r:1024}},{key:"moofToSamples",value:function(t,r,n){var i={};return t.mfhd&&(r&&(r.sequenceNumber=t.mfhd.sequenceNumber),n&&(n.sequenceNumber=t.mfhd.sequenceNumber)),t.traf.forEach((function(t){var a=t.tfhd,s=t.tfdt,o=t.trun;if(a&&o){s&&(r&&r.id===a.trackId&&(r.baseMediaDecodeTime=s.baseMediaDecodeTime),n&&n.id===a.trackId&&(n.baseMediaDecodeTime=s.baseMediaDecodeTime));var u=a.defaultSampleSize||0,c=a.defaultSampleDuration||e.evaluateDefaultDuration(r,n,o.samples.length||o.sampleCount),l=o.dataOffset||0,d=0,f=-1;if(!o.samples.length&&o.sampleCount){i[a.trackId]=[];for(var h=0;h<o.sampleCount;h++)i[a.trackId].push({offset:l,dts:d,duration:c,size:u}),d+=c,l+=u}else i[a.trackId]=o.samples.map((function(e,t){return(e={offset:l,dts:d,pts:d+(e.cts||0),duration:e.duration||c,size:e.size||u,gopId:f,keyframe:0===t||null!==e.flags&&void 0!==e.flags&&(65536&e.flags)>>>0!=65536}).keyframe&&(f++,e.gopId=f),d+=e.duration,l+=e.size,e}))}})),i}},{key:"moovToSamples",value:function(e){var t=e.trak;if(t&&t.length){var r=t.find((function(e){var t,r;return"vide"===(null===(t=e.mdia)||void 0===t||null===(r=t.hdlr)||void 0===r?void 0:r.handlerType)})),n=t.find((function(e){var t,r;return"soun"===(null===(t=e.mdia)||void 0===t||null===(r=t.hdlr)||void 0===r?void 0:r.handlerType)}));if(r||n){var i,a;if(r){var s,o,u=null===(s=r.mdia)||void 0===s||null===(o=s.minf)||void 0===o?void 0:o.stbl;if(!u)return;var c=u.stts,l=u.stsc,d=u.stsz,f=u.stco,h=u.stss,p=u.ctts;if(!(c&&l&&d&&f&&h))return;i=getSamples(c,l,d,f,p,h)}if(n){var _,y,v,m=null===(_=n.mdia)||void 0===_||null===(y=_.minf)||void 0===y?void 0:y.stbl;if(!m)return;var g=null===(v=n.mdia.mdhd)||void 0===v?void 0:v.timescale,E=m.stts,b=m.stsc,S=m.stsz,T=m.stco;if(!(g&&E&&b&&S&&T))return;a=getSamples(E,b,S,T)}return{videoSamples:i,audioSamples:a}}}}}]),e}();function getAudioSampleRate(e){return("mp4a"===e.type?e.sampleRate>0?e.sampleRate:e.esds.sampleRate:e.sampleRate)||0}function getSamples(e,t,r,n,i,a){var s,o,u,c=[],l=null==i?void 0:i.entries,d=t.entries,f=n.entries,h=r.entrySizes,p=null==a?void 0:a.entries;p&&(s={},p.forEach((function(e){s[e-1]=!0}))),l&&(o=[],l.forEach((function(e){for(var t=e.count,r=e.offset,n=0;n<t;n++)o.push(r)})));var _=-1,y=0,v=0,m=0,g=0,E=0,b=d[0].samplesPerChunk,S=d[1]?d[1].firstChunk-1:1/0;return e.entries.forEach((function(e){for(var t=e.count,n=e.delta,i=0;i<t;i++)u={dts:y,duration:n,size:h[v]||r.sampleSize,offset:f[m]+E,index:v},p&&(u.keyframe=s[v],u.keyframe&&_++,u.gopId=_),o&&v<o.length&&(u.pts=u.dts+o[v]),c.push(u),y+=n,++v<b?E+=u.size:(m++,E=0,m>=S&&(g++,S=d[g+1]?d[g+1].firstChunk-1:1/0),b+=d[g].samplesPerChunk)})),c}function parseVisualSampleEntry(e,t){return e.dataReferenceIndex=readBig16(t,6),e.width=readBig16(t,24),e.height=readBig16(t,26),e.horizresolution=readBig32(t,28),e.vertresolution=readBig32(t,32),e.frameCount=readBig16(t,40),e.depth=readBig16(t,74),78}function parseAudioSampleEntry(e,t){return e.dataReferenceIndex=readBig16(t,6),e.channelCount=readBig16(t,16),e.sampleSize=readBig16(t,18),e.sampleRate=readBig32(t,24)/65536,28}function parseBox(e,t,r){if(e){if(e.size!==e.data.length)throw new Error("box ".concat(e.type," size !== data.length"));var n={start:e.start,size:e.size,headerSize:e.headerSize,type:e.type};return t&&(n.version=e.data[e.headerSize],n.flags=readBig24(e.data,e.headerSize+1),n.headerSize+=4),r(n,e.data.subarray(n.headerSize),n.start+n.headerSize),n}}var padStart=function(e,t,r){for(var n=String(r),i=t>>0,a=Math.ceil(i/n.length),s=[],o=String(e);a--;)s.push(n);return s.join("").substring(0,i-o.length)+o},toHex=function(){for(var e=[],t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return r.forEach((function(t){e.push(padStart(Number(t).toString(16),2,0))})),e[0]},FMP4Demuxer=function(){function e(t,r,n){_classCallCheck(this,e),_defineProperty(this,"__loadedMoofWraps",[]),_defineProperty(this,"__lastRemainData",null),_defineProperty(this,"__lastRemainDataStart",0),_defineProperty(this,"__nextMoofStart",-1),this.videoTrack=t||new VideoTrack,this.audioTrack=r||new AudioTrack,this.metadataTrack=n||new MetadataTrack}return _createClass(e,[{key:"demuxPart",value:function(e,t,r){var n=this,i=this.videoTrack,a=this.audioTrack,s=i.exist(),o=a.exist(),u=/av01/.test(i.codec);i.samples=[],a.samples=[];var c=e,l=t;if(this.__lastRemainData){var d=this.__lastRemainDataStart+this.__lastRemainData.byteLength;if(t<=d&&t>this.__lastRemainDataStart&&t+e.byteLength>d){var f=e.subarray(this.__lastRemainData.byteLength+this.__lastRemainDataStart-t);c=concatUint8Array(this.__lastRemainData,f),l=this.__lastRemainDataStart,this.__lastRemainData=null}else this.__lastRemainData=null,this.__lastRemainDataStart=0,this.__nextMoofStart=-1}if(!r){var h=MP4Parser.findBox(c,["moov"])[0];if(!h)throw new Error("cannot found moov box");r=MP4Parser.moov(h)}if(c){var p=l+c.byteLength;s||o||MP4Parser.moovToTrack(r,i,a);var _=[];this.__nextMoofStart<0?MP4Parser.findBox(c,["moof"],l).forEach((function(e){return _.push(e)})):this.__nextMoofStart>=l&&this.__nextMoofStart<=p-8&&MP4Parser.findBox(c.subarray(this.__nextMoofStart-l),["moof"],this.__nextMoofStart).forEach((function(e){return _.push(e)})),_.filter((function(e){return e.size<=e.data.length})).forEach((function(e){var t=MP4Parser.moof(e);n.__nextMoofStart=t.start+Math.max.apply(Math,_toConsumableArray(t.traf.map((function(e){return e.trun.samples.reduce((function(e,t){return e+t.size}),e.trun.dataOffset||0)})))),n.__loadedMoofWraps.push({start:t.start,nextMoofStart:n.__nextMoofStart,moof:t}),n.__loadedMoofWraps.sort((function(e,t){return e.start-t.start}))}));var y,v=_createForOfIteratorHelper(this.__loadedMoofWraps);try{var m=function(){var e=y.value;if(e.start>p||e.nextMoofStart<l)return"continue";var t,r=e.start,s=MP4Parser.moofToSamples(e.moof,i,a),o=i.baseMediaDecodeTime,d=a.baseMediaDecodeTime;Object.keys(s).forEach((function(e){i.id==e?s[e].some((function(e){var a=e.offset+=r;if(!(a<l)){if(a+e.size>p)return!0;var s=new VideoSample((e.pts||e.dts)+o,e.dts+o);s.duration=e.duration,s.gopId=e.gopId,e.keyframe&&s.setToKeyframe();var d=c.subarray(a-l,a-l+e.size);if(s.data=d,!u)for(var f=0,h=d.length-1;f<h;)t=readBig32(d,f),f+=4,s.units.push(d.subarray(f,f+t)),f+=t;n.__lastRemainDataStart=a+e.size,i.samples.push(s)}})):a.id==e&&s[e].some((function(e){var t=e.offset+r;if(!(t<l)){if(t+e.size>p)return!0;var i=c.subarray(t-l,t-l+e.size);a.samples.push(new AudioSample(e.dts+d,i,e.duration)),n.__lastRemainDataStart=t+e.size}}))}))};for(v.s();!(y=v.n()).done;)m()}catch(e){v.e(e)}finally{v.f()}}return this.__lastRemainDataStart>l&&this.__lastRemainDataStart<c.byteLength+l?this.__lastRemainData=c.subarray(this.__lastRemainDataStart-l):(this.__lastRemainData=c,this.__lastRemainDataStart=l),i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].pts),a.samples.length&&(a.baseMediaDecodeTime=a.samples[0].pts),{videoTrack:i,audioTrack:a,metadataTrack:this.metadataTrack}}},{key:"demux",value:function(e,t){var r=this.videoTrack,n=this.audioTrack,i=r.exist(),a=n.exist();if(r.samples=[],n.samples=[],t){if(!a){var s=MP4Parser.findBox(t,["moov"])[0];if(!s)throw new Error("cannot found moov box");MP4Parser.moovToTrack(MP4Parser.moov(s),null,n)}var o=MP4Parser.findBox(t,["moof"])[0];if(o){var u=MP4Parser.moofToSamples(MP4Parser.moof(o),null,n)[n.id],c=n.baseMediaDecodeTime;if(u){var l=o.start;u.map((function(e){e.offset+=l;var r=t.subarray(e.offset,e.offset+e.size);n.samples.push(new AudioSample(e.dts+c,r,e.duration))}))}}}if(e){if(!i&&!a){var d=MP4Parser.findBox(e,["moov"])[0];if(!d)throw new Error("cannot found moov box");MP4Parser.moovToTrack(MP4Parser.moov(d),r,n)}var f=MP4Parser.findBox(e,["moof"])[0];if(f){var h,p=MP4Parser.moofToSamples(MP4Parser.moof(f),r,n),_=r.baseMediaDecodeTime,y=n.baseMediaDecodeTime,v=f.start;Object.keys(p).forEach((function(t){r.id==t?p[t].map((function(t){t.offset+=v;var n=new VideoSample((t.pts||t.dts)+_,t.dts+_);n.duration=t.duration,n.gopId=t.gopId,t.keyframe&&n.setToKeyframe();var i=e.subarray(t.offset,t.offset+t.size);n.data=i;for(var a=0,s=i.length-1;a<s;)h=readBig32(i,a),a+=4,n.units.push(i.subarray(a,a+h)),a+=h;r.samples.push(n)})):n.id==t&&p[t].map((function(t){t.offset+=v;var r=e.subarray(t.offset,t.offset+t.size);n.samples.push(new AudioSample(t.dts+y,r,t.duration))}))}))}}return{videoTrack:r,audioTrack:n,metadataTrack:this.metadataTrack}}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset(),this.metadataTrack.reset()}}],[{key:"probe",value:function(e){return MP4Parser.probe(e)}}]),e}();function Concat(e){for(var t=0,r=arguments.length,n=new Array(r>1?r-1:0),i=1;i<r;i++)n[i-1]=arguments[i];n.forEach((function(e){t+=e.length}));var a=new e(t),s=0;return n.forEach((function(e){a.set(e,s),s+=e.length})),a}var Buffer=function(){function e(){_classCallCheck(this,e),this.buffer=new Uint8Array(0)}return _createClass(e,[{key:"write",value:function(){for(var e=this,t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];r.forEach((function(t){t?e.buffer=Concat(Uint8Array,e.buffer,t):window.console.warn(t)}))}}],[{key:"writeUint16",value:function(e){return new Uint8Array([e>>8&255,255&e])}},{key:"writeUint32",value:function(e){return new Uint8Array([e>>24,e>>16&255,e>>8&255,255&e])}}]),e}(),UINT32_MAX=Math.pow(2,32)-1,MP4=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"box",value: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];var i=8+(r=r.filter(Boolean)).reduce((function(e,t){return e+t.byteLength}),0),a=new Uint8Array(i);a[0]=i>>24&255,a[1]=i>>16&255,a[2]=i>>8&255,a[3]=255&i,a.set(e,4);var s=8;return r.forEach((function(e){a.set(e,s),s+=e.byteLength})),a}},{key:"ftyp",value:function(t){return t.find((function(e){return e.type===TrackType.VIDEO&&e.codecType===VideoCodecType.HEVC}))?e.FTYPHEV1:e.FTYPAVC1}},{key:"initSegment",value:function(t){return concatUint8Array(e.ftyp(t),e.moov(t))}},{key:"pssh",value:function(t){var r=new Uint8Array([1,0,0,0].concat([16,119,239,236,192,178,77,2,172,227,60,30,82,226,251,75],[0,0,0,1],parse2(t.kid),[0,0,0,0]));return e.box(e.types.pssh,r)}},{key:"moov",value:function(t){if(t[0].useEME&&(t[0].encv||t[0].enca)){t[0].pssh||(t[0].pssh={kid:t[0].kid});var r=this.pssh(t[0].pssh);return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale),e.mvex(t)].concat(_toConsumableArray(t.map((function(t){return e.trak(t)}))),[r]))}return e.box.apply(e,[e.types.moov,e.mvhd(t[0].mvhdDurtion||t[0].duration,t[0].mvhdTimecale||t[0].timescale)].concat(_toConsumableArray(t.map((function(t){return e.trak(t)}))),[e.mvex(t)]))}},{key:"mvhd",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return e.box(e.types.mvhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,t>>24&255,t>>16&255,t>>8&255,255&t,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]))}},{key:"trak",value:function(t){return e.box(e.types.trak,e.tkhd(t.id,t.tkhdDuration||0,t.width,t.height),e.mdia(t))}},{key:"tkhd",value:function(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,t>>24&255,t>>16&255,t>>8&255,255&t,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,n>>8&255,255&n,0,0,i>>8&255,255&i,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.duration,t.timescale),e.hdlr(t.type),e.minf(t))}},{key:"mdhd",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,t>>24&255,t>>16&255,t>>8&255,255&t,85,196,0,0]))}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"minf",value:function(t){return e.box(e.types.minf,t.type===TrackType.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stbl(t))}},{key:"stbl",value:function(t){var r=[];return t&&t.ext&&t.ext.stss&&r.push(e.stss(t.ext.stss.entries)),e.box(e.types.stbl,e.stsd(t),e.STTS,r[0],e.STSC,e.STSZ,e.STCO)}},{key:"stsd",value:function(t){var r;return r="audio"===t.type?t.useEME&&t.enca?e.enca(t):t.codecType===AudioCodecType.OPUS?e.opus(t):e.mp4a(t):t.useEME&&t.encv?e.encv(t):t.av1C?e.av01(t):e.avc1hev1(t),e.box(e.types.stsd,new Uint8Array([0,0,0,0,0,0,0,1]),r)}},{key:"enca",value:function(t){var r=t.enca.channelCount,n=t.enca.sampleRate,i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,r,0,16,0,0,0,0,n>>8&255,255&n,0,0]),a=e.esds(t.config),s=e.sinf(t.enca);return e.box(e.types.enca,i,a,s)}},{key:"encv",value:function(t){var r,n,i=t.sps.length>0?t.sps[0]:[],a=t.pps.length>0?t.pps[0]:[],s=t.width,o=t.height,u=t.sarRatio[0],c=t.sarRatio[1],l=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,s>>8&255,255&s,o>>8&255,255&o,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,100,97,105,108,121,109,111,116,105,111,110,47,104,108,115,46,106,115,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),d=new Uint8Array((r=(n=[1,i[1],i[2],i[3],255,225,i.length>>>8&255,255&i.length]).concat.apply(n,_toConsumableArray(i)).concat([1,a.length>>>8&255,255&a.length])).concat.apply(r,_toConsumableArray(a))),f=new Uint8Array([0,0,88,57,0,15,200,192,0,4,86,72]),h=e.sinf(t.encv),p=new Uint8Array([u>>24,u>>16&255,u>>8&255,255&u,c>>24,c>>16&255,c>>8&255,255&c]);return e.box(e.types.encv,l,e.box(e.types.avcC,d),e.box(e.types.btrt,f),h,e.box(e.types.pasp,p))}},{key:"schi",value:function(t){var r=new Uint8Array([]),n=e.tenc(t);return e.box(e.types.schi,r,n)}},{key:"tenc",value:function(t){var r=new Uint8Array([0,0,0,0,0,0,255&t.default_IsEncrypted,255&t.default_IV_size].concat(parse2(t.default_KID)));return e.box(e.types.tenc,r)}},{key:"sinf",value:function(t){var r=new Uint8Array([]),n=new Uint8Array([t.data_format.charCodeAt(0),t.data_format.charCodeAt(1),t.data_format.charCodeAt(2),t.data_format.charCodeAt(3)]),i=new Uint8Array([0,0,0,0,99,101,110,99,0,1,0,0]),a=e.schi(t);return e.box(e.types.sinf,r,e.box(e.types.frma,n),e.box(e.types.schm,i),a)}},{key:"av01",value:function(t){return e.box(e.types.av01,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,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,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,0,0,0,0,0,0,24,17,17]),t.av1C,t.colr)}},{key:"avc1hev1",value:function(t){var r=t.codecType===VideoCodecType.HEVC,n=r?e.types.hvc1:e.types.avc1,i=r?e.hvcC(t):e.avcC(t),a=[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,t.width>>8&255,255&t.width,t.height>>8&255,255&t.height,0,72,0,0,0,72,0,0,0,0,0,0,0,1,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,0,0,0,0,0,0,24,17,17]),i];return r?a.push(e.box(e.types.fiel,new Uint8Array([1,0]))):t.sarRatio&&t.sarRatio.length>1&&a.push(e.pasp(t.sarRatio)),e.box.apply(e,[n].concat(a))}},{key:"avcC",value:function(t){var r,n,i,a=[],s=[];return t.sps.forEach((function(e){i=e.byteLength,a.push(i>>>8&255),a.push(255&i),a.push.apply(a,_toConsumableArray(e))})),t.pps.forEach((function(e){i=e.byteLength,s.push(i>>>8&255),s.push(255&i),s.push.apply(s,_toConsumableArray(e))})),e.box(e.types.avcC,new Uint8Array((r=(n=[1,a[3],a[4],a[5],255,224|t.sps.length]).concat.apply(n,a).concat([t.pps.length])).concat.apply(r,s)))}},{key:"hvcC",value:function(t){var r=t.hvcC;if(r instanceof ArrayBuffer||r instanceof Uint8Array)return r;var n,i=t.vps,a=t.sps,s=t.pps;if(r){var o=r.generalProfileCompatibilityFlags,u=r.generalConstraintIndicatorFlags,c=(i.length&&1)+(a.length&&1)+(s.length&&1);n=[1,r.generalProfileSpace<<6|r.generalTierFlag<<5|r.generalProfileIdc,o>>>24,o>>>16,o>>>8,o,u[0],u[1],u[2],u[3],u[4],u[5],r.generalLevelIdc,240,0,252,252|r.chromaFormatIdc,248|r.bitDepthLumaMinus8,248|r.bitDepthChromaMinus8,0,0,r.numTemporalLayers<<3|r.temporalIdNested<<2|3,c];var l=function(e){var t;n.push(e.length>>8,e.length),(t=n).push.apply(t,_toConsumableArray(e))};i.length&&(n.push(160,0,i.length),i.forEach(l)),a.length&&(n.push(161,0,a.length),a.forEach(l)),s.length&&(n.push(162,0,s.length),s.forEach(l))}else n=[1,1,96,0,0,0,144,0,0,0,0,0,93,240,0,252,253,248,248,0,0,15,3,160,0,1,0,24,64,1,12,1,255,255,1,96,0,0,3,0,144,0,0,3,0,0,3,0,93,153,152,9,161,0,1,0,45,66,1,1,1,96,0,0,3,0,144,0,0,3,0,0,3,0,93,160,2,128,128,45,22,89,153,164,147,43,154,128,128,128,130,0,0,3,0,2,0,0,3,0,50,16,162,0,1,0,7,68,1,193,114,180,98,64];return e.box(e.types.hvcC,new Uint8Array(n))}},{key:"pasp",value:function(t){var r=_slicedToArray(t,2),n=r[0],i=r[1];return e.box(e.types.pasp,new Uint8Array([n>>24,n>>16&255,n>>8&255,255&n,i>>24,i>>16&255,i>>8&255,255&i]))}},{key:"mp4a",value:function(t){return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.sampleRate>>8&255,255&t.sampleRate,0,0]),t.config.length?e.esds(t.config):void 0)}},{key:"esds",value:function(t){var r=t.length;return e.box(e.types.esds,new Uint8Array([0,0,0,0,3,23+r,0,0,0,4,15+r,64,21,0,6,0,0,0,218,192,0,0,218,192,5].concat([r]).concat(t).concat([6,1,2])))}},{key:"opus",value:function(t){var r=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,t.sampleRate>>8&255,255&t.sampleRate,0,0]),n=t.config.length?e.dOps(t):[];return e.box(e.types.Opus,r,n)}},{key:"dOps",value:function(t){if(t.config)return t.config[4]=t.sampleRate>>>24&255,t.config[5]=t.sampleRate>>>16&255,t.config[6]=t.sampleRate>>>8&255,t.config[7]=255&t.sampleRate,e.box(e.types.dOps,t.config)}},{key:"mvex",value:function(t){return e.box.apply(e,[e.types.mvex].concat(_toConsumableArray(t.map((function(t){return e.trex(t.id)})))))}},{key:"trex",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trex1",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,2,0,0,0,0,0,0,1,0,0]))}},{key:"trex2",value:function(t){return e.box(e.types.trex,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t,0,0,0,1,0,0,4,0,0,0,0,0,2,0,0,0]))}},{key:"moof",value:function(t){return e.box.apply(e,[e.types.moof,e.mfhd(t[0].samples?t[0].samples[0].gopId:0)].concat(_toConsumableArray(t.map((function(t){return e.traf(t)})))))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"traf",value:function(t){var r=e.tfhd(t.id),n=e.tfdt(t,t.baseMediaDecodeTime),i=0;if(t.isVideo&&t.videoSenc&&t.videoSenc.forEach((function(e){i+=8,e.subsamples&&e.subsamples.length&&(i+=2,i+=6*e.subsamples.length)})),t.videoSencLength=i,t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)){if(t.isVideoEncryption){if(t.isVideo){var a=e.saiz(t),s=e.saio(t),o=e.trun1(t),u=e.senc(t);return e.box(e.types.traf,r,n,a,s,o,u)}if(t.isAudioEncryption){var c=e.sbgp(),l=e.saiz(t),d=e.saio(t),f=e.senc(t),h=e.trun1(t);return e.box(e.types.traf,r,n,c,l,d,f,h)}var p=e.sbgp(),_=e.trun1(t);return e.box(e.types.traf,r,n,p,_)}if(t.isVideo){var y=e.trun1(t);return e.box(e.types.traf,r,n,y)}var v=e.sbgp(),m=e.saiz(t),g=e.saio(t),E=e.senc(t),b=e.trun1(t);return e.box(e.types.traf,r,n,v,m,g,E,b)}var S=e.sdtp(t);return e.box(e.types.traf,r,n,S,e.trun(t.samples,S.byteLength+76))}},{key:"sdtp",value:function(t){var r=new Buffer;return t.samples.forEach((function(e){r.write(new Uint8Array(t.isVideo?[e.keyframe?32:16]:[16]))})),e.box(e.types.sdtp,this.extension(0,0),r.buffer)}},{key:"trun1",value:function(t){var r=new Buffer,n=Buffer.writeUint32(t.samples.length),i=null;if(t.isVideo){var a=t.videoSencLength;i=Buffer.writeUint32(16*t.samples.length+a+149),!t.isVideoEncryption&&t.isAudioEncryption&&(i=Buffer.writeUint32(16*t.samples.length+92))}else{var s=12*t.samples.length+124;t.isAudioEncryption&&(s=12*t.samples.length+8*t.audioSenc.length+177),i=Buffer.writeUint32(s)}return t.samples.forEach((function(e){r.write(Buffer.writeUint32(e.duration)),r.write(Buffer.writeUint32(e.size)),r.write(Buffer.writeUint32(e.keyframe?33554432:65536)),t.isVideo&&r.write(Buffer.writeUint32(e.cts?e.cts:0))})),e.box(e.types.trun,this.extension(0,t.flags),n,i,r.buffer)}},{key:"senc",value:function(t){var r=new Buffer,n=t.samples.length,i=t.isVideo?16:8,a=t.isVideo?2:0,s=[],o=0;return t.isVideo?(s=t.videoSenc,o=t.videoSencLength):s=t.audioSenc,o=o||i*n,r.write(Buffer.writeUint32(16+o),e.types.senc,this.extension(0,a)),r.write(Buffer.writeUint32(n)),s.forEach((function(e){for(var t=0;t<e.InitializationVector.length;t++)r.write(new Uint8Array([e.InitializationVector[t]]));e.subsamples&&e.subsamples.length&&(r.write(Buffer.writeUint16(e.subsamples.length)),e.subsamples.forEach((function(e){r.write(Buffer.writeUint16(e.BytesOfClearData)),r.write(Buffer.writeUint32(e.BytesOfProtectedData))})))})),r.buffer}},{key:"saio",value:function(t){var r=12*t.samples.length+141;!t.isVideo&&t.isAudioEncryption&&(r=149);var n=new Uint8Array([1,0,0,0,0,0,0,1,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r]);return e.box(e.types.saio,n)}},{key:"saiz",value:function(t){var r=t.samples.length,n=new Uint8Array([0,0,0,0,16,r>>24&255,r>>16&255,r>>8&255,255&r]);return e.box(e.types.saiz,n)}},{key:"sbgp",value:function(){var t=new Uint8Array([114,111,108,108,0,0,0,1,0,0,1,25,0,0,0,1]);return e.box(e.types.sbgp,this.extension(0,0),t)}},{key:"extension",value:function(e,t){return new Uint8Array([e,t>>16&255,t>>8&255,255&t])}},{key:"tfhd",value:function(t){return e.box(e.types.tfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"tfdt",value:function(t,r){var n=Math.floor(r/(UINT32_MAX+1)),i=Math.floor(r%(UINT32_MAX+1));return t.useEME&&(t.isVideoEncryption||t.isAudioEncryption)?e.box(e.types.tfdt,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,n>>24,n>>16&255,n>>8&255,255&n,i>>24,i>>16&255,i>>8&255,255&i]))}},{key:"trun",value:function(t,r){var n=t.length,i=12+16*n;r+=8+i;var a=new Uint8Array(i);a.set([0,0,15,1,n>>>24&255,n>>>16&255,n>>>8&255,255&n,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0);for(var s=0;s<n;s++){var o=t[s],u=o.duration,c=o.size,l=o.flag,d=void 0===l?{}:l,f=o.cts,h=void 0===f?0:f;a.set([u>>>24&255,u>>>16&255,u>>>8&255,255&u,c>>>24&255,c>>>16&255,c>>>8&255,255&c,d.isLeading<<2|(null===d.dependsOn||void 0===d.dependsOn?1:d.dependsOn),d.isDependedOn<<6|d.hasRedundancy<<4|d.paddingValue<<1|(null===d.isNonSyncSample||void 0===d.isNonSyncSample?1:d.isNonSyncSample),61440&d.degradationPriority,15&d.degradationPriority,h>>>24&255,h>>>16&255,h>>>8&255,255&h],12+16*s)}return e.box(e.types.trun,a)}},{key:"moovMP4",value:function(t){return e.box.apply(e,[e.types.moov,e.mvhd(t[0].duration,t[0].timescale)].concat(_toConsumableArray(t.map((function(t){return e.trackMP4(t)})))))}},{key:"trackMP4",value:function(t){return e.box(e.types.trak,e.tkhd(t.id,t.duration,t.width,t.height),e.mdiaMP4(t))}},{key:"mdiaMP4",value:function(t){return e.box(e.types.mdia,e.mdhd(t.duration,t.timescale),e.hdlr(t.type),e.minfMP4(t))}},{key:"minfMP4",value:function(t){return e.box(e.types.minf,t.type===TrackType.VIDEO?e.VMHD:e.SMHD,e.DINF,e.stblMP4(t))}},{key:"stblMP4",value:function(t){var r=t.ext,n=[e.stsd(t),e.stts(r.stts),e.stsc(r.stsc),e.stsz(r.stsz),e.stco(r.stco)];return r.stss.length&&n.push(e.stss(r.stss)),r.ctts.length&&n.push(e.ctts(r.ctts)),e.box.apply(e,[e.types.stbl].concat(n))}},{key:"stts",value:function(t){var r=t.length,n=new Uint8Array(8*r),i=0;return t.forEach((function(e){var t=e.value,r=e.count;n.set([r>>24,r>>16&255,r>>8&255,255&r,t>>24,t>>16&255,t>>8&255,255&t],i),i+=8})),e.box(e.types.stts,concatUint8Array(new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r]),n))}},{key:"stsc",value:function(t){var r=t.length,n=new Uint8Array(12*r),i=0;return t.forEach((function(e){var t=e.firstChunk,r=e.samplesPerChunk,a=e.sampleDescIndex;n.set([t>>24,t>>16&255,t>>8&255,255&t,r>>24,r>>16&255,r>>8&255,255&r,a>>24,a>>16&255,a>>8&255,255&a],i),i+=12})),e.box(e.types.stsc,concatUint8Array(new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r]),n))}},{key:"stsz",value:function(t){var r=t.length,n=new Uint8Array(4*r),i=0;return t.forEach((function(e){n.set([e>>24,e>>16&255,e>>8&255,255&e],i),i+=4})),e.box(e.types.stsz,concatUint8Array(new Uint8Array([0,0,0,0,0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r]),n))}},{key:"stco",value:function(t){var r=t.length,n=new Uint8Array(4*r),i=0;return t.forEach((function(e){n.set([e>>24,e>>16&255,e>>8&255,255&e],i),i+=4})),e.box(e.types.stco,concatUint8Array(new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r]),n))}},{key:"stss",value:function(t){var r=t.length,n=new Uint8Array(4*r),i=0;return t.forEach((function(e){n.set([e>>24,e>>16&255,e>>8&255,255&e],i),i+=4})),e.box(e.types.stss,concatUint8Array(new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r]),n))}},{key:"ctts",value:function(t){var r=t.length,n=new Uint8Array(8*r),i=0;return t.forEach((function(e){var t=e.value,r=e.count;n.set([r>>24,r>>16&255,r>>8&255,255&r,t>>24,t>>16&255,t>>8&255,255&t],i),i+=8})),e.box(e.types.ctts,concatUint8Array(new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r]),n))}},{key:"styp",value:function(){return e.box(e.types.styp,new Uint8Array([109,115,100,104,0,0,0,0,109,115,100,104,109,115,105,120]))}},{key:"sidx",value:function(t){var r=t.timescale,n=t.samples[0].duration,i=n*t.samples.length,a=t.samples[0].sampleOffset*n,s=8;t.samples.forEach((function(e){s+=e.size}));var o=0;if(t.isVideo){var u,c=0;t.videoSenc&&(u=t.videoSenc),t.isVideo&&u.forEach((function(e){c+=8,e.subsamples&&e.subsamples.length&&(c+=2,c+=6*e.subsamples.length)})),t.videoSencLength=c,o=s+141+16*t.samples.length+c,t.useEME&&t.isAudioEncryption&&!t.isVideoEncryption&&(o=s+16*t.samples.length+84)}else o=s+116+12*t.samples.length,t.useEME&&t.isAudioEncryption&&(o=s+169+12*t.samples.length+8*t.audioSenc.length);var l=new Uint8Array([0,0,0,0,0,0,0,255&t.id,r>>24&255,r>>16&255,r>>8&255,255&r,a>>24&255,a>>16&255,a>>8&255,255&a,0,0,0,0,0,0,0,1,0,o>>16&255,o>>8&255,255&o,i>>24&255,i>>16&255,i>>8&255,255&i,144,0,0,0]);return e.box(e.types.sidx,l)}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}}]),e}();_defineProperty(MP4,"types",["Opus","dOps","av01","av1C","avc1","avcC","hvc1","hvcC","dinf","dref","esds","ftyp","hdlr","mdat","mdhd","mdia","mfhd","minf","moof","moov","mp4a","mvex","mvhd","pasp","stbl","stco","stsc","stsd","stsz","stts","tfdt","tfhd","traf","trak","trex","tkhd","vmhd","smhd","ctts","stss","styp","pssh","sidx","sbgp","saiz","saio","senc","trun","encv","enca","sinf","btrt","frma","tenc","schm","schi","mehd","fiel","sdtp"].reduce((function(e,t){return e[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)],e}),Object.create(null))),_defineProperty(MP4,"HDLR_TYPES",{video: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]),audio: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])}),_defineProperty(MP4,"FTYPAVC1",MP4.box(MP4.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,97,118,99,49]))),_defineProperty(MP4,"FTYPHEV1",MP4.box(MP4.types.ftyp,new Uint8Array([105,115,111,109,0,0,0,1,105,115,111,109,104,101,118,49]))),_defineProperty(MP4,"DINF",MP4.box(MP4.types.dinf,MP4.box(MP4.types.dref,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1])))),_defineProperty(MP4,"VMHD",MP4.box(MP4.types.vmhd,new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]))),_defineProperty(MP4,"SMHD",MP4.box(MP4.types.smhd,new Uint8Array([0,0,0,0,0,0,0,0]))),_defineProperty(MP4,"StblTable",new Uint8Array([0,0,0,0,0,0,0,0])),_defineProperty(MP4,"STTS",MP4.box(MP4.types.stts,MP4.StblTable)),_defineProperty(MP4,"STSC",MP4.box(MP4.types.stsc,MP4.StblTable)),_defineProperty(MP4,"STSZ",MP4.box(MP4.types.stsz,new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]))),_defineProperty(MP4,"STCO",MP4.box(MP4.types.stco,MP4.StblTable));var Logger=function(){function e(t,r){_classCallCheck(this,e),this.name=t||"",this._prefix="[".concat(this.name,"]"),e.disabled=r}return _createClass(e,[{key:"debug",value:function(){var t;if(!e.disabled){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];(t=console).debug.apply(t,[this._prefix].concat(n))}}},{key:"log",value:function(){var t;if(!e.disabled){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];(t=console).log.apply(t,[this._prefix].concat(n))}}},{key:"warn",value:function(){var t;if(!e.disabled){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];(t=console).warn.apply(t,[this._prefix].concat(n))}}},{key:"error",value:function(){var t;if(!e.disabled){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];(t=console).error.apply(t,[this._prefix].concat(n))}}},{key:"table",value:function(){var t;e.disabled||(console.group(this._prefix),(t=console).table.apply(t,arguments),console.groupEnd())}}],[{key:"enable",value:function(){e.disabled=!1}},{key:"disable",value:function(){e.disabled=!0}}]),e}();_defineProperty(Logger,"disabled",!0);var FMP4Remuxer=function(){function e(t,r,n){_classCallCheck(this,e),this.videoTrack=t,this.audioTrack=r;var i=/Chrome\/([^.]+)/.exec(navigator.userAgent);this.forceFirstIDR=i&&Number(i[1])<50,this.log=new Logger("FMP4Remuxer",!n||!n.openLog||!n.openLog)}return _createClass(e,[{key:"remux",value:function(){var e,t,r,n,i,a=arguments.length>0&&void 0!==arguments[0]&&arguments[0],s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=this.videoTrack,u=this.audioTrack,c=o.exist(),l=u.exist(),d=[];return a&&(s&&s.initMerge?(c&&d.push(this.videoTrack),l&&d.push(this.audioTrack),r=MP4.initSegment(d)):(c&&(e=MP4.initSegment([this.videoTrack])),l&&(t=MP4.initSegment([this.audioTrack])))),c&&o.hasSample()&&(n=this._remuxVideo()),l&&u.hasSample()&&(i=this._remuxAudio()),o.samples=[],u.samples=[],{initSegment:r,videoInitSegment:e,audioInitSegment:t,videoSegment:n,audioSegment:i}}},{key:"_remuxVideo",value:function(){var e=this.videoTrack;this.forceFirstIDR&&(e.samples[0].flag={dependsOn:2,isNonSyncSample:0});var t=e.samples,r=/av01/.test(e.codec),n=0;r?t.forEach((function(e){n+=e.data.byteLength})):t.forEach((function(e){n+=e.units.reduce((function(e,t){return e+t.byteLength}),0),n+=4*e.units.length}));var i=new Uint8Array(n);if(r)for(var a,s=0,o=t.length,u=0;s<o;s++)a=t[s],i.set(a.data,u),a.size=a.data.byteLength,u+=a.size;else for(var c,l=new DataView(i.buffer),d=function(e,r){r=t[f];var n=0;r.units.forEach((function(t){l.setUint32(e,t.byteLength),e+=4,i.set(t,e),e+=t.byteLength,n+=4+t.byteLength})),r.size=n,p=e,c=r},f=0,h=t.length,p=0;f<h;f++)d(p,c);var _=MP4.mdat(i);return concatUint8Array(MP4.moof([e]),_)}},{key:"_remuxAudio",value:function(){var e=this.audioTrack,t=new Uint8Array(e.samples.reduce((function(e,t){return e+t.size}),0));e.samples.reduce((function(e,r){return t.set(r.data,e),e+r.size}),0);var r=MP4.mdat(t);return concatUint8Array(MP4.moof([e]),r)}},{key:"reset",value:function(){this.videoTrack.reset(),this.audioTrack.reset()}}]),e}(),Decryptor=function(){function e(){_classCallCheck$3(this,e);var t=window.crypto||window.msCrypto;this.subtle=t&&(t.subtle||t.webkitSubtle),this.externalDecryptor=null}var t,r;return _createClass$3(e,[{key:"destroy",value:function(){var e;null!==(e=this.externalDecryptor)&&void 0!==e&&e.destroy&&this.externalDecryptor.destroy()}},{key:"decrypt",value:function(e,t){if(e||t){var r=[];return e&&(r[0]=this._decryptSegment(e)),t&&(r[1]=this._decryptSegment(t)),Promise.all(r)}}},{key:"_decryptSegment",value:(r=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.data,!t.key){e.next=5;break}return e.next=4,this._decryptData(t.data,t.key,t.keyIv);case 4:r=e.sent;case 5:if(t.map){e.next=7;break}return e.abrupt("return",r);case 7:return e.abrupt("return",concatUint8Array$1(t.map,r));case 8:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"_decryptData",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r,n){var i;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.externalDecryptor){e.next=6;break}return e.next=3,this.externalDecryptor.decrypt(t,r,n);case 3:return e.abrupt("return",e.sent);case 6:if(this.subtle){e.next=8;break}throw new Error("crypto is not defined");case 8:return e.next=10,this.subtle.importKey("raw",r,{name:"AES-CBC"},!1,["encrypt","decrypt"]);case 10:return i=e.sent,e.t0=Uint8Array,e.next=14,this.subtle.decrypt({name:"AES-CBC",iv:n},i,t);case 14:return e.t1=e.sent,e.abrupt("return",new e.t0(e.t1));case 16:case"end":return e.stop()}}),e,this)}))),function(e,r,n){return t.apply(this,arguments)})}]),e}(),Event$1=_objectSpread2$2(_objectSpread2$2({},EVENT),{},{STREAM_PARSED:"core.streamparsed",NO_AUDIO_TRACK:"core.noaudiotrack",SUBTITLE_SEGMENTS:"core.subtitlesegments",SUBTITLE_PLAYLIST:"core.subtitleplaylist",SEI_PAYLOAD_TIME:"core.seipayloadtime",APPEND_COST:"core.appendcost"}),logger$3=new Logger$2("Transmuxer"),Transmuxer=function(){function e(t,r,n,i){_classCallCheck$3(this,e),_defineProperty$3(this,"_initSegmentId",""),this.hls=t,this._demuxer=r?new FMP4Demuxer:new TsDemuxer(null,null,null,i),this._isMP4=r,n&&(this._remuxer=new FMP4Remuxer(this._demuxer.videoTrack,this._demuxer.audioTrack))}return _createClass$3(e,[{key:"transmux",value:function(e,t,r,n,i,a){var s=this._demuxer;try{this._isMP4?s.demux(e,t):s.demuxAndFix(concatUint8Array$1(e,t),r,n,i)}catch(e){throw new StreamingError(ERR.DEMUX,ERR.SUB_TYPES.HLS,e)}var o=s.videoTrack,u=s.audioTrack,c=s.metadataTrack,l={codec:o.codec,timescale:o.timescale,firstDts:o.firstDts/o.timescale,firstPts:o.firstPts/o.timescale,duration:o.samplesDuration/o.timescale},d={codec:u.codec,timescale:u.timescale,firstDts:u.firstDts/o.timescale,firstPts:u.firstPts/o.timescale,duration:u.samplesDuration/o.timescale,container:u.container},f="".concat(o.codec,"/").concat(o.width,"/").concat(o.height,"/").concat(u.codec,"/").concat(u.config);if(f!==this._initSegmentId&&(this._initSegmentId=f,a=!0),this._fireEvents(o,u,c,r||a),this.hls.emit(Event$1.DEMUXED_TRACK,{videoTrack:o,audioTrack:u}),!this._remuxer)return[o,u];a&&this.hls.isLive&&!this.hls.config.mseLowLatency&&(o.duration=this.hls.totalDuration*o.timescale,u.duration=this.hls.totalDuration*u.timescale);try{var h=this._remuxer.remux(a),p=h.videoInitSegment,_=h.videoSegment,y=h.audioInitSegment,v=h.audioSegment,m=concatUint8Array$1(p,_),g=concatUint8Array$1(y,v);return[m?_objectSpread2$2(_objectSpread2$2({},l),{},{data:m}):void 0,g?_objectSpread2$2(_objectSpread2$2({},d),{},{data:g}):void 0]}catch(e){throw new StreamingError(ERR.REMUX,ERR.SUB_TYPES.FMP4,e)}}},{key:"_fireEvents",value:function(e,t,r,n){var i=this,a=[e,t],s="discontinuity: ".concat(n);a.forEach((function(e){var t;null!==(t=e.samples)&&void 0!==t&&t.length&&(s+="; ".concat(e.samples.length," ").concat(e.type===TrackType.VIDEO?"video":"audio"," samples, firstDts/firstPts/duration: ").concat((e.firstDts/e.timescale).toFixed(3),"/").concat((e.firstPts/e.timescale).toFixed(3),"/").concat((e.samplesDuration/e.timescale).toFixed(3))),n&&e.exist()&&i.hls.emit(Event$1.METADATA_PARSED,{type:e.type,track:e,meta:_objectSpread2$2({codec:e.codec,timescale:e.timescale,baseDts:e.baseDts},e.type===TrackType.VIDEO?{width:e.width,height:e.height,sarRatio:e.sarRatio}:{codec:e.codec,channelCount:e.channelCount,sampleRate:e.sampleRate})})})),logger$3.debug(s),e.warnings.forEach((function(e){var t;switch(e.type){case WarningType.LARGE_AV_SHIFT:t=Event$1.LARGE_AV_FIRST_FRAME_GAP_DETECT;break;case WarningType.LARGE_VIDEO_GAP:t=Event$1.LARGE_VIDEO_DTS_GAP_DETECT;break;case WarningType.LARGE_VIDEO_GAP_BETWEEN_CHUNK:t=Event$1.MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT}t&&i.hls.emit(Event$1.STREAM_EXCEPTION,_objectSpread2$2(_objectSpread2$2({},e),{},{type:t})),logger$3.warn("video exception",e)})),t.warnings.forEach((function(e){var t;switch(e.type){case WarningType.LARGE_AUDIO_GAP:t=Event$1.LARGE_AUDIO_DTS_GAP_DETECT;break;case WarningType.AUDIO_FILLED:t=Event$1.AUDIO_GAP_DETECT;break;case WarningType.AUDIO_DROPPED:t=Event$1.AUDIO_OVERLAP_DETECT}t&&i.hls.emit(Event$1.STREAM_EXCEPTION,_objectSpread2$2(_objectSpread2$2({},e),{},{type:t})),logger$3.warn("audio exception",e)})),e.samples.forEach((function(e){e.keyframe&&i.hls.emit(Event$1.KEYFRAME,{pts:e.pts})})),r.seiSamples.forEach((function(e){i.hls.emit(Event$1.SEI,_objectSpread2$2(_objectSpread2$2({},e),{},{originPts:e.originPts/90,sei:{code:e.data.type,content:e.data.payload,dts:e.pts}}))}))}}]),e}(),_excluded$1=["data"],_excluded2=["data"],logger$2=new Logger$2("BufferService"),BufferService=function(){function e(t){var r=this;_classCallCheck$3(this,e),_defineProperty$3(this,"_decryptor",new Decryptor),_defineProperty$3(this,"_transmuxer",null),_defineProperty$3(this,"_mse",null),_defineProperty$3(this,"_softVideo",null),_defineProperty$3(this,"_sourceCreated",!1),_defineProperty$3(this,"_needInitSegment",!0),_defineProperty$3(this,"_directAppend",!1),this.hls=t,t.config.softDecode?this._softVideo=t.media:(this._mse=new MSE(null,{preferMMS:t.config.preferMMS}),t.config.url&&this._mse.bindMedia(t.media).then((function(e){r.hls.emit(EVENT.MEDIASOURCE_OPENED,e)}))),t.config.decryptor&&(this._decryptor.externalDecryptor=t.config.decryptor)}var t,r,n,i,a,s,o,u,c,l;return _createClass$3(e,[{key:"baseDts",get:function(){var e,t,r;return null===(e=this._transmuxer)||void 0===e||null===(t=e._demuxer)||void 0===t||null===(r=t._fixer)||void 0===r?void 0:r._baseDts}},{key:"nbSb",get:function(){var e;return null!==(e=this._mse)&&void 0!==e&&e._sourceBuffer?Object.keys(this._mse._sourceBuffer).length:0}},{key:"msIsOpened",get:function(){var e;return null===(e=this._mse)||void 0===e?void 0:e.isOpened}},{key:"msHasOpTasks",get:function(){var e;return null===(e=this._mse)||void 0===e?void 0:e.hasOpTasks}},{key:"msStreaming",get:function(){var e;return null===(e=this._mse)||void 0===e?void 0:e.streaming}},{key:"updateDuration",value:(l=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(logger$2.debug("update duration",t),!this._mse){e.next=9;break}if(this._mse.isOpened){e.next=5;break}return e.next=5,this._mse.open();case 5:return e.next=7,this._mse.updateDuration(t);case 7:e.next=10;break;case 9:this._softVideo&&(this._softVideo.duration=t);case 10:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"createSource",value:function(e,t,r,n){if(!this._sourceCreated){var i=e||t;if(i){if(TsDemuxer.probe(i))this._transmuxer||(this._transmuxer=new Transmuxer(this.hls,!1,!this._softVideo,this.hls.config.fixerConfig));else{if(!MP4Parser.probe(i))throw new StreamingError(ERR.OTHER,null,null,null,"unsupported stream");if(this._softVideo)this._transmuxer||(this._transmuxer=new Transmuxer(this.hls,!0,null,this.hls.config.fixerConfig));else{this._directAppend=!0;var a=!1;e&&!r&&MP4Parser.findBox(e,["moov","trak"]).forEach((function(e){var t=MP4Parser.findBox(e.data,["trak","mdia","minf","stbl","stsd"])[0];if(t){var i=MP4Parser.stsd(t).entries[0];if(i)if(i.hvcC)r=i.hvcC.codec||"hev1.1.6.L93.B0";else if(i.avcC)r=i.avcC.codec;else if(i.sampleRate||i.esds){var s;n=(null===(s=i.esds)||void 0===s?void 0:s.codec)||"mp4a.40.2",a=!0}}})),t&&!n&&MP4Parser.findBox(t,["moov","trak","mdia","minf","stbl","stsd"]).forEach((function(e){var t=MP4Parser.stsd(e).entries[0];t&&t.esds&&(n=t.esds.codec)})),e&&!r&&(r="avc1.42e01e"),t&&!n&&(n="mp4a.40.2"),a&&(r+=", ".concat(n),n=""),this._createMseSource(r,n)}}this._softVideo&&(this._sourceCreated=!0)}}}},{key:"appendBuffer",value:(c=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r,n,i,a,s,o){var u,c,l,d,f,h,p,_,y,v,m,g,E,b,S,T=this;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!=n&&n.length||null!=i&&i.length){e.next=2;break}return e.abrupt("return");case 2:if(u=function(){var e,r;null!==(e=T.hls)&&void 0!==e&&e.emit&&(null===(r=T.hls)||void 0===r||r.emit(EVENT.APPEND_BUFFER,{start:t.start,end:t.end}))},!this._directAppend){e.next=8;break}return c=[],n&&c.push(this._mse.append(MSE.VIDEO,n)),i&&c.push(this._mse.append(MSE.AUDIO,i)),e.abrupt("return",Promise.all(c).then(u));case 8:if(l=this._needInitSegment||a,d=this._transmuxer.transmux(n,i,l,s,o,this._needInitSegment||a),f=_slicedToArray$1(d,2),h=f[0],p=f[1],i&&r&&(null==r||r.setTrackExist(!1,!0)),i&&t&&(null==t||t.setTrackExist(!0,!1)),r||null==t||t.setTrackExist(!!h,!!p),h&&!p&&this.hls.emit(Event$1.NO_AUDIO_TRACK),!this._softVideo){e.next=20;break}this._softVideo.appendBuffer(h,p),this._needInitSegment=!1,u(),e.next=32;break;case 20:if(!this._mse){e.next=32;break}return(_=!this._sourceCreated)&&this._createMseSource(null==h?void 0:h.codec,null==p?void 0:p.codec,null==p?void 0:p.container),this._needInitSegment=!1,y=this._mse,v=[],l&&!_&&this._handleCodecChange(h,p).forEach((function(e){return v.push(e)})),h&&(m=h.data,g=_objectWithoutProperties$1(h,_excluded$1),v.push(y.append(MSE.VIDEO,m,g))),p&&(E=p.data,b=_objectWithoutProperties$1(p,_excluded2),v.push(y.append(MSE.AUDIO,E,b))),(S=Promise.all(v)).then(u),e.abrupt("return",S);case 32:case"end":return e.stop()}}),e,this)}))),function(e,t,r,n,i,a,s){return c.apply(this,arguments)})},{key:"removeBuffer",value:(u=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,r,n,i=this,a=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=a.length>0&&void 0!==a[0]?a[0]:0,r=a.length>1&&void 0!==a[1]?a[1]:1/0,n=this.hls.media,!(!this._mse||!n||t<0||r<t||t>=this._mse.duration)){e.next=5;break}return e.abrupt("return");case 5:return e.abrupt("return",this._mse.clearBuffer(t,r).then((function(){return i.hls.emit(EVENT.REMOVE_BUFFER,{start:t,end:r,removeEnd:r})})));case 6:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"evictBuffer",value:(o=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.hls.media,this._mse&&r&&t&&!(t<0)){e.next=3;break}return e.abrupt("return");case 3:if(n=r.currentTime,!((i=n-t)<=0)){e.next=7;break}return e.abrupt("return");case 7:if(!(Buffer$1.start(Buffer$1.get(r))+1>=i)){e.next=10;break}return e.abrupt("return");case 10:return e.abrupt("return",this.removeBuffer(0,i));case 11:case"end":return e.stop()}}),e,this)}))),function(e){return o.apply(this,arguments)})},{key:"clearAllBuffer",value:(s=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._mse){e.next=2;break}return e.abrupt("return",this._mse.clearAllBuffer());case 2:case"end":return e.stop()}}),e,this)}))),function(){return s.apply(this,arguments)})},{key:"decryptBuffer",value:function(e,t){return this._decryptor.decrypt(e,t)}},{key:"reset",value:(a=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,r=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.length>0&&void 0!==r[0]&&r[0],!this._mse||t){e.next=8;break}return this._transmuxer=null,this._sourceCreated=!1,e.next=6,this._mse.unbindMedia();case 6:return e.next=8,this._mse.bindMedia(this.hls.media);case 8:this._needInitSegment=!0,this._directAppend=!1;case 10:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"endOfStream",value:(i=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._mse){e.next=5;break}if(!this._sourceCreated){e.next=5;break}return e.next=4,this._mse.endOfStream();case 4:this.hls.emit(EVENT.BUFFEREOS);case 5:this._softVideo&&this._softVideo.endOfStream();case 6:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"setLiveSeekableRange",value:(n=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this._mse&&this._mse.setLiveSeekableRange(t,r);case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return n.apply(this,arguments)})},{key:"detachMedia",value:(r=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._mse){e.next=3;break}return e.next=3,this._mse.unbindMedia();case 3:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"destroy",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return null===(t=this._decryptor)||void 0===t||t.destroy(),e.next=3,this.detachMedia();case 3:this._decryptor=null,this._mse=null,this._softVideo=null;case 6:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_createMseSource",value:function(e,t,r){logger$2.debug("create mse source, videoCodec=".concat(e,", audioCodec=").concat(t));var n=this._mse;n&&(e&&(n.createSource(MSE.VIDEO,"video/mp4;codecs=".concat(e)),this._sourceCreated=!0),t?(n.createSource(MSE.AUDIO,"audio/mp4;codecs=".concat(t)),this._sourceCreated=!0):r&&(n.createSource(MSE.AUDIO,"".concat(r,';codecs=""')),this._sourceCreated=!0),this.hls.emit(EVENT.SOURCEBUFFER_CREATED))}},{key:"_handleCodecChange",value:function(e,t){var r=[],n=this._mse;return[{type:MSE.VIDEO,codecs:null==e?void 0:e.codec},{type:MSE.AUDIO,codecs:null==t?void 0:t.codec}].filter((function(e){return!!e.codecs})).forEach((function(e){var t=e.type,i=e.codecs,a=n.getSourceBuffer(t);if(a){var s=i.split(",")[0];new RegExp(s,"ig").test(a.mimeType)||r.push(n.changeType(t,"".concat(t,"/mp4;codecs=").concat(i)))}})),r}},{key:"seamlessSwitch",value:function(){this._needInitSegment=!0}},{key:"isFull",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:MSE.VIDEO;return null===(e=this._mse)||void 0===e?void 0:e.isFull(t)}}]),e}();function getConfig(e){var t=(null==e?void 0:e.media)||document.createElement("video");return _objectSpread2$2(_objectSpread2$2({maxPlaylistSize:50,retryCount:3,retryDelay:1e3,pollRetryCount:2,loadTimeout:1e4,manifestLoadTimeout:1e4,preloadTime:30,softDecode:!1,bufferBehind:10,maxJumpDistance:3,startTime:0,useLowLatency:!0,targetLatency:10,maxLatency:20,allowedStreamTrackChange:!0,seiInTime:!1,manifestList:[],minSegmentsStartPlay:3,preferMMS:!1,preferMMSStreaming:!1,mseLowLatency:!0,fixerConfig:{forceFixLargeGap:!1,largeGapThreshold:5}},e),{},{media:t})}var MasterPlaylist=_createClass$3((function e(){_classCallCheck$3(this,e),_defineProperty$3(this,"version",0),_defineProperty$3(this,"streams",[]),_defineProperty$3(this,"isMaster",!0)})),MediaType={Audio:"AUDIO",Video:"VIDEO",SubTitle:"SUBTITLE",ClosedCaptions:"CLOSED-CAPTIONS"},KeySystems={CLEAR_KEY:"org.w3.clearkey",FAIRPLAY:["urn:uuid:94ce86fb-07ff-4f43-adb8-93d2fa968ca2","com.apple.streamingkeydelivery"],WIDEVINE:["urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed","com.widevine.alpha","com.widevine"],PLAYREADY:["urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95","com.microsoft.playready"]};function flatArray(e){for(var t=[],r=0;r<e.length;r++)Array.isArray(e[r])?t=t.concat(flatArray(e[r])):t.push(e[r]);return t}var MediaStream=_createClass$3((function e(){_classCallCheck$3(this,e),_defineProperty$3(this,"id",0),_defineProperty$3(this,"url",""),_defineProperty$3(this,"default",!1),_defineProperty$3(this,"autoSelect",!1),_defineProperty$3(this,"forced",!1),_defineProperty$3(this,"group",""),_defineProperty$3(this,"name",""),_defineProperty$3(this,"lang",""),_defineProperty$3(this,"segments",[]),_defineProperty$3(this,"endSN",0)})),AudioStream=function(e){_inherits$2(r,MediaStream);var t=_createSuper$2(r);function r(){var e;_classCallCheck$3(this,r);for(var n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return _defineProperty$3(_assertThisInitialized$2(e=t.call.apply(t,[this].concat(i))),"mediaType",MediaType.Audio),_defineProperty$3(_assertThisInitialized$2(e),"channels",0),e}return _createClass$3(r)}(),SubTitleStream=function(e){_inherits$2(r,MediaStream);var t=_createSuper$2(r);function r(){var e;_classCallCheck$3(this,r);for(var n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return _defineProperty$3(_assertThisInitialized$2(e=t.call.apply(t,[this].concat(i))),"mediaType",MediaType.SubTitle),e}return _createClass$3(r)}(),MasterStream=_createClass$3((function e(){_classCallCheck$3(this,e),_defineProperty$3(this,"id",0),_defineProperty$3(this,"bitrate",0),_defineProperty$3(this,"width",0),_defineProperty$3(this,"height",0),_defineProperty$3(this,"name",""),_defineProperty$3(this,"url",""),_defineProperty$3(this,"audioCodec",""),_defineProperty$3(this,"videoCodec",""),_defineProperty$3(this,"textCodec",""),_defineProperty$3(this,"audioGroup",""),_defineProperty$3(this,"audioStreams",[]),_defineProperty$3(this,"subtitleStreams",[]),_defineProperty$3(this,"closedCaptionsStream",[])})),MediaPlaylist=_createClass$3((function e(){_classCallCheck$3(this,e),_defineProperty$3(this,"version",0),_defineProperty$3(this,"url",""),_defineProperty$3(this,"type",""),_defineProperty$3(this,"startCC",0),_defineProperty$3(this,"endCC",0),_defineProperty$3(this,"startSN",0),_defineProperty$3(this,"endSN",0),_defineProperty$3(this,"totalDuration",0),_defineProperty$3(this,"targetDuration",0),_defineProperty$3(this,"partTargetDuration",0),_defineProperty$3(this,"canSkipUntil",0),_defineProperty$3(this,"canSkipDateRanges",!1),_defineProperty$3(this,"skippedSegments",0),_defineProperty$3(this,"canBlockReload",!1),_defineProperty$3(this,"partHoldBack",0),_defineProperty$3(this,"live",!0),_defineProperty$3(this,"lowLatency",!1),_defineProperty$3(this,"endPartIndex",0),_defineProperty$3(this,"segments",[]),_defineProperty$3(this,"dateRanges",{}),_defineProperty$3(this,"skippedSegments",0)})),MediaSegment=function(){function e(t){_classCallCheck$3(this,e),_defineProperty$3(this,"sn",0),_defineProperty$3(this,"cc",0),_defineProperty$3(this,"url",""),_defineProperty$3(this,"parentUrl",""),_defineProperty$3(this,"title",""),_defineProperty$3(this,"start",0),_defineProperty$3(this,"duration",0),_defineProperty$3(this,"dataTime",""),_defineProperty$3(this,"key",null),_defineProperty$3(this,"byteRange",null),_defineProperty$3(this,"isInitSegment",!1),_defineProperty$3(this,"initSegment",null),_defineProperty$3(this,"isLast",!1),_defineProperty$3(this,"hasAudio",!1),_defineProperty$3(this,"hasVideo",!1),_defineProperty$3(this,"independent",!1),_defineProperty$3(this,"partIndex",0),this.parentUrl=t}return _createClass$3(e,[{key:"end",get:function(){return this.start+this.duration}},{key:"setTrackExist",value:function(e,t){this.hasVideo=e,this.hasAudio=t}},{key:"setByteRange",value:function(e,t){this.byteRange=[0];var r=e.split("@");1===r.length&&t&&t.byteRange?(this.byteRange[0]=t.byteRange[1]||0,this.byteRange[0]&&(this.byteRange[0]+=1)):this.byteRange[0]=parseInt(r[1]),this.byteRange[1]=this.byteRange[0]+parseInt(r[0])-1}}]),e}(),MediaSegmentKey=function(){function e(t){_classCallCheck$3(this,e),_defineProperty$3(this,"method",""),_defineProperty$3(this,"url",""),_defineProperty$3(this,"iv",null),_defineProperty$3(this,"keyFormat",""),_defineProperty$3(this,"keyFormatVersions",""),t instanceof e&&(this.method=t.method,this.url=t.url,this.keyFormat=t.keyFormat,this.keyFormatVersions=t.keyFormatVersions,t.iv&&(this.iv=new Uint8Array(t.iv)))}return _createClass$3(e,[{key:"clone",value:function(t){var r=new e(this);return null!=t&&r.setIVFromSN(t),r}},{key:"setIVFromSN",value:function(e){if(!this.iv&&"AES-128"===this.method&&"number"==typeof e&&this.url){this.iv=new Uint8Array(16);for(var t=12;t<16;t++)this.iv[t]=e>>8*(15-t)&255}}},{key:"isSegmentEncrypted",value:function(){return"AES-128"===this.method}},{key:"isValidKeySystem",value:function(){return flatArray([KeySystems.CLEAR_KEY,KeySystems.FAIRPLAY,KeySystems.WIDEVINE,KeySystems.PLAYREADY]).indexOf(this.keyFormat)>-1&&!!(["SAMPLE-AES","SAMPLE-AES-CENC","SAMPLE-AES-CTR"].indexOf(this.method)>-1)}},{key:"isSupported",value:function(){return!!this.method&&(!!this.isSegmentEncrypted()||!!this.isValidKeySystem())}}]),e}(),HlsUrlParameters=function(){function e(t,r,n){_classCallCheck$3(this,e),this.msn=t,this.part=r,this.skip=n}return _createClass$3(e,[{key:"addDirectives",value:function(e){var t=new self.URL(e);return void 0!==this.msn&&t.searchParams.set("_HLS_msn",this.msn.toString()),this.part&&t.searchParams.set("_HLS_part",this.part.toString()),this.skip&&t.searchParams.set("_HLS_skip",this.skip),t.href}}]),e}(),REGEXP_TAG=/^#(EXT[^:]*)(?::(.*))?$/,REGEXP_ATTR=/([^=]+)=(?:"([^"]*)"|([^",]*))(?:,|$)/g,REGEXP_ABSOLUTE_URL=/^(?:[a-zA-Z0-9+\-.]+:)?\/\//,REGEXP_URL_PAIR=/^((?:[a-zA-Z0-9+\-.]+:)?\/\/[^/?#]*)?([^?#]*\/)?/;function getLines(e){return e.split(/[\r\n]/).map((function(e){return e.trim()})).filter(Boolean)}function parseTag(e){var t=e.match(REGEXP_TAG);if(t&&t[1])return[t[1].replace("EXT-X-",""),t[2]]}function parseAttr(e){for(var t={},r=REGEXP_ATTR.exec(e);r;)t[r[1]]=r[2]||r[3],r=REGEXP_ATTR.exec(e);return t}function getAbsoluteUrl(e,t){if(!t||!e||REGEXP_ABSOLUTE_URL.test(e))return e;var r=REGEXP_URL_PAIR.exec(t);return r?"/"===e[0]?r[1]+e:r[1]+r[2]+e:e}var CODECS_REGEXP={audio:[/^mp4a/,/^vorbis$/,/^opus$/,/^flac$/,/^[ae]c-3$/],video:[/^avc/,/^hev/,/^hvc/,/^vp0?[89]/,/^av1$/],text:[/^vtt$/,/^wvtt/,/^stpp/]};function getCodecs(e,t){var r=CODECS_REGEXP[e];if(r&&t&&t.length)for(var n=0;n<r.length;n++)for(var i=0;i<t.length;i++)if(r[n].test(t[i]))return t[i]}function isValidDaterange(e,t){var r;if(t)for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e[n]!==t[n]){r=n;break}var i=null;e.DURATION&&(i=parseFloat(e.DURATION),Number.isFinite(i)?e._endDate&&(i=(e._endDate.getTime()-e._startDate.getTime())/1e3):i=null);var a=enumeratedStringList(e.CUE||e["X-CUE"],{pre:!1,post:!1,once:!1});return!!e.ID&&!r&&Number.isFinite(e._startDate.getTime())&&(null===i||i>=0)&&(!("YES"===e.END_ON_NEXT)||!!e.CLASS)&&(!e.CUE||!a.pre&&!a.post||a.pre!==a.post)&&(!("com.apple.hls.interstitial"===e.CLASS)||"X-ASSET-URI"in e||"X-ASSET-LIST"in e)}function enumeratedStringList(e,t){return(e?e.split(/[ ,]+/):[]).reduce((function(e,t){return e[t.toLowerCase()]=!0,e}),t)}function parseMasterPlaylist(e,t){for(var r,n=new MasterPlaylist,i=0,a=[],s=[];r=e[i++];){var o=parseTag(r);if(o){var u=_slicedToArray$1(o,2),c=u[0],l=u[1];if("VERSION"===c)n.version=parseInt(l);else if("MEDIA"===c&&l){var d=parseAttr(l),f=void 0;switch(d.TYPE){case"AUDIO":f=new AudioStream;break;case"SUBTITLES":f=new SubTitleStream;break;default:f=new MediaStream}f.url=getAbsoluteUrl(d.URI,t),f.default="YES"===d.DEFAULT,f.autoSelect="YES"===d.AUTOSELECT,f.group=d["GROUP-ID"],f.name=d.NAME,f.lang=d.LANGUAGE,d.CHANNELS&&(f.channels=Number(d.CHANNELS.split("/")[0]),Number.isNaN(f.channels)&&(f.channels=0)),"AUDIO"===d.TYPE&&d.URI&&a.push(f),"SUBTITLES"===d.TYPE&&s.push(f)}else if("STREAM-INF"===c&&l){var h=new MasterStream,p=parseAttr(l);if(h.bitrate=parseInt(p["AVERAGE-BANDWIDTH"]||p.BANDWIDTH),h.name=p.NAME,h.url=getAbsoluteUrl(e[i++],t),p.RESOLUTION){var _=_slicedToArray$1(p.RESOLUTION.split("x"),2),y=_[0],v=_[1];h.width=parseInt(y),h.height=parseInt(v)}if(p.CODECS){var m=p.CODECS.split(/[ ,]+/).filter(Boolean);h.videoCodec=getCodecs("video",m),h.audioCodec=getCodecs("audio",m),h.textCodec=getCodecs("text",m)}h.audioGroup=p.AUDIO,h.subtitleGroup=p.SUBTITLES,n.streams.push(h)}}}return n.streams.forEach((function(e,t){e.id=t})),a.length&&(a.forEach((function(e,t){e.id=t})),n.streams.forEach((function(e){e.audioGroup&&(e.audioStreams=a.filter((function(t){return t.group===e.audioGroup})))}))),s.length&&(s.forEach((function(e,t){e.id=t})),n.streams.forEach((function(e){e.subtitleGroup&&(e.subtitleStreams=s.filter((function(t){return t.group===e.subtitleGroup})))}))),n}function parseMediaPlaylist(e,t,r){var n=new MediaPlaylist;n.url=t;for(var i,a=new MediaSegment(t),s=null,o=null,u=0,c=0,l=0,d=0,f=!1,h=0;i=e[d++];)if("#"===i[0]){var p=parseTag(i);if(p){var _=_slicedToArray$1(p,2),y=_[0],v=_[1];switch(y){case"VERSION":n.version=parseInt(v);break;case"PLAYLIST-TYPE":n.type=null==v?void 0:v.toUpperCase();break;case"TARGETDURATION":n.targetDuration=parseFloat(v);break;case"PART-INF":r&&(n.lowLatency=!0);var m=parseAttr(v);m["PART-TARGET"]&&(n.partTargetDuration=parseFloat(m["PART-TARGET"]));break;case"SERVER-CONTROL":var g=parseAttr(v);n.canBlockReload="YES"===g["CAN-BLOCK-RELOAD"],n.partHoldBack=parseFloat(g["PART-HOLD-BACK"]||0),n.canSkipUntil=parseFloat(g["CAN-SKIP-UNTIL"]||0),n.canSkipDateRanges=n.canSkipUntil>0&&"YES"===g["CAN-SKIP-DATERANGES"];break;case"ENDLIST":f=!0;break;case"MEDIA-SEQUENCE":c=n.startSN=parseInt(v);break;case"DISCONTINUITY-SEQUENCE":l=n.startCC=parseInt(v);break;case"DISCONTINUITY":l++;break;case"BYTERANGE":a.setByteRange(v,n.segments[n.segments.length-1]);break;case"PART":if(!n.lowLatency)break;var E=parseAttr(v);a.duration=parseFloat(E.DURATION),a.independent="YES"===E.INDEPENDENT,a.sn=c,a.cc=l,a.partIndex=h,a.start=u,a.duration=parseFloat(E.DURATION),u+=a.duration,a.url=getAbsoluteUrl(E.URI,t),o&&(a.key=o.clone(c)),s&&(a.initSegment=s),n.segments.push(a),a=new MediaSegment(t),h++;break;case"PRELOAD-HINT":var b=parseAttr(v);if(n.preloadHint=b,"PART"===b.TYPE&&b.URI){var S=b.URI.split(".ts")[0].split("-");n.nextSN=S[3],n.nextIndex=S[S.length-1]}break;case"PROGRAM-DATE-TIME":a.dataTime=v;break;case"EXTINF":if(n.lowLatency){h=0;break}var T=_slicedToArray$1(v.split(","),2),k=T[0],P=T[1];a.start=u,a.duration=parseFloat(k),u+=a.duration,a.title=P;break;case"KEY":var A=parseAttr(v);if("NONE"===A.METHOD){o=null;break}if((o=new MediaSegmentKey).method=A.METHOD,o.url=/^blob:/.test(A.URI)?A.URI:getAbsoluteUrl(A.URI,t),o.keyFormat=A.KEYFORMAT||"identity",o.keyFormatVersions=A.KEYFORMATVERSIONS,!o.isSupported())throw new Error("encrypt ".concat(A.METHOD,"/").concat(A.KEYFORMAT," is not supported"));if(A.IV){var x=A.IV.slice(2);x=(1&x.length?"0":"")+x,o.iv=new Uint8Array(x.length/2);for(var w=0,C=x.length/2;w<C;w++)o.iv[w]=parseInt(x.slice(2*w,2*w+2),16)}break;case"MAP":var R=parseAttr(v);a.url=getAbsoluteUrl(R.URI,t),R.BYTERANGE&&a.setByteRange(R.BYTERANGE),a.isInitSegment=!0,a.sn=0,o&&(a.key=o.clone(0)),s=a,a=new MediaSegment(t);break;case"SKIP":var $=parseAttr(v),D=parseInt($["SKIPPED-SEGMENTS"],10);D<=Number.MAX_SAFE_INTEGER&&(n.skippedSegments+=D,c+=D);break;case"DATERANGE":var O=parseAttr(v),I=n.dateRanges[O.ID];O._startDate=I?I._startDate:new Date(O["START-DATE"]);var L=(null==I?void 0:I._endDate)||new Date(O.END_DATE);Number.isFinite(L)&&(O._endDate=L),(isValidDaterange(O,I)||n.skippedSegments)&&(n.dateRanges[O.ID]=O)}}}else{if(n.lowLatency){c++;continue}a.sn=c,a.cc=l,a.url=getAbsoluteUrl(i,t),o&&(a.key=o.clone(c)),s&&(a.initSegment=s),n.segments.push(a),a=new MediaSegment(t),c++}n.segments=n.segments.filter((function(e){return 0!==e.duration}));var M=n.segments[n.segments.length-1];return M&&(f&&(M.isLast=!0),n.endSN=M.sn,n.endPartIndex=M.partIndex),f&&(n.live=!1),n.totalDuration=u,n.endCC=l,n}var M3U8Parser=function(){function e(){_classCallCheck$3(this,e)}return _createClass$3(e,null,[{key:"parse",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",r=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0;if(!t.includes("#EXTM3U"))throw new Error("Invalid m3u8 file");var i=getLines(t);return e.isMediaPlaylist(t)?parseMediaPlaylist(i,r,n):parseMasterPlaylist(i,r)}},{key:"isMediaPlaylist",value:function(e){return e.includes("#EXTINF:")||e.includes("#EXT-X-TARGETDURATION:")}}]),e}(),ManifestLoader=function(){function e(t){var r=this;_classCallCheck$3(this,e),_defineProperty$3(this,"_emitOnLoaded",(function(e,t){var n=e.response,i=e.options||{},a=i.firstByteTime,s=i.startTime,o=i.endTime,u=i.contentLength,c=o-s;r.hls.emit(EVENT.SPEED,{time:c,byteLength:u,url:t}),r.hls.emit(EVENT.LOAD_COMPLETE,{url:t,elapsed:c||0}),r.hls.emit(EVENT.TTFB,{url:t,responseUrl:n.url,elapsed:a-s}),r.hls.emit(EVENT.LOAD_RESPONSE_HEADERS,{headers:n.headers,url:t})})),_defineProperty$3(this,"_onLoaderRetry",(function(e,t){r.hls.emit(Event$1.LOAD_RETRY,{error:StreamingError.network(e),retryTime:t})})),this.hls=t,this._timer=null,this._useLowLatency=t.config.useLowLatency;var n=this.hls.config,i=n.retryCount,a=n.retryDelay,s=n.manifestLoadTimeout,o=n.fetchOptions;this._loader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},o),{},{responseType:"text",retry:i,retryDelay:a,timeout:s,onRetryError:this._onLoaderRetry})),this._audioLoader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},o),{},{responseType:"text",retry:i,retryDelay:a,timeout:s,onRetryError:this._onLoaderRetry})),this._subtitleLoader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},o),{},{responseType:"text",retry:i,retryDelay:a,timeout:s,onRetryError:this._onLoaderRetry}))}var t;return _createClass$3(e,[{key:"load",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r,n){var i,a,s,o,u,c,l,d,f,h,p,_,y,v,m,g,E,b,S,T;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=[this._loader.load(t)],r&&i.push(this._audioLoader.load(r)),n&&i.push(this._subtitleLoader.load(n)),e.prev=3,e.next=6,Promise.all(i);case 6:if(d=e.sent,f=_slicedToArray$1(d,3),h=f[0],p=f[1],_=f[2],h){e.next=13;break}return e.abrupt("return",[]);case 13:this._emitOnLoaded(h,t),a=h.data,u=h.response.url||t,r?(s=null==p?void 0:p.data,o=null==_?void 0:_.data,c=(null==p||null===(y=p.response)||void 0===y?void 0:y.url)||r,l=(null==_||null===(v=_.response)||void 0===v?void 0:v.url)||n,s&&this._emitOnLoaded(p,r),o&&this._emitOnLoaded(_,n)):(o=null==p?void 0:p.data,l=(null==p||null===(m=p.response)||void 0===m?void 0:m.url)||n,o&&this._emitOnLoaded(p,n)),e.next=22;break;case 19:throw e.prev=19,e.t0=e.catch(3),StreamingError.network(e.t0);case 22:if(g=this.hls.config.onPreM3U8Parse,e.prev=23,g&&(a=g(a)||a,s&&(s=g(s,!0)||s),o&&(o=g(o,!0)||o)),E=M3U8Parser.parse(a,u,this._useLowLatency),!1!==(null===(T=E)||void 0===T?void 0:T.live)||!E.segments||E.segments.length){e.next=28;break}throw new Error("empty segments list");case 28:s&&(b=M3U8Parser.parse(s,c,this._useLowLatency)),o&&(S=M3U8Parser.parse(o,l,this._useLowLatency)),e.next=35;break;case 32:throw e.prev=32,e.t1=e.catch(23),new StreamingError(ERR.MANIFEST,ERR.SUB_TYPES.HLS,e.t1);case 35:return E&&(E.isMaster?this.hls.emit(Event$1.HLS_MANIFEST_LOADED,{playlist:E}):(this._useLowLatency&&(E.canBlockReload?this.deliveryDirectives=new HlsUrlParameters(E.nextSN,E.nextIndex,""):this.deliveryDirectives=null),this.hls.emit(Event$1.HLS_LEVEL_LOADED,{playlist:E}))),e.abrupt("return",[E,b,S]);case 37:case"end":return e.stop()}}),e,this,[[3,19],[23,32]])}))),function(e,r,n){return t.apply(this,arguments)})},{key:"parseText",value:function(e,t){var r,n=this.hls.config.onPreM3U8Parse;try{var i;if(n&&(e=n(e)||e),!1===(null===(i=r=M3U8Parser.parse(e,t,this._useLowLatency))||void 0===i?void 0:i.live)&&r.segments&&!r.segments.length)throw new Error("empty segments list")}catch(e){throw new StreamingError(ERR.MANIFEST,ERR.SUB_TYPES.HLS,e)}return r&&(r.isMaster?this.hls.emit(Event$1.HLS_MANIFEST_LOADED,{playlist:r}):this.hls.emit(Event$1.HLS_LEVEL_LOADED,{playlist:r})),[r]}},{key:"poll",value:function(e,t,r,n,i,a){var s=this;clearTimeout(this._timer),a=a||3e3;var o=this.hls.config.pollRetryCount,u=function(){var c=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function c(){var l,d;return _regeneratorRuntime$1().wrap((function(c){for(;;)switch(c.prev=c.next){case 0:return clearTimeout(s._timer),l=e,c.prev=2,s.deliveryDirectives&&(l=s.deliveryDirectives.addDirectives(e)),c.next=6,s.load(l,t,r);case 6:if((d=c.sent)[0]){c.next=9;break}return c.abrupt("return");case 9:o=s.hls.config.pollRetryCount,n(d[0],d[1],d[2]),c.next=17;break;case 13:c.prev=13,c.t0=c.catch(2),--o<=0&&i(c.t0);case 17:s._timer=setTimeout(u,a);case 18:case"end":return c.stop()}}),c,null,[[2,13]])})));return function(){return c.apply(this,arguments)}}();this._timer=setTimeout(u,a)}},{key:"stopPoll",value:function(){return clearTimeout(this._timer),this.cancel()}},{key:"cancel",value:function(){return Promise.all([this._loader.cancel(),this._audioLoader.cancel()])}}]),e}();function clamp(e,t,r){return t>r&&(r=t),Math.min(Math.max(e,t),r)}var logger$1=new Logger$2("playlist"),Stream=function(){function e(t,r,n){_classCallCheck$3(this,e),_defineProperty$3(this,"live",void 0),_defineProperty$3(this,"id",0),_defineProperty$3(this,"bitrate",0),_defineProperty$3(this,"width",0),_defineProperty$3(this,"height",0),_defineProperty$3(this,"name",""),_defineProperty$3(this,"url",""),_defineProperty$3(this,"audioCodec",""),_defineProperty$3(this,"videoCodec",""),_defineProperty$3(this,"textCodec",""),_defineProperty$3(this,"startCC",0),_defineProperty$3(this,"endCC",0),_defineProperty$3(this,"startSN",0),_defineProperty$3(this,"endSN",-1),_defineProperty$3(this,"totalDuration",0),_defineProperty$3(this,"targetDuration",0),_defineProperty$3(this,"partTargetDuration",0),_defineProperty$3(this,"canSkipUntil",0),_defineProperty$3(this,"canSkipDateRanges",!1),_defineProperty$3(this,"skippedSegments",0),_defineProperty$3(this,"canBlockReload",!1),_defineProperty$3(this,"partHoldBack",0),_defineProperty$3(this,"lowLatency",!1),_defineProperty$3(this,"endPartIndex",0),_defineProperty$3(this,"snDiff",null),_defineProperty$3(this,"segments",[]),_defineProperty$3(this,"audioStreams",[]),_defineProperty$3(this,"subtitleStreams",[]),_defineProperty$3(this,"closedCaptions",[]),_defineProperty$3(this,"currentAudioStream",null),_defineProperty$3(this,"currentSubtitleStream",null),this.update(this._setLLPlaybackPoint(t),r,n)}return _createClass$3(e,[{key:"lastSegment",get:function(){return this.segments.length?this.segments[this.segments.length-1]:null}},{key:"segmentDuration",get:function(){var e;return this.targetDuration||(null===(e=this.segments[0])||void 0===e?void 0:e.duration)||0}},{key:"liveEdge",get:function(){return this.endTime},set:function(e){this.endTime=e}},{key:"endTime",get:function(){var e;return(null===(e=this.lastSegment)||void 0===e?void 0:e.end)||0},set:function(e){var t=this.lastSegment;t&&(t.duration=e-t.start)}},{key:"currentSubtitleEndSn",get:function(){var e;return(null===(e=this.currentSubtitleStream)||void 0===e?void 0:e.endSN)||0}},{key:"clearOldSegment",value:function(e,t){return this.currentAudioStream&&this._clearSegments(e,t),this._clearSegments(e,t)}},{key:"getAudioSegment",value:function(e){if(e&&this.currentAudioStream){var t=e.sn-this.snDiff;return this.currentAudioStream.segments.find((function(e){return e.sn===t}))}}},{key:"update",value:function(e,t){this.url=e.url,Array.isArray(e.segments)?(null!==this.live&&void 0!==this.live||(this.live=e.live),this._updateSegments(e,this),this.startCC=e.startCC,this.endCC=e.endCC,this.startSN=e.startSN,this.endSN=e.endSN||-1,this.totalDuration=e.totalDuration,this.targetDuration=e.targetDuration,this.live=e.live,this.lowLatency=e.lowLatency,this.canBlockReload=e.canBlockReload,this.canSkipDateRanges=e.canSkipDateRanges,this.canSkipUntil=e.canSkipUntil,this.partHoldBack=e.partHoldBack,this.partTargetDuration=e.partTargetDuration,this.skippedSegments=e.skippedSegments,this.endPartIndex=e.endPartIndex,t&&this.currentAudioStream&&Array.isArray(t.segments)&&(this._updateSegments(t,this.currentAudioStream),(null===this.snDiff||void 0===this.snDiff)&&e.segments.length&&t.segments.length&&(this.snDiff=e.segments[0].sn-t.segments[0].sn))):(this.id=e.id,this.bitrate=e.bitrate,this.width=e.width,this.height=e.height,this.name=e.name,this.audioCodec=e.audioCodec,this.videoCodec=e.videoCodec,this.textCodec=e.textCodec,this.audioStreams=e.audioStreams,this.subtitleStreams=e.subtitleStreams,!this.currentAudioStream&&this.audioStreams.length&&(this.currentAudioStream=this.audioStreams.find((function(e){return e.default}))||this.audioStreams[0]),!this.currentSubtitleStream&&this.subtitleStreams.length&&(this.currentSubtitleStream=this.subtitleStreams.find((function(e){return e.default}))||this.subtitleStreams[0]))}},{key:"updateSubtitle",value:function(e){var t=this;if(e&&this.currentSubtitleStream&&Array.isArray(e.segments)){var r=this._updateSegments(e,this.currentSubtitleStream),n=this.currentSubtitleStream.segments;if(n.length>100&&(this.currentSubtitleStream.segments=n.slice(100)),r)return r.map((function(e){return{sn:e.sn,url:e.url,duration:e.duration,start:e.start,end:e.end,lang:t.currentSubtitleStream.lang}}))}}},{key:"switchSubtitle",value:function(e){var t=this.subtitleStreams.find((function(t){return t.lang===e})),r=this.currentSubtitleStream;t&&(this.currentSubtitleStream=t,r.segments=[])}},{key:"_setLLPlaybackPoint",value:function(e){if(!e.lowLatency||!e.segments.length)return e;for(var t=e.totalDuration-e.partHoldBack,r=e.segments,n=0,i=0,a=r.length;i<a;i++)r[i].start<=t&&r[i].independent&&(n=i);var s=r.slice(n),o=0;return s.forEach((function(e){e.start=o,o=e.end})),e.segments=s,e.totalDuration=o,e.startSN=s[0].sn,e.startCC=s[0].cc,logger$1.log("set ll-hls playback point: SN=".concat(e.startSN," partIndex=").concat(s[0].partIndex,", duration=").concat(o)),e}},{key:"_clearSegments",value:function(e,t){for(var r=0,n=this.segments,i=0,a=n.length;i<a;i++)if(n[i].end>=e){r=i;break}return r>t&&(r=t),r&&(this.segments=this.segments.slice(r),this.currentAudioStream&&(this.currentAudioStream.segments=this.currentAudioStream.segments.slice(r))),t-r}},{key:"_updateSegments",value:function(e,t){var r=t.segments;if(this.live){var n,i=e.lowLatency,a=r[r.length-1],s=null!==(n=null==a?void 0:a.sn)&&void 0!==n?n:-1,o=(null==a?void 0:a.partIndex)||0,u=s<e.endSN&&e.segments.length;if(i&&(u=u||o<e.endPartIndex),u){logger$1.log("update segments: endSN:".concat(s,", partIndex:").concat(o," --\x3e endSN:").concat(e.endSN,", partIndex:").concat(e.endPartIndex));var c=e.segments.findIndex((function(e){return e.sn===s&&e.partIndex===o})),l=c<0?e.segments:e.segments.slice(c+1);if(r.length&&l.length){var d=a.end,f=d;l.forEach((function(e){e.start=d,d=e.end})),logger$1.log("liveEdge: ".concat(f," -> ").concat(d));var h=(null==a?void 0:a.cc)||-1;h>l[0].cc&&l.forEach((function(e){return e.cc+=h}))}return t.endSN=e.endSN,t.segments=r.concat(l),l}}else t.segments=e.segments}}]),e}(),Playlist=function(){function e(t){_classCallCheck$3(this,e),_defineProperty$3(this,"streams",[]),_defineProperty$3(this,"currentStream",null),_defineProperty$3(this,"dvrWindow",0),_defineProperty$3(this,"_segmentPointer",-1),this.hls=t}return _createClass$3(e,[{key:"lowLatency",get:function(){var e;return null===(e=this.currentStream)||void 0===e?void 0:e.lowLatency}},{key:"lastSegment",get:function(){var e;return null===(e=this.currentStream)||void 0===e?void 0:e.lastSegment}},{key:"currentSegment",get:function(){var e;return null===(e=this.currentSegments)||void 0===e?void 0:e[this._segmentPointer]}},{key:"nextSegment",get:function(){var e;return null===(e=this.currentSegments)||void 0===e?void 0:e[this._segmentPointer+1]}},{key:"currentSegments",get:function(){var e;return null===(e=this.currentStream)||void 0===e?void 0:e.segments}},{key:"currentSubtitleEndSn",get:function(){var e;return null===(e=this.currentStream)||void 0===e?void 0:e.currentSubtitleEndSn}},{key:"liveEdge",get:function(){var e;return null===(e=this.currentStream)||void 0===e?void 0:e.liveEdge},set:function(e){this.currentStream&&(this.currentStream.liveEdge=e)}},{key:"totalDuration",get:function(){var e;return(null===(e=this.currentStream)||void 0===e?void 0:e.totalDuration)||0}},{key:"seekRange",get:function(){var e=this.currentSegments;if(e&&e.length)return[e[0].start,e[e.length-1].end]}},{key:"nbSegments",get:function(){var e;return(null===(e=this.currentSegments)||void 0===e?void 0:e.length)||0}},{key:"isEmpty",get:function(){var e;return!(null!==(e=this.currentSegments)&&void 0!==e&&e.length)}},{key:"isLive",get:function(){var e;return null===(e=this.currentStream)||void 0===e?void 0:e.live}},{key:"hadSegmentLoaded",get:function(){return-1!==this._segmentPointer}},{key:"hasSubtitle",get:function(){var e;return!(null===(e=this.currentStream)||void 0===e||!e.currentSubtitleStream)}},{key:"getAudioSegment",value:function(e){var t;return null===(t=this.currentStream)||void 0===t?void 0:t.getAudioSegment(e)}},{key:"moveSegmentPointer",value:function(e){var t;null==e&&(e=this._segmentPointer+1),this._segmentPointer=clamp(e,-1,null===(t=this.currentSegments)||void 0===t?void 0:t.length)}},{key:"reset",value:function(){this.streams=[],this.currentStream=null,this.dvrWindow=0,this._segmentPointer=-1}},{key:"getSegmentByIndex",value:function(e){var t;return null===(t=this.currentSegments)||void 0===t?void 0:t[e]}},{key:"setNextSegmentByIndex",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this._segmentPointer=e-1}},{key:"setNextSegmentBySN",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=null===(e=this.currentSegments)||void 0===e?void 0:e.findIndex((function(e){return e.sn===t}));return-1!==r&&this.setNextSegmentByIndex(r+1),r}},{key:"findSegmentIndexByTime",value:function(e){var t=this.currentSegments;if(t){for(var r,n=0,i=t.length;n<i;n++)if(e>=(r=t[n]).start&&e<r.end)return n;var a=t[t.length-1];if(Math.abs(e-(null==a?void 0:a.end))<.2)return t.length-1}}},{key:"upsertPlaylist",value:function(e,t,r){var n=this;if(e){if(e.isMaster)this.streams.length=e.streams.length,e.streams.filter((function(e){return e.url})).forEach((function(e,t){n.streams[t]?n.streams[t].update(e):n.streams[t]=new Stream(e)})),this.currentStream=this.streams[0];else if(Array.isArray(e.segments)){var i=this.currentStream;if(i){i.update(e,t,r);var a=i.updateSubtitle(r);a&&this.hls.emit(Event$1.SUBTITLE_SEGMENTS,{list:a})}else this.reset(),this.currentStream=this.streams[0]=new Stream(e,t,r)}this.currentStream&&this.hls.isLive&&!this.dvrWindow&&(this.dvrWindow=this.currentSegments.reduce((function(e,t){return e+=t.duration}),0))}}},{key:"updateSegmentsRanges",value:function(e,t){var r;(null===(r=this.currentSegments)||void 0===r?void 0:r.filter((function(t){return t.sn>=e}))).forEach((function(e){e.start=t,t=e.end}))}},{key:"switchSubtitle",value:function(e){var t;null===(t=this.currentStream)||void 0===t||t.switchSubtitle(e)}},{key:"clearOldSegment",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.hls.config.maxPlaylistSize||50,t=this.currentStream;if(this.dvrWindow&&t){var r=t.endTime-this.dvrWindow;if(!(r<=0))t.segments.length<=e||(this._segmentPointer=t.clearOldSegment(r,this._segmentPointer))}}},{key:"checkSegmentTrackChange",value:function(e,t){var r=this.findSegmentIndexByTime(e),n=this.getSegmentByIndex(r);if(n&&(n.hasAudio||n.hasVideo)){if(2!==t&&n.hasAudio&&n.hasVideo)return n;if(!(n.end-e>.3)){var i=this.getSegmentByIndex(r+1);if(i&&(i.hasAudio||i.hasVideo))return i.hasAudio!==n.hasAudio||i.hasVideo!==n.hasVideo?i:void 0}}}},{key:"feedbackLiveEdge",value:function(e,t){var r;this.currentSegments&&((null===(r=this.lastSegment)||void 0===r?void 0:r.sn)===e.sn?this.liveEdge=t:this.updateSegmentsRanges(e.sn+1,t))}}]),e}(),SegmentLoader=function(){function e(t){var r=this;_classCallCheck$3(this,e),_defineProperty$3(this,"error",null),_defineProperty$3(this,"_emitOnLoaded",(function(e,t){var n=e.data,i=e.response,a=e.options||{},s=a.firstByteTime,o=a.startTime,u=a.endTime,c=a.contentLength,l=u-o;r._bandwidthService.addRecord(c||n.byteLength,l),r.hls.emit(EVENT.SPEED,{time:l,byteLength:c,url:t}),r.hls.emit(EVENT.LOAD_COMPLETE,{url:t,elapsed:l||0}),r.hls.emit(EVENT.TTFB,{url:t,responseUrl:i.url,elapsed:s-o}),r.hls.emit(EVENT.LOAD_RESPONSE_HEADERS,{headers:i.headers,url:t})})),_defineProperty$3(this,"_onLoaderRetry",(function(e,t){r.hls.emit(EVENT.LOAD_RETRY,{error:StreamingError.network(e),retryTime:t})})),this.hls=t,this._bandwidthService=new BandwidthService,this._mapCache={},this._keyCache={};var n=this.hls.config,i=n.retryCount,a=n.retryDelay,s=n.loadTimeout,o=n.fetchOptions;this._segmentLoader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},o),{},{responseType:"arraybuffer",retry:i,retryDelay:a,timeout:s,onRetryError:this._onLoaderRetry})),this._audioSegmentLoader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},o),{},{responseType:"arraybuffer",retry:i,retryDelay:a,timeout:s,onRetryError:this._onLoaderRetry})),this._keyLoader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},o),{},{responseType:"arraybuffer",retry:i,retryDelay:a,timeout:s,onRetryError:this._onLoaderRetry}))}var t,r;return _createClass$3(e,[{key:"speedInfo",value:function(){return{speed:this._bandwidthService.getLatestSpeed(),avgSpeed:this._bandwidthService.getAvgSpeed()}}},{key:"load",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:r,i=[];return e&&(i[0]=this.loadVideoSegment(e,r)),t&&(i[1]=this.loadAudioSegment(t,n)),Promise.all(i)}},{key:"loadVideoSegment",value:function(e,t){return this._loadSegment(this._segmentLoader,e,t)}},{key:"loadAudioSegment",value:function(e,t){return this._loadSegment(this._audioSegmentLoader,e,t)}},{key:"_loadSegment",value:(r=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r,n){var i,a,s,o,u,c,l,d,f,h,p,_,y,v,m,g=this;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return l=[],this.hls.emit(EVENT.LOAD_START,{url:r.url}),l[0]=t.load(r.url),n&&r.initSegment&&(f=r.initSegment.url,(a=this._mapCache[f])||(this.hls.emit(EVENT.LOAD_START,{url:f}),l[1]=t.load(f).then((function(e){e&&(Object.keys(g._mapCache)>30&&(g._mapCache={}),a=g._mapCache[f]=e.data,g._emitOnLoaded(e,f))}))),(h=null===(d=r.initSegment.key)||void 0===d?void 0:d.url)&&(c=r.initSegment.key.iv,(u=this._keyCache[h])||(this.hls.emit(EVENT.LOAD_START,{url:h}),l[2]=this._keyLoader.load(h).then((function(e){e&&(u=g._keyCache[h]=e.data,g._emitOnLoaded(e,h))}))))),(p=null===(i=r.key)||void 0===i?void 0:i.url)&&r.key.isSegmentEncrypted()&&(o=r.key.iv,(s=this._keyCache[p])||(this.hls.emit(EVENT.LOAD_START,{url:p}),l[3]=this._keyLoader.load(p).then((function(e){e&&(s=g._keyCache[p]=e.data,g._emitOnLoaded(e,p))})))),e.next=8,Promise.all(l);case 8:if(_=e.sent,y=_slicedToArray$1(_,1),v=y[0]){e.next=13;break}return e.abrupt("return");case 13:return m=v.data,this._emitOnLoaded(v,r.url),e.abrupt("return",{data:m,map:a,key:s,mapKey:u,keyIv:o,mapKeyIv:c});case 16:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return r.apply(this,arguments)})},{key:"reset",value:function(){this.error=null,this._mapCache={},this._keyCache={},this._bandwidthService.reset()}},{key:"cancel",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all([this._keyLoader.cancel(),this._segmentLoader.cancel(),this._audioSegmentLoader.cancel()]);case 2:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),logger=new Logger$2("hls"),Hls=function(e){_inherits$2(v,EventEmitter);var t,r,n,i,a,s,o,u,c,l,d,f,h,p,_,y=_createSuper$2(v);function v(e){var t;return _classCallCheck$3(this,v),_defineProperty$3(_assertThisInitialized$2(t=y.call(this)),"version",v.version),_defineProperty$3(_assertThisInitialized$2(t),"media",null),_defineProperty$3(_assertThisInitialized$2(t),"config",null),_defineProperty$3(_assertThisInitialized$2(t),"_manifestLoader",null),_defineProperty$3(_assertThisInitialized$2(t),"_segmentLoader",null),_defineProperty$3(_assertThisInitialized$2(t),"_playlist",null),_defineProperty$3(_assertThisInitialized$2(t),"_bufferService",null),_defineProperty$3(_assertThisInitialized$2(t),"_gapService",null),_defineProperty$3(_assertThisInitialized$2(t),"_seiService",null),_defineProperty$3(_assertThisInitialized$2(t),"_stats",null),_defineProperty$3(_assertThisInitialized$2(t),"_prevSegSn",null),_defineProperty$3(_assertThisInitialized$2(t),"_prevSegCc",null),_defineProperty$3(_assertThisInitialized$2(t),"_tickTimer",null),_defineProperty$3(_assertThisInitialized$2(t),"_tickInterval",500),_defineProperty$3(_assertThisInitialized$2(t),"_segmentProcessing",!1),_defineProperty$3(_assertThisInitialized$2(t),"_reloadOnPlay",!1),_defineProperty$3(_assertThisInitialized$2(t),"_switchUrlOpts",null),_defineProperty$3(_assertThisInitialized$2(t),"_isProcessQuotaExceeded",!1),_defineProperty$3(_assertThisInitialized$2(t),"_loadSegment",_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var r,n,i,a,s,o,u,c;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t._segmentProcessing&&t.media){e.next=2;break}return e.abrupt("return");case 2:if(r=t._playlist,n=r.nextSegment,i=r.lastSegment,a=_assertThisInitialized$2(t),s=a.config,.016,o=Math.min(Math.max((null==i?void 0:i.duration)-.008||0,.016),.1),n){e.next=8;break}return e.abrupt("return");case 8:if(t.isLive){e.next=18;break}if(u=t.bufferInfo(),t.media.paused&&!t.media.currentTime&&(u=t.bufferInfo(u.nextStart||.5)),c=Math.abs(u.end-t.media.duration)<o,!(u.remaining>=s.preloadTime||c&&!n)){e.next=15;break}return t._tryEos(),e.abrupt("return");case 15:if(!s.preferMMSStreaming||t._bufferService.msStreaming){e.next=17;break}return e.abrupt("return");case 17:!t._urlSwitching&&t._prevSegSn!==n.sn-1&&u.end&&Math.abs(n.start-u.end)>1&&t._playlist.setNextSegmentByIndex(t._playlist.findSegmentIndexByTime(u.end+.1));case 18:return e.abrupt("return",t._loadSegmentDirect());case 19:case"end":return e.stop()}}),e)})))),_defineProperty$3(_assertThisInitialized$2(t),"_onLoadeddata",(function(){t.isLive&&!t.config.mseLowLatency&&t.media.duration!==1/0&&t._bufferService.updateDuration(1/0).catch((function(e){}))})),_defineProperty$3(_assertThisInitialized$2(t),"_onPlay",_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!t.media.seeking||0!==t.media.currentTime){e.next=3;break}return logger.debug("replay currentTime 0, return"),e.abrupt("return");case 3:if(clearTimeout(t._disconnectTimer),!t._reloadOnPlay){e.next=9;break}t._reloadOnPlay=!1,t.replay(!0),e.next=12;break;case 9:return e.next=11,t._loadSegment();case 11:t._startTick();case 12:case"end":return e.stop()}}),e)})))),_defineProperty$3(_assertThisInitialized$2(t),"_onPause",(function(){if(t.isLive){if(!t._reloadOnPlay){var e=t.config.disconnectTime;if(null==e&&(e=t._playlist.dvrWindow),!Number.isFinite(e))return;clearTimeout(t._disconnectTimer),t._disconnectTimer=setTimeout((function(){t._reloadOnPlay=!0,t._clear()}),e||0)}}else t._stopTick()})),_defineProperty$3(_assertThisInitialized$2(t),"_onSeeking",_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var r,n,i,a,s,o,u;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.media){e.next=2;break}return e.abrupt("return");case 2:if(t._onCheckQuotaExceeded(),r=t.media.currentTime,!(n=t._playlist.seekRange)){e.next=10;break}if(!((i=clamp(r,n[0],t.isLive?n[1]:t.media.duration))>=0&&Math.abs(r-i)>=.1)){e.next=10;break}return t.media.currentTime=i,e.abrupt("return");case 10:if(a=t._playlist.currentSegment,s=Buffer$1.info(Buffer$1.get(t.media),r,.1),!a){e.next=17;break}if(!(s.end&&Math.abs(s.end-a.end)<.2)){e.next=15;break}return e.abrupt("return");case 15:if(!t.isLive||!s.end){e.next=17;break}return e.abrupt("return");case 17:if(o=t._playlist.findSegmentIndexByTime(r),u=t._playlist.getSegmentByIndex(o),null!=o&&u&&(!t._segmentProcessing||u!==t._playlist.nextSegment)){e.next=21;break}return e.abrupt("return");case 21:return logger.debug("seek to",r,u),t._playlist.setNextSegmentByIndex(o),t._stopTick(),e.next=26,t._segmentLoader.cancel();case 26:if(t._segmentProcessing=!1,s.end&&!t.isLive){e.next=30;break}return e.next=30,t._loadSegmentDirect(!0);case 30:t._startTick();case 31:case"end":return e.stop()}}),e)})))),_defineProperty$3(_assertThisInitialized$2(t),"_onTimeupdate",(function(){if(t.media){var e,r=t.config;if(r.isLive&&r.maxLatency&&r.targetLatency){var n=t._playlist.liveEdge;if(!n)return;var i=n-t.media.currentTime;i>=r.maxLatency&&(logger.debug("latency jump, currentTime:".concat(t.media.currentTime,", liveEdge:").concat(n,", latency=").concat(i)),t.media.currentTime=n-r.targetLatency)}if(r.seiInTime)null===(e=t._seiService)||void 0===e||e.throw(t.media.currentTime);r.allowedStreamTrackChange&&!r.softDecode&&t.media.readyState&&t._checkStreamTrackChange(t.media.currentTime)}})),_defineProperty$3(_assertThisInitialized$2(t),"_tick",(function(){if(t.media){t._startTick();var e=t.media,r=t._segmentLoader.error;if(t._onCheckQuotaExceeded(),t._isProcessQuotaExceeded&&(t._bufferService.isFull()||(t._isProcessQuotaExceeded=!1,t._segmentProcessing=!1)),r){(!e.readyState||t.bufferInfo(.5).remaining<1)&&(r.fatal=!0,t._emitError(StreamingError.network(r)))}else e.readyState&&(isMediaPlaying(e)?(t._loadSegment(),t._gapService&&t._gapService.do(e,t.config.maxJumpDistance,t.isLive)):e.readyState<2&&t._gapService&&t._gapService.do(e,t.config.maxJumpDistance,!e.currentTime||t.isLive)),t.isLive||t._tryEos()}})),t.config=e=getConfig(e),t.media=t.config.media,t._manifestLoader=new ManifestLoader(_assertThisInitialized$2(t)),t._segmentLoader=new SegmentLoader(_assertThisInitialized$2(t)),t._playlist=new Playlist(_assertThisInitialized$2(t)),t._bufferService=new BufferService(_assertThisInitialized$2(t)),e.seiInTime&&(t._seiService=new SeiService(_assertThisInitialized$2(t))),e.softDecode||(t._gapService=new GapService),t._stats=new MediaStatsService(_assertThisInitialized$2(t),9e4),t.media.addEventListener("loadeddata",t._onLoadeddata),t.media.addEventListener("play",t._onPlay),t.media.addEventListener("pause",t._onPause),t.media.addEventListener("seeking",t._onSeeking),t.media.addEventListener("timeupdate",t._onTimeupdate),t}return _createClass$3(v,[{key:"isLive",get:function(){return this._playlist.isLive}},{key:"streams",get:function(){return this._playlist.streams}},{key:"currentStream",get:function(){return this._playlist.currentStream}},{key:"hasSubtitle",get:function(){return this._playlist.hasSubtitle}},{key:"totalDuration",get:function(){return this._playlist.totalDuration}},{key:"baseDts",get:function(){var e;return null===(e=this._bufferService)||void 0===e?void 0:e.baseDts}},{key:"abrSwitchPoint",get:function(){var e=this._urlSwitching?this._playlist.currentSegment:this._playlist.nextSegment;return e?e.start+e.duration/2:null}},{key:"speedInfo",value:function(){return this._segmentLoader.speedInfo()}},{key:"bufferInfo",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:.1;return Buffer$1.info(Buffer$1.get(this.media),null===(e=this.media)||void 0===e?void 0:e.currentTime,t)}},{key:"getStats",value:function(){return this._stats.getStats()}},{key:"playbackQuality",value:function(){return getVideoPlaybackQuality(this.media)}},{key:"load",value:(_=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,r,n,i=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=i.length>0&&void 0!==i[0]?i[0]:"",n="boolean"==typeof(r=i.length>1&&void 0!==i[1]?i[1]:{})?r:!(null==r||!r.reuseMse),"object"===_typeof$2(r)&&null!=r&&r.clearSwitchStatus&&(this._urlSwitching=!1,this._switchUrlOpts=null,this.config.startTime=void 0),t&&(this.config.url=t),t=this.config.url,e.next=8,this._reset(n);case 8:return e.next=10,this._loadData(t);case 10:this._startTick();case 11:case"end":return e.stop()}}),e,this)}))),function(){return _.apply(this,arguments)})},{key:"_loadData",value:(p=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,s,o,u,c,l,d,f,h,p;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:try{t&&(t=t.trim())}catch(e){}if(t){e.next=3;break}throw this._emitError(new StreamingError(ERR.OTHER,ERR.SUB_TYPES.OPTION,null,null,"m3u8 url is missing"));case 3:return e.next=5,this._loadM3U8(t);case 5:if(r=e.sent,n=this._playlist.currentStream,!this._urlSwitching){e.next=23;break}if(!this.isLive){e.next=14;break}i=this._playlist.setNextSegmentBySN(this._prevSegSn),logger.log("segment nb=".concat(this._prevSegSn," index of ").concat(i," in the new playlist")),-1===i&&(this._prevSegCc=null,this._prevSegSn=null),e.next=23;break;case 14:if(0===n.bitrate&&null!==(a=this._switchUrlOpts)&&void 0!==a&&a.bitrate&&(n.bitrate=null===(u=this._switchUrlOpts)||void 0===u?void 0:u.bitrate),c="number"==typeof(null===(s=this._switchUrlOpts)||void 0===s?void 0:s.startTime)?null===(o=this._switchUrlOpts)||void 0===o?void 0:o.startTime:this._getSeamlessSwitchPoint(),this.config.startTime=c,l=this._playlist.findSegmentIndexByTime(c),!(d=this._playlist.getSegmentByIndex(l+1))){e.next=23;break}return f=d.start,e.next=23,this._bufferService.removeBuffer(f);case 23:if(r){e.next=25;break}return e.abrupt("return");case 25:if(!this.isLive){e.next=36;break}if(this._bufferService.setLiveSeekableRange(0,4294967295),logger.log("totalDuration first time got:",this._playlist.totalDuration),logger.log("nb segments got:",this._playlist.nbSegments),this.config.targetLatency<this._playlist.totalDuration&&(this.config.targetLatency=this._playlist.totalDuration,this.config.maxLatency=1.5*this.config.targetLatency),r.isMaster||this._pollM3U8(t),!(this._playlist.nbSegments<this.config.minSegmentsStartPlay)){e.next=33;break}return e.abrupt("return");case 33:return e.next=35,this._loadSegment();case 35:return e.abrupt("return");case 36:return e.next=38,this._bufferService.updateDuration(n.totalDuration);case 38:return(h=this.config.startTime)&&(null!==(p=this._switchUrlOpts)&&void 0!==p&&p.seamless||(this.media.currentTime=h),this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(h)||0)),e.next=42,this._loadSegment();case 42:case"end":return e.stop()}}),e,this)}))),function(e){return p.apply(this,arguments)})},{key:"replay",value:(h=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.config.startTime=0,this._urlSwitching=!1,this._switchUrlOpts=null,e.next=5,this.load();case 5:return this._reloadOnPlay=!1,e.abrupt("return",this.media.play(!t));case 7:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"switchURL",value:(f=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,s,o,u,c=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:r=c.length>1&&void 0!==c[1]?c[1]:{},n={seamless:!1,startTime:0,bitrate:0},e.t0=_typeof$2(r),e.next="number"===e.t0?5:"boolean"===e.t0?7:"object"===e.t0?9:11;break;case 5:return r={startTime:r},e.abrupt("break",12);case 7:return r={seamless:r},e.abrupt("break",12);case 9:for(i in r)void 0!==r[i]&&null!==r[i]||delete r[i];return e.abrupt("break",12);case 11:throw"unsupported switchURL args: ".concat(r);case 12:if(r=Object.assign({},n,r),s=(a=r).seamless,o=a.startTime,this.config.url=t,this.config.startTime=o,this._switchUrlOpts=r,s){e.next=38;break}if(e.prev=18,!this.config.softDecode){e.next=23;break}e.t1=this.load(t),e.next=26;break;case 23:return e.next=25,this.load(t);case 25:e.t1=e.sent;case 26:u=e.t1,e.next=33;break;case 29:throw e.prev=29,e.t2=e.catch(18),this.emit(Event$1.SWITCH_URL_FAILED,e.t2),e.t2;case 33:return this._reloadOnPlay=!1,u&&this.emit(Event$1.SWITCH_URL_SUCCESS,{url:t}),e.abrupt("return",this.media.play(!0));case 38:return this._urlSwitching=!0,this.isLive||(this._prevSegSn=null,this._prevSegCc=null),this._playlist.reset(),this._bufferService.seamlessSwitch(),e.next=44,this._clear();case 44:return e.next=46,this._loadData(t);case 46:this._startTick();case 47:this._switchUrlOpts=null;case 48:case"end":return e.stop()}}),e,this,[[18,29]])}))),function(e){return f.apply(this,arguments)})},{key:"switchStream",value:(d=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,s,o=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!(o.length>1&&void 0!==o[1])||o[1],n=this.currentStream,i=this.streams,n&&n.id!==t&&i&&!(i.length<2)){e.next=5;break}return e.abrupt("return");case 5:if(a=i.find((function(e){return e.id===t}))){e.next=8;break}return e.abrupt("return");case 8:return e.prev=8,e.next=11,this._clear();case 11:if(!r){e.next=14;break}return e.next=14,this._bufferService.clearAllBuffer();case 14:e.next=19;break;case 16:throw e.prev=16,e.t0=e.catch(8),this._emitError(StreamingError.create(e.t0));case 19:if(n.currentAudioStream&&a.audioStreams.length>2&&(s=n.currentAudioStream.id,a.currentAudioStream=a.audioStreams.find((function(e){return e.id===s}))||a.currentAudioStream),this._playlist.currentStream=a,e.prev=21,!this.isLive&&a.segments.length){e.next=25;break}return e.next=25,this._refreshM3U8();case 25:return this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(this.media.currentTime)||0),this._prevSegCc=null,e.next=29,this._loadSegmentDirect();case 29:e.next=35;break;case 31:throw e.prev=31,e.t1=e.catch(21),this._playlist.currentStream=n,e.t1;case 35:return this._startTick(),e.abrupt("return",a);case 37:case"end":return e.stop()}}),e,this,[[8,16],[21,31]])}))),function(e){return d.apply(this,arguments)})},{key:"switchAudioStream",value:(l=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,s=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!(s.length>1&&void 0!==s[1])||s[1],n=this.currentStream){e.next=4;break}return e.abrupt("return");case 4:if((i=n.currentAudioStream)&&i.id!==t&&!(n.audioStreams.length<2)){e.next=7;break}return e.abrupt("return");case 7:if(a=n.audioStreams.find((function(e){return e.id===t}))){e.next=10;break}return e.abrupt("return");case 10:return e.prev=10,e.next=13,this._clear();case 13:if(!r){e.next=16;break}return e.next=16,this._bufferService.clearAllBuffer();case 16:e.next=21;break;case 18:throw e.prev=18,e.t0=e.catch(10),this._emitError(StreamingError.create(e.t0));case 21:if(n.currentAudioStream=a,e.prev=22,!this.isLive&&a.segments.length){e.next=26;break}return e.next=26,this._refreshM3U8();case 26:return this._playlist.setNextSegmentByIndex(this._playlist.findSegmentIndexByTime(this.media.currentTime)||0),this._prevSegCc=null,e.next=30,this._loadSegmentDirect();case 30:e.next=36;break;case 32:throw e.prev=32,e.t1=e.catch(22),n.currentAudioStream=i,e.t1;case 36:return this._startTick(),e.abrupt("return",a);case 38:case"end":return e.stop()}}),e,this,[[10,18],[22,32]])}))),function(e){return l.apply(this,arguments)})},{key:"switchSubtitleStream",value:(c=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this._playlist.switchSubtitle(t),e.next=3,this._manifestLoader.stopPoll();case 3:return e.next=5,this._refreshM3U8();case 5:case"end":return e.stop()}}),e,this)}))),function(e){return c.apply(this,arguments)})},{key:"detachMedia",value:(u=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._bufferService){e.next=3;break}return e.next=3,this._bufferService.detachMedia();case 3:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"destroy",value:(o=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.media){e.next=2;break}return e.abrupt("return");case 2:return this.removeAllListeners(),this._playlist.reset(),this._segmentLoader.reset(),null===(t=this._seiService)||void 0===t||t.reset(),this.media.removeEventListener("loadeddata",this._onLoadeddata),this.media.removeEventListener("play",this._onPlay),this.media.removeEventListener("pause",this._onPause),this.media.removeEventListener("seeking",this._onSeeking),this.media.removeEventListener("timeupdate",this._onTimeupdate),e.next=13,Promise.all([this._clear(),this._bufferService.destroy()]);case 13:this.media=null;case 14:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"_loadM3U8",value:(s=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,s,o,u;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,!(a=null===(n=this.config.manifestList)||void 0===n||null===(i=n.filter((function(e){return e.url===t}))[0])||void 0===i?void 0:i.manifest)){e.next=6;break}e.t0=this._manifestLoader.parseText(a,t),e.next=9;break;case 6:return e.next=8,this._manifestLoader.load(t);case 8:e.t0=e.sent;case 9:s=e.t0,o=_slicedToArray$1(s,1),r=o[0],e.next=17;break;case 14:throw e.prev=14,e.t1=e.catch(0),this._emitError(StreamingError.create(e.t1));case 17:if(r){e.next=19;break}return e.abrupt("return");case 19:if(this._playlist.upsertPlaylist(r),!r.isMaster){e.next=24;break}return null!==(u=this._playlist.currentStream.subtitleStreams)&&void 0!==u&&u.length&&this.emit(Event$1.SUBTITLE_PLAYLIST,{list:this._playlist.currentStream.subtitleStreams}),e.next=24,this._refreshM3U8();case 24:return this.emit(Event$1.STREAM_PARSED),e.abrupt("return",r);case 26:case"end":return e.stop()}}),e,this,[[0,14]])}))),function(e){return s.apply(this,arguments)})},{key:"_refreshM3U8",value:function(){var e,t,r=this,n=this._playlist.currentStream;if(!n||!n.url)throw this._emitError(StreamingError.create(null,null,new Error("m3u8 url is not defined")));var i=n.url,a=null===(e=n.currentAudioStream)||void 0===e?void 0:e.url,s=null===(t=n.currentSubtitleStream)||void 0===t?void 0:t.url;return this._manifestLoader.load(i,a,s).then((function(e){var t=_slicedToArray$1(e,3),n=t[0],o=t[1],u=t[2];n&&(r._playlist.upsertPlaylist(n,o,u),r.isLive&&r._pollM3U8(i,a,s))})).catch((function(e){throw r._emitError(StreamingError.create(e))}))}},{key:"_pollM3U8",value:function(e,t,r){var n,i,a=this,s=this._playlist.isEmpty;this._playlist.lowLatency?n=1e3*(this._playlist.currentStream.partTargetDuration||0):n=1e3*((null===(i=this._playlist.lastSegment)||void 0===i?void 0:i.duration)||0);this._manifestLoader.poll(e,t,r,(function(e,t,r){a._playlist.upsertPlaylist(e,t,r),a._playlist.clearOldSegment(),(e&&s&&!a._playlist.isEmpty||!a._playlist.hadSegmentLoaded&&a._playlist.nbSegments>=a.config.minSegmentsStartPlay)&&a._loadSegment(),s&&(s=a._playlist.isEmpty)}),(function(e){a._emitError(StreamingError.create(e))}),n)}},{key:"_loadSegmentDirect",value:(a=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,s,o;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this._playlist.nextSegment){e.next=3;break}return e.abrupt("return");case 3:return n=!1,i=null,e.prev=5,this._segmentProcessing=!0,logger.log("load segment, sn:".concat(r.sn,", [").concat(r.start,", ").concat(r.end,"], partIndex:").concat(r.partIndex)),e.next=10,this._reqAndBufferSegment(r,this._playlist.getAudioSegment(r));case 10:n=e.sent,e.next=16;break;case 13:e.prev=13,e.t0=e.catch(5),i=e.t0;case 16:return e.prev=16,this._segmentProcessing=!1,e.finish(16);case 19:if(!i){e.next=26;break}if(!this._bufferService.isFull()){e.next=25;break}return logger.log("load segment, sn:".concat(r.sn,", partIndex:").concat(r.partIndex)),this._segmentProcessing=!0,this._isProcessQuotaExceeded=!0,e.abrupt("return",!1);case 25:return e.abrupt("return",this._emitError(StreamingError.create(i)));case 26:return n&&(s=this.bufferInfo().end,this.isLive&&!this.media.seeking&&s&&Math.abs(r.end-s)>1&&(logger.warn("segment: ".concat(r.sn," expected end=").concat(r.end,", real end=").concat(s)),this._playlist.feedbackLiveEdge(r,s)),o=(null===(a=this._playlist.currentStream)||void 0===a?void 0:a.url)===r.parentUrl,this._urlSwitching&&!o&&(logger.warn("pre playlist segment appended!"),this._bufferService.seamlessSwitch()),this.isLive&&this._urlSwitching&&o&&(this._urlSwitching=!1,this.emit(Event$1.SWITCH_URL_SUCCESS,{url:this.config.url})),this._playlist.moveSegmentPointer(),r.isLast?this._end():t||this._loadSegment()),e.abrupt("return",n);case 28:case"end":return e.stop()}}),e,this,[[5,13,16,19]])}))),function(e){return a.apply(this,arguments)})},{key:"_reqAndBufferSegment",value:(i=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r){var n,i,a,s,o,u,c,l,d,f,h;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=t?t.cc:r.cc,a=this._prevSegCc!==i,s=[],e.prev=3,e.next=6,this._segmentLoader.load(t,r,a);case 6:s=e.sent,e.next=14;break;case 9:throw e.prev=9,e.t0=e.catch(3),e.t0.fatal=!1,this._segmentLoader.error=e.t0,e.t0;case 14:if(s[0]){e.next=16;break}return e.abrupt("return");case 16:return e.next=18,(n=this._bufferService).decryptBuffer.apply(n,_toConsumableArray$2(s));case 18:if(o=e.sent){e.next=21;break}return e.abrupt("return");case 21:return u=t?t.sn:r.sn,c=t?t.start:r.start,l=this._playlist.currentStream,this._bufferService.createSource(o[0],o[1],null==l?void 0:l.videoCodec,null==l?void 0:l.audioCodec),d=Date.now(),f=this._prevSegSn===u-1,this.isLive&&this._urlSwitching&&(h=this.bufferInfo().end,this._playlist.updateSegmentsRanges(u,h),logger.warn("update the new playlist liveEdge, segment id=".concat(u,", buffer start=").concat(h,", liveEdge=").concat(this._playlist.liveEdge)),c=h),e.next=30,this._bufferService.appendBuffer(t,r,o[0],o[1],a,f,c);case 30:return this.emit(Event$1.APPEND_COST,{elapsed:Date.now()-d,url:t.url}),e.next=33,this._bufferService.evictBuffer(this.config.bufferBehind);case 33:return this._prevSegCc=i,this._prevSegSn=u,e.abrupt("return",!0);case 36:case"end":return e.stop()}}),e,this,[[3,9]])}))),function(e,t){return i.apply(this,arguments)})},{key:"_onCheckQuotaExceeded",value:(n=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,r,n,i,a,s;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=this.media.currentTime,r=this.media.buffered,n=!1,i=0;case 4:if(!(i<r.length)){e.next=11;break}if(!(r.start(0)>=t&&t<r.end(i))){e.next=8;break}return n=!0,e.abrupt("break",11);case 8:i++,e.next=4;break;case 11:if(!this._bufferService.isFull()){e.next=17;break}if(a=n?this.config.bufferBehind:5,!((s=this.media.currentTime)-a>0)){e.next=17;break}return e.next=17,this._bufferService.removeBuffer(0,s-a);case 17:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"_checkStreamTrackChange",value:function(e){var t=this._playlist.checkSegmentTrackChange(e,this._bufferService.nbSb);t&&this.switchURL(this.config.url,t.start+.2)}},{key:"_clear",value:(r=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return clearTimeout(this._disconnectTimer),this._stopTick(),e.next=4,Promise.all([this._segmentLoader.cancel(),this._manifestLoader.stopPoll()]);case 4:this._segmentProcessing=!1;case 5:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"_reset",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,r,n=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>0&&void 0!==n[0]&&n[0],this._reloadOnPlay=!1,this._prevSegSn=null,this._prevSegCc=null,this._switchUrlOpts=null,this._playlist.reset(),this._segmentLoader.reset(),null===(t=this._seiService)||void 0===t||t.reset(),this._stats.reset(),e.next=11,this._clear();case 11:return e.abrupt("return",this._bufferService.reset(r));case 12:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"_end",value:function(){this._clear(),this._bufferService.endOfStream(),(this.media.readyState<=2||this.media.buffered.length>1)&&this._startTick()}},{key:"_stopTick",value:function(){this._tickTimer&&clearTimeout(this._tickTimer),this._tickTimer=null}},{key:"_startTick",value:function(){this._stopTick(),this._tickTimer=setTimeout(this._tick,this._tickInterval)}},{key:"_emitError",value:function(e){var t,r,n,i,a=arguments.length>1&&void 0!==arguments[1]&&arguments[1];!1===(null===(t=e.originError)||void 0===t?void 0:t.fatal)?logger.warn(e):(logger.table(e),logger.error(e),logger.error(null===(r=this.media)||void 0===r?void 0:r.error),null!==(n=this.media)&&void 0!==n&&n.readyState&&this.media.pause(),this._stopTick(),this._urlSwitching&&(this._urlSwitching=!1,this.emit(Event$1.SWITCH_URL_FAILED,e)),this.emit(Event$1.ERROR,e),a&&this._end(),null===(i=this._seiService)||void 0===i||i.reset());return e}},{key:"_getSeamlessSwitchPoint",value:function(){var e=this.media,t=e.currentTime;if(!e.paused){var r,n=this._playlist.findSegmentIndexByTime(e.currentTime),i=this._playlist.getSegmentByIndex(n),a=null===(r=this._stats)||void 0===r?void 0:r.getStats().downloadSpeed;if(a&&i)t+=i.duration*this._playlist.currentStream.bitrate/a+1;else t+=5}return t}},{key:"_tryEos",value:function(){var e,t,r=this.media,n=this._playlist,i=n.nextSegment,a=n.lastSegment;if((!i||a&&Buffer$1.isBuffered(r,a.start+a.duration/2))&&r.readyState&&r.duration>0&&(null===(e=this._bufferService)||void 0===e?void 0:e.msIsOpened)&&!(null!==(t=this._bufferService)&&void 0!==t&&t.msHasOpTasks)){var s=this.bufferInfo();r.paused&&!r.currentTime&&(s=this.bufferInfo(s.nextStart||.5)),(Math.abs(s.end-r.duration)<.1||!this.isLive&&a&&s.end>=a.start+a.duration)&&this._bufferService.endOfStream()}}}],[{key:"isSupported",value:function(e){return e&&"video"!==e&&"audio"!==e?"undefined"!=typeof WebAssembly:MSE.isSupported()}},{key:"enableLogger",value:function(){Logger$2.enable(),Logger$1.enable()}},{key:"disableLogger",value:function(){Logger$2.disable(),Logger$1.disable()}}]),v}();_defineProperty$3(Hls,"version","3.0.24-rc.18");try{localStorage.getItem("xgd")?Hls.enableLogger():Hls.disableLogger()}catch(e){}var PluginExtension=function(){function e(t,r){var n=this;_classCallCheck$3(this,e),_defineProperty$3(this,"_opts",null),_defineProperty$3(this,"_plugin",null),_defineProperty$3(this,"_onLowDecode",(function(){var e,t,r,i,a=n._opts,s=a.media,o=a.innerDegrade;null===(e=n._plugin)||void 0===e||null===(t=e.player)||void 0===t||t.emit("lowdecode",s.degradeInfo),null===(r=n._plugin)||void 0===r||null===(i=r.player)||void 0===i||i.emit("core_event",_objectSpread2$2(_objectSpread2$2({},s.degradeInfo),{},{eventName:Event$1.LOWDECODE})),1===o&&n._degrade(s.src)})),_defineProperty$3(this,"_degrade",(function(e){var t=n._plugin.player,r=t.video;if(!r||"MVideo"===r.TAG){var i=t.video.degradeVideo;t.video=i,r.degrade(e),e&&(t.config.url=e);var a=t.root.firstChild;"MVideo"===a.TAG&&t.root.replaceChild(i,a);var s=n._plugin.constructor.pluginName.toLowerCase();t.unRegisterPlugin(s),t.once("canplay",(function(){t.play()}))}})),_defineProperty$3(this,"forceDegradeToVideo",(function(e){1===n._opts.innerDegrade&&n._degrade(e)})),this._opts=t,this._plugin=r,this._init()}return _createClass$3(e,[{key:"_init",value:function(){var e=this._opts,t=e.media,r=e.preloadTime,n=e.innerDegrade,i=e.isLive;t&&(i||!t.setPlayMode?(n&&t.setAttribute("innerdegrade",n),r&&t.setAttribute("preloadtime",r),this._bindEvents()):t.setPlayMode("VOD"))}},{key:"_bindEvents",value:function(){this._opts.media.addEventListener("lowdecode",this._onLowDecode)}},{key:"destroy",value:function(){var e,t;null===(e=this._opts)||void 0===e||null===(t=e.media)||void 0===t||t.removeEventListener("lowdecode",this._onLowDecode),this._plugin=null}}]),e}(),_excluded=["currentTime"];function parseSwitchUrlArgs(e,t){var r={startTime:t.player.currentTime};switch(_typeof$2(e)){case"boolean":r.seamless=e;break;case"object":var n=e.currentTime,i=_objectWithoutProperties$1(e,_excluded);Object.assign(r,i),"number"==typeof n&&(r.startTime=n)}return r}var HlsPlugin=function(e){_inherits$2(r,BasePlugin);var t=_createSuper$2(r);function r(){var e;_classCallCheck$3(this,r);for(var n=arguments.length,i=new Array(n),a=0;a<n;a++)i[a]=arguments[a];return _defineProperty$3(_assertThisInitialized$2(e=t.call.apply(t,[this].concat(i))),"logger",logger),_defineProperty$3(_assertThisInitialized$2(e),"hls",null),_defineProperty$3(_assertThisInitialized$2(e),"pluginExtension",null),_defineProperty$3(_assertThisInitialized$2(e),"getStats",(function(){var t;return null===(t=e.hls)||void 0===t?void 0:t.getStats()})),_defineProperty$3(_assertThisInitialized$2(e),"_onSwitchSubtitle",(function(t){var r,n=t.lang;null===(r=e.hls)||void 0===r||r.switchSubtitleStream(n)})),_defineProperty$3(_assertThisInitialized$2(e),"_keepPauseStatus",(function(){e.player.paused&&e.player.once("canplay",(function(){e.player.pause()}))})),e}return _createClass$3(r,[{key:"core",get:function(){return this.hls}},{key:"version",get:function(){var e;return null===(e=this.hls)||void 0===e?void 0:e.version}},{key:"softDecode",get:function(){var e,t,r=null===(e=this.player)||void 0===e||null===(t=e.config)||void 0===t?void 0:t.mediaType;return!!r&&"video"!==r&&"audio"!==r&&"offscreen-video"!==r}},{key:"beforePlayerInit",value:function(){var e=this,t=this.player.config,r=this.player.media||this.player.video,n=t.hls||{};if((t.url||t.__allowHlsEmptyUrl__)&&(this.softDecode||n.preferMMS||!MSE.isMMSOnly())){this.hls&&this.hls.destroy();var i=Object.getOwnPropertyDescriptor(this.player,"switchURL");i&&!i.writable||(this.player.switchURL=function(t,r){return new Promise((function(n,i){var a=e.player,s=e.hls;if(s){var o,u,c=parseSwitchUrlArgs(r,e);a.config.url=t,s.switchURL(t,c).then((function(){return n(!0)})).catch(i),!c.seamless&&null!==(o=e.player.config)&&void 0!==o&&null!==(u=o.hls)&&void 0!==u&&u.keepStatusAfterSwitch&&e._keepPauseStatus()}else i()}))});var a,s=this.player.switchURL;if(this.player.handleSource=!1,n.innerDegrade=n.innerDegrade||t.innerDegrade,null!==n.disconnectTime&&void 0!==n.disconnectTime||(n.disconnectTime=0),this.hls=new Hls(_objectSpread2$2({softDecode:this.softDecode,isLive:t.isLive,media:r,startTime:t.startTime,url:t.url},n)),this.softDecode||BasePlugin.defineGetterOrSetter(this.player,{url:{get:function(){var t,r;return null===(t=e.hls)||void 0===t||null===(r=t.media)||void 0===r?void 0:r.src},configurable:!0}}),this.softDecode&&(this.pluginExtension=new PluginExtension(_objectSpread2$2({isLive:t.isLive,media:r},n),this),this.player.forceDegradeToVideo=function(){for(var t,r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];return null===(t=e.pluginExtension)||void 0===t?void 0:t.forceDegradeToVideo.apply(t,n)}),t.isLive)null===(a=this.player)||void 0===a||a.useHooks("replay",(function(){var t;return null===(t=e.hls)||void 0===t?void 0:t.replay()}));this.on(URL_CHANGE,s),this.on(SWITCH_SUBTITLE,this._onSwitchSubtitle),this.on(DESTROY,this.destroy.bind(this)),this._transError(),this._transCoreEvent(EVENT.TTFB),this._transCoreEvent(EVENT.LOAD_START),this._transCoreEvent(EVENT.LOAD_RESPONSE_HEADERS),this._transCoreEvent(EVENT.LOAD_COMPLETE),this._transCoreEvent(EVENT.LOAD_RETRY),this._transCoreEvent(EVENT.SOURCEBUFFER_CREATED),this._transCoreEvent(EVENT.MEDIASOURCE_OPENED),this._transCoreEvent(EVENT.APPEND_BUFFER),this._transCoreEvent(EVENT.REMOVE_BUFFER),this._transCoreEvent(EVENT.BUFFEREOS),this._transCoreEvent(EVENT.KEYFRAME),this._transCoreEvent(EVENT.METADATA_PARSED),this._transCoreEvent(EVENT.DEMUXED_TRACK),this._transCoreEvent(EVENT.SEI),this._transCoreEvent(EVENT.SEI_IN_TIME),this._transCoreEvent(EVENT.SPEED),this._transCoreEvent(EVENT.HLS_MANIFEST_LOADED),this._transCoreEvent(EVENT.HLS_LEVEL_LOADED),this._transCoreEvent(EVENT.STREAM_EXCEPTION),this._transCoreEvent(EVENT.SWITCH_URL_SUCCESS),this._transCoreEvent(EVENT.SWITCH_URL_FAILED),this._transCoreEvent(Event$1.NO_AUDIO_TRACK),this._transCoreEvent(Event$1.STREAM_PARSED),this._transCoreEvent(Event$1.SUBTITLE_SEGMENTS),this._transCoreEvent(Event$1.SUBTITLE_PLAYLIST),this._transCoreEvent(Event$1.APPEND_COST),t.url&&this.hls.load(t.url,{reuseMse:!0}).catch((function(e){}))}}},{key:"destroy",value:function(){var e;this.hls&&(this.hls.destroy(),this.hls=null),null===(e=this.pluginExtension)||void 0===e||e.destroy(),this.pluginExtension=null}},{key:"_transError",value:function(){var e=this;this.hls.on(Event$1.ERROR,(function(t){e.player&&e.player.emit(ERROR,new Errors(e.player,t))}))}},{key:"_transCoreEvent",value:function(e){var t=this;this.hls.on(e,(function(r){t.player&&(t.player.emit("core_event",_objectSpread2$2(_objectSpread2$2({},r),{},{eventName:e})),e===EVENT.SEI_IN_TIME&&t.hls.hasSubtitle&&t._emitSeiPaylodTime(r))}))}},{key:"_emitSeiPaylodTime",value:function(e){try{var t=JSON.parse(Array.from(e.data.payload).map((function(e){return String.fromCharCode(e)})).join("").slice(0,-1));if(!t.rtmp_dts)return;this.player.emit("core_event",{eventName:Event$1.SEI_PAYLOAD_TIME,time:t.rtmp_dts})}catch(e){}}}],[{key:"pluginName",get:function(){return"hls"}},{key:"isSupported",value:function(e,t){return Hls.isSupported(e,t)}}]),r}();_defineProperty$3(HlsPlugin,"Hls",Hls),_defineProperty$3(HlsPlugin,"EVENT",Event$1);export{HlsPlugin as default};
|