insite-ws 2.0.7 → 2.0.9
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/bun.lockb +0 -0
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +3 -3
- package/dist/server/WebSocketServer.d.ts +0 -1
- package/dist/server/WebSocketServer.d.ts.map +1 -1
- package/dist/server/WebSocketServerClient.d.ts +0 -1
- package/dist/server/WebSocketServerClient.d.ts.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/types.d.ts +0 -2
- package/dist/server/types.d.ts.map +1 -1
- package/package.json +4 -3
package/bun.lockb
CHANGED
|
Binary file
|
package/dist/client/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var P=Object.defineProperty;var W=n=>{throw TypeError(n)};var T=(n,i,e)=>i in n?P(n,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[i]=e;var r=(n,i,e)=>T(n,typeof i!="symbol"?i+"":i,e),$=(n,i,e)=>i.has(n)||W("Cannot "+e);var s=(n,i,e)=>($(n,i,"read from private field"),e?e.call(n):i.get(n)),c=(n,i,e)=>i.has(n)?W("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,e),l=(n,i,e,t)=>($(n,i,"write to private field"),t?t.call(n,e):i.set(n,e),e);import I from"eventemitter3";import{debounce as V,noop as C,uid as _}from"@nesvet/n";var
|
|
1
|
+
var P=Object.defineProperty;var W=n=>{throw TypeError(n)};var T=(n,i,e)=>i in n?P(n,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[i]=e;var r=(n,i,e)=>T(n,typeof i!="symbol"?i+"":i,e),$=(n,i,e)=>i.has(n)||W("Cannot "+e);var s=(n,i,e)=>($(n,i,"read from private field"),e?e.call(n):i.get(n)),c=(n,i,e)=>i.has(n)?W("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(n):i.set(n,e),l=(n,i,e,t)=>($(n,i,"write to private field"),t?t.call(n,e):i.set(n,e),e);import I from"eventemitter3";import{debounce as V,noop as C,uid as _}from"@nesvet/n";var k={request:"~r-q",response:"~r-s"};var B=2e3,j=0,M=new WeakMap,m,p,u,E,q,v,w,y,b,O,g,R,N=class N extends I{constructor(e,t={}){super();r(this,"isWebSocket",!0);r(this,"isWebSocketServer",!1);r(this,"isWebSocketServerClient",!1);r(this,"url");r(this,"name");r(this,"protocols");r(this,"autoReconnect");r(this,"webSocket",null);c(this,m,V(N.defib,65e3));c(this,p);c(this,u);c(this,E,()=>{s(this,p).call(this),l(this,p,void 0),l(this,u,void 0),this.emit("open"),s(this,m).call(this)});c(this,q,({data:e})=>{if(s(this,m).call(this),e)try{let[t,...o]=JSON.parse(e);this.emit("message",t,...o),this.emit(`message:${t}`,...o)}catch(t){s(this,v).call(this,t)}else this.webSocket.send("")});c(this,v,e=>{e instanceof Event&&(e=void 0),s(this,u)&&(s(this,u).call(this,e),l(this,p,void 0),l(this,u,void 0)),this.emit("error",e)});c(this,w);c(this,y,e=>{process.env.NODE_ENV==="development"&&console.info(`WebSocket ${this.name} is closed with code ${e.code} and reason "${e.reason}"`),s(this,m).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`),l(this,w,setTimeout(()=>this.open().catch(C),B)))});r(this,"connect",this.open);r(this,"disconnect",this.close);c(this,b,[]);c(this,O,()=>{for(let e of s(this,b))this.webSocket.send(e);s(this,b).length=0});c(this,g,new Map);r(this,"onRequest",this.addRequestListener);r(this,"offRequest",this.removeRequestListener);c(this,R,async(e,t,...o)=>{let f=s(this,g).get(t),S,a=null;if(f)try{S=await f.apply(this,o)}catch(h){if(h instanceof Error){let{message:d,...L}=h;a={message:d,...L}}}else a={message:`Unknown request kind "${t}"`};this.sendMessage(`${k.response}-${e}`,a,S)});this.url=e;let{name:o=(j++).toString(),protocols:f,immediately:S=!0,autoReconnect:a=!0,on:h}=t;if(this.name=o,this.protocols=f,this.autoReconnect=!!a,this.on(`message:${k.request}`,s(this,R)),h)for(let d in h)h[d]&&this.on(d,h[d]);this.url&&S&&this.open().catch(C)}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(s(this,w)),await this.close(4e3,"reopen"),e.url&&(this.url=e.url),e.protocols&&(this.protocols=e.protocols),this.webSocket&&M.get(this.webSocket)!==this.url&&this.emit("server-change"),new Promise((t,o)=>{l(this,p,t),l(this,u,o),this.webSocket=new WebSocket(this.url,this.protocols),this.webSocket.addEventListener("open",s(this,E)),this.webSocket.addEventListener("message",s(this,q)),this.webSocket.addEventListener("error",s(this,v)),this.webSocket.addEventListener("close",s(this,y)),this.send=this.webSocket.send.bind(this.webSocket),M.set(this.webSocket,this.url),this.emit("connecting")})}close(e=3500,t="manual"){return clearTimeout(s(this,w)),new Promise(o=>{this.isConnecting||this.isOpen?(this.webSocket.addEventListener("close",o),this.webSocket.close(e,t)):o(null)})}sendMessage(...e){let t=JSON.stringify(e);this.isOpen?this.webSocket.send(t):(s(this,b).length||this.once("open",s(this,O)),s(this,b).push(t))}sendRequest(...e){let t=_(),o=`message:${k.response}-${t}`;return typeof e.at(-1)=="function"?(this.once(o,e.splice(-1,1)[0]),this.sendMessage(k.request,t,...e),this):new Promise((f,S)=>{this.once(o,(a,h)=>{if(a){let{message:d,...L}=a;S(Object.assign(new Error(d),L))}else f(h)}),this.sendMessage(k.request,t,...e)})}addRequestListener(e,t){return s(this,g).set(e,t),this}removeRequestListener(e){return s(this,g).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())}};m=new WeakMap,p=new WeakMap,u=new WeakMap,E=new WeakMap,q=new WeakMap,v=new WeakMap,w=new WeakMap,y=new WeakMap,b=new WeakMap,O=new WeakMap,g=new WeakMap,R=new WeakMap;var x=N;export{x 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 {\n\theartbeatGap,\n\theartbeatInterval,\n\trequestHeaders,\n\ttype RequestListener\n} from \"../common\";\nimport { Options } from \"./types\";\n\n\nconst reconnectTimeout = 2000;\n\nlet i = 0;\n\nconst
|
|
5
|
-
"mappings": "2eAAA,OAAOA,MAAkB,gBACzB,OAAS,YAAAC,EAAU,QAAAC,EAAM,OAAAC,MAAW,YCE7B,IAAMC,EAAiB,CAC7B,QAAS,OACT,SAAU,MACX,EDKA,IAAMC,EAAmB,IAErBC,EAAI,EAEFC,
|
|
6
|
-
"names": ["EventEmitter", "debounce", "noop", "uid", "requestHeaders", "reconnectTimeout", "i", "
|
|
4
|
+
"sourcesContent": ["import EventEmitter from \"eventemitter3\";\nimport { debounce, noop, uid } from \"@nesvet/n\";\nimport {\n\theartbeatGap,\n\theartbeatInterval,\n\trequestHeaders,\n\ttype RequestListener\n} from \"../common\";\nimport { Options } from \"./types\";\n\n\nconst reconnectTimeout = 2000;\n\nlet i = 0;\n\nconst webSocketUrlMap = new WeakMap<WebSocket, string>();\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\tname;\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\t#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\t#openResolve?: (value?: unknown) => void;\n\t#openReject?: (reason?: unknown) => void;\n\t\n\t#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\t#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\t#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\t#reconnectTimeout?: number;\n\t\n\t#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\t#queue: 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\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\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\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\t#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\nexport type RequestListener = (...args: any[]) => any | Promise<any>;// eslint-disable-line @typescript-eslint/no-explicit-any\n"],
|
|
5
|
+
"mappings": "2eAAA,OAAOA,MAAkB,gBACzB,OAAS,YAAAC,EAAU,QAAAC,EAAM,OAAAC,MAAW,YCE7B,IAAMC,EAAiB,CAC7B,QAAS,OACT,SAAU,MACX,EDKA,IAAMC,EAAmB,IAErBC,EAAI,EAEFC,EAAkB,IAAI,QAf5BC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAAAC,EAkBaC,EAAN,MAAMA,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,aAEAA,EAAA,kBAEAA,EAAA,sBAIAA,EAAA,iBAA8B,MAE9BC,EAAA,KAAAjB,EAASkB,EAASN,EAAgB,MAAO,IAAgC,GAkBzEK,EAAA,KAAAhB,GACAgB,EAAA,KAAAf,GAEAe,EAAA,KAAAd,EAAuB,IAAM,CAE5BgB,EAAA,KAAKlB,GAAL,WACAmB,EAAA,KAAKnB,EAAe,QACpBmB,EAAA,KAAKlB,EAAc,QAEnB,KAAK,KAAK,MAAM,EAEhBiB,EAAA,KAAKnB,GAAL,UAED,GAEAiB,EAAA,KAAAb,EAA0B,CAAC,CAAE,KAAMiB,CAAQ,IAAoB,CAI9D,GAFAF,EAAA,KAAKnB,GAAL,WAEIqB,EACH,GAAI,CACH,GAAM,CAAEC,EAAM,GAAGC,CAAK,EAAI,KAAK,MAAMF,CAAO,EAE5C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ocketUrlMap", "_defib", "_openResolve", "_openReject", "_handleWebSocketOpen", "_handleWebSocketMessage", "_handleWebSocketError", "_reconnectTimeout", "_handleWebSocketClose", "_queue", "_releaseQueue", "_requestListeners", "_handleRequest", "_InSiteWebSocket", "EventEmitter", "url", "options", "__publicField", "__privateAdd", "debounce", "__privateGet", "__privateSet", "message", "kind", "rest", "error", "event", "noop", "id", "listener", "result", "requestError", "restProps", "requestHeaders", "name", "protocols", "immediately", "autoReconnect", "on", "eventName", "resolve", "reject", "code", "reason", "args", "uid", "InSiteWebSocket"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketServer.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebSocketServer.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,SAAS,EAAE,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAsB,OAAO,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAGtE,qBAAa,qBAAsB,SAAQ,eAAe,CAAC,OAAO,2BAA2B,CAAC;;gBACjF,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC;IA4B1F,QAAQ,CAAC,iBAAiB,QAAQ;IAClC,QAAQ,CAAC,uBAAuB,SAAS;IACzC,QAAQ,CAAC,WAAW,SAAS;IAI7B,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe;IAM1D,SAAS,SANgB,MAAM,YAAY,eAAe,UAMtB;IAEpC,qBAAqB,CAAC,IAAI,EAAE,MAAM;IAMlC,UAAU,SANkB,MAAM,UAMM;IAyBxC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,qBAAqB,EAAE,IAAI,EAAE,2BAA2B,GAAG,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,eAAe;IAyDjI,MAAM,CAAC,mBAAmB,CAAC,IAAI,EAAE,2BAA2B,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO;IAsBrF,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,2BAA2B,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,GAAG,SAAS;IAW5F,MAAM,CAAC,iBAAiB,CAAC,IAAI,EAAE,2BAA2B,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE;CAa9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServerClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebSocketServerClient.d.ts","sourceRoot":"","sources":["../../src/server/WebSocketServerClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAG/B,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,qBAAa,2BAA4B,SAAQ,SAAS;IAEzD,IAAI,YAAY,YAEf;IAED,IAAI,MAAM,YAET;IAED,IAAI,SAAS,YAEZ;IAED,IAAI,QAAQ,YAEX;IAED,QAAQ,CAAC,uBAAuB,QAAQ;IACxC,QAAQ,CAAC,iBAAiB,SAAS;IACnC,QAAQ,CAAC,WAAW,SAAS;IAE7B,GAAG,EAAG,qBAAqB,CAAC;IAE5B,SAAS,SAAM;IAEf,aAAa,SAAM;IAEnB,CAAC,WAAW,CAAC,sCAAoD;IAEjE,OAAO,SAAK;IAEZ,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;IAExB,CAAC,uBAAuB,CAAC,iBAAgE;IAEzF,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IAI9B,WAAW,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE;IA4B9B,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,2BAA2B;IAIlD,MAAM,CAAC,qBAAqB,CAAC,IAAI,EAAE,2BAA2B;CAS9D"}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import k from"node:http";import W from"node:https";import{WebSocketServer as
|
|
1
|
+
import k from"node:http";import W from"node:https";import{WebSocketServer as O}from"ws";var l={request:"~r-q",response:"~r-s"};var p=Symbol("heartbeatInterval"),c=Symbol("defib"),S=Symbol("pingTs");import{WebSocket as y}from"ws";import{debounce as v,uid as C}from"@nesvet/n";var r=class i extends y{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="";[c]=i.makeDefib.call(this);latency=0;[S];[p]=i.makeHeartbeatInterval.call(this);sendMessage(...e){return this.send(JSON.stringify(e))}sendRequest(...e){let t=C(),s=`message:${l.response}-${t}`;return typeof e.at(-1)=="function"?(this.once(s,e.splice(-1,1)[0]),this.sendMessage(l.request,t,...e),this):new Promise((n,h)=>{this.once(s,(o,a)=>{if(o){let{message:m,...b}=o;h(Object.assign(new Error(m),b))}else n(a)}),this.sendMessage(l.request,t,...e)})}static makeDefib(){return v(()=>this.terminate(),65e3)}static makeHeartbeatInterval(){return setInterval(()=>{this[S]=Date.now(),this.send("")},5e3)}};var g=class i extends O{constructor(e,t,s){let{ssl:n,port:h,server:o=n?W.createServer({...n}):k.createServer(),...a}=e;super({...a,WebSocket:r,server:o}),t&&(typeof t=="function"?s=t:Object.assign(this,t)),this.on("connection",i.handleConnection),this.on(`client-message:${l.request}`,this.#t),o.listen(h,s)}isWebSocketServer=!0;isWebSocketServerClient=!1;isWebSocket=!1;#e=new Map;addRequestListener(e,t){return this.#e.set(e,t),this}onRequest=this.addRequestListener;removeRequestListener(e){return this.#e.delete(e),this}offRequest=this.removeRequestListener;#t=async(e,t,s,...n)=>{let h=this.#e.get(s),o,a=null;if(h)try{o=await h.call(this,e,...n)}catch(m){if(m instanceof Error){let{message:b,...f}=m;a={message:b,...f}}}else a={message:`Unknown request kind "${s}"`};e.sendMessage(`${l.response}-${t}`,a,o)};static handleConnection(e,t){if(!(e instanceof r)){Object.defineProperties(e,{isConnecting:{get:Object.getOwnPropertyDescriptor(r.prototype,"isConnecting").get},isOpen:{get:Object.getOwnPropertyDescriptor(r.prototype,"isOpen").get},isClosing:{get:Object.getOwnPropertyDescriptor(r.prototype,"isClosing").get},isClosed:{get:Object.getOwnPropertyDescriptor(r.prototype,"isClosed").get}});let{terminate:s}=e;Object.assign(e,{isWebSocketServerClient:!0,isWebSocketServer:!1,isWebSocket:!1,[c]:r.makeDefib.call(e),latency:0,[p]:r.makeHeartbeatInterval.call(e),sendMessage:r.prototype.sendMessage,sendRequest:r.prototype.sendRequest,terminate(){try{s.call(e)}catch(n){console.error(n)}}})}Object.assign(e,{wss:this,userAgent:t.headers["user-agent"]??"",remoteAddress:t.headers["x-real-ip"]??t.headers["x-forwarded-for"]??""}),e[c](),e.on("message",i.handleClientMessage),e.on("error",i.handleClientError),e.on("close",i.handleClientClose),this.emit("client-connect",e,t)}static handleClientMessage(e){let t=e.toString();if(this[c](),t)try{let[s,...n]=JSON.parse(t);this.emit(`message:${s}`,...n),this.wss.emit("client-message",this,s,...n),this.wss.emit(`client-message:${s}`,this,...n)}catch(s){i.handleClientError.call(this,s)}else this[S]&&(this.latency=Date.now()-this[S],delete this[S])}static handleClientError(e){e instanceof Event&&(e=void 0),process.env.NODE_ENV==="development"&&console.error("WebSocketServer Client error",e),this.wss.emit("client-error",this,e)}static handleClientClose(...e){process.env.NODE_ENV==="development"&&console.info("WebSocketServer Client closed",...e),this[c].clear(),clearInterval(this[p]),this.wss.emit("client-close",this),this.wss.emit("client-closed",this)}};export{g as InSiteWebSocketServer,r as InSiteWebSocketServerClient};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/server/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,SAAS,MAAM,IAAI,CAAC;AAG3B,MAAM,MAAM,OAAO,GAAG;IACrB,GAAG,CAAC,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACZ,CAAC;IACF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;CACpC,GAAG,SAAS,CAAC,aAAa,CAAC;AAE5B,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "insite-ws",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.9",
|
|
4
4
|
"description": "inSite WebSockets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "Eugene Nesvetaev <dev@nesvet.dev> (https://nesvet.dev/)",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@nesvet/n": "^1.0
|
|
28
|
+
"@nesvet/n": "^1.1.0",
|
|
29
29
|
"eventemitter3": "^5.0.1",
|
|
30
30
|
"ws": "^8.18.0"
|
|
31
31
|
},
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@nesvet/conveyer": "^2.2.1",
|
|
34
34
|
"@nesvet/eslint-config": "^2.0.24",
|
|
35
35
|
"@types/node": "^20.14.13",
|
|
36
|
-
"@types/ws": "^8.5.
|
|
36
|
+
"@types/ws": "^8.5.12",
|
|
37
|
+
"typescript": "^5.5.4"
|
|
37
38
|
}
|
|
38
39
|
}
|