Files
2023-06-20 10:33:32 +08:00

1 line
66 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.jPlayer=t():e.jPlayer=t()}(window,(function(){return function(e){var t={};function o(a){if(t[a])return t[a].exports;var r=t[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,o),r.l=!0,r.exports}return o.m=e,o.c=t,o.d=function(e,t,a){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)o.d(a,r,function(t){return e[t]}.bind(null,r));return a},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=3)}([function(e,t,o){var a,r;a="undefined"!=typeof window?window:this,r=function(e,t){const o={closeTalk:60,TalkHandshakeReq:59,kFileData:1,kInitDecoderReq:0,kUninitDecoderReq:1,kOpenDecoderReq:2,kCloseDecoderReq:3,kFeedDataReq:4,kStartDecodingReq:5,kPauseDecodingReq:6,kInitDecoderRsp:0,kUninitDecoderRsp:1,kOpenDecoderRsp:2,kCloseDecoderRsp:10,kVideoFrame:4,kAudioFrame:5,kDecodeFinishedEvt:8,cmdCallback:11,kGetParamRsp:12,sendDataCallback:13,socketLinkState:14,getHeartBeatRequest:15,DownloaderHeartBeat:16,closeWebsocket:17,fetchStream:18,resetDecoderFifo:19,getSetPlayBackSpeedReq:20,getSetPlayBackStartReq:21,deviceReady:22,getSetPlayBackStartTimeReq:23,responseCurDateTime:24,eventTypeFifoFull:25,eventTypeFifoEnough:26,playbakcRecordList:27,socketActiveClose:28,serverDataTimeout:29,heartPingResp:30,serverDecoderError:31,socketNoActive:32,getHandsharkReq:33,getHandsharkRes:34,recoderStart:35,recoderPause:36,onWasmLoaded:37,getHandshakeReq:38,DownloaderHandshakeReq:39,sendHandshakeReq:40,kVideoDownRep:100,kVideoDownChumksRep:101,getTalkStartReq:50,talkStartRep:51,pcmDataReq:52,kStartTalkEncoderRsq:53,kStartTalkEncoderRsp:54,kGetDeviceInfo:55,kGetAudioDataReq:56,kgetTalkStartRep:57,DestroyTalkReq:58,DestroyTalkRes:61,kStartTalkEncoderdeviceready:62,initTalkEncode:64,_getTalkStartReq:63,PlaybackOver:65,serverDecoderTalkError:66};return e.common=o,o},"object"==typeof e.exports?e.exports=a.document?r(a):function(e){if(!e.document)throw new Error("common requires a window with a document");return r(e)}:r(a)},function(e,t,o){"use strict";e.exports=function(e,t,o,a){try{try{var r;try{r=new window.Blob([e])}catch(t){(r=new(window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder)).append(e),r=r.getBlob()}var s=window.URL||window.webkitURL,i=s.createObjectURL(r),n=new window[t](i,o);return s.revokeObjectURL(i),n}catch(a){return new window[t]("data:application/javascript,".concat(encodeURIComponent(e)),o)}}catch(e){if(!a)throw Error("Inline worker is not supported");return new window[t](a,o)}}},function(e,t,o){var a,r;a="undefined"!=typeof window?window:this,r=function(e,t){function o(e){this.module=e}return o.prototype.log=function(e){},o.prototype.logError=function(e){},o.prototype.logInfo=function(e){},o.prototype.logDebug=function(e){},o.prototype.currentTimeStr=function(){var e=new Date(Date.now());return e.getFullYear()+"-"+(e.getMonth()+1)+"-"+e.getDate()+" "+e.getHours()+":"+e.getMinutes()+":"+e.getSeconds()+":"+e.getMilliseconds()},e.Logger=o,o},"object"==typeof e.exports?e.exports=a.document?r(a):function(e){if(!e.document)throw new Error("Logger requires a window with a document");return r(e)}:r(a)},function(e,t,o){"use strict";function a(e){this.init(e)}o.r(t),o.d(t,"playerStateIdle",(function(){return T})),o.d(t,"playerStatePlaying",(function(){return E})),o.d(t,"playerStatePausing",(function(){return _})),a.prototype.init=function(e){this.option={encoding:"16bitInt",channels:1,sampleRate:8e3,flushingTime:5e3,...e},this.samples=new Float32Array,this.flush=this.flush.bind(this),this.interval=setInterval(this.flush,this.option.flushingTime),this.maxValue=this.getMaxValue(),this.TypedArray=this.getTypedArray(),this.createContext()},a.prototype.getMaxValue=function(){var e={"8bitInt":128,"16bitInt":32768,"32bitInt":2147483648,"32bitFloat":1};return e[this.option.encoding]?e[this.option.encoding]:e["16bitInt"]},a.prototype.getTypedArray=function(){var e={"8bitInt":Int8Array,"16bitInt":Int16Array,"32bitInt":Int32Array,"32bitFloat":Float32Array};return e[this.option.encoding]?e[this.option.encoding]:e["16bitInt"]},a.prototype.createContext=function(){this.audioCtx=new(window.AudioContext||window.webkitAudioContext),this.gainNode=this.audioCtx.createGain(),this.gainNode.gain.value=1,this.gainNode.connect(this.audioCtx.destination),this.startTime=this.audioCtx.currentTime},a.prototype.isTypedArray=function(e){return e.byteLength&&e.buffer&&e.buffer.constructor==ArrayBuffer},a.prototype.feed=function(e){if(this.isTypedArray(e)){e=this.getFormatedValue(e);var t=new Float32Array(this.samples.length+e.length);t.set(this.samples,0),t.set(e,this.samples.length),this.samples=t}},a.prototype.getFormatedValue=function(e){e=new this.TypedArray(e.buffer);var t,o=new Float32Array(e.length);for(t=0;t<e.length;t++)o[t]=e[t]/this.maxValue;return o},a.prototype.volume=function(e){this.gainNode.gain.value=e},a.prototype.destroy=function(){this.interval&&clearInterval(this.interval),this.samples=null,this.audioCtx.close(),this.audioCtx=null},a.prototype.createAudioAssembly=function(e){var t,o,a,r,s,i=this.audioCtx.createBufferSource(),n=e.length/this.option.channels,l=this.audioCtx.createBuffer(this.option.channels,n,this.option.sampleRate);for(o=0;o<this.option.channels;o++)for(t=l.getChannelData(o),a=o,s=50,r=0;r<n;r++)t[r]=e[a],r<50&&(t[r]=t[r]*r/50),r>=n-51&&(t[r]=t[r]*s--/50),a+=this.option.channels;this.startTime<this.audioCtx.currentTime&&(this.startTime=this.audioCtx.currentTime),i.buffer=l,i.connect(this.gainNode),i.start(this.startTime);(new Date).getTime();this.startTime+=l.duration},a.prototype.flush=function(){this.samples.length&&(this.createAudioAssembly(this.samples),this.samples=new Float32Array)},a.prototype.getTimestamp=function(){return this.audioCtx?this.audioCtx.currentTime:0},a.prototype.play=function(e){this.isTypedArray(e)&&(e=this.getFormatedValue(e)).length&&this.createAudioAssembly(e)},a.prototype.pause=function(){"running"===this.audioCtx.state&&this.audioCtx.suspend()},a.prototype.resume=function(){"suspended"===this.audioCtx.state&&this.audioCtx.resume()};var r=a;function s(e){this.gl=e,this.texture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.texture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}function i(e,t){this.canvas=e,this.gl=e.getContext("webgl",t)||e.getContext("experimental-webgl"),this.program=null,this.verticesBuffer=null,this.texCoordBuffer=null,this.initGL(t)}s.prototype.fill=function(e,t,o){var a=this.gl;a.bindTexture(a.TEXTURE_2D,this.texture),a.texImage2D(a.TEXTURE_2D,0,a.LUMINANCE,e,t,0,a.LUMINANCE,a.UNSIGNED_BYTE,o)},i.prototype.initGL=function(e){if(this.gl){var t=this.gl;t.pixelStorei(t.UNPACK_ALIGNMENT,1);var o=t.createProgram();this.program=o;var a=["attribute highp vec4 aVertexPosition;","attribute vec2 aTextureCoord;","varying highp vec2 vTextureCoord;","void main(void) {"," gl_Position = aVertexPosition;"," vTextureCoord = aTextureCoord;","}"].join("\n"),r=t.createShader(t.VERTEX_SHADER);t.shaderSource(r,a),t.compileShader(r);var i=["precision highp float;","varying lowp vec2 vTextureCoord;","uniform sampler2D YTexture;","uniform sampler2D UTexture;","uniform sampler2D VTexture;","const mat4 YUV2RGB = mat4","("," 1.1643828125, 0, 1.59602734375, -.87078515625,"," 1.1643828125, -.39176171875, -.81296875, .52959375,"," 1.1643828125, 2.017234375, 0, -1.081390625,"," 0, 0, 0, 1",");","void main(void) {"," gl_FragColor = vec4( texture2D(YTexture, vTextureCoord).x, texture2D(UTexture, vTextureCoord).x, texture2D(VTexture, vTextureCoord).x, 1) * YUV2RGB;","}"].join("\n"),n=t.createShader(t.FRAGMENT_SHADER);t.shaderSource(n,i),t.compileShader(n),t.attachShader(o,r),t.attachShader(o,n),t.linkProgram(o),t.deleteShader(r),t.deleteShader(n),t.useProgram(o),t.getProgramParameter(o,t.LINK_STATUS);var l=t.getAttribLocation(o,"aVertexPosition");t.enableVertexAttribArray(l);var c=t.getAttribLocation(o,"aTextureCoord");t.enableVertexAttribArray(c);var d=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,d),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,0,-1,1,0,1,-1,0,-1,-1,0]),t.STATIC_DRAW),t.vertexAttribPointer(l,3,t.FLOAT,!1,0,0);var h=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,h),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,0,0,0,1,1,0,1]),t.STATIC_DRAW),t.vertexAttribPointer(c,2,t.FLOAT,!1,0,0),this.verticesBuffer=d,this.texCoordBuffer=h,t.y=new s(t),t.u=new s(t),t.v=new s(t),t.y.bind(0,o,"YTexture"),t.u.bind(1,o,"UTexture"),t.v.bind(2,o,"VTexture")}},i.prototype.renderFrame=function(e,t,o,a,r){if(this.gl){var s=this.gl;s.viewport(0,0,s.canvas.width,s.canvas.height),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT|s.DEPTH_BUFFER_BIT),s.y.fill(t,o,e.subarray(0,a)),s.u.fill(t>>1,o>>1,e.subarray(a,a+r)),s.v.fill(t>>1,o>>1,e.subarray(a+r,e.length)),s.drawArrays(s.TRIANGLE_STRIP,0,4)}},i.prototype.fullscreen=function(){var e=this.canvas;e.RequestFullScreen?e.RequestFullScreen():e.webkitRequestFullScreen?e.webkitRequestFullScreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.msRequestFullscreen?e.msRequestFullscreen():alert("This browser doesn't supporter fullscreen")},s.prototype.bind=function(e,t,o){var a=this.gl;a.activeTexture([a.TEXTURE0,a.TEXTURE1,a.TEXTURE2][e]),a.bindTexture(a.TEXTURE_2D,this.texture),a.uniform1i(a.getUniformLocation(t,o),e)},i.prototype.exitfullscreen=function(){document.exitFullscreen?document.exitFullscreen():document.webkitExitFullscreen?document.webkitExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.msExitFullscreen?document.msExitFullscreen():alert("Exit fullscreen doesn't work")},i.prototype.webGLDestroy=function(){var e=this.gl,t=this.program;e.clear(e.COLOR_BUFFER_BIT),e.clear(e.DEPTH_BUFFER_BIT),e.clear(e.STENCIL_BUFFER_BIT),e.deleteProgram(t);var o=this.verticesBuffer,a=this.texCoordBuffer;e.deleteBuffer(o),e.deleteBuffer(a);var r=e.y.texture,s=e.u.texture,i=e.v.texture;e.deleteTexture(r),e.deleteTexture(s),e.deleteTexture(i),this.canvas=null,this.gl=null};var n=i,l=o(1),c=o.n(l);function d(){return c()('!function(e){var o={};function t(a){if(o[a])return o[a].exports;var r=o[a]={i:a,l:!1,exports:{}};return e[a].call(r.exports,r,r.exports,t),r.l=!0,r.exports}t.m=e,t.c=o,t.d=function(e,o,a){t.o(e,o)||Object.defineProperty(e,o,{enumerable:!0,get:a})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,o){if(1&o&&(e=t(e)),8&o)return e;if(4&o&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(t.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&o&&"string"!=typeof e)for(var r in e)t.d(a,r,function(o){return e[o]}.bind(null,r));return a},t.n=function(e){var o=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(o,"a",o),o},t.o=function(e,o){return Object.prototype.hasOwnProperty.call(e,o)},t.p="",t(t.s=0)}([function(e,o){function t(){this.logger=new Logger("Decoder"),this.coreLogLevel=0,this.wasmLoaded=!1,this.tmpReqQue=[],this.cacheBuffer=null,this.decodeTimer=null,this.videoCallback=null,this.audioCallback=null,this.requestCallback=null,this.responseCallback=null,this.eventCallback=null,this.decoderCmdCallback=null,this.recordWriteCallback=null,this.recordUpdateCallback=null,this.key="",this.iv="",this.allChunks=[],this.recoding=!1,this.handShakeData=null,this.deviceReadyStatus=!1}self.Module={onRuntimeInitialized:function(){self.decoder&&self.decoder.onWasmLoaded()},locateFile:function(e,o){return location.origin+"/"+e}},self.importScripts(location.origin+"/enumConstant.js"),self.importScripts(location.origin+"/logger.js"),self.importScripts(location.origin+"/libffmpeg.js"),t.prototype.initDecoder=function(e,o,t,a,r){var l=Module._initDecoder(this.coreLogLevel,this.eventCallback,this.decoderCmdCallback,this.responseCallback);if(this.logger.logInfo("initDecoder return "+l+"."),0==l){if(t&&""!=t&&a&&""!=a&&r&&""!=r){var s=allocateUTF8(t),n=allocateUTF8(a),c=allocateUTF8(r);Module._setCipherInfo(c,s,n)}null==this.cacheBuffer&&(this.cacheBuffer=Module._malloc(o)),Module._setPlayMode(e)}var i={t:common.kInitDecoderRsp,e:l};self.postMessage(i)},t.prototype.uninitDecoder=function(){this.closeDecoder();var e=Module._uninitDecoder(),o={t:common.kCloseDecoderRsp,e:0};self.postMessage(o),this.logger.logInfo("Uninit ffmpeg decoder return "+e+"."),null!==this.cacheBuffer&&(Module._free(this.cacheBuffer),this.cacheBuffer=null)},t.prototype.getParam=function(e){var o,t,a,r,l,s,n,c,i,d,u=2002==e?3:4,f=Module._malloc(4*u),g=2002==e?Module._getAudioParam(f,u):Module._getVideoParam(f,u);this.logger.logInfo("getParam return "+g),0==g?(t=f>>2,a=Module.HEAP32.subarray(t,t+u),r=2002==e?"":a[0],l=2002==e?"":a[1],s=2002==e?"":a[2],n=2002==e?"":a[3],c=2002==e?a[0]:"",i=2002==e?a[1]:"",d=2002==e?a[2]:"",o={t:common.kGetParamRsp,e:g,type:2002==e?"audio":"video",v:{d:r,p:l,w:s,h:n},a:{f:c,c:i,r:d}},self.postMessage(o)):(o={t:common.kGetParamRsp,e:g},self.postMessage(o)),Module._free(f)},t.prototype.openDecoder=function(){Module._setRecordCallback(this.recordWriteCallback,this.recordUpdateCallback);var e,o=Module._openDecoder(this.videoCallback,this.audioCallback,this.requestCallback);this.logger.logInfo("openDecoder return "+o),0==o&&(e={t:common.kOpenDecoderRsp,e:o},self.postMessage(e))},t.prototype.closeDecoder=function(){!1,a=!1,this.logger.logInfo("closeDecoder."),this.decodeTimer&&(clearInterval(this.decodeTimer),this.decodeTimer=null,this.logger.logInfo("Decode timer stopped."));var e=Module._closeDecoder();this.logger.logInfo("Close ffmpeg decoder return "+e+".")},t.prototype.startDecoding=function(e){this.logger.logInfo("Start decoding."),this.decodeTimer&&clearInterval(this.decodeTimer),this.decodeTimer=setInterval(this.decode,e)},t.prototype.pauseDecoding=function(){this.logger.logInfo("Pause decoding."),this.decodeTimer&&(clearInterval(this.decodeTimer),this.decodeTimer=null)};t.prototype.decode=function(){(new Date).getTime();var e=Module._decodeOnePacket();(new Date).getTime();for(7==e&&self.decoder.logger.logInfo("Decoder finished."),0==e&&!0;9==e&&this.decodeTimer;)e=Module._decodeOnePacket()},t.prototype.sendData=function(e){var o=new Uint8Array(e);Module.HEAPU8.set(o,this.cacheBuffer),Module._sendData(this.cacheBuffer,o.length)},t.prototype.getSetPlayBackSpeedReq=function(e){var o,t,a,r,l,s=Module._malloc(4),n=Module._malloc(1024),c=allocateUTF8(e),i=Module._getSetPlayBackSpeedReq(n,s,1024,c);this.logger.logInfo("_getSetPlayBackSpeedReq return "+i),0==i&&(t=s>>2,a=Module.HEAP32.subarray(t,t+1)[0],r=Module.HEAPU8.subarray(n,n+a),l=new Uint8Array(r),o={t:common.getSetPlayBackSpeedReq,b:l},self.postMessage(o),l=null),Module._free(s),Module._free(n)},t.prototype.getSetPlayBackStartReq=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getSetPlayBackStartReq(s,l,1024);this.logger.logInfo("_getSetPlayBackStartReq return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getSetPlayBackStartReq,b:r},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.getSetPlayBackStartTimeReq=function(e){var o,t,a,r,l,s=Module._malloc(4),n=Module._malloc(1024),c=allocateUTF8(String(e)),i=Module._getSetPlayBackStartTimeReq(n,s,1024,c);this.logger.logInfo("_getSetPlayBackStartTimeReq return "+i),0==i&&(t=s>>2,a=Module.HEAP32.subarray(t,t+1)[0],r=Module.HEAPU8.subarray(n,n+a),l=new Uint8Array(r),o={t:common.getSetPlayBackStartTimeReq,b:l},self.postMessage(o)),Module._free(s),Module._free(n)},t.prototype.getHeartbeatPing=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getHeartbeatPing(s,l,1024);this.logger.logInfo("_getHeartbeatPing return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getHeartBeatRequest,b:r,l:t},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.handshakeReq=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getHandshakeReq(s,l,1024);this.logger.logInfo("_getHandshakeReq return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getHandshakeReq,b:r,l:t},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.talkhandshakeReq=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getHandshakeReq(s,l,1024);this.logger.logInfo("_getHandshakeReq return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getTalkHandshakeReq,b:r,l:t},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.getHandsharkReq=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getHandsharkReq(s,l,1024);this.logger.logInfo("_getHeartbeatPing return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getHandsharkRes,b:r,l:t},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.processReq=function(e){switch(e.t){case common.kInitDecoderReq:this.initDecoder(e.s,e.c,e.k,e.i,e.ct);break;case common.kUninitDecoderReq:this.uninitDecoder();break;case common.kOpenDecoderReq:this.openDecoder();break;case common.kCloseDecoderReq:this.closeDecoder();break;case common.kStartDecodingReq:this.startDecoding(e.i);break;case common.kPauseDecodingReq:this.pauseDecoding();break;case common.kFeedDataReq:this.sendData(e.d);break;case common.getHeartBeatRequest:this.getHeartbeatPing();break;case common.getHandshakeReq:this.handshakeReq();break;case common.resetDecoderFifo:this.resetDecoderFifo();break;case common.getSetPlayBackSpeedReq:this.getSetPlayBackSpeedReq(e.l);break;case common.getSetPlayBackStartReq:this.getSetPlayBackStartReq();break;case common.getSetPlayBackStartTimeReq:this.getSetPlayBackStartTimeReq(e.s);break;case common.getHandsharkReq:this.getHandsharkReq();break;case common.recoderStart:this.recoderStart();break;case common.recoderPause:case common.recoderPause:this.recoderPause();break;case common.getTalkStartReq:case common.initTalkEncode:this.initEncoder();break;case common.kGetDeviceInfo:this.sendTalkData(e.d);break;case common._getTalkStartReq:this.getTalkStartReq();break;case common.kStartTalkEncoderRsp:if(e.b){let o=JSON.parse(e.b);this.startTalkEncoder(8e3,16,1,o.audio_codec,o.sample,o.bitwidth,o.channel)}else this.startTalkEncoder();break;case common.pcmDataReq:this.encodePcmDataReq(e);break;case common.DestroyTalkReq:this.closeTalkEncoder(),this.uninitTalkDecoder();break;default:this.logger.logError("Unsupport messsage "+e.t)}},t.prototype.cacheReq=function(e){e&&this.tmpReqQue.push(e)},t.prototype.resetDecoderFifo=function(e){Module._resetDecoderFifo()};var a=!1;t.prototype.recoderStart=function(){this.recoding=!0,this.allChunks=[];Module._recoderStart()},t.prototype.recoderPause=function(){this.recoding=!1;Module._recoderPause();let e=this.allChunks;var o={t:common.kVideoDownRep,s:(new Date).getTime(),d:e};self.postMessage(o)},t.prototype.onWasmLoaded=function(){let e=this;this.logger.logInfo("Wasm loaded."),this.wasmLoaded=!0,this.videoCallback=Module.addFunction((function(e,o,t){var a=Module.HEAPU8.subarray(e,e+o),r=new Uint8Array(a);(new Date).getTime();var l={t:common.kVideoFrame,s:t,d:r};self.postMessage(l,[l.d.buffer])}),"viid"),this.audioCallback=Module.addFunction((function(e,o,t){var a=Module.HEAPU8.subarray(e,e+o),r=new Uint8Array(a);(new Date).getTime();var l={t:common.kAudioFrame,s:t,d:r};self.postMessage(l,[l.d.buffer]),r=null}),"viid"),this.requestCallback=Module.addFunction((function(e,o){}),"vii"),this.TalkEventCallback=Module.addFunction((function(e,o){if(e>=4&&e<=18){const e={t:common.serverDecoderTalkError,s:o};self.postMessage(e)}}),"vii"),this.TalkCmdCallback=Module.addFunction((function(o,t,a,r,l,s,n){let c=Number(t);if(0===c)switch(o){case 1:let o={t:common.kStartTalkEncoderdeviceready,b:""};e.deviceReadyStatus||(e.deviceReadyStatus=!0,self.postMessage(o));break;case 10:let t=UTF8ToString(s,n),a={t:common.kStartTalkEncoderRsp,b:t};self.postMessage(a)}else{let e={t:common.closeTalk,b:"",errorCode:c};self.postMessage(e)}}),"vijiijii"),this.TalkUserDataCallback=Module.addFunction((function(e,o){}),"vii"),this.recordWriteCallback=Module.addFunction(((e,o,t)=>{var a=Module.HEAPU8.subarray(o,o+t);o=new Uint8Array(a);if(this.allChunks.push(o),this.recoding){let e=this.allChunks;var r={t:common.kVideoDownChumksRep,s:(new Date).getTime(),d:e};self.postMessage(r)}}),"viii"),this.recordUpdateCallback=Module.addFunction(((e,o,t,a)=>{var r=Module.HEAPU8.subarray(o,o+t)||[0];this.allChunks[0][a]=r[0]}),"viiii"),this.decoderCmdCallback=Module.addFunction((function(e,o,t,a,r,l,s){var n,c,i,d,u;switch(e){case 1:d={t:common.deviceReady},self.postMessage(d);break;case 2:break;case 3:i={t:common.responseCurDateTime,d:r},self.postMessage(i);break;case 4:i={t:common.PlaybackOver},self.postMessage(i);break;case 8:c=UTF8ToString(l,s),n={t:common.playbakcRecordList,d:c},self.postMessage(n);break;case 9:u={t:common.heartPingResp},self.postMessage(u)}}),"vijiijii"),this.responseCallback=Module.addFunction((function(e,o){}),"vii");const o=this;this.eventCallback=Module.addFunction((function(e,t){if(e>=4&&e<=18){const o={t:common.serverDecoderError,s:e};self.postMessage(o)}switch(e){case 0:if(!a){const e={t:common.sendDataCallback};self.postMessage(e),a=!0}break;case 1:case 2:case 3:const t={t:common.socketLinkState,s:e};self.postMessage(t);break;case 2e3:const r={t:common.eventTypeFifoFull};self.postMessage(r);break;case 2001:const l={t:common.eventTypeFifoEnough};self.postMessage(l);break;case 2002:o.getParam(2002);break;case 2003:o.getParam(2003);break;case 2004:o.recoderPause();break;case 17:const s={t:common.serverDataTimeout};self.postMessage(s)}}),"vii");let t={t:common.onWasmLoaded};var r;for(self.postMessage(t);this.tmpReqQue.length>0;)r=this.tmpReqQue.shift(),this.processReq(r)},t.prototype.initEncoder=function(){Module._initTalkEncoder(this.TalkEventCallback,this.TalkCmdCallback,this.TalkUserDataCallback)},t.prototype.getTalkStartReq=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getTalkStartReq(s,l,1024);this.logger.logInfo("_getTalkStartReq return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getTalkStartReq,b:r,l:t},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.sendTalkData=function(e){var o=new Uint8Array(e);Module.HEAPU8.set(o,this.cacheBuffer),Module._sendTalkData(this.cacheBuffer,o.length)},t.prototype.getTalkStopReq=function(){var e,o,t,a,r,l=Module._malloc(4),s=Module._malloc(1024),n=Module._getTalkStopReq(s,l,1024);this.logger.logInfo("_getTalkStartReq return "+n),0==n&&(o=l>>2,t=Module.HEAP32.subarray(o,o+1)[0],a=Module.HEAPU8.subarray(s,s+t),r=new Uint8Array(a),e={t:common.getTalkStopReq,b:r,l:t},self.postMessage(e)),Module._free(l),Module._free(s)},t.prototype.startTalkEncoder=function(e=8e3,o=16,t=1,a=1,r=8e3,l=16,s=1){var n=Module._startTalkEncoder(e,o,t,a,r,l,s);if(this.logger.logInfo("开启音频编码器 "+n),0==n){let e={t:common.kGetAudioDataReq,b:""};self.postMessage(e)}},t.prototype.closeTalkEncoder=function(){Module._closeTalkEncoder();this.deviceReadyStatus=!1},t.prototype.uninitTalkDecoder=function(){Module._uninitTalkDecoder()},t.prototype.encodePcmDataReq=function(e){let o=e.p.d,t=e.p.h;if(0==t)return;e.p.t;var a=Module._malloc(4),r=Module._malloc(51200),l=Module._malloc(51200),s=new Uint8Array(o);Module.HEAPU8.set(s,r);var n,c,i,d,u,f=t+10240,g=Module._getAudioData(r,t,0,l,a,f),m=a,h=l;this.logger.logInfo("_getAudioData return "+g),0==g&&(c=m>>2,i=Module.HEAP32.subarray(c,c+1)[0],d=Module.HEAPU8.subarray(h,h+i),u=new Uint8Array(d),n={t:common.kgetTalkStartRep,b:u,l:i},self.postMessage(n)),Module._free(m),Module._free(h),Module._free(a),Module._free(r),Module._free(l)},self.decoder=new t,self.onmessage=function(e){if(self.decoder){var o=e.data;if(!self.decoder.wasmLoaded)return self.decoder.cacheReq(o),void self.decoder.logger.logInfo("Temp cache req "+o.t+".");self.decoder.processReq(o)}}}]);',"Worker",void 0,o.p+"decoder.worker:9c62edef.js")}function h(){return c()('!function(e){var t={};function o(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,o),s.l=!0,s.exports}o.m=e,o.c=t,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)o.d(r,s,function(t){return e[t]}.bind(null,s));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(e,t){function o(){this.logger=new Logger("Downloader"),this.ws=null,this.heartbeatTimer=null,this.heartbeatTimes=0}self.importScripts(location.origin+"/enumConstant.js"),self.importScripts(location.origin+"/logger.js"),o.prototype.appendBuffer=function(e,t){var o=new Uint8Array(e.byteLength+t.byteLength);return o.set(new Uint8Array(e),0),o.set(new Uint8Array(t),e.byteLength),o.buffer},o.prototype.reportData=function(e){var t={t:common.kFileData,d:e};self.postMessage(t,[t.d])},o.prototype.requestWebsocket=function(e,t){var o,r,s=this;null===this.ws&&(this.ws=new WebSocket(e),this.ws.binaryType="arraybuffer",this.ws.onopen=function(e){s.logger.logInfo("Ws connected."),s.heartbeatTimes=0,r={t:common.sendHandshakeReq},self.postMessage(r)},this.ws.onerror=function(e){s.logger.logError("Ws connect error "+e.data),s.heartbeatTimes=0,s.ws=null},this.ws.onclose=function(e){clearInterval(s.heartbeatTimer),s.ws=null,o={t:common.socketActiveClose,d:e.code,w:e.wasClean},self.postMessage(o),s.heartbeatTimes=0},this.ws.onmessage=this.onmessage.bind(this))},o.prototype.onmessage=function(e){this.heartbeatTimes=0;var t=e.data;t.byteLength>10485760||self.downloader.reportData(t)},o.prototype.handshakeReq=function(e){this.ws&&this.ws.send(e)},o.prototype.startHeartbeatTimer=function(e){this.ws&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=setInterval((()=>{this.ws.send(e),this.heartbeatTimes=this.heartbeatTimes+1,this.heartbeatTimes>3&&(this.ws.close(),clearInterval(this.heartbeatTimer),this.ws=null,req={t:common.socketNoActive},self.postMessage(req),this.heartbeatTimes=0)}),13e3))},o.prototype.closeWebsocket=function(e){this.ws&&(this.ws.close(),clearInterval(this.heartbeatTimer))},o.prototype.setPlayBackSpeed=function(e){this.ws&&this.ws.send(e)},o.prototype.setPlayBackStart=function(e){this.ws&&this.ws.send(e)},o.prototype.SetPlayBackStartTime=function(e){this.ws&&this.ws.send(e)},o.prototype.heartPingResp=function(){this.heartbeatTimes=0},self.downloader=new o,self.onmessage=function(e){if(self.downloader){var t=e.data;switch(t.t){case common.fetchStream:self.downloader.requestWebsocket(t.url,t.msg);break;case common.DownloaderHeartBeat:self.downloader.startHeartbeatTimer(t.b);break;case common.DownloaderHandshakeReq:self.downloader.handshakeReq(t.b);break;case common.closeWebsocket:self.downloader.closeWebsocket();break;case common.getSetPlayBackSpeedReq:self.downloader.setPlayBackSpeed(t.b);break;case common.getSetPlayBackStartReq:self.downloader.setPlayBackStart(t.b);break;case common.getSetPlayBackStartTimeReq:self.downloader.SetPlayBackStartTime(t.b);break;case common.heartPingResp:self.downloader.heartPingResp();break;default:self.downloader.logger.logError("Unsupport messsage "+t.t)}}}}]);',"Worker",void 0,o.p+"downloader.worker:3ede097f.js")}function u(){return c()('!function(e){var t={};function a(s){if(t[s])return t[s].exports;var r=t[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,a),r.l=!0,r.exports}a.m=e,a.c=t,a.d=function(e,t,s){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(a.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)a.d(s,r,function(t){return e[t]}.bind(null,r));return s},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=0)}([function(e,t){function a(){this.logger=new Logger("Talkloader"),this.ws=null,this.heartbeatTimer=null,this.heartbeatTimes=0,this.handShakeData=null,this.heartbeatPingData=null,this.audioBufferArray=[]}self.importScripts(location.origin+"/enumConstant.js"),self.importScripts(location.origin+"/logger.js"),a.prototype.appendBuffer=function(e,t){var a=new Uint8Array(e.byteLength+t.byteLength);return a.set(new Uint8Array(e),0),a.set(new Uint8Array(t),e.byteLength),a.buffer},a.prototype.requestWebsocket=function(e,t){var a=this;null===this.ws?(this.ws=new WebSocket(e),this.ws.binaryType="arraybuffer",this.ws.onopen=function(e){a.logger.logInfo("talkWs connected."),a.heartbeatTimes=0,a.ws.send(a.handShakeData),a.startHeartbeatTimer(a.heartbeatPingData),a.initTalkEncode()},this.ws.onerror=function(e){a.logger.logError("talkWs connect error "+e.data),a.heartbeatTimes=0},this.ws.onclose=function(e){clearInterval(a.heartbeatTimer),a.ws=null,req={t:common.socketActiveClose,d:e.code,w:e.wasClean},self.postMessage(req),a.heartbeatTimes=0},this.ws.onmessage=this.onmessage.bind(this)):this.ws.onmessage=this.onmessage.bind(this)},a.prototype.onmessage=function(e){this.heartbeatTimes=0;var t=e.data;let a={t:common.kGetDeviceInfo,d:t};self.postMessage(a)},a.prototype.initTalkEncode=function(){var e={t:common.initTalkEncode,s:new Date};self.postMessage(e)},a.prototype.startHeartbeatTimer=function(e){this.ws&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=setInterval((()=>{this.ws.send(e),this.heartbeatTimes=this.heartbeatTimes+1,this.heartbeatTimes>3&&(this.ws.close(),clearInterval(this.heartbeatTimer),this.ws=null,req={t:common.socketNoActive},self.postMessage(req),this.heartbeatTimes=0)}),13e3))},a.prototype.getTalkStartReq=function(){var e={t:common.getTalkStartReq,s:new Date};self.postMessage(e)},a.prototype.setTalkStartRep=function(e){0===this.ws.bufferedAmount&&this.ws.send(e)},a.prototype.setTalkG711Data=function(e){this.ws&&this.ws.send(e)},a.prototype.closeWebsocket=function(e){if(this.ws){this.ws.close(),clearInterval(this.heartbeatTimer),this.ws=null;let e={t:common.DestroyTalkRes};self.postMessage(e)}},a.prototype.setHandShakeData=function(e){this.handShakeData=e},a.prototype.setHeartbeatPingData=function(e){this.heartbeatPingData=e},a.prototype.heartPingResp=function(){this.heartbeatTimes=0},self.talkloader=new a,self.onmessage=function(e){if(self.talkloader){var t=e.data;switch(t.t){case common.fetchStream:self.talkloader.requestWebsocket(t.url);break;case common.DownloaderHeartBeat:self.talkloader.setHeartbeatPingData(t.b);break;case common.TalkHandshakeReq:self.talkloader.setHandShakeData(t.b);break;case common.talkStartRep:self.talkloader.setTalkStartRep(t.b);break;case common.kgetTalkStartRep:self.talkloader.setTalkG711Data(t.b);break;case common.closeWebsocket:self.talkloader.closeWebsocket();break;case common.heartPingResp:self.talkloader.heartPingResp();break;case common.DestroyTalkReq:self.talkloader.closeWebsocket();break;default:self.talkloader.logger.logError("Unsupport messsage "+t.t)}}}}]);',"Worker",void 0,o.p+"talk.worker:e994faef.js")}var p=o(2),f=o.n(p);new f.a("Event").logInfo("Event.js 已加载");class m{constructor(e){this.target={},this.eventsQueue={},this.disallowRepeat=!1}add(e=[],t,o){for(let a of e)this.on(a,t,o)}on(e,t,o){if(void 0===this.eventsQueue[e]&&(this.eventsQueue[e]={methods:[]}),"function"==typeof t){if(!this.disallowRepeat||!this.eventsQueue[e].methods.includes(t))return void 0!==o&&(t.once=o),this.eventsQueue[e].methods.push(t),this.target}else logger.error("on","the argument is not function.",t)}once(e,t){this.on(e,t,!0)}off(e,t){let o=this.eventsQueue[e];if(!o)return;let a=o.methods;if(t){let e=a.length;for(;e--;)a[e]===t&&a.splice(e,1)}else delete this.eventsQueue[e];return this.target}emit(e,...t){let o=this.eventsQueue[e];if(o)return o.methods.forEach((o=>{o.apply(this.target,t),o.once&&this.off(e,o)})),this.target}clear(e){delete this.eventsQueue[e]}clearAll(){this.eventsQueue={}}}var g=function(e){const t=new m(e);return e=>(t.target=e,t)};var k=o(0),y=o.n(k);function R(e,t){let o=t||{};if(!e)return;this.canvasContainer=e,e.style.position="relative";const a=parseInt(getComputedStyle(e).width),r=parseInt(getComputedStyle(e).height);this.conW=a,this.conH=r;const s=document.createElement("canvas");s.width=a,s.height=r,s.style.cssText="transform: scale(1);transform-origin: 0 0;",s.setAttribute("class","videoCanvas"),this.msg="链接已断开";const i=document.createElement("div");i.style.cssText="position: absolute;z-index: 2;background-color: rgba(0, 0, 0, 0);margin: 0;top: 0;right: 0;bottom: 0;left: 0;",e.appendChild(s),e.appendChild(i),i.setAttribute("class","videoCanvasMsg");this.container_el=e,this.canvas=s,this.stateContainer_el=i,this.loading_el_str=o.loading_el_str?o.loading_el_str:'<div style="top: 50%;margin-top: -21px;width: 100%;text-align: center;position: absolute;"><svg t="1607391066926" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1837" width="20" height="20"><path d="M512 64q14.016 0 23.008 8.992T544 96v192q0 14.016-8.992 23.008T512 320t-23.008-8.992T480 288V96q0-14.016 8.992-23.008T512 64z m0 640q14.016 0 23.008 8.992T544 736v192q0 14.016-8.992 23.008T512 960t-23.008-8.992T480 928v-192q0-14.016 8.992-23.008T512 704z m448-192q0 14.016-8.992 23.008T928 544h-192q-14.016 0-23.008-8.992T704 512t8.992-23.008T736 480h192q14.016 0 23.008 8.992T960 512z m-640 0q0 14.016-8.992 23.008T288 544H96q-14.016 0-23.008-8.992T64 512t8.992-23.008T96 480h192q14.016 0 23.008 8.992T320 512zM195.008 195.008q10.016-8.992 23.008-8.992t22.016 8.992l136 136q8.992 10.016 8.992 22.496t-9.504 22.016-22.016 9.504-22.496-8.992l-136-136q-8.992-8.992-8.992-22.016t8.992-23.008zM648 648q10.016-10.016 22.496-10.016t22.496 10.016l136 136q8.992 8.992 8.992 22.016t-9.504 22.496-22.496 9.504-22.016-8.992l-136-136q-10.016-10.016-10.016-22.496t10.016-22.496z m180.992-452.992q8.992 10.016 8.992 23.008t-8.992 22.016l-136 136q-10.016 8.992-22.496 8.992t-22.016-9.504-9.504-22.016 8.992-22.496l136-136q8.992-8.992 22.016-8.992t23.008 8.992zM376 648q10.016 10.016 10.016 22.496t-10.016 22.496l-136 136q-8.992 8.992-22.016 8.992t-22.496-9.504-9.504-22.496 8.992-22.016l136-136q10.016-10.016 22.496-10.016t22.496 10.016z" p-id="1838" fill="#A4A9B3"></path></svg><p style="color: #A4A9B3;margin: 3px 0;font-size: 14px;">视频连接中...</p></div>',this.pauseimg_el_str=o.pauseimg_el_str?o.pauseimg_el_str:'<div id="iconPlay" style="width: 120px;height: 120px;position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%);display: flex;align-items: center;justify-content: center;" class="iconPlay">\n <svg width="61px" height="60px" viewBox="0 0 61 60" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\n <title>重播</title>\n <g id="实时预览-云台" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <g id="录像回放/重播按钮" transform="translate(-827.000000, -257.000000)">\n <g id="编组-5" transform="translate(510.000000, 110.000000)">\n <g id="重播" transform="translate(317.500000, 147.000000)">\n <rect id="矩形" fill="#1F1F1F" style="mix-blend-mode: multiply;" opacity="0.565970285" x="0" y="0" width="60" height="60" rx="30"></rect>\n <path d="M34.7557911,21.2189504 L44.4776159,39.0422957 C45.0065413,40.0119924 44.6492256,41.2268657 43.679529,41.7557911 C43.3857518,41.9160333 43.0564627,42 42.7218247,42 L23.2781753,42 C22.1736058,42 21.2781753,41.1045695 21.2781753,40 C21.2781753,39.665362 21.362142,39.3360729 21.5223841,39.0422957 L31.2442089,21.2189504 C31.7731343,20.2492538 32.9880076,19.8919381 33.9577043,20.4208635 C34.2948373,20.6047543 34.5719004,20.8818174 34.7557911,21.2189504 Z" id="三角形备份" fill="#FFFFFF" transform="translate(33.000000, 30.000000) rotate(-270.000000) translate(-33.000000, -30.000000) "></path>\n </g>\n </g>\n </g>\n </g>\n </svg>\n </div>',this.msg_el_str=o.msg_el_str?o.msg_el_str():function(e){return`<div style="top: 50%;margin-top: -21px;width: 100%;text-align: center;position: absolute;"><p style="color: #A4A9B3;margin: 3px 0;font-size: 14px;">${e}</p></div>`},this.stateContainer_el.innerHTML=""}R.prototype._showOrHideShade=function(e){this.stateContainer_el.style.backgroundColor=e},R.prototype.showPauseIcon=function(){this._showOrHideShade("rgba(0,0,0,0)"),this.pauseimg_el_str.nodeType?(this.stateContainer_el.innerHTML="",this.stateContainer_el.appendChild(this.pauseimg_el_str)):this.stateContainer_el.innerHTML=this.pauseimg_el_str},R.prototype.showLoading=function(){this._showOrHideShade("rgba(0,0,0,1)"),this.stateContainer_el.innerHTML="",this.loading_el_str.nodeType?(this.stateContainer_el.innerHTML="",this.stateContainer_el.appendChild(this.loading_el_str)):this.stateContainer_el.innerHTML=this.loading_el_str},R.prototype.showMsg=function(e,t){this._showOrHideShade("rgba(0,0,0,1)"),this.stateContainer_el.innerHTML="";let o=null;o=e||t?"function"==typeof this.msg_el_str&&e?this.msg_el_str(e,t):this.msg_el_str(t):this.msg_el_str(""),o.nodeType?(this.stateContainer_el.innerHTML="",this.stateContainer_el.appendChild(o)):this.stateContainer_el.innerHTML=o},R.prototype.hideAll=function(){this._showOrHideShade("rgba(0,0,0,0)"),this.msg="",this.stateContainer_el.innerHTML=""};var v=R;var b={4:{code:4,code16:4,eventStr:"SERVER_UNKNOWN_ERROR",msg:"服务器未知错误"},5:{code:5,code16:5,eventStr:"SERVER_NOT_READY",msg:"服务器未准备好"},6:{code:6,code16:6,eventStr:"SERVER_USER_ABORT",msg:"服务器端用户主动断开"},7:{code:7,code16:7,eventStr:"SERVER_STOPPED",msg:"服务器服务已停止"},8:{code:8,code16:8,eventStr:"SERVER_ABORT",msg:"服务器服务已中断"},9:{code:9,code16:9,eventStr:"SERVER_STREAM_STOP",msg:"服务器流停止"},10:{code:10,code16:10,eventStr:"SERVER_CONNECT_DEV_FAILED",msg:"连接设备失败"},11:{code:11,code16:11,eventStr:"SERVER_SUBDEV_STREAM_ERR",msg:"订阅设备流失败"},12:{code:12,code16:12,eventStr:"SERVER_INVALID_CONTEXT",msg:"不合法的上下文"},13:{code:13,code16:13,eventStr:"SERVER_DEVICE_TIMEOUT",msg:"设备超时"},14:{code:14,code16:14,eventStr:"SERVER_CLIENT_TIMEOUT",msg:"客户端超时"},15:{code:15,code16:15,eventStr:"SERVER_OVER_DEV_LIMIT",msg:"超过设备最大连接数"},16:{code:16,code16:16,eventStr:"SERVER_PERM_DENIED",msg:"无权限"},17:{code:17,code16:17,eventStr:"SERVER_DATA_TIMEOUT",msg:"数据超时"},18:{code:18,code16:18,eventStr:"SERVER_DEVICE_ABORT",msg:"服务器端设备主动断开"}};let S=function(e,t=16,o=48e3){t=t,o=o;var a=new AudioContext,r=a.createMediaStreamSource(e),s=a.createScriptProcessor(4096,1,1),i={size:0,buffer:[],inputSampleRate:o,inputSampleBits:16,outputSampleRate:8e3,oututSampleBits:t,clear:function(){this.buffer=[],this.size=0},input:function(e){this.buffer.push(new Float32Array(e)),this.size+=e.length},compress:function(){for(var e=new Float32Array(this.size),t=0,o=0;o<this.buffer.length;o++)e.set(this.buffer[o],t),t+=this.buffer[o].length;for(var a=parseInt(this.inputSampleRate/this.outputSampleRate),r=e.length/a,s=new Float32Array(r),i=0,n=0;i<r;)s[i]=e[n],n+=a,i++;return s},encodePCM:function(){Math.min(this.inputSampleRate,this.outputSampleRate);for(var e=Math.min(this.inputSampleBits,this.oututSampleBits),t=this.compress(),o=t.length*(e/8),a=new ArrayBuffer(o),r=new DataView(a),s=0,i=0;i<t.length;i++,s+=2){var n=Math.max(-1,Math.min(1,t[i]));r.setInt16(s,n<0?32768*n:32767*n,!0)}return new Blob([r])}};this.start=function(){r.connect(s),s.connect(a.destination)},this.stop=function(){s.disconnect()},this.getBlob=function(){return i.encodePCM()},this.clear=function(){i.clear()},s.onaudioprocess=function(e){i.input(e.inputBuffer.getChannelData(0))}};const T=0,E=1,_=2;var w=0;function D(e){this.url=e.url,this.endtime=e.endtime,this.isStream=e.isStream,this.k=e.encrypted_key,this.i=e.encrypted_iv,this.ct=e.encrypted_type,this.streamHighWaterFrame=e.streamHighWaterFrame?e.streamHighWaterFrame:25,this.playbackHighWaterFrame=e.playbackHighWaterFrame?e.playbackHighWaterFrame:25,this.playbackLowWaterFrame=e.playbackLowWaterFrame?e.playbackLowWaterFrame:10,this.language=e.language?e.language:"ch",this.deviceName=e.deviceName?e.deviceName:"设备"}function M(e,t){var o;this.el=e,this.observer=null,this.event=g(this)(),(o=this.event).on("SERVER_UNKNOWN_ERROR",(e=>{o.emit("UNKNOWN_ERROR",e)})),o.on("SERVER_NOT_READY",(e=>{o.emit("NOT_READY",e)})),o.on("SERVER_USER_ABORT",(e=>{o.emit("USER_ABORT",e)})),o.on("SERVER_STOPPED",(e=>{o.emit("STOPPED",e)})),o.on("SERVER_ABORT",(e=>{o.emit("ABORT",e)})),o.on("SERVER_STREAM_STOP",(e=>{o.emit("STREAM_STOP",e)})),o.on("SERVER_CONNECT_DEV_FAILED",(e=>{o.emit("CONNECT_DEV_FAILED",e)})),o.on("SERVER_SUBDEV_STREAM_ERR",(e=>{o.emit("SUBDEV_STREAM_ERR",e)})),o.on("SERVER_INVALID_CONTEXT",(e=>{o.emit("INVALID_CONTEXT",e)})),o.on("SERVER_DEVICE_TIMEOUT",(e=>{o.emit("DEVICE_TIMEOUT",e)})),o.on("SERVER_CLIENT_TIMEOUT",(e=>{o.emit("CLIENT_TIMEOUT",e)})),o.on("SERVER_OVER_DEV_LIMIT",(e=>{o.emit("OVER_DEV_LIMIT",e)})),o.on("SERVER_PERM_DENIED",(e=>{o.emit("PERM_DENIED",e)})),o.on("SERVER_DATA_TIMEOUT",(e=>{o.emit("DATA_TIMEOUT",e)})),o.on("SERVER_DEVICE_ABORT",(e=>{o.emit("DEVICE_ABORT",e)})),o.on("MEDIA_ERROR",(e=>{o.emit("GET_MEDIA_ERROR",e)})),o.on("MEDIA_PROGRESS_INFO",(e=>{o.emit("GET_MEDIA_PROGRESS_INFO",e)})),o.on("DEVICE_RECORD_LIST",(e=>{o.emit("GET_DEVICE_RECORD_LIST",e)})),o.on("MEDIA_PLAY",(()=>{o.emit("GET_MEDIA_PLAY")})),o.on("MEDIA_PAUSE",(()=>{o.emit("GET_MEDIA_PAUSE")})),o.on("MEDIA_STOP",(()=>{o.emit("GET_MEDIA_STOP")})),o.on("VIDEO_MAX_END",(()=>{o.emit("GET_VIDEO_MAX_END")})),this.currentVolume=100,this.configInfo=null,this.pcmPlayer=null,this.canvas=null,this.webglPlayer=null,this.frameRate=0,this.pixFmt=0,this.videoWidth=0,this.videoHeight=0,this.yLength=0,this.uvLength=0,this.playerState=T,this.socketSending=!1,this.decoding=!1,this.currentTimestamp="",this.audioEncoding="",this.audioChannels=0,this.audioSampleRate=0,this.sampleFmt=0,this.speedNum=2,this.setFrameRate=1,this.seeking=!1,this.loadingDiv=null,this.loadingState=!0,this.buffering=!1,this.frameBuffer=[],this.isStream=!1,this.logger=new f.a("Player"),this.drawingState=!1,this.speeding=!1,this.playInitState=!0,this.playFirstGetParams=!0,this.requestAnimationFrame=null,this._onSnapshot=null,this._curSpeed=null,this.endtime=null;const a=new v(e,t);this.showPauseIcon=()=>{a.showPauseIcon()},this.showLoading=()=>{a.showLoading()},this.showMsg=(e,t)=>{a.showMsg(e,t)},this.hideAll=()=>{a.hideAll()},this._msgController=a,this.talkRecord=null,this.talkTimer=null,this.talkStream=null,this.getAudioDating=!1,this.getAudioDataStatus=!1;this.observer=new MutationObserver((e=>{if(this.videoHeight&&this.videoWidth&&this._msgController){let e=Math.ceil(1e5*parseInt(getComputedStyle(this.el).width)/this.videoWidth)/1e5,t=Math.ceil(1e5*parseInt(getComputedStyle(this.el).height)/this.videoHeight)/1e5;this.canvas.style.cssText=`transform: scale(${e},${t});transform-origin: 0 0;position:absolute;left: 0;top: 0;`}})),this.observer.observe(this._msgController.canvasContainer,{attributes:!0}),Object.defineProperty(this,"onSnapshot",{set:e=>{this._onSnapshot=e}})}M.prototype.initDownloadWorker=function(){var e,t=this;this.downloadWorker=new h,this.downloadWorker.onmessage=function(o){var a=o.data;switch(a.t){case y.a.sendHandshakeReq:e={t:y.a.getHandshakeReq},t.decodeWorker.postMessage(e);break;case y.a.kFileData:t.onFileData(a.d);break;case y.a.socketActiveClose:t.onsocketActiveClose(a.d,a.w);break;case y.a.socketNoActive:t.onsocketNoActive()}}},M.prototype.initDecodeWorker=function(){var e=this;this.decodeWorker=new d,this.decodeWorker.onmessage=function(t){var o=t.data;const a={[y.a.kInitDecoderRsp]:"onInitDecoder",[y.a.kOpenDecoderRsp]:"onOpenDecoder",[y.a.kVideoFrame]:"onVideoFrame",[y.a.kAudioFrame]:"onAudioFrame",[y.a.kDecodeFinishedEvt]:"onDecodeFinished",[y.a.sendDataCallback]:"onSendDataCallback",[y.a.kGetParamRsp]:"onGetParam",[y.a.socketLinkState]:"onSocketLinkState",[y.a.getHeartBeatRequest]:"onGetHeartBeatRequest",[y.a.getHandshakeReq]:"onGetHandshakeReq",[y.a.getSetPlayBackSpeedReq]:"onGetSetPlayBackSpeedReq",[y.a.getSetPlayBackStartReq]:"onGetSetPlayBackStartReq",[y.a.deviceReady]:"onDeviceReady",[y.a.getSetPlayBackStartTimeReq]:"onGetSetPlayBackStartTimeReq",[y.a.responseCurDateTime]:"onResponseCurDateTime",[y.a.eventTypeFifoFull]:"onEventTypeFifoFull",[y.a.eventTypeFifoEnough]:"onEventTypeFifoEnough",[y.a.playbakcRecordList]:"onPlaybakcRecordList",[y.a.serverDataTimeout]:"onServerDataTimeout",[y.a.serverDecoderError]:"onDecoderError",[y.a.serverDecoderTalkError]:"onDecoderTalkError",[y.a.heartPingResp]:"onHeartPingResp",[y.a.getHandsharkRes]:"onGetHandsharkRes",[y.a.kCloseDecoderRsp]:"onCloseDecoderRsp",[y.a.onWasmLoaded]:"onWasmLoaded",[y.a.kVideoDownRep]:"onVideoDownRep",[y.a.kVideoDownChumksRep]:"onVideoDownChumksRep",[y.a.getTalkStartReq]:"onTalkStartRep",[y.a.kStartTalkEncoderRsp]:"onStartTalkEncoder",[y.a.kGetAudioDataReq]:"onGetAudioDataReq",[y.a.kgetTalkStartRep]:"onGetAudioDataRep",[y.a.closeTalk]:"onCloseTalk",[y.a.kStartTalkEncoderdeviceready]:"onkTalkEncoderdeviceready",[y.a.PlaybackOver]:"onPlaybackOver"};a[o.t]&&e[a[o.t]](o)}},M.prototype.play=function(e){this.frameBuffer.length=0,this.frameBuffer=[];let{url:t,endtime:o,isStream:a,i:r,k:s,t:i}=e,l={e:0,m:"Success"},c=this;{if(this.playerState==_)return l=this.resume(),l;if(this.playerState==E)return l;if(!t)return l={e:-1,m:"Invalid url"},this.logger.logError("[ER] playVideo error, url empty."),l;if(!a&&!o)return l={e:-1,m:"Invalid endtime"},this.logger.logError("[ER] playVideo error, endtime empty."),l;if(!("AES-256-GCM"!=i||r&&s))return l={e:-1,m:"Invalid params"},this.logger.logError("[ER] playVideo error, params empty."),l;this.initDownloadWorker(),this.initDecodeWorker(),this.initTalkWorker(),this.canvas=this._msgController.canvas,this.configInfo=null,this.configInfo=new D(e),this.playerState=E,this.isStream=a,this.endtime=o,this.webglPlayer=new n(this.canvas,{preserveDrawingBuffer:!0,antialias:!0}),this.displayLoop();const d={t:y.a.kInitDecoderReq,s:this.isStream?0:1,c:4194304,k:this.configInfo.k,i:this.configInfo.i,ct:this.configInfo.ct};this.decodeWorker.postMessage(d);let h=!1;this.registerVisibilityEvent((function(e){e&&1==c.playerState?(c.getAudioDataStatus&&!c.getAudioDating&&c.startRecord(),c.isStream?1==h&&(c.pcmPlayer&&c.pcmPlayer.resume(),c.decodeWorker.postMessage({t:y.a.resetDecoderFifo}),c.startDecoding(),h=!1):1==h&&(c.resume(),h=!1)):(c.getAudioDataStatus&&c.getAudioDating&&c.talkPause(),c.isStream?(h=!0,c.pcmPlayer&&c.pcmPlayer.pause(),c.pauseDecoding()):c.playerState==E&&(c.pause(),h=!0))})),this.buffering=!0,this.loadingState=!0,this.hideAll(),this.event.emit("GET_MEDIA_PLAY")}return l},M.prototype.seekTo=function(e){let t={e:-1,m:"Parameter Null."};if(!e)return this.logger.logError("[ER] seekTo error, time empty."),t;if(this.playerState!=E)return t.m="Player Is NotPlaying",t;this.seeking=!0,this.speeding=!1,this.pauseDecoding(),this.decodeWorker.postMessage({t:y.a.resetDecoderFifo}),this.frameBuffer.length=0;const o={t:y.a.getSetPlayBackStartTimeReq,s:e};return this.decodeWorker.postMessage(o),t.e=0,t.m="SeekTo Success.",t},M.prototype.setSpeed=function(e){let t={e:-1,m:"Parameter Null."};if(!e)return this.logger.logError("[ER] seekTo error, time empty."),t;const o=["0","1/16","1/8","1/4","1/2","1","2","4","8","16"];let a=["0","0.0625","0.125","0.25","0.5","1","2","4","8","16"].findIndex((t=>t==e));if(a>-1){this.speed(o[a]),"0"!=o[a]&&(this._curSpeed=e),this.event.emit("speedNum",o[a]);const r=parseFloat(e);return r>1&&(this.speeding=!0,this.setFrameRate=this.setFrameRateFn(),this.speedNum=2*r,this.restartAudio()),r>0&&r<1&&(this.speeding=!0,this.speedNum=2,0!=this.frameRate&&(this.setFrameRate=Math.floor(this.setFrameRateFn()/r)),this.restartAudio()),1!=r&&0!=r||(this.speeding=!1,this.speedNum=2,this.setFrameRate=this.setFrameRateFn()),t.e=0,t.m="SetSpeed Success.",t}return t.m="Invalid Parameter.",t},M.prototype.pause=function(){let e={e:-1,m:"Not playing"};if(!this.isStream)return this.playerState!=E||(this.playerState=_,this.pcmPlayer&&this.pcmPlayer.pause(),this.setSpeed("0"),this.pauseDecoding(),this.showPauseIcon(),this.event.emit("GET_MEDIA_PAUSE"),e.e=0,e.m="Pause Success."),e},M.prototype.resume=function(){this.logger.logInfo("Resume.");let e={e:-1,m:"Not pausing"};return this.playerState!=_||(this.playerState=E,this.pcmPlayer&&this.pcmPlayer.resume(),this.startDecoding(),this.setSpeed("1"),this.hideAll(),this.event.emit("GET_MEDIA_PLAY"),e.e=0,e.m="Resume Success."),e},M.prototype.stop=function(e,t){let o={e:-1,m:"Not playing."};return this.playerState==T||(this.playerState=T,this.resetPlayer(e,t),this.getAudioDataStatus&&(this.getAudioDataStatus=!1,this.talkDestroy()),o.e=0,o.m="Stop Success."),o},M.prototype.resetPlayer=function(e,t){this.closeWebsocket(),(window.cancelAnimationFrame||window.mozCancelAnimationFrame)(this.requestAnimationFrame),this.webglPlayer.webGLDestroy(),this.loadingState=!1,this.canvas=null,this.webglPlayer=null,this.frameRate=0,this.pixFmt=0,this.videoWidth=0,this.videoHeight=0,this.yLength=0,this.uvLength=0,this.audioEncoding="",this.audioChannels=0,this.audioSampleRate=0,this.sampleFmt=0,this.speedNum=2,this.setFrameRate=1,this.playerState=T,this.socketSending=!1,this.decoding=!1,this.currentTimestamp="",this.frameBuffer.length=0,this.frameBuffer=[],this.buffering=!1,this.drawingState=!1,this.speeding=!1,this.playInitState=!0,this.playFirstGetParams=!0,w=0,this.requestAnimationFrame=null,this.endtime=null,this._curSpeed=null,this.pcmPlayer&&(this.pcmPlayer.destroy(),this.pcmPlayer=null,this.logger.logInfo("Pcm player released.")),this.logger.logInfo("Closing decoder."),this.decodeWorker.postMessage({t:y.a.kUninitDecoderReq}),this.showMsg(e,t),this.logger.logInfo("Uniniting decoder."),this.observer=null},M.prototype.reconnection=function(){const e={url:this.configInfo.url,endtime:this.configInfo.endtime,isStream:this.configInfo.isStream,k:this.configInfo.k,i:this.configInfo.i,ct:this.configInfo.ct,streamHighWaterFrame:this.configInfo.streamHighWaterFrame,playbackHighWaterFrame:this.configInfo.playbackHighWaterFrame,playbackLowWaterFrame:this.configInfo.playbackLowWaterFrame,language:this.configInfo.language?this.configInfo.language:"ch",deviceName:this.configInfo.deviceName?this.configInfo.deviceName:"设备"};this.play(e)},M.prototype.getCurTimestamp=function(){return this.currentTimestamp},M.prototype.fullscreen=function(){this.webglPlayer&&this.webglPlayer.fullscreen()},M.prototype.getState=function(){return this.playerState},M.prototype.volume=function(e){let t={e:-1,m:"Parameter Null"};return null===e||(null!==this.pcmPlayer&&this.pcmPlayer.volume(e),this.currentVolume=e,t.e=0,t.m="Set Volume Success."),t},M.prototype.recoderStart=function(){var e={t:y.a.recoderStart};this.decodeWorker.postMessage(e)},M.prototype.recoderPause=function(){var e={t:y.a.recoderPause};this.decodeWorker.postMessage(e)},M.prototype.setFrameRateFn=function(){return 1},M.prototype.displayLoop=function(){if(this.playerState!=T){let e=window.requestAnimationFrame||window.mozRequestAnimationFrame;this.requestAnimationFrame=e(this.displayLoop.bind(this))}if(this.playerState==E&&0!=this.frameBuffer.length&&!this.buffering)if(!this.isStream&&w<this.setFrameRate)w++;else{var e;this.loadingState=!1;for(let t=0;t<this.speedNum;++t){switch((e=this.frameBuffer[0]).t){case y.a.kAudioFrame:if(this.displayAudioFrame(e)){this.frameBuffer.shift();this.frameBuffer.filter((e=>5==e.t))}break;case y.a.kVideoFrame:if(this.displayVideoFrame(e)){this.frameBuffer.shift(),w=0;this.frameBuffer.filter((e=>4==e.t))}break;default:return}if(0==this.frameBuffer.length)break}!this.isStream&&this.frameBuffer.length>=this.configInfo.playbackHighWaterFrame&&this.socketSending&&(this.setSpeed("0"),this.event.emit("speedNum",0)),!this.isStream&&this.frameBuffer.length<this.configInfo.playbackLowWaterFrame&&(this.socketSending||(this._curSpeed?(this.setSpeed(this._curSpeed),this.event.emit("speedNum",this._curSpeed)):(this.setSpeed("1"),this.event.emit("speedNum",1)))),this.isStream&&this.frameBuffer.length>=this.configInfo.streamHighWaterFrame&&(this.frameBuffer=[])}},M.prototype.displayAudioFrame=function(e){if(this.playerState!=E)return!1;if(this.speeding)return!0;if(this.seeking&&(this.restartAudio(),this.loadingState=!1,this.seeking=!1),this.pcmPlayer){(new Date).getTime();this.pcmPlayer.feed(e.d)}return!0},M.prototype.displayVideoFrame=function(e){if(this.playerState!=E)return!1;if(this.seeking&&(this.restartAudio(),this.loadingState=!1,this.seeking=!1),this.drawingState){this.canvas.toBlob((e=>{this._onSnapshot(e)})),this.drawingState=!1;(function(){const e=document.createElement("a");document.body.appendChild(e),e.style.display="none"})()}(new Date).getTime();var t=new Uint8Array(e.d);return this.renderVideoFrame(t),!0},M.prototype.renderVideoFrame=function(e){this.webglPlayer.renderFrame(e,this.videoWidth,this.videoHeight,this.yLength,this.uvLength)},M.prototype.onFileData=function(e){var t;t={t:y.a.kFeedDataReq,d:e},this.decodeWorker.postMessage(t,[t.d])},M.prototype.onsocketActiveClose=function(e,t){let o="连接失败";this.serverDataTimeout&&(this.serverDataTimeout=!1),this.decoderErrorFlag?(this.event.emit("CLIENT_LINK_ERROR_ONE"),o=(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+"数据接收超时!(0x"+this.serverDeviceUnLinkCode.toString(16)+")",this.decoderErrorFlag=!1):this.socketNoActive?(this.event.emit("CLIENT_LINK_ERROR_THREE"),o=(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+"视频加载失败,请检查设备或网络配置!",this.socketNoActive=!1):1005==e||1e3==e||t?this.decoderErrorFlag&&(this.event.emit("CLIENT_LINK_ERROR_ONE"),o=(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+"链接异常(0x"+this.serverDeviceUnLinkCode.toString(16)+")",this.decoderErrorFlag=!1):this.serverDeviceUnLinkCode?(o=(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+"链接异常(0x"+this.serverDeviceUnLinkCode.toString(16)+")",this.event.emit("CLIENT_LINK_ERROR_ONE")):(o=(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+"链接异常("+e+")",this.event.emit("CLIENT_LINK_ERROR_ONE")),this.stop("linkfail",o)},M.prototype.onsocketTalkActiveClose=function(e){1005===e&&1e3===e||this.talkDestroy()},M.prototype.onsocketNoActive=function(){this.stop(),this.socketNoActive=!0},M.prototype.onInitDecoder=function(e){if(this.playerState!=T)if(this.logger.logInfo("Init decoder response "+e.e+"."),0==e.e){const e={t:y.a.fetchStream,url:this.configInfo.url,msg:"start"};this.downloadWorker.postMessage(e),this.socketSending=!0,this.showLoading()}else this.reportPlayError(e.e)},M.prototype.onSendDataCallback=function(){const e={t:y.a.kOpenDecoderReq};this.decodeWorker.postMessage(e)},M.prototype.onOpenDecoder=function(e){this.startDecoding()},M.prototype.startDecoding=function(){var e={t:y.a.kStartDecodingReq,i:5};this.decodeWorker.postMessage(e),this.decoding=!0},M.prototype.onGetParam=function(e){if(this.playerState!=T&&this.playerState!=_)if(0==e.e){if(!this.playFirstGetParams&&("video"==e.type&&(this.frameRate!=e.v.d||this.pixFmt!=e.v.p||this.videoWidth!=e.v.w||this.videoHeight!=e.v.h)||"audio"==e.type&&(this.audioChannels!=e.a.c||this.audioSampleRate!=e.a.r||this.sampleFmt!=e.a.f)))return this.resetPlayer(),void setTimeout((()=>{this.reconnection()}),1e3);"audio"==e.type?this.onAudioParam(e.a):this.onVideoParam(e.v),this.decoding=!0,this.buffering=!1,this.loadingState=!1,this.hideAll(),this.event.emit("MEDIA_INFO",e)}else this.reportPlayError(e.e)},M.prototype.onVideoParam=function(e){if(this.playerState==T)return;this.logger.logInfo("Video param duation:"+e.d+" pixFmt:"+e.p+" width:"+e.w+" height:"+e.h+"."),this.frameRate=e.d,this.pixFmt=e.p,this.canvas.width=e.w,this.canvas.height=e.h;let t=Math.ceil(1e5*parseInt(getComputedStyle(this.el).width)/e.w)/1e5,o=Math.ceil(1e5*parseInt(getComputedStyle(this.el).height)/e.h)/1e5;this.canvas.style.cssText=`transform: scale(${t},${o});transform-origin: 0 0;position:absolute;left: 0;top: 0;`,this.videoWidth=e.w,this.videoHeight=e.h,this.yLength=this.videoWidth*this.videoHeight,this.uvLength=this.videoWidth/2*(this.videoHeight/2)},M.prototype.onAudioParam=function(e){if(this.playerState!=T&&(this.logger.logInfo("Audio param sampleFmt:"+e.f+" channels:"+e.c+" sampleRate:"+e.r+"."),0!=e.r&&0!=e.c)){var t=e.f;this.sampleFmt=e.f;var o=e.c,a=e.r,s="16bitInt";switch(t){case 0:s="8bitInt";break;case 1:s="16bitInt";break;case 2:s="32bitInt";break;case 3:s="32bitFloat";break;default:this.logger.logError("Unsupported audio sampleFmt "+t+"!")}this.logger.logInfo("Audio encoding "+s+"."),this.playInitState&&(this.pcmPlayer=new r({encoding:s,channels:o,sampleRate:a,flushingTime:100}),this.audioEncoding=s,this.audioChannels=o,this.audioSampleRate=a,this.playInitState=!1,this.volume(0))}},M.prototype.onAudioFrame=function(e){this.bufferFrame(e)},M.prototype.onVideoFrame=function(e){if(this.frameBuffer.filter((e=>4==e.t)).length>5){let e=this.frameBuffer.filter((e=>5==e.t));this.frameBuffer=e}this.bufferFrame(e)},M.prototype.bufferFrame=function(e){this.frameBuffer.push(e),this.getBufferTimerLength()>=500&&this.buffering&&(this.buffering=!1,this.loadingState=!1)},M.prototype.onSocketLinkState=function(e){var t;switch(this.logger.logInfo("Open socket response "+e.s+"."),e.s){case 1:t={t:y.a.getHeartBeatRequest},this.decodeWorker.postMessage(t);break;case 2:case 3:this.stop()}},M.prototype.onGetHeartBeatRequest=function(e){const t={t:y.a.DownloaderHeartBeat,b:e.b,l:e.l};this.downloadWorker.postMessage(t),this.talkWorker.postMessage(t)},M.prototype.onGetHandshakeReq=function(e){const t={t:y.a.DownloaderHandshakeReq,b:e.b,l:e.l},o={t:y.a.TalkHandshakeReq,b:e.b,l:e.l};this.downloadWorker.postMessage(t),this.talkWorker.postMessage(o),this.setSpeed("1")},M.prototype.onGetSetPlayBackSpeedReq=function(e){const t={t:y.a.getSetPlayBackSpeedReq,b:e.b};this.downloadWorker.postMessage(t)},M.prototype.onGetSetPlayBackStartReq=function(e){const t={t:y.a.getSetPlayBackStartReq,b:e.b};this.downloadWorker.postMessage(t)},M.prototype.onDeviceReady=function(){const e={t:y.a.getSetPlayBackStartReq};this.decodeWorker.postMessage(e)},M.prototype.onGetSetPlayBackStartTimeReq=function(e){this.startDecoding();const t={t:y.a.getSetPlayBackStartTimeReq,b:e.b};this.downloadWorker.postMessage(t)},M.prototype.onResponseCurDateTime=function(e){String(e.d).replace("n","");this.currentTimestamp=e.d;const t=new Date(this.endtime).getTime();parseInt(e.d)>=t&&this.event.emit("MEDIA_PROGRESS_INFO_STOP",parseInt(e.d)),this.event.emit("MEDIA_PROGRESS_INFO",parseInt(e.d))},M.prototype.onEventTypeFifoFull=function(e){this.playerState==E&&(this.setSpeed("0"),this.event.emit("speedNum",0))},M.prototype.onEventTypeFifoEnough=function(e){this.playerState==E&&(this._curSpeed?(this.setSpeed(this._curSpeed),this.event.emit("speedNum",this._curSpeed)):(this.setSpeed("1"),this.event.emit("speedNum",1)))},M.prototype.onServerDataTimeout=function(e){this.serverDataTimeout=!0,this.stop()},M.prototype.onGetHandsharkRes=function(e){const t=window.btoa(String.fromCharCode(...e.b)),o={t:y.a.fetchStream,url:this.configInfo.url+"&public_key="+t,msg:"start"};this.downloadWorker.postMessage(o),this.socketSending=!0,this.showLoading()},M.prototype.onCloseDecoderRsp=function(){this.event.emit("MEDIA_STOP"),this.decodeWorker.terminate(),this.downloadWorker.terminate(),this.talkWorker.terminate()},M.prototype.onWasmLoaded=function(){this.event.emit("WASMLOADED")},M.prototype.onPlaybakcRecordList=function(e){let t=JSON.parse(e.d);t.rec_file_infos?this.isStream||this.event.emit("DEVICE_RECORD_LIST",t):this.showMsg("linkfail",(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+"数据列表为空!")},M.prototype.onHeartPingResp=function(){const e={t:y.a.heartPingResp};this.downloadWorker.postMessage(e)},M.prototype.onDecoderError=function(e){let t="连接失败(服务)";this.serverDeviceUnLinkCode=e.s,b[e.s]&&b[e.s].eventStr&&(this.event.emit(b[e.s].eventStr,b[e.s]),t=(this.configInfo.deviceName?this.configInfo.deviceName+"":"")+b[e.s].msg+"(0x"+this.serverDeviceUnLinkCode.toString(16)+")",this.stop("linkfail",t)),this.event.emit("decoderError",e),this.decoderErrorFlag=!0},M.prototype.speed=function(e){if(!e)return;this.socketSending="0"!=e;const t={t:y.a.getSetPlayBackSpeedReq,l:e};this.decodeWorker.postMessage(t)},M.prototype.restartAudio=function(){this.pcmPlayer&&(this.pcmPlayer.destroy(),this.pcmPlayer=null),0!=this.audioSampleRate&&0!=this.audioChannels&&(this.pcmPlayer=new r({encoding:this.audioEncoding,channels:this.audioChannels,sampleRate:this.audioSampleRate,flushingTime:1e3}),this.volume(this.currentVolume))},M.prototype.onDecodeFinished=function(e){this.pauseDecoding()},M.prototype.getBufferTimerLength=function(){if(!this.frameBuffer||0==this.frameBuffer.length)return 0;let e=this.frameBuffer[0],t=this.frameBuffer[this.frameBuffer.length-1];return Math.abs(t.s-e.s)},M.prototype.closeWebsocket=function(){const e={t:y.a.closeWebsocket};this.downloadWorker.postMessage(e)},M.prototype.pauseDecoding=function(){var e={t:y.a.kPauseDecodingReq};this.decodeWorker.postMessage(e),this.decoding=!1},M.prototype.formatTime=function(e){return(Math.floor(e/3600)<10?"0"+Math.floor(e/3600):Math.floor(e/3600))+":"+(Math.floor(e/60%60)<10?"0"+Math.floor(e/60%60):Math.floor(e/60%60))+":"+(e=Math.floor(e%60)<10?"0"+Math.floor(e%60):Math.floor(e%60))},M.prototype.reportPlayError=function(e,t,o){},M.prototype.registerVisibilityEvent=function(e){var t="hidden";function o(o){var a=!0,r=!1,s={focus:a,focusin:a,pageshow:a,blur:r,focusout:r,pagehide:r},i=a;i=(o=o||window.event).type in s?s[o.type]:document[t]?r:a,e(i)}t in document?document.addEventListener("visibilitychange",o):(t="mozHidden")in document?document.addEventListener("mozvisibilitychange",o):(t="webkitHidden")in document?document.addEventListener("webkitvisibilitychange",o):(t="msHidden")in document?document.addEventListener("msvisibilitychange",o):"onfocusin"in document?document.onfocusin=document.onfocusout=o:window.onpageshow=window.onpagehide=window.onfocus=window.onblur=o,void 0!==document[t]&&o({type:document[t]?"blur":"focus"})},M.prototype.snapshot=function(){this.drawingState=!0},M.prototype.onVideoDownRep=function(e){let t=e.d.map((e=>e.buffer));const o=document.createElement("a");o.style.display="none";const a=new Blob(t,{type:"video/mp4"}),r=window.URL.createObjectURL(a);o.href=r,o.download="录像"+(new Date).getTime()+".mp4",document.body.appendChild(o),o.click(),o.remove(),e.d=[]},M.prototype.onVideoDownChumksRep=function(e){e.d.length>=25&&(this.recoderPause(),this.event.emit("VIDEO_MAX_END"))},M.prototype.initTalkWorker=function(){var e=this;this.talkWorker=new u,this.talkWorker.onmessage=function(t){var o=t.data;switch(o.t){case y.a.kGetDeviceInfo:e.decodeWorker.postMessage(o);break;case y.a.socketActiveClose:e.onsocketTalkActiveClose(o.d);break;case y.a.getTalkStartReq:const t={t:y.a.getTalkStartReq,b:"",msg:""};e.decodeWorker.postMessage(t);break;case y.a.socketNoActive:e.onsocketNoActive();break;case y.a.DestroyTalkRes:break;case y.a.initTalkEncode:const a={t:y.a.initTalkEncode,b:"",msg:""};e.decodeWorker.postMessage(a)}}},M.prototype.onTalkStartRep=function(e){const t={t:y.a.talkStartRep,b:e.b,msg:"start"};this.talkWorker.postMessage(t)},M.prototype.onStartTalkEncoder=function(e){const t={t:y.a.kStartTalkEncoderRsp,b:e.b};this.decodeWorker.postMessage(t)},M.prototype.talk=function(e){const t={t:y.a.fetchStream,url:e};this.talkWorker.postMessage(t)},M.prototype.onGetAudioDataReq=function(){this.getAudioDataStatus=!0,this.startRecord()},M.prototype.onGetAudioDataRep=function(e){this.talkWorker.postMessage(e)},M.prototype.onkTalkEncoderdeviceready=function(){const e={t:y.a._getTalkStartReq,b:"",msg:""};this.decodeWorker.postMessage(e)},M.prototype.onPlaybackOver=function(){this.event.emit("PLAYBACKOVER")},M.prototype.onDecoderTalkError=function(e){b[e.s]&&b[e.s].eventStr&&this.event.emit(b[e.s].eventStr,b[e.s],"talk"),this.event.emit("CLIENT_TALK_ERROR_ONE",e),this.talkDestroy()};M.prototype.startRecord=function(){this.getAudioDating=!0,this.talkRecord||navigator.mediaDevices.getUserMedia({audio:{sampleRate:48e3,sampleSize:16,channelCount:1,volume:1,noiseSuppression:!0,echoCancellation:!0}}).then((e=>{this.talkStream=e,this.talkRecord=new S(this.talkStream),this.talkRecord.start(),this.talkTimer=setInterval((async()=>{if(this.getAudioDating&&this.talkRecord){let t=this.talkRecord.getBlob();this.talkRecord.clear();let o=await(e=t,new Promise(((t,o)=>{let a=new FileReader;a.readAsArrayBuffer(e),a.onload=function(e){a.result.slice(0,24e3),t({d:a.result,t:(new Date).getTime(),h:a.result.byteLength})}})));const a={t:y.a.pcmDataReq,p:o};this.decodeWorker.postMessage(a)}var e}),50)})).catch((e=>{this.event.emit("getUserMediaError")}))},M.prototype.talkPause=function(){this.talkRecord&&(clearInterval(this.talkTimer),this.talkRecord.stop(),this.talkRecord.clear(),this.talkRecord=null,this.talkStream.getTracks().forEach((e=>e.stop())),this.getAudioDating=!1)},M.prototype.onCloseTalk=function(e){this.event.emit("CLIENT_TALK_ERROR_ONE",e),this.talkDestroy()},M.prototype.talkDestroy=function(){this.talkRecord&&(clearInterval(this.talkTimer),this.talkRecord.stop(),this.talkRecord.clear(),this.talkRecord=null,this.talkStream.getTracks().forEach((e=>e.stop())),this.getAudioDating=!1);const e={t:y.a.DestroyTalkReq};this.talkWorker.postMessage(e),this.decodeWorker.postMessage(e)};t.default=M}])}));