zoujiandong 360c1bb977 视频
2024-01-12 09:38:24 +08:00

1 line
31 KiB
JavaScript

"use strict";var t=function(t){return s=t={exports:{}},a=Object.prototype.hasOwnProperty,_="~",Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(_=!1)),e.prototype.eventNames=function(){var t,e,i=[];if(0===this._eventsCount)return i;for(e in t=this._events)a.call(t,e)&&i.push(_?e.slice(1):e);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(t)):i},e.prototype.listeners=function(t){var t=_?_+t:t,e=this._events[t];if(!e)return[];if(e.fn)return[e.fn];for(var i=0,n=e.length,s=new Array(n);i<n;i++)s[i]=e[i].fn;return s},e.prototype.listenerCount=function(t){t=_?_+t:t,t=this._events[t];return t?t.fn?1:t.length:0},e.prototype.emit=function(t,e,i,n,l,c){var h=_?_+t:t;if(!this._events[h])return!1;var s,o=this._events[h],a=arguments.length;if(o.fn){switch(o.once&&this.removeListener(t,o.fn,void 0,!0),a){case 1:return o.fn.call(o.context),!0;case 2:return o.fn.call(o.context,e),!0;case 3:return o.fn.call(o.context,e,i),!0;case 4:return o.fn.call(o.context,e,i,n),!0;case 5:return o.fn.call(o.context,e,i,n,l),!0;case 6:return o.fn.call(o.context,e,i,n,l,c),!0}for(g=1,s=new Array(a-1);g<a;g++)s[g-1]=arguments[g];o.fn.apply(o.context,s)}else for(var r,u=o.length,g=0;g<u;g++)switch(o[g].once&&this.removeListener(t,o[g].fn,void 0,!0),a){case 1:o[g].fn.call(o[g].context);break;case 2:o[g].fn.call(o[g].context,e);break;case 3:o[g].fn.call(o[g].context,e,i);break;case 4:o[g].fn.call(o[g].context,e,i,n);break;default:if(!s)for(r=1,s=new Array(a-1);r<a;r++)s[r-1]=arguments[r];o[g].fn.apply(o[g].context,s)}return!0},e.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},e.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},e.prototype.removeListener=function(t,e,i,n){t=_?_+t:t;if(!this._events[t])return this;if(!e)return g(this,t),this;var s=this._events[t];if(s.fn)s.fn!==e||n&&!s.once||i&&s.context!==i||g(this,t);else{for(var o=0,a=[],r=s.length;o<r;o++)(s[o].fn!==e||n&&!s[o].once||i&&s[o].context!==i)&&a.push(s[o]);a.length?this._events[t]=1===a.length?a[0]:a:g(this,t)}return this},e.prototype.removeAllListeners=function(t){return t?(t=_?_+t:t,this._events[t]&&g(this,t)):(this._events=new i,this._eventsCount=0),this},e.prototype.off=e.prototype.removeListener,e.prototype.addListener=e.prototype.on,e.prefixed=_,s.exports=e.EventEmitter=e,t.exports;function i(){}function o(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,i,n,s){if("function"!=typeof i)throw new TypeError("The listener must be a function");i=new o(i,n||t,s),n=_?_+e:e;return t._events[n]?t._events[n].fn?t._events[n]=[t._events[n],i]:t._events[n].push(i):(t._events[n]=i,t._eventsCount++),t}function g(t,e){0==--t._eventsCount?t._events=new i:delete t._events[e]}function e(){this._events=new i,this._eventsCount=0}var s,a,_}();const e=2,n=11,i=12,s=20,o=23,r=27;class a{constructor(t=0,e=0){this.high=t,this.low=e}equal(t){return null!==t&&this.low===t.low&&this.high===t.high}toString(){var t=Number(this.high).toString(16);let e=Number(this.low).toString(16);if(e.length<8){let t=8-e.length;for(;t;)e="0"+e,t--}return t+e}}const c={TEST:{CHINA:{DEFAULT:"wss://wss-dev.tim.qq.com"},OVERSEA:{DEFAULT:"wss://wss-dev.tim.qq.com"},SINGAPORE:{DEFAULT:"wss://wsssgp-dev.im.qcloud.com"},KOREA:{DEFAULT:"wss://wsskr-dev.im.qcloud.com"},GERMANY:{DEFAULT:"wss://wssger-dev.im.qcloud.com"},IND:{DEFAULT:"wss://wssind-dev.im.qcloud.com"},JPN:{DEFAULT:"wss://wssjpn-dev.im.qcloud.com"},USA:{DEFAULT:"wss://wssusa-dev.im.qcloud.com"},INDONESIA:{DEFAULT:"wss://wssidn-dev.im.qcloud.com"}},PRODUCTION:{CHINA:{DEFAULT:"wss://wss.im.qcloud.com",BACKUP:"wss://wss.tim.qq.com",STAT:"https://events.im.qcloud.com",ANYCAST:"wss://162.14.13.203"},OVERSEA:{DEFAULT:"wss://wss.im.qcloud.com",BACKUP:"wss://wss.my-imcloud.com",STAT:"https://api.my-imcloud.com"},SINGAPORE:{DEFAULT:"wss://wsssgp.im.qcloud.com",BACKUP:"wss://wsssgp.my-imcloud.com",STAT:"https://apisgp.my-imcloud.com",ANYCAST:"wss://162.14.19.159"},KOREA:{DEFAULT:"wss://wsskr.im.qcloud.com",BACKUP:"wss://wsskr.my-imcloud.com",STAT:"https://apikr.my-imcloud.com",ANYCAST:"wss://162.14.13.104"},GERMANY:{DEFAULT:"wss://wssger.im.qcloud.com",BACKUP:"wss://wssger.my-imcloud.com",STAT:"https://apiger.my-imcloud.com",ANYCAST:"wss://162.14.3.17"},IND:{DEFAULT:"wss://wssind.my-imcloud.com",BACKUP:"wss://wssind.im.qcloud.com",STAT:"https://apiind.my-imcloud.com",ANYCAST:"wss://162.14.18.188"},JPN:{DEFAULT:"wss://wssjpn.im.qcloud.com",BACKUP:"wss://wssjpn.my-imcloud.com",STAT:"https://apijpn.my-imcloud.com"},USA:{DEFAULT:"wss://wssusa.im.qcloud.com",BACKUP:"wss://wssusa.my-imcloud.com",STAT:"https://apiusa.my-imcloud.com",ANYCAST:"wss://162.14.10.42"},INDONESIA:{DEFAULT:"wss://wssidn.im.qcloud.com",BACKUP:"wss://wssidn.my-imcloud.com",STAT:"https://apiidn.my-imcloud.com",ANYCAST:"wss://43.129.34.169"}}},g={ANDROID:2,IOS:3,MAC:4,WEB:7,WX_MP:8,QQ_MP:9,TT_MP:10,BAIDU_MP:11,ALI_MP:12,IPAD:13,UNI_NATIVE_APP:15},l="CHINA",h={HOST:{CURRENT:{DEFAULT:"wss://wss.im.qcloud.com",STAT:"https://events.im.qcloud.com"},setCurrent(t=l){this.CURRENT=c.PRODUCTION[t]}},NAME:{OPEN_IM:"openim",OPEN_IM_MSG_EXT:"openim_msg_ext_http_svc",GRP:"group_open_http_svc",GRP_AV:"group_open_avchatroom_http_svc",GRP_COMMUNITY:"million_group_open_http_svc",GRP_ATTR:"group_open_attr_http_svc",FD:"sns",PROFILE:"profile",RECENT_CONTACT:"recentcontact",PIC:"openpic",BIG_GRP_NO_AUTH:"group_open_http_noauth_svc",BIG_GRP_POLLING:"group_open_long_polling_http_svc",BIG_GRP_POLLING_NO_AUTH:"group_open_long_polling_http_noauth_svc",IM_OPEN_STAT:"imopenstat",WEB_IM:"webim",IM_COS_SIGN:"im_cos_sign_svr",CUSTOM_UPLOAD:"im_cos_msg",HEARTBEAT:"heartbeat",IM_OPEN_PUSH:"im_open_push",IM_OPEN_STATUS:"im_open_status",IM_LONG_MSG:"im_long_msg",IM_CONFIG_MANAGER:"im_sdk_config_mgr",STAT_SERVICE:"StatSvc",OVERLOAD_PUSH:"OverLoadPush",IM_MSG_AUDIT_MGR:"im_msg_audit_mgr",TUIROOM_SVR:"tui_room_svr",IM_OPEN_TRANSLATE:"im_open_translate",IM_OPEN_SPEECH:"im_open_speech",MSG_SEARCH:"message_search",FOLLOW:"follow"}},u=(new a(0,Math.pow(2,0)).toString(),new a(0,Math.pow(2,1)).toString(),new a(0,Math.pow(2,2)).toString(),new a(0,Math.pow(2,3)).toString(),new a(0,Math.pow(2,4)).toString(),new a(0,Math.pow(2,6)).toString(),new a(0,Math.pow(2,7)).toString(),new a(0,Math.pow(2,9)).toString(),new a(0,Math.pow(2,10)).toString(),new a(0,Math.pow(2,11)).toString(),new a(0,Math.pow(2,13)).toString(),new a(0,Math.pow(2,15)).toString(),new a(Math.pow(2,6)).toString(),new a(Math.pow(2,7)).toString(),new a(Math.pow(2,8)).toString(),new a(Math.pow(2,9)).toString(),new a(Math.pow(2,10)).toString(),new a(Math.pow(2,16)).toString(),h.HOST.setCurrent(l),"undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting)),_=(u&&wx.createGamePortal,"undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting)),d="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),m="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),I="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),f="undefined"!=typeof jd&&"function"==typeof jd.getSystemInfoSync,v="undefined"!=typeof uni&&"undefined"==typeof window&&"function"==typeof uni.requireNativePlugin,p=u||_||d||m||I||v||f,D=("undefined"!=typeof uni||"undefined"!=typeof window)&&!p,S=(_?qq:d?tt:m?swan:I?my:u?wx:v?uni:f&&jd,D&&window&&window.navigator&&window.navigator.userAgent||""),y=/(micromessenger|webbrowser)/i.test(S),M=/AppleWebKit\/([\d.]+)/i.exec(S),w=(M&&parseFloat(M.pop()),function(){let t="WEB";return y?t="WEB":_?t="QQ_MP":d?t="TT_MP":m?t="BAIDU_MP":I?t="ALI_MP":u?t="WX_MP":v&&(t="UNI_NATIVE_APP"),g[t]}()),C=(!function(){var t=S.match(/OS (\d+)_/i);t&&t[1]&&t[1]}(),function(){var t,e,i=S.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);i&&(t=i[1]&&parseFloat(i[1]),e=i[2]&&parseFloat(i[2]),t&&e&&parseFloat(i[1]+"."+i[2]))}(),function(){var t=S.match(/Chrome\/(\d+)/);t&&t[1]&&parseFloat(t[1])}(),/MSIE/.test(S)||-1<S.indexOf("Trident")&&-1<S.indexOf("rv:11.0"));let T,E;!function(){var t=/MSIE\s(\d+)\.\d/.exec(S),t=t&&parseFloat(t[1]);!t&&/Trident\/7.0/i.test(S)&&/rv:11.0/.test(S)}(),function(){var t=S.match(/TBS\/(\d+)/i);t&&t[1]&&t[1]}(),T="undefined"!=typeof console?console:"undefined"!=typeof global&&global.console?global.console:"undefined"!=typeof window&&window.console?window.console:{};const L=function(){},A=["assert","clear","count","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"];let N=A.length;for(;N--;)E=A[N],console[E]||(T[E]=L);var O=T;const $="TIMCustomElem",P="High",U="C2C",H="GROUP",R="@TIM#SYSTEM",x=function(){const t=new Date;return t.setTime((new Date).getTime()+0),t},b=Object.prototype.hasOwnProperty;function F(t){if(null==t)return!0;if("boolean"==typeof t)return!1;if("number"==typeof t)return 0===t;if("string"==typeof t)return 0===t.length;if("function"==typeof t)return 0===t.length;if(Array.isArray(t))return 0===t.length;if(t instanceof Error)return""===t.message;if(B(t)){for(const e in t)if(b.call(t,e))return!1;return!0}return!!(q(t)||j(t)||G(t))&&0===t.size}const q=function(t){return"map"===K(t)},j=function(t){return"set"===K(t)},G=function(t){return"file"===K(t)},B=function(t){if("object"!=typeof t||null===t)return!1;t=Object.getPrototypeOf(t);if(null===t)return!0;let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return t===e},k=function(t){return void 0===t},J=function(t){return e=t,("function"==typeof Array.isArray?Array.isArray(e):"array"===K(e))||null!==t&&"object"==typeof t;var e},K=function(t){return Object.prototype.toString.call(t).match(/^\[object (.*)\]$/)[1].toLowerCase()};function Y(){return!C&&!p}Date.now||(Date.now=function(){return(new Date).getTime()});let V=0;function W(){return Y()?"%c Chat %c":"Chat"}function z(){const t=x();return t.toLocaleTimeString("en-US",{hour12:!1})+"."+function(t){let e;switch(t.toString().length){case 1:e="00"+t;break;case 2:e="0"+t;break;default:e=t}return e}(t.getMilliseconds())}const X={arguments2String(i){let n="";if(1===i.length)n=i[0];else for(let t=0,e=i.length;t<e;t++)J(i[t])?i[t]instanceof Error?n+=(s=i[t],JSON.stringify(s,["message","code"])):n+=JSON.stringify(i[t]):n+=i[t],n+=" ";var s;return n},_exec(t,e){Y()?O[t](W(),"background:#0abf5b; padding:1px; border-radius:3px; color: #fff","background:transparent",z(),e):O[t](`${W()} ${z()} `+e)},d:function(){var t;V<=-1&&(t=this.arguments2String(arguments),this._exec("debug",t))},l:function(){var t;V<=0&&(t=this.arguments2String(arguments),this._exec("log",t))},log:function(){var t;V<=0&&(t=this.arguments2String(arguments),this._exec("log",t))},i:function(){var t;V<=1&&(t=this.arguments2String(arguments),this._exec("info",t))},w:function(){var t;V<=2&&(t=this.arguments2String(arguments),this._exec("warn",t))},e:function(){var t;V<=3&&(t=this.arguments2String(arguments),this._exec("error",t))},setLevel:function(t){t<4&&this._exec("log","set level from "+V+" to "+t),V=t},getLevel:function(){return V}};class Q extends Error{constructor(t){super();var{code:t,message:e,data:i}=t;this.code=t,this.message=e||this._getErrorMessage(this.code),this.data=i||{}}}const Z=2903,et=3122,nt=8010,it=8011,st=8020,ot="error";let rt=null;const at=function(t,e=!1){if(t instanceof Q)return e&&null!==rt&&rt.emit(ot,t),Promise.reject(t);if(t instanceof Error){const t=new Q({code:Z});return e&&null!==rt&&rt.emit(ot,t),Promise.reject(t)}if(k(t)||k(t.code))return Promise.reject(new Q({code:Z}));t=new Q(t);return e&&null!==rt&&rt.emit(ot,t),Promise.reject(t)},ct="newInvitationReceived",gt="ts_invitee_accepted",lt="ts_invitee_rejected",ht="ts_invitation_cancelled",ut="ts_invitation_timeout",_t="ts_invitation_modified",dt=1,mt=2,It=3,ft=4,vt=5;class pt{constructor(t){this._n="RemoteSignalingHandler",this._sigM=t}onNewMessageList(t){const e=this._sigM.filterMessageList(t);0<e.length&&e.forEach(t=>{var e=this.getPayloadData(t);e&&this._handleActionType(e,t)})}onMessageModified(t){const e=this._sigM.filterMessageList(t);0<e.length&&e.forEach(t=>{var e=this.getPayloadData(t);e&&this._onInvitationModified(e,t)})}getPayloadData(e){var i=this._n+".getPayloadData",e=e.payload["data"];try{return JSON.parse(e)}catch(t){return X.e(i+" JSON parse error. signalingData:"+e),null}}_handleActionType(t,e){var i=t["actionType"];switch(i){case dt:this._onNewInvitationReceived(t,e);break;case ft:this._onInviteeRejected(t);break;case It:this._onInviteeAccepted(t);break;case mt:this._onInvitationCancelled(t);break;case vt:this._onInvitationTimeout(t)}}_createDefaultEmitData(t){var{inviteID:t,inviter:e,groupID:i,data:n}=t;return{inviteID:t,inviter:e,groupID:i,data:n||""}}_onNewInvitationReceived(t,e){const i=this._n+"._onNewInvitationReceived",{inviteID:n,inviteeList:s,groupID:o,inviter:c}=t,a=this._sigM.getMyUserID(),r=s.includes(a);let g=t.timeout;var l=(x().getTime()-1e3*e.time)/1e3,h=(0<g&&0<l&&g>l&&(g-=l),i+` myselfIncluded:${r} groupID:${o} signalObj:`+JSON.stringify(t));if(X.l(h+` timeout:${g}s delta:${l}s`),o&&r||!o){const i=this._sigM.getInviteInfo(n);i&&i===t||(i||this._sigM.setInviteInfo(n,{...t,message:e}),this._sigM.emitEvent(ct,{...this._createDefaultEmitData(t),inviteeList:s}),c!==a&&this._sigM.startTimer({...t,timeout:g}))}}_onInviteeRejected(t){var e=this._n+"._onInviteeRejected",{inviteID:i,inviter:n,groupID:s}=t,o=this._sigM.hasInviteInfo(i);X.l(e+` inviteID:${i} hasInviteID:${o} inviter:${n} groupID:`+s),(s&&o||!s)&&(this._sigM.updateInviteInfo(t),this._sigM.emitEvent(lt,{...this._createDefaultEmitData(t),invitee:t.inviteeList[0]}))}_onInviteeAccepted(t){var e=this._n+"._onInviteeAccepted",{inviteID:i,inviter:n,groupID:s}=t,o=this._sigM.hasInviteInfo(i);X.l(e+` inviteID:${i} hasInviteID:${o} inviter:${n} groupID:`+s),(s&&o||!s)&&(this._sigM.updateInviteInfo(t),this._sigM.emitEvent(gt,{...this._createDefaultEmitData(t),invitee:t.inviteeList[0]}))}_onInvitationCancelled(t){var e=this._n+"._onInvitationCancelled",{inviteID:i,inviter:n,groupID:s}=t,o=this._sigM.hasInviteInfo(i);X.l(e+` inviteID:${i} hasInviteID:${o} inviter:${n} groupID:`+s),(s&&o||!s)&&(this._sigM.deleteInviteInfo(i),this._sigM.emitEvent(ht,this._createDefaultEmitData(t)))}_onInvitationTimeout(t){var e=this._n+"._onInvitationTimeout",{inviteID:i,inviter:n,groupID:s,inviteeList:o}=t,a=this._sigM.hasInviteInfo(i);X.l(e+` inviteID:${i} hasInviteID:${a} inviter:${n} groupID:${s} data:`+t.data),(s&&a||!s)&&(this._sigM.updateInviteInfo(t),this._sigM.emitEvent(ut,{...this._createDefaultEmitData(t),inviteeList:o,isSelfTimeout:!1}))}_onInvitationModified(t,e){var i=this._n+"._onInvitationModified",{inviteID:n,data:s}=t;X.l(i+` inviteID:${n} data:`+s),this._sigM.setInviteInfo(n,{...t,message:e}),this._sigM.emitEvent(_t,{inviteID:n,data:s})}}const Dt=function(t){if(t<0||53<t)return NaN;var e=0|1073741824*Math.random();return 30<t?e+1073741824*(0|Math.random()*(1<<t-30)):e>>>30-t},St=function(t,e){let i=t.toString(16),n=e-i.length,s="0";for(;0<n;n>>>=1,s+=s)1&n&&(i=s+i);return i};class yt{constructor(t){this._n="LocalSignalingHandler",this._sigM=t}generateInviteID(){var t=function(){const t=Dt,e=St;return e(t(32),8)+"-"+e(t(16),4)+"-"+e(16384|t(12),4)+"-"+e(32768|t(14),4)+"-"+e(t(48),12)}();return X.l(this._n+".generateInviteID inviteID:"+t),t}createInviteInfo(t){var e=this.generateInviteID(),t=this.createInviteCustomData({...t,inviteID:e}),{groupID:i,inviteeList:n}=t,i=i||n[0];return{customData:t,message:this.createSignalingMessage(t,i),inviteID:e}}_createDefaultCustomData(t){var{data:t="",inviteID:e="",groupID:i=""}=t;return{businessID:1,timeout:0,data:t,inviteID:e,groupID:i}}createInviteCustomData(t){var{userID:e,timeout:i=0,groupID:n=""}=t,s=this._sigM.getMyUserID(),s={...this._createDefaultCustomData(t),actionType:dt,inviter:s,inviteeList:n?t.inviteeList:[e],timeout:i};return X.l(this._n+".createInviteCustomData customData:"+JSON.stringify(s)),s}createCancelCustomData(t){var e=this._n+".createCancelCustomData",i=t["inviteID"];let n;var s=this._sigM.getMyUserID(),{inviteeList:i,groupID:o,inviter:a}=this._sigM.getInviteInfo(i);return a===s?n={...this._createDefaultCustomData(t),actionType:mt,groupID:o,inviter:s,inviteeList:i}:X.e(e+` unmatched inviter:${a} and my userID:`+s),X.l(e+" customData:"+JSON.stringify(n)),n}createAcceptCustomData(t){var e=this._n+".createAcceptCustomData",i=t["inviteID"];let n;const s=this._sigM.getMyUserID(),{inviter:o,groupID:a,inviteeList:r}=this._sigM.getInviteInfo(i);return r.includes(s)?n={...this._createDefaultCustomData(t),actionType:It,groupID:a,inviter:o,inviteeList:[s]}:X.e(e+` userID:${s} not in inviteeList. inviteID:${i} groupID:`+a),X.l(e+" customData:"+JSON.stringify(n)),n}createRejectCustomData(t){var e=this._n+".createRejectCustomData",i=t["inviteID"];let n;const s=this._sigM.getMyUserID(),{inviter:o,groupID:a,inviteeList:r}=this._sigM.getInviteInfo(i);return r.includes(s)?n={...this._createDefaultCustomData(t),actionType:ft,groupID:a,inviter:o,inviteeList:[s]}:X.e(e+` userID:${s} not in inviteeList. inviteID:${i} groupID:`+a),X.l(e+" customData:"+JSON.stringify(n)),n}createTimeoutCustomData(t){var e=this._n+".createTimeoutCustomData",{inviteeList:i,inviter:n,isInviter:s=!1}=t,o=this._sigM.getMyUserID(),t={...this._createDefaultCustomData(t),actionType:vt,inviter:n,inviteeList:s?i:[o]};return X.l(e+" customData:"+JSON.stringify(t)),t}createSignalingMessage(t,i){const{groupID:n,inviter:s}=t,o=this._sigM.get(e),a={to:i||n||s,conversationType:n?H:U,priority:P,payload:{data:JSON.stringify(t)}},r=o.createCustomMessage(a);return X.d(this._n+".createSignalingMessage. message:"+JSON.stringify(r)),r}}class Mt{constructor(t){this._n="HistorySignalingHandler",this._sigM=t,this.EXPIRED_TIME=3e4,this.COUNT=20,this._signalingMap=new Map,this._signalingRelatedToMeMap=new Map}getHistorySignaling(){var t=this._sigM.get(n).getLocalConversationList();F(t)||this._getSignalingList(t).then(t=>{this._handleSignalingList(t)})}_getSignalingList(t){t=this._getValidConversationList(t),t=this._createPromiseList(t);return F(t)?Promise.resolve([]):this._concurrentGetMessageList(t).then(t=>{let e=new Map;return t.forEach(t=>{t=t.signalingList,t=this._getSignalingRelatedToMeMap(t);e=new Map([...e,...t])}),this._sortSignaling(e)})}_handleSignalingList(t){F(t)||(X.d(this._n+"._handleSignalingList signalingList:"+JSON.stringify(t)),this._sigM.onNewMessageList(t))}_isSignalingNotExpired(t,e){return t[e]&&1e3*t[e]>(new Date).getTime()-this.EXPIRED_TIME}_getValidConversationList(e){const i=[];for(let t=0;t<e.length;t++){var{type:n,unreadCount:s,lastMessage:o}=e[t],o=this._isSignalingNotExpired(o,"lastTime");n!==R&&0<s&&o&&i.push(e[t])}return i}_createPromiseList(e){const i=[];for(let t=0;t<e.length;t++){var{conversationID:s,unreadCount:o,type:a}=e[t],a=a===U?o:this.COUNT,o=(this._signalingMap.set(s,{needMessageCount:a,signalingList:[]}),this._sigM.get(n).getMessageList({conversationID:s}));i.push(o)}return i}_concurrentGetMessageList(t){const s=[];return Promise.all(t).then(e=>{for(let t=0;t<e.length;t++){var{code:i,data:n}=e[t];0===i&&0!==n.messageList.length&&(this._handleMessageList(n.messageList),(i=this._relayGetMessageList(n))&&s.push(i))}return 0<s.length?this._concurrentGetMessageList(s):this._signalingMap})}_relayGetMessageList(t){var{messageList:t,nextReqMessageID:e,isCompleted:i}=t,s=t.length;if(0===s)return null;var{conversationID:o,conversationType:a}=t[0],r=this._signalingMap.get(o)["needMessageCount"],a=a===H,i=0===r||i,t=this._isSignalingNotExpired(t[s-1],"time");return a||i||!t?null:this._sigM.get(n).getMessageList({conversationID:o,nextReqMessageID:e,count:r})}_handleMessageList(e){const i=e.length,t=e[0]["conversationID"],{needMessageCount:n,signalingList:s}=this._signalingMap.get(t),o=0<n-i?n-i:0,a=[];for(let t=0;t<e.length;t++){const i=e[t];this._isSignalingNotExpired(i,"time")&&a.push(i)}var r=this._sigM.filterMessageList(a);this._signalingMap.set(t,{needMessageCount:o,signalingList:s.concat(r)})}_getSignalingRelatedToMeMap(e){for(let t=0;t<e.length;t++){var i=e[t];this._saveSignalingRelatedToMe(i)}return this._signalingRelatedToMeMap}_saveSignalingRelatedToMe(t){const e=this._sigM.getRemoteSignalingHandler().getPayloadData(t)||{},{actionType:i="",inviteID:n="",inviteeList:s=[]}=e,o=this._sigM.getMyUserID();switch(i){case dt:s.includes(o)&&this._signalingRelatedToMeMap.set(n,{...e,messageList:[t]});break;case ft:case It:this.updateHistoryInviteInfo(t);break;case mt:this.deleteHistoryInviteInfo(n);break;case vt:this.updateHistoryInviteInfo(t)}}deleteHistoryInviteInfo(t){this._signalingRelatedToMeMap.has(t)&&this._signalingRelatedToMeMap.delete(t)}updateHistoryInviteInfo(t){const e=this._sigM.getRemoteSignalingHandler().getPayloadData(t)||{},{inviteID:i="",inviteeList:n=[]}=e;if(this._signalingRelatedToMeMap.has(i)){const{inviteeList:e,messageList:s}=this._signalingRelatedToMeMap.get(i);for(let t=0;t<n.length;t++){const i=n[t];e.includes(i)&&e.splice(e.indexOf(i),1)}0===e.length?this.deleteHistoryInviteInfo(i):s.push(t)}else this.deleteHistoryInviteInfo(i)}_sortSignaling(t){let e=[];return t.forEach(t=>{e=[...e,...t.messageList]}),e.sort(function(t,e){return(t.time||0)-(e.time||0)})}reset(){this._signalingMap.clear(),this._signalingRelatedToMeMap.clear()}}class wt{constructor(t,e){this.businessID=t.businessID||1,this.inviteID=t.inviteID,this.groupID=t.groupID||"",this.inviter=t.inviter||"",this.inviteeList=t.inviteeList||[],this.data=t.data||"",this.actionType=t.actionType||dt,this.timeout=t.timeout||0}}const Ct={A2KEY_AND_TINYID_UPDATED:"_inner1",CLOUD_CONFIG_UPDATED:"_inner2",PROFILE_UPDATED:"_inner3",CONV_SYNC_COMPLETED:"_inner4",C2C_UNREAD_HANDLE_COMPLETED:"_inner5"};class Tt extends class{constructor(t){this._m=t,this._n=""}isLoggedIn(){return this._m.get(i).isLoggedIn()}isOversea(){return this._m.get(i).isOversea()}isPrivateNetWork(){return this._m.get(i).isPrivateNetWork()}getFileDownloadProxy(){return this._m.get(i).getFileDownloadProxy()}getMyUserID(){return this._m.get(i).getUserID()}getMyTinyID(){return this._m.get(i).getTinyID()}getSDKAppID(){return this._m.get(i).getSDKAppID()}isIntl(){return this._m.get(i).isIntl()}isUsingChatCore(){return this._m.get(i).isUsingChatCore()}isDevMode(){return this._m.get(i).isDevMode()}get(t){return this._m.get(t)}getPlatform(){return w}getCloudConfig(t){return this._m.get(o).getCloudConfig(t)}emitOuterEvent(t,e){this._m.getOuterEmitterInstance().emit(t,e)}emitInnerEvent(t,e){this._m.getInnerEmitterInstance().emit(t,e)}getInnerEmitterInstance(){return this._m.getInnerEmitterInstance()}generateTjgID(t){return this._m.get(i).getTinyID()+"-"+t.random}req(t){return this._m.get(s).req(t)}canIUse(t){return this._m.get(r).canIUse(t)}getErrorMessage(t,e,i){return this._m.getErrorMessage(t,e,i)}outputWarning(t,e,i){t=this.getErrorMessage(t,e,i);t&&X.w(t)}cannotUseCommercialAbility(t){var e=et;return at({code:e,message:this.getErrorMessage(e,t)})}}{constructor(e){super(e),this._n="SignalingModule",this._inviteInfoMap=new Map,this._outerEmitter=new t,this._outerEmitter._emit=this._outerEmitter.emit,this._outerEmitter.emit=function(...t){t=[t[0],{name:t[0],data:t[1]}];this._outerEmitter._emit.apply(this._outerEmitter,[...t])}.bind(this),this._canIUseSignaling=!1,this._isHandling=!1,this._remoteSignalingHandler=new pt(this),this._localSignalingHandler=new yt(this),this._historySignalingHandler=new Mt(this),this._isC2CUnreadHandleCompleted=!1,this._isConvSyncCompleted=!1,this._isSyncCompleted=!1,this.getInnerEmitterInstance().on(Ct.C2C_UNREAD_HANDLE_COMPLETED,this.onC2CUnreadHandleCompleted,this),this.getInnerEmitterInstance().on(Ct.CONV_SYNC_COMPLETED,this.onConvSyncCompleted,this)}onC2CUnreadHandleCompleted(){this._isC2CUnreadHandleCompleted=!0,this._isC2CUnreadHandleCompleted&&this._isConvSyncCompleted&&!this._isSyncCompleted&&this.onReady()}onConvSyncCompleted(){this._isConvSyncCompleted=!0,this._isC2CUnreadHandleCompleted&&this._isConvSyncCompleted&&!this._isSyncCompleted&&this.onReady()}onReady(){X.l(this._n+".onReady"),this._isSyncCompleted=!0,this._historySignalingHandler.getHistorySignaling()}onNewMessageList(t){return this._remoteSignalingHandler.onNewMessageList(t)}onMessageModified(t){return this._remoteSignalingHandler.onMessageModified(t)}hasInviteInfo(t){return this._inviteInfoMap.has(t)}getInviteInfo(t){return this._inviteInfoMap.get(t)}setInviteInfo(t,e){const{message:i,...n}=e;X.l(this._n+`.setInviteInfo inviteID:${t} data:`+JSON.stringify(n)),this._inviteInfoMap.set(t,{...n,message:i})}deleteInviteInfo(t){this.hasInviteInfo(t)&&(X.l(this._n+`.deleteInviteInfo inviteID:${t}.`),this._inviteInfoMap.delete(t))}updateInviteInfo(t){const e=this._n+".updateInviteInfo",{inviteID:i,inviter:n,inviteeList:s,groupID:o}=t;if(X.l(e+` inviteID:${i} inviter:${n} groupID:`+o),o&&this.hasInviteInfo(i)){const t=s[0],n=this.getInviteInfo(i)["inviteeList"];n.includes(t)&&(n.splice(n.indexOf(t),1),X.l(e+` remove ${t}. localInviteeList.length:`+n.length)),0===n.length&&this.deleteInviteInfo(i)}else this.deleteInviteInfo(i)}getLocalSignalingHandler(){return this._localSignalingHandler}getRemoteSignalingHandler(){return this._remoteSignalingHandler}canIUseSignaling(){return this._canIUseSignaling}emitEvent(t,e){this._outerEmitter.emit(t,e)}addSignalingListener(t,e,i){this._canIUseSignaling||(this._canIUseSignaling=!0),this._outerEmitter.on(t,e,i)}removeSignalingListener(t,e,i){this._outerEmitter.off(t,e,i),0===this._outerEmitter.eventNames().length&&(this._canIUseSignaling=!1)}invite(t){const e=this._n+".invite",{message:i,customData:n,inviteID:s}=this._localSignalingHandler.createInviteInfo(t);return X.l(e+` options:${JSON.stringify(t)} inviteID:`+s),this.sendSignaling(i,t).then(t=>t&&0===t.code?(this.setInviteInfo(s,{...n,message:i}),this.startTimer({...n,inviteID:s}),{...t,inviteID:s}):t).catch(t=>at(t))}inviteSync(t,e,i){const n=this._n+".inviteSync",{message:s,customData:o,inviteID:a}=this._localSignalingHandler.createInviteInfo(t);return X.l(n+` options:${JSON.stringify(t)} inviteID:`+a),this.sendSignaling(s,t).then(t=>{if(t&&0===t.code)return this.setInviteInfo(a,{...o,message:s}),this.startTimer({...o,inviteID:a}),e&&e({inviteID:a}),{inviteID:a};i&&i(0===t.code,t.message||"")}).catch(t=>(i&&i(t.code,t.message),at(t))),a}_handleImResponse(t,e,i){e&&0===e.code&&(this._isHandling=!1,i?this.deleteInviteInfo(t.inviteID):this.updateInviteInfo(t))}cancel(e){var t=this._n+".cancel";if(X.l(t+" options:"+JSON.stringify(e)),!this.hasInviteInfo(e.inviteID)||this._isHandling)return at({code:st});this._isHandling=!0;const i=this._localSignalingHandler.createCancelCustomData(e);if(!i)return this._isHandling=!1,at({code:it});var{groupID:t,inviteeList:n}=i,t=t||n[0],n=this._localSignalingHandler.createSignalingMessage(i,t);return this.sendSignaling(n,e).then(t=>(this._handleImResponse(i,t,!0),0===t.code?{...t,inviteID:e.inviteID}:t)).catch(t=>at(t))}accept(e){var t=this._n+".accept";if(X.l(t+" options:"+JSON.stringify(e)),!this.hasInviteInfo(e.inviteID)||this._isHandling)return at({code:nt});this._isHandling=!0;const i=this._localSignalingHandler.createAcceptCustomData(e);if(!i)return this._isHandling=!1,at({code:it});t=this._localSignalingHandler.createSignalingMessage(i);return this.sendSignaling(t,e).then(t=>(this._handleImResponse(i,t),0===t.code?{...t,inviteID:e.inviteID}:t)).catch(t=>at(t))}reject(e){var t=this._n+".reject";if(X.l(t+" options:"+JSON.stringify(e)),!this.hasInviteInfo(e.inviteID)||this._isHandling)return at({code:nt});this._isHandling=!0;const i=this._localSignalingHandler.createRejectCustomData(e);if(!i)return this._isHandling=!1,at({code:it});t=this._localSignalingHandler.createSignalingMessage(i);return this.sendSignaling(t,e).then(t=>(this._handleImResponse(i,t,!0),0===t.code?{...t,inviteID:e.inviteID}:t)).catch(t=>at(t))}getSignalingInfo(t){const e=this._n+".getSignalingInfo",{ID:i,from:n,to:s}=t,o=this._filterSignalingMessage(t);let a=null;if(o){const e=this._remoteSignalingHandler.getPayloadData(t);a=new wt(e)}t=o?"actionType:"+a.actionType:"";return X.l(e+` messageID:${i} from:${n} to:${s} ${t} isSignaling:`+o),a}modifyInvitation(t){const{inviteID:i,data:n}=t;if(!this.hasInviteInfo(t.inviteID)||this._isHandling)return at({code:nt});this._isHandling=!0;const{message:s,...o}=this.getInviteInfo(i),a=s.payload.data;return o.data=n,s.payload.data=JSON.stringify(o),this.get(e).modifyRemoteMessage(s).then(t=>(this.setInviteInfo(i,{...o,message:s}),this._isHandling=!1,t)).catch(t=>(this._isHandling=!1,s.payload.data=a,at(t)))}_genMessageControlInfo(t={}){const{data:e="",onlineUserOnly:i,inviteID:n="",offlinePushInfo:s,actionType:o}=t;let a={_onlineOnlyFlag:!1};const r={onlineUserOnly:(a=n&&this.getInviteInfo(n)?this.getInviteInfo(n).message:a)._onlineOnlyFlag||i||!1,offlinePushInfo:s,messageControlInfo:{excludedFromContentModeration:!0,excludedFromUnreadCount:!1,excludedFromLastMessage:!1}};if(o===vt){const t=!!e.match(/excludeTimeoutSignalingFromHistoryMessage/);return r.messageControlInfo.excludedFromUnreadCount=t,r.messageControlInfo.excludedFromLastMessage=t,r}var t=!!e.match(/excludeFromHistoryMessage/),g=!!e.match(/excludeOriginalSignalingFromHistoryMessage/);return r.messageControlInfo.excludedFromUnreadCount=t||g,r.messageControlInfo.excludedFromLastMessage=t||g,r}sendSignaling(t,i){return this.get(e).sendMessageInstance(t,this._genMessageControlInfo(i)).catch(t=>(this._isHandling=!1,at(t)))}filterMessageList(t){return t.filter(t=>this._filterSignalingMessage(t))}_filterSignalingMessage(t){let e=!1;if(t.type&&t.type===$){const{cloudCustomData:i="",payload:{data:n=""}}=t,s=i.match(/"type":"tsignaling"/),o=n.match(/inviteID/),a=n.match(/actionType/);e=s||o&&a}return!!e}startTimer(i){const n=this._n+".startTimer",{timeout:t,inviteID:s,inviter:e,groupID:o}=i,a=e===this.getMyUserID();if(X.l(n+` timeout:${t} isInviter:${a} groupID:`+o),!(t<=0)){const r=a?t+5:t;let e=1;const g=setInterval(()=>{var t=this._hasLocalInviteInfo(i,a);e<r&&t?++e:(t&&this._sendTimeoutNotice(s,a),X.l(n+" end."),clearInterval(g))},1e3)}}_hasLocalInviteInfo(t,e){var{inviteID:t,groupID:i}=t;if(!this.hasInviteInfo(t))return!1;const n=this._n+"._hasLocalInviteInfo",s=this.getInviteInfo(t)["inviteeList"];return X.l(n+` inviteID:${t} inviteeList:${s} groupID:`+i),!i||(e?0<s.length:0<s.length&&s.includes(this.getMyUserID()))}_getReceiver(t,e){var{groupID:e,inviteeList:i,inviter:n}=e;return t?e||i[0]:e||n}_sendTimeoutNotice(s,o){var t=this.getInviteInfo(s),e=this._getReceiver(o,t);X.l(this._n+`._sendTimeoutNotice inviteID:${s} to:${e} isInviter:`+o);const a=this._localSignalingHandler.createTimeoutCustomData({...t,isInviter:o}),r=this._localSignalingHandler.createSignalingMessage(a,e);return this.sendSignaling(r,a).then(t=>{if(t&&0===t.code){const{data:t,groupID:e,inviteeList:i,inviter:n}=a;this.emitEvent(ut,{data:t,groupID:e,inviteID:s,inviteeList:i,inviter:n,isSelfTimeout:!0,message:r}),o?this.deleteInviteInfo(s):this.updateInviteInfo(a)}})}reset(){X.l(this._n+".reset"),this._inviteInfoMap.clear(),this._canIUseSignaling=!1,this._isHandling=!1,this._historySignalingHandler.reset(),this._isC2CUnreadHandleCompleted=!1,this._isConvSyncCompleted=!1,this._isSyncCompleted=!1}}export{Tt as default};