@lynx-js/devtool-connector 0.13.1 → 0.16.2

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 (76) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +1 -1
  3. package/README.md +18 -134
  4. package/dist/2.js +2019 -0
  5. package/dist/{346.js → a.js} +102 -143
  6. package/dist/client-id.d.ts +0 -6
  7. package/dist/command/client.d.ts +8 -7
  8. package/dist/command/contract.d.ts +82 -24
  9. package/dist/command/core.d.ts +11 -10
  10. package/dist/command/in-process-client.d.ts +16 -0
  11. package/dist/command/index.d.ts +28 -20
  12. package/dist/command/index.js +177 -159
  13. package/dist/command/list-clients.d.ts +6 -0
  14. package/dist/command/list-sessions.d.ts +5 -0
  15. package/dist/command/open.d.ts +5 -0
  16. package/dist/command/query.d.ts +1 -1
  17. package/dist/command/reactlynx/controller.d.ts +3 -3
  18. package/dist/command/reactlynx/model.d.ts +7 -7
  19. package/dist/command/reactlynx/protocol.d.ts +0 -1
  20. package/dist/command/reactlynx/session.d.ts +3 -3
  21. package/dist/command/reactlynx/types.d.ts +7 -7
  22. package/dist/command/ref-actions.d.ts +4 -4
  23. package/dist/command/result.d.ts +0 -1
  24. package/dist/command/screenshot-annotation.d.ts +2 -2
  25. package/dist/command/screenshot.d.ts +2 -2
  26. package/dist/command/snapshot.d.ts +2 -2
  27. package/dist/command/source-info.d.ts +20 -0
  28. package/dist/command/targets.d.ts +8 -10
  29. package/dist/command/timeout.d.ts +3 -0
  30. package/dist/command/wait-for-client.d.ts +5 -0
  31. package/dist/daemon/device-connection.d.ts +4 -3
  32. package/dist/daemon/entry.js +18 -20
  33. package/dist/daemon/index.d.ts +7 -2
  34. package/dist/daemon/index.js +7 -3
  35. package/dist/daemon/inspector-assets.d.ts +11 -0
  36. package/dist/daemon/manager.d.ts +12 -4
  37. package/dist/daemon/protocol.d.ts +20 -16
  38. package/dist/daemon/server.d.ts +7 -1
  39. package/dist/daemon/static-server.d.ts +3 -1
  40. package/dist/f.js +5790 -0
  41. package/dist/f1.js +737 -0
  42. package/dist/{962.js → h.js} +841 -3259
  43. package/dist/{712.js → hb.js} +26 -19
  44. package/dist/i.js +2505 -0
  45. package/dist/index.d.ts +13 -18
  46. package/dist/index.js +3 -2
  47. package/dist/main.d.ts +2 -0
  48. package/dist/main.js +3 -0
  49. package/dist/request-id.d.ts +1 -0
  50. package/dist/streams/cdp.d.ts +3 -3
  51. package/dist/streams/customized.d.ts +5 -5
  52. package/dist/streams/index.d.ts +4 -3
  53. package/dist/streams/index.js +1 -1
  54. package/dist/streams/utils.d.ts +3 -3
  55. package/dist/{872.js → t.js} +364 -301
  56. package/dist/transport/adb-shell-types.d.ts +14 -0
  57. package/dist/transport/android-app-icon-helper.d.ts +1 -0
  58. package/dist/transport/android.d.ts +13 -3
  59. package/dist/transport/base.d.ts +2 -9
  60. package/dist/transport/daemon.d.ts +3 -2
  61. package/dist/transport/desktop.d.ts +1 -1
  62. package/dist/transport/hdt.d.ts +13 -0
  63. package/dist/transport/index.d.ts +9 -9
  64. package/dist/transport/index.js +2 -3
  65. package/dist/transport/ios.d.ts +2 -2
  66. package/dist/transport/peertalk.d.ts +4 -3
  67. package/dist/transport/stream-lifecycle.d.ts +4 -0
  68. package/dist/transport/transport.d.ts +4 -8
  69. package/dist/transport/usbmux.d.ts +5 -5
  70. package/dist/transport/ws-stream.d.ts +3 -10
  71. package/dist/types.d.ts +27 -54
  72. package/dist/{63.js → ws-stream.js} +23 -24
  73. package/package.json +32 -22
  74. package/dist/390.js +0 -329
  75. package/dist/556.js +0 -258
  76. package/dist/61.js +0 -3432
