@tencentcloud/lite-chat
Version:
Tencent Cloud Chat SDK for Web/Mini Program/uni-app
1 lines • 704 kB
JavaScript
import e from"events";import t from"https";import s from"http";import n from"net";import o from"tls";import i from"crypto";import r from"stream";import a from"url";import c from"zlib";const u=e=>void 0===e,l=e=>"string"==typeof e,d=e=>{var t;return null===(t=Object.prototype.toString.call(e).match(/^\[object (.*)\]$/))||void 0===t?void 0:t[1].toLowerCase()},h=e=>"function"==typeof Array.isArray?Array.isArray(e):"array"===d(e),p=e=>null!==e&&"object"==typeof e,_=e=>h(e)||p(e),g=e=>{if("string"!=typeof e)return!1;const t=e[0];return!/[^a-zA-Z0-9]/.test(t)},m=e=>{if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let s=t;for(;null!==Object.getPrototypeOf(s);)s=Object.getPrototypeOf(s);return t===s};function f(e=99999999){return Math.round(Math.random()*e)}const v=(e,t,s,n)=>{if(!_(e)||!_(t))return 0;let o=0;const i=Object.keys(t);let r;for(let a=0,c=i.length;a<c;a++)if(r=i[a],!(u(t[r])||s&&s.includes(r)))if(_(e[r])&&_(t[r]))o+=v(e[r],t[r],s,n);else{if(n&&n.includes(t[r]))continue;e[r]!==t[r]&&(e[r]=t[r],o+=1)}return o};function I(e){let t,s,n=e;e.length%8!=0&&(n="0".repeat(8-e.length%8)+e);let o="";for(let e=0,{length:i}=n;e<i;e+=8)t=parseInt(n.slice(e,e+4),2),s=parseInt(n.slice(e+4,e+8),2),o+=base16Map.get(t)+base16Map.get(s);return o}const E={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,DONUT_NATIVE_APP:19,NS_NATIVE_APP:20,RN_NATIVE_APP:21},S=["heartbeat.alive","im_open_status.wslogin","im_open_status.wslogout","group_open_long_polling_http_svc.get_msg","group_open_long_polling_http_noauth_svc.get_msg"];var C;!function(e){e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.NONE=4]="NONE"}(C||(C={}));const y="LiteChat",M={[C.DEBUG]:console.debug,[C.INFO]:console.info,[C.WARN]:console.warn,[C.ERROR]:console.error},T={[C.INFO]:4,[C.WARN]:5,[C.ERROR]:6},A=1e3,O=2,D=5e3,R=50,L={CHINA:"CHINA",OVERSEA:"OVERSEA",SINGAPORE:"SINGAPORE",KOREA:"KOREA",GERMANY:"GERMANY",IND:"IND",JPN:"JPN",USA:"USA",INDONESIA:"INDONESIA",KSA:"KSA"},b={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"},KSA:{DEFAULT:"wss://wssksa-dev.im.qcloud.com"}},PRODUCTION:{CHINA:{INITIAL:"wss://*w4c.my-imcloud.com",DEFAULT:"wss://wss.im.qcloud.com",IPV6:"wss://wssv6.im.qcloud.com",BACKUP:"wss://wss.tim.qq.com",BACKUP_WEB_ONLY:"wss://*w4c.my-cpaas.com",BACKUP_CN:"wss://wss.im.tencent.cn",STAT:"https://events.im.qcloud.com",ANYCAST:"wss://162.14.13.203"},OVERSEA:{INITIAL:"wss://*w4c.my-imcloud.com",DEFAULT:"wss://wss.im.qcloud.com",IPV6:"wss://wssv6.im.qcloud.com",BACKUP:"wss://wss.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4c.my-cpaas.com",BACKUP_CN:"wss://wss.im.tencent.cn",STAT:"https://api.my-imcloud.com"},SINGAPORE:{INITIAL:"wss://*w4s.my-imcloud.com",DEFAULT:"wss://wsssgp.im.qcloud.com",IPV6:"wss://wsssgpv6.im.qcloud.com",BACKUP:"wss://wsssgp.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4s.my-cpaas.com",STAT:"https://apisgp.my-imcloud.com",ANYCAST:"wss://162.14.19.159"},KOREA:{INITIAL:"wss://*w4k.my-imcloud.com",DEFAULT:"wss://wsskr.im.qcloud.com",IPV6:"wss://wsskrv6.im.qcloud.com",BACKUP:"wss://wsskr.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4k.my-cpaas.com",STAT:"https://apikr.my-imcloud.com",ANYCAST:"wss://162.14.13.104"},GERMANY:{INITIAL:"wss://*w4g.my-imcloud.com",DEFAULT:"wss://wssger.im.qcloud.com",IPV6:"wss://wssgerv6.im.qcloud.com",BACKUP:"wss://wssger.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4g.my-cpaas.com",STAT:"https://apiger.my-imcloud.com",ANYCAST:"wss://162.14.3.17"},IND:{INITIAL:"wss://*w4i.my-imcloud.com",DEFAULT:"wss://wssind.my-imcloud.com",IPV6:"wss://wssindv6.im.qcloud.com",BACKUP:"wss://wssind.im.qcloud.com",BACKUP_WEB_ONLY:"wss://*w4i.my-cpaas.com",STAT:"https://apiind.my-imcloud.com",ANYCAST:"wss://162.14.19.46"},JPN:{INITIAL:"wss://*w4j.my-imcloud.com",DEFAULT:"wss://wssjpn.im.qcloud.com",IPV6:"wss://wssjpnv6.im.qcloud.com",BACKUP:"wss://wssjpn.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4j.my-cpaas.com",STAT:"https://apijpn.my-imcloud.com",ANYCAST:"wss://162.14.13.254"},USA:{INITIAL:"wss://*w4u.my-imcloud.com",DEFAULT:"wss://wssusa.im.qcloud.com",IPV6:"wss://wssusav6.im.qcloud.com",BACKUP:"wss://wssusa.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4u.my-cpaas.com",STAT:"https://apiusa.my-imcloud.com",ANYCAST:"wss://162.14.10.42"},INDONESIA:{INITIAL:"wss://*w4y.my-imcloud.com",DEFAULT:"wss://wssidn.im.qcloud.com",IPV6:"wss://wssidnv6.im.qcloud.com",BACKUP:"wss://wssidn.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4y.my-cpaas.com",STAT:"https://apiidn.my-imcloud.com",ANYCAST:"wss://43.129.34.169"},KSA:{INITIAL:"wss://*w4a.my-imcloud.com",DEFAULT:"wss://wssksa.im.qcloud.com",IPV6:"wss://wssksav6.im.qcloud.com",BACKUP:"wss://wssksa.my-imcloud.com",BACKUP_WEB_ONLY:"wss://*w4a.my-cpaas.com",STAT:"https://apiksa.my-imcloud.com",ANYCAST:"wss://43.164.68.251"}}};var N;!function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(N||(N={}));var G=Object.freeze({__proto__:null,ACCESS_ENVIRONMENT:L,CONSOLE_METHOD:M,CloudConfigReportLevelMap:T,get ConvModifyPushType(){return N},DEFAULT_GLOBAL_MAX_TOTAL_COUNT:R,DEFAULT_GLOBAL_THROTTLE_TIME:D,DEFAULT_SINGLE_MAX_TOTAL_COUNT:O,DEFAULT_SINGLE_THROTTLE_TIME:A,ENUM_PLATFORM:E,HOST_CONFIG:b,IS_TOPIC_MESSAGE:2,get LogLevel(){return C},NOT_NEED_CRC_SERVCMD:S,SDK_NAME:y});const w="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&("mac"===wx.getSystemInfoSync().platform||"windows"===wx.getSystemInfoSync().platform)&&void 0===wx.getSystemInfoSync().uniPlatform,P="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting)||w,U=P&&"function"==typeof wx.createGamePortal,k="undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting),F="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),x=F&&"function"==typeof tt.onShow,$="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),q="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),V="undefined"!=typeof jd&&"function"==typeof jd.getSystemInfoSync,B="undefined"!=typeof uni&&"undefined"==typeof window&&"function"==typeof uni.requireNativePlugin,j=P&&"object"==typeof wx.miniapp,W="undefined"!=typeof uni,H=F&&"function"==typeof tt.enterChat,K=P||k||F||$||q||B||V,Y="undefined"==typeof window&&!K&&"undefined"!=typeof global&&void 0!==global.NativeScriptGlobals,z="undefined"!=typeof global&&(void 0!==global.nativeModuleProxy||void 0!==global.ReactNative),J="undefined"!=typeof wx&&"function"==typeof wx.getAccountInfoSync&&Boolean(wx.getAccountInfoSync().plugin),Q="undefined"!=typeof uni?!K:"undefined"!=typeof window&&!K&&!z,X=k?qq:F?tt:$?swan:q?my:P?wx:B?uni:V?jd:{},Z=Q&&window&&window.navigator&&window.navigator.userAgent||"",ee=/(micromessenger|webbrowser)/i.test(Z),te=function(){let e="WEB";return ee?e="WEB":k?e="QQ_MP":F?e="TT_MP":$?e="BAIDU_MP":q?e="ALI_MP":P?e=j?"DONUT_NATIVE_APP":"WX_MP":B?e="UNI_NATIVE_APP":Y?e="NS_NATIVE_APP":z&&(e="RN_NATIVE_APP"),E[e]}(),se=/iPad/i.test(Z),ne=/iPhone/i.test(Z)&&!se,oe=/iPod/i.test(Z),ie=ne||se||oe,re=function(){const e=Z.match(/OS (\d+)_/i);return e&&e[1]?e[1]:null}(),ae=/Android/i.test(Z),ce=function(){const e=Z.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);if(!e)return null;const t=e[1]&&parseFloat(e[1]),s=e[2]&&parseFloat(e[2]);return t&&s?parseFloat(`${e[1]}.${e[2]}`):t||null}(),ue=/Firefox/i.test(Z),le=/Edge/i.test(Z),de=!le&&/Chrome/i.test(Z),he=/MSIE/.test(Z)||Z.indexOf("Trident")>-1&&Z.indexOf("rv:11.0")>-1,pe=function(){const e=/MSIE\s(\d+)\.\d/.exec(Z);let t=e&&parseFloat(e[1]);return!t&&/Trident\/7.0/i.test(Z)&&/rv:11.0/.test(Z)&&(t=11),t}(),_e=/Safari/i.test(Z)&&!de&&!ae&&!le,ge=/Windows/i.test(Z),me=/MAC OS X/i.test(Z),fe=Q&&"undefined"!=typeof Worker&&!he,ve=ae||ie,Ie=function(){if("undefined"==typeof window||void 0===window.navigator)return!1;const{standalone:e}=window.navigator;return!(!ie||e||_e)}();function Ee(){let e="unknown";if(me&&(e="mac"),ge&&(e="windows"),ie&&(e="ios"),ae&&(e="android"),K)try{const{platform:t}=X.getSystemInfoSync();void 0!==t&&(e=t)}catch(e){console.error(e)}return e}const Se="undefined"!=typeof process&&void 0!==process.versions&&void 0!==process.versions.node&&"undefined"==typeof window;function Ce(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}function ye(e,t,s,n){return new(s||(s=Promise))(function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(r,a)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const Me=2800,Te=2801;const Ae=3e3,Oe="application/x-www-form-urlencoded;charset=UTF-8";function De(e){return ye(this,arguments,void 0,function*({method:e,url:t,data:s,timeout:n=Ae}){return K?new Promise((o,i)=>{X.request({url:t,data:s,method:e,timeout:n,header:{"content-type":Oe},success:e=>o(e.data),fail:()=>i(new Error(`{"message":"Network error","code":${Me}}`))})}):Se?function(e){return ye(this,arguments,void 0,function*({method:e,url:t,data:s,timeout:n}){const o=new AbortController,i=setTimeout(()=>o.abort(),n);try{const n=yield fetch(t,{method:e,body:s||null,headers:{"content-type":"application/x-www-form-urlencoded;charset=UTF-8"},signal:o.signal});return clearTimeout(i),yield n.json()}catch(e){throw clearTimeout(i),new Error(`{"message":"Network error","code":${Me}}`)}})}({method:e,url:t,data:s,timeout:n}):new Promise((o,i)=>{const r=new XMLHttpRequest,a=setTimeout(()=>{r.abort(),i(new Error(`{"message":"Request timeout","code":${Te}}`))},n);r.onreadystatechange=function(){if(4===r.readyState)if(clearTimeout(a),200===r.status||304===r.status)try{o(r.responseText?JSON.parse(r.responseText):null)}catch(e){o(r.responseText)}else i(new Error(`{"message":"Network error","code":${Me}}`))},r.open(e,t,!0),r.setRequestHeader("Content-type",Oe),r.send(s||null)})})}function Re(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(m(e)){for(const t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}return("[object Map]"===Object.prototype.toString.call(e)||"[object Set]"===Object.prototype.toString.call(e)||"[object File]"===Object.prototype.toString.call(e))&&0===e.size}function Le(e,t){if(null===e||"object"!=typeof e)return e;const s=t||new WeakMap;if(s.has(e))return s.get(e);if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){const t=new Map;return s.set(e,t),e.forEach((e,n)=>{t.set(Le(n,s),Le(e,s))}),t}if(e instanceof Set){const t=new Set;return s.set(e,t),e.forEach(e=>{t.add(Le(e,s))}),t}if(Array.isArray(e)){const t=[];return s.set(e,t),e.forEach(e=>{t.push(Le(e,s))}),t}const n=Object.getPrototypeOf(e),o=Object.create(n);s.set(e,o);return[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)].forEach(t=>{if("__ob__"===t||"__v_skip"===t||"__v_isRef"===t||"__v_isReadonly"===t)return;const n=Object.getOwnPropertyDescriptor(e,t);n&&(n.get||n.set?Object.defineProperty(o,t,n):o[t]=Le(e[t],s))}),o}function be(e,t,s){const n=new WeakSet,o=(e,s)=>{if(t&&(s=t(e,s)),void 0===s)return"undefined";if(null===s)return null;if(Number.isNaN(s))return"NaN";if(s===1/0)return"Infinity";if(s===-1/0)return"-Infinity";if("function"==typeof s)return`[Function: ${s.name||"anonymous"}]`;if("symbol"==typeof s)return s.toString();if("bigint"==typeof s)return`${s.toString()}n`;if("object"==typeof s&&null!==s){if(n.has(s))return"[Circular]";n.add(s)}return s instanceof Date?s.toISOString():s instanceof Error?{name:s.name,message:s.message,stack:s.stack}:s instanceof Map?{dataType:"Map",value:Array.from(s.entries())}:s instanceof Set?{dataType:"Set",value:Array.from(s.values())}:s};try{return JSON.stringify(e,o,s)}catch(e){return console.error("Failed to stringify:",e),""}}function Ne(){let e,t;return{promise:new Promise((s,n)=>{e=s,t=n}),resolve:e,reject:t}}var Ge,we=Object.freeze({__proto__:null,ANDROID_VERSION:ce,IE_VERSION:pe,IN_ALIPAY_MINI_APP:q,IN_BAIDU_MINI_APP:$,IN_BROWSER:Q,IN_DONUT_NATIVE_APP:j,IN_FEISHU_MINI_APP:H,IN_JD_MINI_APP:V,IN_MINI_APP:K,IN_NODE:Se,IN_NS_NATIVE_APP:Y,IN_QQ_MINI_APP:k,IN_RN_APP:z,IN_TT_MINI_APP:F,IN_TT_MINI_GAME:x,IN_UNI_APP:W,IN_UNI_NATIVE_APP:B,IN_WX_MINI_APP:P,IN_WX_MINI_APP_DESK:w,IN_WX_MINI_GAME:U,IN_WX_MINI_PLUGIN:J,IOS_VERSION:re,IS_ANDROID:ae,IS_CHROME:de,IS_EDGE:le,IS_FIREFOX:ue,IS_IE:he,IS_IOS:ie,IS_IPAD:se,IS_IPHONE:ne,IS_IPOD:oe,IS_MAC:me,IS_SAFARI:_e,IS_WECHAT:ee,IS_WIN:ge,IS_WORKER_AVAILABLE:fe,MINI_APP_NAMESPACE:X,USER_AGENT:Z,base16EncodeBinaryString:I,deepCopyWithMethods:Le,deepMerge:v,generatePromise:Ne,getPlatformType:Ee,getType:d,httpRequest:De,isArray:h,isArrayOrObject:_,isEmpty:Re,isH5:ve,isIOSWebView:Ie,isNumber:e=>null!==e&&("number"==typeof e&&!Number.isNaN(e-0)||"object"==typeof e&&e.constructor===Number),isObject:p,isPlainObject:m,isString:l,isUndefined:u,isUniIOSApp:function(){return B&&"ios"===uni.getDeviceInfo().platform.toLocaleLowerCase()},isValidRequestKey:g,platform:te,randomInt:f,randomString:function(){const e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";let t="";for(let s=32;s>0;--s)t+=e[Math.floor(62*Math.random())];return t},safeStringify:be});class Pe{constructor(){this.listeners={}}on(e,t,s){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push({fn:t,context:s})}off(e,t,s){var n;t&&(this.listeners[e]=null===(n=this.listeners[e])||void 0===n?void 0:n.filter(e=>{const n=e.fn===t,o=!s||e.context===s;return!(n&&o)}))}emit(e,...t){const s=this.listeners[e];s&&s.forEach(s=>{const{fn:n,context:o}=s;try{n.apply(o,t)}catch(t){console.warn(`Error in event handler for ${e} error: ${be(t)}`)}})}once(e,t,s){const n=(...o)=>{t.apply(s,o),this.off(e,n)};this.on(e,n)}}!function(e){e.BUSINESS_COMMAND="business_command",e.C2C_REALTIME_MESSAGE="c2c_realtime_message",e.C2C_MESSAGE_MODIFIED="c2c_message_modified",e.C2C_REVOKED_MESSAGE="c2c_message_revoked",e.GROUP_REALTIME_MESSAGE="group_realtime_message",e.GROUP_MESSAGE_MODIFIED="group_message_modified",e.GROUP_MESSAGE_REVOKED="group_message_revoked",e.C2C_MESSAGE_READ_RECEIPT="c2c_message_read_receipt",e.MESSAGE_REACTION_UPDATED="message_reaction_updated",e.MESSAGE_REACTION_UPDATED_SYNC="message_reaction_updated_sync",e.GROUP_AT_TIPS="group_at_tips",e.USER_STATUS_UPDATE="user_status_update",e.FRIEND_LIST_MODIFIED="friend_list_modified",e.PROFILE_MODIFIED="profile_modified",e.CONV_MODIFIED="conversation_modified",e.GROUP_TIPS_NOTIFICATION="group_tips_notification",e.GROUP_MESSAGE_READ_RECEIPT="group_message_read_receipt",e.GROUP_MESSAGE_READ_SYNC="group_message_read_sync",e.GROUP_SYSTEM_NOTIFICATION="group_system_notification",e.C2C_MESSAGE_PEER_READ="c2c_message_peer_read",e.C2C_MESSAGE_READ_SYNC="c2c_message_read_sync",e.C2C_REMIND_TYPE_SYNC="c2c_remind_type_sync",e.FOLLOW_LIST_UPDATED="follow_list_updated",e.MESSAGE_EXTENSIONS_UPDATED="message_extensions_updated",e.ALL_MESSAGE_READ="all_message_read",e.CONVERSATION_MARK_UPDATED="conversation_mark_updated",e.CONVERSATION_GROUP_ADD="conversation_group_add",e.CONVERSATION_GROUP_DELETED="conversation_group_deleted",e.CONVERSATION_GROUP_UPDATED="conversation_group_updated",e.ALL_RECEIVE_MESSAGE_OPTION="all_receive_message_option",e.TOPIC_AT_TIPS="topic_at_tips",e.TOPIC_TIPS_NOTIFICATION="topic_tips_notification",e.TOPIC_SYSTEM_NOTIFICATION="topic_system_notification",e.TOPIC_MESSAGE_READ_SYNC="topic_message_read_sync",e.TOPIC_LATEST_MESSAGE="topic_latest_message",e.GROUP_MESSAGE_PINNED="group_message_pinned"}(Ge||(Ge={}));const Ue=[16,17];function ke(e){var t;const s=[];return null===(t=null==e?void 0:e.GroupTips)||void 0===t||t.forEach(e=>{var t;2===e.GroupInfo.MillionGroupFlag?s.push(Ge.TOPIC_TIPS_NOTIFICATION):Ue.includes(null===(t=null==e?void 0:e.MsgBody)||void 0===t?void 0:t.OpType)?s.push(Ge.GROUP_MESSAGE_PINNED):s.push(Ge.GROUP_TIPS_NOTIFICATION)}),s}const Fe=[{conditions:[{type:"event",value:100}],subType:Ge.BUSINESS_COMMAND},{conditions:[{type:"event",value:24}],subType:Ge.ALL_RECEIVE_MESSAGE_OPTION},{conditions:[{type:"event",value:26}],subType:Ge.TOPIC_LATEST_MESSAGE},{conditions:[{type:"hasKey",value:"C2cMsgArray"}],subType:Ge.C2C_REALTIME_MESSAGE},{conditions:[{type:"hasKey",value:"C2cMsgModNotifys"}],subType:Ge.C2C_MESSAGE_MODIFIED},{conditions:[{type:"hasKey",value:"ProfileDataMod"}],subType:Ge.PROFILE_MODIFIED},{conditions:[{type:"hasKey",value:"UserStatusList"}],subType:Ge.USER_STATUS_UPDATE},{conditions:[{type:"hasKey",value:"FriendListMod"}],subType:Ge.FRIEND_LIST_MODIFIED},{conditions:[{type:"hasKey",value:"GroupMsgArray"}],subType:Ge.GROUP_REALTIME_MESSAGE},{conditions:[{type:"hasKey",value:"GroupMsgModNotifys"}],subType:Ge.GROUP_MESSAGE_MODIFIED},{conditions:[{type:"hasKey",value:"C2cNotifyMsgArray"}],subTypeParser:function(e){var t;const s=[];return null===(t=null==e?void 0:e.C2cNotifyMsgArray)||void 0===t||t.forEach(e=>{e.WithdrawC2cMsgNotify&&s.push(Ge.C2C_REVOKED_MESSAGE),e.C2cReadedReceipt&&s.push(Ge.C2C_MESSAGE_PEER_READ),e.ReadC2cMsgNotify&&s.push(Ge.C2C_MESSAGE_READ_SYNC),e.MuteNotificationsSync&&s.push(Ge.C2C_REMIND_TYPE_SYNC)}),s}},{conditions:[{type:"hasKey",value:"GroupTips"},{type:"event",value:4}],subTypeParser:ke},{conditions:[{type:"hasKey",value:"GroupTips"},{type:"event",value:5}],subTypeParser:function(e){var t;const s=[];return null===(t=null==e?void 0:e.GroupTips)||void 0===t||t.forEach(e=>{Array.isArray(e.MsgBody.GroupWithdrawInfoArray)?s.push(Ge.GROUP_MESSAGE_REVOKED):Array.isArray(e.MsgBody.GroupMsgReceiptList)?s.push(Ge.GROUP_MESSAGE_READ_RECEIPT):Array.isArray(e.MsgBody.GroupReadInfoArray)?e.MsgBody.GroupReadInfoArray[0].TopicId?s.push(Ge.TOPIC_MESSAGE_READ_SYNC):s.push(Ge.GROUP_MESSAGE_READ_SYNC):2===e.GroupInfo.MillionGroupFlag?s.push(Ge.TOPIC_SYSTEM_NOTIFICATION):s.push(Ge.GROUP_SYSTEM_NOTIFICATION)}),s}},{conditions:[{type:"hasKey",value:"GroupTips"},{type:"event",value:6}],subTypeParser:ke},{conditions:[{type:"hasKey",value:"GroupTips"},{type:"event",value:12}],subTypeParser:function(e){var t;const s=[];return null===(t=null==e?void 0:e.GroupTips)||void 0===t||t.forEach(e=>{const{GroupAtTips:{TopicId:t}}=e;t?s.push(Ge.TOPIC_AT_TIPS):s.push(Ge.GROUP_AT_TIPS)}),s}},{conditions:[{type:"hasKey",value:"RecentContactMod"}],subTypeParser:function(e){var t;const s=[];return null===(t=null==e?void 0:e.RecentContactMod)||void 0===t||t.forEach(e=>{switch(e.PushType){case N.CONV_MARK_UPDATED:s.push(Ge.CONVERSATION_MARK_UPDATED);break;case N.CONV_GROUP_ADDED:s.push(Ge.CONVERSATION_GROUP_ADD);break;case N.CONV_GROUP_DELETED:s.push(Ge.CONVERSATION_GROUP_DELETED);break;case N.CONV_GROUP_UPDATED:s.push(Ge.CONVERSATION_GROUP_UPDATED);break;default:s.push(Ge.CONV_MODIFIED)}}),s}},{conditions:[{type:"hasKey",value:"MsgReactionNotifyList"}],subType:Ge.MESSAGE_REACTION_UPDATED},{conditions:[{type:"hasKey",value:"MsgReactionNotify"}],subType:Ge.MESSAGE_REACTION_UPDATED_SYNC},{conditions:[{type:"hasKey",value:"C2cMsgInfo"}],subType:Ge.C2C_MESSAGE_READ_RECEIPT},{conditions:[{type:"hasKey",value:"FollowChangeList"}],subType:Ge.FOLLOW_LIST_UPDATED},{conditions:[{type:"hasKey",value:"MsgExtensionNotify"}],subType:Ge.MESSAGE_EXTENSIONS_UPDATED},{conditions:[{type:"hasKey",value:"C2CReadAllMsg"}],subType:Ge.ALL_MESSAGE_READ}];var xe;function $e(e){var t;const s=Array.isArray(null===(t=null==e?void 0:e.body)||void 0===t?void 0:t.EventArray)?e.body.EventArray:[],n=[];return s.forEach(t=>{t.Flag=e.body.Flag;const s=Fe.find(e=>e.conditions.every(e=>{switch(e.type){case"event":return t.Event===e.value;case"hasKey":return Object.prototype.hasOwnProperty.call(t,e.value);default:return!1}}));if(!s)return null;let o=[];"function"==typeof s.subTypeParser?o=s.subTypeParser(t):s.subType&&(o=s.subType),Array.isArray(o)?o.forEach(e=>{n.push({type:`${xe.SERVER_PUSH_MESSAGE}:${e}`,data:t})}):n.push({type:`${xe.SERVER_PUSH_MESSAGE}:${o}`,data:t})}),n}!function(e){e.SERVER_PUSH_MESSAGE="im_open_push.msg_push",e.SERVER_PUSH_MESSAGE_MULTIPLE="im_open_push.multi_msg_push_ws",e.ERROR="error"}(xe||(xe={}));const qe={[xe.SERVER_PUSH_MESSAGE]:$e,[xe.SERVER_PUSH_MESSAGE_MULTIPLE]:$e,[xe.ERROR]:function(e){const{errorCode:t}=e;return[{type:`error:${t}`,data:e}]}};const Ve=new class{constructor(){this._outerEventEmitter=null,this._innerEventEmitter=null,this._filteredCallbackMap=new Map,this._outerEventEmitter=new Pe,this._innerEventEmitter=new Pe,this.InnerEventSubType=Ge}subscribeInnerEvent(e,t,s,n,o){var i;let r,a,c,u;["string","number"].includes(typeof t)?(c=`${e}:${t}`,u=s,a=n,r=o):(c=e,u=t,a=s,r="function"==typeof n?n:void 0),r?this._subscribeWithFilter(c,u,a,r):null===(i=this._innerEventEmitter)||void 0===i||i.on(c,u,a)}emitInnerEvent(e,t){var s,n;if(null===(s=this._innerEventEmitter)||void 0===s||s.emit(e,t),Object.keys(qe).includes(e)){const s=null===(n=qe[e])||void 0===n?void 0:n.call(qe,t);null==s||s.forEach(e=>{var t;e&&(null===(t=this._innerEventEmitter)||void 0===t||t.emit(e.type,e.data))})}}subscribeOuterEvent(e,t,s){var n;null===(n=this._outerEventEmitter)||void 0===n||n.on(e,t,s)}unSubscribeOuterEvent(e,t,s){var n;null===(n=this._outerEventEmitter)||void 0===n||n.off(e,t,s)}unSubscribeInnerEvent(e,t,s,n){if(["string","number"].includes(typeof t)){const o=s,i=`${e}:${t}`;this._unsubscribeEvent(i,o,n)}else{const n=t;this._unsubscribeEvent(e,n,s)}}emitOuterEvent(e,t){var s;null===(s=this._outerEventEmitter)||void 0===s||s.emit(e,t)}getOuterEventEmitter(){return this._outerEventEmitter}rest(){this._outerEventEmitter=null,this._innerEventEmitter=null}_subscribeWithFilter(e,t,s,n){var o;const i=e=>{n.call(s,e)&&t.call(s,e)};this._filteredCallbackMap.has(e)||this._filteredCallbackMap.set(e,[]),this._filteredCallbackMap.get(e).push({originalCallback:t,filteredCallback:i,filter:n,context:s}),null===(o=this._innerEventEmitter)||void 0===o||o.on(e,i,s)}_unsubscribeEvent(e,t,s){var n,o;const i=this._filteredCallbackMap.get(e);if(i){const o=i.findIndex(e=>e.originalCallback===t&&e.context===s);if(-1!==o){const{filteredCallback:t}=i[o];return null===(n=this._innerEventEmitter)||void 0===n||n.off(e,t,s),i.splice(o,1),void(0===i.length&&this._filteredCallbackMap.delete(e))}}null===(o=this._innerEventEmitter)||void 0===o||o.off(e,t,s)}};class Be{constructor(){this._socket=null}connectSocket(e){return this._socket=new WebSocket(e),this._socket}send(e){var t,s;try{null===(t=this._socket)||void 0===t||t.send(e)}catch(e){null===(s=this._onSendFail)||void 0===s||s.call(this,e)}}bindSocketHandlers(e){const{onOpen:t,onMessage:s,onClose:n,onError:o,onSendFail:i}=e;this._socket&&(this._socket.binaryType="arraybuffer",this._socket.onopen=t,this._socket.onmessage=s,this._socket.onclose=n,this._socket.onerror=o,this._onSendFail=i)}unbindSocketHandlers(){this._socket&&(this._socket.onopen=null,this._socket.onmessage=null,this._socket.onclose=null,this._socket.onerror=null)}disconnect(){this._socket&&(this._socket.close(),this._socket=null)}}class je{constructor(e){this._onError=e.onError}connectSocket(e){const t=this;return this._socket=X.connectSocket({url:e,header:{"content-type":"application/json"},complete:()=>{},fail:e=>t._onError(e)}),this._socket}send(e){var t;null===(t=this._socket)||void 0===t||t.send({data:e,fail:this._onSendFail})}bindSocketHandlers(e){const{onOpen:t,onMessage:s,onClose:n,onError:o,onSendFail:i}=e;this._socket&&(this._socket.onClose(n),this._socket.onOpen(t),this._socket.onMessage(s),this._socket.onError(o),this._onSendFail=i)}unbindSocketHandlers(){this._socket&&(this._socket.onClose(()=>{}),this._socket.onOpen(()=>{}),this._socket.onMessage(()=>{}),this._socket.onError(()=>{}))}disconnect(){this._socket&&(this._socket.close(),this._socket=null)}}const We="CONNECT",He="SEND",Ke="DISCONNECT",Ye="OPEN",ze="MESSAGE",Je="CLOSE",Qe="ERROR",Xe="SEND_FAIL";class Ze{constructor(){this._worker=null,this._blobUrl=null}connectSocket(e){const t=new Blob(["\n let _socket = null;\n\n self.onmessage = (event) => {\n const { type, url, data } = event.data;\n\n switch (type) {\n case 'CONNECT':\n connectSocket(url);\n break;\n case 'SEND':\n send(data);\n break;\n case 'DISCONNECT':\n disconnect();\n break;\n }\n };\n\n function connectSocket(url) {\n _socket = new WebSocket(url);\n _socket.binaryType = 'arraybuffer';\n bindSocketHandlers();\n return _socket;\n }\n\n function send(packet) {\n try {\n _socket?.send(packet);\n } catch (error) {\n self.postMessage({\n type: 'SEND_FAIL', \n error: {\n message: error.message,\n name: error.name,\n },\n });\n }\n }\n\n function bindSocketHandlers() {\n if (_socket) {\n _socket.onopen = (event) => {\n self.postMessage({\n type: 'OPEN',\n data: {\n type: event.type,\n timeStamp: event.timeStamp,\n },\n });\n };\n\n _socket.onmessage = (event) => {\n self.postMessage({ \n type: 'MESSAGE',\n data: event.data,\n });\n };\n\n _socket.onclose = (event) => {\n self.postMessage({ \n type: 'CLOSE', \n data: { \n code: event.code,\n reason: event.reason,\n timeStamp: event.timeStamp,\n },\n });\n };\n\n _socket.onerror = (error) => {\n self.postMessage({\n type: 'ERROR',\n data: {\n message: error.message,\n name: error.name\n },\n });\n };\n }\n }\n\n function unbindSocketHandlers() {\n if (_socket) {\n _socket.onopen = null;\n _socket.onmessage = null;\n _socket.onclose = null;\n _socket.onerror = null;\n }\n }\n\n function disconnect() {\n if (_socket) {\n _socket.close();\n _socket = null;\n }\n }\n"],{type:"application/javascript"});this._worker=new Worker(URL.createObjectURL(t)),this._worker.postMessage({type:We,url:e})}send(e){var t,s;try{null===(t=this._worker)||void 0===t||t.postMessage({type:He,data:e})}catch(e){null===(s=this._onSendFail)||void 0===s||s.call(this,e)}}bindSocketHandlers(e){const{onOpen:t,onMessage:s,onClose:n,onError:o,onSendFail:i}=e;if(this._worker){const e={[Ye]:t,[ze]:s,[Je]:n,[Qe]:o,[Xe]:i};this._onSendFail=i,this._worker.onmessage=t=>{var s;const{type:n}=(null==t?void 0:t.data)||{};"function"==typeof e[n]&&(null===(s=e[n])||void 0===s||s.call(e,null==t?void 0:t.data))}}}unbindSocketHandlers(){this._worker&&(this._worker.onmessage=null)}disconnect(){this._worker&&(this._worker.postMessage({type:Ke}),this._worker.terminate(),this._worker=null),this._blobUrl&&(URL.revokeObjectURL(this._blobUrl),this._blobUrl=null)}}function et(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var st,nt,ot,it,rt,at,ct,ut={exports:{}};function lt(){return nt?st:(nt=1,st={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),EMPTY_BUFFER:Buffer.alloc(0),NOOP:()=>{}})}function dt(){if(ot)return ut.exports;ot=1;const{EMPTY_BUFFER:e}=lt();function t(t,s){if(0===t.length)return e;if(1===t.length)return t[0];const n=Buffer.allocUnsafe(s);let o=0;for(let e=0;e<t.length;e++){const s=t[e];n.set(s,o),o+=s.length}return o<s?n.slice(0,o):n}function s(e,t,s,n,o){for(let i=0;i<o;i++)s[n+i]=e[i]^t[3&i]}function n(e,t){const s=e.length;for(let n=0;n<s;n++)e[n]^=t[3&n]}function o(e){return e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function i(e){if(i.readOnly=!0,Buffer.isBuffer(e))return e;let t;return e instanceof ArrayBuffer?t=Buffer.from(e):ArrayBuffer.isView(e)?t=Buffer.from(e.buffer,e.byteOffset,e.byteLength):(t=Buffer.from(e),i.readOnly=!1),t}try{const e=require("bufferutil"),r=e.BufferUtil||e;ut.exports={concat:t,mask(e,t,n,o,i){i<48?s(e,t,n,o,i):r.mask(e,t,n,o,i)},toArrayBuffer:o,toBuffer:i,unmask(e,t){e.length<32?n(e,t):r.unmask(e,t)}}}catch(e){ut.exports={concat:t,mask:s,toArrayBuffer:o,toBuffer:i,unmask:n}}return ut.exports}function ht(){if(ct)return at;ct=1;const e=c,t=dt(),s=function(){if(rt)return it;rt=1;const e=Symbol("kDone"),t=Symbol("kRun");return it=class{constructor(s){this[e]=()=>{this.pending--,this[t]()},this.concurrency=s||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[t]()}[t](){if(this.pending!==this.concurrency&&this.jobs.length){const t=this.jobs.shift();this.pending++,t(this[e])}}}}(),{kStatusCode:n,NOOP:o}=lt(),i=Buffer.from([0,0,255,255]),r=Symbol("permessage-deflate"),a=Symbol("total-length"),u=Symbol("callback"),l=Symbol("buffers"),d=Symbol("error");let h;function p(e){this[l].push(e),this[a]+=e.length}function _(e){this[a]+=e.length,this[r]._maxPayload<1||this[a]<=this[r]._maxPayload?this[l].push(e):(this[d]=new RangeError("Max payload size exceeded"),this[d].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[d][n]=1009,this.removeListener("data",_),this.reset())}function g(e){this[r]._inflate=null,e[n]=1007,this[u](e)}return at=class{constructor(e,t,n){if(this._maxPayload=0|n,this._options=e||{},this._threshold=void 0!==this._options.threshold?this._options.threshold:1024,this._isServer=!!t,this._deflate=null,this._inflate=null,this.params=null,!h){const e=void 0!==this._options.concurrencyLimit?this._options.concurrencyLimit:10;h=new s(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:null==this._options.clientMaxWindowBits&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){const e=this._deflate[u];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){const t=this._options,s=e.find(e=>!(!1===t.serverNoContextTakeover&&e.server_no_context_takeover||e.server_max_window_bits&&(!1===t.serverMaxWindowBits||"number"==typeof t.serverMaxWindowBits&&t.serverMaxWindowBits>e.server_max_window_bits)||"number"==typeof t.clientMaxWindowBits&&!e.client_max_window_bits));if(!s)throw new Error("None of the extension offers can be accepted");return t.serverNoContextTakeover&&(s.server_no_context_takeover=!0),t.clientNoContextTakeover&&(s.client_no_context_takeover=!0),"number"==typeof t.serverMaxWindowBits&&(s.server_max_window_bits=t.serverMaxWindowBits),"number"==typeof t.clientMaxWindowBits?s.client_max_window_bits=t.clientMaxWindowBits:!0!==s.client_max_window_bits&&!1!==t.clientMaxWindowBits||delete s.client_max_window_bits,s}acceptAsClient(e){const t=e[0];if(!1===this._options.clientNoContextTakeover&&t.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(t.client_max_window_bits){if(!1===this._options.clientMaxWindowBits||"number"==typeof this._options.clientMaxWindowBits&&t.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}else"number"==typeof this._options.clientMaxWindowBits&&(t.client_max_window_bits=this._options.clientMaxWindowBits);return t}normalizeParams(e){return e.forEach(e=>{Object.keys(e).forEach(t=>{let s=e[t];if(s.length>1)throw new Error(`Parameter "${t}" must have only a single value`);if(s=s[0],"client_max_window_bits"===t){if(!0!==s){const e=+s;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${s}`);s=e}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}else if("server_max_window_bits"===t){const e=+s;if(!Number.isInteger(e)||e<8||e>15)throw new TypeError(`Invalid value for parameter "${t}": ${s}`);s=e}else{if("client_no_context_takeover"!==t&&"server_no_context_takeover"!==t)throw new Error(`Unknown parameter "${t}"`);if(!0!==s)throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}e[t]=s})}),e}decompress(e,t,s){h.add(n=>{this._decompress(e,t,(e,t)=>{n(),s(e,t)})})}compress(e,t,s){h.add(n=>{this._compress(e,t,(e,t)=>{n(),s(e,t)})})}_decompress(s,n,o){const c=this._isServer?"client":"server";if(!this._inflate){const t=`${c}_max_window_bits`,s="number"!=typeof this.params[t]?e.Z_DEFAULT_WINDOWBITS:this.params[t];this._inflate=e.createInflateRaw({...this._options.zlibInflateOptions,windowBits:s}),this._inflate[r]=this,this._inflate[a]=0,this._inflate[l]=[],this._inflate.on("error",g),this._inflate.on("data",_)}this._inflate[u]=o,this._inflate.write(s),n&&this._inflate.write(i),this._inflate.flush(()=>{const e=this._inflate[d];if(e)return this._inflate.close(),this._inflate=null,void o(e);const s=t.concat(this._inflate[l],this._inflate[a]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[a]=0,this._inflate[l]=[],n&&this.params[`${c}_no_context_takeover`]&&this._inflate.reset()),o(null,s)})}_compress(s,n,i){const r=this._isServer?"server":"client";if(!this._deflate){const t=`${r}_max_window_bits`,s="number"!=typeof this.params[t]?e.Z_DEFAULT_WINDOWBITS:this.params[t];this._deflate=e.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:s}),this._deflate[a]=0,this._deflate[l]=[],this._deflate.on("error",o),this._deflate.on("data",p)}this._deflate[u]=i,this._deflate.write(s),this._deflate.flush(e.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let e=t.concat(this._deflate[l],this._deflate[a]);n&&(e=e.slice(0,e.length-4)),this._deflate[u]=null,this._deflate[a]=0,this._deflate[l]=[],n&&this.params[`${r}_no_context_takeover`]&&this._deflate.reset(),i(null,e)})}}}var pt,_t,gt,mt,ft,vt,It,Et,St,Ct,yt,Mt,Tt,At,Ot,Dt,Rt,Lt={exports:{}};function bt(){if(pt)return Lt.exports;function e(e){return e>=1e3&&e<=1014&&1004!==e&&1005!==e&&1006!==e||e>=3e3&&e<=4999}function t(e){const t=e.length;let s=0;for(;s<t;)if(128&e[s])if(192==(224&e[s])){if(s+1===t||128!=(192&e[s+1])||192==(254&e[s]))return!1;s+=2}else if(224==(240&e[s])){if(s+2>=t||128!=(192&e[s+1])||128!=(192&e[s+2])||224===e[s]&&128==(224&e[s+1])||237===e[s]&&160==(224&e[s+1]))return!1;s+=3}else{if(240!=(248&e[s]))return!1;if(s+3>=t||128!=(192&e[s+1])||128!=(192&e[s+2])||128!=(192&e[s+3])||240===e[s]&&128==(240&e[s+1])||244===e[s]&&e[s+1]>143||e[s]>244)return!1;s+=4}else s++;return!0}pt=1;try{let s=require("utf-8-validate");"object"==typeof s&&(s=s.Validation.isValidUTF8),Lt.exports={isValidStatusCode:e,isValidUTF8:e=>e.length<150?t(e):s(e)}}catch(s){Lt.exports={isValidStatusCode:e,isValidUTF8:t}}return Lt.exports}function Nt(){if(gt)return _t;gt=1;const{Writable:e}=r,t=ht(),{BINARY_TYPES:s,EMPTY_BUFFER:n,kStatusCode:o,kWebSocket:i}=lt(),{concat:a,toArrayBuffer:c,unmask:u}=dt(),{isValidStatusCode:l,isValidUTF8:d}=bt();function h(e,t,s,n,i){const r=new e(s?`Invalid WebSocket frame: ${t}`:t);return Error.captureStackTrace(r,h),r.code=i,r[o]=n,r}return _t=class extends e{constructor(e,t,n,o){super(),this._binaryType=e||s[0],this[i]=void 0,this._extensions=t||{},this._isServer=!!n,this._maxPayload=0|o,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._state=0,this._loop=!1}_write(e,t,s){if(8===this._opcode&&0==this._state)return s();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(s)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];return this._buffers[0]=t.slice(e),t.slice(0,e)}const t=Buffer.allocUnsafe(e);do{const s=this._buffers[0],n=t.length-e;e>=s.length?t.set(this._buffers.shift(),n):(t.set(new Uint8Array(s.buffer,s.byteOffset,e),n),this._buffers[0]=s.slice(e)),e-=s.length}while(e>0);return t}startLoop(e){let t;this._loop=!0;do{switch(this._state){case 0:t=this.getInfo();break;case 1:t=this.getPayloadLength16();break;case 2:t=this.getPayloadLength64();break;case 3:this.getMask();break;case 4:t=this.getData(e);break;default:return void(this._loop=!1)}}while(this._loop);e(t)}getInfo(){if(this._bufferedBytes<2)return void(this._loop=!1);const e=this.consume(2);if(48&e[0])return this._loop=!1,h(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");const s=!(64&~e[0]);if(s&&!this._extensions[t.extensionName])return this._loop=!1,h(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");if(this._fin=!(128&~e[0]),this._opcode=15&e[0],this._payloadLength=127&e[1],0===this._opcode){if(s)return this._loop=!1,h(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");if(!this._fragmented)return this._loop=!1,h(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");this._opcode=this._fragmented}else if(1===this._opcode||2===this._opcode){if(this._fragmented)return this._loop=!1,h(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");this._compressed=s}else{if(!(this._opcode>7&&this._opcode<11))return this._loop=!1,h(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");if(!this._fin)return this._loop=!1,h(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");if(s)return this._loop=!1,h(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");if(this._payloadLength>125)return this._loop=!1,h(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH")}if(this._fin||this._fragmented||(this._fragmented=this._opcode),this._masked=!(128&~e[1]),this._isServer){if(!this._masked)return this._loop=!1,h(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK")}else if(this._masked)return this._loop=!1,h(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");if(126===this._payloadLength)this._state=1;else{if(127!==this._payloadLength)return this.haveLength();this._state=2}}getPayloadLength16(){if(!(this._bufferedBytes<2))return this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength();this._loop=!1}getPayloadLength64(){if(this._bufferedBytes<8)return void(this._loop=!1);const e=this.consume(8),t=e.readUInt32BE(0);return t>Math.pow(2,21)-1?(this._loop=!1,h(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH")):(this._payloadLength=t*Math.pow(2,32)+e.readUInt32BE(4),this.haveLength())}haveLength(){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0))return this._loop=!1,h(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");this._masked?this._state=3:this._state=4}getMask(){this._bufferedBytes<4?this._loop=!1:(this._mask=this.consume(4),this._state=4)}getData(e){let t=n;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength)return void(this._loop=!1);t=this.consume(this._payloadLength),this._masked&&u(t,this._mask)}return this._opcode>7?this.controlMessage(t):this._compressed?(this._state=5,void this.decompress(t,e)):(t.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(t)),this.dataMessage())}decompress(e,s){this._extensions[t.extensionName].decompress(e,this._fin,(e,t)=>{if(e)return s(e);if(t.length){if(this._messageLength+=t.length,this._messageLength>this._maxPayload&&this._maxPayload>0)return s(h(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));this._fragments.push(t)}const n=this.dataMessage();if(n)return s(n);this.startLoop(s)})}dataMessage(){if(this._fin){const e=this._messageLength,t=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],2===this._opcode){let s;s="nodebuffer"===this._binaryType?a(t,e):"arraybuffer"===this._binaryType?c(a(t,e)):t,this.emit("message",s)}else{const s=a(t,e);if(!d(s))return this._loop=!1,h(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");this.emit("message",s.toString())}}this._state=0}controlMessage(e){if(8===this._opcode)if(this._loop=!1,0===e.length)this.emit("conclude",1005,""),this.end();else{if(1===e.length)return h(RangeError,"invalid payload length 1",!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");{const t=e.readUInt16BE(0);if(!l(t))return h(RangeError,`invalid status code ${t}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");const s=e.slice(2);if(!d(s))return h(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");this.emit("conclude",t,s.toString()),this.end()}}else 9===this._opcode?this.emit("ping",e):this.emit("pong",e);this._state=0}}}function Gt(){if(ft)return mt;ft=1;const{randomFillSync:e}=i,t=ht(),{EMPTY_BUFFER:s}=lt(),{isValidStatusCode:n}=bt(),{mask:o,toBuffer:r}=dt(),a=Buffer.alloc(4);class c{constructor(e,t){this._extensions=t||{},this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(t,s){const n=s.mask&&s.readOnly;let i=s.mask?6:2,r=t.length;t.length>=65536?(i+=8,r=127):t.length>125&&(i+=2,r=126);const c=Buffer.allocUnsafe(n?t.length+i:i);return c[0]=s.fin?128|s.opcode:s.opcode,s.rsv1&&(c[0]|=64),c[1]=r,126===r?c.writeUInt16BE(t.length,2):127===r&&(c.writeUInt32BE(0,2),c.writeUInt32BE(t.length,6)),s.mask?(e(a,0,4),c[1]|=128,c[i-4]=a[0],c[i-3]=a[1],c[i-2]=a[2],c[i-1]=a[3],n?(o(t,a,c,i,t.length),[c]):(o(t,a,t,0,t.length),[c,t])):[c,t]}close(e,t,o,i){let r;if(void 0===e)r=s;else{if("number"!=typeof e||!n(e))throw new TypeError("First argument must be a valid error code number");if(void 0===t||""===t)r=Buffer.allocUnsafe(2),r.writeUInt16BE(e,0);else{const s=Buffer.byteLength(t);if(s>123)throw new RangeError("The message must not be greater than 123 bytes");r=Buffer.allocUnsafe(2+s),r.writeUInt16BE(e,0),r.write(t,2)}}this._deflating?this.enqueue([this.doClose,r,o,i]):this.doClose(r,o,i)}doClose(e,t,s){this.sendFrame(c.frame(e,{fin:!0,rsv1:!1,opcode:8,mask:t,readOnly:!1}),s)}ping(e,t,s){const n=r(e);if(n.length>125)throw new RangeError("The data size must not be greater than 125 bytes");this._deflating?this.enqueue([this.doPing,n,t,r.readOnly,s]):this.doPing(n,t,r.readOnly,s)}doPing(e,t,s,n){this.sendFrame(c.frame(e,{fin:!0,rsv1:!1,opcode:9,mask:t,readOnly:s}),n)}pong(e,t,s){const n=r(e);if(n.length>125)throw new RangeError("The data size must not be greater than 125 bytes");this._deflating?this.enqueue([this.doPong,n,t,r.readOnly,s]):this.doPong(n,t,r.readOnly,s)}doPong(e,t,s,n){this.sendFrame(c.frame(e,{fin:!0,rsv1:!1,opcode:10,mask:t,readOnly:s}),n)}send(e,s,n){const o=r(e),i=this._extensions[t.extensionName];let a=s.binary?2:1,u=s.compress;if(this._firstFragment?(this._firstFragment=!1,u&&i&&(u=o.length>=i._threshold),this._compress=u):(u=!1,a=0),s.fin&&(this._firstFragment=!0),i){const e={fin:s.fin,rsv1:u,opcode:a,mask:s.mask,readOnly:r.readOnly};this._deflating?this.enqueue([this.dispatch,o,this._compress,e,n]):this.dispatch(o,this._compress,e,n)}else this.sendFrame(c.frame(o,{fin:s.fin,rsv1:!1,opcode:a,mask:s.mask,readOnly:r.readOnly}),n)}dispatch(e,s,n,o){if(!s)return void this.sendFrame(c.frame(e,n),o);const i=this._extensions[t.extensionName];this._bufferedBytes+=e.length,this._deflating=!0,i.compress(e,n.fin,(t,s)=>{if(this._socket.destroyed){const e=new Error("The socket was closed while data was being compressed");"function"==typeof o&&o(e);for(let t=0;t<this._queue.length;t++){const s=this._queue[t][4];"function"==typeof s&&s(e)}return}this._bufferedBytes-=e.length,this._deflating=!1,n.readOnly=!1,this.sendFrame(c.frame(s,n),o),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){const e=this._queue.shift();this._bufferedBytes-=e[1].length,Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[1].length,this._queue.push(e)}sendFrame(e,t){2===e.length?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],t),this._socket.uncork()):this._socket.write(e[0],t)}}return mt=c}function wt(){if(St)return Et;St=1;const e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function t(e,t,s){void 0===e[t]?e[t]=[s]:e[t].push(s)}return Et={format:function(e){return Object.keys(e).map(t=>{let s=e[t];return Array.isArray(s)||(s=[s]),s.map(e=>[t].concat(Object.keys(e).map(t=>{let s=e[t];return Array.isArray(s)||(s=[s]),s.map(e=>!0===e?t:`${t}=${e}`).join("; ")})).join("; ")).join(", ")}).join(", ")},parse:function(s){const n=Object.create(null);if(void 0===s||""===s)return n;let o,i,r=Object.create(null),a=!1,c=!1,u=!1,l=-1,d=-1,h=0;for(;h<s.length;h++){const p=s.charCodeAt(h);if(void 0===o)if(-1===d&&1===e[p])-1===l&&(l=h);else if(32===p||9===p)-1===d&&-1!==l&&(d=h);else{if(59!==p&&44!==p)throw new SyntaxError(`Unexpected character at index ${h}`);{if(-1===l)throw new SyntaxError(`Unexpected character at index ${h}`);-1===d&&(d=h);const e=s.slice(l,d);44===p?(t(n,e,r),r=Object.create(null)):o=e,l=d=-1}}else if(void 0===i)if(-1===d&&1===e[p])-1===l&&(l=h);else if(32===p||9===p)-1===d&&-1!==l&&(d=h);else if(59===p||44===p){if(-1===l)throw new SyntaxError(`Unexpected character at index ${h}`);-1===d&&(d=h),t(r,s.slice(l,d),!0),44===p&&(t(n,o,r),r=Object.create(null),o=void 0),l=d=-1}else{if(61!==p||-1===l||-1!==d)throw new SyntaxError(`Unexpected character at index ${h}`);i=s.slice(l,h),l=d=-1}else if(c){if(1!==e[p])throw new SyntaxError(`Unexpected character at index ${h}`);-1===l?l=h:a||(a=!0),c=!1}else if(u)if(1===e[p])-1===l&&(l=h);else if(34===p&&-1!==l)u=!1,d=h;else{if(92!==p)throw new SyntaxError(`Unexpected character at index ${h}`);c=!0}else if(34===p&&61===s.charCodeAt(h-1))u=!0;else if(-1===d&&1===e[p])-1===l&&(l=h);else if(-1===l||32!==p&&9!==p){if(59!==p&&44!==p)throw new SyntaxError(`Unexpected character at index ${h}`);{if(-1===l)throw new SyntaxError(`Unexpected character at index ${h}`);-1===d&&(d=h);let e=s.slice(l,d);a&&(e=e.replace(/\\/g,""),a=!1),t(r,i,e),44===p&&(t(n,o,r),r=Object.create(null),o=void 0),i=void 0,l=d=-1}}else-1===d&&(d=h)}if(-1===l||u)throw new SyntaxError("Unexpected end of input");-1===d&&(d=h);const p=s.slice(l,d);return void 0===o?t(n,p,r):(void 0===i?t(r,p,!0):t(r,i,a?p.replace(/\\/g,""):p),t(n,o,r)),n}}}function Pt(){if(yt)return Ct;yt=1;const c=e,u=t,l=s,d=n,h=o,{randomBytes:p,createHash:_}=i,{Readable:g}=r,{URL:m}=a,f=ht(),v=Nt(),I=Gt(),{BINARY_TYPES:E,EMPTY_BUFFER:S,GUID:C,kStatusCode:y,kWebSocket:M,NOOP:T}=lt(),{addEventListener:A,removeEventListener:O}=function(){if(It)return vt;It=1;class e{constructor(e,t){this.target=t,this.type=e}}class t extends e{constructor(e,t){super("message",t),this.data=e}}class s extends e{constructor(e,t,s){super("close",s),this.wasClean=s._closeFrameReceived&&s._closeFrameSent,this.reason=t,this.code=e}}class n extends e{constructor(e){super("open",e)}}class o extends e{constructor(e,t){super("error",t),this.message=e.message,this.error=e}}return vt={addEventListener(e,i,r){if("function"!=typeof i)return;function a(e){i.call(this,new t(e,this))}function c(e,t){i.call(this,new s(e,t,this))}function u(e){i.call(this,new o(e,this))}function l(){i.call(this,new n(this))}const d=r&&r.once?"once":"on";"message"===e?(a._listener=i,this[d](e,a)):"close"===e?(c._listener=i,this[d](e,c)):"error"===e?(u._listener=i,this[d](e,u)):"open"===e?(l._listener=i,this[d](e,l)):this[d](e,i)},removeEventListener(e,t){const s=this.listeners(e);for(let n=0;n<s.length;n++)s[n]!==t&&s[n]._listener!==t||this.removeListener(e,s[n])}}}(),{format:D,parse:R}=wt(),{toBuffer:L}=dt(),b=["CONNECTING","OPEN","CLOSING","CLOSED"],N=[8,13];class G extends c{constructor(e,t,s){super(),this._binaryType=E[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage="",this._closeTimer=null,this._extensions={},this._protocol="",this._readyState=G.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,null!==e?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,Array.isArray(t)?t=t.join(", "):"object"==typeof t&&null!==t&&(s=t,t=void 0),w(this,e,t,s)):this._isServer=!0}get binaryType(){return this._binaryType}set binaryType(e){E.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return t