@rspack/dev-server 2.0.0-rc.1 → 2.0.0-rc.3
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/client/modules/logger/Logger.d.ts +3 -4
- package/client/modules/logger/Logger.js +9 -11
- package/client/modules/logger/index.d.ts +9 -1
- package/client/modules/logger/index.js +4 -5
- package/client/type.js +1 -0
- package/client/utils/ansiHTML.js +1 -1
- package/dist/0~chokidar.js +1477 -0
- package/dist/0~chokidar.js.LICENSE.txt +1 -0
- package/dist/0~connect-history-api-fallback.js +2 -2
- package/dist/0~connect-next.js +1245 -0
- package/dist/0~connect-next.js.LICENSE.txt +57 -0
- package/dist/0~debug.js +2 -2
- package/dist/0~http-proxy-middleware.js +238 -24
- package/dist/0~launch-editor.js +2 -2
- package/dist/0~open.js +11 -7
- package/dist/0~p-retry.js +8 -5
- package/dist/0~serve-static.js +2 -2
- package/dist/{621.js → 937.js} +2474 -8
- package/dist/index.d.ts +587 -2
- package/dist/index.js +1 -1
- package/package.json +20 -21
- package/dist/config.d.ts +0 -22
- package/dist/getPort.d.ts +0 -13
- package/dist/server.d.ts +0 -74
- package/dist/servers/BaseServer.d.ts +0 -17
- package/dist/servers/WebsocketServer.d.ts +0 -17
- package/dist/types.d.ts +0 -73
package/dist/{621.js → 937.js}
RENAMED
|
@@ -8,7 +8,6 @@ import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
|
8
8
|
import * as __rspack_external_node_url_e96de089 from "node:url";
|
|
9
9
|
import * as __rspack_external_node_util_1b29d436 from "node:util";
|
|
10
10
|
import * as __rspack_external_node_net_0373943e from "node:net";
|
|
11
|
-
import * as __rspack_external_ws from "ws";
|
|
12
11
|
var __webpack_modules__ = {};
|
|
13
12
|
var __webpack_module_cache__ = {};
|
|
14
13
|
function __webpack_require__(moduleId) {
|
|
@@ -87,7 +86,7 @@ var __webpack_require__temp = __webpack_require__;
|
|
|
87
86
|
(()=>{
|
|
88
87
|
var installedChunks = {
|
|
89
88
|
410: 0,
|
|
90
|
-
|
|
89
|
+
937: 0
|
|
91
90
|
};
|
|
92
91
|
var installChunk = (data)=>{
|
|
93
92
|
var __rspack_esm_ids = data.__rspack_esm_ids;
|
|
@@ -105,7 +104,7 @@ var __webpack_require__temp = __webpack_require__;
|
|
|
105
104
|
__webpack_require__.C = installChunk;
|
|
106
105
|
})();
|
|
107
106
|
__webpack_require__.add({
|
|
108
|
-
"./node_modules/.pnpm/http-compression@1.1.
|
|
107
|
+
"./node_modules/.pnpm/http-compression@1.1.3/node_modules/http-compression/src/index.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
109
108
|
const zlib = __webpack_require__("zlib");
|
|
110
109
|
const MIMES = /text|javascript|\/json|xml/i;
|
|
111
110
|
const noop = ()=>{};
|
|
@@ -1255,18 +1254,2471 @@ __webpack_require__.add({
|
|
|
1255
1254
|
else root.ipaddr = ipaddr;
|
|
1256
1255
|
})(this);
|
|
1257
1256
|
},
|
|
1257
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
1258
|
+
const { EMPTY_BUFFER } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
1259
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
1260
|
+
function concat(list, totalLength) {
|
|
1261
|
+
if (0 === list.length) return EMPTY_BUFFER;
|
|
1262
|
+
if (1 === list.length) return list[0];
|
|
1263
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
1264
|
+
let offset = 0;
|
|
1265
|
+
for(let i = 0; i < list.length; i++){
|
|
1266
|
+
const buf = list[i];
|
|
1267
|
+
target.set(buf, offset);
|
|
1268
|
+
offset += buf.length;
|
|
1269
|
+
}
|
|
1270
|
+
if (offset < totalLength) return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
1271
|
+
return target;
|
|
1272
|
+
}
|
|
1273
|
+
function _mask(source, mask, output, offset, length) {
|
|
1274
|
+
for(let i = 0; i < length; i++)output[offset + i] = source[i] ^ mask[3 & i];
|
|
1275
|
+
}
|
|
1276
|
+
function _unmask(buffer, mask) {
|
|
1277
|
+
for(let i = 0; i < buffer.length; i++)buffer[i] ^= mask[3 & i];
|
|
1278
|
+
}
|
|
1279
|
+
function toArrayBuffer(buf) {
|
|
1280
|
+
if (buf.length === buf.buffer.byteLength) return buf.buffer;
|
|
1281
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
1282
|
+
}
|
|
1283
|
+
function toBuffer(data) {
|
|
1284
|
+
toBuffer.readOnly = true;
|
|
1285
|
+
if (Buffer.isBuffer(data)) return data;
|
|
1286
|
+
let buf;
|
|
1287
|
+
if (data instanceof ArrayBuffer) buf = new FastBuffer(data);
|
|
1288
|
+
else if (ArrayBuffer.isView(data)) buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
1289
|
+
else {
|
|
1290
|
+
buf = Buffer.from(data);
|
|
1291
|
+
toBuffer.readOnly = false;
|
|
1292
|
+
}
|
|
1293
|
+
return buf;
|
|
1294
|
+
}
|
|
1295
|
+
module.exports = {
|
|
1296
|
+
concat,
|
|
1297
|
+
mask: _mask,
|
|
1298
|
+
toArrayBuffer,
|
|
1299
|
+
toBuffer,
|
|
1300
|
+
unmask: _unmask
|
|
1301
|
+
};
|
|
1302
|
+
},
|
|
1303
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js" (module) {
|
|
1304
|
+
const BINARY_TYPES = [
|
|
1305
|
+
'nodebuffer',
|
|
1306
|
+
'arraybuffer',
|
|
1307
|
+
'fragments'
|
|
1308
|
+
];
|
|
1309
|
+
const hasBlob = "u" > typeof Blob;
|
|
1310
|
+
if (hasBlob) BINARY_TYPES.push('blob');
|
|
1311
|
+
module.exports = {
|
|
1312
|
+
BINARY_TYPES,
|
|
1313
|
+
CLOSE_TIMEOUT: 30000,
|
|
1314
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
1315
|
+
GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
|
|
1316
|
+
hasBlob,
|
|
1317
|
+
kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
|
|
1318
|
+
kListener: Symbol('kListener'),
|
|
1319
|
+
kStatusCode: Symbol('status-code'),
|
|
1320
|
+
kWebSocket: Symbol('websocket'),
|
|
1321
|
+
NOOP: ()=>{}
|
|
1322
|
+
};
|
|
1323
|
+
},
|
|
1324
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/event-target.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
1325
|
+
const { kForOnEventAttribute, kListener } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
1326
|
+
const kCode = Symbol('kCode');
|
|
1327
|
+
const kData = Symbol('kData');
|
|
1328
|
+
const kError = Symbol('kError');
|
|
1329
|
+
const kMessage = Symbol('kMessage');
|
|
1330
|
+
const kReason = Symbol('kReason');
|
|
1331
|
+
const kTarget = Symbol('kTarget');
|
|
1332
|
+
const kType = Symbol('kType');
|
|
1333
|
+
const kWasClean = Symbol('kWasClean');
|
|
1334
|
+
class Event {
|
|
1335
|
+
constructor(type){
|
|
1336
|
+
this[kTarget] = null;
|
|
1337
|
+
this[kType] = type;
|
|
1338
|
+
}
|
|
1339
|
+
get target() {
|
|
1340
|
+
return this[kTarget];
|
|
1341
|
+
}
|
|
1342
|
+
get type() {
|
|
1343
|
+
return this[kType];
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
Object.defineProperty(Event.prototype, 'target', {
|
|
1347
|
+
enumerable: true
|
|
1348
|
+
});
|
|
1349
|
+
Object.defineProperty(Event.prototype, 'type', {
|
|
1350
|
+
enumerable: true
|
|
1351
|
+
});
|
|
1352
|
+
class CloseEvent extends Event {
|
|
1353
|
+
constructor(type, options = {}){
|
|
1354
|
+
super(type);
|
|
1355
|
+
this[kCode] = void 0 === options.code ? 0 : options.code;
|
|
1356
|
+
this[kReason] = void 0 === options.reason ? '' : options.reason;
|
|
1357
|
+
this[kWasClean] = void 0 === options.wasClean ? false : options.wasClean;
|
|
1358
|
+
}
|
|
1359
|
+
get code() {
|
|
1360
|
+
return this[kCode];
|
|
1361
|
+
}
|
|
1362
|
+
get reason() {
|
|
1363
|
+
return this[kReason];
|
|
1364
|
+
}
|
|
1365
|
+
get wasClean() {
|
|
1366
|
+
return this[kWasClean];
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
Object.defineProperty(CloseEvent.prototype, 'code', {
|
|
1370
|
+
enumerable: true
|
|
1371
|
+
});
|
|
1372
|
+
Object.defineProperty(CloseEvent.prototype, 'reason', {
|
|
1373
|
+
enumerable: true
|
|
1374
|
+
});
|
|
1375
|
+
Object.defineProperty(CloseEvent.prototype, 'wasClean', {
|
|
1376
|
+
enumerable: true
|
|
1377
|
+
});
|
|
1378
|
+
class ErrorEvent extends Event {
|
|
1379
|
+
constructor(type, options = {}){
|
|
1380
|
+
super(type);
|
|
1381
|
+
this[kError] = void 0 === options.error ? null : options.error;
|
|
1382
|
+
this[kMessage] = void 0 === options.message ? '' : options.message;
|
|
1383
|
+
}
|
|
1384
|
+
get error() {
|
|
1385
|
+
return this[kError];
|
|
1386
|
+
}
|
|
1387
|
+
get message() {
|
|
1388
|
+
return this[kMessage];
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
Object.defineProperty(ErrorEvent.prototype, 'error', {
|
|
1392
|
+
enumerable: true
|
|
1393
|
+
});
|
|
1394
|
+
Object.defineProperty(ErrorEvent.prototype, 'message', {
|
|
1395
|
+
enumerable: true
|
|
1396
|
+
});
|
|
1397
|
+
class MessageEvent extends Event {
|
|
1398
|
+
constructor(type, options = {}){
|
|
1399
|
+
super(type);
|
|
1400
|
+
this[kData] = void 0 === options.data ? null : options.data;
|
|
1401
|
+
}
|
|
1402
|
+
get data() {
|
|
1403
|
+
return this[kData];
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
Object.defineProperty(MessageEvent.prototype, 'data', {
|
|
1407
|
+
enumerable: true
|
|
1408
|
+
});
|
|
1409
|
+
const EventTarget = {
|
|
1410
|
+
addEventListener (type, handler, options = {}) {
|
|
1411
|
+
for (const listener of this.listeners(type))if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) return;
|
|
1412
|
+
let wrapper;
|
|
1413
|
+
if ('message' === type) wrapper = function(data, isBinary) {
|
|
1414
|
+
const event = new MessageEvent('message', {
|
|
1415
|
+
data: isBinary ? data : data.toString()
|
|
1416
|
+
});
|
|
1417
|
+
event[kTarget] = this;
|
|
1418
|
+
callListener(handler, this, event);
|
|
1419
|
+
};
|
|
1420
|
+
else if ('close' === type) wrapper = function(code, message) {
|
|
1421
|
+
const event = new CloseEvent('close', {
|
|
1422
|
+
code,
|
|
1423
|
+
reason: message.toString(),
|
|
1424
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
1425
|
+
});
|
|
1426
|
+
event[kTarget] = this;
|
|
1427
|
+
callListener(handler, this, event);
|
|
1428
|
+
};
|
|
1429
|
+
else if ('error' === type) wrapper = function(error) {
|
|
1430
|
+
const event = new ErrorEvent('error', {
|
|
1431
|
+
error,
|
|
1432
|
+
message: error.message
|
|
1433
|
+
});
|
|
1434
|
+
event[kTarget] = this;
|
|
1435
|
+
callListener(handler, this, event);
|
|
1436
|
+
};
|
|
1437
|
+
else {
|
|
1438
|
+
if ('open' !== type) return;
|
|
1439
|
+
wrapper = function() {
|
|
1440
|
+
const event = new Event('open');
|
|
1441
|
+
event[kTarget] = this;
|
|
1442
|
+
callListener(handler, this, event);
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
1446
|
+
wrapper[kListener] = handler;
|
|
1447
|
+
if (options.once) this.once(type, wrapper);
|
|
1448
|
+
else this.on(type, wrapper);
|
|
1449
|
+
},
|
|
1450
|
+
removeEventListener (type, handler) {
|
|
1451
|
+
for (const listener of this.listeners(type))if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
1452
|
+
this.removeListener(type, listener);
|
|
1453
|
+
break;
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
};
|
|
1457
|
+
module.exports = {
|
|
1458
|
+
CloseEvent,
|
|
1459
|
+
ErrorEvent,
|
|
1460
|
+
Event,
|
|
1461
|
+
EventTarget,
|
|
1462
|
+
MessageEvent
|
|
1463
|
+
};
|
|
1464
|
+
function callListener(listener, thisArg, event) {
|
|
1465
|
+
if ('object' == typeof listener && listener.handleEvent) listener.handleEvent.call(listener, event);
|
|
1466
|
+
else listener.call(thisArg, event);
|
|
1467
|
+
}
|
|
1468
|
+
},
|
|
1469
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
1470
|
+
const { tokenChars } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js");
|
|
1471
|
+
function push(dest, name, elem) {
|
|
1472
|
+
if (void 0 === dest[name]) dest[name] = [
|
|
1473
|
+
elem
|
|
1474
|
+
];
|
|
1475
|
+
else dest[name].push(elem);
|
|
1476
|
+
}
|
|
1477
|
+
function parse(header) {
|
|
1478
|
+
const offers = Object.create(null);
|
|
1479
|
+
let params = Object.create(null);
|
|
1480
|
+
let mustUnescape = false;
|
|
1481
|
+
let isEscaping = false;
|
|
1482
|
+
let inQuotes = false;
|
|
1483
|
+
let extensionName;
|
|
1484
|
+
let paramName;
|
|
1485
|
+
let start = -1;
|
|
1486
|
+
let code = -1;
|
|
1487
|
+
let end = -1;
|
|
1488
|
+
let i = 0;
|
|
1489
|
+
for(; i < header.length; i++){
|
|
1490
|
+
code = header.charCodeAt(i);
|
|
1491
|
+
if (void 0 === extensionName) if (-1 === end && 1 === tokenChars[code]) {
|
|
1492
|
+
if (-1 === start) start = i;
|
|
1493
|
+
} else if (0 !== i && (0x20 === code || 0x09 === code)) {
|
|
1494
|
+
if (-1 === end && -1 !== start) end = i;
|
|
1495
|
+
} else if (0x3b === code || 0x2c === code) {
|
|
1496
|
+
if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1497
|
+
if (-1 === end) end = i;
|
|
1498
|
+
const name = header.slice(start, end);
|
|
1499
|
+
if (0x2c === code) {
|
|
1500
|
+
push(offers, name, params);
|
|
1501
|
+
params = Object.create(null);
|
|
1502
|
+
} else extensionName = name;
|
|
1503
|
+
start = end = -1;
|
|
1504
|
+
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1505
|
+
else if (void 0 === paramName) if (-1 === end && 1 === tokenChars[code]) {
|
|
1506
|
+
if (-1 === start) start = i;
|
|
1507
|
+
} else if (0x20 === code || 0x09 === code) {
|
|
1508
|
+
if (-1 === end && -1 !== start) end = i;
|
|
1509
|
+
} else if (0x3b === code || 0x2c === code) {
|
|
1510
|
+
if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1511
|
+
if (-1 === end) end = i;
|
|
1512
|
+
push(params, header.slice(start, end), true);
|
|
1513
|
+
if (0x2c === code) {
|
|
1514
|
+
push(offers, extensionName, params);
|
|
1515
|
+
params = Object.create(null);
|
|
1516
|
+
extensionName = void 0;
|
|
1517
|
+
}
|
|
1518
|
+
start = end = -1;
|
|
1519
|
+
} else if (0x3d === code && -1 !== start && -1 === end) {
|
|
1520
|
+
paramName = header.slice(start, i);
|
|
1521
|
+
start = end = -1;
|
|
1522
|
+
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1523
|
+
else if (isEscaping) {
|
|
1524
|
+
if (1 !== tokenChars[code]) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1525
|
+
if (-1 === start) start = i;
|
|
1526
|
+
else if (!mustUnescape) mustUnescape = true;
|
|
1527
|
+
isEscaping = false;
|
|
1528
|
+
} else if (inQuotes) if (1 === tokenChars[code]) {
|
|
1529
|
+
if (-1 === start) start = i;
|
|
1530
|
+
} else if (0x22 === code && -1 !== start) {
|
|
1531
|
+
inQuotes = false;
|
|
1532
|
+
end = i;
|
|
1533
|
+
} else if (0x5c === code) isEscaping = true;
|
|
1534
|
+
else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1535
|
+
else if (0x22 === code && 0x3d === header.charCodeAt(i - 1)) inQuotes = true;
|
|
1536
|
+
else if (-1 === end && 1 === tokenChars[code]) {
|
|
1537
|
+
if (-1 === start) start = i;
|
|
1538
|
+
} else if (-1 !== start && (0x20 === code || 0x09 === code)) {
|
|
1539
|
+
if (-1 === end) end = i;
|
|
1540
|
+
} else if (0x3b === code || 0x2c === code) {
|
|
1541
|
+
if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1542
|
+
if (-1 === end) end = i;
|
|
1543
|
+
let value = header.slice(start, end);
|
|
1544
|
+
if (mustUnescape) {
|
|
1545
|
+
value = value.replace(/\\/g, '');
|
|
1546
|
+
mustUnescape = false;
|
|
1547
|
+
}
|
|
1548
|
+
push(params, paramName, value);
|
|
1549
|
+
if (0x2c === code) {
|
|
1550
|
+
push(offers, extensionName, params);
|
|
1551
|
+
params = Object.create(null);
|
|
1552
|
+
extensionName = void 0;
|
|
1553
|
+
}
|
|
1554
|
+
paramName = void 0;
|
|
1555
|
+
start = end = -1;
|
|
1556
|
+
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1557
|
+
}
|
|
1558
|
+
if (-1 === start || inQuotes || 0x20 === code || 0x09 === code) throw new SyntaxError('Unexpected end of input');
|
|
1559
|
+
if (-1 === end) end = i;
|
|
1560
|
+
const token = header.slice(start, end);
|
|
1561
|
+
if (void 0 === extensionName) push(offers, token, params);
|
|
1562
|
+
else {
|
|
1563
|
+
if (void 0 === paramName) push(params, token, true);
|
|
1564
|
+
else mustUnescape ? push(params, paramName, token.replace(/\\/g, '')) : push(params, paramName, token);
|
|
1565
|
+
push(offers, extensionName, params);
|
|
1566
|
+
}
|
|
1567
|
+
return offers;
|
|
1568
|
+
}
|
|
1569
|
+
function format(extensions) {
|
|
1570
|
+
return Object.keys(extensions).map((extension)=>{
|
|
1571
|
+
let configurations = extensions[extension];
|
|
1572
|
+
if (!Array.isArray(configurations)) configurations = [
|
|
1573
|
+
configurations
|
|
1574
|
+
];
|
|
1575
|
+
return configurations.map((params)=>[
|
|
1576
|
+
extension
|
|
1577
|
+
].concat(Object.keys(params).map((k)=>{
|
|
1578
|
+
let values = params[k];
|
|
1579
|
+
if (!Array.isArray(values)) values = [
|
|
1580
|
+
values
|
|
1581
|
+
];
|
|
1582
|
+
return values.map((v)=>true === v ? k : `${k}=${v}`).join('; ');
|
|
1583
|
+
})).join('; ')).join(', ');
|
|
1584
|
+
}).join(', ');
|
|
1585
|
+
}
|
|
1586
|
+
module.exports = {
|
|
1587
|
+
format,
|
|
1588
|
+
parse
|
|
1589
|
+
};
|
|
1590
|
+
},
|
|
1591
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/limiter.js" (module) {
|
|
1592
|
+
const kDone = Symbol('kDone');
|
|
1593
|
+
const kRun = Symbol('kRun');
|
|
1594
|
+
class Limiter {
|
|
1595
|
+
constructor(concurrency){
|
|
1596
|
+
this[kDone] = ()=>{
|
|
1597
|
+
this.pending--;
|
|
1598
|
+
this[kRun]();
|
|
1599
|
+
};
|
|
1600
|
+
this.concurrency = concurrency || 1 / 0;
|
|
1601
|
+
this.jobs = [];
|
|
1602
|
+
this.pending = 0;
|
|
1603
|
+
}
|
|
1604
|
+
add(job) {
|
|
1605
|
+
this.jobs.push(job);
|
|
1606
|
+
this[kRun]();
|
|
1607
|
+
}
|
|
1608
|
+
[kRun]() {
|
|
1609
|
+
if (this.pending === this.concurrency) return;
|
|
1610
|
+
if (this.jobs.length) {
|
|
1611
|
+
const job = this.jobs.shift();
|
|
1612
|
+
this.pending++;
|
|
1613
|
+
job(this[kDone]);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
module.exports = Limiter;
|
|
1618
|
+
},
|
|
1619
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
1620
|
+
const zlib = __webpack_require__("zlib");
|
|
1621
|
+
const bufferUtil = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js");
|
|
1622
|
+
const Limiter = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/limiter.js");
|
|
1623
|
+
const { kStatusCode } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
1624
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
1625
|
+
const TRAILER = Buffer.from([
|
|
1626
|
+
0x00,
|
|
1627
|
+
0x00,
|
|
1628
|
+
0xff,
|
|
1629
|
+
0xff
|
|
1630
|
+
]);
|
|
1631
|
+
const kPerMessageDeflate = Symbol('permessage-deflate');
|
|
1632
|
+
const kTotalLength = Symbol('total-length');
|
|
1633
|
+
const kCallback = Symbol('callback');
|
|
1634
|
+
const kBuffers = Symbol('buffers');
|
|
1635
|
+
const kError = Symbol('error');
|
|
1636
|
+
let zlibLimiter;
|
|
1637
|
+
class PerMessageDeflate {
|
|
1638
|
+
constructor(options){
|
|
1639
|
+
this._options = options || {};
|
|
1640
|
+
this._threshold = void 0 !== this._options.threshold ? this._options.threshold : 1024;
|
|
1641
|
+
this._maxPayload = 0 | this._options.maxPayload;
|
|
1642
|
+
this._isServer = !!this._options.isServer;
|
|
1643
|
+
this._deflate = null;
|
|
1644
|
+
this._inflate = null;
|
|
1645
|
+
this.params = null;
|
|
1646
|
+
if (!zlibLimiter) {
|
|
1647
|
+
const concurrency = void 0 !== this._options.concurrencyLimit ? this._options.concurrencyLimit : 10;
|
|
1648
|
+
zlibLimiter = new Limiter(concurrency);
|
|
1649
|
+
}
|
|
1650
|
+
}
|
|
1651
|
+
static get extensionName() {
|
|
1652
|
+
return 'permessage-deflate';
|
|
1653
|
+
}
|
|
1654
|
+
offer() {
|
|
1655
|
+
const params = {};
|
|
1656
|
+
if (this._options.serverNoContextTakeover) params.server_no_context_takeover = true;
|
|
1657
|
+
if (this._options.clientNoContextTakeover) params.client_no_context_takeover = true;
|
|
1658
|
+
if (this._options.serverMaxWindowBits) params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
1659
|
+
if (this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
1660
|
+
else if (null == this._options.clientMaxWindowBits) params.client_max_window_bits = true;
|
|
1661
|
+
return params;
|
|
1662
|
+
}
|
|
1663
|
+
accept(configurations) {
|
|
1664
|
+
configurations = this.normalizeParams(configurations);
|
|
1665
|
+
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
1666
|
+
return this.params;
|
|
1667
|
+
}
|
|
1668
|
+
cleanup() {
|
|
1669
|
+
if (this._inflate) {
|
|
1670
|
+
this._inflate.close();
|
|
1671
|
+
this._inflate = null;
|
|
1672
|
+
}
|
|
1673
|
+
if (this._deflate) {
|
|
1674
|
+
const callback = this._deflate[kCallback];
|
|
1675
|
+
this._deflate.close();
|
|
1676
|
+
this._deflate = null;
|
|
1677
|
+
if (callback) callback(new Error('The deflate stream was closed while data was being processed'));
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
acceptAsServer(offers) {
|
|
1681
|
+
const opts = this._options;
|
|
1682
|
+
const accepted = offers.find((params)=>{
|
|
1683
|
+
if (false === opts.serverNoContextTakeover && params.server_no_context_takeover || params.server_max_window_bits && (false === opts.serverMaxWindowBits || 'number' == typeof opts.serverMaxWindowBits && opts.serverMaxWindowBits > params.server_max_window_bits) || 'number' == typeof opts.clientMaxWindowBits && !params.client_max_window_bits) return false;
|
|
1684
|
+
return true;
|
|
1685
|
+
});
|
|
1686
|
+
if (!accepted) throw new Error('None of the extension offers can be accepted');
|
|
1687
|
+
if (opts.serverNoContextTakeover) accepted.server_no_context_takeover = true;
|
|
1688
|
+
if (opts.clientNoContextTakeover) accepted.client_no_context_takeover = true;
|
|
1689
|
+
if ('number' == typeof opts.serverMaxWindowBits) accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
1690
|
+
if ('number' == typeof opts.clientMaxWindowBits) accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
1691
|
+
else if (true === accepted.client_max_window_bits || false === opts.clientMaxWindowBits) delete accepted.client_max_window_bits;
|
|
1692
|
+
return accepted;
|
|
1693
|
+
}
|
|
1694
|
+
acceptAsClient(response) {
|
|
1695
|
+
const params = response[0];
|
|
1696
|
+
if (false === this._options.clientNoContextTakeover && params.client_no_context_takeover) throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
1697
|
+
if (params.client_max_window_bits) {
|
|
1698
|
+
if (false === this._options.clientMaxWindowBits || 'number' == typeof this._options.clientMaxWindowBits && params.client_max_window_bits > this._options.clientMaxWindowBits) throw new Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
1699
|
+
} else if ('number' == typeof this._options.clientMaxWindowBits) params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
1700
|
+
return params;
|
|
1701
|
+
}
|
|
1702
|
+
normalizeParams(configurations) {
|
|
1703
|
+
configurations.forEach((params)=>{
|
|
1704
|
+
Object.keys(params).forEach((key)=>{
|
|
1705
|
+
let value = params[key];
|
|
1706
|
+
if (value.length > 1) throw new Error(`Parameter "${key}" must have only a single value`);
|
|
1707
|
+
value = value[0];
|
|
1708
|
+
if ('client_max_window_bits' === key) {
|
|
1709
|
+
if (true !== value) {
|
|
1710
|
+
const num = +value;
|
|
1711
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
1712
|
+
value = num;
|
|
1713
|
+
} else if (!this._isServer) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
1714
|
+
} else if ('server_max_window_bits' === key) {
|
|
1715
|
+
const num = +value;
|
|
1716
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
1717
|
+
value = num;
|
|
1718
|
+
} else if ('client_no_context_takeover' === key || 'server_no_context_takeover' === key) {
|
|
1719
|
+
if (true !== value) throw new TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
1720
|
+
} else throw new Error(`Unknown parameter "${key}"`);
|
|
1721
|
+
params[key] = value;
|
|
1722
|
+
});
|
|
1723
|
+
});
|
|
1724
|
+
return configurations;
|
|
1725
|
+
}
|
|
1726
|
+
decompress(data, fin, callback) {
|
|
1727
|
+
zlibLimiter.add((done)=>{
|
|
1728
|
+
this._decompress(data, fin, (err, result)=>{
|
|
1729
|
+
done();
|
|
1730
|
+
callback(err, result);
|
|
1731
|
+
});
|
|
1732
|
+
});
|
|
1733
|
+
}
|
|
1734
|
+
compress(data, fin, callback) {
|
|
1735
|
+
zlibLimiter.add((done)=>{
|
|
1736
|
+
this._compress(data, fin, (err, result)=>{
|
|
1737
|
+
done();
|
|
1738
|
+
callback(err, result);
|
|
1739
|
+
});
|
|
1740
|
+
});
|
|
1741
|
+
}
|
|
1742
|
+
_decompress(data, fin, callback) {
|
|
1743
|
+
const endpoint = this._isServer ? 'client' : 'server';
|
|
1744
|
+
if (!this._inflate) {
|
|
1745
|
+
const key = `${endpoint}_max_window_bits`;
|
|
1746
|
+
const windowBits = 'number' != typeof this.params[key] ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
1747
|
+
this._inflate = zlib.createInflateRaw({
|
|
1748
|
+
...this._options.zlibInflateOptions,
|
|
1749
|
+
windowBits
|
|
1750
|
+
});
|
|
1751
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
1752
|
+
this._inflate[kTotalLength] = 0;
|
|
1753
|
+
this._inflate[kBuffers] = [];
|
|
1754
|
+
this._inflate.on('error', inflateOnError);
|
|
1755
|
+
this._inflate.on('data', inflateOnData);
|
|
1756
|
+
}
|
|
1757
|
+
this._inflate[kCallback] = callback;
|
|
1758
|
+
this._inflate.write(data);
|
|
1759
|
+
if (fin) this._inflate.write(TRAILER);
|
|
1760
|
+
this._inflate.flush(()=>{
|
|
1761
|
+
const err = this._inflate[kError];
|
|
1762
|
+
if (err) {
|
|
1763
|
+
this._inflate.close();
|
|
1764
|
+
this._inflate = null;
|
|
1765
|
+
callback(err);
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
|
+
const data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
1769
|
+
if (this._inflate._readableState.endEmitted) {
|
|
1770
|
+
this._inflate.close();
|
|
1771
|
+
this._inflate = null;
|
|
1772
|
+
} else {
|
|
1773
|
+
this._inflate[kTotalLength] = 0;
|
|
1774
|
+
this._inflate[kBuffers] = [];
|
|
1775
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) this._inflate.reset();
|
|
1776
|
+
}
|
|
1777
|
+
callback(null, data);
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
_compress(data, fin, callback) {
|
|
1781
|
+
const endpoint = this._isServer ? 'server' : 'client';
|
|
1782
|
+
if (!this._deflate) {
|
|
1783
|
+
const key = `${endpoint}_max_window_bits`;
|
|
1784
|
+
const windowBits = 'number' != typeof this.params[key] ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
1785
|
+
this._deflate = zlib.createDeflateRaw({
|
|
1786
|
+
...this._options.zlibDeflateOptions,
|
|
1787
|
+
windowBits
|
|
1788
|
+
});
|
|
1789
|
+
this._deflate[kTotalLength] = 0;
|
|
1790
|
+
this._deflate[kBuffers] = [];
|
|
1791
|
+
this._deflate.on('data', deflateOnData);
|
|
1792
|
+
}
|
|
1793
|
+
this._deflate[kCallback] = callback;
|
|
1794
|
+
this._deflate.write(data);
|
|
1795
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, ()=>{
|
|
1796
|
+
if (!this._deflate) return;
|
|
1797
|
+
let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
1798
|
+
if (fin) data = new FastBuffer(data.buffer, data.byteOffset, data.length - 4);
|
|
1799
|
+
this._deflate[kCallback] = null;
|
|
1800
|
+
this._deflate[kTotalLength] = 0;
|
|
1801
|
+
this._deflate[kBuffers] = [];
|
|
1802
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) this._deflate.reset();
|
|
1803
|
+
callback(null, data);
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
module.exports = PerMessageDeflate;
|
|
1808
|
+
function deflateOnData(chunk) {
|
|
1809
|
+
this[kBuffers].push(chunk);
|
|
1810
|
+
this[kTotalLength] += chunk.length;
|
|
1811
|
+
}
|
|
1812
|
+
function inflateOnData(chunk) {
|
|
1813
|
+
this[kTotalLength] += chunk.length;
|
|
1814
|
+
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) return void this[kBuffers].push(chunk);
|
|
1815
|
+
this[kError] = new RangeError('Max payload size exceeded');
|
|
1816
|
+
this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
|
|
1817
|
+
this[kError][kStatusCode] = 1009;
|
|
1818
|
+
this.removeListener('data', inflateOnData);
|
|
1819
|
+
this.reset();
|
|
1820
|
+
}
|
|
1821
|
+
function inflateOnError(err) {
|
|
1822
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
1823
|
+
if (this[kError]) return void this[kCallback](this[kError]);
|
|
1824
|
+
err[kStatusCode] = 1007;
|
|
1825
|
+
this[kCallback](err);
|
|
1826
|
+
}
|
|
1827
|
+
},
|
|
1828
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/receiver.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
1829
|
+
const { Writable } = __webpack_require__("stream");
|
|
1830
|
+
const PerMessageDeflate = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js");
|
|
1831
|
+
const { BINARY_TYPES, EMPTY_BUFFER, kStatusCode, kWebSocket } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
1832
|
+
const { concat, toArrayBuffer, unmask } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js");
|
|
1833
|
+
const { isValidStatusCode, isValidUTF8 } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js");
|
|
1834
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
1835
|
+
const GET_INFO = 0;
|
|
1836
|
+
const GET_PAYLOAD_LENGTH_16 = 1;
|
|
1837
|
+
const GET_PAYLOAD_LENGTH_64 = 2;
|
|
1838
|
+
const GET_MASK = 3;
|
|
1839
|
+
const GET_DATA = 4;
|
|
1840
|
+
const INFLATING = 5;
|
|
1841
|
+
const DEFER_EVENT = 6;
|
|
1842
|
+
class Receiver extends Writable {
|
|
1843
|
+
constructor(options = {}){
|
|
1844
|
+
super();
|
|
1845
|
+
this._allowSynchronousEvents = void 0 !== options.allowSynchronousEvents ? options.allowSynchronousEvents : true;
|
|
1846
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
1847
|
+
this._extensions = options.extensions || {};
|
|
1848
|
+
this._isServer = !!options.isServer;
|
|
1849
|
+
this._maxPayload = 0 | options.maxPayload;
|
|
1850
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
1851
|
+
this[kWebSocket] = void 0;
|
|
1852
|
+
this._bufferedBytes = 0;
|
|
1853
|
+
this._buffers = [];
|
|
1854
|
+
this._compressed = false;
|
|
1855
|
+
this._payloadLength = 0;
|
|
1856
|
+
this._mask = void 0;
|
|
1857
|
+
this._fragmented = 0;
|
|
1858
|
+
this._masked = false;
|
|
1859
|
+
this._fin = false;
|
|
1860
|
+
this._opcode = 0;
|
|
1861
|
+
this._totalPayloadLength = 0;
|
|
1862
|
+
this._messageLength = 0;
|
|
1863
|
+
this._fragments = [];
|
|
1864
|
+
this._errored = false;
|
|
1865
|
+
this._loop = false;
|
|
1866
|
+
this._state = GET_INFO;
|
|
1867
|
+
}
|
|
1868
|
+
_write(chunk, encoding, cb) {
|
|
1869
|
+
if (0x08 === this._opcode && this._state == GET_INFO) return cb();
|
|
1870
|
+
this._bufferedBytes += chunk.length;
|
|
1871
|
+
this._buffers.push(chunk);
|
|
1872
|
+
this.startLoop(cb);
|
|
1873
|
+
}
|
|
1874
|
+
consume(n) {
|
|
1875
|
+
this._bufferedBytes -= n;
|
|
1876
|
+
if (n === this._buffers[0].length) return this._buffers.shift();
|
|
1877
|
+
if (n < this._buffers[0].length) {
|
|
1878
|
+
const buf = this._buffers[0];
|
|
1879
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
1880
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
1881
|
+
}
|
|
1882
|
+
const dst = Buffer.allocUnsafe(n);
|
|
1883
|
+
do {
|
|
1884
|
+
const buf = this._buffers[0];
|
|
1885
|
+
const offset = dst.length - n;
|
|
1886
|
+
if (n >= buf.length) dst.set(this._buffers.shift(), offset);
|
|
1887
|
+
else {
|
|
1888
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
1889
|
+
this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n);
|
|
1890
|
+
}
|
|
1891
|
+
n -= buf.length;
|
|
1892
|
+
}while (n > 0);
|
|
1893
|
+
return dst;
|
|
1894
|
+
}
|
|
1895
|
+
startLoop(cb) {
|
|
1896
|
+
this._loop = true;
|
|
1897
|
+
do switch(this._state){
|
|
1898
|
+
case GET_INFO:
|
|
1899
|
+
this.getInfo(cb);
|
|
1900
|
+
break;
|
|
1901
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
1902
|
+
this.getPayloadLength16(cb);
|
|
1903
|
+
break;
|
|
1904
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
1905
|
+
this.getPayloadLength64(cb);
|
|
1906
|
+
break;
|
|
1907
|
+
case GET_MASK:
|
|
1908
|
+
this.getMask();
|
|
1909
|
+
break;
|
|
1910
|
+
case GET_DATA:
|
|
1911
|
+
this.getData(cb);
|
|
1912
|
+
break;
|
|
1913
|
+
case INFLATING:
|
|
1914
|
+
case DEFER_EVENT:
|
|
1915
|
+
this._loop = false;
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
while (this._loop);
|
|
1919
|
+
if (!this._errored) cb();
|
|
1920
|
+
}
|
|
1921
|
+
getInfo(cb) {
|
|
1922
|
+
if (this._bufferedBytes < 2) {
|
|
1923
|
+
this._loop = false;
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
const buf = this.consume(2);
|
|
1927
|
+
if ((0x30 & buf[0]) !== 0x00) {
|
|
1928
|
+
const error = this.createError(RangeError, 'RSV2 and RSV3 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_2_3');
|
|
1929
|
+
cb(error);
|
|
1930
|
+
return;
|
|
1931
|
+
}
|
|
1932
|
+
const compressed = (0x40 & buf[0]) === 0x40;
|
|
1933
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
|
|
1934
|
+
const error = this.createError(RangeError, 'RSV1 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_1');
|
|
1935
|
+
cb(error);
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
this._fin = (0x80 & buf[0]) === 0x80;
|
|
1939
|
+
this._opcode = 0x0f & buf[0];
|
|
1940
|
+
this._payloadLength = 0x7f & buf[1];
|
|
1941
|
+
if (0x00 === this._opcode) {
|
|
1942
|
+
if (compressed) {
|
|
1943
|
+
const error = this.createError(RangeError, 'RSV1 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_1');
|
|
1944
|
+
cb(error);
|
|
1945
|
+
return;
|
|
1946
|
+
}
|
|
1947
|
+
if (!this._fragmented) {
|
|
1948
|
+
const error = this.createError(RangeError, 'invalid opcode 0', true, 1002, 'WS_ERR_INVALID_OPCODE');
|
|
1949
|
+
cb(error);
|
|
1950
|
+
return;
|
|
1951
|
+
}
|
|
1952
|
+
this._opcode = this._fragmented;
|
|
1953
|
+
} else if (0x01 === this._opcode || 0x02 === this._opcode) {
|
|
1954
|
+
if (this._fragmented) {
|
|
1955
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, 'WS_ERR_INVALID_OPCODE');
|
|
1956
|
+
cb(error);
|
|
1957
|
+
return;
|
|
1958
|
+
}
|
|
1959
|
+
this._compressed = compressed;
|
|
1960
|
+
} else if (this._opcode > 0x07 && this._opcode < 0x0b) {
|
|
1961
|
+
if (!this._fin) {
|
|
1962
|
+
const error = this.createError(RangeError, 'FIN must be set', true, 1002, 'WS_ERR_EXPECTED_FIN');
|
|
1963
|
+
cb(error);
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
if (compressed) {
|
|
1967
|
+
const error = this.createError(RangeError, 'RSV1 must be clear', true, 1002, 'WS_ERR_UNEXPECTED_RSV_1');
|
|
1968
|
+
cb(error);
|
|
1969
|
+
return;
|
|
1970
|
+
}
|
|
1971
|
+
if (this._payloadLength > 0x7d || 0x08 === this._opcode && 1 === this._payloadLength) {
|
|
1972
|
+
const error = this.createError(RangeError, `invalid payload length ${this._payloadLength}`, true, 1002, 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH');
|
|
1973
|
+
cb(error);
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1976
|
+
} else {
|
|
1977
|
+
const error = this.createError(RangeError, `invalid opcode ${this._opcode}`, true, 1002, 'WS_ERR_INVALID_OPCODE');
|
|
1978
|
+
cb(error);
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
1982
|
+
this._masked = (0x80 & buf[1]) === 0x80;
|
|
1983
|
+
if (this._isServer) {
|
|
1984
|
+
if (!this._masked) {
|
|
1985
|
+
const error = this.createError(RangeError, 'MASK must be set', true, 1002, 'WS_ERR_EXPECTED_MASK');
|
|
1986
|
+
cb(error);
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
} else if (this._masked) {
|
|
1990
|
+
const error = this.createError(RangeError, 'MASK must be clear', true, 1002, 'WS_ERR_UNEXPECTED_MASK');
|
|
1991
|
+
cb(error);
|
|
1992
|
+
return;
|
|
1993
|
+
}
|
|
1994
|
+
if (126 === this._payloadLength) this._state = GET_PAYLOAD_LENGTH_16;
|
|
1995
|
+
else if (127 === this._payloadLength) this._state = GET_PAYLOAD_LENGTH_64;
|
|
1996
|
+
else this.haveLength(cb);
|
|
1997
|
+
}
|
|
1998
|
+
getPayloadLength16(cb) {
|
|
1999
|
+
if (this._bufferedBytes < 2) {
|
|
2000
|
+
this._loop = false;
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
2004
|
+
this.haveLength(cb);
|
|
2005
|
+
}
|
|
2006
|
+
getPayloadLength64(cb) {
|
|
2007
|
+
if (this._bufferedBytes < 8) {
|
|
2008
|
+
this._loop = false;
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
const buf = this.consume(8);
|
|
2012
|
+
const num = buf.readUInt32BE(0);
|
|
2013
|
+
if (num > Math.pow(2, 21) - 1) {
|
|
2014
|
+
const error = this.createError(RangeError, 'Unsupported WebSocket frame: payload length > 2^53 - 1', false, 1009, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH');
|
|
2015
|
+
cb(error);
|
|
2016
|
+
return;
|
|
2017
|
+
}
|
|
2018
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
2019
|
+
this.haveLength(cb);
|
|
2020
|
+
}
|
|
2021
|
+
haveLength(cb) {
|
|
2022
|
+
if (this._payloadLength && this._opcode < 0x08) {
|
|
2023
|
+
this._totalPayloadLength += this._payloadLength;
|
|
2024
|
+
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
2025
|
+
const error = this.createError(RangeError, 'Max payload size exceeded', false, 1009, 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH');
|
|
2026
|
+
cb(error);
|
|
2027
|
+
return;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
if (this._masked) this._state = GET_MASK;
|
|
2031
|
+
else this._state = GET_DATA;
|
|
2032
|
+
}
|
|
2033
|
+
getMask() {
|
|
2034
|
+
if (this._bufferedBytes < 4) {
|
|
2035
|
+
this._loop = false;
|
|
2036
|
+
return;
|
|
2037
|
+
}
|
|
2038
|
+
this._mask = this.consume(4);
|
|
2039
|
+
this._state = GET_DATA;
|
|
2040
|
+
}
|
|
2041
|
+
getData(cb) {
|
|
2042
|
+
let data = EMPTY_BUFFER;
|
|
2043
|
+
if (this._payloadLength) {
|
|
2044
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
2045
|
+
this._loop = false;
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
data = this.consume(this._payloadLength);
|
|
2049
|
+
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) unmask(data, this._mask);
|
|
2050
|
+
}
|
|
2051
|
+
if (this._opcode > 0x07) return void this.controlMessage(data, cb);
|
|
2052
|
+
if (this._compressed) {
|
|
2053
|
+
this._state = INFLATING;
|
|
2054
|
+
this.decompress(data, cb);
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2057
|
+
if (data.length) {
|
|
2058
|
+
this._messageLength = this._totalPayloadLength;
|
|
2059
|
+
this._fragments.push(data);
|
|
2060
|
+
}
|
|
2061
|
+
this.dataMessage(cb);
|
|
2062
|
+
}
|
|
2063
|
+
decompress(data, cb) {
|
|
2064
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
2065
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf)=>{
|
|
2066
|
+
if (err) return cb(err);
|
|
2067
|
+
if (buf.length) {
|
|
2068
|
+
this._messageLength += buf.length;
|
|
2069
|
+
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
2070
|
+
const error = this.createError(RangeError, 'Max payload size exceeded', false, 1009, 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH');
|
|
2071
|
+
cb(error);
|
|
2072
|
+
return;
|
|
2073
|
+
}
|
|
2074
|
+
this._fragments.push(buf);
|
|
2075
|
+
}
|
|
2076
|
+
this.dataMessage(cb);
|
|
2077
|
+
if (this._state === GET_INFO) this.startLoop(cb);
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
dataMessage(cb) {
|
|
2081
|
+
if (!this._fin) {
|
|
2082
|
+
this._state = GET_INFO;
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
const messageLength = this._messageLength;
|
|
2086
|
+
const fragments = this._fragments;
|
|
2087
|
+
this._totalPayloadLength = 0;
|
|
2088
|
+
this._messageLength = 0;
|
|
2089
|
+
this._fragmented = 0;
|
|
2090
|
+
this._fragments = [];
|
|
2091
|
+
if (2 === this._opcode) {
|
|
2092
|
+
let data;
|
|
2093
|
+
data = 'nodebuffer' === this._binaryType ? concat(fragments, messageLength) : 'arraybuffer' === this._binaryType ? toArrayBuffer(concat(fragments, messageLength)) : 'blob' === this._binaryType ? new Blob(fragments) : fragments;
|
|
2094
|
+
if (this._allowSynchronousEvents) {
|
|
2095
|
+
this.emit('message', data, true);
|
|
2096
|
+
this._state = GET_INFO;
|
|
2097
|
+
} else {
|
|
2098
|
+
this._state = DEFER_EVENT;
|
|
2099
|
+
setImmediate(()=>{
|
|
2100
|
+
this.emit('message', data, true);
|
|
2101
|
+
this._state = GET_INFO;
|
|
2102
|
+
this.startLoop(cb);
|
|
2103
|
+
});
|
|
2104
|
+
}
|
|
2105
|
+
} else {
|
|
2106
|
+
const buf = concat(fragments, messageLength);
|
|
2107
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
2108
|
+
const error = this.createError(Error, 'invalid UTF-8 sequence', true, 1007, 'WS_ERR_INVALID_UTF8');
|
|
2109
|
+
cb(error);
|
|
2110
|
+
return;
|
|
2111
|
+
}
|
|
2112
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
2113
|
+
this.emit('message', buf, false);
|
|
2114
|
+
this._state = GET_INFO;
|
|
2115
|
+
} else {
|
|
2116
|
+
this._state = DEFER_EVENT;
|
|
2117
|
+
setImmediate(()=>{
|
|
2118
|
+
this.emit('message', buf, false);
|
|
2119
|
+
this._state = GET_INFO;
|
|
2120
|
+
this.startLoop(cb);
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
controlMessage(data, cb) {
|
|
2126
|
+
if (0x08 === this._opcode) {
|
|
2127
|
+
if (0 === data.length) {
|
|
2128
|
+
this._loop = false;
|
|
2129
|
+
this.emit('conclude', 1005, EMPTY_BUFFER);
|
|
2130
|
+
this.end();
|
|
2131
|
+
} else {
|
|
2132
|
+
const code = data.readUInt16BE(0);
|
|
2133
|
+
if (!isValidStatusCode(code)) {
|
|
2134
|
+
const error = this.createError(RangeError, `invalid status code ${code}`, true, 1002, 'WS_ERR_INVALID_CLOSE_CODE');
|
|
2135
|
+
cb(error);
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
const buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
2139
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
2140
|
+
const error = this.createError(Error, 'invalid UTF-8 sequence', true, 1007, 'WS_ERR_INVALID_UTF8');
|
|
2141
|
+
cb(error);
|
|
2142
|
+
return;
|
|
2143
|
+
}
|
|
2144
|
+
this._loop = false;
|
|
2145
|
+
this.emit('conclude', code, buf);
|
|
2146
|
+
this.end();
|
|
2147
|
+
}
|
|
2148
|
+
this._state = GET_INFO;
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
if (this._allowSynchronousEvents) {
|
|
2152
|
+
this.emit(0x09 === this._opcode ? 'ping' : 'pong', data);
|
|
2153
|
+
this._state = GET_INFO;
|
|
2154
|
+
} else {
|
|
2155
|
+
this._state = DEFER_EVENT;
|
|
2156
|
+
setImmediate(()=>{
|
|
2157
|
+
this.emit(0x09 === this._opcode ? 'ping' : 'pong', data);
|
|
2158
|
+
this._state = GET_INFO;
|
|
2159
|
+
this.startLoop(cb);
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
2164
|
+
this._loop = false;
|
|
2165
|
+
this._errored = true;
|
|
2166
|
+
const err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
2167
|
+
Error.captureStackTrace(err, this.createError);
|
|
2168
|
+
err.code = errorCode;
|
|
2169
|
+
err[kStatusCode] = statusCode;
|
|
2170
|
+
return err;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
module.exports = Receiver;
|
|
2174
|
+
},
|
|
2175
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/sender.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
2176
|
+
const { Duplex } = __webpack_require__("stream");
|
|
2177
|
+
const { randomFillSync } = __webpack_require__("crypto");
|
|
2178
|
+
const PerMessageDeflate = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js");
|
|
2179
|
+
const { EMPTY_BUFFER, kWebSocket, NOOP } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
2180
|
+
const { isBlob, isValidStatusCode } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js");
|
|
2181
|
+
const { mask: applyMask, toBuffer } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js");
|
|
2182
|
+
const kByteLength = Symbol('kByteLength');
|
|
2183
|
+
const maskBuffer = Buffer.alloc(4);
|
|
2184
|
+
const RANDOM_POOL_SIZE = 8192;
|
|
2185
|
+
let randomPool;
|
|
2186
|
+
let randomPoolPointer = RANDOM_POOL_SIZE;
|
|
2187
|
+
const DEFAULT = 0;
|
|
2188
|
+
const DEFLATING = 1;
|
|
2189
|
+
const GET_BLOB_DATA = 2;
|
|
2190
|
+
class Sender {
|
|
2191
|
+
constructor(socket, extensions, generateMask){
|
|
2192
|
+
this._extensions = extensions || {};
|
|
2193
|
+
if (generateMask) {
|
|
2194
|
+
this._generateMask = generateMask;
|
|
2195
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
2196
|
+
}
|
|
2197
|
+
this._socket = socket;
|
|
2198
|
+
this._firstFragment = true;
|
|
2199
|
+
this._compress = false;
|
|
2200
|
+
this._bufferedBytes = 0;
|
|
2201
|
+
this._queue = [];
|
|
2202
|
+
this._state = DEFAULT;
|
|
2203
|
+
this.onerror = NOOP;
|
|
2204
|
+
this[kWebSocket] = void 0;
|
|
2205
|
+
}
|
|
2206
|
+
static frame(data, options) {
|
|
2207
|
+
let mask;
|
|
2208
|
+
let merge = false;
|
|
2209
|
+
let offset = 2;
|
|
2210
|
+
let skipMasking = false;
|
|
2211
|
+
if (options.mask) {
|
|
2212
|
+
mask = options.maskBuffer || maskBuffer;
|
|
2213
|
+
if (options.generateMask) options.generateMask(mask);
|
|
2214
|
+
else {
|
|
2215
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
2216
|
+
if (void 0 === randomPool) randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
2217
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
2218
|
+
randomPoolPointer = 0;
|
|
2219
|
+
}
|
|
2220
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
2221
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
2222
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
2223
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
2224
|
+
}
|
|
2225
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
2226
|
+
offset = 6;
|
|
2227
|
+
}
|
|
2228
|
+
let dataLength;
|
|
2229
|
+
if ('string' == typeof data) if ((!options.mask || skipMasking) && void 0 !== options[kByteLength]) dataLength = options[kByteLength];
|
|
2230
|
+
else {
|
|
2231
|
+
data = Buffer.from(data);
|
|
2232
|
+
dataLength = data.length;
|
|
2233
|
+
}
|
|
2234
|
+
else {
|
|
2235
|
+
dataLength = data.length;
|
|
2236
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
2237
|
+
}
|
|
2238
|
+
let payloadLength = dataLength;
|
|
2239
|
+
if (dataLength >= 65536) {
|
|
2240
|
+
offset += 8;
|
|
2241
|
+
payloadLength = 127;
|
|
2242
|
+
} else if (dataLength > 125) {
|
|
2243
|
+
offset += 2;
|
|
2244
|
+
payloadLength = 126;
|
|
2245
|
+
}
|
|
2246
|
+
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
2247
|
+
target[0] = options.fin ? 0x80 | options.opcode : options.opcode;
|
|
2248
|
+
if (options.rsv1) target[0] |= 0x40;
|
|
2249
|
+
target[1] = payloadLength;
|
|
2250
|
+
if (126 === payloadLength) target.writeUInt16BE(dataLength, 2);
|
|
2251
|
+
else if (127 === payloadLength) {
|
|
2252
|
+
target[2] = target[3] = 0;
|
|
2253
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
2254
|
+
}
|
|
2255
|
+
if (!options.mask) return [
|
|
2256
|
+
target,
|
|
2257
|
+
data
|
|
2258
|
+
];
|
|
2259
|
+
target[1] |= 0x80;
|
|
2260
|
+
target[offset - 4] = mask[0];
|
|
2261
|
+
target[offset - 3] = mask[1];
|
|
2262
|
+
target[offset - 2] = mask[2];
|
|
2263
|
+
target[offset - 1] = mask[3];
|
|
2264
|
+
if (skipMasking) return [
|
|
2265
|
+
target,
|
|
2266
|
+
data
|
|
2267
|
+
];
|
|
2268
|
+
if (merge) {
|
|
2269
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
2270
|
+
return [
|
|
2271
|
+
target
|
|
2272
|
+
];
|
|
2273
|
+
}
|
|
2274
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
2275
|
+
return [
|
|
2276
|
+
target,
|
|
2277
|
+
data
|
|
2278
|
+
];
|
|
2279
|
+
}
|
|
2280
|
+
close(code, data, mask, cb) {
|
|
2281
|
+
let buf;
|
|
2282
|
+
if (void 0 === code) buf = EMPTY_BUFFER;
|
|
2283
|
+
else if ('number' == typeof code && isValidStatusCode(code)) if (void 0 !== data && data.length) {
|
|
2284
|
+
const length = Buffer.byteLength(data);
|
|
2285
|
+
if (length > 123) throw new RangeError('The message must not be greater than 123 bytes');
|
|
2286
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
2287
|
+
buf.writeUInt16BE(code, 0);
|
|
2288
|
+
if ('string' == typeof data) buf.write(data, 2);
|
|
2289
|
+
else buf.set(data, 2);
|
|
2290
|
+
} else {
|
|
2291
|
+
buf = Buffer.allocUnsafe(2);
|
|
2292
|
+
buf.writeUInt16BE(code, 0);
|
|
2293
|
+
}
|
|
2294
|
+
else throw new TypeError('First argument must be a valid error code number');
|
|
2295
|
+
const options = {
|
|
2296
|
+
[kByteLength]: buf.length,
|
|
2297
|
+
fin: true,
|
|
2298
|
+
generateMask: this._generateMask,
|
|
2299
|
+
mask,
|
|
2300
|
+
maskBuffer: this._maskBuffer,
|
|
2301
|
+
opcode: 0x08,
|
|
2302
|
+
readOnly: false,
|
|
2303
|
+
rsv1: false
|
|
2304
|
+
};
|
|
2305
|
+
if (this._state !== DEFAULT) this.enqueue([
|
|
2306
|
+
this.dispatch,
|
|
2307
|
+
buf,
|
|
2308
|
+
false,
|
|
2309
|
+
options,
|
|
2310
|
+
cb
|
|
2311
|
+
]);
|
|
2312
|
+
else this.sendFrame(Sender.frame(buf, options), cb);
|
|
2313
|
+
}
|
|
2314
|
+
ping(data, mask, cb) {
|
|
2315
|
+
let byteLength;
|
|
2316
|
+
let readOnly;
|
|
2317
|
+
if ('string' == typeof data) {
|
|
2318
|
+
byteLength = Buffer.byteLength(data);
|
|
2319
|
+
readOnly = false;
|
|
2320
|
+
} else if (isBlob(data)) {
|
|
2321
|
+
byteLength = data.size;
|
|
2322
|
+
readOnly = false;
|
|
2323
|
+
} else {
|
|
2324
|
+
data = toBuffer(data);
|
|
2325
|
+
byteLength = data.length;
|
|
2326
|
+
readOnly = toBuffer.readOnly;
|
|
2327
|
+
}
|
|
2328
|
+
if (byteLength > 125) throw new RangeError('The data size must not be greater than 125 bytes');
|
|
2329
|
+
const options = {
|
|
2330
|
+
[kByteLength]: byteLength,
|
|
2331
|
+
fin: true,
|
|
2332
|
+
generateMask: this._generateMask,
|
|
2333
|
+
mask,
|
|
2334
|
+
maskBuffer: this._maskBuffer,
|
|
2335
|
+
opcode: 0x09,
|
|
2336
|
+
readOnly,
|
|
2337
|
+
rsv1: false
|
|
2338
|
+
};
|
|
2339
|
+
if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
|
|
2340
|
+
this.getBlobData,
|
|
2341
|
+
data,
|
|
2342
|
+
false,
|
|
2343
|
+
options,
|
|
2344
|
+
cb
|
|
2345
|
+
]);
|
|
2346
|
+
else this.getBlobData(data, false, options, cb);
|
|
2347
|
+
else if (this._state !== DEFAULT) this.enqueue([
|
|
2348
|
+
this.dispatch,
|
|
2349
|
+
data,
|
|
2350
|
+
false,
|
|
2351
|
+
options,
|
|
2352
|
+
cb
|
|
2353
|
+
]);
|
|
2354
|
+
else this.sendFrame(Sender.frame(data, options), cb);
|
|
2355
|
+
}
|
|
2356
|
+
pong(data, mask, cb) {
|
|
2357
|
+
let byteLength;
|
|
2358
|
+
let readOnly;
|
|
2359
|
+
if ('string' == typeof data) {
|
|
2360
|
+
byteLength = Buffer.byteLength(data);
|
|
2361
|
+
readOnly = false;
|
|
2362
|
+
} else if (isBlob(data)) {
|
|
2363
|
+
byteLength = data.size;
|
|
2364
|
+
readOnly = false;
|
|
2365
|
+
} else {
|
|
2366
|
+
data = toBuffer(data);
|
|
2367
|
+
byteLength = data.length;
|
|
2368
|
+
readOnly = toBuffer.readOnly;
|
|
2369
|
+
}
|
|
2370
|
+
if (byteLength > 125) throw new RangeError('The data size must not be greater than 125 bytes');
|
|
2371
|
+
const options = {
|
|
2372
|
+
[kByteLength]: byteLength,
|
|
2373
|
+
fin: true,
|
|
2374
|
+
generateMask: this._generateMask,
|
|
2375
|
+
mask,
|
|
2376
|
+
maskBuffer: this._maskBuffer,
|
|
2377
|
+
opcode: 0x0a,
|
|
2378
|
+
readOnly,
|
|
2379
|
+
rsv1: false
|
|
2380
|
+
};
|
|
2381
|
+
if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
|
|
2382
|
+
this.getBlobData,
|
|
2383
|
+
data,
|
|
2384
|
+
false,
|
|
2385
|
+
options,
|
|
2386
|
+
cb
|
|
2387
|
+
]);
|
|
2388
|
+
else this.getBlobData(data, false, options, cb);
|
|
2389
|
+
else if (this._state !== DEFAULT) this.enqueue([
|
|
2390
|
+
this.dispatch,
|
|
2391
|
+
data,
|
|
2392
|
+
false,
|
|
2393
|
+
options,
|
|
2394
|
+
cb
|
|
2395
|
+
]);
|
|
2396
|
+
else this.sendFrame(Sender.frame(data, options), cb);
|
|
2397
|
+
}
|
|
2398
|
+
send(data, options, cb) {
|
|
2399
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
2400
|
+
let opcode = options.binary ? 2 : 1;
|
|
2401
|
+
let rsv1 = options.compress;
|
|
2402
|
+
let byteLength;
|
|
2403
|
+
let readOnly;
|
|
2404
|
+
if ('string' == typeof data) {
|
|
2405
|
+
byteLength = Buffer.byteLength(data);
|
|
2406
|
+
readOnly = false;
|
|
2407
|
+
} else if (isBlob(data)) {
|
|
2408
|
+
byteLength = data.size;
|
|
2409
|
+
readOnly = false;
|
|
2410
|
+
} else {
|
|
2411
|
+
data = toBuffer(data);
|
|
2412
|
+
byteLength = data.length;
|
|
2413
|
+
readOnly = toBuffer.readOnly;
|
|
2414
|
+
}
|
|
2415
|
+
if (this._firstFragment) {
|
|
2416
|
+
this._firstFragment = false;
|
|
2417
|
+
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? 'server_no_context_takeover' : 'client_no_context_takeover']) rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
2418
|
+
this._compress = rsv1;
|
|
2419
|
+
} else {
|
|
2420
|
+
rsv1 = false;
|
|
2421
|
+
opcode = 0;
|
|
2422
|
+
}
|
|
2423
|
+
if (options.fin) this._firstFragment = true;
|
|
2424
|
+
const opts = {
|
|
2425
|
+
[kByteLength]: byteLength,
|
|
2426
|
+
fin: options.fin,
|
|
2427
|
+
generateMask: this._generateMask,
|
|
2428
|
+
mask: options.mask,
|
|
2429
|
+
maskBuffer: this._maskBuffer,
|
|
2430
|
+
opcode,
|
|
2431
|
+
readOnly,
|
|
2432
|
+
rsv1
|
|
2433
|
+
};
|
|
2434
|
+
if (isBlob(data)) if (this._state !== DEFAULT) this.enqueue([
|
|
2435
|
+
this.getBlobData,
|
|
2436
|
+
data,
|
|
2437
|
+
this._compress,
|
|
2438
|
+
opts,
|
|
2439
|
+
cb
|
|
2440
|
+
]);
|
|
2441
|
+
else this.getBlobData(data, this._compress, opts, cb);
|
|
2442
|
+
else if (this._state !== DEFAULT) this.enqueue([
|
|
2443
|
+
this.dispatch,
|
|
2444
|
+
data,
|
|
2445
|
+
this._compress,
|
|
2446
|
+
opts,
|
|
2447
|
+
cb
|
|
2448
|
+
]);
|
|
2449
|
+
else this.dispatch(data, this._compress, opts, cb);
|
|
2450
|
+
}
|
|
2451
|
+
getBlobData(blob, compress, options, cb) {
|
|
2452
|
+
this._bufferedBytes += options[kByteLength];
|
|
2453
|
+
this._state = GET_BLOB_DATA;
|
|
2454
|
+
blob.arrayBuffer().then((arrayBuffer)=>{
|
|
2455
|
+
if (this._socket.destroyed) {
|
|
2456
|
+
const err = new Error('The socket was closed while the blob was being read');
|
|
2457
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
2458
|
+
return;
|
|
2459
|
+
}
|
|
2460
|
+
this._bufferedBytes -= options[kByteLength];
|
|
2461
|
+
const data = toBuffer(arrayBuffer);
|
|
2462
|
+
if (compress) this.dispatch(data, compress, options, cb);
|
|
2463
|
+
else {
|
|
2464
|
+
this._state = DEFAULT;
|
|
2465
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
2466
|
+
this.dequeue();
|
|
2467
|
+
}
|
|
2468
|
+
}).catch((err)=>{
|
|
2469
|
+
process.nextTick(onError, this, err, cb);
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
dispatch(data, compress, options, cb) {
|
|
2473
|
+
if (!compress) return void this.sendFrame(Sender.frame(data, options), cb);
|
|
2474
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
2475
|
+
this._bufferedBytes += options[kByteLength];
|
|
2476
|
+
this._state = DEFLATING;
|
|
2477
|
+
perMessageDeflate.compress(data, options.fin, (_, buf)=>{
|
|
2478
|
+
if (this._socket.destroyed) {
|
|
2479
|
+
const err = new Error('The socket was closed while data was being compressed');
|
|
2480
|
+
callCallbacks(this, err, cb);
|
|
2481
|
+
return;
|
|
2482
|
+
}
|
|
2483
|
+
this._bufferedBytes -= options[kByteLength];
|
|
2484
|
+
this._state = DEFAULT;
|
|
2485
|
+
options.readOnly = false;
|
|
2486
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
2487
|
+
this.dequeue();
|
|
2488
|
+
});
|
|
2489
|
+
}
|
|
2490
|
+
dequeue() {
|
|
2491
|
+
while(this._state === DEFAULT && this._queue.length){
|
|
2492
|
+
const params = this._queue.shift();
|
|
2493
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
2494
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
enqueue(params) {
|
|
2498
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
2499
|
+
this._queue.push(params);
|
|
2500
|
+
}
|
|
2501
|
+
sendFrame(list, cb) {
|
|
2502
|
+
if (2 === list.length) {
|
|
2503
|
+
this._socket.cork();
|
|
2504
|
+
this._socket.write(list[0]);
|
|
2505
|
+
this._socket.write(list[1], cb);
|
|
2506
|
+
this._socket.uncork();
|
|
2507
|
+
} else this._socket.write(list[0], cb);
|
|
2508
|
+
}
|
|
2509
|
+
}
|
|
2510
|
+
module.exports = Sender;
|
|
2511
|
+
function callCallbacks(sender, err, cb) {
|
|
2512
|
+
if ('function' == typeof cb) cb(err);
|
|
2513
|
+
for(let i = 0; i < sender._queue.length; i++){
|
|
2514
|
+
const params = sender._queue[i];
|
|
2515
|
+
const callback = params[params.length - 1];
|
|
2516
|
+
if ('function' == typeof callback) callback(err);
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
function onError(sender, err, cb) {
|
|
2520
|
+
callCallbacks(sender, err, cb);
|
|
2521
|
+
sender.onerror(err);
|
|
2522
|
+
}
|
|
2523
|
+
},
|
|
2524
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/stream.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
2525
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js");
|
|
2526
|
+
const { Duplex } = __webpack_require__("stream");
|
|
2527
|
+
function emitClose(stream) {
|
|
2528
|
+
stream.emit('close');
|
|
2529
|
+
}
|
|
2530
|
+
function duplexOnEnd() {
|
|
2531
|
+
if (!this.destroyed && this._writableState.finished) this.destroy();
|
|
2532
|
+
}
|
|
2533
|
+
function duplexOnError(err) {
|
|
2534
|
+
this.removeListener('error', duplexOnError);
|
|
2535
|
+
this.destroy();
|
|
2536
|
+
if (0 === this.listenerCount('error')) this.emit('error', err);
|
|
2537
|
+
}
|
|
2538
|
+
function createWebSocketStream(ws, options) {
|
|
2539
|
+
let terminateOnDestroy = true;
|
|
2540
|
+
const duplex = new Duplex({
|
|
2541
|
+
...options,
|
|
2542
|
+
autoDestroy: false,
|
|
2543
|
+
emitClose: false,
|
|
2544
|
+
objectMode: false,
|
|
2545
|
+
writableObjectMode: false
|
|
2546
|
+
});
|
|
2547
|
+
ws.on('message', function(msg, isBinary) {
|
|
2548
|
+
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
2549
|
+
if (!duplex.push(data)) ws.pause();
|
|
2550
|
+
});
|
|
2551
|
+
ws.once('error', function(err) {
|
|
2552
|
+
if (duplex.destroyed) return;
|
|
2553
|
+
terminateOnDestroy = false;
|
|
2554
|
+
duplex.destroy(err);
|
|
2555
|
+
});
|
|
2556
|
+
ws.once('close', function() {
|
|
2557
|
+
if (duplex.destroyed) return;
|
|
2558
|
+
duplex.push(null);
|
|
2559
|
+
});
|
|
2560
|
+
duplex._destroy = function(err, callback) {
|
|
2561
|
+
if (ws.readyState === ws.CLOSED) {
|
|
2562
|
+
callback(err);
|
|
2563
|
+
process.nextTick(emitClose, duplex);
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
let called = false;
|
|
2567
|
+
ws.once('error', function(err) {
|
|
2568
|
+
called = true;
|
|
2569
|
+
callback(err);
|
|
2570
|
+
});
|
|
2571
|
+
ws.once('close', function() {
|
|
2572
|
+
if (!called) callback(err);
|
|
2573
|
+
process.nextTick(emitClose, duplex);
|
|
2574
|
+
});
|
|
2575
|
+
if (terminateOnDestroy) ws.terminate();
|
|
2576
|
+
};
|
|
2577
|
+
duplex._final = function(callback) {
|
|
2578
|
+
if (ws.readyState === ws.CONNECTING) return void ws.once('open', function() {
|
|
2579
|
+
duplex._final(callback);
|
|
2580
|
+
});
|
|
2581
|
+
if (null === ws._socket) return;
|
|
2582
|
+
if (ws._socket._writableState.finished) {
|
|
2583
|
+
callback();
|
|
2584
|
+
if (duplex._readableState.endEmitted) duplex.destroy();
|
|
2585
|
+
} else {
|
|
2586
|
+
ws._socket.once('finish', function() {
|
|
2587
|
+
callback();
|
|
2588
|
+
});
|
|
2589
|
+
ws.close();
|
|
2590
|
+
}
|
|
2591
|
+
};
|
|
2592
|
+
duplex._read = function() {
|
|
2593
|
+
if (ws.isPaused) ws.resume();
|
|
2594
|
+
};
|
|
2595
|
+
duplex._write = function(chunk, encoding, callback) {
|
|
2596
|
+
if (ws.readyState === ws.CONNECTING) return void ws.once('open', function() {
|
|
2597
|
+
duplex._write(chunk, encoding, callback);
|
|
2598
|
+
});
|
|
2599
|
+
ws.send(chunk, callback);
|
|
2600
|
+
};
|
|
2601
|
+
duplex.on('end', duplexOnEnd);
|
|
2602
|
+
duplex.on('error', duplexOnError);
|
|
2603
|
+
return duplex;
|
|
2604
|
+
}
|
|
2605
|
+
module.exports = createWebSocketStream;
|
|
2606
|
+
},
|
|
2607
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/subprotocol.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
2608
|
+
const { tokenChars } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js");
|
|
2609
|
+
function parse(header) {
|
|
2610
|
+
const protocols = new Set();
|
|
2611
|
+
let start = -1;
|
|
2612
|
+
let end = -1;
|
|
2613
|
+
let i = 0;
|
|
2614
|
+
for(i; i < header.length; i++){
|
|
2615
|
+
const code = header.charCodeAt(i);
|
|
2616
|
+
if (-1 === end && 1 === tokenChars[code]) {
|
|
2617
|
+
if (-1 === start) start = i;
|
|
2618
|
+
} else if (0 !== i && (0x20 === code || 0x09 === code)) {
|
|
2619
|
+
if (-1 === end && -1 !== start) end = i;
|
|
2620
|
+
} else if (0x2c === code) {
|
|
2621
|
+
if (-1 === start) throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
2622
|
+
if (-1 === end) end = i;
|
|
2623
|
+
const protocol = header.slice(start, end);
|
|
2624
|
+
if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
2625
|
+
protocols.add(protocol);
|
|
2626
|
+
start = end = -1;
|
|
2627
|
+
} else throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
2628
|
+
}
|
|
2629
|
+
if (-1 === start || -1 !== end) throw new SyntaxError('Unexpected end of input');
|
|
2630
|
+
const protocol = header.slice(start, i);
|
|
2631
|
+
if (protocols.has(protocol)) throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
2632
|
+
protocols.add(protocol);
|
|
2633
|
+
return protocols;
|
|
2634
|
+
}
|
|
2635
|
+
module.exports = {
|
|
2636
|
+
parse
|
|
2637
|
+
};
|
|
2638
|
+
},
|
|
2639
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
2640
|
+
const { isUtf8 } = __webpack_require__("buffer");
|
|
2641
|
+
const { hasBlob } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
2642
|
+
const tokenChars = [
|
|
2643
|
+
0,
|
|
2644
|
+
0,
|
|
2645
|
+
0,
|
|
2646
|
+
0,
|
|
2647
|
+
0,
|
|
2648
|
+
0,
|
|
2649
|
+
0,
|
|
2650
|
+
0,
|
|
2651
|
+
0,
|
|
2652
|
+
0,
|
|
2653
|
+
0,
|
|
2654
|
+
0,
|
|
2655
|
+
0,
|
|
2656
|
+
0,
|
|
2657
|
+
0,
|
|
2658
|
+
0,
|
|
2659
|
+
0,
|
|
2660
|
+
0,
|
|
2661
|
+
0,
|
|
2662
|
+
0,
|
|
2663
|
+
0,
|
|
2664
|
+
0,
|
|
2665
|
+
0,
|
|
2666
|
+
0,
|
|
2667
|
+
0,
|
|
2668
|
+
0,
|
|
2669
|
+
0,
|
|
2670
|
+
0,
|
|
2671
|
+
0,
|
|
2672
|
+
0,
|
|
2673
|
+
0,
|
|
2674
|
+
0,
|
|
2675
|
+
0,
|
|
2676
|
+
1,
|
|
2677
|
+
0,
|
|
2678
|
+
1,
|
|
2679
|
+
1,
|
|
2680
|
+
1,
|
|
2681
|
+
1,
|
|
2682
|
+
1,
|
|
2683
|
+
0,
|
|
2684
|
+
0,
|
|
2685
|
+
1,
|
|
2686
|
+
1,
|
|
2687
|
+
0,
|
|
2688
|
+
1,
|
|
2689
|
+
1,
|
|
2690
|
+
0,
|
|
2691
|
+
1,
|
|
2692
|
+
1,
|
|
2693
|
+
1,
|
|
2694
|
+
1,
|
|
2695
|
+
1,
|
|
2696
|
+
1,
|
|
2697
|
+
1,
|
|
2698
|
+
1,
|
|
2699
|
+
1,
|
|
2700
|
+
1,
|
|
2701
|
+
0,
|
|
2702
|
+
0,
|
|
2703
|
+
0,
|
|
2704
|
+
0,
|
|
2705
|
+
0,
|
|
2706
|
+
0,
|
|
2707
|
+
0,
|
|
2708
|
+
1,
|
|
2709
|
+
1,
|
|
2710
|
+
1,
|
|
2711
|
+
1,
|
|
2712
|
+
1,
|
|
2713
|
+
1,
|
|
2714
|
+
1,
|
|
2715
|
+
1,
|
|
2716
|
+
1,
|
|
2717
|
+
1,
|
|
2718
|
+
1,
|
|
2719
|
+
1,
|
|
2720
|
+
1,
|
|
2721
|
+
1,
|
|
2722
|
+
1,
|
|
2723
|
+
1,
|
|
2724
|
+
1,
|
|
2725
|
+
1,
|
|
2726
|
+
1,
|
|
2727
|
+
1,
|
|
2728
|
+
1,
|
|
2729
|
+
1,
|
|
2730
|
+
1,
|
|
2731
|
+
1,
|
|
2732
|
+
1,
|
|
2733
|
+
1,
|
|
2734
|
+
0,
|
|
2735
|
+
0,
|
|
2736
|
+
0,
|
|
2737
|
+
1,
|
|
2738
|
+
1,
|
|
2739
|
+
1,
|
|
2740
|
+
1,
|
|
2741
|
+
1,
|
|
2742
|
+
1,
|
|
2743
|
+
1,
|
|
2744
|
+
1,
|
|
2745
|
+
1,
|
|
2746
|
+
1,
|
|
2747
|
+
1,
|
|
2748
|
+
1,
|
|
2749
|
+
1,
|
|
2750
|
+
1,
|
|
2751
|
+
1,
|
|
2752
|
+
1,
|
|
2753
|
+
1,
|
|
2754
|
+
1,
|
|
2755
|
+
1,
|
|
2756
|
+
1,
|
|
2757
|
+
1,
|
|
2758
|
+
1,
|
|
2759
|
+
1,
|
|
2760
|
+
1,
|
|
2761
|
+
1,
|
|
2762
|
+
1,
|
|
2763
|
+
1,
|
|
2764
|
+
1,
|
|
2765
|
+
1,
|
|
2766
|
+
0,
|
|
2767
|
+
1,
|
|
2768
|
+
0,
|
|
2769
|
+
1,
|
|
2770
|
+
0
|
|
2771
|
+
];
|
|
2772
|
+
function isValidStatusCode(code) {
|
|
2773
|
+
return code >= 1000 && code <= 1014 && 1004 !== code && 1005 !== code && 1006 !== code || code >= 3000 && code <= 4999;
|
|
2774
|
+
}
|
|
2775
|
+
function _isValidUTF8(buf) {
|
|
2776
|
+
const len = buf.length;
|
|
2777
|
+
let i = 0;
|
|
2778
|
+
while(i < len)if ((0x80 & buf[i]) === 0) i++;
|
|
2779
|
+
else if ((0xe0 & buf[i]) === 0xc0) {
|
|
2780
|
+
if (i + 1 === len || (0xc0 & buf[i + 1]) !== 0x80 || (0xfe & buf[i]) === 0xc0) return false;
|
|
2781
|
+
i += 2;
|
|
2782
|
+
} else if ((0xf0 & buf[i]) === 0xe0) {
|
|
2783
|
+
if (i + 2 >= len || (0xc0 & buf[i + 1]) !== 0x80 || (0xc0 & buf[i + 2]) !== 0x80 || 0xe0 === buf[i] && (0xe0 & buf[i + 1]) === 0x80 || 0xed === buf[i] && (0xe0 & buf[i + 1]) === 0xa0) return false;
|
|
2784
|
+
i += 3;
|
|
2785
|
+
} else {
|
|
2786
|
+
if ((0xf8 & buf[i]) !== 0xf0) return false;
|
|
2787
|
+
if (i + 3 >= len || (0xc0 & buf[i + 1]) !== 0x80 || (0xc0 & buf[i + 2]) !== 0x80 || (0xc0 & buf[i + 3]) !== 0x80 || 0xf0 === buf[i] && (0xf0 & buf[i + 1]) === 0x80 || 0xf4 === buf[i] && buf[i + 1] > 0x8f || buf[i] > 0xf4) return false;
|
|
2788
|
+
i += 4;
|
|
2789
|
+
}
|
|
2790
|
+
return true;
|
|
2791
|
+
}
|
|
2792
|
+
function isBlob(value) {
|
|
2793
|
+
return hasBlob && 'object' == typeof value && 'function' == typeof value.arrayBuffer && 'string' == typeof value.type && 'function' == typeof value.stream && ('Blob' === value[Symbol.toStringTag] || 'File' === value[Symbol.toStringTag]);
|
|
2794
|
+
}
|
|
2795
|
+
module.exports = {
|
|
2796
|
+
isBlob,
|
|
2797
|
+
isValidStatusCode,
|
|
2798
|
+
isValidUTF8: _isValidUTF8,
|
|
2799
|
+
tokenChars
|
|
2800
|
+
};
|
|
2801
|
+
if (isUtf8) module.exports.isValidUTF8 = function(buf) {
|
|
2802
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
2803
|
+
};
|
|
2804
|
+
},
|
|
2805
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket-server.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
2806
|
+
const EventEmitter = __webpack_require__("events");
|
|
2807
|
+
const http = __webpack_require__("http");
|
|
2808
|
+
const { Duplex } = __webpack_require__("stream");
|
|
2809
|
+
const { createHash } = __webpack_require__("crypto");
|
|
2810
|
+
const extension = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js");
|
|
2811
|
+
const PerMessageDeflate = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js");
|
|
2812
|
+
const subprotocol = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/subprotocol.js");
|
|
2813
|
+
const WebSocket = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js");
|
|
2814
|
+
const { CLOSE_TIMEOUT, GUID, kWebSocket } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
2815
|
+
const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
2816
|
+
const RUNNING = 0;
|
|
2817
|
+
const CLOSING = 1;
|
|
2818
|
+
const CLOSED = 2;
|
|
2819
|
+
class WebSocketServer extends EventEmitter {
|
|
2820
|
+
constructor(options, callback){
|
|
2821
|
+
super();
|
|
2822
|
+
options = {
|
|
2823
|
+
allowSynchronousEvents: true,
|
|
2824
|
+
autoPong: true,
|
|
2825
|
+
maxPayload: 104857600,
|
|
2826
|
+
skipUTF8Validation: false,
|
|
2827
|
+
perMessageDeflate: false,
|
|
2828
|
+
handleProtocols: null,
|
|
2829
|
+
clientTracking: true,
|
|
2830
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
2831
|
+
verifyClient: null,
|
|
2832
|
+
noServer: false,
|
|
2833
|
+
backlog: null,
|
|
2834
|
+
server: null,
|
|
2835
|
+
host: null,
|
|
2836
|
+
path: null,
|
|
2837
|
+
port: null,
|
|
2838
|
+
WebSocket,
|
|
2839
|
+
...options
|
|
2840
|
+
};
|
|
2841
|
+
if (null == options.port && !options.server && !options.noServer || null != options.port && (options.server || options.noServer) || options.server && options.noServer) throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');
|
|
2842
|
+
if (null != options.port) {
|
|
2843
|
+
this._server = http.createServer((req, res)=>{
|
|
2844
|
+
const body = http.STATUS_CODES[426];
|
|
2845
|
+
res.writeHead(426, {
|
|
2846
|
+
'Content-Length': body.length,
|
|
2847
|
+
'Content-Type': 'text/plain'
|
|
2848
|
+
});
|
|
2849
|
+
res.end(body);
|
|
2850
|
+
});
|
|
2851
|
+
this._server.listen(options.port, options.host, options.backlog, callback);
|
|
2852
|
+
} else if (options.server) this._server = options.server;
|
|
2853
|
+
if (this._server) {
|
|
2854
|
+
const emitConnection = this.emit.bind(this, 'connection');
|
|
2855
|
+
this._removeListeners = addListeners(this._server, {
|
|
2856
|
+
listening: this.emit.bind(this, 'listening'),
|
|
2857
|
+
error: this.emit.bind(this, 'error'),
|
|
2858
|
+
upgrade: (req, socket, head)=>{
|
|
2859
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
2860
|
+
}
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
if (true === options.perMessageDeflate) options.perMessageDeflate = {};
|
|
2864
|
+
if (options.clientTracking) {
|
|
2865
|
+
this.clients = new Set();
|
|
2866
|
+
this._shouldEmitClose = false;
|
|
2867
|
+
}
|
|
2868
|
+
this.options = options;
|
|
2869
|
+
this._state = RUNNING;
|
|
2870
|
+
}
|
|
2871
|
+
address() {
|
|
2872
|
+
if (this.options.noServer) throw new Error('The server is operating in "noServer" mode');
|
|
2873
|
+
if (!this._server) return null;
|
|
2874
|
+
return this._server.address();
|
|
2875
|
+
}
|
|
2876
|
+
close(cb) {
|
|
2877
|
+
if (this._state === CLOSED) {
|
|
2878
|
+
if (cb) this.once('close', ()=>{
|
|
2879
|
+
cb(new Error('The server is not running'));
|
|
2880
|
+
});
|
|
2881
|
+
process.nextTick(emitClose, this);
|
|
2882
|
+
return;
|
|
2883
|
+
}
|
|
2884
|
+
if (cb) this.once('close', cb);
|
|
2885
|
+
if (this._state === CLOSING) return;
|
|
2886
|
+
this._state = CLOSING;
|
|
2887
|
+
if (this.options.noServer || this.options.server) {
|
|
2888
|
+
if (this._server) {
|
|
2889
|
+
this._removeListeners();
|
|
2890
|
+
this._removeListeners = this._server = null;
|
|
2891
|
+
}
|
|
2892
|
+
if (this.clients) if (this.clients.size) this._shouldEmitClose = true;
|
|
2893
|
+
else process.nextTick(emitClose, this);
|
|
2894
|
+
else process.nextTick(emitClose, this);
|
|
2895
|
+
} else {
|
|
2896
|
+
const server = this._server;
|
|
2897
|
+
this._removeListeners();
|
|
2898
|
+
this._removeListeners = this._server = null;
|
|
2899
|
+
server.close(()=>{
|
|
2900
|
+
emitClose(this);
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
shouldHandle(req) {
|
|
2905
|
+
if (this.options.path) {
|
|
2906
|
+
const index = req.url.indexOf('?');
|
|
2907
|
+
const pathname = -1 !== index ? req.url.slice(0, index) : req.url;
|
|
2908
|
+
if (pathname !== this.options.path) return false;
|
|
2909
|
+
}
|
|
2910
|
+
return true;
|
|
2911
|
+
}
|
|
2912
|
+
handleUpgrade(req, socket, head, cb) {
|
|
2913
|
+
socket.on('error', socketOnError);
|
|
2914
|
+
const key = req.headers['sec-websocket-key'];
|
|
2915
|
+
const upgrade = req.headers.upgrade;
|
|
2916
|
+
const version = +req.headers['sec-websocket-version'];
|
|
2917
|
+
if ('GET' !== req.method) {
|
|
2918
|
+
const message = 'Invalid HTTP method';
|
|
2919
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
2920
|
+
return;
|
|
2921
|
+
}
|
|
2922
|
+
if (void 0 === upgrade || 'websocket' !== upgrade.toLowerCase()) {
|
|
2923
|
+
const message = 'Invalid Upgrade header';
|
|
2924
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2925
|
+
return;
|
|
2926
|
+
}
|
|
2927
|
+
if (void 0 === key || !keyRegex.test(key)) {
|
|
2928
|
+
const message = 'Missing or invalid Sec-WebSocket-Key header';
|
|
2929
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
if (13 !== version && 8 !== version) {
|
|
2933
|
+
const message = 'Missing or invalid Sec-WebSocket-Version header';
|
|
2934
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
2935
|
+
'Sec-WebSocket-Version': '13, 8'
|
|
2936
|
+
});
|
|
2937
|
+
return;
|
|
2938
|
+
}
|
|
2939
|
+
if (!this.shouldHandle(req)) return void abortHandshake(socket, 400);
|
|
2940
|
+
const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
|
|
2941
|
+
let protocols = new Set();
|
|
2942
|
+
if (void 0 !== secWebSocketProtocol) try {
|
|
2943
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
2944
|
+
} catch (err) {
|
|
2945
|
+
const message = 'Invalid Sec-WebSocket-Protocol header';
|
|
2946
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2947
|
+
return;
|
|
2948
|
+
}
|
|
2949
|
+
const secWebSocketExtensions = req.headers['sec-websocket-extensions'];
|
|
2950
|
+
const extensions = {};
|
|
2951
|
+
if (this.options.perMessageDeflate && void 0 !== secWebSocketExtensions) {
|
|
2952
|
+
const perMessageDeflate = new PerMessageDeflate({
|
|
2953
|
+
...this.options.perMessageDeflate,
|
|
2954
|
+
isServer: true,
|
|
2955
|
+
maxPayload: this.options.maxPayload
|
|
2956
|
+
});
|
|
2957
|
+
try {
|
|
2958
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
2959
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
2960
|
+
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
2961
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
2962
|
+
}
|
|
2963
|
+
} catch (err) {
|
|
2964
|
+
const message = 'Invalid or unacceptable Sec-WebSocket-Extensions header';
|
|
2965
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2966
|
+
return;
|
|
2967
|
+
}
|
|
2968
|
+
}
|
|
2969
|
+
if (this.options.verifyClient) {
|
|
2970
|
+
const info = {
|
|
2971
|
+
origin: req.headers[`${8 === version ? 'sec-websocket-origin' : 'origin'}`],
|
|
2972
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
2973
|
+
req
|
|
2974
|
+
};
|
|
2975
|
+
if (2 === this.options.verifyClient.length) return void this.options.verifyClient(info, (verified, code, message, headers)=>{
|
|
2976
|
+
if (!verified) return abortHandshake(socket, code || 401, message, headers);
|
|
2977
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
2978
|
+
});
|
|
2979
|
+
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
2980
|
+
}
|
|
2981
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
2982
|
+
}
|
|
2983
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
2984
|
+
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
2985
|
+
if (socket[kWebSocket]) throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
|
|
2986
|
+
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
2987
|
+
const digest = createHash('sha1').update(key + GUID).digest('base64');
|
|
2988
|
+
const headers = [
|
|
2989
|
+
'HTTP/1.1 101 Switching Protocols',
|
|
2990
|
+
'Upgrade: websocket',
|
|
2991
|
+
'Connection: Upgrade',
|
|
2992
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
2993
|
+
];
|
|
2994
|
+
const ws = new this.options.WebSocket(null, void 0, this.options);
|
|
2995
|
+
if (protocols.size) {
|
|
2996
|
+
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
2997
|
+
if (protocol) {
|
|
2998
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
2999
|
+
ws._protocol = protocol;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
3003
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
3004
|
+
const value = extension.format({
|
|
3005
|
+
[PerMessageDeflate.extensionName]: [
|
|
3006
|
+
params
|
|
3007
|
+
]
|
|
3008
|
+
});
|
|
3009
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
3010
|
+
ws._extensions = extensions;
|
|
3011
|
+
}
|
|
3012
|
+
this.emit('headers', headers, req);
|
|
3013
|
+
socket.write(headers.concat('\r\n').join('\r\n'));
|
|
3014
|
+
socket.removeListener('error', socketOnError);
|
|
3015
|
+
ws.setSocket(socket, head, {
|
|
3016
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
3017
|
+
maxPayload: this.options.maxPayload,
|
|
3018
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
3019
|
+
});
|
|
3020
|
+
if (this.clients) {
|
|
3021
|
+
this.clients.add(ws);
|
|
3022
|
+
ws.on('close', ()=>{
|
|
3023
|
+
this.clients.delete(ws);
|
|
3024
|
+
if (this._shouldEmitClose && !this.clients.size) process.nextTick(emitClose, this);
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
cb(ws, req);
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
module.exports = WebSocketServer;
|
|
3031
|
+
function addListeners(server, map) {
|
|
3032
|
+
for (const event of Object.keys(map))server.on(event, map[event]);
|
|
3033
|
+
return function() {
|
|
3034
|
+
for (const event of Object.keys(map))server.removeListener(event, map[event]);
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
function emitClose(server) {
|
|
3038
|
+
server._state = CLOSED;
|
|
3039
|
+
server.emit('close');
|
|
3040
|
+
}
|
|
3041
|
+
function socketOnError() {
|
|
3042
|
+
this.destroy();
|
|
3043
|
+
}
|
|
3044
|
+
function abortHandshake(socket, code, message, headers) {
|
|
3045
|
+
message = message || http.STATUS_CODES[code];
|
|
3046
|
+
headers = {
|
|
3047
|
+
Connection: 'close',
|
|
3048
|
+
'Content-Type': 'text/html',
|
|
3049
|
+
'Content-Length': Buffer.byteLength(message),
|
|
3050
|
+
...headers
|
|
3051
|
+
};
|
|
3052
|
+
socket.once('finish', socket.destroy);
|
|
3053
|
+
socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + Object.keys(headers).map((h)=>`${h}: ${headers[h]}`).join('\r\n') + '\r\n\r\n' + message);
|
|
3054
|
+
}
|
|
3055
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
3056
|
+
if (server.listenerCount('wsClientError')) {
|
|
3057
|
+
const err = new Error(message);
|
|
3058
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
3059
|
+
server.emit('wsClientError', err, socket, req);
|
|
3060
|
+
} else abortHandshake(socket, code, message, headers);
|
|
3061
|
+
}
|
|
3062
|
+
},
|
|
3063
|
+
"./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
3064
|
+
const EventEmitter = __webpack_require__("events");
|
|
3065
|
+
const https = __webpack_require__("https");
|
|
3066
|
+
const http = __webpack_require__("http");
|
|
3067
|
+
const net = __webpack_require__("net");
|
|
3068
|
+
const tls = __webpack_require__("tls");
|
|
3069
|
+
const { randomBytes, createHash } = __webpack_require__("crypto");
|
|
3070
|
+
const { Duplex, Readable } = __webpack_require__("stream");
|
|
3071
|
+
const { URL: URL1 } = __webpack_require__("url");
|
|
3072
|
+
const PerMessageDeflate = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js");
|
|
3073
|
+
const Receiver = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/receiver.js");
|
|
3074
|
+
const Sender = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/sender.js");
|
|
3075
|
+
const { isBlob } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/validation.js");
|
|
3076
|
+
const { BINARY_TYPES, CLOSE_TIMEOUT, EMPTY_BUFFER, GUID, kForOnEventAttribute, kListener, kStatusCode, kWebSocket, NOOP } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/constants.js");
|
|
3077
|
+
const { EventTarget: { addEventListener, removeEventListener } } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/event-target.js");
|
|
3078
|
+
const { format, parse } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js");
|
|
3079
|
+
const { toBuffer } = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/buffer-util.js");
|
|
3080
|
+
const kAborted = Symbol('kAborted');
|
|
3081
|
+
const protocolVersions = [
|
|
3082
|
+
8,
|
|
3083
|
+
13
|
|
3084
|
+
];
|
|
3085
|
+
const readyStates = [
|
|
3086
|
+
'CONNECTING',
|
|
3087
|
+
'OPEN',
|
|
3088
|
+
'CLOSING',
|
|
3089
|
+
'CLOSED'
|
|
3090
|
+
];
|
|
3091
|
+
const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
3092
|
+
class WebSocket extends EventEmitter {
|
|
3093
|
+
constructor(address, protocols, options){
|
|
3094
|
+
super();
|
|
3095
|
+
this._binaryType = BINARY_TYPES[0];
|
|
3096
|
+
this._closeCode = 1006;
|
|
3097
|
+
this._closeFrameReceived = false;
|
|
3098
|
+
this._closeFrameSent = false;
|
|
3099
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
3100
|
+
this._closeTimer = null;
|
|
3101
|
+
this._errorEmitted = false;
|
|
3102
|
+
this._extensions = {};
|
|
3103
|
+
this._paused = false;
|
|
3104
|
+
this._protocol = '';
|
|
3105
|
+
this._readyState = WebSocket.CONNECTING;
|
|
3106
|
+
this._receiver = null;
|
|
3107
|
+
this._sender = null;
|
|
3108
|
+
this._socket = null;
|
|
3109
|
+
if (null !== address) {
|
|
3110
|
+
this._bufferedAmount = 0;
|
|
3111
|
+
this._isServer = false;
|
|
3112
|
+
this._redirects = 0;
|
|
3113
|
+
if (void 0 === protocols) protocols = [];
|
|
3114
|
+
else if (!Array.isArray(protocols)) if ('object' == typeof protocols && null !== protocols) {
|
|
3115
|
+
options = protocols;
|
|
3116
|
+
protocols = [];
|
|
3117
|
+
} else protocols = [
|
|
3118
|
+
protocols
|
|
3119
|
+
];
|
|
3120
|
+
initAsClient(this, address, protocols, options);
|
|
3121
|
+
} else {
|
|
3122
|
+
this._autoPong = options.autoPong;
|
|
3123
|
+
this._closeTimeout = options.closeTimeout;
|
|
3124
|
+
this._isServer = true;
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
get binaryType() {
|
|
3128
|
+
return this._binaryType;
|
|
3129
|
+
}
|
|
3130
|
+
set binaryType(type) {
|
|
3131
|
+
if (!BINARY_TYPES.includes(type)) return;
|
|
3132
|
+
this._binaryType = type;
|
|
3133
|
+
if (this._receiver) this._receiver._binaryType = type;
|
|
3134
|
+
}
|
|
3135
|
+
get bufferedAmount() {
|
|
3136
|
+
if (!this._socket) return this._bufferedAmount;
|
|
3137
|
+
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
3138
|
+
}
|
|
3139
|
+
get extensions() {
|
|
3140
|
+
return Object.keys(this._extensions).join();
|
|
3141
|
+
}
|
|
3142
|
+
get isPaused() {
|
|
3143
|
+
return this._paused;
|
|
3144
|
+
}
|
|
3145
|
+
get onclose() {
|
|
3146
|
+
return null;
|
|
3147
|
+
}
|
|
3148
|
+
get onerror() {
|
|
3149
|
+
return null;
|
|
3150
|
+
}
|
|
3151
|
+
get onopen() {
|
|
3152
|
+
return null;
|
|
3153
|
+
}
|
|
3154
|
+
get onmessage() {
|
|
3155
|
+
return null;
|
|
3156
|
+
}
|
|
3157
|
+
get protocol() {
|
|
3158
|
+
return this._protocol;
|
|
3159
|
+
}
|
|
3160
|
+
get readyState() {
|
|
3161
|
+
return this._readyState;
|
|
3162
|
+
}
|
|
3163
|
+
get url() {
|
|
3164
|
+
return this._url;
|
|
3165
|
+
}
|
|
3166
|
+
setSocket(socket, head, options) {
|
|
3167
|
+
const receiver = new Receiver({
|
|
3168
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
3169
|
+
binaryType: this.binaryType,
|
|
3170
|
+
extensions: this._extensions,
|
|
3171
|
+
isServer: this._isServer,
|
|
3172
|
+
maxPayload: options.maxPayload,
|
|
3173
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
3174
|
+
});
|
|
3175
|
+
const sender = new Sender(socket, this._extensions, options.generateMask);
|
|
3176
|
+
this._receiver = receiver;
|
|
3177
|
+
this._sender = sender;
|
|
3178
|
+
this._socket = socket;
|
|
3179
|
+
receiver[kWebSocket] = this;
|
|
3180
|
+
sender[kWebSocket] = this;
|
|
3181
|
+
socket[kWebSocket] = this;
|
|
3182
|
+
receiver.on('conclude', receiverOnConclude);
|
|
3183
|
+
receiver.on('drain', receiverOnDrain);
|
|
3184
|
+
receiver.on('error', receiverOnError);
|
|
3185
|
+
receiver.on('message', receiverOnMessage);
|
|
3186
|
+
receiver.on('ping', receiverOnPing);
|
|
3187
|
+
receiver.on('pong', receiverOnPong);
|
|
3188
|
+
sender.onerror = senderOnError;
|
|
3189
|
+
if (socket.setTimeout) socket.setTimeout(0);
|
|
3190
|
+
if (socket.setNoDelay) socket.setNoDelay();
|
|
3191
|
+
if (head.length > 0) socket.unshift(head);
|
|
3192
|
+
socket.on('close', socketOnClose);
|
|
3193
|
+
socket.on('data', socketOnData);
|
|
3194
|
+
socket.on('end', socketOnEnd);
|
|
3195
|
+
socket.on('error', socketOnError);
|
|
3196
|
+
this._readyState = WebSocket.OPEN;
|
|
3197
|
+
this.emit('open');
|
|
3198
|
+
}
|
|
3199
|
+
emitClose() {
|
|
3200
|
+
if (!this._socket) {
|
|
3201
|
+
this._readyState = WebSocket.CLOSED;
|
|
3202
|
+
this.emit('close', this._closeCode, this._closeMessage);
|
|
3203
|
+
return;
|
|
3204
|
+
}
|
|
3205
|
+
if (this._extensions[PerMessageDeflate.extensionName]) this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
3206
|
+
this._receiver.removeAllListeners();
|
|
3207
|
+
this._readyState = WebSocket.CLOSED;
|
|
3208
|
+
this.emit('close', this._closeCode, this._closeMessage);
|
|
3209
|
+
}
|
|
3210
|
+
close(code, data) {
|
|
3211
|
+
if (this.readyState === WebSocket.CLOSED) return;
|
|
3212
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3213
|
+
const msg = 'WebSocket was closed before the connection was established';
|
|
3214
|
+
abortHandshake(this, this._req, msg);
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
3218
|
+
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) this._socket.end();
|
|
3219
|
+
return;
|
|
3220
|
+
}
|
|
3221
|
+
this._readyState = WebSocket.CLOSING;
|
|
3222
|
+
this._sender.close(code, data, !this._isServer, (err)=>{
|
|
3223
|
+
if (err) return;
|
|
3224
|
+
this._closeFrameSent = true;
|
|
3225
|
+
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) this._socket.end();
|
|
3226
|
+
});
|
|
3227
|
+
setCloseTimer(this);
|
|
3228
|
+
}
|
|
3229
|
+
pause() {
|
|
3230
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
|
|
3231
|
+
this._paused = true;
|
|
3232
|
+
this._socket.pause();
|
|
3233
|
+
}
|
|
3234
|
+
ping(data, mask, cb) {
|
|
3235
|
+
if (this.readyState === WebSocket.CONNECTING) throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
3236
|
+
if ('function' == typeof data) {
|
|
3237
|
+
cb = data;
|
|
3238
|
+
data = mask = void 0;
|
|
3239
|
+
} else if ('function' == typeof mask) {
|
|
3240
|
+
cb = mask;
|
|
3241
|
+
mask = void 0;
|
|
3242
|
+
}
|
|
3243
|
+
if ('number' == typeof data) data = data.toString();
|
|
3244
|
+
if (this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
|
|
3245
|
+
if (void 0 === mask) mask = !this._isServer;
|
|
3246
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
3247
|
+
}
|
|
3248
|
+
pong(data, mask, cb) {
|
|
3249
|
+
if (this.readyState === WebSocket.CONNECTING) throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
3250
|
+
if ('function' == typeof data) {
|
|
3251
|
+
cb = data;
|
|
3252
|
+
data = mask = void 0;
|
|
3253
|
+
} else if ('function' == typeof mask) {
|
|
3254
|
+
cb = mask;
|
|
3255
|
+
mask = void 0;
|
|
3256
|
+
}
|
|
3257
|
+
if ('number' == typeof data) data = data.toString();
|
|
3258
|
+
if (this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
|
|
3259
|
+
if (void 0 === mask) mask = !this._isServer;
|
|
3260
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
3261
|
+
}
|
|
3262
|
+
resume() {
|
|
3263
|
+
if (this.readyState === WebSocket.CONNECTING || this.readyState === WebSocket.CLOSED) return;
|
|
3264
|
+
this._paused = false;
|
|
3265
|
+
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
3266
|
+
}
|
|
3267
|
+
send(data, options, cb) {
|
|
3268
|
+
if (this.readyState === WebSocket.CONNECTING) throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
3269
|
+
if ('function' == typeof options) {
|
|
3270
|
+
cb = options;
|
|
3271
|
+
options = {};
|
|
3272
|
+
}
|
|
3273
|
+
if ('number' == typeof data) data = data.toString();
|
|
3274
|
+
if (this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
|
|
3275
|
+
const opts = {
|
|
3276
|
+
binary: 'string' != typeof data,
|
|
3277
|
+
mask: !this._isServer,
|
|
3278
|
+
compress: true,
|
|
3279
|
+
fin: true,
|
|
3280
|
+
...options
|
|
3281
|
+
};
|
|
3282
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) opts.compress = false;
|
|
3283
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
3284
|
+
}
|
|
3285
|
+
terminate() {
|
|
3286
|
+
if (this.readyState === WebSocket.CLOSED) return;
|
|
3287
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
3288
|
+
const msg = 'WebSocket was closed before the connection was established';
|
|
3289
|
+
abortHandshake(this, this._req, msg);
|
|
3290
|
+
return;
|
|
3291
|
+
}
|
|
3292
|
+
if (this._socket) {
|
|
3293
|
+
this._readyState = WebSocket.CLOSING;
|
|
3294
|
+
this._socket.destroy();
|
|
3295
|
+
}
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
Object.defineProperty(WebSocket, 'CONNECTING', {
|
|
3299
|
+
enumerable: true,
|
|
3300
|
+
value: readyStates.indexOf('CONNECTING')
|
|
3301
|
+
});
|
|
3302
|
+
Object.defineProperty(WebSocket.prototype, 'CONNECTING', {
|
|
3303
|
+
enumerable: true,
|
|
3304
|
+
value: readyStates.indexOf('CONNECTING')
|
|
3305
|
+
});
|
|
3306
|
+
Object.defineProperty(WebSocket, 'OPEN', {
|
|
3307
|
+
enumerable: true,
|
|
3308
|
+
value: readyStates.indexOf('OPEN')
|
|
3309
|
+
});
|
|
3310
|
+
Object.defineProperty(WebSocket.prototype, 'OPEN', {
|
|
3311
|
+
enumerable: true,
|
|
3312
|
+
value: readyStates.indexOf('OPEN')
|
|
3313
|
+
});
|
|
3314
|
+
Object.defineProperty(WebSocket, 'CLOSING', {
|
|
3315
|
+
enumerable: true,
|
|
3316
|
+
value: readyStates.indexOf('CLOSING')
|
|
3317
|
+
});
|
|
3318
|
+
Object.defineProperty(WebSocket.prototype, 'CLOSING', {
|
|
3319
|
+
enumerable: true,
|
|
3320
|
+
value: readyStates.indexOf('CLOSING')
|
|
3321
|
+
});
|
|
3322
|
+
Object.defineProperty(WebSocket, 'CLOSED', {
|
|
3323
|
+
enumerable: true,
|
|
3324
|
+
value: readyStates.indexOf('CLOSED')
|
|
3325
|
+
});
|
|
3326
|
+
Object.defineProperty(WebSocket.prototype, 'CLOSED', {
|
|
3327
|
+
enumerable: true,
|
|
3328
|
+
value: readyStates.indexOf('CLOSED')
|
|
3329
|
+
});
|
|
3330
|
+
[
|
|
3331
|
+
'binaryType',
|
|
3332
|
+
'bufferedAmount',
|
|
3333
|
+
'extensions',
|
|
3334
|
+
'isPaused',
|
|
3335
|
+
'protocol',
|
|
3336
|
+
'readyState',
|
|
3337
|
+
'url'
|
|
3338
|
+
].forEach((property)=>{
|
|
3339
|
+
Object.defineProperty(WebSocket.prototype, property, {
|
|
3340
|
+
enumerable: true
|
|
3341
|
+
});
|
|
3342
|
+
});
|
|
3343
|
+
[
|
|
3344
|
+
'open',
|
|
3345
|
+
'error',
|
|
3346
|
+
'close',
|
|
3347
|
+
'message'
|
|
3348
|
+
].forEach((method)=>{
|
|
3349
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
3350
|
+
enumerable: true,
|
|
3351
|
+
get () {
|
|
3352
|
+
for (const listener of this.listeners(method))if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
3353
|
+
return null;
|
|
3354
|
+
},
|
|
3355
|
+
set (handler) {
|
|
3356
|
+
for (const listener of this.listeners(method))if (listener[kForOnEventAttribute]) {
|
|
3357
|
+
this.removeListener(method, listener);
|
|
3358
|
+
break;
|
|
3359
|
+
}
|
|
3360
|
+
if ('function' != typeof handler) return;
|
|
3361
|
+
this.addEventListener(method, handler, {
|
|
3362
|
+
[kForOnEventAttribute]: true
|
|
3363
|
+
});
|
|
3364
|
+
}
|
|
3365
|
+
});
|
|
3366
|
+
});
|
|
3367
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
3368
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
3369
|
+
module.exports = WebSocket;
|
|
3370
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
3371
|
+
const opts = {
|
|
3372
|
+
allowSynchronousEvents: true,
|
|
3373
|
+
autoPong: true,
|
|
3374
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
3375
|
+
protocolVersion: protocolVersions[1],
|
|
3376
|
+
maxPayload: 104857600,
|
|
3377
|
+
skipUTF8Validation: false,
|
|
3378
|
+
perMessageDeflate: true,
|
|
3379
|
+
followRedirects: false,
|
|
3380
|
+
maxRedirects: 10,
|
|
3381
|
+
...options,
|
|
3382
|
+
socketPath: void 0,
|
|
3383
|
+
hostname: void 0,
|
|
3384
|
+
protocol: void 0,
|
|
3385
|
+
timeout: void 0,
|
|
3386
|
+
method: 'GET',
|
|
3387
|
+
host: void 0,
|
|
3388
|
+
path: void 0,
|
|
3389
|
+
port: void 0
|
|
3390
|
+
};
|
|
3391
|
+
websocket._autoPong = opts.autoPong;
|
|
3392
|
+
websocket._closeTimeout = opts.closeTimeout;
|
|
3393
|
+
if (!protocolVersions.includes(opts.protocolVersion)) throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(', ')})`);
|
|
3394
|
+
let parsedUrl;
|
|
3395
|
+
if (address instanceof URL1) parsedUrl = address;
|
|
3396
|
+
else try {
|
|
3397
|
+
parsedUrl = new URL1(address);
|
|
3398
|
+
} catch {
|
|
3399
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
3400
|
+
}
|
|
3401
|
+
if ('http:' === parsedUrl.protocol) parsedUrl.protocol = 'ws:';
|
|
3402
|
+
else if ('https:' === parsedUrl.protocol) parsedUrl.protocol = 'wss:';
|
|
3403
|
+
websocket._url = parsedUrl.href;
|
|
3404
|
+
const isSecure = 'wss:' === parsedUrl.protocol;
|
|
3405
|
+
const isIpcUrl = 'ws+unix:' === parsedUrl.protocol;
|
|
3406
|
+
let invalidUrlMessage;
|
|
3407
|
+
if ('ws:' === parsedUrl.protocol || isSecure || isIpcUrl) {
|
|
3408
|
+
if (isIpcUrl && !parsedUrl.pathname) invalidUrlMessage = "The URL's pathname is empty";
|
|
3409
|
+
else if (parsedUrl.hash) invalidUrlMessage = 'The URL contains a fragment identifier';
|
|
3410
|
+
} else invalidUrlMessage = 'The URL\'s protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"';
|
|
3411
|
+
if (invalidUrlMessage) {
|
|
3412
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
3413
|
+
if (0 !== websocket._redirects) return void emitErrorAndClose(websocket, err);
|
|
3414
|
+
throw err;
|
|
3415
|
+
}
|
|
3416
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
3417
|
+
const key = randomBytes(16).toString('base64');
|
|
3418
|
+
const request = isSecure ? https.request : http.request;
|
|
3419
|
+
const protocolSet = new Set();
|
|
3420
|
+
let perMessageDeflate;
|
|
3421
|
+
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
3422
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
3423
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
3424
|
+
opts.host = parsedUrl.hostname.startsWith('[') ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
3425
|
+
opts.headers = {
|
|
3426
|
+
...opts.headers,
|
|
3427
|
+
'Sec-WebSocket-Version': opts.protocolVersion,
|
|
3428
|
+
'Sec-WebSocket-Key': key,
|
|
3429
|
+
Connection: 'Upgrade',
|
|
3430
|
+
Upgrade: 'websocket'
|
|
3431
|
+
};
|
|
3432
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
3433
|
+
opts.timeout = opts.handshakeTimeout;
|
|
3434
|
+
if (opts.perMessageDeflate) {
|
|
3435
|
+
perMessageDeflate = new PerMessageDeflate({
|
|
3436
|
+
...opts.perMessageDeflate,
|
|
3437
|
+
isServer: false,
|
|
3438
|
+
maxPayload: opts.maxPayload
|
|
3439
|
+
});
|
|
3440
|
+
opts.headers['Sec-WebSocket-Extensions'] = format({
|
|
3441
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
3442
|
+
});
|
|
3443
|
+
}
|
|
3444
|
+
if (protocols.length) {
|
|
3445
|
+
for (const protocol of protocols){
|
|
3446
|
+
if ('string' != typeof protocol || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) throw new SyntaxError('An invalid or duplicated subprotocol was specified');
|
|
3447
|
+
protocolSet.add(protocol);
|
|
3448
|
+
}
|
|
3449
|
+
opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
|
|
3450
|
+
}
|
|
3451
|
+
if (opts.origin) if (opts.protocolVersion < 13) opts.headers['Sec-WebSocket-Origin'] = opts.origin;
|
|
3452
|
+
else opts.headers.Origin = opts.origin;
|
|
3453
|
+
if (parsedUrl.username || parsedUrl.password) opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
3454
|
+
if (isIpcUrl) {
|
|
3455
|
+
const parts = opts.path.split(':');
|
|
3456
|
+
opts.socketPath = parts[0];
|
|
3457
|
+
opts.path = parts[1];
|
|
3458
|
+
}
|
|
3459
|
+
let req;
|
|
3460
|
+
if (opts.followRedirects) {
|
|
3461
|
+
if (0 === websocket._redirects) {
|
|
3462
|
+
websocket._originalIpc = isIpcUrl;
|
|
3463
|
+
websocket._originalSecure = isSecure;
|
|
3464
|
+
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
3465
|
+
const headers = options && options.headers;
|
|
3466
|
+
options = {
|
|
3467
|
+
...options,
|
|
3468
|
+
headers: {}
|
|
3469
|
+
};
|
|
3470
|
+
if (headers) for (const [key, value] of Object.entries(headers))options.headers[key.toLowerCase()] = value;
|
|
3471
|
+
} else if (0 === websocket.listenerCount('redirect')) {
|
|
3472
|
+
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
3473
|
+
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
3474
|
+
delete opts.headers.authorization;
|
|
3475
|
+
delete opts.headers.cookie;
|
|
3476
|
+
if (!isSameHost) delete opts.headers.host;
|
|
3477
|
+
opts.auth = void 0;
|
|
3478
|
+
}
|
|
3479
|
+
}
|
|
3480
|
+
if (opts.auth && !options.headers.authorization) options.headers.authorization = 'Basic ' + Buffer.from(opts.auth).toString('base64');
|
|
3481
|
+
req = websocket._req = request(opts);
|
|
3482
|
+
if (websocket._redirects) websocket.emit('redirect', websocket.url, req);
|
|
3483
|
+
} else req = websocket._req = request(opts);
|
|
3484
|
+
if (opts.timeout) req.on('timeout', ()=>{
|
|
3485
|
+
abortHandshake(websocket, req, 'Opening handshake has timed out');
|
|
3486
|
+
});
|
|
3487
|
+
req.on('error', (err)=>{
|
|
3488
|
+
if (null === req || req[kAborted]) return;
|
|
3489
|
+
req = websocket._req = null;
|
|
3490
|
+
emitErrorAndClose(websocket, err);
|
|
3491
|
+
});
|
|
3492
|
+
req.on('response', (res)=>{
|
|
3493
|
+
const location = res.headers.location;
|
|
3494
|
+
const statusCode = res.statusCode;
|
|
3495
|
+
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
3496
|
+
if (++websocket._redirects > opts.maxRedirects) return void abortHandshake(websocket, req, 'Maximum redirects exceeded');
|
|
3497
|
+
req.abort();
|
|
3498
|
+
let addr;
|
|
3499
|
+
try {
|
|
3500
|
+
addr = new URL1(location, address);
|
|
3501
|
+
} catch (e) {
|
|
3502
|
+
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
3503
|
+
emitErrorAndClose(websocket, err);
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
initAsClient(websocket, addr, protocols, options);
|
|
3507
|
+
} else if (!websocket.emit('unexpected-response', req, res)) abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
3508
|
+
});
|
|
3509
|
+
req.on('upgrade', (res, socket, head)=>{
|
|
3510
|
+
websocket.emit('upgrade', res);
|
|
3511
|
+
if (websocket.readyState !== WebSocket.CONNECTING) return;
|
|
3512
|
+
req = websocket._req = null;
|
|
3513
|
+
const upgrade = res.headers.upgrade;
|
|
3514
|
+
if (void 0 === upgrade || 'websocket' !== upgrade.toLowerCase()) return void abortHandshake(websocket, socket, 'Invalid Upgrade header');
|
|
3515
|
+
const digest = createHash('sha1').update(key + GUID).digest('base64');
|
|
3516
|
+
if (res.headers['sec-websocket-accept'] !== digest) return void abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
|
|
3517
|
+
const serverProt = res.headers['sec-websocket-protocol'];
|
|
3518
|
+
let protError;
|
|
3519
|
+
if (void 0 !== serverProt) if (protocolSet.size) {
|
|
3520
|
+
if (!protocolSet.has(serverProt)) protError = 'Server sent an invalid subprotocol';
|
|
3521
|
+
} else protError = 'Server sent a subprotocol but none was requested';
|
|
3522
|
+
else if (protocolSet.size) protError = 'Server sent no subprotocol';
|
|
3523
|
+
if (protError) return void abortHandshake(websocket, socket, protError);
|
|
3524
|
+
if (serverProt) websocket._protocol = serverProt;
|
|
3525
|
+
const secWebSocketExtensions = res.headers['sec-websocket-extensions'];
|
|
3526
|
+
if (void 0 !== secWebSocketExtensions) {
|
|
3527
|
+
if (!perMessageDeflate) {
|
|
3528
|
+
const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
|
|
3529
|
+
abortHandshake(websocket, socket, message);
|
|
3530
|
+
return;
|
|
3531
|
+
}
|
|
3532
|
+
let extensions;
|
|
3533
|
+
try {
|
|
3534
|
+
extensions = parse(secWebSocketExtensions);
|
|
3535
|
+
} catch (err) {
|
|
3536
|
+
const message = 'Invalid Sec-WebSocket-Extensions header';
|
|
3537
|
+
abortHandshake(websocket, socket, message);
|
|
3538
|
+
return;
|
|
3539
|
+
}
|
|
3540
|
+
const extensionNames = Object.keys(extensions);
|
|
3541
|
+
if (1 !== extensionNames.length || extensionNames[0] !== PerMessageDeflate.extensionName) {
|
|
3542
|
+
const message = 'Server indicated an extension that was not requested';
|
|
3543
|
+
abortHandshake(websocket, socket, message);
|
|
3544
|
+
return;
|
|
3545
|
+
}
|
|
3546
|
+
try {
|
|
3547
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
3548
|
+
} catch (err) {
|
|
3549
|
+
const message = 'Invalid Sec-WebSocket-Extensions header';
|
|
3550
|
+
abortHandshake(websocket, socket, message);
|
|
3551
|
+
return;
|
|
3552
|
+
}
|
|
3553
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
3554
|
+
}
|
|
3555
|
+
websocket.setSocket(socket, head, {
|
|
3556
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
3557
|
+
generateMask: opts.generateMask,
|
|
3558
|
+
maxPayload: opts.maxPayload,
|
|
3559
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
3560
|
+
});
|
|
3561
|
+
});
|
|
3562
|
+
if (opts.finishRequest) opts.finishRequest(req, websocket);
|
|
3563
|
+
else req.end();
|
|
3564
|
+
}
|
|
3565
|
+
function emitErrorAndClose(websocket, err) {
|
|
3566
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3567
|
+
websocket._errorEmitted = true;
|
|
3568
|
+
websocket.emit('error', err);
|
|
3569
|
+
websocket.emitClose();
|
|
3570
|
+
}
|
|
3571
|
+
function netConnect(options) {
|
|
3572
|
+
options.path = options.socketPath;
|
|
3573
|
+
return net.connect(options);
|
|
3574
|
+
}
|
|
3575
|
+
function tlsConnect(options) {
|
|
3576
|
+
options.path = void 0;
|
|
3577
|
+
if (!options.servername && '' !== options.servername) options.servername = net.isIP(options.host) ? '' : options.host;
|
|
3578
|
+
return tls.connect(options);
|
|
3579
|
+
}
|
|
3580
|
+
function abortHandshake(websocket, stream, message) {
|
|
3581
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3582
|
+
const err = new Error(message);
|
|
3583
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
3584
|
+
if (stream.setHeader) {
|
|
3585
|
+
stream[kAborted] = true;
|
|
3586
|
+
stream.abort();
|
|
3587
|
+
if (stream.socket && !stream.socket.destroyed) stream.socket.destroy();
|
|
3588
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
3589
|
+
} else {
|
|
3590
|
+
stream.destroy(err);
|
|
3591
|
+
stream.once('error', websocket.emit.bind(websocket, 'error'));
|
|
3592
|
+
stream.once('close', websocket.emitClose.bind(websocket));
|
|
3593
|
+
}
|
|
3594
|
+
}
|
|
3595
|
+
function sendAfterClose(websocket, data, cb) {
|
|
3596
|
+
if (data) {
|
|
3597
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
3598
|
+
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
3599
|
+
else websocket._bufferedAmount += length;
|
|
3600
|
+
}
|
|
3601
|
+
if (cb) {
|
|
3602
|
+
const err = new Error(`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`);
|
|
3603
|
+
process.nextTick(cb, err);
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
function receiverOnConclude(code, reason) {
|
|
3607
|
+
const websocket = this[kWebSocket];
|
|
3608
|
+
websocket._closeFrameReceived = true;
|
|
3609
|
+
websocket._closeMessage = reason;
|
|
3610
|
+
websocket._closeCode = code;
|
|
3611
|
+
if (void 0 === websocket._socket[kWebSocket]) return;
|
|
3612
|
+
websocket._socket.removeListener('data', socketOnData);
|
|
3613
|
+
process.nextTick(resume, websocket._socket);
|
|
3614
|
+
if (1005 === code) websocket.close();
|
|
3615
|
+
else websocket.close(code, reason);
|
|
3616
|
+
}
|
|
3617
|
+
function receiverOnDrain() {
|
|
3618
|
+
const websocket = this[kWebSocket];
|
|
3619
|
+
if (!websocket.isPaused) websocket._socket.resume();
|
|
3620
|
+
}
|
|
3621
|
+
function receiverOnError(err) {
|
|
3622
|
+
const websocket = this[kWebSocket];
|
|
3623
|
+
if (void 0 !== websocket._socket[kWebSocket]) {
|
|
3624
|
+
websocket._socket.removeListener('data', socketOnData);
|
|
3625
|
+
process.nextTick(resume, websocket._socket);
|
|
3626
|
+
websocket.close(err[kStatusCode]);
|
|
3627
|
+
}
|
|
3628
|
+
if (!websocket._errorEmitted) {
|
|
3629
|
+
websocket._errorEmitted = true;
|
|
3630
|
+
websocket.emit('error', err);
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
function receiverOnFinish() {
|
|
3634
|
+
this[kWebSocket].emitClose();
|
|
3635
|
+
}
|
|
3636
|
+
function receiverOnMessage(data, isBinary) {
|
|
3637
|
+
this[kWebSocket].emit('message', data, isBinary);
|
|
3638
|
+
}
|
|
3639
|
+
function receiverOnPing(data) {
|
|
3640
|
+
const websocket = this[kWebSocket];
|
|
3641
|
+
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
|
3642
|
+
websocket.emit('ping', data);
|
|
3643
|
+
}
|
|
3644
|
+
function receiverOnPong(data) {
|
|
3645
|
+
this[kWebSocket].emit('pong', data);
|
|
3646
|
+
}
|
|
3647
|
+
function resume(stream) {
|
|
3648
|
+
stream.resume();
|
|
3649
|
+
}
|
|
3650
|
+
function senderOnError(err) {
|
|
3651
|
+
const websocket = this[kWebSocket];
|
|
3652
|
+
if (websocket.readyState === WebSocket.CLOSED) return;
|
|
3653
|
+
if (websocket.readyState === WebSocket.OPEN) {
|
|
3654
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3655
|
+
setCloseTimer(websocket);
|
|
3656
|
+
}
|
|
3657
|
+
this._socket.end();
|
|
3658
|
+
if (!websocket._errorEmitted) {
|
|
3659
|
+
websocket._errorEmitted = true;
|
|
3660
|
+
websocket.emit('error', err);
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
function setCloseTimer(websocket) {
|
|
3664
|
+
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
3665
|
+
}
|
|
3666
|
+
function socketOnClose() {
|
|
3667
|
+
const websocket = this[kWebSocket];
|
|
3668
|
+
this.removeListener('close', socketOnClose);
|
|
3669
|
+
this.removeListener('data', socketOnData);
|
|
3670
|
+
this.removeListener('end', socketOnEnd);
|
|
3671
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3672
|
+
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && 0 !== this._readableState.length) {
|
|
3673
|
+
const chunk = this.read(this._readableState.length);
|
|
3674
|
+
websocket._receiver.write(chunk);
|
|
3675
|
+
}
|
|
3676
|
+
websocket._receiver.end();
|
|
3677
|
+
this[kWebSocket] = void 0;
|
|
3678
|
+
clearTimeout(websocket._closeTimer);
|
|
3679
|
+
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) websocket.emitClose();
|
|
3680
|
+
else {
|
|
3681
|
+
websocket._receiver.on('error', receiverOnFinish);
|
|
3682
|
+
websocket._receiver.on('finish', receiverOnFinish);
|
|
3683
|
+
}
|
|
3684
|
+
}
|
|
3685
|
+
function socketOnData(chunk) {
|
|
3686
|
+
if (!this[kWebSocket]._receiver.write(chunk)) this.pause();
|
|
3687
|
+
}
|
|
3688
|
+
function socketOnEnd() {
|
|
3689
|
+
const websocket = this[kWebSocket];
|
|
3690
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3691
|
+
websocket._receiver.end();
|
|
3692
|
+
this.end();
|
|
3693
|
+
}
|
|
3694
|
+
function socketOnError() {
|
|
3695
|
+
const websocket = this[kWebSocket];
|
|
3696
|
+
this.removeListener('error', socketOnError);
|
|
3697
|
+
this.on('error', NOOP);
|
|
3698
|
+
if (websocket) {
|
|
3699
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3700
|
+
this.destroy();
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
},
|
|
1258
3704
|
assert (module) {
|
|
1259
3705
|
module.exports = __rspack_createRequire_require("assert");
|
|
1260
3706
|
},
|
|
1261
3707
|
async_hooks (module) {
|
|
1262
3708
|
module.exports = __rspack_createRequire_require("async_hooks");
|
|
1263
3709
|
},
|
|
3710
|
+
buffer (module) {
|
|
3711
|
+
module.exports = __rspack_createRequire_require("buffer");
|
|
3712
|
+
},
|
|
1264
3713
|
child_process (module) {
|
|
1265
3714
|
module.exports = __rspack_createRequire_require("child_process");
|
|
1266
3715
|
},
|
|
1267
3716
|
crypto (module) {
|
|
1268
3717
|
module.exports = __rspack_createRequire_require("crypto");
|
|
1269
3718
|
},
|
|
3719
|
+
events (module) {
|
|
3720
|
+
module.exports = __rspack_createRequire_require("events");
|
|
3721
|
+
},
|
|
1270
3722
|
fs (module) {
|
|
1271
3723
|
module.exports = __rspack_createRequire_require("fs");
|
|
1272
3724
|
},
|
|
@@ -1276,6 +3728,9 @@ __webpack_require__.add({
|
|
|
1276
3728
|
https (module) {
|
|
1277
3729
|
module.exports = __rspack_createRequire_require("https");
|
|
1278
3730
|
},
|
|
3731
|
+
net (module) {
|
|
3732
|
+
module.exports = __rspack_createRequire_require("net");
|
|
3733
|
+
},
|
|
1279
3734
|
os (module) {
|
|
1280
3735
|
module.exports = __rspack_createRequire_require("os");
|
|
1281
3736
|
},
|
|
@@ -1288,6 +3743,9 @@ __webpack_require__.add({
|
|
|
1288
3743
|
stream (module) {
|
|
1289
3744
|
module.exports = __rspack_createRequire_require("stream");
|
|
1290
3745
|
},
|
|
3746
|
+
tls (module) {
|
|
3747
|
+
module.exports = __rspack_createRequire_require("tls");
|
|
3748
|
+
},
|
|
1291
3749
|
tty (module) {
|
|
1292
3750
|
module.exports = __rspack_createRequire_require("tty");
|
|
1293
3751
|
},
|
|
@@ -1355,6 +3813,14 @@ async function getPort(basePort, host) {
|
|
|
1355
3813
|
}
|
|
1356
3814
|
throw new Error('No available ports found');
|
|
1357
3815
|
}
|
|
3816
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/stream.js");
|
|
3817
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/extension.js");
|
|
3818
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/permessage-deflate.js");
|
|
3819
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/receiver.js");
|
|
3820
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/sender.js");
|
|
3821
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/subprotocol.js");
|
|
3822
|
+
__webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket.js");
|
|
3823
|
+
const websocket_server = __webpack_require__("./node_modules/.pnpm/ws@8.20.0/node_modules/ws/lib/websocket-server.js");
|
|
1358
3824
|
class BaseServer {
|
|
1359
3825
|
server;
|
|
1360
3826
|
clients;
|
|
@@ -1375,7 +3841,7 @@ class WebsocketServer extends servers_BaseServer {
|
|
|
1375
3841
|
};
|
|
1376
3842
|
const isNoServerMode = void 0 === options.port && void 0 === options.server;
|
|
1377
3843
|
if (isNoServerMode) options.noServer = true;
|
|
1378
|
-
this.implementation = new
|
|
3844
|
+
this.implementation = new websocket_server(options);
|
|
1379
3845
|
this.server.server.on('upgrade', (req, sock, head)=>{
|
|
1380
3846
|
if (!this.implementation.shouldHandle(req)) return;
|
|
1381
3847
|
this.implementation.handleUpgrade(req, sock, head, (connection)=>{
|
|
@@ -1413,7 +3879,7 @@ class WebsocketServer extends servers_BaseServer {
|
|
|
1413
3879
|
});
|
|
1414
3880
|
}
|
|
1415
3881
|
}
|
|
1416
|
-
const src = __webpack_require__("./node_modules/.pnpm/http-compression@1.1.
|
|
3882
|
+
const src = __webpack_require__("./node_modules/.pnpm/http-compression@1.1.3/node_modules/http-compression/src/index.js");
|
|
1417
3883
|
var src_default = /*#__PURE__*/ __webpack_require__.n(src);
|
|
1418
3884
|
const ipaddr = __webpack_require__("./node_modules/.pnpm/ipaddr.js@2.3.0/node_modules/ipaddr.js/lib/ipaddr.js");
|
|
1419
3885
|
var ipaddr_default = /*#__PURE__*/ __webpack_require__.n(ipaddr);
|
|
@@ -1421,10 +3887,10 @@ const { styleText: styleText } = __rspack_external_node_util_1b29d436;
|
|
|
1421
3887
|
const server_require = createRequire(import.meta.url);
|
|
1422
3888
|
if (!process.env.RSPACK_SERVE) process.env.RSPACK_SERVE = 'true';
|
|
1423
3889
|
const getConnect = async ()=>{
|
|
1424
|
-
const { connect } = await import("connect-next");
|
|
3890
|
+
const { connect } = await import("./0~connect-next.js");
|
|
1425
3891
|
return connect;
|
|
1426
3892
|
};
|
|
1427
|
-
const getChokidar = ()=>import("chokidar");
|
|
3893
|
+
const getChokidar = ()=>import("./0~chokidar.js").then((m)=>m.chokidar_namespaceObject);
|
|
1428
3894
|
const encodeOverlaySettings = (setting)=>'function' == typeof setting ? encodeURIComponent(setting.toString()) : setting;
|
|
1429
3895
|
const DEFAULT_ALLOWED_PROTOCOLS = /^(file|.+-extension):/i;
|
|
1430
3896
|
function parseHostnameFromHeader(header) {
|
|
@@ -1981,7 +4447,7 @@ class Server {
|
|
|
1981
4447
|
#getClientTransport() {
|
|
1982
4448
|
let clientImplementation;
|
|
1983
4449
|
let clientImplementationFound = true;
|
|
1984
|
-
|
|
4450
|
+
const clientTransport = 'object' == typeof this.options.client && null !== this.options.client && void 0 !== this.options.client.webSocketTransport ? this.options.client.webSocketTransport : 'ws';
|
|
1985
4451
|
switch(typeof clientTransport){
|
|
1986
4452
|
case 'string':
|
|
1987
4453
|
if ('sockjs' === clientTransport) throw new Error("SockJS support has been removed. Please set client.webSocketTransport to 'ws' or provide a custom transport implementation path.");
|