@zoralabs/protocol-deployments 0.3.5-COMMENTS.3 → 0.3.5

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