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