asai-nodejs-host 0.2.11 → 0.2.12
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/index.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var __webpack_modules__={546:function(e,t,s){var r=this&&this.__assign||function(){r=Object.assign||function(e){for(var t,s=1,r=arguments.length;s<r;s++){t=arguments[s];for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o))e[o]=t[o]}return e};return r.apply(this,arguments)};var o=this&&this.__spreadArray||function(e,t,s){if(s||arguments.length===2)for(var r=0,o=t.length,n;r<o;r++){if(n||!(r in t)){if(!n)n=Array.prototype.slice.call(t,0,r);n[r]=t[r]}}return e.concat(n||Array.prototype.slice.call(t))};e.exports=function(e,t){var n=s(354);var i=t.sysWork,a=t.apiWork,c=t.wsWork,l=t.jsonpWork;function initAsaiHost(){var t,s,r,o;e.setAppend=setAppend;e.getHost=getHostCFG;e.getHostIP=getHostIP;initProcess();initLog();if(!((t=e.hostconfig)===null||t===void 0?void 0:t.ip)){e.hostconfig.ip=getIp()}e.hostconfig.asaiport=[];e.hostconfig.guardtm=null;if(((r=(s=e.hostconfig)===null||s===void 0?void 0:s.aes)===null||r===void 0?void 0:r.lv)&&!((o=e.$lib)===null||o===void 0?void 0:o.aesfns)){var n=e.$lib.AsAES(e),i=n.reqAES,a=n.resAES;e.$lib.aesfns={allaes:e.hostconfig.aes.lv>1,reqAES:i,resAES:a}}}function getHostIP(t){if(t===void 0){t=null}if(t&&typeof t==="string"){return t}else if(e.hostconfig.ip==="asai"){return"localhost"}return e.hostconfig.ip||"127.0.0.1"}function getHostCFG(t){var s=r(r({},e.hostconfig.hosts.default||{}),e.hostconfig.hosts[t]);return s}function getProxyHostCFG(t){var s=r(r({},e.hostconfig.proxyhosts.default||{}),e.hostconfig.proxyhosts[t]);if(!s.url&&s.port){s.url=(s===null||s===void 0?void 0:s.httptype)+getHostIP(s.ip)+":"+(s===null||s===void 0?void 0:s.port)}return s}function setAppend(t){var s=[];for(var r=1;r<arguments.length;r++){s[r-1]=arguments[r]}return new Promise((function(r,o){try{e.asaifs.ensureFile(t).then((function(){var n="";if((s===null||s===void 0?void 0:s[0])===1){s.shift();n=s.join("\n")+"\n"}else{n=s.join(" ").replace(/\n/g," ").replace(/\r/g," ")+"\n"}e.asaifs.append(t,n).then((function(){r()})).catch(o)})).catch(o)}catch(e){console.error(e);o(e)}}))}function initProcess(t){if(t===void 0){t=null}var s=10;var r=6e4;var o=[];process.on("unhandledRejection",(function(t,s){var r;var o=(new Error).stack;var n="";if(s&&typeof s==="object"){n=((r=s.constructor)===null||r===void 0?void 0:r.name)||"Promise";var i=(o===null||o===void 0?void 0:o.split("\n"))||[];var a=i.slice(3,6).join(" | ");n+=" Created at: ".concat(a)}var c="";if(t instanceof Error){c="\n".concat(t.name,": ").concat(t.message);if(t.stack){c+="\n【Stack】".concat(t.stack)}}else if(typeof t==="object"&&t!==null){try{c=JSON.stringify(t,null,2).substring(0,500)}catch(e){c=String(t)}}else{c=String(t)}var l="Unhandled Promise Rejection:\n【Reason】 ".concat(c,"\n【Promise】").concat(n);e.$log("★",l)}));process.on("uncaughtException",(function(n){var i="Uncaught Exception: ".concat(JSON.stringify(n));e.$log("★",i);var a=Date.now();o.push(a);while(o.length>0&&o[0]<a-r){o.shift()}if(o.length>s){e.$log("★","Process crashed too frequently, not restarting.");e.$log("★","Error:",(n===null||n===void 0?void 0:n.message)||n);process.exit(1)}if(t&&typeof t==="function"){try{t(n)}catch(e){console.error("Error in process error callback:",e)}}}));process.on("SIGTERM",(function(){e.$log("★","SIGTERM,CLOSING...");gracefulShutdown()}));process.on("SIGINT",(function(){e.$log("★","SIGINT,CLOSING...");gracefulShutdown()}))}function initLog(){var t,s;if(e&&typeof e==="object"&&((s=(t=e.hostconfig)===null||t===void 0?void 0:t.path)===null||s===void 0?void 0:s.log)){try{e.$log=function(){var t=[];for(var s=0;s<arguments.length;s++){t[s]=arguments[s]}return new Promise((function(s,r){var n,i,a,c,l;try{var f=t[0];if(typeof f==="number"&&f>666){((n=e.hostconfig)===null||n===void 0?void 0:n.log)&&console.log.apply(console,t);s()}else if(f===1){setLog.apply(void 0,o([(((a=(i=e.hostconfig.path)===null||i===void 0?void 0:i.log)===null||a===void 0?void 0:a.client)||"")+"log-".concat(getNowTime(2),".txt")],t,false)).then(s).catch(r)}else{setLog.apply(void 0,o([(((l=(c=e.hostconfig.path)===null||c===void 0?void 0:c.log)===null||l===void 0?void 0:l.server)||"")+"log-".concat(getNowTime(2),".txt"),"【".concat(getNowTime(1),"】")],t,false)).then(s).catch(r)}}catch(e){console.error(e);r(e)}}))}}catch(e){console.error(e)}return}if(typeof e!=="object"){e={}}e.$log=function(){var t;var s=[];for(var r=0;r<arguments.length;r++){s[r]=arguments[r]}((t=e.hostconfig)===null||t===void 0?void 0:t.log)&&console.log.apply(console,s)}}function gracefulShutdown(){var t=6e4;var s;var r=Date.now();s=setTimeout((function(){e.$log("★","Timeout! Exiting after ".concat(Date.now()-r,"ms"));process.exit(1)}),t);try{Object.values(e.servershttp||{}).forEach((function(t){if(t&&typeof t.close==="function"){t.close((function(t){if(t){e.$log("★","HTTP server close error:",t)}}))}}));Object.values(e.serversws||{}).forEach((function(t){if(t&&typeof t.close==="function"){t.close((function(t){if(t){e.$log("★","WS server close error:",t)}}))}}));if(e.hostconfig.guardtm){clearTimeout(e.hostconfig.guardtm);e.hostconfig.guardtm=null}Object.keys(e.tasksws||{}).forEach((function(t){if(e.tasksws[t].httpMonitor){clearInterval(e.tasksws[t].httpMonitor);delete e.tasksws[t].httpMonitor}}));setTimeout((function(){clearTimeout(s);e.$log("★","Web Server Closed (".concat(Date.now()-r,"ms)"));process.exit(0)}),3e3)}catch(t){e.$log("★","Graceful shutdown error:",t);clearTimeout(s);process.exit(1)}}function setLog(t){var s=[];for(var r=1;r<arguments.length;r++){s[r-1]=arguments[r]}return new Promise((function(r,n){var i;try{((i=e.hostconfig)===null||i===void 0?void 0:i.log)&&console.log.apply(console,s);setAppend.apply(void 0,o([t],s,false)).then((function(){r()})).catch(n)}catch(e){console.error(e);n(e)}}))}function startHTTPServer(t){var n,c,f,h,u;var d=getHostCFG(t);if(d&&!(d===null||d===void 0?void 0:d.close)){try{if(!e.servershttp[t]){if("mimetypes"in d){d.mimetypes=r(r({},e.hostconfig.mimetypes||{}),d.mimetypes||{})}var p=getHTTPServer(d===null||d===void 0?void 0:d.httptype,d);var _=((n=d.weburls)===null||n===void 0?void 0:n.rewrite)&&((c=d.weburls)===null||c===void 0?void 0:c.webdir)&&((h=(f=d.weburls)===null||f===void 0?void 0:f.keys)===null||h===void 0?void 0:h.length);var v=o([((u=d.weburls)===null||u===void 0?void 0:u.webdir)||""],d.hostdirs||[],true).filter((function(e){return e}));var g=!!v.length;e.servershttp[t]=p.AsCreateServer((function(r,o){try{if(checkHttpHeader(r)){if(r.url.startsWith("/sys")){i(r,o,t)}else if(r.url.startsWith("/api")){a(r,o,t)}else if(r.url.startsWith("/jsonp")){l(r,o,t)}else if(g){o.setHeader("Cross-Origin-Resource-Policy","cross-origin");o.setHeader("Cross-Origin-Opener-Policy","cross-origin");if(checkWebUrls(r.url)){showHostDirs([d.weburls.webdir],"/"+e.hostconfig.index)}else{showHostDirs(v,r.url)}function checkWebUrls(e){var t,s,r;console.log(666.0055,e);if(_&&typeof e==="string"&&e){return(r=(s=(t=d.weburls)===null||t===void 0?void 0:t.keys)===null||s===void 0?void 0:s.some)===null||r===void 0?void 0:r.call(s,(function(t){return e.startsWith(t)}))}return false}function showHostDirs(t,r,n){var i;if(n===void 0){n=0}var a=s(896);var c=s(928);var l=parseUrlPath(r);var findValidFile=function(t,r){var o,n;for(var i=0,a=t;i<a.length;i++){var l=a[i];var f="./"+l+r;if(r.endsWith("/")){f=f+(e.hostconfig.index||"index.html")}if(((n=(o=e.hostconfig)===null||o===void 0?void 0:o.pkg)===null||n===void 0?void 0:n.type)==1){var h=s.ab+"asai-nodejs-host/"+l+"\\"+r;console.log(666.888888,h);if(checkFileExists(h)){return h}}var u=c.normalize(f);if(u.includes(".."))continue;if(checkFileExists(u)){return u}}return null};var f=l.endsWith("/")?l+(e.hostconfig.index||"index.html"):l;var h=findValidFile(t,f);if(!h){if(n>0||!_){o.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"});o.end("File not found!");return}else{var u=[d.weburls.webdir];var p="/"+e.hostconfig.index;showHostDirs(u,p,n+1);return}}var v;try{v=a.statSync(h)}catch(t){e.$log("●","File stat error:",t);if(!o.headersSent){o.writeHead(500,{"Content-Type":"text/plain; charset=utf-8"});o.end("Internal Server Error")}else{o.destroy()}return}var g=((i=d.mimetypes)===null||i===void 0?void 0:i[c.extname(h)])||"application/octet-stream";var m=a.createReadStream(h);m.once("open",(function(){o.writeHead(200,{"Content-Type":g,"Content-Length":v.size,"Cache-Control":"public, max-age=3600"});m.pipe(o)}));m.once("error",(function(t){e.$log("●","Stream error:",t);if(!o.headersSent){o.writeHead(500,{"Content-Type":"text/plain; charset=utf-8"});o.end("Internal Server Error")}else{o.destroy()}}));o.once("close",(function(){if(!m.destroyed){m.destroy()}}))}function checkFileExists(e){var t=s(896);try{var r=t.statSync(e);return r.isFile()&&r.mode&t.constants.R_OK}catch(e){return false}}function parseUrlPath(e){try{if(!e)return"/";var t=e.startsWith("http")?undefined:"http://localhost";return new URL(e,t).pathname}catch(t){return e}}}else{o.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"});o.end("404")}}else{o.writeHead(502,{"Content-Type":"text/plain; charset=utf-8"});o.end("502")}}catch(n){if(!o.headersSent){o.writeHead(500,{"Content-Type":"text/plain; charset=utf-8"})}o.end("Internal server error");e.$log("★","HTTP request error:",n)}}));d.ws&&createWSHost(t);e.servershttp[t].on("error",(function(t){e.hostconfig.asaiport.push(d.port);asaiGuard();if(t.code==="EADDRINUSE"){e.$log("★","[41mPort ".concat(d.port," is already start![0m"))}else{e.$log("★","Server error:",t)}}));if(e.hostconfig.ip==="asai"||!d.ip&&!e.hostconfig.ip){e.servershttp[t].listen(d.port,(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));d.ws&&console.log("[41;28mWS Server ".concat(d.wstype,"localhost:").concat(d.port,"[0m"));console.log("[42;28mHTTP Server ".concat(d.httptype,"localhost:").concat(d.port,"[0m"));console.log("================================================")}))}else{e.servershttp[t].listen(d.port,getHostIP(d.ip),(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));d.ws&&console.log("[44;28mWS Server ".concat(d.wstype+getHostIP(d.ip),":").concat(d.port,"[0m"));console.log("[42;28mHTTP Server ".concat(d.httptype+getHostIP(d.ip),":").concat(d.port,"[0m"));console.log("================================================")}))}}}catch(t){e.$log("●","Http server error:",JSON.stringify(t))}if(d.ckhttp){var m=d.maxhttp||100;var y=setInterval((function(){var s;var r=((s=e.connectionshttp[t])===null||s===void 0?void 0:s.size)||0;if(r>m*.8){e.$log("★","HTTP Connection HIGH (".concat(r,"/").concat(m,")"))}if(r>m*.95){e.$log("★","HTTP Connection CRITICAL! Forcing cleanup");if(e.connectionshttp[t]){e.connectionshttp[t].forEach((function(e){if(e._idleTime&&Date.now()-e._idleTime>3e5){e.destroy()}}))}}}),18e5);if(!e.tasksws[t]){e.tasksws[t]={}}e.tasksws[t].httpMonitor=y;e.servershttp[t].on("connection",(function(s){var r;if(!e.connectionshttp[t]){e.connectionshttp[t]=new Set}var o=((r=e.connectionshttp[t])===null||r===void 0?void 0:r.size)||0;if(o>=m){try{e.$log("★","HTTP Connection MAX rejected (".concat(o,"/").concat(m,")"));s.destroy()}catch(t){e.$log("★","Close connection error:",t)}return}e.connectionshttp[t].add(s);s.on("close",(function(){e.connectionshttp[t].delete(s)}));s.setTimeout(3e5)}))}return e.servershttp[t]}return}function getHTTPServer(t,r){if(t===void 0){t=""}if(r===void 0){r={}}var o=s(611);var n=s(692);try{if(t.startsWith("https")){n.AsCreateServer=function(t){return n.createServer((r===null||r===void 0?void 0:r.httpscert)||e.hostconfig.httpscert,t)};return n}else{o.AsCreateServer=o.createServer;return o}}catch(t){e.$log("●","Http server error:",JSON.stringify(t));o.AsCreateServer=o.createServer;return o}}function startProxyServer(t){var s=getProxyHostCFG(t);if(s.url){try{var r=getHTTPServer(s.proxyhttptype,s);var o=r.AsCreateServer((function(t,r){if(s.redirect){r.writeHead(301,{Location:s.url+t.url,"Strict-Transport-Security":"max-age=31536000"});r.end()}else{var o=new URL(s.url+t.url);var n=o.protocol==="https:";var i=getHTTPServer(s.url,s);var a={keepAlive:s.keepAlive||true,timeout:s.timeout||6e4,keepAliveMsecs:s.keepAliveMsecs||3e4,maxSockets:s.maxSockets||1e3,maxFreeSockets:s.maxFreeSockets||100,rejectUnauthorized:s.rejectUnauthorized||false,secureProtocol:s.secureProtocol||"TLS_method"};var c=new i.Agent(a);var l={agent:c,method:t.method,hostname:o.hostname,port:o.port||(n?443:80),path:o.pathname+o.search,headers:t.headers};if(n){l.servername=o.hostname}var f=i.request(l,(function(e){Object.keys(e.headers).forEach((function(t){var s=["transfer-encoding","connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailers","upgrade"];if(!s.includes(t.toLowerCase())){r.setHeader(t,e.headers[t])}}));r.statusCode=e.statusCode;var s=getHttpUserinfo(t);s&&r.setHeader("Userinfo",s);e.pipe(r,{end:true})}));t.pipe(f,{end:true});t.on("error",(function(t){e.$log("●","Client request error:",t);f.destroy()}));f.on("error",(function(t){e.$log("●","Forward request error:",t);e.$log("●","Target: ".concat(o.href,", HTTPS: ").concat(n));if(!r.headersSent){r.writeHead(502,{"Content-Type":"text/plain; charset=utf-8"})}r.end("Bad Gateway: "+t.message)}));f.setTimeout(12e4,(function(){e.$log("★","Forward request timeout");f.destroy();if(!r.headersSent){r.writeHead(504,{"Content-Type":"text/plain; charset=utf-8"})}r.end("Gateway Timeout")}))}}));o.on("error",(function(t){if(t.code==="EADDRINUSE"){e.$log("★","[41mPort ".concat(s.proxyport," is already start![0m"))}else{e.$log("★","Proxy server error:",t)}}));var n=getHostIP(s.proxyip);if(n){o.listen(s.proxyport,n,(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));console.log("[45;28mProxy Server ".concat(s.proxyhttptype).concat(n,":").concat(s.proxyport,"[0m"));console.log("[46;28mTarget Server ".concat(s.url,"[0m"));console.log("================================================")}))}else{o.listen(s.proxyport,(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));console.log("[45;28mProxy server ".concat(s.proxyhttptype,"localhost:").concat(s.proxyport,"[0m"));console.log("[46;28mTarget Server ".concat(s.url,"[0m"));console.log("================================================")}))}}catch(t){e.$log("●","Proxy server error:",JSON.stringify(t))}}}function asaiGuard(){var t;if(e.hostconfig.asaiport.includes(e.hostconfig.hosts.asai.port)){process.exit(1)}else{if(e.hostconfig.guardtm){clearTimeout(e.hostconfig.guardtm);e.hostconfig.guardtm=null}e.hostconfig.guardtm=setTimeout((function(){startHTTPServer("asai");clearTimeout(e.hostconfig.guardtm);e.hostconfig.guardtm=null}),((t=e.hostconfig.tm)===null||t===void 0?void 0:t.d)||2e3)}}function getWsUserinfo(e){var t;try{var s=Object.fromEntries(Array.from({length:e.rawHeaders.length/2},(function(t,s){return[e.rawHeaders[s*2].toLowerCase(),e.rawHeaders[s*2+1]]})));var r=(t=s["sec-websocket-protocol"])===null||t===void 0?void 0:t.split("##");return deUserInfo(r)}catch(e){}return null}function getHttpUserinfo(e){var t;try{var s=Object.fromEntries(Array.from({length:e.rawHeaders.length/2},(function(t,s){return[e.rawHeaders[s*2].toLowerCase(),e.rawHeaders[s*2+1]]})));var r=(t=s["userinfo"])===null||t===void 0?void 0:t.split("##");return deUserInfo(r)}catch(e){}return""}function checkHttpHeader(e){e.Userinfo=getHttpUserinfo(e);return true}function deUserInfo(t){if(!Array.isArray(t)||t.length<3){return t}if(t[2]){try{t[2]=e.$lib.AsCode.asdecode(t[2],e.hostconfig.asaisn);t[0]=e.$lib.AsCode.asdecode(t[0],t[2]);t[1]=e.$lib.AsCode.asdecode(t[1],t[2])}catch(t){e.$log("●","User info decode error:",t)}}return t}function clearWsServerTasks(t){if(e.tasksws[t]&&typeof e.tasksws[t]==="object"){Object.values(e.tasksws[t]).forEach((function(e){e&&clearInterval(e)}));e.tasksws[t]={}}}function _resWsMsg(t){var s,r,o;if(t==="ping"||t==="pong"){}else if(typeof t==="object"){if(((t===null||t===void 0?void 0:t.aes)||((s=e.$lib.aesfns)===null||s===void 0?void 0:s.allaes))&&(t===null||t===void 0?void 0:t.db)&&((o=(r=e.$lib)===null||r===void 0?void 0:r.aesfns)===null||o===void 0?void 0:o.resAES)){t.db=e.$lib.aesfns.resAES(t.db)}t=JSON.stringify(t)}return t}function createWSHost(t){var r=getHostCFG(t);try{if(!e.serversws[t]){var o=s(354),n=o.WebSocket,i=o.WebSocketServer;if(r.ckws){if(!e.connectionsws[t]){e.connectionsws[t]=new WeakMap}}if(!e.tasksws[t]){e.tasksws[t]={}}e.serversws[t]=new i({server:e.servershttp[t],perMessageDeflate:false});e.serversws[t].sendws=function(s,r,o){s=_resWsMsg(s);if(r){e.serversws[t].clients.forEach((function(e){if((r==2||e!==o)&&e.readyState==n.OPEN){e.send(s)}}))}else{o.send(s)}};e.serversws[t].broadws=function(s){var r,o;s=_resWsMsg(s);(o=(r=e.serversws[t])===null||r===void 0?void 0:r.clients)===null||o===void 0?void 0:o.forEach((function(e){var t;if(e&&(e===null||e===void 0?void 0:e.readyState)==(n===null||n===void 0?void 0:n.OPEN)&&typeof(e===null||e===void 0?void 0:e.send)==="function"){(t=e===null||e===void 0?void 0:e.send)===null||t===void 0?void 0:t.call(e,s)}}))};e.serversws[t].on("error",(function(s){clearWsServerTasks(t);e.$log("●","WS Server error!",s);if(typeof e.serversws[t].close==="function"){e.serversws[t].close((function(){e.$log("●","WS Server closed");delete e.serversws[t]}))}}));e.serversws[t].on("close",(function(s,r){try{e.$log("●","WebSocket closed, server ".concat(t,", code: ").concat(s,", reason: ").concat(r));clearWsServerTasks(t)}catch(t){e.$log("★","WS close handler error:",t)}}));e.serversws[t].on("connection",(function(s,o){var n=r.maxws||100;var i=Object.keys(e.connectionsws[t]||{}).length;if(i>=n){e.$log("★","WS Connection MAX rejected (".concat(i,"/").concat(n,")"));s.send(JSON.stringify({ty:"publish/web",db:{exit:1,type:"err",lang:"maxws",langpm:"".concat(n),con:"max ".concat(n," clients online!")}}));s.close(1013,"Server busy");return}o.Userinfo=getWsUserinfo(o)||[];s.Userinfo=o.Userinfo;var a=true;if(r.ckws){a=isOkWs(t,s,o)}if(a){loginWs(t,s,o)}else{s.close()}}))}}catch(t){e.$log("●","ws server:",JSON.stringify(t))}return e.serversws[t]}function isOkWs(t,s,r){var o,n;var i=getHostCFG(t);var a=s.Userinfo,c=a[0],l=a[1],f=a[2];if(c){if(c==="asai"){}else if(e.connectionsws[t][c]){var h={ty:"publish/web",db:{exit:1,type:"err",lang:"logged",langpm:"".concat(c),con:"".concat(c," logged in!")}};checkWsIsOn(e.connectionsws[t][c]);if(((n=(o=e.connectionsws[t][c])===null||o===void 0?void 0:o.Userinfo)===null||n===void 0?void 0:n[2])===f){h.db.lang="loggedsametk";s.send(JSON.stringify(h));e.connectionsws[t][c].send(JSON.stringify(h));e.connectionsws[t][c].close()}else{s.send(JSON.stringify(h))}return false}else{var u=Object.values(e.connectionsws[t]).find((function(e){var t;return((t=e.Userinfo)===null||t===void 0?void 0:t[2])===f}));var d=i.maxonline||100;if(u){var h={ty:"publish/web",db:{exit:1,type:"err",lang:"loggedsametk",langpm:"".concat(c,"(").concat(u.Userinfo[0],")"),con:"".concat(c,"(").concat(u.Userinfo[0],") logged in!")}};s.send(JSON.stringify(h));u.send(JSON.stringify(h));u.close();return false}else if(Object.keys(e.connectionsws[t]).length>=d){s.send(JSON.stringify({ty:"publish/web",db:{exit:1,type:"err",lang:"maxlogged",langpm:"".concat(d),con:"max ".concat(d," users online!")}}));return false}}}else{s.send(JSON.stringify({ty:"publish/web",db:{exit:1,type:"err",lang:"nousername",con:"no username!"}}));return false}return true}function checkWsIsOn(t){var s,r;if(t){try{t.send(JSON.stringify({ty:"publish/web",db:"pong"}));var o=setTimeout((function(){if(typeof t.terminate==="function"){t.terminate()}if(typeof t.close==="function"){t.close()}}),((r=(s=e===null||e===void 0?void 0:e.hostconfig)===null||s===void 0?void 0:s.tm)===null||r===void 0?void 0:r.d)||3e3);if(typeof t.once==="function"){t.once("message",(function(e){if(o){clearTimeout(o);o=null}}))}}catch(e){}}}function loginWs(t,s,r){var o=s.Userinfo,n=o[0],i=o[1],a=o[2];var l=getHostCFG(t);if(l.ckws&&n){if(!(s===null||s===void 0?void 0:s.tasksws)){s.tasksws={}}e.connectionsws[t][n]=s}s.on("message",(function(e){c(e,s,t,r)}));s.on("close",(function(r){if(l.ckws){if(s.tasksws&&typeof s.tasksws==="object"){Object.values(s.tasksws).forEach((function(e){e&&clearInterval(e)}));s.tasksws=null}if(n&&e.connectionsws[t][n]){delete e.connectionsws[t][n]}}typeof s.close=="function"&&s.close()}))}function getNowTime(e){if(e===void 0){e=0}try{var t=new Date(Date.now());var s=t.getFullYear();var r=String(t.getMonth()+1).padStart(2,"0");var o=String(t.getDate()).padStart(2,"0");var n=String(t.getHours()).padStart(2,"0");var i=String(t.getMinutes()).padStart(2,"0");var a=String(t.getSeconds()).padStart(2,"0");if(e==2){return"".concat(s,"-").concat(r,"-").concat(o)}else if(e==1){return"".concat(n,":").concat(i,":").concat(a)}return"".concat(s,"-").concat(r,"-").concat(o," ").concat(n,":").concat(i,":").concat(a)}catch(e){console.error("Date formatting error:",e);return"unknown-time"}}function getIp(){try{var t=s(857);var r=t.networkInterfaces();for(var o in r){var n=r[o];if(!n)continue;for(var i=0,a=n;i<a.length;i++){var c=a[i];if(c.family==="IPv4"&&c.address!=="127.0.0.1"&&!c.internal){return c.address}}}}catch(t){e.$log("●","Get IP address error:",t)}return"127.0.0.1"}function validateHostdir(e){if(typeof e!=="string"||e.length===0||e.length>100||e==="default"||e==="asai"){return false}return/^[a-zA-Z0-9_-]+$/.test(e)}function StartAsaiHost(){var t,s;initAsaiHost();console.log("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");if((t=e.hostconfig)===null||t===void 0?void 0:t.hosts){e.startHTTPServer=startHTTPServer;Object.keys(e.hostconfig.hosts).forEach((function(e){if(validateHostdir(e)){startHTTPServer(e)}}))}if((s=e.hostconfig)===null||s===void 0?void 0:s.proxyhosts){Object.keys(e.hostconfig.proxyhosts).forEach((function(e){if(validateHostdir(e)){startProxyServer(e)}}))}}return{StartAsaiHost:StartAsaiHost,asaiWs:n}}},354:(e,t,s)=>{"use strict";const r=s(681);r.createWebSocketStream=s(412);r.Server=s(129);r.Receiver=s(893);r.Sender=s(389);r.WebSocket=r;r.WebSocketServer=r.Server;e.exports=r},803:(e,t,s)=>{"use strict";const{EMPTY_BUFFER:r}=s(791);const o=Buffer[Symbol.species];function concat(e,t){if(e.length===0)return r;if(e.length===1)return e[0];const s=Buffer.allocUnsafe(t);let n=0;for(let t=0;t<e.length;t++){const r=e[t];s.set(r,n);n+=r.length}if(n<t){return new o(s.buffer,s.byteOffset,n)}return s}function _mask(e,t,s,r,o){for(let n=0;n<o;n++){s[r+n]=e[n]^t[n&3]}}function _unmask(e,t){for(let s=0;s<e.length;s++){e[s]^=t[s&3]}}function toArrayBuffer(e){if(e.length===e.buffer.byteLength){return e.buffer}return e.buffer.slice(e.byteOffset,e.byteOffset+e.length)}function toBuffer(e){toBuffer.readOnly=true;if(Buffer.isBuffer(e))return e;let t;if(e instanceof ArrayBuffer){t=new o(e)}else if(ArrayBuffer.isView(e)){t=new o(e.buffer,e.byteOffset,e.byteLength)}else{t=Buffer.from(e);toBuffer.readOnly=false}return t}e.exports={concat:concat,mask:_mask,toArrayBuffer:toArrayBuffer,toBuffer:toBuffer,unmask:_unmask};if(!process.env.WS_NO_BUFFER_UTIL){try{const t=s(327);e.exports.mask=function(e,s,r,o,n){if(n<48)_mask(e,s,r,o,n);else t.mask(e,s,r,o,n)};e.exports.unmask=function(e,s){if(e.length<32)_unmask(e,s);else t.unmask(e,s)}}catch(e){}}},791:e=>{"use strict";const t=["nodebuffer","arraybuffer","fragments"];const s=typeof Blob!=="undefined";if(s)t.push("blob");e.exports={BINARY_TYPES:t,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:s,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}},634:(e,t,s)=>{"use strict";const{kForOnEventAttribute:r,kListener:o}=s(791);const n=Symbol("kCode");const i=Symbol("kData");const a=Symbol("kError");const c=Symbol("kMessage");const l=Symbol("kReason");const f=Symbol("kTarget");const h=Symbol("kType");const u=Symbol("kWasClean");class Event{constructor(e){this[f]=null;this[h]=e}get target(){return this[f]}get type(){return this[h]}}Object.defineProperty(Event.prototype,"target",{enumerable:true});Object.defineProperty(Event.prototype,"type",{enumerable:true});class CloseEvent extends Event{constructor(e,t={}){super(e);this[n]=t.code===undefined?0:t.code;this[l]=t.reason===undefined?"":t.reason;this[u]=t.wasClean===undefined?false:t.wasClean}get code(){return this[n]}get reason(){return this[l]}get wasClean(){return this[u]}}Object.defineProperty(CloseEvent.prototype,"code",{enumerable:true});Object.defineProperty(CloseEvent.prototype,"reason",{enumerable:true});Object.defineProperty(CloseEvent.prototype,"wasClean",{enumerable:true});class ErrorEvent extends Event{constructor(e,t={}){super(e);this[a]=t.error===undefined?null:t.error;this[c]=t.message===undefined?"":t.message}get error(){return this[a]}get message(){return this[c]}}Object.defineProperty(ErrorEvent.prototype,"error",{enumerable:true});Object.defineProperty(ErrorEvent.prototype,"message",{enumerable:true});class MessageEvent extends Event{constructor(e,t={}){super(e);this[i]=t.data===undefined?null:t.data}get data(){return this[i]}}Object.defineProperty(MessageEvent.prototype,"data",{enumerable:true});const d={addEventListener(e,t,s={}){for(const n of this.listeners(e)){if(!s[r]&&n[o]===t&&!n[r]){return}}let n;if(e==="message"){n=function onMessage(e,s){const r=new MessageEvent("message",{data:s?e:e.toString()});r[f]=this;callListener(t,this,r)}}else if(e==="close"){n=function onClose(e,s){const r=new CloseEvent("close",{code:e,reason:s.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[f]=this;callListener(t,this,r)}}else if(e==="error"){n=function onError(e){const s=new ErrorEvent("error",{error:e,message:e.message});s[f]=this;callListener(t,this,s)}}else if(e==="open"){n=function onOpen(){const e=new Event("open");e[f]=this;callListener(t,this,e)}}else{return}n[r]=!!s[r];n[o]=t;if(s.once){this.once(e,n)}else{this.on(e,n)}},removeEventListener(e,t){for(const s of this.listeners(e)){if(s[o]===t&&!s[r]){this.removeListener(e,s);break}}}};e.exports={CloseEvent:CloseEvent,ErrorEvent:ErrorEvent,Event:Event,EventTarget:d,MessageEvent:MessageEvent};function callListener(e,t,s){if(typeof e==="object"&&e.handleEvent){e.handleEvent.call(e,s)}else{e.call(t,s)}}},335:(e,t,s)=>{"use strict";const{tokenChars:r}=s(615);function push(e,t,s){if(e[t]===undefined)e[t]=[s];else e[t].push(s)}function parse(e){const t=Object.create(null);let s=Object.create(null);let o=false;let n=false;let i=false;let a;let c;let l=-1;let f=-1;let h=-1;let u=0;for(;u<e.length;u++){f=e.charCodeAt(u);if(a===undefined){if(h===-1&&r[f]===1){if(l===-1)l=u}else if(u!==0&&(f===32||f===9)){if(h===-1&&l!==-1)h=u}else if(f===59||f===44){if(l===-1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(h===-1)h=u;const r=e.slice(l,h);if(f===44){push(t,r,s);s=Object.create(null)}else{a=r}l=h=-1}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}else if(c===undefined){if(h===-1&&r[f]===1){if(l===-1)l=u}else if(f===32||f===9){if(h===-1&&l!==-1)h=u}else if(f===59||f===44){if(l===-1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(h===-1)h=u;push(s,e.slice(l,h),true);if(f===44){push(t,a,s);s=Object.create(null);a=undefined}l=h=-1}else if(f===61&&l!==-1&&h===-1){c=e.slice(l,u);l=h=-1}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}else{if(n){if(r[f]!==1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(l===-1)l=u;else if(!o)o=true;n=false}else if(i){if(r[f]===1){if(l===-1)l=u}else if(f===34&&l!==-1){i=false;h=u}else if(f===92){n=true}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}else if(f===34&&e.charCodeAt(u-1)===61){i=true}else if(h===-1&&r[f]===1){if(l===-1)l=u}else if(l!==-1&&(f===32||f===9)){if(h===-1)h=u}else if(f===59||f===44){if(l===-1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(h===-1)h=u;let r=e.slice(l,h);if(o){r=r.replace(/\\/g,"");o=false}push(s,c,r);if(f===44){push(t,a,s);s=Object.create(null);a=undefined}c=undefined;l=h=-1}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}}if(l===-1||i||f===32||f===9){throw new SyntaxError("Unexpected end of input")}if(h===-1)h=u;const d=e.slice(l,h);if(a===undefined){push(t,d,s)}else{if(c===undefined){push(s,d,true)}else if(o){push(s,c,d.replace(/\\/g,""))}else{push(s,c,d)}push(t,a,s)}return t}function format(e){return Object.keys(e).map((t=>{let s=e[t];if(!Array.isArray(s))s=[s];return s.map((e=>[t].concat(Object.keys(e).map((t=>{let s=e[t];if(!Array.isArray(s))s=[s];return s.map((e=>e===true?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")}e.exports={format:format,parse:parse}},958:e=>{"use strict";const t=Symbol("kDone");const s=Symbol("kRun");class Limiter{constructor(e){this[t]=()=>{this.pending--;this[s]()};this.concurrency=e||Infinity;this.jobs=[];this.pending=0}add(e){this.jobs.push(e);this[s]()}[s](){if(this.pending===this.concurrency)return;if(this.jobs.length){const e=this.jobs.shift();this.pending++;e(this[t])}}}e.exports=Limiter},376:(e,t,s)=>{"use strict";const r=s(106);const o=s(803);const n=s(958);const{kStatusCode:i}=s(791);const a=Buffer[Symbol.species];const c=Buffer.from([0,0,255,255]);const l=Symbol("permessage-deflate");const f=Symbol("total-length");const h=Symbol("callback");const u=Symbol("buffers");const d=Symbol("error");let p;class PerMessageDeflate{constructor(e,t,s){this._maxPayload=s|0;this._options=e||{};this._threshold=this._options.threshold!==undefined?this._options.threshold:1024;this._isServer=!!t;this._deflate=null;this._inflate=null;this.params=null;if(!p){const e=this._options.concurrencyLimit!==undefined?this._options.concurrencyLimit:10;p=new n(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};if(this._options.serverNoContextTakeover){e.server_no_context_takeover=true}if(this._options.clientNoContextTakeover){e.client_no_context_takeover=true}if(this._options.serverMaxWindowBits){e.server_max_window_bits=this._options.serverMaxWindowBits}if(this._options.clientMaxWindowBits){e.client_max_window_bits=this._options.clientMaxWindowBits}else if(this._options.clientMaxWindowBits==null){e.client_max_window_bits=true}return e}accept(e){e=this.normalizeParams(e);this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e);return this.params}cleanup(){if(this._inflate){this._inflate.close();this._inflate=null}if(this._deflate){const e=this._deflate[h];this._deflate.close();this._deflate=null;if(e){e(new Error("The deflate stream was closed while data was being processed"))}}}acceptAsServer(e){const t=this._options;const s=e.find((e=>{if(t.serverNoContextTakeover===false&&e.server_no_context_takeover||e.server_max_window_bits&&(t.serverMaxWindowBits===false||typeof t.serverMaxWindowBits==="number"&&t.serverMaxWindowBits>e.server_max_window_bits)||typeof t.clientMaxWindowBits==="number"&&!e.client_max_window_bits){return false}return true}));if(!s){throw new Error("None of the extension offers can be accepted")}if(t.serverNoContextTakeover){s.server_no_context_takeover=true}if(t.clientNoContextTakeover){s.client_no_context_takeover=true}if(typeof t.serverMaxWindowBits==="number"){s.server_max_window_bits=t.serverMaxWindowBits}if(typeof t.clientMaxWindowBits==="number"){s.client_max_window_bits=t.clientMaxWindowBits}else if(s.client_max_window_bits===true||t.clientMaxWindowBits===false){delete s.client_max_window_bits}return s}acceptAsClient(e){const t=e[0];if(this._options.clientNoContextTakeover===false&&t.client_no_context_takeover){throw new Error('Unexpected parameter "client_no_context_takeover"')}if(!t.client_max_window_bits){if(typeof this._options.clientMaxWindowBits==="number"){t.client_max_window_bits=this._options.clientMaxWindowBits}}else if(this._options.clientMaxWindowBits===false||typeof this._options.clientMaxWindowBits==="number"&&t.client_max_window_bits>this._options.clientMaxWindowBits){throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}return t}normalizeParams(e){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`)}s=s[0];if(t==="client_max_window_bits"){if(s!==true){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(t==="server_max_window_bits"){const e=+s;if(!Number.isInteger(e)||e<8||e>15){throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}s=e}else if(t==="client_no_context_takeover"||t==="server_no_context_takeover"){if(s!==true){throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}}else{throw new Error(`Unknown parameter "${t}"`)}e[t]=s}))}));return e}decompress(e,t,s){p.add((r=>{this._decompress(e,t,((e,t)=>{r();s(e,t)}))}))}compress(e,t,s){p.add((r=>{this._compress(e,t,((e,t)=>{r();s(e,t)}))}))}_decompress(e,t,s){const n=this._isServer?"client":"server";if(!this._inflate){const e=`${n}_max_window_bits`;const t=typeof this.params[e]!=="number"?r.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=r.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t});this._inflate[l]=this;this._inflate[f]=0;this._inflate[u]=[];this._inflate.on("error",inflateOnError);this._inflate.on("data",inflateOnData)}this._inflate[h]=s;this._inflate.write(e);if(t)this._inflate.write(c);this._inflate.flush((()=>{const e=this._inflate[d];if(e){this._inflate.close();this._inflate=null;s(e);return}const r=o.concat(this._inflate[u],this._inflate[f]);if(this._inflate._readableState.endEmitted){this._inflate.close();this._inflate=null}else{this._inflate[f]=0;this._inflate[u]=[];if(t&&this.params[`${n}_no_context_takeover`]){this._inflate.reset()}}s(null,r)}))}_compress(e,t,s){const n=this._isServer?"server":"client";if(!this._deflate){const e=`${n}_max_window_bits`;const t=typeof this.params[e]!=="number"?r.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=r.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t});this._deflate[f]=0;this._deflate[u]=[];this._deflate.on("data",deflateOnData)}this._deflate[h]=s;this._deflate.write(e);this._deflate.flush(r.Z_SYNC_FLUSH,(()=>{if(!this._deflate){return}let e=o.concat(this._deflate[u],this._deflate[f]);if(t){e=new a(e.buffer,e.byteOffset,e.length-4)}this._deflate[h]=null;this._deflate[f]=0;this._deflate[u]=[];if(t&&this.params[`${n}_no_context_takeover`]){this._deflate.reset()}s(null,e)}))}}e.exports=PerMessageDeflate;function deflateOnData(e){this[u].push(e);this[f]+=e.length}function inflateOnData(e){this[f]+=e.length;if(this[l]._maxPayload<1||this[f]<=this[l]._maxPayload){this[u].push(e);return}this[d]=new RangeError("Max payload size exceeded");this[d].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";this[d][i]=1009;this.removeListener("data",inflateOnData);this.reset()}function inflateOnError(e){this[l]._inflate=null;if(this[d]){this[h](this[d]);return}e[i]=1007;this[h](e)}},893:(e,t,s)=>{"use strict";const{Writable:r}=s(203);const o=s(376);const{BINARY_TYPES:n,EMPTY_BUFFER:i,kStatusCode:a,kWebSocket:c}=s(791);const{concat:l,toArrayBuffer:f,unmask:h}=s(803);const{isValidStatusCode:u,isValidUTF8:d}=s(615);const p=Buffer[Symbol.species];const _=0;const v=1;const g=2;const m=3;const y=4;const b=5;const S=6;class Receiver extends r{constructor(e={}){super();this._allowSynchronousEvents=e.allowSynchronousEvents!==undefined?e.allowSynchronousEvents:true;this._binaryType=e.binaryType||n[0];this._extensions=e.extensions||{};this._isServer=!!e.isServer;this._maxPayload=e.maxPayload|0;this._skipUTF8Validation=!!e.skipUTF8Validation;this[c]=undefined;this._bufferedBytes=0;this._buffers=[];this._compressed=false;this._payloadLength=0;this._mask=undefined;this._fragmented=0;this._masked=false;this._fin=false;this._opcode=0;this._totalPayloadLength=0;this._messageLength=0;this._fragments=[];this._errored=false;this._loop=false;this._state=_}_write(e,t,s){if(this._opcode===8&&this._state==_)return s();this._bufferedBytes+=e.length;this._buffers.push(e);this.startLoop(s)}consume(e){this._bufferedBytes-=e;if(e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];this._buffers[0]=new p(t.buffer,t.byteOffset+e,t.length-e);return new p(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const s=this._buffers[0];const r=t.length-e;if(e>=s.length){t.set(this._buffers.shift(),r)}else{t.set(new Uint8Array(s.buffer,s.byteOffset,e),r);this._buffers[0]=new p(s.buffer,s.byteOffset+e,s.length-e)}e-=s.length}while(e>0);return t}startLoop(e){this._loop=true;do{switch(this._state){case _:this.getInfo(e);break;case v:this.getPayloadLength16(e);break;case g:this.getPayloadLength64(e);break;case m:this.getMask();break;case y:this.getData(e);break;case b:case S:this._loop=false;return}}while(this._loop);if(!this._errored)e()}getInfo(e){if(this._bufferedBytes<2){this._loop=false;return}const t=this.consume(2);if((t[0]&48)!==0){const t=this.createError(RangeError,"RSV2 and RSV3 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(t);return}const s=(t[0]&64)===64;if(s&&!this._extensions[o.extensionName]){const t=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(t);return}this._fin=(t[0]&128)===128;this._opcode=t[0]&15;this._payloadLength=t[1]&127;if(this._opcode===0){if(s){const t=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(t);return}if(!this._fragmented){const t=this.createError(RangeError,"invalid opcode 0",true,1002,"WS_ERR_INVALID_OPCODE");e(t);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){const t=this.createError(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE");e(t);return}this._compressed=s}else if(this._opcode>7&&this._opcode<11){if(!this._fin){const t=this.createError(RangeError,"FIN must be set",true,1002,"WS_ERR_EXPECTED_FIN");e(t);return}if(s){const t=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(t);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){const t=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,true,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(t);return}}else{const t=this.createError(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE");e(t);return}if(!this._fin&&!this._fragmented)this._fragmented=this._opcode;this._masked=(t[1]&128)===128;if(this._isServer){if(!this._masked){const t=this.createError(RangeError,"MASK must be set",true,1002,"WS_ERR_EXPECTED_MASK");e(t);return}}else if(this._masked){const t=this.createError(RangeError,"MASK must be clear",true,1002,"WS_ERR_UNEXPECTED_MASK");e(t);return}if(this._payloadLength===126)this._state=v;else if(this._payloadLength===127)this._state=g;else this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=false;return}this._payloadLength=this.consume(2).readUInt16BE(0);this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=false;return}const t=this.consume(8);const s=t.readUInt32BE(0);if(s>Math.pow(2,53-32)-1){const t=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",false,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(t);return}this._payloadLength=s*Math.pow(2,32)+t.readUInt32BE(4);this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8){this._totalPayloadLength+=this._payloadLength;if(this._totalPayloadLength>this._maxPayload&&this._maxPayload>0){const t=this.createError(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(t);return}}if(this._masked)this._state=m;else this._state=y}getMask(){if(this._bufferedBytes<4){this._loop=false;return}this._mask=this.consume(4);this._state=y}getData(e){let t=i;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=false;return}t=this.consume(this._payloadLength);if(this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0){h(t,this._mask)}}if(this._opcode>7){this.controlMessage(t,e);return}if(this._compressed){this._state=b;this.decompress(t,e);return}if(t.length){this._messageLength=this._totalPayloadLength;this._fragments.push(t)}this.dataMessage(e)}decompress(e,t){const s=this._extensions[o.extensionName];s.decompress(e,this._fin,((e,s)=>{if(e)return t(e);if(s.length){this._messageLength+=s.length;if(this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");t(e);return}this._fragments.push(s)}this.dataMessage(t);if(this._state===_)this.startLoop(t)}))}dataMessage(e){if(!this._fin){this._state=_;return}const t=this._messageLength;const s=this._fragments;this._totalPayloadLength=0;this._messageLength=0;this._fragmented=0;this._fragments=[];if(this._opcode===2){let r;if(this._binaryType==="nodebuffer"){r=l(s,t)}else if(this._binaryType==="arraybuffer"){r=f(l(s,t))}else if(this._binaryType==="blob"){r=new Blob(s)}else{r=s}if(this._allowSynchronousEvents){this.emit("message",r,true);this._state=_}else{this._state=S;setImmediate((()=>{this.emit("message",r,true);this._state=_;this.startLoop(e)}))}}else{const r=l(s,t);if(!this._skipUTF8Validation&&!d(r)){const t=this.createError(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8");e(t);return}if(this._state===b||this._allowSynchronousEvents){this.emit("message",r,false);this._state=_}else{this._state=S;setImmediate((()=>{this.emit("message",r,false);this._state=_;this.startLoop(e)}))}}}controlMessage(e,t){if(this._opcode===8){if(e.length===0){this._loop=false;this.emit("conclude",1005,i);this.end()}else{const s=e.readUInt16BE(0);if(!u(s)){const e=this.createError(RangeError,`invalid status code ${s}`,true,1002,"WS_ERR_INVALID_CLOSE_CODE");t(e);return}const r=new p(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!d(r)){const e=this.createError(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8");t(e);return}this._loop=false;this.emit("conclude",s,r);this.end()}this._state=_;return}if(this._allowSynchronousEvents){this.emit(this._opcode===9?"ping":"pong",e);this._state=_}else{this._state=S;setImmediate((()=>{this.emit(this._opcode===9?"ping":"pong",e);this._state=_;this.startLoop(t)}))}}createError(e,t,s,r,o){this._loop=false;this._errored=true;const n=new e(s?`Invalid WebSocket frame: ${t}`:t);Error.captureStackTrace(n,this.createError);n.code=o;n[a]=r;return n}}e.exports=Receiver},389:(e,t,s)=>{"use strict";const{Duplex:r}=s(203);const{randomFillSync:o}=s(982);const n=s(376);const{EMPTY_BUFFER:i,kWebSocket:a,NOOP:c}=s(791);const{isBlob:l,isValidStatusCode:f}=s(615);const{mask:h,toBuffer:u}=s(803);const d=Symbol("kByteLength");const p=Buffer.alloc(4);const _=8*1024;let v;let g=_;const m=0;const y=1;const b=2;class Sender{constructor(e,t,s){this._extensions=t||{};if(s){this._generateMask=s;this._maskBuffer=Buffer.alloc(4)}this._socket=e;this._firstFragment=true;this._compress=false;this._bufferedBytes=0;this._queue=[];this._state=m;this.onerror=c;this[a]=undefined}static frame(e,t){let s;let r=false;let n=2;let i=false;if(t.mask){s=t.maskBuffer||p;if(t.generateMask){t.generateMask(s)}else{if(g===_){if(v===undefined){v=Buffer.alloc(_)}o(v,0,_);g=0}s[0]=v[g++];s[1]=v[g++];s[2]=v[g++];s[3]=v[g++]}i=(s[0]|s[1]|s[2]|s[3])===0;n=6}let a;if(typeof e==="string"){if((!t.mask||i)&&t[d]!==undefined){a=t[d]}else{e=Buffer.from(e);a=e.length}}else{a=e.length;r=t.mask&&t.readOnly&&!i}let c=a;if(a>=65536){n+=8;c=127}else if(a>125){n+=2;c=126}const l=Buffer.allocUnsafe(r?a+n:n);l[0]=t.fin?t.opcode|128:t.opcode;if(t.rsv1)l[0]|=64;l[1]=c;if(c===126){l.writeUInt16BE(a,2)}else if(c===127){l[2]=l[3]=0;l.writeUIntBE(a,4,6)}if(!t.mask)return[l,e];l[1]|=128;l[n-4]=s[0];l[n-3]=s[1];l[n-2]=s[2];l[n-1]=s[3];if(i)return[l,e];if(r){h(e,s,l,n,a);return[l]}h(e,s,e,0,a);return[l,e]}close(e,t,s,r){let o;if(e===undefined){o=i}else if(typeof e!=="number"||!f(e)){throw new TypeError("First argument must be a valid error code number")}else if(t===undefined||!t.length){o=Buffer.allocUnsafe(2);o.writeUInt16BE(e,0)}else{const s=Buffer.byteLength(t);if(s>123){throw new RangeError("The message must not be greater than 123 bytes")}o=Buffer.allocUnsafe(2+s);o.writeUInt16BE(e,0);if(typeof t==="string"){o.write(t,2)}else{o.set(t,2)}}const n={[d]:o.length,fin:true,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:8,readOnly:false,rsv1:false};if(this._state!==m){this.enqueue([this.dispatch,o,false,n,r])}else{this.sendFrame(Sender.frame(o,n),r)}}ping(e,t,s){let r;let o;if(typeof e==="string"){r=Buffer.byteLength(e);o=false}else if(l(e)){r=e.size;o=false}else{e=u(e);r=e.length;o=u.readOnly}if(r>125){throw new RangeError("The data size must not be greater than 125 bytes")}const n={[d]:r,fin:true,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:o,rsv1:false};if(l(e)){if(this._state!==m){this.enqueue([this.getBlobData,e,false,n,s])}else{this.getBlobData(e,false,n,s)}}else if(this._state!==m){this.enqueue([this.dispatch,e,false,n,s])}else{this.sendFrame(Sender.frame(e,n),s)}}pong(e,t,s){let r;let o;if(typeof e==="string"){r=Buffer.byteLength(e);o=false}else if(l(e)){r=e.size;o=false}else{e=u(e);r=e.length;o=u.readOnly}if(r>125){throw new RangeError("The data size must not be greater than 125 bytes")}const n={[d]:r,fin:true,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:o,rsv1:false};if(l(e)){if(this._state!==m){this.enqueue([this.getBlobData,e,false,n,s])}else{this.getBlobData(e,false,n,s)}}else if(this._state!==m){this.enqueue([this.dispatch,e,false,n,s])}else{this.sendFrame(Sender.frame(e,n),s)}}send(e,t,s){const r=this._extensions[n.extensionName];let o=t.binary?2:1;let i=t.compress;let a;let c;if(typeof e==="string"){a=Buffer.byteLength(e);c=false}else if(l(e)){a=e.size;c=false}else{e=u(e);a=e.length;c=u.readOnly}if(this._firstFragment){this._firstFragment=false;if(i&&r&&r.params[r._isServer?"server_no_context_takeover":"client_no_context_takeover"]){i=a>=r._threshold}this._compress=i}else{i=false;o=0}if(t.fin)this._firstFragment=true;const f={[d]:a,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:o,readOnly:c,rsv1:i};if(l(e)){if(this._state!==m){this.enqueue([this.getBlobData,e,this._compress,f,s])}else{this.getBlobData(e,this._compress,f,s)}}else if(this._state!==m){this.enqueue([this.dispatch,e,this._compress,f,s])}else{this.dispatch(e,this._compress,f,s)}}getBlobData(e,t,s,r){this._bufferedBytes+=s[d];this._state=b;e.arrayBuffer().then((e=>{if(this._socket.destroyed){const e=new Error("The socket was closed while the blob was being read");process.nextTick(callCallbacks,this,e,r);return}this._bufferedBytes-=s[d];const o=u(e);if(!t){this._state=m;this.sendFrame(Sender.frame(o,s),r);this.dequeue()}else{this.dispatch(o,t,s,r)}})).catch((e=>{process.nextTick(onError,this,e,r)}))}dispatch(e,t,s,r){if(!t){this.sendFrame(Sender.frame(e,s),r);return}const o=this._extensions[n.extensionName];this._bufferedBytes+=s[d];this._state=y;o.compress(e,s.fin,((e,t)=>{if(this._socket.destroyed){const e=new Error("The socket was closed while data was being compressed");callCallbacks(this,e,r);return}this._bufferedBytes-=s[d];this._state=m;s.readOnly=false;this.sendFrame(Sender.frame(t,s),r);this.dequeue()}))}dequeue(){while(this._state===m&&this._queue.length){const e=this._queue.shift();this._bufferedBytes-=e[3][d];Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][d];this._queue.push(e)}sendFrame(e,t){if(e.length===2){this._socket.cork();this._socket.write(e[0]);this._socket.write(e[1],t);this._socket.uncork()}else{this._socket.write(e[0],t)}}}e.exports=Sender;function callCallbacks(e,t,s){if(typeof s==="function")s(t);for(let s=0;s<e._queue.length;s++){const r=e._queue[s];const o=r[r.length-1];if(typeof o==="function")o(t)}}function onError(e,t,s){callCallbacks(e,t,s);e.onerror(t)}},412:(e,t,s)=>{"use strict";const r=s(681);const{Duplex:o}=s(203);function emitClose(e){e.emit("close")}function duplexOnEnd(){if(!this.destroyed&&this._writableState.finished){this.destroy()}}function duplexOnError(e){this.removeListener("error",duplexOnError);this.destroy();if(this.listenerCount("error")===0){this.emit("error",e)}}function createWebSocketStream(e,t){let s=true;const r=new o({...t,autoDestroy:false,emitClose:false,objectMode:false,writableObjectMode:false});e.on("message",(function message(t,s){const o=!s&&r._readableState.objectMode?t.toString():t;if(!r.push(o))e.pause()}));e.once("error",(function error(e){if(r.destroyed)return;s=false;r.destroy(e)}));e.once("close",(function close(){if(r.destroyed)return;r.push(null)}));r._destroy=function(t,o){if(e.readyState===e.CLOSED){o(t);process.nextTick(emitClose,r);return}let n=false;e.once("error",(function error(e){n=true;o(e)}));e.once("close",(function close(){if(!n)o(t);process.nextTick(emitClose,r)}));if(s)e.terminate()};r._final=function(t){if(e.readyState===e.CONNECTING){e.once("open",(function open(){r._final(t)}));return}if(e._socket===null)return;if(e._socket._writableState.finished){t();if(r._readableState.endEmitted)r.destroy()}else{e._socket.once("finish",(function finish(){t()}));e.close()}};r._read=function(){if(e.isPaused)e.resume()};r._write=function(t,s,o){if(e.readyState===e.CONNECTING){e.once("open",(function open(){r._write(t,s,o)}));return}e.send(t,o)};r.on("end",duplexOnEnd);r.on("error",duplexOnError);return r}e.exports=createWebSocketStream},332:(e,t,s)=>{"use strict";const{tokenChars:r}=s(615);function parse(e){const t=new Set;let s=-1;let o=-1;let n=0;for(n;n<e.length;n++){const i=e.charCodeAt(n);if(o===-1&&r[i]===1){if(s===-1)s=n}else if(n!==0&&(i===32||i===9)){if(o===-1&&s!==-1)o=n}else if(i===44){if(s===-1){throw new SyntaxError(`Unexpected character at index ${n}`)}if(o===-1)o=n;const r=e.slice(s,o);if(t.has(r)){throw new SyntaxError(`The "${r}" subprotocol is duplicated`)}t.add(r);s=o=-1}else{throw new SyntaxError(`Unexpected character at index ${n}`)}}if(s===-1||o!==-1){throw new SyntaxError("Unexpected end of input")}const i=e.slice(s,n);if(t.has(i)){throw new SyntaxError(`The "${i}" subprotocol is duplicated`)}t.add(i);return t}e.exports={parse:parse}},615:(e,t,s)=>{"use strict";const{isUtf8:r}=s(181);const{hasBlob:o}=s(791);const n=[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 isValidStatusCode(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function _isValidUTF8(e){const t=e.length;let s=0;while(s<t){if((e[s]&128)===0){s++}else if((e[s]&224)===192){if(s+1===t||(e[s+1]&192)!==128||(e[s]&254)===192){return false}s+=2}else if((e[s]&240)===224){if(s+2>=t||(e[s+1]&192)!==128||(e[s+2]&192)!==128||e[s]===224&&(e[s+1]&224)===128||e[s]===237&&(e[s+1]&224)===160){return false}s+=3}else if((e[s]&248)===240){if(s+3>=t||(e[s+1]&192)!==128||(e[s+2]&192)!==128||(e[s+3]&192)!==128||e[s]===240&&(e[s+1]&240)===128||e[s]===244&&e[s+1]>143||e[s]>244){return false}s+=4}else{return false}}return true}function isBlob(e){return o&&typeof e==="object"&&typeof e.arrayBuffer==="function"&&typeof e.type==="string"&&typeof e.stream==="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}e.exports={isBlob:isBlob,isValidStatusCode:isValidStatusCode,isValidUTF8:_isValidUTF8,tokenChars:n};if(r){e.exports.isValidUTF8=function(e){return e.length<24?_isValidUTF8(e):r(e)}}else if(!process.env.WS_NO_UTF_8_VALIDATE){try{const t=s(414);e.exports.isValidUTF8=function(e){return e.length<32?_isValidUTF8(e):t(e)}}catch(e){}}},129:(e,t,s)=>{"use strict";const r=s(434);const o=s(611);const{Duplex:n}=s(203);const{createHash:i}=s(982);const a=s(335);const c=s(376);const l=s(332);const f=s(681);const{GUID:h,kWebSocket:u}=s(791);const d=/^[+/0-9A-Za-z]{22}==$/;const p=0;const _=1;const v=2;class WebSocketServer extends r{constructor(e,t){super();e={allowSynchronousEvents:true,autoPong:true,maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:false,handleProtocols:null,clientTracking:true,verifyClient:null,noServer:false,backlog:null,server:null,host:null,path:null,port:null,WebSocket:f,...e};if(e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer){throw new TypeError('One and only one of the "port", "server", or "noServer" options '+"must be specified")}if(e.port!=null){this._server=o.createServer(((e,t)=>{const s=o.STATUS_CODES[426];t.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"});t.end(s)}));this._server.listen(e.port,e.host,e.backlog,t)}else if(e.server){this._server=e.server}if(this._server){const e=this.emit.bind(this,"connection");this._removeListeners=addListeners(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,s,r)=>{this.handleUpgrade(t,s,r,e)}})}if(e.perMessageDeflate===true)e.perMessageDeflate={};if(e.clientTracking){this.clients=new Set;this._shouldEmitClose=false}this.options=e;this._state=p}address(){if(this.options.noServer){throw new Error('The server is operating in "noServer" mode')}if(!this._server)return null;return this._server.address()}close(e){if(this._state===v){if(e){this.once("close",(()=>{e(new Error("The server is not running"))}))}process.nextTick(emitClose,this);return}if(e)this.once("close",e);if(this._state===_)return;this._state=_;if(this.options.noServer||this.options.server){if(this._server){this._removeListeners();this._removeListeners=this._server=null}if(this.clients){if(!this.clients.size){process.nextTick(emitClose,this)}else{this._shouldEmitClose=true}}else{process.nextTick(emitClose,this)}}else{const e=this._server;this._removeListeners();this._removeListeners=this._server=null;e.close((()=>{emitClose(this)}))}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");const s=t!==-1?e.url.slice(0,t):e.url;if(s!==this.options.path)return false}return true}handleUpgrade(e,t,s,r){t.on("error",socketOnError);const o=e.headers["sec-websocket-key"];const n=e.headers.upgrade;const i=+e.headers["sec-websocket-version"];if(e.method!=="GET"){const s="Invalid HTTP method";abortHandshakeOrEmitwsClientError(this,e,t,405,s);return}if(n===undefined||n.toLowerCase()!=="websocket"){const s="Invalid Upgrade header";abortHandshakeOrEmitwsClientError(this,e,t,400,s);return}if(o===undefined||!d.test(o)){const s="Missing or invalid Sec-WebSocket-Key header";abortHandshakeOrEmitwsClientError(this,e,t,400,s);return}if(i!==13&&i!==8){const s="Missing or invalid Sec-WebSocket-Version header";abortHandshakeOrEmitwsClientError(this,e,t,400,s,{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){abortHandshake(t,400);return}const f=e.headers["sec-websocket-protocol"];let h=new Set;if(f!==undefined){try{h=l.parse(f)}catch(s){const r="Invalid Sec-WebSocket-Protocol header";abortHandshakeOrEmitwsClientError(this,e,t,400,r);return}}const u=e.headers["sec-websocket-extensions"];const p={};if(this.options.perMessageDeflate&&u!==undefined){const s=new c(this.options.perMessageDeflate,true,this.options.maxPayload);try{const e=a.parse(u);if(e[c.extensionName]){s.accept(e[c.extensionName]);p[c.extensionName]=s}}catch(s){const r="Invalid or unacceptable Sec-WebSocket-Extensions header";abortHandshakeOrEmitwsClientError(this,e,t,400,r);return}}if(this.options.verifyClient){const n={origin:e.headers[`${i===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(n,((n,i,a,c)=>{if(!n){return abortHandshake(t,i||401,a,c)}this.completeUpgrade(p,o,h,e,t,s,r)}));return}if(!this.options.verifyClient(n))return abortHandshake(t,401)}this.completeUpgrade(p,o,h,e,t,s,r)}completeUpgrade(e,t,s,r,o,n,l){if(!o.readable||!o.writable)return o.destroy();if(o[u]){throw new Error("server.handleUpgrade() was called more than once with the same "+"socket, possibly due to a misconfiguration")}if(this._state>p)return abortHandshake(o,503);const f=i("sha1").update(t+h).digest("base64");const d=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${f}`];const _=new this.options.WebSocket(null,undefined,this.options);if(s.size){const e=this.options.handleProtocols?this.options.handleProtocols(s,r):s.values().next().value;if(e){d.push(`Sec-WebSocket-Protocol: ${e}`);_._protocol=e}}if(e[c.extensionName]){const t=e[c.extensionName].params;const s=a.format({[c.extensionName]:[t]});d.push(`Sec-WebSocket-Extensions: ${s}`);_._extensions=e}this.emit("headers",d,r);o.write(d.concat("\r\n").join("\r\n"));o.removeListener("error",socketOnError);_.setSocket(o,n,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation});if(this.clients){this.clients.add(_);_.on("close",(()=>{this.clients.delete(_);if(this._shouldEmitClose&&!this.clients.size){process.nextTick(emitClose,this)}}))}l(_,r)}}e.exports=WebSocketServer;function addListeners(e,t){for(const s of Object.keys(t))e.on(s,t[s]);return function removeListeners(){for(const s of Object.keys(t)){e.removeListener(s,t[s])}}}function emitClose(e){e._state=v;e.emit("close")}function socketOnError(){this.destroy()}function abortHandshake(e,t,s,r){s=s||o.STATUS_CODES[t];r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(s),...r};e.once("finish",e.destroy);e.end(`HTTP/1.1 ${t} ${o.STATUS_CODES[t]}\r\n`+Object.keys(r).map((e=>`${e}: ${r[e]}`)).join("\r\n")+"\r\n\r\n"+s)}function abortHandshakeOrEmitwsClientError(e,t,s,r,o,n){if(e.listenerCount("wsClientError")){const r=new Error(o);Error.captureStackTrace(r,abortHandshakeOrEmitwsClientError);e.emit("wsClientError",r,s,t)}else{abortHandshake(s,r,o,n)}}},681:(e,t,s)=>{"use strict";const r=s(434);const o=s(692);const n=s(611);const i=s(278);const a=s(756);const{randomBytes:c,createHash:l}=s(982);const{Duplex:f,Readable:h}=s(203);const{URL:u}=s(16);const d=s(376);const p=s(893);const _=s(389);const{isBlob:v}=s(615);const{BINARY_TYPES:g,EMPTY_BUFFER:m,GUID:y,kForOnEventAttribute:b,kListener:S,kStatusCode:k,kWebSocket:w,NOOP:E}=s(791);const{EventTarget:{addEventListener:x,removeEventListener:O}}=s(634);const{format:C,parse:T}=s(335);const{toBuffer:P}=s(803);const N=30*1e3;const W=Symbol("kAborted");const L=[8,13];const I=["CONNECTING","OPEN","CLOSING","CLOSED"];const U=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class WebSocket extends r{constructor(e,t,s){super();this._binaryType=g[0];this._closeCode=1006;this._closeFrameReceived=false;this._closeFrameSent=false;this._closeMessage=m;this._closeTimer=null;this._errorEmitted=false;this._extensions={};this._paused=false;this._protocol="";this._readyState=WebSocket.CONNECTING;this._receiver=null;this._sender=null;this._socket=null;if(e!==null){this._bufferedAmount=0;this._isServer=false;this._redirects=0;if(t===undefined){t=[]}else if(!Array.isArray(t)){if(typeof t==="object"&&t!==null){s=t;t=[]}else{t=[t]}}initAsClient(this,e,t,s)}else{this._autoPong=s.autoPong;this._isServer=true}}get binaryType(){return this._binaryType}set binaryType(e){if(!g.includes(e))return;this._binaryType=e;if(this._receiver)this._receiver._binaryType=e}get bufferedAmount(){if(!this._socket)return this._bufferedAmount;return this._socket._writableState.length+this._sender._bufferedBytes}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,t,s){const r=new p({allowSynchronousEvents:s.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation});const o=new _(e,this._extensions,s.generateMask);this._receiver=r;this._sender=o;this._socket=e;r[w]=this;o[w]=this;e[w]=this;r.on("conclude",receiverOnConclude);r.on("drain",receiverOnDrain);r.on("error",receiverOnError);r.on("message",receiverOnMessage);r.on("ping",receiverOnPing);r.on("pong",receiverOnPong);o.onerror=senderOnError;if(e.setTimeout)e.setTimeout(0);if(e.setNoDelay)e.setNoDelay();if(t.length>0)e.unshift(t);e.on("close",socketOnClose);e.on("data",socketOnData);e.on("end",socketOnEnd);e.on("error",socketOnError);this._readyState=WebSocket.OPEN;this.emit("open")}emitClose(){if(!this._socket){this._readyState=WebSocket.CLOSED;this.emit("close",this._closeCode,this._closeMessage);return}if(this._extensions[d.extensionName]){this._extensions[d.extensionName].cleanup()}this._receiver.removeAllListeners();this._readyState=WebSocket.CLOSED;this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState===WebSocket.CLOSED)return;if(this.readyState===WebSocket.CONNECTING){const e="WebSocket was closed before the connection was established";abortHandshake(this,this._req,e);return}if(this.readyState===WebSocket.CLOSING){if(this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)){this._socket.end()}return}this._readyState=WebSocket.CLOSING;this._sender.close(e,t,!this._isServer,(e=>{if(e)return;this._closeFrameSent=true;if(this._closeFrameReceived||this._receiver._writableState.errorEmitted){this._socket.end()}}));setCloseTimer(this)}pause(){if(this.readyState===WebSocket.CONNECTING||this.readyState===WebSocket.CLOSED){return}this._paused=true;this._socket.pause()}ping(e,t,s){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof e==="function"){s=e;e=t=undefined}else if(typeof t==="function"){s=t;t=undefined}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,s);return}if(t===undefined)t=!this._isServer;this._sender.ping(e||m,t,s)}pong(e,t,s){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof e==="function"){s=e;e=t=undefined}else if(typeof t==="function"){s=t;t=undefined}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,s);return}if(t===undefined)t=!this._isServer;this._sender.pong(e||m,t,s)}resume(){if(this.readyState===WebSocket.CONNECTING||this.readyState===WebSocket.CLOSED){return}this._paused=false;if(!this._receiver._writableState.needDrain)this._socket.resume()}send(e,t,s){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof t==="function"){s=t;t={}}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,s);return}const r={binary:typeof e!=="string",mask:!this._isServer,compress:true,fin:true,...t};if(!this._extensions[d.extensionName]){r.compress=false}this._sender.send(e||m,r,s)}terminate(){if(this.readyState===WebSocket.CLOSED)return;if(this.readyState===WebSocket.CONNECTING){const e="WebSocket was closed before the connection was established";abortHandshake(this,this._req,e);return}if(this._socket){this._readyState=WebSocket.CLOSING;this._socket.destroy()}}}Object.defineProperty(WebSocket,"CONNECTING",{enumerable:true,value:I.indexOf("CONNECTING")});Object.defineProperty(WebSocket.prototype,"CONNECTING",{enumerable:true,value:I.indexOf("CONNECTING")});Object.defineProperty(WebSocket,"OPEN",{enumerable:true,value:I.indexOf("OPEN")});Object.defineProperty(WebSocket.prototype,"OPEN",{enumerable:true,value:I.indexOf("OPEN")});Object.defineProperty(WebSocket,"CLOSING",{enumerable:true,value:I.indexOf("CLOSING")});Object.defineProperty(WebSocket.prototype,"CLOSING",{enumerable:true,value:I.indexOf("CLOSING")});Object.defineProperty(WebSocket,"CLOSED",{enumerable:true,value:I.indexOf("CLOSED")});Object.defineProperty(WebSocket.prototype,"CLOSED",{enumerable:true,value:I.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(WebSocket.prototype,e,{enumerable:true})}));["open","error","close","message"].forEach((e=>{Object.defineProperty(WebSocket.prototype,`on${e}`,{enumerable:true,get(){for(const t of this.listeners(e)){if(t[b])return t[S]}return null},set(t){for(const t of this.listeners(e)){if(t[b]){this.removeListener(e,t);break}}if(typeof t!=="function")return;this.addEventListener(e,t,{[b]:true})}})}));WebSocket.prototype.addEventListener=x;WebSocket.prototype.removeEventListener=O;e.exports=WebSocket;function initAsClient(e,t,s,r){const i={allowSynchronousEvents:true,autoPong:true,protocolVersion:L[1],maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:true,followRedirects:false,maxRedirects:10,...r,socketPath:undefined,hostname:undefined,protocol:undefined,timeout:undefined,method:"GET",host:undefined,path:undefined,port:undefined};e._autoPong=i.autoPong;if(!L.includes(i.protocolVersion)){throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} `+`(supported versions: ${L.join(", ")})`)}let a;if(t instanceof u){a=t}else{try{a=new u(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}}if(a.protocol==="http:"){a.protocol="ws:"}else if(a.protocol==="https:"){a.protocol="wss:"}e._url=a.href;const f=a.protocol==="wss:";const h=a.protocol==="ws+unix:";let p;if(a.protocol!=="ws:"&&!f&&!h){p='The URL\'s protocol must be one of "ws:", "wss:", '+'"http:", "https:", or "ws+unix:"'}else if(h&&!a.pathname){p="The URL's pathname is empty"}else if(a.hash){p="The URL contains a fragment identifier"}if(p){const t=new SyntaxError(p);if(e._redirects===0){throw t}else{emitErrorAndClose(e,t);return}}const _=f?443:80;const v=c(16).toString("base64");const g=f?o.request:n.request;const m=new Set;let b;i.createConnection=i.createConnection||(f?tlsConnect:netConnect);i.defaultPort=i.defaultPort||_;i.port=a.port||_;i.host=a.hostname.startsWith("[")?a.hostname.slice(1,-1):a.hostname;i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":v,Connection:"Upgrade",Upgrade:"websocket"};i.path=a.pathname+a.search;i.timeout=i.handshakeTimeout;if(i.perMessageDeflate){b=new d(i.perMessageDeflate!==true?i.perMessageDeflate:{},false,i.maxPayload);i.headers["Sec-WebSocket-Extensions"]=C({[d.extensionName]:b.offer()})}if(s.length){for(const e of s){if(typeof e!=="string"||!U.test(e)||m.has(e)){throw new SyntaxError("An invalid or duplicated subprotocol was specified")}m.add(e)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin){if(i.protocolVersion<13){i.headers["Sec-WebSocket-Origin"]=i.origin}else{i.headers.Origin=i.origin}}if(a.username||a.password){i.auth=`${a.username}:${a.password}`}if(h){const e=i.path.split(":");i.socketPath=e[0];i.path=e[1]}let S;if(i.followRedirects){if(e._redirects===0){e._originalIpc=h;e._originalSecure=f;e._originalHostOrSocketPath=h?i.socketPath:a.host;const t=r&&r.headers;r={...r,headers:{}};if(t){for(const[e,s]of Object.entries(t)){r.headers[e.toLowerCase()]=s}}}else if(e.listenerCount("redirect")===0){const t=h?e._originalIpc?i.socketPath===e._originalHostOrSocketPath:false:e._originalIpc?false:a.host===e._originalHostOrSocketPath;if(!t||e._originalSecure&&!f){delete i.headers.authorization;delete i.headers.cookie;if(!t)delete i.headers.host;i.auth=undefined}}if(i.auth&&!r.headers.authorization){r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")}S=e._req=g(i);if(e._redirects){e.emit("redirect",e.url,S)}}else{S=e._req=g(i)}if(i.timeout){S.on("timeout",(()=>{abortHandshake(e,S,"Opening handshake has timed out")}))}S.on("error",(t=>{if(S===null||S[W])return;S=e._req=null;emitErrorAndClose(e,t)}));S.on("response",(o=>{const n=o.headers.location;const a=o.statusCode;if(n&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects){abortHandshake(e,S,"Maximum redirects exceeded");return}S.abort();let o;try{o=new u(n,t)}catch(t){const s=new SyntaxError(`Invalid URL: ${n}`);emitErrorAndClose(e,s);return}initAsClient(e,o,s,r)}else if(!e.emit("unexpected-response",S,o)){abortHandshake(e,S,`Unexpected server response: ${o.statusCode}`)}}));S.on("upgrade",((t,s,r)=>{e.emit("upgrade",t);if(e.readyState!==WebSocket.CONNECTING)return;S=e._req=null;const o=t.headers.upgrade;if(o===undefined||o.toLowerCase()!=="websocket"){abortHandshake(e,s,"Invalid Upgrade header");return}const n=l("sha1").update(v+y).digest("base64");if(t.headers["sec-websocket-accept"]!==n){abortHandshake(e,s,"Invalid Sec-WebSocket-Accept header");return}const a=t.headers["sec-websocket-protocol"];let c;if(a!==undefined){if(!m.size){c="Server sent a subprotocol but none was requested"}else if(!m.has(a)){c="Server sent an invalid subprotocol"}}else if(m.size){c="Server sent no subprotocol"}if(c){abortHandshake(e,s,c);return}if(a)e._protocol=a;const f=t.headers["sec-websocket-extensions"];if(f!==undefined){if(!b){const t="Server sent a Sec-WebSocket-Extensions header but no extension "+"was requested";abortHandshake(e,s,t);return}let t;try{t=T(f)}catch(t){const r="Invalid Sec-WebSocket-Extensions header";abortHandshake(e,s,r);return}const r=Object.keys(t);if(r.length!==1||r[0]!==d.extensionName){const t="Server indicated an extension that was not requested";abortHandshake(e,s,t);return}try{b.accept(t[d.extensionName])}catch(t){const r="Invalid Sec-WebSocket-Extensions header";abortHandshake(e,s,r);return}e._extensions[d.extensionName]=b}e.setSocket(s,r,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}));if(i.finishRequest){i.finishRequest(S,e)}else{S.end()}}function emitErrorAndClose(e,t){e._readyState=WebSocket.CLOSING;e._errorEmitted=true;e.emit("error",t);e.emitClose()}function netConnect(e){e.path=e.socketPath;return i.connect(e)}function tlsConnect(e){e.path=undefined;if(!e.servername&&e.servername!==""){e.servername=i.isIP(e.host)?"":e.host}return a.connect(e)}function abortHandshake(e,t,s){e._readyState=WebSocket.CLOSING;const r=new Error(s);Error.captureStackTrace(r,abortHandshake);if(t.setHeader){t[W]=true;t.abort();if(t.socket&&!t.socket.destroyed){t.socket.destroy()}process.nextTick(emitErrorAndClose,e,r)}else{t.destroy(r);t.once("error",e.emit.bind(e,"error"));t.once("close",e.emitClose.bind(e))}}function sendAfterClose(e,t,s){if(t){const s=v(t)?t.size:P(t).length;if(e._socket)e._sender._bufferedBytes+=s;else e._bufferedAmount+=s}if(s){const t=new Error(`WebSocket is not open: readyState ${e.readyState} `+`(${I[e.readyState]})`);process.nextTick(s,t)}}function receiverOnConclude(e,t){const s=this[w];s._closeFrameReceived=true;s._closeMessage=t;s._closeCode=e;if(s._socket[w]===undefined)return;s._socket.removeListener("data",socketOnData);process.nextTick(resume,s._socket);if(e===1005)s.close();else s.close(e,t)}function receiverOnDrain(){const e=this[w];if(!e.isPaused)e._socket.resume()}function receiverOnError(e){const t=this[w];if(t._socket[w]!==undefined){t._socket.removeListener("data",socketOnData);process.nextTick(resume,t._socket);t.close(e[k])}if(!t._errorEmitted){t._errorEmitted=true;t.emit("error",e)}}function receiverOnFinish(){this[w].emitClose()}function receiverOnMessage(e,t){this[w].emit("message",e,t)}function receiverOnPing(e){const t=this[w];if(t._autoPong)t.pong(e,!this._isServer,E);t.emit("ping",e)}function receiverOnPong(e){this[w].emit("pong",e)}function resume(e){e.resume()}function senderOnError(e){const t=this[w];if(t.readyState===WebSocket.CLOSED)return;if(t.readyState===WebSocket.OPEN){t._readyState=WebSocket.CLOSING;setCloseTimer(t)}this._socket.end();if(!t._errorEmitted){t._errorEmitted=true;t.emit("error",e)}}function setCloseTimer(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),N)}function socketOnClose(){const e=this[w];this.removeListener("close",socketOnClose);this.removeListener("data",socketOnData);this.removeListener("end",socketOnEnd);e._readyState=WebSocket.CLOSING;let t;if(!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&(t=e._socket.read())!==null){e._receiver.write(t)}e._receiver.end();this[w]=undefined;clearTimeout(e._closeTimer);if(e._receiver._writableState.finished||e._receiver._writableState.errorEmitted){e.emitClose()}else{e._receiver.on("error",receiverOnFinish);e._receiver.on("finish",receiverOnFinish)}}function socketOnData(e){if(!this[w]._receiver.write(e)){this.pause()}}function socketOnEnd(){const e=this[w];e._readyState=WebSocket.CLOSING;e._receiver.end();this.end()}function socketOnError(){const e=this[w];this.removeListener("error",socketOnError);this.on("error",E);if(e){e._readyState=WebSocket.CLOSING;this.destroy()}}},327:module=>{module.exports=eval("require")("bufferutil")},414:module=>{module.exports=eval("require")("utf-8-validate")},181:e=>{"use strict";e.exports=require("buffer")},982:e=>{"use strict";e.exports=require("crypto")},434:e=>{"use strict";e.exports=require("events")},896:e=>{"use strict";e.exports=require("fs")},611:e=>{"use strict";e.exports=require("http")},692:e=>{"use strict";e.exports=require("https")},278:e=>{"use strict";e.exports=require("net")},857:e=>{"use strict";e.exports=require("os")},928:e=>{"use strict";e.exports=require("path")},203:e=>{"use strict";e.exports=require("stream")},756:e=>{"use strict";e.exports=require("tls")},16:e=>{"use strict";e.exports=require("url")},106:e=>{"use strict";e.exports=require("zlib")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var t=__webpack_module_cache__[e];if(t!==undefined){return t.exports}var s=__webpack_module_cache__[e]={exports:{}};var r=true;try{__webpack_modules__[e].call(s.exports,s,s.exports,__nccwpck_require__);r=false}finally{if(r)delete __webpack_module_cache__[e]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__=__nccwpck_require__(546);module.exports=__webpack_exports__})();
|
|
1
|
+
(()=>{var __webpack_modules__={546:function(e,t,s){var r=this&&this.__assign||function(){r=Object.assign||function(e){for(var t,s=1,r=arguments.length;s<r;s++){t=arguments[s];for(var o in t)if(Object.prototype.hasOwnProperty.call(t,o))e[o]=t[o]}return e};return r.apply(this,arguments)};var o=this&&this.__spreadArray||function(e,t,s){if(s||arguments.length===2)for(var r=0,o=t.length,n;r<o;r++){if(n||!(r in t)){if(!n)n=Array.prototype.slice.call(t,0,r);n[r]=t[r]}}return e.concat(n||Array.prototype.slice.call(t))};e.exports=function(e,t){var n=s(354);var i=t.sysWork,a=t.apiWork,c=t.wsWork,l=t.jsonpWork;function initAsaiHost(){var t,s,r,o;e.setAppend=setAppend;e.getHost=getHostCFG;e.getHostIP=getHostIP;initProcess();initLog();if(!((t=e.hostconfig)===null||t===void 0?void 0:t.ip)){e.hostconfig.ip=getIp()}e.hostconfig.asaiport=[];e.hostconfig.guardtm=null;if(((r=(s=e.hostconfig)===null||s===void 0?void 0:s.aes)===null||r===void 0?void 0:r.lv)&&!((o=e.$lib)===null||o===void 0?void 0:o.aesfns)){var n=e.$lib.AsAES(e),i=n.reqAES,a=n.resAES;e.$lib.aesfns={allaes:e.hostconfig.aes.lv>1,reqAES:i,resAES:a}}}function getHostIP(t){if(t===void 0){t=null}if(t&&typeof t==="string"){return t}else if(e.hostconfig.ip==="asai"){return"localhost"}return e.hostconfig.ip||"127.0.0.1"}function getHostCFG(t){var s=r(r({},e.hostconfig.hosts.default||{}),e.hostconfig.hosts[t]);return s}function getProxyHostCFG(t){var s=r(r({},e.hostconfig.proxyhosts.default||{}),e.hostconfig.proxyhosts[t]);if(!s.url&&s.port){s.url=(s===null||s===void 0?void 0:s.httptype)+getHostIP(s.ip)+":"+(s===null||s===void 0?void 0:s.port)}return s}function setAppend(t){var s=[];for(var r=1;r<arguments.length;r++){s[r-1]=arguments[r]}return new Promise((function(r,o){try{e.asaifs.ensureFile(t).then((function(){var n="";if((s===null||s===void 0?void 0:s[0])===1){s.shift();n=s.join("\n")+"\n"}else{n=s.join(" ").replace(/\n/g," ").replace(/\r/g," ")+"\n"}e.asaifs.append(t,n).then((function(){r()})).catch(o)})).catch(o)}catch(e){console.error(e);o(e)}}))}function initProcess(t){if(t===void 0){t=null}var s=10;var r=6e4;var o=[];process.on("unhandledRejection",(function(t,s){var r;var o=(new Error).stack;var n="";if(s&&typeof s==="object"){n=((r=s.constructor)===null||r===void 0?void 0:r.name)||"Promise";var i=(o===null||o===void 0?void 0:o.split("\n"))||[];var a=i.slice(3,6).join(" | ");n+=" Created at: ".concat(a)}var c="";if(t instanceof Error){c="\n".concat(t.name,": ").concat(t.message);if(t.stack){c+="\n【Stack】".concat(t.stack)}}else if(typeof t==="object"&&t!==null){try{c=JSON.stringify(t,null,2).substring(0,500)}catch(e){c=String(t)}}else{c=String(t)}var l="Unhandled Promise Rejection:\n【Reason】 ".concat(c,"\n【Promise】").concat(n);e.$log("★",l)}));process.on("uncaughtException",(function(n){var i="Uncaught Exception: ".concat(JSON.stringify(n));e.$log("★",i);var a=Date.now();o.push(a);while(o.length>0&&o[0]<a-r){o.shift()}if(o.length>s){e.$log("★","Process crashed too frequently, not restarting.");e.$log("★","Error:",(n===null||n===void 0?void 0:n.message)||n);process.exit(1)}if(t&&typeof t==="function"){try{t(n)}catch(e){console.error("Error in process error callback:",e)}}}));process.on("SIGTERM",(function(){e.$log("★","SIGTERM,CLOSING...");gracefulShutdown()}));process.on("SIGINT",(function(){e.$log("★","SIGINT,CLOSING...");gracefulShutdown()}))}function initLog(){var t,s;if(e&&typeof e==="object"&&((s=(t=e.hostconfig)===null||t===void 0?void 0:t.path)===null||s===void 0?void 0:s.log)){try{e.$log=function(){var t=[];for(var s=0;s<arguments.length;s++){t[s]=arguments[s]}return new Promise((function(s,r){var n,i,a,c,l;try{var f=t[0];if(typeof f==="number"&&f>666){((n=e.hostconfig)===null||n===void 0?void 0:n.log)&&console.log.apply(console,t);s()}else if(f===1){setLog.apply(void 0,o([(((a=(i=e.hostconfig.path)===null||i===void 0?void 0:i.log)===null||a===void 0?void 0:a.client)||"")+"log-".concat(getNowTime(2),".txt")],t,false)).then(s).catch(r)}else{setLog.apply(void 0,o([(((l=(c=e.hostconfig.path)===null||c===void 0?void 0:c.log)===null||l===void 0?void 0:l.server)||"")+"log-".concat(getNowTime(2),".txt"),"【".concat(getNowTime(1),"】")],t,false)).then(s).catch(r)}}catch(e){console.error(e);r(e)}}))}}catch(e){console.error(e)}return}if(typeof e!=="object"){e={}}e.$log=function(){var t;var s=[];for(var r=0;r<arguments.length;r++){s[r]=arguments[r]}((t=e.hostconfig)===null||t===void 0?void 0:t.log)&&console.log.apply(console,s)}}function gracefulShutdown(){var t=6e4;var s;var r=Date.now();s=setTimeout((function(){e.$log("★","Timeout! Exiting after ".concat(Date.now()-r,"ms"));process.exit(1)}),t);try{Object.values(e.servershttp||{}).forEach((function(t){if(t&&typeof t.close==="function"){t.close((function(t){if(t){e.$log("★","HTTP server close error:",t)}}))}}));Object.values(e.serversws||{}).forEach((function(t){if(t&&typeof t.close==="function"){t.close((function(t){if(t){e.$log("★","WS server close error:",t)}}))}}));if(e.hostconfig.guardtm){clearTimeout(e.hostconfig.guardtm);e.hostconfig.guardtm=null}Object.keys(e.tasksws||{}).forEach((function(t){if(e.tasksws[t].httpMonitor){clearInterval(e.tasksws[t].httpMonitor);delete e.tasksws[t].httpMonitor}}));setTimeout((function(){clearTimeout(s);e.$log("★","Web Server Closed (".concat(Date.now()-r,"ms)"));process.exit(0)}),3e3)}catch(t){e.$log("★","Graceful shutdown error:",t);clearTimeout(s);process.exit(1)}}function setLog(t){var s=[];for(var r=1;r<arguments.length;r++){s[r-1]=arguments[r]}return new Promise((function(r,n){var i;try{((i=e.hostconfig)===null||i===void 0?void 0:i.log)&&console.log.apply(console,s);setAppend.apply(void 0,o([t],s,false)).then((function(){r()})).catch(n)}catch(e){console.error(e);n(e)}}))}function startHTTPServer(t){var n,c,f,h,u;var d=getHostCFG(t);if(d&&!(d===null||d===void 0?void 0:d.close)){try{if(!e.servershttp[t]){if("mimetypes"in d){d.mimetypes=r(r({},e.hostconfig.mimetypes||{}),d.mimetypes||{})}var p=getHTTPServer(d===null||d===void 0?void 0:d.httptype,d);var _=((n=d.weburls)===null||n===void 0?void 0:n.rewrite)&&((c=d.weburls)===null||c===void 0?void 0:c.webdir)&&((h=(f=d.weburls)===null||f===void 0?void 0:f.keys)===null||h===void 0?void 0:h.length);var v=o([((u=d.weburls)===null||u===void 0?void 0:u.webdir)||""],d.hostdirs||[],true).filter((function(e){return e}));var g=!!v.length;e.servershttp[t]=p.AsCreateServer((function(r,o){try{if(checkHttpHeader(r)){if(r.url.startsWith("/sys")){i(r,o,t)}else if(r.url.startsWith("/api")){a(r,o,t)}else if(r.url.startsWith("/jsonp")){l(r,o,t)}else if(g){o.setHeader("Cross-Origin-Resource-Policy","cross-origin");o.setHeader("Cross-Origin-Opener-Policy","cross-origin");if(checkWebUrls(r.url)){showHostDirs([d.weburls.webdir],"/"+e.hostconfig.index)}else{showHostDirs(v,r.url)}function checkWebUrls(e){var t,s,r;console.log(666.0055,e);if(_&&typeof e==="string"&&e){return(r=(s=(t=d.weburls)===null||t===void 0?void 0:t.keys)===null||s===void 0?void 0:s.some)===null||r===void 0?void 0:r.call(s,(function(t){return e.startsWith(t)}))}return false}function showHostDirs(t,r,n){var i,a,c;if(n===void 0){n=0}var l=s(896);var f=s(928);var h=parseUrlPath(r);var findValidFile=function(t,r){var o,n;for(var i=0,a=t;i<a.length;i++){var c=a[i];var l="./"+c+r;if(r.endsWith("/")){l=l+(e.hostconfig.index||"index.html")}if(((n=(o=e.hostconfig)===null||o===void 0?void 0:o.pkg)===null||n===void 0?void 0:n.type)==1){var h=s.ab+"asai-nodejs-host/"+c+"\\"+r;console.log(666.888888,h);if(checkFileExists(h)){return h}}var u=f.normalize(l);if(u.includes(".."))continue;if(checkFileExists(u)){return u}}return null};var u=h.endsWith("/")?h+(e.hostconfig.index||"index.html"):h;var p=findValidFile(t,u);if(!p){if(n>0||!_){o.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"});o.end("File not found!");return}else{var v=[d.weburls.webdir];var g=(((a=(i=e.hostconfig)===null||i===void 0?void 0:i.pkg)===null||a===void 0?void 0:a.type)==1?"":"/")+e.hostconfig.index;showHostDirs(v,g,n+1);return}}var m;try{m=l.statSync(p)}catch(t){e.$log("●","File stat error:",t);if(!o.headersSent){o.writeHead(500,{"Content-Type":"text/plain; charset=utf-8"});o.end("Internal Server Error")}else{o.destroy()}return}var y=((c=d.mimetypes)===null||c===void 0?void 0:c[f.extname(p)])||"application/octet-stream";var b=l.createReadStream(p);b.once("open",(function(){o.writeHead(200,{"Content-Type":y,"Content-Length":m.size,"Cache-Control":"public, max-age=3600"});b.pipe(o)}));b.once("error",(function(t){e.$log("●","Stream error:",t);if(!o.headersSent){o.writeHead(500,{"Content-Type":"text/plain; charset=utf-8"});o.end("Internal Server Error")}else{o.destroy()}}));o.once("close",(function(){if(!b.destroyed){b.destroy()}}))}function checkFileExists(e){var t=s(896);try{var r=t.statSync(e);return r.isFile()&&r.mode&t.constants.R_OK}catch(e){return false}}function parseUrlPath(e){try{if(!e)return"/";var t=e.startsWith("http")?undefined:"http://localhost";return new URL(e,t).pathname}catch(t){return e}}}else{o.writeHead(404,{"Content-Type":"text/plain; charset=utf-8"});o.end("404")}}else{o.writeHead(502,{"Content-Type":"text/plain; charset=utf-8"});o.end("502")}}catch(n){if(!o.headersSent){o.writeHead(500,{"Content-Type":"text/plain; charset=utf-8"})}o.end("Internal server error");e.$log("★","HTTP request error:",n)}}));d.ws&&createWSHost(t);e.servershttp[t].on("error",(function(t){e.hostconfig.asaiport.push(d.port);asaiGuard();if(t.code==="EADDRINUSE"){e.$log("★","[41mPort ".concat(d.port," is already start![0m"))}else{e.$log("★","Server error:",t)}}));if(e.hostconfig.ip==="asai"||!d.ip&&!e.hostconfig.ip){e.servershttp[t].listen(d.port,(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));d.ws&&console.log("[41;28mWS Server ".concat(d.wstype,"localhost:").concat(d.port,"[0m"));console.log("[42;28mHTTP Server ".concat(d.httptype,"localhost:").concat(d.port,"[0m"));console.log("================================================")}))}else{e.servershttp[t].listen(d.port,getHostIP(d.ip),(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));d.ws&&console.log("[44;28mWS Server ".concat(d.wstype+getHostIP(d.ip),":").concat(d.port,"[0m"));console.log("[42;28mHTTP Server ".concat(d.httptype+getHostIP(d.ip),":").concat(d.port,"[0m"));console.log("================================================")}))}}}catch(t){e.$log("●","Http server error:",JSON.stringify(t))}if(d.ckhttp){var m=d.maxhttp||100;var y=setInterval((function(){var s;var r=((s=e.connectionshttp[t])===null||s===void 0?void 0:s.size)||0;if(r>m*.8){e.$log("★","HTTP Connection HIGH (".concat(r,"/").concat(m,")"))}if(r>m*.95){e.$log("★","HTTP Connection CRITICAL! Forcing cleanup");if(e.connectionshttp[t]){e.connectionshttp[t].forEach((function(e){if(e._idleTime&&Date.now()-e._idleTime>3e5){e.destroy()}}))}}}),18e5);if(!e.tasksws[t]){e.tasksws[t]={}}e.tasksws[t].httpMonitor=y;e.servershttp[t].on("connection",(function(s){var r;if(!e.connectionshttp[t]){e.connectionshttp[t]=new Set}var o=((r=e.connectionshttp[t])===null||r===void 0?void 0:r.size)||0;if(o>=m){try{e.$log("★","HTTP Connection MAX rejected (".concat(o,"/").concat(m,")"));s.destroy()}catch(t){e.$log("★","Close connection error:",t)}return}e.connectionshttp[t].add(s);s.on("close",(function(){e.connectionshttp[t].delete(s)}));s.setTimeout(3e5)}))}return e.servershttp[t]}return}function getHTTPServer(t,r){if(t===void 0){t=""}if(r===void 0){r={}}var o=s(611);var n=s(692);try{if(t.startsWith("https")){n.AsCreateServer=function(t){return n.createServer((r===null||r===void 0?void 0:r.httpscert)||e.hostconfig.httpscert,t)};return n}else{o.AsCreateServer=o.createServer;return o}}catch(t){e.$log("●","Http server error:",JSON.stringify(t));o.AsCreateServer=o.createServer;return o}}function startProxyServer(t){var s=getProxyHostCFG(t);if(s.url){try{var r=getHTTPServer(s.proxyhttptype,s);var o=r.AsCreateServer((function(t,r){if(s.redirect){r.writeHead(301,{Location:s.url+t.url,"Strict-Transport-Security":"max-age=31536000"});r.end()}else{var o=new URL(s.url+t.url);var n=o.protocol==="https:";var i=getHTTPServer(s.url,s);var a={keepAlive:s.keepAlive||true,timeout:s.timeout||6e4,keepAliveMsecs:s.keepAliveMsecs||3e4,maxSockets:s.maxSockets||1e3,maxFreeSockets:s.maxFreeSockets||100,rejectUnauthorized:s.rejectUnauthorized||false,secureProtocol:s.secureProtocol||"TLS_method"};var c=new i.Agent(a);var l={agent:c,method:t.method,hostname:o.hostname,port:o.port||(n?443:80),path:o.pathname+o.search,headers:t.headers};if(n){l.servername=o.hostname}var f=i.request(l,(function(e){Object.keys(e.headers).forEach((function(t){var s=["transfer-encoding","connection","keep-alive","proxy-authenticate","proxy-authorization","te","trailers","upgrade"];if(!s.includes(t.toLowerCase())){r.setHeader(t,e.headers[t])}}));r.statusCode=e.statusCode;var s=getHttpUserinfo(t);s&&r.setHeader("Userinfo",s);e.pipe(r,{end:true})}));t.pipe(f,{end:true});t.on("error",(function(t){e.$log("●","Client request error:",t);f.destroy()}));f.on("error",(function(t){e.$log("●","Forward request error:",t);e.$log("●","Target: ".concat(o.href,", HTTPS: ").concat(n));if(!r.headersSent){r.writeHead(502,{"Content-Type":"text/plain; charset=utf-8"})}r.end("Bad Gateway: "+t.message)}));f.setTimeout(12e4,(function(){e.$log("★","Forward request timeout");f.destroy();if(!r.headersSent){r.writeHead(504,{"Content-Type":"text/plain; charset=utf-8"})}r.end("Gateway Timeout")}))}}));o.on("error",(function(t){if(t.code==="EADDRINUSE"){e.$log("★","[41mPort ".concat(s.proxyport," is already start![0m"))}else{e.$log("★","Proxy server error:",t)}}));var n=getHostIP(s.proxyip);if(n){o.listen(s.proxyport,n,(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));console.log("[45;28mProxy Server ".concat(s.proxyhttptype).concat(n,":").concat(s.proxyport,"[0m"));console.log("[46;28mTarget Server ".concat(s.url,"[0m"));console.log("================================================")}))}else{o.listen(s.proxyport,(function(){console.log("[".concat(t,"] Start At ").concat(getNowTime(),"."));console.log("[45;28mProxy server ".concat(s.proxyhttptype,"localhost:").concat(s.proxyport,"[0m"));console.log("[46;28mTarget Server ".concat(s.url,"[0m"));console.log("================================================")}))}}catch(t){e.$log("●","Proxy server error:",JSON.stringify(t))}}}function asaiGuard(){var t;if(e.hostconfig.asaiport.includes(e.hostconfig.hosts.asai.port)){process.exit(1)}else{if(e.hostconfig.guardtm){clearTimeout(e.hostconfig.guardtm);e.hostconfig.guardtm=null}e.hostconfig.guardtm=setTimeout((function(){startHTTPServer("asai");clearTimeout(e.hostconfig.guardtm);e.hostconfig.guardtm=null}),((t=e.hostconfig.tm)===null||t===void 0?void 0:t.d)||2e3)}}function getWsUserinfo(e){var t;try{var s=Object.fromEntries(Array.from({length:e.rawHeaders.length/2},(function(t,s){return[e.rawHeaders[s*2].toLowerCase(),e.rawHeaders[s*2+1]]})));var r=(t=s["sec-websocket-protocol"])===null||t===void 0?void 0:t.split("##");return deUserInfo(r)}catch(e){}return null}function getHttpUserinfo(e){var t;try{var s=Object.fromEntries(Array.from({length:e.rawHeaders.length/2},(function(t,s){return[e.rawHeaders[s*2].toLowerCase(),e.rawHeaders[s*2+1]]})));var r=(t=s["userinfo"])===null||t===void 0?void 0:t.split("##");return deUserInfo(r)}catch(e){}return""}function checkHttpHeader(e){e.Userinfo=getHttpUserinfo(e);return true}function deUserInfo(t){if(!Array.isArray(t)||t.length<3){return t}if(t[2]){try{t[2]=e.$lib.AsCode.asdecode(t[2],e.hostconfig.asaisn);t[0]=e.$lib.AsCode.asdecode(t[0],t[2]);t[1]=e.$lib.AsCode.asdecode(t[1],t[2])}catch(t){e.$log("●","User info decode error:",t)}}return t}function clearWsServerTasks(t){if(e.tasksws[t]&&typeof e.tasksws[t]==="object"){Object.values(e.tasksws[t]).forEach((function(e){e&&clearInterval(e)}));e.tasksws[t]={}}}function _resWsMsg(t){var s,r,o;if(t==="ping"||t==="pong"){}else if(typeof t==="object"){if(((t===null||t===void 0?void 0:t.aes)||((s=e.$lib.aesfns)===null||s===void 0?void 0:s.allaes))&&(t===null||t===void 0?void 0:t.db)&&((o=(r=e.$lib)===null||r===void 0?void 0:r.aesfns)===null||o===void 0?void 0:o.resAES)){t.db=e.$lib.aesfns.resAES(t.db)}t=JSON.stringify(t)}return t}function createWSHost(t){var r=getHostCFG(t);try{if(!e.serversws[t]){var o=s(354),n=o.WebSocket,i=o.WebSocketServer;if(r.ckws){if(!e.connectionsws[t]){e.connectionsws[t]=new WeakMap}}if(!e.tasksws[t]){e.tasksws[t]={}}e.serversws[t]=new i({server:e.servershttp[t],perMessageDeflate:false});e.serversws[t].sendws=function(s,r,o){s=_resWsMsg(s);if(r){e.serversws[t].clients.forEach((function(e){if((r==2||e!==o)&&e.readyState==n.OPEN){e.send(s)}}))}else{o.send(s)}};e.serversws[t].broadws=function(s){var r,o;s=_resWsMsg(s);(o=(r=e.serversws[t])===null||r===void 0?void 0:r.clients)===null||o===void 0?void 0:o.forEach((function(e){var t;if(e&&(e===null||e===void 0?void 0:e.readyState)==(n===null||n===void 0?void 0:n.OPEN)&&typeof(e===null||e===void 0?void 0:e.send)==="function"){(t=e===null||e===void 0?void 0:e.send)===null||t===void 0?void 0:t.call(e,s)}}))};e.serversws[t].on("error",(function(s){clearWsServerTasks(t);e.$log("●","WS Server error!",s);if(typeof e.serversws[t].close==="function"){e.serversws[t].close((function(){e.$log("●","WS Server closed");delete e.serversws[t]}))}}));e.serversws[t].on("close",(function(s,r){try{e.$log("●","WebSocket closed, server ".concat(t,", code: ").concat(s,", reason: ").concat(r));clearWsServerTasks(t)}catch(t){e.$log("★","WS close handler error:",t)}}));e.serversws[t].on("connection",(function(s,o){var n=r.maxws||100;var i=Object.keys(e.connectionsws[t]||{}).length;if(i>=n){e.$log("★","WS Connection MAX rejected (".concat(i,"/").concat(n,")"));s.send(JSON.stringify({ty:"publish/web",db:{exit:1,type:"err",lang:"maxws",langpm:"".concat(n),con:"max ".concat(n," clients online!")}}));s.close(1013,"Server busy");return}o.Userinfo=getWsUserinfo(o)||[];s.Userinfo=o.Userinfo;var a=true;if(r.ckws){a=isOkWs(t,s,o)}if(a){loginWs(t,s,o)}else{s.close()}}))}}catch(t){e.$log("●","ws server:",JSON.stringify(t))}return e.serversws[t]}function isOkWs(t,s,r){var o,n;var i=getHostCFG(t);var a=s.Userinfo,c=a[0],l=a[1],f=a[2];if(c){if(c==="asai"){}else if(e.connectionsws[t][c]){var h={ty:"publish/web",db:{exit:1,type:"err",lang:"logged",langpm:"".concat(c),con:"".concat(c," logged in!")}};checkWsIsOn(e.connectionsws[t][c]);if(((n=(o=e.connectionsws[t][c])===null||o===void 0?void 0:o.Userinfo)===null||n===void 0?void 0:n[2])===f){h.db.lang="loggedsametk";s.send(JSON.stringify(h));e.connectionsws[t][c].send(JSON.stringify(h));e.connectionsws[t][c].close()}else{s.send(JSON.stringify(h))}return false}else{var u=Object.values(e.connectionsws[t]).find((function(e){var t;return((t=e.Userinfo)===null||t===void 0?void 0:t[2])===f}));var d=i.maxonline||100;if(u){var h={ty:"publish/web",db:{exit:1,type:"err",lang:"loggedsametk",langpm:"".concat(c,"(").concat(u.Userinfo[0],")"),con:"".concat(c,"(").concat(u.Userinfo[0],") logged in!")}};s.send(JSON.stringify(h));u.send(JSON.stringify(h));u.close();return false}else if(Object.keys(e.connectionsws[t]).length>=d){s.send(JSON.stringify({ty:"publish/web",db:{exit:1,type:"err",lang:"maxlogged",langpm:"".concat(d),con:"max ".concat(d," users online!")}}));return false}}}else{s.send(JSON.stringify({ty:"publish/web",db:{exit:1,type:"err",lang:"nousername",con:"no username!"}}));return false}return true}function checkWsIsOn(t){var s,r;if(t){try{t.send(JSON.stringify({ty:"publish/web",db:"pong"}));var o=setTimeout((function(){if(typeof t.terminate==="function"){t.terminate()}if(typeof t.close==="function"){t.close()}}),((r=(s=e===null||e===void 0?void 0:e.hostconfig)===null||s===void 0?void 0:s.tm)===null||r===void 0?void 0:r.d)||3e3);if(typeof t.once==="function"){t.once("message",(function(e){if(o){clearTimeout(o);o=null}}))}}catch(e){}}}function loginWs(t,s,r){var o=s.Userinfo,n=o[0],i=o[1],a=o[2];var l=getHostCFG(t);if(l.ckws&&n){if(!(s===null||s===void 0?void 0:s.tasksws)){s.tasksws={}}e.connectionsws[t][n]=s}s.on("message",(function(e){c(e,s,t,r)}));s.on("close",(function(r){if(l.ckws){if(s.tasksws&&typeof s.tasksws==="object"){Object.values(s.tasksws).forEach((function(e){e&&clearInterval(e)}));s.tasksws=null}if(n&&e.connectionsws[t][n]){delete e.connectionsws[t][n]}}typeof s.close=="function"&&s.close()}))}function getNowTime(e){if(e===void 0){e=0}try{var t=new Date(Date.now());var s=t.getFullYear();var r=String(t.getMonth()+1).padStart(2,"0");var o=String(t.getDate()).padStart(2,"0");var n=String(t.getHours()).padStart(2,"0");var i=String(t.getMinutes()).padStart(2,"0");var a=String(t.getSeconds()).padStart(2,"0");if(e==2){return"".concat(s,"-").concat(r,"-").concat(o)}else if(e==1){return"".concat(n,":").concat(i,":").concat(a)}return"".concat(s,"-").concat(r,"-").concat(o," ").concat(n,":").concat(i,":").concat(a)}catch(e){console.error("Date formatting error:",e);return"unknown-time"}}function getIp(){try{var t=s(857);var r=t.networkInterfaces();for(var o in r){var n=r[o];if(!n)continue;for(var i=0,a=n;i<a.length;i++){var c=a[i];if(c.family==="IPv4"&&c.address!=="127.0.0.1"&&!c.internal){return c.address}}}}catch(t){e.$log("●","Get IP address error:",t)}return"127.0.0.1"}function validateHostdir(e){if(typeof e!=="string"||e.length===0||e.length>100||e==="default"||e==="asai"){return false}return/^[a-zA-Z0-9_-]+$/.test(e)}function StartAsaiHost(){var t,s;initAsaiHost();console.log("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※");if((t=e.hostconfig)===null||t===void 0?void 0:t.hosts){e.startHTTPServer=startHTTPServer;Object.keys(e.hostconfig.hosts).forEach((function(e){if(validateHostdir(e)){startHTTPServer(e)}}))}if((s=e.hostconfig)===null||s===void 0?void 0:s.proxyhosts){Object.keys(e.hostconfig.proxyhosts).forEach((function(e){if(validateHostdir(e)){startProxyServer(e)}}))}}return{StartAsaiHost:StartAsaiHost,asaiWs:n}}},354:(e,t,s)=>{"use strict";const r=s(681);r.createWebSocketStream=s(412);r.Server=s(129);r.Receiver=s(893);r.Sender=s(389);r.WebSocket=r;r.WebSocketServer=r.Server;e.exports=r},803:(e,t,s)=>{"use strict";const{EMPTY_BUFFER:r}=s(791);const o=Buffer[Symbol.species];function concat(e,t){if(e.length===0)return r;if(e.length===1)return e[0];const s=Buffer.allocUnsafe(t);let n=0;for(let t=0;t<e.length;t++){const r=e[t];s.set(r,n);n+=r.length}if(n<t){return new o(s.buffer,s.byteOffset,n)}return s}function _mask(e,t,s,r,o){for(let n=0;n<o;n++){s[r+n]=e[n]^t[n&3]}}function _unmask(e,t){for(let s=0;s<e.length;s++){e[s]^=t[s&3]}}function toArrayBuffer(e){if(e.length===e.buffer.byteLength){return e.buffer}return e.buffer.slice(e.byteOffset,e.byteOffset+e.length)}function toBuffer(e){toBuffer.readOnly=true;if(Buffer.isBuffer(e))return e;let t;if(e instanceof ArrayBuffer){t=new o(e)}else if(ArrayBuffer.isView(e)){t=new o(e.buffer,e.byteOffset,e.byteLength)}else{t=Buffer.from(e);toBuffer.readOnly=false}return t}e.exports={concat:concat,mask:_mask,toArrayBuffer:toArrayBuffer,toBuffer:toBuffer,unmask:_unmask};if(!process.env.WS_NO_BUFFER_UTIL){try{const t=s(327);e.exports.mask=function(e,s,r,o,n){if(n<48)_mask(e,s,r,o,n);else t.mask(e,s,r,o,n)};e.exports.unmask=function(e,s){if(e.length<32)_unmask(e,s);else t.unmask(e,s)}}catch(e){}}},791:e=>{"use strict";const t=["nodebuffer","arraybuffer","fragments"];const s=typeof Blob!=="undefined";if(s)t.push("blob");e.exports={BINARY_TYPES:t,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:s,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}},634:(e,t,s)=>{"use strict";const{kForOnEventAttribute:r,kListener:o}=s(791);const n=Symbol("kCode");const i=Symbol("kData");const a=Symbol("kError");const c=Symbol("kMessage");const l=Symbol("kReason");const f=Symbol("kTarget");const h=Symbol("kType");const u=Symbol("kWasClean");class Event{constructor(e){this[f]=null;this[h]=e}get target(){return this[f]}get type(){return this[h]}}Object.defineProperty(Event.prototype,"target",{enumerable:true});Object.defineProperty(Event.prototype,"type",{enumerable:true});class CloseEvent extends Event{constructor(e,t={}){super(e);this[n]=t.code===undefined?0:t.code;this[l]=t.reason===undefined?"":t.reason;this[u]=t.wasClean===undefined?false:t.wasClean}get code(){return this[n]}get reason(){return this[l]}get wasClean(){return this[u]}}Object.defineProperty(CloseEvent.prototype,"code",{enumerable:true});Object.defineProperty(CloseEvent.prototype,"reason",{enumerable:true});Object.defineProperty(CloseEvent.prototype,"wasClean",{enumerable:true});class ErrorEvent extends Event{constructor(e,t={}){super(e);this[a]=t.error===undefined?null:t.error;this[c]=t.message===undefined?"":t.message}get error(){return this[a]}get message(){return this[c]}}Object.defineProperty(ErrorEvent.prototype,"error",{enumerable:true});Object.defineProperty(ErrorEvent.prototype,"message",{enumerable:true});class MessageEvent extends Event{constructor(e,t={}){super(e);this[i]=t.data===undefined?null:t.data}get data(){return this[i]}}Object.defineProperty(MessageEvent.prototype,"data",{enumerable:true});const d={addEventListener(e,t,s={}){for(const n of this.listeners(e)){if(!s[r]&&n[o]===t&&!n[r]){return}}let n;if(e==="message"){n=function onMessage(e,s){const r=new MessageEvent("message",{data:s?e:e.toString()});r[f]=this;callListener(t,this,r)}}else if(e==="close"){n=function onClose(e,s){const r=new CloseEvent("close",{code:e,reason:s.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});r[f]=this;callListener(t,this,r)}}else if(e==="error"){n=function onError(e){const s=new ErrorEvent("error",{error:e,message:e.message});s[f]=this;callListener(t,this,s)}}else if(e==="open"){n=function onOpen(){const e=new Event("open");e[f]=this;callListener(t,this,e)}}else{return}n[r]=!!s[r];n[o]=t;if(s.once){this.once(e,n)}else{this.on(e,n)}},removeEventListener(e,t){for(const s of this.listeners(e)){if(s[o]===t&&!s[r]){this.removeListener(e,s);break}}}};e.exports={CloseEvent:CloseEvent,ErrorEvent:ErrorEvent,Event:Event,EventTarget:d,MessageEvent:MessageEvent};function callListener(e,t,s){if(typeof e==="object"&&e.handleEvent){e.handleEvent.call(e,s)}else{e.call(t,s)}}},335:(e,t,s)=>{"use strict";const{tokenChars:r}=s(615);function push(e,t,s){if(e[t]===undefined)e[t]=[s];else e[t].push(s)}function parse(e){const t=Object.create(null);let s=Object.create(null);let o=false;let n=false;let i=false;let a;let c;let l=-1;let f=-1;let h=-1;let u=0;for(;u<e.length;u++){f=e.charCodeAt(u);if(a===undefined){if(h===-1&&r[f]===1){if(l===-1)l=u}else if(u!==0&&(f===32||f===9)){if(h===-1&&l!==-1)h=u}else if(f===59||f===44){if(l===-1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(h===-1)h=u;const r=e.slice(l,h);if(f===44){push(t,r,s);s=Object.create(null)}else{a=r}l=h=-1}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}else if(c===undefined){if(h===-1&&r[f]===1){if(l===-1)l=u}else if(f===32||f===9){if(h===-1&&l!==-1)h=u}else if(f===59||f===44){if(l===-1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(h===-1)h=u;push(s,e.slice(l,h),true);if(f===44){push(t,a,s);s=Object.create(null);a=undefined}l=h=-1}else if(f===61&&l!==-1&&h===-1){c=e.slice(l,u);l=h=-1}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}else{if(n){if(r[f]!==1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(l===-1)l=u;else if(!o)o=true;n=false}else if(i){if(r[f]===1){if(l===-1)l=u}else if(f===34&&l!==-1){i=false;h=u}else if(f===92){n=true}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}else if(f===34&&e.charCodeAt(u-1)===61){i=true}else if(h===-1&&r[f]===1){if(l===-1)l=u}else if(l!==-1&&(f===32||f===9)){if(h===-1)h=u}else if(f===59||f===44){if(l===-1){throw new SyntaxError(`Unexpected character at index ${u}`)}if(h===-1)h=u;let r=e.slice(l,h);if(o){r=r.replace(/\\/g,"");o=false}push(s,c,r);if(f===44){push(t,a,s);s=Object.create(null);a=undefined}c=undefined;l=h=-1}else{throw new SyntaxError(`Unexpected character at index ${u}`)}}}if(l===-1||i||f===32||f===9){throw new SyntaxError("Unexpected end of input")}if(h===-1)h=u;const d=e.slice(l,h);if(a===undefined){push(t,d,s)}else{if(c===undefined){push(s,d,true)}else if(o){push(s,c,d.replace(/\\/g,""))}else{push(s,c,d)}push(t,a,s)}return t}function format(e){return Object.keys(e).map((t=>{let s=e[t];if(!Array.isArray(s))s=[s];return s.map((e=>[t].concat(Object.keys(e).map((t=>{let s=e[t];if(!Array.isArray(s))s=[s];return s.map((e=>e===true?t:`${t}=${e}`)).join("; ")}))).join("; "))).join(", ")})).join(", ")}e.exports={format:format,parse:parse}},958:e=>{"use strict";const t=Symbol("kDone");const s=Symbol("kRun");class Limiter{constructor(e){this[t]=()=>{this.pending--;this[s]()};this.concurrency=e||Infinity;this.jobs=[];this.pending=0}add(e){this.jobs.push(e);this[s]()}[s](){if(this.pending===this.concurrency)return;if(this.jobs.length){const e=this.jobs.shift();this.pending++;e(this[t])}}}e.exports=Limiter},376:(e,t,s)=>{"use strict";const r=s(106);const o=s(803);const n=s(958);const{kStatusCode:i}=s(791);const a=Buffer[Symbol.species];const c=Buffer.from([0,0,255,255]);const l=Symbol("permessage-deflate");const f=Symbol("total-length");const h=Symbol("callback");const u=Symbol("buffers");const d=Symbol("error");let p;class PerMessageDeflate{constructor(e,t,s){this._maxPayload=s|0;this._options=e||{};this._threshold=this._options.threshold!==undefined?this._options.threshold:1024;this._isServer=!!t;this._deflate=null;this._inflate=null;this.params=null;if(!p){const e=this._options.concurrencyLimit!==undefined?this._options.concurrencyLimit:10;p=new n(e)}}static get extensionName(){return"permessage-deflate"}offer(){const e={};if(this._options.serverNoContextTakeover){e.server_no_context_takeover=true}if(this._options.clientNoContextTakeover){e.client_no_context_takeover=true}if(this._options.serverMaxWindowBits){e.server_max_window_bits=this._options.serverMaxWindowBits}if(this._options.clientMaxWindowBits){e.client_max_window_bits=this._options.clientMaxWindowBits}else if(this._options.clientMaxWindowBits==null){e.client_max_window_bits=true}return e}accept(e){e=this.normalizeParams(e);this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e);return this.params}cleanup(){if(this._inflate){this._inflate.close();this._inflate=null}if(this._deflate){const e=this._deflate[h];this._deflate.close();this._deflate=null;if(e){e(new Error("The deflate stream was closed while data was being processed"))}}}acceptAsServer(e){const t=this._options;const s=e.find((e=>{if(t.serverNoContextTakeover===false&&e.server_no_context_takeover||e.server_max_window_bits&&(t.serverMaxWindowBits===false||typeof t.serverMaxWindowBits==="number"&&t.serverMaxWindowBits>e.server_max_window_bits)||typeof t.clientMaxWindowBits==="number"&&!e.client_max_window_bits){return false}return true}));if(!s){throw new Error("None of the extension offers can be accepted")}if(t.serverNoContextTakeover){s.server_no_context_takeover=true}if(t.clientNoContextTakeover){s.client_no_context_takeover=true}if(typeof t.serverMaxWindowBits==="number"){s.server_max_window_bits=t.serverMaxWindowBits}if(typeof t.clientMaxWindowBits==="number"){s.client_max_window_bits=t.clientMaxWindowBits}else if(s.client_max_window_bits===true||t.clientMaxWindowBits===false){delete s.client_max_window_bits}return s}acceptAsClient(e){const t=e[0];if(this._options.clientNoContextTakeover===false&&t.client_no_context_takeover){throw new Error('Unexpected parameter "client_no_context_takeover"')}if(!t.client_max_window_bits){if(typeof this._options.clientMaxWindowBits==="number"){t.client_max_window_bits=this._options.clientMaxWindowBits}}else if(this._options.clientMaxWindowBits===false||typeof this._options.clientMaxWindowBits==="number"&&t.client_max_window_bits>this._options.clientMaxWindowBits){throw new Error('Unexpected or invalid parameter "client_max_window_bits"')}return t}normalizeParams(e){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`)}s=s[0];if(t==="client_max_window_bits"){if(s!==true){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(t==="server_max_window_bits"){const e=+s;if(!Number.isInteger(e)||e<8||e>15){throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}s=e}else if(t==="client_no_context_takeover"||t==="server_no_context_takeover"){if(s!==true){throw new TypeError(`Invalid value for parameter "${t}": ${s}`)}}else{throw new Error(`Unknown parameter "${t}"`)}e[t]=s}))}));return e}decompress(e,t,s){p.add((r=>{this._decompress(e,t,((e,t)=>{r();s(e,t)}))}))}compress(e,t,s){p.add((r=>{this._compress(e,t,((e,t)=>{r();s(e,t)}))}))}_decompress(e,t,s){const n=this._isServer?"client":"server";if(!this._inflate){const e=`${n}_max_window_bits`;const t=typeof this.params[e]!=="number"?r.Z_DEFAULT_WINDOWBITS:this.params[e];this._inflate=r.createInflateRaw({...this._options.zlibInflateOptions,windowBits:t});this._inflate[l]=this;this._inflate[f]=0;this._inflate[u]=[];this._inflate.on("error",inflateOnError);this._inflate.on("data",inflateOnData)}this._inflate[h]=s;this._inflate.write(e);if(t)this._inflate.write(c);this._inflate.flush((()=>{const e=this._inflate[d];if(e){this._inflate.close();this._inflate=null;s(e);return}const r=o.concat(this._inflate[u],this._inflate[f]);if(this._inflate._readableState.endEmitted){this._inflate.close();this._inflate=null}else{this._inflate[f]=0;this._inflate[u]=[];if(t&&this.params[`${n}_no_context_takeover`]){this._inflate.reset()}}s(null,r)}))}_compress(e,t,s){const n=this._isServer?"server":"client";if(!this._deflate){const e=`${n}_max_window_bits`;const t=typeof this.params[e]!=="number"?r.Z_DEFAULT_WINDOWBITS:this.params[e];this._deflate=r.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:t});this._deflate[f]=0;this._deflate[u]=[];this._deflate.on("data",deflateOnData)}this._deflate[h]=s;this._deflate.write(e);this._deflate.flush(r.Z_SYNC_FLUSH,(()=>{if(!this._deflate){return}let e=o.concat(this._deflate[u],this._deflate[f]);if(t){e=new a(e.buffer,e.byteOffset,e.length-4)}this._deflate[h]=null;this._deflate[f]=0;this._deflate[u]=[];if(t&&this.params[`${n}_no_context_takeover`]){this._deflate.reset()}s(null,e)}))}}e.exports=PerMessageDeflate;function deflateOnData(e){this[u].push(e);this[f]+=e.length}function inflateOnData(e){this[f]+=e.length;if(this[l]._maxPayload<1||this[f]<=this[l]._maxPayload){this[u].push(e);return}this[d]=new RangeError("Max payload size exceeded");this[d].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";this[d][i]=1009;this.removeListener("data",inflateOnData);this.reset()}function inflateOnError(e){this[l]._inflate=null;if(this[d]){this[h](this[d]);return}e[i]=1007;this[h](e)}},893:(e,t,s)=>{"use strict";const{Writable:r}=s(203);const o=s(376);const{BINARY_TYPES:n,EMPTY_BUFFER:i,kStatusCode:a,kWebSocket:c}=s(791);const{concat:l,toArrayBuffer:f,unmask:h}=s(803);const{isValidStatusCode:u,isValidUTF8:d}=s(615);const p=Buffer[Symbol.species];const _=0;const v=1;const g=2;const m=3;const y=4;const b=5;const S=6;class Receiver extends r{constructor(e={}){super();this._allowSynchronousEvents=e.allowSynchronousEvents!==undefined?e.allowSynchronousEvents:true;this._binaryType=e.binaryType||n[0];this._extensions=e.extensions||{};this._isServer=!!e.isServer;this._maxPayload=e.maxPayload|0;this._skipUTF8Validation=!!e.skipUTF8Validation;this[c]=undefined;this._bufferedBytes=0;this._buffers=[];this._compressed=false;this._payloadLength=0;this._mask=undefined;this._fragmented=0;this._masked=false;this._fin=false;this._opcode=0;this._totalPayloadLength=0;this._messageLength=0;this._fragments=[];this._errored=false;this._loop=false;this._state=_}_write(e,t,s){if(this._opcode===8&&this._state==_)return s();this._bufferedBytes+=e.length;this._buffers.push(e);this.startLoop(s)}consume(e){this._bufferedBytes-=e;if(e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){const t=this._buffers[0];this._buffers[0]=new p(t.buffer,t.byteOffset+e,t.length-e);return new p(t.buffer,t.byteOffset,e)}const t=Buffer.allocUnsafe(e);do{const s=this._buffers[0];const r=t.length-e;if(e>=s.length){t.set(this._buffers.shift(),r)}else{t.set(new Uint8Array(s.buffer,s.byteOffset,e),r);this._buffers[0]=new p(s.buffer,s.byteOffset+e,s.length-e)}e-=s.length}while(e>0);return t}startLoop(e){this._loop=true;do{switch(this._state){case _:this.getInfo(e);break;case v:this.getPayloadLength16(e);break;case g:this.getPayloadLength64(e);break;case m:this.getMask();break;case y:this.getData(e);break;case b:case S:this._loop=false;return}}while(this._loop);if(!this._errored)e()}getInfo(e){if(this._bufferedBytes<2){this._loop=false;return}const t=this.consume(2);if((t[0]&48)!==0){const t=this.createError(RangeError,"RSV2 and RSV3 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(t);return}const s=(t[0]&64)===64;if(s&&!this._extensions[o.extensionName]){const t=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(t);return}this._fin=(t[0]&128)===128;this._opcode=t[0]&15;this._payloadLength=t[1]&127;if(this._opcode===0){if(s){const t=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(t);return}if(!this._fragmented){const t=this.createError(RangeError,"invalid opcode 0",true,1002,"WS_ERR_INVALID_OPCODE");e(t);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){const t=this.createError(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE");e(t);return}this._compressed=s}else if(this._opcode>7&&this._opcode<11){if(!this._fin){const t=this.createError(RangeError,"FIN must be set",true,1002,"WS_ERR_EXPECTED_FIN");e(t);return}if(s){const t=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(t);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){const t=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,true,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(t);return}}else{const t=this.createError(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE");e(t);return}if(!this._fin&&!this._fragmented)this._fragmented=this._opcode;this._masked=(t[1]&128)===128;if(this._isServer){if(!this._masked){const t=this.createError(RangeError,"MASK must be set",true,1002,"WS_ERR_EXPECTED_MASK");e(t);return}}else if(this._masked){const t=this.createError(RangeError,"MASK must be clear",true,1002,"WS_ERR_UNEXPECTED_MASK");e(t);return}if(this._payloadLength===126)this._state=v;else if(this._payloadLength===127)this._state=g;else this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=false;return}this._payloadLength=this.consume(2).readUInt16BE(0);this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=false;return}const t=this.consume(8);const s=t.readUInt32BE(0);if(s>Math.pow(2,53-32)-1){const t=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",false,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(t);return}this._payloadLength=s*Math.pow(2,32)+t.readUInt32BE(4);this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8){this._totalPayloadLength+=this._payloadLength;if(this._totalPayloadLength>this._maxPayload&&this._maxPayload>0){const t=this.createError(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(t);return}}if(this._masked)this._state=m;else this._state=y}getMask(){if(this._bufferedBytes<4){this._loop=false;return}this._mask=this.consume(4);this._state=y}getData(e){let t=i;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=false;return}t=this.consume(this._payloadLength);if(this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0){h(t,this._mask)}}if(this._opcode>7){this.controlMessage(t,e);return}if(this._compressed){this._state=b;this.decompress(t,e);return}if(t.length){this._messageLength=this._totalPayloadLength;this._fragments.push(t)}this.dataMessage(e)}decompress(e,t){const s=this._extensions[o.extensionName];s.decompress(e,this._fin,((e,s)=>{if(e)return t(e);if(s.length){this._messageLength+=s.length;if(this._messageLength>this._maxPayload&&this._maxPayload>0){const e=this.createError(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");t(e);return}this._fragments.push(s)}this.dataMessage(t);if(this._state===_)this.startLoop(t)}))}dataMessage(e){if(!this._fin){this._state=_;return}const t=this._messageLength;const s=this._fragments;this._totalPayloadLength=0;this._messageLength=0;this._fragmented=0;this._fragments=[];if(this._opcode===2){let r;if(this._binaryType==="nodebuffer"){r=l(s,t)}else if(this._binaryType==="arraybuffer"){r=f(l(s,t))}else if(this._binaryType==="blob"){r=new Blob(s)}else{r=s}if(this._allowSynchronousEvents){this.emit("message",r,true);this._state=_}else{this._state=S;setImmediate((()=>{this.emit("message",r,true);this._state=_;this.startLoop(e)}))}}else{const r=l(s,t);if(!this._skipUTF8Validation&&!d(r)){const t=this.createError(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8");e(t);return}if(this._state===b||this._allowSynchronousEvents){this.emit("message",r,false);this._state=_}else{this._state=S;setImmediate((()=>{this.emit("message",r,false);this._state=_;this.startLoop(e)}))}}}controlMessage(e,t){if(this._opcode===8){if(e.length===0){this._loop=false;this.emit("conclude",1005,i);this.end()}else{const s=e.readUInt16BE(0);if(!u(s)){const e=this.createError(RangeError,`invalid status code ${s}`,true,1002,"WS_ERR_INVALID_CLOSE_CODE");t(e);return}const r=new p(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!d(r)){const e=this.createError(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8");t(e);return}this._loop=false;this.emit("conclude",s,r);this.end()}this._state=_;return}if(this._allowSynchronousEvents){this.emit(this._opcode===9?"ping":"pong",e);this._state=_}else{this._state=S;setImmediate((()=>{this.emit(this._opcode===9?"ping":"pong",e);this._state=_;this.startLoop(t)}))}}createError(e,t,s,r,o){this._loop=false;this._errored=true;const n=new e(s?`Invalid WebSocket frame: ${t}`:t);Error.captureStackTrace(n,this.createError);n.code=o;n[a]=r;return n}}e.exports=Receiver},389:(e,t,s)=>{"use strict";const{Duplex:r}=s(203);const{randomFillSync:o}=s(982);const n=s(376);const{EMPTY_BUFFER:i,kWebSocket:a,NOOP:c}=s(791);const{isBlob:l,isValidStatusCode:f}=s(615);const{mask:h,toBuffer:u}=s(803);const d=Symbol("kByteLength");const p=Buffer.alloc(4);const _=8*1024;let v;let g=_;const m=0;const y=1;const b=2;class Sender{constructor(e,t,s){this._extensions=t||{};if(s){this._generateMask=s;this._maskBuffer=Buffer.alloc(4)}this._socket=e;this._firstFragment=true;this._compress=false;this._bufferedBytes=0;this._queue=[];this._state=m;this.onerror=c;this[a]=undefined}static frame(e,t){let s;let r=false;let n=2;let i=false;if(t.mask){s=t.maskBuffer||p;if(t.generateMask){t.generateMask(s)}else{if(g===_){if(v===undefined){v=Buffer.alloc(_)}o(v,0,_);g=0}s[0]=v[g++];s[1]=v[g++];s[2]=v[g++];s[3]=v[g++]}i=(s[0]|s[1]|s[2]|s[3])===0;n=6}let a;if(typeof e==="string"){if((!t.mask||i)&&t[d]!==undefined){a=t[d]}else{e=Buffer.from(e);a=e.length}}else{a=e.length;r=t.mask&&t.readOnly&&!i}let c=a;if(a>=65536){n+=8;c=127}else if(a>125){n+=2;c=126}const l=Buffer.allocUnsafe(r?a+n:n);l[0]=t.fin?t.opcode|128:t.opcode;if(t.rsv1)l[0]|=64;l[1]=c;if(c===126){l.writeUInt16BE(a,2)}else if(c===127){l[2]=l[3]=0;l.writeUIntBE(a,4,6)}if(!t.mask)return[l,e];l[1]|=128;l[n-4]=s[0];l[n-3]=s[1];l[n-2]=s[2];l[n-1]=s[3];if(i)return[l,e];if(r){h(e,s,l,n,a);return[l]}h(e,s,e,0,a);return[l,e]}close(e,t,s,r){let o;if(e===undefined){o=i}else if(typeof e!=="number"||!f(e)){throw new TypeError("First argument must be a valid error code number")}else if(t===undefined||!t.length){o=Buffer.allocUnsafe(2);o.writeUInt16BE(e,0)}else{const s=Buffer.byteLength(t);if(s>123){throw new RangeError("The message must not be greater than 123 bytes")}o=Buffer.allocUnsafe(2+s);o.writeUInt16BE(e,0);if(typeof t==="string"){o.write(t,2)}else{o.set(t,2)}}const n={[d]:o.length,fin:true,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:8,readOnly:false,rsv1:false};if(this._state!==m){this.enqueue([this.dispatch,o,false,n,r])}else{this.sendFrame(Sender.frame(o,n),r)}}ping(e,t,s){let r;let o;if(typeof e==="string"){r=Buffer.byteLength(e);o=false}else if(l(e)){r=e.size;o=false}else{e=u(e);r=e.length;o=u.readOnly}if(r>125){throw new RangeError("The data size must not be greater than 125 bytes")}const n={[d]:r,fin:true,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:9,readOnly:o,rsv1:false};if(l(e)){if(this._state!==m){this.enqueue([this.getBlobData,e,false,n,s])}else{this.getBlobData(e,false,n,s)}}else if(this._state!==m){this.enqueue([this.dispatch,e,false,n,s])}else{this.sendFrame(Sender.frame(e,n),s)}}pong(e,t,s){let r;let o;if(typeof e==="string"){r=Buffer.byteLength(e);o=false}else if(l(e)){r=e.size;o=false}else{e=u(e);r=e.length;o=u.readOnly}if(r>125){throw new RangeError("The data size must not be greater than 125 bytes")}const n={[d]:r,fin:true,generateMask:this._generateMask,mask:t,maskBuffer:this._maskBuffer,opcode:10,readOnly:o,rsv1:false};if(l(e)){if(this._state!==m){this.enqueue([this.getBlobData,e,false,n,s])}else{this.getBlobData(e,false,n,s)}}else if(this._state!==m){this.enqueue([this.dispatch,e,false,n,s])}else{this.sendFrame(Sender.frame(e,n),s)}}send(e,t,s){const r=this._extensions[n.extensionName];let o=t.binary?2:1;let i=t.compress;let a;let c;if(typeof e==="string"){a=Buffer.byteLength(e);c=false}else if(l(e)){a=e.size;c=false}else{e=u(e);a=e.length;c=u.readOnly}if(this._firstFragment){this._firstFragment=false;if(i&&r&&r.params[r._isServer?"server_no_context_takeover":"client_no_context_takeover"]){i=a>=r._threshold}this._compress=i}else{i=false;o=0}if(t.fin)this._firstFragment=true;const f={[d]:a,fin:t.fin,generateMask:this._generateMask,mask:t.mask,maskBuffer:this._maskBuffer,opcode:o,readOnly:c,rsv1:i};if(l(e)){if(this._state!==m){this.enqueue([this.getBlobData,e,this._compress,f,s])}else{this.getBlobData(e,this._compress,f,s)}}else if(this._state!==m){this.enqueue([this.dispatch,e,this._compress,f,s])}else{this.dispatch(e,this._compress,f,s)}}getBlobData(e,t,s,r){this._bufferedBytes+=s[d];this._state=b;e.arrayBuffer().then((e=>{if(this._socket.destroyed){const e=new Error("The socket was closed while the blob was being read");process.nextTick(callCallbacks,this,e,r);return}this._bufferedBytes-=s[d];const o=u(e);if(!t){this._state=m;this.sendFrame(Sender.frame(o,s),r);this.dequeue()}else{this.dispatch(o,t,s,r)}})).catch((e=>{process.nextTick(onError,this,e,r)}))}dispatch(e,t,s,r){if(!t){this.sendFrame(Sender.frame(e,s),r);return}const o=this._extensions[n.extensionName];this._bufferedBytes+=s[d];this._state=y;o.compress(e,s.fin,((e,t)=>{if(this._socket.destroyed){const e=new Error("The socket was closed while data was being compressed");callCallbacks(this,e,r);return}this._bufferedBytes-=s[d];this._state=m;s.readOnly=false;this.sendFrame(Sender.frame(t,s),r);this.dequeue()}))}dequeue(){while(this._state===m&&this._queue.length){const e=this._queue.shift();this._bufferedBytes-=e[3][d];Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][d];this._queue.push(e)}sendFrame(e,t){if(e.length===2){this._socket.cork();this._socket.write(e[0]);this._socket.write(e[1],t);this._socket.uncork()}else{this._socket.write(e[0],t)}}}e.exports=Sender;function callCallbacks(e,t,s){if(typeof s==="function")s(t);for(let s=0;s<e._queue.length;s++){const r=e._queue[s];const o=r[r.length-1];if(typeof o==="function")o(t)}}function onError(e,t,s){callCallbacks(e,t,s);e.onerror(t)}},412:(e,t,s)=>{"use strict";const r=s(681);const{Duplex:o}=s(203);function emitClose(e){e.emit("close")}function duplexOnEnd(){if(!this.destroyed&&this._writableState.finished){this.destroy()}}function duplexOnError(e){this.removeListener("error",duplexOnError);this.destroy();if(this.listenerCount("error")===0){this.emit("error",e)}}function createWebSocketStream(e,t){let s=true;const r=new o({...t,autoDestroy:false,emitClose:false,objectMode:false,writableObjectMode:false});e.on("message",(function message(t,s){const o=!s&&r._readableState.objectMode?t.toString():t;if(!r.push(o))e.pause()}));e.once("error",(function error(e){if(r.destroyed)return;s=false;r.destroy(e)}));e.once("close",(function close(){if(r.destroyed)return;r.push(null)}));r._destroy=function(t,o){if(e.readyState===e.CLOSED){o(t);process.nextTick(emitClose,r);return}let n=false;e.once("error",(function error(e){n=true;o(e)}));e.once("close",(function close(){if(!n)o(t);process.nextTick(emitClose,r)}));if(s)e.terminate()};r._final=function(t){if(e.readyState===e.CONNECTING){e.once("open",(function open(){r._final(t)}));return}if(e._socket===null)return;if(e._socket._writableState.finished){t();if(r._readableState.endEmitted)r.destroy()}else{e._socket.once("finish",(function finish(){t()}));e.close()}};r._read=function(){if(e.isPaused)e.resume()};r._write=function(t,s,o){if(e.readyState===e.CONNECTING){e.once("open",(function open(){r._write(t,s,o)}));return}e.send(t,o)};r.on("end",duplexOnEnd);r.on("error",duplexOnError);return r}e.exports=createWebSocketStream},332:(e,t,s)=>{"use strict";const{tokenChars:r}=s(615);function parse(e){const t=new Set;let s=-1;let o=-1;let n=0;for(n;n<e.length;n++){const i=e.charCodeAt(n);if(o===-1&&r[i]===1){if(s===-1)s=n}else if(n!==0&&(i===32||i===9)){if(o===-1&&s!==-1)o=n}else if(i===44){if(s===-1){throw new SyntaxError(`Unexpected character at index ${n}`)}if(o===-1)o=n;const r=e.slice(s,o);if(t.has(r)){throw new SyntaxError(`The "${r}" subprotocol is duplicated`)}t.add(r);s=o=-1}else{throw new SyntaxError(`Unexpected character at index ${n}`)}}if(s===-1||o!==-1){throw new SyntaxError("Unexpected end of input")}const i=e.slice(s,n);if(t.has(i)){throw new SyntaxError(`The "${i}" subprotocol is duplicated`)}t.add(i);return t}e.exports={parse:parse}},615:(e,t,s)=>{"use strict";const{isUtf8:r}=s(181);const{hasBlob:o}=s(791);const n=[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 isValidStatusCode(e){return e>=1e3&&e<=1014&&e!==1004&&e!==1005&&e!==1006||e>=3e3&&e<=4999}function _isValidUTF8(e){const t=e.length;let s=0;while(s<t){if((e[s]&128)===0){s++}else if((e[s]&224)===192){if(s+1===t||(e[s+1]&192)!==128||(e[s]&254)===192){return false}s+=2}else if((e[s]&240)===224){if(s+2>=t||(e[s+1]&192)!==128||(e[s+2]&192)!==128||e[s]===224&&(e[s+1]&224)===128||e[s]===237&&(e[s+1]&224)===160){return false}s+=3}else if((e[s]&248)===240){if(s+3>=t||(e[s+1]&192)!==128||(e[s+2]&192)!==128||(e[s+3]&192)!==128||e[s]===240&&(e[s+1]&240)===128||e[s]===244&&e[s+1]>143||e[s]>244){return false}s+=4}else{return false}}return true}function isBlob(e){return o&&typeof e==="object"&&typeof e.arrayBuffer==="function"&&typeof e.type==="string"&&typeof e.stream==="function"&&(e[Symbol.toStringTag]==="Blob"||e[Symbol.toStringTag]==="File")}e.exports={isBlob:isBlob,isValidStatusCode:isValidStatusCode,isValidUTF8:_isValidUTF8,tokenChars:n};if(r){e.exports.isValidUTF8=function(e){return e.length<24?_isValidUTF8(e):r(e)}}else if(!process.env.WS_NO_UTF_8_VALIDATE){try{const t=s(414);e.exports.isValidUTF8=function(e){return e.length<32?_isValidUTF8(e):t(e)}}catch(e){}}},129:(e,t,s)=>{"use strict";const r=s(434);const o=s(611);const{Duplex:n}=s(203);const{createHash:i}=s(982);const a=s(335);const c=s(376);const l=s(332);const f=s(681);const{GUID:h,kWebSocket:u}=s(791);const d=/^[+/0-9A-Za-z]{22}==$/;const p=0;const _=1;const v=2;class WebSocketServer extends r{constructor(e,t){super();e={allowSynchronousEvents:true,autoPong:true,maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:false,handleProtocols:null,clientTracking:true,verifyClient:null,noServer:false,backlog:null,server:null,host:null,path:null,port:null,WebSocket:f,...e};if(e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer){throw new TypeError('One and only one of the "port", "server", or "noServer" options '+"must be specified")}if(e.port!=null){this._server=o.createServer(((e,t)=>{const s=o.STATUS_CODES[426];t.writeHead(426,{"Content-Length":s.length,"Content-Type":"text/plain"});t.end(s)}));this._server.listen(e.port,e.host,e.backlog,t)}else if(e.server){this._server=e.server}if(this._server){const e=this.emit.bind(this,"connection");this._removeListeners=addListeners(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(t,s,r)=>{this.handleUpgrade(t,s,r,e)}})}if(e.perMessageDeflate===true)e.perMessageDeflate={};if(e.clientTracking){this.clients=new Set;this._shouldEmitClose=false}this.options=e;this._state=p}address(){if(this.options.noServer){throw new Error('The server is operating in "noServer" mode')}if(!this._server)return null;return this._server.address()}close(e){if(this._state===v){if(e){this.once("close",(()=>{e(new Error("The server is not running"))}))}process.nextTick(emitClose,this);return}if(e)this.once("close",e);if(this._state===_)return;this._state=_;if(this.options.noServer||this.options.server){if(this._server){this._removeListeners();this._removeListeners=this._server=null}if(this.clients){if(!this.clients.size){process.nextTick(emitClose,this)}else{this._shouldEmitClose=true}}else{process.nextTick(emitClose,this)}}else{const e=this._server;this._removeListeners();this._removeListeners=this._server=null;e.close((()=>{emitClose(this)}))}}shouldHandle(e){if(this.options.path){const t=e.url.indexOf("?");const s=t!==-1?e.url.slice(0,t):e.url;if(s!==this.options.path)return false}return true}handleUpgrade(e,t,s,r){t.on("error",socketOnError);const o=e.headers["sec-websocket-key"];const n=e.headers.upgrade;const i=+e.headers["sec-websocket-version"];if(e.method!=="GET"){const s="Invalid HTTP method";abortHandshakeOrEmitwsClientError(this,e,t,405,s);return}if(n===undefined||n.toLowerCase()!=="websocket"){const s="Invalid Upgrade header";abortHandshakeOrEmitwsClientError(this,e,t,400,s);return}if(o===undefined||!d.test(o)){const s="Missing or invalid Sec-WebSocket-Key header";abortHandshakeOrEmitwsClientError(this,e,t,400,s);return}if(i!==13&&i!==8){const s="Missing or invalid Sec-WebSocket-Version header";abortHandshakeOrEmitwsClientError(this,e,t,400,s,{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){abortHandshake(t,400);return}const f=e.headers["sec-websocket-protocol"];let h=new Set;if(f!==undefined){try{h=l.parse(f)}catch(s){const r="Invalid Sec-WebSocket-Protocol header";abortHandshakeOrEmitwsClientError(this,e,t,400,r);return}}const u=e.headers["sec-websocket-extensions"];const p={};if(this.options.perMessageDeflate&&u!==undefined){const s=new c(this.options.perMessageDeflate,true,this.options.maxPayload);try{const e=a.parse(u);if(e[c.extensionName]){s.accept(e[c.extensionName]);p[c.extensionName]=s}}catch(s){const r="Invalid or unacceptable Sec-WebSocket-Extensions header";abortHandshakeOrEmitwsClientError(this,e,t,400,r);return}}if(this.options.verifyClient){const n={origin:e.headers[`${i===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(n,((n,i,a,c)=>{if(!n){return abortHandshake(t,i||401,a,c)}this.completeUpgrade(p,o,h,e,t,s,r)}));return}if(!this.options.verifyClient(n))return abortHandshake(t,401)}this.completeUpgrade(p,o,h,e,t,s,r)}completeUpgrade(e,t,s,r,o,n,l){if(!o.readable||!o.writable)return o.destroy();if(o[u]){throw new Error("server.handleUpgrade() was called more than once with the same "+"socket, possibly due to a misconfiguration")}if(this._state>p)return abortHandshake(o,503);const f=i("sha1").update(t+h).digest("base64");const d=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${f}`];const _=new this.options.WebSocket(null,undefined,this.options);if(s.size){const e=this.options.handleProtocols?this.options.handleProtocols(s,r):s.values().next().value;if(e){d.push(`Sec-WebSocket-Protocol: ${e}`);_._protocol=e}}if(e[c.extensionName]){const t=e[c.extensionName].params;const s=a.format({[c.extensionName]:[t]});d.push(`Sec-WebSocket-Extensions: ${s}`);_._extensions=e}this.emit("headers",d,r);o.write(d.concat("\r\n").join("\r\n"));o.removeListener("error",socketOnError);_.setSocket(o,n,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation});if(this.clients){this.clients.add(_);_.on("close",(()=>{this.clients.delete(_);if(this._shouldEmitClose&&!this.clients.size){process.nextTick(emitClose,this)}}))}l(_,r)}}e.exports=WebSocketServer;function addListeners(e,t){for(const s of Object.keys(t))e.on(s,t[s]);return function removeListeners(){for(const s of Object.keys(t)){e.removeListener(s,t[s])}}}function emitClose(e){e._state=v;e.emit("close")}function socketOnError(){this.destroy()}function abortHandshake(e,t,s,r){s=s||o.STATUS_CODES[t];r={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(s),...r};e.once("finish",e.destroy);e.end(`HTTP/1.1 ${t} ${o.STATUS_CODES[t]}\r\n`+Object.keys(r).map((e=>`${e}: ${r[e]}`)).join("\r\n")+"\r\n\r\n"+s)}function abortHandshakeOrEmitwsClientError(e,t,s,r,o,n){if(e.listenerCount("wsClientError")){const r=new Error(o);Error.captureStackTrace(r,abortHandshakeOrEmitwsClientError);e.emit("wsClientError",r,s,t)}else{abortHandshake(s,r,o,n)}}},681:(e,t,s)=>{"use strict";const r=s(434);const o=s(692);const n=s(611);const i=s(278);const a=s(756);const{randomBytes:c,createHash:l}=s(982);const{Duplex:f,Readable:h}=s(203);const{URL:u}=s(16);const d=s(376);const p=s(893);const _=s(389);const{isBlob:v}=s(615);const{BINARY_TYPES:g,EMPTY_BUFFER:m,GUID:y,kForOnEventAttribute:b,kListener:S,kStatusCode:k,kWebSocket:w,NOOP:E}=s(791);const{EventTarget:{addEventListener:x,removeEventListener:O}}=s(634);const{format:C,parse:T}=s(335);const{toBuffer:P}=s(803);const N=30*1e3;const W=Symbol("kAborted");const L=[8,13];const I=["CONNECTING","OPEN","CLOSING","CLOSED"];const U=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;class WebSocket extends r{constructor(e,t,s){super();this._binaryType=g[0];this._closeCode=1006;this._closeFrameReceived=false;this._closeFrameSent=false;this._closeMessage=m;this._closeTimer=null;this._errorEmitted=false;this._extensions={};this._paused=false;this._protocol="";this._readyState=WebSocket.CONNECTING;this._receiver=null;this._sender=null;this._socket=null;if(e!==null){this._bufferedAmount=0;this._isServer=false;this._redirects=0;if(t===undefined){t=[]}else if(!Array.isArray(t)){if(typeof t==="object"&&t!==null){s=t;t=[]}else{t=[t]}}initAsClient(this,e,t,s)}else{this._autoPong=s.autoPong;this._isServer=true}}get binaryType(){return this._binaryType}set binaryType(e){if(!g.includes(e))return;this._binaryType=e;if(this._receiver)this._receiver._binaryType=e}get bufferedAmount(){if(!this._socket)return this._bufferedAmount;return this._socket._writableState.length+this._sender._bufferedBytes}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,t,s){const r=new p({allowSynchronousEvents:s.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation});const o=new _(e,this._extensions,s.generateMask);this._receiver=r;this._sender=o;this._socket=e;r[w]=this;o[w]=this;e[w]=this;r.on("conclude",receiverOnConclude);r.on("drain",receiverOnDrain);r.on("error",receiverOnError);r.on("message",receiverOnMessage);r.on("ping",receiverOnPing);r.on("pong",receiverOnPong);o.onerror=senderOnError;if(e.setTimeout)e.setTimeout(0);if(e.setNoDelay)e.setNoDelay();if(t.length>0)e.unshift(t);e.on("close",socketOnClose);e.on("data",socketOnData);e.on("end",socketOnEnd);e.on("error",socketOnError);this._readyState=WebSocket.OPEN;this.emit("open")}emitClose(){if(!this._socket){this._readyState=WebSocket.CLOSED;this.emit("close",this._closeCode,this._closeMessage);return}if(this._extensions[d.extensionName]){this._extensions[d.extensionName].cleanup()}this._receiver.removeAllListeners();this._readyState=WebSocket.CLOSED;this.emit("close",this._closeCode,this._closeMessage)}close(e,t){if(this.readyState===WebSocket.CLOSED)return;if(this.readyState===WebSocket.CONNECTING){const e="WebSocket was closed before the connection was established";abortHandshake(this,this._req,e);return}if(this.readyState===WebSocket.CLOSING){if(this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)){this._socket.end()}return}this._readyState=WebSocket.CLOSING;this._sender.close(e,t,!this._isServer,(e=>{if(e)return;this._closeFrameSent=true;if(this._closeFrameReceived||this._receiver._writableState.errorEmitted){this._socket.end()}}));setCloseTimer(this)}pause(){if(this.readyState===WebSocket.CONNECTING||this.readyState===WebSocket.CLOSED){return}this._paused=true;this._socket.pause()}ping(e,t,s){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof e==="function"){s=e;e=t=undefined}else if(typeof t==="function"){s=t;t=undefined}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,s);return}if(t===undefined)t=!this._isServer;this._sender.ping(e||m,t,s)}pong(e,t,s){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof e==="function"){s=e;e=t=undefined}else if(typeof t==="function"){s=t;t=undefined}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,s);return}if(t===undefined)t=!this._isServer;this._sender.pong(e||m,t,s)}resume(){if(this.readyState===WebSocket.CONNECTING||this.readyState===WebSocket.CLOSED){return}this._paused=false;if(!this._receiver._writableState.needDrain)this._socket.resume()}send(e,t,s){if(this.readyState===WebSocket.CONNECTING){throw new Error("WebSocket is not open: readyState 0 (CONNECTING)")}if(typeof t==="function"){s=t;t={}}if(typeof e==="number")e=e.toString();if(this.readyState!==WebSocket.OPEN){sendAfterClose(this,e,s);return}const r={binary:typeof e!=="string",mask:!this._isServer,compress:true,fin:true,...t};if(!this._extensions[d.extensionName]){r.compress=false}this._sender.send(e||m,r,s)}terminate(){if(this.readyState===WebSocket.CLOSED)return;if(this.readyState===WebSocket.CONNECTING){const e="WebSocket was closed before the connection was established";abortHandshake(this,this._req,e);return}if(this._socket){this._readyState=WebSocket.CLOSING;this._socket.destroy()}}}Object.defineProperty(WebSocket,"CONNECTING",{enumerable:true,value:I.indexOf("CONNECTING")});Object.defineProperty(WebSocket.prototype,"CONNECTING",{enumerable:true,value:I.indexOf("CONNECTING")});Object.defineProperty(WebSocket,"OPEN",{enumerable:true,value:I.indexOf("OPEN")});Object.defineProperty(WebSocket.prototype,"OPEN",{enumerable:true,value:I.indexOf("OPEN")});Object.defineProperty(WebSocket,"CLOSING",{enumerable:true,value:I.indexOf("CLOSING")});Object.defineProperty(WebSocket.prototype,"CLOSING",{enumerable:true,value:I.indexOf("CLOSING")});Object.defineProperty(WebSocket,"CLOSED",{enumerable:true,value:I.indexOf("CLOSED")});Object.defineProperty(WebSocket.prototype,"CLOSED",{enumerable:true,value:I.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach((e=>{Object.defineProperty(WebSocket.prototype,e,{enumerable:true})}));["open","error","close","message"].forEach((e=>{Object.defineProperty(WebSocket.prototype,`on${e}`,{enumerable:true,get(){for(const t of this.listeners(e)){if(t[b])return t[S]}return null},set(t){for(const t of this.listeners(e)){if(t[b]){this.removeListener(e,t);break}}if(typeof t!=="function")return;this.addEventListener(e,t,{[b]:true})}})}));WebSocket.prototype.addEventListener=x;WebSocket.prototype.removeEventListener=O;e.exports=WebSocket;function initAsClient(e,t,s,r){const i={allowSynchronousEvents:true,autoPong:true,protocolVersion:L[1],maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:true,followRedirects:false,maxRedirects:10,...r,socketPath:undefined,hostname:undefined,protocol:undefined,timeout:undefined,method:"GET",host:undefined,path:undefined,port:undefined};e._autoPong=i.autoPong;if(!L.includes(i.protocolVersion)){throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} `+`(supported versions: ${L.join(", ")})`)}let a;if(t instanceof u){a=t}else{try{a=new u(t)}catch(e){throw new SyntaxError(`Invalid URL: ${t}`)}}if(a.protocol==="http:"){a.protocol="ws:"}else if(a.protocol==="https:"){a.protocol="wss:"}e._url=a.href;const f=a.protocol==="wss:";const h=a.protocol==="ws+unix:";let p;if(a.protocol!=="ws:"&&!f&&!h){p='The URL\'s protocol must be one of "ws:", "wss:", '+'"http:", "https:", or "ws+unix:"'}else if(h&&!a.pathname){p="The URL's pathname is empty"}else if(a.hash){p="The URL contains a fragment identifier"}if(p){const t=new SyntaxError(p);if(e._redirects===0){throw t}else{emitErrorAndClose(e,t);return}}const _=f?443:80;const v=c(16).toString("base64");const g=f?o.request:n.request;const m=new Set;let b;i.createConnection=i.createConnection||(f?tlsConnect:netConnect);i.defaultPort=i.defaultPort||_;i.port=a.port||_;i.host=a.hostname.startsWith("[")?a.hostname.slice(1,-1):a.hostname;i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":v,Connection:"Upgrade",Upgrade:"websocket"};i.path=a.pathname+a.search;i.timeout=i.handshakeTimeout;if(i.perMessageDeflate){b=new d(i.perMessageDeflate!==true?i.perMessageDeflate:{},false,i.maxPayload);i.headers["Sec-WebSocket-Extensions"]=C({[d.extensionName]:b.offer()})}if(s.length){for(const e of s){if(typeof e!=="string"||!U.test(e)||m.has(e)){throw new SyntaxError("An invalid or duplicated subprotocol was specified")}m.add(e)}i.headers["Sec-WebSocket-Protocol"]=s.join(",")}if(i.origin){if(i.protocolVersion<13){i.headers["Sec-WebSocket-Origin"]=i.origin}else{i.headers.Origin=i.origin}}if(a.username||a.password){i.auth=`${a.username}:${a.password}`}if(h){const e=i.path.split(":");i.socketPath=e[0];i.path=e[1]}let S;if(i.followRedirects){if(e._redirects===0){e._originalIpc=h;e._originalSecure=f;e._originalHostOrSocketPath=h?i.socketPath:a.host;const t=r&&r.headers;r={...r,headers:{}};if(t){for(const[e,s]of Object.entries(t)){r.headers[e.toLowerCase()]=s}}}else if(e.listenerCount("redirect")===0){const t=h?e._originalIpc?i.socketPath===e._originalHostOrSocketPath:false:e._originalIpc?false:a.host===e._originalHostOrSocketPath;if(!t||e._originalSecure&&!f){delete i.headers.authorization;delete i.headers.cookie;if(!t)delete i.headers.host;i.auth=undefined}}if(i.auth&&!r.headers.authorization){r.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")}S=e._req=g(i);if(e._redirects){e.emit("redirect",e.url,S)}}else{S=e._req=g(i)}if(i.timeout){S.on("timeout",(()=>{abortHandshake(e,S,"Opening handshake has timed out")}))}S.on("error",(t=>{if(S===null||S[W])return;S=e._req=null;emitErrorAndClose(e,t)}));S.on("response",(o=>{const n=o.headers.location;const a=o.statusCode;if(n&&i.followRedirects&&a>=300&&a<400){if(++e._redirects>i.maxRedirects){abortHandshake(e,S,"Maximum redirects exceeded");return}S.abort();let o;try{o=new u(n,t)}catch(t){const s=new SyntaxError(`Invalid URL: ${n}`);emitErrorAndClose(e,s);return}initAsClient(e,o,s,r)}else if(!e.emit("unexpected-response",S,o)){abortHandshake(e,S,`Unexpected server response: ${o.statusCode}`)}}));S.on("upgrade",((t,s,r)=>{e.emit("upgrade",t);if(e.readyState!==WebSocket.CONNECTING)return;S=e._req=null;const o=t.headers.upgrade;if(o===undefined||o.toLowerCase()!=="websocket"){abortHandshake(e,s,"Invalid Upgrade header");return}const n=l("sha1").update(v+y).digest("base64");if(t.headers["sec-websocket-accept"]!==n){abortHandshake(e,s,"Invalid Sec-WebSocket-Accept header");return}const a=t.headers["sec-websocket-protocol"];let c;if(a!==undefined){if(!m.size){c="Server sent a subprotocol but none was requested"}else if(!m.has(a)){c="Server sent an invalid subprotocol"}}else if(m.size){c="Server sent no subprotocol"}if(c){abortHandshake(e,s,c);return}if(a)e._protocol=a;const f=t.headers["sec-websocket-extensions"];if(f!==undefined){if(!b){const t="Server sent a Sec-WebSocket-Extensions header but no extension "+"was requested";abortHandshake(e,s,t);return}let t;try{t=T(f)}catch(t){const r="Invalid Sec-WebSocket-Extensions header";abortHandshake(e,s,r);return}const r=Object.keys(t);if(r.length!==1||r[0]!==d.extensionName){const t="Server indicated an extension that was not requested";abortHandshake(e,s,t);return}try{b.accept(t[d.extensionName])}catch(t){const r="Invalid Sec-WebSocket-Extensions header";abortHandshake(e,s,r);return}e._extensions[d.extensionName]=b}e.setSocket(s,r,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation})}));if(i.finishRequest){i.finishRequest(S,e)}else{S.end()}}function emitErrorAndClose(e,t){e._readyState=WebSocket.CLOSING;e._errorEmitted=true;e.emit("error",t);e.emitClose()}function netConnect(e){e.path=e.socketPath;return i.connect(e)}function tlsConnect(e){e.path=undefined;if(!e.servername&&e.servername!==""){e.servername=i.isIP(e.host)?"":e.host}return a.connect(e)}function abortHandshake(e,t,s){e._readyState=WebSocket.CLOSING;const r=new Error(s);Error.captureStackTrace(r,abortHandshake);if(t.setHeader){t[W]=true;t.abort();if(t.socket&&!t.socket.destroyed){t.socket.destroy()}process.nextTick(emitErrorAndClose,e,r)}else{t.destroy(r);t.once("error",e.emit.bind(e,"error"));t.once("close",e.emitClose.bind(e))}}function sendAfterClose(e,t,s){if(t){const s=v(t)?t.size:P(t).length;if(e._socket)e._sender._bufferedBytes+=s;else e._bufferedAmount+=s}if(s){const t=new Error(`WebSocket is not open: readyState ${e.readyState} `+`(${I[e.readyState]})`);process.nextTick(s,t)}}function receiverOnConclude(e,t){const s=this[w];s._closeFrameReceived=true;s._closeMessage=t;s._closeCode=e;if(s._socket[w]===undefined)return;s._socket.removeListener("data",socketOnData);process.nextTick(resume,s._socket);if(e===1005)s.close();else s.close(e,t)}function receiverOnDrain(){const e=this[w];if(!e.isPaused)e._socket.resume()}function receiverOnError(e){const t=this[w];if(t._socket[w]!==undefined){t._socket.removeListener("data",socketOnData);process.nextTick(resume,t._socket);t.close(e[k])}if(!t._errorEmitted){t._errorEmitted=true;t.emit("error",e)}}function receiverOnFinish(){this[w].emitClose()}function receiverOnMessage(e,t){this[w].emit("message",e,t)}function receiverOnPing(e){const t=this[w];if(t._autoPong)t.pong(e,!this._isServer,E);t.emit("ping",e)}function receiverOnPong(e){this[w].emit("pong",e)}function resume(e){e.resume()}function senderOnError(e){const t=this[w];if(t.readyState===WebSocket.CLOSED)return;if(t.readyState===WebSocket.OPEN){t._readyState=WebSocket.CLOSING;setCloseTimer(t)}this._socket.end();if(!t._errorEmitted){t._errorEmitted=true;t.emit("error",e)}}function setCloseTimer(e){e._closeTimer=setTimeout(e._socket.destroy.bind(e._socket),N)}function socketOnClose(){const e=this[w];this.removeListener("close",socketOnClose);this.removeListener("data",socketOnData);this.removeListener("end",socketOnEnd);e._readyState=WebSocket.CLOSING;let t;if(!this._readableState.endEmitted&&!e._closeFrameReceived&&!e._receiver._writableState.errorEmitted&&(t=e._socket.read())!==null){e._receiver.write(t)}e._receiver.end();this[w]=undefined;clearTimeout(e._closeTimer);if(e._receiver._writableState.finished||e._receiver._writableState.errorEmitted){e.emitClose()}else{e._receiver.on("error",receiverOnFinish);e._receiver.on("finish",receiverOnFinish)}}function socketOnData(e){if(!this[w]._receiver.write(e)){this.pause()}}function socketOnEnd(){const e=this[w];e._readyState=WebSocket.CLOSING;e._receiver.end();this.end()}function socketOnError(){const e=this[w];this.removeListener("error",socketOnError);this.on("error",E);if(e){e._readyState=WebSocket.CLOSING;this.destroy()}}},327:module=>{module.exports=eval("require")("bufferutil")},414:module=>{module.exports=eval("require")("utf-8-validate")},181:e=>{"use strict";e.exports=require("buffer")},982:e=>{"use strict";e.exports=require("crypto")},434:e=>{"use strict";e.exports=require("events")},896:e=>{"use strict";e.exports=require("fs")},611:e=>{"use strict";e.exports=require("http")},692:e=>{"use strict";e.exports=require("https")},278:e=>{"use strict";e.exports=require("net")},857:e=>{"use strict";e.exports=require("os")},928:e=>{"use strict";e.exports=require("path")},203:e=>{"use strict";e.exports=require("stream")},756:e=>{"use strict";e.exports=require("tls")},16:e=>{"use strict";e.exports=require("url")},106:e=>{"use strict";e.exports=require("zlib")}};var __webpack_module_cache__={};function __nccwpck_require__(e){var t=__webpack_module_cache__[e];if(t!==undefined){return t.exports}var s=__webpack_module_cache__[e]={exports:{}};var r=true;try{__webpack_modules__[e].call(s.exports,s,s.exports,__nccwpck_require__);r=false}finally{if(r)delete __webpack_module_cache__[e]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var __webpack_exports__=__nccwpck_require__(546);module.exports=__webpack_exports__})();
|