websocket-ts 2.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 (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,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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IAED;;;;;;;;OAQG;IACI,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,GAAG,eAAe,GAAG,IAAI;IAY1E;;;;;;OAMG;IACI,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAMlD;;;;;;;OAOG;IACI,gBAAgB,CAAC,CAAC,SAAS,cAAc,EAC9C,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,EACnC,OAAO,CAAC,EAAE,6BAA6B,GACtC,IAAI;IAIP;;;;;;OAMG;IACI,mBAAmB,CAAC,CAAC,SAAS,cAAc,EACjD,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,EACnC,OAAO,CAAC,EAAE,6BAA6B,GACtC,IAAI;IASP;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAsBlB;;OAEG;IACH,OAAO,CAAC,cAAc;IAoBtB;;;OAGG;IACH,OAAO,CAAC,eAAe,CACwB;IAE/C;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CACwB;IAEhD;;;OAGG;IACH,OAAO,CAAC,gBAAgB,CACwB;IAEhD;;;OAGG;IACH,OAAO,CAAC,kBAAkB,CACwB;IAElD;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAuBrB;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAyCnB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACH,OAAO,CAAC,+BAA+B;IAuCvC;;OAEG;IACH,OAAO,CAAC,8BAA8B;CAGvC"}
@@ -0,0 +1,434 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Websocket = void 0;
13
+ var websocket_event_1 = require("./websocket_event");
14
+ /**
15
+ * A websocket wrapper that can be configured to reconnect automatically and buffer messages when the websocket is not connected.
16
+ */
17
+ var Websocket = /** @class */ (function () {
18
+ /**
19
+ * Creates a new websocket.
20
+ *
21
+ * @param url to connect to.
22
+ * @param protocols optional protocols to use.
23
+ * @param options optional options to use.
24
+ */
25
+ function Websocket(url, protocols, options) {
26
+ var _this = this;
27
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
28
+ this._closedByUser = false; // whether the websocket was closed by the user
29
+ /**
30
+ * Handles the 'open' event of the browser-native websocket.
31
+ * @param event to handle.
32
+ */
33
+ this.handleOpenEvent = function (event) {
34
+ return _this.handleEvent(websocket_event_1.WebsocketEvent.open, event);
35
+ };
36
+ /**
37
+ * Handles the 'error' event of the browser-native websocket.
38
+ * @param event to handle.
39
+ */
40
+ this.handleErrorEvent = function (event) {
41
+ return _this.handleEvent(websocket_event_1.WebsocketEvent.error, event);
42
+ };
43
+ /**
44
+ * Handles the 'close' event of the browser-native websocket.
45
+ * @param event to handle.
46
+ */
47
+ this.handleCloseEvent = function (event) {
48
+ return _this.handleEvent(websocket_event_1.WebsocketEvent.close, event);
49
+ };
50
+ /**
51
+ * Handles the 'message' event of the browser-native websocket.
52
+ * @param event to handle.
53
+ */
54
+ this.handleMessageEvent = function (event) {
55
+ return _this.handleEvent(websocket_event_1.WebsocketEvent.message, event);
56
+ };
57
+ this._url = url;
58
+ this._protocols = protocols;
59
+ // make a copy of the options to prevent the user from changing them
60
+ this._options = {
61
+ buffer: options === null || options === void 0 ? void 0 : options.buffer,
62
+ retry: {
63
+ maxRetries: (_a = options === null || options === void 0 ? void 0 : options.retry) === null || _a === void 0 ? void 0 : _a.maxRetries,
64
+ instantReconnect: (_b = options === null || options === void 0 ? void 0 : options.retry) === null || _b === void 0 ? void 0 : _b.instantReconnect,
65
+ backoff: (_c = options === null || options === void 0 ? void 0 : options.retry) === null || _c === void 0 ? void 0 : _c.backoff,
66
+ },
67
+ listeners: {
68
+ open: __spreadArray([], ((_e = (_d = options === null || options === void 0 ? void 0 : options.listeners) === null || _d === void 0 ? void 0 : _d.open) !== null && _e !== void 0 ? _e : []), true),
69
+ close: __spreadArray([], ((_g = (_f = options === null || options === void 0 ? void 0 : options.listeners) === null || _f === void 0 ? void 0 : _f.close) !== null && _g !== void 0 ? _g : []), true),
70
+ error: __spreadArray([], ((_j = (_h = options === null || options === void 0 ? void 0 : options.listeners) === null || _h === void 0 ? void 0 : _h.error) !== null && _j !== void 0 ? _j : []), true),
71
+ message: __spreadArray([], ((_l = (_k = options === null || options === void 0 ? void 0 : options.listeners) === null || _k === void 0 ? void 0 : _k.message) !== null && _l !== void 0 ? _l : []), true),
72
+ retry: __spreadArray([], ((_o = (_m = options === null || options === void 0 ? void 0 : options.listeners) === null || _m === void 0 ? void 0 : _m.retry) !== null && _o !== void 0 ? _o : []), true),
73
+ reconnect: __spreadArray([], ((_q = (_p = options === null || options === void 0 ? void 0 : options.listeners) === null || _p === void 0 ? void 0 : _p.reconnect) !== null && _q !== void 0 ? _q : []), true),
74
+ },
75
+ };
76
+ this._underlyingWebsocket = this.tryConnect();
77
+ }
78
+ Object.defineProperty(Websocket.prototype, "url", {
79
+ /**
80
+ * Getter for the url.
81
+ *
82
+ * @return the url.
83
+ */
84
+ get: function () {
85
+ return this._url;
86
+ },
87
+ enumerable: false,
88
+ configurable: true
89
+ });
90
+ Object.defineProperty(Websocket.prototype, "protocols", {
91
+ /**
92
+ * Getter for the protocols.
93
+ *
94
+ * @return the protocols, or undefined if none were provided.
95
+ */
96
+ get: function () {
97
+ return this._protocols;
98
+ },
99
+ enumerable: false,
100
+ configurable: true
101
+ });
102
+ Object.defineProperty(Websocket.prototype, "buffer", {
103
+ /**
104
+ * Getter for the buffer.
105
+ *
106
+ * @return the buffer, or undefined if none was provided.
107
+ */
108
+ get: function () {
109
+ return this._options.buffer;
110
+ },
111
+ enumerable: false,
112
+ configurable: true
113
+ });
114
+ Object.defineProperty(Websocket.prototype, "maxRetries", {
115
+ /**
116
+ * Getter for the maxRetries.
117
+ *
118
+ * @return the maxRetries, or undefined if none was provided (no limit).
119
+ */
120
+ get: function () {
121
+ return this._options.retry.maxRetries;
122
+ },
123
+ enumerable: false,
124
+ configurable: true
125
+ });
126
+ Object.defineProperty(Websocket.prototype, "instantReconnect", {
127
+ /**
128
+ * Getter for the instantReconnect.
129
+ *
130
+ * @return the instantReconnect, or undefined if none was provided.
131
+ */
132
+ get: function () {
133
+ return this._options.retry.instantReconnect;
134
+ },
135
+ enumerable: false,
136
+ configurable: true
137
+ });
138
+ Object.defineProperty(Websocket.prototype, "backoff", {
139
+ /**
140
+ * Getter for the backoff.
141
+ *
142
+ * @return the backoff, or undefined if none was provided.
143
+ */
144
+ get: function () {
145
+ return this._options.retry.backoff;
146
+ },
147
+ enumerable: false,
148
+ configurable: true
149
+ });
150
+ Object.defineProperty(Websocket.prototype, "closedByUser", {
151
+ /**
152
+ * Whether the websocket was closed by the user. A websocket is closed by the user if the close().
153
+ *
154
+ * @return true if the websocket was closed by the user, false otherwise.
155
+ */
156
+ get: function () {
157
+ return this._closedByUser;
158
+ },
159
+ enumerable: false,
160
+ configurable: true
161
+ });
162
+ Object.defineProperty(Websocket.prototype, "lastConnection", {
163
+ /**
164
+ * Getter for the last 'open' event, e.g. the last time the websocket was connected.
165
+ *
166
+ * @return the last 'open' event, or undefined if the websocket was never connected.
167
+ */
168
+ get: function () {
169
+ return this._lastConnection;
170
+ },
171
+ enumerable: false,
172
+ configurable: true
173
+ });
174
+ Object.defineProperty(Websocket.prototype, "underlyingWebsocket", {
175
+ /**
176
+ * Getter for the underlying websocket. This can be used to access the browser's native websocket directly.
177
+ *
178
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
179
+ * @return the underlying websocket.
180
+ */
181
+ get: function () {
182
+ return this._underlyingWebsocket;
183
+ },
184
+ enumerable: false,
185
+ configurable: true
186
+ });
187
+ Object.defineProperty(Websocket.prototype, "readyState", {
188
+ /**
189
+ * Getter for the readyState of the underlying websocket.
190
+ *
191
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState
192
+ * @return the readyState of the underlying websocket.
193
+ */
194
+ get: function () {
195
+ return this._underlyingWebsocket.readyState;
196
+ },
197
+ enumerable: false,
198
+ configurable: true
199
+ });
200
+ Object.defineProperty(Websocket.prototype, "bufferedAmount", {
201
+ /**
202
+ * Getter for the bufferedAmount of the underlying websocket.
203
+ *
204
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount
205
+ * @return the bufferedAmount of the underlying websocket.
206
+ */
207
+ get: function () {
208
+ return this._underlyingWebsocket.bufferedAmount;
209
+ },
210
+ enumerable: false,
211
+ configurable: true
212
+ });
213
+ Object.defineProperty(Websocket.prototype, "extensions", {
214
+ /**
215
+ * Getter for the extensions of the underlying websocket.
216
+ *
217
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions
218
+ * @return the extensions of the underlying websocket.
219
+ */
220
+ get: function () {
221
+ return this._underlyingWebsocket.extensions;
222
+ },
223
+ enumerable: false,
224
+ configurable: true
225
+ });
226
+ Object.defineProperty(Websocket.prototype, "binaryType", {
227
+ /**
228
+ * Getter for the binaryType of the underlying websocket.
229
+ *
230
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType
231
+ * @return the binaryType of the underlying websocket.
232
+ */
233
+ get: function () {
234
+ return this._underlyingWebsocket.binaryType;
235
+ },
236
+ /**
237
+ * Setter for the binaryType of the underlying websocket.
238
+ *
239
+ * @param value to set, 'blob' or 'arraybuffer'.
240
+ */
241
+ set: function (value) {
242
+ this._underlyingWebsocket.binaryType = value;
243
+ },
244
+ enumerable: false,
245
+ configurable: true
246
+ });
247
+ /**
248
+ * Sends data over the websocket.
249
+ *
250
+ * If the websocket is not connected and a buffer was provided on creation, the data will be added to the buffer.
251
+ * If no buffer was provided or the websocket was closed by the user, the data will be dropped.
252
+ *
253
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
254
+ * @param data to send.
255
+ */
256
+ Websocket.prototype.send = function (data) {
257
+ if (this.closedByUser)
258
+ return; // no-op if closed by user
259
+ if (this._underlyingWebsocket.readyState === this._underlyingWebsocket.OPEN) {
260
+ this._underlyingWebsocket.send(data); // websocket is connected, send data
261
+ }
262
+ else if (this.buffer !== undefined) {
263
+ this.buffer.add(data); // websocket is not connected, add data to buffer
264
+ }
265
+ };
266
+ /**
267
+ * Close the websocket. No connection-retry will be attempted after this.
268
+ *
269
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
270
+ * @param code optional close code.
271
+ * @param reason optional close reason.
272
+ */
273
+ Websocket.prototype.close = function (code, reason) {
274
+ this.cancelScheduledConnectionRetry(); // cancel any scheduled retries
275
+ this._closedByUser = true; // mark websocket as closed by user
276
+ this._underlyingWebsocket.close(code, reason); // close underlying websocket with provided code and reason
277
+ };
278
+ /**
279
+ * Adds an event listener for the given event-type.
280
+ *
281
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
282
+ * @param type of the event to add the listener for.
283
+ * @param listener to add.
284
+ * @param options to use when adding the listener.
285
+ */
286
+ Websocket.prototype.addEventListener = function (type, listener, options) {
287
+ this._options.listeners[type].push({ listener: listener, options: options }); // add listener to list of listeners
288
+ };
289
+ /**
290
+ * Removes one or more event listener for the given event-type that match the given listener and options.
291
+ *
292
+ * @param type of the event to remove the listener for.
293
+ * @param listener to remove.
294
+ * @param options that were used when the listener was added.
295
+ */
296
+ Websocket.prototype.removeEventListener = function (type, listener, options) {
297
+ var isListenerNotToBeRemoved = function (l) { return l.listener !== listener || l.options !== options; };
298
+ this._options.listeners[type] =
299
+ this._options.listeners[type].filter(isListenerNotToBeRemoved); // only keep listeners that are not to be removed
300
+ };
301
+ /**
302
+ * Creates a new browser-native websocket and connects it to the given URL with the given protocols
303
+ * and adds all event listeners to the browser-native websocket.
304
+ *
305
+ * @return the created browser-native websocket which is also stored in the '_underlyingWebsocket' property.
306
+ */
307
+ Websocket.prototype.tryConnect = function () {
308
+ this._underlyingWebsocket = new WebSocket(this.url, this.protocols); // create new browser-native websocket and add all event listeners
309
+ this._underlyingWebsocket.addEventListener(websocket_event_1.WebsocketEvent.open, this.handleOpenEvent);
310
+ this._underlyingWebsocket.addEventListener(websocket_event_1.WebsocketEvent.close, this.handleCloseEvent);
311
+ this._underlyingWebsocket.addEventListener(websocket_event_1.WebsocketEvent.error, this.handleErrorEvent);
312
+ this._underlyingWebsocket.addEventListener(websocket_event_1.WebsocketEvent.message, this.handleMessageEvent);
313
+ return this._underlyingWebsocket;
314
+ };
315
+ /**
316
+ * Removes all event listeners from the browser-native websocket and closes it.
317
+ */
318
+ Websocket.prototype.clearWebsocket = function () {
319
+ this._underlyingWebsocket.removeEventListener(websocket_event_1.WebsocketEvent.open, this.handleOpenEvent);
320
+ this._underlyingWebsocket.removeEventListener(websocket_event_1.WebsocketEvent.close, this.handleCloseEvent);
321
+ this._underlyingWebsocket.removeEventListener(websocket_event_1.WebsocketEvent.error, this.handleErrorEvent);
322
+ this._underlyingWebsocket.removeEventListener(websocket_event_1.WebsocketEvent.message, this.handleMessageEvent);
323
+ this._underlyingWebsocket.close();
324
+ };
325
+ /**
326
+ * Dispatch an event to all listeners of the given event-type.
327
+ *
328
+ * @param type of the event to dispatch.
329
+ * @param event to dispatch.
330
+ */
331
+ Websocket.prototype.dispatchEvent = function (type, event) {
332
+ var _this = this;
333
+ var eventListeners = this._options.listeners[type];
334
+ var newEventListeners = [];
335
+ eventListeners.forEach(function (_a) {
336
+ var listener = _a.listener, options = _a.options;
337
+ listener(_this, event); // invoke listener with event
338
+ if (options === undefined ||
339
+ options.once === undefined ||
340
+ !options.once) {
341
+ newEventListeners.push({ listener: listener, options: options }); // only keep listener if it isn't a once-listener
342
+ }
343
+ });
344
+ this._options.listeners[type] = newEventListeners; // replace old listeners with new listeners that don't include once-listeners
345
+ };
346
+ /**
347
+ * Handles the given event by dispatching it to all listeners of the given event-type.
348
+ *
349
+ * @param type of the event to handle.
350
+ * @param event to handle.
351
+ */
352
+ Websocket.prototype.handleEvent = function (type, event) {
353
+ switch (type) {
354
+ case websocket_event_1.WebsocketEvent.close:
355
+ this.dispatchEvent(type, event);
356
+ this.scheduleConnectionRetryIfNeeded(); // schedule a new connection retry if the websocket was closed by the server
357
+ break;
358
+ case websocket_event_1.WebsocketEvent.open:
359
+ if (this.backoff !== undefined && this._lastConnection !== undefined) {
360
+ // websocket was reconnected, dispatch reconnect event and reset backoff
361
+ var detail = {
362
+ retries: this.backoff.retries,
363
+ lastConnection: new Date(this._lastConnection),
364
+ };
365
+ var event_1 = new CustomEvent(websocket_event_1.WebsocketEvent.reconnect, {
366
+ detail: detail,
367
+ });
368
+ this.dispatchEvent(websocket_event_1.WebsocketEvent.reconnect, event_1);
369
+ this.backoff.reset();
370
+ }
371
+ this._lastConnection = new Date();
372
+ this.dispatchEvent(type, event); // dispatch open event and send buffered data
373
+ this.sendBufferedData();
374
+ break;
375
+ case websocket_event_1.WebsocketEvent.retry:
376
+ this.dispatchEvent(type, event); // dispatch retry event and try to connect
377
+ this.clearWebsocket(); // clear the old websocket
378
+ this.tryConnect();
379
+ break;
380
+ default:
381
+ this.dispatchEvent(type, event); // dispatch event to all listeners of the given event-type
382
+ break;
383
+ }
384
+ };
385
+ /**
386
+ * Sends buffered data if there is a buffer defined.
387
+ */
388
+ Websocket.prototype.sendBufferedData = function () {
389
+ if (this.buffer === undefined) {
390
+ return; // no buffer defined, nothing to send
391
+ }
392
+ for (var ele = this.buffer.read(); ele !== undefined; ele = this.buffer.read()) {
393
+ this.send(ele); // send buffered data
394
+ }
395
+ };
396
+ /**
397
+ * Schedules a connection-retry if there is a backoff defined and the websocket was not closed by the user.
398
+ */
399
+ Websocket.prototype.scheduleConnectionRetryIfNeeded = function () {
400
+ var _this = this;
401
+ if (this.closedByUser) {
402
+ return; // user closed the websocket, no retry
403
+ }
404
+ if (this.backoff === undefined) {
405
+ return; // no backoff defined, no retry
406
+ }
407
+ var handleRetryEvent = function (detail) {
408
+ var event = new CustomEvent(websocket_event_1.WebsocketEvent.retry, { detail: detail });
409
+ _this.handleEvent(websocket_event_1.WebsocketEvent.retry, event);
410
+ };
411
+ // create retry event detail, depending on the 'instantReconnect' option
412
+ var retryEventDetail = {
413
+ backoff: this._options.retry.instantReconnect === true ? 0 : this.backoff.next(),
414
+ retries: this._options.retry.instantReconnect === true
415
+ ? 0
416
+ : this.backoff.retries,
417
+ lastConnection: this._lastConnection,
418
+ };
419
+ // schedule a new connection-retry if the maximum number of retries is not reached yet
420
+ if (this._options.retry.maxRetries === undefined ||
421
+ retryEventDetail.retries <= this._options.retry.maxRetries) {
422
+ this.retryTimeout = window.setTimeout(function () { return handleRetryEvent(retryEventDetail); }, retryEventDetail.backoff);
423
+ }
424
+ };
425
+ /**
426
+ * Cancels the scheduled connection-retry, if there is one.
427
+ */
428
+ Websocket.prototype.cancelScheduledConnectionRetry = function () {
429
+ window.clearTimeout(this.retryTimeout);
430
+ };
431
+ return Websocket;
432
+ }());
433
+ exports.Websocket = Websocket;
434
+ //# sourceMappingURL=websocket.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../../src/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,qDAS2B;AAG3B;;GAEG;AACH;IAYE;;;;;;OAMG;IACH,mBACE,GAAW,EACX,SAA6B,EAC7B,OAA0B;QAH5B,iBA2BC;;QA1CO,kBAAa,GAAY,KAAK,CAAC,CAAC,+CAA+C;QAwSvF;;;WAGG;QACK,oBAAe,GAAG,UAAC,KAAY;YACrC,OAAA,KAAI,CAAC,WAAW,CAAC,gCAAc,CAAC,IAAI,EAAE,KAAK,CAAC;QAA5C,CAA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IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,gBAAgB,KAAK,IAAI;gBAC3C,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO;YAC1B,cAAc,EAAE,IAAI,CAAC,eAAe;SACrC,CAAC;QAEF,sFAAsF;QACtF,IACE,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS;YAC5C,gBAAgB,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,EAC1D;YACA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,UAAU,CACnC,cAAM,OAAA,gBAAgB,CAAC,gBAAgB,CAAC,EAAlC,CAAkC,EACxC,gBAAgB,CAAC,OAAO,CACzB,CAAC;SACH;IACH,CAAC;IAED;;OAEG;IACK,kDAA8B,GAAtC;QACE,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzC,CAAC;IACH,gBAAC;AAAD,CAAC,AArdD,IAqdC;AArdY,8BAAS"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A WebsocketBuffer is used to store messages temporarily until they can be sent.
3
+ */
4
+ export interface WebsocketBuffer<E = string | ArrayBufferLike | Blob | ArrayBufferView> {
5
+ /**
6
+ * Adds an element to the buffer.
7
+ * @param element the element to add
8
+ */
9
+ add(element: E): void;
10
+ /**
11
+ * Reads an element from the buffer.
12
+ * @return an element from the buffer or undefined if the buffer is empty
13
+ */
14
+ read(): E | undefined;
15
+ }
16
+ //# sourceMappingURL=websocket_buffer.d.ts.map