!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("AgoraSDK",[],t):"object"==typeof exports?exports.AgoraSDK=t():e.AgoraSDK=t()}(window,(function(){return function(e){var t={};function i(n){if(t[n])return t[n].exports;var r=t[n]={i:n,l:!1,exports:{}};return e[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)i.d(n,r,function(t){return e[t]}.bind(null,r));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=54)}([function(e,t,i){"use strict";var n=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{u(n.next(e))}catch(e){s(e)}}function o(e){try{u(n.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}u((n=n.apply(e,t||[])).next())}))},r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=r(i(36)),a=i(5),o=r(i(1)),u=i(6),l=i(4),h=()=>{};class c extends s.default{constructor(e,t){super(),this._state=g.RELAY_STATE_IDLE,this._onStatus=e=>{o.default.debug(`[${this.clientId}] ChannelMediaStatus: ${JSON.stringify(e)}`),e&&e.command&&("onAudioPacketReceived"===e.command&&this.emit("event",v.PACKET_RECEIVED_AUDIO_FROM_SRC),"onVideoPacketReceived"===e.command&&this.emit("event",v.PACKET_RECEIVED_VIDEO_FROM_SRC),"onSrcTokenPrivilegeDidExpire"===e.command&&(this._state=g.RELAY_STATE_FAILURE,this.emit("state",g.RELAY_STATE_FAILURE,T.SRC_TOKEN_EXPIRED)),"onDestTokenPrivilegeDidExpire"===e.command&&(this._state=g.RELAY_STATE_FAILURE,this.emit("state",g.RELAY_STATE_FAILURE,T.DEST_TOKEN_EXPIRED,e.channelName?{came:e.channelName}:null)))},this._onClose=()=>n(this,void 0,void 0,(function*(){if(o.default.debug(`[${this.clientId}] ChannelMediaSocket onClose`),this.emit("event",v.NETWORK_DISCONNECTED),this.state=g.RELAY_STATE_IDLE,this._prevChannelMediaConfig)try{yield this.startChannelMediaRelay(this._prevChannelMediaConfig)}catch(e){if(e instanceof p&&(e.message===f.WS_ABORT||e.message===f.AP_REQUEST_ABORT))return;this.emit("state",g.RELAY_STATE_FAILURE,T.SERVER_CONNECTION_LOST)}})),this.token=e.appId,this.appId=e.appId,this.cname=e.cname,this.uid=e.uid,this.sid=e.sid,this.clientId=t}set state(e){const t=this._state;this._state=e,t!==e&&this.emit("state",e)}get state(){return this._state}startChannelMediaRelay(e){return n(this,void 0,void 0,(function*(){if(this.state!==g.RELAY_STATE_IDLE)throw new p(f.BAD_STATE);this.state=g.RELAY_STATE_CONNECTING,yield this._connect(),o.default.debug(`[${this.clientId}] startChannelMediaRelay: connect success`),yield this._sendStartRelayMessage(e),this._prevChannelMediaConfig=e}))}updateChannelMediaRelay(e){return n(this,void 0,void 0,(function*(){if(this.state!==g.RELAY_STATE_RUNNING)throw new p(f.BAD_STATE);yield this._sendUpdateMessage(e),this._prevChannelMediaConfig=e}))}stopChannelMediaRelay(){return n(this,void 0,void 0,(function*(){yield this._sendStopRelayMessage(),o.default.debug(`[${this.clientId}] stopChannelMediaRelay: send stop message success`),this.state=g.RELAY_STATE_IDLE,this.dispose()}))}dispose(){o.default.debug(`[${this.clientId}] disposeChannelMediaRelay`),this.state=g.RELAY_STATE_IDLE,this.emit("dispose"),this._signal&&this._signal.dispose(),this._prevChannelMediaConfig=null,this.removeEvent()}_requestOneAP(e){return new Promise((t,i)=>{const n={command:"convergeAllocateEdge",sid:this.sid,appId:this.appId,token:"",ts:+new Date,version:a.VERSION,cname:this.cname,uid:this.uid+"",seq:1,requestId:1},r={service_name:"tele_channel",json_body:JSON.stringify(n)},s="https://"+e;wx.request({url:s,data:r,header:{"content-type":"application/json","X-Packet-Service-Type":0,"X-Packet-URI":61},method:"POST",success:e=>{let n=null,r=null;try{n=e.data}catch(e){i(new p(f.AP_JSON_PARSE_ERROR,e))}0!==n.code&&i(new p(f.AP_REQUEST_ERROR,n));try{r=JSON.parse(n.json_body)}catch(e){i(new p(f.AP_JSON_PARSE_ERROR,e))}200!==r.code&&i(new p(f.AP_REQUEST_ERROR,r)),r.servers?t(r.servers):i(new p(f.AP_JSON_PARSE_ERROR,r))},fail:e=>i(e)})})}_requestAP(){const e=["uap-ap-web-1.agora.io","uap-ap-web-2.agoraio.cn","uap-ap-web-3.agora.io","uap-ap-web-4.agoraio.cn"];return new Promise((t,i)=>{setTimeout(()=>{i(new p(f.AP_REQUEST_TIMEOUT))},3e3),this.on("dispose",()=>{i(new p(f.AP_REQUEST_ABORT))}),e.forEach(e=>{e+="/api/v1",this._requestOneAP(e).then(i=>{o.default.debug(`[${this.clientId}] startChannelMediaRelay request AP ${e} success: ${JSON.stringify(i)}`);const n=i[0];let r=(e=n.address).split("."),s=r.length;const a=`wss://miniapp.agoraio.cn/${r[s-4]}-${r[s-3]}-${r[s-2]}-${r[s-1]}-${n.ws}/`;t(a)}).catch(t=>{o.default.debug(`[${this.clientId}] startChannelMediaRelay request AP ${e} failed: ${JSON.stringify(t)}`)})})})}_connectWebsocket(e){return this._signal=new d(this.appId,this.cname,this.uid,this.sid),this._signal.connect(e)}_connect(){return n(this,void 0,void 0,(function*(){const e=yield this._requestAP();yield this._connectWebsocket(e),this._signal.on("close",this._onClose.bind(this)),this._signal.on("status",this._onStatus.bind(this)),this.emit("event",v.NETWORK_CONNECTED)}))}_sendStartRelayMessage(e){return n(this,void 0,void 0,(function*(){this._checkSignal();const t=this._genMessage(y.StopPacketTransfer);yield Promise.all([this._signal.request(t),this._signal.waitStatus("Normal Quit")]),o.default.debug(`[${this.clientId}] startChannelMediaRelay: StopPacketTransfer success`);const i=this._genMessage(y.SetSdkProfile,e);yield this._signal.request(i),o.default.debug(`[${this.clientId}] startChannelMediaRelay: SetSdkProfile success`);const n=this._genMessage(y.SetSourceChannel,e);yield Promise.all([this._signal.request(n),this._signal.waitStatus("SetSourceChannelStatus")]),this.emit("event",v.PACKET_JOINED_SRC_CHANNEL),o.default.debug(`[${this.clientId}] startChannelMediaRelay: SetSourceChannel success`);const r=this._genMessage(y.SetSourceUserId,e);yield this._signal.request(r),o.default.debug(`[${this.clientId}] startChannelMediaRelay: SetSourceUserId success`);const s=this._genMessage(y.SetDestChannel,e);yield Promise.all([this._signal.request(s),this._signal.waitStatus("SetDestChannelStatus")]),this.emit("event",v.PACKET_JOINED_DEST_CHANNEL),o.default.debug(`[${this.clientId}] startChannelMediaRelay: SetDestChannel success`);const a=this._genMessage(y.StartPacketTransfer,e);yield this._signal.request(a),this.emit("event",v.PACKET_SENT_TO_DEST_CHANNEL),this.state=g.RELAY_STATE_RUNNING,o.default.debug(`[${this.clientId}] startChannelMediaRelay: StartPacketTransfer success`)}))}_sendReconnectMessage(e){return n(this,void 0,void 0,(function*(){this._checkSignal();const t=this._genMessage(y.Reconnect,e);yield this._signal.request(t)}))}_sendUpdateMessage(e){return n(this,void 0,void 0,(function*(){this._checkSignal();const t=this._genMessage(y.UpdateDestChannel,e);yield this._signal.request(t),this.emit("event",v.PACKET_UPDATE_DEST_CHANNEL),o.default.debug(`[${this.clientId}] sendUpdateMessage: UpdateDestChannel success`)}))}_sendStopRelayMessage(){return n(this,void 0,void 0,(function*(){this._checkSignal();const e=this._genMessage(y.StopPacketTransfer);yield this._signal.request(e),o.default.debug(`[${this.clientId}] sendStopRelayMessage: StopPacketTransfer success`)}))}_genMessage(e,t){const i=[],n=[],r=[],s={appId:this.appId,cname:this.cname,uid:this.uid+"",sdkVersion:a.VERSION,sid:this.sid,ts:+new Date,requestId:0,seq:0,allocate:!0,clientRequest:{}};let o=null,u=null;switch(e){case y.SetSdkProfile:return s.clientRequest={command:"SetSdkProfile",type:"multi_channel"},s;case y.SetSourceChannel:return u=t.getSrcChannelMediaInfo(),s.clientRequest={command:"SetSourceChannel",uid:u.uid+"",channelName:u.channelName,token:u.token||this.appId},s;case y.SetSourceUserId:return u=t.getSrcChannelMediaInfo(),s.clientRequest={command:"SetSourceUserId",uid:this.uid+""},s;case y.SetDestChannel:return o=t.getDestChannelMediaInfos(),o.forEach(e=>{i.push(e.channelName),n.push(e.uid+""),r.push(e.token||this.appId)}),s.clientRequest={command:"SetDestChannel",channelName:i,uid:n,token:r},s;case y.StartPacketTransfer:return s.clientRequest={command:"StartPacketTransfer"},s;case y.Reconnect:return s.clientRequest={command:"Reconnect"},s;case y.StopPacketTransfer:return s.clientRequest={command:"StopPacketTransfer"},s;case y.UpdateDestChannel:return o=t.getDestChannelMediaInfos(),o.forEach(e=>{i.push(e.channelName),n.push(e.uid+""),r.push(e.token||this.appId)}),s.clientRequest={command:"UpdateDestChannel",channelName:i,uid:n,token:r},s}}_checkSignal(){if(!this._signal||!this._signal.isConnect())throw new p(f.WS_DISCONNECTED)}}t.default=c;t.ChannelMediaRelayConfiguration=class{constructor(){this.destChannelMediaInfos=new Map}setSrcChannelInfo(e){u.checkValidObject(e,"srcInfo");const{uid:t,channelName:i,token:n}=e;if(n&&!u.isValidToken(n))throw new Error("Invalid token in SrcChannelInfo");if(!u.isValidChannelName(i))throw new Error("Invalid channelName in SrcChannelInfo");if(!l.is32Uint(t))throw new Error("Invalid uid in SrcChannelInfo");o.default.debug("[setSrcChannelInfo]: srcInfo: ",e),this.srcChannelMediaInfo=e}setDestChannelInfo(e,t){if(!u.isValidChannelName(e))throw new Error("Invalid channelName in DestChannelInfo");u.checkValidObject(t,"destInfo");const{uid:i,token:n}=t,r=t.channelName;if(n&&!u.isValidToken(n))throw new Error("Invalid token in DestChannelInfo");if(!u.isValidChannelName(r))throw new Error("Invalid channelName in DestChannelInfo");if(!l.is32Uint(i))throw new Error("Invalid uid in DestChannelInfo");o.default.debug("[setDestChannelInfo]: destInfo: ",t,"channelName: ",e),this.destChannelMediaInfos.set(e,t)}removeDestChannelInfo(e){if(!u.isValidChannelName(e))throw new Error("Invalid channelName when invoke removeDestChannelInfo");o.default.debug("[removeDestChannelInfo]: channelName: ",e),this.destChannelMediaInfos.delete(e)}getSrcChannelMediaInfo(){return this.srcChannelMediaInfo}getDestChannelMediaInfos(){return this.destChannelMediaInfos}};class d extends s.default{constructor(e,t,i,n){super(),this._onOpen=()=>{o.default.debug("[ChannelMediaRelay] onOpen"),this.emit("open")},this._onClose=e=>{o.default.debug("[ChannelMediaRelay] onClose"),this.emit("close"),this.dispose()},this._onMessage=e=>{o.default.blind("ChannelMediaRelay receive message",e);const t=JSON.parse(e.data);if(!t||"serverResponse"!==t.command||!t.requestId)return t&&"serverStatus"===t.command&&t.serverStatus&&t.serverStatus.command?(this.emit("status",t.serverStatus),void this.emit(t.serverStatus.command,t.serverStatus)):void 0;this.emit("req_"+t.requestId,t)},this._requestId=1,this.appId=e,this.cname=t,this.uid=i,this.sid=n}isConnect(){return this._ws&&1===this._ws.readyState}sendMessage(e){if(!this._ws||1!==this._ws.readyState)throw new p(f.WS_DISCONNECTED);const t=this._requestId++;return e.requestId=t,e.seq=t,this._ws.send({data:JSON.stringify(e)}),t}waitStatus(e){return new Promise((t,i)=>{const n=setTimeout(()=>{i(new p(f.WAIT_STATUS_TIMEOUT,e))},5e3);this.once(e,r=>{clearTimeout(n),r.state&&0!==r.state?i(new p(f.WAIT_STATUS_ERROR,e)):t()}),this.once("dispose",()=>{clearTimeout(n),i(new p(f.WS_ABORT))})})}request(e){return new Promise((t,i)=>{const n=this.sendMessage(e),r=setTimeout(()=>{this.removeAllListeners("req_"+n),i(new p(f.REQUEST_TIMEOUT))},3e3);this.once("req_"+n,e=>{clearTimeout(r),e&&200===e.code?t(e):i(new p(f.REQUEST_FAILED,e))}),this.once("dispose",()=>{clearTimeout(r),i(new p(f.WS_ABORT))})})}connect(e){return new Promise((t,i)=>{this._ws=wx.connectSocket({url:e}),this._ws.onOpen((i,n)=>{o.default.debug("[ChannelMediaRelay] ws.onOpen"),this._onOpen(),this._prvUrl=e,this._ws.onMessage(this._onMessage),this._ws.onClose(this._onClose),this._startHeartBeatCheck(),t()}),this._ws.onClose(e=>{o.default.debug("[ChannelMediaRelay] ws.onClose",e),this.dispose(),i(new p(f.CONNECT_FAILED,"websocket error code: "+e.code))}),setTimeout(()=>{this._ws&&1!==this._ws.readyState&&(this._ws.onMessage(h),this._ws.onClose(h),this._ws.close(),this._ws=null,i(new p(f.CONNECT_TIMEOUT)))},5e3),this.once("dispose",()=>{i(new p(f.WS_ABORT))})})}dispose(){o.default.debug("[ChannelMediaRelay] dispose"),this._clearHeartBeatCheck(),this.emit("dispose"),this.removeEvent(),this._ws&&(this._ws.onOpen(h),this._ws.onClose(h),this._ws.onMessage(h),this._ws.close(h)),this._ws=null}_sendPing(e){if(!this._ws||1!==this._ws.readyState)throw new p(f.WS_DISCONNECTED);const t=this._requestId++;return e.requestId=t,this._ws.send({data:JSON.stringify(e)}),t}_startHeartBeatCheck(){this._heartBeatTimer=setInterval(()=>{this._sendPing({command:"ping",appId:this.appId,cname:this.cname,uid:this.uid+"",sid:this.sid,ts:+new Date,requestId:0})},3e3)}_clearHeartBeatCheck(){clearInterval(this._heartBeatTimer)}}class p{constructor(e="",t,i){this.code=i,this.data=t,this.message=e}}var f,y,v,g,T;t.ChannelMediaError=p,function(e){e.CONNECT_FAILED="connect failed",e.CONNECT_TIMEOUT="connect timeout",e.WS_DISCONNECTED="websocket disconnected",e.REQUEST_TIMEOUT="request timeout",e.REQUEST_FAILED="request failed",e.WAIT_STATUS_TIMEOUT="wait status timeout",e.WAIT_STATUS_ERROR="wait status error",e.BAD_STATE="bad state",e.WS_ABORT="ws abort",e.AP_REQUEST_TIMEOUT="AP request timeout",e.AP_JSON_PARSE_ERROR="AP json parse error",e.AP_REQUEST_ERROR="AP request error",e.AP_REQUEST_ABORT="AP request abort"}(f=t.CHANNEL_MEDIA_ERROR||(t.CHANNEL_MEDIA_ERROR={})),function(e){e[e.SetSdkProfile=0]="SetSdkProfile",e[e.SetSourceChannel=1]="SetSourceChannel",e[e.SetSourceUserId=2]="SetSourceUserId",e[e.SetDestChannel=3]="SetDestChannel",e[e.StartPacketTransfer=4]="StartPacketTransfer",e[e.StopPacketTransfer=5]="StopPacketTransfer",e[e.UpdateDestChannel=6]="UpdateDestChannel",e[e.Reconnect=7]="Reconnect",e[e.SetVideoProfile=8]="SetVideoProfile"}(y||(y={})),function(e){e[e.NETWORK_DISCONNECTED=0]="NETWORK_DISCONNECTED",e[e.NETWORK_CONNECTED=1]="NETWORK_CONNECTED",e[e.PACKET_JOINED_SRC_CHANNEL=2]="PACKET_JOINED_SRC_CHANNEL",e[e.PACKET_JOINED_DEST_CHANNEL=3]="PACKET_JOINED_DEST_CHANNEL",e[e.PACKET_SENT_TO_DEST_CHANNEL=4]="PACKET_SENT_TO_DEST_CHANNEL",e[e.PACKET_RECEIVED_VIDEO_FROM_SRC=5]="PACKET_RECEIVED_VIDEO_FROM_SRC",e[e.PACKET_RECEIVED_AUDIO_FROM_SRC=6]="PACKET_RECEIVED_AUDIO_FROM_SRC",e[e.PACKET_UPDATE_DEST_CHANNEL=7]="PACKET_UPDATE_DEST_CHANNEL",e[e.PACKET_UPDATE_DEST_CHANNEL_REFUSED=8]="PACKET_UPDATE_DEST_CHANNEL_REFUSED",e[e.PACKET_UPDATE_DEST_CHANNEL_NOT_CHANGE=9]="PACKET_UPDATE_DEST_CHANNEL_NOT_CHANGE"}(v=t.CHANNEL_MEDIA_RELAY_EVENT||(t.CHANNEL_MEDIA_RELAY_EVENT={})),function(e){e[e.RELAY_STATE_IDLE=0]="RELAY_STATE_IDLE",e[e.RELAY_STATE_CONNECTING=1]="RELAY_STATE_CONNECTING",e[e.RELAY_STATE_RUNNING=2]="RELAY_STATE_RUNNING",e[e.RELAY_STATE_FAILURE=3]="RELAY_STATE_FAILURE"}(g=t.CHANNEL_MEDIA_RELAY_STATE||(t.CHANNEL_MEDIA_RELAY_STATE={})),function(e){e[e.RELAY_OK=0]="RELAY_OK",e[e.SERVER_ERROR_RESPONSE=1]="SERVER_ERROR_RESPONSE",e[e.SERVER_NO_RESPONSE=2]="SERVER_NO_RESPONSE",e[e.NO_RESOURCE_AVAILABLE=3]="NO_RESOURCE_AVAILABLE",e[e.FAILED_JOIN_SRC=4]="FAILED_JOIN_SRC",e[e.FAILED_JOIN_DEST=5]="FAILED_JOIN_DEST",e[e.FAILED_PACKET_RECEIVED_FROM_SRC=6]="FAILED_PACKET_RECEIVED_FROM_SRC",e[e.FAILED_PACKET_SENT_TO_DEST=7]="FAILED_PACKET_SENT_TO_DEST",e[e.SERVER_CONNECTION_LOST=8]="SERVER_CONNECTION_LOST",e[e.INTERNAL_ERROR=9]="INTERNAL_ERROR",e[e.SRC_TOKEN_EXPIRED=10]="SRC_TOKEN_EXPIRED",e[e.DEST_TOKEN_EXPIRED=11]="DEST_TOKEN_EXPIRED",e[e.RELAY_ALREADY_START=12]="RELAY_ALREADY_START",e[e.RELAY_NOT_START=13]="RELAY_NOT_START",e[e.OPERATION_ABORT=14]="OPERATION_ABORT"}(T=t.CHANNEL_MEDIA_RELAY_ERROR||(t.CHANNEL_MEDIA_RELAY_ERROR={}))},function(e,t,i){"use strict";i.r(t),i.d(t,"Log",(function(){return l}));var n=i(10),r=i.n(n),s=i(2),a=i.n(s),o=i(3),u=i.n(o),l=function(){function e(){a()(this,e),this.level=3,this.onLog=null}return u()(e,[{key:"setLogLevel",value:function(e){if("number"!=typeof e||!(e<=4&&e>=-1))throw Error("Invaild level");this.level=e}},{key:"log",value:function(){var e,t=Array.prototype.slice.call(arguments);this.onLog&&this.onLog(JSON.stringify(t)),(e=console).log.apply(e,r()(t))}},{key:"err",value:function(){var e,t=Array.prototype.slice.call(arguments);this.onLog&&this.onLog(JSON.stringify(t)),(e=console).error.apply(e,r()(t))}},{key:"blind",value:function(){var e=Array.prototype.slice.call(arguments);this.level<=-1&&this.log.apply(this,["".concat(new Date," [BLIND]: ")].concat(r()(e)))}},{key:"debug",value:function(){var e=Array.prototype.slice.call(arguments);this.level<=0&&this.log.apply(this,["".concat(new Date," [DEBUG]: ")].concat(r()(e)))}},{key:"info",value:function(e){this.level<=1&&this.log("".concat(new Date," [INFO]: ").concat(e))}},{key:"warn",value:function(e){this.level<=2&&this.log("".concat(new Date," [WARN]: ").concat(e))}},{key:"error",value:function(e){this.level<=3&&this.err("".concat(new Date," [ERROR]: ").concat(e))}}]),e}(),h=new l;t.default=h},function(e,t){e.exports=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}},function(e,t){function i(e,t){for(var i=0;i=t&&e.length<=i},d=function(e,t,i){return T(e)&&e>=t&&e<=i},p=function(e,t,i){return _(e)&&e>=t&&e<=i},f=function(e){return"boolean"==typeof e},y=function(e){return c(e,1,2047)},v=function(e){return S(e)&&/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/.test(e)},g=function(e){if("string"==typeof e){for(var t=0;t255)return!1}return!0}},T=function(e){return"number"==typeof e&&e%1==0},_=function(e){return"number"==typeof e},S=function(e){return"string"==typeof e},m=function(e){return e instanceof Array},E=function(e){return null==e}},function(e,t,i){"use strict";(function(e){var n=t;function r(e,t,i){for(var n=Object.keys(t),r=0;r0)},n.Buffer=function(){try{var e=n.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),n._Buffer_from=null,n._Buffer_allocUnsafe=null,n.newBuffer=function(e){return"number"==typeof e?n.Buffer?n._Buffer_allocUnsafe(e):new n.Array(e):n.Buffer?n._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},n.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,n.Long=n.global.dcodeIO&&n.global.dcodeIO.Long||n.global.Long||n.inquire("long"),n.key2Re=/^true|false|0|1$/,n.key32Re=/^-?(?:0|[1-9][0-9]*)$/,n.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,n.longToHash=function(e){return e?n.LongBits.from(e).toHash():n.LongBits.zeroHash},n.longFromHash=function(e,t){var i=n.LongBits.fromHash(e);return n.Long?n.Long.fromBits(i.lo,i.hi,t):i.toNumber(Boolean(t))},n.merge=r,n.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},n.newError=s,n.ProtocolError=s("ProtocolError"),n.oneOfGetter=function(e){for(var t={},i=0;i-1;--i)if(1===t[e[i]]&&void 0!==this[e[i]]&&null!==this[e[i]])return e[i]}},n.oneOfSetter=function(e){return function(t){for(var i=0;i0&&(this.send_pending.forEach((function(t){var i;this.socket.send(t.buf),this.callbacks.push((i=t.cb,function(t){e.setRecvBuffer(t),i()}))})),this.send_pending=[])},__onClose:function(e){this.__reset(this.url)},__onMessage:function(e){this.callbacks.length&&this.callbacks.shift()(e.data)},__onError:function(e){console.log("Thrift WebSocket Error: "+e.toString()),this.socket.close()},setRecvBuffer:function(e){this.recv_buf=e,this.recv_buf_sz=this.recv_buf.length,this.wpos=this.recv_buf.length,this.rpos=0},isOpen:function(){return this.socket&&this.socket.readyState==this.socket.OPEN},open:function(){this.socket&&this.socket.readyState!=this.socket.CLOSED||(this.socket=new WebSocket(this.url),this.socket.onopen=this.__onOpen.bind(this),this.socket.onmessage=this.__onMessage.bind(this),this.socket.onerror=this.__onError.bind(this),this.socket.onclose=this.__onClose.bind(this))},close:function(){this.socket.close()},read:function(e){var t=this.wpos-this.rpos;if(0===t)return"";var i=e;te+1;){var r=this.tstack.pop(),s=this.tstack.pop();n?n=!1:i=","+i,isNaN(s)||(s='"'+s+'"'),i=s+":"+r+i}i="{"+i,this.tstack[e].push(i),this.tstack[e]="["+this.tstack[e].join(",")+"]"}},writeListBegin:function(e,t){this.tpos.push(this.tstack.length),this.tstack.push([Thrift.Protocol.Type[e],t])},writeListEnd:function(){for(var e=this.tpos.pop();this.tstack.length>e+1;){var t=this.tstack[e+1];this.tstack.splice(e+1,1),this.tstack[e].push(t)}this.tstack[e]="["+this.tstack[e].join(",")+"]"},writeSetBegin:function(e,t){this.tpos.push(this.tstack.length),this.tstack.push([Thrift.Protocol.Type[e],t])},writeSetEnd:function(){for(var e=this.tpos.pop();this.tstack.length>e+1;){var t=this.tstack[e+1];this.tstack.splice(e+1,1),this.tstack[e].push(t)}this.tstack[e]="["+this.tstack[e].join(",")+"]"},writeBool:function(e){this.tstack.push(e?1:0)},writeByte:function(e){this.tstack.push(e)},writeI16:function(e){this.tstack.push(e)},writeI32:function(e){this.tstack.push(e)},writeI64:function(e){this.tstack.push(e)},writeDouble:function(e){this.tstack.push(e)},writeString:function(e){if(null===e)this.tstack.push(null);else{for(var t="",i=0;ie;)this.rstack.pop()},readMapBegin:function(){var e=this.rstack.pop(),t=e.shift();t instanceof Array&&(this.rstack.push(e),t=(e=t).shift());var i={};return i.ktype=Thrift.Protocol.RType[t],i.vtype=Thrift.Protocol.RType[e.shift()],i.size=e.shift(),this.rpos.push(this.rstack.length),this.rstack.push(e.shift()),i},readMapEnd:function(){this.readFieldEnd()},readListBegin:function(){var e=this.rstack[this.rstack.length-1],t={};return t.etype=Thrift.Protocol.RType[e.shift()],t.size=e.shift(),this.rpos.push(this.rstack.length),this.rstack.push(e.shift()),t},readListEnd:function(){this.readFieldEnd()},readSetBegin:function(e,t){return this.readListBegin(e,t)},readSetEnd:function(){return this.readListEnd()},readBool:function(){var e=this.readI32();return null!==e&&"1"==e.value?e.value=!0:e.value=!1,e},readByte:function(){return this.readI32()},readI16:function(){return this.readI32()},readI32:function(e){void 0===e&&(e=this.rstack[this.rstack.length-1]);var t={};if(e instanceof Array)0===e.length?t.value=void 0:t.value=e.shift();else if(e instanceof Object){for(var i in e)if(null!==i){this.rstack.push(e[i]),delete e[i],t.value=i;break}}else t.value=e,this.rstack.pop();return t},readI64:function(){return this.readI32()},readDouble:function(){return this.readI32()},readString:function(){return this.readI32()},readBinary:function(){var e=this.readI32();return e.value=atob(e.value),e},skip:function(e){var t,i;switch(e){case Thrift.Type.STOP:return null;case Thrift.Type.BOOL:return this.readBool();case Thrift.Type.BYTE:return this.readByte();case Thrift.Type.I16:return this.readI16();case Thrift.Type.I32:return this.readI32();case Thrift.Type.I64:return this.readI64();case Thrift.Type.DOUBLE:return this.readDouble();case Thrift.Type.STRING:return this.readString();case Thrift.Type.STRUCT:for(this.readStructBegin();(t=this.readFieldBegin()).ftype!=Thrift.Type.STOP;)this.skip(t.ftype),this.readFieldEnd();return this.readStructEnd(),null;case Thrift.Type.MAP:for(t=this.readMapBegin(),i=0;i0&&this.rstack.length>this.rpos[this.rpos.length-1]+1&&this.rstack.pop(),this.skip(t.ktype),this.skip(t.vtype);return this.readMapEnd(),null;case Thrift.Type.SET:for(t=this.readSetBegin(),i=0;i>>24)|4278255360&(i[p]<<24|i[p]>>>8);i[u>>>5]|=128<>>9<<4)]=u;var f=o._ff,y=o._gg,v=o._hh,g=o._ii;for(p=0;p>>0,h=h+_>>>0,c=c+S>>>0,d=d+m>>>0}return n.endian([l,h,c,d])})._ff=function(e,t,i,n,r,s,a){var o=e+(t&i|~t&n)+(r>>>0)+a;return(o<>>32-s)+t},o._gg=function(e,t,i,n,r,s,a){var o=e+(t&n|i&~n)+(r>>>0)+a;return(o<>>32-s)+t},o._hh=function(e,t,i,n,r,s,a){var o=e+(t^i^n)+(r>>>0)+a;return(o<>>32-s)+t},o._ii=function(e,t,i,n,r,s,a){var o=e+(i^(t|~n))+(r>>>0)+a;return(o<>>32-s)+t},o._blocksize=16,o._digestsize=16,e.exports=function(e,t){if(null==e)throw new Error("Illegal argument "+e);var i=n.wordsToBytes(o(e,t));return t&&t.asBytes?i:t&&t.asString?a.bytesToString(i):n.bytesToHex(i)}},function(e,t){function i(e,t,i,n,r,s,a){try{var o=e[s](a),u=o.value}catch(e){return void i(e)}o.done?t(u):Promise.resolve(u).then(n,r)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(r,s){var a=e.apply(t,n);function o(e){i(a,r,s,o,u,"next",e)}function u(e){i(a,r,s,o,u,"throw",e)}o(void 0)}))}}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[i++]=127&e.lo|128,e.lo=e.lo>>>7;t[i++]=e.lo}function v(e,t,i){t[i]=255&e,t[i+1]=e>>>8&255,t[i+2]=e>>>16&255,t[i+3]=e>>>24}c.create=d(),c.alloc=function(e){return new r.Array(e)},r.Array!==Array&&(c.alloc=r.pool(c.alloc,r.Array.prototype.subarray)),c.prototype._push=function(e,t,i){return this.tail=this.tail.next=new u(e,t,i),this.len+=t,this},f.prototype=Object.create(u.prototype),f.prototype.fn=function(e,t,i){for(;e>127;)t[i++]=127&e|128,e>>>=7;t[i]=e},c.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new f((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},c.prototype.int32=function(e){return e<0?this._push(y,10,s.fromNumber(e)):this.uint32(e)},c.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},c.prototype.uint64=function(e){var t=s.from(e);return this._push(y,t.length(),t)},c.prototype.int64=c.prototype.uint64,c.prototype.sint64=function(e){var t=s.from(e).zzEncode();return this._push(y,t.length(),t)},c.prototype.bool=function(e){return this._push(p,1,e?1:0)},c.prototype.fixed32=function(e){return this._push(v,4,e>>>0)},c.prototype.sfixed32=c.prototype.fixed32,c.prototype.fixed64=function(e){var t=s.from(e);return this._push(v,4,t.lo)._push(v,4,t.hi)},c.prototype.sfixed64=c.prototype.fixed64,c.prototype.float=function(e){return this._push(r.float.writeFloatLE,4,e)},c.prototype.double=function(e){return this._push(r.float.writeDoubleLE,8,e)};var g=r.Array.prototype.set?function(e,t,i){t.set(e,i)}:function(e,t,i){for(var n=0;n>>0;if(!t)return this._push(p,1,0);if(r.isString(e)){var i=c.alloc(t=a.length(e));a.decode(e,i,0),e=i}return this.uint32(t)._push(g,t,e)},c.prototype.string=function(e){var t=o.length(e);return t?this.uint32(t)._push(o.write,t,e):this._push(p,1,0)},c.prototype.fork=function(){return this.states=new h(this),this.head=this.tail=new u(l,0,0),this.len=0,this},c.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new u(l,0,0),this.len=0),this},c.prototype.ldelim=function(){var e=this.head,t=this.tail,i=this.len;return this.reset().uint32(i),i&&(this.tail.next=e.next,this.tail=t,this.len+=i),this},c.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),i=0;e;)e.fn(e.val,t,i),i+=e.len,e=e.next;return t},c._configure=function(e){n=e,c.create=d(),n._configure()}},function(e,t,i){"use strict";e.exports=u;var n,r=i(7),s=r.LongBits,a=r.utf8;function o(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function u(e){this.buf=e,this.pos=0,this.len=e.length}var l,h="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new u(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new u(e);throw Error("illegal buffer")},c=function(){return r.Buffer?function(e){return(u.create=function(e){return r.Buffer.isBuffer(e)?new n(e):h(e)})(e)}:h};function d(){var e=new s(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw o(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw o(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function p(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function f(){if(this.pos+8>this.len)throw o(this,8);return new s(p(this.buf,this.pos+=4),p(this.buf,this.pos+=4))}u.create=c(),u.prototype._slice=r.Array.prototype.subarray||r.Array.prototype.slice,u.prototype.uint32=(l=4294967295,function(){if(l=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return l;if(l=(l|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return l;if((this.pos+=5)>this.len)throw this.pos=this.len,o(this,10);return l}),u.prototype.int32=function(){return 0|this.uint32()},u.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},u.prototype.bool=function(){return 0!==this.uint32()},u.prototype.fixed32=function(){if(this.pos+4>this.len)throw o(this,4);return p(this.buf,this.pos+=4)},u.prototype.sfixed32=function(){if(this.pos+4>this.len)throw o(this,4);return 0|p(this.buf,this.pos+=4)},u.prototype.float=function(){if(this.pos+4>this.len)throw o(this,4);var e=r.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},u.prototype.double=function(){if(this.pos+8>this.len)throw o(this,4);var e=r.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},u.prototype.bytes=function(){var e=this.uint32(),t=this.pos,i=this.pos+e;if(i>this.len)throw o(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,i):t===i?new this.buf.constructor(0):this._slice.call(this.buf,t,i)},u.prototype.string=function(){var e=this.bytes();return a.read(e,0,e.length)},u.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw o(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw o(this)}while(128&this.buf[this.pos++]);return this},u.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},u._configure=function(e){n=e,u.create=c(),n._configure();var t=r.Long?"toLong":"toNumber";r.merge(u.prototype,{int64:function(){return d.call(this)[t](!1)},uint64:function(){return d.call(this)[t](!0)},sint64:function(){return d.call(this).zzDecode()[t](!1)},fixed64:function(){return f.call(this)[t](!0)},sfixed64:function(){return f.call(this)[t](!1)}})}},function(e,t,i){var n=i(24),r=i(25);e.exports=function(e,t,i){var s=t&&i||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var a=(e=e||{}).random||(e.rng||n)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t)for(var o=0;o<16;++o)t[s+o]=a[o];return t||r(a)}},function(e,t){function i(){return e.exports=i=Object.assign||function(e){for(var t=1;t>>((3&t)<<3)&255;return r}}},function(e,t){for(var i=[],n=0;n<256;++n)i[n]=(n+256).toString(16).substr(1);e.exports=function(e,t){var n=t||0,r=i;return[r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],"-",r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]],r[e[n++]]].join("")}},function(e,t,i){var n=function(e){"use strict";var t=Object.prototype,i=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",s=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function o(e,t,i,n){var r=t&&t.prototype instanceof h?t:h,s=Object.create(r.prototype),a=new E(n||[]);return s._invoke=function(e,t,i){var n="suspendedStart";return function(r,s){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===r)throw s;return R()}for(i.method=r,i.arg=s;;){var a=i.delegate;if(a){var o=_(a,i);if(o){if(o===l)continue;return o}}if("next"===i.method)i.sent=i._sent=i.arg;else if("throw"===i.method){if("suspendedStart"===n)throw n="completed",i.arg;i.dispatchException(i.arg)}else"return"===i.method&&i.abrupt("return",i.arg);n="executing";var h=u(e,t,i);if("normal"===h.type){if(n=i.done?"completed":"suspendedYield",h.arg===l)continue;return{value:h.arg,done:i.done}}"throw"===h.type&&(n="completed",i.method="throw",i.arg=h.arg)}}}(e,i,a),s}function u(e,t,i){try{return{type:"normal",arg:e.call(t,i)}}catch(e){return{type:"throw",arg:e}}}e.wrap=o;var l={};function h(){}function c(){}function d(){}var p={};p[r]=function(){return this};var f=Object.getPrototypeOf,y=f&&f(f(w([])));y&&y!==t&&i.call(y,r)&&(p=y);var v=d.prototype=h.prototype=Object.create(p);function g(e){["next","throw","return"].forEach((function(t){e[t]=function(e){return this._invoke(t,e)}}))}function T(e,t){var n;this._invoke=function(r,s){function a(){return new t((function(n,a){!function n(r,s,a,o){var l=u(e[r],e,s);if("throw"!==l.type){var h=l.arg,c=h.value;return c&&"object"==typeof c&&i.call(c,"__await")?t.resolve(c.__await).then((function(e){n("next",e,a,o)}),(function(e){n("throw",e,a,o)})):t.resolve(c).then((function(e){h.value=e,a(h)}),(function(e){return n("throw",e,a,o)}))}o(l.arg)}(r,s,n,a)}))}return n=n?n.then(a,a):a()}}function _(e,t){var i=e.iterator[t.method];if(void 0===i){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,_(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=u(i,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var r=n.arg;return r?r.done?(t[e.resultName]=r.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):r:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function S(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function m(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function w(e){if(e){var t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,s=function t(){for(;++n=0;--r){var s=this.tryEntries[r],a=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var o=i.call(s,"catchLoc"),u=i.call(s,"finallyLoc");if(o&&u){if(this.prev=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&i.call(r,"finallyLoc")&&this.prev=0;--t){var i=this.tryEntries[t];if(i.finallyLoc===e)return this.complete(i.completion,i.afterLoc),m(i),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var i=this.tryEntries[t];if(i.tryLoc===e){var n=i.completion;if("throw"===n.type){var r=n.arg;m(i)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,i){return this.delegate={iterator:w(e),resultName:t,nextLoc:i},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=n}catch(e){Function("r","regeneratorRuntime = r")(n)}},function(e,t,i){var n=i(14);e.exports=function(e){if(Array.isArray(e))return n(e)}},function(e,t){e.exports=function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}},function(e,t,i){var n=i(14);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?n(e,t):void 0}}},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}},function(e,t,i){(function(e){var n=void 0!==e&&e||"undefined"!=typeof self&&self||window,r=Function.prototype.apply;function s(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new s(r.call(setTimeout,n,arguments),clearTimeout)},t.setInterval=function(){return new s(r.call(setInterval,n,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},s.prototype.unref=s.prototype.ref=function(){},s.prototype.close=function(){this._clearFn.call(n,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout((function(){e._onTimeout&&e._onTimeout()}),t))},i(32),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(this,i(13))},function(e,t,i){(function(e,t){!function(e,i){"use strict";if(!e.setImmediate){var n,r,s,a,o,u=1,l={},h=!1,c=e.document,d=Object.getPrototypeOf&&Object.getPrototypeOf(e);d=d&&d.setTimeout?d:e,"[object process]"==={}.toString.call(e.process)?n=function(e){t.nextTick((function(){f(e)}))}:!function(){if(e.postMessage&&!e.importScripts){var t=!0,i=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=i,t}}()?e.MessageChannel?((s=new MessageChannel).port1.onmessage=function(e){f(e.data)},n=function(e){s.port2.postMessage(e)}):c&&"onreadystatechange"in c.createElement("script")?(r=c.documentElement,n=function(e){var t=c.createElement("script");t.onreadystatechange=function(){f(e),t.onreadystatechange=null,r.removeChild(t),t=null},r.appendChild(t)}):n=function(e){setTimeout(f,0,e)}:(a="setImmediate$"+Math.random()+"$",o=function(t){t.source===e&&"string"==typeof t.data&&0===t.data.indexOf(a)&&f(+t.data.slice(a.length))},e.addEventListener?e.addEventListener("message",o,!1):e.attachEvent("onmessage",o),n=function(t){e.postMessage(a+t,"*")}),d.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),i=0;i1)for(var i=1;i>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return 16711935&n.rotl(e,8)|4278255360&n.rotl(e,24);for(var t=0;t0;e--)t.push(Math.floor(256*Math.random()));return t},bytesToWords:function(e){for(var t=[],i=0,n=0;i>>5]|=e[i]<<24-n%32;return t},wordsToBytes:function(e){for(var t=[],i=0;i<32*e.length;i+=8)t.push(e[i>>>5]>>>24-i%32&255);return t},bytesToHex:function(e){for(var t=[],i=0;i>>4).toString(16)),t.push((15&e[i]).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],i=0;i>>6*(3-s)&63)):t.push("=");return t.join("")},base64ToBytes:function(e){e=e.replace(/[^A-Z0-9+\/]/gi,"");for(var t=[],n=0,r=0;n>>6-2*r);return t}},e.exports=n},function(e,t){function i(e){return!!e.constructor&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)} /*! * Determine if an object is a Buffer * * @author Feross Aboukhadijeh * @license MIT */ e.exports=function(e){return null!=e&&(i(e)||function(e){return"function"==typeof e.readFloatLE&&"function"==typeof e.slice&&i(e.slice(0,0))}(e)||!!e._isBuffer)}},function(e,t,i){var n; /*! * EventEmitter v5.2.9 - git.io/ee * Unlicense - http://unlicense.org/ * Oliver Caldwell - https://oli.me.uk/ * @preserve */!function(t){"use strict";function r(){}var s=r.prototype,a=t.EventEmitter;function o(e,t){for(var i=e.length;i--;)if(e[i].listener===t)return i;return-1}function u(e){return function(){return this[e].apply(this,arguments)}}s.getListeners=function(e){var t,i,n=this._getEvents();if(e instanceof RegExp)for(i in t={},n)n.hasOwnProperty(i)&&e.test(i)&&(t[i]=n[i]);else t=n[e]||(n[e]=[]);return t},s.flattenListeners=function(e){var t,i=[];for(t=0;t1&&"="===e.charAt(t);)++i;return Math.ceil(3*e.length)/4-i};for(var r=new Array(64),s=new Array(123),a=0;a<64;)s[r[a]=a<26?a+65:a<52?a+71:a<62?a-4:a-59|43]=a++;n.encode=function(e,t,i){for(var n,s=null,a=[],o=0,u=0;t>2],n=(3&l)<<4,u=1;break;case 1:a[o++]=r[n|l>>4],n=(15&l)<<2,u=2;break;case 2:a[o++]=r[n|l>>6],a[o++]=r[63&l],u=0}o>8191&&((s||(s=[])).push(String.fromCharCode.apply(String,a)),o=0)}return u&&(a[o++]=r[n],a[o++]=61,1===u&&(a[o++]=61)),s?(o&&s.push(String.fromCharCode.apply(String,a.slice(0,o))),s.join("")):String.fromCharCode.apply(String,a.slice(0,o))};n.decode=function(e,t,i){for(var n,r=i,a=0,o=0;o1)break;if(void 0===(u=s[u]))throw Error("invalid encoding");switch(a){case 0:n=u,a=1;break;case 1:t[i++]=n<<2|(48&u)>>4,n=u,a=2;break;case 2:t[i++]=(15&n)<<4|(60&u)>>2,n=u,a=3;break;case 3:t[i++]=(3&n)<<6|u,a=0}}if(1===a)throw Error("invalid encoding");return i-r},n.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}},function(e,t,i){"use strict";function n(){this._listeners={}}e.exports=n,n.prototype.on=function(e,t,i){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:i||this}),this},n.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var i=this._listeners[e],n=0;n0?0:2147483648,i,n);else if(isNaN(t))e(2143289344,i,n);else if(t>34028234663852886e22)e((r<<31|2139095040)>>>0,i,n);else if(t<11754943508222875e-54)e((r<<31|Math.round(t/1401298464324817e-60))>>>0,i,n);else{var s=Math.floor(Math.log(t)/Math.LN2);e((r<<31|s+127<<23|8388607&Math.round(t*Math.pow(2,-s)*8388608))>>>0,i,n)}}function i(e,t,i){var n=e(t,i),r=2*(n>>31)+1,s=n>>>23&255,a=8388607&n;return 255===s?a?NaN:r*(1/0):0===s?1401298464324817e-60*r*a:r*Math.pow(2,s-150)*(a+8388608)}e.writeFloatLE=t.bind(null,r),e.writeFloatBE=t.bind(null,s),e.readFloatLE=i.bind(null,a),e.readFloatBE=i.bind(null,o)}(),"undefined"!=typeof Float64Array?function(){var t=new Float64Array([-0]),i=new Uint8Array(t.buffer),n=128===i[7];function r(e,n,r){t[0]=e,n[r]=i[0],n[r+1]=i[1],n[r+2]=i[2],n[r+3]=i[3],n[r+4]=i[4],n[r+5]=i[5],n[r+6]=i[6],n[r+7]=i[7]}function s(e,n,r){t[0]=e,n[r]=i[7],n[r+1]=i[6],n[r+2]=i[5],n[r+3]=i[4],n[r+4]=i[3],n[r+5]=i[2],n[r+6]=i[1],n[r+7]=i[0]}function a(e,n){return i[0]=e[n],i[1]=e[n+1],i[2]=e[n+2],i[3]=e[n+3],i[4]=e[n+4],i[5]=e[n+5],i[6]=e[n+6],i[7]=e[n+7],t[0]}function o(e,n){return i[7]=e[n],i[6]=e[n+1],i[5]=e[n+2],i[4]=e[n+3],i[3]=e[n+4],i[2]=e[n+5],i[1]=e[n+6],i[0]=e[n+7],t[0]}e.writeDoubleLE=n?r:s,e.writeDoubleBE=n?s:r,e.readDoubleLE=n?a:o,e.readDoubleBE=n?o:a}():function(){function t(e,t,i,n,r,s){var a=n<0?1:0;if(a&&(n=-n),0===n)e(0,r,s+t),e(1/n>0?0:2147483648,r,s+i);else if(isNaN(n))e(0,r,s+t),e(2146959360,r,s+i);else if(n>17976931348623157e292)e(0,r,s+t),e((a<<31|2146435072)>>>0,r,s+i);else{var o;if(n<22250738585072014e-324)e((o=n/5e-324)>>>0,r,s+t),e((a<<31|o/4294967296)>>>0,r,s+i);else{var u=Math.floor(Math.log(n)/Math.LN2);1024===u&&(u=1023),e(4503599627370496*(o=n*Math.pow(2,-u))>>>0,r,s+t),e((a<<31|u+1023<<20|1048576*o&1048575)>>>0,r,s+i)}}}function i(e,t,i,n,r){var s=e(n,r+t),a=e(n,r+i),o=2*(a>>31)+1,u=a>>>20&2047,l=4294967296*(1048575&a)+s;return 2047===u?l?NaN:o*(1/0):0===u?5e-324*o*l:o*Math.pow(2,u-1075)*(l+4503599627370496)}e.writeDoubleLE=t.bind(null,r,0,4),e.writeDoubleBE=t.bind(null,s,4,0),e.readDoubleLE=i.bind(null,a,0,4),e.readDoubleBE=i.bind(null,o,4,0)}(),e}function r(e,t,i){t[i]=255&e,t[i+1]=e>>>8&255,t[i+2]=e>>>16&255,t[i+3]=e>>>24}function s(e,t,i){t[i]=e>>>24,t[i+1]=e>>>16&255,t[i+2]=e>>>8&255,t[i+3]=255&e}function a(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function o(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}e.exports=n(n)},function(module,exports,__webpack_require__){"use strict";function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(e){}return null}module.exports=inquire},function(e,t,i){"use strict";var n=t;n.length=function(e){for(var t=0,i=0,n=0;n191&&n<224?s[a++]=(31&n)<<6|63&e[t++]:n>239&&n<365?(n=((7&n)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,s[a++]=55296+(n>>10),s[a++]=56320+(1023&n)):s[a++]=(15&n)<<12|(63&e[t++])<<6|63&e[t++],a>8191&&((r||(r=[])).push(String.fromCharCode.apply(String,s)),a=0);return r?(a&&r.push(String.fromCharCode.apply(String,s.slice(0,a))),r.join("")):String.fromCharCode.apply(String,s.slice(0,a))},n.write=function(e,t,i){for(var n,r,s=i,a=0;a>6|192,t[i++]=63&n|128):55296==(64512&n)&&56320==(64512&(r=e.charCodeAt(a+1)))?(n=65536+((1023&n)<<10)+(1023&r),++a,t[i++]=n>>18|240,t[i++]=n>>12&63|128,t[i++]=n>>6&63|128,t[i++]=63&n|128):(t[i++]=n>>12|224,t[i++]=n>>6&63|128,t[i++]=63&n|128);return i-s}},function(e,t,i){"use strict";e.exports=function(e,t,i){var n=i||8192,r=n>>>1,s=null,a=n;return function(i){if(i<1||i>r)return e(i);a+i>n&&(s=e(n),a=0);var o=t.call(s,a,a+=i);return 7&a&&(a=1+(7|a)),o}}},function(e,t,i){"use strict";e.exports=r;var n=i(7);function r(e,t){this.lo=e>>>0,this.hi=t>>>0}var s=r.zero=new r(0,0);s.toNumber=function(){return 0},s.zzEncode=s.zzDecode=function(){return this},s.length=function(){return 1};var a=r.zeroHash="\0\0\0\0\0\0\0\0";r.fromNumber=function(e){if(0===e)return s;var t=e<0;t&&(e=-e);var i=e>>>0,n=(e-i)/4294967296>>>0;return t&&(n=~n>>>0,i=~i>>>0,++i>4294967295&&(i=0,++n>4294967295&&(n=0))),new r(i,n)},r.from=function(e){if("number"==typeof e)return r.fromNumber(e);if(n.isString(e)){if(!n.Long)return r.fromNumber(parseInt(e,10));e=n.Long.fromString(e)}return e.low||e.high?new r(e.low>>>0,e.high>>>0):s},r.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,i=~this.hi>>>0;return t||(i=i+1>>>0),-(t+4294967296*i)}return this.lo+4294967296*this.hi},r.prototype.toLong=function(e){return n.Long?new n.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var o=String.prototype.charCodeAt;r.fromHash=function(e){return e===a?s:new r((o.call(e,0)|o.call(e,1)<<8|o.call(e,2)<<16|o.call(e,3)<<24)>>>0,(o.call(e,4)|o.call(e,5)<<8|o.call(e,6)<<16|o.call(e,7)<<24)>>>0)},r.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},r.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},r.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},r.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,i=this.hi>>>24;return 0===i?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:i<128?9:10}},function(e,t,i){"use strict";e.exports=s;var n=i(18);(s.prototype=Object.create(n.prototype)).constructor=s;var r=i(7);function s(){n.call(this)}function a(e,t,i){e.length<40?r.utf8.write(e,t,i):t.utf8Write?t.utf8Write(e,i):t.write(e,i)}s._configure=function(){s.alloc=r._Buffer_allocUnsafe,s.writeBytesBuffer=r.Buffer&&r.Buffer.prototype instanceof Uint8Array&&"set"===r.Buffer.prototype.set.name?function(e,t,i){t.set(e,i)}:function(e,t,i){if(e.copy)e.copy(t,i,0,e.length);else for(var n=0;n>>0;return this.uint32(t),t&&this._push(s.writeBytesBuffer,t,e),this},s.prototype.string=function(e){var t=r.Buffer.byteLength(e);return this.uint32(t),t&&this._push(a,t,e),this},s._configure()},function(e,t,i){"use strict";e.exports=s;var n=i(19);(s.prototype=Object.create(n.prototype)).constructor=s;var r=i(7);function s(e){n.call(this,e)}s._configure=function(){r.Buffer&&(s.prototype._slice=r.Buffer.prototype.slice)},s.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))},s._configure()},function(e,t,i){"use strict";t.Service=i(52)},function(e,t,i){"use strict";e.exports=r;var n=i(7);function r(e,t,i){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");n.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(i)}(r.prototype=Object.create(n.EventEmitter.prototype)).constructor=r,r.prototype.rpcCall=function e(t,i,r,s,a){if(!s)throw TypeError("request must be specified");var o=this;if(!a)return n.asPromise(e,o,t,i,r,s);if(o.rpcImpl)try{return o.rpcImpl(t,i[o.requestDelimited?"encodeDelimited":"encode"](s).finish(),(function(e,i){if(e)return o.emit("error",e,t),a(e);if(null!==i){if(!(i instanceof r))try{i=r[o.responseDelimited?"decodeDelimited":"decode"](i)}catch(e){return o.emit("error",e,t),a(e)}return o.emit("data",i,t),a(null,i)}o.end(!0)}))}catch(e){return o.emit("error",e,t),void setTimeout((function(){a(e)}),0)}else setTimeout((function(){a(Error("already ended"))}),0)},r.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},function(e,t,i){"use strict";e.exports={}},function(e,t,i){"use strict";i.r(t);var n=i(2),r=i.n(n),s=i(3),a=i.n(s),o=i(4),u=i(5),l=i(8),h=i.n(l),c=i(12),d=i.n(c),p=i(1);var f=function(e){return e=e||Object.create(null),{on:function(t,i){(e[t]||(e[t]=[])).push(i)},off:function(t,i){e[t]&&e[t].splice(e[t].indexOf(i)>>>0,1)},emit:function(t,i){(e[t]||[]).slice().map((function(e){e(i)})),(e["*"]||[]).slice().map((function(e){e(t,i)}))}}},y=(i(31),i(21)),v=i.n(y),g=i(11),T=i.n(g),_="success",S="fail",m=function(){function e(){r()(this,e),this.vid=w().vid,this.url="https://report-ad.agoralab.co/v1/report",this.sdk_version=u.SDK_VERSION,this.onlineTimer=null}return a()(e,[{key:"onlineUser",value:function(){var e=this;this.onlineTimer=setInterval((function(){e.report("online_user")}),2e4)}},{key:"destroy",value:function(){null!==this.onlineTimer&&clearInterval(this.onlineTimer)}},{key:"report",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",r=Date.now(),s={pts:[{m:"online_user"===e?"online_user":"event",ls:{vid:this.vid,version:this.sdk_version},vs:{count:1}}],sign:T()("src=miniapp&ts=".concat(r)),src:"miniapp",ts:r};if("online_user"!==e){var a={event:e,result:"success"===t?"1":"0",err_code:i.toString()};"pusher_state_change"!==e&&"player_state_change"!==e||void 0!==n&&("string"==typeof n?a.message=n:(a.wx_version=n.version,a.user_mobile_model=n.model,a.user_IP=n.ip,a.system=n.system)),v()(s.pts[0].ls,a)}return this.request({body:s,url:this.url})}},{key:"request",value:function(e){return new Promise((function(t,i){wx.request({url:e.url,data:e.body,header:{"content-type":"application/json"},method:"POST",success:function(e){p.default.info("weixin request report success"),200===e.statusCode?(p.default.info("response success"),t(e)):p.default.info("response fail: ".concat(e.statusCode))},fail:function(e){p.default.warn("weixin request report fail"),i(e)}})}))}}]),e}(),E={};function w(){return E}var R=["https://uap-ap-web-1.agora.io/api/v1","https://uap-ap-web-3.agora.io/api/v1","https://uap-ap-web-2.agoraio.cn/api/v1","https://uap-ap-web-4.agoraio.cn/api/v1"],b=function(e){var t=e.reportManager,i=e.grafanaReport,n={command:"convergeAllocateEdge",sid:e.sid,appId:e.appId,token:e.appId,uid:e.uid+"",cname:e.channel,ts:Math.floor(Date.now()/1e3),version:u.VERSION,seq:0,requestId:1};return new Promise((function(r,s){var a=0,o=function(i,n){try{t.report("chooseServer",{header:{sid:e.sid,cname:e.channel,uid:e.uid,success:!1},body:{csurl:n,ec:JSON.stringify(i)}})}catch(e){}4===++a&&s(i)},u=function(s){var a=R[s];wx.request({url:a,data:{service_name:"miniapp",json_body:JSON.stringify(n)},header:{"content-type":"application/json","X-Packet-URI":61,"X-Packet-Service-Type":0},method:"POST",success:function(n){var s,u,l=n.data;if(p.default.debug("From choose server",n),n.profile){var h=n.profile.peerIP;s=h,E.ip=s}else p.default.debug("skip user IP report!");if(200!==n.statusCode){o({code:901,reason:l.error||"choose server fail"},a);try{i.report("chooseServer",S,n.statusCode)}catch(e){}}else{var c=JSON.parse(l.json_body),d=c.vid;u=d,E.vid=u;var f=function(e){if(void 0!==e)return e.map((function(e){var t=e.address.split("."),i=t.length;return"wss://miniapp.agoraio.cn/".concat(t[i-4],"-").concat(t[i-3],"-").concat(t[i-2],"-").concat(t[i-1],"/api")}));p.default.error("miniapp service is not enabled for this AppID")}(c.servers);t.report("chooseServer",{header:{sid:e.sid,cname:e.channel,uid:e.uid,success:!0},body:{csurl:a,gatewaylist:f}});try{i.report("chooseServer",_)}catch(e){}r({serverlist:f,url:a})}},fail:function(e){o({code:901,reason:e.errMsg||"choose server fail"},a)}})};R.map((function(e,t){u(t)}))}))},k=function(){function e(t,i){r()(this,e),this.serverlist=[],this.option=t,this.index=0,this.isInit=!0,this.state="disconnected",this.hasInvokeClose=!1,this.emitter=i,this.on=this.emitter.on,this.off=this.emitter.off,this.emit=this.emitter.emit}return a()(e,[{key:"connect",value:function(){var e=this;"disconnected"!==this.state&&this.close(),b(this.option).then((function(t){var i=t.serverlist,n=t.url;p.default.debug("Get server list from "+n),e.index=0,e.serverlist=i,e.option&&e.option.servers&&(e.serverlist=e.option.servers),p.default.debug("Connect server with list: ",e.serverlist),e.connectWorker(e.serverlist[e.index])})).catch((function(t){e.emit&&e.emit("socketError",t)}))}},{key:"connectWorker",value:function(){var e=this;this.state="connecting";var t=this.serverlist[this.index];p.default.debug("Connect server: ",t);var i=this.option,n=i.sid,r=i.channel,s=i.uid,a=i.reportManager,o=i.grafanaReport;this.ws=wx.connectSocket({url:t,complete:function(e){return p.default.debug("wxSocket: complete: ",e)},fail:function(e){p.default.debug("wxSocket: fail: ",e),a&&a.report("connectWebSocket",{header:{sid:n,cname:r,uid:s,success:!1},body:{wsurl:t,ec:JSON.stringify(e)}}),o&&o.report("connectWebSocket",S,e.statusCode)},success:function(e){p.default.debug("wxSocket success: ",e),a&&a.report("connectWebSocket",{header:{sid:n,cname:r,uid:s,success:!0},body:{wsurl:t}}),o&&o.report("connectWebSocket",_)}}),this.ws.onOpen(this._onopen.bind(this)),this.ws.onMessage(this._onmessage.bind(this)),this.establishWSTimeoutTimer=setTimeout((function(){"connected"!==e.state&&e.connectNextWorker()}),5e3)}},{key:"connectNextWorker",value:function(){"disconnected"!==this.state&&this.close(),p.default.debug(this.index,this.serverlist.length),this.index>=this.serverlist.length-1?this.emit&&this.emit("socketError",{code:905,reason:"connect websocket failed",wsurl:JSON.stringify(this.serverlist)}):(this.index++,this.connectWorker())}},{key:"_onopen",value:function(){p.default.info("websocket onopen"),clearTimeout(this.establishWSTimeoutTimer),this.state="connected",this.isInit=!1,this.hasInvokeClose?p.default.debug("Alread invoke ws.Close, will not throw onopen event"):(this.ws.onClose(this._onclose.bind(this)),this.emit&&this.emit("onopen"))}},{key:"_onclose",value:function(e){p.default.info("websocket onclose:"+JSON.stringify(e)),this.emitter.emit("_wsClose"),clearTimeout(this.establishWSTimeoutTimer),this.state="disconnected",e&&"close"==e.reason||this.hasInvokeClose||(this.isInit?this.connectNextWorker():this.emit&&this.emit("onclose"))}},{key:"_onmessage",value:function(e){this.hasInvokeClose||(p.default.blind("receive message: ",JSON.stringify(e)),this.isConnected()&&this.emit&&this.emit("onmessage",e))}},{key:"isConnected",value:function(){return"connected"===this.state}},{key:"sendMessage",value:function(e){p.default.blind("send message: ",e),this.isConnected()&&this.ws&&this.ws.send({data:e})}},{key:"_checkServerList",value:function(e){return e instanceof Array!=0&&0!=e.length}},{key:"destroy",value:function(e){var t=this;"disconnected"!==this.state&&this.close();this.on("_wsClose",(function i(){t.off("_wsClose",i),t.serverlist=null,t.ws=null,t.emitter=null,t.on=null,t.off=null,t.emit=null,e&&e()}))}},{key:"close",value:function(){p.default.debug("Close websocket"),clearTimeout(this.establishWSTimeoutTimer),this.hasInvokeClose=!0,this.state="disconnected",this.ws&&this.ws.close({reason:"close"}),this.ws=null}}]),e}(),I=function(){function e(t){r()(this,e),this.appId=t.appId,this.channel=t.channel,this.uid=t.uid+"",this.sid=t.sid,this.seq=1,this.requestId=2}return a()(e,[{key:"setSid",value:function(e){this.sid=e}},{key:"_getWorkerManagerMsg",value:function(){return{appId:this.appId,cname:this.channel,uid:this.uid,sid:this.sid,sdkVersion:u.VERSION,seq:++this.seq,requestId:++this.requestId,ts:Math.floor(Date.now()/1e3)}}},{key:"send",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest=e,t}},{key:"updatePushUrl",value:function(){var e=this._getWorkerManagerMsg();return e.clientRequest={action:"update_url",role:"publish",uid:+this.uid},e}},{key:"ping",value:function(){return{command:"ping",requestId:++this.requestId,appId:this.appId,cname:this.channel,uid:this.uid+"",sid:this.sid,ts:Math.floor(Date.now()/1e3)}}},{key:"ping2",value:function(){var e=this._getWorkerManagerMsg();return e.clientRequest={action:"ping"},e}},{key:"setRole",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"set_role",role:e},t}},{key:"rejoin",value:function(e,t,i,n,r,s){var a=this._getWorkerManagerMsg();return a.clientRequest={action:"join",role:s,appId:e,key_vocs:n||e,key_vos:n||e,channel_name:t,uid:i+"",known_speakers:r,clientType:"undefined"==typeof qq?"wechat":"qq"},a}},{key:"join",value:function(e,t,i,n,r,s,a){var o=this._getWorkerManagerMsg();return o.clientRequest={action:"join",role:r,appId:e,key_vocs:n||e,key_vos:n||e,channel_name:t,uid:i+"",vid:w().vid.toString(),device:s,os:a,version:u.SDK_VERSION,clientType:"undefined"==typeof qq?"wechat":"qq"},o}},{key:"muteLocal",value:function(e,t){var i=this._getWorkerManagerMsg();return i.clientRequest={action:"mute_local",uid:+e,target:t,mute:!0},i}},{key:"unmuteLocal",value:function(e,t){var i=this._getWorkerManagerMsg();return i.clientRequest={action:"mute_local",uid:+e,target:t,mute:!1},i}},{key:"mute",value:function(e,t){var i=this._getWorkerManagerMsg();return i.clientRequest={action:"mute",uid:+e,target:t},i}},{key:"unmute",value:function(e,t){var i=this._getWorkerManagerMsg();return i.clientRequest={action:"unmute",uid:+e,target:t},i}},{key:"publish",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"publish",uid:+e},t}},{key:"unpublish",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"unpublish",uid:+e},t}},{key:"subscribe",value:function(e,t){var i=this._getWorkerManagerMsg();return i.clientRequest={action:"subscribe",uid:+e,options:{audio:t.audio,video:t.video}},i}},{key:"unsubscribe",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"unsubscribe",uid:[+e]},t}},{key:"setRemoteVideoStreamType",value:function(e,t){var i=this._getWorkerManagerMsg();return i.clientRequest={action:"set_remote_stream_type",uid:+e,type:t},i}},{key:"renewToken",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"update_key",key_vos:e},t}},{key:"leave",value:function(e){var t=this._getWorkerManagerMsg();return t.clientRequest={action:"leave",uid:+e},t}}]),e}(),C=i(0),N=i.n(C),A=function(){function e(t,i){r()(this,e),this.appId=t.appId,this.channel=t.channel,this.uid=t.uid,this.sid=t.sid,this.role=t.role,this.channelKey=t.channelKey,this.clientId="client",this.option=t,this.timers=new Set,this.reportManager=t.reportManager,this.grafanaReport=t.grafanaReport,this.clientEmitter=i,this.emitter=new f,this.on=this.emitter.on,this.off=this.emitter.off,this.emit=this.emitter.emit,this.join=this.join.bind(this),this.msgManager=new I(t)}var t,i,n;return a()(e,[{key:"connect",value:function(){var e=this;return new Promise((function(t,i){e.ws=new k(e.option,e.emitter),e.ws.connect(),e.on("onmessage",e._onMessage.bind(e));e.on("socketError",i),e.on("onopen",(function i(){e.off&&e.off("onopen",i),e._ping(),t()})),e.on("onclose",(function(){return e.clientEmitter.emit("error",{code:904,reason:"websocket disconnected"})}))}))}},{key:"_onMessage",value:function(e){if(e&&e.data){var t=JSON.parse(e.data);if(t&&"pong"!==t.command){p.default.debug("worker message: ",t),p.default.debug("code message:",t);try{this.reportManager.report("serverEvent",{header:{sid:this.sid,cname:this.channel,uid:this.uid,success:!0},body:{action:"serverEvent",details:t,req_ts:+new Date}})}catch(e){}}if(t.requestId&&this.emit(t.requestId,t),"serverStatus"===t.command){if(t.code&&200!==t.code){if(503===t.code)return;this.clientEmitter.emit("error",{code:t.code,reason:t.reason||"server error"})}if(t.serverStatus){p.default.info("Receive message from server: ".concat(JSON.stringify(t.serverStatus)));var i=t.serverStatus.action;if("audio-mute"==i)return t.serverStatus.mute?this.clientEmitter.emit("mute-audio",{uid:t.serverStatus.uid}):this.clientEmitter.emit("unmute-audio",{uid:t.serverStatus.uid});if("video-mute"==i)return t.serverStatus.mute?this.clientEmitter.emit("mute-video",{uid:t.serverStatus.uid}):this.clientEmitter.emit("unmute-video",{uid:t.serverStatus.uid});if("key-expired"===i)return this.clientEmitter.emit("token-privilege-did-expire");if("key-will-expire"===i)return this.clientEmitter.emit("token-privilege-will-expire");this.clientEmitter.emit(i,t.serverStatus)}}}}},{key:"_sendMessage",value:function(e){var t=this;if(this.ws)return new Promise((function(i,n){if(!t.isWSConnected())return n({code:904,reason:"websocket disconnected",wsurl:t.getWSUrl()});"ping"!==e.command&&p.default.debug("send to woker: ",e);var r,s=e?e.requestId:null,a=function e(a){if(t.ws)return t.off(s,e),clearTimeout(r),t.timers.delete(r),200==a.code?i(a.serverResponse):n({code:a.code,reason:a.msg||a.reason,serverResponse:a.serverResponse,wsurl:t.getWSUrl()})};if(!s)return n({code:902,reason:"no requestid"});t.ws.sendMessage(JSON.stringify(e)),t.on(s,a),r=setTimeout((function(){return a({code:903,reason:"time out"})}),1e4),t.timers.add(r)}))}},{key:"_ping",value:function(){var e=this;this.pingTimer=setInterval((function(){e.ws.sendMessage(JSON.stringify(e.msgManager.ping()))}),3e3)}},{key:"setRole",value:function(e){return this._sendMessage(this.msgManager.setRole(e))}},{key:"rejoin",value:function(e){return this._sendMessage(this.msgManager.rejoin(this.appId,this.channel,this.uid,this.channelKey,e,this.role))}},{key:"join",value:function(e,t){return this._sendMessage(this.msgManager.join(this.appId,this.channel,this.uid,this.channelKey,this.role,e,t))}},{key:"send",value:function(e){return this._sendMessage(this.msgManager.send(e))}},{key:"updatePushUrl",value:function(){return this._sendMessage(this.msgManager.updatePushUrl())}},{key:"publish",value:function(){return this._sendMessage(this.msgManager.publish(this.uid))}},{key:"unpublish",value:function(){return this._sendMessage(this.msgManager.unpublish(this.uid))}},{key:"subscribe",value:function(e,t){return this._sendMessage(this.msgManager.subscribe(e,t))}},{key:"unsubscribe",value:function(e){return this._sendMessage(this.msgManager.unsubscribe(e))}},{key:"setRemoteVideoStreamType",value:function(e,t){return this._sendMessage(this.msgManager.setRemoteVideoStreamType(e,t))}},{key:"mute",value:function(e,t){return this._sendMessage(this.msgManager.mute(e,t))}},{key:"unmute",value:function(e,t){return this._sendMessage(this.msgManager.unmute(e,t))}},{key:"muteLocal",value:function(e){return this._sendMessage(this.msgManager.muteLocal(this.uid,e))}},{key:"unmuteLocal",value:function(e){return this._sendMessage(this.msgManager.unmuteLocal(this.uid,e))}},{key:"renewToken",value:function(e){return this._sendMessage(this.msgManager.renewToken(e))}},{key:"leave",value:function(){return this._sendMessage(this.msgManager.leave(this.uid))}},{key:"isWSConnected",value:function(){return!!this.ws&&this.ws.isConnected()}},{key:"getWSUrl",value:function(){return this.ws.serverlist[this.ws.index]}},{key:"destroy",value:function(e){var t=this;clearInterval(this.pingTimer),this.timers.forEach((function(e){clearInterval(e)})),this.timers=null,this.ws&&this.ws.destroy((function(){t.ws=null,t.emitter=null,t.on=null,t.off=null,t.emit=null,e&&e()}))}},{key:"startChannelMediaRelay",value:(n=d()(h.a.mark((function e(t){var i,n,r,s,a,o=this;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.channelMediaRelayController){e.next=2;break}throw new C.ChannelMediaError("RELAY_ALREADY_START","",C.CHANNEL_MEDIA_RELAY_ERROR.RELAY_ALREADY_START);case 2:return i=function(e){o.clientEmitter.emit({type:"channel-media-relay-event",code:e})},n=function(e,t,i){e===C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE&&t===C.CHANNEL_MEDIA_RELAY_ERROR.SERVER_CONNECTION_LOST&&(o.channelMediaRelayController.dispose(),o.channelMediaRelayController=null),o.clientEmitter.emit({type:"channel-media-relay-state",state:e,code:t,data:i})},r={token:this.appId,appId:this.appId,cname:this.channel,uid:this.uid,sid:this.sid,clientId:this.clientId},this.channelMediaRelayController=new N.a(r,this.clientId),this.channelMediaRelayController.on("event",i),this.channelMediaRelayController.on("state",n),e.prev=8,e.next=11,this.channelMediaRelayController.startChannelMediaRelay(t);case 11:e.next=23;break;case 13:throw e.prev=13,e.t0=e.catch(8),p.default.debug("[".concat(this.clientId,"] startChannelMediaRelay exception: ").concat(JSON.stringify(e.t0))),s=C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE,a="",a=e.t0 instanceof C.ChannelMediaError?"SetSourceChannelStatus"===e.t0.data||e.t0.data&&e.t0.data.serverResponse&&"SetSourceChannel"===e.t0.data.serverResponse.command?"FAILED_JOIN_SRC":"SetDestChannelStatus"===e.t0.data||e.t0.data&&e.t0.data.serverResponse&&"SetDestChannel"===e.t0.data.serverResponse.command?"FAILED_JOIN_DEST":e.t0.data&&e.t0.data.serverResponse&&"StartPacketTransfer"===e.t0.data.serverResponse.command?"FAILED_PACKET_SENT_TO_DEST":e.t0.message===C.CHANNEL_MEDIA_ERROR.REQUEST_TIMEOUT||e.t0.message===C.CHANNEL_MEDIA_ERROR.WAIT_STATUS_TIMEOUT?"SERVER_NO_RESPONSE":e.t0.message===C.CHANNEL_MEDIA_ERROR.REQUEST_FAILED||e.t0.message===C.CHANNEL_MEDIA_ERROR.WAIT_STATUS_ERROR?"SERVER_ERROR_RESPONSE":e.t0.message===C.CHANNEL_MEDIA_ERROR.AP_REQUEST_TIMEOUT?"NO_RESOURCE_AVAILABLE":e.t0.message===C.CHANNEL_MEDIA_ERROR.WS_ABORT||e.t0.message===C.CHANNEL_MEDIA_ERROR.AP_REQUEST_ABORT?"OPERATION_ABORT":"INTERNAL_ERROR":"INTERNAL_ERROR",this.clientEmitter.emit({type:"channel-media-relay-state",state:s,code:C.CHANNEL_MEDIA_RELAY_ERROR[a]}),this.channelMediaRelayController&&(this.channelMediaRelayController.dispose(),this.channelMediaConfig=null,this.channelMediaRelayController=null),this.clientEmitter.emit({type:"channel-media-relay-state",state:C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_IDLE}),new C.ChannelMediaError(a,null,C.CHANNEL_MEDIA_RELAY_ERROR[a]);case 23:this.clientEmitter.emit({type:"channel-media-relay-state",state:C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_RUNNING,code:C.CHANNEL_MEDIA_RELAY_ERROR.RELAY_OK}),this.channelMediaConfig=t;case 25:case"end":return e.stop()}}),e,this,[[8,13]])}))),function(e){return n.apply(this,arguments)})},{key:"updateChannelMediaRelay",value:(i=d()(h.a.mark((function e(t){var i,n;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelMediaRelayController){e.next=2;break}throw new C.ChannelMediaError("RELAY_NOT_START",null,C.CHANNEL_MEDIA_RELAY_ERROR.RELAY_NOT_START);case 2:return e.prev=2,e.next=5,this.channelMediaRelayController.updateChannelMediaRelay(t);case 5:e.next=18;break;case 7:throw e.prev=7,e.t0=e.catch(2),p.default.debug("[".concat(this.clientId,"] updateChannelMediaRelay exception: ").concat(JSON.stringify(e.t0))),i=C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE,n="",n=e.t0 instanceof C.ChannelMediaError?e.t0.message===C.CHANNEL_MEDIA_ERROR.REQUEST_TIMEOUT||e.t0.message===C.CHANNEL_MEDIA_ERROR.WAIT_STATUS_TIMEOUT?"SERVER_NO_RESPONSE":e.t0.message===C.CHANNEL_MEDIA_ERROR.REQUEST_FAILED||e.t0.message===C.CHANNEL_MEDIA_ERROR.WAIT_STATUS_ERROR?"SERVER_ERROR_RESPONSE":e.t0.message===C.CHANNEL_MEDIA_ERROR.WS_ABORT||e.t0.message===C.CHANNEL_MEDIA_ERROR.AP_REQUEST_ABORT?"OPERATION_ABORT":"INTERNAL_ERROR":"INTERNAL_ERROR",this.clientEmitter.emit({type:"channel-media-relay-event",code:C.CHANNEL_MEDIA_RELAY_EVENT.PACKET_UPDATE_DEST_CHANNEL_REFUSED}),this.clientEmitter.emit({type:"channel-media-relay-state",state:i,code:C.CHANNEL_MEDIA_RELAY_ERROR[n]}),this.channelMediaRelayController&&(this.channelMediaRelayController.dispose(),this.channelMediaConfig=null,this.channelMediaRelayController=null),this.clientEmitter.emit({type:"channel-media-relay-state",state:C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_IDLE}),new C.ChannelMediaError(n,null,C.CHANNEL_MEDIA_RELAY_ERROR[n]);case 18:this.channelMediaConfig=t;case 19:case"end":return e.stop()}}),e,this,[[2,7]])}))),function(e){return i.apply(this,arguments)})},{key:"stopChannelMediaRelay",value:(t=d()(h.a.mark((function e(){var t,i;return h.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(this.channelMediaRelayController){e.next=2;break}throw new C.ChannelMediaError("RELAY_NOT_START",null,C.CHANNEL_MEDIA_RELAY_ERROR.RELAY_NOT_START);case 2:return e.prev=2,e.next=5,this.channelMediaRelayController.stopChannelMediaRelay();case 5:e.next=17;break;case 7:throw e.prev=7,e.t0=e.catch(2),p.default.debug("[".concat(this.clientId,"] stopChannelMediaRelay exception: ").concat(JSON.stringify(e.t0))),t=C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_FAILURE,i="",i=e.t0 instanceof C.ChannelMediaError?e.t0.message===C.CHANNEL_MEDIA_ERROR.REQUEST_TIMEOUT||e.t0.message===C.CHANNEL_MEDIA_ERROR.WAIT_STATUS_TIMEOUT?"SERVER_NO_RESPONSE":e.t0.message===C.CHANNEL_MEDIA_ERROR.REQUEST_FAILED||e.t0.message===C.CHANNEL_MEDIA_ERROR.WAIT_STATUS_ERROR?"SERVER_ERROR_RESPONSE":"INTERNAL_ERROR":"INTERNAL_ERROR",this.clientEmitter.emit({type:"channel-media-relay-state",state:t,code:C.CHANNEL_MEDIA_RELAY_ERROR[i]}),this.channelMediaRelayController&&(this.channelMediaRelayController.dispose(),this.channelMediaConfig=null,this.channelMediaRelayController=null),this.emit({type:"channel-media-relay-state",state:C.CHANNEL_MEDIA_RELAY_STATE.RELAY_STATE_IDLE}),new C.ChannelMediaError(i,null,C.CHANNEL_MEDIA_RELAY_ERROR[i]);case 17:this.channelMediaConfig=null,this.channelMediaRelayController=null;case 19:case"end":return e.stop()}}),e,this,[[2,7]])}))),function(){return t.apply(this,arguments)})}]),e}(),M=i(37).ReportServiceClient,O=i(9).default,P=i(17).VosdkHeader,L=i(16),B=function(){function e(){r()(this,e),this.transport=new O.TXHRTransport("https://uni-webcollector.agora.io/report"),this.protocol=new O.TJSONProtocol(this.transport),this.client=new M(this.protocol),this.seqId=0,this._cache=[],this.isReporting=!1,this.retryCount=0}return a()(e,[{key:"generateHeader",value:function(e){if(e&&e.sid)return new P({sid:e.sid,cname:e.cname||"",lts:e.lts,elapse:e.lts-this.startTime,uid:e.uid,success:e.success})}},{key:"report",value:function(e,t){var i=null;if(t.header&&(t.header.lts=+new Date,"sessionStart"===e&&(this.startTime=t.header.lts),i=this.generateHeader(t.header)),t.body&&i){var n=t.body;switch(e){case"sessionStart":(r=new L({miniappSession:!0})).uri=8e3,r.miniappSession.header=i,r.miniappSession.appid=n.appId,r.miniappSession.uname=n.uname,r.miniappSession.ver=u.SDK_VERSION,r.miniappSession.dk=n.dk,r.miniappSession.details=JSON.stringify({seq:this.seqId++});break;case"chooseServer":(r=new L({miniappJoinChooseServer:!0})).uri=8001,r.miniappJoinChooseServer.header=i,r.miniappJoinChooseServer.csurl=n.csurl,r.miniappJoinChooseServer.ec=n.ec,r.miniappJoinChooseServer.gatewaylist=n.gatewaylist,r.miniappJoinChooseServer.details=JSON.stringify({seq:this.seqId++});break;case"connectWebSocket":(r=new L({miniappConnectWebSocket:!0})).uri=8002,r.miniappConnectWebSocket.header=i,r.miniappConnectWebSocket.ec=n.ec,r.miniappConnectWebSocket.wsurl=n.wsurl,r.miniappConnectWebSocket.details=JSON.stringify({seq:this.seqId++});break;case"join":(r=new L({miniappJoin:!0})).uri=8003,r.miniappJoin.header=i,r.miniappJoin.ec=n.ec,r.miniappJoin.isrejoin=n.isrejoin,r.miniappJoin.details=JSON.stringify({seq:this.seqId++,appId:n.appId,wsurl:n.wsurl});break;case"publish":(r=new L({miniappPublish:!0})).uri=8004,r.miniappPublish.header=i,r.miniappPublish.ec=n.ec,r.miniappPublish.pushurl=n.pushurl,r.miniappPublish.details=JSON.stringify({seq:this.seqId++});break;case"unpublish":(r=new L({miniappUnpublish:!0})).uri=8005,r.miniappUnpublish.header=i,r.miniappUnpublish.ec=n.ec,r.miniappUnpublish.details=JSON.stringify({seq:this.seqId++});break;case"subscribe":(r=new L({miniappSubscribe:!0})).uri=8006,r.miniappSubscribe.header=i,r.miniappSubscribe.ec=n.ec,r.miniappSubscribe.pullurl=n.pullurl,r.miniappSubscribe.peerid=n.peerid,r.miniappSubscribe.details=JSON.stringify({seq:this.seqId++});break;case"unsubscribe":(r=new L({miniappUnsubscribe:!0})).uri=8007,r.miniappUnsubscribe.header=i,r.miniappUnsubscribe.ec=n.ec,r.miniappUnsubscribe.peerid=n.peerid,r.miniappUnsubscribe.details=JSON.stringify({seq:this.seqId++});break;case"leave":(r=new L({miniappLeave:!0})).uri=8008,r.miniappLeave.header=i,r.miniappLeave.ec=n.ec,r.miniappLeave.details=JSON.stringify({seq:this.seqId++});break;case"pusherState":(r=new L({miniappPusherState:!0})).uri=8010,r.miniappPusherState.header=i,r.miniappPusherState.url=n.url,r.miniappPusherState.code=n.code,r.miniappPusherState.status=n.status,r.miniappPusherState.error=n.error,r.miniappPusherState.details=JSON.stringify({seq:this.seqId++});break;case"playerState":(r=new L({miniappPlayerState:!0})).uri=8011,r.miniappPlayerState.header=i,r.miniappPlayerState.url=n.url,r.miniappPlayerState.code=n.code,r.miniappPlayerState.status=n.status,r.miniappPlayerState.error=n.error,r.miniappPlayerState.details=JSON.stringify({seq:this.seqId++});break;case"serverEvent":(r=new L({miniappServerEvent:!0})).uri=8009,r.miniappServerEvent.header=i,r.miniappServerEvent.action=n.action,r.miniappServerEvent.details=JSON.stringify(n.details),r.miniappServerEvent.req_ts=n.req_ts}}if(this._cache.push(r),!this.isReporting&&this._cache.length>0){var r=this._cache.shift();this._report(r)}}},{key:"_report",value:function(e){var t=this;this.isReporting=!0,this.client.Report(e,(function(i){if(i){p.default.debug("Report failed: ",i,e);var n=t.retryCount++<2?200:1e4;setTimeout((function(){t._report(e)}),n)}else{p.default.debug("Report succcess: ",e);var r=t._cache.shift();r?t._report(r):t.isReporting=!1}}))}}]),e}(),F={videoBitrate:"Miniapp_SDK_Pusher_Video_Bitrate",audioBitrate:"Miniapp_SDK_Pusher_Audio_Bitrate",videoFPS:"Miniapp_SDK_Pusher_Video_FPS",videoGOP:"Miniapp_SDK_Pusher_Video_GOP",netSpeed:"Miniapp_SDK_Pusher_Net_Speed",videoCache:"Miniapp_SDK_Pusher_Video_Cache",audioCache:"Miniapp_SDK_Pusher_Audio_Cache",videoWidth:"Miniapp_SDK_Pusher_Video_Width",videoHeight:"Miniapp_SDK_Pusher_Video_Height"},D={videoBitrate:"Miniapp_SDK_Player_Video_Bitrate",audioBitrate:"Miniapp_SDK_Player_Audio_Bitrate",videoFPS:"Miniapp_SDK_Player_Video_FPS",videoGOP:"Miniapp_SDK_Player_Video_GOP",netSpeed:"Miniapp_SDK_Player_Video_Cache",videoCache:"Miniapp_SDK_Player_Video_Cache",audioCache:"Miniapp_SDK_Player_Audio_Cache",vDecCacheSize:"Miniapp_SDK_Player_V_Dec_Cache_Size",vSumCacheSize:"Miniapp_SDK_Player_V_Sum_Cache_Size",avPlayInterval:"Miniapp_SDK_Player_AV_Play_Interval",avRecvInterval:"Miniapp_SDK_Player_AV_Recv_Interval",audioCacheThreshold:"Miniapp_SDK_Player_Audio_Cache_Threshold",videoWidth:"Miniapp_SDK_Player_Video_Width",videoHeight:"Miniapp_SDK_Player_Video_Height"},U=i(23),x=i.n(U).a.io.agora.pb,j=x.CounterCompact,q=x.Id,V=(x.Item,function(){function e(){r()(this,e),this.url="https://rest-argus-ad.agoralab.co/v2/report",this.sid=Object(o.generateSessionId)(),this.pusherNet=null,this.playerNetMap={},this.pusherTimer=null,this.playerTimer=null,this.startPusherReport(),this.startPlayerReport()}return a()(e,[{key:"setPusherNetData",value:function(e){this.pusherNet=e}},{key:"setPlayerNetData",value:function(e,t){this.playerNetMap[e]=t}},{key:"getMessageTypeId",value:function(e){return q[e]}},{key:"shiftPb",value:function(e,t,i){var n=this,r=Date.now(),s=t.map((function(e){return{lts:r,id:n.getMessageTypeId(i[e.type]),value:e.value,tagErrorCode:6,streamId:0}})),a={sid:this.sid,peer:e,items:s},o=j.create(a);return j.encode(o).finish()}},{key:"startPusherReport",value:function(){var e=this;this.pusherTimer=setInterval((function(){if(e.pusherNet){var t=Object.keys(e.pusherNet).map((function(t){return void 0!==F[t]?{type:t,value:e.pusherNet[t]}:null}));t=t.filter((function(e){return null!==e}));var i=e.shiftPb(0,t,F);e.report(i)}}),6e3)}},{key:"startPlayerReport",value:function(){var e=this;this.playerTimer=setInterval((function(){if(e.playerNetMap){var t=function(t){var i=e.playerNetMap[t],n=Object.keys(i).map((function(e){return void 0!==D[e]?{type:e,value:i[e]}:null}));n=n.filter((function(e){return null!==e}));var r=e.shiftPb(t,n,D);e.report(r)};for(var i in e.playerNetMap)t(i)}e.playerNetMap={}}),6e3)}},{key:"destroy",value:function(){null!==this.pusherTimer&&clearInterval(this.pusherTimer),null!==this.playerTimer&&clearInterval(this.playerTimer),this.pusherNet=null,this.playerNet=null}},{key:"report",value:function(e){var t=Date.now();t=Math.floor(t/1e3);var i=wx.arrayBufferToBase64(e),n={id:1,payload:i,qos:1,sign:T()("payload=".concat(i,"&src=miniapp_sdk&ts=").concat(t)),src:"miniapp_sdk",ts:t};return this.request({body:n,url:this.url})}},{key:"request",value:function(e){return new Promise((function(t,i){wx.request({url:e.url,data:e.body,header:{"Content-Type":"application/json"},method:"POST",success:function(e){p.default.info("weixin request argus report success"),200===e.statusCode?(p.default.info("response success"),t(e)):p.default.info("response fail: ".concat(e.statusCode))},fail:function(e){p.default.warn("weixin request argus report fail"),i(e)}})}))}}]),e}()),W=i(6),G=function(){function e(t){var i=this;r()(this,e),this.emitter=new f,this.on=this.emitter.on,this.off=this.emitter.off,this.sid=Object(o.generateSessionId)(),this.pushUrl=null,this.playUrls=new Map,this.servers=t&&t.servers,this.reportManager=new B,this.role="broadcaster",this.grafanaReport=new m,this.argusReport=new V,this.systemInfo=null,this.emitter.on("stream-removed",(function(e){i.playUrls&&i.playUrls.delete(e.uid)}))}return a()(e,[{key:"init",value:function(e,t,i){if(!e||"string"!=typeof e||"null"===e.toLowerCase())throw Error("Invalid appId");this.appId=e.trim(),this.argusReport.sid=this.sid,this.grafanaReport.vid="",this.grafanaReport.onlineUser();try{this.systemInfo=wx.getSystemInfoSync()}catch(e){}this.reportManager.report("sessionStart",{header:{sid:this.sid,lts:+new Date,success:!0},body:{appId:e}}),t&&t()}},{key:"setRole",value:function(e,t,i){var n=this;if("broadcaster"===!e&&"audience"===!e)throw Error("Invalid role");this.role=e,this.worker&&this.worker.setRole(e).then((function(e){try{n.grafanaReport.report("set_role",_)}catch(e){}setTimeout((function(){if(!e)return t&&t();t&&t({updateURL:e["update-url"]})}),1)})).catch((function(){try{n.grafanaReport.report("set_role",S,err.code)}catch(e){}i&&i()}))}},{key:"rejoin",value:function(e,t,i,n,r,s){var a=this;if(!this.worker){if(e){if("string"!=typeof e||"null"===e.toLowerCase())throw Error("Invalid channelKey")}else e=this.appId;if(!t||"string"!=typeof t||"null"===t.toLowerCase()||t.length>128)throw Error("Invalid channel");if(this.uid=i||Object(o.random)(1e7),this.uid=Number.parseInt(this.uid),!Object(o.is32Uint)(this.uid))throw new Error("Invalid uid type");this.channel=t,this.worker=new A({appId:this.appId,channel:this.channel,uid:this.uid,sid:this.sid,role:this.role,servers:this.servers,channelKey:e,reportManager:this.reportManager,grafanaReport:this.grafanaReport},this.emitter),this.worker.connect().then((function(){return a.worker.rejoin(n)})).then((function(){try{a.reportManager.report("join",{header:{sid:a.sid,cname:a.channel,uid:a.uid,success:!0},body:{isrejoin:!0,appId:a.appId,wsurl:a.worker&&a.worker.getWSUrl()}})}catch(e){}try{a.grafanaReport.report("join",_)}catch(e){}setTimeout((function(){r&&r(this.uid)}),1)})).catch((function(e){try{a.reportManager.report("join",{header:{sid:a.sid,cname:a.channel,uid:a.uid,success:!1},body:{ec:JSON.stringify(e),appId:a.appId,wsurl:a.worker&&a.worker.getWSUrl()}})}catch(e){}try{a.grafanaReport.report("join",S,e.code)}catch(e){}a.destroy(),s&&s(e)}))}}},{key:"join",value:function(e,t,i,n,r){var s=this;if(!this.worker){if(e){if("string"!=typeof e||"null"===e.toLowerCase())throw Error("Invalid channelKey")}else e=this.appId;if(!t||"string"!=typeof t||"null"===t.toLowerCase()||t.length>128)throw Error("Invalid channel");if(this.uid=i||Object(o.random)(1e7),this.uid=Number.parseInt(this.uid),!Object(o.is32Uint)(this.uid))throw new Error("Invalid uid type");this.channel=t,this.worker=new A({appId:this.appId,channel:this.channel,uid:this.uid,sid:this.sid,role:this.role,servers:this.servers,channelKey:e,reportManager:this.reportManager,grafanaReport:this.grafanaReport},this.emitter),this.worker.connect().then((function(){return s.worker.join(s.systemInfo.model,s.systemInfo.system)})).then((function(e){try{s.reportManager.report("join",{header:{sid:s.sid,cname:s.channel,uid:s.uid,success:!0},body:{isrejoin:!1,appId:s.appId,wsurl:s.worker&&s.worker.getWSUrl()}})}catch(e){}try{s.grafanaReport.report("join",_,"",{model:s.systemInfo.model,version:s.systemInfo.version,system:s.systemInfo.system,ip:w().ip})}catch(e){}setTimeout((function(){n&&n(this.uid)}),1)})).catch((function(e){try{s.reportManager.report("join",{header:{sid:s.sid,cname:s.channel,uid:s.uid,success:!1},body:{ec:JSON.stringify(e),appId:s.appId,wsurl:e.wsurl||s.worker&&s.worker.getWSUrl()}})}catch(e){}try{s.grafanaReport.report("join",S,e.code,{model:s.systemInfo.model,version:s.systemInfo.version,system:s.systemInfo.system,ip:w().ip})}catch(e){}s.destroy(),r&&r(e)}))}}},{key:"publish",value:function(e,t){var i=this;this._checkWorker(),this.worker.publish().then((function(t){i.pushUrl=t.url;try{i.reportManager.report("publish",{header:{sid:i.sid,cname:i.channel,uid:i.uid,success:!0},body:{pushurl:t.url}})}catch(e){}try{i.grafanaReport.report("publish",_)}catch(e){}setTimeout((function(){e&&e(t.url)}),1)})).catch((function(e){i.reportManager.report("publish",{header:{sid:i.sid,cname:i.channel,uid:i.uid,success:!1},body:{ec:JSON.stringify(e)}});try{i.grafanaReport.report("publish",S,e.code)}catch(e){}t&&t(e)}))}},{key:"unpublish",value:function(e,t){var i=this;this._checkWorker(),this.worker.unpublish().then((function(t){i.pushUrl=null;try{i.reportManager.report("unpublish",{header:{sid:i.sid,cname:i.channel,uid:i.uid,success:!0},body:{}})}catch(e){}try{i.grafanaReport.report("unpublish",_)}catch(e){}setTimeout((function(){e&&e()}),1)})).catch((function(e){i.reportManager.report("unpublish",{header:{sid:i.sid,cname:i.channel,uid:i.uid,success:!1},body:{ec:JSON.stringify(e)}});try{i.grafanaReport.report("unpublish",S,e.code)}catch(e){}t&&t(e)}))}},{key:"subscribe",value:function(e,t,i){var n=this,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{audio:!0,video:!0};this._checkUid(e),this._checkWorker(),this.worker.subscribe(e,r).then((function(i){n.playUrls.set(e,i.url);try{n.reportManager.report("subscribe",{header:{sid:n.sid,cname:n.channel,uid:n.uid,success:!0},body:{pullurl:i.url}})}catch(e){}try{n.grafanaReport.report("subscribe",_)}catch(e){}setTimeout((function(){t&&t(i.url,i.rotation)}),1)})).catch((function(e){n.reportManager.report("subscribe",{header:{sid:n.sid,cname:n.channel,uid:n.uid,success:!1},body:{ec:JSON.stringify(e)}});try{n.grafanaReport.report("subscribe",S,e.code)}catch(e){}i&&i(e)}))}},{key:"unsubscribe",value:function(e,t,i){var n=this;this._checkUid(e),this._checkWorker(),this.worker.unsubscribe(e).then((function(i){n.playUrls.delete(e);try{n.reportManager.report("unsubscribe",{header:{sid:n.sid,cname:n.channel,uid:n.uid,success:!1},body:{}})}catch(e){}try{n.grafanaReport.report("unsubscribe",_)}catch(e){}setTimeout((function(){t&&t()}),1)})).catch((function(e){n.reportManager.report("unsubscribe",{header:{sid:n.sid,cname:n.channel,uid:n.uid,success:!1},body:{ec:JSON.stringify(e)}});try{n.grafanaReport.report("unsubscribe",S,e.code)}catch(e){}i&&i(e)}))}},{key:"mute",value:function(e,t,i,n){var r=this;if(this._checkUid(e),this._checkWorker(),"video"!==t&&"audio"!==t&&"all"!==t)throw new Error('target should be "video", "audio" or "all"');this.worker.mute(e,t).then((function(e){try{r.grafanaReport.report("mute",_)}catch(e){}setTimeout((function(){i&&i()}),1)})).catch((function(e){try{r.grafanaReport.report("mute",S,e.code)}catch(e){}n&&n(e)}))}},{key:"unmute",value:function(e,t,i,n){var r=this;if(this._checkUid(e),this._checkWorker(),"video"!==t&&"audio"!==t&&"all"!==t)throw new Error('target should be "video", "audio" or "all"');this.worker.unmute(e,t).then((function(e){try{r.grafanaReport.report("unmute",_)}catch(e){}setTimeout((function(){i&&i()}),1)})).catch((function(e){try{r.grafanaReport.report("unmute",S,e.code)}catch(e){}n&&n(e)}))}},{key:"setRemoteVideoStreamType",value:function(e,t,i,n){var r=this;this._checkUid(e),this._checkWorker(),this.worker.setRemoteVideoStreamType(e,t).then((function(e){try{r.grafanaReport.report("set_remote_stream_type",_)}catch(e){}setTimeout((function(){i&&i()}),1)})).catch((function(e){try{r.grafanaReport.report("set_remote_stream_type",S,e.code)}catch(e){}n&&n(e)}))}},{key:"renewToken",value:function(e,t,i){var n=this;this._checkWorker(),this.worker.renewToken(e).then((function(e){try{n.grafanaReport.report("update_token",_)}catch(e){}setTimeout((function(){t&&t()}),1)})).catch((function(e){try{n.grafanaReport.report("update_token",S,e.code)}catch(e){}i&&i(e)}))}},{key:"muteLocal",value:function(e,t,i){var n=this;if(this._checkWorker(),"video"!==e&&"audio"!==e&&"all"!==e)throw new Error('target should be "video", "audio" or "all"');this.worker.muteLocal(e).then((function(e){try{n.grafanaReport.report("mute_local",_)}catch(e){}setTimeout((function(){t&&t()}),1)})).catch((function(e){try{n.grafanaReport.report("mute_local",S,e.code)}catch(e){}i&&i(e)}))}},{key:"unmuteLocal",value:function(e,t,i){var n=this;if(this._checkWorker(),"video"!==e&&"audio"!==e&&"all"!==e)throw new Error('target should be "video", "audio" or "all"');this.worker.unmuteLocal(e).then((function(e){try{n.grafanaReport.report("unmute_local",_)}catch(e){}setTimeout((function(){t&&t()}),1)})).catch((function(e){try{n.grafanaReport.report("unmute_local",S,e.code)}catch(e){}i&&i(e)}))}},{key:"leave",value:function(e,t){var i=this;this.worker&&this.worker.isWSConnected()&&this.worker.leave().then((function(t){try{i.reportManager.report("leave",{header:{sid:i.sid,cname:i.channel,uid:i.uid,success:!0},body:{}})}catch(e){}try{i.grafanaReport.report("leave",_)}catch(e){}i.destroy((function(){setTimeout((function(){e&&e()}),1)}))})).catch((function(e){try{i.grafanaReport.report("leave",S,e.code)}catch(e){}t&&t(e)}))}},{key:"_checkUid",value:function(e){if(!e||"number"!=typeof e||!Object(o.is32Uint)(e))throw new Error("Invalid uid type")}},{key:"_checkWorker",value:function(){if(!this.worker||!this.worker.isWSConnected())throw new Error("Disconnected from server")}},{key:"isConnected",value:function(){return!(!this.worker||!this.worker.isWSConnected())}},{key:"updatePusherStateChange",value:function(e){if(this.pushUrl){var t=e.detail.code,i=e.detail.message;if(1002===t)try{this.grafanaReport.report("pusher_state_change",_,t)}catch(e){}if(-1307===t)try{this.grafanaReport.report("pusher_state_change",S,t,i)}catch(e){}}}},{key:"updatePlayerStateChange",value:function(e,t){if(this.playUrls.get(Number(e))){var i=t.detail.code,n=t.detail.message;if(2003===i||-2301===i){var r=2003===i?_:S;try{this.grafanaReport.report("player_state_change",r,i,n)}catch(e){}}}}},{key:"updatePusherNetStatus",value:function(e){if(this.pushUrl){var t=e.detail.info;this.argusReport.setPusherNetData(t)}}},{key:"updatePlayerNetStatus",value:function(e,t){if(this.playUrls.get(Number(e))){var i=t.detail.info;this.argusReport.setPlayerNetData(e,i)}}},{key:"send",value:function(e,t,i){this._checkWorker(),this.worker.send(e).then((function(e){t&&t(e)})).catch((function(e){i&&i(e)}))}},{key:"updatePushUrl",value:function(e,t){var i=this;this._checkWorker(),this.worker.updatePushUrl().then((function(t){setTimeout((function(){try{this.grafanaReport.report("update_url",_)}catch(e){}e&&e(t)}),1)})).catch((function(e){try{i.grafanaReport.report("update_url",S,e.code)}catch(e){}t&&t(e)}))}},{key:"destroy",value:function(e,t){var i=this;this.worker?(this.worker.destroy((function(){i.pushUrl=null,i.playUrls=null,e&&e()})),this.worker=null):(this.pushUrl=null,this.playUrls=null,e&&e()),this.grafanaReport.destroy(),this.argusReport.destroy()}},{key:"startChannelMediaRelay",value:function(e,t){if(!(e instanceof C.ChannelMediaRelayConfiguration))throw"Configration should be instance of [ChannelMediaRelayConfiguration]";var i=e.getSrcChannelMediaInfo(),n=e.getDestChannelMediaInfos();if(Object(W.isEmpty)(i))throw"srcChannelMediaInfo should not be empty";if(Object(W.isEmpty)(n)||0===n.length)throw"destChannelMediaInfos should not be empty";if(p.default.debug("[startChannelMediaRelay]: srcInfo: ",i," destInfo: ",n),!Object(o.is32Uint)(i.uid))throw"Invalid uid in srcChannelMediaInfo";if(!Object(W.isValidChannelName)(i.channelName))throw"Invalid channelName in srcChannelMediaInfo";if(i.token&&!Object(W.isValidToken)(i.token))throw"Invalid token in srcChannelMediaInfo";if(n.forEach((function(e){if(!Object(o.is32Uint)(e.uid))throw"Invalid uid in destChannelMediaInfo";if(!Object(W.isValidChannelName)(e.channelName))throw"Invalid channelName in destChannelMediaInfo";if(e.token&&!Object(W.isValidToken)(e.token))throw"Invalid token in destChannelMediaInfo"})),!this.worker)throw"startChannelMediaRelay should be used after join";this.worker.startChannelMediaRelay(e).then((function(){t&&t()})).catch((function(e){t&&t(e)}))}},{key:"updateChannelMediaRelay",value:function(e,t){if(!(e instanceof C.ChannelMediaRelayConfiguration))throw"Configration should be instance of [ChannelMediaRelayConfiguration]";var i=e.getSrcChannelMediaInfo(),n=e.getDestChannelMediaInfos();if(Object(W.isEmpty)(i))throw"srcChannelMediaInfo should not be empty";if(Object(W.isEmpty)(n)||0===n.length)throw"destChannelMediaInfos should not be empty";if(p.default.debug("[updateChannelMediaRelay]: srcInfo: ",i," destInfo: ",n),!Object(o.is32Uint)(i.uid))throw"Invalid uid in srcChannelMediaInfo";if(!Object(W.isValidChannelName)(i.channelName))throw"Invalid channelName in srcChannelMediaInfo";if(i.token&&!Object(W.isValidToken)(i.token))throw"Invalid token in srcChannelMediaInfo";if(n.forEach((function(e){if(!Object(o.is32Uint)(e.uid))throw"Invalid uid in destChannelMediaInfo";if(!Object(W.isValidChannelName)(e.channelName))throw"Invalid channelName in destChannelMediaInfo";if(e.token&&!Object(W.isValidToken)(e.token))throw"Invalid token in destChannelMediaInfo"})),!this.worker)throw"updateChannelMediaRelay should be used after join";this.worker.updateChannelMediaRelay(e).then((function(){t&&t()})).catch((function(e){t&&t(e)}))}},{key:"stopChannelMediaRelay",value:function(e){p.default.debug("[stopChannelMediaRelay]"),this.worker.stopChannelMediaRelay().then((function(){e&&e()})).catch((function(t){e&&e(t)}))}}]),e}();i.d(t,"Client",(function(){return G})),i.d(t,"LOG",(function(){return p.default})),i.d(t,"Log",(function(){return p.Log})),i.d(t,"ChannelMediaRelayConfiguration",(function(){return C.ChannelMediaRelayConfiguration})),i.d(t,"SDK_VERSION",(function(){return u.SDK_VERSION}))}])})); //# sourceMappingURL=mini-app-sdk-production.js.map