anycodex 0.0.11 → 0.0.13

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