@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/flv.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 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",o=i.asyncIterator||"@@asyncIterator",s=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,o=Object.create(a.prototype),s=new P(i||[]);return n(o,"_invoke",{value:b(e,r,s)}),o}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 g=p.prototype=f.prototype=Object.create(_);function m(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,o,s){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,o,s)}),(function(e){i("throw",e,o,s)})):t.resolve(d).then((function(e){c.value=e,o(c)}),(function(e){return i("throw",e,o,s)}))}s(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 o=r.delegate;if(o){var s=T(o,r);if(s){if(s===d)continue;return s}}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 T(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,T(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 S(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(S,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:w}}function w(){return{value:void 0,done:!0}}return h.prototype=p,n(g,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:h,configurable:!0}),h.displayName=u(p,s,"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,s,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(E.prototype),u(E.prototype,o,(function(){return this})),e.AsyncIterator=E,e.async=function(t,r,n,i,a){void 0===a&&(a=Promise);var o=new E(c(t,r,n,i),a);return e.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},m(g),u(g,s,"Generator"),u(g,a,(function(){return this})),u(g,"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 o.type="throw",o.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],o=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){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 o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(o)},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,o){try{var s=e[a](o),u=s.value}catch(e){return void r(e)}s.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 o(e){asyncGeneratorStep$1(a,n,i,o,s,"next",e)}function s(e){asyncGeneratorStep$1(a,n,i,o,s,"throw",e)}o(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 _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 _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,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new i(n,a||e,o),u=r?r+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],s]:e._events[u].push(s):(e._events[u]=s,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function s(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),s.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},s.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,o=new Array(a);i<a;i++)o[i]=n[i].fn;return o},s.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},s.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var u,c,l=this._events[s],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,o),!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},s.prototype.on=function(e,t,r){return a(this,e,t,r,!1)},s.prototype.once=function(e,t,r){return a(this,e,t,r,!0)},s.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return o(this,a),this;var s=this._events[a];if(s.fn)s.fn!==t||i&&!s.once||n&&s.context!==n||o(this,a);else{for(var u=0,c=[],l=s.length;u<l;u++)(s[u].fn!==t||i&&!s[u].once||n&&s[u].context!==n)&&c.push(s[u]);c.length?this._events[a]=1===c.length?c[0]:c:o(this,a)}return this},s.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&o(this,t)):(this._events=new n,this._eventsCount=0),this},s.prototype.off=s.prototype.removeListener,s.prototype.addListener=s.prototype.on,s.prefixed=r,s.EventEmitter=s,e.exports=s}(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),o=[],s=String(e);a--;)o.push(n);return o.join("").substring(0,i-s.length)+s},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,o,s=util.createDom("xg-".concat(e),"",{},"xgplayer-".concat(e,"-img"));(s.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()),o=e,!1)})),s.style.width="".concat(i).concat(o),s.style.height="".concat(a).concat(o),s.style.backgroundSize="".concat(i).concat(o," ").concat(a).concat(o),s.style.margin="start"===e?"-".concat(a/2).concat(o," auto auto -").concat(i/2).concat(o):"auto 5px auto 5px");return s},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 o=i.length;if(o){var s=i[o-1].end;r[a].start-s<t?r[a].end>s&&(i[o-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],o=a.start,s=a.end,u=a.cTime,c=a.offset;return e<o?u:e>=o&&e<=s?e-c:e>s&&n>=i-1?s:-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,o=t.currentTime,s=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:o,duration:a,ended:s,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";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 o=t.call.apply(t,[e].concat(i));r&&"function"==typeof r&&(o&&o.then?o.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 o=runHooks.apply(void 0,[this,e,t].concat(Array.prototype.slice.call(arguments)));o?o.then?o.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===o&&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 o=e.__hooks[t],s=-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(s++,0===o.length||s===o.length)return n.call.apply(n,[t,t].concat(a));var c=o[s],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",o=i.asyncIterator||"@@asyncIterator",s=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,o=Object.create(a.prototype),s=new P(i||[]);return n(o,"_invoke",{value:b(e,r,s)}),o}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 g=p.prototype=f.prototype=Object.create(_);function m(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,o,s){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,o,s)}),(function(e){i("throw",e,o,s)})):t.resolve(d).then((function(e){c.value=e,o(c)}),(function(e){return i("throw",e,o,s)}))}s(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 o=r.delegate;if(o){var s=T(o,r);if(s){if(s===d)continue;return s}}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 T(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,T(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 S(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(S,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:w}}function w(){return{value:void 0,done:!0}}return h.prototype=p,n(g,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:h,configurable:!0}),h.displayName=u(p,s,"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,s,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(E.prototype),u(E.prototype,o,(function(){return this})),e.AsyncIterator=E,e.async=function(t,r,n,i,a){void 0===a&&(a=Promise);var o=new E(c(t,r,n,i),a);return e.isGeneratorFunction(r)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},m(g),u(g,s,"Generator"),u(g,a,(function(){return this})),u(g,"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 o.type="throw",o.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],o=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),u=r.call(a,"finallyLoc");if(s&&u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){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 o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(o)},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,o){try{var s=e[a](o),u=s.value}catch(e){return void r(e)}s.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 o(e){asyncGeneratorStep(a,n,i,o,s,"next",e)}function s(e){asyncGeneratorStep(a,n,i,o,s,"throw",e)}o(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(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,o=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==r.return||r.return()}finally{if(s)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 o=r[a-1],s=o[1];if(e.start(n)-s<=t){var u=e.end(n);u>s&&(o[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,o=0,s=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],o=f;else{if(r+n<p[0]){s=p[0],u=p[1];break}r+n>p[1]&&(c=p[0],l=p[1])}}return{start:i,end:a,index:o,buffers:d,nextStart:s,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,o){var s;return _classCallCheck$1(this,r),(s=t.call(this,o||(null==i?void 0:i.message))).errorType=e===ERR.NETWORK_TIMEOUT?ERR.NETWORK:e,s.originError=i,s.ext=a,s.errorCode=ERR_CODE[e][n]||ERR_CODE[e],s.errorMessage=s.message,s.errorCode||(s.errorType=ERR.OTHER,s.errorCode=ERR_CODE[s.errorType]),s}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 o=this.logTextArray.shift();this.logSize-=o.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,o=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)),o,r.context),r.promise.resolve({name:r.opName,context:r.context,costtime:o});var s=null===(a=r.context)||void 0===a?void 0:a.callback;s&&"function"==typeof s&&s(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,o=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()-o._st;o._logger.debug("sourceopen"),n.removeEventListener("sourceopen",e),URL.revokeObjectURL(t.src),o._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 o=this._queue[e]=this._queue[e]||[],s={exec:t,promise:createPublicPromise(),opName:r,context:n};return i?(o.splice(0,0,s),this._mseFullFlag[e]=!1,this._startQueue(e)):o.push(s),this.isOpened||this.isEnded?1===o.length&&this._startQueue(e):this._openPromise.then((function(){1===o.length&&a._startQueue(e)})),s.promise}},{key:"_enqueueBlockingOp",value:(t=_asyncToGenerator(_regeneratorRuntime().mark((function e(t,r,n){var i,a,o=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=o._queue[e],i=createPublicPromise();a.push(i),t.push({exec:function(){i.resolve()},promise:i,opName:r,context:n}),1===t.length&&o._startQueue(e)})),e.abrupt("return",Promise.all(a).then((function(){try{return t()}finally{i.forEach((function(e){var t=o._queue[e],r=o._sourceBuffer[e];null==t||t.shift(),r&&r.updating||o._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 o;return _classCallCheck$1(this,r),_defineProperty$1(_assertThisInitialized$1(o=t.call(this,a)),"retryCount",0),_defineProperty$1(_assertThisInitialized$1(o),"isTimeout",!1),_defineProperty$1(_assertThisInitialized$1(o),"loaderType",LoaderType.FETCH),_defineProperty$1(_assertThisInitialized$1(o),"startTime",0),_defineProperty$1(_assertThisInitialized$1(o),"endTime",0),_defineProperty$1(_assertThisInitialized$1(o),"options",{}),o.url=e,o.request=n,o.response=i,o}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,o,s,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:s,contentLength:n,age:i,startTime:a,firstByteTime:o,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,o=e.responseType,s=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,g=e.body,m=e.mode,E=e.credentials,b=e.cache,T=e.redirect,S=e.referrer,k=e.referrerPolicy,P=e.onProcessMinLen,A=e.priOptions,w=e.streamRes,C=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=C;var x={method:y,headers:v,body:g,mode:m,credentials:E,cache:b,redirect:T,referrer:S,referrerPolicy:k,signal:null===(t=this._abortController)||void 0===t?void 0:t.signal},R=!1;clearTimeout(this._timeoutTimer),n=setUrlParams(n,p);var O=getRangeValue(d);O&&(v=h?h.headers:x.headers=x.headers||(Headers?new Headers:{}),Headers&&v instanceof Headers?v.append("Range",O):v.Range=O),a&&(this._timeoutTimer=setTimeout((function(){if(R=!0,r.cancel(),c){var e=new NetError(n,x,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){(w?new Promise((function(e){e(w)})):fetch(h||n,h?void 0:x)).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,x,a,"bad network response");case 7:if(c=Date.now(),o!==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(o!==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(!s){i.next=29;break}return r.resolve=e,r.reject=t,r._loadChunk(a,s,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,x,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 o,s,u,c=this._reader=e.body.getReader(),l=function(){var a=_asyncToGenerator(_regeneratorRuntime().mark((function a(){var d,f,h,p,_,y,v,g,m,E;return _regeneratorRuntime().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return s=Date.now(),a.prev=1,a.next=4,c.read();case 4:o=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:s,endTime:u,st:r,firstByteTime:n,priOptions:i._priOptions},e),a.abrupt("return");case 19:p=o.value?o.value.byteLength:0,i._receivedLength+=p,i._logger.debug("【fetchLoader,onProgress call】,task,",i._range,", start,",h,", end,",f+i._receivedLength,", done,",o.done),i._onProcessMinLen>0?i._writeIdx+p>=i._onProcessMinLen||o.done?((_=new Uint8Array(i._writeIdx+p)).set(i._cache.slice(0,i._writeIdx),0),p>0&&_.set(o.value,i._writeIdx),i._writeIdx=0,i._logger.debug("【fetchLoader,onProgress enough】,done,",o.done,",len,",_.byteLength,", writeIdx,",i._writeIdx)):p>0&&i._writeIdx+p<CACHESIZE?(i._cache.set(o.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(o.value,i._writeIdx),i._writeIdx+=p,delete i._cache,i._cache=y,i._logger.debug("【fetchLoader,onProgress extra end】,len,",p,", writeIdx,",i._writeIdx)):_=o.value,(_&&_.byteLength>0||o.done)&&(i._firstMaxChunkSize&&(i._firtstByte?i._cacheData&&((g=new Uint8Array(i._cacheData.byteLength+_.byteLength)).set(i._cacheData,0),g.set(_,i._cacheData.byteLength),_=g,i._cacheData=null):(i._firtstByte++,v=_.slice(0,i._firstMaxChunkSize),i._cacheData=_.slice(i._firstMaxChunkSize),_=v)),t(_,o.done,{range:[i._range[0]+i._receivedLength-(_?_.byteLength:0),i._range[0]+i._receivedLength],vid:i._vid,index:i._index,startTime:s,endTime:u,st:r,firstByteTime:n,priOptions:i._priOptions},e)),o.done?(m=Date.now()-r,E=calculateSpeed(i._receivedLength,m),i.emit(EVENT.REAL_TIME_SPEED,{speed:E,len:i._receivedLength,time:m,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,",o.done),i.resolve(createResponse(o,!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(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,o=!1,s=(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=s+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,s+this._receivedLength],priOptions:this._priOptions})}a=c,o=!((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 ",s+this._receivedLength,",dataLen,",c?c.byteLength:0,",receivedLength",this._receivedLength,",index,",this._index,", done,",o)}else o=!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,o,{index:this._index,vid:this._vid,range:[i,s+this._receivedLength],startTime:this._startTime,endTime:Date.now(),priOptions:this._priOptions},f),o?(this._runing=!1,this._loadCompleteResolve&&this._loadCompleteResolve(createResponse(this._onProgress?null:a,o,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(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=["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,o=_objectWithoutProperties(t,_excluded),s=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(o);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:o.index,vid:o.vid,range:o.range,priOptions:o.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,",o.range),e._retryTimer=setTimeout(s,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 s(),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(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 o=Buffer$1.info(Buffer$1.get(e),i);if(!o.buffers.length)return;r&&o.nextStart||o.nextStart&&o.nextStart-i<t?a=o.nextStart+.1:o.end&&o.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,o,s,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===(o=a.speedInfo)||void 0===o?void 0:o.call(a).totalSize)||0,totalReceivedCost:(null===(s=this._core)||void 0===s||null===(u=s.speedInfo)||void 0===u?void 0:u.call(s).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,o,s=[],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)&&(s.push(n.value),s.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(c)throw i}}return s}}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 _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,"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})),FlvScriptSample=function(e){_inherits(r,Sample);var t=_createSuper(r);function r(){return _classCallCheck(this,r),t.apply(this,arguments)}return _createClass(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,o=[],s=(60&t[i+2])>>>2,u=e.FREQ[s];if(!u)throw new Error("Invalid sampling index: ".concat(s));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(s,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]),o.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:o,samplingFrequencyIndex:s,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 o=e._getConfig(n,i,r);return{samplingFrequencyIndex:n,sampleRate:a,objectType:r,channelCount:i,config:o.config,codec:o.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}();_defineProperty(AAC,"FREQ",[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]);var OPUS=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"getFrameDuration",value:function(e){return 20}},{key:"parseHeaderPackets",value:function(e){if(e.length){for(var t=new DataView(e.buffer,e.byteOffset,e.byteLength),r="",n=0;n<8;n++)r+=String.fromCodePoint(e[n]);if("OpusHead"!==r)throw new Error("Invalid Opus MagicSignature");var i=e[9];console.log("Pre-skip",e[10],e[11]);var a=t.getUint32(12,!0),o=t.getInt16(16,!0);if(a){return{outputGain:o,sampleRate:a,channelCount:i,config:new Uint8Array(e.buffer,e.byteOffset+8,e.byteLength-8),codec:"opus",originCodec:"opus"}}}}}]),e}(),LARGE_AV_FIRST_FRAME_GAP=500,AUDIO_GAP_OVERLAP_THRESHOLD_COUNT=3,MAX_SILENT_FRAME_DURATION=1e3,AUDIO_EXCEPTION_LOG_EMIT_DURATION=5e3,MAX_VIDEO_FRAME_DURATION=1e3,MAX_DTS_DELTA_WITH_NEXT_CHUNK=200,VIDEO_EXCEPTION_LOG_EMIT_DURATION=5e3,TRACK_BROKEN_CHECK_TIME=5,FlvFixer=function(){function e(t,r,n){_classCallCheck(this,e),this.videoTrack=t,this.audioTrack=r,this.metadataTrack=n,this._baseDts=-1,this._baseDtsInited=!1,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=0,this._videoTimestampBreak=0,this._lastVideoDuration=0,this._keyFrameInNextChunk=!1,this._lastAudioExceptionGapDot=-1/0,this._lastAudioExceptionOverlapDot=-1/0,this._lastAudioExceptionLargeGapDot=-1/0,this._lastVideoExceptionLargeGapDot=-1/0,this._lastVideoExceptionChunkFirstDtsDot=-1/0}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(1e3*t);var i=this.videoTrack,a=this.audioTrack;if(!r&&n||(this._videoLastSample=null,this._audioNextPts=void 0,this._videoNextDts=void 0,this._audioTimestampBreak=0,this._videoTimestampBreak=0,this._lastAudioExceptionGapDot=-1/0,this._lastAudioExceptionOverlapDot=-1/0,this._lastAudioExceptionLargeGapDot=-1/0,this._lastVideoExceptionLargeGapDot=-1/0,this._lastVideoExceptionChunkFirstDtsDot=-1/0),r&&!n&&(this._baseDtsInited=!1),this._baseDtsInited||this._calculateBaseDts(a,i),!n&&t&&(this._audioNextPts=this._videoNextDts=t),this._baseDtsInited&&(this._videoTimestampBreak||!this.videoTrack.exist())&&(this._audioTimestampBreak||!this.audioTrack.exist())&&this._resetBaseDtsWhenStreamBreaked(),this._fixAudio(a),this._keyFrameInNextChunk=!1,this._fixVideo(i),this.metadataTrack.exist()){var o=this.metadataTrack.timescale;this.metadataTrack.seiSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/o})),this.metadataTrack.flvScriptSamples.forEach((function(t){t.pts=t.originPts-e._baseDts,t.time=Math.max(0,t.pts)/o}))}i.samples.length&&(i.baseMediaDecodeTime=i.samples[0].dts),a.samples.length&&(a.baseMediaDecodeTime=a.samples[0].pts*a.timescale/1e3)}},{key:"_fixVideo",value:function(e){var t=this,r=e.samples;if(r.length){var n;if(r.forEach((function(e){e.dts-=t._baseDts,e.pts-=t._baseDts,e.keyframe&&(t._keyFrameInNextChunk=!0)})),e.fpsNum&&e.fpsDen)n=e.timescale*(e.fpsDen/e.fpsNum);else if(e.length>1){var i=e.samples[0],a=e.samples[r.length-1];n=Math.floor((a.dts-i.dts)/(r.length-1))}else n=this._lastVideoDuration||40;var o=r.pop();if(this._videoLastSample&&r.unshift(this._videoLastSample),this._videoLastSample=o,r.length){if(void 0===this._videoNextDts){var s=r[0];this._videoNextDts=s.dts}var u=r.length,c=0,l=r[0],d=this._videoNextDts-l.dts;if(Math.abs(d)>MAX_DTS_DELTA_WITH_NEXT_CHUNK){var f;if(Math.abs(l.dts-this._lastVideoExceptionChunkFirstDtsDot)>VIDEO_EXCEPTION_LOG_EMIT_DURATION)this._lastVideoExceptionChunkFirstDtsDot=l.dts,e.warnings.push({type:WarningType.LARGE_VIDEO_GAP_BETWEEN_CHUNK,nextDts:this._videoNextDts,firstSampleDts:l.dts,nextSampleDts:null===(f=r[1])||void 0===f?void 0:f.dts,sampleDuration:d});this._videoTimestampBreak>=TRACK_BROKEN_CHECK_TIME?(this._videoNextDts=l.dts,this._videoTimestampBreak=0):(l.dts+=d,l.pts+=d,this.audioTrack.exist()||(this._videoTimestampBreak=1))}for(var h=0;h<u;h++){var p=r[h].dts,_=r[h+1];((c=h<u-1?_.dts-p:o?o.dts-p:n)>MAX_VIDEO_FRAME_DURATION||c<0)&&(this._videoTimestampBreak++,Math.abs(p-this._lastVideoExceptionLargeGapDot)>VIDEO_EXCEPTION_LOG_EMIT_DURATION&&(this._lastVideoExceptionLargeGapDot=p,e.warnings.push({type:WarningType.LARGE_VIDEO_GAP,time:p/e.timescale,dts:p,originDts:r[h].originDts,nextDts:this._videoNextDts,sampleDuration:c,refSampleDuration:n})),c=n),r[h].duration=c,this._videoNextDts+=c,this._lastVideoDuration=c}}}}},{key:"_fixAudio",value:function(e){var t=this,r=e.samples;r.length&&(r.forEach((function(e){e.dts=e.pts-=t._baseDts})),this._doFixAudioInternal(e,r,1e3))}},{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),n.length&&(t.baseDts=a=n[0].dts),this._baseDts=Math.min(i,a);var o=a-i;return Number.isFinite(o)&&Math.abs(o)>LARGE_AV_FIRST_FRAME_GAP&&t.warnings.push({type:WarningType.LARGE_AV_SHIFT,videoBaseDts:a,audioBasePts:i,baseDts:this._baseDts,delta:o}),this._baseDtsInited=!0,!0}},{key:"_resetBaseDtsWhenStreamBreaked",value:function(){this._calculateBaseDts(this.audioTrack,this.videoTrack)&&(this.audioTrack.exist()?this.videoTrack.exist()?this._baseDts-=Math.min(this._audioNextPts,this._videoNextDts):this._baseDts-=this._audioNextPts:this._baseDts-=this._videoNextDts,this._videoTimestampBreak=0,this._audioTimestampBreak=0)}},{key:"_doFixAudioInternal",value:function(e,t,r){if(!e.sampleDuration)switch(e.codecType){case AudioCodecType.AAC:e.sampleDuration=AAC.getFrameDuration(e.timescale,r);break;case AudioCodecType.OPUS:e.sampleDuration=OPUS.getFrameDuration(e.samples,r);break;case AudioCodecType.G711PCMA:case AudioCodecType.G711PCMU:e.sampleDuration=this._getG711Duration(e);break;default:console.error("can't fix audio codecType:",e.codecType)}var n=e.sampleDuration,i=e.codecType===AudioCodecType.OPUS?20:e.codecType===AudioCodecType.AAC?1024:n*e.timescale/1e3;if(void 0===this._audioNextPts){var a=t[0];this._audioNextPts=a.pts}for(var o=0;o<t.length;o++){var s=this._audioNextPts,u=t[o],c=u.pts-s;if(0===o&&this._audioTimestampBreak>=TRACK_BROKEN_CHECK_TIME&&this._keyFrameInNextChunk&&(s=this._audioNextPts=u.dts,c=0,this._audioTimestampBreak=0),!this._audioTimestampBreak&&c>=AUDIO_GAP_OVERLAP_THRESHOLD_COUNT*n&&c<=MAX_SILENT_FRAME_DURATION&&!isSafari){var l=this._getSilentFrame(e)||t[0].data.subarray(),d=Math.floor(c/n);Math.abs(u.pts-this._lastAudioExceptionGapDot)>AUDIO_EXCEPTION_LOG_EMIT_DURATION&&(this._lastAudioExceptionGapDot=u.pts,e.warnings.push({type:WarningType.AUDIO_FILLED,pts:u.pts,originPts:u.originPts,count:d,nextPts:s,refSampleDuration:n}));for(var f=0;f<d;f++){var h=new AudioSample(Math.floor(this._audioNextPts+n)-Math.floor(this._audioNextPts),l,i);h.originPts=Math.floor(this._baseDts+s),t.splice(o,0,h),this._audioNextPts+=n,o++}o--}else if(c<=-AUDIO_GAP_OVERLAP_THRESHOLD_COUNT*n&&c>=-1*MAX_SILENT_FRAME_DURATION)Math.abs(u.pts-this._lastAudioExceptionOverlapDot)>AUDIO_EXCEPTION_LOG_EMIT_DURATION&&(this._lastAudioExceptionOverlapDot=u.pts,e.warnings.push({type:WarningType.AUDIO_DROPPED,pts:u.pts,originPts:u.originPts,nextPts:s,refSampleDuration:n})),t.splice(o,1),o--;else{if(Math.abs(c)>MAX_SILENT_FRAME_DURATION&&(this._audioTimestampBreak++,Math.abs(u.pts-this._lastAudioExceptionLargeGapDot)>AUDIO_EXCEPTION_LOG_EMIT_DURATION&&(this._lastAudioExceptionLargeGapDot=u.pts,e.warnings.push({type:WarningType.LARGE_AUDIO_GAP,time:u.pts/1e3,pts:u.pts,originPts:u.originPts,nextPts:s,sampleDuration:c,refSampleDuration:n}))),e.codecType===AudioCodecType.OPUS){var p=t[t.length-1];p&&(p.duration=u.pts-p.pts)}else u.dts=u.pts=s,u.duration=i;this._audioNextPts+=n}}}},{key:"_getG711Duration",value:function(e){var t=e.sampleSize,r=e.channelCount,n=e.sampleRate,i=e.samples[0];if(i)return 2*i.data.byteLength/r/(t/8)/n*1e3}},{key:"_getSilentFrame",value:function(e){return e.codecType===AudioCodecType.AAC?AAC.getSilentFrame(e.codec,e.channelCount):new Uint8Array(8*e.sampleDuration*e.channelCount)}}]),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}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 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)}))}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 o=[];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&&o.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&&o.push(e.subarray(i,a-2)),a=(i=a+1)+2;break;default:a+=3}return i<n&&o.push(e.subarray(i)),o}},{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,o="";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 s=0;s<16;s++)o+=e[n].toString(16),n++;return{payload:e.subarray(n,n+a),type:i,size:a,uuid:o}}},{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),o=0;for(n=0;n<i;o++,n++)o===r[0]&&(o++,r.shift()),a[n]=e[o];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=[],o=[],s=6,u=31&t[5],c=0;c<u;c++)if(n=t[s]<<8|t[s+1],s+=2,n){var l=t.subarray(s,s+n);s+=n,a.push(l),r||(r=e.parseSPS(NALu.removeEPB(l)))}var d,f=t[s];s++;for(var h=0;h<f;h++)d=t[s]<<8|t[s+1],s+=2,d&&(o.push(t.subarray(s,s+d)),s+=d);return{sps:r,spsArr:a,ppsArr:o,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 o=t.readUEG();if(o<=3&&(a=[0,420,422,444][o]),3===o&&t.skipBits(1),t.skipUEG(),t.skipUEG(),t.skipBits(1),t.readBool())for(var s=3!==o?8:12,u=0;u<s;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,g,m,E=0,b=0,T=0,S=0;if(t.readBool()&&(E=t.readUEG(),b=t.readUEG(),T=t.readUEG(),S=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(),m=(v=P)/(g=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)*(T+S),sarRatio:_,fpsNum:v,fpsDen:g,fps:m,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,o,s,u=1+(3&t[21]),c=[],l=[],d=[],f=23,h=t[22],p=0;p<h;p++){a=63&t[f],o=t[f+1]<<8|t[f+2],f+=3;for(var _=0;_<o;_++)if(s=t[f]<<8|t[f+1],f+=2,s){switch(a){case 32:var y=t.subarray(f,f+s);n||(n=e.parseVPS(NALu.removeEPB(y),r)),d.push(y);break;case 33:var v=t.subarray(f,f+s);i||(i=e.parseSPS(NALu.removeEPB(v),r)),c.push(v);break;case 34:l.push(t.subarray(f,f+s))}f+=s}}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(),o=420;a<=3&&(o=[0,420,422,444][a]);var s=0;3===a&&(s=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!==s?1:2)*(c+u),h-=(1===a&&0===s?2:1)*(d+l));return{codec:"hev1.1.6.L93.B0",width:f,height:h,chromaFormat:o,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=[],o=[];if(t>e.bitsAvailable)throw new Error("maxSubLayersMinus inavlid size ".concat(t));for(var s=0;s<t;s++)a[s]=e.readBits(1),o[s]=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!==o[u]&&e.readBits(8)}}]),e}(),UTF8=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"decode",value:function(t){for(var r=[],n=t,i=0,a=t.length;i<a;)if(n[i]<128)r.push(String.fromCharCode(n[i])),++i;else{if(n[i]<192);else if(n[i]<224){if(e._checkContinuation(n,i,1)){var o=(31&n[i])<<6|63&n[i+1];if(o>=128){r.push(String.fromCharCode(65535&o)),i+=2;continue}}}else if(n[i]<240){if(e._checkContinuation(n,i,2)){var s=(15&n[i])<<12|(63&n[i+1])<<6|63&n[i+2];if(s>=2048&&55296!=(63488&s)){r.push(String.fromCharCode(65535&s)),i+=3;continue}}}else if(n[i]<248&&e._checkContinuation(n,i,3)){var u=(7&n[i])<<18|(63&n[i+1])<<12|(63&n[i+2])<<6|63&n[i+3];if(u>65536&&u<1114112){u-=65536,r.push(String.fromCharCode(u>>>10|55296)),r.push(String.fromCharCode(1023&u|56320)),i+=4;continue}}r.push(String.fromCharCode(65533)),++i}return r.join("")}},{key:"_checkContinuation",value:function(e,t,r){var n=e;if(t+r<n.length){for(;r--;)if(128!=(192&n[++t]))return!1;return!0}return!1}}]),e}(),AMF=function(){function e(){_classCallCheck(this,e)}return _createClass(e,null,[{key:"parse",value:function(t){if(!(t.length<3)){var r={},n=e._parseValue(new DataView(t.buffer,t.byteOffset,t.byteLength)),i=e._parseValue(new DataView(t.buffer,t.byteOffset+n.size,t.byteLength-n.size));return r[n.data]=i.data,r}}},{key:"_parseValue",value:function(t){var r,n=t.byteLength,i=1,a=!1;switch(t.getUint8(0)){case 0:r=t.getFloat64(1),i+=8;break;case 1:r=!!t.getUint8(1),i+=1;break;case 2:var o=e._parseString(new DataView(t.buffer,t.byteOffset+i,t.byteLength-i));r=o.data,i+=o.size;break;case 3:r={};var s=0;for(9==(16777215&t.getUint32(n-4))&&(s=3);i<n-4;){var u=e._parseObject(new DataView(t.buffer,t.byteOffset+i,t.byteLength-i-s)),c=u.size,l=u.data;if(u.isEnd)break;r[l.name]=l.value,i+=c}if(i<=n-3)9===(16777215&t.getUint32(i-1))&&(i+=3);break;case 8:r={},i+=4;var d=0;for(9==(16777215&t.getUint32(n-4))&&(d=3);i<n-8;){var f=e._parseObject(new DataView(t.buffer,t.byteOffset+i,t.byteLength-i-d)),h=f.size,p=f.data;if(f.isEnd)break;r[p.name]=p.value,i+=h}if(i<=n-3)9===(16777215&t.getUint32(i-1))&&(i+=3);break;case 9:r=void 0,i=1,a=!0;break;case 10:r=[];var _=t.getUint32(1);i+=4;for(var y=0;y<_;y++){var v=e._parseValue(new DataView(t.buffer,t.byteOffset+i,t.byteLength-i)),g=v.data,m=v.size;r.push(g),i+=m}break;case 11:var E=t.getFloat64(i)+6e4*t.getInt16(i+8);r=new Date(E),i+=10;break;case 12:var b=t.getUint32(1);i+=4,r="",b>0&&(r=UTF8.decode(new Uint8Array(t.buffer,t.byteOffset+i,b))),i+=b;break;default:i=n}return{data:r,size:i,isEnd:a}}},{key:"_parseString",value:function(e){var t=e.getUint16(0),r="";return t>0&&(r=UTF8.decode(new Uint8Array(e.buffer,e.byteOffset+2,t))),{data:r,size:2+t}}},{key:"_parseObject",value:function(t){if(!(t.byteLength<3)){var r=e._parseString(t),n=e._parseValue(new DataView(t.buffer,t.byteOffset+r.size,t.byteLength-r.size));return{data:{name:r.data,value:n.data},size:r.size+n.size,isEnd:n.isEnd}}}}]),e}(),FlvSoundFormat={MP3:2,G711A:7,G711M:8,AAC:10,OPUS:13},logger$2=new Logger$1("FlvDemuxer"),FlvDemuxer=function(){function e(t,r,n){_classCallCheck(this,e),_defineProperty(this,"_headerParsed",!1),_defineProperty(this,"_remainingData",null),_defineProperty(this,"_gopId",0),_defineProperty(this,"_needAddMetaBeforeKeyFrameNal",!0),this.videoTrack=t||new VideoTrack,this.audioTrack=r||new AudioTrack,this.metadataTrack=n||new MetadataTrack,this._fixer=new FlvFixer(this.videoTrack,this.audioTrack,this.metadataTrack)}return _createClass(e,[{key:"demux",value:function(t){var r,n=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],a=arguments.length>3?arguments[3]:void 0,o=this.audioTrack,s=this.videoTrack,u=this.metadataTrack;if(!n&&i||(this._remainingData=null),n&&(this._headerParsed=!1),n?(s.reset(),o.reset(),u.reset()):(s.samples=[],o.samples=[],u.seiSamples=[],u.flvScriptSamples=[],s.warnings=[],o.warnings=[],this._remainingData&&(t=concatUint8Array(this._remainingData,t),this._remainingData=null)),!t.length)return{videoTrack:s,audioTrack:o,metadataTrack:u};var c=0;if(!this._headerParsed){if(!e.probe(t))throw new Error("Invalid flv file");o.present=(4&t[4])>>>2!=0,s.present=0!=(1&t[4]),this._headerParsed=!0,c=readBig32(t,5)+4}for(var l,d,f,h,p,_=t.length;c+15<_&&(l=t[c],!(c+15+(d=t[c+1]<<16|t[c+2]<<8|t[c+3])>_));)f=(t[c+7]<<24>>>0)+(t[c+4]<<16)+(t[c+5]<<8)+t[c+6],c+=11,h=t.subarray(c,c+d),8===l?this._parseAudio(h,f):9===l?(a&&(this.seamlessLoadingSwitching=!0),this._parseVideo(h,f)):18===l?this._parseScript(h,f):logger$2.warn("Invalid tag type: ".concat(l)),(p=readBig32(t,c+=d))!==11+d&&logger$2.warn("Invalid PrevTagSize ".concat(p," (").concat(11+d,")")),c+=4;c<_&&(this._remainingData=t.subarray(c)),o.formatTimescale=s.formatTimescale=s.timescale=u.timescale=1e3,o.timescale=o.codecType===AudioCodecType.OPUS?1e3:o.sampleRate||0,!o.exist()&&o.hasSample()&&o.reset(),!s.exist()&&s.hasSample()&&s.reset();var y=u.flvScriptSamples[u.flvScriptSamples.length-1],v=null==y||null===(r=y.data)||void 0===r?void 0:r.onMetaData;return v&&(null!=s&&s.exist()&&(v.hasOwnProperty("duration")&&(s.duration=1e3*v.duration),!s.width&&v.hasOwnProperty("width")&&(s.width=v.width),!s.height&&v.hasOwnProperty("height")&&(s.height=v.height)),null!=o&&o.exist()&&v.hasOwnProperty("duration")&&(o.duration=1e3*v.duration)),{videoTrack:s,audioTrack:o,metadataTrack:u}}},{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,i){return this.demux(e,t,r,i),this.fix(n,t,r)}},{key:"_parseAudio",value:function(t,r){if(t.length){var n=(240&t[0])>>>4,i=this.audioTrack;if(n!==FlvSoundFormat.AAC&&n!==FlvSoundFormat.G711A&&n!==FlvSoundFormat.G711M&&n!==FlvSoundFormat.OPUS)return logger$2.warn("Unsupported sound format: ".concat(n)),void i.reset();if(n!==FlvSoundFormat.AAC&&n!==FlvSoundFormat.OPUS){var a=(12&t[0])>>2,o=(2&t[0])>>1,s=1&t[0];i.sampleRate=e.AUDIO_RATE[a],i.sampleSize=o?16:8,i.channelCount=s+1}switch(n){case FlvSoundFormat.G711A:case FlvSoundFormat.G711M:this._parseG711(t,r,n);break;case FlvSoundFormat.AAC:this._parseAac(t,r);break;case FlvSoundFormat.OPUS:this._parseOpus(t,r)}}}},{key:"_parseOpus",value:function(e,t){var r=this.audioTrack,n=e[1];switch(r.codecType=AudioCodecType.OPUS,n){case 0:var i=OPUS.parseHeaderPackets(e.subarray(2));i?(r.codec=i.codec,r.channelCount=i.channelCount,r.sampleRate=i.sampleRate,r.config=i.config,r.sampleDuration=OPUS.getFrameDuration([],r.timescale)):(r.reset(),logger$2.warn("Cannot parse AudioSpecificConfig",e));break;case 1:if(null==t)return;var a=new AudioSample(t,e.subarray(2),r.sampleDuration);r.samples.push(a);break;default:logger$2.warn("Unknown OpusPacketType: ".concat(n))}}},{key:"_parseG711",value:function(e,t,r){var n=this.audioTrack,i=e.subarray(1);if(!(i.byteLength<1)){var a=new AudioSample(t,i);n.codecType=7===r?AudioCodecType.G711PCMA:AudioCodecType.G711PCMU,n.sampleRate=8e3,n.codec=n.codecType,n.samples.push(a)}}},{key:"_parseAac",value:function(e,t){var r=this.audioTrack;if(r.codecType=AudioCodecType.AAC,0===e[1]){var n=AAC.parseAudioSpecificConfig(e.subarray(2));n?(r.codec=n.codec,r.channelCount=n.channelCount,r.sampleRate=n.sampleRate,r.config=n.config,r.objectType=n.objectType,r.sampleRateIndex=n.samplingFrequencyIndex):(r.reset(),logger$2.warn("Cannot parse AudioSpecificConfig",e))}else if(1===e[1]){if(null==t)return;r.samples.push(new AudioSample(t,e.subarray(2)))}else logger$2.warn("Unknown AACPacketType: ".concat(e[1]))}},{key:"_parseVideo",value:function(e,t){var r=this;if(!(e.length<6)){var n=(240&e[0])>>>4,i=15&e[0],a=this.videoTrack;if(7!==i&&12!==i)return a.reset(),void logger$2.warn("Unsupported codecId: ".concat(i));var o=12===i;a.codecType=o?VideoCodecType.HEVC:VideoCodecType.AVC;var s=e[1],u=(e[2]<<16|e[3]<<8|e[4])<<8>>8;if(0===s){var c=e.subarray(5),l=o?HEVC.parseHEVCDecoderConfigurationRecord(c):AVC.parseAVCDecoderConfigurationRecord(c);if(l){var d=l.hvcC,f=l.sps,h=l.ppsArr,p=l.spsArr,_=l.vpsArr,y=l.nalUnitSize;d&&(a.hvcC=a.hvcC||d),f&&(a.codec=f.codec,a.width=f.width,a.height=f.height,a.sarRatio=f.sarRatio,a.fpsNum=f.fpsNum,a.fpsDen=f.fpsDen),p.length&&(a.sps=p),h.length&&(a.pps=h),_&&_.length&&(a.vps=_),y&&(a.nalUnitSize=y)}else logger$2.warn("Cannot parse ".concat(o?"HEVC":"AVC","DecoderConfigurationRecord"),e)}else if(1===s){var v=NALu.parseAvcC(e.subarray(5),a.nalUnitSize);if((v=this._checkAddMetaNalToUnits(o,v,a))&&v.length){var g=new VideoSample(t+u,t,v);if(this.seamlessLoadingSwitching&&t<a.lastKeyFrameDts)return;this.seamlessLoadingSwitching=!1,1===n&&(g.setToKeyframe(),a.lastKeyFrameDts=t),a.samples.push(g),v.forEach((function(e){var n=o?e[0]>>>1&63:31&e[0];switch(n){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!o&&5!==n||o&&5===n)break;g.setToKeyframe();break;case 6:case 39:case 40:if(!o&&6!==n||o&&6===n)break;r.metadataTrack.seiSamples.push(new SeiSample(NALu.parseSEI(NALu.removeEPB(e),o),t+u))}})),g.keyframe&&this._gopId++,g.gopId=this._gopId}else logger$2.warn("Cannot parse NALUs",e)}else 2===s||logger$2.warn("Unknown AVCPacketType: ".concat(s))}}},{key:"_checkAddMetaNalToUnits",value:function(e,t,r){return e&&this._needAddMetaBeforeKeyFrameNal?t.map((function(e){return e[0]>>>1&63})).includes(32)?(this._needAddMetaBeforeKeyFrameNal=!1,t):(t.unshift(r.pps[0]),t.unshift(r.sps[0]),t.unshift(r.vps[0]),t.filter(Boolean)):(this._needAddMetaBeforeKeyFrameNal=!1,t)}},{key:"_parseScript",value:function(e,t){this.metadataTrack.flvScriptSamples.push(new FlvScriptSample(AMF.parse(e),t))}}],[{key:"probe",value:function(e){return 70===e[0]&&76===e[1]&&86===e[2]&&1===e[3]&&readBig32(e,5)>=9}}]),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),o=0;return n.forEach((function(e){a.set(e,o),o+=e.length})),a}_defineProperty(FlvDemuxer,"AUDIO_RATE",[5500,11e3,22e3,44e3]);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 o=8;return r.forEach((function(e){a.set(e,o),o+=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),o=e.sinf(t.enca);return e.box(e.types.enca,i,a,o)}},{key:"encv",value:function(t){var r,n,i=t.sps.length>0?t.sps[0]:[],a=t.pps.length>0?t.pps[0]:[],o=t.width,s=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,o>>8&255,255&o,s>>8&255,255&s,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=[],o=[];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,o.push(i>>>8&255),o.push(255&i),o.push.apply(o,_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,o)))}},{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,o=t.pps;if(r){var s=r.generalProfileCompatibilityFlags,u=r.generalConstraintIndicatorFlags,c=(i.length&&1)+(a.length&&1)+(o.length&&1);n=[1,r.generalProfileSpace<<6|r.generalTierFlag<<5|r.generalProfileIdc,s>>>24,s>>>16,s>>>8,s,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)),o.length&&(n.push(162,0,o.length),o.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),o=e.saio(t),s=e.trun1(t),u=e.senc(t);return e.box(e.types.traf,r,n,a,o,s,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(),g=e.saiz(t),m=e.saio(t),E=e.senc(t),b=e.trun1(t);return e.box(e.types.traf,r,n,v,g,m,E,b)}var T=e.sdtp(t);return e.box(e.types.traf,r,n,T,e.trun(t.samples,T.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 o=12*t.samples.length+124;t.isAudioEncryption&&(o=12*t.samples.length+8*t.audioSenc.length+177),i=Buffer.writeUint32(o)}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,o=[],s=0;return t.isVideo?(o=t.videoSenc,s=t.videoSencLength):o=t.audioSenc,s=s||i*n,r.write(Buffer.writeUint32(16+s),e.types.senc,this.extension(0,a)),r.write(Buffer.writeUint32(n)),o.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 o=0;o<n;o++){var s=t[o],u=s.duration,c=s.size,l=s.flag,d=void 0===l?{}:l,f=s.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*o)}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,o=8;t.samples.forEach((function(e){o+=e.size}));var s=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,s=o+141+16*t.samples.length+c,t.useEME&&t.isAudioEncryption&&!t.isVideoEncryption&&(s=o+16*t.samples.length+84)}else s=o+116+12*t.samples.length,t.useEME&&t.isAudioEncryption&&(s=o+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,s>>16&255,s>>8&255,255&s,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],o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=this.videoTrack,u=this.audioTrack,c=s.exist(),l=u.exist(),d=[];return a&&(o&&o.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&&s.hasSample()&&(n=this._remuxVideo()),l&&u.hasSample()&&(i=this._remuxAudio()),s.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,o=0,s=t.length,u=0;o<s;o++)a=t[o],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}(),TransferCost=function(){function e(){_classCallCheck$3(this,e),_defineProperty$3(this,"_ttfb",0),_defineProperty$3(this,"_demuxStart",0),_defineProperty$3(this,"_demuxEnd",0),_defineProperty$3(this,"_demuxCost",0),_defineProperty$3(this,"_remuxStart",0),_defineProperty$3(this,"_remuxEnd",0),_defineProperty$3(this,"_remuxCost",0),_defineProperty$3(this,"_appendStart",0),_defineProperty$3(this,"_appendEnd",0),_defineProperty$3(this,"_appendCost",0)}return _createClass$3(e,[{key:"set",value:function(e,t){this["_".concat(e)]=t}},{key:"start",value:function(e){this["_".concat(e,"Start")]=Date.now()}},{key:"end",value:function(e){this["_".concat(e,"End")]=Date.now(),this["_".concat(e,"Cost")]=this["_".concat(e,"Cost")]+(this["_".concat(e,"End")]-this["_".concat(e,"Start")])}},{key:"transferCost",get:function(){return{ttfbCost:this._ttfb,demuxCost:this._demuxCost,remuxCost:this._remuxCost,appendCost:this._appendCost}}}]),e}(),TRANSFER_EVENT={TTFB:"ttfb",DEMUX:"demux",REMUX:"remux",APPEND:"append"},logger$1=new Logger$2("BufferService"),BufferService=function(){function e(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};_classCallCheck$3(this,e),_defineProperty$3(this,"flv",null),_defineProperty$3(this,"_demuxer",new FlvDemuxer),_defineProperty$3(this,"_remuxer",null),_defineProperty$3(this,"_mse",null),_defineProperty$3(this,"_softVideo",null),_defineProperty$3(this,"_sourceCreated",!1),_defineProperty$3(this,"_needInitSegment",!0),_defineProperty$3(this,"_discontinuity",!0),_defineProperty$3(this,"_contiguous",!1),_defineProperty$3(this,"_initSegmentId",""),_defineProperty$3(this,"_cachedBuffer",null),_defineProperty$3(this,"_demuxStartTime",0),_defineProperty$3(this,"_opts",null),this.flv=t,this._opts=n,r?this._softVideo=r:(this._remuxer=new FMP4Remuxer(this._demuxer.videoTrack,this._demuxer.audioTrack),this._mse=new MSE(null,{preferMMS:"boolean"==typeof n.preferMMS?n.preferMMS:!!n.perferMMS}),this._mse.bindMedia(t.media))}var t,r,n,i,a,o;return _createClass$3(e,[{key:"baseDts",get:function(){var e,t;return null===(e=this._demuxer)||void 0===e||null===(t=e._fixer)||void 0===t?void 0:t._baseDts}},{key:"blobUrl",get:function(){var e;return null===(e=this._mse)||void 0===e?void 0:e.url}},{key:"isFull",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:MSE.VIDEO;return this._mse.isFull(e)}},{key:"seamlessSwitch",value:function(){this._needInitSegment=!0,this._discontinuity=!0,this._contiguous=!0,this._initSegmentId=""}},{key:"unContiguous",value:function(e){this._contiguous=!1,this._demuxStartTime=e}},{key:"reset",value:(o=_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=6;break}return e.next=4,this._mse.unbindMedia();case 4:return e.next=6,this._mse.bindMedia(this.flv.media);case 6:this._needInitSegment=!0,this._discontinuity=!0,this._contiguous=!1,this._sourceCreated=!1,this._initSegmentId="",this.resetSeamlessSwitchStats();case 12:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"resetSeamlessSwitchStats",value:function(){this.seamlessLoadingSwitch=null,this.seamlessLoadingSwitching=!1,this._demuxer&&(this._demuxer.seamlessLoadingSwitching=!1)}},{key:"endOfStream",value:(a=_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=7;break}if(!this._sourceCreated){e.next=5;break}return e.next=4,this._mse.endOfStream();case 4:this.flv.emit(EVENT.BUFFEREOS);case 5:e.next=8;break;case 7:this._softVideo&&this._softVideo.endOfStream();case 8:case"end":return e.stop()}}),e,this)}))),function(){return a.apply(this,arguments)})},{key:"updateDuration",value:(i=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._mse){e.next=7;break}if(this._mse.isOpened){e.next=4;break}return e.next=4,this._mse.open();case 4:return logger$1.debug("update duration",t),e.next=7,this._mse.updateDuration(t);case 7:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"destroy",value:(n=_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:this._mse=null,this._softVideo=null,this._demuxer=null,this._remuxer=null;case 7:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"appendBuffer",value:(r=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a,o,s,u,c,l,d,f,h,p,_,y,v,g,m,E=this;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=!1,this._cachedBuffer&&(t=concatUint8Array$1(this._cachedBuffer,t),this._cachedBuffer=null),n=this._demuxer,t&&t.length&&n){e.next=5;break}return e.abrupt("return");case 5:e.prev=5,this.flv._transferCost.start(TRANSFER_EVENT.DEMUX),n.demuxAndFix(t,this.seamlessLoadingSwitching||this._discontinuity,this._contiguous,this._demuxStartTime,this.seamlessLoadingSwitching),this.seamlessLoadingSwitching=!1,this.flv._transferCost.end(TRANSFER_EVENT.DEMUX),e.next=15;break;case 12:throw e.prev=12,e.t0=e.catch(5),new StreamingError(ERR.DEMUX,ERR.SUB_TYPES.FLV,e.t0);case 15:if(i=n.videoTrack,a=n.audioTrack,o=n.metadataTrack,!this.seamlessLoadingSwitch){e.next=25;break}if(!((s=i.samples.findIndex((function(e){return e.originDts===i.lastKeyFrameDts})))>=0)){e.next=25;break}return i.samples.splice(s),e.next=22,this.seamlessLoadingSwitch();case 22:this.seamlessLoadingSwitch=null,t=null,r=!0;case 25:if(u=i.exist(),c=a.exist(),this._opts.onlyAudio&&(u=!1,i.present=!1),this._opts.onlyVideo&&(c=!1,a.present=!1),!(!u&&i.present||!c&&a.present)){e.next=42;break}if(l=0,(d=u?i:c?a:void 0)&&d.samples.length&&(l=(d.samples[d.samples.length-1].originPts-d.samples[0].originPts)/d.timescale*1e3),!(l>this._opts.analyzeDuration)){e.next=40;break}logger$1.warn("analyze duration exceeded, ".concat(l,"ms"),d),i.present=u,a.present=c,this.flv.emit(EVENT.ANALYZE_DURATION_EXCEEDED,{duration:l}),e.next=42;break;case 40:return this._cachedBuffer=t,e.abrupt("return");case 42:if(f=i.type,h=a.type,this._fireEvents(i,a,o),r||(this._discontinuity=!1,this._contiguous=!0,this._demuxStartTime=0),p=this._mse,_=function(){var e,t;null!==(e=E.flv)&&void 0!==e&&e.emit&&(null===(t=E.flv)||void 0===t||t.emit(EVENT.APPEND_BUFFER,{}))},this.flv.emit(EVENT.DEMUXED_TRACK,{videoTrack:i}),(y="".concat(i.codec,"/").concat(i.width,"/").concat(i.height,"/").concat(a.codec,"/").concat(a.config))!==this._initSegmentId&&(this._needInitSegment=!0,this._initSegmentId=y,this._emitMetaParsedEvent(i,a)),!p){e.next=83;break}if(this._sourceCreated){e.next=59;break}return e.next=55,p.open();case 55:u&&(logger$1.log("codec: video/mp4;codecs=".concat(i.codec)),p.createSource(f,"video/mp4;codecs=".concat(i.codec))),c&&(logger$1.log("codec: audio/mp4;codecs=".concat(a.codec)),p.createSource(h,"audio/mp4;codecs=".concat(a.codec))),this._sourceCreated=!0,this.flv.emit(EVENT.SOURCEBUFFER_CREATED);case 59:e.prev=59,this._needInitSegment&&!this._opts.mseLowLatency&&(i.duration=this._opts.durationForMSELowLatencyOff*i.timescale,a.duration=this._opts.durationForMSELowLatencyOff*c.timescale),this.flv._transferCost.start(TRANSFER_EVENT.REMUX),v=this._remuxer.remux(this._needInitSegment),this.flv._transferCost.end(TRANSFER_EVENT.REMUX),e.next=69;break;case 66:throw e.prev=66,e.t1=e.catch(59),new StreamingError(ERR.REMUX,ERR.SUB_TYPES.FMP4,e.t1);case 69:if(!this._needInitSegment||v.videoInitSegment||v.audioInitSegment){e.next=71;break}return e.abrupt("return");case 71:return this._needInitSegment=!1,g=[],v.videoInitSegment&&g.push(p.append(f,v.videoInitSegment)),v.audioInitSegment&&g.push(p.append(h,v.audioInitSegment)),v.videoSegment&&g.push(p.append(f,v.videoSegment)),v.audioSegment&&g.push(p.append(h,v.audioSegment)),this.flv._transferCost.start(TRANSFER_EVENT.APPEND),(m=Promise.all(g)).then(_).then((function(){E.flv._transferCost.end(TRANSFER_EVENT.APPEND),_()})),e.abrupt("return",m);case 83:this._softVideo&&(this._softVideo.appendBuffer(i,a),_());case 84:case"end":return e.stop()}}),e,this,[[5,12],[59,66]])}))),function(e){return r.apply(this,arguments)})},{key:"evictBuffer",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i,a=this;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.flv.media,this._mse&&this._demuxer&&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._mse.clearBuffer(0,i).then((function(){return a.flv.emit(EVENT.REMOVE_BUFFER,{removeEnd:i})})));case 11:case"end":return e.stop()}}),e,this)}))),function(e){return t.apply(this,arguments)})},{key:"_emitMetaParsedEvent",value:function(e,t){e.exist()&&this.flv.emit(EVENT.METADATA_PARSED,{type:"video",track:e,meta:{codec:e.codec,timescale:e.timescale,width:e.width,height:e.height,sarRatio:e.sarRatio,baseDts:e.baseDts}}),t.exist()&&this.flv.emit(EVENT.METADATA_PARSED,{type:"audio",track:t,meta:{codec:t.codec,channelCount:t.channelCount,sampleRate:t.sampleRate,timescale:t.timescale,baseDts:t.baseDts}}),logger$1.debug("track parsed",e,t)}},{key:"_fireEvents",value:function(e,t,r){var n=this;logger$1.debug("videoTrack samples count: ".concat(e.samples.length,", audioTrack samples count: ").concat(t.samples.length)),r.flvScriptSamples.forEach((function(e){n.flv.emit(EVENT.FLV_SCRIPT_DATA,e),logger$1.debug("flvScriptData",e)})),e.samples.forEach((function(e){e.keyframe&&n.flv.emit(EVENT.KEYFRAME,{pts:e.originPts})})),e.warnings.forEach((function(e){var t;switch(e.type){case WarningType.LARGE_AV_SHIFT:t=EVENT.LARGE_AV_FIRST_FRAME_GAP_DETECT;break;case WarningType.LARGE_VIDEO_GAP:t=EVENT.LARGE_VIDEO_DTS_GAP_DETECT;break;case WarningType.LARGE_VIDEO_GAP_BETWEEN_CHUNK:t=EVENT.MAX_DTS_DELTA_WITH_NEXT_SEGMENT_DETECT}t&&n.flv.emit(EVENT.STREAM_EXCEPTION,_objectSpread2$2(_objectSpread2$2({},e),{},{type:t})),logger$1.warn("video exception",e)})),t.warnings.forEach((function(e){var t;switch(e.type){case WarningType.LARGE_AUDIO_GAP:t=EVENT.LARGE_AUDIO_DTS_GAP_DETECT;break;case WarningType.AUDIO_FILLED:t=EVENT.AUDIO_GAP_DETECT;break;case WarningType.AUDIO_DROPPED:t=EVENT.AUDIO_OVERLAP_DETECT}t&&n.flv.emit(EVENT.STREAM_EXCEPTION,_objectSpread2$2(_objectSpread2$2({},e),{},{type:t})),logger$1.warn("audio exception",e)})),r.seiSamples.forEach((function(e){n.flv.emit(EVENT.SEI,_objectSpread2$2(_objectSpread2$2({},e),{},{sei:{code:e.data.type,content:e.data.payload,dts:e.pts}}))}))}}]),e}();function getOption(e){var t=_objectSpread2$2({retryCount:3,retryDelay:1e3,disconnectRetryCount:0,loadTimeout:1e4,maxReaderInterval:5e3,preloadTime:5,defaultVodLoadSize:1e7,isLive:!1,softDecode:!1,bufferBehind:10,maxJumpDistance:3,analyzeDuration:2e4,seamlesslyReload:!1,keepStatusAfterSwitch:!0,onlyVideo:!1,onlyAudio:!1,preferMMS:!1,mseLowLatency:!0,durationForMSELowLatencyOff:6,chunkCountForSpeed:50,skipChunkSize:1e3,longtimeNoReceived:3e3,enableStartGapJump:!0},e);return t.isLive&&t.preloadTime&&(t.maxLatency||(t.maxLatency=2*t.preloadTime),t.targetLatency||(t.targetLatency=t.preloadTime),null!==t.disconnectTime&&void 0!==t.disconnectTime||(t.disconnectTime=t.maxLatency)),t}function searchKeyframeIndex(e,t){var r=0,n=e.length-1,i=0,a=0,o=n;for(t<e[0]&&(r=0,a=o+1);a<=o;){if((i=a+Math.floor((o-a)/2))===n||t>=e[i]&&t<e[i+1]){r=i;break}e[i]<t?a=i+1:o=i-1}return r}var logger=new Logger$2("flv"),MAX_HOLE=.1,MAX_START_GAP=.3,Flv=function(e){_inherits$2(c,EventEmitter);var t,r,n,i,a,o,s,u=_createSuper$2(c);function c(e){var t;return _classCallCheck$3(this,c),_defineProperty$3(_assertThisInitialized$2(t=u.call(this)),"media",null),_defineProperty$3(_assertThisInitialized$2(t),"_loading",!1),_defineProperty$3(_assertThisInitialized$2(t),"_opts",null),_defineProperty$3(_assertThisInitialized$2(t),"_bufferService",null),_defineProperty$3(_assertThisInitialized$2(t),"_gapService",null),_defineProperty$3(_assertThisInitialized$2(t),"_stats",null),_defineProperty$3(_assertThisInitialized$2(t),"_mediaLoader",null),_defineProperty$3(_assertThisInitialized$2(t),"_maxChunkWaitTimer",null),_defineProperty$3(_assertThisInitialized$2(t),"_tickTimer",null),_defineProperty$3(_assertThisInitialized$2(t),"_tickInterval",500),_defineProperty$3(_assertThisInitialized$2(t),"_urlSwitching",!1),_defineProperty$3(_assertThisInitialized$2(t),"_seamlessSwitching",!1),_defineProperty$3(_assertThisInitialized$2(t),"_disconnectRetryCount",0),_defineProperty$3(_assertThisInitialized$2(t),"_preLoadEndPoint",0),_defineProperty$3(_assertThisInitialized$2(t),"_keyframes",null),_defineProperty$3(_assertThisInitialized$2(t),"_acceptRanges",!0),_defineProperty$3(_assertThisInitialized$2(t),"_onProgress",function(){var e=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(r,n,i,a){var o,s,u,c,l,d,f,h,p,_;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=i.startTime,s=i.endTime,u=i.st,c=i.firstByteTime,t._loading=!n,t._firstProgressEmit){e.next=13;break}if(t.media){e.next=6;break}return null===(l=t._mediaLoader)||void 0===l||l.cancel(),e.abrupt("return");case 6:d=a.headers,f=u?c-u:s-o,t.emit(EVENT.TTFB,{url:t._opts.url,responseUrl:a.url,elapsed:f}),t.emit(EVENT.LOAD_RESPONSE_HEADERS,{headers:d}),t._transferCost.set(TRANSFER_EVENT.TTFB,f),t._acceptRanges=!(null==d||!d.get("Accept-Ranges"))||!(null==d||!d.get("Content-Range")),t._firstProgressEmit=!0;case 13:if(t._bufferService){e.next=15;break}return e.abrupt("return");case 15:return clearTimeout(t._maxChunkWaitTimer),t._bandwidthService.addChunkRecord(null==r?void 0:r.byteLength,s-o),e.prev=17,e.next=20,t._bufferService.appendBuffer(r);case 20:null===(h=t._bufferService)||void 0===h||h.evictBuffer(t._opts.bufferBehind),e.next=33;break;case 23:if(e.prev=23,e.t0=e.catch(17),t.isLive||!t._bufferService.isFull()){e.next=32;break}return e.next=28,t._mediaLoader.cancel();case 28:return t._loading=!1,p=t.bufferInfo().remaining,t._opts.preloadTime=parseInt(p)/2,e.abrupt("return");case 32:return e.abrupt("return",t._emitError(StreamingError.create(e.t0)));case 33:if(t._urlSwitching&&(t._urlSwitching=!1,t.emit(EVENT.SWITCH_URL_SUCCESS,{url:t._opts.url})),t._seamlessSwitching&&(t._seamlessSwitching=!1,t._tick()),!n||t.media.seeking){e.next=40;break}return t.emit(EVENT.LOAD_COMPLETE),logger.debug("load done"),t.isLive&&t._disconnectRetryCount<=0&&t._end(),e.abrupt("return");case 40:if(t.isLive){e.next=42;break}return e.abrupt("return");case 42:(_=t._opts.maxReaderInterval)&&t._firstProgressEmit&&(clearTimeout(t._maxChunkWaitTimer),t._maxChunkWaitTimer=setTimeout((function(){if(t._disconnectRetryCount)return t._disconnectRetryCount--,void t.load();logger.debug("onMaxChunkWait",_),t._end()}),_));case 44:case"end":return e.stop()}}),e,null,[[17,23]])})));return function(t,r,n,i){return e.apply(this,arguments)}}()),_defineProperty$3(_assertThisInitialized$2(t),"_onRetryError",(function(e,r){logger.debug("load retry",e,r),t.emit(EVENT.LOAD_RETRY,{error:StreamingError.network(e),retryTime:r})})),_defineProperty$3(_assertThisInitialized$2(t),"_end",(function(){t._clear(),t._bufferService&&t._bufferService.endOfStream(),logger.debug("end stream")})),_defineProperty$3(_assertThisInitialized$2(t),"_resetDisconnectCount",(function(){t._disconnectRetryCount=t._opts.disconnectRetryCount})),_defineProperty$3(_assertThisInitialized$2(t),"_tick",(function(){clearTimeout(t._tickTimer);var e=_assertThisInitialized$2(t).media;if(e){t._tickTimer=setTimeout(t._tick,t._tickInterval);var r=Buffer$1.end(Buffer$1.get(e));if(!(r<MAX_HOLE)&&e.readyState){var n=t._opts;if(isMediaPlaying(e)&&e.currentTime)t._gapService&&t._gapService.do(e,n.maxJumpDistance,t.isLive,3);else{if(!e.currentTime&&t._gapService&&n.enableStartGapJump)return void((t._opts.mseLowLatency||!1===t._opts.mseLowLatency&&t.bufferInfo(MAX_START_GAP).nextStart)&&t._gapService.do(e,n.maxJumpDistance,t.isLive,3));n.isLive&&4===e.readyState&&r-e.currentTime>n.disconnectTime&&t.disconnect()}}}})),_defineProperty$3(_assertThisInitialized$2(t),"_onPlay",(function(){var e,r,n=t._opts.softDecode||(null===(e=t.media)||void 0===e||null===(r=e.buffered)||void 0===r?void 0:r.length);if(t.isLive)!t._loading&&n&&t.replay(void 0,!0);else{var i=t.bufferInfo();(i.start||i.nextStart)>MAX_HOLE&&t._tick()}})),_defineProperty$3(_assertThisInitialized$2(t),"_onLoadeddata",(function(){t.isLive&&!t._opts.mseLowLatency&&t.media.duration!==1/0&&t._bufferService.updateDuration(1/0).catch((function(e){}))})),_defineProperty$3(_assertThisInitialized$2(t),"_onSeeking",_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:!t.isLive&&t.seekable&&(t._preLoadEndPoint=-1,t._checkPreload());case 1:case"end":return e.stop()}}),e)})))),_defineProperty$3(_assertThisInitialized$2(t),"_onTimeupdate",(function(){if(t.media){var e=t._opts,r=t.media.currentTime;if(e.isLive&&e.maxLatency&&e.targetLatency){var n=Buffer$1.end(Buffer$1.get(t.media));n-r>=e.maxLatency&&(t.media.currentTime=n-e.targetLatency,t.emit(EVENT.CHASEFRAME,{currentTime:t.media.currentTime,latency:e.targetLatency}))}t._seiService.throw(r,!0),e.isLive||!t.seekable||t._loading||t._checkPreload()}})),_defineProperty$3(_assertThisInitialized$2(t),"_onWaiting",(function(){t.isLive&&!t._loading&&t._disconnectRetryCount&&(t._disconnectRetryCount--,t.load())})),_defineProperty$3(_assertThisInitialized$2(t),"_onBufferUpdate",(function(){if(!t._opts.isLive){var e=t.bufferInfo(),r=e.end,n=e.nextEnd;Math.abs((r||n)-t.media.duration)<1&&(t._end(),t.media.readyState<=2&&t._tick())}})),_defineProperty$3(_assertThisInitialized$2(t),"_checkPreload",_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var r,n,i,a,o,s,u,c,l,d;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.bufferInfo(),n=r.remaining,i=void 0===n?0:n,a=t._opts,o=t._keyframes.filepositions,s=t._keyframes.times,u=t.media.currentTime,!(i<a.preloadTime)){e.next=19;break}if(c=searchKeyframeIndex(t._keyframes.times,u+i+MAX_HOLE),(l=searchKeyframeIndex(t._keyframes.times,u+i+t._opts.preloadTime))===c&&(l=c+1),t._preLoadEndPoint!==l){e.next=11;break}return e.abrupt("return");case 11:if(null!=(d=o[c])){e.next=14;break}return e.abrupt("return");case 14:return e.next=16,t._mediaLoader.cancel();case 16:t._loadData(null,[d,o[l]]),t._preLoadEndPoint=l,t._bufferService.unContiguous(s[c]);case 19:case"end":return e.stop()}}),e)})))),_defineProperty$3(_assertThisInitialized$2(t),"_onFlvScriptData",(function(e){var r,n,i,a,o=null===(r=e.data)||void 0===r||null===(n=r.onMetaData)||void 0===n?void 0:n.keyframes,s=null===(i=e.data)||void 0===i||null===(a=i.onMetaData)||void 0===a?void 0:a.duration;o&&(t._keyframes=o),!t._opts.isLive&&s&&t._bufferService.updateDuration(s)})),t._opts=getOption(e),t.media=t._opts.media||document.createElement("video"),t._opts.media=null,t._firstProgressEmit=!1,t._mediaLoader=new NetLoader(_objectSpread2$2(_objectSpread2$2({},t._opts.fetchOptions),{},{retry:t._opts.retryCount,retryDelay:t._opts.retryDelay,timeout:t._opts.loadTimeout,onRetryError:t._onRetryError,onProgress:t._onProgress,responseType:"arraybuffer"})),t._disconnectRetryCount=t._opts.disconnectRetryCount,t._transferCost=new TransferCost,t._bufferService=new BufferService(_assertThisInitialized$2(t),t._opts.softDecode?t.media:void 0,t._opts),t._seiService=new SeiService(_assertThisInitialized$2(t)),t._bandwidthService=new BandwidthService({chunkCountForSpeed:t._opts.chunkCountForSpeed,skipChunkSize:t._opts.skipChunkSize,longtimeNoReceived:t._opts.longtimeNoReceived}),t._stats=new MediaStatsService(_assertThisInitialized$2(t)),t._opts.softDecode||(t._gapService=new GapService),t.media.addEventListener("play",t._onPlay),t.media.addEventListener("loadeddata",t._onLoadeddata),t.media.addEventListener("seeking",t._onSeeking),t.media.addEventListener("timeupdate",t._onTimeupdate),t.media.addEventListener("progress",t._onBufferUpdate),t.media.addEventListener("waiting",t._onWaiting),t.on(EVENT.FLV_SCRIPT_DATA,t._onFlvScriptData),t}return _createClass$3(c,[{key:"version",get:function(){return"3.0.23-rc.6"}},{key:"isLive",get:function(){return this._opts.isLive}},{key:"baseDts",get:function(){var e;return null===(e=this._bufferService)||void 0===e?void 0:e.baseDts}},{key:"seekable",get:function(){return!!this._keyframes&&this._acceptRanges}},{key:"loader",get:function(){return this._mediaLoader}},{key:"blobUrl",get:function(){var e;return null===(e=this._bufferService)||void 0===e?void 0:e.blobUrl}},{key:"speedInfo",value:function(){return{speed:this._bandwidthService.getLatestSpeed(),avgSpeed:this._bandwidthService.getAvgSpeed(),totalSize:this._bandwidthService.getTotalSize(),totalCost:this._bandwidthService.getTotalCost()}}},{key:"getStats",value:function(){return this._stats.getStats()}},{key:"bufferInfo",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:MAX_HOLE;return Buffer$1.info(Buffer$1.get(this.media),null===(e=this.media)||void 0===e?void 0:e.currentTime,t)}},{key:"playbackQuality",value:function(){return getVideoPlaybackQuality(this.media)}},{key:"load",value:(s=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t){var r,n,i=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=i.length>1&&void 0!==i[1]&&i[1],n=i.length>2?i[2]:void 0,this._bufferService){e.next=4;break}return e.abrupt("return");case 4:return e.next=6,this._reset(r);case 6:this._loadData(t,this._opts.isLive?[]:[0,this._opts.defaultVodLoadSize],n),clearTimeout(this._tickTimer),this._tickTimer=setTimeout(this._tick,this._tickInterval);case 9:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"replay",value:(o=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){var t,r,n=this,i=arguments;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t=i.length>0&&void 0!==i[0]?i[0]:this._opts.seamlesslyReload,r=i.length>1?i[1]:void 0,this.media){e.next=4;break}return e.abrupt("return");case 4:if(this._resetDisconnectCount(),!t){e.next=11;break}return e.next=8,this._clear();case 8:setTimeout((function(){n._seamlessSwitching=!0,n._loadData(n._opts.url),n._bufferService.seamlessSwitch()})),e.next=13;break;case 11:return e.next=13,this.load();case 13:return e.abrupt("return",this.media.play(!r).catch((function(){})));case 14:case"end":return e.stop()}}),e,this)}))),function(){return o.apply(this,arguments)})},{key:"disconnect",value:function(){var e;return logger.debug("disconnect!"),null===(e=this._bufferService)||void 0===e||e.resetSeamlessSwitchStats(),this._clear()}},{key:"switchURL",value:(a=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(t,r){var n=this;return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this._bufferService){e.next=2;break}return e.abrupt("return");case 2:if(this._resetDisconnectCount(),!this._loading||!r){e.next=6;break}return this._bufferService.seamlessLoadingSwitch=function(){var e=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(r){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n._clear();case 2:n._bufferService.seamlessLoadingSwitching=!0,n._urlSwitching=!0,n._seamlessSwitching=!0,n._bufferService.seamlessSwitch(),n._loadData(t);case 7:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.abrupt("return");case 6:if(r&&this._opts.isLive){e.next=11;break}return e.next=9,this.load(t);case 9:return this._urlSwitching=!0,e.abrupt("return",this.media.play(!0).catch((function(){})));case 11:return e.next=13,this._clear();case 13:setTimeout((function(){n._urlSwitching=!0,n._seamlessSwitching=!0,n._loadData(t),n._bufferService.seamlessSwitch()}));case 14:case"end":return e.stop()}}),e,this)}))),function(e,t){return a.apply(this,arguments)})},{key:"destroy",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.media){e.next=2;break}return e.abrupt("return");case 2:return this.removeAllListeners(),this._seiService.reset(),this.media.removeEventListener("play",this._onPlay),this.media.removeEventListener("loadeddata",this._onLoadeddata),this.media.removeEventListener("seeking",this._onSeeking),this.media.removeEventListener("timeupdate",this._onTimeupdate),this.media.removeEventListener("waiting",this._onWaiting),this.media.removeEventListener("progress",this._onBufferUpdate),e.next=12,Promise.all([this._clear(),this._bufferService.destroy()]);case 12:this.media=null,this._bufferService=null;case 14:case"end":return e.stop()}}),e,this)}))),function(){return i.apply(this,arguments)})},{key:"_emitError",value:function(e){var t,r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];logger.table(e),logger.error(e),logger.error(null===(t=this.media)||void 0===t?void 0:t.error),this._urlSwitching&&(this._urlSwitching=!1,this._seamlessSwitching=!1,this.emit(EVENT.SWITCH_URL_FAILED,e)),this.emit(EVENT.ERROR,e),r&&(this._seiService.reset(),this._end())}},{key:"_reset",value:(n=_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:return t=r.length>0&&void 0!==r[0]&&r[0],this._seiService.reset(),this._bandwidthService.reset(),this._stats.reset(),e.next=6,this._clear();case 6:return e.next=8,this._bufferService.reset(t);case 8:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"_loadData",value:(r=_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(t&&(this._opts.url=t),i=t=this._opts.url,t){e.next=4;break}throw new Error("Source url is missing");case 4:if(this._opts.preProcessUrl&&(i=this._opts.preProcessUrl(t).url),this._mediaLoader.finnalUrl=i,this.emit(EVENT.LOAD_START,{url:i,seamlessSwitching:this._seamlessSwitching}),logger.debug("load data, loading:",this._loading,i),!this._loading){e.next=11;break}return e.next=11,this._mediaLoader.cancel();case 11:return this._loading=!0,e.prev=12,e.next=15,this._mediaLoader.load({url:i,range:r,streamRes:n,firstMaxChunkSize:this._opts.firstMaxChunkSize});case 15:e.next=21;break;case 17:return e.prev=17,e.t0=e.catch(12),this._loading=!1,e.abrupt("return",this._emitError(StreamingError.network(e.t0),!1));case 21:case"end":return e.stop()}}),e,this,[[12,17]])}))),function(e,t,n){return r.apply(this,arguments)})},{key:"_clear",value:(t=_asyncToGenerator$1(_regeneratorRuntime$1().mark((function e(){return _regeneratorRuntime$1().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._mediaLoader){e.next=3;break}return e.next=3,this._mediaLoader.cancel();case 3:clearTimeout(this._maxChunkWaitTimer),clearTimeout(this._tickTimer),this._loading=!1,this._firstProgressEmit=!1;case 7:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}],[{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()}}]),c}();try{localStorage.getItem("xgd")?Flv.enableLogger():Flv.disableLogger()}catch(e){}var PluginExtension=function(){function e(t,r){var n=this;_classCallCheck$3(this,e),_defineProperty$3(this,"_onLowDecode",(function(){var e,t,r,i,a=n._opts,o=a.media,s=a.innerDegrade,u=a.backupURL;null===(e=n._plugin)||void 0===e||null===(t=e.player)||void 0===t||t.emit("lowdecode",o.degradeInfo),null===(r=n._plugin)||void 0===r||null===(i=r.player)||void 0===i||i.emit("core_event",_objectSpread2$2(_objectSpread2$2({},o.degradeInfo),{},{eventName:EVENT.LOWDECODE})),1!==s&&3!==s||!u||n._degrade(u)})),_defineProperty$3(this,"_degrade",(function(e){var t=n._plugin.player,r=t.video;if("MVideo"===(null==r?void 0: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 o=n._plugin.constructor.pluginName.toLowerCase();t.unRegisterPlugin(o),t.once("canplay",(function(){t.play()}))}})),_defineProperty$3(this,"forceDegradeToVideo",(function(e){var t=n._opts.innerDegrade;1!==t&&3!==t||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.isLive,n=e.preloadTime,i=e.innerDegrade,a=e.decodeMode;t&&(r||!t.setPlayMode?(i&&t.setAttribute("innerdegrade",i),n&&t.setAttribute("preloadtime",n),t.setDecodeMode&&t.setDecodeMode(a),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}(),FlvPlugin=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),"flv",null),_defineProperty$3(_assertThisInitialized$2(e),"pluginExtension",null),_defineProperty$3(_assertThisInitialized$2(e),"getStats",(function(){var t;return null===(t=e.flv)||void 0===t?void 0:t.getStats()})),_defineProperty$3(_assertThisInitialized$2(e),"loadSource",(function(){var t;arguments.length>0&&void 0!==arguments[0]||e.player.config.url;var r=arguments.length>1?arguments[1]:void 0;null===(t=e.flv)||void 0===t||t.load(e.player.config.url,!0,r)})),_defineProperty$3(_assertThisInitialized$2(e),"destroy",(function(){var t;e.flv&&(e.flv.destroy(),e.flv=null),null===(t=e.pluginExtension)||void 0===t||t.destroy(),e.pluginExtension=null})),_defineProperty$3(_assertThisInitialized$2(e),"_onSwitchURL",(function(t,r){var n,i;e.flv&&(e.player.config.url=t,"object"===_typeof$2(r)&&(r=r.seamless),e.flv.switchURL(t,r),!r&&null!==(n=e.player.config)&&void 0!==n&&null!==(i=n.flv)&&void 0!==i&&i.keepStatusAfterSwitch&&e._keepPauseStatus())})),_defineProperty$3(_assertThisInitialized$2(e),"_keepPauseStatus",(function(){e.player.paused&&e.player.once("canplay",(function(){e.player.pause()}))})),_defineProperty$3(_assertThisInitialized$2(e),"_onDefinitionChange",(function(t){var r=t.to;e.flv&&e.flv.switchURL(r)})),e}return _createClass$3(r,[{key:"core",get:function(){return this.flv}},{key:"version",get:function(){var e;return null===(e=this.flv)||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:"loader",get:function(){var e;return null===(e=this.flv)||void 0===e?void 0:e.loader}},{key:"transferCost",get:function(){return this.flv._transferCost.transferCost}},{key:"beforePlayerInit",value:function(){var e=this,t=this.player.config,r=this.player.media||this.player.video;if(t.url){this.flv&&this.flv.destroy(),this.player.switchURL=this._onSwitchURL;var n,i=t.flv||{};if(null!==i.disconnectTime&&void 0!==i.disconnectTime||(i.disconnectTime=0),this.flv=new Flv(_objectSpread2$2({softDecode:this.softDecode,isLive:t.isLive,media:r,preProcessUrl:function(t,r){var n,i;return(null===(n=e.player)||void 0===n||null===(i=n.preProcessUrl)||void 0===i?void 0:i.call(n,t,r))||{url:t,ext:r}}},i)),this.softDecode||BasePlugin.defineGetterOrSetter(this.player,{url:{get:function(){var t;return null===(t=e.flv)||void 0===t?void 0:t.blobUrl},configurable:!0}}),this.softDecode&&(this.pluginExtension=new PluginExtension(_objectSpread2$2({media:this.player.video,isLive:t.isLive},t.flv),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===(n=this.player)||void 0===n||n.useHooks("replay",(function(){var t;return null===(t=e.flv)||void 0===t?void 0:t.replay()}));this.on(URL_CHANGE,this._onSwitchURL),this.on(DESTROY,this.destroy),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.ANALYZE_DURATION_EXCEEDED),this._transCoreEvent(EVENT.APPEND_BUFFER),this._transCoreEvent(EVENT.REMOVE_BUFFER),this._transCoreEvent(EVENT.BUFFEREOS),this._transCoreEvent(EVENT.KEYFRAME),this._transCoreEvent(EVENT.CHASEFRAME),this._transCoreEvent(EVENT.METADATA_PARSED),this._transCoreEvent(EVENT.SEI),this._transCoreEvent(EVENT.SEI_IN_TIME),this._transCoreEvent(EVENT.FLV_SCRIPT_DATA),this._transCoreEvent(EVENT.STREAM_EXCEPTION),this._transCoreEvent(EVENT.SWITCH_URL_SUCCESS),this._transCoreEvent(EVENT.SWITCH_URL_FAILED),i.manualLoad||this.loadSource(t.url,i.streamRes)}}},{key:"_transError",value:function(){var e=this;this.flv.on(EVENT.ERROR,(function(t){e.player&&e.player.emit(ERROR,new Errors(e.player,t))}))}},{key:"_transCoreEvent",value:function(e){var t=this;this.flv.on(e,(function(r){t.player&&t.player.emit("core_event",_objectSpread2$2(_objectSpread2$2({},r),{},{eventName:e}))}))}}],[{key:"pluginName",get:function(){return"flv"}},{key:"isSupported",value:function(e,t){return Flv.isSupported(e,t)}},{key:"isSupportedMMS",value:function(){return"undefined"!=typeof ManagedMediaSource}}]),r}();_defineProperty$3(FlvPlugin,"Flv",Flv);export{FlvPlugin as default};
|