insite-ws 2.0.13 → 2.0.16
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/.conveyer.ts +2 -1
- package/dist/client/WebSocket.d.ts +10 -2
- package/dist/client/WebSocket.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +2 -2
- package/dist/server/WebSocketServer.d.ts +3 -5
- package/dist/server/WebSocketServer.d.ts.map +1 -1
- package/dist/server/WebSocketServerClient.d.ts +2 -5
- package/dist/server/WebSocketServerClient.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/index.js.map +3 -3
- package/package.json +4 -4
- package/bun.lockb +0 -0
- package/dist/client/types.d.ts +0 -9
- package/dist/client/types.d.ts.map +0 -1
package/.conveyer.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { Conveyer, ESBuild } from "@nesvet/conveyer";
|
|
|
5
5
|
const distDir = "dist";
|
|
6
6
|
|
|
7
7
|
const common = {
|
|
8
|
-
external: true,
|
|
9
8
|
format: "esm",
|
|
10
9
|
sourcemap: true
|
|
11
10
|
};
|
|
@@ -17,6 +16,7 @@ new Conveyer([
|
|
|
17
16
|
title: "Server",
|
|
18
17
|
entryPoints: [ "src/server/index.ts" ],
|
|
19
18
|
outfile: path.resolve(distDir, "server/index.js"),
|
|
19
|
+
external: [ true, "insite-*" ],
|
|
20
20
|
platform: "node",
|
|
21
21
|
target: "node20",
|
|
22
22
|
...common
|
|
@@ -26,6 +26,7 @@ new Conveyer([
|
|
|
26
26
|
title: "Client",
|
|
27
27
|
entryPoints: [ "src/client/index.ts" ],
|
|
28
28
|
outfile: path.resolve(distDir, "client/index.js"),
|
|
29
|
+
external: true,
|
|
29
30
|
platform: "neutral",
|
|
30
31
|
target: "es2020",
|
|
31
32
|
...common
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import EventEmitter from "eventemitter3";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export type Options = {
|
|
3
|
+
url?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
protocols?: string[];
|
|
6
|
+
immediately?: boolean;
|
|
7
|
+
autoReconnect?: boolean;
|
|
8
|
+
on?: Record<string, (...args: any[]) => void>;
|
|
9
|
+
};
|
|
10
|
+
type RequestListener = (...args: any[]) => any | Promise<any>;
|
|
4
11
|
export declare class InSiteWebSocket extends EventEmitter {
|
|
5
12
|
constructor(url: string, options?: Options);
|
|
6
13
|
readonly isWebSocket = true;
|
|
@@ -40,4 +47,5 @@ export declare class InSiteWebSocket extends EventEmitter {
|
|
|
40
47
|
private handleRequest;
|
|
41
48
|
static defib(this: InSiteWebSocket): void;
|
|
42
49
|
}
|
|
50
|
+
export {};
|
|
43
51
|
//# sourceMappingURL=WebSocket.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../../src/client/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"WebSocket.d.ts","sourceRoot":"","sources":["../../src/client/WebSocket.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,eAAe,CAAC;AAWzC,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,KAAK,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAG9D,qBAAa,eAAgB,SAAQ,Y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CAAC,IAAI,EAAE,MAAM;IAMlC,UAAU,SANkB,MAAM,UAMM;IAExC,OAAO,CAAC,aAAa,CAoBnB;IAGF,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,eAAe;CAWlC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var f=Object.defineProperty;var k=(c,o,e)=>o in c?f(c,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[o]=e;var t=(c,o,e)=>k(c,typeof o!="symbol"?o+"":o,e);import g from"eventemitter3";import{debounce as v,noop as p,uid as q}from"@nesvet/n";var u={request:"~r-q",response:"~r-s"};var R=2e3,E=0,b=new WeakMap,S=class c extends g{constructor(e,s={}){super();t(this,"isWebSocket",!0);t(this,"isWebSocketServer",!1);t(this,"isWebSocketServerClient",!1);t(this,"url");t(this,"name");t(this,"protocols");t(this,"autoReconnect");t(this,"webSocket",null);t(this,"defib",v(c.defib,65e3));t(this,"openResolve");t(this,"openReject");t(this,"handleWebSocketOpen",()=>{this.openResolve(),this.openResolve=void 0,this.openReject=void 0,this.emit("open"),this.defib()});t(this,"handleWebSocketMessage",({data:e})=>{if(this.defib(),e)try{let[s,...n]=JSON.parse(e);this.emit("message",s,...n),this.emit(`message:${s}`,...n)}catch(s){this.handleWebSocketError(s)}else this.webSocket.send("")});t(this,"handleWebSocketError",e=>{e instanceof Event&&(e=void 0),this.openReject&&(this.openReject(e),this.openResolve=void 0,this.openReject=void 0),this.emit("error",e)});t(this,"reconnectTimeout");t(this,"handleWebSocketClose",e=>{process.env.NODE_ENV==="development"&&console.info(`WebSocket ${this.name} is closed with code ${e.code} and reason "${e.reason}"`),this.defib.clear(),this.emit("close",e),this.autoReconnect&&![1002,3500,4e3].includes(e.code)&&(process.env.NODE_ENV==="development"&&console.info(`WebSocket ${this.name} will try to reconnect in 2 sec\u2026`),this.reconnectTimeout=setTimeout(()=>this.open().catch(p),R))});t(this,"connect",this.open);t(this,"disconnect",this.close);t(this,"queue",[]);t(this,"releaseQueue",()=>{for(let e of this.queue)this.webSocket.send(e);this.queue.length=0});t(this,"requestListeners",new Map);t(this,"onRequest",this.addRequestListener);t(this,"offRequest",this.removeRequestListener);t(this,"handleRequest",async(e,s,...n)=>{let h=this.requestListeners.get(s),l,r=null;if(h)try{l=await h.apply(this,n)}catch(i){if(i instanceof Error){let{message:a,...d}=i;r={message:a,...d}}}else r={message:`Unknown request kind "${s}"`};this.sendMessage(`${u.response}-${e}`,r,l)});this.url=e;let{name:n=(E++).toString(),protocols:h,immediately:l=!0,autoReconnect:r=!0,on:i}=s;if(this.name=n,this.protocols=h,this.autoReconnect=!!r,this.on(`message:${u.request}`,this.handleRequest),i)for(let a in i)i[a]&&this.on(a,i[a]);this.url&&l&&this.open().catch(p)}get isConnecting(){return this.webSocket?this.webSocket.readyState===this.webSocket.CONNECTING:null}get isOpen(){return this.webSocket?this.webSocket.readyState===this.webSocket.OPEN:null}get isClosing(){return this.webSocket?this.webSocket.readyState===this.webSocket.CLOSING:null}get isClosed(){return this.webSocket?this.webSocket.readyState===this.webSocket.CLOSED:null}async open(e={}){return clearTimeout(this.reconnectTimeout),await this.close(4e3,"reopen"),e.url&&(this.url=e.url),e.protocols&&(this.protocols=e.protocols),this.webSocket&&b.get(this.webSocket)!==this.url&&this.emit("server-change"),new Promise((s,n)=>{this.openResolve=s,this.openReject=n,this.webSocket=new WebSocket(this.url,this.protocols),this.webSocket.addEventListener("open",this.handleWebSocketOpen),this.webSocket.addEventListener("message",this.handleWebSocketMessage),this.webSocket.addEventListener("error",this.handleWebSocketError),this.webSocket.addEventListener("close",this.handleWebSocketClose),this.send=this.webSocket.send.bind(this.webSocket),b.set(this.webSocket,this.url),this.emit("connecting")})}close(e=3500,s="manual"){return clearTimeout(this.reconnectTimeout),new Promise(n=>{this.isConnecting||this.isOpen?(this.webSocket.addEventListener("close",n),this.webSocket.close(e,s)):n(null)})}sendMessage(...e){let s=JSON.stringify(e);this.isOpen?this.webSocket.send(s):(this.queue.length||this.once("open",this.releaseQueue),this.queue.push(s))}sendRequest(...e){let s=q(),n=`message:${u.response}-${s}`;return typeof e.at(-1)=="function"?(this.once(n,e.splice(-1,1)[0]),this.sendMessage(u.request,s,...e),this):new Promise((h,l)=>{this.once(n,(r,i)=>{if(r){let{message:a,...d}=r;l(Object.assign(new Error(a),d))}else h(i)}),this.sendMessage(u.request,s,...e)})}addRequestListener(e,s){return this.requestListeners.set(e,s),this}removeRequestListener(e){return this.requestListeners.delete(e),this}static defib(){this.isOpen&&(process.env.NODE_ENV==="development"&&console.info(`WebSocket ${this.name} has no heartbeat - going offline`),this.webSocket.close())}};export{S as InSiteWebSocket};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/client/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/client/WebSocket.ts", "../../src/common.ts"],
|
|
4
|
-
"sourcesContent": ["import EventEmitter from \"eventemitter3\";\nimport { debounce, noop, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\
|
|
5
|
-
"mappings": "oKAAA,OAAOA,MAAkB,gBACzB,OAAS,YAAAC,EAAU,QAAAC,EAAM,OAAAC,MAAW,YCE7B,IAAMC,EAAiB,CAC7B,QAAS,OACT,SAAU,MACX,
|
|
4
|
+
"sourcesContent": ["import EventEmitter from \"eventemitter3\";\nimport { debounce, noop, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\n\n\nconst reconnectTimeout = 2000;\n\nlet i = 0;\n\nconst webSocketUrlMap = new WeakMap<WebSocket, string>();\n\nexport type Options = {\n\turl?: string;\n\tname?: string;\n\tprotocols?: string[];\n\timmediately?: boolean;\n\tautoReconnect?: boolean;\n\ton?: Record<string, (...args: any[]) => void>;// eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\ntype RequestListener = (...args: any[]) => any | Promise<any>;// eslint-disable-line @typescript-eslint/no-explicit-any\n\n\nexport class InSiteWebSocket extends EventEmitter {\n\tconstructor(url: string, options: Options = {}) {\n\t\tsuper();\n\t\t\n\t\tthis.url = url;\n\t\t\n\t\tconst {\n\t\t\tname = (i++).toString(),\n\t\t\tprotocols,\n\t\t\timmediately = true,\n\t\t\tautoReconnect = true,\n\t\t\ton\n\t\t} = options;\n\t\t\n\t\tthis.name = name;\n\t\t\n\t\tthis.protocols = protocols;\n\t\t\n\t\tthis.autoReconnect = !!autoReconnect;\n\t\t\n\t\tthis.on(`message:${requestHeaders.request}`, this.handleRequest);\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 (this.url && immediately)\n\t\t\tthis.open().catch(noop);\n\t\t\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\tautoReconnect;\n\t\n\tsend?(data: ArrayBufferLike | ArrayBufferView | Blob | string): void;\n\t\n\twebSocket: null | WebSocket = null;\n\t\n\tprivate defib = debounce(InSiteWebSocket.defib, heartbeatInterval + heartbeatGap);\n\t\n\tget isConnecting() {\n\t\treturn this.webSocket ? this.webSocket.readyState === this.webSocket.CONNECTING : null;\n\t}\n\t\n\tget isOpen() {\n\t\treturn this.webSocket ? this.webSocket.readyState === this.webSocket.OPEN : null;\n\t}\n\t\n\tget isClosing() {\n\t\treturn this.webSocket ? this.webSocket.readyState === this.webSocket.CLOSING : null;\n\t}\n\t\n\tget isClosed() {\n\t\treturn this.webSocket ? this.webSocket.readyState === this.webSocket.CLOSED : null;\n\t}\n\t\n\tprivate openResolve?: (value?: unknown) => void;\n\tprivate openReject?: (reason?: unknown) => void;\n\t\n\tprivate handleWebSocketOpen = () => {\n\t\t\n\t\tthis.openResolve!();\n\t\tthis.openResolve = undefined;\n\t\tthis.openReject = undefined;\n\t\t\n\t\tthis.emit(\"open\");\n\t\t\n\t\tthis.defib();\n\t\t\n\t};\n\t\n\tprivate handleWebSocketMessage = ({ data: message }: MessageEvent) => {\n\t\t\n\t\tthis.defib();\n\t\t\n\t\tif (message)\n\t\t\ttry {\n\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\n\t\t\t\tthis.emit(\"message\", kind, ...rest);\n\t\t\t\tthis.emit(`message:${kind}`, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.handleWebSocketError(error as Error);\n\t\t\t}\n\t\telse\n\t\t\tthis.webSocket!.send(\"\");\n\t\t\n\t};\n\t\n\tprivate handleWebSocketError = (error: Error | Event | undefined) => {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tif (this.openReject) {\n\t\t\tthis.openReject(error);\n\t\t\tthis.openResolve = undefined;\n\t\t\tthis.openReject = undefined;\n\t\t}\n\t\t\n\t\tthis.emit(\"error\", error);\n\t\t\n\t};\n\t\n\tprivate reconnectTimeout?: number;\n\t\n\tprivate handleWebSocketClose = (event: CloseEvent) => {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.info(`WebSocket ${this.name} is closed with code ${event.code} and reason \"${event.reason}\"`);\n\t\t\n\t\tthis.defib.clear();\n\t\t\n\t\tthis.emit(\"close\", event);\n\t\t\n\t\tif (this.autoReconnect && ![ 1002, 3500, 4000 ].includes(event.code)) {\n\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\tconsole.info(`WebSocket ${this.name} will try to reconnect in 2 sec\u2026`);\n\t\t\t\n\t\t\tthis.reconnectTimeout = setTimeout(() => this.open().catch(noop), reconnectTimeout) as unknown as number;\n\t\t}\n\t\t\n\t};\n\t\n\tasync open(options: Options = {}) {\n\t\t\n\t\tclearTimeout(this.reconnectTimeout);\n\t\t\n\t\tawait this.close(4000, \"reopen\");\n\t\t\n\t\tif (options.url)\n\t\t\tthis.url = options.url;\n\t\t\n\t\tif (options.protocols)\n\t\t\tthis.protocols = options.protocols;\n\t\t\n\t\tif (this.webSocket && webSocketUrlMap.get(this.webSocket) !== this.url)\n\t\t\tthis.emit(\"server-change\");\n\t\t\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tthis.openResolve = resolve;\n\t\t\tthis.openReject = reject;\n\t\t\t\n\t\t\tthis.webSocket = new WebSocket(this.url, this.protocols);\n\t\t\t\n\t\t\tthis.webSocket.addEventListener(\"open\", this.handleWebSocketOpen);\n\t\t\tthis.webSocket.addEventListener(\"message\", this.handleWebSocketMessage);\n\t\t\tthis.webSocket.addEventListener(\"error\", this.handleWebSocketError);\n\t\t\tthis.webSocket.addEventListener(\"close\", this.handleWebSocketClose);\n\t\t\t\n\t\t\tthis.send = this.webSocket.send.bind(this.webSocket);\n\t\t\t\n\t\t\twebSocketUrlMap.set(this.webSocket, this.url);\n\t\t\t\n\t\t\tthis.emit(\"connecting\");\n\t\t\t\n\t\t});\n\t}\n\t\n\tconnect = this.open;\n\t\n\tclose(code = 3500, reason = \"manual\") {\n\t\t\n\t\tclearTimeout(this.reconnectTimeout);\n\t\t\n\t\treturn new Promise(resolve => {\n\t\t\tif (this.isConnecting || this.isOpen) {\n\t\t\t\tthis.webSocket!.addEventListener(\"close\", resolve);\n\t\t\t\tthis.webSocket!.close(code, reason);\n\t\t\t} else\n\t\t\t\tresolve(null);\n\t\t\t\n\t\t});\n\t}\n\t\n\tdisconnect = this.close;\n\t\n\tprivate queue: string[] = [];\n\t\n\tprivate 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\tsendMessage(...args: unknown[]) {\n\t\tconst message = JSON.stringify(args);\n\t\t\n\t\tif (this.isOpen)\n\t\t\tthis.webSocket!.send(message);\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(message);\n\t\t}\n\t\t\n\t}\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = uid();\n\t\tconst eventName = `message:${requestHeaders.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\tthis.sendMessage(requestHeaders.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));\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\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\tprivate 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\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\toffRequest = this.removeRequestListener;\n\t\n\tprivate handleRequest = async (id: string, 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(`${requestHeaders.response}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\t\n\tstatic defib(this: InSiteWebSocket) {\n\t\t\n\t\tif (this.isOpen) {\n\t\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\t\tconsole.info(`WebSocket ${this.name} has no heartbeat - going offline`);\n\t\t\t\n\t\t\tthis.webSocket!.close();\n\t\t}\n\t\t\n\t}\n\t\n}\n", "export const heartbeatInterval = 5_000;\nexport const heartbeatGap = 60_000;\n\nexport const requestHeaders = {\n\trequest: \"~r-q\",\n\tresponse: \"~r-s\"\n};\n"],
|
|
5
|
+
"mappings": "oKAAA,OAAOA,MAAkB,gBACzB,OAAS,YAAAC,EAAU,QAAAC,EAAM,OAAAC,MAAW,YCE7B,IAAMC,EAAiB,CAC7B,QAAS,OACT,SAAU,MACX,EDDA,IAAMC,EAAmB,IAErBC,EAAI,EAEFC,EAAkB,IAAI,QAcfC,EAAN,MAAMC,UAAwBC,CAAa,CACjD,YAAYC,EAAaC,EAAmB,CAAC,EAAG,CAC/C,MAAM,EA8BPC,EAAA,KAAS,cAAc,IACvBA,EAAA,KAAS,oBAAoB,IAC7BA,EAAA,KAAS,0BAA0B,IAEnCA,EAAA,YAEAA,EAAA,KAAS,QAETA,EAAA,kBAEAA,EAAA,sBAIAA,EAAA,iBAA8B,MAE9BA,EAAA,KAAQ,QAAQC,EAASL,EAAgB,MAAO,IAAgC,GAkBhFI,EAAA,KAAQ,eACRA,EAAA,KAAQ,cAERA,EAAA,KAAQ,sBAAsB,IAAM,CAEnC,KAAK,YAAa,EAClB,KAAK,YAAc,OACnB,KAAK,WAAa,OAElB,KAAK,KAAK,MAAM,EAEhB,KAAK,MAAM,CAEZ,GAEAA,EAAA,KAAQ,yBAAyB,CAAC,CAAE,KAAME,CAAQ,IAAoB,CAIrE,GAFA,KAAK,MAAM,EAEPA,EACH,GAAI,CACH,GAAM,CAAEC,EAAM,GAAGC,CAAK,EAAI,KAAK,MAAMF,CAAO,EAE5C,KAAK,KAAK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L,EAAWK,EAAK,OAAO,GAAI,CAAC,EAAE,CAAC,CAAe,EACxD,KAAK,YAAYX,EAAe,QAASL,EAAI,GAAGgB,CAAI,EAE7C,MAGD,IAAI,QAAQ,CAACJ,EAASC,IAAW,CAEvC,KAAK,KAAKF,EAAW,CAACd,EAAOK,IAAW,CACvC,GAAIL,EAAO,CACV,GAAM,CAAE,QAAAH,EAAS,GAAGU,CAAU,EAAIP,EAClCgB,EAAO,OAAO,OAAO,IAAI,MAAMnB,CAAO,EAAGU,CAAS,CAAC,CACpD,MACCQ,EAAQV,CAAM,CAEhB,CAAC,EACD,KAAK,YAAYG,EAAe,QAASL,EAAI,GAAGgB,CAAI,CAErD,CAAC,CACF,CAIA,mBAAmBrB,EAAcM,EAA2B,CAC3D,YAAK,iBAAiB,IAAIN,EAAMM,CAAQ,EAEjC,IACR,CAIA,sBAAsBN,EAAc,CACnC,YAAK,iBAAiB,OAAOA,CAAI,EAE1B,IACR,CA2BA,OAAO,OAA6B,CAE/B,KAAK,SACJ,QAAQ,IAAI,WAAa,eAC5B,QAAQ,KAAK,aAAa,KAAK,IAAI,mCAAmC,EAEvE,KAAK,UAAW,MAAM,EAGxB,CAED",
|
|
6
6
|
"names": ["EventEmitter", "debounce", "noop", "uid", "requestHeaders", "reconnectTimeout", "i", "webSocketUrlMap", "InSiteWebSocket", "_InSiteWebSocket", "EventEmitter", "url", "options", "__publicField", "debounce", "message", "kind", "rest", "error", "event", "noop", "id", "listener", "result", "requestError", "restProps", "requestHeaders", "name", "protocols", "immediately", "autoReconnect", "on", "eventName", "resolve", "reject", "code", "reason", "args", "uid"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import http from "node:http";
|
|
2
|
-
import
|
|
2
|
+
import { WebSocketServer } from "ws";
|
|
3
3
|
import { InSiteWebSocketServerClient } from "./WebSocketServerClient";
|
|
4
4
|
import type { Options } from "./types";
|
|
5
5
|
type RequestListener<WSSC extends InSiteWebSocketServerClient> = (wscc: WSSC, ...args: any[]) => any | Promise<any>;
|
|
6
|
-
declare
|
|
6
|
+
export declare class InSiteWebSocketServer<WSSC extends InSiteWebSocketServerClient = InSiteWebSocketServerClient> extends WebSocketServer<typeof InSiteWebSocketServerClient> {
|
|
7
|
+
constructor(options: Options<WSSC>, props?: Record<string, unknown>, handleListen?: (() => void));
|
|
7
8
|
on(event: "connection", callback: (this: InSiteWebSocketServer<WSSC>, socket: WSSC, request: http.IncomingMessage) => void): this;
|
|
8
9
|
on(event: "error", callback: (this: InSiteWebSocketServer<WSSC>, error: Error) => void): this;
|
|
9
10
|
on(event: "headers", callback: (this: InSiteWebSocketServer<WSSC>, headers: string[], request: http.IncomingMessage) => void): this;
|
|
@@ -12,9 +13,6 @@ declare abstract class PrepareWebSocketServer<WSSC extends InSiteWebSocketServer
|
|
|
12
13
|
on(event: "client-error", listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, error: Error | undefined) => void): this;
|
|
13
14
|
on(event: `client-${string}`, listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, ...args: any[]) => void): this;
|
|
14
15
|
on(event: string | symbol, listener: (this: InSiteWebSocketServer<WSSC>, ...args: any[]) => void): this;
|
|
15
|
-
}
|
|
16
|
-
export declare class InSiteWebSocketServer<WSSC extends InSiteWebSocketServerClient = InSiteWebSocketServerClient> extends PrepareWebSocketServer<WSSC> {
|
|
17
|
-
constructor(options: Options<WSSC>, props?: Record<string, unknown>, handleListen?: (() => void));
|
|
18
16
|
readonly isWebSocketServer = true;
|
|
19
17
|
readonly isWebSocketServerClient = false;
|
|
20
18
|
readonly isWebSocket = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketServer.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServer.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,
|
|
1
|
+
{"version":3,"file":"WebSocketServer.d.ts","sourceRoot":"","sources":["../../src/server/WebSoc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CAoBnB;IAEF,OAAO,CAAC,gBAAgB;IAyDxB,OAAO,CAAC,mBAAmB;IAsB3B,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,iBAAiB;CAazB"}
|
|
@@ -2,7 +2,7 @@ import { ClientRequest, IncomingMessage } from "node:http";
|
|
|
2
2
|
import { RawData, WebSocket } from "ws";
|
|
3
3
|
import { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from "./symbols";
|
|
4
4
|
import { InSiteWebSocketServer } from "./WebSocketServer";
|
|
5
|
-
declare
|
|
5
|
+
export declare class InSiteWebSocketServerClient<WSSC extends InSiteWebSocketServerClient = any> extends WebSocket {
|
|
6
6
|
on(event: "close", listener: (this: WSSC, code: number, reason: Buffer) => void): this;
|
|
7
7
|
on(event: "error", listener: (this: WSSC, error: Error) => void): this;
|
|
8
8
|
on(event: "upgrade", listener: (this: WSSC, request: IncomingMessage) => void): this;
|
|
@@ -10,9 +10,7 @@ declare abstract class PrepareWebSocket<WSSC extends InSiteWebSocketServerClient
|
|
|
10
10
|
on(event: "open", listener: (this: WSSC) => void): this;
|
|
11
11
|
on(event: "ping" | "pong", listener: (this: WSSC, data: Buffer) => void): this;
|
|
12
12
|
on(event: "unexpected-response", listener: (this: WSSC, request: ClientRequest, response: IncomingMessage) => void): this;
|
|
13
|
-
on(event: string | symbol, listener: (this: WSSC, ...args:
|
|
14
|
-
}
|
|
15
|
-
export declare class InSiteWebSocketServerClient<WSSC extends InSiteWebSocketServerClient = any> extends PrepareWebSocket<WSSC> {
|
|
13
|
+
on(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this;
|
|
16
14
|
get isConnecting(): boolean;
|
|
17
15
|
get isOpen(): boolean;
|
|
18
16
|
get isClosing(): boolean;
|
|
@@ -32,5 +30,4 @@ export declare class InSiteWebSocketServerClient<WSSC extends InSiteWebSocketSer
|
|
|
32
30
|
static makeDefib(this: InSiteWebSocketServerClient<any>): import("@nesvet/n").Debounced<void>;
|
|
33
31
|
static makeHeartbeatInterval(this: InSiteWebSocketServerClient<any>): NodeJS.Timeout;
|
|
34
32
|
}
|
|
35
|
-
export {};
|
|
36
33
|
//# sourceMappingURL=WebSocketServerClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGxC,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"WebSocketServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAGxC,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,qBAAa,2BAA2B,CAAC,IAAI,SAAS,2BAA2B,GAAG,GAAG,CAAE,SAAQ,SAAS;IACzG,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,S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,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAI9B,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IA4B9B,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,2BAA2B,CAAC,GAAG,CAAC;IAIvD,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,2BAA2B,CAAC,GAAG,CAAC;CASnE"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import m from"node:fs";import
|
|
1
|
+
import m from"node:fs";import k from"node:http";import I from"node:https";import{WebSocketServer as q}from"ws";var S={request:"~r-q",response:"~r-s"};var h=Symbol("heartbeatInterval"),l=Symbol("defib"),c=Symbol("pingTs");import{WebSocket as C}from"ws";import{debounce as f,uid as W}from"@nesvet/n";var s=class p extends C{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="";[l]=p.makeDefib.call(this);latency=0;[c];[h]=p.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}sendRequest(...e){let t=W(),n=`message:${S.response}-${t}`;return typeof e.at(-1)=="function"?(this.once(n,e.splice(-1,1)[0]),this.sendMessage(S.request,t,...e),this):new Promise((r,i)=>{this.once(n,(o,a)=>{if(o){let{message:d,...v}=o;i(Object.assign(new Error(d),v))}else r(a)}),this.sendMessage(S.request,t,...e)})}static makeDefib(){return f(()=>this.terminate(),65e3)}static makeHeartbeatInterval(){return setInterval(()=>{this[c]=Date.now(),this.send("")},5e3)}};var b=class extends q{constructor(e,t,n){let{ssl:r,port:i,...o}=e;if(r){if(typeof r.cert=="string"&&!/^-{3,}BEGIN/.test(r.cert))try{r.cert=m.readFileSync(r.cert)}catch{}if(typeof r.key=="string"&&!/^-{3,}BEGIN/.test(r.key))try{r.key=m.readFileSync(r.key)}catch{}}let{server:a=r?I.createServer({...r}):k.createServer()}=o;super({WebSocket:s,...o,server:a}),this.port=typeof i=="string"?Number.parseInt(i):i,t&&(typeof t=="function"?n=t:Object.assign(this,t)),this.on("connection",this.handleConnection),this.on(`client-message:${S.request}`,this.handleRequest),a.listen(this.port,n)}on(e,t){return super.on(e,t)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;port;requestListeners=new Map;addRequestListener(e,t){return this.requestListeners.set(e,t),this}onRequest=this.addRequestListener;removeRequestListener(e){return this.requestListeners.delete(e),this}offRequest=this.removeRequestListener;handleRequest=async(e,t,n,...r)=>{let i=this.requestListeners.get(n),o,a=null;if(i)try{o=await i.call(this,e,...r)}catch(d){if(d instanceof Error){let{message:v,...y}=d;a={message:v,...y}}}else a={message:`Unknown request kind "${n}"`};e.sendMessage(`${S.response}-${t}`,a,o)};handleConnection(e,t){if(!(e instanceof s)){Object.defineProperties(e,{isConnecting:{get:Object.getOwnPropertyDescriptor(s.prototype,"isConnecting").get},isOpen:{get:Object.getOwnPropertyDescriptor(s.prototype,"isOpen").get},isClosing:{get:Object.getOwnPropertyDescriptor(s.prototype,"isClosing").get},isClosed:{get:Object.getOwnPropertyDescriptor(s.prototype,"isClosed").get}});let{terminate:n}=e;Object.assign(e,{isWebSocketServerClient:!0,isWebSocketServer:!1,isWebSocket:!1,[l]:s.makeDefib.call(e),latency:0,[h]:s.makeHeartbeatInterval.call(e),sendMessage:s.prototype.sendMessage,sendRequest:s.prototype.sendRequest,terminate(){try{n.call(e)}catch(r){console.error(r)}}})}Object.assign(e,{wss:this,userAgent:t.headers["user-agent"]??"",remoteAddress:t.headers["x-real-ip"]??t.headers["x-forwarded-for"]??""}),e[l](),e.on("message",n=>this.handleClientMessage(e,n)),e.on("error",n=>this.handleClientError(e,n)),e.on("close",(...n)=>this.handleClientClose(e,...n)),this.emit("client-connect",e,t)}handleClientMessage(e,t){let n=t.toString();if(e[l](),n)try{let[r,...i]=JSON.parse(n);e.emit(`message:${r}`,...i),this.emit("client-message",e,r,...i),this.emit(`client-message:${r}`,e,...i)}catch(r){this.handleClientError(e,r)}else e[c]&&(e.latency=Date.now()-e[c],delete e[c])}handleClientError(e,t){t instanceof Event&&(t=void 0),process.env.NODE_ENV==="development"&&console.error("WebSocketServer Client error",t),this.emit("client-error",e,t)}handleClientClose(e,...t){process.env.NODE_ENV==="development"&&console.info("WebSocketServer Client closed",...t),e[l].clear(),clearInterval(e[h]),this.emit("client-close",e),this.emit("client-closed",e)}};export{b as InSiteWebSocketServer,s as InSiteWebSocketServerClient};
|
|
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/WebSocketServer.ts", "../../src/common.ts", "../../src/server/symbols.ts", "../../src/server/WebSocketServerClient.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from \"node:fs\";\nimport http from \"node:http\";\nimport https from \"node:https\";\nimport type { RawData, WebSocket, WebSocketServer } from \"ws\";\nimport { requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { InSiteWebSocketServerClient } from \"./WebSocketServerClient\";\nimport type { Options } from \"./types\";\n\n\ntype RequestListener<WSSC extends InSiteWebSocketServerClient> = (wscc: WSSC, ...args: any[]) => any | Promise<any>;// eslint-disable-line @typescript-eslint/no-explicit-any\n\ndeclare abstract class PrepareWebSocketServer<WSSC extends InSiteWebSocketServerClient> extends WebSocketServer<typeof InSiteWebSocketServerClient> {\n\ton(event: \"connection\", callback: (this: InSiteWebSocketServer<WSSC>, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: InSiteWebSocketServer<WSSC>, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: InSiteWebSocketServer<WSSC>, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: InSiteWebSocketServer<WSSC>) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, ...args: any[]) => void): this;// eslint-disable-line @typescript-eslint/no-explicit-any\n\t\n\ton(event: string | symbol, listener: (this: InSiteWebSocketServer<WSSC>, ...args: any[]) => void): this;// eslint-disable-line @typescript-eslint/no-explicit-any\n}\n\n\nexport class InSiteWebSocketServer<WSSC extends InSiteWebSocketServerClient = InSiteWebSocketServerClient> extends PrepareWebSocketServer<WSSC> {\n\tconstructor(options: Options<WSSC>, props?: Record<string, unknown>, handleListen?: (() => void)) {\n\t\tconst {\n\t\t\tssl,\n\t\t\tport,\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tif (ssl) {\n\t\t\tif (typeof ssl.cert == \"string\" && !/^-{3,}BEGIN/.test(ssl.cert))\n\t\t\t\ttry {\n\t\t\t\t\tssl.cert = fs.readFileSync(ssl.cert);\n\t\t\t\t} catch {}\n\t\t\tif (typeof ssl.key == \"string\" && !/^-{3,}BEGIN/.test(ssl.key))\n\t\t\t\ttry {\n\t\t\t\t\tssl.key = fs.readFileSync(ssl.key);\n\t\t\t\t} catch {}\n\t\t}\n\t\t\n\t\tconst {\n\t\t\tserver = ssl ? https.createServer({ ...ssl }) : http.createServer()\n\t\t} = wssOptions;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: InSiteWebSocketServerClient<WSSC>,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.port = typeof port == \"string\" ? Number.parseInt(port) : port;\n\t\t\n\t\tif (props)\n\t\t\tif (typeof props == \"function\")\n\t\t\t\thandleListen = props;\n\t\t\telse\n\t\t\t\tObject.assign(this, props);\n\t\t\n\t\tthis.on(\"connection\", this.handleConnection);\n\t\t\n\t\tthis.on(`client-message:${requestHeaders.request}`, this.handleRequest);\n\t\t\n\t\tserver.listen(this.port, handleListen);\n\t\t\n\t}\n\t\n\treadonly isWebSocketServer = true;\n\treadonly isWebSocketServerClient = false;\n\treadonly isWebSocket = false;\n\t\n\treadonly port;\n\t\n\tprivate readonly requestListeners = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis.requestListeners.set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\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\toffRequest = this.removeRequestListener;\n\t\n\tprivate handleRequest = async (wssc: WSSC, id: string, 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.call(this, wssc, ...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\twssc.sendMessage(`${requestHeaders.response}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\tprivate handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\tif (!(wssc instanceof InSiteWebSocketServerClient)) { /* Compatibility with Bun */\n\t\t\tObject.defineProperties(wssc, {\n\t\t\t\tisConnecting: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isConnecting\")!.get\n\t\t\t\t},\n\t\t\t\tisOpen: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isOpen\")!.get\n\t\t\t\t},\n\t\t\t\tisClosing: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isClosing\")!.get\n\t\t\t\t},\n\t\t\t\tisClosed: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isClosed\")!.get\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tconst { terminate } = wssc as WebSocket;\n\t\t\t\n\t\t\tObject.assign(wssc, {\n\t\t\t\tisWebSocketServerClient: true,\n\t\t\t\tisWebSocketServer: false,\n\t\t\t\tisWebSocket: false,\n\t\t\t\t[defibSymbol]: InSiteWebSocketServerClient.makeDefib.call(wssc),\n\t\t\t\tlatency: 0,\n\t\t\t\t[heartbeatIntervalSymbol]: InSiteWebSocketServerClient.makeHeartbeatInterval.call(wssc),\n\t\t\t\tsendMessage: InSiteWebSocketServerClient.prototype.sendMessage,\n\t\t\t\tsendRequest: InSiteWebSocketServerClient.prototype.sendRequest,\n\t\t\t\tterminate() { /* Workaround Bun's WebSocket#terminate bug */\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tterminate.call(wssc);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t});\n\t\t}\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: request.headers[\"x-real-ip\"] ?? request.headers[\"x-forwarded-for\"] ?? \"\"\n\t\t});\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\twssc.on(\"message\", data => this.handleClientMessage(wssc, data));\n\t\twssc.on(\"error\", error => this.handleClientError(wssc, error));\n\t\twssc.on(\"close\", (...args) => this.handleClientClose(wssc, ...args));\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t}\n\t\n\t\n\tprivate handleClientMessage(wssc: WSSC, data: RawData) {\n\t\tconst message = data.toString();\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\ttry {\n\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\n\t\t\t\twssc.emit(`message:${kind}`, ...rest);\n\t\t\t\tthis.emit(\"client-message\", wssc, kind, ...rest);\n\t\t\t\tthis.emit(`client-message:${kind}`, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.handleClientError(wssc, error as Error);\n\t\t\t}\n\t\telse if (wssc[pingTsSymbol]) {\n\t\t\twssc.latency = Date.now() - wssc[pingTsSymbol];\n\t\t\tdelete wssc[pingTsSymbol];\n\t\t}\n\t\t\n\t}\n\t\n\tprivate handleClientError(wssc: WSSC, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.error(\"WebSocketServer Client error\", error);\n\t\t\n\t\tthis.emit(\"client-error\", wssc, error);\n\t\t\n\t}\n\t\n\tprivate handleClientClose(wssc: WSSC, ...args: unknown[]) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.info(\"WebSocketServer Client closed\", ...args);\n\t\t\n\t\twssc[defibSymbol].clear();\n\t\tclearInterval(wssc[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.emit(\"client-close\", wssc);\n\t\tthis.emit(\"client-closed\", wssc);\n\t\t\n\t}\n\t\n}\n", "export const heartbeatInterval = 5_000;\nexport const heartbeatGap = 60_000;\n\nexport const requestHeaders = {\n\trequest: \"~r-q\",\n\tresponse: \"~r-s\"\n};\n", "export const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const pingTsSymbol = Symbol(\"pingTs\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { debounce, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { InSiteWebSocketServer } from \"./WebSocketServer\";\n\n\ndeclare abstract class PrepareWebSocket<WSSC extends InSiteWebSocketServerClient = InSiteWebSocketServerClient> extends WebSocket {\n\ton(event: \"close\", listener: (this: WSSC, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: WSSC, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: WSSC, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: WSSC, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: WSSC) => void): this;\n\ton(event: \"ping\" | \"pong\", listener: (this: WSSC, data: Buffer) => void): this;\n\ton(\n\t\tevent: \"unexpected-response\",\n\t\tlistener: (this: WSSC, request: ClientRequest, response: IncomingMessage) => void,\n\t): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: unknown[]) => void): this;\n}\n\n\nexport class InSiteWebSocketServerClient<WSSC extends InSiteWebSocketServerClient = any> extends PrepareWebSocket<WSSC> {// eslint-disable-line @typescript-eslint/no-explicit-any\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!: InSiteWebSocketServer<WSSC>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[defibSymbol] = InSiteWebSocketServerClient.makeDefib.call(this);\n\t\n\tlatency = 0;\n\t\n\t[pingTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = InSiteWebSocketServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = uid();\n\t\tconst eventName = `message:${requestHeaders.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\tthis.sendMessage(requestHeaders.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));\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\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeDefib(this: InSiteWebSocketServerClient<any>) { // eslint-disable-line @typescript-eslint/no-explicit-any\n\t\treturn debounce(() => this.terminate(), heartbeatInterval + heartbeatGap);\n\t}\n\t\n\tstatic makeHeartbeatInterval(this: InSiteWebSocketServerClient<any>) { // eslint-disable-line @typescript-eslint/no-explicit-any\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[pingTsSymbol] = Date.now();\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, heartbeatInterval);\n\t}\n\t\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAOA,MAAQ,UACf,OAAOC,MAAU,YACjB,OAAOC,MAAW,
|
|
6
|
-
"names": ["fs", "http", "https", "requestHeaders", "heartbeatIntervalSymbol", "defibSymbol", "pingTsSymbol", "debounce", "uid", "InSiteWebSocketServerClient", "_InSiteWebSocketServerClient", "defibSymbol", "pingTsSymbol", "heartbeatIntervalSymbol", "args", "id", "uid", "eventName", "requestHeaders", "resolve", "reject", "error", "result", "message", "restProps", "debounce", "InSiteWebSocketServer", "options", "props", "handleListen", "ssl", "port", "wssOptions", "fs", "server", "https", "http", "InSiteWebSocketServerClient", "requestHeaders", "
|
|
4
|
+
"sourcesContent": ["import fs from \"node:fs\";\nimport http from \"node:http\";\nimport https from \"node:https\";\nimport { type RawData, type WebSocket, WebSocketServer } from \"ws\";\nimport { requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { InSiteWebSocketServerClient } from \"./WebSocketServerClient\";\nimport type { Options } from \"./types\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\ntype RequestListener<WSSC extends InSiteWebSocketServerClient> = (wscc: WSSC, ...args: any[]) => any | Promise<any>;\n\n\nexport class InSiteWebSocketServer<WSSC extends InSiteWebSocketServerClient = InSiteWebSocketServerClient> extends WebSocketServer<typeof InSiteWebSocketServerClient> {\n\tconstructor(options: Options<WSSC>, props?: Record<string, unknown>, handleListen?: (() => void)) {\n\t\tconst {\n\t\t\tssl,\n\t\t\tport,\n\t\t\t...wssOptions\n\t\t} = options;\n\t\t\n\t\tif (ssl) {\n\t\t\tif (typeof ssl.cert == \"string\" && !/^-{3,}BEGIN/.test(ssl.cert))\n\t\t\t\ttry {\n\t\t\t\t\tssl.cert = fs.readFileSync(ssl.cert);\n\t\t\t\t} catch {}\n\t\t\tif (typeof ssl.key == \"string\" && !/^-{3,}BEGIN/.test(ssl.key))\n\t\t\t\ttry {\n\t\t\t\t\tssl.key = fs.readFileSync(ssl.key);\n\t\t\t\t} catch {}\n\t\t}\n\t\t\n\t\tconst {\n\t\t\tserver = ssl ? https.createServer({ ...ssl }) : http.createServer()\n\t\t} = wssOptions;\n\t\t\n\t\tsuper({\n\t\t\tWebSocket: InSiteWebSocketServerClient<WSSC>,\n\t\t\t...wssOptions,\n\t\t\tserver\n\t\t});\n\t\t\n\t\tthis.port = typeof port == \"string\" ? Number.parseInt(port) : port;\n\t\t\n\t\tif (props)\n\t\t\tif (typeof props == \"function\")\n\t\t\t\thandleListen = props;\n\t\t\telse\n\t\t\t\tObject.assign(this, props);\n\t\t\n\t\tthis.on(\"connection\", this.handleConnection);\n\t\t\n\t\tthis.on(`client-message:${requestHeaders.request}`, this.handleRequest);\n\t\t\n\t\tserver.listen(this.port, handleListen);\n\t\t\n\t}\n\t\n\ton(event: \"connection\", callback: (this: InSiteWebSocketServer<WSSC>, socket: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"error\", callback: (this: InSiteWebSocketServer<WSSC>, error: Error) => void): this;\n\ton(event: \"headers\", callback: (this: InSiteWebSocketServer<WSSC>, headers: string[], request: http.IncomingMessage) => void): this;\n\ton(event: \"close\" | \"listening\", callback: (this: InSiteWebSocketServer<WSSC>) => void): this;\n\t\n\ton(event: \"client-connect\", listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, request: http.IncomingMessage) => void): this;\n\ton(event: \"client-error\", listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, error: Error | undefined) => void): this;\n\ton(event: `client-${string}`, listener: (this: InSiteWebSocketServer<WSSC>, wscc: WSSC, ...args: any[]) => void): this;\n\t\n\ton(event: string | symbol, listener: (this: InSiteWebSocketServer<WSSC>, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: InSiteWebSocketServer<WSSC>, ...args: any[]) => void): this {\n\t\treturn super.on(event, listener as unknown 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\treadonly port;\n\t\n\tprivate readonly requestListeners = new Map<string, RequestListener<WSSC>>();\n\t\n\taddRequestListener(kind: string, listener: RequestListener<WSSC>) {\n\t\tthis.requestListeners.set(kind, listener);\n\t\t\n\t\treturn this;\n\t}\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\toffRequest = this.removeRequestListener;\n\t\n\tprivate handleRequest = async (wssc: WSSC, id: string, 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.call(this, wssc, ...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\twssc.sendMessage(`${requestHeaders.response}-${id}`, requestError, result);\n\t\t\n\t};\n\t\n\tprivate handleConnection(wssc: WSSC, request: http.IncomingMessage) {\n\t\tif (!(wssc instanceof InSiteWebSocketServerClient)) { /* Compatibility with Bun */\n\t\t\tObject.defineProperties(wssc, {\n\t\t\t\tisConnecting: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isConnecting\")!.get\n\t\t\t\t},\n\t\t\t\tisOpen: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isOpen\")!.get\n\t\t\t\t},\n\t\t\t\tisClosing: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isClosing\")!.get\n\t\t\t\t},\n\t\t\t\tisClosed: {\n\t\t\t\t\tget: Object.getOwnPropertyDescriptor(InSiteWebSocketServerClient.prototype, \"isClosed\")!.get\n\t\t\t\t}\n\t\t\t});\n\t\t\t\n\t\t\tconst { terminate } = wssc as WebSocket;\n\t\t\t\n\t\t\tObject.assign(wssc, {\n\t\t\t\tisWebSocketServerClient: true,\n\t\t\t\tisWebSocketServer: false,\n\t\t\t\tisWebSocket: false,\n\t\t\t\t[defibSymbol]: InSiteWebSocketServerClient.makeDefib.call(wssc),\n\t\t\t\tlatency: 0,\n\t\t\t\t[heartbeatIntervalSymbol]: InSiteWebSocketServerClient.makeHeartbeatInterval.call(wssc),\n\t\t\t\tsendMessage: InSiteWebSocketServerClient.prototype.sendMessage,\n\t\t\t\tsendRequest: InSiteWebSocketServerClient.prototype.sendRequest,\n\t\t\t\tterminate() { /* Workaround Bun's WebSocket#terminate bug */\n\t\t\t\t\t\n\t\t\t\t\ttry {\n\t\t\t\t\t\tterminate.call(wssc);\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\tconsole.error(error);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t}\n\t\t\t});\n\t\t}\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: request.headers[\"x-real-ip\"] ?? request.headers[\"x-forwarded-for\"] ?? \"\"\n\t\t});\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\twssc.on(\"message\", data => this.handleClientMessage(wssc, data));\n\t\twssc.on(\"error\", error => this.handleClientError(wssc, error));\n\t\twssc.on(\"close\", (...args) => this.handleClientClose(wssc, ...args));\n\t\t\n\t\tthis.emit(\"client-connect\", wssc, request);\n\t\t\n\t}\n\t\n\t\n\tprivate handleClientMessage(wssc: WSSC, data: RawData) {\n\t\tconst message = data.toString();\n\t\t\n\t\twssc[defibSymbol]();\n\t\t\n\t\tif (message)\n\t\t\ttry {\n\t\t\t\tconst [ kind, ...rest ] = JSON.parse(message);\n\t\t\t\t\n\t\t\t\twssc.emit(`message:${kind}`, ...rest);\n\t\t\t\tthis.emit(\"client-message\", wssc, kind, ...rest);\n\t\t\t\tthis.emit(`client-message:${kind}`, wssc, ...rest);\n\t\t\t} catch (error) {\n\t\t\t\tthis.handleClientError(wssc, error as Error);\n\t\t\t}\n\t\telse if (wssc[pingTsSymbol]) {\n\t\t\twssc.latency = Date.now() - wssc[pingTsSymbol];\n\t\t\tdelete wssc[pingTsSymbol];\n\t\t}\n\t\t\n\t}\n\t\n\tprivate handleClientError(wssc: WSSC, error: Error | Event | undefined) {\n\t\tif (error instanceof Event)\n\t\t\terror = undefined;\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.error(\"WebSocketServer Client error\", error);\n\t\t\n\t\tthis.emit(\"client-error\", wssc, error);\n\t\t\n\t}\n\t\n\tprivate handleClientClose(wssc: WSSC, ...args: unknown[]) {\n\t\t\n\t\tif (process.env.NODE_ENV === \"development\")\n\t\t\tconsole.info(\"WebSocketServer Client closed\", ...args);\n\t\t\n\t\twssc[defibSymbol].clear();\n\t\tclearInterval(wssc[heartbeatIntervalSymbol]);\n\t\t\n\t\tthis.emit(\"client-close\", wssc);\n\t\tthis.emit(\"client-closed\", wssc);\n\t\t\n\t}\n\t\n}\n", "export const heartbeatInterval = 5_000;\nexport const heartbeatGap = 60_000;\n\nexport const requestHeaders = {\n\trequest: \"~r-q\",\n\tresponse: \"~r-s\"\n};\n", "export const heartbeatIntervalSymbol = Symbol(\"heartbeatInterval\");\nexport const defibSymbol = Symbol(\"defib\");\nexport const pingTsSymbol = Symbol(\"pingTs\");\n", "import { ClientRequest, IncomingMessage } from \"node:http\";\nimport { RawData, WebSocket } from \"ws\";\nimport { debounce, uid } from \"@nesvet/n\";\nimport { heartbeatGap, heartbeatInterval, requestHeaders } from \"../common\";\nimport { defibSymbol, heartbeatIntervalSymbol, pingTsSymbol } from \"./symbols\";\nimport { InSiteWebSocketServer } from \"./WebSocketServer\";\n\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n\nexport class InSiteWebSocketServerClient<WSSC extends InSiteWebSocketServerClient = any> extends WebSocket {\n\ton(event: \"close\", listener: (this: WSSC, code: number, reason: Buffer) => void): this;\n\ton(event: \"error\", listener: (this: WSSC, error: Error) => void): this;\n\ton(event: \"upgrade\", listener: (this: WSSC, request: IncomingMessage) => void): this;\n\ton(event: \"message\", listener: (this: WSSC, data: RawData, isBinary: boolean) => void): this;\n\ton(event: \"open\", listener: (this: WSSC) => void): this;\n\ton(event: \"ping\" | \"pong\", listener: (this: WSSC, data: Buffer) => void): this;\n\ton(event: \"unexpected-response\", listener: (this: WSSC, request: ClientRequest, response: IncomingMessage) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...args: any[]) => void): this;\n\ton(event: string | symbol, listener: (this: WSSC, ...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!: InSiteWebSocketServer<WSSC>;\n\t\n\tuserAgent = \"\";\n\t\n\tremoteAddress = \"\";\n\t\n\t[defibSymbol] = InSiteWebSocketServerClient.makeDefib.call(this);\n\t\n\tlatency = 0;\n\t\n\t[pingTsSymbol]?: number;\n\t\n\t[heartbeatIntervalSymbol] = InSiteWebSocketServerClient.makeHeartbeatInterval.call(this);\n\t\n\tsendMessage(...args: unknown[]) {\n\t\treturn this.send(JSON.stringify(args));\n\t}\n\t\n\tsendRequest(...args: unknown[]) {\n\t\t\n\t\tconst id = uid();\n\t\tconst eventName = `message:${requestHeaders.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\tthis.sendMessage(requestHeaders.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));\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\tthis.sendMessage(requestHeaders.request, id, ...args);\n\t\t\t\n\t\t});\n\t}\n\t\n\t\n\tstatic makeDefib(this: InSiteWebSocketServerClient<any>) {\n\t\treturn debounce(() => this.terminate(), heartbeatInterval + heartbeatGap);\n\t}\n\t\n\tstatic makeHeartbeatInterval(this: InSiteWebSocketServerClient<any>) {\n\t\treturn setInterval(() => {\n\t\t\t\n\t\t\tthis[pingTsSymbol] = Date.now();\n\t\t\tthis.send(\"\");\n\t\t\t\n\t\t}, heartbeatInterval);\n\t}\n\t\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAOA,MAAQ,UACf,OAAOC,MAAU,YACjB,OAAOC,MAAW,aAClB,OAAuC,mBAAAC,MAAuB,KCAvD,IAAMC,EAAiB,CAC7B,QAAS,OACT,SAAU,MACX,ECNO,IAAMC,EAA0B,OAAO,mBAAmB,EACpDC,EAAc,OAAO,OAAO,EAC5BC,EAAe,OAAO,QAAQ,ECD3C,OAAkB,aAAAC,MAAiB,KACnC,OAAS,YAAAC,EAAU,OAAAC,MAAW,YASvB,IAAMC,EAAN,MAAMC,UAAoFC,CAAU,CAS1G,GAAGC,EAAwBC,EAAsD,CAChF,OAAO,MAAM,GAAGD,EAAOC,CAAqD,CAC7E,CAEA,IAAI,cAAe,CAClB,OAAO,KAAK,aAAe,KAAK,UACjC,CAEA,IAAI,QAAS,CACZ,OAAO,KAAK,aAAe,KAAK,IACjC,CAEA,IAAI,WAAY,CACf,OAAO,KAAK,aAAe,KAAK,OACjC,CAEA,IAAI,UAAW,CACd,OAAO,KAAK,aAAe,KAAK,MACjC,CAES,wBAA0B,GAC1B,kBAAoB,GACpB,YAAc,GAEvB,IAEA,UAAY,GAEZ,cAAgB,GAEh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WebSocketServer", "requestHeaders", "heartbeatIntervalSymbol", "defibSymbol", "pingTsSymbol", "WebSocket", "debounce", "uid", "InSiteWebSocketServerClient", "_InSiteWebSocketServerClient", "WebSocket", "event", "listener", "defibSymbol", "pingTsSymbol", "heartbeatIntervalSymbol", "args", "id", "uid", "eventName", "requestHeaders", "resolve", "reject", "error", "result", "message", "restProps", "debounce", "InSiteWebSocketServer", "WebSocketServer", "options", "props", "handleListen", "ssl", "port", "wssOptions", "fs", "server", "https", "http", "InSiteWebSocketServerClient", "requestHeaders", "event", "listener", "kind", "wssc", "id", "rest", "result", "requestError", "error", "message", "restProps", "request", "terminate", "defibSymbol", "heartbeatIntervalSymbol", "data", "args", "pingTsSymbol"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-ws",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "inSite WebSockets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./server": "./dist/server/index.js",
|
|
8
8
|
"./client": "./dist/client/index.js"
|
|
9
9
|
},
|
|
10
|
-
"packageManager": "bun@1.1.
|
|
10
|
+
"packageManager": "bun@1.1.25",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
13
|
"build": "bun .conveyer.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"ws": "^8.18.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@nesvet/conveyer": "^2.2.
|
|
33
|
+
"@nesvet/conveyer": "^2.2.4",
|
|
34
34
|
"@nesvet/eslint-config": "^2.0.24",
|
|
35
|
-
"@types/node": "^22.
|
|
35
|
+
"@types/node": "^22.5.0",
|
|
36
36
|
"@types/ws": "^8.5.12",
|
|
37
37
|
"typescript": "^5.5.4"
|
|
38
38
|
}
|
package/bun.lockb
DELETED
|
Binary file
|
package/dist/client/types.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/client/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC,CAAC;CAClD,CAAC"}
|