@rsbuild/core 2.0.0-beta.7 → 2.0.0-beta.8
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/bin/rsbuild.js +13 -0
- package/compiled/connect-next/index.d.ts +56 -0
- package/compiled/{connect → connect-next}/license +1 -0
- package/compiled/connect-next/package.json +1 -0
- package/compiled/css-loader/index.js +2 -2
- package/compiled/html-rspack-plugin/index.js +14 -14
- package/compiled/jiti/dist/babel.cjs +60 -60
- package/compiled/jiti/dist/jiti.cjs +2 -2
- package/compiled/postcss-loader/index.js +6 -6
- package/compiled/rslog/index.d.ts +17 -1
- package/compiled/rslog/package.json +1 -1
- package/dist/{131.js → 958.js} +254 -357
- package/dist/chokidar.js +59 -57
- package/dist/client/hmr.js +1 -1
- package/dist/client/overlay.js +1 -1
- package/dist/connect-next.js +268 -0
- package/dist/{connect.js.LICENSE.txt → connect-next.js.LICENSE.txt} +3 -13
- package/dist/cors.js +2 -2
- package/dist/http-proxy-middleware.js +57 -552
- package/dist/index.js +1 -1
- package/dist/launch-editor-middleware.js +23 -8
- package/dist/manifest-plugin.js +18 -18
- package/dist/memfs.js +178 -717
- package/dist/{710.js → mrmime.js} +2 -1
- package/dist/open.js +35 -32
- package/dist/range-parser.js +2 -2
- package/dist/remapping.js +2 -2
- package/dist/rslib-runtime.js +3 -3
- package/dist/sirv.js +14 -14
- package/dist/src.js +510 -0
- package/dist/tinyglobby.js +25 -25
- package/dist/transformLoader.mjs +38 -1
- package/dist/transformRawLoader.mjs +1 -1
- package/dist/ws.js +1541 -0
- package/dist-types/helpers/index.d.ts +1 -1
- package/dist-types/helpers/vendors.d.ts +0 -1
- package/dist-types/server/runner/asModule.d.ts +1 -1
- package/dist-types/server/socketServer.d.ts +1 -1
- package/dist-types/types/thirdParty.d.ts +1 -1
- package/package.json +7 -8
- package/compiled/connect/index.d.ts +0 -90
- package/compiled/connect/package.json +0 -1
- package/compiled/ws/index.d.ts +0 -437
- package/compiled/ws/index.js +0 -3166
- package/compiled/ws/license +0 -20
- package/compiled/ws/package.json +0 -1
- package/dist/397.js +0 -11
- package/dist/7.js +0 -1
- package/dist/712.js +0 -15
- package/dist/743.js +0 -7
- package/dist/88.js +0 -40
- package/dist/connect.js +0 -574
- package/dist-types/helpers/color.d.ts +0 -4
- /package/dist/{131.js.LICENSE.txt → 958.js.LICENSE.txt} +0 -0
- /package/dist/client/{59.js → 797.js} +0 -0
- /package/dist/{31.js → trace-mapping.js} +0 -0
package/dist/ws.js
ADDED
|
@@ -0,0 +1,1541 @@
|
|
|
1
|
+
import * as __rspack_external_buffer from "buffer";
|
|
2
|
+
import * as __rspack_external_crypto from "crypto";
|
|
3
|
+
import * as __rspack_external_http from "http";
|
|
4
|
+
import * as __rspack_external_https from "https";
|
|
5
|
+
import * as __rspack_external_net from "net";
|
|
6
|
+
import * as __rspack_external_stream from "stream";
|
|
7
|
+
import * as __rspack_external_tls from "tls";
|
|
8
|
+
import * as __rspack_external_url from "url";
|
|
9
|
+
import * as __rspack_external_zlib from "zlib";
|
|
10
|
+
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
11
|
+
import "./958.js";
|
|
12
|
+
__webpack_require__.add({
|
|
13
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
14
|
+
let { EMPTY_BUFFER } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), FastBuffer = Buffer[Symbol.species];
|
|
15
|
+
function toBuffer(data) {
|
|
16
|
+
let buf;
|
|
17
|
+
return (toBuffer.readOnly = !0, Buffer.isBuffer(data)) ? data : (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);
|
|
18
|
+
}
|
|
19
|
+
module.exports = {
|
|
20
|
+
concat: function concat(list, totalLength) {
|
|
21
|
+
if (0 === list.length) return EMPTY_BUFFER;
|
|
22
|
+
if (1 === list.length) return list[0];
|
|
23
|
+
let target = Buffer.allocUnsafe(totalLength), offset = 0;
|
|
24
|
+
for(let i = 0; i < list.length; i++){
|
|
25
|
+
let buf = list[i];
|
|
26
|
+
target.set(buf, offset), offset += buf.length;
|
|
27
|
+
}
|
|
28
|
+
return offset < totalLength ? new FastBuffer(target.buffer, target.byteOffset, offset) : target;
|
|
29
|
+
},
|
|
30
|
+
mask: function _mask(source, mask, output, offset, length) {
|
|
31
|
+
for(let i = 0; i < length; i++)output[offset + i] = source[i] ^ mask[3 & i];
|
|
32
|
+
},
|
|
33
|
+
toArrayBuffer: function toArrayBuffer(buf) {
|
|
34
|
+
return buf.length === buf.buffer.byteLength ? buf.buffer : buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
35
|
+
},
|
|
36
|
+
toBuffer,
|
|
37
|
+
unmask: function _unmask(buffer, mask) {
|
|
38
|
+
for(let i = 0; i < buffer.length; i++)buffer[i] ^= mask[3 & i];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js" (module) {
|
|
43
|
+
let BINARY_TYPES = [
|
|
44
|
+
'nodebuffer',
|
|
45
|
+
'arraybuffer',
|
|
46
|
+
'fragments'
|
|
47
|
+
], hasBlob = "u" > typeof Blob;
|
|
48
|
+
hasBlob && BINARY_TYPES.push('blob'), module.exports = {
|
|
49
|
+
BINARY_TYPES,
|
|
50
|
+
CLOSE_TIMEOUT: 30000,
|
|
51
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
52
|
+
GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
|
|
53
|
+
hasBlob,
|
|
54
|
+
kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
|
|
55
|
+
kListener: Symbol('kListener'),
|
|
56
|
+
kStatusCode: Symbol('status-code'),
|
|
57
|
+
kWebSocket: Symbol('websocket'),
|
|
58
|
+
NOOP: ()=>{}
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
62
|
+
let { kForOnEventAttribute, kListener } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), kCode = Symbol('kCode'), kData = Symbol('kData'), kError = Symbol('kError'), kMessage = Symbol('kMessage'), kReason = Symbol('kReason'), kTarget = Symbol('kTarget'), kType = Symbol('kType'), kWasClean = Symbol('kWasClean');
|
|
63
|
+
class Event {
|
|
64
|
+
constructor(type){
|
|
65
|
+
this[kTarget] = null, this[kType] = type;
|
|
66
|
+
}
|
|
67
|
+
get target() {
|
|
68
|
+
return this[kTarget];
|
|
69
|
+
}
|
|
70
|
+
get type() {
|
|
71
|
+
return this[kType];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
Object.defineProperty(Event.prototype, 'target', {
|
|
75
|
+
enumerable: !0
|
|
76
|
+
}), Object.defineProperty(Event.prototype, 'type', {
|
|
77
|
+
enumerable: !0
|
|
78
|
+
});
|
|
79
|
+
class CloseEvent extends Event {
|
|
80
|
+
constructor(type, options = {}){
|
|
81
|
+
super(type), this[kCode] = void 0 === options.code ? 0 : options.code, this[kReason] = void 0 === options.reason ? '' : options.reason, this[kWasClean] = void 0 !== options.wasClean && options.wasClean;
|
|
82
|
+
}
|
|
83
|
+
get code() {
|
|
84
|
+
return this[kCode];
|
|
85
|
+
}
|
|
86
|
+
get reason() {
|
|
87
|
+
return this[kReason];
|
|
88
|
+
}
|
|
89
|
+
get wasClean() {
|
|
90
|
+
return this[kWasClean];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
Object.defineProperty(CloseEvent.prototype, 'code', {
|
|
94
|
+
enumerable: !0
|
|
95
|
+
}), Object.defineProperty(CloseEvent.prototype, 'reason', {
|
|
96
|
+
enumerable: !0
|
|
97
|
+
}), Object.defineProperty(CloseEvent.prototype, 'wasClean', {
|
|
98
|
+
enumerable: !0
|
|
99
|
+
});
|
|
100
|
+
class ErrorEvent extends Event {
|
|
101
|
+
constructor(type, options = {}){
|
|
102
|
+
super(type), this[kError] = void 0 === options.error ? null : options.error, this[kMessage] = void 0 === options.message ? '' : options.message;
|
|
103
|
+
}
|
|
104
|
+
get error() {
|
|
105
|
+
return this[kError];
|
|
106
|
+
}
|
|
107
|
+
get message() {
|
|
108
|
+
return this[kMessage];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
Object.defineProperty(ErrorEvent.prototype, 'error', {
|
|
112
|
+
enumerable: !0
|
|
113
|
+
}), Object.defineProperty(ErrorEvent.prototype, 'message', {
|
|
114
|
+
enumerable: !0
|
|
115
|
+
});
|
|
116
|
+
class MessageEvent extends Event {
|
|
117
|
+
constructor(type, options = {}){
|
|
118
|
+
super(type), this[kData] = void 0 === options.data ? null : options.data;
|
|
119
|
+
}
|
|
120
|
+
get data() {
|
|
121
|
+
return this[kData];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function callListener(listener, thisArg, event) {
|
|
125
|
+
'object' == typeof listener && listener.handleEvent ? listener.handleEvent.call(listener, event) : listener.call(thisArg, event);
|
|
126
|
+
}
|
|
127
|
+
Object.defineProperty(MessageEvent.prototype, 'data', {
|
|
128
|
+
enumerable: !0
|
|
129
|
+
}), module.exports = {
|
|
130
|
+
CloseEvent,
|
|
131
|
+
ErrorEvent,
|
|
132
|
+
Event,
|
|
133
|
+
EventTarget: {
|
|
134
|
+
addEventListener (type, handler, options = {}) {
|
|
135
|
+
let wrapper;
|
|
136
|
+
for (let listener of this.listeners(type))if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) return;
|
|
137
|
+
if ('message' === type) wrapper = function onMessage(data, isBinary) {
|
|
138
|
+
let event = new MessageEvent('message', {
|
|
139
|
+
data: isBinary ? data : data.toString()
|
|
140
|
+
});
|
|
141
|
+
event[kTarget] = this, callListener(handler, this, event);
|
|
142
|
+
};
|
|
143
|
+
else if ('close' === type) wrapper = function onClose(code, message) {
|
|
144
|
+
let event = new CloseEvent('close', {
|
|
145
|
+
code,
|
|
146
|
+
reason: message.toString(),
|
|
147
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
148
|
+
});
|
|
149
|
+
event[kTarget] = this, callListener(handler, this, event);
|
|
150
|
+
};
|
|
151
|
+
else if ('error' === type) wrapper = function onError(error) {
|
|
152
|
+
let event = new ErrorEvent('error', {
|
|
153
|
+
error,
|
|
154
|
+
message: error.message
|
|
155
|
+
});
|
|
156
|
+
event[kTarget] = this, callListener(handler, this, event);
|
|
157
|
+
};
|
|
158
|
+
else {
|
|
159
|
+
if ('open' !== type) return;
|
|
160
|
+
wrapper = function onOpen() {
|
|
161
|
+
let event = new Event('open');
|
|
162
|
+
event[kTarget] = this, callListener(handler, this, event);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute], wrapper[kListener] = handler, options.once ? this.once(type, wrapper) : this.on(type, wrapper);
|
|
166
|
+
},
|
|
167
|
+
removeEventListener (type, handler) {
|
|
168
|
+
for (let listener of this.listeners(type))if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
|
|
169
|
+
this.removeListener(type, listener);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
MessageEvent
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
178
|
+
let { tokenChars } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js");
|
|
179
|
+
function push(dest, name, elem) {
|
|
180
|
+
void 0 === dest[name] ? dest[name] = [
|
|
181
|
+
elem
|
|
182
|
+
] : dest[name].push(elem);
|
|
183
|
+
}
|
|
184
|
+
module.exports = {
|
|
185
|
+
format: function format(extensions) {
|
|
186
|
+
return Object.keys(extensions).map((extension)=>{
|
|
187
|
+
let configurations = extensions[extension];
|
|
188
|
+
return Array.isArray(configurations) || (configurations = [
|
|
189
|
+
configurations
|
|
190
|
+
]), configurations.map((params)=>[
|
|
191
|
+
extension
|
|
192
|
+
].concat(Object.keys(params).map((k)=>{
|
|
193
|
+
let values = params[k];
|
|
194
|
+
return Array.isArray(values) || (values = [
|
|
195
|
+
values
|
|
196
|
+
]), values.map((v)=>!0 === v ? k : `${k}=${v}`).join('; ');
|
|
197
|
+
})).join('; ')).join(', ');
|
|
198
|
+
}).join(', ');
|
|
199
|
+
},
|
|
200
|
+
parse: function parse(header) {
|
|
201
|
+
let extensionName, paramName, offers = Object.create(null), params = Object.create(null), mustUnescape = !1, isEscaping = !1, inQuotes = !1, start = -1, code = -1, end = -1, i = 0;
|
|
202
|
+
for(; i < header.length; i++)if (code = header.charCodeAt(i), void 0 === extensionName) if (-1 === end && 1 === tokenChars[code]) -1 === start && (start = i);
|
|
203
|
+
else if (0 !== i && (0x20 === code || 0x09 === code)) -1 === end && -1 !== start && (end = i);
|
|
204
|
+
else if (0x3b === code || 0x2c === code) {
|
|
205
|
+
if (-1 === start) throw SyntaxError(`Unexpected character at index ${i}`);
|
|
206
|
+
-1 === end && (end = i);
|
|
207
|
+
let name = header.slice(start, end);
|
|
208
|
+
0x2c === code ? (push(offers, name, params), params = Object.create(null)) : extensionName = name, start = end = -1;
|
|
209
|
+
} else throw SyntaxError(`Unexpected character at index ${i}`);
|
|
210
|
+
else if (void 0 === paramName) if (-1 === end && 1 === tokenChars[code]) -1 === start && (start = i);
|
|
211
|
+
else if (0x20 === code || 0x09 === code) -1 === end && -1 !== start && (end = i);
|
|
212
|
+
else if (0x3b === code || 0x2c === code) {
|
|
213
|
+
if (-1 === start) throw SyntaxError(`Unexpected character at index ${i}`);
|
|
214
|
+
-1 === end && (end = i), push(params, header.slice(start, end), !0), 0x2c === code && (push(offers, extensionName, params), params = Object.create(null), extensionName = void 0), start = end = -1;
|
|
215
|
+
} else if (0x3d === code && -1 !== start && -1 === end) paramName = header.slice(start, i), start = end = -1;
|
|
216
|
+
else throw SyntaxError(`Unexpected character at index ${i}`);
|
|
217
|
+
else if (isEscaping) {
|
|
218
|
+
if (1 !== tokenChars[code]) throw SyntaxError(`Unexpected character at index ${i}`);
|
|
219
|
+
-1 === start ? start = i : mustUnescape || (mustUnescape = !0), isEscaping = !1;
|
|
220
|
+
} else if (inQuotes) if (1 === tokenChars[code]) -1 === start && (start = i);
|
|
221
|
+
else if (0x22 === code && -1 !== start) inQuotes = !1, end = i;
|
|
222
|
+
else if (0x5c === code) isEscaping = !0;
|
|
223
|
+
else throw SyntaxError(`Unexpected character at index ${i}`);
|
|
224
|
+
else if (0x22 === code && 0x3d === header.charCodeAt(i - 1)) inQuotes = !0;
|
|
225
|
+
else if (-1 === end && 1 === tokenChars[code]) -1 === start && (start = i);
|
|
226
|
+
else if (-1 !== start && (0x20 === code || 0x09 === code)) -1 === end && (end = i);
|
|
227
|
+
else if (0x3b === code || 0x2c === code) {
|
|
228
|
+
if (-1 === start) throw SyntaxError(`Unexpected character at index ${i}`);
|
|
229
|
+
-1 === end && (end = i);
|
|
230
|
+
let value = header.slice(start, end);
|
|
231
|
+
mustUnescape && (value = value.replace(/\\/g, ''), mustUnescape = !1), push(params, paramName, value), 0x2c === code && (push(offers, extensionName, params), params = Object.create(null), extensionName = void 0), paramName = void 0, start = end = -1;
|
|
232
|
+
} else throw SyntaxError(`Unexpected character at index ${i}`);
|
|
233
|
+
if (-1 === start || inQuotes || 0x20 === code || 0x09 === code) throw SyntaxError('Unexpected end of input');
|
|
234
|
+
-1 === end && (end = i);
|
|
235
|
+
let token = header.slice(start, end);
|
|
236
|
+
return void 0 === extensionName ? push(offers, token, params) : (void 0 === paramName ? push(params, token, !0) : mustUnescape ? push(params, paramName, token.replace(/\\/g, '')) : push(params, paramName, token), push(offers, extensionName, params)), offers;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
},
|
|
240
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js" (module) {
|
|
241
|
+
let kDone = Symbol('kDone'), kRun = Symbol('kRun');
|
|
242
|
+
module.exports = class {
|
|
243
|
+
constructor(concurrency){
|
|
244
|
+
this[kDone] = ()=>{
|
|
245
|
+
this.pending--, this[kRun]();
|
|
246
|
+
}, this.concurrency = concurrency || 1 / 0, this.jobs = [], this.pending = 0;
|
|
247
|
+
}
|
|
248
|
+
add(job) {
|
|
249
|
+
this.jobs.push(job), this[kRun]();
|
|
250
|
+
}
|
|
251
|
+
[kRun]() {
|
|
252
|
+
if (this.pending !== this.concurrency && this.jobs.length) {
|
|
253
|
+
let job = this.jobs.shift();
|
|
254
|
+
this.pending++, job(this[kDone]);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
260
|
+
let zlibLimiter, zlib = __webpack_require__("zlib?f7b9"), bufferUtil = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js"), Limiter = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/limiter.js"), { kStatusCode } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), FastBuffer = Buffer[Symbol.species], TRAILER = Buffer.from([
|
|
261
|
+
0x00,
|
|
262
|
+
0x00,
|
|
263
|
+
0xff,
|
|
264
|
+
0xff
|
|
265
|
+
]), kPerMessageDeflate = Symbol('permessage-deflate'), kTotalLength = Symbol('total-length'), kCallback = Symbol('callback'), kBuffers = Symbol('buffers'), kError = Symbol('error');
|
|
266
|
+
function deflateOnData(chunk) {
|
|
267
|
+
this[kBuffers].push(chunk), this[kTotalLength] += chunk.length;
|
|
268
|
+
}
|
|
269
|
+
function inflateOnData(chunk) {
|
|
270
|
+
(this[kTotalLength] += chunk.length, this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) ? this[kBuffers].push(chunk) : (this[kError] = RangeError('Max payload size exceeded'), this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH', this[kError][kStatusCode] = 1009, this.removeListener('data', inflateOnData), this.reset());
|
|
271
|
+
}
|
|
272
|
+
function inflateOnError(err) {
|
|
273
|
+
(this[kPerMessageDeflate]._inflate = null, this[kError]) ? this[kCallback](this[kError]) : (err[kStatusCode] = 1007, this[kCallback](err));
|
|
274
|
+
}
|
|
275
|
+
module.exports = class {
|
|
276
|
+
constructor(options, isServer, maxPayload){
|
|
277
|
+
this._maxPayload = 0 | maxPayload, this._options = options || {}, this._threshold = void 0 !== this._options.threshold ? this._options.threshold : 1024, this._isServer = !!isServer, this._deflate = null, this._inflate = null, this.params = null, zlibLimiter || (zlibLimiter = new Limiter(void 0 !== this._options.concurrencyLimit ? this._options.concurrencyLimit : 10));
|
|
278
|
+
}
|
|
279
|
+
static get extensionName() {
|
|
280
|
+
return 'permessage-deflate';
|
|
281
|
+
}
|
|
282
|
+
offer() {
|
|
283
|
+
let params = {};
|
|
284
|
+
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 : null == this._options.clientMaxWindowBits && (params.client_max_window_bits = !0), params;
|
|
285
|
+
}
|
|
286
|
+
accept(configurations) {
|
|
287
|
+
return configurations = this.normalizeParams(configurations), this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations), this.params;
|
|
288
|
+
}
|
|
289
|
+
cleanup() {
|
|
290
|
+
if (this._inflate && (this._inflate.close(), this._inflate = null), this._deflate) {
|
|
291
|
+
let callback = this._deflate[kCallback];
|
|
292
|
+
this._deflate.close(), this._deflate = null, callback && callback(Error('The deflate stream was closed while data was being processed'));
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
acceptAsServer(offers) {
|
|
296
|
+
let opts = this._options, accepted = offers.find((params)=>(!1 !== opts.serverNoContextTakeover || !params.server_no_context_takeover) && (!params.server_max_window_bits || !1 !== opts.serverMaxWindowBits && ('number' != typeof opts.serverMaxWindowBits || !(opts.serverMaxWindowBits > params.server_max_window_bits))) && ('number' != typeof opts.clientMaxWindowBits || !!params.client_max_window_bits));
|
|
297
|
+
if (!accepted) throw Error('None of the extension offers can be accepted');
|
|
298
|
+
return opts.serverNoContextTakeover && (accepted.server_no_context_takeover = !0), opts.clientNoContextTakeover && (accepted.client_no_context_takeover = !0), 'number' == typeof opts.serverMaxWindowBits && (accepted.server_max_window_bits = opts.serverMaxWindowBits), 'number' == typeof opts.clientMaxWindowBits ? accepted.client_max_window_bits = opts.clientMaxWindowBits : (!0 === accepted.client_max_window_bits || !1 === opts.clientMaxWindowBits) && delete accepted.client_max_window_bits, accepted;
|
|
299
|
+
}
|
|
300
|
+
acceptAsClient(response) {
|
|
301
|
+
let params = response[0];
|
|
302
|
+
if (!1 === this._options.clientNoContextTakeover && params.client_no_context_takeover) throw Error('Unexpected parameter "client_no_context_takeover"');
|
|
303
|
+
if (params.client_max_window_bits) {
|
|
304
|
+
if (!1 === this._options.clientMaxWindowBits || 'number' == typeof this._options.clientMaxWindowBits && params.client_max_window_bits > this._options.clientMaxWindowBits) throw Error('Unexpected or invalid parameter "client_max_window_bits"');
|
|
305
|
+
} else 'number' == typeof this._options.clientMaxWindowBits && (params.client_max_window_bits = this._options.clientMaxWindowBits);
|
|
306
|
+
return params;
|
|
307
|
+
}
|
|
308
|
+
normalizeParams(configurations) {
|
|
309
|
+
return configurations.forEach((params)=>{
|
|
310
|
+
Object.keys(params).forEach((key)=>{
|
|
311
|
+
let value = params[key];
|
|
312
|
+
if (value.length > 1) throw Error(`Parameter "${key}" must have only a single value`);
|
|
313
|
+
if (value = value[0], 'client_max_window_bits' === key) {
|
|
314
|
+
if (!0 !== value) {
|
|
315
|
+
let num = +value;
|
|
316
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) throw TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
317
|
+
value = num;
|
|
318
|
+
} else if (!this._isServer) throw TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
319
|
+
} else if ('server_max_window_bits' === key) {
|
|
320
|
+
let num = +value;
|
|
321
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) throw TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
322
|
+
value = num;
|
|
323
|
+
} else if ('client_no_context_takeover' === key || 'server_no_context_takeover' === key) {
|
|
324
|
+
if (!0 !== value) throw TypeError(`Invalid value for parameter "${key}": ${value}`);
|
|
325
|
+
} else throw Error(`Unknown parameter "${key}"`);
|
|
326
|
+
params[key] = value;
|
|
327
|
+
});
|
|
328
|
+
}), configurations;
|
|
329
|
+
}
|
|
330
|
+
decompress(data, fin, callback) {
|
|
331
|
+
zlibLimiter.add((done)=>{
|
|
332
|
+
this._decompress(data, fin, (err, result)=>{
|
|
333
|
+
done(), callback(err, result);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
compress(data, fin, callback) {
|
|
338
|
+
zlibLimiter.add((done)=>{
|
|
339
|
+
this._compress(data, fin, (err, result)=>{
|
|
340
|
+
done(), callback(err, result);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
_decompress(data, fin, callback) {
|
|
345
|
+
let endpoint = this._isServer ? 'client' : 'server';
|
|
346
|
+
if (!this._inflate) {
|
|
347
|
+
let key = `${endpoint}_max_window_bits`, windowBits = 'number' != typeof this.params[key] ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
348
|
+
this._inflate = zlib.createInflateRaw({
|
|
349
|
+
...this._options.zlibInflateOptions,
|
|
350
|
+
windowBits
|
|
351
|
+
}), this._inflate[kPerMessageDeflate] = this, this._inflate[kTotalLength] = 0, this._inflate[kBuffers] = [], this._inflate.on('error', inflateOnError), this._inflate.on('data', inflateOnData);
|
|
352
|
+
}
|
|
353
|
+
this._inflate[kCallback] = callback, this._inflate.write(data), fin && this._inflate.write(TRAILER), this._inflate.flush(()=>{
|
|
354
|
+
let err = this._inflate[kError];
|
|
355
|
+
if (err) {
|
|
356
|
+
this._inflate.close(), this._inflate = null, callback(err);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
let data = bufferUtil.concat(this._inflate[kBuffers], this._inflate[kTotalLength]);
|
|
360
|
+
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, data);
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
_compress(data, fin, callback) {
|
|
364
|
+
let endpoint = this._isServer ? 'server' : 'client';
|
|
365
|
+
if (!this._deflate) {
|
|
366
|
+
let key = `${endpoint}_max_window_bits`, windowBits = 'number' != typeof this.params[key] ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
|
|
367
|
+
this._deflate = zlib.createDeflateRaw({
|
|
368
|
+
...this._options.zlibDeflateOptions,
|
|
369
|
+
windowBits
|
|
370
|
+
}), this._deflate[kTotalLength] = 0, this._deflate[kBuffers] = [], this._deflate.on('data', deflateOnData);
|
|
371
|
+
}
|
|
372
|
+
this._deflate[kCallback] = callback, this._deflate.write(data), this._deflate.flush(zlib.Z_SYNC_FLUSH, ()=>{
|
|
373
|
+
if (!this._deflate) return;
|
|
374
|
+
let data = bufferUtil.concat(this._deflate[kBuffers], this._deflate[kTotalLength]);
|
|
375
|
+
fin && (data = new FastBuffer(data.buffer, data.byteOffset, data.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, data);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
381
|
+
let { Writable } = __webpack_require__("stream?3f22"), PerMessageDeflate = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js"), { BINARY_TYPES, EMPTY_BUFFER, kStatusCode, kWebSocket } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), { concat, toArrayBuffer, unmask } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js"), { isValidStatusCode, isValidUTF8 } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js"), FastBuffer = Buffer[Symbol.species];
|
|
382
|
+
module.exports = class extends Writable {
|
|
383
|
+
constructor(options = {}){
|
|
384
|
+
super(), this._allowSynchronousEvents = void 0 === options.allowSynchronousEvents || options.allowSynchronousEvents, this._binaryType = options.binaryType || BINARY_TYPES[0], this._extensions = options.extensions || {}, this._isServer = !!options.isServer, this._maxPayload = 0 | options.maxPayload, 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._errored = !1, this._loop = !1, this._state = 0;
|
|
385
|
+
}
|
|
386
|
+
_write(chunk, encoding, cb) {
|
|
387
|
+
if (0x08 === this._opcode && 0 == this._state) return cb();
|
|
388
|
+
this._bufferedBytes += chunk.length, this._buffers.push(chunk), this.startLoop(cb);
|
|
389
|
+
}
|
|
390
|
+
consume(n) {
|
|
391
|
+
if (this._bufferedBytes -= n, n === this._buffers[0].length) return this._buffers.shift();
|
|
392
|
+
if (n < this._buffers[0].length) {
|
|
393
|
+
let buf = this._buffers[0];
|
|
394
|
+
return this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n), new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
395
|
+
}
|
|
396
|
+
let dst = Buffer.allocUnsafe(n);
|
|
397
|
+
do {
|
|
398
|
+
let buf = this._buffers[0], offset = dst.length - n;
|
|
399
|
+
n >= buf.length ? dst.set(this._buffers.shift(), offset) : (dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset), this._buffers[0] = new FastBuffer(buf.buffer, buf.byteOffset + n, buf.length - n)), n -= buf.length;
|
|
400
|
+
}while (n > 0);
|
|
401
|
+
return dst;
|
|
402
|
+
}
|
|
403
|
+
startLoop(cb) {
|
|
404
|
+
this._loop = !0;
|
|
405
|
+
do switch(this._state){
|
|
406
|
+
case 0:
|
|
407
|
+
this.getInfo(cb);
|
|
408
|
+
break;
|
|
409
|
+
case 1:
|
|
410
|
+
this.getPayloadLength16(cb);
|
|
411
|
+
break;
|
|
412
|
+
case 2:
|
|
413
|
+
this.getPayloadLength64(cb);
|
|
414
|
+
break;
|
|
415
|
+
case 3:
|
|
416
|
+
this.getMask();
|
|
417
|
+
break;
|
|
418
|
+
case 4:
|
|
419
|
+
this.getData(cb);
|
|
420
|
+
break;
|
|
421
|
+
case 5:
|
|
422
|
+
case 6:
|
|
423
|
+
this._loop = !1;
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
while (this._loop);
|
|
427
|
+
this._errored || cb();
|
|
428
|
+
}
|
|
429
|
+
getInfo(cb) {
|
|
430
|
+
if (this._bufferedBytes < 2) {
|
|
431
|
+
this._loop = !1;
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
let buf = this.consume(2);
|
|
435
|
+
if ((0x30 & buf[0]) != 0x00) return void cb(this.createError(RangeError, 'RSV2 and RSV3 must be clear', !0, 1002, 'WS_ERR_UNEXPECTED_RSV_2_3'));
|
|
436
|
+
let compressed = (0x40 & buf[0]) == 0x40;
|
|
437
|
+
if (compressed && !this._extensions[PerMessageDeflate.extensionName]) return void cb(this.createError(RangeError, 'RSV1 must be clear', !0, 1002, 'WS_ERR_UNEXPECTED_RSV_1'));
|
|
438
|
+
if (this._fin = (0x80 & buf[0]) == 0x80, this._opcode = 0x0f & buf[0], this._payloadLength = 0x7f & buf[1], 0x00 === this._opcode) {
|
|
439
|
+
if (compressed) return void cb(this.createError(RangeError, 'RSV1 must be clear', !0, 1002, 'WS_ERR_UNEXPECTED_RSV_1'));
|
|
440
|
+
if (!this._fragmented) return void cb(this.createError(RangeError, 'invalid opcode 0', !0, 1002, 'WS_ERR_INVALID_OPCODE'));
|
|
441
|
+
this._opcode = this._fragmented;
|
|
442
|
+
} else if (0x01 === this._opcode || 0x02 === this._opcode) {
|
|
443
|
+
if (this._fragmented) return void cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, !0, 1002, 'WS_ERR_INVALID_OPCODE'));
|
|
444
|
+
this._compressed = compressed;
|
|
445
|
+
} else {
|
|
446
|
+
if (!(this._opcode > 0x07) || !(this._opcode < 0x0b)) return void cb(this.createError(RangeError, `invalid opcode ${this._opcode}`, !0, 1002, 'WS_ERR_INVALID_OPCODE'));
|
|
447
|
+
if (!this._fin) return void cb(this.createError(RangeError, 'FIN must be set', !0, 1002, 'WS_ERR_EXPECTED_FIN'));
|
|
448
|
+
if (compressed) return void cb(this.createError(RangeError, 'RSV1 must be clear', !0, 1002, 'WS_ERR_UNEXPECTED_RSV_1'));
|
|
449
|
+
if (this._payloadLength > 0x7d || 0x08 === this._opcode && 1 === this._payloadLength) return void cb(this.createError(RangeError, `invalid payload length ${this._payloadLength}`, !0, 1002, 'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'));
|
|
450
|
+
}
|
|
451
|
+
if (this._fin || this._fragmented || (this._fragmented = this._opcode), this._masked = (0x80 & buf[1]) == 0x80, this._isServer) {
|
|
452
|
+
if (!this._masked) return void cb(this.createError(RangeError, 'MASK must be set', !0, 1002, 'WS_ERR_EXPECTED_MASK'));
|
|
453
|
+
} else if (this._masked) return void cb(this.createError(RangeError, 'MASK must be clear', !0, 1002, 'WS_ERR_UNEXPECTED_MASK'));
|
|
454
|
+
126 === this._payloadLength ? this._state = 1 : 127 === this._payloadLength ? this._state = 2 : this.haveLength(cb);
|
|
455
|
+
}
|
|
456
|
+
getPayloadLength16(cb) {
|
|
457
|
+
if (this._bufferedBytes < 2) {
|
|
458
|
+
this._loop = !1;
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
this._payloadLength = this.consume(2).readUInt16BE(0), this.haveLength(cb);
|
|
462
|
+
}
|
|
463
|
+
getPayloadLength64(cb) {
|
|
464
|
+
if (this._bufferedBytes < 8) {
|
|
465
|
+
this._loop = !1;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
let buf = this.consume(8), num = buf.readUInt32BE(0);
|
|
469
|
+
num > 2097151 ? cb(this.createError(RangeError, 'Unsupported WebSocket frame: payload length > 2^53 - 1', !1, 1009, 'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH')) : (this._payloadLength = 4294967296 * num + buf.readUInt32BE(4), this.haveLength(cb));
|
|
470
|
+
}
|
|
471
|
+
haveLength(cb) {
|
|
472
|
+
this._payloadLength && this._opcode < 0x08 && (this._totalPayloadLength += this._payloadLength, this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) ? cb(this.createError(RangeError, 'Max payload size exceeded', !1, 1009, 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH')) : this._masked ? this._state = 3 : this._state = 4;
|
|
473
|
+
}
|
|
474
|
+
getMask() {
|
|
475
|
+
if (this._bufferedBytes < 4) {
|
|
476
|
+
this._loop = !1;
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
this._mask = this.consume(4), this._state = 4;
|
|
480
|
+
}
|
|
481
|
+
getData(cb) {
|
|
482
|
+
let data = EMPTY_BUFFER;
|
|
483
|
+
if (this._payloadLength) {
|
|
484
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
485
|
+
this._loop = !1;
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
data = this.consume(this._payloadLength), this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) != 0 && unmask(data, this._mask);
|
|
489
|
+
}
|
|
490
|
+
if (this._opcode > 0x07) return void this.controlMessage(data, cb);
|
|
491
|
+
if (this._compressed) {
|
|
492
|
+
this._state = 5, this.decompress(data, cb);
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
data.length && (this._messageLength = this._totalPayloadLength, this._fragments.push(data)), this.dataMessage(cb);
|
|
496
|
+
}
|
|
497
|
+
decompress(data, cb) {
|
|
498
|
+
this._extensions[PerMessageDeflate.extensionName].decompress(data, this._fin, (err, buf)=>{
|
|
499
|
+
if (err) return cb(err);
|
|
500
|
+
if (buf.length) {
|
|
501
|
+
if (this._messageLength += buf.length, this._messageLength > this._maxPayload && this._maxPayload > 0) return void cb(this.createError(RangeError, 'Max payload size exceeded', !1, 1009, 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'));
|
|
502
|
+
this._fragments.push(buf);
|
|
503
|
+
}
|
|
504
|
+
this.dataMessage(cb), 0 === this._state && this.startLoop(cb);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
dataMessage(cb) {
|
|
508
|
+
if (!this._fin) {
|
|
509
|
+
this._state = 0;
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
let messageLength = this._messageLength, fragments = this._fragments;
|
|
513
|
+
if (this._totalPayloadLength = 0, this._messageLength = 0, this._fragmented = 0, this._fragments = [], 2 === this._opcode) {
|
|
514
|
+
let data;
|
|
515
|
+
data = 'nodebuffer' === this._binaryType ? concat(fragments, messageLength) : 'arraybuffer' === this._binaryType ? toArrayBuffer(concat(fragments, messageLength)) : 'blob' === this._binaryType ? new Blob(fragments) : fragments, this._allowSynchronousEvents ? (this.emit('message', data, !0), this._state = 0) : (this._state = 6, setImmediate(()=>{
|
|
516
|
+
this.emit('message', data, !0), this._state = 0, this.startLoop(cb);
|
|
517
|
+
}));
|
|
518
|
+
} else {
|
|
519
|
+
let buf = concat(fragments, messageLength);
|
|
520
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) return void cb(this.createError(Error, 'invalid UTF-8 sequence', !0, 1007, 'WS_ERR_INVALID_UTF8'));
|
|
521
|
+
5 === this._state || this._allowSynchronousEvents ? (this.emit('message', buf, !1), this._state = 0) : (this._state = 6, setImmediate(()=>{
|
|
522
|
+
this.emit('message', buf, !1), this._state = 0, this.startLoop(cb);
|
|
523
|
+
}));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
controlMessage(data, cb) {
|
|
527
|
+
if (0x08 === this._opcode) {
|
|
528
|
+
if (0 === data.length) this._loop = !1, this.emit('conclude', 1005, EMPTY_BUFFER), this.end();
|
|
529
|
+
else {
|
|
530
|
+
let code = data.readUInt16BE(0);
|
|
531
|
+
if (!isValidStatusCode(code)) return void cb(this.createError(RangeError, `invalid status code ${code}`, !0, 1002, 'WS_ERR_INVALID_CLOSE_CODE'));
|
|
532
|
+
let buf = new FastBuffer(data.buffer, data.byteOffset + 2, data.length - 2);
|
|
533
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) return void cb(this.createError(Error, 'invalid UTF-8 sequence', !0, 1007, 'WS_ERR_INVALID_UTF8'));
|
|
534
|
+
this._loop = !1, this.emit('conclude', code, buf), this.end();
|
|
535
|
+
}
|
|
536
|
+
this._state = 0;
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
this._allowSynchronousEvents ? (this.emit(0x09 === this._opcode ? 'ping' : 'pong', data), this._state = 0) : (this._state = 6, setImmediate(()=>{
|
|
540
|
+
this.emit(0x09 === this._opcode ? 'ping' : 'pong', data), this._state = 0, this.startLoop(cb);
|
|
541
|
+
}));
|
|
542
|
+
}
|
|
543
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
544
|
+
this._loop = !1, this._errored = !0;
|
|
545
|
+
let err = new ErrorCtor(prefix ? `Invalid WebSocket frame: ${message}` : message);
|
|
546
|
+
return Error.captureStackTrace(err, this.createError), err.code = errorCode, err[kStatusCode] = statusCode, err;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
},
|
|
550
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
551
|
+
let randomPool, { Duplex } = __webpack_require__("stream?3f22"), { randomFillSync } = __webpack_require__("crypto"), PerMessageDeflate = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js"), { EMPTY_BUFFER, kWebSocket, NOOP } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), { isBlob, isValidStatusCode } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js"), { mask: applyMask, toBuffer } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js"), kByteLength = Symbol('kByteLength'), maskBuffer = Buffer.alloc(4), randomPoolPointer = 8192;
|
|
552
|
+
class Sender {
|
|
553
|
+
constructor(socket, extensions, generateMask){
|
|
554
|
+
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._queue = [], this._state = 0, this.onerror = NOOP, this[kWebSocket] = void 0;
|
|
555
|
+
}
|
|
556
|
+
static frame(data, options) {
|
|
557
|
+
let mask, dataLength, merge = !1, offset = 2, skipMasking = !1;
|
|
558
|
+
options.mask && (mask = options.maskBuffer || maskBuffer, options.generateMask ? options.generateMask(mask) : (8192 === randomPoolPointer && (void 0 === randomPool && (randomPool = Buffer.alloc(8192)), randomFillSync(randomPool, 0, 8192), randomPoolPointer = 0), mask[0] = randomPool[randomPoolPointer++], mask[1] = randomPool[randomPoolPointer++], mask[2] = randomPool[randomPoolPointer++], mask[3] = randomPool[randomPoolPointer++]), skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) == 0, offset = 6), 'string' == typeof data ? dataLength = (!options.mask || skipMasking) && void 0 !== options[kByteLength] ? options[kByteLength] : (data = Buffer.from(data)).length : (dataLength = data.length, merge = options.mask && options.readOnly && !skipMasking);
|
|
559
|
+
let payloadLength = dataLength;
|
|
560
|
+
dataLength >= 65536 ? (offset += 8, payloadLength = 127) : dataLength > 125 && (offset += 2, payloadLength = 126);
|
|
561
|
+
let target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
562
|
+
return (target[0] = options.fin ? 0x80 | options.opcode : options.opcode, options.rsv1 && (target[0] |= 0x40), target[1] = payloadLength, 126 === payloadLength ? target.writeUInt16BE(dataLength, 2) : 127 === payloadLength && (target[2] = target[3] = 0, target.writeUIntBE(dataLength, 4, 6)), options.mask) ? (target[1] |= 0x80, target[offset - 4] = mask[0], target[offset - 3] = mask[1], target[offset - 2] = mask[2], target[offset - 1] = mask[3], skipMasking) ? [
|
|
563
|
+
target,
|
|
564
|
+
data
|
|
565
|
+
] : merge ? (applyMask(data, mask, target, offset, dataLength), [
|
|
566
|
+
target
|
|
567
|
+
]) : (applyMask(data, mask, data, 0, dataLength), [
|
|
568
|
+
target,
|
|
569
|
+
data
|
|
570
|
+
]) : [
|
|
571
|
+
target,
|
|
572
|
+
data
|
|
573
|
+
];
|
|
574
|
+
}
|
|
575
|
+
close(code, data, mask, cb) {
|
|
576
|
+
let buf;
|
|
577
|
+
if (void 0 === code) buf = EMPTY_BUFFER;
|
|
578
|
+
else if ('number' == typeof code && isValidStatusCode(code)) if (void 0 !== data && data.length) {
|
|
579
|
+
let length = Buffer.byteLength(data);
|
|
580
|
+
if (length > 123) throw RangeError('The message must not be greater than 123 bytes');
|
|
581
|
+
(buf = Buffer.allocUnsafe(2 + length)).writeUInt16BE(code, 0), 'string' == typeof data ? buf.write(data, 2) : buf.set(data, 2);
|
|
582
|
+
} else (buf = Buffer.allocUnsafe(2)).writeUInt16BE(code, 0);
|
|
583
|
+
else throw TypeError('First argument must be a valid error code number');
|
|
584
|
+
let options = {
|
|
585
|
+
[kByteLength]: buf.length,
|
|
586
|
+
fin: !0,
|
|
587
|
+
generateMask: this._generateMask,
|
|
588
|
+
mask,
|
|
589
|
+
maskBuffer: this._maskBuffer,
|
|
590
|
+
opcode: 0x08,
|
|
591
|
+
readOnly: !1,
|
|
592
|
+
rsv1: !1
|
|
593
|
+
};
|
|
594
|
+
0 !== this._state ? this.enqueue([
|
|
595
|
+
this.dispatch,
|
|
596
|
+
buf,
|
|
597
|
+
!1,
|
|
598
|
+
options,
|
|
599
|
+
cb
|
|
600
|
+
]) : this.sendFrame(Sender.frame(buf, options), cb);
|
|
601
|
+
}
|
|
602
|
+
ping(data, mask, cb) {
|
|
603
|
+
let byteLength, readOnly;
|
|
604
|
+
if ('string' == typeof data ? (byteLength = Buffer.byteLength(data), readOnly = !1) : isBlob(data) ? (byteLength = data.size, readOnly = !1) : (byteLength = (data = toBuffer(data)).length, readOnly = toBuffer.readOnly), byteLength > 125) throw RangeError('The data size must not be greater than 125 bytes');
|
|
605
|
+
let options = {
|
|
606
|
+
[kByteLength]: byteLength,
|
|
607
|
+
fin: !0,
|
|
608
|
+
generateMask: this._generateMask,
|
|
609
|
+
mask,
|
|
610
|
+
maskBuffer: this._maskBuffer,
|
|
611
|
+
opcode: 0x09,
|
|
612
|
+
readOnly,
|
|
613
|
+
rsv1: !1
|
|
614
|
+
};
|
|
615
|
+
isBlob(data) ? 0 !== this._state ? this.enqueue([
|
|
616
|
+
this.getBlobData,
|
|
617
|
+
data,
|
|
618
|
+
!1,
|
|
619
|
+
options,
|
|
620
|
+
cb
|
|
621
|
+
]) : this.getBlobData(data, !1, options, cb) : 0 !== this._state ? this.enqueue([
|
|
622
|
+
this.dispatch,
|
|
623
|
+
data,
|
|
624
|
+
!1,
|
|
625
|
+
options,
|
|
626
|
+
cb
|
|
627
|
+
]) : this.sendFrame(Sender.frame(data, options), cb);
|
|
628
|
+
}
|
|
629
|
+
pong(data, mask, cb) {
|
|
630
|
+
let byteLength, readOnly;
|
|
631
|
+
if ('string' == typeof data ? (byteLength = Buffer.byteLength(data), readOnly = !1) : isBlob(data) ? (byteLength = data.size, readOnly = !1) : (byteLength = (data = toBuffer(data)).length, readOnly = toBuffer.readOnly), byteLength > 125) throw RangeError('The data size must not be greater than 125 bytes');
|
|
632
|
+
let options = {
|
|
633
|
+
[kByteLength]: byteLength,
|
|
634
|
+
fin: !0,
|
|
635
|
+
generateMask: this._generateMask,
|
|
636
|
+
mask,
|
|
637
|
+
maskBuffer: this._maskBuffer,
|
|
638
|
+
opcode: 0x0a,
|
|
639
|
+
readOnly,
|
|
640
|
+
rsv1: !1
|
|
641
|
+
};
|
|
642
|
+
isBlob(data) ? 0 !== this._state ? this.enqueue([
|
|
643
|
+
this.getBlobData,
|
|
644
|
+
data,
|
|
645
|
+
!1,
|
|
646
|
+
options,
|
|
647
|
+
cb
|
|
648
|
+
]) : this.getBlobData(data, !1, options, cb) : 0 !== this._state ? this.enqueue([
|
|
649
|
+
this.dispatch,
|
|
650
|
+
data,
|
|
651
|
+
!1,
|
|
652
|
+
options,
|
|
653
|
+
cb
|
|
654
|
+
]) : this.sendFrame(Sender.frame(data, options), cb);
|
|
655
|
+
}
|
|
656
|
+
send(data, options, cb) {
|
|
657
|
+
let byteLength, readOnly, perMessageDeflate = this._extensions[PerMessageDeflate.extensionName], opcode = options.binary ? 2 : 1, rsv1 = options.compress;
|
|
658
|
+
'string' == typeof data ? (byteLength = Buffer.byteLength(data), readOnly = !1) : isBlob(data) ? (byteLength = data.size, readOnly = !1) : (byteLength = (data = toBuffer(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);
|
|
659
|
+
let opts = {
|
|
660
|
+
[kByteLength]: byteLength,
|
|
661
|
+
fin: options.fin,
|
|
662
|
+
generateMask: this._generateMask,
|
|
663
|
+
mask: options.mask,
|
|
664
|
+
maskBuffer: this._maskBuffer,
|
|
665
|
+
opcode,
|
|
666
|
+
readOnly,
|
|
667
|
+
rsv1
|
|
668
|
+
};
|
|
669
|
+
isBlob(data) ? 0 !== this._state ? this.enqueue([
|
|
670
|
+
this.getBlobData,
|
|
671
|
+
data,
|
|
672
|
+
this._compress,
|
|
673
|
+
opts,
|
|
674
|
+
cb
|
|
675
|
+
]) : this.getBlobData(data, this._compress, opts, cb) : 0 !== this._state ? this.enqueue([
|
|
676
|
+
this.dispatch,
|
|
677
|
+
data,
|
|
678
|
+
this._compress,
|
|
679
|
+
opts,
|
|
680
|
+
cb
|
|
681
|
+
]) : this.dispatch(data, this._compress, opts, cb);
|
|
682
|
+
}
|
|
683
|
+
getBlobData(blob, compress, options, cb) {
|
|
684
|
+
this._bufferedBytes += options[kByteLength], this._state = 2, blob.arrayBuffer().then((arrayBuffer)=>{
|
|
685
|
+
if (this._socket.destroyed) {
|
|
686
|
+
let err = Error('The socket was closed while the blob was being read');
|
|
687
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
this._bufferedBytes -= options[kByteLength];
|
|
691
|
+
let data = toBuffer(arrayBuffer);
|
|
692
|
+
compress ? this.dispatch(data, compress, options, cb) : (this._state = 0, this.sendFrame(Sender.frame(data, options), cb), this.dequeue());
|
|
693
|
+
}).catch((err)=>{
|
|
694
|
+
process.nextTick(onError, this, err, cb);
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
dispatch(data, compress, options, cb) {
|
|
698
|
+
if (!compress) return void this.sendFrame(Sender.frame(data, options), cb);
|
|
699
|
+
let perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
|
|
700
|
+
this._bufferedBytes += options[kByteLength], this._state = 1, perMessageDeflate.compress(data, options.fin, (_, buf)=>{
|
|
701
|
+
this._socket.destroyed ? callCallbacks(this, Error('The socket was closed while data was being compressed'), cb) : (this._bufferedBytes -= options[kByteLength], this._state = 0, options.readOnly = !1, this.sendFrame(Sender.frame(buf, options), cb), this.dequeue());
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
dequeue() {
|
|
705
|
+
for(; 0 === this._state && this._queue.length;){
|
|
706
|
+
let params = this._queue.shift();
|
|
707
|
+
this._bufferedBytes -= params[3][kByteLength], Reflect.apply(params[0], this, params.slice(1));
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
enqueue(params) {
|
|
711
|
+
this._bufferedBytes += params[3][kByteLength], this._queue.push(params);
|
|
712
|
+
}
|
|
713
|
+
sendFrame(list, cb) {
|
|
714
|
+
2 === list.length ? (this._socket.cork(), this._socket.write(list[0]), this._socket.write(list[1], cb), this._socket.uncork()) : this._socket.write(list[0], cb);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
function callCallbacks(sender, err, cb) {
|
|
718
|
+
'function' == typeof cb && cb(err);
|
|
719
|
+
for(let i = 0; i < sender._queue.length; i++){
|
|
720
|
+
let params = sender._queue[i], callback = params[params.length - 1];
|
|
721
|
+
'function' == typeof callback && callback(err);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
function onError(sender, err, cb) {
|
|
725
|
+
callCallbacks(sender, err, cb), sender.onerror(err);
|
|
726
|
+
}
|
|
727
|
+
module.exports = Sender;
|
|
728
|
+
},
|
|
729
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
730
|
+
__webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js");
|
|
731
|
+
let { Duplex } = __webpack_require__("stream?3f22");
|
|
732
|
+
function emitClose(stream) {
|
|
733
|
+
stream.emit('close');
|
|
734
|
+
}
|
|
735
|
+
function duplexOnEnd() {
|
|
736
|
+
!this.destroyed && this._writableState.finished && this.destroy();
|
|
737
|
+
}
|
|
738
|
+
function duplexOnError(err) {
|
|
739
|
+
this.removeListener('error', duplexOnError), this.destroy(), 0 === this.listenerCount('error') && this.emit('error', err);
|
|
740
|
+
}
|
|
741
|
+
module.exports = function createWebSocketStream(ws, options) {
|
|
742
|
+
let terminateOnDestroy = !0, duplex = new Duplex({
|
|
743
|
+
...options,
|
|
744
|
+
autoDestroy: !1,
|
|
745
|
+
emitClose: !1,
|
|
746
|
+
objectMode: !1,
|
|
747
|
+
writableObjectMode: !1
|
|
748
|
+
});
|
|
749
|
+
return ws.on('message', function message(msg, isBinary) {
|
|
750
|
+
let data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
|
|
751
|
+
duplex.push(data) || ws.pause();
|
|
752
|
+
}), ws.once('error', function error(err) {
|
|
753
|
+
duplex.destroyed || (terminateOnDestroy = !1, duplex.destroy(err));
|
|
754
|
+
}), ws.once('close', function close() {
|
|
755
|
+
duplex.destroyed || duplex.push(null);
|
|
756
|
+
}), duplex._destroy = function(err, callback) {
|
|
757
|
+
if (ws.readyState === ws.CLOSED) {
|
|
758
|
+
callback(err), process.nextTick(emitClose, duplex);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
let called = !1;
|
|
762
|
+
ws.once('error', function error(err) {
|
|
763
|
+
called = !0, callback(err);
|
|
764
|
+
}), ws.once('close', function close() {
|
|
765
|
+
called || callback(err), process.nextTick(emitClose, duplex);
|
|
766
|
+
}), terminateOnDestroy && ws.terminate();
|
|
767
|
+
}, duplex._final = function(callback) {
|
|
768
|
+
ws.readyState === ws.CONNECTING ? ws.once('open', function open() {
|
|
769
|
+
duplex._final(callback);
|
|
770
|
+
}) : null !== ws._socket && (ws._socket._writableState.finished ? (callback(), duplex._readableState.endEmitted && duplex.destroy()) : (ws._socket.once('finish', function finish() {
|
|
771
|
+
callback();
|
|
772
|
+
}), ws.close()));
|
|
773
|
+
}, duplex._read = function() {
|
|
774
|
+
ws.isPaused && ws.resume();
|
|
775
|
+
}, duplex._write = function(chunk, encoding, callback) {
|
|
776
|
+
ws.readyState === ws.CONNECTING ? ws.once('open', function open() {
|
|
777
|
+
duplex._write(chunk, encoding, callback);
|
|
778
|
+
}) : ws.send(chunk, callback);
|
|
779
|
+
}, duplex.on('end', duplexOnEnd), duplex.on('error', duplexOnError), duplex;
|
|
780
|
+
};
|
|
781
|
+
},
|
|
782
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
783
|
+
let { tokenChars } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js");
|
|
784
|
+
module.exports = {
|
|
785
|
+
parse: function parse(header) {
|
|
786
|
+
let protocols = new Set(), start = -1, end = -1, i = 0;
|
|
787
|
+
for(; i < header.length; i++){
|
|
788
|
+
let code = header.charCodeAt(i);
|
|
789
|
+
if (-1 === end && 1 === tokenChars[code]) -1 === start && (start = i);
|
|
790
|
+
else if (0 !== i && (0x20 === code || 0x09 === code)) -1 === end && -1 !== start && (end = i);
|
|
791
|
+
else if (0x2c === code) {
|
|
792
|
+
if (-1 === start) throw SyntaxError(`Unexpected character at index ${i}`);
|
|
793
|
+
-1 === end && (end = i);
|
|
794
|
+
let protocol = header.slice(start, end);
|
|
795
|
+
if (protocols.has(protocol)) throw SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
796
|
+
protocols.add(protocol), start = end = -1;
|
|
797
|
+
} else throw SyntaxError(`Unexpected character at index ${i}`);
|
|
798
|
+
}
|
|
799
|
+
if (-1 === start || -1 !== end) throw SyntaxError('Unexpected end of input');
|
|
800
|
+
let protocol = header.slice(start, i);
|
|
801
|
+
if (protocols.has(protocol)) throw SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
802
|
+
return protocols.add(protocol), protocols;
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
},
|
|
806
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
807
|
+
let { isUtf8 } = __webpack_require__("buffer"), { hasBlob } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js");
|
|
808
|
+
function _isValidUTF8(buf) {
|
|
809
|
+
let len = buf.length, i = 0;
|
|
810
|
+
for(; i < len;)if ((0x80 & buf[i]) == 0) i++;
|
|
811
|
+
else if ((0xe0 & buf[i]) == 0xc0) {
|
|
812
|
+
if (i + 1 === len || (0xc0 & buf[i + 1]) != 0x80 || (0xfe & buf[i]) == 0xc0) return !1;
|
|
813
|
+
i += 2;
|
|
814
|
+
} else if ((0xf0 & buf[i]) == 0xe0) {
|
|
815
|
+
if (i + 2 >= len || (0xc0 & buf[i + 1]) != 0x80 || (0xc0 & buf[i + 2]) != 0x80 || 0xe0 === buf[i] && (0xe0 & buf[i + 1]) == 0x80 || 0xed === buf[i] && (0xe0 & buf[i + 1]) == 0xa0) return !1;
|
|
816
|
+
i += 3;
|
|
817
|
+
} else {
|
|
818
|
+
if ((0xf8 & buf[i]) != 0xf0 || i + 3 >= len || (0xc0 & buf[i + 1]) != 0x80 || (0xc0 & buf[i + 2]) != 0x80 || (0xc0 & buf[i + 3]) != 0x80 || 0xf0 === buf[i] && (0xf0 & buf[i + 1]) == 0x80 || 0xf4 === buf[i] && buf[i + 1] > 0x8f || buf[i] > 0xf4) return !1;
|
|
819
|
+
i += 4;
|
|
820
|
+
}
|
|
821
|
+
return !0;
|
|
822
|
+
}
|
|
823
|
+
module.exports = {
|
|
824
|
+
isBlob: function isBlob(value) {
|
|
825
|
+
return hasBlob && 'object' == typeof value && 'function' == typeof value.arrayBuffer && 'string' == typeof value.type && 'function' == typeof value.stream && ('Blob' === value[Symbol.toStringTag] || 'File' === value[Symbol.toStringTag]);
|
|
826
|
+
},
|
|
827
|
+
isValidStatusCode: function isValidStatusCode(code) {
|
|
828
|
+
return code >= 1000 && code <= 1014 && 1004 !== code && 1005 !== code && 1006 !== code || code >= 3000 && code <= 4999;
|
|
829
|
+
},
|
|
830
|
+
isValidUTF8: _isValidUTF8,
|
|
831
|
+
tokenChars: [
|
|
832
|
+
0,
|
|
833
|
+
0,
|
|
834
|
+
0,
|
|
835
|
+
0,
|
|
836
|
+
0,
|
|
837
|
+
0,
|
|
838
|
+
0,
|
|
839
|
+
0,
|
|
840
|
+
0,
|
|
841
|
+
0,
|
|
842
|
+
0,
|
|
843
|
+
0,
|
|
844
|
+
0,
|
|
845
|
+
0,
|
|
846
|
+
0,
|
|
847
|
+
0,
|
|
848
|
+
0,
|
|
849
|
+
0,
|
|
850
|
+
0,
|
|
851
|
+
0,
|
|
852
|
+
0,
|
|
853
|
+
0,
|
|
854
|
+
0,
|
|
855
|
+
0,
|
|
856
|
+
0,
|
|
857
|
+
0,
|
|
858
|
+
0,
|
|
859
|
+
0,
|
|
860
|
+
0,
|
|
861
|
+
0,
|
|
862
|
+
0,
|
|
863
|
+
0,
|
|
864
|
+
0,
|
|
865
|
+
1,
|
|
866
|
+
0,
|
|
867
|
+
1,
|
|
868
|
+
1,
|
|
869
|
+
1,
|
|
870
|
+
1,
|
|
871
|
+
1,
|
|
872
|
+
0,
|
|
873
|
+
0,
|
|
874
|
+
1,
|
|
875
|
+
1,
|
|
876
|
+
0,
|
|
877
|
+
1,
|
|
878
|
+
1,
|
|
879
|
+
0,
|
|
880
|
+
1,
|
|
881
|
+
1,
|
|
882
|
+
1,
|
|
883
|
+
1,
|
|
884
|
+
1,
|
|
885
|
+
1,
|
|
886
|
+
1,
|
|
887
|
+
1,
|
|
888
|
+
1,
|
|
889
|
+
1,
|
|
890
|
+
0,
|
|
891
|
+
0,
|
|
892
|
+
0,
|
|
893
|
+
0,
|
|
894
|
+
0,
|
|
895
|
+
0,
|
|
896
|
+
0,
|
|
897
|
+
1,
|
|
898
|
+
1,
|
|
899
|
+
1,
|
|
900
|
+
1,
|
|
901
|
+
1,
|
|
902
|
+
1,
|
|
903
|
+
1,
|
|
904
|
+
1,
|
|
905
|
+
1,
|
|
906
|
+
1,
|
|
907
|
+
1,
|
|
908
|
+
1,
|
|
909
|
+
1,
|
|
910
|
+
1,
|
|
911
|
+
1,
|
|
912
|
+
1,
|
|
913
|
+
1,
|
|
914
|
+
1,
|
|
915
|
+
1,
|
|
916
|
+
1,
|
|
917
|
+
1,
|
|
918
|
+
1,
|
|
919
|
+
1,
|
|
920
|
+
1,
|
|
921
|
+
1,
|
|
922
|
+
1,
|
|
923
|
+
0,
|
|
924
|
+
0,
|
|
925
|
+
0,
|
|
926
|
+
1,
|
|
927
|
+
1,
|
|
928
|
+
1,
|
|
929
|
+
1,
|
|
930
|
+
1,
|
|
931
|
+
1,
|
|
932
|
+
1,
|
|
933
|
+
1,
|
|
934
|
+
1,
|
|
935
|
+
1,
|
|
936
|
+
1,
|
|
937
|
+
1,
|
|
938
|
+
1,
|
|
939
|
+
1,
|
|
940
|
+
1,
|
|
941
|
+
1,
|
|
942
|
+
1,
|
|
943
|
+
1,
|
|
944
|
+
1,
|
|
945
|
+
1,
|
|
946
|
+
1,
|
|
947
|
+
1,
|
|
948
|
+
1,
|
|
949
|
+
1,
|
|
950
|
+
1,
|
|
951
|
+
1,
|
|
952
|
+
1,
|
|
953
|
+
1,
|
|
954
|
+
1,
|
|
955
|
+
0,
|
|
956
|
+
1,
|
|
957
|
+
0,
|
|
958
|
+
1,
|
|
959
|
+
0
|
|
960
|
+
]
|
|
961
|
+
}, isUtf8 && (module.exports.isValidUTF8 = function(buf) {
|
|
962
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
963
|
+
});
|
|
964
|
+
},
|
|
965
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
966
|
+
let EventEmitter = __webpack_require__("events"), http = __webpack_require__("http?4112"), { Duplex } = __webpack_require__("stream?3f22"), { createHash } = __webpack_require__("crypto"), extension = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js"), PerMessageDeflate = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js"), subprotocol = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/subprotocol.js"), WebSocket = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js"), { CLOSE_TIMEOUT, GUID, kWebSocket } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
967
|
+
function addListeners(server, map) {
|
|
968
|
+
for (let event of Object.keys(map))server.on(event, map[event]);
|
|
969
|
+
return function removeListeners() {
|
|
970
|
+
for (let event of Object.keys(map))server.removeListener(event, map[event]);
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
function emitClose(server) {
|
|
974
|
+
server._state = 2, server.emit('close');
|
|
975
|
+
}
|
|
976
|
+
function socketOnError() {
|
|
977
|
+
this.destroy();
|
|
978
|
+
}
|
|
979
|
+
function abortHandshake(socket, code, message, headers) {
|
|
980
|
+
message = message || http.STATUS_CODES[code], headers = {
|
|
981
|
+
Connection: 'close',
|
|
982
|
+
'Content-Type': 'text/html',
|
|
983
|
+
'Content-Length': Buffer.byteLength(message),
|
|
984
|
+
...headers
|
|
985
|
+
}, socket.once('finish', socket.destroy), socket.end(`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + Object.keys(headers).map((h)=>`${h}: ${headers[h]}`).join('\r\n') + '\r\n\r\n' + message);
|
|
986
|
+
}
|
|
987
|
+
function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
|
|
988
|
+
if (server.listenerCount('wsClientError')) {
|
|
989
|
+
let err = Error(message);
|
|
990
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError), server.emit('wsClientError', err, socket, req);
|
|
991
|
+
} else abortHandshake(socket, code, message, headers);
|
|
992
|
+
}
|
|
993
|
+
module.exports = class extends EventEmitter {
|
|
994
|
+
constructor(options, callback){
|
|
995
|
+
if (super(), null == (options = {
|
|
996
|
+
allowSynchronousEvents: !0,
|
|
997
|
+
autoPong: !0,
|
|
998
|
+
maxPayload: 104857600,
|
|
999
|
+
skipUTF8Validation: !1,
|
|
1000
|
+
perMessageDeflate: !1,
|
|
1001
|
+
handleProtocols: null,
|
|
1002
|
+
clientTracking: !0,
|
|
1003
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
1004
|
+
verifyClient: null,
|
|
1005
|
+
noServer: !1,
|
|
1006
|
+
backlog: null,
|
|
1007
|
+
server: null,
|
|
1008
|
+
host: null,
|
|
1009
|
+
path: null,
|
|
1010
|
+
port: null,
|
|
1011
|
+
WebSocket,
|
|
1012
|
+
...options
|
|
1013
|
+
}).port && !options.server && !options.noServer || null != options.port && (options.server || options.noServer) || options.server && options.noServer) throw TypeError('One and only one of the "port", "server", or "noServer" options must be specified');
|
|
1014
|
+
if (null != options.port ? (this._server = http.createServer((req, res)=>{
|
|
1015
|
+
let body = http.STATUS_CODES[426];
|
|
1016
|
+
res.writeHead(426, {
|
|
1017
|
+
'Content-Length': body.length,
|
|
1018
|
+
'Content-Type': 'text/plain'
|
|
1019
|
+
}), res.end(body);
|
|
1020
|
+
}), this._server.listen(options.port, options.host, options.backlog, callback)) : options.server && (this._server = options.server), this._server) {
|
|
1021
|
+
let emitConnection = this.emit.bind(this, 'connection');
|
|
1022
|
+
this._removeListeners = addListeners(this._server, {
|
|
1023
|
+
listening: this.emit.bind(this, 'listening'),
|
|
1024
|
+
error: this.emit.bind(this, 'error'),
|
|
1025
|
+
upgrade: (req, socket, head)=>{
|
|
1026
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
1027
|
+
}
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
!0 === options.perMessageDeflate && (options.perMessageDeflate = {}), options.clientTracking && (this.clients = new Set(), this._shouldEmitClose = !1), this.options = options, this._state = 0;
|
|
1031
|
+
}
|
|
1032
|
+
address() {
|
|
1033
|
+
if (this.options.noServer) throw Error('The server is operating in "noServer" mode');
|
|
1034
|
+
return this._server ? this._server.address() : null;
|
|
1035
|
+
}
|
|
1036
|
+
close(cb) {
|
|
1037
|
+
if (2 === this._state) {
|
|
1038
|
+
cb && this.once('close', ()=>{
|
|
1039
|
+
cb(Error('The server is not running'));
|
|
1040
|
+
}), process.nextTick(emitClose, this);
|
|
1041
|
+
return;
|
|
1042
|
+
}
|
|
1043
|
+
if (cb && this.once('close', cb), 1 !== this._state) if (this._state = 1, this.options.noServer || this.options.server) this._server && (this._removeListeners(), this._removeListeners = this._server = null), this.clients && this.clients.size ? this._shouldEmitClose = !0 : process.nextTick(emitClose, this);
|
|
1044
|
+
else {
|
|
1045
|
+
let server = this._server;
|
|
1046
|
+
this._removeListeners(), this._removeListeners = this._server = null, server.close(()=>{
|
|
1047
|
+
emitClose(this);
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
shouldHandle(req) {
|
|
1052
|
+
if (this.options.path) {
|
|
1053
|
+
let index = req.url.indexOf('?');
|
|
1054
|
+
if ((-1 !== index ? req.url.slice(0, index) : req.url) !== this.options.path) return !1;
|
|
1055
|
+
}
|
|
1056
|
+
return !0;
|
|
1057
|
+
}
|
|
1058
|
+
handleUpgrade(req, socket, head, cb) {
|
|
1059
|
+
socket.on('error', socketOnError);
|
|
1060
|
+
let key = req.headers['sec-websocket-key'], upgrade = req.headers.upgrade, version = +req.headers['sec-websocket-version'];
|
|
1061
|
+
if ('GET' !== req.method) return void abortHandshakeOrEmitwsClientError(this, req, socket, 405, 'Invalid HTTP method');
|
|
1062
|
+
if (void 0 === upgrade || 'websocket' !== upgrade.toLowerCase()) return void abortHandshakeOrEmitwsClientError(this, req, socket, 400, 'Invalid Upgrade header');
|
|
1063
|
+
if (void 0 === key || !keyRegex.test(key)) return void abortHandshakeOrEmitwsClientError(this, req, socket, 400, 'Missing or invalid Sec-WebSocket-Key header');
|
|
1064
|
+
if (13 !== version && 8 !== version) return void abortHandshakeOrEmitwsClientError(this, req, socket, 400, 'Missing or invalid Sec-WebSocket-Version header', {
|
|
1065
|
+
'Sec-WebSocket-Version': '13, 8'
|
|
1066
|
+
});
|
|
1067
|
+
if (!this.shouldHandle(req)) return void abortHandshake(socket, 400);
|
|
1068
|
+
let secWebSocketProtocol = req.headers['sec-websocket-protocol'], protocols = new Set();
|
|
1069
|
+
if (void 0 !== secWebSocketProtocol) try {
|
|
1070
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, 'Invalid Sec-WebSocket-Protocol header');
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
let secWebSocketExtensions = req.headers['sec-websocket-extensions'], extensions = {};
|
|
1076
|
+
if (this.options.perMessageDeflate && void 0 !== secWebSocketExtensions) {
|
|
1077
|
+
let perMessageDeflate = new PerMessageDeflate(this.options.perMessageDeflate, !0, this.options.maxPayload);
|
|
1078
|
+
try {
|
|
1079
|
+
let offers = extension.parse(secWebSocketExtensions);
|
|
1080
|
+
offers[PerMessageDeflate.extensionName] && (perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]), extensions[PerMessageDeflate.extensionName] = perMessageDeflate);
|
|
1081
|
+
} catch (err) {
|
|
1082
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, 'Invalid or unacceptable Sec-WebSocket-Extensions header');
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
if (this.options.verifyClient) {
|
|
1087
|
+
let info = {
|
|
1088
|
+
origin: req.headers[`${8 === version ? 'sec-websocket-origin' : 'origin'}`],
|
|
1089
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
1090
|
+
req
|
|
1091
|
+
};
|
|
1092
|
+
if (2 === this.options.verifyClient.length) return void this.options.verifyClient(info, (verified, code, message, headers)=>{
|
|
1093
|
+
if (!verified) return abortHandshake(socket, code || 401, message, headers);
|
|
1094
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
1095
|
+
});
|
|
1096
|
+
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
1097
|
+
}
|
|
1098
|
+
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
1099
|
+
}
|
|
1100
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
1101
|
+
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
1102
|
+
if (socket[kWebSocket]) throw Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");
|
|
1103
|
+
if (this._state > 0) return abortHandshake(socket, 503);
|
|
1104
|
+
let digest = createHash('sha1').update(key + GUID).digest('base64'), headers = [
|
|
1105
|
+
'HTTP/1.1 101 Switching Protocols',
|
|
1106
|
+
'Upgrade: websocket',
|
|
1107
|
+
'Connection: Upgrade',
|
|
1108
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
1109
|
+
], ws = new this.options.WebSocket(null, void 0, this.options);
|
|
1110
|
+
if (protocols.size) {
|
|
1111
|
+
let protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
|
|
1112
|
+
protocol && (headers.push(`Sec-WebSocket-Protocol: ${protocol}`), ws._protocol = protocol);
|
|
1113
|
+
}
|
|
1114
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
1115
|
+
let params = extensions[PerMessageDeflate.extensionName].params, value = extension.format({
|
|
1116
|
+
[PerMessageDeflate.extensionName]: [
|
|
1117
|
+
params
|
|
1118
|
+
]
|
|
1119
|
+
});
|
|
1120
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`), ws._extensions = extensions;
|
|
1121
|
+
}
|
|
1122
|
+
this.emit('headers', headers, req), socket.write(headers.concat('\r\n').join('\r\n')), socket.removeListener('error', socketOnError), ws.setSocket(socket, head, {
|
|
1123
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
1124
|
+
maxPayload: this.options.maxPayload,
|
|
1125
|
+
skipUTF8Validation: this.options.skipUTF8Validation
|
|
1126
|
+
}), this.clients && (this.clients.add(ws), ws.on('close', ()=>{
|
|
1127
|
+
this.clients.delete(ws), this._shouldEmitClose && !this.clients.size && process.nextTick(emitClose, this);
|
|
1128
|
+
})), cb(ws, req);
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
},
|
|
1132
|
+
"../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js" (module, __unused_rspack_exports, __webpack_require__) {
|
|
1133
|
+
let EventEmitter = __webpack_require__("events"), https = __webpack_require__("https?6bbf"), http = __webpack_require__("http?4112"), net = __webpack_require__("net"), tls = __webpack_require__("tls"), { randomBytes, createHash } = __webpack_require__("crypto"), { Duplex, Readable } = __webpack_require__("stream?3f22"), { URL } = __webpack_require__("url?291b"), PerMessageDeflate = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/permessage-deflate.js"), Receiver = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js"), Sender = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js"), { isBlob } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/validation.js"), { BINARY_TYPES, CLOSE_TIMEOUT, EMPTY_BUFFER, GUID, kForOnEventAttribute, kListener, kStatusCode, kWebSocket, NOOP } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/constants.js"), { EventTarget: { addEventListener, removeEventListener } } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/event-target.js"), { format, parse } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/extension.js"), { toBuffer } = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/buffer-util.js"), kAborted = Symbol('kAborted'), protocolVersions = [
|
|
1134
|
+
8,
|
|
1135
|
+
13
|
|
1136
|
+
], readyStates = [
|
|
1137
|
+
'CONNECTING',
|
|
1138
|
+
'OPEN',
|
|
1139
|
+
'CLOSING',
|
|
1140
|
+
'CLOSED'
|
|
1141
|
+
], subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
1142
|
+
class WebSocket extends EventEmitter {
|
|
1143
|
+
constructor(address, protocols, options){
|
|
1144
|
+
super(), this._binaryType = BINARY_TYPES[0], this._closeCode = 1006, this._closeFrameReceived = !1, this._closeFrameSent = !1, this._closeMessage = EMPTY_BUFFER, this._closeTimer = null, this._errorEmitted = !1, this._extensions = {}, this._paused = !1, this._protocol = '', this._readyState = WebSocket.CONNECTING, this._receiver = null, this._sender = null, this._socket = null, null !== address ? (this._bufferedAmount = 0, this._isServer = !1, this._redirects = 0, void 0 === protocols ? protocols = [] : Array.isArray(protocols) || ('object' == typeof protocols && null !== protocols ? (options = protocols, protocols = []) : protocols = [
|
|
1145
|
+
protocols
|
|
1146
|
+
]), initAsClient(this, address, protocols, options)) : (this._autoPong = options.autoPong, this._closeTimeout = options.closeTimeout, this._isServer = !0);
|
|
1147
|
+
}
|
|
1148
|
+
get binaryType() {
|
|
1149
|
+
return this._binaryType;
|
|
1150
|
+
}
|
|
1151
|
+
set binaryType(type) {
|
|
1152
|
+
BINARY_TYPES.includes(type) && (this._binaryType = type, this._receiver && (this._receiver._binaryType = type));
|
|
1153
|
+
}
|
|
1154
|
+
get bufferedAmount() {
|
|
1155
|
+
return this._socket ? this._socket._writableState.length + this._sender._bufferedBytes : this._bufferedAmount;
|
|
1156
|
+
}
|
|
1157
|
+
get extensions() {
|
|
1158
|
+
return Object.keys(this._extensions).join();
|
|
1159
|
+
}
|
|
1160
|
+
get isPaused() {
|
|
1161
|
+
return this._paused;
|
|
1162
|
+
}
|
|
1163
|
+
get onclose() {
|
|
1164
|
+
return null;
|
|
1165
|
+
}
|
|
1166
|
+
get onerror() {
|
|
1167
|
+
return null;
|
|
1168
|
+
}
|
|
1169
|
+
get onopen() {
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1172
|
+
get onmessage() {
|
|
1173
|
+
return null;
|
|
1174
|
+
}
|
|
1175
|
+
get protocol() {
|
|
1176
|
+
return this._protocol;
|
|
1177
|
+
}
|
|
1178
|
+
get readyState() {
|
|
1179
|
+
return this._readyState;
|
|
1180
|
+
}
|
|
1181
|
+
get url() {
|
|
1182
|
+
return this._url;
|
|
1183
|
+
}
|
|
1184
|
+
setSocket(socket, head, options) {
|
|
1185
|
+
let receiver = new Receiver({
|
|
1186
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
1187
|
+
binaryType: this.binaryType,
|
|
1188
|
+
extensions: this._extensions,
|
|
1189
|
+
isServer: this._isServer,
|
|
1190
|
+
maxPayload: options.maxPayload,
|
|
1191
|
+
skipUTF8Validation: options.skipUTF8Validation
|
|
1192
|
+
}), sender = new Sender(socket, this._extensions, options.generateMask);
|
|
1193
|
+
this._receiver = receiver, this._sender = sender, this._socket = socket, receiver[kWebSocket] = this, sender[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), sender.onerror = senderOnError, socket.setTimeout && socket.setTimeout(0), socket.setNoDelay && 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');
|
|
1194
|
+
}
|
|
1195
|
+
emitClose() {
|
|
1196
|
+
if (!this._socket) {
|
|
1197
|
+
this._readyState = WebSocket.CLOSED, this.emit('close', this._closeCode, this._closeMessage);
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
this._extensions[PerMessageDeflate.extensionName] && this._extensions[PerMessageDeflate.extensionName].cleanup(), this._receiver.removeAllListeners(), this._readyState = WebSocket.CLOSED, this.emit('close', this._closeCode, this._closeMessage);
|
|
1201
|
+
}
|
|
1202
|
+
close(code, data) {
|
|
1203
|
+
if (this.readyState !== WebSocket.CLOSED) {
|
|
1204
|
+
if (this.readyState === WebSocket.CONNECTING) return void abortHandshake(this, this._req, 'WebSocket was closed before the connection was established');
|
|
1205
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
1206
|
+
this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end();
|
|
1207
|
+
return;
|
|
1208
|
+
}
|
|
1209
|
+
this._readyState = WebSocket.CLOSING, this._sender.close(code, data, !this._isServer, (err)=>{
|
|
1210
|
+
!err && (this._closeFrameSent = !0, (this._closeFrameReceived || this._receiver._writableState.errorEmitted) && this._socket.end());
|
|
1211
|
+
}), setCloseTimer(this);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
pause() {
|
|
1215
|
+
this.readyState !== WebSocket.CONNECTING && this.readyState !== WebSocket.CLOSED && (this._paused = !0, this._socket.pause());
|
|
1216
|
+
}
|
|
1217
|
+
ping(data, mask, cb) {
|
|
1218
|
+
if (this.readyState === WebSocket.CONNECTING) throw Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
1219
|
+
('function' == typeof data ? (cb = data, data = mask = void 0) : 'function' == typeof mask && (cb = mask, mask = void 0), 'number' == typeof data && (data = data.toString()), this.readyState !== WebSocket.OPEN) ? sendAfterClose(this, data, cb) : (void 0 === mask && (mask = !this._isServer), this._sender.ping(data || EMPTY_BUFFER, mask, cb));
|
|
1220
|
+
}
|
|
1221
|
+
pong(data, mask, cb) {
|
|
1222
|
+
if (this.readyState === WebSocket.CONNECTING) throw Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
1223
|
+
('function' == typeof data ? (cb = data, data = mask = void 0) : 'function' == typeof mask && (cb = mask, mask = void 0), 'number' == typeof data && (data = data.toString()), this.readyState !== WebSocket.OPEN) ? sendAfterClose(this, data, cb) : (void 0 === mask && (mask = !this._isServer), this._sender.pong(data || EMPTY_BUFFER, mask, cb));
|
|
1224
|
+
}
|
|
1225
|
+
resume() {
|
|
1226
|
+
this.readyState !== WebSocket.CONNECTING && this.readyState !== WebSocket.CLOSED && (this._paused = !1, this._receiver._writableState.needDrain || this._socket.resume());
|
|
1227
|
+
}
|
|
1228
|
+
send(data, options, cb) {
|
|
1229
|
+
if (this.readyState === WebSocket.CONNECTING) throw Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
1230
|
+
if ('function' == typeof options && (cb = options, options = {}), 'number' == typeof data && (data = data.toString()), this.readyState !== WebSocket.OPEN) return void sendAfterClose(this, data, cb);
|
|
1231
|
+
let opts = {
|
|
1232
|
+
binary: 'string' != typeof data,
|
|
1233
|
+
mask: !this._isServer,
|
|
1234
|
+
compress: !0,
|
|
1235
|
+
fin: !0,
|
|
1236
|
+
...options
|
|
1237
|
+
};
|
|
1238
|
+
this._extensions[PerMessageDeflate.extensionName] || (opts.compress = !1), this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
1239
|
+
}
|
|
1240
|
+
terminate() {
|
|
1241
|
+
if (this.readyState !== WebSocket.CLOSED) {
|
|
1242
|
+
if (this.readyState === WebSocket.CONNECTING) return void abortHandshake(this, this._req, 'WebSocket was closed before the connection was established');
|
|
1243
|
+
this._socket && (this._readyState = WebSocket.CLOSING, this._socket.destroy());
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
1248
|
+
let parsedUrl, invalidUrlMessage, perMessageDeflate, req, opts = {
|
|
1249
|
+
allowSynchronousEvents: !0,
|
|
1250
|
+
autoPong: !0,
|
|
1251
|
+
closeTimeout: CLOSE_TIMEOUT,
|
|
1252
|
+
protocolVersion: protocolVersions[1],
|
|
1253
|
+
maxPayload: 104857600,
|
|
1254
|
+
skipUTF8Validation: !1,
|
|
1255
|
+
perMessageDeflate: !0,
|
|
1256
|
+
followRedirects: !1,
|
|
1257
|
+
maxRedirects: 10,
|
|
1258
|
+
...options,
|
|
1259
|
+
socketPath: void 0,
|
|
1260
|
+
hostname: void 0,
|
|
1261
|
+
protocol: void 0,
|
|
1262
|
+
timeout: void 0,
|
|
1263
|
+
method: 'GET',
|
|
1264
|
+
host: void 0,
|
|
1265
|
+
path: void 0,
|
|
1266
|
+
port: void 0
|
|
1267
|
+
};
|
|
1268
|
+
if (websocket._autoPong = opts.autoPong, websocket._closeTimeout = opts.closeTimeout, !protocolVersions.includes(opts.protocolVersion)) throw RangeError(`Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(', ')})`);
|
|
1269
|
+
if (address instanceof URL) parsedUrl = address;
|
|
1270
|
+
else try {
|
|
1271
|
+
parsedUrl = new URL(address);
|
|
1272
|
+
} catch (e) {
|
|
1273
|
+
throw SyntaxError(`Invalid URL: ${address}`);
|
|
1274
|
+
}
|
|
1275
|
+
'http:' === parsedUrl.protocol ? parsedUrl.protocol = 'ws:' : 'https:' === parsedUrl.protocol && (parsedUrl.protocol = 'wss:'), websocket._url = parsedUrl.href;
|
|
1276
|
+
let isSecure = 'wss:' === parsedUrl.protocol, isIpcUrl = 'ws+unix:' === parsedUrl.protocol;
|
|
1277
|
+
if ('ws:' === parsedUrl.protocol || isSecure || isIpcUrl ? isIpcUrl && !parsedUrl.pathname ? invalidUrlMessage = "The URL's pathname is empty" : parsedUrl.hash && (invalidUrlMessage = 'The URL contains a fragment identifier') : invalidUrlMessage = 'The URL\'s protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"', invalidUrlMessage) {
|
|
1278
|
+
let err = SyntaxError(invalidUrlMessage);
|
|
1279
|
+
if (0 !== websocket._redirects) return void emitErrorAndClose(websocket, err);
|
|
1280
|
+
throw err;
|
|
1281
|
+
}
|
|
1282
|
+
let defaultPort = isSecure ? 443 : 80, key = randomBytes(16).toString('base64'), request = isSecure ? https.request : http.request, protocolSet = new Set();
|
|
1283
|
+
if (opts.createConnection = 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 = {
|
|
1284
|
+
...opts.headers,
|
|
1285
|
+
'Sec-WebSocket-Version': opts.protocolVersion,
|
|
1286
|
+
'Sec-WebSocket-Key': key,
|
|
1287
|
+
Connection: 'Upgrade',
|
|
1288
|
+
Upgrade: 'websocket'
|
|
1289
|
+
}, opts.path = parsedUrl.pathname + parsedUrl.search, opts.timeout = opts.handshakeTimeout, opts.perMessageDeflate && (perMessageDeflate = new PerMessageDeflate(!0 !== opts.perMessageDeflate ? opts.perMessageDeflate : {}, !1, opts.maxPayload), opts.headers['Sec-WebSocket-Extensions'] = format({
|
|
1290
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer()
|
|
1291
|
+
})), protocols.length) {
|
|
1292
|
+
for (let protocol of protocols){
|
|
1293
|
+
if ('string' != typeof protocol || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) throw SyntaxError('An invalid or duplicated subprotocol was specified');
|
|
1294
|
+
protocolSet.add(protocol);
|
|
1295
|
+
}
|
|
1296
|
+
opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
|
|
1297
|
+
}
|
|
1298
|
+
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) {
|
|
1299
|
+
let parts = opts.path.split(':');
|
|
1300
|
+
opts.socketPath = parts[0], opts.path = parts[1];
|
|
1301
|
+
}
|
|
1302
|
+
if (opts.followRedirects) {
|
|
1303
|
+
if (0 === websocket._redirects) {
|
|
1304
|
+
websocket._originalIpc = isIpcUrl, websocket._originalSecure = isSecure, websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
|
|
1305
|
+
let headers = options && options.headers;
|
|
1306
|
+
if (options = {
|
|
1307
|
+
...options,
|
|
1308
|
+
headers: {}
|
|
1309
|
+
}, headers) for (let [key, value] of Object.entries(headers))options.headers[key.toLowerCase()] = value;
|
|
1310
|
+
} else if (0 === websocket.listenerCount('redirect')) {
|
|
1311
|
+
let isSameHost = isIpcUrl ? !!websocket._originalIpc && opts.socketPath === websocket._originalHostOrSocketPath : !websocket._originalIpc && parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
1312
|
+
isSameHost && (!websocket._originalSecure || isSecure) || (delete opts.headers.authorization, delete opts.headers.cookie, isSameHost || delete opts.headers.host, opts.auth = void 0);
|
|
1313
|
+
}
|
|
1314
|
+
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);
|
|
1315
|
+
} else req = websocket._req = request(opts);
|
|
1316
|
+
opts.timeout && req.on('timeout', ()=>{
|
|
1317
|
+
abortHandshake(websocket, req, 'Opening handshake has timed out');
|
|
1318
|
+
}), req.on('error', (err)=>{
|
|
1319
|
+
null === req || req[kAborted] || (req = websocket._req = null, emitErrorAndClose(websocket, err));
|
|
1320
|
+
}), req.on('response', (res)=>{
|
|
1321
|
+
let location = res.headers.location, statusCode = res.statusCode;
|
|
1322
|
+
if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
1323
|
+
let addr;
|
|
1324
|
+
if (++websocket._redirects > opts.maxRedirects) return void abortHandshake(websocket, req, 'Maximum redirects exceeded');
|
|
1325
|
+
req.abort();
|
|
1326
|
+
try {
|
|
1327
|
+
addr = new URL(location, address);
|
|
1328
|
+
} catch (e) {
|
|
1329
|
+
emitErrorAndClose(websocket, SyntaxError(`Invalid URL: ${location}`));
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
initAsClient(websocket, addr, protocols, options);
|
|
1333
|
+
} else websocket.emit('unexpected-response', req, res) || abortHandshake(websocket, req, `Unexpected server response: ${res.statusCode}`);
|
|
1334
|
+
}), req.on('upgrade', (res, socket, head)=>{
|
|
1335
|
+
let protError;
|
|
1336
|
+
if (websocket.emit('upgrade', res), websocket.readyState !== WebSocket.CONNECTING) return;
|
|
1337
|
+
req = websocket._req = null;
|
|
1338
|
+
let upgrade = res.headers.upgrade;
|
|
1339
|
+
if (void 0 === upgrade || 'websocket' !== upgrade.toLowerCase()) return void abortHandshake(websocket, socket, 'Invalid Upgrade header');
|
|
1340
|
+
let digest = createHash('sha1').update(key + GUID).digest('base64');
|
|
1341
|
+
if (res.headers['sec-websocket-accept'] !== digest) return void abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
|
|
1342
|
+
let serverProt = res.headers['sec-websocket-protocol'];
|
|
1343
|
+
if (void 0 !== serverProt ? 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) return void abortHandshake(websocket, socket, protError);
|
|
1344
|
+
serverProt && (websocket._protocol = serverProt);
|
|
1345
|
+
let secWebSocketExtensions = res.headers['sec-websocket-extensions'];
|
|
1346
|
+
if (void 0 !== secWebSocketExtensions) {
|
|
1347
|
+
let extensions;
|
|
1348
|
+
if (!perMessageDeflate) return void abortHandshake(websocket, socket, "Server sent a Sec-WebSocket-Extensions header but no extension was requested");
|
|
1349
|
+
try {
|
|
1350
|
+
extensions = parse(secWebSocketExtensions);
|
|
1351
|
+
} catch (err) {
|
|
1352
|
+
abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Extensions header');
|
|
1353
|
+
return;
|
|
1354
|
+
}
|
|
1355
|
+
let extensionNames = Object.keys(extensions);
|
|
1356
|
+
if (1 !== extensionNames.length || extensionNames[0] !== PerMessageDeflate.extensionName) return void abortHandshake(websocket, socket, 'Server indicated an extension that was not requested');
|
|
1357
|
+
try {
|
|
1358
|
+
perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
|
|
1359
|
+
} catch (err) {
|
|
1360
|
+
abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Extensions header');
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
1364
|
+
}
|
|
1365
|
+
websocket.setSocket(socket, head, {
|
|
1366
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
1367
|
+
generateMask: opts.generateMask,
|
|
1368
|
+
maxPayload: opts.maxPayload,
|
|
1369
|
+
skipUTF8Validation: opts.skipUTF8Validation
|
|
1370
|
+
});
|
|
1371
|
+
}), opts.finishRequest ? opts.finishRequest(req, websocket) : req.end();
|
|
1372
|
+
}
|
|
1373
|
+
function emitErrorAndClose(websocket, err) {
|
|
1374
|
+
websocket._readyState = WebSocket.CLOSING, websocket._errorEmitted = !0, websocket.emit('error', err), websocket.emitClose();
|
|
1375
|
+
}
|
|
1376
|
+
function netConnect(options) {
|
|
1377
|
+
return options.path = options.socketPath, net.connect(options);
|
|
1378
|
+
}
|
|
1379
|
+
function tlsConnect(options) {
|
|
1380
|
+
return options.path = void 0, options.servername || '' === options.servername || (options.servername = net.isIP(options.host) ? '' : options.host), tls.connect(options);
|
|
1381
|
+
}
|
|
1382
|
+
function abortHandshake(websocket, stream, message) {
|
|
1383
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
1384
|
+
let err = Error(message);
|
|
1385
|
+
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)));
|
|
1386
|
+
}
|
|
1387
|
+
function sendAfterClose(websocket, data, cb) {
|
|
1388
|
+
if (data) {
|
|
1389
|
+
let length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
1390
|
+
websocket._socket ? websocket._sender._bufferedBytes += length : websocket._bufferedAmount += length;
|
|
1391
|
+
}
|
|
1392
|
+
if (cb) {
|
|
1393
|
+
let err = Error(`WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`);
|
|
1394
|
+
process.nextTick(cb, err);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
function receiverOnConclude(code, reason) {
|
|
1398
|
+
let websocket = this[kWebSocket];
|
|
1399
|
+
websocket._closeFrameReceived = !0, websocket._closeMessage = reason, websocket._closeCode = code, void 0 !== websocket._socket[kWebSocket] && (websocket._socket.removeListener('data', socketOnData), process.nextTick(resume, websocket._socket), 1005 === code ? websocket.close() : websocket.close(code, reason));
|
|
1400
|
+
}
|
|
1401
|
+
function receiverOnDrain() {
|
|
1402
|
+
let websocket = this[kWebSocket];
|
|
1403
|
+
websocket.isPaused || websocket._socket.resume();
|
|
1404
|
+
}
|
|
1405
|
+
function receiverOnError(err) {
|
|
1406
|
+
let websocket = this[kWebSocket];
|
|
1407
|
+
void 0 !== websocket._socket[kWebSocket] && (websocket._socket.removeListener('data', socketOnData), process.nextTick(resume, websocket._socket), websocket.close(err[kStatusCode])), websocket._errorEmitted || (websocket._errorEmitted = !0, websocket.emit('error', err));
|
|
1408
|
+
}
|
|
1409
|
+
function receiverOnFinish() {
|
|
1410
|
+
this[kWebSocket].emitClose();
|
|
1411
|
+
}
|
|
1412
|
+
function receiverOnMessage(data, isBinary) {
|
|
1413
|
+
this[kWebSocket].emit('message', data, isBinary);
|
|
1414
|
+
}
|
|
1415
|
+
function receiverOnPing(data) {
|
|
1416
|
+
let websocket = this[kWebSocket];
|
|
1417
|
+
websocket._autoPong && websocket.pong(data, !this._isServer, NOOP), websocket.emit('ping', data);
|
|
1418
|
+
}
|
|
1419
|
+
function receiverOnPong(data) {
|
|
1420
|
+
this[kWebSocket].emit('pong', data);
|
|
1421
|
+
}
|
|
1422
|
+
function resume(stream) {
|
|
1423
|
+
stream.resume();
|
|
1424
|
+
}
|
|
1425
|
+
function senderOnError(err) {
|
|
1426
|
+
let websocket = this[kWebSocket];
|
|
1427
|
+
websocket.readyState !== WebSocket.CLOSED && (websocket.readyState === WebSocket.OPEN && (websocket._readyState = WebSocket.CLOSING, setCloseTimer(websocket)), this._socket.end(), websocket._errorEmitted || (websocket._errorEmitted = !0, websocket.emit('error', err)));
|
|
1428
|
+
}
|
|
1429
|
+
function setCloseTimer(websocket) {
|
|
1430
|
+
websocket._closeTimer = setTimeout(websocket._socket.destroy.bind(websocket._socket), websocket._closeTimeout);
|
|
1431
|
+
}
|
|
1432
|
+
function socketOnClose() {
|
|
1433
|
+
let websocket = this[kWebSocket];
|
|
1434
|
+
if (this.removeListener('close', socketOnClose), this.removeListener('data', socketOnData), this.removeListener('end', socketOnEnd), websocket._readyState = WebSocket.CLOSING, !this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && 0 !== this._readableState.length) {
|
|
1435
|
+
let chunk = this.read(this._readableState.length);
|
|
1436
|
+
websocket._receiver.write(chunk);
|
|
1437
|
+
}
|
|
1438
|
+
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));
|
|
1439
|
+
}
|
|
1440
|
+
function socketOnData(chunk) {
|
|
1441
|
+
this[kWebSocket]._receiver.write(chunk) || this.pause();
|
|
1442
|
+
}
|
|
1443
|
+
function socketOnEnd() {
|
|
1444
|
+
let websocket = this[kWebSocket];
|
|
1445
|
+
websocket._readyState = WebSocket.CLOSING, websocket._receiver.end(), this.end();
|
|
1446
|
+
}
|
|
1447
|
+
function socketOnError() {
|
|
1448
|
+
let websocket = this[kWebSocket];
|
|
1449
|
+
this.removeListener('error', socketOnError), this.on('error', NOOP), websocket && (websocket._readyState = WebSocket.CLOSING, this.destroy());
|
|
1450
|
+
}
|
|
1451
|
+
Object.defineProperty(WebSocket, 'CONNECTING', {
|
|
1452
|
+
enumerable: !0,
|
|
1453
|
+
value: readyStates.indexOf('CONNECTING')
|
|
1454
|
+
}), Object.defineProperty(WebSocket.prototype, 'CONNECTING', {
|
|
1455
|
+
enumerable: !0,
|
|
1456
|
+
value: readyStates.indexOf('CONNECTING')
|
|
1457
|
+
}), Object.defineProperty(WebSocket, 'OPEN', {
|
|
1458
|
+
enumerable: !0,
|
|
1459
|
+
value: readyStates.indexOf('OPEN')
|
|
1460
|
+
}), Object.defineProperty(WebSocket.prototype, 'OPEN', {
|
|
1461
|
+
enumerable: !0,
|
|
1462
|
+
value: readyStates.indexOf('OPEN')
|
|
1463
|
+
}), Object.defineProperty(WebSocket, 'CLOSING', {
|
|
1464
|
+
enumerable: !0,
|
|
1465
|
+
value: readyStates.indexOf('CLOSING')
|
|
1466
|
+
}), Object.defineProperty(WebSocket.prototype, 'CLOSING', {
|
|
1467
|
+
enumerable: !0,
|
|
1468
|
+
value: readyStates.indexOf('CLOSING')
|
|
1469
|
+
}), Object.defineProperty(WebSocket, 'CLOSED', {
|
|
1470
|
+
enumerable: !0,
|
|
1471
|
+
value: readyStates.indexOf('CLOSED')
|
|
1472
|
+
}), Object.defineProperty(WebSocket.prototype, 'CLOSED', {
|
|
1473
|
+
enumerable: !0,
|
|
1474
|
+
value: readyStates.indexOf('CLOSED')
|
|
1475
|
+
}), [
|
|
1476
|
+
'binaryType',
|
|
1477
|
+
'bufferedAmount',
|
|
1478
|
+
'extensions',
|
|
1479
|
+
'isPaused',
|
|
1480
|
+
'protocol',
|
|
1481
|
+
'readyState',
|
|
1482
|
+
'url'
|
|
1483
|
+
].forEach((property)=>{
|
|
1484
|
+
Object.defineProperty(WebSocket.prototype, property, {
|
|
1485
|
+
enumerable: !0
|
|
1486
|
+
});
|
|
1487
|
+
}), [
|
|
1488
|
+
'open',
|
|
1489
|
+
'error',
|
|
1490
|
+
'close',
|
|
1491
|
+
'message'
|
|
1492
|
+
].forEach((method)=>{
|
|
1493
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
1494
|
+
enumerable: !0,
|
|
1495
|
+
get () {
|
|
1496
|
+
for (let listener of this.listeners(method))if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
1497
|
+
return null;
|
|
1498
|
+
},
|
|
1499
|
+
set (handler) {
|
|
1500
|
+
for (let listener of this.listeners(method))if (listener[kForOnEventAttribute]) {
|
|
1501
|
+
this.removeListener(method, listener);
|
|
1502
|
+
break;
|
|
1503
|
+
}
|
|
1504
|
+
'function' == typeof handler && this.addEventListener(method, handler, {
|
|
1505
|
+
[kForOnEventAttribute]: !0
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
});
|
|
1509
|
+
}), WebSocket.prototype.addEventListener = addEventListener, WebSocket.prototype.removeEventListener = removeEventListener, module.exports = WebSocket;
|
|
1510
|
+
},
|
|
1511
|
+
buffer (module) {
|
|
1512
|
+
module.exports = __rspack_external_buffer;
|
|
1513
|
+
},
|
|
1514
|
+
crypto (module) {
|
|
1515
|
+
module.exports = __rspack_external_crypto;
|
|
1516
|
+
},
|
|
1517
|
+
"http?4112" (module) {
|
|
1518
|
+
module.exports = __rspack_external_http;
|
|
1519
|
+
},
|
|
1520
|
+
"https?6bbf" (module) {
|
|
1521
|
+
module.exports = __rspack_external_https;
|
|
1522
|
+
},
|
|
1523
|
+
net (module) {
|
|
1524
|
+
module.exports = __rspack_external_net;
|
|
1525
|
+
},
|
|
1526
|
+
"stream?3f22" (module) {
|
|
1527
|
+
module.exports = __rspack_external_stream;
|
|
1528
|
+
},
|
|
1529
|
+
tls (module) {
|
|
1530
|
+
module.exports = __rspack_external_tls;
|
|
1531
|
+
},
|
|
1532
|
+
"url?291b" (module) {
|
|
1533
|
+
module.exports = __rspack_external_url;
|
|
1534
|
+
},
|
|
1535
|
+
"zlib?f7b9" (module) {
|
|
1536
|
+
module.exports = __rspack_external_zlib;
|
|
1537
|
+
}
|
|
1538
|
+
});
|
|
1539
|
+
let websocket_server = __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket-server.js");
|
|
1540
|
+
__webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/stream.js"), __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/receiver.js"), __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/sender.js"), __webpack_require__("../../node_modules/.pnpm/ws@8.19.0/node_modules/ws/lib/websocket.js");
|
|
1541
|
+
export { websocket_server as WebSocketServer };
|