websocket-ts 2.3.0 → 3.0.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.
Files changed (188) hide show
  1. package/README.md +134 -9
  2. package/dist/cjs/{src/backoff → backoff}/backoff.d.ts +6 -3
  3. package/dist/{esm/src → cjs}/backoff/backoff.d.ts.map +1 -1
  4. package/dist/{esm/src → cjs}/backoff/backoff.js.map +1 -1
  5. package/dist/cjs/{src/backoff → backoff}/constantbackoff.d.ts +2 -2
  6. package/dist/cjs/backoff/constantbackoff.d.ts.map +1 -0
  7. package/dist/cjs/backoff/constantbackoff.js +34 -0
  8. package/dist/cjs/backoff/constantbackoff.js.map +1 -0
  9. package/dist/{esm/src → cjs}/backoff/exponentialbackoff.d.ts +2 -2
  10. package/dist/cjs/backoff/exponentialbackoff.d.ts.map +1 -0
  11. package/dist/cjs/{src/backoff → backoff}/exponentialbackoff.js +19 -27
  12. package/dist/cjs/backoff/exponentialbackoff.js.map +1 -0
  13. package/dist/{esm/src → cjs}/backoff/linearbackoff.d.ts +1 -1
  14. package/dist/cjs/backoff/linearbackoff.d.ts.map +1 -0
  15. package/dist/cjs/{src/backoff → backoff}/linearbackoff.js +23 -31
  16. package/dist/cjs/backoff/linearbackoff.js.map +1 -0
  17. package/dist/cjs/index.d.ts +14 -0
  18. package/dist/cjs/index.d.ts.map +1 -0
  19. package/dist/cjs/index.js +20 -0
  20. package/dist/cjs/index.js.map +1 -0
  21. package/dist/cjs/package.json +1 -0
  22. package/dist/{esm/src → cjs}/queue/array_queue.d.ts +1 -1
  23. package/dist/cjs/queue/array_queue.d.ts.map +1 -0
  24. package/dist/cjs/{src/queue → queue}/array_queue.js +17 -18
  25. package/dist/cjs/queue/array_queue.js.map +1 -0
  26. package/dist/cjs/queue/queue.d.ts.map +1 -0
  27. package/dist/cjs/{src/queue → queue}/queue.js.map +1 -1
  28. package/dist/cjs/{src/queue → queue}/ring_queue.d.ts +1 -1
  29. package/dist/cjs/queue/ring_queue.d.ts.map +1 -0
  30. package/dist/cjs/{src/queue → queue}/ring_queue.js +25 -22
  31. package/dist/cjs/queue/ring_queue.js.map +1 -0
  32. package/dist/cjs/{src/websocket.d.ts → websocket.d.ts} +75 -17
  33. package/dist/cjs/websocket.d.ts.map +1 -0
  34. package/dist/cjs/websocket.js +588 -0
  35. package/dist/cjs/websocket.js.map +1 -0
  36. package/dist/cjs/{src/websocket_buffer.d.ts → websocket_buffer.d.ts} +1 -1
  37. package/dist/cjs/websocket_buffer.d.ts.map +1 -0
  38. package/dist/cjs/websocket_buffer.js.map +1 -0
  39. package/dist/{esm/src → cjs}/websocket_builder.d.ts +14 -5
  40. package/dist/cjs/{src/websocket_builder.d.ts.map → websocket_builder.d.ts.map} +1 -1
  41. package/dist/cjs/websocket_builder.js +236 -0
  42. package/dist/cjs/websocket_builder.js.map +1 -0
  43. package/dist/{esm/src → cjs}/websocket_event.d.ts +20 -5
  44. package/dist/cjs/websocket_event.d.ts.map +1 -0
  45. package/dist/cjs/{src/websocket_event.js → websocket_event.js} +7 -1
  46. package/dist/cjs/websocket_event.js.map +1 -0
  47. package/dist/{esm/src → cjs}/websocket_options.d.ts +6 -5
  48. package/dist/cjs/websocket_options.d.ts.map +1 -0
  49. package/dist/cjs/websocket_options.js.map +1 -0
  50. package/dist/{esm/src → cjs}/websocket_retry_options.d.ts +3 -2
  51. package/dist/cjs/websocket_retry_options.d.ts.map +1 -0
  52. package/dist/cjs/websocket_retry_options.js.map +1 -0
  53. package/dist/esm/{src/backoff → backoff}/backoff.d.ts +6 -3
  54. package/dist/{cjs/src → esm}/backoff/backoff.d.ts.map +1 -1
  55. package/dist/{cjs/src → esm}/backoff/backoff.js.map +1 -1
  56. package/dist/esm/{src/backoff → backoff}/constantbackoff.d.ts +2 -2
  57. package/dist/esm/backoff/constantbackoff.d.ts.map +1 -0
  58. package/dist/esm/{src/backoff → backoff}/constantbackoff.js +3 -3
  59. package/dist/esm/backoff/constantbackoff.js.map +1 -0
  60. package/dist/{cjs/src → esm}/backoff/exponentialbackoff.d.ts +2 -2
  61. package/dist/esm/backoff/exponentialbackoff.d.ts.map +1 -0
  62. package/dist/esm/{src/backoff → backoff}/exponentialbackoff.js +6 -5
  63. package/dist/esm/backoff/exponentialbackoff.js.map +1 -0
  64. package/dist/{cjs/src → esm}/backoff/linearbackoff.d.ts +1 -1
  65. package/dist/esm/backoff/linearbackoff.d.ts.map +1 -0
  66. package/dist/esm/{src/backoff → backoff}/linearbackoff.js +8 -7
  67. package/dist/esm/backoff/linearbackoff.js.map +1 -0
  68. package/dist/esm/index.d.ts +14 -0
  69. package/dist/esm/index.d.ts.map +1 -0
  70. package/dist/esm/index.js +9 -0
  71. package/dist/esm/index.js.map +1 -0
  72. package/dist/esm/package.json +1 -0
  73. package/dist/{cjs/src → esm}/queue/array_queue.d.ts +1 -1
  74. package/dist/esm/queue/array_queue.d.ts.map +1 -0
  75. package/dist/esm/queue/array_queue.js.map +1 -0
  76. package/dist/esm/queue/queue.d.ts.map +1 -0
  77. package/dist/esm/{src/queue → queue}/queue.js.map +1 -1
  78. package/dist/esm/{src/queue → queue}/ring_queue.d.ts +1 -1
  79. package/dist/esm/queue/ring_queue.d.ts.map +1 -0
  80. package/dist/esm/{src/queue → queue}/ring_queue.js +7 -3
  81. package/dist/esm/queue/ring_queue.js.map +1 -0
  82. package/dist/esm/{src/websocket.d.ts → websocket.d.ts} +75 -17
  83. package/dist/esm/websocket.d.ts.map +1 -0
  84. package/dist/esm/websocket.js +584 -0
  85. package/dist/esm/websocket.js.map +1 -0
  86. package/dist/esm/{src/websocket_buffer.d.ts → websocket_buffer.d.ts} +1 -1
  87. package/dist/esm/websocket_buffer.d.ts.map +1 -0
  88. package/dist/esm/websocket_buffer.js.map +1 -0
  89. package/dist/{cjs/src → esm}/websocket_builder.d.ts +14 -5
  90. package/dist/esm/{src/websocket_builder.d.ts.map → websocket_builder.d.ts.map} +1 -1
  91. package/dist/esm/{src/websocket_builder.js → websocket_builder.js} +36 -17
  92. package/dist/esm/websocket_builder.js.map +1 -0
  93. package/dist/{cjs/src → esm}/websocket_event.d.ts +20 -5
  94. package/dist/esm/websocket_event.d.ts.map +1 -0
  95. package/dist/esm/{src/websocket_event.js → websocket_event.js} +7 -1
  96. package/dist/esm/websocket_event.js.map +1 -0
  97. package/dist/{cjs/src → esm}/websocket_options.d.ts +6 -5
  98. package/dist/esm/websocket_options.d.ts.map +1 -0
  99. package/dist/esm/websocket_options.js.map +1 -0
  100. package/dist/{cjs/src → esm}/websocket_retry_options.d.ts +3 -2
  101. package/dist/esm/websocket_retry_options.d.ts.map +1 -0
  102. package/dist/esm/websocket_retry_options.js.map +1 -0
  103. package/package.json +35 -16
  104. package/src/backoff/backoff.ts +6 -3
  105. package/src/backoff/constantbackoff.ts +4 -4
  106. package/src/backoff/exponentialbackoff.ts +7 -6
  107. package/src/backoff/linearbackoff.ts +9 -8
  108. package/src/index.ts +14 -13
  109. package/src/queue/array_queue.ts +1 -1
  110. package/src/queue/ring_queue.ts +12 -8
  111. package/src/websocket.ts +333 -79
  112. package/src/websocket_buffer.ts +1 -3
  113. package/src/websocket_builder.ts +24 -13
  114. package/src/websocket_event.ts +25 -6
  115. package/src/websocket_options.ts +6 -5
  116. package/src/websocket_retry_options.ts +3 -2
  117. package/dist/cjs/src/backoff/constantbackoff.d.ts.map +0 -1
  118. package/dist/cjs/src/backoff/constantbackoff.js +0 -43
  119. package/dist/cjs/src/backoff/constantbackoff.js.map +0 -1
  120. package/dist/cjs/src/backoff/exponentialbackoff.d.ts.map +0 -1
  121. package/dist/cjs/src/backoff/exponentialbackoff.js.map +0 -1
  122. package/dist/cjs/src/backoff/linearbackoff.d.ts.map +0 -1
  123. package/dist/cjs/src/backoff/linearbackoff.js.map +0 -1
  124. package/dist/cjs/src/index.d.ts +0 -14
  125. package/dist/cjs/src/index.d.ts.map +0 -1
  126. package/dist/cjs/src/index.js +0 -20
  127. package/dist/cjs/src/index.js.map +0 -1
  128. package/dist/cjs/src/queue/array_queue.d.ts.map +0 -1
  129. package/dist/cjs/src/queue/array_queue.js.map +0 -1
  130. package/dist/cjs/src/queue/queue.d.ts.map +0 -1
  131. package/dist/cjs/src/queue/ring_queue.d.ts.map +0 -1
  132. package/dist/cjs/src/queue/ring_queue.js.map +0 -1
  133. package/dist/cjs/src/websocket.d.ts.map +0 -1
  134. package/dist/cjs/src/websocket.js +0 -439
  135. package/dist/cjs/src/websocket.js.map +0 -1
  136. package/dist/cjs/src/websocket_buffer.d.ts.map +0 -1
  137. package/dist/cjs/src/websocket_buffer.js.map +0 -1
  138. package/dist/cjs/src/websocket_builder.js +0 -263
  139. package/dist/cjs/src/websocket_builder.js.map +0 -1
  140. package/dist/cjs/src/websocket_event.d.ts.map +0 -1
  141. package/dist/cjs/src/websocket_event.js.map +0 -1
  142. package/dist/cjs/src/websocket_options.d.ts.map +0 -1
  143. package/dist/cjs/src/websocket_options.js.map +0 -1
  144. package/dist/cjs/src/websocket_retry_options.d.ts.map +0 -1
  145. package/dist/cjs/src/websocket_retry_options.js.map +0 -1
  146. package/dist/esm/src/backoff/constantbackoff.d.ts.map +0 -1
  147. package/dist/esm/src/backoff/constantbackoff.js.map +0 -1
  148. package/dist/esm/src/backoff/exponentialbackoff.d.ts.map +0 -1
  149. package/dist/esm/src/backoff/exponentialbackoff.js.map +0 -1
  150. package/dist/esm/src/backoff/linearbackoff.d.ts.map +0 -1
  151. package/dist/esm/src/backoff/linearbackoff.js.map +0 -1
  152. package/dist/esm/src/index.d.ts +0 -14
  153. package/dist/esm/src/index.d.ts.map +0 -1
  154. package/dist/esm/src/index.js +0 -9
  155. package/dist/esm/src/index.js.map +0 -1
  156. package/dist/esm/src/queue/array_queue.d.ts.map +0 -1
  157. package/dist/esm/src/queue/array_queue.js.map +0 -1
  158. package/dist/esm/src/queue/queue.d.ts.map +0 -1
  159. package/dist/esm/src/queue/ring_queue.d.ts.map +0 -1
  160. package/dist/esm/src/queue/ring_queue.js.map +0 -1
  161. package/dist/esm/src/websocket.d.ts.map +0 -1
  162. package/dist/esm/src/websocket.js +0 -361
  163. package/dist/esm/src/websocket.js.map +0 -1
  164. package/dist/esm/src/websocket_buffer.d.ts.map +0 -1
  165. package/dist/esm/src/websocket_buffer.js.map +0 -1
  166. package/dist/esm/src/websocket_builder.js.map +0 -1
  167. package/dist/esm/src/websocket_event.d.ts.map +0 -1
  168. package/dist/esm/src/websocket_event.js.map +0 -1
  169. package/dist/esm/src/websocket_options.d.ts.map +0 -1
  170. package/dist/esm/src/websocket_options.js.map +0 -1
  171. package/dist/esm/src/websocket_retry_options.d.ts.map +0 -1
  172. package/dist/esm/src/websocket_retry_options.js.map +0 -1
  173. package/eslint.config.mjs +0 -43
  174. package/tsconfig.cjs.json +0 -74
  175. package/tsconfig.esm.json +0 -74
  176. /package/dist/cjs/{src/backoff → backoff}/backoff.js +0 -0
  177. /package/dist/cjs/{src/queue → queue}/queue.d.ts +0 -0
  178. /package/dist/cjs/{src/queue → queue}/queue.js +0 -0
  179. /package/dist/cjs/{src/websocket_buffer.js → websocket_buffer.js} +0 -0
  180. /package/dist/cjs/{src/websocket_options.js → websocket_options.js} +0 -0
  181. /package/dist/cjs/{src/websocket_retry_options.js → websocket_retry_options.js} +0 -0
  182. /package/dist/esm/{src/backoff → backoff}/backoff.js +0 -0
  183. /package/dist/esm/{src/queue → queue}/array_queue.js +0 -0
  184. /package/dist/esm/{src/queue → queue}/queue.d.ts +0 -0
  185. /package/dist/esm/{src/queue → queue}/queue.js +0 -0
  186. /package/dist/esm/{src/websocket_buffer.js → websocket_buffer.js} +0 -0
  187. /package/dist/esm/{src/websocket_options.js → websocket_options.js} +0 -0
  188. /package/dist/esm/{src/websocket_retry_options.js → websocket_retry_options.js} +0 -0
