@agentxjs/core 1.9.3-dev → 1.9.6-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/Processor-DT0N1qI6.d.ts +64 -0
  2. package/dist/agent/engine/internal/index.d.ts +223 -0
  3. package/dist/agent/engine/internal/index.js +24 -0
  4. package/dist/agent/engine/internal/index.js.map +1 -0
  5. package/dist/agent/engine/mealy/index.d.ts +157 -0
  6. package/dist/agent/engine/mealy/index.js +26 -0
  7. package/dist/agent/engine/mealy/index.js.map +1 -0
  8. package/dist/agent/index.d.ts +244 -0
  9. package/dist/agent/index.js +66 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/agent/types/index.d.ts +322 -0
  12. package/dist/agent/types/index.js +12 -0
  13. package/dist/agent/types/index.js.map +1 -0
  14. package/dist/base-m40r3Qgu.d.ts +157 -0
  15. package/dist/bus-uF1DM2ox.d.ts +906 -0
  16. package/dist/chunk-7D4SUZUM.js +38 -0
  17. package/dist/chunk-7D4SUZUM.js.map +1 -0
  18. package/dist/chunk-7ZDX3O6I.js +173 -0
  19. package/dist/chunk-7ZDX3O6I.js.map +1 -0
  20. package/dist/chunk-AT5P47YA.js +543 -0
  21. package/dist/chunk-AT5P47YA.js.map +1 -0
  22. package/dist/chunk-E5FPOAPO.js +123 -0
  23. package/dist/chunk-E5FPOAPO.js.map +1 -0
  24. package/dist/chunk-EKHT54KN.js +272 -0
  25. package/dist/chunk-EKHT54KN.js.map +1 -0
  26. package/dist/chunk-I7GYR3MN.js +502 -0
  27. package/dist/chunk-I7GYR3MN.js.map +1 -0
  28. package/dist/chunk-K6WXQ2RW.js +38 -0
  29. package/dist/chunk-K6WXQ2RW.js.map +1 -0
  30. package/dist/chunk-RL3JRNXM.js +3 -0
  31. package/dist/chunk-RL3JRNXM.js.map +1 -0
  32. package/dist/combinators-nEa5dD0T.d.ts +271 -0
  33. package/dist/common/index.d.ts +1 -0
  34. package/dist/common/index.js +2 -0
  35. package/dist/common/index.js.map +1 -0
  36. package/dist/common/logger/index.d.ts +163 -0
  37. package/dist/common/logger/index.js +184 -0
  38. package/dist/common/logger/index.js.map +1 -0
  39. package/dist/container/index.d.ts +110 -0
  40. package/dist/container/index.js +127 -0
  41. package/dist/container/index.js.map +1 -0
  42. package/dist/driver/index.d.ts +266 -0
  43. package/dist/driver/index.js +1 -0
  44. package/dist/driver/index.js.map +1 -0
  45. package/dist/event/index.d.ts +55 -0
  46. package/dist/event/index.js +60 -0
  47. package/dist/event/index.js.map +1 -0
  48. package/dist/event/types/index.d.ts +1149 -0
  49. package/dist/event/types/index.js +56 -0
  50. package/dist/event/types/index.js.map +1 -0
  51. package/dist/event-CDuTzs__.d.ts +296 -0
  52. package/dist/image/index.d.ts +112 -0
  53. package/dist/image/index.js +151 -0
  54. package/dist/image/index.js.map +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.js +67 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/message-BMrMm1pq.d.ts +305 -0
  59. package/dist/mq/index.d.ts +165 -0
  60. package/dist/mq/index.js +37 -0
  61. package/dist/mq/index.js.map +1 -0
  62. package/dist/network/index.d.ts +567 -0
  63. package/dist/network/index.js +435 -0
  64. package/dist/network/index.js.map +1 -0
  65. package/dist/persistence/index.d.ts +155 -0
  66. package/dist/persistence/index.js +1 -0
  67. package/dist/persistence/index.js.map +1 -0
  68. package/dist/runtime/index.d.ts +240 -0
  69. package/dist/runtime/index.js +347 -0
  70. package/dist/runtime/index.js.map +1 -0
  71. package/dist/session/index.d.ts +92 -0
  72. package/dist/session/index.js +56 -0
  73. package/dist/session/index.js.map +1 -0
  74. package/dist/workspace/index.d.ts +111 -0
  75. package/dist/workspace/index.js +1 -0
  76. package/dist/workspace/index.js.map +1 -0
  77. package/dist/wrapper-Y3UTVU2E.js +3635 -0
  78. package/dist/wrapper-Y3UTVU2E.js.map +1 -0
  79. package/package.json +74 -14
  80. package/tsconfig.json +0 -10
