zen-code 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2658 @@
1
+ import Qe from "node:events";
2
+ import dt from "node:https";
3
+ import Je from "node:http";
4
+ import _t from "node:net";
5
+ import pt from "node:tls";
6
+ import Oe from "node:crypto";
7
+ import se from "node:stream";
8
+ import mt from "node:url";
9
+ import gt from "node:zlib";
10
+ import { g as et, a as yt } from "./_commonjsHelpers-DQNKXVTB.mjs";
11
+ import Et from "node:buffer";
12
+ import tt from "react-devtools-core";
13
+ var te = { exports: {} }, _e, $e;
14
+ function j() {
15
+ if ($e) return _e;
16
+ $e = 1;
17
+ const P = ["nodebuffer", "arraybuffer", "fragments"], T = typeof Blob < "u";
18
+ return T && P.push("blob"), _e = {
19
+ BINARY_TYPES: P,
20
+ EMPTY_BUFFER: Buffer.alloc(0),
21
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
22
+ hasBlob: T,
23
+ kForOnEventAttribute: /* @__PURE__ */ Symbol("kIsForOnEventAttribute"),
24
+ kListener: /* @__PURE__ */ Symbol("kListener"),
25
+ kStatusCode: /* @__PURE__ */ Symbol("status-code"),
26
+ kWebSocket: /* @__PURE__ */ Symbol("websocket"),
27
+ NOOP: () => {
28
+ }
29
+ }, _e;
30
+ }
31
+ const xt = {}, St = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
32
+ __proto__: null,
33
+ default: xt
34
+ }, Symbol.toStringTag, { value: "Module" })), vt = /* @__PURE__ */ et(St);
35
+ var Fe;
36
+ function oe() {
37
+ if (Fe) return te.exports;
38
+ Fe = 1;
39
+ const { EMPTY_BUFFER: P } = j(), T = Buffer[Symbol.species];
40
+ function M(f, a) {
41
+ if (f.length === 0) return P;
42
+ if (f.length === 1) return f[0];
43
+ const _ = Buffer.allocUnsafe(a);
44
+ let h = 0;
45
+ for (let C = 0; C < f.length; C++) {
46
+ const c = f[C];
47
+ _.set(c, h), h += c.length;
48
+ }
49
+ return h < a ? new T(_.buffer, _.byteOffset, h) : _;
50
+ }
51
+ function B(f, a, _, h, C) {
52
+ for (let c = 0; c < C; c++)
53
+ _[h + c] = f[c] ^ a[c & 3];
54
+ }
55
+ function b(f, a) {
56
+ for (let _ = 0; _ < f.length; _++)
57
+ f[_] ^= a[_ & 3];
58
+ }
59
+ function d(f) {
60
+ return f.length === f.buffer.byteLength ? f.buffer : f.buffer.slice(f.byteOffset, f.byteOffset + f.length);
61
+ }
62
+ function n(f) {
63
+ if (n.readOnly = !0, Buffer.isBuffer(f)) return f;
64
+ let a;
65
+ return f instanceof ArrayBuffer ? a = new T(f) : ArrayBuffer.isView(f) ? a = new T(f.buffer, f.byteOffset, f.byteLength) : (a = Buffer.from(f), n.readOnly = !1), a;
66
+ }
67
+ if (te.exports = {
68
+ concat: M,
69
+ mask: B,
70
+ toArrayBuffer: d,
71
+ toBuffer: n,
72
+ unmask: b
73
+ }, !process.env.WS_NO_BUFFER_UTIL)
74
+ try {
75
+ const f = vt;
76
+ te.exports.mask = function(a, _, h, C, c) {
77
+ c < 48 ? B(a, _, h, C, c) : f.mask(a, _, h, C, c);
78
+ }, te.exports.unmask = function(a, _) {
79
+ a.length < 32 ? b(a, _) : f.unmask(a, _);
80
+ };
81
+ } catch {
82
+ }
83
+ return te.exports;
84
+ }
85
+ var pe, We;
86
+ function bt() {
87
+ if (We) return pe;
88
+ We = 1;
89
+ const P = /* @__PURE__ */ Symbol("kDone"), T = /* @__PURE__ */ Symbol("kRun");
90
+ class M {
91
+ /**
92
+ * Creates a new `Limiter`.
93
+ *
94
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
95
+ * to run concurrently
96
+ */
97
+ constructor(b) {
98
+ this[P] = () => {
99
+ this.pending--, this[T]();
100
+ }, this.concurrency = b || 1 / 0, this.jobs = [], this.pending = 0;
101
+ }
102
+ /**
103
+ * Adds a job to the queue.
104
+ *
105
+ * @param {Function} job The job to run
106
+ * @public
107
+ */
108
+ add(b) {
109
+ this.jobs.push(b), this[T]();
110
+ }
111
+ /**
112
+ * Removes a job from the queue and runs it if possible.
113
+ *
114
+ * @private
115
+ */
116
+ [T]() {
117
+ if (this.pending !== this.concurrency && this.jobs.length) {
118
+ const b = this.jobs.shift();
119
+ this.pending++, b(this[P]);
120
+ }
121
+ }
122
+ }
123
+ return pe = M, pe;
124
+ }
125
+ var me, Ve;
126
+ function ae() {
127
+ if (Ve) return me;
128
+ Ve = 1;
129
+ const P = gt, T = oe(), M = bt(), { kStatusCode: B } = j(), b = Buffer[Symbol.species], d = Buffer.from([0, 0, 255, 255]), n = /* @__PURE__ */ Symbol("permessage-deflate"), f = /* @__PURE__ */ Symbol("total-length"), a = /* @__PURE__ */ Symbol("callback"), _ = /* @__PURE__ */ Symbol("buffers"), h = /* @__PURE__ */ Symbol("error");
130
+ let C;
131
+ class c {
132
+ /**
133
+ * Creates a PerMessageDeflate instance.
134
+ *
135
+ * @param {Object} [options] Configuration options
136
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
137
+ * for, or request, a custom client window size
138
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
139
+ * acknowledge disabling of client context takeover
140
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
141
+ * calls to zlib
142
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
143
+ * use of a custom server window size
144
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
145
+ * disabling of server context takeover
146
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
147
+ * messages should not be compressed if context takeover is disabled
148
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
149
+ * deflate
150
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
151
+ * inflate
152
+ * @param {Boolean} [isServer=false] Create the instance in either server or
153
+ * client mode
154
+ * @param {Number} [maxPayload=0] The maximum allowed message length
155
+ */
156
+ constructor(p, l, E) {
157
+ if (this._maxPayload = E | 0, this._options = p || {}, this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024, this._isServer = !!l, this._deflate = null, this._inflate = null, this.params = null, !C) {
158
+ const u = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
159
+ C = new M(u);
160
+ }
161
+ }
162
+ /**
163
+ * @type {String}
164
+ */
165
+ static get extensionName() {
166
+ return "permessage-deflate";
167
+ }
168
+ /**
169
+ * Create an extension negotiation offer.
170
+ *
171
+ * @return {Object} Extension parameters
172
+ * @public
173
+ */
174
+ offer() {
175
+ const p = {};
176
+ return this._options.serverNoContextTakeover && (p.server_no_context_takeover = !0), this._options.clientNoContextTakeover && (p.client_no_context_takeover = !0), this._options.serverMaxWindowBits && (p.server_max_window_bits = this._options.serverMaxWindowBits), this._options.clientMaxWindowBits ? p.client_max_window_bits = this._options.clientMaxWindowBits : this._options.clientMaxWindowBits == null && (p.client_max_window_bits = !0), p;
177
+ }
178
+ /**
179
+ * Accept an extension negotiation offer/response.
180
+ *
181
+ * @param {Array} configurations The extension negotiation offers/reponse
182
+ * @return {Object} Accepted configuration
183
+ * @public
184
+ */
185
+ accept(p) {
186
+ return p = this.normalizeParams(p), this.params = this._isServer ? this.acceptAsServer(p) : this.acceptAsClient(p), this.params;
187
+ }
188
+ /**
189
+ * Releases all resources used by the extension.
190
+ *
191
+ * @public
192
+ */
193
+ cleanup() {
194
+ if (this._inflate && (this._inflate.close(), this._inflate = null), this._deflate) {
195
+ const p = this._deflate[a];
196
+ this._deflate.close(), this._deflate = null, p && p(
197
+ new Error(
198
+ "The deflate stream was closed while data was being processed"
199
+ )
200
+ );
201
+ }
202
+ }
203
+ /**
204
+ * Accept an extension negotiation offer.
205
+ *
206
+ * @param {Array} offers The extension negotiation offers
207
+ * @return {Object} Accepted configuration
208
+ * @private
209
+ */
210
+ acceptAsServer(p) {
211
+ const l = this._options, E = p.find((u) => !(l.serverNoContextTakeover === !1 && u.server_no_context_takeover || u.server_max_window_bits && (l.serverMaxWindowBits === !1 || typeof l.serverMaxWindowBits == "number" && l.serverMaxWindowBits > u.server_max_window_bits) || typeof l.clientMaxWindowBits == "number" && !u.client_max_window_bits));
212
+ if (!E)
213
+ throw new Error("None of the extension offers can be accepted");
214
+ return l.serverNoContextTakeover && (E.server_no_context_takeover = !0), l.clientNoContextTakeover && (E.client_no_context_takeover = !0), typeof l.serverMaxWindowBits == "number" && (E.server_max_window_bits = l.serverMaxWindowBits), typeof l.clientMaxWindowBits == "number" ? E.client_max_window_bits = l.clientMaxWindowBits : (E.client_max_window_bits === !0 || l.clientMaxWindowBits === !1) && delete E.client_max_window_bits, E;
215
+ }
216
+ /**
217
+ * Accept the extension negotiation response.
218
+ *
219
+ * @param {Array} response The extension negotiation response
220
+ * @return {Object} Accepted configuration
221
+ * @private
222
+ */
223
+ acceptAsClient(p) {
224
+ const l = p[0];
225
+ if (this._options.clientNoContextTakeover === !1 && l.client_no_context_takeover)
226
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
227
+ if (!l.client_max_window_bits)
228
+ typeof this._options.clientMaxWindowBits == "number" && (l.client_max_window_bits = this._options.clientMaxWindowBits);
229
+ else if (this._options.clientMaxWindowBits === !1 || typeof this._options.clientMaxWindowBits == "number" && l.client_max_window_bits > this._options.clientMaxWindowBits)
230
+ throw new Error(
231
+ 'Unexpected or invalid parameter "client_max_window_bits"'
232
+ );
233
+ return l;
234
+ }
235
+ /**
236
+ * Normalize parameters.
237
+ *
238
+ * @param {Array} configurations The extension negotiation offers/reponse
239
+ * @return {Array} The offers/response with normalized parameters
240
+ * @private
241
+ */
242
+ normalizeParams(p) {
243
+ return p.forEach((l) => {
244
+ Object.keys(l).forEach((E) => {
245
+ let u = l[E];
246
+ if (u.length > 1)
247
+ throw new Error(`Parameter "${E}" must have only a single value`);
248
+ if (u = u[0], E === "client_max_window_bits") {
249
+ if (u !== !0) {
250
+ const e = +u;
251
+ if (!Number.isInteger(e) || e < 8 || e > 15)
252
+ throw new TypeError(
253
+ `Invalid value for parameter "${E}": ${u}`
254
+ );
255
+ u = e;
256
+ } else if (!this._isServer)
257
+ throw new TypeError(
258
+ `Invalid value for parameter "${E}": ${u}`
259
+ );
260
+ } else if (E === "server_max_window_bits") {
261
+ const e = +u;
262
+ if (!Number.isInteger(e) || e < 8 || e > 15)
263
+ throw new TypeError(
264
+ `Invalid value for parameter "${E}": ${u}`
265
+ );
266
+ u = e;
267
+ } else if (E === "client_no_context_takeover" || E === "server_no_context_takeover") {
268
+ if (u !== !0)
269
+ throw new TypeError(
270
+ `Invalid value for parameter "${E}": ${u}`
271
+ );
272
+ } else
273
+ throw new Error(`Unknown parameter "${E}"`);
274
+ l[E] = u;
275
+ });
276
+ }), p;
277
+ }
278
+ /**
279
+ * Decompress data. Concurrency limited.
280
+ *
281
+ * @param {Buffer} data Compressed data
282
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
283
+ * @param {Function} callback Callback
284
+ * @public
285
+ */
286
+ decompress(p, l, E) {
287
+ C.add((u) => {
288
+ this._decompress(p, l, (e, t) => {
289
+ u(), E(e, t);
290
+ });
291
+ });
292
+ }
293
+ /**
294
+ * Compress data. Concurrency limited.
295
+ *
296
+ * @param {(Buffer|String)} data Data to compress
297
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
298
+ * @param {Function} callback Callback
299
+ * @public
300
+ */
301
+ compress(p, l, E) {
302
+ C.add((u) => {
303
+ this._compress(p, l, (e, t) => {
304
+ u(), E(e, t);
305
+ });
306
+ });
307
+ }
308
+ /**
309
+ * Decompress data.
310
+ *
311
+ * @param {Buffer} data Compressed data
312
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
313
+ * @param {Function} callback Callback
314
+ * @private
315
+ */
316
+ _decompress(p, l, E) {
317
+ const u = this._isServer ? "client" : "server";
318
+ if (!this._inflate) {
319
+ const e = `${u}_max_window_bits`, t = typeof this.params[e] != "number" ? P.Z_DEFAULT_WINDOWBITS : this.params[e];
320
+ this._inflate = P.createInflateRaw({
321
+ ...this._options.zlibInflateOptions,
322
+ windowBits: t
323
+ }), this._inflate[n] = this, this._inflate[f] = 0, this._inflate[_] = [], this._inflate.on("error", v), this._inflate.on("data", k);
324
+ }
325
+ this._inflate[a] = E, this._inflate.write(p), l && this._inflate.write(d), this._inflate.flush(() => {
326
+ const e = this._inflate[h];
327
+ if (e) {
328
+ this._inflate.close(), this._inflate = null, E(e);
329
+ return;
330
+ }
331
+ const t = T.concat(
332
+ this._inflate[_],
333
+ this._inflate[f]
334
+ );
335
+ this._inflate._readableState.endEmitted ? (this._inflate.close(), this._inflate = null) : (this._inflate[f] = 0, this._inflate[_] = [], l && this.params[`${u}_no_context_takeover`] && this._inflate.reset()), E(null, t);
336
+ });
337
+ }
338
+ /**
339
+ * Compress data.
340
+ *
341
+ * @param {(Buffer|String)} data Data to compress
342
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
343
+ * @param {Function} callback Callback
344
+ * @private
345
+ */
346
+ _compress(p, l, E) {
347
+ const u = this._isServer ? "server" : "client";
348
+ if (!this._deflate) {
349
+ const e = `${u}_max_window_bits`, t = typeof this.params[e] != "number" ? P.Z_DEFAULT_WINDOWBITS : this.params[e];
350
+ this._deflate = P.createDeflateRaw({
351
+ ...this._options.zlibDeflateOptions,
352
+ windowBits: t
353
+ }), this._deflate[f] = 0, this._deflate[_] = [], this._deflate.on("data", w);
354
+ }
355
+ this._deflate[a] = E, this._deflate.write(p), this._deflate.flush(P.Z_SYNC_FLUSH, () => {
356
+ if (!this._deflate)
357
+ return;
358
+ let e = T.concat(
359
+ this._deflate[_],
360
+ this._deflate[f]
361
+ );
362
+ l && (e = new b(e.buffer, e.byteOffset, e.length - 4)), this._deflate[a] = null, this._deflate[f] = 0, this._deflate[_] = [], l && this.params[`${u}_no_context_takeover`] && this._deflate.reset(), E(null, e);
363
+ });
364
+ }
365
+ }
366
+ me = c;
367
+ function w(O) {
368
+ this[_].push(O), this[f] += O.length;
369
+ }
370
+ function k(O) {
371
+ if (this[f] += O.length, this[n]._maxPayload < 1 || this[f] <= this[n]._maxPayload) {
372
+ this[_].push(O);
373
+ return;
374
+ }
375
+ this[h] = new RangeError("Max payload size exceeded"), this[h].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH", this[h][B] = 1009, this.removeListener("data", k), this.reset();
376
+ }
377
+ function v(O) {
378
+ if (this[n]._inflate = null, this[h]) {
379
+ this[a](this[h]);
380
+ return;
381
+ }
382
+ O[B] = 1007, this[a](O);
383
+ }
384
+ return me;
385
+ }
386
+ var re = { exports: {} };
387
+ const wt = {}, Ot = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
388
+ __proto__: null,
389
+ default: wt
390
+ }, Symbol.toStringTag, { value: "Module" })), Tt = /* @__PURE__ */ et(Ot);
391
+ var Ge;
392
+ function ie() {
393
+ if (Ge) return re.exports;
394
+ Ge = 1;
395
+ const { isUtf8: P } = Et, { hasBlob: T } = j(), M = [
396
+ 0,
397
+ 0,
398
+ 0,
399
+ 0,
400
+ 0,
401
+ 0,
402
+ 0,
403
+ 0,
404
+ 0,
405
+ 0,
406
+ 0,
407
+ 0,
408
+ 0,
409
+ 0,
410
+ 0,
411
+ 0,
412
+ // 0 - 15
413
+ 0,
414
+ 0,
415
+ 0,
416
+ 0,
417
+ 0,
418
+ 0,
419
+ 0,
420
+ 0,
421
+ 0,
422
+ 0,
423
+ 0,
424
+ 0,
425
+ 0,
426
+ 0,
427
+ 0,
428
+ 0,
429
+ // 16 - 31
430
+ 0,
431
+ 1,
432
+ 0,
433
+ 1,
434
+ 1,
435
+ 1,
436
+ 1,
437
+ 1,
438
+ 0,
439
+ 0,
440
+ 1,
441
+ 1,
442
+ 0,
443
+ 1,
444
+ 1,
445
+ 0,
446
+ // 32 - 47
447
+ 1,
448
+ 1,
449
+ 1,
450
+ 1,
451
+ 1,
452
+ 1,
453
+ 1,
454
+ 1,
455
+ 1,
456
+ 1,
457
+ 0,
458
+ 0,
459
+ 0,
460
+ 0,
461
+ 0,
462
+ 0,
463
+ // 48 - 63
464
+ 0,
465
+ 1,
466
+ 1,
467
+ 1,
468
+ 1,
469
+ 1,
470
+ 1,
471
+ 1,
472
+ 1,
473
+ 1,
474
+ 1,
475
+ 1,
476
+ 1,
477
+ 1,
478
+ 1,
479
+ 1,
480
+ // 64 - 79
481
+ 1,
482
+ 1,
483
+ 1,
484
+ 1,
485
+ 1,
486
+ 1,
487
+ 1,
488
+ 1,
489
+ 1,
490
+ 1,
491
+ 1,
492
+ 0,
493
+ 0,
494
+ 0,
495
+ 1,
496
+ 1,
497
+ // 80 - 95
498
+ 1,
499
+ 1,
500
+ 1,
501
+ 1,
502
+ 1,
503
+ 1,
504
+ 1,
505
+ 1,
506
+ 1,
507
+ 1,
508
+ 1,
509
+ 1,
510
+ 1,
511
+ 1,
512
+ 1,
513
+ 1,
514
+ // 96 - 111
515
+ 1,
516
+ 1,
517
+ 1,
518
+ 1,
519
+ 1,
520
+ 1,
521
+ 1,
522
+ 1,
523
+ 1,
524
+ 1,
525
+ 1,
526
+ 0,
527
+ 1,
528
+ 0,
529
+ 1,
530
+ 0
531
+ // 112 - 127
532
+ ];
533
+ function B(n) {
534
+ return n >= 1e3 && n <= 1014 && n !== 1004 && n !== 1005 && n !== 1006 || n >= 3e3 && n <= 4999;
535
+ }
536
+ function b(n) {
537
+ const f = n.length;
538
+ let a = 0;
539
+ for (; a < f; )
540
+ if ((n[a] & 128) === 0)
541
+ a++;
542
+ else if ((n[a] & 224) === 192) {
543
+ if (a + 1 === f || (n[a + 1] & 192) !== 128 || (n[a] & 254) === 192)
544
+ return !1;
545
+ a += 2;
546
+ } else if ((n[a] & 240) === 224) {
547
+ if (a + 2 >= f || (n[a + 1] & 192) !== 128 || (n[a + 2] & 192) !== 128 || n[a] === 224 && (n[a + 1] & 224) === 128 || // Overlong
548
+ n[a] === 237 && (n[a + 1] & 224) === 160)
549
+ return !1;
550
+ a += 3;
551
+ } else if ((n[a] & 248) === 240) {
552
+ if (a + 3 >= f || (n[a + 1] & 192) !== 128 || (n[a + 2] & 192) !== 128 || (n[a + 3] & 192) !== 128 || n[a] === 240 && (n[a + 1] & 240) === 128 || // Overlong
553
+ n[a] === 244 && n[a + 1] > 143 || n[a] > 244)
554
+ return !1;
555
+ a += 4;
556
+ } else
557
+ return !1;
558
+ return !0;
559
+ }
560
+ function d(n) {
561
+ return T && typeof n == "object" && typeof n.arrayBuffer == "function" && typeof n.type == "string" && typeof n.stream == "function" && (n[Symbol.toStringTag] === "Blob" || n[Symbol.toStringTag] === "File");
562
+ }
563
+ if (re.exports = {
564
+ isBlob: d,
565
+ isValidStatusCode: B,
566
+ isValidUTF8: b,
567
+ tokenChars: M
568
+ }, P)
569
+ re.exports.isValidUTF8 = function(n) {
570
+ return n.length < 24 ? b(n) : P(n);
571
+ };
572
+ else if (!process.env.WS_NO_UTF_8_VALIDATE)
573
+ try {
574
+ const n = Tt;
575
+ re.exports.isValidUTF8 = function(f) {
576
+ return f.length < 32 ? b(f) : n(f);
577
+ };
578
+ } catch {
579
+ }
580
+ return re.exports;
581
+ }
582
+ var ge, je;
583
+ function rt() {
584
+ if (je) return ge;
585
+ je = 1;
586
+ const { Writable: P } = se, T = ae(), {
587
+ BINARY_TYPES: M,
588
+ EMPTY_BUFFER: B,
589
+ kStatusCode: b,
590
+ kWebSocket: d
591
+ } = j(), { concat: n, toArrayBuffer: f, unmask: a } = oe(), { isValidStatusCode: _, isValidUTF8: h } = ie(), C = Buffer[Symbol.species], c = 0, w = 1, k = 2, v = 3, O = 4, p = 5, l = 6;
592
+ class E extends P {
593
+ /**
594
+ * Creates a Receiver instance.
595
+ *
596
+ * @param {Object} [options] Options object
597
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
598
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
599
+ * multiple times in the same tick
600
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
601
+ * @param {Object} [options.extensions] An object containing the negotiated
602
+ * extensions
603
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
604
+ * client or server mode
605
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
606
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
607
+ * not to skip UTF-8 validation for text and close messages
608
+ */
609
+ constructor(e = {}) {
610
+ super(), this._allowSynchronousEvents = e.allowSynchronousEvents !== void 0 ? e.allowSynchronousEvents : !0, this._binaryType = e.binaryType || M[0], this._extensions = e.extensions || {}, this._isServer = !!e.isServer, this._maxPayload = e.maxPayload | 0, this._skipUTF8Validation = !!e.skipUTF8Validation, this[d] = void 0, this._bufferedBytes = 0, this._buffers = [], this._compressed = !1, this._payloadLength = 0, this._mask = void 0, this._fragmented = 0, this._masked = !1, this._fin = !1, this._opcode = 0, this._totalPayloadLength = 0, this._messageLength = 0, this._fragments = [], this._errored = !1, this._loop = !1, this._state = c;
611
+ }
612
+ /**
613
+ * Implements `Writable.prototype._write()`.
614
+ *
615
+ * @param {Buffer} chunk The chunk of data to write
616
+ * @param {String} encoding The character encoding of `chunk`
617
+ * @param {Function} cb Callback
618
+ * @private
619
+ */
620
+ _write(e, t, i) {
621
+ if (this._opcode === 8 && this._state == c) return i();
622
+ this._bufferedBytes += e.length, this._buffers.push(e), this.startLoop(i);
623
+ }
624
+ /**
625
+ * Consumes `n` bytes from the buffered data.
626
+ *
627
+ * @param {Number} n The number of bytes to consume
628
+ * @return {Buffer} The consumed bytes
629
+ * @private
630
+ */
631
+ consume(e) {
632
+ if (this._bufferedBytes -= e, e === this._buffers[0].length) return this._buffers.shift();
633
+ if (e < this._buffers[0].length) {
634
+ const i = this._buffers[0];
635
+ return this._buffers[0] = new C(
636
+ i.buffer,
637
+ i.byteOffset + e,
638
+ i.length - e
639
+ ), new C(i.buffer, i.byteOffset, e);
640
+ }
641
+ const t = Buffer.allocUnsafe(e);
642
+ do {
643
+ const i = this._buffers[0], s = t.length - e;
644
+ e >= i.length ? t.set(this._buffers.shift(), s) : (t.set(new Uint8Array(i.buffer, i.byteOffset, e), s), this._buffers[0] = new C(
645
+ i.buffer,
646
+ i.byteOffset + e,
647
+ i.length - e
648
+ )), e -= i.length;
649
+ } while (e > 0);
650
+ return t;
651
+ }
652
+ /**
653
+ * Starts the parsing loop.
654
+ *
655
+ * @param {Function} cb Callback
656
+ * @private
657
+ */
658
+ startLoop(e) {
659
+ this._loop = !0;
660
+ do
661
+ switch (this._state) {
662
+ case c:
663
+ this.getInfo(e);
664
+ break;
665
+ case w:
666
+ this.getPayloadLength16(e);
667
+ break;
668
+ case k:
669
+ this.getPayloadLength64(e);
670
+ break;
671
+ case v:
672
+ this.getMask();
673
+ break;
674
+ case O:
675
+ this.getData(e);
676
+ break;
677
+ case p:
678
+ case l:
679
+ this._loop = !1;
680
+ return;
681
+ }
682
+ while (this._loop);
683
+ this._errored || e();
684
+ }
685
+ /**
686
+ * Reads the first two bytes of a frame.
687
+ *
688
+ * @param {Function} cb Callback
689
+ * @private
690
+ */
691
+ getInfo(e) {
692
+ if (this._bufferedBytes < 2) {
693
+ this._loop = !1;
694
+ return;
695
+ }
696
+ const t = this.consume(2);
697
+ if ((t[0] & 48) !== 0) {
698
+ const s = this.createError(
699
+ RangeError,
700
+ "RSV2 and RSV3 must be clear",
701
+ !0,
702
+ 1002,
703
+ "WS_ERR_UNEXPECTED_RSV_2_3"
704
+ );
705
+ e(s);
706
+ return;
707
+ }
708
+ const i = (t[0] & 64) === 64;
709
+ if (i && !this._extensions[T.extensionName]) {
710
+ const s = this.createError(
711
+ RangeError,
712
+ "RSV1 must be clear",
713
+ !0,
714
+ 1002,
715
+ "WS_ERR_UNEXPECTED_RSV_1"
716
+ );
717
+ e(s);
718
+ return;
719
+ }
720
+ if (this._fin = (t[0] & 128) === 128, this._opcode = t[0] & 15, this._payloadLength = t[1] & 127, this._opcode === 0) {
721
+ if (i) {
722
+ const s = this.createError(
723
+ RangeError,
724
+ "RSV1 must be clear",
725
+ !0,
726
+ 1002,
727
+ "WS_ERR_UNEXPECTED_RSV_1"
728
+ );
729
+ e(s);
730
+ return;
731
+ }
732
+ if (!this._fragmented) {
733
+ const s = this.createError(
734
+ RangeError,
735
+ "invalid opcode 0",
736
+ !0,
737
+ 1002,
738
+ "WS_ERR_INVALID_OPCODE"
739
+ );
740
+ e(s);
741
+ return;
742
+ }
743
+ this._opcode = this._fragmented;
744
+ } else if (this._opcode === 1 || this._opcode === 2) {
745
+ if (this._fragmented) {
746
+ const s = this.createError(
747
+ RangeError,
748
+ `invalid opcode ${this._opcode}`,
749
+ !0,
750
+ 1002,
751
+ "WS_ERR_INVALID_OPCODE"
752
+ );
753
+ e(s);
754
+ return;
755
+ }
756
+ this._compressed = i;
757
+ } else if (this._opcode > 7 && this._opcode < 11) {
758
+ if (!this._fin) {
759
+ const s = this.createError(
760
+ RangeError,
761
+ "FIN must be set",
762
+ !0,
763
+ 1002,
764
+ "WS_ERR_EXPECTED_FIN"
765
+ );
766
+ e(s);
767
+ return;
768
+ }
769
+ if (i) {
770
+ const s = this.createError(
771
+ RangeError,
772
+ "RSV1 must be clear",
773
+ !0,
774
+ 1002,
775
+ "WS_ERR_UNEXPECTED_RSV_1"
776
+ );
777
+ e(s);
778
+ return;
779
+ }
780
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
781
+ const s = this.createError(
782
+ RangeError,
783
+ `invalid payload length ${this._payloadLength}`,
784
+ !0,
785
+ 1002,
786
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
787
+ );
788
+ e(s);
789
+ return;
790
+ }
791
+ } else {
792
+ const s = this.createError(
793
+ RangeError,
794
+ `invalid opcode ${this._opcode}`,
795
+ !0,
796
+ 1002,
797
+ "WS_ERR_INVALID_OPCODE"
798
+ );
799
+ e(s);
800
+ return;
801
+ }
802
+ if (!this._fin && !this._fragmented && (this._fragmented = this._opcode), this._masked = (t[1] & 128) === 128, this._isServer) {
803
+ if (!this._masked) {
804
+ const s = this.createError(
805
+ RangeError,
806
+ "MASK must be set",
807
+ !0,
808
+ 1002,
809
+ "WS_ERR_EXPECTED_MASK"
810
+ );
811
+ e(s);
812
+ return;
813
+ }
814
+ } else if (this._masked) {
815
+ const s = this.createError(
816
+ RangeError,
817
+ "MASK must be clear",
818
+ !0,
819
+ 1002,
820
+ "WS_ERR_UNEXPECTED_MASK"
821
+ );
822
+ e(s);
823
+ return;
824
+ }
825
+ this._payloadLength === 126 ? this._state = w : this._payloadLength === 127 ? this._state = k : this.haveLength(e);
826
+ }
827
+ /**
828
+ * Gets extended payload length (7+16).
829
+ *
830
+ * @param {Function} cb Callback
831
+ * @private
832
+ */
833
+ getPayloadLength16(e) {
834
+ if (this._bufferedBytes < 2) {
835
+ this._loop = !1;
836
+ return;
837
+ }
838
+ this._payloadLength = this.consume(2).readUInt16BE(0), this.haveLength(e);
839
+ }
840
+ /**
841
+ * Gets extended payload length (7+64).
842
+ *
843
+ * @param {Function} cb Callback
844
+ * @private
845
+ */
846
+ getPayloadLength64(e) {
847
+ if (this._bufferedBytes < 8) {
848
+ this._loop = !1;
849
+ return;
850
+ }
851
+ const t = this.consume(8), i = t.readUInt32BE(0);
852
+ if (i > Math.pow(2, 21) - 1) {
853
+ const s = this.createError(
854
+ RangeError,
855
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
856
+ !1,
857
+ 1009,
858
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
859
+ );
860
+ e(s);
861
+ return;
862
+ }
863
+ this._payloadLength = i * Math.pow(2, 32) + t.readUInt32BE(4), this.haveLength(e);
864
+ }
865
+ /**
866
+ * Payload length has been read.
867
+ *
868
+ * @param {Function} cb Callback
869
+ * @private
870
+ */
871
+ haveLength(e) {
872
+ if (this._payloadLength && this._opcode < 8 && (this._totalPayloadLength += this._payloadLength, this._totalPayloadLength > this._maxPayload && this._maxPayload > 0)) {
873
+ const t = this.createError(
874
+ RangeError,
875
+ "Max payload size exceeded",
876
+ !1,
877
+ 1009,
878
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
879
+ );
880
+ e(t);
881
+ return;
882
+ }
883
+ this._masked ? this._state = v : this._state = O;
884
+ }
885
+ /**
886
+ * Reads mask bytes.
887
+ *
888
+ * @private
889
+ */
890
+ getMask() {
891
+ if (this._bufferedBytes < 4) {
892
+ this._loop = !1;
893
+ return;
894
+ }
895
+ this._mask = this.consume(4), this._state = O;
896
+ }
897
+ /**
898
+ * Reads data bytes.
899
+ *
900
+ * @param {Function} cb Callback
901
+ * @private
902
+ */
903
+ getData(e) {
904
+ let t = B;
905
+ if (this._payloadLength) {
906
+ if (this._bufferedBytes < this._payloadLength) {
907
+ this._loop = !1;
908
+ return;
909
+ }
910
+ t = this.consume(this._payloadLength), this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0 && a(t, this._mask);
911
+ }
912
+ if (this._opcode > 7) {
913
+ this.controlMessage(t, e);
914
+ return;
915
+ }
916
+ if (this._compressed) {
917
+ this._state = p, this.decompress(t, e);
918
+ return;
919
+ }
920
+ t.length && (this._messageLength = this._totalPayloadLength, this._fragments.push(t)), this.dataMessage(e);
921
+ }
922
+ /**
923
+ * Decompresses data.
924
+ *
925
+ * @param {Buffer} data Compressed data
926
+ * @param {Function} cb Callback
927
+ * @private
928
+ */
929
+ decompress(e, t) {
930
+ this._extensions[T.extensionName].decompress(e, this._fin, (s, m) => {
931
+ if (s) return t(s);
932
+ if (m.length) {
933
+ if (this._messageLength += m.length, this._messageLength > this._maxPayload && this._maxPayload > 0) {
934
+ const y = this.createError(
935
+ RangeError,
936
+ "Max payload size exceeded",
937
+ !1,
938
+ 1009,
939
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
940
+ );
941
+ t(y);
942
+ return;
943
+ }
944
+ this._fragments.push(m);
945
+ }
946
+ this.dataMessage(t), this._state === c && this.startLoop(t);
947
+ });
948
+ }
949
+ /**
950
+ * Handles a data message.
951
+ *
952
+ * @param {Function} cb Callback
953
+ * @private
954
+ */
955
+ dataMessage(e) {
956
+ if (!this._fin) {
957
+ this._state = c;
958
+ return;
959
+ }
960
+ const t = this._messageLength, i = this._fragments;
961
+ if (this._totalPayloadLength = 0, this._messageLength = 0, this._fragmented = 0, this._fragments = [], this._opcode === 2) {
962
+ let s;
963
+ this._binaryType === "nodebuffer" ? s = n(i, t) : this._binaryType === "arraybuffer" ? s = f(n(i, t)) : this._binaryType === "blob" ? s = new Blob(i) : s = i, this._allowSynchronousEvents ? (this.emit("message", s, !0), this._state = c) : (this._state = l, setImmediate(() => {
964
+ this.emit("message", s, !0), this._state = c, this.startLoop(e);
965
+ }));
966
+ } else {
967
+ const s = n(i, t);
968
+ if (!this._skipUTF8Validation && !h(s)) {
969
+ const m = this.createError(
970
+ Error,
971
+ "invalid UTF-8 sequence",
972
+ !0,
973
+ 1007,
974
+ "WS_ERR_INVALID_UTF8"
975
+ );
976
+ e(m);
977
+ return;
978
+ }
979
+ this._state === p || this._allowSynchronousEvents ? (this.emit("message", s, !1), this._state = c) : (this._state = l, setImmediate(() => {
980
+ this.emit("message", s, !1), this._state = c, this.startLoop(e);
981
+ }));
982
+ }
983
+ }
984
+ /**
985
+ * Handles a control message.
986
+ *
987
+ * @param {Buffer} data Data to handle
988
+ * @return {(Error|RangeError|undefined)} A possible error
989
+ * @private
990
+ */
991
+ controlMessage(e, t) {
992
+ if (this._opcode === 8) {
993
+ if (e.length === 0)
994
+ this._loop = !1, this.emit("conclude", 1005, B), this.end();
995
+ else {
996
+ const i = e.readUInt16BE(0);
997
+ if (!_(i)) {
998
+ const m = this.createError(
999
+ RangeError,
1000
+ `invalid status code ${i}`,
1001
+ !0,
1002
+ 1002,
1003
+ "WS_ERR_INVALID_CLOSE_CODE"
1004
+ );
1005
+ t(m);
1006
+ return;
1007
+ }
1008
+ const s = new C(
1009
+ e.buffer,
1010
+ e.byteOffset + 2,
1011
+ e.length - 2
1012
+ );
1013
+ if (!this._skipUTF8Validation && !h(s)) {
1014
+ const m = this.createError(
1015
+ Error,
1016
+ "invalid UTF-8 sequence",
1017
+ !0,
1018
+ 1007,
1019
+ "WS_ERR_INVALID_UTF8"
1020
+ );
1021
+ t(m);
1022
+ return;
1023
+ }
1024
+ this._loop = !1, this.emit("conclude", i, s), this.end();
1025
+ }
1026
+ this._state = c;
1027
+ return;
1028
+ }
1029
+ this._allowSynchronousEvents ? (this.emit(this._opcode === 9 ? "ping" : "pong", e), this._state = c) : (this._state = l, setImmediate(() => {
1030
+ this.emit(this._opcode === 9 ? "ping" : "pong", e), this._state = c, this.startLoop(t);
1031
+ }));
1032
+ }
1033
+ /**
1034
+ * Builds an error object.
1035
+ *
1036
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1037
+ * @param {String} message The error message
1038
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1039
+ * `message`
1040
+ * @param {Number} statusCode The status code
1041
+ * @param {String} errorCode The exposed error code
1042
+ * @return {(Error|RangeError)} The error
1043
+ * @private
1044
+ */
1045
+ createError(e, t, i, s, m) {
1046
+ this._loop = !1, this._errored = !0;
1047
+ const y = new e(
1048
+ i ? `Invalid WebSocket frame: ${t}` : t
1049
+ );
1050
+ return Error.captureStackTrace(y, this.createError), y.code = m, y[b] = s, y;
1051
+ }
1052
+ }
1053
+ return ge = E, ge;
1054
+ }
1055
+ var ye, qe;
1056
+ function st() {
1057
+ if (qe) return ye;
1058
+ qe = 1;
1059
+ const { Duplex: P } = se, { randomFillSync: T } = Oe, M = ae(), { EMPTY_BUFFER: B, kWebSocket: b, NOOP: d } = j(), { isBlob: n, isValidStatusCode: f } = ie(), { mask: a, toBuffer: _ } = oe(), h = /* @__PURE__ */ Symbol("kByteLength"), C = Buffer.alloc(4), c = 8 * 1024;
1060
+ let w, k = c;
1061
+ const v = 0, O = 1, p = 2;
1062
+ class l {
1063
+ /**
1064
+ * Creates a Sender instance.
1065
+ *
1066
+ * @param {Duplex} socket The connection socket
1067
+ * @param {Object} [extensions] An object containing the negotiated extensions
1068
+ * @param {Function} [generateMask] The function used to generate the masking
1069
+ * key
1070
+ */
1071
+ constructor(t, i, s) {
1072
+ this._extensions = i || {}, s && (this._generateMask = s, this._maskBuffer = Buffer.alloc(4)), this._socket = t, this._firstFragment = !0, this._compress = !1, this._bufferedBytes = 0, this._queue = [], this._state = v, this.onerror = d, this[b] = void 0;
1073
+ }
1074
+ /**
1075
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1076
+ *
1077
+ * @param {(Buffer|String)} data The data to frame
1078
+ * @param {Object} options Options object
1079
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1080
+ * FIN bit
1081
+ * @param {Function} [options.generateMask] The function used to generate the
1082
+ * masking key
1083
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1084
+ * `data`
1085
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1086
+ * key
1087
+ * @param {Number} options.opcode The opcode
1088
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1089
+ * modified
1090
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1091
+ * RSV1 bit
1092
+ * @return {(Buffer|String)[]} The framed data
1093
+ * @public
1094
+ */
1095
+ static frame(t, i) {
1096
+ let s, m = !1, y = 2, R = !1;
1097
+ i.mask && (s = i.maskBuffer || C, i.generateMask ? i.generateMask(s) : (k === c && (w === void 0 && (w = Buffer.alloc(c)), T(w, 0, c), k = 0), s[0] = w[k++], s[1] = w[k++], s[2] = w[k++], s[3] = w[k++]), R = (s[0] | s[1] | s[2] | s[3]) === 0, y = 6);
1098
+ let D;
1099
+ typeof t == "string" ? (!i.mask || R) && i[h] !== void 0 ? D = i[h] : (t = Buffer.from(t), D = t.length) : (D = t.length, m = i.mask && i.readOnly && !R);
1100
+ let A = D;
1101
+ D >= 65536 ? (y += 8, A = 127) : D > 125 && (y += 2, A = 126);
1102
+ const N = Buffer.allocUnsafe(m ? D + y : y);
1103
+ return N[0] = i.fin ? i.opcode | 128 : i.opcode, i.rsv1 && (N[0] |= 64), N[1] = A, A === 126 ? N.writeUInt16BE(D, 2) : A === 127 && (N[2] = N[3] = 0, N.writeUIntBE(D, 4, 6)), i.mask ? (N[1] |= 128, N[y - 4] = s[0], N[y - 3] = s[1], N[y - 2] = s[2], N[y - 1] = s[3], R ? [N, t] : m ? (a(t, s, N, y, D), [N]) : (a(t, s, t, 0, D), [N, t])) : [N, t];
1104
+ }
1105
+ /**
1106
+ * Sends a close message to the other peer.
1107
+ *
1108
+ * @param {Number} [code] The status code component of the body
1109
+ * @param {(String|Buffer)} [data] The message component of the body
1110
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1111
+ * @param {Function} [cb] Callback
1112
+ * @public
1113
+ */
1114
+ close(t, i, s, m) {
1115
+ let y;
1116
+ if (t === void 0)
1117
+ y = B;
1118
+ else {
1119
+ if (typeof t != "number" || !f(t))
1120
+ throw new TypeError("First argument must be a valid error code number");
1121
+ if (i === void 0 || !i.length)
1122
+ y = Buffer.allocUnsafe(2), y.writeUInt16BE(t, 0);
1123
+ else {
1124
+ const D = Buffer.byteLength(i);
1125
+ if (D > 123)
1126
+ throw new RangeError("The message must not be greater than 123 bytes");
1127
+ y = Buffer.allocUnsafe(2 + D), y.writeUInt16BE(t, 0), typeof i == "string" ? y.write(i, 2) : y.set(i, 2);
1128
+ }
1129
+ }
1130
+ const R = {
1131
+ [h]: y.length,
1132
+ fin: !0,
1133
+ generateMask: this._generateMask,
1134
+ mask: s,
1135
+ maskBuffer: this._maskBuffer,
1136
+ opcode: 8,
1137
+ readOnly: !1,
1138
+ rsv1: !1
1139
+ };
1140
+ this._state !== v ? this.enqueue([this.dispatch, y, !1, R, m]) : this.sendFrame(l.frame(y, R), m);
1141
+ }
1142
+ /**
1143
+ * Sends a ping message to the other peer.
1144
+ *
1145
+ * @param {*} data The message to send
1146
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1147
+ * @param {Function} [cb] Callback
1148
+ * @public
1149
+ */
1150
+ ping(t, i, s) {
1151
+ let m, y;
1152
+ if (typeof t == "string" ? (m = Buffer.byteLength(t), y = !1) : n(t) ? (m = t.size, y = !1) : (t = _(t), m = t.length, y = _.readOnly), m > 125)
1153
+ throw new RangeError("The data size must not be greater than 125 bytes");
1154
+ const R = {
1155
+ [h]: m,
1156
+ fin: !0,
1157
+ generateMask: this._generateMask,
1158
+ mask: i,
1159
+ maskBuffer: this._maskBuffer,
1160
+ opcode: 9,
1161
+ readOnly: y,
1162
+ rsv1: !1
1163
+ };
1164
+ n(t) ? this._state !== v ? this.enqueue([this.getBlobData, t, !1, R, s]) : this.getBlobData(t, !1, R, s) : this._state !== v ? this.enqueue([this.dispatch, t, !1, R, s]) : this.sendFrame(l.frame(t, R), s);
1165
+ }
1166
+ /**
1167
+ * Sends a pong message to the other peer.
1168
+ *
1169
+ * @param {*} data The message to send
1170
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1171
+ * @param {Function} [cb] Callback
1172
+ * @public
1173
+ */
1174
+ pong(t, i, s) {
1175
+ let m, y;
1176
+ if (typeof t == "string" ? (m = Buffer.byteLength(t), y = !1) : n(t) ? (m = t.size, y = !1) : (t = _(t), m = t.length, y = _.readOnly), m > 125)
1177
+ throw new RangeError("The data size must not be greater than 125 bytes");
1178
+ const R = {
1179
+ [h]: m,
1180
+ fin: !0,
1181
+ generateMask: this._generateMask,
1182
+ mask: i,
1183
+ maskBuffer: this._maskBuffer,
1184
+ opcode: 10,
1185
+ readOnly: y,
1186
+ rsv1: !1
1187
+ };
1188
+ n(t) ? this._state !== v ? this.enqueue([this.getBlobData, t, !1, R, s]) : this.getBlobData(t, !1, R, s) : this._state !== v ? this.enqueue([this.dispatch, t, !1, R, s]) : this.sendFrame(l.frame(t, R), s);
1189
+ }
1190
+ /**
1191
+ * Sends a data message to the other peer.
1192
+ *
1193
+ * @param {*} data The message to send
1194
+ * @param {Object} options Options object
1195
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1196
+ * or text
1197
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
1198
+ * compress `data`
1199
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1200
+ * last one
1201
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1202
+ * `data`
1203
+ * @param {Function} [cb] Callback
1204
+ * @public
1205
+ */
1206
+ send(t, i, s) {
1207
+ const m = this._extensions[M.extensionName];
1208
+ let y = i.binary ? 2 : 1, R = i.compress, D, A;
1209
+ typeof t == "string" ? (D = Buffer.byteLength(t), A = !1) : n(t) ? (D = t.size, A = !1) : (t = _(t), D = t.length, A = _.readOnly), this._firstFragment ? (this._firstFragment = !1, R && m && m.params[m._isServer ? "server_no_context_takeover" : "client_no_context_takeover"] && (R = D >= m._threshold), this._compress = R) : (R = !1, y = 0), i.fin && (this._firstFragment = !0);
1210
+ const N = {
1211
+ [h]: D,
1212
+ fin: i.fin,
1213
+ generateMask: this._generateMask,
1214
+ mask: i.mask,
1215
+ maskBuffer: this._maskBuffer,
1216
+ opcode: y,
1217
+ readOnly: A,
1218
+ rsv1: R
1219
+ };
1220
+ n(t) ? this._state !== v ? this.enqueue([this.getBlobData, t, this._compress, N, s]) : this.getBlobData(t, this._compress, N, s) : this._state !== v ? this.enqueue([this.dispatch, t, this._compress, N, s]) : this.dispatch(t, this._compress, N, s);
1221
+ }
1222
+ /**
1223
+ * Gets the contents of a blob as binary data.
1224
+ *
1225
+ * @param {Blob} blob The blob
1226
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1227
+ * the data
1228
+ * @param {Object} options Options object
1229
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1230
+ * FIN bit
1231
+ * @param {Function} [options.generateMask] The function used to generate the
1232
+ * masking key
1233
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1234
+ * `data`
1235
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1236
+ * key
1237
+ * @param {Number} options.opcode The opcode
1238
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1239
+ * modified
1240
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1241
+ * RSV1 bit
1242
+ * @param {Function} [cb] Callback
1243
+ * @private
1244
+ */
1245
+ getBlobData(t, i, s, m) {
1246
+ this._bufferedBytes += s[h], this._state = p, t.arrayBuffer().then((y) => {
1247
+ if (this._socket.destroyed) {
1248
+ const D = new Error(
1249
+ "The socket was closed while the blob was being read"
1250
+ );
1251
+ process.nextTick(E, this, D, m);
1252
+ return;
1253
+ }
1254
+ this._bufferedBytes -= s[h];
1255
+ const R = _(y);
1256
+ i ? this.dispatch(R, i, s, m) : (this._state = v, this.sendFrame(l.frame(R, s), m), this.dequeue());
1257
+ }).catch((y) => {
1258
+ process.nextTick(u, this, y, m);
1259
+ });
1260
+ }
1261
+ /**
1262
+ * Dispatches a message.
1263
+ *
1264
+ * @param {(Buffer|String)} data The message to send
1265
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1266
+ * `data`
1267
+ * @param {Object} options Options object
1268
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1269
+ * FIN bit
1270
+ * @param {Function} [options.generateMask] The function used to generate the
1271
+ * masking key
1272
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1273
+ * `data`
1274
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1275
+ * key
1276
+ * @param {Number} options.opcode The opcode
1277
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1278
+ * modified
1279
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1280
+ * RSV1 bit
1281
+ * @param {Function} [cb] Callback
1282
+ * @private
1283
+ */
1284
+ dispatch(t, i, s, m) {
1285
+ if (!i) {
1286
+ this.sendFrame(l.frame(t, s), m);
1287
+ return;
1288
+ }
1289
+ const y = this._extensions[M.extensionName];
1290
+ this._bufferedBytes += s[h], this._state = O, y.compress(t, s.fin, (R, D) => {
1291
+ if (this._socket.destroyed) {
1292
+ const A = new Error(
1293
+ "The socket was closed while data was being compressed"
1294
+ );
1295
+ E(this, A, m);
1296
+ return;
1297
+ }
1298
+ this._bufferedBytes -= s[h], this._state = v, s.readOnly = !1, this.sendFrame(l.frame(D, s), m), this.dequeue();
1299
+ });
1300
+ }
1301
+ /**
1302
+ * Executes queued send operations.
1303
+ *
1304
+ * @private
1305
+ */
1306
+ dequeue() {
1307
+ for (; this._state === v && this._queue.length; ) {
1308
+ const t = this._queue.shift();
1309
+ this._bufferedBytes -= t[3][h], Reflect.apply(t[0], this, t.slice(1));
1310
+ }
1311
+ }
1312
+ /**
1313
+ * Enqueues a send operation.
1314
+ *
1315
+ * @param {Array} params Send operation parameters.
1316
+ * @private
1317
+ */
1318
+ enqueue(t) {
1319
+ this._bufferedBytes += t[3][h], this._queue.push(t);
1320
+ }
1321
+ /**
1322
+ * Sends a frame.
1323
+ *
1324
+ * @param {(Buffer | String)[]} list The frame to send
1325
+ * @param {Function} [cb] Callback
1326
+ * @private
1327
+ */
1328
+ sendFrame(t, i) {
1329
+ t.length === 2 ? (this._socket.cork(), this._socket.write(t[0]), this._socket.write(t[1], i), this._socket.uncork()) : this._socket.write(t[0], i);
1330
+ }
1331
+ }
1332
+ ye = l;
1333
+ function E(e, t, i) {
1334
+ typeof i == "function" && i(t);
1335
+ for (let s = 0; s < e._queue.length; s++) {
1336
+ const m = e._queue[s], y = m[m.length - 1];
1337
+ typeof y == "function" && y(t);
1338
+ }
1339
+ }
1340
+ function u(e, t, i) {
1341
+ E(e, t, i), e.onerror(t);
1342
+ }
1343
+ return ye;
1344
+ }
1345
+ var Ee, ze;
1346
+ function Ct() {
1347
+ if (ze) return Ee;
1348
+ ze = 1;
1349
+ const { kForOnEventAttribute: P, kListener: T } = j(), M = /* @__PURE__ */ Symbol("kCode"), B = /* @__PURE__ */ Symbol("kData"), b = /* @__PURE__ */ Symbol("kError"), d = /* @__PURE__ */ Symbol("kMessage"), n = /* @__PURE__ */ Symbol("kReason"), f = /* @__PURE__ */ Symbol("kTarget"), a = /* @__PURE__ */ Symbol("kType"), _ = /* @__PURE__ */ Symbol("kWasClean");
1350
+ class h {
1351
+ /**
1352
+ * Create a new `Event`.
1353
+ *
1354
+ * @param {String} type The name of the event
1355
+ * @throws {TypeError} If the `type` argument is not specified
1356
+ */
1357
+ constructor(p) {
1358
+ this[f] = null, this[a] = p;
1359
+ }
1360
+ /**
1361
+ * @type {*}
1362
+ */
1363
+ get target() {
1364
+ return this[f];
1365
+ }
1366
+ /**
1367
+ * @type {String}
1368
+ */
1369
+ get type() {
1370
+ return this[a];
1371
+ }
1372
+ }
1373
+ Object.defineProperty(h.prototype, "target", { enumerable: !0 }), Object.defineProperty(h.prototype, "type", { enumerable: !0 });
1374
+ class C extends h {
1375
+ /**
1376
+ * Create a new `CloseEvent`.
1377
+ *
1378
+ * @param {String} type The name of the event
1379
+ * @param {Object} [options] A dictionary object that allows for setting
1380
+ * attributes via object members of the same name
1381
+ * @param {Number} [options.code=0] The status code explaining why the
1382
+ * connection was closed
1383
+ * @param {String} [options.reason=''] A human-readable string explaining why
1384
+ * the connection was closed
1385
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
1386
+ * connection was cleanly closed
1387
+ */
1388
+ constructor(p, l = {}) {
1389
+ super(p), this[M] = l.code === void 0 ? 0 : l.code, this[n] = l.reason === void 0 ? "" : l.reason, this[_] = l.wasClean === void 0 ? !1 : l.wasClean;
1390
+ }
1391
+ /**
1392
+ * @type {Number}
1393
+ */
1394
+ get code() {
1395
+ return this[M];
1396
+ }
1397
+ /**
1398
+ * @type {String}
1399
+ */
1400
+ get reason() {
1401
+ return this[n];
1402
+ }
1403
+ /**
1404
+ * @type {Boolean}
1405
+ */
1406
+ get wasClean() {
1407
+ return this[_];
1408
+ }
1409
+ }
1410
+ Object.defineProperty(C.prototype, "code", { enumerable: !0 }), Object.defineProperty(C.prototype, "reason", { enumerable: !0 }), Object.defineProperty(C.prototype, "wasClean", { enumerable: !0 });
1411
+ class c extends h {
1412
+ /**
1413
+ * Create a new `ErrorEvent`.
1414
+ *
1415
+ * @param {String} type The name of the event
1416
+ * @param {Object} [options] A dictionary object that allows for setting
1417
+ * attributes via object members of the same name
1418
+ * @param {*} [options.error=null] The error that generated this event
1419
+ * @param {String} [options.message=''] The error message
1420
+ */
1421
+ constructor(p, l = {}) {
1422
+ super(p), this[b] = l.error === void 0 ? null : l.error, this[d] = l.message === void 0 ? "" : l.message;
1423
+ }
1424
+ /**
1425
+ * @type {*}
1426
+ */
1427
+ get error() {
1428
+ return this[b];
1429
+ }
1430
+ /**
1431
+ * @type {String}
1432
+ */
1433
+ get message() {
1434
+ return this[d];
1435
+ }
1436
+ }
1437
+ Object.defineProperty(c.prototype, "error", { enumerable: !0 }), Object.defineProperty(c.prototype, "message", { enumerable: !0 });
1438
+ class w extends h {
1439
+ /**
1440
+ * Create a new `MessageEvent`.
1441
+ *
1442
+ * @param {String} type The name of the event
1443
+ * @param {Object} [options] A dictionary object that allows for setting
1444
+ * attributes via object members of the same name
1445
+ * @param {*} [options.data=null] The message content
1446
+ */
1447
+ constructor(p, l = {}) {
1448
+ super(p), this[B] = l.data === void 0 ? null : l.data;
1449
+ }
1450
+ /**
1451
+ * @type {*}
1452
+ */
1453
+ get data() {
1454
+ return this[B];
1455
+ }
1456
+ }
1457
+ Object.defineProperty(w.prototype, "data", { enumerable: !0 }), Ee = {
1458
+ CloseEvent: C,
1459
+ ErrorEvent: c,
1460
+ Event: h,
1461
+ EventTarget: {
1462
+ /**
1463
+ * Register an event listener.
1464
+ *
1465
+ * @param {String} type A string representing the event type to listen for
1466
+ * @param {(Function|Object)} handler The listener to add
1467
+ * @param {Object} [options] An options object specifies characteristics about
1468
+ * the event listener
1469
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
1470
+ * listener should be invoked at most once after being added. If `true`,
1471
+ * the listener would be automatically removed when invoked.
1472
+ * @public
1473
+ */
1474
+ addEventListener(O, p, l = {}) {
1475
+ for (const u of this.listeners(O))
1476
+ if (!l[P] && u[T] === p && !u[P])
1477
+ return;
1478
+ let E;
1479
+ if (O === "message")
1480
+ E = function(e, t) {
1481
+ const i = new w("message", {
1482
+ data: t ? e : e.toString()
1483
+ });
1484
+ i[f] = this, v(p, this, i);
1485
+ };
1486
+ else if (O === "close")
1487
+ E = function(e, t) {
1488
+ const i = new C("close", {
1489
+ code: e,
1490
+ reason: t.toString(),
1491
+ wasClean: this._closeFrameReceived && this._closeFrameSent
1492
+ });
1493
+ i[f] = this, v(p, this, i);
1494
+ };
1495
+ else if (O === "error")
1496
+ E = function(e) {
1497
+ const t = new c("error", {
1498
+ error: e,
1499
+ message: e.message
1500
+ });
1501
+ t[f] = this, v(p, this, t);
1502
+ };
1503
+ else if (O === "open")
1504
+ E = function() {
1505
+ const e = new h("open");
1506
+ e[f] = this, v(p, this, e);
1507
+ };
1508
+ else
1509
+ return;
1510
+ E[P] = !!l[P], E[T] = p, l.once ? this.once(O, E) : this.on(O, E);
1511
+ },
1512
+ /**
1513
+ * Remove an event listener.
1514
+ *
1515
+ * @param {String} type A string representing the event type to remove
1516
+ * @param {(Function|Object)} handler The listener to remove
1517
+ * @public
1518
+ */
1519
+ removeEventListener(O, p) {
1520
+ for (const l of this.listeners(O))
1521
+ if (l[T] === p && !l[P]) {
1522
+ this.removeListener(O, l);
1523
+ break;
1524
+ }
1525
+ }
1526
+ },
1527
+ MessageEvent: w
1528
+ };
1529
+ function v(O, p, l) {
1530
+ typeof O == "object" && O.handleEvent ? O.handleEvent.call(O, l) : O.call(p, l);
1531
+ }
1532
+ return Ee;
1533
+ }
1534
+ var xe, He;
1535
+ function it() {
1536
+ if (He) return xe;
1537
+ He = 1;
1538
+ const { tokenChars: P } = ie();
1539
+ function T(b, d, n) {
1540
+ b[d] === void 0 ? b[d] = [n] : b[d].push(n);
1541
+ }
1542
+ function M(b) {
1543
+ const d = /* @__PURE__ */ Object.create(null);
1544
+ let n = /* @__PURE__ */ Object.create(null), f = !1, a = !1, _ = !1, h, C, c = -1, w = -1, k = -1, v = 0;
1545
+ for (; v < b.length; v++)
1546
+ if (w = b.charCodeAt(v), h === void 0)
1547
+ if (k === -1 && P[w] === 1)
1548
+ c === -1 && (c = v);
1549
+ else if (v !== 0 && (w === 32 || w === 9))
1550
+ k === -1 && c !== -1 && (k = v);
1551
+ else if (w === 59 || w === 44) {
1552
+ if (c === -1)
1553
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1554
+ k === -1 && (k = v);
1555
+ const p = b.slice(c, k);
1556
+ w === 44 ? (T(d, p, n), n = /* @__PURE__ */ Object.create(null)) : h = p, c = k = -1;
1557
+ } else
1558
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1559
+ else if (C === void 0)
1560
+ if (k === -1 && P[w] === 1)
1561
+ c === -1 && (c = v);
1562
+ else if (w === 32 || w === 9)
1563
+ k === -1 && c !== -1 && (k = v);
1564
+ else if (w === 59 || w === 44) {
1565
+ if (c === -1)
1566
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1567
+ k === -1 && (k = v), T(n, b.slice(c, k), !0), w === 44 && (T(d, h, n), n = /* @__PURE__ */ Object.create(null), h = void 0), c = k = -1;
1568
+ } else if (w === 61 && c !== -1 && k === -1)
1569
+ C = b.slice(c, v), c = k = -1;
1570
+ else
1571
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1572
+ else if (a) {
1573
+ if (P[w] !== 1)
1574
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1575
+ c === -1 ? c = v : f || (f = !0), a = !1;
1576
+ } else if (_)
1577
+ if (P[w] === 1)
1578
+ c === -1 && (c = v);
1579
+ else if (w === 34 && c !== -1)
1580
+ _ = !1, k = v;
1581
+ else if (w === 92)
1582
+ a = !0;
1583
+ else
1584
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1585
+ else if (w === 34 && b.charCodeAt(v - 1) === 61)
1586
+ _ = !0;
1587
+ else if (k === -1 && P[w] === 1)
1588
+ c === -1 && (c = v);
1589
+ else if (c !== -1 && (w === 32 || w === 9))
1590
+ k === -1 && (k = v);
1591
+ else if (w === 59 || w === 44) {
1592
+ if (c === -1)
1593
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1594
+ k === -1 && (k = v);
1595
+ let p = b.slice(c, k);
1596
+ f && (p = p.replace(/\\/g, ""), f = !1), T(n, C, p), w === 44 && (T(d, h, n), n = /* @__PURE__ */ Object.create(null), h = void 0), C = void 0, c = k = -1;
1597
+ } else
1598
+ throw new SyntaxError(`Unexpected character at index ${v}`);
1599
+ if (c === -1 || _ || w === 32 || w === 9)
1600
+ throw new SyntaxError("Unexpected end of input");
1601
+ k === -1 && (k = v);
1602
+ const O = b.slice(c, k);
1603
+ return h === void 0 ? T(d, O, n) : (C === void 0 ? T(n, O, !0) : f ? T(n, C, O.replace(/\\/g, "")) : T(n, C, O), T(d, h, n)), d;
1604
+ }
1605
+ function B(b) {
1606
+ return Object.keys(b).map((d) => {
1607
+ let n = b[d];
1608
+ return Array.isArray(n) || (n = [n]), n.map((f) => [d].concat(
1609
+ Object.keys(f).map((a) => {
1610
+ let _ = f[a];
1611
+ return Array.isArray(_) || (_ = [_]), _.map((h) => h === !0 ? a : `${a}=${h}`).join("; ");
1612
+ })
1613
+ ).join("; ")).join(", ");
1614
+ }).join(", ");
1615
+ }
1616
+ return xe = { format: B, parse: M }, xe;
1617
+ }
1618
+ var Se, Ye;
1619
+ function Te() {
1620
+ if (Ye) return Se;
1621
+ Ye = 1;
1622
+ const P = Qe, T = dt, M = Je, B = _t, b = pt, { randomBytes: d, createHash: n } = Oe, { Duplex: f, Readable: a } = se, { URL: _ } = mt, h = ae(), C = rt(), c = st(), { isBlob: w } = ie(), {
1623
+ BINARY_TYPES: k,
1624
+ EMPTY_BUFFER: v,
1625
+ GUID: O,
1626
+ kForOnEventAttribute: p,
1627
+ kListener: l,
1628
+ kStatusCode: E,
1629
+ kWebSocket: u,
1630
+ NOOP: e
1631
+ } = j(), {
1632
+ EventTarget: { addEventListener: t, removeEventListener: i }
1633
+ } = Ct(), { format: s, parse: m } = it(), { toBuffer: y } = oe(), R = 30 * 1e3, D = /* @__PURE__ */ Symbol("kAborted"), A = [8, 13], N = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"], V = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1634
+ class S extends P {
1635
+ /**
1636
+ * Create a new `WebSocket`.
1637
+ *
1638
+ * @param {(String|URL)} address The URL to which to connect
1639
+ * @param {(String|String[])} [protocols] The subprotocols
1640
+ * @param {Object} [options] Connection options
1641
+ */
1642
+ constructor(o, x, L) {
1643
+ super(), this._binaryType = k[0], this._closeCode = 1006, this._closeFrameReceived = !1, this._closeFrameSent = !1, this._closeMessage = v, this._closeTimer = null, this._errorEmitted = !1, this._extensions = {}, this._paused = !1, this._protocol = "", this._readyState = S.CONNECTING, this._receiver = null, this._sender = null, this._socket = null, o !== null ? (this._bufferedAmount = 0, this._isServer = !1, this._redirects = 0, x === void 0 ? x = [] : Array.isArray(x) || (typeof x == "object" && x !== null ? (L = x, x = []) : x = [x]), G(this, o, x, L)) : (this._autoPong = L.autoPong, this._isServer = !0);
1644
+ }
1645
+ /**
1646
+ * For historical reasons, the custom "nodebuffer" type is used by the default
1647
+ * instead of "blob".
1648
+ *
1649
+ * @type {String}
1650
+ */
1651
+ get binaryType() {
1652
+ return this._binaryType;
1653
+ }
1654
+ set binaryType(o) {
1655
+ k.includes(o) && (this._binaryType = o, this._receiver && (this._receiver._binaryType = o));
1656
+ }
1657
+ /**
1658
+ * @type {Number}
1659
+ */
1660
+ get bufferedAmount() {
1661
+ return this._socket ? this._socket._writableState.length + this._sender._bufferedBytes : this._bufferedAmount;
1662
+ }
1663
+ /**
1664
+ * @type {String}
1665
+ */
1666
+ get extensions() {
1667
+ return Object.keys(this._extensions).join();
1668
+ }
1669
+ /**
1670
+ * @type {Boolean}
1671
+ */
1672
+ get isPaused() {
1673
+ return this._paused;
1674
+ }
1675
+ /**
1676
+ * @type {Function}
1677
+ */
1678
+ /* istanbul ignore next */
1679
+ get onclose() {
1680
+ return null;
1681
+ }
1682
+ /**
1683
+ * @type {Function}
1684
+ */
1685
+ /* istanbul ignore next */
1686
+ get onerror() {
1687
+ return null;
1688
+ }
1689
+ /**
1690
+ * @type {Function}
1691
+ */
1692
+ /* istanbul ignore next */
1693
+ get onopen() {
1694
+ return null;
1695
+ }
1696
+ /**
1697
+ * @type {Function}
1698
+ */
1699
+ /* istanbul ignore next */
1700
+ get onmessage() {
1701
+ return null;
1702
+ }
1703
+ /**
1704
+ * @type {String}
1705
+ */
1706
+ get protocol() {
1707
+ return this._protocol;
1708
+ }
1709
+ /**
1710
+ * @type {Number}
1711
+ */
1712
+ get readyState() {
1713
+ return this._readyState;
1714
+ }
1715
+ /**
1716
+ * @type {String}
1717
+ */
1718
+ get url() {
1719
+ return this._url;
1720
+ }
1721
+ /**
1722
+ * Set up the socket and the internal resources.
1723
+ *
1724
+ * @param {Duplex} socket The network socket between the server and client
1725
+ * @param {Buffer} head The first packet of the upgraded stream
1726
+ * @param {Object} options Options object
1727
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
1728
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
1729
+ * multiple times in the same tick
1730
+ * @param {Function} [options.generateMask] The function used to generate the
1731
+ * masking key
1732
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
1733
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1734
+ * not to skip UTF-8 validation for text and close messages
1735
+ * @private
1736
+ */
1737
+ setSocket(o, x, L) {
1738
+ const g = new C({
1739
+ allowSynchronousEvents: L.allowSynchronousEvents,
1740
+ binaryType: this.binaryType,
1741
+ extensions: this._extensions,
1742
+ isServer: this._isServer,
1743
+ maxPayload: L.maxPayload,
1744
+ skipUTF8Validation: L.skipUTF8Validation
1745
+ }), U = new c(o, this._extensions, L.generateMask);
1746
+ this._receiver = g, this._sender = U, this._socket = o, g[u] = this, U[u] = this, o[u] = this, g.on("conclude", nt), g.on("drain", ot), g.on("error", at), g.on("message", lt), g.on("ping", ft), g.on("pong", ht), U.onerror = ct, o.setTimeout && o.setTimeout(0), o.setNoDelay && o.setNoDelay(), x.length > 0 && o.unshift(x), o.on("close", Ne), o.on("data", ne), o.on("end", Pe), o.on("error", Re), this._readyState = S.OPEN, this.emit("open");
1747
+ }
1748
+ /**
1749
+ * Emit the `'close'` event.
1750
+ *
1751
+ * @private
1752
+ */
1753
+ emitClose() {
1754
+ if (!this._socket) {
1755
+ this._readyState = S.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1756
+ return;
1757
+ }
1758
+ this._extensions[h.extensionName] && this._extensions[h.extensionName].cleanup(), this._receiver.removeAllListeners(), this._readyState = S.CLOSED, this.emit("close", this._closeCode, this._closeMessage);
1759
+ }
1760
+ /**
1761
+ * Start a closing handshake.
1762
+ *
1763
+ * +----------+ +-----------+ +----------+
1764
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
1765
+ * | +----------+ +-----------+ +----------+ |
1766
+ * +----------+ +-----------+ |
1767
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
1768
+ * +----------+ +-----------+ |
1769
+ * | | | +---+ |
1770
+ * +------------------------+-->|fin| - - - -
1771
+ * | +---+ | +---+
1772
+ * - - - - -|fin|<---------------------+
1773
+ * +---+
1774
+ *
1775
+ * @param {Number} [code] Status code explaining why the connection is closing
1776
+ * @param {(String|Buffer)} [data] The reason why the connection is
1777
+ * closing
1778
+ * @public
1779
+ */
1780
+ close(o, x) {
1781
+ if (this.readyState !== S.CLOSED) {
1782
+ if (this.readyState === S.CONNECTING) {
1783
+ W(this, this._req, "WebSocket was closed before the connection was established");
1784
+ return;
1785
+ }
1786
+ if (this.readyState === S.CLOSING) {
1787
+ this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end();
1788
+ return;
1789
+ }
1790
+ this._readyState = S.CLOSING, this._sender.close(o, x, !this._isServer, (L) => {
1791
+ L || (this._closeFrameSent = !0, (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end());
1792
+ }), Le(this);
1793
+ }
1794
+ }
1795
+ /**
1796
+ * Pause the socket.
1797
+ *
1798
+ * @public
1799
+ */
1800
+ pause() {
1801
+ this.readyState === S.CONNECTING || this.readyState === S.CLOSED || (this._paused = !0, this._socket.pause());
1802
+ }
1803
+ /**
1804
+ * Send a ping.
1805
+ *
1806
+ * @param {*} [data] The data to send
1807
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
1808
+ * @param {Function} [cb] Callback which is executed when the ping is sent
1809
+ * @public
1810
+ */
1811
+ ping(o, x, L) {
1812
+ if (this.readyState === S.CONNECTING)
1813
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1814
+ if (typeof o == "function" ? (L = o, o = x = void 0) : typeof x == "function" && (L = x, x = void 0), typeof o == "number" && (o = o.toString()), this.readyState !== S.OPEN) {
1815
+ ce(this, o, L);
1816
+ return;
1817
+ }
1818
+ x === void 0 && (x = !this._isServer), this._sender.ping(o || v, x, L);
1819
+ }
1820
+ /**
1821
+ * Send a pong.
1822
+ *
1823
+ * @param {*} [data] The data to send
1824
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
1825
+ * @param {Function} [cb] Callback which is executed when the pong is sent
1826
+ * @public
1827
+ */
1828
+ pong(o, x, L) {
1829
+ if (this.readyState === S.CONNECTING)
1830
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1831
+ if (typeof o == "function" ? (L = o, o = x = void 0) : typeof x == "function" && (L = x, x = void 0), typeof o == "number" && (o = o.toString()), this.readyState !== S.OPEN) {
1832
+ ce(this, o, L);
1833
+ return;
1834
+ }
1835
+ x === void 0 && (x = !this._isServer), this._sender.pong(o || v, x, L);
1836
+ }
1837
+ /**
1838
+ * Resume the socket.
1839
+ *
1840
+ * @public
1841
+ */
1842
+ resume() {
1843
+ this.readyState === S.CONNECTING || this.readyState === S.CLOSED || (this._paused = !1, this._receiver._writableState.needDrain || this._socket.resume());
1844
+ }
1845
+ /**
1846
+ * Send a data message.
1847
+ *
1848
+ * @param {*} data The message to send
1849
+ * @param {Object} [options] Options object
1850
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
1851
+ * text
1852
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
1853
+ * `data`
1854
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
1855
+ * last one
1856
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
1857
+ * @param {Function} [cb] Callback which is executed when data is written out
1858
+ * @public
1859
+ */
1860
+ send(o, x, L) {
1861
+ if (this.readyState === S.CONNECTING)
1862
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
1863
+ if (typeof x == "function" && (L = x, x = {}), typeof o == "number" && (o = o.toString()), this.readyState !== S.OPEN) {
1864
+ ce(this, o, L);
1865
+ return;
1866
+ }
1867
+ const g = {
1868
+ binary: typeof o != "string",
1869
+ mask: !this._isServer,
1870
+ compress: !0,
1871
+ fin: !0,
1872
+ ...x
1873
+ };
1874
+ this._extensions[h.extensionName] || (g.compress = !1), this._sender.send(o || v, g, L);
1875
+ }
1876
+ /**
1877
+ * Forcibly close the connection.
1878
+ *
1879
+ * @public
1880
+ */
1881
+ terminate() {
1882
+ if (this.readyState !== S.CLOSED) {
1883
+ if (this.readyState === S.CONNECTING) {
1884
+ W(this, this._req, "WebSocket was closed before the connection was established");
1885
+ return;
1886
+ }
1887
+ this._socket && (this._readyState = S.CLOSING, this._socket.destroy());
1888
+ }
1889
+ }
1890
+ }
1891
+ Object.defineProperty(S, "CONNECTING", {
1892
+ enumerable: !0,
1893
+ value: N.indexOf("CONNECTING")
1894
+ }), Object.defineProperty(S.prototype, "CONNECTING", {
1895
+ enumerable: !0,
1896
+ value: N.indexOf("CONNECTING")
1897
+ }), Object.defineProperty(S, "OPEN", {
1898
+ enumerable: !0,
1899
+ value: N.indexOf("OPEN")
1900
+ }), Object.defineProperty(S.prototype, "OPEN", {
1901
+ enumerable: !0,
1902
+ value: N.indexOf("OPEN")
1903
+ }), Object.defineProperty(S, "CLOSING", {
1904
+ enumerable: !0,
1905
+ value: N.indexOf("CLOSING")
1906
+ }), Object.defineProperty(S.prototype, "CLOSING", {
1907
+ enumerable: !0,
1908
+ value: N.indexOf("CLOSING")
1909
+ }), Object.defineProperty(S, "CLOSED", {
1910
+ enumerable: !0,
1911
+ value: N.indexOf("CLOSED")
1912
+ }), Object.defineProperty(S.prototype, "CLOSED", {
1913
+ enumerable: !0,
1914
+ value: N.indexOf("CLOSED")
1915
+ }), [
1916
+ "binaryType",
1917
+ "bufferedAmount",
1918
+ "extensions",
1919
+ "isPaused",
1920
+ "protocol",
1921
+ "readyState",
1922
+ "url"
1923
+ ].forEach((r) => {
1924
+ Object.defineProperty(S.prototype, r, { enumerable: !0 });
1925
+ }), ["open", "error", "close", "message"].forEach((r) => {
1926
+ Object.defineProperty(S.prototype, `on${r}`, {
1927
+ enumerable: !0,
1928
+ get() {
1929
+ for (const o of this.listeners(r))
1930
+ if (o[p]) return o[l];
1931
+ return null;
1932
+ },
1933
+ set(o) {
1934
+ for (const x of this.listeners(r))
1935
+ if (x[p]) {
1936
+ this.removeListener(r, x);
1937
+ break;
1938
+ }
1939
+ typeof o == "function" && this.addEventListener(r, o, {
1940
+ [p]: !0
1941
+ });
1942
+ }
1943
+ });
1944
+ }), S.prototype.addEventListener = t, S.prototype.removeEventListener = i, Se = S;
1945
+ function G(r, o, x, L) {
1946
+ const g = {
1947
+ allowSynchronousEvents: !0,
1948
+ autoPong: !0,
1949
+ protocolVersion: A[1],
1950
+ maxPayload: 104857600,
1951
+ skipUTF8Validation: !1,
1952
+ perMessageDeflate: !0,
1953
+ followRedirects: !1,
1954
+ maxRedirects: 10,
1955
+ ...L,
1956
+ socketPath: void 0,
1957
+ hostname: void 0,
1958
+ protocol: void 0,
1959
+ timeout: void 0,
1960
+ method: "GET",
1961
+ host: void 0,
1962
+ path: void 0,
1963
+ port: void 0
1964
+ };
1965
+ if (r._autoPong = g.autoPong, !A.includes(g.protocolVersion))
1966
+ throw new RangeError(
1967
+ `Unsupported protocol version: ${g.protocolVersion} (supported versions: ${A.join(", ")})`
1968
+ );
1969
+ let U;
1970
+ if (o instanceof _)
1971
+ U = o;
1972
+ else
1973
+ try {
1974
+ U = new _(o);
1975
+ } catch {
1976
+ throw new SyntaxError(`Invalid URL: ${o}`);
1977
+ }
1978
+ U.protocol === "http:" ? U.protocol = "ws:" : U.protocol === "https:" && (U.protocol = "wss:"), r._url = U.href;
1979
+ const z = U.protocol === "wss:", H = U.protocol === "ws+unix:";
1980
+ let X;
1981
+ if (U.protocol !== "ws:" && !z && !H ? X = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"` : H && !U.pathname ? X = "The URL's pathname is empty" : U.hash && (X = "The URL contains a fragment identifier"), X) {
1982
+ const I = new SyntaxError(X);
1983
+ if (r._redirects === 0)
1984
+ throw I;
1985
+ q(r, I);
1986
+ return;
1987
+ }
1988
+ const Be = z ? 443 : 80, De = d(16).toString("base64"), Ie = z ? T.request : M.request, Z = /* @__PURE__ */ new Set();
1989
+ let Q;
1990
+ if (g.createConnection = g.createConnection || (z ? he : fe), g.defaultPort = g.defaultPort || Be, g.port = U.port || Be, g.host = U.hostname.startsWith("[") ? U.hostname.slice(1, -1) : U.hostname, g.headers = {
1991
+ ...g.headers,
1992
+ "Sec-WebSocket-Version": g.protocolVersion,
1993
+ "Sec-WebSocket-Key": De,
1994
+ Connection: "Upgrade",
1995
+ Upgrade: "websocket"
1996
+ }, g.path = U.pathname + U.search, g.timeout = g.handshakeTimeout, g.perMessageDeflate && (Q = new h(
1997
+ g.perMessageDeflate !== !0 ? g.perMessageDeflate : {},
1998
+ !1,
1999
+ g.maxPayload
2000
+ ), g.headers["Sec-WebSocket-Extensions"] = s({
2001
+ [h.extensionName]: Q.offer()
2002
+ })), x.length) {
2003
+ for (const I of x) {
2004
+ if (typeof I != "string" || !V.test(I) || Z.has(I))
2005
+ throw new SyntaxError(
2006
+ "An invalid or duplicated subprotocol was specified"
2007
+ );
2008
+ Z.add(I);
2009
+ }
2010
+ g.headers["Sec-WebSocket-Protocol"] = x.join(",");
2011
+ }
2012
+ if (g.origin && (g.protocolVersion < 13 ? g.headers["Sec-WebSocket-Origin"] = g.origin : g.headers.Origin = g.origin), (U.username || U.password) && (g.auth = `${U.username}:${U.password}`), H) {
2013
+ const I = g.path.split(":");
2014
+ g.socketPath = I[0], g.path = I[1];
2015
+ }
2016
+ let $;
2017
+ if (g.followRedirects) {
2018
+ if (r._redirects === 0) {
2019
+ r._originalIpc = H, r._originalSecure = z, r._originalHostOrSocketPath = H ? g.socketPath : U.host;
2020
+ const I = L && L.headers;
2021
+ if (L = { ...L, headers: {} }, I)
2022
+ for (const [F, Y] of Object.entries(I))
2023
+ L.headers[F.toLowerCase()] = Y;
2024
+ } else if (r.listenerCount("redirect") === 0) {
2025
+ const I = H ? r._originalIpc ? g.socketPath === r._originalHostOrSocketPath : !1 : r._originalIpc ? !1 : U.host === r._originalHostOrSocketPath;
2026
+ (!I || r._originalSecure && !z) && (delete g.headers.authorization, delete g.headers.cookie, I || delete g.headers.host, g.auth = void 0);
2027
+ }
2028
+ g.auth && !L.headers.authorization && (L.headers.authorization = "Basic " + Buffer.from(g.auth).toString("base64")), $ = r._req = Ie(g), r._redirects && r.emit("redirect", r.url, $);
2029
+ } else
2030
+ $ = r._req = Ie(g);
2031
+ g.timeout && $.on("timeout", () => {
2032
+ W(r, $, "Opening handshake has timed out");
2033
+ }), $.on("error", (I) => {
2034
+ $ === null || $[D] || ($ = r._req = null, q(r, I));
2035
+ }), $.on("response", (I) => {
2036
+ const F = I.headers.location, Y = I.statusCode;
2037
+ if (F && g.followRedirects && Y >= 300 && Y < 400) {
2038
+ if (++r._redirects > g.maxRedirects) {
2039
+ W(r, $, "Maximum redirects exceeded");
2040
+ return;
2041
+ }
2042
+ $.abort();
2043
+ let J;
2044
+ try {
2045
+ J = new _(F, o);
2046
+ } catch {
2047
+ const K = new SyntaxError(`Invalid URL: ${F}`);
2048
+ q(r, K);
2049
+ return;
2050
+ }
2051
+ G(r, J, x, L);
2052
+ } else r.emit("unexpected-response", $, I) || W(
2053
+ r,
2054
+ $,
2055
+ `Unexpected server response: ${I.statusCode}`
2056
+ );
2057
+ }), $.on("upgrade", (I, F, Y) => {
2058
+ if (r.emit("upgrade", I), r.readyState !== S.CONNECTING) return;
2059
+ $ = r._req = null;
2060
+ const J = I.headers.upgrade;
2061
+ if (J === void 0 || J.toLowerCase() !== "websocket") {
2062
+ W(r, F, "Invalid Upgrade header");
2063
+ return;
2064
+ }
2065
+ const Ue = n("sha1").update(De + O).digest("base64");
2066
+ if (I.headers["sec-websocket-accept"] !== Ue) {
2067
+ W(r, F, "Invalid Sec-WebSocket-Accept header");
2068
+ return;
2069
+ }
2070
+ const K = I.headers["sec-websocket-protocol"];
2071
+ let ee;
2072
+ if (K !== void 0 ? Z.size ? Z.has(K) || (ee = "Server sent an invalid subprotocol") : ee = "Server sent a subprotocol but none was requested" : Z.size && (ee = "Server sent no subprotocol"), ee) {
2073
+ W(r, F, ee);
2074
+ return;
2075
+ }
2076
+ K && (r._protocol = K);
2077
+ const Me = I.headers["sec-websocket-extensions"];
2078
+ if (Me !== void 0) {
2079
+ if (!Q) {
2080
+ W(r, F, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
2081
+ return;
2082
+ }
2083
+ let ue;
2084
+ try {
2085
+ ue = m(Me);
2086
+ } catch {
2087
+ W(r, F, "Invalid Sec-WebSocket-Extensions header");
2088
+ return;
2089
+ }
2090
+ const Ae = Object.keys(ue);
2091
+ if (Ae.length !== 1 || Ae[0] !== h.extensionName) {
2092
+ W(r, F, "Server indicated an extension that was not requested");
2093
+ return;
2094
+ }
2095
+ try {
2096
+ Q.accept(ue[h.extensionName]);
2097
+ } catch {
2098
+ W(r, F, "Invalid Sec-WebSocket-Extensions header");
2099
+ return;
2100
+ }
2101
+ r._extensions[h.extensionName] = Q;
2102
+ }
2103
+ r.setSocket(F, Y, {
2104
+ allowSynchronousEvents: g.allowSynchronousEvents,
2105
+ generateMask: g.generateMask,
2106
+ maxPayload: g.maxPayload,
2107
+ skipUTF8Validation: g.skipUTF8Validation
2108
+ });
2109
+ }), g.finishRequest ? g.finishRequest($, r) : $.end();
2110
+ }
2111
+ function q(r, o) {
2112
+ r._readyState = S.CLOSING, r._errorEmitted = !0, r.emit("error", o), r.emitClose();
2113
+ }
2114
+ function fe(r) {
2115
+ return r.path = r.socketPath, B.connect(r);
2116
+ }
2117
+ function he(r) {
2118
+ return r.path = void 0, !r.servername && r.servername !== "" && (r.servername = B.isIP(r.host) ? "" : r.host), b.connect(r);
2119
+ }
2120
+ function W(r, o, x) {
2121
+ r._readyState = S.CLOSING;
2122
+ const L = new Error(x);
2123
+ Error.captureStackTrace(L, W), o.setHeader ? (o[D] = !0, o.abort(), o.socket && !o.socket.destroyed && o.socket.destroy(), process.nextTick(q, r, L)) : (o.destroy(L), o.once("error", r.emit.bind(r, "error")), o.once("close", r.emitClose.bind(r)));
2124
+ }
2125
+ function ce(r, o, x) {
2126
+ if (o) {
2127
+ const L = w(o) ? o.size : y(o).length;
2128
+ r._socket ? r._sender._bufferedBytes += L : r._bufferedAmount += L;
2129
+ }
2130
+ if (x) {
2131
+ const L = new Error(
2132
+ `WebSocket is not open: readyState ${r.readyState} (${N[r.readyState]})`
2133
+ );
2134
+ process.nextTick(x, L);
2135
+ }
2136
+ }
2137
+ function nt(r, o) {
2138
+ const x = this[u];
2139
+ x._closeFrameReceived = !0, x._closeMessage = o, x._closeCode = r, x._socket[u] !== void 0 && (x._socket.removeListener("data", ne), process.nextTick(ke, x._socket), r === 1005 ? x.close() : x.close(r, o));
2140
+ }
2141
+ function ot() {
2142
+ const r = this[u];
2143
+ r.isPaused || r._socket.resume();
2144
+ }
2145
+ function at(r) {
2146
+ const o = this[u];
2147
+ o._socket[u] !== void 0 && (o._socket.removeListener("data", ne), process.nextTick(ke, o._socket), o.close(r[E])), o._errorEmitted || (o._errorEmitted = !0, o.emit("error", r));
2148
+ }
2149
+ function Ce() {
2150
+ this[u].emitClose();
2151
+ }
2152
+ function lt(r, o) {
2153
+ this[u].emit("message", r, o);
2154
+ }
2155
+ function ft(r) {
2156
+ const o = this[u];
2157
+ o._autoPong && o.pong(r, !this._isServer, e), o.emit("ping", r);
2158
+ }
2159
+ function ht(r) {
2160
+ this[u].emit("pong", r);
2161
+ }
2162
+ function ke(r) {
2163
+ r.resume();
2164
+ }
2165
+ function ct(r) {
2166
+ const o = this[u];
2167
+ o.readyState !== S.CLOSED && (o.readyState === S.OPEN && (o._readyState = S.CLOSING, Le(o)), this._socket.end(), o._errorEmitted || (o._errorEmitted = !0, o.emit("error", r)));
2168
+ }
2169
+ function Le(r) {
2170
+ r._closeTimer = setTimeout(
2171
+ r._socket.destroy.bind(r._socket),
2172
+ R
2173
+ );
2174
+ }
2175
+ function Ne() {
2176
+ const r = this[u];
2177
+ this.removeListener("close", Ne), this.removeListener("data", ne), this.removeListener("end", Pe), r._readyState = S.CLOSING;
2178
+ let o;
2179
+ !this._readableState.endEmitted && !r._closeFrameReceived && !r._receiver._writableState.errorEmitted && (o = r._socket.read()) !== null && r._receiver.write(o), r._receiver.end(), this[u] = void 0, clearTimeout(r._closeTimer), r._receiver._writableState.finished || r._receiver._writableState.errorEmitted ? r.emitClose() : (r._receiver.on("error", Ce), r._receiver.on("finish", Ce));
2180
+ }
2181
+ function ne(r) {
2182
+ this[u]._receiver.write(r) || this.pause();
2183
+ }
2184
+ function Pe() {
2185
+ const r = this[u];
2186
+ r._readyState = S.CLOSING, r._receiver.end(), this.end();
2187
+ }
2188
+ function Re() {
2189
+ const r = this[u];
2190
+ this.removeListener("error", Re), this.on("error", e), r && (r._readyState = S.CLOSING, this.destroy());
2191
+ }
2192
+ return Se;
2193
+ }
2194
+ var ve, Ke;
2195
+ function kt() {
2196
+ if (Ke) return ve;
2197
+ Ke = 1, Te();
2198
+ const { Duplex: P } = se;
2199
+ function T(d) {
2200
+ d.emit("close");
2201
+ }
2202
+ function M() {
2203
+ !this.destroyed && this._writableState.finished && this.destroy();
2204
+ }
2205
+ function B(d) {
2206
+ this.removeListener("error", B), this.destroy(), this.listenerCount("error") === 0 && this.emit("error", d);
2207
+ }
2208
+ function b(d, n) {
2209
+ let f = !0;
2210
+ const a = new P({
2211
+ ...n,
2212
+ autoDestroy: !1,
2213
+ emitClose: !1,
2214
+ objectMode: !1,
2215
+ writableObjectMode: !1
2216
+ });
2217
+ return d.on("message", function(h, C) {
2218
+ const c = !C && a._readableState.objectMode ? h.toString() : h;
2219
+ a.push(c) || d.pause();
2220
+ }), d.once("error", function(h) {
2221
+ a.destroyed || (f = !1, a.destroy(h));
2222
+ }), d.once("close", function() {
2223
+ a.destroyed || a.push(null);
2224
+ }), a._destroy = function(_, h) {
2225
+ if (d.readyState === d.CLOSED) {
2226
+ h(_), process.nextTick(T, a);
2227
+ return;
2228
+ }
2229
+ let C = !1;
2230
+ d.once("error", function(w) {
2231
+ C = !0, h(w);
2232
+ }), d.once("close", function() {
2233
+ C || h(_), process.nextTick(T, a);
2234
+ }), f && d.terminate();
2235
+ }, a._final = function(_) {
2236
+ if (d.readyState === d.CONNECTING) {
2237
+ d.once("open", function() {
2238
+ a._final(_);
2239
+ });
2240
+ return;
2241
+ }
2242
+ d._socket !== null && (d._socket._writableState.finished ? (_(), a._readableState.endEmitted && a.destroy()) : (d._socket.once("finish", function() {
2243
+ _();
2244
+ }), d.close()));
2245
+ }, a._read = function() {
2246
+ d.isPaused && d.resume();
2247
+ }, a._write = function(_, h, C) {
2248
+ if (d.readyState === d.CONNECTING) {
2249
+ d.once("open", function() {
2250
+ a._write(_, h, C);
2251
+ });
2252
+ return;
2253
+ }
2254
+ d.send(_, C);
2255
+ }, a.on("end", M), a.on("error", B), a;
2256
+ }
2257
+ return ve = b, ve;
2258
+ }
2259
+ kt();
2260
+ rt();
2261
+ st();
2262
+ var Lt = Te();
2263
+ const Nt = /* @__PURE__ */ yt(Lt);
2264
+ var be, Xe;
2265
+ function Pt() {
2266
+ if (Xe) return be;
2267
+ Xe = 1;
2268
+ const { tokenChars: P } = ie();
2269
+ function T(M) {
2270
+ const B = /* @__PURE__ */ new Set();
2271
+ let b = -1, d = -1, n = 0;
2272
+ for (n; n < M.length; n++) {
2273
+ const a = M.charCodeAt(n);
2274
+ if (d === -1 && P[a] === 1)
2275
+ b === -1 && (b = n);
2276
+ else if (n !== 0 && (a === 32 || a === 9))
2277
+ d === -1 && b !== -1 && (d = n);
2278
+ else if (a === 44) {
2279
+ if (b === -1)
2280
+ throw new SyntaxError(`Unexpected character at index ${n}`);
2281
+ d === -1 && (d = n);
2282
+ const _ = M.slice(b, d);
2283
+ if (B.has(_))
2284
+ throw new SyntaxError(`The "${_}" subprotocol is duplicated`);
2285
+ B.add(_), b = d = -1;
2286
+ } else
2287
+ throw new SyntaxError(`Unexpected character at index ${n}`);
2288
+ }
2289
+ if (b === -1 || d !== -1)
2290
+ throw new SyntaxError("Unexpected end of input");
2291
+ const f = M.slice(b, n);
2292
+ if (B.has(f))
2293
+ throw new SyntaxError(`The "${f}" subprotocol is duplicated`);
2294
+ return B.add(f), B;
2295
+ }
2296
+ return be = { parse: T }, be;
2297
+ }
2298
+ var we, Ze;
2299
+ function Rt() {
2300
+ if (Ze) return we;
2301
+ Ze = 1;
2302
+ const P = Qe, T = Je, { Duplex: M } = se, { createHash: B } = Oe, b = it(), d = ae(), n = Pt(), f = Te(), { GUID: a, kWebSocket: _ } = j(), h = /^[+/0-9A-Za-z]{22}==$/, C = 0, c = 1, w = 2;
2303
+ class k extends P {
2304
+ /**
2305
+ * Create a `WebSocketServer` instance.
2306
+ *
2307
+ * @param {Object} options Configuration options
2308
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
2309
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2310
+ * multiple times in the same tick
2311
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
2312
+ * automatically send a pong in response to a ping
2313
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
2314
+ * pending connections
2315
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
2316
+ * track clients
2317
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
2318
+ * @param {String} [options.host] The hostname where to bind the server
2319
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
2320
+ * size
2321
+ * @param {Boolean} [options.noServer=false] Enable no server mode
2322
+ * @param {String} [options.path] Accept only connections matching this path
2323
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
2324
+ * permessage-deflate
2325
+ * @param {Number} [options.port] The port where to bind the server
2326
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
2327
+ * server to use
2328
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2329
+ * not to skip UTF-8 validation for text and close messages
2330
+ * @param {Function} [options.verifyClient] A hook to reject connections
2331
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
2332
+ * class to use. It must be the `WebSocket` class or class that extends it
2333
+ * @param {Function} [callback] A listener for the `listening` event
2334
+ */
2335
+ constructor(e, t) {
2336
+ if (super(), e = {
2337
+ allowSynchronousEvents: !0,
2338
+ autoPong: !0,
2339
+ maxPayload: 100 * 1024 * 1024,
2340
+ skipUTF8Validation: !1,
2341
+ perMessageDeflate: !1,
2342
+ handleProtocols: null,
2343
+ clientTracking: !0,
2344
+ verifyClient: null,
2345
+ noServer: !1,
2346
+ backlog: null,
2347
+ // use default (511 as implemented in net.js)
2348
+ server: null,
2349
+ host: null,
2350
+ path: null,
2351
+ port: null,
2352
+ WebSocket: f,
2353
+ ...e
2354
+ }, e.port == null && !e.server && !e.noServer || e.port != null && (e.server || e.noServer) || e.server && e.noServer)
2355
+ throw new TypeError(
2356
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
2357
+ );
2358
+ if (e.port != null ? (this._server = T.createServer((i, s) => {
2359
+ const m = T.STATUS_CODES[426];
2360
+ s.writeHead(426, {
2361
+ "Content-Length": m.length,
2362
+ "Content-Type": "text/plain"
2363
+ }), s.end(m);
2364
+ }), this._server.listen(
2365
+ e.port,
2366
+ e.host,
2367
+ e.backlog,
2368
+ t
2369
+ )) : e.server && (this._server = e.server), this._server) {
2370
+ const i = this.emit.bind(this, "connection");
2371
+ this._removeListeners = v(this._server, {
2372
+ listening: this.emit.bind(this, "listening"),
2373
+ error: this.emit.bind(this, "error"),
2374
+ upgrade: (s, m, y) => {
2375
+ this.handleUpgrade(s, m, y, i);
2376
+ }
2377
+ });
2378
+ }
2379
+ e.perMessageDeflate === !0 && (e.perMessageDeflate = {}), e.clientTracking && (this.clients = /* @__PURE__ */ new Set(), this._shouldEmitClose = !1), this.options = e, this._state = C;
2380
+ }
2381
+ /**
2382
+ * Returns the bound address, the address family name, and port of the server
2383
+ * as reported by the operating system if listening on an IP socket.
2384
+ * If the server is listening on a pipe or UNIX domain socket, the name is
2385
+ * returned as a string.
2386
+ *
2387
+ * @return {(Object|String|null)} The address of the server
2388
+ * @public
2389
+ */
2390
+ address() {
2391
+ if (this.options.noServer)
2392
+ throw new Error('The server is operating in "noServer" mode');
2393
+ return this._server ? this._server.address() : null;
2394
+ }
2395
+ /**
2396
+ * Stop the server from accepting new connections and emit the `'close'` event
2397
+ * when all existing connections are closed.
2398
+ *
2399
+ * @param {Function} [cb] A one-time listener for the `'close'` event
2400
+ * @public
2401
+ */
2402
+ close(e) {
2403
+ if (this._state === w) {
2404
+ e && this.once("close", () => {
2405
+ e(new Error("The server is not running"));
2406
+ }), process.nextTick(O, this);
2407
+ return;
2408
+ }
2409
+ if (e && this.once("close", e), this._state !== c)
2410
+ if (this._state = c, this.options.noServer || this.options.server)
2411
+ this._server && (this._removeListeners(), this._removeListeners = this._server = null), this.clients ? this.clients.size ? this._shouldEmitClose = !0 : process.nextTick(O, this) : process.nextTick(O, this);
2412
+ else {
2413
+ const t = this._server;
2414
+ this._removeListeners(), this._removeListeners = this._server = null, t.close(() => {
2415
+ O(this);
2416
+ });
2417
+ }
2418
+ }
2419
+ /**
2420
+ * See if a given request should be handled by this server instance.
2421
+ *
2422
+ * @param {http.IncomingMessage} req Request object to inspect
2423
+ * @return {Boolean} `true` if the request is valid, else `false`
2424
+ * @public
2425
+ */
2426
+ shouldHandle(e) {
2427
+ if (this.options.path) {
2428
+ const t = e.url.indexOf("?");
2429
+ if ((t !== -1 ? e.url.slice(0, t) : e.url) !== this.options.path) return !1;
2430
+ }
2431
+ return !0;
2432
+ }
2433
+ /**
2434
+ * Handle a HTTP Upgrade request.
2435
+ *
2436
+ * @param {http.IncomingMessage} req The request object
2437
+ * @param {Duplex} socket The network socket between the server and client
2438
+ * @param {Buffer} head The first packet of the upgraded stream
2439
+ * @param {Function} cb Callback
2440
+ * @public
2441
+ */
2442
+ handleUpgrade(e, t, i, s) {
2443
+ t.on("error", p);
2444
+ const m = e.headers["sec-websocket-key"], y = e.headers.upgrade, R = +e.headers["sec-websocket-version"];
2445
+ if (e.method !== "GET") {
2446
+ E(this, e, t, 405, "Invalid HTTP method");
2447
+ return;
2448
+ }
2449
+ if (y === void 0 || y.toLowerCase() !== "websocket") {
2450
+ E(this, e, t, 400, "Invalid Upgrade header");
2451
+ return;
2452
+ }
2453
+ if (m === void 0 || !h.test(m)) {
2454
+ E(this, e, t, 400, "Missing or invalid Sec-WebSocket-Key header");
2455
+ return;
2456
+ }
2457
+ if (R !== 13 && R !== 8) {
2458
+ E(this, e, t, 400, "Missing or invalid Sec-WebSocket-Version header", {
2459
+ "Sec-WebSocket-Version": "13, 8"
2460
+ });
2461
+ return;
2462
+ }
2463
+ if (!this.shouldHandle(e)) {
2464
+ l(t, 400);
2465
+ return;
2466
+ }
2467
+ const D = e.headers["sec-websocket-protocol"];
2468
+ let A = /* @__PURE__ */ new Set();
2469
+ if (D !== void 0)
2470
+ try {
2471
+ A = n.parse(D);
2472
+ } catch {
2473
+ E(this, e, t, 400, "Invalid Sec-WebSocket-Protocol header");
2474
+ return;
2475
+ }
2476
+ const N = e.headers["sec-websocket-extensions"], V = {};
2477
+ if (this.options.perMessageDeflate && N !== void 0) {
2478
+ const S = new d(
2479
+ this.options.perMessageDeflate,
2480
+ !0,
2481
+ this.options.maxPayload
2482
+ );
2483
+ try {
2484
+ const G = b.parse(N);
2485
+ G[d.extensionName] && (S.accept(G[d.extensionName]), V[d.extensionName] = S);
2486
+ } catch {
2487
+ E(this, e, t, 400, "Invalid or unacceptable Sec-WebSocket-Extensions header");
2488
+ return;
2489
+ }
2490
+ }
2491
+ if (this.options.verifyClient) {
2492
+ const S = {
2493
+ origin: e.headers[`${R === 8 ? "sec-websocket-origin" : "origin"}`],
2494
+ secure: !!(e.socket.authorized || e.socket.encrypted),
2495
+ req: e
2496
+ };
2497
+ if (this.options.verifyClient.length === 2) {
2498
+ this.options.verifyClient(S, (G, q, fe, he) => {
2499
+ if (!G)
2500
+ return l(t, q || 401, fe, he);
2501
+ this.completeUpgrade(
2502
+ V,
2503
+ m,
2504
+ A,
2505
+ e,
2506
+ t,
2507
+ i,
2508
+ s
2509
+ );
2510
+ });
2511
+ return;
2512
+ }
2513
+ if (!this.options.verifyClient(S)) return l(t, 401);
2514
+ }
2515
+ this.completeUpgrade(V, m, A, e, t, i, s);
2516
+ }
2517
+ /**
2518
+ * Upgrade the connection to WebSocket.
2519
+ *
2520
+ * @param {Object} extensions The accepted extensions
2521
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
2522
+ * @param {Set} protocols The subprotocols
2523
+ * @param {http.IncomingMessage} req The request object
2524
+ * @param {Duplex} socket The network socket between the server and client
2525
+ * @param {Buffer} head The first packet of the upgraded stream
2526
+ * @param {Function} cb Callback
2527
+ * @throws {Error} If called more than once with the same socket
2528
+ * @private
2529
+ */
2530
+ completeUpgrade(e, t, i, s, m, y, R) {
2531
+ if (!m.readable || !m.writable) return m.destroy();
2532
+ if (m[_])
2533
+ throw new Error(
2534
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
2535
+ );
2536
+ if (this._state > C) return l(m, 503);
2537
+ const A = [
2538
+ "HTTP/1.1 101 Switching Protocols",
2539
+ "Upgrade: websocket",
2540
+ "Connection: Upgrade",
2541
+ `Sec-WebSocket-Accept: ${B("sha1").update(t + a).digest("base64")}`
2542
+ ], N = new this.options.WebSocket(null, void 0, this.options);
2543
+ if (i.size) {
2544
+ const V = this.options.handleProtocols ? this.options.handleProtocols(i, s) : i.values().next().value;
2545
+ V && (A.push(`Sec-WebSocket-Protocol: ${V}`), N._protocol = V);
2546
+ }
2547
+ if (e[d.extensionName]) {
2548
+ const V = e[d.extensionName].params, S = b.format({
2549
+ [d.extensionName]: [V]
2550
+ });
2551
+ A.push(`Sec-WebSocket-Extensions: ${S}`), N._extensions = e;
2552
+ }
2553
+ this.emit("headers", A, s), m.write(A.concat(`\r
2554
+ `).join(`\r
2555
+ `)), m.removeListener("error", p), N.setSocket(m, y, {
2556
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
2557
+ maxPayload: this.options.maxPayload,
2558
+ skipUTF8Validation: this.options.skipUTF8Validation
2559
+ }), this.clients && (this.clients.add(N), N.on("close", () => {
2560
+ this.clients.delete(N), this._shouldEmitClose && !this.clients.size && process.nextTick(O, this);
2561
+ })), R(N, s);
2562
+ }
2563
+ }
2564
+ we = k;
2565
+ function v(u, e) {
2566
+ for (const t of Object.keys(e)) u.on(t, e[t]);
2567
+ return function() {
2568
+ for (const i of Object.keys(e))
2569
+ u.removeListener(i, e[i]);
2570
+ };
2571
+ }
2572
+ function O(u) {
2573
+ u._state = w, u.emit("close");
2574
+ }
2575
+ function p() {
2576
+ this.destroy();
2577
+ }
2578
+ function l(u, e, t, i) {
2579
+ t = t || T.STATUS_CODES[e], i = {
2580
+ Connection: "close",
2581
+ "Content-Type": "text/html",
2582
+ "Content-Length": Buffer.byteLength(t),
2583
+ ...i
2584
+ }, u.once("finish", u.destroy), u.end(
2585
+ `HTTP/1.1 ${e} ${T.STATUS_CODES[e]}\r
2586
+ ` + Object.keys(i).map((s) => `${s}: ${i[s]}`).join(`\r
2587
+ `) + `\r
2588
+ \r
2589
+ ` + t
2590
+ );
2591
+ }
2592
+ function E(u, e, t, i, s, m) {
2593
+ if (u.listenerCount("wsClientError")) {
2594
+ const y = new Error(s);
2595
+ Error.captureStackTrace(y, E), u.emit("wsClientError", y, t, e);
2596
+ } else
2597
+ l(t, i, s, m);
2598
+ }
2599
+ return we;
2600
+ }
2601
+ Rt();
2602
+ const le = global;
2603
+ le.WebSocket ||= Nt;
2604
+ le.window ||= global;
2605
+ le.self ||= global;
2606
+ le.window.__REACT_DEVTOOLS_COMPONENT_FILTERS__ = [
2607
+ {
2608
+ // ComponentFilterElementType
2609
+ type: 1,
2610
+ // ElementTypeHostComponent
2611
+ value: 7,
2612
+ isEnabled: !0
2613
+ },
2614
+ {
2615
+ // ComponentFilterDisplayName
2616
+ type: 2,
2617
+ value: "InternalApp",
2618
+ isEnabled: !0,
2619
+ isValid: !0
2620
+ },
2621
+ {
2622
+ // ComponentFilterDisplayName
2623
+ type: 2,
2624
+ value: "InternalAppContext",
2625
+ isEnabled: !0,
2626
+ isValid: !0
2627
+ },
2628
+ {
2629
+ // ComponentFilterDisplayName
2630
+ type: 2,
2631
+ value: "InternalStdoutContext",
2632
+ isEnabled: !0,
2633
+ isValid: !0
2634
+ },
2635
+ {
2636
+ // ComponentFilterDisplayName
2637
+ type: 2,
2638
+ value: "InternalStderrContext",
2639
+ isEnabled: !0,
2640
+ isValid: !0
2641
+ },
2642
+ {
2643
+ // ComponentFilterDisplayName
2644
+ type: 2,
2645
+ value: "InternalStdinContext",
2646
+ isEnabled: !0,
2647
+ isValid: !0
2648
+ },
2649
+ {
2650
+ // ComponentFilterDisplayName
2651
+ type: 2,
2652
+ value: "InternalFocusContext",
2653
+ isEnabled: !0,
2654
+ isValid: !0
2655
+ }
2656
+ ];
2657
+ tt.initialize();
2658
+ tt.connectToDevTools();