flvplayer.js 49 KB

12345678
  1. /*!
  2. * FlvPlayer.js v1.1.8
  3. * Github: https://github.com/zhw2590582/FlvPlayer#readme
  4. * (c) 2017-2023 Harvey Zack
  5. * Released under the MIT License.
  6. */
  7. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).FlvPlayer=t()}(this,(function(){"use strict";"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function t(e,t){return e(t={exports:{}},t.exports),t.exports}var r=t((function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports})),n=e(r),o=t((function(e){var t=r.default;e.exports=function(e,r){if("object"!==t(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,r||"default");if("object"!==t(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports}));e(o);var i=t((function(e){var t=r.default;e.exports=function(e){var r=o(e,"string");return"symbol"===t(r)?r:String(r)},e.exports.__esModule=!0,e.exports.default=e.exports}));e(i);var a=e(t((function(e){e.exports=function(e,t,r){return(t=i(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports}))),u=e(t((function(e){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},e.exports.__esModule=!0,e.exports.default=e.exports}))),c=e(t((function(e){function t(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,i(n.key),n)}}e.exports=function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e},e.exports.__esModule=!0,e.exports.default=e.exports}))),s=t((function(e){function t(r,n){return e.exports=t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r,n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}));e(s);var f=e(t((function(e){e.exports=function(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&&s(e,t)},e.exports.__esModule=!0,e.exports.default=e.exports}))),d=t((function(e){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e},e.exports.__esModule=!0,e.exports.default=e.exports}));e(d);var l=t((function(e){var t=r.default;e.exports=function(e,r){if(r&&("object"===t(r)||"function"==typeof r))return r;if(void 0!==r)throw new TypeError("Derived constructors may only return object or undefined");return d(e)},e.exports.__esModule=!0,e.exports.default=e.exports})),p=e(l),h=t((function(e){function t(r){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports})),y=e(h),m=t((function(e,t){e.exports=function(){function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}var t=Object.prototype.toString,r=function(r){if(void 0===r)return"undefined";if(null===r)return"null";var o=e(r);if("boolean"===o)return"boolean";if("string"===o)return"string";if("number"===o)return"number";if("symbol"===o)return"symbol";if("function"===o)return function(e){return"GeneratorFunction"===n(e)}(r)?"generatorfunction":"function";if(function(e){return Array.isArray?Array.isArray(e):e instanceof Array}(r))return"array";if(function(e){return!(!e.constructor||"function"!=typeof e.constructor.isBuffer)&&e.constructor.isBuffer(e)}(r))return"buffer";if(function(e){try{if("number"==typeof e.length&&"function"==typeof e.callee)return!0}catch(e){if(-1!==e.message.indexOf("callee"))return!0}return!1}(r))return"arguments";if(function(e){return e instanceof Date||"function"==typeof e.toDateString&&"function"==typeof e.getDate&&"function"==typeof e.setDate}(r))return"date";if(function(e){return e instanceof Error||"string"==typeof e.message&&e.constructor&&"number"==typeof e.constructor.stackTraceLimit}(r))return"error";if(function(e){return e instanceof RegExp||"string"==typeof e.flags&&"boolean"==typeof e.ignoreCase&&"boolean"==typeof e.multiline&&"boolean"==typeof e.global}(r))return"regexp";switch(n(r)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(e){return"function"==typeof e.throw&&"function"==typeof e.return&&"function"==typeof e.next}(r))return"generator";switch(o=t.call(r)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return o.slice(8,-1).toLowerCase().replace(/\s/g,"")};function n(e){return e.constructor?e.constructor.name:null}function o(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return i(e,t,n),a(e,t,n),function(e,t,n){var u=r(t),c=r(e);if("object"===u){if("object"!==c)throw new Error("[Type Error]: '".concat(n.join("."),"' require 'object' type, but got '").concat(c,"'"));Object.keys(t).forEach((function(r){var u=e[r],c=t[r],s=n.slice();s.push(r),i(u,c,s),a(u,c,s),o(u,c,s)}))}if("array"===u){if("array"!==c)throw new Error("[Type Error]: '".concat(n.join("."),"' require 'array' type, but got '").concat(c,"'"));e.forEach((function(r,u){var c=e[u],s=t[u]||t[0],f=n.slice();f.push(u),i(c,s,f),a(c,s,f),o(c,s,f)}))}}(e,t,n),e}function i(e,t,n){if("string"===r(t)){var o=r(e);if("?"===t[0]&&(t=t.slice(1)+"|undefined"),!(-1<t.indexOf("|")?t.split("|").map((function(e){return e.toLowerCase().trim()})).filter(Boolean).some((function(e){return o===e})):t.toLowerCase().trim()===o))throw new Error("[Type Error]: '".concat(n.join("."),"' require '").concat(t,"' type, but got '").concat(o,"'"))}}function a(e,t,n){if("function"===r(t)){var o=t(e,r(e),n);if(!0!==o){var i=r(o);throw"string"===i?new Error(o):"error"===i?o:new Error("[Validator Error]: The scheme for '".concat(n.join("."),"' validator require return true, but got '").concat(o,"'"))}}}return o.kindOf=r,o}()}));function g(){return function(){try{if("object"===n(window.WebAssembly)&&"function"==typeof window.WebAssembly.instantiate){var e=new window.WebAssembly.Module(Uint8Array.of(0,97,115,109,1,0,0,0));if(e instanceof window.WebAssembly.Module)return new window.WebAssembly.Instance(e)instanceof window.WebAssembly.Instance}return!1}catch(e){return!1}}()&&"function"==typeof window.Worker&&"function"==typeof window.fetch&&"function"==typeof window.Blob&&function(){try{return!!new window.Blob}catch(e){return!1}}()&&"function"==typeof window.ArrayBuffer&&window.URL&&"function"==typeof window.URL.createObjectURL&&("probably"===(e=(new Audio).canPlayType("audio/aac;"))||"maybe"===e)&&(window.AudioContext||window.webkitAudioContext)&&function(){if(window.WebGLRenderingContext){for(var e=document.createElement("canvas"),t=["webgl2","webgl","experimental-webgl","moz-webgl","webkit-3d"],r=!1,n=0;n<t.length;n+=1)try{if((r=e.getContext(t[n]))&&"function"==typeof r.getParameter)return!0}catch(e){}return!1}return!1}();var e}var b=function(){function e(){u(this,e)}return c(e,[{key:"on",value:function(e,t,r){var n=this.e||(this.e={});return(n[e]||(n[e]=[])).push({fn:t,ctx:r}),this}},{key:"once",value:function(e,t,r){var n=this;function o(){n.off(e,o);for(var i=arguments.length,a=new Array(i),u=0;u<i;u++)a[u]=arguments[u];t.apply(r,a)}return o._=t,this.on(e,o,r)}},{key:"emit",value:function(e){for(var t=((this.e||(this.e={}))[e]||[]).slice(),r=arguments.length,n=new Array(r>1?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];for(var i=0;i<t.length;i+=1)t[i].fn.apply(t[i].ctx,n);return this}},{key:"off",value:function(e,t){var r=this.e||(this.e={}),n=r[e],o=[];if(n&&t)for(var i=0,a=n.length;i<a;i+=1)n[i].fn!==t&&n[i].fn._!==t&&o.push(n[i]);return o.length?r[e]=o:delete r[e],this}}]),e}(),v=t((function(e){e.exports=function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}},e.exports.__esModule=!0,e.exports.default=e.exports}));e(v);var w=t((function(e){e.exports=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}},e.exports.__esModule=!0,e.exports.default=e.exports}));e(w);var x=t((function(e){function t(r,n,o){return w()?(e.exports=t=Reflect.construct.bind(),e.exports.__esModule=!0,e.exports.default=e.exports):(e.exports=t=function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&s(o,r.prototype),o},e.exports.__esModule=!0,e.exports.default=e.exports),t.apply(null,arguments)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}));e(x);var S=t((function(e){function t(r){var n="function"==typeof Map?new Map:void 0;return e.exports=t=function(e){if(null===e||!v(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(e))return n.get(e);n.set(e,t)}function t(){return x(e,arguments,h(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),s(t,e)},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}));function k(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=y(e);if(t){var o=y(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return p(this,r)}}var O=function(e){f(r,e);var t=k(r);function r(e){var n;return u(this,r),(n=t.call(this,e)).name="FlvPlayerError",n}return c(r)}(e(S)(Error)),P=c((function e(t){u(this,e);var r=t.options.debug;this.log=function(e){if(r){for(var t,n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];(t=console).log.apply(t,["FlvPlayer: [".concat(e,"]")].concat(o))}},this.warn=function(e){if(!e&&r){for(var t,n=arguments.length,o=new Array(n>1?n-1:0),i=1;i<n;i++)o[i-1]=arguments[i];(t=console).warn.apply(t,o)}},this.error=function(e,t){if(!e)throw new O(t)}})),A=function(){function e(t){var r=this;u(this,e),this.destroys=[],this.proxy=this.proxy.bind(this),t.on("destroy",(function(){r.destroy()}))}return c(e,[{key:"proxy",value:function(e,t,r){var n=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(Array.isArray(t))return t.map((function(t){return n.proxy(e,t,r,o)}));e.addEventListener(t,r,o);var i=function(){return e.removeEventListener(t,r,o)};return this.destroys.push(i),i}},{key:"destroy",value:function(){this.destroys.forEach((function(e){return e()}))}}]),e}();function j(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function _(){return/MicroMessenger/i.test(navigator.userAgent)}function C(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function T(e){var t=0;function r(n){for(var o=new Uint8Array(n),i=0;i<n;i+=1)o[i]=e[t],t+=1;return r.index=t,o}return r.index=0,r}function D(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=t[0].constructor;return t.reduce((function(e,t){var r=new n((0|e.byteLength)+(0|t.byteLength));return r.set(e,0),r.set(t,0|e.byteLength),r}),new n)}function M(){return performance&&"function"==typeof performance.now?performance.now():Date.now()}function R(e,t){var r,n,o=!1;return function i(){for(var a=arguments.length,u=new Array(a),c=0;c<a;c++)u[c]=arguments[c];if(o)return r=u,void(n=this);o=!0,e.apply(this,u),setTimeout((function(){o=!1,r&&(i.apply(n,r),r=null,n=null)}),t)}}function E(e,t,r){return Math.max(Math.min(e,Math.max(t,r)),Math.min(t,r))}function L(e,t){return new Promise((function(r,n){var o=document.createElement("script");o.type="text/javascript",o.onload=function(){window[t]?r(window[t]):n(new Error("Unable to find global variable '".concat(t,"' from '").concat(e,"'")))},o.onerror=function(){n(new Error("Resource loading failed '".concat(e,"'")))},o.src=e,document.head.appendChild(o)}))}function B(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return r.reduce((function(e,t){return Object.getOwnPropertyNames(t).forEach((function(r){if(C(e,r))throw new Error("Target attribute name is duplicated: ".concat(r));Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}),e)}function F(e){var t=0,r=M();return function(n){t+=n;var o=M(),i=o-r;i>=1e3&&(e(t/i*1e3),r=o,t=0)}}var V=Object.freeze({__proto__:null,isMobile:j,isWechat:_,hasOwnProperty:C,readBuffer:T,mergeBuffer:D,createWorker:function(e){return new Worker(URL.createObjectURL(new Blob([e],{type:"application/javascript"})))},secondToTime:function(e){var t=Math.floor(e/3600),r=Math.floor((e-3600*t)/60),n=Math.floor(e-3600*t-60*r);return(t>0?[t,r,n]:[r,n]).map((function(e){return e<10?"0".concat(e):String(e)})).join(":")},getNowTime:M,debounce:function(e,t,r){var n;function o(){for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];clearTimeout(n),n=setTimeout((function(){n=null,e.apply(r,i)}),t)}return o.clearTimeout=function(){clearTimeout(n)},o},throttle:R,clamp:E,setStyle:function e(t,r,o){return"object"===n(r)&&Object.keys(r).forEach((function(n){e(t,n,r[n])})),t.style[r]=o,t},getStyle:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=getComputedStyle(e,null).getPropertyValue(t);return r?parseFloat(n):n},loadScript:L,proxyPropertys:B,calculationRate:F});var U=c((function e(t){u(this,e),function(e,t){var r=e.options,n=r.container.style.cssText;r.container.classList.add("flvplayer-container"),r.container.innerHTML='<div class="flvplayer-player"><canvas class="flvplayer-canvas" width="'.concat(r.width,'" height="').concat(r.height,'"></canvas></div>'),e.on("destroy",(function(){r.container.innerHTML="",r.container.style.cssText=n,r.container.classList.remove("flvplayer-container")})),Object.defineProperty(t,"$container",{value:r.container}),Object.defineProperty(t,"$player",{value:r.container.querySelector(".flvplayer-player")}),Object.defineProperty(t,"$canvas",{value:r.container.querySelector(".flvplayer-canvas")})}(t,this),function(e,t){Object.defineProperty(t,"rect",{get:function(){return t.$container.getBoundingClientRect()}}),["bottom","height","left","right","top","width"].forEach((function(e){Object.defineProperty(t,e,{get:function(){return t.rect[e]}})})),Object.defineProperty(t,"currentTime",{get:function(){return e.decoder.currentTime},set:function(r){e.options.cache&&e.decoder.seeked(E(r,0,t.loaded))}}),Object.defineProperty(t,"streaming",{get:function(){return e.demuxer.streaming}}),Object.defineProperty(t,"demuxed",{get:function(){return e.demuxer.demuxed}}),Object.defineProperty(t,"videoDecoding",{get:function(){return e.decoder.video.decoding}}),Object.defineProperty(t,"audioDecoding",{get:function(){return e.decoder.audio.decoding}}),Object.defineProperty(t,"duration",{get:function(){try{return e.demuxer.scripMeta.amf2.metaData.duration||e.options.duration}catch(t){return e.options.duration}}}),Object.defineProperty(t,"frameRate",{get:function(){var t=Math.round(e.options.frameRate||30);try{return Math.round(e.demuxer.scripMeta.amf2.metaData.framerate)||t}catch(e){return t}}}),Object.defineProperty(t,"frameDuration",{get:function(){return 1e3/t.frameRate|0}}),Object.defineProperty(t,"muted",{get:function(){return e.decoder.audio.muted},set:function(t){e.decoder.audio.muted=t}}),Object.defineProperty(t,"volume",{get:function(){try{return e.decoder.audio.volume}catch(e){return 0}},set:function(r){try{return e.decoder.audio.volume=E(r,0,1),t.volume}catch(e){return r}}}),Object.defineProperty(t,"loaded",{get:function(){return e.decoder.video.loaded}}),Object.defineProperty(t,"playing",{get:function(){return e.decoder.playing}}),Object.defineProperty(t,"ended",{get:function(){return e.decoder.ended}}),Object.defineProperty(t,"play",{value:function(){t.playing||e.decoder.play()}}),Object.defineProperty(t,"pause",{value:function(){e.decoder.pause()}}),Object.defineProperty(t,"toggle",{value:function(){t.playing?t.pause():t.play()}})}(t,this),function(e,t){var r=e.events.proxy;e.on("scripMeta",(function(e){var r=e.amf2.metaData,n=r.width,o=r.height;n&&o&&(t.$canvas.width=n,t.$canvas.height=o)})),r(t.$canvas,"click",(function(){t.toggle()}))}(t,this)}));function I(e,t,r){return Math.max(Math.min(e,Math.max(t,r)),Math.min(t,r))}function z(...e){const t=e[0].constructor;return e.reduce(((e,r)=>{const n=new t((0|e.byteLength)+(0|r.byteLength));return n.set(e,0),n.set(r,0|e.byteLength),n}),new t)}class W{constructor(e={}){if(this.option=m({...W.option,...e},W.scheme),this.option.volume=I(this.option.volume,0,1),this.option.chunk=I(this.option.chunk,0,1/0),this.option.maxTimeDiff=I(this.option.maxTimeDiff,0,1/0),this.option.autoEndTime=I(this.option.autoEndTime,0,1/0),this.context=new(window.AudioContext||window.webkitAudioContext),this.gainNode=this.context.createGain(),this.gainNode.gain.value=this.option.volume,this.source=null,this.decoding=!1,this.playing=!1,this.loadLength=0,this.loadByteSize=0,this.audioDuration=0,this.pcmLength=0,this.timestamps=[],this.audiobuffers=[],this.timestampTmp=[],this.decodeErrorBuffer=new Uint8Array,this.decodeWaitingBuffer=new Uint8Array,this.autoEndDebounce=function(e,t,r){let n;return function(...o){clearTimeout(n),n=setTimeout((function(){n=null,e.apply(r,o)}),t)}}((()=>{this.end()}),this.option.autoEndTime),this.option.touchResume&&"suspended"===this.context.state&&"ontouchstart"in window){const e=()=>{this.context.resume(),this.volume=1,document.body.removeEventListener("touchstart",e,!1),document.body.removeEventListener("click",e,!1)};document.body.addEventListener("touchstart",e,!1),document.body.addEventListener("click",e,!1)}}static get option(){return{volume:.7,cache:!0,chunk:65536,maxTimeDiff:200,autoEnd:!0,autoEndTime:5e3,touchResume:!0,onNext:e=>e,onLoad:()=>null,onStop:()=>null,onPlay:()=>null,onEnd:()=>null,onDestroy:()=>null,onDecodeDone:()=>null,onDecodeError:()=>null,onVolumeChange:()=>null,onFreeMemory:()=>null}}static get scheme(){return{volume:"number",cache:"boolean",chunk:"number",maxTimeDiff:"number",autoEnd:"boolean",autoEndTime:"number",touchResume:"boolean",onNext:"function",onLoad:"function",onStop:"function",onPlay:"function",onEnd:"function",onDestroy:"function",onDecodeDone:"function",onDecodeError:"function",onVolumeChange:"function",onFreeMemory:"function"}}get volume(){return this.gainNode.gain.value}set volume(e){this.gainNode.gain.value=I(e,0,1),this.option.onVolumeChange(e)}get duration(){return this.audiobuffers.reduce(((e,t)=>e+=t.duration),0)}destroy(){return this.stop(),this.context=null,this.gainNode=null,this.source=null,this.timestamps=[],this.audiobuffers=[],this.timestampTmp=[],this.decodeErrorBuffer=new Uint8Array,this.decodeWaitingBuffer=new Uint8Array,this.option.onDestroy(),this}load(e,t){if(this.decoding=!0,this.loadLength+=1,this.loadByteSize+=e.byteLength,this.option.onLoad(e,t),this.decodeWaitingBuffer.byteLength>=this.option.chunk){this.timestamps.push(this.timestampTmp[0]),this.timestampTmp=[];const{buffer:e}=z(this.decodeErrorBuffer,this.decodeWaitingBuffer);this.decodeWaitingBuffer=new Uint8Array,this.context.decodeAudioData(e,(e=>{this.audioDuration+=e.duration,this.pcmLength+=e.length,this.audiobuffers.push(e),this.decodeErrorBuffer=new Uint8Array,this.option.onDecodeDone(e)}),(e=>{this.decodeErrorBuffer=z(this.decodeErrorBuffer,this.decodeWaitingBuffer),this.option.onDecodeError(e)}))}else this.timestampTmp.push(t),this.decodeWaitingBuffer=z(this.decodeWaitingBuffer,e);return this.option.autoEnd&&this.autoEndDebounce(),this}end(){if(this.decodeWaitingBuffer.length){this.timestamps.push(this.timestampTmp[0]),this.timestampTmp=[];const{buffer:e}=this.decodeWaitingBuffer;this.decodeWaitingBuffer=new Uint8Array,this.decodeErrorBuffer=new Uint8Array,this.context.decodeAudioData(e,(e=>{this.audioDuration+=e.duration,this.pcmLength+=e.length,this.audiobuffers.push(e),this.decoding=!1,this.option.onEnd()}))}return this}findIndex(e){return this.timestamps.findIndex(((t,r)=>{const n=this.audiobuffers[r];return n&&t+1e3*n.duration>=e}))}play(e=0){this.source&&(this.source.onended=null,this.source.stop(),this.source=null),e+=1,this.playing=!0;const t=this.findIndex(e),r=this.timestamps[t],n=this.audiobuffers[t];if(void 0===r||void 0===n)return this.stop(t,r);const o=Math.max(0,(e-r)/1e3);return this.source=this.context.createBufferSource(),this.source.connect(this.gainNode),this.gainNode.connect(this.context.destination),this.source.buffer=n,this.option.onPlay(n,e,o),this.source.start(0,o),this.source.onended=()=>{const e=this.timestamps[t+1],n=this.audiobuffers[t+1];if(void 0!==e&&void 0!==n){const t=this.option.onNext(e),r=this.findIndex(t);!this.option.cache&&r>0&&(this.option.onFreeMemory({total:this.pcmLength,pcm:this.audiobuffers.reduce(((e,t)=>e+=t.length),0),index:r}),this.audiobuffers.splice(0,r),this.timestamps.splice(0,r)),this.play(t)}else this.stop(t,r)},this}stop(e,t){return this.playing=!1,this.source&&(this.source.onended=null,this.source.stop(),this.source=null),this.option.onStop(e,t),this}}var q=function(){function e(t,r){var n=this;u(this,e),this.flv=t,this.dida=new W({volume:t.options.muted?0:t.options.volume,cache:t.options.cache,chunk:t.options.audioChunk,maxTimeDiff:t.options.maxTimeDiff,touchResume:t.options.touchResume,onNext:function(e){var n=e-1e3*r.currentTime;return t.debug.log("time-diff",n),Math.abs(n)>=t.options.maxTimeDiff&&(t.debug.log("time-sync",n),r.currentTime=e/1e3),e},onVolumeChange:function(e){t.emit("volumechange",e)},onFreeMemory:function(e){t.debug.log("free-audio-memory",e),t.emit("freeAudioMemory",e)}}),t.on("audioData",(function(e,t){n.dida.load(e,t)})),t.on("destroy",(function(){n.dida.destroy()}))}return c(e,[{key:"muted",get:function(){return 0===this.volume},set:function(e){this.volume=e?0:.7}},{key:"volume",get:function(){return this.dida.volume},set:function(e){this.dida.volume=e}},{key:"decoding",get:function(){return this.dida.decoding}},{key:"playing",get:function(){return this.dida.playing}},{key:"play",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;this.dida.play(1e3*e)}},{key:"stop",value:function(){this.dida.stop()}}]),e}(),N=function(){function e(t){var r=this;u(this,e),this.flv=t,this.ended=!1,this.playing=!1,this.waiting=!1,this.animationFrameTimer=null,this.waitingTimer=null,this.currentTime=0,this.lastUpdateTime=0,this.video=new window.FlvplayerDecoder(t,this),t.options.hasAudio?this.audio=new q(t,this):this.audio={play:function(){return null},stop:function(){return null},playing:!0,decoding:!1},t.on("ready",(function(){t.options.autoPlay?r.play():r.video.draw(0)})),t.on("destroy",(function(){r.pause()})),t.on("timeupdate",(function(e){!t.options.live&&e>=t.player.duration&&r.pause()}));var n=!1;t.events.proxy(document,"visibilitychange",(function(){document.hidden?(n=r.playing,r.pause()):n&&r.play()}))}return c(e,[{key:"play",value:function(){this.lastUpdateTime=M(),this.video.play(this.currentTime),this.audio.play(this.currentTime),this.animationFrame(),this.flv.emit("play")}},{key:"animationFrame",value:function(){var e=this,t=this.flv,r=t.options,n=t.player,o=t.debug;this.animationFrameTimer=requestAnimationFrame((function(){if(!e.video.playing||!e.audio.playing)return n.streaming||e.video.decoding||e.audio.decoding?(e.ended=!1,e.playing=!0,e.waiting=!0,e.flv.emit("waiting",e.currentTime),void(e.waitingTimer=setTimeout((function(){o.log("play-retry",{streaming:n.streaming,playing:{video:e.video.playing,audio:e.audio.playing},decoding:{video:e.video.decoding,audio:e.audio.decoding}}),e.play()}),r.live?3e3:1e3))):(e.ended=!0,e.playing=!1,e.waiting=!1,e.pause(),e.flv.emit("ended",e.currentTime),void(r.loop&&r.cache&&!r.live&&(e.currentTime=0,e.play(),e.flv.emit("loop"))));e.ended=!1,e.playing=!0,e.waiting=!1;var t=M();e.currentTime+=(t-e.lastUpdateTime)/1e3,e.lastUpdateTime=t,e.flv.emit("timeupdate",e.currentTime),e.animationFrame()}))}},{key:"pause",value:function(){cancelAnimationFrame(this.animationFrameTimer),clearTimeout(this.waitingTimer),this.animationFrameTimer=null,this.waitingTimer=null,this.video.stop(),this.audio.stop(),this.ended=!1,this.playing=!1,this.waiting=!1,this.flv.emit("pause")}},{key:"seeked",value:function(e){var t=this.flv,r=t.player,n=t.options;n.cache&&!n.live&&(cancelAnimationFrame(this.animationFrameTimer),clearTimeout(this.waitingTimer),this.animationFrameTimer=null,this.waitingTimer=null,this.currentTime=e,this.video.draw(Math.floor(e*r.frameRate)),this.playing&&this.play(),this.flv.emit("seeked",e))}}]),e}();var H=c((function e(t){var r=this;u(this,e);var n=t.options,o=t.debug;this.header=null,this.streaming=!1,this.demuxed=!1,this.videoDataSize=0,this.audioDataSize=0,this.videoDataLength=0,this.audioDataLength=0,this.streamStartTime=0,this.streamEndTime=0,this.scripMeta=null,this.AudioSpecificConfig=null,this.AVCDecoderConfigurationRecord=null,this.demuxWorker=new Worker(URL.createObjectURL(new Blob(['"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"===_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!==_typeof(a)||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!==_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return a}function _wrapNativeSuper(a){var b="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(a){function c(){return _construct(a,arguments,_getPrototypeOf(this).constructor)}if(null===a||!_isNativeFunction(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(c,a)},_wrapNativeSuper(a)}function _construct(){return _construct=_isNativeReflectConstruct()?Reflect.construct.bind():function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _isNativeFunction(a){try{return-1!==Function.toString.call(a).indexOf("[native code]")}catch(b){return"function"==typeof a}}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}var FlvPlayerError=/*#__PURE__*/function(a){function b(a){var d;return _classCallCheck(this,b),d=c.call(this,a),d.name="FlvPlayerError",d}_inherits(b,a);var c=_createSuper(b);return _createClass(b)}(/*#__PURE__*/_wrapNativeSuper(Error)),debug={warn:function warn(a){if(!a){for(var b,c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];(b=console).warn.apply(b,d)}},error:function error(a,b){if(!a)throw new FlvPlayerError(b)}};function mergeBuffer(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];var d=b[0].constructor;return b.reduce(function(a,b){var c=new d((0|a.byteLength)+(0|b.byteLength));return c.set(a,0),c.set(b,0|a.byteLength),c},new d)}function readBufferSum(a){var b=!(1<arguments.length&&arguments[1]!==void 0)||arguments[1];return a.reduce(function(c,d,e){return c+(b?d:d-128)*Math.pow(256,a.length-e-1)},0)}function readString(a){return String.fromCharCode.apply(String,a)}function readBuffer(a){function b(d){for(var e=new Uint8Array(d),f=0;f<d;f+=1)e[f]=a[c],c+=1;return b.index=c,e}var c=0;return b.index=0,b}function readDouble(a){var c=new DataView(new ArrayBuffer(a.length));return a.forEach(function(a,b){c.setUint8(b,a)}),c.getFloat64(0)}function readBoolean(a){return 0!==a[0]}var index=0,header=null,uint8=new Uint8Array,scripMeta=null,AudioSpecificConfig=null,AVCDecoderConfigurationRecord=null,nalStart=new Uint8Array([0,0,0,1]);function readable(a){return uint8.length-index>=a}function read(a){for(var b=new Uint8Array(a),c=0;c<a;c+=1)b[c]=uint8[index],index+=1;return b}function demuxerScripTag(a){function b(a){var d=null;if(a!==void 0)switch(a){case 0:d=readDouble(c(8));break;case 1:d=readBoolean(c(1));break;case 2:{var e=readBufferSum(c(2));d=readString(c(e));break}case 3:{d=Object.create(null);for(var f=-1;9!==f;){var g=readBufferSum(c(2)),h=readString(c(g)),j=c(1)[0];h&&(d[h]=b(j)),f=j}break}case 5:d=null;break;case 6:d=void 0;break;case 7:d="Reference #".concat(c.index),c(2);break;case 8:{d=Object.create(null);for(var k=-1;9!==k;){var l=readBufferSum(c(2)),m=readString(c(l)),n=c(1)[0];m&&(d[m]=b(n)),k=n}break}case 10:{var o=readBufferSum(c(4));d=[];for(var p,q=0;q<o;q+=1)p=c(1)[0],d.push(b(p));break}case 11:d=readDouble(c(2));break;case 12:{var r=readBufferSum(c(4));d=readString(c(r));break}default:debug.error(!1,"AMF: Unknown metaData type: ".concat(a))}return d}var c=readBuffer(a.body),d=Object.create(null),e=Object.create(null);for(d.type=c(1)[0],debug.error(2===d.type,"AMF: [amf1] type expect 2, but got ".concat(d.type)),d.size=readBufferSum(c(2)),d.string=readString(c(d.size)),e.type=c(1)[0],debug.error(8===e.type||3===e.type,"AMF: [amf2] type expect 8 or 3, but got ".concat(e.type)),e.size=readBufferSum(c(4)),e.metaData=Object.create(null);c.index<a.body.length;){var f=readBufferSum(c(2)),g=readString(c(f)),h=c(1)[0];g&&(e.metaData[g]=b(h))}debug.warn(c.index===a.body.length,"[AMF] Seems to be incompletely parsed"),debug.warn(e.size===Object.keys(e.metaData).length,"[AMF] [amf2] length does not match"),scripMeta={amf1:d,amf2:e},postMessage({type:"scripMeta",data:scripMeta})}function demuxerVideoTag(a){debug.error(1<a.body.length,"Invalid video packet");var b={frameType:(240&a.body[0])>>4,codecID:15&a.body[0]};debug.error(7===b.codecID,"[videoTrack] Unsupported codec in video frame: ".concat(b.codecID));var c=a.body.slice(1,5);debug.error(4<=c.length,"[H264] Invalid AVC packet, missing AVCPacketType or/and CompositionTime");var d=new DataView(c.buffer),e=d.getUint8(0),f=(16777215&d.getUint32(0))<<8>>8,g=f+a.timestamp,h=a.body.subarray(5);if(0===e){debug.warn(!AVCDecoderConfigurationRecord,"[h264] Find another one AVCDecoderConfigurationRecord"),debug.error(7<=h.length,"[H264] AVCDecoderConfigurationRecord parse length is not enough");var j=readBuffer(h),k={};k.configurationVersion=j(1)[0],debug.error(1===k.configurationVersion,"[H264] Invalid configurationVersion: ".concat(k.configurationVersion)),k.AVCProfileIndication=j(1)[0],debug.error(0!==k.AVCProfileIndication,"[H264] Invalid AVCProfileIndication: ".concat(k.AVCProfileIndication)),k.profile_compatibility=j(1)[0],k.AVCLevelIndication=j(1)[0],k.lengthSizeMinusOne=(3&j(1)[0])+1,debug.error(4===k.lengthSizeMinusOne||3!==k.lengthSizeMinusOne,"[H264] Invalid lengthSizeMinusOne: ".concat(k.lengthSizeMinusOne)),k.numOfSequenceParameterSets=31&j(1)[0],debug.error(0!==k.numOfSequenceParameterSets,"[H264] Invalid numOfSequenceParameterSets: ".concat(k.numOfSequenceParameterSets)),debug.warn(1===k.numOfSequenceParameterSets,"[H264] Strange numOfSequenceParameterSets: ".concat(k.numOfSequenceParameterSets));for(var l=0;l<k.numOfSequenceParameterSets;l+=1)if(k.sequenceParameterSetLength=readBufferSum(j(2)),0<k.sequenceParameterSetLength){var m=j(k.sequenceParameterSetLength);postMessage({type:"videoData",data:mergeBuffer(nalStart,m)})}k.numOfPictureParameterSets=j(1)[0],debug.error(0!==k.numOfPictureParameterSets,"[H264] Invalid numOfPictureParameterSets: ".concat(k.numOfPictureParameterSets)),debug.warn(1===k.numOfPictureParameterSets,"[H264] Strange numOfPictureParameterSets: ".concat(k.numOfPictureParameterSets));for(var n=0;n<k.numOfPictureParameterSets;n+=1)if(k.pictureParameterSetLength=readBufferSum(j(2)),0<k.pictureParameterSetLength){var o=j(k.pictureParameterSetLength);postMessage({type:"videoData",data:mergeBuffer(nalStart,o)})}AVCDecoderConfigurationRecord=k,postMessage({type:"AVCDecoderConfigurationRecord",data:k})}else if(1===e)for(var p,q=AVCDecoderConfigurationRecord,r=q.lengthSizeMinusOne,s=readBuffer(h);s.index<h.length;)p=readBufferSum(s(r)),postMessage({type:"videoData",data:mergeBuffer(nalStart,s(p)),timestamp:g});else debug.error(2===e,"[H264] Invalid video packet type ".concat(e))}function demuxerAudioTag(a){debug.error(1<a.body.length,"Invalid audio packet");var b={soundFormat:(240&a.body[0])>>4,soundRate:(12&a.body[0])>>2,soundSize:(2&a.body[0])>>1,soundType:(1&a.body[0])>>0};debug.error(10===b.soundFormat,"[audioTrack] unsupported audio format: ".concat(b.soundFormat));var c=a.body.subarray(1),d=c[0];if(0===d){var e=c.subarray(1);debug.warn(!AudioSpecificConfig,"[AAC] Find another one AudioSpecificConfig"),debug.error(2<=e.length,"[AAC] AudioSpecificConfig parse length is not enough");var f={};f.audioObjectType=(248&e[0])>>3,f.samplingFrequencyIndex=((7&e[0])<<1)+(1&(128&e[1])>>7),f.channelConfiguration=(127&e[1])>>3,AudioSpecificConfig=f,postMessage({type:"AudioSpecificConfig",data:f})}else{var g=AudioSpecificConfig,h=g.audioObjectType,i=g.samplingFrequencyIndex,j=g.channelConfiguration,k=a.dataSize-2+7,l=new Uint8Array(7);l[0]=255,l[1]=240,l[1]|=0,l[1]|=0,l[1]|=1,l[2]=h-1<<6,l[2]|=(15&i)<<2,l[2]|=0,l[2]|=(4&j)>>2,l[3]=(3&j)<<6,l[3]|=0,l[3]|=0,l[3]|=0,l[3]|=0,l[3]|=(6144&k)>>11,l[4]=(2040&k)>>3,l[5]=(7&k)<<5,l[5]|=31,l[6]=252;var m=a.body.subarray(2);postMessage({type:"audioData",data:mergeBuffer(l,m),timestamp:a.timestamp})}}onmessage=function onmessage(a){if(uint8=mergeBuffer(uint8,a.data.uint8),!header&&readable(13)){header=Object.create(null),header.signature=readString(read(3)),header.version=read(1)[0],debug.error("FLV"===header.signature&&1===header.version,"FLV header not found"),header.flags=read(1)[0];var b=0!=(4&header.flags)>>>2,c=0!=(1&header.flags);debug.warn(c,"[FLV header] flags not found video"),debug.warn(b,"[FLV header] flags not found audio"),header.headersize=readBufferSum(read(4));var d=readBufferSum(read(4));debug.error(0===d,"PrevTagSize0 should be equal to 0, but got ".concat(d)),postMessage({type:"flvHeader",data:header})}for(;index<uint8.length;){var e=Object.create(null),f=index;if(readable(11)){e.tagType=read(1)[0],e.dataSize=readBufferSum(read(3));var g=read(1)[0],h=read(1)[0],i=read(1)[0],j=read(1)[0];e.timestamp=i|h<<8|g<<16|j<<24,e.streamID=readBufferSum(read(3)),debug.error(0===e.streamID,"streamID should be equal to 0, but got ".concat(e.streamID))}else return index=0,void(uint8=uint8.subarray(f));if(readable(e.dataSize+4)){e.body=read(e.dataSize);var k=readBufferSum(read(4));debug.error(k===e.dataSize+11,"Invalid PrevTagSize: ".concat(k))}else return index=0,void(uint8=uint8.subarray(f));switch(e.tagType){case 18:demuxerScripTag(e);break;case 9:demuxerVideoTag(e);break;case 8:a.data.hasAudio&&demuxerAudioTag(e);break;default:debug.error(!1,"unknown tag type: ".concat(e.tagType))}}index=0,uint8=new Uint8Array};']))),this.demuxRate=F((function(e){t.emit("demuxRate",e)})),t.on("destroy",(function(){r.demuxWorker.terminate(),r.demuxWorker=null})),t.on("streamStart",(function(){if(r.streaming=!0,r.streamStartTime=M(),"string"==typeof n.url){var e=Object.assign(document.createElement("a"),{href:n.url}).href;o.log("stream-url",e)}})),t.on("streaming",(function(e){r.demuxWorker.postMessage({uint8:e,hasAudio:n.hasAudio})})),t.on("streamEnd",(function(e){r.streaming=!1,r.streamEndTime=M(),e&&(r.index=0,r.demuxWorker.postMessage({uint8:e,hasAudio:n.hasAudio})),o.log("stream-time","".concat(r.streamEndTime-r.streamStartTime," ms")),r.demuxed=!0,t.emit("demuxDone"),o.log("demux-done")}));var i=new Uint8Array,a=new Uint8Array;this.demuxWorker.onmessage=function(e){var n,u,c,s,f,d,l,p=e.data;switch(p.type){case"flvHeader":r.header=p.data,t.emit("flvHeader",r.header),o.log("flv-header",r.header);break;case"scripMeta":r.scripMeta=p.data,t.emit("scripMeta",r.scripMeta),o.log("scrip-meta",r.scripMeta);break;case"AVCDecoderConfigurationRecord":r.AVCDecoderConfigurationRecord=p.data,t.emit("AVCDecoderConfigurationRecord",r.AVCDecoderConfigurationRecord),o.log("AVCDecoderConfigurationRecord",r.AVCDecoderConfigurationRecord),o.log("AVC-codecs",(s=r.AVCDecoderConfigurationRecord,f=s.AVCProfileIndication.toString(16),d=s.profile_compatibility.toString(16),l=s.AVCLevelIndication.toString(16),"avc1.".concat(f).concat(d).concat(l))),o.log("AVC-profile",function(e){switch(e){case 66:return"Baseline";case 77:return"Main";case 88:return"Extended";case 100:return"High";case 110:return"High10";case 122:return"High422";case 244:return"High444";default:return"Unknown"}}(r.AVCDecoderConfigurationRecord.AVCProfileIndication)),o.log("AVC-level",(r.AVCDecoderConfigurationRecord.AVCLevelIndication/10).toFixed(1));break;case"AudioSpecificConfig":r.AudioSpecificConfig=p.data,t.emit("AudioSpecificConfig",r.AudioSpecificConfig),o.log("AudioSpecificConfig",r.AudioSpecificConfig),o.log("AAC-codecs",(n=r.AudioSpecificConfig,u=n.audioObjectType,c=(u-1<<6).toString(16),"mp4a.".concat(c,".").concat(u)));break;case"videoData":r.demuxRate(1),r.videoDataLength+=1,r.videoDataSize+=p.data.byteLength;var h=T(p.data);switch(h(4),31&h(1)[0]){case 1:case 5:t.emit("videoData",D(i,a,p.data),p.timestamp);break;case 7:i=p.data;break;case 8:a=p.data}break;case"audioData":r.audioDataLength+=1,r.audioDataSize+=p.data.byteLength,t.emit("audioData",p.data,p.timestamp)}}}));function $(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 G(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?$(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):$(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var K=function(){function e(t){var r=this;u(this,e),this.flv=t;var n=t.options,o=t.player,i=t.debug;this.byteLength=0,this.reader=null,this.chunkStart=0,this.contentLength=0,this.data=new Uint8Array,this.readChunk=R(this.readChunk,1e3),this.chunkSize=n.hasAudio?n.videoChunk+n.audioChunk:n.videoChunk,this.controller=null,this.streamRate=F((function(e){t.emit("streamRate",e)})),i.log("FetchLoader","FetchLoader Init"),t.on("destroy",(function(){r.reader&&r.reader.cancel(),i.log("this.controller",r.controller),r.controller&&r.controller.abort(),r.data=null})),t.on("timeupdate",(function(e){!n.live&&o.loaded-e<=5&&r.readChunk()})),"function"==typeof window.ReadableStream&&"function"==typeof window.Response&&Object.prototype.hasOwnProperty.call(window.Response.prototype,"body")?(i.log("stream-type","Try use ReadableStream"),this.initFetchStream()):(i.log("stream-type","Try use http headers range"),this.controller=new AbortController,fetch(n.url,{method:"head",credentials:n.withCredentials?"include":"omit",mode:n.cors?"cors":"no-cors",signal:this.controller.signal}).then((function(e){r.contentLength=Number(e.headers.get("content-length"))||n.filesize,i.log("stream-contentLength",r.contentLength),r.flv.emit("streamStart"),r.initFetchRange(0,r.chunkSize)})).catch((function(e){throw t.emit("streamError",e),e})))}return c(e,[{key:"readChunk",value:function(){var e=Math.min(this.chunkStart+this.chunkSize,this.data.length);if(e>this.chunkStart){var t=this.data.subarray(this.chunkStart,e);this.flv.emit("streaming",t),this.chunkStart=e}}},{key:"initFetchStream",value:function(){var e=this,t=this.flv,r=t.options,n=t.debug;return this.flv.emit("streamStart"),this.controller=new AbortController,n.log("this.controller",this.controller),fetch(r.url,{credentials:r.withCredentials?"include":"omit",mode:r.cors?"cors":"no-cors",headers:r.headers,signal:this.controller.signal}).then((function(t){return t.body&&"function"==typeof t.body.getReader?(e.reader=t.body.getReader(),function e(){var t=this;return this.reader.read().then((function(o){var i=o.done,a=o.value;if(i)return t.flv.emit("streamEnd"),n.log("stream-end","".concat(t.byteLength," byte")),null;var u=new Uint8Array(a);return t.byteLength+=u.byteLength,t.streamRate(u.byteLength),r.live?t.flv.emit("streaming",u):(t.data=D(t.data,u),0===t.chunkStart&&t.data.length>=t.chunkSize&&t.readChunk()),e.call(t)})).catch((function(e){throw t.flv.emit("streamError",e),e}))}.call(e)):(n.log("stream-type","Try use response arrayBuffer"),t.arrayBuffer())})).then((function(t){t&&t.byteLength&&!r.live&&(e.data=new Uint8Array(t),e.byteLength+=e.data.byteLength,e.flv.emit("streamEnd",e.data),n.log("stream-end","".concat(e.byteLength," byte")))})).catch((function(t){throw e.flv.emit("streamError",t),t}))}},{key:"initFetchRange",value:function(e,t){var r=this,n=this.flv,o=n.options,i=n.debug;return this.controller=new AbortController,i.log("this.controller",this.controller),fetch(o.url,{credentials:o.withCredentials?"include":"omit",mode:o.cors?"cors":"no-cors",headers:G(G({},o.headers),{},{range:"bytes=".concat(e,"-").concat(t)}),signal:this.controller.signal}).then((function(e){return e.arrayBuffer()})).then((function(e){var n=new Uint8Array(e);r.byteLength+=n.byteLength,r.streamRate(n.byteLength),o.live?r.flv.emit("streaming",n):(r.data=D(r.data,n),0===r.chunkStart&&r.data.length>=r.chunkSize&&r.readChunk());var i=Math.min(r.contentLength,t+1),a=Math.min(r.contentLength,i+r.chunkSize);a>i&&r.initFetchRange(i,a)})).catch((function(e){throw r.flv.emit("streamError",e),e}))}}]),e}(),J=c((function e(t){var r=this;u(this,e);var n=t.debug,o=t.options,i=t.events.proxy;this.byteLength=0,this.streamRate=F((function(e){t.emit("streamRate",e)})),this.socket=new WebSocket(t.options.url),this.socket.binaryType="arraybuffer",t.emit("streamStart"),i(this.socket,"open",(function(){r.socket.send(o.socketSend)})),i(this.socket,"message",(function(e){var n=new Uint8Array(e.data);r.byteLength+=n.byteLength,r.streamRate(n.byteLength),t.emit("streaming",n)})),i(this.socket,"close",(function(){t.emit("streamEnd"),n.log("stream-end","".concat(r.byteLength," byte"))})),i(this.socket,"error",(function(e){throw t.emit("streamError",e),e})),t.on("destroy",(function(){r.socket.close()}))})),Q=c((function e(t){u(this,e);var r=new FileReader,n=t.events.proxy;n(r,"load",(function(e){var r=new Uint8Array(e.target.result);t.emit("streamEnd",r),t.debug.log("stream-end","".concat(r.byteLength," byte"))})),n(r,"error",(function(e){t.emit("streamError",e)})),t.on("destroy",(function(){r.abort()})),t.emit("streamStart"),r.readAsArrayBuffer(t.options.url)})),X=function(){function e(t){u(this,e);var r=e.getLoaderFactory(t.options.url);return t.debug.log("stream-loader",r.name),new r(t,this)}return c(e,null,[{key:"getLoaderFactory",value:function(e){return e instanceof File?Q:/^ws{1,2}:\/\//i.test(e)?J:K}}]),e}();function Y(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 Z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Y(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Y(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function ee(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=y(e);if(t){var o=y(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return p(this,r)}}var te=0,re=[],ne=function(e){f(r,e);var t=ee(r);function r(e){var n;return u(this,r),(n=t.call(this)).options=m(Z(Z({},r.options),e),r.scheme),n.options.live&&(n.options.cache=!1),"string"==typeof n.options.container&&(n.options.container=document.querySelector(n.options.container)),window.FlvplayerDecoder?n.init():L(n.options.decoder,"FlvplayerDecoder").then((function(){n.init()})),n}return c(r,[{key:"init",value:function(){this.isDestroy=!1,this.isMobile=j(),this.isWechat=_(),this.debug=new P(this),this.events=new A(this),this.player=new U(this),this.decoder=new N(this),this.demuxer=new H(this),this.stream=new X(this),B(this,this.player),window.FlvplayerControl&&this.options.control&&(this.control=new window.FlvplayerControl(this),B(this,this.control)),te+=1,this.id=te,re.push(this)}},{key:"destroy",value:function(){this.isDestroy=!0,this.emit("destroy"),re.splice(re.indexOf(this),1)}}],[{key:"options",get:function(){return{url:"",container:"",poster:"",debug:!1,live:!1,loop:!1,autoPlay:!1,hasAudio:!0,control:!0,cache:!0,muted:!1,cors:!0,touchResume:!0,withCredentials:!1,volume:.7,frameRate:30,maxTimeDiff:200,videoChunk:1048576,audioChunk:16384,filesize:1/0,width:400,height:300,duration:0,socketSend:"",headers:{},decoder:"./flvplayer-decoder-baseline.js"}}},{key:"scheme",get:function(){return{url:"string|file",container:"string|htmldivelement",poster:"string",debug:"boolean",live:"boolean",loop:"boolean",autoPlay:"boolean",hasAudio:"boolean",control:"boolean",cache:"boolean",muted:"boolean",cors:"boolean",touchResume:"boolean",withCredentials:"boolean",volume:"number",frameRate:"number",maxTimeDiff:"number",videoChunk:"number",audioChunk:"number",filesize:"number",width:"number",height:"number",duration:"number",socketSend:"string",headers:"object",decoder:"string"}}},{key:"isSupported",get:function(){return g}},{key:"instances",get:function(){return re}},{key:"version",get:function(){return"1.1.8"}},{key:"env",get:function(){return'"production"'}},{key:"utils",get:function(){return V}}]),r}(b);return console.log("%c FlvPlayer.js %c 1.1.8 %c https://flvplayer.js.org","color: #fff; background: #5f5f5f","color: #fff; background: #4bc729",""),ne}));