@moxxy/cli 0.48.0 → 0.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +265 -3780
- package/package.json +6 -6
package/dist/bin.js
CHANGED
|
@@ -30564,7 +30564,7 @@ var require_permessage_deflate = __commonJS({
|
|
|
30564
30564
|
var kBuffers = /* @__PURE__ */ Symbol("buffers");
|
|
30565
30565
|
var kError = /* @__PURE__ */ Symbol("error");
|
|
30566
30566
|
var zlibLimiter;
|
|
30567
|
-
var
|
|
30567
|
+
var PerMessageDeflate2 = class {
|
|
30568
30568
|
/**
|
|
30569
30569
|
* Creates a PerMessageDeflate instance.
|
|
30570
30570
|
*
|
|
@@ -30902,7 +30902,7 @@ var require_permessage_deflate = __commonJS({
|
|
|
30902
30902
|
});
|
|
30903
30903
|
}
|
|
30904
30904
|
};
|
|
30905
|
-
module.exports =
|
|
30905
|
+
module.exports = PerMessageDeflate2;
|
|
30906
30906
|
function deflateOnData(chunk) {
|
|
30907
30907
|
this[kBuffers].push(chunk);
|
|
30908
30908
|
this[kTotalLength] += chunk.length;
|
|
@@ -31135,7 +31135,7 @@ var require_validation = __commonJS({
|
|
|
31135
31135
|
var require_receiver = __commonJS({
|
|
31136
31136
|
"../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/lib/receiver.js"(exports, module) {
|
|
31137
31137
|
var { Writable } = __require("stream");
|
|
31138
|
-
var
|
|
31138
|
+
var PerMessageDeflate2 = require_permessage_deflate();
|
|
31139
31139
|
var {
|
|
31140
31140
|
BINARY_TYPES,
|
|
31141
31141
|
EMPTY_BUFFER,
|
|
@@ -31152,7 +31152,7 @@ var require_receiver = __commonJS({
|
|
|
31152
31152
|
var GET_DATA = 4;
|
|
31153
31153
|
var INFLATING = 5;
|
|
31154
31154
|
var DEFER_EVENT = 6;
|
|
31155
|
-
var
|
|
31155
|
+
var Receiver2 = class extends Writable {
|
|
31156
31156
|
/**
|
|
31157
31157
|
* Creates a Receiver instance.
|
|
31158
31158
|
*
|
|
@@ -31321,7 +31321,7 @@ var require_receiver = __commonJS({
|
|
|
31321
31321
|
return;
|
|
31322
31322
|
}
|
|
31323
31323
|
const compressed = (buf[0] & 64) === 64;
|
|
31324
|
-
if (compressed && !this._extensions[
|
|
31324
|
+
if (compressed && !this._extensions[PerMessageDeflate2.extensionName]) {
|
|
31325
31325
|
const error = this.createError(
|
|
31326
31326
|
RangeError,
|
|
31327
31327
|
"RSV1 must be clear",
|
|
@@ -31576,7 +31576,7 @@ var require_receiver = __commonJS({
|
|
|
31576
31576
|
* @private
|
|
31577
31577
|
*/
|
|
31578
31578
|
decompress(data, cb) {
|
|
31579
|
-
const perMessageDeflate = this._extensions[
|
|
31579
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
|
|
31580
31580
|
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
31581
31581
|
if (err) return cb(err);
|
|
31582
31582
|
if (buf.length) {
|
|
@@ -31749,7 +31749,7 @@ var require_receiver = __commonJS({
|
|
|
31749
31749
|
return err;
|
|
31750
31750
|
}
|
|
31751
31751
|
};
|
|
31752
|
-
module.exports =
|
|
31752
|
+
module.exports = Receiver2;
|
|
31753
31753
|
}
|
|
31754
31754
|
});
|
|
31755
31755
|
|
|
@@ -31761,7 +31761,7 @@ var require_sender = __commonJS({
|
|
|
31761
31761
|
var {
|
|
31762
31762
|
types: { isUint8Array }
|
|
31763
31763
|
} = __require("util");
|
|
31764
|
-
var
|
|
31764
|
+
var PerMessageDeflate2 = require_permessage_deflate();
|
|
31765
31765
|
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
|
|
31766
31766
|
var { isBlob, isValidStatusCode } = require_validation();
|
|
31767
31767
|
var { mask: applyMask, toBuffer } = require_buffer_util();
|
|
@@ -31773,7 +31773,7 @@ var require_sender = __commonJS({
|
|
|
31773
31773
|
var DEFAULT = 0;
|
|
31774
31774
|
var DEFLATING = 1;
|
|
31775
31775
|
var GET_BLOB_DATA = 2;
|
|
31776
|
-
var
|
|
31776
|
+
var Sender2 = class _Sender {
|
|
31777
31777
|
/**
|
|
31778
31778
|
* Creates a Sender instance.
|
|
31779
31779
|
*
|
|
@@ -32047,7 +32047,7 @@ var require_sender = __commonJS({
|
|
|
32047
32047
|
* @public
|
|
32048
32048
|
*/
|
|
32049
32049
|
send(data, options, cb) {
|
|
32050
|
-
const perMessageDeflate = this._extensions[
|
|
32050
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
|
|
32051
32051
|
let opcode = options.binary ? 2 : 1;
|
|
32052
32052
|
let rsv1 = options.compress;
|
|
32053
32053
|
let byteLength;
|
|
@@ -32171,7 +32171,7 @@ var require_sender = __commonJS({
|
|
|
32171
32171
|
this.sendFrame(_Sender.frame(data, options), cb);
|
|
32172
32172
|
return;
|
|
32173
32173
|
}
|
|
32174
|
-
const perMessageDeflate = this._extensions[
|
|
32174
|
+
const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
|
|
32175
32175
|
this._bufferedBytes += options[kByteLength];
|
|
32176
32176
|
this._state = DEFLATING;
|
|
32177
32177
|
perMessageDeflate.compress(data, options.fin, (_2, buf) => {
|
|
@@ -32229,7 +32229,7 @@ var require_sender = __commonJS({
|
|
|
32229
32229
|
}
|
|
32230
32230
|
}
|
|
32231
32231
|
};
|
|
32232
|
-
module.exports =
|
|
32232
|
+
module.exports = Sender2;
|
|
32233
32233
|
function callCallbacks(sender, err, cb) {
|
|
32234
32234
|
if (typeof cb === "function") cb(err);
|
|
32235
32235
|
for (let i2 = 0; i2 < sender._queue.length; i2++) {
|
|
@@ -32607,11 +32607,11 @@ var require_extension = __commonJS({
|
|
|
32607
32607
|
return offers;
|
|
32608
32608
|
}
|
|
32609
32609
|
function format(extensions) {
|
|
32610
|
-
return Object.keys(extensions).map((
|
|
32611
|
-
let configurations = extensions[
|
|
32610
|
+
return Object.keys(extensions).map((extension2) => {
|
|
32611
|
+
let configurations = extensions[extension2];
|
|
32612
32612
|
if (!Array.isArray(configurations)) configurations = [configurations];
|
|
32613
32613
|
return configurations.map((params) => {
|
|
32614
|
-
return [
|
|
32614
|
+
return [extension2].concat(
|
|
32615
32615
|
Object.keys(params).map((k) => {
|
|
32616
32616
|
let values = params[k];
|
|
32617
32617
|
if (!Array.isArray(values)) values = [values];
|
|
@@ -32636,9 +32636,9 @@ var require_websocket = __commonJS({
|
|
|
32636
32636
|
var { randomBytes: randomBytes8, createHash: createHash11 } = __require("crypto");
|
|
32637
32637
|
var { Duplex, Readable } = __require("stream");
|
|
32638
32638
|
var { URL: URL2 } = __require("url");
|
|
32639
|
-
var
|
|
32640
|
-
var
|
|
32641
|
-
var
|
|
32639
|
+
var PerMessageDeflate2 = require_permessage_deflate();
|
|
32640
|
+
var Receiver2 = require_receiver();
|
|
32641
|
+
var Sender2 = require_sender();
|
|
32642
32642
|
var { isBlob } = require_validation();
|
|
32643
32643
|
var {
|
|
32644
32644
|
BINARY_TYPES,
|
|
@@ -32660,7 +32660,7 @@ var require_websocket = __commonJS({
|
|
|
32660
32660
|
var protocolVersions = [8, 13];
|
|
32661
32661
|
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
32662
32662
|
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
32663
|
-
var
|
|
32663
|
+
var WebSocket2 = class _WebSocket extends EventEmitter3 {
|
|
32664
32664
|
/**
|
|
32665
32665
|
* Create a new `WebSocket`.
|
|
32666
32666
|
*
|
|
@@ -32817,7 +32817,7 @@ var require_websocket = __commonJS({
|
|
|
32817
32817
|
* @private
|
|
32818
32818
|
*/
|
|
32819
32819
|
setSocket(socket, head2, options) {
|
|
32820
|
-
const receiver = new
|
|
32820
|
+
const receiver = new Receiver2({
|
|
32821
32821
|
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
32822
32822
|
binaryType: this.binaryType,
|
|
32823
32823
|
extensions: this._extensions,
|
|
@@ -32827,7 +32827,7 @@ var require_websocket = __commonJS({
|
|
|
32827
32827
|
maxPayload: options.maxPayload,
|
|
32828
32828
|
skipUTF8Validation: options.skipUTF8Validation
|
|
32829
32829
|
});
|
|
32830
|
-
const sender = new
|
|
32830
|
+
const sender = new Sender2(socket, this._extensions, options.generateMask);
|
|
32831
32831
|
this._receiver = receiver;
|
|
32832
32832
|
this._sender = sender;
|
|
32833
32833
|
this._socket = socket;
|
|
@@ -32862,8 +32862,8 @@ var require_websocket = __commonJS({
|
|
|
32862
32862
|
this.emit("close", this._closeCode, this._closeMessage);
|
|
32863
32863
|
return;
|
|
32864
32864
|
}
|
|
32865
|
-
if (this._extensions[
|
|
32866
|
-
this._extensions[
|
|
32865
|
+
if (this._extensions[PerMessageDeflate2.extensionName]) {
|
|
32866
|
+
this._extensions[PerMessageDeflate2.extensionName].cleanup();
|
|
32867
32867
|
}
|
|
32868
32868
|
this._receiver.removeAllListeners();
|
|
32869
32869
|
this._readyState = _WebSocket.CLOSED;
|
|
@@ -33025,7 +33025,7 @@ var require_websocket = __commonJS({
|
|
|
33025
33025
|
fin: true,
|
|
33026
33026
|
...options
|
|
33027
33027
|
};
|
|
33028
|
-
if (!this._extensions[
|
|
33028
|
+
if (!this._extensions[PerMessageDeflate2.extensionName]) {
|
|
33029
33029
|
opts.compress = false;
|
|
33030
33030
|
}
|
|
33031
33031
|
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
@@ -33048,35 +33048,35 @@ var require_websocket = __commonJS({
|
|
|
33048
33048
|
}
|
|
33049
33049
|
}
|
|
33050
33050
|
};
|
|
33051
|
-
Object.defineProperty(
|
|
33051
|
+
Object.defineProperty(WebSocket2, "CONNECTING", {
|
|
33052
33052
|
enumerable: true,
|
|
33053
33053
|
value: readyStates.indexOf("CONNECTING")
|
|
33054
33054
|
});
|
|
33055
|
-
Object.defineProperty(
|
|
33055
|
+
Object.defineProperty(WebSocket2.prototype, "CONNECTING", {
|
|
33056
33056
|
enumerable: true,
|
|
33057
33057
|
value: readyStates.indexOf("CONNECTING")
|
|
33058
33058
|
});
|
|
33059
|
-
Object.defineProperty(
|
|
33059
|
+
Object.defineProperty(WebSocket2, "OPEN", {
|
|
33060
33060
|
enumerable: true,
|
|
33061
33061
|
value: readyStates.indexOf("OPEN")
|
|
33062
33062
|
});
|
|
33063
|
-
Object.defineProperty(
|
|
33063
|
+
Object.defineProperty(WebSocket2.prototype, "OPEN", {
|
|
33064
33064
|
enumerable: true,
|
|
33065
33065
|
value: readyStates.indexOf("OPEN")
|
|
33066
33066
|
});
|
|
33067
|
-
Object.defineProperty(
|
|
33067
|
+
Object.defineProperty(WebSocket2, "CLOSING", {
|
|
33068
33068
|
enumerable: true,
|
|
33069
33069
|
value: readyStates.indexOf("CLOSING")
|
|
33070
33070
|
});
|
|
33071
|
-
Object.defineProperty(
|
|
33071
|
+
Object.defineProperty(WebSocket2.prototype, "CLOSING", {
|
|
33072
33072
|
enumerable: true,
|
|
33073
33073
|
value: readyStates.indexOf("CLOSING")
|
|
33074
33074
|
});
|
|
33075
|
-
Object.defineProperty(
|
|
33075
|
+
Object.defineProperty(WebSocket2, "CLOSED", {
|
|
33076
33076
|
enumerable: true,
|
|
33077
33077
|
value: readyStates.indexOf("CLOSED")
|
|
33078
33078
|
});
|
|
33079
|
-
Object.defineProperty(
|
|
33079
|
+
Object.defineProperty(WebSocket2.prototype, "CLOSED", {
|
|
33080
33080
|
enumerable: true,
|
|
33081
33081
|
value: readyStates.indexOf("CLOSED")
|
|
33082
33082
|
});
|
|
@@ -33089,10 +33089,10 @@ var require_websocket = __commonJS({
|
|
|
33089
33089
|
"readyState",
|
|
33090
33090
|
"url"
|
|
33091
33091
|
].forEach((property) => {
|
|
33092
|
-
Object.defineProperty(
|
|
33092
|
+
Object.defineProperty(WebSocket2.prototype, property, { enumerable: true });
|
|
33093
33093
|
});
|
|
33094
33094
|
["open", "error", "close", "message"].forEach((method) => {
|
|
33095
|
-
Object.defineProperty(
|
|
33095
|
+
Object.defineProperty(WebSocket2.prototype, `on${method}`, {
|
|
33096
33096
|
enumerable: true,
|
|
33097
33097
|
get() {
|
|
33098
33098
|
for (const listener of this.listeners(method)) {
|
|
@@ -33114,9 +33114,9 @@ var require_websocket = __commonJS({
|
|
|
33114
33114
|
}
|
|
33115
33115
|
});
|
|
33116
33116
|
});
|
|
33117
|
-
|
|
33118
|
-
|
|
33119
|
-
module.exports =
|
|
33117
|
+
WebSocket2.prototype.addEventListener = addEventListener;
|
|
33118
|
+
WebSocket2.prototype.removeEventListener = removeEventListener;
|
|
33119
|
+
module.exports = WebSocket2;
|
|
33120
33120
|
function initAsClient(websocket, address, protocols, options) {
|
|
33121
33121
|
const opts = {
|
|
33122
33122
|
allowSynchronousEvents: true,
|
|
@@ -33202,13 +33202,13 @@ var require_websocket = __commonJS({
|
|
|
33202
33202
|
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
33203
33203
|
opts.timeout = opts.handshakeTimeout;
|
|
33204
33204
|
if (opts.perMessageDeflate) {
|
|
33205
|
-
perMessageDeflate = new
|
|
33205
|
+
perMessageDeflate = new PerMessageDeflate2({
|
|
33206
33206
|
...opts.perMessageDeflate,
|
|
33207
33207
|
isServer: false,
|
|
33208
33208
|
maxPayload: opts.maxPayload
|
|
33209
33209
|
});
|
|
33210
33210
|
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
33211
|
-
[
|
|
33211
|
+
[PerMessageDeflate2.extensionName]: perMessageDeflate.offer()
|
|
33212
33212
|
});
|
|
33213
33213
|
}
|
|
33214
33214
|
if (protocols.length) {
|
|
@@ -33307,7 +33307,7 @@ var require_websocket = __commonJS({
|
|
|
33307
33307
|
});
|
|
33308
33308
|
req.on("upgrade", (res, socket, head2) => {
|
|
33309
33309
|
websocket.emit("upgrade", res);
|
|
33310
|
-
if (websocket.readyState !==
|
|
33310
|
+
if (websocket.readyState !== WebSocket2.CONNECTING) return;
|
|
33311
33311
|
req = websocket._req = null;
|
|
33312
33312
|
const upgrade = res.headers.upgrade;
|
|
33313
33313
|
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
@@ -33351,19 +33351,19 @@ var require_websocket = __commonJS({
|
|
|
33351
33351
|
return;
|
|
33352
33352
|
}
|
|
33353
33353
|
const extensionNames = Object.keys(extensions);
|
|
33354
|
-
if (extensionNames.length !== 1 || extensionNames[0] !==
|
|
33354
|
+
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate2.extensionName) {
|
|
33355
33355
|
const message = "Server indicated an extension that was not requested";
|
|
33356
33356
|
abortHandshake(websocket, socket, message);
|
|
33357
33357
|
return;
|
|
33358
33358
|
}
|
|
33359
33359
|
try {
|
|
33360
|
-
perMessageDeflate.accept(extensions[
|
|
33360
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate2.extensionName]);
|
|
33361
33361
|
} catch (err) {
|
|
33362
33362
|
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
33363
33363
|
abortHandshake(websocket, socket, message);
|
|
33364
33364
|
return;
|
|
33365
33365
|
}
|
|
33366
|
-
websocket._extensions[
|
|
33366
|
+
websocket._extensions[PerMessageDeflate2.extensionName] = perMessageDeflate;
|
|
33367
33367
|
}
|
|
33368
33368
|
websocket.setSocket(socket, head2, {
|
|
33369
33369
|
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
@@ -33381,7 +33381,7 @@ var require_websocket = __commonJS({
|
|
|
33381
33381
|
}
|
|
33382
33382
|
}
|
|
33383
33383
|
function emitErrorAndClose(websocket, err) {
|
|
33384
|
-
websocket._readyState =
|
|
33384
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
33385
33385
|
websocket._errorEmitted = true;
|
|
33386
33386
|
websocket.emit("error", err);
|
|
33387
33387
|
websocket.emitClose();
|
|
@@ -33398,7 +33398,7 @@ var require_websocket = __commonJS({
|
|
|
33398
33398
|
return tls.connect(options);
|
|
33399
33399
|
}
|
|
33400
33400
|
function abortHandshake(websocket, stream2, message) {
|
|
33401
|
-
websocket._readyState =
|
|
33401
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
33402
33402
|
const err = new Error(message);
|
|
33403
33403
|
Error.captureStackTrace(err, abortHandshake);
|
|
33404
33404
|
if (stream2.setHeader) {
|
|
@@ -33473,9 +33473,9 @@ var require_websocket = __commonJS({
|
|
|
33473
33473
|
}
|
|
33474
33474
|
function senderOnError(err) {
|
|
33475
33475
|
const websocket = this[kWebSocket];
|
|
33476
|
-
if (websocket.readyState ===
|
|
33477
|
-
if (websocket.readyState ===
|
|
33478
|
-
websocket._readyState =
|
|
33476
|
+
if (websocket.readyState === WebSocket2.CLOSED) return;
|
|
33477
|
+
if (websocket.readyState === WebSocket2.OPEN) {
|
|
33478
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
33479
33479
|
setCloseTimer(websocket);
|
|
33480
33480
|
}
|
|
33481
33481
|
this._socket.end();
|
|
@@ -33495,7 +33495,7 @@ var require_websocket = __commonJS({
|
|
|
33495
33495
|
this.removeListener("close", socketOnClose);
|
|
33496
33496
|
this.removeListener("data", socketOnData);
|
|
33497
33497
|
this.removeListener("end", socketOnEnd);
|
|
33498
|
-
websocket._readyState =
|
|
33498
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
33499
33499
|
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
33500
33500
|
const chunk = this.read(this._readableState.length);
|
|
33501
33501
|
websocket._receiver.write(chunk);
|
|
@@ -33517,7 +33517,7 @@ var require_websocket = __commonJS({
|
|
|
33517
33517
|
}
|
|
33518
33518
|
function socketOnEnd() {
|
|
33519
33519
|
const websocket = this[kWebSocket];
|
|
33520
|
-
websocket._readyState =
|
|
33520
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
33521
33521
|
websocket._receiver.end();
|
|
33522
33522
|
this.end();
|
|
33523
33523
|
}
|
|
@@ -33526,7 +33526,7 @@ var require_websocket = __commonJS({
|
|
|
33526
33526
|
this.removeListener("error", socketOnError);
|
|
33527
33527
|
this.on("error", NOOP);
|
|
33528
33528
|
if (websocket) {
|
|
33529
|
-
websocket._readyState =
|
|
33529
|
+
websocket._readyState = WebSocket2.CLOSING;
|
|
33530
33530
|
this.destroy();
|
|
33531
33531
|
}
|
|
33532
33532
|
}
|
|
@@ -33553,7 +33553,7 @@ var require_stream = __commonJS({
|
|
|
33553
33553
|
this.emit("error", err);
|
|
33554
33554
|
}
|
|
33555
33555
|
}
|
|
33556
|
-
function
|
|
33556
|
+
function createWebSocketStream2(ws, options) {
|
|
33557
33557
|
let terminateOnDestroy = true;
|
|
33558
33558
|
const duplex = new Duplex({
|
|
33559
33559
|
...options,
|
|
@@ -33626,7 +33626,7 @@ var require_stream = __commonJS({
|
|
|
33626
33626
|
duplex.on("error", duplexOnError);
|
|
33627
33627
|
return duplex;
|
|
33628
33628
|
}
|
|
33629
|
-
module.exports =
|
|
33629
|
+
module.exports = createWebSocketStream2;
|
|
33630
33630
|
}
|
|
33631
33631
|
});
|
|
33632
33632
|
|
|
@@ -33681,16 +33681,16 @@ var require_websocket_server = __commonJS({
|
|
|
33681
33681
|
var http = __require("http");
|
|
33682
33682
|
var { Duplex } = __require("stream");
|
|
33683
33683
|
var { createHash: createHash11 } = __require("crypto");
|
|
33684
|
-
var
|
|
33685
|
-
var
|
|
33686
|
-
var
|
|
33687
|
-
var
|
|
33684
|
+
var extension2 = require_extension();
|
|
33685
|
+
var PerMessageDeflate2 = require_permessage_deflate();
|
|
33686
|
+
var subprotocol2 = require_subprotocol();
|
|
33687
|
+
var WebSocket2 = require_websocket();
|
|
33688
33688
|
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
|
|
33689
33689
|
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
33690
33690
|
var RUNNING = 0;
|
|
33691
33691
|
var CLOSING = 1;
|
|
33692
33692
|
var CLOSED = 2;
|
|
33693
|
-
var
|
|
33693
|
+
var WebSocketServer2 = class extends EventEmitter3 {
|
|
33694
33694
|
/**
|
|
33695
33695
|
* Create a `WebSocketServer` instance.
|
|
33696
33696
|
*
|
|
@@ -33750,7 +33750,7 @@ var require_websocket_server = __commonJS({
|
|
|
33750
33750
|
host: null,
|
|
33751
33751
|
path: null,
|
|
33752
33752
|
port: null,
|
|
33753
|
-
WebSocket:
|
|
33753
|
+
WebSocket: WebSocket2,
|
|
33754
33754
|
...options
|
|
33755
33755
|
};
|
|
33756
33756
|
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
@@ -33912,7 +33912,7 @@ var require_websocket_server = __commonJS({
|
|
|
33912
33912
|
let protocols = /* @__PURE__ */ new Set();
|
|
33913
33913
|
if (secWebSocketProtocol !== void 0) {
|
|
33914
33914
|
try {
|
|
33915
|
-
protocols =
|
|
33915
|
+
protocols = subprotocol2.parse(secWebSocketProtocol);
|
|
33916
33916
|
} catch (err) {
|
|
33917
33917
|
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
33918
33918
|
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
@@ -33922,16 +33922,16 @@ var require_websocket_server = __commonJS({
|
|
|
33922
33922
|
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
33923
33923
|
const extensions = {};
|
|
33924
33924
|
if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
|
|
33925
|
-
const perMessageDeflate = new
|
|
33925
|
+
const perMessageDeflate = new PerMessageDeflate2({
|
|
33926
33926
|
...this.options.perMessageDeflate,
|
|
33927
33927
|
isServer: true,
|
|
33928
33928
|
maxPayload: this.options.maxPayload
|
|
33929
33929
|
});
|
|
33930
33930
|
try {
|
|
33931
|
-
const offers =
|
|
33932
|
-
if (offers[
|
|
33933
|
-
perMessageDeflate.accept(offers[
|
|
33934
|
-
extensions[
|
|
33931
|
+
const offers = extension2.parse(secWebSocketExtensions);
|
|
33932
|
+
if (offers[PerMessageDeflate2.extensionName]) {
|
|
33933
|
+
perMessageDeflate.accept(offers[PerMessageDeflate2.extensionName]);
|
|
33934
|
+
extensions[PerMessageDeflate2.extensionName] = perMessageDeflate;
|
|
33935
33935
|
}
|
|
33936
33936
|
} catch (err) {
|
|
33937
33937
|
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
@@ -34002,10 +34002,10 @@ var require_websocket_server = __commonJS({
|
|
|
34002
34002
|
ws._protocol = protocol;
|
|
34003
34003
|
}
|
|
34004
34004
|
}
|
|
34005
|
-
if (extensions[
|
|
34006
|
-
const params = extensions[
|
|
34007
|
-
const value2 =
|
|
34008
|
-
[
|
|
34005
|
+
if (extensions[PerMessageDeflate2.extensionName]) {
|
|
34006
|
+
const params = extensions[PerMessageDeflate2.extensionName].params;
|
|
34007
|
+
const value2 = extension2.format({
|
|
34008
|
+
[PerMessageDeflate2.extensionName]: [params]
|
|
34009
34009
|
});
|
|
34010
34010
|
headers.push(`Sec-WebSocket-Extensions: ${value2}`);
|
|
34011
34011
|
ws._extensions = extensions;
|
|
@@ -34032,7 +34032,7 @@ var require_websocket_server = __commonJS({
|
|
|
34032
34032
|
cb(ws, req);
|
|
34033
34033
|
}
|
|
34034
34034
|
};
|
|
34035
|
-
module.exports =
|
|
34035
|
+
module.exports = WebSocketServer2;
|
|
34036
34036
|
function addListeners(server, map) {
|
|
34037
34037
|
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
34038
34038
|
return function removeListeners() {
|
|
@@ -34075,7 +34075,7 @@ var require_websocket_server = __commonJS({
|
|
|
34075
34075
|
});
|
|
34076
34076
|
|
|
34077
34077
|
// ../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/wrapper.mjs
|
|
34078
|
-
var import_websocket;
|
|
34078
|
+
var import_websocket, wrapper_default;
|
|
34079
34079
|
var init_wrapper = __esm({
|
|
34080
34080
|
"../../node_modules/.pnpm/ws@8.22.0/node_modules/ws/wrapper.mjs"() {
|
|
34081
34081
|
__toESM(require_stream());
|
|
@@ -34086,6 +34086,7 @@ var init_wrapper = __esm({
|
|
|
34086
34086
|
__toESM(require_subprotocol());
|
|
34087
34087
|
import_websocket = __toESM(require_websocket());
|
|
34088
34088
|
__toESM(require_websocket_server());
|
|
34089
|
+
wrapper_default = import_websocket.default;
|
|
34089
34090
|
}
|
|
34090
34091
|
});
|
|
34091
34092
|
|
|
@@ -66046,3693 +66047,11 @@ var init_styles = __esm({
|
|
|
66046
66047
|
}
|
|
66047
66048
|
});
|
|
66048
66049
|
|
|
66049
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/constants.js
|
|
66050
|
-
var require_constants3 = __commonJS({
|
|
66051
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/constants.js"(exports, module) {
|
|
66052
|
-
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
66053
|
-
var hasBlob = typeof Blob !== "undefined";
|
|
66054
|
-
if (hasBlob) BINARY_TYPES.push("blob");
|
|
66055
|
-
module.exports = {
|
|
66056
|
-
BINARY_TYPES,
|
|
66057
|
-
CLOSE_TIMEOUT: 3e4,
|
|
66058
|
-
EMPTY_BUFFER: Buffer.alloc(0),
|
|
66059
|
-
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
66060
|
-
hasBlob,
|
|
66061
|
-
kForOnEventAttribute: /* @__PURE__ */ Symbol("kIsForOnEventAttribute"),
|
|
66062
|
-
kListener: /* @__PURE__ */ Symbol("kListener"),
|
|
66063
|
-
kStatusCode: /* @__PURE__ */ Symbol("status-code"),
|
|
66064
|
-
kWebSocket: /* @__PURE__ */ Symbol("websocket"),
|
|
66065
|
-
NOOP: () => {
|
|
66066
|
-
}
|
|
66067
|
-
};
|
|
66068
|
-
}
|
|
66069
|
-
});
|
|
66070
|
-
|
|
66071
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/buffer-util.js
|
|
66072
|
-
var require_buffer_util2 = __commonJS({
|
|
66073
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/buffer-util.js"(exports, module) {
|
|
66074
|
-
var { EMPTY_BUFFER } = require_constants3();
|
|
66075
|
-
var FastBuffer = Buffer[Symbol.species];
|
|
66076
|
-
function concat(list, totalLength) {
|
|
66077
|
-
if (list.length === 0) return EMPTY_BUFFER;
|
|
66078
|
-
if (list.length === 1) return list[0];
|
|
66079
|
-
const target = Buffer.allocUnsafe(totalLength);
|
|
66080
|
-
let offset = 0;
|
|
66081
|
-
for (let i2 = 0; i2 < list.length; i2++) {
|
|
66082
|
-
const buf = list[i2];
|
|
66083
|
-
target.set(buf, offset);
|
|
66084
|
-
offset += buf.length;
|
|
66085
|
-
}
|
|
66086
|
-
if (offset < totalLength) {
|
|
66087
|
-
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
66088
|
-
}
|
|
66089
|
-
return target;
|
|
66090
|
-
}
|
|
66091
|
-
function _mask(source, mask, output, offset, length) {
|
|
66092
|
-
for (let i2 = 0; i2 < length; i2++) {
|
|
66093
|
-
output[offset + i2] = source[i2] ^ mask[i2 & 3];
|
|
66094
|
-
}
|
|
66095
|
-
}
|
|
66096
|
-
function _unmask(buffer, mask) {
|
|
66097
|
-
for (let i2 = 0; i2 < buffer.length; i2++) {
|
|
66098
|
-
buffer[i2] ^= mask[i2 & 3];
|
|
66099
|
-
}
|
|
66100
|
-
}
|
|
66101
|
-
function toArrayBuffer(buf) {
|
|
66102
|
-
if (buf.length === buf.buffer.byteLength) {
|
|
66103
|
-
return buf.buffer;
|
|
66104
|
-
}
|
|
66105
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
66106
|
-
}
|
|
66107
|
-
function toBuffer(data) {
|
|
66108
|
-
toBuffer.readOnly = true;
|
|
66109
|
-
if (Buffer.isBuffer(data)) return data;
|
|
66110
|
-
let buf;
|
|
66111
|
-
if (data instanceof ArrayBuffer) {
|
|
66112
|
-
buf = new FastBuffer(data);
|
|
66113
|
-
} else if (ArrayBuffer.isView(data)) {
|
|
66114
|
-
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
66115
|
-
} else {
|
|
66116
|
-
buf = Buffer.from(data);
|
|
66117
|
-
toBuffer.readOnly = false;
|
|
66118
|
-
}
|
|
66119
|
-
return buf;
|
|
66120
|
-
}
|
|
66121
|
-
module.exports = {
|
|
66122
|
-
concat,
|
|
66123
|
-
mask: _mask,
|
|
66124
|
-
toArrayBuffer,
|
|
66125
|
-
toBuffer,
|
|
66126
|
-
unmask: _unmask
|
|
66127
|
-
};
|
|
66128
|
-
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
66129
|
-
try {
|
|
66130
|
-
const bufferUtil = __require("bufferutil");
|
|
66131
|
-
module.exports.mask = function(source, mask, output, offset, length) {
|
|
66132
|
-
if (length < 48) _mask(source, mask, output, offset, length);
|
|
66133
|
-
else bufferUtil.mask(source, mask, output, offset, length);
|
|
66134
|
-
};
|
|
66135
|
-
module.exports.unmask = function(buffer, mask) {
|
|
66136
|
-
if (buffer.length < 32) _unmask(buffer, mask);
|
|
66137
|
-
else bufferUtil.unmask(buffer, mask);
|
|
66138
|
-
};
|
|
66139
|
-
} catch (e) {
|
|
66140
|
-
}
|
|
66141
|
-
}
|
|
66142
|
-
}
|
|
66143
|
-
});
|
|
66144
|
-
|
|
66145
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/limiter.js
|
|
66146
|
-
var require_limiter2 = __commonJS({
|
|
66147
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/limiter.js"(exports, module) {
|
|
66148
|
-
var kDone = /* @__PURE__ */ Symbol("kDone");
|
|
66149
|
-
var kRun = /* @__PURE__ */ Symbol("kRun");
|
|
66150
|
-
var Limiter = class {
|
|
66151
|
-
/**
|
|
66152
|
-
* Creates a new `Limiter`.
|
|
66153
|
-
*
|
|
66154
|
-
* @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
|
|
66155
|
-
* to run concurrently
|
|
66156
|
-
*/
|
|
66157
|
-
constructor(concurrency) {
|
|
66158
|
-
this[kDone] = () => {
|
|
66159
|
-
this.pending--;
|
|
66160
|
-
this[kRun]();
|
|
66161
|
-
};
|
|
66162
|
-
this.concurrency = concurrency || Infinity;
|
|
66163
|
-
this.jobs = [];
|
|
66164
|
-
this.pending = 0;
|
|
66165
|
-
}
|
|
66166
|
-
/**
|
|
66167
|
-
* Adds a job to the queue.
|
|
66168
|
-
*
|
|
66169
|
-
* @param {Function} job The job to run
|
|
66170
|
-
* @public
|
|
66171
|
-
*/
|
|
66172
|
-
add(job) {
|
|
66173
|
-
this.jobs.push(job);
|
|
66174
|
-
this[kRun]();
|
|
66175
|
-
}
|
|
66176
|
-
/**
|
|
66177
|
-
* Removes a job from the queue and runs it if possible.
|
|
66178
|
-
*
|
|
66179
|
-
* @private
|
|
66180
|
-
*/
|
|
66181
|
-
[kRun]() {
|
|
66182
|
-
if (this.pending === this.concurrency) return;
|
|
66183
|
-
if (this.jobs.length) {
|
|
66184
|
-
const job = this.jobs.shift();
|
|
66185
|
-
this.pending++;
|
|
66186
|
-
job(this[kDone]);
|
|
66187
|
-
}
|
|
66188
|
-
}
|
|
66189
|
-
};
|
|
66190
|
-
module.exports = Limiter;
|
|
66191
|
-
}
|
|
66192
|
-
});
|
|
66193
|
-
|
|
66194
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/permessage-deflate.js
|
|
66195
|
-
var require_permessage_deflate2 = __commonJS({
|
|
66196
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
|
|
66197
|
-
var zlib = __require("zlib");
|
|
66198
|
-
var bufferUtil = require_buffer_util2();
|
|
66199
|
-
var Limiter = require_limiter2();
|
|
66200
|
-
var { kStatusCode } = require_constants3();
|
|
66201
|
-
var FastBuffer = Buffer[Symbol.species];
|
|
66202
|
-
var TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
66203
|
-
var kPerMessageDeflate = /* @__PURE__ */ Symbol("permessage-deflate");
|
|
66204
|
-
var kTotalLength = /* @__PURE__ */ Symbol("total-length");
|
|
66205
|
-
var kCallback = /* @__PURE__ */ Symbol("callback");
|
|
66206
|
-
var kBuffers = /* @__PURE__ */ Symbol("buffers");
|
|
66207
|
-
var kError = /* @__PURE__ */ Symbol("error");
|
|
66208
|
-
var zlibLimiter;
|
|
66209
|
-
var PerMessageDeflate3 = class {
|
|
66210
|
-
/**
|
|
66211
|
-
* Creates a PerMessageDeflate instance.
|
|
66212
|
-
*
|
|
66213
|
-
* @param {Object} [options] Configuration options
|
|
66214
|
-
* @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
|
|
66215
|
-
* for, or request, a custom client window size
|
|
66216
|
-
* @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
|
|
66217
|
-
* acknowledge disabling of client context takeover
|
|
66218
|
-
* @param {Number} [options.concurrencyLimit=10] The number of concurrent
|
|
66219
|
-
* calls to zlib
|
|
66220
|
-
* @param {Boolean} [options.isServer=false] Create the instance in either
|
|
66221
|
-
* server or client mode
|
|
66222
|
-
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
|
66223
|
-
* @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
|
|
66224
|
-
* use of a custom server window size
|
|
66225
|
-
* @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
|
|
66226
|
-
* disabling of server context takeover
|
|
66227
|
-
* @param {Number} [options.threshold=1024] Size (in bytes) below which
|
|
66228
|
-
* messages should not be compressed if context takeover is disabled
|
|
66229
|
-
* @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
|
|
66230
|
-
* deflate
|
|
66231
|
-
* @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
|
|
66232
|
-
* inflate
|
|
66233
|
-
*/
|
|
66234
|
-
constructor(options) {
|
|
66235
|
-
this._options = options || {};
|
|
66236
|
-
this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
|
|
66237
|
-
this._maxPayload = this._options.maxPayload | 0;
|
|
66238
|
-
this._isServer = !!this._options.isServer;
|
|
66239
|
-
this._deflate = null;
|
|
66240
|
-
this._inflate = null;
|
|
66241
|
-
this.params = null;
|
|
66242
|
-
if (!zlibLimiter) {
|
|
66243
|
-
const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
|
|
66244
|
-
zlibLimiter = new Limiter(concurrency);
|
|
66245
|
-
}
|
|
66246
|
-
}
|
|
66247
|
-
/**
|
|
66248
|
-
* @type {String}
|
|
66249
|
-
*/
|
|
66250
|
-
static get extensionName() {
|
|
66251
|
-
return "permessage-deflate";
|
|
66252
|
-
}
|
|
66253
|
-
/**
|
|
66254
|
-
* Create an extension negotiation offer.
|
|
66255
|
-
*
|
|
66256
|
-
* @return {Object} Extension parameters
|
|
66257
|
-
* @public
|
|
66258
|
-
*/
|
|
66259
|
-
offer() {
|
|
66260
|
-
const params = {};
|
|
66261
|
-
if (this._options.serverNoContextTakeover) {
|
|
66262
|
-
params.server_no_context_takeover = true;
|
|
66263
|
-
}
|
|
66264
|
-
if (this._options.clientNoContextTakeover) {
|
|
66265
|
-
params.client_no_context_takeover = true;
|
|
66266
|
-
}
|
|
66267
|
-
if (this._options.serverMaxWindowBits) {
|
|
66268
|
-
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
66269
|
-
}
|
|
66270
|
-
if (this._options.clientMaxWindowBits) {
|
|
66271
|
-
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
66272
|
-
} else if (this._options.clientMaxWindowBits == null) {
|
|
66273
|
-
params.client_max_window_bits = true;
|
|
66274
|
-
}
|
|
66275
|
-
return params;
|
|
66276
|
-
}
|
|
66277
|
-
/**
|
|
66278
|
-
* Accept an extension negotiation offer/response.
|
|
66279
|
-
*
|
|
66280
|
-
* @param {Array} configurations The extension negotiation offers/reponse
|
|
66281
|
-
* @return {Object} Accepted configuration
|
|
66282
|
-
* @public
|
|
66283
|
-
*/
|
|
66284
|
-
accept(configurations) {
|
|
66285
|
-
configurations = this.normalizeParams(configurations);
|
|
66286
|
-
this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
|
|
66287
|
-
return this.params;
|
|
66288
|
-
}
|
|
66289
|
-
/**
|
|
66290
|
-
* Releases all resources used by the extension.
|
|
66291
|
-
*
|
|
66292
|
-
* @public
|
|
66293
|
-
*/
|
|
66294
|
-
cleanup() {
|
|
66295
|
-
if (this._inflate) {
|
|
66296
|
-
this._inflate.close();
|
|
66297
|
-
this._inflate = null;
|
|
66298
|
-
}
|
|
66299
|
-
if (this._deflate) {
|
|
66300
|
-
const callback = this._deflate[kCallback];
|
|
66301
|
-
this._deflate.close();
|
|
66302
|
-
this._deflate = null;
|
|
66303
|
-
if (callback) {
|
|
66304
|
-
callback(
|
|
66305
|
-
new Error(
|
|
66306
|
-
"The deflate stream was closed while data was being processed"
|
|
66307
|
-
)
|
|
66308
|
-
);
|
|
66309
|
-
}
|
|
66310
|
-
}
|
|
66311
|
-
}
|
|
66312
|
-
/**
|
|
66313
|
-
* Accept an extension negotiation offer.
|
|
66314
|
-
*
|
|
66315
|
-
* @param {Array} offers The extension negotiation offers
|
|
66316
|
-
* @return {Object} Accepted configuration
|
|
66317
|
-
* @private
|
|
66318
|
-
*/
|
|
66319
|
-
acceptAsServer(offers) {
|
|
66320
|
-
const opts = this._options;
|
|
66321
|
-
const accepted = offers.find((params) => {
|
|
66322
|
-
if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
|
|
66323
|
-
return false;
|
|
66324
|
-
}
|
|
66325
|
-
return true;
|
|
66326
|
-
});
|
|
66327
|
-
if (!accepted) {
|
|
66328
|
-
throw new Error("None of the extension offers can be accepted");
|
|
66329
|
-
}
|
|
66330
|
-
if (opts.serverNoContextTakeover) {
|
|
66331
|
-
accepted.server_no_context_takeover = true;
|
|
66332
|
-
}
|
|
66333
|
-
if (opts.clientNoContextTakeover) {
|
|
66334
|
-
accepted.client_no_context_takeover = true;
|
|
66335
|
-
}
|
|
66336
|
-
if (typeof opts.serverMaxWindowBits === "number") {
|
|
66337
|
-
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
66338
|
-
}
|
|
66339
|
-
if (typeof opts.clientMaxWindowBits === "number") {
|
|
66340
|
-
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
66341
|
-
} else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
|
|
66342
|
-
delete accepted.client_max_window_bits;
|
|
66343
|
-
}
|
|
66344
|
-
return accepted;
|
|
66345
|
-
}
|
|
66346
|
-
/**
|
|
66347
|
-
* Accept the extension negotiation response.
|
|
66348
|
-
*
|
|
66349
|
-
* @param {Array} response The extension negotiation response
|
|
66350
|
-
* @return {Object} Accepted configuration
|
|
66351
|
-
* @private
|
|
66352
|
-
*/
|
|
66353
|
-
acceptAsClient(response) {
|
|
66354
|
-
const params = response[0];
|
|
66355
|
-
if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
|
|
66356
|
-
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
66357
|
-
}
|
|
66358
|
-
if (!params.client_max_window_bits) {
|
|
66359
|
-
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
66360
|
-
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
66361
|
-
}
|
|
66362
|
-
} else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
|
|
66363
|
-
throw new Error(
|
|
66364
|
-
'Unexpected or invalid parameter "client_max_window_bits"'
|
|
66365
|
-
);
|
|
66366
|
-
}
|
|
66367
|
-
return params;
|
|
66368
|
-
}
|
|
66369
|
-
/**
|
|
66370
|
-
* Normalize parameters.
|
|
66371
|
-
*
|
|
66372
|
-
* @param {Array} configurations The extension negotiation offers/reponse
|
|
66373
|
-
* @return {Array} The offers/response with normalized parameters
|
|
66374
|
-
* @private
|
|
66375
|
-
*/
|
|
66376
|
-
normalizeParams(configurations) {
|
|
66377
|
-
configurations.forEach((params) => {
|
|
66378
|
-
Object.keys(params).forEach((key) => {
|
|
66379
|
-
let value2 = params[key];
|
|
66380
|
-
if (value2.length > 1) {
|
|
66381
|
-
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
66382
|
-
}
|
|
66383
|
-
value2 = value2[0];
|
|
66384
|
-
if (key === "client_max_window_bits") {
|
|
66385
|
-
if (value2 !== true) {
|
|
66386
|
-
const num = +value2;
|
|
66387
|
-
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
66388
|
-
throw new TypeError(
|
|
66389
|
-
`Invalid value for parameter "${key}": ${value2}`
|
|
66390
|
-
);
|
|
66391
|
-
}
|
|
66392
|
-
value2 = num;
|
|
66393
|
-
} else if (!this._isServer) {
|
|
66394
|
-
throw new TypeError(
|
|
66395
|
-
`Invalid value for parameter "${key}": ${value2}`
|
|
66396
|
-
);
|
|
66397
|
-
}
|
|
66398
|
-
} else if (key === "server_max_window_bits") {
|
|
66399
|
-
const num = +value2;
|
|
66400
|
-
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
66401
|
-
throw new TypeError(
|
|
66402
|
-
`Invalid value for parameter "${key}": ${value2}`
|
|
66403
|
-
);
|
|
66404
|
-
}
|
|
66405
|
-
value2 = num;
|
|
66406
|
-
} else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
|
|
66407
|
-
if (value2 !== true) {
|
|
66408
|
-
throw new TypeError(
|
|
66409
|
-
`Invalid value for parameter "${key}": ${value2}`
|
|
66410
|
-
);
|
|
66411
|
-
}
|
|
66412
|
-
} else {
|
|
66413
|
-
throw new Error(`Unknown parameter "${key}"`);
|
|
66414
|
-
}
|
|
66415
|
-
params[key] = value2;
|
|
66416
|
-
});
|
|
66417
|
-
});
|
|
66418
|
-
return configurations;
|
|
66419
|
-
}
|
|
66420
|
-
/**
|
|
66421
|
-
* Decompress data. Concurrency limited.
|
|
66422
|
-
*
|
|
66423
|
-
* @param {Buffer} data Compressed data
|
|
66424
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
66425
|
-
* @param {Function} callback Callback
|
|
66426
|
-
* @public
|
|
66427
|
-
*/
|
|
66428
|
-
decompress(data, fin, callback) {
|
|
66429
|
-
zlibLimiter.add((done) => {
|
|
66430
|
-
this._decompress(data, fin, (err, result) => {
|
|
66431
|
-
done();
|
|
66432
|
-
callback(err, result);
|
|
66433
|
-
});
|
|
66434
|
-
});
|
|
66435
|
-
}
|
|
66436
|
-
/**
|
|
66437
|
-
* Compress data. Concurrency limited.
|
|
66438
|
-
*
|
|
66439
|
-
* @param {(Buffer|String)} data Data to compress
|
|
66440
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
66441
|
-
* @param {Function} callback Callback
|
|
66442
|
-
* @public
|
|
66443
|
-
*/
|
|
66444
|
-
compress(data, fin, callback) {
|
|
66445
|
-
zlibLimiter.add((done) => {
|
|
66446
|
-
this._compress(data, fin, (err, result) => {
|
|
66447
|
-
done();
|
|
66448
|
-
callback(err, result);
|
|
66449
|
-
});
|
|
66450
|
-
});
|
|
66451
|
-
}
|
|
66452
|
-
/**
|
|
66453
|
-
* Decompress data.
|
|
66454
|
-
*
|
|
66455
|
-
* @param {Buffer} data Compressed data
|
|
66456
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
66457
|
-
* @param {Function} callback Callback
|
|
66458
|
-
* @private
|
|
66459
|
-
*/
|
|
66460
|
-
_decompress(data, fin, callback) {
|
|
66461
|
-
const endpoint = this._isServer ? "client" : "server";
|
|
66462
|
-
if (!this._inflate) {
|
|
66463
|
-
const key = `${endpoint}_max_window_bits`;
|
|
66464
|
-
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
66465
|
-
this._inflate = zlib.createInflateRaw({
|
|
66466
|
-
...this._options.zlibInflateOptions,
|
|
66467
|
-
windowBits
|
|
66468
|
-
});
|
|
66469
|
-
this._inflate[kPerMessageDeflate] = this;
|
|
66470
|
-
this._inflate[kTotalLength] = 0;
|
|
66471
|
-
this._inflate[kBuffers] = [];
|
|
66472
|
-
this._inflate.on("error", inflateOnError);
|
|
66473
|
-
this._inflate.on("data", inflateOnData);
|
|
66474
|
-
}
|
|
66475
|
-
this._inflate[kCallback] = callback;
|
|
66476
|
-
this._inflate.write(data);
|
|
66477
|
-
if (fin) this._inflate.write(TRAILER);
|
|
66478
|
-
this._inflate.flush(() => {
|
|
66479
|
-
const err = this._inflate[kError];
|
|
66480
|
-
if (err) {
|
|
66481
|
-
this._inflate.close();
|
|
66482
|
-
this._inflate = null;
|
|
66483
|
-
callback(err);
|
|
66484
|
-
return;
|
|
66485
|
-
}
|
|
66486
|
-
const data2 = bufferUtil.concat(
|
|
66487
|
-
this._inflate[kBuffers],
|
|
66488
|
-
this._inflate[kTotalLength]
|
|
66489
|
-
);
|
|
66490
|
-
if (this._inflate._readableState.endEmitted) {
|
|
66491
|
-
this._inflate.close();
|
|
66492
|
-
this._inflate = null;
|
|
66493
|
-
} else {
|
|
66494
|
-
this._inflate[kTotalLength] = 0;
|
|
66495
|
-
this._inflate[kBuffers] = [];
|
|
66496
|
-
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
66497
|
-
this._inflate.reset();
|
|
66498
|
-
}
|
|
66499
|
-
}
|
|
66500
|
-
callback(null, data2);
|
|
66501
|
-
});
|
|
66502
|
-
}
|
|
66503
|
-
/**
|
|
66504
|
-
* Compress data.
|
|
66505
|
-
*
|
|
66506
|
-
* @param {(Buffer|String)} data Data to compress
|
|
66507
|
-
* @param {Boolean} fin Specifies whether or not this is the last fragment
|
|
66508
|
-
* @param {Function} callback Callback
|
|
66509
|
-
* @private
|
|
66510
|
-
*/
|
|
66511
|
-
_compress(data, fin, callback) {
|
|
66512
|
-
const endpoint = this._isServer ? "server" : "client";
|
|
66513
|
-
if (!this._deflate) {
|
|
66514
|
-
const key = `${endpoint}_max_window_bits`;
|
|
66515
|
-
const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
66516
|
-
this._deflate = zlib.createDeflateRaw({
|
|
66517
|
-
...this._options.zlibDeflateOptions,
|
|
66518
|
-
windowBits
|
|
66519
|
-
});
|
|
66520
|
-
this._deflate[kTotalLength] = 0;
|
|
66521
|
-
this._deflate[kBuffers] = [];
|
|
66522
|
-
this._deflate.on("data", deflateOnData);
|
|
66523
|
-
}
|
|
66524
|
-
this._deflate[kCallback] = callback;
|
|
66525
|
-
this._deflate.write(data);
|
|
66526
|
-
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
66527
|
-
if (!this._deflate) {
|
|
66528
|
-
return;
|
|
66529
|
-
}
|
|
66530
|
-
let data2 = bufferUtil.concat(
|
|
66531
|
-
this._deflate[kBuffers],
|
|
66532
|
-
this._deflate[kTotalLength]
|
|
66533
|
-
);
|
|
66534
|
-
if (fin) {
|
|
66535
|
-
data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
|
|
66536
|
-
}
|
|
66537
|
-
this._deflate[kCallback] = null;
|
|
66538
|
-
this._deflate[kTotalLength] = 0;
|
|
66539
|
-
this._deflate[kBuffers] = [];
|
|
66540
|
-
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
66541
|
-
this._deflate.reset();
|
|
66542
|
-
}
|
|
66543
|
-
callback(null, data2);
|
|
66544
|
-
});
|
|
66545
|
-
}
|
|
66546
|
-
};
|
|
66547
|
-
module.exports = PerMessageDeflate3;
|
|
66548
|
-
function deflateOnData(chunk) {
|
|
66549
|
-
this[kBuffers].push(chunk);
|
|
66550
|
-
this[kTotalLength] += chunk.length;
|
|
66551
|
-
}
|
|
66552
|
-
function inflateOnData(chunk) {
|
|
66553
|
-
this[kTotalLength] += chunk.length;
|
|
66554
|
-
if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
|
|
66555
|
-
this[kBuffers].push(chunk);
|
|
66556
|
-
return;
|
|
66557
|
-
}
|
|
66558
|
-
this[kError] = new RangeError("Max payload size exceeded");
|
|
66559
|
-
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
66560
|
-
this[kError][kStatusCode] = 1009;
|
|
66561
|
-
this.removeListener("data", inflateOnData);
|
|
66562
|
-
this.reset();
|
|
66563
|
-
}
|
|
66564
|
-
function inflateOnError(err) {
|
|
66565
|
-
this[kPerMessageDeflate]._inflate = null;
|
|
66566
|
-
if (this[kError]) {
|
|
66567
|
-
this[kCallback](this[kError]);
|
|
66568
|
-
return;
|
|
66569
|
-
}
|
|
66570
|
-
err[kStatusCode] = 1007;
|
|
66571
|
-
this[kCallback](err);
|
|
66572
|
-
}
|
|
66573
|
-
}
|
|
66574
|
-
});
|
|
66575
|
-
|
|
66576
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/validation.js
|
|
66577
|
-
var require_validation2 = __commonJS({
|
|
66578
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/validation.js"(exports, module) {
|
|
66579
|
-
var { isUtf8 } = __require("buffer");
|
|
66580
|
-
var { hasBlob } = require_constants3();
|
|
66581
|
-
var tokenChars = [
|
|
66582
|
-
0,
|
|
66583
|
-
0,
|
|
66584
|
-
0,
|
|
66585
|
-
0,
|
|
66586
|
-
0,
|
|
66587
|
-
0,
|
|
66588
|
-
0,
|
|
66589
|
-
0,
|
|
66590
|
-
0,
|
|
66591
|
-
0,
|
|
66592
|
-
0,
|
|
66593
|
-
0,
|
|
66594
|
-
0,
|
|
66595
|
-
0,
|
|
66596
|
-
0,
|
|
66597
|
-
0,
|
|
66598
|
-
// 0 - 15
|
|
66599
|
-
0,
|
|
66600
|
-
0,
|
|
66601
|
-
0,
|
|
66602
|
-
0,
|
|
66603
|
-
0,
|
|
66604
|
-
0,
|
|
66605
|
-
0,
|
|
66606
|
-
0,
|
|
66607
|
-
0,
|
|
66608
|
-
0,
|
|
66609
|
-
0,
|
|
66610
|
-
0,
|
|
66611
|
-
0,
|
|
66612
|
-
0,
|
|
66613
|
-
0,
|
|
66614
|
-
0,
|
|
66615
|
-
// 16 - 31
|
|
66616
|
-
0,
|
|
66617
|
-
1,
|
|
66618
|
-
0,
|
|
66619
|
-
1,
|
|
66620
|
-
1,
|
|
66621
|
-
1,
|
|
66622
|
-
1,
|
|
66623
|
-
1,
|
|
66624
|
-
0,
|
|
66625
|
-
0,
|
|
66626
|
-
1,
|
|
66627
|
-
1,
|
|
66628
|
-
0,
|
|
66629
|
-
1,
|
|
66630
|
-
1,
|
|
66631
|
-
0,
|
|
66632
|
-
// 32 - 47
|
|
66633
|
-
1,
|
|
66634
|
-
1,
|
|
66635
|
-
1,
|
|
66636
|
-
1,
|
|
66637
|
-
1,
|
|
66638
|
-
1,
|
|
66639
|
-
1,
|
|
66640
|
-
1,
|
|
66641
|
-
1,
|
|
66642
|
-
1,
|
|
66643
|
-
0,
|
|
66644
|
-
0,
|
|
66645
|
-
0,
|
|
66646
|
-
0,
|
|
66647
|
-
0,
|
|
66648
|
-
0,
|
|
66649
|
-
// 48 - 63
|
|
66650
|
-
0,
|
|
66651
|
-
1,
|
|
66652
|
-
1,
|
|
66653
|
-
1,
|
|
66654
|
-
1,
|
|
66655
|
-
1,
|
|
66656
|
-
1,
|
|
66657
|
-
1,
|
|
66658
|
-
1,
|
|
66659
|
-
1,
|
|
66660
|
-
1,
|
|
66661
|
-
1,
|
|
66662
|
-
1,
|
|
66663
|
-
1,
|
|
66664
|
-
1,
|
|
66665
|
-
1,
|
|
66666
|
-
// 64 - 79
|
|
66667
|
-
1,
|
|
66668
|
-
1,
|
|
66669
|
-
1,
|
|
66670
|
-
1,
|
|
66671
|
-
1,
|
|
66672
|
-
1,
|
|
66673
|
-
1,
|
|
66674
|
-
1,
|
|
66675
|
-
1,
|
|
66676
|
-
1,
|
|
66677
|
-
1,
|
|
66678
|
-
0,
|
|
66679
|
-
0,
|
|
66680
|
-
0,
|
|
66681
|
-
1,
|
|
66682
|
-
1,
|
|
66683
|
-
// 80 - 95
|
|
66684
|
-
1,
|
|
66685
|
-
1,
|
|
66686
|
-
1,
|
|
66687
|
-
1,
|
|
66688
|
-
1,
|
|
66689
|
-
1,
|
|
66690
|
-
1,
|
|
66691
|
-
1,
|
|
66692
|
-
1,
|
|
66693
|
-
1,
|
|
66694
|
-
1,
|
|
66695
|
-
1,
|
|
66696
|
-
1,
|
|
66697
|
-
1,
|
|
66698
|
-
1,
|
|
66699
|
-
1,
|
|
66700
|
-
// 96 - 111
|
|
66701
|
-
1,
|
|
66702
|
-
1,
|
|
66703
|
-
1,
|
|
66704
|
-
1,
|
|
66705
|
-
1,
|
|
66706
|
-
1,
|
|
66707
|
-
1,
|
|
66708
|
-
1,
|
|
66709
|
-
1,
|
|
66710
|
-
1,
|
|
66711
|
-
1,
|
|
66712
|
-
0,
|
|
66713
|
-
1,
|
|
66714
|
-
0,
|
|
66715
|
-
1,
|
|
66716
|
-
0
|
|
66717
|
-
// 112 - 127
|
|
66718
|
-
];
|
|
66719
|
-
function isValidStatusCode(code) {
|
|
66720
|
-
return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
|
|
66721
|
-
}
|
|
66722
|
-
function _isValidUTF8(buf) {
|
|
66723
|
-
const len = buf.length;
|
|
66724
|
-
let i2 = 0;
|
|
66725
|
-
while (i2 < len) {
|
|
66726
|
-
if ((buf[i2] & 128) === 0) {
|
|
66727
|
-
i2++;
|
|
66728
|
-
} else if ((buf[i2] & 224) === 192) {
|
|
66729
|
-
if (i2 + 1 === len || (buf[i2 + 1] & 192) !== 128 || (buf[i2] & 254) === 192) {
|
|
66730
|
-
return false;
|
|
66731
|
-
}
|
|
66732
|
-
i2 += 2;
|
|
66733
|
-
} else if ((buf[i2] & 240) === 224) {
|
|
66734
|
-
if (i2 + 2 >= len || (buf[i2 + 1] & 192) !== 128 || (buf[i2 + 2] & 192) !== 128 || buf[i2] === 224 && (buf[i2 + 1] & 224) === 128 || // Overlong
|
|
66735
|
-
buf[i2] === 237 && (buf[i2 + 1] & 224) === 160) {
|
|
66736
|
-
return false;
|
|
66737
|
-
}
|
|
66738
|
-
i2 += 3;
|
|
66739
|
-
} else if ((buf[i2] & 248) === 240) {
|
|
66740
|
-
if (i2 + 3 >= len || (buf[i2 + 1] & 192) !== 128 || (buf[i2 + 2] & 192) !== 128 || (buf[i2 + 3] & 192) !== 128 || buf[i2] === 240 && (buf[i2 + 1] & 240) === 128 || // Overlong
|
|
66741
|
-
buf[i2] === 244 && buf[i2 + 1] > 143 || buf[i2] > 244) {
|
|
66742
|
-
return false;
|
|
66743
|
-
}
|
|
66744
|
-
i2 += 4;
|
|
66745
|
-
} else {
|
|
66746
|
-
return false;
|
|
66747
|
-
}
|
|
66748
|
-
}
|
|
66749
|
-
return true;
|
|
66750
|
-
}
|
|
66751
|
-
function isBlob(value2) {
|
|
66752
|
-
return hasBlob && typeof value2 === "object" && typeof value2.arrayBuffer === "function" && typeof value2.type === "string" && typeof value2.stream === "function" && (value2[Symbol.toStringTag] === "Blob" || value2[Symbol.toStringTag] === "File");
|
|
66753
|
-
}
|
|
66754
|
-
module.exports = {
|
|
66755
|
-
isBlob,
|
|
66756
|
-
isValidStatusCode,
|
|
66757
|
-
isValidUTF8: _isValidUTF8,
|
|
66758
|
-
tokenChars
|
|
66759
|
-
};
|
|
66760
|
-
if (isUtf8) {
|
|
66761
|
-
module.exports.isValidUTF8 = function(buf) {
|
|
66762
|
-
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
66763
|
-
};
|
|
66764
|
-
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
66765
|
-
try {
|
|
66766
|
-
const isValidUTF8 = __require("utf-8-validate");
|
|
66767
|
-
module.exports.isValidUTF8 = function(buf) {
|
|
66768
|
-
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
66769
|
-
};
|
|
66770
|
-
} catch (e) {
|
|
66771
|
-
}
|
|
66772
|
-
}
|
|
66773
|
-
}
|
|
66774
|
-
});
|
|
66775
|
-
|
|
66776
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/receiver.js
|
|
66777
|
-
var require_receiver2 = __commonJS({
|
|
66778
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/receiver.js"(exports, module) {
|
|
66779
|
-
var { Writable } = __require("stream");
|
|
66780
|
-
var PerMessageDeflate3 = require_permessage_deflate2();
|
|
66781
|
-
var {
|
|
66782
|
-
BINARY_TYPES,
|
|
66783
|
-
EMPTY_BUFFER,
|
|
66784
|
-
kStatusCode,
|
|
66785
|
-
kWebSocket
|
|
66786
|
-
} = require_constants3();
|
|
66787
|
-
var { concat, toArrayBuffer, unmask } = require_buffer_util2();
|
|
66788
|
-
var { isValidStatusCode, isValidUTF8 } = require_validation2();
|
|
66789
|
-
var FastBuffer = Buffer[Symbol.species];
|
|
66790
|
-
var GET_INFO = 0;
|
|
66791
|
-
var GET_PAYLOAD_LENGTH_16 = 1;
|
|
66792
|
-
var GET_PAYLOAD_LENGTH_64 = 2;
|
|
66793
|
-
var GET_MASK = 3;
|
|
66794
|
-
var GET_DATA = 4;
|
|
66795
|
-
var INFLATING = 5;
|
|
66796
|
-
var DEFER_EVENT = 6;
|
|
66797
|
-
var Receiver3 = class extends Writable {
|
|
66798
|
-
/**
|
|
66799
|
-
* Creates a Receiver instance.
|
|
66800
|
-
*
|
|
66801
|
-
* @param {Object} [options] Options object
|
|
66802
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
66803
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
66804
|
-
* multiple times in the same tick
|
|
66805
|
-
* @param {String} [options.binaryType=nodebuffer] The type for binary data
|
|
66806
|
-
* @param {Object} [options.extensions] An object containing the negotiated
|
|
66807
|
-
* extensions
|
|
66808
|
-
* @param {Boolean} [options.isServer=false] Specifies whether to operate in
|
|
66809
|
-
* client or server mode
|
|
66810
|
-
* @param {Number} [options.maxBufferedChunks=0] The maximum number of
|
|
66811
|
-
* buffered data chunks
|
|
66812
|
-
* @param {Number} [options.maxFragments=0] The maximum number of message
|
|
66813
|
-
* fragments
|
|
66814
|
-
* @param {Number} [options.maxPayload=0] The maximum allowed message length
|
|
66815
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
66816
|
-
* not to skip UTF-8 validation for text and close messages
|
|
66817
|
-
*/
|
|
66818
|
-
constructor(options = {}) {
|
|
66819
|
-
super();
|
|
66820
|
-
this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
|
|
66821
|
-
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
66822
|
-
this._extensions = options.extensions || {};
|
|
66823
|
-
this._isServer = !!options.isServer;
|
|
66824
|
-
this._maxBufferedChunks = options.maxBufferedChunks | 0;
|
|
66825
|
-
this._maxFragments = options.maxFragments | 0;
|
|
66826
|
-
this._maxPayload = options.maxPayload | 0;
|
|
66827
|
-
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
66828
|
-
this[kWebSocket] = void 0;
|
|
66829
|
-
this._bufferedBytes = 0;
|
|
66830
|
-
this._buffers = [];
|
|
66831
|
-
this._compressed = false;
|
|
66832
|
-
this._payloadLength = 0;
|
|
66833
|
-
this._mask = void 0;
|
|
66834
|
-
this._fragmented = 0;
|
|
66835
|
-
this._masked = false;
|
|
66836
|
-
this._fin = false;
|
|
66837
|
-
this._opcode = 0;
|
|
66838
|
-
this._totalPayloadLength = 0;
|
|
66839
|
-
this._messageLength = 0;
|
|
66840
|
-
this._fragments = [];
|
|
66841
|
-
this._errored = false;
|
|
66842
|
-
this._loop = false;
|
|
66843
|
-
this._state = GET_INFO;
|
|
66844
|
-
}
|
|
66845
|
-
/**
|
|
66846
|
-
* Implements `Writable.prototype._write()`.
|
|
66847
|
-
*
|
|
66848
|
-
* @param {Buffer} chunk The chunk of data to write
|
|
66849
|
-
* @param {String} encoding The character encoding of `chunk`
|
|
66850
|
-
* @param {Function} cb Callback
|
|
66851
|
-
* @private
|
|
66852
|
-
*/
|
|
66853
|
-
_write(chunk, encoding, cb) {
|
|
66854
|
-
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
66855
|
-
if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
|
|
66856
|
-
cb(
|
|
66857
|
-
this.createError(
|
|
66858
|
-
RangeError,
|
|
66859
|
-
"Too many buffered chunks",
|
|
66860
|
-
false,
|
|
66861
|
-
1008,
|
|
66862
|
-
"WS_ERR_TOO_MANY_BUFFERED_PARTS"
|
|
66863
|
-
)
|
|
66864
|
-
);
|
|
66865
|
-
return;
|
|
66866
|
-
}
|
|
66867
|
-
this._bufferedBytes += chunk.length;
|
|
66868
|
-
this._buffers.push(chunk);
|
|
66869
|
-
this.startLoop(cb);
|
|
66870
|
-
}
|
|
66871
|
-
/**
|
|
66872
|
-
* Consumes `n` bytes from the buffered data.
|
|
66873
|
-
*
|
|
66874
|
-
* @param {Number} n The number of bytes to consume
|
|
66875
|
-
* @return {Buffer} The consumed bytes
|
|
66876
|
-
* @private
|
|
66877
|
-
*/
|
|
66878
|
-
consume(n3) {
|
|
66879
|
-
this._bufferedBytes -= n3;
|
|
66880
|
-
if (n3 === this._buffers[0].length) return this._buffers.shift();
|
|
66881
|
-
if (n3 < this._buffers[0].length) {
|
|
66882
|
-
const buf = this._buffers[0];
|
|
66883
|
-
this._buffers[0] = new FastBuffer(
|
|
66884
|
-
buf.buffer,
|
|
66885
|
-
buf.byteOffset + n3,
|
|
66886
|
-
buf.length - n3
|
|
66887
|
-
);
|
|
66888
|
-
return new FastBuffer(buf.buffer, buf.byteOffset, n3);
|
|
66889
|
-
}
|
|
66890
|
-
const dst = Buffer.allocUnsafe(n3);
|
|
66891
|
-
do {
|
|
66892
|
-
const buf = this._buffers[0];
|
|
66893
|
-
const offset = dst.length - n3;
|
|
66894
|
-
if (n3 >= buf.length) {
|
|
66895
|
-
dst.set(this._buffers.shift(), offset);
|
|
66896
|
-
} else {
|
|
66897
|
-
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n3), offset);
|
|
66898
|
-
this._buffers[0] = new FastBuffer(
|
|
66899
|
-
buf.buffer,
|
|
66900
|
-
buf.byteOffset + n3,
|
|
66901
|
-
buf.length - n3
|
|
66902
|
-
);
|
|
66903
|
-
}
|
|
66904
|
-
n3 -= buf.length;
|
|
66905
|
-
} while (n3 > 0);
|
|
66906
|
-
return dst;
|
|
66907
|
-
}
|
|
66908
|
-
/**
|
|
66909
|
-
* Starts the parsing loop.
|
|
66910
|
-
*
|
|
66911
|
-
* @param {Function} cb Callback
|
|
66912
|
-
* @private
|
|
66913
|
-
*/
|
|
66914
|
-
startLoop(cb) {
|
|
66915
|
-
this._loop = true;
|
|
66916
|
-
do {
|
|
66917
|
-
switch (this._state) {
|
|
66918
|
-
case GET_INFO:
|
|
66919
|
-
this.getInfo(cb);
|
|
66920
|
-
break;
|
|
66921
|
-
case GET_PAYLOAD_LENGTH_16:
|
|
66922
|
-
this.getPayloadLength16(cb);
|
|
66923
|
-
break;
|
|
66924
|
-
case GET_PAYLOAD_LENGTH_64:
|
|
66925
|
-
this.getPayloadLength64(cb);
|
|
66926
|
-
break;
|
|
66927
|
-
case GET_MASK:
|
|
66928
|
-
this.getMask();
|
|
66929
|
-
break;
|
|
66930
|
-
case GET_DATA:
|
|
66931
|
-
this.getData(cb);
|
|
66932
|
-
break;
|
|
66933
|
-
case INFLATING:
|
|
66934
|
-
case DEFER_EVENT:
|
|
66935
|
-
this._loop = false;
|
|
66936
|
-
return;
|
|
66937
|
-
}
|
|
66938
|
-
} while (this._loop);
|
|
66939
|
-
if (!this._errored) cb();
|
|
66940
|
-
}
|
|
66941
|
-
/**
|
|
66942
|
-
* Reads the first two bytes of a frame.
|
|
66943
|
-
*
|
|
66944
|
-
* @param {Function} cb Callback
|
|
66945
|
-
* @private
|
|
66946
|
-
*/
|
|
66947
|
-
getInfo(cb) {
|
|
66948
|
-
if (this._bufferedBytes < 2) {
|
|
66949
|
-
this._loop = false;
|
|
66950
|
-
return;
|
|
66951
|
-
}
|
|
66952
|
-
const buf = this.consume(2);
|
|
66953
|
-
if ((buf[0] & 48) !== 0) {
|
|
66954
|
-
const error = this.createError(
|
|
66955
|
-
RangeError,
|
|
66956
|
-
"RSV2 and RSV3 must be clear",
|
|
66957
|
-
true,
|
|
66958
|
-
1002,
|
|
66959
|
-
"WS_ERR_UNEXPECTED_RSV_2_3"
|
|
66960
|
-
);
|
|
66961
|
-
cb(error);
|
|
66962
|
-
return;
|
|
66963
|
-
}
|
|
66964
|
-
const compressed = (buf[0] & 64) === 64;
|
|
66965
|
-
if (compressed && !this._extensions[PerMessageDeflate3.extensionName]) {
|
|
66966
|
-
const error = this.createError(
|
|
66967
|
-
RangeError,
|
|
66968
|
-
"RSV1 must be clear",
|
|
66969
|
-
true,
|
|
66970
|
-
1002,
|
|
66971
|
-
"WS_ERR_UNEXPECTED_RSV_1"
|
|
66972
|
-
);
|
|
66973
|
-
cb(error);
|
|
66974
|
-
return;
|
|
66975
|
-
}
|
|
66976
|
-
this._fin = (buf[0] & 128) === 128;
|
|
66977
|
-
this._opcode = buf[0] & 15;
|
|
66978
|
-
this._payloadLength = buf[1] & 127;
|
|
66979
|
-
if (this._opcode === 0) {
|
|
66980
|
-
if (compressed) {
|
|
66981
|
-
const error = this.createError(
|
|
66982
|
-
RangeError,
|
|
66983
|
-
"RSV1 must be clear",
|
|
66984
|
-
true,
|
|
66985
|
-
1002,
|
|
66986
|
-
"WS_ERR_UNEXPECTED_RSV_1"
|
|
66987
|
-
);
|
|
66988
|
-
cb(error);
|
|
66989
|
-
return;
|
|
66990
|
-
}
|
|
66991
|
-
if (!this._fragmented) {
|
|
66992
|
-
const error = this.createError(
|
|
66993
|
-
RangeError,
|
|
66994
|
-
"invalid opcode 0",
|
|
66995
|
-
true,
|
|
66996
|
-
1002,
|
|
66997
|
-
"WS_ERR_INVALID_OPCODE"
|
|
66998
|
-
);
|
|
66999
|
-
cb(error);
|
|
67000
|
-
return;
|
|
67001
|
-
}
|
|
67002
|
-
this._opcode = this._fragmented;
|
|
67003
|
-
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
67004
|
-
if (this._fragmented) {
|
|
67005
|
-
const error = this.createError(
|
|
67006
|
-
RangeError,
|
|
67007
|
-
`invalid opcode ${this._opcode}`,
|
|
67008
|
-
true,
|
|
67009
|
-
1002,
|
|
67010
|
-
"WS_ERR_INVALID_OPCODE"
|
|
67011
|
-
);
|
|
67012
|
-
cb(error);
|
|
67013
|
-
return;
|
|
67014
|
-
}
|
|
67015
|
-
this._compressed = compressed;
|
|
67016
|
-
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
67017
|
-
if (!this._fin) {
|
|
67018
|
-
const error = this.createError(
|
|
67019
|
-
RangeError,
|
|
67020
|
-
"FIN must be set",
|
|
67021
|
-
true,
|
|
67022
|
-
1002,
|
|
67023
|
-
"WS_ERR_EXPECTED_FIN"
|
|
67024
|
-
);
|
|
67025
|
-
cb(error);
|
|
67026
|
-
return;
|
|
67027
|
-
}
|
|
67028
|
-
if (compressed) {
|
|
67029
|
-
const error = this.createError(
|
|
67030
|
-
RangeError,
|
|
67031
|
-
"RSV1 must be clear",
|
|
67032
|
-
true,
|
|
67033
|
-
1002,
|
|
67034
|
-
"WS_ERR_UNEXPECTED_RSV_1"
|
|
67035
|
-
);
|
|
67036
|
-
cb(error);
|
|
67037
|
-
return;
|
|
67038
|
-
}
|
|
67039
|
-
if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
|
|
67040
|
-
const error = this.createError(
|
|
67041
|
-
RangeError,
|
|
67042
|
-
`invalid payload length ${this._payloadLength}`,
|
|
67043
|
-
true,
|
|
67044
|
-
1002,
|
|
67045
|
-
"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
|
|
67046
|
-
);
|
|
67047
|
-
cb(error);
|
|
67048
|
-
return;
|
|
67049
|
-
}
|
|
67050
|
-
} else {
|
|
67051
|
-
const error = this.createError(
|
|
67052
|
-
RangeError,
|
|
67053
|
-
`invalid opcode ${this._opcode}`,
|
|
67054
|
-
true,
|
|
67055
|
-
1002,
|
|
67056
|
-
"WS_ERR_INVALID_OPCODE"
|
|
67057
|
-
);
|
|
67058
|
-
cb(error);
|
|
67059
|
-
return;
|
|
67060
|
-
}
|
|
67061
|
-
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
67062
|
-
this._masked = (buf[1] & 128) === 128;
|
|
67063
|
-
if (this._isServer) {
|
|
67064
|
-
if (!this._masked) {
|
|
67065
|
-
const error = this.createError(
|
|
67066
|
-
RangeError,
|
|
67067
|
-
"MASK must be set",
|
|
67068
|
-
true,
|
|
67069
|
-
1002,
|
|
67070
|
-
"WS_ERR_EXPECTED_MASK"
|
|
67071
|
-
);
|
|
67072
|
-
cb(error);
|
|
67073
|
-
return;
|
|
67074
|
-
}
|
|
67075
|
-
} else if (this._masked) {
|
|
67076
|
-
const error = this.createError(
|
|
67077
|
-
RangeError,
|
|
67078
|
-
"MASK must be clear",
|
|
67079
|
-
true,
|
|
67080
|
-
1002,
|
|
67081
|
-
"WS_ERR_UNEXPECTED_MASK"
|
|
67082
|
-
);
|
|
67083
|
-
cb(error);
|
|
67084
|
-
return;
|
|
67085
|
-
}
|
|
67086
|
-
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
67087
|
-
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
67088
|
-
else this.haveLength(cb);
|
|
67089
|
-
}
|
|
67090
|
-
/**
|
|
67091
|
-
* Gets extended payload length (7+16).
|
|
67092
|
-
*
|
|
67093
|
-
* @param {Function} cb Callback
|
|
67094
|
-
* @private
|
|
67095
|
-
*/
|
|
67096
|
-
getPayloadLength16(cb) {
|
|
67097
|
-
if (this._bufferedBytes < 2) {
|
|
67098
|
-
this._loop = false;
|
|
67099
|
-
return;
|
|
67100
|
-
}
|
|
67101
|
-
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
67102
|
-
this.haveLength(cb);
|
|
67103
|
-
}
|
|
67104
|
-
/**
|
|
67105
|
-
* Gets extended payload length (7+64).
|
|
67106
|
-
*
|
|
67107
|
-
* @param {Function} cb Callback
|
|
67108
|
-
* @private
|
|
67109
|
-
*/
|
|
67110
|
-
getPayloadLength64(cb) {
|
|
67111
|
-
if (this._bufferedBytes < 8) {
|
|
67112
|
-
this._loop = false;
|
|
67113
|
-
return;
|
|
67114
|
-
}
|
|
67115
|
-
const buf = this.consume(8);
|
|
67116
|
-
const num = buf.readUInt32BE(0);
|
|
67117
|
-
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
67118
|
-
const error = this.createError(
|
|
67119
|
-
RangeError,
|
|
67120
|
-
"Unsupported WebSocket frame: payload length > 2^53 - 1",
|
|
67121
|
-
false,
|
|
67122
|
-
1009,
|
|
67123
|
-
"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
|
|
67124
|
-
);
|
|
67125
|
-
cb(error);
|
|
67126
|
-
return;
|
|
67127
|
-
}
|
|
67128
|
-
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
67129
|
-
this.haveLength(cb);
|
|
67130
|
-
}
|
|
67131
|
-
/**
|
|
67132
|
-
* Payload length has been read.
|
|
67133
|
-
*
|
|
67134
|
-
* @param {Function} cb Callback
|
|
67135
|
-
* @private
|
|
67136
|
-
*/
|
|
67137
|
-
haveLength(cb) {
|
|
67138
|
-
if (this._payloadLength && this._opcode < 8) {
|
|
67139
|
-
this._totalPayloadLength += this._payloadLength;
|
|
67140
|
-
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
67141
|
-
const error = this.createError(
|
|
67142
|
-
RangeError,
|
|
67143
|
-
"Max payload size exceeded",
|
|
67144
|
-
false,
|
|
67145
|
-
1009,
|
|
67146
|
-
"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
|
|
67147
|
-
);
|
|
67148
|
-
cb(error);
|
|
67149
|
-
return;
|
|
67150
|
-
}
|
|
67151
|
-
}
|
|
67152
|
-
if (this._masked) this._state = GET_MASK;
|
|
67153
|
-
else this._state = GET_DATA;
|
|
67154
|
-
}
|
|
67155
|
-
/**
|
|
67156
|
-
* Reads mask bytes.
|
|
67157
|
-
*
|
|
67158
|
-
* @private
|
|
67159
|
-
*/
|
|
67160
|
-
getMask() {
|
|
67161
|
-
if (this._bufferedBytes < 4) {
|
|
67162
|
-
this._loop = false;
|
|
67163
|
-
return;
|
|
67164
|
-
}
|
|
67165
|
-
this._mask = this.consume(4);
|
|
67166
|
-
this._state = GET_DATA;
|
|
67167
|
-
}
|
|
67168
|
-
/**
|
|
67169
|
-
* Reads data bytes.
|
|
67170
|
-
*
|
|
67171
|
-
* @param {Function} cb Callback
|
|
67172
|
-
* @private
|
|
67173
|
-
*/
|
|
67174
|
-
getData(cb) {
|
|
67175
|
-
let data = EMPTY_BUFFER;
|
|
67176
|
-
if (this._payloadLength) {
|
|
67177
|
-
if (this._bufferedBytes < this._payloadLength) {
|
|
67178
|
-
this._loop = false;
|
|
67179
|
-
return;
|
|
67180
|
-
}
|
|
67181
|
-
data = this.consume(this._payloadLength);
|
|
67182
|
-
if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
|
|
67183
|
-
unmask(data, this._mask);
|
|
67184
|
-
}
|
|
67185
|
-
}
|
|
67186
|
-
if (this._opcode > 7) {
|
|
67187
|
-
this.controlMessage(data, cb);
|
|
67188
|
-
return;
|
|
67189
|
-
}
|
|
67190
|
-
if (this._compressed) {
|
|
67191
|
-
this._state = INFLATING;
|
|
67192
|
-
this.decompress(data, cb);
|
|
67193
|
-
return;
|
|
67194
|
-
}
|
|
67195
|
-
if (data.length) {
|
|
67196
|
-
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
67197
|
-
const error = this.createError(
|
|
67198
|
-
RangeError,
|
|
67199
|
-
"Too many message fragments",
|
|
67200
|
-
false,
|
|
67201
|
-
1008,
|
|
67202
|
-
"WS_ERR_TOO_MANY_BUFFERED_PARTS"
|
|
67203
|
-
);
|
|
67204
|
-
cb(error);
|
|
67205
|
-
return;
|
|
67206
|
-
}
|
|
67207
|
-
this._messageLength = this._totalPayloadLength;
|
|
67208
|
-
this._fragments.push(data);
|
|
67209
|
-
}
|
|
67210
|
-
this.dataMessage(cb);
|
|
67211
|
-
}
|
|
67212
|
-
/**
|
|
67213
|
-
* Decompresses data.
|
|
67214
|
-
*
|
|
67215
|
-
* @param {Buffer} data Compressed data
|
|
67216
|
-
* @param {Function} cb Callback
|
|
67217
|
-
* @private
|
|
67218
|
-
*/
|
|
67219
|
-
decompress(data, cb) {
|
|
67220
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate3.extensionName];
|
|
67221
|
-
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
67222
|
-
if (err) return cb(err);
|
|
67223
|
-
if (buf.length) {
|
|
67224
|
-
this._messageLength += buf.length;
|
|
67225
|
-
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
67226
|
-
const error = this.createError(
|
|
67227
|
-
RangeError,
|
|
67228
|
-
"Max payload size exceeded",
|
|
67229
|
-
false,
|
|
67230
|
-
1009,
|
|
67231
|
-
"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
|
|
67232
|
-
);
|
|
67233
|
-
cb(error);
|
|
67234
|
-
return;
|
|
67235
|
-
}
|
|
67236
|
-
if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
|
|
67237
|
-
const error = this.createError(
|
|
67238
|
-
RangeError,
|
|
67239
|
-
"Too many message fragments",
|
|
67240
|
-
false,
|
|
67241
|
-
1008,
|
|
67242
|
-
"WS_ERR_TOO_MANY_BUFFERED_PARTS"
|
|
67243
|
-
);
|
|
67244
|
-
cb(error);
|
|
67245
|
-
return;
|
|
67246
|
-
}
|
|
67247
|
-
this._fragments.push(buf);
|
|
67248
|
-
}
|
|
67249
|
-
this.dataMessage(cb);
|
|
67250
|
-
if (this._state === GET_INFO) this.startLoop(cb);
|
|
67251
|
-
});
|
|
67252
|
-
}
|
|
67253
|
-
/**
|
|
67254
|
-
* Handles a data message.
|
|
67255
|
-
*
|
|
67256
|
-
* @param {Function} cb Callback
|
|
67257
|
-
* @private
|
|
67258
|
-
*/
|
|
67259
|
-
dataMessage(cb) {
|
|
67260
|
-
if (!this._fin) {
|
|
67261
|
-
this._state = GET_INFO;
|
|
67262
|
-
return;
|
|
67263
|
-
}
|
|
67264
|
-
const messageLength = this._messageLength;
|
|
67265
|
-
const fragments = this._fragments;
|
|
67266
|
-
this._totalPayloadLength = 0;
|
|
67267
|
-
this._messageLength = 0;
|
|
67268
|
-
this._fragmented = 0;
|
|
67269
|
-
this._fragments = [];
|
|
67270
|
-
if (this._opcode === 2) {
|
|
67271
|
-
let data;
|
|
67272
|
-
if (this._binaryType === "nodebuffer") {
|
|
67273
|
-
data = concat(fragments, messageLength);
|
|
67274
|
-
} else if (this._binaryType === "arraybuffer") {
|
|
67275
|
-
data = toArrayBuffer(concat(fragments, messageLength));
|
|
67276
|
-
} else if (this._binaryType === "blob") {
|
|
67277
|
-
data = new Blob(fragments);
|
|
67278
|
-
} else {
|
|
67279
|
-
data = fragments;
|
|
67280
|
-
}
|
|
67281
|
-
if (this._allowSynchronousEvents) {
|
|
67282
|
-
this.emit("message", data, true);
|
|
67283
|
-
this._state = GET_INFO;
|
|
67284
|
-
} else {
|
|
67285
|
-
this._state = DEFER_EVENT;
|
|
67286
|
-
setImmediate(() => {
|
|
67287
|
-
this.emit("message", data, true);
|
|
67288
|
-
this._state = GET_INFO;
|
|
67289
|
-
this.startLoop(cb);
|
|
67290
|
-
});
|
|
67291
|
-
}
|
|
67292
|
-
} else {
|
|
67293
|
-
const buf = concat(fragments, messageLength);
|
|
67294
|
-
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
67295
|
-
const error = this.createError(
|
|
67296
|
-
Error,
|
|
67297
|
-
"invalid UTF-8 sequence",
|
|
67298
|
-
true,
|
|
67299
|
-
1007,
|
|
67300
|
-
"WS_ERR_INVALID_UTF8"
|
|
67301
|
-
);
|
|
67302
|
-
cb(error);
|
|
67303
|
-
return;
|
|
67304
|
-
}
|
|
67305
|
-
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
67306
|
-
this.emit("message", buf, false);
|
|
67307
|
-
this._state = GET_INFO;
|
|
67308
|
-
} else {
|
|
67309
|
-
this._state = DEFER_EVENT;
|
|
67310
|
-
setImmediate(() => {
|
|
67311
|
-
this.emit("message", buf, false);
|
|
67312
|
-
this._state = GET_INFO;
|
|
67313
|
-
this.startLoop(cb);
|
|
67314
|
-
});
|
|
67315
|
-
}
|
|
67316
|
-
}
|
|
67317
|
-
}
|
|
67318
|
-
/**
|
|
67319
|
-
* Handles a control message.
|
|
67320
|
-
*
|
|
67321
|
-
* @param {Buffer} data Data to handle
|
|
67322
|
-
* @return {(Error|RangeError|undefined)} A possible error
|
|
67323
|
-
* @private
|
|
67324
|
-
*/
|
|
67325
|
-
controlMessage(data, cb) {
|
|
67326
|
-
if (this._opcode === 8) {
|
|
67327
|
-
if (data.length === 0) {
|
|
67328
|
-
this._loop = false;
|
|
67329
|
-
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
67330
|
-
this.end();
|
|
67331
|
-
} else {
|
|
67332
|
-
const code = data.readUInt16BE(0);
|
|
67333
|
-
if (!isValidStatusCode(code)) {
|
|
67334
|
-
const error = this.createError(
|
|
67335
|
-
RangeError,
|
|
67336
|
-
`invalid status code ${code}`,
|
|
67337
|
-
true,
|
|
67338
|
-
1002,
|
|
67339
|
-
"WS_ERR_INVALID_CLOSE_CODE"
|
|
67340
|
-
);
|
|
67341
|
-
cb(error);
|
|
67342
|
-
return;
|
|
67343
|
-
}
|
|
67344
|
-
const buf = new FastBuffer(
|
|
67345
|
-
data.buffer,
|
|
67346
|
-
data.byteOffset + 2,
|
|
67347
|
-
data.length - 2
|
|
67348
|
-
);
|
|
67349
|
-
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
67350
|
-
const error = this.createError(
|
|
67351
|
-
Error,
|
|
67352
|
-
"invalid UTF-8 sequence",
|
|
67353
|
-
true,
|
|
67354
|
-
1007,
|
|
67355
|
-
"WS_ERR_INVALID_UTF8"
|
|
67356
|
-
);
|
|
67357
|
-
cb(error);
|
|
67358
|
-
return;
|
|
67359
|
-
}
|
|
67360
|
-
this._loop = false;
|
|
67361
|
-
this.emit("conclude", code, buf);
|
|
67362
|
-
this.end();
|
|
67363
|
-
}
|
|
67364
|
-
this._state = GET_INFO;
|
|
67365
|
-
return;
|
|
67366
|
-
}
|
|
67367
|
-
if (this._allowSynchronousEvents) {
|
|
67368
|
-
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
67369
|
-
this._state = GET_INFO;
|
|
67370
|
-
} else {
|
|
67371
|
-
this._state = DEFER_EVENT;
|
|
67372
|
-
setImmediate(() => {
|
|
67373
|
-
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
67374
|
-
this._state = GET_INFO;
|
|
67375
|
-
this.startLoop(cb);
|
|
67376
|
-
});
|
|
67377
|
-
}
|
|
67378
|
-
}
|
|
67379
|
-
/**
|
|
67380
|
-
* Builds an error object.
|
|
67381
|
-
*
|
|
67382
|
-
* @param {function(new:Error|RangeError)} ErrorCtor The error constructor
|
|
67383
|
-
* @param {String} message The error message
|
|
67384
|
-
* @param {Boolean} prefix Specifies whether or not to add a default prefix to
|
|
67385
|
-
* `message`
|
|
67386
|
-
* @param {Number} statusCode The status code
|
|
67387
|
-
* @param {String} errorCode The exposed error code
|
|
67388
|
-
* @return {(Error|RangeError)} The error
|
|
67389
|
-
* @private
|
|
67390
|
-
*/
|
|
67391
|
-
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
67392
|
-
this._loop = false;
|
|
67393
|
-
this._errored = true;
|
|
67394
|
-
const err = new ErrorCtor(
|
|
67395
|
-
prefix ? `Invalid WebSocket frame: ${message}` : message
|
|
67396
|
-
);
|
|
67397
|
-
Error.captureStackTrace(err, this.createError);
|
|
67398
|
-
err.code = errorCode;
|
|
67399
|
-
err[kStatusCode] = statusCode;
|
|
67400
|
-
return err;
|
|
67401
|
-
}
|
|
67402
|
-
};
|
|
67403
|
-
module.exports = Receiver3;
|
|
67404
|
-
}
|
|
67405
|
-
});
|
|
67406
|
-
|
|
67407
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/sender.js
|
|
67408
|
-
var require_sender2 = __commonJS({
|
|
67409
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/sender.js"(exports, module) {
|
|
67410
|
-
var { Duplex } = __require("stream");
|
|
67411
|
-
var { randomFillSync } = __require("crypto");
|
|
67412
|
-
var {
|
|
67413
|
-
types: { isUint8Array }
|
|
67414
|
-
} = __require("util");
|
|
67415
|
-
var PerMessageDeflate3 = require_permessage_deflate2();
|
|
67416
|
-
var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants3();
|
|
67417
|
-
var { isBlob, isValidStatusCode } = require_validation2();
|
|
67418
|
-
var { mask: applyMask, toBuffer } = require_buffer_util2();
|
|
67419
|
-
var kByteLength = /* @__PURE__ */ Symbol("kByteLength");
|
|
67420
|
-
var maskBuffer = Buffer.alloc(4);
|
|
67421
|
-
var RANDOM_POOL_SIZE = 8 * 1024;
|
|
67422
|
-
var randomPool;
|
|
67423
|
-
var randomPoolPointer = RANDOM_POOL_SIZE;
|
|
67424
|
-
var DEFAULT = 0;
|
|
67425
|
-
var DEFLATING = 1;
|
|
67426
|
-
var GET_BLOB_DATA = 2;
|
|
67427
|
-
var Sender3 = class _Sender {
|
|
67428
|
-
/**
|
|
67429
|
-
* Creates a Sender instance.
|
|
67430
|
-
*
|
|
67431
|
-
* @param {Duplex} socket The connection socket
|
|
67432
|
-
* @param {Object} [extensions] An object containing the negotiated extensions
|
|
67433
|
-
* @param {Function} [generateMask] The function used to generate the masking
|
|
67434
|
-
* key
|
|
67435
|
-
*/
|
|
67436
|
-
constructor(socket, extensions, generateMask) {
|
|
67437
|
-
this._extensions = extensions || {};
|
|
67438
|
-
if (generateMask) {
|
|
67439
|
-
this._generateMask = generateMask;
|
|
67440
|
-
this._maskBuffer = Buffer.alloc(4);
|
|
67441
|
-
}
|
|
67442
|
-
this._socket = socket;
|
|
67443
|
-
this._firstFragment = true;
|
|
67444
|
-
this._compress = false;
|
|
67445
|
-
this._bufferedBytes = 0;
|
|
67446
|
-
this._queue = [];
|
|
67447
|
-
this._state = DEFAULT;
|
|
67448
|
-
this.onerror = NOOP;
|
|
67449
|
-
this[kWebSocket] = void 0;
|
|
67450
|
-
}
|
|
67451
|
-
/**
|
|
67452
|
-
* Frames a piece of data according to the HyBi WebSocket protocol.
|
|
67453
|
-
*
|
|
67454
|
-
* @param {(Buffer|String)} data The data to frame
|
|
67455
|
-
* @param {Object} options Options object
|
|
67456
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
67457
|
-
* FIN bit
|
|
67458
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
67459
|
-
* masking key
|
|
67460
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
67461
|
-
* `data`
|
|
67462
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
67463
|
-
* key
|
|
67464
|
-
* @param {Number} options.opcode The opcode
|
|
67465
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
67466
|
-
* modified
|
|
67467
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
67468
|
-
* RSV1 bit
|
|
67469
|
-
* @return {(Buffer|String)[]} The framed data
|
|
67470
|
-
* @public
|
|
67471
|
-
*/
|
|
67472
|
-
static frame(data, options) {
|
|
67473
|
-
let mask;
|
|
67474
|
-
let merge = false;
|
|
67475
|
-
let offset = 2;
|
|
67476
|
-
let skipMasking = false;
|
|
67477
|
-
if (options.mask) {
|
|
67478
|
-
mask = options.maskBuffer || maskBuffer;
|
|
67479
|
-
if (options.generateMask) {
|
|
67480
|
-
options.generateMask(mask);
|
|
67481
|
-
} else {
|
|
67482
|
-
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
67483
|
-
if (randomPool === void 0) {
|
|
67484
|
-
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
67485
|
-
}
|
|
67486
|
-
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
67487
|
-
randomPoolPointer = 0;
|
|
67488
|
-
}
|
|
67489
|
-
mask[0] = randomPool[randomPoolPointer++];
|
|
67490
|
-
mask[1] = randomPool[randomPoolPointer++];
|
|
67491
|
-
mask[2] = randomPool[randomPoolPointer++];
|
|
67492
|
-
mask[3] = randomPool[randomPoolPointer++];
|
|
67493
|
-
}
|
|
67494
|
-
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
67495
|
-
offset = 6;
|
|
67496
|
-
}
|
|
67497
|
-
let dataLength;
|
|
67498
|
-
if (typeof data === "string") {
|
|
67499
|
-
if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
|
|
67500
|
-
dataLength = options[kByteLength];
|
|
67501
|
-
} else {
|
|
67502
|
-
data = Buffer.from(data);
|
|
67503
|
-
dataLength = data.length;
|
|
67504
|
-
}
|
|
67505
|
-
} else {
|
|
67506
|
-
dataLength = data.length;
|
|
67507
|
-
merge = options.mask && options.readOnly && !skipMasking;
|
|
67508
|
-
}
|
|
67509
|
-
let payloadLength = dataLength;
|
|
67510
|
-
if (dataLength >= 65536) {
|
|
67511
|
-
offset += 8;
|
|
67512
|
-
payloadLength = 127;
|
|
67513
|
-
} else if (dataLength > 125) {
|
|
67514
|
-
offset += 2;
|
|
67515
|
-
payloadLength = 126;
|
|
67516
|
-
}
|
|
67517
|
-
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
67518
|
-
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
67519
|
-
if (options.rsv1) target[0] |= 64;
|
|
67520
|
-
target[1] = payloadLength;
|
|
67521
|
-
if (payloadLength === 126) {
|
|
67522
|
-
target.writeUInt16BE(dataLength, 2);
|
|
67523
|
-
} else if (payloadLength === 127) {
|
|
67524
|
-
target[2] = target[3] = 0;
|
|
67525
|
-
target.writeUIntBE(dataLength, 4, 6);
|
|
67526
|
-
}
|
|
67527
|
-
if (!options.mask) return [target, data];
|
|
67528
|
-
target[1] |= 128;
|
|
67529
|
-
target[offset - 4] = mask[0];
|
|
67530
|
-
target[offset - 3] = mask[1];
|
|
67531
|
-
target[offset - 2] = mask[2];
|
|
67532
|
-
target[offset - 1] = mask[3];
|
|
67533
|
-
if (skipMasking) return [target, data];
|
|
67534
|
-
if (merge) {
|
|
67535
|
-
applyMask(data, mask, target, offset, dataLength);
|
|
67536
|
-
return [target];
|
|
67537
|
-
}
|
|
67538
|
-
applyMask(data, mask, data, 0, dataLength);
|
|
67539
|
-
return [target, data];
|
|
67540
|
-
}
|
|
67541
|
-
/**
|
|
67542
|
-
* Sends a close message to the other peer.
|
|
67543
|
-
*
|
|
67544
|
-
* @param {Number} [code] The status code component of the body
|
|
67545
|
-
* @param {(String|Buffer)} [data] The message component of the body
|
|
67546
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask the message
|
|
67547
|
-
* @param {Function} [cb] Callback
|
|
67548
|
-
* @public
|
|
67549
|
-
*/
|
|
67550
|
-
close(code, data, mask, cb) {
|
|
67551
|
-
let buf;
|
|
67552
|
-
if (code === void 0) {
|
|
67553
|
-
buf = EMPTY_BUFFER;
|
|
67554
|
-
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
67555
|
-
throw new TypeError("First argument must be a valid error code number");
|
|
67556
|
-
} else if (data === void 0 || !data.length) {
|
|
67557
|
-
buf = Buffer.allocUnsafe(2);
|
|
67558
|
-
buf.writeUInt16BE(code, 0);
|
|
67559
|
-
} else {
|
|
67560
|
-
const length = Buffer.byteLength(data);
|
|
67561
|
-
if (length > 123) {
|
|
67562
|
-
throw new RangeError("The message must not be greater than 123 bytes");
|
|
67563
|
-
}
|
|
67564
|
-
buf = Buffer.allocUnsafe(2 + length);
|
|
67565
|
-
buf.writeUInt16BE(code, 0);
|
|
67566
|
-
if (typeof data === "string") {
|
|
67567
|
-
buf.write(data, 2);
|
|
67568
|
-
} else if (isUint8Array(data)) {
|
|
67569
|
-
buf.set(data, 2);
|
|
67570
|
-
} else {
|
|
67571
|
-
throw new TypeError("Second argument must be a string or a Uint8Array");
|
|
67572
|
-
}
|
|
67573
|
-
}
|
|
67574
|
-
const options = {
|
|
67575
|
-
[kByteLength]: buf.length,
|
|
67576
|
-
fin: true,
|
|
67577
|
-
generateMask: this._generateMask,
|
|
67578
|
-
mask,
|
|
67579
|
-
maskBuffer: this._maskBuffer,
|
|
67580
|
-
opcode: 8,
|
|
67581
|
-
readOnly: false,
|
|
67582
|
-
rsv1: false
|
|
67583
|
-
};
|
|
67584
|
-
if (this._state !== DEFAULT) {
|
|
67585
|
-
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
67586
|
-
} else {
|
|
67587
|
-
this.sendFrame(_Sender.frame(buf, options), cb);
|
|
67588
|
-
}
|
|
67589
|
-
}
|
|
67590
|
-
/**
|
|
67591
|
-
* Sends a ping message to the other peer.
|
|
67592
|
-
*
|
|
67593
|
-
* @param {*} data The message to send
|
|
67594
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
67595
|
-
* @param {Function} [cb] Callback
|
|
67596
|
-
* @public
|
|
67597
|
-
*/
|
|
67598
|
-
ping(data, mask, cb) {
|
|
67599
|
-
let byteLength;
|
|
67600
|
-
let readOnly;
|
|
67601
|
-
if (typeof data === "string") {
|
|
67602
|
-
byteLength = Buffer.byteLength(data);
|
|
67603
|
-
readOnly = false;
|
|
67604
|
-
} else if (isBlob(data)) {
|
|
67605
|
-
byteLength = data.size;
|
|
67606
|
-
readOnly = false;
|
|
67607
|
-
} else {
|
|
67608
|
-
data = toBuffer(data);
|
|
67609
|
-
byteLength = data.length;
|
|
67610
|
-
readOnly = toBuffer.readOnly;
|
|
67611
|
-
}
|
|
67612
|
-
if (byteLength > 125) {
|
|
67613
|
-
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
67614
|
-
}
|
|
67615
|
-
const options = {
|
|
67616
|
-
[kByteLength]: byteLength,
|
|
67617
|
-
fin: true,
|
|
67618
|
-
generateMask: this._generateMask,
|
|
67619
|
-
mask,
|
|
67620
|
-
maskBuffer: this._maskBuffer,
|
|
67621
|
-
opcode: 9,
|
|
67622
|
-
readOnly,
|
|
67623
|
-
rsv1: false
|
|
67624
|
-
};
|
|
67625
|
-
if (isBlob(data)) {
|
|
67626
|
-
if (this._state !== DEFAULT) {
|
|
67627
|
-
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
67628
|
-
} else {
|
|
67629
|
-
this.getBlobData(data, false, options, cb);
|
|
67630
|
-
}
|
|
67631
|
-
} else if (this._state !== DEFAULT) {
|
|
67632
|
-
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
67633
|
-
} else {
|
|
67634
|
-
this.sendFrame(_Sender.frame(data, options), cb);
|
|
67635
|
-
}
|
|
67636
|
-
}
|
|
67637
|
-
/**
|
|
67638
|
-
* Sends a pong message to the other peer.
|
|
67639
|
-
*
|
|
67640
|
-
* @param {*} data The message to send
|
|
67641
|
-
* @param {Boolean} [mask=false] Specifies whether or not to mask `data`
|
|
67642
|
-
* @param {Function} [cb] Callback
|
|
67643
|
-
* @public
|
|
67644
|
-
*/
|
|
67645
|
-
pong(data, mask, cb) {
|
|
67646
|
-
let byteLength;
|
|
67647
|
-
let readOnly;
|
|
67648
|
-
if (typeof data === "string") {
|
|
67649
|
-
byteLength = Buffer.byteLength(data);
|
|
67650
|
-
readOnly = false;
|
|
67651
|
-
} else if (isBlob(data)) {
|
|
67652
|
-
byteLength = data.size;
|
|
67653
|
-
readOnly = false;
|
|
67654
|
-
} else {
|
|
67655
|
-
data = toBuffer(data);
|
|
67656
|
-
byteLength = data.length;
|
|
67657
|
-
readOnly = toBuffer.readOnly;
|
|
67658
|
-
}
|
|
67659
|
-
if (byteLength > 125) {
|
|
67660
|
-
throw new RangeError("The data size must not be greater than 125 bytes");
|
|
67661
|
-
}
|
|
67662
|
-
const options = {
|
|
67663
|
-
[kByteLength]: byteLength,
|
|
67664
|
-
fin: true,
|
|
67665
|
-
generateMask: this._generateMask,
|
|
67666
|
-
mask,
|
|
67667
|
-
maskBuffer: this._maskBuffer,
|
|
67668
|
-
opcode: 10,
|
|
67669
|
-
readOnly,
|
|
67670
|
-
rsv1: false
|
|
67671
|
-
};
|
|
67672
|
-
if (isBlob(data)) {
|
|
67673
|
-
if (this._state !== DEFAULT) {
|
|
67674
|
-
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
67675
|
-
} else {
|
|
67676
|
-
this.getBlobData(data, false, options, cb);
|
|
67677
|
-
}
|
|
67678
|
-
} else if (this._state !== DEFAULT) {
|
|
67679
|
-
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
67680
|
-
} else {
|
|
67681
|
-
this.sendFrame(_Sender.frame(data, options), cb);
|
|
67682
|
-
}
|
|
67683
|
-
}
|
|
67684
|
-
/**
|
|
67685
|
-
* Sends a data message to the other peer.
|
|
67686
|
-
*
|
|
67687
|
-
* @param {*} data The message to send
|
|
67688
|
-
* @param {Object} options Options object
|
|
67689
|
-
* @param {Boolean} [options.binary=false] Specifies whether `data` is binary
|
|
67690
|
-
* or text
|
|
67691
|
-
* @param {Boolean} [options.compress=false] Specifies whether or not to
|
|
67692
|
-
* compress `data`
|
|
67693
|
-
* @param {Boolean} [options.fin=false] Specifies whether the fragment is the
|
|
67694
|
-
* last one
|
|
67695
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
67696
|
-
* `data`
|
|
67697
|
-
* @param {Function} [cb] Callback
|
|
67698
|
-
* @public
|
|
67699
|
-
*/
|
|
67700
|
-
send(data, options, cb) {
|
|
67701
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate3.extensionName];
|
|
67702
|
-
let opcode = options.binary ? 2 : 1;
|
|
67703
|
-
let rsv1 = options.compress;
|
|
67704
|
-
let byteLength;
|
|
67705
|
-
let readOnly;
|
|
67706
|
-
if (typeof data === "string") {
|
|
67707
|
-
byteLength = Buffer.byteLength(data);
|
|
67708
|
-
readOnly = false;
|
|
67709
|
-
} else if (isBlob(data)) {
|
|
67710
|
-
byteLength = data.size;
|
|
67711
|
-
readOnly = false;
|
|
67712
|
-
} else {
|
|
67713
|
-
data = toBuffer(data);
|
|
67714
|
-
byteLength = data.length;
|
|
67715
|
-
readOnly = toBuffer.readOnly;
|
|
67716
|
-
}
|
|
67717
|
-
if (this._firstFragment) {
|
|
67718
|
-
this._firstFragment = false;
|
|
67719
|
-
if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
|
|
67720
|
-
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
67721
|
-
}
|
|
67722
|
-
this._compress = rsv1;
|
|
67723
|
-
} else {
|
|
67724
|
-
rsv1 = false;
|
|
67725
|
-
opcode = 0;
|
|
67726
|
-
}
|
|
67727
|
-
if (options.fin) this._firstFragment = true;
|
|
67728
|
-
const opts = {
|
|
67729
|
-
[kByteLength]: byteLength,
|
|
67730
|
-
fin: options.fin,
|
|
67731
|
-
generateMask: this._generateMask,
|
|
67732
|
-
mask: options.mask,
|
|
67733
|
-
maskBuffer: this._maskBuffer,
|
|
67734
|
-
opcode,
|
|
67735
|
-
readOnly,
|
|
67736
|
-
rsv1
|
|
67737
|
-
};
|
|
67738
|
-
if (isBlob(data)) {
|
|
67739
|
-
if (this._state !== DEFAULT) {
|
|
67740
|
-
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
67741
|
-
} else {
|
|
67742
|
-
this.getBlobData(data, this._compress, opts, cb);
|
|
67743
|
-
}
|
|
67744
|
-
} else if (this._state !== DEFAULT) {
|
|
67745
|
-
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
67746
|
-
} else {
|
|
67747
|
-
this.dispatch(data, this._compress, opts, cb);
|
|
67748
|
-
}
|
|
67749
|
-
}
|
|
67750
|
-
/**
|
|
67751
|
-
* Gets the contents of a blob as binary data.
|
|
67752
|
-
*
|
|
67753
|
-
* @param {Blob} blob The blob
|
|
67754
|
-
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
67755
|
-
* the data
|
|
67756
|
-
* @param {Object} options Options object
|
|
67757
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
67758
|
-
* FIN bit
|
|
67759
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
67760
|
-
* masking key
|
|
67761
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
67762
|
-
* `data`
|
|
67763
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
67764
|
-
* key
|
|
67765
|
-
* @param {Number} options.opcode The opcode
|
|
67766
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
67767
|
-
* modified
|
|
67768
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
67769
|
-
* RSV1 bit
|
|
67770
|
-
* @param {Function} [cb] Callback
|
|
67771
|
-
* @private
|
|
67772
|
-
*/
|
|
67773
|
-
getBlobData(blob, compress, options, cb) {
|
|
67774
|
-
this._bufferedBytes += options[kByteLength];
|
|
67775
|
-
this._state = GET_BLOB_DATA;
|
|
67776
|
-
blob.arrayBuffer().then((arrayBuffer) => {
|
|
67777
|
-
if (this._socket.destroyed) {
|
|
67778
|
-
const err = new Error(
|
|
67779
|
-
"The socket was closed while the blob was being read"
|
|
67780
|
-
);
|
|
67781
|
-
process.nextTick(callCallbacks, this, err, cb);
|
|
67782
|
-
return;
|
|
67783
|
-
}
|
|
67784
|
-
this._bufferedBytes -= options[kByteLength];
|
|
67785
|
-
const data = toBuffer(arrayBuffer);
|
|
67786
|
-
if (!compress) {
|
|
67787
|
-
this._state = DEFAULT;
|
|
67788
|
-
this.sendFrame(_Sender.frame(data, options), cb);
|
|
67789
|
-
this.dequeue();
|
|
67790
|
-
} else {
|
|
67791
|
-
this.dispatch(data, compress, options, cb);
|
|
67792
|
-
}
|
|
67793
|
-
}).catch((err) => {
|
|
67794
|
-
process.nextTick(onError2, this, err, cb);
|
|
67795
|
-
});
|
|
67796
|
-
}
|
|
67797
|
-
/**
|
|
67798
|
-
* Dispatches a message.
|
|
67799
|
-
*
|
|
67800
|
-
* @param {(Buffer|String)} data The message to send
|
|
67801
|
-
* @param {Boolean} [compress=false] Specifies whether or not to compress
|
|
67802
|
-
* `data`
|
|
67803
|
-
* @param {Object} options Options object
|
|
67804
|
-
* @param {Boolean} [options.fin=false] Specifies whether or not to set the
|
|
67805
|
-
* FIN bit
|
|
67806
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
67807
|
-
* masking key
|
|
67808
|
-
* @param {Boolean} [options.mask=false] Specifies whether or not to mask
|
|
67809
|
-
* `data`
|
|
67810
|
-
* @param {Buffer} [options.maskBuffer] The buffer used to store the masking
|
|
67811
|
-
* key
|
|
67812
|
-
* @param {Number} options.opcode The opcode
|
|
67813
|
-
* @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
|
|
67814
|
-
* modified
|
|
67815
|
-
* @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
|
|
67816
|
-
* RSV1 bit
|
|
67817
|
-
* @param {Function} [cb] Callback
|
|
67818
|
-
* @private
|
|
67819
|
-
*/
|
|
67820
|
-
dispatch(data, compress, options, cb) {
|
|
67821
|
-
if (!compress) {
|
|
67822
|
-
this.sendFrame(_Sender.frame(data, options), cb);
|
|
67823
|
-
return;
|
|
67824
|
-
}
|
|
67825
|
-
const perMessageDeflate = this._extensions[PerMessageDeflate3.extensionName];
|
|
67826
|
-
this._bufferedBytes += options[kByteLength];
|
|
67827
|
-
this._state = DEFLATING;
|
|
67828
|
-
perMessageDeflate.compress(data, options.fin, (_2, buf) => {
|
|
67829
|
-
if (this._socket.destroyed) {
|
|
67830
|
-
const err = new Error(
|
|
67831
|
-
"The socket was closed while data was being compressed"
|
|
67832
|
-
);
|
|
67833
|
-
callCallbacks(this, err, cb);
|
|
67834
|
-
return;
|
|
67835
|
-
}
|
|
67836
|
-
this._bufferedBytes -= options[kByteLength];
|
|
67837
|
-
this._state = DEFAULT;
|
|
67838
|
-
options.readOnly = false;
|
|
67839
|
-
this.sendFrame(_Sender.frame(buf, options), cb);
|
|
67840
|
-
this.dequeue();
|
|
67841
|
-
});
|
|
67842
|
-
}
|
|
67843
|
-
/**
|
|
67844
|
-
* Executes queued send operations.
|
|
67845
|
-
*
|
|
67846
|
-
* @private
|
|
67847
|
-
*/
|
|
67848
|
-
dequeue() {
|
|
67849
|
-
while (this._state === DEFAULT && this._queue.length) {
|
|
67850
|
-
const params = this._queue.shift();
|
|
67851
|
-
this._bufferedBytes -= params[3][kByteLength];
|
|
67852
|
-
Reflect.apply(params[0], this, params.slice(1));
|
|
67853
|
-
}
|
|
67854
|
-
}
|
|
67855
|
-
/**
|
|
67856
|
-
* Enqueues a send operation.
|
|
67857
|
-
*
|
|
67858
|
-
* @param {Array} params Send operation parameters.
|
|
67859
|
-
* @private
|
|
67860
|
-
*/
|
|
67861
|
-
enqueue(params) {
|
|
67862
|
-
this._bufferedBytes += params[3][kByteLength];
|
|
67863
|
-
this._queue.push(params);
|
|
67864
|
-
}
|
|
67865
|
-
/**
|
|
67866
|
-
* Sends a frame.
|
|
67867
|
-
*
|
|
67868
|
-
* @param {(Buffer | String)[]} list The frame to send
|
|
67869
|
-
* @param {Function} [cb] Callback
|
|
67870
|
-
* @private
|
|
67871
|
-
*/
|
|
67872
|
-
sendFrame(list, cb) {
|
|
67873
|
-
if (list.length === 2) {
|
|
67874
|
-
this._socket.cork();
|
|
67875
|
-
this._socket.write(list[0]);
|
|
67876
|
-
this._socket.write(list[1], cb);
|
|
67877
|
-
this._socket.uncork();
|
|
67878
|
-
} else {
|
|
67879
|
-
this._socket.write(list[0], cb);
|
|
67880
|
-
}
|
|
67881
|
-
}
|
|
67882
|
-
};
|
|
67883
|
-
module.exports = Sender3;
|
|
67884
|
-
function callCallbacks(sender, err, cb) {
|
|
67885
|
-
if (typeof cb === "function") cb(err);
|
|
67886
|
-
for (let i2 = 0; i2 < sender._queue.length; i2++) {
|
|
67887
|
-
const params = sender._queue[i2];
|
|
67888
|
-
const callback = params[params.length - 1];
|
|
67889
|
-
if (typeof callback === "function") callback(err);
|
|
67890
|
-
}
|
|
67891
|
-
}
|
|
67892
|
-
function onError2(sender, err, cb) {
|
|
67893
|
-
callCallbacks(sender, err, cb);
|
|
67894
|
-
sender.onerror(err);
|
|
67895
|
-
}
|
|
67896
|
-
}
|
|
67897
|
-
});
|
|
67898
|
-
|
|
67899
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/event-target.js
|
|
67900
|
-
var require_event_target2 = __commonJS({
|
|
67901
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/event-target.js"(exports, module) {
|
|
67902
|
-
var { kForOnEventAttribute, kListener } = require_constants3();
|
|
67903
|
-
var kCode = /* @__PURE__ */ Symbol("kCode");
|
|
67904
|
-
var kData = /* @__PURE__ */ Symbol("kData");
|
|
67905
|
-
var kError = /* @__PURE__ */ Symbol("kError");
|
|
67906
|
-
var kMessage = /* @__PURE__ */ Symbol("kMessage");
|
|
67907
|
-
var kReason = /* @__PURE__ */ Symbol("kReason");
|
|
67908
|
-
var kTarget = /* @__PURE__ */ Symbol("kTarget");
|
|
67909
|
-
var kType = /* @__PURE__ */ Symbol("kType");
|
|
67910
|
-
var kWasClean = /* @__PURE__ */ Symbol("kWasClean");
|
|
67911
|
-
var Event = class {
|
|
67912
|
-
/**
|
|
67913
|
-
* Create a new `Event`.
|
|
67914
|
-
*
|
|
67915
|
-
* @param {String} type The name of the event
|
|
67916
|
-
* @throws {TypeError} If the `type` argument is not specified
|
|
67917
|
-
*/
|
|
67918
|
-
constructor(type) {
|
|
67919
|
-
this[kTarget] = null;
|
|
67920
|
-
this[kType] = type;
|
|
67921
|
-
}
|
|
67922
|
-
/**
|
|
67923
|
-
* @type {*}
|
|
67924
|
-
*/
|
|
67925
|
-
get target() {
|
|
67926
|
-
return this[kTarget];
|
|
67927
|
-
}
|
|
67928
|
-
/**
|
|
67929
|
-
* @type {String}
|
|
67930
|
-
*/
|
|
67931
|
-
get type() {
|
|
67932
|
-
return this[kType];
|
|
67933
|
-
}
|
|
67934
|
-
};
|
|
67935
|
-
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
67936
|
-
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
67937
|
-
var CloseEvent = class extends Event {
|
|
67938
|
-
/**
|
|
67939
|
-
* Create a new `CloseEvent`.
|
|
67940
|
-
*
|
|
67941
|
-
* @param {String} type The name of the event
|
|
67942
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
67943
|
-
* attributes via object members of the same name
|
|
67944
|
-
* @param {Number} [options.code=0] The status code explaining why the
|
|
67945
|
-
* connection was closed
|
|
67946
|
-
* @param {String} [options.reason=''] A human-readable string explaining why
|
|
67947
|
-
* the connection was closed
|
|
67948
|
-
* @param {Boolean} [options.wasClean=false] Indicates whether or not the
|
|
67949
|
-
* connection was cleanly closed
|
|
67950
|
-
*/
|
|
67951
|
-
constructor(type, options = {}) {
|
|
67952
|
-
super(type);
|
|
67953
|
-
this[kCode] = options.code === void 0 ? 0 : options.code;
|
|
67954
|
-
this[kReason] = options.reason === void 0 ? "" : options.reason;
|
|
67955
|
-
this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
|
|
67956
|
-
}
|
|
67957
|
-
/**
|
|
67958
|
-
* @type {Number}
|
|
67959
|
-
*/
|
|
67960
|
-
get code() {
|
|
67961
|
-
return this[kCode];
|
|
67962
|
-
}
|
|
67963
|
-
/**
|
|
67964
|
-
* @type {String}
|
|
67965
|
-
*/
|
|
67966
|
-
get reason() {
|
|
67967
|
-
return this[kReason];
|
|
67968
|
-
}
|
|
67969
|
-
/**
|
|
67970
|
-
* @type {Boolean}
|
|
67971
|
-
*/
|
|
67972
|
-
get wasClean() {
|
|
67973
|
-
return this[kWasClean];
|
|
67974
|
-
}
|
|
67975
|
-
};
|
|
67976
|
-
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
67977
|
-
Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
|
|
67978
|
-
Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
|
|
67979
|
-
var ErrorEvent = class extends Event {
|
|
67980
|
-
/**
|
|
67981
|
-
* Create a new `ErrorEvent`.
|
|
67982
|
-
*
|
|
67983
|
-
* @param {String} type The name of the event
|
|
67984
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
67985
|
-
* attributes via object members of the same name
|
|
67986
|
-
* @param {*} [options.error=null] The error that generated this event
|
|
67987
|
-
* @param {String} [options.message=''] The error message
|
|
67988
|
-
*/
|
|
67989
|
-
constructor(type, options = {}) {
|
|
67990
|
-
super(type);
|
|
67991
|
-
this[kError] = options.error === void 0 ? null : options.error;
|
|
67992
|
-
this[kMessage] = options.message === void 0 ? "" : options.message;
|
|
67993
|
-
}
|
|
67994
|
-
/**
|
|
67995
|
-
* @type {*}
|
|
67996
|
-
*/
|
|
67997
|
-
get error() {
|
|
67998
|
-
return this[kError];
|
|
67999
|
-
}
|
|
68000
|
-
/**
|
|
68001
|
-
* @type {String}
|
|
68002
|
-
*/
|
|
68003
|
-
get message() {
|
|
68004
|
-
return this[kMessage];
|
|
68005
|
-
}
|
|
68006
|
-
};
|
|
68007
|
-
Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
|
|
68008
|
-
Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
|
|
68009
|
-
var MessageEvent = class extends Event {
|
|
68010
|
-
/**
|
|
68011
|
-
* Create a new `MessageEvent`.
|
|
68012
|
-
*
|
|
68013
|
-
* @param {String} type The name of the event
|
|
68014
|
-
* @param {Object} [options] A dictionary object that allows for setting
|
|
68015
|
-
* attributes via object members of the same name
|
|
68016
|
-
* @param {*} [options.data=null] The message content
|
|
68017
|
-
*/
|
|
68018
|
-
constructor(type, options = {}) {
|
|
68019
|
-
super(type);
|
|
68020
|
-
this[kData] = options.data === void 0 ? null : options.data;
|
|
68021
|
-
}
|
|
68022
|
-
/**
|
|
68023
|
-
* @type {*}
|
|
68024
|
-
*/
|
|
68025
|
-
get data() {
|
|
68026
|
-
return this[kData];
|
|
68027
|
-
}
|
|
68028
|
-
};
|
|
68029
|
-
Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
|
|
68030
|
-
var EventTarget = {
|
|
68031
|
-
/**
|
|
68032
|
-
* Register an event listener.
|
|
68033
|
-
*
|
|
68034
|
-
* @param {String} type A string representing the event type to listen for
|
|
68035
|
-
* @param {(Function|Object)} handler The listener to add
|
|
68036
|
-
* @param {Object} [options] An options object specifies characteristics about
|
|
68037
|
-
* the event listener
|
|
68038
|
-
* @param {Boolean} [options.once=false] A `Boolean` indicating that the
|
|
68039
|
-
* listener should be invoked at most once after being added. If `true`,
|
|
68040
|
-
* the listener would be automatically removed when invoked.
|
|
68041
|
-
* @public
|
|
68042
|
-
*/
|
|
68043
|
-
addEventListener(type, handler, options = {}) {
|
|
68044
|
-
for (const listener of this.listeners(type)) {
|
|
68045
|
-
if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
68046
|
-
return;
|
|
68047
|
-
}
|
|
68048
|
-
}
|
|
68049
|
-
let wrapper;
|
|
68050
|
-
if (type === "message") {
|
|
68051
|
-
wrapper = function onMessage(data, isBinary) {
|
|
68052
|
-
const event = new MessageEvent("message", {
|
|
68053
|
-
data: isBinary ? data : data.toString()
|
|
68054
|
-
});
|
|
68055
|
-
event[kTarget] = this;
|
|
68056
|
-
callListener(handler, this, event);
|
|
68057
|
-
};
|
|
68058
|
-
} else if (type === "close") {
|
|
68059
|
-
wrapper = function onClose(code, message) {
|
|
68060
|
-
const event = new CloseEvent("close", {
|
|
68061
|
-
code,
|
|
68062
|
-
reason: message.toString(),
|
|
68063
|
-
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
68064
|
-
});
|
|
68065
|
-
event[kTarget] = this;
|
|
68066
|
-
callListener(handler, this, event);
|
|
68067
|
-
};
|
|
68068
|
-
} else if (type === "error") {
|
|
68069
|
-
wrapper = function onError2(error) {
|
|
68070
|
-
const event = new ErrorEvent("error", {
|
|
68071
|
-
error,
|
|
68072
|
-
message: error.message
|
|
68073
|
-
});
|
|
68074
|
-
event[kTarget] = this;
|
|
68075
|
-
callListener(handler, this, event);
|
|
68076
|
-
};
|
|
68077
|
-
} else if (type === "open") {
|
|
68078
|
-
wrapper = function onOpen() {
|
|
68079
|
-
const event = new Event("open");
|
|
68080
|
-
event[kTarget] = this;
|
|
68081
|
-
callListener(handler, this, event);
|
|
68082
|
-
};
|
|
68083
|
-
} else {
|
|
68084
|
-
return;
|
|
68085
|
-
}
|
|
68086
|
-
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
68087
|
-
wrapper[kListener] = handler;
|
|
68088
|
-
if (options.once) {
|
|
68089
|
-
this.once(type, wrapper);
|
|
68090
|
-
} else {
|
|
68091
|
-
this.on(type, wrapper);
|
|
68092
|
-
}
|
|
68093
|
-
},
|
|
68094
|
-
/**
|
|
68095
|
-
* Remove an event listener.
|
|
68096
|
-
*
|
|
68097
|
-
* @param {String} type A string representing the event type to remove
|
|
68098
|
-
* @param {(Function|Object)} handler The listener to remove
|
|
68099
|
-
* @public
|
|
68100
|
-
*/
|
|
68101
|
-
removeEventListener(type, handler) {
|
|
68102
|
-
for (const listener of this.listeners(type)) {
|
|
68103
|
-
if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
68104
|
-
this.removeListener(type, listener);
|
|
68105
|
-
break;
|
|
68106
|
-
}
|
|
68107
|
-
}
|
|
68108
|
-
}
|
|
68109
|
-
};
|
|
68110
|
-
module.exports = {
|
|
68111
|
-
CloseEvent,
|
|
68112
|
-
ErrorEvent,
|
|
68113
|
-
Event,
|
|
68114
|
-
EventTarget,
|
|
68115
|
-
MessageEvent
|
|
68116
|
-
};
|
|
68117
|
-
function callListener(listener, thisArg, event) {
|
|
68118
|
-
if (typeof listener === "object" && listener.handleEvent) {
|
|
68119
|
-
listener.handleEvent.call(listener, event);
|
|
68120
|
-
} else {
|
|
68121
|
-
listener.call(thisArg, event);
|
|
68122
|
-
}
|
|
68123
|
-
}
|
|
68124
|
-
}
|
|
68125
|
-
});
|
|
68126
|
-
|
|
68127
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/extension.js
|
|
68128
|
-
var require_extension2 = __commonJS({
|
|
68129
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/extension.js"(exports, module) {
|
|
68130
|
-
var { tokenChars } = require_validation2();
|
|
68131
|
-
function push(dest, name, elem) {
|
|
68132
|
-
if (dest[name] === void 0) dest[name] = [elem];
|
|
68133
|
-
else dest[name].push(elem);
|
|
68134
|
-
}
|
|
68135
|
-
function parse(header) {
|
|
68136
|
-
const offers = /* @__PURE__ */ Object.create(null);
|
|
68137
|
-
let params = /* @__PURE__ */ Object.create(null);
|
|
68138
|
-
let mustUnescape = false;
|
|
68139
|
-
let isEscaping = false;
|
|
68140
|
-
let inQuotes = false;
|
|
68141
|
-
let extensionName;
|
|
68142
|
-
let paramName;
|
|
68143
|
-
let start = -1;
|
|
68144
|
-
let code = -1;
|
|
68145
|
-
let end = -1;
|
|
68146
|
-
let i2 = 0;
|
|
68147
|
-
for (; i2 < header.length; i2++) {
|
|
68148
|
-
code = header.charCodeAt(i2);
|
|
68149
|
-
if (extensionName === void 0) {
|
|
68150
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
68151
|
-
if (start === -1) start = i2;
|
|
68152
|
-
} else if (i2 !== 0 && (code === 32 || code === 9)) {
|
|
68153
|
-
if (end === -1 && start !== -1) end = i2;
|
|
68154
|
-
} else if (code === 59 || code === 44) {
|
|
68155
|
-
if (start === -1) {
|
|
68156
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68157
|
-
}
|
|
68158
|
-
if (end === -1) end = i2;
|
|
68159
|
-
const name = header.slice(start, end);
|
|
68160
|
-
if (code === 44) {
|
|
68161
|
-
push(offers, name, params);
|
|
68162
|
-
params = /* @__PURE__ */ Object.create(null);
|
|
68163
|
-
} else {
|
|
68164
|
-
extensionName = name;
|
|
68165
|
-
}
|
|
68166
|
-
start = end = -1;
|
|
68167
|
-
} else {
|
|
68168
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68169
|
-
}
|
|
68170
|
-
} else if (paramName === void 0) {
|
|
68171
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
68172
|
-
if (start === -1) start = i2;
|
|
68173
|
-
} else if (code === 32 || code === 9) {
|
|
68174
|
-
if (end === -1 && start !== -1) end = i2;
|
|
68175
|
-
} else if (code === 59 || code === 44) {
|
|
68176
|
-
if (start === -1) {
|
|
68177
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68178
|
-
}
|
|
68179
|
-
if (end === -1) end = i2;
|
|
68180
|
-
push(params, header.slice(start, end), true);
|
|
68181
|
-
if (code === 44) {
|
|
68182
|
-
push(offers, extensionName, params);
|
|
68183
|
-
params = /* @__PURE__ */ Object.create(null);
|
|
68184
|
-
extensionName = void 0;
|
|
68185
|
-
}
|
|
68186
|
-
start = end = -1;
|
|
68187
|
-
} else if (code === 61 && start !== -1 && end === -1) {
|
|
68188
|
-
paramName = header.slice(start, i2);
|
|
68189
|
-
start = end = -1;
|
|
68190
|
-
} else {
|
|
68191
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68192
|
-
}
|
|
68193
|
-
} else {
|
|
68194
|
-
if (isEscaping) {
|
|
68195
|
-
if (tokenChars[code] !== 1) {
|
|
68196
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68197
|
-
}
|
|
68198
|
-
if (start === -1) start = i2;
|
|
68199
|
-
else if (!mustUnescape) mustUnescape = true;
|
|
68200
|
-
isEscaping = false;
|
|
68201
|
-
} else if (inQuotes) {
|
|
68202
|
-
if (tokenChars[code] === 1) {
|
|
68203
|
-
if (start === -1) start = i2;
|
|
68204
|
-
} else if (code === 34 && start !== -1) {
|
|
68205
|
-
inQuotes = false;
|
|
68206
|
-
end = i2;
|
|
68207
|
-
} else if (code === 92) {
|
|
68208
|
-
isEscaping = true;
|
|
68209
|
-
} else {
|
|
68210
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68211
|
-
}
|
|
68212
|
-
} else if (code === 34 && header.charCodeAt(i2 - 1) === 61) {
|
|
68213
|
-
inQuotes = true;
|
|
68214
|
-
} else if (end === -1 && tokenChars[code] === 1) {
|
|
68215
|
-
if (start === -1) start = i2;
|
|
68216
|
-
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
68217
|
-
if (end === -1) end = i2;
|
|
68218
|
-
} else if (code === 59 || code === 44) {
|
|
68219
|
-
if (start === -1) {
|
|
68220
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68221
|
-
}
|
|
68222
|
-
if (end === -1) end = i2;
|
|
68223
|
-
let value2 = header.slice(start, end);
|
|
68224
|
-
if (mustUnescape) {
|
|
68225
|
-
value2 = value2.replace(/\\/g, "");
|
|
68226
|
-
mustUnescape = false;
|
|
68227
|
-
}
|
|
68228
|
-
push(params, paramName, value2);
|
|
68229
|
-
if (code === 44) {
|
|
68230
|
-
push(offers, extensionName, params);
|
|
68231
|
-
params = /* @__PURE__ */ Object.create(null);
|
|
68232
|
-
extensionName = void 0;
|
|
68233
|
-
}
|
|
68234
|
-
paramName = void 0;
|
|
68235
|
-
start = end = -1;
|
|
68236
|
-
} else {
|
|
68237
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
68238
|
-
}
|
|
68239
|
-
}
|
|
68240
|
-
}
|
|
68241
|
-
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
68242
|
-
throw new SyntaxError("Unexpected end of input");
|
|
68243
|
-
}
|
|
68244
|
-
if (end === -1) end = i2;
|
|
68245
|
-
const token = header.slice(start, end);
|
|
68246
|
-
if (extensionName === void 0) {
|
|
68247
|
-
push(offers, token, params);
|
|
68248
|
-
} else {
|
|
68249
|
-
if (paramName === void 0) {
|
|
68250
|
-
push(params, token, true);
|
|
68251
|
-
} else if (mustUnescape) {
|
|
68252
|
-
push(params, paramName, token.replace(/\\/g, ""));
|
|
68253
|
-
} else {
|
|
68254
|
-
push(params, paramName, token);
|
|
68255
|
-
}
|
|
68256
|
-
push(offers, extensionName, params);
|
|
68257
|
-
}
|
|
68258
|
-
return offers;
|
|
68259
|
-
}
|
|
68260
|
-
function format(extensions) {
|
|
68261
|
-
return Object.keys(extensions).map((extension3) => {
|
|
68262
|
-
let configurations = extensions[extension3];
|
|
68263
|
-
if (!Array.isArray(configurations)) configurations = [configurations];
|
|
68264
|
-
return configurations.map((params) => {
|
|
68265
|
-
return [extension3].concat(
|
|
68266
|
-
Object.keys(params).map((k) => {
|
|
68267
|
-
let values = params[k];
|
|
68268
|
-
if (!Array.isArray(values)) values = [values];
|
|
68269
|
-
return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
|
|
68270
|
-
})
|
|
68271
|
-
).join("; ");
|
|
68272
|
-
}).join(", ");
|
|
68273
|
-
}).join(", ");
|
|
68274
|
-
}
|
|
68275
|
-
module.exports = { format, parse };
|
|
68276
|
-
}
|
|
68277
|
-
});
|
|
68278
|
-
|
|
68279
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/websocket.js
|
|
68280
|
-
var require_websocket2 = __commonJS({
|
|
68281
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/websocket.js"(exports, module) {
|
|
68282
|
-
var EventEmitter3 = __require("events");
|
|
68283
|
-
var https = __require("https");
|
|
68284
|
-
var http = __require("http");
|
|
68285
|
-
var net3 = __require("net");
|
|
68286
|
-
var tls = __require("tls");
|
|
68287
|
-
var { randomBytes: randomBytes8, createHash: createHash11 } = __require("crypto");
|
|
68288
|
-
var { Duplex, Readable } = __require("stream");
|
|
68289
|
-
var { URL: URL2 } = __require("url");
|
|
68290
|
-
var PerMessageDeflate3 = require_permessage_deflate2();
|
|
68291
|
-
var Receiver3 = require_receiver2();
|
|
68292
|
-
var Sender3 = require_sender2();
|
|
68293
|
-
var { isBlob } = require_validation2();
|
|
68294
|
-
var {
|
|
68295
|
-
BINARY_TYPES,
|
|
68296
|
-
CLOSE_TIMEOUT,
|
|
68297
|
-
EMPTY_BUFFER,
|
|
68298
|
-
GUID,
|
|
68299
|
-
kForOnEventAttribute,
|
|
68300
|
-
kListener,
|
|
68301
|
-
kStatusCode,
|
|
68302
|
-
kWebSocket,
|
|
68303
|
-
NOOP
|
|
68304
|
-
} = require_constants3();
|
|
68305
|
-
var {
|
|
68306
|
-
EventTarget: { addEventListener, removeEventListener }
|
|
68307
|
-
} = require_event_target2();
|
|
68308
|
-
var { format, parse } = require_extension2();
|
|
68309
|
-
var { toBuffer } = require_buffer_util2();
|
|
68310
|
-
var kAborted = /* @__PURE__ */ Symbol("kAborted");
|
|
68311
|
-
var protocolVersions = [8, 13];
|
|
68312
|
-
var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
68313
|
-
var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
68314
|
-
var WebSocket3 = class _WebSocket extends EventEmitter3 {
|
|
68315
|
-
/**
|
|
68316
|
-
* Create a new `WebSocket`.
|
|
68317
|
-
*
|
|
68318
|
-
* @param {(String|URL)} address The URL to which to connect
|
|
68319
|
-
* @param {(String|String[])} [protocols] The subprotocols
|
|
68320
|
-
* @param {Object} [options] Connection options
|
|
68321
|
-
*/
|
|
68322
|
-
constructor(address, protocols, options) {
|
|
68323
|
-
super();
|
|
68324
|
-
this._binaryType = BINARY_TYPES[0];
|
|
68325
|
-
this._closeCode = 1006;
|
|
68326
|
-
this._closeFrameReceived = false;
|
|
68327
|
-
this._closeFrameSent = false;
|
|
68328
|
-
this._closeMessage = EMPTY_BUFFER;
|
|
68329
|
-
this._closeTimer = null;
|
|
68330
|
-
this._errorEmitted = false;
|
|
68331
|
-
this._extensions = {};
|
|
68332
|
-
this._paused = false;
|
|
68333
|
-
this._protocol = "";
|
|
68334
|
-
this._readyState = _WebSocket.CONNECTING;
|
|
68335
|
-
this._receiver = null;
|
|
68336
|
-
this._sender = null;
|
|
68337
|
-
this._socket = null;
|
|
68338
|
-
if (address !== null) {
|
|
68339
|
-
this._bufferedAmount = 0;
|
|
68340
|
-
this._isServer = false;
|
|
68341
|
-
this._redirects = 0;
|
|
68342
|
-
if (protocols === void 0) {
|
|
68343
|
-
protocols = [];
|
|
68344
|
-
} else if (!Array.isArray(protocols)) {
|
|
68345
|
-
if (typeof protocols === "object" && protocols !== null) {
|
|
68346
|
-
options = protocols;
|
|
68347
|
-
protocols = [];
|
|
68348
|
-
} else {
|
|
68349
|
-
protocols = [protocols];
|
|
68350
|
-
}
|
|
68351
|
-
}
|
|
68352
|
-
initAsClient(this, address, protocols, options);
|
|
68353
|
-
} else {
|
|
68354
|
-
this._autoPong = options.autoPong;
|
|
68355
|
-
this._closeTimeout = options.closeTimeout;
|
|
68356
|
-
this._isServer = true;
|
|
68357
|
-
}
|
|
68358
|
-
}
|
|
68359
|
-
/**
|
|
68360
|
-
* For historical reasons, the custom "nodebuffer" type is used by the default
|
|
68361
|
-
* instead of "blob".
|
|
68362
|
-
*
|
|
68363
|
-
* @type {String}
|
|
68364
|
-
*/
|
|
68365
|
-
get binaryType() {
|
|
68366
|
-
return this._binaryType;
|
|
68367
|
-
}
|
|
68368
|
-
set binaryType(type) {
|
|
68369
|
-
if (!BINARY_TYPES.includes(type)) return;
|
|
68370
|
-
this._binaryType = type;
|
|
68371
|
-
if (this._receiver) this._receiver._binaryType = type;
|
|
68372
|
-
}
|
|
68373
|
-
/**
|
|
68374
|
-
* @type {Number}
|
|
68375
|
-
*/
|
|
68376
|
-
get bufferedAmount() {
|
|
68377
|
-
if (!this._socket) return this._bufferedAmount;
|
|
68378
|
-
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
68379
|
-
}
|
|
68380
|
-
/**
|
|
68381
|
-
* @type {String}
|
|
68382
|
-
*/
|
|
68383
|
-
get extensions() {
|
|
68384
|
-
return Object.keys(this._extensions).join();
|
|
68385
|
-
}
|
|
68386
|
-
/**
|
|
68387
|
-
* @type {Boolean}
|
|
68388
|
-
*/
|
|
68389
|
-
get isPaused() {
|
|
68390
|
-
return this._paused;
|
|
68391
|
-
}
|
|
68392
|
-
/**
|
|
68393
|
-
* @type {Function}
|
|
68394
|
-
*/
|
|
68395
|
-
/* istanbul ignore next */
|
|
68396
|
-
get onclose() {
|
|
68397
|
-
return null;
|
|
68398
|
-
}
|
|
68399
|
-
/**
|
|
68400
|
-
* @type {Function}
|
|
68401
|
-
*/
|
|
68402
|
-
/* istanbul ignore next */
|
|
68403
|
-
get onerror() {
|
|
68404
|
-
return null;
|
|
68405
|
-
}
|
|
68406
|
-
/**
|
|
68407
|
-
* @type {Function}
|
|
68408
|
-
*/
|
|
68409
|
-
/* istanbul ignore next */
|
|
68410
|
-
get onopen() {
|
|
68411
|
-
return null;
|
|
68412
|
-
}
|
|
68413
|
-
/**
|
|
68414
|
-
* @type {Function}
|
|
68415
|
-
*/
|
|
68416
|
-
/* istanbul ignore next */
|
|
68417
|
-
get onmessage() {
|
|
68418
|
-
return null;
|
|
68419
|
-
}
|
|
68420
|
-
/**
|
|
68421
|
-
* @type {String}
|
|
68422
|
-
*/
|
|
68423
|
-
get protocol() {
|
|
68424
|
-
return this._protocol;
|
|
68425
|
-
}
|
|
68426
|
-
/**
|
|
68427
|
-
* @type {Number}
|
|
68428
|
-
*/
|
|
68429
|
-
get readyState() {
|
|
68430
|
-
return this._readyState;
|
|
68431
|
-
}
|
|
68432
|
-
/**
|
|
68433
|
-
* @type {String}
|
|
68434
|
-
*/
|
|
68435
|
-
get url() {
|
|
68436
|
-
return this._url;
|
|
68437
|
-
}
|
|
68438
|
-
/**
|
|
68439
|
-
* Set up the socket and the internal resources.
|
|
68440
|
-
*
|
|
68441
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
68442
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
68443
|
-
* @param {Object} options Options object
|
|
68444
|
-
* @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
|
|
68445
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
68446
|
-
* multiple times in the same tick
|
|
68447
|
-
* @param {Function} [options.generateMask] The function used to generate the
|
|
68448
|
-
* masking key
|
|
68449
|
-
* @param {Number} [options.maxBufferedChunks=0] The maximum number of
|
|
68450
|
-
* buffered data chunks
|
|
68451
|
-
* @param {Number} [options.maxFragments=0] The maximum number of message
|
|
68452
|
-
* fragments
|
|
68453
|
-
* @param {Number} [options.maxPayload=0] The maximum allowed message size
|
|
68454
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
68455
|
-
* not to skip UTF-8 validation for text and close messages
|
|
68456
|
-
* @private
|
|
68457
|
-
*/
|
|
68458
|
-
setSocket(socket, head2, options) {
|
|
68459
|
-
const receiver = new Receiver3({
|
|
68460
|
-
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
68461
|
-
binaryType: this.binaryType,
|
|
68462
|
-
extensions: this._extensions,
|
|
68463
|
-
isServer: this._isServer,
|
|
68464
|
-
maxBufferedChunks: options.maxBufferedChunks,
|
|
68465
|
-
maxFragments: options.maxFragments,
|
|
68466
|
-
maxPayload: options.maxPayload,
|
|
68467
|
-
skipUTF8Validation: options.skipUTF8Validation
|
|
68468
|
-
});
|
|
68469
|
-
const sender = new Sender3(socket, this._extensions, options.generateMask);
|
|
68470
|
-
this._receiver = receiver;
|
|
68471
|
-
this._sender = sender;
|
|
68472
|
-
this._socket = socket;
|
|
68473
|
-
receiver[kWebSocket] = this;
|
|
68474
|
-
sender[kWebSocket] = this;
|
|
68475
|
-
socket[kWebSocket] = this;
|
|
68476
|
-
receiver.on("conclude", receiverOnConclude);
|
|
68477
|
-
receiver.on("drain", receiverOnDrain);
|
|
68478
|
-
receiver.on("error", receiverOnError);
|
|
68479
|
-
receiver.on("message", receiverOnMessage);
|
|
68480
|
-
receiver.on("ping", receiverOnPing);
|
|
68481
|
-
receiver.on("pong", receiverOnPong);
|
|
68482
|
-
sender.onerror = senderOnError;
|
|
68483
|
-
if (socket.setTimeout) socket.setTimeout(0);
|
|
68484
|
-
if (socket.setNoDelay) socket.setNoDelay();
|
|
68485
|
-
if (head2.length > 0) socket.unshift(head2);
|
|
68486
|
-
socket.on("close", socketOnClose);
|
|
68487
|
-
socket.on("data", socketOnData);
|
|
68488
|
-
socket.on("end", socketOnEnd);
|
|
68489
|
-
socket.on("error", socketOnError);
|
|
68490
|
-
this._readyState = _WebSocket.OPEN;
|
|
68491
|
-
this.emit("open");
|
|
68492
|
-
}
|
|
68493
|
-
/**
|
|
68494
|
-
* Emit the `'close'` event.
|
|
68495
|
-
*
|
|
68496
|
-
* @private
|
|
68497
|
-
*/
|
|
68498
|
-
emitClose() {
|
|
68499
|
-
if (!this._socket) {
|
|
68500
|
-
this._readyState = _WebSocket.CLOSED;
|
|
68501
|
-
this.emit("close", this._closeCode, this._closeMessage);
|
|
68502
|
-
return;
|
|
68503
|
-
}
|
|
68504
|
-
if (this._extensions[PerMessageDeflate3.extensionName]) {
|
|
68505
|
-
this._extensions[PerMessageDeflate3.extensionName].cleanup();
|
|
68506
|
-
}
|
|
68507
|
-
this._receiver.removeAllListeners();
|
|
68508
|
-
this._readyState = _WebSocket.CLOSED;
|
|
68509
|
-
this.emit("close", this._closeCode, this._closeMessage);
|
|
68510
|
-
}
|
|
68511
|
-
/**
|
|
68512
|
-
* Start a closing handshake.
|
|
68513
|
-
*
|
|
68514
|
-
* +----------+ +-----------+ +----------+
|
|
68515
|
-
* - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
|
|
68516
|
-
* | +----------+ +-----------+ +----------+ |
|
|
68517
|
-
* +----------+ +-----------+ |
|
|
68518
|
-
* CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
|
|
68519
|
-
* +----------+ +-----------+ |
|
|
68520
|
-
* | | | +---+ |
|
|
68521
|
-
* +------------------------+-->|fin| - - - -
|
|
68522
|
-
* | +---+ | +---+
|
|
68523
|
-
* - - - - -|fin|<---------------------+
|
|
68524
|
-
* +---+
|
|
68525
|
-
*
|
|
68526
|
-
* @param {Number} [code] Status code explaining why the connection is closing
|
|
68527
|
-
* @param {(String|Buffer)} [data] The reason why the connection is
|
|
68528
|
-
* closing
|
|
68529
|
-
* @public
|
|
68530
|
-
*/
|
|
68531
|
-
close(code, data) {
|
|
68532
|
-
if (this.readyState === _WebSocket.CLOSED) return;
|
|
68533
|
-
if (this.readyState === _WebSocket.CONNECTING) {
|
|
68534
|
-
const msg = "WebSocket was closed before the connection was established";
|
|
68535
|
-
abortHandshake(this, this._req, msg);
|
|
68536
|
-
return;
|
|
68537
|
-
}
|
|
68538
|
-
if (this.readyState === _WebSocket.CLOSING) {
|
|
68539
|
-
if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
|
|
68540
|
-
this._socket.end();
|
|
68541
|
-
}
|
|
68542
|
-
return;
|
|
68543
|
-
}
|
|
68544
|
-
this._readyState = _WebSocket.CLOSING;
|
|
68545
|
-
this._sender.close(code, data, !this._isServer, (err) => {
|
|
68546
|
-
if (err) return;
|
|
68547
|
-
this._closeFrameSent = true;
|
|
68548
|
-
if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
|
|
68549
|
-
this._socket.end();
|
|
68550
|
-
}
|
|
68551
|
-
});
|
|
68552
|
-
setCloseTimer(this);
|
|
68553
|
-
}
|
|
68554
|
-
/**
|
|
68555
|
-
* Pause the socket.
|
|
68556
|
-
*
|
|
68557
|
-
* @public
|
|
68558
|
-
*/
|
|
68559
|
-
pause() {
|
|
68560
|
-
if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
|
|
68561
|
-
return;
|
|
68562
|
-
}
|
|
68563
|
-
this._paused = true;
|
|
68564
|
-
this._socket.pause();
|
|
68565
|
-
}
|
|
68566
|
-
/**
|
|
68567
|
-
* Send a ping.
|
|
68568
|
-
*
|
|
68569
|
-
* @param {*} [data] The data to send
|
|
68570
|
-
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
68571
|
-
* @param {Function} [cb] Callback which is executed when the ping is sent
|
|
68572
|
-
* @public
|
|
68573
|
-
*/
|
|
68574
|
-
ping(data, mask, cb) {
|
|
68575
|
-
if (this.readyState === _WebSocket.CONNECTING) {
|
|
68576
|
-
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
68577
|
-
}
|
|
68578
|
-
if (typeof data === "function") {
|
|
68579
|
-
cb = data;
|
|
68580
|
-
data = mask = void 0;
|
|
68581
|
-
} else if (typeof mask === "function") {
|
|
68582
|
-
cb = mask;
|
|
68583
|
-
mask = void 0;
|
|
68584
|
-
}
|
|
68585
|
-
if (typeof data === "number") data = data.toString();
|
|
68586
|
-
if (this.readyState !== _WebSocket.OPEN) {
|
|
68587
|
-
sendAfterClose(this, data, cb);
|
|
68588
|
-
return;
|
|
68589
|
-
}
|
|
68590
|
-
if (mask === void 0) mask = !this._isServer;
|
|
68591
|
-
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
68592
|
-
}
|
|
68593
|
-
/**
|
|
68594
|
-
* Send a pong.
|
|
68595
|
-
*
|
|
68596
|
-
* @param {*} [data] The data to send
|
|
68597
|
-
* @param {Boolean} [mask] Indicates whether or not to mask `data`
|
|
68598
|
-
* @param {Function} [cb] Callback which is executed when the pong is sent
|
|
68599
|
-
* @public
|
|
68600
|
-
*/
|
|
68601
|
-
pong(data, mask, cb) {
|
|
68602
|
-
if (this.readyState === _WebSocket.CONNECTING) {
|
|
68603
|
-
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
68604
|
-
}
|
|
68605
|
-
if (typeof data === "function") {
|
|
68606
|
-
cb = data;
|
|
68607
|
-
data = mask = void 0;
|
|
68608
|
-
} else if (typeof mask === "function") {
|
|
68609
|
-
cb = mask;
|
|
68610
|
-
mask = void 0;
|
|
68611
|
-
}
|
|
68612
|
-
if (typeof data === "number") data = data.toString();
|
|
68613
|
-
if (this.readyState !== _WebSocket.OPEN) {
|
|
68614
|
-
sendAfterClose(this, data, cb);
|
|
68615
|
-
return;
|
|
68616
|
-
}
|
|
68617
|
-
if (mask === void 0) mask = !this._isServer;
|
|
68618
|
-
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
68619
|
-
}
|
|
68620
|
-
/**
|
|
68621
|
-
* Resume the socket.
|
|
68622
|
-
*
|
|
68623
|
-
* @public
|
|
68624
|
-
*/
|
|
68625
|
-
resume() {
|
|
68626
|
-
if (this.readyState === _WebSocket.CONNECTING || this.readyState === _WebSocket.CLOSED) {
|
|
68627
|
-
return;
|
|
68628
|
-
}
|
|
68629
|
-
this._paused = false;
|
|
68630
|
-
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
68631
|
-
}
|
|
68632
|
-
/**
|
|
68633
|
-
* Send a data message.
|
|
68634
|
-
*
|
|
68635
|
-
* @param {*} data The message to send
|
|
68636
|
-
* @param {Object} [options] Options object
|
|
68637
|
-
* @param {Boolean} [options.binary] Specifies whether `data` is binary or
|
|
68638
|
-
* text
|
|
68639
|
-
* @param {Boolean} [options.compress] Specifies whether or not to compress
|
|
68640
|
-
* `data`
|
|
68641
|
-
* @param {Boolean} [options.fin=true] Specifies whether the fragment is the
|
|
68642
|
-
* last one
|
|
68643
|
-
* @param {Boolean} [options.mask] Specifies whether or not to mask `data`
|
|
68644
|
-
* @param {Function} [cb] Callback which is executed when data is written out
|
|
68645
|
-
* @public
|
|
68646
|
-
*/
|
|
68647
|
-
send(data, options, cb) {
|
|
68648
|
-
if (this.readyState === _WebSocket.CONNECTING) {
|
|
68649
|
-
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
68650
|
-
}
|
|
68651
|
-
if (typeof options === "function") {
|
|
68652
|
-
cb = options;
|
|
68653
|
-
options = {};
|
|
68654
|
-
}
|
|
68655
|
-
if (typeof data === "number") data = data.toString();
|
|
68656
|
-
if (this.readyState !== _WebSocket.OPEN) {
|
|
68657
|
-
sendAfterClose(this, data, cb);
|
|
68658
|
-
return;
|
|
68659
|
-
}
|
|
68660
|
-
const opts = {
|
|
68661
|
-
binary: typeof data !== "string",
|
|
68662
|
-
mask: !this._isServer,
|
|
68663
|
-
compress: true,
|
|
68664
|
-
fin: true,
|
|
68665
|
-
...options
|
|
68666
|
-
};
|
|
68667
|
-
if (!this._extensions[PerMessageDeflate3.extensionName]) {
|
|
68668
|
-
opts.compress = false;
|
|
68669
|
-
}
|
|
68670
|
-
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
68671
|
-
}
|
|
68672
|
-
/**
|
|
68673
|
-
* Forcibly close the connection.
|
|
68674
|
-
*
|
|
68675
|
-
* @public
|
|
68676
|
-
*/
|
|
68677
|
-
terminate() {
|
|
68678
|
-
if (this.readyState === _WebSocket.CLOSED) return;
|
|
68679
|
-
if (this.readyState === _WebSocket.CONNECTING) {
|
|
68680
|
-
const msg = "WebSocket was closed before the connection was established";
|
|
68681
|
-
abortHandshake(this, this._req, msg);
|
|
68682
|
-
return;
|
|
68683
|
-
}
|
|
68684
|
-
if (this._socket) {
|
|
68685
|
-
this._readyState = _WebSocket.CLOSING;
|
|
68686
|
-
this._socket.destroy();
|
|
68687
|
-
}
|
|
68688
|
-
}
|
|
68689
|
-
};
|
|
68690
|
-
Object.defineProperty(WebSocket3, "CONNECTING", {
|
|
68691
|
-
enumerable: true,
|
|
68692
|
-
value: readyStates.indexOf("CONNECTING")
|
|
68693
|
-
});
|
|
68694
|
-
Object.defineProperty(WebSocket3.prototype, "CONNECTING", {
|
|
68695
|
-
enumerable: true,
|
|
68696
|
-
value: readyStates.indexOf("CONNECTING")
|
|
68697
|
-
});
|
|
68698
|
-
Object.defineProperty(WebSocket3, "OPEN", {
|
|
68699
|
-
enumerable: true,
|
|
68700
|
-
value: readyStates.indexOf("OPEN")
|
|
68701
|
-
});
|
|
68702
|
-
Object.defineProperty(WebSocket3.prototype, "OPEN", {
|
|
68703
|
-
enumerable: true,
|
|
68704
|
-
value: readyStates.indexOf("OPEN")
|
|
68705
|
-
});
|
|
68706
|
-
Object.defineProperty(WebSocket3, "CLOSING", {
|
|
68707
|
-
enumerable: true,
|
|
68708
|
-
value: readyStates.indexOf("CLOSING")
|
|
68709
|
-
});
|
|
68710
|
-
Object.defineProperty(WebSocket3.prototype, "CLOSING", {
|
|
68711
|
-
enumerable: true,
|
|
68712
|
-
value: readyStates.indexOf("CLOSING")
|
|
68713
|
-
});
|
|
68714
|
-
Object.defineProperty(WebSocket3, "CLOSED", {
|
|
68715
|
-
enumerable: true,
|
|
68716
|
-
value: readyStates.indexOf("CLOSED")
|
|
68717
|
-
});
|
|
68718
|
-
Object.defineProperty(WebSocket3.prototype, "CLOSED", {
|
|
68719
|
-
enumerable: true,
|
|
68720
|
-
value: readyStates.indexOf("CLOSED")
|
|
68721
|
-
});
|
|
68722
|
-
[
|
|
68723
|
-
"binaryType",
|
|
68724
|
-
"bufferedAmount",
|
|
68725
|
-
"extensions",
|
|
68726
|
-
"isPaused",
|
|
68727
|
-
"protocol",
|
|
68728
|
-
"readyState",
|
|
68729
|
-
"url"
|
|
68730
|
-
].forEach((property) => {
|
|
68731
|
-
Object.defineProperty(WebSocket3.prototype, property, { enumerable: true });
|
|
68732
|
-
});
|
|
68733
|
-
["open", "error", "close", "message"].forEach((method) => {
|
|
68734
|
-
Object.defineProperty(WebSocket3.prototype, `on${method}`, {
|
|
68735
|
-
enumerable: true,
|
|
68736
|
-
get() {
|
|
68737
|
-
for (const listener of this.listeners(method)) {
|
|
68738
|
-
if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
68739
|
-
}
|
|
68740
|
-
return null;
|
|
68741
|
-
},
|
|
68742
|
-
set(handler) {
|
|
68743
|
-
for (const listener of this.listeners(method)) {
|
|
68744
|
-
if (listener[kForOnEventAttribute]) {
|
|
68745
|
-
this.removeListener(method, listener);
|
|
68746
|
-
break;
|
|
68747
|
-
}
|
|
68748
|
-
}
|
|
68749
|
-
if (typeof handler !== "function") return;
|
|
68750
|
-
this.addEventListener(method, handler, {
|
|
68751
|
-
[kForOnEventAttribute]: true
|
|
68752
|
-
});
|
|
68753
|
-
}
|
|
68754
|
-
});
|
|
68755
|
-
});
|
|
68756
|
-
WebSocket3.prototype.addEventListener = addEventListener;
|
|
68757
|
-
WebSocket3.prototype.removeEventListener = removeEventListener;
|
|
68758
|
-
module.exports = WebSocket3;
|
|
68759
|
-
function initAsClient(websocket, address, protocols, options) {
|
|
68760
|
-
const opts = {
|
|
68761
|
-
allowSynchronousEvents: true,
|
|
68762
|
-
autoPong: true,
|
|
68763
|
-
closeTimeout: CLOSE_TIMEOUT,
|
|
68764
|
-
protocolVersion: protocolVersions[1],
|
|
68765
|
-
maxBufferedChunks: 1024 * 1024,
|
|
68766
|
-
maxFragments: 128 * 1024,
|
|
68767
|
-
maxPayload: 100 * 1024 * 1024,
|
|
68768
|
-
skipUTF8Validation: false,
|
|
68769
|
-
perMessageDeflate: true,
|
|
68770
|
-
followRedirects: false,
|
|
68771
|
-
maxRedirects: 10,
|
|
68772
|
-
...options,
|
|
68773
|
-
socketPath: void 0,
|
|
68774
|
-
hostname: void 0,
|
|
68775
|
-
protocol: void 0,
|
|
68776
|
-
timeout: void 0,
|
|
68777
|
-
method: "GET",
|
|
68778
|
-
host: void 0,
|
|
68779
|
-
path: void 0,
|
|
68780
|
-
port: void 0
|
|
68781
|
-
};
|
|
68782
|
-
websocket._autoPong = opts.autoPong;
|
|
68783
|
-
websocket._closeTimeout = opts.closeTimeout;
|
|
68784
|
-
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
68785
|
-
throw new RangeError(
|
|
68786
|
-
`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
|
|
68787
|
-
);
|
|
68788
|
-
}
|
|
68789
|
-
let parsedUrl;
|
|
68790
|
-
if (address instanceof URL2) {
|
|
68791
|
-
parsedUrl = address;
|
|
68792
|
-
} else {
|
|
68793
|
-
try {
|
|
68794
|
-
parsedUrl = new URL2(address);
|
|
68795
|
-
} catch {
|
|
68796
|
-
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
68797
|
-
}
|
|
68798
|
-
}
|
|
68799
|
-
if (parsedUrl.protocol === "http:") {
|
|
68800
|
-
parsedUrl.protocol = "ws:";
|
|
68801
|
-
} else if (parsedUrl.protocol === "https:") {
|
|
68802
|
-
parsedUrl.protocol = "wss:";
|
|
68803
|
-
}
|
|
68804
|
-
websocket._url = parsedUrl.href;
|
|
68805
|
-
const isSecure = parsedUrl.protocol === "wss:";
|
|
68806
|
-
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
68807
|
-
let invalidUrlMessage;
|
|
68808
|
-
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
68809
|
-
invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
|
|
68810
|
-
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
68811
|
-
invalidUrlMessage = "The URL's pathname is empty";
|
|
68812
|
-
} else if (parsedUrl.hash) {
|
|
68813
|
-
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
68814
|
-
}
|
|
68815
|
-
if (invalidUrlMessage) {
|
|
68816
|
-
const err = new SyntaxError(invalidUrlMessage);
|
|
68817
|
-
if (websocket._redirects === 0) {
|
|
68818
|
-
throw err;
|
|
68819
|
-
} else {
|
|
68820
|
-
emitErrorAndClose(websocket, err);
|
|
68821
|
-
return;
|
|
68822
|
-
}
|
|
68823
|
-
}
|
|
68824
|
-
const defaultPort = isSecure ? 443 : 80;
|
|
68825
|
-
const key = randomBytes8(16).toString("base64");
|
|
68826
|
-
const request = isSecure ? https.request : http.request;
|
|
68827
|
-
const protocolSet = /* @__PURE__ */ new Set();
|
|
68828
|
-
let perMessageDeflate;
|
|
68829
|
-
opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect2);
|
|
68830
|
-
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
68831
|
-
opts.port = parsedUrl.port || defaultPort;
|
|
68832
|
-
opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
|
|
68833
|
-
opts.headers = {
|
|
68834
|
-
...opts.headers,
|
|
68835
|
-
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
68836
|
-
"Sec-WebSocket-Key": key,
|
|
68837
|
-
Connection: "Upgrade",
|
|
68838
|
-
Upgrade: "websocket"
|
|
68839
|
-
};
|
|
68840
|
-
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
68841
|
-
opts.timeout = opts.handshakeTimeout;
|
|
68842
|
-
if (opts.perMessageDeflate) {
|
|
68843
|
-
perMessageDeflate = new PerMessageDeflate3({
|
|
68844
|
-
...opts.perMessageDeflate,
|
|
68845
|
-
isServer: false,
|
|
68846
|
-
maxPayload: opts.maxPayload
|
|
68847
|
-
});
|
|
68848
|
-
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
68849
|
-
[PerMessageDeflate3.extensionName]: perMessageDeflate.offer()
|
|
68850
|
-
});
|
|
68851
|
-
}
|
|
68852
|
-
if (protocols.length) {
|
|
68853
|
-
for (const protocol of protocols) {
|
|
68854
|
-
if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
|
|
68855
|
-
throw new SyntaxError(
|
|
68856
|
-
"An invalid or duplicated subprotocol was specified"
|
|
68857
|
-
);
|
|
68858
|
-
}
|
|
68859
|
-
protocolSet.add(protocol);
|
|
68860
|
-
}
|
|
68861
|
-
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
68862
|
-
}
|
|
68863
|
-
if (opts.origin) {
|
|
68864
|
-
if (opts.protocolVersion < 13) {
|
|
68865
|
-
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
68866
|
-
} else {
|
|
68867
|
-
opts.headers.Origin = opts.origin;
|
|
68868
|
-
}
|
|
68869
|
-
}
|
|
68870
|
-
if (parsedUrl.username || parsedUrl.password) {
|
|
68871
|
-
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
68872
|
-
}
|
|
68873
|
-
if (isIpcUrl) {
|
|
68874
|
-
const parts = opts.path.split(":");
|
|
68875
|
-
opts.socketPath = parts[0];
|
|
68876
|
-
opts.path = parts[1];
|
|
68877
|
-
}
|
|
68878
|
-
let req;
|
|
68879
|
-
if (opts.followRedirects) {
|
|
68880
|
-
if (websocket._redirects === 0) {
|
|
68881
|
-
websocket._originalIpc = isIpcUrl;
|
|
68882
|
-
websocket._originalSecure = isSecure;
|
|
68883
|
-
websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
68884
|
-
const headers = options && options.headers;
|
|
68885
|
-
options = { ...options, headers: {} };
|
|
68886
|
-
if (headers) {
|
|
68887
|
-
for (const [key2, value2] of Object.entries(headers)) {
|
|
68888
|
-
options.headers[key2.toLowerCase()] = value2;
|
|
68889
|
-
}
|
|
68890
|
-
}
|
|
68891
|
-
} else if (websocket.listenerCount("redirect") === 0) {
|
|
68892
|
-
const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
68893
|
-
if (!isSameHost || websocket._originalSecure && !isSecure) {
|
|
68894
|
-
delete opts.headers.authorization;
|
|
68895
|
-
delete opts.headers.cookie;
|
|
68896
|
-
if (!isSameHost) delete opts.headers.host;
|
|
68897
|
-
opts.auth = void 0;
|
|
68898
|
-
}
|
|
68899
|
-
}
|
|
68900
|
-
if (opts.auth && !options.headers.authorization) {
|
|
68901
|
-
options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
|
|
68902
|
-
}
|
|
68903
|
-
req = websocket._req = request(opts);
|
|
68904
|
-
if (websocket._redirects) {
|
|
68905
|
-
websocket.emit("redirect", websocket.url, req);
|
|
68906
|
-
}
|
|
68907
|
-
} else {
|
|
68908
|
-
req = websocket._req = request(opts);
|
|
68909
|
-
}
|
|
68910
|
-
if (opts.timeout) {
|
|
68911
|
-
req.on("timeout", () => {
|
|
68912
|
-
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
68913
|
-
});
|
|
68914
|
-
}
|
|
68915
|
-
req.on("error", (err) => {
|
|
68916
|
-
if (req === null || req[kAborted]) return;
|
|
68917
|
-
req = websocket._req = null;
|
|
68918
|
-
emitErrorAndClose(websocket, err);
|
|
68919
|
-
});
|
|
68920
|
-
req.on("response", (res) => {
|
|
68921
|
-
const location = res.headers.location;
|
|
68922
|
-
const statusCode = res.statusCode;
|
|
68923
|
-
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
68924
|
-
if (++websocket._redirects > opts.maxRedirects) {
|
|
68925
|
-
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
68926
|
-
return;
|
|
68927
|
-
}
|
|
68928
|
-
req.abort();
|
|
68929
|
-
let addr;
|
|
68930
|
-
try {
|
|
68931
|
-
addr = new URL2(location, address);
|
|
68932
|
-
} catch (e) {
|
|
68933
|
-
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
68934
|
-
emitErrorAndClose(websocket, err);
|
|
68935
|
-
return;
|
|
68936
|
-
}
|
|
68937
|
-
initAsClient(websocket, addr, protocols, options);
|
|
68938
|
-
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
68939
|
-
abortHandshake(
|
|
68940
|
-
websocket,
|
|
68941
|
-
req,
|
|
68942
|
-
`Unexpected server response: ${res.statusCode}`
|
|
68943
|
-
);
|
|
68944
|
-
}
|
|
68945
|
-
});
|
|
68946
|
-
req.on("upgrade", (res, socket, head2) => {
|
|
68947
|
-
websocket.emit("upgrade", res);
|
|
68948
|
-
if (websocket.readyState !== WebSocket3.CONNECTING) return;
|
|
68949
|
-
req = websocket._req = null;
|
|
68950
|
-
const upgrade = res.headers.upgrade;
|
|
68951
|
-
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
68952
|
-
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
68953
|
-
return;
|
|
68954
|
-
}
|
|
68955
|
-
const digest = createHash11("sha1").update(key + GUID).digest("base64");
|
|
68956
|
-
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
68957
|
-
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
68958
|
-
return;
|
|
68959
|
-
}
|
|
68960
|
-
const serverProt = res.headers["sec-websocket-protocol"];
|
|
68961
|
-
let protError;
|
|
68962
|
-
if (serverProt !== void 0) {
|
|
68963
|
-
if (!protocolSet.size) {
|
|
68964
|
-
protError = "Server sent a subprotocol but none was requested";
|
|
68965
|
-
} else if (!protocolSet.has(serverProt)) {
|
|
68966
|
-
protError = "Server sent an invalid subprotocol";
|
|
68967
|
-
}
|
|
68968
|
-
} else if (protocolSet.size) {
|
|
68969
|
-
protError = "Server sent no subprotocol";
|
|
68970
|
-
}
|
|
68971
|
-
if (protError) {
|
|
68972
|
-
abortHandshake(websocket, socket, protError);
|
|
68973
|
-
return;
|
|
68974
|
-
}
|
|
68975
|
-
if (serverProt) websocket._protocol = serverProt;
|
|
68976
|
-
const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
|
|
68977
|
-
if (secWebSocketExtensions !== void 0) {
|
|
68978
|
-
if (!perMessageDeflate) {
|
|
68979
|
-
const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
|
|
68980
|
-
abortHandshake(websocket, socket, message);
|
|
68981
|
-
return;
|
|
68982
|
-
}
|
|
68983
|
-
let extensions;
|
|
68984
|
-
try {
|
|
68985
|
-
extensions = parse(secWebSocketExtensions);
|
|
68986
|
-
} catch (err) {
|
|
68987
|
-
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
68988
|
-
abortHandshake(websocket, socket, message);
|
|
68989
|
-
return;
|
|
68990
|
-
}
|
|
68991
|
-
const extensionNames = Object.keys(extensions);
|
|
68992
|
-
if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate3.extensionName) {
|
|
68993
|
-
const message = "Server indicated an extension that was not requested";
|
|
68994
|
-
abortHandshake(websocket, socket, message);
|
|
68995
|
-
return;
|
|
68996
|
-
}
|
|
68997
|
-
try {
|
|
68998
|
-
perMessageDeflate.accept(extensions[PerMessageDeflate3.extensionName]);
|
|
68999
|
-
} catch (err) {
|
|
69000
|
-
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
69001
|
-
abortHandshake(websocket, socket, message);
|
|
69002
|
-
return;
|
|
69003
|
-
}
|
|
69004
|
-
websocket._extensions[PerMessageDeflate3.extensionName] = perMessageDeflate;
|
|
69005
|
-
}
|
|
69006
|
-
websocket.setSocket(socket, head2, {
|
|
69007
|
-
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
69008
|
-
generateMask: opts.generateMask,
|
|
69009
|
-
maxBufferedChunks: opts.maxBufferedChunks,
|
|
69010
|
-
maxFragments: opts.maxFragments,
|
|
69011
|
-
maxPayload: opts.maxPayload,
|
|
69012
|
-
skipUTF8Validation: opts.skipUTF8Validation
|
|
69013
|
-
});
|
|
69014
|
-
});
|
|
69015
|
-
if (opts.finishRequest) {
|
|
69016
|
-
opts.finishRequest(req, websocket);
|
|
69017
|
-
} else {
|
|
69018
|
-
req.end();
|
|
69019
|
-
}
|
|
69020
|
-
}
|
|
69021
|
-
function emitErrorAndClose(websocket, err) {
|
|
69022
|
-
websocket._readyState = WebSocket3.CLOSING;
|
|
69023
|
-
websocket._errorEmitted = true;
|
|
69024
|
-
websocket.emit("error", err);
|
|
69025
|
-
websocket.emitClose();
|
|
69026
|
-
}
|
|
69027
|
-
function netConnect2(options) {
|
|
69028
|
-
options.path = options.socketPath;
|
|
69029
|
-
return net3.connect(options);
|
|
69030
|
-
}
|
|
69031
|
-
function tlsConnect(options) {
|
|
69032
|
-
options.path = void 0;
|
|
69033
|
-
if (!options.servername && options.servername !== "") {
|
|
69034
|
-
options.servername = net3.isIP(options.host) ? "" : options.host;
|
|
69035
|
-
}
|
|
69036
|
-
return tls.connect(options);
|
|
69037
|
-
}
|
|
69038
|
-
function abortHandshake(websocket, stream2, message) {
|
|
69039
|
-
websocket._readyState = WebSocket3.CLOSING;
|
|
69040
|
-
const err = new Error(message);
|
|
69041
|
-
Error.captureStackTrace(err, abortHandshake);
|
|
69042
|
-
if (stream2.setHeader) {
|
|
69043
|
-
stream2[kAborted] = true;
|
|
69044
|
-
stream2.abort();
|
|
69045
|
-
if (stream2.socket && !stream2.socket.destroyed) {
|
|
69046
|
-
stream2.socket.destroy();
|
|
69047
|
-
}
|
|
69048
|
-
process.nextTick(emitErrorAndClose, websocket, err);
|
|
69049
|
-
} else {
|
|
69050
|
-
stream2.destroy(err);
|
|
69051
|
-
stream2.once("error", websocket.emit.bind(websocket, "error"));
|
|
69052
|
-
stream2.once("close", websocket.emitClose.bind(websocket));
|
|
69053
|
-
}
|
|
69054
|
-
}
|
|
69055
|
-
function sendAfterClose(websocket, data, cb) {
|
|
69056
|
-
if (data) {
|
|
69057
|
-
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
69058
|
-
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
69059
|
-
else websocket._bufferedAmount += length;
|
|
69060
|
-
}
|
|
69061
|
-
if (cb) {
|
|
69062
|
-
const err = new Error(
|
|
69063
|
-
`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
|
|
69064
|
-
);
|
|
69065
|
-
process.nextTick(cb, err);
|
|
69066
|
-
}
|
|
69067
|
-
}
|
|
69068
|
-
function receiverOnConclude(code, reason) {
|
|
69069
|
-
const websocket = this[kWebSocket];
|
|
69070
|
-
websocket._closeFrameReceived = true;
|
|
69071
|
-
websocket._closeMessage = reason;
|
|
69072
|
-
websocket._closeCode = code;
|
|
69073
|
-
if (websocket._socket[kWebSocket] === void 0) return;
|
|
69074
|
-
websocket._socket.removeListener("data", socketOnData);
|
|
69075
|
-
process.nextTick(resume, websocket._socket);
|
|
69076
|
-
if (code === 1005) websocket.close();
|
|
69077
|
-
else websocket.close(code, reason);
|
|
69078
|
-
}
|
|
69079
|
-
function receiverOnDrain() {
|
|
69080
|
-
const websocket = this[kWebSocket];
|
|
69081
|
-
if (!websocket.isPaused) websocket._socket.resume();
|
|
69082
|
-
}
|
|
69083
|
-
function receiverOnError(err) {
|
|
69084
|
-
const websocket = this[kWebSocket];
|
|
69085
|
-
if (websocket._socket[kWebSocket] !== void 0) {
|
|
69086
|
-
websocket._socket.removeListener("data", socketOnData);
|
|
69087
|
-
process.nextTick(resume, websocket._socket);
|
|
69088
|
-
websocket.close(err[kStatusCode]);
|
|
69089
|
-
}
|
|
69090
|
-
if (!websocket._errorEmitted) {
|
|
69091
|
-
websocket._errorEmitted = true;
|
|
69092
|
-
websocket.emit("error", err);
|
|
69093
|
-
}
|
|
69094
|
-
}
|
|
69095
|
-
function receiverOnFinish() {
|
|
69096
|
-
this[kWebSocket].emitClose();
|
|
69097
|
-
}
|
|
69098
|
-
function receiverOnMessage(data, isBinary) {
|
|
69099
|
-
this[kWebSocket].emit("message", data, isBinary);
|
|
69100
|
-
}
|
|
69101
|
-
function receiverOnPing(data) {
|
|
69102
|
-
const websocket = this[kWebSocket];
|
|
69103
|
-
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
|
69104
|
-
websocket.emit("ping", data);
|
|
69105
|
-
}
|
|
69106
|
-
function receiverOnPong(data) {
|
|
69107
|
-
this[kWebSocket].emit("pong", data);
|
|
69108
|
-
}
|
|
69109
|
-
function resume(stream2) {
|
|
69110
|
-
stream2.resume();
|
|
69111
|
-
}
|
|
69112
|
-
function senderOnError(err) {
|
|
69113
|
-
const websocket = this[kWebSocket];
|
|
69114
|
-
if (websocket.readyState === WebSocket3.CLOSED) return;
|
|
69115
|
-
if (websocket.readyState === WebSocket3.OPEN) {
|
|
69116
|
-
websocket._readyState = WebSocket3.CLOSING;
|
|
69117
|
-
setCloseTimer(websocket);
|
|
69118
|
-
}
|
|
69119
|
-
this._socket.end();
|
|
69120
|
-
if (!websocket._errorEmitted) {
|
|
69121
|
-
websocket._errorEmitted = true;
|
|
69122
|
-
websocket.emit("error", err);
|
|
69123
|
-
}
|
|
69124
|
-
}
|
|
69125
|
-
function setCloseTimer(websocket) {
|
|
69126
|
-
websocket._closeTimer = setTimeout(
|
|
69127
|
-
websocket._socket.destroy.bind(websocket._socket),
|
|
69128
|
-
websocket._closeTimeout
|
|
69129
|
-
);
|
|
69130
|
-
}
|
|
69131
|
-
function socketOnClose() {
|
|
69132
|
-
const websocket = this[kWebSocket];
|
|
69133
|
-
this.removeListener("close", socketOnClose);
|
|
69134
|
-
this.removeListener("data", socketOnData);
|
|
69135
|
-
this.removeListener("end", socketOnEnd);
|
|
69136
|
-
websocket._readyState = WebSocket3.CLOSING;
|
|
69137
|
-
if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && this._readableState.length !== 0) {
|
|
69138
|
-
const chunk = this.read(this._readableState.length);
|
|
69139
|
-
websocket._receiver.write(chunk);
|
|
69140
|
-
}
|
|
69141
|
-
websocket._receiver.end();
|
|
69142
|
-
this[kWebSocket] = void 0;
|
|
69143
|
-
clearTimeout(websocket._closeTimer);
|
|
69144
|
-
if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
|
|
69145
|
-
websocket.emitClose();
|
|
69146
|
-
} else {
|
|
69147
|
-
websocket._receiver.on("error", receiverOnFinish);
|
|
69148
|
-
websocket._receiver.on("finish", receiverOnFinish);
|
|
69149
|
-
}
|
|
69150
|
-
}
|
|
69151
|
-
function socketOnData(chunk) {
|
|
69152
|
-
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
69153
|
-
this.pause();
|
|
69154
|
-
}
|
|
69155
|
-
}
|
|
69156
|
-
function socketOnEnd() {
|
|
69157
|
-
const websocket = this[kWebSocket];
|
|
69158
|
-
websocket._readyState = WebSocket3.CLOSING;
|
|
69159
|
-
websocket._receiver.end();
|
|
69160
|
-
this.end();
|
|
69161
|
-
}
|
|
69162
|
-
function socketOnError() {
|
|
69163
|
-
const websocket = this[kWebSocket];
|
|
69164
|
-
this.removeListener("error", socketOnError);
|
|
69165
|
-
this.on("error", NOOP);
|
|
69166
|
-
if (websocket) {
|
|
69167
|
-
websocket._readyState = WebSocket3.CLOSING;
|
|
69168
|
-
this.destroy();
|
|
69169
|
-
}
|
|
69170
|
-
}
|
|
69171
|
-
}
|
|
69172
|
-
});
|
|
69173
|
-
|
|
69174
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/stream.js
|
|
69175
|
-
var require_stream2 = __commonJS({
|
|
69176
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/stream.js"(exports, module) {
|
|
69177
|
-
require_websocket2();
|
|
69178
|
-
var { Duplex } = __require("stream");
|
|
69179
|
-
function emitClose(stream2) {
|
|
69180
|
-
stream2.emit("close");
|
|
69181
|
-
}
|
|
69182
|
-
function duplexOnEnd() {
|
|
69183
|
-
if (!this.destroyed && this._writableState.finished) {
|
|
69184
|
-
this.destroy();
|
|
69185
|
-
}
|
|
69186
|
-
}
|
|
69187
|
-
function duplexOnError(err) {
|
|
69188
|
-
this.removeListener("error", duplexOnError);
|
|
69189
|
-
this.destroy();
|
|
69190
|
-
if (this.listenerCount("error") === 0) {
|
|
69191
|
-
this.emit("error", err);
|
|
69192
|
-
}
|
|
69193
|
-
}
|
|
69194
|
-
function createWebSocketStream3(ws, options) {
|
|
69195
|
-
let terminateOnDestroy = true;
|
|
69196
|
-
const duplex = new Duplex({
|
|
69197
|
-
...options,
|
|
69198
|
-
autoDestroy: false,
|
|
69199
|
-
emitClose: false,
|
|
69200
|
-
objectMode: false,
|
|
69201
|
-
writableObjectMode: false
|
|
69202
|
-
});
|
|
69203
|
-
ws.on("message", function message(msg, isBinary) {
|
|
69204
|
-
const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
69205
|
-
if (!duplex.push(data)) ws.pause();
|
|
69206
|
-
});
|
|
69207
|
-
ws.once("error", function error(err) {
|
|
69208
|
-
if (duplex.destroyed) return;
|
|
69209
|
-
terminateOnDestroy = false;
|
|
69210
|
-
duplex.destroy(err);
|
|
69211
|
-
});
|
|
69212
|
-
ws.once("close", function close() {
|
|
69213
|
-
if (duplex.destroyed) return;
|
|
69214
|
-
duplex.push(null);
|
|
69215
|
-
});
|
|
69216
|
-
duplex._destroy = function(err, callback) {
|
|
69217
|
-
if (ws.readyState === ws.CLOSED) {
|
|
69218
|
-
callback(err);
|
|
69219
|
-
process.nextTick(emitClose, duplex);
|
|
69220
|
-
return;
|
|
69221
|
-
}
|
|
69222
|
-
let called = false;
|
|
69223
|
-
ws.once("error", function error(err2) {
|
|
69224
|
-
called = true;
|
|
69225
|
-
callback(err2);
|
|
69226
|
-
});
|
|
69227
|
-
ws.once("close", function close() {
|
|
69228
|
-
if (!called) callback(err);
|
|
69229
|
-
process.nextTick(emitClose, duplex);
|
|
69230
|
-
});
|
|
69231
|
-
if (terminateOnDestroy) ws.terminate();
|
|
69232
|
-
};
|
|
69233
|
-
duplex._final = function(callback) {
|
|
69234
|
-
if (ws.readyState === ws.CONNECTING) {
|
|
69235
|
-
ws.once("open", function open3() {
|
|
69236
|
-
duplex._final(callback);
|
|
69237
|
-
});
|
|
69238
|
-
return;
|
|
69239
|
-
}
|
|
69240
|
-
if (ws._socket === null) return;
|
|
69241
|
-
if (ws._socket._writableState.finished) {
|
|
69242
|
-
callback();
|
|
69243
|
-
if (duplex._readableState.endEmitted) duplex.destroy();
|
|
69244
|
-
} else {
|
|
69245
|
-
ws._socket.once("finish", function finish() {
|
|
69246
|
-
callback();
|
|
69247
|
-
});
|
|
69248
|
-
ws.close();
|
|
69249
|
-
}
|
|
69250
|
-
};
|
|
69251
|
-
duplex._read = function() {
|
|
69252
|
-
if (ws.isPaused) ws.resume();
|
|
69253
|
-
};
|
|
69254
|
-
duplex._write = function(chunk, encoding, callback) {
|
|
69255
|
-
if (ws.readyState === ws.CONNECTING) {
|
|
69256
|
-
ws.once("open", function open3() {
|
|
69257
|
-
duplex._write(chunk, encoding, callback);
|
|
69258
|
-
});
|
|
69259
|
-
return;
|
|
69260
|
-
}
|
|
69261
|
-
ws.send(chunk, callback);
|
|
69262
|
-
};
|
|
69263
|
-
duplex.on("end", duplexOnEnd);
|
|
69264
|
-
duplex.on("error", duplexOnError);
|
|
69265
|
-
return duplex;
|
|
69266
|
-
}
|
|
69267
|
-
module.exports = createWebSocketStream3;
|
|
69268
|
-
}
|
|
69269
|
-
});
|
|
69270
|
-
|
|
69271
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/subprotocol.js
|
|
69272
|
-
var require_subprotocol2 = __commonJS({
|
|
69273
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/subprotocol.js"(exports, module) {
|
|
69274
|
-
var { tokenChars } = require_validation2();
|
|
69275
|
-
function parse(header) {
|
|
69276
|
-
const protocols = /* @__PURE__ */ new Set();
|
|
69277
|
-
let start = -1;
|
|
69278
|
-
let end = -1;
|
|
69279
|
-
let i2 = 0;
|
|
69280
|
-
for (i2; i2 < header.length; i2++) {
|
|
69281
|
-
const code = header.charCodeAt(i2);
|
|
69282
|
-
if (end === -1 && tokenChars[code] === 1) {
|
|
69283
|
-
if (start === -1) start = i2;
|
|
69284
|
-
} else if (i2 !== 0 && (code === 32 || code === 9)) {
|
|
69285
|
-
if (end === -1 && start !== -1) end = i2;
|
|
69286
|
-
} else if (code === 44) {
|
|
69287
|
-
if (start === -1) {
|
|
69288
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
69289
|
-
}
|
|
69290
|
-
if (end === -1) end = i2;
|
|
69291
|
-
const protocol2 = header.slice(start, end);
|
|
69292
|
-
if (protocols.has(protocol2)) {
|
|
69293
|
-
throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
|
|
69294
|
-
}
|
|
69295
|
-
protocols.add(protocol2);
|
|
69296
|
-
start = end = -1;
|
|
69297
|
-
} else {
|
|
69298
|
-
throw new SyntaxError(`Unexpected character at index ${i2}`);
|
|
69299
|
-
}
|
|
69300
|
-
}
|
|
69301
|
-
if (start === -1 || end !== -1) {
|
|
69302
|
-
throw new SyntaxError("Unexpected end of input");
|
|
69303
|
-
}
|
|
69304
|
-
const protocol = header.slice(start, i2);
|
|
69305
|
-
if (protocols.has(protocol)) {
|
|
69306
|
-
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
69307
|
-
}
|
|
69308
|
-
protocols.add(protocol);
|
|
69309
|
-
return protocols;
|
|
69310
|
-
}
|
|
69311
|
-
module.exports = { parse };
|
|
69312
|
-
}
|
|
69313
|
-
});
|
|
69314
|
-
|
|
69315
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/websocket-server.js
|
|
69316
|
-
var require_websocket_server2 = __commonJS({
|
|
69317
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/websocket-server.js"(exports, module) {
|
|
69318
|
-
var EventEmitter3 = __require("events");
|
|
69319
|
-
var http = __require("http");
|
|
69320
|
-
var { Duplex } = __require("stream");
|
|
69321
|
-
var { createHash: createHash11 } = __require("crypto");
|
|
69322
|
-
var extension3 = require_extension2();
|
|
69323
|
-
var PerMessageDeflate3 = require_permessage_deflate2();
|
|
69324
|
-
var subprotocol3 = require_subprotocol2();
|
|
69325
|
-
var WebSocket3 = require_websocket2();
|
|
69326
|
-
var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants3();
|
|
69327
|
-
var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
69328
|
-
var RUNNING = 0;
|
|
69329
|
-
var CLOSING = 1;
|
|
69330
|
-
var CLOSED = 2;
|
|
69331
|
-
var WebSocketServer3 = class extends EventEmitter3 {
|
|
69332
|
-
/**
|
|
69333
|
-
* Create a `WebSocketServer` instance.
|
|
69334
|
-
*
|
|
69335
|
-
* @param {Object} options Configuration options
|
|
69336
|
-
* @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
|
|
69337
|
-
* any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
|
|
69338
|
-
* multiple times in the same tick
|
|
69339
|
-
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
|
|
69340
|
-
* automatically send a pong in response to a ping
|
|
69341
|
-
* @param {Number} [options.backlog=511] The maximum length of the queue of
|
|
69342
|
-
* pending connections
|
|
69343
|
-
* @param {Boolean} [options.clientTracking=true] Specifies whether or not to
|
|
69344
|
-
* track clients
|
|
69345
|
-
* @param {Number} [options.closeTimeout=30000] Duration in milliseconds to
|
|
69346
|
-
* wait for the closing handshake to finish after `websocket.close()` is
|
|
69347
|
-
* called
|
|
69348
|
-
* @param {Function} [options.handleProtocols] A hook to handle protocols
|
|
69349
|
-
* @param {String} [options.host] The hostname where to bind the server
|
|
69350
|
-
* @param {Number} [options.maxBufferedChunks=1048576] The maximum number of
|
|
69351
|
-
* buffered data chunks
|
|
69352
|
-
* @param {Number} [options.maxFragments=131072] The maximum number of message
|
|
69353
|
-
* fragments
|
|
69354
|
-
* @param {Number} [options.maxPayload=104857600] The maximum allowed message
|
|
69355
|
-
* size
|
|
69356
|
-
* @param {Boolean} [options.noServer=false] Enable no server mode
|
|
69357
|
-
* @param {String} [options.path] Accept only connections matching this path
|
|
69358
|
-
* @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
|
|
69359
|
-
* permessage-deflate
|
|
69360
|
-
* @param {Number} [options.port] The port where to bind the server
|
|
69361
|
-
* @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
|
|
69362
|
-
* server to use
|
|
69363
|
-
* @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
|
|
69364
|
-
* not to skip UTF-8 validation for text and close messages
|
|
69365
|
-
* @param {Function} [options.verifyClient] A hook to reject connections
|
|
69366
|
-
* @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
|
|
69367
|
-
* class to use. It must be the `WebSocket` class or class that extends it
|
|
69368
|
-
* @param {Function} [callback] A listener for the `listening` event
|
|
69369
|
-
*/
|
|
69370
|
-
constructor(options, callback) {
|
|
69371
|
-
super();
|
|
69372
|
-
options = {
|
|
69373
|
-
allowSynchronousEvents: true,
|
|
69374
|
-
autoPong: true,
|
|
69375
|
-
maxBufferedChunks: 1024 * 1024,
|
|
69376
|
-
maxFragments: 128 * 1024,
|
|
69377
|
-
maxPayload: 100 * 1024 * 1024,
|
|
69378
|
-
skipUTF8Validation: false,
|
|
69379
|
-
perMessageDeflate: false,
|
|
69380
|
-
handleProtocols: null,
|
|
69381
|
-
clientTracking: true,
|
|
69382
|
-
closeTimeout: CLOSE_TIMEOUT,
|
|
69383
|
-
verifyClient: null,
|
|
69384
|
-
noServer: false,
|
|
69385
|
-
backlog: null,
|
|
69386
|
-
// use default (511 as implemented in net.js)
|
|
69387
|
-
server: null,
|
|
69388
|
-
host: null,
|
|
69389
|
-
path: null,
|
|
69390
|
-
port: null,
|
|
69391
|
-
WebSocket: WebSocket3,
|
|
69392
|
-
...options
|
|
69393
|
-
};
|
|
69394
|
-
if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
|
|
69395
|
-
throw new TypeError(
|
|
69396
|
-
'One and only one of the "port", "server", or "noServer" options must be specified'
|
|
69397
|
-
);
|
|
69398
|
-
}
|
|
69399
|
-
if (options.port != null) {
|
|
69400
|
-
this._server = http.createServer((req, res) => {
|
|
69401
|
-
const body = http.STATUS_CODES[426];
|
|
69402
|
-
res.writeHead(426, {
|
|
69403
|
-
"Content-Length": body.length,
|
|
69404
|
-
"Content-Type": "text/plain"
|
|
69405
|
-
});
|
|
69406
|
-
res.end(body);
|
|
69407
|
-
});
|
|
69408
|
-
this._server.listen(
|
|
69409
|
-
options.port,
|
|
69410
|
-
options.host,
|
|
69411
|
-
options.backlog,
|
|
69412
|
-
callback
|
|
69413
|
-
);
|
|
69414
|
-
} else if (options.server) {
|
|
69415
|
-
this._server = options.server;
|
|
69416
|
-
}
|
|
69417
|
-
if (this._server) {
|
|
69418
|
-
const emitConnection = this.emit.bind(this, "connection");
|
|
69419
|
-
this._removeListeners = addListeners(this._server, {
|
|
69420
|
-
listening: this.emit.bind(this, "listening"),
|
|
69421
|
-
error: this.emit.bind(this, "error"),
|
|
69422
|
-
upgrade: (req, socket, head2) => {
|
|
69423
|
-
this.handleUpgrade(req, socket, head2, emitConnection);
|
|
69424
|
-
}
|
|
69425
|
-
});
|
|
69426
|
-
}
|
|
69427
|
-
if (options.perMessageDeflate === true) options.perMessageDeflate = {};
|
|
69428
|
-
if (options.clientTracking) {
|
|
69429
|
-
this.clients = /* @__PURE__ */ new Set();
|
|
69430
|
-
this._shouldEmitClose = false;
|
|
69431
|
-
}
|
|
69432
|
-
this.options = options;
|
|
69433
|
-
this._state = RUNNING;
|
|
69434
|
-
}
|
|
69435
|
-
/**
|
|
69436
|
-
* Returns the bound address, the address family name, and port of the server
|
|
69437
|
-
* as reported by the operating system if listening on an IP socket.
|
|
69438
|
-
* If the server is listening on a pipe or UNIX domain socket, the name is
|
|
69439
|
-
* returned as a string.
|
|
69440
|
-
*
|
|
69441
|
-
* @return {(Object|String|null)} The address of the server
|
|
69442
|
-
* @public
|
|
69443
|
-
*/
|
|
69444
|
-
address() {
|
|
69445
|
-
if (this.options.noServer) {
|
|
69446
|
-
throw new Error('The server is operating in "noServer" mode');
|
|
69447
|
-
}
|
|
69448
|
-
if (!this._server) return null;
|
|
69449
|
-
return this._server.address();
|
|
69450
|
-
}
|
|
69451
|
-
/**
|
|
69452
|
-
* Stop the server from accepting new connections and emit the `'close'` event
|
|
69453
|
-
* when all existing connections are closed.
|
|
69454
|
-
*
|
|
69455
|
-
* @param {Function} [cb] A one-time listener for the `'close'` event
|
|
69456
|
-
* @public
|
|
69457
|
-
*/
|
|
69458
|
-
close(cb) {
|
|
69459
|
-
if (this._state === CLOSED) {
|
|
69460
|
-
if (cb) {
|
|
69461
|
-
this.once("close", () => {
|
|
69462
|
-
cb(new Error("The server is not running"));
|
|
69463
|
-
});
|
|
69464
|
-
}
|
|
69465
|
-
process.nextTick(emitClose, this);
|
|
69466
|
-
return;
|
|
69467
|
-
}
|
|
69468
|
-
if (cb) this.once("close", cb);
|
|
69469
|
-
if (this._state === CLOSING) return;
|
|
69470
|
-
this._state = CLOSING;
|
|
69471
|
-
if (this.options.noServer || this.options.server) {
|
|
69472
|
-
if (this._server) {
|
|
69473
|
-
this._removeListeners();
|
|
69474
|
-
this._removeListeners = this._server = null;
|
|
69475
|
-
}
|
|
69476
|
-
if (this.clients) {
|
|
69477
|
-
if (!this.clients.size) {
|
|
69478
|
-
process.nextTick(emitClose, this);
|
|
69479
|
-
} else {
|
|
69480
|
-
this._shouldEmitClose = true;
|
|
69481
|
-
}
|
|
69482
|
-
} else {
|
|
69483
|
-
process.nextTick(emitClose, this);
|
|
69484
|
-
}
|
|
69485
|
-
} else {
|
|
69486
|
-
const server = this._server;
|
|
69487
|
-
this._removeListeners();
|
|
69488
|
-
this._removeListeners = this._server = null;
|
|
69489
|
-
server.close(() => {
|
|
69490
|
-
emitClose(this);
|
|
69491
|
-
});
|
|
69492
|
-
}
|
|
69493
|
-
}
|
|
69494
|
-
/**
|
|
69495
|
-
* See if a given request should be handled by this server instance.
|
|
69496
|
-
*
|
|
69497
|
-
* @param {http.IncomingMessage} req Request object to inspect
|
|
69498
|
-
* @return {Boolean} `true` if the request is valid, else `false`
|
|
69499
|
-
* @public
|
|
69500
|
-
*/
|
|
69501
|
-
shouldHandle(req) {
|
|
69502
|
-
if (this.options.path) {
|
|
69503
|
-
const index = req.url.indexOf("?");
|
|
69504
|
-
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
69505
|
-
if (pathname !== this.options.path) return false;
|
|
69506
|
-
}
|
|
69507
|
-
return true;
|
|
69508
|
-
}
|
|
69509
|
-
/**
|
|
69510
|
-
* Handle a HTTP Upgrade request.
|
|
69511
|
-
*
|
|
69512
|
-
* @param {http.IncomingMessage} req The request object
|
|
69513
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
69514
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
69515
|
-
* @param {Function} cb Callback
|
|
69516
|
-
* @public
|
|
69517
|
-
*/
|
|
69518
|
-
handleUpgrade(req, socket, head2, cb) {
|
|
69519
|
-
socket.on("error", socketOnError);
|
|
69520
|
-
const key = req.headers["sec-websocket-key"];
|
|
69521
|
-
const upgrade = req.headers.upgrade;
|
|
69522
|
-
const version = +req.headers["sec-websocket-version"];
|
|
69523
|
-
if (req.method !== "GET") {
|
|
69524
|
-
const message = "Invalid HTTP method";
|
|
69525
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
69526
|
-
return;
|
|
69527
|
-
}
|
|
69528
|
-
if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
|
|
69529
|
-
const message = "Invalid Upgrade header";
|
|
69530
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
69531
|
-
return;
|
|
69532
|
-
}
|
|
69533
|
-
if (key === void 0 || !keyRegex.test(key)) {
|
|
69534
|
-
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
69535
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
69536
|
-
return;
|
|
69537
|
-
}
|
|
69538
|
-
if (version !== 13 && version !== 8) {
|
|
69539
|
-
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
69540
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
69541
|
-
"Sec-WebSocket-Version": "13, 8"
|
|
69542
|
-
});
|
|
69543
|
-
return;
|
|
69544
|
-
}
|
|
69545
|
-
if (!this.shouldHandle(req)) {
|
|
69546
|
-
abortHandshake(socket, 400);
|
|
69547
|
-
return;
|
|
69548
|
-
}
|
|
69549
|
-
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
69550
|
-
let protocols = /* @__PURE__ */ new Set();
|
|
69551
|
-
if (secWebSocketProtocol !== void 0) {
|
|
69552
|
-
try {
|
|
69553
|
-
protocols = subprotocol3.parse(secWebSocketProtocol);
|
|
69554
|
-
} catch (err) {
|
|
69555
|
-
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
69556
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
69557
|
-
return;
|
|
69558
|
-
}
|
|
69559
|
-
}
|
|
69560
|
-
const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
|
|
69561
|
-
const extensions = {};
|
|
69562
|
-
if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
|
|
69563
|
-
const perMessageDeflate = new PerMessageDeflate3({
|
|
69564
|
-
...this.options.perMessageDeflate,
|
|
69565
|
-
isServer: true,
|
|
69566
|
-
maxPayload: this.options.maxPayload
|
|
69567
|
-
});
|
|
69568
|
-
try {
|
|
69569
|
-
const offers = extension3.parse(secWebSocketExtensions);
|
|
69570
|
-
if (offers[PerMessageDeflate3.extensionName]) {
|
|
69571
|
-
perMessageDeflate.accept(offers[PerMessageDeflate3.extensionName]);
|
|
69572
|
-
extensions[PerMessageDeflate3.extensionName] = perMessageDeflate;
|
|
69573
|
-
}
|
|
69574
|
-
} catch (err) {
|
|
69575
|
-
const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
69576
|
-
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
69577
|
-
return;
|
|
69578
|
-
}
|
|
69579
|
-
}
|
|
69580
|
-
if (this.options.verifyClient) {
|
|
69581
|
-
const info = {
|
|
69582
|
-
origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
|
|
69583
|
-
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
69584
|
-
req
|
|
69585
|
-
};
|
|
69586
|
-
if (this.options.verifyClient.length === 2) {
|
|
69587
|
-
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
69588
|
-
if (!verified) {
|
|
69589
|
-
return abortHandshake(socket, code || 401, message, headers);
|
|
69590
|
-
}
|
|
69591
|
-
this.completeUpgrade(
|
|
69592
|
-
extensions,
|
|
69593
|
-
key,
|
|
69594
|
-
protocols,
|
|
69595
|
-
req,
|
|
69596
|
-
socket,
|
|
69597
|
-
head2,
|
|
69598
|
-
cb
|
|
69599
|
-
);
|
|
69600
|
-
});
|
|
69601
|
-
return;
|
|
69602
|
-
}
|
|
69603
|
-
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
69604
|
-
}
|
|
69605
|
-
this.completeUpgrade(extensions, key, protocols, req, socket, head2, cb);
|
|
69606
|
-
}
|
|
69607
|
-
/**
|
|
69608
|
-
* Upgrade the connection to WebSocket.
|
|
69609
|
-
*
|
|
69610
|
-
* @param {Object} extensions The accepted extensions
|
|
69611
|
-
* @param {String} key The value of the `Sec-WebSocket-Key` header
|
|
69612
|
-
* @param {Set} protocols The subprotocols
|
|
69613
|
-
* @param {http.IncomingMessage} req The request object
|
|
69614
|
-
* @param {Duplex} socket The network socket between the server and client
|
|
69615
|
-
* @param {Buffer} head The first packet of the upgraded stream
|
|
69616
|
-
* @param {Function} cb Callback
|
|
69617
|
-
* @throws {Error} If called more than once with the same socket
|
|
69618
|
-
* @private
|
|
69619
|
-
*/
|
|
69620
|
-
completeUpgrade(extensions, key, protocols, req, socket, head2, cb) {
|
|
69621
|
-
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
69622
|
-
if (socket[kWebSocket]) {
|
|
69623
|
-
throw new Error(
|
|
69624
|
-
"server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
|
|
69625
|
-
);
|
|
69626
|
-
}
|
|
69627
|
-
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
69628
|
-
const digest = createHash11("sha1").update(key + GUID).digest("base64");
|
|
69629
|
-
const headers = [
|
|
69630
|
-
"HTTP/1.1 101 Switching Protocols",
|
|
69631
|
-
"Upgrade: websocket",
|
|
69632
|
-
"Connection: Upgrade",
|
|
69633
|
-
`Sec-WebSocket-Accept: ${digest}`
|
|
69634
|
-
];
|
|
69635
|
-
const ws = new this.options.WebSocket(null, void 0, this.options);
|
|
69636
|
-
if (protocols.size) {
|
|
69637
|
-
const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
69638
|
-
if (protocol) {
|
|
69639
|
-
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
69640
|
-
ws._protocol = protocol;
|
|
69641
|
-
}
|
|
69642
|
-
}
|
|
69643
|
-
if (extensions[PerMessageDeflate3.extensionName]) {
|
|
69644
|
-
const params = extensions[PerMessageDeflate3.extensionName].params;
|
|
69645
|
-
const value2 = extension3.format({
|
|
69646
|
-
[PerMessageDeflate3.extensionName]: [params]
|
|
69647
|
-
});
|
|
69648
|
-
headers.push(`Sec-WebSocket-Extensions: ${value2}`);
|
|
69649
|
-
ws._extensions = extensions;
|
|
69650
|
-
}
|
|
69651
|
-
this.emit("headers", headers, req);
|
|
69652
|
-
socket.write(headers.concat("\r\n").join("\r\n"));
|
|
69653
|
-
socket.removeListener("error", socketOnError);
|
|
69654
|
-
ws.setSocket(socket, head2, {
|
|
69655
|
-
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
69656
|
-
maxBufferedChunks: this.options.maxBufferedChunks,
|
|
69657
|
-
maxFragments: this.options.maxFragments,
|
|
69658
|
-
maxPayload: this.options.maxPayload,
|
|
69659
|
-
skipUTF8Validation: this.options.skipUTF8Validation
|
|
69660
|
-
});
|
|
69661
|
-
if (this.clients) {
|
|
69662
|
-
this.clients.add(ws);
|
|
69663
|
-
ws.on("close", () => {
|
|
69664
|
-
this.clients.delete(ws);
|
|
69665
|
-
if (this._shouldEmitClose && !this.clients.size) {
|
|
69666
|
-
process.nextTick(emitClose, this);
|
|
69667
|
-
}
|
|
69668
|
-
});
|
|
69669
|
-
}
|
|
69670
|
-
cb(ws, req);
|
|
69671
|
-
}
|
|
69672
|
-
};
|
|
69673
|
-
module.exports = WebSocketServer3;
|
|
69674
|
-
function addListeners(server, map) {
|
|
69675
|
-
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
69676
|
-
return function removeListeners() {
|
|
69677
|
-
for (const event of Object.keys(map)) {
|
|
69678
|
-
server.removeListener(event, map[event]);
|
|
69679
|
-
}
|
|
69680
|
-
};
|
|
69681
|
-
}
|
|
69682
|
-
function emitClose(server) {
|
|
69683
|
-
server._state = CLOSED;
|
|
69684
|
-
server.emit("close");
|
|
69685
|
-
}
|
|
69686
|
-
function socketOnError() {
|
|
69687
|
-
this.destroy();
|
|
69688
|
-
}
|
|
69689
|
-
function abortHandshake(socket, code, message, headers) {
|
|
69690
|
-
message = message || http.STATUS_CODES[code];
|
|
69691
|
-
headers = {
|
|
69692
|
-
Connection: "close",
|
|
69693
|
-
"Content-Type": "text/html",
|
|
69694
|
-
"Content-Length": Buffer.byteLength(message),
|
|
69695
|
-
...headers
|
|
69696
|
-
};
|
|
69697
|
-
socket.once("finish", socket.destroy);
|
|
69698
|
-
socket.end(
|
|
69699
|
-
`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
|
|
69700
|
-
` + Object.keys(headers).map((h2) => `${h2}: ${headers[h2]}`).join("\r\n") + "\r\n\r\n" + message
|
|
69701
|
-
);
|
|
69702
|
-
}
|
|
69703
|
-
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
69704
|
-
if (server.listenerCount("wsClientError")) {
|
|
69705
|
-
const err = new Error(message);
|
|
69706
|
-
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
69707
|
-
server.emit("wsClientError", err, socket, req);
|
|
69708
|
-
} else {
|
|
69709
|
-
abortHandshake(socket, code, message, headers);
|
|
69710
|
-
}
|
|
69711
|
-
}
|
|
69712
|
-
}
|
|
69713
|
-
});
|
|
69714
|
-
|
|
69715
|
-
// ../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/wrapper.mjs
|
|
69716
|
-
var import_websocket2, wrapper_default;
|
|
69717
|
-
var init_wrapper2 = __esm({
|
|
69718
|
-
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/wrapper.mjs"() {
|
|
69719
|
-
__toESM(require_stream2());
|
|
69720
|
-
__toESM(require_extension2());
|
|
69721
|
-
__toESM(require_permessage_deflate2());
|
|
69722
|
-
__toESM(require_receiver2());
|
|
69723
|
-
__toESM(require_sender2());
|
|
69724
|
-
__toESM(require_subprotocol2());
|
|
69725
|
-
import_websocket2 = __toESM(require_websocket2());
|
|
69726
|
-
__toESM(require_websocket_server2());
|
|
69727
|
-
wrapper_default = import_websocket2.default;
|
|
69728
|
-
}
|
|
69729
|
-
});
|
|
69730
|
-
|
|
69731
66050
|
// ../../node_modules/.pnpm/ink@5.2.1_@types+react@18.3.28_react@18.3.1/node_modules/ink/build/devtools-window-polyfill.js
|
|
69732
66051
|
var customGlobal;
|
|
69733
66052
|
var init_devtools_window_polyfill = __esm({
|
|
69734
66053
|
"../../node_modules/.pnpm/ink@5.2.1_@types+react@18.3.28_react@18.3.1/node_modules/ink/build/devtools-window-polyfill.js"() {
|
|
69735
|
-
|
|
66054
|
+
init_wrapper();
|
|
69736
66055
|
customGlobal = global;
|
|
69737
66056
|
customGlobal.WebSocket ||= wrapper_default;
|
|
69738
66057
|
customGlobal.window ||= global;
|
|
@@ -76018,6 +72337,82 @@ var init_id = __esm({
|
|
|
76018
72337
|
}
|
|
76019
72338
|
});
|
|
76020
72339
|
|
|
72340
|
+
// ../chat-model/dist/trim-trailing.js
|
|
72341
|
+
function trimTrailing2(text3, marks) {
|
|
72342
|
+
let end = text3.length;
|
|
72343
|
+
while (end > 0 && marks.has(text3.charAt(end - 1)))
|
|
72344
|
+
end -= 1;
|
|
72345
|
+
return text3.slice(0, end);
|
|
72346
|
+
}
|
|
72347
|
+
var init_trim_trailing = __esm({
|
|
72348
|
+
"../chat-model/dist/trim-trailing.js"() {
|
|
72349
|
+
}
|
|
72350
|
+
});
|
|
72351
|
+
|
|
72352
|
+
// ../chat-model/dist/speech-tables.js
|
|
72353
|
+
function isTableRow(line) {
|
|
72354
|
+
return line !== void 0 && line.includes("|") && line.trim() !== "";
|
|
72355
|
+
}
|
|
72356
|
+
function cells(line) {
|
|
72357
|
+
return line.trim().replace(/^\|/u, "").replace(/\|$/u, "").split("|").map((cell) => cell.trim());
|
|
72358
|
+
}
|
|
72359
|
+
function isSeparatorFor(header, line) {
|
|
72360
|
+
if (line === void 0)
|
|
72361
|
+
return false;
|
|
72362
|
+
const marks = cells(line);
|
|
72363
|
+
return marks.length === cells(header).length && marks.every((mark) => SEPARATOR_CELL.test(mark));
|
|
72364
|
+
}
|
|
72365
|
+
function tableStartsAt(lines, index) {
|
|
72366
|
+
const header = lines[index];
|
|
72367
|
+
return header !== void 0 && isTableRow(header) && isSeparatorFor(header, lines[index + 1]);
|
|
72368
|
+
}
|
|
72369
|
+
function tableLength(lines, index) {
|
|
72370
|
+
let end = index + 2;
|
|
72371
|
+
while (isTableRow(lines[end]))
|
|
72372
|
+
end += 1;
|
|
72373
|
+
return end - index;
|
|
72374
|
+
}
|
|
72375
|
+
function bare(cell) {
|
|
72376
|
+
return trimTrailing2(cell, SENTENCE_PUNCTUATION);
|
|
72377
|
+
}
|
|
72378
|
+
function speakTable(lines) {
|
|
72379
|
+
if (!tableStartsAt(lines, 0))
|
|
72380
|
+
return null;
|
|
72381
|
+
const [header = "", , ...rows] = lines;
|
|
72382
|
+
const names = cells(header);
|
|
72383
|
+
return rows.map((row) => {
|
|
72384
|
+
const [first = "", ...rest] = cells(row).map(bare);
|
|
72385
|
+
const values = rest.map((value2, index) => value2 ? `${names[index + 1] ?? ""} ${value2}`.trim() : "").filter(Boolean);
|
|
72386
|
+
if (!first)
|
|
72387
|
+
return values.length ? `${values.join("; ")}.` : "";
|
|
72388
|
+
return values.length ? `${first}: ${values.join("; ")}.` : `${first}.`;
|
|
72389
|
+
}).filter(Boolean);
|
|
72390
|
+
}
|
|
72391
|
+
function speakMarkdownTables(markdown) {
|
|
72392
|
+
const lines = markdown.split("\n");
|
|
72393
|
+
const out = [];
|
|
72394
|
+
for (let index = 0; index < lines.length; ) {
|
|
72395
|
+
if (!tableStartsAt(lines, index)) {
|
|
72396
|
+
out.push(lines[index] ?? "");
|
|
72397
|
+
index += 1;
|
|
72398
|
+
continue;
|
|
72399
|
+
}
|
|
72400
|
+
const length = tableLength(lines, index);
|
|
72401
|
+
const spoken = speakTable(lines.slice(index, index + length)) ?? [];
|
|
72402
|
+
out.push(...spoken.flatMap((sentence, at) => at === 0 ? [sentence] : ["", sentence]));
|
|
72403
|
+
index += length;
|
|
72404
|
+
}
|
|
72405
|
+
return out.join("\n");
|
|
72406
|
+
}
|
|
72407
|
+
var SEPARATOR_CELL, SENTENCE_PUNCTUATION;
|
|
72408
|
+
var init_speech_tables = __esm({
|
|
72409
|
+
"../chat-model/dist/speech-tables.js"() {
|
|
72410
|
+
init_trim_trailing();
|
|
72411
|
+
SEPARATOR_CELL = /^:?-{3,}:?$/u;
|
|
72412
|
+
SENTENCE_PUNCTUATION = /* @__PURE__ */ new Set([".", ",", ";", ":"]);
|
|
72413
|
+
}
|
|
72414
|
+
});
|
|
72415
|
+
|
|
76021
72416
|
// ../chat-model/dist/streaming-speech.js
|
|
76022
72417
|
function detectSpeechLanguage(text3, previous) {
|
|
76023
72418
|
const lower2 = text3.toLocaleLowerCase();
|
|
@@ -76045,6 +72440,7 @@ function detectSpeechLanguage(text3, previous) {
|
|
|
76045
72440
|
var POLISH_WORDS, ENGLISH_WORDS, POLISH_DIACRITIC_RE, WORD_RE, ENGLISH_SUFFIX_RE, POLISH_CLUSTER_RE;
|
|
76046
72441
|
var init_streaming_speech = __esm({
|
|
76047
72442
|
"../chat-model/dist/streaming-speech.js"() {
|
|
72443
|
+
init_speech_tables();
|
|
76048
72444
|
POLISH_WORDS = /* @__PURE__ */ new Set([
|
|
76049
72445
|
"a",
|
|
76050
72446
|
"aby",
|
|
@@ -76256,6 +72652,104 @@ var init_streaming_speech = __esm({
|
|
|
76256
72652
|
}
|
|
76257
72653
|
});
|
|
76258
72654
|
|
|
72655
|
+
// ../chat-model/dist/spoken-links.js
|
|
72656
|
+
function hostOf(address) {
|
|
72657
|
+
return address.replace(SCHEME_RE, "").split(/[/?#]/u)[0]?.replace(/:\d+$/u, "") ?? "";
|
|
72658
|
+
}
|
|
72659
|
+
function siteName(address) {
|
|
72660
|
+
const labels = hostOf(address).replace(/^www\./iu, "").split(".").filter(Boolean);
|
|
72661
|
+
if (labels.length === 0 || labels.every((label3) => /^\d+$/u.test(label3)))
|
|
72662
|
+
return null;
|
|
72663
|
+
if (labels.length > 1)
|
|
72664
|
+
labels.pop();
|
|
72665
|
+
if (labels.length > 1 && SECOND_LEVEL_LABELS.has(labels.at(-1)?.toLowerCase() ?? ""))
|
|
72666
|
+
labels.pop();
|
|
72667
|
+
return labels.at(-1) ?? null;
|
|
72668
|
+
}
|
|
72669
|
+
function isWebAddress(value2) {
|
|
72670
|
+
if (SCHEME_RE.test(value2))
|
|
72671
|
+
return true;
|
|
72672
|
+
const host = hostOf(value2);
|
|
72673
|
+
return host.length < value2.length && DOMAIN_RE.test(host);
|
|
72674
|
+
}
|
|
72675
|
+
function isBareDomain(value2) {
|
|
72676
|
+
return DOMAIN_RE.test(value2);
|
|
72677
|
+
}
|
|
72678
|
+
function spokenLink(address, language) {
|
|
72679
|
+
const site = siteName(address);
|
|
72680
|
+
if (language === "pl")
|
|
72681
|
+
return site ? `link do strony ${site}` : "link";
|
|
72682
|
+
return site ? `a link to ${site}` : "a link";
|
|
72683
|
+
}
|
|
72684
|
+
var SECOND_LEVEL_LABELS, SCHEME_RE, DOMAIN_RE;
|
|
72685
|
+
var init_spoken_links = __esm({
|
|
72686
|
+
"../chat-model/dist/spoken-links.js"() {
|
|
72687
|
+
SECOND_LEVEL_LABELS = /* @__PURE__ */ new Set(["ac", "co", "com", "edu", "gov", "net", "org"]);
|
|
72688
|
+
SCHEME_RE = /^[a-z][a-z0-9+.-]*:\/\//iu;
|
|
72689
|
+
DOMAIN_RE = /^(?:www\.)?(?:[a-z0-9-]+\.)+[a-z]{2,}$/iu;
|
|
72690
|
+
}
|
|
72691
|
+
});
|
|
72692
|
+
|
|
72693
|
+
// ../chat-model/dist/speech-text.js
|
|
72694
|
+
function stripNonVerbalArtifacts(text3) {
|
|
72695
|
+
return text3.replace(KEYCAP_EMOJI_RE, " ").replace(NON_VERBAL_SYMBOL_RE, " ").replace(EMOJI_MODIFIER_RE, "").replace(EMOJI_JOINER_RE, "").replace(/\*/g, " ");
|
|
72696
|
+
}
|
|
72697
|
+
function isUrlOrFileReference(value2) {
|
|
72698
|
+
const candidate = trimTrailing2(value2.trim(), TRAILING_PUNCTUATION);
|
|
72699
|
+
return /^(?:https?:\/\/|www\.)/iu.test(candidate) || /^(?:~[\\/]|\.{1,2}[\\/]|[A-Za-z]:[\\/]|\/)/u.test(candidate) || /[\\/][^\\/]+\.[A-Za-z0-9]{2,8}(?::\d+(?::\d+)?)?$/u.test(candidate) || FILE_EXTENSION_RE.test(candidate) || /^(?:[a-z0-9-]+\.)+[a-z]{2,}(?:\/[^\s<>)]*)?$/iu.test(candidate) && !FILE_EXTENSION_RE.test(candidate);
|
|
72700
|
+
}
|
|
72701
|
+
function speakReference(value2, language) {
|
|
72702
|
+
const trimmed = value2.trim();
|
|
72703
|
+
const reference = trimTrailing2(trimmed, TRAILING_PUNCTUATION);
|
|
72704
|
+
const after = trimmed.slice(reference.length);
|
|
72705
|
+
if (isWebAddress(reference))
|
|
72706
|
+
return `${spokenLink(reference, language)}${after}`;
|
|
72707
|
+
if (isBareDomain(reference) && !FILE_EXTENSION_RE.test(reference))
|
|
72708
|
+
return `${siteName(reference) ?? " "}${after}`;
|
|
72709
|
+
return isUrlOrFileReference(reference) ? " " : value2;
|
|
72710
|
+
}
|
|
72711
|
+
function proseLanguage(markdown) {
|
|
72712
|
+
return detectSpeechLanguage(markdown.replace(/\([^()]*\)|<[^<>]*>/gu, " ").replace(WEB_ADDRESS_RE, " "));
|
|
72713
|
+
}
|
|
72714
|
+
function normalizeSpeakableMarkdown(markdown, fencedCodeReplacement) {
|
|
72715
|
+
const language = proseLanguage(markdown);
|
|
72716
|
+
const stripped = speakMarkdownTables(markdown).replace(/```[\s\S]*?```/g, fencedCodeReplacement).replace(/~~~[\s\S]*?~~~/g, fencedCodeReplacement).replace(/^\s*\[[^\]]+\]:\s*\S+.*$/gm, " ").replace(/!\[([^\]]*)\]\([^)]*\)/g, (_match, label3) => speakReference(label3, language)).replace(/\[([^\]]+)\]\([^)]*\)/g, (_match, label3) => speakReference(label3, language)).replace(/\[([^\]]+)\]\s*\[[^\]]*\]/g, (_match, label3) => speakReference(label3, language)).replace(/<(https?:\/\/[^>]+)>/giu, (_match, address) => spokenLink(address, language)).replace(WEB_ADDRESS_RE, (address) => speakReference(address, language)).replace(/`([^`]+)`/g, (_match, code) => speakReference(code, language)).replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/__([^_]+)__/g, "$1").replace(/(^|[^a-zA-Z0-9])_([^_]+)_(?![a-zA-Z0-9])/g, "$1$2").replace(/~~([^~]+)~~/g, "$1").replace(/^\s{0,3}#{1,6}\s+/gm, "").replace(/^\s*>\s?/gm, "").replace(/^\s*[-*+]\s+/gm, "").replace(/^\s*\d+[.)]\s+/gm, "").replace(/^\s*([-*_])\1{2,}\s*$/gm, "").replace(/\|/g, " ");
|
|
72717
|
+
const withoutPaths = stripped.replace(ABSOLUTE_FILE_PATH_RE, " ").replace(FILE_PATH_RE, (match) => {
|
|
72718
|
+
if (SLASHED_PROSE_RE.test(match))
|
|
72719
|
+
return match;
|
|
72720
|
+
return isWebAddress(match) ? speakReference(match, language) : " ";
|
|
72721
|
+
}).replace(DOMAIN_RE2, (match, offset, whole) => FILE_EXTENSION_RE.test(match) || DOTTED_PROSE_RE.test(match) || whole[offset - 1] === "@" ? match : speakReference(match, language));
|
|
72722
|
+
return stripNonVerbalArtifacts(withoutPaths).split(/\n{2,}/).map((p3) => p3.replace(/\s+/g, " ").trim()).filter(Boolean).map((p3) => /[.!?:]$/.test(p3) ? p3 : `${p3}.`).join(" ").replace(/\s+([.!?])/gu, "$1").replace(/\s+([,;:!?])/gu, "$1").replace(/([,;:])\s*[.!?]/gu, ".").replace(/([,;:])(?:\s*[,;:])+/gu, "$1").replace(/\s{2,}/g, " ").trim();
|
|
72723
|
+
}
|
|
72724
|
+
function toSpeakableText(markdown) {
|
|
72725
|
+
return normalizeSpeakableMarkdown(markdown, " (code block) ");
|
|
72726
|
+
}
|
|
72727
|
+
function toVoiceConversationText(markdown) {
|
|
72728
|
+
const withoutCode = markdown.replace(/```[\s\S]*?```/g, " ").replace(/~~~[\s\S]*?~~~/g, " ").replace(/```[\s\S]*$/g, " ").replace(/~~~[\s\S]*$/g, " ").replace(/^(?: {4}|\t).*(?:\n|$)/gm, " ");
|
|
72729
|
+
return normalizeSpeakableMarkdown(withoutCode, " ");
|
|
72730
|
+
}
|
|
72731
|
+
var KEYCAP_EMOJI_RE, NON_VERBAL_SYMBOL_RE, EMOJI_MODIFIER_RE, EMOJI_JOINER_RE, DOMAIN_RE2, FILE_EXTENSION_RE, ABSOLUTE_FILE_PATH_RE, FILE_PATH_RE, DOTTED_PROSE_RE, SLASHED_PROSE_RE, TRAILING_PUNCTUATION, WEB_ADDRESS_RE;
|
|
72732
|
+
var init_speech_text = __esm({
|
|
72733
|
+
"../chat-model/dist/speech-text.js"() {
|
|
72734
|
+
init_speech_tables();
|
|
72735
|
+
init_spoken_links();
|
|
72736
|
+
init_streaming_speech();
|
|
72737
|
+
init_trim_trailing();
|
|
72738
|
+
KEYCAP_EMOJI_RE = /[#*0-9]\uFE0F?\u20E3/gu;
|
|
72739
|
+
NON_VERBAL_SYMBOL_RE = new RegExp("(?!\xB0)\\p{So}", "gu");
|
|
72740
|
+
EMOJI_MODIFIER_RE = new RegExp("\\p{Emoji_Modifier}", "gu");
|
|
72741
|
+
EMOJI_JOINER_RE = /(?:\uFE0E|\uFE0F|\u200D|[\u{E0020}-\u{E007F}])/gu;
|
|
72742
|
+
DOMAIN_RE2 = /\b(?:[a-z0-9-]+\.)+[a-z]{2,}(?:\/[^\s<>)]*)?/giu;
|
|
72743
|
+
FILE_EXTENSION_RE = /\.(?:js|jsx|ts|tsx|mjs|cjs|json|jsonl|ya?ml|toml|md|mdx|txt|log|pdf|docx|xlsx|pptx|csv|tsv|py|rs|go|java|kt|c|h|cpp|hpp|cs|php|sh|bash|zsh|sql|html|css|scss|xml|ini|env|conf|png|jpe?g|svg|webp|wav|mp3|ogg)(?::\d+(?::\d+)?)?$/iu;
|
|
72744
|
+
ABSOLUTE_FILE_PATH_RE = /(?<![\p{L}\p{N}_])(?:~[\\/]|[A-Za-z]:[\\/]|\/)[^<>\r\n`"'()[\],;!?]*?\.[A-Za-z]{2,8}(?::\d+(?::\d+)?)?(?=$|[\s),;.!?])/gu;
|
|
72745
|
+
FILE_PATH_RE = /(?<![\p{L}\p{N}_])(?:~[\\/]|\.{1,2}[\\/]|[A-Za-z]:[\\/]|\/)?(?:[\p{L}\p{N}_.@+-]+[\\/])+[\p{L}\p{N}_.@+-]+(?:\.[A-Za-z0-9]{2,8})?(?::\d+(?::\d+)?)?(?![\p{L}\p{N}_])/gu;
|
|
72746
|
+
DOTTED_PROSE_RE = /^m\.in$/iu;
|
|
72747
|
+
SLASHED_PROSE_RE = new RegExp("^(?:\\d+(?:[.,]\\d+)?(?:\\/\\d+(?:[.,]\\d+)?)+|(?:k?m|mi|[kKMG][bB])\\/(?:h|s|min)|\\p{Lu}{1,5}\\/\\p{Lu}{1,5}|and\\/or|i\\/lub)[.,;:!?]?$", "u");
|
|
72748
|
+
TRAILING_PUNCTUATION = /* @__PURE__ */ new Set([")", ",", ".", ";", ":", "!", "?"]);
|
|
72749
|
+
WEB_ADDRESS_RE = /\b(?:https?:\/\/|www\.)[^\s<>()[\]`]+/giu;
|
|
72750
|
+
}
|
|
72751
|
+
});
|
|
72752
|
+
|
|
76259
72753
|
// ../chat-model/dist/voice-operations.js
|
|
76260
72754
|
var init_voice_operations = __esm({
|
|
76261
72755
|
"../chat-model/dist/voice-operations.js"() {
|
|
@@ -76373,6 +72867,8 @@ var init_dist24 = __esm({
|
|
|
76373
72867
|
init_log2();
|
|
76374
72868
|
init_id();
|
|
76375
72869
|
init_streaming_speech();
|
|
72870
|
+
init_speech_tables();
|
|
72871
|
+
init_speech_text();
|
|
76376
72872
|
init_voice_feedback_scheduler();
|
|
76377
72873
|
init_voice_operations();
|
|
76378
72874
|
init_account_limit();
|
|
@@ -76424,12 +72920,12 @@ function parseBlocks(src) {
|
|
|
76424
72920
|
assertDefined4(row, "line index within bounds");
|
|
76425
72921
|
if (!row.trim().startsWith("|"))
|
|
76426
72922
|
break;
|
|
76427
|
-
const
|
|
76428
|
-
if (
|
|
72923
|
+
const cells2 = parseTableCells(row);
|
|
72924
|
+
if (cells2.length === 0)
|
|
76429
72925
|
break;
|
|
76430
|
-
while (
|
|
76431
|
-
|
|
76432
|
-
rows.push(
|
|
72926
|
+
while (cells2.length < header.length)
|
|
72927
|
+
cells2.push("");
|
|
72928
|
+
rows.push(cells2.slice(0, header.length));
|
|
76433
72929
|
i2++;
|
|
76434
72930
|
}
|
|
76435
72931
|
blocks.push({ kind: "table", header, aligns, rows });
|
|
@@ -76558,8 +73054,8 @@ function parseTableCells(line) {
|
|
|
76558
73054
|
return stripOuterPipes(line).split("|").map((s) => s.trim());
|
|
76559
73055
|
}
|
|
76560
73056
|
function parseTableAligns(sep8) {
|
|
76561
|
-
const
|
|
76562
|
-
return
|
|
73057
|
+
const cells2 = stripOuterPipes(sep8).split("|");
|
|
73058
|
+
return cells2.map((c3) => {
|
|
76563
73059
|
const t2 = c3.trim();
|
|
76564
73060
|
const left = t2.startsWith(":");
|
|
76565
73061
|
const right = t2.endsWith(":");
|
|
@@ -76822,8 +73318,8 @@ var init_table = __esm({
|
|
|
76822
73318
|
const aligns = block2.header.map((_2, ci) => block2.aligns[ci] ?? "left");
|
|
76823
73319
|
return (0, import_jsx_runtime10.jsxs)(Box_default, { flexDirection: "column", marginTop: suppressTopMargin ? 0 : 1, children: [(0, import_jsx_runtime10.jsx)(TableRow, { cells: block2.header, widths, aligns, bold: true }), (0, import_jsx_runtime10.jsx)(TableRule, { widths }), block2.rows.map((row, i2) => (0, import_jsx_runtime10.jsx)(TableRow, { cells: row, widths, aligns }, i2))] });
|
|
76824
73320
|
};
|
|
76825
|
-
TableRow = ({ cells, widths, aligns, bold }) => (0, import_jsx_runtime10.jsx)(Box_default, { children: widths.map((w, ci) => {
|
|
76826
|
-
const text3 = padCell(
|
|
73321
|
+
TableRow = ({ cells: cells2, widths, aligns, bold }) => (0, import_jsx_runtime10.jsx)(Box_default, { children: widths.map((w, ci) => {
|
|
73322
|
+
const text3 = padCell(cells2[ci] ?? "", w, aligns[ci] ?? "left");
|
|
76827
73323
|
return (0, import_jsx_runtime10.jsxs)(import_react31.default.Fragment, { children: [ci > 0 ? (0, import_jsx_runtime10.jsx)(Text, { dimColor: true, children: " \u2502 " }) : null, (0, import_jsx_runtime10.jsx)(Box_default, { width: w, flexShrink: 0, children: (0, import_jsx_runtime10.jsx)(Text, { bold, color: "white", wrap: "truncate", children: text3 }) })] }, ci);
|
|
76828
73324
|
}) });
|
|
76829
73325
|
TableRule = ({ widths }) => (0, import_jsx_runtime10.jsx)(Text, { dimColor: true, children: widths.map((w) => "\u2500".repeat(w)).join("\u2500\u253C\u2500") });
|
|
@@ -79167,19 +75663,7 @@ var init_dedupe2 = __esm({
|
|
|
79167
75663
|
}
|
|
79168
75664
|
});
|
|
79169
75665
|
function toSpeech(markdown) {
|
|
79170
|
-
|
|
79171
|
-
t2 = t2.replace(/```[\s\S]*?```/g, " (code omitted) ");
|
|
79172
|
-
t2 = t2.replace(/```[\s\S]*$/g, " (code omitted) ");
|
|
79173
|
-
t2 = t2.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
|
|
79174
|
-
t2 = t2.replace(/\[([^\]]+)\]\([^)]*\)/g, "$1");
|
|
79175
|
-
t2 = t2.replace(/`([^`]+)`/g, "$1");
|
|
79176
|
-
t2 = t2.replace(/(\*\*|__|~~|\*|_)/g, "");
|
|
79177
|
-
t2 = t2.replace(/^\s{0,3}#{1,6}\s*/gm, "");
|
|
79178
|
-
t2 = t2.replace(/^\s{0,3}>\s?/gm, "");
|
|
79179
|
-
t2 = t2.replace(/^\s{0,3}[-*+]\s+/gm, "");
|
|
79180
|
-
t2 = t2.replace(/[ \t]+/g, " ");
|
|
79181
|
-
t2 = t2.replace(/\n{3,}/g, "\n\n");
|
|
79182
|
-
return t2.trim();
|
|
75666
|
+
return toSpeakableText(markdown ?? "");
|
|
79183
75667
|
}
|
|
79184
75668
|
function truncateForSpeech(text3, max) {
|
|
79185
75669
|
if (text3.length <= max)
|
|
@@ -79199,7 +75683,8 @@ async function synthesizeReply(session, text3, opts = {}) {
|
|
|
79199
75683
|
}
|
|
79200
75684
|
if (!synth)
|
|
79201
75685
|
return { ok: false, reason: "no-synthesizer" };
|
|
79202
|
-
const
|
|
75686
|
+
const spoken = opts.conversation ? toVoiceConversationText(text3 ?? "") : toSpeech(text3);
|
|
75687
|
+
const speech = truncateForSpeech(spoken, opts.maxChars ?? DEFAULT_MAX_SPEECH_CHARS);
|
|
79203
75688
|
if (!speech)
|
|
79204
75689
|
return { ok: false, reason: "empty" };
|
|
79205
75690
|
const synthOpts = {};
|
|
@@ -98152,10 +94637,10 @@ function agentCliTargetAt(desc, found, opts = {}) {
|
|
|
98152
94637
|
const platform2 = opts.platform ?? process.platform;
|
|
98153
94638
|
if (platform2 !== "win32")
|
|
98154
94639
|
return { kind: "direct", command: found };
|
|
98155
|
-
const
|
|
98156
|
-
if (WINDOWS_NATIVE.has(
|
|
94640
|
+
const extension2 = path3__default.win32.extname(found).toLowerCase();
|
|
94641
|
+
if (WINDOWS_NATIVE.has(extension2))
|
|
98157
94642
|
return { kind: "direct", command: found };
|
|
98158
|
-
if (!WINDOWS_SHIMS.has(
|
|
94643
|
+
if (!WINDOWS_SHIMS.has(extension2))
|
|
98159
94644
|
throw new Error(`Cannot run ${desc.name} from ${found}; install it again or point at ${desc.command}.exe.`);
|
|
98160
94645
|
const dir = path3__default.win32.dirname(found);
|
|
98161
94646
|
const at = (relative9) => path3__default.win32.join(dir, ...relative9.split("/"));
|