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