@kizenapps/cli 0.3.0 → 0.5.0

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