crossws 0.4.4 → 0.4.6
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/adapters/bunny.d.ts +2 -0
- package/adapters/vercel.d.ts +2 -0
- package/dist/THIRD-PARTY-LICENSES.md +33 -0
- package/dist/_chunks/_request.mjs +1 -4
- package/dist/_chunks/_types.d.mts +9 -10
- package/dist/_chunks/adapter.d.mts +7 -15
- package/dist/_chunks/adapter.mjs +6 -7
- package/dist/_chunks/bun.d.mts +2 -5
- package/dist/_chunks/bunny.d.mts +22 -0
- package/dist/_chunks/cloudflare.d.mts +3 -6
- package/dist/_chunks/deno.d.mts +2 -5
- package/dist/_chunks/error.mjs +1 -4
- package/dist/_chunks/libs/ws.mjs +96 -1171
- package/dist/_chunks/node.d.mts +36 -7
- package/dist/_chunks/node.mjs +129 -0
- package/dist/_chunks/peer.mjs +2 -60
- package/dist/_chunks/rolldown-runtime.mjs +8 -16
- package/dist/_chunks/sse.d.mts +2 -5
- package/dist/_chunks/web.d.mts +1 -3
- package/dist/adapters/bun.d.mts +1 -1
- package/dist/adapters/bun.mjs +3 -8
- package/dist/adapters/bunny.d.mts +2 -0
- package/dist/adapters/bunny.mjs +68 -0
- package/dist/adapters/cloudflare.d.mts +1 -1
- package/dist/adapters/cloudflare.mjs +11 -15
- package/dist/adapters/deno.d.mts +1 -1
- package/dist/adapters/deno.mjs +4 -9
- package/dist/adapters/node.d.mts +2 -2
- package/dist/adapters/node.mjs +2 -125
- package/dist/adapters/sse.d.mts +1 -1
- package/dist/adapters/sse.mjs +3 -8
- package/dist/adapters/uws.d.mts +2 -7
- package/dist/adapters/uws.mjs +6 -10
- package/dist/adapters/vercel.d.mts +25 -0
- package/dist/adapters/vercel.mjs +48 -0
- package/dist/index.d.mts +97 -2
- package/dist/index.mjs +178 -3
- package/dist/server/bun.d.mts +1 -7
- package/dist/server/bun.mjs +3 -7
- package/dist/server/bunny.d.mts +5 -0
- package/dist/server/bunny.mjs +23 -0
- package/dist/server/cloudflare.d.mts +1 -7
- package/dist/server/cloudflare.mjs +3 -7
- package/dist/server/default.d.mts +1 -7
- package/dist/server/default.mjs +3 -7
- package/dist/server/deno.d.mts +1 -7
- package/dist/server/deno.mjs +3 -7
- package/dist/server/node.d.mts +1 -7
- package/dist/server/node.mjs +3 -9
- package/dist/websocket/native.d.mts +0 -2
- package/dist/websocket/native.mjs +1 -5
- package/dist/websocket/node.d.mts +0 -2
- package/dist/websocket/node.mjs +2 -8
- package/dist/websocket/sse.d.mts +1 -4
- package/dist/websocket/sse.mjs +1 -4
- package/package.json +45 -42
- package/server/bunny.d.ts +2 -0
package/dist/_chunks/libs/ws.mjs
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js
|
|
1
|
+
import { __commonJSMin, __require, __toESM } from "../rolldown-runtime.mjs";
|
|
4
2
|
var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
5
3
|
const BINARY_TYPES = [
|
|
6
4
|
"nodebuffer",
|
|
@@ -22,20 +20,9 @@ var require_constants = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
22
20
|
NOOP: () => {}
|
|
23
21
|
};
|
|
24
22
|
}));
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js
|
|
28
23
|
var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
29
24
|
const { EMPTY_BUFFER } = require_constants();
|
|
30
25
|
const FastBuffer = Buffer[Symbol.species];
|
|
31
|
-
/**
|
|
32
|
-
* Merges an array of buffers into a new buffer.
|
|
33
|
-
*
|
|
34
|
-
* @param {Buffer[]} list The array of buffers to concat
|
|
35
|
-
* @param {Number} totalLength The total length of buffers in the list
|
|
36
|
-
* @return {Buffer} The resulting buffer
|
|
37
|
-
* @public
|
|
38
|
-
*/
|
|
39
26
|
function concat(list, totalLength) {
|
|
40
27
|
if (list.length === 0) return EMPTY_BUFFER;
|
|
41
28
|
if (list.length === 1) return list[0];
|
|
@@ -49,48 +36,16 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
49
36
|
if (offset < totalLength) return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
50
37
|
return target;
|
|
51
38
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Masks a buffer using the given mask.
|
|
54
|
-
*
|
|
55
|
-
* @param {Buffer} source The buffer to mask
|
|
56
|
-
* @param {Buffer} mask The mask to use
|
|
57
|
-
* @param {Buffer} output The buffer where to store the result
|
|
58
|
-
* @param {Number} offset The offset at which to start writing
|
|
59
|
-
* @param {Number} length The number of bytes to mask.
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
39
|
function _mask(source, mask, output, offset, length) {
|
|
63
40
|
for (let i = 0; i < length; i++) output[offset + i] = source[i] ^ mask[i & 3];
|
|
64
41
|
}
|
|
65
|
-
/**
|
|
66
|
-
* Unmasks a buffer using the given mask.
|
|
67
|
-
*
|
|
68
|
-
* @param {Buffer} buffer The buffer to unmask
|
|
69
|
-
* @param {Buffer} mask The mask to use
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
42
|
function _unmask(buffer, mask) {
|
|
73
43
|
for (let i = 0; i < buffer.length; i++) buffer[i] ^= mask[i & 3];
|
|
74
44
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Converts a buffer to an `ArrayBuffer`.
|
|
77
|
-
*
|
|
78
|
-
* @param {Buffer} buf The buffer to convert
|
|
79
|
-
* @return {ArrayBuffer} Converted buffer
|
|
80
|
-
* @public
|
|
81
|
-
*/
|
|
82
45
|
function toArrayBuffer(buf) {
|
|
83
46
|
if (buf.length === buf.buffer.byteLength) return buf.buffer;
|
|
84
47
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
85
48
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Converts `data` to a `Buffer`.
|
|
88
|
-
*
|
|
89
|
-
* @param {*} data The data to convert
|
|
90
|
-
* @return {Buffer} The buffer
|
|
91
|
-
* @throws {TypeError}
|
|
92
|
-
* @public
|
|
93
|
-
*/
|
|
94
49
|
function toBuffer(data) {
|
|
95
50
|
toBuffer.readOnly = true;
|
|
96
51
|
if (Buffer.isBuffer(data)) return data;
|
|
@@ -110,7 +65,6 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
110
65
|
toBuffer,
|
|
111
66
|
unmask: _unmask
|
|
112
67
|
};
|
|
113
|
-
/* istanbul ignore else */
|
|
114
68
|
if (!process.env.WS_NO_BUFFER_UTIL) try {
|
|
115
69
|
const bufferUtil = __require("bufferutil");
|
|
116
70
|
module.exports.mask = function(source, mask, output, offset, length) {
|
|
@@ -123,23 +77,10 @@ var require_buffer_util = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
123
77
|
};
|
|
124
78
|
} catch (e) {}
|
|
125
79
|
}));
|
|
126
|
-
|
|
127
|
-
//#endregion
|
|
128
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js
|
|
129
80
|
var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
130
81
|
const kDone = Symbol("kDone");
|
|
131
82
|
const kRun = Symbol("kRun");
|
|
132
|
-
/**
|
|
133
|
-
* A very simple job queue with adjustable concurrency. Adapted from
|
|
134
|
-
* https://github.com/STRML/async-limiter
|
|
135
|
-
*/
|
|
136
83
|
var Limiter = class {
|
|
137
|
-
/**
|
|
138
|
-
* Creates a new `Limiter`.
|
|
139
|
-
*
|
|
140
|
-
* @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
|
|
141
|
-
* to run concurrently
|
|
142
|
-
*/
|
|
143
84
|
constructor(concurrency) {
|
|
144
85
|
this[kDone] = () => {
|
|
145
86
|
this.pending--;
|
|
@@ -149,21 +90,10 @@ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
149
90
|
this.jobs = [];
|
|
150
91
|
this.pending = 0;
|
|
151
92
|
}
|
|
152
|
-
/**
|
|
153
|
-
* Adds a job to the queue.
|
|
154
|
-
*
|
|
155
|
-
* @param {Function} job The job to run
|
|
156
|
-
* @public
|
|
157
|
-
*/
|
|
158
93
|
add(job) {
|
|
159
94
|
this.jobs.push(job);
|
|
160
95
|
this[kRun]();
|
|
161
96
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Removes a job from the queue and runs it if possible.
|
|
164
|
-
*
|
|
165
|
-
* @private
|
|
166
|
-
*/
|
|
167
97
|
[kRun]() {
|
|
168
98
|
if (this.pending === this.concurrency) return;
|
|
169
99
|
if (this.jobs.length) {
|
|
@@ -175,9 +105,6 @@ var require_limiter = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
175
105
|
};
|
|
176
106
|
module.exports = Limiter;
|
|
177
107
|
}));
|
|
178
|
-
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js
|
|
181
108
|
var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
182
109
|
const zlib = __require("zlib");
|
|
183
110
|
const bufferUtil = require_buffer_util();
|
|
@@ -196,56 +123,20 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
196
123
|
const kBuffers = Symbol("buffers");
|
|
197
124
|
const kError = Symbol("error");
|
|
198
125
|
let zlibLimiter;
|
|
199
|
-
/**
|
|
200
|
-
* permessage-deflate implementation.
|
|
201
|
-
*/
|
|
202
126
|
var PerMessageDeflate = class {
|
|
203
|
-
|
|
204
|
-
* Creates a PerMessageDeflate instance.
|
|
205
|
-
*
|
|
206
|
-
* @param {Object} [options] Configuration options
|
|
207
|
-
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
|
|
208
|
-
* for, or request, a custom client window size
|
|
209
|
-
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
|
|
210
|
-
* acknowledge disabling of client context takeover
|
|
211
|
-
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
|
|
212
|
-
* calls to zlib
|
|
213
|
-
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
|
|
214
|
-
* use of a custom server window size
|
|
215
|
-
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
|
|
216
|
-
* disabling of server context takeover
|
|
217
|
-
* @param {Number} [options.threshold=1024] Size (in bytes) below which
|
|
218
|
-
* messages should not be compressed if context takeover is disabled
|
|
219
|
-
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
|
|
220
|
-
* deflate
|
|
221
|
-
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
|
|
222
|
-
* inflate
|
|
223
|
-
* @param {Boolean} [isServer=false] Create the instance in either server or
|
|
224
|
-
* client mode
|
|
225
|
-
* @param {Number} [maxPayload=0] The maximum allowed message length
|
|
226
|
-
*/
|
|
227
|
-
constructor(options, isServer, maxPayload) {
|
|
228
|
-
this._maxPayload = maxPayload | 0;
|
|
127
|
+
constructor(options) {
|
|
229
128
|
this._options = options || {};
|
|
230
129
|
this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
|
|
231
|
-
this.
|
|
130
|
+
this._maxPayload = this._options.maxPayload | 0;
|
|
131
|
+
this._isServer = !!this._options.isServer;
|
|
232
132
|
this._deflate = null;
|
|
233
133
|
this._inflate = null;
|
|
234
134
|
this.params = null;
|
|
235
135
|
if (!zlibLimiter) zlibLimiter = new Limiter(this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10);
|
|
236
136
|
}
|
|
237
|
-
/**
|
|
238
|
-
* @type {String}
|
|
239
|
-
*/
|
|
240
137
|
static get extensionName() {
|
|
241
138
|
return "permessage-deflate";
|
|
242
139
|
}
|
|
243
|
-
/**
|
|
244
|
-
* Create an extension negotiation offer.
|
|
245
|
-
*
|
|
246
|
-
* @return {Object} Extension parameters
|
|
247
|
-
* @public
|
|
248
|
-
*/
|
|
249
140
|
offer() {
|
|
250
141
|
const params = {};
|
|
251
142
|
if (this._options.serverNoContextTakeover) params.server_no_context_takeover = true;
|
|
@@ -255,23 +146,11 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
255
146
|
else if (this._options.clientMaxWindowBits == null) params.client_max_window_bits = true;
|
|
256
147
|
return params;
|
|
257
148
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Accept an extension negotiation offer/response.
|
|
260
|
-
*
|
|
261
|
-
* @param {Array} configurations The extension negotiation offers/reponse
|
|
262
|
-
* @return {Object} Accepted configuration
|
|
263
|
-
* @public
|
|
264
|
-
*/
|
|
265
149
|
accept(configurations) {
|
|
266
150
|
configurations = this.normalizeParams(configurations);
|
|
267
151
|
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
268
152
|
return this.params;
|
|
269
153
|
}
|
|
270
|
-
/**
|
|
271
|
-
* Releases all resources used by the extension.
|
|
272
|
-
*
|
|
273
|
-
* @public
|
|
274
|
-
*/
|
|
275
154
|
cleanup() {
|
|
276
155
|
if (this._inflate) {
|
|
277
156
|
this._inflate.close();
|
|
@@ -284,13 +163,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
284
163
|
if (callback) callback(/* @__PURE__ */ new Error("The deflate stream was closed while data was being processed"));
|
|
285
164
|
}
|
|
286
165
|
}
|
|
287
|
-
/**
|
|
288
|
-
* Accept an extension negotiation offer.
|
|
289
|
-
*
|
|
290
|
-
* @param {Array} offers The extension negotiation offers
|
|
291
|
-
* @return {Object} Accepted configuration
|
|
292
|
-
* @private
|
|
293
|
-
*/
|
|
294
166
|
acceptAsServer(offers) {
|
|
295
167
|
const opts = this._options;
|
|
296
168
|
const accepted = offers.find((params) => {
|
|
@@ -305,13 +177,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
305
177
|
else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) delete accepted.client_max_window_bits;
|
|
306
178
|
return accepted;
|
|
307
179
|
}
|
|
308
|
-
/**
|
|
309
|
-
* Accept the extension negotiation response.
|
|
310
|
-
*
|
|
311
|
-
* @param {Array} response The extension negotiation response
|
|
312
|
-
* @return {Object} Accepted configuration
|
|
313
|
-
* @private
|
|
314
|
-
*/
|
|
315
180
|
acceptAsClient(response) {
|
|
316
181
|
const params = response[0];
|
|
317
182
|
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) throw new Error("Unexpected parameter \"client_no_context_takeover\"");
|
|
@@ -320,13 +185,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
320
185
|
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) throw new Error("Unexpected or invalid parameter \"client_max_window_bits\"");
|
|
321
186
|
return params;
|
|
322
187
|
}
|
|
323
|
-
/**
|
|
324
|
-
* Normalize parameters.
|
|
325
|
-
*
|
|
326
|
-
* @param {Array} configurations The extension negotiation offers/reponse
|
|
327
|
-
* @return {Array} The offers/response with normalized parameters
|
|
328
|
-
* @private
|
|
329
|
-
*/
|
|
330
188
|
normalizeParams(configurations) {
|
|
331
189
|
configurations.forEach((params) => {
|
|
332
190
|
Object.keys(params).forEach((key) => {
|
|
@@ -351,14 +209,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
351
209
|
});
|
|
352
210
|
return configurations;
|
|
353
211
|
}
|
|
354
|
-
/**
|
|
355
|
-
* Decompress data. Concurrency limited.
|
|
356
|
-
*
|
|
357
|
-
* @param {Buffer} data Compressed data
|
|
358
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
359
|
-
* @param {Function} callback Callback
|
|
360
|
-
* @public
|
|
361
|
-
*/
|
|
362
212
|
decompress(data, fin, callback) {
|
|
363
213
|
zlibLimiter.add((done) => {
|
|
364
214
|
this._decompress(data, fin, (err, result) => {
|
|
@@ -367,14 +217,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
367
217
|
});
|
|
368
218
|
});
|
|
369
219
|
}
|
|
370
|
-
/**
|
|
371
|
-
* Compress data. Concurrency limited.
|
|
372
|
-
*
|
|
373
|
-
* @param {(Buffer|String)} data Data to compress
|
|
374
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
375
|
-
* @param {Function} callback Callback
|
|
376
|
-
* @public
|
|
377
|
-
*/
|
|
378
220
|
compress(data, fin, callback) {
|
|
379
221
|
zlibLimiter.add((done) => {
|
|
380
222
|
this._compress(data, fin, (err, result) => {
|
|
@@ -383,14 +225,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
383
225
|
});
|
|
384
226
|
});
|
|
385
227
|
}
|
|
386
|
-
/**
|
|
387
|
-
* Decompress data.
|
|
388
|
-
*
|
|
389
|
-
* @param {Buffer} data Compressed data
|
|
390
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
391
|
-
* @param {Function} callback Callback
|
|
392
|
-
* @private
|
|
393
|
-
*/
|
|
394
228
|
_decompress(data, fin, callback) {
|
|
395
229
|
const endpoint = this._isServer ? "client" : "server";
|
|
396
230
|
if (!this._inflate) {
|
|
@@ -429,14 +263,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
429
263
|
callback(null, data);
|
|
430
264
|
});
|
|
431
265
|
}
|
|
432
|
-
/**
|
|
433
|
-
* Compress data.
|
|
434
|
-
*
|
|
435
|
-
* @param {(Buffer|String)} data Data to compress
|
|
436
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
437
|
-
* @param {Function} callback Callback
|
|
438
|
-
* @private
|
|
439
|
-
*/
|
|
440
266
|
_compress(data, fin, callback) {
|
|
441
267
|
const endpoint = this._isServer ? "server" : "client";
|
|
442
268
|
if (!this._deflate) {
|
|
@@ -465,22 +291,10 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
465
291
|
}
|
|
466
292
|
};
|
|
467
293
|
module.exports = PerMessageDeflate;
|
|
468
|
-
/**
|
|
469
|
-
* The listener of the `zlib.DeflateRaw` stream `'data'` event.
|
|
470
|
-
*
|
|
471
|
-
* @param {Buffer} chunk A chunk of data
|
|
472
|
-
* @private
|
|
473
|
-
*/
|
|
474
294
|
function deflateOnData(chunk) {
|
|
475
295
|
this[kBuffers].push(chunk);
|
|
476
296
|
this[kTotalLength] += chunk.length;
|
|
477
297
|
}
|
|
478
|
-
/**
|
|
479
|
-
* The listener of the `zlib.InflateRaw` stream `'data'` event.
|
|
480
|
-
*
|
|
481
|
-
* @param {Buffer} chunk A chunk of data
|
|
482
|
-
* @private
|
|
483
|
-
*/
|
|
484
298
|
function inflateOnData(chunk) {
|
|
485
299
|
this[kTotalLength] += chunk.length;
|
|
486
300
|
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
@@ -493,12 +307,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
493
307
|
this.removeListener("data", inflateOnData);
|
|
494
308
|
this.reset();
|
|
495
309
|
}
|
|
496
|
-
/**
|
|
497
|
-
* The listener of the `zlib.InflateRaw` stream `'error'` event.
|
|
498
|
-
*
|
|
499
|
-
* @param {Error} err The emitted error
|
|
500
|
-
* @private
|
|
501
|
-
*/
|
|
502
310
|
function inflateOnError(err) {
|
|
503
311
|
this[kPerMessageDeflate]._inflate = null;
|
|
504
312
|
if (this[kError]) {
|
|
@@ -509,9 +317,6 @@ var require_permessage_deflate = /* @__PURE__ */ __commonJSMin(((exports, module
|
|
|
509
317
|
this[kCallback](err);
|
|
510
318
|
}
|
|
511
319
|
}));
|
|
512
|
-
|
|
513
|
-
//#endregion
|
|
514
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js
|
|
515
320
|
var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
516
321
|
const { isUtf8 } = __require("buffer");
|
|
517
322
|
const { hasBlob } = require_constants();
|
|
@@ -645,25 +450,9 @@ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
645
450
|
1,
|
|
646
451
|
0
|
|
647
452
|
];
|
|
648
|
-
/**
|
|
649
|
-
* Checks if a status code is allowed in a close frame.
|
|
650
|
-
*
|
|
651
|
-
* @param {Number} code The status code
|
|
652
|
-
* @return {Boolean} `true` if the status code is valid, else `false`
|
|
653
|
-
* @public
|
|
654
|
-
*/
|
|
655
453
|
function isValidStatusCode(code) {
|
|
656
454
|
return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
|
|
657
455
|
}
|
|
658
|
-
/**
|
|
659
|
-
* Checks if a given buffer contains only correct UTF-8.
|
|
660
|
-
* Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
|
|
661
|
-
* Markus Kuhn.
|
|
662
|
-
*
|
|
663
|
-
* @param {Buffer} buf The buffer to check
|
|
664
|
-
* @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
|
|
665
|
-
* @public
|
|
666
|
-
*/
|
|
667
456
|
function _isValidUTF8(buf) {
|
|
668
457
|
const len = buf.length;
|
|
669
458
|
let i = 0;
|
|
@@ -680,13 +469,6 @@ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
680
469
|
} else return false;
|
|
681
470
|
return true;
|
|
682
471
|
}
|
|
683
|
-
/**
|
|
684
|
-
* Determines whether a value is a `Blob`.
|
|
685
|
-
*
|
|
686
|
-
* @param {*} value The value to be tested
|
|
687
|
-
* @return {Boolean} `true` if `value` is a `Blob`, else `false`
|
|
688
|
-
* @private
|
|
689
|
-
*/
|
|
690
472
|
function isBlob(value) {
|
|
691
473
|
return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
|
|
692
474
|
}
|
|
@@ -706,9 +488,6 @@ var require_validation = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
706
488
|
};
|
|
707
489
|
} catch (e) {}
|
|
708
490
|
}));
|
|
709
|
-
|
|
710
|
-
//#endregion
|
|
711
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js
|
|
712
491
|
var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
713
492
|
const { Writable } = __require("stream");
|
|
714
493
|
const PerMessageDeflate = require_permessage_deflate();
|
|
@@ -723,34 +502,15 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
723
502
|
const GET_DATA = 4;
|
|
724
503
|
const INFLATING = 5;
|
|
725
504
|
const DEFER_EVENT = 6;
|
|
726
|
-
/**
|
|
727
|
-
* HyBi Receiver implementation.
|
|
728
|
-
*
|
|
729
|
-
* @extends Writable
|
|
730
|
-
*/
|
|
731
505
|
var Receiver = class extends Writable {
|
|
732
|
-
/**
|
|
733
|
-
* Creates a Receiver instance.
|
|
734
|
-
*
|
|
735
|
-
* @param {Object} [options] Options object
|
|
736
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
737
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
738
|
-
* multiple times in the same tick
|
|
739
|
-
* @param {String} [options.binaryType=nodebuffer] The type for binary data
|
|
740
|
-
* @param {Object} [options.extensions] An object containing the negotiated
|
|
741
|
-
* extensions
|
|
742
|
-
* @param {Boolean} [options.isServer=false] Specifies whether to operate in
|
|
743
|
-
* client or server mode
|
|
744
|
-
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
|
745
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
746
|
-
* not to skip UTF-8 validation for text and close messages
|
|
747
|
-
*/
|
|
748
506
|
constructor(options = {}) {
|
|
749
507
|
super();
|
|
750
508
|
this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
|
|
751
509
|
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
752
510
|
this._extensions = options.extensions || {};
|
|
753
511
|
this._isServer = !!options.isServer;
|
|
512
|
+
this._maxBufferedChunks = options.maxBufferedChunks | 0;
|
|
513
|
+
this._maxFragments = options.maxFragments | 0;
|
|
754
514
|
this._maxPayload = options.maxPayload | 0;
|
|
755
515
|
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
756
516
|
this[kWebSocket] = void 0;
|
|
@@ -770,27 +530,16 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
770
530
|
this._loop = false;
|
|
771
531
|
this._state = GET_INFO;
|
|
772
532
|
}
|
|
773
|
-
/**
|
|
774
|
-
* Implements `Writable.prototype._write()`.
|
|
775
|
-
*
|
|
776
|
-
* @param {Buffer} chunk The chunk of data to write
|
|
777
|
-
* @param {String} encoding The character encoding of `chunk`
|
|
778
|
-
* @param {Function} cb Callback
|
|
779
|
-
* @private
|
|
780
|
-
*/
|
|
781
533
|
_write(chunk, encoding, cb) {
|
|
782
534
|
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
535
|
+
if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
|
|
536
|
+
cb(this.createError(RangeError, "Too many buffered chunks", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
783
539
|
this._bufferedBytes += chunk.length;
|
|
784
540
|
this._buffers.push(chunk);
|
|
785
541
|
this.startLoop(cb);
|
|
786
542
|
}
|
|
787
|
-
/**
|
|
788
|
-
* Consumes `n` bytes from the buffered data.
|
|
789
|
-
*
|
|
790
|
-
* @param {Number} n The number of bytes to consume
|
|
791
|
-
* @return {Buffer} The consumed bytes
|
|
792
|
-
* @private
|
|
793
|
-
*/
|
|
794
543
|
consume(n) {
|
|
795
544
|
this._bufferedBytes -= n;
|
|
796
545
|
if (n === this._buffers[0].length) return this._buffers.shift();
|
|
@@ -812,12 +561,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
812
561
|
} while (n > 0);
|
|
813
562
|
return dst;
|
|
814
563
|
}
|
|
815
|
-
/**
|
|
816
|
-
* Starts the parsing loop.
|
|
817
|
-
*
|
|
818
|
-
* @param {Function} cb Callback
|
|
819
|
-
* @private
|
|
820
|
-
*/
|
|
821
564
|
startLoop(cb) {
|
|
822
565
|
this._loop = true;
|
|
823
566
|
do
|
|
@@ -845,12 +588,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
845
588
|
while (this._loop);
|
|
846
589
|
if (!this._errored) cb();
|
|
847
590
|
}
|
|
848
|
-
/**
|
|
849
|
-
* Reads the first two bytes of a frame.
|
|
850
|
-
*
|
|
851
|
-
* @param {Function} cb Callback
|
|
852
|
-
* @private
|
|
853
|
-
*/
|
|
854
591
|
getInfo(cb) {
|
|
855
592
|
if (this._bufferedBytes < 2) {
|
|
856
593
|
this._loop = false;
|
|
@@ -917,12 +654,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
917
654
|
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
918
655
|
else this.haveLength(cb);
|
|
919
656
|
}
|
|
920
|
-
/**
|
|
921
|
-
* Gets extended payload length (7+16).
|
|
922
|
-
*
|
|
923
|
-
* @param {Function} cb Callback
|
|
924
|
-
* @private
|
|
925
|
-
*/
|
|
926
657
|
getPayloadLength16(cb) {
|
|
927
658
|
if (this._bufferedBytes < 2) {
|
|
928
659
|
this._loop = false;
|
|
@@ -931,12 +662,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
931
662
|
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
932
663
|
this.haveLength(cb);
|
|
933
664
|
}
|
|
934
|
-
/**
|
|
935
|
-
* Gets extended payload length (7+64).
|
|
936
|
-
*
|
|
937
|
-
* @param {Function} cb Callback
|
|
938
|
-
* @private
|
|
939
|
-
*/
|
|
940
665
|
getPayloadLength64(cb) {
|
|
941
666
|
if (this._bufferedBytes < 8) {
|
|
942
667
|
this._loop = false;
|
|
@@ -951,12 +676,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
951
676
|
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
952
677
|
this.haveLength(cb);
|
|
953
678
|
}
|
|
954
|
-
/**
|
|
955
|
-
* Payload length has been read.
|
|
956
|
-
*
|
|
957
|
-
* @param {Function} cb Callback
|
|
958
|
-
* @private
|
|
959
|
-
*/
|
|
960
679
|
haveLength(cb) {
|
|
961
680
|
if (this._payloadLength && this._opcode < 8) {
|
|
962
681
|
this._totalPayloadLength += this._payloadLength;
|
|
@@ -968,11 +687,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
968
687
|
if (this._masked) this._state = GET_MASK;
|
|
969
688
|
else this._state = GET_DATA;
|
|
970
689
|
}
|
|
971
|
-
/**
|
|
972
|
-
* Reads mask bytes.
|
|
973
|
-
*
|
|
974
|
-
* @private
|
|
975
|
-
*/
|
|
976
690
|
getMask() {
|
|
977
691
|
if (this._bufferedBytes < 4) {
|
|
978
692
|
this._loop = false;
|
|
@@ -981,12 +695,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
981
695
|
this._mask = this.consume(4);
|
|
982
696
|
this._state = GET_DATA;
|
|
983
697
|
}
|
|
984
|
-
/**
|
|
985
|
-
* Reads data bytes.
|
|
986
|
-
*
|
|
987
|
-
* @param {Function} cb Callback
|
|
988
|
-
* @private
|
|
989
|
-
*/
|
|
990
698
|
getData(cb) {
|
|
991
699
|
let data = EMPTY_BUFFER;
|
|
992
700
|
if (this._payloadLength) {
|
|
@@ -1007,18 +715,15 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1007
715
|
return;
|
|
1008
716
|
}
|
|
1009
717
|
if (data.length) {
|
|
718
|
+
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
719
|
+
cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
1010
722
|
this._messageLength = this._totalPayloadLength;
|
|
1011
723
|
this._fragments.push(data);
|
|
1012
724
|
}
|
|
1013
725
|
this.dataMessage(cb);
|
|
1014
726
|
}
|
|
1015
|
-
/**
|
|
1016
|
-
* Decompresses data.
|
|
1017
|
-
*
|
|
1018
|
-
* @param {Buffer} data Compressed data
|
|
1019
|
-
* @param {Function} cb Callback
|
|
1020
|
-
* @private
|
|
1021
|
-
*/
|
|
1022
727
|
decompress(data, cb) {
|
|
1023
728
|
this._extensions[PerMessageDeflate.extensionName].decompress(data, this._fin, (err, buf) => {
|
|
1024
729
|
if (err) return cb(err);
|
|
@@ -1028,18 +733,16 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1028
733
|
cb(this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"));
|
|
1029
734
|
return;
|
|
1030
735
|
}
|
|
736
|
+
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
737
|
+
cb(this.createError(RangeError, "Too many message fragments", false, 1008, "WS_ERR_TOO_MANY_BUFFERED_PARTS"));
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
1031
740
|
this._fragments.push(buf);
|
|
1032
741
|
}
|
|
1033
742
|
this.dataMessage(cb);
|
|
1034
743
|
if (this._state === GET_INFO) this.startLoop(cb);
|
|
1035
744
|
});
|
|
1036
745
|
}
|
|
1037
|
-
/**
|
|
1038
|
-
* Handles a data message.
|
|
1039
|
-
*
|
|
1040
|
-
* @param {Function} cb Callback
|
|
1041
|
-
* @private
|
|
1042
|
-
*/
|
|
1043
746
|
dataMessage(cb) {
|
|
1044
747
|
if (!this._fin) {
|
|
1045
748
|
this._state = GET_INFO;
|
|
@@ -1087,13 +790,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1087
790
|
}
|
|
1088
791
|
}
|
|
1089
792
|
}
|
|
1090
|
-
/**
|
|
1091
|
-
* Handles a control message.
|
|
1092
|
-
*
|
|
1093
|
-
* @param {Buffer} data Data to handle
|
|
1094
|
-
* @return {(Error|RangeError|undefined)} A possible error
|
|
1095
|
-
* @private
|
|
1096
|
-
*/
|
|
1097
793
|
controlMessage(data, cb) {
|
|
1098
794
|
if (this._opcode === 8) {
|
|
1099
795
|
if (data.length === 0) {
|
|
@@ -1130,18 +826,6 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1130
826
|
});
|
|
1131
827
|
}
|
|
1132
828
|
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Builds an error object.
|
|
1135
|
-
*
|
|
1136
|
-
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
1137
|
-
* @param {String} message The error message
|
|
1138
|
-
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
1139
|
-
* `message`
|
|
1140
|
-
* @param {Number} statusCode The status code
|
|
1141
|
-
* @param {String} errorCode The exposed error code
|
|
1142
|
-
* @return {(Error|RangeError)} The error
|
|
1143
|
-
* @private
|
|
1144
|
-
*/
|
|
1145
829
|
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
1146
830
|
this._loop = false;
|
|
1147
831
|
this._errored = true;
|
|
@@ -1154,12 +838,10 @@ var require_receiver = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1154
838
|
};
|
|
1155
839
|
module.exports = Receiver;
|
|
1156
840
|
}));
|
|
1157
|
-
|
|
1158
|
-
//#endregion
|
|
1159
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js
|
|
1160
841
|
var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1161
842
|
const { Duplex: Duplex$3 } = __require("stream");
|
|
1162
843
|
const { randomFillSync } = __require("crypto");
|
|
844
|
+
const { types: { isUint8Array } } = __require("util");
|
|
1163
845
|
const PerMessageDeflate = require_permessage_deflate();
|
|
1164
846
|
const { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
|
|
1165
847
|
const { isBlob, isValidStatusCode } = require_validation();
|
|
@@ -1172,18 +854,7 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1172
854
|
const DEFAULT = 0;
|
|
1173
855
|
const DEFLATING = 1;
|
|
1174
856
|
const GET_BLOB_DATA = 2;
|
|
1175
|
-
|
|
1176
|
-
* HyBi Sender implementation.
|
|
1177
|
-
*/
|
|
1178
|
-
var Sender = class Sender {
|
|
1179
|
-
/**
|
|
1180
|
-
* Creates a Sender instance.
|
|
1181
|
-
*
|
|
1182
|
-
* @param {Duplex} socket The connection socket
|
|
1183
|
-
* @param {Object} [extensions] An object containing the negotiated extensions
|
|
1184
|
-
* @param {Function} [generateMask] The function used to generate the masking
|
|
1185
|
-
* key
|
|
1186
|
-
*/
|
|
857
|
+
module.exports = class Sender {
|
|
1187
858
|
constructor(socket, extensions, generateMask) {
|
|
1188
859
|
this._extensions = extensions || {};
|
|
1189
860
|
if (generateMask) {
|
|
@@ -1199,27 +870,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1199
870
|
this.onerror = NOOP;
|
|
1200
871
|
this[kWebSocket] = void 0;
|
|
1201
872
|
}
|
|
1202
|
-
/**
|
|
1203
|
-
* Frames a piece of data according to the HyBi WebSocket protocol.
|
|
1204
|
-
*
|
|
1205
|
-
* @param {(Buffer|String)} data The data to frame
|
|
1206
|
-
* @param {Object} options Options object
|
|
1207
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
1208
|
-
* FIN bit
|
|
1209
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
1210
|
-
* masking key
|
|
1211
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
1212
|
-
* `data`
|
|
1213
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
1214
|
-
* key
|
|
1215
|
-
* @param {Number} options.opcode The opcode
|
|
1216
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
1217
|
-
* modified
|
|
1218
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
1219
|
-
* RSV1 bit
|
|
1220
|
-
* @return {(Buffer|String)[]} The framed data
|
|
1221
|
-
* @public
|
|
1222
|
-
*/
|
|
1223
873
|
static frame(data, options) {
|
|
1224
874
|
let mask;
|
|
1225
875
|
let merge = false;
|
|
@@ -1230,7 +880,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1230
880
|
if (options.generateMask) options.generateMask(mask);
|
|
1231
881
|
else {
|
|
1232
882
|
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
1233
|
-
/* istanbul ignore else */
|
|
1234
883
|
if (randomPool === void 0) randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
1235
884
|
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
1236
885
|
randomPoolPointer = 0;
|
|
@@ -1284,15 +933,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1284
933
|
applyMask(data, mask, data, 0, dataLength);
|
|
1285
934
|
return [target, data];
|
|
1286
935
|
}
|
|
1287
|
-
/**
|
|
1288
|
-
* Sends a close message to the other peer.
|
|
1289
|
-
*
|
|
1290
|
-
* @param {Number} [code] The status code component of the body
|
|
1291
|
-
* @param {(String|Buffer)} [data] The message component of the body
|
|
1292
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask the message
|
|
1293
|
-
* @param {Function} [cb] Callback
|
|
1294
|
-
* @public
|
|
1295
|
-
*/
|
|
1296
936
|
close(code, data, mask, cb) {
|
|
1297
937
|
let buf;
|
|
1298
938
|
if (code === void 0) buf = EMPTY_BUFFER;
|
|
@@ -1306,7 +946,8 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1306
946
|
buf = Buffer.allocUnsafe(2 + length);
|
|
1307
947
|
buf.writeUInt16BE(code, 0);
|
|
1308
948
|
if (typeof data === "string") buf.write(data, 2);
|
|
1309
|
-
else buf.set(data, 2);
|
|
949
|
+
else if (isUint8Array(data)) buf.set(data, 2);
|
|
950
|
+
else throw new TypeError("Second argument must be a string or a Uint8Array");
|
|
1310
951
|
}
|
|
1311
952
|
const options = {
|
|
1312
953
|
[kByteLength]: buf.length,
|
|
@@ -1327,14 +968,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1327
968
|
]);
|
|
1328
969
|
else this.sendFrame(Sender.frame(buf, options), cb);
|
|
1329
970
|
}
|
|
1330
|
-
/**
|
|
1331
|
-
* Sends a ping message to the other peer.
|
|
1332
|
-
*
|
|
1333
|
-
* @param {*} data The message to send
|
|
1334
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
1335
|
-
* @param {Function} [cb] Callback
|
|
1336
|
-
* @public
|
|
1337
|
-
*/
|
|
1338
971
|
ping(data, mask, cb) {
|
|
1339
972
|
let byteLength;
|
|
1340
973
|
let readOnly;
|
|
@@ -1377,14 +1010,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1377
1010
|
]);
|
|
1378
1011
|
else this.sendFrame(Sender.frame(data, options), cb);
|
|
1379
1012
|
}
|
|
1380
|
-
/**
|
|
1381
|
-
* Sends a pong message to the other peer.
|
|
1382
|
-
*
|
|
1383
|
-
* @param {*} data The message to send
|
|
1384
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
1385
|
-
* @param {Function} [cb] Callback
|
|
1386
|
-
* @public
|
|
1387
|
-
*/
|
|
1388
1013
|
pong(data, mask, cb) {
|
|
1389
1014
|
let byteLength;
|
|
1390
1015
|
let readOnly;
|
|
@@ -1427,22 +1052,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1427
1052
|
]);
|
|
1428
1053
|
else this.sendFrame(Sender.frame(data, options), cb);
|
|
1429
1054
|
}
|
|
1430
|
-
/**
|
|
1431
|
-
* Sends a data message to the other peer.
|
|
1432
|
-
*
|
|
1433
|
-
* @param {*} data The message to send
|
|
1434
|
-
* @param {Object} options Options object
|
|
1435
|
-
* @param {Boolean} [options.binary=false] Specifies whether `data` is binary
|
|
1436
|
-
* or text
|
|
1437
|
-
* @param {Boolean} [options.compress=false] Specifies whether or not to
|
|
1438
|
-
* compress `data`
|
|
1439
|
-
* @param {Boolean} [options.fin=false] Specifies whether the fragment is the
|
|
1440
|
-
* last one
|
|
1441
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
1442
|
-
* `data`
|
|
1443
|
-
* @param {Function} [cb] Callback
|
|
1444
|
-
* @public
|
|
1445
|
-
*/
|
|
1446
1055
|
send(data, options, cb) {
|
|
1447
1056
|
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
1448
1057
|
let opcode = options.binary ? 2 : 1;
|
|
@@ -1496,29 +1105,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1496
1105
|
]);
|
|
1497
1106
|
else this.dispatch(data, this._compress, opts, cb);
|
|
1498
1107
|
}
|
|
1499
|
-
/**
|
|
1500
|
-
* Gets the contents of a blob as binary data.
|
|
1501
|
-
*
|
|
1502
|
-
* @param {Blob} blob The blob
|
|
1503
|
-
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
1504
|
-
* the data
|
|
1505
|
-
* @param {Object} options Options object
|
|
1506
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
1507
|
-
* FIN bit
|
|
1508
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
1509
|
-
* masking key
|
|
1510
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
1511
|
-
* `data`
|
|
1512
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
1513
|
-
* key
|
|
1514
|
-
* @param {Number} options.opcode The opcode
|
|
1515
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
1516
|
-
* modified
|
|
1517
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
1518
|
-
* RSV1 bit
|
|
1519
|
-
* @param {Function} [cb] Callback
|
|
1520
|
-
* @private
|
|
1521
|
-
*/
|
|
1522
1108
|
getBlobData(blob, compress, options, cb) {
|
|
1523
1109
|
this._bufferedBytes += options[kByteLength];
|
|
1524
1110
|
this._state = GET_BLOB_DATA;
|
|
@@ -1539,29 +1125,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1539
1125
|
process.nextTick(onError, this, err, cb);
|
|
1540
1126
|
});
|
|
1541
1127
|
}
|
|
1542
|
-
/**
|
|
1543
|
-
* Dispatches a message.
|
|
1544
|
-
*
|
|
1545
|
-
* @param {(Buffer|String)} data The message to send
|
|
1546
|
-
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
1547
|
-
* `data`
|
|
1548
|
-
* @param {Object} options Options object
|
|
1549
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
1550
|
-
* FIN bit
|
|
1551
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
1552
|
-
* masking key
|
|
1553
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
1554
|
-
* `data`
|
|
1555
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
1556
|
-
* key
|
|
1557
|
-
* @param {Number} options.opcode The opcode
|
|
1558
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
1559
|
-
* modified
|
|
1560
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
1561
|
-
* RSV1 bit
|
|
1562
|
-
* @param {Function} [cb] Callback
|
|
1563
|
-
* @private
|
|
1564
|
-
*/
|
|
1565
1128
|
dispatch(data, compress, options, cb) {
|
|
1566
1129
|
if (!compress) {
|
|
1567
1130
|
this.sendFrame(Sender.frame(data, options), cb);
|
|
@@ -1572,7 +1135,8 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1572
1135
|
this._state = DEFLATING;
|
|
1573
1136
|
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
1574
1137
|
if (this._socket.destroyed) {
|
|
1575
|
-
|
|
1138
|
+
const err = /* @__PURE__ */ new Error("The socket was closed while data was being compressed");
|
|
1139
|
+
callCallbacks(this, err, cb);
|
|
1576
1140
|
return;
|
|
1577
1141
|
}
|
|
1578
1142
|
this._bufferedBytes -= options[kByteLength];
|
|
@@ -1582,11 +1146,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1582
1146
|
this.dequeue();
|
|
1583
1147
|
});
|
|
1584
1148
|
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Executes queued send operations.
|
|
1587
|
-
*
|
|
1588
|
-
* @private
|
|
1589
|
-
*/
|
|
1590
1149
|
dequeue() {
|
|
1591
1150
|
while (this._state === DEFAULT && this._queue.length) {
|
|
1592
1151
|
const params = this._queue.shift();
|
|
@@ -1594,23 +1153,10 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1594
1153
|
Reflect.apply(params[0], this, params.slice(1));
|
|
1595
1154
|
}
|
|
1596
1155
|
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Enqueues a send operation.
|
|
1599
|
-
*
|
|
1600
|
-
* @param {Array} params Send operation parameters.
|
|
1601
|
-
* @private
|
|
1602
|
-
*/
|
|
1603
1156
|
enqueue(params) {
|
|
1604
1157
|
this._bufferedBytes += params[3][kByteLength];
|
|
1605
1158
|
this._queue.push(params);
|
|
1606
1159
|
}
|
|
1607
|
-
/**
|
|
1608
|
-
* Sends a frame.
|
|
1609
|
-
*
|
|
1610
|
-
* @param {(Buffer | String)[]} list The frame to send
|
|
1611
|
-
* @param {Function} [cb] Callback
|
|
1612
|
-
* @private
|
|
1613
|
-
*/
|
|
1614
1160
|
sendFrame(list, cb) {
|
|
1615
1161
|
if (list.length === 2) {
|
|
1616
1162
|
this._socket.cork();
|
|
@@ -1620,15 +1166,6 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1620
1166
|
} else this._socket.write(list[0], cb);
|
|
1621
1167
|
}
|
|
1622
1168
|
};
|
|
1623
|
-
module.exports = Sender;
|
|
1624
|
-
/**
|
|
1625
|
-
* Calls queued callbacks with an error.
|
|
1626
|
-
*
|
|
1627
|
-
* @param {Sender} sender The `Sender` instance
|
|
1628
|
-
* @param {Error} err The error to call the callbacks with
|
|
1629
|
-
* @param {Function} [cb] The first callback
|
|
1630
|
-
* @private
|
|
1631
|
-
*/
|
|
1632
1169
|
function callCallbacks(sender, err, cb) {
|
|
1633
1170
|
if (typeof cb === "function") cb(err);
|
|
1634
1171
|
for (let i = 0; i < sender._queue.length; i++) {
|
|
@@ -1637,22 +1174,11 @@ var require_sender = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1637
1174
|
if (typeof callback === "function") callback(err);
|
|
1638
1175
|
}
|
|
1639
1176
|
}
|
|
1640
|
-
/**
|
|
1641
|
-
* Handles a `Sender` error.
|
|
1642
|
-
*
|
|
1643
|
-
* @param {Sender} sender The `Sender` instance
|
|
1644
|
-
* @param {Error} err The error
|
|
1645
|
-
* @param {Function} [cb] The first pending callback
|
|
1646
|
-
* @private
|
|
1647
|
-
*/
|
|
1648
1177
|
function onError(sender, err, cb) {
|
|
1649
1178
|
callCallbacks(sender, err, cb);
|
|
1650
1179
|
sender.onerror(err);
|
|
1651
1180
|
}
|
|
1652
1181
|
}));
|
|
1653
|
-
|
|
1654
|
-
//#endregion
|
|
1655
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js
|
|
1656
1182
|
var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1657
1183
|
const { kForOnEventAttribute, kListener } = require_constants();
|
|
1658
1184
|
const kCode = Symbol("kCode");
|
|
@@ -1663,75 +1189,33 @@ var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1663
1189
|
const kTarget = Symbol("kTarget");
|
|
1664
1190
|
const kType = Symbol("kType");
|
|
1665
1191
|
const kWasClean = Symbol("kWasClean");
|
|
1666
|
-
/**
|
|
1667
|
-
* Class representing an event.
|
|
1668
|
-
*/
|
|
1669
1192
|
var Event = class {
|
|
1670
|
-
/**
|
|
1671
|
-
* Create a new `Event`.
|
|
1672
|
-
*
|
|
1673
|
-
* @param {String} type The name of the event
|
|
1674
|
-
* @throws {TypeError} If the `type` argument is not specified
|
|
1675
|
-
*/
|
|
1676
1193
|
constructor(type) {
|
|
1677
1194
|
this[kTarget] = null;
|
|
1678
1195
|
this[kType] = type;
|
|
1679
1196
|
}
|
|
1680
|
-
/**
|
|
1681
|
-
* @type {*}
|
|
1682
|
-
*/
|
|
1683
1197
|
get target() {
|
|
1684
1198
|
return this[kTarget];
|
|
1685
1199
|
}
|
|
1686
|
-
/**
|
|
1687
|
-
* @type {String}
|
|
1688
|
-
*/
|
|
1689
1200
|
get type() {
|
|
1690
1201
|
return this[kType];
|
|
1691
1202
|
}
|
|
1692
1203
|
};
|
|
1693
1204
|
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
1694
1205
|
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
1695
|
-
/**
|
|
1696
|
-
* Class representing a close event.
|
|
1697
|
-
*
|
|
1698
|
-
* @extends Event
|
|
1699
|
-
*/
|
|
1700
1206
|
var CloseEvent = class extends Event {
|
|
1701
|
-
/**
|
|
1702
|
-
* Create a new `CloseEvent`.
|
|
1703
|
-
*
|
|
1704
|
-
* @param {String} type The name of the event
|
|
1705
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
1706
|
-
* attributes via object members of the same name
|
|
1707
|
-
* @param {Number} [options.code=0] The status code explaining why the
|
|
1708
|
-
* connection was closed
|
|
1709
|
-
* @param {String} [options.reason=''] A human-readable string explaining why
|
|
1710
|
-
* the connection was closed
|
|
1711
|
-
* @param {Boolean} [options.wasClean=false] Indicates whether or not the
|
|
1712
|
-
* connection was cleanly closed
|
|
1713
|
-
*/
|
|
1714
1207
|
constructor(type, options = {}) {
|
|
1715
1208
|
super(type);
|
|
1716
1209
|
this[kCode] = options.code === void 0 ? 0 : options.code;
|
|
1717
1210
|
this[kReason] = options.reason === void 0 ? "" : options.reason;
|
|
1718
1211
|
this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
|
|
1719
1212
|
}
|
|
1720
|
-
/**
|
|
1721
|
-
* @type {Number}
|
|
1722
|
-
*/
|
|
1723
1213
|
get code() {
|
|
1724
1214
|
return this[kCode];
|
|
1725
1215
|
}
|
|
1726
|
-
/**
|
|
1727
|
-
* @type {String}
|
|
1728
|
-
*/
|
|
1729
1216
|
get reason() {
|
|
1730
1217
|
return this[kReason];
|
|
1731
1218
|
}
|
|
1732
|
-
/**
|
|
1733
|
-
* @type {Boolean}
|
|
1734
|
-
*/
|
|
1735
1219
|
get wasClean() {
|
|
1736
1220
|
return this[kWasClean];
|
|
1737
1221
|
}
|
|
@@ -1739,163 +1223,92 @@ var require_event_target = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1739
1223
|
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
1740
1224
|
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
1741
1225
|
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
1742
|
-
/**
|
|
1743
|
-
* Class representing an error event.
|
|
1744
|
-
*
|
|
1745
|
-
* @extends Event
|
|
1746
|
-
*/
|
|
1747
1226
|
var ErrorEvent = class extends Event {
|
|
1748
|
-
/**
|
|
1749
|
-
* Create a new `ErrorEvent`.
|
|
1750
|
-
*
|
|
1751
|
-
* @param {String} type The name of the event
|
|
1752
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
1753
|
-
* attributes via object members of the same name
|
|
1754
|
-
* @param {*} [options.error=null] The error that generated this event
|
|
1755
|
-
* @param {String} [options.message=''] The error message
|
|
1756
|
-
*/
|
|
1757
1227
|
constructor(type, options = {}) {
|
|
1758
1228
|
super(type);
|
|
1759
1229
|
this[kError] = options.error === void 0 ? null : options.error;
|
|
1760
1230
|
this[kMessage] = options.message === void 0 ? "" : options.message;
|
|
1761
1231
|
}
|
|
1762
|
-
/**
|
|
1763
|
-
* @type {*}
|
|
1764
|
-
*/
|
|
1765
1232
|
get error() {
|
|
1766
1233
|
return this[kError];
|
|
1767
1234
|
}
|
|
1768
|
-
/**
|
|
1769
|
-
* @type {String}
|
|
1770
|
-
*/
|
|
1771
1235
|
get message() {
|
|
1772
1236
|
return this[kMessage];
|
|
1773
1237
|
}
|
|
1774
1238
|
};
|
|
1775
1239
|
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
1776
1240
|
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
1777
|
-
/**
|
|
1778
|
-
* Class representing a message event.
|
|
1779
|
-
*
|
|
1780
|
-
* @extends Event
|
|
1781
|
-
*/
|
|
1782
1241
|
var MessageEvent = class extends Event {
|
|
1783
|
-
/**
|
|
1784
|
-
* Create a new `MessageEvent`.
|
|
1785
|
-
*
|
|
1786
|
-
* @param {String} type The name of the event
|
|
1787
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
1788
|
-
* attributes via object members of the same name
|
|
1789
|
-
* @param {*} [options.data=null] The message content
|
|
1790
|
-
*/
|
|
1791
1242
|
constructor(type, options = {}) {
|
|
1792
1243
|
super(type);
|
|
1793
1244
|
this[kData] = options.data === void 0 ? null : options.data;
|
|
1794
1245
|
}
|
|
1795
|
-
/**
|
|
1796
|
-
* @type {*}
|
|
1797
|
-
*/
|
|
1798
1246
|
get data() {
|
|
1799
1247
|
return this[kData];
|
|
1800
1248
|
}
|
|
1801
1249
|
};
|
|
1802
1250
|
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
1803
|
-
/**
|
|
1804
|
-
* This provides methods for emulating the `EventTarget` interface. It's not
|
|
1805
|
-
* meant to be used directly.
|
|
1806
|
-
*
|
|
1807
|
-
* @mixin
|
|
1808
|
-
*/
|
|
1809
|
-
const EventTarget = {
|
|
1810
|
-
addEventListener(type, handler, options = {}) {
|
|
1811
|
-
for (const listener of this.listeners(type)) if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) return;
|
|
1812
|
-
let wrapper;
|
|
1813
|
-
if (type === "message") wrapper = function onMessage(data, isBinary) {
|
|
1814
|
-
const event = new MessageEvent("message", { data: isBinary ? data : data.toString() });
|
|
1815
|
-
event[kTarget] = this;
|
|
1816
|
-
callListener(handler, this, event);
|
|
1817
|
-
};
|
|
1818
|
-
else if (type === "close") wrapper = function onClose(code, message) {
|
|
1819
|
-
const event = new CloseEvent("close", {
|
|
1820
|
-
code,
|
|
1821
|
-
reason: message.toString(),
|
|
1822
|
-
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
1823
|
-
});
|
|
1824
|
-
event[kTarget] = this;
|
|
1825
|
-
callListener(handler, this, event);
|
|
1826
|
-
};
|
|
1827
|
-
else if (type === "error") wrapper = function onError(error) {
|
|
1828
|
-
const event = new ErrorEvent("error", {
|
|
1829
|
-
error,
|
|
1830
|
-
message: error.message
|
|
1831
|
-
});
|
|
1832
|
-
event[kTarget] = this;
|
|
1833
|
-
callListener(handler, this, event);
|
|
1834
|
-
};
|
|
1835
|
-
else if (type === "open") wrapper = function onOpen() {
|
|
1836
|
-
const event = new Event("open");
|
|
1837
|
-
event[kTarget] = this;
|
|
1838
|
-
callListener(handler, this, event);
|
|
1839
|
-
};
|
|
1840
|
-
else return;
|
|
1841
|
-
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
1842
|
-
wrapper[kListener] = handler;
|
|
1843
|
-
if (options.once) this.once(type, wrapper);
|
|
1844
|
-
else this.on(type, wrapper);
|
|
1845
|
-
},
|
|
1846
|
-
removeEventListener(type, handler) {
|
|
1847
|
-
for (const listener of this.listeners(type)) if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1848
|
-
this.removeListener(type, listener);
|
|
1849
|
-
break;
|
|
1850
|
-
}
|
|
1851
|
-
}
|
|
1852
|
-
};
|
|
1853
1251
|
module.exports = {
|
|
1854
1252
|
CloseEvent,
|
|
1855
1253
|
ErrorEvent,
|
|
1856
1254
|
Event,
|
|
1857
|
-
EventTarget
|
|
1255
|
+
EventTarget: {
|
|
1256
|
+
addEventListener(type, handler, options = {}) {
|
|
1257
|
+
for (const listener of this.listeners(type)) if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) return;
|
|
1258
|
+
let wrapper;
|
|
1259
|
+
if (type === "message") wrapper = function onMessage(data, isBinary) {
|
|
1260
|
+
const event = new MessageEvent("message", { data: isBinary ? data : data.toString() });
|
|
1261
|
+
event[kTarget] = this;
|
|
1262
|
+
callListener(handler, this, event);
|
|
1263
|
+
};
|
|
1264
|
+
else if (type === "close") wrapper = function onClose(code, message) {
|
|
1265
|
+
const event = new CloseEvent("close", {
|
|
1266
|
+
code,
|
|
1267
|
+
reason: message.toString(),
|
|
1268
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
1269
|
+
});
|
|
1270
|
+
event[kTarget] = this;
|
|
1271
|
+
callListener(handler, this, event);
|
|
1272
|
+
};
|
|
1273
|
+
else if (type === "error") wrapper = function onError(error) {
|
|
1274
|
+
const event = new ErrorEvent("error", {
|
|
1275
|
+
error,
|
|
1276
|
+
message: error.message
|
|
1277
|
+
});
|
|
1278
|
+
event[kTarget] = this;
|
|
1279
|
+
callListener(handler, this, event);
|
|
1280
|
+
};
|
|
1281
|
+
else if (type === "open") wrapper = function onOpen() {
|
|
1282
|
+
const event = new Event("open");
|
|
1283
|
+
event[kTarget] = this;
|
|
1284
|
+
callListener(handler, this, event);
|
|
1285
|
+
};
|
|
1286
|
+
else return;
|
|
1287
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
1288
|
+
wrapper[kListener] = handler;
|
|
1289
|
+
if (options.once) this.once(type, wrapper);
|
|
1290
|
+
else this.on(type, wrapper);
|
|
1291
|
+
},
|
|
1292
|
+
removeEventListener(type, handler) {
|
|
1293
|
+
for (const listener of this.listeners(type)) if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1294
|
+
this.removeListener(type, listener);
|
|
1295
|
+
break;
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
},
|
|
1858
1299
|
MessageEvent
|
|
1859
1300
|
};
|
|
1860
|
-
/**
|
|
1861
|
-
* Call an event listener
|
|
1862
|
-
*
|
|
1863
|
-
* @param {(Function|Object)} listener The listener to call
|
|
1864
|
-
* @param {*} thisArg The value to use as `this`` when calling the listener
|
|
1865
|
-
* @param {Event} event The event to pass to the listener
|
|
1866
|
-
* @private
|
|
1867
|
-
*/
|
|
1868
1301
|
function callListener(listener, thisArg, event) {
|
|
1869
1302
|
if (typeof listener === "object" && listener.handleEvent) listener.handleEvent.call(listener, event);
|
|
1870
1303
|
else listener.call(thisArg, event);
|
|
1871
1304
|
}
|
|
1872
1305
|
}));
|
|
1873
|
-
|
|
1874
|
-
//#endregion
|
|
1875
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js
|
|
1876
1306
|
var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
1877
1307
|
const { tokenChars } = require_validation();
|
|
1878
|
-
/**
|
|
1879
|
-
* Adds an offer to the map of extension offers or a parameter to the map of
|
|
1880
|
-
* parameters.
|
|
1881
|
-
*
|
|
1882
|
-
* @param {Object} dest The map of extension offers or parameters
|
|
1883
|
-
* @param {String} name The extension or parameter name
|
|
1884
|
-
* @param {(Object|Boolean|String)} elem The extension parameters or the
|
|
1885
|
-
* parameter value
|
|
1886
|
-
* @private
|
|
1887
|
-
*/
|
|
1888
1308
|
function push(dest, name, elem) {
|
|
1889
1309
|
if (dest[name] === void 0) dest[name] = [elem];
|
|
1890
1310
|
else dest[name].push(elem);
|
|
1891
1311
|
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Parses the `Sec-WebSocket-Extensions` header into an object.
|
|
1894
|
-
*
|
|
1895
|
-
* @param {String} header The field value of the header
|
|
1896
|
-
* @return {Object} The parsed object
|
|
1897
|
-
* @public
|
|
1898
|
-
*/
|
|
1899
1312
|
function parse(header) {
|
|
1900
1313
|
const offers = Object.create(null);
|
|
1901
1314
|
let params = Object.create(null);
|
|
@@ -1989,13 +1402,6 @@ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
1989
1402
|
}
|
|
1990
1403
|
return offers;
|
|
1991
1404
|
}
|
|
1992
|
-
/**
|
|
1993
|
-
* Builds the `Sec-WebSocket-Extensions` header field value.
|
|
1994
|
-
*
|
|
1995
|
-
* @param {Object} extensions The map of extensions and parameters to format
|
|
1996
|
-
* @return {String} A string representing the given object
|
|
1997
|
-
* @public
|
|
1998
|
-
*/
|
|
1999
1405
|
function format(extensions) {
|
|
2000
1406
|
return Object.keys(extensions).map((extension) => {
|
|
2001
1407
|
let configurations = extensions[extension];
|
|
@@ -2014,9 +1420,6 @@ var require_extension = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2014
1420
|
parse
|
|
2015
1421
|
};
|
|
2016
1422
|
}));
|
|
2017
|
-
|
|
2018
|
-
//#endregion
|
|
2019
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js
|
|
2020
1423
|
var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2021
1424
|
const EventEmitter$1 = __require("events");
|
|
2022
1425
|
const https = __require("https");
|
|
@@ -2043,19 +1446,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2043
1446
|
"CLOSED"
|
|
2044
1447
|
];
|
|
2045
1448
|
const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
2046
|
-
/**
|
|
2047
|
-
* Class representing a WebSocket.
|
|
2048
|
-
*
|
|
2049
|
-
* @extends EventEmitter
|
|
2050
|
-
*/
|
|
2051
1449
|
var WebSocket = class WebSocket extends EventEmitter$1 {
|
|
2052
|
-
/**
|
|
2053
|
-
* Create a new `WebSocket`.
|
|
2054
|
-
*
|
|
2055
|
-
* @param {(String|URL)} address The URL to which to connect
|
|
2056
|
-
* @param {(String|String[])} [protocols] The subprotocols
|
|
2057
|
-
* @param {Object} [options] Connection options
|
|
2058
|
-
*/
|
|
2059
1450
|
constructor(address, protocols, options) {
|
|
2060
1451
|
super();
|
|
2061
1452
|
this._binaryType = BINARY_TYPES[0];
|
|
@@ -2088,12 +1479,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2088
1479
|
this._isServer = true;
|
|
2089
1480
|
}
|
|
2090
1481
|
}
|
|
2091
|
-
/**
|
|
2092
|
-
* For historical reasons, the custom "nodebuffer" type is used by the default
|
|
2093
|
-
* instead of "blob".
|
|
2094
|
-
*
|
|
2095
|
-
* @type {String}
|
|
2096
|
-
*/
|
|
2097
1482
|
get binaryType() {
|
|
2098
1483
|
return this._binaryType;
|
|
2099
1484
|
}
|
|
@@ -2102,93 +1487,45 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2102
1487
|
this._binaryType = type;
|
|
2103
1488
|
if (this._receiver) this._receiver._binaryType = type;
|
|
2104
1489
|
}
|
|
2105
|
-
/**
|
|
2106
|
-
* @type {Number}
|
|
2107
|
-
*/
|
|
2108
1490
|
get bufferedAmount() {
|
|
2109
1491
|
if (!this._socket) return this._bufferedAmount;
|
|
2110
1492
|
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
2111
1493
|
}
|
|
2112
|
-
/**
|
|
2113
|
-
* @type {String}
|
|
2114
|
-
*/
|
|
2115
1494
|
get extensions() {
|
|
2116
1495
|
return Object.keys(this._extensions).join();
|
|
2117
1496
|
}
|
|
2118
|
-
/**
|
|
2119
|
-
* @type {Boolean}
|
|
2120
|
-
*/
|
|
2121
1497
|
get isPaused() {
|
|
2122
1498
|
return this._paused;
|
|
2123
1499
|
}
|
|
2124
|
-
/**
|
|
2125
|
-
* @type {Function}
|
|
2126
|
-
*/
|
|
2127
|
-
/* istanbul ignore next */
|
|
2128
1500
|
get onclose() {
|
|
2129
1501
|
return null;
|
|
2130
1502
|
}
|
|
2131
|
-
/**
|
|
2132
|
-
* @type {Function}
|
|
2133
|
-
*/
|
|
2134
|
-
/* istanbul ignore next */
|
|
2135
1503
|
get onerror() {
|
|
2136
1504
|
return null;
|
|
2137
1505
|
}
|
|
2138
|
-
/**
|
|
2139
|
-
* @type {Function}
|
|
2140
|
-
*/
|
|
2141
|
-
/* istanbul ignore next */
|
|
2142
1506
|
get onopen() {
|
|
2143
1507
|
return null;
|
|
2144
1508
|
}
|
|
2145
|
-
/**
|
|
2146
|
-
* @type {Function}
|
|
2147
|
-
*/
|
|
2148
|
-
/* istanbul ignore next */
|
|
2149
1509
|
get onmessage() {
|
|
2150
1510
|
return null;
|
|
2151
1511
|
}
|
|
2152
|
-
/**
|
|
2153
|
-
* @type {String}
|
|
2154
|
-
*/
|
|
2155
1512
|
get protocol() {
|
|
2156
1513
|
return this._protocol;
|
|
2157
1514
|
}
|
|
2158
|
-
/**
|
|
2159
|
-
* @type {Number}
|
|
2160
|
-
*/
|
|
2161
1515
|
get readyState() {
|
|
2162
1516
|
return this._readyState;
|
|
2163
1517
|
}
|
|
2164
|
-
/**
|
|
2165
|
-
* @type {String}
|
|
2166
|
-
*/
|
|
2167
1518
|
get url() {
|
|
2168
1519
|
return this._url;
|
|
2169
1520
|
}
|
|
2170
|
-
/**
|
|
2171
|
-
* Set up the socket and the internal resources.
|
|
2172
|
-
*
|
|
2173
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
2174
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
2175
|
-
* @param {Object} options Options object
|
|
2176
|
-
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
|
|
2177
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
2178
|
-
* multiple times in the same tick
|
|
2179
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
2180
|
-
* masking key
|
|
2181
|
-
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
|
2182
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
2183
|
-
* not to skip UTF-8 validation for text and close messages
|
|
2184
|
-
* @private
|
|
2185
|
-
*/
|
|
2186
1521
|
setSocket(socket, head, options) {
|
|
2187
1522
|
const receiver = new Receiver({
|
|
2188
1523
|
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
2189
1524
|
binaryType: this.binaryType,
|
|
2190
1525
|
extensions: this._extensions,
|
|
2191
1526
|
isServer: this._isServer,
|
|
1527
|
+
maxBufferedChunks: options.maxBufferedChunks,
|
|
1528
|
+
maxFragments: options.maxFragments,
|
|
2192
1529
|
maxPayload: options.maxPayload,
|
|
2193
1530
|
skipUTF8Validation: options.skipUTF8Validation
|
|
2194
1531
|
});
|
|
@@ -2216,11 +1553,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2216
1553
|
this._readyState = WebSocket.OPEN;
|
|
2217
1554
|
this.emit("open");
|
|
2218
1555
|
}
|
|
2219
|
-
/**
|
|
2220
|
-
* Emit the `'close'` event.
|
|
2221
|
-
*
|
|
2222
|
-
* @private
|
|
2223
|
-
*/
|
|
2224
1556
|
emitClose() {
|
|
2225
1557
|
if (!this._socket) {
|
|
2226
1558
|
this._readyState = WebSocket.CLOSED;
|
|
@@ -2232,26 +1564,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2232
1564
|
this._readyState = WebSocket.CLOSED;
|
|
2233
1565
|
this.emit("close", this._closeCode, this._closeMessage);
|
|
2234
1566
|
}
|
|
2235
|
-
/**
|
|
2236
|
-
* Start a closing handshake.
|
|
2237
|
-
*
|
|
2238
|
-
* +----------+ +-----------+ +----------+
|
|
2239
|
-
* - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
|
|
2240
|
-
* | +----------+ +-----------+ +----------+ |
|
|
2241
|
-
* +----------+ +-----------+ |
|
|
2242
|
-
* CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
|
|
2243
|
-
* +----------+ +-----------+ |
|
|
2244
|
-
* | | | +---+ |
|
|
2245
|
-
* +------------------------+-->|fin| - - - -
|
|
2246
|
-
* | +---+ | +---+
|
|
2247
|
-
* - - - - -|fin|<---------------------+
|
|
2248
|
-
* +---+
|
|
2249
|
-
*
|
|
2250
|
-
* @param {Number} [code] Status code explaining why the connection is closing
|
|
2251
|
-
* @param {(String|Buffer)} [data] The reason why the connection is
|
|
2252
|
-
* closing
|
|
2253
|
-
* @public
|
|
2254
|
-
*/
|
|
2255
1567
|
close(code, data) {
|
|
2256
1568
|
if (this.readyState === WebSocket.CLOSED) return;
|
|
2257
1569
|
if (this.readyState === WebSocket.CONNECTING) {
|
|
@@ -2270,24 +1582,11 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2270
1582
|
});
|
|
2271
1583
|
setCloseTimer(this);
|
|
2272
1584
|
}
|
|
2273
|
-
/**
|
|
2274
|
-
* Pause the socket.
|
|
2275
|
-
*
|
|
2276
|
-
* @public
|
|
2277
|
-
*/
|
|
2278
1585
|
pause() {
|
|
2279
1586
|
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
|
|
2280
1587
|
this._paused = true;
|
|
2281
1588
|
this._socket.pause();
|
|
2282
1589
|
}
|
|
2283
|
-
/**
|
|
2284
|
-
* Send a ping.
|
|
2285
|
-
*
|
|
2286
|
-
* @param {*} [data] The data to send
|
|
2287
|
-
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
2288
|
-
* @param {Function} [cb] Callback which is executed when the ping is sent
|
|
2289
|
-
* @public
|
|
2290
|
-
*/
|
|
2291
1590
|
ping(data, mask, cb) {
|
|
2292
1591
|
if (this.readyState === WebSocket.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2293
1592
|
if (typeof data === "function") {
|
|
@@ -2305,14 +1604,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2305
1604
|
if (mask === void 0) mask = !this._isServer;
|
|
2306
1605
|
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
2307
1606
|
}
|
|
2308
|
-
/**
|
|
2309
|
-
* Send a pong.
|
|
2310
|
-
*
|
|
2311
|
-
* @param {*} [data] The data to send
|
|
2312
|
-
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
2313
|
-
* @param {Function} [cb] Callback which is executed when the pong is sent
|
|
2314
|
-
* @public
|
|
2315
|
-
*/
|
|
2316
1607
|
pong(data, mask, cb) {
|
|
2317
1608
|
if (this.readyState === WebSocket.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2318
1609
|
if (typeof data === "function") {
|
|
@@ -2330,31 +1621,11 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2330
1621
|
if (mask === void 0) mask = !this._isServer;
|
|
2331
1622
|
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
2332
1623
|
}
|
|
2333
|
-
/**
|
|
2334
|
-
* Resume the socket.
|
|
2335
|
-
*
|
|
2336
|
-
* @public
|
|
2337
|
-
*/
|
|
2338
1624
|
resume() {
|
|
2339
1625
|
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
|
|
2340
1626
|
this._paused = false;
|
|
2341
1627
|
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
2342
1628
|
}
|
|
2343
|
-
/**
|
|
2344
|
-
* Send a data message.
|
|
2345
|
-
*
|
|
2346
|
-
* @param {*} data The message to send
|
|
2347
|
-
* @param {Object} [options] Options object
|
|
2348
|
-
* @param {Boolean} [options.binary] Specifies whether `data` is binary or
|
|
2349
|
-
* text
|
|
2350
|
-
* @param {Boolean} [options.compress] Specifies whether or not to compress
|
|
2351
|
-
* `data`
|
|
2352
|
-
* @param {Boolean} [options.fin=true] Specifies whether the fragment is the
|
|
2353
|
-
* last one
|
|
2354
|
-
* @param {Boolean} [options.mask] Specifies whether or not to mask `data`
|
|
2355
|
-
* @param {Function} [cb] Callback which is executed when data is written out
|
|
2356
|
-
* @public
|
|
2357
|
-
*/
|
|
2358
1629
|
send(data, options, cb) {
|
|
2359
1630
|
if (this.readyState === WebSocket.CONNECTING) throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2360
1631
|
if (typeof options === "function") {
|
|
@@ -2376,11 +1647,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2376
1647
|
if (!this._extensions[PerMessageDeflate.extensionName]) opts.compress = false;
|
|
2377
1648
|
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
2378
1649
|
}
|
|
2379
|
-
/**
|
|
2380
|
-
* Forcibly close the connection.
|
|
2381
|
-
*
|
|
2382
|
-
* @public
|
|
2383
|
-
*/
|
|
2384
1650
|
terminate() {
|
|
2385
1651
|
if (this.readyState === WebSocket.CLOSED) return;
|
|
2386
1652
|
if (this.readyState === WebSocket.CONNECTING) {
|
|
@@ -2393,66 +1659,34 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2393
1659
|
}
|
|
2394
1660
|
}
|
|
2395
1661
|
};
|
|
2396
|
-
/**
|
|
2397
|
-
* @constant {Number} CONNECTING
|
|
2398
|
-
* @memberof WebSocket
|
|
2399
|
-
*/
|
|
2400
1662
|
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
2401
1663
|
enumerable: true,
|
|
2402
1664
|
value: readyStates.indexOf("CONNECTING")
|
|
2403
1665
|
});
|
|
2404
|
-
/**
|
|
2405
|
-
* @constant {Number} CONNECTING
|
|
2406
|
-
* @memberof WebSocket.prototype
|
|
2407
|
-
*/
|
|
2408
1666
|
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
2409
1667
|
enumerable: true,
|
|
2410
1668
|
value: readyStates.indexOf("CONNECTING")
|
|
2411
1669
|
});
|
|
2412
|
-
/**
|
|
2413
|
-
* @constant {Number} OPEN
|
|
2414
|
-
* @memberof WebSocket
|
|
2415
|
-
*/
|
|
2416
1670
|
Object.defineProperty(WebSocket, "OPEN", {
|
|
2417
1671
|
enumerable: true,
|
|
2418
1672
|
value: readyStates.indexOf("OPEN")
|
|
2419
1673
|
});
|
|
2420
|
-
/**
|
|
2421
|
-
* @constant {Number} OPEN
|
|
2422
|
-
* @memberof WebSocket.prototype
|
|
2423
|
-
*/
|
|
2424
1674
|
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
2425
1675
|
enumerable: true,
|
|
2426
1676
|
value: readyStates.indexOf("OPEN")
|
|
2427
1677
|
});
|
|
2428
|
-
/**
|
|
2429
|
-
* @constant {Number} CLOSING
|
|
2430
|
-
* @memberof WebSocket
|
|
2431
|
-
*/
|
|
2432
1678
|
Object.defineProperty(WebSocket, "CLOSING", {
|
|
2433
1679
|
enumerable: true,
|
|
2434
1680
|
value: readyStates.indexOf("CLOSING")
|
|
2435
1681
|
});
|
|
2436
|
-
/**
|
|
2437
|
-
* @constant {Number} CLOSING
|
|
2438
|
-
* @memberof WebSocket.prototype
|
|
2439
|
-
*/
|
|
2440
1682
|
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
2441
1683
|
enumerable: true,
|
|
2442
1684
|
value: readyStates.indexOf("CLOSING")
|
|
2443
1685
|
});
|
|
2444
|
-
/**
|
|
2445
|
-
* @constant {Number} CLOSED
|
|
2446
|
-
* @memberof WebSocket
|
|
2447
|
-
*/
|
|
2448
1686
|
Object.defineProperty(WebSocket, "CLOSED", {
|
|
2449
1687
|
enumerable: true,
|
|
2450
1688
|
value: readyStates.indexOf("CLOSED")
|
|
2451
1689
|
});
|
|
2452
|
-
/**
|
|
2453
|
-
* @constant {Number} CLOSED
|
|
2454
|
-
* @memberof WebSocket.prototype
|
|
2455
|
-
*/
|
|
2456
1690
|
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
2457
1691
|
enumerable: true,
|
|
2458
1692
|
value: readyStates.indexOf("CLOSED")
|
|
@@ -2493,48 +1727,14 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2493
1727
|
WebSocket.prototype.addEventListener = addEventListener;
|
|
2494
1728
|
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
2495
1729
|
module.exports = WebSocket;
|
|
2496
|
-
/**
|
|
2497
|
-
* Initialize a WebSocket client.
|
|
2498
|
-
*
|
|
2499
|
-
* @param {WebSocket} websocket The client to initialize
|
|
2500
|
-
* @param {(String|URL)} address The URL to which to connect
|
|
2501
|
-
* @param {Array} protocols The subprotocols
|
|
2502
|
-
* @param {Object} [options] Connection options
|
|
2503
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether any
|
|
2504
|
-
* of the `'message'`, `'ping'`, and `'pong'` events can be emitted multiple
|
|
2505
|
-
* times in the same tick
|
|
2506
|
-
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
2507
|
-
* automatically send a pong in response to a ping
|
|
2508
|
-
* @param {Number} [options.closeTimeout=30000] Duration in milliseconds to wait
|
|
2509
|
-
* for the closing handshake to finish after `websocket.close()` is called
|
|
2510
|
-
* @param {Function} [options.finishRequest] A function which can be used to
|
|
2511
|
-
* customize the headers of each http request before it is sent
|
|
2512
|
-
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
|
|
2513
|
-
* redirects
|
|
2514
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
2515
|
-
* masking key
|
|
2516
|
-
* @param {Number} [options.handshakeTimeout] Timeout in milliseconds for the
|
|
2517
|
-
* handshake request
|
|
2518
|
-
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
2519
|
-
* size
|
|
2520
|
-
* @param {Number} [options.maxRedirects=10] The maximum number of redirects
|
|
2521
|
-
* allowed
|
|
2522
|
-
* @param {String} [options.origin] Value of the `Origin` or
|
|
2523
|
-
* `Sec-WebSocket-Origin` header
|
|
2524
|
-
* @param {(Boolean|Object)} [options.perMessageDeflate=true] Enable/disable
|
|
2525
|
-
* permessage-deflate
|
|
2526
|
-
* @param {Number} [options.protocolVersion=13] Value of the
|
|
2527
|
-
* `Sec-WebSocket-Version` header
|
|
2528
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
2529
|
-
* not to skip UTF-8 validation for text and close messages
|
|
2530
|
-
* @private
|
|
2531
|
-
*/
|
|
2532
1730
|
function initAsClient(websocket, address, protocols, options) {
|
|
2533
1731
|
const opts = {
|
|
2534
1732
|
allowSynchronousEvents: true,
|
|
2535
1733
|
autoPong: true,
|
|
2536
1734
|
closeTimeout: CLOSE_TIMEOUT,
|
|
2537
1735
|
protocolVersion: protocolVersions[1],
|
|
1736
|
+
maxBufferedChunks: 1024 * 1024,
|
|
1737
|
+
maxFragments: 128 * 1024,
|
|
2538
1738
|
maxPayload: 100 * 1024 * 1024,
|
|
2539
1739
|
skipUTF8Validation: false,
|
|
2540
1740
|
perMessageDeflate: true,
|
|
@@ -2557,7 +1757,7 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2557
1757
|
if (address instanceof URL) parsedUrl = address;
|
|
2558
1758
|
else try {
|
|
2559
1759
|
parsedUrl = new URL(address);
|
|
2560
|
-
} catch
|
|
1760
|
+
} catch {
|
|
2561
1761
|
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
2562
1762
|
}
|
|
2563
1763
|
if (parsedUrl.protocol === "http:") parsedUrl.protocol = "ws:";
|
|
@@ -2596,7 +1796,11 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2596
1796
|
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
2597
1797
|
opts.timeout = opts.handshakeTimeout;
|
|
2598
1798
|
if (opts.perMessageDeflate) {
|
|
2599
|
-
perMessageDeflate = new PerMessageDeflate(
|
|
1799
|
+
perMessageDeflate = new PerMessageDeflate({
|
|
1800
|
+
...opts.perMessageDeflate,
|
|
1801
|
+
isServer: false,
|
|
1802
|
+
maxPayload: opts.maxPayload
|
|
1803
|
+
});
|
|
2600
1804
|
opts.headers["Sec-WebSocket-Extensions"] = format({ [PerMessageDeflate.extensionName]: perMessageDeflate.offer() });
|
|
2601
1805
|
}
|
|
2602
1806
|
if (protocols.length) {
|
|
@@ -2720,6 +1924,8 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2720
1924
|
websocket.setSocket(socket, head, {
|
|
2721
1925
|
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
2722
1926
|
generateMask: opts.generateMask,
|
|
1927
|
+
maxBufferedChunks: opts.maxBufferedChunks,
|
|
1928
|
+
maxFragments: opts.maxFragments,
|
|
2723
1929
|
maxPayload: opts.maxPayload,
|
|
2724
1930
|
skipUTF8Validation: opts.skipUTF8Validation
|
|
2725
1931
|
});
|
|
@@ -2727,51 +1933,21 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2727
1933
|
if (opts.finishRequest) opts.finishRequest(req, websocket);
|
|
2728
1934
|
else req.end();
|
|
2729
1935
|
}
|
|
2730
|
-
/**
|
|
2731
|
-
* Emit the `'error'` and `'close'` events.
|
|
2732
|
-
*
|
|
2733
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
2734
|
-
* @param {Error} The error to emit
|
|
2735
|
-
* @private
|
|
2736
|
-
*/
|
|
2737
1936
|
function emitErrorAndClose(websocket, err) {
|
|
2738
1937
|
websocket._readyState = WebSocket.CLOSING;
|
|
2739
1938
|
websocket._errorEmitted = true;
|
|
2740
1939
|
websocket.emit("error", err);
|
|
2741
1940
|
websocket.emitClose();
|
|
2742
1941
|
}
|
|
2743
|
-
/**
|
|
2744
|
-
* Create a `net.Socket` and initiate a connection.
|
|
2745
|
-
*
|
|
2746
|
-
* @param {Object} options Connection options
|
|
2747
|
-
* @return {net.Socket} The newly created socket used to start the connection
|
|
2748
|
-
* @private
|
|
2749
|
-
*/
|
|
2750
1942
|
function netConnect(options) {
|
|
2751
1943
|
options.path = options.socketPath;
|
|
2752
1944
|
return net.connect(options);
|
|
2753
1945
|
}
|
|
2754
|
-
/**
|
|
2755
|
-
* Create a `tls.TLSSocket` and initiate a connection.
|
|
2756
|
-
*
|
|
2757
|
-
* @param {Object} options Connection options
|
|
2758
|
-
* @return {tls.TLSSocket} The newly created socket used to start the connection
|
|
2759
|
-
* @private
|
|
2760
|
-
*/
|
|
2761
1946
|
function tlsConnect(options) {
|
|
2762
1947
|
options.path = void 0;
|
|
2763
1948
|
if (!options.servername && options.servername !== "") options.servername = net.isIP(options.host) ? "" : options.host;
|
|
2764
1949
|
return tls.connect(options);
|
|
2765
1950
|
}
|
|
2766
|
-
/**
|
|
2767
|
-
* Abort the handshake and emit an error.
|
|
2768
|
-
*
|
|
2769
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
2770
|
-
* @param {(http.ClientRequest|net.Socket|tls.Socket)} stream The request to
|
|
2771
|
-
* abort or the socket to destroy
|
|
2772
|
-
* @param {String} message The error message
|
|
2773
|
-
* @private
|
|
2774
|
-
*/
|
|
2775
1951
|
function abortHandshake(websocket, stream, message) {
|
|
2776
1952
|
websocket._readyState = WebSocket.CLOSING;
|
|
2777
1953
|
const err = new Error(message);
|
|
@@ -2787,15 +1963,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2787
1963
|
stream.once("close", websocket.emitClose.bind(websocket));
|
|
2788
1964
|
}
|
|
2789
1965
|
}
|
|
2790
|
-
/**
|
|
2791
|
-
* Handle cases where the `ping()`, `pong()`, or `send()` methods are called
|
|
2792
|
-
* when the `readyState` attribute is `CLOSING` or `CLOSED`.
|
|
2793
|
-
*
|
|
2794
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
2795
|
-
* @param {*} [data] The data to send
|
|
2796
|
-
* @param {Function} [cb] Callback
|
|
2797
|
-
* @private
|
|
2798
|
-
*/
|
|
2799
1966
|
function sendAfterClose(websocket, data, cb) {
|
|
2800
1967
|
if (data) {
|
|
2801
1968
|
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
@@ -2807,13 +1974,6 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2807
1974
|
process.nextTick(cb, err);
|
|
2808
1975
|
}
|
|
2809
1976
|
}
|
|
2810
|
-
/**
|
|
2811
|
-
* The listener of the `Receiver` `'conclude'` event.
|
|
2812
|
-
*
|
|
2813
|
-
* @param {Number} code The status code
|
|
2814
|
-
* @param {Buffer} reason The reason for closing
|
|
2815
|
-
* @private
|
|
2816
|
-
*/
|
|
2817
1977
|
function receiverOnConclude(code, reason) {
|
|
2818
1978
|
const websocket = this[kWebSocket];
|
|
2819
1979
|
websocket._closeFrameReceived = true;
|
|
@@ -2825,21 +1985,10 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2825
1985
|
if (code === 1005) websocket.close();
|
|
2826
1986
|
else websocket.close(code, reason);
|
|
2827
1987
|
}
|
|
2828
|
-
/**
|
|
2829
|
-
* The listener of the `Receiver` `'drain'` event.
|
|
2830
|
-
*
|
|
2831
|
-
* @private
|
|
2832
|
-
*/
|
|
2833
1988
|
function receiverOnDrain() {
|
|
2834
1989
|
const websocket = this[kWebSocket];
|
|
2835
1990
|
if (!websocket.isPaused) websocket._socket.resume();
|
|
2836
1991
|
}
|
|
2837
|
-
/**
|
|
2838
|
-
* The listener of the `Receiver` `'error'` event.
|
|
2839
|
-
*
|
|
2840
|
-
* @param {(RangeError|Error)} err The emitted error
|
|
2841
|
-
* @private
|
|
2842
|
-
*/
|
|
2843
1992
|
function receiverOnError(err) {
|
|
2844
1993
|
const websocket = this[kWebSocket];
|
|
2845
1994
|
if (websocket._socket[kWebSocket] !== void 0) {
|
|
@@ -2852,59 +2001,23 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2852
2001
|
websocket.emit("error", err);
|
|
2853
2002
|
}
|
|
2854
2003
|
}
|
|
2855
|
-
/**
|
|
2856
|
-
* The listener of the `Receiver` `'finish'` event.
|
|
2857
|
-
*
|
|
2858
|
-
* @private
|
|
2859
|
-
*/
|
|
2860
2004
|
function receiverOnFinish() {
|
|
2861
2005
|
this[kWebSocket].emitClose();
|
|
2862
2006
|
}
|
|
2863
|
-
/**
|
|
2864
|
-
* The listener of the `Receiver` `'message'` event.
|
|
2865
|
-
*
|
|
2866
|
-
* @param {Buffer|ArrayBuffer|Buffer[])} data The message
|
|
2867
|
-
* @param {Boolean} isBinary Specifies whether the message is binary or not
|
|
2868
|
-
* @private
|
|
2869
|
-
*/
|
|
2870
2007
|
function receiverOnMessage(data, isBinary) {
|
|
2871
2008
|
this[kWebSocket].emit("message", data, isBinary);
|
|
2872
2009
|
}
|
|
2873
|
-
/**
|
|
2874
|
-
* The listener of the `Receiver` `'ping'` event.
|
|
2875
|
-
*
|
|
2876
|
-
* @param {Buffer} data The data included in the ping frame
|
|
2877
|
-
* @private
|
|
2878
|
-
*/
|
|
2879
2010
|
function receiverOnPing(data) {
|
|
2880
2011
|
const websocket = this[kWebSocket];
|
|
2881
2012
|
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
|
2882
2013
|
websocket.emit("ping", data);
|
|
2883
2014
|
}
|
|
2884
|
-
/**
|
|
2885
|
-
* The listener of the `Receiver` `'pong'` event.
|
|
2886
|
-
*
|
|
2887
|
-
* @param {Buffer} data The data included in the pong frame
|
|
2888
|
-
* @private
|
|
2889
|
-
*/
|
|
2890
2015
|
function receiverOnPong(data) {
|
|
2891
2016
|
this[kWebSocket].emit("pong", data);
|
|
2892
2017
|
}
|
|
2893
|
-
/**
|
|
2894
|
-
* Resume a readable stream
|
|
2895
|
-
*
|
|
2896
|
-
* @param {Readable} stream The readable stream
|
|
2897
|
-
* @private
|
|
2898
|
-
*/
|
|
2899
2018
|
function resume(stream) {
|
|
2900
2019
|
stream.resume();
|
|
2901
2020
|
}
|
|
2902
|
-
/**
|
|
2903
|
-
* The `Sender` error event handler.
|
|
2904
|
-
*
|
|
2905
|
-
* @param {Error} The error
|
|
2906
|
-
* @private
|
|
2907
|
-
*/
|
|
2908
2021
|
function senderOnError(err) {
|
|
2909
2022
|
const websocket = this[kWebSocket];
|
|
2910
2023
|
if (websocket.readyState === WebSocket.CLOSED) return;
|
|
@@ -2918,20 +2031,9 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2918
2031
|
websocket.emit("error", err);
|
|
2919
2032
|
}
|
|
2920
2033
|
}
|
|
2921
|
-
/**
|
|
2922
|
-
* Set a timer to destroy the underlying raw socket of a WebSocket.
|
|
2923
|
-
*
|
|
2924
|
-
* @param {WebSocket} websocket The WebSocket instance
|
|
2925
|
-
* @private
|
|
2926
|
-
*/
|
|
2927
2034
|
function setCloseTimer(websocket) {
|
|
2928
2035
|
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
2929
2036
|
}
|
|
2930
|
-
/**
|
|
2931
|
-
* The listener of the socket `'close'` event.
|
|
2932
|
-
*
|
|
2933
|
-
* @private
|
|
2934
|
-
*/
|
|
2935
2037
|
function socketOnClose() {
|
|
2936
2038
|
const websocket = this[kWebSocket];
|
|
2937
2039
|
this.removeListener("close", socketOnClose);
|
|
@@ -2951,31 +2053,15 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2951
2053
|
websocket._receiver.on("finish", receiverOnFinish);
|
|
2952
2054
|
}
|
|
2953
2055
|
}
|
|
2954
|
-
/**
|
|
2955
|
-
* The listener of the socket `'data'` event.
|
|
2956
|
-
*
|
|
2957
|
-
* @param {Buffer} chunk A chunk of data
|
|
2958
|
-
* @private
|
|
2959
|
-
*/
|
|
2960
2056
|
function socketOnData(chunk) {
|
|
2961
2057
|
if (!this[kWebSocket]._receiver.write(chunk)) this.pause();
|
|
2962
2058
|
}
|
|
2963
|
-
/**
|
|
2964
|
-
* The listener of the socket `'end'` event.
|
|
2965
|
-
*
|
|
2966
|
-
* @private
|
|
2967
|
-
*/
|
|
2968
2059
|
function socketOnEnd() {
|
|
2969
2060
|
const websocket = this[kWebSocket];
|
|
2970
2061
|
websocket._readyState = WebSocket.CLOSING;
|
|
2971
2062
|
websocket._receiver.end();
|
|
2972
2063
|
this.end();
|
|
2973
2064
|
}
|
|
2974
|
-
/**
|
|
2975
|
-
* The listener of the socket `'error'` event.
|
|
2976
|
-
*
|
|
2977
|
-
* @private
|
|
2978
|
-
*/
|
|
2979
2065
|
function socketOnError() {
|
|
2980
2066
|
const websocket = this[kWebSocket];
|
|
2981
2067
|
this.removeListener("error", socketOnError);
|
|
@@ -2986,48 +2072,20 @@ var require_websocket = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2986
2072
|
}
|
|
2987
2073
|
}
|
|
2988
2074
|
}));
|
|
2989
|
-
|
|
2990
|
-
//#endregion
|
|
2991
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js
|
|
2992
2075
|
var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2993
2076
|
require_websocket();
|
|
2994
2077
|
const { Duplex: Duplex$1 } = __require("stream");
|
|
2995
|
-
/**
|
|
2996
|
-
* Emits the `'close'` event on a stream.
|
|
2997
|
-
*
|
|
2998
|
-
* @param {Duplex} stream The stream.
|
|
2999
|
-
* @private
|
|
3000
|
-
*/
|
|
3001
2078
|
function emitClose(stream) {
|
|
3002
2079
|
stream.emit("close");
|
|
3003
2080
|
}
|
|
3004
|
-
/**
|
|
3005
|
-
* The listener of the `'end'` event.
|
|
3006
|
-
*
|
|
3007
|
-
* @private
|
|
3008
|
-
*/
|
|
3009
2081
|
function duplexOnEnd() {
|
|
3010
2082
|
if (!this.destroyed && this._writableState.finished) this.destroy();
|
|
3011
2083
|
}
|
|
3012
|
-
/**
|
|
3013
|
-
* The listener of the `'error'` event.
|
|
3014
|
-
*
|
|
3015
|
-
* @param {Error} err The error
|
|
3016
|
-
* @private
|
|
3017
|
-
*/
|
|
3018
2084
|
function duplexOnError(err) {
|
|
3019
2085
|
this.removeListener("error", duplexOnError);
|
|
3020
2086
|
this.destroy();
|
|
3021
2087
|
if (this.listenerCount("error") === 0) this.emit("error", err);
|
|
3022
2088
|
}
|
|
3023
|
-
/**
|
|
3024
|
-
* Wraps a `WebSocket` in a duplex stream.
|
|
3025
|
-
*
|
|
3026
|
-
* @param {WebSocket} ws The `WebSocket` to wrap
|
|
3027
|
-
* @param {Object} [options] The options for the `Duplex` constructor
|
|
3028
|
-
* @return {Duplex} The duplex stream
|
|
3029
|
-
* @public
|
|
3030
|
-
*/
|
|
3031
2089
|
function createWebSocketStream(ws, options) {
|
|
3032
2090
|
let terminateOnDestroy = true;
|
|
3033
2091
|
const duplex = new Duplex$1({
|
|
@@ -3103,18 +2161,8 @@ var require_stream = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3103
2161
|
}
|
|
3104
2162
|
module.exports = createWebSocketStream;
|
|
3105
2163
|
}));
|
|
3106
|
-
|
|
3107
|
-
//#endregion
|
|
3108
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js
|
|
3109
2164
|
var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3110
2165
|
const { tokenChars } = require_validation();
|
|
3111
|
-
/**
|
|
3112
|
-
* Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
|
|
3113
|
-
*
|
|
3114
|
-
* @param {String} header The field value of the header
|
|
3115
|
-
* @return {Set} The subprotocol names
|
|
3116
|
-
* @public
|
|
3117
|
-
*/
|
|
3118
2166
|
function parse(header) {
|
|
3119
2167
|
const protocols = /* @__PURE__ */ new Set();
|
|
3120
2168
|
let start = -1;
|
|
@@ -3143,9 +2191,6 @@ var require_subprotocol = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
3143
2191
|
}
|
|
3144
2192
|
module.exports = { parse };
|
|
3145
2193
|
}));
|
|
3146
|
-
|
|
3147
|
-
//#endregion
|
|
3148
|
-
//#region node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js
|
|
3149
2194
|
var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
3150
2195
|
const EventEmitter = __require("events");
|
|
3151
2196
|
const http = __require("http");
|
|
@@ -3160,51 +2205,14 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3160
2205
|
const RUNNING = 0;
|
|
3161
2206
|
const CLOSING = 1;
|
|
3162
2207
|
const CLOSED = 2;
|
|
3163
|
-
/**
|
|
3164
|
-
* Class representing a WebSocket server.
|
|
3165
|
-
*
|
|
3166
|
-
* @extends EventEmitter
|
|
3167
|
-
*/
|
|
3168
2208
|
var WebSocketServer = class extends EventEmitter {
|
|
3169
|
-
/**
|
|
3170
|
-
* Create a `WebSocketServer` instance.
|
|
3171
|
-
*
|
|
3172
|
-
* @param {Object} options Configuration options
|
|
3173
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
3174
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
3175
|
-
* multiple times in the same tick
|
|
3176
|
-
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
3177
|
-
* automatically send a pong in response to a ping
|
|
3178
|
-
* @param {Number} [options.backlog=511] The maximum length of the queue of
|
|
3179
|
-
* pending connections
|
|
3180
|
-
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
|
3181
|
-
* track clients
|
|
3182
|
-
* @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
|
|
3183
|
-
* wait for the closing handshake to finish after `websocket.close()` is
|
|
3184
|
-
* called
|
|
3185
|
-
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
3186
|
-
* @param {String} [options.host] The hostname where to bind the server
|
|
3187
|
-
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
3188
|
-
* size
|
|
3189
|
-
* @param {Boolean} [options.noServer=false] Enable no server mode
|
|
3190
|
-
* @param {String} [options.path] Accept only connections matching this path
|
|
3191
|
-
* @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
|
|
3192
|
-
* permessage-deflate
|
|
3193
|
-
* @param {Number} [options.port] The port where to bind the server
|
|
3194
|
-
* @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
|
|
3195
|
-
* server to use
|
|
3196
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
3197
|
-
* not to skip UTF-8 validation for text and close messages
|
|
3198
|
-
* @param {Function} [options.verifyClient] A hook to reject connections
|
|
3199
|
-
* @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
|
|
3200
|
-
* class to use. It must be the `WebSocket` class or class that extends it
|
|
3201
|
-
* @param {Function} [callback] A listener for the `listening` event
|
|
3202
|
-
*/
|
|
3203
2209
|
constructor(options, callback) {
|
|
3204
2210
|
super();
|
|
3205
2211
|
options = {
|
|
3206
2212
|
allowSynchronousEvents: true,
|
|
3207
2213
|
autoPong: true,
|
|
2214
|
+
maxBufferedChunks: 1024 * 1024,
|
|
2215
|
+
maxFragments: 128 * 1024,
|
|
3208
2216
|
maxPayload: 100 * 1024 * 1024,
|
|
3209
2217
|
skipUTF8Validation: false,
|
|
3210
2218
|
perMessageDeflate: false,
|
|
@@ -3251,27 +2259,11 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3251
2259
|
this.options = options;
|
|
3252
2260
|
this._state = RUNNING;
|
|
3253
2261
|
}
|
|
3254
|
-
/**
|
|
3255
|
-
* Returns the bound address, the address family name, and port of the server
|
|
3256
|
-
* as reported by the operating system if listening on an IP socket.
|
|
3257
|
-
* If the server is listening on a pipe or UNIX domain socket, the name is
|
|
3258
|
-
* returned as a string.
|
|
3259
|
-
*
|
|
3260
|
-
* @return {(Object|String|null)} The address of the server
|
|
3261
|
-
* @public
|
|
3262
|
-
*/
|
|
3263
2262
|
address() {
|
|
3264
2263
|
if (this.options.noServer) throw new Error("The server is operating in \"noServer\" mode");
|
|
3265
2264
|
if (!this._server) return null;
|
|
3266
2265
|
return this._server.address();
|
|
3267
2266
|
}
|
|
3268
|
-
/**
|
|
3269
|
-
* Stop the server from accepting new connections and emit the `'close'` event
|
|
3270
|
-
* when all existing connections are closed.
|
|
3271
|
-
*
|
|
3272
|
-
* @param {Function} [cb] A one-time listener for the `'close'` event
|
|
3273
|
-
* @public
|
|
3274
|
-
*/
|
|
3275
2267
|
close(cb) {
|
|
3276
2268
|
if (this._state === CLOSED) {
|
|
3277
2269
|
if (cb) this.once("close", () => {
|
|
@@ -3300,13 +2292,6 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3300
2292
|
});
|
|
3301
2293
|
}
|
|
3302
2294
|
}
|
|
3303
|
-
/**
|
|
3304
|
-
* See if a given request should be handled by this server instance.
|
|
3305
|
-
*
|
|
3306
|
-
* @param {http.IncomingMessage} req Request object to inspect
|
|
3307
|
-
* @return {Boolean} `true` if the request is valid, else `false`
|
|
3308
|
-
* @public
|
|
3309
|
-
*/
|
|
3310
2295
|
shouldHandle(req) {
|
|
3311
2296
|
if (this.options.path) {
|
|
3312
2297
|
const index = req.url.indexOf("?");
|
|
@@ -3314,15 +2299,6 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3314
2299
|
}
|
|
3315
2300
|
return true;
|
|
3316
2301
|
}
|
|
3317
|
-
/**
|
|
3318
|
-
* Handle a HTTP Upgrade request.
|
|
3319
|
-
*
|
|
3320
|
-
* @param {http.IncomingMessage} req The request object
|
|
3321
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
3322
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
3323
|
-
* @param {Function} cb Callback
|
|
3324
|
-
* @public
|
|
3325
|
-
*/
|
|
3326
2302
|
handleUpgrade(req, socket, head, cb) {
|
|
3327
2303
|
socket.on("error", socketOnError);
|
|
3328
2304
|
const key = req.headers["sec-websocket-key"];
|
|
@@ -3359,7 +2335,11 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3359
2335
|
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
3360
2336
|
const extensions = {};
|
|
3361
2337
|
if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
|
|
3362
|
-
const perMessageDeflate = new PerMessageDeflate(
|
|
2338
|
+
const perMessageDeflate = new PerMessageDeflate({
|
|
2339
|
+
...this.options.perMessageDeflate,
|
|
2340
|
+
isServer: true,
|
|
2341
|
+
maxPayload: this.options.maxPayload
|
|
2342
|
+
});
|
|
3363
2343
|
try {
|
|
3364
2344
|
const offers = extension.parse(secWebSocketExtensions);
|
|
3365
2345
|
if (offers[PerMessageDeflate.extensionName]) {
|
|
@@ -3388,19 +2368,6 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3388
2368
|
}
|
|
3389
2369
|
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
3390
2370
|
}
|
|
3391
|
-
/**
|
|
3392
|
-
* Upgrade the connection to WebSocket.
|
|
3393
|
-
*
|
|
3394
|
-
* @param {Object} extensions The accepted extensions
|
|
3395
|
-
* @param {String} key The value of the `Sec-WebSocket-Key` header
|
|
3396
|
-
* @param {Set} protocols The subprotocols
|
|
3397
|
-
* @param {http.IncomingMessage} req The request object
|
|
3398
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
3399
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
3400
|
-
* @param {Function} cb Callback
|
|
3401
|
-
* @throws {Error} If called more than once with the same socket
|
|
3402
|
-
* @private
|
|
3403
|
-
*/
|
|
3404
2371
|
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
3405
2372
|
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
3406
2373
|
if (socket[kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
|
|
@@ -3430,6 +2397,8 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3430
2397
|
socket.removeListener("error", socketOnError);
|
|
3431
2398
|
ws.setSocket(socket, head, {
|
|
3432
2399
|
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
2400
|
+
maxBufferedChunks: this.options.maxBufferedChunks,
|
|
2401
|
+
maxFragments: this.options.maxFragments,
|
|
3433
2402
|
maxPayload: this.options.maxPayload,
|
|
3434
2403
|
skipUTF8Validation: this.options.skipUTF8Validation
|
|
3435
2404
|
});
|
|
@@ -3444,49 +2413,19 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3444
2413
|
}
|
|
3445
2414
|
};
|
|
3446
2415
|
module.exports = WebSocketServer;
|
|
3447
|
-
/**
|
|
3448
|
-
* Add event listeners on an `EventEmitter` using a map of <event, listener>
|
|
3449
|
-
* pairs.
|
|
3450
|
-
*
|
|
3451
|
-
* @param {EventEmitter} server The event emitter
|
|
3452
|
-
* @param {Object.<String, Function>} map The listeners to add
|
|
3453
|
-
* @return {Function} A function that will remove the added listeners when
|
|
3454
|
-
* called
|
|
3455
|
-
* @private
|
|
3456
|
-
*/
|
|
3457
2416
|
function addListeners(server, map) {
|
|
3458
2417
|
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
3459
2418
|
return function removeListeners() {
|
|
3460
2419
|
for (const event of Object.keys(map)) server.removeListener(event, map[event]);
|
|
3461
2420
|
};
|
|
3462
2421
|
}
|
|
3463
|
-
/**
|
|
3464
|
-
* Emit a `'close'` event on an `EventEmitter`.
|
|
3465
|
-
*
|
|
3466
|
-
* @param {EventEmitter} server The event emitter
|
|
3467
|
-
* @private
|
|
3468
|
-
*/
|
|
3469
2422
|
function emitClose(server) {
|
|
3470
2423
|
server._state = CLOSED;
|
|
3471
2424
|
server.emit("close");
|
|
3472
2425
|
}
|
|
3473
|
-
/**
|
|
3474
|
-
* Handle socket errors.
|
|
3475
|
-
*
|
|
3476
|
-
* @private
|
|
3477
|
-
*/
|
|
3478
2426
|
function socketOnError() {
|
|
3479
2427
|
this.destroy();
|
|
3480
2428
|
}
|
|
3481
|
-
/**
|
|
3482
|
-
* Close the connection when preconditions are not fulfilled.
|
|
3483
|
-
*
|
|
3484
|
-
* @param {Duplex} socket The socket of the upgrade request
|
|
3485
|
-
* @param {Number} code The HTTP response status code
|
|
3486
|
-
* @param {String} [message] The HTTP response body
|
|
3487
|
-
* @param {Object} [headers] Additional HTTP response headers
|
|
3488
|
-
* @private
|
|
3489
|
-
*/
|
|
3490
2429
|
function abortHandshake(socket, code, message, headers) {
|
|
3491
2430
|
message = message || http.STATUS_CODES[code];
|
|
3492
2431
|
headers = {
|
|
@@ -3498,18 +2437,6 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3498
2437
|
socket.once("finish", socket.destroy);
|
|
3499
2438
|
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message);
|
|
3500
2439
|
}
|
|
3501
|
-
/**
|
|
3502
|
-
* Emit a `'wsClientError'` event on a `WebSocketServer` if there is at least
|
|
3503
|
-
* one listener for it, otherwise call `abortHandshake()`.
|
|
3504
|
-
*
|
|
3505
|
-
* @param {WebSocketServer} server The WebSocket server
|
|
3506
|
-
* @param {http.IncomingMessage} req The request object
|
|
3507
|
-
* @param {Duplex} socket The socket of the upgrade request
|
|
3508
|
-
* @param {Number} code The HTTP response status code
|
|
3509
|
-
* @param {String} message The HTTP response body
|
|
3510
|
-
* @param {Object} [headers] The HTTP response headers
|
|
3511
|
-
* @private
|
|
3512
|
-
*/
|
|
3513
2440
|
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
3514
2441
|
if (server.listenerCount("wsClientError")) {
|
|
3515
2442
|
const err = new Error(message);
|
|
@@ -3518,14 +2445,12 @@ var require_websocket_server = /* @__PURE__ */ __commonJSMin(((exports, module)
|
|
|
3518
2445
|
} else abortHandshake(socket, code, message, headers);
|
|
3519
2446
|
}
|
|
3520
2447
|
}));
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
2448
|
+
require_stream();
|
|
2449
|
+
require_extension();
|
|
2450
|
+
require_permessage_deflate();
|
|
2451
|
+
require_receiver();
|
|
2452
|
+
require_sender();
|
|
2453
|
+
require_subprotocol();
|
|
3527
2454
|
var import_websocket = /* @__PURE__ */ __toESM(require_websocket(), 1);
|
|
3528
2455
|
var import_websocket_server = /* @__PURE__ */ __toESM(require_websocket_server(), 1);
|
|
3529
|
-
|
|
3530
|
-
//#endregion
|
|
3531
|
-
export { import_websocket_server as n, import_websocket as t };
|
|
2456
|
+
export { import_websocket, import_websocket_server };
|