@volcengine/veplayer 1.11.1-rc.1 → 1.11.1

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.
@@ -0,0 +1,2 @@
1
+ // Built @Tue, 19 Mar 2024 03:31:11 GMT
2
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("core-js/modules/es.object.to-string.js"),require("core-js/modules/es.promise.js"),require("core-js/modules/es.promise.finally.js"),require("core-js/modules/es.array.splice.js"),require("core-js/modules/es.array.concat.js"),require("core-js/modules/es.object.assign.js"),require("core-js/modules/es.array.sort.js"),require("core-js/modules/es.array.filter.js"),require("core-js/modules/web.dom-collections.for-each.js"),require("core-js/modules/es.object.keys.js"),require("core-js/modules/es.regexp.exec.js"),require("core-js/modules/es.string.split.js"),require("core-js/modules/es.array.join.js"),require("core-js/modules/es.array.slice.js"),require("core-js/modules/es.object.values.js"),require("core-js/modules/es.array.includes.js"),require("core-js/modules/es.string.includes.js"),require("core-js/modules/es.function.name.js"),require("core-js/modules/es.array.iterator.js"),require("core-js/modules/es.string.iterator.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/es.regexp.to-string.js"),require("core-js/modules/es.map.js"),require("core-js/modules/esnext.map.delete-all.js"),require("core-js/modules/esnext.map.every.js"),require("core-js/modules/esnext.map.filter.js"),require("core-js/modules/esnext.map.find.js"),require("core-js/modules/esnext.map.find-key.js"),require("core-js/modules/esnext.map.includes.js"),require("core-js/modules/esnext.map.key-of.js"),require("core-js/modules/esnext.map.map-keys.js"),require("core-js/modules/esnext.map.map-values.js"),require("core-js/modules/esnext.map.merge.js"),require("core-js/modules/esnext.map.reduce.js"),require("core-js/modules/esnext.map.some.js"),require("core-js/modules/esnext.map.update.js")):"function"==typeof define&&define.amd?define(["exports","core-js/modules/es.object.to-string.js","core-js/modules/es.promise.js","core-js/modules/es.promise.finally.js","core-js/modules/es.array.splice.js","core-js/modules/es.array.concat.js","core-js/modules/es.object.assign.js","core-js/modules/es.array.sort.js","core-js/modules/es.array.filter.js","core-js/modules/web.dom-collections.for-each.js","core-js/modules/es.object.keys.js","core-js/modules/es.regexp.exec.js","core-js/modules/es.string.split.js","core-js/modules/es.array.join.js","core-js/modules/es.array.slice.js","core-js/modules/es.object.values.js","core-js/modules/es.array.includes.js","core-js/modules/es.string.includes.js","core-js/modules/es.function.name.js","core-js/modules/es.array.iterator.js","core-js/modules/es.string.iterator.js","core-js/modules/web.dom-collections.iterator.js","core-js/modules/es.regexp.to-string.js","core-js/modules/es.map.js","core-js/modules/esnext.map.delete-all.js","core-js/modules/esnext.map.every.js","core-js/modules/esnext.map.filter.js","core-js/modules/esnext.map.find.js","core-js/modules/esnext.map.find-key.js","core-js/modules/esnext.map.includes.js","core-js/modules/esnext.map.key-of.js","core-js/modules/esnext.map.map-keys.js","core-js/modules/esnext.map.map-values.js","core-js/modules/esnext.map.merge.js","core-js/modules/esnext.map.reduce.js","core-js/modules/esnext.map.some.js","core-js/modules/esnext.map.update.js"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).XGPlayerPreload={})}(this,(function(e){"use strict";var t=function(e){return e[e.DURATION=0]="DURATION",e[e.SIZE=1]="SIZE",e}(t||{}),r=function(e){return e[e.INDEXDB=0]="INDEXDB",e[e.MEMORY=1]="MEMORY",e}(r||{});function n(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 o(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?n(Object(r),!0).forEach((function(t){d(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function a(){a=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",s=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(O){c=function(e,t,r){return e[t]=r}}function l(e,t,r,o){var a=t&&t.prototype instanceof h?t:h,i=Object.create(a.prototype),s=new x(o||[]);return n(i,"_invoke",{value:w(e,r,s)}),i}function f(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(O){return{type:"throw",arg:O}}}e.wrap=l;var d={};function h(){}function v(){}function p(){}var y={};c(y,i,(function(){return this}));var m=Object.getPrototypeOf,g=m&&m(m(C([])));g&&g!==t&&r.call(g,i)&&(y=g);var _=p.prototype=h.prototype=Object.create(y);function b(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){function o(n,a,i,s){var u=f(e[n],e,a);if("throw"!==u.type){var c=u.arg,l=c.value;return l&&"object"==typeof l&&r.call(l,"__await")?t.resolve(l.__await).then((function(e){o("next",e,i,s)}),(function(e){o("throw",e,i,s)})):t.resolve(l).then((function(e){c.value=e,i(c)}),(function(e){return o("throw",e,i,s)}))}s(u.arg)}var a;n(this,"_invoke",{value:function(e,r){function n(){return new t((function(t,n){o(e,r,t,n)}))}return a=a?a.then(n,n):n()}})}function w(e,t,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=j(i,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=f(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 j(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,j(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),d;var o=f(n,e.iterator,t.arg);if("throw"===o.type)return t.method="throw",t.arg=o.arg,t.delegate=null,d;var a=o.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 P(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 I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(P,this),this.reset(!0)}function C(e){if(e){var t=e[i];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,o=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 o.next=o}}return{next:S}}function S(){return{value:void 0,done:!0}}return v.prototype=p,n(_,"constructor",{value:p,configurable:!0}),n(p,"constructor",{value:v,configurable:!0}),v.displayName=c(p,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===v||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,c(e,u,"GeneratorFunction")),e.prototype=Object.create(_),e},e.awrap=function(e){return{__await:e}},b(k.prototype),c(k.prototype,s,(function(){return this})),e.AsyncIterator=k,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new k(l(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},b(_),c(_,u,"Generator"),c(_,i,(function(){return this})),c(_,"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=C,x.prototype={constructor:x,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(I),!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 i.type="throw",i.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=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 o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(i)},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),I(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 o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:C(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),d}},e}function i(e){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function s(e,t,r,n,o,a,i){try{var s=e[a](i),u=s.value}catch(c){return void r(c)}s.done?t(u):Promise.resolve(u).then(n,o)}function u(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var a=e.apply(t,r);function i(e){s(a,n,o,i,u,"next",e)}function u(e){s(a,n,o,i,u,"throw",e)}i(void 0)}))}}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(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,j(n.key),n)}}function f(e,t,r){return t&&l(e.prototype,t),r&&l(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e,t,r){return(t=j(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function h(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&&p(e,t)}function v(e){return(v=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function y(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function m(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=v(e);if(t){var o=v(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return function(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 y(e)}(this,r)}}function g(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a,i,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(l){c=!0,o=l}finally{try{if(!u&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(c)throw o}}return s}}(e,t)||b(e,t)||function(){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 _(e){return function(e){if(Array.isArray(e))return k(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||b(e)||function(){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 b(e,t){if(e){if("string"==typeof e)return k(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)?k(e,t):void 0}}function k(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 w(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=b(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}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,i=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){s=!0,a=e},f:function(){try{i||null==r.return||r.return()}finally{if(s)throw a}}}}function j(e){var t=function(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)}(e,"string");return"symbol"==typeof t?t:String(t)}function P(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var I={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function o(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function a(e,t,n,a,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var s=new o(n,a||e,i),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 i(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,o=[];if(0===this._eventsCount)return o;for(n in e=this._events)t.call(e,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(e)):o},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 o=0,a=n.length,i=new Array(a);o<a;o++)i[o]=n[o].fn;return i},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,o,a,i){var s=r?r+e:e;if(!this._events[s])return!1;var u,c,l=this._events[s],f=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),f){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,o),!0;case 5:return l.fn.call(l.context,t,n,o,a),!0;case 6:return l.fn.call(l.context,t,n,o,a,i),!0}for(c=1,u=new Array(f-1);c<f;c++)u[c-1]=arguments[c];l.fn.apply(l.context,u)}else{var d,h=l.length;for(c=0;c<h;c++)switch(l[c].once&&this.removeListener(e,l[c].fn,void 0,!0),f){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,o);break;default:if(!u)for(d=1,u=new Array(f-1);d<f;d++)u[d-1]=arguments[d];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,o){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return i(this,a),this;var s=this._events[a];if(s.fn)s.fn!==t||o&&!s.once||n&&s.context!==n||i(this,a);else{for(var u=0,c=[],l=s.length;u<l;u++)(s[u].fn!==t||o&&!s[u].once||n&&s[u].context!==n)&&c.push(s[u]);c.length?this._events[a]=1===c.length?c[0]:c:i(this,a)}return this},s.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&i(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}(I);var x=P(I.exports),C=function(e){return e.MP4="MP4",e.MP4_MSE_SOFT="MP4_MSE_SOFT",e.MP4_MSE="MP4_MSE",e.MP4_0="MP4_0",e.MP4_1="MP4_1",e.MP4_2="MP4_2",e.DASH="DASH",e.HLS="HLS",e}(C||{}),S="cdn";var O=L&&!function(){var e="_localstorage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(t){return!0}}();function L(){try{return"undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return!1}}var T={length:O?localStorage.length:0,clear:function(e){try{for(var t=localStorage.length-1;t>=0;t--){var r=localStorage.key(t);0===r.indexOf(e)&&localStorage.removeItem(r)}}catch(n){}},getItem:function(e){try{return localStorage.getItem(e)}catch(t){return null}},key:function(e){try{return localStorage.key(e)}catch(t){return null}},setItem:function(e,t){try{localStorage.setItem(e,t)}catch(r){}},removeItem:function(e){try{localStorage.removeItem(e)}catch(t){}},isSupport:O},E=function(){function e(){var t,r;c(this,e);var n=new Promise((function(e,n){t=e,r=n}));return n.resolve=t,n.reject=r,n}return f(e,[{key:"resolve",value:function(e){}},{key:"reject",value:function(e){}}]),e}();Promise.withResolvers||(Promise.withResolvers=function(){var e={};return e.promise=new Promise((function(t,r){e.resolve=t,e.reject=r})),e});var D=function(){try{if("undefined"!=typeof indexedDB)return indexedDB}catch(e){}}();function K(e,t){t&&e.then((function(e){t(null,e)}),(function(e){t(e)}))}function M(e){return"string"!=typeof e&&(console.warn("".concat(e," used as a key, but it is not a string.")),e=String(e)),e}var q={},A="readonly",B="readwrite";function R(e){var t=q[e.name],r={};r.promise=new Promise((function(e,t){r.resolve=e,r.reject=t})),t.deferredOperations.push(r),t.dbReady?t.dbReady=t.dbReady.then((function(){return r.promise})):t.dbReady=r.promise}function N(e,t){return new Promise((function(r,n){if(q[e.name]=q[e.name]||{forages:[],db:null,dbReady:null,deferredOperations:[]},e.db){if(!t)return r(e.db);R(e),e.db.close()}var o=[e.name];t&&o.push(e.version);var a=null==D?void 0:D.open.apply(D,o);t&&(a.onupgradeneeded=function(t){var r=a.result;try{r.createObjectStore(e.storeName)}catch(n){if("ConstraintError"!==n.name)throw n;console.warn('The database "'.concat(e.name,'" has been upgraded from version ').concat(t.oldVersion," to\n version ").concat(t.newVersion,', but the storage "').concat(e.storeName,'" already exists.'))}}),a.onerror=function(e){e.preventDefault(),n(a.error)},a.onsuccess=function(){r(a.result),function(e){var t=q[e.name].deferredOperations.pop();if(t)t.resolve(),t.promise}(e)}}))}function U(e){return N(e,!1)}function V(e){return N(e,!0)}function F(e,t){if(!e.db)return!0;var r=!e.db.objectStoreNames.contains(e.storeName),n=e.version<e.db.version,o=e.version>e.db.version;if(n&&(e.version!==t&&console.warn('The database "'.concat(e.name,"\" can't be downgraded from version ").concat(e.db.version," to\n version ").concat(e.version,".")),e.version=e.db.version),o||r){if(r){var a=e.db.version+1;a>e.version&&(e.version=a)}return!0}return!1}function Y(e){R(e);for(var t=q[e.name],r=t.forages,n=0;n<r.length;n++){var o=r[n];o._dbInfo.db&&(o._dbInfo.db.close(),o._dbInfo.db=null)}return e.db=null,U(e).then((function(t){return e.db=t,F(e)?V(e):t})).then((function(n){e.db=t.db=n;for(var o=0;o<r.length;o++)r[o]._dbInfo.db=n})).catch((function(t){throw function(e,t){var r=q[e.name].deferredOperations.pop();if(r)r.reject(t),r.promise}(e,t),t}))}function G(e,t,r,n){void 0===n&&(n=1);try{var o=e.db.transaction(e.storeName,t);r(null,o)}catch(a){if(n>0&&(!e.db||"InvalidStateError"===a.name||"NotFoundError"===a.name))return Promise.resolve().then((function(){if(!e.db||"NotFoundError"===a.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),V(e)})).then((function(){return Y(e).then((function(){G(e,t,r,n-1)}))})).catch(r);r(a)}}var H=function(){function e(){c(this,e)}return f(e,[{key:"ready",value:function(){return this._ready}},{key:"_initStorage",value:function(e){var t=this;t._defaultConfig=e;var r={db:null,name:"",version:""};if(e)for(var n in e)r[n]=e[n];var o=q[r.name];o||(o={forages:[],db:null,dbReady:null,deferredOperations:[]},q[r.name]=o),o.forages.push(t),t._initReady||(t._initReady=t.ready,t._ready=t._fullyReady);var a=[];function i(){return Promise.resolve()}for(var s=0;s<o.forages.length;s++){var u=o.forages[s];u!==t&&a.push(u._initReady().catch(i))}var c=o.forages.slice(0);return t._ready=Promise.all(a).then((function(){return r.db=o.db,U(r)})).then((function(e){return r.db=e,F(r,t._defaultConfig.version)?V(r):e})).then((function(e){r.db=o.db=e,t._dbInfo=r;for(var n=0;n<c.length;n++){var a=c[n];a!==t&&(a._dbInfo.db=r.db,a._dbInfo.version=r.version)}})),t._ready}},{key:"probeSupport",get:function(){return function(){try{if(null==D||!D.open)return!1;var e=/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return(!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(r){return!1}}()}},{key:"getItem",value:function(e,t){var r=this;e=M(e);var n=new Promise((function(t,n){r.ready().then((function(){G(r._dbInfo,A,(function(o,a){if(o)return n(o);try{var i=a.objectStore(r._dbInfo.storeName).get(e);i.onsuccess=function(){var e=i.result;void 0===e&&(e=null),t(e)},i.onerror=function(){n(i.error)}}catch(s){n(s)}}))})).catch(n)}));return K(n,t),n}},{key:"setItem",value:function(e,t,r){var n=this;e=M(e);var o=new Promise((function(r,o){n.ready().then((function(){return n._dbInfo,t})).then((function(t){G(n._dbInfo,B,(function(a,i){if(a)return o(a);try{var s=i.objectStore(n._dbInfo.storeName);null===t&&(t=void 0);var u=s.put(t,e);i.oncomplete=function(){void 0===t&&(t=null),r(t)},i.onabort=i.onerror=function(){var e=u.error?u.error:u.transaction.error;o(e)}}catch(c){o(c)}}))})).catch(o)}));return K(o,r),o}},{key:"removeItem",value:function(e,t){var r=this;e=M(e);var n=new Promise((function(t,n){r.ready().then((function(){G(r._dbInfo,B,(function(o,a){if(o)return n(o);try{var i=a.objectStore(r._dbInfo.storeName).delete(e);a.oncomplete=function(){t()},a.onerror=function(){n(i.error)},a.onabort=function(){var e=i.error?i.error:i.transaction.error;n(e)}}catch(s){n(s)}}))})).catch(n)}));return K(n,t),n}},{key:"clear",value:function(e){var t=this,r=new Promise((function(e,r){t.ready().then((function(){G(t._dbInfo,B,(function(n,o){if(n)return r(n);try{var a=o.objectStore(t._dbInfo.storeName).clear();o.oncomplete=function(){e()},o.onabort=o.onerror=function(){var e=a.error?a.error:a.transaction.error;r(e)}}catch(i){r(i)}}))})).catch(r)}));return K(r,e),r}},{key:"length",value:function(e){var t=this,r=new Promise((function(e,r){t.ready().then((function(){G(t._dbInfo,A,(function(n,o){if(n)return r(n);try{var a=o.objectStore(t._dbInfo.storeName).count();a.onsuccess=function(){e(a.result)},a.onerror=function(){r(a.error)}}catch(i){r(i)}}))})).catch(r)}));return K(r,e),r}},{key:"all",value:function(e){var t=this,r=new Promise((function(e,r){t.ready().then((function(){G(t._dbInfo,A,(function(n,o){if(n)return r(n);try{var a=o.objectStore(t._dbInfo.storeName).openCursor(),i=[];a.onsuccess=function(){var t=a.result;t?(i.push({key:t.key,value:t.value}),t.continue()):e(i)},a.onerror=function(){r(a.error)}}catch(s){r(s)}}))})).catch(r)}));return K(r,e),r}},{key:"_fullyReady",value:function(e){var t=this,r=t._initReady().then((function(){var e=q[t._dbInfo.name];if(null!=e&&e.dbReady)return e.dbReady}));return function(e,t,r){"function"==typeof t&&e.then(t),"function"==typeof r&&e.catch(r)}(r,e,e),r}}]),e}(),z=function(){function e(){c(this,e)}return f(e,[{key:"_initStorage",value:function(e){var t=e.name,r=e.storeName,n="".concat(t,"_").concat(r);return this.key=n,window[n]&&"object"===i(window[n])||(window[n]={}),this.store=window[n],Promise.resolve()}},{key:"getItem",value:function(e,t){var r=this.store[e];return void 0===r&&(r=null),this._internalPromise(t,r)}},{key:"setItem",value:function(e,t,r){return this.store[e]=t,this._internalPromise(r)}},{key:"removeItem",value:function(e,t){return delete this.store[e],this._internalPromise(t)}},{key:"clear",value:function(e){return this.store={},window[this.key]={},this._internalPromise(e)}},{key:"length",value:function(e){var t=Object.keys(this.store).length;return this._internalPromise(e,t)}},{key:"_internalPromise",value:function(e,t){var r=t?Promise.resolve(t):Promise.resolve();return K(r,e),r}},{key:"all",value:function(e){for(var t=[],r=Object.keys(this.store),n=0;n<r.length;n++){var o=r[n];t.push({key:o,value:this.store[o]})}return this._internalPromise(e,t)}},{key:"probeSupport",value:function(){return!0}}]),e}(),X={description:"",name:"__PRE_CACHE__",storeName:"keyvaluepairs",version:1},$="__PRE_CACHE__KEYS",Z=function(){function e(t,n){c(this,e),this._allCachedKeyMap={},this._memory=0,this._cnt=0;var o=n===r.MEMORY?z:H;this._driver=new o,this._driver._initStorage(X).catch((function(){})),this._hasIdbForbidden=!1,this._maxCache=!t||t<=0?200:t,this.setMaxCache(this._maxCache),this._allCachedKeys={},this._allCachedTimeKeys={},this.getCachedKeysFromLocal(),this._readyPromise=new E,this.init()}var t;return f(e,[{key:"getCachedKeysFromLocal",value:function(){var e=T.getItem($);if(e)for(var t=e.split("|"),r=0;r<t.length;r++){var n=t[r],o=this._getCacheKeyInfos(n),a=o.time,i=o.cachedKey;this._allCachedKeys[i]=1,this._allCachedTimeKeys[i]=a}}},{key:"_getCacheKeyInfos",value:function(e){var t,r=e.split("$");return 2===r.length&&(t=r[0],e=r[1]),{time:t,cachedKey:e}}},{key:"writeCachedKeysToLocal",value:function(e){var t=[];this._allCachedKeys={},this._allCachedTimeKeys={};for(var r=0;r<e.length;r++){var n=e[r].key,o=this._getCacheKeyInfos(n),a=o.time,i=o.cachedKey;this._allCachedKeys[i]=1,this._allCachedTimeKeys[i]=a,t.push(n)}var s=t.join("|");T.setItem($,s)}},{key:"init",value:function(){var e=this;this._driver.setItem("test","test").then((function(){})).catch((function(){e._hasIdbForbidden=!0})).finally((function(){e._driver.removeItem("test").catch((function(){})),e._hasIdbForbidden&&(e._driver=new z,e._driver._initStorage(X)),e._getAll(),e._readyPromise.resolve()}))}},{key:"_getAll",value:function(){var e=this;this._memory=0,this._cnt=0,this._driver.all().then((function(t){e._cachedLength=t.length;var r=t.length-e._maxCache,n=t;if(r>0){var o=t.slice(0,r);n=t.slice(r);for(var a=0;a<o.length;a++)e.removeItem(o[a].key).then((function(){}))}e._cnt=n.length;for(var s=0;s<n.length;s++){var u=n[s];if("object"===i(u.value)){Object.values(u.value).forEach((function(t){e._memory+=(null==t?void 0:t.memory)||0}));var c=e._getCacheKeyInfos(u.key).cachedKey;e._allCachedKeyMap[c]=Object.keys(u.value)}}e.writeCachedKeysToLocal(n)})).catch((function(){}))}},{key:"getAllCachedDataKeys",value:function(){var e=[];return Object.values(this._allCachedKeyMap).forEach((function(t){e.push.apply(e,_(t))})),e}},{key:"getItem",value:(t=u(a().mark((function e(t,r,n){var o,i,s,u,c;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if((o=this.hasItem(t))&&n&&(i=this._allCachedKeyMap[t],o=(null==i?void 0:i.includes(n))||!1),o){e.next=4;break}return e.abrupt("return",Promise.resolve(!1));case 4:return s=this._getTimeKey(t),u=s.timeKey,e.next=7,this._driver.getItem(u,r);case 7:if(c=e.sent,!n){e.next=10;break}return e.abrupt("return",c[n]);case 10:return e.abrupt("return",c);case 11:case"end":return e.stop()}}),e,this)}))),function(e,r,n){return t.apply(this,arguments)})},{key:"setItem",value:function(e,t,r){var n=this;this._getTimeKey(e).timeKey&&this.removeItem(e);var o=(new Date).getTime();this._allCachedKeys[e]=1,this._allCachedTimeKeys[e]=o;var a=this._genTimeKey(e,o);return r=r?function(){n._getAll(),r()}:function(){n._getAll()},this._driver.setItem(a,t,r)}},{key:"_getTimeKey",value:function(e){var t=this._allCachedTimeKeys[e],r=e;return t&&(r=this._genTimeKey(e,t)),{timeKey:r,time:t}}},{key:"_genTimeKey",value:function(e,t){return"".concat(t).concat("$").concat(e)}},{key:"removeItem",value:function(e,t){var r=this._getTimeKey(e).timeKey,n=this._driver.removeItem(r,t);return delete this._allCachedKeys[e],delete this._allCachedTimeKeys[e],delete this._allCachedKeyMap[e],n}},{key:"hasItem",value:function(e){return!!this._allCachedKeys[e]}},{key:"clear",value:function(e){return this._driver.clear(e)}},{key:"length",value:function(e){return this._driver.length(e)}},{key:"setMaxCache",value:function(e){"number"==typeof e&&e>0&&(this._maxCache=e)}},{key:"getMemoryInfo",value:function(){return{memory:this._memory,cnt:this._cnt}}}]),e}(),J=Z,Q=0,W=function(){function e(t){var r=this;c(this,e),this._preload_bandwith_map=new Map,this._usepreload_info=new Map,this._pcdn_info_map=new Map,this._updateRealTimeSpeed=function(e){Q=e.speed,r.emit("real_time_speed",e)},this._manager=t}return f(e,[{key:"setPreloadBandwidth",value:function(e,t){this._preload_bandwith_map.set(e,t)}},{key:"getPreloadBandwidth",value:function(e){return this._preload_bandwith_map.get(e)}},{key:"_updateLoadInfo",value:function(e,t,r){var n=this._pcdn_info_map.get(e);!n&&(n={}),n[t]||(n[t]={},n[t].loadLen=0),n[t].loadLen=n[t].loadLen+r,this._pcdn_info_map.set(e,n)}},{key:"getLoadInfoAndDelete",value:function(e){var t=this._pcdn_info_map.get(e);return this._pcdn_info_map.delete(e),t}},{key:"getPreloadUnuseInfo",value:function(){var e,t={},r=w(this._preload_bandwith_map);try{for(r.s();!(e=r.n()).done;){var n=g(e.value,2),o=n[0],a=n[1];if(this._usepreload_info.get(o))this._preload_bandwith_map.delete(o);else{var i=o.split("#"),s=i.length>0?i[0]:o;t[s]?(t[s].bw+=a.bw||0,t[s].pbw+=a.pbw||0):t[s]={vid:s,bw:a.bw||0,pbw:a.pbw||0,bitrate:a.bitrate||0,duration:a.duration||0}}}}catch(u){r.e(u)}finally{r.f()}return Object.values(t)}},{key:"bwEventEmit",value:function(e){var t=e.vid,r=e.loadType,n=e.size,o=e.speed,a=e.cacheKey,i=e.vtype,s=e.duration,u=e.bitrate,c=this.getPreloadBandwidth(a)||{bw:0,pbw:0,vid:t,duration:s,bitrate:u};r&&r!==S?(c.pbw=c.pbw+n,this.emit("prf_data_size",{vid:t,task_type:2,pcdn_size:n,pcdn_speed:o,vtype:i,bitrate:u,duration:s})):(c.bw=c.bw+n,this.emit("prf_data_size",{vid:t,task_type:2,cdn_size:n,cdn_speed:o,vtype:i,duration:s,bitrate:u})),this.setPreloadBandwidth(a,c),this._updateRealTimeSpeed({speed:o,type:r||S}),this._updateLoadInfo(a,r,n)}},{key:"setUsePreloadInfo",value:function(e,t){this._usepreload_info.set(e,t)}},{key:"realTimeSpeed",get:function(){return Q}},{key:"emit",value:function(e,t){var r;null===(r=this._manager)||void 0===r||r.emit(e,t)}},{key:"destroy",value:function(){this._preload_bandwith_map=new Map,this._usepreload_info=new Map,this._pcdn_info_map=new Map,this._manager=null}}]),e}();function ee(e,t){var r=[0,0];if(e)for(var n=0,o=e.length;n<o&&(r[0]=e.start(n),r[1]=e.end(n),!(r[0]<=t&&t<=r[1]));n++);return r[0]-t<=0&&t-r[1]<=0?r:[0,0]}function te(e,t,r){for(var n=0;n<e.length;n++)if(r===e[n][t])return n;return-1}var re={PRELOAD_TIME:"PRELOAD_TIME"},ne=!1,oe="PRELOAD_NEXT",ae=function(e){h(g,e);var t,n,i,s,l,v,p=m(g);function g(){var e;return c(this,g),(e=p.call(this))._loaders={},e._loaderInsts={},e._taskIntervalId=0,e._currentPreloadInst=null,e._preloadDataList=[],e._player=null,e._stepwise=!1,e._playingVids=[],e._isOpen=!0,e._userDefinition=null,e._startDefinition=null,e.onPreloadNext=u(a().mark((function t(){var r,n,o,i,s,u,c,l,f,d,h,v,p,m;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(o=y(e),i=o._preloadDataList,s=o._config,!(!e._isOpen||e._currentPreloadInst||e._preloadDataList.length<1)){t.next=3;break}return t.abrupt("return",!1);case 3:if(u=e.findPreloadItem(i,!1),c=null==u?void 0:u.data,u&&null!=c&&c.payload){t.next=7;break}return t.abrupt("return",!1);case 7:if(null,l=e.selectBeforeStart(c),e._filterMixPayload(c,l),e.setStartDefinition(null===(r=l)||void 0===r?void 0:r.definition),e.log("log","selectBeforeStart",null===(n=l)||void 0===n?void 0:n.vtype,l),f=e._getPreloaderKey(l||c)){t.next=17;break}return e.log("warn","need to set vtype, no preloader",c),s.autoPreload&&e.emit(oe),t.abrupt("return",!1);case 17:if(d=e._getLoaderInst(f)){t.next=23;break}if(h=e._getLoader(f)){t.next=22;break}return t.abrupt("return",!1);case 22:d=new h(y(e),e._config);case 23:return e._currentPreloadInst=d,e._currentPreloadInst.setData(c),t.prev=25,e.log("log","loaderInst.start",f,e.getStartDefinition(),c),t.next=29,d.start(c,e.getStartDefinition());case 29:(v=t.sent)&&v.remove&&(p=i.indexOf(u))>-1&&i.splice(p,1),t.next=36;break;case 33:t.prev=33,t.t0=t.catch(25),e.log("error","preload data error!",t.t0);case 36:return t.prev=36,null===(m=e._currentPreloadInst)||void 0===m||m.setData(null),e._currentPreloadInst=null,e._config.autoPreload&&e.emit(oe),t.finish(36);case 41:return t.abrupt("return",!0);case 42:case"end":return t.stop()}}),t,null,[[25,33,36,41]])}))),e._stats=new W(y(e)),e}return f(g,[{key:"getPreloadMetaByVid",value:function(e){for(var t=this.getAllCachedDataKeys(),r=[],n="",o=0;o<t.length;o++){var a=t[o],i=g.parseKey(a);i.vid===e&&(n=i.vtype,r.push(a))}if(0===r.length)return null;var s=this._getLoaderInst(n);return s?s.parseKey(r):null}},{key:"VTYPES",get:function(){return C}},{key:"log",value:function(e){for(var t,r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];ne&&(t=console)[e].apply(t,["[PreloaderManager]"].concat(n))}},{key:"register",value:function(e){try{if("undefined"==typeof window)return void this.log("preloader shoud use in window env");var t=g.getDefaultConfig();this._config=Object.assign({},t,e.config),this._options=e;var r=this._config,n=r.preloadMaxCacheCount,o=r.preloadCacheType;this._stepwise=!!this._config.stepwise,this._cacheInst=new J(n,o),this._selector=e.BitrateSelector,this.on(oe,this.onPreloadNext);for(var a=e.loaders,i=0;i<a.length;i++)this.registerLoader(a[i].vtype,a[i])}catch(s){this.log("register error",s)}}},{key:"registerLoader",value:function(e,t){e&&(this._loaders[e]&&this.log("warn","vtype:".concat(e," Preloader already exist")),this._loaders[e]=t,this._loaderInsts[e]=new t(this,this._config))}},{key:"_checkIfCanPreload",value:function(){if(null===this._currentPreloadInst&&this._preloadDataList.length>0){var e=this.findPreloadItem(this._preloadDataList),t=null==e?void 0:e.data;if(e&&null!=t&&t.payload){if(!this._getPreloaderKey(t))return this.log("warn","need to set vtype"),this.stopCheckTask(),!1;var r=this._config.checkIfCanPreload;return r&&"function"==typeof r?r(t):this._config.autoCheckPreload?this._autoCheckPreload(t,e):(this.stopCheckTask(),!1)}}return!1}},{key:"_autoCheckPreload",value:function(e,t){if(!this._media)return this.log("warn","need set video"),!1;var r=function(e,t,r){if(!e)return!1;var n=ee(e.buffered,e.currentTime),o=t.startPreloadControl,a=t.startPreloadMinBuffer,i=t.startPreloadMinPosTime,s=t.minBufferLength;if(o){var u=Math.max(n[1]-e.currentTime,0);if(u>a){if(e.currentTime>i||e.currentTime>e.duration/2)return null==r||r("log","[checkIfCanPreload] hit buffer",u,"startPreloadMinBuffer",a),!0}else if(e.currentTime+a+1>e.duration&&e.currentTime+u>e.duration-1)return null==r||r("log","[checkIfCanPreload] hit end"),!0}else{var c=e.duration>s+5?s:e.duration/2,l=Math.min(e.currentTime+s,e.duration),f=n[1]-l;if(e.currentTime>c&&f>-1)return null==r||r("log","[checkIfCanPreload] hit minPos",c,"minCacheTime",l),!0}return!1}(this._media,this._config,this.log),n=this._player;if(r&&n){var o=n.config.vid,a=this._config,i=a.minBufferLength,s=a.startPreloadControl,u=a.startPreloadMinBuffer,c=a.startPreloadMinPosTime,l=ee(n.video.buffered,n.currentTime),f=l[1]?l[1]-n.currentTime:0;this.emit(re.PRELOAD_TIME,{vid:o,pid:e.vid,buffer:l,currentTime:n.currentTime,minBufferLength:i,startPreloadControl:s,startPreloadMinBuffer:u,startPreloadMinPosTime:c,bufferHead:f})}return r}},{key:"_getPreloaderKey",value:function(e){return e.vtype?e.vtype.toUpperCase():""}},{key:"_sort",value:function(e){e.sort((function(e,t){return void 0===e.order&&void 0===t.order||"number"==typeof e.order&&"number"==typeof t.order&&e.order<t.order?-1:1}))}},{key:"_addPlayingVid",value:function(e,t){var r=this._playingVids,n=te(this._playingVids,"playerId",e);n>-1?r[n].vid=t:r.push({vid:t,playerId:e})}},{key:"selectBeforeStart",value:function(e){var t=e.targetDefinition,r=e.defaultDefinition;if(t)return o({},t);var n=this.getUserSelectDefinition(),a=this.selectBitrate(null==e?void 0:e.payload,r,n),i=(null==a?void 0:a.vtype)||e.vtype,s=o(o({},a),{},{vtype:i});return e.targetDefinition=s,this.log("log","selectBeforeStart",null==e?void 0:e.vid,i,null==a?void 0:a.definition,null==e?void 0:e.payload,a),s}},{key:"selectBitrate",value:function(e,t,r){if(e.length<1)return null;var n=null;if(this._selector){var a,i,s;n=this._selector.getSuitableBitrate(e,r),this.log("log","BitRateAdapter result",null===(a=n)||void 0===a?void 0:a.vtype,null===(i=n)||void 0===i?void 0:i.definition,null===(s=n)||void 0===s?void 0:s.bitrate)}else{for(var u=-1,c=-1,l=0;l<e.length;l++){var f=e[l];r&&f.definition===r?u=l:t&&f.definition===t&&(c=l)}n=e[u>=0?u:c>=0?c:0]}return o({},n)}},{key:"startCheckTask",value:function(){var e=this,t=this._preloadDataList,r=this._config.autoCheck;(this._taskIntervalId&&(window.clearTimeout(this._taskIntervalId),this._taskIntervalId=0),0!==t.length)&&(this._checkIfCanPreload()&&this.onPreloadNext(),this._taskIntervalId=window.setTimeout((function(){e.startCheckTask()}),r.interval))}},{key:"stopCheckTask",value:function(){this._taskIntervalId&&(window.clearTimeout(this._taskIntervalId),this._taskIntervalId=-1)}},{key:"preloadNext",value:function(){this.onPreloadNext()}},{key:"_filterMixPayload",value:function(e,t){var r=t.vtype;if(r&&Array.isArray(e.payload)){var n=e.vtype===r;e.vtype=r,e.payload=e.payload.filter((function(e){return e.vtype===r||n}))}}},{key:"addPreloadList",value:(v=u(a().mark((function e(t){var r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this._sort(t),r=w(t),e.prev=2,r.s();case 4:if((n=r.n()).done){e.next=10;break}return o=n.value,e.next=8,this._addData(o);case 8:e.next=4;break;case 10:e.next=15;break;case 12:e.prev=12,e.t0=e.catch(2),r.e(e.t0);case 15:return e.prev=15,r.f(),e.finish(15);case 18:this._checkAutoTask();case 19:case"end":return e.stop()}}),e,this,[[2,12,15,18]])}))),function(e){return v.apply(this,arguments)})},{key:"addPlayingId",value:function(e,t){for(var r=this._preloadDataList,n=-1,o=0;o<r.length;o++){if(e===r[o].data.vid){n=o;break}}if(n>-1){var a=r.splice(n,1);this.log("log","cancelPreloadByVid remove from list",a.length>0&&a[0].data.vid)}var i=this._currentPreloadInst,s=i?i.getData():null;this.log("log","_currentPreloadInst",s),s&&s.vid===e&&this.cancel(),t&&this._addPlayingVid(t,e)}},{key:"removePlayingId",value:function(e){var t=this._playingVids,r=te(t,"playerId",e);if(r>-1){var n=t.splice(r,1);this.log("log","removePlayingId",n.length>0&&n[0].playerId)}}},{key:"addPreload",value:(l=u(a().mark((function e(t){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._addData(t);case 2:if(e.sent){e.next=5;break}return e.abrupt("return");case 5:this._sort(this._preloadDataList),this._checkAutoTask();case 7:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"_addData",value:(s=u(a().mark((function e(t){var r,n,o,i,s,u,c,l,f,d=this;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t.data.vtype){e.next=3;break}return this.log("warn","vtype is null, can·t select loader"),e.abrupt("return",!1);case 3:if(r=t.data,n=this._getLoader(r.vtype)){e.next=8;break}return this.log("warn","the loader for ".concat(r.vtype," not registered")),e.abrupt("return",!1);case 8:if(o=this._playingVids,!((i=te(o,"vid",t.data.vid))>=0)){e.next=14;break}return s=o[i],this.log("log","vid:".concat(s.vid," is already instantiated and loaded, playerId is ").concat(s.playerId)),e.abrupt("return");case 14:return u=this._getUniqueKey(t),e.next=17,this.getItem(t.data,!0);case 17:if(!(c=e.sent)){e.next=22;break}if(!n.isUniqueCache(c)){e.next=22;break}return this.log("log","".concat(u," already exist in cache")),e.abrupt("return",!1);case 22:if(!this._currentPreloadInst){e.next=29;break}if(!(l=this._currentPreloadInst.getData())){e.next=29;break}if(this._getUniqueKey({data:l,order:0})!==u){e.next=29;break}return this.log("log","currentKey repeat"),e.abrupt("return");case 29:if(f=this._preloadDataList.filter((function(e){return d._getUniqueKey(e)===u})),this.log("log","addedItems",u,f),0!==f.length){e.next=35;break}return this._stepwise&&"undefined"===t.data.steps&&(t.data.steps=[0]),this._preloadDataList.push(t),e.abrupt("return",!0);case 35:return this.log("log","".concat(u," already exist in preloadList")),e.abrupt("return",!1);case 37:case"end":return e.stop()}}),e,this)}))),function(e){return s.apply(this,arguments)})},{key:"_getUniqueKey",value:function(e){return e.data.vtype?g.generateUniqueCacheKey(e.data):e.data.vid}},{key:"_checkAutoTask",value:function(){var e=this,t=this._config,r=t.autoCheck,n=t.autoPreload;Promise.resolve().then((function(){n&&e.emit(oe),r.enable&&!e._taskIntervalId&&e.startCheckTask()}))}},{key:"setItem",value:function(e,t,r,n){var o=g.generateUniqueCacheKey(e);if(!r){var a=this._getLoader(e.vtype);if(!a)return this.log("warn","no ".concat(e.vtype," preloader, register")),Promise.resolve(!1);t=d({},a.generateUniqueKey(e),t)}return this._cacheInst.setItem(o,t,n)}},{key:"getItem",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=g.generateUniqueCacheKey(e),o=this._getLoader(e.vtype);if(!o)return this.log("warn","no ".concat(e.vtype," preloader, register")),Promise.resolve(!1);var a=t?"":o.generateUniqueKey(e);return this._cacheInst.getItem(n,r,a)}},{key:"removeItem",value:function(e,t){var r=g.generateUniqueCacheKey(e);return this._cacheInst.removeItem(r,t)}},{key:"getPreLoadData",value:(i=u(a().mark((function e(t){var r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.vtype,!(n=this._getLoaderInst(r))){e.next=7;break}return e.next=5,n.getPreLoadData(t);case 5:return o=e.sent,e.abrupt("return",o);case 7:return e.abrupt("return",null);case 8:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"removeAll",value:function(){var e=this;this.getAllCachedDataKeys().forEach((function(t){var r=e.getPreloadMetaByVid(t.split("#")[0]);r&&e.removeItem(r,null)}))}},{key:"removeAllPreloadTask",value:function(){this.cancel(),this._preloadDataList=[],this._playingVids=[]}},{key:"disable",value:function(){this._isOpen=!1,this.stopCheckTask()}},{key:"enable",value:function(){this._isOpen=!0,this._config.autoCheck.enable&&!this._taskIntervalId&&this._preloadDataList.length>0&&this.startCheckTask()}},{key:"setUserSelectDefinition",value:function(e){this._userDefinition=e}},{key:"getUserSelectDefinition",value:function(){return this._userDefinition||null}},{key:"getStartDefinition",value:function(){return this._startDefinition}},{key:"setStartDefinition",value:function(e){this._startDefinition=e}},{key:"destroy",value:(n=u(a().mark((function e(){var t,r,n,o;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:this._stats.destroy(),t=Object.keys(this._loaderInsts),r=0;case 3:if(!(r<t.length)){e.next=13;break}if(n=t[r],o=this._getLoaderInst(n),e.t0=o,!e.t0){e.next=10;break}return e.next=10,o.destroy();case 10:r++,e.next=3;break;case 13:this.removeAllListeners(),this._loaderInsts={},this._loaders={},this._playingVids=[],this.detachPlayer();case 18:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})},{key:"cancel",value:(t=u(a().mark((function e(){var t;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this._currentPreloadInst){e.next=4;break}return e.next=3,this._currentPreloadInst.cancel();case 3:null===(t=this._currentPreloadInst)||void 0===t||t.setData(null);case 4:this._currentPreloadInst=null;case 5:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})},{key:"removeByPlayInst",value:function(e,t){for(var r=this._preloadDataList.length-1;r>-1;r--){var n=this._preloadDataList[r];if(n.data.vid===e&&n.playerId===t){this._preloadDataList.splice(r,1);break}}}},{key:"getAllCachedDataKeys",value:function(){return this._cacheInst.getAllCachedDataKeys()}},{key:"getDataUniqueKey",value:function(e){var t=this._getLoader(e.vtype);return!!t&&t.generateUniqueKey(e)}},{key:"hasItemSameVid",value:function(e){var t=this._getLoader(e.vtype),r=this._getLoaderInst(e.vtype);if(t&&r){var n=t.generateUniqueKey(e);return r.hasItemSameVid(n)}return!1}},{key:"_getLoader",value:function(e){e=e||"";var t=this._loaders[e]||this._loaders[e.toLocaleLowerCase()];return t||(this.log("warn","no ".concat(e," preloader, register")),null)}},{key:"_getLoaderInst",value:function(e){e=e||"";var t=this._loaderInsts[e]||this._loaderInsts[e.toLocaleLowerCase()];return t||(this.log("warn","no ".concat(e," preloader, register")),null)}},{key:"currentPreloadInst",get:function(){return this._currentPreloadInst}},{key:"preloadDataList",get:function(){return this._preloadDataList}},{key:"getPreloadMemoryInfo",value:function(){return this._cacheInst.getMemoryInfo()}},{key:"attachPlayer",value:function(e){this._player=e,this._media=e.video||e.media}},{key:"detachPlayer",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e&&this._player!==e||(this._player=null,this._media=null)}},{key:"player",get:function(){return this._player}},{key:"setPreloadBandwidth",value:function(e,t){this._stats.setPreloadBandwidth(e,t)}},{key:"getPreloadBandwidth",value:function(e){return this._stats.getPreloadBandwidth(e)}},{key:"getLoadInfoAndDelete",value:function(e){return this._stats.getLoadInfoAndDelete(e)}},{key:"getPreloadUnuseInfo",value:function(){return this._stats.getPreloadUnuseInfo()}},{key:"setUsePreloadInfo",value:function(e,t){this._stats.setUsePreloadInfo(e,t)}},{key:"bwEventEmit",value:function(e){var t=e.vid,r=e.loadType,n=e.size,o=e.speed,a=e.cacheKey,i=e.vtype,s=e.duration,u=e.bitrate;this._stats.bwEventEmit({vid:t,loadType:r,size:n,speed:o,cacheKey:a,vtype:i,duration:s,bitrate:u})}},{key:"stepwise",get:function(){return this._stepwise}},{key:"findPreloadItem",value:function(e){var t,r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(this._stepwise){var n=e.reduce((function(e,t){return void 0===t.data.stepIdx||"number"==typeof t.data.stepIdx&&"number"==typeof e.data.stepIdx&&t.data.stepIdx<e.data.stepIdx?t:e})),o=e.filter((function(e){return e.data.stepIdx===n.data.stepIdx}));if(o.length>1&&this._sort(o),t=o[0],!r){if("number"!=typeof t.data.stepIdx&&(t.data.stepIdx=-1),t.data.stepIdx++,Array.isArray(t.data.steps)&&t.data.stepIdx>=t.data.steps.length-1){var a=e.indexOf(t);e.splice(a,1)}t.data.stepIdx===1/0&&(t=void 0)}}else t=r?e[0]:e.shift();return t}},{key:"realTimeSpeed",get:function(){return this._stats.realTimeSpeed}},{key:"updateConfig",value:function(e){Object.assign(this._config,e);var t=this._config.autoCheck;t&&!t.enable&&this.stopCheckTask(),t&&t.enable&&this.startCheckTask()}}],[{key:"getDefaultConfig",value:function(){return{autoPreload:!1,autoCheck:{enable:!1,interval:1e3},preloadMaxCacheCount:5,preloadCacheType:r.MEMORY,autoCheckPreload:!0,startPreloadControl:!1,startPreloadMinBuffer:5,startPreloadMinPosTime:5,minBufferLength:5}}},{key:"generateUniqueCacheKey",value:function(e){var t=e.vid,r=e.codecType,n=e.vtype;return"".concat(t,"#").concat(r,"#").concat(n.toUpperCase())}},{key:"parseKey",value:function(e){if(!e)throw new Error("key ".concat(e," is empty"));var t=e.split("#");if(t.length<5)throw new Error("key ".concat(e," is not right format"));return{vid:t[0],mediaType:t[1],codecType:t[2],vtype:t[3],definition:t[4]}}},{key:"debugger",set:function(e){ne=e}}]),g}(x),ie=function(e){h(s,e);var t,r,n,o,i=m(s);function s(e,t){var r;return c(this,s),(r=i.call(this))._data=null,r._preloadManager=e,r._config=t,r.promisePolyfill(),r}return f(s,[{key:"getRequestOption",value:function(e){var t=this._config,r=t.getRequestOptionsCallback,n=t.reqOptions,o={};return e?o=e.reqOptions?e.reqOptions:"function"==typeof r?r(e):n||{}:o}},{key:"getUserSelectDefinition",value:function(){return this._preloadManager.getUserSelectDefinition()}},{key:"selectBitrate",value:function(e,t,r){return this._preloadManager.selectBitrate(e,t,r)}},{key:"promisePolyfill",value:function(){Promise.prototype.finally||(Promise.prototype.finally={finally:function(e){var t=function(t){return Promise.resolve(e()).then(t)};return this.then((function(e){return t((function(){return e}))}),(function(e){return t((function(){return Promise.reject(e)}))}))}}.finally)}},{key:"preloadManager",get:function(){return this._preloadManager}},{key:"getData",value:function(){return this._data}},{key:"setData",value:function(e){this._data=e}},{key:"start",value:(o=u(a().mark((function e(t,r){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("start need implment, return Promise");case 1:case"end":return e.stop()}}),e)}))),function(e,t){return o.apply(this,arguments)})},{key:"cancel",value:(n=u(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("cancel need implment, cancel current preload request");case 1:case"end":return e.stop()}}),e)}))),function(){return n.apply(this,arguments)})},{key:"getPreLoadData",value:(r=u(a().mark((function e(t){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error("getPreLoadData not implement");case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})},{key:"hasItemSameVid",value:function(e){return!0}},{key:"destroy",value:(t=u(a().mark((function e(){return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Promise.resolve());case 1:case"end":return e.stop()}}),e)}))),function(){return t.apply(this,arguments)})},{key:"stepwise",get:function(){return this._preloadManager.stepwise}},{key:"parseKey",value:function(e){return ae.parseKey(e[0])}}],[{key:"generateUniqueKey",value:function(e){throw new Error("generateUniqueCacheKey need implement, return string")}},{key:"vtype",get:function(){throw new Error("need vtype")}},{key:"isUniqueCache",value:function(e){return!0}}]),s}(x);e.CACHE_TYPES=r,e.PRELOAD_EVENTS=re,e.PRELOAD_TYPES=t,e.PreloaderBase=ie,e.PreloaderManager=ae}));
@@ -0,0 +1,2 @@
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).StreamProbe={})}(this,(function(e){"use strict";function r(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function t(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(r){f(e,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))}))}return e}function n(){n=function(){return e};var e={},r=Object.prototype,t=r.hasOwnProperty,a=Object.defineProperty||function(e,r,t){e[r]=t.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",s=i.asyncIterator||"@@asyncIterator",u=i.toStringTag||"@@toStringTag";function d(e,r,t){return Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}),e[r]}try{d({},"")}catch(E){d=function(e,r,t){return e[r]=t}}function f(e,r,t,n){var i=r&&r.prototype instanceof p?r:p,o=Object.create(i.prototype),s=new U(n||[]);return a(o,"_invoke",{value:S(e,t,s)}),o}function c(e,r,t){try{return{type:"normal",arg:e.call(r,t)}}catch(E){return{type:"throw",arg:E}}}e.wrap=f;var l={};function p(){}function v(){}function h(){}var y={};d(y,o,(function(){return this}));var m=Object.getPrototypeOf,b=m&&m(m(A([])));b&&b!==r&&t.call(b,o)&&(y=b);var w=h.prototype=p.prototype=Object.create(y);function g(e){["next","throw","return"].forEach((function(r){d(e,r,(function(e){return this._invoke(r,e)}))}))}function k(e,r){function n(a,i,o,s){var u=c(e[a],e,i);if("throw"!==u.type){var d=u.arg,f=d.value;return f&&"object"==typeof f&&t.call(f,"__await")?r.resolve(f.__await).then((function(e){n("next",e,o,s)}),(function(e){n("throw",e,o,s)})):r.resolve(f).then((function(e){d.value=e,o(d)}),(function(e){return n("throw",e,o,s)}))}s(u.arg)}var i;a(this,"_invoke",{value:function(e,t){function a(){return new r((function(r,a){n(e,t,r,a)}))}return i=i?i.then(a,a):a()}})}function S(e,r,t){var n="suspendedStart";return function(a,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw i;return{value:void 0,done:!0}}for(t.method=a,t.arg=i;;){var o=t.delegate;if(o){var s=_(o,t);if(s){if(s===l)continue;return s}}if("next"===t.method)t.sent=t._sent=t.arg;else if("throw"===t.method){if("suspendedStart"===n)throw n="completed",t.arg;t.dispatchException(t.arg)}else"return"===t.method&&t.abrupt("return",t.arg);n="executing";var u=c(e,r,t);if("normal"===u.type){if(n=t.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:t.done}}"throw"===u.type&&(n="completed",t.method="throw",t.arg=u.arg)}}}function _(e,r){var t=r.method,n=e.iterator[t];if(void 0===n)return r.delegate=null,"throw"===t&&e.iterator.return&&(r.method="return",r.arg=void 0,_(e,r),"throw"===r.method)||"return"!==t&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+t+"' method")),l;var a=c(n,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,l;var i=a.arg;return i?i.done?(r[e.resultName]=i.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}function V(e){var r={tryLoc:e[0]};1 in e&&(r.catchLoc=e[1]),2 in e&&(r.finallyLoc=e[2],r.afterLoc=e[3]),this.tryEntries.push(r)}function T(e){var r=e.completion||{};r.type="normal",delete r.arg,e.completion=r}function U(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(V,this),this.reset(!0)}function A(e){if(e){var r=e[o];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,a=function r(){for(;++n<e.length;)if(t.call(e,n))return r.value=e[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return a.next=a}}return{next:P}}function P(){return{value:void 0,done:!0}}return v.prototype=h,a(w,"constructor",{value:h,configurable:!0}),a(h,"constructor",{value:v,configurable:!0}),v.displayName=d(h,u,"GeneratorFunction"),e.isGeneratorFunction=function(e){var r="function"==typeof e&&e.constructor;return!!r&&(r===v||"GeneratorFunction"===(r.displayName||r.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,h):(e.__proto__=h,d(e,u,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},g(k.prototype),d(k.prototype,s,(function(){return this})),e.AsyncIterator=k,e.async=function(r,t,n,a,i){void 0===i&&(i=Promise);var o=new k(f(r,t,n,a),i);return e.isGeneratorFunction(t)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},g(w),d(w,u,"Generator"),d(w,o,(function(){return this})),d(w,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var r=Object(e),t=[];for(var n in r)t.push(n);return t.reverse(),function e(){for(;t.length;){var n=t.pop();if(n in r)return e.value=n,e.done=!1,e}return e.done=!0,e}},e.values=A,U.prototype={constructor:U,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(T),!e)for(var r in this)"t"===r.charAt(0)&&t.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=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 r=this;function n(t,n){return o.type="throw",o.arg=e,r.next=t,n&&(r.method="next",r.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],o=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=t.call(i,"catchLoc"),u=t.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(e,r){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&t.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var i=a;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=r,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(o)},complete:function(e,r){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&&r&&(this.next=r),l},finish:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),T(t),l}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var a=n.arg;T(t)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,t){return this.delegate={iterator:A(e),resultName:r,nextLoc:t},"next"===this.method&&(this.arg=void 0),l}},e}function a(e){return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,r,t,n,a,i,o){try{var s=e[i](o),u=s.value}catch(d){return void t(d)}s.done?r(u):Promise.resolve(u).then(n,a)}function o(e){return function(){var r=this,t=arguments;return new Promise((function(n,a){var o=e.apply(r,t);function s(e){i(o,n,a,s,u,"next",e)}function u(e){i(o,n,a,s,u,"throw",e)}s(void 0)}))}}function s(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function u(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,p(n.key),n)}}function d(e,r,t){return r&&u(e.prototype,r),t&&u(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e,r,t){return(r=p(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function c(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var t=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=t){var n,a,i,o,s=[],u=!0,d=!1;try{if(i=(t=t.call(e)).next,0===r){if(Object(t)!==t)return;u=!1}else for(;!(u=(n=i.call(t)).done)&&(s.push(n.value),s.length!==r);u=!0);}catch(f){d=!0,a=f}finally{try{if(!u&&null!=t.return&&(o=t.return(),Object(o)!==o))return}finally{if(d)throw a}}return s}}(e,r)||function(e,r){if(!e)return;if("string"==typeof e)return l(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);"Object"===t&&e.constructor&&(t=e.constructor.name);if("Map"===t||"Set"===t)return Array.from(e);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return l(e,r)}(e,r)||function(){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 l(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function p(e){var r=function(e,r){if("object"!=typeof e||null===e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}var v=function(){function e(r){if(s(this,e),f(this,"_bytesAvailable",void 0),f(this,"_bitsAvailable",0),f(this,"_word",0),!r)throw new Error("ExpGolomb data params is required");this._data=r,this._bytesAvailable=r.byteLength,this._bytesAvailable&&this._loadWord()}return d(e,[{key:"_loadWord",value:function(){var e=this._data.byteLength-this._bytesAvailable,r=Math.min(4,this._bytesAvailable);if(0===r)throw new Error("No bytes available");var t=new Uint8Array(4);t.set(this._data.subarray(e,e+r)),this._word=new DataView(t.buffer).getUint32(0),this._bitsAvailable=8*r,this._bytesAvailable-=r}},{key:"skipBits",value:function(e){if(this._bitsAvailable>e)this._word<<=e,this._bitsAvailable-=e;else{e-=this._bitsAvailable;var r=Math.floor(e/8);e-=8*r,this._bytesAvailable-=r,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 r=Math.min(this._bitsAvailable,e),t=this._word>>>32-r;return this._bitsAvailable-=r,this._bitsAvailable>0?this._word<<=r:this._bytesAvailable>0&&this._loadWord(),(r=e-r)>0&&this._bitsAvailable?t<<r|this.readBits(r):t}},{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 r=8,t=8,n=0;n<e;n++)0!==t&&(t=(r+this.readEG()+256)%256),r=0===t?r:t}},{key:"readSliceType",value:function(){return this.readUByte(),this.readUEG(),this.readUEG()}},{key:"firstMbInSlice",value:function(){return this.readUByte(),this.readUEG()}}]),e}();function h(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(e[r]<<24>>>0)+(e[r+1]<<16)+(e[r+2]<<8)+(e[r+3]||0)}var y=function(){function e(){s(this,e)}return d(e,null,[{key:"parseAnnexB",value:function(e){for(var r=e.length,t=2,n=0;null!==e[t]&&1!==e[t];)t++;if((n=++t+2)>=r)return[];for(var a=[];n<r;)switch(e[n]){case 0:if(0!==e[n-1]){n+=2;break}if(0!==e[n-2]){n++;break}t!==n-2&&a.push(e.subarray(t,n-2));do{n++}while(1!==e[n]&&n<r);n=(t=n+1)+2;break;case 1:if(0!==e[n-1]||0!==e[n-2]){n+=3;break}t!==n-2&&a.push(e.subarray(t,n-2)),n=(t=n+1)+2;break;default:n+=3}return t<r&&a.push(e.subarray(t)),a}},{key:"parseNalu",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;if(!(e.length<4)){for(var t,n=e.length,a=[],i=0;i+r<n;)if(t=h(e,i),3===r&&(t>>>=8),i+=r,t){if(i+t>n)break;a.push(e.subarray(i,i+t)),i+=t}return a}}},{key:"parseNaluType",value:function(e,r){return null==e?void 0:e.map((function(e){var t=r?e[0]>>>1&63:31&e[0],n=r&&(39===t||40===t),a={type:t,unit:e,isSei:n=n||!r&&6===t};switch(t){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!r&&5!==t||r&&5===t)break;a.frameType="I"}return r||1!==t||(a.frameType=function(e){var r=new v(e).readSliceType();return 2===r||4===r||7===r||9===r?"I":0===r||3===r||5===r||8===r?"P":1===r||6===r?"B":void 0}(e)),!r||0!==t&&1!==t||(a.frameType="P"),!r&&t<=5&&(a.firstMbInSlice=new v(e).firstMbInSlice()),r&&t<=21&&(a.firstMbInSlice=128==(128&e[2])),a}))}},{key:"parseSEI",value:function(e){for(var r=e.length,t=1,n=0,a=0,i="";255===e[t];)n+=255,t++;for(n+=e[t++];255===e[t];)a+=255,t++;if(a+=e[t++],5===n&&r>t+16)for(var o=0;o<16;o++)i+=e[t].toString(16),t++;return{payload:e.subarray(t),type:n,size:a,uuid:i}}},{key:"removeEPB",value:function(e){for(var r=e.byteLength,t=[],n=1;n<r-2;)0===e[n]&&0===e[n+1]&&3===e[n+2]?(t.push(n+2),n+=2):n++;if(!t.length)return e;var a=r-t.length,i=new Uint8Array(a),o=0;for(n=0;n<a;o++,n++)o===t[0]&&(o++,t.shift()),i[n]=e[o];return i}}]),e}(),m=function(){function e(){s(this,e)}return d(e,null,[{key:"parseAVCDecoderConfigurationRecord",value:function(r){if(!(r.length<7)){for(var t,n,a=1+(3&r[4]),i=[],o=[],s=6,u=31&r[5],d=0;d<u;d++)if(n=r[s]<<8|r[s+1],s+=2,n){var f=r.subarray(s,s+n);s+=n,i.push(f),t||(t=e.parseSPS(y.removeEPB(f)))}var c,l=r[s];s++;for(var p=0;p<l;p++)c=r[s]<<8|r[s+1],s+=2,c&&(o.push(r.subarray(s,s+c)),s+=c);return{sps:t,spsArr:i,ppsArr:o,nalUnitSize:a}}}},{key:"parseSPS",value:function(e){var r=new v(e);r.readUByte();var t=r.readUByte(),n=r.readUByte(),a=r.readUByte();r.skipUEG();var i=420;if(100===t||110===t||122===t||244===t||44===t||83===t||86===t||118===t||128===t||138===t||144===t){var o=r.readUEG();if(o<=3&&(i=[0,420,422,444][o]),3===o&&r.skipBits(1),r.skipUEG(),r.skipUEG(),r.skipBits(1),r.readBool())for(var s=3!==o?8:12,u=0;u<s;u++)r.readBool()&&(u<6?r.skipScalingList(16):r.skipScalingList(64))}r.skipUEG();var d=r.readUEG();if(0===d)r.readUEG();else if(1===d){r.skipBits(1),r.skipUEG(),r.skipUEG();for(var f=r.readUEG(),c=0;c<f;c++)r.skipUEG()}r.skipUEG(),r.skipBits(1);var l=r.readUEG(),p=r.readUEG(),h=r.readBits(1);0===h&&r.skipBits(1),r.skipBits(1);var y,m,b,w,g,k=0,S=0,_=0,V=0;if(r.readBool()&&(k=r.readUEG(),S=r.readUEG(),_=r.readUEG(),V=r.readUEG()),r.readBool()){if(r.readBool())switch(r.readUByte()){case 1:y=[1,1];break;case 2:y=[12,11];break;case 3:y=[10,11];break;case 4:y=[16,11];break;case 5:y=[40,33];break;case 6:y=[24,11];break;case 7:y=[20,11];break;case 8:y=[32,11];break;case 9:y=[80,33];break;case 10:y=[18,11];break;case 11:y=[15,11];break;case 12:y=[64,33];break;case 13:y=[160,99];break;case 14:y=[4,3];break;case 15:y=[3,2];break;case 16:y=[2,1];break;case 255:y=[r.readUByte()<<8|r.readUByte(),r.readUByte()<<8|r.readUByte()]}if(r.readBool()&&r.readBool(),r.readBool()&&(r.readBits(4),r.readBool()&&r.readBits(24)),r.readBool()&&(r.readUEG(),r.readUEG()),r.readBool()){var T=r.readBits(32),U=r.readBits(32);m=r.readBool(),g=(b=U)/(w=2*T)}}for(var A=e.subarray(1,4),P="avc1.",E=0;E<3;E++){var D=A[E].toString(16);D.length<2&&(D="0".concat(D)),P+=D}return{codec:P,profileIdc:t,profileCompatibility:n,levelIdc:a,chromaFormat:i,width:Math.ceil(16*(l+1)-2*(k+S)),height:(2-h)*(p+1)*16-(h?2:4)*(_+V),sarRatio:y,fpsNum:b,fpsDen:w,fps:g,fixedFrame:m}}}]),e}(),b=function(){function e(){s(this,e)}return d(e,null,[{key:"parseHEVCDecoderConfigurationRecord",value:function(r){if(!(r.length<23)){for(var t,n,a,i,o=1+(3&r[21]),s=[],u=[],d=[],f=23,c=r[22],l=0;l<c;l++){n=63&r[f],a=r[f+1]<<8|r[f+2],f+=3;for(var p=0;p<a;p++)if(i=r[f]<<8|r[f+1],f+=2,i){switch(n){case 32:d.push(r.subarray(f,f+i));break;case 33:var v=r.subarray(f,f+i);t||(t=e.parseSPS(y.removeEPB(v))),s.push(v);break;case 34:u.push(r.subarray(f,f+i))}f+=i}}return{sps:t,spsArr:s,ppsArr:u,vpsArr:d,nalUnitSize:o}}}},{key:"parseSPS",value:function(e){var r=new v(e);r.readUByte(),r.readUByte(),r.readBits(4);var t=r.readBits(3);r.readBits(1);var n=this._parseProfileTierLevel(r,t);r.readUEG();var a=r.readUEG(),i=420;a<=3&&(i=[0,420,422,444][a]);var o=0;3===a&&(o=r.readBits(1));var s,u,d,f,c=r.readUEG(),l=r.readUEG(),p=r.readBits(1);(1===p&&(s=r.readUEG(),u=r.readUEG(),d=r.readUEG(),f=r.readUEG()),1===p)&&(c-=(1!==a&&2!==a||0!==o?1:2)*(u+s),l-=(1===a&&0===o?2:1)*(f+d));return{codec:"hev1.1.6.L93.B0",width:c,height:l,chromaFormat:i,bitDepthLumaMinus8:r.readUEG(),bitDepthChromaMinus8:r.readUEG(),generalProfileSpace:n.generalProfileSpace,generalTierFlag:n.generalTierFlag,generalProfileIdc:n.generalProfileIdc,generalLevelIdc:n.generalLevelIdc}}},{key:"_parseProfileTierLevel",value:function(e,r){var t,n,a,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;i&&(t=e.readBits(2),n=e.readBits(1),a=e.readBits(5)),e.readBits(32),e.readBits(1),e.readBits(1),e.readBits(1),e.readBits(1),e.readBits(16),e.readBits(16),e.readBits(12);for(var o=e.readUByte(),s=[],u=[],d=0;d<r;d++)s[d]=e.readBits(1),u[d]=e.readBits(1);r>0&&e.readBits(2*(8-r));for(var f=0;f<r;f++)0!==s[f]&&(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!==u[f]&&e.readBits(8);return{generalProfileSpace:t,generalTierFlag:n,generalProfileIdc:a,generalLevelIdc:o}}}]),e}();function w(e){var r=e.reduce((function(e,r){return e+r.byteLength}),0),t=new Uint8Array(r),n=0;return e.forEach((function(e){t.set(e,n),n+=e.byteLength})),t}function g(e,r){return parseFloat(null==e?void 0:e.toFixed(r||4))}var k="ScriptData",S="Sequence_Header",_="RawData",V=[5500,11e3,22e3,44e3],T="aac",U="pcma",A="pcmu",P="avc",E="bytevc1",D=function(){function e(r){var t=this;s(this,e),f(this,"type",0),f(this,"tagSize",0),f(this,"timestamp",0),f(this,"duration",0),f(this,"header",null),f(this,"body",null),f(this,"bodyView",null),f(this,"tailsize",null),Object.keys(r).forEach((function(e){t[e]=r[e]}))}return d(e,[{key:"streamType",get:function(){switch(this.type){case 18:return"scriptData";case 9:return"video";case 8:return"audio"}}},{key:"packetType",get:function(){var e;return null===(e=this.bodyView)||void 0===e?void 0:e.packetType}},{key:"frameType",get:function(){var e;return null===(e=this.bodyView)||void 0===e?void 0:e.frameType},set:function(e){this.bodyView.frameType=e}},{key:"dts",get:function(){return this.timestamp}},{key:"pts",get:function(){var e;return((null===(e=this.bodyView)||void 0===e?void 0:e.cts)||0)+this.timestamp}},{key:"ptsTime",get:function(){return this.pts?g(this.pts/1e3):0}},{key:"dtsTime",get:function(){return this.dts?g(this.dts/1e3):0}},{key:"sampleView",get:function(){var e,r,t;if("Sequence_Header"!==(null===(e=this.bodyView)||void 0===e?void 0:e.packetType)&&18!==this.type)return{dts:this.timestamp,pts:((null===(r=this.bodyView)||void 0===r?void 0:r.cts)||0)+this.timestamp,data:this._getSampleData(),units:null===(t=this.bodyView)||void 0===t?void 0:t.units}}},{key:"size",get:function(){var e,r;return null===(e=this.sampleView)||void 0===e||null===(r=e.data)||void 0===r?void 0:r.length}},{key:"data",get:function(){return this._getSampleData()}},{key:"nalTypes",get:function(){var e,r;return null===(e=this.bodyView)||void 0===e||null===(r=e.units)||void 0===r?void 0:r.map((function(e){return e.type}))}},{key:"nalSizes",get:function(){var e,r;return null===(e=this.bodyView)||void 0===e||null===(r=e.units)||void 0===r?void 0:r.map((function(e){return e.unit.length}))}},{key:"keyframe",get:function(){return"I"===this.frameType}},{key:"isSample",get:function(){return"scriptData"!==this.streamType&&"Sequence_Header"!==this.packetType}},{key:"isVideo",get:function(){return this.isSample&&"video"===this.streamType}},{key:"isAudio",get:function(){return this.isSample&&"audio"===this.streamType}},{key:"isSqHeader",get:function(){return"Sequence_Header"===this.packetType}},{key:"timescale",get:function(){return 1e3}},{key:"isHevc",get:function(){var e;return"bytevc1"===(null===(e=this.bodyView)||void 0===e?void 0:e.codecType)}},{key:"_getSampleData",value:function(){var e;if("audio"===this.streamType)return this.bodyView.sample;var r=(null===(e=this.bodyView)||void 0===e?void 0:e.units.filter((function(e){return!e.isSei})))||[],t=r.reduce((function(e,r){return e+(r.unit.byteLength+4)}),0),n=new Uint8Array(t),a=0;return r.forEach((function(e){n.set([0,0,0,1],a),a+=4,n.set(e.unit,a),a+=e.unit.byteLength})),n}}]),e}(),O=function(){function e(){s(this,e)}return d(e,null,[{key:"decode",value:function(r){for(var t=[],n=r,a=0,i=r.length;a<i;)if(n[a]<128)t.push(String.fromCharCode(n[a])),++a;else{if(n[a]<192);else if(n[a]<224){if(e._checkContinuation(n,a,1)){var o=(31&n[a])<<6|63&n[a+1];if(o>=128){t.push(String.fromCharCode(65535&o)),a+=2;continue}}}else if(n[a]<240){if(e._checkContinuation(n,a,2)){var s=(15&n[a])<<12|(63&n[a+1])<<6|63&n[a+2];if(s>=2048&&55296!=(63488&s)){t.push(String.fromCharCode(65535&s)),a+=3;continue}}}else if(n[a]<248&&e._checkContinuation(n,a,3)){var u=(7&n[a])<<18|(63&n[a+1])<<12|(63&n[a+2])<<6|63&n[a+3];if(u>65536&&u<1114112){u-=65536,t.push(String.fromCharCode(u>>>10|55296)),t.push(String.fromCharCode(1023&u|56320)),a+=4;continue}}t.push(String.fromCharCode(65533)),++a}return t.join("")}},{key:"_checkContinuation",value:function(e,r,t){var n=e;if(r+t<n.length){for(;t--;)if(128!=(192&n[++r]))return!1;return!0}return!1}}]),e}(),B=function(){function e(){s(this,e)}return d(e,null,[{key:"parse",value:function(r){if(!(r.length<3)){var t={},n=e._parseValue(new DataView(r.buffer,r.byteOffset,r.byteLength));try{var a=e._parseValue(new DataView(r.buffer,r.byteOffset+n.size,r.byteLength-n.size));t[n.data]=a.data}catch(i){}return t}}},{key:"_parseValue",value:function(r){var t,n=r.byteLength,a=1,i=!1;switch(r.getUint8(0)){case 0:t=r.getFloat64(1),a+=8;break;case 1:t=!!r.getUint8(1),a+=1;break;case 2:var o=e._parseString(new DataView(r.buffer,r.byteOffset+a,r.byteLength-a));t=o.data,a+=o.size;break;case 3:t={};var s=0;for(9==(16777215&r.getUint32(n-4))&&(s=3);a<n-4;){var u=e._parseObject(new DataView(r.buffer,r.byteOffset+a,r.byteLength-a-s)),d=u.size,f=u.data;if(u.isEnd)break;t[f.name]=f.value,a+=d}if(a<=n-3)9===(16777215&r.getUint32(a-1))&&(a+=3);break;case 8:t={},a+=4;var c=0;for(9==(16777215&r.getUint32(n-4))&&(c=3);a<n-8;){var l=e._parseObject(new DataView(r.buffer,r.byteOffset+a,r.byteLength-a-c)),p=l.size,v=l.data;if(l.isEnd)break;t[v.name]=v.value,a+=p}if(a<=n-3)9===(16777215&r.getUint32(a-1))&&(a+=3);break;case 9:t=void 0,a=1,i=!0;break;case 10:t=[];var h=r.getUint32(1);a+=4;for(var y=0;y<h;y++){var m=e._parseValue(new DataView(r.buffer,r.byteOffset+a,r.byteLength-a)),b=m.data,w=m.size;t.push(b),a+=w}break;case 11:var g=r.getFloat64(a)+6e4*r.getInt16(a+8);t=new Date(g),a+=10;break;case 12:var k=r.getUint32(1);a+=4,t="",k>0&&(t=O.decode(new Uint8Array(r.buffer,r.byteOffset+a,k))),a+=k;break;default:a=n}return{data:t,size:a,isEnd:i}}},{key:"_parseString",value:function(e){var r=e.getUint16(0),t="";return r>0&&(t=O.decode(new Uint8Array(e.buffer,e.byteOffset+2,r))),{data:t,size:2+r}}},{key:"_parseObject",value:function(r){if(!(r.byteLength<3)){var t=e._parseString(r),n=e._parseValue(new DataView(r.buffer,r.byteOffset+t.size,r.byteLength-t.size));return{data:{name:t.data,value:n.data},size:t.size+n.size,isEnd:n.isEnd}}}}]),e}(),C="undefined"!=typeof window,I=C&&navigator.userAgent.toLocaleLowerCase();C&&/^((?!chrome|android).)*safari/.test(I);var L=C&&I.includes("firefox"),x=C&&I.includes("android"),j=function(){function e(){s(this,e)}return d(e,null,[{key:"parseADTS",value:function(r,t){for(var n=r.length,a=0;a+2<n&&(255!==r[a]||240!=(246&r[a+1]));)a++;if(!(a>=n)){var i=a,o=[],s=(60&r[a+2])>>>2,u=e.FREQ[s];if(!u)throw new Error("Invalid sampling index: ".concat(s));for(var d,f,c=1+((192&r[a+2])>>>6),l=(1&r[a+2])<<2|(192&r[a+3])>>>6,p=e._getConfig(s,l,c),v=p.config,h=p.codec,y=0,m=e.getFrameDuration(u);a+7<n;)if(255===r[a]&&240==(246&r[a+1])){if(n-a<(f=(3&r[a+3])<<11|r[a+4]<<3|(224&r[a+5])>>5))break;d=2*(1&~r[a+1]);var b=g(t+y*m);o.push({pts:b,dts:b,ptsTime:g(b/9e4),dtsTime:g(b/9e4),data:r.subarray(a+7+d,a+f)}),y++,a+=f}else a++;return{skip:i,remaining:a>=n?void 0:r.subarray(a),frames:o,nbFrame:o.length,samplingFrequencyIndex:s,sampleRate:u,objectType:c,channelCount:l,codec:h,config:v,originCodec:"mp4a.40.".concat(c)}}}},{key:"parseAudioSpecificConfig",value:function(r){if(r.length){var t=r[0]>>>3,n=(7&r[0])<<1|r[1]>>>7,a=(120&r[1])>>>3,i=e.FREQ[n];if(!i)throw new Error("Invalid sampling index: ".concat(n));var o=e._getConfig(n,a,t);return{samplingFrequencyIndex:n,sampleRate:i,objectType:t,channelCount:a,config:o.config,codec:o.codec,originCodec:"mp4a.40.".concat(t)}}}},{key:"getFrameDuration",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:9e4;return 1024*r/e}},{key:"_getConfig",value:function(e,r,t){var n,a,i=[];return L?e>=6?(n=5,a=e-3):(n=2,a=e):x?(n=2,a=e):(n=t,a=e,e>=6?a=e-3:1===r&&(n=2,a=e)),i[0]=n<<3,i[0]|=(14&e)>>1,i[1]=(1&e)<<7,i[1]|=r<<3,5===n&&(i[1]|=(14&a)>>1,i[2]=(1&a)<<7,i[2]|=8,i[3]=0),{config:i,codec:"mp4a.40.".concat(n)}}},{key:"getSilentFrame",value:function(e,r){if("mp4a.40.2"===e){if(1===r)return new Uint8Array([0,200,0,128,35,128]);if(2===r)return new Uint8Array([33,0,73,144,2,25,0,35,128]);if(3===r)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,142]);if(4===r)return new Uint8Array([0,200,0,128,32,132,1,38,64,8,100,0,128,44,128,8,2,56]);if(5===r)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===r)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===r)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===r)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===r)return new Uint8Array([1,64,34,128,163,94,230,128,186,8,0,0,0,0,149,0,6,241,161,10,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,90,94])}}}]),e}();function z(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=e.items.filter((function(e){return e.isSample&&e.isVideo}))[0],n=e.items.filter((function(e){return e.isSample&&e.isAudio}))[0],a=Math.min((null==n?void 0:n.dtsTime)||0,(null==t?void 0:t.dtsTime)||0);return a-=r,e.items.forEach((function(e){e.time=g(e.dtsTime-a)})),e}function F(e){var r=e.items.filter((function(e){return e.isVideo})),t=[],n=-1,a={},i={};return r.forEach((function(e,o){(e.keyframe||o===r.length-1)&&(n=-1===n?e.time:n,t.push({time:e.time,value:g(e.time-n)}),n=e.time);var s=Math.ceil(e.time+1e-5);a[s]?a[s]++:a[s]=1,i[s]?i[s]+=8*e.size:i[s]=8*e.size})),{bitRates:N(i),gops:t.filter((function(e){return e.value})),frameRates:N(a)}}function N(e){return Object.keys(e).map((function(r){return{time:Number(r),value:e[r]}}))}function G(e){var r=e.slice().filter((function(e){return e.isSample})).sort((function(e,r){return e.time>r.time?1:-1})).slice(0,3).reduce((function(e,r){return e+r.size}),0);return r>1e3?g(r/1e3)+"KB":r+"B"}function M(e){return e.reduce((function(e,r){return e+r.size}),0)/e.reduce((function(e,r){return e+r.duration}),0)*8e3}function R(e){if(null!=e&&e.profileIdc)switch(e.profileIdc){case 66:return"66(Baseline)";case 77:return"77(Main)";case 100:return"100(High)"}}f(j,"FREQ",[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]);var q=function(){function e(){s(this,e),f(this,"_nalUnitSize",0),f(this,"_lastAudio",null),f(this,"_lastVideo",null),f(this,"_videoStartDts",-1),f(this,"_audioStartDts",-1)}return d(e,[{key:"parse",value:function(e){for(var r=e.byteLength,n=e.subarray(0,13),a=13,i=t(t({header:n},this._parseHeader(n)),{},{items:[]});a+11<r;){var o=e.subarray(a,a+11),s=o[1]<<16|o[2]<<8|o[3],u=a+11+s;if(u>r)break;var d=e.subarray(a+11,u),f=new D(t({tagSize:11+s+4,header:o,body:d,tailsize:e.subarray(u,u+4)},this._parseTag(o,d)));f.isAudio&&(this._lastAudio&&(this._lastAudio.duration=f.dts-this._lastAudio.dts),this._lastAudio=f),f.isVideo&&(this._lastVideo&&(this._lastVideo.duration=f.dts-this._lastVideo.dts),this._lastVideo=f),i.items.push(f),a=u+4}var c=z(i);return c.rates=F(c),this._addMetadataToFirstKeyFrame(c),c}},{key:"getSnapshoot",value:function(r,t){var n=r.items.filter((function(e){return 8===e.type}))[0],a=r.items.filter((function(e){return 9===e.type}))[0],i=n&&n.bodyView||n,o=a&&a.bodyView||a,s=r.items.filter((function(e){return e.isVideo})).length,u=this._getNbFrame(r,"I"),d=this._getNbFrame(r,"P"),f=this._getNbFrame(r,"B"),c=0;if(null!=t&&t.gopCacheBuffer){var l,p=(new e).parse(t.gopCacheBuffer).items.filter((function(e){return e.isVideo})),v=null===(l=p[p.length-1])||void 0===l?void 0:l.time;v&&(c=v-t.take/1e3)}return{rates:r.rates,audio:i?Object.assign({},i,this._getExt(r,"audio")):null,video:o?Object.assign({},o,this._getExt(r,"video"),{topThreeFrameSize:G(r.items),gopCache:g(c),profile:R(o.sps),iFrames:u,pFrames:d,bFrames:f,iPercent:g(u/s*100),pPercent:g(d/s*100),bPercent:g(f/s*100)}):null}}},{key:"_addMetadataToFirstKeyFrame",value:function(e){var r,t=e.items.filter((function(e){return 9===e.type}))[0];if(t&&null!==(r=t.bodyView)&&void 0!==r&&r.sps){var n=e.items.filter((function(e){return e.isVideo&&e.keyframe}))[0];n&&(n.bodyView.sps=t.bodyView.sps,n.bodyView.vpsArr=t.bodyView.vpsArr,n.bodyView.spsArr=t.bodyView.spsArr,n.bodyView.ppsArr=t.bodyView.ppsArr)}}},{key:"_getExt",value:function(e,r){var t=e.items.filter((function(e){return e.streamType===r&&e.isSample})),n=e.items.filter((function(e){var t;return e.streamType===r&&(null===(t=e.bodyView)||void 0===t?void 0:t.packetType)===S}))[0];if(!t.length)return 0;var a,i=t[0],o=t[t.length-1],s=0;"audio"===r&&(s=n&&1024/(null===(a=n.bodyView)||void 0===a?void 0:a.sampleRate)*1e3);return"video"===r&&(s=i.duration),{avgBits:M(t),startDts:t[0].dts,duration:(o.timestamp-i.timestamp)/1e3,refDuration:s,frameLength:t.length}}},{key:"_getNbFrame",value:function(e,r){return e.items.filter((function(e){return e.isVideo&&e.frameType===r})).length}},{key:"_parseHeader",value:function(e){return{hasAudio:!!(e[4]>>2&1),hasVideo:!!(1&e[4])}}},{key:"_parseTag",value:function(e,r){var t,n=31&e[0],a=(e[7]<<24>>>0)+(e[4]<<16)+(e[5]<<8)+e[6];switch(n){case 18:t=Object.assign({packetType:k},B.parse(r));break;case 9:t=this._parseVideo(r,a);break;case 8:t=this._parseAudio(r,a)}return{type:n,timestamp:a,bodyView:t}}},{key:"_parseAudio",value:function(e){if(e.length){var r=(240&e[0])>>>4;if(10===r||7===r||8===r){if(10!==r){var n=(12&e[0])>>2,a=(2&e[0])>>1,i=1&e[0];return t({format:r,sampleRate:V[n],sampleSize:a?2:1,channelCount:i+1},this._parseG711(e))}return this._parseAac(e,r)}console.warn("Unsupported sound format: ".concat(r))}}},{key:"_parseG711",value:function(e,r){return{codecType:7===r?U:A,sampleRate:8e3,sample:e.subarray(1),packetType:_}}},{key:"_parseAac",value:function(e,r){if(0===e[1]){var n=e.subarray(2);return t(t({},j.parseAudioSpecificConfig(n)),{},{format:r,timescale:1e3,codecType:T,packetType:S,sequenceData:[n],frameType:"A"})}if(1===e[1])return{sample:e.subarray(2),format:r,codecType:T,packetType:_,frameType:"A"}}},{key:"_parseVideo",value:function(e,r){if(!(e.length<6)){var n=(240&e[0])>>>4,a=15&e[0];if(7===a||12===a){var i=12===a,o=e[1],s=(e[2]<<16|e[3]<<8|e[4])<<8>>8;if(0===o){var u=e.subarray(5),d=i?b.parseHEVCDecoderConfigurationRecord(u):m.parseAVCDecoderConfigurationRecord(u);return this._nalUnitSize=d.nalUnitSize,t({codecId:a,codecType:i?E:P,packetType:S,timescale:1e3,sequenceData:[u]},d)}if(1===o){var f=y.parseNalu(e.subarray(5),this._nalUnitSize);if(!f||!f.length)return;var c={dts:r,cts:s,units:f=y.parseNaluType(f,i)};return 1===n&&(c.keyframe=!0),f.forEach((function(e){var r=e.type,t=e.unit,n=e.frameType;switch(r){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!i&&5!==r||i&&5===r)break;c.keyframe=!0,c.frameType="I";break;case 6:case 39:case 40:if(!i&&6!==r||i&&6===r)break;c.seis?c.seis.push(y.parseSEI(y.removeEPB(t))):c.seis=[y.parseSEI(y.removeEPB(t))];break;case 32:if(!i)break;c.vpsArr?c.vpsArr.push(t):c.vpsArr=[t];break;case 7:case 33:if(!i&&7!==r||i&&7===r)break;c.spsArr?c.spsArr.push(t):c.spsArr=[t];var a=y.removeEPB(t);c.sps=i?b.parseSPS(a):m.parseSPS(a);break;case 8:case 34:if(!i&&8!==r||i&&8===r)break;c.ppsArr?c.ppsArr.push(t):c.ppsArr=[t];break;case 1:case 0:c.frameType=n}})),t({codecId:a,codecType:i?E:P,packetType:_},c)}}else console.warn("Unsupported codecId: ".concat(a))}}}]),e}(),H="FLV",K="MPEG-TS",W="MP4",X="RAW264",Z="NOSUPPORT";function Q(e){for(var r=Math.min(1e3,e.byteLength-564),t=0;t<r;t++)if(71===e[t]&&71===e[t+188]&&71===e[t+376])return t;return-1}function $(e,r){return[e[r],e[r+1],e[r+2],e[r+3]].map((function(e){return String.fromCharCode(e)})).join("")}function Y(e){return function(e){return 70===e[0]&&76===e[1]&&86===e[2]}(e)?H:-1!==Q(e)?K:function(e){var r=$(e,4);return"ftyp"===r||"moov"===r||"moof"===r||"mdat"===r}(e)?W:function(e){return 0===e[0]&&0===e[1]&&(1===e[2]||0===e[2]&&1===e[3])}(e)?X:Z}var J=d((function e(r){var t=r.startIndictor,n=r.packetType,a=r.pid,i=r.afc;s(this,e),f(this,"startIndictor",0),f(this,"pid",0),f(this,"afc",0),f(this,"eleInfo",null),f(this,"packetType",""),this.startIndictor=t,this.packetType=n,this.pid=a,this.afc=i})),ee=function(){function e(r){var t=r.header,n=r.headerObject,a=r.body,i=r.eleInfo,o=r.bodyView,u=r.headerView;s(this,e),f(this,"header",null),f(this,"headerView",null),f(this,"body",null),f(this,"bodyView",null),f(this,"eleInfo",null),f(this,"duration",0),this.header=t,this.headerView=u||new J(n),this.eleInfo=i,this.body=a,this.bodyView=o}return d(e,[{key:"type",get:function(){var e;return null===(e=this.headerView)||void 0===e?void 0:e.packetType}},{key:"streamType",get:function(){return this.eleInfo?this.eleInfo[this.headerView.pid]:""}},{key:"packetType",get:function(){var e;return null===(e=this.headerView)||void 0===e?void 0:e.packetType}},{key:"frameType",get:function(){var e;return null===(e=this.bodyView)||void 0===e?void 0:e.frameType}},{key:"pts",get:function(){var e;return null===(e=this.bodyView)||void 0===e?void 0:e.pts}},{key:"ptsTime",get:function(){return this.pts?g(this.pts/9e4):0}},{key:"dtsTime",get:function(){return this.dts?g(this.dts/9e4):0}},{key:"dts",get:function(){var e;return null===(e=this.bodyView)||void 0===e?void 0:e.dts}},{key:"keyframe",get:function(){return"I"===this.frameType}},{key:"nalTypes",get:function(){var e,r;return null===(e=this.bodyView)||void 0===e||null===(r=e.units)||void 0===r?void 0:r.map((function(e){return e.type}))}},{key:"nalSizes",get:function(){var e,r;return null===(e=this.bodyView)||void 0===e||null===(r=e.units)||void 0===r?void 0:r.map((function(e){return e.unit.length}))}},{key:"isSample",get:function(){return"PES"===this.packetType}},{key:"timescale",get:function(){return 9e4}},{key:"isHevc",get:function(){var e,r;return"bytevc1"===(null===(e=this.eleInfo)||void 0===e||null===(r=e.video)||void 0===r?void 0:r.codecType)}},{key:"sampleView",get:function(){var e;if("PES"===this.type)return{dts:this.dts,pts:this.pts,units:null===(e=this.bodyView)||void 0===e?void 0:e.units,data:this._getSampleData()}}},{key:"data",get:function(){return this._getSampleData()}},{key:"size",get:function(){var e,r;return null===(e=this.sampleView)||void 0===e||null===(r=e.data)||void 0===r?void 0:r.length}},{key:"isVideo",get:function(){return this.isSample&&"video"===this.streamType}},{key:"isAudio",get:function(){return this.isSample&&"audio"===this.streamType}},{key:"_getSampleData",value:function(){var e;if("audio"===this.streamType)return this.bodyView.data;var r=(null===(e=this.bodyView)||void 0===e?void 0:e.units.filter((function(e){return!e.isSei&&!e.isDivision})))||[],t=r.reduce((function(e,r){return e+(r.unit.byteLength+4)}),0),n=new Uint8Array(t),a=0;return r.forEach((function(e){n.set([0,0,0,1],a),a+=4,n.set(e.unit,a),a+=e.unit.byteLength})),n}}]),e}(),re=function(){function e(){s(this,e)}return d(e,[{key:"parse",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=Q(e);if(-1===n)throw new Error("invalid ts file");var a=e.byteLength;a-=(a-n)%188;for(var i,o=[],s=[],u=[],d=0,f=n;f<a;){var c=e.subarray(f,f+188),l=c.subarray(0,4),p=this._parseTsHeader(c.subarray(0,4));f+=188;var v=void 0,h=void 0,y=4,m="";switch((null==p?void 0:p.afc)>1&&(y+=1+Math.min(c[y],183)),p.pid){case 0:y+=1+c[y],v=c.subarray(y),m="PAT",h={pmtId:d=this._parsePAT(v)};break;default:if(p.pid===d){y+=1+c[y],v=c.subarray(y),h=i=this._parsePMT(v),m="PMT";break}if(!i||!i[p.pid])continue;v=c.subarray(y),m="PES"}if(p.packetType=m,"PES"===m){var b="video"===i[p.pid]?s:u;p.startIndictor&&b.length&&(o.push(new ee(t(t({},this._concatPesChunk(b)),{},{eleInfo:i}))),b="video"===i[p.pid]?s=[]:u=[]),b.push({header:l,headerObject:p,body:v})}else o.push(new ee({header:l,headerObject:p,body:v,eleInfo:i,bodyView:h}))}s.length&&(o.push(new ee(t(t({},this._concatPesChunk(s)),{},{eleInfo:i}))),s=[]),u.length&&(o.push(new ee(t(t({},this._concatPesChunk(u)),{},{eleInfo:i}))),u=[]);var w={items:this._parsePES(o)},g=z(w,r);return g.rates=F(g),g}},{key:"getSnapshoot",value:function(e){var r,t,n,a=e.items,i=e.rates,o=a.filter((function(e){return"video"===e.streamType})),s=a.filter((function(e){return"audio"===e.streamType})),u=a.find((function(e){return"PMT"===e.type})),d=o[0],f=s[0],c=o.length,l=this._getNbFrame(o,"I"),p=this._getNbFrame(o,"P"),v=this._getNbFrame(o,"B"),h={rates:i,video:d?Object.assign({},null==d?void 0:d.bodyView,{codecType:d.eleInfo.video.codecType,frameLength:c,topThreeFrameSize:G(a),avgBits:M(o),profile:R(null==d||null===(r=d.bodyView)||void 0===r?void 0:r.sps),iFrames:l,pFrames:p,bFrames:v,iPercent:g(l/c*100),pPercent:g(p/c*100),bPercent:g(v/c*100),timescale:9e4},this._getDuration(o,"video")):null,audio:f?Object.assign({},null==f?void 0:f.bodyView,{codecType:f.eleInfo.audio.codecType,frameLength:s.length,timescale:9e4,avgBits:M(s)},this._getDuration(s,"audio")):null};u&&null!==(t=u.bodyView)&&void 0!==t&&t.noSupported&&(h.noSupported=null===(n=u.bodyView)||void 0===n?void 0:n.noSupported);return h}},{key:"getRates",value:function(e){return F(e)}},{key:"_getDuration",value:function(e,r){var t,n=e[0],a=e[e.length-1],i=0;"audio"===r&&(i=1024/(null===(t=n.bodyView)||void 0===t?void 0:t.sampleRate)*1e3);return"video"===r&&(i=n.duration),{duration:(a.pts-n.pts)/9e4,refDuration:i}}},{key:"_getNbKeyFrame",value:function(e){return e.filter((function(e){var r;return null===(r=e.bodyView)||void 0===r?void 0:r.keyframe})).length}},{key:"_getNbFrame",value:function(e,r){return e.filter((function(e){return e.frameType===r})).length}},{key:"_parseTsHeader",value:function(e){if(71===e[0]){var r={};return r.startIndictor=(64&e[1])>>6,r.pid=((31&e[1])<<8)+e[2],r.afc=(48&e[3])>>4,r}return null}},{key:"_parsePAT",value:function(e){return(31&e[10])<<8|e[11]}},{key:"_parsePMT",value:function(e){var r=0,t=3+((15&e[1])<<8|e[2])-4;e[3],e[4],r=r+11+((15&e[10])<<8|e[11])+1;for(var n,a={video:null,audio:null,noSupported:0};r<t;){n=e[r];var i=(31&e[r+1])<<8|e[r+2];switch(n){case 27:case 36:a.video={elePid:i,streamType:n,codecType:27===n?"avc":"bytevc1"},a[i]="video";break;case 15:a.audio={elePid:i,streamType:n,codecType:"aac"},a[i]="audio";break;default:a.noSupported=n,console.warn("unsupported streamType,",n)}r+=5+((15&e[r+3])<<8|e[r+4])}return a}},{key:"_concatPesChunk",value:function(e){var r=e.reduce((function(e,r){return e+r.body.byteLength}),0),n=new Uint8Array(r),a=0;return e.forEach((function(e){var r=e.body;n.set(r,a),a+=r.byteLength})),t(t({},e[0]),{},{body:n,packetType:"PES"})}},{key:"_parsePES",value:function(e){var r=this,n=[];return e.forEach((function(e,a){if(e.isSample){var i=e,o=r._parsePESInternal(i.body)||{},s=o.data,u=o.pts,d=o.dts;if(s){if(e.isVideo&&(i.bodyView=r._parseVideoFrame(s,u,d,"bytevc1"===i.eleInfo.video.codecType),r._lastVideo&&(r._lastVideo.duration=1e3*(e.dtsTime-r._lastVideo.dtsTime)),r._lastVideo=i),e.isAudio){var f=j.parseADTS(s,u),c=f.frames;return delete f.frames,void(null==c||c.forEach((function(e){var a=new ee(Object.assign({},i,{bodyView:t(t(t({},f),e),{},{frameType:"A"})}));n.push(a),r._lastAudio&&(r._lastAudio.duration=1e3*(a.dtsTime-r._lastAudio.dtsTime)),r._lastAudio=a})))}n.push(e)}}else n.push(e)})),n}},{key:"_parsePESInternal",value:function(e){var r=e[8];if(!(0===r||e.length<r+9)&&1===(e[0]<<16|e[1]<<8|e[2])){var t=(e[4]<<8)+e[5];if(!(t&&t>e.length-6)){var n,a,i=e[7];return 192&i&&(n=536870912*(14&e[9])+4194304*(255&e[10])+16384*(254&e[11])+128*(255&e[12])+(254&e[13])/2,64&i?n-(a=536870912*(14&e[14])+4194304*(255&e[15])+16384*(254&e[16])+128*(255&e[17])+(254&e[18])/2)>54e5&&(n=a):a=n),a=a||n,{data:e.subarray(9+r),pts:n,dts:a}}}}},{key:"_parseVideoFrame",value:function(e,r,t,n){var a=y.parseAnnexB(e);if(a.length){var i={units:a=y.parseNaluType(a,n),pts:r,dts:t};return a.forEach((function(e){var r=e.unit,t=e.type,a=e.frameType;switch(t){case 5:case 16:case 17:case 18:case 19:case 20:case 21:case 22:case 23:if(!n&&5!==t||n&&5===t)break;i.keyframe=!0,i.frameType="I";break;case 6:case 39:case 40:if(!n&&6!==t||n&&6===t)break;i.seis?i.seis.push(y.parseSEI(y.removeEPB(r))):i.seis=[y.parseSEI(y.removeEPB(r))];break;case 32:if(!n)break;i.vpsArr?i.vpsArr.push(r):i.vpsArr=[r];break;case 7:case 33:if(!n&&7!==t||n&&7===t)break;i.spsArr?i.spsArr.push(r):i.spsArr=[r];var o=y.removeEPB(r);i.sps=n?b.parseSPS(o):m.parseSPS(o);break;case 8:case 34:if(!n&&8!==t||n&&8===t)break;i.ppsArr?i.ppsArr.push(r):i.ppsArr=[r];break;case 9:case 35:break;case 0:case 1:i.frameType=a}})),i}}}]),e}(),te=function(){function e(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;s(this,e),this._offset=t,this._buffer=r,this._length=r.byteLength}return d(e,[{key:"offset",get:function(){return this._offset},set:function(e){this._offset=e}},{key:"forward",value:function(e){this._offset+=e}},{key:"subarray",value:function(e){return e?this._buffer.subarray(this._offset,this._offset+e):this._buffer.subarray(this._offset,e)}},{key:"slice",value:function(e){for(var r=this._offset,t=this._buffer,n=[],a=0;a<e;a++)n.push(t[r+a]);return new Uint8Array(n)}},{key:"readU8",value:function(){return this._buffer[this._offset]}},{key:"readU16",value:function(){var e=this._offset,r=this._buffer;return r[e]<<8|r[e+1]}},{key:"readU24",value:function(){var e=this._offset,r=this._buffer;return r[e]<<16|r[e+1]<<8|r[e+12]}},{key:"readU32",value:function(){var e=this._offset,r=this._buffer;return r[e]*(1<<24)+65536*r[e+1]+256*r[e+2]+r[e+3]}},{key:"read32",value:function(){var e=this._offset,r=this._buffer;return r[e]<<24|r[e+1]<<16|r[e+2]<<8|r[e+3]}}]),e}(),ne=function(){function e(r,t,n,a,i,o,u,d,c,l){s(this,e),f(this,"dts",0),f(this,"pts",0),f(this,"units",null),f(this,"timescale",0),f(this,"offset",0),f(this,"duration",0),f(this,"data",null),f(this,"size",0),f(this,"streamType",""),f(this,"_frameType",""),f(this,"isHevc",!1),this.dts=r,this.pts=t,this.units=n,this.timescale=a,this.offset=i,this.data=o,this.size=u,this.duration=d,this.streamType=c,this.isHevc=l}return d(e,[{key:"isSample",get:function(){return!0}},{key:"dtsTime",get:function(){return this.dts/this.timescale}},{key:"ptsTime",get:function(){return this.pts/this.timescale}},{key:"frameType",get:function(){var e;return"audio"===this.streamType?"A":this._frameType||(null===(e=this.units)||void 0===e?void 0:e.map((function(e){return e.frameType})).filter(Boolean)[0])},set:function(e){this._frameType=e}},{key:"nalTypes",get:function(){var e;return null===(e=this.units)||void 0===e?void 0:e.map((function(e){return e.type}))}},{key:"nalSizes",get:function(){var e;return null===(e=this.units)||void 0===e?void 0:e.map((function(e){return e.unit.length}))}},{key:"keyframe",get:function(){return"I"===this.frameType}},{key:"isVideo",get:function(){return"video"===this.streamType}},{key:"isAudio",get:function(){return"audio"===this.streamType}}]),e}(),ae={ftyp:"file type and compatibility",free:"free box",moov:"container for all metadata",mvhd:"movie header,overall declarations",trak:"container for an individual track or stream",tkhd:"track header,overall information about the track",tref:"track reference container",mdia:"container for the media information in a track",mdhd:"media header,oervall information about the media",hdlr:"declares the media type",minf:"media information container",vmhd:"video media header",smhd:"sound media header",dinf:"data information box",stbl:"sample table box",stsd:"sample descriptions(codec types, etc)",stts:"decoding time to sample",ctts:"compostion time to sample",cslg:"compostion to decode timeline mapping",stsc:"sample to chunk",stsz:"sample size",stco:"chunk offset",stss:"sync sample table",sdtp:"independent abd disposable samples",sbgp:"sample to group",mvex:"movid extends box",moof:"movie fragment",mfhd:"movie fragment header",traf:"track fragment",tfhd:"track fragment header",trun:"track fragment run",tfdt:"track fragment decode time",mdat:"media data",meta:"metadata",avc1:"h264 codec info box",hev1:"hevc codec info box"};function ie(e,r){return{isLeading:(12&e[r])>>2,dependsOn:3&e[r],isDenpendedOn:(192&e[r+1])>>6,hasRedundancy:(48&e[r+1])>>4,padding:(14&e[r+1])>>1,nonSync:1&e[r+1],degradationPriority:e[r+2]<<8|e[r+3]}}function oe(e,r){return[e[r],e[r+1],e[r+2],e[r+3]].map((function(e){return String.fromCharCode(e)})).join("")}function se(e){for(var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,t=[],n=0;n<e.byteLength;){var a=e[n]*(1<<24)+65536*e[n+1]+256*e[n+2]+e[n+3];if(1===a){var i=oe(e,n+4);if("mdat"===i){var o=new DataView(e.buffer),s=o.getUint32(n+8)*Math.pow(2,32)+o.getUint32(n+12);console.log("".concat(i,": largesize=").concat(s)),a=s}}if(a){var u=e.subarray(n,n+a),d=oe(u,4);t.push({size:a,length:u.byteLength,start:n+r,type:d,sizetypeRepresent:u.subarray(0,8).slice(),body:u.subarray(8),typeDes:ae[d]||""}),n+=a}else n+=4}return t}function ue(e,r,t){if(e)for(var n=0;n<e.length;n++){var a=e[n];if(a.type===r){if(!t)return a;if(t(a))return a}if(a.bodyView instanceof Array){var i=ue(a.bodyView,r,t);if(i){if(!t)return i;if(t(i))return i}}}}function de(e,r){return ue(e,"trak",(function(e){var t=ue(e.bodyView,"hdlr");return t&&t.bodyView.handlerType===r}))}function fe(e,r,n){var a,i,o,s,u,d,f,c,l,p,v,h,m,b=de(e,r);if(!b)return null;var w=ue(b.bodyView,"stbl"),g=ue(b.bodyView,"mdhd")||{},k=(null===(a=w.bodyView.filter((function(e){return"stts"===e.type}))[0])||void 0===a||null===(i=a.bodyView)||void 0===i?void 0:i.entries)||[];null===(o=w.bodyView.filter((function(e){return"stss"===e.type}))[0])||void 0===o||null===(s=o.bodyView)||void 0===s||s.entries;var S=(null===(u=w.bodyView.filter((function(e){return"ctts"===e.type}))[0])||void 0===u||null===(d=u.bodyView)||void 0===d?void 0:d.entries)||[],_=(null===(f=w.bodyView.filter((function(e){return"stsc"===e.type}))[0])||void 0===f||null===(c=f.bodyView)||void 0===c?void 0:c.entries)||[],V=(null===(l=w.bodyView.filter((function(e){return"stsz"===e.type}))[0])||void 0===l||null===(p=l.bodyView)||void 0===p?void 0:p.entries)||[],T=(null===(v=w.bodyView.filter((function(e){return"stco"===e.type}))[0])||void 0===v||null===(h=v.bodyView)||void 0===h?void 0:h.entries)||[],U=!!ue(w.bodyView,"hvcC"),A="vide"===r;if(!_.length||!T.length||!V.length)return[];for(var P,E=g.bodyView,D=E.timescale,O=void 0===D?1:D,B=E.duration,C=V.length,I=T.length,L=1,x=0,j=[],z=function(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],a=0,i=0,o=0,s=0,u=0,d=[];r=r.map((function(e){return t({},e)})),n=n.map((function(e){return t({},e)}));for(;o<e;){var f=r[a],c=n[i];f.sampleCount&&(s+=f.sampleDelta),f.sampleCount--,f.sampleCount||a++,c&&(u=c.sampleOffset,c.sampleCount--,c.sampleCount||i++),d.push({dts:s,pts:s+u}),o++}return d}(C,k,S,O);L<=I;){var F=_[x];(null==F?void 0:F.firstChunk)!==L?(j.push(Object.assign({},P,{firstChunk:L,offset:T[L-1]})),L++):(j.push(t(t({},F),{},{offset:T[L-1]})),P=F,L++,x++)}var N=V.map((function(e,r){var t=j[0],a=t.offset;t.offset+=e,t.samplesPreChunk--,t.samplesPreChunk||j.shift();var i=z[r],o=n.subarray(a,a+e);if(A){var s=y.parseNalu(o);return new ne(i.dts,i.pts,y.parseNaluType(s,U),O,a,o,e,0,"video",U)}return new ne(i.dts,i.pts,null,O,a,o,e,0,"audio")}));N.reduce((function(e,r){return e?(e.duration=(r.dts-e.dts)/O*1e3,r):r}),null);var G=null===(m=ue(null==b?void 0:b.bodyView,"vide"===r?U?"hvcC":"avcC":"mp4a"))||void 0===m?void 0:m.bodyView;return t(t(t({samples:N,iFrames:N.filter((function(e){return"I"===e.frameType})).length,pFrames:N.filter((function(e){return"P"===e.frameType})).length,bFrames:N.filter((function(e){return"B"===e.frameType})).length},g.bodyView),{},{frameLength:C,duration:B/O,timescale:O},G),null==G?void 0:G.ests)}function ce(e,r){var n=function(e){var r,n,a,i,o=de(e,"vide"),s=de(e,"soun"),u=ue(null==o?void 0:o.bodyView,"tkhd"),d=ue(null==s?void 0:s.bodyView,"tkhd"),c=ue(null==o?void 0:o.bodyView,"mdhd"),l=ue(null==s?void 0:s.bodyView,"mdhd"),p=ue(null==o?void 0:o.bodyView,"avcC")||ue(null==o?void 0:o.bodyView,"hvcC"),v=ue(null==s?void 0:s.bodyView,"mp4a"),h=s?t(t(t({type:"audio",trackId:null===(r=d.bodyView)||void 0===r?void 0:r.trackId},l.bodyView),null==v?void 0:v.bodyView),null==v||null===(n=v.bodyView)||void 0===n?void 0:n.ests):null,y=o?t(t({type:"video",trackId:null===(a=u.bodyView)||void 0===a?void 0:a.trackId},null==c?void 0:c.bodyView),null==p?void 0:p.bodyView):null;return f(i={},(null==h?void 0:h.trackId)||0,h),f(i,(null==y?void 0:y.trackId)||0,y),i}(e),a=e.findIndex((function(e){return"moof"===e.type}));if(-1===a)return!1;n.lastVdts=-1,n.lastAdts=-1;for(var i=a;i<e.length&&"moof"===e[i].type;i+=2){var o=e[i];e[i+1].bodyView=le(o,r,n)}return!0}function le(e,r,n){return e.bodyView.filter((function(e){return"traf"===e.type})).map((function(e){var r=ue(e.bodyView,"tfhd"),a=ue(e.bodyView,"tfdt"),i=ue(e.bodyView,"trun");if(r&&i){var o=r.bodyView.trackId;return t({trackId:o,baseDataOffset:r.bodyView.baseDataOffset,defaultSampleDuration:r.bodyView.defaultSampleDuration,defaultSampleSize:r.bodyView.defaultSampleSize,baseMediaDecodeTime:a.bodyView.baseMediaDecodeTime,dataOffset:i.bodyView.dataOffset,samples:i.bodyView.samples,sampleCount:i.bodyView.sampleCount},n[o])}})).filter(Boolean).map((function(e){var t=e.baseDataOffset,n=e.defaultSampleDuration,a=void 0===n?0:n,i=e.defaultSampleSize,o=void 0===i?0:i,s=e.dataOffset,u=e.baseMediaDecodeTime,d=void 0===u?0:u,f=e.samples,c=e.sps,l=e.timescale,p=e.type,v=t+s,h=0;return e.samples=f.map((function(e){var t=r.subarray(v,v+e.size);h+=e.duration||a;var n=d+h;if("video"===p){var i="hev1.1.6.L93.B0"===(null==c?void 0:c.codec),s=y.parseNalu(t);return v+=e.size,new ne(n,n+(e.ctOffset||0),y.parseNaluType(s,i),l,v,t,e.size||o,(e.duration||a)/l*1e3,"video",i)}return v+=e.size,new ne(n,n+(e.ctOffset||0),null,l,v,t,e.size||o,(e.duration||a)/l*1e3,"audio")})),e.frameLength=e.samples.length,e.duration=h/l,e.iFrames=e.samples.filter((function(e){return"I"===e.frameType})).length,e.pFrames=e.samples.filter((function(e){return"P"===e.frameType})).length,e.bFrames=e.samples.filter((function(e){return"B"===e.frameType})).length,e}))}var pe=Math.pow(2,32);var ve=function(){var e=[];e[3]="ES_Descriptor",e[4]="DecoderConfigDescriptor",e[5]="DecoderSpecificInfo",e[6]="SLConfigDescriptor",this.getDescriptorName=function(r){return e[r]};var r=this,t={};return this.parseOneDescriptor=function(r){var n,a,i=0,o=r.readU8();for(r.forward(1),a=r.readU8(),r.forward(1);128&a;)i=(127&a)<<7,a=r.readU8(),r.forward(1);return i+=127&a,(n=e[o]?new t[e[o]](i):new t.Descriptor(i)).parse(r),n},t.Descriptor=function(e,r){this.tag=e,this.size=r,this.descs=[]},t.Descriptor.prototype.parse=function(e){this.data=e.slice(this.size),e.forward(this.size)},t.Descriptor.prototype.findDescriptor=function(e){for(var r=0;r<this.descs.length;r++)if(this.descs[r].tag===e)return this.descs[r];return null},t.Descriptor.prototype.parseRemainingDescriptors=function(e){for(var t=e.offset;e.offset<t+this.size;){var n=r.parseOneDescriptor(e);this.descs.push(n)}},t.ES_Descriptor=function(e){t.Descriptor.call(this,3,e)},t.ES_Descriptor.prototype=new t.Descriptor,t.ES_Descriptor.prototype.parse=function(e){if(this.ES_ID=e.readU16(),e.forward(2),this.flags=e.readU8(),e.forward(1),this.size-=3,128&this.flags?(this.dependsOn_ES_ID=e.readU16(),e.forward(2),this.size-=2):this.dependsOn_ES_ID=0,64&this.flags){var r=e.readU8();e.forward(1),this.URL=Array.from(e.slice(r)).map((function(e){return String.fromCharCode(e)})),e.forward(r),this.size-=r+1}else this.URL="";32&this.flags?(this.OCR_ES_ID=e.readU16(),e.forward(2),this.size-=2):this.OCR_ES_ID=0,this.parseRemainingDescriptors(e)},t.ES_Descriptor.prototype.getOTI=function(e){var r=this.findDescriptor(4);return r?r.oti:0},t.ES_Descriptor.prototype.getAudioConfig=function(e){var r=this.findDescriptor(4);if(!r)return null;var t=r.findDescriptor(5);if(t&&t.data){var n=(248&t.data[0])>>3;return 31===n&&t.data.length>=2&&(n=32+((7&t.data[0])<<3)+((224&t.data[1])>>5)),n}return null},t.DecoderConfigDescriptor=function(e){t.Descriptor.call(this,4,e)},t.DecoderConfigDescriptor.prototype=new t.Descriptor,t.DecoderConfigDescriptor.prototype.parse=function(e){this.oti=e.readU8(),e.forward(1),this.streamType=e.readU8(),e.forward(1),this.bufferSize=e.readU24(),e.forward(3),this.maxBitrate=e.readU32(),e.forward(4),this.avgBitrate=e.readU32(),e.forward(4),this.size-=13,this.parseRemainingDescriptors(e)},t.DecoderSpecificInfo=function(e){t.Descriptor.call(this,5,e)},t.DecoderSpecificInfo.prototype=new t.Descriptor,t.SLConfigDescriptor=function(e){t.Descriptor.call(this,6,e)},t.SLConfigDescriptor.prototype=new t.Descriptor,this};function he(e){var r,t,n,a=e.descs.find((function(e){return 4===e.tag}));a&&(n=a.descs.find((function(e){return 5===e.tag})));var i=Object.assign({},a);return delete i.descs,i.config=null!==(r=n)&&void 0!==r&&r.data.length?Array.from(null===(t=n)||void 0===t?void 0:t.data):[],i}function ye(e){return e.map((function(e){return e.toString(16)})).join("")}function me(e){var r=e.body,t={},n=r[0],a=new te(r);if(a.forward(4),t.systemId=ye(a.slice(16)),a.forward(16),n>0){var i=a.readU32();t.kids=[];var o=0;for(a.forward(4);o<i;)t.kids.push(ye(a.slice(16))),a.forward(16),o++}var s=a.readU32();return a.forward(4),t.dataSize=s,t.data=a.slice(s),t.dataToBase64=btoa(t.data.map((function(e){return String.fromCharCode(e)})).join("")),t}var be=Math.pow(2,32);var we=Math.pow(2,32);function ge(e){var r=e.body,t={samples:[]},n=new te(r);t.version=n.readU8(),n.forward(1),t.flags=n.slice(3);var a,i,o,s,u=(a=t.flags,i=c(a,3),o=i[1],{dataOffsetPresent:!!(1&(s=i[2])),firstSampleFlagsPresent:!!(4&s),sampleDurationPresent:!!(1&o),sampleSizePresent:!!((2&o)>>1),sampleFlagsPresent:!!((4&o)>>2),sampleCompositionTimeOffsetPresent:!!((8&o)>>3)}),d=u.dataOffsetPresent,f=u.firstSampleFlagsPresent,l=u.sampleDurationPresent,p=u.sampleSizePresent,v=u.sampleFlagsPresent,h=u.sampleCompositionTimeOffsetPresent;t.trFlags=u,n.forward(3),t.sampleCount=n.readU32(),n.forward(4),d&&(t.dataOffset=n.readU32(),n.forward(4)),f&&(t.firstSampleFlags=ie(r,n.offset),n.forward(4));for(var y=0;y<t.sampleCount;){var m={};l&&(m.duration=n.readU32(),n.forward(4)),p&&(m.size=n.readU32(),n.forward(4)),v&&(m.flags=ie(r,n.offset),n.forward(4)),h&&(m.ctOffset=n.readU32(),n.forward(4)),t.samples.push(m),y++}return t}function ke(e){var r=se(e instanceof ArrayBuffer?new Uint8Array(e):e,0);if(Se(r),!ce(r,e)){var n=ue(r,"mdat");n&&(n.bodyView=[t({type:"video"},fe(r,"vide",e)),t({type:"audio"},fe(r,"soun",e))].filter((function(e){return!!e.samples})))}return r}function Se(e){var r=0;e.forEach((function(e){switch(e.type){case"ftyp":case"styp":e.bodyView=function(e){var r=e.body,t=e.length,n=new te(r),a={compatible:[]};a.major=$(r,0),n.forward(4),a.version=n.readU32(),n.forward(4);for(var i=n.offset;i<t-8;)a.compatible.push($(r,i)),i+=4;return a}(e);break;case"moov":case"trak":case"mvex":case"mdia":case"minf":case"dinf":case"moof":case"traf":case"stbl":e.bodyView=se(e.body,e.start+8),Se(e.bodyView);break;case"stsd":var t=function(e){var r=e.body,t=e.start,n=new te(r);n.forward(4);var a=n.readU32();return n.forward(4),{entryCount:a,childData:se(n.subarray(),t+8+8)}}(e),n=t.entryCount,a=t.childData;e.entryCount=n,e.bodyView=a,Se(e.bodyView);break;case"mvhd":e.bodyView=(c=e.body,l=new te(c),p={},l.forward(4),p.createTime=l.readU32(),l.forward(4),p.modifyTime=l.readU32(),l.forward(4),p.timescale=l.readU32(),l.forward(4),p.duration=l.readU32(),l.forward(4),p.rate=l.readU32(),l.forward(4),l.forward(2),l.forward(70),p.nextTrackId=l.readU32(),p);break;case"tkhd":e.bodyView=function(e){var r=e.body,t=new te(r,4),n={},a=t.readU8();n.version=a,1===a?t.forward(16):t.forward(8),n.trackId=t.readU32(),t.forward(4),1===a?(n.duration=t.readU32()*we,t.forward(4),n.duration+=t.readU32()):n.duration=t.readU32();var i=r.byteLength;return i-=8,t.offset=i,n.width=t.readU32()>>16,t.forward(4),n.height=t.readU32()>>16,n}(e);break;case"mehd":e.bodyView=function(e){var r,t=e.body,n=new te(t);if(n.forward(4),1===t[0]){var a=n.readU32();n.forward(4),r=a*(1<<30)*2+n.readU32()}else r=n.readU32();return{fragDuration:r}}(e);break;case"mdhd":e.bodyView=function(e){var r=e.body,t={},n=new te(r),a=r[0];return n.forward(4),1===a?(n.forward(16),t.timescale=n.readU32(),n.forward(4),t.duration=n.readU32()*pe,n.forward(4),t.duration+=n.readU32()):(n.forward(8),t.timescale=n.readU32(),n.forward(4),t.duration=n.readU32()),t}(e);break;case"hdlr":e.bodyView=function(e){return{handlerType:$(e.body,8)}}(e);break;case"trex":e.bodyView=function(e){var r=e.body,t={},n=new te(r);return n.forward(4),t.trackId=n.readU32(),n.forward(4),t.defaultSdescriptionIndex=n.readU32(),n.forward(4),t.defaultSampleDuration=n.readU32(),n.forward(4),t.defaultSampleSize=n.readU32(),n.forward(4),t.defaultSampleFlags=ie(r,n.offset),t}(e);break;case"trun":e.bodyView=ge(e),r=e.bodyView.samples.length;break;case"tfdt":e.bodyView=function(e){var r=e.body,t=new te(r),n=0;return t.forward(4),1===r[0]?(n=t.readU32()*be,t.forward(4),n+=t.readU32()):n=t.readU32(),{baseMediaDecodeTime:n}}(e);break;case"avc1":case"hvc1":case"hev1":e.bodyView=function(e){var r=e.body,t=e.start,n=new te(r);return n.forward(78),se(n.subarray(),t+78+8)}(e),Se(e.bodyView);break;case"mp4a":e.bodyView=function(e){var r=e.body,t=r.slice(28),n=(new ve).parseOneDescriptor(new te(t.slice(12),0)),a=(null==n?void 0:n.getAudioConfig)&&n.getAudioConfig();return{channelCount:r[17],samplesize:r[19],sampleRate:r[24]<<8|r[25],objectType:a,codec:"mp4a.40."+a,ests:he(n)}}(e),e.bodyView&&(e.bodyView.codecType="aac");break;case"avcC":e.bodyView=function(e){var r=e.body,t={spsArr:[],ppsArr:[]},n=new te(r);t.configVersion=r[0],t.avcProfile=r[1],t.profileComptibility=r[2],t.avcLevel=r[3],n.forward(4),n.forward(1);var a=31&n.slice(1);n.forward(1);for(var i=0;i<a;i++){var o=n.readU16();n.forward(2),t.spsArr.push(n.subarray(o)),n.forward(o)}var s=n.slice(1);n.forward(1);for(var u=0;u<s;u++){var d=n.readU16();n.forward(2),t.ppsArr.push(n.subarray(d)),n.forward(d)}return t}(e);var i=e.bodyView;if(i.codecType="avc",null==i||!i.sps){var o=i.spsArr[0],s=y.removeEPB(o);i.sps=m.parseSPS(s)}break;case"hvcC":e.bodyView=function(e){var r=e.body;if(!(r.length<23)){r[21];for(var t,n,a,i=[],o=[],s=[],u=23,d=r[22],f=0;f<d;f++){t=63&r[u],n=r[u+1]<<8|r[u+2],u+=3;for(var c=0;c<n;c++)if(a=r[u]<<8|r[u+1],u+=2,a){switch(t){case 32:s.push(r.subarray(u,u+a));break;case 33:i.push(r.subarray(u,u+a));break;case 34:o.push(r.subarray(u,u+a))}u+=a}}return{spsArr:i,ppsArr:o,vpsArr:s}}}(e);var u=e.bodyView;if(u.codecType="bytevc1",null==u||!u.sps){var d=u.spsArr[0],f=y.removeEPB(d);u.sps=b.parseSPS(f)}break;case"btrt":e.bodyView=function(e){var r=e.body,t=new te(r),n=t.readU32();t.forward(4);var a=t.readU32();return t.forward(4),{bufferSizeDB:n,maxBitrate:a,avgBitrate:t.readU32()}}(e);break;case"stts":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(4);var n=t.readU32(),a=[];t.forward(4);for(var i=0;i<n;i++){var o=t.readU32();t.forward(4);var s=t.readU32();t.forward(4),a.push({sampleCount:o,sampleDelta:s})}return{entries:a,count:a.length}}(e),e.bodyView.entries.length&&(r=e.bodyView.entries[0].sampleCount);break;case"ctts":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(4);var n=t.readU32(),a=[];t.forward(4);for(var i=0;i<n;i++){var o=t.readU32();t.forward(4);var s=t.readU32();t.forward(4),a.push({sampleCount:o,sampleOffset:s})}return{entries:a,count:a.length}}(e);break;case"cslg":e.bodyView=function(e){var r,t,n,a,i=e.body,o=new te(i);return o.forward(4),r=o.read32(),o.forward(4),t=o.read32(),o.forward(4),n=o.read32(),o.forward(4),a=o.read32(),o.forward(4),{compositionToDTSShift:r,leastDecodeToDisplayDelta:t,greatestDecodeToDisplayDelta:n,compositionStartTime:a,compositionEndTime:o.read32()}}(e);break;case"stss":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(4);var n=[],a=t.readU32();t.forward(4);for(var i=0;i<a;i++){var o=t.readU32();n.push(o),t.forward(4)}return{entries:n,count:n.length}}(e);break;case"stsz":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(4);var n=[],a=t.readU32();t.forward(4);var i=t.readU32();if(t.forward(4),0===a)for(var o=0;o<i;o++){var s=t.readU32();n.push(s),t.forward(4)}else console.warn("parse stsz, sample size not equal 0");return{entries:n,count:n.length}}(e);break;case"stsc":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(4);var n=[],a=t.readU32();t.forward(4);for(var i=0;i<a;i++){var o=t.readU32();t.forward(4);var s=t.readU32();t.forward(4);var u=t.readU32();t.forward(4),n.push({firstChunk:o,samplesPreChunk:s,sampleDesIndex:u})}return{entries:n,count:n.length}}(e);break;case"stco":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(4);var n=t.readU32(),a=[];t.forward(4);for(var i=0;i<n;i++){var o=t.readU32();a.push(o),t.forward(4)}return{entries:a,count:a.length}}(e);break;case"sdtp":e.bodyView=function(e,r){var t=e.body,n=new te(t);n.forward(4);for(var a,i,o,s,u=[],d=0;d<r;d++){var f=n.readU8();a=(192&f)>>6,i=(48&f)>>4,o=(12&f)>>2,s=3&f,u.push({isLeading:a,dependsOn:i,isDenpendedOn:o,hasRedundancy:s}),n.forward(1)}return{entries:u}}(e,r);break;case"mfhd":e.bodyView=function(e){var r=e.body,t=new te(r);return t.forward(4),{seqNumber:t.readU32()}}(e);break;case"tfhd":e.bodyView=function(e){var r=e.body,t=new te(r);t.forward(1);var n=t.slice(3),a=n[0]<<16|n[1]<<8|n[2],i={flags:n},o={baseDataOffsetPresent:!!(1&a),sampleDescriptionIndexPresent:!!(2&a),defaultSampleDurationPresent:!!(8&a),defaultSampleSizePresent:!!(16&a),defaultSampleFlagsPresent:!!(32&a),durationIsEmpty:!!(65536&a),defaultBaseIsMoof:!!(131072&a)};if(i.tfFlags=o,t.forward(3),i.trackId=t.readU32(),o.baseDataOffsetPresent){t.forward(4);var s=t.readU32();t.forward(4);var u=t.readU32();i.baseDataOffset=s<<32|u}else i.baseDataOffset=0,console.warn("base data offset not detected in tfhd");return o.sampleDescriptionIndexPresent&&(t.forward(4),i.sampleDescriptionIndex=t.readU32()),o.defaultSampleDurationPresent&&(t.forward(4),i.defaultSampleDuration=t.readU32()),o.defaultSampleSizePresent&&(t.forward(4),i.defaultSampleSize=t.readU32()),o.defaultSampleFlagsPresent&&(t.forward(4),i.defaultSampleFlags=t.readU32()),i}(e);break;case"pssh":e.bodyView=me(e)}var c,l,p}))}var _e=function(){function e(){s(this,e)}return d(e,[{key:"parse",value:function(e){return ke(e)}},{key:"parseV2",value:function(e,r){var t,n,a,i,o,s,u=e.filter((function(e){return"mdat"===e.type})),d=[],f=null===(t=u[0])||void 0===t||null===(n=t.bodyView)||void 0===n?void 0:n.filter((function(e){return"video"===e.type}))[0],c=null===(a=u[0])||void 0===a||null===(i=a.bodyView)||void 0===i?void 0:i.filter((function(e){return"audio"===e.type}))[0],l=Math.min((null==c||null===(o=c.samples[0])||void 0===o?void 0:o.dtsTime)||0,(null==f||null===(s=f.samples[0])||void 0===s?void 0:s.dtsTime)||0);u.forEach((function(e){e.bodyView.forEach((function(e){e.samples.forEach((function(e){e.time=g(e.dtsTime-l),d.push(e)}))}))}));var p={items:d.sort((function(e,r){return e.time>r.time?1:-1}))};return this._addMetadataToFirstKeyFrame(f),p.rates=F(p),p}},{key:"getSnapshoot",value:function(e){return function(e){var r=e.filter((function(e){return"mdat"===e.type}));if(!r.length){var n,a,i,o,s,u=de(e,"vide"),d=de(e,"soun"),f=null===(n=ue(null==u?void 0:u.bodyView,"mdhd"))||void 0===n?void 0:n.bodyView,c=(null===(a=ue(null==u?void 0:u.bodyView,"avcC"))||void 0===a?void 0:a.bodyView)||(null===(i=ue(null==u?void 0:u.bodyView,"hvcC"))||void 0===i?void 0:i.bodyView),l=null===(o=ue(null==d?void 0:d.bodyView,"mdhd"))||void 0===o?void 0:o.bodyView,p=null===(s=ue(null==d?void 0:d.bodyView,"mp4a"))||void 0===s?void 0:s.bodyView;try{return{video:t(t({},f),{},{duration:(null==f?void 0:f.duration)/f.timescale},c),audio:t(t(t({},l),{},{duration:(null==l?void 0:l.duration)/l.timescale},p),p.ests)}}catch(k){}return{}}var v=r.map((function(e){return e.bodyView})).reduce((function(e,r){return e.concat(r)}),[]).reduce((function(e,r){var t,n=r.type,a=r.frameLength,i=r.iFrames,o=r.pFrames,s=r.bFrames,u=r.duration;return e[n]?(e[n].frameLength+=a,e[n].iFrames+=i,e[n].pFrames+=o,e[n].bFrames+=s,e[n].duration+=u,e):(e[n]=Object.assign({},r),e[n].refDuration||(e[n].refDuration=null===(t=r.samples[0])||void 0===t?void 0:t.duration),e)}),{}),h=v.video;if(h){var y=h.frameLength,m=h.iFrames,b=h.pFrames,w=h.bFrames;h.iPercent=g(m/y*100),h.pPercent=g(b/y*100),h.bPercent=g(w/y*100)}return v}(e)}},{key:"_addMetadataToFirstKeyFrame",value:function(e){if(e){var r=e.samples.filter((function(e){return e.keyframe}))[0];r&&(r.sps=e.sps,r.vpsArr=e.vpsArr,r.spsArr=e.spsArr,r.ppsArr=e.ppsArr)}}}]),e}(),Ve=function(){function e(){s(this,e)}return d(e,[{key:"parse",value:function(e){return this._parse(e)}},{key:"_parse",value:function(e){var r,n,a;switch(Y(e)){case H:r=q;break;case K:r=re;break;case W:r=_e}if(!r)throw new Error("not support format");var i=new r;return n=i.parse(e),i.getSnapshoot&&(a=i.getSnapshoot(n)),i.parseV2&&(n=i.parseV2(n)),t(t({},n),a)}}]),e}(),Te=function(){function e(r){var t=this;s(this,e),f(this,"_opts",null),f(this,"_controller",null),f(this,"_reader",null),f(this,"_loading",!1),f(this,"_chunks",[]),f(this,"_readStream",(function(e,r){var n=0;t._reader=e.getReader();var a=t._chunks;return function e(){var i;return null===(i=t._reader)||void 0===i?void 0:i.read().then((function(t){var i=t.value,o=t.done;return a.push(i),r(n,i),o?Promise.resolve(w(a.filter(Boolean))):(n+=i.byteLength,e())}))}()})),this._opts=r}return d(e,[{key:"request",value:function(){var e=this,r=this._opts,t=r.url,n=r.onProgress,a=r.contentType,i=void 0===a?"ArrayBuffer":a,o=r.loadTimeout,s=void 0===o?5e3:o,u=r.headers;return this._controller=new AbortController,Promise.race([fetch(t,{signal:this._controller.signal,headers:u}),new Promise((function(r,t){setTimeout((function(){var r;e._loading||(t({code:0,message:"timeout"}),null===(r=e._controller)||void 0===r||r.abort())}),s)}))]).then((function(r){return r.ok&&r.status>=200&&r.status<300?(e._loading=!0,r):Promise.reject({code:r.status,message:r.statusText})})).then((function(r){switch(i){case"TEXT":return r.text();case"JSON":return r.json();case"ArrayBuffer":return n?e._readStream(r.clone().body,n):r.arrayBuffer()}})).catch((function(r){if(e._loading=!1,"AbortError"!==r.name)return Promise.reject({code:r.code||0,message:r.message})}))}},{key:"cancel",value:function(){try{var e,r;null===(e=this._reader)||void 0===e||e.cancel(),null===(r=this._controller)||void 0===r||r.abort(),this._reader=null,this._controller=null}catch(t){}}}]),e}(),Ue=function(){function e(){s(this,e)}var r;return d(e,[{key:"parse",value:(r=o(n().mark((function e(r,a){var i,o,s,u,d,f,c,l=this;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return d=[],this._loader=new Te(t(t({url:r},a),{},{onProgress:function(e,r){d.push(r),e>a.probeSize&&l._loader.cancel()}})),e.next=4,this._loader.request();case 4:return f=(new q).parse(w(d)),c=null===(i=f.items.filter((function(e){return 9===e.type}))[0])||void 0===i?void 0:i.bodyView,e.abrupt("return",{codec:null==c?void 0:c.codecType,codecStr:null===(o=c.sps)||void 0===o?void 0:o.codec,width:null==c||null===(s=c.sps)||void 0===s?void 0:s.width,height:null==c||null===(u=c.sps)||void 0===u?void 0:u.height});case 7:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})}]),e}(),Ae=("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self,{exports:{}});function Pe(e){return Ee.apply(this,arguments)}function Ee(){return Ee=o(n().mark((function e(r){var a,i,o,s,u=arguments;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=u.length>1&&void 0!==u[1]?u[1]:{},i=new Te(t(t({url:r},a),{},{contentType:"TEXT"})),e.next=4,i.request();case 4:return o=e.sent,s=Ae.exports.m3u8Parser(o,r,(function(e,r){if(!e.url||!/^\//.test(e.url))return r;var t=e.url,n=r.segments[r.segments.length-1];return n.url=n.url.split("/").slice(0,3).join("/")+t,r})),e.abrupt("return",s);case 7:case"end":return e.stop()}}),e)}))),Ee.apply(this,arguments)}Ae.exports=function(e){var r={};function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,r){if(1&r&&(e=t(e)),8&r)return e;if(4&r&&"object"==a(e)&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)t.d(n,i,function(r){return e[r]}.bind(null,i));return n},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},t.p="",t(t.s=0)}([function(e,r,t){function n(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function i(e){return(i="function"==typeof Symbol&&"symbol"==a(Symbol.iterator)?function(e){return a(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":a(e)})(e)}function o(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}t.r(r),t.d(r,"m3u8Parser",(function(){return l})),t.d(r,"mpdParser",(function(){return m}));var s=/EXT(?:-X-)?([^:]+):?(.*)$/,u=/([^,="]+)((="[^"]+")|(=[^,]+))*/g;function d(e){return e.split("-").reduce((function(e,r){return e+(e?r.charAt(0)+r.slice(1).toLowerCase():r.toLowerCase())}),"")}function f(e){if(!/^#EXT/.test(e)&&/^\s*#/.test(e))return null;var r,t,a=s.exec(e);return a?(r=d(a[1]),t=function(e){if(!e)return null;var r=e.match(u).map((function(e){return function(e){var r=e.trim().replace("=","|").split("|");if(2==r.length)return o({},d(r[0]),r[1].replace(/("|')/g,""));var t=parseFloat(r[0]);return Number.isNaN(t)?r[0]:t}(e)}));return 1===r.length?r[0]:0===r.filter((function(e){return"object"===i(e)})).length?r:r.reduce((function(e,r){return function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?n(Object(t),!0).forEach((function(r){o(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):n(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}({},e,{},r)}),{})}(a[2])):(r="url",t=e),o({},r,t)}function c(e,r){if(/^https?/.test(e)||/^data:/.test(e)||/^sdk:/.test(e))return e;for(r=r.split("/").slice(0,-1),e=e.split("/");e.length;){var t=e.shift();-1==r.indexOf(t)&&r.push(t)}return r.join("/")}var l=function(e,r,t){if(!e||!r)return{error:1,msg:"invalid input"};var n,a=e.split("\n").filter(Boolean).map((function(e){return f(e.trim())})).filter(Boolean);if(!a.length)return{error:1,msg:"invalid m3u8"};n=0!==a.filter((function(e){return!!e.streamInf})).length?{master:!0,m3u8Url:r,levels:[],medias:[]}:{master:!1,m3u8Url:r,duration:0,startSN:0,endSN:0,segments:[],live:!0};try{n=function(e,r,t){for(var n=r.master,a=e.length,i=0,o=0,s=0,u=0,d=0,f=-1,l=0;l<a;l++){var p=e[l];for(var v in p){var h=p[v];switch(h&&h.uri&&(h.url=c(h.uri,r.m3u8Url)),v){case"inf":var y={start:o,end:o+(Array.isArray(h)?h[0]:h),cc:i,sn:s+u};f>=0&&(y.keyIndex=f),u++,o=y.end,r.segments.push(y);break;case"start":o=h;break;case"discontinuity":i++;break;case"mediaSequence":s=h;break;case"streamInf":d++,h.levelId=d,r.levels.push(h);break;case"media":r.medias.push(h);break;case"endlist":r.live=!1;break;case"key":f++,r.key?r.key.push(h):r.key=[h];break;case"url":var m=n?r.levels:r.segments;if(!m.length)throw new Error("invalid m3u8");n?m[d-1].url=c(h,r.m3u8Url):m[u-1].url=c(h,r.m3u8Url);break;default:h&&(r[v]=h)}}t&&(r=t(p,r))}return n||(r.startSN=s,r.endSN=s+u-1,r.duration=o),r}(a,n,t)}catch(i){return{error:1,msg:i.message}}return n},p=/\s*(<\/?[^>]+>)/,v=/\s*(?:<\/?([^\s>]+))?\s*([^>]+)*(?:\/?>)?/,h=/\s*([^=]+)="([^"]+)"/g;function y(e,r){for(var t,n,a,i=[],o=e.length,s=0;s<o;s++)if((t=e[s]).closed)if(n=i.pop(),"pureValue"!==t.tagName){if(n&&n.tagName===t.tagName?a=i.pop():(a=n,n=t),!a){i.push(n);break}var u=n,d=u.tagName,f=u.attrs,c=a.attrs[d];r&&(f=r(d,f)),a.attrs[d]=c?Array.isArray(c)?c.concat(f):[c,f]:f,i.push(a)}else n.attrs?n.attrs.value=t.attrs.value:n.attrs=t.attrs,i.push(n);else i.push(t);var l,p,v,h=i[0];return h?"undefined"!=h.tagName?(l={},p=h.tagName,v=h.attrs,p in l?Object.defineProperty(l,p,{value:v,enumerable:!0,configurable:!0,writable:!0}):l[p]=v,l):h.tagName:null}var m=function(e,r){if(!e)return{error:1,msg:"invalid input"};try{return y(e.split(p).filter(Boolean).map((function(e){return function(e){var r,t=e.match(v),n={},a=(r=t&&t[1])?r.split("_").reduce((function(e,r){return e?e+=r.charAt(0).toUpperCase()+r.slice(1):e=r.charAt(0).toLowerCase()+r.slice(1)}),""):"";if(t&&t[1]&&t[2]){for(var i,o={};null!=(i=h.exec(t[2]));)o[i[1]]=i[2];return"?xml"===a?null:(n.tagName=a,n.attrs=o,n.closed=/\/$/.test(t[2]),n)}return t?/^<\//.test(t[0])?(n.tagName=a,n.closed=!0,n):/^</.test(t[0])?(n.tagName=a,n.attrs={},n):(n.tagName="pureValue",n.attrs={value:t[2]},n.closed=!0,n):null}(e)})).filter(Boolean),r)}catch(t){return{error:1,msg:t.message}}}}]);var De=function(){function e(){s(this,e)}var r;return d(e,[{key:"parse",value:(r=o(n().mark((function e(r,a){var i,o,s,u,d,f,c,l,p,v,h,y,m;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Pe(r,a);case 2:if(!(l=e.sent).master){e.next=7;break}return e.next=6,Pe(l.levels[0].url);case 6:l=e.sent;case 7:if(null!==(i=l)&&void 0!==i&&i.segments.length){e.next=9;break}throw new Error("invalid m3u8");case 9:return p=[],v=new Te(t(t({url:l.segments[0].url},a),{},{onProgress:function(e,r){p.push(r),e>a.probeSize&&v.cancel()}})),e.next=13,v.request();case 13:return h=(new re).parse(new Uint8Array(w(p))),y=h.items.filter((function(e){return"PMT"===e.packetType}))[0],m=null===(o=h.items.filter((function(e){return"PES"===e.packetType&&e.isVideo&&e.keyframe}))[0])||void 0===o?void 0:o.bodyView,e.abrupt("return",{codec:null==y||null===(s=y.bodyView)||void 0===s||null===(u=s.video)||void 0===u?void 0:u.codecType,codecStr:null===(d=m.sps)||void 0===d?void 0:d.codec,width:null==m||null===(f=m.sps)||void 0===f?void 0:f.width,height:null==m||null===(c=m.sps)||void 0===c?void 0:c.height});case 17:case"end":return e.stop()}}),e)}))),function(e,t){return r.apply(this,arguments)})}]),e}(),Oe=function(){function e(){s(this,e)}var r;return d(e,[{key:"parse",value:(r=o(n().mark((function e(r,a){var i,o,s,u,d,f,c,l,p,v,h,y,m,b;return n().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return u=new Te(t(t({url:r},a),{},{contentType:"ArrayBuffer",headers:{Range:"bytes=0-1499"}})),d=[],e.next=4,u.request();case 4:return f=e.sent,c=new Uint8Array(f),l=(new _e).parse(c),p=l.find((function(e){return"mdat"===e.type})),(v=l.find((function(e){return"moov"===e.type})))?(d.push(v.start),d.push(v.start+v.size)):p&&d.push(p.start+p.size),u=new Te(t(t({url:r},a),{},{contentType:"ArrayBuffer",headers:{Range:"bytes=".concat(d[0],"-").concat(d[1]||"")}})),e.next=13,u.request();case 13:return h=e.sent,y=new _e,m=y.parse(h),b=y.getSnapshoot(m).video,e.abrupt("return",{codec:null==b?void 0:b.codecType,codecStr:null===(i=b.sps)||void 0===i?void 0:i.codec,width:null==b||null===(o=b.sps)||void 0===o?void 0:o.width,height:null==b||null===(s=b.sps)||void 0===s?void 0:s.height});case 18:case"end":return e.stop()}}),e)}))),function(e,t){return r.apply(this,arguments)})}]),e}(),Be=function(){function e(){s(this,e)}return d(e,[{key:"parseUrl",value:function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{timeout:5e3,probeSize:8e4};return/flv/.test(e)?(new Ue).parse(e,r):/m3u8?/.test(e)?(new De).parse(e,r):(new Oe).parse(e,r)}}]),e}();e.LoadProbe=Be,e.Probe=Ve,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
2
+ //# sourceMappingURL=index.min.js.map