websocket-ts 2.1.1 → 2.1.3

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 (113) hide show
  1. package/dist/cjs/src/backoff/backoff.d.ts +24 -0
  2. package/dist/cjs/src/backoff/backoff.d.ts.map +1 -0
  3. package/dist/cjs/src/backoff/backoff.js +3 -0
  4. package/dist/cjs/src/backoff/backoff.js.map +1 -0
  5. package/dist/cjs/src/backoff/constantbackoff.d.ts +18 -0
  6. package/dist/cjs/src/backoff/constantbackoff.d.ts.map +1 -0
  7. package/dist/cjs/src/backoff/constantbackoff.js +43 -0
  8. package/dist/cjs/src/backoff/constantbackoff.js.map +1 -0
  9. package/dist/cjs/src/backoff/exponentialbackoff.d.ts +48 -0
  10. package/dist/cjs/src/backoff/exponentialbackoff.d.ts.map +1 -0
  11. package/dist/cjs/src/backoff/exponentialbackoff.js +81 -0
  12. package/dist/cjs/src/backoff/exponentialbackoff.js.map +1 -0
  13. package/dist/cjs/src/backoff/linearbackoff.d.ts +51 -0
  14. package/dist/cjs/src/backoff/linearbackoff.d.ts.map +1 -0
  15. package/dist/cjs/src/backoff/linearbackoff.js +89 -0
  16. package/dist/cjs/src/backoff/linearbackoff.js.map +1 -0
  17. package/dist/cjs/src/index.d.ts +14 -0
  18. package/dist/cjs/src/index.d.ts.map +1 -0
  19. package/dist/cjs/src/index.js +20 -0
  20. package/dist/cjs/src/index.js.map +1 -0
  21. package/dist/cjs/src/queue/array_queue.d.ts +17 -0
  22. package/dist/cjs/src/queue/array_queue.d.ts.map +1 -0
  23. package/dist/cjs/src/queue/array_queue.js +36 -0
  24. package/dist/cjs/src/queue/array_queue.js.map +1 -0
  25. package/dist/cjs/src/queue/queue.d.ts +41 -0
  26. package/dist/cjs/src/queue/queue.d.ts.map +1 -0
  27. package/dist/cjs/src/queue/queue.js +3 -0
  28. package/dist/cjs/src/queue/queue.js.map +1 -0
  29. package/dist/cjs/src/queue/ring_queue.d.ts +20 -0
  30. package/dist/cjs/src/queue/ring_queue.d.ts.map +1 -0
  31. package/dist/cjs/src/queue/ring_queue.js +57 -0
  32. package/dist/cjs/src/queue/ring_queue.js.map +1 -0
  33. package/dist/cjs/src/websocket.d.ts +206 -0
  34. package/dist/cjs/src/websocket.d.ts.map +1 -0
  35. package/dist/cjs/src/websocket.js +434 -0
  36. package/dist/cjs/src/websocket.js.map +1 -0
  37. package/dist/cjs/src/websocket_buffer.d.ts +16 -0
  38. package/dist/cjs/src/websocket_buffer.d.ts.map +1 -0
  39. package/dist/cjs/src/websocket_buffer.js +3 -0
  40. package/dist/cjs/src/websocket_buffer.js.map +1 -0
  41. package/dist/cjs/src/websocket_builder.d.ts +147 -0
  42. package/dist/cjs/src/websocket_builder.d.ts.map +1 -0
  43. package/dist/cjs/src/websocket_builder.js +263 -0
  44. package/dist/cjs/src/websocket_builder.js.map +1 -0
  45. package/dist/cjs/src/websocket_event.d.ts +67 -0
  46. package/dist/cjs/src/websocket_event.d.ts.map +1 -0
  47. package/dist/cjs/src/websocket_event.js +22 -0
  48. package/dist/cjs/src/websocket_event.js.map +1 -0
  49. package/dist/cjs/src/websocket_options.d.ts +21 -0
  50. package/dist/cjs/src/websocket_options.d.ts.map +1 -0
  51. package/dist/cjs/src/websocket_options.js +3 -0
  52. package/dist/cjs/src/websocket_options.js.map +1 -0
  53. package/dist/cjs/src/websocket_retry_options.d.ts +20 -0
  54. package/dist/cjs/src/websocket_retry_options.d.ts.map +1 -0
  55. package/dist/cjs/src/websocket_retry_options.js +3 -0
  56. package/dist/cjs/src/websocket_retry_options.js.map +1 -0
  57. package/dist/esm/src/backoff/backoff.d.ts +24 -0
  58. package/dist/esm/src/backoff/backoff.d.ts.map +1 -0
  59. package/dist/esm/src/backoff/backoff.js +2 -0
  60. package/dist/esm/src/backoff/backoff.js.map +1 -0
  61. package/dist/esm/src/backoff/constantbackoff.d.ts +18 -0
  62. package/dist/esm/src/backoff/constantbackoff.d.ts.map +1 -0
  63. package/dist/esm/src/backoff/constantbackoff.js +30 -0
  64. package/dist/esm/src/backoff/constantbackoff.js.map +1 -0
  65. package/dist/esm/src/backoff/exponentialbackoff.d.ts +48 -0
  66. package/dist/esm/src/backoff/exponentialbackoff.d.ts.map +1 -0
  67. package/dist/esm/src/backoff/exponentialbackoff.js +68 -0
  68. package/dist/esm/src/backoff/exponentialbackoff.js.map +1 -0
  69. package/dist/esm/src/backoff/linearbackoff.d.ts +51 -0
  70. package/dist/esm/src/backoff/linearbackoff.d.ts.map +1 -0
  71. package/dist/esm/src/backoff/linearbackoff.js +76 -0
  72. package/dist/esm/src/backoff/linearbackoff.js.map +1 -0
  73. package/dist/esm/src/index.d.ts +14 -0
  74. package/dist/esm/src/index.d.ts.map +1 -0
  75. package/dist/esm/src/index.js +9 -0
  76. package/dist/esm/src/index.js.map +1 -0
  77. package/dist/esm/src/queue/array_queue.d.ts +17 -0
  78. package/dist/esm/src/queue/array_queue.d.ts.map +1 -0
  79. package/dist/esm/src/queue/array_queue.js +31 -0
  80. package/dist/esm/src/queue/array_queue.js.map +1 -0
  81. package/dist/esm/src/queue/queue.d.ts +41 -0
  82. package/dist/esm/src/queue/queue.d.ts.map +1 -0
  83. package/dist/esm/src/queue/queue.js +2 -0
  84. package/dist/esm/src/queue/queue.js.map +1 -0
  85. package/dist/esm/src/queue/ring_queue.d.ts +20 -0
  86. package/dist/esm/src/queue/ring_queue.d.ts.map +1 -0
  87. package/dist/esm/src/queue/ring_queue.js +52 -0
  88. package/dist/esm/src/queue/ring_queue.js.map +1 -0
  89. package/dist/esm/src/websocket.d.ts +206 -0
  90. package/dist/esm/src/websocket.d.ts.map +1 -0
  91. package/dist/esm/src/websocket.js +356 -0
  92. package/dist/esm/src/websocket.js.map +1 -0
  93. package/dist/esm/src/websocket_buffer.d.ts +16 -0
  94. package/dist/esm/src/websocket_buffer.d.ts.map +1 -0
  95. package/dist/esm/src/websocket_buffer.js +2 -0
  96. package/dist/esm/src/websocket_buffer.js.map +1 -0
  97. package/dist/esm/src/websocket_builder.d.ts +147 -0
  98. package/dist/esm/src/websocket_builder.d.ts.map +1 -0
  99. package/dist/esm/src/websocket_builder.js +213 -0
  100. package/dist/esm/src/websocket_builder.js.map +1 -0
  101. package/dist/esm/src/websocket_event.d.ts +67 -0
  102. package/dist/esm/src/websocket_event.d.ts.map +1 -0
  103. package/dist/esm/src/websocket_event.js +19 -0
  104. package/dist/esm/src/websocket_event.js.map +1 -0
  105. package/dist/esm/src/websocket_options.d.ts +21 -0
  106. package/dist/esm/src/websocket_options.d.ts.map +1 -0
  107. package/dist/esm/src/websocket_options.js +2 -0
  108. package/dist/esm/src/websocket_options.js.map +1 -0
  109. package/dist/esm/src/websocket_retry_options.d.ts +20 -0
  110. package/dist/esm/src/websocket_retry_options.d.ts.map +1 -0
  111. package/dist/esm/src/websocket_retry_options.js +2 -0
  112. package/dist/esm/src/websocket_retry_options.js.map +1 -0
  113. package/package.json +1 -1
