You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
9 lines
46 KiB
JavaScript
9 lines
46 KiB
JavaScript
/*!
|
|
* FlvPlayer.js v1.1.8
|
|
* Github: https://github.com/zhw2590582/FlvPlayer#readme
|
|
* (c) 2017-2020 Harvey Zack
|
|
* Released under the MIT License.
|
|
*/
|
|
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).FlvPlayer=t()}(this,(function(){"use strict";var e=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};var t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")};function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var r=function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e};"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function o(e,t){return e(t={exports:{}},t.exports),t.exports}var i=o((function(e){function t(n,r){return e.exports=t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},t(n,r)}e.exports=t}));var a=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}}),t&&i(e,t)},u=o((function(e){function t(n){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=t=function(e){return typeof e}:e.exports=t=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(n)}e.exports=t}));var c=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e};var s=function(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?c(e):t},f=o((function(e){function t(n){return e.exports=t=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},t(n)}e.exports=t})),d=o((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,n=function(n){if(void 0===n)return"undefined";if(null===n)return"null";var o=e(n);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"===r(e)}(n)?"generatorfunction":"function";if(function(e){return Array.isArray?Array.isArray(e):e instanceof Array}(n))return"array";if(function(e){return!(!e.constructor||"function"!=typeof e.constructor.isBuffer)&&e.constructor.isBuffer(e)}(n))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}(n))return"arguments";if(function(e){return e instanceof Date||"function"==typeof e.toDateString&&"function"==typeof e.getDate&&"function"==typeof e.setDate}(n))return"date";if(function(e){return e instanceof Error||"string"==typeof e.message&&e.constructor&&"number"==typeof e.constructor.stackTraceLimit}(n))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}(n))return"regexp";switch(r(n)){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}(n))return"generator";switch(o=t.call(n)){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 r(e){return e.constructor?e.constructor.name:null}function o(e,t){var r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:["option"];return i(e,t,r),a(e,t,r),function(e,t,r){var u=n(t),c=n(e);if("object"===u){if("object"!==c)throw new Error("[Type Error]: '".concat(r.join("."),"' require 'object' type, but got '").concat(c,"'"));Object.keys(t).forEach((function(n){var u=e[n],c=t[n],s=r.slice();s.push(n),i(u,c,s),a(u,c,s),o(u,c,s)}))}if("array"===u){if("array"!==c)throw new Error("[Type Error]: '".concat(r.join("."),"' require 'array' type, but got '").concat(c,"'"));e.forEach((function(n,u){var c=e[u],s=t[u]||t[0],f=r.slice();f.push(u),i(c,s,f),a(c,s,f),o(c,s,f)}))}}(e,t,r),e}function i(e,t,r){if("string"===n(t)){var o=n(e);if(!(-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(r.join("."),"' require '").concat(t,"' type, but got '").concat(o,"'"))}}function a(e,t,r){if("function"===n(t)){var o=t(e,n(e),r);if(!0!==o){var i=n(o);throw"string"===i?new Error(o):"error"===i?o:new Error("[Validator Error]: The scheme for '".concat(r.join("."),"' validator require return true, but got '").concat(o,"'"))}}}return o.kindOf=n,o}()}));function l(){return function(){try{if("object"===u(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"],n=!1,r=0;r<t.length;r+=1)try{if((n=e.getContext(t[r]))&&"function"==typeof n.getParameter)return!0}catch(e){}return!1}return!1}();var e}var h=function(){function e(){t(this,e)}return r(e,[{key:"on",value:function(e,t,n){var r=this.e||(this.e={});return(r[e]||(r[e]=[])).push({fn:t,ctx:n}),this}},{key:"once",value:function(e,t,n){var r=this;function o(){r.off(e,o);for(var i=arguments.length,a=new Array(i),u=0;u<i;u++)a[u]=arguments[u];t.apply(n,a)}return o._=t,this.on(e,o,n)}},{key:"emit",value:function(e){for(var t=((this.e||(this.e={}))[e]||[]).slice(),n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];for(var i=0;i<t.length;i+=1)t[i].fn.apply(t[i].ctx,r);return this}},{key:"off",value:function(e,t){var n=this.e||(this.e={}),r=n[e],o=[];if(r&&t)for(var i=0,a=r.length;i<a;i+=1)r[i].fn!==t&&r[i].fn._!==t&&o.push(r[i]);return o.length?n[e]=o:delete n[e],this}}]),e}();var p=function(e){return-1!==Function.toString.call(e).indexOf("[native code]")};var m=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}},y=o((function(e){function t(n,r,o){return m()?e.exports=t=Reflect.construct:e.exports=t=function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o},t.apply(null,arguments)}e.exports=t}));function g(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}var b=function(e){a(o,e);var n,r=(n=o,function(){var e,t=f(n);if(g()){var r=f(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return s(this,e)});function o(e){var n;return t(this,o),(n=r.call(this,e)).name="FlvPlayerError",n}return o}(o((function(e){function t(n){var r="function"==typeof Map?new Map:void 0;return e.exports=t=function(e){if(null===e||!p(e))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(e))return r.get(e);r.set(e,t)}function t(){return y(e,arguments,f(this).constructor)}return t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),i(t,e)},t(n)}e.exports=t}))(Error)),v=function e(n){t(this,e);var r=n.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 b(t)}},w=function(){function e(n){var r=this;t(this,e),this.destroys=[],this.proxy=this.proxy.bind(this),n.on("destroy",(function(){r.destroy()}))}return r(e,[{key:"proxy",value:function(e,t,n){var r=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(Array.isArray(t))return t.map((function(t){return r.proxy(e,t,n,o)}));e.addEventListener(t,n,o);var i=function(){return e.removeEventListener(t,n,o)};return this.destroys.push(i),i}},{key:"destroy",value:function(){this.destroys.forEach((function(e){return e()}))}}]),e}();function S(){return/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function k(){return/MicroMessenger/i.test(navigator.userAgent)}function O(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function j(e){var t=0;function n(r){for(var o=new Uint8Array(r),i=0;i<r;i+=1)o[i]=e[t],t+=1;return n.index=t,o}return n.index=0,n}function A(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=t[0].constructor;return t.reduce((function(e,t){var n=new r((0|e.byteLength)+(0|t.byteLength));return n.set(e,0),n.set(t,0|e.byteLength),n}),new r)}function x(){return performance&&"function"==typeof performance.now?performance.now():Date.now()}function P(e,t){var n,r,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 n=u,void(r=this);o=!0,e.apply(this,u),setTimeout((function(){o=!1,n&&(i.apply(r,n),n=null,r=null)}),t)}}function C(e,t,n){return Math.max(Math.min(e,Math.max(t,n)),Math.min(t,n))}function T(e,t){return new Promise((function(n,r){var o=document.createElement("script");o.type="text/javascript",o.onload=function(){window[t]?n(window[t]):r(new Error("Unable to find global variable '".concat(t,"' from '").concat(e,"'")))},o.onerror=function(){r(new Error("Resource loading failed '".concat(e,"'")))},o.src=e,document.head.appendChild(o)}))}function D(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];return n.reduce((function(e,t){return Object.getOwnPropertyNames(t).forEach((function(n){if(O(e,n))throw new Error("Target attribute name is duplicated: ".concat(n));Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})),e}),e)}function R(e){var t=0,n=x();return function(r){t+=r;var o=x(),i=o-n;i>=1e3&&(e(t/i*1e3),n=o,t=0)}}var E=Object.freeze({__proto__:null,isMobile:S,isWechat:k,hasOwnProperty:O,readBuffer:j,mergeBuffer:A,createWorker:function(e){return new Worker(URL.createObjectURL(new Blob([e],{type:"application/javascript"})))},secondToTime:function(e){var t=Math.floor(e/3600),n=Math.floor((e-3600*t)/60),r=Math.floor(e-3600*t-60*n);return(t>0?[t,n,r]:[n,r]).map((function(e){return e<10?"0".concat(e):String(e)})).join(":")},getNowTime:x,debounce:function(e,t,n){var r;function o(){for(var o=arguments.length,i=new Array(o),a=0;a<o;a++)i[a]=arguments[a];var u=function(){r=null,e.apply(n,i)};clearTimeout(r),r=setTimeout(u,t)}return o.clearTimeout=function(){clearTimeout(r)},o},throttle:P,clamp:C,setStyle:function e(t,n,r){return"object"===u(n)&&Object.keys(n).forEach((function(r){e(t,r,n[r])})),t.style[n]=r,t},getStyle:function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=getComputedStyle(e,null).getPropertyValue(t);return n?parseFloat(r):r},loadScript:T,proxyPropertys:D,calculationRate:R});var L=function e(n){t(this,e),function(e,t){var n=e.options,r=n.container.style.cssText;n.container.classList.add("flvplayer-container"),n.container.innerHTML='<div class="flvplayer-player"><canvas class="flvplayer-canvas" width="'.concat(n.width,'" height="').concat(n.height,'"></canvas></div>'),e.on("destroy",(function(){n.container.innerHTML="",n.container.style.cssText=r,n.container.classList.remove("flvplayer-container")})),Object.defineProperty(t,"$container",{value:n.container}),Object.defineProperty(t,"$player",{value:n.container.querySelector(".flvplayer-player")}),Object.defineProperty(t,"$canvas",{value:n.container.querySelector(".flvplayer-canvas")})}(n,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(n){e.options.cache&&e.decoder.seeked(C(n,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(n){try{return e.decoder.audio.volume=C(n,0,1),t.volume}catch(e){return n}}}),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()}})}(n,this),function(e,t){var n=e.events.proxy;e.on("scripMeta",(function(e){var n=e.amf2.metaData,r=n.width,o=n.height;r&&o&&(t.$canvas.width=r,t.$canvas.height=o)})),n(t.$canvas,"click",(function(){t.toggle()}))}(n,this)};function M(e,t,n){return Math.max(Math.min(e,Math.max(t,n)),Math.min(t,n))}function _(...e){const t=e[0].constructor;return e.reduce((e,n)=>{const r=new t((0|e.byteLength)+(0|n.byteLength));return r.set(e,0),r.set(n,0|e.byteLength),r},new t)}class B{constructor(e={}){if(this.option=d({...B.option,...e},B.scheme),this.option.volume=M(this.option.volume,0,1),this.option.chunk=M(this.option.chunk,0,1/0),this.option.maxTimeDiff=M(this.option.maxTimeDiff,0,1/0),this.option.autoEndTime=M(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,n){let r;return function(...o){clearTimeout(r),r=setTimeout((function(){r=null,e.apply(n,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=M(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}=_(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=_(this.decodeErrorBuffer,this.decodeWaitingBuffer),this.option.onDecodeError(e)})}else this.timestampTmp.push(t),this.decodeWaitingBuffer=_(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,n)=>{const r=this.audiobuffers[n];return r&&t+1e3*r.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),n=this.timestamps[t],r=this.audiobuffers[t];if(void 0===n||void 0===r)return this.stop(t,n);const o=Math.max(0,(e-n)/1e3);return this.source=this.context.createBufferSource(),this.source.connect(this.gainNode),this.gainNode.connect(this.context.destination),this.source.buffer=r,this.option.onPlay(r,e,o),this.source.start(0,o),this.source.onended=()=>{const e=this.timestamps[t+1],r=this.audiobuffers[t+1];if(void 0!==e&&void 0!==r){const t=this.option.onNext(e),n=this.findIndex(t);!this.option.cache&&n>0&&(this.option.onFreeMemory({total:this.pcmLength,pcm:this.audiobuffers.reduce((e,t)=>e+=t.length,0),index:n}),this.audiobuffers.splice(0,n),this.timestamps.splice(0,n)),this.play(t)}else this.stop(t,n)},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 F=function(){function e(n,r){var o=this;t(this,e),this.flv=n,this.dida=new B({volume:n.options.muted?0:n.options.volume,cache:n.options.cache,chunk:n.options.audioChunk,maxTimeDiff:n.options.maxTimeDiff,touchResume:n.options.touchResume,onNext:function(e){var t=e-1e3*r.currentTime;return n.debug.log("time-diff",t),Math.abs(t)>=n.options.maxTimeDiff&&(n.debug.log("time-sync",t),r.currentTime=e/1e3),e},onVolumeChange:function(e){n.emit("volumechange",e)},onFreeMemory:function(e){n.debug.log("free-audio-memory",e),n.emit("freeAudioMemory",e)}}),n.on("audioData",(function(e,t){o.dida.load(e,t)})),n.on("destroy",(function(){o.dida.destroy()}))}return r(e,[{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()}},{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}}]),e}(),V=function(){function e(n){var r=this;t(this,e),this.flv=n,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(n,this),n.options.hasAudio?this.audio=new F(n,this):this.audio={play:function(){return null},stop:function(){return null},playing:!0,decoding:!1},n.on("ready",(function(){n.options.autoPlay?r.play():r.video.draw(0)})),n.on("destroy",(function(){r.pause()})),n.on("timeupdate",(function(e){!n.options.live&&e>=n.player.duration&&r.pause()}));var o=!1;n.events.proxy(document,"visibilitychange",(function(){document.hidden?(o=r.playing,r.pause()):o&&r.play()}))}return r(e,[{key:"play",value:function(){this.lastUpdateTime=x(),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,n=t.options,r=t.player,o=t.debug;this.animationFrameTimer=requestAnimationFrame((function(){if(!e.video.playing||!e.audio.playing)return r.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:r.streaming,playing:{video:e.video.playing,audio:e.audio.playing},decoding:{video:e.video.decoding,audio:e.audio.decoding}}),e.play()}),n.live?3e3:1e3))):(e.ended=!0,e.playing=!1,e.waiting=!1,e.pause(),e.flv.emit("ended",e.currentTime),void(n.loop&&n.cache&&!n.live&&(e.currentTime=0,e.play(),e.flv.emit("loop"))));e.ended=!1,e.playing=!0,e.waiting=!1;var t=x();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,n=t.player,r=t.options;r.cache&&!r.live&&(cancelAnimationFrame(this.animationFrameTimer),clearTimeout(this.waitingTimer),this.animationFrameTimer=null,this.waitingTimer=null,this.currentTime=e,this.video.draw(Math.floor(e*n.frameRate)),this.playing&&this.play(),this.flv.emit("seeked",e))}}]),e}();var U=function e(n){var r=this;t(this,e);var o=n.options,i=n.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 _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(a){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a))return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}}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 _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}}),b&&_setPrototypeOf(a,b)}function _createSuper(a){function b(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}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){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_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 isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _construct(){return _construct=isNativeReflectConstruct()?Reflect.construct: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 _isNativeFunction(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf: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 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){var b;return(b=String.fromCharCode).call.apply(b,[String].concat(_toConsumableArray(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 l=readBufferSum(c(2));d=readString(c(l));break}case 3:{d=Object.create(null);for(var m=-1;9!==m;){var e=readBufferSum(c(2)),f=readString(c(e)),g=c(1)[0];f&&(d[f]=b(g)),m=g}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 n=-1;9!==n;){var h=readBufferSum(c(2)),j=readString(c(h)),k=c(1)[0];j&&(d[j]=b(k)),n=k}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 i=readBufferSum(c(4));d=readString(c(i));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 p=0;p<k.numOfSequenceParameterSets;p+=1)if(k.sequenceParameterSetLength=readBufferSum(j(2)),0<k.sequenceParameterSetLength){var i=j(k.sequenceParameterSetLength);postMessage({type:"videoData",data:mergeBuffer(nalStart,i)})}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 q=0;q<k.numOfPictureParameterSets;q+=1)if(k.pictureParameterSetLength=readBufferSum(j(2)),0<k.pictureParameterSetLength){var r=j(k.pictureParameterSetLength);postMessage({type:"videoData",data:mergeBuffer(nalStart,r)})}AVCDecoderConfigurationRecord=k,postMessage({type:"AVCDecoderConfigurationRecord",data:k})}else if(1===e)for(var l,m=AVCDecoderConfigurationRecord,n=m.lengthSizeMinusOne,o=readBuffer(h);o.index<h.length;)l=readBufferSum(o(n)),postMessage({type:"videoData",data:mergeBuffer(nalStart,o(l)),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 k=c.subarray(1);debug.warn(!AudioSpecificConfig,"[AAC] Find another one AudioSpecificConfig"),debug.error(2<=k.length,"[AAC] AudioSpecificConfig parse length is not enough");var l={};l.audioObjectType=(248&k[0])>>3,l.samplingFrequencyIndex=((7&k[0])<<1)+(1&(128&k[1])>>7),l.channelConfiguration=(127&k[1])>>3,AudioSpecificConfig=l,postMessage({type:"AudioSpecificConfig",data:l})}else{var e=AudioSpecificConfig,f=e.audioObjectType,g=e.samplingFrequencyIndex,h=e.channelConfiguration,i=a.dataSize-2+7,j=new Uint8Array(7);j[0]=255,j[1]=240,j[1]|=0,j[1]|=0,j[1]|=1,j[2]=f-1<<6,j[2]|=(15&g)<<2,j[2]|=0,j[2]|=(4&h)>>2,j[3]=(3&h)<<6,j[3]|=0,j[3]|=0,j[3]|=0,j[3]|=0,j[3]|=(6144&i)>>11,j[4]=(2040&i)>>3,j[5]=(7&i)<<5,j[5]|=31,j[6]=252;var m=a.body.subarray(2);postMessage({type:"audioData",data:mergeBuffer(j,m),timestamp:a.timestamp})}}onmessage=function onmessage(a){if(uint8=mergeBuffer(uint8,a.data),!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 j=readBufferSum(read(4));debug.error(0===j,"PrevTagSize0 should be equal to 0, but got ".concat(j)),postMessage({type:"flvHeader",data:header})}for(;index<uint8.length;){var d=Object.create(null),e=index;if(readable(11)){d.tagType=read(1)[0],d.dataSize=readBufferSum(read(3));var f=read(1)[0],g=read(1)[0],h=read(1)[0],i=read(1)[0];d.timestamp=h|g<<8|f<<16|i<<24,d.streamID=readBufferSum(read(3)),debug.error(0===d.streamID,"streamID should be equal to 0, but got ".concat(d.streamID))}else return index=0,void(uint8=uint8.subarray(e));if(readable(d.dataSize+4)){d.body=read(d.dataSize);var k=readBufferSum(read(4));debug.error(k===d.dataSize+11,"Invalid PrevTagSize: ".concat(k))}else return index=0,void(uint8=uint8.subarray(e));switch(d.tagType){case 18:demuxerScripTag(d);break;case 9:demuxerVideoTag(d);break;case 8:demuxerAudioTag(d);break;default:debug.error(!1,"unknown tag type: ".concat(d.tagType));}}index=0,uint8=new Uint8Array};']))),this.demuxRate=R((function(e){n.emit("demuxRate",e)})),n.on("destroy",(function(){r.demuxWorker.terminate(),r.demuxWorker=null})),n.on("streamStart",(function(){if(r.streaming=!0,r.streamStartTime=x(),"string"==typeof o.url){var e=Object.assign(document.createElement("a"),{href:o.url}).href;i.log("stream-url",e)}})),n.on("streaming",(function(e){r.demuxWorker.postMessage(e)})),n.on("streamEnd",(function(e){r.streaming=!1,r.streamEndTime=x(),e&&(r.index=0,r.demuxWorker.postMessage(e)),i.log("stream-time","".concat(r.streamEndTime-r.streamStartTime," ms")),r.demuxed=!0,n.emit("demuxDone"),i.log("demux-done")}));var a=new Uint8Array,u=new Uint8Array;this.demuxWorker.onmessage=function(e){var t,o,c,s,f,d,l,h=e.data;switch(h.type){case"flvHeader":r.header=h.data,n.emit("flvHeader",r.header),i.log("flv-header",r.header);break;case"scripMeta":r.scripMeta=h.data,n.emit("scripMeta",r.scripMeta),i.log("scrip-meta",r.scripMeta);break;case"AVCDecoderConfigurationRecord":r.AVCDecoderConfigurationRecord=h.data,n.emit("AVCDecoderConfigurationRecord",r.AVCDecoderConfigurationRecord),i.log("AVCDecoderConfigurationRecord",r.AVCDecoderConfigurationRecord),i.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))),i.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)),i.log("AVC-level",(r.AVCDecoderConfigurationRecord.AVCLevelIndication/10).toFixed(1));break;case"AudioSpecificConfig":r.AudioSpecificConfig=h.data,n.emit("AudioSpecificConfig",r.AudioSpecificConfig),i.log("AudioSpecificConfig",r.AudioSpecificConfig),i.log("AAC-codecs",(t=r.AudioSpecificConfig,o=t.audioObjectType,c=(o-1<<6).toString(16),"mp4a.".concat(c,".").concat(o)));break;case"videoData":r.demuxRate(1),r.videoDataLength+=1,r.videoDataSize+=h.data.byteLength;var p=j(h.data);switch(p(4),31&p(1)[0]){case 1:case 5:n.emit("videoData",A(a,u,h.data),h.timestamp);break;case 7:a=h.data;break;case 8:u=h.data}break;case"audioData":r.audioDataLength+=1,r.audioDataSize+=h.data.byteLength,n.emit("audioData",h.data,h.timestamp)}}};function I(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function z(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?I(Object(r),!0).forEach((function(n){e(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):I(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var W=function(){function e(n){var r=this;t(this,e),this.flv=n;var o=n.options,i=n.player,a=n.debug;this.byteLength=0,this.reader=null,this.chunkStart=0,this.contentLength=0,this.data=new Uint8Array,this.readChunk=P(this.readChunk,1e3),this.chunkSize=o.hasAudio?o.videoChunk+o.audioChunk:o.videoChunk,this.streamRate=R((function(e){n.emit("streamRate",e)})),n.on("destroy",(function(){r.reader&&r.reader.cancel(),r.data=null})),n.on("timeupdate",(function(e){!o.live&&i.loaded-e<=5&&r.readChunk()})),"function"==typeof window.ReadableStream&&"function"==typeof window.Response&&Object.prototype.hasOwnProperty.call(window.Response.prototype,"body")?(a.log("stream-type","Try use ReadableStream"),this.initFetchStream()):(a.log("stream-type","Try use http headers range"),fetch(o.url,{method:"head",credentials:o.withCredentials?"include":"omit",mode:o.cors?"cors":"no-cors"}).then((function(e){r.contentLength=Number(e.headers.get("content-length"))||o.filesize,a.log("stream-contentLength",r.contentLength),r.flv.emit("streamStart"),r.initFetchRange(0,r.chunkSize)})).catch((function(e){throw n.emit("streamError",e),e})))}return r(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,n=t.options,r=t.debug;return this.flv.emit("streamStart"),fetch(n.url,{credentials:n.withCredentials?"include":"omit",mode:n.cors?"cors":"no-cors",headers:n.headers}).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"),r.log("stream-end","".concat(t.byteLength," byte")),null;var u=new Uint8Array(a);return t.byteLength+=u.byteLength,t.streamRate(u.byteLength),n.live?t.flv.emit("streaming",u):(t.data=A(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)):(r.log("stream-type","Try use response arrayBuffer"),t.arrayBuffer())})).then((function(t){t&&t.byteLength&&!n.live&&(e.data=new Uint8Array(t),e.byteLength+=e.data.byteLength,e.flv.emit("streamEnd",e.data),r.log("stream-end","".concat(e.byteLength," byte")))})).catch((function(t){throw e.flv.emit("streamError",t),t}))}},{key:"initFetchRange",value:function(e,t){var n=this,r=this.flv.options;return fetch(r.url,{credentials:r.withCredentials?"include":"omit",mode:r.cors?"cors":"no-cors",headers:z({},r.headers,{range:"bytes=".concat(e,"-").concat(t)})}).then((function(e){return e.arrayBuffer()})).then((function(e){var o=new Uint8Array(e);n.byteLength+=o.byteLength,n.streamRate(o.byteLength),r.live?n.flv.emit("streaming",o):(n.data=A(n.data,o),0===n.chunkStart&&n.data.length>=n.chunkSize&&n.readChunk());var i=Math.min(n.contentLength,t+1),a=Math.min(n.contentLength,i+n.chunkSize);a>i&&n.initFetchRange(i,a)})).catch((function(e){throw n.flv.emit("streamError",e),e}))}}]),e}(),q=function e(n){var r=this;t(this,e);var o=n.debug,i=n.options,a=n.events.proxy;this.byteLength=0,this.streamRate=R((function(e){n.emit("streamRate",e)})),this.socket=new WebSocket(n.options.url),this.socket.binaryType="arraybuffer",n.emit("streamStart"),a(this.socket,"open",(function(){r.socket.send(i.socketSend)})),a(this.socket,"message",(function(e){var t=new Uint8Array(e.data);r.byteLength+=t.byteLength,r.streamRate(t.byteLength),n.emit("streaming",t)})),a(this.socket,"close",(function(){n.emit("streamEnd"),o.log("stream-end","".concat(r.byteLength," byte"))})),a(this.socket,"error",(function(e){throw n.emit("streamError",e),e})),n.on("destroy",(function(){r.socket.close()}))},N=function e(n){t(this,e);var r=new FileReader,o=n.events.proxy;o(r,"load",(function(e){var t=new Uint8Array(e.target.result);n.emit("streamEnd",t),n.debug.log("stream-end","".concat(t.byteLength," byte"))})),o(r,"error",(function(e){n.emit("streamError",e)})),n.on("destroy",(function(){r.abort()})),n.emit("streamStart"),r.readAsArrayBuffer(n.options.url)},H=function(){function e(n){t(this,e);var r=e.getLoaderFactory(n.options.url);return n.debug.log("stream-loader",r.name),new r(n,this)}return r(e,null,[{key:"getLoaderFactory",value:function(e){return e instanceof File?N:/^ws{1,2}:\/\//i.test(e)?q:W}}]),e}();function $(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function G(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}var J=0,K=function(n){a(u,n);var o,i=(o=u,function(){var e,t=f(o);if(G()){var n=f(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return s(this,e)});function u(n){var r;return t(this,u),(r=i.call(this)).options=d(function(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?$(Object(r),!0).forEach((function(n){e(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):$(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}({},u.options,{},n),u.scheme),r.options.live&&(r.options.cache=!1),"string"==typeof r.options.container&&(r.options.container=document.querySelector(r.options.container)),window.FlvplayerDecoder?r.init():T(r.options.decoder,"FlvplayerDecoder").then((function(){r.init()})),console.log("%c FlvPlayer.js %c 1.1.8 %c https://flvplayer.js.org","color: #fff; background: #5f5f5f","color: #fff; background: #4bc729",""),r}return r(u,[{key:"init",value:function(){this.isDestroy=!1,this.isMobile=S(),this.isWechat=k(),this.debug=new v(this),this.events=new w(this),this.player=new L(this),this.decoder=new V(this),this.demuxer=new U(this),this.stream=new H(this),D(this,this.player),window.FlvplayerControl&&this.options.control&&(this.control=new window.FlvplayerControl(this),D(this,this.control)),J+=1,this.id=J,u.instances.push(this)}},{key:"destroy",value:function(){this.isDestroy=!0,this.emit("destroy"),u.instances.splice(u.instances.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 l}},{key:"version",get:function(){return"1.1.8"}},{key:"env",get:function(){return'"production"'}},{key:"utils",get:function(){return E}}]),u}(h);return Object.defineProperty(K,"instances",{value:[]}),K}));
|