websocket-ts 2.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +134 -9
- package/dist/cjs/{src/backoff → backoff}/backoff.d.ts +6 -3
- package/dist/{esm/src → cjs}/backoff/backoff.d.ts.map +1 -1
- package/dist/{esm/src → cjs}/backoff/backoff.js.map +1 -1
- package/dist/cjs/{src/backoff → backoff}/constantbackoff.d.ts +2 -2
- package/dist/cjs/backoff/constantbackoff.d.ts.map +1 -0
- package/dist/cjs/backoff/constantbackoff.js +34 -0
- package/dist/cjs/backoff/constantbackoff.js.map +1 -0
- package/dist/{esm/src → cjs}/backoff/exponentialbackoff.d.ts +2 -2
- package/dist/cjs/backoff/exponentialbackoff.d.ts.map +1 -0
- package/dist/cjs/{src/backoff → backoff}/exponentialbackoff.js +19 -27
- package/dist/cjs/backoff/exponentialbackoff.js.map +1 -0
- package/dist/{esm/src → cjs}/backoff/linearbackoff.d.ts +1 -1
- package/dist/cjs/backoff/linearbackoff.d.ts.map +1 -0
- package/dist/cjs/{src/backoff → backoff}/linearbackoff.js +23 -31
- package/dist/cjs/backoff/linearbackoff.js.map +1 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +20 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/{esm/src → cjs}/queue/array_queue.d.ts +1 -1
- package/dist/cjs/queue/array_queue.d.ts.map +1 -0
- package/dist/cjs/{src/queue → queue}/array_queue.js +17 -18
- package/dist/cjs/queue/array_queue.js.map +1 -0
- package/dist/cjs/queue/queue.d.ts.map +1 -0
- package/dist/cjs/{src/queue → queue}/queue.js.map +1 -1
- package/dist/cjs/{src/queue → queue}/ring_queue.d.ts +1 -1
- package/dist/cjs/queue/ring_queue.d.ts.map +1 -0
- package/dist/cjs/{src/queue → queue}/ring_queue.js +25 -22
- package/dist/cjs/queue/ring_queue.js.map +1 -0
- package/dist/cjs/{src/websocket.d.ts → websocket.d.ts} +75 -17
- package/dist/cjs/websocket.d.ts.map +1 -0
- package/dist/cjs/websocket.js +588 -0
- package/dist/cjs/websocket.js.map +1 -0
- package/dist/cjs/{src/websocket_buffer.d.ts → websocket_buffer.d.ts} +1 -1
- package/dist/cjs/websocket_buffer.d.ts.map +1 -0
- package/dist/cjs/websocket_buffer.js.map +1 -0
- package/dist/{esm/src → cjs}/websocket_builder.d.ts +14 -5
- package/dist/cjs/{src/websocket_builder.d.ts.map → websocket_builder.d.ts.map} +1 -1
- package/dist/cjs/websocket_builder.js +236 -0
- package/dist/cjs/websocket_builder.js.map +1 -0
- package/dist/{esm/src → cjs}/websocket_event.d.ts +20 -5
- package/dist/cjs/websocket_event.d.ts.map +1 -0
- package/dist/cjs/{src/websocket_event.js → websocket_event.js} +7 -1
- package/dist/cjs/websocket_event.js.map +1 -0
- package/dist/{esm/src → cjs}/websocket_options.d.ts +6 -5
- package/dist/cjs/websocket_options.d.ts.map +1 -0
- package/dist/cjs/websocket_options.js.map +1 -0
- package/dist/{esm/src → cjs}/websocket_retry_options.d.ts +3 -2
- package/dist/cjs/websocket_retry_options.d.ts.map +1 -0
- package/dist/cjs/websocket_retry_options.js.map +1 -0
- package/dist/esm/{src/backoff → backoff}/backoff.d.ts +6 -3
- package/dist/{cjs/src → esm}/backoff/backoff.d.ts.map +1 -1
- package/dist/{cjs/src → esm}/backoff/backoff.js.map +1 -1
- package/dist/esm/{src/backoff → backoff}/constantbackoff.d.ts +2 -2
- package/dist/esm/backoff/constantbackoff.d.ts.map +1 -0
- package/dist/esm/{src/backoff → backoff}/constantbackoff.js +3 -3
- package/dist/esm/backoff/constantbackoff.js.map +1 -0
- package/dist/{cjs/src → esm}/backoff/exponentialbackoff.d.ts +2 -2
- package/dist/esm/backoff/exponentialbackoff.d.ts.map +1 -0
- package/dist/esm/{src/backoff → backoff}/exponentialbackoff.js +6 -5
- package/dist/esm/backoff/exponentialbackoff.js.map +1 -0
- package/dist/{cjs/src → esm}/backoff/linearbackoff.d.ts +1 -1
- package/dist/esm/backoff/linearbackoff.d.ts.map +1 -0
- package/dist/esm/{src/backoff → backoff}/linearbackoff.js +8 -7
- package/dist/esm/backoff/linearbackoff.js.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/{cjs/src → esm}/queue/array_queue.d.ts +1 -1
- package/dist/esm/queue/array_queue.d.ts.map +1 -0
- package/dist/esm/queue/array_queue.js.map +1 -0
- package/dist/esm/queue/queue.d.ts.map +1 -0
- package/dist/esm/{src/queue → queue}/queue.js.map +1 -1
- package/dist/esm/{src/queue → queue}/ring_queue.d.ts +1 -1
- package/dist/esm/queue/ring_queue.d.ts.map +1 -0
- package/dist/esm/{src/queue → queue}/ring_queue.js +7 -3
- package/dist/esm/queue/ring_queue.js.map +1 -0
- package/dist/esm/{src/websocket.d.ts → websocket.d.ts} +75 -17
- package/dist/esm/websocket.d.ts.map +1 -0
- package/dist/esm/websocket.js +584 -0
- package/dist/esm/websocket.js.map +1 -0
- package/dist/esm/{src/websocket_buffer.d.ts → websocket_buffer.d.ts} +1 -1
- package/dist/esm/websocket_buffer.d.ts.map +1 -0
- package/dist/esm/websocket_buffer.js.map +1 -0
- package/dist/{cjs/src → esm}/websocket_builder.d.ts +14 -5
- package/dist/esm/{src/websocket_builder.d.ts.map → websocket_builder.d.ts.map} +1 -1
- package/dist/esm/{src/websocket_builder.js → websocket_builder.js} +36 -17
- package/dist/esm/websocket_builder.js.map +1 -0
- package/dist/{cjs/src → esm}/websocket_event.d.ts +20 -5
- package/dist/esm/websocket_event.d.ts.map +1 -0
- package/dist/esm/{src/websocket_event.js → websocket_event.js} +7 -1
- package/dist/esm/websocket_event.js.map +1 -0
- package/dist/{cjs/src → esm}/websocket_options.d.ts +6 -5
- package/dist/esm/websocket_options.d.ts.map +1 -0
- package/dist/esm/websocket_options.js.map +1 -0
- package/dist/{cjs/src → esm}/websocket_retry_options.d.ts +3 -2
- package/dist/esm/websocket_retry_options.d.ts.map +1 -0
- package/dist/esm/websocket_retry_options.js.map +1 -0
- package/package.json +35 -16
- package/src/backoff/backoff.ts +6 -3
- package/src/backoff/constantbackoff.ts +4 -4
- package/src/backoff/exponentialbackoff.ts +7 -6
- package/src/backoff/linearbackoff.ts +9 -8
- package/src/index.ts +14 -13
- package/src/queue/array_queue.ts +1 -1
- package/src/queue/ring_queue.ts +12 -8
- package/src/websocket.ts +333 -79
- package/src/websocket_buffer.ts +1 -3
- package/src/websocket_builder.ts +24 -13
- package/src/websocket_event.ts +25 -6
- package/src/websocket_options.ts +6 -5
- package/src/websocket_retry_options.ts +3 -2
- package/dist/cjs/src/backoff/constantbackoff.d.ts.map +0 -1
- package/dist/cjs/src/backoff/constantbackoff.js +0 -43
- package/dist/cjs/src/backoff/constantbackoff.js.map +0 -1
- package/dist/cjs/src/backoff/exponentialbackoff.d.ts.map +0 -1
- package/dist/cjs/src/backoff/exponentialbackoff.js.map +0 -1
- package/dist/cjs/src/backoff/linearbackoff.d.ts.map +0 -1
- package/dist/cjs/src/backoff/linearbackoff.js.map +0 -1
- package/dist/cjs/src/index.d.ts +0 -14
- package/dist/cjs/src/index.d.ts.map +0 -1
- package/dist/cjs/src/index.js +0 -20
- package/dist/cjs/src/index.js.map +0 -1
- package/dist/cjs/src/queue/array_queue.d.ts.map +0 -1
- package/dist/cjs/src/queue/array_queue.js.map +0 -1
- package/dist/cjs/src/queue/queue.d.ts.map +0 -1
- package/dist/cjs/src/queue/ring_queue.d.ts.map +0 -1
- package/dist/cjs/src/queue/ring_queue.js.map +0 -1
- package/dist/cjs/src/websocket.d.ts.map +0 -1
- package/dist/cjs/src/websocket.js +0 -439
- package/dist/cjs/src/websocket.js.map +0 -1
- package/dist/cjs/src/websocket_buffer.d.ts.map +0 -1
- package/dist/cjs/src/websocket_buffer.js.map +0 -1
- package/dist/cjs/src/websocket_builder.js +0 -263
- package/dist/cjs/src/websocket_builder.js.map +0 -1
- package/dist/cjs/src/websocket_event.d.ts.map +0 -1
- package/dist/cjs/src/websocket_event.js.map +0 -1
- package/dist/cjs/src/websocket_options.d.ts.map +0 -1
- package/dist/cjs/src/websocket_options.js.map +0 -1
- package/dist/cjs/src/websocket_retry_options.d.ts.map +0 -1
- package/dist/cjs/src/websocket_retry_options.js.map +0 -1
- package/dist/esm/src/backoff/constantbackoff.d.ts.map +0 -1
- package/dist/esm/src/backoff/constantbackoff.js.map +0 -1
- package/dist/esm/src/backoff/exponentialbackoff.d.ts.map +0 -1
- package/dist/esm/src/backoff/exponentialbackoff.js.map +0 -1
- package/dist/esm/src/backoff/linearbackoff.d.ts.map +0 -1
- package/dist/esm/src/backoff/linearbackoff.js.map +0 -1
- package/dist/esm/src/index.d.ts +0 -14
- package/dist/esm/src/index.d.ts.map +0 -1
- package/dist/esm/src/index.js +0 -9
- package/dist/esm/src/index.js.map +0 -1
- package/dist/esm/src/queue/array_queue.d.ts.map +0 -1
- package/dist/esm/src/queue/array_queue.js.map +0 -1
- package/dist/esm/src/queue/queue.d.ts.map +0 -1
- package/dist/esm/src/queue/ring_queue.d.ts.map +0 -1
- package/dist/esm/src/queue/ring_queue.js.map +0 -1
- package/dist/esm/src/websocket.d.ts.map +0 -1
- package/dist/esm/src/websocket.js +0 -361
- package/dist/esm/src/websocket.js.map +0 -1
- package/dist/esm/src/websocket_buffer.d.ts.map +0 -1
- package/dist/esm/src/websocket_buffer.js.map +0 -1
- package/dist/esm/src/websocket_builder.js.map +0 -1
- package/dist/esm/src/websocket_event.d.ts.map +0 -1
- package/dist/esm/src/websocket_event.js.map +0 -1
- package/dist/esm/src/websocket_options.d.ts.map +0 -1
- package/dist/esm/src/websocket_options.js.map +0 -1
- package/dist/esm/src/websocket_retry_options.d.ts.map +0 -1
- package/dist/esm/src/websocket_retry_options.js.map +0 -1
- package/eslint.config.mjs +0 -43
- package/tsconfig.cjs.json +0 -74
- package/tsconfig.esm.json +0 -74
- /package/dist/cjs/{src/backoff → backoff}/backoff.js +0 -0
- /package/dist/cjs/{src/queue → queue}/queue.d.ts +0 -0
- /package/dist/cjs/{src/queue → queue}/queue.js +0 -0
- /package/dist/cjs/{src/websocket_buffer.js → websocket_buffer.js} +0 -0
- /package/dist/cjs/{src/websocket_options.js → websocket_options.js} +0 -0
- /package/dist/cjs/{src/websocket_retry_options.js → websocket_retry_options.js} +0 -0
- /package/dist/esm/{src/backoff → backoff}/backoff.js +0 -0
- /package/dist/esm/{src/queue → queue}/array_queue.js +0 -0
- /package/dist/esm/{src/queue → queue}/queue.d.ts +0 -0
- /package/dist/esm/{src/queue → queue}/queue.js +0 -0
- /package/dist/esm/{src/websocket_buffer.js → websocket_buffer.js} +0 -0
- /package/dist/esm/{src/websocket_options.js → websocket_options.js} +0 -0
- /package/dist/esm/{src/websocket_retry_options.js → websocket_retry_options.js} +0 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Websocket = void 0;
|
|
4
|
+
const websocket_event_js_1 = require("./websocket_event.js");
|
|
5
|
+
/**
|
|
6
|
+
* A websocket wrapper that can be configured to reconnect automatically and buffer messages when the websocket is not connected.
|
|
7
|
+
*/
|
|
8
|
+
class Websocket {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new websocket.
|
|
11
|
+
*
|
|
12
|
+
* @param url to connect to, or a function that returns a URL.
|
|
13
|
+
* @param protocols optional protocols to use.
|
|
14
|
+
* @param options optional options to use.
|
|
15
|
+
* @throws Error if retry options (maxRetries, instantReconnect) are set without a backoff.
|
|
16
|
+
* @throws Error if maxRetries is neither Infinity nor a non-negative integer.
|
|
17
|
+
*/
|
|
18
|
+
constructor(url, protocols, options) {
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
20
|
+
this._closedByUser = false; // whether the websocket was closed by the user
|
|
21
|
+
// incremented by close() and reconnect() to invalidate in-flight lifecycle
|
|
22
|
+
// work: event handlers and retry timers belonging to an older generation
|
|
23
|
+
// must not commit further state transitions or create sockets
|
|
24
|
+
this._connectionGeneration = 0;
|
|
25
|
+
// for each listener-registration made with an AbortSignal, the function that
|
|
26
|
+
// unhooks the 'abort'-handler again; used to avoid piling up dead handlers on
|
|
27
|
+
// long-lived signals when listeners are removed by other means
|
|
28
|
+
this.abortHandlerCleanups = new WeakMap();
|
|
29
|
+
/**
|
|
30
|
+
* Handles the 'open' event of the browser-native websocket.
|
|
31
|
+
* @param event to handle.
|
|
32
|
+
*/
|
|
33
|
+
this.handleOpenEvent = (event) => this.handleEvent(websocket_event_js_1.WebsocketEvent.open, event);
|
|
34
|
+
/**
|
|
35
|
+
* Handles the 'error' event of the browser-native websocket.
|
|
36
|
+
* @param event to handle.
|
|
37
|
+
*/
|
|
38
|
+
this.handleErrorEvent = (event) => this.handleEvent(websocket_event_js_1.WebsocketEvent.error, event);
|
|
39
|
+
/**
|
|
40
|
+
* Handles the 'close' event of the browser-native websocket.
|
|
41
|
+
* @param event to handle.
|
|
42
|
+
*/
|
|
43
|
+
this.handleCloseEvent = (event) => this.handleEvent(websocket_event_js_1.WebsocketEvent.close, event);
|
|
44
|
+
/**
|
|
45
|
+
* Handles the 'message' event of the browser-native websocket.
|
|
46
|
+
* @param event to handle.
|
|
47
|
+
*/
|
|
48
|
+
this.handleMessageEvent = (event) => this.handleEvent(websocket_event_js_1.WebsocketEvent.message, event);
|
|
49
|
+
if (((_a = options === null || options === void 0 ? void 0 : options.retry) === null || _a === void 0 ? void 0 : _a.backoff) === undefined &&
|
|
50
|
+
(((_b = options === null || options === void 0 ? void 0 : options.retry) === null || _b === void 0 ? void 0 : _b.maxRetries) !== undefined ||
|
|
51
|
+
((_c = options === null || options === void 0 ? void 0 : options.retry) === null || _c === void 0 ? void 0 : _c.instantReconnect) !== undefined)) {
|
|
52
|
+
// retrying is driven by the backoff; without one, the other retry options would silently do nothing
|
|
53
|
+
throw new Error("Retry options (maxRetries, instantReconnect) require a backoff to be configured");
|
|
54
|
+
}
|
|
55
|
+
const maxRetries = (_d = options === null || options === void 0 ? void 0 : options.retry) === null || _d === void 0 ? void 0 : _d.maxRetries;
|
|
56
|
+
if (maxRetries !== undefined &&
|
|
57
|
+
maxRetries !== Infinity &&
|
|
58
|
+
(!Number.isInteger(maxRetries) || maxRetries < 0)) {
|
|
59
|
+
// NaN would silently never exhaust, negative values exhaust before any
|
|
60
|
+
// retry, and fractions break the promise that the exhausted-detail
|
|
61
|
+
// retries equal the configured limit; fail fast like the backoffs do.
|
|
62
|
+
// Infinity is accepted as an explicit 'no limit', like undefined
|
|
63
|
+
throw new Error("MaxRetries must be undefined, Infinity or a non-negative integer");
|
|
64
|
+
}
|
|
65
|
+
this._urlProvider = url;
|
|
66
|
+
this._protocols = protocols;
|
|
67
|
+
// make a copy of the options to prevent the user from changing them
|
|
68
|
+
this._options = {
|
|
69
|
+
buffer: options === null || options === void 0 ? void 0 : options.buffer,
|
|
70
|
+
retry: {
|
|
71
|
+
maxRetries: (_e = options === null || options === void 0 ? void 0 : options.retry) === null || _e === void 0 ? void 0 : _e.maxRetries,
|
|
72
|
+
instantReconnect: (_f = options === null || options === void 0 ? void 0 : options.retry) === null || _f === void 0 ? void 0 : _f.instantReconnect,
|
|
73
|
+
backoff: (_g = options === null || options === void 0 ? void 0 : options.retry) === null || _g === void 0 ? void 0 : _g.backoff,
|
|
74
|
+
},
|
|
75
|
+
listeners: {
|
|
76
|
+
open: [],
|
|
77
|
+
close: [],
|
|
78
|
+
error: [],
|
|
79
|
+
message: [],
|
|
80
|
+
retry: [],
|
|
81
|
+
reconnect: [],
|
|
82
|
+
exhausted: [],
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
try {
|
|
86
|
+
// register the initial listeners through addEventListener so that
|
|
87
|
+
// listener options (e.g. 'signal') are honored for them as well; the
|
|
88
|
+
// generic helper keeps each event's listeners typed for that event
|
|
89
|
+
const register = (type) => {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
return (_b = (_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b.forEach((l) => this.addEventListener(type, l.listener, l.options));
|
|
92
|
+
};
|
|
93
|
+
Object.values(websocket_event_js_1.WebsocketEvent).forEach(register);
|
|
94
|
+
// this first attempt always assigns the underlying websocket: the URL
|
|
95
|
+
// provider is called without the instance as 'this', so it cannot reach
|
|
96
|
+
// close() or reconnect() to supersede it
|
|
97
|
+
this.tryConnect();
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
// the caller never receives this instance and cannot remove its
|
|
101
|
+
// listeners, so unhook their abort-handlers; otherwise a long-lived
|
|
102
|
+
// signal would retain the failed instance and everything it references
|
|
103
|
+
Object.values(this._options.listeners).forEach((listeners) => listeners.forEach((l) => this.cleanupAbortHandler(l)));
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Getter for the url of the most recently constructed underlying websocket. This is not
|
|
109
|
+
* necessarily the URL of the last successful connection, and a URL that the WebSocket
|
|
110
|
+
* constructor rejected, or whose connection attempt was superseded, is not recorded.
|
|
111
|
+
*
|
|
112
|
+
* @return the url.
|
|
113
|
+
*/
|
|
114
|
+
get url() {
|
|
115
|
+
return this._url;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Getter for the protocols.
|
|
119
|
+
*
|
|
120
|
+
* @return the protocols, or undefined if none were provided.
|
|
121
|
+
*/
|
|
122
|
+
get protocols() {
|
|
123
|
+
return this._protocols;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Getter for the buffer.
|
|
127
|
+
*
|
|
128
|
+
* @return the buffer, or undefined if none was provided.
|
|
129
|
+
*/
|
|
130
|
+
get buffer() {
|
|
131
|
+
return this._options.buffer;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Getter for the maxRetries.
|
|
135
|
+
*
|
|
136
|
+
* @return the maxRetries, or undefined if none was provided (no limit).
|
|
137
|
+
*/
|
|
138
|
+
get maxRetries() {
|
|
139
|
+
return this._options.retry.maxRetries;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Getter for the instantReconnect.
|
|
143
|
+
*
|
|
144
|
+
* @return the instantReconnect, or undefined if none was provided.
|
|
145
|
+
*/
|
|
146
|
+
get instantReconnect() {
|
|
147
|
+
return this._options.retry.instantReconnect;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Getter for the backoff.
|
|
151
|
+
*
|
|
152
|
+
* @return the backoff, or undefined if none was provided.
|
|
153
|
+
*/
|
|
154
|
+
get backoff() {
|
|
155
|
+
return this._options.retry.backoff;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Whether the websocket was closed by the user. A websocket is closed by the user by calling close().
|
|
159
|
+
*
|
|
160
|
+
* @return true if the websocket was closed by the user, false otherwise.
|
|
161
|
+
*/
|
|
162
|
+
get closedByUser() {
|
|
163
|
+
return this._closedByUser;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Getter for the time of the last 'open' event, i.e. the last time the websocket was connected.
|
|
167
|
+
*
|
|
168
|
+
* @return the time of the last 'open' event, or undefined if the websocket was never connected.
|
|
169
|
+
*/
|
|
170
|
+
get lastConnection() {
|
|
171
|
+
// defensive copy: retry/reconnect/exhausted event details are derived
|
|
172
|
+
// from the internal timestamp, so callers must not be able to mutate it
|
|
173
|
+
return this._lastConnection && new Date(this._lastConnection);
|
|
174
|
+
}
|
|
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 underlyingWebsocket() {
|
|
182
|
+
return this._underlyingWebsocket;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Getter for the readyState of the underlying websocket.
|
|
186
|
+
*
|
|
187
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState
|
|
188
|
+
* @return the readyState of the underlying websocket.
|
|
189
|
+
*/
|
|
190
|
+
get readyState() {
|
|
191
|
+
return this._underlyingWebsocket.readyState;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Getter for the bufferedAmount of the underlying websocket.
|
|
195
|
+
*
|
|
196
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount
|
|
197
|
+
* @return the bufferedAmount of the underlying websocket.
|
|
198
|
+
*/
|
|
199
|
+
get bufferedAmount() {
|
|
200
|
+
return this._underlyingWebsocket.bufferedAmount;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Getter for the extensions of the underlying websocket.
|
|
204
|
+
*
|
|
205
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/extensions
|
|
206
|
+
* @return the extensions of the underlying websocket.
|
|
207
|
+
*/
|
|
208
|
+
get extensions() {
|
|
209
|
+
return this._underlyingWebsocket.extensions;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Getter for the binaryType of the underlying websocket.
|
|
213
|
+
*
|
|
214
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType
|
|
215
|
+
* @return the binaryType of the underlying websocket.
|
|
216
|
+
*/
|
|
217
|
+
get binaryType() {
|
|
218
|
+
return this._underlyingWebsocket.binaryType;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Setter for the binaryType of the underlying websocket. The value is remembered
|
|
222
|
+
* and re-applied whenever a new underlying websocket is created after a reconnect.
|
|
223
|
+
*
|
|
224
|
+
* @param value to set, 'blob' or 'arraybuffer'.
|
|
225
|
+
*/
|
|
226
|
+
set binaryType(value) {
|
|
227
|
+
this._binaryType = value;
|
|
228
|
+
this._underlyingWebsocket.binaryType = value;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Sends data over the websocket.
|
|
232
|
+
*
|
|
233
|
+
* If the websocket is not connected and a buffer was provided on creation, the data will be added to the buffer.
|
|
234
|
+
* If no buffer was provided or the websocket was closed by the user, the data will be dropped.
|
|
235
|
+
*
|
|
236
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
237
|
+
* @param data to send.
|
|
238
|
+
*/
|
|
239
|
+
send(data) {
|
|
240
|
+
if (this.closedByUser)
|
|
241
|
+
return; // no-op if closed by user
|
|
242
|
+
if (this._underlyingWebsocket.readyState === this._underlyingWebsocket.OPEN) {
|
|
243
|
+
this._underlyingWebsocket.send(data); // websocket is connected, send data
|
|
244
|
+
}
|
|
245
|
+
else if (this.buffer !== undefined) {
|
|
246
|
+
this.buffer.add(data); // websocket is not connected, add data to buffer
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Close the websocket. No automatic connection-retry will be attempted after this,
|
|
251
|
+
* until reconnect() is called.
|
|
252
|
+
*
|
|
253
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
|
|
254
|
+
* @param code optional close code.
|
|
255
|
+
* @param reason optional close reason.
|
|
256
|
+
*/
|
|
257
|
+
close(code, reason) {
|
|
258
|
+
this._connectionGeneration++; // invalidate in-flight lifecycle work and pending retries
|
|
259
|
+
this.cancelScheduledConnectionRetry(); // cancel any scheduled retries
|
|
260
|
+
this._closedByUser = true; // mark websocket as closed by user
|
|
261
|
+
this._underlyingWebsocket.close(code, reason); // close underlying websocket with provided code and reason
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* (Re-)connects the websocket immediately, regardless of its current state:
|
|
265
|
+
* any scheduled retry is cancelled, the backoff and its retry-counter are
|
|
266
|
+
* reset, the URL provider is resolved again and a new connection is opened.
|
|
267
|
+
* This also revives a websocket that was closed by the user or that gave up
|
|
268
|
+
* after exceeding maxRetries (see the 'exhausted' event).
|
|
269
|
+
*
|
|
270
|
+
* Typical uses: a "reconnect" button after the 'exhausted' event, reacting to
|
|
271
|
+
* the browser's 'online' event, or forcing the URL provider to pick up a new
|
|
272
|
+
* auth token without waiting for the connection to drop.
|
|
273
|
+
*
|
|
274
|
+
* @throws whatever the URL provider or the WebSocket constructor throws.
|
|
275
|
+
*/
|
|
276
|
+
reconnect() {
|
|
277
|
+
var _a;
|
|
278
|
+
this._connectionGeneration++; // invalidate in-flight lifecycle work and pending retries
|
|
279
|
+
this.cancelScheduledConnectionRetry(); // cancel any scheduled retries
|
|
280
|
+
this._closedByUser = false; // revive if the websocket was closed by the user
|
|
281
|
+
(_a = this.backoff) === null || _a === void 0 ? void 0 : _a.reset(); // start the next disconnection episode with a fresh retry budget
|
|
282
|
+
this.clearWebsocket(); // detach and close the current underlying websocket
|
|
283
|
+
this.tryConnect();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Adds an event listener for the given event-type. When an AbortSignal is
|
|
287
|
+
* provided in the options, aborting it removes exactly this registration;
|
|
288
|
+
* a listener whose signal is already aborted is never registered, mirroring
|
|
289
|
+
* the native EventTarget.
|
|
290
|
+
*
|
|
291
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
|
|
292
|
+
* @param type of the event to add the listener for.
|
|
293
|
+
* @param listener to add.
|
|
294
|
+
* @param options to use when adding the listener.
|
|
295
|
+
*/
|
|
296
|
+
addEventListener(type, listener, options) {
|
|
297
|
+
const signal = options === null || options === void 0 ? void 0 : options.signal;
|
|
298
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
299
|
+
return; // the signal is already aborted, never register the listener
|
|
300
|
+
}
|
|
301
|
+
const entry = { listener, options };
|
|
302
|
+
if (signal !== undefined) {
|
|
303
|
+
// aborting the signal removes exactly this registration; the same
|
|
304
|
+
// listener-function may be registered again with a different signal
|
|
305
|
+
const removeOnAbort = () => {
|
|
306
|
+
this.abortHandlerCleanups.delete(entry);
|
|
307
|
+
this._options.listeners[type] = this._options.listeners[type].filter((l) => l !== entry);
|
|
308
|
+
};
|
|
309
|
+
signal.addEventListener("abort", removeOnAbort, { once: true });
|
|
310
|
+
this.abortHandlerCleanups.set(entry, () => signal.removeEventListener("abort", removeOnAbort));
|
|
311
|
+
}
|
|
312
|
+
this._options.listeners[type].push(entry); // add listener to list of listeners
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Removes all event listeners for the given event-type that match the given listener.
|
|
316
|
+
*
|
|
317
|
+
* Matching is done by listener identity only, mirroring the native EventTarget:
|
|
318
|
+
* the options a listener was added with are ignored when matching.
|
|
319
|
+
*
|
|
320
|
+
* @param type of the event to remove the listener for.
|
|
321
|
+
* @param listener to remove.
|
|
322
|
+
* @param options ignored when matching, present for backward compatibility.
|
|
323
|
+
*/
|
|
324
|
+
removeEventListener(type, listener,
|
|
325
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
326
|
+
options) {
|
|
327
|
+
const isListenerNotToBeRemoved = (l) => l.listener !== listener;
|
|
328
|
+
this._options.listeners[type]
|
|
329
|
+
.filter((l) => !isListenerNotToBeRemoved(l))
|
|
330
|
+
.forEach((l) => this.cleanupAbortHandler(l)); // unhook abort-handlers of removed listeners
|
|
331
|
+
this._options.listeners[type] =
|
|
332
|
+
this._options.listeners[type].filter(isListenerNotToBeRemoved); // only keep listeners that are not to be removed
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Creates a new browser-native websocket and connects it to the given URL with the given protocols
|
|
336
|
+
* and adds all event listeners to the browser-native websocket. The new websocket is stored in the
|
|
337
|
+
* '_underlyingWebsocket' property, unless the URL provider superseded this attempt by calling close()
|
|
338
|
+
* or reconnect().
|
|
339
|
+
*/
|
|
340
|
+
tryConnect() {
|
|
341
|
+
const generation = this._connectionGeneration;
|
|
342
|
+
const urlProvider = this._urlProvider; // call the provider without the wrapper as receiver
|
|
343
|
+
const url = typeof urlProvider === "function" ? urlProvider() : urlProvider;
|
|
344
|
+
// the URL provider is user code and may have re-entered close() or
|
|
345
|
+
// reconnect(); that call now owns the lifecycle, so this attempt must
|
|
346
|
+
// neither open a socket after close() nor overwrite (and thereby orphan)
|
|
347
|
+
// the socket a nested reconnect() already committed
|
|
348
|
+
if (generation !== this._connectionGeneration)
|
|
349
|
+
return;
|
|
350
|
+
const socket = new WebSocket(url, this.protocols); // create new browser-native websocket and add all event listeners
|
|
351
|
+
this._url = url;
|
|
352
|
+
this._underlyingWebsocket = socket;
|
|
353
|
+
if (this._binaryType !== undefined) {
|
|
354
|
+
this._underlyingWebsocket.binaryType = this._binaryType; // re-apply the user-chosen binaryType
|
|
355
|
+
}
|
|
356
|
+
this._underlyingWebsocket.addEventListener(websocket_event_js_1.WebsocketEvent.open, this.handleOpenEvent);
|
|
357
|
+
this._underlyingWebsocket.addEventListener(websocket_event_js_1.WebsocketEvent.close, this.handleCloseEvent);
|
|
358
|
+
this._underlyingWebsocket.addEventListener(websocket_event_js_1.WebsocketEvent.error, this.handleErrorEvent);
|
|
359
|
+
this._underlyingWebsocket.addEventListener(websocket_event_js_1.WebsocketEvent.message, this.handleMessageEvent);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Removes all event listeners from the browser-native websocket and closes it.
|
|
363
|
+
*/
|
|
364
|
+
clearWebsocket() {
|
|
365
|
+
this._underlyingWebsocket.removeEventListener(websocket_event_js_1.WebsocketEvent.open, this.handleOpenEvent);
|
|
366
|
+
this._underlyingWebsocket.removeEventListener(websocket_event_js_1.WebsocketEvent.close, this.handleCloseEvent);
|
|
367
|
+
this._underlyingWebsocket.removeEventListener(websocket_event_js_1.WebsocketEvent.error, this.handleErrorEvent);
|
|
368
|
+
this._underlyingWebsocket.removeEventListener(websocket_event_js_1.WebsocketEvent.message, this.handleMessageEvent);
|
|
369
|
+
this._underlyingWebsocket.close();
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Dispatch an event to all listeners of the given event-type.
|
|
373
|
+
*
|
|
374
|
+
* @param type of the event to dispatch.
|
|
375
|
+
* @param event to dispatch.
|
|
376
|
+
*/
|
|
377
|
+
dispatchEvent(type, event) {
|
|
378
|
+
// iterate over a snapshot so that listeners registered during dispatch are
|
|
379
|
+
// not invoked in this round, while mutations of the live list persist
|
|
380
|
+
const snapshot = [
|
|
381
|
+
...this._options.listeners[type],
|
|
382
|
+
];
|
|
383
|
+
snapshot.forEach((listenerWithOptions) => {
|
|
384
|
+
var _a;
|
|
385
|
+
// re-read the live list on every invocation: a listener may have
|
|
386
|
+
// added/removed listeners of this type, or replaced the list entirely
|
|
387
|
+
const listeners = this._options.listeners[type];
|
|
388
|
+
const index = listeners.indexOf(listenerWithOptions);
|
|
389
|
+
if (index === -1) {
|
|
390
|
+
return; // listener was removed during dispatch, don't invoke it
|
|
391
|
+
}
|
|
392
|
+
if ((_a = listenerWithOptions.options) === null || _a === void 0 ? void 0 : _a.once) {
|
|
393
|
+
listeners.splice(index, 1); // remove once-listener before invoking it
|
|
394
|
+
this.cleanupAbortHandler(listenerWithOptions); // unhook its abort-handler, if any
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
listenerWithOptions.listener(this, event); // invoke listener with event
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
// a throwing listener must neither stop the remaining listeners nor the
|
|
401
|
+
// lifecycle work that follows dispatch (retry scheduling, reconnection),
|
|
402
|
+
// mirroring how the native EventTarget isolates listener exceptions
|
|
403
|
+
this.reportListenerError(error);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Reports an exception thrown by a user-provided event listener. Uses
|
|
409
|
+
* globalThis.reportError where available (browsers); otherwise the exception
|
|
410
|
+
* is rethrown asynchronously so it still reaches the runtime's global
|
|
411
|
+
* error handling (e.g. 'uncaughtException' in Node.js) without breaking
|
|
412
|
+
* the dispatch it escaped from.
|
|
413
|
+
*
|
|
414
|
+
* @param error the exception thrown by the listener.
|
|
415
|
+
*/
|
|
416
|
+
reportListenerError(error) {
|
|
417
|
+
if (typeof globalThis.reportError === "function") {
|
|
418
|
+
globalThis.reportError(error);
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
globalThis.setTimeout(() => {
|
|
422
|
+
throw error;
|
|
423
|
+
}, 0);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Handles the given event by dispatching it to all listeners of the given event-type.
|
|
428
|
+
*
|
|
429
|
+
* @param type of the event to handle.
|
|
430
|
+
* @param event to handle.
|
|
431
|
+
*/
|
|
432
|
+
handleEvent(type, event) {
|
|
433
|
+
// a listener may re-enter close() or reconnect() during dispatch; both bump
|
|
434
|
+
// the generation, in which case the transitions below must not be committed
|
|
435
|
+
const generation = this._connectionGeneration;
|
|
436
|
+
switch (type) {
|
|
437
|
+
case websocket_event_js_1.WebsocketEvent.close:
|
|
438
|
+
this.dispatchEvent(type, event);
|
|
439
|
+
if (generation !== this._connectionGeneration)
|
|
440
|
+
break; // a listener already closed/reconnected
|
|
441
|
+
this.scheduleConnectionRetryIfNeeded(); // schedule a new connection retry if the websocket was closed by the server
|
|
442
|
+
break;
|
|
443
|
+
case websocket_event_js_1.WebsocketEvent.open: {
|
|
444
|
+
if (this.backoff !== undefined && this.backoff.retries > 0) {
|
|
445
|
+
// a retry preceded this open, so the websocket was reconnected; this
|
|
446
|
+
// includes recovery from a server that was unavailable at construction,
|
|
447
|
+
// where no previous connection exists yet
|
|
448
|
+
const detail = {
|
|
449
|
+
retries: this.backoff.retries,
|
|
450
|
+
lastConnection: this._lastConnection && new Date(this._lastConnection),
|
|
451
|
+
};
|
|
452
|
+
this.backoff.reset(); // reset before dispatch, so listeners observe a fresh retry budget
|
|
453
|
+
const event = new CustomEvent(websocket_event_js_1.WebsocketEvent.reconnect, {
|
|
454
|
+
detail,
|
|
455
|
+
});
|
|
456
|
+
this.dispatchEvent(websocket_event_js_1.WebsocketEvent.reconnect, event);
|
|
457
|
+
if (generation !== this._connectionGeneration)
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
this._lastConnection = new Date();
|
|
461
|
+
this.dispatchEvent(type, event); // dispatch open event and send buffered data
|
|
462
|
+
if (generation !== this._connectionGeneration)
|
|
463
|
+
break;
|
|
464
|
+
this.sendBufferedData();
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
case websocket_event_js_1.WebsocketEvent.retry:
|
|
468
|
+
this.dispatchEvent(type, event); // dispatch retry event and try to connect
|
|
469
|
+
if (generation !== this._connectionGeneration)
|
|
470
|
+
break; // this attempt was superseded during dispatch
|
|
471
|
+
this.clearWebsocket(); // clear the old websocket
|
|
472
|
+
try {
|
|
473
|
+
this.tryConnect();
|
|
474
|
+
}
|
|
475
|
+
catch (error) {
|
|
476
|
+
// the url provider or websocket-construction threw; surface the thrown
|
|
477
|
+
// value as an 'error' event and keep the retry chain alive under the
|
|
478
|
+
// usual rules. Native error events are plain Events, so listeners can
|
|
479
|
+
// tell this case apart with 'instanceof ErrorEvent'
|
|
480
|
+
this.dispatchEvent(websocket_event_js_1.WebsocketEvent.error, new ErrorEvent(websocket_event_js_1.WebsocketEvent.error, {
|
|
481
|
+
error,
|
|
482
|
+
message: error instanceof Error ? error.message : "",
|
|
483
|
+
}));
|
|
484
|
+
if (generation !== this._connectionGeneration)
|
|
485
|
+
break;
|
|
486
|
+
this.scheduleConnectionRetryIfNeeded();
|
|
487
|
+
}
|
|
488
|
+
break;
|
|
489
|
+
default:
|
|
490
|
+
this.dispatchEvent(type, event); // dispatch event to all listeners of the given event-type
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Sends buffered data if there is a buffer defined. Draining stops as soon as the
|
|
496
|
+
* websocket is no longer open, e.g. when a listener closed it during the drain;
|
|
497
|
+
* remaining elements stay buffered for the next successful connection. Without
|
|
498
|
+
* this guard, send() would re-add each read element to the buffer, cycling forever.
|
|
499
|
+
*/
|
|
500
|
+
sendBufferedData() {
|
|
501
|
+
if (this.buffer === undefined) {
|
|
502
|
+
return; // no buffer defined, nothing to send
|
|
503
|
+
}
|
|
504
|
+
while (!this.closedByUser &&
|
|
505
|
+
this._underlyingWebsocket.readyState === this._underlyingWebsocket.OPEN) {
|
|
506
|
+
const ele = this.buffer.read();
|
|
507
|
+
if (ele === undefined) {
|
|
508
|
+
return; // buffer is empty
|
|
509
|
+
}
|
|
510
|
+
this.send(ele); // send buffered data
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Schedules a connection-retry if there is a backoff defined and the websocket was not closed by the user.
|
|
515
|
+
*/
|
|
516
|
+
scheduleConnectionRetryIfNeeded() {
|
|
517
|
+
if (this.closedByUser) {
|
|
518
|
+
return; // user closed the websocket, no retry
|
|
519
|
+
}
|
|
520
|
+
if (this.backoff === undefined) {
|
|
521
|
+
return; // no backoff defined, no retry
|
|
522
|
+
}
|
|
523
|
+
// handler dispatches the retry event to all listeners of the retry event-type
|
|
524
|
+
const handleRetryEvent = (detail) => {
|
|
525
|
+
const event = new CustomEvent(websocket_event_js_1.WebsocketEvent.retry, { detail });
|
|
526
|
+
this.handleEvent(websocket_event_js_1.WebsocketEvent.retry, event);
|
|
527
|
+
};
|
|
528
|
+
// when the maximum number of retries is exceeded, give up and dispatch the
|
|
529
|
+
// exhausted event; checked before advancing the backoff so that the counter
|
|
530
|
+
// equals the number of retries actually performed
|
|
531
|
+
if (this._options.retry.maxRetries !== undefined &&
|
|
532
|
+
this.backoff.retries >= this._options.retry.maxRetries) {
|
|
533
|
+
const detail = {
|
|
534
|
+
retries: this.backoff.retries,
|
|
535
|
+
lastConnection: this._lastConnection && new Date(this._lastConnection),
|
|
536
|
+
};
|
|
537
|
+
const event = new CustomEvent(websocket_event_js_1.WebsocketEvent.exhausted, {
|
|
538
|
+
detail,
|
|
539
|
+
});
|
|
540
|
+
this.dispatchEvent(websocket_event_js_1.WebsocketEvent.exhausted, event);
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
// the backoff is reset on every successful reconnect, so a retry-count of
|
|
544
|
+
// zero means this is the first retry of the current disconnection episode
|
|
545
|
+
const isFirstRetryOfEpisode = this.backoff.retries === 0;
|
|
546
|
+
// advance the backoff so the retry-count is accurate and maxRetries applies;
|
|
547
|
+
// with 'instantReconnect' only the episode's first retry is instant. Browsers
|
|
548
|
+
// store timer delays as signed 32-bit integers, so longer delays would
|
|
549
|
+
// overflow and fire (almost) immediately; cap them at the maximum instead
|
|
550
|
+
const backoff = Math.min(this.backoff.next(), 2 ** 31 - 1);
|
|
551
|
+
const retryEventDetail = {
|
|
552
|
+
backoff: this._options.retry.instantReconnect === true && isFirstRetryOfEpisode
|
|
553
|
+
? 0
|
|
554
|
+
: backoff,
|
|
555
|
+
retries: this.backoff.retries,
|
|
556
|
+
lastConnection: this._lastConnection && new Date(this._lastConnection), // copy so listeners can't mutate our state
|
|
557
|
+
};
|
|
558
|
+
// no generation check is needed here: close() and reconnect() bump the
|
|
559
|
+
// generation and synchronously cancel this timeout, so a superseded
|
|
560
|
+
// attempt can never fire
|
|
561
|
+
this.retryTimeout = globalThis.setTimeout(() => {
|
|
562
|
+
this.retryTimeout = undefined;
|
|
563
|
+
handleRetryEvent(retryEventDetail);
|
|
564
|
+
}, retryEventDetail.backoff);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Cancels the scheduled connection-retry, if there is one.
|
|
568
|
+
*/
|
|
569
|
+
cancelScheduledConnectionRetry() {
|
|
570
|
+
globalThis.clearTimeout(this.retryTimeout);
|
|
571
|
+
this.retryTimeout = undefined;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Unhooks the 'abort'-handler that was registered on the AbortSignal of the
|
|
575
|
+
* given listener-registration, if there is one.
|
|
576
|
+
*
|
|
577
|
+
* @param entry the listener-registration to unhook the abort-handler for.
|
|
578
|
+
*/
|
|
579
|
+
cleanupAbortHandler(entry) {
|
|
580
|
+
const cleanup = this.abortHandlerCleanups.get(entry);
|
|
581
|
+
if (cleanup !== undefined) {
|
|
582
|
+
cleanup();
|
|
583
|
+
this.abortHandlerCleanups.delete(entry);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
exports.Websocket = Websocket;
|
|
588
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/websocket.ts"],"names":[],"mappings":";;;AAEA,6DAU8B;AAmB9B;;GAEG;AACH,MAAa,SAAS;IA6BpB;;;;;;;;OAQG;IACH,YACE,GAAgB,EAChB,SAA6B,EAC7B,OAA0B;;QApCpB,kBAAa,GAAY,KAAK,CAAC,CAAC,+CAA+C;QAMvF,2EAA2E;QAC3E,yEAAyE;QACzE,8DAA8D;QACtD,0BAAqB,GAAG,CAAC,CAAC;QAElC,6EAA6E;QAC7E,8EAA8E;QAC9E,+DAA+D;QAC9C,yBAAoB,GAAG,IAAI,OAAO,EAAsB,CAAC;QAya1E;;;WAGG;QACK,oBAAe,GAAG,CAAC,KAAY,EAAE,EAAE,CACzC,IAAI,CAAC,WAAW,CAAC,mCAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAE/C;;;WAGG;QACK,qBAAgB,GAAG,CAAC,KAAY,EAAE,EAAE,CAC1C,IAAI,CAAC,WAAW,CAAC,mCAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAEhD;;;WAGG;QACK,qBAAgB,GAAG,CAAC,KAAiB,EAAE,EAAE,CAC/C,IAAI,CAAC,WAAW,CAAC,mCAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QAEhD;;;WAGG;QACK,uBAAkB,GAAG,CAAC,KAAmB,EAAE,EAAE,CACnD,IAAI,CAAC,WAAW,CAAC,mCAAc,CAAC,OAAO,EA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KAAK,CAAC,gBAAgB,KAAK,IAAI,IAAI,qBAAqB;gBACpE,CAAC,CAAC,CAAC;gBACH,CAAC,CAAC,OAAO;YACb,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;YAC7B,cAAc,EAAE,IAAI,CAAC,eAAe,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,2CAA2C;SACpH,CAAC;QAEF,uEAAuE;QACvE,oEAAoE;QACpE,yBAAyB;QACzB,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,GAAG,EAAE;YAC7C,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;YAC9B,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;QACrC,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC/B,CAAC;IAED;;OAEG;IACK,8BAA8B;QACpC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACK,mBAAmB,CAAC,KAAa;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,EAAE,CAAC;YACV,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;CACF;AA9sBD,8BA8sBC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A WebsocketBuffer is used to store messages temporarily until they can be sent.
|
|
3
3
|
*/
|
|
4
|
-
export interface WebsocketBuffer<E = string |
|
|
4
|
+
export interface WebsocketBuffer<E = string | Blob | BufferSource> {
|
|
5
5
|
/**
|
|
6
6
|
* Adds an element to the buffer.
|
|
7
7
|
* @param element the element to add
|
|
@@ -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,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,YAAY;IAC/D;;;OAGG;IACH,GAAG,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;IAEtB;;;OAGG;IACH,IAAI,IAAI,CAAC,GAAG,SAAS,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket_buffer.js","sourceRoot":"","sources":["../../src/websocket_buffer.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Backoff } from "./backoff/backoff";
|
|
2
|
-
import { WebsocketEvent, WebsocketEventListener, WebsocketEventListenerOptions } from "./websocket_event";
|
|
3
|
-
import { UrlProvider, Websocket } from "./websocket";
|
|
4
|
-
import { WebsocketBuffer } from "./websocket_buffer";
|
|
1
|
+
import { Backoff } from "./backoff/backoff.js";
|
|
2
|
+
import { WebsocketEvent, WebsocketEventListener, WebsocketEventListenerOptions } from "./websocket_event.js";
|
|
3
|
+
import { UrlProvider, Websocket } from "./websocket.js";
|
|
4
|
+
import { WebsocketBuffer } from "./websocket_buffer.js";
|
|
5
5
|
/**
|
|
6
6
|
* Builder for websockets.
|
|
7
7
|
*/
|
|
@@ -34,7 +34,8 @@ export declare class WebsocketBuilder {
|
|
|
34
34
|
*/
|
|
35
35
|
get protocols(): string | string[] | undefined;
|
|
36
36
|
/**
|
|
37
|
-
* Sets the maximum number of retries before giving up. No limit if undefined.
|
|
37
|
+
* Sets the maximum number of retries before giving up. No limit if undefined or Infinity.
|
|
38
|
+
* Must be Infinity or a non-negative integer, otherwise build() will throw.
|
|
38
39
|
*
|
|
39
40
|
* @param maxRetries the maximum number of retries before giving up
|
|
40
41
|
*/
|
|
@@ -129,6 +130,14 @@ export declare class WebsocketBuilder {
|
|
|
129
130
|
* @param options the listener options
|
|
130
131
|
*/
|
|
131
132
|
onReconnect(listener: WebsocketEventListener<WebsocketEvent.reconnect>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
|
|
133
|
+
/**
|
|
134
|
+
* Adds an 'exhausted' event listener to the websocket. Subsequent calls to this method will add additional listeners that will be
|
|
135
|
+
* called in the order they were added.
|
|
136
|
+
*
|
|
137
|
+
* @param listener the listener to add
|
|
138
|
+
* @param options the listener options
|
|
139
|
+
*/
|
|
140
|
+
onExhausted(listener: WebsocketEventListener<WebsocketEvent.exhausted>, options?: WebsocketEventListenerOptions): WebsocketBuilder;
|
|
132
141
|
/**
|
|
133
142
|
* Builds the websocket.
|
|
134
143
|
*
|