websocket-ts 1.1.1 → 2.1.2

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 (181) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +157 -93
  3. package/dist/cjs/src/backoff/backoff.d.ts +24 -0
  4. package/dist/cjs/src/backoff/backoff.d.ts.map +1 -0
  5. package/{lib → dist/cjs/src}/backoff/backoff.js.map +1 -1
  6. package/dist/cjs/src/backoff/constantbackoff.d.ts +18 -0
  7. package/dist/cjs/src/backoff/constantbackoff.d.ts.map +1 -0
  8. package/dist/cjs/src/backoff/constantbackoff.js +43 -0
  9. package/dist/cjs/src/backoff/constantbackoff.js.map +1 -0
  10. package/dist/cjs/src/backoff/exponentialbackoff.d.ts +48 -0
  11. package/dist/cjs/src/backoff/exponentialbackoff.d.ts.map +1 -0
  12. package/dist/cjs/src/backoff/exponentialbackoff.js +81 -0
  13. package/dist/cjs/src/backoff/exponentialbackoff.js.map +1 -0
  14. package/dist/cjs/src/backoff/linearbackoff.d.ts +51 -0
  15. package/dist/cjs/src/backoff/linearbackoff.d.ts.map +1 -0
  16. package/dist/cjs/src/backoff/linearbackoff.js +89 -0
  17. package/dist/cjs/src/backoff/linearbackoff.js.map +1 -0
  18. package/dist/cjs/src/index.d.ts +14 -0
  19. package/dist/cjs/src/index.d.ts.map +1 -0
  20. package/dist/cjs/src/index.js +20 -0
  21. package/dist/cjs/src/index.js.map +1 -0
  22. package/dist/cjs/src/queue/array_queue.d.ts +17 -0
  23. package/dist/cjs/src/queue/array_queue.d.ts.map +1 -0
  24. package/dist/cjs/src/queue/array_queue.js +36 -0
  25. package/dist/cjs/src/queue/array_queue.js.map +1 -0
  26. package/dist/cjs/src/queue/queue.d.ts +41 -0
  27. package/dist/cjs/src/queue/queue.d.ts.map +1 -0
  28. package/{lib/buffer/buffer.js → dist/cjs/src/queue/queue.js} +1 -1
  29. package/dist/cjs/src/queue/queue.js.map +1 -0
  30. package/dist/cjs/src/queue/ring_queue.d.ts +20 -0
  31. package/dist/cjs/src/queue/ring_queue.d.ts.map +1 -0
  32. package/dist/cjs/src/queue/ring_queue.js +57 -0
  33. package/dist/cjs/src/queue/ring_queue.js.map +1 -0
  34. package/dist/cjs/src/websocket.d.ts +206 -0
  35. package/dist/cjs/src/websocket.d.ts.map +1 -0
  36. package/dist/cjs/src/websocket.js +434 -0
  37. package/dist/cjs/src/websocket.js.map +1 -0
  38. package/dist/cjs/src/websocket_buffer.d.ts +16 -0
  39. package/dist/cjs/src/websocket_buffer.d.ts.map +1 -0
  40. package/dist/cjs/src/websocket_buffer.js +3 -0
  41. package/dist/cjs/src/websocket_buffer.js.map +1 -0
  42. package/dist/cjs/src/websocket_builder.d.ts +147 -0
  43. package/dist/cjs/src/websocket_builder.d.ts.map +1 -0
  44. package/dist/cjs/src/websocket_builder.js +263 -0
  45. package/dist/cjs/src/websocket_builder.js.map +1 -0
  46. package/dist/cjs/src/websocket_event.d.ts +67 -0
  47. package/dist/cjs/src/websocket_event.d.ts.map +1 -0
  48. package/dist/cjs/src/websocket_event.js +22 -0
  49. package/dist/cjs/src/websocket_event.js.map +1 -0
  50. package/dist/cjs/src/websocket_options.d.ts +21 -0
  51. package/dist/cjs/src/websocket_options.d.ts.map +1 -0
  52. package/dist/cjs/src/websocket_options.js +3 -0
  53. package/dist/cjs/src/websocket_options.js.map +1 -0
  54. package/dist/cjs/src/websocket_retry_options.d.ts +20 -0
  55. package/dist/cjs/src/websocket_retry_options.d.ts.map +1 -0
  56. package/dist/cjs/src/websocket_retry_options.js +3 -0
  57. package/dist/cjs/src/websocket_retry_options.js.map +1 -0
  58. package/dist/esm/src/backoff/backoff.d.ts +24 -0
  59. package/dist/esm/src/backoff/backoff.d.ts.map +1 -0
  60. package/dist/esm/src/backoff/backoff.js +2 -0
  61. package/dist/esm/src/backoff/backoff.js.map +1 -0
  62. package/dist/esm/src/backoff/constantbackoff.d.ts +18 -0
  63. package/dist/esm/src/backoff/constantbackoff.d.ts.map +1 -0
  64. package/dist/esm/src/backoff/constantbackoff.js +30 -0
  65. package/dist/esm/src/backoff/constantbackoff.js.map +1 -0
  66. package/dist/esm/src/backoff/exponentialbackoff.d.ts +48 -0
  67. package/dist/esm/src/backoff/exponentialbackoff.d.ts.map +1 -0
  68. package/dist/esm/src/backoff/exponentialbackoff.js +68 -0
  69. package/dist/esm/src/backoff/exponentialbackoff.js.map +1 -0
  70. package/dist/esm/src/backoff/linearbackoff.d.ts +51 -0
  71. package/dist/esm/src/backoff/linearbackoff.d.ts.map +1 -0
  72. package/dist/esm/src/backoff/linearbackoff.js +76 -0
  73. package/dist/esm/src/backoff/linearbackoff.js.map +1 -0
  74. package/dist/esm/src/index.d.ts +14 -0
  75. package/dist/esm/src/index.d.ts.map +1 -0
  76. package/dist/esm/src/index.js +9 -0
  77. package/dist/esm/src/index.js.map +1 -0
  78. package/dist/esm/src/queue/array_queue.d.ts +17 -0
  79. package/dist/esm/src/queue/array_queue.d.ts.map +1 -0
  80. package/dist/esm/src/queue/array_queue.js +31 -0
  81. package/dist/esm/src/queue/array_queue.js.map +1 -0
  82. package/dist/esm/src/queue/queue.d.ts +41 -0
  83. package/dist/esm/src/queue/queue.d.ts.map +1 -0
  84. package/dist/esm/src/queue/queue.js +2 -0
  85. package/dist/esm/src/queue/queue.js.map +1 -0
  86. package/dist/esm/src/queue/ring_queue.d.ts +20 -0
  87. package/dist/esm/src/queue/ring_queue.d.ts.map +1 -0
  88. package/dist/esm/src/queue/ring_queue.js +52 -0
  89. package/dist/esm/src/queue/ring_queue.js.map +1 -0
  90. package/dist/esm/src/websocket.d.ts +206 -0
  91. package/dist/esm/src/websocket.d.ts.map +1 -0
  92. package/dist/esm/src/websocket.js +356 -0
  93. package/dist/esm/src/websocket.js.map +1 -0
  94. package/dist/esm/src/websocket_buffer.d.ts +16 -0
  95. package/dist/esm/src/websocket_buffer.d.ts.map +1 -0
  96. package/dist/esm/src/websocket_buffer.js +2 -0
  97. package/dist/esm/src/websocket_buffer.js.map +1 -0
  98. package/dist/esm/src/websocket_builder.d.ts +147 -0
  99. package/dist/esm/src/websocket_builder.d.ts.map +1 -0
  100. package/dist/esm/src/websocket_builder.js +213 -0
  101. package/dist/esm/src/websocket_builder.js.map +1 -0
  102. package/dist/esm/src/websocket_event.d.ts +67 -0
  103. package/dist/esm/src/websocket_event.d.ts.map +1 -0
  104. package/dist/esm/src/websocket_event.js +19 -0
  105. package/dist/esm/src/websocket_event.js.map +1 -0
  106. package/dist/esm/src/websocket_options.d.ts +21 -0
  107. package/dist/esm/src/websocket_options.d.ts.map +1 -0
  108. package/dist/esm/src/websocket_options.js +2 -0
  109. package/dist/esm/src/websocket_options.js.map +1 -0
  110. package/dist/esm/src/websocket_retry_options.d.ts +20 -0
  111. package/dist/esm/src/websocket_retry_options.d.ts.map +1 -0
  112. package/dist/esm/src/websocket_retry_options.js +2 -0
  113. package/dist/esm/src/websocket_retry_options.js.map +1 -0
  114. package/package.json +27 -14
  115. package/src/backoff/backoff.ts +21 -13
  116. package/src/backoff/constantbackoff.ts +29 -11
  117. package/src/backoff/exponentialbackoff.ts +68 -28
  118. package/src/backoff/linearbackoff.ts +77 -26
  119. package/src/index.ts +23 -9
  120. package/src/queue/array_queue.ts +41 -0
  121. package/src/queue/queue.ts +46 -0
  122. package/src/queue/ring_queue.ts +69 -0
  123. package/src/websocket.ts +463 -138
  124. package/src/websocket_buffer.ts +18 -0
  125. package/src/websocket_builder.ts +274 -0
  126. package/src/websocket_event.ts +88 -0
  127. package/src/websocket_options.ts +23 -0
  128. package/src/websocket_retry_options.ts +22 -0
  129. package/{tsconfig.json → tsconfig.cjs.json} +8 -8
  130. package/tsconfig.esm.json +71 -0
  131. package/jest.config.js +0 -9
  132. package/lib/backoff/backoff.d.ts +0 -18
  133. package/lib/backoff/backoff.d.ts.map +0 -1
  134. package/lib/backoff/constantbackoff.d.ts +0 -11
  135. package/lib/backoff/constantbackoff.d.ts.map +0 -1
  136. package/lib/backoff/constantbackoff.js +0 -20
  137. package/lib/backoff/constantbackoff.js.map +0 -1
  138. package/lib/backoff/exponentialbackoff.d.ts +0 -22
  139. package/lib/backoff/exponentialbackoff.d.ts.map +0 -1
  140. package/lib/backoff/exponentialbackoff.js +0 -35
  141. package/lib/backoff/exponentialbackoff.js.map +0 -1
  142. package/lib/backoff/linearbackoff.d.ts +0 -19
  143. package/lib/backoff/linearbackoff.d.ts.map +0 -1
  144. package/lib/backoff/linearbackoff.js +0 -34
  145. package/lib/backoff/linearbackoff.js.map +0 -1
  146. package/lib/buffer/buffer.d.ts +0 -41
  147. package/lib/buffer/buffer.d.ts.map +0 -1
  148. package/lib/buffer/buffer.js.map +0 -1
  149. package/lib/buffer/lrubuffer.d.ts +0 -24
  150. package/lib/buffer/lrubuffer.d.ts.map +0 -1
  151. package/lib/buffer/lrubuffer.js +0 -76
  152. package/lib/buffer/lrubuffer.js.map +0 -1
  153. package/lib/buffer/timebuffer.d.ts +0 -25
  154. package/lib/buffer/timebuffer.d.ts.map +0 -1
  155. package/lib/buffer/timebuffer.js +0 -92
  156. package/lib/buffer/timebuffer.js.map +0 -1
  157. package/lib/index.d.ts +0 -10
  158. package/lib/index.d.ts.map +0 -1
  159. package/lib/index.js +0 -22
  160. package/lib/index.js.map +0 -1
  161. package/lib/websocket.d.ts +0 -47
  162. package/lib/websocket.d.ts.map +0 -1
  163. package/lib/websocket.js +0 -120
  164. package/lib/websocket.js.map +0 -1
  165. package/lib/websocketBuilder.d.ts +0 -32
  166. package/lib/websocketBuilder.d.ts.map +0 -1
  167. package/lib/websocketBuilder.js +0 -68
  168. package/lib/websocketBuilder.js.map +0 -1
  169. package/src/buffer/buffer.ts +0 -45
  170. package/src/buffer/lrubuffer.ts +0 -80
  171. package/src/buffer/timebuffer.ts +0 -105
  172. package/src/websocketBuilder.ts +0 -98
  173. package/test/backoff/constantbackoff.test.ts +0 -21
  174. package/test/backoff/exponentialbackoff.test.ts +0 -13
  175. package/test/backoff/linearbackoff.test.ts +0 -32
  176. package/test/buffer/common.ts +0 -10
  177. package/test/buffer/lrubuffer.test.ts +0 -128
  178. package/test/buffer/timebuffer.test.ts +0 -115
  179. package/test/websocket.test.ts +0 -341
  180. package/test/websocketBuilder.test.ts +0 -36
  181. /package/{lib → dist/cjs/src}/backoff/backoff.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exponentialbackoff.js","sourceRoot":"","sources":["../../../../src/backoff/exponentialbackoff.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,OAAO,kBAAkB;IAM7B;;;;OAIG;IACH,YAAY,IAAY,EAAE,MAAe;QAPjC,aAAQ,GAAW,CAAC,CAAC;QAQ3B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC5D;QACD,IAAI,MAAM,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,EAAE;YACrE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;SAC3E;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,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,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ import { Backoff } from "./backoff";
