insite-ws 2.4.1 → 2.6.0
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/dist/client/index.js +1 -1
- package/dist/client/index.js.map +2 -2
- package/dist/server/WSServer.d.ts.map +1 -1
- package/dist/server/WSServerClient.d.ts +1 -2
- package/dist/server/WSServerClient.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +2 -2
- package/package.json +4 -4
package/dist/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import v from"eventemitter3";import{noop as S,StatefulPromise as g}from"@nesvet/n";var f=Number.MAX_SAFE_INTEGER/2,r={NORMAL:1e3,PROTOCOL_ERROR:1002,ABNORMAL:1006,NO_HEARTBEAT:3e3,OFFLINE:3001,MANUAL:3500,REOPEN:4e3},N=[r.PROTOCOL_ERROR,r.MANUAL,r.REOPEN],E={REQUEST:"~r-q",RESPONSE:"~r-s"};var R=0,O=class a extends v{constructor(e={}){super();let{url:t=globalThis.__insite?.wss_url||"/",name:s=(R++).toString(),protocols:o,immediately:i=!0,reconnectAfter:n=2e3,on:h,once:l,quiet:u=!1,signal:d}=e;if(this.url=t,this.name=s,this.protocols=o,this.reconnectAfter=n,h)for(let c in h)h[c]&&this.on(c,h[c]);if(l)for(let c in l)l[c]&&this.once(c,l[c]);this.#c=u,this.#l=d,this.#l?.addEventListener("abort",this.#p,{once:!0}),this.url&&i&&this.open().catch(S),this.#c||this.on("error",c=>c&&console.error("\u{1F50C}\u2757\uFE0F WS",`${this.name}:`,c))}on(e,t){return super.on(e,t)}isWebSocket=!0;isWebSocketServer=!1;isWebSocketServerClient=!1;url;name;protocols;reconnectAfter;#c;#l;isUsed=!1;connectionQuality=0;#n(e){if(e!==this.connectionQuality){let t=this.connectionQuality;this.connectionQuality=e,this.emit("connection-quality-change",this.connectionQuality,t)}}webSocket=null;#o;#T(){clearTimeout(this.#o),this.#o=setTimeout(()=>this.close(r.NO_HEARTBEAT,"no-heartbeat",!1),35e3),this.#t&&(clearTimeout(this.#t),this.#t=void 0),this.#r=!1,this.#s&&(clearTimeout(this.#s),this.#s=void 0),this.#i&&(this.#i=!1,this.emit("responsive")),this.#n(a.CONNECTION_QUALITY.OPEN)}#t;#r=!1;#s;#i=!1;get state(){if(!this.webSocket)return"closed";switch(this.webSocket.readyState){case WebSocket.CONNECTING:return"connecting";case WebSocket.OPEN:return this.#i?"unresponsive":"open";case WebSocket.CLOSING:return"closing"}return"closed"}get isConnecting(){return this.webSocket?.readyState===WebSocket.CONNECTING}get isOpen(){return this.webSocket?.readyState===WebSocket.OPEN}get isClosing(){return this.webSocket?.readyState===WebSocket.CLOSING}get isClosed(){return!this.webSocket}isDestroyed=!1;#e;#E=!1;#S=()=>{this.#E=!0,this.closedWith=null,this.#e.resolve(),this.#T(),this.emit("open")};#O=({data:e})=>{if(this.#T(),e){if(e!=="!")try{let[t,...s]=JSON.parse(e);t===E.REQUEST?this.#g(...s):(this.emit("message",t,...s),this.emit(`message:${t}`,...s))}catch(t){this.#u(t)}}else this.webSocket.send("")};#u=e=>{e instanceof Event&&(e=void 0),this.#e?.isPending&&this.#e.reject(e),this.emit("error",e)};#a;#m(e){this.#a&&clearTimeout(this.#a),this.reconnectAfter&&!N.includes(e)?(process.env.NODE_ENV==="development"&&!this.#c&&console.info(`\u{1F50C} WS ${this.name} will try to reconnect in ${Math.round(this.reconnectAfter/1e3)} seconds`),this.#a=setTimeout(()=>this.open().catch(S),this.reconnectAfter),this.#n(a.CONNECTION_QUALITY.RECONNECTING)):(this.#a=void 0,this.#n(e===r.REOPEN?a.CONNECTION_QUALITY.RECONNECTING:a.CONNECTION_QUALITY.CLOSED))}#d=e=>{let{code:t,reason:s,wasClean:o}=e;if(this.closedWith={code:t,reason:s,wasClean:o},this.#o&&(clearTimeout(this.#o),this.#o=void 0),this.#t&&(clearTimeout(this.#t),this.#t=void 0),this.#r=!1,this.#s&&(clearTimeout(this.#s),this.#s=void 0),this.#i=!1,this.#e?.isPending&&this.#e.reject(new Error("Closed")),process.env.NODE_ENV==="development"&&!this.#c){let n=`\u{1F50C} WS ${this.name} is closed`;t&&(n+=` with code ${t}`),t&&s&&(n+=" and"),s&&(n+=` reason "${s}"`),s==="no-heartbeat"&&(n+=". Going offline"),!o||t===r.ABNORMAL?(n+=" [UNEXPECTED]",console.warn(n)):console.info(n)}let i=this.webSocket;i.removeEventListener("open",this.#S),i.removeEventListener("message",this.#O),i.removeEventListener("error",this.#u),this.#E&&(this.emit("close",e),this.#E=!1),this.webSocket=null,this.#m(t),"navigator"in globalThis&&"addEventListener"in globalThis&&globalThis.removeEventListener("offline",this.#b)};#p=()=>this.#e?.isPending&&this.#e.reject(new DOMException("Operation aborted","AbortError"));async open(e={}){if(this.isDestroyed)throw new Error("WS has been destroyed");if(this.#l?.aborted)throw new DOMException("Operation aborted","AbortError");if(this.closedWith=null,this.#e?.isPending)return this.#e;this.isUsed?this.close(r.REOPEN,"reopen"):this.isUsed=!0;let t;return e.url&&this.url!==e.url&&(t=this.url,this.url=e.url),e.protocols&&(this.protocols=e.protocols),this.#e=new g((s,o)=>{if(this.url){let i=new WebSocket(this.url,this.protocols);i.addEventListener("open",this.#S,{once:!0}),i.addEventListener("message",this.#O),i.addEventListener("error",this.#u),i.addEventListener("close",this.#d,{once:!0}),this.webSocket=i,t&&this.emit("server-change",this.url,t),this.emit("connecting"),"navigator"in globalThis&&"addEventListener"in globalThis&&globalThis.addEventListener("offline",this.#b)}else this.webSocket=null,o(new Error("url prop is not set"))}),this.#e}connect=this.open;close(e=r.MANUAL,t="manual",s=!0){this.isClosed?this.#m(e):(this.webSocket.removeEventListener("close",this.#d),this.webSocket.close(e,t),this.#d(Object.assign(new Event("close"),{code:e,reason:t,wasClean:s})))}closedWith=null;disconnect=this.close;#h=[];#v=()=>{for(let e of this.#h)this.webSocket.send(e);this.#h.length=0};send(e){this.isOpen?this.webSocket.send(e):(this.#h.length||this.once("open",this.#v),this.#h.push(e))}sendMessage(...e){return this.send(JSON.stringify(e))}#f=0;sendRequest(...e){let t=this.#f++;this.#f>=f&&(this.#f=0);let s=`message:${E.RESPONSE}-${t}`,o=e.at(-1);return typeof o=="function"?(this.once(s,o),this.sendMessage(E.REQUEST,t,...e.slice(0,-1)),this):new Promise((i,n)=>{this.once(s,(h,l)=>{if(h){let{message:u,...d}=h;n(Object.assign(new Error(u),d))}else i(l)}),this.sendMessage(E.REQUEST,t,...e)})}#N=new Map;addRequestListener(e,t){return this.#N.set(e,t),this}onRequest=this.addRequestListener;removeRequestListener(e){return this.#N.delete(e),this}offRequest=this.removeRequestListener;#g=async(e,t,...s)=>{let o=this.#N.get(t),i,n=null;if(o)try{i=await o.apply(this,s)}catch(h){if(h instanceof Error){let{message:l,...u}=h;n={message:l,...u}}}else n={message:`Unknown request kind "${t}"`};this.sendMessage(`${E.RESPONSE}-${e}`,n,i)};#b=()=>{this.isOpen&&!this.#r&&(this.#r=!0,this.#n(a.CONNECTION_QUALITY.CHECKING_RESPONSIVENESS),this.#t=setTimeout(()=>{this.#r=!1,this.#i=!0,this.#n(a.CONNECTION_QUALITY.UNRESPONSIVE),this.emit("unresponsive"),this.#s=setTimeout(()=>{this.#i=!1,this.close(r.OFFLINE,"offline",!1)},4e3)},1e3),this.webSocket.send("?"))};destroy(){this.isDestroyed=!0,this.#h.length=0,this.close(r.NORMAL,"destroy"),this.emit("destroy"),this.removeAllListeners(),this.#l?.removeEventListener("abort",this.#p)}static CONNECTION_QUALITY={CLOSED:0,RECONNECTING:1,UNRESPONSIVE:2,CHECKING_RESPONSIVENESS:3,OPEN:4}};export{O as WS};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/client/WS.ts", "../../src/common.ts"],
|
|
4
4
|
"sourcesContent": ["import EventEmitter from \"eventemitter3\";\nimport { noop, StatefulPromise } from \"@nesvet/n\";\nimport {\n\tCODES,\n\tHEARTBEAT_GAP,\n\tHEARTBEAT_INTERVAL,\n\tNON_RECONNECTABLE_CODES,\n\tOFFLINE_TIMEOUT,\n\tREQUEST_COUNTER_LIMIT,\n\tREQUEST_HEADERS,\n\tRESPONSIVENESS_TIMEOUT\n} from \"../common\";\nimport type { ConnectionQuality, Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nlet i = 0;\n\n\nexport class WS extends EventEmitter {\n\tconstructor(options: Options = {}) {\n\t\tsuper();\n\t\t\n\t\tconst {\n\t\t\turl = globalThis.__insite?.wss_url || \"/\",\n\t\t\tname = (i++).toString(),\n\t\t\tprotocols,\n\t\t\timmediately = true,\n\t\t\treconnectAfter = 2000,\n\t\t\ton,\n\t\t\tonce,\n\t\t\tquiet = false,\n\t\t\tsignal\n\t\t} = options;\n\t\t\n\t\tthis.url = url;\n\t\tthis.name = name;\n\t\t\n\t\tthis.protocols = protocols;\n\t\t\n\t\tthis.reconnectAfter = reconnectAfter;\n\t\t\n\t\tif (on)\n\t\t\tfor (const eventName in on)\n\t\t\t\tif (on[eventName])\n\t\t\t\t\tthis.on(eventName, on[eventName]);\n\t\t\n\t\tif (once)\n\t\t\tfor (const eventName in once)\n\t\t\t\tif (once[eventName])\n\t\t\t\t\tthis.once(eventName, once[eventName]);\n\t\t\n\t\tthis.#isQuiet = quiet;\n\t\t\n\t\tthis.#abortSignal = signal;\n\t\tthis.#abortSignal?.addEventListener(\"abort\", this.#handleAbortSignalAbort, { once: true });\n\t\t\n\t\tif (this.url && immediately)\n\t\t\tthis.open().catch(noop);\n\t\t\n\t\tif (!this.#isQuiet)\n\t\t\tthis.on(\"error\", (error: Error) => error && console.error(\"\uD83D\uDD0C\u2757\uFE0F WS\", `${this.name}:`, error));\n\t\t\n\t}\n\t\n\ton(event: \"connecting\" | \"destroy\" | \"open\" | \"responsive\" | \"unresponsive\", callback: (this: this) => void): this;\n\ton<T extends unknown[]>(event: \"message\", callback: (this: this, kind: string, ...rest: T) => void): this;\n\ton<T extends unknown[]>(event: `message:${string}`, callback: (this: this, ...rest: T) => void): this;\n\ton(event: \"connection-quality-change\", callback: (this: this, connectionQuality: ConnectionQuality, prevConnectionQuality: ConnectionQuality) => void): this;\n\ton(event: \"close\", callback: (this: this, closeEvent: CloseEvent) => void): this;\n\ton(event: \"server-change\", callback: (this: this, url: string, prevURL: string) => void): this;\n\ton(event: \"error\", callback: (this: this, error: Error) => void): this;\n\t\n\ton<T extends string | symbol>(event: T, fn: (...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener);\n\t}\n\t\n\treadonly isWebSocket = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocketServerClient = false;\n\t\n\turl;\n\t\n\treadonly name;\n\t\n\tprotocols?;\n\t\n\treconnectAfter;\n\t\n\t#isQuiet;\n\t\n\t#abortSignal?: AbortSignal;\n\t\n\tisUsed = false;\n\t\n\tconnectionQuality: ConnectionQuality = 0;\n\t\n\t#updateConnectionQuality(connectionQuality: ConnectionQuality) {\n\t\tif (connectionQuality !== this.connectionQuality) {\n\t\t\tconst prevConnectionQuality = this.connectionQuality;\n\t\t\tthis.connectionQuality = connectionQuality;\n\t\t\t\n\t\t\tthis.emit(\"connection-quality-change\", this.connectionQuality, prevConnectionQuality);\n\t\t}\n\t\t\n\t}\n\t\n\twebSocket: WebSocket | null = null;\n\t\n\t#heartbeatTimeout?: ReturnType<typeof setTimeout>;\n\t\n\t#defib() {\n\t\t\n\t\tclearTimeout(this.#heartbeatTimeout);\n\t\tthis.#heartbeatTimeout = setTimeout(\n\t\t\t() => this.close(CODES.NO_HEARTBEAT, \"no-heartbeat\", false),\n\t\t\tHEARTBEAT_INTERVAL + HEARTBEAT_GAP\n\t\t);\n\t\t\n\t\tif (this.#unresponsiveTimeout) {\n\t\t\tclearTimeout(this.#unresponsiveTimeout);\n\t\t\tthis.#unresponsiveTimeout = undefined;\n\t\t}\n\t\t\n\t\tthis.#isCheckingResponsiveness = false;\n\t\t\n\t\tif (this.#offlineTimeout) {\n\t\t\tclearTimeout(this.#offlineTimeout);\n\t\t\tthis.#offlineTimeout = undefined;\n\t\t}\n\t\t\n\t\tif (this.#isUnresponsive) {\n\t\t\tthis.#isUnresponsive = false;\n\t\t\t\n\t\t\tthis.emit(\"responsive\");\n\t\t}\n\t\t\n\t\tthis.#updateConnectionQuality(WS.CONNECTION_QUALITY.OPEN);\n\t\t\n\t}\n\t\n\t#unresponsiveTimeout?: ReturnType<typeof setTimeout>;\n\t#isCheckingResponsiveness = false;\n\t\n\t#offlineTimeout?: ReturnType<typeof setTimeout>;\n\t#isUnresponsive = false;\n\t\n\tget state() {\n\t\t\n\t\tif (!this.webSocket)\n\t\t\treturn \"closed\";\n\t\t\n\t\tswitch (this.webSocket.readyState) {\n\t\t\tcase WebSocket.CONNECTING:\n\t\t\t\treturn \"connecting\";\n\t\t\t\n\t\t\tcase WebSocket.OPEN:\n\t\t\t\treturn this.#isUnresponsive ? \"unresponsive\" : \"open\";\n\t\t\t\n\t\t\tcase WebSocket.CLOSING:\n\t\t\t\treturn \"closing\";\n\t\t}\n\t\t\n\t\treturn \"closed\";\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.webSocket?.readyState === WebSocket.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.webSocket?.readyState === WebSocket.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.webSocket?.readyState === WebSocket.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn !this.webSocket;\n\t}\n\t\n\tisDestroyed = false;\n\t\n\t#openPromise?: StatefulPromise<void>;\n\t\n\t#wasOpened = false;\n\t\n\t#handleWebSocketOpen = () => {\n\t\t\n\t\tthis.#wasOpened = true;\n\t\t\n\t\tthis.closedWith = null;\n\t\t\n\t\tthis.#openPromise!.resolve();\n\t\t\n\t\tthis.#defib();\n\t\t\n\t\tthis.emit(\"open\");\n\t\t\n\t};\n\t\n\t#handleWebSocketMessage = ({ data: message }: MessageEvent<string>) => {\n\t\t\n\t\tthis.#defib();\n\t\t\n\t\tif (message) {\n\t\t\tif (message !== \"!\")\n\t\t\t\ttry {\n\t\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\t\n\t\t\t\t\tswitch (kind) {\n\t\t\t\t\t\tcase REQUEST_HEADERS.REQUEST:\n\t\t\t\t\t\t\tvoid this.#handleRequest(...rest as [ id: number, kind: string, ...rest: unknown[] ]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthis.emit(\"message\", kind, ...rest);\n\t\t\t\t\t\t\tthis.emit(`message:${kind}`, ...rest);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.#handleWebSocketError(error as Error);\n\t\t\t\t}\n\t\t} else\n\t\t\tthis.webSocket!.send(\"\");\n\t\t\n\t};\n\t\n\t#handleWebSocketError = (error: Error | Event | undefined) => {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tif (this.#openPromise?.isPending)\n\t\t\tthis.#openPromise.reject(error as Error);\n\t\t\n\t\tthis.emit(\"error\", error);\n\t\t\n\t};\n\t\n\t#reconnectTimeout?: ReturnType<typeof setTimeout>;\n\t\n\t#decideReconnect(code: number) {\n\t\t\n\t\tif (this.#reconnectTimeout)\n\t\t\tclearTimeout(this.#reconnectTimeout);\n\t\t\n\t\tif (this.reconnectAfter && !NON_RECONNECTABLE_CODES.includes(code as typeof NON_RECONNECTABLE_CODES[number])) {\n\t\t\tif (process.env.NODE_ENV === \"development\" && !this.#isQuiet)\n\t\t\t\tconsole.info(`\uD83D\uDD0C WS ${this.name} will try to reconnect in ${Math.round(this.reconnectAfter / 1000)} seconds`);\n\t\t\t\n\t\t\tthis.#reconnectTimeout = setTimeout(() => this.open().catch(noop), this.reconnectAfter);\n\t\t\t\n\t\t\tthis.#updateConnectionQuality(WS.CONNECTION_QUALITY.RECONNECTING);\n\t\t} else {\n\t\t\tthis.#reconnectTimeout = undefined;\n\t\t\t\n\t\t\tthis.#updateConnectionQuality(code === CODES.REOPEN ? WS.CONNECTION_QUALITY.RECONNECTING : WS.CONNECTION_QUALITY.CLOSED);\n\t\t}\n\t\t\n\t}\n\t\n\t#handleWebSocketClose = (event: CloseEvent) => {\n\t\tconst { code, reason, wasClean } = event;\n\t\t\n\t\tthis.closedWith = { code, reason, wasClean };\n\t\t\n\t\tif (this.#heartbeatTimeout) {\n\t\t\tclearTimeout(this.#heartbeatTimeout);\n\t\t\tthis.#heartbeatTimeout = undefined;\n\t\t}\n\t\t\n\t\tif (this.#unresponsiveTimeout) {\n\t\t\tclearTimeout(this.#unresponsiveTimeout);\n\t\t\tthis.#unresponsiveTimeout = undefined;\n\t\t}\n\t\t\n\t\tthis.#isCheckingResponsiveness = false;\n\t\t\n\t\tif (this.#offlineTimeout) {\n\t\t\tclearTimeout(this.#offlineTimeout);\n\t\t\tthis.#offlineTimeout = undefined;\n\t\t}\n\t\t\n\t\tthis.#isUnresponsive = false;\n\t\t\n\t\tif (this.#openPromise?.isPending)\n\t\t\tthis.#openPromise.reject(new Error(\"Closed\"));\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\" && !this.#isQuiet) {\n\t\t\tlet message = `\uD83D\uDD0C WS ${this.name} is closed`;\n\t\t\t\n\t\t\tif (code)\n\t\t\t\tmessage += ` with code ${code}`;\n\t\t\t\n\t\t\tif (code && reason)\n\t\t\t\tmessage += \" and\";\n\t\t\t\n\t\t\tif (reason)\n\t\t\t\tmessage += ` reason \"${reason}\"`;\n\t\t\t\n\t\t\tswitch (reason) {\n\t\t\t\tcase \"no-heartbeat\":\n\t\t\t\t\tmessage += \". Going offline\";\n\t\t\t}\n\t\t\t\n\t\t\tif (!wasClean || code === CODES.ABNORMAL) {\n\t\t\t\tmessage += \" [UNEXPECTED]\";\n\t\t\t\tconsole.warn(message);\n\t\t\t} else\n\t\t\t\tconsole.info(message);\n\t\t}\n\t\t\n\t\tconst webSocket = this.webSocket!;\n\t\t\n\t\twebSocket.removeEventListener(\"open\", this.#handleWebSocketOpen);\n\t\twebSocket.removeEventListener(\"message\", this.#handleWebSocketMessage);\n\t\twebSocket.removeEventListener(\"error\", this.#handleWebSocketError);\n\t\t\n\t\tif (this.#wasOpened) {\n\t\t\tthis.emit(\"close\", event);\n\t\t\t\n\t\t\tthis.#wasOpened = false;\n\t\t}\n\t\t\n\t\tthis.webSocket = null;\n\t\t\n\t\tthis.#decideReconnect(code);\n\t\t\n\t\tif (\"navigator\" in globalThis && \"addEventListener\" in globalThis)\n\t\t\tglobalThis.removeEventListener(\"offline\", this.#handleOffline);\n\t\t\n\t};\n\t\n\t#handleAbortSignalAbort = () =>\n\t\tthis.#openPromise?.isPending &&\n\t\tthis.#openPromise.reject(new DOMException(\"Operation aborted\", \"AbortError\"));\n\t\n\tasync open(options: Pick<Options, \"protocols\" | \"url\"> = {}): Promise<void> {\n\t\t\n\t\tif (this.isDestroyed)\n\t\t\tthrow new Error(\"WS has been destroyed\");\n\t\t\n\t\tif (this.#abortSignal?.aborted)\n\t\t\tthrow new DOMException(\"Operation aborted\", \"AbortError\");\n\t\t\n\t\tthis.closedWith = null;\n\t\t\n\t\tif (this.#openPromise?.isPending)\n\t\t\treturn this.#openPromise;\n\t\t\n\t\tif (this.isUsed)\n\t\t\tthis.close(CODES.REOPEN, \"reopen\");\n\t\telse\n\t\t\tthis.isUsed = true;\n\t\t\n\t\tlet prevURL: URL | string | undefined;\n\t\tif (options.url && this.url !== options.url) {\n\t\t\tprevURL = this.url;\n\t\t\tthis.url = options.url;\n\t\t}\n\t\t\n\t\tif (options.protocols)\n\t\t\tthis.protocols = options.protocols;\n\t\t\n\t\tthis.#openPromise = new StatefulPromise((_, reject) => {\n\t\t\t\n\t\t\tif (this.url) {\n\t\t\t\tconst webSocket = new WebSocket(this.url, this.protocols);\n\t\t\t\t\n\t\t\t\twebSocket.addEventListener(\"open\", this.#handleWebSocketOpen, { once: true });\n\t\t\t\twebSocket.addEventListener(\"message\", this.#handleWebSocketMessage);\n\t\t\t\twebSocket.addEventListener(\"error\", this.#handleWebSocketError);\n\t\t\t\twebSocket.addEventListener(\"close\", this.#handleWebSocketClose, { once: true });\n\t\t\t\t\n\t\t\t\tthis.webSocket = webSocket;\n\t\t\t\t\n\t\t\t\tif (prevURL)\n\t\t\t\t\tthis.emit(\"server-change\", this.url, prevURL);\n\t\t\t\t\n\t\t\t\tthis.emit(\"connecting\");\n\t\t\t\t\n\t\t\t\tif (\"navigator\" in globalThis && \"addEventListener\" in globalThis)\n\t\t\t\t\tglobalThis.addEventListener(\"offline\", this.#handleOffline);\n\t\t\t} else {\n\t\t\t\tthis.webSocket = null;\n\t\t\t\t\n\t\t\t\treject(new Error(\"url prop is not set\"));\n\t\t\t}\n\t\t\t\n\t\t});\n\t\t\n\t\treturn this.#openPromise;\n\t}\n\t\n\t/**\n\t * Alias for `open()`\n\t */\n\tconnect = this.open;\n\t\n\tclose(code: number = CODES.MANUAL, reason = \"manual\", wasClean: boolean = true) {\n\t\t\n\t\tif (this.isClosed)\n\t\t\tthis.#decideReconnect(code);\n\t\telse {\n\t\t\tthis.webSocket!.removeEventListener(\"close\", this.#handleWebSocketClose);\n\t\t\t\n\t\t\tthis.webSocket!.close(code, reason);\n\t\t\t\n\t\t\tthis.#handleWebSocketClose(Object.assign(new Event(\"close\"), {\n\t\t\t\tcode,\n\t\t\t\treason,\n\t\t\t\twasClean\n\t\t\t}));\n\t\t}\n\t\t\n\t}\n\t\n\tclosedWith: { code: number; reason: string; wasClean: boolean } | null = null;\n\t\n\t/**\n\t * Alias for `close()`\n\t */\n\tdisconnect = this.close;\n\t\n\t#queue: (ArrayBufferLike | ArrayBufferView | Blob | string)[] = [];\n\t\n\t#releaseQueue = () => {\n\t\t\n\t\tfor (const message of this.#queue)\n\t\t\tthis.webSocket!.send(message);\n\t\t\n\t\tthis.#queue.length = 0;\n\t\t\n\t};\n\t\n\tsend(data: ArrayBufferLike | ArrayBufferView | Blob | string) {\n\t\t\n\t\tif (this.isOpen)\n\t\t\tthis.webSocket!.send(data);\n\t\telse {\n\t\t\tif (!this.#queue.length)\n\t\t\t\tthis.once(\"open\", this.#releaseQueue);\n\t\t\t\n\t\t\tthis.#queue.push(data);\n\t\t}\n\t\t\n\t}\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\t#requestCounter = 0;\n\t\n\tsendRequest<T>(...args: [...unknown[], callback: (error: Error | null, result: T) => void]): this;\n\tsendRequest<T>(...args: unknown[]): Promise<T>;\n\tsendRequest<T>(...args: unknown[]) {\n\t\t\n\t\tconst id = this.#requestCounter++;\n\t\t\n\t\tif (this.#requestCounter >= REQUEST_COUNTER_LIMIT)\n\t\t\tthis.#requestCounter = 0;\n\t\t\n\t\tconst eventName = `message:${REQUEST_HEADERS.RESPONSE}-${id}`;\n\t\t\n\t\tconst lastArg = args.at(-1);\n\t\t\n\t\tif (typeof lastArg == \"function\") {\n\t\t\tthis.once(eventName, lastArg as (error: Error, result: T) => void);\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args.slice(0, -1));\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result: T) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps) as Error);\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t#requestListeners = new Map<string, RequestListener>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener) {\n\t\tthis.#requestListeners.set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `addRequestListener()`\n\t */\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis.#requestListeners.delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `removeRequestListener()`\n\t */\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleRequest = async (id: number, kind: string, ...rest: unknown[]) => {\n\t\tconst listener = this.#requestListeners.get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.apply(this, rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\tthis.sendMessage(`${REQUEST_HEADERS.RESPONSE}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\t#handleOffline = () => {\n\t\t\n\t\tif (this.isOpen && !this.#isCheckingResponsiveness) {\n\t\t\tthis.#isCheckingResponsiveness = true;\n\t\t\t\n\t\t\tthis.#updateConnectionQuality(WS.CONNECTION_QUALITY.CHECKING_RESPONSIVENESS);\n\t\t\t\n\t\t\tthis.#unresponsiveTimeout = setTimeout(() => {\n\t\t\t\t\n\t\t\t\tthis.#isCheckingResponsiveness = false;\n\t\t\t\tthis.#isUnresponsive = true;\n\t\t\t\t\n\t\t\t\tthis.#updateConnectionQuality(WS.CONNECTION_QUALITY.UNRESPONSIVE);\n\t\t\t\t\n\t\t\t\tthis.emit(\"unresponsive\");\n\t\t\t\t\n\t\t\t\tthis.#offlineTimeout = setTimeout(() => {\n\t\t\t\t\t\n\t\t\t\t\tthis.#isUnresponsive = false;\n\t\t\t\t\t\n\t\t\t\t\tthis.close(CODES.OFFLINE, \"offline\", false);\n\t\t\t\t\t\n\t\t\t\t}, OFFLINE_TIMEOUT - RESPONSIVENESS_TIMEOUT);\n\t\t\t\t\n\t\t\t}, RESPONSIVENESS_TIMEOUT);\n\t\t\t\n\t\t\tthis.webSocket!.send(\"?\");\n\t\t}\n\t\t\n\t};\n\t\n\tdestroy() {\n\t\t\n\t\tthis.isDestroyed = true;\n\t\t\n\t\tthis.#queue.length = 0;\n\t\t\n\t\tthis.close(CODES.NORMAL, \"destroy\");\n\t\t\n\t\tthis.emit(\"destroy\");\n\t\t\n\t\tthis.removeAllListeners();\n\t\t\n\t\tthis.#abortSignal?.removeEventListener(\"abort\", this.#handleAbortSignalAbort);\n\t\t\n\t}\n\t\n\t\n\tstatic CONNECTION_QUALITY = {\n\t\tCLOSED: 0,\n\t\tRECONNECTING: 1,\n\t\tUNRESPONSIVE: 2,\n\t\tCHECKING_RESPONSIVENESS: 3,\n\t\tOPEN: 4\n\t} as const;\n\t\n}\n", "export const HEARTBEAT_INTERVAL = 5_000;\nexport const HEARTBEAT_GAP = 30_000;\nexport const RESPONSIVENESS_TIMEOUT = 1000;\nexport const OFFLINE_TIMEOUT = 5000;\nexport const REQUEST_COUNTER_LIMIT = Number.MAX_SAFE_INTEGER / 2;\n\nexport const CODES = {\n\tNORMAL: 1000,\n\tPROTOCOL_ERROR: 1002,\n\tABNORMAL: 1006,\n\tNO_HEARTBEAT: 3000,\n\tOFFLINE: 3001,\n\tMANUAL: 3500,\n\tREOPEN: 4000\n} as const;\n\nexport const NON_RECONNECTABLE_CODES = [\n\tCODES.PROTOCOL_ERROR,\n\tCODES.MANUAL,\n\tCODES.REOPEN\n];\n\nexport const REQUEST_HEADERS = {\n\tREQUEST: \"~r-q\",\n\tRESPONSE: \"~r-s\"\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["EventEmitter", "noop", "StatefulPromise", "REQUEST_COUNTER_LIMIT", "CODES", "NON_RECONNECTABLE_CODES", "REQUEST_HEADERS", "i", "
|
|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,mBAAmB,EAExB,KAAKX,IAAc,oBAAoB,QAAS,KAAKC,EAAuB,CAE7E,CAGA,OAAO,mBAAqB,CAC3B,OAAQ,EACR,aAAc,EACd,aAAc,EACd,wBAAyB,EACzB,KAAM,CACP,CAED",
|
|
6
|
+
"names": ["EventEmitter", "noop", "StatefulPromise", "REQUEST_COUNTER_LIMIT", "CODES", "NON_RECONNECTABLE_CODES", "REQUEST_HEADERS", "i", "WS", "_WS", "EventEmitter", "options", "url", "name", "protocols", "immediately", "reconnectAfter", "on", "once", "quiet", "signal", "eventName", "#isQuiet", "#abortSignal", "#handleAbortSignalAbort", "noop", "error", "event", "listener", "#updateConnectionQuality", "connectionQuality", "prevConnectionQuality", "#heartbeatTimeout", "#defib", "CODES", "#unresponsiveTimeout", "#isCheckingResponsiveness", "#offlineTimeout", "#isUnresponsive", "#openPromise", "#wasOpened", "#handleWebSocketOpen", "#handleWebSocketMessage", "message", "kind", "rest", "REQUEST_HEADERS", "#handleRequest", "#handleWebSocketError", "#reconnectTimeout", "#decideReconnect", "code", "NON_RECONNECTABLE_CODES", "#handleWebSocketClose", "reason", "wasClean", "webSocket", "#handleOffline", "prevURL", "StatefulPromise", "_", "reject", "#queue", "#releaseQueue", "data", "args", "#requestCounter", "id", "REQUEST_COUNTER_LIMIT", "lastArg", "resolve", "result", "restProps", "#requestListeners", "requestError"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WSServer.d.ts","sourceRoot":"","sources":["../../src/server/WSServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAQrC,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,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,GAAG,IAAI;IAC/F,EAAE,CAAC,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,IAAI;IAE3E,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAKhF,QAAQ,CAAC,iBAAiB,QAAQ;IAClC,QAAQ,CAAC,uBAAuB,SAAS;IACzC,QAAQ,CAAC,WAAW,SAAS;IAE7B,IAAI,SAAC;IACL,IAAI,SAAC;IACL,IAAI,QAAQ,WAEX;IAED,MAAM,+IAAC;IAEP,IAAI,GAAG,YAEN;IAED,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAEzB,CAAC,sBAAsB,CAAC,qCAA4C;IAEpE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,CAAC,IAAI,CAAC;IAMhE;;OAEG;IACH,SAAS,SATgB,MAAM,YAAY,eAAe,CAAC,IAAI,CAAC,UAS5B;IAEpC,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAMlC;;OAEG;IACH,UAAU,SATkB,MAAM,UASM;IAwBxC,MAAM,CAAC,SAAS,CAAC,KAAK,SAAS,cAAc,EAAE,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC,aAAa;IAMjH,MAAM,CAAC,WAAW;;;;;;;;MAAS;CAE3B"}
|
|
@@ -29,11 +29,10 @@ export declare class WSServerClient extends WebSocket {
|
|
|
29
29
|
[requestCounterSymbol]: number;
|
|
30
30
|
sendRequest(...args: unknown[]): this | Promise<unknown>;
|
|
31
31
|
static makeHeartbeatInterval(this: WSServerClient): NodeJS.Timeout;
|
|
32
|
-
static extend(this: WSServerClient): void;
|
|
33
32
|
static handleConnect(this: WSServerClient): void;
|
|
34
33
|
static handleMessage(this: WSServerClient, data: RawData): void;
|
|
35
34
|
static handleRequest(this: WSServerClient, id: number, kind: string, ...rest: unknown[]): Promise<void>;
|
|
36
|
-
static handleError(this: WSServerClient, error: Error |
|
|
35
|
+
static handleError(this: WSServerClient, error: Error | undefined): void;
|
|
37
36
|
static handleClose(this: WSServerClient, code: number, reason: Buffer): void;
|
|
38
37
|
static CLOSE_CODES: {
|
|
39
38
|
readonly NORMAL: 1000;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WSServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WSServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AASxC,OAAO,EACN,WAAW,EACX,uBAAuB,EACvB,sBAAsB,EACtB,iBAAiB,EAEjB,oBAAoB,EAEpB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMtC,qBAAa,cAAe,SAAQ,SAAS;IAC5C,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IACtF,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IACtE,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;IACpF,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,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}
|
package/dist/server/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{WebSocketServer as
|
|
1
|
+
import{WebSocketServer as W}from"ws";import{createServer as x,getRemoteAddress as w,resolveSSL as A,showServerListeningMessage as C}from"insite-common/backend";var y=Number.MAX_SAFE_INTEGER/2,S={NORMAL:1e3,PROTOCOL_ERROR:1002,ABNORMAL:1006,NO_HEARTBEAT:3e3,OFFLINE:3001,MANUAL:3500,REOPEN:4e3},L=[S.PROTOCOL_ERROR,S.MANUAL,S.REOPEN],c={REQUEST:"~r-q",RESPONSE:"~r-s"};var n=Symbol("isQuiet"),m=Symbol("requestListeners"),b=Symbol("heartbeatInterval"),v=Symbol("heartbeatTimeout"),g=Symbol("defib"),d=Symbol("heartbeatTs"),E=Symbol("requestCounter");import{WebSocket as T}from"ws";import{handleMongoError as N}from"@nesvet/n";var p=class o extends T{on(e,t){return super.on(e,t)}get isConnecting(){return this.readyState===this.CONNECTING}get isOpen(){return this.readyState===this.OPEN}get isClosing(){return this.readyState===this.CLOSING}get isClosed(){return this.readyState===this.CLOSED}isWebSocketServerClient=!0;isWebSocketServer=!1;isWebSocket=!1;wss;userAgent="";remoteAddress="";[v];[g](){clearTimeout(this[v]),this[v]=setTimeout(()=>this.terminate(),35e3)}latency=0;[d];[b]=o.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}[E]=0;sendRequest(...e){let t=this[E]++;this[E]>=y&&(this[E]=0);let s=`message:${c.RESPONSE}-${t}`;return typeof e.at(-1)=="function"?(this.once(s,e.splice(-1,1)[0]),this.sendMessage(c.REQUEST,t,...e),this):new Promise((i,a)=>{this.once(s,(r,h)=>{if(r){let{message:u,...l}=r;a(Object.assign(new Error(u),l))}else i(h)}),this.sendMessage(c.REQUEST,t,...e)})}static makeHeartbeatInterval(){return setInterval(()=>{this[d]=Date.now(),this.send("")},5e3)}static handleConnect(){this.on("message",o.handleMessage),this.on("error",o.handleError),this.on("close",o.handleClose),this[g]()}static handleMessage(e){let t=e.toString();if(this[g](),t)if(t==="?")this.send("!");else try{let[s,...i]=JSON.parse(t);s===c.REQUEST?o.handleRequest.call(this,...i):(this.emit(`message:${s}`,...i),this.wss.emit("client-message",this,s,...i),this.wss.emit(`client-message:${s}`,this,...i))}catch(s){o.handleError.call(this,s)}else this[d]&&(this.latency=Date.now()-this[d],this[d]=void 0)}static async handleRequest(e,t,...s){let i=this.wss[m].get(t),a,r=null;if(i)try{a=await i.call(this.wss,this,...s)}catch(h){if(process.env.NODE_ENV==="development"&&N(h),h instanceof Error){let{message:u,...l}=h;r={message:u,...l}}process.env.NODE_ENV==="development"&&!this.wss[n]&&console.error(`${this.wss.icon}\u2757\uFE0F WS Server request "${t}" (${e}):`,h)}else r={message:`Unknown request kind "${t}"`};this.sendMessage(`${c.RESPONSE}-${e}`,r,a)}static handleError(e){this.wss[n]||console.error(`${this.wss.icon}\u2757\uFE0F WS Server client`,"user"in this?`\x1B[1m${this.user.email}\x1B[0m:`:"\x1B[3manonymous\x1B[0m:",e),this.wss.emit("client-error",this,e)}static handleClose(e,t){if(process.env.NODE_ENV==="development"){let s=t.toString();this.wss[n]||console.info(`${this.wss.icon} WS Server:`,"user"in this?`\x1B[1m${this.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m",`disconnected ${e?`with code ${e}`:""} ${e&&s?"and ":""}${s?`reason "${s}"`:""}`)}clearTimeout(this[v]),clearInterval(this[b]),this.wss.emit("client-close",this)}static CLOSE_CODES=S};var R=class o extends W{constructor(e){let{icon:t="\u{1F50C}",name:s="WS",ssl:i,port:a,server:r=x(o.makeProps(e)),quiet:h=!1,...u}=e;super({WebSocket:p,...u,server:r}),this.icon=t,this.name=s,this.server=r,e.server?new Promise(l=>{r.listening?l():r.on("listening",l)}).then(()=>C(this)):this.server.listen(typeof a=="string"?Number.parseInt(a):a??(this.isS?443:80),()=>C(this)),this[n]=h,this.on("connection",this.#e),this[n]||(this.on("error",l=>console.error(`${this.icon}\u2757\uFE0F WS Server:`,l)),this.on("close",()=>console.error(`${this.icon}\u2757\uFE0F WS Server closed`)))}on(e,t){return super.on(e,t)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;icon;name;get protocol(){return`ws${this.isS?"s":""}`}server;get isS(){return"setSecureContext"in this.server}[n];[m]=new Map;addRequestListener(e,t){return this[m].set(e,t),this}onRequest=this.addRequestListener;removeRequestListener(e){return this[m].delete(e),this}offRequest=this.removeRequestListener;#e(e,t){Object.assign(e,{wss:this,userAgent:t.headers["user-agent"]??"",remoteAddress:w(t)}),p.handleConnect.call(e),this.emit("client-connect",e,t),process.env.NODE_ENV==="development"&&!this[n]&&console.info(`${this.icon} WS Server:`,"user"in e?`\x1B[1m${e.user.email}\x1B[0m`:"\x1B[3manonymous\x1B[0m","connected")}static makeProps({ssl:e}){return{...A(e)}}static CLOSE_CODES=S};export{R as WSServer,p as WSServerClient};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/WSServer.ts", "../../src/common.ts", "../../src/server/symbols.ts", "../../src/server/WSServerClient.ts"],
|
|
4
|
-
"sourcesContent": ["import type http from \"node:http\";\nimport type https from \"node:https\";\nimport { WebSocketServer } from \"ws\";\nimport {\n\tcreateServer,\n\tgetRemoteAddress,\n\tresolveSSL,\n\tshowServerListeningMessage\n} from \"insite-common/backend\";\nimport { CODES } from \"../common\";\nimport { isQuietSymbol, requestListenersSymbol } from \"./symbols\";\nimport { WSServerClient } from \"./WSServerClient\";\nimport type { Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {\n\tconstructor(options: Options<WSSC>) {\n\t\tconst {\n\t\t\ticon = \"\uD83D\uDD0C\",\n\t\t\tname = \"WS\",\n\t\t\tssl: _,\n\t\t\tport,\n\t\t\tserver = createServer(WSServer.makeProps(options)),\n\t\t\tquiet = false,\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: WSServerClient,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.icon = icon;\n\t\tthis.name = name;\n\t\t\n\t\tthis.server = server;\n\t\t\n\t\tif (options.server)\n\t\t\tvoid new Promise<void>(resolve => void (\n\t\t\t\tserver.listening ?\n\t\t\t\t\tresolve() :\n\t\t\t\t\tserver.on(\"listening\", resolve)\n\t\t\t)).then(() => showServerListeningMessage(this));\n\t\telse\n\t\t\tthis.server.listen(\n\t\t\t\ttypeof port == \"string\" ?\n\t\t\t\t\tNumber.parseInt(port) :\n\t\t\t\t\tport ?? (this.isS ? 443 : 80),\n\t\t\t\t() => showServerListeningMessage(this)\n\t\t\t);\n\t\t\n\t\tthis[isQuietSymbol] = quiet;\n\t\t\n\t\tthis.on(\"connection\", this.#handleConnection);\n\t\t\n\t\tif (!this[isQuietSymbol]) {\n\t\t\tthis.on(\"error\", (error: Error) => console.error(`${this.icon}\u2757\uFE0F WS Server:`, error));\n\t\t\t\n\t\t\tthis.on(\"close\", () => console.error(`${this.icon}\u2757\uFE0F WS Server closed`));\n\t\t}\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: this, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: this, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: this, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: this) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: this, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: this, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: this, wscc: WSSC, ...args: any[]) => void): this;\n\ton(event: \"client-close\", listener: (this: this, wscc: WSSC) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocketServer, ...args: any[]) => void);\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\ticon;\n\tname;\n\tget protocol() {\n\t\treturn `ws${this.isS ? \"s\" : \"\"}`;\n\t}\n\t\n\tserver;\n\t\n\tget isS() {\n\t\treturn \"setSecureContext\" in this.server;\n\t}\n\t\n\t[isQuietSymbol]: boolean;\n\t\n\t[requestListenersSymbol] = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis[requestListenersSymbol].set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `addRequestListener()`\n\t */\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis[requestListenersSymbol].delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `removeRequestListener()`\n\t */\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\t\n\t\t/* Compatibility with Bun */\n\t\tif (!(wssc instanceof WSServerClient))\n\t\t\tWSServerClient.extend.call(wssc);\n\t\t\n\t\tObject.assign(wssc, {\n\t\t\twss: this,\n\t\t\tuserAgent: request.headers[\"user-agent\"] ?? \"\",\n\t\t\tremoteAddress: getRemoteAddress(request)\n\t\t});\n\t\t\n\t\tWSServerClient.handleConnect.call(wssc);\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\" && !this[isQuietSymbol])\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\"connected\"\n\t\t\t);\n\t\t\n\t}\n\t\n\t\n\tstatic makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions {\n\t\treturn {\n\t\t\t...resolveSSL(ssl)\n\t\t};\n\t}\n\t\n\tstatic CLOSE_CODES = CODES;\n\t\n}\n", "export const HEARTBEAT_INTERVAL = 5_000;\nexport const HEARTBEAT_GAP = 30_000;\nexport const RESPONSIVENESS_TIMEOUT = 1000;\nexport const OFFLINE_TIMEOUT = 5000;\nexport const REQUEST_COUNTER_LIMIT = Number.MAX_SAFE_INTEGER / 2;\n\nexport const CODES = {\n\tNORMAL: 1000,\n\tPROTOCOL_ERROR: 1002,\n\tABNORMAL: 1006,\n\tNO_HEARTBEAT: 3000,\n\tOFFLINE: 3001,\n\tMANUAL: 3500,\n\tREOPEN: 4000\n} as const;\n\nexport const NON_RECONNECTABLE_CODES = [\n\tCODES.PROTOCOL_ERROR,\n\tCODES.MANUAL,\n\tCODES.REOPEN\n];\n\nexport const REQUEST_HEADERS = {\n\tREQUEST: \"~r-q\",\n\tRESPONSE: \"~r-s\"\n};\n", "export const isQuietSymbol = Symbol(\"isQuiet\");\nexport const requestListenersSymbol = Symbol(\"requestListeners\");\nexport const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const heartbeatTimeoutSymbol = Symbol(\"heartbeatTimeout\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const heartbeatTsSymbol = Symbol(\"heartbeatTs\");\nexport const requestCounterSymbol = Symbol(\"requestCounter\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { handleMongoError } from \"@nesvet/n\";\nimport {\n\tCODES,\n\tHEARTBEAT_GAP,\n\tHEARTBEAT_INTERVAL,\n\tREQUEST_COUNTER_LIMIT,\n\tREQUEST_HEADERS\n} from \"../common\";\nimport {\n\tdefibSymbol,\n\theartbeatIntervalSymbol,\n\theartbeatTimeoutSymbol,\n\theartbeatTsSymbol,\n\tisQuietSymbol,\n\trequestCounterSymbol,\n\trequestListenersSymbol\n} from \"./symbols\";\nimport { WSServer } from \"./WSServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServerClient extends WebSocket {\n\ton(event: \"close\", listener: (this: this, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: this, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: this, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: this, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: this) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: this, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocket, ...args: any[]) => void);\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.readyState === this.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.readyState === this.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.readyState === this.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.readyState === this.CLOSED;\n\t}\n\t\n\treadonly isWebSocketServerClient = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocket = false;\n\t\n\twss!: WSServer<this>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[heartbeatTimeoutSymbol]?: ReturnType<typeof setTimeout>;\n\t\n\t[defibSymbol]() {\n\t\t\n\t\tclearTimeout(this[heartbeatTimeoutSymbol]);\n\t\t\n\t\tthis[heartbeatTimeoutSymbol] = setTimeout(\n\t\t\t() => this.terminate(),\n\t\t\tHEARTBEAT_INTERVAL + HEARTBEAT_GAP\n\t\t);\n\t\t\n\t}\n\t\n\tlatency = 0;\n\t\n\t[heartbeatTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = WSServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\t[requestCounterSymbol]: number = 0;\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = this[requestCounterSymbol]++;\n\t\t\n\t\tif (this[requestCounterSymbol] >= REQUEST_COUNTER_LIMIT)\n\t\t\tthis[requestCounterSymbol] = 0;\n\t\t\n\t\tconst eventName = `message:${REQUEST_HEADERS.RESPONSE}-${id}`;\n\t\t\n\t\tif (typeof args.at(-1) == \"function\") {\n\t\t\tthis.once(eventName, args.splice(-1, 1)[0] as () => void);\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps) as Error);\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeHeartbeatInterval(this: WSServerClient) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[heartbeatTsSymbol] = Date.now();\n\t\t\t\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, HEARTBEAT_INTERVAL);\n\t}\n\t\n\t/* Compatibility with Bun */\n\tstatic extend(this: WSServerClient) {\n\t\t\n\t\tObject.defineProperties(this, {\n\t\t\tisConnecting: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isConnecting\")!.get\n\t\t\t},\n\t\t\tisOpen: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isOpen\")!.get\n\t\t\t},\n\t\t\tisClosing: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosing\")!.get\n\t\t\t},\n\t\t\tisClosed: {\n\t\t\t\tget: Object.getOwnPropertyDescriptor(WSServerClient.prototype, \"isClosed\")!.get\n\t\t\t}\n\t\t});\n\t\t\n\t\tObject.assign(this, {\n\t\t\tisWebSocketServerClient: true,\n\t\t\tisWebSocketServer: false,\n\t\t\tisWebSocket: false,\n\t\t\t[defibSymbol]: WSServerClient.prototype[defibSymbol],\n\t\t\tlatency: 0,\n\t\t\t[requestCounterSymbol]: 0,\n\t\t\t[heartbeatIntervalSymbol]: WSServerClient.makeHeartbeatInterval.call(this),\n\t\t\tsendMessage: WSServerClient.prototype.sendMessage,\n\t\t\tsendRequest: WSServerClient.prototype.sendRequest\n\t\t});\n\t\t\n\t}\n\t\n\tstatic handleConnect(this: WSServerClient) {\n\t\t\n\t\tthis.on(\"message\", WSServerClient.handleMessage);\n\t\tthis.on(\"error\", WSServerClient.handleError);\n\t\tthis.on(\"close\", WSServerClient.handleClose);\n\t\t\n\t\tthis[defibSymbol]();\n\t\t\n\t}\n\t\n\tstatic handleMessage(this: WSServerClient, data: RawData) {\n\t\tconst message = data.toString();// eslint-disable-line @typescript-eslint/no-base-to-string\n\t\t\n\t\tthis[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\tif (message === \"?\")\n\t\t\t\tthis.send(\"!\");\n\t\t\telse\n\t\t\t\ttry {\n\t\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\t\n\t\t\t\t\tswitch (kind) {\n\t\t\t\t\t\tcase REQUEST_HEADERS.REQUEST:\n\t\t\t\t\t\t\tvoid WSServerClient.handleRequest.call(this, ...rest as [ id: number, kind: string, ...rest: unknown[] ]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthis.emit(`message:${kind}`, ...rest);\n\t\t\t\t\t\t\tthis.wss.emit(\"client-message\", this, kind, ...rest);\n\t\t\t\t\t\t\tthis.wss.emit(`client-message:${kind}`, this, ...rest);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tWSServerClient.handleError.call(this, error as Error);\n\t\t\t\t}\n\t\telse if (this[heartbeatTsSymbol]) {\n\t\t\tthis.latency = Date.now() - this[heartbeatTsSymbol];\n\t\t\tthis[heartbeatTsSymbol] = undefined;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic async handleRequest(this: WSServerClient, id: number, kind: string, ...rest: unknown[]) {\n\t\tconst listener = this.wss[requestListenersSymbol].get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.call(this.wss, this, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\thandleMongoError(error);\n\t\t\t\t\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (process.env.NODE_ENV === \"development\" && !this.wss[isQuietSymbol])\n\t\t\t\t\tconsole.error(`${this.wss.icon}\u2757\uFE0F WS Server request \"${kind}\" (${id}):`, error);\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\tthis.sendMessage(`${REQUEST_HEADERS.RESPONSE}-${id}`, requestError, result);\n\t\t\n\t}\n\t\n\tstatic handleError(this: WSServerClient, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tif (!this.wss[isQuietSymbol])\n\t\t\tconsole.error(\n\t\t\t\t`${this.wss.icon}\u2757\uFE0F WS Server client`,\n\t\t\t\t\"user\" in this ? `\\x1B[1m${(this.user as { email: string }).email}\\x1B[0m:` : \"\\x1B[3manonymous\\x1B[0m:\",\n\t\t\t\terror\n\t\t\t);\n\t\t\n\t\tthis.wss.emit(\"client-error\", this, error);\n\t\t\n\t}\n\t\n\tstatic handleClose(this: WSServerClient, code: number, reason: Buffer) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst reasonString = reason.toString();\n\t\t\t\n\t\t\tif (!this.wss[isQuietSymbol])\n\t\t\t\tconsole.info(\n\t\t\t\t\t`${this.wss.icon} WS Server:`,\n\t\t\t\t\t\"user\" in this ? `\\x1B[1m${(this.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\t`disconnected ${code ? `with code ${code}` : \"\"} ${code && reasonString ? \"and \" : \"\"}${reasonString ? `reason \"${reasonString}\"` : \"\"}`\n\t\t\t\t);\n\t\t}\n\t\t\n\t\tclearTimeout(this[heartbeatTimeoutSymbol]);\n\t\tclearInterval(this[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.wss.emit(\"client-close\", this);\n\t\t\n\t}\n\t\n\tstatic CLOSE_CODES = CODES;\n\t\n}\n"],
|
|
5
|
-
"mappings": "AAEA,OAAS,mBAAAA,MAAuB,KAChC,OACC,gBAAAC,EACA,oBAAAC,EACA,cAAAC,EACA,8BAAAC,MACM,wBCJA,IAAMC,EAAwB,OAAO,iBAAmB,EAElDC,EAAQ,CACpB,OAAQ,IACR,eAAgB,KAChB,SAAU,KACV,aAAc,IACd,QAAS,KACT,OAAQ,KACR,OAAQ,GACT,EAEaC,EAA0B,CACtCD,EAAM,eACNA,EAAM,OACNA,EAAM,MACP,EAEaE,EAAkB,CAC9B,QAAS,OACT,SAAU,MACX,ECzBO,IAAMC,EAAgB,OAAO,SAAS,EAChCC,EAAyB,OAAO,kBAAkB,EAClDC,EAA0B,OAAO,mBAAmB,EACpDC,EAAyB,OAAO,kBAAkB,EAClDC,EAAc,OAAO,OAAO,E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W,CAEvC,KAAK,KAAKH,EAAW,CAACI,EAAOC,IAAW,CACvC,GAAID,EAAO,CACV,GAAM,CAAE,QAAAE,EAAS,GAAGC,CAAU,EAAIH,EAClCD,EAAO,OAAO,OAAO,IAAI,MAAMG,CAAO,EAAGC,CAAS,CAAU,CAC7D,MACCL,EAAQG,CAAM,CAEhB,CAAC,EAED,KAAK,YAAYJ,EAAgB,QAASH,EAAI,GAAGF,CAAI,CAEtD,CAAC,CACF,CAGA,OAAO,uBAA4C,CAClD,OAAO,YAAY,IAAM,CAExB,KAAKF,CAAiB,EAAI,KAAK,IAAI,EAEnC,KAAK,KAAK,EAAE,CAEb,EAAG,GAAkB,CACtB,
|
|
4
|
+
"sourcesContent": ["import type http from \"node:http\";\nimport type https from \"node:https\";\nimport { WebSocketServer } from \"ws\";\nimport {\n\tcreateServer,\n\tgetRemoteAddress,\n\tresolveSSL,\n\tshowServerListeningMessage\n} from \"insite-common/backend\";\nimport { CODES } from \"../common\";\nimport { isQuietSymbol, requestListenersSymbol } from \"./symbols\";\nimport { WSServerClient } from \"./WSServerClient\";\nimport type { Options, RequestListener } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServer<WSSC extends WSServerClient = WSServerClient> extends WebSocketServer<typeof WSServerClient> {\n\tconstructor(options: Options<WSSC>) {\n\t\tconst {\n\t\t\ticon = \"\uD83D\uDD0C\",\n\t\t\tname = \"WS\",\n\t\t\tssl: _,\n\t\t\tport,\n\t\t\tserver = createServer(WSServer.makeProps(options)),\n\t\t\tquiet = false,\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: WSServerClient,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.icon = icon;\n\t\tthis.name = name;\n\t\t\n\t\tthis.server = server;\n\t\t\n\t\tif (options.server)\n\t\t\tvoid new Promise<void>(resolve => void (\n\t\t\t\tserver.listening ?\n\t\t\t\t\tresolve() :\n\t\t\t\t\tserver.on(\"listening\", resolve)\n\t\t\t)).then(() => showServerListeningMessage(this));\n\t\telse\n\t\t\tthis.server.listen(\n\t\t\t\ttypeof port == \"string\" ?\n\t\t\t\t\tNumber.parseInt(port) :\n\t\t\t\t\tport ?? (this.isS ? 443 : 80),\n\t\t\t\t() => showServerListeningMessage(this)\n\t\t\t);\n\t\t\n\t\tthis[isQuietSymbol] = quiet;\n\t\t\n\t\tthis.on(\"connection\", this.#handleConnection);\n\t\t\n\t\tif (!this[isQuietSymbol]) {\n\t\t\tthis.on(\"error\", (error: Error) => console.error(`${this.icon}\u2757\uFE0F WS Server:`, error));\n\t\t\t\n\t\t\tthis.on(\"close\", () => console.error(`${this.icon}\u2757\uFE0F WS Server closed`));\n\t\t}\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: this, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: this, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: this, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: this) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: this, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: this, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: this, wscc: WSSC, ...args: any[]) => void): this;\n\ton(event: \"client-close\", listener: (this: this, wscc: WSSC) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocketServer, ...args: any[]) => void);\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\ticon;\n\tname;\n\tget protocol() {\n\t\treturn `ws${this.isS ? \"s\" : \"\"}`;\n\t}\n\t\n\tserver;\n\t\n\tget isS() {\n\t\treturn \"setSecureContext\" in this.server;\n\t}\n\t\n\t[isQuietSymbol]: boolean;\n\t\n\t[requestListenersSymbol] = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis[requestListenersSymbol].set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `addRequestListener()`\n\t */\n\tonRequest = this.addRequestListener;\n\t\n\tremoveRequestListener(kind: string) {\n\t\tthis[requestListenersSymbol].delete(kind);\n\t\t\n\t\treturn this;\n\t}\n\t\n\t/**\n\t * Alias for `removeRequestListener()`\n\t */\n\toffRequest = this.removeRequestListener;\n\t\n\t#handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\t\n\t\tObject.assign(wssc, {\n\t\t\twss: this,\n\t\t\tuserAgent: request.headers[\"user-agent\"] ?? \"\",\n\t\t\tremoteAddress: getRemoteAddress(request)\n\t\t});\n\t\t\n\t\tWSServerClient.handleConnect.call(wssc);\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\" && !this[isQuietSymbol])\n\t\t\tconsole.info(\n\t\t\t\t`${this.icon} WS Server:`,\n\t\t\t\t\"user\" in wssc ? `\\x1B[1m${(wssc.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\"connected\"\n\t\t\t);\n\t\t\n\t}\n\t\n\t\n\tstatic makeProps<SWSSC extends WSServerClient>({ ssl }: Options<SWSSC>): http.ServerOptions | https.ServerOptions {\n\t\treturn {\n\t\t\t...resolveSSL(ssl)\n\t\t};\n\t}\n\t\n\tstatic CLOSE_CODES = CODES;\n\t\n}\n", "export const HEARTBEAT_INTERVAL = 5_000;\nexport const HEARTBEAT_GAP = 30_000;\nexport const RESPONSIVENESS_TIMEOUT = 1000;\nexport const OFFLINE_TIMEOUT = 5000;\nexport const REQUEST_COUNTER_LIMIT = Number.MAX_SAFE_INTEGER / 2;\n\nexport const CODES = {\n\tNORMAL: 1000,\n\tPROTOCOL_ERROR: 1002,\n\tABNORMAL: 1006,\n\tNO_HEARTBEAT: 3000,\n\tOFFLINE: 3001,\n\tMANUAL: 3500,\n\tREOPEN: 4000\n} as const;\n\nexport const NON_RECONNECTABLE_CODES = [\n\tCODES.PROTOCOL_ERROR,\n\tCODES.MANUAL,\n\tCODES.REOPEN\n];\n\nexport const REQUEST_HEADERS = {\n\tREQUEST: \"~r-q\",\n\tRESPONSE: \"~r-s\"\n};\n", "export const isQuietSymbol = Symbol(\"isQuiet\");\nexport const requestListenersSymbol = Symbol(\"requestListeners\");\nexport const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const heartbeatTimeoutSymbol = Symbol(\"heartbeatTimeout\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const heartbeatTsSymbol = Symbol(\"heartbeatTs\");\nexport const requestCounterSymbol = Symbol(\"requestCounter\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { handleMongoError } from \"@nesvet/n\";\nimport {\n\tCODES,\n\tHEARTBEAT_GAP,\n\tHEARTBEAT_INTERVAL,\n\tREQUEST_COUNTER_LIMIT,\n\tREQUEST_HEADERS\n} from \"../common\";\nimport {\n\tdefibSymbol,\n\theartbeatIntervalSymbol,\n\theartbeatTimeoutSymbol,\n\theartbeatTsSymbol,\n\tisQuietSymbol,\n\trequestCounterSymbol,\n\trequestListenersSymbol\n} from \"./symbols\";\nimport { WSServer } from \"./WSServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class WSServerClient extends WebSocket {\n\ton(event: \"close\", listener: (this: this, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: this, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: this, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: this, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: this) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: this, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: this, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as (this: WebSocket, ...args: any[]) => void);\n\t}\n\t\n\tget isConnecting() {\n\t\treturn this.readyState === this.CONNECTING;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.readyState === this.OPEN;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.readyState === this.CLOSING;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.readyState === this.CLOSED;\n\t}\n\t\n\treadonly isWebSocketServerClient = true;\n\treadonly isWebSocketServer = false;\n\treadonly isWebSocket = false;\n\t\n\twss!: WSServer<this>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[heartbeatTimeoutSymbol]?: ReturnType<typeof setTimeout>;\n\t\n\t[defibSymbol]() {\n\t\t\n\t\tclearTimeout(this[heartbeatTimeoutSymbol]);\n\t\t\n\t\tthis[heartbeatTimeoutSymbol] = setTimeout(\n\t\t\t() => this.terminate(),\n\t\t\tHEARTBEAT_INTERVAL + HEARTBEAT_GAP\n\t\t);\n\t\t\n\t}\n\t\n\tlatency = 0;\n\t\n\t[heartbeatTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = WSServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\t[requestCounterSymbol]: number = 0;\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = this[requestCounterSymbol]++;\n\t\t\n\t\tif (this[requestCounterSymbol] >= REQUEST_COUNTER_LIMIT)\n\t\t\tthis[requestCounterSymbol] = 0;\n\t\t\n\t\tconst eventName = `message:${REQUEST_HEADERS.RESPONSE}-${id}`;\n\t\t\n\t\tif (typeof args.at(-1) == \"function\") {\n\t\t\tthis.once(eventName, args.splice(-1, 1)[0] as () => void);\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t\treturn this;\n\t\t}\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t\n\t\t\tthis.once(eventName, (error, result) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\treject(Object.assign(new Error(message), restProps) as Error);\n\t\t\t\t} else\n\t\t\t\t\tresolve(result);\n\t\t\t\t\n\t\t\t});\n\t\t\t\n\t\t\tthis.sendMessage(REQUEST_HEADERS.REQUEST, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeHeartbeatInterval(this: WSServerClient) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[heartbeatTsSymbol] = Date.now();\n\t\t\t\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, HEARTBEAT_INTERVAL);\n\t}\n\t\n\tstatic handleConnect(this: WSServerClient) {\n\t\t\n\t\tthis.on(\"message\", WSServerClient.handleMessage);\n\t\tthis.on(\"error\", WSServerClient.handleError);\n\t\tthis.on(\"close\", WSServerClient.handleClose);\n\t\t\n\t\tthis[defibSymbol]();\n\t\t\n\t}\n\t\n\tstatic handleMessage(this: WSServerClient, data: RawData) {\n\t\tconst message = data.toString();// eslint-disable-line @typescript-eslint/no-base-to-string\n\t\t\n\t\tthis[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\tif (message === \"?\")\n\t\t\t\tthis.send(\"!\");\n\t\t\telse\n\t\t\t\ttry {\n\t\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\t\n\t\t\t\t\tswitch (kind) {\n\t\t\t\t\t\tcase REQUEST_HEADERS.REQUEST:\n\t\t\t\t\t\t\tvoid WSServerClient.handleRequest.call(this, ...rest as [ id: number, kind: string, ...rest: unknown[] ]);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthis.emit(`message:${kind}`, ...rest);\n\t\t\t\t\t\t\tthis.wss.emit(\"client-message\", this, kind, ...rest);\n\t\t\t\t\t\t\tthis.wss.emit(`client-message:${kind}`, this, ...rest);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tWSServerClient.handleError.call(this, error as Error);\n\t\t\t\t}\n\t\telse if (this[heartbeatTsSymbol]) {\n\t\t\tthis.latency = Date.now() - this[heartbeatTsSymbol];\n\t\t\tthis[heartbeatTsSymbol] = undefined;\n\t\t}\n\t\t\n\t}\n\t\n\tstatic async handleRequest(this: WSServerClient, id: number, kind: string, ...rest: unknown[]) {\n\t\tconst listener = this.wss[requestListenersSymbol].get(kind);\n\t\t\n\t\tlet result;\n\t\tlet requestError = null;\n\t\t\n\t\tif (listener)\n\t\t\ttry {\n\t\t\t\tresult = await listener.call(this.wss, this, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\t\thandleMongoError(error);\n\t\t\t\t\n\t\t\t\tif (error instanceof Error) {\n\t\t\t\t\tconst { message, ...restProps } = error;\n\t\t\t\t\trequestError = { message, ...restProps };\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (process.env.NODE_ENV === \"development\" && !this.wss[isQuietSymbol])\n\t\t\t\t\tconsole.error(`${this.wss.icon}\u2757\uFE0F WS Server request \"${kind}\" (${id}):`, error);\n\t\t\t}\n\t\telse\n\t\t\trequestError = { message: `Unknown request kind \"${kind}\"` };\n\t\t\n\t\tthis.sendMessage(`${REQUEST_HEADERS.RESPONSE}-${id}`, requestError, result);\n\t\t\n\t}\n\t\n\tstatic handleError(this: WSServerClient, error: Error | undefined) {\n\t\t\n\t\tif (!this.wss[isQuietSymbol])\n\t\t\tconsole.error(\n\t\t\t\t`${this.wss.icon}\u2757\uFE0F WS Server client`,\n\t\t\t\t\"user\" in this ? `\\x1B[1m${(this.user as { email: string }).email}\\x1B[0m:` : \"\\x1B[3manonymous\\x1B[0m:\",\n\t\t\t\terror\n\t\t\t);\n\t\t\n\t\tthis.wss.emit(\"client-error\", this, error);\n\t\t\n\t}\n\t\n\tstatic handleClose(this: WSServerClient, code: number, reason: Buffer) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tconst reasonString = reason.toString();\n\t\t\t\n\t\t\tif (!this.wss[isQuietSymbol])\n\t\t\t\tconsole.info(\n\t\t\t\t\t`${this.wss.icon} WS Server:`,\n\t\t\t\t\t\"user\" in this ? `\\x1B[1m${(this.user as { email: string }).email}\\x1B[0m` : \"\\x1B[3manonymous\\x1B[0m\",\n\t\t\t\t\t`disconnected ${code ? `with code ${code}` : \"\"} ${code && reasonString ? \"and \" : \"\"}${reasonString ? `reason \"${reasonString}\"` : \"\"}`\n\t\t\t\t);\n\t\t}\n\t\t\n\t\tclearTimeout(this[heartbeatTimeoutSymbol]);\n\t\tclearInterval(this[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.wss.emit(\"client-close\", this);\n\t\t\n\t}\n\t\n\tstatic CLOSE_CODES = CODES;\n\t\n}\n"],
|
|
5
|
+
"mappings": "AAEA,OAAS,mBAAAA,MAAuB,KAChC,OACC,gBAAAC,EACA,oBAAAC,EACA,cAAAC,EACA,8BAAAC,MACM,wBCJA,IAAMC,EAAwB,OAAO,iBAAmB,EAElDC,EAAQ,CACpB,OAAQ,IACR,eAAgB,KAChB,SAAU,KACV,aAAc,IACd,QAAS,KACT,OAAQ,KACR,OAAQ,GACT,EAEaC,EAA0B,CACtCD,EAAM,eACNA,EAAM,OACNA,EAAM,MACP,EAEaE,EAAkB,CAC9B,QAAS,OACT,SAAU,MACX,ECzBO,IAAMC,EAAgB,OAAO,SAAS,EAChCC,EAAyB,OAAO,kBAAkB,EAClDC,EAA0B,OAAO,mBAAmB,EACpDC,EAAyB,OAAO,kBAAkB,EAClDC,EAAc,OAAO,OAAO,EAC5BC,EAAo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AAM,CACT,MAAO,qBAAsB,KAAK,MACnC,CAEA,CAACJ,CAAa,EAEd,CAACK,CAAsB,EAAI,IAAI,IAE/B,mBAAmBC,EAAcF,EAAiC,CACjE,YAAKC,CAAsB,EAAE,IAAIC,EAAMF,CAAQ,EAExC,IACR,CAKA,UAAY,KAAK,mBAEjB,sBAAsBE,EAAc,CACnC,YAAKD,CAAsB,EAAE,OAAOC,CAAI,EAEjC,IACR,CAKA,WAAa,KAAK,sBAElBL,GAAkBM,EAAYC,EAA+B,CAE5D,OAAO,OAAOD,EAAM,CACnB,IAAK,KACL,UAAWC,EAAQ,QAAQ,YAAY,GAAK,GAC5C,cAAeC,EAAiBD,CAAO,CACxC,CAAC,EAEDX,EAAe,cAAc,KAAKU,CAAI,EAEtC,KAAK,KAAK,iBAAkBA,EAAMC,CAAO,EAErC,QAAQ,IAAI,WAAa,eAAiB,CAAC,KAAKR,CAAa,GAChE,QAAQ,KACP,GAAG,KAAK,IAAI,cACZ,SAAUO,EAAO,UAAWA,EAAK,KAA2B,KAAK,UAAY,0BAC7E,WACD,CAEF,CAGA,OAAO,UAAwC,CAAE,IAAAG,CAAI,EAA6D,CACjH,MAAO,CACN,GAAGC,EAAWD,CAAG,CAClB,CACD,CAEA,OAAO,YAAcE,CAEtB",
|
|
6
6
|
"names": ["WebSocketServer", "createServer", "getRemoteAddress", "resolveSSL", "showServerListeningMessage", "REQUEST_COUNTER_LIMIT", "CODES", "NON_RECONNECTABLE_CODES", "REQUEST_HEADERS", "isQuietSymbol", "requestListenersSymbol", "heartbeatIntervalSymbol", "heartbeatTimeoutSymbol", "defibSymbol", "heartbeatTsSymbol", "requestCounterSymbol", "WebSocket", "handleMongoError", "WSServerClient", "_WSServerClient", "WebSocket", "event", "listener", "heartbeatTimeoutSymbol", "defibSymbol", "heartbeatTsSymbol", "heartbeatIntervalSymbol", "args", "requestCounterSymbol", "id", "REQUEST_COUNTER_LIMIT", "eventName", "REQUEST_HEADERS", "resolve", "reject", "error", "result", "message", "restProps", "data", "kind", "rest", "requestListenersSymbol", "requestError", "handleMongoError", "isQuietSymbol", "code", "reason", "reasonString", "CODES", "WSServer", "_WSServer", "WebSocketServer", "options", "icon", "name", "_", "port", "server", "createServer", "quiet", "wssOptions", "WSServerClient", "resolve", "showServerListeningMessage", "isQuietSymbol", "#handleConnection", "error", "event", "listener", "requestListenersSymbol", "kind", "wssc", "request", "getRemoteAddress", "ssl", "resolveSSL", "CODES"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-ws",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"description": "WebSocket abstraction (server + client, heartbeat, RPC)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"insite",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@nesvet/n": "^1.2.1",
|
|
46
46
|
"eventemitter3": "^5.0.4",
|
|
47
|
-
"insite-common": "^2.
|
|
47
|
+
"insite-common": "^2.6.0",
|
|
48
48
|
"ws": "^8.19.0"
|
|
49
49
|
},
|
|
50
|
-
"packageManager": "bun@1.3.9",
|
|
51
50
|
"engines": {
|
|
52
|
-
"
|
|
51
|
+
"bun": ">=1.4.4",
|
|
52
|
+
"node": ">=22.0.0"
|
|
53
53
|
}
|
|
54
54
|
}
|