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 @@
1
+ {"version":3,"file":"websocket_buffer.d.ts","sourceRoot":"","sources":["../../../src/websocket_buffer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe,CAC9B,CAAC,GAAG,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,eAAe;IAErD;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEtB;;;OAGG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;CACvB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=websocket_buffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_buffer.js","sourceRoot":"","sources":["../../../src/websocket_buffer.ts"],"names":[],"mappings":""}
@@ -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,"file":"websocket_builder.d.ts","sourceRoot":"","sources":["../../../src/websocket_builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAE9B,OAAO,CAAC,UAAU,CAAC,CAAoB;IACvC,OAAO,CAAC,QAAQ,CAAC,CAAmB;IAEpC;;;;OAIG;gBACS,GAAG,EAAE,MAAM;IAIvB;;;;OAIG;IACH,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED;;;;OAIG;IACI,aAAa,CAClB,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,GACvC,gBAAgB;IAKnB;;;;OAIG;IACH,IAAI,SAAS,IAAI,MAAM,GAAG,MAAM,EAAE,GA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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,263 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.WebsocketBuilder = void 0;
24
+ var websocket_event_1 = require("./websocket_event");
25
+ var websocket_1 = require("./websocket");
26
+ /**
27
+ * Builder for websockets.
28
+ */
29
+ var WebsocketBuilder = /** @class */ (function () {
30
+ /**
31
+ * Creates a new WebsocketBuilder.
32
+ *
33
+ * @param url the url to connect to
34
+ */
35
+ function WebsocketBuilder(url) {
36
+ this._url = url;
37
+ }
38
+ Object.defineProperty(WebsocketBuilder.prototype, "url", {
39
+ /**
40
+ * Getter for the url.
41
+ *
42
+ * @returns the url
43
+ */
44
+ get: function () {
45
+ return this._url;
46
+ },
47
+ enumerable: false,
48
+ configurable: true
49
+ });
50
+ /**
51
+ * Adds protocols to the websocket. Subsequent calls to this method will override the previously set protocols.
52
+ *
53
+ * @param protocols the protocols to add
54
+ */
55
+ WebsocketBuilder.prototype.withProtocols = function (protocols) {
56
+ this._protocols = protocols;
57
+ return this;
58
+ };
59
+ Object.defineProperty(WebsocketBuilder.prototype, "protocols", {
60
+ /**
61
+ * Getter for the protocols.
62
+ *
63
+ * @returns the protocols, undefined if no protocols have been set
64
+ */
65
+ get: function () {
66
+ return this._protocols;
67
+ },
68
+ enumerable: false,
69
+ configurable: true
70
+ });
71
+ /**
72
+ * Sets the maximum number of retries before giving up. No limit if undefined.
73
+ *
74
+ * @param maxRetries the maximum number of retries before giving up
75
+ */
76
+ WebsocketBuilder.prototype.withMaxRetries = function (maxRetries) {
77
+ var _a;
78
+ this._options = __assign(__assign({}, this._options), { retry: __assign(__assign({}, (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry), { maxRetries: maxRetries }) });
79
+ return this;
80
+ };
81
+ Object.defineProperty(WebsocketBuilder.prototype, "maxRetries", {
82
+ /**
83
+ * Getter for the maximum number of retries before giving up.
84
+ *
85
+ * @returns the maximum number of retries before giving up, undefined if no maximum has been set
86
+ */
87
+ get: function () {
88
+ var _a, _b;
89
+ return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry) === null || _b === void 0 ? void 0 : _b.maxRetries;
90
+ },
91
+ enumerable: false,
92
+ configurable: true
93
+ });
94
+ /**
95
+ * Sets wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
96
+ *
97
+ * @param instantReconnect wether to reconnect immediately after a connection has been lost
98
+ */
99
+ WebsocketBuilder.prototype.withInstantReconnect = function (instantReconnect) {
100
+ var _a;
101
+ this._options = __assign(__assign({}, this._options), { retry: __assign(__assign({}, (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry), { instantReconnect: instantReconnect }) });
102
+ return this;
103
+ };
104
+ Object.defineProperty(WebsocketBuilder.prototype, "instantReconnect", {
105
+ /**
106
+ * Getter for wether to reconnect immediately after a connection has been lost, ignoring the backoff strategy for the first retry.
107
+ *
108
+ * @returns wether to reconnect immediately after a connection has been lost, undefined if no value has been set
109
+ */
110
+ get: function () {
111
+ var _a, _b;
112
+ return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry) === null || _b === void 0 ? void 0 : _b.instantReconnect;
113
+ },
114
+ enumerable: false,
115
+ configurable: true
116
+ });
117
+ /**
118
+ * Adds a backoff to the websocket. Subsequent calls to this method will override the previously set backoff.
119
+ *
120
+ * @param backoff the backoff to add
121
+ */
122
+ WebsocketBuilder.prototype.withBackoff = function (backoff) {
123
+ var _a;
124
+ this._options = __assign(__assign({}, this._options), { retry: __assign(__assign({}, (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry), { backoff: backoff }) });
125
+ return this;
126
+ };
127
+ Object.defineProperty(WebsocketBuilder.prototype, "backoff", {
128
+ /**
129
+ * Getter for the backoff.
130
+ *
131
+ * @returns the backoff, undefined if no backoff has been set
132
+ */
133
+ get: function () {
134
+ var _a, _b;
135
+ return (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.retry) === null || _b === void 0 ? void 0 : _b.backoff;
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ /**
141
+ * Adds a buffer to the websocket. Subsequent calls to this method will override the previously set buffer.
142
+ *
143
+ * @param buffer the buffer to add
144
+ */
145
+ WebsocketBuilder.prototype.withBuffer = function (buffer) {
146
+ this._options = __assign(__assign({}, this._options), { buffer: buffer });
147
+ return this;
148
+ };
149
+ Object.defineProperty(WebsocketBuilder.prototype, "buffer", {
150
+ /**
151
+ * Getter for the buffer.
152
+ *
153
+ * @returns the buffer, undefined if no buffer has been set
154
+ */
155
+ get: function () {
156
+ var _a;
157
+ return (_a = this._options) === null || _a === void 0 ? void 0 : _a.buffer;
158
+ },
159
+ enumerable: false,
160
+ configurable: true
161
+ });
162
+ /**
163
+ * Adds an 'open' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
164
+ * called in the order they were added.
165
+ *
166
+ * @param listener the listener to add
167
+ * @param options the listener options
168
+ */
169
+ WebsocketBuilder.prototype.onOpen = function (listener, options) {
170
+ this.addListener(websocket_event_1.WebsocketEvent.open, listener, options);
171
+ return this;
172
+ };
173
+ /**
174
+ * Adds an 'close' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
175
+ * called in the order they were added.
176
+ *
177
+ * @param listener the listener to add
178
+ * @param options the listener options
179
+ */
180
+ WebsocketBuilder.prototype.onClose = function (listener, options) {
181
+ this.addListener(websocket_event_1.WebsocketEvent.close, listener, options);
182
+ return this;
183
+ };
184
+ /**
185
+ * Adds an 'error' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
186
+ * called in the order they were added.
187
+ *
188
+ * @param listener the listener to add
189
+ * @param options the listener options
190
+ */
191
+ WebsocketBuilder.prototype.onError = function (listener, options) {
192
+ this.addListener(websocket_event_1.WebsocketEvent.error, listener, options);
193
+ return this;
194
+ };
195
+ /**
196
+ * Adds an 'message' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
197
+ * called in the order they were added.
198
+ *
199
+ * @param listener the listener to add
200
+ * @param options the listener options
201
+ */
202
+ WebsocketBuilder.prototype.onMessage = function (listener, options) {
203
+ this.addListener(websocket_event_1.WebsocketEvent.message, listener, options);
204
+ return this;
205
+ };
206
+ /**
207
+ * Adds an 'retry' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
208
+ * called in the order they were added.
209
+ *
210
+ * @param listener the listener to add
211
+ * @param options the listener options
212
+ */
213
+ WebsocketBuilder.prototype.onRetry = function (listener, options) {
214
+ this.addListener(websocket_event_1.WebsocketEvent.retry, listener, options);
215
+ return this;
216
+ };
217
+ /**
218
+ * Adds an 'reconnect' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
219
+ * called in the order they were added.
220
+ *
221
+ * @param listener the listener to add
222
+ * @param options the listener options
223
+ */
224
+ WebsocketBuilder.prototype.onReconnect = function (listener, options) {
225
+ this.addListener(websocket_event_1.WebsocketEvent.reconnect, listener, options);
226
+ return this;
227
+ };
228
+ /**
229
+ * Builds the websocket.
230
+ *
231
+ * @return a new websocket, with the set options
232
+ */
233
+ WebsocketBuilder.prototype.build = function () {
234
+ return new websocket_1.Websocket(this._url, this._protocols, this._options); // instantiate the websocket with the set options
235
+ };
236
+ /**
237
+ * Adds an event listener to the options.
238
+ *
239
+ * @param event the event to add the listener to
240
+ * @param listener the listener to add
241
+ * @param options the listener options
242
+ */
243
+ WebsocketBuilder.prototype.addListener = function (event, listener, options) {
244
+ var _a;
245
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
246
+ this._options = __assign(__assign({}, this._options), { listeners: (_a = {
247
+ open: (_d = (_c = (_b = this._options) === null || _b === void 0 ? void 0 : _b.listeners) === null || _c === void 0 ? void 0 : _c.open) !== null && _d !== void 0 ? _d : [],
248
+ close: (_g = (_f = (_e = this._options) === null || _e === void 0 ? void 0 : _e.listeners) === null || _f === void 0 ? void 0 : _f.close) !== null && _g !== void 0 ? _g : [],
249
+ error: (_k = (_j = (_h = this._options) === null || _h === void 0 ? void 0 : _h.listeners) === null || _j === void 0 ? void 0 : _j.error) !== null && _k !== void 0 ? _k : [],
250
+ message: (_o = (_m = (_l = this._options) === null || _l === void 0 ? void 0 : _l.listeners) === null || _m === void 0 ? void 0 : _m.message) !== null && _o !== void 0 ? _o : [],
251
+ retry: (_r = (_q = (_p = this._options) === null || _p === void 0 ? void 0 : _p.listeners) === null || _q === void 0 ? void 0 : _q.retry) !== null && _r !== void 0 ? _r : [],
252
+ reconnect: (_u = (_t = (_s = this._options) === null || _s === void 0 ? void 0 : _s.listeners) === null || _t === void 0 ? void 0 : _t.reconnect) !== null && _u !== void 0 ? _u : []
253
+ },
254
+ _a[event] = __spreadArray(__spreadArray([], ((_x = (_w = (_v = this._options) === null || _v === void 0 ? void 0 : _v.listeners) === null || _w === void 0 ? void 0 : _w[event]) !== null && _x !== void 0 ? _x : []), true), [
255
+ { listener: listener, options: options },
256
+ ], false),
257
+ _a) });
258
+ return this;
259
+ };
260
+ return WebsocketBuilder;
261
+ }());
262
+ exports.WebsocketBuilder = WebsocketBuilder;
263
+ //# sourceMappingURL=websocket_builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket_builder.js","sourceRoot":"","sources":["../../../src/websocket_builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,qDAI2B;AAC3B,yCAAwC;AAIxC;;GAEG;AACH;IAME;;;;OAIG;IACH,0BAAY,GAAW;QACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAClB,CAAC;IAOD,sBAAI,iCAAG;QALP;;;;WAIG;aACH;YACE,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;;;OAAA;IAED;;;;OAIG;IACI,wCAAa,GAApB,UACE,SAAwC;QAExC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAOD,sBAAI,uCAAS;QALb;;;;WAIG;aACH;YACE,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;;;OAAA;IAED;;;;OAIG;IACI,yCAAc,GAArB,UAAsB,UAA8B;;QAClD,IAAI,CAAC,QAAQ,yBACR,IAAI,CAAC,QAAQ,KAChB,KAAK,wBAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,KAAK,KAAE,UAAU,YAAA,MAC7C,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAOD,sBAAI,wCAAU;QALd;;;;WAIG;aACH;;YACE,OAAO,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,KAAK,0CAAE,UAAU,CAAC;QAC1C,CAAC;;;OAAA;IAED;;;;OAIG;IACI,+CAAoB,GAA3B,UACE,gBAAqC;;QAErC,IAAI,CAAC,QAAQ,yBACR,IAAI,CAAC,QAAQ,KAChB,KAAK,wBAAO,MAAA,IAAI,CAAC,QAAQ,0CAAE,KAAK,KAAE,gBAAgB,kBAAA,MACnD,C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A,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,KAAK,mCAAI,EAAE;oBAC5C,OAAO,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,OAAO,mCAAI,EAAE;oBAChD,KAAK,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,KAAK,mCAAI,EAAE;oBAC5C,SAAS,EAAE,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAE,SAAS,mCAAI,EAAE;;gBACpD,GAAC,KAAK,oCACD,CAAC,MAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,0CAAE,SAAS,0CAAG,KAAK,CAAC,mCAAI,EAAE,CAAC;oBAC5C,EAAE,QAAQ,UAAA,EAAE,OAAO,SAAA,EAAE;yBACtB;sBAEJ,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IACH,uBAAC;AAAD,CAAC,AApQD,IAoQC;AApQY,4CAAgB"}
@@ -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,2E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,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,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebsocketEvent = void 0;
4
+ /**
5
+ * Events that can be fired by the websocket.
6
+ */
7
+ var WebsocketEvent;
8
+ (function (WebsocketEvent) {
9
+ /** Fired when the connection is opened. */
10
+ WebsocketEvent["open"] = "open";
11
+ /** Fired when the connection is closed. */
12
+ WebsocketEvent["close"] = "close";
13
+ /** Fired when the connection has been closed because of an error, such as when some data couldn't be sent. */
14
+ WebsocketEvent["error"] = "error";
15
+ /** Fired when a message is received. */
16
+ WebsocketEvent["message"] = "message";
17
+ /** Fired when the websocket tries to reconnect after a connection loss. */
18
+ WebsocketEvent["retry"] = "retry";
19
+ /** Fired when the websocket successfully reconnects after a connection loss. */
20
+ WebsocketEvent["reconnect"] = "reconnect";
21
+ })(WebsocketEvent || (exports.WebsocketEvent = WebsocketEvent = {}));
22
+ //# 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,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,8BAAd,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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# 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,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# 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":""}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * A Backoff produces a series of numbers that are used to determine
3
+ * the delay between connection-retries. Values are expected to be in milliseconds.
4
+ */
5
+ export interface Backoff {
6
+ /**
7
+ * The number of retries. Starts at 0, increases by 1 for each call to next(). Resets to 0 when reset() is called.
8
+ */
9
+ readonly retries: number;
10
+ /**
11
+ * Current number in the series.
12
+ */
13
+ readonly current: number;
14
+ /**
15
+ * Advances the series to the next number and returns it.
16
+ * @return the next number in the series
17
+ */
18
+ next(): number;
19
+ /**
20
+ * Resets the series to its initial state.
21
+ */
22
+ reset(): void;
23
+ }
24
+ //# sourceMappingURL=backoff.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=backoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backoff.js","sourceRoot":"","sources":["../../../../src/backoff/backoff.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { Backoff } from "./backoff";
2
+ /**
3
+ * ConstantBackoff always returns the same backoff-time.
4
+ */
5
+ export declare class ConstantBackoff implements Backoff {
6
+ private readonly backoff;
7
+ private _retries;
8
+ /**
9
+ * Creates a new ConstantBackoff.
10
+ * @param backoff the backoff-time to return
11
+ */
12
+ constructor(backoff: number);
13
+ get retries(): number;
14
+ get current(): number;
15
+ next(): number;
16
+ reset(): void;
17
+ }
18
+ //# sourceMappingURL=constantbackoff.d.ts.map