2
+ /**
3
+ * LinearBackoff returns a backoff-time that is incremented by a fixed amount
4
+ * with every step/retry. An optional maximum can be provided as an upper bound
5
+ * to the returned backoff.
6
+ *
7
+ * The series can be described as ('i' is the current step/retry):
8
+ * backoff = initial + increment * i | without bound
9
+ * backoff = initial + increment * min(i, max) | with bound
10
+ *
11
+ * Example:
12
+ *
13
+ * 1) Without bound:
14
+ * initial = 1000, increment = 1000
15
+ * backoff = 1000 + 1000 * 0 = 1000 // first retry
16
+ * backoff = 1000 + 1000 * 1 = 2000 // second retry
17
+ * backoff = 1000 + 1000 * 2 = 3000 // ...increases by 'increment' with every retry
18
+ * backoff = 1000 + 1000 * 3 = 4000
19
+ * backoff = 1000 + 1000 * 4 = 5000
20
+ * ... // and so on
21
+ *
22
+ * 2) With bound:
23
+ * initial = 1000, increment = 1000, max = 5000
24
+ * backoff = 1000 + 1000 * 0 = 1000 // first retry
25
+ * backoff = 1000 + 1000 * 1 = 2000 // second retry
26
+ * backoff = 1000 + 1000 * 2 = 3000 // third retry
27
+ * backoff = 1000 + 1000 * 3 = 4000 // fourth retry
28
+ * backoff = 1000 + 1000 * 4 = 5000 // maximum reached, don't increase further
29
+ * backoff = 1000 + 1000 * 4 = 5000
30
+ * backoff = 1000 + 1000 * 4 = 5000
31
+ * ... // and so on
32
+ */
33
+ export declare class LinearBackoff implements Backoff {
34
+ private readonly initial;
35
+ private readonly increment;
36
+ private readonly max?;
37
+ private i;
38
+ private _retries;
39
+ /**
40
+ * Creates a new LinearBackoff.
41
+ * @param initial the initial backoff-time in milliseconds
42
+ * @param increment the amount to increment the backoff-time with every step (in milliseconds)
43
+ * @param max the maximum backoff-time (in milliseconds), no bound if undefined
44
+ */
45
+ constructor(initial: number, increment: number, max?: number);
46
+ get retries(): number;
47
+ get current(): number;
48
+ next(): number;
49
+ reset(): void;
50
+ }
51
+ //# sourceMappingURL=linearbackoff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linearbackoff.d.ts","sourceRoot":"","sources":["../../../../src/backoff/linearbackoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;IAMd,KAAK,IAAI,IAAI;CAId"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * LinearBackoff returns a backoff-time that is incremented by a fixed amount
3
+ * with every step/retry. An optional maximum can be provided as an upper bound
4
+ * to the returned backoff.
5
+ *
6
+ * The series can be described as ('i' is the current step/retry):
7
+ * backoff = initial + increment * i | without bound
8
+ * backoff = initial + increment * min(i, max) | with bound
9
+ *
10
+ * Example:
11
+ *
12
+ * 1) Without bound:
13
+ * initial = 1000, increment = 1000
14
+ * backoff = 1000 + 1000 * 0 = 1000 // first retry
15
+ * backoff = 1000 + 1000 * 1 = 2000 // second retry
16
+ * backoff = 1000 + 1000 * 2 = 3000 // ...increases by 'increment' with every retry
17
+ * backoff = 1000 + 1000 * 3 = 4000
18
+ * backoff = 1000 + 1000 * 4 = 5000
19
+ * ... // and so on
20
+ *
21
+ * 2) With bound:
22
+ * initial = 1000, increment = 1000, max = 5000
23
+ * backoff = 1000 + 1000 * 0 = 1000 // first retry
24
+ * backoff = 1000 + 1000 * 1 = 2000 // second retry
25
+ * backoff = 1000 + 1000 * 2 = 3000 // third retry
26
+ * backoff = 1000 + 1000 * 3 = 4000 // fourth retry
27
+ * backoff = 1000 + 1000 * 4 = 5000 // maximum reached, don't increase further
28
+ * backoff = 1000 + 1000 * 4 = 5000
29
+ * backoff = 1000 + 1000 * 4 = 5000
30
+ * ... // and so on
31
+ */
32
+ export class LinearBackoff {
33
+ /**
34
+ * Creates a new LinearBackoff.
35
+ * @param initial the initial backoff-time in milliseconds
36
+ * @param increment the amount to increment the backoff-time with every step (in milliseconds)
37
+ * @param max the maximum backoff-time (in milliseconds), no bound if undefined
38
+ */
39
+ constructor(initial, increment, max) {
40
+ this.i = 0;
41
+ this._retries = 0;
42
+ if (initial < 0) {
43
+ throw new Error("Initial must be a positive number or zero");
44
+ }
45
+ if (increment < 0) {
46
+ throw new Error("Increment must be a positive number or zero");
47
+ }
48
+ if (max !== undefined && max < 0) {
49
+ throw new Error("Max must be undefined, a positive number or zero");
50
+ }
51
+ if (max !== undefined && max < initial) {
52
+ throw new Error("Max must be undefined or greater than or equal to initial");
53
+ }
54
+ this.initial = initial;
55
+ this.increment = increment;
56
+ this.max = max;
57
+ }
58
+ get retries() {
59
+ return this._retries;
60
+ }
61
+ get current() {
62
+ return this.max === undefined
63
+ ? this.initial + this.increment * this.i
64
+ : Math.min(this.initial + this.increment * this.i, this.max);
65
+ }
66
+ next() {
67
+ this._retries++;
68
+ this.i++;
69
+ return this.current;
70
+ }
71
+ reset() {
72
+ this._retries = 0;
73
+ this.i = 0;
74
+ }
75
+ }
76
+ //# sourceMappingURL=linearbackoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linearbackoff.js","sourceRoot":"","sources":["../../../../src/backoff/linearbackoff.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,aAAa;IAOxB;;;;;OAKG;IACH,YAAY,OAAe,EAAE,SAAiB,EAAE,GAAY;QATpD,MAAC,GAAW,CAAC,CAAC;QACd,aAAQ,GAAW,CAAC,CAAC;QAS3B,IAAI,OAAO,GAAG,CAAC,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;SAC9D;QACD,IAAI,SAAS,GAAG,CAAC,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;SAChE;QACD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;SACrE;QACD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,GAAG,OAAO,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;SACH;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,IAAI,CAAC,QAAQ,EAAE,CAAC;QAChB,IAAI,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAClB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ export { Backoff } from "./backoff/backoff";
2
+ export { ConstantBackoff } from "./backoff/constantbackoff";
3
+ export { ExponentialBackoff } from "./backoff/exponentialbackoff";
4
+ export { LinearBackoff } from "./backoff/linearbackoff";
5
+ export { Queue } from "./queue/queue";
6
+ export { ArrayQueue } from "./queue/array_queue";
7
+ export { RingQueue } from "./queue/ring_queue";
8
+ export { Websocket } from "./websocket";
9
+ export { WebsocketBuffer } from "./websocket_buffer";
10
+ export { WebsocketBuilder } from "./websocket_builder";
11
+ export { WebsocketEvent, RetryEventDetail, ReconnectEventDetail, WebsocketEventMap, WebsocketEventListener, WebsocketEventListenerParams, WebsocketEventListenerOptions, WebsocketEventListenerWithOptions, WebsocketEventListeners, } from "./websocket_event";
12
+ export { WebsocketOptions } from "./websocket_options";
13
+ export { WebsocketConnectionRetryOptions } from "./websocket_retry_options";
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,mBAAmB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,iBAAiB,EACjB,sBAAsB,EACtB,4BAA4B,EAC5B,6BAA6B,EAC7B,iCAAiC,EACjC,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { ConstantBackoff } from "./backoff/constantbackoff";
2
+ export { ExponentialBackoff } from "./backoff/exponentialbackoff";
3
+ export { LinearBackoff } from "./backoff/linearbackoff";
4
+ export { ArrayQueue } from "./queue/array_queue";
5
+ export { RingQueue } from "./queue/ring_queue";
6
+ export { Websocket } from "./websocket";
7
+ export { WebsocketBuilder } from "./websocket_builder";
8
+ export { WebsocketEvent, } from "./websocket_event";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EACL,cAAc,GASf,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { Queue } from "./queue";
2
+ /**
3
+ * An array queue is a queue that has an unbounded capacity. Reading from an array queue
4
+ * will return the oldest element and effectively remove it from the queue.
5
+ */
6
+ export declare class ArrayQueue<E> implements Queue<E> {
7
+ private readonly elements;
8
+ constructor();
9
+ add(element: E): void;
10
+ clear(): void;
11
+ forEach(fn: (element: E) => unknown): void;
12
+ length(): number;
13
+ isEmpty(): boolean;
14
+ peek(): E | undefined;
15
+ read(): E | undefined;
16
+ }
17
+ //# sourceMappingURL=array_queue.d.ts.map
@@ -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,SAAS,CAAC;AAEhC;;;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"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * An array queue is a queue that has an unbounded capacity. Reading from an array queue
3
+ * will return the oldest element and effectively remove it from the queue.
4
+ */
5
+ export class ArrayQueue {
6
+ constructor() {
7
+ this.elements = [];
8
+ }
9
+ add(element) {
10
+ this.elements.push(element);
11
+ }
12
+ clear() {
13
+ this.elements.length = 0;
14
+ }
15
+ forEach(fn) {
16
+ this.elements.forEach(fn);
17
+ }
18
+ length() {
19
+ return this.elements.length;
20
+ }
21
+ isEmpty() {
22
+ return this.elements.length === 0;
23
+ }
24
+ peek() {
25
+ return this.elements[0];
26
+ }
27
+ read() {
28
+ return this.elements.shift();
29
+ }
30
+ }
31
+ //# 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,MAAM,OAAO,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"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * A queue holds elements until they are read. The order in which elements are
3
+ * read is determined by the implementation of the queue.
4
+ */
5
+ export interface Queue<E> {
6
+ /**
7
+ * Adds an element to the queue.
8
+ * @param element the element to add
9
+ */
10
+ add(element: E): void;
11
+ /**
12
+ * Clears the queue, removing all elements.
13
+ */
14
+ clear(): void;
15
+ /**
16
+ * Calls the given function for each element in the queue.
17
+ * @param fn the function to call
18
+ */
19
+ forEach(fn: (element: E) => unknown): void;
20
+ /**
21
+ * Number of elements in the queue.
22
+ * @return the number of elements in the queue
23
+ */
24
+ length(): number;
25
+ /**
26
+ * Whether the queue is empty.
27
+ * @return true if the queue is empty, false otherwise
28
+ */
29
+ isEmpty(): boolean;
30
+ /**
31
+ * Returns the next element in the queue without removing it.
32
+ * @return the next element in the queue, or undefined if the queue is empty
33
+ */
34
+ peek(): E | undefined;
35
+ /**
36
+ * Removes and returns the next element in the queue.
37
+ * @return the next element in the queue, or undefined if the queue is empty
38
+ */
39
+ read(): E | undefined;
40
+ }
41
+ //# sourceMappingURL=queue.d.ts.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../../../../src/queue/queue.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { Queue } from "./queue";
2
+ /**
3
+ * A ring queue is a queue that has a fixed capacity. When the queue is full, the oldest element is
4
+ * removed to make room for the new element. Reading from a ring queue will return the oldest
5
+ * element and effectively remove it from the queue.
6
+ */
7
+ export declare class RingQueue<E> implements Queue<E> {
8
+ private readonly elements;
9
+ private head;
10
+ private tail;
11
+ constructor(capacity: number);
12
+ add(element: E): void;
13
+ clear(): void;
14
+ forEach(fn: (element: E) => unknown): void;
15
+ length(): number;
16
+ isEmpty(): boolean;
17
+ peek(): E | undefined;
18
+ read(): E | undefined;
19
+ }
20
+ //# sourceMappingURL=ring_queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ring_queue.d.ts","sourceRoot":"","sources":["../../../../src/queue/ring_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;GAIG;AACH,qBAAa,SAAS,CAAC,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAC/B,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,IAAI,CAAS;gBAET,QAAQ,EAAE,MAAM;IAU5B,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;IAQrB,KAAK;IAKL,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,OAAO;IAUnC,MAAM,IAAI,MAAM;IAQhB,OAAO,IAAI,OAAO;IAIlB,IAAI,IAAI,CAAC,GAAG,SAAS;IAIrB,IAAI,IAAI,CAAC,GAAG,SAAS;CAOtB"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A ring queue is a queue that has a fixed capacity. When the queue is full, the oldest element is
3
+ * removed to make room for the new element. Reading from a ring queue will return the oldest
4
+ * element and effectively remove it from the queue.
5
+ */
6
+ export class RingQueue {
7
+ constructor(capacity) {
8
+ if (!Number.isInteger(capacity) || capacity <= 0) {
9
+ throw new Error("Capacity must be a positive integer");
10
+ }
11
+ this.elements = new Array(capacity + 1); // +1 to distinguish between full and empty
12
+ this.head = 0;
13
+ this.tail = 0;
14
+ }
15
+ add(element) {
16
+ this.elements[this.head] = element;
17
+ this.head = (this.head + 1) % this.elements.length;
18
+ if (this.head === this.tail) {
19
+ this.tail = (this.tail + 1) % this.elements.length;
20
+ }
21
+ }
22
+ clear() {
23
+ this.head = 0;
24
+ this.tail = 0;
25
+ }
26
+ forEach(fn) {
27
+ for (let i = this.tail; i !== this.head; i = (i + 1) % this.elements.length) {
28
+ fn(this.elements[i]);
29
+ }
30
+ }
31
+ length() {
32
+ return this.tail === this.head
33
+ ? 0
34
+ : this.tail < this.head
35
+ ? this.head - this.tail
36
+ : this.elements.length - this.tail + this.head;
37
+ }
38
+ isEmpty() {
39
+ return this.head === this.tail;
40
+ }
41
+ peek() {
42
+ return this.isEmpty() ? undefined : this.elements[this.tail];
43
+ }
44
+ read() {
45
+ const e = this.peek();
46
+ if (e !== undefined) {
47
+ this.tail = (this.tail + 1) % this.elements.length;
48
+ }
49
+ return e;
50
+ }
51
+ }
52
+ //# sourceMappingURL=ring_queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ring_queue.js","sourceRoot":"","sources":["../../../../src/queue/ring_queue.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAKpB,YAAY,QAAgB;QAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,QAAQ,IAAI,CAAC,EAAE;YAChD,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SACxD;QAED,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,CAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,2CAA2C;QACvF,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACd,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;IAChB,CAAC;IAED,GAAG,CAAC,OAAU;QACZ,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAA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AI,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,KAAK,SAAS,EAAE;YACnB,IAAI,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;SACpD;QACD,OAAO,CAAC,CAAC;IACX,CAAC;CACF"}
@@ -0,0 +1,206 @@
1
+ import { Backoff } from "./backoff/backoff";
2
+ import { WebsocketBuffer } from "./websocket_buffer";
3
+ import { WebsocketEvent, WebsocketEventListener, WebsocketEventListenerOptions } from "./websocket_event";
4
+ import { WebsocketOptions } from "./websocket_options";
5
+ /**
6
+ * A websocket wrapper that can be configured to reconnect automatically and buffer messages when the websocket is not connected.
7
+ */
8
+ export declare class Websocket {
9
+ private readonly _url;
10
+ private readonly _protocols?;
11
+ private _closedByUser;
12
+ private _lastConnection?;
13
+ private _underlyingWebsocket;
14
+ private retryTimeout?;
15
+ private _options;
16
+ /**
17
+ * Creates a new websocket.
18
+ *
19
+ * @param url to connect to.
20
+ * @param protocols optional protocols to use.
21
+ * @param options optional options to use.
22
+ */
23
+ constructor(url: string, protocols?: string | string[], options?: WebsocketOptions);
24
+ /**
25
+ * Getter for the url.
26
+ *
27
+ * @return the url.
28
+ */
29
+ get url(): string;
30
+ /**
31
+ * Getter for the protocols.
32
+ *
33
+ * @return the protocols, or undefined if none were provided.
34
+ */
35
+ get protocols(): string | string[] | undefined;
36
+ /**
37
+ * Getter for the buffer.
38
+ *
39
+ * @return the buffer, or undefined if none was provided.
40
+ */
41
+ get buffer(): WebsocketBuffer | undefined;
42
+ /**
43
+ * Getter for the maxRetries.
44
+ *
45
+ * @return the maxRetries, or undefined if none was provided (no limit).
46
+ */
47
+ get maxRetries(): number | undefined;
48
+ /**
49
+ * Getter for the instantReconnect.
50
+ *
51
+ * @return the instantReconnect, or undefined if none was provided.
52
+ */
53
+ get instantReconnect(): boolean | undefined;
54
+ /**
55
+ * Getter for the backoff.
56
+ *
57
+ * @return the backoff, or undefined if none was provided.
58
+ */
59
+ get backoff(): Backoff | undefined;
60
+ /**
61
+ * Whether the websocket was closed by the user. A websocket is closed by the user if the close().
62
+ *
63
+ * @return true if the websocket was closed by the user, false otherwise.
64
+ */
65
+ get closedByUser(): boolean;
66
+ /**
67
+ * Getter for the last 'open' event, e.g. the last time the websocket was connected.
68
+ *
69
+ * @return the last 'open' event, or undefined if the websocket was never connected.
70
+ */
71
+ get lastConnection(): Date | undefined;
72
+ /**
73
+ * Getter for the underlying websocket. This can be used to access the browser's native websocket directly.
74
+ *
75
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
76
+ * @return the underlying websocket.
77
+ */
78
+ get underlyingWebsocket(): WebSocket;
79
+ /**
80
+ * Getter for the readyState of the underlying websocket.
81
+ *
82
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState
83
+ * @return the readyState of the underlying websocket.
84
+ */
85
+ get readyState(): number;
86
+ /**
87
+ * Getter for the bufferedAmount of the underlying websocket.
88
+ *
89
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount
90
+ * @return the bufferedAmount of the underlying websocket.
91
+ */
92
+ get bufferedAmount(): number;
93
+ /**
94
+ * Getter for the extensions of the underlying websocket.
95
+ *
96
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions
97
+ * @return the extensions of the underlying websocket.
98
+ */
99
+ get extensions(): string;
100
+ /**
101
+ * Getter for the binaryType of the underlying websocket.
102
+ *
103
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType
104
+ * @return the binaryType of the underlying websocket.
105
+ */
106
+ get binaryType(): BinaryType;
107
+ /**
108
+ * Setter for the binaryType of the underlying websocket.
109
+ *
110
+ * @param value to set, 'blob' or 'arraybuffer'.
111
+ */
112
+ set binaryType(value: BinaryType);
113
+ /**
114
+ * Sends data over the websocket.
115
+ *
116
+ * If the websocket is not connected and a buffer was provided on creation, the data will be added to the buffer.
117
+ * If no buffer was provided or the websocket was closed by the user, the data will be dropped.
118
+ *
119
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
120
+ * @param data to send.
121
+ */
122
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
123
+ /**
124
+ * Close the websocket. No connection-retry will be attempted after this.
125
+ *
126
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
127
+ * @param code optional close code.
128
+ * @param reason optional close reason.
129
+ */
130
+ close(code?: number, reason?: string): void;
131
+ /**
132
+ * Adds an event listener for the given event-type.
133
+ *
134
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
135
+ * @param type of the event to add the listener for.
136
+ * @param listener to add.
137
+ * @param options to use when adding the listener.
138
+ */
139
+ addEventListener<K extends WebsocketEvent>(type: K, listener: WebsocketEventListener<K>, options?: WebsocketEventListenerOptions): void;
140
+ /**
141
+ * Removes one or more event listener for the given event-type that match the given listener and options.
142
+ *
143
+ * @param type of the event to remove the listener for.
144
+ * @param listener to remove.
145
+ * @param options that were used when the listener was added.
146
+ */
147
+ removeEventListener<K extends WebsocketEvent>(type: K, listener: WebsocketEventListener<K>, options?: WebsocketEventListenerOptions): void;
148
+ /**
149
+ * Creates a new browser-native websocket and connects it to the given URL with the given protocols
150
+ * and adds all event listeners to the browser-native websocket.
151
+ *
152
+ * @return the created browser-native websocket which is also stored in the '_underlyingWebsocket' property.
153
+ */
154
+ private tryConnect;
155
+ /**
156
+ * Removes all event listeners from the browser-native websocket and closes it.
157
+ */
158
+ private clearWebsocket;
159
+ /**
160
+ * Handles the 'open' event of the browser-native websocket.
161
+ * @param event to handle.
162
+ */
163
+ private handleOpenEvent;
164
+ /**
165
+ * Handles the 'error' event of the browser-native websocket.
166
+ * @param event to handle.
167
+ */
168
+ private handleErrorEvent;
169
+ /**
170
+ * Handles the 'close' event of the browser-native websocket.
171
+ * @param event to handle.
172
+ */
173
+ private handleCloseEvent;
174
+ /**
175
+ * Handles the 'message' event of the browser-native websocket.
176
+ * @param event to handle.
177
+ */
178
+ private handleMessageEvent;
179
+ /**
180
+ * Dispatch an event to all listeners of the given event-type.
181
+ *
182
+ * @param type of the event to dispatch.
183
+ * @param event to dispatch.
184
+ */
185
+ private dispatchEvent;
186
+ /**
187
+ * Handles the given event by dispatching it to all listeners of the given event-type.
188
+ *
189
+ * @param type of the event to handle.
190
+ * @param event to handle.
191
+ */
192
+ private handleEvent;
193
+ /**
194
+ * Sends buffered data if there is a buffer defined.
195
+ */
196
+ private sendBufferedData;
197
+ /**
198
+ * Schedules a connection-retry if there is a backoff defined and the websocket was not closed by the user.
199
+ */
200
+ private scheduleConnectionRetryIfNeeded;
201
+ /**
202
+ * Cancels the scheduled connection-retry, if there is one.
203
+ */
204
+ private cancelScheduledConnectionRetry;
205
+ }
206
+ //# sourceMappingURL=websocket.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../../src/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAGL,cAAc,EACd,sBAAsB,EACtB,6BAA6B,EAI9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAoB;IAEhD,OAAO,CAAC,aAAa,CAAkB;IACvC,OAAO,CAAC,eAAe,CAAC,CAAO;IAC/B,OAAO,CAAC,oBAAoB,CAAY;IACxC,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B,OAAO,CAAC,QAAQ,CAC0C;IAE1D;;;;;;OAMG;gBAED,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MA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