package/dist/i.js ADDED
@@ -0,0 +1,2505 @@
1
+ import { __webpack_require__ } from "./rslib-runtime.js";
2
+ import "./f1.js";
3
+ import { createRequire as __rspack_createRequire } from "node:module";
4
+ const __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
5
+ __webpack_require__.add({
6
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/buffer-util.js" (module, __unused_rspack_exports, __webpack_require__) {
7
+ const { EMPTY_BUFFER } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
8
+ const FastBuffer = Buffer[Symbol.species];
9
+ function concat(list, totalLength) {
10
+ if (0 === list.length) return EMPTY_BUFFER;
11
+ if (1 === list.length) return list[0];
12
+ const target = Buffer.allocUnsafe(totalLength);
13
+ let offset = 0;
14
+ for(let i = 0; i < list.length; i++){
15
+ const buf = list[i];
16
+ target.set(buf, offset);
17
+ offset += buf.length;
18
+ }
19
+ if (offset < totalLength) return new FastBuffer(target.buffer, target.byteOffset, offset);
20
+ return target;
21
+ }
22
+ function _mask(source, mask, output, offset, length) {
23
+ for(let i = 0; i < length; i++)output[offset + i] = source[i] ^ mask[3 & i];
24
+ }
25
+ function _unmask(buffer, mask) {
26
+ for(let i = 0; i < buffer.length; i++)buffer[i] ^= mask[3 & i];
27
+ }
28
+ function toArrayBuffer(buf) {
29
+ if (buf.length === buf.buffer.byteLength) return buf.buffer;
30
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
31
+ }
32
+ function toBuffer(data) {
33
+ toBuffer.readOnly = true;
34
+ if (Buffer.isBuffer(data)) return data;
35
+ let buf;
36
+ if (data instanceof ArrayBuffer) buf = new FastBuffer(data);
37
+ else if (ArrayBuffer.isView(data)) buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
38
+ else {
39
+ buf = Buffer.from(data);
40
+ toBuffer.readOnly = false;
41
+ }
42
+ return buf;
43
+ }
44
+ module.exports = {
45
+ concat,
46
+ mask: _mask,
47
+ toArrayBuffer,
48
+ toBuffer,
49
+ unmask: _unmask
50
+ };
51
+ if (!process.env.WS_NO_BUFFER_UTIL) try {
52
+ const bufferUtil = __webpack_require__("bufferutil");
53
+ module.exports.mask = function(source, mask, output, offset, length) {
54
+ if (length < 48) _mask(source, mask, output, offset, length);
55
+ else bufferUtil.mask(source, mask, output, offset, length);
56
+ };
57
+ module.exports.unmask = function(buffer, mask) {
58
+ if (buffer.length < 32) _unmask(buffer, mask);
59
+ else bufferUtil.unmask(buffer, mask);
60
+ };
61
+ } catch (e) {}
62
+ },
63
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js" (module) {
64
+ const BINARY_TYPES = [
65
+ 'nodebuffer',
66
+ 'arraybuffer',
67
+ 'fragments'
68
+ ];
69
+ const hasBlob = "u" > typeof Blob;
70
+ if (hasBlob) BINARY_TYPES.push('blob');
71
+ module.exports = {
72
+ BINARY_TYPES,
73
+ CLOSE_TIMEOUT: 30000,
74
+ EMPTY_BUFFER: Buffer.alloc(0),
75
+ GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
76
+ hasBlob,
77
+ kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
78
+ kListener: Symbol('kListener'),
79
+ kStatusCode: Symbol('status-code'),
80
+ kWebSocket: Symbol('websocket'),
81
+ NOOP: ()=>{}
82
+ };
83
+ },
84
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/event-target.js" (module, __unused_rspack_exports, __webpack_require__) {
85
+ const { kForOnEventAttribute, kListener } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
86
+ const kCode = Symbol('kCode');
87
+ const kData = Symbol('kData');
88
+ const kError = Symbol('kError');
89
+ const kMessage = Symbol('kMessage');
90
+ const kReason = Symbol('kReason');
91
+ const kTarget = Symbol('kTarget');
92
+ const kType = Symbol('kType');
93
+ const kWasClean = Symbol('kWasClean');
94
+ class Event {
95
+ constructor(type){
96
+ this[kTarget] = null;
97
+ this[kType] = type;
98
+ }
99
+ get target() {
100
+ return this[kTarget];
101
+ }
102
+ get type() {
103
+ return this[kType];
104
+ }
105
+ }
106
+ Object.defineProperty(Event.prototype, 'target', {
107
+ enumerable: true
108
+ });
109
+ Object.defineProperty(Event.prototype, 'type', {
110
+ enumerable: true
111
+ });
112
+ class CloseEvent extends Event {
113
+ constructor(type, options = {}){
114
+ super(type);
115
+ this[kCode] = void 0 === options.code ? 0 : options.code;
116
+ this[kReason] = void 0 === options.reason ? '' : options.reason;
117
+ this[kWasClean] = void 0 === options.wasClean ? false : options.wasClean;
118
+ }
119
+ get code() {
120
+ return this[kCode];
121
+ }
122
+ get reason() {
123
+ return this[kReason];
124
+ }
125
+ get wasClean() {
126
+ return this[kWasClean];
127
+ }
128
+ }
129
+ Object.defineProperty(CloseEvent.prototype, 'code', {
130
+ enumerable: true
131
+ });
132
+ Object.defineProperty(CloseEvent.prototype, 'reason', {
133
+ enumerable: true
134
+ });
135
+ Object.defineProperty(CloseEvent.prototype, 'wasClean', {
136
+ enumerable: true
137
+ });
138
+ class ErrorEvent extends Event {
139
+ constructor(type, options = {}){
140
+ super(type);
141
+ this[kError] = void 0 === options.error ? null : options.error;
142
+ this[kMessage] = void 0 === options.message ? '' : options.message;
143
+ }
144
+ get error() {
145
+ return this[kError];
146
+ }
147
+ get message() {
148
+ return this[kMessage];
149
+ }
150
+ }
151
+ Object.defineProperty(ErrorEvent.prototype, 'error', {
152
+ enumerable: true
153
+ });
154
+ Object.defineProperty(ErrorEvent.prototype, 'message', {
155
+ enumerable: true
156
+ });
157
+ class MessageEvent extends Event {
158
+ constructor(type, options = {}){
159
+ super(type);
160
+ this[kData] = void 0 === options.data ? null : options.data;
161
+ }
162
+ get data() {
163
+ return this[kData];
164
+ }
165
+ }
166
+ Object.defineProperty(MessageEvent.prototype, 'data', {
167
+ enumerable: true
168
+ });
169
+ const EventTarget = {
170
+ addEventListener (type, handler, options = {}) {
171
+ for (const listener of this.listeners(type))if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) return;
172
+ let wrapper;
173
+ if ('message' === type) wrapper = function(data, isBinary) {
174
+ const event = new MessageEvent('message', {
175
+ data: isBinary ? data : data.toString()
176
+ });
177
+ event[kTarget] = this;
178
+ callListener(handler, this, event);
179
+ };
180
+ else if ('close' === type) wrapper = function(code, message) {
181
+ const event = new CloseEvent('close', {
182
+ code,
183
+ reason: message.toString(),
184
+ wasClean: this._closeFrameReceived && this._closeFrameSent
185
+ });
186
+ event[kTarget] = this;
187
+ callListener(handler, this, event);
188
+ };
189
+ else if ('error' === type) wrapper = function(error) {
190
+ const event = new ErrorEvent('error', {
191
+ error,
192
+ message: error.message
193
+ });
194
+ event[kTarget] = this;
195
+ callListener(handler, this, event);
196
+ };
197
+ else {
198
+ if ('open' !== type) return;
199
+ wrapper = function() {
200
+ const event = new Event('open');
201
+ event[kTarget] = this;
202
+ callListener(handler, this, event);
203
+ };
204
+ }
205
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
206
+ wrapper[kListener] = handler;
207
+ if (options.once) this.once(type, wrapper);
208
+ else this.on(type, wrapper);
209
+ },
210
+ removeEventListener (type, handler) {
211
+ for (const listener of this.listeners(type))if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
212
+ this.removeListener(type, listener);
213
+ break;
214
+ }
215
+ }
216
+ };
217
+ module.exports = {
218
+ CloseEvent,
219
+ ErrorEvent,
220
+ Event,
221
+ EventTarget,
222
+ MessageEvent
223
+ };
224
+ function callListener(listener, thisArg, event) {
225
+ if ('object' == typeof listener && listener.handleEvent) listener.handleEvent.call(listener, event);
226
+ else listener.call(thisArg, event);
227
+ }
228
+ },
229
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/extension.js" (module, __unused_rspack_exports, __webpack_require__) {
230
+ const { tokenChars } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/validation.js");
231
+ function push(dest, name, elem) {
232
+ if (void 0 === dest[name]) dest[name] = [
233
+ elem
234
+ ];
235
+ else dest[name].push(elem);
236
+ }
237
+ function parse(header) {
238
+ const offers = Object.create(null);
239
+ let params = Object.create(null);
240
+ let mustUnescape = false;
241
+ let isEscaping = false;
242
+ let inQuotes = false;
243
+ let extensionName;
244
+ let paramName;
245
+ let start = -1;
246
+ let code = -1;
247
+ let end = -1;
248
+ let i = 0;
249
+ for(; i < header.length; i++){
250
+ code = header.charCodeAt(i);
251
+ if (void 0 === extensionName) if (-1 === end && 1 === tokenChars[code]) {
252
+ if (-1 === start) start = i;
253
+ } else if (0 !== i && (0x20 === code || 0x09 === code)) {
254
+ if (-1 === end && -1 !== start) end = i;
255
+ } else if (0x3b === code || 0x2c === code) {
256
+ if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
257
+ if (-1 === end) end = i;
258
+ const name = header.slice(start, end);
259
+ if (0x2c === code) {
260
+ push(offers, name, params);
261
+ params = Object.create(null);
262
+ } else extensionName = name;
263
+ start = end = -1;
264
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
265
+ else if (void 0 === paramName) if (-1 === end && 1 === tokenChars[code]) {
266
+ if (-1 === start) start = i;
267
+ } else if (0x20 === code || 0x09 === code) {
268
+ if (-1 === end && -1 !== start) end = i;
269
+ } else if (0x3b === code || 0x2c === code) {
270
+ if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
271
+ if (-1 === end) end = i;
272
+ push(params, header.slice(start, end), true);
273
+ if (0x2c === code) {
274
+ push(offers, extensionName, params);
275
+ params = Object.create(null);
276
+ extensionName = void 0;
277
+ }
278
+ start = end = -1;
279
+ } else if (0x3d === code && -1 !== start && -1 === end) {
280
+ paramName = header.slice(start, i);
281
+ start = end = -1;
282
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
283
+ else if (isEscaping) {
284
+ if (1 !== tokenChars[code]) throw new SyntaxError(`Unexpected character at index ${i}`);
285
+ if (-1 === start) start = i;
286
+ else if (!mustUnescape) mustUnescape = true;
287
+ isEscaping = false;
288
+ } else if (inQuotes) if (1 === tokenChars[code]) {
289
+ if (-1 === start) start = i;
290
+ } else if (0x22 === code && -1 !== start) {
291
+ inQuotes = false;
292
+ end = i;
293
+ } else if (0x5c === code) isEscaping = true;
294
+ else throw new SyntaxError(`Unexpected character at index ${i}`);
295
+ else if (0x22 === code && 0x3d === header.charCodeAt(i - 1)) inQuotes = true;
296
+ else if (-1 === end && 1 === tokenChars[code]) {
297
+ if (-1 === start) start = i;
298
+ } else if (-1 !== start && (0x20 === code || 0x09 === code)) {
299
+ if (-1 === end) end = i;
300
+ } else if (0x3b === code || 0x2c === code) {
301
+ if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
302
+ if (-1 === end) end = i;
303
+ let value = header.slice(start, end);
304
+ if (mustUnescape) {
305
+ value = value.replace(/\\/g, '');
306
+ mustUnescape = false;
307
+ }
308
+ push(params, paramName, value);
309
+ if (0x2c === code) {
310
+ push(offers, extensionName, params);
311
+ params = Object.create(null);
312
+ extensionName = void 0;
313
+ }
314
+ paramName = void 0;
315
+ start = end = -1;
316
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
317
+ }
318
+ if (-1 === start || inQuotes || 0x20 === code || 0x09 === code) throw new SyntaxError('Unexpected end of input');
319
+ if (-1 === end) end = i;
320
+ const token = header.slice(start, end);
321
+ if (void 0 === extensionName) push(offers, token, params);
322
+ else {
323
+ if (void 0 === paramName) push(params, token, true);
324
+ else mustUnescape ? push(params, paramName, token.replace(/\\/g, '')) : push(params, paramName, token);
325
+ push(offers, extensionName, params);
326
+ }
327
+ return offers;
328
+ }
329
+ function format(extensions) {
330
+ return Object.keys(extensions).map((extension)=>{
331
+ let configurations = extensions[extension];
332
+ if (!Array.isArray(configurations)) configurations = [
333
+ configurations
334
+ ];
335
+ return configurations.map((params)=>[
336
+ extension
337
+ ].concat(Object.keys(params).map((k)=>{
338
+ let values = params[k];
339
+ if (!Array.isArray(values)) values = [
340
+ values
341
+ ];
342
+ return values.map((v)=>true === v ? k : `${k}=${v}`).join('; ');
343
+ })).join('; ')).join(', ');
344
+ }).join(', ');
345
+ }
346
+ module.exports = {
347
+ format,
348
+ parse
349
+ };
350
+ },
351
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/limiter.js" (module) {
352
+ const kDone = Symbol('kDone');
353
+ const kRun = Symbol('kRun');
354
+ class Limiter {
355
+ constructor(concurrency){
356
+ this[kDone] = ()=>{
357
+ this.pending--;
358
+ this[kRun]();
359
+ };
360
+ this.concurrency = concurrency || 1 / 0;
361
+ this.jobs = [];
362
+ this.pending = 0;
363
+ }
364
+ add(job) {
365
+ this.jobs.push(job);
366
+ this[kRun]();
367
+ }
368
+ [kRun]() {
369
+ if (this.pending === this.concurrency) return;
370
+ if (this.jobs.length) {
371
+ const job = this.jobs.shift();
372
+ this.pending++;
373
+ job(this[kDone]);
374
+ }
375
+ }
376
+ }
377
+ module.exports = Limiter;
378
+ },
379
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/permessage-deflate.js" (module, __unused_rspack_exports, __webpack_require__) {
380
+ const zlib = __rspack_createRequire_require("zlib");
381
+ const bufferUtil = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/buffer-util.js");
382
+ const Limiter = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/limiter.js");
383
+ const { kStatusCode } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
384
+ const FastBuffer = Buffer[Symbol.species];
385
+ const TRAILER = Buffer.from([
386
+ 0x00,
387
+ 0x00,
388
+ 0xff,
389
+ 0xff
390
+ ]);
391
+ const kPerMessageDeflate = Symbol('permessage-deflate');
392
+ const kTotalLength = Symbol('total-length');
393
+ const kCallback = Symbol('callback');
394
+ const kBuffers = Symbol('buffers');
395
+ const kError = Symbol('error');
396
+ let zlibLimiter;
397
+ class PerMessageDeflate {
398
+ constructor(options){
399
+ this._options = options || {};
400
+ this._threshold = void 0 !== this._options.threshold ? this._options.threshold : 1024;
401
+ this._maxPayload = 0 | this._options.maxPayload;
402
+ this._isServer = !!this._options.isServer;
403
+ this._deflate = null;
404
+ this._inflate = null;
405
+ this.params = null;
406
+ if (!zlibLimiter) {
407
+ const concurrency = void 0 !== this._options.concurrencyLimit ? this._options.concurrencyLimit : 10;
408
+ zlibLimiter = new Limiter(concurrency);
409
+ }
410
+ }
411
+ static get extensionName() {
412
+ return 'permessage-deflate';
413
+ }
414
+ offer() {
415
+ const params = {};
416
+ if (this._options.serverNoContextTakeover) params.server_no_context_takeover = true;
417
+ if (this._options.clientNoContextTakeover) params.client_no_context_takeover = true;
418
+ if (this._options.serverMaxWindowBits) params.server_max_window_bits = this._options.serverMaxWindowBits;
419
+ if (this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
420
+ else if (null == this._options.clientMaxWindowBits) params.client_max_window_bits = true;
421
+ return params;
422
+ }
423
+ accept(configurations) {
424
+ configurations = this.normalizeParams(configurations);
425
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
426
+ return this.params;
427
+ }
428
+ cleanup() {
429
+ if (this._inflate) {
430
+ this._inflate.close();
431
+ this._inflate = null;
432
+ }
433
+ if (this._deflate) {
434
+ const callback = this._deflate[kCallback];
435
+ this._deflate.close();
436
+ this._deflate = null;
437
+ if (callback) callback(new Error('The deflate stream was closed while data was being processed'));
438
+ }
439
+ }
440
+ acceptAsServer(offers) {
441
+ const opts = this._options;
442
+ const accepted = offers.find((params)=>{
443
+ if (false === opts.serverNoContextTakeover && params.server_no_context_takeover || params.server_max_window_bits && (false === opts.serverMaxWindowBits || 'number' == typeof opts.serverMaxWindowBits && opts.serverMaxWindowBits > params.server_max_window_bits) || 'number' == typeof opts.clientMaxWindowBits && ('number' == typeof params.client_max_window_bits ? opts.clientMaxWindowBits > params.client_max_window_bits : !params.client_max_window_bits)) return false;
444
+ return true;
445
+ });
446
+ if (!accepted) throw new Error('None of the extension offers can be accepted');
447
+ if (opts.serverNoContextTakeover) accepted.server_no_context_takeover = true;
448
+ if (opts.clientNoContextTakeover) accepted.client_no_context_takeover = true;
449
+ if ('number' == typeof opts.serverMaxWindowBits) accepted.server_max_window_bits = opts.serverMaxWindowBits;
450
+ if ('number' == typeof opts.clientMaxWindowBits) accepted.client_max_window_bits = opts.clientMaxWindowBits;
451
+ else if (true === accepted.client_max_window_bits || false === opts.clientMaxWindowBits) delete accepted.client_max_window_bits;
452
+ return accepted;
453
+ }
454
+ acceptAsClient(response) {
455
+ const params = response[0];
456
+ if (false === this._options.clientNoContextTakeover && params.client_no_context_takeover) throw new Error('Unexpected parameter "client_no_context_takeover"');
457
+ if (params.client_max_window_bits) {
458
+ if (false === this._options.clientMaxWindowBits || 'number' == typeof this._options.clientMaxWindowBits && params.client_max_window_bits > this._options.clientMaxWindowBits) throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
459
+ } else if ('number' == typeof this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
460
+ return params;
461
+ }
462
+ normalizeParams(configurations) {
463
+ configurations.forEach((params)=>{
464
+ Object.keys(params).forEach((key)=>{
465
+ let value = params[key];
466
+ if (value.length > 1) throw new Error(`Parameter "${key}" must have only a single value`);
467
+ value = value[0];
468
+ if ('client_max_window_bits' === key) {
469
+ if (true !== value) {
470
+ const num = +value;
471
+ if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
472
+ value = num;
473
+ } else if (!this._isServer) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
474
+ } else if ('server_max_window_bits' === key) {
475
+ const num = +value;
476
+ if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
477
+ value = num;
478
+ } else if ('client_no_context_takeover' === key || 'server_no_context_takeover' === key) {
479
+ if (true !== value) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
480
+ } else throw new Error(`Unknown parameter "${key}"`);
481
+ params[key] = value;
482
+ });
483
+ });
484
+ return configurations;
485
+ }
486
+ decompress(data, fin, callback) {
487
+ zlibLimiter.add((done)=>{
488
+ this._decompress(data, fin, (err, result)=>{
489
+ done();
490
+ callback(err, result);
491
+ });
492
+ });
493
+ }
494
+ compress(data, fin, callback) {
495
+ zlibLimiter.add((done)=>{
496
+ this._compress(data, fin, (err, result)=>{
497
+ done();
498
+ callback(err, result);
499
+ });
500
+ });
501
+ }
502
+ _decompress(data, fin, callback) {
503
+ const endpoint = this._isServer ? 'client' : 'server';
504
+ if (!this._inflate) {
505
+ const key = `${endpoint}_max_window_bits`;
506
+ const windowBits = 'number' != typeof this.params[key] ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
507
+ this._inflate = zlib.createInflateRaw({
508
+ ...this._options.zlibInflateOptions,
509
+ windowBits
510
+ });
511
+ this._inflate[kPerMessageDeflate] = this;
512
+ this._inflate[kTotalLength] = 0;
513
+ this._inflate[kBuffers] = [];
514
+ this._inflate.on('error', inflateOnError);
515
+ this._inflate.on('data', inflateOnData);
516
+ }
517
+ this._inflate[kCallback] = callback;
518
+ this._inflate.write(data);
519
+ if (fin) this._inflate.write(TRAILER);
520
+ this._inflate.flush(()=>{
521
+ const err = this._inflate[kError];
522
+ if (err) {
523
+ this._inflate.close();
524
+ this._inflate = null;
525
+ callback(err);
526
+ return;
527
+ }
528
+ const data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
529
+ if (this._inflate._readableState.endEmitted) {
530
+ this._inflate.close();
531
+ this._inflate = null;
532
+ } else {
533
+ this._inflate[kTotalLength] = 0;
534
+ this._inflate[kBuffers] = [];
535
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) this._inflate.reset();
536
+ }
537
+ callback(null, data);
538
+ });
539
+ }
540
+ _compress(data, fin, callback) {
541
+ const endpoint = this._isServer ? 'server' : 'client';
542
+ if (!this._deflate) {
543
+ const key = `${endpoint}_max_window_bits`;
544
+ const windowBits = 'number' != typeof this.params[key] ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
545
+ this._deflate = zlib.createDeflateRaw({
546
+ ...this._options.zlibDeflateOptions,
547
+ windowBits
548
+ });
549
+ this._deflate[kTotalLength] = 0;
550
+ this._deflate[kBuffers] = [];
551
+ this._deflate.on('data', deflateOnData);
552
+ }
553
+ this._deflate[kCallback] = callback;
554
+ this._deflate.write(data);
555
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, ()=>{
556
+ if (!this._deflate) return;
557
+ let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
558
+ if (fin) data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
559
+ this._deflate[kCallback] = null;
560
+ this._deflate[kTotalLength] = 0;
561
+ this._deflate[kBuffers] = [];
562
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) this._deflate.reset();
563
+ callback(null, data);
564
+ });
565
+ }
566
+ }
567
+ module.exports = PerMessageDeflate;
568
+ function deflateOnData(chunk) {
569
+ this[kBuffers].push(chunk);
570
+ this[kTotalLength] += chunk.length;
571
+ }
572
+ function inflateOnData(chunk) {
573
+ this[kTotalLength] += chunk.length;
574
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) return void this[kBuffers].push(chunk);
575
+ this[kError] = new RangeError('Max payload size exceeded');
576
+ this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
577
+ this[kError][kStatusCode] = 1009;
578
+ this.removeListener('data', inflateOnData);
579
+ this.reset();
580
+ }
581
+ function inflateOnError(err) {
582
+ this[kPerMessageDeflate]._inflate = null;
583
+ if (this[kError]) return void this[kCallback](this[kError]);
584
+ err[kStatusCode] = 1007;
585
+ this[kCallback](err);
586
+ }
587
+ },
588
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/receiver.js" (module, __unused_rspack_exports, __webpack_require__) {
589
+ const { Writable } = __rspack_createRequire_require("stream");
590
+ const PerMessageDeflate = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/permessage-deflate.js");
591
+ const { BINARY_TYPES, EMPTY_BUFFER, kStatusCode, kWebSocket } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
592
+ const { concat, toArrayBuffer, unmask } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/buffer-util.js");
593
+ const { isValidStatusCode, isValidUTF8 } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/validation.js");
594
+ const FastBuffer = Buffer[Symbol.species];
595
+ const GET_INFO = 0;
596
+ const GET_PAYLOAD_LENGTH_16 = 1;
597
+ const GET_PAYLOAD_LENGTH_64 = 2;
598
+ const GET_MASK = 3;
599
+ const GET_DATA = 4;
600
+ const INFLATING = 5;
601
+ const DEFER_EVENT = 6;
602
+ class Receiver extends Writable {
603
+ constructor(options = {}){
604
+ super();
605
+ this._allowSynchronousEvents = void 0 !== options.allowSynchronousEvents ? options.allowSynchronousEvents : true;
606
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
607
+ this._extensions = options.extensions || {};
608
+ this._isServer = !!options.isServer;
609
+ this._maxBufferedChunks = 0 | options.maxBufferedChunks;
610
+ this._maxFragments = 0 | options.maxFragments;
611
+ this._maxPayload = 0 | options.maxPayload;
612
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
613
+ this[kWebSocket] = void 0;
614
+ this._bufferedBytes = 0;
615
+ this._buffers = [];
616
+ this._compressed = false;
617
+ this._payloadLength = 0;
618
+ this._mask = void 0;
619
+ this._fragmented = 0;
620
+ this._masked = false;
621
+ this._fin = false;
622
+ this._opcode = 0;
623
+ this._totalPayloadLength = 0;
624
+ this._messageLength = 0;
625
+ this._numFragments = 0;
626
+ this._fragments = [];
627
+ this._errored = false;
628
+ this._loop = false;
629
+ this._state = GET_INFO;
630
+ }
631
+ _write(chunk, encoding, cb) {
632
+ if (0x08 === this._opcode && this._state == GET_INFO) return cb();
633
+ if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) return void cb(this.createError(RangeError, 'Too many buffered chunks', false, 1008, 'WS_ERR_TOO_MANY_BUFFERED_PARTS'));
634
+ this._bufferedBytes += chunk.length;
635
+ this._buffers.push(chunk);
636
+ this.startLoop(cb);
637
+ }
638
+ consume(n) {
639
+ this._bufferedBytes -= n;
640
+ if (n === this._buffers[0].length) return this._buffers.shift();
641
+ if (n < this._buffers[0].length) {
642
+ const buf = this._buffers[0];
643
+ this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
644
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
645
+ }
646
+ const dst = Buffer.allocUnsafe(n);
647
+ do {
648
+ const buf = this._buffers[0];
649
+ const offset = dst.length - n;
650
+ if (n >= buf.length) dst.set(this._buffers.shift(), offset);
651
+ else {
652
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
653
+ this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
654
+ }
655
+ n -= buf.length;
656
+ }while (n > 0);
657
+ return dst;
658
+ }
659
+ startLoop(cb) {
660
+ this._loop = true;
661
+ do switch(this._state){
662
+ case GET_INFO:
663
+ this.getInfo(cb);
664
+ break;
665
+ case GET_PAYLOAD_LENGTH_16:
666
+ this.getPayloadLength16(cb);
667
+ break;
668
+ case GET_PAYLOAD_LENGTH_64:
669
+ this.getPayloadLength64(cb);
670
+ break;
671
+ case GET_MASK:
672
+ this.getMask();
673
+ break;
674
+ case GET_DATA:
675
+ this.getData(cb);
676
+ break;
677
+ case INFLATING:
678
+ case DEFER_EVENT:
679
+ this._loop = false;
680
+ return;
681
+ }
682
+ while (this._loop);
683
+ if (!this._errored) cb();
684
+ }
685
+ getInfo(cb) {
686
+ if (this._bufferedBytes < 2) {
687
+ this._loop = false;
688
+ return;
689
+ }
690
+ const buf = this.consume(2);
691
+ if ((0x30 & buf[0]) !== 0x00) {
692
+ const error = this.createError(RangeError, 'RSV2 and RSV3 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_2_3');
693
+ cb(error);
694
+ return;
695
+ }
696
+ const compressed = (0x40 & buf[0]) === 0x40;
697
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
698
+ const error = this.createError(RangeError, 'RSV1 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_1');
699
+ cb(error);
700
+ return;
701
+ }
702
+ this._fin = (0x80 & buf[0]) === 0x80;
703
+ this._opcode = 0x0f & buf[0];
704
+ this._payloadLength = 0x7f & buf[1];
705
+ if (0x00 === this._opcode) {
706
+ if (compressed) {
707
+ const error = this.createError(RangeError, 'RSV1 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_1');
708
+ cb(error);
709
+ return;
710
+ }
711
+ if (!this._fragmented) {
712
+ const error = this.createError(RangeError, 'invalid opcode 0', true, 1002, 'WS_ERR_INVALID_OPCODE');
713
+ cb(error);
714
+ return;
715
+ }
716
+ this._opcode = this._fragmented;
717
+ } else if (0x01 === this._opcode || 0x02 === this._opcode) {
718
+ if (this._fragmented) {
719
+ const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, 'WS_ERR_INVALID_OPCODE');
720
+ cb(error);
721
+ return;
722
+ }
723
+ this._compressed = compressed;
724
+ } else if (this._opcode > 0x07 && this._opcode < 0x0b) {
725
+ if (!this._fin) {
726
+ const error = this.createError(RangeError, 'FIN must be set', true, 1002, 'WS_ERR_EXPECTED_FIN');
727
+ cb(error);
728
+ return;
729
+ }
730
+ if (compressed) {
731
+ const error = this.createError(RangeError, 'RSV1 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_1');
732
+ cb(error);
733
+ return;
734
+ }
735
+ if (this._payloadLength > 0x7d || 0x08 === this._opcode && 1 === this._payloadLength) {
736
+ const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH');
737
+ cb(error);
738
+ return;
739
+ }
740
+ } else {
741
+ const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, 'WS_ERR_INVALID_OPCODE');
742
+ cb(error);
743
+ return;
744
+ }
745
+ if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
746
+ this._masked = (0x80 & buf[1]) === 0x80;
747
+ if (this._isServer) {
748
+ if (!this._masked) {
749
+ const error = this.createError(RangeError, 'MASK must be set', true, 1002, 'WS_ERR_EXPECTED_MASK');
750
+ cb(error);
751
+ return;
752
+ }
753
+ } else if (this._masked) {
754
+ const error = this.createError(RangeError, 'MASK must be clear', true, 1002, 'WS_ERR_UNEXPECTED_MASK');
755
+ cb(error);
756
+ return;
757
+ }
758
+ if (126 === this._payloadLength) this._state = GET_PAYLOAD_LENGTH_16;
759
+ else if (127 === this._payloadLength) this._state = GET_PAYLOAD_LENGTH_64;
760
+ else this.haveLength(cb);
761
+ }
762
+ getPayloadLength16(cb) {
763
+ if (this._bufferedBytes < 2) {
764
+ this._loop = false;
765
+ return;
766
+ }
767
+ this._payloadLength = this.consume(2).readUInt16BE(0);
768
+ this.haveLength(cb);
769
+ }
770
+ getPayloadLength64(cb) {
771
+ if (this._bufferedBytes < 8) {
772
+ this._loop = false;
773
+ return;
774
+ }
775
+ const buf = this.consume(8);
776
+ const num = buf.readUInt32BE(0);
777
+ if (num > Math.pow(2, 21) - 1) {
778
+ const error = this.createError(RangeError, 'Unsupported WebSocket frame: payload length > 2^53 - 1', false, 1009, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH');
779
+ cb(error);
780
+ return;
781
+ }
782
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
783
+ this.haveLength(cb);
784
+ }
785
+ haveLength(cb) {
786
+ if (this._payloadLength && this._opcode < 0x08) {
787
+ this._totalPayloadLength += this._payloadLength;
788
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
789
+ const error = this.createError(RangeError, 'Max payload size exceeded', false, 1009, 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH');
790
+ cb(error);
791
+ return;
792
+ }
793
+ }
794
+ if (this._masked) this._state = GET_MASK;
795
+ else this._state = GET_DATA;
796
+ }
797
+ getMask() {
798
+ if (this._bufferedBytes < 4) {
799
+ this._loop = false;
800
+ return;
801
+ }
802
+ this._mask = this.consume(4);
803
+ this._state = GET_DATA;
804
+ }
805
+ getData(cb) {
806
+ let data = EMPTY_BUFFER;
807
+ if (this._payloadLength) {
808
+ if (this._bufferedBytes < this._payloadLength) {
809
+ this._loop = false;
810
+ return;
811
+ }
812
+ data = this.consume(this._payloadLength);
813
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
814
+ }
815
+ if (this._opcode > 0x07) return void this.controlMessage(data, cb);
816
+ if (this._maxFragments > 0 && ++this._numFragments > this._maxFragments) {
817
+ const error = this.createError(RangeError, 'Too many message fragments', false, 1008, 'WS_ERR_TOO_MANY_BUFFERED_PARTS');
818
+ cb(error);
819
+ return;
820
+ }
821
+ if (this._compressed) {
822
+ this._state = INFLATING;
823
+ this.decompress(data, cb);
824
+ return;
825
+ }
826
+ if (data.length) {
827
+ this._messageLength = this._totalPayloadLength;
828
+ this._fragments.push(data);
829
+ }
830
+ this.dataMessage(cb);
831
+ }
832
+ decompress(data, cb) {
833
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
834
+ perMessageDeflate.decompress(data, this._fin, (err, buf)=>{
835
+ if (err) return cb(err);
836
+ if (buf.length) {
837
+ this._messageLength += buf.length;
838
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
839
+ const error = this.createError(RangeError, 'Max payload size exceeded', false, 1009, 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH');
840
+ cb(error);
841
+ return;
842
+ }
843
+ this._fragments.push(buf);
844
+ }
845
+ this.dataMessage(cb);
846
+ if (this._state === GET_INFO) this.startLoop(cb);
847
+ });
848
+ }
849
+ dataMessage(cb) {
850
+ if (!this._fin) {
851
+ this._state = GET_INFO;
852
+ return;
853
+ }
854
+ const messageLength = this._messageLength;
855
+ const fragments = this._fragments;
856
+ this._totalPayloadLength = 0;
857
+ this._messageLength = 0;
858
+ this._fragmented = 0;
859
+ this._numFragments = 0;
860
+ this._fragments = [];
861
+ if (2 === this._opcode) {
862
+ let data;
863
+ data = 'nodebuffer' === this._binaryType ? concat(fragments, messageLength) : 'arraybuffer' === this._binaryType ? toArrayBuffer(concat(fragments, messageLength)) : 'blob' === this._binaryType ? new Blob(fragments) : fragments;
864
+ if (this._allowSynchronousEvents) {
865
+ this.emit('message', data, true);
866
+ this._state = GET_INFO;
867
+ } else {
868
+ this._state = DEFER_EVENT;
869
+ setImmediate(()=>{
870
+ this.emit('message', data, true);
871
+ this._state = GET_INFO;
872
+ this.startLoop(cb);
873
+ });
874
+ }
875
+ } else {
876
+ const buf = concat(fragments, messageLength);
877
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
878
+ const error = this.createError(Error, 'invalid UTF-8 sequence', true, 1007, 'WS_ERR_INVALID_UTF8');
879
+ cb(error);
880
+ return;
881
+ }
882
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
883
+ this.emit('message', buf, false);
884
+ this._state = GET_INFO;
885
+ } else {
886
+ this._state = DEFER_EVENT;
887
+ setImmediate(()=>{
888
+ this.emit('message', buf, false);
889
+ this._state = GET_INFO;
890
+ this.startLoop(cb);
891
+ });
892
+ }
893
+ }
894
+ }
895
+ controlMessage(data, cb) {
896
+ if (0x08 === this._opcode) {
897
+ if (0 === data.length) {
898
+ this._loop = false;
899
+ this.emit('conclude', 1005, EMPTY_BUFFER);
900
+ this.end();
901
+ } else {
902
+ const code = data.readUInt16BE(0);
903
+ if (!isValidStatusCode(code)) {
904
+ const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, 'WS_ERR_INVALID_CLOSE_CODE');
905
+ cb(error);
906
+ return;
907
+ }
908
+ const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
909
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
910
+ const error = this.createError(Error, 'invalid UTF-8 sequence', true, 1007, 'WS_ERR_INVALID_UTF8');
911
+ cb(error);
912
+ return;
913
+ }
914
+ this._loop = false;
915
+ this.emit('conclude', code, buf);
916
+ this.end();
917
+ }
918
+ this._state = GET_INFO;
919
+ return;
920
+ }
921
+ if (this._allowSynchronousEvents) {
922
+ this.emit(0x09 === this._opcode ? 'ping' : 'pong', data);
923
+ this._state = GET_INFO;
924
+ } else {
925
+ this._state = DEFER_EVENT;
926
+ setImmediate(()=>{
927
+ this.emit(0x09 === this._opcode ? 'ping' : 'pong', data);
928
+ this._state = GET_INFO;
929
+ this.startLoop(cb);
930
+ });
931
+ }
932
+ }
933
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
934
+ this._loop = false;
935
+ this._errored = true;
936
+ const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
937
+ Error.captureStackTrace(err, this.createError);
938
+ err.code = errorCode;
939
+ err[kStatusCode] = statusCode;
940
+ return err;
941
+ }
942
+ }
943
+ module.exports = Receiver;
944
+ },
945
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/sender.js" (module, __unused_rspack_exports, __webpack_require__) {
946
+ const { Duplex } = __rspack_createRequire_require("stream");
947
+ const { randomFillSync } = __rspack_createRequire_require("crypto");
948
+ const { types: { isUint8Array } } = __rspack_createRequire_require("util");
949
+ const PerMessageDeflate = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/permessage-deflate.js");
950
+ const { EMPTY_BUFFER, kWebSocket, NOOP } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
951
+ const { isBlob, isValidStatusCode } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/validation.js");
952
+ const { mask: applyMask, toBuffer } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/buffer-util.js");
953
+ const kByteLength = Symbol('kByteLength');
954
+ const maskBuffer = Buffer.alloc(4);
955
+ const RANDOM_POOL_SIZE = 8192;
956
+ let randomPool;
957
+ let randomPoolPointer = RANDOM_POOL_SIZE;
958
+ const DEFAULT = 0;
959
+ const DEFLATING = 1;
960
+ const GET_BLOB_DATA = 2;
961
+ class Sender {
962
+ constructor(socket, extensions, generateMask){
963
+ this._extensions = extensions || {};
964
+ if (generateMask) {
965
+ this._generateMask = generateMask;
966
+ this._maskBuffer = Buffer.alloc(4);
967
+ }
968
+ this._socket = socket;
969
+ this._firstFragment = true;
970
+ this._compress = false;
971
+ this._bufferedBytes = 0;
972
+ this._queue = [];
973
+ this._state = DEFAULT;
974
+ this.onerror = NOOP;
975
+ this[kWebSocket] = void 0;
976
+ }
977
+ static frame(data, options) {
978
+ let mask;
979
+ let merge = false;
980
+ let offset = 2;
981
+ let skipMasking = false;
982
+ if (options.mask) {
983
+ mask = options.maskBuffer || maskBuffer;
984
+ if (options.generateMask) options.generateMask(mask);
985
+ else {
986
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
987
+ if (void 0 === randomPool) randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
988
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
989
+ randomPoolPointer = 0;
990
+ }
991
+ mask[0] = randomPool[randomPoolPointer++];
992
+ mask[1] = randomPool[randomPoolPointer++];
993
+ mask[2] = randomPool[randomPoolPointer++];
994
+ mask[3] = randomPool[randomPoolPointer++];
995
+ }
996
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
997
+ offset = 6;
998
+ }
999
+ let dataLength;
1000
+ if ('string' == typeof data) if ((!options.mask || skipMasking) && void 0 !== options[kByteLength]) dataLength = options[kByteLength];
1001
+ else {
1002
+ data = Buffer.from(data);
1003
+ dataLength = data.length;
1004
+ }
1005
+ else {
1006
+ dataLength = data.length;
1007
+ merge = options.mask && options.readOnly && !skipMasking;
1008
+ }
1009
+ let payloadLength = dataLength;
1010
+ if (dataLength >= 65536) {
1011
+ offset += 8;
1012
+ payloadLength = 127;
1013
+ } else if (dataLength > 125) {
1014
+ offset += 2;
1015
+ payloadLength = 126;
1016
+ }
1017
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1018
+ target[0] = options.fin ? 0x80 | options.opcode : options.opcode;
1019
+ if (options.rsv1) target[0] |= 0x40;
1020
+ target[1] = payloadLength;
1021
+ if (126 === payloadLength) target.writeUInt16BE(dataLength, 2);
1022
+ else if (127 === payloadLength) {
1023
+ target[2] = target[3] = 0;
1024
+ target.writeUIntBE(dataLength, 4, 6);
1025
+ }
1026
+ if (!options.mask) return [
1027
+ target,
1028
+ data
1029
+ ];
1030
+ target[1] |= 0x80;
1031
+ target[offset - 4] = mask[0];
1032
+ target[offset - 3] = mask[1];
1033
+ target[offset - 2] = mask[2];
1034
+ target[offset - 1] = mask[3];
1035
+ if (skipMasking) return [
1036
+ target,
1037
+ data
1038
+ ];
1039
+ if (merge) {
1040
+ applyMask(data, mask, target, offset, dataLength);
1041
+ return [
1042
+ target
1043
+ ];
1044
+ }
1045
+ applyMask(data, mask, data, 0, dataLength);
1046
+ return [
1047
+ target,
1048
+ data
1049
+ ];
1050
+ }
1051
+ close(code, data, mask, cb) {
1052
+ let buf;
1053
+ if (void 0 === code) buf = EMPTY_BUFFER;
1054
+ else if ('number' == typeof code && isValidStatusCode(code)) if (void 0 !== data && data.length) {
1055
+ const length = Buffer.byteLength(data);
1056
+ if (length > 123) throw new RangeError('The message must not be greater than 123 bytes');
1057
+ buf = Buffer.allocUnsafe(2 + length);
1058
+ buf.writeUInt16BE(code, 0);
1059
+ if ('string' == typeof data) buf.write(data, 2);
1060
+ else if (isUint8Array(data)) buf.set(data, 2);
1061
+ else throw new TypeError('Second argument must be a string or a Uint8Array');
1062
+ } else {
1063
+ buf = Buffer.allocUnsafe(2);
1064
+ buf.writeUInt16BE(code, 0);
1065
+ }
1066
+ else throw new TypeError('First argument must be a valid error code number');
1067
+ const options = {
1068
+ [kByteLength]: buf.length,
1069
+ fin: true,
1070
+ generateMask: this._generateMask,
1071
+ mask,
1072
+ maskBuffer: this._maskBuffer,
1073
+ opcode: 0x08,
1074
+ readOnly: false,
1075
+ rsv1: false
1076
+ };
1077
+ if (this._state !== DEFAULT) this.enqueue([
1078
+ this.dispatch,
1079
+ buf,
1080
+ false,
1081
+ options,
1082
+ cb
1083
+ ]);
1084
+ else this.sendFrame(Sender.frame(buf, options), cb);
1085
+ }
1086
+ ping(data, mask, cb) {
1087
+ let byteLength;
1088
+ let readOnly;
1089
+ if ('string' == typeof data) {
1090
+ byteLength = Buffer.byteLength(data);
1091
+ readOnly = false;
1092
+ } else if (isBlob(data)) {
1093
+ byteLength = data.size;
1094
+ readOnly = false;
1095
+ } else {
1096
+ data = toBuffer(data);
1097
+ byteLength = data.length;
1098
+ readOnly = toBuffer.readOnly;
1099
+ }
1100
+ if (byteLength > 125) throw new RangeError('The data size must not be greater than 125 bytes');
1101
+ const options = {
1102
+ [kByteLength]: byteLength,
1103
+ fin: true,
1104
+ generateMask: this._generateMask,
1105
+ mask,
1106
+ maskBuffer: this._maskBuffer,
1107
+ opcode: 0x09,
1108
+ readOnly,
1109
+ rsv1: false
1110
+ };
1111
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
1112
+ this.getBlobData,
1113
+ data,
1114
+ false,
1115
+ options,
1116
+ cb
1117
+ ]);
1118
+ else this.getBlobData(data, false, options, cb);
1119
+ else if (this._state !== DEFAULT) this.enqueue([
1120
+ this.dispatch,
1121
+ data,
1122
+ false,
1123
+ options,
1124
+ cb
1125
+ ]);
1126
+ else this.sendFrame(Sender.frame(data, options), cb);
1127
+ }
1128
+ pong(data, mask, cb) {
1129
+ let byteLength;
1130
+ let readOnly;
1131
+ if ('string' == typeof data) {
1132
+ byteLength = Buffer.byteLength(data);
1133
+ readOnly = false;
1134
+ } else if (isBlob(data)) {
1135
+ byteLength = data.size;
1136
+ readOnly = false;
1137
+ } else {
1138
+ data = toBuffer(data);
1139
+ byteLength = data.length;
1140
+ readOnly = toBuffer.readOnly;
1141
+ }
1142
+ if (byteLength > 125) throw new RangeError('The data size must not be greater than 125 bytes');
1143
+ const options = {
1144
+ [kByteLength]: byteLength,
1145
+ fin: true,
1146
+ generateMask: this._generateMask,
1147
+ mask,
1148
+ maskBuffer: this._maskBuffer,
1149
+ opcode: 0x0a,
1150
+ readOnly,
1151
+ rsv1: false
1152
+ };
1153
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
1154
+ this.getBlobData,
1155
+ data,
1156
+ false,
1157
+ options,
1158
+ cb
1159
+ ]);
1160
+ else this.getBlobData(data, false, options, cb);
1161
+ else if (this._state !== DEFAULT) this.enqueue([
1162
+ this.dispatch,
1163
+ data,
1164
+ false,
1165
+ options,
1166
+ cb
1167
+ ]);
1168
+ else this.sendFrame(Sender.frame(data, options), cb);
1169
+ }
1170
+ send(data, options, cb) {
1171
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1172
+ let opcode = options.binary ? 2 : 1;
1173
+ let rsv1 = options.compress;
1174
+ let byteLength;
1175
+ let readOnly;
1176
+ if ('string' == typeof data) {
1177
+ byteLength = Buffer.byteLength(data);
1178
+ readOnly = false;
1179
+ } else if (isBlob(data)) {
1180
+ byteLength = data.size;
1181
+ readOnly = false;
1182
+ } else {
1183
+ data = toBuffer(data);
1184
+ byteLength = data.length;
1185
+ readOnly = toBuffer.readOnly;
1186
+ }
1187
+ if (this._firstFragment) {
1188
+ this._firstFragment = false;
1189
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? 'server_no_context_takeover' : 'client_no_context_takeover']) rsv1 = byteLength >= perMessageDeflate._threshold;
1190
+ this._compress = rsv1;
1191
+ } else {
1192
+ rsv1 = false;
1193
+ opcode = 0;
1194
+ }
1195
+ if (options.fin) this._firstFragment = true;
1196
+ const opts = {
1197
+ [kByteLength]: byteLength,
1198
+ fin: options.fin,
1199
+ generateMask: this._generateMask,
1200
+ mask: options.mask,
1201
+ maskBuffer: this._maskBuffer,
1202
+ opcode,
1203
+ readOnly,
1204
+ rsv1
1205
+ };
1206
+ if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
1207
+ this.getBlobData,
1208
+ data,
1209
+ this._compress,
1210
+ opts,
1211
+ cb
1212
+ ]);
1213
+ else this.getBlobData(data, this._compress, opts, cb);
1214
+ else if (this._state !== DEFAULT) this.enqueue([
1215
+ this.dispatch,
1216
+ data,
1217
+ this._compress,
1218
+ opts,
1219
+ cb
1220
+ ]);
1221
+ else this.dispatch(data, this._compress, opts, cb);
1222
+ }
1223
+ getBlobData(blob, compress, options, cb) {
1224
+ this._bufferedBytes += options[kByteLength];
1225
+ this._state = GET_BLOB_DATA;
1226
+ blob.arrayBuffer().then((arrayBuffer)=>{
1227
+ if (this._socket.destroyed) {
1228
+ const err = new Error('The socket was closed while the blob was being read');
1229
+ process.nextTick(callCallbacks, this, err, cb);
1230
+ return;
1231
+ }
1232
+ this._bufferedBytes -= options[kByteLength];
1233
+ const data = toBuffer(arrayBuffer);
1234
+ if (compress) this.dispatch(data, compress, options, cb);
1235
+ else {
1236
+ this._state = DEFAULT;
1237
+ this.sendFrame(Sender.frame(data, options), cb);
1238
+ this.dequeue();
1239
+ }
1240
+ }).catch((err)=>{
1241
+ process.nextTick(onError, this, err, cb);
1242
+ });
1243
+ }
1244
+ dispatch(data, compress, options, cb) {
1245
+ if (!compress) return void this.sendFrame(Sender.frame(data, options), cb);
1246
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1247
+ this._bufferedBytes += options[kByteLength];
1248
+ this._state = DEFLATING;
1249
+ perMessageDeflate.compress(data, options.fin, (_, buf)=>{
1250
+ if (this._socket.destroyed) {
1251
+ const err = new Error('The socket was closed while data was being compressed');
1252
+ callCallbacks(this, err, cb);
1253
+ return;
1254
+ }
1255
+ this._bufferedBytes -= options[kByteLength];
1256
+ this._state = DEFAULT;
1257
+ options.readOnly = false;
1258
+ this.sendFrame(Sender.frame(buf, options), cb);
1259
+ this.dequeue();
1260
+ });
1261
+ }
1262
+ dequeue() {
1263
+ while(this._state === DEFAULT && this._queue.length){
1264
+ const params = this._queue.shift();
1265
+ this._bufferedBytes -= params[3][kByteLength];
1266
+ Reflect.apply(params[0], this, params.slice(1));
1267
+ }
1268
+ }
1269
+ enqueue(params) {
1270
+ this._bufferedBytes += params[3][kByteLength];
1271
+ this._queue.push(params);
1272
+ }
1273
+ sendFrame(list, cb) {
1274
+ if (2 === list.length) {
1275
+ this._socket.cork();
1276
+ this._socket.write(list[0]);
1277
+ this._socket.write(list[1], cb);
1278
+ this._socket.uncork();
1279
+ } else this._socket.write(list[0], cb);
1280
+ }
1281
+ }
1282
+ module.exports = Sender;
1283
+ function callCallbacks(sender, err, cb) {
1284
+ if ('function' == typeof cb) cb(err);
1285
+ for(let i = 0; i < sender._queue.length; i++){
1286
+ const params = sender._queue[i];
1287
+ const callback = params[params.length - 1];
1288
+ if ('function' == typeof callback) callback(err);
1289
+ }
1290
+ }
1291
+ function onError(sender, err, cb) {
1292
+ callCallbacks(sender, err, cb);
1293
+ sender.onerror(err);
1294
+ }
1295
+ },
1296
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/stream.js" (module, __unused_rspack_exports, __webpack_require__) {
1297
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/websocket.js");
1298
+ const { Duplex } = __rspack_createRequire_require("stream");
1299
+ function emitClose(stream) {
1300
+ stream.emit('close');
1301
+ }
1302
+ function duplexOnEnd() {
1303
+ if (!this.destroyed && this._writableState.finished) this.destroy();
1304
+ }
1305
+ function duplexOnError(err) {
1306
+ this.removeListener('error', duplexOnError);
1307
+ this.destroy();
1308
+ if (0 === this.listenerCount('error')) this.emit('error', err);
1309
+ }
1310
+ function createWebSocketStream(ws, options) {
1311
+ let terminateOnDestroy = true;
1312
+ const duplex = new Duplex({
1313
+ ...options,
1314
+ autoDestroy: false,
1315
+ emitClose: false,
1316
+ objectMode: false,
1317
+ writableObjectMode: false
1318
+ });
1319
+ ws.on('message', function(msg, isBinary) {
1320
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
1321
+ if (!duplex.push(data)) ws.pause();
1322
+ });
1323
+ ws.once('error', function(err) {
1324
+ if (duplex.destroyed) return;
1325
+ terminateOnDestroy = false;
1326
+ duplex.destroy(err);
1327
+ });
1328
+ ws.once('close', function() {
1329
+ if (duplex.destroyed) return;
1330
+ duplex.push(null);
1331
+ });
1332
+ duplex._destroy = function(err, callback) {
1333
+ if (ws.readyState === ws.CLOSED) {
1334
+ callback(err);
1335
+ process.nextTick(emitClose, duplex);
1336
+ return;
1337
+ }
1338
+ let called = false;
1339
+ ws.once('error', function(err) {
1340
+ called = true;
1341
+ callback(err);
1342
+ });
1343
+ ws.once('close', function() {
1344
+ if (!called) callback(err);
1345
+ process.nextTick(emitClose, duplex);
1346
+ });
1347
+ if (terminateOnDestroy) ws.terminate();
1348
+ };
1349
+ duplex._final = function(callback) {
1350
+ if (ws.readyState === ws.CONNECTING) return void ws.once('open', function() {
1351
+ duplex._final(callback);
1352
+ });
1353
+ if (null === ws._socket) return;
1354
+ if (ws._socket._writableState.finished) {
1355
+ callback();
1356
+ if (duplex._readableState.endEmitted) duplex.destroy();
1357
+ } else {
1358
+ ws._socket.once('finish', function() {
1359
+ callback();
1360
+ });
1361
+ ws.close();
1362
+ }
1363
+ };
1364
+ duplex._read = function() {
1365
+ if (ws.isPaused) ws.resume();
1366
+ };
1367
+ duplex._write = function(chunk, encoding, callback) {
1368
+ if (ws.readyState === ws.CONNECTING) return void ws.once('open', function() {
1369
+ duplex._write(chunk, encoding, callback);
1370
+ });
1371
+ ws.send(chunk, callback);
1372
+ };
1373
+ duplex.on('end', duplexOnEnd);
1374
+ duplex.on('error', duplexOnError);
1375
+ return duplex;
1376
+ }
1377
+ module.exports = createWebSocketStream;
1378
+ },
1379
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/subprotocol.js" (module, __unused_rspack_exports, __webpack_require__) {
1380
+ const { tokenChars } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/validation.js");
1381
+ function parse(header) {
1382
+ const protocols = new Set();
1383
+ let start = -1;
1384
+ let end = -1;
1385
+ let i = 0;
1386
+ for(i; i < header.length; i++){
1387
+ const code = header.charCodeAt(i);
1388
+ if (-1 === end && 1 === tokenChars[code]) {
1389
+ if (-1 === start) start = i;
1390
+ } else if (0 !== i && (0x20 === code || 0x09 === code)) {
1391
+ if (-1 === end && -1 !== start) end = i;
1392
+ } else if (0x2c === code) {
1393
+ if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
1394
+ if (-1 === end) end = i;
1395
+ const protocol = header.slice(start, end);
1396
+ if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
1397
+ protocols.add(protocol);
1398
+ start = end = -1;
1399
+ } else throw new SyntaxError(`Unexpected character at index ${i}`);
1400
+ }
1401
+ if (-1 === start || -1 !== end) throw new SyntaxError('Unexpected end of input');
1402
+ const protocol = header.slice(start, i);
1403
+ if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
1404
+ protocols.add(protocol);
1405
+ return protocols;
1406
+ }
1407
+ module.exports = {
1408
+ parse
1409
+ };
1410
+ },
1411
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/validation.js" (module, __unused_rspack_exports, __webpack_require__) {
1412
+ const { isUtf8 } = __rspack_createRequire_require("buffer");
1413
+ const { hasBlob } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
1414
+ const tokenChars = [
1415
+ 0,
1416
+ 0,
1417
+ 0,
1418
+ 0,
1419
+ 0,
1420
+ 0,
1421
+ 0,
1422
+ 0,
1423
+ 0,
1424
+ 0,
1425
+ 0,
1426
+ 0,
1427
+ 0,
1428
+ 0,
1429
+ 0,
1430
+ 0,
1431
+ 0,
1432
+ 0,
1433
+ 0,
1434
+ 0,
1435
+ 0,
1436
+ 0,
1437
+ 0,
1438
+ 0,
1439
+ 0,
1440
+ 0,
1441
+ 0,
1442
+ 0,
1443
+ 0,
1444
+ 0,
1445
+ 0,
1446
+ 0,
1447
+ 0,
1448
+ 1,
1449
+ 0,
1450
+ 1,
1451
+ 1,
1452
+ 1,
1453
+ 1,
1454
+ 1,
1455
+ 0,
1456
+ 0,
1457
+ 1,
1458
+ 1,
1459
+ 0,
1460
+ 1,
1461
+ 1,
1462
+ 0,
1463
+ 1,
1464
+ 1,
1465
+ 1,
1466
+ 1,
1467
+ 1,
1468
+ 1,
1469
+ 1,
1470
+ 1,
1471
+ 1,
1472
+ 1,
1473
+ 0,
1474
+ 0,
1475
+ 0,
1476
+ 0,
1477
+ 0,
1478
+ 0,
1479
+ 0,
1480
+ 1,
1481
+ 1,
1482
+ 1,
1483
+ 1,
1484
+ 1,
1485
+ 1,
1486
+ 1,
1487
+ 1,
1488
+ 1,
1489
+ 1,
1490
+ 1,
1491
+ 1,
1492
+ 1,
1493
+ 1,
1494
+ 1,
1495
+ 1,
1496
+ 1,
1497
+ 1,
1498
+ 1,
1499
+ 1,
1500
+ 1,
1501
+ 1,
1502
+ 1,
1503
+ 1,
1504
+ 1,
1505
+ 1,
1506
+ 0,
1507
+ 0,
1508
+ 0,
1509
+ 1,
1510
+ 1,
1511
+ 1,
1512
+ 1,
1513
+ 1,
1514
+ 1,
1515
+ 1,
1516
+ 1,
1517
+ 1,
1518
+ 1,
1519
+ 1,
1520
+ 1,
1521
+ 1,
1522
+ 1,
1523
+ 1,
1524
+ 1,
1525
+ 1,
1526
+ 1,
1527
+ 1,
1528
+ 1,
1529
+ 1,
1530
+ 1,
1531
+ 1,
1532
+ 1,
1533
+ 1,
1534
+ 1,
1535
+ 1,
1536
+ 1,
1537
+ 1,
1538
+ 0,
1539
+ 1,
1540
+ 0,
1541
+ 1,
1542
+ 0
1543
+ ];
1544
+ function isValidStatusCode(code) {
1545
+ return code >= 1000 && code <= 1014 && 1004 !== code && 1005 !== code && 1006 !== code || code >= 3000 && code <= 4999;
1546
+ }
1547
+ function _isValidUTF8(buf) {
1548
+ const len = buf.length;
1549
+ let i = 0;
1550
+ while(i < len)if ((0x80 & buf[i]) === 0) i++;
1551
+ else if ((0xe0 & buf[i]) === 0xc0) {
1552
+ if (i + 1 === len || (0xc0 & buf[i + 1]) !== 0x80 || (0xfe & buf[i]) === 0xc0) return false;
1553
+ i += 2;
1554
+ } else if ((0xf0 & buf[i]) === 0xe0) {
1555
+ if (i + 2 >= len || (0xc0 & buf[i + 1]) !== 0x80 || (0xc0 & buf[i + 2]) !== 0x80 || 0xe0 === buf[i] && (0xe0 & buf[i + 1]) === 0x80 || 0xed === buf[i] && (0xe0 & buf[i + 1]) === 0xa0) return false;
1556
+ i += 3;
1557
+ } else {
1558
+ if ((0xf8 & buf[i]) !== 0xf0) return false;
1559
+ if (i + 3 >= len || (0xc0 & buf[i + 1]) !== 0x80 || (0xc0 & buf[i + 2]) !== 0x80 || (0xc0 & buf[i + 3]) !== 0x80 || 0xf0 === buf[i] && (0xf0 & buf[i + 1]) === 0x80 || 0xf4 === buf[i] && buf[i + 1] > 0x8f || buf[i] > 0xf4) return false;
1560
+ i += 4;
1561
+ }
1562
+ return true;
1563
+ }
1564
+ function isBlob(value) {
1565
+ return hasBlob && 'object' == typeof value && 'function' == typeof value.arrayBuffer && 'string' == typeof value.type && 'function' == typeof value.stream && ('Blob' === value[Symbol.toStringTag] || 'File' === value[Symbol.toStringTag]);
1566
+ }
1567
+ module.exports = {
1568
+ isBlob,
1569
+ isValidStatusCode,
1570
+ isValidUTF8: _isValidUTF8,
1571
+ tokenChars
1572
+ };
1573
+ if (isUtf8) module.exports.isValidUTF8 = function(buf) {
1574
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
1575
+ };
1576
+ else if (!process.env.WS_NO_UTF_8_VALIDATE) try {
1577
+ const isValidUTF8 = __webpack_require__("utf-8-validate");
1578
+ module.exports.isValidUTF8 = function(buf) {
1579
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
1580
+ };
1581
+ } catch (e) {}
1582
+ },
1583
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/websocket-server.js" (module, __unused_rspack_exports, __webpack_require__) {
1584
+ const EventEmitter = __rspack_createRequire_require("events");
1585
+ const http = __rspack_createRequire_require("http");
1586
+ const { Duplex } = __rspack_createRequire_require("stream");
1587
+ const { createHash } = __rspack_createRequire_require("crypto");
1588
+ const extension = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/extension.js");
1589
+ const PerMessageDeflate = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/permessage-deflate.js");
1590
+ const subprotocol = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/subprotocol.js");
1591
+ const WebSocket = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/websocket.js");
1592
+ const { CLOSE_TIMEOUT, GUID, kWebSocket } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
1593
+ const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
1594
+ const RUNNING = 0;
1595
+ const CLOSING = 1;
1596
+ const CLOSED = 2;
1597
+ class WebSocketServer extends EventEmitter {
1598
+ constructor(options, callback){
1599
+ super();
1600
+ options = {
1601
+ allowSynchronousEvents: true,
1602
+ autoPong: true,
1603
+ maxBufferedChunks: 262144,
1604
+ maxFragments: 16384,
1605
+ maxPayload: 104857600,
1606
+ skipUTF8Validation: false,
1607
+ perMessageDeflate: false,
1608
+ handleProtocols: null,
1609
+ clientTracking: true,
1610
+ closeTimeout: CLOSE_TIMEOUT,
1611
+ verifyClient: null,
1612
+ noServer: false,
1613
+ backlog: null,
1614
+ server: null,
1615
+ host: null,
1616
+ path: null,
1617
+ port: null,
1618
+ WebSocket,
1619
+ ...options
1620
+ };
1621
+ if (null == options.port && !options.server && !options.noServer || null != options.port && (options.server || options.noServer) || options.server && options.noServer) throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');
1622
+ if (null != options.port) {
1623
+ this._server = http.createServer((req, res)=>{
1624
+ const body = http.STATUS_CODES[426];
1625
+ res.writeHead(426, {
1626
+ 'Content-Length': body.length,
1627
+ 'Content-Type': 'text/plain'
1628
+ });
1629
+ res.end(body);
1630
+ });
1631
+ this._server.listen(options.port, options.host, options.backlog, callback);
1632
+ } else if (options.server) this._server = options.server;
1633
+ if (this._server) {
1634
+ const emitConnection = this.emit.bind(this, 'connection');
1635
+ this._removeListeners = addListeners(this._server, {
1636
+ listening: this.emit.bind(this, 'listening'),
1637
+ error: this.emit.bind(this, 'error'),
1638
+ upgrade: (req, socket, head)=>{
1639
+ this.handleUpgrade(req, socket, head, emitConnection);
1640
+ }
1641
+ });
1642
+ }
1643
+ if (true === options.perMessageDeflate) options.perMessageDeflate = {};
1644
+ if (options.clientTracking) {
1645
+ this.clients = new Set();
1646
+ this._shouldEmitClose = false;
1647
+ }
1648
+ this.options = options;
1649
+ this._state = RUNNING;
1650
+ }
1651
+ address() {
1652
+ if (this.options.noServer) throw new Error('The server is operating in "noServer" mode');
1653
+ if (!this._server) return null;
1654
+ return this._server.address();
1655
+ }
1656
+ close(cb) {
1657
+ if (this._state === CLOSED) {
1658
+ if (cb) this.once('close', ()=>{
1659
+ cb(new Error('The server is not running'));
1660
+ });
1661
+ process.nextTick(emitClose, this);
1662
+ return;
1663
+ }
1664
+ if (cb) this.once('close', cb);
1665
+ if (this._state === CLOSING) return;
1666
+ this._state = CLOSING;
1667
+ if (this.options.noServer || this.options.server) {
1668
+ if (this._server) {
1669
+ this._removeListeners();
1670
+ this._removeListeners = this._server = null;
1671
+ }
1672
+ if (this.clients) if (this.clients.size) this._shouldEmitClose = true;
1673
+ else process.nextTick(emitClose, this);
1674
+ else process.nextTick(emitClose, this);
1675
+ } else {
1676
+ const server = this._server;
1677
+ this._removeListeners();
1678
+ this._removeListeners = this._server = null;
1679
+ server.close(()=>{
1680
+ emitClose(this);
1681
+ });
1682
+ }
1683
+ }
1684
+ shouldHandle(req) {
1685
+ if (this.options.path) {
1686
+ const index = req.url.indexOf('?');
1687
+ const pathname = -1 !== index ? req.url.slice(0, index) : req.url;
1688
+ if (pathname !== this.options.path) return false;
1689
+ }
1690
+ return true;
1691
+ }
1692
+ handleUpgrade(req, socket, head, cb) {
1693
+ socket.on('error', socketOnError);
1694
+ const key = req.headers['sec-websocket-key'];
1695
+ const upgrade = req.headers.upgrade;
1696
+ const version = +req.headers['sec-websocket-version'];
1697
+ if ('GET' !== req.method) {
1698
+ const message = 'Invalid HTTP method';
1699
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
1700
+ return;
1701
+ }
1702
+ if (void 0 === upgrade || 'websocket' !== upgrade.toLowerCase()) {
1703
+ const message = 'Invalid Upgrade header';
1704
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
1705
+ return;
1706
+ }
1707
+ if (void 0 === key || !keyRegex.test(key)) {
1708
+ const message = 'Missing or invalid Sec-WebSocket-Key header';
1709
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
1710
+ return;
1711
+ }
1712
+ if (13 !== version && 8 !== version) {
1713
+ const message = 'Missing or invalid Sec-WebSocket-Version header';
1714
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
1715
+ 'Sec-WebSocket-Version': '13, 8'
1716
+ });
1717
+ return;
1718
+ }
1719
+ if (!this.shouldHandle(req)) return void abortHandshake(socket, 400);
1720
+ const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
1721
+ let protocols = new Set();
1722
+ if (void 0 !== secWebSocketProtocol) try {
1723
+ protocols = subprotocol.parse(secWebSocketProtocol);
1724
+ } catch (err) {
1725
+ const message = 'Invalid Sec-WebSocket-Protocol header';
1726
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
1727
+ return;
1728
+ }
1729
+ const secWebSocketExtensions = req.headers['sec-websocket-extensions'];
1730
+ const extensions = {};
1731
+ if (this.options.perMessageDeflate && void 0 !== secWebSocketExtensions) {
1732
+ const perMessageDeflate = new PerMessageDeflate({
1733
+ ...this.options.perMessageDeflate,
1734
+ isServer: true,
1735
+ maxPayload: this.options.maxPayload
1736
+ });
1737
+ try {
1738
+ const offers = extension.parse(secWebSocketExtensions);
1739
+ if (offers[PerMessageDeflate.extensionName]) {
1740
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
1741
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
1742
+ }
1743
+ } catch (err) {
1744
+ const message = 'Invalid or unacceptable Sec-WebSocket-Extensions header';
1745
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
1746
+ return;
1747
+ }
1748
+ }
1749
+ if (this.options.verifyClient) {
1750
+ const info = {
1751
+ origin: req.headers[`${8 === version ? 'sec-websocket-origin' : 'origin'}`],
1752
+ secure: !!(req.socket.authorized || req.socket.encrypted),
1753
+ req
1754
+ };
1755
+ if (2 === this.options.verifyClient.length) return void this.options.verifyClient(info, (verified, code, message, headers)=>{
1756
+ if (!verified) return abortHandshake(socket, code || 401, message, headers);
1757
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
1758
+ });
1759
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
1760
+ }
1761
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
1762
+ }
1763
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
1764
+ if (!socket.readable || !socket.writable) return socket.destroy();
1765
+ if (socket[kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
1766
+ if (this._state > RUNNING) return abortHandshake(socket, 503);
1767
+ const digest = createHash('sha1').update(key + GUID).digest('base64');
1768
+ const headers = [
1769
+ 'HTTP/1.1 101 Switching Protocols',
1770
+ 'Upgrade: websocket',
1771
+ 'Connection: Upgrade',
1772
+ `Sec-WebSocket-Accept: ${digest}`
1773
+ ];
1774
+ const ws = new this.options.WebSocket(null, void 0, this.options);
1775
+ if (protocols.size) {
1776
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
1777
+ if (protocol) {
1778
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
1779
+ ws._protocol = protocol;
1780
+ }
1781
+ }
1782
+ if (extensions[PerMessageDeflate.extensionName]) {
1783
+ const params = extensions[PerMessageDeflate.extensionName].params;
1784
+ const value = extension.format({
1785
+ [PerMessageDeflate.extensionName]: [
1786
+ params
1787
+ ]
1788
+ });
1789
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
1790
+ ws._extensions = extensions;
1791
+ }
1792
+ this.emit('headers', headers, req);
1793
+ socket.write(headers.concat('\r\n').join('\r\n'));
1794
+ socket.removeListener('error', socketOnError);
1795
+ ws.setSocket(socket, head, {
1796
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
1797
+ maxBufferedChunks: this.options.maxBufferedChunks,
1798
+ maxFragments: this.options.maxFragments,
1799
+ maxPayload: this.options.maxPayload,
1800
+ skipUTF8Validation: this.options.skipUTF8Validation
1801
+ });
1802
+ if (this.clients) {
1803
+ this.clients.add(ws);
1804
+ ws.on('close', ()=>{
1805
+ this.clients.delete(ws);
1806
+ if (this._shouldEmitClose && !this.clients.size) process.nextTick(emitClose, this);
1807
+ });
1808
+ }
1809
+ cb(ws, req);
1810
+ }
1811
+ }
1812
+ module.exports = WebSocketServer;
1813
+ function addListeners(server, map) {
1814
+ for (const event of Object.keys(map))server.on(event, map[event]);
1815
+ return function() {
1816
+ for (const event of Object.keys(map))server.removeListener(event, map[event]);
1817
+ };
1818
+ }
1819
+ function emitClose(server) {
1820
+ server._state = CLOSED;
1821
+ server.emit('close');
1822
+ }
1823
+ function socketOnError() {
1824
+ this.destroy();
1825
+ }
1826
+ function abortHandshake(socket, code, message, headers) {
1827
+ message = message || http.STATUS_CODES[code];
1828
+ headers = {
1829
+ Connection: 'close',
1830
+ 'Content-Type': 'text/html',
1831
+ 'Content-Length': Buffer.byteLength(message),
1832
+ ...headers
1833
+ };
1834
+ socket.once('finish', socket.destroy);
1835
+ socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + Object.keys(headers).map((h)=>`${h}: ${headers[h]}`).join('\r\n') + '\r\n\r\n' + message);
1836
+ }
1837
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
1838
+ if (server.listenerCount('wsClientError')) {
1839
+ const err = new Error(message);
1840
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
1841
+ server.emit('wsClientError', err, socket, req);
1842
+ } else abortHandshake(socket, code, message, headers);
1843
+ }
1844
+ },
1845
+ "../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/websocket.js" (module, __unused_rspack_exports, __webpack_require__) {
1846
+ const EventEmitter = __rspack_createRequire_require("events");
1847
+ const https = __rspack_createRequire_require("https");
1848
+ const http = __rspack_createRequire_require("http");
1849
+ const net = __rspack_createRequire_require("net");
1850
+ const tls = __rspack_createRequire_require("tls");
1851
+ const { randomBytes, createHash } = __rspack_createRequire_require("crypto");
1852
+ const { Duplex, Readable } = __rspack_createRequire_require("stream");
1853
+ const { URL } = __rspack_createRequire_require("url");
1854
+ const PerMessageDeflate = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/permessage-deflate.js");
1855
+ const Receiver = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/receiver.js");
1856
+ const Sender = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/sender.js");
1857
+ const { isBlob } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/validation.js");
1858
+ const { BINARY_TYPES, CLOSE_TIMEOUT, EMPTY_BUFFER, GUID, kForOnEventAttribute, kListener, kStatusCode, kWebSocket, NOOP } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/constants.js");
1859
+ const { EventTarget: { addEventListener, removeEventListener } } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/event-target.js");
1860
+ const { format, parse } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/extension.js");
1861
+ const { toBuffer } = __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/buffer-util.js");
1862
+ const kAborted = Symbol('kAborted');
1863
+ const protocolVersions = [
1864
+ 8,
1865
+ 13
1866
+ ];
1867
+ const readyStates = [
1868
+ 'CONNECTING',
1869
+ 'OPEN',
1870
+ 'CLOSING',
1871
+ 'CLOSED'
1872
+ ];
1873
+ const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
1874
+ class WebSocket extends EventEmitter {
1875
+ constructor(address, protocols, options){
1876
+ super();
1877
+ this._binaryType = BINARY_TYPES[0];
1878
+ this._closeCode = 1006;
1879
+ this._closeFrameReceived = false;
1880
+ this._closeFrameSent = false;
1881
+ this._closeMessage = EMPTY_BUFFER;
1882
+ this._closeTimer = null;
1883
+ this._errorEmitted = false;
1884
+ this._extensions = {};
1885
+ this._paused = false;
1886
+ this._protocol = '';
1887
+ this._readyState = WebSocket.CONNECTING;
1888
+ this._receiver = null;
1889
+ this._sender = null;
1890
+ this._socket = null;
1891
+ if (null !== address) {
1892
+ this._bufferedAmount = 0;
1893
+ this._isServer = false;
1894
+ this._redirects = 0;
1895
+ if (void 0 === protocols) protocols = options && void 0 !== options.protocols ? Array.isArray(options.protocols) ? options.protocols : [
1896
+ options.protocols
1897
+ ] : [];
1898
+ else if (!Array.isArray(protocols)) if ('object' == typeof protocols && null !== protocols) {
1899
+ options = protocols;
1900
+ protocols = void 0 === options.protocols ? [] : Array.isArray(options.protocols) ? options.protocols : [
1901
+ options.protocols
1902
+ ];
1903
+ } else protocols = [
1904
+ protocols
1905
+ ];
1906
+ initAsClient(this, address, protocols, options);
1907
+ } else {
1908
+ this._autoPong = options.autoPong;
1909
+ this._closeTimeout = options.closeTimeout;
1910
+ this._isServer = true;
1911
+ }
1912
+ }
1913
+ get binaryType() {
1914
+ return this._binaryType;
1915
+ }
1916
+ set binaryType(type) {
1917
+ if (!BINARY_TYPES.includes(type)) return;
1918
+ this._binaryType = type;
1919
+ if (this._receiver) this._receiver._binaryType = type;
1920
+ }
1921
+ get bufferedAmount() {
1922
+ if (!this._socket) return this._bufferedAmount;
1923
+ return this._socket._writableState.length + this._sender._bufferedBytes;
1924
+ }
1925
+ get extensions() {
1926
+ return Object.keys(this._extensions).join();
1927
+ }
1928
+ get isPaused() {
1929
+ return this._paused;
1930
+ }
1931
+ get onclose() {
1932
+ return null;
1933
+ }
1934
+ get onerror() {
1935
+ return null;
1936
+ }
1937
+ get onopen() {
1938
+ return null;
1939
+ }
1940
+ get onmessage() {
1941
+ return null;
1942
+ }
1943
+ get protocol() {
1944
+ return this._protocol;
1945
+ }
1946
+ get readyState() {
1947
+ return this._readyState;
1948
+ }
1949
+ get url() {
1950
+ return this._url;
1951
+ }
1952
+ setSocket(socket, head, options) {
1953
+ const receiver = new Receiver({
1954
+ allowSynchronousEvents: options.allowSynchronousEvents,
1955
+ binaryType: this.binaryType,
1956
+ extensions: this._extensions,
1957
+ isServer: this._isServer,
1958
+ maxBufferedChunks: options.maxBufferedChunks,
1959
+ maxFragments: options.maxFragments,
1960
+ maxPayload: options.maxPayload,
1961
+ skipUTF8Validation: options.skipUTF8Validation
1962
+ });
1963
+ const sender = new Sender(socket, this._extensions, options.generateMask);
1964
+ this._receiver = receiver;
1965
+ this._sender = sender;
1966
+ this._socket = socket;
1967
+ receiver[kWebSocket] = this;
1968
+ sender[kWebSocket] = this;
1969
+ socket[kWebSocket] = this;
1970
+ receiver.on('conclude', receiverOnConclude);
1971
+ receiver.on('drain', receiverOnDrain);
1972
+ receiver.on('error', receiverOnError);
1973
+ receiver.on('message', receiverOnMessage);
1974
+ receiver.on('ping', receiverOnPing);
1975
+ receiver.on('pong', receiverOnPong);
1976
+ sender.onerror = senderOnError;
1977
+ if (socket.setTimeout) socket.setTimeout(0);
1978
+ if (socket.setNoDelay) socket.setNoDelay();
1979
+ if (head.length > 0) socket.unshift(head);
1980
+ socket.on('close', socketOnClose);
1981
+ socket.on('data', socketOnData);
1982
+ socket.on('end', socketOnEnd);
1983
+ socket.on('error', socketOnError);
1984
+ this._readyState = WebSocket.OPEN;
1985
+ this.emit('open');
1986
+ }
1987
+ emitClose() {
1988
+ if (!this._socket) {
1989
+ this._readyState = WebSocket.CLOSED;
1990
+ this.emit('close', this._closeCode, this._closeMessage);
1991
+ return;
1992
+ }
1993
+ if (this._extensions[PerMessageDeflate.extensionName]) this._extensions[PerMessageDeflate.extensionName].cleanup();
1994
+ this._receiver.removeAllListeners();
1995
+ this._readyState = WebSocket.CLOSED;
1996
+ this.emit('close', this._closeCode, this._closeMessage);
1997
+ }
1998
+ close(code, data) {
1999
+ if (this.readyState === WebSocket.CLOSED) return;
2000
+ if (this.readyState === WebSocket.CONNECTING) {
2001
+ const msg = 'WebSocket was closed before the connection was established';
2002
+ abortHandshake(this, this._req, msg);
2003
+ return;
2004
+ }
2005
+ if (this.readyState === WebSocket.CLOSING) {
2006
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) this._socket.end();
2007
+ return;
2008
+ }
2009
+ this._sender.close(code, data, !this._isServer, (err)=>{
2010
+ if (err) return;
2011
+ this._closeFrameSent = true;
2012
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) this._socket.end();
2013
+ });
2014
+ this._readyState = WebSocket.CLOSING;
2015
+ setCloseTimer(this);
2016
+ }
2017
+ pause() {
2018
+ if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
2019
+ this._paused = true;
2020
+ this._socket.pause();
2021
+ }
2022
+ ping(data, mask, cb) {
2023
+ if (this.readyState === WebSocket.CONNECTING) throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
2024
+ if ('function' == typeof data) {
2025
+ cb = data;
2026
+ data = mask = void 0;
2027
+ } else if ('function' == typeof mask) {
2028
+ cb = mask;
2029
+ mask = void 0;
2030
+ }
2031
+ if ('number' == typeof data) data = data.toString();
2032
+ if (this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
2033
+ if (void 0 === mask) mask = !this._isServer;
2034
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2035
+ }
2036
+ pong(data, mask, cb) {
2037
+ if (this.readyState === WebSocket.CONNECTING) throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
2038
+ if ('function' == typeof data) {
2039
+ cb = data;
2040
+ data = mask = void 0;
2041
+ } else if ('function' == typeof mask) {
2042
+ cb = mask;
2043
+ mask = void 0;
2044
+ }
2045
+ if ('number' == typeof data) data = data.toString();
2046
+ if (this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
2047
+ if (void 0 === mask) mask = !this._isServer;
2048
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2049
+ }
2050
+ resume() {
2051
+ if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
2052
+ this._paused = false;
2053
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
2054
+ }
2055
+ send(data, options, cb) {
2056
+ if (this.readyState === WebSocket.CONNECTING) throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
2057
+ if ('function' == typeof options) {
2058
+ cb = options;
2059
+ options = {};
2060
+ }
2061
+ if ('number' == typeof data) data = data.toString();
2062
+ if (this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
2063
+ const opts = {
2064
+ binary: 'string' != typeof data,
2065
+ mask: !this._isServer,
2066
+ compress: true,
2067
+ fin: true,
2068
+ ...options
2069
+ };
2070
+ if (!this._extensions[PerMessageDeflate.extensionName]) opts.compress = false;
2071
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2072
+ }
2073
+ terminate() {
2074
+ if (this.readyState === WebSocket.CLOSED) return;
2075
+ if (this.readyState === WebSocket.CONNECTING) {
2076
+ const msg = 'WebSocket was closed before the connection was established';
2077
+ abortHandshake(this, this._req, msg);
2078
+ return;
2079
+ }
2080
+ if (this._socket) {
2081
+ this._readyState = WebSocket.CLOSING;
2082
+ this._socket.destroy();
2083
+ }
2084
+ }
2085
+ }
2086
+ Object.defineProperty(WebSocket, 'CONNECTING', {
2087
+ enumerable: true,
2088
+ value: readyStates.indexOf('CONNECTING')
2089
+ });
2090
+ Object.defineProperty(WebSocket.prototype, 'CONNECTING', {
2091
+ enumerable: true,
2092
+ value: readyStates.indexOf('CONNECTING')
2093
+ });
2094
+ Object.defineProperty(WebSocket, 'OPEN', {
2095
+ enumerable: true,
2096
+ value: readyStates.indexOf('OPEN')
2097
+ });
2098
+ Object.defineProperty(WebSocket.prototype, 'OPEN', {
2099
+ enumerable: true,
2100
+ value: readyStates.indexOf('OPEN')
2101
+ });
2102
+ Object.defineProperty(WebSocket, 'CLOSING', {
2103
+ enumerable: true,
2104
+ value: readyStates.indexOf('CLOSING')
2105
+ });
2106
+ Object.defineProperty(WebSocket.prototype, 'CLOSING', {
2107
+ enumerable: true,
2108
+ value: readyStates.indexOf('CLOSING')
2109
+ });
2110
+ Object.defineProperty(WebSocket, 'CLOSED', {
2111
+ enumerable: true,
2112
+ value: readyStates.indexOf('CLOSED')
2113
+ });
2114
+ Object.defineProperty(WebSocket.prototype, 'CLOSED', {
2115
+ enumerable: true,
2116
+ value: readyStates.indexOf('CLOSED')
2117
+ });
2118
+ [
2119
+ 'binaryType',
2120
+ 'bufferedAmount',
2121
+ 'extensions',
2122
+ 'isPaused',
2123
+ 'protocol',
2124
+ 'readyState',
2125
+ 'url'
2126
+ ].forEach((property)=>{
2127
+ Object.defineProperty(WebSocket.prototype, property, {
2128
+ enumerable: true
2129
+ });
2130
+ });
2131
+ [
2132
+ 'open',
2133
+ 'error',
2134
+ 'close',
2135
+ 'message'
2136
+ ].forEach((method)=>{
2137
+ Object.defineProperty(WebSocket.prototype, `on${method}`, {
2138
+ enumerable: true,
2139
+ get () {
2140
+ for (const listener of this.listeners(method))if (listener[kForOnEventAttribute]) return listener[kListener];
2141
+ return null;
2142
+ },
2143
+ set (handler) {
2144
+ for (const listener of this.listeners(method))if (listener[kForOnEventAttribute]) {
2145
+ this.removeListener(method, listener);
2146
+ break;
2147
+ }
2148
+ if ('function' != typeof handler) return;
2149
+ this.addEventListener(method, handler, {
2150
+ [kForOnEventAttribute]: true
2151
+ });
2152
+ }
2153
+ });
2154
+ });
2155
+ WebSocket.prototype.addEventListener = addEventListener;
2156
+ WebSocket.prototype.removeEventListener = removeEventListener;
2157
+ module.exports = WebSocket;
2158
+ function initAsClient(websocket, address, protocols, options) {
2159
+ const opts = {
2160
+ allowSynchronousEvents: true,
2161
+ autoPong: true,
2162
+ closeTimeout: CLOSE_TIMEOUT,
2163
+ protocolVersion: protocolVersions[1],
2164
+ maxBufferedChunks: 262144,
2165
+ maxFragments: 16384,
2166
+ maxPayload: 104857600,
2167
+ skipUTF8Validation: false,
2168
+ perMessageDeflate: true,
2169
+ followRedirects: false,
2170
+ maxRedirects: 10,
2171
+ ...options,
2172
+ socketPath: void 0,
2173
+ hostname: void 0,
2174
+ protocol: void 0,
2175
+ protocols: void 0,
2176
+ timeout: void 0,
2177
+ method: 'GET',
2178
+ host: void 0,
2179
+ path: void 0,
2180
+ port: void 0
2181
+ };
2182
+ websocket._autoPong = opts.autoPong;
2183
+ websocket._closeTimeout = opts.closeTimeout;
2184
+ if (!protocolVersions.includes(opts.protocolVersion)) throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(', ')})`);
2185
+ let parsedUrl;
2186
+ if (address instanceof URL) parsedUrl = address;
2187
+ else try {
2188
+ parsedUrl = new URL(address);
2189
+ } catch {
2190
+ throw new SyntaxError(`Invalid URL: ${address}`);
2191
+ }
2192
+ if ('http:' === parsedUrl.protocol) parsedUrl.protocol = 'ws:';
2193
+ else if ('https:' === parsedUrl.protocol) parsedUrl.protocol = 'wss:';
2194
+ websocket._url = parsedUrl.href;
2195
+ const isSecure = 'wss:' === parsedUrl.protocol;
2196
+ const isIpcUrl = 'ws+unix:' === parsedUrl.protocol;
2197
+ let invalidUrlMessage;
2198
+ if ('ws:' === parsedUrl.protocol || isSecure || isIpcUrl) {
2199
+ if (isIpcUrl && !parsedUrl.pathname) invalidUrlMessage = "The URL's pathname is empty";
2200
+ else if (parsedUrl.hash) invalidUrlMessage = 'The URL contains a fragment identifier';
2201
+ } else invalidUrlMessage = 'The URL\'s protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"';
2202
+ if (invalidUrlMessage) {
2203
+ const err = new SyntaxError(invalidUrlMessage);
2204
+ if (0 !== websocket._redirects) return void emitErrorAndClose(websocket, err);
2205
+ else throw err;
2206
+ }
2207
+ const defaultPort = isSecure ? 443 : 80;
2208
+ const key = randomBytes(16).toString('base64');
2209
+ const request = isSecure ? https.request : http.request;
2210
+ const protocolSet = new Set();
2211
+ let perMessageDeflate;
2212
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
2213
+ opts.defaultPort = opts.defaultPort || defaultPort;
2214
+ opts.port = parsedUrl.port || defaultPort;
2215
+ opts.host = parsedUrl.hostname.startsWith('[') ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
2216
+ opts.headers = {
2217
+ ...opts.headers,
2218
+ 'Sec-WebSocket-Version': opts.protocolVersion,
2219
+ 'Sec-WebSocket-Key': key,
2220
+ Connection: 'Upgrade',
2221
+ Upgrade: 'websocket'
2222
+ };
2223
+ opts.path = parsedUrl.pathname + parsedUrl.search;
2224
+ opts.timeout = opts.handshakeTimeout;
2225
+ if (opts.perMessageDeflate) {
2226
+ perMessageDeflate = new PerMessageDeflate({
2227
+ ...opts.perMessageDeflate,
2228
+ isServer: false,
2229
+ maxPayload: opts.maxPayload
2230
+ });
2231
+ opts.headers['Sec-WebSocket-Extensions'] = format({
2232
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
2233
+ });
2234
+ }
2235
+ if (protocols.length) {
2236
+ for (const protocol of protocols){
2237
+ if ('string' != typeof protocol || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) throw new SyntaxError('An invalid or duplicated subprotocol was specified');
2238
+ protocolSet.add(protocol);
2239
+ }
2240
+ opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
2241
+ }
2242
+ if (opts.origin) if (opts.protocolVersion < 13) opts.headers['Sec-WebSocket-Origin'] = opts.origin;
2243
+ else opts.headers.Origin = opts.origin;
2244
+ if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2245
+ if (isIpcUrl) {
2246
+ const parts = opts.path.split(':');
2247
+ opts.socketPath = parts[0];
2248
+ opts.path = parts[1];
2249
+ }
2250
+ let req;
2251
+ if (opts.followRedirects) {
2252
+ if (0 === websocket._redirects) {
2253
+ websocket._originalIpc = isIpcUrl;
2254
+ websocket._originalSecure = isSecure;
2255
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
2256
+ const headers = options && options.headers;
2257
+ options = {
2258
+ ...options,
2259
+ headers: {}
2260
+ };
2261
+ if (headers) for (const [key, value] of Object.entries(headers))options.headers[key.toLowerCase()] = value;
2262
+ } else if (0 === websocket.listenerCount('redirect')) {
2263
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
2264
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
2265
+ delete opts.headers.authorization;
2266
+ delete opts.headers.cookie;
2267
+ if (!isSameHost) delete opts.headers.host;
2268
+ opts.auth = void 0;
2269
+ }
2270
+ }
2271
+ if (opts.auth && !options.headers.authorization) options.headers.authorization = 'Basic ' + Buffer.from(opts.auth).toString('base64');
2272
+ req = websocket._req = request(opts);
2273
+ if (websocket._redirects) websocket.emit('redirect', websocket.url, req);
2274
+ } else req = websocket._req = request(opts);
2275
+ if (opts.timeout) req.on('timeout', ()=>{
2276
+ abortHandshake(websocket, req, 'Opening handshake has timed out');
2277
+ });
2278
+ req.on('error', (err)=>{
2279
+ if (null === req || req[kAborted]) return;
2280
+ req = websocket._req = null;
2281
+ emitErrorAndClose(websocket, err);
2282
+ });
2283
+ req.on('response', (res)=>{
2284
+ const location = res.headers.location;
2285
+ const statusCode = res.statusCode;
2286
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
2287
+ if (++websocket._redirects > opts.maxRedirects) return void abortHandshake(websocket, req, 'Maximum redirects exceeded');
2288
+ req.abort();
2289
+ let addr;
2290
+ try {
2291
+ addr = new URL(location, address);
2292
+ } catch (e) {
2293
+ const err = new SyntaxError(`Invalid URL: ${location}`);
2294
+ emitErrorAndClose(websocket, err);
2295
+ return;
2296
+ }
2297
+ initAsClient(websocket, addr, protocols, options);
2298
+ } else if (!websocket.emit('unexpected-response', req, res)) abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
2299
+ });
2300
+ req.on('upgrade', (res, socket, head)=>{
2301
+ websocket.emit('upgrade', res);
2302
+ if (websocket.readyState !== WebSocket.CONNECTING) return;
2303
+ req = websocket._req = null;
2304
+ const upgrade = res.headers.upgrade;
2305
+ if (void 0 === upgrade || 'websocket' !== upgrade.toLowerCase()) return void abortHandshake(websocket, socket, 'Invalid Upgrade header');
2306
+ const digest = createHash('sha1').update(key + GUID).digest('base64');
2307
+ if (res.headers['sec-websocket-accept'] !== digest) return void abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
2308
+ const serverProt = res.headers['sec-websocket-protocol'];
2309
+ let protError;
2310
+ if (void 0 !== serverProt) if (protocolSet.size) {
2311
+ if (!protocolSet.has(serverProt)) protError = 'Server sent an invalid subprotocol';
2312
+ } else protError = 'Server sent a subprotocol but none was requested';
2313
+ else if (protocolSet.size) protError = 'Server sent no subprotocol';
2314
+ if (protError) return void abortHandshake(websocket, socket, protError);
2315
+ if (serverProt) websocket._protocol = serverProt;
2316
+ const secWebSocketExtensions = res.headers['sec-websocket-extensions'];
2317
+ if (void 0 !== secWebSocketExtensions) {
2318
+ if (!perMessageDeflate) {
2319
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
2320
+ abortHandshake(websocket, socket, message);
2321
+ return;
2322
+ }
2323
+ let extensions;
2324
+ try {
2325
+ extensions = parse(secWebSocketExtensions);
2326
+ } catch (err) {
2327
+ const message = 'Invalid Sec-WebSocket-Extensions header';
2328
+ abortHandshake(websocket, socket, message);
2329
+ return;
2330
+ }
2331
+ const extensionNames = Object.keys(extensions);
2332
+ if (1 !== extensionNames.length || extensionNames[0] !== PerMessageDeflate.extensionName) {
2333
+ const message = 'Server indicated an extension that was not requested';
2334
+ abortHandshake(websocket, socket, message);
2335
+ return;
2336
+ }
2337
+ try {
2338
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
2339
+ } catch (err) {
2340
+ const message = 'Invalid Sec-WebSocket-Extensions header';
2341
+ abortHandshake(websocket, socket, message);
2342
+ return;
2343
+ }
2344
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
2345
+ }
2346
+ websocket.setSocket(socket, head, {
2347
+ allowSynchronousEvents: opts.allowSynchronousEvents,
2348
+ generateMask: opts.generateMask,
2349
+ maxBufferedChunks: opts.maxBufferedChunks,
2350
+ maxFragments: opts.maxFragments,
2351
+ maxPayload: opts.maxPayload,
2352
+ skipUTF8Validation: opts.skipUTF8Validation
2353
+ });
2354
+ });
2355
+ if (opts.finishRequest) opts.finishRequest(req, websocket);
2356
+ else req.end();
2357
+ }
2358
+ function emitErrorAndClose(websocket, err) {
2359
+ websocket._readyState = WebSocket.CLOSING;
2360
+ websocket._errorEmitted = true;
2361
+ websocket.emit('error', err);
2362
+ websocket.emitClose();
2363
+ }
2364
+ function netConnect(options) {
2365
+ options.path = options.socketPath;
2366
+ return net.connect(options);
2367
+ }
2368
+ function tlsConnect(options) {
2369
+ options.path = void 0;
2370
+ if (!options.servername && '' !== options.servername) options.servername = net.isIP(options.host) ? '' : options.host;
2371
+ return tls.connect(options);
2372
+ }
2373
+ function abortHandshake(websocket, stream, message) {
2374
+ websocket._readyState = WebSocket.CLOSING;
2375
+ const err = new Error(message);
2376
+ Error.captureStackTrace(err, abortHandshake);
2377
+ if (stream.setHeader) {
2378
+ stream[kAborted] = true;
2379
+ stream.abort();
2380
+ if (stream.socket && !stream.socket.destroyed) stream.socket.destroy();
2381
+ process.nextTick(emitErrorAndClose, websocket, err);
2382
+ } else {
2383
+ stream.destroy(err);
2384
+ stream.once('error', websocket.emit.bind(websocket, 'error'));
2385
+ stream.once('close', websocket.emitClose.bind(websocket));
2386
+ }
2387
+ }
2388
+ function sendAfterClose(websocket, data, cb) {
2389
+ if (data) {
2390
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
2391
+ if (websocket._socket) websocket._sender._bufferedBytes += length;
2392
+ else websocket._bufferedAmount += length;
2393
+ }
2394
+ if (cb) {
2395
+ const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`);
2396
+ process.nextTick(cb, err);
2397
+ }
2398
+ }
2399
+ function receiverOnConclude(code, reason) {
2400
+ const websocket = this[kWebSocket];
2401
+ websocket._closeFrameReceived = true;
2402
+ websocket._closeMessage = reason;
2403
+ websocket._closeCode = code;
2404
+ if (void 0 === websocket._socket[kWebSocket]) return;
2405
+ websocket._socket.removeListener('data', socketOnData);
2406
+ process.nextTick(resume, websocket._socket);
2407
+ if (1005 === code) websocket.close();
2408
+ else websocket.close(code, reason);
2409
+ }
2410
+ function receiverOnDrain() {
2411
+ const websocket = this[kWebSocket];
2412
+ if (!websocket.isPaused) websocket._socket.resume();
2413
+ }
2414
+ function receiverOnError(err) {
2415
+ const websocket = this[kWebSocket];
2416
+ if (void 0 !== websocket._socket[kWebSocket]) {
2417
+ websocket._socket.removeListener('data', socketOnData);
2418
+ process.nextTick(resume, websocket._socket);
2419
+ websocket.close(err[kStatusCode]);
2420
+ }
2421
+ if (!websocket._errorEmitted) {
2422
+ websocket._errorEmitted = true;
2423
+ websocket.emit('error', err);
2424
+ }
2425
+ }
2426
+ function receiverOnFinish() {
2427
+ this[kWebSocket].emitClose();
2428
+ }
2429
+ function receiverOnMessage(data, isBinary) {
2430
+ this[kWebSocket].emit('message', data, isBinary);
2431
+ }
2432
+ function receiverOnPing(data) {
2433
+ const websocket = this[kWebSocket];
2434
+ if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
2435
+ websocket.emit('ping', data);
2436
+ }
2437
+ function receiverOnPong(data) {
2438
+ this[kWebSocket].emit('pong', data);
2439
+ }
2440
+ function resume(stream) {
2441
+ stream.resume();
2442
+ }
2443
+ function senderOnError(err) {
2444
+ const websocket = this[kWebSocket];
2445
+ if (websocket.readyState === WebSocket.CLOSED) return;
2446
+ if (websocket.readyState === WebSocket.OPEN) {
2447
+ websocket._readyState = WebSocket.CLOSING;
2448
+ setCloseTimer(websocket);
2449
+ }
2450
+ this._socket.end();
2451
+ if (!websocket._errorEmitted) {
2452
+ websocket._errorEmitted = true;
2453
+ websocket.emit('error', err);
2454
+ }
2455
+ }
2456
+ function setCloseTimer(websocket) {
2457
+ websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
2458
+ }
2459
+ function socketOnClose() {
2460
+ const websocket = this[kWebSocket];
2461
+ this.removeListener('close', socketOnClose);
2462
+ this.removeListener('data', socketOnData);
2463
+ this.removeListener('end', socketOnEnd);
2464
+ websocket._readyState = WebSocket.CLOSING;
2465
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && 0 !== this._readableState.length) {
2466
+ const chunk = this.read(this._readableState.length);
2467
+ websocket._receiver.write(chunk);
2468
+ }
2469
+ websocket._receiver.end();
2470
+ this[kWebSocket] = void 0;
2471
+ clearTimeout(websocket._closeTimer);
2472
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) websocket.emitClose();
2473
+ else {
2474
+ websocket._receiver.on('error', receiverOnFinish);
2475
+ websocket._receiver.on('finish', receiverOnFinish);
2476
+ }
2477
+ }
2478
+ function socketOnData(chunk) {
2479
+ if (!this[kWebSocket]._receiver.write(chunk)) this.pause();
2480
+ }
2481
+ function socketOnEnd() {
2482
+ const websocket = this[kWebSocket];
2483
+ websocket._readyState = WebSocket.CLOSING;
2484
+ websocket._receiver.end();
2485
+ this.end();
2486
+ }
2487
+ function socketOnError() {
2488
+ const websocket = this[kWebSocket];
2489
+ this.removeListener('error', socketOnError);
2490
+ this.on('error', NOOP);
2491
+ if (websocket) {
2492
+ websocket._readyState = WebSocket.CLOSING;
2493
+ this.destroy();
2494
+ }
2495
+ }
2496
+ }
2497
+ });
2498
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/stream.js");
2499
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/extension.js");
2500
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/permessage-deflate.js");
2501
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/receiver.js");
2502
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/sender.js");
2503
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/subprotocol.js");
2504
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/websocket.js");
2505
+ __webpack_require__("../../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/websocket-server.js");