package/README.md CHANGED
@@ -10,7 +10,7 @@ A <b>WebSocket</b> for browsers with <b>auto-reconnect</b> and <b>message buffer
10
10
 
11
11
  [![Build Status](https://img.shields.io/github/actions/workflow/status/jjxxs/websocket-ts/build.yml)](https://github.com/jjxxs/websocket-ts/actions/workflows/build.yml)
12
12
  [![Test Status](https://img.shields.io/github/actions/workflow/status/jjxxs/websocket-ts/test.yml?label=tests)](https://github.com/jjxxs/websocket-ts/actions/workflows/test.yml)
13
- [![Coverage Status](https://img.shields.io/coveralls/github/jjxxs/websocket-ts/master)](https://coveralls.io/github/jjxxs/websocket-ts?branch=master)
13
+ [![Coverage Status](https://img.shields.io/coveralls/github/jjxxs/websocket-ts/main)](https://coveralls.io/github/jjxxs/websocket-ts?branch=main)
14
14
  [![npm downloads](https://img.shields.io/npm/dm/websocket-ts.svg)](https://npm-stat.com/charts.html?package=websocket-ts)
15
15
 
16
16
  </div>
@@ -18,15 +18,15 @@ A <b>WebSocket</b> for browsers with <b>auto-reconnect</b> and <b>message buffer
18
18
  <div align="center">
19
19
 
20
20
  [![npm version](https://img.shields.io/npm/v/websocket-ts.svg)](https://www.npmjs.org/package/websocket-ts)
21
- [![Bundle Size](https://deno.bundlejs.com/badge?q=websocket-ts@2.2.1)](https://bundlejs.com/?q=websocket-ts)
22
- [![Known Vulnerabilities](https://snyk.io/test/npm/websocket-ts/badge.svg)](https://snyk.io/test/npm/websocket-ts)
23
- [![License](https://img.shields.io/github/license/jjxxs/websocket-ts)](/LICENSE)
21
+ [![Bundle Size](https://deno.bundlejs.com/badge?q=websocket-ts)](https://bundlejs.com/?q=websocket-ts)
22
+ [![Snyk security](https://snyk.io/test/npm/websocket-ts/badge.svg)](https://snyk.io/test/npm/websocket-ts)
23
+ [![License](https://img.shields.io/npm/l/websocket-ts)](https://github.com/jjxxs/websocket-ts/blob/main/LICENSE)
24
24
 
25
25
  </div>
26
26
 
27
27
  ## Features
28
28
 
29
- - **Lightweight & Standalone**: No dependencies, 2.5 kB minified & gzipped.
29
+ - **Lightweight & Standalone**: No dependencies, only a few kB minified & gzipped (see badge).
30
30
  - **Browser-native**: Utilizes native WebSocket API, offers direct access to the underlying connection.
31
31
  - **Smart Reconnect**: Optional auto-reconnect and message buffering.
32
32
  - **Easy Setup**: Optional builder class for quick initialization.
@@ -88,7 +88,7 @@ const ws = new WebsocketBuilder("ws://localhost:42421").build();
88
88
 
89
89
  #### Events
90
90
 
91
- There are six events you can listen for:
91
+ There are seven events you can listen for:
92
92
 
93
93
  | Event | Description |
94
94
  |---|---|
@@ -97,10 +97,29 @@ There are six events you can listen for:
97
97
  | `error` | An error occurred |
98
98
  | `message` | Message received |
99
99
  | `retry` | Reconnect attempt |
100
- | `reconnect` | Successful reconnect |
100
+ | `reconnect` | Automatic retry succeeded (fires before `open`) |
101
+ | `exhausted` | Gave up reconnecting after `maxRetries` consecutive failed attempts |
101
102
 
102
103
  You can use either `WebsocketEvent.open` or the string `"open"` when registering listeners.
103
104
 
105
+ The `retry`, `reconnect` and `exhausted` events are `CustomEvent`s whose `detail`
106
+ carries the number of retries and the time of the last successful connection.
107
+
108
+ The browser's own `error` events carry no details. When an automatic retry
109
+ fails because the URL provider or the `WebSocket` constructor threw, the
110
+ `error` event is an `ErrorEvent` whose `error` is the thrown value:
111
+
112
+ ```typescript
113
+ ws.addEventListener(WebsocketEvent.error, (i, ev) => {
114
+ if (ev instanceof ErrorEvent) {
115
+ console.warn("connection attempt failed", ev.error);
116
+ }
117
+ });
118
+ ```
119
+
120
+ Errors thrown by the `WebSocket` constructor may include the URL in their
121
+ message, so take care when forwarding them to logs if the URL contains a token.
122
+
104
123
  #### Add Event Listeners
105
124
  Event listeners receive the websocket instance (`i`) and the triggering event (`ev`) as arguments.
106
125
 
@@ -112,12 +131,28 @@ const ws = new WebsocketBuilder("ws://localhost:42421")
112
131
  .onMessage((i, ev) => console.log("message"))
113
132
  .onRetry((i, ev) => console.log("retry"))
114
133
  .onReconnect((i, ev) => console.log("reconnect"))
134
+ .onExhausted((i, ev) => console.log("gave up"))
115
135
  .build();
116
136
  ```
117
137
 
138
+ Listeners accept the options `once` (remove after the first call) and `signal`
139
+ (an `AbortSignal`). Aborting the signal removes the listener again, which is
140
+ handy for tearing down a group of listeners in one call, e.g. when a component
141
+ unmounts:
142
+
143
+ ```typescript
144
+ const controller = new AbortController();
145
+ ws.addEventListener(WebsocketEvent.message, onMessage, { signal: controller.signal });
146
+ ws.addEventListener(WebsocketEvent.close, onClose, { signal: controller.signal });
147
+ /* ... on teardown: */
148
+ controller.abort(); // removes both listeners
149
+ ```
150
+
118
151
  #### Remove Event Listeners
119
152
 
120
- To unregister a specific event listener, use `removeEventListener`:
153
+ To unregister a specific event listener, use `removeEventListener`. Listeners
154
+ are matched by function identity; the options they were registered with are
155
+ ignored when matching:
121
156
 
122
157
  ```typescript
123
158
  let ws: Websocket
@@ -135,6 +170,11 @@ let ws: Websocket;
135
170
  ws.send("Hello World!");
136
171
  ```
137
172
 
173
+ If the websocket is not connected, the message is stored in the buffer and
174
+ sent once the connection is (re-)established — but only if a buffer was
175
+ configured (see below). Without a buffer, or after `close()` was called, the
176
+ message is silently dropped.
177
+
138
178
  #### Reconnect & Backoff (Optional)
139
179
 
140
180
  To automatically reconnect after a disconnection, provide a `Backoff` strategy.
@@ -176,6 +216,46 @@ const ws = new WebsocketBuilder("ws://localhost:42421")
176
216
  .build();
177
217
  ```
178
218
 
219
+ ##### Retry Limit & Instant Reconnect
220
+
221
+ Two options refine the retry behavior. Both require a backoff to be
222
+ configured — setting them without one throws at construction:
223
+
224
+ - `withMaxRetries(n)` stops reconnecting after `n` consecutive failed
225
+ attempts. The counter resets on every successful reconnect, so the limit
226
+ applies per outage, not per websocket lifetime. When the limit is reached,
227
+ the `exhausted` event fires.
228
+ - `withInstantReconnect(true)` skips the backoff delay for the *first* retry
229
+ of an outage — useful when a dropped connection is usually recoverable
230
+ immediately (e.g. a server restart). Subsequent retries follow the backoff.
231
+
232
+ ```typescript
233
+ const ws = new WebsocketBuilder("ws://localhost:42421")
234
+ .withBackoff(new ExponentialBackoff(1000, 6))
235
+ .withMaxRetries(10) // give up after 10 consecutive failures
236
+ .withInstantReconnect(true) // first retry of an outage is instant
237
+ .build();
238
+ ```
239
+
240
+ ##### Giving Up & Resuming
241
+
242
+ When `maxRetries` is exhausted, the websocket stops retrying and fires the
243
+ `exhausted` event. Use `reconnect()` to resume — it resets the retry budget,
244
+ resolves the URL (provider) again and connects immediately. It also works on
245
+ an open or user-closed websocket, e.g. to force a new connection after an
246
+ auth-token rotation or when the browser comes back online:
247
+
248
+ ```typescript
249
+ const ws = new WebsocketBuilder("ws://localhost:42421")
250
+ .withBackoff(new ConstantBackoff(1000))
251
+ .withMaxRetries(5)
252
+ .onExhausted(() => showReconnectBanner())
253
+ .build();
254
+
255
+ reconnectButton.onclick = () => ws.reconnect();
256
+ window.addEventListener("online", () => ws.reconnect());
257
+ ```
258
+
179
259
  #### Buffer (Optional)
180
260
 
181
261
  To buffer outgoing messages when the websocket is disconnected, provide a `Queue`.
@@ -184,6 +264,14 @@ the websocket (re)connects. Two built-in `Queue` implementations are available,
184
264
  create your own by implementing the `Queue` interface. If no queue is provided, messages
185
265
  won't be buffered.
186
266
 
267
+ The buffer only covers the time the websocket is not open: a message handed to an open
268
+ connection is not buffered again, so it is lost if the connection drops before it arrives.
269
+ If you need guaranteed delivery, add acknowledgements at the application level.
270
+
271
+ Buffered messages are kept when you call `close()` and are sent once `reconnect()` opens a
272
+ new connection, even if the URL provider now returns a URL for a different user. At such a
273
+ boundary, clear the queue you passed in (e.g. `queue.clear()`) or create a new websocket.
274
+
187
275
  ##### RingQueue
188
276
 
189
277
  `RingQueue` is a fixed-capacity, first-in-first-out (FIFO) queue. When it reaches capacity,
@@ -210,7 +298,8 @@ const ws = new WebsocketBuilder("ws://localhost:42421")
210
298
 
211
299
  By default, the URL is a static string. To use a different URL between connection attempts, provide
212
300
  a function instead. The function is called on each connection attempt, including the initial one and
213
- any retries. This enables use cases like load balancing, auth token rotation, and failover.
301
+ any retries, and should only resolve a URL. This enables use cases like load balancing, auth token
302
+ rotation, and failover.
214
303
 
215
304
  ```typescript
216
305
  const ws = new WebsocketBuilder(() => `ws://localhost:42421?token=${getToken()}`)
@@ -218,6 +307,42 @@ const ws = new WebsocketBuilder(() => `ws://localhost:42421?token=${getToken()}`
218
307
  .build();
219
308
  ```
220
309
 
310
+ Calling `reconnect()` also re-runs the provider, so a fresh URL (e.g. a new
311
+ token) can be forced without waiting for the connection to drop.
312
+
313
+ If the provider throws during an automatic retry, the websocket fires an
314
+ `error` event carrying the thrown value (see [Events](#events)) and keeps
315
+ retrying under the usual backoff and `maxRetries` rules. When called from the
316
+ constructor or `reconnect()`, the exception propagates to the caller.
317
+
318
+ ## Upgrading from 2.x
319
+
320
+ - **Imports**: import from `websocket-ts` only. Deep imports such as
321
+ `websocket-ts/dist/cjs/src/...` no longer resolve.
322
+ - **JavaScript target**: the published code is ES2018 (2.x shipped ES5/ES2015).
323
+ Transpile it yourself if you support older browsers.
324
+ - **Retry options**: setting `maxRetries` or `instantReconnect` (even to `false`)
325
+ without a backoff now throws, as does a `maxRetries` that is neither a whole
326
+ number ≥ 0 nor `Infinity`.
327
+ - **`instantReconnect`**: only the first retry of an outage is instant; later
328
+ retries follow the backoff and count towards `maxRetries`. In 2.x every retry
329
+ was instant and `maxRetries` was ignored.
330
+ - **Backoff**: the first retry now waits the first value of the series, as
331
+ documented, e.g. `ExponentialBackoff(1000)` waits 1s, 2s, 4s, … (2.x: 2s, 4s, …).
332
+ Custom `Backoff`s must return `current` from `next()` and then advance.
333
+ - **`reconnect` event**: fires (before `open`) whenever an automatic retry
334
+ succeeds, now also if the initial connection failed. A manual `reconnect()`
335
+ only fires `open`, so put (re-)subscription logic into `open`.
336
+ - **URL provider errors**: an exception from the provider (or the `WebSocket`
337
+ constructor) during an automatic retry no longer escapes as an uncaught
338
+ error that stops reconnecting. It is delivered as an `error` event (an
339
+ `ErrorEvent` carrying the thrown value), and retrying continues.
340
+ - **Listeners**: options are limited to `once` and `signal`.
341
+ `removeEventListener` removes every registration of the given function,
342
+ regardless of its options.
343
+ - **Types**: `send()` and buffers accept `string | Blob | BufferSource`;
344
+ `SharedArrayBuffer`-backed data is no longer accepted.
345
+
221
346
  ## Build & Tests
222
347
 
223
348
  To compile the project, run `npm run build`.
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * A Backoff produces a series of numbers that are used to determine
3
3
  * the delay between connection-retries. Values are expected to be in milliseconds.
4
+ *
5
+ * Implementations must not call back into the websocket (e.g. close() or reconnect()):
6
+ * the websocket calls them in the middle of its lifecycle transitions.
4
7
  */
5
8
  export interface Backoff {
6
9
  /**
@@ -8,12 +11,12 @@ export interface Backoff {
8
11
  */
9
12
  readonly retries: number;
10
13
  /**
11
- * Current number in the series.
14
+ * Current number in the series, i.e. the value that the next call to next() will return.
12
15
  */
13
16
  readonly current: number;
14
17
  /**
15
- * Advances the series to the next number and returns it.
16
- * @return the next number in the series
18
+ * Returns the current number in the series and advances the series by one step.
19
+ * @return the current number in the series
17
20
  */
18
21
  next(): number;
19
22
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../../../src/backoff/backoff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf"}
1
+ {"version":3,"file":"backoff.d.ts","sourceRoot":"","sources":["../../../src/backoff/backoff.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf"}
@@ -1 +1 @@
1
- {"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../../../src/backoff/backoff.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../../src/backoff/backoff.ts"],"names":[],"mappings":""}
@@ -1,4 +1,4 @@
1
- import { Backoff } from "./backoff";
1
+ import { Backoff } from "./backoff.js";
2
2
  /**
3
3
  * ConstantBackoff always returns the same backoff-time.
4
4
  */
@@ -7,7 +7,7 @@ export declare class ConstantBackoff implements Backoff {
7
7
  private _retries;
8
8
  /**
9
9
  * Creates a new ConstantBackoff.
10
- * @param backoff the backoff-time to return
10
+ * @param backoff the backoff-time (in milliseconds) to return
11
11
  */
12
12
  constructor(backoff: number);
13
13
  get retries(): number;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constantbackoff.d.ts","sourceRoot":"","sources":["../../../src/backoff/constantbackoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;GAEG;AACH,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAa;IAE7B;;;OAGG;gBACS,OAAO,EAAE,MAAM;IAQ3B,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,IAAI,MAAM;IAKd,KAAK,IAAI,IAAI;CAGd"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConstantBackoff = void 0;
4
+ /**
5
+ * ConstantBackoff always returns the same backoff-time.
6
+ */
7
+ class ConstantBackoff {
8
+ /**
9
+ * Creates a new ConstantBackoff.
10
+ * @param backoff the backoff-time (in milliseconds) to return
11
+ */
12
+ constructor(backoff) {
13
+ this._retries = 0;
14
+ if (!Number.isFinite(backoff) || backoff < 0) {
15
+ throw new Error("Backoff must be a finite, non-negative number");
16
+ }
17
+ this.backoff = backoff;
18
+ }
19
+ get retries() {
20
+ return this._retries;
21
+ }
22
+ get current() {
23
+ return this.backoff;
24
+ }
25
+ next() {
26
+ this._retries++;
27
+ return this.backoff;
28
+ }
29
+ reset() {
30
+ this._retries = 0;
31
+ }
32
+ }
33
+ exports.ConstantBackoff = ConstantBackoff;
34
+ //# sourceMappingURL=constantbackoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constantbackoff.js","sourceRoot":"","sources":["../../../src/backoff/constantbackoff.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,eAAe;IAI1B;;;OAGG;IACH,YAAY,OAAe;QANnB,aAAQ,GAAW,CAAC,CAAC;QAO3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI;QACF,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;IACpB,CAAC;CACF;AAhCD,0CAgCC"}
@@ -1,4 +1,4 @@
1
- import { Backoff } from "./backoff";
1
+ import { Backoff } from "./backoff.js";
2
2
  /**
3
3
  * ExponentialBackoff increases the backoff-time exponentially.
4
4
  * An optional maximum can be provided as an upper bound to the
@@ -36,7 +36,7 @@ export declare class ExponentialBackoff implements Backoff {
36
36
  private _retries;
37
37
  /**
38
38
  * Creates a new ExponentialBackoff.
39
- * @param base the base of the exponentiation
39
+ * @param base the base of the exponentiation (in milliseconds)
40
40
  * @param expMax the maximum exponent, no bound if undefined
41
41
  */
42
42
  constructor(base: number, expMax?: number);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exponentialbackoff.d.ts","sourceRoot":"","sources":["../../../src/backoff/exponentialbackoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBAAa,kBAAmB,YAAW,OAAO;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,CAAC,CAAS;IAClB,OAAO,CAAC,QAAQ,CAAa;IAE7B;;;;OAIG;gBACS,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAazC,IAAI,OAAO,WAEV;IAED,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,IAAI,MAAM;IAUd,KAAK,IAAI,IAAI;CAId"}
@@ -31,51 +31,43 @@ exports.ExponentialBackoff = void 0;
31
31
  * backoff = 1000 * 2^3 = 8000
32
32
  * ... // and so on
33
33
  */
34
- var ExponentialBackoff = /** @class */ (function () {
34
+ class ExponentialBackoff {
35
35
  /**
36
36
  * Creates a new ExponentialBackoff.
37
- * @param base the base of the exponentiation
37
+ * @param base the base of the exponentiation (in milliseconds)
38
38
  * @param expMax the maximum exponent, no bound if undefined
39
39
  */
40
- function ExponentialBackoff(base, expMax) {
40
+ constructor(base, expMax) {
41
41
  this._retries = 0;
42
- if (!Number.isInteger(base) || base < 0) {
43
- throw new Error("Base must be a positive integer or zero");
42
+ if (!Number.isFinite(base) || base < 0) {
43
+ throw new Error("Base must be a finite, non-negative number");
44
44
  }
45
45
  if (expMax !== undefined && (!Number.isInteger(expMax) || expMax < 0)) {
46
- throw new Error("ExpMax must be undefined, a positive integer, or zero");
46
+ throw new Error("ExpMax must be undefined or a non-negative integer");
47
47
  }
48
48
  this.base = base;
49
49
  this.expMax = expMax;
50
50
  this.i = 0;
51
51
  }
52
- Object.defineProperty(ExponentialBackoff.prototype, "retries", {
53
- get: function () {
54
- return this._retries;
55
- },
56
- enumerable: false,
57
- configurable: true
58
- });
59
- Object.defineProperty(ExponentialBackoff.prototype, "current", {
60
- get: function () {
61
- return this.base * Math.pow(2, this.i);
62
- },
63
- enumerable: false,
64
- configurable: true
65
- });
66
- ExponentialBackoff.prototype.next = function () {
52
+ get retries() {
53
+ return this._retries;
54
+ }
55
+ get current() {
56
+ return this.base * Math.pow(2, this.i);
57
+ }
58
+ next() {
59
+ const backoff = this.current;
67
60
  this._retries++;
68
61
  this.i =
69
62
  this.expMax === undefined
70
63
  ? this.i + 1
71
64
  : Math.min(this.i + 1, this.expMax);
72
- return this.current;
73
- };
74
- ExponentialBackoff.prototype.reset = function () {
65
+ return backoff;
66
+ }
67
+ reset() {
75
68
  this._retries = 0;
76
69
  this.i = 0;
77
- };
78
- return ExponentialBackoff;
79
- }());
70
+ }
71
+ }
80
72
  exports.ExponentialBackoff = ExponentialBackoff;
81
73
  //# sourceMappingURL=exponentialbackoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exponentialbackoff.js","sourceRoot":"","sources":["../../../src/backoff/exponentialbackoff.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,kBAAkB;IAM7B;;;;OAIG;IACH,YAAY,IAAY,EAAE,MAAe;QAPjC,aAAQ,GAAW,CAAC,CAAC;QAQ3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,IAAI;QACF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC;YACJ,IAAI,CAAC,MAAM,KAAK,SAAS;gBACvB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;gBACZ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF;AA9CD,gDA8CC"}
@@ -1,4 +1,4 @@
1
- import { Backoff } from "./backoff";
1
+ import { Backoff } from "./backoff.js";
2
2
  /**
3
3
  * LinearBackoff returns a backoff-time that is incremented by a fixed amount
4
4
  * with every step/retry. An optional maximum can be provided as an upper bound
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linearbackoff.d.ts","sourceRoot":"","sources":["../../../src/backoff/linearbackoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;IAC9B,OAAO,CAAC,CAAC,CAAa;IACtB,OAAO,CAAC,QAAQ,CAAa;IAE7B;;;;;OAKG;gBACS,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAqB5D,IAAI,OAAO,WAEV;IAED,IAAI,OAAO,IAAI,MAAM,CAIpB;IAED,IAAI,IAAI,MAAM;IAOd,KAAK,IAAI,IAAI;CAId"}
@@ -32,24 +32,24 @@ exports.LinearBackoff = void 0;
32
32
  * backoff = 1000 + 1000 * 4 = 5000
33
33
  * ... // and so on
34
34
  */
35
- var LinearBackoff = /** @class */ (function () {
35
+ class LinearBackoff {
36
36
  /**
37
37
  * Creates a new LinearBackoff.
38
38
  * @param initial the initial backoff-time in milliseconds
39
39
  * @param increment the amount to increment the backoff-time with every step (in milliseconds)
40
40
  * @param max the maximum backoff-time (in milliseconds), no bound if undefined
41
41
  */
42
- function LinearBackoff(initial, increment, max) {
42
+ constructor(initial, increment, max) {
43
43
  this.i = 0;
44
44
  this._retries = 0;
45
- if (initial < 0) {
46
- throw new Error("Initial must be a positive number or zero");
45
+ if (!Number.isFinite(initial) || initial < 0) {
46
+ throw new Error("Initial must be a finite, non-negative number");
47
47
  }
48
- if (increment < 0) {
49
- throw new Error("Increment must be a positive number or zero");
48
+ if (!Number.isFinite(increment) || increment < 0) {
49
+ throw new Error("Increment must be a finite, non-negative number");
50
50
  }
51
- if (max !== undefined && max < 0) {
52
- throw new Error("Max must be undefined, a positive number or zero");
51
+ if (max !== undefined && (!Number.isFinite(max) || max < 0)) {
52
+ throw new Error("Max must be undefined or a finite, non-negative number");
53
53
  }
54
54
  if (max !== undefined && max < initial) {
55
55
  throw new Error("Max must be undefined or greater than or equal to initial");
@@ -58,32 +58,24 @@ var LinearBackoff = /** @class */ (function () {
58
58
  this.increment = increment;
59
59
  this.max = max;
60
60
  }
61
- Object.defineProperty(LinearBackoff.prototype, "retries", {
62
- get: function () {
63
- return this._retries;
64
- },
65
- enumerable: false,
66
- configurable: true
67
- });
68
- Object.defineProperty(LinearBackoff.prototype, "current", {
69
- get: function () {
70
- return this.max === undefined
71
- ? this.initial + this.increment * this.i
72
- : Math.min(this.initial + this.increment * this.i, this.max);
73
- },
74
- enumerable: false,
75
- configurable: true
76
- });
77
- LinearBackoff.prototype.next = function () {
61
+ get retries() {
62
+ return this._retries;
63
+ }
64
+ get current() {
65
+ return this.max === undefined
66
+ ? this.initial + this.increment * this.i
67
+ : Math.min(this.initial + this.increment * this.i, this.max);
68
+ }
69
+ next() {
70
+ const backoff = this.current;
78
71
  this._retries++;
79
72
  this.i++;
80
- return this.current;
81
- };
82
- LinearBackoff.prototype.reset = function () {
73
+ return backoff;
74
+ }
75
+ reset() {
83
76
  this._retries = 0;
84
77
  this.i = 0;
85
- };
86
- return LinearBackoff;
87
- }());
78
+ }
79
+ }
88
80
  exports.LinearBackoff = LinearBackoff;
89
81
  //# sourceMappingURL=linearbackoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linearbackoff.js","sourceRoot":"","sources":["../../../src/backoff/linearbackoff.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,aAAa;IAOxB;;;;;OAKG;IACH,YAAY,OAAe,EAAE,SAAiB,EAAE,GAAY;QATpD,MAAC,GAAW,CAAC,CAAC;QACd,aAAQ,GAAW,CAAC,CAAC;QAS3B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,GAAG,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;YAC5D,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QACD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,OAAO,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,GAAG,KAAK,SAAS;YAC3B,CAAC,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;YACxC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACjE,CAAC;IAED,IAAI;QACF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC7B,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF;AAvDD,sCAuDC"}
@@ -0,0 +1,14 @@
1
+ export { Backoff } from "./backoff/backoff.js";
2
+ export { ConstantBackoff } from "./backoff/constantbackoff.js";
3
+ export { ExponentialBackoff } from "./backoff/exponentialbackoff.js";
4
+ export { LinearBackoff } from "./backoff/linearbackoff.js";
5
+ export { Queue } from "./queue/queue.js";
6
+ export { ArrayQueue } from "./queue/array_queue.js";
7
+ export { RingQueue } from "./queue/ring_queue.js";
8
+ export { UrlProvider, Websocket } from "./websocket.js";
9
+ export { WebsocketBuffer } from "./websocket_buffer.js";
10
+ export { WebsocketBuilder } from "./websocket_builder.js";
11
+ export { WebsocketEvent, RetryEventDetail, ReconnectEventDetail, ExhaustedEventDetail, WebsocketEventMap, WebsocketEventListener, WebsocketEventListenerParams, WebsocketEventListenerOptions, WebsocketEventListenerWithOptions, WebsocketEventListeners, } from "./websocket_event.js";
12
+ export { WebsocketOptions } from "./websocket_options.js";
13
+ export { WebsocketConnectionRetryOptions } from "./websocket_retry_options.js";
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebsocketEvent = exports.WebsocketBuilder = exports.Websocket = exports.RingQueue = exports.ArrayQueue = exports.LinearBackoff = exports.ExponentialBackoff = exports.ConstantBackoff = void 0;
4
+ var constantbackoff_js_1 = require("./backoff/constantbackoff.js");
5
+ Object.defineProperty(exports, "ConstantBackoff", { enumerable: true, get: function () { return constantbackoff_js_1.ConstantBackoff; } });
6
+ var exponentialbackoff_js_1 = require("./backoff/exponentialbackoff.js");
7
+ Object.defineProperty(exports, "ExponentialBackoff", { enumerable: true, get: function () { return exponentialbackoff_js_1.ExponentialBackoff; } });
8
+ var linearbackoff_js_1 = require("./backoff/linearbackoff.js");
9
+ Object.defineProperty(exports, "LinearBackoff", { enumerable: true, get: function () { return linearbackoff_js_1.LinearBackoff; } });
10
+ var array_queue_js_1 = require("./queue/array_queue.js");
11
+ Object.defineProperty(exports, "ArrayQueue", { enumerable: true, get: function () { return array_queue_js_1.ArrayQueue; } });
12
+ var ring_queue_js_1 = require("./queue/ring_queue.js");
13
+ Object.defineProperty(exports, "RingQueue", { enumerable: true, get: function () { return ring_queue_js_1.RingQueue; } });
14
+ var websocket_js_1 = require("./websocket.js");
15
+ Object.defineProperty(exports, "Websocket", { enumerable: true, get: function () { return websocket_js_1.Websocket; } });
16
+ var websocket_builder_js_1 = require("./websocket_builder.js");
17
+ Object.defineProperty(exports, "WebsocketBuilder", { enumerable: true, get: function () { return websocket_builder_js_1.WebsocketBuilder; } });
18
+ var websocket_event_js_1 = require("./websocket_event.js");
19
+ Object.defineProperty(exports, "WebsocketEvent", { enumerable: true, get: function () { return websocket_event_js_1.WebsocketEvent; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AACA,mEAA+D;AAAtD,qHAAA,eAAe,OAAA;AACxB,yEAAqE;AAA5D,2HAAA,kBAAkB,OAAA;AAC3B,+DAA2D;AAAlD,iHAAA,aAAa,OAAA;AAEtB,yDAAoD;AAA3C,4GAAA,UAAU,OAAA;AACnB,uDAAkD;AAAzC,0GAAA,SAAS,OAAA;AAClB,+CAAwD;AAAlC,yGAAA,SAAS,OAAA;AAE/B,+DAA0D;AAAjD,wHAAA,gBAAgB,OAAA;AACzB,2DAW8B;AAV5B,oHAAA,cAAc,OAAA"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,4 +1,4 @@
1
- import { Queue } from "./queue";
1
+ import { Queue } from "./queue.js";
2
2
  /**
3
3
  * An array queue is a queue that has an unbounded capacity. Reading from an array queue
4
4
  * will return the oldest element and effectively remove it from the queue.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array_queue.d.ts","sourceRoot":"","sources":["../../../src/queue/array_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;GAGG;AACH,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;;IAM/B,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;IAIrB,KAAK;IAIL,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO;IAInC,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,IAAI,IAAI,CAAC,GAAG,SAAS;CAGtB"}
@@ -5,32 +5,31 @@ exports.ArrayQueue = void 0;
5
5
  * An array queue is a queue that has an unbounded capacity. Reading from an array queue
6
6
  * will return the oldest element and effectively remove it from the queue.
7
7
  */
8
- var ArrayQueue = /** @class */ (function () {
9
- function ArrayQueue() {
8
+ class ArrayQueue {
9
+ constructor() {
10
10
  this.elements = [];
11
11
  }
12
- ArrayQueue.prototype.add = function (element) {
12
+ add(element) {
13
13
  this.elements.push(element);
14
- };
15
- ArrayQueue.prototype.clear = function () {
14
+ }
15
+ clear() {
16
16
  this.elements.length = 0;
17
- };
18
- ArrayQueue.prototype.forEach = function (fn) {
17
+ }
18
+ forEach(fn) {
19
19
  this.elements.forEach(fn);
20
- };
21
- ArrayQueue.prototype.length = function () {
20
+ }
21
+ length() {
22
22
  return this.elements.length;
23
- };
24
- ArrayQueue.prototype.isEmpty = function () {
23
+ }
24
+ isEmpty() {
25
25
  return this.elements.length === 0;
26
- };
27
- ArrayQueue.prototype.peek = function () {
26
+ }
27
+ peek() {
28
28
  return this.elements[0];
29
- };
30
- ArrayQueue.prototype.read = function () {
29
+ }
30
+ read() {
31
31
  return this.elements.shift();
32
- };
33
- return ArrayQueue;
34
- }());
32
+ }
33
+ }
35
34
  exports.ArrayQueue = ArrayQueue;
36
35
  //# sourceMappingURL=array_queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array_queue.js","sourceRoot":"","sources":["../../../src/queue/array_queue.ts"],"names":[],"mappings":";;;AAEA;;;GAGG;AACH,MAAa,UAAU;IAGrB;QACE,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,GAAG,CAAC,OAAU;QACZ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,EAA2B;QACjC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF;AAlCD,gCAkCC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../../../src/queue/queue.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEtB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;OAGG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO,GAAG,IAAI,CAAC;IAE3C;;;OAGG;IACH,MAAM,IAAI,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC;IAEnB;;;OAGG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;IAEtB;;;OAGG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;CACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/queue/queue.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../src/queue/queue.ts"],"names":[],"mappings":""}