@rongcloud/electron 5.9.8 → 5.9.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding/electron-darwin-arm64.node +0 -0
- package/binding/electron-darwin-x64.node +0 -0
- package/binding/electron-linux-arm64.node +0 -0
- package/binding/electron-linux-x64.node +0 -0
- package/binding/electron-win32-ia32.node +0 -0
- package/binding/electron-win32-x64.node +0 -0
- package/cppServiceProcess.js +1 -1
- package/index.d.ts +15 -6
- package/index.esm.js +1 -1
- package/index.js +1 -1
- package/package.json +2 -2
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cppServiceProcess.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@rongcloud/engine"),t=require("os"),o=require("child_process"),r=require("path"),n=require("http"),s=require("https"),i=require("url"),a=require("net"),c=require("events"),u=require("tls"),p=require("fs"),d=require("crypto");function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var f=l(t),h=function(e,t){return h=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},h(e,t)};function C(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}h(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var g,v=function(){return v=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},v.apply(this,arguments)};function S(e,t,o,r){return new(o||(o=Promise))((function(n,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))}function y(e,t){var o,r,n,s,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){i.label=a[1];break}if(6===a[0]&&i.label<n[1]){i.label=n[1],n=a;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(a);break}n[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{o=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function _(e,t,o){if(o||2===arguments.length)for(var r,n=0,s=t.length;n<s;n++)!r&&n in t||(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_ADDON_T="P-call_addon-T",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_R="P-call_addon-R",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_O="P-connect-O",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_PARSE_JSON_MSGS_R="P-parse_json_messsages-R",e.P_RECEIVE_MESSAGE_E="P-receive_message-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_SUBSCRIBE_DATA_E="P-parse_json_subscribe_data-E",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R",e.P_PARSE_JSON_E="P-parse_json-E"}(g||(g={}));var m,E={flushTimestamp:Date.now(),queue:[],locked:!1};function T(){m&&clearInterval(m)}function P(e,t){T(),m=setInterval((function(){return O(e,t)}),1e4)}function R(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=E.queue).push.apply(e,t)}var I=200;function O(e,t){var o=E.queue,r=E.flushTimestamp;if(!(E.locked||0===o.length||Date.now()-r<3e4&&o.length<I)){E.locked=!0;var n=t.createTraceId(),s=t.getSessionId(),i=o.splice(0,I).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,i=e.tag,a=e.loggerId,c=e.content,u=e.traceId;return{level:o,time:r,type:n,tag:i,sessionId:s+":"+t,content:JSON.stringify({loggerId:a,content:c,traceId:u})}}));t.debug(g.P_WRITE_LOG_T,"writingLen: "+i.length+", queueLen: "+o.length,n);var a=JSON.stringify(i);e.writeLog(a),t.debug(g.P_WRITE_LOG_R,"write done, queueLen: "+o.length,n),E.flushTimestamp=Date.now(),E.locked=!1,setTimeout((function(){return O(e,t)}))}}var M=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.flush=function(e){R(e)},t}(e.BasicLogger),N=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.flush=function(e){R(e)},t}(e.BasicStatistic),b=function(e,t){var o,r=Buffer.from(e),n=r.length;for(t.push(n),o=0;o<n;o++)t.push(r[o])},U=function(e){return"string"==typeof e},x=function(e){return U(e)?e.toUpperCase():""},L=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: "+e[0]+".":255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: "+e[1]+"."),o},w=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: "+e[0]+".":0!==e[1]&&(t="Username and password authentication failure: "+e[1]+"."),t},A=function(e){var t=x(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var s="";for(var i in s=t+" "+(o+n)+" HTTP/1.1\n",r){if(Object.hasOwnProperty.call(r,i))s+=i+": "+r[i]+"\n"}return e.body&&(s+="Content-Length: "+e.body.length+"\n"),s+="\n","POST"===t&&e.body&&(s+=""+e.body),s},D=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,s=L(r,o);if(!s)return 2===r[1]?(e.socket.once("data",(function(o){var r=w(o);r?e.emit("error",new Error("SOCKS authentication failed. "+r)):t()})),n=[1],b(e.socksUsername,n),b(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. "+s))})),o=[0],e.socksUsername&&o.push(2),(r=Buffer.alloc(2+o.length))[0]=5,r[1]=o.length,o.forEach((function(e,t){r[2+t]=e})),e.write(r)}))},k=function(e,t,o){return new Promise((function(r){var n,s;switch(e.socket.once("data",(function(t){var o;5!==t[0]?o="Unexpected SOCKS version number: "+t[0]+".":0!==t[1]?o=function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code "+e}}(t[1])+".":0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. "+o)):r()})),(n=[]).push(5),n.push(1),n.push(0),a.isIP(t)){case 0:n.push(3),b(t,n);break;case 4:n.push(1),function(e,t){var o,r,n=e.split(".");for(o=0;o<4;o++)r=parseInt(n[o],10),t.push(r)}(t,n);break;case 6:e.emit("error",new Error("Does not support IPV6"))}n.length+=2,(s=Buffer.from(n)).writeUInt16BE(o,s.length-2),e.write(s)}))},J=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new a.Socket,o.options=t,o.socksHost=t.socksHost||"localhost",o.socksPort=t.socksPort||1080,o.socksUsername=t.socksUsername||"",o.socksPassword=t.socksPassword||"",o.socket.on("error",(function(e){o.emit("error",e)})),o.on("error",(function(){o.socket.destroyed||o.socket.destroy()})),o.on("end",o.end),o}return C(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var o=this.socket.end(e,t);return this.writable=this.socket.writable,o},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,o){return this.socket.write(e,t,o)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var o=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: "+e);if(!t||"string"!=typeof t)throw new TypeError("Invalid host: "+t);return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return S(o,void 0,void 0,(function(){var o;return y(this,(function(r){switch(r.label){case 0:return[4,D(this)];case 1:return r.sent(),[4,k(this,t,e)];case 2:return r.sent(),this.onProxied(),o=A(this.options),this.socket.write(Buffer.from(o)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(c.EventEmitter),B=function(e){var t,o=e.hostname,r=e.port;return!e.host||o&&r||(t=e.host.split(":")),!r&&t&&(r=parseInt(t[1],10)||0),!o&&t&&(o=t[0]),new J(e).connect(r,o)},j=function(e){function t(t){var o=e.call(this)||this;return o.createConnection=B,o}return C(t,e),t}(n.Agent),F=function(e,t,o){return(t=v(v({},t),i.parse(e))).port||(t.port=80),t.agent=new j(t),n.request(t,o)},V=function(e){var t,o;return t=B(e),o=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=u.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},q=function(e){function t(t,o){var r=e.call(this,o)||this;return r.url=t,r.socksHost=o.socksHost||"localhost",r.socksPort=o.socksPort||1080,r.createConnection=V,r}return C(t,e),t}(s.Agent),H=function(e,t,o,r){var n,i;return t.protocol="https:",!t.port&&t.host&&(n=t.host.split(":"),t.port=n[0],t.port=n[1]),t.port||(t.port=443),i=new q(e,t),t.agent=i,s.request(e,t,o)},G=null;function K(t,o,r){void 0===r&&(r=!1);var i=o.url,a=o.headers,c=o.body,u=o.method,p=o.query,d=o.timeout,l=void 0===d?e.HTTP_TIMEOUT:d;return new Promise((function(o){var d=/^https/.test(i),f={headers:a,method:u};d&&(f.rejectUnauthorized=r);var h=null;G?((f=v(v({},f),G)).body=c,h=d?H:F):(h=n.request,d&&(f.agent=new s.Agent(f),h=s.request));var C=h(e.appendUrl(i,p),f,(function(e){var t=e.statusCode,r="";e.setEncoding("utf8"),e.on("data",(function(e){r+=e})),e.once("end",(function(){o({status:t||0,data:r})}))}));C.once("timeout",(function(){t.warn(g.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:i,method:u,query:p,timeout:l})),o({status:0})})),C.setTimeout(l),C.once("error",(function(e){t.warn(g.P_HTTP_REQ_E,JSON.stringify({msg:e.stack,url:i,method:u,query:p,timeout:l})),o({status:0})})),C.write(c),C.end()}))}function W(t,o){return t?(G=v(v({},G),t),o.info(e.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:G})),{code:e.ErrorCode.SUCCESS}):(G=null,o.info(e.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:e.ErrorCode.SUCCESS})}function Q(){var t=G||void 0;return{code:e.ErrorCode.SUCCESS,data:t}}var Y,X=[],z=!1,Z=function(){return S(void 0,void 0,void 0,(function(){var t,o,r,n,s,i,a,c,u,p,d,l,f;return y(this,(function(h){return z||0===X.length||(z=!0,t=X.shift(),o=t.args,r=t.resolve,n=o.addon,s=o.startTime,i=o.endTime,a=o.level,c=o.realtimeReport,u=0,p=0,d=[],l=function(t){u+=t.length;var o=t.split(","),n=o[0],s=o[1],i=o[2],l=o[3],f=o[4],h=o.slice(5);if(u>e.REAT_TIME_LOG_SIZE&&parseInt(s,10)!==p)r(d);else{p=parseInt(s,10);try{if(!c&&a<0)return;var C={time:parseInt(s,10),level:parseInt(l,10),sessionId:n,type:i,tag:f,content:h.join(",")};d.push(C)}catch(e){console.error(e)}}},f=function(e){r(d),z=!1,Z()},n.getFullLog(a,s,i,!1,l,f)),[2]}))}))},$=function(t){function o(o,r,n,s,i){var a=this,c="Electron|"+process.versions.electron+"|"+process.arch+"|"+process.platform;return(a=t.call(this,r,n,c,{getLogs:function(e,t,r,n){return S(this,void 0,void 0,(function(){return y(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:t,level:r,realtimeReport:n,addon:o},S(void 0,void 0,void 0,(function(){return y(this,(function(e){return[2,new Promise((function(e){X.push({resolve:e,args:i}),Z()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var t=o.getStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(t,10)||0},setTimestamp4RealtimeLog:function(t){o.setStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP,t.toString())}},s)||this).subProcess=i,a}return C(o,t),o.prototype.send=function(e){return K(this.logger,e)},o.prototype.compressLogs=function(e){return S(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=n.sent(),o=t.success,r=t.data,o?[2,{success:o,data:r.data}]:[2,{success:o,data:""}]}}))}))},o}(e.BasicReporter),ee=[e.EConnectProtocol.RMTP,e.EConnectProtocol.TLS,e.EConnectProtocol.QUIC],te=function(e){return"RongCloud/navis/"+e+"/navi-cache.json"},oe="deviceId",re=function(e){return"RongCloud/caches/"+e+"/staticConfig.json"},ne=function(e){return"RongCloud/cloudControl/"+e+"/cloudControl.json"},se=null,ie=function(){var e,o=Date.now(),r=[t.arch(),t.platform(),process.pid,o,Math.floor(Math.random()*o)].join("__");return e=r,d.createHash("md5").update(e).digest("hex")},ae=function(e){if(se)return se;var t=r.resolve(e,oe);return p.existsSync(t)?se=p.readFileSync(t).toString():(se=ie(),p.writeFileSync(t,se),se)},ce=function(){function e(e){this._callCppProxy=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,s){var i=JSON.stringify(n);"{}"!==i&&e.info(g.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._callCppProxy("setMessageExtension",t,o,r,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime,c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,r,n,s,c,o||"")},e.prototype.setLocalFromExtMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._callCppProxy("getMessage",a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var f=d[l];f&&f.ts<i-this._setTime?(f.v=c[l],f.ts=i-this._setTime):(d[l]={v:"",ts:0},d[l].v=c[l],d[l].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete d[e]})),this._setToProtocol(e,r,n,a.mid,d,o||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var r in t)o[r]=t[r].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),r={};for(var n in o)r[n]=o[n].v;return r},e}();!function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(Y||(Y={}));var ue,pe=function(){function t(t,o,r,n){var s=this;this.p=t,this.emit=o,this.callback=r,this.errorHandle=n,this.count=0,this.maps={},this.p.on("message",(function(e){var t=e.type,i=e.data;switch(t){case Y.EVENT:var a=i,c=a.eventName,u=a.data;null==o||o.apply(void 0,_([c],u,!1));break;case Y.RESPONSE:var p=i,d=p.reqId,l=p.success,f=p.data,h=s.maps[d];if(!h)return;h({success:l,data:f}),delete s.maps[d];break;case Y.CALLBACK:var C=i,g=(d=C.reqId,C.data);null==r||r(d,g);break;case Y.ERROR:var v=i.msg;null==n||n(v)}})),this.p.on("error",(function(e){null==n||n("SubProcessProxy error "+e)})),this.p.on("exit",(function(t,o){if(0!==t){for(var r in s.maps){if(Object.prototype.hasOwnProperty.call(s.maps,r))(0,s.maps[r])({success:!0,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==n||n("SubProcessProxy exit "+t+" "+o,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return t.prototype.call=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r=this;return y(this,(function(n){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(e){var n=++r.count;r.maps[n]=e;var s={reqId:n,method:t,args:o,hasResponse:!0};r.p.send(s)}))]}))}))},t.prototype.send=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r;return y(this,(function(n){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),r={reqId:-1,method:e,args:o},this.p.send(r),[2]}))}))},t.prototype.destroy=function(){this.send("destroy")},t}(),de=function(e,t,o){return S(void 0,void 0,void 0,(function(){var r,n;return y(this,(function(s){return r=d.createDecipheriv("aes-256-cbc",t,o),n=r.update(e,"base64","utf-8"),[2,n+=r.final("utf8")]}))}))},le=function(e){if(!p.existsSync(e)){var t=r.resolve(e,"..");p.existsSync(t)||le(t),p.mkdirSync(e)}},fe=function(t){function o(e,o,n,s,i){var a=t.call(this,e,o,n,i)||this;a.naviPath="",a._caches={},a.naviPath=s+"/"+te(e);var c=r.dirname(a.naviPath);return p.existsSync(c)||le(c),a}return C(o,t),o.prototype.httpRequest=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c,u;return y(this,(function(p){switch(p.label){case 0:return s="token="+encodeURIComponent(r)+"&v="+e.FORMATED_VERSION+"&p=PC&ev=5.9.8",i=t+"/navi.json?r="+Date.now(),this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:i,body:s}),n),[4,K(this.logger,{method:"POST",headers:{appId:o},body:s,url:i,timeout:e.NAVI_REQ_TIMEOUT})];case 1:if(200!==(a=p.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,code:a.status}),n),[2,{code:this.transHttpCode(a.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,data:a.data}),n);try{return c=JSON.parse(a.data),u=/^https/.test(i)?"https":"http",c.protocol=u,[2,{code:e.ErrorCode.SUCCESS,data:c}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,a.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.httpRequestV2=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return s=this.getNaviV2RequestOption({appkey:o,token:r,uri:t,platform:"electron",protocol:ee.join(",")}),this.logger.debug(e.LogTagId.L_REQUEST_T,JSON.stringify({url:s.url,body:s.body,headers:s.headers}),n),[4,K(this.logger,s)];case 1:if(200!==(i=u.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,code:i.status}),n),[2,{code:this.transHttpCode(i.status)}];try{return a=JSON.parse(i.data),c=/^https/.test(s.url)?"https":"http",a.protocol=c,[2,{code:e.ErrorCode.SUCCESS,data:a}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,i.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.getNaviCache=function(t){var o=this._caches[t];if(o)return o;if(!p.existsSync(this.naviPath))return null;var r=p.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(r),this._caches[t]}catch(t){this.logger.error(e.LogTagId.L_PARSE_NAVI_E,r)}return null},o.prototype.setNaviCache=function(t,o){var r=Date.now();if(e.notEmptyObject(this._caches))for(var n in this._caches){var s=this._caches[n];(r-s.timestamp>e.NAVI_CACHE_DURATION||t===s.token)&&delete this._caches[n]}this._caches[t]={token:t,naviInfo:o,timestamp:Date.now()},p.writeFileSync(this.naviPath,JSON.stringify(this._caches))},o}(e.BasicNavi);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(ue||(ue={}));var he=function(t){function o(o,r,n,s,i,a){var c=t.call(this,o,n,s,i,a)||this;return c.callCppProxy=r,c._connectedTime=0,c._naviInfo=null,c._excludeLogTag=["P-RCGetValueForKey-T","P-RCGetValueForKey-E","P-RCGetValueForKey-R","P-RCSetValueForKey-T","P-RCSetValueForKey-E","P-RCSetValueForKey-R"],c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.callCppProxy("setConnectionStatusListener",c._onConnectionStatusChange.bind(c),(function(e){c.logger.info(g.P_DB_OPEN_O,e)}),(function(){return c.recvPong(e.ErrorCode.SUCCESS)}),c._onConnectionStatusChange.bind(c),c._onTcpConnectResponse.bind(c)),c}return C(o,t),o.prototype.getConnectedTime=function(){return this._connectedTime},o.prototype.connectWithToken=function(t,o,r,n){var s=this;return new Promise((function(i){s._naviInfo=o,s.connectResolve={resolve:i,traceId:n,userId:o.userId};var a={},c=Q().data;c&&(a={proxy_passwd:c.socksPassword||"",proxy_name:c.socksUsername||"",proxy_port:c.socksPort||1082,proxy_host:c.socksHost||"localhost",proxy_type:0});var u=JSON.stringify(v(v({},a),{call_plus:s._openCallPlus})),p=s.getCmpList(o,!0).filter((function(e){return ee.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(t){var o=d.find((function(e){return e.addr===t.addr}));o?o.protocol!==e.EConnectProtocol.QUIC&&t.protocol!==e.EConnectProtocol.QUIC||(o.race=!0,o.protocol=e.EConnectProtocol.QUIC):(t.race=!1,d.push(t))})),s.logger.info(g.P_CONNECT_O,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:e.FORMATED_VERSION,reconnectKickEnable:r}),n),s._startTime=Date.now();try{s.callCppProxy("connectWithToken",t,e.FORMATED_VERSION,JSON.stringify(v(v({},o),{serverAddr:d,tagBlacklist:s._excludeLogTag.join(",")})),r,u)}catch(t){s.logger.error(g.P_CALL_ADDON_E,null==t?void 0:t.stack,n),s.recvConnectRes(e.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},o.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.callCppProxy("disconnect",t)},o.prototype.sendPing=function(t){var o=this;return new Promise((function(r){o.pingResolve=r,o.callCppProxy("sendHeartbeat"),setTimeout((function(){return o.recvPong(e.ErrorCode.TIMEOUT)}),t)}))},o.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},o.prototype._onConnectionStatusChange=function(t,o){switch(this.logger.info(g.P_CONNECT_S,JSON.stringify({status:t,delay:o})),t){case e.ErrorCode.SUCCESS:this.recvConnectRes(e.ErrorCode.SUCCESS);break;case e.ErrorCode.RC_CONN_REDIRECTED:case 32061:this.recvConnectRes(e.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case e.ErrorCode.RC_SOCKET_DISCONNECTED:this.recvConnectRes(t,!1);break;case e.ErrorCode.RC_SOCKET_NOT_CREATED:case e.ErrorCode.RC_CONN_ACK_TIMEOUT:case e.ErrorCode.RC_TCP_RESET:this.recvConnectRes(t);break;case e.ErrorCode.RC_UDP_DISCONNECTED:this.recvConnectRes(t,!0,o);break;default:this.recvConnectRes(t,!0)}},o.prototype.recvConnectRes=function(t,o,r){if(this.connectResolve){var n=this.connectResolve,s=n.resolve,i=n.userId,a=Date.now()-(this._startTime+this._tcpDuration),c={bid:e.getbundleId(),cod:t,net:this.getNetwork().type,dur:a,spr:0,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,count:this.retryCount};return this.statisticLog.record(e.StatisticsTag.IM_CMP_RMTP,JSON.stringify(c)),t===e.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.callCppProxy("getDeltaTime")),s({code:t,data:i}),void(this.connectResolve=null)}if(o)this.onDisconnectByServer(t,r);else{if(t===e.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(t)}},o.prototype._onTcpConnectResponse=function(t,o,r,n,s,i,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr===o+":"+r})),p={bid:e.getbundleId(),ptc:e.ProtocalType.TCP,cod:t,net:this.getNetwork().type,dur:n,spr:0,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:o+":"+r,idx:u,rct:this.retryCount?e.ConnectType.RECONNECT:e.ConnectType.CONNECT,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,rsn:this.reason,ddu:s,count:this.retryCount,weight:u>=0?this.cmpWeightCache[u].weight:-1};this.statisticLog.record(e.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(g.P_CONNECT_ENTRY_S,JSON.stringify({code:t,host:o,port:r,duration:n,dnsDuration:s,index:i,isQuic:a})),t===ue.SUCCESS&&(this.curCmpUrl=o+":"+r,this.updateCmpWeight(o+":"+r,!0,a))},o}(e.AConnectionMgr),Ce=function(t){function o(e,o,n){var s=t.call(this,e,o)||this;s.appkey=e,s.logger=o,s.dbpath=n,s._cachePath="",s._cachePath=n+"/"+re(e);var i=r.dirname(s._cachePath);return p.existsSync(i)||le(i),s}return C(o,t),o.prototype.getCache=function(){return p.existsSync(this._cachePath)&&p.readFileSync(this._cachePath,{encoding:"utf8"})||null},o.prototype.setCache=function(e){p.writeFileSync(this._cachePath,e)},o.prototype.clearCache=function(){p.writeFileSync(this._cachePath,"")},o.prototype.sendRequest=function(e){return S(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,K(this.logger,{url:e,body:""})];case 1:return t=n.sent(),o=t.status,r=t.data,[2,{code:o,data:r}]}}))}))},o.prototype.decryptData=function(t){return S(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,de(t,e.STATIC_CONFIG_KEY,e.STATIC_CONFIG_IV)];case 1:return o=n.sent(),[2,JSON.parse(o)];case 2:return r=n.sent(),this.logger.error(e.LogTagId.L_GET_STATIC_CONF_E,JSON.stringify({error:null==r?void 0:r.stack})),[3,3];case 3:return[2]}}))}))},o}(e.BasicStaticConfigManager),ge=function(t){function o(e,o,n,s,i,a,c){var u=t.call(this,o,e,n,a)||this;u.deviceId=s,u.model="",u.catchFilePath="",u.addon=c,u.model="Electron|"+process.platform+"|"+process.arch,u.catchFilePath=i+"/"+ne(e);var d=r.dirname(u.catchFilePath);return p.existsSync(d)||le(d),u.init(),u}return C(o,t),o.prototype.httpRequest=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c,u,p,d,l;return y(this,(function(f){switch(f.label){case 0:return(s=n).deviceId=this.deviceId,s.model=this.model,i={url:t,method:o,headers:r,body:JSON.stringify(s)},this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify(i)),[4,K(this.logger,i)];case 1:a=f.sent(),c=a.status,u=a.data,p=void 0===u?"":u,this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({status:c,data:p}));try{return d=JSON.parse(p),l=d.data,[2,{code:c,data:l}]}catch(t){return this.logger.warn(e.LogTagId.L_CLOUD_CONFIG_DATA_E,JSON.stringify({status:c,data:p,error:t})),[2,{code:c,msg:t}]}return[2]}}))}))},o.prototype.setCloudControllerCache=function(t){p.writeFileSync(this.catchFilePath,JSON.stringify(t)),this.logger.info(e.LogTagId.L_CLOUD_SET_CACHE_O,JSON.stringify(t))},o.prototype.getLocalCloudControllerCache=function(){if(!p.existsSync(this.catchFilePath))return null;var t=p.readFileSync(this.catchFilePath,{encoding:"utf8"});return this.logger.info(e.LogTagId.L_CLOUD_GET_CACHE_O,JSON.stringify({appkey:this.appkey,data:t})),t},o.prototype.setMRTRConfig=function(t){var o={mrtrChatroom:t.chatroom,mrtrGroup:t.group,mrtrPrivate:t.private,mrtrUltraGroup:t.ultraGroup};this.logger.info(e.LogTagId.L_CLOUD_SET_MRTR_O,JSON.stringify(o)),this.addon.setCloudConfig(JSON.stringify(o))},o}(e.BaseCloudController),ve=function(){function t(t,n,s,i,a){var c=this;this._appkey=t,this._cppProtocol=n,this._dbpath=s,this._dispatchEvent=i,this._logOutputLevel=a,this._customMessageType={},this.cloudControllerUri="",this.cloudControllerLock=!0,this.cloudControllerMsgs=[],this._buildSubscribeEventData=function(e){var t=[];try{JSON.parse(e).list.forEach((function(e){var o=JSON.parse(e.obj),r=o.userId,n=o.subscribeType,s=o.subscribeTime,i=o.duration,a=o.operationType,c=o.details,u=void 0===c?[]:c;t.push({userId:r,subscribeType:n,subscribeTime:s,duration:i,operationType:a,details:u.map((function(e){var t=JSON.parse(e);return{changeTime:t.changeTime,eventValue:t.changeValue,platform:t.platform}}))})}))}catch(t){c.logger.error(g.P_PARSE_JSON_SUBSCRIBE_DATA_E,JSON.stringify({error:null==t?void 0:t.stack,data:e}))}return t},this._chatroomCache=[],this.rtcHeartbeatResolves={};var u=this._dbpath,p=ae(u);this.logger=new M(this._appkey,"RC-M","IM"),this._cppProtocol.initWithAppkey(t,u,e.FORMATED_VERSION,this.logger.getSessionId());var d=o.fork(r.resolve(__dirname,"sub-process.js"));this.subProxy=new pe(d),this.statisticLog=new N(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),P(this._cppProtocol,this.logger),this.reporter=new $(this._cppProtocol,t,p,this.logger,this.subProxy),this.logger.info(g.P_INIT_O,JSON.stringify({appkey:t,dbpath:u,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:p,commit:"818915a24854e2a6959314debabd4999590e5f0d"})),this._callCppProxy("setDeviceId",p),this._staticConfigManager=new Ce(t,this.logger,u),this.navi=new fe(t,this.logger,this.statisticLog,u,this._staticConfigManager),this.tcpMgr=new he(t,this._callCppProxy.bind(this),this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this)}),this._initCloudController(p,u),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setSubscribeEventListener(),this._msgExpansionHandler=new ce(this._callCppProxy.bind(this))}return t.prototype._initCloudController=function(t,o){var r=e.urlCenter.getCloudControllerUrl();this.cloudControllerUri=r[0],this.cloudController=new ge(this._appkey,this.logger,this.reporter,t,o,this.statisticLog,this._cppProtocol),e.isStartCloudController()&&this.cloudControllerUri&&this.cloudController.request(this.cloudControllerUri,e.InvokerType.init)},t.prototype.callProxy=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r,n,s;return y(this,(function(i){switch(i.label){case 0:if(!(r=this[t]))return this.logger.warn(g.P_CALL_MAIN_E,JSON.stringify({method:t,error:"not found"})),[2,Promise.resolve({code:e.ErrorCode.NOT_SUPPORT})];n="",i.label=1;case 1:return i.trys.push([1,3,,4]),[4,r.call.apply(r,_([this],o,!1))];case 2:return[2,i.sent()];case 3:return s=i.sent(),n=JSON.stringify({error:null==s?void 0:s.stack,method:t}),this.logger.error(g.P_CALL_MAIN_E,n),[3,4];case 4:return[2,{code:e.ErrorCode.MAIN_PROCESS_ERROR,msg:n}]}}))}))},t.prototype.sendProxy=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return S(this,void 0,void 0,(function(){var o;return y(this,(function(r){if(!(o=this[e]))return this.logger.warn(g.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2];try{o.call.apply(o,_([this],t,!1))}catch(t){this.logger.error(g.P_CALL_MAIN_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return[2]}))}))},t.prototype.registerRenderers=function(t){var o=t.navigators,r=t.areaCode,n=t.logServerUrl;e.urlCenter.init({areaCode:r,navigators:o,logServerUrl:n})},t.prototype.onConnected=function(){return S(this,void 0,void 0,(function(){var e,t,o;return y(this,(function(r){switch(r.label){case 0:return e=this.getNaviInfoFromCache(),this.reporter.checkStart(e),this._try2RejoinChatroom(),t=this._dispatchEvent,o=["onConnected"],[4,this.getMainProcessCache()];case 1:return t.apply(this,o.concat([r.sent()])),[2]}}))}))},t.prototype.onConnecting=function(){this._dispatchEvent("onConnecting",void 0)},t.prototype.onSuspend=function(e){this._dispatchEvent("onSuspend",e)},t.prototype.onDisconnected=function(e){this._dispatchEvent("onDisconnected",e)},t.prototype._callCppProxy=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this.logger.createTraceId();try{return this.logger.debug(g.P_CALL_ADDON_O,JSON.stringify({method:e,content:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){throw this.logger.error(g.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n),t}},t.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},t.prototype.sendHTTPRequest=function(e){return K(this.logger,e)},t.prototype.onRendererLogsReceived=function(e){R.apply(void 0,e)},t.prototype.onRendererNetworkStatusReceived=function(t,o){if(this.tcpMgr.setNetwork(t,o),t.status&&e.isStartCloudController()&&this.cloudController){var r=this.tcpMgr.getToken();this.cloudController.request(this.cloudControllerUri,e.InvokerType.newWorkChange,r)}},t.prototype.destroy=function(){this.reporter.stop(),this.subProxy.destroy(),this._cppProtocol,T(),this._cppProtocol.destroy(),process.exit(0)},t.prototype.callExtra=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this[t];if(!n)return this.logger.warn(g.P_CALL_EXTRA_E,JSON.stringify({method:t,error:"not found"})),Promise.resolve({code:e.ErrorCode.NOT_SUPPORT});try{return n.call.apply(n,_([this],o,!1))}catch(e){this.logger.error(g.P_CALL_EXTRA_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(t,o,r,n,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",t,o,r,s||!1,n||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.getUnreadConversationList=function(t){var o,r=this,n=this._callCppProxy("getUnreadConversationList",t);try{o=JSON.parse(n).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t.prototype.getConversationListWithAllChannel=function(){var t,o=this,r=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],n=this._callCppProxy("getConversationListWithAllChannel",r);try{t=JSON.parse(n).list.map((function(e){return o._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},t.prototype.getConversationListWithAllChannelByPage=function(t,o){var r,n=this,s=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,t,o);try{r=JSON.parse(i).list.map((function(e){return n._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},t.prototype.getHistoryMessagesByObjectNames=function(t,o,r,n,s,i,a){var c=0===i,u=n+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",t,o,r,u,s,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var f=0;f<l.length;f++){var h=this._buildMessage(l[f].obj);d[f]=h}}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:n<d.length}})},t.prototype.updateMessageReceiptStatus=function(t,o,r,n){void 0===n&&(n="");var s=this._callCppProxy("updateMessageReceiptStatus",t,o,r,n);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},t.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new M(this._appkey,e,t)},t.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},t.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId(),n=this.getDeviceId(),s=this._cppProtocol.getDeltaTime();return Promise.resolve({connectedTime:e,deviceId:n,crtUserId:r,naviInfo:o,connectionStatus:t,deltaTime:s})},t.prototype._registerMsgTypes=function(){for(var t in e.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},e.SEND_MESSAGE_TYPE_OPTION){var o=e.SEND_MESSAGE_TYPE_OPTION[t],r=o.isCounted,n=o.isPersited,s=o.searchProps,i=0;n&&(i|=1),r&&(i|=2),"RC:TypSts"===t&&(i=16),this._callCppProxy("registerMessageType",t,i,s||[])}},t.prototype._buildIsMentioned=function(t,o){var r,n=!1;if(e.isObject(t))r=t;else try{r=t?JSON.parse(t):t}catch(e){r=t,this.logger.error(g.P_PARSE_JSON_MSGS_E,JSON.stringify({content:t}))}return e.isObject(r)&&(n=!!r.mentionedInfo),{isMentioned:n,msgContent:r}},t.prototype._buildMsgOption=function(t){var o={isCounted:!1,isPersited:!1};return t in e.SEND_MESSAGE_TYPE_OPTION?o=e.SEND_MESSAGE_TYPE_OPTION[t]:t in this._customMessageType&&(o=this._customMessageType[t]),o},t.prototype._buildSupportExt=function(e,t,o){var r=null;return e&&(r=this._msgExpansionHandler.parseReceiveExpansion(o),"conversation"!==t&&"history"!==t||(r=this._msgExpansionHandler.parseConverOrHisExpansion(o))),r},t.prototype._handleReadReceiptRequest=function(e){var t=JSON.parse(e),o=this.getNaviInfoFromCache();if(!(null==o?void 0:o.grpRRVer))return t;var r=t,n=r.hasRespond,s=r.readerInfo,i=void 0===s?{}:s,a=r.readCount,c=r.totalCount,u=r.readerList,p=void 0===u?[]:u,d={readCount:a,totalCount:c};if(1===(null==o?void 0:o.grpRRVer)){var l=[];for(var f in i)l.push({userId:f,readTime:i[f]});d.readerList=l,d.hasRespond=n}return 3===(null==o?void 0:o.grpRRVer)&&(d.readerList=p),d},t.prototype._buildMessage=function(t,o){var r;void 0===o&&(o={});var n=o.isOffLineMessage,s=o.buildFrom,i=JSON.parse(t),a=i.channelId,c=i.conversationType,u=i.targetId,p=i.senderUserId,d=i.content,l=i.objectName,f=i.messageUid,h=i.direction,C=i.status,g=i.messageId,S=i.sentTime,y=i.readReceiptRequest,_=i.supportExt,m=i.pushContent,E=i.pushTitle,T=i.pushId,P=i.pushConfig,R=i.templateId,I=i.disableTitle,O=i.forcePushDetail,M=i.hasMore,N=i.directedUsers,b=this._buildIsMentioned(d,g),U=b.isMentioned,x=b.msgContent,L=this._buildMsgOption(l),w=this._buildSupportExt(_,s,i),A=e.isUndefined(n)?S<this.tcpMgr.getConnectedTime():n,D={};P&&(D=e.pushJSONToConfigs(this.logger,P,T));var k=v(v({},D),{pushTitle:E,pushContent:m,pushData:m,disablePushTitle:I,forceShowDetailContent:O,templateId:R}),J={channelId:a,conversationType:c,targetId:u,senderUserId:p,content:x||{},messageType:l,messageUId:f||"",messageDirection:h,isOffLineMessage:A,sentTime:S,receivedTime:0,isPersited:L.isPersited,isCounted:L.isCounted,isMentioned:U,disableNotification:!1,isStatusMessage:(null===(r=this._customMessageType[l])||void 0===r?void 0:r.isStatusMessage)||!1,canIncludeExpansion:_,expansion:_?w:null,receivedStatus:C,receivedStatusInfo:e.transformReceivedStatusInfo(C),messageId:g,pushConfig:k,hasMore:M,directedUserIds:N||[]};if(h===e.MessageDirection.RECEIVE?J.receivedStatus=this._compatibleReceivedStatus(J.receivedStatusInfo):h===e.MessageDirection.SEND&&(J.sentStatus=C),y){var B=this._handleReadReceiptRequest(y);J.readReceiptInfo=B}return J},t.prototype._compatibleReceivedStatus=function(t){var o=e.ReceivedStatus.UNREAD;return t.isRead?o=e.ReceivedStatus.READ:t.isListened?o=e.ReceivedStatus.LISTENED:t.isDownload?o=e.ReceivedStatus.DOWNLOADED:t.isRetrieved&&(o=e.ReceivedStatus.RETRIEVED),o},t.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},s=v(v({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},t.prototype._processRRRspMsg=function(e,t,o){if(t!==this.getCurrentUserId())for(var r=0,n=e[this.getCurrentUserId()]||[];r<n.length;r++){h=n[r];var s=this._callCppProxy("getMessage",h),i=JSON.parse(s),a=i.readReceiptRequest?JSON.parse(i.readReceiptRequest):{},c=a.isReceiptRequestMessage,u=a.readerList,p=void 0===u?[]:u;c&&!p.includes(t)&&(p.push(t),this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:c,readerList:p})))}else for(var d in e)for(var l=0,f=e[d];l<f.length;l++){var h=f[l];this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:!0,hasRespond:!0}))}},t.prototype._processRSMsg=function(t){var o=t.conversationType,r=t.targetId,n=t.content,s=t.channelId,i=n.msgId,a=n.rrn,c=n.tmn,u=n.endMsgTime;o===e.ConversationType.PRIVATE?this.updateMessageReceiptStatus(o,r,u,s||""):this._updateReadReceiptInfo(i,{readCount:a,totalCount:c});var p={conversationType:o,targetId:r,channelId:s};this._sendMessageReadReceipt(o===e.ConversationType.PRIVATE?{privateReadReceipt:v(v({},p),{endMsgTime:n.endMsgTime})}:{groupReadReceipt:v(v({},p),{totalCount:n.tmn,readedCount:n.rrn,messageUId:n.msgId})})},t.prototype._processSRSMsg=function(e){var t=this.getNaviInfoFromCache(),o=e.conversationType,r=e.targetId,n=e.content,s=e.channelId,i=e.senderUserId,a=e.sentTime;return i===this.tcpMgr.getCurrentUserId()&&(this._callCppProxy("clearUnreadCountByTimestamp",o,r,n.lastMessageSendTime,s||""),1!==(null==t?void 0:t.sesDriven)||(a>this.tcpMgr.getConnectedTime()||this._sendsyncReadStatus({conversationType:o,targetId:r,channelId:s,timestamp:n.lastMessageSendTime}),!1))},t.prototype._buildConversation=function(t){var o=JSON.parse(t),r=o.channelId,n=o.conversationType,s=o.targetId,i=o.unreadCount,a=o.lastestMsg,c=o.isTop,u=o.blockStatus,p=o.matchCount,d=o.hasUnreadMention,l=o.conversationTime,f=o.draft,h=u>0?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE;return{channelId:r,conversationType:n,targetId:s,unreadMessageCount:i,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:d,mentionedInfo:null,notificationStatus:h,isTop:c,lastUnreadTime:0,matchCount:p,operationTime:l,notificationLevel:u,draft:f}},t.prototype._convertResultList=function(e,t){var o=JSON.parse(e).list;return o=o.map((function(e){var o=JSON.parse(e.obj);return t?t(o):o}))},t.prototype._handleNotNotificationMessage=function(t){var o,r=t.messageType,n=t.senderUserId,s=t.content;if(r===e.MessageType.LOG_COMMAND&&t.senderUserId===e.RC_DEFAULT_USER){var i=t.content,a=i.startTime,c=i.endTime,u=i.platform,p=i.logId,d=i.uri;return this.reporter.report(parseInt(a,10),parseInt(c,10),u,d,p,t.messageUId),!0}if(r===e.MessageType.CLOUD_CONTROL&&n===e.RC_DEFAULT_USER)return this.cloudControllerMsgs.push(t),this._ccMsgHandler(),!0;if(r===e.MessageType.READ_STATE)return this._processRSMsg(t),!0;if("RC:MsgExMsg"===r)return this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),this._sendMessageExpansion(t),!0;if(r===e.MessageType.SYNC_READ_STATUS&&!this._processSRSMsg(t))return!0;if(r===e.MessageType.DELIVERED)return this._callCppProxy("setMessageDeliverTime",JSON.stringify(s)),this._sendMessageDelivered(t.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}}))),!0;if(r===e.MessageType.DELIVERED_MSG){var l={totalCount:t.content.tmn,list:null===(o=t.content.dl)||void 0===o?void 0:o.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};return this._sendGroupMessageDeliveredStatus(l),!0}return!1},t.prototype._setOnReceiveMessageListener=function(){var t=this;this._cppProtocol.setOnReceiveMessageListener((function(o,r,n,s){try{var i=t._buildMessage(o,{isOffLineMessage:n}),a=i.messageType,c=i.channelId,u=void 0===c?"":c,p=i.senderUserId,d=i.content,l=i.sentTime,f=i.conversationType,h=i.targetId;if(t._handleNotNotificationMessage(i))return;if(a===e.MessageType.READ_RECEIPT_REQUEST&&d.messageUId&&t._updateReadReceiptInfo(d.messageUId,{isReceiptRequestMessage:!0,hasRespond:!1}),a===e.MessageType.READ_RECEIPT_RESPONSE&&d.receiptMessageDic&&t._processRRRspMsg(d.receiptMessageDic,p,l),a===e.MessageType.GROUP_READ_RECEIPT_REQUEST){var C=d.msgId,v=d.rrn,S=d.tmn;t._updateReadReceiptInfo(C,{readCount:v,totalCount:S})}i.canIncludeExpansion&&t._msgExpansionHandler.setLocalFromReceiveMsg(t.logger,i),a===e.MessageType.READ_RECEIPT&&p===t.tcpMgr.getCurrentUserId()&&t._callCppProxy("clearUnreadCountByTimestamp",f,h,d.lastMessageSendTime,u);var y=!0;if(0!==r||s||(y=!1),a===e.MessageType.RECALL){if(!t.handleRecalledMessage(i))return;var _=t._fixRecallContentInfo(i);f=_.conversationType,h=_.targetId}t._sendMessageNotification(Object.assign(i,{hasMoreMsg:y,conversationType:f,targetId:h}))}catch(e){t.logger.error(g.P_RECEIVE_MESSAGE_E,JSON.stringify({error:null==e?void 0:e.stack,message:o}))}}),(function(){t._sendPullOfflineFinished()}))},t.prototype._ccMsgHandler=function(){var t;return S(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return this.cloudControllerLock?(this.cloudControllerLock=!1,this.cloudControllerMsgs.shift()?(o=this.tcpMgr.getToken(),[4,null===(t=this.cloudController)||void 0===t?void 0:t.request(this.cloudControllerUri,e.InvokerType.other,o)]):[3,2]):[2];case 1:r=n.sent()||0,this.cloudControllerMsgs=this.cloudControllerMsgs.filter((function(e){return e.sentTime>r})),this.cloudControllerLock=!0,this._ccMsgHandler(),n.label=2;case 2:return[2]}}))}))},t.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,o=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,o=e.content.targetId||o),{conversationType:t,targetId:o}},t.prototype.handleRecalledMessage=function(t){var o=t.content,r=o.messageUId,n=o.sentTime;if(!r)return!0;var s=this._callCppProxy("getMessage",r),i=this._buildMessage(s,{isOffLineMessage:!1});if(t.content.isDelete)return-1===i.messageId||this._callCppProxy("deleteMessages",[i.messageId]),!0;if(i.messageType===e.MessageType.RECALL_NOTIFICATION_MESSAGE)return!1;var a={recallTime:Date.now(),admin:!!t.content.isAdmin,originalObjectName:i.messageType,originalMessageContent:i.content,recallActionTime:t.sentTime,operatorId:t.senderUserId};if(t.content.user&&(a.user=t.content.user),t.content.extra&&(a.extra=t.content.extra),i.messageType===e.MessageType.TextMessage&&(a.recallContent=i.content.content),-1===i.messageId){var c=t.conversationType,u=t.targetId,p=t.senderUserId,d=t.channelId,l=t.messageDirection;return this._callCppProxy("insertMessage",c,u,p,e.MessageType.RECALL_NOTIFICATION_MESSAGE,JSON.stringify(a),(function(){}),(function(){}),l,1,10,n,"",0,r,!1,!0,JSON.stringify({}),d||""),!0}return i.receivedStatus||this.setMessageReceivedStatus(i.messageId,1),this._callCppProxy("setMessageContent",i.messageId,JSON.stringify(a),e.MessageType.RECALL_NOTIFICATION_MESSAGE),!0},t.prototype._sendMessageExpansion=function(e){var t=e.channelId,o=void 0===t?"":t,r=e.content,n=e.conversationType,s=e.targetId,i=r,a=i.put,c=i.del,u=i.mid,p={};a&&(p.updatedExpansion={channelId:o,messageUId:u,expansion:a,conversationType:n,targetId:s}),c&&(p.deletedExpansion={channelId:o,messageUId:u,deletedKeys:c,conversationType:n,targetId:s}),this._dispatchEvent("expansion",p)},t.prototype._sendMessageNotification=function(e){this._dispatchEvent("batchMessage",e)},t.prototype._sendPullOfflineFinished=function(){this._dispatchEvent("pullFinished",null)},t.prototype._sendMessageDelivered=function(e){this._dispatchEvent("messageDelivered",e)},t.prototype._sendGroupMessageDeliveredStatus=function(e){this._dispatchEvent("groupMessageDeliveredStatus",e)},t.prototype._sendChatroomStatus=function(e){this._dispatchEvent("chatroom",e)},t.prototype._sendMessageReadReceipt=function(e){this._dispatchEvent("messageReadReceipt",e)},t.prototype._sendsyncReadStatus=function(e){this._dispatchEvent("syncReadStatus",e)},t.prototype._setConversationStatusListener=function(){var t=this;this._cppProtocol.setConversationStatusListener((function(o){var r=JSON.parse(o).list,n=[];r.forEach((function(t){var o=JSON.parse(t.obj),r=o.conversationType,s=o.targetId,i=o.status,a=o.channelId,c={notificationStatus:2,isTop:!1};i.forEach((function(t){var o=JSON.parse(t.item);1===o.type?c.notificationStatus=1===Number(o.value)?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE:c.isTop=1===Number(o.value)})),n.push({channelId:a,conversationType:r,targetId:s,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),t._dispatchEvent("conversation",n)}),(function(e){t._dispatchEvent("conversationTag",e)}),(function(e,o,r,n){t._callCppProxy("clearUnreadCountByTimestamp",e,o,n,r||""),t._sendsyncReadStatus({conversationType:e,targetId:o,channelId:r,timestamp:n})}))},t.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._dispatchEvent("tag",t),e._getRTCProfile()}))},t.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var o=this.navi.getNaviInfoFromCache(t);this._dispatchEvent("onNaviDataChange",o)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){var o=new Uint8Array(t).buffer;e._dispatchEvent("onRTCDataChange",o)}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},t.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._dispatchEvent("callInfo",t)}))},t.prototype._setSubscribeEventListener=function(){var e=this;this._cppProtocol.setSubscribeEventListener((function(){}),(function(){e._dispatchEvent("syncSubscribedUserStatusFinished")}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,operationType:e.operationType}}));e._dispatchEvent("subscribedRelationChange",o)}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,details:e.details}}));e._dispatchEvent("subscribedUserStatusChange",o)}))},t.prototype._updateMentionedInfo=function(t,o,r){var n,s,i;return{userIdList:(null===(n=t.mentionedInfo)||void 0===n?void 0:n.userIdList)||o,type:(null===(s=t.mentionedInfo)||void 0===s?void 0:s.type)||r||e.MentionedType.ALL,mentionedContent:(null===(i=t.mentionedInfo)||void 0===i?void 0:i.mentionedContent)||""}},t.prototype.registerMessageType=function(e,t,o,r,n){var s=0;t&&(s|=1),o&&(s|=2),n&&(s=16),this._customMessageType[e]={isCounted:o,isPersited:t,isStatusMessage:n},this.logger.info(g.P_REGTYP_O,JSON.stringify({type:e,opt:s,search:r})),this._callCppProxy("registerMessageType",e,s,r||[])},t.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},t.prototype.reportSDKInfo=function(e){var t=JSON.stringify(v(v({},e),{"electron-main":"5.9.8"}));this.logger.info(g.P_REPORT_VER_O,t),this._callCppProxy("uploadSDKVersion",t,"")},t.prototype.disconnect=function(e){e=e||!0,this._chatroomCache.length=0,this.reporter.stop(),W(null,this.logger),this.tcpMgr.disconnect(e)},t.prototype.logout=function(){this.disconnect()},t.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,o){t({userId:e,status:o})}));var o=e.userIds||[];o.length&&this.subscribeUserStatus(o)},t.prototype.subscribeUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("subscribeUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.setUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("setUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getUserStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:{status:t}})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype._handleDirectionalUserIdList=function(t){var o=t.messageType,r=t.content,n=t.directionalUserIdList,s=void 0===n?[]:n;if(o===e.MessageType.READ_RECEIPT_RESPONSE&&r.receiptMessageDic)for(var i in r.receiptMessageDic)s.push(i);return o===e.MessageType.SYNC_READ_STATUS&&(s=[this.getCurrentUserId()]),s},t.prototype._handleMessage2Callback=function(t,o){var r=this;if("RC:MsgExMsg"===t.messageType&&this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),t.messageType===e.MessageType.READ_RECEIPT_REQUEST)this._updateReadReceiptInfo(o.content.messageUId,{isReceiptRequestMessage:!0,readerList:[]});else if(t.messageType===e.MessageType.READ_RECEIPT_RESPONSE){var n=o.content.receiptMessageDic;if(!n)return;for(var s in n)n[s].forEach((function(e){r._updateReadReceiptInfo(e,{isReceiptRequestMessage:!0,hasRespond:!0})}))}},t.prototype.sendMessage=function(t,o,r,n,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=r.messageType,c=r.content,u=r.expansion,p=r.pushConfig,d=r.isMentioned,l=r.mentionedType,f=r.mentionedUserIdList,h=void 0===f?[]:f,C=r.pushContent,v=void 0===C?"":C,S=r.pushData,y=void 0===S?"":S,_=r.directionalUserIdList,m=void 0===_?[]:_,E=r.disableNotification,T=void 0!==E&&E,P=r.canIncludeExpansion,R=void 0!==P&&P,I=r.isVoipPush,O=void 0!==I&&I,M=r.channelId,N=void 0===M?"":M,b=r.messageId,U=void 0===b?0:b,x=p||{},L=x.iOSConfig,w=x.androidConfig,A=x.templateId,D=void 0===A?"":A,k=x.pushTitle,J=void 0===k?"":k,B=x.pushContent,j=void 0===B?v:B,F=x.pushData,V=void 0===F?y:F,q=x.disablePushTitle,H=void 0!==q&&q,G=x.forceShowDetailContent,K=void 0!==G&&G,W=e.pushConfigsToJSON(L,w);return new Promise((function(p){v=j,y=V;var f=(null==w?void 0:w.notificationId)||"",C=t===e.ConversationType.GROUP;C&&d&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,h,l)),C&&(m=i._handleDirectionalUserIdList(r));var S={};for(var _ in u)S[_]={v:""},S[_].v=u[_];var E=D;i.logger.info(g.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:t,targetId:o,channelId:N}),s);var P=i._callCppProxy("sendMessage",(function(t,o){var n=i._buildMessage(t,{isOffLineMessage:!1});if(i.logger.info(g.P_SEND_MSG_R,JSON.stringify({code:o,messageUId:n.messageUId}),s),o===e.ErrorCode.SENSITIVE_REPLACE)return setTimeout((function(){p({code:o})}),0);[e.MessageType.READ_RECEIPT_REQUEST,e.MessageType.READ_RECEIPT_RESPONSE,e.MessageType.EXPANSION_NOTIFY].findIndex((function(e){return e===n.messageType}))>-1&&i._handleMessage2Callback(n,r),n.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,n),setTimeout((function(){p({code:e.ErrorCode.SUCCESS,data:n})}),0)}),(function(e,t){var o=i._buildMessage(e,{isOffLineMessage:!1});i.logger.warn(g.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),s),o.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),setTimeout((function(){p({code:t,data:o})}),0)}),t,o,a,JSON.stringify(c),m,T,H,K,v,y,f,J,W,E,R,JSON.stringify(S),O,N,U),I=JSON.parse(P);null==n||n(I.messageId)}))},t.prototype.recallMsg=function(t,o,r,n,s){var i=this;return new Promise((function(a){var c,u=s.user,p=s.pushContent,d=s.channelId,l=s.extra,f=s.pushConfig,h=s.disableNotification,C=s.isDelete,g=s.directionalUserIdList,v={conversationType:t,targetId:o,messageUId:r,sentTime:n,user:u,extra:l,channelId:d,isDelete:C||!1};u&&(v.user=u),l&&(v.extra=l);var S={conversationType:t,targetId:o,senderUserId:i.tcpMgr.getCurrentUserId(),content:v,objectName:e.MessageType.RECALL,messageUid:r,direction:e.MessageDirection.SEND,status:e.ReceivedStatus.UNREAD,sentTime:n,channelId:d},y=i._buildMessage(JSON.stringify(S),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){i.handleRecalledMessage(y),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:y})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}),e.MessageType.RECALL,JSON.stringify(v),h||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,p||"",(null==f?void 0:f.pushData)||"",(null===(c=null==f?void 0:f.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==f?void 0:f.pushTitle)||"",e.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",d,g||[])}))},t.prototype.getHistoryMessage=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){r=r||0;var p=0===s,d=n+1,l=c._callCppProxy("getHistoryMessages",t,o,r,d,a,p,i),f=JSON.parse(l).list,h=[];f.reverse();for(var C=0;C<f.length;C++){var g=c._buildMessage(f[C].obj);h[C]=g}u({code:e.ErrorCode.SUCCESS,data:{list:d===h.length?h.slice(1,d):h,hasMore:n<h.length}})}))},t.prototype.getMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){var u=0===s,p=r,d=0!==r,l=n+1;d&&(p+=u?1:-1,l++);for(var f=a._callCppProxy("getMessages",t,o,p,l,u,i),h=JSON.parse(f).list,C=[],g=0;g<h.length;g++){var v=a._buildMessage(h[g].obj);C[g]=v}var S=a._computeRepairInfo(C,u,r,p,l),y=S.isNeedRepair,_=void 0!==y&&y,m=S.repairTime,E=void 0===m?0:m;if(!_)return d&&(C.shift(),l--),C.reverse(),void c({code:e.ErrorCode.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:n<C.length}});a._processRepairHisMsg(t,o,r,n,s,i,E,c)}))},t.prototype._computeRepairInfo=function(e,t,o,r,n){var s=!1,i=0,a=this.getNaviInfoFromCache()||{},c=a.repairHisMsg,u=void 0===c?0:c,p=a.historyMsg;if(1!==u||!p)return{isNeedRepair:s,repairTime:i};var d=e.findIndex((function(e){return e.hasMore||0===Object.keys(e.content).length}));return t&&d>=0?(s=!0,i=e[d].hasMore?e[d].sentTime:e[d].sentTime+1):!t&&d>=1?(s=!0,i=e[d-1].sentTime):e.length<n||0===o?(s=!0,i=o):e.length>0&&e[0].sentTime!==o&&(s=!0,i=r),{isNeedRepair:s,repairTime:i}},t.prototype._processRepairHisMsg=function(e,t,o,r,n,s,i,a){var c=this,u=function(i){for(var u=0===n,p=r+1,d=c._callCppProxy("getMessages",e,t,o,p,u,s),l=JSON.parse(d).list,f=[],h=0;h<l.length;h++){var C=c._buildMessage(l[h].obj);f[h]=C}f.reverse(),a({code:i,data:{list:p<=f.length?f.slice(1,p):f,hasMore:r<f.length}})},p=r+10>100?100:r+10;this._callCppProxy("getRemoteHistoryMessages",e,t,i,p,(function(){return u(0)}),(function(e){u(e)}),n,!0,s,!1)},t.prototype.getContinuousMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;var u=0===s;a._callCppProxy("getContinuousMessages",t,o,r,n,(function(t,o,r){var n=JSON.parse(t).list,s=[];n.reverse();for(var i=0;i<n.length;i++){var u=a._buildMessage(n[i].obj);s[i]=u}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:s,timestamp:o,hasMore:r}})}))}),(function(e){setTimeout((function(){c({code:e})}),0)}),u,i)}))},t.prototype.getRemoteHistoryMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;a._callCppProxy("getRemoteHistoryMessages",t,o,r,n,(function(t,o){var r=JSON.parse(t).list,n=[];r.reverse();for(var s=0;s<r.length;s++){var i=a._buildMessage(r[s].obj);n[s]=i}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:n,hasMore:!!o}})}),0)}),(function(e){setTimeout((function(){c({code:e})}),0)}),s,!0,i,!0)}))},t.prototype.deleteRemoteMessage=function(t,o,r,n){var s=this;return new Promise((function(i){var a=JSON.stringify(r);s._callCppProxy("deleteRemoteHistoryMessages",t,o,a,!1,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),i)}))},t.prototype.deleteRemoteMessageByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearRemoteHistoryMessages",t,o,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),n)}))},t.prototype.clearMessages=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearMessages",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.getConversationList=function(t,o,r,n,s){var i=this;return void 0===s&&(s=""),new Promise((function(t){for(var o=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(o).list,n=[],a=0;a<r.length;a++)n.push(i._buildConversation(r[a].obj));t({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.getConversation=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversation",t,o,r);if(i)s({code:e.ErrorCode.SUCCESS,data:n._buildConversation(i)});else{var a=n._callCppProxy("getHistoryMessages",t,o,0,1,"",!0,r),c=void 0;try{c=JSON.parse(a).list}catch(e){n.logger.error(g.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=n._buildMessage(c[0].obj));var p=n._callCppProxy("getConversationNotificationStatus",t,o,r),d=n._callCppProxy("getConversationTopStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:{conversationType:t,targetId:o,channelId:r,unreadMessageCount:0,latestMessage:u,notificationStatus:p?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(t,o,r){var n=this._callCppProxy("removeConversation",t,o,r);return Promise.resolve(n?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.batchRemoveConversation=function(t){var o=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId}})),r=this._callCppProxy("removeConversationInBatches",JSON.stringify(o));return Promise.resolve(r?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.clearConversations=function(t,o){var r=this;return new Promise((function(n){var s=[];s=e.isArray(t)?t:[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.PUBLIC_SERVICE],r._callCppProxy("clearConversations",s,o||""),n(e.ErrorCode.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(t,o,r){var n=this._callCppProxy("getTotalUnreadCount",o,r,t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){var i=n._callCppProxy("getUnreadCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){n._callCppProxy("clearUnreadCount",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearUnreadCountByTimestamp",t,o,r,n),i(e.ErrorCode.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),a=n._buildMessage(i);s({code:e.ErrorCode.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.getFirstUnreadMessageInfo=function(t,o,r){var n=this;return new Promise((function(s,i){var a=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),c=n._buildMessage(a);s({code:e.ErrorCode.SUCCESS,data:-1!==c.messageId?{messageUId:c.messageUId,sentTime:c.sentTime}:null})}))},t.prototype.batchSetConversationToTop=function(t,o,r){var n=this;return new Promise((function(s,i){var a=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,is_top:o}}));n._callCppProxy("setIsTopInBatches",JSON.stringify(a),r||!1),s(e.ErrorCode.SUCCESS)}))},t.prototype.setConversationStatus=function(t,o,r,n,s,i){var a=this;return new Promise((function(i){a._callCppProxy("setConversationStatus",t,o,r,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),s,!0)}))},t.prototype.getConversationNotificationStatus=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversationNotificationStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE})}))},t.prototype.searchConversationByContent=function(t,o,r,n){var s=this;return new Promise((function(i){n=n||[1,3,6,7];for(var a=s._callCppProxy("searchConversationByContent",n,t,o,r),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=s._buildConversation(c[p].obj);i({code:e.ErrorCode.SUCCESS,data:u})}))},t.prototype.searchConversationByContentWithAllChannel=function(t,o,r){var n=this;return new Promise((function(s){r=r||[1,3,6,7];for(var i=n._callCppProxy("searchConversationByContentWithAllChannel",r,t,o),a=JSON.parse(i).list,c=[],u=0;u<a.length;u++)c[u]=n._buildConversation(a[u].obj);s({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.searchMessageByContent=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(i){c._callCppProxy("searchMessageByContent",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=c._buildMessage(r[s].obj);setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}),a)}))},t.prototype.searchMessageByContentAndMessageType=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){for(var p=c._callCppProxy("searchMessageByContentAndObjectName",o,t,a||"",void 0===a,r,i,s,n),d=p?JSON.parse(p).list:[],l=[],f=0;f<d.length;f++)l[f]=c._buildMessage(d[f].obj);u({code:e.ErrorCode.SUCCESS,data:{messages:l}})}))},t.prototype.searchMessagesByUser=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){a._callCppProxy("getMessageBySender",t,o,r,n,s,i,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=a._buildMessage(o[n].obj);setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.searchMessageByContentWithAllChannel=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("searchMessageByContentWithAllChannel",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=i._buildMessage(r[s].obj);setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByTimestampWithAllChannel",t,o,r,n,s,i,a,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=c._buildMessage(o[n].obj);setTimeout((function(){u({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.getUnreadMentionedMessages=function(e,t,o){for(var r=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,n=0;n<r.length;n++)r[n]=this._buildMessage(r[n].obj);return r},t.prototype.addToBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addToBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.removeFromBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("removeFromBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getBlacklist=function(){var t=this;return new Promise((function(o){t._callCppProxy("getBlacklist",(function(t){setTimeout((function(){o({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){o({code:e})}),0)}))}))},t.prototype.getBlacklistStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getBlacklistStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.insertMessage=function(t,o,r){var n=this,s=r.content,i=r.senderUserId,a=r.messageType,c=r.messageDirection,u=r.readStatus,p=r.sentStatus,d=r.sentTime,l=r.searchContent,f=r.isUnread,h=r.messageUId,C=r.disableNotification,g=r.canIncludeExpansion,v=r.expansionMsg,S=r.channelId,y=r.directedUserIds;s=JSON.stringify(s);var _={};if(d=d||0,v){var m=JSON.parse(v);for(var E in m)_[E]={v:"",ts:0},_[E].v=m[E],_[E].ts=d}return new Promise((function(r){var v=f?0:1,m=n._callCppProxy("insertMessage",t,o,i,a,s,(function(){}),(function(e){setTimeout((function(){r({code:e})}),0)}),c,u||0,p||10,d,l||"",v,h||"",!!C,!!g,JSON.stringify(_),S||"",y||[]),E=n._buildMessage(m,{isOffLineMessage:!1});E.messageUId=h,E.sentTime=d,r({code:-1===E.messageId?e.ErrorCode.MSG_INSERT_ERROR:e.ErrorCode.SUCCESS,data:E})}))},t.prototype.batchInsertMessage=function(t,o){var r=this;return void 0===o&&(o=!1),new Promise((function(n){var s=t.map((function(t){var o=t.content,r=t.senderUserId,n=t.messageType,s=t.messageDirection,i=t.receivedStatus,a=void 0===i?0:i,c=t.sentStatus,u=t.sentTime,p=t.searchContent,d=t.isUnread,l=t.messageUId,f=t.disableNotification,h=t.canIncludeExpansion,C=t.expansion,g=t.channelId,v=t.conversationType,S=t.targetId,y=t.source,_=t.isMentioned,m=t.receivedStatusInfo,E=t.directedUserIds,T=a;m&&(T=e.transformReceivedStatusFlag(m));var P={};if(u=u||0,C)for(var R in C)P[R]={v:"",ts:0},P[R].v=C[R],P[R].ts=u;return{conversationType:v,targetId:S,channelId:g||"",direction:s,senderUserId:r,status:c||10,sentTime:u,objectName:n,content:JSON.stringify(o),messageUid:l||"",noNotification:!!f,supportExt:!!h,extMsg:JSON.stringify(P),readStatus:T,searchContent:p||"",isUnread:!!d,source:y||"",isMention:_,directedUsers:E}})),i=r._callCppProxy("insertMessages",JSON.stringify(s),o);n({code:i?e.ErrorCode.SUCCESS:e.ErrorCode.MSG_INSERT_ERROR,data:i||!1})}))},t.prototype.getMessageCount=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getMessageCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.deleteMessages=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteMessages",t),r(e.ErrorCode.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("deleteMessagesByTimestamp",t,o,r,n,s),a(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearMessagesByTimestamp=function(t){var o=this;return new Promise((function(r,n){var s=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));o._callCppProxy("deleteMessageBySendTimeInBatches",JSON.stringify(s)),r(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearRemoteHistoryMessages=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));r._callCppProxy("deleteRemoteMessageBySendTimeInBatches",JSON.stringify(i),o||!1,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getMessage",t),s=o._buildMessage(n,{isOffLineMessage:!1});r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setMessageContent=function(t,o,r){var n=this;return new Promise((function(s){o=JSON.stringify(o),n._callCppProxy("setMessageContent",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSearchField=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setMessageSearchField",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSentStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageSentStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageReceivedStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("saveTextMessageDraft",t,o,r,n||"")&&i(e.ErrorCode.SUCCESS),i(e.ErrorCode.DRAFT_SAVE_ERROR)}))},t.prototype.getConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTextMessageDraft",t,o,r||"");s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearTextMessageDraft",t,o,r||"")&&s(e.ErrorCode.SUCCESS),s(e.ErrorCode.DRAFT_REMOVE_ERROR)}))},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(t){var o=t[0],r=o.conversationType,n=o.targetId,s=o.isTop,i=o.notificationStatus,a=o.channelId,c=o.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",r,n,a||""),d=this._callCppProxy("getConversationTopStatus",r,n,a||""),l=e.isUndefined(i)?Boolean(p):i===e.NotificationStatus.OPEN,f=e.isUndefined(s)?Boolean(d):s;return this.setConversationStatus(r,n,l,f,a,u)},t.prototype.getConversationNotificationLevel=function(t,o,r){return S(this,void 0,void 0,(function(){var n;return y(this,(function(s){return n=this._callCppProxy("getBlockPushLevelForConversation",o,r,t),[2,Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})]}))}))},t.prototype.setConversationNotificationLevel=function(t,o,r,n){var s=this;return void 0===n&&(n=""),new Promise((function(i){s._callCppProxy("setBlockPushLevelForConversation",o,n,t,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}))}))},t.prototype.batchSetConversationNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,level:o}}));r._callCppProxy("setBlockPushLevelInBatches",JSON.stringify(i),(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getTotalUnreadCountByLevels=function(t,o,r){if(r){var n=this._callCppProxy("getUnreadMentionedCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})}var s=this._callCppProxy("getUnreadCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("sendReadReceipt",t,r||"",o,(function(){o.forEach((function(e){n._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(n._callCppProxy("getMessage",e)).messageId;n.setMessageReceivedStatus(t,1)}catch(t){n.logger.error(g.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReader=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getMessageReader",t,r,o,(function(t,r){var i=[],a={};(t=JSON.parse(t)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;i.push({userId:o,readTime:r}),a[o]=r}));var c={readerInfo:a,readCount:i.length,totalCount:r};n._updateReadReceiptInfo(o,c),setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.sendReadReceiptMessageV4=function(t,o,r){var n=this;return new Promise((function(s){var i=t.conversationType,a=t.targetId,c=t.channelId;n._callCppProxy("sendMessageReadReceipt",i,a,c||"",o,r,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReadReceiptV4=function(t,o){var r=this;return new Promise((function(n){var s=t.targetId,i=t.channelId;r._callCppProxy("getMessageReadReceipt",s,i||"",o,(function(t,s,i){var a=[],c=r._callCppProxy("getMessage",o),u=JSON.parse(c);try{JSON.parse(i).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;a.push({userId:o,readTime:r})}))}catch(e){r.logger.error(g.P_PARSE_JSON_E,"method: getMessageReadReceipt, info: "+i+", error: "+e)}var p=JSON.parse(u.readReceiptRequest||"{}"),d=p.readerList,l=void 0===d?[]:d,f=p.readCount,h=void 0===f?0:f,C=!1;l.length<a.length&&(l=a,C=!0),h<s&&(h=s,C=!0),C&&r._callCppProxy("updateReadReceiptRequestInfo",o,JSON.stringify({readerList:l,readCount:h,totalCount:t})),setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:{list:a,totalCount:t,readCount:h}})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.updateConversationReadTime=function(t,o){var r=this;return new Promise((function(n){var s=t.conversationType,i=t.targetId,a=t.channelId;r._callCppProxy("updateConversationReadTime",s,i,a||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},t.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},t.prototype._try2RejoinChatroom=function(){var t=this;if(0!==this._chatroomCache.length){var o=this.logger.createTraceId();this._chatroomCache.forEach((function(r){return S(t,void 0,void 0,(function(){var t,n,s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return t=r.chatroomId,n=r.joinExist,s=r.count,this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_T,t,o),[4,this._joinChrm(t,s,n,!1)];case 1:return i=u.sent(),a=i.code,c=i.data,a===e.ErrorCode.SUCCESS?(this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_R,t,o),this._sendChatroomStatus({rejoinedRoom:v({chatroomId:t,count:s},c)}),[2]):(a===e.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:t,errorCode:a}}),this.logger.warn(e.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: "+t+", code: "+a,o),[2])}}))}))}))}},t.prototype._joinChrm=function(t,o,r,n){var s=this,i=r?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){n&&s._callCppProxy("clearMessages",e.ConversationType.CHATROOM,t,""),s._callCppProxy(i,t,o,(function(n,i,c,u,p,d){s._addChatroomCache(t,o,r),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{createTime:Number(n),memberCount:i,isAllChatroomBanned:c,isCurrentUserBanned:u,isCurrentChatroomBanned:p,isCurrentChatroomInWhitelist:d}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.joinChatroom=function(e,t){return S(this,void 0,void 0,(function(){return y(this,(function(o){switch(o.label){case 0:return[4,this._joinChrm(e,t,!1,!0)];case 1:return[2,o.sent().code]}}))}))},t.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},t.prototype.quitChatroom=function(t){var o=this;return this._rmChatroomCache(t),new Promise((function(r){o._callCppProxy("quitChatRoom",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getChatroomInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getChatroomInfo",t,o,r,(function(t,o){var r=t?JSON.parse(t).list:[],n=[];if(r.length>0)for(var i=0;i<r.length;i++)n.push(JSON.parse(r[i].obj));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{userInfos:n,userCount:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getChatroomHistoryMessages=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("getChatroomHistoryMessage",t,o,r,n,(function(t){var o;try{o=JSON.parse(t)}catch(e){o={list:[],hasMore:!1}}var r=o.list;if(r&&r.length)try{o.list=r.map((function(e){return s._buildMessage(e.obj)}))}catch(e){o.list=[]}setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}),"")}))},t.prototype.setChatroomEntry=function(t,o){var r=this;return new Promise((function(n){var s='[{"key":"'+o.key+'", "value":"'+o.value+'"}]';r._callCppProxy("setChatroomKV",t,s,!!o.isAutoDelete,!!o.isOverwrite,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.setChatroomEntries=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setChatroomKV",t,JSON.stringify(o.entries),!!o.isAutoDelete,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(t,o){var r=this,n=[o.key];return new Promise((function(s){r._callCppProxy("deleteChatroomKV",t,n,!!o.isOverwrite,(function(){s(e.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(t,o){var r=this;return new Promise((function(n){var s=o.entries.map((function(e){return e.key}));r._callCppProxy("deleteChatroomKV",t,s,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getChatroomEntry=function(t,o){return S(this,void 0,void 0,(function(){var r;return y(this,(function(n){switch(n.label){case 0:return[4,this.getAllChatroomEntry(t)];case 1:return(r=n.sent()).code===e.ErrorCode.SUCCESS?[2,{code:e.ErrorCode.SUCCESS,data:r.data?r.data[o]:null}]:[2,{code:r.code}]}}))}))},t.prototype.getAllChatroomEntry=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getChatroomKV",t,(function(t){var o={};try{(t?JSON.parse(t):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){o[e.key]=e.value?e.value:""}))}catch(e){}setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getFileToken=function(t,o,r,n,s){var i=this;return r=r||"",n=n||"",s=s||"",new Promise((function(a){var c;c=n&&"uploads"!==n?o||"":e.getUploadFileName(t,o),i._callCppProxy("getUploadToken",t,c,r,n,s,(function(t,o,r,n,s,i,u,p,d,l,f,h,C,g,v,S,y,_,m,E,T,P,R){setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{token:t,deadline:0,bosToken:o,bosDate:r,path:n,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:f,s3Policy:h,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:S,stcDate:y,stcBucketName:_,minioAuthorization:m,minioContentSha256:E,minioDate:T,minioBucketName:P,downloadAuthInfo:R?JSON.parse(R):null}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.getFileUrl=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("getDownloadUrl",t,r,n,o-1,(function(t){setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{downloadUrl:t}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.clearData=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("clearData");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getDeviceId=function(){var e=this._dbpath;return ae(e)},t.prototype.getVoIPKey=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("getVoIPKey",t,o,"",(function(t){setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.bindRTCRoomForChatroom=function(t){var o=this;return new Promise((function(r){var n=t.chatRoomId,s=t.rtcRoomId;o._callCppProxy("bindRTCRoomForChatroom",n,s,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getGroupMessageDeliverList=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getGroupMessageDeliverList",t,r,o,(function(t,o){var r=JSON.parse(t).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{totalCount:o,list:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getPrivateMessageDeliverTime=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getMessageDeliverTime",t);if(s)n({code:e.ErrorCode.SUCCESS,data:s});else{r._callCppProxy("getPrivateMessageDeliverList",o,t,(function(t){var o=0,r=JSON.parse(t).list;if(r.length>0){var s=JSON.parse(r[0].obj).time;o=s}setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}}))},t.prototype.rtcSignaling=function(t,o,r,n){var s=this,i=Array.prototype.slice.call(new Uint8Array(n));return new Promise((function(n){s._callCppProxy("rtcSignaling",t,o,r,i,(function(t){var o=new Uint8Array(t).buffer;n({code:e.ErrorCode.SUCCESS,buffer:o})}),(function(e){n({code:e})}),30)}))},t.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var r=e.rtcHeartbeatResolves[t];if(r){var n=r.find((function(e){return""===e.seqId}));n&&(n.seqId=o)}}),(function(t,o,r,n){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===r}));-1!==i&&s.splice(i,1)[0].resolve({code:o,data:{version:Number(n)}})}}))},t.prototype.rtcPing=function(e,t,o){var r=this;return new Promise((function(t){var o={resolve:t,seqId:""},n=r.rtcHeartbeatResolves[e];n?n.push(o):r.rtcHeartbeatResolves[e]=[o],r._callCppProxy("sendRTCHeartbeat",[e],30)}))},t.prototype.createTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.removeTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteTag",t,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.updateTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("renameTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getTagList=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getTags"),n=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));o({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.addTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));r._callCppProxy("addConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),r._callCppProxy("removeConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagsForConversation=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("removeTagsForConversation",t.conversationType,t.targetId,t.channelId||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.getConversationListByTag=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",t,o,r||20,n||""),c=s._convertResultList(a,(function(e){return v(v({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.getUnreadCountByTag=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getConversationUnreadCountForTag",t,o);n({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setConversationStatusInTag=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setConversationToTopForTag",t,o.conversationType,o.targetId,o.channelId||"",r.isTop||!1,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getTagsForConversation=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getTagsForConversation",t.conversationType,t.targetId,t.channelId||""),s=o._convertResultList(n,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(t,o){var r=this;return new Promise((function(n){var s=e.isUndefined(o)?r._callCppProxy("getTopConversations",t):r._callCppProxy("getTopConversations",t,o),i=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}));n({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getUnreadAndMentionCount",[e.ConversationType.GROUP],"");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getOSInfo=function(){return S(this,void 0,void 0,(function(){var t;return y(this,(function(o){return t={arch:f.arch(),platform:f.platform(),type:f.type(),version:f.version(),release:f.release(),uptime:f.uptime(),cpus:f.cpus(),freemem:f.freemem(),totalmem:f.totalmem(),networkInterfaces:f.networkInterfaces()},[2,{code:e.ErrorCode.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return S(this,void 0,void 0,(function(){return y(this,(function(t){return[2,{code:e.ErrorCode.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},t.prototype.setCallInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("callInfoSignaling",t,o,r,(function(t,o){setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{key:t,value:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.setProxy=function(t){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:e.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(W(t,this.logger))},t.prototype.getProxy=function(){return Promise.resolve(Q())},t.prototype.testProxy=function(t,o){return function(t,o,r){return new Promise((function(n){var s=/^https/.test(o)?H:F;r.info(e.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:t,testHost:o}));var i=s(o,t,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var o="";e.on("data",(function(e){o+=e})),e.once("end",(function(){n({status:t||0,data:o})}))}));i.once("timeout",(function(){return n({status:0})})),i.once("error",(function(e){return n({status:0,data:e.stack})})),i.end()}))}(t,o,this.logger)},t.prototype.checkDuplicateMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("checkDuplicateMessage",t);r({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.subscribeUser=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.SUBSCRIBE,t,(function(){s({code:e.ErrorCode.SUCCESS})}),(function(e,t){s({code:e,data:t})}),r)}))},t.prototype.unSubscribeUser=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.UNSUBSCRIBE,t,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}),0)}))},t.prototype.getSubscribeUserList=function(t,o,r){var n=this._callCppProxy("getSubscribeUserList",t,o,r),s=this._buildSubscribeEventData(n).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.getSubscribeUserStatus=function(t,o){var r=this._callCppProxy("getSubscribeStatusByUserIds",t,o),n=this._buildSubscribeEventData(r).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getMatchedMessage=function(t,o,r,n){var s,i=this._callCppProxy("getMatchedMessage",t.conversationType,t.targetId,o,r,n,t.channelId||""),a=[];try{s=JSON.parse(i).list;for(var c=0;c<s.length;c++){var u=this._buildMessage(s[c].obj);a.push(u)}}catch(t){return this.logger.error(g.P_PARSE_JSON_MSGS_E,i),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:a})},t}(),Se=function(e){return{sendError:function(t){e.send({type:Y.ERROR,data:{msg:t}})},sendEvent:function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];e.send({type:Y.EVENT,data:{eventName:t,data:o}})},sendResponse:function(t){e.send({type:Y.RESPONSE,data:t})},sendCallback:function(t){e.send({type:Y.CALLBACK,data:t})}}},ye=r.resolve(__dirname,"binding","electron-"+t.platform()+"-"+t.arch()+".node"),_e={addon:null},me=Se(process).sendError;try{_e.addon=require(ye)}catch(e){console.error("error ->",ye,"\n",e),me(e.toString())}_e.addon||console.error("error -> cannot find module: ",ye);var Ee=_e.addon;!function(t){var o=this,r=t.argv.slice(2),n=r[0],s=r[1],i=r[2],a=Se(t),c=a.sendCallback,u=a.sendError,p=a.sendEvent,d=a.sendResponse,l=Ee?new ve(n,Ee,s,p,~~i):null;t.on("message",(function(t){return S(o,void 0,void 0,(function(){var o,r,n,s,i,a;return y(this,(function(u){switch(u.label){case 0:return o=t.reqId,r=t.method,n=t.args,s=t.hasResponse,l?s?("sendMessage"===r&&(i=n[3],n[3]=function(e){c({reqId:i,data:e})}),[4,l.callProxy.apply(l,_([r],n,!1))]):[3,2]:[2,d({reqId:o,success:!0,data:{code:e.ErrorCode.ADDON_NOT_EXIST,msg:"Cannot find module "+ye}})];case 1:return a=u.sent(),!0,d({reqId:o,success:true,data:a}),[3,3];case 2:l.sendProxy.apply(l,_([r],n,!1)),u.label=3;case 3:return[2]}}))}))})),t.on("beforeExit",(function(e){null==l||l.destroy()})),t.on("uncaughtException",(function(e){u("uncaughtException "+(e.stack||e.toString()))})),t.on("unhandledRejection",(function(e){u("unhandledRejection "+e.stack)}))}(process);
|
|
1
|
+
"use strict";var e=require("@rongcloud/engine"),t=require("os"),o=require("child_process"),r=require("path"),n=require("http"),s=require("https"),i=require("url"),a=require("net"),c=require("events"),u=require("tls"),p=require("fs"),d=require("crypto");function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var f=l(t),h=function(e,t){return h=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},h(e,t)};function C(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}h(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var g,v=function(){return v=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},v.apply(this,arguments)};function S(e,t,o,r){return new(o||(o=Promise))((function(n,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))}function y(e,t){var o,r,n,s,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){i.label=a[1];break}if(6===a[0]&&i.label<n[1]){i.label=n[1],n=a;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(a);break}n[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{o=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function _(e,t,o){if(o||2===arguments.length)for(var r,n=0,s=t.length;n<s;n++)!r&&n in t||(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_ADDON_T="P-call_addon-T",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_R="P-call_addon-R",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_O="P-connect-O",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_PARSE_JSON_MSGS_R="P-parse_json_messsages-R",e.P_RECEIVE_MESSAGE_E="P-receive_message-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_SUBSCRIBE_DATA_E="P-parse_json_subscribe_data-E",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R",e.P_PARSE_JSON_E="P-parse_json-E"}(g||(g={}));var m,E={flushTimestamp:Date.now(),queue:[],locked:!1};function T(){m&&clearInterval(m)}function P(e,t){T(),m=setInterval((function(){return O(e,t)}),1e4)}function R(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=E.queue).push.apply(e,t)}var I=200;function O(e,t){var o=E.queue,r=E.flushTimestamp;if(!(E.locked||0===o.length||Date.now()-r<3e4&&o.length<I)){E.locked=!0;var n=t.createTraceId(),s=t.getSessionId(),i=o.splice(0,I).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,i=e.tag,a=e.loggerId,c=e.content,u=e.traceId;return{level:o,time:r,type:n,tag:i,sessionId:s+":"+t,content:JSON.stringify({loggerId:a,content:c,traceId:u})}}));t.debug(g.P_WRITE_LOG_T,"writingLen: "+i.length+", queueLen: "+o.length,n);var a=JSON.stringify(i);e.writeLog(a),t.debug(g.P_WRITE_LOG_R,"write done, queueLen: "+o.length,n),E.flushTimestamp=Date.now(),E.locked=!1,setTimeout((function(){return O(e,t)}))}}var M=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.flush=function(e){R(e)},t}(e.BasicLogger),N=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.flush=function(e){R(e)},t}(e.BasicStatistic),b=function(e,t){var o,r=Buffer.from(e),n=r.length;for(t.push(n),o=0;o<n;o++)t.push(r[o])},U=function(e){return"string"==typeof e},x=function(e){return U(e)?e.toUpperCase():""},L=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: "+e[0]+".":255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: "+e[1]+"."),o},w=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: "+e[0]+".":0!==e[1]&&(t="Username and password authentication failure: "+e[1]+"."),t},A=function(e){var t=x(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var s="";for(var i in s=t+" "+(o+n)+" HTTP/1.1\n",r){if(Object.hasOwnProperty.call(r,i))s+=i+": "+r[i]+"\n"}return e.body&&(s+="Content-Length: "+e.body.length+"\n"),s+="\n","POST"===t&&e.body&&(s+=""+e.body),s},D=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,s=L(r,o);if(!s)return 2===r[1]?(e.socket.once("data",(function(o){var r=w(o);r?e.emit("error",new Error("SOCKS authentication failed. "+r)):t()})),n=[1],b(e.socksUsername,n),b(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. "+s))})),o=[0],e.socksUsername&&o.push(2),(r=Buffer.alloc(2+o.length))[0]=5,r[1]=o.length,o.forEach((function(e,t){r[2+t]=e})),e.write(r)}))},k=function(e,t,o){return new Promise((function(r){var n,s;switch(e.socket.once("data",(function(t){var o;5!==t[0]?o="Unexpected SOCKS version number: "+t[0]+".":0!==t[1]?o=function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code "+e}}(t[1])+".":0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. "+o)):r()})),(n=[]).push(5),n.push(1),n.push(0),a.isIP(t)){case 0:n.push(3),b(t,n);break;case 4:n.push(1),function(e,t){var o,r,n=e.split(".");for(o=0;o<4;o++)r=parseInt(n[o],10),t.push(r)}(t,n);break;case 6:e.emit("error",new Error("Does not support IPV6"))}n.length+=2,(s=Buffer.from(n)).writeUInt16BE(o,s.length-2),e.write(s)}))},J=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new a.Socket,o.options=t,o.socksHost=t.socksHost||"localhost",o.socksPort=t.socksPort||1080,o.socksUsername=t.socksUsername||"",o.socksPassword=t.socksPassword||"",o.socket.on("error",(function(e){o.emit("error",e)})),o.on("error",(function(){o.socket.destroyed||o.socket.destroy()})),o.on("end",o.end),o}return C(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var o=this.socket.end(e,t);return this.writable=this.socket.writable,o},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,o){return this.socket.write(e,t,o)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var o=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: "+e);if(!t||"string"!=typeof t)throw new TypeError("Invalid host: "+t);return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return S(o,void 0,void 0,(function(){var o;return y(this,(function(r){switch(r.label){case 0:return[4,D(this)];case 1:return r.sent(),[4,k(this,t,e)];case 2:return r.sent(),this.onProxied(),o=A(this.options),this.socket.write(Buffer.from(o)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(c.EventEmitter),B=function(e){var t,o=e.hostname,r=e.port;return!e.host||o&&r||(t=e.host.split(":")),!r&&t&&(r=parseInt(t[1],10)||0),!o&&t&&(o=t[0]),new J(e).connect(r,o)},j=function(e){function t(t){var o=e.call(this)||this;return o.createConnection=B,o}return C(t,e),t}(n.Agent),F=function(e,t,o){return(t=v(v({},t),i.parse(e))).port||(t.port=80),t.agent=new j(t),n.request(t,o)},V=function(e){var t,o;return t=B(e),o=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=u.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},H=function(e){function t(t,o){var r=e.call(this,o)||this;return r.url=t,r.socksHost=o.socksHost||"localhost",r.socksPort=o.socksPort||1080,r.createConnection=V,r}return C(t,e),t}(s.Agent),q=function(e,t,o,r){var n,i;return t.protocol="https:",!t.port&&t.host&&(n=t.host.split(":"),t.port=n[0],t.port=n[1]),t.port||(t.port=443),i=new H(e,t),t.agent=i,s.request(e,t,o)},G=null;function K(t,o,r){void 0===r&&(r=!1);var i=o.url,a=o.headers,c=o.body,u=o.method,p=o.query,d=o.timeout,l=void 0===d?e.HTTP_TIMEOUT:d;return new Promise((function(o){var d=/^https/.test(i),f={headers:a,method:u};d&&(f.rejectUnauthorized=r);var h=null;G?((f=v(v({},f),G)).body=c,h=d?q:F):(h=n.request,d&&(f.agent=new s.Agent(f),h=s.request));var C=h(e.appendUrl(i,p),f,(function(e){var t=e.statusCode,r="";e.setEncoding("utf8"),e.on("data",(function(e){r+=e})),e.once("end",(function(){o({status:t||0,data:r})}))}));C.once("timeout",(function(){t.warn(g.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:i,method:u,query:p,timeout:l})),o({status:0})})),C.setTimeout(l),C.once("error",(function(e){t.warn(g.P_HTTP_REQ_E,JSON.stringify({msg:e.stack,url:i,method:u,query:p,timeout:l})),o({status:0})})),C.write(c),C.end()}))}function W(t,o){return t?(G=v(v({},G),t),o.info(e.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:G})),{code:e.ErrorCode.SUCCESS}):(G=null,o.info(e.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:e.ErrorCode.SUCCESS})}function Q(){var t=G||void 0;return{code:e.ErrorCode.SUCCESS,data:t}}var Y,X=[],z=!1,$=function(){return S(void 0,void 0,void 0,(function(){var t,o,r,n,s,i,a,c,u,p,d,l,f;return y(this,(function(h){return z||0===X.length||(z=!0,t=X.shift(),o=t.args,r=t.resolve,n=o.addon,s=o.startTime,i=o.endTime,a=o.level,c=o.realtimeReport,u=0,p=0,d=[],l=function(t){u+=t.length;var o=t.split(","),n=o[0],s=o[1],i=o[2],l=o[3],f=o[4],h=o.slice(5);if(u>e.REAT_TIME_LOG_SIZE&&parseInt(s,10)!==p)r(d);else{p=parseInt(s,10);try{if(!c&&a<0)return;var C={time:parseInt(s,10),level:parseInt(l,10),sessionId:n,type:i,tag:f,content:h.join(",")};d.push(C)}catch(e){console.error(e)}}},f=function(e){r(d),z=!1,$()},n.getFullLog(a,s,i,!1,l,f)),[2]}))}))},Z=function(t){function o(o,r,n,s,i){var a=this,c="Electron|"+process.versions.electron+"|"+process.arch+"|"+process.platform;return(a=t.call(this,r,n,c,{getLogs:function(e,t,r,n){return S(this,void 0,void 0,(function(){return y(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:t,level:r,realtimeReport:n,addon:o},S(void 0,void 0,void 0,(function(){return y(this,(function(e){return[2,new Promise((function(e){X.push({resolve:e,args:i}),$()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var t=o.getStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(t,10)||0},setTimestamp4RealtimeLog:function(t){o.setStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP,t.toString())}},s)||this).subProcess=i,a}return C(o,t),o.prototype.send=function(e){return K(this.logger,e)},o.prototype.compressLogs=function(e){return S(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=n.sent(),o=t.success,r=t.data,o?[2,{success:o,data:r.data}]:[2,{success:o,data:""}]}}))}))},o}(e.BasicReporter),ee=[e.EConnectProtocol.RMTP,e.EConnectProtocol.TLS,e.EConnectProtocol.QUIC],te=function(e){return"RongCloud/navis/"+e+"/navi-cache.json"},oe="deviceId",re=function(e){return"RongCloud/caches/"+e+"/staticConfig.json"},ne=function(e){return"RongCloud/cloudControl/"+e+"/cloudControl.json"},se=null,ie=function(){var e,o=Date.now(),r=[t.arch(),t.platform(),process.pid,o,Math.floor(Math.random()*o)].join("__");return e=r,d.createHash("md5").update(e).digest("hex")},ae=function(e){if(se)return se;var t=r.resolve(e,oe);return p.existsSync(t)?se=p.readFileSync(t).toString():(se=ie(),p.writeFileSync(t,se),se)},ce=function(){function e(e){this._callCppProxy=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,s){var i=JSON.stringify(n);"{}"!==i&&e.info(g.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._callCppProxy("setMessageExtension",t,o,r,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime,c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,r,n,s,c,o||"")},e.prototype.setLocalFromExtMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._callCppProxy("getMessage",a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var f=d[l];f&&f.ts<i-this._setTime?(f.v=c[l],f.ts=i-this._setTime):(d[l]={v:"",ts:0},d[l].v=c[l],d[l].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete d[e]})),this._setToProtocol(e,r,n,a.mid,d,o||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var r in t)o[r]=t[r].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),r={};for(var n in o)r[n]=o[n].v;return r},e}();!function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(Y||(Y={}));var ue=function(){function t(t,o,r,n){var s=this;this.p=t,this.emit=o,this.callback=r,this.errorHandle=n,this.count=0,this.maps={},this.p.on("message",(function(e){var t=e.type,i=e.data;switch(t){case Y.EVENT:var a=i,c=a.eventName,u=a.data;null==o||o.apply(void 0,_([c],u,!1));break;case Y.RESPONSE:var p=i,d=p.reqId,l=p.success,f=p.data,h=s.maps[d];if(!h)return;h({success:l,data:f}),delete s.maps[d];break;case Y.CALLBACK:null==r||r(i);break;case Y.ERROR:var C=i.msg;null==n||n(C)}})),this.p.on("error",(function(e){null==n||n("SubProcessProxy error "+e)})),this.p.on("exit",(function(t,o){if(0!==t){for(var r in s.maps){if(Object.prototype.hasOwnProperty.call(s.maps,r))(0,s.maps[r])({success:!0,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==n||n("SubProcessProxy exit "+t+" "+o,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return t.prototype.call=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r=this;return y(this,(function(n){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(e){var n=++r.count;r.maps[n]=e;var s={reqId:n,method:t,args:o,hasResponse:!0};r.p.send(s)}))]}))}))},t.prototype.send=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r;return y(this,(function(n){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),r={reqId:-1,method:e,args:o},this.p.send(r),[2]}))}))},t.prototype.destroy=function(){this.send("destroy")},t}();function pe(e){void 0===e&&(e="IPv4");for(var o=t.networkInterfaces(),r=[],n=0,s=Object.values(o);n<s.length;n++){var i=s[n];if(i&&-1!==Object.prototype.toString.call(i).indexOf("Array")){var a=i.filter((function(t){return!(t.internal||(o=t.mac,/^(0{1,2}[:-]){5}0{1,2}$/.test(o))||t.family&&t.family!==e);var o})).map((function(e){return e.mac}));r.push.apply(r,a)}}return r.length?r.sort()[0]:""}var de,le=function(e,t,o){return S(void 0,void 0,void 0,(function(){var r,n;return y(this,(function(s){return r=d.createDecipheriv("aes-256-cbc",t,o),n=r.update(e,"base64","utf-8"),[2,n+=r.final("utf8")]}))}))},fe=function(e){if(!p.existsSync(e)){var t=r.resolve(e,"..");p.existsSync(t)||fe(t),p.mkdirSync(e)}},he=function(t){function o(e,o,n,s,i){var a=t.call(this,e,o,n,i)||this;a.naviPath="",a._caches={},a.naviPath=s+"/"+te(e);var c=r.dirname(a.naviPath);return p.existsSync(c)||fe(c),a}return C(o,t),o.prototype.httpRequest=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c,u;return y(this,(function(p){switch(p.label){case 0:return s="token="+encodeURIComponent(r)+"&v="+e.FORMATED_VERSION+"&p=PC&ev=5.9.9&m="+pe(),i=t+"/navi.json?r="+Date.now()+"&env="+this._environment,this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:i,body:s}),n),[4,K(this.logger,{method:"POST",headers:{appId:o},body:s,url:i,timeout:e.NAVI_REQ_TIMEOUT})];case 1:if(200!==(a=p.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,code:a.status}),n),[2,{code:this.transHttpCode(a.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,data:a.data}),n);try{return c=JSON.parse(a.data),u=/^https/.test(i)?"https":"http",c.protocol=u,c.code&&200!==c.code?[2,{code:this.transHttpCode(c.code)}]:[2,{code:e.ErrorCode.SUCCESS,data:c}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,a.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.httpRequestV2=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return s=this.getNaviV2RequestOption({appkey:o,token:r,uri:t,platform:"electron",protocol:ee.join(","),mac:pe()}),this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:s.url,body:s.body,headers:s.headers}),n),[4,K(this.logger,s)];case 1:if(200!==(i=u.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,code:i.status}),n),[2,{code:this.transHttpCode(i.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,data:i.data}),n);try{return a=JSON.parse(i.data),c=/^https/.test(s.url)?"https":"http",a.protocol=c,[2,{code:e.ErrorCode.SUCCESS,data:a}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,i.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.getNaviCache=function(t){var o=this.getCatchKey(t),r=this._caches[o];if(r)return r;if(!p.existsSync(this.naviPath))return null;var n=p.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(n),this._caches[o]}catch(t){this.logger.error(e.LogTagId.L_PARSE_NAVI_E,n)}return null},o.prototype.setNaviCache=function(t,o){var r=Date.now(),n=this.getCatchKey(t);if(e.notEmptyObject(this._caches))for(var s in this._caches){(r-this._caches[s].timestamp>e.NAVI_CACHE_DURATION||n===s)&&delete this._caches[s]}this._caches[n]={token:t,naviInfo:o,timestamp:Date.now(),environment:this._environment},p.writeFileSync(this.naviPath,JSON.stringify(this._caches))},o.prototype.setEnvironment=function(e){this._environment=e},o}(e.BasicNavi);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(de||(de={}));var Ce,ge=function(t){function o(o,r,n,s,i,a){var c=t.call(this,o,n,s,i,a)||this;return c.callCppProxy=r,c._connectedTime=0,c._naviInfo=null,c._excludeLogTag=["P-RCGetValueForKey-T","P-RCGetValueForKey-E","P-RCGetValueForKey-R","P-RCSetValueForKey-T","P-RCSetValueForKey-E","P-RCSetValueForKey-R"],c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.callCppProxy("setConnectionStatusListener",c._onConnectionStatusChange.bind(c),(function(e){c.logger.info(g.P_DB_OPEN_O,e)}),(function(){return c.recvPong(e.ErrorCode.SUCCESS)}),c._onConnectionStatusChange.bind(c),c._onTcpConnectResponse.bind(c)),c}return C(o,t),o.prototype.getConnectedTime=function(){return this._connectedTime},o.prototype.connectWithToken=function(t,o,r,n){var s=this;return new Promise((function(i){s._naviInfo=o,s.connectResolve={resolve:i,traceId:n,userId:o.userId};var a={},c=Q().data;c&&(a={proxy_passwd:c.socksPassword||"",proxy_name:c.socksUsername||"",proxy_port:c.socksPort||1082,proxy_host:c.socksHost||"localhost",proxy_type:0});var u=JSON.stringify(v(v({},a),{call_plus:s._openCallPlus})),p=s.getCmpList(o,!0).filter((function(e){return ee.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(t){var o=d.find((function(e){return e.addr===t.addr}));o?o.protocol!==e.EConnectProtocol.QUIC&&t.protocol!==e.EConnectProtocol.QUIC||(o.race=!0,o.protocol=e.EConnectProtocol.QUIC):(t.race=!1,d.push(t))})),s.logger.info(g.P_CONNECT_O,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:e.FORMATED_VERSION,reconnectKickEnable:r}),n),s._startTime=Date.now();try{s.callCppProxy("connectWithToken",t,e.FORMATED_VERSION,JSON.stringify(v(v({},o),{serverAddr:d,tagBlacklist:s._excludeLogTag.join(",")})),r,u)}catch(t){s.logger.error(g.P_CALL_ADDON_E,null==t?void 0:t.stack,n),s.recvConnectRes(e.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},o.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.callCppProxy("disconnect",t)},o.prototype.sendPing=function(t){var o=this;return new Promise((function(r){o.pingResolve=r,o.callCppProxy("sendHeartbeat"),setTimeout((function(){return o.recvPong(e.ErrorCode.TIMEOUT)}),t)}))},o.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},o.prototype._onConnectionStatusChange=function(t,o){switch(this.logger.info(g.P_CONNECT_S,JSON.stringify({status:t,delay:o})),t){case e.ErrorCode.SUCCESS:this.recvConnectRes(e.ErrorCode.SUCCESS);break;case e.ErrorCode.RC_CONN_REDIRECTED:case 32061:this.recvConnectRes(e.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case e.ErrorCode.RC_SOCKET_DISCONNECTED:this.recvConnectRes(t,!1);break;case e.ErrorCode.RC_SOCKET_NOT_CREATED:case e.ErrorCode.RC_CONN_ACK_TIMEOUT:case e.ErrorCode.RC_TCP_RESET:this.recvConnectRes(t);break;case e.ErrorCode.RC_UDP_DISCONNECTED:this.recvConnectRes(t,!0,o);break;default:this.recvConnectRes(t,!0)}},o.prototype.recvConnectRes=function(t,o,r){if(this.connectResolve){var n=this.connectResolve,s=n.resolve,i=n.userId,a=Date.now()-(this._startTime+this._tcpDuration),c={bid:e.getbundleId(),cod:t,net:this.getNetwork().type,dur:a,spr:0,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,count:this.retryCount};return this.statisticLog.record(e.StatisticsTag.IM_CMP_RMTP,JSON.stringify(c)),t===e.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.callCppProxy("getDeltaTime")),s({code:t,data:i}),void(this.connectResolve=null)}if(o)this.onDisconnectByServer(t,r);else{if(t===e.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(t)}},o.prototype._onTcpConnectResponse=function(t,o,r,n,s,i,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr===o+":"+r})),p={bid:e.getbundleId(),ptc:e.ProtocalType.TCP,cod:t,net:this.getNetwork().type,dur:n,spr:0,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:o+":"+r,idx:u,rct:this.retryCount?e.ConnectType.RECONNECT:e.ConnectType.CONNECT,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,rsn:this.reason,ddu:s,count:this.retryCount,weight:u>=0?this.cmpWeightCache[u].weight:-1};this.statisticLog.record(e.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(g.P_CONNECT_ENTRY_S,JSON.stringify({code:t,host:o,port:r,duration:n,dnsDuration:s,index:i,isQuic:a})),t===de.SUCCESS&&(this.curCmpUrl=o+":"+r,this.updateCmpWeight(o+":"+r,!0,a))},o}(e.AConnectionMgr),ve=function(t){function o(e,o,n){var s=t.call(this,e,o)||this;s.appkey=e,s.logger=o,s.dbpath=n,s._cachePath="",s._cachePath=n+"/"+re(e);var i=r.dirname(s._cachePath);return p.existsSync(i)||fe(i),s}return C(o,t),o.prototype.getCache=function(){return p.existsSync(this._cachePath)&&p.readFileSync(this._cachePath,{encoding:"utf8"})||null},o.prototype.setCache=function(e){p.writeFileSync(this._cachePath,e)},o.prototype.clearCache=function(){p.writeFileSync(this._cachePath,"")},o.prototype.sendRequest=function(e){return S(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,K(this.logger,{url:e,body:""})];case 1:return t=n.sent(),o=t.status,r=t.data,[2,{code:o,data:r}]}}))}))},o.prototype.decryptData=function(t){return S(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,le(t,e.STATIC_CONFIG_KEY,e.STATIC_CONFIG_IV)];case 1:return o=n.sent(),[2,JSON.parse(o)];case 2:return r=n.sent(),this.logger.error(e.LogTagId.L_GET_STATIC_CONF_E,JSON.stringify({error:null==r?void 0:r.stack})),[3,3];case 3:return[2]}}))}))},o}(e.BasicStaticConfigManager),Se=function(t){function o(e,o,n,s,i,a,c){var u=t.call(this,o,e,n,a)||this;u.deviceId=s,u.model="",u.catchFilePath="",u.addon=c,u.model="Electron|"+process.platform+"|"+process.arch,u.catchFilePath=i+"/"+ne(e);var d=r.dirname(u.catchFilePath);return p.existsSync(d)||fe(d),u.init(),u}return C(o,t),o.prototype.httpRequest=function(t,o,r,n){return S(this,void 0,void 0,(function(){var s,i,a,c,u,p,d,l;return y(this,(function(f){switch(f.label){case 0:return(s=n).deviceId=this.deviceId,s.model=this.model,i={url:t,method:o,headers:r,body:JSON.stringify(s)},this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify(i)),[4,K(this.logger,i)];case 1:a=f.sent(),c=a.status,u=a.data,p=void 0===u?"":u,this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({status:c,data:p}));try{return d=JSON.parse(p),l=d.data,[2,{code:c,data:l}]}catch(t){return this.logger.warn(e.LogTagId.L_CLOUD_CONFIG_DATA_E,JSON.stringify({status:c,data:p,error:t})),[2,{code:c,msg:t}]}return[2]}}))}))},o.prototype.setCloudControllerCache=function(t){p.writeFileSync(this.catchFilePath,JSON.stringify(t)),this.logger.info(e.LogTagId.L_CLOUD_SET_CACHE_O,JSON.stringify(t))},o.prototype.getLocalCloudControllerCache=function(){if(!p.existsSync(this.catchFilePath))return null;var t=p.readFileSync(this.catchFilePath,{encoding:"utf8"});return this.logger.info(e.LogTagId.L_CLOUD_GET_CACHE_O,JSON.stringify({appkey:this.appkey,data:t})),t},o.prototype.setMRTRConfig=function(t){var o={mrtrChatroom:t.chatroom,mrtrGroup:t.group,mrtrPrivate:t.private,mrtrUltraGroup:t.ultraGroup};this.logger.info(e.LogTagId.L_CLOUD_SET_MRTR_O,JSON.stringify(o)),this.addon.setCloudConfig(JSON.stringify(o))},o}(e.BaseCloudController);!function(e){e[e.cuid=1]="cuid",e[e.uid=2]="uid",e[e.all=4]="all"}(Ce||(Ce={}));var ye=function(){function t(t,n,s,i,a){var c=this;this._appkey=t,this._cppProtocol=n,this._dbpath=s,this._dispatchEvent=i,this._logOutputLevel=a,this._customMessageType={},this.cloudControllerUri="",this.cloudControllerLock=!0,this.cloudControllerMsgs=[],this._buildSubscribeEventData=function(e){var t=[];try{JSON.parse(e).list.forEach((function(e){var o=JSON.parse(e.obj),r=o.userId,n=o.subscribeType,s=o.subscribeTime,i=o.duration,a=o.operationType,c=o.details,u=void 0===c?[]:c;t.push({userId:r,subscribeType:n,subscribeTime:s,duration:i,operationType:a,details:u.map((function(e){var t=JSON.parse(e);return{changeTime:t.changeTime,eventValue:t.changeValue,platform:t.platform}}))})}))}catch(t){c.logger.error(g.P_PARSE_JSON_SUBSCRIBE_DATA_E,JSON.stringify({error:null==t?void 0:t.stack,data:e}))}return t},this._chatroomCache=[],this.rtcHeartbeatResolves={};var u=this._dbpath,p=ae(u);this.logger=new M(this._appkey,"RC-M","IM"),this._cppProtocol.initWithAppkey(t,u,e.FORMATED_VERSION,this.logger.getSessionId());var d=o.fork(r.resolve(__dirname,"sub-process.js"));this.subProxy=new ue(d),this.statisticLog=new N(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),P(this._cppProtocol,this.logger),this.reporter=new Z(this._cppProtocol,t,p,this.logger,this.subProxy),this.logger.info(g.P_INIT_O,JSON.stringify({appkey:t,dbpath:u,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:p,commit:"ac04313edeb4b97f5b9015d75bbe9396b2781d95"})),this._callCppProxy("setDeviceId",p),this._staticConfigManager=new ve(t,this.logger,u),this.navi=new he(t,this.logger,this.statisticLog,u,this._staticConfigManager),this.tcpMgr=new ge(t,this._callCppProxy.bind(this),this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this)}),this._initCloudController(p,u),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setSubscribeEventListener(),this._msgExpansionHandler=new ce(this._callCppProxy.bind(this))}return t.prototype._initCloudController=function(t,o){var r=e.urlCenter.getCloudControllerUrl();this.cloudControllerUri=r[0],this.cloudController=new Se(this._appkey,this.logger,this.reporter,t,o,this.statisticLog,this._cppProtocol),e.isStartCloudController()&&this.cloudControllerUri&&this.cloudController.request(this.cloudControllerUri,e.InvokerType.init)},t.prototype.callProxy=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return S(this,void 0,void 0,(function(){var r,n,s;return y(this,(function(i){switch(i.label){case 0:if(!(r=this[t]))return this.logger.warn(g.P_CALL_MAIN_E,JSON.stringify({method:t,error:"not found"})),[2,Promise.resolve({code:e.ErrorCode.NOT_SUPPORT})];n="",i.label=1;case 1:return i.trys.push([1,3,,4]),[4,r.call.apply(r,_([this],o,!1))];case 2:return[2,i.sent()];case 3:return s=i.sent(),n=JSON.stringify({error:null==s?void 0:s.stack,method:t}),this.logger.error(g.P_CALL_MAIN_E,n),[3,4];case 4:return[2,{code:e.ErrorCode.MAIN_PROCESS_ERROR,msg:n}]}}))}))},t.prototype.sendProxy=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return S(this,void 0,void 0,(function(){var o;return y(this,(function(r){if(!(o=this[e]))return this.logger.warn(g.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2];try{o.call.apply(o,_([this],t,!1))}catch(t){this.logger.error(g.P_CALL_MAIN_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return[2]}))}))},t.prototype.registerRenderers=function(t){var o=t.navigators,r=t.areaCode,n=t.logServerUrl,s=t.environment;this._environment=s||"default",this.navi.setEnvironment(s),e.urlCenter.init({areaCode:r,navigators:o,logServerUrl:n})},t.prototype.onConnected=function(){return S(this,void 0,void 0,(function(){var e,t,o;return y(this,(function(r){switch(r.label){case 0:return e=this.getNaviInfoFromCache(),this.reporter.checkStart(e),this._try2RejoinChatroom(),t=this._dispatchEvent,o=["onConnected"],[4,this.getMainProcessCache()];case 1:return t.apply(this,o.concat([r.sent()])),[2]}}))}))},t.prototype.onConnecting=function(){this._dispatchEvent("onConnecting",void 0)},t.prototype.onSuspend=function(e){this._dispatchEvent("onSuspend",e)},t.prototype.onDisconnected=function(e){this._dispatchEvent("onDisconnected",e)},t.prototype._callCppProxy=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this.logger.createTraceId();try{return this.logger.debug(g.P_CALL_ADDON_O,JSON.stringify({method:e,content:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){throw this.logger.error(g.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n),t}},t.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},t.prototype.sendHTTPRequest=function(e){return K(this.logger,e)},t.prototype.onRendererLogsReceived=function(e){R.apply(void 0,e)},t.prototype.onRendererNetworkStatusReceived=function(t,o){if(this.tcpMgr.setNetwork(t,o),t.status&&e.isStartCloudController()&&this.cloudController){var r=this.tcpMgr.getToken();this.cloudController.request(this.cloudControllerUri,e.InvokerType.newWorkChange,r)}},t.prototype.destroy=function(){this.reporter.stop(),this.subProxy.destroy(),this._cppProtocol,T(),this._cppProtocol.destroy(),process.exit(0)},t.prototype.callExtra=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this[t];if(!n)return this.logger.warn(g.P_CALL_EXTRA_E,JSON.stringify({method:t,error:"not found"})),Promise.resolve({code:e.ErrorCode.NOT_SUPPORT});try{return n.call.apply(n,_([this],o,!1))}catch(e){this.logger.error(g.P_CALL_EXTRA_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(t,o,r,n,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",t,o,r,s||!1,n||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.getUnreadConversationList=function(t){var o,r=this,n=this._callCppProxy("getUnreadConversationList",t);try{o=JSON.parse(n).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t.prototype.getConversationListWithAllChannel=function(){var t,o=this,r=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],n=this._callCppProxy("getConversationListWithAllChannel",r);try{t=JSON.parse(n).list.map((function(e){return o._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},t.prototype.getConversationListWithAllChannelByPage=function(t,o){var r,n=this,s=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,t,o);try{r=JSON.parse(i).list.map((function(e){return n._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},t.prototype.getHistoryMessagesByObjectNames=function(t,o,r,n,s,i,a){var c=0===i,u=n+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",t,o,r,u,s,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var f=0;f<l.length;f++){var h=this._buildMessage(l[f].obj);d[f]=h}}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:n<d.length}})},t.prototype.updateMessageReceiptStatus=function(t,o,r,n){void 0===n&&(n="");var s=this._callCppProxy("updateMessageReceiptStatus",t,o,r,n);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},t.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new M(this._appkey,e,t)},t.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},t.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId(),n=this.getDeviceId(),s=this._cppProtocol.getDeltaTime();return Promise.resolve({connectedTime:e,deviceId:n,crtUserId:r,naviInfo:o,connectionStatus:t,deltaTime:s})},t.prototype._registerMsgTypes=function(){for(var t in e.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},e.SEND_MESSAGE_TYPE_OPTION){var o=e.SEND_MESSAGE_TYPE_OPTION[t],r=o.isCounted,n=o.isPersited,s=o.searchProps,i=0;n&&(i|=1),r&&(i|=2),"RC:TypSts"===t&&(i=16),this._callCppProxy("registerMessageType",t,i,s||[])}},t.prototype._buildIsMentioned=function(t,o){var r,n=!1;if(e.isObject(t))r=t;else try{r=t?JSON.parse(t):t}catch(e){r=t,this.logger.error(g.P_PARSE_JSON_MSGS_E,JSON.stringify({content:t}))}return e.isObject(r)&&(n=!!r.mentionedInfo),{isMentioned:n,msgContent:r}},t.prototype._buildMsgOption=function(t){var o={isCounted:!1,isPersited:!1};return t in e.SEND_MESSAGE_TYPE_OPTION?o=e.SEND_MESSAGE_TYPE_OPTION[t]:t in this._customMessageType&&(o=this._customMessageType[t]),o},t.prototype._buildSupportExt=function(e,t,o){var r=null;return e&&(r=this._msgExpansionHandler.parseReceiveExpansion(o),"conversation"!==t&&"history"!==t||(r=this._msgExpansionHandler.parseConverOrHisExpansion(o))),r},t.prototype._handleReadReceiptRequest=function(e){var t=JSON.parse(e),o=this.getNaviInfoFromCache();if(!(null==o?void 0:o.grpRRVer))return t;var r=t,n=r.hasRespond,s=r.readerInfo,i=void 0===s?{}:s,a=r.readCount,c=r.totalCount,u=r.readerList,p=void 0===u?[]:u,d={readCount:a,totalCount:c};if(1===(null==o?void 0:o.grpRRVer)){var l=[];for(var f in i)l.push({userId:f,readTime:i[f]});d.readerList=l,d.hasRespond=n}return 3===(null==o?void 0:o.grpRRVer)&&(d.readerList=p),d},t.prototype._buildMessage=function(t,o){var r;void 0===o&&(o={});var n=o.isOffLineMessage,s=o.buildFrom,i=JSON.parse(t),a=i.channelId,c=i.conversationType,u=i.targetId,p=i.senderUserId,d=i.content,l=i.objectName,f=i.messageUid,h=i.direction,C=i.status,g=i.messageId,S=i.sentTime,y=i.readReceiptRequest,_=i.supportExt,m=i.pushContent,E=i.pushTitle,T=i.pushId,P=i.pushConfig,R=i.templateId,I=i.disableTitle,O=i.forcePushDetail,M=i.hasMore,N=i.directedUsers,b=i.noNotification,U=this._buildIsMentioned(d,g),x=U.isMentioned,L=U.msgContent,w=this._buildMsgOption(l),A=this._buildSupportExt(_,s,i),D=e.isUndefined(n)?S<this.tcpMgr.getConnectedTime():n,k={};P&&(k=e.pushJSONToConfigs(this.logger,P,T));var J=v(v({},k),{pushTitle:E,pushContent:m,pushData:m,disablePushTitle:I,forceShowDetailContent:O,templateId:R}),B={channelId:a,conversationType:c,targetId:u,senderUserId:p,content:L||{},messageType:l,messageUId:f||"",messageDirection:h,isOffLineMessage:D,sentTime:S,receivedTime:0,isPersited:w.isPersited,isCounted:w.isCounted,isMentioned:x,disableNotification:b,isStatusMessage:(null===(r=this._customMessageType[l])||void 0===r?void 0:r.isStatusMessage)||!1,canIncludeExpansion:_,expansion:_?A:null,receivedStatus:C,receivedStatusInfo:e.transformReceivedStatusInfo(C),messageId:g,pushConfig:J,hasMore:M,directedUserIds:N||[]};if(h===e.MessageDirection.RECEIVE?B.receivedStatus=this._compatibleReceivedStatus(B.receivedStatusInfo):h===e.MessageDirection.SEND&&(B.sentStatus=C),y){var j=this._handleReadReceiptRequest(y);B.readReceiptInfo=j}return B},t.prototype._compatibleReceivedStatus=function(t){var o=e.ReceivedStatus.UNREAD;return t.isRead?o=e.ReceivedStatus.READ:t.isListened?o=e.ReceivedStatus.LISTENED:t.isDownload?o=e.ReceivedStatus.DOWNLOADED:t.isRetrieved&&(o=e.ReceivedStatus.RETRIEVED),o},t.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},s=v(v({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},t.prototype._processRRRspMsg=function(e,t,o){if(t!==this.getCurrentUserId())for(var r=0,n=e[this.getCurrentUserId()]||[];r<n.length;r++){h=n[r];var s=this._callCppProxy("getMessage",h),i=JSON.parse(s),a=i.readReceiptRequest?JSON.parse(i.readReceiptRequest):{},c=a.isReceiptRequestMessage,u=a.readerList,p=void 0===u?[]:u;c&&!p.includes(t)&&(p.push(t),this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:c,readerList:p})))}else for(var d in e)for(var l=0,f=e[d];l<f.length;l++){var h=f[l];this._callCppProxy("updateReadReceiptRequestInfo",h,JSON.stringify({isReceiptRequestMessage:!0,hasRespond:!0}))}},t.prototype._processRSMsg=function(t){var o=t.conversationType,r=t.targetId,n=t.content,s=t.channelId,i=n.msgId,a=n.rrn,c=n.tmn,u=n.endMsgTime;o===e.ConversationType.PRIVATE?this.updateMessageReceiptStatus(o,r,u,s||""):this._updateReadReceiptInfo(i,{readCount:a,totalCount:c});var p={conversationType:o,targetId:r,channelId:s};this._sendMessageReadReceipt(o===e.ConversationType.PRIVATE?{privateReadReceipt:v(v({},p),{endMsgTime:n.endMsgTime})}:{groupReadReceipt:v(v({},p),{totalCount:n.tmn,readedCount:n.rrn,messageUId:n.msgId})})},t.prototype._processSRSMsg=function(e){var t=this.getNaviInfoFromCache(),o=e.conversationType,r=e.targetId,n=e.content,s=e.channelId,i=e.senderUserId,a=e.sentTime;return i===this.tcpMgr.getCurrentUserId()&&(this._callCppProxy("clearUnreadCountByTimestamp",o,r,n.lastMessageSendTime,s||""),1!==(null==t?void 0:t.sesDriven)||(a>this.tcpMgr.getConnectedTime()||this._sendsyncReadStatus({conversationType:o,targetId:r,channelId:s,timestamp:n.lastMessageSendTime}),!1))},t.prototype._buildConversation=function(t){var o=JSON.parse(t),r=o.channelId,n=o.conversationType,s=o.targetId,i=o.unreadCount,a=o.lastestMsg,c=o.isTop,u=o.blockStatus,p=o.matchCount,d=o.hasUnreadMention,l=o.conversationTime,f=o.draft,h=u>0?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE;return{channelId:r,conversationType:n,targetId:s,unreadMessageCount:i,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:d,mentionedInfo:null,notificationStatus:h,isTop:c,lastUnreadTime:0,matchCount:p,operationTime:l,notificationLevel:u,draft:f}},t.prototype._convertResultList=function(e,t){var o=JSON.parse(e).list;return o=o.map((function(e){var o=JSON.parse(e.obj);return t?t(o):o}))},t.prototype._handleNotNotificationMessage=function(t){var o,r=t.messageType,n=t.senderUserId,s=t.content;if(r===e.MessageType.LOG_COMMAND&&t.senderUserId===e.RC_DEFAULT_USER){var i=t.content,a=i.startTime,c=i.endTime,u=i.platform,p=i.logId,d=i.uri;return this.reporter.report(parseInt(a,10),parseInt(c,10),u,d,p,t.messageUId),!0}if(r===e.MessageType.CLOUD_CONTROL&&n===e.RC_DEFAULT_USER)return this.cloudControllerMsgs.push(t),this._ccMsgHandler(),!0;if(r===e.MessageType.READ_STATE)return this._processRSMsg(t),!0;if("RC:MsgExMsg"===r)return this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),this._sendMessageExpansion(t),!0;if(r===e.MessageType.SYNC_READ_STATUS&&!this._processSRSMsg(t))return!0;if(r===e.MessageType.DELIVERED)return this._callCppProxy("setMessageDeliverTime",JSON.stringify(s)),this._sendMessageDelivered(t.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}}))),!0;if(r===e.MessageType.DELIVERED_MSG){var l={totalCount:t.content.tmn,list:null===(o=t.content.dl)||void 0===o?void 0:o.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};return this._sendGroupMessageDeliveredStatus(l),!0}return!1},t.prototype._setOnReceiveMessageListener=function(){var t=this;this._cppProtocol.setOnReceiveMessageListener((function(o,r,n,s){try{var i=t._buildMessage(o,{isOffLineMessage:n}),a=i.messageType,c=i.channelId,u=void 0===c?"":c,p=i.senderUserId,d=i.content,l=i.sentTime,f=i.conversationType,h=i.targetId;if(t._handleNotNotificationMessage(i))return;if(a===e.MessageType.READ_RECEIPT_REQUEST&&d.messageUId&&t._updateReadReceiptInfo(d.messageUId,{isReceiptRequestMessage:!0,hasRespond:!1}),a===e.MessageType.READ_RECEIPT_RESPONSE&&d.receiptMessageDic&&t._processRRRspMsg(d.receiptMessageDic,p,l),a===e.MessageType.GROUP_READ_RECEIPT_REQUEST){var C=d.msgId,v=d.rrn,S=d.tmn;t._updateReadReceiptInfo(C,{readCount:v,totalCount:S})}i.canIncludeExpansion&&t._msgExpansionHandler.setLocalFromReceiveMsg(t.logger,i),a===e.MessageType.READ_RECEIPT&&p===t.tcpMgr.getCurrentUserId()&&t._callCppProxy("clearUnreadCountByTimestamp",f,h,d.lastMessageSendTime,u);var y=!0;if(0!==r||s||(y=!1),a===e.MessageType.RECALL){if(!t.handleRecalledMessage(i))return;var _=t._fixRecallContentInfo(i);f=_.conversationType,h=_.targetId}t._sendMessageNotification(Object.assign(i,{hasMoreMsg:y,conversationType:f,targetId:h}))}catch(e){t.logger.error(g.P_RECEIVE_MESSAGE_E,JSON.stringify({error:null==e?void 0:e.stack,message:o}))}}),(function(){t._sendPullOfflineFinished()}))},t.prototype._ccMsgHandler=function(){var t;return S(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return this.cloudControllerLock?(this.cloudControllerLock=!1,this.cloudControllerMsgs.shift()?(o=this.tcpMgr.getToken(),[4,null===(t=this.cloudController)||void 0===t?void 0:t.request(this.cloudControllerUri,e.InvokerType.other,o)]):[3,2]):[2];case 1:r=n.sent()||0,this.cloudControllerMsgs=this.cloudControllerMsgs.filter((function(e){return e.sentTime>r})),this.cloudControllerLock=!0,this._ccMsgHandler(),n.label=2;case 2:return[2]}}))}))},t.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,o=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,o=e.content.targetId||o),{conversationType:t,targetId:o}},t.prototype.handleRecalledMessage=function(t){var o=t.content,r=o.messageUId,n=o.sentTime;if(!r)return!0;var s=this._callCppProxy("getMessage",r),i=this._buildMessage(s,{isOffLineMessage:!1});if(t.content.isDelete)return-1===i.messageId||this._callCppProxy("deleteMessages",[i.messageId]),!0;if(i.messageType===e.MessageType.RECALL_NOTIFICATION_MESSAGE)return!1;var a={recallTime:Date.now(),admin:!!t.content.isAdmin,originalObjectName:i.messageType,originalMessageContent:i.content,recallActionTime:t.sentTime,operatorId:t.senderUserId};if(t.content.user&&(a.user=t.content.user),t.content.extra&&(a.extra=t.content.extra),i.messageType===e.MessageType.TextMessage&&(a.recallContent=i.content.content),-1===i.messageId){var c=t.conversationType,u=t.targetId,p=t.senderUserId,d=t.channelId,l=t.messageDirection;return this._callCppProxy("insertMessage",c,u,p,e.MessageType.RECALL_NOTIFICATION_MESSAGE,JSON.stringify(a),(function(){}),(function(){}),l,1,30,n,"",0,r,!1,!0,JSON.stringify({}),d||""),!0}return i.receivedStatus||this.setMessageReceivedStatus(i.messageId,1),this._callCppProxy("setMessageContent",i.messageId,JSON.stringify(a),e.MessageType.RECALL_NOTIFICATION_MESSAGE),!0},t.prototype._sendMessageExpansion=function(e){var t=e.channelId,o=void 0===t?"":t,r=e.content,n=e.conversationType,s=e.targetId,i=r,a=i.put,c=i.del,u=i.mid,p={};a&&(p.updatedExpansion={channelId:o,messageUId:u,expansion:a,conversationType:n,targetId:s}),c&&(p.deletedExpansion={channelId:o,messageUId:u,deletedKeys:c,conversationType:n,targetId:s}),this._dispatchEvent("expansion",p)},t.prototype._sendMessageNotification=function(e){this._dispatchEvent("batchMessage",e)},t.prototype._sendPullOfflineFinished=function(){this._dispatchEvent("pullFinished",null)},t.prototype._sendMessageDelivered=function(e){this._dispatchEvent("messageDelivered",e)},t.prototype._sendGroupMessageDeliveredStatus=function(e){this._dispatchEvent("groupMessageDeliveredStatus",e)},t.prototype._sendChatroomStatus=function(e){this._dispatchEvent("chatroom",e)},t.prototype._sendMessageReadReceipt=function(e){this._dispatchEvent("messageReadReceipt",e)},t.prototype._sendsyncReadStatus=function(e){this._dispatchEvent("syncReadStatus",e)},t.prototype._setConversationStatusListener=function(){var t=this;this._cppProtocol.setConversationStatusListener((function(o){var r=JSON.parse(o).list,n=[];r.forEach((function(t){var o=JSON.parse(t.obj),r=o.conversationType,s=o.targetId,i=o.status,a=o.channelId,c={notificationStatus:2,isTop:!1};i.forEach((function(t){var o=JSON.parse(t.item);1===o.type?c.notificationStatus=1===Number(o.value)?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE:c.isTop=1===Number(o.value)})),n.push({channelId:a,conversationType:r,targetId:s,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),t._dispatchEvent("conversation",n)}),(function(e){t._dispatchEvent("conversationTag",e)}),(function(e,o,r,n){t._callCppProxy("clearUnreadCountByTimestamp",e,o,n,r||""),t._sendsyncReadStatus({conversationType:e,targetId:o,channelId:r,timestamp:n})}))},t.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._dispatchEvent("tag",t),e._getRTCProfile()}))},t.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var o=this.navi.getNaviInfoFromCache(t);this._dispatchEvent("onNaviDataChange",o)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){e._dispatchEvent("onRTCDataChange",Array.prototype.slice.call(t))}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},t.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._dispatchEvent("callInfo",t)}))},t.prototype._setSubscribeEventListener=function(){var e=this;this._cppProtocol.setSubscribeEventListener((function(){}),(function(){e._dispatchEvent("syncSubscribedUserStatusFinished")}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,operationType:e.operationType}}));e._dispatchEvent("subscribedRelationChange",o)}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,details:e.details}}));e._dispatchEvent("subscribedUserStatusChange",o)}))},t.prototype._updateMentionedInfo=function(t,o,r){var n,s,i;return{userIdList:(null===(n=t.mentionedInfo)||void 0===n?void 0:n.userIdList)||o,type:(null===(s=t.mentionedInfo)||void 0===s?void 0:s.type)||r||e.MentionedType.ALL,mentionedContent:(null===(i=t.mentionedInfo)||void 0===i?void 0:i.mentionedContent)||""}},t.prototype.registerMessageType=function(e,t,o,r,n){var s=0;t&&(s|=1),o&&(s|=2),n&&(s=16),this._customMessageType[e]={isCounted:o,isPersited:t,isStatusMessage:n},this.logger.info(g.P_REGTYP_O,JSON.stringify({type:e,opt:s,search:r})),this._callCppProxy("registerMessageType",e,s,r||[])},t.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},t.prototype.reportSDKInfo=function(e){var t=JSON.stringify(v(v({},e),{"electron-main":"5.9.9"}));this.logger.info(g.P_REPORT_VER_O,t),this._callCppProxy("uploadSDKVersion",t,"")},t.prototype.disconnect=function(e){e=e||!0,this._chatroomCache.length=0,this.reporter.stop(),W(null,this.logger),this.tcpMgr.disconnect(e)},t.prototype.logout=function(){this.disconnect()},t.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,o){t({userId:e,status:o})}));var o=e.userIds||[];o.length&&this.subscribeUserStatus(o)},t.prototype.subscribeUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("subscribeUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.setUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("setUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getUserStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:{status:t}})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype._handleDirectionalUserIdList=function(t){var o=t.messageType,r=t.content,n=t.directionalUserIdList,s=void 0===n?[]:n;if(o===e.MessageType.READ_RECEIPT_RESPONSE&&r.receiptMessageDic)for(var i in r.receiptMessageDic)s.push(i);return o===e.MessageType.SYNC_READ_STATUS&&(s=[this.getCurrentUserId()]),s},t.prototype._handleMessage2Callback=function(t,o){var r=this;if("RC:MsgExMsg"===t.messageType&&this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),t.messageType===e.MessageType.READ_RECEIPT_REQUEST)this._updateReadReceiptInfo(o.content.messageUId,{isReceiptRequestMessage:!0,readerList:[]});else if(t.messageType===e.MessageType.READ_RECEIPT_RESPONSE){var n=o.content.receiptMessageDic;if(!n)return;for(var s in n)n[s].forEach((function(e){r._updateReadReceiptInfo(e,{isReceiptRequestMessage:!0,hasRespond:!0})}))}},t.prototype.sendMessage=function(t,o,r,n,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=r.messageType,c=r.content,u=r.expansion,p=r.pushConfig,d=r.isMentioned,l=r.mentionedType,f=r.mentionedUserIdList,h=void 0===f?[]:f,C=r.pushContent,v=void 0===C?"":C,S=r.pushData,y=void 0===S?"":S,_=r.directionalUserIdList,m=void 0===_?[]:_,E=r.disableNotification,T=void 0!==E&&E,P=r.canIncludeExpansion,R=void 0!==P&&P,I=r.isVoipPush,O=void 0!==I&&I,M=r.channelId,N=void 0===M?"":M,b=r.messageId,U=void 0===b?0:b,x=p||{},L=x.iOSConfig,w=x.androidConfig,A=x.templateId,D=void 0===A?"":A,k=x.pushTitle,J=void 0===k?"":k,B=x.pushContent,j=void 0===B?v:B,F=x.pushData,V=void 0===F?y:F,H=x.disablePushTitle,q=void 0!==H&&H,G=x.forceShowDetailContent,K=void 0!==G&&G,W=e.pushConfigsToJSON(L,w);return new Promise((function(p){v=j,y=V;var f=(null==w?void 0:w.notificationId)||"",C=t===e.ConversationType.GROUP;C&&d&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,h,l)),C&&(m=i._handleDirectionalUserIdList(r));var S={};for(var _ in u)S[_]={v:""},S[_].v=u[_];var E=D;i.logger.info(g.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:t,targetId:o,channelId:N}),s);var P=i._callCppProxy("sendMessage",(function(t,o){var n=i._buildMessage(t,{isOffLineMessage:!1});if(i.logger.info(g.P_SEND_MSG_R,JSON.stringify({code:o,messageUId:n.messageUId}),s),o===e.ErrorCode.SENSITIVE_REPLACE)return setTimeout((function(){p({code:o})}),0);[e.MessageType.READ_RECEIPT_REQUEST,e.MessageType.READ_RECEIPT_RESPONSE,e.MessageType.EXPANSION_NOTIFY].findIndex((function(e){return e===n.messageType}))>-1&&i._handleMessage2Callback(n,r),n.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,n),setTimeout((function(){p({code:e.ErrorCode.SUCCESS,data:n})}),0)}),(function(e,t){var o=i._buildMessage(e,{isOffLineMessage:!1});i.logger.warn(g.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),s),o.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),setTimeout((function(){p({code:t,data:o})}),0)}),t,o,a,JSON.stringify(c),m,T,q,K,v,y,f,J,W,E,R,JSON.stringify(S),O,N,U),I=JSON.parse(P);null==n||n(I.messageId)}))},t.prototype.recallMsg=function(t,o,r,n,s){var i=this;return new Promise((function(a){var c,u=s.user,p=s.pushContent,d=s.channelId,l=s.extra,f=s.pushConfig,h=s.disableNotification,C=s.isDelete,g=s.directionalUserIdList,v={conversationType:t,targetId:o,messageUId:r,sentTime:n,user:u,extra:l,channelId:d,isDelete:C||!1};u&&(v.user=u),l&&(v.extra=l);var S={conversationType:t,targetId:o,senderUserId:i.tcpMgr.getCurrentUserId(),content:v,objectName:e.MessageType.RECALL,messageUid:r,direction:e.MessageDirection.SEND,status:e.ReceivedStatus.UNREAD,sentTime:n,channelId:d},y=i._buildMessage(JSON.stringify(S),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){i.handleRecalledMessage(y),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:y})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}),e.MessageType.RECALL,JSON.stringify(v),h||!1,(null==f?void 0:f.disablePushTitle)||!1,(null==f?void 0:f.forceShowDetailContent)||!1,p||"",(null==f?void 0:f.pushData)||"",(null===(c=null==f?void 0:f.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==f?void 0:f.pushTitle)||"",e.pushConfigsToJSON(null==f?void 0:f.iOSConfig,null==f?void 0:f.androidConfig),(null==f?void 0:f.templateId)||"",d,g||[])}))},t.prototype.getHistoryMessage=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){r=r||0;var p=0===s,d=n+1,l=c._callCppProxy("getHistoryMessages",t,o,r,d,a,p,i),f=JSON.parse(l).list,h=[];f.reverse();for(var C=0;C<f.length;C++){var g=c._buildMessage(f[C].obj);h[C]=g}u({code:e.ErrorCode.SUCCESS,data:{list:d===h.length?h.slice(1,d):h,hasMore:n<h.length}})}))},t.prototype.getMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){var u=0===s,p=r,d=0!==r,l=n+1;d&&(p+=u?1:-1,l++);for(var f=a._callCppProxy("getMessages",t,o,p,l,u,i),h=JSON.parse(f).list,C=[],g=0;g<h.length;g++){var v=a._buildMessage(h[g].obj);C[g]=v}var S=a._computeRepairInfo(C,u,r,p,l),y=S.isNeedRepair,_=void 0!==y&&y,m=S.repairTime,E=void 0===m?0:m;if(!_)return d&&(C.shift(),l--),C.reverse(),void c({code:e.ErrorCode.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:n<C.length}});a._processRepairHisMsg(t,o,r,n,s,i,E,c)}))},t.prototype._computeRepairInfo=function(e,t,o,r,n){var s=!1,i=0,a=this.getNaviInfoFromCache()||{},c=a.repairHisMsg,u=void 0===c?0:c,p=a.historyMsg;if(1!==u||!p)return{isNeedRepair:s,repairTime:i};var d=e.findIndex((function(e){return e.hasMore||0===Object.keys(e.content).length}));return t&&d>=0?(s=!0,i=e[d].hasMore?e[d].sentTime:e[d].sentTime+1):!t&&d>=1?(s=!0,i=e[d-1].sentTime):e.length<n||0===o?(s=!0,i=o):e.length>0&&e[0].sentTime!==o&&(s=!0,i=r),{isNeedRepair:s,repairTime:i}},t.prototype._processRepairHisMsg=function(e,t,o,r,n,s,i,a){var c=this,u=function(i){for(var u=0===n,p=r+1,d=c._callCppProxy("getMessages",e,t,o,p,u,s),l=JSON.parse(d).list,f=[],h=0;h<l.length;h++){var C=c._buildMessage(l[h].obj);f[h]=C}f.reverse(),a({code:i,data:{list:p<=f.length?f.slice(1,p):f,hasMore:r<f.length}})},p=r+10>100?100:r+10;this._callCppProxy("getRemoteHistoryMessages",e,t,i,p,(function(){return u(0)}),(function(e){u(e)}),n,!0,s,!1)},t.prototype.getContinuousMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;var u=0===s;a._callCppProxy("getContinuousMessages",t,o,r,n,(function(t,o,r){var n=JSON.parse(t).list,s=[];n.reverse();for(var i=0;i<n.length;i++){var u=a._buildMessage(n[i].obj);s[i]=u}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:s,timestamp:o,hasMore:r}})}))}),(function(e){setTimeout((function(){c({code:e})}),0)}),u,i)}))},t.prototype.getRemoteHistoryMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;a._callCppProxy("getRemoteHistoryMessages",t,o,r,n,(function(t,o){var r=JSON.parse(t).list,n=[];r.reverse();for(var s=0;s<r.length;s++){var i=a._buildMessage(r[s].obj);n[s]=i}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:n,hasMore:!!o}})}),0)}),(function(e){setTimeout((function(){c({code:e})}),0)}),s,!0,i,!0)}))},t.prototype.deleteRemoteMessage=function(t,o,r,n){var s=this;return new Promise((function(i){var a=JSON.stringify(r);s._callCppProxy("deleteRemoteHistoryMessages",t,o,a,!1,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),i)}))},t.prototype.deleteRemoteMessageByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearRemoteHistoryMessages",t,o,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),n)}))},t.prototype.clearMessages=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearMessages",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.getConversationList=function(t,o,r,n,s){var i=this;return void 0===s&&(s=""),new Promise((function(t){for(var o=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(o).list,n=[],a=0;a<r.length;a++)n.push(i._buildConversation(r[a].obj));t({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.getConversation=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversation",t,o,r);if(i)s({code:e.ErrorCode.SUCCESS,data:n._buildConversation(i)});else{var a=n._callCppProxy("getHistoryMessages",t,o,0,1,"",!0,r),c=void 0;try{c=JSON.parse(a).list}catch(e){n.logger.error(g.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=n._buildMessage(c[0].obj));var p=n._callCppProxy("getConversationNotificationStatus",t,o,r),d=n._callCppProxy("getConversationTopStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:{conversationType:t,targetId:o,channelId:r,unreadMessageCount:0,latestMessage:u,notificationStatus:p?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(t,o,r){var n=this._callCppProxy("removeConversation",t,o,r);return Promise.resolve(n?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.batchRemoveConversation=function(t){var o=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId}})),r=this._callCppProxy("removeConversationInBatches",JSON.stringify(o));return Promise.resolve(r?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.clearConversations=function(t,o){var r=this;return new Promise((function(n){var s=[];s=e.isArray(t)?t:[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.PUBLIC_SERVICE],r._callCppProxy("clearConversations",s,o||""),n(e.ErrorCode.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(t,o,r){var n=this._callCppProxy("getTotalUnreadCount",o,r,t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){var i=n._callCppProxy("getUnreadCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){n._callCppProxy("clearUnreadCount",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearUnreadCountByTimestamp",t,o,r,n),i(e.ErrorCode.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),a=n._buildMessage(i);s({code:e.ErrorCode.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.getFirstUnreadMessageInfo=function(t,o,r){var n=this;return new Promise((function(s,i){var a=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),c=n._buildMessage(a);s({code:e.ErrorCode.SUCCESS,data:-1!==c.messageId?{messageUId:c.messageUId,sentTime:c.sentTime}:null})}))},t.prototype.batchSetConversationToTop=function(t,o,r){var n=this;return new Promise((function(s,i){var a=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,is_top:o}}));n._callCppProxy("setIsTopInBatches",JSON.stringify(a),r||!1),s(e.ErrorCode.SUCCESS)}))},t.prototype.setConversationStatus=function(t,o,r,n,s,i){var a=this;return new Promise((function(i){a._callCppProxy("setConversationStatus",t,o,r,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),s,!0)}))},t.prototype.getConversationNotificationStatus=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversationNotificationStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE})}))},t.prototype.setConversationTypeNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){r._callCppProxy("setBlockPushLevelForType",t,o,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getConversationTypeNotificationLevel=function(t){var o=this;return new Promise((function(r,n){var s=o._callCppProxy("getBlockPushLevelForType",t);r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.searchConversationByContent=function(t,o,r,n){var s=this;return new Promise((function(i){n=n||[1,3,6,7];for(var a=s._callCppProxy("searchConversationByContent",n,t,o,r),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=s._buildConversation(c[p].obj);i({code:e.ErrorCode.SUCCESS,data:u})}))},t.prototype.searchConversationByContentWithAllChannel=function(t,o,r){var n=this;return new Promise((function(s){r=r||[1,3,6,7];for(var i=n._callCppProxy("searchConversationByContentWithAllChannel",r,t,o),a=JSON.parse(i).list,c=[],u=0;u<a.length;u++)c[u]=n._buildConversation(a[u].obj);s({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.searchMessageByContent=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(i){c._callCppProxy("searchMessageByContent",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=c._buildMessage(r[s].obj);setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}),a)}))},t.prototype.searchMessageByContentAndMessageType=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){for(var p=c._callCppProxy("searchMessageByContentAndObjectName",o,t,a||"",void 0===a,r,i,s,n),d=p?JSON.parse(p).list:[],l=[],f=0;f<d.length;f++)l[f]=c._buildMessage(d[f].obj);u({code:e.ErrorCode.SUCCESS,data:{messages:l}})}))},t.prototype.searchMessagesByUser=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){a._callCppProxy("getMessageBySender",t,o,r,n,s,i,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=a._buildMessage(o[n].obj);setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.searchMessageByContentWithAllChannel=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("searchMessageByContentWithAllChannel",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=i._buildMessage(r[s].obj);setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByTimestampWithAllChannel",t,o,r,n,s,i,a,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=c._buildMessage(o[n].obj);setTimeout((function(){u({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.getUnreadMentionedMessages=function(e,t,o){for(var r=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,n=0;n<r.length;n++)r[n]=this._buildMessage(r[n].obj);return r},t.prototype.addToBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addToBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.removeFromBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("removeFromBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getBlacklist=function(){var t=this;return new Promise((function(o){t._callCppProxy("getBlacklist",(function(t){setTimeout((function(){o({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){o({code:e})}),0)}))}))},t.prototype.getBlacklistStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getBlacklistStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.insertMessage=function(t,o,r){var n=this,s=r.content,i=r.senderUserId,a=r.messageType,c=r.messageDirection,u=r.readStatus,p=r.sentStatus,d=r.sentTime,l=r.searchContent,f=r.isUnread,h=r.messageUId,C=r.disableNotification,g=r.canIncludeExpansion,v=r.expansionMsg,S=r.channelId,y=r.directedUserIds;s=JSON.stringify(s);var _={};if(d=d||0,v){var m=JSON.parse(v);for(var E in m)_[E]={v:"",ts:0},_[E].v=m[E],_[E].ts=d}return new Promise((function(r){var v=f?0:1,m=n._callCppProxy("insertMessage",t,o,i,a,s,(function(){}),(function(e){setTimeout((function(){r({code:e})}),0)}),c,u||0,p||10,d,l||"",v,h||"",!!C,!!g,JSON.stringify(_),S||"",y||[]),E=n._buildMessage(m,{isOffLineMessage:!1});E.messageUId=h,E.sentTime=d,r({code:-1===E.messageId?e.ErrorCode.MSG_INSERT_ERROR:e.ErrorCode.SUCCESS,data:E})}))},t.prototype.batchInsertMessage=function(t,o){var r=this;return void 0===o&&(o=!1),new Promise((function(n){var s=t.map((function(t){var o=t.content,r=t.senderUserId,n=t.messageType,s=t.messageDirection,i=t.receivedStatus,a=void 0===i?0:i,c=t.sentStatus,u=t.sentTime,p=t.searchContent,d=t.isUnread,l=t.messageUId,f=t.disableNotification,h=t.canIncludeExpansion,C=t.expansion,g=t.channelId,v=t.conversationType,S=t.targetId,y=t.source,_=t.isMentioned,m=t.receivedStatusInfo,E=t.directedUserIds,T=a;m&&(T=e.transformReceivedStatusFlag(m));var P={};if(u=u||0,C)for(var R in C)P[R]={v:"",ts:0},P[R].v=C[R],P[R].ts=u;return{conversationType:v,targetId:S,channelId:g||"",direction:s,senderUserId:r,status:c||10,sentTime:u,objectName:n,content:JSON.stringify(o),messageUid:l||"",noNotification:!!f,supportExt:!!h,extMsg:JSON.stringify(P),readStatus:T,searchContent:p||"",isUnread:!!d,source:y||"",isMention:_,directedUsers:E}})),i=r._callCppProxy("insertMessages",JSON.stringify(s),o);n({code:i?e.ErrorCode.SUCCESS:e.ErrorCode.MSG_INSERT_ERROR,data:i||!1})}))},t.prototype.getMessageCount=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getMessageCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.deleteMessages=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteMessages",t),r(e.ErrorCode.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("deleteMessagesByTimestamp",t,o,r,n,s),a(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearMessagesByTimestamp=function(t){var o=this;return new Promise((function(r,n){var s=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));o._callCppProxy("deleteMessageBySendTimeInBatches",JSON.stringify(s)),r(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearRemoteHistoryMessages=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));r._callCppProxy("deleteRemoteMessageBySendTimeInBatches",JSON.stringify(i),o||!1,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getMessage",t),s=o._buildMessage(n,{isOffLineMessage:!1});r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setMessageContent=function(t,o,r){var n=this;return new Promise((function(s){o=JSON.stringify(o),n._callCppProxy("setMessageContent",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSearchField=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setMessageSearchField",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSentStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageSentStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageReceivedStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("saveTextMessageDraft",t,o,r,n||"")&&i(e.ErrorCode.SUCCESS),i(e.ErrorCode.DRAFT_SAVE_ERROR)}))},t.prototype.getConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTextMessageDraft",t,o,r||"");s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearTextMessageDraft",t,o,r||"")&&s(e.ErrorCode.SUCCESS),s(e.ErrorCode.DRAFT_REMOVE_ERROR)}))},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(t){var o=t[0],r=o.conversationType,n=o.targetId,s=o.isTop,i=o.notificationStatus,a=o.channelId,c=o.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",r,n,a||""),d=this._callCppProxy("getConversationTopStatus",r,n,a||""),l=e.isUndefined(i)?Boolean(p):i===e.NotificationStatus.OPEN,f=e.isUndefined(s)?Boolean(d):s;return this.setConversationStatus(r,n,l,f,a,u)},t.prototype.getConversationNotificationLevel=function(t,o,r){return S(this,void 0,void 0,(function(){var n;return y(this,(function(s){return n=this._callCppProxy("getBlockPushLevelForConversation",o,r,t),[2,Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})]}))}))},t.prototype.setConversationNotificationLevel=function(t,o,r,n){var s=this;return void 0===n&&(n=""),new Promise((function(i){s._callCppProxy("setBlockPushLevelForConversation",o,n,t,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}))}))},t.prototype.batchSetConversationNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,level:o}}));r._callCppProxy("setBlockPushLevelInBatches",JSON.stringify(i),(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getTotalUnreadCountByLevels=function(t,o,r){if(r){var n=this._callCppProxy("getUnreadMentionedCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})}var s=this._callCppProxy("getUnreadCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("sendReadReceipt",t,r||"",o,(function(){o.forEach((function(e){n._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(n._callCppProxy("getMessage",e)).messageId;n.setMessageReceivedStatus(t,1)}catch(t){n.logger.error(g.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReader=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getMessageReader",t,r,o,(function(t,r){var i=[],a={};(t=JSON.parse(t)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;i.push({userId:o,readTime:r}),a[o]=r}));var c={readerInfo:a,readCount:i.length,totalCount:r};n._updateReadReceiptInfo(o,c),setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.sendReadReceiptMessageV4=function(t,o,r){var n=this;return new Promise((function(s){var i=t.conversationType,a=t.targetId,c=t.channelId;n._callCppProxy("sendMessageReadReceipt",i,a,c||"",o,r,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReadReceiptV4=function(t,o){var r=this;return new Promise((function(n){var s=t.targetId,i=t.channelId;r._callCppProxy("getMessageReadReceipt",s,i||"",o,(function(t,s,i){var a=[],c=r._callCppProxy("getMessage",o),u=JSON.parse(c);try{JSON.parse(i).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;a.push({userId:o,readTime:r})}))}catch(e){r.logger.error(g.P_PARSE_JSON_E,"method: getMessageReadReceipt, info: "+i+", error: "+e)}var p=JSON.parse(u.readReceiptRequest||"{}"),d=p.readerList,l=void 0===d?[]:d,f=p.readCount,h=void 0===f?0:f,C=!1;l.length<a.length&&(l=a,C=!0),h<s&&(h=s,C=!0),C&&r._callCppProxy("updateReadReceiptRequestInfo",o,JSON.stringify({readerList:l,readCount:h,totalCount:t})),setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:{list:a,totalCount:t,readCount:h}})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.updateConversationReadTime=function(t,o){var r=this;return new Promise((function(n){var s=t.conversationType,i=t.targetId,a=t.channelId;r._callCppProxy("updateConversationReadTime",s,i,a||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},t.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},t.prototype._try2RejoinChatroom=function(){var t=this;if(0!==this._chatroomCache.length){var o=this.logger.createTraceId();this._chatroomCache.forEach((function(r){return S(t,void 0,void 0,(function(){var t,n,s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return t=r.chatroomId,n=r.joinExist,s=r.count,this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_T,t,o),[4,this._joinChrm(t,s,n,!1)];case 1:return i=u.sent(),a=i.code,c=i.data,a===e.ErrorCode.SUCCESS?(this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_R,t,o),this._sendChatroomStatus({rejoinedRoom:v({chatroomId:t,count:s},c)}),[2]):(a===e.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:t,errorCode:a}}),this.logger.warn(e.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: "+t+", code: "+a,o),[2])}}))}))}))}},t.prototype._joinChrm=function(t,o,r,n){var s=this,i=r?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){n&&s._callCppProxy("clearMessages",e.ConversationType.CHATROOM,t,""),s._callCppProxy(i,t,o,(function(n,i,c,u,p,d){s._addChatroomCache(t,o,r),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{createTime:Number(n),memberCount:i,isAllChatroomBanned:c,isCurrentUserBanned:u,isCurrentChatroomBanned:p,isCurrentChatroomInWhitelist:d}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.joinChatroom=function(e,t){return S(this,void 0,void 0,(function(){return y(this,(function(o){switch(o.label){case 0:return[4,this._joinChrm(e,t,!1,!0)];case 1:return[2,o.sent().code]}}))}))},t.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},t.prototype.quitChatroom=function(t){var o=this;return this._rmChatroomCache(t),new Promise((function(r){o._callCppProxy("quitChatRoom",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getChatroomInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getChatroomInfo",t,o,r,(function(t,o){var r=t?JSON.parse(t).list:[],n=[];if(r.length>0)for(var i=0;i<r.length;i++)n.push(JSON.parse(r[i].obj));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{userInfos:n,userCount:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getChatroomHistoryMessages=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("getChatroomHistoryMessage",t,o,r,n,(function(t){var o;try{o=JSON.parse(t)}catch(e){o={list:[],hasMore:!1}}var r=o.list;if(r&&r.length)try{o.list=r.map((function(e){return s._buildMessage(e.obj)}))}catch(e){o.list=[]}setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}),"")}))},t.prototype.setChatroomEntry=function(t,o){var r=this;return new Promise((function(n){var s='[{"key":"'+o.key+'", "value":"'+o.value+'"}]';r._callCppProxy("setChatroomKV",t,s,!!o.isAutoDelete,!!o.isOverwrite,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.setChatroomEntries=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setChatroomKV",t,JSON.stringify(o.entries),!!o.isAutoDelete,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(t,o){var r=this,n=[o.key];return new Promise((function(s){r._callCppProxy("deleteChatroomKV",t,n,!!o.isOverwrite,(function(){s(e.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(t,o){var r=this;return new Promise((function(n){var s=o.entries.map((function(e){return e.key}));r._callCppProxy("deleteChatroomKV",t,s,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getChatroomEntry=function(t,o){return S(this,void 0,void 0,(function(){var r;return y(this,(function(n){switch(n.label){case 0:return[4,this.getAllChatroomEntry(t)];case 1:return(r=n.sent()).code===e.ErrorCode.SUCCESS?[2,{code:e.ErrorCode.SUCCESS,data:r.data?r.data[o]:null}]:[2,{code:r.code}]}}))}))},t.prototype.getAllChatroomEntry=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getChatroomKV",t,(function(t){var o={};try{(t?JSON.parse(t):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){o[e.key]=e.value?e.value:""}))}catch(e){}setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getFileToken=function(t,o,r,n,s){var i=this;return r=r||"",n=n||"",s=s||"",new Promise((function(a){var c;c=n&&"uploads"!==n?o||"":e.getUploadFileName(t,o);var u=i.getNaviInfoFromCache(),p={uploadDomain:e.getMinionURL(u,i.logger),env:i._environment};i._callCppProxy("getUploadToken",t,c,r,n,s,JSON.stringify(p),(function(t,o,r,n,s,i,u,p,d,l,f,h,C,g,v,S,y,_,m,E,T,P,R){setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{token:t,deadline:0,bosToken:o,bosDate:r,path:n,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:f,s3Policy:h,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:S,stcDate:y,stcBucketName:_,minioAuthorization:m,minioContentSha256:E,minioDate:T,minioBucketName:P,downloadAuthInfo:R?JSON.parse(R):null}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.getFileUrl=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s.getNaviInfoFromCache(),c={url:e.getMinionURL(a,s.logger)};s._callCppProxy("getDownloadUrl",t,r,n,o-1,JSON.stringify(c),(function(t){setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{downloadUrl:t}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.clearData=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("clearData");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getDeviceId=function(){var e=this._dbpath;return ae(e)},t.prototype.getVoIPKey=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("getVoIPKey",t,o,"",(function(t){setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.bindRTCRoomForChatroom=function(t){var o=this;return new Promise((function(r){var n=t.chatRoomId,s=t.rtcRoomId;o._callCppProxy("bindRTCRoomForChatroom",n,s,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getGroupMessageDeliverList=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getGroupMessageDeliverList",t,r,o,(function(t,o){var r=JSON.parse(t).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{totalCount:o,list:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getPrivateMessageDeliverTime=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getMessageDeliverTime",t);if(s)n({code:e.ErrorCode.SUCCESS,data:s});else{r._callCppProxy("getPrivateMessageDeliverList",o,t,(function(t){var o=0,r=JSON.parse(t).list;if(r.length>0){var s=JSON.parse(r[0].obj).time;o=s}setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}}))},t.prototype.rtcSignaling=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("rtcSignaling",t,o,r,n,(function(t){var o=Array.prototype.slice.call(t);i({code:e.ErrorCode.SUCCESS,buffer:o})}),(function(e){i({code:e})}),30)}))},t.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var r=e.rtcHeartbeatResolves[t];if(r){var n=r.find((function(e){return""===e.seqId}));n&&(n.seqId=o)}}),(function(t,o,r,n){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===r}));-1!==i&&s.splice(i,1)[0].resolve({code:o,data:{version:Number(n)}})}}))},t.prototype.rtcPing=function(e,t,o){var r=this;return new Promise((function(t){var o={resolve:t,seqId:""},n=r.rtcHeartbeatResolves[e];n?n.push(o):r.rtcHeartbeatResolves[e]=[o],r._callCppProxy("sendRTCHeartbeat",[e],30)}))},t.prototype.createTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.removeTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteTag",t,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.updateTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("renameTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getTagList=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getTags"),n=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));o({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.addTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));r._callCppProxy("addConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),r._callCppProxy("removeConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagsForConversation=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("removeTagsForConversation",t.conversationType,t.targetId,t.channelId||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.getConversationListByTag=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",t,o,r||20,n||""),c=s._convertResultList(a,(function(e){return v(v({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.getUnreadCountByTag=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getConversationUnreadCountForTag",t,o);n({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setConversationStatusInTag=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setConversationToTopForTag",t,o.conversationType,o.targetId,o.channelId||"",r.isTop||!1,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getTagsForConversation=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getTagsForConversation",t.conversationType,t.targetId,t.channelId||""),s=o._convertResultList(n,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(t,o){var r=this;return new Promise((function(n){var s=e.isUndefined(o)?r._callCppProxy("getTopConversations",t):r._callCppProxy("getTopConversations",t,o),i=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}));n({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getUnreadAndMentionCount",[e.ConversationType.GROUP],"");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getOSInfo=function(){return S(this,void 0,void 0,(function(){var t;return y(this,(function(o){return t={arch:f.arch(),platform:f.platform(),type:f.type(),version:f.version(),release:f.release(),uptime:f.uptime(),cpus:f.cpus(),freemem:f.freemem(),totalmem:f.totalmem(),networkInterfaces:f.networkInterfaces()},[2,{code:e.ErrorCode.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return S(this,void 0,void 0,(function(){return y(this,(function(t){return[2,{code:e.ErrorCode.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},t.prototype.setCallInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("callInfoSignaling",t,o,r,(function(t,o){setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{key:t,value:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.setProxy=function(t){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:e.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(W(t,this.logger))},t.prototype.getProxy=function(){return Promise.resolve(Q())},t.prototype.testProxy=function(t,o){return function(t,o,r){return new Promise((function(n){var s=/^https/.test(o)?q:F;r.info(e.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:t,testHost:o}));var i=s(o,t,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var o="";e.on("data",(function(e){o+=e})),e.once("end",(function(){n({status:t||0,data:o})}))}));i.once("timeout",(function(){return n({status:0})})),i.once("error",(function(e){return n({status:0,data:e.stack})})),i.end()}))}(t,o,this.logger)},t.prototype.checkDuplicateMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("checkDuplicateMessage",t);r({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.subscribeUser=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.SUBSCRIBE,t,(function(){s({code:e.ErrorCode.SUCCESS})}),(function(e,t){s({code:e,data:t})}),r)}))},t.prototype.unSubscribeUser=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.UNSUBSCRIBE,t,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}),0)}))},t.prototype.getSubscribeUserList=function(t,o,r){var n=this._callCppProxy("getSubscribeUserList",t,o,r),s=this._buildSubscribeEventData(n).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.setDuplicateMessageConfig=function(t){var o=this._callCppProxy("setDuplicateMessageConfig",[e.ConversationType.CHATROOM],Ce.cuid,t);return Promise.resolve({code:o})},t.prototype.getSubscribeUserStatus=function(t,o){var r=this._callCppProxy("getSubscribeStatusByUserIds",t,o),n=this._buildSubscribeEventData(r).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getMatchedMessage=function(t,o,r,n){var s,i=this._callCppProxy("getMatchedMessage",t.conversationType,t.targetId,o,r,n,t.channelId||""),a=[];try{s=JSON.parse(i).list;for(var c=0;c<s.length;c++){var u=this._buildMessage(s[c].obj);a.push(u)}}catch(t){return this.logger.error(g.P_PARSE_JSON_MSGS_E,i),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:a})},t.prototype.getConversations=function(t){var o,r=this,n=t.map((function(e){var t=e.conversationType,o=e.targetId,r=e.channelId;return{targetId:o,channelId:void 0===r?"":r,type:t}})),s=this._callCppProxy("getConversations",JSON.stringify(n));try{o=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return this.logger.error(g.P_PARSE_JSON_MSGS_E,s),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t}(),_e=function(e){return{sendError:function(t){e.send({type:Y.ERROR,data:{msg:t}})},sendEvent:function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];e.send({type:Y.EVENT,data:{eventName:t,data:o}})},sendResponse:function(t){e.send({type:Y.RESPONSE,data:t})},sendCallback:function(t){e.send({type:Y.CALLBACK,data:t})}}},me=r.resolve(__dirname,"binding","electron-"+t.platform()+"-"+t.arch()+".node"),Ee={addon:null},Te=_e(process).sendError;try{Ee.addon=require(me)}catch(e){console.error("error ->",me,"\n",e),Te(e.toString())}Ee.addon||console.error("error -> cannot find module: ",me);var Pe=Ee.addon;!function(t){var o=this,r=t.argv.slice(2),n=r[0],s=r[1],i=r[2],a=_e(t),c=a.sendCallback,u=a.sendError,p=a.sendEvent,d=a.sendResponse,l=Pe?new ye(n,Pe,s,p,~~i):null;t.on("message",(function(t){return S(o,void 0,void 0,(function(){var o,r,n,s,i,a;return y(this,(function(u){switch(u.label){case 0:return o=t.reqId,r=t.method,n=t.args,s=t.hasResponse,l?s?("sendMessage"===r&&(i=n[3],n[3]=function(e){c({reqId:i,data:e})}),[4,l.callProxy.apply(l,_([r],n,!1))]):[3,2]:[2,d({reqId:o,success:!0,data:{code:e.ErrorCode.ADDON_NOT_EXIST,msg:"Cannot find module "+me}})];case 1:return a=u.sent(),!0,d({reqId:o,success:true,data:a}),[3,3];case 2:l.sendProxy.apply(l,_([r],n,!1)),u.label=3;case 3:return[2]}}))}))})),t.on("beforeExit",(function(e){null==l||l.destroy()})),t.on("uncaughtException",(function(e){u("uncaughtException "+(e.stack||e.toString()))})),t.on("unhandledRejection",(function(e){u("unhandledRejection "+e.stack)}))}(process);
|
package/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { EnableLogL } from '@rongcloud/engine';
|
|
|
2
2
|
|
|
3
3
|
declare class RCMainProxy {
|
|
4
4
|
private _rcMain;
|
|
5
|
-
constructor(appkey: string, dbpath: string, logOutputLevel: EnableLogL);
|
|
5
|
+
constructor(appkey: string, dbpath: string, logOutputLevel: EnableLogL, runInMainProcess: boolean);
|
|
6
6
|
/**
|
|
7
7
|
* @deprecated
|
|
8
8
|
*/
|
|
@@ -23,10 +23,10 @@ declare class RCMainProxy {
|
|
|
23
23
|
getServerTime(): number;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
interface IInitOptions {
|
|
27
27
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
* 应用标识 appkey
|
|
29
|
+
*/
|
|
30
30
|
appkey: string;
|
|
31
31
|
/**
|
|
32
32
|
* 指定 C++ 协议栈的数据存储目录,包括消息数据库与日志数据库
|
|
@@ -41,6 +41,15 @@ declare const _default: (options: {
|
|
|
41
41
|
* 设置日志打印级别
|
|
42
42
|
*/
|
|
43
43
|
logOutputLevel?: EnableLogL;
|
|
44
|
-
|
|
44
|
+
/**
|
|
45
|
+
* environment 私有环境配置
|
|
46
|
+
*/
|
|
47
|
+
environment?: string;
|
|
48
|
+
/**
|
|
49
|
+
* 是否在主进程中运行,默认值为 `false`
|
|
50
|
+
*/
|
|
51
|
+
runInMainProcess?: boolean;
|
|
52
|
+
}
|
|
53
|
+
declare const _default: (options: IInitOptions) => RCMainProxy;
|
|
45
54
|
|
|
46
|
-
export { _default as default };
|
|
55
|
+
export { IInitOptions, _default as default };
|
package/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ErrorCode as e,RCConnectionStatus as t,LogL as r}from"@rongcloud/engine";import{ipcMain as n,app as s}from"electron";import{fork as o}from"child_process";import{resolve as i}from"path";function c(e,t,r,n){return new(r||(r=Promise))((function(s,o){function i(e){try{a(n.next(e))}catch(e){o(e)}}function c(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,c)}a((n=n.apply(e,t||[])).next())}))}function a(e,t){var r,n,s,o,i={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(c){return function(a){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(i=0)),i;)try{if(r=1,n&&(s=2&c[0]?n.return:c[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,c[1])).done)return s;switch(n=0,s&&(c=[2&c[0],s.value]),c[0]){case 0:case 1:s=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,n=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(s=i.trys,(s=s.length>0&&s[s.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!s||c[1]>s[0]&&c[1]<s[3])){i.label=c[1];break}if(6===c[0]&&i.label<s[1]){i.label=s[1],s=c;break}if(s&&i.label<s[2]){i.label=s[2],i.ops.push(c);break}s[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],n=0}finally{r=s=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function u(e,t,r){if(r||2===arguments.length)for(var n,s=0,o=t.length;s<o;s++)!n&&s in t||(n||(n=Array.prototype.slice.call(t,0,s)),n[s]=t[s]);return e.concat(n||Array.prototype.slice.call(t))}var p;"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(p||(p={}));var l,d=function(){function t(t,r,n,s){var o=this;this.p=t,this.emit=r,this.callback=n,this.errorHandle=s,this.count=0,this.maps={},this.p.on("message",(function(e){var t=e.type,i=e.data;switch(t){case p.EVENT:var c=i,a=c.eventName,l=c.data;null==r||r.apply(void 0,u([a],l,!1));break;case p.RESPONSE:var d=i,h=d.reqId,_=d.success,f=d.data,y=o.maps[h];if(!y)return;y({success:_,data:f}),delete o.maps[h];break;case p.CALLBACK:var v=i,S=(h=v.reqId,v.data);null==n||n(h,S);break;case p.ERROR:var C=i.msg;null==s||s(C)}})),this.p.on("error",(function(e){null==s||s("SubProcessProxy error "+e)})),this.p.on("exit",(function(t,r){if(0!==t){for(var n in o.maps){if(Object.prototype.hasOwnProperty.call(o.maps,n))(0,o.maps[n])({success:!0,data:{code:e.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==s||s("SubProcessProxy exit "+t+" "+r,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return t.prototype.call=function(t){for(var r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return c(this,void 0,void 0,(function(){var n=this;return a(this,(function(s){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:e.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(e){var s=++n.count;n.maps[s]=e;var o={reqId:s,method:t,args:r,hasResponse:!0};n.p.send(o)}))]}))}))},t.prototype.send=function(e){for(var t,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];return c(this,void 0,void 0,(function(){var n;return a(this,(function(s){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),n={reqId:-1,method:e,args:r},this.p.send(n),[2]}))}))},t.prototype.destroy=function(){this.send("destroy")},t}(),h=function(){function r(e,r,s){var o=this;this._appkey=e,this._dbpath=r,this._logOutputLevel=s,this._catch={crtUserId:"",connectedTime:0,naviInfo:null,connectionStatus:2,deviceId:"",deltaTime:0},this._connectionStatus=t.DISCONNECTED,this._connectInfo={token:"",reconnectKickEnable:!1,openCallPlus:!1,traceId:""},this._registerMessageTypeList=[],this._senders={},this._callbackCache={},this._createSubProcess(),n.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];return c(o,void 0,void 0,(function(){var n,s;return a(this,(function(o){switch(o.label){case 0:return[4,(s=this._cppServiceProcessProxy).call.apply(s,u([t],r,!1))];case 1:return n=o.sent(),e.returnValue=n.data,[2]}}))}))})),n.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,r){for(var n=[],s=3;s<arguments.length;s++)n[s-3]=arguments[s];return c(o,void 0,void 0,(function(){var s,o,i;return a(this,(function(c){switch(c.label){case 0:return"sendMessage"===r&&(s=n[3],this._callbackCache[s]=e.sender),"connect"===r&&(this._connectInfo={token:n[0],reconnectKickEnable:n[1],openCallPlus:n[2],traceId:n[3]}),"registerMessageType"===r&&this._registerMessageTypeList.push({objectName:n[0],isPersited:n[1],isCounted:n[2],searchProps:n[3]}),[4,(i=this._cppServiceProcessProxy).call.apply(i,u([r],n,!1))];case 1:if(!(o=c.sent()).success)throw new Error(o.data.msg);return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,o.data),[2]}}))}))})),n.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var r,n=[],s=2;s<arguments.length;s++)n[s-2]=arguments[s];(r=o._cppServiceProcessProxy).send.apply(r,u([t],n,!1))})),n.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this))}return r.prototype._send2Renderer=function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,u([t],r,!1))},r.prototype._send2AllRenderer=function(e,t,r){var n=this;void 0===r&&(r=[]),Object.keys(this._senders).forEach((function(s){var o=n._senders[s];r.includes(o)||n._send2Renderer(o,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},r.prototype._registerRenderers=function(e,t){var r=this,n=e.sender,s=n.id;this._cppServiceProcessProxy.send("registerRenderers",t),this._senders[s]||(this._senders[s]=n,n.once("destroyed",(function(){delete r._senders[s]})))},r.prototype.getMainCache=function(){return this._catch},r.prototype._restartSubProcessProxy=function(){var r=this;if(this._createSubProcess(),this._connectionStatus!==t.DISCONNECTED){this._send2AllRenderer("onSuspend",e.SUB_PROCESS_EXIT),this._registerMessageTypeList.forEach((function(e){r._cppServiceProcessProxy.send("registerMessageType",e.objectName,e.isPersited,e.isCounted,e.searchProps)}));var n=this._connectInfo,s=n.token,o=n.reconnectKickEnable,i=n.openCallPlus,c=n.traceId;this._cppServiceProcessProxy.send("connect",s,o,i,c)}},r.prototype._createSubProcess=function(){var e=this,r=this._dbpath||i(s.getPath("userData")),n=o(i(__dirname,"cppServiceProcess.js"),[this._appkey,r,this._logOutputLevel.toString()]);this._cppServiceProcessProxy=new d(n,(function(r){for(var n=[],s=1;s<arguments.length;s++)n[s-1]=arguments[s];var o=n[0],i=n[1];switch(r){case"onConnected":e._catch=o,e._connectionStatus=t.CONNECTED;break;case"onSuspend":e._connectionStatus=t.SUSPENDED;break;case"onDisconnected":e._connectionStatus=t.DISCONNECTED;break;case"onConnecting":e._connectionStatus=t.CONNECTING}e._send2AllRenderer(r,o,i)}),(function(t,r){e._callbackCache[t]&&e._send2Renderer(e._callbackCache[t],"__RC_CHANNEL_RESULT_FROM_MAIN__",t,r)}),(function(t,r){if(void 0===r&&(r=!1),console.error("sub process exit, msg: "+t+", isRestart: "+r),r)return e._restartSubProcessProxy();throw new Error(t)}))},r.prototype.destroy=function(){this._cppServiceProcessProxy.destroy()},r}(),_=function(){function e(e,t,r){this._rcMain=new h(e,t,r)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._rcMain.destroy()},e.prototype.getDeviceId=function(){return this._rcMain.getMainCache().deviceId},e.prototype.getServerTime=function(){return this._rcMain.getMainCache().connectedTime},e}(),f=function(e){return function(e,t){if(l)return l;if(!e)throw new Error("Initializ failed, `appkey` is required!");return l=new _(e,(null==t?void 0:t.dbpath)||"",(null==t?void 0:t.logOutputLevel)||r.WARN)}(e.appkey,e)};export{f as default};
|
|
1
|
+
import{BasicLogger as e,BasicStatistic as t,appendUrl as n,ErrorCode as o,HTTP_TIMEOUT as r,LogTagId as s,StoreKeys as i,BasicReporter as a,REAT_TIME_LOG_SIZE as c,EConnectProtocol as u,notEmptyObject as p,NAVI_CACHE_DURATION as l,BasicNavi as d,FORMATED_VERSION as h,NAVI_REQ_TIMEOUT as f,getbundleId as g,StatisticsVersion as v,StatisticsTag as C,RCConnectionStatus as _,ProtocalType as S,ConnectType as y,AConnectionMgr as m,BasicStaticConfigManager as P,STATIC_CONFIG_IV as E,STATIC_CONFIG_KEY as T,BaseCloudController as R,urlCenter as I,isStartCloudController as N,InvokerType as O,ConversationType as M,SEND_MESSAGE_TYPE_OPTION as b,isObject as U,isUndefined as x,pushJSONToConfigs as L,transformReceivedStatusInfo as w,MessageDirection as A,ReceivedStatus as D,NotificationStatus as k,MessageType as J,RC_DEFAULT_USER as B,MentionedType as j,pushConfigsToJSON as F,isArray as H,transformReceivedStatusFlag as V,getUploadFileName as G,getMinionURL as q,SubscribeOperationType as K,completeSubscriptionPlatformStatus as Q,LogL as W}from"@rongcloud/engine";import{ipcMain as Y,app as X}from"electron";import{fork as z}from"child_process";import{resolve as $,dirname as Z}from"path";import*as ee from"os";import{arch as te,platform as ne,networkInterfaces as oe}from"os";import{Agent as re,request as se}from"http";import{Agent as ie,request as ae}from"https";import{parse as ce}from"url";import{isIP as ue,Socket as pe}from"net";import{EventEmitter as le}from"events";import{connect as de}from"tls";import{existsSync as he,readFileSync as fe,writeFileSync as ge,mkdirSync as ve}from"fs";import{createHash as Ce,createDecipheriv as _e}from"crypto";var Se=function(e,t){return Se=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},Se(e,t)};function ye(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}Se(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var me,Pe=function(){return Pe=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},Pe.apply(this,arguments)};function Ee(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}c((o=o.apply(e,t||[])).next())}))}function Te(e,t){var n,o,r,s,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,o=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){i.label=a[1];break}if(6===a[0]&&i.label<r[1]){i.label=r[1],r=a;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(a);break}r[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],o=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function Re(e,t,n){if(n||2===arguments.length)for(var o,r=0,s=t.length;r<s;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_ADDON_T="P-call_addon-T",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_R="P-call_addon-R",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_O="P-connect-O",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_PARSE_JSON_MSGS_R="P-parse_json_messsages-R",e.P_RECEIVE_MESSAGE_E="P-receive_message-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_SUBSCRIBE_DATA_E="P-parse_json_subscribe_data-E",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R",e.P_PARSE_JSON_E="P-parse_json-E"}(me||(me={}));var Ie,Ne={flushTimestamp:Date.now(),queue:[],locked:!1};function Oe(){Ie&&clearInterval(Ie)}function Me(e,t){Oe(),Ie=setInterval((function(){return xe(e,t)}),1e4)}function be(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];(e=Ne.queue).push.apply(e,t)}var Ue=200;function xe(e,t){var n=Ne.queue,o=Ne.flushTimestamp;if(!(Ne.locked||0===n.length||Date.now()-o<3e4&&n.length<Ue)){Ne.locked=!0;var r=t.createTraceId(),s=t.getSessionId(),i=n.splice(0,Ue).map((function(e){var t=e.sessionId,n=e.level,o=e.time,r=e.type,i=e.tag,a=e.loggerId,c=e.content,u=e.traceId;return{level:n,time:o,type:r,tag:i,sessionId:s+":"+t,content:JSON.stringify({loggerId:a,content:c,traceId:u})}}));t.debug(me.P_WRITE_LOG_T,"writingLen: "+i.length+", queueLen: "+n.length,r);var a=JSON.stringify(i);e.writeLog(a),t.debug(me.P_WRITE_LOG_R,"write done, queueLen: "+n.length,r),Ne.flushTimestamp=Date.now(),Ne.locked=!1,setTimeout((function(){return xe(e,t)}))}}var Le=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return ye(t,e),t.prototype.flush=function(e){be(e)},t}(e),we=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return ye(t,e),t.prototype.flush=function(e){be(e)},t}(t),Ae=function(e,t){var n,o=Buffer.from(e),r=o.length;for(t.push(r),n=0;n<r;n++)t.push(o[n])},De=function(e){return"string"==typeof e},ke=function(e){return De(e)?e.toUpperCase():""},Je=function(e,t){var n="";return 2!==e.length?n="Unexpected number of bytes received.":5!==e[0]?n="Unexpected SOCKS version number: "+e[0]+".":255===e[1]?n="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(n="Unexpected SOCKS authentication method: "+e[1]+"."),n},Be=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: "+e[0]+".":0!==e[1]&&(t="Username and password authentication failure: "+e[1]+"."),t},je=function(e){var t=ke(e.method)||"GET",n=e.pathname||"/",o=e.headers||{},r=e.search||"";o.Host=e.host||"loclahost";var s="";for(var i in s=t+" "+(n+r)+" HTTP/1.1\n",o){if(Object.hasOwnProperty.call(o,i))s+=i+": "+o[i]+"\n"}return e.body&&(s+="Content-Length: "+e.body.length+"\n"),s+="\n","POST"===t&&e.body&&(s+=""+e.body),s},Fe=function(e){return new Promise((function(t){var n,o;e.socket.once("data",(function(o){var r,s=Je(o,n);if(!s)return 2===o[1]?(e.socket.once("data",(function(n){var o=Be(n);o?e.emit("error",new Error("SOCKS authentication failed. "+o)):t()})),r=[1],Ae(e.socksUsername,r),Ae(e.socksPassword,r),void e.write(Buffer.from(r))):void t();e.emit("error",new Error("SOCKS authentication failed. "+s))})),n=[0],e.socksUsername&&n.push(2),(o=Buffer.alloc(2+n.length))[0]=5,o[1]=n.length,n.forEach((function(e,t){o[2+t]=e})),e.write(o)}))},He=function(e,t,n){return new Promise((function(o){var r,s;switch(e.socket.once("data",(function(t){var n;5!==t[0]?n="Unexpected SOCKS version number: "+t[0]+".":0!==t[1]?n=function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code "+e}}(t[1])+".":0!==t[2]&&(n="The reserved byte must be 0x00."),n?e.emit("error",new Error("SOCKS connection failed. "+n)):o()})),(r=[]).push(5),r.push(1),r.push(0),ue(t)){case 0:r.push(3),Ae(t,r);break;case 4:r.push(1),function(e,t){var n,o,r=e.split(".");for(n=0;n<4;n++)o=parseInt(r[n],10),t.push(o)}(t,r);break;case 6:e.emit("error",new Error("Does not support IPV6"))}r.length+=2,(s=Buffer.from(r)).writeUInt16BE(n,s.length-2),e.write(s)}))},Ve=function(e){function t(t){var n=e.call(this)||this;return n.readable=!0,n.socket=new pe,n.options=t,n.socksHost=t.socksHost||"localhost",n.socksPort=t.socksPort||1080,n.socksUsername=t.socksUsername||"",n.socksPassword=t.socksPassword||"",n.socket.on("error",(function(e){n.emit("error",e)})),n.on("error",(function(){n.socket.destroyed||n.socket.destroy()})),n.on("end",n.end),n}return ye(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var n=this.socket.end(e,t);return this.writable=this.socket.writable,n},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,n){return this.socket.write(e,t,n)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var n=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: "+e);if(!t||"string"!=typeof t)throw new TypeError("Invalid host: "+t);return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return Ee(n,void 0,void 0,(function(){var n;return Te(this,(function(o){switch(o.label){case 0:return[4,Fe(this)];case 1:return o.sent(),[4,He(this,t,e)];case 2:return o.sent(),this.onProxied(),n=je(this.options),this.socket.write(Buffer.from(n)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(le),Ge=function(e){var t,n=e.hostname,o=e.port;return!e.host||n&&o||(t=e.host.split(":")),!o&&t&&(o=parseInt(t[1],10)||0),!n&&t&&(n=t[0]),new Ve(e).connect(o,n)},qe=function(e){function t(t){var n=e.call(this)||this;return n.createConnection=Ge,n}return ye(t,e),t}(re),Ke=function(e,t,n){return(t=Pe(Pe({},t),ce(e))).port||(t.port=80),t.agent=new qe(t),se(t,n)},Qe=function(e){var t,n;return t=Ge(e),n=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=de(e,(function(){t.authorized=t.socket.authorized,n.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},We=function(e){function t(t,n){var o=e.call(this,n)||this;return o.url=t,o.socksHost=n.socksHost||"localhost",o.socksPort=n.socksPort||1080,o.createConnection=Qe,o}return ye(t,e),t}(ie),Ye=function(e,t,n,o){var r,s;return t.protocol="https:",!t.port&&t.host&&(r=t.host.split(":"),t.port=r[0],t.port=r[1]),t.port||(t.port=443),s=new We(e,t),t.agent=s,ae(e,t,n)},Xe=null;function ze(e,t,o){void 0===o&&(o=!1);var s=t.url,i=t.headers,a=t.body,c=t.method,u=t.query,p=t.timeout,l=void 0===p?r:p;return new Promise((function(t){var r=/^https/.test(s),p={headers:i,method:c};r&&(p.rejectUnauthorized=o);var d=null;Xe?((p=Pe(Pe({},p),Xe)).body=a,d=r?Ye:Ke):(d=se,r&&(p.agent=new ie(p),d=ae));var h=d(n(s,u),p,(function(e){var n=e.statusCode,o="";e.setEncoding("utf8"),e.on("data",(function(e){o+=e})),e.once("end",(function(){t({status:n||0,data:o})}))}));h.once("timeout",(function(){e.warn(me.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:s,method:c,query:u,timeout:l})),t({status:0})})),h.setTimeout(l),h.once("error",(function(n){e.warn(me.P_HTTP_REQ_E,JSON.stringify({msg:n.stack,url:s,method:c,query:u,timeout:l})),t({status:0})})),h.write(a),h.end()}))}function $e(e,t){return e?(Xe=Pe(Pe({},Xe),e),t.info(s.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:Xe})),{code:o.SUCCESS}):(Xe=null,t.info(s.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:o.SUCCESS})}function Ze(){var e=Xe||void 0;return{code:o.SUCCESS,data:e}}var et,tt=[],nt=!1,ot=function(){return Ee(void 0,void 0,void 0,(function(){var e,t,n,o,r,s,i,a,u,p,l,d,h;return Te(this,(function(f){return nt||0===tt.length||(nt=!0,e=tt.shift(),t=e.args,n=e.resolve,o=t.addon,r=t.startTime,s=t.endTime,i=t.level,a=t.realtimeReport,u=0,p=0,l=[],d=function(e){u+=e.length;var t=e.split(","),o=t[0],r=t[1],s=t[2],d=t[3],h=t[4],f=t.slice(5);if(u>c&&parseInt(r,10)!==p)n(l);else{p=parseInt(r,10);try{if(!a&&i<0)return;var g={time:parseInt(r,10),level:parseInt(d,10),sessionId:o,type:s,tag:h,content:f.join(",")};l.push(g)}catch(e){console.error(e)}}},h=function(e){n(l),nt=!1,ot()},o.getFullLog(i,r,s,!1,d,h)),[2]}))}))},rt=function(e){function t(t,n,o,r,s){var a=this,c="Electron|"+process.versions.electron+"|"+process.arch+"|"+process.platform;return a=e.call(this,n,o,c,{getLogs:function(e,n,o,r){return Ee(this,void 0,void 0,(function(){return Te(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:n,level:o,realtimeReport:r,addon:t},Ee(void 0,void 0,void 0,(function(){return Te(this,(function(e){return[2,new Promise((function(e){tt.push({resolve:e,args:i}),ot()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var e=t.getStoreValue(i.REALTIME_LOG_TIMESTAMP);return parseInt(e,10)||0},setTimestamp4RealtimeLog:function(e){t.setStoreValue(i.REALTIME_LOG_TIMESTAMP,e.toString())}},r)||this,a.subProcess=s,a}return ye(t,e),t.prototype.send=function(e){return ze(this.logger,e)},t.prototype.compressLogs=function(e){return Ee(this,void 0,void 0,(function(){var t,n,o;return Te(this,(function(r){switch(r.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=r.sent(),n=t.success,o=t.data,n?[2,{success:n,data:o.data}]:[2,{success:n,data:""}]}}))}))},t}(a),st=[u.RMTP,u.TLS,u.QUIC],it=function(e){return"RongCloud/navis/"+e+"/navi-cache.json"},at="deviceId",ct=function(e){return"RongCloud/caches/"+e+"/staticConfig.json"},ut=function(e){return"RongCloud/cloudControl/"+e+"/cloudControl.json"},pt=null,lt=function(){var e,t=Date.now(),n=[te(),ne(),process.pid,t,Math.floor(Math.random()*t)].join("__");return e=n,Ce("md5").update(e).digest("hex")},dt=function(e){if(pt)return pt;var t=$(e,at);return he(t)?pt=fe(t).toString():(pt=lt(),ge(t,pt),pt)},ht=function(){function e(e){this._callCppProxy=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,n,o,r,s){var i=JSON.stringify(r);"{}"!==i&&e.info(me.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:o,ext:r})),this._callCppProxy("setMessageExtension",t,n,o,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime,c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,o,r,s,c,n||"")},e.prototype.setLocalFromExtMsg=function(e,t){var n=t.channelId,o=t.conversationType,r=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._callCppProxy("getMessage",a.mid),p=JSON.parse(u).extMsg,l=JSON.parse(p||"{}");if(c)for(var d in c){var h=l[d];h&&h.ts<i-this._setTime?(h.v=c[d],h.ts=i-this._setTime):(l[d]={v:"",ts:0},l[d].v=c[d],l[d].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete l[e]})),this._setToProtocol(e,o,r,a.mid,l,n||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),n={};for(var o in t)n[o]=t[o].v;return n},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),n=JSON.parse(t||"{}"),o={};for(var r in n)o[r]=n[r].v;return o},e}();!function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(et||(et={}));var ft=function(){function e(e,t,n,r){var s=this;this.p=e,this.emit=t,this.callback=n,this.errorHandle=r,this.count=0,this.maps={},this.p.on("message",(function(e){var o=e.type,i=e.data;switch(o){case et.EVENT:var a=i,c=a.eventName,u=a.data;null==t||t.apply(void 0,Re([c],u,!1));break;case et.RESPONSE:var p=i,l=p.reqId,d=p.success,h=p.data,f=s.maps[l];if(!f)return;f({success:d,data:h}),delete s.maps[l];break;case et.CALLBACK:null==n||n(i);break;case et.ERROR:var g=i.msg;null==r||r(g)}})),this.p.on("error",(function(e){null==r||r("SubProcessProxy error "+e)})),this.p.on("exit",(function(e,t){if(0!==e){for(var n in s.maps){if(Object.prototype.hasOwnProperty.call(s.maps,n))(0,s.maps[n])({success:!0,data:{code:o.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==r||r("SubProcessProxy exit "+e+" "+t,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return e.prototype.call=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return Ee(this,void 0,void 0,(function(){var n=this;return Te(this,(function(r){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:o.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(o){var r=++n.count;n.maps[r]=o;var s={reqId:r,method:e,args:t,hasResponse:!0};n.p.send(s)}))]}))}))},e.prototype.send=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];return Ee(this,void 0,void 0,(function(){var o;return Te(this,(function(r){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),o={reqId:-1,method:e,args:n},this.p.send(o),[2]}))}))},e.prototype.destroy=function(){this.send("destroy")},e}();function gt(e){void 0===e&&(e="IPv4");for(var t=oe(),n=[],o=0,r=Object.values(t);o<r.length;o++){var s=r[o];if(s&&-1!==Object.prototype.toString.call(s).indexOf("Array")){var i=s.filter((function(t){return!(t.internal||(n=t.mac,/^(0{1,2}[:-]){5}0{1,2}$/.test(n))||t.family&&t.family!==e);var n})).map((function(e){return e.mac}));n.push.apply(n,i)}}return n.length?n.sort()[0]:""}var vt,Ct=function(e,t,n){return Ee(void 0,void 0,void 0,(function(){var o,r;return Te(this,(function(s){return o=_e("aes-256-cbc",t,n),r=o.update(e,"base64","utf-8"),[2,r+=o.final("utf8")]}))}))},_t=function(e){if(!he(e)){var t=$(e,"..");he(t)||_t(t),ve(e)}},St=function(e){function t(t,n,o,r,s){var i=e.call(this,t,n,o,s)||this;i.naviPath="",i._caches={},i.naviPath=r+"/"+it(t);var a=Z(i.naviPath);return he(a)||_t(a),i}return ye(t,e),t.prototype.httpRequest=function(e,t,n,r){return Ee(this,void 0,void 0,(function(){var i,a,c,u,p;return Te(this,(function(l){switch(l.label){case 0:return i="token="+encodeURIComponent(n)+"&v="+h+"&p=PC&ev=5.9.9&m="+gt(),a=e+"/navi.json?r="+Date.now()+"&env="+this._environment,this.logger.info(s.L_REQUEST_T,JSON.stringify({url:a,body:i}),r),[4,ze(this.logger,{method:"POST",headers:{appId:t},body:i,url:a,timeout:f})];case 1:if(200!==(c=l.sent()).status)return this.logger.warn(s.L_REQUEST_R,JSON.stringify({url:a,code:c.status}),r),[2,{code:this.transHttpCode(c.status)}];this.logger.info(s.L_REQUEST_R,JSON.stringify({url:a,data:c.data}),r);try{return u=JSON.parse(c.data),p=/^https/.test(a)?"https":"http",u.protocol=p,u.code&&200!==u.code?[2,{code:this.transHttpCode(u.code)}]:[2,{code:o.SUCCESS,data:u}]}catch(e){return this.logger.error(s.L_PARSE_NAVI_E,c.data,r),[2,{code:o.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.httpRequestV2=function(e,t,n,r){return Ee(this,void 0,void 0,(function(){var i,a,c,u;return Te(this,(function(p){switch(p.label){case 0:return i=this.getNaviV2RequestOption({appkey:t,token:n,uri:e,platform:"electron",protocol:st.join(","),mac:gt()}),this.logger.info(s.L_REQUEST_T,JSON.stringify({url:i.url,body:i.body,headers:i.headers}),r),[4,ze(this.logger,i)];case 1:if(200!==(a=p.sent()).status)return this.logger.warn(s.L_REQUEST_R,JSON.stringify({url:i.url,code:a.status}),r),[2,{code:this.transHttpCode(a.status)}];this.logger.info(s.L_REQUEST_R,JSON.stringify({url:i.url,data:a.data}),r);try{return c=JSON.parse(a.data),u=/^https/.test(i.url)?"https":"http",c.protocol=u,[2,{code:o.SUCCESS,data:c}]}catch(e){return this.logger.error(s.L_PARSE_NAVI_E,a.data,r),[2,{code:o.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},t.prototype.getNaviCache=function(e){var t=this.getCatchKey(e),n=this._caches[t];if(n)return n;if(!he(this.naviPath))return null;var o=fe(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(o),this._caches[t]}catch(e){this.logger.error(s.L_PARSE_NAVI_E,o)}return null},t.prototype.setNaviCache=function(e,t){var n=Date.now(),o=this.getCatchKey(e);if(p(this._caches))for(var r in this._caches){(n-this._caches[r].timestamp>l||o===r)&&delete this._caches[r]}this._caches[o]={token:e,naviInfo:t,timestamp:Date.now(),environment:this._environment},ge(this.naviPath,JSON.stringify(this._caches))},t.prototype.setEnvironment=function(e){this._environment=e},t}(d);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(vt||(vt={}));var yt,mt=function(e){function t(t,n,r,s,i,a){var c=e.call(this,t,r,s,i,a)||this;return c.callCppProxy=n,c._connectedTime=0,c._naviInfo=null,c._excludeLogTag=["P-RCGetValueForKey-T","P-RCGetValueForKey-E","P-RCGetValueForKey-R","P-RCSetValueForKey-T","P-RCSetValueForKey-E","P-RCSetValueForKey-R"],c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.callCppProxy("setConnectionStatusListener",c._onConnectionStatusChange.bind(c),(function(e){c.logger.info(me.P_DB_OPEN_O,e)}),(function(){return c.recvPong(o.SUCCESS)}),c._onConnectionStatusChange.bind(c),c._onTcpConnectResponse.bind(c)),c}return ye(t,e),t.prototype.getConnectedTime=function(){return this._connectedTime},t.prototype.connectWithToken=function(e,t,n,r){var s=this;return new Promise((function(i){s._naviInfo=t,s.connectResolve={resolve:i,traceId:r,userId:t.userId};var a={},c=Ze().data;c&&(a={proxy_passwd:c.socksPassword||"",proxy_name:c.socksUsername||"",proxy_port:c.socksPort||1082,proxy_host:c.socksHost||"localhost",proxy_type:0});var p=JSON.stringify(Pe(Pe({},a),{call_plus:s._openCallPlus})),l=s.getCmpList(t,!0).filter((function(e){return st.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];l.forEach((function(e){var t=d.find((function(t){return t.addr===e.addr}));t?t.protocol!==u.QUIC&&e.protocol!==u.QUIC||(t.race=!0,t.protocol=u.QUIC):(e.race=!1,d.push(e))})),s.logger.info(me.P_CONNECT_O,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:h,reconnectKickEnable:n}),r),s._startTime=Date.now();try{s.callCppProxy("connectWithToken",e,h,JSON.stringify(Pe(Pe({},t),{serverAddr:d,tagBlacklist:s._excludeLogTag.join(",")})),n,p)}catch(e){s.logger.error(me.P_CALL_ADDON_E,null==e?void 0:e.stack,r),s.recvConnectRes(o.RC_SOCKET_NOT_CREATED)}}))},t.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.callCppProxy("disconnect",t)},t.prototype.sendPing=function(e){var t=this;return new Promise((function(n){t.pingResolve=n,t.callCppProxy("sendHeartbeat"),setTimeout((function(){return t.recvPong(o.TIMEOUT)}),e)}))},t.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},t.prototype._onConnectionStatusChange=function(e,t){switch(this.logger.info(me.P_CONNECT_S,JSON.stringify({status:e,delay:t})),e){case o.SUCCESS:this.recvConnectRes(o.SUCCESS);break;case o.RC_CONN_REDIRECTED:case 32061:this.recvConnectRes(o.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case o.RC_SOCKET_DISCONNECTED:this.recvConnectRes(e,!1);break;case o.RC_SOCKET_NOT_CREATED:case o.RC_CONN_ACK_TIMEOUT:case o.RC_TCP_RESET:this.recvConnectRes(e);break;case o.RC_UDP_DISCONNECTED:this.recvConnectRes(e,!0,t);break;default:this.recvConnectRes(e,!0)}},t.prototype.recvConnectRes=function(e,t,n){if(this.connectResolve){var r=this.connectResolve,s=r.resolve,i=r.userId,a=Date.now()-(this._startTime+this._tcpDuration),c={bid:g(),cod:e,net:this.getNetwork().type,dur:a,spr:0,cid:this.uuid+"_"+this.retryCount,v:v.CURRENT,count:this.retryCount};return this.statisticLog.record(C.IM_CMP_RMTP,JSON.stringify(c)),e===o.SUCCESS&&(this._connectedTime=Date.now()-this.callCppProxy("getDeltaTime")),s({code:e,data:i}),void(this.connectResolve=null)}if(t)this.onDisconnectByServer(e,n);else{if(e===o.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==_.CONNECTED)return;this.onDisconenctUnusual(e)}},t.prototype._onTcpConnectResponse=function(e,t,n,o,r,s,i){var a,c=this.cmpWeightCache.findIndex((function(e){return e.addr===t+":"+n})),u={bid:g(),ptc:S.TCP,cod:e,net:this.getNetwork().type,dur:o,spr:0,pr:(null===(a=this._naviInfo)||void 0===a?void 0:a.type)||0,hos:t+":"+n,idx:c,rct:this.retryCount?y.RECONNECT:y.CONNECT,cid:this.uuid+"_"+this.retryCount,v:v.CURRENT,rsn:this.reason,ddu:r,count:this.retryCount,weight:c>=0?this.cmpWeightCache[c].weight:-1};this.statisticLog.record(C.IM_CMP,JSON.stringify(u)),this.logger.info(me.P_CONNECT_ENTRY_S,JSON.stringify({code:e,host:t,port:n,duration:o,dnsDuration:r,index:s,isQuic:i})),e===vt.SUCCESS&&(this.curCmpUrl=t+":"+n,this.updateCmpWeight(t+":"+n,!0,i))},t}(m),Pt=function(e){function t(t,n,o){var r=e.call(this,t,n)||this;r.appkey=t,r.logger=n,r.dbpath=o,r._cachePath="",r._cachePath=o+"/"+ct(t);var s=Z(r._cachePath);return he(s)||_t(s),r}return ye(t,e),t.prototype.getCache=function(){return he(this._cachePath)&&fe(this._cachePath,{encoding:"utf8"})||null},t.prototype.setCache=function(e){ge(this._cachePath,e)},t.prototype.clearCache=function(){ge(this._cachePath,"")},t.prototype.sendRequest=function(e){return Ee(this,void 0,void 0,(function(){var t,n,o;return Te(this,(function(r){switch(r.label){case 0:return[4,ze(this.logger,{url:e,body:""})];case 1:return t=r.sent(),n=t.status,o=t.data,[2,{code:n,data:o}]}}))}))},t.prototype.decryptData=function(e){return Ee(this,void 0,void 0,(function(){var t,n;return Te(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,Ct(e,T,E)];case 1:return t=o.sent(),[2,JSON.parse(t)];case 2:return n=o.sent(),this.logger.error(s.L_GET_STATIC_CONF_E,JSON.stringify({error:null==n?void 0:n.stack})),[3,3];case 3:return[2]}}))}))},t}(P),Et=function(e){function t(t,n,o,r,s,i,a){var c=e.call(this,n,t,o,i)||this;c.deviceId=r,c.model="",c.catchFilePath="",c.addon=a,c.model="Electron|"+process.platform+"|"+process.arch,c.catchFilePath=s+"/"+ut(t);var u=Z(c.catchFilePath);return he(u)||_t(u),c.init(),c}return ye(t,e),t.prototype.httpRequest=function(e,t,n,o){return Ee(this,void 0,void 0,(function(){var r,i,a,c,u,p,l,d;return Te(this,(function(h){switch(h.label){case 0:return(r=o).deviceId=this.deviceId,r.model=this.model,i={url:e,method:t,headers:n,body:JSON.stringify(r)},this.logger.info(s.L_REQUEST_T,JSON.stringify(i)),[4,ze(this.logger,i)];case 1:a=h.sent(),c=a.status,u=a.data,p=void 0===u?"":u,this.logger.info(s.L_REQUEST_R,JSON.stringify({status:c,data:p}));try{return l=JSON.parse(p),d=l.data,[2,{code:c,data:d}]}catch(e){return this.logger.warn(s.L_CLOUD_CONFIG_DATA_E,JSON.stringify({status:c,data:p,error:e})),[2,{code:c,msg:e}]}return[2]}}))}))},t.prototype.setCloudControllerCache=function(e){ge(this.catchFilePath,JSON.stringify(e)),this.logger.info(s.L_CLOUD_SET_CACHE_O,JSON.stringify(e))},t.prototype.getLocalCloudControllerCache=function(){if(!he(this.catchFilePath))return null;var e=fe(this.catchFilePath,{encoding:"utf8"});return this.logger.info(s.L_CLOUD_GET_CACHE_O,JSON.stringify({appkey:this.appkey,data:e})),e},t.prototype.setMRTRConfig=function(e){var t={mrtrChatroom:e.chatroom,mrtrGroup:e.group,mrtrPrivate:e.private,mrtrUltraGroup:e.ultraGroup};this.logger.info(s.L_CLOUD_SET_MRTR_O,JSON.stringify(t)),this.addon.setCloudConfig(JSON.stringify(t))},t}(R);!function(e){e[e.cuid=1]="cuid",e[e.uid=2]="uid",e[e.all=4]="all"}(yt||(yt={}));var Tt,Rt=function(){function e(e,t,n,o,r){var s=this;this._appkey=e,this._cppProtocol=t,this._dbpath=n,this._dispatchEvent=o,this._logOutputLevel=r,this._customMessageType={},this.cloudControllerUri="",this.cloudControllerLock=!0,this.cloudControllerMsgs=[],this._buildSubscribeEventData=function(e){var t=[];try{JSON.parse(e).list.forEach((function(e){var n=JSON.parse(e.obj),o=n.userId,r=n.subscribeType,s=n.subscribeTime,i=n.duration,a=n.operationType,c=n.details,u=void 0===c?[]:c;t.push({userId:o,subscribeType:r,subscribeTime:s,duration:i,operationType:a,details:u.map((function(e){var t=JSON.parse(e);return{changeTime:t.changeTime,eventValue:t.changeValue,platform:t.platform}}))})}))}catch(t){s.logger.error(me.P_PARSE_JSON_SUBSCRIBE_DATA_E,JSON.stringify({error:null==t?void 0:t.stack,data:e}))}return t},this._chatroomCache=[],this.rtcHeartbeatResolves={};var i=this._dbpath,a=dt(i);this.logger=new Le(this._appkey,"RC-M","IM"),this._cppProtocol.initWithAppkey(e,i,h,this.logger.getSessionId());var c=z($(__dirname,"sub-process.js"));this.subProxy=new ft(c),this.statisticLog=new we(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),Me(this._cppProtocol,this.logger),this.reporter=new rt(this._cppProtocol,e,a,this.logger,this.subProxy),this.logger.info(me.P_INIT_O,JSON.stringify({appkey:e,dbpath:i,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:a,commit:"ac04313edeb4b97f5b9015d75bbe9396b2781d95"})),this._callCppProxy("setDeviceId",a),this._staticConfigManager=new Pt(e,this.logger,i),this.navi=new St(e,this.logger,this.statisticLog,i,this._staticConfigManager),this.tcpMgr=new mt(e,this._callCppProxy.bind(this),this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this)}),this._initCloudController(a,i),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setSubscribeEventListener(),this._msgExpansionHandler=new ht(this._callCppProxy.bind(this))}return e.prototype._initCloudController=function(e,t){var n=I.getCloudControllerUrl();this.cloudControllerUri=n[0],this.cloudController=new Et(this._appkey,this.logger,this.reporter,e,t,this.statisticLog,this._cppProtocol),N()&&this.cloudControllerUri&&this.cloudController.request(this.cloudControllerUri,O.init)},e.prototype.callProxy=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return Ee(this,void 0,void 0,(function(){var n,r,s;return Te(this,(function(i){switch(i.label){case 0:if(!(n=this[e]))return this.logger.warn(me.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2,Promise.resolve({code:o.NOT_SUPPORT})];r="",i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n.call.apply(n,Re([this],t,!1))];case 2:return[2,i.sent()];case 3:return s=i.sent(),r=JSON.stringify({error:null==s?void 0:s.stack,method:e}),this.logger.error(me.P_CALL_MAIN_E,r),[3,4];case 4:return[2,{code:o.MAIN_PROCESS_ERROR,msg:r}]}}))}))},e.prototype.sendProxy=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return Ee(this,void 0,void 0,(function(){var n;return Te(this,(function(o){if(!(n=this[e]))return this.logger.warn(me.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2];try{n.call.apply(n,Re([this],t,!1))}catch(t){this.logger.error(me.P_CALL_MAIN_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return[2]}))}))},e.prototype.registerRenderers=function(e){var t=e.navigators,n=e.areaCode,o=e.logServerUrl,r=e.environment;this._environment=r||"default",this.navi.setEnvironment(r),I.init({areaCode:n,navigators:t,logServerUrl:o})},e.prototype.onConnected=function(){return Ee(this,void 0,void 0,(function(){var e,t,n;return Te(this,(function(o){switch(o.label){case 0:return e=this.getNaviInfoFromCache(),this.reporter.checkStart(e),this._try2RejoinChatroom(),t=this._dispatchEvent,n=["onConnected"],[4,this.getMainProcessCache()];case 1:return t.apply(this,n.concat([o.sent()])),[2]}}))}))},e.prototype.onConnecting=function(){this._dispatchEvent("onConnecting",void 0)},e.prototype.onSuspend=function(e){this._dispatchEvent("onSuspend",e)},e.prototype.onDisconnected=function(e){this._dispatchEvent("onDisconnected",e)},e.prototype._callCppProxy=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];var r=this.logger.createTraceId();try{return this.logger.debug(me.P_CALL_ADDON_O,JSON.stringify({method:e,content:n}),r),(t=this._cppProtocol)[e].apply(t,n)}catch(t){throw this.logger.error(me.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),r),t}},e.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},e.prototype.sendHTTPRequest=function(e){return ze(this.logger,e)},e.prototype.onRendererLogsReceived=function(e){be.apply(void 0,e)},e.prototype.onRendererNetworkStatusReceived=function(e,t){if(this.tcpMgr.setNetwork(e,t),e.status&&N()&&this.cloudController){var n=this.tcpMgr.getToken();this.cloudController.request(this.cloudControllerUri,O.newWorkChange,n)}},e.prototype.destroy=function(){this.reporter.stop(),this.subProxy.destroy(),this._cppProtocol,Oe(),this._cppProtocol.destroy(),process.exit(0)},e.prototype.callExtra=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=this[e];if(!r)return this.logger.warn(me.P_CALL_EXTRA_E,JSON.stringify({method:e,error:"not found"})),Promise.resolve({code:o.NOT_SUPPORT});try{return r.call.apply(r,Re([this],t,!1))}catch(t){this.logger.error(me.P_CALL_EXTRA_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return Promise.resolve({code:o.MAIN_PROCESS_ERROR})},e.prototype.getConversationsByPage=function(e,t,n,r,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",e,t,n,s||!1,r||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:i})},e.prototype.getUnreadConversationList=function(e){var t,n=this,r=this._callCppProxy("getUnreadConversationList",e);try{t=JSON.parse(r).list.map((function(e){return n._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:t})},e.prototype.getConversationListWithAllChannel=function(){var e,t=this,n=[M.PRIVATE,M.GROUP,M.SYSTEM,M.APP_PUBLIC_SERVICE,M.PUBLIC_SERVICE],r=this._callCppProxy("getConversationListWithAllChannel",n);try{e=JSON.parse(r).list.map((function(e){return t._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:e})},e.prototype.getConversationListWithAllChannelByPage=function(e,t){var n,r=this,s=[M.PRIVATE,M.GROUP,M.SYSTEM,M.APP_PUBLIC_SERVICE,M.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,e,t);try{n=JSON.parse(i).list.map((function(e){return r._buildConversation(e.obj)}))}catch(e){return Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:n})},e.prototype.getHistoryMessagesByObjectNames=function(e,t,n,r,s,i,a){var c=0===i,u=r+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",e,t,n,u,s,c,a||""),l=[];try{var d=JSON.parse(p).list;d.reverse();for(var h=0;h<d.length;h++){var f=this._buildMessage(d[h].obj);l[h]=f}}catch(e){return Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:{list:u===l.length?l.slice(1,u):l,hasMore:r<l.length}})},e.prototype.updateMessageReceiptStatus=function(e,t,n,r){void 0===r&&(r="");var s=this._callCppProxy("updateMessageReceiptStatus",e,t,n,r);return Promise.resolve({code:o.SUCCESS,data:s})},e.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==_.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},e.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new Le(this._appkey,e,t)},e.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},e.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},e.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},e.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),n=this.getNaviInfoFromCache(),o=this.tcpMgr.getCurrentUserId(),r=this.getDeviceId(),s=this._cppProtocol.getDeltaTime();return Promise.resolve({connectedTime:e,deviceId:r,crtUserId:o,naviInfo:n,connectionStatus:t,deltaTime:s})},e.prototype._registerMsgTypes=function(){for(var e in b["RC:RcCmd"]={isCounted:!1,isPersited:!1},b){var t=b[e],n=t.isCounted,o=t.isPersited,r=t.searchProps,s=0;o&&(s|=1),n&&(s|=2),"RC:TypSts"===e&&(s=16),this._callCppProxy("registerMessageType",e,s,r||[])}},e.prototype._buildIsMentioned=function(e,t){var n,o=!1;if(U(e))n=e;else try{n=e?JSON.parse(e):e}catch(t){n=e,this.logger.error(me.P_PARSE_JSON_MSGS_E,JSON.stringify({content:e}))}return U(n)&&(o=!!n.mentionedInfo),{isMentioned:o,msgContent:n}},e.prototype._buildMsgOption=function(e){var t={isCounted:!1,isPersited:!1};return e in b?t=b[e]:e in this._customMessageType&&(t=this._customMessageType[e]),t},e.prototype._buildSupportExt=function(e,t,n){var o=null;return e&&(o=this._msgExpansionHandler.parseReceiveExpansion(n),"conversation"!==t&&"history"!==t||(o=this._msgExpansionHandler.parseConverOrHisExpansion(n))),o},e.prototype._handleReadReceiptRequest=function(e){var t=JSON.parse(e),n=this.getNaviInfoFromCache();if(!(null==n?void 0:n.grpRRVer))return t;var o=t,r=o.hasRespond,s=o.readerInfo,i=void 0===s?{}:s,a=o.readCount,c=o.totalCount,u=o.readerList,p=void 0===u?[]:u,l={readCount:a,totalCount:c};if(1===(null==n?void 0:n.grpRRVer)){var d=[];for(var h in i)d.push({userId:h,readTime:i[h]});l.readerList=d,l.hasRespond=r}return 3===(null==n?void 0:n.grpRRVer)&&(l.readerList=p),l},e.prototype._buildMessage=function(e,t){var n;void 0===t&&(t={});var o=t.isOffLineMessage,r=t.buildFrom,s=JSON.parse(e),i=s.channelId,a=s.conversationType,c=s.targetId,u=s.senderUserId,p=s.content,l=s.objectName,d=s.messageUid,h=s.direction,f=s.status,g=s.messageId,v=s.sentTime,C=s.readReceiptRequest,_=s.supportExt,S=s.pushContent,y=s.pushTitle,m=s.pushId,P=s.pushConfig,E=s.templateId,T=s.disableTitle,R=s.forcePushDetail,I=s.hasMore,N=s.directedUsers,O=s.noNotification,M=this._buildIsMentioned(p,g),b=M.isMentioned,U=M.msgContent,D=this._buildMsgOption(l),k=this._buildSupportExt(_,r,s),J=x(o)?v<this.tcpMgr.getConnectedTime():o,B={};P&&(B=L(this.logger,P,m));var j=Pe(Pe({},B),{pushTitle:y,pushContent:S,pushData:S,disablePushTitle:T,forceShowDetailContent:R,templateId:E}),F={channelId:i,conversationType:a,targetId:c,senderUserId:u,content:U||{},messageType:l,messageUId:d||"",messageDirection:h,isOffLineMessage:J,sentTime:v,receivedTime:0,isPersited:D.isPersited,isCounted:D.isCounted,isMentioned:b,disableNotification:O,isStatusMessage:(null===(n=this._customMessageType[l])||void 0===n?void 0:n.isStatusMessage)||!1,canIncludeExpansion:_,expansion:_?k:null,receivedStatus:f,receivedStatusInfo:w(f),messageId:g,pushConfig:j,hasMore:I,directedUserIds:N||[]};if(h===A.RECEIVE?F.receivedStatus=this._compatibleReceivedStatus(F.receivedStatusInfo):h===A.SEND&&(F.sentStatus=f),C){var H=this._handleReadReceiptRequest(C);F.readReceiptInfo=H}return F},e.prototype._compatibleReceivedStatus=function(e){var t=D.UNREAD;return e.isRead?t=D.READ:e.isListened?t=D.LISTENED:e.isDownload?t=D.DOWNLOADED:e.isRetrieved&&(t=D.RETRIEVED),t},e.prototype._updateReadReceiptInfo=function(e,t){var n=this._callCppProxy("getMessage",e),o=JSON.parse(n),r=o.readReceiptRequest?JSON.parse(o.readReceiptRequest):{},s=Pe(Pe({},r),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},e.prototype._processRRRspMsg=function(e,t,n){if(t!==this.getCurrentUserId())for(var o=0,r=e[this.getCurrentUserId()]||[];o<r.length;o++){f=r[o];var s=this._callCppProxy("getMessage",f),i=JSON.parse(s),a=i.readReceiptRequest?JSON.parse(i.readReceiptRequest):{},c=a.isReceiptRequestMessage,u=a.readerList,p=void 0===u?[]:u;c&&!p.includes(t)&&(p.push(t),this._callCppProxy("updateReadReceiptRequestInfo",f,JSON.stringify({isReceiptRequestMessage:c,readerList:p})))}else for(var l in e)for(var d=0,h=e[l];d<h.length;d++){var f=h[d];this._callCppProxy("updateReadReceiptRequestInfo",f,JSON.stringify({isReceiptRequestMessage:!0,hasRespond:!0}))}},e.prototype._processRSMsg=function(e){var t=e.conversationType,n=e.targetId,o=e.content,r=e.channelId,s=o.msgId,i=o.rrn,a=o.tmn,c=o.endMsgTime;t===M.PRIVATE?this.updateMessageReceiptStatus(t,n,c,r||""):this._updateReadReceiptInfo(s,{readCount:i,totalCount:a});var u={conversationType:t,targetId:n,channelId:r};this._sendMessageReadReceipt(t===M.PRIVATE?{privateReadReceipt:Pe(Pe({},u),{endMsgTime:o.endMsgTime})}:{groupReadReceipt:Pe(Pe({},u),{totalCount:o.tmn,readedCount:o.rrn,messageUId:o.msgId})})},e.prototype._processSRSMsg=function(e){var t=this.getNaviInfoFromCache(),n=e.conversationType,o=e.targetId,r=e.content,s=e.channelId,i=e.senderUserId,a=e.sentTime;return i===this.tcpMgr.getCurrentUserId()&&(this._callCppProxy("clearUnreadCountByTimestamp",n,o,r.lastMessageSendTime,s||""),1!==(null==t?void 0:t.sesDriven)||(a>this.tcpMgr.getConnectedTime()||this._sendsyncReadStatus({conversationType:n,targetId:o,channelId:s,timestamp:r.lastMessageSendTime}),!1))},e.prototype._buildConversation=function(e){var t=JSON.parse(e),n=t.channelId,o=t.conversationType,r=t.targetId,s=t.unreadCount,i=t.lastestMsg,a=t.isTop,c=t.blockStatus,u=t.matchCount,p=t.hasUnreadMention,l=t.conversationTime,d=t.draft,h=c>0?k.OPEN:k.CLOSE;return{channelId:n,conversationType:o,targetId:r,unreadMessageCount:s,latestMessage:-1===JSON.parse(i).messageId?null:this._buildMessage(i),hasMentioned:p,mentionedInfo:null,notificationStatus:h,isTop:a,lastUnreadTime:0,matchCount:u,operationTime:l,notificationLevel:c,draft:d}},e.prototype._convertResultList=function(e,t){var n=JSON.parse(e).list;return n=n.map((function(e){var n=JSON.parse(e.obj);return t?t(n):n}))},e.prototype._handleNotNotificationMessage=function(e){var t,n=e.messageType,o=e.senderUserId,r=e.content;if(n===J.LOG_COMMAND&&e.senderUserId===B){var s=e.content,i=s.startTime,a=s.endTime,c=s.platform,u=s.logId,p=s.uri;return this.reporter.report(parseInt(i,10),parseInt(a,10),c,p,u,e.messageUId),!0}if(n===J.CLOUD_CONTROL&&o===B)return this.cloudControllerMsgs.push(e),this._ccMsgHandler(),!0;if(n===J.READ_STATE)return this._processRSMsg(e),!0;if("RC:MsgExMsg"===n)return this._msgExpansionHandler.setLocalFromExtMsg(this.logger,e),this._sendMessageExpansion(e),!0;if(n===J.SYNC_READ_STATUS&&!this._processSRSMsg(e))return!0;if(n===J.DELIVERED)return this._callCppProxy("setMessageDeliverTime",JSON.stringify(r)),this._sendMessageDelivered(e.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}}))),!0;if(n===J.DELIVERED_MSG){var l={totalCount:e.content.tmn,list:null===(t=e.content.dl)||void 0===t?void 0:t.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};return this._sendGroupMessageDeliveredStatus(l),!0}return!1},e.prototype._setOnReceiveMessageListener=function(){var e=this;this._cppProtocol.setOnReceiveMessageListener((function(t,n,o,r){try{var s=e._buildMessage(t,{isOffLineMessage:o}),i=s.messageType,a=s.channelId,c=void 0===a?"":a,u=s.senderUserId,p=s.content,l=s.sentTime,d=s.conversationType,h=s.targetId;if(e._handleNotNotificationMessage(s))return;if(i===J.READ_RECEIPT_REQUEST&&p.messageUId&&e._updateReadReceiptInfo(p.messageUId,{isReceiptRequestMessage:!0,hasRespond:!1}),i===J.READ_RECEIPT_RESPONSE&&p.receiptMessageDic&&e._processRRRspMsg(p.receiptMessageDic,u,l),i===J.GROUP_READ_RECEIPT_REQUEST){var f=p.msgId,g=p.rrn,v=p.tmn;e._updateReadReceiptInfo(f,{readCount:g,totalCount:v})}s.canIncludeExpansion&&e._msgExpansionHandler.setLocalFromReceiveMsg(e.logger,s),i===J.READ_RECEIPT&&u===e.tcpMgr.getCurrentUserId()&&e._callCppProxy("clearUnreadCountByTimestamp",d,h,p.lastMessageSendTime,c);var C=!0;if(0!==n||r||(C=!1),i===J.RECALL){if(!e.handleRecalledMessage(s))return;var _=e._fixRecallContentInfo(s);d=_.conversationType,h=_.targetId}e._sendMessageNotification(Object.assign(s,{hasMoreMsg:C,conversationType:d,targetId:h}))}catch(n){e.logger.error(me.P_RECEIVE_MESSAGE_E,JSON.stringify({error:null==n?void 0:n.stack,message:t}))}}),(function(){e._sendPullOfflineFinished()}))},e.prototype._ccMsgHandler=function(){var e;return Ee(this,void 0,void 0,(function(){var t,n;return Te(this,(function(o){switch(o.label){case 0:return this.cloudControllerLock?(this.cloudControllerLock=!1,this.cloudControllerMsgs.shift()?(t=this.tcpMgr.getToken(),[4,null===(e=this.cloudController)||void 0===e?void 0:e.request(this.cloudControllerUri,O.other,t)]):[3,2]):[2];case 1:n=o.sent()||0,this.cloudControllerMsgs=this.cloudControllerMsgs.filter((function(e){return e.sentTime>n})),this.cloudControllerLock=!0,this._ccMsgHandler(),o.label=2;case 2:return[2]}}))}))},e.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,n=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,n=e.content.targetId||n),{conversationType:t,targetId:n}},e.prototype.handleRecalledMessage=function(e){var t=e.content,n=t.messageUId,o=t.sentTime;if(!n)return!0;var r=this._callCppProxy("getMessage",n),s=this._buildMessage(r,{isOffLineMessage:!1});if(e.content.isDelete)return-1===s.messageId||this._callCppProxy("deleteMessages",[s.messageId]),!0;if(s.messageType===J.RECALL_NOTIFICATION_MESSAGE)return!1;var i={recallTime:Date.now(),admin:!!e.content.isAdmin,originalObjectName:s.messageType,originalMessageContent:s.content,recallActionTime:e.sentTime,operatorId:e.senderUserId};if(e.content.user&&(i.user=e.content.user),e.content.extra&&(i.extra=e.content.extra),s.messageType===J.TextMessage&&(i.recallContent=s.content.content),-1===s.messageId){var a=e.conversationType,c=e.targetId,u=e.senderUserId,p=e.channelId,l=e.messageDirection;return this._callCppProxy("insertMessage",a,c,u,J.RECALL_NOTIFICATION_MESSAGE,JSON.stringify(i),(function(){}),(function(){}),l,1,30,o,"",0,n,!1,!0,JSON.stringify({}),p||""),!0}return s.receivedStatus||this.setMessageReceivedStatus(s.messageId,1),this._callCppProxy("setMessageContent",s.messageId,JSON.stringify(i),J.RECALL_NOTIFICATION_MESSAGE),!0},e.prototype._sendMessageExpansion=function(e){var t=e.channelId,n=void 0===t?"":t,o=e.content,r=e.conversationType,s=e.targetId,i=o,a=i.put,c=i.del,u=i.mid,p={};a&&(p.updatedExpansion={channelId:n,messageUId:u,expansion:a,conversationType:r,targetId:s}),c&&(p.deletedExpansion={channelId:n,messageUId:u,deletedKeys:c,conversationType:r,targetId:s}),this._dispatchEvent("expansion",p)},e.prototype._sendMessageNotification=function(e){this._dispatchEvent("batchMessage",e)},e.prototype._sendPullOfflineFinished=function(){this._dispatchEvent("pullFinished",null)},e.prototype._sendMessageDelivered=function(e){this._dispatchEvent("messageDelivered",e)},e.prototype._sendGroupMessageDeliveredStatus=function(e){this._dispatchEvent("groupMessageDeliveredStatus",e)},e.prototype._sendChatroomStatus=function(e){this._dispatchEvent("chatroom",e)},e.prototype._sendMessageReadReceipt=function(e){this._dispatchEvent("messageReadReceipt",e)},e.prototype._sendsyncReadStatus=function(e){this._dispatchEvent("syncReadStatus",e)},e.prototype._setConversationStatusListener=function(){var e=this;this._cppProtocol.setConversationStatusListener((function(t){var n=JSON.parse(t).list,o=[];n.forEach((function(e){var t=JSON.parse(e.obj),n=t.conversationType,r=t.targetId,s=t.status,i=t.channelId,a={notificationStatus:2,isTop:!1};s.forEach((function(e){var t=JSON.parse(e.item);1===t.type?a.notificationStatus=1===Number(t.value)?k.OPEN:k.CLOSE:a.isTop=1===Number(t.value)})),o.push({channelId:i,conversationType:n,targetId:r,updatedItems:{notificationStatus:{val:a.notificationStatus,time:0},isTop:{val:a.isTop,time:0}}})})),e._dispatchEvent("conversation",o)}),(function(t){e._dispatchEvent("conversationTag",t)}),(function(t,n,o,r){e._callCppProxy("clearUnreadCountByTimestamp",t,n,r,o||""),e._sendsyncReadStatus({conversationType:t,targetId:n,channelId:o,timestamp:r})}))},e.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._dispatchEvent("tag",t),e._getRTCProfile()}))},e.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var n=this.navi.getNaviInfoFromCache(t);this._dispatchEvent("onNaviDataChange",n)}},e.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){e._dispatchEvent("onRTCDataChange",Array.prototype.slice.call(t))}))},e.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,n){e._sendChatroomStatus({chatroomDestroyed:t})}))},e.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._dispatchEvent("callInfo",t)}))},e.prototype._setSubscribeEventListener=function(){var e=this;this._cppProtocol.setSubscribeEventListener((function(){}),(function(){e._dispatchEvent("syncSubscribedUserStatusFinished")}),(function(t){var n=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,operationType:e.operationType}}));e._dispatchEvent("subscribedRelationChange",n)}),(function(t){var n=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,details:e.details}}));e._dispatchEvent("subscribedUserStatusChange",n)}))},e.prototype._updateMentionedInfo=function(e,t,n){var o,r,s;return{userIdList:(null===(o=e.mentionedInfo)||void 0===o?void 0:o.userIdList)||t,type:(null===(r=e.mentionedInfo)||void 0===r?void 0:r.type)||n||j.ALL,mentionedContent:(null===(s=e.mentionedInfo)||void 0===s?void 0:s.mentionedContent)||""}},e.prototype.registerMessageType=function(e,t,n,o,r){var s=0;t&&(s|=1),n&&(s|=2),r&&(s=16),this._customMessageType[e]={isCounted:n,isPersited:t,isStatusMessage:r},this.logger.info(me.P_REGTYP_O,JSON.stringify({type:e,opt:s,search:o})),this._callCppProxy("registerMessageType",e,s,o||[])},e.prototype.connect=function(e,t,n,o){return this.tcpMgr.connect(e,t,n,o)},e.prototype.reportSDKInfo=function(e){var t=JSON.stringify(Pe(Pe({},e),{"electron-main":"5.9.9"}));this.logger.info(me.P_REPORT_VER_O,t),this._callCppProxy("uploadSDKVersion",t,"")},e.prototype.disconnect=function(e){e=e||!0,this._chatroomCache.length=0,this.reporter.stop(),$e(null,this.logger),this.tcpMgr.disconnect(e)},e.prototype.logout=function(){this.disconnect()},e.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,n){t({userId:e,status:n})}));var n=e.userIds||[];n.length&&this.subscribeUserStatus(n)},e.prototype.subscribeUserStatus=function(e){var t=this;return new Promise((function(n){t._callCppProxy("subscribeUserStatus",e,(function(){setTimeout((function(){n(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},e.prototype.setUserStatus=function(e){var t=this;return new Promise((function(n){t._callCppProxy("setUserStatus",e,(function(){setTimeout((function(){n(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},e.prototype.getUserStatus=function(e){var t=this;return new Promise((function(n){t._callCppProxy("getUserStatus",e,(function(e){setTimeout((function(){n({code:o.SUCCESS,data:{status:e}})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},e.prototype._handleDirectionalUserIdList=function(e){var t=e.messageType,n=e.content,o=e.directionalUserIdList,r=void 0===o?[]:o;if(t===J.READ_RECEIPT_RESPONSE&&n.receiptMessageDic)for(var s in n.receiptMessageDic)r.push(s);return t===J.SYNC_READ_STATUS&&(r=[this.getCurrentUserId()]),r},e.prototype._handleMessage2Callback=function(e,t){var n=this;if("RC:MsgExMsg"===e.messageType&&this._msgExpansionHandler.setLocalFromExtMsg(this.logger,e),e.messageType===J.READ_RECEIPT_REQUEST)this._updateReadReceiptInfo(t.content.messageUId,{isReceiptRequestMessage:!0,readerList:[]});else if(e.messageType===J.READ_RECEIPT_RESPONSE){var o=t.content.receiptMessageDic;if(!o)return;for(var r in o)o[r].forEach((function(e){n._updateReadReceiptInfo(e,{isReceiptRequestMessage:!0,hasRespond:!0})}))}},e.prototype.sendMessage=function(e,t,n,r,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=n.messageType,c=n.content,u=n.expansion,p=n.pushConfig,l=n.isMentioned,d=n.mentionedType,h=n.mentionedUserIdList,f=void 0===h?[]:h,g=n.pushContent,v=void 0===g?"":g,C=n.pushData,_=void 0===C?"":C,S=n.directionalUserIdList,y=void 0===S?[]:S,m=n.disableNotification,P=void 0!==m&&m,E=n.canIncludeExpansion,T=void 0!==E&&E,R=n.isVoipPush,I=void 0!==R&&R,N=n.channelId,O=void 0===N?"":N,b=n.messageId,U=void 0===b?0:b,x=p||{},L=x.iOSConfig,w=x.androidConfig,A=x.templateId,D=void 0===A?"":A,k=x.pushTitle,B=void 0===k?"":k,j=x.pushContent,H=void 0===j?v:j,V=x.pushData,G=void 0===V?_:V,q=x.disablePushTitle,K=void 0!==q&&q,Q=x.forceShowDetailContent,W=void 0!==Q&&Q,Y=F(L,w);return new Promise((function(p){v=H,_=G;var h=(null==w?void 0:w.notificationId)||"",g=e===M.GROUP;g&&l&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,f,d)),g&&(y=i._handleDirectionalUserIdList(n));var C={};for(var S in u)C[S]={v:""},C[S].v=u[S];var m=D;i.logger.info(me.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:e,targetId:t,channelId:O}),s);var E=i._callCppProxy("sendMessage",(function(e,t){var r=i._buildMessage(e,{isOffLineMessage:!1});if(i.logger.info(me.P_SEND_MSG_R,JSON.stringify({code:t,messageUId:r.messageUId}),s),t===o.SENSITIVE_REPLACE)return setTimeout((function(){p({code:t})}),0);[J.READ_RECEIPT_REQUEST,J.READ_RECEIPT_RESPONSE,J.EXPANSION_NOTIFY].findIndex((function(e){return e===r.messageType}))>-1&&i._handleMessage2Callback(r,n),r.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,r),setTimeout((function(){p({code:o.SUCCESS,data:r})}),0)}),(function(e,t){var n=i._buildMessage(e,{isOffLineMessage:!1});i.logger.warn(me.P_SEND_MSG_R,JSON.stringify({code:t,messageId:n.messageId}),s),n.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),setTimeout((function(){p({code:t,data:n})}),0)}),e,t,a,JSON.stringify(c),y,P,K,W,v,_,h,B,Y,m,T,JSON.stringify(C),I,O,U),R=JSON.parse(E);null==r||r(R.messageId)}))},e.prototype.recallMsg=function(e,t,n,r,s){var i=this;return new Promise((function(a){var c,u=s.user,p=s.pushContent,l=s.channelId,d=s.extra,h=s.pushConfig,f=s.disableNotification,g=s.isDelete,v=s.directionalUserIdList,C={conversationType:e,targetId:t,messageUId:n,sentTime:r,user:u,extra:d,channelId:l,isDelete:g||!1};u&&(C.user=u),d&&(C.extra=d);var _={conversationType:e,targetId:t,senderUserId:i.tcpMgr.getCurrentUserId(),content:C,objectName:J.RECALL,messageUid:n,direction:A.SEND,status:D.UNREAD,sentTime:r,channelId:l},S=i._buildMessage(JSON.stringify(_),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){i.handleRecalledMessage(S),setTimeout((function(){a({code:o.SUCCESS,data:S})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}),J.RECALL,JSON.stringify(C),f||!1,(null==h?void 0:h.disablePushTitle)||!1,(null==h?void 0:h.forceShowDetailContent)||!1,p||"",(null==h?void 0:h.pushData)||"",(null===(c=null==h?void 0:h.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==h?void 0:h.pushTitle)||"",F(null==h?void 0:h.iOSConfig,null==h?void 0:h.androidConfig),(null==h?void 0:h.templateId)||"",l,v||[])}))},e.prototype.getHistoryMessage=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u){n=n||0;var p=0===s,l=r+1,d=c._callCppProxy("getHistoryMessages",e,t,n,l,a,p,i),h=JSON.parse(d).list,f=[];h.reverse();for(var g=0;g<h.length;g++){var v=c._buildMessage(h[g].obj);f[g]=v}u({code:o.SUCCESS,data:{list:l===f.length?f.slice(1,l):f,hasMore:r<f.length}})}))},e.prototype.getMessages=function(e,t,n,r,s,i){var a=this;return new Promise((function(c){var u=0===s,p=n,l=0!==n,d=r+1;l&&(p+=u?1:-1,d++);for(var h=a._callCppProxy("getMessages",e,t,p,d,u,i),f=JSON.parse(h).list,g=[],v=0;v<f.length;v++){var C=a._buildMessage(f[v].obj);g[v]=C}var _=a._computeRepairInfo(g,u,n,p,d),S=_.isNeedRepair,y=void 0!==S&&S,m=_.repairTime,P=void 0===m?0:m;if(!y)return l&&(g.shift(),d--),g.reverse(),void c({code:o.SUCCESS,data:{list:d===g.length?g.slice(1,d):g,hasMore:r<g.length}});a._processRepairHisMsg(e,t,n,r,s,i,P,c)}))},e.prototype._computeRepairInfo=function(e,t,n,o,r){var s=!1,i=0,a=this.getNaviInfoFromCache()||{},c=a.repairHisMsg,u=void 0===c?0:c,p=a.historyMsg;if(1!==u||!p)return{isNeedRepair:s,repairTime:i};var l=e.findIndex((function(e){return e.hasMore||0===Object.keys(e.content).length}));return t&&l>=0?(s=!0,i=e[l].hasMore?e[l].sentTime:e[l].sentTime+1):!t&&l>=1?(s=!0,i=e[l-1].sentTime):e.length<r||0===n?(s=!0,i=n):e.length>0&&e[0].sentTime!==n&&(s=!0,i=o),{isNeedRepair:s,repairTime:i}},e.prototype._processRepairHisMsg=function(e,t,n,o,r,s,i,a){var c=this,u=function(i){for(var u=0===r,p=o+1,l=c._callCppProxy("getMessages",e,t,n,p,u,s),d=JSON.parse(l).list,h=[],f=0;f<d.length;f++){var g=c._buildMessage(d[f].obj);h[f]=g}h.reverse(),a({code:i,data:{list:p<=h.length?h.slice(1,p):h,hasMore:o<h.length}})},p=o+10>100?100:o+10;this._callCppProxy("getRemoteHistoryMessages",e,t,i,p,(function(){return u(0)}),(function(e){u(e)}),r,!0,s,!1)},e.prototype.getContinuousMessages=function(e,t,n,r,s,i){var a=this;return new Promise((function(c){n=n||0;var u=0===s;a._callCppProxy("getContinuousMessages",e,t,n,r,(function(e,t,n){var r=JSON.parse(e).list,s=[];r.reverse();for(var i=0;i<r.length;i++){var u=a._buildMessage(r[i].obj);s[i]=u}setTimeout((function(){c({code:o.SUCCESS,data:{list:s,timestamp:t,hasMore:n}})}))}),(function(e){setTimeout((function(){c({code:e})}),0)}),u,i)}))},e.prototype.getRemoteHistoryMessages=function(e,t,n,r,s,i){var a=this;return new Promise((function(c){n=n||0;a._callCppProxy("getRemoteHistoryMessages",e,t,n,r,(function(e,t){var n=JSON.parse(e).list,r=[];n.reverse();for(var s=0;s<n.length;s++){var i=a._buildMessage(n[s].obj);r[s]=i}setTimeout((function(){c({code:o.SUCCESS,data:{list:r,hasMore:!!t}})}),0)}),(function(e){setTimeout((function(){c({code:e})}),0)}),s,!0,i,!0)}))},e.prototype.deleteRemoteMessage=function(e,t,n,r){var s=this;return new Promise((function(i){var a=JSON.stringify(n);s._callCppProxy("deleteRemoteHistoryMessages",e,t,a,!1,r,(function(){setTimeout((function(){i(o.SUCCESS)}),0)}),i)}))},e.prototype.deleteRemoteMessageByTimestamp=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("clearRemoteHistoryMessages",e,t,n,(function(){setTimeout((function(){i(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),r)}))},e.prototype.clearMessages=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("clearMessages",e,t,n),s(o.SUCCESS)}))},e.prototype.getConversationList=function(e,t,n,r,s){var i=this;return void 0===s&&(s=""),new Promise((function(e){for(var t=i._callCppProxy("getConversationList",[1,3,6,7],s),n=JSON.parse(t).list,r=[],a=0;a<n.length;a++)r.push(i._buildConversation(n[a].obj));e({code:o.SUCCESS,data:r})}))},e.prototype.getConversation=function(e,t,n){var r=this;return new Promise((function(s){var i=r._callCppProxy("getConversation",e,t,n);if(i)s({code:o.SUCCESS,data:r._buildConversation(i)});else{var a=r._callCppProxy("getHistoryMessages",e,t,0,1,"",!0,n),c=void 0;try{c=JSON.parse(a).list}catch(e){r.logger.error(me.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=r._buildMessage(c[0].obj));var p=r._callCppProxy("getConversationNotificationStatus",e,t,n),l=r._callCppProxy("getConversationTopStatus",e,t,n);s({code:o.SUCCESS,data:{conversationType:e,targetId:t,channelId:n,unreadMessageCount:0,latestMessage:u,notificationStatus:p?k.OPEN:k.CLOSE,isTop:Boolean(l),lastUnreadTime:0}})}}))},e.prototype.removeConversation=function(e,t,n){var r=this._callCppProxy("removeConversation",e,t,n);return Promise.resolve(r?o.SUCCESS:o.CONVER_REMOVE_ERROR)},e.prototype.batchRemoveConversation=function(e){var t=e.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId}})),n=this._callCppProxy("removeConversationInBatches",JSON.stringify(t));return Promise.resolve(n?o.SUCCESS:o.CONVER_REMOVE_ERROR)},e.prototype.clearConversations=function(e,t){var n=this;return new Promise((function(r){var s=[];s=H(e)?e:[M.PRIVATE,M.GROUP,M.SYSTEM,M.PUBLIC_SERVICE],n._callCppProxy("clearConversations",s,t||""),r(o.SUCCESS)}))},e.prototype.getAllConversationUnreadCount=function(e,t,n){var r=this._callCppProxy("getTotalUnreadCount",t,n,e);return Promise.resolve({code:o.SUCCESS,data:r})},e.prototype.getConversationUnreadCount=function(e,t,n){var r=this;return void 0===n&&(n=""),new Promise((function(s){var i=r._callCppProxy("getUnreadCount",e,t,n);s({code:o.SUCCESS,data:i})}))},e.prototype.clearConversationUnreadCount=function(e,t,n){var r=this;return void 0===n&&(n=""),new Promise((function(s){r._callCppProxy("clearUnreadCount",e,t,n),s(o.SUCCESS)}))},e.prototype.clearUnreadCountByTimestamp=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("clearUnreadCountByTimestamp",e,t,n,r),i(o.SUCCESS)}))},e.prototype.getFirstUnreadMessage=function(e,t,n){var r=this;return new Promise((function(s){var i=r._callCppProxy("getTheFirstUnreadMessage",e,t,n),a=r._buildMessage(i);s({code:o.SUCCESS,data:-1!==a.messageId?a:null})}))},e.prototype.getFirstUnreadMessageInfo=function(e,t,n){var r=this;return new Promise((function(s,i){var a=r._callCppProxy("getTheFirstUnreadMessage",e,t,n),c=r._buildMessage(a);s({code:o.SUCCESS,data:-1!==c.messageId?{messageUId:c.messageUId,sentTime:c.sentTime}:null})}))},e.prototype.batchSetConversationToTop=function(e,t,n){var r=this;return new Promise((function(s,i){var a=e.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,is_top:t}}));r._callCppProxy("setIsTopInBatches",JSON.stringify(a),n||!1),s(o.SUCCESS)}))},e.prototype.setConversationStatus=function(e,t,n,r,s,i){var a=this;return new Promise((function(i){a._callCppProxy("setConversationStatus",e,t,n,r,(function(){setTimeout((function(){i(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),s,!0)}))},e.prototype.getConversationNotificationStatus=function(e,t,n){var r=this;return new Promise((function(s){var i=r._callCppProxy("getConversationNotificationStatus",e,t,n);s({code:o.SUCCESS,data:i?k.OPEN:k.CLOSE})}))},e.prototype.setConversationTypeNotificationLevel=function(e,t){var n=this;return new Promise((function(r,s){n._callCppProxy("setBlockPushLevelForType",e,t,(function(){r({code:o.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.getConversationTypeNotificationLevel=function(e){var t=this;return new Promise((function(n,r){var s=t._callCppProxy("getBlockPushLevelForType",e);n({code:o.SUCCESS,data:s})}))},e.prototype.searchConversationByContent=function(e,t,n,r){var s=this;return new Promise((function(i){r=r||[1,3,6,7];for(var a=s._callCppProxy("searchConversationByContent",r,e,t,n),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=s._buildConversation(c[p].obj);i({code:o.SUCCESS,data:u})}))},e.prototype.searchConversationByContentWithAllChannel=function(e,t,n){var r=this;return new Promise((function(s){n=n||[1,3,6,7];for(var i=r._callCppProxy("searchConversationByContentWithAllChannel",n,e,t),a=JSON.parse(i).list,c=[],u=0;u<a.length;u++)c[u]=r._buildConversation(a[u].obj);s({code:o.SUCCESS,data:c})}))},e.prototype.searchMessageByContent=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(i){c._callCppProxy("searchMessageByContent",e,t,n,r,s,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],r=[],s=0;s<n.length;s++)r[s]=c._buildMessage(n[s].obj);setTimeout((function(){i({code:o.SUCCESS,data:{messages:r,count:t}})}),0)}),a)}))},e.prototype.searchMessageByContentAndMessageType=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u){for(var p=c._callCppProxy("searchMessageByContentAndObjectName",t,e,a||"",void 0===a,n,i,s,r),l=p?JSON.parse(p).list:[],d=[],h=0;h<l.length;h++)d[h]=c._buildMessage(l[h].obj);u({code:o.SUCCESS,data:{messages:d}})}))},e.prototype.searchMessagesByUser=function(e,t,n,r,s,i){var a=this;return new Promise((function(c){a._callCppProxy("getMessageBySender",e,t,n,r,s,i,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],r=0;r<t.length;r++)n[r]=a._buildMessage(t[r].obj);setTimeout((function(){c({code:o.SUCCESS,data:{messages:n}})}),0)}))}))},e.prototype.searchMessageByContentWithAllChannel=function(e,t,n,r,s){var i=this;return new Promise((function(a){i._callCppProxy("searchMessageByContentWithAllChannel",e,t,n,r,s,1,(function(e,t){for(var n=e?JSON.parse(e).list:[],r=[],s=0;s<n.length;s++)r[s]=i._buildMessage(n[s].obj);setTimeout((function(){a({code:o.SUCCESS,data:{messages:r,count:t}})}),0)}))}))},e.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(e,t,n,r,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByTimestampWithAllChannel",e,t,n,r,s,i,a,(function(e){for(var t=e?JSON.parse(e).list:[],n=[],r=0;r<t.length;r++)n[r]=c._buildMessage(t[r].obj);setTimeout((function(){u({code:o.SUCCESS,data:{messages:n}})}),0)}))}))},e.prototype.getUnreadMentionedMessages=function(e,t,n){for(var o=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,n)).list,r=0;r<o.length;r++)o[r]=this._buildMessage(o[r].obj);return o},e.prototype.addToBlacklist=function(e){var t=this;return new Promise((function(n){t._callCppProxy("addToBlacklist",e,(function(){setTimeout((function(){n(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},e.prototype.removeFromBlacklist=function(e){var t=this;return new Promise((function(n){t._callCppProxy("removeFromBlacklist",e,(function(){setTimeout((function(){n(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},e.prototype.getBlacklist=function(){var e=this;return new Promise((function(t){e._callCppProxy("getBlacklist",(function(e){setTimeout((function(){t({code:o.SUCCESS,data:e})}),0)}),(function(e){setTimeout((function(){t({code:e})}),0)}))}))},e.prototype.getBlacklistStatus=function(e){var t=this;return new Promise((function(n){t._callCppProxy("getBlacklistStatus",e,(function(e){setTimeout((function(){n({code:o.SUCCESS,data:e})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},e.prototype.insertMessage=function(e,t,n){var r=this,s=n.content,i=n.senderUserId,a=n.messageType,c=n.messageDirection,u=n.readStatus,p=n.sentStatus,l=n.sentTime,d=n.searchContent,h=n.isUnread,f=n.messageUId,g=n.disableNotification,v=n.canIncludeExpansion,C=n.expansionMsg,_=n.channelId,S=n.directedUserIds;s=JSON.stringify(s);var y={};if(l=l||0,C){var m=JSON.parse(C);for(var P in m)y[P]={v:"",ts:0},y[P].v=m[P],y[P].ts=l}return new Promise((function(n){var C=h?0:1,m=r._callCppProxy("insertMessage",e,t,i,a,s,(function(){}),(function(e){setTimeout((function(){n({code:e})}),0)}),c,u||0,p||10,l,d||"",C,f||"",!!g,!!v,JSON.stringify(y),_||"",S||[]),P=r._buildMessage(m,{isOffLineMessage:!1});P.messageUId=f,P.sentTime=l,n({code:-1===P.messageId?o.MSG_INSERT_ERROR:o.SUCCESS,data:P})}))},e.prototype.batchInsertMessage=function(e,t){var n=this;return void 0===t&&(t=!1),new Promise((function(r){var s=e.map((function(e){var t=e.content,n=e.senderUserId,o=e.messageType,r=e.messageDirection,s=e.receivedStatus,i=void 0===s?0:s,a=e.sentStatus,c=e.sentTime,u=e.searchContent,p=e.isUnread,l=e.messageUId,d=e.disableNotification,h=e.canIncludeExpansion,f=e.expansion,g=e.channelId,v=e.conversationType,C=e.targetId,_=e.source,S=e.isMentioned,y=e.receivedStatusInfo,m=e.directedUserIds,P=i;y&&(P=V(y));var E={};if(c=c||0,f)for(var T in f)E[T]={v:"",ts:0},E[T].v=f[T],E[T].ts=c;return{conversationType:v,targetId:C,channelId:g||"",direction:r,senderUserId:n,status:a||10,sentTime:c,objectName:o,content:JSON.stringify(t),messageUid:l||"",noNotification:!!d,supportExt:!!h,extMsg:JSON.stringify(E),readStatus:P,searchContent:u||"",isUnread:!!p,source:_||"",isMention:S,directedUsers:m}})),i=n._callCppProxy("insertMessages",JSON.stringify(s),t);r({code:i?o.SUCCESS:o.MSG_INSERT_ERROR,data:i||!1})}))},e.prototype.getMessageCount=function(e,t,n){var r=this;return new Promise((function(s){var i=r._callCppProxy("getMessageCount",e,t,n);s({code:o.SUCCESS,data:i})}))},e.prototype.deleteMessages=function(e){var t=this;return new Promise((function(n){t._callCppProxy("deleteMessages",e),n(o.SUCCESS)}))},e.prototype.deleteMessagesByTimestamp=function(e,t,n,r,s){var i=this;return new Promise((function(a){i._callCppProxy("deleteMessagesByTimestamp",e,t,n,r,s),a(o.SUCCESS)}))},e.prototype.batchClearMessagesByTimestamp=function(e){var t=this;return new Promise((function(n,r){var s=e.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));t._callCppProxy("deleteMessageBySendTimeInBatches",JSON.stringify(s)),n(o.SUCCESS)}))},e.prototype.batchClearRemoteHistoryMessages=function(e,t){var n=this;return new Promise((function(r,s){var i=e.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));n._callCppProxy("deleteRemoteMessageBySendTimeInBatches",JSON.stringify(i),t||!1,(function(){setTimeout((function(){r(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},e.prototype.getMessage=function(e){var t=this;return new Promise((function(n){var r=t._callCppProxy("getMessage",e),s=t._buildMessage(r,{isOffLineMessage:!1});n({code:o.SUCCESS,data:s})}))},e.prototype.setMessageContent=function(e,t,n){var r=this;return new Promise((function(s){t=JSON.stringify(t),r._callCppProxy("setMessageContent",e,t,n),s(o.SUCCESS)}))},e.prototype.setMessageSearchField=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("setMessageSearchField",e,t,n),s(o.SUCCESS)}))},e.prototype.setMessageSentStatus=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("setMessageSentStatus",e,t),r(o.SUCCESS)}))},e.prototype.setMessageReceivedStatus=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("setMessageReceivedStatus",e,t),r(o.SUCCESS)}))},e.prototype.saveConversationMessageDraft=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("saveTextMessageDraft",e,t,n,r||"")&&i(o.SUCCESS),i(o.DRAFT_SAVE_ERROR)}))},e.prototype.getConversationMessageDraft=function(e,t,n){var r=this;return new Promise((function(s){var i=r._callCppProxy("getTextMessageDraft",e,t,n||"");s({code:o.SUCCESS,data:i})}))},e.prototype.clearConversationMessageDraft=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("clearTextMessageDraft",e,t,n||"")&&s(o.SUCCESS),s(o.DRAFT_REMOVE_ERROR)}))},e.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},e.prototype.batchSetConversationStatus=function(e){var t=e[0],n=t.conversationType,o=t.targetId,r=t.isTop,s=t.notificationStatus,i=t.channelId,a=t.isUpdateTime,c=void 0===a||a,u=this._callCppProxy("getConversationNotificationStatus",n,o,i||""),p=this._callCppProxy("getConversationTopStatus",n,o,i||""),l=x(s)?Boolean(u):s===k.OPEN,d=x(r)?Boolean(p):r;return this.setConversationStatus(n,o,l,d,i,c)},e.prototype.getConversationNotificationLevel=function(e,t,n){return Ee(this,void 0,void 0,(function(){var r;return Te(this,(function(s){return r=this._callCppProxy("getBlockPushLevelForConversation",t,n,e),[2,Promise.resolve({code:o.SUCCESS,data:r})]}))}))},e.prototype.setConversationNotificationLevel=function(e,t,n,r){var s=this;return void 0===r&&(r=""),new Promise((function(i){s._callCppProxy("setBlockPushLevelForConversation",t,r,e,n,(function(){setTimeout((function(){i(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}))}))},e.prototype.batchSetConversationNotificationLevel=function(e,t){var n=this;return new Promise((function(r,s){var i=e.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,level:t}}));n._callCppProxy("setBlockPushLevelInBatches",JSON.stringify(i),(function(){setTimeout((function(){r(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},e.prototype.getTotalUnreadCountByLevels=function(e,t,n){if(n){var r=this._callCppProxy("getUnreadMentionedCountByLevel",e,t);return Promise.resolve({code:o.SUCCESS,data:r})}var s=this._callCppProxy("getUnreadCountByLevel",e,t);return Promise.resolve({code:o.SUCCESS,data:s})},e.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},e.prototype.sendReadReceiptMessage=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("sendReadReceipt",e,n||"",t,(function(){t.forEach((function(e){r._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(r._callCppProxy("getMessage",e)).messageId;r.setMessageReceivedStatus(t,1)}catch(t){r.logger.error(me.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),setTimeout((function(){s({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.getMessageReader=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("getMessageReader",e,n,t,(function(e,n){var i=[],a={};(e=JSON.parse(e)).list.forEach((function(e){var t=JSON.parse(e.obj),n=t.id,o=t.time;i.push({userId:n,readTime:o}),a[n]=o}));var c={readerInfo:a,readCount:i.length,totalCount:n};r._updateReadReceiptInfo(t,c),setTimeout((function(){s({code:o.SUCCESS,data:{list:i,totalMemberCount:n}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.sendReadReceiptMessageV4=function(e,t,n){var r=this;return new Promise((function(s){var i=e.conversationType,a=e.targetId,c=e.channelId;r._callCppProxy("sendMessageReadReceipt",i,a,c||"",t,n,(function(){setTimeout((function(){s({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.getMessageReadReceiptV4=function(e,t){var n=this;return new Promise((function(r){var s=e.targetId,i=e.channelId;n._callCppProxy("getMessageReadReceipt",s,i||"",t,(function(e,s,i){var a=[],c=n._callCppProxy("getMessage",t),u=JSON.parse(c);try{JSON.parse(i).list.forEach((function(e){var t=JSON.parse(e.obj),n=t.id,o=t.time;a.push({userId:n,readTime:o})}))}catch(e){n.logger.error(me.P_PARSE_JSON_E,"method: getMessageReadReceipt, info: "+i+", error: "+e)}var p=JSON.parse(u.readReceiptRequest||"{}"),l=p.readerList,d=void 0===l?[]:l,h=p.readCount,f=void 0===h?0:h,g=!1;d.length<a.length&&(d=a,g=!0),f<s&&(f=s,g=!0),g&&n._callCppProxy("updateReadReceiptRequestInfo",t,JSON.stringify({readerList:d,readCount:f,totalCount:e})),setTimeout((function(){r({code:o.SUCCESS,data:{list:a,totalCount:e,readCount:f}})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},e.prototype.updateConversationReadTime=function(e,t){var n=this;return new Promise((function(r){var s=e.conversationType,i=e.targetId,a=e.channelId;n._callCppProxy("updateConversationReadTime",s,i,a||"",t,(function(){setTimeout((function(){r({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},e.prototype._addChatroomCache=function(e,t,n){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:n,count:t})},e.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},e.prototype._try2RejoinChatroom=function(){var e=this;if(0!==this._chatroomCache.length){var t=this.logger.createTraceId();this._chatroomCache.forEach((function(n){return Ee(e,void 0,void 0,(function(){var e,r,i,a,c,u;return Te(this,(function(p){switch(p.label){case 0:return e=n.chatroomId,r=n.joinExist,i=n.count,this.logger.info(s.L_REJOIN_CHATROOM_T,e,t),[4,this._joinChrm(e,i,r,!1)];case 1:return a=p.sent(),c=a.code,u=a.data,c===o.SUCCESS?(this.logger.info(s.L_REJOIN_CHATROOM_R,e,t),this._sendChatroomStatus({rejoinedRoom:Pe({chatroomId:e,count:i},u)}),[2]):(c===o.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(e),this._sendChatroomStatus({rejoinedRoom:{chatroomId:e,errorCode:c}}),this.logger.warn(s.L_REJOIN_CHATROOM_R,"chrmId: "+e+", code: "+c,t),[2])}}))}))}))}},e.prototype._joinChrm=function(e,t,n,r){var s=this,i=n?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){r&&s._callCppProxy("clearMessages",M.CHATROOM,e,""),s._callCppProxy(i,e,t,(function(r,i,c,u,p,l){s._addChatroomCache(e,t,n),setTimeout((function(){a({code:o.SUCCESS,data:{createTime:Number(r),memberCount:i,isAllChatroomBanned:c,isCurrentUserBanned:u,isCurrentChatroomBanned:p,isCurrentChatroomInWhitelist:l}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},e.prototype.joinChatroom=function(e,t){return Ee(this,void 0,void 0,(function(){return Te(this,(function(n){switch(n.label){case 0:return[4,this._joinChrm(e,t,!1,!0)];case 1:return[2,n.sent().code]}}))}))},e.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},e.prototype.quitChatroom=function(e){var t=this;return this._rmChatroomCache(e),new Promise((function(n){t._callCppProxy("quitChatRoom",e,(function(){setTimeout((function(){n(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},e.prototype.getChatroomInfo=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("getChatroomInfo",e,t,n,(function(e,t){var n=e?JSON.parse(e).list:[],r=[];if(n.length>0)for(var i=0;i<n.length;i++)r.push(JSON.parse(n[i].obj));setTimeout((function(){s({code:o.SUCCESS,data:{userInfos:r,userCount:t}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.getChatroomHistoryMessages=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("getChatroomHistoryMessage",e,t,n,r,(function(e){var t;try{t=JSON.parse(e)}catch(e){t={list:[],hasMore:!1}}var n=t.list;if(n&&n.length)try{t.list=n.map((function(e){return s._buildMessage(e.obj)}))}catch(e){t.list=[]}setTimeout((function(){i({code:o.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}),"")}))},e.prototype.setChatroomEntry=function(e,t){var n=this;return new Promise((function(r){var s='[{"key":"'+t.key+'", "value":"'+t.value+'"}]';n._callCppProxy("setChatroomKV",e,s,!!t.isAutoDelete,!!t.isOverwrite,(function(){setTimeout((function(){r(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},e.prototype.setChatroomEntries=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("setChatroomKV",e,JSON.stringify(t.entries),!!t.isAutoDelete,!!t.isOverwrite,(function(){r({code:o.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},e.prototype.removeChatroomEntry=function(e,t){var n=this,r=[t.key];return new Promise((function(s){n._callCppProxy("deleteChatroomKV",e,r,!!t.isOverwrite,(function(){s(o.SUCCESS)}),(function(e){s(e)}))}))},e.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},e.prototype.removeChatroomEntries=function(e,t){var n=this;return new Promise((function(r){var s=t.entries.map((function(e){return e.key}));n._callCppProxy("deleteChatroomKV",e,s,!!t.isOverwrite,(function(){r({code:o.SUCCESS})}),(function(e){r({code:e})}))}))},e.prototype.getChatroomEntry=function(e,t){return Ee(this,void 0,void 0,(function(){var n;return Te(this,(function(r){switch(r.label){case 0:return[4,this.getAllChatroomEntry(e)];case 1:return(n=r.sent()).code===o.SUCCESS?[2,{code:o.SUCCESS,data:n.data?n.data[t]:null}]:[2,{code:n.code}]}}))}))},e.prototype.getAllChatroomEntry=function(e){var t=this;return new Promise((function(n){t._callCppProxy("getChatroomKV",e,(function(e){var t={};try{(e?JSON.parse(e):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){t[e.key]=e.value?e.value:""}))}catch(e){}setTimeout((function(){n({code:o.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},e.prototype.getFileToken=function(e,t,n,r,s){var i=this;return n=n||"",r=r||"",s=s||"",new Promise((function(a){var c;c=r&&"uploads"!==r?t||"":G(e,t);var u=i.getNaviInfoFromCache(),p={uploadDomain:q(u,i.logger),env:i._environment};i._callCppProxy("getUploadToken",e,c,n,r,s,JSON.stringify(p),(function(e,t,n,r,s,i,u,p,l,d,h,f,g,v,C,_,S,y,m,P,E,T,R){setTimeout((function(){a({code:o.SUCCESS,data:{token:e,deadline:0,bosToken:t,bosDate:n,path:r,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:l,s3Algorithm:d,s3Date:h,s3Policy:f,s3Signature:g,s3BucketName:v,stcAuthorization:C,stcContentSha256:_,stcDate:S,stcBucketName:y,minioAuthorization:m,minioContentSha256:P,minioDate:E,minioBucketName:T,downloadAuthInfo:R?JSON.parse(R):null}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},e.prototype.getFileUrl=function(e,t,n,r){var s=this;return new Promise((function(i){var a=s.getNaviInfoFromCache(),c={url:q(a,s.logger)};s._callCppProxy("getDownloadUrl",e,n,r,t-1,JSON.stringify(c),(function(e){setTimeout((function(){i({code:o.SUCCESS,data:{downloadUrl:e}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},e.prototype.clearData=function(){var e=this;return new Promise((function(t){var n=e._callCppProxy("clearData");t({code:o.SUCCESS,data:n})}))},e.prototype.getDeviceId=function(){var e=this._dbpath;return dt(e)},e.prototype.getVoIPKey=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("getVoIPKey",e,t,"",(function(e){setTimeout((function(){r({code:o.SUCCESS,data:e})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},e.prototype.bindRTCRoomForChatroom=function(e){var t=this;return new Promise((function(n){var r=e.chatRoomId,s=e.rtcRoomId;t._callCppProxy("bindRTCRoomForChatroom",r,s,(function(){setTimeout((function(){n(o.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},e.prototype.getGroupMessageDeliverList=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("getGroupMessageDeliverList",e,n,t,(function(e,t){var n=JSON.parse(e).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));setTimeout((function(){s({code:o.SUCCESS,data:{totalCount:t,list:n}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.getPrivateMessageDeliverTime=function(e,t){var n=this;return new Promise((function(r){var s=n._callCppProxy("getMessageDeliverTime",e);if(s)r({code:o.SUCCESS,data:s});else{n._callCppProxy("getPrivateMessageDeliverList",t,e,(function(e){var t=0,n=JSON.parse(e).list;if(n.length>0){var s=JSON.parse(n[0].obj).time;t=s}setTimeout((function(){r({code:o.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}}))},e.prototype.rtcSignaling=function(e,t,n,r){var s=this;return new Promise((function(i){s._callCppProxy("rtcSignaling",e,t,n,r,(function(e){var t=Array.prototype.slice.call(e);i({code:o.SUCCESS,buffer:t})}),(function(e){i({code:e})}),30)}))},e.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,n){var o=e.rtcHeartbeatResolves[t];if(o){var r=o.find((function(e){return""===e.seqId}));r&&(r.seqId=n)}}),(function(t,n,o,r){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===o}));-1!==i&&s.splice(i,1)[0].resolve({code:n,data:{version:Number(r)}})}}))},e.prototype.rtcPing=function(e,t,n){var o=this;return new Promise((function(t){var n={resolve:t,seqId:""},r=o.rtcHeartbeatResolves[e];r?r.push(n):o.rtcHeartbeatResolves[e]=[n],o._callCppProxy("sendRTCHeartbeat",[e],30)}))},e.prototype.createTag=function(e){var t=this;return new Promise((function(n){t._callCppProxy("addTag",e.tagId,e.tagName,(function(){setTimeout((function(){n({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},e.prototype.removeTag=function(e){var t=this;return new Promise((function(n){t._callCppProxy("deleteTag",e,(function(){setTimeout((function(){n({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},e.prototype.updateTag=function(e){var t=this;return new Promise((function(n){t._callCppProxy("renameTag",e.tagId,e.tagName,(function(){setTimeout((function(){n({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},e.prototype.getTagList=function(){var e=this;return new Promise((function(t){var n=e._callCppProxy("getTags"),r=e._convertResultList(n,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));t({code:o.SUCCESS,data:r})}))},e.prototype.addTagForConversations=function(e,t){var n=this;return new Promise((function(r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));n._callCppProxy("addConversationsForTag",e,JSON.stringify(t),(function(){setTimeout((function(){r({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},e.prototype.removeTagForConversations=function(e,t){var n=this;return new Promise((function(r){t.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),n._callCppProxy("removeConversationsForTag",e,JSON.stringify(t),(function(){setTimeout((function(){r({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},e.prototype.removeTagsForConversation=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("removeTagsForConversation",e.conversationType,e.targetId,e.channelId||"",t,(function(){setTimeout((function(){r({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},e.prototype.getConversationListByTag=function(e,t,n,r){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",e,t,n||20,r||""),c=s._convertResultList(a,(function(e){return Pe(Pe({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:o.SUCCESS,data:c})}))},e.prototype.getUnreadCountByTag=function(e,t){var n=this;return new Promise((function(r){var s=n._callCppProxy("getConversationUnreadCountForTag",e,t);r({code:o.SUCCESS,data:s})}))},e.prototype.setConversationStatusInTag=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("setConversationToTopForTag",e,t.conversationType,t.targetId,t.channelId||"",n.isTop||!1,(function(){setTimeout((function(){s({code:o.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.getTagsForConversation=function(e){var t=this;return new Promise((function(n){var r=t._callCppProxy("getTagsForConversation",e.conversationType,e.targetId,e.channelId||""),s=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));n({code:o.SUCCESS,data:s})}))},e.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},e.prototype.getTopConversationList=function(e,t){var n=this;return new Promise((function(r){var s=x(t)?n._callCppProxy("getTopConversations",e):n._callCppProxy("getTopConversations",e,t),i=JSON.parse(s).list.map((function(e){return n._buildConversation(e.obj)}));r({code:o.SUCCESS,data:i})}))},e.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},e.prototype.getAllUnreadMentionedCount=function(){var e=this;return new Promise((function(t){var n=e._callCppProxy("getUnreadAndMentionCount",[M.GROUP],"");t({code:o.SUCCESS,data:n})}))},e.prototype.getOSInfo=function(){return Ee(this,void 0,void 0,(function(){var e;return Te(this,(function(t){return e={arch:ee.arch(),platform:ee.platform(),type:ee.type(),version:ee.version(),release:ee.release(),uptime:ee.uptime(),cpus:ee.cpus(),freemem:ee.freemem(),totalmem:ee.totalmem(),networkInterfaces:ee.networkInterfaces()},[2,{code:o.SUCCESS,data:e}]}))}))},e.prototype.getMainProcessInfo=function(){return Ee(this,void 0,void 0,(function(){return Te(this,(function(e){return[2,{code:o.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},e.prototype.setCallInfo=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("callInfoSignaling",e,t,n,(function(e,t){setTimeout((function(){s({code:o.SUCCESS,data:{key:e,value:t}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},e.prototype.setProxy=function(e){return this.tcpMgr.getConnectionStatus()!==_.DISCONNECTED?Promise.resolve({code:o.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve($e(e,this.logger))},e.prototype.getProxy=function(){return Promise.resolve(Ze())},e.prototype.testProxy=function(e,t){return function(e,t,n){return new Promise((function(o){var r=/^https/.test(t)?Ye:Ke;n.info(s.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:e,testHost:t}));var i=r(t,e,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var n="";e.on("data",(function(e){n+=e})),e.once("end",(function(){o({status:t||0,data:n})}))}));i.once("timeout",(function(){return o({status:0})})),i.once("error",(function(e){return o({status:0,data:e.stack})})),i.end()}))}(e,t,this.logger)},e.prototype.checkDuplicateMessage=function(e){var t=this;return new Promise((function(n){var r=t._callCppProxy("checkDuplicateMessage",e);n({code:o.SUCCESS,data:r})}))},e.prototype.subscribeUser=function(e,t,n){var r=this;return new Promise((function(s){r._callCppProxy("updateSubscribeStatus",t,K.SUBSCRIBE,e,(function(){s({code:o.SUCCESS})}),(function(e,t){s({code:e,data:t})}),n)}))},e.prototype.unSubscribeUser=function(e,t){var n=this;return new Promise((function(r){n._callCppProxy("updateSubscribeStatus",t,K.UNSUBSCRIBE,e,(function(){r({code:o.SUCCESS})}),(function(e){r({code:e})}),0)}))},e.prototype.getSubscribeUserList=function(e,t,n){var r=this._callCppProxy("getSubscribeUserList",e,t,n),s=this._buildSubscribeEventData(r).map((function(e){var t=e.userId,n=e.subscribeType,o=e.subscribeTime,r=e.duration,s=e.details;return{userId:t,subscribeType:n,subscribeTime:o,expiry:r,details:Q(s)}}));return Promise.resolve({code:o.SUCCESS,data:s})},e.prototype.setDuplicateMessageConfig=function(e){var t=this._callCppProxy("setDuplicateMessageConfig",[M.CHATROOM],yt.cuid,e);return Promise.resolve({code:t})},e.prototype.getSubscribeUserStatus=function(e,t){var n=this._callCppProxy("getSubscribeStatusByUserIds",e,t),r=this._buildSubscribeEventData(n).map((function(e){var t=e.userId,n=e.subscribeType,o=e.subscribeTime,r=e.duration,s=e.details;return{userId:t,subscribeType:n,subscribeTime:o,expiry:r,details:Q(s)}}));return Promise.resolve({code:o.SUCCESS,data:r})},e.prototype.getMatchedMessage=function(e,t,n,r){var s,i=this._callCppProxy("getMatchedMessage",e.conversationType,e.targetId,t,n,r,e.channelId||""),a=[];try{s=JSON.parse(i).list;for(var c=0;c<s.length;c++){var u=this._buildMessage(s[c].obj);a.push(u)}}catch(e){return this.logger.error(me.P_PARSE_JSON_MSGS_E,i),Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:a})},e.prototype.getConversations=function(e){var t,n=this,r=e.map((function(e){var t=e.conversationType,n=e.targetId,o=e.channelId;return{targetId:n,channelId:void 0===o?"":o,type:t}})),s=this._callCppProxy("getConversations",JSON.stringify(r));try{t=JSON.parse(s).list.map((function(e){return n._buildConversation(e.obj)}))}catch(e){return this.logger.error(me.P_PARSE_JSON_MSGS_E,s),Promise.resolve({code:o.MAIN_PROCESS_ERROR})}return Promise.resolve({code:o.SUCCESS,data:t})},e}(),It=$(__dirname,"binding","electron-"+ne()+"-"+te()+".node"),Nt={addon:null},Ot=(Tt=process,{sendError:function(e){Tt.send({type:et.ERROR,data:{msg:e}})},sendEvent:function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];Tt.send({type:et.EVENT,data:{eventName:e,data:t}})},sendResponse:function(e){Tt.send({type:et.RESPONSE,data:e})},sendCallback:function(e){Tt.send({type:et.CALLBACK,data:e})}}).sendError;try{Nt.addon=require(It)}catch(e){console.error("error ->",It,"\n",e),Ot(e.toString())}Nt.addon||console.error("error -> cannot find module: ",It);var Mt,bt=Nt.addon,Ut=function(){function e(e,t,n,o,r){this.sendCallback=r,this._cppService=new Rt(e,bt,t,o,n)}return e.prototype.call=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return Ee(this,void 0,void 0,(function(){var n,o=this;return Te(this,(function(r){switch(r.label){case 0:return"sendMessage"===e&&(t[3]=function(e){var n=t[3];o.sendCallback({reqId:n,data:e})}),[4,(n=this._cppService).callProxy.apply(n,Re([e],t,!1))];case 1:return[2,{success:!0,data:r.sent()}]}}))}))},e.prototype.send=function(e){for(var t,n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];(t=this._cppService).sendProxy.apply(t,Re([e],n,!1))},e.prototype.destroy=function(){this._cppService.destroy()},e}(),xt=function(){function e(e,t,n,o){var r=this;this._appkey=e,this._dbpath=t,this._logOutputLevel=n,this._runInMainProcess=o,this._catch={crtUserId:"",connectedTime:0,naviInfo:null,connectionStatus:2,deviceId:"",deltaTime:0},this._connectionStatus=_.DISCONNECTED,this._connectInfo={token:"",reconnectKickEnable:!1,openCallPlus:!1,traceId:""},this._registerMessageTypeList=[],this._isProcessQuit=!1,this._senders={},this._callbackCache={},this._createServiceProxy(),Y.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];return Ee(r,void 0,void 0,(function(){var o,r;return Te(this,(function(s){switch(s.label){case 0:return[4,(r=this._cppServiceProcessProxy).call.apply(r,Re([t],n,!1))];case 1:return o=s.sent(),e.returnValue=o.data,[2]}}))}))})),Y.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var o=[],s=3;s<arguments.length;s++)o[s-3]=arguments[s];return Ee(r,void 0,void 0,(function(){var r,s,i;return Te(this,(function(a){switch(a.label){case 0:return"sendMessage"===n&&(r=o[3],this._callbackCache[r]=e.sender),"connect"===n&&(this._connectInfo={token:o[0],reconnectKickEnable:o[1],openCallPlus:o[2],traceId:o[3]}),"registerMessageType"===n&&this._registerMessageTypeList.push({objectName:o[0],isPersited:o[1],isCounted:o[2],searchProps:o[3]}),[4,(i=this._cppServiceProcessProxy).call.apply(i,Re([n],o,!1))];case 1:if(!(s=a.sent()).success)throw new Error(s.data.msg);return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,s.data),[2]}}))}))})),Y.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var n,o=[],s=2;s<arguments.length;s++)o[s-2]=arguments[s];(n=r._cppServiceProcessProxy).send.apply(n,Re([t],o,!1))})),Y.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this)),X.on("before-quit",(function(){r._isProcessQuit=!0,r.destroy()})),X.on("window-all-closed",(function(){r._isProcessQuit=!0,r.destroy()}))}return e.prototype._send2Renderer=function(e,t){for(var n=[],o=2;o<arguments.length;o++)n[o-2]=arguments[o];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,Re([t],n,!1))},e.prototype._send2AllRenderer=function(e,t,n){var o=this;void 0===n&&(n=[]),Object.keys(this._senders).forEach((function(r){var s=o._senders[r];n.includes(s)||o._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},e.prototype._registerRenderers=function(e,t){var n=this,o=e.sender,r=o.id;this._cppServiceProcessProxy.send("registerRenderers",t),this._senders[r]||(this._senders[r]=o,o.once("destroyed",(function(){delete n._senders[r]})))},e.prototype.getMainCache=function(){return this._catch},e.prototype._restartSubProcessProxy=function(){var e=this;if(this._createServiceProxy(),this._connectionStatus!==_.DISCONNECTED){this._send2AllRenderer("onSuspend",o.SUB_PROCESS_EXIT),this._registerMessageTypeList.forEach((function(t){e._cppServiceProcessProxy.send("registerMessageType",t.objectName,t.isPersited,t.isCounted,t.searchProps)}));var t=this._connectInfo,n=t.token,r=t.reconnectKickEnable,s=t.openCallPlus,i=t.traceId;this._cppServiceProcessProxy.send("connect",n,r,s,i)}},e.prototype._eventNotifyHandler=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var o=t[0],r=t[1];switch(e){case"onConnected":this._catch=o,this._connectionStatus=_.CONNECTED;break;case"onSuspend":this._connectionStatus=_.SUSPENDED;break;case"onDisconnected":this._connectionStatus=_.DISCONNECTED;break;case"onConnecting":this._connectionStatus=_.CONNECTING}this._send2AllRenderer(e,o,r)},e.prototype._callbackHandler=function(e){var t=e.reqId,n=e.data;this._callbackCache[t]&&this._send2Renderer(this._callbackCache[t],"__RC_CHANNEL_RESULT_FROM_MAIN__",t,n)},e.prototype._createServiceProxy=function(){var e=this,t=this._dbpath||$(X.getPath("userData"));if(this._runInMainProcess)this._cppServiceProcessProxy=new Ut(this._appkey,t,this._logOutputLevel,this._eventNotifyHandler.bind(this),this._callbackHandler.bind(this));else{var n=z($(__dirname,"cppServiceProcess.js"),[this._appkey,t,this._logOutputLevel.toString()]);this._cppServiceProcessProxy=new ft(n,this._eventNotifyHandler.bind(this),this._callbackHandler.bind(this),(function(t,n){void 0===n&&(n=!1);var o="sub process exit, msg: "+t+", isRestart: "+n+", _isProcessQuit: "+e._isProcessQuit;if(console.error(o),n&&!e._isProcessQuit)return e._restartSubProcessProxy()}))}},e.prototype.destroy=function(){this._cppServiceProcessProxy.destroy()},e}(),Lt=function(){function e(e,t,n,o){this._rcMain=new xt(e,t,n,o)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._rcMain.destroy()},e.prototype.getDeviceId=function(){return this._rcMain.getMainCache().deviceId},e.prototype.getServerTime=function(){return this._rcMain.getMainCache().connectedTime},e}(),wt=function(e){return function(e,t){if(Mt)return Mt;if(!e)throw new Error("Initializ failed, `appkey` is required!");return Mt=new Lt(e,(null==t?void 0:t.dbpath)||"",(null==t?void 0:t.logOutputLevel)||W.WARN,(null==t?void 0:t.runInMainProcess)||!1)}(e.appkey,e)};export{wt as default};
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,t=require("@rongcloud/engine"),n=require("electron"),r=require("child_process"),o=require("path");function s(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{a(r.next(e))}catch(e){s(e)}}function c(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,c)}a((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,o,s,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return s={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,c[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,r=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=t.call(e,i)}catch(e){c=[6,e],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function c(e,t,n){if(n||2===arguments.length)for(var r,o=0,s=t.length;o<s;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(e||(e={}));var a,u=function(){function n(n,r,o,s){var i=this;this.p=n,this.emit=r,this.callback=o,this.errorHandle=s,this.count=0,this.maps={},this.p.on("message",(function(t){var n=t.type,a=t.data;switch(n){case e.EVENT:var u=a,p=u.eventName,l=u.data;null==r||r.apply(void 0,c([p],l,!1));break;case e.RESPONSE:var d=a,h=d.reqId,_=d.success,f=d.data,y=i.maps[h];if(!y)return;y({success:_,data:f}),delete i.maps[h];break;case e.CALLBACK:var v=a,C=(h=v.reqId,v.data);null==o||o(h,C);break;case e.ERROR:var S=a.msg;null==s||s(S)}})),this.p.on("error",(function(e){null==s||s("SubProcessProxy error "+e)})),this.p.on("exit",(function(e,n){if(0!==e){for(var r in i.maps){if(Object.prototype.hasOwnProperty.call(i.maps,r))(0,i.maps[r])({success:!0,data:{code:t.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==s||s("SubProcessProxy exit "+e+" "+n,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return n.prototype.call=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return s(this,void 0,void 0,(function(){var r=this;return i(this,(function(o){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:t.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(t){var o=++r.count;r.maps[o]=t;var s={reqId:o,method:e,args:n,hasResponse:!0};r.p.send(s)}))]}))}))},n.prototype.send=function(e){for(var t,n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return s(this,void 0,void 0,(function(){var r;return i(this,(function(o){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),r={reqId:-1,method:e,args:n},this.p.send(r),[2]}))}))},n.prototype.destroy=function(){this.send("destroy")},n}(),p=function(){function e(e,r,o){var a=this;this._appkey=e,this._dbpath=r,this._logOutputLevel=o,this._catch={crtUserId:"",connectedTime:0,naviInfo:null,connectionStatus:2,deviceId:"",deltaTime:0},this._connectionStatus=t.RCConnectionStatus.DISCONNECTED,this._connectInfo={token:"",reconnectKickEnable:!1,openCallPlus:!1,traceId:""},this._registerMessageTypeList=[],this._senders={},this._callbackCache={},this._createSubProcess(),n.ipcMain.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];return s(a,void 0,void 0,(function(){var r,o;return i(this,(function(s){switch(s.label){case 0:return[4,(o=this._cppServiceProcessProxy).call.apply(o,c([t],n,!1))];case 1:return r=s.sent(),e.returnValue=r.data,[2]}}))}))})),n.ipcMain.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,n){for(var r=[],o=3;o<arguments.length;o++)r[o-3]=arguments[o];return s(a,void 0,void 0,(function(){var o,s,a;return i(this,(function(i){switch(i.label){case 0:return"sendMessage"===n&&(o=r[3],this._callbackCache[o]=e.sender),"connect"===n&&(this._connectInfo={token:r[0],reconnectKickEnable:r[1],openCallPlus:r[2],traceId:r[3]}),"registerMessageType"===n&&this._registerMessageTypeList.push({objectName:r[0],isPersited:r[1],isCounted:r[2],searchProps:r[3]}),[4,(a=this._cppServiceProcessProxy).call.apply(a,c([n],r,!1))];case 1:if(!(s=i.sent()).success)throw new Error(s.data.msg);return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,s.data),[2]}}))}))})),n.ipcMain.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var n,r=[],o=2;o<arguments.length;o++)r[o-2]=arguments[o];(n=a._cppServiceProcessProxy).send.apply(n,c([t],r,!1))})),n.ipcMain.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this))}return e.prototype._send2Renderer=function(e,t){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,c([t],n,!1))},e.prototype._send2AllRenderer=function(e,t,n){var r=this;void 0===n&&(n=[]),Object.keys(this._senders).forEach((function(o){var s=r._senders[o];n.includes(s)||r._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},e.prototype._registerRenderers=function(e,t){var n=this,r=e.sender,o=r.id;this._cppServiceProcessProxy.send("registerRenderers",t),this._senders[o]||(this._senders[o]=r,r.once("destroyed",(function(){delete n._senders[o]})))},e.prototype.getMainCache=function(){return this._catch},e.prototype._restartSubProcessProxy=function(){var e=this;if(this._createSubProcess(),this._connectionStatus!==t.RCConnectionStatus.DISCONNECTED){this._send2AllRenderer("onSuspend",t.ErrorCode.SUB_PROCESS_EXIT),this._registerMessageTypeList.forEach((function(t){e._cppServiceProcessProxy.send("registerMessageType",t.objectName,t.isPersited,t.isCounted,t.searchProps)}));var n=this._connectInfo,r=n.token,o=n.reconnectKickEnable,s=n.openCallPlus,i=n.traceId;this._cppServiceProcessProxy.send("connect",r,o,s,i)}},e.prototype._createSubProcess=function(){var e=this,s=this._dbpath||o.resolve(n.app.getPath("userData")),i=r.fork(o.resolve(__dirname,"cppServiceProcess.js"),[this._appkey,s,this._logOutputLevel.toString()]);this._cppServiceProcessProxy=new u(i,(function(n){for(var r=[],o=1;o<arguments.length;o++)r[o-1]=arguments[o];var s=r[0],i=r[1];switch(n){case"onConnected":e._catch=s,e._connectionStatus=t.RCConnectionStatus.CONNECTED;break;case"onSuspend":e._connectionStatus=t.RCConnectionStatus.SUSPENDED;break;case"onDisconnected":e._connectionStatus=t.RCConnectionStatus.DISCONNECTED;break;case"onConnecting":e._connectionStatus=t.RCConnectionStatus.CONNECTING}e._send2AllRenderer(n,s,i)}),(function(t,n){e._callbackCache[t]&&e._send2Renderer(e._callbackCache[t],"__RC_CHANNEL_RESULT_FROM_MAIN__",t,n)}),(function(t,n){if(void 0===n&&(n=!1),console.error("sub process exit, msg: "+t+", isRestart: "+n),n)return e._restartSubProcessProxy();throw new Error(t)}))},e.prototype.destroy=function(){this._cppServiceProcessProxy.destroy()},e}(),l=function(){function e(e,t,n){this._rcMain=new p(e,t,n)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._rcMain.destroy()},e.prototype.getDeviceId=function(){return this._rcMain.getMainCache().deviceId},e.prototype.getServerTime=function(){return this._rcMain.getMainCache().connectedTime},e}();module.exports=function(e){return function(e,n){if(a)return a;if(!e)throw new Error("Initializ failed, `appkey` is required!");return a=new l(e,(null==n?void 0:n.dbpath)||"",(null==n?void 0:n.logOutputLevel)||t.LogL.WARN)}(e.appkey,e)};
|
|
1
|
+
"use strict";var e=require("@rongcloud/engine"),t=require("electron"),o=require("child_process"),r=require("path"),n=require("os"),s=require("http"),i=require("https"),a=require("url"),c=require("net"),u=require("events"),p=require("tls"),d=require("fs"),l=require("crypto");function h(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var r=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(t,o,r.get?r:{enumerable:!0,get:function(){return e[o]}})}})),t.default=e,Object.freeze(t)}var f=h(n),C=function(e,t){return C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])},C(e,t)};function g(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}C(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var v,S=function(){return S=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},S.apply(this,arguments)};function _(e,t,o,r){return new(o||(o=Promise))((function(n,s){function i(e){try{c(r.next(e))}catch(e){s(e)}}function a(e){try{c(r.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,a)}c((r=r.apply(e,t||[])).next())}))}function y(e,t){var o,r,n,s,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return s={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(c){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(i=0)),i;)try{if(o=1,r&&(n=2&a[0]?r.return:a[0]?r.throw||((n=r.return)&&n.call(r),0):r.next)&&!(n=n.call(r,a[1])).done)return n;switch(r=0,n&&(a=[2&a[0],n.value]),a[0]){case 0:case 1:n=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!n||a[1]>n[0]&&a[1]<n[3])){i.label=a[1];break}if(6===a[0]&&i.label<n[1]){i.label=n[1],n=a;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(a);break}n[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{o=n=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function m(e,t,o){if(o||2===arguments.length)for(var r,n=0,s=t.length;n<s;n++)!r&&n in t||(r||(r=Array.prototype.slice.call(t,0,n)),r[n]=t[n]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.P_INIT_O="P-init-O",e.P_DB_OPEN_O="P-db_open-O",e.P_CALL_MAIN_SYNC_E="P-call_main_sync-E",e.P_CALL_MAIN_E="P-call_main-E",e.P_SEND_2_MAIN_E="P-send_2_main-E",e.P_REGTYP_O="P-regtype-O",e.P_CALL_ADDON_E="P-call_addon-E",e.P_CALL_ADDON_T="P-call_addon-T",e.P_CALL_ADDON_O="P-call_addon-O",e.P_CALL_ADDON_R="P-call_addon-R",e.P_CALL_EXTRA_E="P-call_extra-E",e.P_CONNECT_S="P-connect-S",e.P_CONNECT_T="P-connect-T",e.P_CONNECT_O="P-connect-O",e.P_CONNECT_ENTRY_S="P-connect_entry-S",e.P_REPORT_VER_O="P-report_version-O",e.P_PARSE_JSON_MSGS_E="P-parse_json_messsages-E",e.P_PARSE_JSON_MSGS_R="P-parse_json_messsages-R",e.P_RECEIVE_MESSAGE_E="P-receive_message-E",e.P_HTTP_REQ_E="P-http_request-E",e.P_SET_MSG_EXTEN_O="P-set_msg_extension-O",e.P_SEND_MSG_T="P-send_msg-T",e.P_SEND_MSG_R="P-send_msg-R",e.P_PARSE_JSON_SUBSCRIBE_DATA_E="P-parse_json_subscribe_data-E",e.P_WRITE_LOG_T="P_WRITE_LOG_T",e.P_WRITE_LOG_R="P_WRITE_LOG_R",e.P_PARSE_JSON_E="P-parse_json-E"}(v||(v={}));var E,T={flushTimestamp:Date.now(),queue:[],locked:!1};function P(){E&&clearInterval(E)}function R(e,t){P(),E=setInterval((function(){return M(e,t)}),1e4)}function I(){for(var e,t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];(e=T.queue).push.apply(e,t)}var O=200;function M(e,t){var o=T.queue,r=T.flushTimestamp;if(!(T.locked||0===o.length||Date.now()-r<3e4&&o.length<O)){T.locked=!0;var n=t.createTraceId(),s=t.getSessionId(),i=o.splice(0,O).map((function(e){var t=e.sessionId,o=e.level,r=e.time,n=e.type,i=e.tag,a=e.loggerId,c=e.content,u=e.traceId;return{level:o,time:r,type:n,tag:i,sessionId:s+":"+t,content:JSON.stringify({loggerId:a,content:c,traceId:u})}}));t.debug(v.P_WRITE_LOG_T,"writingLen: "+i.length+", queueLen: "+o.length,n);var a=JSON.stringify(i);e.writeLog(a),t.debug(v.P_WRITE_LOG_R,"write done, queueLen: "+o.length,n),T.flushTimestamp=Date.now(),T.locked=!1,setTimeout((function(){return M(e,t)}))}}var N=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return g(t,e),t.prototype.flush=function(e){I(e)},t}(e.BasicLogger),b=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return g(t,e),t.prototype.flush=function(e){I(e)},t}(e.BasicStatistic),U=function(e,t){var o,r=Buffer.from(e),n=r.length;for(t.push(n),o=0;o<n;o++)t.push(r[o])},x=function(e){return"string"==typeof e},L=function(e){return x(e)?e.toUpperCase():""},w=function(e,t){var o="";return 2!==e.length?o="Unexpected number of bytes received.":5!==e[0]?o="Unexpected SOCKS version number: "+e[0]+".":255===e[1]?o="No acceptable authentication methods were offered.":-1===t.indexOf(e[1])&&(o="Unexpected SOCKS authentication method: "+e[1]+"."),o},A=function(e){var t="";return 2!==e.length?t="Unexpected number of bytes received.":1!==e[0]?t="Unexpected authentication method code: "+e[0]+".":0!==e[1]&&(t="Username and password authentication failure: "+e[1]+"."),t},D=function(e){var t=L(e.method)||"GET",o=e.pathname||"/",r=e.headers||{},n=e.search||"";r.Host=e.host||"loclahost";var s="";for(var i in s=t+" "+(o+n)+" HTTP/1.1\n",r){if(Object.hasOwnProperty.call(r,i))s+=i+": "+r[i]+"\n"}return e.body&&(s+="Content-Length: "+e.body.length+"\n"),s+="\n","POST"===t&&e.body&&(s+=""+e.body),s},k=function(e){return new Promise((function(t){var o,r;e.socket.once("data",(function(r){var n,s=w(r,o);if(!s)return 2===r[1]?(e.socket.once("data",(function(o){var r=A(o);r?e.emit("error",new Error("SOCKS authentication failed. "+r)):t()})),n=[1],U(e.socksUsername,n),U(e.socksPassword,n),void e.write(Buffer.from(n))):void t();e.emit("error",new Error("SOCKS authentication failed. "+s))})),o=[0],e.socksUsername&&o.push(2),(r=Buffer.alloc(2+o.length))[0]=5,r[1]=o.length,o.forEach((function(e,t){r[2+t]=e})),e.write(r)}))},J=function(e,t,o){return new Promise((function(r){var n,s;switch(e.socket.once("data",(function(t){var o;5!==t[0]?o="Unexpected SOCKS version number: "+t[0]+".":0!==t[1]?o=function(e){switch(e){case 1:return"General SOCKS server failure";case 2:return"Connection not allowed by ruleset";case 3:return"Network unreachable";case 4:return"Host unreachable";case 5:return"Connection refused";case 6:return"TTL expired";case 7:return"Command not supported";case 8:return"Address type not supported";default:return"Unknown status code "+e}}(t[1])+".":0!==t[2]&&(o="The reserved byte must be 0x00."),o?e.emit("error",new Error("SOCKS connection failed. "+o)):r()})),(n=[]).push(5),n.push(1),n.push(0),c.isIP(t)){case 0:n.push(3),U(t,n);break;case 4:n.push(1),function(e,t){var o,r,n=e.split(".");for(o=0;o<4;o++)r=parseInt(n[o],10),t.push(r)}(t,n);break;case 6:e.emit("error",new Error("Does not support IPV6"))}n.length+=2,(s=Buffer.from(n)).writeUInt16BE(o,s.length-2),e.write(s)}))},B=function(e){function t(t){var o=e.call(this)||this;return o.readable=!0,o.socket=new c.Socket,o.options=t,o.socksHost=t.socksHost||"localhost",o.socksPort=t.socksPort||1080,o.socksUsername=t.socksUsername||"",o.socksPassword=t.socksPassword||"",o.socket.on("error",(function(e){o.emit("error",e)})),o.on("error",(function(){o.socket.destroyed||o.socket.destroy()})),o.on("end",o.end),o}return g(t,e),t.prototype.ref=function(){return this.socket.ref()},t.prototype.unref=function(){return this.socket.unref()},t.prototype.setTimeout=function(e,t){return this.socket.setTimeout(e,t)},t.prototype.setNoDelay=function(e){return this.socket.setNoDelay(e)},t.prototype.setKeepAlive=function(e,t){return this.socket.setKeepAlive(e,t)},t.prototype.address=function(){return this.socket.address()},t.prototype.cork=function(){return this.socket.cork()},t.prototype.uncork=function(){return this.socket.uncork()},t.prototype.pause=function(){return this.socket.pause()},t.prototype.resume=function(){return this.socket.resume()},t.prototype.pipe=function(e){return this.socket.pipe(e)},t.prototype.end=function(e,t){var o=this.socket.end(e,t);return this.writable=this.socket.writable,o},t.prototype.destroy=function(e){return this.socket.destroy(e)},t.prototype.setEncoding=function(e){return this.socket.setEncoding(e)},t.prototype.write=function(e,t,o){return this.socket.write(e,t,o)},t.prototype.read=function(e){return this.socket.read(e)},t.prototype.connect=function(e,t){var o=this;if("string"==typeof e&&/^\d+$/.test(e)&&(e=parseInt(e,10)),!Number.isInteger(e)||e<1||e>65535)throw new TypeError("Invalid port: "+e);if(!t||"string"!=typeof t)throw new TypeError("Invalid host: "+t);return this.socket.connect({port:this.socksPort,host:this.socksHost},(function(){return _(o,void 0,void 0,(function(){var o;return y(this,(function(r){switch(r.label){case 0:return[4,k(this)];case 1:return r.sent(),[4,J(this,t,e)];case 2:return r.sent(),this.onProxied(),o=D(this.options),this.socket.write(Buffer.from(o)),[2]}}))}))})),this},t.prototype.onProxied=function(){var e=this;this.socket.on("close",(function(t){e.emit("close",t)})),this.socket.on("end",(function(){e.emit("end")})),this.socket.on("data",(function(t){e.emit("data",t)})),this.writable=!0,this.readable=!0,this.emit("connect")},t}(u.EventEmitter),F=function(e){var t,o=e.hostname,r=e.port;return!e.host||o&&r||(t=e.host.split(":")),!r&&t&&(r=parseInt(t[1],10)||0),!o&&t&&(o=t[0]),new B(e).connect(r,o)},j=function(e){function t(t){var o=e.call(this)||this;return o.createConnection=F,o}return g(t,e),t}(s.Agent),H=function(e,t,o){return(t=S(S({},t),a.parse(e))).port||(t.port=80),t.agent=new j(t),s.request(t,o)},V=function(e){var t,o;return t=F(e),o=t.onProxied,t.onProxied=function(){e.socket=t.socket,e.hostname?e.servername=e.hostname:e.host&&(e.servername=e.host.split(":")[0]),t.socket=p.connect(e,(function(){t.authorized=t.socket.authorized,o.call(t)})),t.socket.on("error",(function(e){t.emit("error",e)}))},t},q=function(e){function t(t,o){var r=e.call(this,o)||this;return r.url=t,r.socksHost=o.socksHost||"localhost",r.socksPort=o.socksPort||1080,r.createConnection=V,r}return g(t,e),t}(i.Agent),G=function(e,t,o,r){var n,s;return t.protocol="https:",!t.port&&t.host&&(n=t.host.split(":"),t.port=n[0],t.port=n[1]),t.port||(t.port=443),s=new q(e,t),t.agent=s,i.request(e,t,o)},K=null;function Q(t,o,r){void 0===r&&(r=!1);var n=o.url,a=o.headers,c=o.body,u=o.method,p=o.query,d=o.timeout,l=void 0===d?e.HTTP_TIMEOUT:d;return new Promise((function(o){var d=/^https/.test(n),h={headers:a,method:u};d&&(h.rejectUnauthorized=r);var f=null;K?((h=S(S({},h),K)).body=c,f=d?G:H):(f=s.request,d&&(h.agent=new i.Agent(h),f=i.request));var C=f(e.appendUrl(n,p),h,(function(e){var t=e.statusCode,r="";e.setEncoding("utf8"),e.on("data",(function(e){r+=e})),e.once("end",(function(){o({status:t||0,data:r})}))}));C.once("timeout",(function(){t.warn(v.P_HTTP_REQ_E,JSON.stringify({msg:"timeout",url:n,method:u,query:p,timeout:l})),o({status:0})})),C.setTimeout(l),C.once("error",(function(e){t.warn(v.P_HTTP_REQ_E,JSON.stringify({msg:e.stack,url:n,method:u,query:p,timeout:l})),o({status:0})})),C.write(c),C.end()}))}function W(t,o){return t?(K=S(S({},K),t),o.info(e.LogTagId.A_SET_PROXY_O,JSON.stringify({msg:"set proxy",data:K})),{code:e.ErrorCode.SUCCESS}):(K=null,o.info(e.LogTagId.A_REMOVE_PROXY_O,JSON.stringify({msg:"remove proxy"})),{code:e.ErrorCode.SUCCESS})}function Y(){var t=K||void 0;return{code:e.ErrorCode.SUCCESS,data:t}}var X,z=[],$=!1,Z=function(){return _(void 0,void 0,void 0,(function(){var t,o,r,n,s,i,a,c,u,p,d,l,h;return y(this,(function(f){return $||0===z.length||($=!0,t=z.shift(),o=t.args,r=t.resolve,n=o.addon,s=o.startTime,i=o.endTime,a=o.level,c=o.realtimeReport,u=0,p=0,d=[],l=function(t){u+=t.length;var o=t.split(","),n=o[0],s=o[1],i=o[2],l=o[3],h=o[4],f=o.slice(5);if(u>e.REAT_TIME_LOG_SIZE&&parseInt(s,10)!==p)r(d);else{p=parseInt(s,10);try{if(!c&&a<0)return;var C={time:parseInt(s,10),level:parseInt(l,10),sessionId:n,type:i,tag:h,content:f.join(",")};d.push(C)}catch(e){console.error(e)}}},h=function(e){r(d),$=!1,Z()},n.getFullLog(a,s,i,!1,l,h)),[2]}))}))},ee=function(t){function o(o,r,n,s,i){var a=this,c="Electron|"+process.versions.electron+"|"+process.arch+"|"+process.platform;return(a=t.call(this,r,n,c,{getLogs:function(e,t,r,n){return _(this,void 0,void 0,(function(){return y(this,(function(s){switch(s.label){case 0:return[4,(i={startTime:e,endTime:t,level:r,realtimeReport:n,addon:o},_(void 0,void 0,void 0,(function(){return y(this,(function(e){return[2,new Promise((function(e){z.push({resolve:e,args:i}),Z()}))]}))})))];case 1:return[2,{logs:s.sent(),dbReady:!0}]}var i}))}))},getTimestamp4RealtimeLog:function(){var t=o.getStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP);return parseInt(t,10)||0},setTimestamp4RealtimeLog:function(t){o.setStoreValue(e.StoreKeys.REALTIME_LOG_TIMESTAMP,t.toString())}},s)||this).subProcess=i,a}return g(o,t),o.prototype.send=function(e){return Q(this.logger,e)},o.prototype.compressLogs=function(e){return _(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,this.subProcess.call("compressLogs",e)];case 1:return t=n.sent(),o=t.success,r=t.data,o?[2,{success:o,data:r.data}]:[2,{success:o,data:""}]}}))}))},o}(e.BasicReporter),te=[e.EConnectProtocol.RMTP,e.EConnectProtocol.TLS,e.EConnectProtocol.QUIC],oe=function(e){return"RongCloud/navis/"+e+"/navi-cache.json"},re="deviceId",ne=function(e){return"RongCloud/caches/"+e+"/staticConfig.json"},se=function(e){return"RongCloud/cloudControl/"+e+"/cloudControl.json"},ie=null,ae=function(){var e,t=Date.now(),o=[n.arch(),n.platform(),process.pid,t,Math.floor(Math.random()*t)].join("__");return e=o,l.createHash("md5").update(e).digest("hex")},ce=function(e){if(ie)return ie;var t=r.resolve(e,re);return d.existsSync(t)?ie=d.readFileSync(t).toString():(ie=ae(),d.writeFileSync(t,ie),ie)},ue=function(){function e(e){this._callCppProxy=e,this._setTime=15962112e5}return e.prototype._setToProtocol=function(e,t,o,r,n,s){var i=JSON.stringify(n);"{}"!==i&&e.info(v.P_SET_MSG_EXTEN_O,JSON.stringify({messageUId:r,ext:n})),this._callCppProxy("setMessageExtension",t,o,r,i,s)},e.prototype.setLocalFromReceiveMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.messageUId,i=t.expansion,a=t.sentTime,c={};for(var u in i)c[u]={v:"",ts:0},c[u].v=i[u],c[u].ts=a;this._setToProtocol(e,r,n,s,c,o||"")},e.prototype.setLocalFromExtMsg=function(e,t){var o=t.channelId,r=t.conversationType,n=t.targetId,s=t.content,i=t.sentTime,a=s,c=a.put,u=this._callCppProxy("getMessage",a.mid),p=JSON.parse(u).extMsg,d=JSON.parse(p||"{}");if(c)for(var l in c){var h=d[l];h&&h.ts<i-this._setTime?(h.v=c[l],h.ts=i-this._setTime):(d[l]={v:"",ts:0},d[l].v=c[l],d[l].ts=i-this._setTime)}a.del&&a.del.forEach((function(e){delete d[e]})),this._setToProtocol(e,r,n,a.mid,d,o||"")},e.prototype.parseReceiveExpansion=function(e){var t=JSON.parse(e.extMsg||"{}"),o={};for(var r in t)o[r]=t[r].v;return o},e.prototype.parseConverOrHisExpansion=function(e){var t=JSON.parse(e.extMsg),o=JSON.parse(t||"{}"),r={};for(var n in o)r[n]=o[n].v;return r},e}();!function(e){e[e.ERROR=-1]="ERROR",e[e.RESPONSE=0]="RESPONSE",e[e.EVENT=1]="EVENT",e[e.CALLBACK=2]="CALLBACK"}(X||(X={}));var pe=function(){function t(t,o,r,n){var s=this;this.p=t,this.emit=o,this.callback=r,this.errorHandle=n,this.count=0,this.maps={},this.p.on("message",(function(e){var t=e.type,i=e.data;switch(t){case X.EVENT:var a=i,c=a.eventName,u=a.data;null==o||o.apply(void 0,m([c],u,!1));break;case X.RESPONSE:var p=i,d=p.reqId,l=p.success,h=p.data,f=s.maps[d];if(!f)return;f({success:l,data:h}),delete s.maps[d];break;case X.CALLBACK:null==r||r(i);break;case X.ERROR:var C=i.msg;null==n||n(C)}})),this.p.on("error",(function(e){null==n||n("SubProcessProxy error "+e)})),this.p.on("exit",(function(t,o){if(0!==t){for(var r in s.maps){if(Object.prototype.hasOwnProperty.call(s.maps,r))(0,s.maps[r])({success:!0,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})}null==n||n("SubProcessProxy exit "+t+" "+o,!0)}})),this.p.on("close",(function(e,t){console.log("SubProcessProxy close",e,t)}))}return t.prototype.call=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return _(this,void 0,void 0,(function(){var r=this;return y(this,(function(n){return this.p.killed||this.p.exitCode?[2,Promise.resolve({success:!1,data:{code:e.ErrorCode.SUB_PROCESS_EXIT,msg:"sub process exit"}})]:[2,new Promise((function(e){var n=++r.count;r.maps[n]=e;var s={reqId:n,method:t,args:o,hasResponse:!0};r.p.send(s)}))]}))}))},t.prototype.send=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return _(this,void 0,void 0,(function(){var r;return y(this,(function(n){return(this.p.killed||this.p.exitCode)&&(null===(t=this.errorHandle)||void 0===t||t.call(this,"sub process exit")),r={reqId:-1,method:e,args:o},this.p.send(r),[2]}))}))},t.prototype.destroy=function(){this.send("destroy")},t}();function de(e){void 0===e&&(e="IPv4");for(var t=n.networkInterfaces(),o=[],r=0,s=Object.values(t);r<s.length;r++){var i=s[r];if(i&&-1!==Object.prototype.toString.call(i).indexOf("Array")){var a=i.filter((function(t){return!(t.internal||(o=t.mac,/^(0{1,2}[:-]){5}0{1,2}$/.test(o))||t.family&&t.family!==e);var o})).map((function(e){return e.mac}));o.push.apply(o,a)}}return o.length?o.sort()[0]:""}var le,he=function(e,t,o){return _(void 0,void 0,void 0,(function(){var r,n;return y(this,(function(s){return r=l.createDecipheriv("aes-256-cbc",t,o),n=r.update(e,"base64","utf-8"),[2,n+=r.final("utf8")]}))}))},fe=function(e){if(!d.existsSync(e)){var t=r.resolve(e,"..");d.existsSync(t)||fe(t),d.mkdirSync(e)}},Ce=function(t){function o(e,o,n,s,i){var a=t.call(this,e,o,n,i)||this;a.naviPath="",a._caches={},a.naviPath=s+"/"+oe(e);var c=r.dirname(a.naviPath);return d.existsSync(c)||fe(c),a}return g(o,t),o.prototype.httpRequest=function(t,o,r,n){return _(this,void 0,void 0,(function(){var s,i,a,c,u;return y(this,(function(p){switch(p.label){case 0:return s="token="+encodeURIComponent(r)+"&v="+e.FORMATED_VERSION+"&p=PC&ev=5.9.9&m="+de(),i=t+"/navi.json?r="+Date.now()+"&env="+this._environment,this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:i,body:s}),n),[4,Q(this.logger,{method:"POST",headers:{appId:o},body:s,url:i,timeout:e.NAVI_REQ_TIMEOUT})];case 1:if(200!==(a=p.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,code:a.status}),n),[2,{code:this.transHttpCode(a.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:i,data:a.data}),n);try{return c=JSON.parse(a.data),u=/^https/.test(i)?"https":"http",c.protocol=u,c.code&&200!==c.code?[2,{code:this.transHttpCode(c.code)}]:[2,{code:e.ErrorCode.SUCCESS,data:c}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,a.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.httpRequestV2=function(t,o,r,n){return _(this,void 0,void 0,(function(){var s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return s=this.getNaviV2RequestOption({appkey:o,token:r,uri:t,platform:"electron",protocol:te.join(","),mac:de()}),this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify({url:s.url,body:s.body,headers:s.headers}),n),[4,Q(this.logger,s)];case 1:if(200!==(i=u.sent()).status)return this.logger.warn(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,code:i.status}),n),[2,{code:this.transHttpCode(i.status)}];this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({url:s.url,data:i.data}),n);try{return a=JSON.parse(i.data),c=/^https/.test(s.url)?"https":"http",a.protocol=c,[2,{code:e.ErrorCode.SUCCESS,data:a}]}catch(t){return this.logger.error(e.LogTagId.L_PARSE_NAVI_E,i.data,n),[2,{code:e.ErrorCode.RC_NAVI_REQ_FAILED}]}return[2]}}))}))},o.prototype.getNaviCache=function(t){var o=this.getCatchKey(t),r=this._caches[o];if(r)return r;if(!d.existsSync(this.naviPath))return null;var n=d.readFileSync(this.naviPath,{encoding:"utf8"});try{return this._caches=JSON.parse(n),this._caches[o]}catch(t){this.logger.error(e.LogTagId.L_PARSE_NAVI_E,n)}return null},o.prototype.setNaviCache=function(t,o){var r=Date.now(),n=this.getCatchKey(t);if(e.notEmptyObject(this._caches))for(var s in this._caches){(r-this._caches[s].timestamp>e.NAVI_CACHE_DURATION||n===s)&&delete this._caches[s]}this._caches[n]={token:t,naviInfo:o,timestamp:Date.now(),environment:this._environment},d.writeFileSync(this.naviPath,JSON.stringify(this._caches))},o.prototype.setEnvironment=function(e){this._environment=e},o}(e.BasicNavi);!function(e){e[e.SUCCESS=0]="SUCCESS",e[e.NOT_INIT=-1]="NOT_INIT",e[e.CANCELED=-2]="CANCELED",e[e.REPEAT=-3]="REPEAT"}(le||(le={}));var ge,ve=function(t){function o(o,r,n,s,i,a){var c=t.call(this,o,n,s,i,a)||this;return c.callCppProxy=r,c._connectedTime=0,c._naviInfo=null,c._excludeLogTag=["P-RCGetValueForKey-T","P-RCGetValueForKey-E","P-RCGetValueForKey-R","P-RCSetValueForKey-T","P-RCSetValueForKey-E","P-RCSetValueForKey-R"],c.connectResolve=null,c._startTime=0,c._tcpDuration=0,c.pingResolve=null,c.callCppProxy("setConnectionStatusListener",c._onConnectionStatusChange.bind(c),(function(e){c.logger.info(v.P_DB_OPEN_O,e)}),(function(){return c.recvPong(e.ErrorCode.SUCCESS)}),c._onConnectionStatusChange.bind(c),c._onTcpConnectResponse.bind(c)),c}return g(o,t),o.prototype.getConnectedTime=function(){return this._connectedTime},o.prototype.connectWithToken=function(t,o,r,n){var s=this;return new Promise((function(i){s._naviInfo=o,s.connectResolve={resolve:i,traceId:n,userId:o.userId};var a={},c=Y().data;c&&(a={proxy_passwd:c.socksPassword||"",proxy_name:c.socksUsername||"",proxy_port:c.socksPort||1082,proxy_host:c.socksHost||"localhost",proxy_type:0});var u=JSON.stringify(S(S({},a),{call_plus:s._openCallPlus})),p=s.getCmpList(o,!0).filter((function(e){return te.includes(e.protocol)})).sort((function(e,t){return e.weight>t.weight?-1:1})),d=[];p.forEach((function(t){var o=d.find((function(e){return e.addr===t.addr}));o?o.protocol!==e.EConnectProtocol.QUIC&&t.protocol!==e.EConnectProtocol.QUIC||(o.race=!0,o.protocol=e.EConnectProtocol.QUIC):(t.race=!1,d.push(t))})),s.logger.info(v.P_CONNECT_O,JSON.stringify({use:d,catche:s.cmpWeightCache,proxy:a,FORMATED_VERSION:e.FORMATED_VERSION,reconnectKickEnable:r}),n),s._startTime=Date.now();try{s.callCppProxy("connectWithToken",t,e.FORMATED_VERSION,JSON.stringify(S(S({},o),{serverAddr:d,tagBlacklist:s._excludeLogTag.join(",")})),r,u)}catch(t){s.logger.error(v.P_CALL_ADDON_E,null==t?void 0:t.stack,n),s.recvConnectRes(e.ErrorCode.RC_SOCKET_NOT_CREATED)}}))},o.prototype.close=function(e,t){void 0===t&&(t=!0),e||this.callCppProxy("disconnect",t)},o.prototype.sendPing=function(t){var o=this;return new Promise((function(r){o.pingResolve=r,o.callCppProxy("sendHeartbeat"),setTimeout((function(){return o.recvPong(e.ErrorCode.TIMEOUT)}),t)}))},o.prototype.recvPong=function(e){this.pingResolve&&(this.pingResolve(e),this.pingResolve=null)},o.prototype._onConnectionStatusChange=function(t,o){switch(this.logger.info(v.P_CONNECT_S,JSON.stringify({status:t,delay:o})),t){case e.ErrorCode.SUCCESS:this.recvConnectRes(e.ErrorCode.SUCCESS);break;case e.ErrorCode.RC_CONN_REDIRECTED:case 32061:this.recvConnectRes(e.ErrorCode.RC_CONN_REDIRECTED,!0);break;case 11:case 10:case 12:break;case e.ErrorCode.RC_SOCKET_DISCONNECTED:this.recvConnectRes(t,!1);break;case e.ErrorCode.RC_SOCKET_NOT_CREATED:case e.ErrorCode.RC_CONN_ACK_TIMEOUT:case e.ErrorCode.RC_TCP_RESET:this.recvConnectRes(t);break;case e.ErrorCode.RC_UDP_DISCONNECTED:this.recvConnectRes(t,!0,o);break;default:this.recvConnectRes(t,!0)}},o.prototype.recvConnectRes=function(t,o,r){if(this.connectResolve){var n=this.connectResolve,s=n.resolve,i=n.userId,a=Date.now()-(this._startTime+this._tcpDuration),c={bid:e.getbundleId(),cod:t,net:this.getNetwork().type,dur:a,spr:0,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,count:this.retryCount};return this.statisticLog.record(e.StatisticsTag.IM_CMP_RMTP,JSON.stringify(c)),t===e.ErrorCode.SUCCESS&&(this._connectedTime=Date.now()-this.callCppProxy("getDeltaTime")),s({code:t,data:i}),void(this.connectResolve=null)}if(o)this.onDisconnectByServer(t,r);else{if(t===e.ErrorCode.RC_SOCKET_DISCONNECTED)if(this.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED)return;this.onDisconenctUnusual(t)}},o.prototype._onTcpConnectResponse=function(t,o,r,n,s,i,a){var c,u=this.cmpWeightCache.findIndex((function(e){return e.addr===o+":"+r})),p={bid:e.getbundleId(),ptc:e.ProtocalType.TCP,cod:t,net:this.getNetwork().type,dur:n,spr:0,pr:(null===(c=this._naviInfo)||void 0===c?void 0:c.type)||0,hos:o+":"+r,idx:u,rct:this.retryCount?e.ConnectType.RECONNECT:e.ConnectType.CONNECT,cid:this.uuid+"_"+this.retryCount,v:e.StatisticsVersion.CURRENT,rsn:this.reason,ddu:s,count:this.retryCount,weight:u>=0?this.cmpWeightCache[u].weight:-1};this.statisticLog.record(e.StatisticsTag.IM_CMP,JSON.stringify(p)),this.logger.info(v.P_CONNECT_ENTRY_S,JSON.stringify({code:t,host:o,port:r,duration:n,dnsDuration:s,index:i,isQuic:a})),t===le.SUCCESS&&(this.curCmpUrl=o+":"+r,this.updateCmpWeight(o+":"+r,!0,a))},o}(e.AConnectionMgr),Se=function(t){function o(e,o,n){var s=t.call(this,e,o)||this;s.appkey=e,s.logger=o,s.dbpath=n,s._cachePath="",s._cachePath=n+"/"+ne(e);var i=r.dirname(s._cachePath);return d.existsSync(i)||fe(i),s}return g(o,t),o.prototype.getCache=function(){return d.existsSync(this._cachePath)&&d.readFileSync(this._cachePath,{encoding:"utf8"})||null},o.prototype.setCache=function(e){d.writeFileSync(this._cachePath,e)},o.prototype.clearCache=function(){d.writeFileSync(this._cachePath,"")},o.prototype.sendRequest=function(e){return _(this,void 0,void 0,(function(){var t,o,r;return y(this,(function(n){switch(n.label){case 0:return[4,Q(this.logger,{url:e,body:""})];case 1:return t=n.sent(),o=t.status,r=t.data,[2,{code:o,data:r}]}}))}))},o.prototype.decryptData=function(t){return _(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,he(t,e.STATIC_CONFIG_KEY,e.STATIC_CONFIG_IV)];case 1:return o=n.sent(),[2,JSON.parse(o)];case 2:return r=n.sent(),this.logger.error(e.LogTagId.L_GET_STATIC_CONF_E,JSON.stringify({error:null==r?void 0:r.stack})),[3,3];case 3:return[2]}}))}))},o}(e.BasicStaticConfigManager),_e=function(t){function o(e,o,n,s,i,a,c){var u=t.call(this,o,e,n,a)||this;u.deviceId=s,u.model="",u.catchFilePath="",u.addon=c,u.model="Electron|"+process.platform+"|"+process.arch,u.catchFilePath=i+"/"+se(e);var p=r.dirname(u.catchFilePath);return d.existsSync(p)||fe(p),u.init(),u}return g(o,t),o.prototype.httpRequest=function(t,o,r,n){return _(this,void 0,void 0,(function(){var s,i,a,c,u,p,d,l;return y(this,(function(h){switch(h.label){case 0:return(s=n).deviceId=this.deviceId,s.model=this.model,i={url:t,method:o,headers:r,body:JSON.stringify(s)},this.logger.info(e.LogTagId.L_REQUEST_T,JSON.stringify(i)),[4,Q(this.logger,i)];case 1:a=h.sent(),c=a.status,u=a.data,p=void 0===u?"":u,this.logger.info(e.LogTagId.L_REQUEST_R,JSON.stringify({status:c,data:p}));try{return d=JSON.parse(p),l=d.data,[2,{code:c,data:l}]}catch(t){return this.logger.warn(e.LogTagId.L_CLOUD_CONFIG_DATA_E,JSON.stringify({status:c,data:p,error:t})),[2,{code:c,msg:t}]}return[2]}}))}))},o.prototype.setCloudControllerCache=function(t){d.writeFileSync(this.catchFilePath,JSON.stringify(t)),this.logger.info(e.LogTagId.L_CLOUD_SET_CACHE_O,JSON.stringify(t))},o.prototype.getLocalCloudControllerCache=function(){if(!d.existsSync(this.catchFilePath))return null;var t=d.readFileSync(this.catchFilePath,{encoding:"utf8"});return this.logger.info(e.LogTagId.L_CLOUD_GET_CACHE_O,JSON.stringify({appkey:this.appkey,data:t})),t},o.prototype.setMRTRConfig=function(t){var o={mrtrChatroom:t.chatroom,mrtrGroup:t.group,mrtrPrivate:t.private,mrtrUltraGroup:t.ultraGroup};this.logger.info(e.LogTagId.L_CLOUD_SET_MRTR_O,JSON.stringify(o)),this.addon.setCloudConfig(JSON.stringify(o))},o}(e.BaseCloudController);!function(e){e[e.cuid=1]="cuid",e[e.uid=2]="uid",e[e.all=4]="all"}(ge||(ge={}));var ye,me=function(){function t(t,n,s,i,a){var c=this;this._appkey=t,this._cppProtocol=n,this._dbpath=s,this._dispatchEvent=i,this._logOutputLevel=a,this._customMessageType={},this.cloudControllerUri="",this.cloudControllerLock=!0,this.cloudControllerMsgs=[],this._buildSubscribeEventData=function(e){var t=[];try{JSON.parse(e).list.forEach((function(e){var o=JSON.parse(e.obj),r=o.userId,n=o.subscribeType,s=o.subscribeTime,i=o.duration,a=o.operationType,c=o.details,u=void 0===c?[]:c;t.push({userId:r,subscribeType:n,subscribeTime:s,duration:i,operationType:a,details:u.map((function(e){var t=JSON.parse(e);return{changeTime:t.changeTime,eventValue:t.changeValue,platform:t.platform}}))})}))}catch(t){c.logger.error(v.P_PARSE_JSON_SUBSCRIBE_DATA_E,JSON.stringify({error:null==t?void 0:t.stack,data:e}))}return t},this._chatroomCache=[],this.rtcHeartbeatResolves={};var u=this._dbpath,p=ce(u);this.logger=new N(this._appkey,"RC-M","IM"),this._cppProtocol.initWithAppkey(t,u,e.FORMATED_VERSION,this.logger.getSessionId());var d=o.fork(r.resolve(__dirname,"sub-process.js"));this.subProxy=new pe(d),this.statisticLog=new b(this._appkey,"RC-M","IM"),this.logger.setOutputLevel(this._logOutputLevel),R(this._cppProtocol,this.logger),this.reporter=new ee(this._cppProtocol,t,p,this.logger,this.subProxy),this.logger.info(v.P_INIT_O,JSON.stringify({appkey:t,dbpath:u,proto_commit:this._cppProtocol.getNodeVersion(),deviceId:p,commit:"ac04313edeb4b97f5b9015d75bbe9396b2781d95"})),this._callCppProxy("setDeviceId",p),this._staticConfigManager=new Se(t,this.logger,u),this.navi=new Ce(t,this.logger,this.statisticLog,u,this._staticConfigManager),this.tcpMgr=new ve(t,this._callCppProxy.bind(this),this.navi,this.logger,this.statisticLog,{onConnected:this.onConnected.bind(this),onSuspend:this.onSuspend.bind(this),onDisconnected:this.onDisconnected.bind(this),onConnecting:this.onConnecting.bind(this)}),this._initCloudController(p,u),this._registerMsgTypes(),this._setOnReceiveMessageListener(),this._setConversationStatusListener(),this._setUserProfileListener(),this._setRTCHeartbeatListener(),this._setRTCLivingRoomEventListener(),this._setChatroomEventListener(),this._setCallInfoListener(),this._setSubscribeEventListener(),this._msgExpansionHandler=new ue(this._callCppProxy.bind(this))}return t.prototype._initCloudController=function(t,o){var r=e.urlCenter.getCloudControllerUrl();this.cloudControllerUri=r[0],this.cloudController=new _e(this._appkey,this.logger,this.reporter,t,o,this.statisticLog,this._cppProtocol),e.isStartCloudController()&&this.cloudControllerUri&&this.cloudController.request(this.cloudControllerUri,e.InvokerType.init)},t.prototype.callProxy=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];return _(this,void 0,void 0,(function(){var r,n,s;return y(this,(function(i){switch(i.label){case 0:if(!(r=this[t]))return this.logger.warn(v.P_CALL_MAIN_E,JSON.stringify({method:t,error:"not found"})),[2,Promise.resolve({code:e.ErrorCode.NOT_SUPPORT})];n="",i.label=1;case 1:return i.trys.push([1,3,,4]),[4,r.call.apply(r,m([this],o,!1))];case 2:return[2,i.sent()];case 3:return s=i.sent(),n=JSON.stringify({error:null==s?void 0:s.stack,method:t}),this.logger.error(v.P_CALL_MAIN_E,n),[3,4];case 4:return[2,{code:e.ErrorCode.MAIN_PROCESS_ERROR,msg:n}]}}))}))},t.prototype.sendProxy=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return _(this,void 0,void 0,(function(){var o;return y(this,(function(r){if(!(o=this[e]))return this.logger.warn(v.P_CALL_MAIN_E,JSON.stringify({method:e,error:"not found"})),[2];try{o.call.apply(o,m([this],t,!1))}catch(t){this.logger.error(v.P_CALL_MAIN_E,JSON.stringify({error:null==t?void 0:t.stack,method:e}))}return[2]}))}))},t.prototype.registerRenderers=function(t){var o=t.navigators,r=t.areaCode,n=t.logServerUrl,s=t.environment;this._environment=s||"default",this.navi.setEnvironment(s),e.urlCenter.init({areaCode:r,navigators:o,logServerUrl:n})},t.prototype.onConnected=function(){return _(this,void 0,void 0,(function(){var e,t,o;return y(this,(function(r){switch(r.label){case 0:return e=this.getNaviInfoFromCache(),this.reporter.checkStart(e),this._try2RejoinChatroom(),t=this._dispatchEvent,o=["onConnected"],[4,this.getMainProcessCache()];case 1:return t.apply(this,o.concat([r.sent()])),[2]}}))}))},t.prototype.onConnecting=function(){this._dispatchEvent("onConnecting",void 0)},t.prototype.onSuspend=function(e){this._dispatchEvent("onSuspend",e)},t.prototype.onDisconnected=function(e){this._dispatchEvent("onDisconnected",e)},t.prototype._callCppProxy=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this.logger.createTraceId();try{return this.logger.debug(v.P_CALL_ADDON_O,JSON.stringify({method:e,content:o}),n),(t=this._cppProtocol)[e].apply(t,o)}catch(t){throw this.logger.error(v.P_CALL_ADDON_E,JSON.stringify({stack:null==t?void 0:t.stack,method:e}),n),t}},t.prototype.refetchNaviInfo=function(){return this.navi.request(this.tcpMgr.getToken(),!0,!0,this.logger.createTraceId())},t.prototype.sendHTTPRequest=function(e){return Q(this.logger,e)},t.prototype.onRendererLogsReceived=function(e){I.apply(void 0,e)},t.prototype.onRendererNetworkStatusReceived=function(t,o){if(this.tcpMgr.setNetwork(t,o),t.status&&e.isStartCloudController()&&this.cloudController){var r=this.tcpMgr.getToken();this.cloudController.request(this.cloudControllerUri,e.InvokerType.newWorkChange,r)}},t.prototype.destroy=function(){this.reporter.stop(),this.subProxy.destroy(),this._cppProtocol,P(),this._cppProtocol.destroy(),process.exit(0)},t.prototype.callExtra=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=this[t];if(!n)return this.logger.warn(v.P_CALL_EXTRA_E,JSON.stringify({method:t,error:"not found"})),Promise.resolve({code:e.ErrorCode.NOT_SUPPORT});try{return n.call.apply(n,m([this],o,!1))}catch(e){this.logger.error(v.P_CALL_EXTRA_E,JSON.stringify({error:null==e?void 0:e.stack,method:t}))}return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})},t.prototype.getConversationsByPage=function(t,o,r,n,s){var i,a=this,c=this._callCppProxy("getConversationListByPageWithTopPriority",t,o,r,s||!1,n||"");try{i=JSON.parse(c).list.map((function(e){return a._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:i})},t.prototype.getUnreadConversationList=function(t){var o,r=this,n=this._callCppProxy("getUnreadConversationList",t);try{o=JSON.parse(n).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t.prototype.getConversationListWithAllChannel=function(){var t,o=this,r=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],n=this._callCppProxy("getConversationListWithAllChannel",r);try{t=JSON.parse(n).list.map((function(e){return o._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},t.prototype.getConversationListWithAllChannelByPage=function(t,o){var r,n=this,s=[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.APP_PUBLIC_SERVICE,e.ConversationType.PUBLIC_SERVICE],i=this._callCppProxy("getConversationListWithAllChannelByPage",s,t,o);try{r=JSON.parse(i).list.map((function(e){return n._buildConversation(e.obj)}))}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},t.prototype.getHistoryMessagesByObjectNames=function(t,o,r,n,s,i,a){var c=0===i,u=n+1,p=this._callCppProxy("getHistoryMessagesByObjectNames",t,o,r,u,s,c,a||""),d=[];try{var l=JSON.parse(p).list;l.reverse();for(var h=0;h<l.length;h++){var f=this._buildMessage(l[h].obj);d[h]=f}}catch(t){return Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:{list:u===d.length?d.slice(1,u):d,hasMore:n<d.length}})},t.prototype.updateMessageReceiptStatus=function(t,o,r,n){void 0===n&&(n="");var s=this._callCppProxy("updateMessageReceiptStatus",t,o,r,n);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.getNaviInfoFromCache=function(){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.CONNECTED?null:this.navi.getNaviInfoFromCache(this.tcpMgr.getToken())},t.prototype.createLogger=function(e,t){return/^RC/.test(e)?null:new N(this._appkey,e,t)},t.prototype.getConnectedTime=function(){return this.tcpMgr.getConnectedTime()},t.prototype.getServerTime=function(){return Date.now()-this._cppProtocol.getDeltaTime()},t.prototype.getCurrentUserId=function(){return this.tcpMgr.getCurrentUserId()},t.prototype.getMainProcessCache=function(){var e=this.tcpMgr.getConnectedTime(),t=this.tcpMgr.getConnectionStatus(),o=this.getNaviInfoFromCache(),r=this.tcpMgr.getCurrentUserId(),n=this.getDeviceId(),s=this._cppProtocol.getDeltaTime();return Promise.resolve({connectedTime:e,deviceId:n,crtUserId:r,naviInfo:o,connectionStatus:t,deltaTime:s})},t.prototype._registerMsgTypes=function(){for(var t in e.SEND_MESSAGE_TYPE_OPTION["RC:RcCmd"]={isCounted:!1,isPersited:!1},e.SEND_MESSAGE_TYPE_OPTION){var o=e.SEND_MESSAGE_TYPE_OPTION[t],r=o.isCounted,n=o.isPersited,s=o.searchProps,i=0;n&&(i|=1),r&&(i|=2),"RC:TypSts"===t&&(i=16),this._callCppProxy("registerMessageType",t,i,s||[])}},t.prototype._buildIsMentioned=function(t,o){var r,n=!1;if(e.isObject(t))r=t;else try{r=t?JSON.parse(t):t}catch(e){r=t,this.logger.error(v.P_PARSE_JSON_MSGS_E,JSON.stringify({content:t}))}return e.isObject(r)&&(n=!!r.mentionedInfo),{isMentioned:n,msgContent:r}},t.prototype._buildMsgOption=function(t){var o={isCounted:!1,isPersited:!1};return t in e.SEND_MESSAGE_TYPE_OPTION?o=e.SEND_MESSAGE_TYPE_OPTION[t]:t in this._customMessageType&&(o=this._customMessageType[t]),o},t.prototype._buildSupportExt=function(e,t,o){var r=null;return e&&(r=this._msgExpansionHandler.parseReceiveExpansion(o),"conversation"!==t&&"history"!==t||(r=this._msgExpansionHandler.parseConverOrHisExpansion(o))),r},t.prototype._handleReadReceiptRequest=function(e){var t=JSON.parse(e),o=this.getNaviInfoFromCache();if(!(null==o?void 0:o.grpRRVer))return t;var r=t,n=r.hasRespond,s=r.readerInfo,i=void 0===s?{}:s,a=r.readCount,c=r.totalCount,u=r.readerList,p=void 0===u?[]:u,d={readCount:a,totalCount:c};if(1===(null==o?void 0:o.grpRRVer)){var l=[];for(var h in i)l.push({userId:h,readTime:i[h]});d.readerList=l,d.hasRespond=n}return 3===(null==o?void 0:o.grpRRVer)&&(d.readerList=p),d},t.prototype._buildMessage=function(t,o){var r;void 0===o&&(o={});var n=o.isOffLineMessage,s=o.buildFrom,i=JSON.parse(t),a=i.channelId,c=i.conversationType,u=i.targetId,p=i.senderUserId,d=i.content,l=i.objectName,h=i.messageUid,f=i.direction,C=i.status,g=i.messageId,v=i.sentTime,_=i.readReceiptRequest,y=i.supportExt,m=i.pushContent,E=i.pushTitle,T=i.pushId,P=i.pushConfig,R=i.templateId,I=i.disableTitle,O=i.forcePushDetail,M=i.hasMore,N=i.directedUsers,b=i.noNotification,U=this._buildIsMentioned(d,g),x=U.isMentioned,L=U.msgContent,w=this._buildMsgOption(l),A=this._buildSupportExt(y,s,i),D=e.isUndefined(n)?v<this.tcpMgr.getConnectedTime():n,k={};P&&(k=e.pushJSONToConfigs(this.logger,P,T));var J=S(S({},k),{pushTitle:E,pushContent:m,pushData:m,disablePushTitle:I,forceShowDetailContent:O,templateId:R}),B={channelId:a,conversationType:c,targetId:u,senderUserId:p,content:L||{},messageType:l,messageUId:h||"",messageDirection:f,isOffLineMessage:D,sentTime:v,receivedTime:0,isPersited:w.isPersited,isCounted:w.isCounted,isMentioned:x,disableNotification:b,isStatusMessage:(null===(r=this._customMessageType[l])||void 0===r?void 0:r.isStatusMessage)||!1,canIncludeExpansion:y,expansion:y?A:null,receivedStatus:C,receivedStatusInfo:e.transformReceivedStatusInfo(C),messageId:g,pushConfig:J,hasMore:M,directedUserIds:N||[]};if(f===e.MessageDirection.RECEIVE?B.receivedStatus=this._compatibleReceivedStatus(B.receivedStatusInfo):f===e.MessageDirection.SEND&&(B.sentStatus=C),_){var F=this._handleReadReceiptRequest(_);B.readReceiptInfo=F}return B},t.prototype._compatibleReceivedStatus=function(t){var o=e.ReceivedStatus.UNREAD;return t.isRead?o=e.ReceivedStatus.READ:t.isListened?o=e.ReceivedStatus.LISTENED:t.isDownload?o=e.ReceivedStatus.DOWNLOADED:t.isRetrieved&&(o=e.ReceivedStatus.RETRIEVED),o},t.prototype._updateReadReceiptInfo=function(e,t){var o=this._callCppProxy("getMessage",e),r=JSON.parse(o),n=r.readReceiptRequest?JSON.parse(r.readReceiptRequest):{},s=S(S({},n),t);this._callCppProxy("updateReadReceiptRequestInfo",e,JSON.stringify(s))},t.prototype._processRRRspMsg=function(e,t,o){if(t!==this.getCurrentUserId())for(var r=0,n=e[this.getCurrentUserId()]||[];r<n.length;r++){f=n[r];var s=this._callCppProxy("getMessage",f),i=JSON.parse(s),a=i.readReceiptRequest?JSON.parse(i.readReceiptRequest):{},c=a.isReceiptRequestMessage,u=a.readerList,p=void 0===u?[]:u;c&&!p.includes(t)&&(p.push(t),this._callCppProxy("updateReadReceiptRequestInfo",f,JSON.stringify({isReceiptRequestMessage:c,readerList:p})))}else for(var d in e)for(var l=0,h=e[d];l<h.length;l++){var f=h[l];this._callCppProxy("updateReadReceiptRequestInfo",f,JSON.stringify({isReceiptRequestMessage:!0,hasRespond:!0}))}},t.prototype._processRSMsg=function(t){var o=t.conversationType,r=t.targetId,n=t.content,s=t.channelId,i=n.msgId,a=n.rrn,c=n.tmn,u=n.endMsgTime;o===e.ConversationType.PRIVATE?this.updateMessageReceiptStatus(o,r,u,s||""):this._updateReadReceiptInfo(i,{readCount:a,totalCount:c});var p={conversationType:o,targetId:r,channelId:s};this._sendMessageReadReceipt(o===e.ConversationType.PRIVATE?{privateReadReceipt:S(S({},p),{endMsgTime:n.endMsgTime})}:{groupReadReceipt:S(S({},p),{totalCount:n.tmn,readedCount:n.rrn,messageUId:n.msgId})})},t.prototype._processSRSMsg=function(e){var t=this.getNaviInfoFromCache(),o=e.conversationType,r=e.targetId,n=e.content,s=e.channelId,i=e.senderUserId,a=e.sentTime;return i===this.tcpMgr.getCurrentUserId()&&(this._callCppProxy("clearUnreadCountByTimestamp",o,r,n.lastMessageSendTime,s||""),1!==(null==t?void 0:t.sesDriven)||(a>this.tcpMgr.getConnectedTime()||this._sendsyncReadStatus({conversationType:o,targetId:r,channelId:s,timestamp:n.lastMessageSendTime}),!1))},t.prototype._buildConversation=function(t){var o=JSON.parse(t),r=o.channelId,n=o.conversationType,s=o.targetId,i=o.unreadCount,a=o.lastestMsg,c=o.isTop,u=o.blockStatus,p=o.matchCount,d=o.hasUnreadMention,l=o.conversationTime,h=o.draft,f=u>0?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE;return{channelId:r,conversationType:n,targetId:s,unreadMessageCount:i,latestMessage:-1===JSON.parse(a).messageId?null:this._buildMessage(a),hasMentioned:d,mentionedInfo:null,notificationStatus:f,isTop:c,lastUnreadTime:0,matchCount:p,operationTime:l,notificationLevel:u,draft:h}},t.prototype._convertResultList=function(e,t){var o=JSON.parse(e).list;return o=o.map((function(e){var o=JSON.parse(e.obj);return t?t(o):o}))},t.prototype._handleNotNotificationMessage=function(t){var o,r=t.messageType,n=t.senderUserId,s=t.content;if(r===e.MessageType.LOG_COMMAND&&t.senderUserId===e.RC_DEFAULT_USER){var i=t.content,a=i.startTime,c=i.endTime,u=i.platform,p=i.logId,d=i.uri;return this.reporter.report(parseInt(a,10),parseInt(c,10),u,d,p,t.messageUId),!0}if(r===e.MessageType.CLOUD_CONTROL&&n===e.RC_DEFAULT_USER)return this.cloudControllerMsgs.push(t),this._ccMsgHandler(),!0;if(r===e.MessageType.READ_STATE)return this._processRSMsg(t),!0;if("RC:MsgExMsg"===r)return this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),this._sendMessageExpansion(t),!0;if(r===e.MessageType.SYNC_READ_STATUS&&!this._processSRSMsg(t))return!0;if(r===e.MessageType.DELIVERED)return this._callCppProxy("setMessageDeliverTime",JSON.stringify(s)),this._sendMessageDelivered(t.content.map((function(e){return{deliverTime:e.time,messageUId:e.messageUId,objectName:e.objectName,targetId:e.targetId}}))),!0;if(r===e.MessageType.DELIVERED_MSG){var l={totalCount:t.content.tmn,list:null===(o=t.content.dl)||void 0===o?void 0:o.map((function(e){return{MessageUId:e.msgId,deliveryCount:e.drn}}))};return this._sendGroupMessageDeliveredStatus(l),!0}return!1},t.prototype._setOnReceiveMessageListener=function(){var t=this;this._cppProtocol.setOnReceiveMessageListener((function(o,r,n,s){try{var i=t._buildMessage(o,{isOffLineMessage:n}),a=i.messageType,c=i.channelId,u=void 0===c?"":c,p=i.senderUserId,d=i.content,l=i.sentTime,h=i.conversationType,f=i.targetId;if(t._handleNotNotificationMessage(i))return;if(a===e.MessageType.READ_RECEIPT_REQUEST&&d.messageUId&&t._updateReadReceiptInfo(d.messageUId,{isReceiptRequestMessage:!0,hasRespond:!1}),a===e.MessageType.READ_RECEIPT_RESPONSE&&d.receiptMessageDic&&t._processRRRspMsg(d.receiptMessageDic,p,l),a===e.MessageType.GROUP_READ_RECEIPT_REQUEST){var C=d.msgId,g=d.rrn,S=d.tmn;t._updateReadReceiptInfo(C,{readCount:g,totalCount:S})}i.canIncludeExpansion&&t._msgExpansionHandler.setLocalFromReceiveMsg(t.logger,i),a===e.MessageType.READ_RECEIPT&&p===t.tcpMgr.getCurrentUserId()&&t._callCppProxy("clearUnreadCountByTimestamp",h,f,d.lastMessageSendTime,u);var _=!0;if(0!==r||s||(_=!1),a===e.MessageType.RECALL){if(!t.handleRecalledMessage(i))return;var y=t._fixRecallContentInfo(i);h=y.conversationType,f=y.targetId}t._sendMessageNotification(Object.assign(i,{hasMoreMsg:_,conversationType:h,targetId:f}))}catch(e){t.logger.error(v.P_RECEIVE_MESSAGE_E,JSON.stringify({error:null==e?void 0:e.stack,message:o}))}}),(function(){t._sendPullOfflineFinished()}))},t.prototype._ccMsgHandler=function(){var t;return _(this,void 0,void 0,(function(){var o,r;return y(this,(function(n){switch(n.label){case 0:return this.cloudControllerLock?(this.cloudControllerLock=!1,this.cloudControllerMsgs.shift()?(o=this.tcpMgr.getToken(),[4,null===(t=this.cloudController)||void 0===t?void 0:t.request(this.cloudControllerUri,e.InvokerType.other,o)]):[3,2]):[2];case 1:r=n.sent()||0,this.cloudControllerMsgs=this.cloudControllerMsgs.filter((function(e){return e.sentTime>r})),this.cloudControllerLock=!0,this._ccMsgHandler(),n.label=2;case 2:return[2]}}))}))},t.prototype._fixRecallContentInfo=function(e){var t=e.conversationType,o=e.targetId;return e.senderUserId===this.tcpMgr.getCurrentUserId()&&(t=e.content.conversationType||t,o=e.content.targetId||o),{conversationType:t,targetId:o}},t.prototype.handleRecalledMessage=function(t){var o=t.content,r=o.messageUId,n=o.sentTime;if(!r)return!0;var s=this._callCppProxy("getMessage",r),i=this._buildMessage(s,{isOffLineMessage:!1});if(t.content.isDelete)return-1===i.messageId||this._callCppProxy("deleteMessages",[i.messageId]),!0;if(i.messageType===e.MessageType.RECALL_NOTIFICATION_MESSAGE)return!1;var a={recallTime:Date.now(),admin:!!t.content.isAdmin,originalObjectName:i.messageType,originalMessageContent:i.content,recallActionTime:t.sentTime,operatorId:t.senderUserId};if(t.content.user&&(a.user=t.content.user),t.content.extra&&(a.extra=t.content.extra),i.messageType===e.MessageType.TextMessage&&(a.recallContent=i.content.content),-1===i.messageId){var c=t.conversationType,u=t.targetId,p=t.senderUserId,d=t.channelId,l=t.messageDirection;return this._callCppProxy("insertMessage",c,u,p,e.MessageType.RECALL_NOTIFICATION_MESSAGE,JSON.stringify(a),(function(){}),(function(){}),l,1,30,n,"",0,r,!1,!0,JSON.stringify({}),d||""),!0}return i.receivedStatus||this.setMessageReceivedStatus(i.messageId,1),this._callCppProxy("setMessageContent",i.messageId,JSON.stringify(a),e.MessageType.RECALL_NOTIFICATION_MESSAGE),!0},t.prototype._sendMessageExpansion=function(e){var t=e.channelId,o=void 0===t?"":t,r=e.content,n=e.conversationType,s=e.targetId,i=r,a=i.put,c=i.del,u=i.mid,p={};a&&(p.updatedExpansion={channelId:o,messageUId:u,expansion:a,conversationType:n,targetId:s}),c&&(p.deletedExpansion={channelId:o,messageUId:u,deletedKeys:c,conversationType:n,targetId:s}),this._dispatchEvent("expansion",p)},t.prototype._sendMessageNotification=function(e){this._dispatchEvent("batchMessage",e)},t.prototype._sendPullOfflineFinished=function(){this._dispatchEvent("pullFinished",null)},t.prototype._sendMessageDelivered=function(e){this._dispatchEvent("messageDelivered",e)},t.prototype._sendGroupMessageDeliveredStatus=function(e){this._dispatchEvent("groupMessageDeliveredStatus",e)},t.prototype._sendChatroomStatus=function(e){this._dispatchEvent("chatroom",e)},t.prototype._sendMessageReadReceipt=function(e){this._dispatchEvent("messageReadReceipt",e)},t.prototype._sendsyncReadStatus=function(e){this._dispatchEvent("syncReadStatus",e)},t.prototype._setConversationStatusListener=function(){var t=this;this._cppProtocol.setConversationStatusListener((function(o){var r=JSON.parse(o).list,n=[];r.forEach((function(t){var o=JSON.parse(t.obj),r=o.conversationType,s=o.targetId,i=o.status,a=o.channelId,c={notificationStatus:2,isTop:!1};i.forEach((function(t){var o=JSON.parse(t.item);1===o.type?c.notificationStatus=1===Number(o.value)?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE:c.isTop=1===Number(o.value)})),n.push({channelId:a,conversationType:r,targetId:s,updatedItems:{notificationStatus:{val:c.notificationStatus,time:0},isTop:{val:c.isTop,time:0}}})})),t._dispatchEvent("conversation",n)}),(function(e){t._dispatchEvent("conversationTag",e)}),(function(e,o,r,n){t._callCppProxy("clearUnreadCountByTimestamp",e,o,n,r||""),t._sendsyncReadStatus({conversationType:e,targetId:o,channelId:r,timestamp:n})}))},t.prototype._setUserProfileListener=function(){var e=this;this._cppProtocol.setUserProfileListener((function(){}),(function(t){e._dispatchEvent("tag",t),e._getRTCProfile()}))},t.prototype._getRTCProfile=function(){var e=this._callCppProxy("getRTCProfile");if(e){var t=this.tcpMgr.getToken();this.navi.updateVoipCallInfo(t,e);var o=this.navi.getNaviInfoFromCache(t);this._dispatchEvent("onNaviDataChange",o)}},t.prototype._setRTCLivingRoomEventListener=function(){var e=this;this._cppProtocol.setRTCRoomEventListener((function(t){e._dispatchEvent("onRTCDataChange",Array.prototype.slice.call(t))}))},t.prototype._setChatroomEventListener=function(){var e=this;this._cppProtocol.setChatroomEventListener((function(t,o){e._sendChatroomStatus({chatroomDestroyed:t})}))},t.prototype._setCallInfoListener=function(){var e=this;this._cppProtocol.setCallInfoListener((function(t){e._dispatchEvent("callInfo",t)}))},t.prototype._setSubscribeEventListener=function(){var e=this;this._cppProtocol.setSubscribeEventListener((function(){}),(function(){e._dispatchEvent("syncSubscribedUserStatusFinished")}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,operationType:e.operationType}}));e._dispatchEvent("subscribedRelationChange",o)}),(function(t){var o=e._buildSubscribeEventData(t).map((function(e){return{userId:e.userId,subscribeType:e.subscribeType,subscribeTime:e.subscribeTime,expiry:e.duration,details:e.details}}));e._dispatchEvent("subscribedUserStatusChange",o)}))},t.prototype._updateMentionedInfo=function(t,o,r){var n,s,i;return{userIdList:(null===(n=t.mentionedInfo)||void 0===n?void 0:n.userIdList)||o,type:(null===(s=t.mentionedInfo)||void 0===s?void 0:s.type)||r||e.MentionedType.ALL,mentionedContent:(null===(i=t.mentionedInfo)||void 0===i?void 0:i.mentionedContent)||""}},t.prototype.registerMessageType=function(e,t,o,r,n){var s=0;t&&(s|=1),o&&(s|=2),n&&(s=16),this._customMessageType[e]={isCounted:o,isPersited:t,isStatusMessage:n},this.logger.info(v.P_REGTYP_O,JSON.stringify({type:e,opt:s,search:r})),this._callCppProxy("registerMessageType",e,s,r||[])},t.prototype.connect=function(e,t,o,r){return this.tcpMgr.connect(e,t,o,r)},t.prototype.reportSDKInfo=function(e){var t=JSON.stringify(S(S({},e),{"electron-main":"5.9.9"}));this.logger.info(v.P_REPORT_VER_O,t),this._callCppProxy("uploadSDKVersion",t,"")},t.prototype.disconnect=function(e){e=e||!0,this._chatroomCache.length=0,this.reporter.stop(),W(null,this.logger),this.tcpMgr.disconnect(e)},t.prototype.logout=function(){this.disconnect()},t.prototype.setUserStatusListener=function(e,t){this._cppProtocol.setOnReceiveStatusListener((function(e,o){t({userId:e,status:o})}));var o=e.userIds||[];o.length&&this.subscribeUserStatus(o)},t.prototype.subscribeUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("subscribeUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.setUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("setUserStatus",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getUserStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getUserStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:{status:t}})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype._handleDirectionalUserIdList=function(t){var o=t.messageType,r=t.content,n=t.directionalUserIdList,s=void 0===n?[]:n;if(o===e.MessageType.READ_RECEIPT_RESPONSE&&r.receiptMessageDic)for(var i in r.receiptMessageDic)s.push(i);return o===e.MessageType.SYNC_READ_STATUS&&(s=[this.getCurrentUserId()]),s},t.prototype._handleMessage2Callback=function(t,o){var r=this;if("RC:MsgExMsg"===t.messageType&&this._msgExpansionHandler.setLocalFromExtMsg(this.logger,t),t.messageType===e.MessageType.READ_RECEIPT_REQUEST)this._updateReadReceiptInfo(o.content.messageUId,{isReceiptRequestMessage:!0,readerList:[]});else if(t.messageType===e.MessageType.READ_RECEIPT_RESPONSE){var n=o.content.receiptMessageDic;if(!n)return;for(var s in n)n[s].forEach((function(e){r._updateReadReceiptInfo(e,{isReceiptRequestMessage:!0,hasRespond:!0})}))}},t.prototype.sendMessage=function(t,o,r,n,s){var i=this;void 0===s&&(s=this.logger.createTraceId());var a=r.messageType,c=r.content,u=r.expansion,p=r.pushConfig,d=r.isMentioned,l=r.mentionedType,h=r.mentionedUserIdList,f=void 0===h?[]:h,C=r.pushContent,g=void 0===C?"":C,S=r.pushData,_=void 0===S?"":S,y=r.directionalUserIdList,m=void 0===y?[]:y,E=r.disableNotification,T=void 0!==E&&E,P=r.canIncludeExpansion,R=void 0!==P&&P,I=r.isVoipPush,O=void 0!==I&&I,M=r.channelId,N=void 0===M?"":M,b=r.messageId,U=void 0===b?0:b,x=p||{},L=x.iOSConfig,w=x.androidConfig,A=x.templateId,D=void 0===A?"":A,k=x.pushTitle,J=void 0===k?"":k,B=x.pushContent,F=void 0===B?g:B,j=x.pushData,H=void 0===j?_:j,V=x.disablePushTitle,q=void 0!==V&&V,G=x.forceShowDetailContent,K=void 0!==G&&G,Q=e.pushConfigsToJSON(L,w);return new Promise((function(p){g=F,_=H;var h=(null==w?void 0:w.notificationId)||"",C=t===e.ConversationType.GROUP;C&&d&&c&&(c.mentionedInfo=i._updateMentionedInfo(c,f,l)),C&&(m=i._handleDirectionalUserIdList(r));var S={};for(var y in u)S[y]={v:""},S[y].v=u[y];var E=D;i.logger.info(v.P_SEND_MSG_T,JSON.stringify({messageType:a,conversationType:t,targetId:o,channelId:N}),s);var P=i._callCppProxy("sendMessage",(function(t,o){var n=i._buildMessage(t,{isOffLineMessage:!1});if(i.logger.info(v.P_SEND_MSG_R,JSON.stringify({code:o,messageUId:n.messageUId}),s),o===e.ErrorCode.SENSITIVE_REPLACE)return setTimeout((function(){p({code:o})}),0);[e.MessageType.READ_RECEIPT_REQUEST,e.MessageType.READ_RECEIPT_RESPONSE,e.MessageType.EXPANSION_NOTIFY].findIndex((function(e){return e===n.messageType}))>-1&&i._handleMessage2Callback(n,r),n.canIncludeExpansion&&i._msgExpansionHandler.setLocalFromReceiveMsg(i.logger,n),setTimeout((function(){p({code:e.ErrorCode.SUCCESS,data:n})}),0)}),(function(e,t){var o=i._buildMessage(e,{isOffLineMessage:!1});i.logger.warn(v.P_SEND_MSG_R,JSON.stringify({code:t,messageId:o.messageId}),s),o.sentTime=Date.now()-i._cppProtocol.getDeltaTime(),setTimeout((function(){p({code:t,data:o})}),0)}),t,o,a,JSON.stringify(c),m,T,q,K,g,_,h,J,Q,E,R,JSON.stringify(S),O,N,U),I=JSON.parse(P);null==n||n(I.messageId)}))},t.prototype.recallMsg=function(t,o,r,n,s){var i=this;return new Promise((function(a){var c,u=s.user,p=s.pushContent,d=s.channelId,l=s.extra,h=s.pushConfig,f=s.disableNotification,C=s.isDelete,g=s.directionalUserIdList,v={conversationType:t,targetId:o,messageUId:r,sentTime:n,user:u,extra:l,channelId:d,isDelete:C||!1};u&&(v.user=u),l&&(v.extra=l);var S={conversationType:t,targetId:o,senderUserId:i.tcpMgr.getCurrentUserId(),content:v,objectName:e.MessageType.RECALL,messageUid:r,direction:e.MessageDirection.SEND,status:e.ReceivedStatus.UNREAD,sentTime:n,channelId:d},_=i._buildMessage(JSON.stringify(S),{isOffLineMessage:!1});i._callCppProxy("recallMessage",(function(){i.handleRecalledMessage(_),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:_})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}),e.MessageType.RECALL,JSON.stringify(v),f||!1,(null==h?void 0:h.disablePushTitle)||!1,(null==h?void 0:h.forceShowDetailContent)||!1,p||"",(null==h?void 0:h.pushData)||"",(null===(c=null==h?void 0:h.androidConfig)||void 0===c?void 0:c.notificationId)||"",(null==h?void 0:h.pushTitle)||"",e.pushConfigsToJSON(null==h?void 0:h.iOSConfig,null==h?void 0:h.androidConfig),(null==h?void 0:h.templateId)||"",d,g||[])}))},t.prototype.getHistoryMessage=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){r=r||0;var p=0===s,d=n+1,l=c._callCppProxy("getHistoryMessages",t,o,r,d,a,p,i),h=JSON.parse(l).list,f=[];h.reverse();for(var C=0;C<h.length;C++){var g=c._buildMessage(h[C].obj);f[C]=g}u({code:e.ErrorCode.SUCCESS,data:{list:d===f.length?f.slice(1,d):f,hasMore:n<f.length}})}))},t.prototype.getMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){var u=0===s,p=r,d=0!==r,l=n+1;d&&(p+=u?1:-1,l++);for(var h=a._callCppProxy("getMessages",t,o,p,l,u,i),f=JSON.parse(h).list,C=[],g=0;g<f.length;g++){var v=a._buildMessage(f[g].obj);C[g]=v}var S=a._computeRepairInfo(C,u,r,p,l),_=S.isNeedRepair,y=void 0!==_&&_,m=S.repairTime,E=void 0===m?0:m;if(!y)return d&&(C.shift(),l--),C.reverse(),void c({code:e.ErrorCode.SUCCESS,data:{list:l===C.length?C.slice(1,l):C,hasMore:n<C.length}});a._processRepairHisMsg(t,o,r,n,s,i,E,c)}))},t.prototype._computeRepairInfo=function(e,t,o,r,n){var s=!1,i=0,a=this.getNaviInfoFromCache()||{},c=a.repairHisMsg,u=void 0===c?0:c,p=a.historyMsg;if(1!==u||!p)return{isNeedRepair:s,repairTime:i};var d=e.findIndex((function(e){return e.hasMore||0===Object.keys(e.content).length}));return t&&d>=0?(s=!0,i=e[d].hasMore?e[d].sentTime:e[d].sentTime+1):!t&&d>=1?(s=!0,i=e[d-1].sentTime):e.length<n||0===o?(s=!0,i=o):e.length>0&&e[0].sentTime!==o&&(s=!0,i=r),{isNeedRepair:s,repairTime:i}},t.prototype._processRepairHisMsg=function(e,t,o,r,n,s,i,a){var c=this,u=function(i){for(var u=0===n,p=r+1,d=c._callCppProxy("getMessages",e,t,o,p,u,s),l=JSON.parse(d).list,h=[],f=0;f<l.length;f++){var C=c._buildMessage(l[f].obj);h[f]=C}h.reverse(),a({code:i,data:{list:p<=h.length?h.slice(1,p):h,hasMore:r<h.length}})},p=r+10>100?100:r+10;this._callCppProxy("getRemoteHistoryMessages",e,t,i,p,(function(){return u(0)}),(function(e){u(e)}),n,!0,s,!1)},t.prototype.getContinuousMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;var u=0===s;a._callCppProxy("getContinuousMessages",t,o,r,n,(function(t,o,r){var n=JSON.parse(t).list,s=[];n.reverse();for(var i=0;i<n.length;i++){var u=a._buildMessage(n[i].obj);s[i]=u}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:s,timestamp:o,hasMore:r}})}))}),(function(e){setTimeout((function(){c({code:e})}),0)}),u,i)}))},t.prototype.getRemoteHistoryMessages=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){r=r||0;a._callCppProxy("getRemoteHistoryMessages",t,o,r,n,(function(t,o){var r=JSON.parse(t).list,n=[];r.reverse();for(var s=0;s<r.length;s++){var i=a._buildMessage(r[s].obj);n[s]=i}setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{list:n,hasMore:!!o}})}),0)}),(function(e){setTimeout((function(){c({code:e})}),0)}),s,!0,i,!0)}))},t.prototype.deleteRemoteMessage=function(t,o,r,n){var s=this;return new Promise((function(i){var a=JSON.stringify(r);s._callCppProxy("deleteRemoteHistoryMessages",t,o,a,!1,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),i)}))},t.prototype.deleteRemoteMessageByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearRemoteHistoryMessages",t,o,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),n)}))},t.prototype.clearMessages=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearMessages",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.getConversationList=function(t,o,r,n,s){var i=this;return void 0===s&&(s=""),new Promise((function(t){for(var o=i._callCppProxy("getConversationList",[1,3,6,7],s),r=JSON.parse(o).list,n=[],a=0;a<r.length;a++)n.push(i._buildConversation(r[a].obj));t({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.getConversation=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversation",t,o,r);if(i)s({code:e.ErrorCode.SUCCESS,data:n._buildConversation(i)});else{var a=n._callCppProxy("getHistoryMessages",t,o,0,1,"",!0,r),c=void 0;try{c=JSON.parse(a).list}catch(e){n.logger.error(v.P_PARSE_JSON_MSGS_E,null==e?void 0:e.stack),c=[]}var u=null;c.length>0&&(u=n._buildMessage(c[0].obj));var p=n._callCppProxy("getConversationNotificationStatus",t,o,r),d=n._callCppProxy("getConversationTopStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:{conversationType:t,targetId:o,channelId:r,unreadMessageCount:0,latestMessage:u,notificationStatus:p?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,isTop:Boolean(d),lastUnreadTime:0}})}}))},t.prototype.removeConversation=function(t,o,r){var n=this._callCppProxy("removeConversation",t,o,r);return Promise.resolve(n?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.batchRemoveConversation=function(t){var o=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId}})),r=this._callCppProxy("removeConversationInBatches",JSON.stringify(o));return Promise.resolve(r?e.ErrorCode.SUCCESS:e.ErrorCode.CONVER_REMOVE_ERROR)},t.prototype.clearConversations=function(t,o){var r=this;return new Promise((function(n){var s=[];s=e.isArray(t)?t:[e.ConversationType.PRIVATE,e.ConversationType.GROUP,e.ConversationType.SYSTEM,e.ConversationType.PUBLIC_SERVICE],r._callCppProxy("clearConversations",s,o||""),n(e.ErrorCode.SUCCESS)}))},t.prototype.getAllConversationUnreadCount=function(t,o,r){var n=this._callCppProxy("getTotalUnreadCount",o,r,t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){var i=n._callCppProxy("getUnreadCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationUnreadCount=function(t,o,r){var n=this;return void 0===r&&(r=""),new Promise((function(s){n._callCppProxy("clearUnreadCount",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.clearUnreadCountByTimestamp=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("clearUnreadCountByTimestamp",t,o,r,n),i(e.ErrorCode.SUCCESS)}))},t.prototype.getFirstUnreadMessage=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),a=n._buildMessage(i);s({code:e.ErrorCode.SUCCESS,data:-1!==a.messageId?a:null})}))},t.prototype.getFirstUnreadMessageInfo=function(t,o,r){var n=this;return new Promise((function(s,i){var a=n._callCppProxy("getTheFirstUnreadMessage",t,o,r),c=n._buildMessage(a);s({code:e.ErrorCode.SUCCESS,data:-1!==c.messageId?{messageUId:c.messageUId,sentTime:c.sentTime}:null})}))},t.prototype.batchSetConversationToTop=function(t,o,r){var n=this;return new Promise((function(s,i){var a=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,is_top:o}}));n._callCppProxy("setIsTopInBatches",JSON.stringify(a),r||!1),s(e.ErrorCode.SUCCESS)}))},t.prototype.setConversationStatus=function(t,o,r,n,s,i){var a=this;return new Promise((function(i){a._callCppProxy("setConversationStatus",t,o,r,n,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}),s,!0)}))},t.prototype.getConversationNotificationStatus=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getConversationNotificationStatus",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE})}))},t.prototype.setConversationTypeNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){r._callCppProxy("setBlockPushLevelForType",t,o,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getConversationTypeNotificationLevel=function(t){var o=this;return new Promise((function(r,n){var s=o._callCppProxy("getBlockPushLevelForType",t);r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.searchConversationByContent=function(t,o,r,n){var s=this;return new Promise((function(i){n=n||[1,3,6,7];for(var a=s._callCppProxy("searchConversationByContent",n,t,o,r),c=JSON.parse(a).list,u=[],p=0;p<c.length;p++)u[p]=s._buildConversation(c[p].obj);i({code:e.ErrorCode.SUCCESS,data:u})}))},t.prototype.searchConversationByContentWithAllChannel=function(t,o,r){var n=this;return new Promise((function(s){r=r||[1,3,6,7];for(var i=n._callCppProxy("searchConversationByContentWithAllChannel",r,t,o),a=JSON.parse(i).list,c=[],u=0;u<a.length;u++)c[u]=n._buildConversation(a[u].obj);s({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.searchMessageByContent=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(i){c._callCppProxy("searchMessageByContent",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=c._buildMessage(r[s].obj);setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}),a)}))},t.prototype.searchMessageByContentAndMessageType=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){for(var p=c._callCppProxy("searchMessageByContentAndObjectName",o,t,a||"",void 0===a,r,i,s,n),d=p?JSON.parse(p).list:[],l=[],h=0;h<d.length;h++)l[h]=c._buildMessage(d[h].obj);u({code:e.ErrorCode.SUCCESS,data:{messages:l}})}))},t.prototype.searchMessagesByUser=function(t,o,r,n,s,i){var a=this;return new Promise((function(c){a._callCppProxy("getMessageBySender",t,o,r,n,s,i,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=a._buildMessage(o[n].obj);setTimeout((function(){c({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.searchMessageByContentWithAllChannel=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("searchMessageByContentWithAllChannel",t,o,r,n,s,1,(function(t,o){for(var r=t?JSON.parse(t).list:[],n=[],s=0;s<r.length;s++)n[s]=i._buildMessage(r[s].obj);setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{messages:n,count:o}})}),0)}))}))},t.prototype.searchMessageByContentInTimeRangeWithAllChannel=function(t,o,r,n,s,i,a){var c=this;return new Promise((function(u){c._callCppProxy("searchMessageByTimestampWithAllChannel",t,o,r,n,s,i,a,(function(t){for(var o=t?JSON.parse(t).list:[],r=[],n=0;n<o.length;n++)r[n]=c._buildMessage(o[n].obj);setTimeout((function(){u({code:e.ErrorCode.SUCCESS,data:{messages:r}})}),0)}))}))},t.prototype.getUnreadMentionedMessages=function(e,t,o){for(var r=JSON.parse(this._callCppProxy("getUnreadMentionedMessages",e,t,o)).list,n=0;n<r.length;n++)r[n]=this._buildMessage(r[n].obj);return r},t.prototype.addToBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addToBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.removeFromBlacklist=function(t){var o=this;return new Promise((function(r){o._callCppProxy("removeFromBlacklist",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getBlacklist=function(){var t=this;return new Promise((function(o){t._callCppProxy("getBlacklist",(function(t){setTimeout((function(){o({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){o({code:e})}),0)}))}))},t.prototype.getBlacklistStatus=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getBlacklistStatus",t,(function(t){setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.insertMessage=function(t,o,r){var n=this,s=r.content,i=r.senderUserId,a=r.messageType,c=r.messageDirection,u=r.readStatus,p=r.sentStatus,d=r.sentTime,l=r.searchContent,h=r.isUnread,f=r.messageUId,C=r.disableNotification,g=r.canIncludeExpansion,v=r.expansionMsg,S=r.channelId,_=r.directedUserIds;s=JSON.stringify(s);var y={};if(d=d||0,v){var m=JSON.parse(v);for(var E in m)y[E]={v:"",ts:0},y[E].v=m[E],y[E].ts=d}return new Promise((function(r){var v=h?0:1,m=n._callCppProxy("insertMessage",t,o,i,a,s,(function(){}),(function(e){setTimeout((function(){r({code:e})}),0)}),c,u||0,p||10,d,l||"",v,f||"",!!C,!!g,JSON.stringify(y),S||"",_||[]),E=n._buildMessage(m,{isOffLineMessage:!1});E.messageUId=f,E.sentTime=d,r({code:-1===E.messageId?e.ErrorCode.MSG_INSERT_ERROR:e.ErrorCode.SUCCESS,data:E})}))},t.prototype.batchInsertMessage=function(t,o){var r=this;return void 0===o&&(o=!1),new Promise((function(n){var s=t.map((function(t){var o=t.content,r=t.senderUserId,n=t.messageType,s=t.messageDirection,i=t.receivedStatus,a=void 0===i?0:i,c=t.sentStatus,u=t.sentTime,p=t.searchContent,d=t.isUnread,l=t.messageUId,h=t.disableNotification,f=t.canIncludeExpansion,C=t.expansion,g=t.channelId,v=t.conversationType,S=t.targetId,_=t.source,y=t.isMentioned,m=t.receivedStatusInfo,E=t.directedUserIds,T=a;m&&(T=e.transformReceivedStatusFlag(m));var P={};if(u=u||0,C)for(var R in C)P[R]={v:"",ts:0},P[R].v=C[R],P[R].ts=u;return{conversationType:v,targetId:S,channelId:g||"",direction:s,senderUserId:r,status:c||10,sentTime:u,objectName:n,content:JSON.stringify(o),messageUid:l||"",noNotification:!!h,supportExt:!!f,extMsg:JSON.stringify(P),readStatus:T,searchContent:p||"",isUnread:!!d,source:_||"",isMention:y,directedUsers:E}})),i=r._callCppProxy("insertMessages",JSON.stringify(s),o);n({code:i?e.ErrorCode.SUCCESS:e.ErrorCode.MSG_INSERT_ERROR,data:i||!1})}))},t.prototype.getMessageCount=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getMessageCount",t,o,r);s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.deleteMessages=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteMessages",t),r(e.ErrorCode.SUCCESS)}))},t.prototype.deleteMessagesByTimestamp=function(t,o,r,n,s){var i=this;return new Promise((function(a){i._callCppProxy("deleteMessagesByTimestamp",t,o,r,n,s),a(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearMessagesByTimestamp=function(t){var o=this;return new Promise((function(r,n){var s=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));o._callCppProxy("deleteMessageBySendTimeInBatches",JSON.stringify(s)),r(e.ErrorCode.SUCCESS)}))},t.prototype.batchClearRemoteHistoryMessages=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId||"",send_time:e.timestamp}}));r._callCppProxy("deleteRemoteMessageBySendTimeInBatches",JSON.stringify(i),o||!1,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getMessage",t),s=o._buildMessage(n,{isOffLineMessage:!1});r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setMessageContent=function(t,o,r){var n=this;return new Promise((function(s){o=JSON.stringify(o),n._callCppProxy("setMessageContent",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSearchField=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setMessageSearchField",t,o,r),s(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageSentStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageSentStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.setMessageReceivedStatus=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setMessageReceivedStatus",t,o),n(e.ErrorCode.SUCCESS)}))},t.prototype.saveConversationMessageDraft=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("saveTextMessageDraft",t,o,r,n||"")&&i(e.ErrorCode.SUCCESS),i(e.ErrorCode.DRAFT_SAVE_ERROR)}))},t.prototype.getConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){var i=n._callCppProxy("getTextMessageDraft",t,o,r||"");s({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.clearConversationMessageDraft=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("clearTextMessageDraft",t,o,r||"")&&s(e.ErrorCode.SUCCESS),s(e.ErrorCode.DRAFT_REMOVE_ERROR)}))},t.prototype.pullConversationStatus=function(e){throw new Error("Method not implemented.")},t.prototype.batchSetConversationStatus=function(t){var o=t[0],r=o.conversationType,n=o.targetId,s=o.isTop,i=o.notificationStatus,a=o.channelId,c=o.isUpdateTime,u=void 0===c||c,p=this._callCppProxy("getConversationNotificationStatus",r,n,a||""),d=this._callCppProxy("getConversationTopStatus",r,n,a||""),l=e.isUndefined(i)?Boolean(p):i===e.NotificationStatus.OPEN,h=e.isUndefined(s)?Boolean(d):s;return this.setConversationStatus(r,n,l,h,a,u)},t.prototype.getConversationNotificationLevel=function(t,o,r){return _(this,void 0,void 0,(function(){var n;return y(this,(function(s){return n=this._callCppProxy("getBlockPushLevelForConversation",o,r,t),[2,Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})]}))}))},t.prototype.setConversationNotificationLevel=function(t,o,r,n){var s=this;return void 0===n&&(n=""),new Promise((function(i){s._callCppProxy("setBlockPushLevelForConversation",o,n,t,r,(function(){setTimeout((function(){i(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){i(e)}),0)}))}))},t.prototype.batchSetConversationNotificationLevel=function(t,o){var r=this;return new Promise((function(n,s){var i=t.map((function(e){return{conversation_type:e.conversationType,target_id:e.targetId,channel_id:e.channelId,level:o}}));r._callCppProxy("setBlockPushLevelInBatches",JSON.stringify(i),(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.getTotalUnreadCountByLevels=function(t,o,r){if(r){var n=this._callCppProxy("getUnreadMentionedCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})}var s=this._callCppProxy("getUnreadCountByLevel",t,o);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.pullUserSettings=function(e){throw new Error("Method not implemented.")},t.prototype.sendReadReceiptMessage=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("sendReadReceipt",t,r||"",o,(function(){o.forEach((function(e){n._updateReadReceiptInfo(e,{hasRespond:!0});try{var t=JSON.parse(n._callCppProxy("getMessage",e)).messageId;n.setMessageReceivedStatus(t,1)}catch(t){n.logger.error(v.P_PARSE_JSON_MSGS_E,JSON.stringify({messageUId:e,error:null==t?void 0:t.stack}))}})),setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReader=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getMessageReader",t,r,o,(function(t,r){var i=[],a={};(t=JSON.parse(t)).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;i.push({userId:o,readTime:r}),a[o]=r}));var c={readerInfo:a,readCount:i.length,totalCount:r};n._updateReadReceiptInfo(o,c),setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{list:i,totalMemberCount:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.sendReadReceiptMessageV4=function(t,o,r){var n=this;return new Promise((function(s){var i=t.conversationType,a=t.targetId,c=t.channelId;n._callCppProxy("sendMessageReadReceipt",i,a,c||"",o,r,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getMessageReadReceiptV4=function(t,o){var r=this;return new Promise((function(n){var s=t.targetId,i=t.channelId;r._callCppProxy("getMessageReadReceipt",s,i||"",o,(function(t,s,i){var a=[],c=r._callCppProxy("getMessage",o),u=JSON.parse(c);try{JSON.parse(i).list.forEach((function(e){var t=JSON.parse(e.obj),o=t.id,r=t.time;a.push({userId:o,readTime:r})}))}catch(e){r.logger.error(v.P_PARSE_JSON_E,"method: getMessageReadReceipt, info: "+i+", error: "+e)}var p=JSON.parse(u.readReceiptRequest||"{}"),d=p.readerList,l=void 0===d?[]:d,h=p.readCount,f=void 0===h?0:h,C=!1;l.length<a.length&&(l=a,C=!0),f<s&&(f=s,C=!0),C&&r._callCppProxy("updateReadReceiptRequestInfo",o,JSON.stringify({readerList:l,readCount:f,totalCount:t})),setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:{list:a,totalCount:t,readCount:f}})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.updateConversationReadTime=function(t,o){var r=this;return new Promise((function(n){var s=t.conversationType,i=t.targetId,a=t.channelId;r._callCppProxy("updateConversationReadTime",s,i,a||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype._addChatroomCache=function(e,t,o){this._rmChatroomCache(e),this._chatroomCache.push({chatroomId:e,joinExist:o,count:t})},t.prototype._rmChatroomCache=function(e){this._chatroomCache=this._chatroomCache.filter((function(t){return t.chatroomId!==e}))},t.prototype._try2RejoinChatroom=function(){var t=this;if(0!==this._chatroomCache.length){var o=this.logger.createTraceId();this._chatroomCache.forEach((function(r){return _(t,void 0,void 0,(function(){var t,n,s,i,a,c;return y(this,(function(u){switch(u.label){case 0:return t=r.chatroomId,n=r.joinExist,s=r.count,this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_T,t,o),[4,this._joinChrm(t,s,n,!1)];case 1:return i=u.sent(),a=i.code,c=i.data,a===e.ErrorCode.SUCCESS?(this.logger.info(e.LogTagId.L_REJOIN_CHATROOM_R,t,o),this._sendChatroomStatus({rejoinedRoom:S({chatroomId:t,count:s},c)}),[2]):(a===e.ErrorCode.RC_CHATROOM_USER_KICKED&&this._rmChatroomCache(t),this._sendChatroomStatus({rejoinedRoom:{chatroomId:t,errorCode:a}}),this.logger.warn(e.LogTagId.L_REJOIN_CHATROOM_R,"chrmId: "+t+", code: "+a,o),[2])}}))}))}))}},t.prototype._joinChrm=function(t,o,r,n){var s=this,i=r?"joinExistChatRoom":"joinChatRoom";return new Promise((function(a){n&&s._callCppProxy("clearMessages",e.ConversationType.CHATROOM,t,""),s._callCppProxy(i,t,o,(function(n,i,c,u,p,d){s._addChatroomCache(t,o,r),setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{createTime:Number(n),memberCount:i,isAllChatroomBanned:c,isCurrentUserBanned:u,isCurrentChatroomBanned:p,isCurrentChatroomInWhitelist:d}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.joinChatroom=function(e,t){return _(this,void 0,void 0,(function(){return y(this,(function(o){switch(o.label){case 0:return[4,this._joinChrm(e,t,!1,!0)];case 1:return[2,o.sent().code]}}))}))},t.prototype.joinExistChatroom=function(e,t){return this._joinChrm(e,t,!0,!0)},t.prototype.quitChatroom=function(t){var o=this;return this._rmChatroomCache(t),new Promise((function(r){o._callCppProxy("quitChatRoom",t,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getChatroomInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getChatroomInfo",t,o,r,(function(t,o){var r=t?JSON.parse(t).list:[],n=[];if(r.length>0)for(var i=0;i<r.length;i++)n.push(JSON.parse(r[i].obj));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{userInfos:n,userCount:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getChatroomHistoryMessages=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("getChatroomHistoryMessage",t,o,r,n,(function(t){var o;try{o=JSON.parse(t)}catch(e){o={list:[],hasMore:!1}}var r=o.list;if(r&&r.length)try{o.list=r.map((function(e){return s._buildMessage(e.obj)}))}catch(e){o.list=[]}setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}),"")}))},t.prototype.setChatroomEntry=function(t,o){var r=this;return new Promise((function(n){var s='[{"key":"'+o.key+'", "value":"'+o.value+'"}]';r._callCppProxy("setChatroomKV",t,s,!!o.isAutoDelete,!!o.isOverwrite,(function(){setTimeout((function(){n(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){n(e)}),0)}))}))},t.prototype.setChatroomEntries=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("setChatroomKV",t,JSON.stringify(o.entries),!!o.isAutoDelete,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.forceSetChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.setChatroomEntry(e,t)},t.prototype.removeChatroomEntry=function(t,o){var r=this,n=[o.key];return new Promise((function(s){r._callCppProxy("deleteChatroomKV",t,n,!!o.isOverwrite,(function(){s(e.ErrorCode.SUCCESS)}),(function(e){s(e)}))}))},t.prototype.forceRemoveChatroomEntry=function(e,t){return t.isOverwrite=!0,t.userId=t.userId||this.tcpMgr.getCurrentUserId(),this.removeChatroomEntry(e,t)},t.prototype.removeChatroomEntries=function(t,o){var r=this;return new Promise((function(n){var s=o.entries.map((function(e){return e.key}));r._callCppProxy("deleteChatroomKV",t,s,!!o.isOverwrite,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}))}))},t.prototype.getChatroomEntry=function(t,o){return _(this,void 0,void 0,(function(){var r;return y(this,(function(n){switch(n.label){case 0:return[4,this.getAllChatroomEntry(t)];case 1:return(r=n.sent()).code===e.ErrorCode.SUCCESS?[2,{code:e.ErrorCode.SUCCESS,data:r.data?r.data[o]:null}]:[2,{code:r.code}]}}))}))},t.prototype.getAllChatroomEntry=function(t){var o=this;return new Promise((function(r){o._callCppProxy("getChatroomKV",t,(function(t){var o={};try{(t?JSON.parse(t):{list:[]}).list.map((function(e){return JSON.parse(e.obj)})).forEach((function(e){o[e.key]=e.value?e.value:""}))}catch(e){}setTimeout((function(){r({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getFileToken=function(t,o,r,n,s){var i=this;return r=r||"",n=n||"",s=s||"",new Promise((function(a){var c;c=n&&"uploads"!==n?o||"":e.getUploadFileName(t,o);var u=i.getNaviInfoFromCache(),p={uploadDomain:e.getMinionURL(u,i.logger),env:i._environment};i._callCppProxy("getUploadToken",t,c,r,n,s,JSON.stringify(p),(function(t,o,r,n,s,i,u,p,d,l,h,f,C,g,v,S,_,y,m,E,T,P,R){setTimeout((function(){a({code:e.ErrorCode.SUCCESS,data:{token:t,deadline:0,bosToken:o,bosDate:r,path:n,osskeyId:s,ossPolicy:i,ossSign:u,ossBucketName:p,fileName:c,s3Credential:d,s3Algorithm:l,s3Date:h,s3Policy:f,s3Signature:C,s3BucketName:g,stcAuthorization:v,stcContentSha256:S,stcDate:_,stcBucketName:y,minioAuthorization:m,minioContentSha256:E,minioDate:T,minioBucketName:P,downloadAuthInfo:R?JSON.parse(R):null}})}),0)}),(function(e){setTimeout((function(){a({code:e})}),0)}))}))},t.prototype.getFileUrl=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s.getNaviInfoFromCache(),c={url:e.getMinionURL(a,s.logger)};s._callCppProxy("getDownloadUrl",t,r,n,o-1,JSON.stringify(c),(function(t){setTimeout((function(){i({code:e.ErrorCode.SUCCESS,data:{downloadUrl:t}})}),0)}),(function(e){setTimeout((function(){i({code:e})}),0)}))}))},t.prototype.clearData=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("clearData");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getDeviceId=function(){var e=this._dbpath;return ce(e)},t.prototype.getVoIPKey=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("getVoIPKey",t,o,"",(function(t){setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:t})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.bindRTCRoomForChatroom=function(t){var o=this;return new Promise((function(r){var n=t.chatRoomId,s=t.rtcRoomId;o._callCppProxy("bindRTCRoomForChatroom",n,s,(function(){setTimeout((function(){r(e.ErrorCode.SUCCESS)}),0)}),(function(e){setTimeout((function(){r(e)}),0)}))}))},t.prototype.getGroupMessageDeliverList=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("getGroupMessageDeliverList",t,r,o,(function(t,o){var r=JSON.parse(t).list.map((function(e){return{time:JSON.parse(e.obj).time,userId:JSON.parse(e.obj).id}}));setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{totalCount:o,list:r}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getPrivateMessageDeliverTime=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getMessageDeliverTime",t);if(s)n({code:e.ErrorCode.SUCCESS,data:s});else{r._callCppProxy("getPrivateMessageDeliverList",o,t,(function(t){var o=0,r=JSON.parse(t).list;if(r.length>0){var s=JSON.parse(r[0].obj).time;o=s}setTimeout((function(){n({code:e.ErrorCode.SUCCESS,data:o})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}}))},t.prototype.rtcSignaling=function(t,o,r,n){var s=this;return new Promise((function(i){s._callCppProxy("rtcSignaling",t,o,r,n,(function(t){var o=Array.prototype.slice.call(t);i({code:e.ErrorCode.SUCCESS,buffer:o})}),(function(e){i({code:e})}),30)}))},t.prototype._setRTCHeartbeatListener=function(){var e=this;this._cppProtocol.setRTCHeartbeatListener((function(t,o){var r=e.rtcHeartbeatResolves[t];if(r){var n=r.find((function(e){return""===e.seqId}));n&&(n.seqId=o)}}),(function(t,o,r,n){var s=e.rtcHeartbeatResolves[t];if(s){var i=s.findIndex((function(e){return e.seqId===r}));-1!==i&&s.splice(i,1)[0].resolve({code:o,data:{version:Number(n)}})}}))},t.prototype.rtcPing=function(e,t,o){var r=this;return new Promise((function(t){var o={resolve:t,seqId:""},n=r.rtcHeartbeatResolves[e];n?n.push(o):r.rtcHeartbeatResolves[e]=[o],r._callCppProxy("sendRTCHeartbeat",[e],30)}))},t.prototype.createTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("addTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.removeTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("deleteTag",t,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.updateTag=function(t){var o=this;return new Promise((function(r){o._callCppProxy("renameTag",t.tagId,t.tagName,(function(){setTimeout((function(){r({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){r({code:e})}),0)}))}))},t.prototype.getTagList=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getTags"),n=t._convertResultList(r,(function(e){return{tagId:e.tagId,tagName:e.tagName,conversationCount:e.conversationCount,createdTime:e.tagTime}}));o({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.addTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)}));r._callCppProxy("addConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagForConversations=function(t,o){var r=this;return new Promise((function(n){o.forEach((function(e){e.conversationType&&(e.type=e.conversationType)})),r._callCppProxy("removeConversationsForTag",t,JSON.stringify(o),(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.removeTagsForConversation=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("removeTagsForConversation",t.conversationType,t.targetId,t.channelId||"",o,(function(){setTimeout((function(){n({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){n({code:e})}),0)}))}))},t.prototype.getConversationListByTag=function(t,o,r,n){var s=this;return new Promise((function(i){var a=s._callCppProxy("getConversationsForTagByPage",t,o,r||20,n||""),c=s._convertResultList(a,(function(e){return S(S({},s._buildConversation(JSON.stringify(e))),{isTopInTag:e.topForTag})}));i({code:e.ErrorCode.SUCCESS,data:c})}))},t.prototype.getUnreadCountByTag=function(t,o){var r=this;return new Promise((function(n){var s=r._callCppProxy("getConversationUnreadCountForTag",t,o);n({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.setConversationStatusInTag=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("setConversationToTopForTag",t,o.conversationType,o.targetId,o.channelId||"",r.isTop||!1,(function(){setTimeout((function(){s({code:e.ErrorCode.SUCCESS})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.getTagsForConversation=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("getTagsForConversation",t.conversationType,t.targetId,t.channelId||""),s=o._convertResultList(n,(function(e){return{tagId:e.tagId,tagName:e.tagName,isTop:e.isTop,createdTime:e.tagTime}}));r({code:e.ErrorCode.SUCCESS,data:s})}))},t.prototype.getBlockConversationList=function(){throw new Error("Method not implemented.")},t.prototype.getTopConversationList=function(t,o){var r=this;return new Promise((function(n){var s=e.isUndefined(o)?r._callCppProxy("getTopConversations",t):r._callCppProxy("getTopConversations",t,o),i=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}));n({code:e.ErrorCode.SUCCESS,data:i})}))},t.prototype.getUnreadMentionedCount=function(e){throw new Error("Method not implemented.")},t.prototype.getAllUnreadMentionedCount=function(){var t=this;return new Promise((function(o){var r=t._callCppProxy("getUnreadAndMentionCount",[e.ConversationType.GROUP],"");o({code:e.ErrorCode.SUCCESS,data:r})}))},t.prototype.getOSInfo=function(){return _(this,void 0,void 0,(function(){var t;return y(this,(function(o){return t={arch:f.arch(),platform:f.platform(),type:f.type(),version:f.version(),release:f.release(),uptime:f.uptime(),cpus:f.cpus(),freemem:f.freemem(),totalmem:f.totalmem(),networkInterfaces:f.networkInterfaces()},[2,{code:e.ErrorCode.SUCCESS,data:t}]}))}))},t.prototype.getMainProcessInfo=function(){return _(this,void 0,void 0,(function(){return y(this,(function(t){return[2,{code:e.ErrorCode.SUCCESS,data:{title:process.title,pid:process.pid,ppid:process.ppid,platform:process.platform,arch:process.arch,uptime:process.uptime(),cpuUsage:process.cpuUsage(),memoryUsage:process.memoryUsage(),resourceUsage:process.resourceUsage()}}]}))}))},t.prototype.setCallInfo=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("callInfoSignaling",t,o,r,(function(t,o){setTimeout((function(){s({code:e.ErrorCode.SUCCESS,data:{key:t,value:o}})}),0)}),(function(e){setTimeout((function(){s({code:e})}),0)}))}))},t.prototype.setProxy=function(t){return this.tcpMgr.getConnectionStatus()!==e.RCConnectionStatus.DISCONNECTED?Promise.resolve({code:e.ErrorCode.RC_CONN_PROXY_UNAVAILABLE}):Promise.resolve(W(t,this.logger))},t.prototype.getProxy=function(){return Promise.resolve(Y())},t.prototype.testProxy=function(t,o){return function(t,o,r){return new Promise((function(n){var s=/^https/.test(o)?G:H;r.info(e.LogTagId.A_TEST_PROXY_O,JSON.stringify({msg:"test proxy",proxy:t,testHost:o}));var i=s(o,t,(function(e){var t=200===e.statusCode?0:e.statusCode;e.setEncoding("utf8");var o="";e.on("data",(function(e){o+=e})),e.once("end",(function(){n({status:t||0,data:o})}))}));i.once("timeout",(function(){return n({status:0})})),i.once("error",(function(e){return n({status:0,data:e.stack})})),i.end()}))}(t,o,this.logger)},t.prototype.checkDuplicateMessage=function(t){var o=this;return new Promise((function(r){var n=o._callCppProxy("checkDuplicateMessage",t);r({code:e.ErrorCode.SUCCESS,data:n})}))},t.prototype.subscribeUser=function(t,o,r){var n=this;return new Promise((function(s){n._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.SUBSCRIBE,t,(function(){s({code:e.ErrorCode.SUCCESS})}),(function(e,t){s({code:e,data:t})}),r)}))},t.prototype.unSubscribeUser=function(t,o){var r=this;return new Promise((function(n){r._callCppProxy("updateSubscribeStatus",o,e.SubscribeOperationType.UNSUBSCRIBE,t,(function(){n({code:e.ErrorCode.SUCCESS})}),(function(e){n({code:e})}),0)}))},t.prototype.getSubscribeUserList=function(t,o,r){var n=this._callCppProxy("getSubscribeUserList",t,o,r),s=this._buildSubscribeEventData(n).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:s})},t.prototype.setDuplicateMessageConfig=function(t){var o=this._callCppProxy("setDuplicateMessageConfig",[e.ConversationType.CHATROOM],ge.cuid,t);return Promise.resolve({code:o})},t.prototype.getSubscribeUserStatus=function(t,o){var r=this._callCppProxy("getSubscribeStatusByUserIds",t,o),n=this._buildSubscribeEventData(r).map((function(t){var o=t.userId,r=t.subscribeType,n=t.subscribeTime,s=t.duration,i=t.details;return{userId:o,subscribeType:r,subscribeTime:n,expiry:s,details:e.completeSubscriptionPlatformStatus(i)}}));return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},t.prototype.getMatchedMessage=function(t,o,r,n){var s,i=this._callCppProxy("getMatchedMessage",t.conversationType,t.targetId,o,r,n,t.channelId||""),a=[];try{s=JSON.parse(i).list;for(var c=0;c<s.length;c++){var u=this._buildMessage(s[c].obj);a.push(u)}}catch(t){return this.logger.error(v.P_PARSE_JSON_MSGS_E,i),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:a})},t.prototype.getConversations=function(t){var o,r=this,n=t.map((function(e){var t=e.conversationType,o=e.targetId,r=e.channelId;return{targetId:o,channelId:void 0===r?"":r,type:t}})),s=this._callCppProxy("getConversations",JSON.stringify(n));try{o=JSON.parse(s).list.map((function(e){return r._buildConversation(e.obj)}))}catch(t){return this.logger.error(v.P_PARSE_JSON_MSGS_E,s),Promise.resolve({code:e.ErrorCode.MAIN_PROCESS_ERROR})}return Promise.resolve({code:e.ErrorCode.SUCCESS,data:o})},t}(),Ee=r.resolve(__dirname,"binding","electron-"+n.platform()+"-"+n.arch()+".node"),Te={addon:null},Pe=(ye=process,{sendError:function(e){ye.send({type:X.ERROR,data:{msg:e}})},sendEvent:function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];ye.send({type:X.EVENT,data:{eventName:e,data:t}})},sendResponse:function(e){ye.send({type:X.RESPONSE,data:e})},sendCallback:function(e){ye.send({type:X.CALLBACK,data:e})}}).sendError;try{Te.addon=require(Ee)}catch(e){console.error("error ->",Ee,"\n",e),Pe(e.toString())}Te.addon||console.error("error -> cannot find module: ",Ee);var Re,Ie=Te.addon,Oe=function(){function e(e,t,o,r,n){this.sendCallback=n,this._cppService=new me(e,Ie,t,r,o)}return e.prototype.call=function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];return _(this,void 0,void 0,(function(){var o,r=this;return y(this,(function(n){switch(n.label){case 0:return"sendMessage"===e&&(t[3]=function(e){var o=t[3];r.sendCallback({reqId:o,data:e})}),[4,(o=this._cppService).callProxy.apply(o,m([e],t,!1))];case 1:return[2,{success:!0,data:n.sent()}]}}))}))},e.prototype.send=function(e){for(var t,o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];(t=this._cppService).sendProxy.apply(t,m([e],o,!1))},e.prototype.destroy=function(){this._cppService.destroy()},e}(),Me=function(){function n(o,r,n,s){var i=this;this._appkey=o,this._dbpath=r,this._logOutputLevel=n,this._runInMainProcess=s,this._catch={crtUserId:"",connectedTime:0,naviInfo:null,connectionStatus:2,deviceId:"",deltaTime:0},this._connectionStatus=e.RCConnectionStatus.DISCONNECTED,this._connectInfo={token:"",reconnectKickEnable:!1,openCallPlus:!1,traceId:""},this._registerMessageTypeList=[],this._isProcessQuit=!1,this._senders={},this._callbackCache={},this._createServiceProxy(),t.ipcMain.on("__RC_CHANNEL_CALL_MAIN_SYNC__",(function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];return _(i,void 0,void 0,(function(){var r,n;return y(this,(function(s){switch(s.label){case 0:return[4,(n=this._cppServiceProcessProxy).call.apply(n,m([t],o,!1))];case 1:return r=s.sent(),e.returnValue=r.data,[2]}}))}))})),t.ipcMain.on("__RC_CHANNEL_CALL_MAIN__",(function(e,t,o){for(var r=[],n=3;n<arguments.length;n++)r[n-3]=arguments[n];return _(i,void 0,void 0,(function(){var n,s,i;return y(this,(function(a){switch(a.label){case 0:return"sendMessage"===o&&(n=r[3],this._callbackCache[n]=e.sender),"connect"===o&&(this._connectInfo={token:r[0],reconnectKickEnable:r[1],openCallPlus:r[2],traceId:r[3]}),"registerMessageType"===o&&this._registerMessageTypeList.push({objectName:r[0],isPersited:r[1],isCounted:r[2],searchProps:r[3]}),[4,(i=this._cppServiceProcessProxy).call.apply(i,m([o],r,!1))];case 1:if(!(s=a.sent()).success)throw new Error(s.data.msg);return this._send2Renderer(e.sender,"__RC_CHANNEL_RESULT_FROM_MAIN__",t,s.data),[2]}}))}))})),t.ipcMain.on("__RC_CHANNEL_SEND_2_MAIN__",(function(e,t){for(var o,r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];(o=i._cppServiceProcessProxy).send.apply(o,m([t],r,!1))})),t.ipcMain.on("__RC_INNER_COMMAND_INIT__",this._registerRenderers.bind(this)),t.app.on("before-quit",(function(){i._isProcessQuit=!0,i.destroy()})),t.app.on("window-all-closed",(function(){i._isProcessQuit=!0,i.destroy()}))}return n.prototype._send2Renderer=function(e,t){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];e.isDestroyed()?delete this._senders[e.id]:e.send.apply(e,m([t],o,!1))},n.prototype._send2AllRenderer=function(e,t,o){var r=this;void 0===o&&(o=[]),Object.keys(this._senders).forEach((function(n){var s=r._senders[n];o.includes(s)||r._send2Renderer(s,"__RC_CHANNEL_NOTIFICATION_FROM_MAIN__",e,t)}))},n.prototype._registerRenderers=function(e,t){var o=this,r=e.sender,n=r.id;this._cppServiceProcessProxy.send("registerRenderers",t),this._senders[n]||(this._senders[n]=r,r.once("destroyed",(function(){delete o._senders[n]})))},n.prototype.getMainCache=function(){return this._catch},n.prototype._restartSubProcessProxy=function(){var t=this;if(this._createServiceProxy(),this._connectionStatus!==e.RCConnectionStatus.DISCONNECTED){this._send2AllRenderer("onSuspend",e.ErrorCode.SUB_PROCESS_EXIT),this._registerMessageTypeList.forEach((function(e){t._cppServiceProcessProxy.send("registerMessageType",e.objectName,e.isPersited,e.isCounted,e.searchProps)}));var o=this._connectInfo,r=o.token,n=o.reconnectKickEnable,s=o.openCallPlus,i=o.traceId;this._cppServiceProcessProxy.send("connect",r,n,s,i)}},n.prototype._eventNotifyHandler=function(t){for(var o=[],r=1;r<arguments.length;r++)o[r-1]=arguments[r];var n=o[0],s=o[1];switch(t){case"onConnected":this._catch=n,this._connectionStatus=e.RCConnectionStatus.CONNECTED;break;case"onSuspend":this._connectionStatus=e.RCConnectionStatus.SUSPENDED;break;case"onDisconnected":this._connectionStatus=e.RCConnectionStatus.DISCONNECTED;break;case"onConnecting":this._connectionStatus=e.RCConnectionStatus.CONNECTING}this._send2AllRenderer(t,n,s)},n.prototype._callbackHandler=function(e){var t=e.reqId,o=e.data;this._callbackCache[t]&&this._send2Renderer(this._callbackCache[t],"__RC_CHANNEL_RESULT_FROM_MAIN__",t,o)},n.prototype._createServiceProxy=function(){var e=this,n=this._dbpath||r.resolve(t.app.getPath("userData"));if(this._runInMainProcess)this._cppServiceProcessProxy=new Oe(this._appkey,n,this._logOutputLevel,this._eventNotifyHandler.bind(this),this._callbackHandler.bind(this));else{var s=o.fork(r.resolve(__dirname,"cppServiceProcess.js"),[this._appkey,n,this._logOutputLevel.toString()]);this._cppServiceProcessProxy=new pe(s,this._eventNotifyHandler.bind(this),this._callbackHandler.bind(this),(function(t,o){void 0===o&&(o=!1);var r="sub process exit, msg: "+t+", isRestart: "+o+", _isProcessQuit: "+e._isProcessQuit;if(console.error(r),o&&!e._isProcessQuit)return e._restartSubProcessProxy()}))}},n.prototype.destroy=function(){this._cppServiceProcessProxy.destroy()},n}(),Ne=function(){function e(e,t,o,r){this._rcMain=new Me(e,t,o,r)}return e.prototype.getCppProto=function(){var e=this;return{destroy:function(){console.warn("`.getCppProto().destroy()` has being deprecated, use `.destroy()` instead."),e.destroy()}}},e.prototype.destroy=function(){this._rcMain.destroy()},e.prototype.getDeviceId=function(){return this._rcMain.getMainCache().deviceId},e.prototype.getServerTime=function(){return this._rcMain.getMainCache().connectedTime},e}();module.exports=function(t){return function(t,o){if(Re)return Re;if(!t)throw new Error("Initializ failed, `appkey` is required!");return Re=new Ne(t,(null==o?void 0:o.dbpath)||"",(null==o?void 0:o.logOutputLevel)||e.LogL.WARN,(null==o?void 0:o.runInMainProcess)||!1)}(t.appkey,t)};
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"types": "index.d.ts",
|
|
16
16
|
"module": "index.esm.js",
|
|
17
|
-
"version": "5.9.
|
|
17
|
+
"version": "5.9.9",
|
|
18
18
|
"author": "pass-web@rongcloud.cn",
|
|
19
19
|
"license": "LGPL 2.1",
|
|
20
20
|
"homepage": "https://www.rongcloud.cn",
|
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
"globals": "RCMain"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@rongcloud/engine": "=5.9.
|
|
28
|
+
"@rongcloud/engine": "=5.9.9"
|
|
29
29
|
}
|
|
30
30
|
}
|