@lowerdeck/websocket-client 1.0.3 → 1.0.4

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/package.json CHANGED
@@ -1,9 +1,15 @@
1
1
  {
2
2
  "name": "@lowerdeck/websocket-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
+ "files": [
8
+ "src/**",
9
+ "dist/**",
10
+ "README.md",
11
+ "package.json"
12
+ ],
7
13
  "author": "Tobias Herber",
8
14
  "license": "Apache 2",
9
15
  "type": "module",
@@ -21,14 +27,14 @@
21
27
  "scripts": {
22
28
  "test": "vitest run --passWithNoTests",
23
29
  "lint": "prettier src/**/*.ts --check",
24
- "build": "microbundle"
30
+ "build": "rm -rf ./dist && microbundle"
25
31
  },
26
32
  "dependencies": {
27
- "@lowerdeck/emitter": "^1.0.3"
33
+ "@lowerdeck/emitter": "^1.0.4"
28
34
  },
29
35
  "devDependencies": {
30
36
  "microbundle": "^0.15.1",
31
- "@lowerdeck/tsconfig": "^1.0.0",
37
+ "@lowerdeck/tsconfig": "^1.0.1",
32
38
  "typescript": "^5.8.3",
33
39
  "vitest": "^3.1.2"
34
40
  }
@@ -1,12 +0,0 @@
1
-
2
- $ microbundle
3
- No name was provided for external module '@lowerdeck/emitter' in output.globals – guessing 'emitter'
4
- Build "@lowerdeck/websocket-client" to dist:
5
- 840 B: index.cjs.gz
6
- 735 B: index.cjs.br
7
- 518 B: index.module.js.gz
8
- 453 B: index.module.js.br
9
- 844 B: index.module.js.gz
10
- 737 B: index.module.js.br
11
- 913 B: index.umd.js.gz
12
- 802 B: index.umd.js.br
@@ -1,11 +0,0 @@
1
-
2
- $ vitest run --passWithNoTests
3
- [?25l
4
-  RUN  v3.2.4 /Users/tobias/code/metorial/metorial-enterprise/oss/src/packages/shared/websocket
5
-
6
- No test files found, exiting with code 0
7
-
8
- include: **/*.{test,spec}.?(c|m)[jt]s?(x)
9
- exclude: **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*
10
-
11
- [?25h
package/CHANGELOG.md DELETED
@@ -1,25 +0,0 @@
1
- # @lowerdeck/websocket-client
2
-
3
- ## 1.0.3
4
-
5
- ### Patch Changes
6
-
7
- - Fix default entry point
8
- - Updated dependencies
9
- - @lowerdeck/emitter@1.0.3
10
-
11
- ## 1.0.2
12
-
13
- ### Patch Changes
14
-
15
- - update versions
16
- - Updated dependencies
17
- - @lowerdeck/emitter@1.0.2
18
-
19
- ## 1.0.1
20
-
21
- ### Patch Changes
22
-
23
- - Fix exports
24
- - Updated dependencies
25
- - @lowerdeck/emitter@1.0.1
@@ -1,2 +0,0 @@
1
- import{Emitter as t}from"@lowerdeck/emitter";class e{constructor(e,s={}){var i;this.ws=void 0,this.attempts=0,this.timer=null,this.url=void 0,this.opts=void 0,this.maxAttempts=void 0,this.emitter=new t,this.url=e,this.opts=s,this.maxAttempts=null!=(i=s.maxAttempts)?i:Infinity,this.open()}open(){var t;this.ws=new WebSocket(this.url,null!=(t=this.opts.protocols)?t:[]),this.ws.addEventListener("open",t=>{this.attempts=0,this.emitter.emit("open",t)}),this.ws.addEventListener("close",t=>{this.reconnect(t)}),this.ws.addEventListener("error",t=>{"ECONNREFUSED"===(null==t?void 0:t.code)?this.reconnect(t):this.emitter.emit("error",t)}),this.ws.addEventListener("message",t=>{this.emitter.emit("message",t)})}reconnect(t){var e;this.timer&&clearTimeout(this.timer),this.attempts++<this.maxAttempts?this.timer=setTimeout(()=>{var e,s;null==(e=(s=this.opts).onReconnect)||e.call(s,t),this.open()},null!=(e=this.opts.timeout)?e:1e3):(this.emitter.emit("maximum",t),this.emitter.emit("close",t),this.emitter.clear())}send(t){this.ws.send(t)}close(t=1e3,e){this.timer&&clearTimeout(this.timer),this.emitter.clear(),this.ws.close(t,e)}addEventListener(t,e){return this.emitter.on(t,e)}get readyState(){return this.ws.readyState}}export{e as ReconnectingWebSocketClient};
2
- //# sourceMappingURL=index.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/index.ts"],"sourcesContent":["import { Emitter } from '@lowerdeck/emitter';\n\n// Highly inspired by https://github.com/lukeed/sockette/blob/master/src/index.js\n\ninterface ReconnectingWebSocketOptions {\n protocols?: string | string[];\n maxAttempts?: number;\n timeout?: number;\n\n onReconnect?: (event: Event) => void;\n}\n\nexport class ReconnectingWebSocketClient {\n private ws!: WebSocket;\n private attempts = 0;\n private timer: ReturnType<typeof setTimeout> | null = null;\n private readonly url: string;\n private readonly opts: ReconnectingWebSocketOptions;\n private readonly maxAttempts: number;\n private emitter = new Emitter<any>();\n\n constructor(url: string, opts: ReconnectingWebSocketOptions = {}) {\n this.url = url;\n this.opts = opts;\n this.maxAttempts = opts.maxAttempts ?? Infinity;\n\n this.open();\n }\n\n private open(): void {\n this.ws = new WebSocket(this.url, this.opts.protocols ?? []);\n\n this.ws.addEventListener('open', event => {\n this.attempts = 0;\n this.emitter.emit('open', event);\n });\n\n this.ws.addEventListener('close', event => {\n // let shouldReconnect = ![1000, 1001, 1005].includes(event.code);\n // if (shouldReconnect) {\n this.reconnect(event);\n // } else {\n // this.emitter.emit('close', event);\n // }\n });\n\n this.ws.addEventListener('error', event => {\n let error = event as any;\n if (error?.code === 'ECONNREFUSED') {\n this.reconnect(event);\n } else {\n this.emitter.emit('error', event);\n }\n });\n\n this.ws.addEventListener('message', event => {\n this.emitter.emit('message', event);\n });\n }\n\n private reconnect(event: Event): void {\n if (this.timer) clearTimeout(this.timer);\n\n if (this.attempts++ < this.maxAttempts) {\n this.timer = setTimeout(() => {\n this.opts.onReconnect?.(event);\n this.open();\n }, this.opts.timeout ?? 1000);\n } else {\n this.emitter.emit('maximum', event);\n this.emitter.emit('close', event);\n this.emitter.clear();\n }\n }\n\n send(data: string | ArrayBufferLike): void {\n this.ws.send(data);\n }\n\n close(code: number = 1000, reason?: string): void {\n if (this.timer) clearTimeout(this.timer);\n this.emitter.clear();\n this.ws.close(code, reason);\n }\n\n addEventListener(event: string, callback: (data: any) => void) {\n return this.emitter.on(event, callback);\n }\n\n get readyState() {\n return this.ws.readyState;\n }\n}\n"],"names":["ReconnectingWebSocketClient","constructor","url","opts","_opts$maxAttempts","this","ws","attempts","timer","maxAttempts","emitter","Emitter","Infinity","open","_this$opts$protocols","WebSocket","protocols","addEventListener","event","emit","reconnect","error","code","_this$opts$timeout","clearTimeout","setTimeout","_this$opts$onReconnec","_this$opts","onReconnect","call","timeout","clear","send","data","close","reason","callback","on","readyState"],"mappings":"6CAYa,MAAAA,EASXC,WAAAA,CAAYC,EAAaC,EAAqC,CAAE,OAAAC,EAAAC,KARxDC,QAAE,EAAAD,KACFE,SAAW,EACXC,KAAAA,MAA8C,KAAIH,KACzCH,SACAC,EAAAA,KAAAA,UACAM,EAAAA,KAAAA,iBACTC,EAAAA,KAAAA,QAAU,IAAIC,EAGpBN,KAAKH,IAAMA,EACXG,KAAKF,KAAOA,EACZE,KAAKI,YAA8B,OAAnBL,EAAGD,EAAKM,aAAWL,EAAIQ,SAEvCP,KAAKQ,MACP,CAEQA,IAAAA,GAAI,IAAAC,EACVT,KAAKC,GAAK,IAAIS,UAAUV,KAAKH,IAAwBY,OAArBA,EAAET,KAAKF,KAAKa,WAASF,EAAI,IAEzDT,KAAKC,GAAGW,iBAAiB,OAAQC,IAC/Bb,KAAKE,SAAW,EAChBF,KAAKK,QAAQS,KAAK,OAAQD,KAG5Bb,KAAKC,GAAGW,iBAAiB,QAASC,IAGhCb,KAAKe,UAAUF,KAMjBb,KAAKC,GAAGW,iBAAiB,QAASC,IAEZ,kBAAhBG,MADQH,OACRG,EADQH,EACDI,MACTjB,KAAKe,UAAUF,GAEfb,KAAKK,QAAQS,KAAK,QAASD,KAI/Bb,KAAKC,GAAGW,iBAAiB,UAAWC,IAClCb,KAAKK,QAAQS,KAAK,UAAWD,IAEjC,CAEQE,SAAAA,CAAUF,GAGwBK,IAAAA,EAFpClB,KAAKG,OAAOgB,aAAanB,KAAKG,OAE9BH,KAAKE,WAAaF,KAAKI,YACzBJ,KAAKG,MAAQiB,WAAW,KAAK,IAAAC,EAAAC,SAC3BD,GAAAC,EAAAtB,KAAKF,MAAKyB,cAAVF,EAAAG,KAAAF,EAAwBT,GACxBb,KAAKQ,QACa,OAAnBU,EAAElB,KAAKF,KAAK2B,SAAOP,EAAI,MAExBlB,KAAKK,QAAQS,KAAK,UAAWD,GAC7Bb,KAAKK,QAAQS,KAAK,QAASD,GAC3Bb,KAAKK,QAAQqB,QAEjB,CAEAC,IAAAA,CAAKC,GACH5B,KAAKC,GAAG0B,KAAKC,EACf,CAEAC,KAAAA,CAAMZ,EAAe,IAAMa,GACrB9B,KAAKG,OAAOgB,aAAanB,KAAKG,OAClCH,KAAKK,QAAQqB,QACb1B,KAAKC,GAAG4B,MAAMZ,EAAMa,EACtB,CAEAlB,gBAAAA,CAAiBC,EAAekB,GAC9B,OAAW/B,KAACK,QAAQ2B,GAAGnB,EAAOkB,EAChC,CAEA,cAAIE,GACF,YAAYhC,GAAGgC,UACjB"}
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@lowerdeck/tsconfig/base.json",
4
- "exclude": [
5
- "dist"
6
- ],
7
- "include": [
8
- "src"
9
- ],
10
- "compilerOptions": {
11
- "outDir": "dist"
12
- }
13
- }