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