@@ -0,0 +1,147 @@
1
+ import { Backoff } from "./backoff/backoff";
2
+ import { WebsocketEvent, WebsocketEventListener, WebsocketEventListenerOptions } from "./websocket_event";
3
+ import { Websocket } from "./websocket";
4
+ import { WebsocketBuffer } from "./websocket_buffer";
5
+ /**
6
+ * Builder for websockets.
7
+ */
8
+ export declare class WebsocketBuilder {
9
+ private readonly _url;
10
+ private _protocols?;
11
+ private _options?;
12
+ /**
13
+ * Creates a new WebsocketBuilder.
14
+ *
15
+ * @param url the url to connect to
16
+ */
17
+ constructor(url: string);
18
+ /**
19
+ * Getter for the url.
20
+ *
21
+ * @returns the url
22
+ */
23
+ get url(): string;
24
+ /**
25
+ * Adds protocols to the websocket. Subsequent calls to this method will override the previously set protocols.
26
+ *
27
+ * @param protocols the protocols to add
28
+ */
29
+ withProtocols(protocols: string | string[] | undefined): WebsocketBuilder;
30
+ /**
31
+ * Getter for the protocols.
32
+ *
33
+ * @returns the protocols, undefined if no protocols have been set
34
+ */
35
+ get protocols(): string | string[] | undefined;
36
+ /**
37
+ * Sets the maximum number of retries before giving up. No limit if undefined.
38
+ *
39
+ * @param maxRetries the maximum number of retries before giving up
40
+ */
41
+ withMaxRetries(maxRetries: number | undefined): WebsocketBuilder;
42
+ /**
43
+ * Getter for the maximum number of retries before giving up.
44
+ *
45
+ * @returns the maximum number of retries before giving up, undefined if no maximum has been set
46
+ */
47
+ get maxRetries(): number | undefined;
48
+ /**
49
+ * Sets wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
50
+ *
51
+ * @param instantReconnect wether to reconnect immediately after a connection has been lost
52
+ */
53
+ withInstantReconnect(instantReconnect: boolean | undefined): WebsocketBuilder;
54
+ /**
55
+ * Getter for wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
56
+ *
57
+ * @returns wether to reconnect immediately after a connection has been lost, undefined if no value has been set
58
+ */
59
+ get instantReconnect(): boolean | undefined;
60
+ /**
61
+ * Adds a backoff to the websocket. Subsequent calls to this method will override the previously set backoff.
62
+ *
63
+ * @param backoff the backoff to add
64
+ */
65
+ withBackoff(backoff: Backoff | undefined): WebsocketBuilder;
66
+ /**
67
+ * Getter for the backoff.
68
+ *
69
+ * @returns the backoff, undefined if no backoff has been set
70
+ */
71
+ get backoff(): Backoff | undefined;
72
+ /**
73
+ * Adds a buffer to the websocket. Subsequent calls to this method will override the previously set buffer.
74
+ *
75
+ * @param buffer the buffer to add
76
+ */
77
+ withBuffer(buffer: WebsocketBuffer | undefined): WebsocketBuilder;
78
+ /**
79
+ * Getter for the buffer.
80
+ *
81
+ * @returns the buffer, undefined if no buffer has been set
82
+ */
83
+ get buffer(): WebsocketBuffer | undefined;
84
+ /**
85
+ * Adds an 'open' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
86
+ * called in the order they were added.
87
+ *
88
+ * @param listener the listener to add
89
+ * @param options the listener options
90
+ */
91
+ onOpen(listener: WebsocketEventListener<WebsocketEvent.open>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
92
+ /**
93
+ * Adds an 'close' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
94
+ * called in the order they were added.
95
+ *
96
+ * @param listener the listener to add
97
+ * @param options the listener options
98
+ */
99
+ onClose(listener: WebsocketEventListener<WebsocketEvent.close>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
100
+ /**
101
+ * Adds an 'error' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
102
+ * called in the order they were added.
103
+ *
104
+ * @param listener the listener to add
105
+ * @param options the listener options
106
+ */
107
+ onError(listener: WebsocketEventListener<WebsocketEvent.error>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
108
+ /**
109
+ * Adds an 'message' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
110
+ * called in the order they were added.
111
+ *
112
+ * @param listener the listener to add
113
+ * @param options the listener options
114
+ */
115
+ onMessage(listener: WebsocketEventListener<WebsocketEvent.message>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
116
+ /**
117
+ * Adds an 'retry' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
118
+ * called in the order they were added.
119
+ *
120
+ * @param listener the listener to add
121
+ * @param options the listener options
122
+ */
123
+ onRetry(listener: WebsocketEventListener<WebsocketEvent.retry>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
124
+ /**
125
+ * Adds an 'reconnect' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
126
+ * called in the order they were added.
127
+ *
128
+ * @param listener the listener to add
129
+ * @param options the listener options
130
+ */
131
+ onReconnect(listener: WebsocketEventListener<WebsocketEvent.reconnect>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
132
+ /**
133
+ * Builds the websocket.
134
+ *
135
+ * @return a new websocket, with the set options
136
+ */
137
+ build(): Websocket;
138
+ /**
139
+ * Adds an event listener to the options.
140
+ *
141
+ * @param event the event to add the listener to
142
+ * @param listener the listener to add
143
+ * @param options the listener options
144
+ */
145
+ private addListener;
146
+ }
147
+ //# sourceMappingURL=websocket_builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3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AKxE;;;;OAIG;IACH,IAAI,MAAM,IAAI,eAAe,GAAG,SAAS,CAExC;IAED;;;;;;OAMG;IACI,MAAM,CACX,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,IAAI,CAAC,EACrD,OAAO,CAAC,EAAE,6BAA6B,GACtC,gBAAgB;IAKnB;;;;;;OAMG;IACI,OAAO,CACZ,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,KAAK,CAAC,EACtD,OAAO,CAAC,EAAE,6BAA6B,GACtC,gBAAgB;IAKnB;;;;;;OAMG;IACI,OAAO,CACZ,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,KAAK,CAAC,EACtD,OAAO,CAAC,EAAE,6BAA6B,GACtC,gBAAgB;IAKnB;;;;;;OAMG;IACI,SAAS,CACd,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,OAAO,CAAC,EACxD,OAAO,CAAC,EAAE,6BAA6B,GACtC,gBAAgB;IAKnB;;;;;;OAMG;IACI,OAAO,CACZ,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,KAAK,CAAC,EACtD,OAAO,CAAC,EAAE,6BAA6B,GACtC,gBAAgB;IAKnB;;;;;;OAMG;IACI,WAAW,CAChB,QAAQ,EAAE,sBAAsB,CAAC,cAAc,CAAC,SAAS,CAAC,EAC1D,OAAO,CAAC,EAAE,6BAA6B,GACtC,gBAAgB;IAKnB;;;;OAIG;IACI,KAAK,IAAI,SAAS;IAIzB;;;;;;OAMG;IACH,OAAO,CAAC,WAAW;CAsBpB"}
@@ -0,0 +1,213 @@
1
+ import { WebsocketEvent, } from "./websocket_event";
2
+ import { Websocket } from "./websocket";
3
+ /**
4
+ * Builder for websockets.
5
+ */
6
+ export class WebsocketBuilder {
7
+ /**
8
+ * Creates a new WebsocketBuilder.
9
+ *
10
+ * @param url the url to connect to
11
+ */
12
+ constructor(url) {
13
+ this._url = url;
14
+ }
15
+ /**
16
+ * Getter for the url.
17
+ *
18
+ * @returns the url
19
+ */
20
+ get url() {
21
+ return this._url;
22
+ }
23
+ /**
24
+ * Adds protocols to the websocket. Subsequent calls to this method will override the previously set protocols.
25
+ *
26
+ * @param protocols the protocols to add
27
+ */
28
+ withProtocols(protocols) {
29
+ this._protocols = protocols;
30
+ return this;
31
+ }
32
+ /**
33
+ * Getter for the protocols.
34
+ *
35
+ * @returns the protocols, undefined if no protocols have been set
36
+ */
37
+ get protocols() {
38
+ return this._protocols;
39
+ }
40
+ /**
41
+ * Sets the maximum number of retries before giving up. No limit if undefined.
42
+ *
43
+ * @param maxRetries the maximum number of retries before giving up
44
+ */
45
+ withMaxRetries(maxRetries) {
46
+ var _a;
47
+ this._options = Object.assign(Object.assign({}, this._options), { retry: Object.assign(Object.assign({}, (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry), { maxRetries }) });
48
+ return this;
49
+ }
50
+ /**
51
+ * Getter for the maximum number of retries before giving up.
52
+ *
53
+ * @returns the maximum number of retries before giving up, undefined if no maximum has been set
54
+ */
55
+ get maxRetries() {
56
+ var _a, _b;
57
+ return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry) === null || _b === void 0 ? void 0 : _b.maxRetries;
58
+ }
59
+ /**
60
+ * Sets wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
61
+ *
62
+ * @param instantReconnect wether to reconnect immediately after a connection has been lost
63
+ */
64
+ withInstantReconnect(instantReconnect) {
65
+ var _a;
66
+ this._options = Object.assign(Object.assign({}, this._options), { retry: Object.assign(Object.assign({}, (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry), { instantReconnect }) });
67
+ return this;
68
+ }
69
+ /**
70
+ * Getter for wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
71
+ *
72
+ * @returns wether to reconnect immediately after a connection has been lost, undefined if no value has been set
73
+ */
74
+ get instantReconnect() {
75
+ var _a, _b;
76
+ return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry) === null || _b === void 0 ? void 0 : _b.instantReconnect;
77
+ }
78
+ /**
79
+ * Adds a backoff to the websocket. Subsequent calls to this method will override the previously set backoff.
80
+ *
81
+ * @param backoff the backoff to add
82
+ */
83
+ withBackoff(backoff) {
84
+ var _a;
85
+ this._options = Object.assign(Object.assign({}, this._options), { retry: Object.assign(Object.assign({}, (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry), { backoff }) });
86
+ return this;
87
+ }
88
+ /**
89
+ * Getter for the backoff.
90
+ *
91
+ * @returns the backoff, undefined if no backoff has been set
92
+ */
93
+ get backoff() {
94
+ var _a, _b;
95
+ return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry) === null || _b === void 0 ? void 0 : _b.backoff;
96
+ }
97
+ /**
98
+ * Adds a buffer to the websocket. Subsequent calls to this method will override the previously set buffer.
99
+ *
100
+ * @param buffer the buffer to add
101
+ */
102
+ withBuffer(buffer) {
103
+ this._options = Object.assign(Object.assign({}, this._options), { buffer });
104
+ return this;
105
+ }
106
+ /**
107
+ * Getter for the buffer.
108
+ *
109
+ * @returns the buffer, undefined if no buffer has been set
110
+ */
111
+ get buffer() {
112
+ var _a;
113
+ return (_a = this._options) === null || _a === void 0 ? void 0 : _a.buffer;
114
+ }
115
+ /**
116
+ * Adds an 'open' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
117
+ * called in the order they were added.
118
+ *
119
+ * @param listener the listener to add
120
+ * @param options the listener options
121
+ */
122
+ onOpen(listener, options) {
123
+ this.addListener(WebsocketEvent.open, listener, options);
124
+ return this;
125
+ }
126
+ /**
127
+ * Adds an 'close' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
128
+ * called in the order they were added.
129
+ *
130
+ * @param listener the listener to add
131
+ * @param options the listener options
132
+ */
133
+ onClose(listener, options) {
134
+ this.addListener(WebsocketEvent.close, listener, options);
135
+ return this;
136
+ }
137
+ /**
138
+ * Adds an 'error' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
139
+ * called in the order they were added.
140
+ *
141
+ * @param listener the listener to add
142
+ * @param options the listener options
143
+ */
144
+ onError(listener, options) {
145
+ this.addListener(WebsocketEvent.error, listener, options);
146
+ return this;
147
+ }
148
+ /**
149
+ * Adds an 'message' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
150
+ * called in the order they were added.
151
+ *
152
+ * @param listener the listener to add
153
+ * @param options the listener options
154
+ */
155
+ onMessage(listener, options) {
156
+ this.addListener(WebsocketEvent.message, listener, options);
157
+ return this;
158
+ }
159
+ /**
160
+ * Adds an 'retry' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
161
+ * called in the order they were added.
162
+ *
163
+ * @param listener the listener to add
164
+ * @param options the listener options
165
+ */
166
+ onRetry(listener, options) {
167
+ this.addListener(WebsocketEvent.retry, listener, options);
168
+ return this;
169
+ }
170
+ /**
171
+ * Adds an 'reconnect' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
172
+ * called in the order they were added.
173
+ *
174
+ * @param listener the listener to add
175
+ * @param options the listener options
176
+ */
177
+ onReconnect(listener, options) {
178
+ this.addListener(WebsocketEvent.reconnect, listener, options);
179
+ return this;
180
+ }
181
+ /**
182
+ * Builds the websocket.
183
+ *
184
+ * @return a new websocket, with the set options
185
+ */
186
+ build() {
187
+ return new Websocket(this._url, this._protocols, this._options); // instantiate the websocket with the set options
188
+ }
189
+ /**
190
+ * Adds an event listener to the options.
191
+ *
192
+ * @param event the event to add the listener to
193
+ * @param listener the listener to add
194
+ * @param options the listener options
195
+ */
196
+ addListener(event, listener, options) {
197
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
198
+ this._options = Object.assign(Object.assign({}, this._options), { listeners: {
199
+ open: (_c = (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.listeners) === null || _b === void 0 ? void 0 : _b.open) !== null && _c !== void 0 ? _c : [],
200
+ close: (_f = (_e = (_d = this._options) === null || _d === void 0 ? void 0 : _d.listeners) === null || _e === void 0 ? void 0 : _e.close) !== null && _f !== void 0 ? _f : [],
201
+ error: (_j = (_h = (_g = this._options) === null || _g === void 0 ? void 0 : _g.listeners) === null || _h === void 0 ? void 0 : _h.error) !== null && _j !== void 0 ? _j : [],
202
+ message: (_m = (_l = (_k = this._options) === null || _k === void 0 ? void 0 : _k.listeners) === null || _l === void 0 ? void 0 : _l.message) !== null && _m !== void 0 ? _m : [],
203
+ retry: (_q = (_p = (_o = this._options) === null || _o === void 0 ? void 0 : _o.listeners) === null || _p === void 0 ? void 0 : _p.retry) !== null && _q !== void 0 ? _q : [],
204
+ reconnect: (_t = (_s = (_r = this._options) === null || _r === void 0 ? void 0 : _r.listeners) === null || _s === void 0 ? void 0 : _s.reconnect) !== null && _t !== void 0 ? _t : [],
205
+ [event]: [
206
+ ...((_w = (_v = (_u = this._options) === null || _u === void 0 ? void 0 : _u.listeners) === null || _v === void 0 ? void 0 : _v[event]) !== null && _w !== void 0 ? _w : []),
207
+ { listener, options },
208
+ ],
209
+ } });
210
+ return this;
211
+ }
212
+ }
213
+ //# sourceMappingURL=websocket_builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_builder.js","sourceRoot":"","sources":["../../../src/websocket_builder.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,GAGf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAIxC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAM3B;;;;OAIG;IACH,YAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACI,aAAa,CAClB,SAAwC;QAExC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,IAAI,SAAS;QACX,OAAO,I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C,CAAC,CAAC,iDAAiD;IACpH,CAAC;IAED;;;;;;OAMG;IACK,WAAW,CACjB,KAAqB,EACrB,QAAmC,EACnC,OAAuC;;QAEvC,IAAI,CAAC,QAAQ,mCACR,IAAI,CAAC,QAAQ,KAChB,SAAS,EAAE;gBACT,IAAI,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,IAAI,mCAAI,EAAE;gBAC1C,KAAK,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,KAAK,mCAAI,EAAE;gBAC5C,KAAK,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,KAAK,mCAAI,EAAE;gBAC5C,OAAO,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,OAAO,mCAAI,EAAE;gBAChD,KAAK,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,KAAK,mCAAI,EAAE;gBAC5C,SAAS,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,SAAS,mCAAI,EAAE;gBACpD,CAAC,KAAK,CAAC,EAAE;oBACP,GAAG,CAAC,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAG,KAAK,CAAC,mCAAI,EAAE,CAAC;oBAC5C,EAAE,QAAQ,EAAE,OAAO,EAAE;iBACtB;aACF,GACF,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,67 @@
1
+ import { Websocket } from "./websocket";
2
+ /**
3
+ * Events that can be fired by the websocket.
4
+ */
5
+ export declare enum WebsocketEvent {
6
+ /** Fired when the connection is opened. */
7
+ open = "open",
8
+ /** Fired when the connection is closed. */
9
+ close = "close",
10
+ /** Fired when the connection has been closed because of an error, such as when some data couldn't be sent. */
11
+ error = "error",
12
+ /** Fired when a message is received. */
13
+ message = "message",
14
+ /** Fired when the websocket tries to reconnect after a connection loss. */
15
+ retry = "retry",
16
+ /** Fired when the websocket successfully reconnects after a connection loss. */
17
+ reconnect = "reconnect"
18
+ }
19
+ /***
20
+ * Details/properties of a retry-event.
21
+ */
22
+ export type RetryEventDetail = {
23
+ /** Number of retries that have been made since the connection was lost. */
24
+ readonly retries: number;
25
+ /** Time (ms) waited since the last connection-retry. */
26
+ readonly backoff: number;
27
+ /** Timestamp of when the connection was lost or undefined if the connection has never been established. */
28
+ readonly lastConnection: Date | undefined;
29
+ };
30
+ /**
31
+ * Properties of a reconnect-event.
32
+ */
33
+ export type ReconnectEventDetail = Omit<RetryEventDetail, "backoff">;
34
+ /**
35
+ * Maps websocket events to their corresponding event.
36
+ */
37
+ export type WebsocketEventMap = {
38
+ [WebsocketEvent.open]: Event;
39
+ [WebsocketEvent.close]: CloseEvent;
40
+ [WebsocketEvent.error]: Event;
41
+ [WebsocketEvent.message]: MessageEvent;
42
+ [WebsocketEvent.retry]: CustomEvent<RetryEventDetail>;
43
+ [WebsocketEvent.reconnect]: CustomEvent<ReconnectEventDetail>;
44
+ };
45
+ /**
46
+ * Listener for websocket events.
47
+ * */
48
+ export type WebsocketEventListener<K extends WebsocketEvent> = (instance: Websocket, ev: WebsocketEventMap[K]) => unknown;
49
+ export type WebsocketEventListenerParams<K extends WebsocketEvent> = Parameters<WebsocketEventListener<K>>;
50
+ /**
51
+ * Options for websocket events.
52
+ */
53
+ export type WebsocketEventListenerOptions = EventListenerOptions & AddEventListenerOptions;
54
+ /**
55
+ * Listener for websocket events with options.
56
+ */
57
+ export type WebsocketEventListenerWithOptions<K extends WebsocketEvent> = {
58
+ readonly listener: WebsocketEventListener<K>;
59
+ readonly options?: WebsocketEventListenerOptions;
60
+ };
61
+ /**
62
+ * Maps websocket events to their corresponding event-listeners.
63
+ */
64
+ export type WebsocketEventListeners = {
65
+ [K in WebsocketEvent]: WebsocketEventListenerWithOptions<K>[];
66
+ };
67
+ //# sourceMappingURL=websocket_event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_event.d.ts","sourceRoot":"","sources":["../../../src/websocket_event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,oBAAY,cAAc;IACxB,2CAA2C;IAC3C,IAAI,SAAS;IAEb,2CAA2C;IAC3C,KAAK,UAAU;IAEf,8GAA8G;IAC9G,KAAK,UAAU;IAEf,wCAAwC;IACxC,OAAO,YAAY;IAEnB,2EAA2E;IAC3E,KAAK,UAAU;IAEf,gFAAgF;IAChF,SAAS,cAAc;CACxB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,2GAA2G;IAC3G,QAAQ,CAAC,cAAc,EAAE,IAAI,GAAG,SAAS,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,gBAAgB,EAAE,SAAS,CAAC,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IAC7B,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IACnC,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IAC9B,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvC,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;IACtD,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAC;CAC/D,CAAC;AAEF;;KAEK;AACL,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,cAAc,IAAI,CAC7D,QAAQ,EAAE,SAAS,EACnB,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,KACrB,OAAO,CAAC;AAEb,MAAM,MAAM,4BAA4B,CAAC,CAAC,SAAS,cAAc,IAAI,UAAU,CAC7E,sBAAsB,CAAC,CAAC,CAAC,CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG,oBAAoB,GAC9D,uBAAuB,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,iCAAiC,CAAC,CAAC,SAAS,cAAc,IAAI;IACxE,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IAC7C,QAAQ,CAAC,OAAO,CAAC,EAAE,6BAA6B,CAAC;CAClD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;KACnC,CAAC,IAAI,cAAc,GAAG,iCAAiC,CAAC,CAAC,CAAC,EAAE;CAC9D,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Events that can be fired by the websocket.
3
+ */
4
+ export var WebsocketEvent;
5
+ (function (WebsocketEvent) {
6
+ /** Fired when the connection is opened. */
7
+ WebsocketEvent["open"] = "open";
8
+ /** Fired when the connection is closed. */
9
+ WebsocketEvent["close"] = "close";
10
+ /** Fired when the connection has been closed because of an error, such as when some data couldn't be sent. */
11
+ WebsocketEvent["error"] = "error";
12
+ /** Fired when a message is received. */
13
+ WebsocketEvent["message"] = "message";
14
+ /** Fired when the websocket tries to reconnect after a connection loss. */
15
+ WebsocketEvent["retry"] = "retry";
16
+ /** Fired when the websocket successfully reconnects after a connection loss. */
17
+ WebsocketEvent["reconnect"] = "reconnect";
18
+ })(WebsocketEvent || (WebsocketEvent = {}));
19
+ //# sourceMappingURL=websocket_event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_event.js","sourceRoot":"","sources":["../../../src/websocket_event.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAN,IAAY,cAkBX;AAlBD,WAAY,cAAc;IACxB,2CAA2C;IAC3C,+BAAa,CAAA;IAEb,2CAA2C;IAC3C,iCAAe,CAAA;IAEf,8GAA8G;IAC9G,iCAAe,CAAA;IAEf,wCAAwC;IACxC,qCAAmB,CAAA;IAEnB,2EAA2E;IAC3E,iCAAe,CAAA;IAEf,gFAAgF;IAChF,yCAAuB,CAAA;AACzB,CAAC,EAlBW,cAAc,KAAd,cAAc,QAkBzB"}
@@ -0,0 +1,21 @@
1
+ import { WebsocketBuffer } from "./websocket_buffer";
2
+ import { WebsocketConnectionRetryOptions } from "./websocket_retry_options";
3
+ import { WebsocketEventListeners } from "./websocket_event";
4
+ /**
5
+ * Options that can be passed to the Websocket constructor.
6
+ */
7
+ export interface WebsocketOptions {
8
+ /**
9
+ * The Buffer to use.
10
+ */
11
+ readonly buffer?: WebsocketBuffer;
12
+ /**
13
+ * The options for the connection-retry-strategy.
14
+ */
15
+ readonly retry?: WebsocketConnectionRetryOptions;
16
+ /**
17
+ * The initial listeners to add to the websocket.
18
+ */
19
+ readonly listeners?: WebsocketEventListeners;
20
+ }
21
+ //# sourceMappingURL=websocket_options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_options.d.ts","sourceRoot":"","sources":["../../../src/websocket_options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,+BAA+B,CAAC;IAEjD;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,uBAAuB,CAAC;CAC9C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=websocket_options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_options.js","sourceRoot":"","sources":["../../../src/websocket_options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,20 @@
1
+ import { Backoff } from "./backoff/backoff";
2
+ /**
3
+ * Options for the websockets retry-strategy.
4
+ */
5
+ export interface WebsocketConnectionRetryOptions {
6
+ /**
7
+ * The maximum number of retries before giving up. No limit if undefined.
8
+ */
9
+ readonly maxRetries?: number;
10
+ /**
11
+ * Wether to reconnect immediately after a connection has been lost,
12
+ * ignoring the backoff strategy for the first retry.
13
+ */
14
+ readonly instantReconnect?: boolean;
15
+ /**
16
+ * The backoff strategy to use. This is used to determine the delay between connection-retries.
17
+ */
18
+ readonly backoff?: Backoff;
19
+ }
20
+ //# sourceMappingURL=websocket_retry_options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_retry_options.d.ts","sourceRoot":"","sources":["../../../src/websocket_retry_options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAEpC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=websocket_retry_options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_retry_options.js","sourceRoot":"","sources":["../../../src/websocket_retry_options.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "websocket-ts",
3
- "version": "2.1.1",
3
+ "version": "2.1.3",
4
4
  "main": "dist/cjs/src/index.js",
5
5
  "types": "dist/cjs/src/index.d.ts",
6
6
  "module": "dist/esm/src/index.js",