liangzimixin 0.3.99 → 0.3.101

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.
package/dist/index.cjs CHANGED
@@ -15911,6 +15911,3622 @@ var require_winston_daily_rotate_file = __commonJS({
15911
15911
  }
15912
15912
  });
15913
15913
 
15914
+ // node_modules/ws/lib/constants.js
15915
+ var require_constants = __commonJS({
15916
+ "node_modules/ws/lib/constants.js"(exports2, module2) {
15917
+ "use strict";
15918
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
15919
+ var hasBlob = typeof Blob !== "undefined";
15920
+ if (hasBlob) BINARY_TYPES.push("blob");
15921
+ module2.exports = {
15922
+ BINARY_TYPES,
15923
+ CLOSE_TIMEOUT: 3e4,
15924
+ EMPTY_BUFFER: Buffer.alloc(0),
15925
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
15926
+ hasBlob,
15927
+ kForOnEventAttribute: /* @__PURE__ */ Symbol("kIsForOnEventAttribute"),
15928
+ kListener: /* @__PURE__ */ Symbol("kListener"),
15929
+ kStatusCode: /* @__PURE__ */ Symbol("status-code"),
15930
+ kWebSocket: /* @__PURE__ */ Symbol("websocket"),
15931
+ NOOP: () => {
15932
+ }
15933
+ };
15934
+ }
15935
+ });
15936
+
15937
+ // node_modules/ws/lib/buffer-util.js
15938
+ var require_buffer_util = __commonJS({
15939
+ "node_modules/ws/lib/buffer-util.js"(exports2, module2) {
15940
+ "use strict";
15941
+ var { EMPTY_BUFFER } = require_constants();
15942
+ var FastBuffer = Buffer[Symbol.species];
15943
+ function concat(list, totalLength) {
15944
+ if (list.length === 0) return EMPTY_BUFFER;
15945
+ if (list.length === 1) return list[0];
15946
+ const target = Buffer.allocUnsafe(totalLength);
15947
+ let offset = 0;
15948
+ for (let i = 0; i < list.length; i++) {
15949
+ const buf = list[i];
15950
+ target.set(buf, offset);
15951
+ offset += buf.length;
15952
+ }
15953
+ if (offset < totalLength) {
15954
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
15955
+ }
15956
+ return target;
15957
+ }
15958
+ function _mask(source, mask, output, offset, length) {
15959
+ for (let i = 0; i < length; i++) {
15960
+ output[offset + i] = source[i] ^ mask[i & 3];
15961
+ }
15962
+ }
15963
+ function _unmask(buffer, mask) {
15964
+ for (let i = 0; i < buffer.length; i++) {
15965
+ buffer[i] ^= mask[i & 3];
15966
+ }
15967
+ }
15968
+ function toArrayBuffer(buf) {
15969
+ if (buf.length === buf.buffer.byteLength) {
15970
+ return buf.buffer;
15971
+ }
15972
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
15973
+ }
15974
+ function toBuffer(data) {
15975
+ toBuffer.readOnly = true;
15976
+ if (Buffer.isBuffer(data)) return data;
15977
+ let buf;
15978
+ if (data instanceof ArrayBuffer) {
15979
+ buf = new FastBuffer(data);
15980
+ } else if (ArrayBuffer.isView(data)) {
15981
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
15982
+ } else {
15983
+ buf = Buffer.from(data);
15984
+ toBuffer.readOnly = false;
15985
+ }
15986
+ return buf;
15987
+ }
15988
+ module2.exports = {
15989
+ concat,
15990
+ mask: _mask,
15991
+ toArrayBuffer,
15992
+ toBuffer,
15993
+ unmask: _unmask
15994
+ };
15995
+ if (!process.env.WS_NO_BUFFER_UTIL) {
15996
+ try {
15997
+ const bufferUtil = require("bufferutil");
15998
+ module2.exports.mask = function(source, mask, output, offset, length) {
15999
+ if (length < 48) _mask(source, mask, output, offset, length);
16000
+ else bufferUtil.mask(source, mask, output, offset, length);
16001
+ };
16002
+ module2.exports.unmask = function(buffer, mask) {
16003
+ if (buffer.length < 32) _unmask(buffer, mask);
16004
+ else bufferUtil.unmask(buffer, mask);
16005
+ };
16006
+ } catch (e) {
16007
+ }
16008
+ }
16009
+ }
16010
+ });
16011
+
16012
+ // node_modules/ws/lib/limiter.js
16013
+ var require_limiter = __commonJS({
16014
+ "node_modules/ws/lib/limiter.js"(exports2, module2) {
16015
+ "use strict";
16016
+ var kDone = /* @__PURE__ */ Symbol("kDone");
16017
+ var kRun = /* @__PURE__ */ Symbol("kRun");
16018
+ var Limiter = class {
16019
+ /**
16020
+ * Creates a new `Limiter`.
16021
+ *
16022
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
16023
+ * to run concurrently
16024
+ */
16025
+ constructor(concurrency) {
16026
+ this[kDone] = () => {
16027
+ this.pending--;
16028
+ this[kRun]();
16029
+ };
16030
+ this.concurrency = concurrency || Infinity;
16031
+ this.jobs = [];
16032
+ this.pending = 0;
16033
+ }
16034
+ /**
16035
+ * Adds a job to the queue.
16036
+ *
16037
+ * @param {Function} job The job to run
16038
+ * @public
16039
+ */
16040
+ add(job) {
16041
+ this.jobs.push(job);
16042
+ this[kRun]();
16043
+ }
16044
+ /**
16045
+ * Removes a job from the queue and runs it if possible.
16046
+ *
16047
+ * @private
16048
+ */
16049
+ [kRun]() {
16050
+ if (this.pending === this.concurrency) return;
16051
+ if (this.jobs.length) {
16052
+ const job = this.jobs.shift();
16053
+ this.pending++;
16054
+ job(this[kDone]);
16055
+ }
16056
+ }
16057
+ };
16058
+ module2.exports = Limiter;
16059
+ }
16060
+ });
16061
+
16062
+ // node_modules/ws/lib/permessage-deflate.js
16063
+ var require_permessage_deflate = __commonJS({
16064
+ "node_modules/ws/lib/permessage-deflate.js"(exports2, module2) {
16065
+ "use strict";
16066
+ var zlib = require("zlib");
16067
+ var bufferUtil = require_buffer_util();
16068
+ var Limiter = require_limiter();
16069
+ var { kStatusCode } = require_constants();
16070
+ var FastBuffer = Buffer[Symbol.species];
16071
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
16072
+ var kPerMessageDeflate = /* @__PURE__ */ Symbol("permessage-deflate");
16073
+ var kTotalLength = /* @__PURE__ */ Symbol("total-length");
16074
+ var kCallback = /* @__PURE__ */ Symbol("callback");
16075
+ var kBuffers = /* @__PURE__ */ Symbol("buffers");
16076
+ var kError = /* @__PURE__ */ Symbol("error");
16077
+ var zlibLimiter;
16078
+ var PerMessageDeflate = class {
16079
+ /**
16080
+ * Creates a PerMessageDeflate instance.
16081
+ *
16082
+ * @param {Object} [options] Configuration options
16083
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
16084
+ * for, or request, a custom client window size
16085
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
16086
+ * acknowledge disabling of client context takeover
16087
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
16088
+ * calls to zlib
16089
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
16090
+ * use of a custom server window size
16091
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
16092
+ * disabling of server context takeover
16093
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
16094
+ * messages should not be compressed if context takeover is disabled
16095
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
16096
+ * deflate
16097
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
16098
+ * inflate
16099
+ * @param {Boolean} [isServer=false] Create the instance in either server or
16100
+ * client mode
16101
+ * @param {Number} [maxPayload=0] The maximum allowed message length
16102
+ */
16103
+ constructor(options, isServer, maxPayload) {
16104
+ this._maxPayload = maxPayload | 0;
16105
+ this._options = options || {};
16106
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
16107
+ this._isServer = !!isServer;
16108
+ this._deflate = null;
16109
+ this._inflate = null;
16110
+ this.params = null;
16111
+ if (!zlibLimiter) {
16112
+ const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
16113
+ zlibLimiter = new Limiter(concurrency);
16114
+ }
16115
+ }
16116
+ /**
16117
+ * @type {String}
16118
+ */
16119
+ static get extensionName() {
16120
+ return "permessage-deflate";
16121
+ }
16122
+ /**
16123
+ * Create an extension negotiation offer.
16124
+ *
16125
+ * @return {Object} Extension parameters
16126
+ * @public
16127
+ */
16128
+ offer() {
16129
+ const params = {};
16130
+ if (this._options.serverNoContextTakeover) {
16131
+ params.server_no_context_takeover = true;
16132
+ }
16133
+ if (this._options.clientNoContextTakeover) {
16134
+ params.client_no_context_takeover = true;
16135
+ }
16136
+ if (this._options.serverMaxWindowBits) {
16137
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
16138
+ }
16139
+ if (this._options.clientMaxWindowBits) {
16140
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
16141
+ } else if (this._options.clientMaxWindowBits == null) {
16142
+ params.client_max_window_bits = true;
16143
+ }
16144
+ return params;
16145
+ }
16146
+ /**
16147
+ * Accept an extension negotiation offer/response.
16148
+ *
16149
+ * @param {Array} configurations The extension negotiation offers/reponse
16150
+ * @return {Object} Accepted configuration
16151
+ * @public
16152
+ */
16153
+ accept(configurations) {
16154
+ configurations = this.normalizeParams(configurations);
16155
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
16156
+ return this.params;
16157
+ }
16158
+ /**
16159
+ * Releases all resources used by the extension.
16160
+ *
16161
+ * @public
16162
+ */
16163
+ cleanup() {
16164
+ if (this._inflate) {
16165
+ this._inflate.close();
16166
+ this._inflate = null;
16167
+ }
16168
+ if (this._deflate) {
16169
+ const callback = this._deflate[kCallback];
16170
+ this._deflate.close();
16171
+ this._deflate = null;
16172
+ if (callback) {
16173
+ callback(
16174
+ new Error(
16175
+ "The deflate stream was closed while data was being processed"
16176
+ )
16177
+ );
16178
+ }
16179
+ }
16180
+ }
16181
+ /**
16182
+ * Accept an extension negotiation offer.
16183
+ *
16184
+ * @param {Array} offers The extension negotiation offers
16185
+ * @return {Object} Accepted configuration
16186
+ * @private
16187
+ */
16188
+ acceptAsServer(offers) {
16189
+ const opts = this._options;
16190
+ const accepted = offers.find((params) => {
16191
+ if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
16192
+ return false;
16193
+ }
16194
+ return true;
16195
+ });
16196
+ if (!accepted) {
16197
+ throw new Error("None of the extension offers can be accepted");
16198
+ }
16199
+ if (opts.serverNoContextTakeover) {
16200
+ accepted.server_no_context_takeover = true;
16201
+ }
16202
+ if (opts.clientNoContextTakeover) {
16203
+ accepted.client_no_context_takeover = true;
16204
+ }
16205
+ if (typeof opts.serverMaxWindowBits === "number") {
16206
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
16207
+ }
16208
+ if (typeof opts.clientMaxWindowBits === "number") {
16209
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
16210
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
16211
+ delete accepted.client_max_window_bits;
16212
+ }
16213
+ return accepted;
16214
+ }
16215
+ /**
16216
+ * Accept the extension negotiation response.
16217
+ *
16218
+ * @param {Array} response The extension negotiation response
16219
+ * @return {Object} Accepted configuration
16220
+ * @private
16221
+ */
16222
+ acceptAsClient(response) {
16223
+ const params = response[0];
16224
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
16225
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
16226
+ }
16227
+ if (!params.client_max_window_bits) {
16228
+ if (typeof this._options.clientMaxWindowBits === "number") {
16229
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
16230
+ }
16231
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
16232
+ throw new Error(
16233
+ 'Unexpected or invalid parameter "client_max_window_bits"'
16234
+ );
16235
+ }
16236
+ return params;
16237
+ }
16238
+ /**
16239
+ * Normalize parameters.
16240
+ *
16241
+ * @param {Array} configurations The extension negotiation offers/reponse
16242
+ * @return {Array} The offers/response with normalized parameters
16243
+ * @private
16244
+ */
16245
+ normalizeParams(configurations) {
16246
+ configurations.forEach((params) => {
16247
+ Object.keys(params).forEach((key) => {
16248
+ let value = params[key];
16249
+ if (value.length > 1) {
16250
+ throw new Error(`Parameter "${key}" must have only a single value`);
16251
+ }
16252
+ value = value[0];
16253
+ if (key === "client_max_window_bits") {
16254
+ if (value !== true) {
16255
+ const num = +value;
16256
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
16257
+ throw new TypeError(
16258
+ `Invalid value for parameter "${key}": ${value}`
16259
+ );
16260
+ }
16261
+ value = num;
16262
+ } else if (!this._isServer) {
16263
+ throw new TypeError(
16264
+ `Invalid value for parameter "${key}": ${value}`
16265
+ );
16266
+ }
16267
+ } else if (key === "server_max_window_bits") {
16268
+ const num = +value;
16269
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
16270
+ throw new TypeError(
16271
+ `Invalid value for parameter "${key}": ${value}`
16272
+ );
16273
+ }
16274
+ value = num;
16275
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
16276
+ if (value !== true) {
16277
+ throw new TypeError(
16278
+ `Invalid value for parameter "${key}": ${value}`
16279
+ );
16280
+ }
16281
+ } else {
16282
+ throw new Error(`Unknown parameter "${key}"`);
16283
+ }
16284
+ params[key] = value;
16285
+ });
16286
+ });
16287
+ return configurations;
16288
+ }
16289
+ /**
16290
+ * Decompress data. Concurrency limited.
16291
+ *
16292
+ * @param {Buffer} data Compressed data
16293
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
16294
+ * @param {Function} callback Callback
16295
+ * @public
16296
+ */
16297
+ decompress(data, fin, callback) {
16298
+ zlibLimiter.add((done) => {
16299
+ this._decompress(data, fin, (err, result) => {
16300
+ done();
16301
+ callback(err, result);
16302
+ });
16303
+ });
16304
+ }
16305
+ /**
16306
+ * Compress data. Concurrency limited.
16307
+ *
16308
+ * @param {(Buffer|String)} data Data to compress
16309
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
16310
+ * @param {Function} callback Callback
16311
+ * @public
16312
+ */
16313
+ compress(data, fin, callback) {
16314
+ zlibLimiter.add((done) => {
16315
+ this._compress(data, fin, (err, result) => {
16316
+ done();
16317
+ callback(err, result);
16318
+ });
16319
+ });
16320
+ }
16321
+ /**
16322
+ * Decompress data.
16323
+ *
16324
+ * @param {Buffer} data Compressed data
16325
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
16326
+ * @param {Function} callback Callback
16327
+ * @private
16328
+ */
16329
+ _decompress(data, fin, callback) {
16330
+ const endpoint = this._isServer ? "client" : "server";
16331
+ if (!this._inflate) {
16332
+ const key = `${endpoint}_max_window_bits`;
16333
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
16334
+ this._inflate = zlib.createInflateRaw({
16335
+ ...this._options.zlibInflateOptions,
16336
+ windowBits
16337
+ });
16338
+ this._inflate[kPerMessageDeflate] = this;
16339
+ this._inflate[kTotalLength] = 0;
16340
+ this._inflate[kBuffers] = [];
16341
+ this._inflate.on("error", inflateOnError);
16342
+ this._inflate.on("data", inflateOnData);
16343
+ }
16344
+ this._inflate[kCallback] = callback;
16345
+ this._inflate.write(data);
16346
+ if (fin) this._inflate.write(TRAILER);
16347
+ this._inflate.flush(() => {
16348
+ const err = this._inflate[kError];
16349
+ if (err) {
16350
+ this._inflate.close();
16351
+ this._inflate = null;
16352
+ callback(err);
16353
+ return;
16354
+ }
16355
+ const data2 = bufferUtil.concat(
16356
+ this._inflate[kBuffers],
16357
+ this._inflate[kTotalLength]
16358
+ );
16359
+ if (this._inflate._readableState.endEmitted) {
16360
+ this._inflate.close();
16361
+ this._inflate = null;
16362
+ } else {
16363
+ this._inflate[kTotalLength] = 0;
16364
+ this._inflate[kBuffers] = [];
16365
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
16366
+ this._inflate.reset();
16367
+ }
16368
+ }
16369
+ callback(null, data2);
16370
+ });
16371
+ }
16372
+ /**
16373
+ * Compress data.
16374
+ *
16375
+ * @param {(Buffer|String)} data Data to compress
16376
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
16377
+ * @param {Function} callback Callback
16378
+ * @private
16379
+ */
16380
+ _compress(data, fin, callback) {
16381
+ const endpoint = this._isServer ? "server" : "client";
16382
+ if (!this._deflate) {
16383
+ const key = `${endpoint}_max_window_bits`;
16384
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
16385
+ this._deflate = zlib.createDeflateRaw({
16386
+ ...this._options.zlibDeflateOptions,
16387
+ windowBits
16388
+ });
16389
+ this._deflate[kTotalLength] = 0;
16390
+ this._deflate[kBuffers] = [];
16391
+ this._deflate.on("data", deflateOnData);
16392
+ }
16393
+ this._deflate[kCallback] = callback;
16394
+ this._deflate.write(data);
16395
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
16396
+ if (!this._deflate) {
16397
+ return;
16398
+ }
16399
+ let data2 = bufferUtil.concat(
16400
+ this._deflate[kBuffers],
16401
+ this._deflate[kTotalLength]
16402
+ );
16403
+ if (fin) {
16404
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
16405
+ }
16406
+ this._deflate[kCallback] = null;
16407
+ this._deflate[kTotalLength] = 0;
16408
+ this._deflate[kBuffers] = [];
16409
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
16410
+ this._deflate.reset();
16411
+ }
16412
+ callback(null, data2);
16413
+ });
16414
+ }
16415
+ };
16416
+ module2.exports = PerMessageDeflate;
16417
+ function deflateOnData(chunk) {
16418
+ this[kBuffers].push(chunk);
16419
+ this[kTotalLength] += chunk.length;
16420
+ }
16421
+ function inflateOnData(chunk) {
16422
+ this[kTotalLength] += chunk.length;
16423
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
16424
+ this[kBuffers].push(chunk);
16425
+ return;
16426
+ }
16427
+ this[kError] = new RangeError("Max payload size exceeded");
16428
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
16429
+ this[kError][kStatusCode] = 1009;
16430
+ this.removeListener("data", inflateOnData);
16431
+ this.reset();
16432
+ }
16433
+ function inflateOnError(err) {
16434
+ this[kPerMessageDeflate]._inflate = null;
16435
+ if (this[kError]) {
16436
+ this[kCallback](this[kError]);
16437
+ return;
16438
+ }
16439
+ err[kStatusCode] = 1007;
16440
+ this[kCallback](err);
16441
+ }
16442
+ }
16443
+ });
16444
+
16445
+ // node_modules/ws/lib/validation.js
16446
+ var require_validation = __commonJS({
16447
+ "node_modules/ws/lib/validation.js"(exports2, module2) {
16448
+ "use strict";
16449
+ var { isUtf8 } = require("buffer");
16450
+ var { hasBlob } = require_constants();
16451
+ var tokenChars = [
16452
+ 0,
16453
+ 0,
16454
+ 0,
16455
+ 0,
16456
+ 0,
16457
+ 0,
16458
+ 0,
16459
+ 0,
16460
+ 0,
16461
+ 0,
16462
+ 0,
16463
+ 0,
16464
+ 0,
16465
+ 0,
16466
+ 0,
16467
+ 0,
16468
+ // 0 - 15
16469
+ 0,
16470
+ 0,
16471
+ 0,
16472
+ 0,
16473
+ 0,
16474
+ 0,
16475
+ 0,
16476
+ 0,
16477
+ 0,
16478
+ 0,
16479
+ 0,
16480
+ 0,
16481
+ 0,
16482
+ 0,
16483
+ 0,
16484
+ 0,
16485
+ // 16 - 31
16486
+ 0,
16487
+ 1,
16488
+ 0,
16489
+ 1,
16490
+ 1,
16491
+ 1,
16492
+ 1,
16493
+ 1,
16494
+ 0,
16495
+ 0,
16496
+ 1,
16497
+ 1,
16498
+ 0,
16499
+ 1,
16500
+ 1,
16501
+ 0,
16502
+ // 32 - 47
16503
+ 1,
16504
+ 1,
16505
+ 1,
16506
+ 1,
16507
+ 1,
16508
+ 1,
16509
+ 1,
16510
+ 1,
16511
+ 1,
16512
+ 1,
16513
+ 0,
16514
+ 0,
16515
+ 0,
16516
+ 0,
16517
+ 0,
16518
+ 0,
16519
+ // 48 - 63
16520
+ 0,
16521
+ 1,
16522
+ 1,
16523
+ 1,
16524
+ 1,
16525
+ 1,
16526
+ 1,
16527
+ 1,
16528
+ 1,
16529
+ 1,
16530
+ 1,
16531
+ 1,
16532
+ 1,
16533
+ 1,
16534
+ 1,
16535
+ 1,
16536
+ // 64 - 79
16537
+ 1,
16538
+ 1,
16539
+ 1,
16540
+ 1,
16541
+ 1,
16542
+ 1,
16543
+ 1,
16544
+ 1,
16545
+ 1,
16546
+ 1,
16547
+ 1,
16548
+ 0,
16549
+ 0,
16550
+ 0,
16551
+ 1,
16552
+ 1,
16553
+ // 80 - 95
16554
+ 1,
16555
+ 1,
16556
+ 1,
16557
+ 1,
16558
+ 1,
16559
+ 1,
16560
+ 1,
16561
+ 1,
16562
+ 1,
16563
+ 1,
16564
+ 1,
16565
+ 1,
16566
+ 1,
16567
+ 1,
16568
+ 1,
16569
+ 1,
16570
+ // 96 - 111
16571
+ 1,
16572
+ 1,
16573
+ 1,
16574
+ 1,
16575
+ 1,
16576
+ 1,
16577
+ 1,
16578
+ 1,
16579
+ 1,
16580
+ 1,
16581
+ 1,
16582
+ 0,
16583
+ 1,
16584
+ 0,
16585
+ 1,
16586
+ 0
16587
+ // 112 - 127
16588
+ ];
16589
+ function isValidStatusCode(code) {
16590
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
16591
+ }
16592
+ function _isValidUTF8(buf) {
16593
+ const len = buf.length;
16594
+ let i = 0;
16595
+ while (i < len) {
16596
+ if ((buf[i] & 128) === 0) {
16597
+ i++;
16598
+ } else if ((buf[i] & 224) === 192) {
16599
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
16600
+ return false;
16601
+ }
16602
+ i += 2;
16603
+ } else if ((buf[i] & 240) === 224) {
16604
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
16605
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
16606
+ return false;
16607
+ }
16608
+ i += 3;
16609
+ } else if ((buf[i] & 248) === 240) {
16610
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
16611
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
16612
+ return false;
16613
+ }
16614
+ i += 4;
16615
+ } else {
16616
+ return false;
16617
+ }
16618
+ }
16619
+ return true;
16620
+ }
16621
+ function isBlob(value) {
16622
+ return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
16623
+ }
16624
+ module2.exports = {
16625
+ isBlob,
16626
+ isValidStatusCode,
16627
+ isValidUTF8: _isValidUTF8,
16628
+ tokenChars
16629
+ };
16630
+ if (isUtf8) {
16631
+ module2.exports.isValidUTF8 = function(buf) {
16632
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
16633
+ };
16634
+ } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
16635
+ try {
16636
+ const isValidUTF8 = require("utf-8-validate");
16637
+ module2.exports.isValidUTF8 = function(buf) {
16638
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
16639
+ };
16640
+ } catch (e) {
16641
+ }
16642
+ }
16643
+ }
16644
+ });
16645
+
16646
+ // node_modules/ws/lib/receiver.js
16647
+ var require_receiver = __commonJS({
16648
+ "node_modules/ws/lib/receiver.js"(exports2, module2) {
16649
+ "use strict";
16650
+ var { Writable } = require("stream");
16651
+ var PerMessageDeflate = require_permessage_deflate();
16652
+ var {
16653
+ BINARY_TYPES,
16654
+ EMPTY_BUFFER,
16655
+ kStatusCode,
16656
+ kWebSocket
16657
+ } = require_constants();
16658
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
16659
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
16660
+ var FastBuffer = Buffer[Symbol.species];
16661
+ var GET_INFO = 0;
16662
+ var GET_PAYLOAD_LENGTH_16 = 1;
16663
+ var GET_PAYLOAD_LENGTH_64 = 2;
16664
+ var GET_MASK = 3;
16665
+ var GET_DATA = 4;
16666
+ var INFLATING = 5;
16667
+ var DEFER_EVENT = 6;
16668
+ var Receiver2 = class extends Writable {
16669
+ /**
16670
+ * Creates a Receiver instance.
16671
+ *
16672
+ * @param {Object} [options] Options object
16673
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
16674
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
16675
+ * multiple times in the same tick
16676
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
16677
+ * @param {Object} [options.extensions] An object containing the negotiated
16678
+ * extensions
16679
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
16680
+ * client or server mode
16681
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
16682
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
16683
+ * not to skip UTF-8 validation for text and close messages
16684
+ */
16685
+ constructor(options = {}) {
16686
+ super();
16687
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
16688
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
16689
+ this._extensions = options.extensions || {};
16690
+ this._isServer = !!options.isServer;
16691
+ this._maxPayload = options.maxPayload | 0;
16692
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
16693
+ this[kWebSocket] = void 0;
16694
+ this._bufferedBytes = 0;
16695
+ this._buffers = [];
16696
+ this._compressed = false;
16697
+ this._payloadLength = 0;
16698
+ this._mask = void 0;
16699
+ this._fragmented = 0;
16700
+ this._masked = false;
16701
+ this._fin = false;
16702
+ this._opcode = 0;
16703
+ this._totalPayloadLength = 0;
16704
+ this._messageLength = 0;
16705
+ this._fragments = [];
16706
+ this._errored = false;
16707
+ this._loop = false;
16708
+ this._state = GET_INFO;
16709
+ }
16710
+ /**
16711
+ * Implements `Writable.prototype._write()`.
16712
+ *
16713
+ * @param {Buffer} chunk The chunk of data to write
16714
+ * @param {String} encoding The character encoding of `chunk`
16715
+ * @param {Function} cb Callback
16716
+ * @private
16717
+ */
16718
+ _write(chunk, encoding, cb) {
16719
+ if (this._opcode === 8 && this._state == GET_INFO) return cb();
16720
+ this._bufferedBytes += chunk.length;
16721
+ this._buffers.push(chunk);
16722
+ this.startLoop(cb);
16723
+ }
16724
+ /**
16725
+ * Consumes `n` bytes from the buffered data.
16726
+ *
16727
+ * @param {Number} n The number of bytes to consume
16728
+ * @return {Buffer} The consumed bytes
16729
+ * @private
16730
+ */
16731
+ consume(n) {
16732
+ this._bufferedBytes -= n;
16733
+ if (n === this._buffers[0].length) return this._buffers.shift();
16734
+ if (n < this._buffers[0].length) {
16735
+ const buf = this._buffers[0];
16736
+ this._buffers[0] = new FastBuffer(
16737
+ buf.buffer,
16738
+ buf.byteOffset + n,
16739
+ buf.length - n
16740
+ );
16741
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
16742
+ }
16743
+ const dst = Buffer.allocUnsafe(n);
16744
+ do {
16745
+ const buf = this._buffers[0];
16746
+ const offset = dst.length - n;
16747
+ if (n >= buf.length) {
16748
+ dst.set(this._buffers.shift(), offset);
16749
+ } else {
16750
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
16751
+ this._buffers[0] = new FastBuffer(
16752
+ buf.buffer,
16753
+ buf.byteOffset + n,
16754
+ buf.length - n
16755
+ );
16756
+ }
16757
+ n -= buf.length;
16758
+ } while (n > 0);
16759
+ return dst;
16760
+ }
16761
+ /**
16762
+ * Starts the parsing loop.
16763
+ *
16764
+ * @param {Function} cb Callback
16765
+ * @private
16766
+ */
16767
+ startLoop(cb) {
16768
+ this._loop = true;
16769
+ do {
16770
+ switch (this._state) {
16771
+ case GET_INFO:
16772
+ this.getInfo(cb);
16773
+ break;
16774
+ case GET_PAYLOAD_LENGTH_16:
16775
+ this.getPayloadLength16(cb);
16776
+ break;
16777
+ case GET_PAYLOAD_LENGTH_64:
16778
+ this.getPayloadLength64(cb);
16779
+ break;
16780
+ case GET_MASK:
16781
+ this.getMask();
16782
+ break;
16783
+ case GET_DATA:
16784
+ this.getData(cb);
16785
+ break;
16786
+ case INFLATING:
16787
+ case DEFER_EVENT:
16788
+ this._loop = false;
16789
+ return;
16790
+ }
16791
+ } while (this._loop);
16792
+ if (!this._errored) cb();
16793
+ }
16794
+ /**
16795
+ * Reads the first two bytes of a frame.
16796
+ *
16797
+ * @param {Function} cb Callback
16798
+ * @private
16799
+ */
16800
+ getInfo(cb) {
16801
+ if (this._bufferedBytes < 2) {
16802
+ this._loop = false;
16803
+ return;
16804
+ }
16805
+ const buf = this.consume(2);
16806
+ if ((buf[0] & 48) !== 0) {
16807
+ const error48 = this.createError(
16808
+ RangeError,
16809
+ "RSV2 and RSV3 must be clear",
16810
+ true,
16811
+ 1002,
16812
+ "WS_ERR_UNEXPECTED_RSV_2_3"
16813
+ );
16814
+ cb(error48);
16815
+ return;
16816
+ }
16817
+ const compressed = (buf[0] & 64) === 64;
16818
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
16819
+ const error48 = this.createError(
16820
+ RangeError,
16821
+ "RSV1 must be clear",
16822
+ true,
16823
+ 1002,
16824
+ "WS_ERR_UNEXPECTED_RSV_1"
16825
+ );
16826
+ cb(error48);
16827
+ return;
16828
+ }
16829
+ this._fin = (buf[0] & 128) === 128;
16830
+ this._opcode = buf[0] & 15;
16831
+ this._payloadLength = buf[1] & 127;
16832
+ if (this._opcode === 0) {
16833
+ if (compressed) {
16834
+ const error48 = this.createError(
16835
+ RangeError,
16836
+ "RSV1 must be clear",
16837
+ true,
16838
+ 1002,
16839
+ "WS_ERR_UNEXPECTED_RSV_1"
16840
+ );
16841
+ cb(error48);
16842
+ return;
16843
+ }
16844
+ if (!this._fragmented) {
16845
+ const error48 = this.createError(
16846
+ RangeError,
16847
+ "invalid opcode 0",
16848
+ true,
16849
+ 1002,
16850
+ "WS_ERR_INVALID_OPCODE"
16851
+ );
16852
+ cb(error48);
16853
+ return;
16854
+ }
16855
+ this._opcode = this._fragmented;
16856
+ } else if (this._opcode === 1 || this._opcode === 2) {
16857
+ if (this._fragmented) {
16858
+ const error48 = this.createError(
16859
+ RangeError,
16860
+ `invalid opcode ${this._opcode}`,
16861
+ true,
16862
+ 1002,
16863
+ "WS_ERR_INVALID_OPCODE"
16864
+ );
16865
+ cb(error48);
16866
+ return;
16867
+ }
16868
+ this._compressed = compressed;
16869
+ } else if (this._opcode > 7 && this._opcode < 11) {
16870
+ if (!this._fin) {
16871
+ const error48 = this.createError(
16872
+ RangeError,
16873
+ "FIN must be set",
16874
+ true,
16875
+ 1002,
16876
+ "WS_ERR_EXPECTED_FIN"
16877
+ );
16878
+ cb(error48);
16879
+ return;
16880
+ }
16881
+ if (compressed) {
16882
+ const error48 = this.createError(
16883
+ RangeError,
16884
+ "RSV1 must be clear",
16885
+ true,
16886
+ 1002,
16887
+ "WS_ERR_UNEXPECTED_RSV_1"
16888
+ );
16889
+ cb(error48);
16890
+ return;
16891
+ }
16892
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
16893
+ const error48 = this.createError(
16894
+ RangeError,
16895
+ `invalid payload length ${this._payloadLength}`,
16896
+ true,
16897
+ 1002,
16898
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
16899
+ );
16900
+ cb(error48);
16901
+ return;
16902
+ }
16903
+ } else {
16904
+ const error48 = this.createError(
16905
+ RangeError,
16906
+ `invalid opcode ${this._opcode}`,
16907
+ true,
16908
+ 1002,
16909
+ "WS_ERR_INVALID_OPCODE"
16910
+ );
16911
+ cb(error48);
16912
+ return;
16913
+ }
16914
+ if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
16915
+ this._masked = (buf[1] & 128) === 128;
16916
+ if (this._isServer) {
16917
+ if (!this._masked) {
16918
+ const error48 = this.createError(
16919
+ RangeError,
16920
+ "MASK must be set",
16921
+ true,
16922
+ 1002,
16923
+ "WS_ERR_EXPECTED_MASK"
16924
+ );
16925
+ cb(error48);
16926
+ return;
16927
+ }
16928
+ } else if (this._masked) {
16929
+ const error48 = this.createError(
16930
+ RangeError,
16931
+ "MASK must be clear",
16932
+ true,
16933
+ 1002,
16934
+ "WS_ERR_UNEXPECTED_MASK"
16935
+ );
16936
+ cb(error48);
16937
+ return;
16938
+ }
16939
+ if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
16940
+ else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
16941
+ else this.haveLength(cb);
16942
+ }
16943
+ /**
16944
+ * Gets extended payload length (7+16).
16945
+ *
16946
+ * @param {Function} cb Callback
16947
+ * @private
16948
+ */
16949
+ getPayloadLength16(cb) {
16950
+ if (this._bufferedBytes < 2) {
16951
+ this._loop = false;
16952
+ return;
16953
+ }
16954
+ this._payloadLength = this.consume(2).readUInt16BE(0);
16955
+ this.haveLength(cb);
16956
+ }
16957
+ /**
16958
+ * Gets extended payload length (7+64).
16959
+ *
16960
+ * @param {Function} cb Callback
16961
+ * @private
16962
+ */
16963
+ getPayloadLength64(cb) {
16964
+ if (this._bufferedBytes < 8) {
16965
+ this._loop = false;
16966
+ return;
16967
+ }
16968
+ const buf = this.consume(8);
16969
+ const num = buf.readUInt32BE(0);
16970
+ if (num > Math.pow(2, 53 - 32) - 1) {
16971
+ const error48 = this.createError(
16972
+ RangeError,
16973
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
16974
+ false,
16975
+ 1009,
16976
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
16977
+ );
16978
+ cb(error48);
16979
+ return;
16980
+ }
16981
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
16982
+ this.haveLength(cb);
16983
+ }
16984
+ /**
16985
+ * Payload length has been read.
16986
+ *
16987
+ * @param {Function} cb Callback
16988
+ * @private
16989
+ */
16990
+ haveLength(cb) {
16991
+ if (this._payloadLength && this._opcode < 8) {
16992
+ this._totalPayloadLength += this._payloadLength;
16993
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
16994
+ const error48 = this.createError(
16995
+ RangeError,
16996
+ "Max payload size exceeded",
16997
+ false,
16998
+ 1009,
16999
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
17000
+ );
17001
+ cb(error48);
17002
+ return;
17003
+ }
17004
+ }
17005
+ if (this._masked) this._state = GET_MASK;
17006
+ else this._state = GET_DATA;
17007
+ }
17008
+ /**
17009
+ * Reads mask bytes.
17010
+ *
17011
+ * @private
17012
+ */
17013
+ getMask() {
17014
+ if (this._bufferedBytes < 4) {
17015
+ this._loop = false;
17016
+ return;
17017
+ }
17018
+ this._mask = this.consume(4);
17019
+ this._state = GET_DATA;
17020
+ }
17021
+ /**
17022
+ * Reads data bytes.
17023
+ *
17024
+ * @param {Function} cb Callback
17025
+ * @private
17026
+ */
17027
+ getData(cb) {
17028
+ let data = EMPTY_BUFFER;
17029
+ if (this._payloadLength) {
17030
+ if (this._bufferedBytes < this._payloadLength) {
17031
+ this._loop = false;
17032
+ return;
17033
+ }
17034
+ data = this.consume(this._payloadLength);
17035
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
17036
+ unmask(data, this._mask);
17037
+ }
17038
+ }
17039
+ if (this._opcode > 7) {
17040
+ this.controlMessage(data, cb);
17041
+ return;
17042
+ }
17043
+ if (this._compressed) {
17044
+ this._state = INFLATING;
17045
+ this.decompress(data, cb);
17046
+ return;
17047
+ }
17048
+ if (data.length) {
17049
+ this._messageLength = this._totalPayloadLength;
17050
+ this._fragments.push(data);
17051
+ }
17052
+ this.dataMessage(cb);
17053
+ }
17054
+ /**
17055
+ * Decompresses data.
17056
+ *
17057
+ * @param {Buffer} data Compressed data
17058
+ * @param {Function} cb Callback
17059
+ * @private
17060
+ */
17061
+ decompress(data, cb) {
17062
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
17063
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
17064
+ if (err) return cb(err);
17065
+ if (buf.length) {
17066
+ this._messageLength += buf.length;
17067
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
17068
+ const error48 = this.createError(
17069
+ RangeError,
17070
+ "Max payload size exceeded",
17071
+ false,
17072
+ 1009,
17073
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
17074
+ );
17075
+ cb(error48);
17076
+ return;
17077
+ }
17078
+ this._fragments.push(buf);
17079
+ }
17080
+ this.dataMessage(cb);
17081
+ if (this._state === GET_INFO) this.startLoop(cb);
17082
+ });
17083
+ }
17084
+ /**
17085
+ * Handles a data message.
17086
+ *
17087
+ * @param {Function} cb Callback
17088
+ * @private
17089
+ */
17090
+ dataMessage(cb) {
17091
+ if (!this._fin) {
17092
+ this._state = GET_INFO;
17093
+ return;
17094
+ }
17095
+ const messageLength = this._messageLength;
17096
+ const fragments = this._fragments;
17097
+ this._totalPayloadLength = 0;
17098
+ this._messageLength = 0;
17099
+ this._fragmented = 0;
17100
+ this._fragments = [];
17101
+ if (this._opcode === 2) {
17102
+ let data;
17103
+ if (this._binaryType === "nodebuffer") {
17104
+ data = concat(fragments, messageLength);
17105
+ } else if (this._binaryType === "arraybuffer") {
17106
+ data = toArrayBuffer(concat(fragments, messageLength));
17107
+ } else if (this._binaryType === "blob") {
17108
+ data = new Blob(fragments);
17109
+ } else {
17110
+ data = fragments;
17111
+ }
17112
+ if (this._allowSynchronousEvents) {
17113
+ this.emit("message", data, true);
17114
+ this._state = GET_INFO;
17115
+ } else {
17116
+ this._state = DEFER_EVENT;
17117
+ setImmediate(() => {
17118
+ this.emit("message", data, true);
17119
+ this._state = GET_INFO;
17120
+ this.startLoop(cb);
17121
+ });
17122
+ }
17123
+ } else {
17124
+ const buf = concat(fragments, messageLength);
17125
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
17126
+ const error48 = this.createError(
17127
+ Error,
17128
+ "invalid UTF-8 sequence",
17129
+ true,
17130
+ 1007,
17131
+ "WS_ERR_INVALID_UTF8"
17132
+ );
17133
+ cb(error48);
17134
+ return;
17135
+ }
17136
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
17137
+ this.emit("message", buf, false);
17138
+ this._state = GET_INFO;
17139
+ } else {
17140
+ this._state = DEFER_EVENT;
17141
+ setImmediate(() => {
17142
+ this.emit("message", buf, false);
17143
+ this._state = GET_INFO;
17144
+ this.startLoop(cb);
17145
+ });
17146
+ }
17147
+ }
17148
+ }
17149
+ /**
17150
+ * Handles a control message.
17151
+ *
17152
+ * @param {Buffer} data Data to handle
17153
+ * @return {(Error|RangeError|undefined)} A possible error
17154
+ * @private
17155
+ */
17156
+ controlMessage(data, cb) {
17157
+ if (this._opcode === 8) {
17158
+ if (data.length === 0) {
17159
+ this._loop = false;
17160
+ this.emit("conclude", 1005, EMPTY_BUFFER);
17161
+ this.end();
17162
+ } else {
17163
+ const code = data.readUInt16BE(0);
17164
+ if (!isValidStatusCode(code)) {
17165
+ const error48 = this.createError(
17166
+ RangeError,
17167
+ `invalid status code ${code}`,
17168
+ true,
17169
+ 1002,
17170
+ "WS_ERR_INVALID_CLOSE_CODE"
17171
+ );
17172
+ cb(error48);
17173
+ return;
17174
+ }
17175
+ const buf = new FastBuffer(
17176
+ data.buffer,
17177
+ data.byteOffset + 2,
17178
+ data.length - 2
17179
+ );
17180
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
17181
+ const error48 = this.createError(
17182
+ Error,
17183
+ "invalid UTF-8 sequence",
17184
+ true,
17185
+ 1007,
17186
+ "WS_ERR_INVALID_UTF8"
17187
+ );
17188
+ cb(error48);
17189
+ return;
17190
+ }
17191
+ this._loop = false;
17192
+ this.emit("conclude", code, buf);
17193
+ this.end();
17194
+ }
17195
+ this._state = GET_INFO;
17196
+ return;
17197
+ }
17198
+ if (this._allowSynchronousEvents) {
17199
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
17200
+ this._state = GET_INFO;
17201
+ } else {
17202
+ this._state = DEFER_EVENT;
17203
+ setImmediate(() => {
17204
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
17205
+ this._state = GET_INFO;
17206
+ this.startLoop(cb);
17207
+ });
17208
+ }
17209
+ }
17210
+ /**
17211
+ * Builds an error object.
17212
+ *
17213
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
17214
+ * @param {String} message The error message
17215
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
17216
+ * `message`
17217
+ * @param {Number} statusCode The status code
17218
+ * @param {String} errorCode The exposed error code
17219
+ * @return {(Error|RangeError)} The error
17220
+ * @private
17221
+ */
17222
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
17223
+ this._loop = false;
17224
+ this._errored = true;
17225
+ const err = new ErrorCtor(
17226
+ prefix ? `Invalid WebSocket frame: ${message}` : message
17227
+ );
17228
+ Error.captureStackTrace(err, this.createError);
17229
+ err.code = errorCode;
17230
+ err[kStatusCode] = statusCode;
17231
+ return err;
17232
+ }
17233
+ };
17234
+ module2.exports = Receiver2;
17235
+ }
17236
+ });
17237
+
17238
+ // node_modules/ws/lib/sender.js
17239
+ var require_sender = __commonJS({
17240
+ "node_modules/ws/lib/sender.js"(exports2, module2) {
17241
+ "use strict";
17242
+ var { Duplex } = require("stream");
17243
+ var { randomFillSync } = require("crypto");
17244
+ var PerMessageDeflate = require_permessage_deflate();
17245
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
17246
+ var { isBlob, isValidStatusCode } = require_validation();
17247
+ var { mask: applyMask, toBuffer } = require_buffer_util();
17248
+ var kByteLength = /* @__PURE__ */ Symbol("kByteLength");
17249
+ var maskBuffer = Buffer.alloc(4);
17250
+ var RANDOM_POOL_SIZE = 8 * 1024;
17251
+ var randomPool;
17252
+ var randomPoolPointer = RANDOM_POOL_SIZE;
17253
+ var DEFAULT = 0;
17254
+ var DEFLATING = 1;
17255
+ var GET_BLOB_DATA = 2;
17256
+ var Sender2 = class _Sender {
17257
+ /**
17258
+ * Creates a Sender instance.
17259
+ *
17260
+ * @param {Duplex} socket The connection socket
17261
+ * @param {Object} [extensions] An object containing the negotiated extensions
17262
+ * @param {Function} [generateMask] The function used to generate the masking
17263
+ * key
17264
+ */
17265
+ constructor(socket, extensions, generateMask) {
17266
+ this._extensions = extensions || {};
17267
+ if (generateMask) {
17268
+ this._generateMask = generateMask;
17269
+ this._maskBuffer = Buffer.alloc(4);
17270
+ }
17271
+ this._socket = socket;
17272
+ this._firstFragment = true;
17273
+ this._compress = false;
17274
+ this._bufferedBytes = 0;
17275
+ this._queue = [];
17276
+ this._state = DEFAULT;
17277
+ this.onerror = NOOP;
17278
+ this[kWebSocket] = void 0;
17279
+ }
17280
+ /**
17281
+ * Frames a piece of data according to the HyBi WebSocket protocol.
17282
+ *
17283
+ * @param {(Buffer|String)} data The data to frame
17284
+ * @param {Object} options Options object
17285
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
17286
+ * FIN bit
17287
+ * @param {Function} [options.generateMask] The function used to generate the
17288
+ * masking key
17289
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
17290
+ * `data`
17291
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
17292
+ * key
17293
+ * @param {Number} options.opcode The opcode
17294
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
17295
+ * modified
17296
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
17297
+ * RSV1 bit
17298
+ * @return {(Buffer|String)[]} The framed data
17299
+ * @public
17300
+ */
17301
+ static frame(data, options) {
17302
+ let mask;
17303
+ let merge2 = false;
17304
+ let offset = 2;
17305
+ let skipMasking = false;
17306
+ if (options.mask) {
17307
+ mask = options.maskBuffer || maskBuffer;
17308
+ if (options.generateMask) {
17309
+ options.generateMask(mask);
17310
+ } else {
17311
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
17312
+ if (randomPool === void 0) {
17313
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
17314
+ }
17315
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
17316
+ randomPoolPointer = 0;
17317
+ }
17318
+ mask[0] = randomPool[randomPoolPointer++];
17319
+ mask[1] = randomPool[randomPoolPointer++];
17320
+ mask[2] = randomPool[randomPoolPointer++];
17321
+ mask[3] = randomPool[randomPoolPointer++];
17322
+ }
17323
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
17324
+ offset = 6;
17325
+ }
17326
+ let dataLength;
17327
+ if (typeof data === "string") {
17328
+ if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
17329
+ dataLength = options[kByteLength];
17330
+ } else {
17331
+ data = Buffer.from(data);
17332
+ dataLength = data.length;
17333
+ }
17334
+ } else {
17335
+ dataLength = data.length;
17336
+ merge2 = options.mask && options.readOnly && !skipMasking;
17337
+ }
17338
+ let payloadLength = dataLength;
17339
+ if (dataLength >= 65536) {
17340
+ offset += 8;
17341
+ payloadLength = 127;
17342
+ } else if (dataLength > 125) {
17343
+ offset += 2;
17344
+ payloadLength = 126;
17345
+ }
17346
+ const target = Buffer.allocUnsafe(merge2 ? dataLength + offset : offset);
17347
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
17348
+ if (options.rsv1) target[0] |= 64;
17349
+ target[1] = payloadLength;
17350
+ if (payloadLength === 126) {
17351
+ target.writeUInt16BE(dataLength, 2);
17352
+ } else if (payloadLength === 127) {
17353
+ target[2] = target[3] = 0;
17354
+ target.writeUIntBE(dataLength, 4, 6);
17355
+ }
17356
+ if (!options.mask) return [target, data];
17357
+ target[1] |= 128;
17358
+ target[offset - 4] = mask[0];
17359
+ target[offset - 3] = mask[1];
17360
+ target[offset - 2] = mask[2];
17361
+ target[offset - 1] = mask[3];
17362
+ if (skipMasking) return [target, data];
17363
+ if (merge2) {
17364
+ applyMask(data, mask, target, offset, dataLength);
17365
+ return [target];
17366
+ }
17367
+ applyMask(data, mask, data, 0, dataLength);
17368
+ return [target, data];
17369
+ }
17370
+ /**
17371
+ * Sends a close message to the other peer.
17372
+ *
17373
+ * @param {Number} [code] The status code component of the body
17374
+ * @param {(String|Buffer)} [data] The message component of the body
17375
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
17376
+ * @param {Function} [cb] Callback
17377
+ * @public
17378
+ */
17379
+ close(code, data, mask, cb) {
17380
+ let buf;
17381
+ if (code === void 0) {
17382
+ buf = EMPTY_BUFFER;
17383
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
17384
+ throw new TypeError("First argument must be a valid error code number");
17385
+ } else if (data === void 0 || !data.length) {
17386
+ buf = Buffer.allocUnsafe(2);
17387
+ buf.writeUInt16BE(code, 0);
17388
+ } else {
17389
+ const length = Buffer.byteLength(data);
17390
+ if (length > 123) {
17391
+ throw new RangeError("The message must not be greater than 123 bytes");
17392
+ }
17393
+ buf = Buffer.allocUnsafe(2 + length);
17394
+ buf.writeUInt16BE(code, 0);
17395
+ if (typeof data === "string") {
17396
+ buf.write(data, 2);
17397
+ } else {
17398
+ buf.set(data, 2);
17399
+ }
17400
+ }
17401
+ const options = {
17402
+ [kByteLength]: buf.length,
17403
+ fin: true,
17404
+ generateMask: this._generateMask,
17405
+ mask,
17406
+ maskBuffer: this._maskBuffer,
17407
+ opcode: 8,
17408
+ readOnly: false,
17409
+ rsv1: false
17410
+ };
17411
+ if (this._state !== DEFAULT) {
17412
+ this.enqueue([this.dispatch, buf, false, options, cb]);
17413
+ } else {
17414
+ this.sendFrame(_Sender.frame(buf, options), cb);
17415
+ }
17416
+ }
17417
+ /**
17418
+ * Sends a ping message to the other peer.
17419
+ *
17420
+ * @param {*} data The message to send
17421
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
17422
+ * @param {Function} [cb] Callback
17423
+ * @public
17424
+ */
17425
+ ping(data, mask, cb) {
17426
+ let byteLength;
17427
+ let readOnly;
17428
+ if (typeof data === "string") {
17429
+ byteLength = Buffer.byteLength(data);
17430
+ readOnly = false;
17431
+ } else if (isBlob(data)) {
17432
+ byteLength = data.size;
17433
+ readOnly = false;
17434
+ } else {
17435
+ data = toBuffer(data);
17436
+ byteLength = data.length;
17437
+ readOnly = toBuffer.readOnly;
17438
+ }
17439
+ if (byteLength > 125) {
17440
+ throw new RangeError("The data size must not be greater than 125 bytes");
17441
+ }
17442
+ const options = {
17443
+ [kByteLength]: byteLength,
17444
+ fin: true,
17445
+ generateMask: this._generateMask,
17446
+ mask,
17447
+ maskBuffer: this._maskBuffer,
17448
+ opcode: 9,
17449
+ readOnly,
17450
+ rsv1: false
17451
+ };
17452
+ if (isBlob(data)) {
17453
+ if (this._state !== DEFAULT) {
17454
+ this.enqueue([this.getBlobData, data, false, options, cb]);
17455
+ } else {
17456
+ this.getBlobData(data, false, options, cb);
17457
+ }
17458
+ } else if (this._state !== DEFAULT) {
17459
+ this.enqueue([this.dispatch, data, false, options, cb]);
17460
+ } else {
17461
+ this.sendFrame(_Sender.frame(data, options), cb);
17462
+ }
17463
+ }
17464
+ /**
17465
+ * Sends a pong message to the other peer.
17466
+ *
17467
+ * @param {*} data The message to send
17468
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
17469
+ * @param {Function} [cb] Callback
17470
+ * @public
17471
+ */
17472
+ pong(data, mask, cb) {
17473
+ let byteLength;
17474
+ let readOnly;
17475
+ if (typeof data === "string") {
17476
+ byteLength = Buffer.byteLength(data);
17477
+ readOnly = false;
17478
+ } else if (isBlob(data)) {
17479
+ byteLength = data.size;
17480
+ readOnly = false;
17481
+ } else {
17482
+ data = toBuffer(data);
17483
+ byteLength = data.length;
17484
+ readOnly = toBuffer.readOnly;
17485
+ }
17486
+ if (byteLength > 125) {
17487
+ throw new RangeError("The data size must not be greater than 125 bytes");
17488
+ }
17489
+ const options = {
17490
+ [kByteLength]: byteLength,
17491
+ fin: true,
17492
+ generateMask: this._generateMask,
17493
+ mask,
17494
+ maskBuffer: this._maskBuffer,
17495
+ opcode: 10,
17496
+ readOnly,
17497
+ rsv1: false
17498
+ };
17499
+ if (isBlob(data)) {
17500
+ if (this._state !== DEFAULT) {
17501
+ this.enqueue([this.getBlobData, data, false, options, cb]);
17502
+ } else {
17503
+ this.getBlobData(data, false, options, cb);
17504
+ }
17505
+ } else if (this._state !== DEFAULT) {
17506
+ this.enqueue([this.dispatch, data, false, options, cb]);
17507
+ } else {
17508
+ this.sendFrame(_Sender.frame(data, options), cb);
17509
+ }
17510
+ }
17511
+ /**
17512
+ * Sends a data message to the other peer.
17513
+ *
17514
+ * @param {*} data The message to send
17515
+ * @param {Object} options Options object
17516
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
17517
+ * or text
17518
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
17519
+ * compress `data`
17520
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
17521
+ * last one
17522
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
17523
+ * `data`
17524
+ * @param {Function} [cb] Callback
17525
+ * @public
17526
+ */
17527
+ send(data, options, cb) {
17528
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
17529
+ let opcode = options.binary ? 2 : 1;
17530
+ let rsv1 = options.compress;
17531
+ let byteLength;
17532
+ let readOnly;
17533
+ if (typeof data === "string") {
17534
+ byteLength = Buffer.byteLength(data);
17535
+ readOnly = false;
17536
+ } else if (isBlob(data)) {
17537
+ byteLength = data.size;
17538
+ readOnly = false;
17539
+ } else {
17540
+ data = toBuffer(data);
17541
+ byteLength = data.length;
17542
+ readOnly = toBuffer.readOnly;
17543
+ }
17544
+ if (this._firstFragment) {
17545
+ this._firstFragment = false;
17546
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
17547
+ rsv1 = byteLength >= perMessageDeflate._threshold;
17548
+ }
17549
+ this._compress = rsv1;
17550
+ } else {
17551
+ rsv1 = false;
17552
+ opcode = 0;
17553
+ }
17554
+ if (options.fin) this._firstFragment = true;
17555
+ const opts = {
17556
+ [kByteLength]: byteLength,
17557
+ fin: options.fin,
17558
+ generateMask: this._generateMask,
17559
+ mask: options.mask,
17560
+ maskBuffer: this._maskBuffer,
17561
+ opcode,
17562
+ readOnly,
17563
+ rsv1
17564
+ };
17565
+ if (isBlob(data)) {
17566
+ if (this._state !== DEFAULT) {
17567
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
17568
+ } else {
17569
+ this.getBlobData(data, this._compress, opts, cb);
17570
+ }
17571
+ } else if (this._state !== DEFAULT) {
17572
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
17573
+ } else {
17574
+ this.dispatch(data, this._compress, opts, cb);
17575
+ }
17576
+ }
17577
+ /**
17578
+ * Gets the contents of a blob as binary data.
17579
+ *
17580
+ * @param {Blob} blob The blob
17581
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
17582
+ * the data
17583
+ * @param {Object} options Options object
17584
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
17585
+ * FIN bit
17586
+ * @param {Function} [options.generateMask] The function used to generate the
17587
+ * masking key
17588
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
17589
+ * `data`
17590
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
17591
+ * key
17592
+ * @param {Number} options.opcode The opcode
17593
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
17594
+ * modified
17595
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
17596
+ * RSV1 bit
17597
+ * @param {Function} [cb] Callback
17598
+ * @private
17599
+ */
17600
+ getBlobData(blob, compress, options, cb) {
17601
+ this._bufferedBytes += options[kByteLength];
17602
+ this._state = GET_BLOB_DATA;
17603
+ blob.arrayBuffer().then((arrayBuffer) => {
17604
+ if (this._socket.destroyed) {
17605
+ const err = new Error(
17606
+ "The socket was closed while the blob was being read"
17607
+ );
17608
+ process.nextTick(callCallbacks, this, err, cb);
17609
+ return;
17610
+ }
17611
+ this._bufferedBytes -= options[kByteLength];
17612
+ const data = toBuffer(arrayBuffer);
17613
+ if (!compress) {
17614
+ this._state = DEFAULT;
17615
+ this.sendFrame(_Sender.frame(data, options), cb);
17616
+ this.dequeue();
17617
+ } else {
17618
+ this.dispatch(data, compress, options, cb);
17619
+ }
17620
+ }).catch((err) => {
17621
+ process.nextTick(onError, this, err, cb);
17622
+ });
17623
+ }
17624
+ /**
17625
+ * Dispatches a message.
17626
+ *
17627
+ * @param {(Buffer|String)} data The message to send
17628
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
17629
+ * `data`
17630
+ * @param {Object} options Options object
17631
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
17632
+ * FIN bit
17633
+ * @param {Function} [options.generateMask] The function used to generate the
17634
+ * masking key
17635
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
17636
+ * `data`
17637
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
17638
+ * key
17639
+ * @param {Number} options.opcode The opcode
17640
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
17641
+ * modified
17642
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
17643
+ * RSV1 bit
17644
+ * @param {Function} [cb] Callback
17645
+ * @private
17646
+ */
17647
+ dispatch(data, compress, options, cb) {
17648
+ if (!compress) {
17649
+ this.sendFrame(_Sender.frame(data, options), cb);
17650
+ return;
17651
+ }
17652
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
17653
+ this._bufferedBytes += options[kByteLength];
17654
+ this._state = DEFLATING;
17655
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
17656
+ if (this._socket.destroyed) {
17657
+ const err = new Error(
17658
+ "The socket was closed while data was being compressed"
17659
+ );
17660
+ callCallbacks(this, err, cb);
17661
+ return;
17662
+ }
17663
+ this._bufferedBytes -= options[kByteLength];
17664
+ this._state = DEFAULT;
17665
+ options.readOnly = false;
17666
+ this.sendFrame(_Sender.frame(buf, options), cb);
17667
+ this.dequeue();
17668
+ });
17669
+ }
17670
+ /**
17671
+ * Executes queued send operations.
17672
+ *
17673
+ * @private
17674
+ */
17675
+ dequeue() {
17676
+ while (this._state === DEFAULT && this._queue.length) {
17677
+ const params = this._queue.shift();
17678
+ this._bufferedBytes -= params[3][kByteLength];
17679
+ Reflect.apply(params[0], this, params.slice(1));
17680
+ }
17681
+ }
17682
+ /**
17683
+ * Enqueues a send operation.
17684
+ *
17685
+ * @param {Array} params Send operation parameters.
17686
+ * @private
17687
+ */
17688
+ enqueue(params) {
17689
+ this._bufferedBytes += params[3][kByteLength];
17690
+ this._queue.push(params);
17691
+ }
17692
+ /**
17693
+ * Sends a frame.
17694
+ *
17695
+ * @param {(Buffer | String)[]} list The frame to send
17696
+ * @param {Function} [cb] Callback
17697
+ * @private
17698
+ */
17699
+ sendFrame(list, cb) {
17700
+ if (list.length === 2) {
17701
+ this._socket.cork();
17702
+ this._socket.write(list[0]);
17703
+ this._socket.write(list[1], cb);
17704
+ this._socket.uncork();
17705
+ } else {
17706
+ this._socket.write(list[0], cb);
17707
+ }
17708
+ }
17709
+ };
17710
+ module2.exports = Sender2;
17711
+ function callCallbacks(sender, err, cb) {
17712
+ if (typeof cb === "function") cb(err);
17713
+ for (let i = 0; i < sender._queue.length; i++) {
17714
+ const params = sender._queue[i];
17715
+ const callback = params[params.length - 1];
17716
+ if (typeof callback === "function") callback(err);
17717
+ }
17718
+ }
17719
+ function onError(sender, err, cb) {
17720
+ callCallbacks(sender, err, cb);
17721
+ sender.onerror(err);
17722
+ }
17723
+ }
17724
+ });
17725
+
17726
+ // node_modules/ws/lib/event-target.js
17727
+ var require_event_target = __commonJS({
17728
+ "node_modules/ws/lib/event-target.js"(exports2, module2) {
17729
+ "use strict";
17730
+ var { kForOnEventAttribute, kListener } = require_constants();
17731
+ var kCode = /* @__PURE__ */ Symbol("kCode");
17732
+ var kData = /* @__PURE__ */ Symbol("kData");
17733
+ var kError = /* @__PURE__ */ Symbol("kError");
17734
+ var kMessage = /* @__PURE__ */ Symbol("kMessage");
17735
+ var kReason = /* @__PURE__ */ Symbol("kReason");
17736
+ var kTarget = /* @__PURE__ */ Symbol("kTarget");
17737
+ var kType = /* @__PURE__ */ Symbol("kType");
17738
+ var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
17739
+ var Event = class {
17740
+ /**
17741
+ * Create a new `Event`.
17742
+ *
17743
+ * @param {String} type The name of the event
17744
+ * @throws {TypeError} If the `type` argument is not specified
17745
+ */
17746
+ constructor(type) {
17747
+ this[kTarget] = null;
17748
+ this[kType] = type;
17749
+ }
17750
+ /**
17751
+ * @type {*}
17752
+ */
17753
+ get target() {
17754
+ return this[kTarget];
17755
+ }
17756
+ /**
17757
+ * @type {String}
17758
+ */
17759
+ get type() {
17760
+ return this[kType];
17761
+ }
17762
+ };
17763
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
17764
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
17765
+ var CloseEvent = class extends Event {
17766
+ /**
17767
+ * Create a new `CloseEvent`.
17768
+ *
17769
+ * @param {String} type The name of the event
17770
+ * @param {Object} [options] A dictionary object that allows for setting
17771
+ * attributes via object members of the same name
17772
+ * @param {Number} [options.code=0] The status code explaining why the
17773
+ * connection was closed
17774
+ * @param {String} [options.reason=''] A human-readable string explaining why
17775
+ * the connection was closed
17776
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
17777
+ * connection was cleanly closed
17778
+ */
17779
+ constructor(type, options = {}) {
17780
+ super(type);
17781
+ this[kCode] = options.code === void 0 ? 0 : options.code;
17782
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
17783
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
17784
+ }
17785
+ /**
17786
+ * @type {Number}
17787
+ */
17788
+ get code() {
17789
+ return this[kCode];
17790
+ }
17791
+ /**
17792
+ * @type {String}
17793
+ */
17794
+ get reason() {
17795
+ return this[kReason];
17796
+ }
17797
+ /**
17798
+ * @type {Boolean}
17799
+ */
17800
+ get wasClean() {
17801
+ return this[kWasClean];
17802
+ }
17803
+ };
17804
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
17805
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
17806
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
17807
+ var ErrorEvent = class extends Event {
17808
+ /**
17809
+ * Create a new `ErrorEvent`.
17810
+ *
17811
+ * @param {String} type The name of the event
17812
+ * @param {Object} [options] A dictionary object that allows for setting
17813
+ * attributes via object members of the same name
17814
+ * @param {*} [options.error=null] The error that generated this event
17815
+ * @param {String} [options.message=''] The error message
17816
+ */
17817
+ constructor(type, options = {}) {
17818
+ super(type);
17819
+ this[kError] = options.error === void 0 ? null : options.error;
17820
+ this[kMessage] = options.message === void 0 ? "" : options.message;
17821
+ }
17822
+ /**
17823
+ * @type {*}
17824
+ */
17825
+ get error() {
17826
+ return this[kError];
17827
+ }
17828
+ /**
17829
+ * @type {String}
17830
+ */
17831
+ get message() {
17832
+ return this[kMessage];
17833
+ }
17834
+ };
17835
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
17836
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
17837
+ var MessageEvent = class extends Event {
17838
+ /**
17839
+ * Create a new `MessageEvent`.
17840
+ *
17841
+ * @param {String} type The name of the event
17842
+ * @param {Object} [options] A dictionary object that allows for setting
17843
+ * attributes via object members of the same name
17844
+ * @param {*} [options.data=null] The message content
17845
+ */
17846
+ constructor(type, options = {}) {
17847
+ super(type);
17848
+ this[kData] = options.data === void 0 ? null : options.data;
17849
+ }
17850
+ /**
17851
+ * @type {*}
17852
+ */
17853
+ get data() {
17854
+ return this[kData];
17855
+ }
17856
+ };
17857
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
17858
+ var EventTarget = {
17859
+ /**
17860
+ * Register an event listener.
17861
+ *
17862
+ * @param {String} type A string representing the event type to listen for
17863
+ * @param {(Function|Object)} handler The listener to add
17864
+ * @param {Object} [options] An options object specifies characteristics about
17865
+ * the event listener
17866
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
17867
+ * listener should be invoked at most once after being added. If `true`,
17868
+ * the listener would be automatically removed when invoked.
17869
+ * @public
17870
+ */
17871
+ addEventListener(type, handler, options = {}) {
17872
+ for (const listener of this.listeners(type)) {
17873
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
17874
+ return;
17875
+ }
17876
+ }
17877
+ let wrapper;
17878
+ if (type === "message") {
17879
+ wrapper = function onMessage(data, isBinary) {
17880
+ const event = new MessageEvent("message", {
17881
+ data: isBinary ? data : data.toString()
17882
+ });
17883
+ event[kTarget] = this;
17884
+ callListener(handler, this, event);
17885
+ };
17886
+ } else if (type === "close") {
17887
+ wrapper = function onClose(code, message) {
17888
+ const event = new CloseEvent("close", {
17889
+ code,
17890
+ reason: message.toString(),
17891
+ wasClean: this._closeFrameReceived && this._closeFrameSent
17892
+ });
17893
+ event[kTarget] = this;
17894
+ callListener(handler, this, event);
17895
+ };
17896
+ } else if (type === "error") {
17897
+ wrapper = function onError(error48) {
17898
+ const event = new ErrorEvent("error", {
17899
+ error: error48,
17900
+ message: error48.message
17901
+ });
17902
+ event[kTarget] = this;
17903
+ callListener(handler, this, event);
17904
+ };
17905
+ } else if (type === "open") {
17906
+ wrapper = function onOpen() {
17907
+ const event = new Event("open");
17908
+ event[kTarget] = this;
17909
+ callListener(handler, this, event);
17910
+ };
17911
+ } else {
17912
+ return;
17913
+ }
17914
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
17915
+ wrapper[kListener] = handler;
17916
+ if (options.once) {
17917
+ this.once(type, wrapper);
17918
+ } else {
17919
+ this.on(type, wrapper);
17920
+ }
17921
+ },
17922
+ /**
17923
+ * Remove an event listener.
17924
+ *
17925
+ * @param {String} type A string representing the event type to remove
17926
+ * @param {(Function|Object)} handler The listener to remove
17927
+ * @public
17928
+ */
17929
+ removeEventListener(type, handler) {
17930
+ for (const listener of this.listeners(type)) {
17931
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
17932
+ this.removeListener(type, listener);
17933
+ break;
17934
+ }
17935
+ }
17936
+ }
17937
+ };
17938
+ module2.exports = {
17939
+ CloseEvent,
17940
+ ErrorEvent,
17941
+ Event,
17942
+ EventTarget,
17943
+ MessageEvent
17944
+ };
17945
+ function callListener(listener, thisArg, event) {
17946
+ if (typeof listener === "object" && listener.handleEvent) {
17947
+ listener.handleEvent.call(listener, event);
17948
+ } else {
17949
+ listener.call(thisArg, event);
17950
+ }
17951
+ }
17952
+ }
17953
+ });
17954
+
17955
+ // node_modules/ws/lib/extension.js
17956
+ var require_extension = __commonJS({
17957
+ "node_modules/ws/lib/extension.js"(exports2, module2) {
17958
+ "use strict";
17959
+ var { tokenChars } = require_validation();
17960
+ function push(dest, name, elem) {
17961
+ if (dest[name] === void 0) dest[name] = [elem];
17962
+ else dest[name].push(elem);
17963
+ }
17964
+ function parse4(header) {
17965
+ const offers = /* @__PURE__ */ Object.create(null);
17966
+ let params = /* @__PURE__ */ Object.create(null);
17967
+ let mustUnescape = false;
17968
+ let isEscaping = false;
17969
+ let inQuotes = false;
17970
+ let extensionName;
17971
+ let paramName;
17972
+ let start = -1;
17973
+ let code = -1;
17974
+ let end = -1;
17975
+ let i = 0;
17976
+ for (; i < header.length; i++) {
17977
+ code = header.charCodeAt(i);
17978
+ if (extensionName === void 0) {
17979
+ if (end === -1 && tokenChars[code] === 1) {
17980
+ if (start === -1) start = i;
17981
+ } else if (i !== 0 && (code === 32 || code === 9)) {
17982
+ if (end === -1 && start !== -1) end = i;
17983
+ } else if (code === 59 || code === 44) {
17984
+ if (start === -1) {
17985
+ throw new SyntaxError(`Unexpected character at index ${i}`);
17986
+ }
17987
+ if (end === -1) end = i;
17988
+ const name = header.slice(start, end);
17989
+ if (code === 44) {
17990
+ push(offers, name, params);
17991
+ params = /* @__PURE__ */ Object.create(null);
17992
+ } else {
17993
+ extensionName = name;
17994
+ }
17995
+ start = end = -1;
17996
+ } else {
17997
+ throw new SyntaxError(`Unexpected character at index ${i}`);
17998
+ }
17999
+ } else if (paramName === void 0) {
18000
+ if (end === -1 && tokenChars[code] === 1) {
18001
+ if (start === -1) start = i;
18002
+ } else if (code === 32 || code === 9) {
18003
+ if (end === -1 && start !== -1) end = i;
18004
+ } else if (code === 59 || code === 44) {
18005
+ if (start === -1) {
18006
+ throw new SyntaxError(`Unexpected character at index ${i}`);
18007
+ }
18008
+ if (end === -1) end = i;
18009
+ push(params, header.slice(start, end), true);
18010
+ if (code === 44) {
18011
+ push(offers, extensionName, params);
18012
+ params = /* @__PURE__ */ Object.create(null);
18013
+ extensionName = void 0;
18014
+ }
18015
+ start = end = -1;
18016
+ } else if (code === 61 && start !== -1 && end === -1) {
18017
+ paramName = header.slice(start, i);
18018
+ start = end = -1;
18019
+ } else {
18020
+ throw new SyntaxError(`Unexpected character at index ${i}`);
18021
+ }
18022
+ } else {
18023
+ if (isEscaping) {
18024
+ if (tokenChars[code] !== 1) {
18025
+ throw new SyntaxError(`Unexpected character at index ${i}`);
18026
+ }
18027
+ if (start === -1) start = i;
18028
+ else if (!mustUnescape) mustUnescape = true;
18029
+ isEscaping = false;
18030
+ } else if (inQuotes) {
18031
+ if (tokenChars[code] === 1) {
18032
+ if (start === -1) start = i;
18033
+ } else if (code === 34 && start !== -1) {
18034
+ inQuotes = false;
18035
+ end = i;
18036
+ } else if (code === 92) {
18037
+ isEscaping = true;
18038
+ } else {
18039
+ throw new SyntaxError(`Unexpected character at index ${i}`);
18040
+ }
18041
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
18042
+ inQuotes = true;
18043
+ } else if (end === -1 && tokenChars[code] === 1) {
18044
+ if (start === -1) start = i;
18045
+ } else if (start !== -1 && (code === 32 || code === 9)) {
18046
+ if (end === -1) end = i;
18047
+ } else if (code === 59 || code === 44) {
18048
+ if (start === -1) {
18049
+ throw new SyntaxError(`Unexpected character at index ${i}`);
18050
+ }
18051
+ if (end === -1) end = i;
18052
+ let value = header.slice(start, end);
18053
+ if (mustUnescape) {
18054
+ value = value.replace(/\\/g, "");
18055
+ mustUnescape = false;
18056
+ }
18057
+ push(params, paramName, value);
18058
+ if (code === 44) {
18059
+ push(offers, extensionName, params);
18060
+ params = /* @__PURE__ */ Object.create(null);
18061
+ extensionName = void 0;
18062
+ }
18063
+ paramName = void 0;
18064
+ start = end = -1;
18065
+ } else {
18066
+ throw new SyntaxError(`Unexpected character at index ${i}`);
18067
+ }
18068
+ }
18069
+ }
18070
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
18071
+ throw new SyntaxError("Unexpected end of input");
18072
+ }
18073
+ if (end === -1) end = i;
18074
+ const token2 = header.slice(start, end);
18075
+ if (extensionName === void 0) {
18076
+ push(offers, token2, params);
18077
+ } else {
18078
+ if (paramName === void 0) {
18079
+ push(params, token2, true);
18080
+ } else if (mustUnescape) {
18081
+ push(params, paramName, token2.replace(/\\/g, ""));
18082
+ } else {
18083
+ push(params, paramName, token2);
18084
+ }
18085
+ push(offers, extensionName, params);
18086
+ }
18087
+ return offers;
18088
+ }
18089
+ function format2(extensions) {
18090
+ return Object.keys(extensions).map((extension) => {
18091
+ let configurations = extensions[extension];
18092
+ if (!Array.isArray(configurations)) configurations = [configurations];
18093
+ return configurations.map((params) => {
18094
+ return [extension].concat(
18095
+ Object.keys(params).map((k) => {
18096
+ let values = params[k];
18097
+ if (!Array.isArray(values)) values = [values];
18098
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
18099
+ })
18100
+ ).join("; ");
18101
+ }).join(", ");
18102
+ }).join(", ");
18103
+ }
18104
+ module2.exports = { format: format2, parse: parse4 };
18105
+ }
18106
+ });
18107
+
18108
+ // node_modules/ws/lib/websocket.js
18109
+ var require_websocket = __commonJS({
18110
+ "node_modules/ws/lib/websocket.js"(exports2, module2) {
18111
+ "use strict";
18112
+ var EventEmitter2 = require("events");
18113
+ var https = require("https");
18114
+ var http = require("http");
18115
+ var net = require("net");
18116
+ var tls = require("tls");
18117
+ var { randomBytes: randomBytes4, createHash: createHash3 } = require("crypto");
18118
+ var { Duplex, Readable } = require("stream");
18119
+ var { URL: URL2 } = require("url");
18120
+ var PerMessageDeflate = require_permessage_deflate();
18121
+ var Receiver2 = require_receiver();
18122
+ var Sender2 = require_sender();
18123
+ var { isBlob } = require_validation();
18124
+ var {
18125
+ BINARY_TYPES,
18126
+ CLOSE_TIMEOUT,
18127
+ EMPTY_BUFFER,
18128
+ GUID,
18129
+ kForOnEventAttribute,
18130
+ kListener,
18131
+ kStatusCode,
18132
+ kWebSocket,
18133
+ NOOP
18134
+ } = require_constants();
18135
+ var {
18136
+ EventTarget: { addEventListener, removeEventListener }
18137
+ } = require_event_target();
18138
+ var { format: format2, parse: parse4 } = require_extension();
18139
+ var { toBuffer } = require_buffer_util();
18140
+ var kAborted = /* @__PURE__ */ Symbol("kAborted");
18141
+ var protocolVersions = [8, 13];
18142
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
18143
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
18144
+ var WebSocket2 = class _WebSocket extends EventEmitter2 {
18145
+ /**
18146
+ * Create a new `WebSocket`.
18147
+ *
18148
+ * @param {(String|URL)} address The URL to which to connect
18149
+ * @param {(String|String[])} [protocols] The subprotocols
18150
+ * @param {Object} [options] Connection options
18151
+ */
18152
+ constructor(address, protocols, options) {
18153
+ super();
18154
+ this._binaryType = BINARY_TYPES[0];
18155
+ this._closeCode = 1006;
18156
+ this._closeFrameReceived = false;
18157
+ this._closeFrameSent = false;
18158
+ this._closeMessage = EMPTY_BUFFER;
18159
+ this._closeTimer = null;
18160
+ this._errorEmitted = false;
18161
+ this._extensions = {};
18162
+ this._paused = false;
18163
+ this._protocol = "";
18164
+ this._readyState = _WebSocket.CONNECTING;
18165
+ this._receiver = null;
18166
+ this._sender = null;
18167
+ this._socket = null;
18168
+ if (address !== null) {
18169
+ this._bufferedAmount = 0;
18170
+ this._isServer = false;
18171
+ this._redirects = 0;
18172
+ if (protocols === void 0) {
18173
+ protocols = [];
18174
+ } else if (!Array.isArray(protocols)) {
18175
+ if (typeof protocols === "object" && protocols !== null) {
18176
+ options = protocols;
18177
+ protocols = [];
18178
+ } else {
18179
+ protocols = [protocols];
18180
+ }
18181
+ }
18182
+ initAsClient(this, address, protocols, options);
18183
+ } else {
18184
+ this._autoPong = options.autoPong;
18185
+ this._closeTimeout = options.closeTimeout;
18186
+ this._isServer = true;
18187
+ }
18188
+ }
18189
+ /**
18190
+ * For historical reasons, the custom "nodebuffer" type is used by the default
18191
+ * instead of "blob".
18192
+ *
18193
+ * @type {String}
18194
+ */
18195
+ get binaryType() {
18196
+ return this._binaryType;
18197
+ }
18198
+ set binaryType(type) {
18199
+ if (!BINARY_TYPES.includes(type)) return;
18200
+ this._binaryType = type;
18201
+ if (this._receiver) this._receiver._binaryType = type;
18202
+ }
18203
+ /**
18204
+ * @type {Number}
18205
+ */
18206
+ get bufferedAmount() {
18207
+ if (!this._socket) return this._bufferedAmount;
18208
+ return this._socket._writableState.length + this._sender._bufferedBytes;
18209
+ }
18210
+ /**
18211
+ * @type {String}
18212
+ */
18213
+ get extensions() {
18214
+ return Object.keys(this._extensions).join();
18215
+ }
18216
+ /**
18217
+ * @type {Boolean}
18218
+ */
18219
+ get isPaused() {
18220
+ return this._paused;
18221
+ }
18222
+ /**
18223
+ * @type {Function}
18224
+ */
18225
+ /* istanbul ignore next */
18226
+ get onclose() {
18227
+ return null;
18228
+ }
18229
+ /**
18230
+ * @type {Function}
18231
+ */
18232
+ /* istanbul ignore next */
18233
+ get onerror() {
18234
+ return null;
18235
+ }
18236
+ /**
18237
+ * @type {Function}
18238
+ */
18239
+ /* istanbul ignore next */
18240
+ get onopen() {
18241
+ return null;
18242
+ }
18243
+ /**
18244
+ * @type {Function}
18245
+ */
18246
+ /* istanbul ignore next */
18247
+ get onmessage() {
18248
+ return null;
18249
+ }
18250
+ /**
18251
+ * @type {String}
18252
+ */
18253
+ get protocol() {
18254
+ return this._protocol;
18255
+ }
18256
+ /**
18257
+ * @type {Number}
18258
+ */
18259
+ get readyState() {
18260
+ return this._readyState;
18261
+ }
18262
+ /**
18263
+ * @type {String}
18264
+ */
18265
+ get url() {
18266
+ return this._url;
18267
+ }
18268
+ /**
18269
+ * Set up the socket and the internal resources.
18270
+ *
18271
+ * @param {Duplex} socket The network socket between the server and client
18272
+ * @param {Buffer} head The first packet of the upgraded stream
18273
+ * @param {Object} options Options object
18274
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
18275
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
18276
+ * multiple times in the same tick
18277
+ * @param {Function} [options.generateMask] The function used to generate the
18278
+ * masking key
18279
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
18280
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
18281
+ * not to skip UTF-8 validation for text and close messages
18282
+ * @private
18283
+ */
18284
+ setSocket(socket, head, options) {
18285
+ const receiver = new Receiver2({
18286
+ allowSynchronousEvents: options.allowSynchronousEvents,
18287
+ binaryType: this.binaryType,
18288
+ extensions: this._extensions,
18289
+ isServer: this._isServer,
18290
+ maxPayload: options.maxPayload,
18291
+ skipUTF8Validation: options.skipUTF8Validation
18292
+ });
18293
+ const sender = new Sender2(socket, this._extensions, options.generateMask);
18294
+ this._receiver = receiver;
18295
+ this._sender = sender;
18296
+ this._socket = socket;
18297
+ receiver[kWebSocket] = this;
18298
+ sender[kWebSocket] = this;
18299
+ socket[kWebSocket] = this;
18300
+ receiver.on("conclude", receiverOnConclude);
18301
+ receiver.on("drain", receiverOnDrain);
18302
+ receiver.on("error", receiverOnError);
18303
+ receiver.on("message", receiverOnMessage);
18304
+ receiver.on("ping", receiverOnPing);
18305
+ receiver.on("pong", receiverOnPong);
18306
+ sender.onerror = senderOnError;
18307
+ if (socket.setTimeout) socket.setTimeout(0);
18308
+ if (socket.setNoDelay) socket.setNoDelay();
18309
+ if (head.length > 0) socket.unshift(head);
18310
+ socket.on("close", socketOnClose);
18311
+ socket.on("data", socketOnData);
18312
+ socket.on("end", socketOnEnd);
18313
+ socket.on("error", socketOnError);
18314
+ this._readyState = _WebSocket.OPEN;
18315
+ this.emit("open");
18316
+ }
18317
+ /**
18318
+ * Emit the `'close'` event.
18319
+ *
18320
+ * @private
18321
+ */
18322
+ emitClose() {
18323
+ if (!this._socket) {
18324
+ this._readyState = _WebSocket.CLOSED;
18325
+ this.emit("close", this._closeCode, this._closeMessage);
18326
+ return;
18327
+ }
18328
+ if (this._extensions[PerMessageDeflate.extensionName]) {
18329
+ this._extensions[PerMessageDeflate.extensionName].cleanup();
18330
+ }
18331
+ this._receiver.removeAllListeners();
18332
+ this._readyState = _WebSocket.CLOSED;
18333
+ this.emit("close", this._closeCode, this._closeMessage);
18334
+ }
18335
+ /**
18336
+ * Start a closing handshake.
18337
+ *
18338
+ * +----------+ +-----------+ +----------+
18339
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
18340
+ * | +----------+ +-----------+ +----------+ |
18341
+ * +----------+ +-----------+ |
18342
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
18343
+ * +----------+ +-----------+ |
18344
+ * | | | +---+ |
18345
+ * +------------------------+-->|fin| - - - -
18346
+ * | +---+ | +---+
18347
+ * - - - - -|fin|<---------------------+
18348
+ * +---+
18349
+ *
18350
+ * @param {Number} [code] Status code explaining why the connection is closing
18351
+ * @param {(String|Buffer)} [data] The reason why the connection is
18352
+ * closing
18353
+ * @public
18354
+ */
18355
+ close(code, data) {
18356
+ if (this.readyState === _WebSocket.CLOSED) return;
18357
+ if (this.readyState === _WebSocket.CONNECTING) {
18358
+ const msg = "WebSocket was closed before the connection was established";
18359
+ abortHandshake(this, this._req, msg);
18360
+ return;
18361
+ }
18362
+ if (this.readyState === _WebSocket.CLOSING) {
18363
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
18364
+ this._socket.end();
18365
+ }
18366
+ return;
18367
+ }
18368
+ this._readyState = _WebSocket.CLOSING;
18369
+ this._sender.close(code, data, !this._isServer, (err) => {
18370
+ if (err) return;
18371
+ this._closeFrameSent = true;
18372
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
18373
+ this._socket.end();
18374
+ }
18375
+ });
18376
+ setCloseTimer(this);
18377
+ }
18378
+ /**
18379
+ * Pause the socket.
18380
+ *
18381
+ * @public
18382
+ */
18383
+ pause() {
18384
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
18385
+ return;
18386
+ }
18387
+ this._paused = true;
18388
+ this._socket.pause();
18389
+ }
18390
+ /**
18391
+ * Send a ping.
18392
+ *
18393
+ * @param {*} [data] The data to send
18394
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
18395
+ * @param {Function} [cb] Callback which is executed when the ping is sent
18396
+ * @public
18397
+ */
18398
+ ping(data, mask, cb) {
18399
+ if (this.readyState === _WebSocket.CONNECTING) {
18400
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
18401
+ }
18402
+ if (typeof data === "function") {
18403
+ cb = data;
18404
+ data = mask = void 0;
18405
+ } else if (typeof mask === "function") {
18406
+ cb = mask;
18407
+ mask = void 0;
18408
+ }
18409
+ if (typeof data === "number") data = data.toString();
18410
+ if (this.readyState !== _WebSocket.OPEN) {
18411
+ sendAfterClose(this, data, cb);
18412
+ return;
18413
+ }
18414
+ if (mask === void 0) mask = !this._isServer;
18415
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
18416
+ }
18417
+ /**
18418
+ * Send a pong.
18419
+ *
18420
+ * @param {*} [data] The data to send
18421
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
18422
+ * @param {Function} [cb] Callback which is executed when the pong is sent
18423
+ * @public
18424
+ */
18425
+ pong(data, mask, cb) {
18426
+ if (this.readyState === _WebSocket.CONNECTING) {
18427
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
18428
+ }
18429
+ if (typeof data === "function") {
18430
+ cb = data;
18431
+ data = mask = void 0;
18432
+ } else if (typeof mask === "function") {
18433
+ cb = mask;
18434
+ mask = void 0;
18435
+ }
18436
+ if (typeof data === "number") data = data.toString();
18437
+ if (this.readyState !== _WebSocket.OPEN) {
18438
+ sendAfterClose(this, data, cb);
18439
+ return;
18440
+ }
18441
+ if (mask === void 0) mask = !this._isServer;
18442
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
18443
+ }
18444
+ /**
18445
+ * Resume the socket.
18446
+ *
18447
+ * @public
18448
+ */
18449
+ resume() {
18450
+ if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
18451
+ return;
18452
+ }
18453
+ this._paused = false;
18454
+ if (!this._receiver._writableState.needDrain) this._socket.resume();
18455
+ }
18456
+ /**
18457
+ * Send a data message.
18458
+ *
18459
+ * @param {*} data The message to send
18460
+ * @param {Object} [options] Options object
18461
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
18462
+ * text
18463
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
18464
+ * `data`
18465
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
18466
+ * last one
18467
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
18468
+ * @param {Function} [cb] Callback which is executed when data is written out
18469
+ * @public
18470
+ */
18471
+ send(data, options, cb) {
18472
+ if (this.readyState === _WebSocket.CONNECTING) {
18473
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
18474
+ }
18475
+ if (typeof options === "function") {
18476
+ cb = options;
18477
+ options = {};
18478
+ }
18479
+ if (typeof data === "number") data = data.toString();
18480
+ if (this.readyState !== _WebSocket.OPEN) {
18481
+ sendAfterClose(this, data, cb);
18482
+ return;
18483
+ }
18484
+ const opts = {
18485
+ binary: typeof data !== "string",
18486
+ mask: !this._isServer,
18487
+ compress: true,
18488
+ fin: true,
18489
+ ...options
18490
+ };
18491
+ if (!this._extensions[PerMessageDeflate.extensionName]) {
18492
+ opts.compress = false;
18493
+ }
18494
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
18495
+ }
18496
+ /**
18497
+ * Forcibly close the connection.
18498
+ *
18499
+ * @public
18500
+ */
18501
+ terminate() {
18502
+ if (this.readyState === _WebSocket.CLOSED) return;
18503
+ if (this.readyState === _WebSocket.CONNECTING) {
18504
+ const msg = "WebSocket was closed before the connection was established";
18505
+ abortHandshake(this, this._req, msg);
18506
+ return;
18507
+ }
18508
+ if (this._socket) {
18509
+ this._readyState = _WebSocket.CLOSING;
18510
+ this._socket.destroy();
18511
+ }
18512
+ }
18513
+ };
18514
+ Object.defineProperty(WebSocket2, "CONNECTING", {
18515
+ enumerable: true,
18516
+ value: readyStates.indexOf("CONNECTING")
18517
+ });
18518
+ Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
18519
+ enumerable: true,
18520
+ value: readyStates.indexOf("CONNECTING")
18521
+ });
18522
+ Object.defineProperty(WebSocket2, "OPEN", {
18523
+ enumerable: true,
18524
+ value: readyStates.indexOf("OPEN")
18525
+ });
18526
+ Object.defineProperty(WebSocket2.prototype, "OPEN", {
18527
+ enumerable: true,
18528
+ value: readyStates.indexOf("OPEN")
18529
+ });
18530
+ Object.defineProperty(WebSocket2, "CLOSING", {
18531
+ enumerable: true,
18532
+ value: readyStates.indexOf("CLOSING")
18533
+ });
18534
+ Object.defineProperty(WebSocket2.prototype, "CLOSING", {
18535
+ enumerable: true,
18536
+ value: readyStates.indexOf("CLOSING")
18537
+ });
18538
+ Object.defineProperty(WebSocket2, "CLOSED", {
18539
+ enumerable: true,
18540
+ value: readyStates.indexOf("CLOSED")
18541
+ });
18542
+ Object.defineProperty(WebSocket2.prototype, "CLOSED", {
18543
+ enumerable: true,
18544
+ value: readyStates.indexOf("CLOSED")
18545
+ });
18546
+ [
18547
+ "binaryType",
18548
+ "bufferedAmount",
18549
+ "extensions",
18550
+ "isPaused",
18551
+ "protocol",
18552
+ "readyState",
18553
+ "url"
18554
+ ].forEach((property) => {
18555
+ Object.defineProperty(WebSocket2.prototype, property, { enumerable: true });
18556
+ });
18557
+ ["open", "error", "close", "message"].forEach((method) => {
18558
+ Object.defineProperty(WebSocket2.prototype, `on${method}`, {
18559
+ enumerable: true,
18560
+ get() {
18561
+ for (const listener of this.listeners(method)) {
18562
+ if (listener[kForOnEventAttribute]) return listener[kListener];
18563
+ }
18564
+ return null;
18565
+ },
18566
+ set(handler) {
18567
+ for (const listener of this.listeners(method)) {
18568
+ if (listener[kForOnEventAttribute]) {
18569
+ this.removeListener(method, listener);
18570
+ break;
18571
+ }
18572
+ }
18573
+ if (typeof handler !== "function") return;
18574
+ this.addEventListener(method, handler, {
18575
+ [kForOnEventAttribute]: true
18576
+ });
18577
+ }
18578
+ });
18579
+ });
18580
+ WebSocket2.prototype.addEventListener = addEventListener;
18581
+ WebSocket2.prototype.removeEventListener = removeEventListener;
18582
+ module2.exports = WebSocket2;
18583
+ function initAsClient(websocket, address, protocols, options) {
18584
+ const opts = {
18585
+ allowSynchronousEvents: true,
18586
+ autoPong: true,
18587
+ closeTimeout: CLOSE_TIMEOUT,
18588
+ protocolVersion: protocolVersions[1],
18589
+ maxPayload: 100 * 1024 * 1024,
18590
+ skipUTF8Validation: false,
18591
+ perMessageDeflate: true,
18592
+ followRedirects: false,
18593
+ maxRedirects: 10,
18594
+ ...options,
18595
+ socketPath: void 0,
18596
+ hostname: void 0,
18597
+ protocol: void 0,
18598
+ timeout: void 0,
18599
+ method: "GET",
18600
+ host: void 0,
18601
+ path: void 0,
18602
+ port: void 0
18603
+ };
18604
+ websocket._autoPong = opts.autoPong;
18605
+ websocket._closeTimeout = opts.closeTimeout;
18606
+ if (!protocolVersions.includes(opts.protocolVersion)) {
18607
+ throw new RangeError(
18608
+ `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
18609
+ );
18610
+ }
18611
+ let parsedUrl;
18612
+ if (address instanceof URL2) {
18613
+ parsedUrl = address;
18614
+ } else {
18615
+ try {
18616
+ parsedUrl = new URL2(address);
18617
+ } catch (e) {
18618
+ throw new SyntaxError(`Invalid URL: ${address}`);
18619
+ }
18620
+ }
18621
+ if (parsedUrl.protocol === "http:") {
18622
+ parsedUrl.protocol = "ws:";
18623
+ } else if (parsedUrl.protocol === "https:") {
18624
+ parsedUrl.protocol = "wss:";
18625
+ }
18626
+ websocket._url = parsedUrl.href;
18627
+ const isSecure = parsedUrl.protocol === "wss:";
18628
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
18629
+ let invalidUrlMessage;
18630
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
18631
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
18632
+ } else if (isIpcUrl && !parsedUrl.pathname) {
18633
+ invalidUrlMessage = "The URL's pathname is empty";
18634
+ } else if (parsedUrl.hash) {
18635
+ invalidUrlMessage = "The URL contains a fragment identifier";
18636
+ }
18637
+ if (invalidUrlMessage) {
18638
+ const err = new SyntaxError(invalidUrlMessage);
18639
+ if (websocket._redirects === 0) {
18640
+ throw err;
18641
+ } else {
18642
+ emitErrorAndClose(websocket, err);
18643
+ return;
18644
+ }
18645
+ }
18646
+ const defaultPort = isSecure ? 443 : 80;
18647
+ const key = randomBytes4(16).toString("base64");
18648
+ const request = isSecure ? https.request : http.request;
18649
+ const protocolSet = /* @__PURE__ */ new Set();
18650
+ let perMessageDeflate;
18651
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
18652
+ opts.defaultPort = opts.defaultPort || defaultPort;
18653
+ opts.port = parsedUrl.port || defaultPort;
18654
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
18655
+ opts.headers = {
18656
+ ...opts.headers,
18657
+ "Sec-WebSocket-Version": opts.protocolVersion,
18658
+ "Sec-WebSocket-Key": key,
18659
+ Connection: "Upgrade",
18660
+ Upgrade: "websocket"
18661
+ };
18662
+ opts.path = parsedUrl.pathname + parsedUrl.search;
18663
+ opts.timeout = opts.handshakeTimeout;
18664
+ if (opts.perMessageDeflate) {
18665
+ perMessageDeflate = new PerMessageDeflate(
18666
+ opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
18667
+ false,
18668
+ opts.maxPayload
18669
+ );
18670
+ opts.headers["Sec-WebSocket-Extensions"] = format2({
18671
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
18672
+ });
18673
+ }
18674
+ if (protocols.length) {
18675
+ for (const protocol of protocols) {
18676
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
18677
+ throw new SyntaxError(
18678
+ "An invalid or duplicated subprotocol was specified"
18679
+ );
18680
+ }
18681
+ protocolSet.add(protocol);
18682
+ }
18683
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
18684
+ }
18685
+ if (opts.origin) {
18686
+ if (opts.protocolVersion < 13) {
18687
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
18688
+ } else {
18689
+ opts.headers.Origin = opts.origin;
18690
+ }
18691
+ }
18692
+ if (parsedUrl.username || parsedUrl.password) {
18693
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
18694
+ }
18695
+ if (isIpcUrl) {
18696
+ const parts = opts.path.split(":");
18697
+ opts.socketPath = parts[0];
18698
+ opts.path = parts[1];
18699
+ }
18700
+ let req;
18701
+ if (opts.followRedirects) {
18702
+ if (websocket._redirects === 0) {
18703
+ websocket._originalIpc = isIpcUrl;
18704
+ websocket._originalSecure = isSecure;
18705
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
18706
+ const headers = options && options.headers;
18707
+ options = { ...options, headers: {} };
18708
+ if (headers) {
18709
+ for (const [key2, value] of Object.entries(headers)) {
18710
+ options.headers[key2.toLowerCase()] = value;
18711
+ }
18712
+ }
18713
+ } else if (websocket.listenerCount("redirect") === 0) {
18714
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
18715
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
18716
+ delete opts.headers.authorization;
18717
+ delete opts.headers.cookie;
18718
+ if (!isSameHost) delete opts.headers.host;
18719
+ opts.auth = void 0;
18720
+ }
18721
+ }
18722
+ if (opts.auth && !options.headers.authorization) {
18723
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
18724
+ }
18725
+ req = websocket._req = request(opts);
18726
+ if (websocket._redirects) {
18727
+ websocket.emit("redirect", websocket.url, req);
18728
+ }
18729
+ } else {
18730
+ req = websocket._req = request(opts);
18731
+ }
18732
+ if (opts.timeout) {
18733
+ req.on("timeout", () => {
18734
+ abortHandshake(websocket, req, "Opening handshake has timed out");
18735
+ });
18736
+ }
18737
+ req.on("error", (err) => {
18738
+ if (req === null || req[kAborted]) return;
18739
+ req = websocket._req = null;
18740
+ emitErrorAndClose(websocket, err);
18741
+ });
18742
+ req.on("response", (res) => {
18743
+ const location = res.headers.location;
18744
+ const statusCode = res.statusCode;
18745
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
18746
+ if (++websocket._redirects > opts.maxRedirects) {
18747
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
18748
+ return;
18749
+ }
18750
+ req.abort();
18751
+ let addr;
18752
+ try {
18753
+ addr = new URL2(location, address);
18754
+ } catch (e) {
18755
+ const err = new SyntaxError(`Invalid URL: ${location}`);
18756
+ emitErrorAndClose(websocket, err);
18757
+ return;
18758
+ }
18759
+ initAsClient(websocket, addr, protocols, options);
18760
+ } else if (!websocket.emit("unexpected-response", req, res)) {
18761
+ abortHandshake(
18762
+ websocket,
18763
+ req,
18764
+ `Unexpected server response: ${res.statusCode}`
18765
+ );
18766
+ }
18767
+ });
18768
+ req.on("upgrade", (res, socket, head) => {
18769
+ websocket.emit("upgrade", res);
18770
+ if (websocket.readyState !== WebSocket2.CONNECTING) return;
18771
+ req = websocket._req = null;
18772
+ const upgrade = res.headers.upgrade;
18773
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
18774
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
18775
+ return;
18776
+ }
18777
+ const digest = createHash3("sha1").update(key + GUID).digest("base64");
18778
+ if (res.headers["sec-websocket-accept"] !== digest) {
18779
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
18780
+ return;
18781
+ }
18782
+ const serverProt = res.headers["sec-websocket-protocol"];
18783
+ let protError;
18784
+ if (serverProt !== void 0) {
18785
+ if (!protocolSet.size) {
18786
+ protError = "Server sent a subprotocol but none was requested";
18787
+ } else if (!protocolSet.has(serverProt)) {
18788
+ protError = "Server sent an invalid subprotocol";
18789
+ }
18790
+ } else if (protocolSet.size) {
18791
+ protError = "Server sent no subprotocol";
18792
+ }
18793
+ if (protError) {
18794
+ abortHandshake(websocket, socket, protError);
18795
+ return;
18796
+ }
18797
+ if (serverProt) websocket._protocol = serverProt;
18798
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
18799
+ if (secWebSocketExtensions !== void 0) {
18800
+ if (!perMessageDeflate) {
18801
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
18802
+ abortHandshake(websocket, socket, message);
18803
+ return;
18804
+ }
18805
+ let extensions;
18806
+ try {
18807
+ extensions = parse4(secWebSocketExtensions);
18808
+ } catch (err) {
18809
+ const message = "Invalid Sec-WebSocket-Extensions header";
18810
+ abortHandshake(websocket, socket, message);
18811
+ return;
18812
+ }
18813
+ const extensionNames = Object.keys(extensions);
18814
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
18815
+ const message = "Server indicated an extension that was not requested";
18816
+ abortHandshake(websocket, socket, message);
18817
+ return;
18818
+ }
18819
+ try {
18820
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
18821
+ } catch (err) {
18822
+ const message = "Invalid Sec-WebSocket-Extensions header";
18823
+ abortHandshake(websocket, socket, message);
18824
+ return;
18825
+ }
18826
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
18827
+ }
18828
+ websocket.setSocket(socket, head, {
18829
+ allowSynchronousEvents: opts.allowSynchronousEvents,
18830
+ generateMask: opts.generateMask,
18831
+ maxPayload: opts.maxPayload,
18832
+ skipUTF8Validation: opts.skipUTF8Validation
18833
+ });
18834
+ });
18835
+ if (opts.finishRequest) {
18836
+ opts.finishRequest(req, websocket);
18837
+ } else {
18838
+ req.end();
18839
+ }
18840
+ }
18841
+ function emitErrorAndClose(websocket, err) {
18842
+ websocket._readyState = WebSocket2.CLOSING;
18843
+ websocket._errorEmitted = true;
18844
+ websocket.emit("error", err);
18845
+ websocket.emitClose();
18846
+ }
18847
+ function netConnect(options) {
18848
+ options.path = options.socketPath;
18849
+ return net.connect(options);
18850
+ }
18851
+ function tlsConnect(options) {
18852
+ options.path = void 0;
18853
+ if (!options.servername && options.servername !== "") {
18854
+ options.servername = net.isIP(options.host) ? "" : options.host;
18855
+ }
18856
+ return tls.connect(options);
18857
+ }
18858
+ function abortHandshake(websocket, stream, message) {
18859
+ websocket._readyState = WebSocket2.CLOSING;
18860
+ const err = new Error(message);
18861
+ Error.captureStackTrace(err, abortHandshake);
18862
+ if (stream.setHeader) {
18863
+ stream[kAborted] = true;
18864
+ stream.abort();
18865
+ if (stream.socket && !stream.socket.destroyed) {
18866
+ stream.socket.destroy();
18867
+ }
18868
+ process.nextTick(emitErrorAndClose, websocket, err);
18869
+ } else {
18870
+ stream.destroy(err);
18871
+ stream.once("error", websocket.emit.bind(websocket, "error"));
18872
+ stream.once("close", websocket.emitClose.bind(websocket));
18873
+ }
18874
+ }
18875
+ function sendAfterClose(websocket, data, cb) {
18876
+ if (data) {
18877
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
18878
+ if (websocket._socket) websocket._sender._bufferedBytes += length;
18879
+ else websocket._bufferedAmount += length;
18880
+ }
18881
+ if (cb) {
18882
+ const err = new Error(
18883
+ `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
18884
+ );
18885
+ process.nextTick(cb, err);
18886
+ }
18887
+ }
18888
+ function receiverOnConclude(code, reason) {
18889
+ const websocket = this[kWebSocket];
18890
+ websocket._closeFrameReceived = true;
18891
+ websocket._closeMessage = reason;
18892
+ websocket._closeCode = code;
18893
+ if (websocket._socket[kWebSocket] === void 0) return;
18894
+ websocket._socket.removeListener("data", socketOnData);
18895
+ process.nextTick(resume, websocket._socket);
18896
+ if (code === 1005) websocket.close();
18897
+ else websocket.close(code, reason);
18898
+ }
18899
+ function receiverOnDrain() {
18900
+ const websocket = this[kWebSocket];
18901
+ if (!websocket.isPaused) websocket._socket.resume();
18902
+ }
18903
+ function receiverOnError(err) {
18904
+ const websocket = this[kWebSocket];
18905
+ if (websocket._socket[kWebSocket] !== void 0) {
18906
+ websocket._socket.removeListener("data", socketOnData);
18907
+ process.nextTick(resume, websocket._socket);
18908
+ websocket.close(err[kStatusCode]);
18909
+ }
18910
+ if (!websocket._errorEmitted) {
18911
+ websocket._errorEmitted = true;
18912
+ websocket.emit("error", err);
18913
+ }
18914
+ }
18915
+ function receiverOnFinish() {
18916
+ this[kWebSocket].emitClose();
18917
+ }
18918
+ function receiverOnMessage(data, isBinary) {
18919
+ this[kWebSocket].emit("message", data, isBinary);
18920
+ }
18921
+ function receiverOnPing(data) {
18922
+ const websocket = this[kWebSocket];
18923
+ if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
18924
+ websocket.emit("ping", data);
18925
+ }
18926
+ function receiverOnPong(data) {
18927
+ this[kWebSocket].emit("pong", data);
18928
+ }
18929
+ function resume(stream) {
18930
+ stream.resume();
18931
+ }
18932
+ function senderOnError(err) {
18933
+ const websocket = this[kWebSocket];
18934
+ if (websocket.readyState === WebSocket2.CLOSED) return;
18935
+ if (websocket.readyState === WebSocket2.OPEN) {
18936
+ websocket._readyState = WebSocket2.CLOSING;
18937
+ setCloseTimer(websocket);
18938
+ }
18939
+ this._socket.end();
18940
+ if (!websocket._errorEmitted) {
18941
+ websocket._errorEmitted = true;
18942
+ websocket.emit("error", err);
18943
+ }
18944
+ }
18945
+ function setCloseTimer(websocket) {
18946
+ websocket._closeTimer = setTimeout(
18947
+ websocket._socket.destroy.bind(websocket._socket),
18948
+ websocket._closeTimeout
18949
+ );
18950
+ }
18951
+ function socketOnClose() {
18952
+ const websocket = this[kWebSocket];
18953
+ this.removeListener("close", socketOnClose);
18954
+ this.removeListener("data", socketOnData);
18955
+ this.removeListener("end", socketOnEnd);
18956
+ websocket._readyState = WebSocket2.CLOSING;
18957
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
18958
+ const chunk = this.read(this._readableState.length);
18959
+ websocket._receiver.write(chunk);
18960
+ }
18961
+ websocket._receiver.end();
18962
+ this[kWebSocket] = void 0;
18963
+ clearTimeout(websocket._closeTimer);
18964
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
18965
+ websocket.emitClose();
18966
+ } else {
18967
+ websocket._receiver.on("error", receiverOnFinish);
18968
+ websocket._receiver.on("finish", receiverOnFinish);
18969
+ }
18970
+ }
18971
+ function socketOnData(chunk) {
18972
+ if (!this[kWebSocket]._receiver.write(chunk)) {
18973
+ this.pause();
18974
+ }
18975
+ }
18976
+ function socketOnEnd() {
18977
+ const websocket = this[kWebSocket];
18978
+ websocket._readyState = WebSocket2.CLOSING;
18979
+ websocket._receiver.end();
18980
+ this.end();
18981
+ }
18982
+ function socketOnError() {
18983
+ const websocket = this[kWebSocket];
18984
+ this.removeListener("error", socketOnError);
18985
+ this.on("error", NOOP);
18986
+ if (websocket) {
18987
+ websocket._readyState = WebSocket2.CLOSING;
18988
+ this.destroy();
18989
+ }
18990
+ }
18991
+ }
18992
+ });
18993
+
18994
+ // node_modules/ws/lib/stream.js
18995
+ var require_stream3 = __commonJS({
18996
+ "node_modules/ws/lib/stream.js"(exports2, module2) {
18997
+ "use strict";
18998
+ var WebSocket2 = require_websocket();
18999
+ var { Duplex } = require("stream");
19000
+ function emitClose(stream) {
19001
+ stream.emit("close");
19002
+ }
19003
+ function duplexOnEnd() {
19004
+ if (!this.destroyed && this._writableState.finished) {
19005
+ this.destroy();
19006
+ }
19007
+ }
19008
+ function duplexOnError(err) {
19009
+ this.removeListener("error", duplexOnError);
19010
+ this.destroy();
19011
+ if (this.listenerCount("error") === 0) {
19012
+ this.emit("error", err);
19013
+ }
19014
+ }
19015
+ function createWebSocketStream2(ws, options) {
19016
+ let terminateOnDestroy = true;
19017
+ const duplex = new Duplex({
19018
+ ...options,
19019
+ autoDestroy: false,
19020
+ emitClose: false,
19021
+ objectMode: false,
19022
+ writableObjectMode: false
19023
+ });
19024
+ ws.on("message", function message(msg, isBinary) {
19025
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
19026
+ if (!duplex.push(data)) ws.pause();
19027
+ });
19028
+ ws.once("error", function error48(err) {
19029
+ if (duplex.destroyed) return;
19030
+ terminateOnDestroy = false;
19031
+ duplex.destroy(err);
19032
+ });
19033
+ ws.once("close", function close() {
19034
+ if (duplex.destroyed) return;
19035
+ duplex.push(null);
19036
+ });
19037
+ duplex._destroy = function(err, callback) {
19038
+ if (ws.readyState === ws.CLOSED) {
19039
+ callback(err);
19040
+ process.nextTick(emitClose, duplex);
19041
+ return;
19042
+ }
19043
+ let called = false;
19044
+ ws.once("error", function error48(err2) {
19045
+ called = true;
19046
+ callback(err2);
19047
+ });
19048
+ ws.once("close", function close() {
19049
+ if (!called) callback(err);
19050
+ process.nextTick(emitClose, duplex);
19051
+ });
19052
+ if (terminateOnDestroy) ws.terminate();
19053
+ };
19054
+ duplex._final = function(callback) {
19055
+ if (ws.readyState === ws.CONNECTING) {
19056
+ ws.once("open", function open() {
19057
+ duplex._final(callback);
19058
+ });
19059
+ return;
19060
+ }
19061
+ if (ws._socket === null) return;
19062
+ if (ws._socket._writableState.finished) {
19063
+ callback();
19064
+ if (duplex._readableState.endEmitted) duplex.destroy();
19065
+ } else {
19066
+ ws._socket.once("finish", function finish() {
19067
+ callback();
19068
+ });
19069
+ ws.close();
19070
+ }
19071
+ };
19072
+ duplex._read = function() {
19073
+ if (ws.isPaused) ws.resume();
19074
+ };
19075
+ duplex._write = function(chunk, encoding, callback) {
19076
+ if (ws.readyState === ws.CONNECTING) {
19077
+ ws.once("open", function open() {
19078
+ duplex._write(chunk, encoding, callback);
19079
+ });
19080
+ return;
19081
+ }
19082
+ ws.send(chunk, callback);
19083
+ };
19084
+ duplex.on("end", duplexOnEnd);
19085
+ duplex.on("error", duplexOnError);
19086
+ return duplex;
19087
+ }
19088
+ module2.exports = createWebSocketStream2;
19089
+ }
19090
+ });
19091
+
19092
+ // node_modules/ws/lib/subprotocol.js
19093
+ var require_subprotocol = __commonJS({
19094
+ "node_modules/ws/lib/subprotocol.js"(exports2, module2) {
19095
+ "use strict";
19096
+ var { tokenChars } = require_validation();
19097
+ function parse4(header) {
19098
+ const protocols = /* @__PURE__ */ new Set();
19099
+ let start = -1;
19100
+ let end = -1;
19101
+ let i = 0;
19102
+ for (i; i < header.length; i++) {
19103
+ const code = header.charCodeAt(i);
19104
+ if (end === -1 && tokenChars[code] === 1) {
19105
+ if (start === -1) start = i;
19106
+ } else if (i !== 0 && (code === 32 || code === 9)) {
19107
+ if (end === -1 && start !== -1) end = i;
19108
+ } else if (code === 44) {
19109
+ if (start === -1) {
19110
+ throw new SyntaxError(`Unexpected character at index ${i}`);
19111
+ }
19112
+ if (end === -1) end = i;
19113
+ const protocol2 = header.slice(start, end);
19114
+ if (protocols.has(protocol2)) {
19115
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
19116
+ }
19117
+ protocols.add(protocol2);
19118
+ start = end = -1;
19119
+ } else {
19120
+ throw new SyntaxError(`Unexpected character at index ${i}`);
19121
+ }
19122
+ }
19123
+ if (start === -1 || end !== -1) {
19124
+ throw new SyntaxError("Unexpected end of input");
19125
+ }
19126
+ const protocol = header.slice(start, i);
19127
+ if (protocols.has(protocol)) {
19128
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
19129
+ }
19130
+ protocols.add(protocol);
19131
+ return protocols;
19132
+ }
19133
+ module2.exports = { parse: parse4 };
19134
+ }
19135
+ });
19136
+
19137
+ // node_modules/ws/lib/websocket-server.js
19138
+ var require_websocket_server = __commonJS({
19139
+ "node_modules/ws/lib/websocket-server.js"(exports2, module2) {
19140
+ "use strict";
19141
+ var EventEmitter2 = require("events");
19142
+ var http = require("http");
19143
+ var { Duplex } = require("stream");
19144
+ var { createHash: createHash3 } = require("crypto");
19145
+ var extension = require_extension();
19146
+ var PerMessageDeflate = require_permessage_deflate();
19147
+ var subprotocol = require_subprotocol();
19148
+ var WebSocket2 = require_websocket();
19149
+ var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
19150
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
19151
+ var RUNNING = 0;
19152
+ var CLOSING = 1;
19153
+ var CLOSED = 2;
19154
+ var WebSocketServer2 = class extends EventEmitter2 {
19155
+ /**
19156
+ * Create a `WebSocketServer` instance.
19157
+ *
19158
+ * @param {Object} options Configuration options
19159
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
19160
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
19161
+ * multiple times in the same tick
19162
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
19163
+ * automatically send a pong in response to a ping
19164
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
19165
+ * pending connections
19166
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
19167
+ * track clients
19168
+ * @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
19169
+ * wait for the closing handshake to finish after `websocket.close()` is
19170
+ * called
19171
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
19172
+ * @param {String} [options.host] The hostname where to bind the server
19173
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
19174
+ * size
19175
+ * @param {Boolean} [options.noServer=false] Enable no server mode
19176
+ * @param {String} [options.path] Accept only connections matching this path
19177
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
19178
+ * permessage-deflate
19179
+ * @param {Number} [options.port] The port where to bind the server
19180
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
19181
+ * server to use
19182
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
19183
+ * not to skip UTF-8 validation for text and close messages
19184
+ * @param {Function} [options.verifyClient] A hook to reject connections
19185
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
19186
+ * class to use. It must be the `WebSocket` class or class that extends it
19187
+ * @param {Function} [callback] A listener for the `listening` event
19188
+ */
19189
+ constructor(options, callback) {
19190
+ super();
19191
+ options = {
19192
+ allowSynchronousEvents: true,
19193
+ autoPong: true,
19194
+ maxPayload: 100 * 1024 * 1024,
19195
+ skipUTF8Validation: false,
19196
+ perMessageDeflate: false,
19197
+ handleProtocols: null,
19198
+ clientTracking: true,
19199
+ closeTimeout: CLOSE_TIMEOUT,
19200
+ verifyClient: null,
19201
+ noServer: false,
19202
+ backlog: null,
19203
+ // use default (511 as implemented in net.js)
19204
+ server: null,
19205
+ host: null,
19206
+ path: null,
19207
+ port: null,
19208
+ WebSocket: WebSocket2,
19209
+ ...options
19210
+ };
19211
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
19212
+ throw new TypeError(
19213
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
19214
+ );
19215
+ }
19216
+ if (options.port != null) {
19217
+ this._server = http.createServer((req, res) => {
19218
+ const body = http.STATUS_CODES[426];
19219
+ res.writeHead(426, {
19220
+ "Content-Length": body.length,
19221
+ "Content-Type": "text/plain"
19222
+ });
19223
+ res.end(body);
19224
+ });
19225
+ this._server.listen(
19226
+ options.port,
19227
+ options.host,
19228
+ options.backlog,
19229
+ callback
19230
+ );
19231
+ } else if (options.server) {
19232
+ this._server = options.server;
19233
+ }
19234
+ if (this._server) {
19235
+ const emitConnection = this.emit.bind(this, "connection");
19236
+ this._removeListeners = addListeners(this._server, {
19237
+ listening: this.emit.bind(this, "listening"),
19238
+ error: this.emit.bind(this, "error"),
19239
+ upgrade: (req, socket, head) => {
19240
+ this.handleUpgrade(req, socket, head, emitConnection);
19241
+ }
19242
+ });
19243
+ }
19244
+ if (options.perMessageDeflate === true) options.perMessageDeflate = {};
19245
+ if (options.clientTracking) {
19246
+ this.clients = /* @__PURE__ */ new Set();
19247
+ this._shouldEmitClose = false;
19248
+ }
19249
+ this.options = options;
19250
+ this._state = RUNNING;
19251
+ }
19252
+ /**
19253
+ * Returns the bound address, the address family name, and port of the server
19254
+ * as reported by the operating system if listening on an IP socket.
19255
+ * If the server is listening on a pipe or UNIX domain socket, the name is
19256
+ * returned as a string.
19257
+ *
19258
+ * @return {(Object|String|null)} The address of the server
19259
+ * @public
19260
+ */
19261
+ address() {
19262
+ if (this.options.noServer) {
19263
+ throw new Error('The server is operating in "noServer" mode');
19264
+ }
19265
+ if (!this._server) return null;
19266
+ return this._server.address();
19267
+ }
19268
+ /**
19269
+ * Stop the server from accepting new connections and emit the `'close'` event
19270
+ * when all existing connections are closed.
19271
+ *
19272
+ * @param {Function} [cb] A one-time listener for the `'close'` event
19273
+ * @public
19274
+ */
19275
+ close(cb) {
19276
+ if (this._state === CLOSED) {
19277
+ if (cb) {
19278
+ this.once("close", () => {
19279
+ cb(new Error("The server is not running"));
19280
+ });
19281
+ }
19282
+ process.nextTick(emitClose, this);
19283
+ return;
19284
+ }
19285
+ if (cb) this.once("close", cb);
19286
+ if (this._state === CLOSING) return;
19287
+ this._state = CLOSING;
19288
+ if (this.options.noServer || this.options.server) {
19289
+ if (this._server) {
19290
+ this._removeListeners();
19291
+ this._removeListeners = this._server = null;
19292
+ }
19293
+ if (this.clients) {
19294
+ if (!this.clients.size) {
19295
+ process.nextTick(emitClose, this);
19296
+ } else {
19297
+ this._shouldEmitClose = true;
19298
+ }
19299
+ } else {
19300
+ process.nextTick(emitClose, this);
19301
+ }
19302
+ } else {
19303
+ const server = this._server;
19304
+ this._removeListeners();
19305
+ this._removeListeners = this._server = null;
19306
+ server.close(() => {
19307
+ emitClose(this);
19308
+ });
19309
+ }
19310
+ }
19311
+ /**
19312
+ * See if a given request should be handled by this server instance.
19313
+ *
19314
+ * @param {http.IncomingMessage} req Request object to inspect
19315
+ * @return {Boolean} `true` if the request is valid, else `false`
19316
+ * @public
19317
+ */
19318
+ shouldHandle(req) {
19319
+ if (this.options.path) {
19320
+ const index = req.url.indexOf("?");
19321
+ const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
19322
+ if (pathname !== this.options.path) return false;
19323
+ }
19324
+ return true;
19325
+ }
19326
+ /**
19327
+ * Handle a HTTP Upgrade request.
19328
+ *
19329
+ * @param {http.IncomingMessage} req The request object
19330
+ * @param {Duplex} socket The network socket between the server and client
19331
+ * @param {Buffer} head The first packet of the upgraded stream
19332
+ * @param {Function} cb Callback
19333
+ * @public
19334
+ */
19335
+ handleUpgrade(req, socket, head, cb) {
19336
+ socket.on("error", socketOnError);
19337
+ const key = req.headers["sec-websocket-key"];
19338
+ const upgrade = req.headers.upgrade;
19339
+ const version2 = +req.headers["sec-websocket-version"];
19340
+ if (req.method !== "GET") {
19341
+ const message = "Invalid HTTP method";
19342
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
19343
+ return;
19344
+ }
19345
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
19346
+ const message = "Invalid Upgrade header";
19347
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
19348
+ return;
19349
+ }
19350
+ if (key === void 0 || !keyRegex.test(key)) {
19351
+ const message = "Missing or invalid Sec-WebSocket-Key header";
19352
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
19353
+ return;
19354
+ }
19355
+ if (version2 !== 13 && version2 !== 8) {
19356
+ const message = "Missing or invalid Sec-WebSocket-Version header";
19357
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
19358
+ "Sec-WebSocket-Version": "13, 8"
19359
+ });
19360
+ return;
19361
+ }
19362
+ if (!this.shouldHandle(req)) {
19363
+ abortHandshake(socket, 400);
19364
+ return;
19365
+ }
19366
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
19367
+ let protocols = /* @__PURE__ */ new Set();
19368
+ if (secWebSocketProtocol !== void 0) {
19369
+ try {
19370
+ protocols = subprotocol.parse(secWebSocketProtocol);
19371
+ } catch (err) {
19372
+ const message = "Invalid Sec-WebSocket-Protocol header";
19373
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
19374
+ return;
19375
+ }
19376
+ }
19377
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
19378
+ const extensions = {};
19379
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
19380
+ const perMessageDeflate = new PerMessageDeflate(
19381
+ this.options.perMessageDeflate,
19382
+ true,
19383
+ this.options.maxPayload
19384
+ );
19385
+ try {
19386
+ const offers = extension.parse(secWebSocketExtensions);
19387
+ if (offers[PerMessageDeflate.extensionName]) {
19388
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
19389
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
19390
+ }
19391
+ } catch (err) {
19392
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
19393
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
19394
+ return;
19395
+ }
19396
+ }
19397
+ if (this.options.verifyClient) {
19398
+ const info = {
19399
+ origin: req.headers[`${version2 === 8 ? "sec-websocket-origin" : "origin"}`],
19400
+ secure: !!(req.socket.authorized || req.socket.encrypted),
19401
+ req
19402
+ };
19403
+ if (this.options.verifyClient.length === 2) {
19404
+ this.options.verifyClient(info, (verified, code, message, headers) => {
19405
+ if (!verified) {
19406
+ return abortHandshake(socket, code || 401, message, headers);
19407
+ }
19408
+ this.completeUpgrade(
19409
+ extensions,
19410
+ key,
19411
+ protocols,
19412
+ req,
19413
+ socket,
19414
+ head,
19415
+ cb
19416
+ );
19417
+ });
19418
+ return;
19419
+ }
19420
+ if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
19421
+ }
19422
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
19423
+ }
19424
+ /**
19425
+ * Upgrade the connection to WebSocket.
19426
+ *
19427
+ * @param {Object} extensions The accepted extensions
19428
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
19429
+ * @param {Set} protocols The subprotocols
19430
+ * @param {http.IncomingMessage} req The request object
19431
+ * @param {Duplex} socket The network socket between the server and client
19432
+ * @param {Buffer} head The first packet of the upgraded stream
19433
+ * @param {Function} cb Callback
19434
+ * @throws {Error} If called more than once with the same socket
19435
+ * @private
19436
+ */
19437
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
19438
+ if (!socket.readable || !socket.writable) return socket.destroy();
19439
+ if (socket[kWebSocket]) {
19440
+ throw new Error(
19441
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
19442
+ );
19443
+ }
19444
+ if (this._state > RUNNING) return abortHandshake(socket, 503);
19445
+ const digest = createHash3("sha1").update(key + GUID).digest("base64");
19446
+ const headers = [
19447
+ "HTTP/1.1 101 Switching Protocols",
19448
+ "Upgrade: websocket",
19449
+ "Connection: Upgrade",
19450
+ `Sec-WebSocket-Accept: ${digest}`
19451
+ ];
19452
+ const ws = new this.options.WebSocket(null, void 0, this.options);
19453
+ if (protocols.size) {
19454
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
19455
+ if (protocol) {
19456
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
19457
+ ws._protocol = protocol;
19458
+ }
19459
+ }
19460
+ if (extensions[PerMessageDeflate.extensionName]) {
19461
+ const params = extensions[PerMessageDeflate.extensionName].params;
19462
+ const value = extension.format({
19463
+ [PerMessageDeflate.extensionName]: [params]
19464
+ });
19465
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
19466
+ ws._extensions = extensions;
19467
+ }
19468
+ this.emit("headers", headers, req);
19469
+ socket.write(headers.concat("\r\n").join("\r\n"));
19470
+ socket.removeListener("error", socketOnError);
19471
+ ws.setSocket(socket, head, {
19472
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
19473
+ maxPayload: this.options.maxPayload,
19474
+ skipUTF8Validation: this.options.skipUTF8Validation
19475
+ });
19476
+ if (this.clients) {
19477
+ this.clients.add(ws);
19478
+ ws.on("close", () => {
19479
+ this.clients.delete(ws);
19480
+ if (this._shouldEmitClose && !this.clients.size) {
19481
+ process.nextTick(emitClose, this);
19482
+ }
19483
+ });
19484
+ }
19485
+ cb(ws, req);
19486
+ }
19487
+ };
19488
+ module2.exports = WebSocketServer2;
19489
+ function addListeners(server, map2) {
19490
+ for (const event of Object.keys(map2)) server.on(event, map2[event]);
19491
+ return function removeListeners() {
19492
+ for (const event of Object.keys(map2)) {
19493
+ server.removeListener(event, map2[event]);
19494
+ }
19495
+ };
19496
+ }
19497
+ function emitClose(server) {
19498
+ server._state = CLOSED;
19499
+ server.emit("close");
19500
+ }
19501
+ function socketOnError() {
19502
+ this.destroy();
19503
+ }
19504
+ function abortHandshake(socket, code, message, headers) {
19505
+ message = message || http.STATUS_CODES[code];
19506
+ headers = {
19507
+ Connection: "close",
19508
+ "Content-Type": "text/html",
19509
+ "Content-Length": Buffer.byteLength(message),
19510
+ ...headers
19511
+ };
19512
+ socket.once("finish", socket.destroy);
19513
+ socket.end(
19514
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
19515
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
19516
+ );
19517
+ }
19518
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
19519
+ if (server.listenerCount("wsClientError")) {
19520
+ const err = new Error(message);
19521
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
19522
+ server.emit("wsClientError", err, socket, req);
19523
+ } else {
19524
+ abortHandshake(socket, code, message, headers);
19525
+ }
19526
+ }
19527
+ }
19528
+ });
19529
+
15914
19530
  // src/index.ts