@@ -0,0 +1,3635 @@
1
+ import {
2
+ __commonJS,
3
+ __require,
4
+ __toESM
5
+ } from "./chunk-7D4SUZUM.js";
6
+
7
+ // ../../node_modules/ws/lib/constants.js
8
+ var require_constants = __commonJS({
9
+ "../../node_modules/ws/lib/constants.js"(exports, module) {
10
+ "use strict";
11
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
12
+ var hasBlob = typeof Blob !== "undefined";
13
+ if (hasBlob) BINARY_TYPES.push("blob");
14
+ module.exports = {
15
+ BINARY_TYPES,
16
+ EMPTY_BUFFER: Buffer.alloc(0),
17
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
18
+ hasBlob,
19
+ kForOnEventAttribute: /* @__PURE__ */ Symbol("kIsForOnEventAttribute"),
20
+ kListener: /* @__PURE__ */ Symbol("kListener"),
21
+ kStatusCode: /* @__PURE__ */ Symbol("status-code"),
22
+ kWebSocket: /* @__PURE__ */ Symbol("websocket"),
23
+ NOOP: () => {
24
+ }
25
+ };
26
+ }
27
+ });
28
+
29
+ // ../../node_modules/ws/lib/buffer-util.js
30
+ var require_buffer_util = __commonJS({
31
+ "../../node_modules/ws/lib/buffer-util.js"(exports, module) {
32
+ "use strict";
33
+ var { EMPTY_BUFFER } = require_constants();
34
+ var FastBuffer = Buffer[Symbol.species];
35
+ function concat(list, totalLength) {
36
+ if (list.length === 0) return EMPTY_BUFFER;
37
+ if (list.length === 1) return list[0];
38
+ const target = Buffer.allocUnsafe(totalLength);
39
+ let offset = 0;
40
+ for (let i = 0; i < list.length; i++) {
41
+ const buf = list[i];
42
+ target.set(buf, offset);
43
+ offset += buf.length;
44
+ }
45
+ if (offset < totalLength) {
46
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
47
+ }
48
+ return target;
49
+ }
50
+ function _mask(source, mask, output, offset, length) {
51
+ for (let i = 0; i < length; i++) {
52
+ output[offset + i] = source[i] ^ mask[i & 3];
53
+ }
54
+ }
55
+ function _unmask(buffer, mask) {
56
+ for (let i = 0; i < buffer.length; i++) {
57
+ buffer[i] ^= mask[i & 3];
58
+ }
59
+ }
60
+ function toArrayBuffer(buf) {
61
+ if (buf.length === buf.buffer.byteLength) {
62
+ return buf.buffer;
63
+ }
64
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
65
+ }
66
+ function toBuffer(data) {
67
+ toBuffer.readOnly = true;
68
+ if (Buffer.isBuffer(data)) return data;
69
+ let buf;
70
+ if (data instanceof ArrayBuffer) {
71
+ buf = new FastBuffer(data);
72
+ } else if (ArrayBuffer.isView(data)) {
73
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
74
+ } else {
75
+ buf = Buffer.from(data);
76
+ toBuffer.readOnly = false;
77
+ }
78
+ return buf;
79
+ }
80
+ module.exports = {
81
+ concat,
82
+ mask: _mask,
83
+ toArrayBuffer,
84
+ toBuffer,
85
+ unmask: _unmask
86
+ };
87
+ if (!process.env.WS_NO_BUFFER_UTIL) {
88
+ try {
89
+ const bufferUtil = __require("bufferutil");
90
+ module.exports.mask = function(source, mask, output, offset, length) {
91
+ if (length < 48) _mask(source, mask, output, offset, length);
92
+ else bufferUtil.mask(source, mask, output, offset, length);
93
+ };
94
+ module.exports.unmask = function(buffer, mask) {
95
+ if (buffer.length < 32) _unmask(buffer, mask);
96
+ else bufferUtil.unmask(buffer, mask);
97
+ };
98
+ } catch (e) {
99
+ }
100
+ }
101
+ }
102
+ });
103
+
104
+ // ../../node_modules/ws/lib/limiter.js
105
+ var require_limiter = __commonJS({
106
+ "../../node_modules/ws/lib/limiter.js"(exports, module) {
107
+ "use strict";
108
+ var kDone = /* @__PURE__ */ Symbol("kDone");
109
+ var kRun = /* @__PURE__ */ Symbol("kRun");
110
+ var Limiter = class {
111
+ /**
112
+ * Creates a new `Limiter`.
113
+ *
114
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
115
+ * to run concurrently
116
+ */
117
+ constructor(concurrency) {
118
+ this[kDone] = () => {
119
+ this.pending--;
120
+ this[kRun]();
121
+ };
122
+ this.concurrency = concurrency || Infinity;
123
+ this.jobs = [];
124
+ this.pending = 0;
125
+ }
126
+ /**
127
+ * Adds a job to the queue.
128
+ *
129
+ * @param {Function} job The job to run
130
+ * @public
131
+ */
132
+ add(job) {
133
+ this.jobs.push(job);
134
+ this[kRun]();
135
+ }
136
+ /**
137
+ * Removes a job from the queue and runs it if possible.
138
+ *
139
+ * @private
140
+ */
141
+ [kRun]() {
142
+ if (this.pending === this.concurrency) return;
143
+ if (this.jobs.length) {
144
+ const job = this.jobs.shift();
145
+ this.pending++;
146
+ job(this[kDone]);
147
+ }
148
+ }
149
+ };
150
+ module.exports = Limiter;
151
+ }
152
+ });
153
+
154
+ // ../../node_modules/ws/lib/permessage-deflate.js
155
+ var require_permessage_deflate = __commonJS({
156
+ "../../node_modules/ws/lib/permessage-deflate.js"(exports, module) {
157
+ "use strict";
158
+ var zlib = __require("zlib");
159
+ var bufferUtil = require_buffer_util();
160
+ var Limiter = require_limiter();
161
+ var { kStatusCode } = require_constants();
162
+ var FastBuffer = Buffer[Symbol.species];
163
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
164
+ var kPerMessageDeflate = /* @__PURE__ */ Symbol("permessage-deflate");
165
+ var kTotalLength = /* @__PURE__ */ Symbol("total-length");
166
+ var kCallback = /* @__PURE__ */ Symbol("callback");
167
+ var kBuffers = /* @__PURE__ */ Symbol("buffers");
168
+ var kError = /* @__PURE__ */ Symbol("error");
169
+ var zlibLimiter;
170
+ var PerMessageDeflate = class {
171
+ /**
172
+ * Creates a PerMessageDeflate instance.
173
+ *
174
+ * @param {Object} [options] Configuration options
175
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
176
+ * for, or request, a custom client window size
177
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
178
+ * acknowledge disabling of client context takeover
179
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
180
+ * calls to zlib
181
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
182
+ * use of a custom server window size
183
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
184
+ * disabling of server context takeover
185
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
186
+ * messages should not be compressed if context takeover is disabled
187
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
188
+ * deflate
189
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
190
+ * inflate
191
+ * @param {Boolean} [isServer=false] Create the instance in either server or
192
+ * client mode
193
+ * @param {Number} [maxPayload=0] The maximum allowed message length
194
+ */
195
+ constructor(options, isServer, maxPayload) {
196
+ this._maxPayload = maxPayload | 0;
197
+ this._options = options || {};
198
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
199
+ this._isServer = !!isServer;
200
+ this._deflate = null;
201
+ this._inflate = null;
202
+ this.params = null;
203
+ if (!zlibLimiter) {
204
+ const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
205
+ zlibLimiter = new Limiter(concurrency);
206
+ }
207
+ }
208
+ /**
209
+ * @type {String}
210
+ */
211
+ static get extensionName() {
212
+ return "permessage-deflate";
213
+ }
214
+ /**
215
+ * Create an extension negotiation offer.
216
+ *
217
+ * @return {Object} Extension parameters
218
+ * @public
219
+ */
220
+ offer() {
221
+ const params = {};
222
+ if (this._options.serverNoContextTakeover) {
223
+ params.server_no_context_takeover = true;
224
+ }
225
+ if (this._options.clientNoContextTakeover) {
226
+ params.client_no_context_takeover = true;
227
+ }
228
+ if (this._options.serverMaxWindowBits) {
229
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
230
+ }
231
+ if (this._options.clientMaxWindowBits) {
232
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
233
+ } else if (this._options.clientMaxWindowBits == null) {
234
+ params.client_max_window_bits = true;
235
+ }
236
+ return params;
237
+ }
238
+ /**
239
+ * Accept an extension negotiation offer/response.
240
+ *
241
+ * @param {Array} configurations The extension negotiation offers/reponse
242
+ * @return {Object} Accepted configuration
243
+ * @public
244
+ */
245
+ accept(configurations) {
246
+ configurations = this.normalizeParams(configurations);
247
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
248
+ return this.params;
249
+ }
250
+ /**
251
+ * Releases all resources used by the extension.
252
+ *
253
+ * @public
254
+ */
255
+ cleanup() {
256
+ if (this._inflate) {
257
+ this._inflate.close();
258
+ this._inflate = null;
259
+ }
260
+ if (this._deflate) {
261
+ const callback = this._deflate[kCallback];
262
+ this._deflate.close();
263
+ this._deflate = null;
264
+ if (callback) {
265
+ callback(
266
+ new Error(
267
+ "The deflate stream was closed while data was being processed"
268
+ )
269
+ );
270
+ }
271
+ }
272
+ }
273
+ /**
274
+ * Accept an extension negotiation offer.
275
+ *
276
+ * @param {Array} offers The extension negotiation offers
277
+ * @return {Object} Accepted configuration
278
+ * @private
279
+ */
280
+ acceptAsServer(offers) {
281
+ const opts = this._options;
282
+ const accepted = offers.find((params) => {
283
+ if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
284
+ return false;
285
+ }
286
+ return true;
287
+ });
288
+ if (!accepted) {
289
+ throw new Error("None of the extension offers can be accepted");
290
+ }
291
+ if (opts.serverNoContextTakeover) {
292
+ accepted.server_no_context_takeover = true;
293
+ }
294
+ if (opts.clientNoContextTakeover) {
295
+ accepted.client_no_context_takeover = true;
296
+ }
297
+ if (typeof opts.serverMaxWindowBits === "number") {
298
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
299
+ }
300
+ if (typeof opts.clientMaxWindowBits === "number") {
301
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
302
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
303
+ delete accepted.client_max_window_bits;
304
+ }
305
+ return accepted;
306
+ }
307
+ /**
308
+ * Accept the extension negotiation response.
309
+ *
310
+ * @param {Array} response The extension negotiation response
311
+ * @return {Object} Accepted configuration
312
+ * @private
313
+ */
314
+ acceptAsClient(response) {
315
+ const params = response[0];
316
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
317
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
318
+ }
319
+ if (!params.client_max_window_bits) {
320
+ if (typeof this._options.clientMaxWindowBits === "number") {
321
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
322
+ }
323
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
324
+ throw new Error(
325
+ 'Unexpected or invalid parameter "client_max_window_bits"'
326
+ );
327
+ }
328
+ return params;
329
+ }
330
+ /**
331
+ * Normalize parameters.
332
+ *
333
+ * @param {Array} configurations The extension negotiation offers/reponse
334
+ * @return {Array} The offers/response with normalized parameters
335
+ * @private
336
+ */
337
+ normalizeParams(configurations) {
338
+ configurations.forEach((params) => {
339
+ Object.keys(params).forEach((key) => {
340
+ let value = params[key];
341
+ if (value.length > 1) {
342
+ throw new Error(`Parameter "${key}" must have only a single value`);
343
+ }
344
+ value = value[0];
345
+ if (key === "client_max_window_bits") {
346
+ if (value !== true) {
347
+ const num = +value;
348
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
349
+ throw new TypeError(
350
+ `Invalid value for parameter "${key}": ${value}`
351
+ );
352
+ }
353
+ value = num;
354
+ } else if (!this._isServer) {
355
+ throw new TypeError(
356
+ `Invalid value for parameter "${key}": ${value}`
357
+ );
358
+ }
359
+ } else if (key === "server_max_window_bits") {
360
+ const num = +value;
361
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
362
+ throw new TypeError(
363
+ `Invalid value for parameter "${key}": ${value}`
364
+ );
365
+ }
366
+ value = num;
367
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
368
+ if (value !== true) {
369
+ throw new TypeError(
370
+ `Invalid value for parameter "${key}": ${value}`
371
+ );
372
+ }
373
+ } else {
374
+ throw new Error(`Unknown parameter "${key}"`);
375
+ }
376
+ params[key] = value;
377
+ });
378
+ });
379
+ return configurations;
380
+ }
381
+ /**
382
+ * Decompress data. Concurrency limited.
383
+ *
384
+ * @param {Buffer} data Compressed data
385
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
386
+ * @param {Function} callback Callback
387
+ * @public
388
+ */
389
+ decompress(data, fin, callback) {
390
+ zlibLimiter.add((done) => {
391
+ this._decompress(data, fin, (err, result) => {
392
+ done();
393
+ callback(err, result);
394
+ });
395
+ });
396
+ }
397
+ /**
398
+ * Compress data. Concurrency limited.
399
+ *
400
+ * @param {(Buffer|String)} data Data to compress
401
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
402
+ * @param {Function} callback Callback
403
+ * @public
404
+ */
405
+ compress(data, fin, callback) {
406
+ zlibLimiter.add((done) => {
407
+ this._compress(data, fin, (err, result) => {
408
+ done();
409
+ callback(err, result);
410
+ });
411
+ });
412
+ }
413
+ /**
414
+ * Decompress data.
415
+ *
416
+ * @param {Buffer} data Compressed data
417
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
418
+ * @param {Function} callback Callback
419
+ * @private
420
+ */
421
+ _decompress(data, fin, callback) {
422
+ const endpoint = this._isServer ? "client" : "server";
423
+ if (!this._inflate) {
424
+ const key = `${endpoint}_max_window_bits`;
425
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
426
+ this._inflate = zlib.createInflateRaw({
427
+ ...this._options.zlibInflateOptions,
428
+ windowBits
429
+ });
430
+ this._inflate[kPerMessageDeflate] = this;
431
+ this._inflate[kTotalLength] = 0;
432
+ this._inflate[kBuffers] = [];
433
+ this._inflate.on("error", inflateOnError);
434
+ this._inflate.on("data", inflateOnData);
435
+ }
436
+ this._inflate[kCallback] = callback;
437
+ this._inflate.write(data);
438
+ if (fin) this._inflate.write(TRAILER);
439
+ this._inflate.flush(() => {
440
+ const err = this._inflate[kError];
441
+ if (err) {
442
+ this._inflate.close();
443
+ this._inflate = null;
444
+ callback(err);
445
+ return;
446
+ }
447
+ const data2 = bufferUtil.concat(
448
+ this._inflate[kBuffers],
449
+ this._inflate[kTotalLength]
450
+ );
451
+ if (this._inflate._readableState.endEmitted) {
452
+ this._inflate.close();
453
+ this._inflate = null;
454
+ } else {
455
+ this._inflate[kTotalLength] = 0;
456
+ this._inflate[kBuffers] = [];
457
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
458
+ this._inflate.reset();
459
+ }
460
+ }
461
+ callback(null, data2);
462
+ });
463
+ }
464
+ /**
465
+ * Compress data.
466
+ *
467
+ * @param {(Buffer|String)} data Data to compress
468
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
469
+ * @param {Function} callback Callback
470
+ * @private
471
+ */
472
+ _compress(data, fin, callback) {
473
+ const endpoint = this._isServer ? "server" : "client";
474
+ if (!this._deflate) {
475
+ const key = `${endpoint}_max_window_bits`;
476
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
477
+ this._deflate = zlib.createDeflateRaw({
478
+ ...this._options.zlibDeflateOptions,
479
+ windowBits
480
+ });
481
+ this._deflate[kTotalLength] = 0;
482
+ this._deflate[kBuffers] = [];
483
+ this._deflate.on("data", deflateOnData);
484
+ }
485
+ this._deflate[kCallback] = callback;
486
+ this._deflate.write(data);
487
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
488
+ if (!this._deflate) {
489
+ return;
490
+ }
491
+ let data2 = bufferUtil.concat(
492
+ this._deflate[kBuffers],
493
+ this._deflate[kTotalLength]
494
+ );
495
+ if (fin) {
496
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
497
+ }
498
+ this._deflate[kCallback] = null;
499
+ this._deflate[kTotalLength] = 0;
500
+ this._deflate[kBuffers] = [];
501
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
502
+ this._deflate.reset();
503
+ }
504
+ callback(null, data2);
505
+ });
506
+ }
507
+ };
508
+ module.exports = PerMessageDeflate;
509
+ function deflateOnData(chunk) {
510
+ this[kBuffers].push(chunk);
511
+ this[kTotalLength] += chunk.length;
512
+ }
513
+ function inflateOnData(chunk) {
514
+ this[kTotalLength] += chunk.length;
515
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
516
+ this[kBuffers].push(chunk);
517
+ return;
518
+ }
519
+ this[kError] = new RangeError("Max payload size exceeded");
520
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
521
+ this[kError][kStatusCode] = 1009;
522
+ this.removeListener("data", inflateOnData);
523
+ this.reset();
524
+ }
525
+ function inflateOnError(err) {
526
+ this[kPerMessageDeflate]._inflate = null;
527
+ if (this[kError]) {
528
+ this[kCallback](this[kError]);
529
+ return;
530
+ }
531
+ err[kStatusCode] = 1007;
532
+ this[kCallback](err);
533
+ }
534
+ }
535
+ });
536
+
537
+ // ../../node_modules/ws/lib/validation.js
538
+ var require_validation = __commonJS({
539
+ "../../node_modules/ws/lib/validation.js"(exports, module) {
540
+ "use strict";
541
+ var { isUtf8 } = __require("buffer");
542
+ var { hasBlob } = require_constants();
543
+ var tokenChars = [
544
+ 0,
545
+ 0,
546
+ 0,
547
+ 0,
548
+ 0,
549
+ 0,
550
+ 0,
551
+ 0,
552
+ 0,
553
+ 0,
554
+ 0,
555
+ 0,
556
+ 0,
557
+ 0,
558
+ 0,
559
+ 0,
560
+ // 0 - 15
561
+ 0,
562
+ 0,
563
+ 0,
564
+ 0,
565
+ 0,
566
+ 0,
567
+ 0,
568
+ 0,
569
+ 0,
570
+ 0,
571
+ 0,
572
+ 0,
573
+ 0,
574
+ 0,
575
+ 0,
576
+ 0,
577
+ // 16 - 31
578
+ 0,
579
+ 1,
580
+ 0,
581
+ 1,
582
+ 1,
583
+ 1,
584
+ 1,
585
+ 1,
586
+ 0,
587
+ 0,
588
+ 1,
589
+ 1,
590
+ 0,
591
+ 1,
592
+ 1,
593
+ 0,
594
+ // 32 - 47
595
+ 1,
596
+ 1,
597
+ 1,
598
+ 1,
599
+ 1,
600
+ 1,
601
+ 1,
602
+ 1,
603
+ 1,
604
+ 1,
605
+ 0,
606
+ 0,
607
+ 0,
608
+ 0,
609
+ 0,
610
+ 0,
611
+ // 48 - 63
612
+ 0,
613
+ 1,
614
+ 1,
615
+ 1,
616
+ 1,
617
+ 1,
618
+ 1,
619
+ 1,
620
+ 1,
621
+ 1,
622
+ 1,
623
+ 1,
624
+ 1,
625
+ 1,
626
+ 1,
627
+ 1,
628
+ // 64 - 79
629
+ 1,
630
+ 1,
631
+ 1,
632
+ 1,
633
+ 1,
634
+ 1,
635
+ 1,
636
+ 1,
637
+ 1,
638
+ 1,
639
+ 1,
640
+ 0,
641
+ 0,
642
+ 0,
643
+ 1,
644
+ 1,
645
+ // 80 - 95
646
+ 1,
647
+ 1,
648
+ 1,
649
+ 1,
650
+ 1,
651
+ 1,
652
+ 1,
653
+ 1,
654
+ 1,
655
+ 1,
656
+ 1,
657
+ 1,
658
+ 1,
659
+ 1,
660
+ 1,
661
+ 1,
662
+ // 96 - 111
663
+ 1,
664
+ 1,
665
+ 1,
666
+ 1,
667
+ 1,
668
+ 1,
669
+ 1,
670
+ 1,
671
+ 1,
672
+ 1,
673
+ 1,
674
+ 0,
675
+ 1,
676
+ 0,
677
+ 1,
678
+ 0
679
+ // 112 - 127
680
+ ];
681
+ function isValidStatusCode(code) {
682
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
683
+ }
684
+ function _isValidUTF8(buf) {
685
+ const len = buf.length;
686
+ let i = 0;
687
+ while (i < len) {
688
+ if ((buf[i] & 128) === 0) {
689
+ i++;
690
+ } else if ((buf[i] & 224) === 192) {
691
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
692
+ return false;
693
+ }
694
+ i += 2;
695
+ } else if ((buf[i] & 240) === 224) {
696
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
697
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
698
+ return false;
699
+ }
700
+ i += 3;
701
+ } else if ((buf[i] & 248) === 240) {
702
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
703
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
704
+ return false;
705
+ }
706
+ i += 4;
707
+ } else {
708
+ return false;
709
+ }
710
+ }
711
+ return true;
712
+ }
713
+ function isBlob(value) {
714
+ 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");
715
+ }
716
+ module.exports = {
717
+ isBlob,
718
+ isValidStatusCode,
719
+ isValidUTF8: _isValidUTF8,
720
+ tokenChars
721
+ };
722
+ if (isUtf8) {
723
+ module.exports.isValidUTF8 = function(buf) {
724
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
725
+ };
726
+ } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
727
+ try {
728
+ const isValidUTF8 = __require("utf-8-validate");
729
+ module.exports.isValidUTF8 = function(buf) {
730
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
731
+ };
732
+ } catch (e) {
733
+ }
734
+ }
735
+ }
736
+ });
737
+
738
+ // ../../node_modules/ws/lib/receiver.js
739
+ var require_receiver = __commonJS({
740
+ "../../node_modules/ws/lib/receiver.js"(exports, module) {
741
+ "use strict";
742
+ var { Writable } = __require("stream");
743
+ var PerMessageDeflate = require_permessage_deflate();
744
+ var {
745
+ BINARY_TYPES,
746
+ EMPTY_BUFFER,
747
+ kStatusCode,
748
+ kWebSocket
749
+ } = require_constants();
750
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
751
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
752
+ var FastBuffer = Buffer[Symbol.species];
753
+ var GET_INFO = 0;
754
+ var GET_PAYLOAD_LENGTH_16 = 1;
755
+ var GET_PAYLOAD_LENGTH_64 = 2;
756
+ var GET_MASK = 3;
757
+ var GET_DATA = 4;
758
+ var INFLATING = 5;
759
+ var DEFER_EVENT = 6;
760
+ var Receiver2 = class extends Writable {
761
+ /**
762
+ * Creates a Receiver instance.
763
+ *
764
+ * @param {Object} [options] Options object
765
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
766
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
767
+ * multiple times in the same tick
768
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
769
+ * @param {Object} [options.extensions] An object containing the negotiated
770
+ * extensions
771
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
772
+ * client or server mode
773
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
774
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
775
+ * not to skip UTF-8 validation for text and close messages
776
+ */
777
+ constructor(options = {}) {
778
+ super();
779
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
780
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
781
+ this._extensions = options.extensions || {};
782
+ this._isServer = !!options.isServer;
783
+ this._maxPayload = options.maxPayload | 0;
784
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
785
+ this[kWebSocket] = void 0;
786
+ this._bufferedBytes = 0;
787
+ this._buffers = [];
788
+ this._compressed = false;
789
+ this._payloadLength = 0;
790
+ this._mask = void 0;
791
+ this._fragmented = 0;
792
+ this._masked = false;
793
+ this._fin = false;
794
+ this._opcode = 0;
795
+ this._totalPayloadLength = 0;
796
+ this._messageLength = 0;
797
+ this._fragments = [];
798
+ this._errored = false;
799
+ this._loop = false;
800
+ this._state = GET_INFO;
801
+ }
802
+ /**
803
+ * Implements `Writable.prototype._write()`.
804
+ *
805
+ * @param {Buffer} chunk The chunk of data to write
806
+ * @param {String} encoding The character encoding of `chunk`
807
+ * @param {Function} cb Callback
808
+ * @private
809
+ */
810
+ _write(chunk, encoding, cb) {
811
+ if (this._opcode === 8 && this._state == GET_INFO) return cb();
812
+ this._bufferedBytes += chunk.length;
813
+ this._buffers.push(chunk);
814
+ this.startLoop(cb);
815
+ }
816
+ /**
817
+ * Consumes `n` bytes from the buffered data.
818
+ *
819
+ * @param {Number} n The number of bytes to consume
820
+ * @return {Buffer} The consumed bytes
821
+ * @private
822
+ */
823
+ consume(n) {
824
+ this._bufferedBytes -= n;
825
+ if (n === this._buffers[0].length) return this._buffers.shift();
826
+ if (n < this._buffers[0].length) {
827
+ const buf = this._buffers[0];
828
+ this._buffers[0] = new FastBuffer(
829
+ buf.buffer,
830
+ buf.byteOffset + n,
831
+ buf.length - n
832
+ );
833
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
834
+ }
835
+ const dst = Buffer.allocUnsafe(n);
836
+ do {
837
+ const buf = this._buffers[0];
838
+ const offset = dst.length - n;
839
+ if (n >= buf.length) {
840
+ dst.set(this._buffers.shift(), offset);
841
+ } else {
842
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
843
+ this._buffers[0] = new FastBuffer(
844
+ buf.buffer,
845
+ buf.byteOffset + n,
846
+ buf.length - n
847
+ );
848
+ }
849
+ n -= buf.length;
850
+ } while (n > 0);
851
+ return dst;
852
+ }
853
+ /**
854
+ * Starts the parsing loop.
855
+ *
856
+ * @param {Function} cb Callback
857
+ * @private
858
+ */
859
+ startLoop(cb) {
860
+ this._loop = true;
861
+ do {
862
+ switch (this._state) {
863
+ case GET_INFO:
864
+ this.getInfo(cb);
865
+ break;
866
+ case GET_PAYLOAD_LENGTH_16:
867
+ this.getPayloadLength16(cb);
868
+ break;
869
+ case GET_PAYLOAD_LENGTH_64:
870
+ this.getPayloadLength64(cb);
871
+ break;
872
+ case GET_MASK:
873
+ this.getMask();
874
+ break;
875
+ case GET_DATA:
876
+ this.getData(cb);
877
+ break;
878
+ case INFLATING:
879
+ case DEFER_EVENT:
880
+ this._loop = false;
881
+ return;
882
+ }
883
+ } while (this._loop);
884
+ if (!this._errored) cb();
885
+ }
886
+ /**
887
+ * Reads the first two bytes of a frame.
888
+ *
889
+ * @param {Function} cb Callback
890
+ * @private
891
+ */
892
+ getInfo(cb) {
893
+ if (this._bufferedBytes < 2) {
894
+ this._loop = false;
895
+ return;
896
+ }
897
+ const buf = this.consume(2);
898
+ if ((buf[0] & 48) !== 0) {
899
+ const error = this.createError(
900
+ RangeError,
901
+ "RSV2 and RSV3 must be clear",
902
+ true,
903
+ 1002,
904
+ "WS_ERR_UNEXPECTED_RSV_2_3"
905
+ );
906
+ cb(error);
907
+ return;
908
+ }
909
+ const compressed = (buf[0] & 64) === 64;
910
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
911
+ const error = this.createError(
912
+ RangeError,
913
+ "RSV1 must be clear",
914
+ true,
915
+ 1002,
916
+ "WS_ERR_UNEXPECTED_RSV_1"
917
+ );
918
+ cb(error);
919
+ return;
920
+ }
921
+ this._fin = (buf[0] & 128) === 128;
922
+ this._opcode = buf[0] & 15;
923
+ this._payloadLength = buf[1] & 127;
924
+ if (this._opcode === 0) {
925
+ if (compressed) {
926
+ const error = this.createError(
927
+ RangeError,
928
+ "RSV1 must be clear",
929
+ true,
930
+ 1002,
931
+ "WS_ERR_UNEXPECTED_RSV_1"
932
+ );
933
+ cb(error);
934
+ return;
935
+ }
936
+ if (!this._fragmented) {
937
+ const error = this.createError(
938
+ RangeError,
939
+ "invalid opcode 0",
940
+ true,
941
+ 1002,
942
+ "WS_ERR_INVALID_OPCODE"
943
+ );
944
+ cb(error);
945
+ return;
946
+ }
947
+ this._opcode = this._fragmented;
948
+ } else if (this._opcode === 1 || this._opcode === 2) {
949
+ if (this._fragmented) {
950
+ const error = this.createError(
951
+ RangeError,
952
+ `invalid opcode ${this._opcode}`,
953
+ true,
954
+ 1002,
955
+ "WS_ERR_INVALID_OPCODE"
956
+ );
957
+ cb(error);
958
+ return;
959
+ }
960
+ this._compressed = compressed;
961
+ } else if (this._opcode > 7 && this._opcode < 11) {
962
+ if (!this._fin) {
963
+ const error = this.createError(
964
+ RangeError,
965
+ "FIN must be set",
966
+ true,
967
+ 1002,
968
+ "WS_ERR_EXPECTED_FIN"
969
+ );
970
+ cb(error);
971
+ return;
972
+ }
973
+ if (compressed) {
974
+ const error = this.createError(
975
+ RangeError,
976
+ "RSV1 must be clear",
977
+ true,
978
+ 1002,
979
+ "WS_ERR_UNEXPECTED_RSV_1"
980
+ );
981
+ cb(error);
982
+ return;
983
+ }
984
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
985
+ const error = this.createError(
986
+ RangeError,
987
+ `invalid payload length ${this._payloadLength}`,
988
+ true,
989
+ 1002,
990
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
991
+ );
992
+ cb(error);
993
+ return;
994
+ }
995
+ } else {
996
+ const error = this.createError(
997
+ RangeError,
998
+ `invalid opcode ${this._opcode}`,
999
+ true,
1000
+ 1002,
1001
+ "WS_ERR_INVALID_OPCODE"
1002
+ );
1003
+ cb(error);
1004
+ return;
1005
+ }
1006
+ if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
1007
+ this._masked = (buf[1] & 128) === 128;
1008
+ if (this._isServer) {
1009
+ if (!this._masked) {
1010
+ const error = this.createError(
1011
+ RangeError,
1012
+ "MASK must be set",
1013
+ true,
1014
+ 1002,
1015
+ "WS_ERR_EXPECTED_MASK"
1016
+ );
1017
+ cb(error);
1018
+ return;
1019
+ }
1020
+ } else if (this._masked) {
1021
+ const error = this.createError(
1022
+ RangeError,
1023
+ "MASK must be clear",
1024
+ true,
1025
+ 1002,
1026
+ "WS_ERR_UNEXPECTED_MASK"
1027
+ );
1028
+ cb(error);
1029
+ return;
1030
+ }
1031
+ if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
1032
+ else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
1033
+ else this.haveLength(cb);
1034
+ }
1035
+ /**
1036
+ * Gets extended payload length (7+16).
1037
+ *
1038
+ * @param {Function} cb Callback
1039
+ * @private
1040
+ */
1041
+ getPayloadLength16(cb) {
1042
+ if (this._bufferedBytes < 2) {
1043
+ this._loop = false;
1044
+ return;
1045
+ }
1046
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1047
+ this.haveLength(cb);
1048
+ }
1049
+ /**
1050
+ * Gets extended payload length (7+64).
1051
+ *
1052
+ * @param {Function} cb Callback
1053
+ * @private
1054
+ */
1055
+ getPayloadLength64(cb) {
1056
+ if (this._bufferedBytes < 8) {
1057
+ this._loop = false;
1058
+ return;
1059
+ }
1060
+ const buf = this.consume(8);
1061
+ const num = buf.readUInt32BE(0);
1062
+ if (num > Math.pow(2, 53 - 32) - 1) {
1063
+ const error = this.createError(
1064
+ RangeError,
1065
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
1066
+ false,
1067
+ 1009,
1068
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1069
+ );
1070
+ cb(error);
1071
+ return;
1072
+ }
1073
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1074
+ this.haveLength(cb);
1075
+ }
1076
+ /**
1077
+ * Payload length has been read.
1078
+ *
1079
+ * @param {Function} cb Callback
1080
+ * @private
1081
+ */
1082
+ haveLength(cb) {
1083
+ if (this._payloadLength && this._opcode < 8) {
1084
+ this._totalPayloadLength += this._payloadLength;
1085
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1086
+ const error = this.createError(
1087
+ RangeError,
1088
+ "Max payload size exceeded",
1089
+ false,
1090
+ 1009,
1091
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1092
+ );
1093
+ cb(error);
1094
+ return;
1095
+ }
1096
+ }
1097
+ if (this._masked) this._state = GET_MASK;
1098
+ else this._state = GET_DATA;
1099
+ }
1100
+ /**
1101
+ * Reads mask bytes.
1102
+ *
1103
+ * @private
1104
+ */
1105
+ getMask() {
1106
+ if (this._bufferedBytes < 4) {
1107
+ this._loop = false;
1108
+ return;
1109
+ }
1110
+ this._mask = this.consume(4);
1111
+ this._state = GET_DATA;
1112
+ }
1113
+ /**
1114
+ * Reads data bytes.
1115
+ *
1116
+ * @param {Function} cb Callback
1117
+ * @private
1118
+ */
1119
+ getData(cb) {
1120
+ let data = EMPTY_BUFFER;
1121
+ if (this._payloadLength) {
1122
+ if (this._bufferedBytes < this._payloadLength) {
1123
+ this._loop = false;
1124
+ return;
1125
+ }
1126
+ data = this.consume(this._payloadLength);
1127
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1128
+ unmask(data, this._mask);
1129
+ }
1130
+ }
1131
+ if (this._opcode > 7) {
1132
+ this.controlMessage(data, cb);
1133
+ return;
1134
+ }
1135
+ if (this._compressed) {
1136
+ this._state = INFLATING;
1137
+ this.decompress(data, cb);
1138
+ return;
1139
+ }
1140
+ if (data.length) {
1141
+ this._messageLength = this._totalPayloadLength;
1142
+ this._fragments.push(data);
1143
+ }
1144
+ this.dataMessage(cb);
1145
+ }
1146
+ /**
1147
+ * Decompresses data.
1148
+ *
1149
+ * @param {Buffer} data Compressed data
1150
+ * @param {Function} cb Callback
1151
+ * @private
1152
+ */
1153
+ decompress(data, cb) {
1154
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1155
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1156
+ if (err) return cb(err);
1157
+ if (buf.length) {
1158
+ this._messageLength += buf.length;
1159
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1160
+ const error = this.createError(
1161
+ RangeError,
1162
+ "Max payload size exceeded",
1163
+ false,
1164
+ 1009,
1165
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1166
+ );
1167
+ cb(error);
1168
+ return;
1169
+ }
1170
+ this._fragments.push(buf);
1171
+ }
1172
+ this.dataMessage(cb);
1173
+ if (this._state === GET_INFO) this.startLoop(cb);
1174
+ });
1175
+ }
1176
+ /**
1177
+ * Handles a data message.
1178
+ *
1179
+ * @param {Function} cb Callback
1180
+ * @private
1181
+ */
1182
+ dataMessage(cb) {
1183
+ if (!this._fin) {
1184
+ this._state = GET_INFO;
1185
+ return;
1186
+ }
1187
+ const messageLength = this._messageLength;
1188
+ const fragments = this._fragments;
1189
+ this._totalPayloadLength = 0;
1190
+ this._messageLength = 0;
1191
+ this._fragmented = 0;
1192
+ this._fragments = [];
1193
+ if (this._opcode === 2) {
1194
+ let data;
1195
+ if (this._binaryType === "nodebuffer") {
1196
+ data = concat(fragments, messageLength);
1197
+ } else if (this._binaryType === "arraybuffer") {
1198
+ data = toArrayBuffer(concat(fragments, messageLength));
1199
+ } else if (this._binaryType === "blob") {
1200
+ data = new Blob(fragments);
1201
+ } else {
1202
+ data = fragments;
1203
+ }
1204
+ if (this._allowSynchronousEvents) {
1205
+ this.emit("message", data, true);
1206
+ this._state = GET_INFO;
1207
+ } else {
1208
+ this._state = DEFER_EVENT;
1209
+ setImmediate(() => {
1210
+ this.emit("message", data, true);
1211
+ this._state = GET_INFO;
1212
+ this.startLoop(cb);
1213
+ });
1214
+ }
1215
+ } else {
1216
+ const buf = concat(fragments, messageLength);
1217
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1218
+ const error = this.createError(
1219
+ Error,
1220
+ "invalid UTF-8 sequence",
1221
+ true,
1222
+ 1007,
1223
+ "WS_ERR_INVALID_UTF8"
1224
+ );
1225
+ cb(error);
1226
+ return;
1227
+ }
1228
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1229
+ this.emit("message", buf, false);
1230
+ this._state = GET_INFO;
1231
+ } else {
1232
+ this._state = DEFER_EVENT;
1233
+ setImmediate(() => {
1234
+ this.emit("message", buf, false);
1235
+ this._state = GET_INFO;
1236
+ this.startLoop(cb);
1237
+ });
1238
+ }
1239
+ }
1240
+ }
1241
+ /**
1242
+ * Handles a control message.
1243
+ *
1244
+ * @param {Buffer} data Data to handle
1245
+ * @return {(Error|RangeError|undefined)} A possible error
1246
+ * @private
1247
+ */
1248
+ controlMessage(data, cb) {
1249
+ if (this._opcode === 8) {
1250
+ if (data.length === 0) {
1251
+ this._loop = false;
1252
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1253
+ this.end();
1254
+ } else {
1255
+ const code = data.readUInt16BE(0);
1256
+ if (!isValidStatusCode(code)) {
1257
+ const error = this.createError(
1258
+ RangeError,
1259
+ `invalid status code ${code}`,
1260
+ true,
1261
+ 1002,
1262
+ "WS_ERR_INVALID_CLOSE_CODE"
1263
+ );
1264
+ cb(error);
1265
+ return;
1266
+ }
1267
+ const buf = new FastBuffer(
1268
+ data.buffer,
1269
+ data.byteOffset + 2,
1270
+ data.length - 2
1271
+ );
1272
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1273
+ const error = this.createError(
1274
+ Error,
1275
+ "invalid UTF-8 sequence",
1276
+ true,
1277
+ 1007,
1278
+ "WS_ERR_INVALID_UTF8"
1279
+ );
1280
+ cb(error);
1281
+ return;
1282
+ }
1283
+ this._loop = false;
1284
+ this.emit("conclude", code, buf);
1285
+ this.end();
1286
+ }
1287
+ this._state = GET_INFO;
1288
+ return;
1289
+ }
1290
+ if (this._allowSynchronousEvents) {
1291
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1292
+ this._state = GET_INFO;
1293
+ } else {
1294
+ this._state = DEFER_EVENT;
1295
+ setImmediate(() => {
1296
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1297
+ this._state = GET_INFO;
1298
+ this.startLoop(cb);
1299
+ });
1300
+ }
1301
+ }
1302
+ /**
1303
+ * Builds an error object.
1304
+ *
1305
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1306
+ * @param {String} message The error message
1307
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1308
+ * `message`
1309
+ * @param {Number} statusCode The status code
1310
+ * @param {String} errorCode The exposed error code
1311
+ * @return {(Error|RangeError)} The error
1312
+ * @private
1313
+ */
1314
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1315
+ this._loop = false;
1316
+ this._errored = true;
1317
+ const err = new ErrorCtor(
1318
+ prefix ? `Invalid WebSocket frame: ${message}` : message
1319
+ );
1320
+ Error.captureStackTrace(err, this.createError);
1321
+ err.code = errorCode;
1322
+ err[kStatusCode] = statusCode;
1323
+ return err;
1324
+ }
1325
+ };
1326
+ module.exports = Receiver2;
1327
+ }
1328
+ });
1329
+
1330
+ // ../../node_modules/ws/lib/sender.js
1331
+ var require_sender = __commonJS({
1332
+ "../../node_modules/ws/lib/sender.js"(exports, module) {
1333
+ "use strict";
1334
+ var { Duplex } = __require("stream");
1335
+ var { randomFillSync } = __require("crypto");
1336
+ var PerMessageDeflate = require_permessage_deflate();
1337
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1338
+ var { isBlob, isValidStatusCode } = require_validation();
1339
+ var { mask: applyMask, toBuffer } = require_buffer_util();
1340
+ var kByteLength = /* @__PURE__ */ Symbol("kByteLength");
1341
+ var maskBuffer = Buffer.alloc(4);
1342
+ var RANDOM_POOL_SIZE = 8 * 1024;
1343
+ var randomPool;
1344
+ var randomPoolPointer = RANDOM_POOL_SIZE;
1345
+ var DEFAULT = 0;
1346
+ var DEFLATING = 1;
1347
+ var GET_BLOB_DATA = 2;
1348
+ var Sender2 = class _Sender {
1349
+ /**
1350
+ * Creates a Sender instance.
1351
+ *
1352
+ * @param {Duplex} socket The connection socket
1353
+ * @param {Object} [extensions] An object containing the negotiated extensions
1354
+ * @param {Function} [generateMask] The function used to generate the masking
1355
+ * key
1356
+ */
1357
+ constructor(socket, extensions, generateMask) {
1358
+ this._extensions = extensions || {};
1359
+ if (generateMask) {
1360
+ this._generateMask = generateMask;
1361
+ this._maskBuffer = Buffer.alloc(4);
1362
+ }
1363
+ this._socket = socket;
1364
+ this._firstFragment = true;
1365
+ this._compress = false;
1366
+ this._bufferedBytes = 0;
1367
+ this._queue = [];
1368
+ this._state = DEFAULT;
1369
+ this.onerror = NOOP;
1370
+ this[kWebSocket] = void 0;
1371
+ }
1372
+ /**
1373
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1374
+ *
1375
+ * @param {(Buffer|String)} data The data to frame
1376
+ * @param {Object} options Options object
1377
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1378
+ * FIN bit
1379
+ * @param {Function} [options.generateMask] The function used to generate the
1380
+ * masking key
1381
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1382
+ * `data`
1383
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1384
+ * key
1385
+ * @param {Number} options.opcode The opcode
1386
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1387
+ * modified
1388
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1389
+ * RSV1 bit
1390
+ * @return {(Buffer|String)[]} The framed data
1391
+ * @public
1392
+ */
1393
+ static frame(data, options) {
1394
+ let mask;
1395
+ let merge = false;
1396
+ let offset = 2;
1397
+ let skipMasking = false;
1398
+ if (options.mask) {
1399
+ mask = options.maskBuffer || maskBuffer;
1400
+ if (options.generateMask) {
1401
+ options.generateMask(mask);
1402
+ } else {
1403
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1404
+ if (randomPool === void 0) {
1405
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1406
+ }
1407
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1408
+ randomPoolPointer = 0;
1409
+ }
1410
+ mask[0] = randomPool[randomPoolPointer++];
1411
+ mask[1] = randomPool[randomPoolPointer++];
1412
+ mask[2] = randomPool[randomPoolPointer++];
1413
+ mask[3] = randomPool[randomPoolPointer++];
1414
+ }
1415
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1416
+ offset = 6;
1417
+ }
1418
+ let dataLength;
1419
+ if (typeof data === "string") {
1420
+ if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1421
+ dataLength = options[kByteLength];
1422
+ } else {
1423
+ data = Buffer.from(data);
1424
+ dataLength = data.length;
1425
+ }
1426
+ } else {
1427
+ dataLength = data.length;
1428
+ merge = options.mask && options.readOnly && !skipMasking;
1429
+ }
1430
+ let payloadLength = dataLength;
1431
+ if (dataLength >= 65536) {
1432
+ offset += 8;
1433
+ payloadLength = 127;
1434
+ } else if (dataLength > 125) {
1435
+ offset += 2;
1436
+ payloadLength = 126;
1437
+ }
1438
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1439
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1440
+ if (options.rsv1) target[0] |= 64;
1441
+ target[1] = payloadLength;
1442
+ if (payloadLength === 126) {
1443
+ target.writeUInt16BE(dataLength, 2);
1444
+ } else if (payloadLength === 127) {
1445
+ target[2] = target[3] = 0;
1446
+ target.writeUIntBE(dataLength, 4, 6);
1447
+ }
1448
+ if (!options.mask) return [target, data];
1449
+ target[1] |= 128;
1450
+ target[offset - 4] = mask[0];
1451
+ target[offset - 3] = mask[1];
1452
+ target[offset - 2] = mask[2];
1453
+ target[offset - 1] = mask[3];
1454
+ if (skipMasking) return [target, data];
1455
+ if (merge) {
1456
+ applyMask(data, mask, target, offset, dataLength);
1457
+ return [target];
1458
+ }
1459
+ applyMask(data, mask, data, 0, dataLength);
1460
+ return [target, data];
1461
+ }
1462
+ /**
1463
+ * Sends a close message to the other peer.
1464
+ *
1465
+ * @param {Number} [code] The status code component of the body
1466
+ * @param {(String|Buffer)} [data] The message component of the body
1467
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1468
+ * @param {Function} [cb] Callback
1469
+ * @public
1470
+ */
1471
+ close(code, data, mask, cb) {
1472
+ let buf;
1473
+ if (code === void 0) {
1474
+ buf = EMPTY_BUFFER;
1475
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1476
+ throw new TypeError("First argument must be a valid error code number");
1477
+ } else if (data === void 0 || !data.length) {
1478
+ buf = Buffer.allocUnsafe(2);
1479
+ buf.writeUInt16BE(code, 0);
1480
+ } else {
1481
+ const length = Buffer.byteLength(data);
1482
+ if (length > 123) {
1483
+ throw new RangeError("The message must not be greater than 123 bytes");
1484
+ }
1485
+ buf = Buffer.allocUnsafe(2 + length);
1486
+ buf.writeUInt16BE(code, 0);
1487
+ if (typeof data === "string") {
1488
+ buf.write(data, 2);
1489
+ } else {
1490
+ buf.set(data, 2);
1491
+ }
1492
+ }
1493
+ const options = {
1494
+ [kByteLength]: buf.length,
1495
+ fin: true,
1496
+ generateMask: this._generateMask,
1497
+ mask,
1498
+ maskBuffer: this._maskBuffer,
1499
+ opcode: 8,
1500
+ readOnly: false,
1501
+ rsv1: false
1502
+ };
1503
+ if (this._state !== DEFAULT) {
1504
+ this.enqueue([this.dispatch, buf, false, options, cb]);
1505
+ } else {
1506
+ this.sendFrame(_Sender.frame(buf, options), cb);
1507
+ }
1508
+ }
1509
+ /**
1510
+ * Sends a ping message to the other peer.
1511
+ *
1512
+ * @param {*} data The message to send
1513
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1514
+ * @param {Function} [cb] Callback
1515
+ * @public
1516
+ */
1517
+ ping(data, mask, cb) {
1518
+ let byteLength;
1519
+ let readOnly;
1520
+ if (typeof data === "string") {
1521
+ byteLength = Buffer.byteLength(data);
1522
+ readOnly = false;
1523
+ } else if (isBlob(data)) {
1524
+ byteLength = data.size;
1525
+ readOnly = false;
1526
+ } else {
1527
+ data = toBuffer(data);
1528
+ byteLength = data.length;
1529
+ readOnly = toBuffer.readOnly;
1530
+ }
1531
+ if (byteLength > 125) {
1532
+ throw new RangeError("The data size must not be greater than 125 bytes");
1533
+ }
1534
+ const options = {
1535
+ [kByteLength]: byteLength,
1536
+ fin: true,
1537
+ generateMask: this._generateMask,
1538
+ mask,
1539
+ maskBuffer: this._maskBuffer,
1540
+ opcode: 9,
1541
+ readOnly,
1542
+ rsv1: false
1543
+ };
1544
+ if (isBlob(data)) {
1545
+ if (this._state !== DEFAULT) {
1546
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1547
+ } else {
1548
+ this.getBlobData(data, false, options, cb);
1549
+ }
1550
+ } else if (this._state !== DEFAULT) {
1551
+ this.enqueue([this.dispatch, data, false, options, cb]);
1552
+ } else {
1553
+ this.sendFrame(_Sender.frame(data, options), cb);
1554
+ }
1555
+ }
1556
+ /**
1557
+ * Sends a pong message to the other peer.
1558
+ *
1559
+ * @param {*} data The message to send
1560
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1561
+ * @param {Function} [cb] Callback
1562
+ * @public
1563
+ */
1564
+ pong(data, mask, cb) {
1565
+ let byteLength;
1566
+ let readOnly;
1567
+ if (typeof data === "string") {
1568
+ byteLength = Buffer.byteLength(data);
1569
+ readOnly = false;
1570
+ } else if (isBlob(data)) {
1571
+ byteLength = data.size;
1572
+ readOnly = false;
1573
+ } else {
1574
+ data = toBuffer(data);
1575
+ byteLength = data.length;
1576
+ readOnly = toBuffer.readOnly;
1577
+ }
1578
+ if (byteLength > 125) {
1579
+ throw new RangeError("The data size must not be greater than 125 bytes");
1580
+ }
1581
+ const options = {
1582
+ [kByteLength]: byteLength,
1583
+ fin: true,
1584
+ generateMask: this._generateMask,
1585
+ mask,
1586
+ maskBuffer: this._maskBuffer,
1587
+ opcode: 10,
1588
+ readOnly,
1589
+ rsv1: false
1590
+ };
1591
+ if (isBlob(data)) {
1592
+ if (this._state !== DEFAULT) {
1593
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1594
+ } else {
1595
+ this.getBlobData(data, false, options, cb);
1596
+ }
1597
+ } else if (this._state !== DEFAULT) {
1598
+ this.enqueue([this.dispatch, data, false, options, cb]);
1599
+ } else {
1600
+ this.sendFrame(_Sender.frame(data, options), cb);
1601
+ }
1602
+ }
1603
+ /**
1604
+ * Sends a data message to the other peer.
1605
+ *
1606
+ * @param {*} data The message to send
1607
+ * @param {Object} options Options object
1608
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1609
+ * or text
1610
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
1611
+ * compress `data`
1612
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1613
+ * last one
1614
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1615
+ * `data`
1616
+ * @param {Function} [cb] Callback
1617
+ * @public
1618
+ */
1619
+ send(data, options, cb) {
1620
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1621
+ let opcode = options.binary ? 2 : 1;
1622
+ let rsv1 = options.compress;
1623
+ let byteLength;
1624
+ let readOnly;
1625
+ if (typeof data === "string") {
1626
+ byteLength = Buffer.byteLength(data);
1627
+ readOnly = false;
1628
+ } else if (isBlob(data)) {
1629
+ byteLength = data.size;
1630
+ readOnly = false;
1631
+ } else {
1632
+ data = toBuffer(data);
1633
+ byteLength = data.length;
1634
+ readOnly = toBuffer.readOnly;
1635
+ }
1636
+ if (this._firstFragment) {
1637
+ this._firstFragment = false;
1638
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1639
+ rsv1 = byteLength >= perMessageDeflate._threshold;
1640
+ }
1641
+ this._compress = rsv1;
1642
+ } else {
1643
+ rsv1 = false;
1644
+ opcode = 0;
1645
+ }
1646
+ if (options.fin) this._firstFragment = true;
1647
+ const opts = {
1648
+ [kByteLength]: byteLength,
1649
+ fin: options.fin,
1650
+ generateMask: this._generateMask,
1651
+ mask: options.mask,
1652
+ maskBuffer: this._maskBuffer,
1653
+ opcode,
1654
+ readOnly,
1655
+ rsv1
1656
+ };
1657
+ if (isBlob(data)) {
1658
+ if (this._state !== DEFAULT) {
1659
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
1660
+ } else {
1661
+ this.getBlobData(data, this._compress, opts, cb);
1662
+ }
1663
+ } else if (this._state !== DEFAULT) {
1664
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1665
+ } else {
1666
+ this.dispatch(data, this._compress, opts, cb);
1667
+ }
1668
+ }
1669
+ /**
1670
+ * Gets the contents of a blob as binary data.
1671
+ *
1672
+ * @param {Blob} blob The blob
1673
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1674
+ * the data
1675
+ * @param {Object} options Options object
1676
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1677
+ * FIN bit
1678
+ * @param {Function} [options.generateMask] The function used to generate the
1679
+ * masking key
1680
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1681
+ * `data`
1682
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1683
+ * key
1684
+ * @param {Number} options.opcode The opcode
1685
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1686
+ * modified
1687
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1688
+ * RSV1 bit
1689
+ * @param {Function} [cb] Callback
1690
+ * @private
1691
+ */
1692
+ getBlobData(blob, compress, options, cb) {
1693
+ this._bufferedBytes += options[kByteLength];
1694
+ this._state = GET_BLOB_DATA;
1695
+ blob.arrayBuffer().then((arrayBuffer) => {
1696
+ if (this._socket.destroyed) {
1697
+ const err = new Error(
1698
+ "The socket was closed while the blob was being read"
1699
+ );
1700
+ process.nextTick(callCallbacks, this, err, cb);
1701
+ return;
1702
+ }
1703
+ this._bufferedBytes -= options[kByteLength];
1704
+ const data = toBuffer(arrayBuffer);
1705
+ if (!compress) {
1706
+ this._state = DEFAULT;
1707
+ this.sendFrame(_Sender.frame(data, options), cb);
1708
+ this.dequeue();
1709
+ } else {
1710
+ this.dispatch(data, compress, options, cb);
1711
+ }
1712
+ }).catch((err) => {
1713
+ process.nextTick(onError, this, err, cb);
1714
+ });
1715
+ }
1716
+ /**
1717
+ * Dispatches a message.
1718
+ *
1719
+ * @param {(Buffer|String)} data The message to send
1720
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1721
+ * `data`
1722
+ * @param {Object} options Options object
1723
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1724
+ * FIN bit
1725
+ * @param {Function} [options.generateMask] The function used to generate the
1726
+ * masking key
1727
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1728
+ * `data`
1729
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1730
+ * key
1731
+ * @param {Number} options.opcode The opcode
1732
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1733
+ * modified
1734
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1735
+ * RSV1 bit
1736
+ * @param {Function} [cb] Callback
1737
+ * @private
1738
+ */
1739
+ dispatch(data, compress, options, cb) {
1740
+ if (!compress) {
1741
+ this.sendFrame(_Sender.frame(data, options), cb);
1742
+ return;
1743
+ }
1744
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1745
+ this._bufferedBytes += options[kByteLength];
1746
+ this._state = DEFLATING;
1747
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
1748
+ if (this._socket.destroyed) {
1749
+ const err = new Error(
1750
+ "The socket was closed while data was being compressed"
1751
+ );
1752
+ callCallbacks(this, err, cb);
1753
+ return;
1754
+ }
1755
+ this._bufferedBytes -= options[kByteLength];
1756
+ this._state = DEFAULT;
1757
+ options.readOnly = false;
1758
+ this.sendFrame(_Sender.frame(buf, options), cb);
1759
+ this.dequeue();
1760
+ });
1761
+ }
1762
+ /**
1763
+ * Executes queued send operations.
1764
+ *
1765
+ * @private
1766
+ */
1767
+ dequeue() {
1768
+ while (this._state === DEFAULT && this._queue.length) {
1769
+ const params = this._queue.shift();
1770
+ this._bufferedBytes -= params[3][kByteLength];
1771
+ Reflect.apply(params[0], this, params.slice(1));
1772
+ }
1773
+ }
1774
+ /**
1775
+ * Enqueues a send operation.
1776
+ *
1777
+ * @param {Array} params Send operation parameters.
1778
+ * @private
1779
+ */
1780
+ enqueue(params) {
1781
+ this._bufferedBytes += params[3][kByteLength];
1782
+ this._queue.push(params);
1783
+ }
1784
+ /**
1785
+ * Sends a frame.
1786
+ *
1787
+ * @param {(Buffer | String)[]} list The frame to send
1788
+ * @param {Function} [cb] Callback
1789
+ * @private
1790
+ */
1791
+ sendFrame(list, cb) {
1792
+ if (list.length === 2) {
1793
+ this._socket.cork();
1794
+ this._socket.write(list[0]);
1795
+ this._socket.write(list[1], cb);
1796
+ this._socket.uncork();
1797
+ } else {
1798
+ this._socket.write(list[0], cb);
1799
+ }
1800
+ }
1801
+ };
1802
+ module.exports = Sender2;
1803
+ function callCallbacks(sender, err, cb) {
1804
+ if (typeof cb === "function") cb(err);
1805
+ for (let i = 0; i < sender._queue.length; i++) {
1806
+ const params = sender._queue[i];
1807
+ const callback = params[params.length - 1];
1808
+ if (typeof callback === "function") callback(err);
1809
+ }
1810
+ }
1811
+ function onError(sender, err, cb) {
1812
+ callCallbacks(sender, err, cb);
1813
+ sender.onerror(err);
1814
+ }
1815
+ }
1816
+ });
1817
+
1818
+ // ../../node_modules/ws/lib/event-target.js
1819
+ var require_event_target = __commonJS({
1820
+ "../../node_modules/ws/lib/event-target.js"(exports, module) {
1821
+ "use strict";
1822
+ var { kForOnEventAttribute, kListener } = require_constants();
1823
+ var kCode = /* @__PURE__ */ Symbol("kCode");
1824
+ var kData = /* @__PURE__ */ Symbol("kData");
1825
+ var kError = /* @__PURE__ */ Symbol("kError");
1826
+ var kMessage = /* @__PURE__ */ Symbol("kMessage");
1827
+ var kReason = /* @__PURE__ */ Symbol("kReason");
1828
+ var kTarget = /* @__PURE__ */ Symbol("kTarget");
1829
+ var kType = /* @__PURE__ */ Symbol("kType");
1830
+ var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
1831
+ var Event = class {
1832
+ /**
1833
+ * Create a new `Event`.
1834
+ *
1835
+ * @param {String} type The name of the event
1836
+ * @throws {TypeError} If the `type` argument is not specified
1837
+ */
1838
+ constructor(type) {
1839
+ this[kTarget] = null;
1840
+ this[kType] = type;
1841
+ }
1842
+ /**
1843
+ * @type {*}
1844
+ */
1845
+ get target() {
1846
+ return this[kTarget];
1847
+ }
1848
+ /**
1849
+ * @type {String}
1850
+ */
1851
+ get type() {
1852
+ return this[kType];
1853
+ }
1854
+ };
1855
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
1856
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
1857
+ var CloseEvent = class extends Event {
1858
+ /**
1859
+ * Create a new `CloseEvent`.
1860
+ *
1861
+ * @param {String} type The name of the event
1862
+ * @param {Object} [options] A dictionary object that allows for setting
1863
+ * attributes via object members of the same name
1864
+ * @param {Number} [options.code=0] The status code explaining why the
1865
+ * connection was closed
1866
+ * @param {String} [options.reason=''] A human-readable string explaining why
1867
+ * the connection was closed
1868
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1869
+ * connection was cleanly closed
1870
+ */
1871
+ constructor(type, options = {}) {
1872
+ super(type);
1873
+ this[kCode] = options.code === void 0 ? 0 : options.code;
1874
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
1875
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
1876
+ }
1877
+ /**
1878
+ * @type {Number}
1879
+ */
1880
+ get code() {
1881
+ return this[kCode];
1882
+ }
1883
+ /**
1884
+ * @type {String}
1885
+ */
1886
+ get reason() {
1887
+ return this[kReason];
1888
+ }
1889
+ /**
1890
+ * @type {Boolean}
1891
+ */
1892
+ get wasClean() {
1893
+ return this[kWasClean];
1894
+ }
1895
+ };
1896
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
1897
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
1898
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
1899
+ var ErrorEvent = class extends Event {
1900
+ /**
1901
+ * Create a new `ErrorEvent`.
1902
+ *
1903
+ * @param {String} type The name of the event
1904
+ * @param {Object} [options] A dictionary object that allows for setting
1905
+ * attributes via object members of the same name
1906
+ * @param {*} [options.error=null] The error that generated this event
1907
+ * @param {String} [options.message=''] The error message
1908
+ */
1909
+ constructor(type, options = {}) {
1910
+ super(type);
1911
+ this[kError] = options.error === void 0 ? null : options.error;
1912
+ this[kMessage] = options.message === void 0 ? "" : options.message;
1913
+ }
1914
+ /**
1915
+ * @type {*}
1916
+ */
1917
+ get error() {
1918
+ return this[kError];
1919
+ }
1920
+ /**
1921
+ * @type {String}
1922
+ */
1923
+ get message() {
1924
+ return this[kMessage];
1925
+ }
1926
+ };
1927
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
1928
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
1929
+ var MessageEvent = class extends Event {
1930
+ /**
1931
+ * Create a new `MessageEvent`.
1932
+ *
1933
+ * @param {String} type The name of the event
1934
+ * @param {Object} [options] A dictionary object that allows for setting
1935
+ * attributes via object members of the same name
1936
+ * @param {*} [options.data=null] The message content
1937
+ */
1938
+ constructor(type, options = {}) {
1939
+ super(type);
1940
+ this[kData] = options.data === void 0 ? null : options.data;
1941
+ }
1942
+ /**
1943
+ * @type {*}
1944
+ */
1945
+ get data() {
1946
+ return this[kData];
1947
+ }
1948
+ };
1949
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
1950
+ var EventTarget = {
1951
+ /**
1952
+ * Register an event listener.
1953
+ *
1954
+ * @param {String} type A string representing the event type to listen for
1955
+ * @param {(Function|Object)} handler The listener to add
1956
+ * @param {Object} [options] An options object specifies characteristics about
1957
+ * the event listener
1958
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1959
+ * listener should be invoked at most once after being added. If `true`,
1960
+ * the listener would be automatically removed when invoked.
1961
+ * @public
1962
+ */
1963
+ addEventListener(type, handler, options = {}) {
1964
+ for (const listener of this.listeners(type)) {
1965
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
1966
+ return;
1967
+ }
1968
+ }
1969
+ let wrapper;
1970
+ if (type === "message") {
1971
+ wrapper = function onMessage(data, isBinary) {
1972
+ const event = new MessageEvent("message", {
1973
+ data: isBinary ? data : data.toString()
1974
+ });
1975
+ event[kTarget] = this;
1976
+ callListener(handler, this, event);
1977
+ };
1978
+ } else if (type === "close") {
1979
+ wrapper = function onClose(code, message) {
1980
+ const event = new CloseEvent("close", {
1981
+ code,
1982
+ reason: message.toString(),
1983
+ wasClean: this._closeFrameReceived && this._closeFrameSent
1984
+ });
1985
+ event[kTarget] = this;
1986
+ callListener(handler, this, event);
1987
+ };
1988
+ } else if (type === "error") {
1989
+ wrapper = function onError(error) {
1990
+ const event = new ErrorEvent("error", {
1991
+ error,
1992
+ message: error.message
1993
+ });
1994
+ event[kTarget] = this;
1995
+ callListener(handler, this, event);
1996
+ };
1997
+ } else if (type === "open") {
1998
+ wrapper = function onOpen() {
1999
+ const event = new Event("open");
2000
+ event[kTarget] = this;
2001
+ callListener(handler, this, event);
2002
+ };
2003
+ } else {
2004
+ return;
2005
+ }
2006
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
2007
+ wrapper[kListener] = handler;
2008
+ if (options.once) {
2009
+ this.once(type, wrapper);
2010
+ } else {
2011
+ this.on(type, wrapper);
2012
+ }
2013
+ },
2014
+ /**
2015
+ * Remove an event listener.
2016
+ *
2017
+ * @param {String} type A string representing the event type to remove
2018
+ * @param {(Function|Object)} handler The listener to remove
2019
+ * @public
2020
+ */
2021
+ removeEventListener(type, handler) {
2022
+ for (const listener of this.listeners(type)) {
2023
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2024
+ this.removeListener(type, listener);
2025
+ break;
2026
+ }
2027
+ }
2028
+ }
2029
+ };
2030
+ module.exports = {
2031
+ CloseEvent,
2032
+ ErrorEvent,
2033
+ Event,
2034
+ EventTarget,
2035
+ MessageEvent
2036
+ };
2037
+ function callListener(listener, thisArg, event) {
2038
+ if (typeof listener === "object" && listener.handleEvent) {
2039
+ listener.handleEvent.call(listener, event);
2040
+ } else {
2041
+ listener.call(thisArg, event);
2042
+ }
2043
+ }
2044
+ }
2045
+ });
2046
+
2047
+ // ../../node_modules/ws/lib/extension.js
2048
+ var require_extension = __commonJS({
2049
+ "../../node_modules/ws/lib/extension.js"(exports, module) {
2050
+ "use strict";
2051
+ var { tokenChars } = require_validation();
2052
+ function push(dest, name, elem) {
2053
+ if (dest[name] === void 0) dest[name] = [elem];
2054
+ else dest[name].push(elem);
2055
+ }
2056
+ function parse(header) {
2057
+ const offers = /* @__PURE__ */ Object.create(null);
2058
+ let params = /* @__PURE__ */ Object.create(null);
2059
+ let mustUnescape = false;
2060
+ let isEscaping = false;
2061
+ let inQuotes = false;
2062
+ let extensionName;
2063
+ let paramName;
2064
+ let start = -1;
2065
+ let code = -1;
2066
+ let end = -1;
2067
+ let i = 0;
2068
+ for (; i < header.length; i++) {
2069
+ code = header.charCodeAt(i);
2070
+ if (extensionName === void 0) {
2071
+ if (end === -1 && tokenChars[code] === 1) {
2072
+ if (start === -1) start = i;
2073
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2074
+ if (end === -1 && start !== -1) end = i;
2075
+ } else if (code === 59 || code === 44) {
2076
+ if (start === -1) {
2077
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2078
+ }
2079
+ if (end === -1) end = i;
2080
+ const name = header.slice(start, end);
2081
+ if (code === 44) {
2082
+ push(offers, name, params);
2083
+ params = /* @__PURE__ */ Object.create(null);
2084
+ } else {
2085
+ extensionName = name;
2086
+ }
2087
+ start = end = -1;
2088
+ } else {
2089
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2090
+ }
2091
+ } else if (paramName === void 0) {
2092
+ if (end === -1 && tokenChars[code] === 1) {
2093
+ if (start === -1) start = i;
2094
+ } else if (code === 32 || code === 9) {
2095
+ if (end === -1 && start !== -1) end = i;
2096
+ } else if (code === 59 || code === 44) {
2097
+ if (start === -1) {
2098
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2099
+ }
2100
+ if (end === -1) end = i;
2101
+ push(params, header.slice(start, end), true);
2102
+ if (code === 44) {
2103
+ push(offers, extensionName, params);
2104
+ params = /* @__PURE__ */ Object.create(null);
2105
+ extensionName = void 0;
2106
+ }
2107
+ start = end = -1;
2108
+ } else if (code === 61 && start !== -1 && end === -1) {
2109
+ paramName = header.slice(start, i);
2110
+ start = end = -1;
2111
+ } else {
2112
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2113
+ }
2114
+ } else {
2115
+ if (isEscaping) {
2116
+ if (tokenChars[code] !== 1) {
2117
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2118
+ }
2119
+ if (start === -1) start = i;
2120
+ else if (!mustUnescape) mustUnescape = true;
2121
+ isEscaping = false;
2122
+ } else if (inQuotes) {
2123
+ if (tokenChars[code] === 1) {
2124
+ if (start === -1) start = i;
2125
+ } else if (code === 34 && start !== -1) {
2126
+ inQuotes = false;
2127
+ end = i;
2128
+ } else if (code === 92) {
2129
+ isEscaping = true;
2130
+ } else {
2131
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2132
+ }
2133
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2134
+ inQuotes = true;
2135
+ } else if (end === -1 && tokenChars[code] === 1) {
2136
+ if (start === -1) start = i;
2137
+ } else if (start !== -1 && (code === 32 || code === 9)) {
2138
+ if (end === -1) end = i;
2139
+ } else if (code === 59 || code === 44) {
2140
+ if (start === -1) {
2141
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2142
+ }
2143
+ if (end === -1) end = i;
2144
+ let value = header.slice(start, end);
2145
+ if (mustUnescape) {
2146
+ value = value.replace(/\\/g, "");
2147
+ mustUnescape = false;
2148
+ }
2149
+ push(params, paramName, value);
2150
+ if (code === 44) {
2151
+ push(offers, extensionName, params);
2152
+ params = /* @__PURE__ */ Object.create(null);
2153
+ extensionName = void 0;
2154
+ }
2155
+ paramName = void 0;
2156
+ start = end = -1;
2157
+ } else {
2158
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2159
+ }
2160
+ }
2161
+ }
2162
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
2163
+ throw new SyntaxError("Unexpected end of input");
2164
+ }
2165
+ if (end === -1) end = i;
2166
+ const token = header.slice(start, end);
2167
+ if (extensionName === void 0) {
2168
+ push(offers, token, params);
2169
+ } else {
2170
+ if (paramName === void 0) {
2171
+ push(params, token, true);
2172
+ } else if (mustUnescape) {
2173
+ push(params, paramName, token.replace(/\\/g, ""));
2174
+ } else {
2175
+ push(params, paramName, token);
2176
+ }
2177
+ push(offers, extensionName, params);
2178
+ }
2179
+ return offers;
2180
+ }
2181
+ function format(extensions) {
2182
+ return Object.keys(extensions).map((extension) => {
2183
+ let configurations = extensions[extension];
2184
+ if (!Array.isArray(configurations)) configurations = [configurations];
2185
+ return configurations.map((params) => {
2186
+ return [extension].concat(
2187
+ Object.keys(params).map((k) => {
2188
+ let values = params[k];
2189
+ if (!Array.isArray(values)) values = [values];
2190
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2191
+ })
2192
+ ).join("; ");
2193
+ }).join(", ");
2194
+ }).join(", ");
2195
+ }
2196
+ module.exports = { format, parse };
2197
+ }
2198
+ });
2199
+
2200
+ // ../../node_modules/ws/lib/websocket.js
2201
+ var require_websocket = __commonJS({
2202
+ "../../node_modules/ws/lib/websocket.js"(exports, module) {
2203
+ "use strict";
2204
+ var EventEmitter = __require("events");
2205
+ var https = __require("https");
2206
+ var http = __require("http");
2207
+ var net = __require("net");
2208
+ var tls = __require("tls");
2209
+ var { randomBytes, createHash } = __require("crypto");
2210
+ var { Duplex, Readable } = __require("stream");
2211
+ var { URL } = __require("url");
2212
+ var PerMessageDeflate = require_permessage_deflate();
2213
+ var Receiver2 = require_receiver();
2214
+ var Sender2 = require_sender();
2215
+ var { isBlob } = require_validation();
2216
+ var {
2217
+ BINARY_TYPES,
2218
+ EMPTY_BUFFER,
2219
+ GUID,
2220
+ kForOnEventAttribute,
2221
+ kListener,
2222
+ kStatusCode,
2223
+ kWebSocket,
2224
+ NOOP
2225
+ } = require_constants();
2226
+ var {
2227
+ EventTarget: { addEventListener, removeEventListener }
2228
+ } = require_event_target();
2229
+ var { format, parse } = require_extension();
2230
+ var { toBuffer } = require_buffer_util();
2231
+ var closeTimeout = 30 * 1e3;
2232
+ var kAborted = /* @__PURE__ */ Symbol("kAborted");
2233
+ var protocolVersions = [8, 13];
2234
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2235
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2236
+ var WebSocket2 = class _WebSocket extends EventEmitter {
2237
+ /**
2238
+ * Create a new `WebSocket`.
2239
+ *
2240
+ * @param {(String|URL)} address The URL to which to connect
2241
+ * @param {(String|String[])} [protocols] The subprotocols
2242
+ * @param {Object} [options] Connection options
2243
+ */
2244
+ constructor(address, protocols, options) {
2245
+ super();
2246
+ this._binaryType = BINARY_TYPES[0];
2247
+ this._closeCode = 1006;
2248
+ this._closeFrameReceived = false;
2249
+ this._closeFrameSent = false;
2250
+ this._closeMessage = EMPTY_BUFFER;
2251
+ this._closeTimer = null;
2252
+ this._errorEmitted = false;
2253
+ this._extensions = {};
2254
+ this._paused = false;
2255
+ this._protocol = "";
2256
+ this._readyState = _WebSocket.CONNECTING;
2257
+ this._receiver = null;
2258
+ this._sender = null;
2259
+ this._socket = null;
2260
+ if (address !== null) {
2261
+ this._bufferedAmount = 0;
2262
+ this._isServer = false;
2263
+ this._redirects = 0;
2264
+ if (protocols === void 0) {
2265
+ protocols = [];
2266
+ } else if (!Array.isArray(protocols)) {
2267
+ if (typeof protocols === "object" && protocols !== null) {
2268
+ options = protocols;
2269
+ protocols = [];
2270
+ } else {
2271
+ protocols = [protocols];
2272
+ }
2273
+ }
2274
+ initAsClient(this, address, protocols, options);
2275
+ } else {
2276
+ this._autoPong = options.autoPong;
2277
+ this._isServer = true;
2278
+ }
2279
+ }
2280
+ /**
2281
+ * For historical reasons, the custom "nodebuffer" type is used by the default
2282
+ * instead of "blob".
2283
+ *
2284
+ * @type {String}
2285
+ */
2286
+ get binaryType() {
2287
+ return this._binaryType;
2288
+ }
2289
+ set binaryType(type) {
2290
+ if (!BINARY_TYPES.includes(type)) return;
2291
+ this._binaryType = type;
2292
+ if (this._receiver) this._receiver._binaryType = type;
2293
+ }
2294
+ /**
2295
+ * @type {Number}
2296
+ */
2297
+ get bufferedAmount() {
2298
+ if (!this._socket) return this._bufferedAmount;
2299
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2300
+ }
2301
+ /**
2302
+ * @type {String}
2303
+ */
2304
+ get extensions() {
2305
+ return Object.keys(this._extensions).join();
2306
+ }
2307
+ /**
2308
+ * @type {Boolean}
2309
+ */
2310
+ get isPaused() {
2311
+ return this._paused;
2312
+ }
2313
+ /**
2314
+ * @type {Function}
2315
+ */
2316
+ /* istanbul ignore next */
2317
+ get onclose() {
2318
+ return null;
2319
+ }
2320
+ /**
2321
+ * @type {Function}
2322
+ */
2323
+ /* istanbul ignore next */
2324
+ get onerror() {
2325
+ return null;
2326
+ }
2327
+ /**
2328
+ * @type {Function}
2329
+ */
2330
+ /* istanbul ignore next */
2331
+ get onopen() {
2332
+ return null;
2333
+ }
2334
+ /**
2335
+ * @type {Function}
2336
+ */
2337
+ /* istanbul ignore next */
2338
+ get onmessage() {
2339
+ return null;
2340
+ }
2341
+ /**
2342
+ * @type {String}
2343
+ */
2344
+ get protocol() {
2345
+ return this._protocol;
2346
+ }
2347
+ /**
2348
+ * @type {Number}
2349
+ */
2350
+ get readyState() {
2351
+ return this._readyState;
2352
+ }
2353
+ /**
2354
+ * @type {String}
2355
+ */
2356
+ get url() {
2357
+ return this._url;
2358
+ }
2359
+ /**
2360
+ * Set up the socket and the internal resources.
2361
+ *
2362
+ * @param {Duplex} socket The network socket between the server and client
2363
+ * @param {Buffer} head The first packet of the upgraded stream
2364
+ * @param {Object} options Options object
2365
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
2366
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2367
+ * multiple times in the same tick
2368
+ * @param {Function} [options.generateMask] The function used to generate the
2369
+ * masking key
2370
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
2371
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2372
+ * not to skip UTF-8 validation for text and close messages
2373
+ * @private
2374
+ */
2375
+ setSocket(socket, head, options) {
2376
+ const receiver = new Receiver2({
2377
+ allowSynchronousEvents: options.allowSynchronousEvents,
2378
+ binaryType: this.binaryType,
2379
+ extensions: this._extensions,
2380
+ isServer: this._isServer,
2381
+ maxPayload: options.maxPayload,
2382
+ skipUTF8Validation: options.skipUTF8Validation
2383
+ });
2384
+ const sender = new Sender2(socket, this._extensions, options.generateMask);
2385
+ this._receiver = receiver;
2386
+ this._sender = sender;
2387
+ this._socket = socket;
2388
+ receiver[kWebSocket] = this;
2389
+ sender[kWebSocket] = this;
2390
+ socket[kWebSocket] = this;
2391
+ receiver.on("conclude", receiverOnConclude);
2392
+ receiver.on("drain", receiverOnDrain);
2393
+ receiver.on("error", receiverOnError);
2394
+ receiver.on("message", receiverOnMessage);
2395
+ receiver.on("ping", receiverOnPing);
2396
+ receiver.on("pong", receiverOnPong);
2397
+ sender.onerror = senderOnError;
2398
+ if (socket.setTimeout) socket.setTimeout(0);
2399
+ if (socket.setNoDelay) socket.setNoDelay();
2400
+ if (head.length > 0) socket.unshift(head);
2401
+ socket.on("close", socketOnClose);
2402
+ socket.on("data", socketOnData);
2403
+ socket.on("end", socketOnEnd);
2404
+ socket.on("error", socketOnError);
2405
+ this._readyState = _WebSocket.OPEN;
2406
+ this.emit("open");
2407
+ }
2408
+ /**
2409
+ * Emit the `'close'` event.
2410
+ *
2411
+ * @private
2412
+ */
2413
+ emitClose() {
2414
+ if (!this._socket) {
2415
+ this._readyState = _WebSocket.CLOSED;
2416
+ this.emit("close", this._closeCode, this._closeMessage);
2417
+ return;
2418
+ }
2419
+ if (this._extensions[PerMessageDeflate.extensionName]) {
2420
+ this._extensions[PerMessageDeflate.extensionName].cleanup();
2421
+ }
2422
+ this._receiver.removeAllListeners();
2423
+ this._readyState = _WebSocket.CLOSED;
2424
+ this.emit("close", this._closeCode, this._closeMessage);
2425
+ }
2426
+ /**
2427
+ * Start a closing handshake.
2428
+ *
2429
+ * +----------+ +-----------+ +----------+
2430
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2431
+ * | +----------+ +-----------+ +----------+ |
2432
+ * +----------+ +-----------+ |
2433
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2434
+ * +----------+ +-----------+ |
2435
+ * | | | +---+ |
2436
+ * +------------------------+-->|fin| - - - -
2437
+ * | +---+ | +---+
2438
+ * - - - - -|fin|<---------------------+
2439
+ * +---+
2440
+ *
2441
+ * @param {Number} [code] Status code explaining why the connection is closing
2442
+ * @param {(String|Buffer)} [data] The reason why the connection is
2443
+ * closing
2444
+ * @public
2445
+ */
2446
+ close(code, data) {
2447
+ if (this.readyState === _WebSocket.CLOSED) return;
2448
+ if (this.readyState === _WebSocket.CONNECTING) {
2449
+ const msg = "WebSocket was closed before the connection was established";
2450
+ abortHandshake(this, this._req, msg);
2451
+ return;
2452
+ }
2453
+ if (this.readyState === _WebSocket.CLOSING) {
2454
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2455
+ this._socket.end();
2456
+ }
2457
+ return;
2458
+ }
2459
+ this._readyState = _WebSocket.CLOSING;
2460
+ this._sender.close(code, data, !this._isServer, (err) => {
2461
+ if (err) return;
2462
+ this._closeFrameSent = true;
2463
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2464
+ this._socket.end();
2465
+ }
2466
+ });
2467
+ setCloseTimer(this);
2468
+ }
2469
+ /**
2470
+ * Pause the socket.
2471
+ *
2472
+ * @public
2473
+ */
2474
+ pause() {
2475
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2476
+ return;
2477
+ }
2478
+ this._paused = true;
2479
+ this._socket.pause();
2480
+ }
2481
+ /**
2482
+ * Send a ping.
2483
+ *
2484
+ * @param {*} [data] The data to send
2485
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2486
+ * @param {Function} [cb] Callback which is executed when the ping is sent
2487
+ * @public
2488
+ */
2489
+ ping(data, mask, cb) {
2490
+ if (this.readyState === _WebSocket.CONNECTING) {
2491
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2492
+ }
2493
+ if (typeof data === "function") {
2494
+ cb = data;
2495
+ data = mask = void 0;
2496
+ } else if (typeof mask === "function") {
2497
+ cb = mask;
2498
+ mask = void 0;
2499
+ }
2500
+ if (typeof data === "number") data = data.toString();
2501
+ if (this.readyState !== _WebSocket.OPEN) {
2502
+ sendAfterClose(this, data, cb);
2503
+ return;
2504
+ }
2505
+ if (mask === void 0) mask = !this._isServer;
2506
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2507
+ }
2508
+ /**
2509
+ * Send a pong.
2510
+ *
2511
+ * @param {*} [data] The data to send
2512
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2513
+ * @param {Function} [cb] Callback which is executed when the pong is sent
2514
+ * @public
2515
+ */
2516
+ pong(data, mask, cb) {
2517
+ if (this.readyState === _WebSocket.CONNECTING) {
2518
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2519
+ }
2520
+ if (typeof data === "function") {
2521
+ cb = data;
2522
+ data = mask = void 0;
2523
+ } else if (typeof mask === "function") {
2524
+ cb = mask;
2525
+ mask = void 0;
2526
+ }
2527
+ if (typeof data === "number") data = data.toString();
2528
+ if (this.readyState !== _WebSocket.OPEN) {
2529
+ sendAfterClose(this, data, cb);
2530
+ return;
2531
+ }
2532
+ if (mask === void 0) mask = !this._isServer;
2533
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2534
+ }
2535
+ /**
2536
+ * Resume the socket.
2537
+ *
2538
+ * @public
2539
+ */
2540
+ resume() {
2541
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
2542
+ return;
2543
+ }
2544
+ this._paused = false;
2545
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
2546
+ }
2547
+ /**
2548
+ * Send a data message.
2549
+ *
2550
+ * @param {*} data The message to send
2551
+ * @param {Object} [options] Options object
2552
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2553
+ * text
2554
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
2555
+ * `data`
2556
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2557
+ * last one
2558
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2559
+ * @param {Function} [cb] Callback which is executed when data is written out
2560
+ * @public
2561
+ */
2562
+ send(data, options, cb) {
2563
+ if (this.readyState === _WebSocket.CONNECTING) {
2564
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2565
+ }
2566
+ if (typeof options === "function") {
2567
+ cb = options;
2568
+ options = {};
2569
+ }
2570
+ if (typeof data === "number") data = data.toString();
2571
+ if (this.readyState !== _WebSocket.OPEN) {
2572
+ sendAfterClose(this, data, cb);
2573
+ return;
2574
+ }
2575
+ const opts = {
2576
+ binary: typeof data !== "string",
2577
+ mask: !this._isServer,
2578
+ compress: true,
2579
+ fin: true,
2580
+ ...options
2581
+ };
2582
+ if (!this._extensions[PerMessageDeflate.extensionName]) {
2583
+ opts.compress = false;
2584
+ }
2585
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2586
+ }
2587
+ /**
2588
+ * Forcibly close the connection.
2589
+ *
2590
+ * @public
2591
+ */
2592
+ terminate() {
2593
+ if (this.readyState === _WebSocket.CLOSED) return;
2594
+ if (this.readyState === _WebSocket.CONNECTING) {
2595
+ const msg = "WebSocket was closed before the connection was established";
2596
+ abortHandshake(this, this._req, msg);
2597
+ return;
2598
+ }
2599
+ if (this._socket) {
2600
+ this._readyState = _WebSocket.CLOSING;
2601
+ this._socket.destroy();
2602
+ }
2603
+ }
2604
+ };
2605
+ Object.defineProperty(WebSocket2, "CONNECTING", {
2606
+ enumerable: true,
2607
+ value: readyStates.indexOf("CONNECTING")
2608
+ });
2609
+ Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
2610
+ enumerable: true,
2611
+ value: readyStates.indexOf("CONNECTING")
2612
+ });
2613
+ Object.defineProperty(WebSocket2, "OPEN", {
2614
+ enumerable: true,
2615
+ value: readyStates.indexOf("OPEN")
2616
+ });
2617
+ Object.defineProperty(WebSocket2.prototype, "OPEN", {
2618
+ enumerable: true,
2619
+ value: readyStates.indexOf("OPEN")
2620
+ });
2621
+ Object.defineProperty(WebSocket2, "CLOSING", {
2622
+ enumerable: true,
2623
+ value: readyStates.indexOf("CLOSING")
2624
+ });
2625
+ Object.defineProperty(WebSocket2.prototype, "CLOSING", {
2626
+ enumerable: true,
2627
+ value: readyStates.indexOf("CLOSING")
2628
+ });
2629
+ Object.defineProperty(WebSocket2, "CLOSED", {
2630
+ enumerable: true,
2631
+ value: readyStates.indexOf("CLOSED")
2632
+ });
2633
+ Object.defineProperty(WebSocket2.prototype, "CLOSED", {
2634
+ enumerable: true,
2635
+ value: readyStates.indexOf("CLOSED")
2636
+ });
2637
+ [
2638
+ "binaryType",
2639
+ "bufferedAmount",
2640
+ "extensions",
2641
+ "isPaused",
2642
+ "protocol",
2643
+ "readyState",
2644
+ "url"
2645
+ ].forEach((property) => {
2646
+ Object.defineProperty(WebSocket2.prototype, property, { enumerable: true });
2647
+ });
2648
+ ["open", "error", "close", "message"].forEach((method) => {
2649
+ Object.defineProperty(WebSocket2.prototype, `on${method}`, {
2650
+ enumerable: true,
2651
+ get() {
2652
+ for (const listener of this.listeners(method)) {
2653
+ if (listener[kForOnEventAttribute]) return listener[kListener];
2654
+ }
2655
+ return null;
2656
+ },
2657
+ set(handler) {
2658
+ for (const listener of this.listeners(method)) {
2659
+ if (listener[kForOnEventAttribute]) {
2660
+ this.removeListener(method, listener);
2661
+ break;
2662
+ }
2663
+ }
2664
+ if (typeof handler !== "function") return;
2665
+ this.addEventListener(method, handler, {
2666
+ [kForOnEventAttribute]: true
2667
+ });
2668
+ }
2669
+ });
2670
+ });
2671
+ WebSocket2.prototype.addEventListener = addEventListener;
2672
+ WebSocket2.prototype.removeEventListener = removeEventListener;
2673
+ module.exports = WebSocket2;
2674
+ function initAsClient(websocket, address, protocols, options) {
2675
+ const opts = {
2676
+ allowSynchronousEvents: true,
2677
+ autoPong: true,
2678
+ protocolVersion: protocolVersions[1],
2679
+ maxPayload: 100 * 1024 * 1024,
2680
+ skipUTF8Validation: false,
2681
+ perMessageDeflate: true,
2682
+ followRedirects: false,
2683
+ maxRedirects: 10,
2684
+ ...options,
2685
+ socketPath: void 0,
2686
+ hostname: void 0,
2687
+ protocol: void 0,
2688
+ timeout: void 0,
2689
+ method: "GET",
2690
+ host: void 0,
2691
+ path: void 0,
2692
+ port: void 0
2693
+ };
2694
+ websocket._autoPong = opts.autoPong;
2695
+ if (!protocolVersions.includes(opts.protocolVersion)) {
2696
+ throw new RangeError(
2697
+ `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
2698
+ );
2699
+ }
2700
+ let parsedUrl;
2701
+ if (address instanceof URL) {
2702
+ parsedUrl = address;
2703
+ } else {
2704
+ try {
2705
+ parsedUrl = new URL(address);
2706
+ } catch (e) {
2707
+ throw new SyntaxError(`Invalid URL: ${address}`);
2708
+ }
2709
+ }
2710
+ if (parsedUrl.protocol === "http:") {
2711
+ parsedUrl.protocol = "ws:";
2712
+ } else if (parsedUrl.protocol === "https:") {
2713
+ parsedUrl.protocol = "wss:";
2714
+ }
2715
+ websocket._url = parsedUrl.href;
2716
+ const isSecure = parsedUrl.protocol === "wss:";
2717
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
2718
+ let invalidUrlMessage;
2719
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
2720
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
2721
+ } else if (isIpcUrl && !parsedUrl.pathname) {
2722
+ invalidUrlMessage = "The URL's pathname is empty";
2723
+ } else if (parsedUrl.hash) {
2724
+ invalidUrlMessage = "The URL contains a fragment identifier";
2725
+ }
2726
+ if (invalidUrlMessage) {
2727
+ const err = new SyntaxError(invalidUrlMessage);
2728
+ if (websocket._redirects === 0) {
2729
+ throw err;
2730
+ } else {
2731
+ emitErrorAndClose(websocket, err);
2732
+ return;
2733
+ }
2734
+ }
2735
+ const defaultPort = isSecure ? 443 : 80;
2736
+ const key = randomBytes(16).toString("base64");
2737
+ const request = isSecure ? https.request : http.request;
2738
+ const protocolSet = /* @__PURE__ */ new Set();
2739
+ let perMessageDeflate;
2740
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2741
+ opts.defaultPort = opts.defaultPort || defaultPort;
2742
+ opts.port = parsedUrl.port || defaultPort;
2743
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2744
+ opts.headers = {
2745
+ ...opts.headers,
2746
+ "Sec-WebSocket-Version": opts.protocolVersion,
2747
+ "Sec-WebSocket-Key": key,
2748
+ Connection: "Upgrade",
2749
+ Upgrade: "websocket"
2750
+ };
2751
+ opts.path = parsedUrl.pathname + parsedUrl.search;
2752
+ opts.timeout = opts.handshakeTimeout;
2753
+ if (opts.perMessageDeflate) {
2754
+ perMessageDeflate = new PerMessageDeflate(
2755
+ opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
2756
+ false,
2757
+ opts.maxPayload
2758
+ );
2759
+ opts.headers["Sec-WebSocket-Extensions"] = format({
2760
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2761
+ });
2762
+ }
2763
+ if (protocols.length) {
2764
+ for (const protocol of protocols) {
2765
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
2766
+ throw new SyntaxError(
2767
+ "An invalid or duplicated subprotocol was specified"
2768
+ );
2769
+ }
2770
+ protocolSet.add(protocol);
2771
+ }
2772
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
2773
+ }
2774
+ if (opts.origin) {
2775
+ if (opts.protocolVersion < 13) {
2776
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
2777
+ } else {
2778
+ opts.headers.Origin = opts.origin;
2779
+ }
2780
+ }
2781
+ if (parsedUrl.username || parsedUrl.password) {
2782
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2783
+ }
2784
+ if (isIpcUrl) {
2785
+ const parts = opts.path.split(":");
2786
+ opts.socketPath = parts[0];
2787
+ opts.path = parts[1];
2788
+ }
2789
+ let req;
2790
+ if (opts.followRedirects) {
2791
+ if (websocket._redirects === 0) {
2792
+ websocket._originalIpc = isIpcUrl;
2793
+ websocket._originalSecure = isSecure;
2794
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2795
+ const headers = options && options.headers;
2796
+ options = { ...options, headers: {} };
2797
+ if (headers) {
2798
+ for (const [key2, value] of Object.entries(headers)) {
2799
+ options.headers[key2.toLowerCase()] = value;
2800
+ }
2801
+ }
2802
+ } else if (websocket.listenerCount("redirect") === 0) {
2803
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2804
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
2805
+ delete opts.headers.authorization;
2806
+ delete opts.headers.cookie;
2807
+ if (!isSameHost) delete opts.headers.host;
2808
+ opts.auth = void 0;
2809
+ }
2810
+ }
2811
+ if (opts.auth && !options.headers.authorization) {
2812
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
2813
+ }
2814
+ req = websocket._req = request(opts);
2815
+ if (websocket._redirects) {
2816
+ websocket.emit("redirect", websocket.url, req);
2817
+ }
2818
+ } else {
2819
+ req = websocket._req = request(opts);
2820
+ }
2821
+ if (opts.timeout) {
2822
+ req.on("timeout", () => {
2823
+ abortHandshake(websocket, req, "Opening handshake has timed out");
2824
+ });
2825
+ }
2826
+ req.on("error", (err) => {
2827
+ if (req === null || req[kAborted]) return;
2828
+ req = websocket._req = null;
2829
+ emitErrorAndClose(websocket, err);
2830
+ });
2831
+ req.on("response", (res) => {
2832
+ const location = res.headers.location;
2833
+ const statusCode = res.statusCode;
2834
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2835
+ if (++websocket._redirects > opts.maxRedirects) {
2836
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
2837
+ return;
2838
+ }
2839
+ req.abort();
2840
+ let addr;
2841
+ try {
2842
+ addr = new URL(location, address);
2843
+ } catch (e) {
2844
+ const err = new SyntaxError(`Invalid URL: ${location}`);
2845
+ emitErrorAndClose(websocket, err);
2846
+ return;
2847
+ }
2848
+ initAsClient(websocket, addr, protocols, options);
2849
+ } else if (!websocket.emit("unexpected-response", req, res)) {
2850
+ abortHandshake(
2851
+ websocket,
2852
+ req,
2853
+ `Unexpected server response: ${res.statusCode}`
2854
+ );
2855
+ }
2856
+ });
2857
+ req.on("upgrade", (res, socket, head) => {
2858
+ websocket.emit("upgrade", res);
2859
+ if (websocket.readyState !== WebSocket2.CONNECTING) return;
2860
+ req = websocket._req = null;
2861
+ const upgrade = res.headers.upgrade;
2862
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
2863
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
2864
+ return;
2865
+ }
2866
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
2867
+ if (res.headers["sec-websocket-accept"] !== digest) {
2868
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
2869
+ return;
2870
+ }
2871
+ const serverProt = res.headers["sec-websocket-protocol"];
2872
+ let protError;
2873
+ if (serverProt !== void 0) {
2874
+ if (!protocolSet.size) {
2875
+ protError = "Server sent a subprotocol but none was requested";
2876
+ } else if (!protocolSet.has(serverProt)) {
2877
+ protError = "Server sent an invalid subprotocol";
2878
+ }
2879
+ } else if (protocolSet.size) {
2880
+ protError = "Server sent no subprotocol";
2881
+ }
2882
+ if (protError) {
2883
+ abortHandshake(websocket, socket, protError);
2884
+ return;
2885
+ }
2886
+ if (serverProt) websocket._protocol = serverProt;
2887
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
2888
+ if (secWebSocketExtensions !== void 0) {
2889
+ if (!perMessageDeflate) {
2890
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
2891
+ abortHandshake(websocket, socket, message);
2892
+ return;
2893
+ }
2894
+ let extensions;
2895
+ try {
2896
+ extensions = parse(secWebSocketExtensions);
2897
+ } catch (err) {
2898
+ const message = "Invalid Sec-WebSocket-Extensions header";
2899
+ abortHandshake(websocket, socket, message);
2900
+ return;
2901
+ }
2902
+ const extensionNames = Object.keys(extensions);
2903
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
2904
+ const message = "Server indicated an extension that was not requested";
2905
+ abortHandshake(websocket, socket, message);
2906
+ return;
2907
+ }
2908
+ try {
2909
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2910
+ } catch (err) {
2911
+ const message = "Invalid Sec-WebSocket-Extensions header";
2912
+ abortHandshake(websocket, socket, message);
2913
+ return;
2914
+ }
2915
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2916
+ }
2917
+ websocket.setSocket(socket, head, {
2918
+ allowSynchronousEvents: opts.allowSynchronousEvents,
2919
+ generateMask: opts.generateMask,
2920
+ maxPayload: opts.maxPayload,
2921
+ skipUTF8Validation: opts.skipUTF8Validation
2922
+ });
2923
+ });
2924
+ if (opts.finishRequest) {
2925
+ opts.finishRequest(req, websocket);
2926
+ } else {
2927
+ req.end();
2928
+ }
2929
+ }
2930
+ function emitErrorAndClose(websocket, err) {
2931
+ websocket._readyState = WebSocket2.CLOSING;
2932
+ websocket._errorEmitted = true;
2933
+ websocket.emit("error", err);
2934
+ websocket.emitClose();
2935
+ }
2936
+ function netConnect(options) {
2937
+ options.path = options.socketPath;
2938
+ return net.connect(options);
2939
+ }
2940
+ function tlsConnect(options) {
2941
+ options.path = void 0;
2942
+ if (!options.servername && options.servername !== "") {
2943
+ options.servername = net.isIP(options.host) ? "" : options.host;
2944
+ }
2945
+ return tls.connect(options);
2946
+ }
2947
+ function abortHandshake(websocket, stream, message) {
2948
+ websocket._readyState = WebSocket2.CLOSING;
2949
+ const err = new Error(message);
2950
+ Error.captureStackTrace(err, abortHandshake);
2951
+ if (stream.setHeader) {
2952
+ stream[kAborted] = true;
2953
+ stream.abort();
2954
+ if (stream.socket && !stream.socket.destroyed) {
2955
+ stream.socket.destroy();
2956
+ }
2957
+ process.nextTick(emitErrorAndClose, websocket, err);
2958
+ } else {
2959
+ stream.destroy(err);
2960
+ stream.once("error", websocket.emit.bind(websocket, "error"));
2961
+ stream.once("close", websocket.emitClose.bind(websocket));
2962
+ }
2963
+ }
2964
+ function sendAfterClose(websocket, data, cb) {
2965
+ if (data) {
2966
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
2967
+ if (websocket._socket) websocket._sender._bufferedBytes += length;
2968
+ else websocket._bufferedAmount += length;
2969
+ }
2970
+ if (cb) {
2971
+ const err = new Error(
2972
+ `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
2973
+ );
2974
+ process.nextTick(cb, err);
2975
+ }
2976
+ }
2977
+ function receiverOnConclude(code, reason) {
2978
+ const websocket = this[kWebSocket];
2979
+ websocket._closeFrameReceived = true;
2980
+ websocket._closeMessage = reason;
2981
+ websocket._closeCode = code;
2982
+ if (websocket._socket[kWebSocket] === void 0) return;
2983
+ websocket._socket.removeListener("data", socketOnData);
2984
+ process.nextTick(resume, websocket._socket);
2985
+ if (code === 1005) websocket.close();
2986
+ else websocket.close(code, reason);
2987
+ }
2988
+ function receiverOnDrain() {
2989
+ const websocket = this[kWebSocket];
2990
+ if (!websocket.isPaused) websocket._socket.resume();
2991
+ }
2992
+ function receiverOnError(err) {
2993
+ const websocket = this[kWebSocket];
2994
+ if (websocket._socket[kWebSocket] !== void 0) {
2995
+ websocket._socket.removeListener("data", socketOnData);
2996
+ process.nextTick(resume, websocket._socket);
2997
+ websocket.close(err[kStatusCode]);
2998
+ }
2999
+ if (!websocket._errorEmitted) {
3000
+ websocket._errorEmitted = true;
3001
+ websocket.emit("error", err);
3002
+ }
3003
+ }
3004
+ function receiverOnFinish() {
3005
+ this[kWebSocket].emitClose();
3006
+ }
3007
+ function receiverOnMessage(data, isBinary) {
3008
+ this[kWebSocket].emit("message", data, isBinary);
3009
+ }
3010
+ function receiverOnPing(data) {
3011
+ const websocket = this[kWebSocket];
3012
+ if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
3013
+ websocket.emit("ping", data);
3014
+ }
3015
+ function receiverOnPong(data) {
3016
+ this[kWebSocket].emit("pong", data);
3017
+ }
3018
+ function resume(stream) {
3019
+ stream.resume();
3020
+ }
3021
+ function senderOnError(err) {
3022
+ const websocket = this[kWebSocket];
3023
+ if (websocket.readyState === WebSocket2.CLOSED) return;
3024
+ if (websocket.readyState === WebSocket2.OPEN) {
3025
+ websocket._readyState = WebSocket2.CLOSING;
3026
+ setCloseTimer(websocket);
3027
+ }
3028
+ this._socket.end();
3029
+ if (!websocket._errorEmitted) {
3030
+ websocket._errorEmitted = true;
3031
+ websocket.emit("error", err);
3032
+ }
3033
+ }
3034
+ function setCloseTimer(websocket) {
3035
+ websocket._closeTimer = setTimeout(
3036
+ websocket._socket.destroy.bind(websocket._socket),
3037
+ closeTimeout
3038
+ );
3039
+ }
3040
+ function socketOnClose() {
3041
+ const websocket = this[kWebSocket];
3042
+ this.removeListener("close", socketOnClose);
3043
+ this.removeListener("data", socketOnData);
3044
+ this.removeListener("end", socketOnEnd);
3045
+ websocket._readyState = WebSocket2.CLOSING;
3046
+ let chunk;
3047
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
3048
+ websocket._receiver.write(chunk);
3049
+ }
3050
+ websocket._receiver.end();
3051
+ this[kWebSocket] = void 0;
3052
+ clearTimeout(websocket._closeTimer);
3053
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3054
+ websocket.emitClose();
3055
+ } else {
3056
+ websocket._receiver.on("error", receiverOnFinish);
3057
+ websocket._receiver.on("finish", receiverOnFinish);
3058
+ }
3059
+ }
3060
+ function socketOnData(chunk) {
3061
+ if (!this[kWebSocket]._receiver.write(chunk)) {
3062
+ this.pause();
3063
+ }
3064
+ }
3065
+ function socketOnEnd() {
3066
+ const websocket = this[kWebSocket];
3067
+ websocket._readyState = WebSocket2.CLOSING;
3068
+ websocket._receiver.end();
3069
+ this.end();
3070
+ }
3071
+ function socketOnError() {
3072
+ const websocket = this[kWebSocket];
3073
+ this.removeListener("error", socketOnError);
3074
+ this.on("error", NOOP);
3075
+ if (websocket) {
3076
+ websocket._readyState = WebSocket2.CLOSING;
3077
+ this.destroy();
3078
+ }
3079
+ }
3080
+ }
3081
+ });
3082
+
3083
+ // ../../node_modules/ws/lib/stream.js
3084
+ var require_stream = __commonJS({
3085
+ "../../node_modules/ws/lib/stream.js"(exports, module) {
3086
+ "use strict";
3087
+ var WebSocket2 = require_websocket();
3088
+ var { Duplex } = __require("stream");
3089
+ function emitClose(stream) {
3090
+ stream.emit("close");
3091
+ }
3092
+ function duplexOnEnd() {
3093
+ if (!this.destroyed && this._writableState.finished) {
3094
+ this.destroy();
3095
+ }
3096
+ }
3097
+ function duplexOnError(err) {
3098
+ this.removeListener("error", duplexOnError);
3099
+ this.destroy();
3100
+ if (this.listenerCount("error") === 0) {
3101
+ this.emit("error", err);
3102
+ }
3103
+ }
3104
+ function createWebSocketStream2(ws, options) {
3105
+ let terminateOnDestroy = true;
3106
+ const duplex = new Duplex({
3107
+ ...options,
3108
+ autoDestroy: false,
3109
+ emitClose: false,
3110
+ objectMode: false,
3111
+ writableObjectMode: false
3112
+ });
3113
+ ws.on("message", function message(msg, isBinary) {
3114
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
3115
+ if (!duplex.push(data)) ws.pause();
3116
+ });
3117
+ ws.once("error", function error(err) {
3118
+ if (duplex.destroyed) return;
3119
+ terminateOnDestroy = false;
3120
+ duplex.destroy(err);
3121
+ });
3122
+ ws.once("close", function close() {
3123
+ if (duplex.destroyed) return;
3124
+ duplex.push(null);
3125
+ });
3126
+ duplex._destroy = function(err, callback) {
3127
+ if (ws.readyState === ws.CLOSED) {
3128
+ callback(err);
3129
+ process.nextTick(emitClose, duplex);
3130
+ return;
3131
+ }
3132
+ let called = false;
3133
+ ws.once("error", function error(err2) {
3134
+ called = true;
3135
+ callback(err2);
3136
+ });
3137
+ ws.once("close", function close() {
3138
+ if (!called) callback(err);
3139
+ process.nextTick(emitClose, duplex);
3140
+ });
3141
+ if (terminateOnDestroy) ws.terminate();
3142
+ };
3143
+ duplex._final = function(callback) {
3144
+ if (ws.readyState === ws.CONNECTING) {
3145
+ ws.once("open", function open() {
3146
+ duplex._final(callback);
3147
+ });
3148
+ return;
3149
+ }
3150
+ if (ws._socket === null) return;
3151
+ if (ws._socket._writableState.finished) {
3152
+ callback();
3153
+ if (duplex._readableState.endEmitted) duplex.destroy();
3154
+ } else {
3155
+ ws._socket.once("finish", function finish() {
3156
+ callback();
3157
+ });
3158
+ ws.close();
3159
+ }
3160
+ };
3161
+ duplex._read = function() {
3162
+ if (ws.isPaused) ws.resume();
3163
+ };
3164
+ duplex._write = function(chunk, encoding, callback) {
3165
+ if (ws.readyState === ws.CONNECTING) {
3166
+ ws.once("open", function open() {
3167
+ duplex._write(chunk, encoding, callback);
3168
+ });
3169
+ return;
3170
+ }
3171
+ ws.send(chunk, callback);
3172
+ };
3173
+ duplex.on("end", duplexOnEnd);
3174
+ duplex.on("error", duplexOnError);
3175
+ return duplex;
3176
+ }
3177
+ module.exports = createWebSocketStream2;
3178
+ }
3179
+ });
3180
+
3181
+ // ../../node_modules/ws/lib/subprotocol.js
3182
+ var require_subprotocol = __commonJS({
3183
+ "../../node_modules/ws/lib/subprotocol.js"(exports, module) {
3184
+ "use strict";
3185
+ var { tokenChars } = require_validation();
3186
+ function parse(header) {
3187
+ const protocols = /* @__PURE__ */ new Set();
3188
+ let start = -1;
3189
+ let end = -1;
3190
+ let i = 0;
3191
+ for (i; i < header.length; i++) {
3192
+ const code = header.charCodeAt(i);
3193
+ if (end === -1 && tokenChars[code] === 1) {
3194
+ if (start === -1) start = i;
3195
+ } else if (i !== 0 && (code === 32 || code === 9)) {
3196
+ if (end === -1 && start !== -1) end = i;
3197
+ } else if (code === 44) {
3198
+ if (start === -1) {
3199
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3200
+ }
3201
+ if (end === -1) end = i;
3202
+ const protocol2 = header.slice(start, end);
3203
+ if (protocols.has(protocol2)) {
3204
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3205
+ }
3206
+ protocols.add(protocol2);
3207
+ start = end = -1;
3208
+ } else {
3209
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3210
+ }
3211
+ }
3212
+ if (start === -1 || end !== -1) {
3213
+ throw new SyntaxError("Unexpected end of input");
3214
+ }
3215
+ const protocol = header.slice(start, i);
3216
+ if (protocols.has(protocol)) {
3217
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3218
+ }
3219
+ protocols.add(protocol);
3220
+ return protocols;
3221
+ }
3222
+ module.exports = { parse };
3223
+ }
3224
+ });
3225
+
3226
+ // ../../node_modules/ws/lib/websocket-server.js
3227
+ var require_websocket_server = __commonJS({
3228
+ "../../node_modules/ws/lib/websocket-server.js"(exports, module) {
3229
+ "use strict";
3230
+ var EventEmitter = __require("events");
3231
+ var http = __require("http");
3232
+ var { Duplex } = __require("stream");
3233
+ var { createHash } = __require("crypto");
3234
+ var extension = require_extension();
3235
+ var PerMessageDeflate = require_permessage_deflate();
3236
+ var subprotocol = require_subprotocol();
3237
+ var WebSocket2 = require_websocket();
3238
+ var { GUID, kWebSocket } = require_constants();
3239
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3240
+ var RUNNING = 0;
3241
+ var CLOSING = 1;
3242
+ var CLOSED = 2;
3243
+ var WebSocketServer2 = class extends EventEmitter {
3244
+ /**
3245
+ * Create a `WebSocketServer` instance.
3246
+ *
3247
+ * @param {Object} options Configuration options
3248
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
3249
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
3250
+ * multiple times in the same tick
3251
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
3252
+ * automatically send a pong in response to a ping
3253
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
3254
+ * pending connections
3255
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3256
+ * track clients
3257
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
3258
+ * @param {String} [options.host] The hostname where to bind the server
3259
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3260
+ * size
3261
+ * @param {Boolean} [options.noServer=false] Enable no server mode
3262
+ * @param {String} [options.path] Accept only connections matching this path
3263
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3264
+ * permessage-deflate
3265
+ * @param {Number} [options.port] The port where to bind the server
3266
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3267
+ * server to use
3268
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3269
+ * not to skip UTF-8 validation for text and close messages
3270
+ * @param {Function} [options.verifyClient] A hook to reject connections
3271
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3272
+ * class to use. It must be the `WebSocket` class or class that extends it
3273
+ * @param {Function} [callback] A listener for the `listening` event
3274
+ */
3275
+ constructor(options, callback) {
3276
+ super();
3277
+ options = {
3278
+ allowSynchronousEvents: true,
3279
+ autoPong: true,
3280
+ maxPayload: 100 * 1024 * 1024,
3281
+ skipUTF8Validation: false,
3282
+ perMessageDeflate: false,
3283
+ handleProtocols: null,
3284
+ clientTracking: true,
3285
+ verifyClient: null,
3286
+ noServer: false,
3287
+ backlog: null,
3288
+ // use default (511 as implemented in net.js)
3289
+ server: null,
3290
+ host: null,
3291
+ path: null,
3292
+ port: null,
3293
+ WebSocket: WebSocket2,
3294
+ ...options
3295
+ };
3296
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3297
+ throw new TypeError(
3298
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
3299
+ );
3300
+ }
3301
+ if (options.port != null) {
3302
+ this._server = http.createServer((req, res) => {
3303
+ const body = http.STATUS_CODES[426];
3304
+ res.writeHead(426, {
3305
+ "Content-Length": body.length,
3306
+ "Content-Type": "text/plain"
3307
+ });
3308
+ res.end(body);
3309
+ });
3310
+ this._server.listen(
3311
+ options.port,
3312
+ options.host,
3313
+ options.backlog,
3314
+ callback
3315
+ );
3316
+ } else if (options.server) {
3317
+ this._server = options.server;
3318
+ }
3319
+ if (this._server) {
3320
+ const emitConnection = this.emit.bind(this, "connection");
3321
+ this._removeListeners = addListeners(this._server, {
3322
+ listening: this.emit.bind(this, "listening"),
3323
+ error: this.emit.bind(this, "error"),
3324
+ upgrade: (req, socket, head) => {
3325
+ this.handleUpgrade(req, socket, head, emitConnection);
3326
+ }
3327
+ });
3328
+ }
3329
+ if (options.perMessageDeflate === true) options.perMessageDeflate = {};
3330
+ if (options.clientTracking) {
3331
+ this.clients = /* @__PURE__ */ new Set();
3332
+ this._shouldEmitClose = false;
3333
+ }
3334
+ this.options = options;
3335
+ this._state = RUNNING;
3336
+ }
3337
+ /**
3338
+ * Returns the bound address, the address family name, and port of the server
3339
+ * as reported by the operating system if listening on an IP socket.
3340
+ * If the server is listening on a pipe or UNIX domain socket, the name is
3341
+ * returned as a string.
3342
+ *
3343
+ * @return {(Object|String|null)} The address of the server
3344
+ * @public
3345
+ */
3346
+ address() {
3347
+ if (this.options.noServer) {
3348
+ throw new Error('The server is operating in "noServer" mode');
3349
+ }
3350
+ if (!this._server) return null;
3351
+ return this._server.address();
3352
+ }
3353
+ /**
3354
+ * Stop the server from accepting new connections and emit the `'close'` event
3355
+ * when all existing connections are closed.
3356
+ *
3357
+ * @param {Function} [cb] A one-time listener for the `'close'` event
3358
+ * @public
3359
+ */
3360
+ close(cb) {
3361
+ if (this._state === CLOSED) {
3362
+ if (cb) {
3363
+ this.once("close", () => {
3364
+ cb(new Error("The server is not running"));
3365
+ });
3366
+ }
3367
+ process.nextTick(emitClose, this);
3368
+ return;
3369
+ }
3370
+ if (cb) this.once("close", cb);
3371
+ if (this._state === CLOSING) return;
3372
+ this._state = CLOSING;
3373
+ if (this.options.noServer || this.options.server) {
3374
+ if (this._server) {
3375
+ this._removeListeners();
3376
+ this._removeListeners = this._server = null;
3377
+ }
3378
+ if (this.clients) {
3379
+ if (!this.clients.size) {
3380
+ process.nextTick(emitClose, this);
3381
+ } else {
3382
+ this._shouldEmitClose = true;
3383
+ }
3384
+ } else {
3385
+ process.nextTick(emitClose, this);
3386
+ }
3387
+ } else {
3388
+ const server = this._server;
3389
+ this._removeListeners();
3390
+ this._removeListeners = this._server = null;
3391
+ server.close(() => {
3392
+ emitClose(this);
3393
+ });
3394
+ }
3395
+ }
3396
+ /**
3397
+ * See if a given request should be handled by this server instance.
3398
+ *
3399
+ * @param {http.IncomingMessage} req Request object to inspect
3400
+ * @return {Boolean} `true` if the request is valid, else `false`
3401
+ * @public
3402
+ */
3403
+ shouldHandle(req) {
3404
+ if (this.options.path) {
3405
+ const index = req.url.indexOf("?");
3406
+ const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3407
+ if (pathname !== this.options.path) return false;
3408
+ }
3409
+ return true;
3410
+ }
3411
+ /**
3412
+ * Handle a HTTP Upgrade request.
3413
+ *
3414
+ * @param {http.IncomingMessage} req The request object
3415
+ * @param {Duplex} socket The network socket between the server and client
3416
+ * @param {Buffer} head The first packet of the upgraded stream
3417
+ * @param {Function} cb Callback
3418
+ * @public
3419
+ */
3420
+ handleUpgrade(req, socket, head, cb) {
3421
+ socket.on("error", socketOnError);
3422
+ const key = req.headers["sec-websocket-key"];
3423
+ const upgrade = req.headers.upgrade;
3424
+ const version = +req.headers["sec-websocket-version"];
3425
+ if (req.method !== "GET") {
3426
+ const message = "Invalid HTTP method";
3427
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3428
+ return;
3429
+ }
3430
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3431
+ const message = "Invalid Upgrade header";
3432
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3433
+ return;
3434
+ }
3435
+ if (key === void 0 || !keyRegex.test(key)) {
3436
+ const message = "Missing or invalid Sec-WebSocket-Key header";
3437
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3438
+ return;
3439
+ }
3440
+ if (version !== 13 && version !== 8) {
3441
+ const message = "Missing or invalid Sec-WebSocket-Version header";
3442
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
3443
+ "Sec-WebSocket-Version": "13, 8"
3444
+ });
3445
+ return;
3446
+ }
3447
+ if (!this.shouldHandle(req)) {
3448
+ abortHandshake(socket, 400);
3449
+ return;
3450
+ }
3451
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3452
+ let protocols = /* @__PURE__ */ new Set();
3453
+ if (secWebSocketProtocol !== void 0) {
3454
+ try {
3455
+ protocols = subprotocol.parse(secWebSocketProtocol);
3456
+ } catch (err) {
3457
+ const message = "Invalid Sec-WebSocket-Protocol header";
3458
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3459
+ return;
3460
+ }
3461
+ }
3462
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3463
+ const extensions = {};
3464
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3465
+ const perMessageDeflate = new PerMessageDeflate(
3466
+ this.options.perMessageDeflate,
3467
+ true,
3468
+ this.options.maxPayload
3469
+ );
3470
+ try {
3471
+ const offers = extension.parse(secWebSocketExtensions);
3472
+ if (offers[PerMessageDeflate.extensionName]) {
3473
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3474
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3475
+ }
3476
+ } catch (err) {
3477
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3478
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3479
+ return;
3480
+ }
3481
+ }
3482
+ if (this.options.verifyClient) {
3483
+ const info = {
3484
+ origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3485
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3486
+ req
3487
+ };
3488
+ if (this.options.verifyClient.length === 2) {
3489
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3490
+ if (!verified) {
3491
+ return abortHandshake(socket, code || 401, message, headers);
3492
+ }
3493
+ this.completeUpgrade(
3494
+ extensions,
3495
+ key,
3496
+ protocols,
3497
+ req,
3498
+ socket,
3499
+ head,
3500
+ cb
3501
+ );
3502
+ });
3503
+ return;
3504
+ }
3505
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
3506
+ }
3507
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3508
+ }
3509
+ /**
3510
+ * Upgrade the connection to WebSocket.
3511
+ *
3512
+ * @param {Object} extensions The accepted extensions
3513
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
3514
+ * @param {Set} protocols The subprotocols
3515
+ * @param {http.IncomingMessage} req The request object
3516
+ * @param {Duplex} socket The network socket between the server and client
3517
+ * @param {Buffer} head The first packet of the upgraded stream
3518
+ * @param {Function} cb Callback
3519
+ * @throws {Error} If called more than once with the same socket
3520
+ * @private
3521
+ */
3522
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3523
+ if (!socket.readable || !socket.writable) return socket.destroy();
3524
+ if (socket[kWebSocket]) {
3525
+ throw new Error(
3526
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3527
+ );
3528
+ }
3529
+ if (this._state > RUNNING) return abortHandshake(socket, 503);
3530
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3531
+ const headers = [
3532
+ "HTTP/1.1 101 Switching Protocols",
3533
+ "Upgrade: websocket",
3534
+ "Connection: Upgrade",
3535
+ `Sec-WebSocket-Accept: ${digest}`
3536
+ ];
3537
+ const ws = new this.options.WebSocket(null, void 0, this.options);
3538
+ if (protocols.size) {
3539
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3540
+ if (protocol) {
3541
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3542
+ ws._protocol = protocol;
3543
+ }
3544
+ }
3545
+ if (extensions[PerMessageDeflate.extensionName]) {
3546
+ const params = extensions[PerMessageDeflate.extensionName].params;
3547
+ const value = extension.format({
3548
+ [PerMessageDeflate.extensionName]: [params]
3549
+ });
3550
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3551
+ ws._extensions = extensions;
3552
+ }
3553
+ this.emit("headers", headers, req);
3554
+ socket.write(headers.concat("\r\n").join("\r\n"));
3555
+ socket.removeListener("error", socketOnError);
3556
+ ws.setSocket(socket, head, {
3557
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3558
+ maxPayload: this.options.maxPayload,
3559
+ skipUTF8Validation: this.options.skipUTF8Validation
3560
+ });
3561
+ if (this.clients) {
3562
+ this.clients.add(ws);
3563
+ ws.on("close", () => {
3564
+ this.clients.delete(ws);
3565
+ if (this._shouldEmitClose && !this.clients.size) {
3566
+ process.nextTick(emitClose, this);
3567
+ }
3568
+ });
3569
+ }
3570
+ cb(ws, req);
3571
+ }
3572
+ };
3573
+ module.exports = WebSocketServer2;
3574
+ function addListeners(server, map) {
3575
+ for (const event of Object.keys(map)) server.on(event, map[event]);
3576
+ return function removeListeners() {
3577
+ for (const event of Object.keys(map)) {
3578
+ server.removeListener(event, map[event]);
3579
+ }
3580
+ };
3581
+ }
3582
+ function emitClose(server) {
3583
+ server._state = CLOSED;
3584
+ server.emit("close");
3585
+ }
3586
+ function socketOnError() {
3587
+ this.destroy();
3588
+ }
3589
+ function abortHandshake(socket, code, message, headers) {
3590
+ message = message || http.STATUS_CODES[code];
3591
+ headers = {
3592
+ Connection: "close",
3593
+ "Content-Type": "text/html",
3594
+ "Content-Length": Buffer.byteLength(message),
3595
+ ...headers
3596
+ };
3597
+ socket.once("finish", socket.destroy);
3598
+ socket.end(
3599
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3600
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3601
+ );
3602
+ }
3603
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3604
+ if (server.listenerCount("wsClientError")) {
3605
+ const err = new Error(message);
3606
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3607
+ server.emit("wsClientError", err, socket, req);
3608
+ } else {
3609
+ abortHandshake(socket, code, message, headers);
3610
+ }
3611
+ }
3612
+ }
3613
+ });
3614
+
3615
+ // ../../node_modules/ws/wrapper.mjs
3616
+ var import_stream = __toESM(require_stream(), 1);
3617
+ var import_receiver = __toESM(require_receiver(), 1);
3618
+ var import_sender = __toESM(require_sender(), 1);
3619
+ var import_websocket = __toESM(require_websocket(), 1);
3620
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
3621
+ var wrapper_default = import_websocket.default;
3622
+ var export_Receiver = import_receiver.default;
3623
+ var export_Sender = import_sender.default;
3624
+ var export_WebSocket = import_websocket.default;
3625
+ var export_WebSocketServer = import_websocket_server.default;
3626
+ var export_createWebSocketStream = import_stream.default;
3627
+ export {
3628
+ export_Receiver as Receiver,
3629
+ export_Sender as Sender,
3630
+ export_WebSocket as WebSocket,
3631
+ export_WebSocketServer as WebSocketServer,
3632
+ export_createWebSocketStream as createWebSocketStream,
3633
+ wrapper_default as default
3634
+ };
3635
+ //# sourceMappingURL=wrapper-Y3UTVU2E.js.map