module.exports = (function() {
var __MODS__ = {};
var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
__DEFINE__(1690447249538, function(require, module, exports) {
/*!
  * ar-rtm-sdk v1.0.11
  * (c) 2023 anyRTM SDK
  * @license MIT
  */
Object.defineProperty(exports,"__esModule",{value:!0});var e={VERSION:"1.0.11",GATEWAY_ADDRESS:"https://rtmgw.agrtc.cn",GATEWAY_CONNECT_TIMEOUT:3e3,GATEWAY_CONNECT_INTERVAL_TIMES:2e3,GATEWAY_RETRY_TIMEOUT:12e5,LOGIN_TIMEOUT:12e3},t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},t(e,r)};function r(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}var n=function(){return n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},n.apply(this,arguments)};function o(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{E(n.next(e))}catch(e){i(e)}}function a(e){try{E(n.throw(e))}catch(e){i(e)}}function E(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}E((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}}function s(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function E(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}var _,c=function(){function e(e){if(this._url="",this._wss=!0,this._port=443,this._timeout=6e4,"[object Object]"===Object.prototype.toString.call(e)){var t=e.url,r=e.wss,n=e.port,o=e.timeout;"string"==typeof t&&(this._url=t),"boolean"==typeof r&&(this._wss=r,this._port=r?443:80),"number"==typeof n&&(this._port=n),"number"==typeof o&&(this._timeout=o)}}return e.prototype.setRequestUrl=function(e){if("[object Object]"===Object.prototype.toString.call(e)){var t=e.url,r=e.wss,n=e.port;"string"==typeof t&&(this._url=t),"boolean"==typeof r&&(this._wss=r,this._port=r?443:80),"number"==typeof n&&(this._port=n)}},e.prototype.request=function(e,t,r){return this._sendUrlRequest(e,t,r)},e.prototype.post=function(e,t){return this.request(e,"POST",t)},e.prototype.get=function(e,t){return this.request(e,"GET",t)},e.prototype._sendUrlRequest=function(e,t,r,n){var o=this;return void 0===n&&(n=!0),new Promise((function(i,s){if(""!==o._url){var a=o._url;e&&(a=o._url+e);try{wx.getSystemInfo(),wx.request({url:a,timeout:o._timeout,method:t,header:{"content-type":"application/json"},data:r,complete:function(e){var t=e.statusCode;i(200===t?e.data:{code:-1,msg:e.errMsg})}})}catch(e){var E=new XMLHttpRequest,_=function(){200===E.status?i(JSON.parse(E.responseText)):s("NETWORK_RESPONSE_ERROR")};n&&(E.onreadystatechange=function(){4===E.readyState&&_()}),E.open(t,a,n),E.onerror=function(e){s("NETWORK_ERROR")},E.ontimeout=function(){s("NETWORK_TIMEOUT")},E.send(JSON.stringify(r)),n||_()}}else s("NO_REQUEST_URL")}))},e}(),u={generateLowCaseString:function(e){void 0===e&&(e=7);var t=Math.random().toString(16).substr(2,e).toLowerCase();return t.length===e?t:t+this.generateLowCaseString(e-t.length)},generateUpperCaseString:function(e){return this.generateLowCaseString(e||32).toUpperCase()},getByteLength:function(e){for(var t=0,r=0;r<e.length;r++)e.charCodeAt(r)>255?t+=2:t++;return t}},R=function(e,t){var r="YYYY-MM-DD hh:mm:ss";if("number"!=typeof e)throw new Error("[timesToDate]: timestamp must be number");t&&"string"==typeof t&&(r=t);var n=e||Date.now(),o=new Date(n)||new Date(n),i=o.getFullYear(),s=o.getMonth()+1,a=o.getDate(),E=o.getHours(),_=o.getMinutes(),c=o.getSeconds();return r.indexOf("YYYY")>-1&&(r=r.replace("YYYY",(function(){return""+i}))),r.indexOf("MM")>-1?r=r.replace("MM",(function(){return s<10?"0"+s:""+s})):r.indexOf("M")>-1&&(r=r.replace("M",(function(){return""+s}))),r.indexOf("DD")>-1?r=r.replace("DD",(function(){return a<10?"0"+a:""+a})):r.indexOf("D")>-1&&(r=r.replace("D",(function(){return""+a}))),r.indexOf("hh")>-1?r=r.replace("hh",(function(){return E<10?"0"+E:""+E})):r.indexOf("h")>-1&&(r=r.replace("h",(function(){return""+E}))),r.indexOf("mm")>-1?r=r.replace("mm",(function(){return _<10?"0"+_:""+_})):r.indexOf("m")>-1&&(r=r.replace("m",(function(){return""+_}))),r.indexOf("ss")>-1?r=r.replace("ss",(function(){return c<10?"0"+c:""+c})):r.indexOf("s")>-1&&(r=r.replace("s",(function(){return""+c}))),r},l=function(e){void 0===e&&(e=13),e>20&&(e=20);var t=Math.ceil(Math.random()*Math.pow(10,e));return t<Math.pow(10,e-1)?l(e):t},d=function(e,t){var r=this;this.onFinally=t,this.promise=new Promise((function(t,n){return o(r,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return this.resolve=t,this.reject=n,e?[4,e(t,n)]:[3,2];case 1:r.sent(),r.label=2;case 2:return[2]}}))}))})).finally((function(){var e;return null===(e=r.onFinally)||void 0===e?void 0:e.call(r)}))};!function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARNING=2]="WARNING",e[e.ERROR=3]="ERROR",e[e.NONE=4]="NONE"}(_||(_={}));var N,I=new(function(){function e(){this.logPrefix="SupLogger",this.logLevel=_.NONE,this.uploadServeTranslators=[],this.DEBUG=_.DEBUG,this.INFO=_.INFO,this.WARNING=_.WARNING,this.ERROR=_.ERROR,this.NONE=_.NONE}return e.prototype.use=function(e){"function"==typeof e&&this.uploadServeTranslators.push((function(t,r){e(t,r)}))},e.prototype.setLogLevel=function(e,t){t&&(this.logPrefix=t),"number"==typeof e&&e>-1&&e<5&&(this.logLevel=e)},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!(this.logLevel>_.ERROR&&this.logLevel!==_.NONE||this.logLevel===_.NONE)){var r=e,n=Date.now();r.unshift("["+R(n,"hh:mm:ss:ms")+"] %c"+this.logPrefix+" [ERROR]:%c","color: #b00020; font-weight: bold;","color: #dc3545;"),this.uploadServeTranslators.length>0?this.uploadServeTranslators.map((function(e){e({type:"error",params:r,timestamp:n},(function(){console.error.apply(console,r)}))})):console.error.apply(console,r)}},e.prototype.warning=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!(this.logLevel>_.WARNING&&this.logLevel!==_.NONE||this.logLevel===_.NONE)){var r=e,n=Date.now();r.unshift("["+R(n,"hh:mm:ss:ms")+"] %c"+this.logPrefix+" [WARNING]:","color: #ffc107; font-weight: bold;"),this.uploadServeTranslators.length>0?this.uploadServeTranslators.map((function(e){e({type:"warning",params:r,timestamp:n},(function(){console.warn.apply(console,r)}))})):console.warn.apply(console,r)}},e.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!(this.logLevel>_.INFO&&this.logLevel!==_.NONE||this.logLevel===_.NONE)){var r=e,n=Date.now();r.unshift("["+R(n,"hh:mm:ss:ms")+"] %c"+this.logPrefix+" [INFO]:","color:  #007bff; font-weight: bold;"),this.uploadServeTranslators.length>0?this.uploadServeTranslators.map((function(e){e({type:"info",params:r,timestamp:n},(function(){console.log.apply(console,r)}))})):console.log.apply(console,r)}},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(!(this.logLevel>_.DEBUG&&this.logLevel!==_.NONE||this.logLevel===_.NONE)){var r=e,n=Date.now();r.unshift("["+R(n,"hh:mm:ss.ms")+"] %c"+this.logPrefix+" [DEBUG]:","color:#6facff;"),this.uploadServeTranslators.length>0?this.uploadServeTranslators.map((function(e){e({type:"debug",params:r,timestamp:n},(function(){console.log.apply(console,r)}))})):console.log.apply(console,r)}},e}());I.setLogLevel(I.DEBUG,"ar-rtm-sdk"),function(e){e.INVALID_PARAMS="INVALID_PARAMS",e.DEVELOPER_INVALID="DEVELOPER_INVALID",e.UID_BANNED="UID_BANNED",e.IP_BANNED="IP_BANNED",e.CHANNEL_BANNED="CHANNEL_BANNED",e.APPID_INVALID="APPID_INVALID",e.SERVER_NOT_OPEN="SERVER_NOT_OPEN",e.TOKEN_EXPIRED="TOKEN_EXPIRED",e.TOKEN_INVALID="TOKEN_INVALID",e.UNKNOWN="UNKNOWN",e.TIMEOUT="TIMEOUT"}(N||(N={}));var T=function(){function t(){this._urls=[],this._urlSuffix="/arapi/v1?action=",this._appid="",this._sessionId="",this.msgSuffix="/arapi/v1/artmgw/",this._urls=[e.GATEWAY_ADDRESS],this._urlSuffix="/arapi/v1?action="}return t.prototype.joinGateway=function(t,r){var s=this;void 0===t&&(t={});var a=this;return new Promise((function(E,_){var u=a._urlSuffix.concat("wrtm_gateway"),R=function(){return o(s,void 0,void 0,(function(){var o,s,l,d,T,O;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,Promise.race(this._urls.map((function(r){return new c({url:r,timeout:e.GATEWAY_CONNECT_TIMEOUT}).post(u,n({},t))})))];case 1:if(o=i.sent())if(0===(s=o.code))l=o.sessionid,d=t.appid,a._sessionId=l,a._appid=d,E(o);else{if(-1===s||1===s)throw new Error("NETWORK_TIMEOUT");_(-4===s||-7===s||3===s?N.INVALID_PARAMS:13===s?N.DEVELOPER_INVALID:14===s?N.UID_BANNED:15===s?N.IP_BANNED:16===s?N.CHANNEL_BANNED:101===s||4===s?N.APPID_INVALID:102===s?N.SERVER_NOT_OPEN:109===s||6===s?N.TOKEN_EXPIRED:110===s||5===s?N.TOKEN_INVALID:"Error Code "+s+".")}return[3,3];case 2:return T=i.sent(),"NETWORK_ERROR"===(O=T)||"NETWORK_TIMEOUT"===O||"NETWORK_RESPONSE_ERROR"===O?(I.warning("reconnect gateway server, reason: "+O),Date.now()>r+e.LOGIN_TIMEOUT?(_(N.TIMEOUT),[2]):(setTimeout((function(){R()}),e.GATEWAY_CONNECT_INTERVAL_TIMES),[2])):(I.debug("XMLHttpRequest abort error ",O),_(N.UNKNOWN),[3,3]);case 3:return[2]}}))}))};R()}))},t.prototype.getChanHistoryMsg=function(t){return o(this,void 0,void 0,(function(){var r,s=this;return i(this,(function(a){return r=this,[2,new Promise((function(a,E){return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return o=r.msgSuffix.concat("getChanHistoryMsg"),[4,new c({url:e.GATEWAY_ADDRESS,timeout:e.GATEWAY_CONNECT_TIMEOUT}).post(o,n(n({},t),{sessId:r._sessionId,appId:r._appid})).then((function(e){return e}))];case 1:return s=i.sent(),a(s),[2]}}))}))}))]}))}))},t.prototype.getOfflineMsg=function(t){return o(this,void 0,void 0,(function(){var r,s=this;return i(this,(function(a){return r=this,[2,new Promise((function(a,E){return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return o=r.msgSuffix.concat("getOfflineMsg"),[4,new c({url:e.GATEWAY_ADDRESS,timeout:e.GATEWAY_CONNECT_TIMEOUT}).post(o,n(n({},t),{sessId:r._sessionId,appId:r._appid})).then((function(e){return e}))];case 1:return s=i.sent(),a(s),[2]}}))}))}))]}))}))},t.prototype.getP2PHistoryMsg=function(t){var r=this,s=this;return new Promise((function(a,E){return o(r,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return r=s.msgSuffix.concat("getP2PHistoryMsg"),[4,new c({url:e.GATEWAY_ADDRESS,timeout:e.GATEWAY_CONNECT_TIMEOUT}).post(r,n(n({},t),{sessId:s._sessionId,appId:s._appid})).then((function(e){return e}))];case 1:return o=i.sent(),a(o),[2]}}))}))}))},t}(),O=function(){function e(e){if(this._websocket=null,this._url="",this._wss=!0,this._port=443,this._listenCallback=[],this.onclose=function(){},this.onerror=function(){},this.onmessage=function(){},e&&"[object Object]"===Object.prototype.toString.call(e)){var t=e.url,r=e.wss,n=e.port;t&&(this._url=t),"boolean"==typeof r&&(this._wss=r),n&&(this._port=n)}}return Object.defineProperty(e.prototype,"connectState",{get:function(){return this._websocket?this._websocket.readyState:WebSocket.CLOSED},enumerable:!1,configurable:!0}),e.prototype.open=function(e){var t=this;return new Promise((function(r,n){if(t._websocket&&I.error("ERROR: SignalingChannel has already opened."),e&&"[object Object]"===Object.prototype.toString.call(e)){var o=e.url,i=e.wss,s=e.port;o&&(t._url=o),"boolean"==typeof i&&(t._wss=i),s&&(t._port=s)}var a=(t._wss?"wss":"ws")+"://"+t._url+":"+t._port;I.debug("SignalingChannel start connect, url "+a+".");var E=function(){I.debug("Signaling channel opened."),t._websocket.onerror=function(e){I.debug("Signaling channel error."),t.onerror(e)},t._websocket.onclose=function(e){I.debug("Channel closed with code: "+e.code+" reason: "+e.reason),t._websocket=null,t.onclose(e)},r()},_=function(e){t._listenCallback.forEach((function(t){t(e)})),t.onmessage(e)},c=function(e){n(Error("WebSocket error."))};try{wx.getSystemInfo(),t._websocket=wx.connectSocket({url:a,complete:function(){}}),t._websocket.onOpen(E),t._websocket.onMessage(_),t._websocket.onError(c)}catch(e){try{t._websocket=new WebSocket(a),t._websocket.onopen=E,t._websocket.onmessage=_,t._websocket.onerror=c}catch(e){t._websocket=null}}}))},e.prototype.close=function(){this._websocket&&(this._websocket.close(),this._websocket=null)},e.prototype.send=function(e){if("object"!=typeof e)return I.error("signal channel msg must be object."),!1;if(this._websocket)try{return wx.getSystemInfo(),this._websocket.send({data:JSON.stringify(e)})}catch(t){1===this._websocket.readyState&&this._websocket.send(JSON.stringify(e))}},e.prototype.addMessageEventListener=function(e,t){this._websocket&&this._listenCallback.push(e)},e.prototype.removeMessageEventListener=function(e,t){if(this._websocket)for(var r=this._listenCallback.length-1;r>-1;r--)this._listenCallback[r]===e&&this._listenCallback.splice(r,1)},e.prototype.clear=function(){this.close(),this.onerror=function(){},this.onclose=function(){},this.onmessage=function(){},this.addMessageEventListener=function(){},this.removeMessageEventListener=function(){}},e}(),p=function(e){function t(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var o=e.apply(this,E([],a(r)))||this;o.name="RTMException",o.code=t;var i="Error Code "+t+" - ";return o.message=r[0]?i.concat(r[0]):i,o.data=r[1]?r[1]:{},o}return r(t,e),t}(Error),C=function(e){function t(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var o=e.apply(this,E([t],a(r)))||this;return o.name="RtmInvalidArgumentError",o}return r(t,e),t}(p);!function(e){function t(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var o=e.apply(this,E([t],a(r)))||this;return o.name="RtmUnauthenticatedError",o}r(t,e)}(p);var v=function(e){return e.then((function(e){return[null,e]})).catch((function(e){return[e]}))},h={},A=function(){return function(){var e,t,r=void 0,n=navigator.userAgent,o=n.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i)||[];"Chrome"===o[1]&&null!=(r=n.match(/(OPR(?=\/))\/?(\d+)/i))&&(o=r),"Safari"===o[1]&&null!=(r=n.match(/version\/(\d+)/i))&&(o[2]=r[1]),~n.toLowerCase().indexOf("qqbrowser")&&null!=(r=n.match(/(qqbrowser(?=\/))\/?(\d+)/i))&&(o=r),~n.toLowerCase().indexOf("micromessenger")&&null!=(r=n.match(/(micromessenger(?=\/))\/?(\d+)/i))&&(o=r),~n.toLowerCase().indexOf("edge")&&null!=(r=n.match(/(edge(?=\/))\/?(\d+)/i))&&(o=r),~n.toLowerCase().indexOf("trident")&&null!=(r=/\brv[ :]+(\d+)/g.exec(n)||[])&&(o=[null,"IE",r[1]]);var i=void 0;try{for(var a=s([{s:"Windows 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:"Windows 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:"Windows 8",r:/(Windows 8|Windows NT 6.2)/},{s:"Windows 7",r:/(Windows 7|Windows NT 6.1)/},{s:"Windows Vista",r:/Windows NT 6.0/},{s:"Windows Server 2003",r:/Windows NT 5.2/},{s:"Windows XP",r:/(Windows NT 5.1|Windows XP)/},{s:"Windows 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:"Windows ME",r:/(Win 9x 4.90|Windows ME)/},{s:"Windows 98",r:/(Windows 98|Win98)/},{s:"Windows 95",r:/(Windows 95|Win95|Windows_95)/},{s:"Windows NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:"Windows CE",r:/Windows CE/},{s:"Windows 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Linux",r:/(Linux|X11)/},{s:"iOS",r:/(iPhone|iPad|iPod)/},{s:"Mac OS X",r:/Mac OS X/},{s:"Mac OS",r:/(MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}]),E=a.next();!E.done;E=a.next()){var _=E.value;if(_.r.test(navigator.userAgent)){i=_.s;break}}}catch(t){e={error:t}}finally{try{E&&!E.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}return{name:o[1],version:o[2],os:i}}()},S=function(){return A().os};h.getBrowserInfo=A,h.getBrowserOS=S,h.isChrome=function(){var e=A();return e.name&&"Chrome"===e.name},h.isSafari=function(){var e=A();return e.name&&"Safari"===e.name},h.isEdge=function(){var e=A();return e.name&&"Edge"===e.name},h.isFireFox=function(){var e=A();return e.name&&"Firefox"===e.name},h.isOpera=function(){var e=A();return e.name&&"OPR"===e.name},h.isQQBrowser=function(){var e=A();return e.name&&"QQBrowser"===e.name},h.isWeChatBrowser=function(){var e=A();return e.name&&"MicroMessenger"===e.name},h.isSupportedPC=function(){var e=S();return"Linux"===e||"Mac OS X"===e||"Mac OS"===e||-1!==e.indexOf("Windows")},h.isSupportedMobile=function(){var e=S();return"Android"===e||"iOS"===e},h.getBrowserVersion=function(){return A().version},h.isChromeKernel=function(){return!!navigator.userAgent.match(/chrome\/[\d]./i)},h.isLegacyChrome=function(){return window.navigator.appVersion&&null!==window.navigator.appVersion.match(/Chrome\/([\w\W]*?)\./)&&window.navigator.appVersion.match(/Chrome\/([\w\W]*?)\./)[1]<=35};var f=!1;try{wx.getSystemInfo()}catch(e){f=h.isChrome()&&h.getBrowserVersion()>=87}var m,L,g,y,U,M,b,w,D,G,P,x,B,F,V,J,W,k,Y,H,K,j,Q,X,z,$,Z=function(e){function t(t){var r=e.call(this)||this;r._cmdEncrypt=!1,r._appId="",r._serverIsWss=!0,r._serverUrl="",r._serverPort=0,r._userId=null,r._connectTimeout=null,r._keepAliveTimeout=null,r._keepALiveInterval=null,r._keepALiveIntervalTime=1e4,r._sendMsgTimeOutInterval=1e4,r._revState="DISCONNECTED",r._curState="DISCONNECTED",r.handleMediaServerEvents=function(){};var n=r;return t&&t.appId&&(n._appId=t.appId),r}return r(t,e),t.prototype.init=function(e){var t=this,r=e.appId,n=e.isWss,o=e.url,i=e.port;t._appId=r,"boolean"==typeof n&&(t._serverIsWss=n),o&&(t._serverUrl=o),i&&(t._serverPort=i)},t.prototype.setAppInfo=function(e){var t=e.appId;this._appId=t},t.prototype.configServer=function(e,t,r){var n=this;n._serverIsWss=e,n._serverUrl=t,n._serverPort=r},t.prototype.connectServer=function(){var e=this,t=this;return new Promise((function(r,n){return o(e,void 0,void 0,(function(){var e,o,s,E=this;return i(this,(function(i){switch(i.label){case 0:return t._emitConnectionState("CONNECTING"),t._setConnectTimeout(),[4,v(t.open({url:t._serverUrl,wss:t._serverIsWss,port:t._serverPort}))];case 1:return e=a.apply(void 0,[i.sent(),2]),(o=e[0])?(t._clearConnectTimeout(),n(o)):(s=(t._serverIsWss?"wss":"ws")+"://"+t._serverUrl+":"+t._serverPort,I.debug("[ws-client] websocket opened: "+s),t._clearConnectTimeout(),t._emitConnectionState("CONNECTED"),t.onmessage=function(e){var r=e.data,n=JSON.parse(r),o=n.Cmd;n.Encrypt;var i=n.Content,s=JSON.parse(i);switch(o){case"KeepAlive":t._clearKeepALiveTimeout();break;case"ReqKeepAlive":E.doKeepAlive();break;case"Login":!f&&t._startKeepAlive();break;default:t.handleMediaServerEvents&&t.handleMediaServerEvents(o,s)}},t.onerror=function(e){I.error("WebSocket with some error ",e)},t.onclose=function(e){var r=e.code,n=e.reason;switch(I.info("serve disconnected...",r),t._clearConnectTimeout(),t._stopKeepAlive(),t._clearKeepALiveTimeout(),r){case 1e3:case 1005:t._emitConnectionState("DISCONNECTED","LEAVE");break;case 3001:t._emitConnectionState("RECONNECTING","NETWORK_ERROR");break;default:I.debug("media ws serve disconnected with code "+r+", reason "+n),"RECONNECTING"!==t._curState&&t._emitConnectionState("RECONNECTING","SERVER_ERROR")}t.clear()},r()),[2]}}))}))}))},t.prototype.doKeepAlive=function(){var e=this,t={Cmd:"KeepAlive"};t.Encrypt=this._cmdEncrypt,t.Content=JSON.stringify({time:Date.now().toString()}),this.send(t),!e._keepAliveTimeout&&(e._keepAliveTimeout=setTimeout((function(){e._stopKeepAlive(),e._clearKeepALiveTimeout(),e.clear(),e._emitConnectionState("RECONNECTING","KEEP_A_LIVE_TIME_OUT")}),2*e._keepALiveIntervalTime))},t.prototype.doOnline=function(e){var t=this;return new Promise((function(r,o){var i=function(e){var n=e.data,s=JSON.parse(n),a=s.Cmd;s.Encrypt;var E=s.Content,_=JSON.parse(E);if("Login"===a){t.removeMessageEventListener(i);var c=_.Code;if(0===c){var u=_.UserId;t._userId=u,r(u)}else I.error("user online failure, code => ",c),o(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_UNKNOWN,"Error Code "+c))}};t.addMessageEventListener(i);var s={Cmd:"Login"};s.AppId=t._appId,s.Encrypt=t._cmdEncrypt;var a=n({},e);f&&(a.SvrKeepAlive=!0),s.Content=JSON.stringify(a),t.send(s)}))},t.prototype.doOffline=function(){var e=this;return new Promise((function(t,r){var n=function(o){var i=o.data,s=JSON.parse(i),a=s.Cmd;s.Encrypt;var E=s.Content,_=JSON.parse(E);if("Logout"===a){e.removeMessageEventListener(n);var c=_.Code;0===c?t():r(c)}};e.addMessageEventListener(n);var o={Cmd:"Logout"};o.Encrypt=e._cmdEncrypt,o.Content="",e.send(o)}))},t.prototype.doQueryOnlineStatus=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(e){var n=e.data,s=JSON.parse(n),a=s.Cmd;s.Encrypt;var E=s.Content,_=JSON.parse(E);if("QueryOnlineStatus"===a){var c=_.MsgId,u=_.Status;c===o&&(t.removeMessageEventListener(i),r(u))}};t.addMessageEventListener(i);var s={Cmd:"QueryOnlineStatus"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify({MsgId:o,UserIds:JSON.stringify(e)}),t.send(s)}))},t.prototype.doQueryOnlineSubStatus=function(){var e=this;return new Promise((function(t,r){var n=l(),o=function(r){var i=r.data,s=JSON.parse(i),a=s.Cmd;s.Encrypt;var E=s.Content,_=JSON.parse(E);if("QueryOnlineSubStatus"===a){var c=_.MsgId,u=_.Status;c===n&&(e.removeMessageEventListener(o),t(u))}};e.addMessageEventListener(o);var i={Cmd:"QueryOnlineSubStatus"};i.Encrypt=e._cmdEncrypt,i.Content=JSON.stringify({MsgId:n}),e.send(i)}))},t.prototype.doSubscribeOnlineStatus=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(e){var s=e.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("SubscribeOnlineStatus"===E){var u=c.MsgId,R=c.Code;u===o&&(t.removeMessageEventListener(i),0===R?r():n(R))}};t.addMessageEventListener(i);var s={Cmd:"SubscribeOnlineStatus"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify({MsgId:o,UserIds:JSON.stringify(e)}),t.send(s)}))},t.prototype.doUnSubscribeOnlineStatus=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(e){var s=e.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("UnSubscribeOnlineStatus"===E){var u=c.MsgId,R=c.Code;u===o&&(t.removeMessageEventListener(i),0===R?r():n(R))}};t.addMessageEventListener(i);var s={Cmd:"UnSubscribeOnlineStatus"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify({MsgId:o,UserIds:JSON.stringify(e)}),t.send(s)}))},t.prototype.doSendMsgToPeer=function(e,t,r,n,o){var i=this;void 0===n&&(n=!1),void 0===o&&(o=!1);var s=this;return new Promise((function(a,E){if(s._websocket&&1===s._websocket.readyState){var _=l(),c=setTimeout((function(){}),0),u=function(e){var t=e.data,r=JSON.parse(t),n=r.Cmd;r.Encrypt;var o=r.Content,i=JSON.parse(o);if("MsgStatus"===n){var E=i.MsgId,R=i.Status;E===_&&(c&&clearTimeout(c),0===R?(s.removeMessageEventListener(u),a(!1)):(s.removeMessageEventListener(u),a(!0)))}};s.addMessageEventListener(u);var R={Cmd:"SendMsgToPeer"};R.Encrypt=s._cmdEncrypt,R.Content=JSON.stringify(Object.assign({MsgId:_,FromUId:s._userId,ToUId:t,MsgType:e,MsgBody:r,OfflineMsg:n,HistoryMsg:o,Desc:""})),s.send(R),c=setTimeout((function(){s.removeMessageEventListener(u),c&&clearTimeout(c),E("TimeOut")}),i._sendMsgTimeOutInterval)}else E()}))},t.prototype.doRecvMsgFromPeerAck=function(e,t){var r=this;if(!r._websocket||1!==r._websocket.readyState)return!1;var n={Cmd:"RecvMsgFromPeerAck"};n.Encrypt=r._cmdEncrypt,n.Content=JSON.stringify(Object.assign({MsgId:e,FromUId:t})),r.send(n)},t.prototype.doAddOrUpdateUserAttributes=function(e,t){void 0===t&&(t=!1);var r=this;return new Promise((function(n,o){var i=l(),s=function(e){var t=e.data,a=JSON.parse(t),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_),u=c.MsgId;if("AddOrUpdateUserAttributes"===E&&u===i){var R=c.Code;r.removeMessageEventListener(s),0===R?n():o(R)}};r.addMessageEventListener(s);var a={Cmd:"AddOrUpdateUserAttributes"};a.Encrypt=r._cmdEncrypt,a.Content=JSON.stringify(Object.assign({MsgId:i,SetLocal:t,Attributes:JSON.stringify(e)})),r.send(a)}))},t.prototype.doDeleteUserAttributes=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(e){var s=e.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("DeleteUserAttributes"===E){var u=c.Code,R=c.MsgId;o===R&&(t.removeMessageEventListener(i),0===u?r(!0):n(u))}};t.addMessageEventListener(i);var s={Cmd:"DeleteUserAttributes"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify(Object.assign({MsgId:o,Keys:JSON.stringify(e)})),t.send(s)}))},t.prototype.doClearUserAttributes=function(){var e=this;return new Promise((function(t,r){var n=l(),o=function(i){var s=i.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("ClearUserAttributes"===E){var u=c.Code;c.MsgId===n&&(e.removeMessageEventListener(o),0===u?t(!0):r(u))}};e.addMessageEventListener(o);var i={Cmd:"ClearUserAttributes"};i.Encrypt=e._cmdEncrypt,i.Content=JSON.stringify(Object.assign({MsgId:n})),e.send(i)}))},t.prototype.doGetUserAttributes=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(n){var s=n.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("QueryAttribKeys"===E){var u=c.QueryUserId,R=c.MsgId,l=c.Attribs;u===e&&o===R&&(t.removeMessageEventListener(i),r(JSON.parse(""!==l?l:[])))}};t.addMessageEventListener(i);var s={Cmd:"GetUserAttributes"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify(Object.assign({MsgId:o,UserId:e})),t.send(s)}))},t.prototype.doGetUserAttributesByKeys=function(e,t){var r=this;return new Promise((function(n,o){var i=l(),s=function(t){var o=t.data,a=JSON.parse(o),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("QueryAttribKeys"===E){var u=c.QueryUserId,R=c.MsgId,l=c.Attribs;u===e&&R===i&&(r.removeMessageEventListener(s),n(JSON.parse(l)))}};r.addMessageEventListener(s);var a={Cmd:"GetUserAttributes"};a.Encrypt=r._cmdEncrypt,a.Content=JSON.stringify(Object.assign({MsgId:i,UserId:e,Keys:t})),r.send(a)}))},t.prototype.doJoinChannel=function(e){var t=this;return new Promise((function(r,n){var o=function(i){var s=i.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("JoinChannel"===E){var u=c.Code,R=c.ChanId;e===R&&(t.removeMessageEventListener(o),0===u?r():n(u))}};t.addMessageEventListener(o);var i={Cmd:"JoinChannel"};i.Encrypt=t._cmdEncrypt,i.Content=JSON.stringify(Object.assign({ChanId:e})),t.send(i)}))},t.prototype.doSendChannelMsg=function(e,t,r,n){void 0===n&&(n=!1);var o=this;return new Promise((function(i,s){var a=l(),E=function(e){var r=e.data,n=JSON.parse(r),_=n.Cmd;n.Encrypt;var c=n.Content,u=JSON.parse(c);if("SendChannelMsg"===_){var R=u.Code,l=u.ChanId,d=u.MsgId;l===t&&a===d&&(o.removeMessageEventListener(E),0===R?i():s(R))}};o.addMessageEventListener(E);var _={Cmd:"SendChannelMsg"};_.Encrypt=o._cmdEncrypt,_.Content=JSON.stringify(Object.assign({ChanId:t,FromUId:o._userId,MsgId:a,MsgType:e,MsgBody:r,HistoryMsg:n,Desc:""})),o.send(_)}))},t.prototype.doLeaveChannel=function(e){var t=this;return new Promise((function(r,n){var o=function(i){var s=i.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("LeaveChannel"===E){var u=c.Code,R=c.ChanId;e===R&&(t.removeMessageEventListener(o),0===u?r():n(u))}};t.addMessageEventListener(o);var i={Cmd:"LeaveChannel"};i.Encrypt=t._cmdEncrypt,i.Content=JSON.stringify(Object.assign({ChanId:e})),t.send(i)}))},t.prototype.doAddOrUpdateChanAttributes=function(e){var t=this,r=e.channelId,n=e.attributes,o=e.notify,i=void 0!==o&&o,s=e.isSet,a=void 0!==s&&s;return new Promise((function(e,o){var s=l(),E=function(n){var i=n.data,a=JSON.parse(i),_=a.Cmd;a.Encrypt;var c=a.Content,u=JSON.parse(c);if("AddOrUpdateChanAttributes"===_){var R=u.Code,l=u.MsgId;u.ChanId===r&&s===l&&(t.removeMessageEventListener(E),0===R?e():o(R))}};t.addMessageEventListener(E);var _={Cmd:"AddOrUpdateChanAttributes"};_.Encrypt=t._cmdEncrypt,_.Content=JSON.stringify(Object.assign({MsgId:s,SetChan:a,ChanId:r,Attributes:JSON.stringify(n),Notify:i})),t.send(_)}))},t.prototype.doDeleteChanAttributes=function(e){var t=this,r=e.channelId,n=e.attributeKeys,o=e.notify;return new Promise((function(e,i){var s=l(),a=function(r){var n=r.data,o=JSON.parse(n),E=o.Cmd;o.Encrypt;var _=o.Content,c=JSON.parse(_);if("DeleteChanAttributes"===E){var u=c.Code,R=c.MsgId;c.ChanId,R===s&&(t.removeMessageEventListener(a),0===u?e():i(u))}};t.addMessageEventListener(a);var E={Cmd:"DeleteChanAttributes"};E.Encrypt=t._cmdEncrypt,E.Content=JSON.stringify(Object.assign({MsgId:s,ChanId:r,Keys:JSON.stringify(n),Notify:o})),t.send(E)}))},t.prototype.doGetChanAttributes=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(s){var a=s.data,E=JSON.parse(a),_=E.Cmd;E.Encrypt;var c=E.Content,u=JSON.parse(c);if("GetChanAttributes"===_){var R=u.Code,l=u.MsgId,d=u.ChanId,N=u.Attributes;e===d&&o===l&&(t.removeMessageEventListener(i),0===R?r(JSON.parse(""===N?"[]":N)):n(R))}};t.addMessageEventListener(i);var s={Cmd:"GetChanAttributes"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify(Object.assign({MsgId:o,ChanId:e})),t.send(s)}))},t.prototype.doGetChanAttributesByKeys=function(e,t){var r=this;return new Promise((function(n,o){var i=l(),s=function(t){var a=t.data,E=JSON.parse(a),_=E.Cmd;E.Encrypt;var c=E.Content,u=JSON.parse(c);if("GetChanAttributesByKeys"===_){var R=u.Code,l=u.MsgId,d=u.ChanId,N=u.Attributes;e===d&&i===l&&(r.removeMessageEventListener(s),0===R?n(""!==N?JSON.parse(N):[]):o(R))}};r.addMessageEventListener(s);var a={Cmd:"GetChanAttributesByKeys"};a.Encrypt=r._cmdEncrypt,a.Content=JSON.stringify(Object.assign({MsgId:i,ChanId:e,Keys:JSON.stringify(t)})),r.send(a)}))},t.prototype.doClearChanAttributes=function(e){var t=this,r=e.channelId,n=e.notify;return new Promise((function(e,o){var i=l(),s=function(r){var n=r.data,a=JSON.parse(n),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("ClearChanAttributes"===E){var u=c.Code;c.MsgId===i&&(t.removeMessageEventListener(s),0===u?e(!0):o(u))}};t.addMessageEventListener(s);var a={Cmd:"ClearChanAttributes"};a.Encrypt=t._cmdEncrypt,a.Content=JSON.stringify(Object.assign({MsgId:i,ChanId:r,Notify:n})),t.send(a)}))},t.prototype.doGetChanMemberSize=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(e){var s=e.data,a=JSON.parse(s),E=a.Cmd;a.Encrypt;var _=a.Content,c=JSON.parse(_);if("GetChanMemberSize"===E){var u=c.Code,R=c.ChanMemSize;c.MsgId===o&&(t.removeMessageEventListener(i),0===u?r(R):n(u))}};t.addMessageEventListener(i);var s={Cmd:"GetChanMemberSize"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify(Object.assign({MsgId:o,ChanIds:JSON.stringify(e)})),t.send(s)}))},t.prototype.doGetChanMembers=function(e){var t=this;return new Promise((function(r,n){var o=l(),i=function(s){var a=s.data,E=JSON.parse(a),_=E.Cmd;E.Encrypt;var c=E.Content,u=JSON.parse(c);if("GetChanMembers"===_){var R=u.Code,l=u.MsgId,d=u.Members,N=u.ChanId;e===N&&o===l&&(t.removeMessageEventListener(i),0===R?r(d):n(R))}};t.addMessageEventListener(i);var s={Cmd:"GetChanMembers"};s.Encrypt=t._cmdEncrypt,s.Content=JSON.stringify(Object.assign({MsgId:o,ChanId:e})),t.send(s)}))},t.prototype.doMakeCall=function(e,t,r){var n=this,o={Cmd:"MakeCall"};o.Encrypt=n._cmdEncrypt,o.Content=JSON.stringify(Object.assign({CallId:e,FromUId:n._userId,ToUId:t,Content:r})),n.send(o)},t.prototype.doCancelCall=function(e,t,r,n){void 0===r&&(r=""),void 0===n&&(n="");var o=this;return new Promise((function(i,s){var a=function(r){var n=r.data,E=JSON.parse(n),_=E.Cmd;E.Encrypt;var c=E.Content,u=JSON.parse(c);if("cancelCallAck"===_){var R=u.Code,l=u.CallId,d=u.FromUId,N=u.ToUId;l===e&&d===o._userId&&N===t&&(o.removeMessageEventListener(a),0===R?i():s(R))}};o.addMessageEventListener(a);var E={Cmd:"CancelCall"};E.Encrypt=o._cmdEncrypt,E.Content=JSON.stringify(Object.assign({CallId:e,FromUId:o._userId,ToUId:t,Reason:r,Content:n})),o.send(E)}))},t.prototype.doAcceptCall=function(e,t,r){var n=this,o={Cmd:"AcceptCall"};o.Encrypt=n._cmdEncrypt,o.Content=JSON.stringify(Object.assign({CallId:e,FromUId:n._userId,ToUId:t,Response:r})),n.send(o)},t.prototype.doRefuseCall=function(e,t,r){var n=this,o={Cmd:"RejectCall"};o.Encrypt=n._cmdEncrypt,o.Content=JSON.stringify(Object.assign({CallId:e,FromUId:n._userId,ToUId:t,Response:r})),n.send(o)},t.prototype.doReNewToken=function(e){var t={Cmd:"RenewAcsToken"};t.Content=JSON.stringify({AcsToken:e}),this.send(t)},t.prototype.disconnectServer=function(e){var t=this;if(t._stopKeepAlive(),t._clearKeepALiveTimeout(),t.clear(),e)switch(e){case"UID_BANNED":t._emitConnectionState("DISCONNECTED","UID_BANNED");break;case"TOKEN_INVALID":t._emitConnectionState("DISCONNECTED","TOKEN_INVALID")}else t._emitConnectionState("DISCONNECTED","LEAVE")},t.prototype._setConnectTimeout=function(){var e=this;e._clearConnectTimeout(),e._connectTimeout=setTimeout((function(){e._emitConnectionState("DISCONNECTING","NETWORK_ERROR")}),1e4)},t.prototype._startKeepAlive=function(){var e=this;e._stopKeepAlive(),e.doKeepAlive(),e._keepALiveInterval=setInterval((function(){e.doKeepAlive()}),e._keepALiveIntervalTime)},t.prototype._stopKeepAlive=function(){var e=this;e._keepALiveInterval&&(clearInterval(e._keepALiveInterval),e._keepALiveInterval=null)},t.prototype._clearConnectTimeout=function(){var e=this;e._connectTimeout&&(clearTimeout(e._connectTimeout),e._connectTimeout=null)},t.prototype._clearKeepALiveTimeout=function(){var e=this;e._keepAliveTimeout&&(clearTimeout(e._keepAliveTimeout),e._keepAliveTimeout=null)},t.prototype._emitConnectionState=function(e,t){"DISCONNECTED"===e&&I.debug("[signal] media websocket closed, reason: "+t),this._revState=this._curState,this._curState=e,this.handleMediaServerEvents&&this.handleMediaServerEvents("connection-state-change",{curState:this._curState,revState:this._revState,reason:t})},t}(O),q=function(){function e(){this._events={}}return e.prototype.on=function(e,t){this._events[e]||(this._events[e]=[]);var r=this._events[e];-1===this._indexOfListener(r,t)&&r.push({listener:t,once:!1})},e.prototype.once=function(e,t){this._events[e]||(this._events[e]=[]);var r=this._events[e];-1===this._indexOfListener(r,t)&&r.push({listener:t,once:!0})},e.prototype.off=function(e,t){this._events[e]||(this._events[e]=[]);var r=this._events[e],n=this._indexOfListener(r,t);-1!==n&&r.splice(n,1)},e.prototype.removeAllListeners=function(e){e?delete this._events[e]:this._events={}},e.prototype.emit=function(e){for(var t,r,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];this._events[e]||(this._events[e]=[]);var i=this._events[e];try{for(var a=s(i),E=a.next();!E.done;E=a.next()){var _=E.value;_.once&&this.off(e,_.listener),_.listener.apply(this,n||[])}}catch(e){t={error:e}}finally{try{E&&!E.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}},e.prototype._indexOfListener=function(e,t){for(var r=e.length;r--;)if(e[r].listener===t)return r;return-1},e}();exports.RtmStatusCode=void 0,m=exports.RtmStatusCode||(exports.RtmStatusCode={}),(L=m.ConnectionChangeReason||(m.ConnectionChangeReason={})).BANNED_BY_SERVER="BANNED_BY_SERVER",L.INTERRUPTED="INTERRUPTED",L.LOGIN="LOGIN",L.LOGIN_FAILURE="LOGIN_FAILURE",L.LOGIN_SUCCESS="LOGIN_SUCCESS",L.LOGIN_TIMEOUT="LOGIN_TIMEOUT",L.LOGOUT="LOGOUT",L.REMOTE_LOGIN="REMOTE_LOGIN",(g=m.ConnectionState||(m.ConnectionState={})).ABORTED="ABORTED",g.CONNECTED="CONNECTED",g.CONNECTING="CONNECTING",g.DISCONNECTED="DISCONNECTED",g.RECONNECTING="RECONNECTING",(y=m.LocalInvitationFailureReason||(m.LocalInvitationFailureReason={})).INVITATION_EXPIRE="INVITATION_EXPIRE",y.NOT_LOGGEDIN="NOT_LOGGEDIN",y.PEER_NO_RESPONSE="PEER_NO_RESPONSE",y.PEER_OFFLINE="PEER_OFFLINE",(U=m.LocalInvitationState||(m.LocalInvitationState={})).ACCEPTED_BY_REMOTE="ACCEPTED_BY_REMOTE",U.CANCELED="CANCELED",U.FAILURE="FAILURE",U.IDLE="IDLE",U.RECEIVED_BY_REMOTE="RECEIVED_BY_REMOTE",U.REFUSED_BY_REMOTE="REFUSED_BY_REMOTE",U.SENT_TO_REMOTE="SENT_TO_REMOTE",(m.MessageType||(m.MessageType={})).TEXT="TEXT",(M=m.PeerOnlineState||(m.PeerOnlineState={})).OFFLINE="OFFLINE",M.ONLINE="ONLINE",M.UNREACHABLE="UNREACHABLE",(m.PeerSubscriptionOption||(m.PeerSubscriptionOption={})).ONLINE_STATUS="ONLINE_STATUS",(b=m.RemoteInvitationFailureReason||(m.RemoteInvitationFailureReason={})).ACCEPT_FAILURE="ACCEPT_FAILURE",b.INVITATION_EXPIRE="INVITATION_EXPIRE",b.PEER_OFFLINE="PEER_OFFLINE",(w=m.RemoteInvitationState||(m.RemoteInvitationState={})).ACCEPTED="ACCEPTED",w.ACCEPT_SENT_TO_LOCAL="ACCEPT_SENT_TO_LOCAL",w.CANCELED="CANCELED",w.FAILURE="FAILURE",w.INVITATION_RECEIVED="INVITATION_RECEIVED",w.REFUSED="REFUSED",exports.RtmErrorCode=void 0,D=exports.RtmErrorCode||(exports.RtmErrorCode={}),(G=D.BasicErrorCode||(D.BasicErrorCode={}))[G.INVALID_OPERATION=1]="INVALID_OPERATION",(P=D.AttributeOperationError||(D.AttributeOperationError={}))[P.ATTRIBUTE_OPERATION_ERR_FAILURE=2]="ATTRIBUTE_OPERATION_ERR_FAILURE",P[P.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT=3]="ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT",P[P.ATTRIBUTE_OPERATION_ERR_SIZE_OVERFLOW=4]="ATTRIBUTE_OPERATION_ERR_SIZE_OVERFLOW",P[P.ATTRIBUTE_OPERATION_ERR_TOO_OFTEN=5]="ATTRIBUTE_OPERATION_ERR_TOO_OFTEN",P[P.ATTRIBUTE_OPERATION_ERR_USER_NOT_FOUND=6]="ATTRIBUTE_OPERATION_ERR_USER_NOT_FOUND",P[P.ATTRIBUTE_OPERATION_ERR_TIMEOUT=7]="ATTRIBUTE_OPERATION_ERR_TIMEOUT",P[P.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN=102]="ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN",(x=D.ChannelMessageError||(D.ChannelMessageError={}))[x.CHANNEL_MESSAGE_ERR_FAILURE=1]="CHANNEL_MESSAGE_ERR_FAILURE",x[x.CHANNEL_MESSAGE_ERR_TIMEOUT=2]="CHANNEL_MESSAGE_ERR_TIMEOUT",x[x.CHANNEL_MESSAGE_ERR_TOO_OFTEN=3]="CHANNEL_MESSAGE_ERR_TOO_OFTEN",x[x.CHANNEL_MESSAGE_ERR_INVALID_MESSAGE=4]="CHANNEL_MESSAGE_ERR_INVALID_MESSAGE",x[x.CHANNEL_MESSAGE_ERR_NOT_IN_CHANNEL=5]="CHANNEL_MESSAGE_ERR_NOT_IN_CHANNEL",x[x.CHANNEL_MESSAGE_ERR_USER_NOT_LOGGED_IN=102]="CHANNEL_MESSAGE_ERR_USER_NOT_LOGGED_IN",(B=D.CreateChannelError||(D.CreateChannelError={}))[B.CREATE_CHANNEL_ERR_INVALID_ARGUMENT=1]="CREATE_CHANNEL_ERR_INVALID_ARGUMENT",(F=D.CreateInstanceError||(D.CreateInstanceError={}))[F.CREATE_INSTANCE_ERR_INVALID_ARGUMENT=1]="CREATE_INSTANCE_ERR_INVALID_ARGUMENT",(V=D.GetChannelMemberCountErrCode||(D.GetChannelMemberCountErrCode={}))[V.GET_CHANNEL_MEMBER_COUNT_ERR_FAILURE=1]="GET_CHANNEL_MEMBER_COUNT_ERR_FAILURE",V[V.GET_CHANNEL_MEMBER_COUNT_ERR_INVALID_ARGUMENT=2]="GET_CHANNEL_MEMBER_COUNT_ERR_INVALID_ARGUMENT",V[V.GET_CHANNEL_MEMBER_COUNT_ERR_TOO_OFTEN=3]="GET_CHANNEL_MEMBER_COUNT_ERR_TOO_OFTEN",V[V.GET_CHANNEL_MEMBER_COUNT_ERR_TIMEOUT=4]="GET_CHANNEL_MEMBER_COUNT_ERR_TIMEOUT",V[V.GET_CHANNEL_MEMBER_COUNT_ERR_EXCEED_LIMIT=5]="GET_CHANNEL_MEMBER_COUNT_ERR_EXCEED_LIMIT",V[V.GET_CHANNEL_MEMBER_COUNT_ERR_NOT_INITIALIZED=101]="GET_CHANNEL_MEMBER_COUNT_ERR_NOT_INITIALIZED",V[V.GET_CHANNEL_MEMBER_COUNT_ERR_USER_NOT_LOGGED_IN=102]="GET_CHANNEL_MEMBER_COUNT_ERR_USER_NOT_LOGGED_IN",(J=D.GetMembersError||(D.GetMembersError={}))[J.GET_MEMBERS_ERR_FAILURE=1]="GET_MEMBERS_ERR_FAILURE",J[J.GET_MEMBERS_ERR_REJECTED=2]="GET_MEMBERS_ERR_REJECTED",J[J.GET_MEMBERS_ERR_TIMEOUT=3]="GET_MEMBERS_ERR_TIMEOUT",J[J.GET_MEMBERS_ERR_TOO_OFTEN=4]="GET_MEMBERS_ERR_TOO_OFTEN",J[J.GET_MEMBERS_ERR_NOT_IN_CHANNEL=5]="GET_MEMBERS_ERR_NOT_IN_CHANNEL",J[J.GET_MEMBERS_ERR_USER_NOT_LOGGED_IN=6]="GET_MEMBERS_ERR_USER_NOT_LOGGED_IN",(W=D.InvitationApiCallError||(D.InvitationApiCallError={}))[W.INVITATION_API_CALL_ERR_INVALID_ARGUMENT=1]="INVITATION_API_CALL_ERR_INVALID_ARGUMENT",W[W.INVITATION_API_CALL_ERR_NOT_STARTED=2]="INVITATION_API_CALL_ERR_NOT_STARTED",W[W.INVITATION_API_CALL_ERR_ALREADY_END=3]="INVITATION_API_CALL_ERR_ALREADY_END",W[W.INVITATION_API_CALL_ERR_ALREADY_ACCEPT=4]="INVITATION_API_CALL_ERR_ALREADY_ACCEPT",W[W.INVITATION_API_CALL_ERR_ALREADY_SENT=5]="INVITATION_API_CALL_ERR_ALREADY_SENT",(k=D.JoinChannelError||(D.JoinChannelError={}))[k.JOIN_CHANNEL_ERR_FAILURE=1]="JOIN_CHANNEL_ERR_FAILURE",k[k.JOIN_CHANNEL_ERR_REJECTED=2]="JOIN_CHANNEL_ERR_REJECTED",k[k.JOIN_CHANNEL_ERR_INVALID_ARGUMENT=3]="JOIN_CHANNEL_ERR_INVALID_ARGUMENT",k[k.JOIN_CHANNEL_TIMEOUT=4]="JOIN_CHANNEL_TIMEOUT",k[k.JOIN_CHANNEL_ERR_EXCEED_LIMIT=5]="JOIN_CHANNEL_ERR_EXCEED_LIMIT",k[k.JOIN_CHANNEL_ERR_ALREADY_JOINED=6]="JOIN_CHANNEL_ERR_ALREADY_JOINED",k[k.JOIN_CHANNEL_ERR_TOO_OFTEN=7]="JOIN_CHANNEL_ERR_TOO_OFTEN",k[k.JOIN_CHANNEL_ERR_JOIN_SAME_CHANNEL_TOO_OFTEN=8]="JOIN_CHANNEL_ERR_JOIN_SAME_CHANNEL_TOO_OFTEN",k[k.JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN=102]="JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN",k[k.JOIN_CHANNEL_ERR_ABORTED_BY_LEAVE=210]="JOIN_CHANNEL_ERR_ABORTED_BY_LEAVE",k[k.JOIN_CHANNEL_ERR_ALREADY_JOINED_CHANNEL_OF_SAME_ID=211]="JOIN_CHANNEL_ERR_ALREADY_JOINED_CHANNEL_OF_SAME_ID",(Y=D.LeaveChannelError||(D.LeaveChannelError={}))[Y.LEAVE_CHANNEL_ERR_FAILURE=1]="LEAVE_CHANNEL_ERR_FAILURE",Y[Y.LEAVE_CHANNEL_ERR_REJECTED=2]="LEAVE_CHANNEL_ERR_REJECTED",Y[Y.LEAVE_CHANNEL_ERR_NOT_IN_CHANNEL=3]="LEAVE_CHANNEL_ERR_NOT_IN_CHANNEL",Y[Y.LEAVE_CHANNEL_ERR_USER_NOT_LOGGED_IN=102]="LEAVE_CHANNEL_ERR_USER_NOT_LOGGED_IN",(H=D.LoginError||(D.LoginError={}))[H.LOGIN_ERR_UNKNOWN=1]="LOGIN_ERR_UNKNOWN",H[H.LOGIN_ERR_INVALID_ARGUMENT=2]="LOGIN_ERR_INVALID_ARGUMENT",H[H.LOGIN_ERR_INVALID_APP_ID=3]="LOGIN_ERR_INVALID_APP_ID",H[H.LOGIN_ERR_INVALID_TOKEN=4]="LOGIN_ERR_INVALID_TOKEN",H[H.LOGIN_ERR_TOKEN_EXPIRED=5]="LOGIN_ERR_TOKEN_EXPIRED",H[H.LOGIN_ERR_NOT_AUTHORIZED=6]="LOGIN_ERR_NOT_AUTHORIZED",H[H.LOGIN_ERR_ALREADY_LOGIN=7]="LOGIN_ERR_ALREADY_LOGIN",H[H.LOGIN_ERR_TIMEOUT=8]="LOGIN_ERR_TIMEOUT",H[H.LOGIN_ERR_TOO_OFTEN=9]="LOGIN_ERR_TOO_OFTEN",H[H.LOGIN_ERR_ABORTED_BY_LOGOUT=10]="LOGIN_ERR_ABORTED_BY_LOGOUT",H[H.LOGIN_ERR_GATEWAY_CONNECT_FAILED=11]="LOGIN_ERR_GATEWAY_CONNECT_FAILED",(K=D.LogoutError||(D.LogoutError={}))[K.LOGOUT_ERR_USER_NOT_LOGGED_IN=102]="LOGOUT_ERR_USER_NOT_LOGGED_IN",(j=D.PeerMessageError||(D.PeerMessageError={}))[j.PEER_MESSAGE_ERR_FAILURE=1]="PEER_MESSAGE_ERR_FAILURE",j[j.PEER_MESSAGE_ERR_TIMEOUT=2]="PEER_MESSAGE_ERR_TIMEOUT",j[j.PEER_MESSAGE_ERR_TOO_OFTEN=5]="PEER_MESSAGE_ERR_TOO_OFTEN",j[j.PEER_MESSAGE_ERR_INVALID_USERID=6]="PEER_MESSAGE_ERR_INVALID_USERID",j[j.PEER_MESSAGE_ERR_INVALID_MESSAGE=7]="PEER_MESSAGE_ERR_INVALID_MESSAGE",j[j.PEER_MESSAGE_ERR_USER_NOT_LOGGED_IN=102]="PEER_MESSAGE_ERR_USER_NOT_LOGGED_IN",(Q=D.PeerSubscriptionStatusError||(D.PeerSubscriptionStatusError={}))[Q.PEER_SUBSCRIPTION_STATUS_ERR_FAILURE=1]="PEER_SUBSCRIPTION_STATUS_ERR_FAILURE",Q[Q.PEER_SUBSCRIPTION_STATUS_ERR_INVALID_ARGUMENT=2]="PEER_SUBSCRIPTION_STATUS_ERR_INVALID_ARGUMENT",Q[Q.PEER_SUBSCRIPTION_STATUS_ERR_REJECTED=3]="PEER_SUBSCRIPTION_STATUS_ERR_REJECTED",Q[Q.PEER_SUBSCRIPTION_STATUS_ERR_TIMEOUT=4]="PEER_SUBSCRIPTION_STATUS_ERR_TIMEOUT",Q[Q.PEER_SUBSCRIPTION_STATUS_ERR_TOO_OFTEN=5]="PEER_SUBSCRIPTION_STATUS_ERR_TOO_OFTEN",Q[Q.PEER_SUBSCRIPTION_STATUS_ERR_OVERFLOW=6]="PEER_SUBSCRIPTION_STATUS_ERR_OVERFLOW",Q[Q.PEER_SUBSCRIPTION_STATUS_ERR_USER_NOT_LOGGED_IN=102]="PEER_SUBSCRIPTION_STATUS_ERR_USER_NOT_LOGGED_IN",(X=D.QueryPeersBySubscriptionOptionError||(D.QueryPeersBySubscriptionOptionError={}))[X.QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_FAILURE=1]="QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_FAILURE",X[X.QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_TIMEOUT=2]="QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_TIMEOUT",X[X.QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_TOO_OFTEN=3]="QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_TOO_OFTEN",X[X.QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_USER_NOT_LOGGED_IN=102]="QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_USER_NOT_LOGGED_IN",(z=D.QueryPeersOnlineStatusError||(D.QueryPeersOnlineStatusError={}))[z.QUERY_PEERS_ONLINE_STATUS_ERR_INVALID_ARGUMENT=0]="QUERY_PEERS_ONLINE_STATUS_ERR_INVALID_ARGUMENT",z[z.QUERY_PEERS_ONLINE_STATUS_ERR_REJECTED=1]="QUERY_PEERS_ONLINE_STATUS_ERR_REJECTED",z[z.QUERY_PEERS_ONLINE_STATUS_ERR_TIMEOUT=2]="QUERY_PEERS_ONLINE_STATUS_ERR_TIMEOUT",z[z.QUERY_PEERS_ONLINE_STATUS_ERR_TOO_OFTEN=3]="QUERY_PEERS_ONLINE_STATUS_ERR_TOO_OFTEN",z[z.QUERY_PEERS_ONLINE_STATUS_ERR_USER_NOT_LOGGED_IN=102]="QUERY_PEERS_ONLINE_STATUS_ERR_USER_NOT_LOGGED_IN",($=D.RenewTokenError||(D.RenewTokenError={}))[$.RENEW_TOKEN_ERR_FAILURE=1]="RENEW_TOKEN_ERR_FAILURE",$[$.RENEW_TOKEN_ERR_INVALID_ARGUMENT=2]="RENEW_TOKEN_ERR_INVALID_ARGUMENT",$[$.RENEW_TOKEN_ERR_REJECTED=3]="RENEW_TOKEN_ERR_REJECTED",$[$.RENEW_TOKEN_ERR_TOO_OFTEN=4]="RENEW_TOKEN_ERR_TOO_OFTEN",$[$.RENEW_TOKEN_ERR_TOKEN_EXPIRED=5]="RENEW_TOKEN_ERR_TOKEN_EXPIRED",$[$.RENEW_TOKEN_ERR_INVALID_TOKEN=6]="RENEW_TOKEN_ERR_INVALID_TOKEN",$[$.RENEW_TOKEN_ERR_USER_NOT_LOGGED_IN=102]="RENEW_TOKEN_ERR_USER_NOT_LOGGED_IN",$[$.RENEW_TOKEN_ERR_ABORTED_BY_LOGOUT=201]="RENEW_TOKEN_ERR_ABORTED_BY_LOGOUT";var ee,te=function(e){function t(t,r){var n=e.call(this)||this;return n.memberCount=0,n.attributes={},n.channelId="",n.client=t,n.channelId=r,n.bindChannelEvents=n._handleChannelEvents.bind(n),n}return r(t,e),t.prototype.getMembers=function(){return o(this,void 0,void 0,(function(){var e,t;return i(this,(function(r){switch(r.label){case 0:return t=(e=this).client._rtmServer,""===this.client.uid?[3,2]:[4,t.doGetChanMembers(e.channelId)];case 1:return[2,r.sent()];case 2:throw new C(exports.RtmErrorCode.GetMembersError.GET_MEMBERS_ERR_USER_NOT_LOGGED_IN,"The client is not logged in. Cannot do the operation.")}}))}))},t.prototype.join=function(){return o(this,void 0,void 0,(function(){var e,t;return i(this,(function(r){switch(r.label){case 0:if(e=this,""===this.client.uid)throw new C(exports.RtmErrorCode.JoinChannelError.JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN,"The client is not logged in. Cannot do the operation.");return e.client.channels[e.channelId].joined?[3,3]:(t=e.client._rtmServer)?(t.addMessageEventListener(this.bindChannelEvents),[4,t.doJoinChannel(e.channelId)]):[3,2];case 1:return r.sent(),e.client.channels[e.channelId].joined=!0,I.info("join channel "+e.channelId+" success."),[2];case 2:return[3,4];case 3:throw new p(exports.RtmErrorCode.JoinChannelError.JOIN_CHANNEL_ERR_ALREADY_JOINED,"The channel has joined. Cannot rejoin.");case 4:return[2]}}))}))},t.prototype.leave=function(){return o(this,void 0,void 0,(function(){var e,t,r;return i(this,(function(n){switch(n.label){case 0:if(e=this,""===this.client.uid)throw new C(exports.RtmErrorCode.JoinChannelError.JOIN_CHANNEL_ERR_USER_NOT_LOGGED_IN,"The client is not logged in. Cannot do the operation.");return(t=e.client.channels[e.channelId]).joined?(r=e.client._rtmServer)?[4,r.doLeaveChannel(e.channelId)]:[3,2]:[3,3];case 1:return n.sent(),t.joined=!1,I.info("leave channel "+e.channelId+" success."),r.removeMessageEventListener(e.bindChannelEvents),[2];case 2:return[3,4];case 3:throw new p(exports.RtmErrorCode.LeaveChannelError.LEAVE_CHANNEL_ERR_NOT_IN_CHANNEL,"The channel does not join. Cannot do the operation.");case 4:return[2]}}))}))},t.prototype.sendMessage=function(e,t){return o(this,void 0,void 0,(function(){var r,n,o,s;return i(this,(function(i){switch(i.label){case 0:if(r=this,""===this.client.uid)throw new C(exports.RtmErrorCode.ChannelMessageError.CHANNEL_MESSAGE_ERR_USER_NOT_LOGGED_IN,"The client is not logged in. Cannot do the operation.");return r.client.channels[r.channelId].joined?(n=(t||{enableHistoricalMessaging:!1}).enableHistoricalMessaging,(o=r.client._rtmServer)?(s=e.text)?(exports.RtmStatusCode.MessageType.TEXT,[4,o.doSendChannelMsg(1,r.channelId,s,n)]):[3,2]:[3,3]):[3,4];case 1:return i.sent(),[2];case 2:throw new C(exports.RtmErrorCode.ChannelMessageError.CHANNEL_MESSAGE_ERR_INVALID_MESSAGE,"Message is not valid.");case 3:return[3,5];case 4:throw new p(exports.RtmErrorCode.ChannelMessageError.CHANNEL_MESSAGE_ERR_NOT_IN_CHANNEL,"The channel does not join. Cannot do the operation.");case 5:return[2]}}))}))},t.prototype._handleChannelEvents=function(e){var t=e.data,r=this,n=JSON.parse(t),o=n.Cmd;n.Encrypt;var i=n.Content,s=JSON.parse(i);if(s.ChanId===r.channelId)if("RecvMsgFromChan"===o){s.MsgId;var a=s.FromUId,E=s.MsgType,_=s.MsgBody,c={isOfflineMessage:!1,serverReceivedTs:s.SvrTS};if(1===E){var u={text:_};r.emit("ChannelMessage",u,a,c)}}else if("ChanMemberJoin"===o){var R=s.UserId;s.ChanMemSize,r.emit("MemberJoined",R)}else if("ChanMemberLeave"===o){R=s.UserId;s.ChanMemSize,r.emit("MemberLeft",R)}else if("MemSizeChanged"===o){var l=s.MemSize;r.emit("MemberCountUpdated",l)}else if("ChanAttribChanged"===o){var d=s.Attributes,N={};d.map((function(e){var t=e.Key,r=e.Val,n=e.UId,o=e.Time;N[t]={lastUpdateTs:o,lastUpdateUserId:n,value:r}})),r.emit("AttributesUpdated",N)}},t}(q),re=function(e){function t(t,r,n){var o=e.call(this)||this;return o._callId="",o.calleeId="",o.content="",o.state=exports.RtmStatusCode.LocalInvitationState.IDLE,o.response="",o.client=t,o._callId=r,o.calleeId=n,o}return r(t,e),t.prototype.cancel=function(){var e=this,t=e.client._rtmServer;if(t)if(e.state===exports.RtmStatusCode.LocalInvitationState.ACCEPTED_BY_REMOTE||e.state===exports.RtmStatusCode.LocalInvitationState.SENT_TO_REMOTE||e.state===exports.RtmStatusCode.LocalInvitationState.FAILURE||e.state===exports.RtmStatusCode.LocalInvitationState.RECEIVED_BY_REMOTE){var r=e.state===exports.RtmStatusCode.LocalInvitationState.FAILURE?"TimeOut":"";t.doCancelCall(e._callId,e.calleeId,r,e.content),e.state!==exports.RtmStatusCode.LocalInvitationState.FAILURE&&e.emit("LocalInvitationCanceled")}else if(e.state===exports.RtmStatusCode.LocalInvitationState.IDLE)throw new p(exports.RtmErrorCode.InvitationApiCallError.INVITATION_API_CALL_ERR_NOT_STARTED,"The call invitation is not send yet.")},t.prototype.send=function(){var e=this;if(e.state!==exports.RtmStatusCode.LocalInvitationState.IDLE){if(e.state===exports.RtmStatusCode.LocalInvitationState.SENT_TO_REMOTE)throw new p(exports.RtmErrorCode.InvitationApiCallError.INVITATION_API_CALL_ERR_ALREADY_SENT,"The call invitation already sent.");if(e.state===exports.RtmStatusCode.LocalInvitationState.ACCEPTED_BY_REMOTE||e.state===exports.RtmStatusCode.LocalInvitationState.REFUSED_BY_REMOTE)throw new p(exports.RtmErrorCode.InvitationApiCallError.INVITATION_API_CALL_ERR_ALREADY_END,"The call invitation already by accept.")}var t=e.client._rtmServer;t?(e.state=exports.RtmStatusCode.LocalInvitationState.SENT_TO_REMOTE,t.doMakeCall(e._callId,e.calleeId,e.content)):e.emit("LocalInvitationFailure",exports.RtmStatusCode.LocalInvitationFailureReason.NOT_LOGGEDIN)},t}(q),ne=function(e){function t(t,r,n){var o=e.call(this)||this;return o._callId="",o.callerId="",o.content="",o.response="",o._callId=t,o.callerId=r,o.content=n,o.state=exports.RtmStatusCode.RemoteInvitationState.INVITATION_RECEIVED,o._timer=setTimeout((function(){o.state===exports.RtmStatusCode.RemoteInvitationState.INVITATION_RECEIVED&&(o.state=exports.RtmStatusCode.RemoteInvitationState.FAILURE,o.emit("RemoteInvitationFailure",exports.RtmStatusCode.RemoteInvitationFailureReason.INVITATION_EXPIRE))}),6e4),o}return r(t,e),t.prototype.accept=function(){var e=this,t=e.client._rtmServer;if(t)if(e.state===exports.RtmStatusCode.RemoteInvitationState.INVITATION_RECEIVED)t.doAcceptCall(e._callId,e.callerId,e.response),e.state=exports.RtmStatusCode.RemoteInvitationState.ACCEPT_SENT_TO_LOCAL;else{if(e.state===exports.RtmStatusCode.RemoteInvitationState.ACCEPTED)throw new p(exports.RtmErrorCode.InvitationApiCallError.INVITATION_API_CALL_ERR_ALREADY_ACCEPT,"The call invitation already by accept.");if(e.state===exports.RtmStatusCode.RemoteInvitationState.REFUSED)throw new p(exports.RtmErrorCode.InvitationApiCallError.INVITATION_API_CALL_ERR_ALREADY_END,"The call invitation already ended.")}this._timer&&clearTimeout(this._timer)},t.prototype.refuse=function(){var e=this,t=e.client._rtmServer;t&&e.state===exports.RtmStatusCode.RemoteInvitationState.INVITATION_RECEIVED&&(t.doRefuseCall(e._callId,e.callerId,e.response),e.state=exports.RtmStatusCode.RemoteInvitationState.REFUSED,e.emit("RemoteInvitationRefused")),this._timer&&clearTimeout(this._timer)},t}(q),oe=function(t){function n(e,r){var n=t.call(this)||this;return n._useWss=!0,n._userAttributes={},n._localCall={},n._remoteCall={},n._sessionId="",n._joinStartTime=0,n.uid="",n.token=null,n.channels={},n.channelAttributesCacheLru={},n._sid=u.generateLowCaseString(32),n._appId=e,n.setParameters(r||{}),n}return r(n,t),n.prototype.addOrUpdateChannelAttributes=function(e,t,r){var n;return o(this,void 0,void 0,(function(){var o,s,a;return i(this,(function(i){switch(i.label){case 0:if(o=this,s=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,"string"!=typeof e||!s.test(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributes in the arguments is invalid.");if("[object Object]"!==Object.prototype.toString.call(t)||"{}"===JSON.stringify(t))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributes in the arguments is invalid.");return Object.keys(t).forEach((function(e){if(null==e||""===e)throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"Invalid attribute key.")})),Object.values(t).map((function(e,t){if(null==e||""===e)throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"Invalid attribute key.")})),""===o.uid?[3,2]:(a=(r||{enableNotificationToChannelMembers:!1}).enableNotificationToChannelMembers,[4,null===(n=o._rtmServer)||void 0===n?void 0:n.doAddOrUpdateChanAttributes({channelId:e,attributes:t,notify:a})]);case 1:return i.sent(),o.channelAttributesCacheLru[e]=t,[2];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.addOrUpdateLocalUserAttributes=function(e){var t;return o(this,void 0,void 0,(function(){var r;return i(this,(function(n){switch(n.label){case 0:if(r=this,"[object Object]"!==Object.prototype.toString.call(e)||"{}"===JSON.stringify(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributes in the arguments is invalid.");return Object.keys(e).forEach((function(e){if(null==e||""===e)throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"Invalid attribute value.")})),Object.values(e).map((function(e,t){if(null==e||""===e)throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"Invalid attribute key.")})),""===r.uid?[3,2]:[4,null===(t=r._rtmServer)||void 0===t?void 0:t.doAddOrUpdateUserAttributes(e)];case 1:return n.sent(),r._userAttributes=e,[2];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.clearChannelAttributes=function(e,t){var r;return o(this,void 0,void 0,(function(){var n,o,s;return i(this,(function(i){switch(i.label){case 0:if(n=this,o=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,"string"!=typeof e||!o.test(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributes in the arguments is invalid.");return""===n.uid?[3,2]:(s=(t||{enableNotificationToChannelMembers:!1}).enableNotificationToChannelMembers,[4,null===(r=n._rtmServer)||void 0===r?void 0:r.doClearChanAttributes({channelId:e,notify:s})]);case 1:return i.sent(),n.channelAttributesCacheLru[e]&&delete n.channelAttributesCacheLru[e],[2];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.clearLocalUserAttributes=function(){var e;return o(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return""===(t=this).uid?[3,2]:[4,null===(e=t._rtmServer)||void 0===e?void 0:e.doClearUserAttributes()];case 1:return r.sent(),t._userAttributes={},[2];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.createChannel=function(e){if("string"!=typeof e||!/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/.test(e)||"null"===e)throw new C(exports.RtmErrorCode.CreateChannelError.CREATE_CHANNEL_ERR_INVALID_ARGUMENT,"The channelId in the arguments is invalid.");var t=new te(this,e);return this.channels[e]={channel:t,joined:!1},t},n.prototype.createLocalInvitation=function(e){if("string"!=typeof e)throw new C(exports.RtmErrorCode.InvitationApiCallError.INVITATION_API_CALL_ERR_INVALID_ARGUMENT,"The calleeId in the arguments is invalid.");var t=u.generateLowCaseString(32),r=new re(this,t,e);return this._localCall[t]=r,r},n.prototype.deleteChannelAttributesByKeys=function(e,t,r){var n;return o(this,void 0,void 0,(function(){var o,s,a,E;return i(this,(function(i){switch(i.label){case 0:if(""===(o=this).uid)return[3,2];if(s=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,"string"!=typeof e||!s.test(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The channelId in the arguments is invalid.");if(!(t instanceof Array))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributeKeys in the arguments is not valid.");return a=(r||{enableNotificationToChannelMembers:!1}).enableNotificationToChannelMembers,[4,null===(n=o._rtmServer)||void 0===n?void 0:n.doDeleteChanAttributes({channelId:e,attributeKeys:t,notify:a})];case 1:return i.sent(),o.channelAttributesCacheLru[e]&&(E=o.channelAttributesCacheLru[e],Object.keys(E).map((function(e){E.hasOwnProperty(e)&&delete E[e]}))),[2];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.deleteLocalUserAttributesByKeys=function(e){var t;return o(this,void 0,void 0,(function(){var r;return i(this,(function(n){switch(n.label){case 0:if(r=this,!(e instanceof Array))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributeKeys in the arguments is not valid.");return""===r.uid?[3,2]:[4,null===(t=r._rtmServer)||void 0===t?void 0:t.doDeleteUserAttributes(e)];case 1:return n.sent(),e.map((function(e){r._userAttributes.hasOwnProperty(e)&&delete r._userAttributes[e]})),[2];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.getChannelAttributes=function(e){var t;return o(this,void 0,void 0,(function(){var r,n,o,s,a;return i(this,(function(i){switch(i.label){case 0:if(r=this,n=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,"string"!=typeof e||!n.test(e))throw new C(exports.RtmErrorCode.CreateChannelError.CREATE_CHANNEL_ERR_INVALID_ARGUMENT,"The channelId in the arguments is invalid.");return""===r.uid?[3,2]:[4,null===(t=r._rtmServer)||void 0===t?void 0:t.doGetChanAttributes(e)];case 1:return o=i.sent(),s={},a={},o.map((function(e){var t=e.Key,r=e.Val,n=e.UId,o=e.Time;s[t]=r,a[t]={lastUpdateTs:o,lastUpdateUserId:n,value:r}})),r.channelAttributesCacheLru[e]=s,[2,a];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.getChannelAttributesByKeys=function(e,t){var r;return o(this,void 0,void 0,(function(){var n,o,s,a,E;return i(this,(function(i){switch(i.label){case 0:if(n=this,o=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,"string"!=typeof e||!o.test(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The channelId in the arguments is invalid.");if(!(t instanceof Array))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributeKeys in the arguments is not valid.");return""===n.uid?[3,2]:[4,null===(r=n._rtmServer)||void 0===r?void 0:r.doGetChanAttributesByKeys(e,t)];case 1:return s=i.sent(),a=n.channelAttributesCacheLru[e]||{},E={},s.map((function(e){var t=e.Key,r=e.Val,n=e.UId,o=e.Time;E[t]={lastUpdateTs:o,lastUpdateUserId:n,value:r},a[t]=r})),[2,E];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.getChannelMemberCount=function(e){var t;return o(this,void 0,void 0,(function(){var r,n;return i(this,(function(o){switch(o.label){case 0:if(r=this,"[object Array]"!==Object.prototype.toString.call(e))throw new C(exports.RtmErrorCode.GetChannelMemberCountErrCode.GET_CHANNEL_MEMBER_COUNT_ERR_INVALID_ARGUMENT,"The channelIds in the arguments is invalid.");if(e.length>32)throw new C(exports.RtmErrorCode.GetChannelMemberCountErrCode.GET_CHANNEL_MEMBER_COUNT_ERR_EXCEED_LIMIT,"The channelIds is out of length.");return""===r.uid?[3,4]:r._rtmServer?(n={},[4,null===(t=r._rtmServer)||void 0===t?void 0:t.doGetChanMemberSize(e)]):[3,2];case 1:return o.sent().map((function(e){n[e.ChanId]=e.MemSize})),[2,n];case 2:throw new C(exports.RtmErrorCode.GetChannelMemberCountErrCode.GET_CHANNEL_MEMBER_COUNT_ERR_NOT_INITIALIZED,"The RTM server is not initialized yet.");case 3:return[3,5];case 4:throw new C(exports.RtmErrorCode.GetChannelMemberCountErrCode.GET_CHANNEL_MEMBER_COUNT_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.");case 5:return[2]}}))}))},n.prototype.getUserAttributes=function(e){var t;return o(this,void 0,void 0,(function(){var r;return i(this,(function(n){switch(n.label){case 0:if(r=this,"string"!=typeof e)throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The channelId in the arguments is invalid.");return""===r.uid?[3,2]:[4,null===(t=r._rtmServer)||void 0===t?void 0:t.doGetUserAttributes(e)];case 1:return[2,n.sent()];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.getUserAttributesByKeys=function(e,t){var r;return o(this,void 0,void 0,(function(){var n;return i(this,(function(o){switch(o.label){case 0:if(""===(n=this).uid)return[3,2];if("string"!=typeof e||!(t instanceof Array))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"arguments is not valid.");return[4,null===(r=n._rtmServer)||void 0===r?void 0:r.doGetUserAttributesByKeys(e,t)];case 1:return[2,o.sent()];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.login=function(e){var t=this,r=this;if(""!==r.uid)return Promise.reject(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_ALREADY_LOGIN,"The SDK is either logging in or has logged in the RTM system."));var n=e.token,s=e.uid;if(r.uid)return I.warning("already connected to room "+r.uid),Promise.resolve();if(r.connectFuture)return r.connectFuture.promise;if(r.reconnectFuture)return r.connectFuture=r.reconnectFuture,r.connectFuture.promise;return r.connectFuture=new d((function(e,E){return o(t,void 0,void 0,(function(){var t,o,_,c,u,R,l,d,N,T;return i(this,(function(i){switch(i.label){case 0:return r._emitConnectionState(exports.RtmStatusCode.ConnectionState.CONNECTING,exports.RtmStatusCode.ConnectionChangeReason.LOGIN),t=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,""===s||null==s||t.test(s)&&"string"==typeof s&&"null"!==s?n&&"string"!=typeof n?(E(new C(exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_ARGUMENT,"The uid length must be string within 64 bytes. The supported characters: a-z,A-Z,0-9,space,!, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _,  {, }, |, ~, ,")),[2]):(this._joinStartTime=Date.now(),r._createRtmServerInstance(),[4,v(r._authGateWay(s,n))]):(E(new C(exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_ARGUMENT,"The uid length must be string within 64 bytes. The supported characters: a-z,A-Z,0-9,space,!, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _,  {, }, |, ~, ,")),[2]);case 1:if(o=a.apply(void 0,[i.sent(),2]),_=o[0],c=o[1],!_)return[3,2];switch(u=exports.RtmStatusCode.ConnectionChangeReason.LOGIN_FAILURE,_.code){case exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_ARGUMENT:u=exports.RtmStatusCode.ConnectionChangeReason.LOGIN_FAILURE;break;case exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_APP_ID:u=exports.RtmStatusCode.ConnectionChangeReason.BANNED_BY_SERVER;break;case exports.RtmErrorCode.LoginError.LOGIN_ERR_TIMEOUT:u=exports.RtmStatusCode.ConnectionChangeReason.LOGIN_TIMEOUT}return r._emitConnectionState(exports.RtmStatusCode.ConnectionState.DISCONNECTED,u),E(_),[3,4];case 2:return c?e():E(),[4,v(this._gateway.getOfflineMsg({uid:r.uid}))];case 3:if(R=a.apply(void 0,[i.sent(),2]),l=R[0],d=R[1],l)return I.error("get offline message failed"),[2];d&&(N=d.code,T=d.data,0===N&&T.map((function(e){var t=e.msgFrom;e.msgStatus;var n=e.msgType,o=e.msgBody,i={isOfflineMessage:!0,serverReceivedTs:e.msgTs};if(1===n){var s={text:o};r.emit("MessageFromPeer",s,t,i)}}))),i.label=4;case 4:return[2]}}))}))}),(function(){r.clearConnectionFutures(),r._emitConnectionState(exports.RtmStatusCode.ConnectionState.CONNECTED,exports.RtmStatusCode.ConnectionChangeReason.LOGIN_SUCCESS)})),r.connectFuture.promise},n.prototype.clearConnectionFutures=function(){this.connectFuture=void 0,this.reconnectFuture=void 0},n.prototype.logout=function(){var e;return o(this,void 0,void 0,(function(){return i(this,(function(t){return""!==this.uid&&(null===(e=this._rtmServer)||void 0===e||e.doOffline(),this._rtmServer.disconnectServer(),this._rtmServer.handleMediaServerEvents=function(){},this._rtmServer=void 0,this.uid="",this.channels={},this._localCall={},this._remoteCall={},this._sessionId="",this.token="",this._joinStartTime=0,this._emitConnectionState(exports.RtmStatusCode.ConnectionState.DISCONNECTED,exports.RtmStatusCode.ConnectionChangeReason.LOGOUT)),[2]}))}))},n.prototype.queryPeersBySubscriptionOption=function(e){var t;return o(this,void 0,void 0,(function(){var r;return i(this,(function(n){switch(n.label){case 0:if(""===this.uid)throw new C(exports.RtmErrorCode.QueryPeersBySubscriptionOptionError.QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in. Cannot do the operation");if(!(e in exports.RtmStatusCode.PeerSubscriptionOption))throw new C(exports.RtmErrorCode.QueryPeersBySubscriptionOptionError.QUERY_PEERS_BY_SUBSCRIPTION_OPTION_ERR_FAILURE,"");return r=[],exports.RtmStatusCode.PeerSubscriptionOption.ONLINE_STATUS!==e?[3,2]:[4,null===(t=this._rtmServer)||void 0===t?void 0:t.doQueryOnlineSubStatus()];case 1:n.sent().map((function(e){1===e.Online&&r.push(e.UserId)})),n.label=2;case 2:return[2,r]}}))}))},n.prototype.queryPeersOnlineStatus=function(e){var t;return o(this,void 0,void 0,(function(){var r;return i(this,(function(n){switch(n.label){case 0:if(r={},""===this.uid)return[3,2];if(!(e instanceof Array&&e))throw new p(exports.RtmErrorCode.QueryPeersOnlineStatusError.QUERY_PEERS_ONLINE_STATUS_ERR_INVALID_ARGUMENT,"invalid arguments.");return[4,null===(t=this._rtmServer)||void 0===t?void 0:t.doQueryOnlineStatus(e)];case 1:return n.sent().map((function(e){r[e.UserId]=!!e.Online})),[2,r];case 2:throw new p(exports.RtmErrorCode.QueryPeersOnlineStatusError.QUERY_PEERS_ONLINE_STATUS_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}}))}))},n.prototype.renewToken=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(r){return t=this,[2,new Promise((function(r,n){var o;try{if(""===t.uid)throw new p(exports.RtmErrorCode.RenewTokenError.RENEW_TOKEN_ERR_USER_NOT_LOGGED_IN,"renewToken should not be called before user join");if(e&&"string"!=typeof e||!e)return void n(new C(exports.RtmErrorCode.RenewTokenError.RENEW_TOKEN_ERR_INVALID_ARGUMENT,"The uid length must be string within 64 bytes. The supported characters: a-z,A-Z,0-9,space,!, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _,  {, }, |, ~, ,"));I.info("set new token"),null===(o=t._rtmServer)||void 0===o||o.doReNewToken(e),r()}catch(e){n(e)}}))]}))}))},n.prototype.sendMessageToPeer=function(e,t,r){return o(this,void 0,void 0,(function(){var n,o,s,E,_,c,u,R,l,d;return i(this,(function(i){switch(i.label){case 0:if(o={hasPeerReceived:!1},""===(n=this).uid)return[3,4];if(!t)throw new C(exports.RtmErrorCode.PeerMessageError.PEER_MESSAGE_ERR_INVALID_USERID,"The send message arguments are not valid.");if(s=e.text,E=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,""!==t&&null!=t&&(!E.test(t)||"string"!=typeof t))throw new C(exports.RtmErrorCode.PeerMessageError.PEER_MESSAGE_ERR_INVALID_USERID,"The uid length must be string within 64 bytes. The supported characters: a-z,A-Z,0-9,space,!, #, $, %, &, (, ), +, -, :, ;, <, =, ., >, ?, @, [, ], ^, _,  {, }, |, ~, ,");return c=(_=r||{enableHistoricalMessaging:!1,enableOfflineMessaging:!1}).enableHistoricalMessaging,u=_.enableOfflineMessaging,s?(exports.RtmStatusCode.MessageType.TEXT,[4,v(n._rtmServer.doSendMsgToPeer(1,t,s,u,c))]):[3,2];case 1:if(R=a.apply(void 0,[i.sent(),2]),l=R[0],d=R[1],l)throw"TimeOut"===l?new p(exports.RtmErrorCode.PeerMessageError.PEER_MESSAGE_ERR_TIMEOUT):new p(exports.RtmErrorCode.PeerMessageError.PEER_MESSAGE_ERR_FAILURE,l);return o.hasPeerReceived=d,[2,o];case 2:throw new p(exports.RtmErrorCode.PeerMessageError.PEER_MESSAGE_ERR_INVALID_MESSAGE,"Message is not valid.");case 3:return[3,5];case 4:throw new p(exports.RtmErrorCode.PeerMessageError.PEER_MESSAGE_ERR_USER_NOT_LOGGED_IN,"Failed to send the peer-to-peer message. The client is not logged in.");case 5:return[2]}}))}))},n.prototype.setChannelAttributes=function(e,t,r){return o(this,void 0,void 0,(function(){var n,o,s;return i(this,(function(i){switch(i.label){case 0:if(n=this,o=/^[a-zA-Z0-9 \!\#\$\%\&\(\)\+\-\:\;\<\=\.\>\?\@\[\]\^\_\{\}\|\~\,]{1,64}$/,"string"!=typeof e||!o.test(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The channelId in the arguments is invalid.");if("[object Object]"!==Object.prototype.toString.call(t))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributes in the arguments is invalid.");return""===n.uid?[3,3]:(s=(r||{enableNotificationToChannelMembers:!1}).enableNotificationToChannelMembers,n._rtmServer?[4,n._rtmServer.doAddOrUpdateChanAttributes({channelId:e,attributes:t,isSet:!0,notify:s})]:[3,2]);case 1:return i.sent(),n.channelAttributesCacheLru[e]=t,[2];case 2:return[3,4];case 3:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.");case 4:return[2]}}))}))},n.prototype.setLocalUserAttributes=function(e){var t;return o(this,void 0,void 0,(function(){var r;return i(this,(function(n){switch(n.label){case 0:if(r=this,"[object Object]"!==Object.prototype.toString.call(e))throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_INVALID_ARGUMENT,"The attributes in the arguments is invalid.");return""===r.uid?[3,2]:(r._userAttributes={},[4,null===(t=r._rtmServer)||void 0===t?void 0:t.doAddOrUpdateUserAttributes(e,!0)]);case 1:return n.sent(),r._userAttributes=e,[3,3];case 2:throw new C(exports.RtmErrorCode.AttributeOperationError.ATTRIBUTE_OPERATION_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.");case 3:return[2]}}))}))},n.prototype.setParameters=function(t){var r=this,n=t.logFilter,o=t.confPriCloudAddr,i=t.ConfPriCloudAddr;if(n&&I.setLogLevel(n),o){var s=o.ServerAdd,a=o.Port,E=o.Wss;r._useWss="boolean"!=typeof E||E,s&&(e.GATEWAY_ADDRESS=(r._useWss?"https://"+s:"http://"+s)+(a?":"+a:""))}if(i){s=i.ServerAdd,a=i.Port,E=i.Wss;r._useWss="boolean"!=typeof E||E,s&&(e.GATEWAY_ADDRESS=(r._useWss?"https://"+s:"http://"+s)+(a?":"+a:""))}},n.prototype.subscribePeersOnlineStatus=function(e){var t;return o(this,void 0,void 0,(function(){return i(this,(function(r){if(""!==this.uid){if(!(e instanceof Array&&e))throw new p(exports.RtmErrorCode.PeerSubscriptionStatusError.PEER_SUBSCRIPTION_STATUS_ERR_INVALID_ARGUMENT,"invalid arguments.");if(e.length<1||e.length>512)throw new p(exports.RtmErrorCode.PeerSubscriptionStatusError.PEER_SUBSCRIPTION_STATUS_ERR_OVERFLOW,"The length of the subscriber must be greater than 0 and less than 512.");return null===(t=this._rtmServer)||void 0===t||t.doSubscribeOnlineStatus(e),[2]}throw new C(exports.RtmErrorCode.PeerSubscriptionStatusError.PEER_SUBSCRIPTION_STATUS_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}))}))},n.prototype.unsubscribePeersOnlineStatus=function(e){var t;return o(this,void 0,void 0,(function(){return i(this,(function(r){if(""!==this.uid){if(!(e instanceof Array&&e))throw new p(exports.RtmErrorCode.PeerSubscriptionStatusError.PEER_SUBSCRIPTION_STATUS_ERR_INVALID_ARGUMENT,"invalid arguments.");if(e.length<1||e.length>512)throw new p(exports.RtmErrorCode.PeerSubscriptionStatusError.PEER_SUBSCRIPTION_STATUS_ERR_OVERFLOW,"The length of the subscriber must be greater than 0 and less than 512.");return null===(t=this._rtmServer)||void 0===t||t.doUnSubscribeOnlineStatus(e),[2]}throw new C(exports.RtmErrorCode.PeerSubscriptionStatusError.PEER_SUBSCRIPTION_STATUS_ERR_USER_NOT_LOGGED_IN,"The client is not logged in.")}))}))},n.prototype._emitConnectionState=function(e,t){this.emit("ConnectionStateChanged",e,t)},n.prototype._createRtmServerInstance=function(){var e=this,t=this;t._rtmServer||(t._rtmServer=new Z),t._rtmServer.handleMediaServerEvents=function(t,r){var n,o=e;if(r.Code,"connection-state-change"===t){var i=r.curState;if(r.reason,"RECONNECTING"===i){o._emitConnectionState(exports.RtmStatusCode.ConnectionState.RECONNECTING);var s=o._userAttributes;o._userAttributes={},o._remoteCall={},o._localCall={},o.channelAttributesCacheLru={},Object.keys(o.channels).map((function(e){o.channels[e].joined=!1})),o._rtmServer=void 0,o._createRtmServerInstance(),o._authGateWay(o.uid,o.token).then((function(e){o.setLocalUserAttributes(s),Object.keys(o.channels).map((function(e){o.channels[e].channel.join()})),o._emitConnectionState(exports.RtmStatusCode.ConnectionState.CONNECTED)}))}}else if("ForceOffline"===t||"AcsTokenDidExpire"===t){var a="";"ForceOffline"===t?e._emitConnectionState(exports.RtmStatusCode.ConnectionState.DISCONNECTED,exports.RtmStatusCode.ConnectionChangeReason.REMOTE_LOGIN):"AcsTokenDidExpire"===t&&(a="TOKEN_INVALID",o.emit("TokenDidExpired"),I.debug("[client}] token privilege did expire.")),e._rtmServer.disconnectServer(a),e._rtmServer.handleMediaServerEvents=function(){},e._rtmServer=void 0,e.uid="",e.channels={},e._localCall={},e._remoteCall={},e._sessionId="",e.token=""}else if("AcsTokenWillExpire"===t)o.emit("TokenWillExpired"),I.debug("[client] token privilege will expire.");else if("RecvMsgFromPeer"===t){var E=r.MsgId,_=r.FromUId,c=r.MsgType,u=r.MsgBody,R={isOfflineMessage:!1,serverReceivedTs:r.SvrTS};if(1===c){var l={text:u};o.emit("MessageFromPeer",l,_,R)}null===(n=o._rtmServer)||void 0===n||n.doRecvMsgFromPeerAck(E,_)}else if("PeerOnlineStatus"===t){var d=r.Status,N={};d.map((function(e){N[e.UserId]=e.Online?exports.RtmStatusCode.PeerOnlineState.ONLINE:exports.RtmStatusCode.PeerOnlineState.OFFLINE})),o.emit("PeersOnlineStatusChanged",N)}else if("MakeCall"===t){var T=r.CallId,O=r.FromUId;r.ToUId;var p=r.Content;(v=new ne(T,O,p)).client=o,o._remoteCall[T]=v,o.emit("RemoteInvitationReceived",v)}else if("CancelCall"===t){T=r.CallId,O=r.FromUId;r.ToUId;var C=r.Reason;p=r.Content;(v=o._remoteCall[T])&&(v.state=exports.RtmStatusCode.RemoteInvitationState.CANCELED,C?"Offline"===C?v.emit("RemoteInvitationFailure",exports.RtmStatusCode.RemoteInvitationFailureReason.PEER_OFFLINE):"TimeOut"===C&&v.emit("RemoteInvitationFailure",exports.RtmStatusCode.RemoteInvitationFailureReason.INVITATION_EXPIRE):v.emit("RemoteInvitationCanceled",p))}else if("AcceptCallAck"===t){var v;T=r.CallId;(v=o._remoteCall[T]).state=exports.RtmStatusCode.RemoteInvitationState.ACCEPTED,v.emit("RemoteInvitationAccepted")}else if("AcceptCall"===t){T=r.CallId,O=r.FromUId;r.ToUId;var h=r.Response;(S=o._localCall[T]).state=exports.RtmStatusCode.LocalInvitationState.ACCEPTED_BY_REMOTE,S.emit("LocalInvitationAccepted",h)}else if("RejectCall"===t){T=r.CallId,O=r.FromUId;r.ToUId;var A=r.Response;(S=o._localCall[T]).state=exports.RtmStatusCode.LocalInvitationState.REFUSED_BY_REMOTE,S.emit("LocalInvitationRefused",A)}else if("CallStatus"===t){T=r.CallId,d=r.Status;var S=o._localCall[T];if(1===d)S.state=exports.RtmStatusCode.LocalInvitationState.SENT_TO_REMOTE;else if(2===d)S.state=exports.RtmStatusCode.LocalInvitationState.RECEIVED_BY_REMOTE,S.emit("LocalInvitationReceivedByPeer");else if(3===d){S.state=exports.RtmStatusCode.LocalInvitationState.FAILURE;var f=exports.RtmStatusCode.LocalInvitationFailureReason.PEER_OFFLINE;S.emit("LocalInvitationFailure",f)}else if(4===d){S.state=exports.RtmStatusCode.LocalInvitationState.FAILURE;var m=exports.RtmStatusCode.LocalInvitationFailureReason.PEER_NO_RESPONSE;S.emit("LocalInvitationFailure",m),S.cancel()}}}},n.prototype._authGateWay=function(t,r){var n=this,s=this;return new Promise((function(E,_){return o(n,void 0,void 0,(function(){var n,c,u,R,l,d,I,O,C,h,A,S,f,m,L=this;return i(this,(function(g){switch(g.label){case 0:return n=new T,this._gateway=n,[4,v(n.joinGateway({appid:s._appId,uid:t,token:r||"",wss:s._useWss},this._joinStartTime))];case 1:return c=a.apply(void 0,[g.sent(),2]),u=c[0],R=c[1],u?(u===N.INVALID_PARAMS?_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_ARGUMENT,"gateway connect failed: ")):u===N.DEVELOPER_INVALID||u===N.UID_BANNED||u===N.IP_BANNED||u===N.CHANNEL_BANNED||u===N.APPID_INVALID||u===N.SERVER_NOT_OPEN?_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_APP_ID)):u===N.TOKEN_EXPIRED?_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_TOKEN_EXPIRED,"You must request a new token from your server and call join to use the new token to join the channel")):u===N.TOKEN_INVALID?_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_INVALID_TOKEN,"make sure token is right and try again please")):u===N.TIMEOUT?_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_TIMEOUT)):_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_UNKNOWN)),[2]):(s.token=r,l=R.addresses,d=R.sessionid,s._sessionId=d,!l||l instanceof Array&&0===l.length?(_(new p(exports.RtmErrorCode.LoginError.LOGIN_ERR_UNKNOWN,"gateway connect failed: Can not find service list")),[2]):[4,v(s._connectRtmServer(R,t,r))]);case 2:return I=a.apply(void 0,[g.sent(),2]),O=I[0],C=I[1],O?(_(O),[2]):C?(h={UserId:t,UserSId:s._sid,AcsToken:r||"",SdkVer:e.VERSION,SessionId:s._sessionId},[4,v(s._rtmServer.doOnline(h))]):(Date.now()-s._joinStartTime<e.GATEWAY_RETRY_TIMEOUT?setTimeout((function(){return o(L,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,this._authGateWay(t,r)];case 1:return e=n.sent(),E(e),[2]}}))}))}),e.GATEWAY_CONNECT_INTERVAL_TIMES):(_(exports.RtmStatusCode.ConnectionChangeReason.LOGIN_FAILURE),s._emitConnectionState(exports.RtmStatusCode.ConnectionState.DISCONNECTED,exports.RtmStatusCode.ConnectionChangeReason.LOGIN_FAILURE)),[2]);case 3:return A=a.apply(void 0,[g.sent(),2]),S=A[0],f=A[1],S?(null===(m=s._rtmServer)||void 0===m||m.disconnectServer(),s._emitConnectionState(exports.RtmStatusCode.ConnectionState.DISCONNECTED,exports.RtmStatusCode.ConnectionChangeReason.LOGIN_FAILURE),_(S),[2]):(s.uid=f,E(s.uid),[2])}}))}))}))},n.prototype._connectRtmServer=function(e,t,r){var n=this,E=this,_=e.addresses;e.sessionid;var c=_.filter((function(e){return 0===e.type}));return new Promise((function(e,t){return o(n,void 0,void 0,(function(){var t,r,n,o,_,u,R,l,d,N;return i(this,(function(i){switch(i.label){case 0:t=!1,i.label=1;case 1:i.trys.push([1,6,7,8]),r=s(c),n=r.next(),i.label=2;case 2:return n.done?[3,5]:(o=n.value,I.info("begin connect rtm server ",o),null===(d=E._rtmServer)||void 0===d||d.setAppInfo({appId:E._appId}),null===(N=E._rtmServer)||void 0===N||N.configServer(E._useWss,o.addr,o.port),[4,v(E._rtmServer.connectServer())]);case 3:if(_=a.apply(void 0,[i.sent(),1]),!_[0])return t=!0,[3,5];i.label=4;case 4:return n=r.next(),[3,2];case 5:return[3,8];case 6:return u=i.sent(),R={error:u},[3,8];case 7:try{n&&!n.done&&(l=r.return)&&l.call(r)}finally{if(R)throw R.error}return[7];case 8:return e(t),[2]}}))}))}))},n}(q);exports.default=void 0,(ee=exports.default||(exports.default={})).BUILD="",ee.ConnectionChangeReason=void 0,ee.ConnectionState=void 0,ee.END_CALL_PREFIX="",ee.LOG_FILTER_ERROR=_.ERROR,ee.LOG_FILTER_INFO=_.INFO,ee.LOG_FILTER_OFF=_.NONE,ee.LOG_FILTER_WARNING=_.WARNING,ee.LocalInvitationState=void 0,ee.MessageType=void 0,ee.PeerOnlineState=void 0,ee.PeerSubscriptionOption=void 0,ee.RemoteInvitationFailureReason=void 0,ee.LocalInvitationFailureReason=void 0,ee.RemoteInvitationState=void 0,ee.VERSION=e.VERSION,ee.createInstance=function(e,t){if(!/^[a-zA-Z0-9]{32}$/.test(e))throw new C(exports.RtmErrorCode.CreateInstanceError.CREATE_INSTANCE_ERR_INVALID_ARGUMENT,"The appId in the arguments is invalid.");return new oe(e,t)},exports.ArRTM=exports.default,exports.LocalInvitation=re,exports.RemoteInvitation=ne,exports.RtmChannel=te,exports.RtmClient=oe;

}, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
return __REQUIRE__(1690447249538);
})()
//miniprogram-npm-outsideDeps=[]
//# sourceMappingURL=index.js.map