15915
19531
  var index_exports = {};
15916
19532
  __export(index_exports, {
@@ -32170,8 +35786,8 @@ var quantumImPlugin = {
32170
35786
  /** 强制调整块级流式的截断阈值,让切块更频繁 */
32171
35787
  streaming: {
32172
35788
  blockStreamingCoalesceDefaults: {
32173
- minChars: 200,
32174
- // 缓冲只要满 200 字且遇到断句,就会立刻发出一块消息
35789
+ minChars: 50,
35790
+ // 缓冲只要满 50 字且遇到断句,就会立刻发出一块消息
32175
35791
  idleMs: 800
32176
35792
  // 思考停顿超过 0.8秒 立刻发出当前累积的段落
32177
35793
  }
@@ -33174,8 +36790,15 @@ var TokenManager = class {
33174
36790
  }
33175
36791
  };
33176
36792
 
36793
+ // node_modules/ws/wrapper.mjs
36794
+ var import_stream = __toESM(require_stream3(), 1);
36795
+ var import_receiver = __toESM(require_receiver(), 1);
36796
+ var import_sender = __toESM(require_sender(), 1);
36797
+ var import_websocket = __toESM(require_websocket(), 1);
36798
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
36799
+ var wrapper_default = import_websocket.default;
36800
+
33177
36801
  // src/transport/ws-client.ts
33178
- var import_ws = __toESM(require("ws"), 1);
33179
36802
  var import_node_events = require("events");
33180
36803
  var log22 = createLogger("transport/ws-client");
33181
36804
  var WSClient = class extends import_node_events.EventEmitter {
@@ -33201,7 +36824,7 @@ var WSClient = class extends import_node_events.EventEmitter {
33201
36824
  const { url: url2, protocols, headers } = options;
33202
36825
  log22.info("ws:connecting", { url: url2 });
33203
36826
  return new Promise((resolve3, reject) => {
33204
- const ws = new import_ws.default(url2, protocols, {
36827
+ const ws = new wrapper_default(url2, protocols, {
33205
36828
  headers,
33206
36829
  maxPayload: 5 * 1024 * 1024
33207
36830
  // 5MB — 防止恶意超大帧导致内存耗尽
@@ -33235,7 +36858,7 @@ var WSClient = class extends import_node_events.EventEmitter {
33235
36858
  }
33236
36859
  /** 发送数据到服务器 — 前置检查连接状态 */
33237
36860
  send(data) {
33238
- if (!this.ws || this.ws.readyState !== import_ws.default.OPEN) {
36861
+ if (!this.ws || this.ws.readyState !== wrapper_default.OPEN) {
33239
36862
  log22.warn("ws:send skipped, not connected", { readyState: this.ws?.readyState });
33240
36863
  return;
33241
36864
  }
@@ -33243,7 +36866,7 @@ var WSClient = class extends import_node_events.EventEmitter {
33243
36866
  }
33244
36867
  /** 发送 WebSocket 协议级 Ping 帧 */
33245
36868
  ping() {
33246
- if (this.ws && this.ws.readyState === import_ws.default.OPEN) {
36869
+ if (this.ws && this.ws.readyState === wrapper_default.OPEN) {
33247
36870
  this.ws.ping();
33248
36871
  }
33249
36872
  }
@@ -33258,7 +36881,7 @@ var WSClient = class extends import_node_events.EventEmitter {
33258
36881
  }
33259
36882
  /** 当前连接状态 (0=CONNECTING, 1=OPEN, 2=CLOSING, 3=CLOSED) */
33260
36883
  get readyState() {
33261
- return this.ws?.readyState ?? import_ws.default.CLOSED;
36884
+ return this.ws?.readyState ?? wrapper_default.CLOSED;
33262
36885
  }
33263
36886
  };
33264
36887
 
@@ -34071,7 +37694,6 @@ var MessagePipe = class _MessagePipe {
34071
37694
  };
34072
37695
 
34073
37696
  // src/transport/connection-manager.ts
34074
- var import_ws2 = __toESM(require("ws"), 1);
34075
37697
  var log26 = createLogger("transport/connection-manager");
34076
37698
  function sleep2(ms) {
34077
37699
  return new Promise((resolve3) => setTimeout(resolve3, ms));
@@ -34169,7 +37791,7 @@ var ConnectionManager = class {
34169
37791
  this.stopHeartbeat();
34170
37792
  this.pongReceived = true;
34171
37793
  this.heartbeatTimer = setInterval(() => {
34172
- if (this.client.readyState !== import_ws2.default.OPEN) {
37794
+ if (this.client.readyState !== wrapper_default.OPEN) {
34173
37795
  log26.warn("heartbeat: connection not open, scheduling reconnect");
34174
37796
  this.scheduleReconnect();
34175
37797
  return;
@@ -34296,7 +37918,7 @@ var ConnectionManager = class {
34296
37918
  }
34297
37919
  /** 当前是否已连接 (WebSocket readyState === OPEN) */
34298
37920
  get isConnected() {
34299
- return this.client.readyState === import_ws2.default.OPEN;
37921
+ return this.client.readyState === wrapper_default.OPEN;
34300
37922
  }
34301
37923
  };
34302
37924