@usherlabs/cex-broker 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/cli.js +452 -26
- package/dist/index.js +666 -3082
- package/dist/proto/node.proto +53 -0
- package/dist/server.d.ts +7 -0
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
2
|
var __create = Object.create;
|
|
3
3
|
var __getProtoOf = Object.getPrototypeOf;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -26,7 +26,7 @@ var __export = (target, all) => {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
29
|
-
var __require =
|
|
29
|
+
var __require = import.meta.require;
|
|
30
30
|
|
|
31
31
|
// node_modules/@grpc/grpc-js/build/src/constants.js
|
|
32
32
|
var require_constants = __commonJS((exports) => {
|
|
@@ -4173,7 +4173,7 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
4173
4173
|
var rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde";
|
|
4174
4174
|
var rsVarRange = "\\ufe0e\\ufe0f";
|
|
4175
4175
|
var rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
|
|
4176
|
-
var rsApos = "['
|
|
4176
|
+
var rsApos = "['\u2019]";
|
|
4177
4177
|
var rsAstral = "[" + rsAstralRange + "]";
|
|
4178
4178
|
var rsBreak = "[" + rsBreakRange + "]";
|
|
4179
4179
|
var rsCombo = "[" + rsComboMarksRange + rsComboSymbolsRange + "]";
|
|
@@ -4212,196 +4212,196 @@ var require_lodash = __commonJS((exports, module) => {
|
|
|
4212
4212
|
var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + "]");
|
|
4213
4213
|
var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
|
|
4214
4214
|
var deburredLetters = {
|
|
4215
|
-
"
|
|
4216
|
-
"
|
|
4217
|
-
"
|
|
4218
|
-
"
|
|
4219
|
-
"
|
|
4220
|
-
"
|
|
4221
|
-
"
|
|
4222
|
-
"
|
|
4223
|
-
"
|
|
4224
|
-
"
|
|
4225
|
-
"
|
|
4226
|
-
"
|
|
4227
|
-
"
|
|
4228
|
-
"
|
|
4229
|
-
"
|
|
4230
|
-
"
|
|
4231
|
-
"
|
|
4232
|
-
"
|
|
4233
|
-
"
|
|
4234
|
-
"
|
|
4235
|
-
"
|
|
4236
|
-
"
|
|
4237
|
-
"
|
|
4238
|
-
"
|
|
4239
|
-
"
|
|
4240
|
-
"
|
|
4241
|
-
"
|
|
4242
|
-
"
|
|
4243
|
-
"
|
|
4244
|
-
"
|
|
4245
|
-
"
|
|
4246
|
-
"
|
|
4247
|
-
"
|
|
4248
|
-
"
|
|
4249
|
-
"
|
|
4250
|
-
"
|
|
4251
|
-
"
|
|
4252
|
-
"
|
|
4253
|
-
"
|
|
4254
|
-
"
|
|
4255
|
-
"
|
|
4256
|
-
"
|
|
4257
|
-
"
|
|
4258
|
-
"
|
|
4259
|
-
"
|
|
4260
|
-
"
|
|
4261
|
-
"
|
|
4262
|
-
"
|
|
4263
|
-
"
|
|
4264
|
-
"
|
|
4265
|
-
"
|
|
4266
|
-
"
|
|
4267
|
-
"
|
|
4268
|
-
"
|
|
4269
|
-
"
|
|
4270
|
-
"
|
|
4271
|
-
"
|
|
4272
|
-
"
|
|
4273
|
-
"
|
|
4274
|
-
"
|
|
4275
|
-
"
|
|
4276
|
-
"
|
|
4277
|
-
"
|
|
4278
|
-
"
|
|
4279
|
-
"
|
|
4280
|
-
"
|
|
4281
|
-
"
|
|
4282
|
-
"
|
|
4283
|
-
"
|
|
4284
|
-
"
|
|
4285
|
-
"
|
|
4286
|
-
"
|
|
4287
|
-
"
|
|
4288
|
-
"
|
|
4289
|
-
"
|
|
4290
|
-
"
|
|
4291
|
-
"
|
|
4292
|
-
"
|
|
4293
|
-
"
|
|
4294
|
-
"
|
|
4295
|
-
"
|
|
4296
|
-
"
|
|
4297
|
-
"
|
|
4298
|
-
"
|
|
4299
|
-
"
|
|
4300
|
-
"
|
|
4301
|
-
"
|
|
4302
|
-
"
|
|
4303
|
-
"
|
|
4304
|
-
"
|
|
4305
|
-
"
|
|
4306
|
-
"
|
|
4307
|
-
"
|
|
4308
|
-
"
|
|
4309
|
-
"
|
|
4310
|
-
"
|
|
4311
|
-
"
|
|
4312
|
-
"
|
|
4313
|
-
"
|
|
4314
|
-
"
|
|
4315
|
-
"
|
|
4316
|
-
"
|
|
4317
|
-
"
|
|
4318
|
-
"
|
|
4319
|
-
"
|
|
4320
|
-
"
|
|
4321
|
-
"
|
|
4322
|
-
"
|
|
4323
|
-
"
|
|
4324
|
-
"
|
|
4325
|
-
"
|
|
4326
|
-
"
|
|
4327
|
-
"
|
|
4328
|
-
"
|
|
4329
|
-
"
|
|
4330
|
-
"
|
|
4331
|
-
"
|
|
4332
|
-
"
|
|
4333
|
-
"
|
|
4334
|
-
"
|
|
4335
|
-
"
|
|
4336
|
-
"
|
|
4337
|
-
"
|
|
4338
|
-
"
|
|
4339
|
-
"
|
|
4340
|
-
"
|
|
4341
|
-
"
|
|
4342
|
-
"
|
|
4343
|
-
"
|
|
4344
|
-
"
|
|
4345
|
-
"
|
|
4346
|
-
"
|
|
4347
|
-
"
|
|
4348
|
-
"
|
|
4349
|
-
"
|
|
4350
|
-
"
|
|
4351
|
-
"
|
|
4352
|
-
"
|
|
4353
|
-
"
|
|
4354
|
-
"
|
|
4355
|
-
"
|
|
4356
|
-
"
|
|
4357
|
-
"
|
|
4358
|
-
"
|
|
4359
|
-
"
|
|
4360
|
-
"
|
|
4361
|
-
"
|
|
4362
|
-
"
|
|
4363
|
-
"
|
|
4364
|
-
"
|
|
4365
|
-
"
|
|
4366
|
-
"
|
|
4367
|
-
"
|
|
4368
|
-
"
|
|
4369
|
-
"
|
|
4370
|
-
"
|
|
4371
|
-
"
|
|
4372
|
-
"
|
|
4373
|
-
"
|
|
4374
|
-
"
|
|
4375
|
-
"
|
|
4376
|
-
"
|
|
4377
|
-
"
|
|
4378
|
-
"
|
|
4379
|
-
"
|
|
4380
|
-
"
|
|
4381
|
-
"
|
|
4382
|
-
"
|
|
4383
|
-
"
|
|
4384
|
-
"
|
|
4385
|
-
"
|
|
4386
|
-
"
|
|
4387
|
-
"
|
|
4388
|
-
"
|
|
4389
|
-
"
|
|
4390
|
-
"
|
|
4391
|
-
"
|
|
4392
|
-
"
|
|
4393
|
-
"
|
|
4394
|
-
"
|
|
4395
|
-
"
|
|
4396
|
-
"
|
|
4397
|
-
"
|
|
4398
|
-
"
|
|
4399
|
-
"
|
|
4400
|
-
"
|
|
4401
|
-
"
|
|
4402
|
-
"
|
|
4403
|
-
"
|
|
4404
|
-
"
|
|
4215
|
+
"\xC0": "A",
|
|
4216
|
+
"\xC1": "A",
|
|
4217
|
+
"\xC2": "A",
|
|
4218
|
+
"\xC3": "A",
|
|
4219
|
+
"\xC4": "A",
|
|
4220
|
+
"\xC5": "A",
|
|
4221
|
+
"\xE0": "a",
|
|
4222
|
+
"\xE1": "a",
|
|
4223
|
+
"\xE2": "a",
|
|
4224
|
+
"\xE3": "a",
|
|
4225
|
+
"\xE4": "a",
|
|
4226
|
+
"\xE5": "a",
|
|
4227
|
+
"\xC7": "C",
|
|
4228
|
+
"\xE7": "c",
|
|
4229
|
+
"\xD0": "D",
|
|
4230
|
+
"\xF0": "d",
|
|
4231
|
+
"\xC8": "E",
|
|
4232
|
+
"\xC9": "E",
|
|
4233
|
+
"\xCA": "E",
|
|
4234
|
+
"\xCB": "E",
|
|
4235
|
+
"\xE8": "e",
|
|
4236
|
+
"\xE9": "e",
|
|
4237
|
+
"\xEA": "e",
|
|
4238
|
+
"\xEB": "e",
|
|
4239
|
+
"\xCC": "I",
|
|
4240
|
+
"\xCD": "I",
|
|
4241
|
+
"\xCE": "I",
|
|
4242
|
+
"\xCF": "I",
|
|
4243
|
+
"\xEC": "i",
|
|
4244
|
+
"\xED": "i",
|
|
4245
|
+
"\xEE": "i",
|
|
4246
|
+
"\xEF": "i",
|
|
4247
|
+
"\xD1": "N",
|
|
4248
|
+
"\xF1": "n",
|
|
4249
|
+
"\xD2": "O",
|
|
4250
|
+
"\xD3": "O",
|
|
4251
|
+
"\xD4": "O",
|
|
4252
|
+
"\xD5": "O",
|
|
4253
|
+
"\xD6": "O",
|
|
4254
|
+
"\xD8": "O",
|
|
4255
|
+
"\xF2": "o",
|
|
4256
|
+
"\xF3": "o",
|
|
4257
|
+
"\xF4": "o",
|
|
4258
|
+
"\xF5": "o",
|
|
4259
|
+
"\xF6": "o",
|
|
4260
|
+
"\xF8": "o",
|
|
4261
|
+
"\xD9": "U",
|
|
4262
|
+
"\xDA": "U",
|
|
4263
|
+
"\xDB": "U",
|
|
4264
|
+
"\xDC": "U",
|
|
4265
|
+
"\xF9": "u",
|
|
4266
|
+
"\xFA": "u",
|
|
4267
|
+
"\xFB": "u",
|
|
4268
|
+
"\xFC": "u",
|
|
4269
|
+
"\xDD": "Y",
|
|
4270
|
+
"\xFD": "y",
|
|
4271
|
+
"\xFF": "y",
|
|
4272
|
+
"\xC6": "Ae",
|
|
4273
|
+
"\xE6": "ae",
|
|
4274
|
+
"\xDE": "Th",
|
|
4275
|
+
"\xFE": "th",
|
|
4276
|
+
"\xDF": "ss",
|
|
4277
|
+
"\u0100": "A",
|
|
4278
|
+
"\u0102": "A",
|
|
4279
|
+
"\u0104": "A",
|
|
4280
|
+
"\u0101": "a",
|
|
4281
|
+
"\u0103": "a",
|
|
4282
|
+
"\u0105": "a",
|
|
4283
|
+
"\u0106": "C",
|
|
4284
|
+
"\u0108": "C",
|
|
4285
|
+
"\u010A": "C",
|
|
4286
|
+
"\u010C": "C",
|
|
4287
|
+
"\u0107": "c",
|
|
4288
|
+
"\u0109": "c",
|
|
4289
|
+
"\u010B": "c",
|
|
4290
|
+
"\u010D": "c",
|
|
4291
|
+
"\u010E": "D",
|
|
4292
|
+
"\u0110": "D",
|
|
4293
|
+
"\u010F": "d",
|
|
4294
|
+
"\u0111": "d",
|
|
4295
|
+
"\u0112": "E",
|
|
4296
|
+
"\u0114": "E",
|
|
4297
|
+
"\u0116": "E",
|
|
4298
|
+
"\u0118": "E",
|
|
4299
|
+
"\u011A": "E",
|
|
4300
|
+
"\u0113": "e",
|
|
4301
|
+
"\u0115": "e",
|
|
4302
|
+
"\u0117": "e",
|
|
4303
|
+
"\u0119": "e",
|
|
4304
|
+
"\u011B": "e",
|
|
4305
|
+
"\u011C": "G",
|
|
4306
|
+
"\u011E": "G",
|
|
4307
|
+
"\u0120": "G",
|
|
4308
|
+
"\u0122": "G",
|
|
4309
|
+
"\u011D": "g",
|
|
4310
|
+
"\u011F": "g",
|
|
4311
|
+
"\u0121": "g",
|
|
4312
|
+
"\u0123": "g",
|
|
4313
|
+
"\u0124": "H",
|
|
4314
|
+
"\u0126": "H",
|
|
4315
|
+
"\u0125": "h",
|
|
4316
|
+
"\u0127": "h",
|
|
4317
|
+
"\u0128": "I",
|
|
4318
|
+
"\u012A": "I",
|
|
4319
|
+
"\u012C": "I",
|
|
4320
|
+
"\u012E": "I",
|
|
4321
|
+
"\u0130": "I",
|
|
4322
|
+
"\u0129": "i",
|
|
4323
|
+
"\u012B": "i",
|
|
4324
|
+
"\u012D": "i",
|
|
4325
|
+
"\u012F": "i",
|
|
4326
|
+
"\u0131": "i",
|
|
4327
|
+
"\u0134": "J",
|
|
4328
|
+
"\u0135": "j",
|
|
4329
|
+
"\u0136": "K",
|
|
4330
|
+
"\u0137": "k",
|
|
4331
|
+
"\u0138": "k",
|
|
4332
|
+
"\u0139": "L",
|
|
4333
|
+
"\u013B": "L",
|
|
4334
|
+
"\u013D": "L",
|
|
4335
|
+
"\u013F": "L",
|
|
4336
|
+
"\u0141": "L",
|
|
4337
|
+
"\u013A": "l",
|
|
4338
|
+
"\u013C": "l",
|
|
4339
|
+
"\u013E": "l",
|
|
4340
|
+
"\u0140": "l",
|
|
4341
|
+
"\u0142": "l",
|
|
4342
|
+
"\u0143": "N",
|
|
4343
|
+
"\u0145": "N",
|
|
4344
|
+
"\u0147": "N",
|
|
4345
|
+
"\u014A": "N",
|
|
4346
|
+
"\u0144": "n",
|
|
4347
|
+
"\u0146": "n",
|
|
4348
|
+
"\u0148": "n",
|
|
4349
|
+
"\u014B": "n",
|
|
4350
|
+
"\u014C": "O",
|
|
4351
|
+
"\u014E": "O",
|
|
4352
|
+
"\u0150": "O",
|
|
4353
|
+
"\u014D": "o",
|
|
4354
|
+
"\u014F": "o",
|
|
4355
|
+
"\u0151": "o",
|
|
4356
|
+
"\u0154": "R",
|
|
4357
|
+
"\u0156": "R",
|
|
4358
|
+
"\u0158": "R",
|
|
4359
|
+
"\u0155": "r",
|
|
4360
|
+
"\u0157": "r",
|
|
4361
|
+
"\u0159": "r",
|
|
4362
|
+
"\u015A": "S",
|
|
4363
|
+
"\u015C": "S",
|
|
4364
|
+
"\u015E": "S",
|
|
4365
|
+
"\u0160": "S",
|
|
4366
|
+
"\u015B": "s",
|
|
4367
|
+
"\u015D": "s",
|
|
4368
|
+
"\u015F": "s",
|
|
4369
|
+
"\u0161": "s",
|
|
4370
|
+
"\u0162": "T",
|
|
4371
|
+
"\u0164": "T",
|
|
4372
|
+
"\u0166": "T",
|
|
4373
|
+
"\u0163": "t",
|
|
4374
|
+
"\u0165": "t",
|
|
4375
|
+
"\u0167": "t",
|
|
4376
|
+
"\u0168": "U",
|
|
4377
|
+
"\u016A": "U",
|
|
4378
|
+
"\u016C": "U",
|
|
4379
|
+
"\u016E": "U",
|
|
4380
|
+
"\u0170": "U",
|
|
4381
|
+
"\u0172": "U",
|
|
4382
|
+
"\u0169": "u",
|
|
4383
|
+
"\u016B": "u",
|
|
4384
|
+
"\u016D": "u",
|
|
4385
|
+
"\u016F": "u",
|
|
4386
|
+
"\u0171": "u",
|
|
4387
|
+
"\u0173": "u",
|
|
4388
|
+
"\u0174": "W",
|
|
4389
|
+
"\u0175": "w",
|
|
4390
|
+
"\u0176": "Y",
|
|
4391
|
+
"\u0177": "y",
|
|
4392
|
+
"\u0178": "Y",
|
|
4393
|
+
"\u0179": "Z",
|
|
4394
|
+
"\u017B": "Z",
|
|
4395
|
+
"\u017D": "Z",
|
|
4396
|
+
"\u017A": "z",
|
|
4397
|
+
"\u017C": "z",
|
|
4398
|
+
"\u017E": "z",
|
|
4399
|
+
"\u0132": "IJ",
|
|
4400
|
+
"\u0133": "ij",
|
|
4401
|
+
"\u0152": "Oe",
|
|
4402
|
+
"\u0153": "oe",
|
|
4403
|
+
"\u0149": "'n",
|
|
4404
|
+
"\u017F": "ss"
|
|
4405
4405
|
};
|
|
4406
4406
|
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
4407
4407
|
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
@@ -12890,7 +12890,7 @@ var require_src2 = __commonJS((exports) => {
|
|
|
12890
12890
|
|
|
12891
12891
|
// node_modules/@grpc/grpc-js/build/src/channelz.js
|
|
12892
12892
|
var require_channelz = __commonJS((exports) => {
|
|
12893
|
-
var __dirname = "/home/
|
|
12893
|
+
var __dirname = "/home/runner/work/cex-broker/cex-broker/node_modules/@grpc/grpc-js/build/src";
|
|
12894
12894
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12895
12895
|
exports.registerChannelzSocket = exports.registerChannelzServer = exports.registerChannelzSubchannel = exports.registerChannelzChannel = exports.ChannelzCallTrackerStub = exports.ChannelzCallTracker = exports.ChannelzChildrenTrackerStub = exports.ChannelzChildrenTracker = exports.ChannelzTrace = exports.ChannelzTraceStub = undefined;
|
|
12896
12896
|
exports.unregisterChannelzRef = unregisterChannelzRef;
|
|
@@ -22168,2843 +22168,6 @@ var require_qs = __commonJS((exports, module) => {
|
|
|
22168
22168
|
};
|
|
22169
22169
|
});
|
|
22170
22170
|
|
|
22171
|
-
// node_modules/ws/lib/constants.js
|
|
22172
|
-
var require_constants2 = __commonJS((exports, module) => {
|
|
22173
|
-
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
22174
|
-
var hasBlob = typeof Blob !== "undefined";
|
|
22175
|
-
if (hasBlob)
|
|
22176
|
-
BINARY_TYPES.push("blob");
|
|
22177
|
-
module.exports = {
|
|
22178
|
-
BINARY_TYPES,
|
|
22179
|
-
EMPTY_BUFFER: Buffer.alloc(0),
|
|
22180
|
-
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
22181
|
-
hasBlob,
|
|
22182
|
-
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
22183
|
-
kListener: Symbol("kListener"),
|
|
22184
|
-
kStatusCode: Symbol("status-code"),
|
|
22185
|
-
kWebSocket: Symbol("websocket"),
|
|
22186
|
-
NOOP: () => {}
|
|
22187
|
-
};
|
|
22188
|
-
});
|
|
22189
|
-
|
|
22190
|
-
// node_modules/ws/lib/buffer-util.js
|
|
22191
|
-
var require_buffer_util = __commonJS((exports, module) => {
|
|
22192
|
-
var { EMPTY_BUFFER } = require_constants2();
|
|
22193
|
-
var FastBuffer = Buffer[Symbol.species];
|
|
22194
|
-
function concat(list, totalLength) {
|
|
22195
|
-
if (list.length === 0)
|
|
22196
|
-
return EMPTY_BUFFER;
|
|
22197
|
-
if (list.length === 1)
|
|
22198
|
-
return list[0];
|
|
22199
|
-
const target = Buffer.allocUnsafe(totalLength);
|
|
22200
|
-
let offset = 0;
|
|
22201
|
-
for (let i = 0;i < list.length; i++) {
|
|
22202
|
-
const buf = list[i];
|
|
22203
|
-
target.set(buf, offset);
|
|
22204
|
-
offset += buf.length;
|
|
22205
|
-
}
|
|
22206
|
-
if (offset < totalLength) {
|
|
22207
|
-
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
22208
|
-
}
|
|
22209
|
-
return target;
|
|
22210
|
-
}
|
|
22211
|
-
function _mask(source, mask, output2, offset, length) {
|
|
22212
|
-
for (let i = 0;i < length; i++) {
|
|
22213
|
-
output2[offset + i] = source[i] ^ mask[i & 3];
|
|
22214
|
-
}
|
|
22215
|
-
}
|
|
22216
|
-
function _unmask(buffer, mask) {
|
|
22217
|
-
for (let i = 0;i < buffer.length; i++) {
|
|
22218
|
-
buffer[i] ^= mask[i & 3];
|
|
22219
|
-
}
|
|
22220
|
-
}
|
|
22221
|
-
function toArrayBuffer(buf) {
|
|
22222
|
-
if (buf.length === buf.buffer.byteLength) {
|
|
22223
|
-
return buf.buffer;
|
|
22224
|
-
}
|
|
22225
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
22226
|
-
}
|
|
22227
|
-
function toBuffer(data) {
|
|
22228
|
-
toBuffer.readOnly = true;
|
|
22229
|
-
if (Buffer.isBuffer(data))
|
|
22230
|
-
return data;
|
|
22231
|
-
let buf;
|
|
22232
|
-
if (data instanceof ArrayBuffer) {
|
|
22233
|
-
buf = new FastBuffer(data);
|
|
22234
|
-
} else if (ArrayBuffer.isView(data)) {
|
|
22235
|
-
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
22236
|
-
} else {
|
|
22237
|
-
buf = Buffer.from(data);
|
|
22238
|
-
toBuffer.readOnly = false;
|
|
22239
|
-
}
|
|
22240
|
-
return buf;
|
|
22241
|
-
}
|
|
22242
|
-
module.exports = {
|
|
22243
|
-
concat,
|
|
22244
|
-
mask: _mask,
|
|
22245
|
-
toArrayBuffer,
|
|
22246
|
-
toBuffer,
|
|
22247
|
-
unmask: _unmask
|
|
22248
|
-
};
|
|
22249
|
-
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
22250
|
-
try {
|
|
22251
|
-
const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
|
|
22252
|
-
module.exports.mask = function(source, mask, output2, offset, length) {
|
|
22253
|
-
if (length < 48)
|
|
22254
|
-
_mask(source, mask, output2, offset, length);
|
|
22255
|
-
else
|
|
22256
|
-
bufferUtil.mask(source, mask, output2, offset, length);
|
|
22257
|
-
};
|
|
22258
|
-
module.exports.unmask = function(buffer, mask) {
|
|
22259
|
-
if (buffer.length < 32)
|
|
22260
|
-
_unmask(buffer, mask);
|
|
22261
|
-
else
|
|
22262
|
-
bufferUtil.unmask(buffer, mask);
|
|
22263
|
-
};
|
|
22264
|
-
} catch (e) {}
|
|
22265
|
-
}
|
|
22266
|
-
});
|
|
22267
|
-
|
|
22268
|
-
// node_modules/ws/lib/limiter.js
|
|
22269
|
-
var require_limiter = __commonJS((exports, module) => {
|
|
22270
|
-
var kDone = Symbol("kDone");
|
|
22271
|
-
var kRun = Symbol("kRun");
|
|
22272
|
-
|
|
22273
|
-
class Limiter {
|
|
22274
|
-
constructor(concurrency) {
|
|
22275
|
-
this[kDone] = () => {
|
|
22276
|
-
this.pending--;
|
|
22277
|
-
this[kRun]();
|
|
22278
|
-
};
|
|
22279
|
-
this.concurrency = concurrency || Infinity;
|
|
22280
|
-
this.jobs = [];
|
|
22281
|
-
this.pending = 0;
|
|
22282
|
-
}
|
|
22283
|
-
add(job) {
|
|
22284
|
-
this.jobs.push(job);
|
|
22285
|
-
this[kRun]();
|
|
22286
|
-
}
|
|
22287
|
-
[kRun]() {
|
|
22288
|
-
if (this.pending === this.concurrency)
|
|
22289
|
-
return;
|
|
22290
|
-
if (this.jobs.length) {
|
|
22291
|
-
const job = this.jobs.shift();
|
|
22292
|
-
this.pending++;
|
|
22293
|
-
job(this[kDone]);
|
|
22294
|
-
}
|
|
22295
|
-
}
|
|
22296
|
-
}
|
|
22297
|
-
module.exports = Limiter;
|
|
22298
|
-
});
|
|
22299
|
-
|
|
22300
|
-
// node_modules/ws/lib/permessage-deflate.js
|
|
22301
|
-
var require_permessage_deflate = __commonJS((exports, module) => {
|
|
22302
|
-
var zlib = __require("zlib");
|
|
22303
|
-
var bufferUtil = require_buffer_util();
|
|
22304
|
-
var Limiter = require_limiter();
|
|
22305
|
-
var { kStatusCode } = require_constants2();
|
|
22306
|
-
var FastBuffer = Buffer[Symbol.species];
|
|
22307
|
-
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
22308
|
-
var kPerMessageDeflate = Symbol("permessage-deflate");
|
|
22309
|
-
var kTotalLength = Symbol("total-length");
|
|
22310
|
-
var kCallback = Symbol("callback");
|
|
22311
|
-
var kBuffers = Symbol("buffers");
|
|
22312
|
-
var kError = Symbol("error");
|
|
22313
|
-
var zlibLimiter;
|
|
22314
|
-
|
|
22315
|
-
class PerMessageDeflate {
|
|
22316
|
-
constructor(options, isServer, maxPayload) {
|
|
22317
|
-
this._maxPayload = maxPayload | 0;
|
|
22318
|
-
this._options = options || {};
|
|
22319
|
-
this._threshold = this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
22320
|
-
this._isServer = !!isServer;
|
|
22321
|
-
this._deflate = null;
|
|
22322
|
-
this._inflate = null;
|
|
22323
|
-
this.params = null;
|
|
22324
|
-
if (!zlibLimiter) {
|
|
22325
|
-
const concurrency = this._options.concurrencyLimit !== undefined ? this._options.concurrencyLimit : 10;
|
|
22326
|
-
zlibLimiter = new Limiter(concurrency);
|
|
22327
|
-
}
|
|
22328
|
-
}
|
|
22329
|
-
static get extensionName() {
|
|
22330
|
-
return "permessage-deflate";
|
|
22331
|
-
}
|
|
22332
|
-
offer() {
|
|
22333
|
-
const params = {};
|
|
22334
|
-
if (this._options.serverNoContextTakeover) {
|
|
22335
|
-
params.server_no_context_takeover = true;
|
|
22336
|
-
}
|
|
22337
|
-
if (this._options.clientNoContextTakeover) {
|
|
22338
|
-
params.client_no_context_takeover = true;
|
|
22339
|
-
}
|
|
22340
|
-
if (this._options.serverMaxWindowBits) {
|
|
22341
|
-
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
22342
|
-
}
|
|
22343
|
-
if (this._options.clientMaxWindowBits) {
|
|
22344
|
-
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
22345
|
-
} else if (this._options.clientMaxWindowBits == null) {
|
|
22346
|
-
params.client_max_window_bits = true;
|
|
22347
|
-
}
|
|
22348
|
-
return params;
|
|
22349
|
-
}
|
|
22350
|
-
accept(configurations) {
|
|
22351
|
-
configurations = this.normalizeParams(configurations);
|
|
22352
|
-
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
22353
|
-
return this.params;
|
|
22354
|
-
}
|
|
22355
|
-
cleanup() {
|
|
22356
|
-
if (this._inflate) {
|
|
22357
|
-
this._inflate.close();
|
|
22358
|
-
this._inflate = null;
|
|
22359
|
-
}
|
|
22360
|
-
if (this._deflate) {
|
|
22361
|
-
const callback = this._deflate[kCallback];
|
|
22362
|
-
this._deflate.close();
|
|
22363
|
-
this._deflate = null;
|
|
22364
|
-
if (callback) {
|
|
22365
|
-
callback(new Error("The deflate stream was closed while data was being processed"));
|
|
22366
|
-
}
|
|
22367
|
-
}
|
|
22368
|
-
}
|
|
22369
|
-
acceptAsServer(offers) {
|
|
22370
|
-
const opts = this._options;
|
|
22371
|
-
const accepted = offers.find((params) => {
|
|
22372
|
-
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) {
|
|
22373
|
-
return false;
|
|
22374
|
-
}
|
|
22375
|
-
return true;
|
|
22376
|
-
});
|
|
22377
|
-
if (!accepted) {
|
|
22378
|
-
throw new Error("None of the extension offers can be accepted");
|
|
22379
|
-
}
|
|
22380
|
-
if (opts.serverNoContextTakeover) {
|
|
22381
|
-
accepted.server_no_context_takeover = true;
|
|
22382
|
-
}
|
|
22383
|
-
if (opts.clientNoContextTakeover) {
|
|
22384
|
-
accepted.client_no_context_takeover = true;
|
|
22385
|
-
}
|
|
22386
|
-
if (typeof opts.serverMaxWindowBits === "number") {
|
|
22387
|
-
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
22388
|
-
}
|
|
22389
|
-
if (typeof opts.clientMaxWindowBits === "number") {
|
|
22390
|
-
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
22391
|
-
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
22392
|
-
delete accepted.client_max_window_bits;
|
|
22393
|
-
}
|
|
22394
|
-
return accepted;
|
|
22395
|
-
}
|
|
22396
|
-
acceptAsClient(response) {
|
|
22397
|
-
const params = response[0];
|
|
22398
|
-
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
22399
|
-
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
22400
|
-
}
|
|
22401
|
-
if (!params.client_max_window_bits) {
|
|
22402
|
-
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
22403
|
-
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
22404
|
-
}
|
|
22405
|
-
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
22406
|
-
throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
22407
|
-
}
|
|
22408
|
-
return params;
|
|
22409
|
-
}
|
|
22410
|
-
normalizeParams(configurations) {
|
|
22411
|
-
configurations.forEach((params) => {
|
|
22412
|
-
Object.keys(params).forEach((key) => {
|
|
22413
|
-
let value = params[key];
|
|
22414
|
-
if (value.length > 1) {
|
|
22415
|
-
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
22416
|
-
}
|
|
22417
|
-
value = value[0];
|
|
22418
|
-
if (key === "client_max_window_bits") {
|
|
22419
|
-
if (value !== true) {
|
|
22420
|
-
const num = +value;
|
|
22421
|
-
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
22422
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
22423
|
-
}
|
|
22424
|
-
value = num;
|
|
22425
|
-
} else if (!this._isServer) {
|
|
22426
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
22427
|
-
}
|
|
22428
|
-
} else if (key === "server_max_window_bits") {
|
|
22429
|
-
const num = +value;
|
|
22430
|
-
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
22431
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
22432
|
-
}
|
|
22433
|
-
value = num;
|
|
22434
|
-
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
22435
|
-
if (value !== true) {
|
|
22436
|
-
throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
22437
|
-
}
|
|
22438
|
-
} else {
|
|
22439
|
-
throw new Error(`Unknown parameter "${key}"`);
|
|
22440
|
-
}
|
|
22441
|
-
params[key] = value;
|
|
22442
|
-
});
|
|
22443
|
-
});
|
|
22444
|
-
return configurations;
|
|
22445
|
-
}
|
|
22446
|
-
decompress(data, fin, callback) {
|
|
22447
|
-
zlibLimiter.add((done) => {
|
|
22448
|
-
this._decompress(data, fin, (err, result) => {
|
|
22449
|
-
done();
|
|
22450
|
-
callback(err, result);
|
|
22451
|
-
});
|
|
22452
|
-
});
|
|
22453
|
-
}
|
|
22454
|
-
compress(data, fin, callback) {
|
|
22455
|
-
zlibLimiter.add((done) => {
|
|
22456
|
-
this._compress(data, fin, (err, result) => {
|
|
22457
|
-
done();
|
|
22458
|
-
callback(err, result);
|
|
22459
|
-
});
|
|
22460
|
-
});
|
|
22461
|
-
}
|
|
22462
|
-
_decompress(data, fin, callback) {
|
|
22463
|
-
const endpoint = this._isServer ? "client" : "server";
|
|
22464
|
-
if (!this._inflate) {
|
|
22465
|
-
const key = `${endpoint}_max_window_bits`;
|
|
22466
|
-
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
22467
|
-
this._inflate = zlib.createInflateRaw({
|
|
22468
|
-
...this._options.zlibInflateOptions,
|
|
22469
|
-
windowBits
|
|
22470
|
-
});
|
|
22471
|
-
this._inflate[kPerMessageDeflate] = this;
|
|
22472
|
-
this._inflate[kTotalLength] = 0;
|
|
22473
|
-
this._inflate[kBuffers] = [];
|
|
22474
|
-
this._inflate.on("error", inflateOnError);
|
|
22475
|
-
this._inflate.on("data", inflateOnData);
|
|
22476
|
-
}
|
|
22477
|
-
this._inflate[kCallback] = callback;
|
|
22478
|
-
this._inflate.write(data);
|
|
22479
|
-
if (fin)
|
|
22480
|
-
this._inflate.write(TRAILER);
|
|
22481
|
-
this._inflate.flush(() => {
|
|
22482
|
-
const err = this._inflate[kError];
|
|
22483
|
-
if (err) {
|
|
22484
|
-
this._inflate.close();
|
|
22485
|
-
this._inflate = null;
|
|
22486
|
-
callback(err);
|
|
22487
|
-
return;
|
|
22488
|
-
}
|
|
22489
|
-
const data2 = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
22490
|
-
if (this._inflate._readableState.endEmitted) {
|
|
22491
|
-
this._inflate.close();
|
|
22492
|
-
this._inflate = null;
|
|
22493
|
-
} else {
|
|
22494
|
-
this._inflate[kTotalLength] = 0;
|
|
22495
|
-
this._inflate[kBuffers] = [];
|
|
22496
|
-
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
22497
|
-
this._inflate.reset();
|
|
22498
|
-
}
|
|
22499
|
-
}
|
|
22500
|
-
callback(null, data2);
|
|
22501
|
-
});
|
|
22502
|
-
}
|
|
22503
|
-
_compress(data, fin, callback) {
|
|
22504
|
-
const endpoint = this._isServer ? "server" : "client";
|
|
22505
|
-
if (!this._deflate) {
|
|
22506
|
-
const key = `${endpoint}_max_window_bits`;
|
|
22507
|
-
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
22508
|
-
this._deflate = zlib.createDeflateRaw({
|
|
22509
|
-
...this._options.zlibDeflateOptions,
|
|
22510
|
-
windowBits
|
|
22511
|
-
});
|
|
22512
|
-
this._deflate[kTotalLength] = 0;
|
|
22513
|
-
this._deflate[kBuffers] = [];
|
|
22514
|
-
this._deflate.on("data", deflateOnData);
|
|
22515
|
-
}
|
|
22516
|
-
this._deflate[kCallback] = callback;
|
|
22517
|
-
this._deflate.write(data);
|
|
22518
|
-
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
22519
|
-
if (!this._deflate) {
|
|
22520
|
-
return;
|
|
22521
|
-
}
|
|
22522
|
-
let data2 = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
22523
|
-
if (fin) {
|
|
22524
|
-
data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
|
|
22525
|
-
}
|
|
22526
|
-
this._deflate[kCallback] = null;
|
|
22527
|
-
this._deflate[kTotalLength] = 0;
|
|
22528
|
-
this._deflate[kBuffers] = [];
|
|
22529
|
-
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
22530
|
-
this._deflate.reset();
|
|
22531
|
-
}
|
|
22532
|
-
callback(null, data2);
|
|
22533
|
-
});
|
|
22534
|
-
}
|
|
22535
|
-
}
|
|
22536
|
-
module.exports = PerMessageDeflate;
|
|
22537
|
-
function deflateOnData(chunk) {
|
|
22538
|
-
this[kBuffers].push(chunk);
|
|
22539
|
-
this[kTotalLength] += chunk.length;
|
|
22540
|
-
}
|
|
22541
|
-
function inflateOnData(chunk) {
|
|
22542
|
-
this[kTotalLength] += chunk.length;
|
|
22543
|
-
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
22544
|
-
this[kBuffers].push(chunk);
|
|
22545
|
-
return;
|
|
22546
|
-
}
|
|
22547
|
-
this[kError] = new RangeError("Max payload size exceeded");
|
|
22548
|
-
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
22549
|
-
this[kError][kStatusCode] = 1009;
|
|
22550
|
-
this.removeListener("data", inflateOnData);
|
|
22551
|
-
this.reset();
|
|
22552
|
-
}
|
|
22553
|
-
function inflateOnError(err) {
|
|
22554
|
-
this[kPerMessageDeflate]._inflate = null;
|
|
22555
|
-
if (this[kError]) {
|
|
22556
|
-
this[kCallback](this[kError]);
|
|
22557
|
-
return;
|
|
22558
|
-
}
|
|
22559
|
-
err[kStatusCode] = 1007;
|
|
22560
|
-
this[kCallback](err);
|
|
22561
|
-
}
|
|
22562
|
-
});
|
|
22563
|
-
|
|
22564
|
-
// node_modules/ws/lib/validation.js
|
|
22565
|
-
var require_validation = __commonJS((exports, module) => {
|
|
22566
|
-
var { isUtf8 } = __require("buffer");
|
|
22567
|
-
var { hasBlob } = require_constants2();
|
|
22568
|
-
var tokenChars = [
|
|
22569
|
-
0,
|
|
22570
|
-
0,
|
|
22571
|
-
0,
|
|
22572
|
-
0,
|
|
22573
|
-
0,
|
|
22574
|
-
0,
|
|
22575
|
-
0,
|
|
22576
|
-
0,
|
|
22577
|
-
0,
|
|
22578
|
-
0,
|
|
22579
|
-
0,
|
|
22580
|
-
0,
|
|
22581
|
-
0,
|
|
22582
|
-
0,
|
|
22583
|
-
0,
|
|
22584
|
-
0,
|
|
22585
|
-
0,
|
|
22586
|
-
0,
|
|
22587
|
-
0,
|
|
22588
|
-
0,
|
|
22589
|
-
0,
|
|
22590
|
-
0,
|
|
22591
|
-
0,
|
|
22592
|
-
0,
|
|
22593
|
-
0,
|
|
22594
|
-
0,
|
|
22595
|
-
0,
|
|
22596
|
-
0,
|
|
22597
|
-
0,
|
|
22598
|
-
0,
|
|
22599
|
-
0,
|
|
22600
|
-
0,
|
|
22601
|
-
0,
|
|
22602
|
-
1,
|
|
22603
|
-
0,
|
|
22604
|
-
1,
|
|
22605
|
-
1,
|
|
22606
|
-
1,
|
|
22607
|
-
1,
|
|
22608
|
-
1,
|
|
22609
|
-
0,
|
|
22610
|
-
0,
|
|
22611
|
-
1,
|
|
22612
|
-
1,
|
|
22613
|
-
0,
|
|
22614
|
-
1,
|
|
22615
|
-
1,
|
|
22616
|
-
0,
|
|
22617
|
-
1,
|
|
22618
|
-
1,
|
|
22619
|
-
1,
|
|
22620
|
-
1,
|
|
22621
|
-
1,
|
|
22622
|
-
1,
|
|
22623
|
-
1,
|
|
22624
|
-
1,
|
|
22625
|
-
1,
|
|
22626
|
-
1,
|
|
22627
|
-
0,
|
|
22628
|
-
0,
|
|
22629
|
-
0,
|
|
22630
|
-
0,
|
|
22631
|
-
0,
|
|
22632
|
-
0,
|
|
22633
|
-
0,
|
|
22634
|
-
1,
|
|
22635
|
-
1,
|
|
22636
|
-
1,
|
|
22637
|
-
1,
|
|
22638
|
-
1,
|
|
22639
|
-
1,
|
|
22640
|
-
1,
|
|
22641
|
-
1,
|
|
22642
|
-
1,
|
|
22643
|
-
1,
|
|
22644
|
-
1,
|
|
22645
|
-
1,
|
|
22646
|
-
1,
|
|
22647
|
-
1,
|
|
22648
|
-
1,
|
|
22649
|
-
1,
|
|
22650
|
-
1,
|
|
22651
|
-
1,
|
|
22652
|
-
1,
|
|
22653
|
-
1,
|
|
22654
|
-
1,
|
|
22655
|
-
1,
|
|
22656
|
-
1,
|
|
22657
|
-
1,
|
|
22658
|
-
1,
|
|
22659
|
-
1,
|
|
22660
|
-
0,
|
|
22661
|
-
0,
|
|
22662
|
-
0,
|
|
22663
|
-
1,
|
|
22664
|
-
1,
|
|
22665
|
-
1,
|
|
22666
|
-
1,
|
|
22667
|
-
1,
|
|
22668
|
-
1,
|
|
22669
|
-
1,
|
|
22670
|
-
1,
|
|
22671
|
-
1,
|
|
22672
|
-
1,
|
|
22673
|
-
1,
|
|
22674
|
-
1,
|
|
22675
|
-
1,
|
|
22676
|
-
1,
|
|
22677
|
-
1,
|
|
22678
|
-
1,
|
|
22679
|
-
1,
|
|
22680
|
-
1,
|
|
22681
|
-
1,
|
|
22682
|
-
1,
|
|
22683
|
-
1,
|
|
22684
|
-
1,
|
|
22685
|
-
1,
|
|
22686
|
-
1,
|
|
22687
|
-
1,
|
|
22688
|
-
1,
|
|
22689
|
-
1,
|
|
22690
|
-
1,
|
|
22691
|
-
1,
|
|
22692
|
-
0,
|
|
22693
|
-
1,
|
|
22694
|
-
0,
|
|
22695
|
-
1,
|
|
22696
|
-
0
|
|
22697
|
-
];
|
|
22698
|
-
function isValidStatusCode(code) {
|
|
22699
|
-
return code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3000 && code <= 4999;
|
|
22700
|
-
}
|
|
22701
|
-
function _isValidUTF8(buf) {
|
|
22702
|
-
const len = buf.length;
|
|
22703
|
-
let i = 0;
|
|
22704
|
-
while (i < len) {
|
|
22705
|
-
if ((buf[i] & 128) === 0) {
|
|
22706
|
-
i++;
|
|
22707
|
-
} else if ((buf[i] & 224) === 192) {
|
|
22708
|
-
if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
|
|
22709
|
-
return false;
|
|
22710
|
-
}
|
|
22711
|
-
i += 2;
|
|
22712
|
-
} else if ((buf[i] & 240) === 224) {
|
|
22713
|
-
if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || buf[i] === 237 && (buf[i + 1] & 224) === 160) {
|
|
22714
|
-
return false;
|
|
22715
|
-
}
|
|
22716
|
-
i += 3;
|
|
22717
|
-
} else if ((buf[i] & 248) === 240) {
|
|
22718
|
-
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 || buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
|
|
22719
|
-
return false;
|
|
22720
|
-
}
|
|
22721
|
-
i += 4;
|
|
22722
|
-
} else {
|
|
22723
|
-
return false;
|
|
22724
|
-
}
|
|
22725
|
-
}
|
|
22726
|
-
return true;
|
|
22727
|
-
}
|
|
22728
|
-
function isBlob(value) {
|
|
22729
|
-
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");
|
|
22730
|
-
}
|
|
22731
|
-
module.exports = {
|
|
22732
|
-
isBlob,
|
|
22733
|
-
isValidStatusCode,
|
|
22734
|
-
isValidUTF8: _isValidUTF8,
|
|
22735
|
-
tokenChars
|
|
22736
|
-
};
|
|
22737
|
-
if (isUtf8) {
|
|
22738
|
-
module.exports.isValidUTF8 = function(buf) {
|
|
22739
|
-
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
22740
|
-
};
|
|
22741
|
-
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
22742
|
-
try {
|
|
22743
|
-
const isValidUTF8 = (()=>{throw new Error("Cannot require module "+"utf-8-validate");})();
|
|
22744
|
-
module.exports.isValidUTF8 = function(buf) {
|
|
22745
|
-
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
22746
|
-
};
|
|
22747
|
-
} catch (e) {}
|
|
22748
|
-
}
|
|
22749
|
-
});
|
|
22750
|
-
|
|
22751
|
-
// node_modules/ws/lib/receiver.js
|
|
22752
|
-
var require_receiver = __commonJS((exports, module) => {
|
|
22753
|
-
var { Writable } = __require("stream");
|
|
22754
|
-
var PerMessageDeflate = require_permessage_deflate();
|
|
22755
|
-
var {
|
|
22756
|
-
BINARY_TYPES,
|
|
22757
|
-
EMPTY_BUFFER,
|
|
22758
|
-
kStatusCode,
|
|
22759
|
-
kWebSocket
|
|
22760
|
-
} = require_constants2();
|
|
22761
|
-
var { concat, toArrayBuffer, unmask } = require_buffer_util();
|
|
22762
|
-
var { isValidStatusCode, isValidUTF8 } = require_validation();
|
|
22763
|
-
var FastBuffer = Buffer[Symbol.species];
|
|
22764
|
-
var GET_INFO = 0;
|
|
22765
|
-
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
22766
|
-
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
22767
|
-
var GET_MASK = 3;
|
|
22768
|
-
var GET_DATA = 4;
|
|
22769
|
-
var INFLATING = 5;
|
|
22770
|
-
var DEFER_EVENT = 6;
|
|
22771
|
-
|
|
22772
|
-
class Receiver extends Writable {
|
|
22773
|
-
constructor(options = {}) {
|
|
22774
|
-
super();
|
|
22775
|
-
this._allowSynchronousEvents = options.allowSynchronousEvents !== undefined ? options.allowSynchronousEvents : true;
|
|
22776
|
-
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
22777
|
-
this._extensions = options.extensions || {};
|
|
22778
|
-
this._isServer = !!options.isServer;
|
|
22779
|
-
this._maxPayload = options.maxPayload | 0;
|
|
22780
|
-
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
22781
|
-
this[kWebSocket] = undefined;
|
|
22782
|
-
this._bufferedBytes = 0;
|
|
22783
|
-
this._buffers = [];
|
|
22784
|
-
this._compressed = false;
|
|
22785
|
-
this._payloadLength = 0;
|
|
22786
|
-
this._mask = undefined;
|
|
22787
|
-
this._fragmented = 0;
|
|
22788
|
-
this._masked = false;
|
|
22789
|
-
this._fin = false;
|
|
22790
|
-
this._opcode = 0;
|
|
22791
|
-
this._totalPayloadLength = 0;
|
|
22792
|
-
this._messageLength = 0;
|
|
22793
|
-
this._fragments = [];
|
|
22794
|
-
this._errored = false;
|
|
22795
|
-
this._loop = false;
|
|
22796
|
-
this._state = GET_INFO;
|
|
22797
|
-
}
|
|
22798
|
-
_write(chunk, encoding, cb) {
|
|
22799
|
-
if (this._opcode === 8 && this._state == GET_INFO)
|
|
22800
|
-
return cb();
|
|
22801
|
-
this._bufferedBytes += chunk.length;
|
|
22802
|
-
this._buffers.push(chunk);
|
|
22803
|
-
this.startLoop(cb);
|
|
22804
|
-
}
|
|
22805
|
-
consume(n) {
|
|
22806
|
-
this._bufferedBytes -= n;
|
|
22807
|
-
if (n === this._buffers[0].length)
|
|
22808
|
-
return this._buffers.shift();
|
|
22809
|
-
if (n < this._buffers[0].length) {
|
|
22810
|
-
const buf = this._buffers[0];
|
|
22811
|
-
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
22812
|
-
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
22813
|
-
}
|
|
22814
|
-
const dst = Buffer.allocUnsafe(n);
|
|
22815
|
-
do {
|
|
22816
|
-
const buf = this._buffers[0];
|
|
22817
|
-
const offset = dst.length - n;
|
|
22818
|
-
if (n >= buf.length) {
|
|
22819
|
-
dst.set(this._buffers.shift(), offset);
|
|
22820
|
-
} else {
|
|
22821
|
-
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
22822
|
-
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
22823
|
-
}
|
|
22824
|
-
n -= buf.length;
|
|
22825
|
-
} while (n > 0);
|
|
22826
|
-
return dst;
|
|
22827
|
-
}
|
|
22828
|
-
startLoop(cb) {
|
|
22829
|
-
this._loop = true;
|
|
22830
|
-
do {
|
|
22831
|
-
switch (this._state) {
|
|
22832
|
-
case GET_INFO:
|
|
22833
|
-
this.getInfo(cb);
|
|
22834
|
-
break;
|
|
22835
|
-
case GET_PAYLOAD_LENGTH_16:
|
|
22836
|
-
this.getPayloadLength16(cb);
|
|
22837
|
-
break;
|
|
22838
|
-
case GET_PAYLOAD_LENGTH_64:
|
|
22839
|
-
this.getPayloadLength64(cb);
|
|
22840
|
-
break;
|
|
22841
|
-
case GET_MASK:
|
|
22842
|
-
this.getMask();
|
|
22843
|
-
break;
|
|
22844
|
-
case GET_DATA:
|
|
22845
|
-
this.getData(cb);
|
|
22846
|
-
break;
|
|
22847
|
-
case INFLATING:
|
|
22848
|
-
case DEFER_EVENT:
|
|
22849
|
-
this._loop = false;
|
|
22850
|
-
return;
|
|
22851
|
-
}
|
|
22852
|
-
} while (this._loop);
|
|
22853
|
-
if (!this._errored)
|
|
22854
|
-
cb();
|
|
22855
|
-
}
|
|
22856
|
-
getInfo(cb) {
|
|
22857
|
-
if (this._bufferedBytes < 2) {
|
|
22858
|
-
this._loop = false;
|
|
22859
|
-
return;
|
|
22860
|
-
}
|
|
22861
|
-
const buf = this.consume(2);
|
|
22862
|
-
if ((buf[0] & 48) !== 0) {
|
|
22863
|
-
const error = this.createError(RangeError, "RSV2 and RSV3 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_2_3");
|
|
22864
|
-
cb(error);
|
|
22865
|
-
return;
|
|
22866
|
-
}
|
|
22867
|
-
const compressed = (buf[0] & 64) === 64;
|
|
22868
|
-
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
22869
|
-
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
22870
|
-
cb(error);
|
|
22871
|
-
return;
|
|
22872
|
-
}
|
|
22873
|
-
this._fin = (buf[0] & 128) === 128;
|
|
22874
|
-
this._opcode = buf[0] & 15;
|
|
22875
|
-
this._payloadLength = buf[1] & 127;
|
|
22876
|
-
if (this._opcode === 0) {
|
|
22877
|
-
if (compressed) {
|
|
22878
|
-
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
22879
|
-
cb(error);
|
|
22880
|
-
return;
|
|
22881
|
-
}
|
|
22882
|
-
if (!this._fragmented) {
|
|
22883
|
-
const error = this.createError(RangeError, "invalid opcode 0", true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
22884
|
-
cb(error);
|
|
22885
|
-
return;
|
|
22886
|
-
}
|
|
22887
|
-
this._opcode = this._fragmented;
|
|
22888
|
-
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
22889
|
-
if (this._fragmented) {
|
|
22890
|
-
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
22891
|
-
cb(error);
|
|
22892
|
-
return;
|
|
22893
|
-
}
|
|
22894
|
-
this._compressed = compressed;
|
|
22895
|
-
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
22896
|
-
if (!this._fin) {
|
|
22897
|
-
const error = this.createError(RangeError, "FIN must be set", true, 1002, "WS_ERR_EXPECTED_FIN");
|
|
22898
|
-
cb(error);
|
|
22899
|
-
return;
|
|
22900
|
-
}
|
|
22901
|
-
if (compressed) {
|
|
22902
|
-
const error = this.createError(RangeError, "RSV1 must be clear", true, 1002, "WS_ERR_UNEXPECTED_RSV_1");
|
|
22903
|
-
cb(error);
|
|
22904
|
-
return;
|
|
22905
|
-
}
|
|
22906
|
-
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
22907
|
-
const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");
|
|
22908
|
-
cb(error);
|
|
22909
|
-
return;
|
|
22910
|
-
}
|
|
22911
|
-
} else {
|
|
22912
|
-
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, "WS_ERR_INVALID_OPCODE");
|
|
22913
|
-
cb(error);
|
|
22914
|
-
return;
|
|
22915
|
-
}
|
|
22916
|
-
if (!this._fin && !this._fragmented)
|
|
22917
|
-
this._fragmented = this._opcode;
|
|
22918
|
-
this._masked = (buf[1] & 128) === 128;
|
|
22919
|
-
if (this._isServer) {
|
|
22920
|
-
if (!this._masked) {
|
|
22921
|
-
const error = this.createError(RangeError, "MASK must be set", true, 1002, "WS_ERR_EXPECTED_MASK");
|
|
22922
|
-
cb(error);
|
|
22923
|
-
return;
|
|
22924
|
-
}
|
|
22925
|
-
} else if (this._masked) {
|
|
22926
|
-
const error = this.createError(RangeError, "MASK must be clear", true, 1002, "WS_ERR_UNEXPECTED_MASK");
|
|
22927
|
-
cb(error);
|
|
22928
|
-
return;
|
|
22929
|
-
}
|
|
22930
|
-
if (this._payloadLength === 126)
|
|
22931
|
-
this._state = GET_PAYLOAD_LENGTH_16;
|
|
22932
|
-
else if (this._payloadLength === 127)
|
|
22933
|
-
this._state = GET_PAYLOAD_LENGTH_64;
|
|
22934
|
-
else
|
|
22935
|
-
this.haveLength(cb);
|
|
22936
|
-
}
|
|
22937
|
-
getPayloadLength16(cb) {
|
|
22938
|
-
if (this._bufferedBytes < 2) {
|
|
22939
|
-
this._loop = false;
|
|
22940
|
-
return;
|
|
22941
|
-
}
|
|
22942
|
-
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
22943
|
-
this.haveLength(cb);
|
|
22944
|
-
}
|
|
22945
|
-
getPayloadLength64(cb) {
|
|
22946
|
-
if (this._bufferedBytes < 8) {
|
|
22947
|
-
this._loop = false;
|
|
22948
|
-
return;
|
|
22949
|
-
}
|
|
22950
|
-
const buf = this.consume(8);
|
|
22951
|
-
const num = buf.readUInt32BE(0);
|
|
22952
|
-
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
22953
|
-
const error = this.createError(RangeError, "Unsupported WebSocket frame: payload length > 2^53 - 1", false, 1009, "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");
|
|
22954
|
-
cb(error);
|
|
22955
|
-
return;
|
|
22956
|
-
}
|
|
22957
|
-
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
22958
|
-
this.haveLength(cb);
|
|
22959
|
-
}
|
|
22960
|
-
haveLength(cb) {
|
|
22961
|
-
if (this._payloadLength && this._opcode < 8) {
|
|
22962
|
-
this._totalPayloadLength += this._payloadLength;
|
|
22963
|
-
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
22964
|
-
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
22965
|
-
cb(error);
|
|
22966
|
-
return;
|
|
22967
|
-
}
|
|
22968
|
-
}
|
|
22969
|
-
if (this._masked)
|
|
22970
|
-
this._state = GET_MASK;
|
|
22971
|
-
else
|
|
22972
|
-
this._state = GET_DATA;
|
|
22973
|
-
}
|
|
22974
|
-
getMask() {
|
|
22975
|
-
if (this._bufferedBytes < 4) {
|
|
22976
|
-
this._loop = false;
|
|
22977
|
-
return;
|
|
22978
|
-
}
|
|
22979
|
-
this._mask = this.consume(4);
|
|
22980
|
-
this._state = GET_DATA;
|
|
22981
|
-
}
|
|
22982
|
-
getData(cb) {
|
|
22983
|
-
let data = EMPTY_BUFFER;
|
|
22984
|
-
if (this._payloadLength) {
|
|
22985
|
-
if (this._bufferedBytes < this._payloadLength) {
|
|
22986
|
-
this._loop = false;
|
|
22987
|
-
return;
|
|
22988
|
-
}
|
|
22989
|
-
data = this.consume(this._payloadLength);
|
|
22990
|
-
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
22991
|
-
unmask(data, this._mask);
|
|
22992
|
-
}
|
|
22993
|
-
}
|
|
22994
|
-
if (this._opcode > 7) {
|
|
22995
|
-
this.controlMessage(data, cb);
|
|
22996
|
-
return;
|
|
22997
|
-
}
|
|
22998
|
-
if (this._compressed) {
|
|
22999
|
-
this._state = INFLATING;
|
|
23000
|
-
this.decompress(data, cb);
|
|
23001
|
-
return;
|
|
23002
|
-
}
|
|
23003
|
-
if (data.length) {
|
|
23004
|
-
this._messageLength = this._totalPayloadLength;
|
|
23005
|
-
this._fragments.push(data);
|
|
23006
|
-
}
|
|
23007
|
-
this.dataMessage(cb);
|
|
23008
|
-
}
|
|
23009
|
-
decompress(data, cb) {
|
|
23010
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
23011
|
-
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
23012
|
-
if (err)
|
|
23013
|
-
return cb(err);
|
|
23014
|
-
if (buf.length) {
|
|
23015
|
-
this._messageLength += buf.length;
|
|
23016
|
-
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
23017
|
-
const error = this.createError(RangeError, "Max payload size exceeded", false, 1009, "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");
|
|
23018
|
-
cb(error);
|
|
23019
|
-
return;
|
|
23020
|
-
}
|
|
23021
|
-
this._fragments.push(buf);
|
|
23022
|
-
}
|
|
23023
|
-
this.dataMessage(cb);
|
|
23024
|
-
if (this._state === GET_INFO)
|
|
23025
|
-
this.startLoop(cb);
|
|
23026
|
-
});
|
|
23027
|
-
}
|
|
23028
|
-
dataMessage(cb) {
|
|
23029
|
-
if (!this._fin) {
|
|
23030
|
-
this._state = GET_INFO;
|
|
23031
|
-
return;
|
|
23032
|
-
}
|
|
23033
|
-
const messageLength = this._messageLength;
|
|
23034
|
-
const fragments = this._fragments;
|
|
23035
|
-
this._totalPayloadLength = 0;
|
|
23036
|
-
this._messageLength = 0;
|
|
23037
|
-
this._fragmented = 0;
|
|
23038
|
-
this._fragments = [];
|
|
23039
|
-
if (this._opcode === 2) {
|
|
23040
|
-
let data;
|
|
23041
|
-
if (this._binaryType === "nodebuffer") {
|
|
23042
|
-
data = concat(fragments, messageLength);
|
|
23043
|
-
} else if (this._binaryType === "arraybuffer") {
|
|
23044
|
-
data = toArrayBuffer(concat(fragments, messageLength));
|
|
23045
|
-
} else if (this._binaryType === "blob") {
|
|
23046
|
-
data = new Blob(fragments);
|
|
23047
|
-
} else {
|
|
23048
|
-
data = fragments;
|
|
23049
|
-
}
|
|
23050
|
-
if (this._allowSynchronousEvents) {
|
|
23051
|
-
this.emit("message", data, true);
|
|
23052
|
-
this._state = GET_INFO;
|
|
23053
|
-
} else {
|
|
23054
|
-
this._state = DEFER_EVENT;
|
|
23055
|
-
setImmediate(() => {
|
|
23056
|
-
this.emit("message", data, true);
|
|
23057
|
-
this._state = GET_INFO;
|
|
23058
|
-
this.startLoop(cb);
|
|
23059
|
-
});
|
|
23060
|
-
}
|
|
23061
|
-
} else {
|
|
23062
|
-
const buf = concat(fragments, messageLength);
|
|
23063
|
-
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
23064
|
-
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
23065
|
-
cb(error);
|
|
23066
|
-
return;
|
|
23067
|
-
}
|
|
23068
|
-
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
23069
|
-
this.emit("message", buf, false);
|
|
23070
|
-
this._state = GET_INFO;
|
|
23071
|
-
} else {
|
|
23072
|
-
this._state = DEFER_EVENT;
|
|
23073
|
-
setImmediate(() => {
|
|
23074
|
-
this.emit("message", buf, false);
|
|
23075
|
-
this._state = GET_INFO;
|
|
23076
|
-
this.startLoop(cb);
|
|
23077
|
-
});
|
|
23078
|
-
}
|
|
23079
|
-
}
|
|
23080
|
-
}
|
|
23081
|
-
controlMessage(data, cb) {
|
|
23082
|
-
if (this._opcode === 8) {
|
|
23083
|
-
if (data.length === 0) {
|
|
23084
|
-
this._loop = false;
|
|
23085
|
-
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
23086
|
-
this.end();
|
|
23087
|
-
} else {
|
|
23088
|
-
const code = data.readUInt16BE(0);
|
|
23089
|
-
if (!isValidStatusCode(code)) {
|
|
23090
|
-
const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, "WS_ERR_INVALID_CLOSE_CODE");
|
|
23091
|
-
cb(error);
|
|
23092
|
-
return;
|
|
23093
|
-
}
|
|
23094
|
-
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
23095
|
-
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
23096
|
-
const error = this.createError(Error, "invalid UTF-8 sequence", true, 1007, "WS_ERR_INVALID_UTF8");
|
|
23097
|
-
cb(error);
|
|
23098
|
-
return;
|
|
23099
|
-
}
|
|
23100
|
-
this._loop = false;
|
|
23101
|
-
this.emit("conclude", code, buf);
|
|
23102
|
-
this.end();
|
|
23103
|
-
}
|
|
23104
|
-
this._state = GET_INFO;
|
|
23105
|
-
return;
|
|
23106
|
-
}
|
|
23107
|
-
if (this._allowSynchronousEvents) {
|
|
23108
|
-
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
23109
|
-
this._state = GET_INFO;
|
|
23110
|
-
} else {
|
|
23111
|
-
this._state = DEFER_EVENT;
|
|
23112
|
-
setImmediate(() => {
|
|
23113
|
-
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
23114
|
-
this._state = GET_INFO;
|
|
23115
|
-
this.startLoop(cb);
|
|
23116
|
-
});
|
|
23117
|
-
}
|
|
23118
|
-
}
|
|
23119
|
-
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
23120
|
-
this._loop = false;
|
|
23121
|
-
this._errored = true;
|
|
23122
|
-
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
23123
|
-
Error.captureStackTrace(err, this.createError);
|
|
23124
|
-
err.code = errorCode;
|
|
23125
|
-
err[kStatusCode] = statusCode;
|
|
23126
|
-
return err;
|
|
23127
|
-
}
|
|
23128
|
-
}
|
|
23129
|
-
module.exports = Receiver;
|
|
23130
|
-
});
|
|
23131
|
-
|
|
23132
|
-
// node_modules/ws/lib/sender.js
|
|
23133
|
-
var require_sender = __commonJS((exports, module) => {
|
|
23134
|
-
var { Duplex } = __require("stream");
|
|
23135
|
-
var { randomFillSync } = __require("crypto");
|
|
23136
|
-
var PerMessageDeflate = require_permessage_deflate();
|
|
23137
|
-
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants2();
|
|
23138
|
-
var { isBlob, isValidStatusCode } = require_validation();
|
|
23139
|
-
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
23140
|
-
var kByteLength = Symbol("kByteLength");
|
|
23141
|
-
var maskBuffer = Buffer.alloc(4);
|
|
23142
|
-
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
23143
|
-
var randomPool;
|
|
23144
|
-
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
23145
|
-
var DEFAULT = 0;
|
|
23146
|
-
var DEFLATING = 1;
|
|
23147
|
-
var GET_BLOB_DATA = 2;
|
|
23148
|
-
|
|
23149
|
-
class Sender {
|
|
23150
|
-
constructor(socket, extensions, generateMask) {
|
|
23151
|
-
this._extensions = extensions || {};
|
|
23152
|
-
if (generateMask) {
|
|
23153
|
-
this._generateMask = generateMask;
|
|
23154
|
-
this._maskBuffer = Buffer.alloc(4);
|
|
23155
|
-
}
|
|
23156
|
-
this._socket = socket;
|
|
23157
|
-
this._firstFragment = true;
|
|
23158
|
-
this._compress = false;
|
|
23159
|
-
this._bufferedBytes = 0;
|
|
23160
|
-
this._queue = [];
|
|
23161
|
-
this._state = DEFAULT;
|
|
23162
|
-
this.onerror = NOOP;
|
|
23163
|
-
this[kWebSocket] = undefined;
|
|
23164
|
-
}
|
|
23165
|
-
static frame(data, options) {
|
|
23166
|
-
let mask;
|
|
23167
|
-
let merge2 = false;
|
|
23168
|
-
let offset = 2;
|
|
23169
|
-
let skipMasking = false;
|
|
23170
|
-
if (options.mask) {
|
|
23171
|
-
mask = options.maskBuffer || maskBuffer;
|
|
23172
|
-
if (options.generateMask) {
|
|
23173
|
-
options.generateMask(mask);
|
|
23174
|
-
} else {
|
|
23175
|
-
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
23176
|
-
if (randomPool === undefined) {
|
|
23177
|
-
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
23178
|
-
}
|
|
23179
|
-
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
23180
|
-
randomPoolPointer = 0;
|
|
23181
|
-
}
|
|
23182
|
-
mask[0] = randomPool[randomPoolPointer++];
|
|
23183
|
-
mask[1] = randomPool[randomPoolPointer++];
|
|
23184
|
-
mask[2] = randomPool[randomPoolPointer++];
|
|
23185
|
-
mask[3] = randomPool[randomPoolPointer++];
|
|
23186
|
-
}
|
|
23187
|
-
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
23188
|
-
offset = 6;
|
|
23189
|
-
}
|
|
23190
|
-
let dataLength;
|
|
23191
|
-
if (typeof data === "string") {
|
|
23192
|
-
if ((!options.mask || skipMasking) && options[kByteLength] !== undefined) {
|
|
23193
|
-
dataLength = options[kByteLength];
|
|
23194
|
-
} else {
|
|
23195
|
-
data = Buffer.from(data);
|
|
23196
|
-
dataLength = data.length;
|
|
23197
|
-
}
|
|
23198
|
-
} else {
|
|
23199
|
-
dataLength = data.length;
|
|
23200
|
-
merge2 = options.mask && options.readOnly && !skipMasking;
|
|
23201
|
-
}
|
|
23202
|
-
let payloadLength = dataLength;
|
|
23203
|
-
if (dataLength >= 65536) {
|
|
23204
|
-
offset += 8;
|
|
23205
|
-
payloadLength = 127;
|
|
23206
|
-
} else if (dataLength > 125) {
|
|
23207
|
-
offset += 2;
|
|
23208
|
-
payloadLength = 126;
|
|
23209
|
-
}
|
|
23210
|
-
const target = Buffer.allocUnsafe(merge2 ? dataLength + offset : offset);
|
|
23211
|
-
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
23212
|
-
if (options.rsv1)
|
|
23213
|
-
target[0] |= 64;
|
|
23214
|
-
target[1] = payloadLength;
|
|
23215
|
-
if (payloadLength === 126) {
|
|
23216
|
-
target.writeUInt16BE(dataLength, 2);
|
|
23217
|
-
} else if (payloadLength === 127) {
|
|
23218
|
-
target[2] = target[3] = 0;
|
|
23219
|
-
target.writeUIntBE(dataLength, 4, 6);
|
|
23220
|
-
}
|
|
23221
|
-
if (!options.mask)
|
|
23222
|
-
return [target, data];
|
|
23223
|
-
target[1] |= 128;
|
|
23224
|
-
target[offset - 4] = mask[0];
|
|
23225
|
-
target[offset - 3] = mask[1];
|
|
23226
|
-
target[offset - 2] = mask[2];
|
|
23227
|
-
target[offset - 1] = mask[3];
|
|
23228
|
-
if (skipMasking)
|
|
23229
|
-
return [target, data];
|
|
23230
|
-
if (merge2) {
|
|
23231
|
-
applyMask(data, mask, target, offset, dataLength);
|
|
23232
|
-
return [target];
|
|
23233
|
-
}
|
|
23234
|
-
applyMask(data, mask, data, 0, dataLength);
|
|
23235
|
-
return [target, data];
|
|
23236
|
-
}
|
|
23237
|
-
close(code, data, mask, cb) {
|
|
23238
|
-
let buf;
|
|
23239
|
-
if (code === undefined) {
|
|
23240
|
-
buf = EMPTY_BUFFER;
|
|
23241
|
-
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
23242
|
-
throw new TypeError("First argument must be a valid error code number");
|
|
23243
|
-
} else if (data === undefined || !data.length) {
|
|
23244
|
-
buf = Buffer.allocUnsafe(2);
|
|
23245
|
-
buf.writeUInt16BE(code, 0);
|
|
23246
|
-
} else {
|
|
23247
|
-
const length = Buffer.byteLength(data);
|
|
23248
|
-
if (length > 123) {
|
|
23249
|
-
throw new RangeError("The message must not be greater than 123 bytes");
|
|
23250
|
-
}
|
|
23251
|
-
buf = Buffer.allocUnsafe(2 + length);
|
|
23252
|
-
buf.writeUInt16BE(code, 0);
|
|
23253
|
-
if (typeof data === "string") {
|
|
23254
|
-
buf.write(data, 2);
|
|
23255
|
-
} else {
|
|
23256
|
-
buf.set(data, 2);
|
|
23257
|
-
}
|
|
23258
|
-
}
|
|
23259
|
-
const options = {
|
|
23260
|
-
[kByteLength]: buf.length,
|
|
23261
|
-
fin: true,
|
|
23262
|
-
generateMask: this._generateMask,
|
|
23263
|
-
mask,
|
|
23264
|
-
maskBuffer: this._maskBuffer,
|
|
23265
|
-
opcode: 8,
|
|
23266
|
-
readOnly: false,
|
|
23267
|
-
rsv1: false
|
|
23268
|
-
};
|
|
23269
|
-
if (this._state !== DEFAULT) {
|
|
23270
|
-
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
23271
|
-
} else {
|
|
23272
|
-
this.sendFrame(Sender.frame(buf, options), cb);
|
|
23273
|
-
}
|
|
23274
|
-
}
|
|
23275
|
-
ping(data, mask, cb) {
|
|
23276
|
-
let byteLength;
|
|
23277
|
-
let readOnly;
|
|
23278
|
-
if (typeof data === "string") {
|
|
23279
|
-
byteLength = Buffer.byteLength(data);
|
|
23280
|
-
readOnly = false;
|
|
23281
|
-
} else if (isBlob(data)) {
|
|
23282
|
-
byteLength = data.size;
|
|
23283
|
-
readOnly = false;
|
|
23284
|
-
} else {
|
|
23285
|
-
data = toBuffer(data);
|
|
23286
|
-
byteLength = data.length;
|
|
23287
|
-
readOnly = toBuffer.readOnly;
|
|
23288
|
-
}
|
|
23289
|
-
if (byteLength > 125) {
|
|
23290
|
-
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
23291
|
-
}
|
|
23292
|
-
const options = {
|
|
23293
|
-
[kByteLength]: byteLength,
|
|
23294
|
-
fin: true,
|
|
23295
|
-
generateMask: this._generateMask,
|
|
23296
|
-
mask,
|
|
23297
|
-
maskBuffer: this._maskBuffer,
|
|
23298
|
-
opcode: 9,
|
|
23299
|
-
readOnly,
|
|
23300
|
-
rsv1: false
|
|
23301
|
-
};
|
|
23302
|
-
if (isBlob(data)) {
|
|
23303
|
-
if (this._state !== DEFAULT) {
|
|
23304
|
-
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
23305
|
-
} else {
|
|
23306
|
-
this.getBlobData(data, false, options, cb);
|
|
23307
|
-
}
|
|
23308
|
-
} else if (this._state !== DEFAULT) {
|
|
23309
|
-
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
23310
|
-
} else {
|
|
23311
|
-
this.sendFrame(Sender.frame(data, options), cb);
|
|
23312
|
-
}
|
|
23313
|
-
}
|
|
23314
|
-
pong(data, mask, cb) {
|
|
23315
|
-
let byteLength;
|
|
23316
|
-
let readOnly;
|
|
23317
|
-
if (typeof data === "string") {
|
|
23318
|
-
byteLength = Buffer.byteLength(data);
|
|
23319
|
-
readOnly = false;
|
|
23320
|
-
} else if (isBlob(data)) {
|
|
23321
|
-
byteLength = data.size;
|
|
23322
|
-
readOnly = false;
|
|
23323
|
-
} else {
|
|
23324
|
-
data = toBuffer(data);
|
|
23325
|
-
byteLength = data.length;
|
|
23326
|
-
readOnly = toBuffer.readOnly;
|
|
23327
|
-
}
|
|
23328
|
-
if (byteLength > 125) {
|
|
23329
|
-
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
23330
|
-
}
|
|
23331
|
-
const options = {
|
|
23332
|
-
[kByteLength]: byteLength,
|
|
23333
|
-
fin: true,
|
|
23334
|
-
generateMask: this._generateMask,
|
|
23335
|
-
mask,
|
|
23336
|
-
maskBuffer: this._maskBuffer,
|
|
23337
|
-
opcode: 10,
|
|
23338
|
-
readOnly,
|
|
23339
|
-
rsv1: false
|
|
23340
|
-
};
|
|
23341
|
-
if (isBlob(data)) {
|
|
23342
|
-
if (this._state !== DEFAULT) {
|
|
23343
|
-
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
23344
|
-
} else {
|
|
23345
|
-
this.getBlobData(data, false, options, cb);
|
|
23346
|
-
}
|
|
23347
|
-
} else if (this._state !== DEFAULT) {
|
|
23348
|
-
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
23349
|
-
} else {
|
|
23350
|
-
this.sendFrame(Sender.frame(data, options), cb);
|
|
23351
|
-
}
|
|
23352
|
-
}
|
|
23353
|
-
send(data, options, cb) {
|
|
23354
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
23355
|
-
let opcode = options.binary ? 2 : 1;
|
|
23356
|
-
let rsv1 = options.compress;
|
|
23357
|
-
let byteLength;
|
|
23358
|
-
let readOnly;
|
|
23359
|
-
if (typeof data === "string") {
|
|
23360
|
-
byteLength = Buffer.byteLength(data);
|
|
23361
|
-
readOnly = false;
|
|
23362
|
-
} else if (isBlob(data)) {
|
|
23363
|
-
byteLength = data.size;
|
|
23364
|
-
readOnly = false;
|
|
23365
|
-
} else {
|
|
23366
|
-
data = toBuffer(data);
|
|
23367
|
-
byteLength = data.length;
|
|
23368
|
-
readOnly = toBuffer.readOnly;
|
|
23369
|
-
}
|
|
23370
|
-
if (this._firstFragment) {
|
|
23371
|
-
this._firstFragment = false;
|
|
23372
|
-
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
23373
|
-
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
23374
|
-
}
|
|
23375
|
-
this._compress = rsv1;
|
|
23376
|
-
} else {
|
|
23377
|
-
rsv1 = false;
|
|
23378
|
-
opcode = 0;
|
|
23379
|
-
}
|
|
23380
|
-
if (options.fin)
|
|
23381
|
-
this._firstFragment = true;
|
|
23382
|
-
const opts = {
|
|
23383
|
-
[kByteLength]: byteLength,
|
|
23384
|
-
fin: options.fin,
|
|
23385
|
-
generateMask: this._generateMask,
|
|
23386
|
-
mask: options.mask,
|
|
23387
|
-
maskBuffer: this._maskBuffer,
|
|
23388
|
-
opcode,
|
|
23389
|
-
readOnly,
|
|
23390
|
-
rsv1
|
|
23391
|
-
};
|
|
23392
|
-
if (isBlob(data)) {
|
|
23393
|
-
if (this._state !== DEFAULT) {
|
|
23394
|
-
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
23395
|
-
} else {
|
|
23396
|
-
this.getBlobData(data, this._compress, opts, cb);
|
|
23397
|
-
}
|
|
23398
|
-
} else if (this._state !== DEFAULT) {
|
|
23399
|
-
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
23400
|
-
} else {
|
|
23401
|
-
this.dispatch(data, this._compress, opts, cb);
|
|
23402
|
-
}
|
|
23403
|
-
}
|
|
23404
|
-
getBlobData(blob, compress, options, cb) {
|
|
23405
|
-
this._bufferedBytes += options[kByteLength];
|
|
23406
|
-
this._state = GET_BLOB_DATA;
|
|
23407
|
-
blob.arrayBuffer().then((arrayBuffer) => {
|
|
23408
|
-
if (this._socket.destroyed) {
|
|
23409
|
-
const err = new Error("The socket was closed while the blob was being read");
|
|
23410
|
-
process.nextTick(callCallbacks, this, err, cb);
|
|
23411
|
-
return;
|
|
23412
|
-
}
|
|
23413
|
-
this._bufferedBytes -= options[kByteLength];
|
|
23414
|
-
const data = toBuffer(arrayBuffer);
|
|
23415
|
-
if (!compress) {
|
|
23416
|
-
this._state = DEFAULT;
|
|
23417
|
-
this.sendFrame(Sender.frame(data, options), cb);
|
|
23418
|
-
this.dequeue();
|
|
23419
|
-
} else {
|
|
23420
|
-
this.dispatch(data, compress, options, cb);
|
|
23421
|
-
}
|
|
23422
|
-
}).catch((err) => {
|
|
23423
|
-
process.nextTick(onError, this, err, cb);
|
|
23424
|
-
});
|
|
23425
|
-
}
|
|
23426
|
-
dispatch(data, compress, options, cb) {
|
|
23427
|
-
if (!compress) {
|
|
23428
|
-
this.sendFrame(Sender.frame(data, options), cb);
|
|
23429
|
-
return;
|
|
23430
|
-
}
|
|
23431
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
23432
|
-
this._bufferedBytes += options[kByteLength];
|
|
23433
|
-
this._state = DEFLATING;
|
|
23434
|
-
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
23435
|
-
if (this._socket.destroyed) {
|
|
23436
|
-
const err = new Error("The socket was closed while data was being compressed");
|
|
23437
|
-
callCallbacks(this, err, cb);
|
|
23438
|
-
return;
|
|
23439
|
-
}
|
|
23440
|
-
this._bufferedBytes -= options[kByteLength];
|
|
23441
|
-
this._state = DEFAULT;
|
|
23442
|
-
options.readOnly = false;
|
|
23443
|
-
this.sendFrame(Sender.frame(buf, options), cb);
|
|
23444
|
-
this.dequeue();
|
|
23445
|
-
});
|
|
23446
|
-
}
|
|
23447
|
-
dequeue() {
|
|
23448
|
-
while (this._state === DEFAULT && this._queue.length) {
|
|
23449
|
-
const params = this._queue.shift();
|
|
23450
|
-
this._bufferedBytes -= params[3][kByteLength];
|
|
23451
|
-
Reflect.apply(params[0], this, params.slice(1));
|
|
23452
|
-
}
|
|
23453
|
-
}
|
|
23454
|
-
enqueue(params) {
|
|
23455
|
-
this._bufferedBytes += params[3][kByteLength];
|
|
23456
|
-
this._queue.push(params);
|
|
23457
|
-
}
|
|
23458
|
-
sendFrame(list, cb) {
|
|
23459
|
-
if (list.length === 2) {
|
|
23460
|
-
this._socket.cork();
|
|
23461
|
-
this._socket.write(list[0]);
|
|
23462
|
-
this._socket.write(list[1], cb);
|
|
23463
|
-
this._socket.uncork();
|
|
23464
|
-
} else {
|
|
23465
|
-
this._socket.write(list[0], cb);
|
|
23466
|
-
}
|
|
23467
|
-
}
|
|
23468
|
-
}
|
|
23469
|
-
module.exports = Sender;
|
|
23470
|
-
function callCallbacks(sender, err, cb) {
|
|
23471
|
-
if (typeof cb === "function")
|
|
23472
|
-
cb(err);
|
|
23473
|
-
for (let i = 0;i < sender._queue.length; i++) {
|
|
23474
|
-
const params = sender._queue[i];
|
|
23475
|
-
const callback = params[params.length - 1];
|
|
23476
|
-
if (typeof callback === "function")
|
|
23477
|
-
callback(err);
|
|
23478
|
-
}
|
|
23479
|
-
}
|
|
23480
|
-
function onError(sender, err, cb) {
|
|
23481
|
-
callCallbacks(sender, err, cb);
|
|
23482
|
-
sender.onerror(err);
|
|
23483
|
-
}
|
|
23484
|
-
});
|
|
23485
|
-
|
|
23486
|
-
// node_modules/ws/lib/event-target.js
|
|
23487
|
-
var require_event_target = __commonJS((exports, module) => {
|
|
23488
|
-
var { kForOnEventAttribute, kListener } = require_constants2();
|
|
23489
|
-
var kCode = Symbol("kCode");
|
|
23490
|
-
var kData = Symbol("kData");
|
|
23491
|
-
var kError = Symbol("kError");
|
|
23492
|
-
var kMessage = Symbol("kMessage");
|
|
23493
|
-
var kReason = Symbol("kReason");
|
|
23494
|
-
var kTarget = Symbol("kTarget");
|
|
23495
|
-
var kType = Symbol("kType");
|
|
23496
|
-
var kWasClean = Symbol("kWasClean");
|
|
23497
|
-
|
|
23498
|
-
class Event {
|
|
23499
|
-
constructor(type2) {
|
|
23500
|
-
this[kTarget] = null;
|
|
23501
|
-
this[kType] = type2;
|
|
23502
|
-
}
|
|
23503
|
-
get target() {
|
|
23504
|
-
return this[kTarget];
|
|
23505
|
-
}
|
|
23506
|
-
get type() {
|
|
23507
|
-
return this[kType];
|
|
23508
|
-
}
|
|
23509
|
-
}
|
|
23510
|
-
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
23511
|
-
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
23512
|
-
|
|
23513
|
-
class CloseEvent extends Event {
|
|
23514
|
-
constructor(type2, options = {}) {
|
|
23515
|
-
super(type2);
|
|
23516
|
-
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
23517
|
-
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
23518
|
-
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
23519
|
-
}
|
|
23520
|
-
get code() {
|
|
23521
|
-
return this[kCode];
|
|
23522
|
-
}
|
|
23523
|
-
get reason() {
|
|
23524
|
-
return this[kReason];
|
|
23525
|
-
}
|
|
23526
|
-
get wasClean() {
|
|
23527
|
-
return this[kWasClean];
|
|
23528
|
-
}
|
|
23529
|
-
}
|
|
23530
|
-
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
23531
|
-
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
23532
|
-
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
23533
|
-
|
|
23534
|
-
class ErrorEvent extends Event {
|
|
23535
|
-
constructor(type2, options = {}) {
|
|
23536
|
-
super(type2);
|
|
23537
|
-
this[kError] = options.error === undefined ? null : options.error;
|
|
23538
|
-
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
23539
|
-
}
|
|
23540
|
-
get error() {
|
|
23541
|
-
return this[kError];
|
|
23542
|
-
}
|
|
23543
|
-
get message() {
|
|
23544
|
-
return this[kMessage];
|
|
23545
|
-
}
|
|
23546
|
-
}
|
|
23547
|
-
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
23548
|
-
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
23549
|
-
|
|
23550
|
-
class MessageEvent extends Event {
|
|
23551
|
-
constructor(type2, options = {}) {
|
|
23552
|
-
super(type2);
|
|
23553
|
-
this[kData] = options.data === undefined ? null : options.data;
|
|
23554
|
-
}
|
|
23555
|
-
get data() {
|
|
23556
|
-
return this[kData];
|
|
23557
|
-
}
|
|
23558
|
-
}
|
|
23559
|
-
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
23560
|
-
var EventTarget = {
|
|
23561
|
-
addEventListener(type2, handler, options = {}) {
|
|
23562
|
-
for (const listener of this.listeners(type2)) {
|
|
23563
|
-
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
23564
|
-
return;
|
|
23565
|
-
}
|
|
23566
|
-
}
|
|
23567
|
-
let wrapper;
|
|
23568
|
-
if (type2 === "message") {
|
|
23569
|
-
wrapper = function onMessage(data, isBinary) {
|
|
23570
|
-
const event = new MessageEvent("message", {
|
|
23571
|
-
data: isBinary ? data : data.toString()
|
|
23572
|
-
});
|
|
23573
|
-
event[kTarget] = this;
|
|
23574
|
-
callListener(handler, this, event);
|
|
23575
|
-
};
|
|
23576
|
-
} else if (type2 === "close") {
|
|
23577
|
-
wrapper = function onClose(code, message) {
|
|
23578
|
-
const event = new CloseEvent("close", {
|
|
23579
|
-
code,
|
|
23580
|
-
reason: message.toString(),
|
|
23581
|
-
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
23582
|
-
});
|
|
23583
|
-
event[kTarget] = this;
|
|
23584
|
-
callListener(handler, this, event);
|
|
23585
|
-
};
|
|
23586
|
-
} else if (type2 === "error") {
|
|
23587
|
-
wrapper = function onError(error) {
|
|
23588
|
-
const event = new ErrorEvent("error", {
|
|
23589
|
-
error,
|
|
23590
|
-
message: error.message
|
|
23591
|
-
});
|
|
23592
|
-
event[kTarget] = this;
|
|
23593
|
-
callListener(handler, this, event);
|
|
23594
|
-
};
|
|
23595
|
-
} else if (type2 === "open") {
|
|
23596
|
-
wrapper = function onOpen() {
|
|
23597
|
-
const event = new Event("open");
|
|
23598
|
-
event[kTarget] = this;
|
|
23599
|
-
callListener(handler, this, event);
|
|
23600
|
-
};
|
|
23601
|
-
} else {
|
|
23602
|
-
return;
|
|
23603
|
-
}
|
|
23604
|
-
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
23605
|
-
wrapper[kListener] = handler;
|
|
23606
|
-
if (options.once) {
|
|
23607
|
-
this.once(type2, wrapper);
|
|
23608
|
-
} else {
|
|
23609
|
-
this.on(type2, wrapper);
|
|
23610
|
-
}
|
|
23611
|
-
},
|
|
23612
|
-
removeEventListener(type2, handler) {
|
|
23613
|
-
for (const listener of this.listeners(type2)) {
|
|
23614
|
-
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
23615
|
-
this.removeListener(type2, listener);
|
|
23616
|
-
break;
|
|
23617
|
-
}
|
|
23618
|
-
}
|
|
23619
|
-
}
|
|
23620
|
-
};
|
|
23621
|
-
module.exports = {
|
|
23622
|
-
CloseEvent,
|
|
23623
|
-
ErrorEvent,
|
|
23624
|
-
Event,
|
|
23625
|
-
EventTarget,
|
|
23626
|
-
MessageEvent
|
|
23627
|
-
};
|
|
23628
|
-
function callListener(listener, thisArg, event) {
|
|
23629
|
-
if (typeof listener === "object" && listener.handleEvent) {
|
|
23630
|
-
listener.handleEvent.call(listener, event);
|
|
23631
|
-
} else {
|
|
23632
|
-
listener.call(thisArg, event);
|
|
23633
|
-
}
|
|
23634
|
-
}
|
|
23635
|
-
});
|
|
23636
|
-
|
|
23637
|
-
// node_modules/ws/lib/extension.js
|
|
23638
|
-
var require_extension = __commonJS((exports, module) => {
|
|
23639
|
-
var { tokenChars } = require_validation();
|
|
23640
|
-
function push(dest, name, elem) {
|
|
23641
|
-
if (dest[name] === undefined)
|
|
23642
|
-
dest[name] = [elem];
|
|
23643
|
-
else
|
|
23644
|
-
dest[name].push(elem);
|
|
23645
|
-
}
|
|
23646
|
-
function parse(header) {
|
|
23647
|
-
const offers = Object.create(null);
|
|
23648
|
-
let params = Object.create(null);
|
|
23649
|
-
let mustUnescape = false;
|
|
23650
|
-
let isEscaping = false;
|
|
23651
|
-
let inQuotes = false;
|
|
23652
|
-
let extensionName;
|
|
23653
|
-
let paramName;
|
|
23654
|
-
let start = -1;
|
|
23655
|
-
let code = -1;
|
|
23656
|
-
let end = -1;
|
|
23657
|
-
let i = 0;
|
|
23658
|
-
for (;i < header.length; i++) {
|
|
23659
|
-
code = header.charCodeAt(i);
|
|
23660
|
-
if (extensionName === undefined) {
|
|
23661
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
23662
|
-
if (start === -1)
|
|
23663
|
-
start = i;
|
|
23664
|
-
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
23665
|
-
if (end === -1 && start !== -1)
|
|
23666
|
-
end = i;
|
|
23667
|
-
} else if (code === 59 || code === 44) {
|
|
23668
|
-
if (start === -1) {
|
|
23669
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23670
|
-
}
|
|
23671
|
-
if (end === -1)
|
|
23672
|
-
end = i;
|
|
23673
|
-
const name = header.slice(start, end);
|
|
23674
|
-
if (code === 44) {
|
|
23675
|
-
push(offers, name, params);
|
|
23676
|
-
params = Object.create(null);
|
|
23677
|
-
} else {
|
|
23678
|
-
extensionName = name;
|
|
23679
|
-
}
|
|
23680
|
-
start = end = -1;
|
|
23681
|
-
} else {
|
|
23682
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23683
|
-
}
|
|
23684
|
-
} else if (paramName === undefined) {
|
|
23685
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
23686
|
-
if (start === -1)
|
|
23687
|
-
start = i;
|
|
23688
|
-
} else if (code === 32 || code === 9) {
|
|
23689
|
-
if (end === -1 && start !== -1)
|
|
23690
|
-
end = i;
|
|
23691
|
-
} else if (code === 59 || code === 44) {
|
|
23692
|
-
if (start === -1) {
|
|
23693
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23694
|
-
}
|
|
23695
|
-
if (end === -1)
|
|
23696
|
-
end = i;
|
|
23697
|
-
push(params, header.slice(start, end), true);
|
|
23698
|
-
if (code === 44) {
|
|
23699
|
-
push(offers, extensionName, params);
|
|
23700
|
-
params = Object.create(null);
|
|
23701
|
-
extensionName = undefined;
|
|
23702
|
-
}
|
|
23703
|
-
start = end = -1;
|
|
23704
|
-
} else if (code === 61 && start !== -1 && end === -1) {
|
|
23705
|
-
paramName = header.slice(start, i);
|
|
23706
|
-
start = end = -1;
|
|
23707
|
-
} else {
|
|
23708
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23709
|
-
}
|
|
23710
|
-
} else {
|
|
23711
|
-
if (isEscaping) {
|
|
23712
|
-
if (tokenChars[code] !== 1) {
|
|
23713
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23714
|
-
}
|
|
23715
|
-
if (start === -1)
|
|
23716
|
-
start = i;
|
|
23717
|
-
else if (!mustUnescape)
|
|
23718
|
-
mustUnescape = true;
|
|
23719
|
-
isEscaping = false;
|
|
23720
|
-
} else if (inQuotes) {
|
|
23721
|
-
if (tokenChars[code] === 1) {
|
|
23722
|
-
if (start === -1)
|
|
23723
|
-
start = i;
|
|
23724
|
-
} else if (code === 34 && start !== -1) {
|
|
23725
|
-
inQuotes = false;
|
|
23726
|
-
end = i;
|
|
23727
|
-
} else if (code === 92) {
|
|
23728
|
-
isEscaping = true;
|
|
23729
|
-
} else {
|
|
23730
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23731
|
-
}
|
|
23732
|
-
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
23733
|
-
inQuotes = true;
|
|
23734
|
-
} else if (end === -1 && tokenChars[code] === 1) {
|
|
23735
|
-
if (start === -1)
|
|
23736
|
-
start = i;
|
|
23737
|
-
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
23738
|
-
if (end === -1)
|
|
23739
|
-
end = i;
|
|
23740
|
-
} else if (code === 59 || code === 44) {
|
|
23741
|
-
if (start === -1) {
|
|
23742
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23743
|
-
}
|
|
23744
|
-
if (end === -1)
|
|
23745
|
-
end = i;
|
|
23746
|
-
let value = header.slice(start, end);
|
|
23747
|
-
if (mustUnescape) {
|
|
23748
|
-
value = value.replace(/\\/g, "");
|
|
23749
|
-
mustUnescape = false;
|
|
23750
|
-
}
|
|
23751
|
-
push(params, paramName, value);
|
|
23752
|
-
if (code === 44) {
|
|
23753
|
-
push(offers, extensionName, params);
|
|
23754
|
-
params = Object.create(null);
|
|
23755
|
-
extensionName = undefined;
|
|
23756
|
-
}
|
|
23757
|
-
paramName = undefined;
|
|
23758
|
-
start = end = -1;
|
|
23759
|
-
} else {
|
|
23760
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
23761
|
-
}
|
|
23762
|
-
}
|
|
23763
|
-
}
|
|
23764
|
-
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
23765
|
-
throw new SyntaxError("Unexpected end of input");
|
|
23766
|
-
}
|
|
23767
|
-
if (end === -1)
|
|
23768
|
-
end = i;
|
|
23769
|
-
const token = header.slice(start, end);
|
|
23770
|
-
if (extensionName === undefined) {
|
|
23771
|
-
push(offers, token, params);
|
|
23772
|
-
} else {
|
|
23773
|
-
if (paramName === undefined) {
|
|
23774
|
-
push(params, token, true);
|
|
23775
|
-
} else if (mustUnescape) {
|
|
23776
|
-
push(params, paramName, token.replace(/\\/g, ""));
|
|
23777
|
-
} else {
|
|
23778
|
-
push(params, paramName, token);
|
|
23779
|
-
}
|
|
23780
|
-
push(offers, extensionName, params);
|
|
23781
|
-
}
|
|
23782
|
-
return offers;
|
|
23783
|
-
}
|
|
23784
|
-
function format(extensions) {
|
|
23785
|
-
return Object.keys(extensions).map((extension) => {
|
|
23786
|
-
let configurations = extensions[extension];
|
|
23787
|
-
if (!Array.isArray(configurations))
|
|
23788
|
-
configurations = [configurations];
|
|
23789
|
-
return configurations.map((params) => {
|
|
23790
|
-
return [extension].concat(Object.keys(params).map((k) => {
|
|
23791
|
-
let values2 = params[k];
|
|
23792
|
-
if (!Array.isArray(values2))
|
|
23793
|
-
values2 = [values2];
|
|
23794
|
-
return values2.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
23795
|
-
})).join("; ");
|
|
23796
|
-
}).join(", ");
|
|
23797
|
-
}).join(", ");
|
|
23798
|
-
}
|
|
23799
|
-
module.exports = { format, parse };
|
|
23800
|
-
});
|
|
23801
|
-
|
|
23802
|
-
// node_modules/ws/lib/websocket.js
|
|
23803
|
-
var require_websocket = __commonJS((exports, module) => {
|
|
23804
|
-
var EventEmitter = __require("events");
|
|
23805
|
-
var https = __require("https");
|
|
23806
|
-
var http = __require("http");
|
|
23807
|
-
var net = __require("net");
|
|
23808
|
-
var tls = __require("tls");
|
|
23809
|
-
var { randomBytes: randomBytes2, createHash } = __require("crypto");
|
|
23810
|
-
var { Duplex, Readable } = __require("stream");
|
|
23811
|
-
var { URL: URL2 } = __require("url");
|
|
23812
|
-
var PerMessageDeflate = require_permessage_deflate();
|
|
23813
|
-
var Receiver = require_receiver();
|
|
23814
|
-
var Sender = require_sender();
|
|
23815
|
-
var { isBlob } = require_validation();
|
|
23816
|
-
var {
|
|
23817
|
-
BINARY_TYPES,
|
|
23818
|
-
EMPTY_BUFFER,
|
|
23819
|
-
GUID,
|
|
23820
|
-
kForOnEventAttribute,
|
|
23821
|
-
kListener,
|
|
23822
|
-
kStatusCode,
|
|
23823
|
-
kWebSocket,
|
|
23824
|
-
NOOP
|
|
23825
|
-
} = require_constants2();
|
|
23826
|
-
var {
|
|
23827
|
-
EventTarget: { addEventListener, removeEventListener }
|
|
23828
|
-
} = require_event_target();
|
|
23829
|
-
var { format, parse } = require_extension();
|
|
23830
|
-
var { toBuffer } = require_buffer_util();
|
|
23831
|
-
var closeTimeout = 30 * 1000;
|
|
23832
|
-
var kAborted = Symbol("kAborted");
|
|
23833
|
-
var protocolVersions = [8, 13];
|
|
23834
|
-
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
23835
|
-
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
23836
|
-
|
|
23837
|
-
class WebSocket extends EventEmitter {
|
|
23838
|
-
constructor(address, protocols, options) {
|
|
23839
|
-
super();
|
|
23840
|
-
this._binaryType = BINARY_TYPES[0];
|
|
23841
|
-
this._closeCode = 1006;
|
|
23842
|
-
this._closeFrameReceived = false;
|
|
23843
|
-
this._closeFrameSent = false;
|
|
23844
|
-
this._closeMessage = EMPTY_BUFFER;
|
|
23845
|
-
this._closeTimer = null;
|
|
23846
|
-
this._errorEmitted = false;
|
|
23847
|
-
this._extensions = {};
|
|
23848
|
-
this._paused = false;
|
|
23849
|
-
this._protocol = "";
|
|
23850
|
-
this._readyState = WebSocket.CONNECTING;
|
|
23851
|
-
this._receiver = null;
|
|
23852
|
-
this._sender = null;
|
|
23853
|
-
this._socket = null;
|
|
23854
|
-
if (address !== null) {
|
|
23855
|
-
this._bufferedAmount = 0;
|
|
23856
|
-
this._isServer = false;
|
|
23857
|
-
this._redirects = 0;
|
|
23858
|
-
if (protocols === undefined) {
|
|
23859
|
-
protocols = [];
|
|
23860
|
-
} else if (!Array.isArray(protocols)) {
|
|
23861
|
-
if (typeof protocols === "object" && protocols !== null) {
|
|
23862
|
-
options = protocols;
|
|
23863
|
-
protocols = [];
|
|
23864
|
-
} else {
|
|
23865
|
-
protocols = [protocols];
|
|
23866
|
-
}
|
|
23867
|
-
}
|
|
23868
|
-
initAsClient(this, address, protocols, options);
|
|
23869
|
-
} else {
|
|
23870
|
-
this._autoPong = options.autoPong;
|
|
23871
|
-
this._isServer = true;
|
|
23872
|
-
}
|
|
23873
|
-
}
|
|
23874
|
-
get binaryType() {
|
|
23875
|
-
return this._binaryType;
|
|
23876
|
-
}
|
|
23877
|
-
set binaryType(type2) {
|
|
23878
|
-
if (!BINARY_TYPES.includes(type2))
|
|
23879
|
-
return;
|
|
23880
|
-
this._binaryType = type2;
|
|
23881
|
-
if (this._receiver)
|
|
23882
|
-
this._receiver._binaryType = type2;
|
|
23883
|
-
}
|
|
23884
|
-
get bufferedAmount() {
|
|
23885
|
-
if (!this._socket)
|
|
23886
|
-
return this._bufferedAmount;
|
|
23887
|
-
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
23888
|
-
}
|
|
23889
|
-
get extensions() {
|
|
23890
|
-
return Object.keys(this._extensions).join();
|
|
23891
|
-
}
|
|
23892
|
-
get isPaused() {
|
|
23893
|
-
return this._paused;
|
|
23894
|
-
}
|
|
23895
|
-
get onclose() {
|
|
23896
|
-
return null;
|
|
23897
|
-
}
|
|
23898
|
-
get onerror() {
|
|
23899
|
-
return null;
|
|
23900
|
-
}
|
|
23901
|
-
get onopen() {
|
|
23902
|
-
return null;
|
|
23903
|
-
}
|
|
23904
|
-
get onmessage() {
|
|
23905
|
-
return null;
|
|
23906
|
-
}
|
|
23907
|
-
get protocol() {
|
|
23908
|
-
return this._protocol;
|
|
23909
|
-
}
|
|
23910
|
-
get readyState() {
|
|
23911
|
-
return this._readyState;
|
|
23912
|
-
}
|
|
23913
|
-
get url() {
|
|
23914
|
-
return this._url;
|
|
23915
|
-
}
|
|
23916
|
-
setSocket(socket, head, options) {
|
|
23917
|
-
const receiver = new Receiver({
|
|
23918
|
-
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
23919
|
-
binaryType: this.binaryType,
|
|
23920
|
-
extensions: this._extensions,
|
|
23921
|
-
isServer: this._isServer,
|
|
23922
|
-
maxPayload: options.maxPayload,
|
|
23923
|
-
skipUTF8Validation: options.skipUTF8Validation
|
|
23924
|
-
});
|
|
23925
|
-
const sender = new Sender(socket, this._extensions, options.generateMask);
|
|
23926
|
-
this._receiver = receiver;
|
|
23927
|
-
this._sender = sender;
|
|
23928
|
-
this._socket = socket;
|
|
23929
|
-
receiver[kWebSocket] = this;
|
|
23930
|
-
sender[kWebSocket] = this;
|
|
23931
|
-
socket[kWebSocket] = this;
|
|
23932
|
-
receiver.on("conclude", receiverOnConclude);
|
|
23933
|
-
receiver.on("drain", receiverOnDrain);
|
|
23934
|
-
receiver.on("error", receiverOnError);
|
|
23935
|
-
receiver.on("message", receiverOnMessage);
|
|
23936
|
-
receiver.on("ping", receiverOnPing);
|
|
23937
|
-
receiver.on("pong", receiverOnPong);
|
|
23938
|
-
sender.onerror = senderOnError;
|
|
23939
|
-
if (socket.setTimeout)
|
|
23940
|
-
socket.setTimeout(0);
|
|
23941
|
-
if (socket.setNoDelay)
|
|
23942
|
-
socket.setNoDelay();
|
|
23943
|
-
if (head.length > 0)
|
|
23944
|
-
socket.unshift(head);
|
|
23945
|
-
socket.on("close", socketOnClose);
|
|
23946
|
-
socket.on("data", socketOnData);
|
|
23947
|
-
socket.on("end", socketOnEnd);
|
|
23948
|
-
socket.on("error", socketOnError);
|
|
23949
|
-
this._readyState = WebSocket.OPEN;
|
|
23950
|
-
this.emit("open");
|
|
23951
|
-
}
|
|
23952
|
-
emitClose() {
|
|
23953
|
-
if (!this._socket) {
|
|
23954
|
-
this._readyState = WebSocket.CLOSED;
|
|
23955
|
-
this.emit("close", this._closeCode, this._closeMessage);
|
|
23956
|
-
return;
|
|
23957
|
-
}
|
|
23958
|
-
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
23959
|
-
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
23960
|
-
}
|
|
23961
|
-
this._receiver.removeAllListeners();
|
|
23962
|
-
this._readyState = WebSocket.CLOSED;
|
|
23963
|
-
this.emit("close", this._closeCode, this._closeMessage);
|
|
23964
|
-
}
|
|
23965
|
-
close(code, data) {
|
|
23966
|
-
if (this.readyState === WebSocket.CLOSED)
|
|
23967
|
-
return;
|
|
23968
|
-
if (this.readyState === WebSocket.CONNECTING) {
|
|
23969
|
-
const msg = "WebSocket was closed before the connection was established";
|
|
23970
|
-
abortHandshake(this, this._req, msg);
|
|
23971
|
-
return;
|
|
23972
|
-
}
|
|
23973
|
-
if (this.readyState === WebSocket.CLOSING) {
|
|
23974
|
-
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
23975
|
-
this._socket.end();
|
|
23976
|
-
}
|
|
23977
|
-
return;
|
|
23978
|
-
}
|
|
23979
|
-
this._readyState = WebSocket.CLOSING;
|
|
23980
|
-
this._sender.close(code, data, !this._isServer, (err) => {
|
|
23981
|
-
if (err)
|
|
23982
|
-
return;
|
|
23983
|
-
this._closeFrameSent = true;
|
|
23984
|
-
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
23985
|
-
this._socket.end();
|
|
23986
|
-
}
|
|
23987
|
-
});
|
|
23988
|
-
setCloseTimer(this);
|
|
23989
|
-
}
|
|
23990
|
-
pause() {
|
|
23991
|
-
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
23992
|
-
return;
|
|
23993
|
-
}
|
|
23994
|
-
this._paused = true;
|
|
23995
|
-
this._socket.pause();
|
|
23996
|
-
}
|
|
23997
|
-
ping(data, mask, cb) {
|
|
23998
|
-
if (this.readyState === WebSocket.CONNECTING) {
|
|
23999
|
-
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
24000
|
-
}
|
|
24001
|
-
if (typeof data === "function") {
|
|
24002
|
-
cb = data;
|
|
24003
|
-
data = mask = undefined;
|
|
24004
|
-
} else if (typeof mask === "function") {
|
|
24005
|
-
cb = mask;
|
|
24006
|
-
mask = undefined;
|
|
24007
|
-
}
|
|
24008
|
-
if (typeof data === "number")
|
|
24009
|
-
data = data.toString();
|
|
24010
|
-
if (this.readyState !== WebSocket.OPEN) {
|
|
24011
|
-
sendAfterClose(this, data, cb);
|
|
24012
|
-
return;
|
|
24013
|
-
}
|
|
24014
|
-
if (mask === undefined)
|
|
24015
|
-
mask = !this._isServer;
|
|
24016
|
-
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
24017
|
-
}
|
|
24018
|
-
pong(data, mask, cb) {
|
|
24019
|
-
if (this.readyState === WebSocket.CONNECTING) {
|
|
24020
|
-
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
24021
|
-
}
|
|
24022
|
-
if (typeof data === "function") {
|
|
24023
|
-
cb = data;
|
|
24024
|
-
data = mask = undefined;
|
|
24025
|
-
} else if (typeof mask === "function") {
|
|
24026
|
-
cb = mask;
|
|
24027
|
-
mask = undefined;
|
|
24028
|
-
}
|
|
24029
|
-
if (typeof data === "number")
|
|
24030
|
-
data = data.toString();
|
|
24031
|
-
if (this.readyState !== WebSocket.OPEN) {
|
|
24032
|
-
sendAfterClose(this, data, cb);
|
|
24033
|
-
return;
|
|
24034
|
-
}
|
|
24035
|
-
if (mask === undefined)
|
|
24036
|
-
mask = !this._isServer;
|
|
24037
|
-
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
24038
|
-
}
|
|
24039
|
-
resume() {
|
|
24040
|
-
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) {
|
|
24041
|
-
return;
|
|
24042
|
-
}
|
|
24043
|
-
this._paused = false;
|
|
24044
|
-
if (!this._receiver._writableState.needDrain)
|
|
24045
|
-
this._socket.resume();
|
|
24046
|
-
}
|
|
24047
|
-
send(data, options, cb) {
|
|
24048
|
-
if (this.readyState === WebSocket.CONNECTING) {
|
|
24049
|
-
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
24050
|
-
}
|
|
24051
|
-
if (typeof options === "function") {
|
|
24052
|
-
cb = options;
|
|
24053
|
-
options = {};
|
|
24054
|
-
}
|
|
24055
|
-
if (typeof data === "number")
|
|
24056
|
-
data = data.toString();
|
|
24057
|
-
if (this.readyState !== WebSocket.OPEN) {
|
|
24058
|
-
sendAfterClose(this, data, cb);
|
|
24059
|
-
return;
|
|
24060
|
-
}
|
|
24061
|
-
const opts = {
|
|
24062
|
-
binary: typeof data !== "string",
|
|
24063
|
-
mask: !this._isServer,
|
|
24064
|
-
compress: true,
|
|
24065
|
-
fin: true,
|
|
24066
|
-
...options
|
|
24067
|
-
};
|
|
24068
|
-
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
24069
|
-
opts.compress = false;
|
|
24070
|
-
}
|
|
24071
|
-
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
24072
|
-
}
|
|
24073
|
-
terminate() {
|
|
24074
|
-
if (this.readyState === WebSocket.CLOSED)
|
|
24075
|
-
return;
|
|
24076
|
-
if (this.readyState === WebSocket.CONNECTING) {
|
|
24077
|
-
const msg = "WebSocket was closed before the connection was established";
|
|
24078
|
-
abortHandshake(this, this._req, msg);
|
|
24079
|
-
return;
|
|
24080
|
-
}
|
|
24081
|
-
if (this._socket) {
|
|
24082
|
-
this._readyState = WebSocket.CLOSING;
|
|
24083
|
-
this._socket.destroy();
|
|
24084
|
-
}
|
|
24085
|
-
}
|
|
24086
|
-
}
|
|
24087
|
-
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
24088
|
-
enumerable: true,
|
|
24089
|
-
value: readyStates.indexOf("CONNECTING")
|
|
24090
|
-
});
|
|
24091
|
-
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
24092
|
-
enumerable: true,
|
|
24093
|
-
value: readyStates.indexOf("CONNECTING")
|
|
24094
|
-
});
|
|
24095
|
-
Object.defineProperty(WebSocket, "OPEN", {
|
|
24096
|
-
enumerable: true,
|
|
24097
|
-
value: readyStates.indexOf("OPEN")
|
|
24098
|
-
});
|
|
24099
|
-
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
24100
|
-
enumerable: true,
|
|
24101
|
-
value: readyStates.indexOf("OPEN")
|
|
24102
|
-
});
|
|
24103
|
-
Object.defineProperty(WebSocket, "CLOSING", {
|
|
24104
|
-
enumerable: true,
|
|
24105
|
-
value: readyStates.indexOf("CLOSING")
|
|
24106
|
-
});
|
|
24107
|
-
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
24108
|
-
enumerable: true,
|
|
24109
|
-
value: readyStates.indexOf("CLOSING")
|
|
24110
|
-
});
|
|
24111
|
-
Object.defineProperty(WebSocket, "CLOSED", {
|
|
24112
|
-
enumerable: true,
|
|
24113
|
-
value: readyStates.indexOf("CLOSED")
|
|
24114
|
-
});
|
|
24115
|
-
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
24116
|
-
enumerable: true,
|
|
24117
|
-
value: readyStates.indexOf("CLOSED")
|
|
24118
|
-
});
|
|
24119
|
-
[
|
|
24120
|
-
"binaryType",
|
|
24121
|
-
"bufferedAmount",
|
|
24122
|
-
"extensions",
|
|
24123
|
-
"isPaused",
|
|
24124
|
-
"protocol",
|
|
24125
|
-
"readyState",
|
|
24126
|
-
"url"
|
|
24127
|
-
].forEach((property) => {
|
|
24128
|
-
Object.defineProperty(WebSocket.prototype, property, { enumerable: true });
|
|
24129
|
-
});
|
|
24130
|
-
["open", "error", "close", "message"].forEach((method) => {
|
|
24131
|
-
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
24132
|
-
enumerable: true,
|
|
24133
|
-
get() {
|
|
24134
|
-
for (const listener of this.listeners(method)) {
|
|
24135
|
-
if (listener[kForOnEventAttribute])
|
|
24136
|
-
return listener[kListener];
|
|
24137
|
-
}
|
|
24138
|
-
return null;
|
|
24139
|
-
},
|
|
24140
|
-
set(handler) {
|
|
24141
|
-
for (const listener of this.listeners(method)) {
|
|
24142
|
-
if (listener[kForOnEventAttribute]) {
|
|
24143
|
-
this.removeListener(method, listener);
|
|
24144
|
-
break;
|
|
24145
|
-
}
|
|
24146
|
-
}
|
|
24147
|
-
if (typeof handler !== "function")
|
|
24148
|
-
return;
|
|
24149
|
-
this.addEventListener(method, handler, {
|
|
24150
|
-
[kForOnEventAttribute]: true
|
|
24151
|
-
});
|
|
24152
|
-
}
|
|
24153
|
-
});
|
|
24154
|
-
});
|
|
24155
|
-
WebSocket.prototype.addEventListener = addEventListener;
|
|
24156
|
-
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
24157
|
-
module.exports = WebSocket;
|
|
24158
|
-
function initAsClient(websocket, address, protocols, options) {
|
|
24159
|
-
const opts = {
|
|
24160
|
-
allowSynchronousEvents: true,
|
|
24161
|
-
autoPong: true,
|
|
24162
|
-
protocolVersion: protocolVersions[1],
|
|
24163
|
-
maxPayload: 100 * 1024 * 1024,
|
|
24164
|
-
skipUTF8Validation: false,
|
|
24165
|
-
perMessageDeflate: true,
|
|
24166
|
-
followRedirects: false,
|
|
24167
|
-
maxRedirects: 10,
|
|
24168
|
-
...options,
|
|
24169
|
-
socketPath: undefined,
|
|
24170
|
-
hostname: undefined,
|
|
24171
|
-
protocol: undefined,
|
|
24172
|
-
timeout: undefined,
|
|
24173
|
-
method: "GET",
|
|
24174
|
-
host: undefined,
|
|
24175
|
-
path: undefined,
|
|
24176
|
-
port: undefined
|
|
24177
|
-
};
|
|
24178
|
-
websocket._autoPong = opts.autoPong;
|
|
24179
|
-
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
24180
|
-
throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
|
|
24181
|
-
}
|
|
24182
|
-
let parsedUrl;
|
|
24183
|
-
if (address instanceof URL2) {
|
|
24184
|
-
parsedUrl = address;
|
|
24185
|
-
} else {
|
|
24186
|
-
try {
|
|
24187
|
-
parsedUrl = new URL2(address);
|
|
24188
|
-
} catch (e) {
|
|
24189
|
-
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
24190
|
-
}
|
|
24191
|
-
}
|
|
24192
|
-
if (parsedUrl.protocol === "http:") {
|
|
24193
|
-
parsedUrl.protocol = "ws:";
|
|
24194
|
-
} else if (parsedUrl.protocol === "https:") {
|
|
24195
|
-
parsedUrl.protocol = "wss:";
|
|
24196
|
-
}
|
|
24197
|
-
websocket._url = parsedUrl.href;
|
|
24198
|
-
const isSecure = parsedUrl.protocol === "wss:";
|
|
24199
|
-
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
24200
|
-
let invalidUrlMessage;
|
|
24201
|
-
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
24202
|
-
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", ` + '"http:", "https:", or "ws+unix:"';
|
|
24203
|
-
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
24204
|
-
invalidUrlMessage = "The URL's pathname is empty";
|
|
24205
|
-
} else if (parsedUrl.hash) {
|
|
24206
|
-
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
24207
|
-
}
|
|
24208
|
-
if (invalidUrlMessage) {
|
|
24209
|
-
const err = new SyntaxError(invalidUrlMessage);
|
|
24210
|
-
if (websocket._redirects === 0) {
|
|
24211
|
-
throw err;
|
|
24212
|
-
} else {
|
|
24213
|
-
emitErrorAndClose(websocket, err);
|
|
24214
|
-
return;
|
|
24215
|
-
}
|
|
24216
|
-
}
|
|
24217
|
-
const defaultPort = isSecure ? 443 : 80;
|
|
24218
|
-
const key = randomBytes2(16).toString("base64");
|
|
24219
|
-
const request = isSecure ? https.request : http.request;
|
|
24220
|
-
const protocolSet = new Set;
|
|
24221
|
-
let perMessageDeflate;
|
|
24222
|
-
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
24223
|
-
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
24224
|
-
opts.port = parsedUrl.port || defaultPort;
|
|
24225
|
-
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
24226
|
-
opts.headers = {
|
|
24227
|
-
...opts.headers,
|
|
24228
|
-
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
24229
|
-
"Sec-WebSocket-Key": key,
|
|
24230
|
-
Connection: "Upgrade",
|
|
24231
|
-
Upgrade: "websocket"
|
|
24232
|
-
};
|
|
24233
|
-
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
24234
|
-
opts.timeout = opts.handshakeTimeout;
|
|
24235
|
-
if (opts.perMessageDeflate) {
|
|
24236
|
-
perMessageDeflate = new PerMessageDeflate(opts.perMessageDeflate !== true ? opts.perMessageDeflate : {}, false, opts.maxPayload);
|
|
24237
|
-
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
24238
|
-
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
24239
|
-
});
|
|
24240
|
-
}
|
|
24241
|
-
if (protocols.length) {
|
|
24242
|
-
for (const protocol of protocols) {
|
|
24243
|
-
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
24244
|
-
throw new SyntaxError("An invalid or duplicated subprotocol was specified");
|
|
24245
|
-
}
|
|
24246
|
-
protocolSet.add(protocol);
|
|
24247
|
-
}
|
|
24248
|
-
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
24249
|
-
}
|
|
24250
|
-
if (opts.origin) {
|
|
24251
|
-
if (opts.protocolVersion < 13) {
|
|
24252
|
-
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
24253
|
-
} else {
|
|
24254
|
-
opts.headers.Origin = opts.origin;
|
|
24255
|
-
}
|
|
24256
|
-
}
|
|
24257
|
-
if (parsedUrl.username || parsedUrl.password) {
|
|
24258
|
-
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
24259
|
-
}
|
|
24260
|
-
if (isIpcUrl) {
|
|
24261
|
-
const parts = opts.path.split(":");
|
|
24262
|
-
opts.socketPath = parts[0];
|
|
24263
|
-
opts.path = parts[1];
|
|
24264
|
-
}
|
|
24265
|
-
let req;
|
|
24266
|
-
if (opts.followRedirects) {
|
|
24267
|
-
if (websocket._redirects === 0) {
|
|
24268
|
-
websocket._originalIpc = isIpcUrl;
|
|
24269
|
-
websocket._originalSecure = isSecure;
|
|
24270
|
-
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
24271
|
-
const headers = options && options.headers;
|
|
24272
|
-
options = { ...options, headers: {} };
|
|
24273
|
-
if (headers) {
|
|
24274
|
-
for (const [key2, value] of Object.entries(headers)) {
|
|
24275
|
-
options.headers[key2.toLowerCase()] = value;
|
|
24276
|
-
}
|
|
24277
|
-
}
|
|
24278
|
-
} else if (websocket.listenerCount("redirect") === 0) {
|
|
24279
|
-
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
24280
|
-
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
24281
|
-
delete opts.headers.authorization;
|
|
24282
|
-
delete opts.headers.cookie;
|
|
24283
|
-
if (!isSameHost)
|
|
24284
|
-
delete opts.headers.host;
|
|
24285
|
-
opts.auth = undefined;
|
|
24286
|
-
}
|
|
24287
|
-
}
|
|
24288
|
-
if (opts.auth && !options.headers.authorization) {
|
|
24289
|
-
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
24290
|
-
}
|
|
24291
|
-
req = websocket._req = request(opts);
|
|
24292
|
-
if (websocket._redirects) {
|
|
24293
|
-
websocket.emit("redirect", websocket.url, req);
|
|
24294
|
-
}
|
|
24295
|
-
} else {
|
|
24296
|
-
req = websocket._req = request(opts);
|
|
24297
|
-
}
|
|
24298
|
-
if (opts.timeout) {
|
|
24299
|
-
req.on("timeout", () => {
|
|
24300
|
-
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
24301
|
-
});
|
|
24302
|
-
}
|
|
24303
|
-
req.on("error", (err) => {
|
|
24304
|
-
if (req === null || req[kAborted])
|
|
24305
|
-
return;
|
|
24306
|
-
req = websocket._req = null;
|
|
24307
|
-
emitErrorAndClose(websocket, err);
|
|
24308
|
-
});
|
|
24309
|
-
req.on("response", (res) => {
|
|
24310
|
-
const location = res.headers.location;
|
|
24311
|
-
const statusCode = res.statusCode;
|
|
24312
|
-
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
24313
|
-
if (++websocket._redirects > opts.maxRedirects) {
|
|
24314
|
-
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
24315
|
-
return;
|
|
24316
|
-
}
|
|
24317
|
-
req.abort();
|
|
24318
|
-
let addr;
|
|
24319
|
-
try {
|
|
24320
|
-
addr = new URL2(location, address);
|
|
24321
|
-
} catch (e) {
|
|
24322
|
-
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
24323
|
-
emitErrorAndClose(websocket, err);
|
|
24324
|
-
return;
|
|
24325
|
-
}
|
|
24326
|
-
initAsClient(websocket, addr, protocols, options);
|
|
24327
|
-
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
24328
|
-
abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
24329
|
-
}
|
|
24330
|
-
});
|
|
24331
|
-
req.on("upgrade", (res, socket, head) => {
|
|
24332
|
-
websocket.emit("upgrade", res);
|
|
24333
|
-
if (websocket.readyState !== WebSocket.CONNECTING)
|
|
24334
|
-
return;
|
|
24335
|
-
req = websocket._req = null;
|
|
24336
|
-
const upgrade = res.headers.upgrade;
|
|
24337
|
-
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
24338
|
-
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
24339
|
-
return;
|
|
24340
|
-
}
|
|
24341
|
-
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
24342
|
-
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
24343
|
-
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
24344
|
-
return;
|
|
24345
|
-
}
|
|
24346
|
-
const serverProt = res.headers["sec-websocket-protocol"];
|
|
24347
|
-
let protError;
|
|
24348
|
-
if (serverProt !== undefined) {
|
|
24349
|
-
if (!protocolSet.size) {
|
|
24350
|
-
protError = "Server sent a subprotocol but none was requested";
|
|
24351
|
-
} else if (!protocolSet.has(serverProt)) {
|
|
24352
|
-
protError = "Server sent an invalid subprotocol";
|
|
24353
|
-
}
|
|
24354
|
-
} else if (protocolSet.size) {
|
|
24355
|
-
protError = "Server sent no subprotocol";
|
|
24356
|
-
}
|
|
24357
|
-
if (protError) {
|
|
24358
|
-
abortHandshake(websocket, socket, protError);
|
|
24359
|
-
return;
|
|
24360
|
-
}
|
|
24361
|
-
if (serverProt)
|
|
24362
|
-
websocket._protocol = serverProt;
|
|
24363
|
-
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
24364
|
-
if (secWebSocketExtensions !== undefined) {
|
|
24365
|
-
if (!perMessageDeflate) {
|
|
24366
|
-
const message = "Server sent a Sec-WebSocket-Extensions header but no extension " + "was requested";
|
|
24367
|
-
abortHandshake(websocket, socket, message);
|
|
24368
|
-
return;
|
|
24369
|
-
}
|
|
24370
|
-
let extensions;
|
|
24371
|
-
try {
|
|
24372
|
-
extensions = parse(secWebSocketExtensions);
|
|
24373
|
-
} catch (err) {
|
|
24374
|
-
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
24375
|
-
abortHandshake(websocket, socket, message);
|
|
24376
|
-
return;
|
|
24377
|
-
}
|
|
24378
|
-
const extensionNames = Object.keys(extensions);
|
|
24379
|
-
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
24380
|
-
const message = "Server indicated an extension that was not requested";
|
|
24381
|
-
abortHandshake(websocket, socket, message);
|
|
24382
|
-
return;
|
|
24383
|
-
}
|
|
24384
|
-
try {
|
|
24385
|
-
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
24386
|
-
} catch (err) {
|
|
24387
|
-
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
24388
|
-
abortHandshake(websocket, socket, message);
|
|
24389
|
-
return;
|
|
24390
|
-
}
|
|
24391
|
-
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
24392
|
-
}
|
|
24393
|
-
websocket.setSocket(socket, head, {
|
|
24394
|
-
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
24395
|
-
generateMask: opts.generateMask,
|
|
24396
|
-
maxPayload: opts.maxPayload,
|
|
24397
|
-
skipUTF8Validation: opts.skipUTF8Validation
|
|
24398
|
-
});
|
|
24399
|
-
});
|
|
24400
|
-
if (opts.finishRequest) {
|
|
24401
|
-
opts.finishRequest(req, websocket);
|
|
24402
|
-
} else {
|
|
24403
|
-
req.end();
|
|
24404
|
-
}
|
|
24405
|
-
}
|
|
24406
|
-
function emitErrorAndClose(websocket, err) {
|
|
24407
|
-
websocket._readyState = WebSocket.CLOSING;
|
|
24408
|
-
websocket._errorEmitted = true;
|
|
24409
|
-
websocket.emit("error", err);
|
|
24410
|
-
websocket.emitClose();
|
|
24411
|
-
}
|
|
24412
|
-
function netConnect(options) {
|
|
24413
|
-
options.path = options.socketPath;
|
|
24414
|
-
return net.connect(options);
|
|
24415
|
-
}
|
|
24416
|
-
function tlsConnect(options) {
|
|
24417
|
-
options.path = undefined;
|
|
24418
|
-
if (!options.servername && options.servername !== "") {
|
|
24419
|
-
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
24420
|
-
}
|
|
24421
|
-
return tls.connect(options);
|
|
24422
|
-
}
|
|
24423
|
-
function abortHandshake(websocket, stream, message) {
|
|
24424
|
-
websocket._readyState = WebSocket.CLOSING;
|
|
24425
|
-
const err = new Error(message);
|
|
24426
|
-
Error.captureStackTrace(err, abortHandshake);
|
|
24427
|
-
if (stream.setHeader) {
|
|
24428
|
-
stream[kAborted] = true;
|
|
24429
|
-
stream.abort();
|
|
24430
|
-
if (stream.socket && !stream.socket.destroyed) {
|
|
24431
|
-
stream.socket.destroy();
|
|
24432
|
-
}
|
|
24433
|
-
process.nextTick(emitErrorAndClose, websocket, err);
|
|
24434
|
-
} else {
|
|
24435
|
-
stream.destroy(err);
|
|
24436
|
-
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
24437
|
-
stream.once("close", websocket.emitClose.bind(websocket));
|
|
24438
|
-
}
|
|
24439
|
-
}
|
|
24440
|
-
function sendAfterClose(websocket, data, cb) {
|
|
24441
|
-
if (data) {
|
|
24442
|
-
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
24443
|
-
if (websocket._socket)
|
|
24444
|
-
websocket._sender._bufferedBytes += length;
|
|
24445
|
-
else
|
|
24446
|
-
websocket._bufferedAmount += length;
|
|
24447
|
-
}
|
|
24448
|
-
if (cb) {
|
|
24449
|
-
const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} ` + `(${readyStates[websocket.readyState]})`);
|
|
24450
|
-
process.nextTick(cb, err);
|
|
24451
|
-
}
|
|
24452
|
-
}
|
|
24453
|
-
function receiverOnConclude(code, reason) {
|
|
24454
|
-
const websocket = this[kWebSocket];
|
|
24455
|
-
websocket._closeFrameReceived = true;
|
|
24456
|
-
websocket._closeMessage = reason;
|
|
24457
|
-
websocket._closeCode = code;
|
|
24458
|
-
if (websocket._socket[kWebSocket] === undefined)
|
|
24459
|
-
return;
|
|
24460
|
-
websocket._socket.removeListener("data", socketOnData);
|
|
24461
|
-
process.nextTick(resume, websocket._socket);
|
|
24462
|
-
if (code === 1005)
|
|
24463
|
-
websocket.close();
|
|
24464
|
-
else
|
|
24465
|
-
websocket.close(code, reason);
|
|
24466
|
-
}
|
|
24467
|
-
function receiverOnDrain() {
|
|
24468
|
-
const websocket = this[kWebSocket];
|
|
24469
|
-
if (!websocket.isPaused)
|
|
24470
|
-
websocket._socket.resume();
|
|
24471
|
-
}
|
|
24472
|
-
function receiverOnError(err) {
|
|
24473
|
-
const websocket = this[kWebSocket];
|
|
24474
|
-
if (websocket._socket[kWebSocket] !== undefined) {
|
|
24475
|
-
websocket._socket.removeListener("data", socketOnData);
|
|
24476
|
-
process.nextTick(resume, websocket._socket);
|
|
24477
|
-
websocket.close(err[kStatusCode]);
|
|
24478
|
-
}
|
|
24479
|
-
if (!websocket._errorEmitted) {
|
|
24480
|
-
websocket._errorEmitted = true;
|
|
24481
|
-
websocket.emit("error", err);
|
|
24482
|
-
}
|
|
24483
|
-
}
|
|
24484
|
-
function receiverOnFinish() {
|
|
24485
|
-
this[kWebSocket].emitClose();
|
|
24486
|
-
}
|
|
24487
|
-
function receiverOnMessage(data, isBinary) {
|
|
24488
|
-
this[kWebSocket].emit("message", data, isBinary);
|
|
24489
|
-
}
|
|
24490
|
-
function receiverOnPing(data) {
|
|
24491
|
-
const websocket = this[kWebSocket];
|
|
24492
|
-
if (websocket._autoPong)
|
|
24493
|
-
websocket.pong(data, !this._isServer, NOOP);
|
|
24494
|
-
websocket.emit("ping", data);
|
|
24495
|
-
}
|
|
24496
|
-
function receiverOnPong(data) {
|
|
24497
|
-
this[kWebSocket].emit("pong", data);
|
|
24498
|
-
}
|
|
24499
|
-
function resume(stream) {
|
|
24500
|
-
stream.resume();
|
|
24501
|
-
}
|
|
24502
|
-
function senderOnError(err) {
|
|
24503
|
-
const websocket = this[kWebSocket];
|
|
24504
|
-
if (websocket.readyState === WebSocket.CLOSED)
|
|
24505
|
-
return;
|
|
24506
|
-
if (websocket.readyState === WebSocket.OPEN) {
|
|
24507
|
-
websocket._readyState = WebSocket.CLOSING;
|
|
24508
|
-
setCloseTimer(websocket);
|
|
24509
|
-
}
|
|
24510
|
-
this._socket.end();
|
|
24511
|
-
if (!websocket._errorEmitted) {
|
|
24512
|
-
websocket._errorEmitted = true;
|
|
24513
|
-
websocket.emit("error", err);
|
|
24514
|
-
}
|
|
24515
|
-
}
|
|
24516
|
-
function setCloseTimer(websocket) {
|
|
24517
|
-
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), closeTimeout);
|
|
24518
|
-
}
|
|
24519
|
-
function socketOnClose() {
|
|
24520
|
-
const websocket = this[kWebSocket];
|
|
24521
|
-
this.removeListener("close", socketOnClose);
|
|
24522
|
-
this.removeListener("data", socketOnData);
|
|
24523
|
-
this.removeListener("end", socketOnEnd);
|
|
24524
|
-
websocket._readyState = WebSocket.CLOSING;
|
|
24525
|
-
let chunk;
|
|
24526
|
-
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
|
|
24527
|
-
websocket._receiver.write(chunk);
|
|
24528
|
-
}
|
|
24529
|
-
websocket._receiver.end();
|
|
24530
|
-
this[kWebSocket] = undefined;
|
|
24531
|
-
clearTimeout(websocket._closeTimer);
|
|
24532
|
-
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
24533
|
-
websocket.emitClose();
|
|
24534
|
-
} else {
|
|
24535
|
-
websocket._receiver.on("error", receiverOnFinish);
|
|
24536
|
-
websocket._receiver.on("finish", receiverOnFinish);
|
|
24537
|
-
}
|
|
24538
|
-
}
|
|
24539
|
-
function socketOnData(chunk) {
|
|
24540
|
-
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
24541
|
-
this.pause();
|
|
24542
|
-
}
|
|
24543
|
-
}
|
|
24544
|
-
function socketOnEnd() {
|
|
24545
|
-
const websocket = this[kWebSocket];
|
|
24546
|
-
websocket._readyState = WebSocket.CLOSING;
|
|
24547
|
-
websocket._receiver.end();
|
|
24548
|
-
this.end();
|
|
24549
|
-
}
|
|
24550
|
-
function socketOnError() {
|
|
24551
|
-
const websocket = this[kWebSocket];
|
|
24552
|
-
this.removeListener("error", socketOnError);
|
|
24553
|
-
this.on("error", NOOP);
|
|
24554
|
-
if (websocket) {
|
|
24555
|
-
websocket._readyState = WebSocket.CLOSING;
|
|
24556
|
-
this.destroy();
|
|
24557
|
-
}
|
|
24558
|
-
}
|
|
24559
|
-
});
|
|
24560
|
-
|
|
24561
|
-
// node_modules/ws/lib/stream.js
|
|
24562
|
-
var require_stream = __commonJS((exports, module) => {
|
|
24563
|
-
var WebSocket = require_websocket();
|
|
24564
|
-
var { Duplex } = __require("stream");
|
|
24565
|
-
function emitClose(stream) {
|
|
24566
|
-
stream.emit("close");
|
|
24567
|
-
}
|
|
24568
|
-
function duplexOnEnd() {
|
|
24569
|
-
if (!this.destroyed && this._writableState.finished) {
|
|
24570
|
-
this.destroy();
|
|
24571
|
-
}
|
|
24572
|
-
}
|
|
24573
|
-
function duplexOnError(err) {
|
|
24574
|
-
this.removeListener("error", duplexOnError);
|
|
24575
|
-
this.destroy();
|
|
24576
|
-
if (this.listenerCount("error") === 0) {
|
|
24577
|
-
this.emit("error", err);
|
|
24578
|
-
}
|
|
24579
|
-
}
|
|
24580
|
-
function createWebSocketStream(ws, options) {
|
|
24581
|
-
let terminateOnDestroy = true;
|
|
24582
|
-
const duplex = new Duplex({
|
|
24583
|
-
...options,
|
|
24584
|
-
autoDestroy: false,
|
|
24585
|
-
emitClose: false,
|
|
24586
|
-
objectMode: false,
|
|
24587
|
-
writableObjectMode: false
|
|
24588
|
-
});
|
|
24589
|
-
ws.on("message", function message(msg, isBinary) {
|
|
24590
|
-
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
24591
|
-
if (!duplex.push(data))
|
|
24592
|
-
ws.pause();
|
|
24593
|
-
});
|
|
24594
|
-
ws.once("error", function error(err) {
|
|
24595
|
-
if (duplex.destroyed)
|
|
24596
|
-
return;
|
|
24597
|
-
terminateOnDestroy = false;
|
|
24598
|
-
duplex.destroy(err);
|
|
24599
|
-
});
|
|
24600
|
-
ws.once("close", function close() {
|
|
24601
|
-
if (duplex.destroyed)
|
|
24602
|
-
return;
|
|
24603
|
-
duplex.push(null);
|
|
24604
|
-
});
|
|
24605
|
-
duplex._destroy = function(err, callback) {
|
|
24606
|
-
if (ws.readyState === ws.CLOSED) {
|
|
24607
|
-
callback(err);
|
|
24608
|
-
process.nextTick(emitClose, duplex);
|
|
24609
|
-
return;
|
|
24610
|
-
}
|
|
24611
|
-
let called = false;
|
|
24612
|
-
ws.once("error", function error(err2) {
|
|
24613
|
-
called = true;
|
|
24614
|
-
callback(err2);
|
|
24615
|
-
});
|
|
24616
|
-
ws.once("close", function close() {
|
|
24617
|
-
if (!called)
|
|
24618
|
-
callback(err);
|
|
24619
|
-
process.nextTick(emitClose, duplex);
|
|
24620
|
-
});
|
|
24621
|
-
if (terminateOnDestroy)
|
|
24622
|
-
ws.terminate();
|
|
24623
|
-
};
|
|
24624
|
-
duplex._final = function(callback) {
|
|
24625
|
-
if (ws.readyState === ws.CONNECTING) {
|
|
24626
|
-
ws.once("open", function open() {
|
|
24627
|
-
duplex._final(callback);
|
|
24628
|
-
});
|
|
24629
|
-
return;
|
|
24630
|
-
}
|
|
24631
|
-
if (ws._socket === null)
|
|
24632
|
-
return;
|
|
24633
|
-
if (ws._socket._writableState.finished) {
|
|
24634
|
-
callback();
|
|
24635
|
-
if (duplex._readableState.endEmitted)
|
|
24636
|
-
duplex.destroy();
|
|
24637
|
-
} else {
|
|
24638
|
-
ws._socket.once("finish", function finish() {
|
|
24639
|
-
callback();
|
|
24640
|
-
});
|
|
24641
|
-
ws.close();
|
|
24642
|
-
}
|
|
24643
|
-
};
|
|
24644
|
-
duplex._read = function() {
|
|
24645
|
-
if (ws.isPaused)
|
|
24646
|
-
ws.resume();
|
|
24647
|
-
};
|
|
24648
|
-
duplex._write = function(chunk, encoding, callback) {
|
|
24649
|
-
if (ws.readyState === ws.CONNECTING) {
|
|
24650
|
-
ws.once("open", function open() {
|
|
24651
|
-
duplex._write(chunk, encoding, callback);
|
|
24652
|
-
});
|
|
24653
|
-
return;
|
|
24654
|
-
}
|
|
24655
|
-
ws.send(chunk, callback);
|
|
24656
|
-
};
|
|
24657
|
-
duplex.on("end", duplexOnEnd);
|
|
24658
|
-
duplex.on("error", duplexOnError);
|
|
24659
|
-
return duplex;
|
|
24660
|
-
}
|
|
24661
|
-
module.exports = createWebSocketStream;
|
|
24662
|
-
});
|
|
24663
|
-
|
|
24664
|
-
// node_modules/ws/lib/subprotocol.js
|
|
24665
|
-
var require_subprotocol = __commonJS((exports, module) => {
|
|
24666
|
-
var { tokenChars } = require_validation();
|
|
24667
|
-
function parse(header) {
|
|
24668
|
-
const protocols = new Set;
|
|
24669
|
-
let start = -1;
|
|
24670
|
-
let end = -1;
|
|
24671
|
-
let i = 0;
|
|
24672
|
-
for (i;i < header.length; i++) {
|
|
24673
|
-
const code = header.charCodeAt(i);
|
|
24674
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
24675
|
-
if (start === -1)
|
|
24676
|
-
start = i;
|
|
24677
|
-
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
24678
|
-
if (end === -1 && start !== -1)
|
|
24679
|
-
end = i;
|
|
24680
|
-
} else if (code === 44) {
|
|
24681
|
-
if (start === -1) {
|
|
24682
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
24683
|
-
}
|
|
24684
|
-
if (end === -1)
|
|
24685
|
-
end = i;
|
|
24686
|
-
const protocol2 = header.slice(start, end);
|
|
24687
|
-
if (protocols.has(protocol2)) {
|
|
24688
|
-
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
24689
|
-
}
|
|
24690
|
-
protocols.add(protocol2);
|
|
24691
|
-
start = end = -1;
|
|
24692
|
-
} else {
|
|
24693
|
-
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
24694
|
-
}
|
|
24695
|
-
}
|
|
24696
|
-
if (start === -1 || end !== -1) {
|
|
24697
|
-
throw new SyntaxError("Unexpected end of input");
|
|
24698
|
-
}
|
|
24699
|
-
const protocol = header.slice(start, i);
|
|
24700
|
-
if (protocols.has(protocol)) {
|
|
24701
|
-
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
24702
|
-
}
|
|
24703
|
-
protocols.add(protocol);
|
|
24704
|
-
return protocols;
|
|
24705
|
-
}
|
|
24706
|
-
module.exports = { parse };
|
|
24707
|
-
});
|
|
24708
|
-
|
|
24709
|
-
// node_modules/ws/lib/websocket-server.js
|
|
24710
|
-
var require_websocket_server = __commonJS((exports, module) => {
|
|
24711
|
-
var EventEmitter = __require("events");
|
|
24712
|
-
var http = __require("http");
|
|
24713
|
-
var { Duplex } = __require("stream");
|
|
24714
|
-
var { createHash } = __require("crypto");
|
|
24715
|
-
var extension = require_extension();
|
|
24716
|
-
var PerMessageDeflate = require_permessage_deflate();
|
|
24717
|
-
var subprotocol = require_subprotocol();
|
|
24718
|
-
var WebSocket = require_websocket();
|
|
24719
|
-
var { GUID, kWebSocket } = require_constants2();
|
|
24720
|
-
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
24721
|
-
var RUNNING = 0;
|
|
24722
|
-
var CLOSING = 1;
|
|
24723
|
-
var CLOSED = 2;
|
|
24724
|
-
|
|
24725
|
-
class WebSocketServer extends EventEmitter {
|
|
24726
|
-
constructor(options, callback) {
|
|
24727
|
-
super();
|
|
24728
|
-
options = {
|
|
24729
|
-
allowSynchronousEvents: true,
|
|
24730
|
-
autoPong: true,
|
|
24731
|
-
maxPayload: 100 * 1024 * 1024,
|
|
24732
|
-
skipUTF8Validation: false,
|
|
24733
|
-
perMessageDeflate: false,
|
|
24734
|
-
handleProtocols: null,
|
|
24735
|
-
clientTracking: true,
|
|
24736
|
-
verifyClient: null,
|
|
24737
|
-
noServer: false,
|
|
24738
|
-
backlog: null,
|
|
24739
|
-
server: null,
|
|
24740
|
-
host: null,
|
|
24741
|
-
path: null,
|
|
24742
|
-
port: null,
|
|
24743
|
-
WebSocket,
|
|
24744
|
-
...options
|
|
24745
|
-
};
|
|
24746
|
-
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
24747
|
-
throw new TypeError('One and only one of the "port", "server", or "noServer" options ' + "must be specified");
|
|
24748
|
-
}
|
|
24749
|
-
if (options.port != null) {
|
|
24750
|
-
this._server = http.createServer((req, res) => {
|
|
24751
|
-
const body = http.STATUS_CODES[426];
|
|
24752
|
-
res.writeHead(426, {
|
|
24753
|
-
"Content-Length": body.length,
|
|
24754
|
-
"Content-Type": "text/plain"
|
|
24755
|
-
});
|
|
24756
|
-
res.end(body);
|
|
24757
|
-
});
|
|
24758
|
-
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
24759
|
-
} else if (options.server) {
|
|
24760
|
-
this._server = options.server;
|
|
24761
|
-
}
|
|
24762
|
-
if (this._server) {
|
|
24763
|
-
const emitConnection = this.emit.bind(this, "connection");
|
|
24764
|
-
this._removeListeners = addListeners(this._server, {
|
|
24765
|
-
listening: this.emit.bind(this, "listening"),
|
|
24766
|
-
error: this.emit.bind(this, "error"),
|
|
24767
|
-
upgrade: (req, socket, head) => {
|
|
24768
|
-
this.handleUpgrade(req, socket, head, emitConnection);
|
|
24769
|
-
}
|
|
24770
|
-
});
|
|
24771
|
-
}
|
|
24772
|
-
if (options.perMessageDeflate === true)
|
|
24773
|
-
options.perMessageDeflate = {};
|
|
24774
|
-
if (options.clientTracking) {
|
|
24775
|
-
this.clients = new Set;
|
|
24776
|
-
this._shouldEmitClose = false;
|
|
24777
|
-
}
|
|
24778
|
-
this.options = options;
|
|
24779
|
-
this._state = RUNNING;
|
|
24780
|
-
}
|
|
24781
|
-
address() {
|
|
24782
|
-
if (this.options.noServer) {
|
|
24783
|
-
throw new Error('The server is operating in "noServer" mode');
|
|
24784
|
-
}
|
|
24785
|
-
if (!this._server)
|
|
24786
|
-
return null;
|
|
24787
|
-
return this._server.address();
|
|
24788
|
-
}
|
|
24789
|
-
close(cb) {
|
|
24790
|
-
if (this._state === CLOSED) {
|
|
24791
|
-
if (cb) {
|
|
24792
|
-
this.once("close", () => {
|
|
24793
|
-
cb(new Error("The server is not running"));
|
|
24794
|
-
});
|
|
24795
|
-
}
|
|
24796
|
-
process.nextTick(emitClose, this);
|
|
24797
|
-
return;
|
|
24798
|
-
}
|
|
24799
|
-
if (cb)
|
|
24800
|
-
this.once("close", cb);
|
|
24801
|
-
if (this._state === CLOSING)
|
|
24802
|
-
return;
|
|
24803
|
-
this._state = CLOSING;
|
|
24804
|
-
if (this.options.noServer || this.options.server) {
|
|
24805
|
-
if (this._server) {
|
|
24806
|
-
this._removeListeners();
|
|
24807
|
-
this._removeListeners = this._server = null;
|
|
24808
|
-
}
|
|
24809
|
-
if (this.clients) {
|
|
24810
|
-
if (!this.clients.size) {
|
|
24811
|
-
process.nextTick(emitClose, this);
|
|
24812
|
-
} else {
|
|
24813
|
-
this._shouldEmitClose = true;
|
|
24814
|
-
}
|
|
24815
|
-
} else {
|
|
24816
|
-
process.nextTick(emitClose, this);
|
|
24817
|
-
}
|
|
24818
|
-
} else {
|
|
24819
|
-
const server = this._server;
|
|
24820
|
-
this._removeListeners();
|
|
24821
|
-
this._removeListeners = this._server = null;
|
|
24822
|
-
server.close(() => {
|
|
24823
|
-
emitClose(this);
|
|
24824
|
-
});
|
|
24825
|
-
}
|
|
24826
|
-
}
|
|
24827
|
-
shouldHandle(req) {
|
|
24828
|
-
if (this.options.path) {
|
|
24829
|
-
const index2 = req.url.indexOf("?");
|
|
24830
|
-
const pathname = index2 !== -1 ? req.url.slice(0, index2) : req.url;
|
|
24831
|
-
if (pathname !== this.options.path)
|
|
24832
|
-
return false;
|
|
24833
|
-
}
|
|
24834
|
-
return true;
|
|
24835
|
-
}
|
|
24836
|
-
handleUpgrade(req, socket, head, cb) {
|
|
24837
|
-
socket.on("error", socketOnError);
|
|
24838
|
-
const key = req.headers["sec-websocket-key"];
|
|
24839
|
-
const upgrade = req.headers.upgrade;
|
|
24840
|
-
const version = +req.headers["sec-websocket-version"];
|
|
24841
|
-
if (req.method !== "GET") {
|
|
24842
|
-
const message = "Invalid HTTP method";
|
|
24843
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
24844
|
-
return;
|
|
24845
|
-
}
|
|
24846
|
-
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
24847
|
-
const message = "Invalid Upgrade header";
|
|
24848
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
24849
|
-
return;
|
|
24850
|
-
}
|
|
24851
|
-
if (key === undefined || !keyRegex.test(key)) {
|
|
24852
|
-
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
24853
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
24854
|
-
return;
|
|
24855
|
-
}
|
|
24856
|
-
if (version !== 8 && version !== 13) {
|
|
24857
|
-
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
24858
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
24859
|
-
return;
|
|
24860
|
-
}
|
|
24861
|
-
if (!this.shouldHandle(req)) {
|
|
24862
|
-
abortHandshake(socket, 400);
|
|
24863
|
-
return;
|
|
24864
|
-
}
|
|
24865
|
-
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
24866
|
-
let protocols = new Set;
|
|
24867
|
-
if (secWebSocketProtocol !== undefined) {
|
|
24868
|
-
try {
|
|
24869
|
-
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
24870
|
-
} catch (err) {
|
|
24871
|
-
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
24872
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
24873
|
-
return;
|
|
24874
|
-
}
|
|
24875
|
-
}
|
|
24876
|
-
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
24877
|
-
const extensions = {};
|
|
24878
|
-
if (this.options.perMessageDeflate && secWebSocketExtensions !== undefined) {
|
|
24879
|
-
const perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, true, this.options.maxPayload);
|
|
24880
|
-
try {
|
|
24881
|
-
const offers = extension.parse(secWebSocketExtensions);
|
|
24882
|
-
if (offers[PerMessageDeflate.extensionName]) {
|
|
24883
|
-
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
24884
|
-
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
24885
|
-
}
|
|
24886
|
-
} catch (err) {
|
|
24887
|
-
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
24888
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
24889
|
-
return;
|
|
24890
|
-
}
|
|
24891
|
-
}
|
|
24892
|
-
if (this.options.verifyClient) {
|
|
24893
|
-
const info = {
|
|
24894
|
-
origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
24895
|
-
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
24896
|
-
req
|
|
24897
|
-
};
|
|
24898
|
-
if (this.options.verifyClient.length === 2) {
|
|
24899
|
-
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
24900
|
-
if (!verified) {
|
|
24901
|
-
return abortHandshake(socket, code || 401, message, headers);
|
|
24902
|
-
}
|
|
24903
|
-
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
24904
|
-
});
|
|
24905
|
-
return;
|
|
24906
|
-
}
|
|
24907
|
-
if (!this.options.verifyClient(info))
|
|
24908
|
-
return abortHandshake(socket, 401);
|
|
24909
|
-
}
|
|
24910
|
-
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
24911
|
-
}
|
|
24912
|
-
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
24913
|
-
if (!socket.readable || !socket.writable)
|
|
24914
|
-
return socket.destroy();
|
|
24915
|
-
if (socket[kWebSocket]) {
|
|
24916
|
-
throw new Error("server.handleUpgrade() was called more than once with the same " + "socket, possibly due to a misconfiguration");
|
|
24917
|
-
}
|
|
24918
|
-
if (this._state > RUNNING)
|
|
24919
|
-
return abortHandshake(socket, 503);
|
|
24920
|
-
const digest = createHash("sha1").update(key + GUID).digest("base64");
|
|
24921
|
-
const headers = [
|
|
24922
|
-
"HTTP/1.1 101 Switching Protocols",
|
|
24923
|
-
"Upgrade: websocket",
|
|
24924
|
-
"Connection: Upgrade",
|
|
24925
|
-
`Sec-WebSocket-Accept: ${digest}`
|
|
24926
|
-
];
|
|
24927
|
-
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
24928
|
-
if (protocols.size) {
|
|
24929
|
-
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
24930
|
-
if (protocol) {
|
|
24931
|
-
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
24932
|
-
ws._protocol = protocol;
|
|
24933
|
-
}
|
|
24934
|
-
}
|
|
24935
|
-
if (extensions[PerMessageDeflate.extensionName]) {
|
|
24936
|
-
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
24937
|
-
const value = extension.format({
|
|
24938
|
-
[PerMessageDeflate.extensionName]: [params]
|
|
24939
|
-
});
|
|
24940
|
-
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
24941
|
-
ws._extensions = extensions;
|
|
24942
|
-
}
|
|
24943
|
-
this.emit("headers", headers, req);
|
|
24944
|
-
socket.write(headers.concat(`\r
|
|
24945
|
-
`).join(`\r
|
|
24946
|
-
`));
|
|
24947
|
-
socket.removeListener("error", socketOnError);
|
|
24948
|
-
ws.setSocket(socket, head, {
|
|
24949
|
-
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
24950
|
-
maxPayload: this.options.maxPayload,
|
|
24951
|
-
skipUTF8Validation: this.options.skipUTF8Validation
|
|
24952
|
-
});
|
|
24953
|
-
if (this.clients) {
|
|
24954
|
-
this.clients.add(ws);
|
|
24955
|
-
ws.on("close", () => {
|
|
24956
|
-
this.clients.delete(ws);
|
|
24957
|
-
if (this._shouldEmitClose && !this.clients.size) {
|
|
24958
|
-
process.nextTick(emitClose, this);
|
|
24959
|
-
}
|
|
24960
|
-
});
|
|
24961
|
-
}
|
|
24962
|
-
cb(ws, req);
|
|
24963
|
-
}
|
|
24964
|
-
}
|
|
24965
|
-
module.exports = WebSocketServer;
|
|
24966
|
-
function addListeners(server, map) {
|
|
24967
|
-
for (const event of Object.keys(map))
|
|
24968
|
-
server.on(event, map[event]);
|
|
24969
|
-
return function removeListeners() {
|
|
24970
|
-
for (const event of Object.keys(map)) {
|
|
24971
|
-
server.removeListener(event, map[event]);
|
|
24972
|
-
}
|
|
24973
|
-
};
|
|
24974
|
-
}
|
|
24975
|
-
function emitClose(server) {
|
|
24976
|
-
server._state = CLOSED;
|
|
24977
|
-
server.emit("close");
|
|
24978
|
-
}
|
|
24979
|
-
function socketOnError() {
|
|
24980
|
-
this.destroy();
|
|
24981
|
-
}
|
|
24982
|
-
function abortHandshake(socket, code, message, headers) {
|
|
24983
|
-
message = message || http.STATUS_CODES[code];
|
|
24984
|
-
headers = {
|
|
24985
|
-
Connection: "close",
|
|
24986
|
-
"Content-Type": "text/html",
|
|
24987
|
-
"Content-Length": Buffer.byteLength(message),
|
|
24988
|
-
...headers
|
|
24989
|
-
};
|
|
24990
|
-
socket.once("finish", socket.destroy);
|
|
24991
|
-
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
24992
|
-
` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join(`\r
|
|
24993
|
-
`) + `\r
|
|
24994
|
-
\r
|
|
24995
|
-
` + message);
|
|
24996
|
-
}
|
|
24997
|
-
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
24998
|
-
if (server.listenerCount("wsClientError")) {
|
|
24999
|
-
const err = new Error(message);
|
|
25000
|
-
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
25001
|
-
server.emit("wsClientError", err, socket, req);
|
|
25002
|
-
} else {
|
|
25003
|
-
abortHandshake(socket, code, message);
|
|
25004
|
-
}
|
|
25005
|
-
}
|
|
25006
|
-
});
|
|
25007
|
-
|
|
25008
22171
|
// node_modules/delayed-stream/lib/delayed_stream.js
|
|
25009
22172
|
var require_delayed_stream = __commonJS((exports, module) => {
|
|
25010
22173
|
var Stream2 = __require("stream").Stream;
|
|
@@ -35192,13 +32355,429 @@ var require_proxy_from_env = __commonJS((exports) => {
|
|
|
35192
32355
|
exports.getProxyForUrl = getProxyForUrl;
|
|
35193
32356
|
});
|
|
35194
32357
|
|
|
35195
|
-
// node_modules/
|
|
32358
|
+
// node_modules/ms/index.js
|
|
32359
|
+
var require_ms = __commonJS((exports, module) => {
|
|
32360
|
+
var s = 1000;
|
|
32361
|
+
var m = s * 60;
|
|
32362
|
+
var h = m * 60;
|
|
32363
|
+
var d = h * 24;
|
|
32364
|
+
var y = d * 365.25;
|
|
32365
|
+
module.exports = function(val, options) {
|
|
32366
|
+
options = options || {};
|
|
32367
|
+
var type2 = typeof val;
|
|
32368
|
+
if (type2 === "string" && val.length > 0) {
|
|
32369
|
+
return parse(val);
|
|
32370
|
+
} else if (type2 === "number" && isNaN(val) === false) {
|
|
32371
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
32372
|
+
}
|
|
32373
|
+
throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(val));
|
|
32374
|
+
};
|
|
32375
|
+
function parse(str) {
|
|
32376
|
+
str = String(str);
|
|
32377
|
+
if (str.length > 100) {
|
|
32378
|
+
return;
|
|
32379
|
+
}
|
|
32380
|
+
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
|
|
32381
|
+
if (!match) {
|
|
32382
|
+
return;
|
|
32383
|
+
}
|
|
32384
|
+
var n2 = parseFloat(match[1]);
|
|
32385
|
+
var type2 = (match[2] || "ms").toLowerCase();
|
|
32386
|
+
switch (type2) {
|
|
32387
|
+
case "years":
|
|
32388
|
+
case "year":
|
|
32389
|
+
case "yrs":
|
|
32390
|
+
case "yr":
|
|
32391
|
+
case "y":
|
|
32392
|
+
return n2 * y;
|
|
32393
|
+
case "days":
|
|
32394
|
+
case "day":
|
|
32395
|
+
case "d":
|
|
32396
|
+
return n2 * d;
|
|
32397
|
+
case "hours":
|
|
32398
|
+
case "hour":
|
|
32399
|
+
case "hrs":
|
|
32400
|
+
case "hr":
|
|
32401
|
+
case "h":
|
|
32402
|
+
return n2 * h;
|
|
32403
|
+
case "minutes":
|
|
32404
|
+
case "minute":
|
|
32405
|
+
case "mins":
|
|
32406
|
+
case "min":
|
|
32407
|
+
case "m":
|
|
32408
|
+
return n2 * m;
|
|
32409
|
+
case "seconds":
|
|
32410
|
+
case "second":
|
|
32411
|
+
case "secs":
|
|
32412
|
+
case "sec":
|
|
32413
|
+
case "s":
|
|
32414
|
+
return n2 * s;
|
|
32415
|
+
case "milliseconds":
|
|
32416
|
+
case "millisecond":
|
|
32417
|
+
case "msecs":
|
|
32418
|
+
case "msec":
|
|
32419
|
+
case "ms":
|
|
32420
|
+
return n2;
|
|
32421
|
+
default:
|
|
32422
|
+
return;
|
|
32423
|
+
}
|
|
32424
|
+
}
|
|
32425
|
+
function fmtShort(ms) {
|
|
32426
|
+
if (ms >= d) {
|
|
32427
|
+
return Math.round(ms / d) + "d";
|
|
32428
|
+
}
|
|
32429
|
+
if (ms >= h) {
|
|
32430
|
+
return Math.round(ms / h) + "h";
|
|
32431
|
+
}
|
|
32432
|
+
if (ms >= m) {
|
|
32433
|
+
return Math.round(ms / m) + "m";
|
|
32434
|
+
}
|
|
32435
|
+
if (ms >= s) {
|
|
32436
|
+
return Math.round(ms / s) + "s";
|
|
32437
|
+
}
|
|
32438
|
+
return ms + "ms";
|
|
32439
|
+
}
|
|
32440
|
+
function fmtLong(ms) {
|
|
32441
|
+
return plural(ms, d, "day") || plural(ms, h, "hour") || plural(ms, m, "minute") || plural(ms, s, "second") || ms + " ms";
|
|
32442
|
+
}
|
|
32443
|
+
function plural(ms, n2, name) {
|
|
32444
|
+
if (ms < n2) {
|
|
32445
|
+
return;
|
|
32446
|
+
}
|
|
32447
|
+
if (ms < n2 * 1.5) {
|
|
32448
|
+
return Math.floor(ms / n2) + " " + name;
|
|
32449
|
+
}
|
|
32450
|
+
return Math.ceil(ms / n2) + " " + name + "s";
|
|
32451
|
+
}
|
|
32452
|
+
});
|
|
32453
|
+
|
|
32454
|
+
// node_modules/debug/src/debug.js
|
|
35196
32455
|
var require_debug = __commonJS((exports, module) => {
|
|
32456
|
+
exports = module.exports = createDebug.debug = createDebug["default"] = createDebug;
|
|
32457
|
+
exports.coerce = coerce;
|
|
32458
|
+
exports.disable = disable;
|
|
32459
|
+
exports.enable = enable;
|
|
32460
|
+
exports.enabled = enabled;
|
|
32461
|
+
exports.humanize = require_ms();
|
|
32462
|
+
exports.names = [];
|
|
32463
|
+
exports.skips = [];
|
|
32464
|
+
exports.formatters = {};
|
|
32465
|
+
var prevTime;
|
|
32466
|
+
function selectColor(namespace) {
|
|
32467
|
+
var hash3 = 0, i2;
|
|
32468
|
+
for (i2 in namespace) {
|
|
32469
|
+
hash3 = (hash3 << 5) - hash3 + namespace.charCodeAt(i2);
|
|
32470
|
+
hash3 |= 0;
|
|
32471
|
+
}
|
|
32472
|
+
return exports.colors[Math.abs(hash3) % exports.colors.length];
|
|
32473
|
+
}
|
|
32474
|
+
function createDebug(namespace) {
|
|
32475
|
+
function debug() {
|
|
32476
|
+
if (!debug.enabled)
|
|
32477
|
+
return;
|
|
32478
|
+
var self2 = debug;
|
|
32479
|
+
var curr = +new Date;
|
|
32480
|
+
var ms = curr - (prevTime || curr);
|
|
32481
|
+
self2.diff = ms;
|
|
32482
|
+
self2.prev = prevTime;
|
|
32483
|
+
self2.curr = curr;
|
|
32484
|
+
prevTime = curr;
|
|
32485
|
+
var args = new Array(arguments.length);
|
|
32486
|
+
for (var i2 = 0;i2 < args.length; i2++) {
|
|
32487
|
+
args[i2] = arguments[i2];
|
|
32488
|
+
}
|
|
32489
|
+
args[0] = exports.coerce(args[0]);
|
|
32490
|
+
if (typeof args[0] !== "string") {
|
|
32491
|
+
args.unshift("%O");
|
|
32492
|
+
}
|
|
32493
|
+
var index2 = 0;
|
|
32494
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, function(match, format) {
|
|
32495
|
+
if (match === "%%")
|
|
32496
|
+
return match;
|
|
32497
|
+
index2++;
|
|
32498
|
+
var formatter2 = exports.formatters[format];
|
|
32499
|
+
if (typeof formatter2 === "function") {
|
|
32500
|
+
var val = args[index2];
|
|
32501
|
+
match = formatter2.call(self2, val);
|
|
32502
|
+
args.splice(index2, 1);
|
|
32503
|
+
index2--;
|
|
32504
|
+
}
|
|
32505
|
+
return match;
|
|
32506
|
+
});
|
|
32507
|
+
exports.formatArgs.call(self2, args);
|
|
32508
|
+
var logFn = debug.log || exports.log || console.log.bind(console);
|
|
32509
|
+
logFn.apply(self2, args);
|
|
32510
|
+
}
|
|
32511
|
+
debug.namespace = namespace;
|
|
32512
|
+
debug.enabled = exports.enabled(namespace);
|
|
32513
|
+
debug.useColors = exports.useColors();
|
|
32514
|
+
debug.color = selectColor(namespace);
|
|
32515
|
+
if (typeof exports.init === "function") {
|
|
32516
|
+
exports.init(debug);
|
|
32517
|
+
}
|
|
32518
|
+
return debug;
|
|
32519
|
+
}
|
|
32520
|
+
function enable(namespaces) {
|
|
32521
|
+
exports.save(namespaces);
|
|
32522
|
+
exports.names = [];
|
|
32523
|
+
exports.skips = [];
|
|
32524
|
+
var split2 = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/);
|
|
32525
|
+
var len = split2.length;
|
|
32526
|
+
for (var i2 = 0;i2 < len; i2++) {
|
|
32527
|
+
if (!split2[i2])
|
|
32528
|
+
continue;
|
|
32529
|
+
namespaces = split2[i2].replace(/\*/g, ".*?");
|
|
32530
|
+
if (namespaces[0] === "-") {
|
|
32531
|
+
exports.skips.push(new RegExp("^" + namespaces.substr(1) + "$"));
|
|
32532
|
+
} else {
|
|
32533
|
+
exports.names.push(new RegExp("^" + namespaces + "$"));
|
|
32534
|
+
}
|
|
32535
|
+
}
|
|
32536
|
+
}
|
|
32537
|
+
function disable() {
|
|
32538
|
+
exports.enable("");
|
|
32539
|
+
}
|
|
32540
|
+
function enabled(name) {
|
|
32541
|
+
var i2, len;
|
|
32542
|
+
for (i2 = 0, len = exports.skips.length;i2 < len; i2++) {
|
|
32543
|
+
if (exports.skips[i2].test(name)) {
|
|
32544
|
+
return false;
|
|
32545
|
+
}
|
|
32546
|
+
}
|
|
32547
|
+
for (i2 = 0, len = exports.names.length;i2 < len; i2++) {
|
|
32548
|
+
if (exports.names[i2].test(name)) {
|
|
32549
|
+
return true;
|
|
32550
|
+
}
|
|
32551
|
+
}
|
|
32552
|
+
return false;
|
|
32553
|
+
}
|
|
32554
|
+
function coerce(val) {
|
|
32555
|
+
if (val instanceof Error)
|
|
32556
|
+
return val.stack || val.message;
|
|
32557
|
+
return val;
|
|
32558
|
+
}
|
|
32559
|
+
});
|
|
32560
|
+
|
|
32561
|
+
// node_modules/debug/src/browser.js
|
|
32562
|
+
var require_browser = __commonJS((exports, module) => {
|
|
32563
|
+
exports = module.exports = require_debug();
|
|
32564
|
+
exports.log = log;
|
|
32565
|
+
exports.formatArgs = formatArgs;
|
|
32566
|
+
exports.save = save;
|
|
32567
|
+
exports.load = load;
|
|
32568
|
+
exports.useColors = useColors;
|
|
32569
|
+
exports.storage = typeof chrome != "undefined" && typeof chrome.storage != "undefined" ? chrome.storage.local : localstorage();
|
|
32570
|
+
exports.colors = [
|
|
32571
|
+
"lightseagreen",
|
|
32572
|
+
"forestgreen",
|
|
32573
|
+
"goldenrod",
|
|
32574
|
+
"dodgerblue",
|
|
32575
|
+
"darkorchid",
|
|
32576
|
+
"crimson"
|
|
32577
|
+
];
|
|
32578
|
+
function useColors() {
|
|
32579
|
+
if (typeof window !== "undefined" && window.process && window.process.type === "renderer") {
|
|
32580
|
+
return true;
|
|
32581
|
+
}
|
|
32582
|
+
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
32583
|
+
}
|
|
32584
|
+
exports.formatters.j = function(v) {
|
|
32585
|
+
try {
|
|
32586
|
+
return JSON.stringify(v);
|
|
32587
|
+
} catch (err2) {
|
|
32588
|
+
return "[UnexpectedJSONParseError]: " + err2.message;
|
|
32589
|
+
}
|
|
32590
|
+
};
|
|
32591
|
+
function formatArgs(args) {
|
|
32592
|
+
var useColors2 = this.useColors;
|
|
32593
|
+
args[0] = (useColors2 ? "%c" : "") + this.namespace + (useColors2 ? " %c" : " ") + args[0] + (useColors2 ? "%c " : " ") + "+" + exports.humanize(this.diff);
|
|
32594
|
+
if (!useColors2)
|
|
32595
|
+
return;
|
|
32596
|
+
var c = "color: " + this.color;
|
|
32597
|
+
args.splice(1, 0, c, "color: inherit");
|
|
32598
|
+
var index2 = 0;
|
|
32599
|
+
var lastC = 0;
|
|
32600
|
+
args[0].replace(/%[a-zA-Z%]/g, function(match) {
|
|
32601
|
+
if (match === "%%")
|
|
32602
|
+
return;
|
|
32603
|
+
index2++;
|
|
32604
|
+
if (match === "%c") {
|
|
32605
|
+
lastC = index2;
|
|
32606
|
+
}
|
|
32607
|
+
});
|
|
32608
|
+
args.splice(lastC, 0, c);
|
|
32609
|
+
}
|
|
32610
|
+
function log() {
|
|
32611
|
+
return typeof console === "object" && console.log && Function.prototype.apply.call(console.log, console, arguments);
|
|
32612
|
+
}
|
|
32613
|
+
function save(namespaces) {
|
|
32614
|
+
try {
|
|
32615
|
+
if (namespaces == null) {
|
|
32616
|
+
exports.storage.removeItem("debug");
|
|
32617
|
+
} else {
|
|
32618
|
+
exports.storage.debug = namespaces;
|
|
32619
|
+
}
|
|
32620
|
+
} catch (e) {}
|
|
32621
|
+
}
|
|
32622
|
+
function load() {
|
|
32623
|
+
var r;
|
|
32624
|
+
try {
|
|
32625
|
+
r = exports.storage.debug;
|
|
32626
|
+
} catch (e) {}
|
|
32627
|
+
if (!r && typeof process !== "undefined" && "env" in process) {
|
|
32628
|
+
r = process.env.DEBUG;
|
|
32629
|
+
}
|
|
32630
|
+
return r;
|
|
32631
|
+
}
|
|
32632
|
+
exports.enable(load());
|
|
32633
|
+
function localstorage() {
|
|
32634
|
+
try {
|
|
32635
|
+
return window.localStorage;
|
|
32636
|
+
} catch (e) {}
|
|
32637
|
+
}
|
|
32638
|
+
});
|
|
32639
|
+
|
|
32640
|
+
// node_modules/debug/src/node.js
|
|
32641
|
+
var require_node = __commonJS((exports, module) => {
|
|
32642
|
+
var tty = __require("tty");
|
|
32643
|
+
var util = __require("util");
|
|
32644
|
+
exports = module.exports = require_debug();
|
|
32645
|
+
exports.init = init;
|
|
32646
|
+
exports.log = log;
|
|
32647
|
+
exports.formatArgs = formatArgs;
|
|
32648
|
+
exports.save = save;
|
|
32649
|
+
exports.load = load;
|
|
32650
|
+
exports.useColors = useColors;
|
|
32651
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
32652
|
+
exports.inspectOpts = Object.keys(process.env).filter(function(key) {
|
|
32653
|
+
return /^debug_/i.test(key);
|
|
32654
|
+
}).reduce(function(obj, key) {
|
|
32655
|
+
var prop3 = key.substring(6).toLowerCase().replace(/_([a-z])/g, function(_, k) {
|
|
32656
|
+
return k.toUpperCase();
|
|
32657
|
+
});
|
|
32658
|
+
var val = process.env[key];
|
|
32659
|
+
if (/^(yes|on|true|enabled)$/i.test(val))
|
|
32660
|
+
val = true;
|
|
32661
|
+
else if (/^(no|off|false|disabled)$/i.test(val))
|
|
32662
|
+
val = false;
|
|
32663
|
+
else if (val === "null")
|
|
32664
|
+
val = null;
|
|
32665
|
+
else
|
|
32666
|
+
val = Number(val);
|
|
32667
|
+
obj[prop3] = val;
|
|
32668
|
+
return obj;
|
|
32669
|
+
}, {});
|
|
32670
|
+
var fd2 = parseInt(process.env.DEBUG_FD, 10) || 2;
|
|
32671
|
+
if (fd2 !== 1 && fd2 !== 2) {
|
|
32672
|
+
util.deprecate(function() {}, "except for stderr(2) and stdout(1), any other usage of DEBUG_FD is deprecated. Override debug.log if you want to use a different log function (https://git.io/debug_fd)")();
|
|
32673
|
+
}
|
|
32674
|
+
var stream = fd2 === 1 ? process.stdout : fd2 === 2 ? process.stderr : createWritableStdioStream(fd2);
|
|
32675
|
+
function useColors() {
|
|
32676
|
+
return "colors" in exports.inspectOpts ? Boolean(exports.inspectOpts.colors) : tty.isatty(fd2);
|
|
32677
|
+
}
|
|
32678
|
+
exports.formatters.o = function(v) {
|
|
32679
|
+
this.inspectOpts.colors = this.useColors;
|
|
32680
|
+
return util.inspect(v, this.inspectOpts).split(`
|
|
32681
|
+
`).map(function(str) {
|
|
32682
|
+
return str.trim();
|
|
32683
|
+
}).join(" ");
|
|
32684
|
+
};
|
|
32685
|
+
exports.formatters.O = function(v) {
|
|
32686
|
+
this.inspectOpts.colors = this.useColors;
|
|
32687
|
+
return util.inspect(v, this.inspectOpts);
|
|
32688
|
+
};
|
|
32689
|
+
function formatArgs(args) {
|
|
32690
|
+
var name = this.namespace;
|
|
32691
|
+
var useColors2 = this.useColors;
|
|
32692
|
+
if (useColors2) {
|
|
32693
|
+
var c = this.color;
|
|
32694
|
+
var prefix = " \x1B[3" + c + ";1m" + name + " " + "\x1B[0m";
|
|
32695
|
+
args[0] = prefix + args[0].split(`
|
|
32696
|
+
`).join(`
|
|
32697
|
+
` + prefix);
|
|
32698
|
+
args.push("\x1B[3" + c + "m+" + exports.humanize(this.diff) + "\x1B[0m");
|
|
32699
|
+
} else {
|
|
32700
|
+
args[0] = new Date().toUTCString() + " " + name + " " + args[0];
|
|
32701
|
+
}
|
|
32702
|
+
}
|
|
32703
|
+
function log() {
|
|
32704
|
+
return stream.write(util.format.apply(util, arguments) + `
|
|
32705
|
+
`);
|
|
32706
|
+
}
|
|
32707
|
+
function save(namespaces) {
|
|
32708
|
+
if (namespaces == null) {
|
|
32709
|
+
delete process.env.DEBUG;
|
|
32710
|
+
} else {
|
|
32711
|
+
process.env.DEBUG = namespaces;
|
|
32712
|
+
}
|
|
32713
|
+
}
|
|
32714
|
+
function load() {
|
|
32715
|
+
return process.env.DEBUG;
|
|
32716
|
+
}
|
|
32717
|
+
function createWritableStdioStream(fd3) {
|
|
32718
|
+
var stream2;
|
|
32719
|
+
var tty_wrap = process.binding("tty_wrap");
|
|
32720
|
+
switch (tty_wrap.guessHandleType(fd3)) {
|
|
32721
|
+
case "TTY":
|
|
32722
|
+
stream2 = new tty.WriteStream(fd3);
|
|
32723
|
+
stream2._type = "tty";
|
|
32724
|
+
if (stream2._handle && stream2._handle.unref) {
|
|
32725
|
+
stream2._handle.unref();
|
|
32726
|
+
}
|
|
32727
|
+
break;
|
|
32728
|
+
case "FILE":
|
|
32729
|
+
var fs = __require("fs");
|
|
32730
|
+
stream2 = new fs.SyncWriteStream(fd3, { autoClose: false });
|
|
32731
|
+
stream2._type = "fs";
|
|
32732
|
+
break;
|
|
32733
|
+
case "PIPE":
|
|
32734
|
+
case "TCP":
|
|
32735
|
+
var net = __require("net");
|
|
32736
|
+
stream2 = new net.Socket({
|
|
32737
|
+
fd: fd3,
|
|
32738
|
+
readable: false,
|
|
32739
|
+
writable: true
|
|
32740
|
+
});
|
|
32741
|
+
stream2.readable = false;
|
|
32742
|
+
stream2.read = null;
|
|
32743
|
+
stream2._type = "pipe";
|
|
32744
|
+
if (stream2._handle && stream2._handle.unref) {
|
|
32745
|
+
stream2._handle.unref();
|
|
32746
|
+
}
|
|
32747
|
+
break;
|
|
32748
|
+
default:
|
|
32749
|
+
throw new Error("Implement me. Unknown stream file type!");
|
|
32750
|
+
}
|
|
32751
|
+
stream2.fd = fd3;
|
|
32752
|
+
stream2._isStdio = true;
|
|
32753
|
+
return stream2;
|
|
32754
|
+
}
|
|
32755
|
+
function init(debug) {
|
|
32756
|
+
debug.inspectOpts = {};
|
|
32757
|
+
var keys2 = Object.keys(exports.inspectOpts);
|
|
32758
|
+
for (var i2 = 0;i2 < keys2.length; i2++) {
|
|
32759
|
+
debug.inspectOpts[keys2[i2]] = exports.inspectOpts[keys2[i2]];
|
|
32760
|
+
}
|
|
32761
|
+
}
|
|
32762
|
+
exports.enable(load());
|
|
32763
|
+
});
|
|
32764
|
+
|
|
32765
|
+
// node_modules/debug/src/index.js
|
|
32766
|
+
var require_src4 = __commonJS((exports, module) => {
|
|
32767
|
+
if (typeof process !== "undefined" && process.type === "renderer") {
|
|
32768
|
+
module.exports = require_browser();
|
|
32769
|
+
} else {
|
|
32770
|
+
module.exports = require_node();
|
|
32771
|
+
}
|
|
32772
|
+
});
|
|
32773
|
+
|
|
32774
|
+
// node_modules/follow-redirects/debug.js
|
|
32775
|
+
var require_debug2 = __commonJS((exports, module) => {
|
|
35197
32776
|
var debug;
|
|
35198
32777
|
module.exports = function() {
|
|
35199
32778
|
if (!debug) {
|
|
35200
32779
|
try {
|
|
35201
|
-
debug = (
|
|
32780
|
+
debug = require_src4()("follow-redirects");
|
|
35202
32781
|
} catch (error) {}
|
|
35203
32782
|
if (typeof debug !== "function") {
|
|
35204
32783
|
debug = function() {};
|
|
@@ -35216,7 +32795,7 @@ var require_follow_redirects = __commonJS((exports, module) => {
|
|
|
35216
32795
|
var https = __require("https");
|
|
35217
32796
|
var Writable = __require("stream").Writable;
|
|
35218
32797
|
var assert4 = __require("assert");
|
|
35219
|
-
var debug =
|
|
32798
|
+
var debug = require_debug2();
|
|
35220
32799
|
(function detectUnsupportedEnvironment() {
|
|
35221
32800
|
var looksLikeNode = typeof process !== "undefined";
|
|
35222
32801
|
var looksLikeBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
@@ -52256,7 +49835,7 @@ var Base64 = {
|
|
|
52256
49835
|
if (decoder === undefined) {
|
|
52257
49836
|
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
52258
49837
|
const ignore = `= \f
|
|
52259
|
-
\r
|
|
49838
|
+
\r \xA0\u2028\u2029`;
|
|
52260
49839
|
decoder = Object.create(null);
|
|
52261
49840
|
for (i = 0;i < 64; ++i) {
|
|
52262
49841
|
decoder[b64.charAt(i)] = i;
|
|
@@ -52393,7 +49972,7 @@ class Int10 {
|
|
|
52393
49972
|
}
|
|
52394
49973
|
|
|
52395
49974
|
// node_modules/@usherlabs/ccxt/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js
|
|
52396
|
-
var ellipsis = "
|
|
49975
|
+
var ellipsis = "\u2026";
|
|
52397
49976
|
var reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
|
|
52398
49977
|
var reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
|
|
52399
49978
|
function stringCut(str, len) {
|
|
@@ -55673,13 +53252,8 @@ class Precise {
|
|
|
55673
53252
|
}
|
|
55674
53253
|
var Precise_default = Precise;
|
|
55675
53254
|
|
|
55676
|
-
// node_modules/ws/
|
|
55677
|
-
|
|
55678
|
-
var import_receiver = __toESM(require_receiver(), 1);
|
|
55679
|
-
var import_sender = __toESM(require_sender(), 1);
|
|
55680
|
-
var import_websocket = __toESM(require_websocket(), 1);
|
|
55681
|
-
var import_websocket_server = __toESM(require_websocket_server(), 1);
|
|
55682
|
-
var wrapper_default = import_websocket.default;
|
|
53255
|
+
// node_modules/@usherlabs/ccxt/js/src/base/ws/WsClient.js
|
|
53256
|
+
import WebSocket from "ws";
|
|
55683
53257
|
|
|
55684
53258
|
// node_modules/@usherlabs/ccxt/js/src/static_dependencies/fflake/browser.js
|
|
55685
53259
|
var u8 = Uint8Array;
|
|
@@ -56441,7 +54015,7 @@ class Client {
|
|
|
56441
54015
|
}
|
|
56442
54016
|
|
|
56443
54017
|
// node_modules/@usherlabs/ccxt/js/src/base/ws/WsClient.js
|
|
56444
|
-
var WebSocketPlatform = isNode || !selfIsDefined() ?
|
|
54018
|
+
var WebSocketPlatform = isNode || !selfIsDefined() ? WebSocket : self.WebSocket;
|
|
56445
54019
|
|
|
56446
54020
|
class WsClient extends Client {
|
|
56447
54021
|
constructor() {
|
|
@@ -71356,7 +68930,7 @@ class Exchange {
|
|
|
71356
68930
|
}
|
|
71357
68931
|
async loadHttpProxyAgent() {
|
|
71358
68932
|
if (!this.httpAgent) {
|
|
71359
|
-
const httpModule = await import("
|
|
68933
|
+
const httpModule = await import("http");
|
|
71360
68934
|
this.httpAgent = new httpModule.Agent;
|
|
71361
68935
|
}
|
|
71362
68936
|
return this.httpAgent;
|
|
@@ -71376,7 +68950,7 @@ class Exchange {
|
|
|
71376
68950
|
if (isNode2) {
|
|
71377
68951
|
if (!this.nodeHttpModuleLoaded) {
|
|
71378
68952
|
this.nodeHttpModuleLoaded = true;
|
|
71379
|
-
const httpsModule = await import("
|
|
68953
|
+
const httpsModule = await import("https");
|
|
71380
68954
|
this.httpsAgent = new httpsModule.Agent({ keepAlive: true });
|
|
71381
68955
|
}
|
|
71382
68956
|
}
|
|
@@ -83636,7 +81210,7 @@ var Hex = {
|
|
|
83636
81210
|
if (decoder2 === undefined) {
|
|
83637
81211
|
let hex2 = "0123456789ABCDEF";
|
|
83638
81212
|
const ignore = ` \f
|
|
83639
|
-
\r
|
|
81213
|
+
\r \xA0\u2028\u2029`;
|
|
83640
81214
|
decoder2 = {};
|
|
83641
81215
|
for (i2 = 0;i2 < 16; ++i2) {
|
|
83642
81216
|
decoder2[hex2.charAt(i2)] = i2;
|
|
@@ -97074,7 +94648,7 @@ class binanceusdm extends binance {
|
|
|
97074
94648
|
describe() {
|
|
97075
94649
|
return this.deepExtend(super.describe(), {
|
|
97076
94650
|
id: "binanceusdm",
|
|
97077
|
-
name: "Binance USD
|
|
94651
|
+
name: "Binance USD\u24C8-M",
|
|
97078
94652
|
urls: {
|
|
97079
94653
|
logo: "https://github.com/user-attachments/assets/871cbea7-eebb-4b28-b260-c1c91df0487a",
|
|
97080
94654
|
doc: [
|
|
@@ -111409,7 +108983,7 @@ class bithumb extends bithumb_default {
|
|
|
111409
108983
|
if (status !== undefined) {
|
|
111410
108984
|
if (status === "0000") {
|
|
111411
108985
|
return;
|
|
111412
|
-
} else if (message === "
|
|
108986
|
+
} else if (message === "\uAC70\uB798 \uC9C4\uD589\uC911\uC778 \uB0B4\uC5ED\uC774 \uC874\uC7AC\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.") {
|
|
111413
108987
|
return;
|
|
111414
108988
|
}
|
|
111415
108989
|
const feedback = this.id + " " + message;
|
|
@@ -206758,7 +204332,7 @@ class okx extends okx_default {
|
|
|
206758
204332
|
const targetNetwork = this.safeDict(currency["networks"], this.networkIdToCode(network), {});
|
|
206759
204333
|
fee = this.safeString(targetNetwork, "fee");
|
|
206760
204334
|
if (fee === undefined) {
|
|
206761
|
-
throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be
|
|
204335
|
+
throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be \u2265 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.');
|
|
206762
204336
|
}
|
|
206763
204337
|
}
|
|
206764
204338
|
request["fee"] = this.numberToString(fee);
|
|
@@ -213254,7 +210828,7 @@ class okcoin extends okcoin_default {
|
|
|
213254
210828
|
const targetNetwork = this.safeValue(currency["networks"], this.networkIdToCode(network), {});
|
|
213255
210829
|
fee = this.safeString(targetNetwork, "fee");
|
|
213256
210830
|
if (fee === undefined) {
|
|
213257
|
-
throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be
|
|
210831
|
+
throw new ArgumentsRequired(this.id + ' withdraw() requires a "fee" string parameter, network transaction fee must be \u2265 0. Withdrawals to OKCoin or OKX are fee-free, please set "0". Withdrawing to external digital asset address requires network transaction fee.');
|
|
213258
210832
|
}
|
|
213259
210833
|
}
|
|
213260
210834
|
request["fee"] = this.numberToString(fee);
|
|
@@ -248697,7 +246271,7 @@ class binanceusdm2 extends binance2 {
|
|
|
248697
246271
|
describe() {
|
|
248698
246272
|
return this.deepExtend(super.describe(), {
|
|
248699
246273
|
id: "binanceusdm",
|
|
248700
|
-
name: "Binance USD
|
|
246274
|
+
name: "Binance USD\u24C8-M",
|
|
248701
246275
|
urls: {
|
|
248702
246276
|
logo: "https://user-images.githubusercontent.com/1294454/117738721-668c8d80-b205-11eb-8c49-3fad84c4a07f.jpg",
|
|
248703
246277
|
doc: "https://developers.binance.com/en"
|
|
@@ -287143,7 +284717,7 @@ class BaseLogger {
|
|
|
287143
284717
|
{{errorName}} {{errorMessage}}
|
|
287144
284718
|
error stack:
|
|
287145
284719
|
{{errorStack}}`,
|
|
287146
|
-
prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? `
|
|
284720
|
+
prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? ` \u2022 {{fileName}} {{method}}
|
|
287147
284721
|
{{filePathWithLine}}`,
|
|
287148
284722
|
prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
|
|
287149
284723
|
prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
|
|
@@ -287614,9 +285188,8 @@ function validateOrder(policy, fromToken, toToken, amount, broker) {
|
|
|
287614
285188
|
// src/server.ts
|
|
287615
285189
|
var grpc = __toESM(require_src3(), 1);
|
|
287616
285190
|
var protoLoader = __toESM(require_src2(), 1);
|
|
287617
|
-
import path from "path";
|
|
287618
285191
|
|
|
287619
|
-
// proto/
|
|
285192
|
+
// proto/cex_broker/Action.ts
|
|
287620
285193
|
var Action = {
|
|
287621
285194
|
NoAction: 0,
|
|
287622
285195
|
Deposit: 1,
|
|
@@ -287628,7 +285201,7 @@ var Action = {
|
|
|
287628
285201
|
FetchDepositAddresses: 7
|
|
287629
285202
|
};
|
|
287630
285203
|
|
|
287631
|
-
// proto/
|
|
285204
|
+
// proto/cex_broker/SubscriptionType.ts
|
|
287632
285205
|
var SubscriptionType = {
|
|
287633
285206
|
ORDERBOOK: 0,
|
|
287634
285207
|
TRADES: 1,
|
|
@@ -287640,14 +285213,13 @@ var SubscriptionType = {
|
|
|
287640
285213
|
|
|
287641
285214
|
// src/server.ts
|
|
287642
285215
|
var import_joi2 = __toESM(require_lib4(), 1);
|
|
287643
|
-
var
|
|
287644
|
-
var
|
|
287645
|
-
var packageDef = protoLoader.loadSync(path.resolve(__dirname, PROTO_FILE));
|
|
285216
|
+
var PROTO_FILE = "./proto/node.proto";
|
|
285217
|
+
var packageDef = protoLoader.loadSync(PROTO_FILE);
|
|
287646
285218
|
var grpcObj = grpc.loadPackageDefinition(packageDef);
|
|
287647
|
-
var cexNode = grpcObj.
|
|
285219
|
+
var cexNode = grpcObj.cex_broker;
|
|
287648
285220
|
function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
287649
285221
|
const server = new grpc.Server;
|
|
287650
|
-
server.addService(cexNode.
|
|
285222
|
+
server.addService(cexNode.cex_service.service, {
|
|
287651
285223
|
ExecuteAction: async (call, callback) => {
|
|
287652
285224
|
if (!authenticateRequest(call, whitelistIps)) {
|
|
287653
285225
|
return callback({
|
|
@@ -287675,7 +285247,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287675
285247
|
const transactionSchema = import_joi2.default.object({
|
|
287676
285248
|
recipientAddress: import_joi2.default.string().required(),
|
|
287677
285249
|
amount: import_joi2.default.number().positive().required(),
|
|
287678
|
-
transactionHash: import_joi2.default.string().required()
|
|
285250
|
+
transactionHash: import_joi2.default.string().required(),
|
|
285251
|
+
since: import_joi2.default.number(),
|
|
285252
|
+
params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
|
|
287679
285253
|
});
|
|
287680
285254
|
const { value, error } = transactionSchema.validate(call.request.payload ?? {});
|
|
287681
285255
|
if (error) {
|
|
@@ -287685,7 +285259,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287685
285259
|
}, null);
|
|
287686
285260
|
}
|
|
287687
285261
|
try {
|
|
287688
|
-
const deposits = await broker.fetchDeposits(symbol, 50);
|
|
285262
|
+
const deposits = await broker.fetchDeposits(symbol, value.since, 50, { ...value.params ?? {} });
|
|
287689
285263
|
const deposit = deposits.find((deposit2) => deposit2.id === value.transactionHash || deposit2.txid === value.transactionHash);
|
|
287690
285264
|
if (deposit) {
|
|
287691
285265
|
log.info(`Amount ${value.amount} at ${value.transactionHash} . Paid to ${value.recipientAddress}`);
|
|
@@ -287708,7 +285282,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287708
285282
|
}
|
|
287709
285283
|
case Action.FetchDepositAddresses: {
|
|
287710
285284
|
const fetchDepositAddressesSchema = import_joi2.default.object({
|
|
287711
|
-
chain: import_joi2.default.string().required()
|
|
285285
|
+
chain: import_joi2.default.string().required(),
|
|
285286
|
+
params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
|
|
287712
285287
|
});
|
|
287713
285288
|
const {
|
|
287714
285289
|
value: fetchDepositAddresses,
|
|
@@ -287722,9 +285297,11 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287722
285297
|
}
|
|
287723
285298
|
try {
|
|
287724
285299
|
const depositAddresses = broker.has.fetchDepositAddress === true ? await broker.fetchDepositAddress(symbol, {
|
|
287725
|
-
network: fetchDepositAddresses.chain
|
|
285300
|
+
network: fetchDepositAddresses.chain,
|
|
285301
|
+
...fetchDepositAddresses.params ?? {}
|
|
287726
285302
|
}) : await broker.fetchDepositAddressesByNetwork(symbol, {
|
|
287727
|
-
network: fetchDepositAddresses.chain
|
|
285303
|
+
network: fetchDepositAddresses.chain,
|
|
285304
|
+
...fetchDepositAddresses.params ?? {}
|
|
287728
285305
|
});
|
|
287729
285306
|
if (depositAddresses) {
|
|
287730
285307
|
return callback(null, {
|
|
@@ -287749,7 +285326,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287749
285326
|
const transferSchema = import_joi2.default.object({
|
|
287750
285327
|
recipientAddress: import_joi2.default.string().required(),
|
|
287751
285328
|
amount: import_joi2.default.number().positive().required(),
|
|
287752
|
-
chain: import_joi2.default.string().required()
|
|
285329
|
+
chain: import_joi2.default.string().required(),
|
|
285330
|
+
params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
|
|
287753
285331
|
});
|
|
287754
285332
|
const { value: transferValue, error: transferError } = transferSchema.validate(call.request.payload ?? {});
|
|
287755
285333
|
if (transferError) {
|
|
@@ -287794,7 +285372,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287794
285372
|
amount: import_joi2.default.number().positive().required(),
|
|
287795
285373
|
fromToken: import_joi2.default.string().required(),
|
|
287796
285374
|
toToken: import_joi2.default.string().required(),
|
|
287797
|
-
price: import_joi2.default.number().positive().required()
|
|
285375
|
+
price: import_joi2.default.number().positive().required(),
|
|
285376
|
+
params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
|
|
287798
285377
|
});
|
|
287799
285378
|
const { value: orderValue, error: orderError } = createOrderSchema.validate(call.request.payload ?? {});
|
|
287800
285379
|
if (orderError) {
|
|
@@ -287820,7 +285399,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287820
285399
|
message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
|
|
287821
285400
|
}, null);
|
|
287822
285401
|
}
|
|
287823
|
-
const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price));
|
|
285402
|
+
const order = await broker.createOrder(symbol2, orderValue.orderType, from === orderValue.fromToken ? "sell" : "buy", Number(orderValue.amount), Number(orderValue.price), orderValue.params ?? {});
|
|
287824
285403
|
callback(null, { result: JSON.stringify({ ...order }) });
|
|
287825
285404
|
} catch (error) {
|
|
287826
285405
|
log.error({ error });
|
|
@@ -287833,7 +285412,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287833
285412
|
}
|
|
287834
285413
|
case Action.GetOrderDetails: {
|
|
287835
285414
|
const getOrderSchema = import_joi2.default.object({
|
|
287836
|
-
orderId: import_joi2.default.string().required()
|
|
285415
|
+
orderId: import_joi2.default.string().required(),
|
|
285416
|
+
params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
|
|
287837
285417
|
});
|
|
287838
285418
|
const { value: getOrderValue, error: getOrderError } = getOrderSchema.validate(call.request.payload ?? {});
|
|
287839
285419
|
if (getOrderError) {
|
|
@@ -287849,7 +285429,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287849
285429
|
message: `Invalid CEX key: ${cex3}. Supported keys: ${Object.keys(brokers).join(", ")}`
|
|
287850
285430
|
}, null);
|
|
287851
285431
|
}
|
|
287852
|
-
const orderDetails = await broker.fetchOrder(getOrderValue.orderId);
|
|
285432
|
+
const orderDetails = await broker.fetchOrder(getOrderValue.orderId, { ...getOrderValue.params });
|
|
287853
285433
|
callback(null, {
|
|
287854
285434
|
result: JSON.stringify({
|
|
287855
285435
|
orderId: orderDetails.id,
|
|
@@ -287872,7 +285452,8 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287872
285452
|
}
|
|
287873
285453
|
case Action.CancelOrder: {
|
|
287874
285454
|
const cancelOrderSchema = import_joi2.default.object({
|
|
287875
|
-
orderId: import_joi2.default.string().required()
|
|
285455
|
+
orderId: import_joi2.default.string().required(),
|
|
285456
|
+
params: import_joi2.default.object().pattern(import_joi2.default.string(), import_joi2.default.string()).default({})
|
|
287876
285457
|
});
|
|
287877
285458
|
const { value: cancelOrderValue, error: cancelOrderError } = cancelOrderSchema.validate(call.request.payload ?? {});
|
|
287878
285459
|
if (cancelOrderError) {
|
|
@@ -287881,7 +285462,7 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287881
285462
|
message: `ValidationError: ${cancelOrderError.message}`
|
|
287882
285463
|
}, null);
|
|
287883
285464
|
}
|
|
287884
|
-
const cancelledOrder = await broker.cancelOrder(cancelOrderValue.orderId);
|
|
285465
|
+
const cancelledOrder = await broker.cancelOrder(cancelOrderValue.orderId, cancelOrderValue.params ?? {});
|
|
287885
285466
|
callback(null, {
|
|
287886
285467
|
result: JSON.stringify({ ...cancelledOrder })
|
|
287887
285468
|
});
|
|
@@ -287889,7 +285470,9 @@ function getServer(policy, brokers, whitelistIps, useVerity, verityProverUrl) {
|
|
|
287889
285470
|
}
|
|
287890
285471
|
case Action.FetchBalance:
|
|
287891
285472
|
try {
|
|
287892
|
-
const balance = await broker.fetchFreeBalance(
|
|
285473
|
+
const balance = await broker.fetchFreeBalance({
|
|
285474
|
+
...call.request.payload ?? {}
|
|
285475
|
+
});
|
|
287893
285476
|
const currencyBalance = balance[symbol];
|
|
287894
285477
|
callback(null, {
|
|
287895
285478
|
result: useVerity ? broker.last_proof : JSON.stringify({
|
|
@@ -288280,7 +285863,7 @@ class CEXBroker {
|
|
|
288280
285863
|
}
|
|
288281
285864
|
match = key.match(/^CEX_BROKER_(\w+)_API_(KEY|SECRET)$/);
|
|
288282
285865
|
if (!match) {
|
|
288283
|
-
log.warn(
|
|
285866
|
+
log.warn(`\u26A0\uFE0F Skipping unrecognized env var: ${key}`);
|
|
288284
285867
|
continue;
|
|
288285
285868
|
}
|
|
288286
285869
|
const broker = match[1]?.toLowerCase() ?? "";
|
|
@@ -288295,7 +285878,7 @@ class CEXBroker {
|
|
|
288295
285878
|
}
|
|
288296
285879
|
}
|
|
288297
285880
|
if (Object.keys(configMap).length === 0) {
|
|
288298
|
-
log.error(
|
|
285881
|
+
log.error(`\u274C NO CEX Broker Key Found`);
|
|
288299
285882
|
}
|
|
288300
285883
|
for (const [broker, creds] of Object.entries(configMap)) {
|
|
288301
285884
|
const hasKey = !!creds.apiKey;
|
|
@@ -288315,7 +285898,7 @@ class CEXBroker {
|
|
|
288315
285898
|
apiKey: sec.apiKey,
|
|
288316
285899
|
apiSecret: sec.apiSecret
|
|
288317
285900
|
};
|
|
288318
|
-
|
|
285901
|
+
const exchange = new ExchangeClass({
|
|
288319
285902
|
apiKey: sec.apiKey,
|
|
288320
285903
|
secret: sec.apiSecret,
|
|
288321
285904
|
enableRateLimit: true,
|
|
@@ -288328,8 +285911,9 @@ class CEXBroker {
|
|
|
288328
285911
|
recvWindow: 60000
|
|
288329
285912
|
}
|
|
288330
285913
|
});
|
|
285914
|
+
secondaryBrokers[+index2] = exchange;
|
|
288331
285915
|
} else {
|
|
288332
|
-
log.warn(
|
|
285916
|
+
log.warn(`\u26A0\uFE0F Incomplete secondary credentials for broker "${broker}" at index ${index2}`);
|
|
288333
285917
|
}
|
|
288334
285918
|
}
|
|
288335
285919
|
}
|
|
@@ -288338,7 +285922,7 @@ class CEXBroker {
|
|
|
288338
285922
|
apiSecret: creds.apiSecret ?? "",
|
|
288339
285923
|
secondaryKeys
|
|
288340
285924
|
};
|
|
288341
|
-
log.info(
|
|
285925
|
+
log.info(`\u2705 Loaded credentials for broker "${broker}"`);
|
|
288342
285926
|
const client = new ExchangeClass({
|
|
288343
285927
|
apiKey: creds.apiKey,
|
|
288344
285928
|
secret: creds.apiSecret,
|
|
@@ -288362,7 +285946,7 @@ class CEXBroker {
|
|
|
288362
285946
|
missing.push("API_KEY");
|
|
288363
285947
|
if (!hasSecret)
|
|
288364
285948
|
missing.push("API_SECRET");
|
|
288365
|
-
log.warn(
|
|
285949
|
+
log.warn(`\u274C Missing ${missing.join(" and ")} for broker "${broker}"`);
|
|
288366
285950
|
}
|
|
288367
285951
|
}
|
|
288368
285952
|
}
|
|
@@ -288384,7 +285968,7 @@ class CEXBroker {
|
|
|
288384
285968
|
if (!ExchangeClass) {
|
|
288385
285969
|
throw new Error(`Invalid Broker : ${broker}`);
|
|
288386
285970
|
}
|
|
288387
|
-
log.info(
|
|
285971
|
+
log.info(`\u2705 Loaded credentials for broker "${broker}" (${1 + (creds2.secondaryKeys?.length || 0)} key sets)`);
|
|
288388
285972
|
const secondaryBroker = [];
|
|
288389
285973
|
for (const index2 of Object.keys(creds2.secondaryKeys)) {
|
|
288390
285974
|
const sec = creds2.secondaryKeys[+index2];
|
|
@@ -288403,7 +285987,7 @@ class CEXBroker {
|
|
|
288403
285987
|
}
|
|
288404
285988
|
});
|
|
288405
285989
|
} else {
|
|
288406
|
-
log.warn(
|
|
285990
|
+
log.warn(`\u26A0\uFE0F Incomplete secondary credentials for broker "${broker}" at index ${index2}`);
|
|
288407
285991
|
}
|
|
288408
285992
|
}
|
|
288409
285993
|
this.#brokerConfig[broker] = {
|