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