@ohos-ports/rsbuild-core 1.7.2-beta.1
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/LICENSE +21 -0
- package/README.md +27 -0
- package/bin/rsbuild.js +20 -0
- package/compiled/@jridgewell/remapping/index.d.ts +1 -0
- package/compiled/@jridgewell/remapping/index.js +1222 -0
- package/compiled/@jridgewell/remapping/license +19 -0
- package/compiled/@jridgewell/remapping/package.json +1 -0
- package/compiled/@jridgewell/trace-mapping/index.d.ts +194 -0
- package/compiled/@jridgewell/trace-mapping/index.js +1408 -0
- package/compiled/@jridgewell/trace-mapping/license +19 -0
- package/compiled/@jridgewell/trace-mapping/package.json +1 -0
- package/compiled/chokidar/index.d.ts +384 -0
- package/compiled/chokidar/index.js +1793 -0
- package/compiled/chokidar/license +21 -0
- package/compiled/chokidar/package.json +1 -0
- package/compiled/connect/index.d.ts +90 -0
- package/compiled/connect/index.js +1240 -0
- package/compiled/connect/license +25 -0
- package/compiled/connect/package.json +1 -0
- package/compiled/cors/index.d.ts +56 -0
- package/compiled/cors/index.js +371 -0
- package/compiled/cors/license +22 -0
- package/compiled/cors/package.json +1 -0
- package/compiled/css-loader/api.js +85 -0
- package/compiled/css-loader/getUrl.js +26 -0
- package/compiled/css-loader/index.d.ts +1 -0
- package/compiled/css-loader/index.js +2 -0
- package/compiled/css-loader/license +20 -0
- package/compiled/css-loader/noSourceMaps.js +5 -0
- package/compiled/css-loader/package.json +1 -0
- package/compiled/css-loader/sourceMaps.js +16 -0
- package/compiled/html-rspack-plugin/default_index.ejs +9 -0
- package/compiled/html-rspack-plugin/index.d.ts +290 -0
- package/compiled/html-rspack-plugin/index.js +1602 -0
- package/compiled/html-rspack-plugin/license +20 -0
- package/compiled/html-rspack-plugin/loader.js +166 -0
- package/compiled/html-rspack-plugin/package.json +1 -0
- package/compiled/http-proxy-middleware/index.d.ts +319 -0
- package/compiled/http-proxy-middleware/index.js +5284 -0
- package/compiled/http-proxy-middleware/license +22 -0
- package/compiled/http-proxy-middleware/package.json +1 -0
- package/compiled/launch-editor-middleware/index.d.ts +1 -0
- package/compiled/launch-editor-middleware/index.js +719 -0
- package/compiled/launch-editor-middleware/license +21 -0
- package/compiled/launch-editor-middleware/package.json +1 -0
- package/compiled/memfs/index.d.ts +1462 -0
- package/compiled/memfs/index.js +1 -0
- package/compiled/memfs/license +201 -0
- package/compiled/memfs/package.json +1 -0
- package/compiled/mrmime/index.d.ts +4 -0
- package/compiled/mrmime/index.js +456 -0
- package/compiled/mrmime/package.json +1 -0
- package/compiled/picocolors/index.d.ts +55 -0
- package/compiled/picocolors/index.js +108 -0
- package/compiled/picocolors/license +15 -0
- package/compiled/picocolors/package.json +1 -0
- package/compiled/postcss/index.js +1 -0
- package/compiled/postcss/lib/at-rule.d.ts +140 -0
- package/compiled/postcss/lib/comment.d.ts +68 -0
- package/compiled/postcss/lib/container.d.ts +483 -0
- package/compiled/postcss/lib/css-syntax-error.d.ts +248 -0
- package/compiled/postcss/lib/declaration.d.ts +151 -0
- package/compiled/postcss/lib/document.d.ts +69 -0
- package/compiled/postcss/lib/fromJSON.d.ts +9 -0
- package/compiled/postcss/lib/input.d.ts +227 -0
- package/compiled/postcss/lib/lazy-result.d.ts +190 -0
- package/compiled/postcss/lib/list.d.ts +60 -0
- package/compiled/postcss/lib/no-work-result.d.ts +46 -0
- package/compiled/postcss/lib/node.d.ts +556 -0
- package/compiled/postcss/lib/parse.d.ts +9 -0
- package/compiled/postcss/lib/postcss.d.ts +458 -0
- package/compiled/postcss/lib/previous-map.d.ts +81 -0
- package/compiled/postcss/lib/processor.d.ts +115 -0
- package/compiled/postcss/lib/result.d.ts +205 -0
- package/compiled/postcss/lib/root.d.ts +87 -0
- package/compiled/postcss/lib/rule.d.ts +126 -0
- package/compiled/postcss/lib/source-map-js.d.ts +4 -0
- package/compiled/postcss/lib/stringifier.d.ts +46 -0
- package/compiled/postcss/lib/stringify.d.ts +9 -0
- package/compiled/postcss/lib/warning.d.ts +147 -0
- package/compiled/postcss/license +20 -0
- package/compiled/postcss/package.json +1 -0
- package/compiled/postcss-loader/index.d.ts +1 -0
- package/compiled/postcss-loader/index.js +720 -0
- package/compiled/postcss-loader/license +20 -0
- package/compiled/postcss-loader/package.json +1 -0
- package/compiled/rslog/index.d.ts +67 -0
- package/compiled/rslog/license +21 -0
- package/compiled/rslog/package.json +1 -0
- package/compiled/rspack-chain/license +22 -0
- package/compiled/rspack-chain/package.json +1 -0
- package/compiled/rspack-chain/types/index.d.ts +545 -0
- package/compiled/rspack-manifest-plugin/index.d.ts +48 -0
- package/compiled/rspack-manifest-plugin/index.js +409 -0
- package/compiled/rspack-manifest-plugin/license +21 -0
- package/compiled/rspack-manifest-plugin/package.json +1 -0
- package/compiled/sirv/index.d.ts +1 -0
- package/compiled/sirv/index.js +274 -0
- package/compiled/sirv/package.json +1 -0
- package/compiled/style-loader/index.d.ts +1 -0
- package/compiled/style-loader/index.js +427 -0
- package/compiled/style-loader/license +20 -0
- package/compiled/style-loader/package.json +1 -0
- package/compiled/style-loader/runtime/injectStylesIntoLinkTag.js +29 -0
- package/compiled/style-loader/runtime/injectStylesIntoStyleTag.js +84 -0
- package/compiled/style-loader/runtime/insertBySelector.js +34 -0
- package/compiled/style-loader/runtime/insertStyleElement.js +10 -0
- package/compiled/style-loader/runtime/isEqualLocals.js +28 -0
- package/compiled/style-loader/runtime/isOldIE.js +17 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributes.js +13 -0
- package/compiled/style-loader/runtime/setAttributesWithAttributesAndNonce.js +9 -0
- package/compiled/style-loader/runtime/setAttributesWithoutAttributes.js +10 -0
- package/compiled/style-loader/runtime/singletonStyleDomAPI.js +86 -0
- package/compiled/style-loader/runtime/styleDomAPI.js +61 -0
- package/compiled/style-loader/runtime/styleTagTransform.js +14 -0
- package/compiled/tinyglobby/index.d.ts +46 -0
- package/compiled/tinyglobby/index.js +2664 -0
- package/compiled/tinyglobby/license +21 -0
- package/compiled/tinyglobby/package.json +1 -0
- package/compiled/webpack-bundle-analyzer/index.d.ts +160 -0
- package/compiled/webpack-bundle-analyzer/index.js +23 -0
- package/compiled/webpack-bundle-analyzer/license +20 -0
- package/compiled/webpack-bundle-analyzer/package.json +1 -0
- package/compiled/webpack-bundle-analyzer/public/viewer.js +16 -0
- package/compiled/webpack-bundle-analyzer/public/viewer.js.LICENSE.txt +10 -0
- package/compiled/webpack-merge/index.d.ts +31 -0
- package/compiled/webpack-merge/index.js +1200 -0
- package/compiled/webpack-merge/license +20 -0
- package/compiled/webpack-merge/package.json +1 -0
- package/compiled/ws/index.d.ts +437 -0
- package/compiled/ws/index.js +3161 -0
- package/compiled/ws/license +20 -0
- package/compiled/ws/package.json +1 -0
- package/dist/0~open.js +427 -0
- package/dist/0~range-parser.js +49 -0
- package/dist/0~range-parser.js.LICENSE.txt +6 -0
- package/dist/131.js +9305 -0
- package/dist/131.js.LICENSE.txt +26 -0
- package/dist/136.mjs +42 -0
- package/dist/2~open.cjs +436 -0
- package/dist/2~range-parser.cjs +52 -0
- package/dist/2~range-parser.cjs.LICENSE.txt +6 -0
- package/dist/client/59.js +22 -0
- package/dist/client/hmr.js +206 -0
- package/dist/client/overlay.js +203 -0
- package/dist/ignoreCssLoader.mjs +3 -0
- package/dist/index.cjs +9456 -0
- package/dist/index.cjs.LICENSE.txt +26 -0
- package/dist/index.js +1 -0
- package/dist/rslib-runtime.js +44 -0
- package/dist/transformLoader.mjs +1 -0
- package/dist/transformRawLoader.mjs +4 -0
- package/dist-types/cli/commands.d.ts +28 -0
- package/dist-types/cli/index.d.ts +1 -0
- package/dist-types/cli/init.d.ts +7 -0
- package/dist-types/client/hmr.d.ts +3 -0
- package/dist-types/client/log.d.ts +13 -0
- package/dist-types/client/overlay.d.ts +1 -0
- package/dist-types/configChain.d.ts +154 -0
- package/dist-types/constants.d.ts +52 -0
- package/dist-types/createContext.d.ts +11 -0
- package/dist-types/createRsbuild.d.ts +5 -0
- package/dist-types/defaultConfig.d.ts +25 -0
- package/dist-types/helpers/compiler.d.ts +5 -0
- package/dist-types/helpers/exitHook.d.ts +3 -0
- package/dist-types/helpers/format.d.ts +2 -0
- package/dist-types/helpers/fs.d.ts +17 -0
- package/dist-types/helpers/index.d.ts +29 -0
- package/dist-types/helpers/path.d.ts +26 -0
- package/dist-types/helpers/stats.d.ts +18 -0
- package/dist-types/helpers/url.d.ts +11 -0
- package/dist-types/helpers/vendors.d.ts +29 -0
- package/dist-types/helpers/version.d.ts +7 -0
- package/dist-types/hooks.d.ts +44 -0
- package/dist-types/index.d.ts +22 -0
- package/dist-types/initPlugins.d.ts +6 -0
- package/dist-types/inspectConfig.d.ts +35 -0
- package/dist-types/loadConfig.d.ts +60 -0
- package/dist-types/loadEnv.d.ts +63 -0
- package/dist-types/loader/ignoreCssLoader.d.ts +3 -0
- package/dist-types/loader/transformLoader.d.ts +8 -0
- package/dist-types/loader/transformRawLoader.d.ts +3 -0
- package/dist-types/logger.d.ts +19 -0
- package/dist-types/mergeConfig.d.ts +2 -0
- package/dist-types/package.json +1 -0
- package/dist-types/pluginHelper.d.ts +12 -0
- package/dist-types/pluginManager.d.ts +21 -0
- package/dist-types/plugins/appIcon.d.ts +2 -0
- package/dist-types/plugins/asset.d.ts +3 -0
- package/dist-types/plugins/basic.d.ts +5 -0
- package/dist-types/plugins/bundleAnalyzer.d.ts +2 -0
- package/dist-types/plugins/cache.d.ts +2 -0
- package/dist-types/plugins/cleanOutput.d.ts +2 -0
- package/dist-types/plugins/css.d.ts +4 -0
- package/dist-types/plugins/define.d.ts +2 -0
- package/dist-types/plugins/entry.d.ts +2 -0
- package/dist-types/plugins/esm.d.ts +2 -0
- package/dist-types/plugins/externals.d.ts +2 -0
- package/dist-types/plugins/fileSize.d.ts +6 -0
- package/dist-types/plugins/html.d.ts +9 -0
- package/dist-types/plugins/inlineChunk.d.ts +6 -0
- package/dist-types/plugins/lazyCompilation.d.ts +2 -0
- package/dist-types/plugins/manifest.d.ts +2 -0
- package/dist-types/plugins/minimize.d.ts +10 -0
- package/dist-types/plugins/moduleFederation.d.ts +2 -0
- package/dist-types/plugins/moment.d.ts +2 -0
- package/dist-types/plugins/nodeAddons.d.ts +2 -0
- package/dist-types/plugins/nonce.d.ts +2 -0
- package/dist-types/plugins/output.d.ts +2 -0
- package/dist-types/plugins/performance.d.ts +5 -0
- package/dist-types/plugins/progress.d.ts +2 -0
- package/dist-types/plugins/resolve.d.ts +2 -0
- package/dist-types/plugins/resourceHints.d.ts +2 -0
- package/dist-types/plugins/rsdoctor.d.ts +2 -0
- package/dist-types/plugins/rspackProfile.d.ts +2 -0
- package/dist-types/plugins/server.d.ts +2 -0
- package/dist-types/plugins/sourceMap.d.ts +2 -0
- package/dist-types/plugins/splitChunks.d.ts +4 -0
- package/dist-types/plugins/sri.d.ts +2 -0
- package/dist-types/plugins/swc.d.ts +5 -0
- package/dist-types/plugins/target.d.ts +2 -0
- package/dist-types/plugins/wasm.d.ts +2 -0
- package/dist-types/provider/build.d.ts +4 -0
- package/dist-types/provider/createCompiler.d.ts +6 -0
- package/dist-types/provider/helpers.d.ts +12 -0
- package/dist-types/provider/initConfigs.d.ts +19 -0
- package/dist-types/provider/provider.d.ts +2 -0
- package/dist-types/provider/rspackConfig.d.ts +8 -0
- package/dist-types/restart.d.ts +18 -0
- package/dist-types/rspack-plugins/RsbuildHtmlPlugin.d.ts +38 -0
- package/dist-types/rspack-plugins/resource-hints/HtmlResourceHintsPlugin.d.ts +32 -0
- package/dist-types/rspack-plugins/resource-hints/doesChunkBelongToHtml.d.ts +28 -0
- package/dist-types/rspack-plugins/resource-hints/extractChunks.d.ts +23 -0
- package/dist-types/rspack-plugins/resource-hints/getResourceType.d.ts +22 -0
- package/dist-types/rspack.d.ts +2 -0
- package/dist-types/server/ansiHTML.d.ts +4 -0
- package/dist-types/server/assets-middleware/getFileFromUrl.d.ts +12 -0
- package/dist-types/server/assets-middleware/index.d.ts +37 -0
- package/dist-types/server/assets-middleware/middleware.d.ts +2 -0
- package/dist-types/server/assets-middleware/parseTokenList.d.ts +1 -0
- package/dist-types/server/assets-middleware/setupOutputFileSystem.d.ts +3 -0
- package/dist-types/server/assets-middleware/setupWriteToDisk.d.ts +15 -0
- package/dist-types/server/browserLogs.d.ts +9 -0
- package/dist-types/server/buildManager.d.ts +33 -0
- package/dist-types/server/cliShortcuts.d.ts +10 -0
- package/dist-types/server/devMiddlewares.d.ts +21 -0
- package/dist-types/server/devServer.d.ts +79 -0
- package/dist-types/server/environment.d.ts +8 -0
- package/dist-types/server/gracefulShutdown.d.ts +10 -0
- package/dist-types/server/gzipMiddleware.d.ts +2 -0
- package/dist-types/server/helper.d.ts +91 -0
- package/dist-types/server/historyApiFallback.d.ts +2 -0
- package/dist-types/server/hmrFallback.d.ts +1 -0
- package/dist-types/server/httpServer.d.ts +7 -0
- package/dist-types/server/middlewares.d.ts +33 -0
- package/dist-types/server/open.d.ts +10 -0
- package/dist-types/server/overlay.d.ts +3 -0
- package/dist-types/server/prodServer.d.ts +24 -0
- package/dist-types/server/proxy.d.ts +6 -0
- package/dist-types/server/runner/asModule.d.ts +2 -0
- package/dist-types/server/runner/basic.d.ts +29 -0
- package/dist-types/server/runner/cjs.d.ts +10 -0
- package/dist-types/server/runner/esm.d.ts +6 -0
- package/dist-types/server/runner/index.d.ts +4 -0
- package/dist-types/server/runner/type.d.ts +42 -0
- package/dist-types/server/socketServer.d.ts +81 -0
- package/dist-types/server/watchFiles.d.ts +14 -0
- package/dist-types/types/config.d.ts +1882 -0
- package/dist-types/types/context.d.ts +110 -0
- package/dist-types/types/hooks.d.ts +275 -0
- package/dist-types/types/index.d.ts +8 -0
- package/dist-types/types/plugin.d.ts +585 -0
- package/dist-types/types/rsbuild.d.ts +286 -0
- package/dist-types/types/rspack.d.ts +16 -0
- package/dist-types/types/thirdParty.d.ts +186 -0
- package/dist-types/types/utils.d.ts +19 -0
- package/package.json +114 -0
- package/static/openChrome.applescript +95 -0
- package/types.d.ts +349 -0
|
@@ -0,0 +1,3161 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
821: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
4
|
+
"use strict";
|
|
5
|
+
const WebSocket = __nccwpck_require__(234);
|
|
6
|
+
WebSocket.createWebSocketStream = __nccwpck_require__(297);
|
|
7
|
+
WebSocket.Server = __nccwpck_require__(788);
|
|
8
|
+
WebSocket.Receiver = __nccwpck_require__(176);
|
|
9
|
+
WebSocket.Sender = __nccwpck_require__(480);
|
|
10
|
+
WebSocket.WebSocket = WebSocket;
|
|
11
|
+
WebSocket.WebSocketServer = WebSocket.Server;
|
|
12
|
+
module.exports = WebSocket;
|
|
13
|
+
},
|
|
14
|
+
72: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
15
|
+
"use strict";
|
|
16
|
+
const { EMPTY_BUFFER } = __nccwpck_require__(892);
|
|
17
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
18
|
+
function concat(list, totalLength) {
|
|
19
|
+
if (list.length === 0) return EMPTY_BUFFER;
|
|
20
|
+
if (list.length === 1) return list[0];
|
|
21
|
+
const target = Buffer.allocUnsafe(totalLength);
|
|
22
|
+
let offset = 0;
|
|
23
|
+
for (let i = 0; i < list.length; i++) {
|
|
24
|
+
const buf = list[i];
|
|
25
|
+
target.set(buf, offset);
|
|
26
|
+
offset += buf.length;
|
|
27
|
+
}
|
|
28
|
+
if (offset < totalLength) {
|
|
29
|
+
return new FastBuffer(target.buffer, target.byteOffset, offset);
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
}
|
|
33
|
+
function _mask(source, mask, output, offset, length) {
|
|
34
|
+
for (let i = 0; i < length; i++) {
|
|
35
|
+
output[offset + i] = source[i] ^ mask[i & 3];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function _unmask(buffer, mask) {
|
|
39
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
40
|
+
buffer[i] ^= mask[i & 3];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function toArrayBuffer(buf) {
|
|
44
|
+
if (buf.length === buf.buffer.byteLength) {
|
|
45
|
+
return buf.buffer;
|
|
46
|
+
}
|
|
47
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
48
|
+
}
|
|
49
|
+
function toBuffer(data) {
|
|
50
|
+
toBuffer.readOnly = true;
|
|
51
|
+
if (Buffer.isBuffer(data)) return data;
|
|
52
|
+
let buf;
|
|
53
|
+
if (data instanceof ArrayBuffer) {
|
|
54
|
+
buf = new FastBuffer(data);
|
|
55
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
56
|
+
buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
|
|
57
|
+
} else {
|
|
58
|
+
buf = Buffer.from(data);
|
|
59
|
+
toBuffer.readOnly = false;
|
|
60
|
+
}
|
|
61
|
+
return buf;
|
|
62
|
+
}
|
|
63
|
+
module.exports = {
|
|
64
|
+
concat,
|
|
65
|
+
mask: _mask,
|
|
66
|
+
toArrayBuffer,
|
|
67
|
+
toBuffer,
|
|
68
|
+
unmask: _unmask,
|
|
69
|
+
};
|
|
70
|
+
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
71
|
+
try {
|
|
72
|
+
const bufferUtil = __nccwpck_require__(431);
|
|
73
|
+
module.exports.mask = function (
|
|
74
|
+
source,
|
|
75
|
+
mask,
|
|
76
|
+
output,
|
|
77
|
+
offset,
|
|
78
|
+
length,
|
|
79
|
+
) {
|
|
80
|
+
if (length < 48) _mask(source, mask, output, offset, length);
|
|
81
|
+
else bufferUtil.mask(source, mask, output, offset, length);
|
|
82
|
+
};
|
|
83
|
+
module.exports.unmask = function (buffer, mask) {
|
|
84
|
+
if (buffer.length < 32) _unmask(buffer, mask);
|
|
85
|
+
else bufferUtil.unmask(buffer, mask);
|
|
86
|
+
};
|
|
87
|
+
} catch (e) {}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
892: (module) => {
|
|
91
|
+
"use strict";
|
|
92
|
+
const BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
93
|
+
const hasBlob = typeof Blob !== "undefined";
|
|
94
|
+
if (hasBlob) BINARY_TYPES.push("blob");
|
|
95
|
+
module.exports = {
|
|
96
|
+
BINARY_TYPES,
|
|
97
|
+
EMPTY_BUFFER: Buffer.alloc(0),
|
|
98
|
+
GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
|
|
99
|
+
hasBlob,
|
|
100
|
+
kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
|
|
101
|
+
kListener: Symbol("kListener"),
|
|
102
|
+
kStatusCode: Symbol("status-code"),
|
|
103
|
+
kWebSocket: Symbol("websocket"),
|
|
104
|
+
NOOP: () => {},
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
95: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
108
|
+
"use strict";
|
|
109
|
+
const { kForOnEventAttribute, kListener } = __nccwpck_require__(892);
|
|
110
|
+
const kCode = Symbol("kCode");
|
|
111
|
+
const kData = Symbol("kData");
|
|
112
|
+
const kError = Symbol("kError");
|
|
113
|
+
const kMessage = Symbol("kMessage");
|
|
114
|
+
const kReason = Symbol("kReason");
|
|
115
|
+
const kTarget = Symbol("kTarget");
|
|
116
|
+
const kType = Symbol("kType");
|
|
117
|
+
const kWasClean = Symbol("kWasClean");
|
|
118
|
+
class Event {
|
|
119
|
+
constructor(type) {
|
|
120
|
+
this[kTarget] = null;
|
|
121
|
+
this[kType] = type;
|
|
122
|
+
}
|
|
123
|
+
get target() {
|
|
124
|
+
return this[kTarget];
|
|
125
|
+
}
|
|
126
|
+
get type() {
|
|
127
|
+
return this[kType];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
Object.defineProperty(Event.prototype, "target", { enumerable: true });
|
|
131
|
+
Object.defineProperty(Event.prototype, "type", { enumerable: true });
|
|
132
|
+
class CloseEvent extends Event {
|
|
133
|
+
constructor(type, options = {}) {
|
|
134
|
+
super(type);
|
|
135
|
+
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
136
|
+
this[kReason] = options.reason === undefined ? "" : options.reason;
|
|
137
|
+
this[kWasClean] =
|
|
138
|
+
options.wasClean === undefined ? false : options.wasClean;
|
|
139
|
+
}
|
|
140
|
+
get code() {
|
|
141
|
+
return this[kCode];
|
|
142
|
+
}
|
|
143
|
+
get reason() {
|
|
144
|
+
return this[kReason];
|
|
145
|
+
}
|
|
146
|
+
get wasClean() {
|
|
147
|
+
return this[kWasClean];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
|
|
151
|
+
Object.defineProperty(CloseEvent.prototype, "reason", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
});
|
|
154
|
+
Object.defineProperty(CloseEvent.prototype, "wasClean", {
|
|
155
|
+
enumerable: true,
|
|
156
|
+
});
|
|
157
|
+
class ErrorEvent extends Event {
|
|
158
|
+
constructor(type, options = {}) {
|
|
159
|
+
super(type);
|
|
160
|
+
this[kError] = options.error === undefined ? null : options.error;
|
|
161
|
+
this[kMessage] = options.message === undefined ? "" : options.message;
|
|
162
|
+
}
|
|
163
|
+
get error() {
|
|
164
|
+
return this[kError];
|
|
165
|
+
}
|
|
166
|
+
get message() {
|
|
167
|
+
return this[kMessage];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
Object.defineProperty(ErrorEvent.prototype, "error", {
|
|
171
|
+
enumerable: true,
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(ErrorEvent.prototype, "message", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
});
|
|
176
|
+
class MessageEvent extends Event {
|
|
177
|
+
constructor(type, options = {}) {
|
|
178
|
+
super(type);
|
|
179
|
+
this[kData] = options.data === undefined ? null : options.data;
|
|
180
|
+
}
|
|
181
|
+
get data() {
|
|
182
|
+
return this[kData];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
Object.defineProperty(MessageEvent.prototype, "data", {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
});
|
|
188
|
+
const EventTarget = {
|
|
189
|
+
addEventListener(type, handler, options = {}) {
|
|
190
|
+
for (const listener of this.listeners(type)) {
|
|
191
|
+
if (
|
|
192
|
+
!options[kForOnEventAttribute] &&
|
|
193
|
+
listener[kListener] === handler &&
|
|
194
|
+
!listener[kForOnEventAttribute]
|
|
195
|
+
) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
let wrapper;
|
|
200
|
+
if (type === "message") {
|
|
201
|
+
wrapper = function onMessage(data, isBinary) {
|
|
202
|
+
const event = new MessageEvent("message", {
|
|
203
|
+
data: isBinary ? data : data.toString(),
|
|
204
|
+
});
|
|
205
|
+
event[kTarget] = this;
|
|
206
|
+
callListener(handler, this, event);
|
|
207
|
+
};
|
|
208
|
+
} else if (type === "close") {
|
|
209
|
+
wrapper = function onClose(code, message) {
|
|
210
|
+
const event = new CloseEvent("close", {
|
|
211
|
+
code,
|
|
212
|
+
reason: message.toString(),
|
|
213
|
+
wasClean: this._closeFrameReceived && this._closeFrameSent,
|
|
214
|
+
});
|
|
215
|
+
event[kTarget] = this;
|
|
216
|
+
callListener(handler, this, event);
|
|
217
|
+
};
|
|
218
|
+
} else if (type === "error") {
|
|
219
|
+
wrapper = function onError(error) {
|
|
220
|
+
const event = new ErrorEvent("error", {
|
|
221
|
+
error,
|
|
222
|
+
message: error.message,
|
|
223
|
+
});
|
|
224
|
+
event[kTarget] = this;
|
|
225
|
+
callListener(handler, this, event);
|
|
226
|
+
};
|
|
227
|
+
} else if (type === "open") {
|
|
228
|
+
wrapper = function onOpen() {
|
|
229
|
+
const event = new Event("open");
|
|
230
|
+
event[kTarget] = this;
|
|
231
|
+
callListener(handler, this, event);
|
|
232
|
+
};
|
|
233
|
+
} else {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
|
|
237
|
+
wrapper[kListener] = handler;
|
|
238
|
+
if (options.once) {
|
|
239
|
+
this.once(type, wrapper);
|
|
240
|
+
} else {
|
|
241
|
+
this.on(type, wrapper);
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
removeEventListener(type, handler) {
|
|
245
|
+
for (const listener of this.listeners(type)) {
|
|
246
|
+
if (
|
|
247
|
+
listener[kListener] === handler &&
|
|
248
|
+
!listener[kForOnEventAttribute]
|
|
249
|
+
) {
|
|
250
|
+
this.removeListener(type, listener);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
module.exports = {
|
|
257
|
+
CloseEvent,
|
|
258
|
+
ErrorEvent,
|
|
259
|
+
Event,
|
|
260
|
+
EventTarget,
|
|
261
|
+
MessageEvent,
|
|
262
|
+
};
|
|
263
|
+
function callListener(listener, thisArg, event) {
|
|
264
|
+
if (typeof listener === "object" && listener.handleEvent) {
|
|
265
|
+
listener.handleEvent.call(listener, event);
|
|
266
|
+
} else {
|
|
267
|
+
listener.call(thisArg, event);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
468: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
272
|
+
"use strict";
|
|
273
|
+
const { tokenChars } = __nccwpck_require__(342);
|
|
274
|
+
function push(dest, name, elem) {
|
|
275
|
+
if (dest[name] === undefined) dest[name] = [elem];
|
|
276
|
+
else dest[name].push(elem);
|
|
277
|
+
}
|
|
278
|
+
function parse(header) {
|
|
279
|
+
const offers = Object.create(null);
|
|
280
|
+
let params = Object.create(null);
|
|
281
|
+
let mustUnescape = false;
|
|
282
|
+
let isEscaping = false;
|
|
283
|
+
let inQuotes = false;
|
|
284
|
+
let extensionName;
|
|
285
|
+
let paramName;
|
|
286
|
+
let start = -1;
|
|
287
|
+
let code = -1;
|
|
288
|
+
let end = -1;
|
|
289
|
+
let i = 0;
|
|
290
|
+
for (; i < header.length; i++) {
|
|
291
|
+
code = header.charCodeAt(i);
|
|
292
|
+
if (extensionName === undefined) {
|
|
293
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
294
|
+
if (start === -1) start = i;
|
|
295
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
296
|
+
if (end === -1 && start !== -1) end = i;
|
|
297
|
+
} else if (code === 59 || code === 44) {
|
|
298
|
+
if (start === -1) {
|
|
299
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
300
|
+
}
|
|
301
|
+
if (end === -1) end = i;
|
|
302
|
+
const name = header.slice(start, end);
|
|
303
|
+
if (code === 44) {
|
|
304
|
+
push(offers, name, params);
|
|
305
|
+
params = Object.create(null);
|
|
306
|
+
} else {
|
|
307
|
+
extensionName = name;
|
|
308
|
+
}
|
|
309
|
+
start = end = -1;
|
|
310
|
+
} else {
|
|
311
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
312
|
+
}
|
|
313
|
+
} else if (paramName === undefined) {
|
|
314
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
315
|
+
if (start === -1) start = i;
|
|
316
|
+
} else if (code === 32 || code === 9) {
|
|
317
|
+
if (end === -1 && start !== -1) end = i;
|
|
318
|
+
} else if (code === 59 || code === 44) {
|
|
319
|
+
if (start === -1) {
|
|
320
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
321
|
+
}
|
|
322
|
+
if (end === -1) end = i;
|
|
323
|
+
push(params, header.slice(start, end), true);
|
|
324
|
+
if (code === 44) {
|
|
325
|
+
push(offers, extensionName, params);
|
|
326
|
+
params = Object.create(null);
|
|
327
|
+
extensionName = undefined;
|
|
328
|
+
}
|
|
329
|
+
start = end = -1;
|
|
330
|
+
} else if (code === 61 && start !== -1 && end === -1) {
|
|
331
|
+
paramName = header.slice(start, i);
|
|
332
|
+
start = end = -1;
|
|
333
|
+
} else {
|
|
334
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
335
|
+
}
|
|
336
|
+
} else {
|
|
337
|
+
if (isEscaping) {
|
|
338
|
+
if (tokenChars[code] !== 1) {
|
|
339
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
340
|
+
}
|
|
341
|
+
if (start === -1) start = i;
|
|
342
|
+
else if (!mustUnescape) mustUnescape = true;
|
|
343
|
+
isEscaping = false;
|
|
344
|
+
} else if (inQuotes) {
|
|
345
|
+
if (tokenChars[code] === 1) {
|
|
346
|
+
if (start === -1) start = i;
|
|
347
|
+
} else if (code === 34 && start !== -1) {
|
|
348
|
+
inQuotes = false;
|
|
349
|
+
end = i;
|
|
350
|
+
} else if (code === 92) {
|
|
351
|
+
isEscaping = true;
|
|
352
|
+
} else {
|
|
353
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
354
|
+
}
|
|
355
|
+
} else if (code === 34 && header.charCodeAt(i - 1) === 61) {
|
|
356
|
+
inQuotes = true;
|
|
357
|
+
} else if (end === -1 && tokenChars[code] === 1) {
|
|
358
|
+
if (start === -1) start = i;
|
|
359
|
+
} else if (start !== -1 && (code === 32 || code === 9)) {
|
|
360
|
+
if (end === -1) end = i;
|
|
361
|
+
} else if (code === 59 || code === 44) {
|
|
362
|
+
if (start === -1) {
|
|
363
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
364
|
+
}
|
|
365
|
+
if (end === -1) end = i;
|
|
366
|
+
let value = header.slice(start, end);
|
|
367
|
+
if (mustUnescape) {
|
|
368
|
+
value = value.replace(/\\/g, "");
|
|
369
|
+
mustUnescape = false;
|
|
370
|
+
}
|
|
371
|
+
push(params, paramName, value);
|
|
372
|
+
if (code === 44) {
|
|
373
|
+
push(offers, extensionName, params);
|
|
374
|
+
params = Object.create(null);
|
|
375
|
+
extensionName = undefined;
|
|
376
|
+
}
|
|
377
|
+
paramName = undefined;
|
|
378
|
+
start = end = -1;
|
|
379
|
+
} else {
|
|
380
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (start === -1 || inQuotes || code === 32 || code === 9) {
|
|
385
|
+
throw new SyntaxError("Unexpected end of input");
|
|
386
|
+
}
|
|
387
|
+
if (end === -1) end = i;
|
|
388
|
+
const token = header.slice(start, end);
|
|
389
|
+
if (extensionName === undefined) {
|
|
390
|
+
push(offers, token, params);
|
|
391
|
+
} else {
|
|
392
|
+
if (paramName === undefined) {
|
|
393
|
+
push(params, token, true);
|
|
394
|
+
} else if (mustUnescape) {
|
|
395
|
+
push(params, paramName, token.replace(/\\/g, ""));
|
|
396
|
+
} else {
|
|
397
|
+
push(params, paramName, token);
|
|
398
|
+
}
|
|
399
|
+
push(offers, extensionName, params);
|
|
400
|
+
}
|
|
401
|
+
return offers;
|
|
402
|
+
}
|
|
403
|
+
function format(extensions) {
|
|
404
|
+
return Object.keys(extensions)
|
|
405
|
+
.map((extension) => {
|
|
406
|
+
let configurations = extensions[extension];
|
|
407
|
+
if (!Array.isArray(configurations))
|
|
408
|
+
configurations = [configurations];
|
|
409
|
+
return configurations
|
|
410
|
+
.map((params) =>
|
|
411
|
+
[extension]
|
|
412
|
+
.concat(
|
|
413
|
+
Object.keys(params).map((k) => {
|
|
414
|
+
let values = params[k];
|
|
415
|
+
if (!Array.isArray(values)) values = [values];
|
|
416
|
+
return values
|
|
417
|
+
.map((v) => (v === true ? k : `${k}=${v}`))
|
|
418
|
+
.join("; ");
|
|
419
|
+
}),
|
|
420
|
+
)
|
|
421
|
+
.join("; "),
|
|
422
|
+
)
|
|
423
|
+
.join(", ");
|
|
424
|
+
})
|
|
425
|
+
.join(", ");
|
|
426
|
+
}
|
|
427
|
+
module.exports = { format, parse };
|
|
428
|
+
},
|
|
429
|
+
137: (module) => {
|
|
430
|
+
"use strict";
|
|
431
|
+
const kDone = Symbol("kDone");
|
|
432
|
+
const kRun = Symbol("kRun");
|
|
433
|
+
class Limiter {
|
|
434
|
+
constructor(concurrency) {
|
|
435
|
+
this[kDone] = () => {
|
|
436
|
+
this.pending--;
|
|
437
|
+
this[kRun]();
|
|
438
|
+
};
|
|
439
|
+
this.concurrency = concurrency || Infinity;
|
|
440
|
+
this.jobs = [];
|
|
441
|
+
this.pending = 0;
|
|
442
|
+
}
|
|
443
|
+
add(job) {
|
|
444
|
+
this.jobs.push(job);
|
|
445
|
+
this[kRun]();
|
|
446
|
+
}
|
|
447
|
+
[kRun]() {
|
|
448
|
+
if (this.pending === this.concurrency) return;
|
|
449
|
+
if (this.jobs.length) {
|
|
450
|
+
const job = this.jobs.shift();
|
|
451
|
+
this.pending++;
|
|
452
|
+
job(this[kDone]);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
module.exports = Limiter;
|
|
457
|
+
},
|
|
458
|
+
465: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
459
|
+
"use strict";
|
|
460
|
+
const zlib = __nccwpck_require__(106);
|
|
461
|
+
const bufferUtil = __nccwpck_require__(72);
|
|
462
|
+
const Limiter = __nccwpck_require__(137);
|
|
463
|
+
const { kStatusCode } = __nccwpck_require__(892);
|
|
464
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
465
|
+
const TRAILER = Buffer.from([0, 0, 255, 255]);
|
|
466
|
+
const kPerMessageDeflate = Symbol("permessage-deflate");
|
|
467
|
+
const kTotalLength = Symbol("total-length");
|
|
468
|
+
const kCallback = Symbol("callback");
|
|
469
|
+
const kBuffers = Symbol("buffers");
|
|
470
|
+
const kError = Symbol("error");
|
|
471
|
+
let zlibLimiter;
|
|
472
|
+
class PerMessageDeflate {
|
|
473
|
+
constructor(options, isServer, maxPayload) {
|
|
474
|
+
this._maxPayload = maxPayload | 0;
|
|
475
|
+
this._options = options || {};
|
|
476
|
+
this._threshold =
|
|
477
|
+
this._options.threshold !== undefined
|
|
478
|
+
? this._options.threshold
|
|
479
|
+
: 1024;
|
|
480
|
+
this._isServer = !!isServer;
|
|
481
|
+
this._deflate = null;
|
|
482
|
+
this._inflate = null;
|
|
483
|
+
this.params = null;
|
|
484
|
+
if (!zlibLimiter) {
|
|
485
|
+
const concurrency =
|
|
486
|
+
this._options.concurrencyLimit !== undefined
|
|
487
|
+
? this._options.concurrencyLimit
|
|
488
|
+
: 10;
|
|
489
|
+
zlibLimiter = new Limiter(concurrency);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
static get extensionName() {
|
|
493
|
+
return "permessage-deflate";
|
|
494
|
+
}
|
|
495
|
+
offer() {
|
|
496
|
+
const params = {};
|
|
497
|
+
if (this._options.serverNoContextTakeover) {
|
|
498
|
+
params.server_no_context_takeover = true;
|
|
499
|
+
}
|
|
500
|
+
if (this._options.clientNoContextTakeover) {
|
|
501
|
+
params.client_no_context_takeover = true;
|
|
502
|
+
}
|
|
503
|
+
if (this._options.serverMaxWindowBits) {
|
|
504
|
+
params.server_max_window_bits = this._options.serverMaxWindowBits;
|
|
505
|
+
}
|
|
506
|
+
if (this._options.clientMaxWindowBits) {
|
|
507
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
508
|
+
} else if (this._options.clientMaxWindowBits == null) {
|
|
509
|
+
params.client_max_window_bits = true;
|
|
510
|
+
}
|
|
511
|
+
return params;
|
|
512
|
+
}
|
|
513
|
+
accept(configurations) {
|
|
514
|
+
configurations = this.normalizeParams(configurations);
|
|
515
|
+
this.params = this._isServer
|
|
516
|
+
? this.acceptAsServer(configurations)
|
|
517
|
+
: this.acceptAsClient(configurations);
|
|
518
|
+
return this.params;
|
|
519
|
+
}
|
|
520
|
+
cleanup() {
|
|
521
|
+
if (this._inflate) {
|
|
522
|
+
this._inflate.close();
|
|
523
|
+
this._inflate = null;
|
|
524
|
+
}
|
|
525
|
+
if (this._deflate) {
|
|
526
|
+
const callback = this._deflate[kCallback];
|
|
527
|
+
this._deflate.close();
|
|
528
|
+
this._deflate = null;
|
|
529
|
+
if (callback) {
|
|
530
|
+
callback(
|
|
531
|
+
new Error(
|
|
532
|
+
"The deflate stream was closed while data was being processed",
|
|
533
|
+
),
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
acceptAsServer(offers) {
|
|
539
|
+
const opts = this._options;
|
|
540
|
+
const accepted = offers.find((params) => {
|
|
541
|
+
if (
|
|
542
|
+
(opts.serverNoContextTakeover === false &&
|
|
543
|
+
params.server_no_context_takeover) ||
|
|
544
|
+
(params.server_max_window_bits &&
|
|
545
|
+
(opts.serverMaxWindowBits === false ||
|
|
546
|
+
(typeof opts.serverMaxWindowBits === "number" &&
|
|
547
|
+
opts.serverMaxWindowBits >
|
|
548
|
+
params.server_max_window_bits))) ||
|
|
549
|
+
(typeof opts.clientMaxWindowBits === "number" &&
|
|
550
|
+
!params.client_max_window_bits)
|
|
551
|
+
) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
return true;
|
|
555
|
+
});
|
|
556
|
+
if (!accepted) {
|
|
557
|
+
throw new Error("None of the extension offers can be accepted");
|
|
558
|
+
}
|
|
559
|
+
if (opts.serverNoContextTakeover) {
|
|
560
|
+
accepted.server_no_context_takeover = true;
|
|
561
|
+
}
|
|
562
|
+
if (opts.clientNoContextTakeover) {
|
|
563
|
+
accepted.client_no_context_takeover = true;
|
|
564
|
+
}
|
|
565
|
+
if (typeof opts.serverMaxWindowBits === "number") {
|
|
566
|
+
accepted.server_max_window_bits = opts.serverMaxWindowBits;
|
|
567
|
+
}
|
|
568
|
+
if (typeof opts.clientMaxWindowBits === "number") {
|
|
569
|
+
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
570
|
+
} else if (
|
|
571
|
+
accepted.client_max_window_bits === true ||
|
|
572
|
+
opts.clientMaxWindowBits === false
|
|
573
|
+
) {
|
|
574
|
+
delete accepted.client_max_window_bits;
|
|
575
|
+
}
|
|
576
|
+
return accepted;
|
|
577
|
+
}
|
|
578
|
+
acceptAsClient(response) {
|
|
579
|
+
const params = response[0];
|
|
580
|
+
if (
|
|
581
|
+
this._options.clientNoContextTakeover === false &&
|
|
582
|
+
params.client_no_context_takeover
|
|
583
|
+
) {
|
|
584
|
+
throw new Error(
|
|
585
|
+
'Unexpected parameter "client_no_context_takeover"',
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
if (!params.client_max_window_bits) {
|
|
589
|
+
if (typeof this._options.clientMaxWindowBits === "number") {
|
|
590
|
+
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
591
|
+
}
|
|
592
|
+
} else if (
|
|
593
|
+
this._options.clientMaxWindowBits === false ||
|
|
594
|
+
(typeof this._options.clientMaxWindowBits === "number" &&
|
|
595
|
+
params.client_max_window_bits > this._options.clientMaxWindowBits)
|
|
596
|
+
) {
|
|
597
|
+
throw new Error(
|
|
598
|
+
'Unexpected or invalid parameter "client_max_window_bits"',
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
return params;
|
|
602
|
+
}
|
|
603
|
+
normalizeParams(configurations) {
|
|
604
|
+
configurations.forEach((params) => {
|
|
605
|
+
Object.keys(params).forEach((key) => {
|
|
606
|
+
let value = params[key];
|
|
607
|
+
if (value.length > 1) {
|
|
608
|
+
throw new Error(
|
|
609
|
+
`Parameter "${key}" must have only a single value`,
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
value = value[0];
|
|
613
|
+
if (key === "client_max_window_bits") {
|
|
614
|
+
if (value !== true) {
|
|
615
|
+
const num = +value;
|
|
616
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
617
|
+
throw new TypeError(
|
|
618
|
+
`Invalid value for parameter "${key}": ${value}`,
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
value = num;
|
|
622
|
+
} else if (!this._isServer) {
|
|
623
|
+
throw new TypeError(
|
|
624
|
+
`Invalid value for parameter "${key}": ${value}`,
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
} else if (key === "server_max_window_bits") {
|
|
628
|
+
const num = +value;
|
|
629
|
+
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
630
|
+
throw new TypeError(
|
|
631
|
+
`Invalid value for parameter "${key}": ${value}`,
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
value = num;
|
|
635
|
+
} else if (
|
|
636
|
+
key === "client_no_context_takeover" ||
|
|
637
|
+
key === "server_no_context_takeover"
|
|
638
|
+
) {
|
|
639
|
+
if (value !== true) {
|
|
640
|
+
throw new TypeError(
|
|
641
|
+
`Invalid value for parameter "${key}": ${value}`,
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
throw new Error(`Unknown parameter "${key}"`);
|
|
646
|
+
}
|
|
647
|
+
params[key] = value;
|
|
648
|
+
});
|
|
649
|
+
});
|
|
650
|
+
return configurations;
|
|
651
|
+
}
|
|
652
|
+
decompress(data, fin, callback) {
|
|
653
|
+
zlibLimiter.add((done) => {
|
|
654
|
+
this._decompress(data, fin, (err, result) => {
|
|
655
|
+
done();
|
|
656
|
+
callback(err, result);
|
|
657
|
+
});
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
compress(data, fin, callback) {
|
|
661
|
+
zlibLimiter.add((done) => {
|
|
662
|
+
this._compress(data, fin, (err, result) => {
|
|
663
|
+
done();
|
|
664
|
+
callback(err, result);
|
|
665
|
+
});
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
_decompress(data, fin, callback) {
|
|
669
|
+
const endpoint = this._isServer ? "client" : "server";
|
|
670
|
+
if (!this._inflate) {
|
|
671
|
+
const key = `${endpoint}_max_window_bits`;
|
|
672
|
+
const windowBits =
|
|
673
|
+
typeof this.params[key] !== "number"
|
|
674
|
+
? zlib.Z_DEFAULT_WINDOWBITS
|
|
675
|
+
: this.params[key];
|
|
676
|
+
this._inflate = zlib.createInflateRaw({
|
|
677
|
+
...this._options.zlibInflateOptions,
|
|
678
|
+
windowBits,
|
|
679
|
+
});
|
|
680
|
+
this._inflate[kPerMessageDeflate] = this;
|
|
681
|
+
this._inflate[kTotalLength] = 0;
|
|
682
|
+
this._inflate[kBuffers] = [];
|
|
683
|
+
this._inflate.on("error", inflateOnError);
|
|
684
|
+
this._inflate.on("data", inflateOnData);
|
|
685
|
+
}
|
|
686
|
+
this._inflate[kCallback] = callback;
|
|
687
|
+
this._inflate.write(data);
|
|
688
|
+
if (fin) this._inflate.write(TRAILER);
|
|
689
|
+
this._inflate.flush(() => {
|
|
690
|
+
const err = this._inflate[kError];
|
|
691
|
+
if (err) {
|
|
692
|
+
this._inflate.close();
|
|
693
|
+
this._inflate = null;
|
|
694
|
+
callback(err);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
const data = bufferUtil.concat(
|
|
698
|
+
this._inflate[kBuffers],
|
|
699
|
+
this._inflate[kTotalLength],
|
|
700
|
+
);
|
|
701
|
+
if (this._inflate._readableState.endEmitted) {
|
|
702
|
+
this._inflate.close();
|
|
703
|
+
this._inflate = null;
|
|
704
|
+
} else {
|
|
705
|
+
this._inflate[kTotalLength] = 0;
|
|
706
|
+
this._inflate[kBuffers] = [];
|
|
707
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
708
|
+
this._inflate.reset();
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
callback(null, data);
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
_compress(data, fin, callback) {
|
|
715
|
+
const endpoint = this._isServer ? "server" : "client";
|
|
716
|
+
if (!this._deflate) {
|
|
717
|
+
const key = `${endpoint}_max_window_bits`;
|
|
718
|
+
const windowBits =
|
|
719
|
+
typeof this.params[key] !== "number"
|
|
720
|
+
? zlib.Z_DEFAULT_WINDOWBITS
|
|
721
|
+
: this.params[key];
|
|
722
|
+
this._deflate = zlib.createDeflateRaw({
|
|
723
|
+
...this._options.zlibDeflateOptions,
|
|
724
|
+
windowBits,
|
|
725
|
+
});
|
|
726
|
+
this._deflate[kTotalLength] = 0;
|
|
727
|
+
this._deflate[kBuffers] = [];
|
|
728
|
+
this._deflate.on("data", deflateOnData);
|
|
729
|
+
}
|
|
730
|
+
this._deflate[kCallback] = callback;
|
|
731
|
+
this._deflate.write(data);
|
|
732
|
+
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
733
|
+
if (!this._deflate) {
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
let data = bufferUtil.concat(
|
|
737
|
+
this._deflate[kBuffers],
|
|
738
|
+
this._deflate[kTotalLength],
|
|
739
|
+
);
|
|
740
|
+
if (fin) {
|
|
741
|
+
data = new FastBuffer(
|
|
742
|
+
data.buffer,
|
|
743
|
+
data.byteOffset,
|
|
744
|
+
data.length - 4,
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
this._deflate[kCallback] = null;
|
|
748
|
+
this._deflate[kTotalLength] = 0;
|
|
749
|
+
this._deflate[kBuffers] = [];
|
|
750
|
+
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
751
|
+
this._deflate.reset();
|
|
752
|
+
}
|
|
753
|
+
callback(null, data);
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
module.exports = PerMessageDeflate;
|
|
758
|
+
function deflateOnData(chunk) {
|
|
759
|
+
this[kBuffers].push(chunk);
|
|
760
|
+
this[kTotalLength] += chunk.length;
|
|
761
|
+
}
|
|
762
|
+
function inflateOnData(chunk) {
|
|
763
|
+
this[kTotalLength] += chunk.length;
|
|
764
|
+
if (
|
|
765
|
+
this[kPerMessageDeflate]._maxPayload < 1 ||
|
|
766
|
+
this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
|
|
767
|
+
) {
|
|
768
|
+
this[kBuffers].push(chunk);
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
this[kError] = new RangeError("Max payload size exceeded");
|
|
772
|
+
this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
|
|
773
|
+
this[kError][kStatusCode] = 1009;
|
|
774
|
+
this.removeListener("data", inflateOnData);
|
|
775
|
+
this.reset();
|
|
776
|
+
}
|
|
777
|
+
function inflateOnError(err) {
|
|
778
|
+
this[kPerMessageDeflate]._inflate = null;
|
|
779
|
+
if (this[kError]) {
|
|
780
|
+
this[kCallback](this[kError]);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
err[kStatusCode] = 1007;
|
|
784
|
+
this[kCallback](err);
|
|
785
|
+
}
|
|
786
|
+
},
|
|
787
|
+
176: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
788
|
+
"use strict";
|
|
789
|
+
const { Writable } = __nccwpck_require__(203);
|
|
790
|
+
const PerMessageDeflate = __nccwpck_require__(465);
|
|
791
|
+
const { BINARY_TYPES, EMPTY_BUFFER, kStatusCode, kWebSocket } =
|
|
792
|
+
__nccwpck_require__(892);
|
|
793
|
+
const { concat, toArrayBuffer, unmask } = __nccwpck_require__(72);
|
|
794
|
+
const { isValidStatusCode, isValidUTF8 } = __nccwpck_require__(342);
|
|
795
|
+
const FastBuffer = Buffer[Symbol.species];
|
|
796
|
+
const GET_INFO = 0;
|
|
797
|
+
const GET_PAYLOAD_LENGTH_16 = 1;
|
|
798
|
+
const GET_PAYLOAD_LENGTH_64 = 2;
|
|
799
|
+
const GET_MASK = 3;
|
|
800
|
+
const GET_DATA = 4;
|
|
801
|
+
const INFLATING = 5;
|
|
802
|
+
const DEFER_EVENT = 6;
|
|
803
|
+
class Receiver extends Writable {
|
|
804
|
+
constructor(options = {}) {
|
|
805
|
+
super();
|
|
806
|
+
this._allowSynchronousEvents =
|
|
807
|
+
options.allowSynchronousEvents !== undefined
|
|
808
|
+
? options.allowSynchronousEvents
|
|
809
|
+
: true;
|
|
810
|
+
this._binaryType = options.binaryType || BINARY_TYPES[0];
|
|
811
|
+
this._extensions = options.extensions || {};
|
|
812
|
+
this._isServer = !!options.isServer;
|
|
813
|
+
this._maxPayload = options.maxPayload | 0;
|
|
814
|
+
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
815
|
+
this[kWebSocket] = undefined;
|
|
816
|
+
this._bufferedBytes = 0;
|
|
817
|
+
this._buffers = [];
|
|
818
|
+
this._compressed = false;
|
|
819
|
+
this._payloadLength = 0;
|
|
820
|
+
this._mask = undefined;
|
|
821
|
+
this._fragmented = 0;
|
|
822
|
+
this._masked = false;
|
|
823
|
+
this._fin = false;
|
|
824
|
+
this._opcode = 0;
|
|
825
|
+
this._totalPayloadLength = 0;
|
|
826
|
+
this._messageLength = 0;
|
|
827
|
+
this._fragments = [];
|
|
828
|
+
this._errored = false;
|
|
829
|
+
this._loop = false;
|
|
830
|
+
this._state = GET_INFO;
|
|
831
|
+
}
|
|
832
|
+
_write(chunk, encoding, cb) {
|
|
833
|
+
if (this._opcode === 8 && this._state == GET_INFO) return cb();
|
|
834
|
+
this._bufferedBytes += chunk.length;
|
|
835
|
+
this._buffers.push(chunk);
|
|
836
|
+
this.startLoop(cb);
|
|
837
|
+
}
|
|
838
|
+
consume(n) {
|
|
839
|
+
this._bufferedBytes -= n;
|
|
840
|
+
if (n === this._buffers[0].length) return this._buffers.shift();
|
|
841
|
+
if (n < this._buffers[0].length) {
|
|
842
|
+
const buf = this._buffers[0];
|
|
843
|
+
this._buffers[0] = new FastBuffer(
|
|
844
|
+
buf.buffer,
|
|
845
|
+
buf.byteOffset + n,
|
|
846
|
+
buf.length - n,
|
|
847
|
+
);
|
|
848
|
+
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
849
|
+
}
|
|
850
|
+
const dst = Buffer.allocUnsafe(n);
|
|
851
|
+
do {
|
|
852
|
+
const buf = this._buffers[0];
|
|
853
|
+
const offset = dst.length - n;
|
|
854
|
+
if (n >= buf.length) {
|
|
855
|
+
dst.set(this._buffers.shift(), offset);
|
|
856
|
+
} else {
|
|
857
|
+
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
858
|
+
this._buffers[0] = new FastBuffer(
|
|
859
|
+
buf.buffer,
|
|
860
|
+
buf.byteOffset + n,
|
|
861
|
+
buf.length - n,
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
n -= buf.length;
|
|
865
|
+
} while (n > 0);
|
|
866
|
+
return dst;
|
|
867
|
+
}
|
|
868
|
+
startLoop(cb) {
|
|
869
|
+
this._loop = true;
|
|
870
|
+
do {
|
|
871
|
+
switch (this._state) {
|
|
872
|
+
case GET_INFO:
|
|
873
|
+
this.getInfo(cb);
|
|
874
|
+
break;
|
|
875
|
+
case GET_PAYLOAD_LENGTH_16:
|
|
876
|
+
this.getPayloadLength16(cb);
|
|
877
|
+
break;
|
|
878
|
+
case GET_PAYLOAD_LENGTH_64:
|
|
879
|
+
this.getPayloadLength64(cb);
|
|
880
|
+
break;
|
|
881
|
+
case GET_MASK:
|
|
882
|
+
this.getMask();
|
|
883
|
+
break;
|
|
884
|
+
case GET_DATA:
|
|
885
|
+
this.getData(cb);
|
|
886
|
+
break;
|
|
887
|
+
case INFLATING:
|
|
888
|
+
case DEFER_EVENT:
|
|
889
|
+
this._loop = false;
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
} while (this._loop);
|
|
893
|
+
if (!this._errored) cb();
|
|
894
|
+
}
|
|
895
|
+
getInfo(cb) {
|
|
896
|
+
if (this._bufferedBytes < 2) {
|
|
897
|
+
this._loop = false;
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const buf = this.consume(2);
|
|
901
|
+
if ((buf[0] & 48) !== 0) {
|
|
902
|
+
const error = this.createError(
|
|
903
|
+
RangeError,
|
|
904
|
+
"RSV2 and RSV3 must be clear",
|
|
905
|
+
true,
|
|
906
|
+
1002,
|
|
907
|
+
"WS_ERR_UNEXPECTED_RSV_2_3",
|
|
908
|
+
);
|
|
909
|
+
cb(error);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
const compressed = (buf[0] & 64) === 64;
|
|
913
|
+
if (
|
|
914
|
+
compressed &&
|
|
915
|
+
!this._extensions[PerMessageDeflate.extensionName]
|
|
916
|
+
) {
|
|
917
|
+
const error = this.createError(
|
|
918
|
+
RangeError,
|
|
919
|
+
"RSV1 must be clear",
|
|
920
|
+
true,
|
|
921
|
+
1002,
|
|
922
|
+
"WS_ERR_UNEXPECTED_RSV_1",
|
|
923
|
+
);
|
|
924
|
+
cb(error);
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
this._fin = (buf[0] & 128) === 128;
|
|
928
|
+
this._opcode = buf[0] & 15;
|
|
929
|
+
this._payloadLength = buf[1] & 127;
|
|
930
|
+
if (this._opcode === 0) {
|
|
931
|
+
if (compressed) {
|
|
932
|
+
const error = this.createError(
|
|
933
|
+
RangeError,
|
|
934
|
+
"RSV1 must be clear",
|
|
935
|
+
true,
|
|
936
|
+
1002,
|
|
937
|
+
"WS_ERR_UNEXPECTED_RSV_1",
|
|
938
|
+
);
|
|
939
|
+
cb(error);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
942
|
+
if (!this._fragmented) {
|
|
943
|
+
const error = this.createError(
|
|
944
|
+
RangeError,
|
|
945
|
+
"invalid opcode 0",
|
|
946
|
+
true,
|
|
947
|
+
1002,
|
|
948
|
+
"WS_ERR_INVALID_OPCODE",
|
|
949
|
+
);
|
|
950
|
+
cb(error);
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
this._opcode = this._fragmented;
|
|
954
|
+
} else if (this._opcode === 1 || this._opcode === 2) {
|
|
955
|
+
if (this._fragmented) {
|
|
956
|
+
const error = this.createError(
|
|
957
|
+
RangeError,
|
|
958
|
+
`invalid opcode ${this._opcode}`,
|
|
959
|
+
true,
|
|
960
|
+
1002,
|
|
961
|
+
"WS_ERR_INVALID_OPCODE",
|
|
962
|
+
);
|
|
963
|
+
cb(error);
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
this._compressed = compressed;
|
|
967
|
+
} else if (this._opcode > 7 && this._opcode < 11) {
|
|
968
|
+
if (!this._fin) {
|
|
969
|
+
const error = this.createError(
|
|
970
|
+
RangeError,
|
|
971
|
+
"FIN must be set",
|
|
972
|
+
true,
|
|
973
|
+
1002,
|
|
974
|
+
"WS_ERR_EXPECTED_FIN",
|
|
975
|
+
);
|
|
976
|
+
cb(error);
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
if (compressed) {
|
|
980
|
+
const error = this.createError(
|
|
981
|
+
RangeError,
|
|
982
|
+
"RSV1 must be clear",
|
|
983
|
+
true,
|
|
984
|
+
1002,
|
|
985
|
+
"WS_ERR_UNEXPECTED_RSV_1",
|
|
986
|
+
);
|
|
987
|
+
cb(error);
|
|
988
|
+
return;
|
|
989
|
+
}
|
|
990
|
+
if (
|
|
991
|
+
this._payloadLength > 125 ||
|
|
992
|
+
(this._opcode === 8 && this._payloadLength === 1)
|
|
993
|
+
) {
|
|
994
|
+
const error = this.createError(
|
|
995
|
+
RangeError,
|
|
996
|
+
`invalid payload length ${this._payloadLength}`,
|
|
997
|
+
true,
|
|
998
|
+
1002,
|
|
999
|
+
"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH",
|
|
1000
|
+
);
|
|
1001
|
+
cb(error);
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
} else {
|
|
1005
|
+
const error = this.createError(
|
|
1006
|
+
RangeError,
|
|
1007
|
+
`invalid opcode ${this._opcode}`,
|
|
1008
|
+
true,
|
|
1009
|
+
1002,
|
|
1010
|
+
"WS_ERR_INVALID_OPCODE",
|
|
1011
|
+
);
|
|
1012
|
+
cb(error);
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
1016
|
+
this._masked = (buf[1] & 128) === 128;
|
|
1017
|
+
if (this._isServer) {
|
|
1018
|
+
if (!this._masked) {
|
|
1019
|
+
const error = this.createError(
|
|
1020
|
+
RangeError,
|
|
1021
|
+
"MASK must be set",
|
|
1022
|
+
true,
|
|
1023
|
+
1002,
|
|
1024
|
+
"WS_ERR_EXPECTED_MASK",
|
|
1025
|
+
);
|
|
1026
|
+
cb(error);
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1029
|
+
} else if (this._masked) {
|
|
1030
|
+
const error = this.createError(
|
|
1031
|
+
RangeError,
|
|
1032
|
+
"MASK must be clear",
|
|
1033
|
+
true,
|
|
1034
|
+
1002,
|
|
1035
|
+
"WS_ERR_UNEXPECTED_MASK",
|
|
1036
|
+
);
|
|
1037
|
+
cb(error);
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
1041
|
+
else if (this._payloadLength === 127)
|
|
1042
|
+
this._state = GET_PAYLOAD_LENGTH_64;
|
|
1043
|
+
else this.haveLength(cb);
|
|
1044
|
+
}
|
|
1045
|
+
getPayloadLength16(cb) {
|
|
1046
|
+
if (this._bufferedBytes < 2) {
|
|
1047
|
+
this._loop = false;
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
1051
|
+
this.haveLength(cb);
|
|
1052
|
+
}
|
|
1053
|
+
getPayloadLength64(cb) {
|
|
1054
|
+
if (this._bufferedBytes < 8) {
|
|
1055
|
+
this._loop = false;
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
const buf = this.consume(8);
|
|
1059
|
+
const num = buf.readUInt32BE(0);
|
|
1060
|
+
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
1061
|
+
const error = this.createError(
|
|
1062
|
+
RangeError,
|
|
1063
|
+
"Unsupported WebSocket frame: payload length > 2^53 - 1",
|
|
1064
|
+
false,
|
|
1065
|
+
1009,
|
|
1066
|
+
"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH",
|
|
1067
|
+
);
|
|
1068
|
+
cb(error);
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
1072
|
+
this.haveLength(cb);
|
|
1073
|
+
}
|
|
1074
|
+
haveLength(cb) {
|
|
1075
|
+
if (this._payloadLength && this._opcode < 8) {
|
|
1076
|
+
this._totalPayloadLength += this._payloadLength;
|
|
1077
|
+
if (
|
|
1078
|
+
this._totalPayloadLength > this._maxPayload &&
|
|
1079
|
+
this._maxPayload > 0
|
|
1080
|
+
) {
|
|
1081
|
+
const error = this.createError(
|
|
1082
|
+
RangeError,
|
|
1083
|
+
"Max payload size exceeded",
|
|
1084
|
+
false,
|
|
1085
|
+
1009,
|
|
1086
|
+
"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",
|
|
1087
|
+
);
|
|
1088
|
+
cb(error);
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
if (this._masked) this._state = GET_MASK;
|
|
1093
|
+
else this._state = GET_DATA;
|
|
1094
|
+
}
|
|
1095
|
+
getMask() {
|
|
1096
|
+
if (this._bufferedBytes < 4) {
|
|
1097
|
+
this._loop = false;
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
this._mask = this.consume(4);
|
|
1101
|
+
this._state = GET_DATA;
|
|
1102
|
+
}
|
|
1103
|
+
getData(cb) {
|
|
1104
|
+
let data = EMPTY_BUFFER;
|
|
1105
|
+
if (this._payloadLength) {
|
|
1106
|
+
if (this._bufferedBytes < this._payloadLength) {
|
|
1107
|
+
this._loop = false;
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
data = this.consume(this._payloadLength);
|
|
1111
|
+
if (
|
|
1112
|
+
this._masked &&
|
|
1113
|
+
(this._mask[0] |
|
|
1114
|
+
this._mask[1] |
|
|
1115
|
+
this._mask[2] |
|
|
1116
|
+
this._mask[3]) !==
|
|
1117
|
+
0
|
|
1118
|
+
) {
|
|
1119
|
+
unmask(data, this._mask);
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
if (this._opcode > 7) {
|
|
1123
|
+
this.controlMessage(data, cb);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
if (this._compressed) {
|
|
1127
|
+
this._state = INFLATING;
|
|
1128
|
+
this.decompress(data, cb);
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
if (data.length) {
|
|
1132
|
+
this._messageLength = this._totalPayloadLength;
|
|
1133
|
+
this._fragments.push(data);
|
|
1134
|
+
}
|
|
1135
|
+
this.dataMessage(cb);
|
|
1136
|
+
}
|
|
1137
|
+
decompress(data, cb) {
|
|
1138
|
+
const perMessageDeflate =
|
|
1139
|
+
this._extensions[PerMessageDeflate.extensionName];
|
|
1140
|
+
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
1141
|
+
if (err) return cb(err);
|
|
1142
|
+
if (buf.length) {
|
|
1143
|
+
this._messageLength += buf.length;
|
|
1144
|
+
if (
|
|
1145
|
+
this._messageLength > this._maxPayload &&
|
|
1146
|
+
this._maxPayload > 0
|
|
1147
|
+
) {
|
|
1148
|
+
const error = this.createError(
|
|
1149
|
+
RangeError,
|
|
1150
|
+
"Max payload size exceeded",
|
|
1151
|
+
false,
|
|
1152
|
+
1009,
|
|
1153
|
+
"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",
|
|
1154
|
+
);
|
|
1155
|
+
cb(error);
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
this._fragments.push(buf);
|
|
1159
|
+
}
|
|
1160
|
+
this.dataMessage(cb);
|
|
1161
|
+
if (this._state === GET_INFO) this.startLoop(cb);
|
|
1162
|
+
});
|
|
1163
|
+
}
|
|
1164
|
+
dataMessage(cb) {
|
|
1165
|
+
if (!this._fin) {
|
|
1166
|
+
this._state = GET_INFO;
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
const messageLength = this._messageLength;
|
|
1170
|
+
const fragments = this._fragments;
|
|
1171
|
+
this._totalPayloadLength = 0;
|
|
1172
|
+
this._messageLength = 0;
|
|
1173
|
+
this._fragmented = 0;
|
|
1174
|
+
this._fragments = [];
|
|
1175
|
+
if (this._opcode === 2) {
|
|
1176
|
+
let data;
|
|
1177
|
+
if (this._binaryType === "nodebuffer") {
|
|
1178
|
+
data = concat(fragments, messageLength);
|
|
1179
|
+
} else if (this._binaryType === "arraybuffer") {
|
|
1180
|
+
data = toArrayBuffer(concat(fragments, messageLength));
|
|
1181
|
+
} else if (this._binaryType === "blob") {
|
|
1182
|
+
data = new Blob(fragments);
|
|
1183
|
+
} else {
|
|
1184
|
+
data = fragments;
|
|
1185
|
+
}
|
|
1186
|
+
if (this._allowSynchronousEvents) {
|
|
1187
|
+
this.emit("message", data, true);
|
|
1188
|
+
this._state = GET_INFO;
|
|
1189
|
+
} else {
|
|
1190
|
+
this._state = DEFER_EVENT;
|
|
1191
|
+
setImmediate(() => {
|
|
1192
|
+
this.emit("message", data, true);
|
|
1193
|
+
this._state = GET_INFO;
|
|
1194
|
+
this.startLoop(cb);
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
} else {
|
|
1198
|
+
const buf = concat(fragments, messageLength);
|
|
1199
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
1200
|
+
const error = this.createError(
|
|
1201
|
+
Error,
|
|
1202
|
+
"invalid UTF-8 sequence",
|
|
1203
|
+
true,
|
|
1204
|
+
1007,
|
|
1205
|
+
"WS_ERR_INVALID_UTF8",
|
|
1206
|
+
);
|
|
1207
|
+
cb(error);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
if (this._state === INFLATING || this._allowSynchronousEvents) {
|
|
1211
|
+
this.emit("message", buf, false);
|
|
1212
|
+
this._state = GET_INFO;
|
|
1213
|
+
} else {
|
|
1214
|
+
this._state = DEFER_EVENT;
|
|
1215
|
+
setImmediate(() => {
|
|
1216
|
+
this.emit("message", buf, false);
|
|
1217
|
+
this._state = GET_INFO;
|
|
1218
|
+
this.startLoop(cb);
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
controlMessage(data, cb) {
|
|
1224
|
+
if (this._opcode === 8) {
|
|
1225
|
+
if (data.length === 0) {
|
|
1226
|
+
this._loop = false;
|
|
1227
|
+
this.emit("conclude", 1005, EMPTY_BUFFER);
|
|
1228
|
+
this.end();
|
|
1229
|
+
} else {
|
|
1230
|
+
const code = data.readUInt16BE(0);
|
|
1231
|
+
if (!isValidStatusCode(code)) {
|
|
1232
|
+
const error = this.createError(
|
|
1233
|
+
RangeError,
|
|
1234
|
+
`invalid status code ${code}`,
|
|
1235
|
+
true,
|
|
1236
|
+
1002,
|
|
1237
|
+
"WS_ERR_INVALID_CLOSE_CODE",
|
|
1238
|
+
);
|
|
1239
|
+
cb(error);
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
const buf = new FastBuffer(
|
|
1243
|
+
data.buffer,
|
|
1244
|
+
data.byteOffset + 2,
|
|
1245
|
+
data.length - 2,
|
|
1246
|
+
);
|
|
1247
|
+
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
1248
|
+
const error = this.createError(
|
|
1249
|
+
Error,
|
|
1250
|
+
"invalid UTF-8 sequence",
|
|
1251
|
+
true,
|
|
1252
|
+
1007,
|
|
1253
|
+
"WS_ERR_INVALID_UTF8",
|
|
1254
|
+
);
|
|
1255
|
+
cb(error);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
this._loop = false;
|
|
1259
|
+
this.emit("conclude", code, buf);
|
|
1260
|
+
this.end();
|
|
1261
|
+
}
|
|
1262
|
+
this._state = GET_INFO;
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
if (this._allowSynchronousEvents) {
|
|
1266
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
1267
|
+
this._state = GET_INFO;
|
|
1268
|
+
} else {
|
|
1269
|
+
this._state = DEFER_EVENT;
|
|
1270
|
+
setImmediate(() => {
|
|
1271
|
+
this.emit(this._opcode === 9 ? "ping" : "pong", data);
|
|
1272
|
+
this._state = GET_INFO;
|
|
1273
|
+
this.startLoop(cb);
|
|
1274
|
+
});
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
createError(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
1278
|
+
this._loop = false;
|
|
1279
|
+
this._errored = true;
|
|
1280
|
+
const err = new ErrorCtor(
|
|
1281
|
+
prefix ? `Invalid WebSocket frame: ${message}` : message,
|
|
1282
|
+
);
|
|
1283
|
+
Error.captureStackTrace(err, this.createError);
|
|
1284
|
+
err.code = errorCode;
|
|
1285
|
+
err[kStatusCode] = statusCode;
|
|
1286
|
+
return err;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
module.exports = Receiver;
|
|
1290
|
+
},
|
|
1291
|
+
480: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
1292
|
+
"use strict";
|
|
1293
|
+
const { Duplex } = __nccwpck_require__(203);
|
|
1294
|
+
const { randomFillSync } = __nccwpck_require__(982);
|
|
1295
|
+
const PerMessageDeflate = __nccwpck_require__(465);
|
|
1296
|
+
const { EMPTY_BUFFER, kWebSocket, NOOP } = __nccwpck_require__(892);
|
|
1297
|
+
const { isBlob, isValidStatusCode } = __nccwpck_require__(342);
|
|
1298
|
+
const { mask: applyMask, toBuffer } = __nccwpck_require__(72);
|
|
1299
|
+
const kByteLength = Symbol("kByteLength");
|
|
1300
|
+
const maskBuffer = Buffer.alloc(4);
|
|
1301
|
+
const RANDOM_POOL_SIZE = 8 * 1024;
|
|
1302
|
+
let randomPool;
|
|
1303
|
+
let randomPoolPointer = RANDOM_POOL_SIZE;
|
|
1304
|
+
const DEFAULT = 0;
|
|
1305
|
+
const DEFLATING = 1;
|
|
1306
|
+
const GET_BLOB_DATA = 2;
|
|
1307
|
+
class Sender {
|
|
1308
|
+
constructor(socket, extensions, generateMask) {
|
|
1309
|
+
this._extensions = extensions || {};
|
|
1310
|
+
if (generateMask) {
|
|
1311
|
+
this._generateMask = generateMask;
|
|
1312
|
+
this._maskBuffer = Buffer.alloc(4);
|
|
1313
|
+
}
|
|
1314
|
+
this._socket = socket;
|
|
1315
|
+
this._firstFragment = true;
|
|
1316
|
+
this._compress = false;
|
|
1317
|
+
this._bufferedBytes = 0;
|
|
1318
|
+
this._queue = [];
|
|
1319
|
+
this._state = DEFAULT;
|
|
1320
|
+
this.onerror = NOOP;
|
|
1321
|
+
this[kWebSocket] = undefined;
|
|
1322
|
+
}
|
|
1323
|
+
static frame(data, options) {
|
|
1324
|
+
let mask;
|
|
1325
|
+
let merge = false;
|
|
1326
|
+
let offset = 2;
|
|
1327
|
+
let skipMasking = false;
|
|
1328
|
+
if (options.mask) {
|
|
1329
|
+
mask = options.maskBuffer || maskBuffer;
|
|
1330
|
+
if (options.generateMask) {
|
|
1331
|
+
options.generateMask(mask);
|
|
1332
|
+
} else {
|
|
1333
|
+
if (randomPoolPointer === RANDOM_POOL_SIZE) {
|
|
1334
|
+
if (randomPool === undefined) {
|
|
1335
|
+
randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
|
|
1336
|
+
}
|
|
1337
|
+
randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
|
|
1338
|
+
randomPoolPointer = 0;
|
|
1339
|
+
}
|
|
1340
|
+
mask[0] = randomPool[randomPoolPointer++];
|
|
1341
|
+
mask[1] = randomPool[randomPoolPointer++];
|
|
1342
|
+
mask[2] = randomPool[randomPoolPointer++];
|
|
1343
|
+
mask[3] = randomPool[randomPoolPointer++];
|
|
1344
|
+
}
|
|
1345
|
+
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
1346
|
+
offset = 6;
|
|
1347
|
+
}
|
|
1348
|
+
let dataLength;
|
|
1349
|
+
if (typeof data === "string") {
|
|
1350
|
+
if (
|
|
1351
|
+
(!options.mask || skipMasking) &&
|
|
1352
|
+
options[kByteLength] !== undefined
|
|
1353
|
+
) {
|
|
1354
|
+
dataLength = options[kByteLength];
|
|
1355
|
+
} else {
|
|
1356
|
+
data = Buffer.from(data);
|
|
1357
|
+
dataLength = data.length;
|
|
1358
|
+
}
|
|
1359
|
+
} else {
|
|
1360
|
+
dataLength = data.length;
|
|
1361
|
+
merge = options.mask && options.readOnly && !skipMasking;
|
|
1362
|
+
}
|
|
1363
|
+
let payloadLength = dataLength;
|
|
1364
|
+
if (dataLength >= 65536) {
|
|
1365
|
+
offset += 8;
|
|
1366
|
+
payloadLength = 127;
|
|
1367
|
+
} else if (dataLength > 125) {
|
|
1368
|
+
offset += 2;
|
|
1369
|
+
payloadLength = 126;
|
|
1370
|
+
}
|
|
1371
|
+
const target = Buffer.allocUnsafe(
|
|
1372
|
+
merge ? dataLength + offset : offset,
|
|
1373
|
+
);
|
|
1374
|
+
target[0] = options.fin ? options.opcode | 128 : options.opcode;
|
|
1375
|
+
if (options.rsv1) target[0] |= 64;
|
|
1376
|
+
target[1] = payloadLength;
|
|
1377
|
+
if (payloadLength === 126) {
|
|
1378
|
+
target.writeUInt16BE(dataLength, 2);
|
|
1379
|
+
} else if (payloadLength === 127) {
|
|
1380
|
+
target[2] = target[3] = 0;
|
|
1381
|
+
target.writeUIntBE(dataLength, 4, 6);
|
|
1382
|
+
}
|
|
1383
|
+
if (!options.mask) return [target, data];
|
|
1384
|
+
target[1] |= 128;
|
|
1385
|
+
target[offset - 4] = mask[0];
|
|
1386
|
+
target[offset - 3] = mask[1];
|
|
1387
|
+
target[offset - 2] = mask[2];
|
|
1388
|
+
target[offset - 1] = mask[3];
|
|
1389
|
+
if (skipMasking) return [target, data];
|
|
1390
|
+
if (merge) {
|
|
1391
|
+
applyMask(data, mask, target, offset, dataLength);
|
|
1392
|
+
return [target];
|
|
1393
|
+
}
|
|
1394
|
+
applyMask(data, mask, data, 0, dataLength);
|
|
1395
|
+
return [target, data];
|
|
1396
|
+
}
|
|
1397
|
+
close(code, data, mask, cb) {
|
|
1398
|
+
let buf;
|
|
1399
|
+
if (code === undefined) {
|
|
1400
|
+
buf = EMPTY_BUFFER;
|
|
1401
|
+
} else if (typeof code !== "number" || !isValidStatusCode(code)) {
|
|
1402
|
+
throw new TypeError(
|
|
1403
|
+
"First argument must be a valid error code number",
|
|
1404
|
+
);
|
|
1405
|
+
} else if (data === undefined || !data.length) {
|
|
1406
|
+
buf = Buffer.allocUnsafe(2);
|
|
1407
|
+
buf.writeUInt16BE(code, 0);
|
|
1408
|
+
} else {
|
|
1409
|
+
const length = Buffer.byteLength(data);
|
|
1410
|
+
if (length > 123) {
|
|
1411
|
+
throw new RangeError(
|
|
1412
|
+
"The message must not be greater than 123 bytes",
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
buf = Buffer.allocUnsafe(2 + length);
|
|
1416
|
+
buf.writeUInt16BE(code, 0);
|
|
1417
|
+
if (typeof data === "string") {
|
|
1418
|
+
buf.write(data, 2);
|
|
1419
|
+
} else {
|
|
1420
|
+
buf.set(data, 2);
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
const options = {
|
|
1424
|
+
[kByteLength]: buf.length,
|
|
1425
|
+
fin: true,
|
|
1426
|
+
generateMask: this._generateMask,
|
|
1427
|
+
mask,
|
|
1428
|
+
maskBuffer: this._maskBuffer,
|
|
1429
|
+
opcode: 8,
|
|
1430
|
+
readOnly: false,
|
|
1431
|
+
rsv1: false,
|
|
1432
|
+
};
|
|
1433
|
+
if (this._state !== DEFAULT) {
|
|
1434
|
+
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
1435
|
+
} else {
|
|
1436
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
ping(data, mask, cb) {
|
|
1440
|
+
let byteLength;
|
|
1441
|
+
let readOnly;
|
|
1442
|
+
if (typeof data === "string") {
|
|
1443
|
+
byteLength = Buffer.byteLength(data);
|
|
1444
|
+
readOnly = false;
|
|
1445
|
+
} else if (isBlob(data)) {
|
|
1446
|
+
byteLength = data.size;
|
|
1447
|
+
readOnly = false;
|
|
1448
|
+
} else {
|
|
1449
|
+
data = toBuffer(data);
|
|
1450
|
+
byteLength = data.length;
|
|
1451
|
+
readOnly = toBuffer.readOnly;
|
|
1452
|
+
}
|
|
1453
|
+
if (byteLength > 125) {
|
|
1454
|
+
throw new RangeError(
|
|
1455
|
+
"The data size must not be greater than 125 bytes",
|
|
1456
|
+
);
|
|
1457
|
+
}
|
|
1458
|
+
const options = {
|
|
1459
|
+
[kByteLength]: byteLength,
|
|
1460
|
+
fin: true,
|
|
1461
|
+
generateMask: this._generateMask,
|
|
1462
|
+
mask,
|
|
1463
|
+
maskBuffer: this._maskBuffer,
|
|
1464
|
+
opcode: 9,
|
|
1465
|
+
readOnly,
|
|
1466
|
+
rsv1: false,
|
|
1467
|
+
};
|
|
1468
|
+
if (isBlob(data)) {
|
|
1469
|
+
if (this._state !== DEFAULT) {
|
|
1470
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
1471
|
+
} else {
|
|
1472
|
+
this.getBlobData(data, false, options, cb);
|
|
1473
|
+
}
|
|
1474
|
+
} else if (this._state !== DEFAULT) {
|
|
1475
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1476
|
+
} else {
|
|
1477
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
pong(data, mask, cb) {
|
|
1481
|
+
let byteLength;
|
|
1482
|
+
let readOnly;
|
|
1483
|
+
if (typeof data === "string") {
|
|
1484
|
+
byteLength = Buffer.byteLength(data);
|
|
1485
|
+
readOnly = false;
|
|
1486
|
+
} else if (isBlob(data)) {
|
|
1487
|
+
byteLength = data.size;
|
|
1488
|
+
readOnly = false;
|
|
1489
|
+
} else {
|
|
1490
|
+
data = toBuffer(data);
|
|
1491
|
+
byteLength = data.length;
|
|
1492
|
+
readOnly = toBuffer.readOnly;
|
|
1493
|
+
}
|
|
1494
|
+
if (byteLength > 125) {
|
|
1495
|
+
throw new RangeError(
|
|
1496
|
+
"The data size must not be greater than 125 bytes",
|
|
1497
|
+
);
|
|
1498
|
+
}
|
|
1499
|
+
const options = {
|
|
1500
|
+
[kByteLength]: byteLength,
|
|
1501
|
+
fin: true,
|
|
1502
|
+
generateMask: this._generateMask,
|
|
1503
|
+
mask,
|
|
1504
|
+
maskBuffer: this._maskBuffer,
|
|
1505
|
+
opcode: 10,
|
|
1506
|
+
readOnly,
|
|
1507
|
+
rsv1: false,
|
|
1508
|
+
};
|
|
1509
|
+
if (isBlob(data)) {
|
|
1510
|
+
if (this._state !== DEFAULT) {
|
|
1511
|
+
this.enqueue([this.getBlobData, data, false, options, cb]);
|
|
1512
|
+
} else {
|
|
1513
|
+
this.getBlobData(data, false, options, cb);
|
|
1514
|
+
}
|
|
1515
|
+
} else if (this._state !== DEFAULT) {
|
|
1516
|
+
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1517
|
+
} else {
|
|
1518
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
send(data, options, cb) {
|
|
1522
|
+
const perMessageDeflate =
|
|
1523
|
+
this._extensions[PerMessageDeflate.extensionName];
|
|
1524
|
+
let opcode = options.binary ? 2 : 1;
|
|
1525
|
+
let rsv1 = options.compress;
|
|
1526
|
+
let byteLength;
|
|
1527
|
+
let readOnly;
|
|
1528
|
+
if (typeof data === "string") {
|
|
1529
|
+
byteLength = Buffer.byteLength(data);
|
|
1530
|
+
readOnly = false;
|
|
1531
|
+
} else if (isBlob(data)) {
|
|
1532
|
+
byteLength = data.size;
|
|
1533
|
+
readOnly = false;
|
|
1534
|
+
} else {
|
|
1535
|
+
data = toBuffer(data);
|
|
1536
|
+
byteLength = data.length;
|
|
1537
|
+
readOnly = toBuffer.readOnly;
|
|
1538
|
+
}
|
|
1539
|
+
if (this._firstFragment) {
|
|
1540
|
+
this._firstFragment = false;
|
|
1541
|
+
if (
|
|
1542
|
+
rsv1 &&
|
|
1543
|
+
perMessageDeflate &&
|
|
1544
|
+
perMessageDeflate.params[
|
|
1545
|
+
perMessageDeflate._isServer
|
|
1546
|
+
? "server_no_context_takeover"
|
|
1547
|
+
: "client_no_context_takeover"
|
|
1548
|
+
]
|
|
1549
|
+
) {
|
|
1550
|
+
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
1551
|
+
}
|
|
1552
|
+
this._compress = rsv1;
|
|
1553
|
+
} else {
|
|
1554
|
+
rsv1 = false;
|
|
1555
|
+
opcode = 0;
|
|
1556
|
+
}
|
|
1557
|
+
if (options.fin) this._firstFragment = true;
|
|
1558
|
+
const opts = {
|
|
1559
|
+
[kByteLength]: byteLength,
|
|
1560
|
+
fin: options.fin,
|
|
1561
|
+
generateMask: this._generateMask,
|
|
1562
|
+
mask: options.mask,
|
|
1563
|
+
maskBuffer: this._maskBuffer,
|
|
1564
|
+
opcode,
|
|
1565
|
+
readOnly,
|
|
1566
|
+
rsv1,
|
|
1567
|
+
};
|
|
1568
|
+
if (isBlob(data)) {
|
|
1569
|
+
if (this._state !== DEFAULT) {
|
|
1570
|
+
this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
|
|
1571
|
+
} else {
|
|
1572
|
+
this.getBlobData(data, this._compress, opts, cb);
|
|
1573
|
+
}
|
|
1574
|
+
} else if (this._state !== DEFAULT) {
|
|
1575
|
+
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
1576
|
+
} else {
|
|
1577
|
+
this.dispatch(data, this._compress, opts, cb);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
getBlobData(blob, compress, options, cb) {
|
|
1581
|
+
this._bufferedBytes += options[kByteLength];
|
|
1582
|
+
this._state = GET_BLOB_DATA;
|
|
1583
|
+
blob
|
|
1584
|
+
.arrayBuffer()
|
|
1585
|
+
.then((arrayBuffer) => {
|
|
1586
|
+
if (this._socket.destroyed) {
|
|
1587
|
+
const err = new Error(
|
|
1588
|
+
"The socket was closed while the blob was being read",
|
|
1589
|
+
);
|
|
1590
|
+
process.nextTick(callCallbacks, this, err, cb);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1593
|
+
this._bufferedBytes -= options[kByteLength];
|
|
1594
|
+
const data = toBuffer(arrayBuffer);
|
|
1595
|
+
if (!compress) {
|
|
1596
|
+
this._state = DEFAULT;
|
|
1597
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1598
|
+
this.dequeue();
|
|
1599
|
+
} else {
|
|
1600
|
+
this.dispatch(data, compress, options, cb);
|
|
1601
|
+
}
|
|
1602
|
+
})
|
|
1603
|
+
.catch((err) => {
|
|
1604
|
+
process.nextTick(onError, this, err, cb);
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
dispatch(data, compress, options, cb) {
|
|
1608
|
+
if (!compress) {
|
|
1609
|
+
this.sendFrame(Sender.frame(data, options), cb);
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
const perMessageDeflate =
|
|
1613
|
+
this._extensions[PerMessageDeflate.extensionName];
|
|
1614
|
+
this._bufferedBytes += options[kByteLength];
|
|
1615
|
+
this._state = DEFLATING;
|
|
1616
|
+
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
1617
|
+
if (this._socket.destroyed) {
|
|
1618
|
+
const err = new Error(
|
|
1619
|
+
"The socket was closed while data was being compressed",
|
|
1620
|
+
);
|
|
1621
|
+
callCallbacks(this, err, cb);
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
this._bufferedBytes -= options[kByteLength];
|
|
1625
|
+
this._state = DEFAULT;
|
|
1626
|
+
options.readOnly = false;
|
|
1627
|
+
this.sendFrame(Sender.frame(buf, options), cb);
|
|
1628
|
+
this.dequeue();
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
dequeue() {
|
|
1632
|
+
while (this._state === DEFAULT && this._queue.length) {
|
|
1633
|
+
const params = this._queue.shift();
|
|
1634
|
+
this._bufferedBytes -= params[3][kByteLength];
|
|
1635
|
+
Reflect.apply(params[0], this, params.slice(1));
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
enqueue(params) {
|
|
1639
|
+
this._bufferedBytes += params[3][kByteLength];
|
|
1640
|
+
this._queue.push(params);
|
|
1641
|
+
}
|
|
1642
|
+
sendFrame(list, cb) {
|
|
1643
|
+
if (list.length === 2) {
|
|
1644
|
+
this._socket.cork();
|
|
1645
|
+
this._socket.write(list[0]);
|
|
1646
|
+
this._socket.write(list[1], cb);
|
|
1647
|
+
this._socket.uncork();
|
|
1648
|
+
} else {
|
|
1649
|
+
this._socket.write(list[0], cb);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
module.exports = Sender;
|
|
1654
|
+
function callCallbacks(sender, err, cb) {
|
|
1655
|
+
if (typeof cb === "function") cb(err);
|
|
1656
|
+
for (let i = 0; i < sender._queue.length; i++) {
|
|
1657
|
+
const params = sender._queue[i];
|
|
1658
|
+
const callback = params[params.length - 1];
|
|
1659
|
+
if (typeof callback === "function") callback(err);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function onError(sender, err, cb) {
|
|
1663
|
+
callCallbacks(sender, err, cb);
|
|
1664
|
+
sender.onerror(err);
|
|
1665
|
+
}
|
|
1666
|
+
},
|
|
1667
|
+
297: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
1668
|
+
"use strict";
|
|
1669
|
+
const WebSocket = __nccwpck_require__(234);
|
|
1670
|
+
const { Duplex } = __nccwpck_require__(203);
|
|
1671
|
+
function emitClose(stream) {
|
|
1672
|
+
stream.emit("close");
|
|
1673
|
+
}
|
|
1674
|
+
function duplexOnEnd() {
|
|
1675
|
+
if (!this.destroyed && this._writableState.finished) {
|
|
1676
|
+
this.destroy();
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
function duplexOnError(err) {
|
|
1680
|
+
this.removeListener("error", duplexOnError);
|
|
1681
|
+
this.destroy();
|
|
1682
|
+
if (this.listenerCount("error") === 0) {
|
|
1683
|
+
this.emit("error", err);
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
function createWebSocketStream(ws, options) {
|
|
1687
|
+
let terminateOnDestroy = true;
|
|
1688
|
+
const duplex = new Duplex({
|
|
1689
|
+
...options,
|
|
1690
|
+
autoDestroy: false,
|
|
1691
|
+
emitClose: false,
|
|
1692
|
+
objectMode: false,
|
|
1693
|
+
writableObjectMode: false,
|
|
1694
|
+
});
|
|
1695
|
+
ws.on("message", function message(msg, isBinary) {
|
|
1696
|
+
const data =
|
|
1697
|
+
!isBinary && duplex._readableState.objectMode
|
|
1698
|
+
? msg.toString()
|
|
1699
|
+
: msg;
|
|
1700
|
+
if (!duplex.push(data)) ws.pause();
|
|
1701
|
+
});
|
|
1702
|
+
ws.once("error", function error(err) {
|
|
1703
|
+
if (duplex.destroyed) return;
|
|
1704
|
+
terminateOnDestroy = false;
|
|
1705
|
+
duplex.destroy(err);
|
|
1706
|
+
});
|
|
1707
|
+
ws.once("close", function close() {
|
|
1708
|
+
if (duplex.destroyed) return;
|
|
1709
|
+
duplex.push(null);
|
|
1710
|
+
});
|
|
1711
|
+
duplex._destroy = function (err, callback) {
|
|
1712
|
+
if (ws.readyState === ws.CLOSED) {
|
|
1713
|
+
callback(err);
|
|
1714
|
+
process.nextTick(emitClose, duplex);
|
|
1715
|
+
return;
|
|
1716
|
+
}
|
|
1717
|
+
let called = false;
|
|
1718
|
+
ws.once("error", function error(err) {
|
|
1719
|
+
called = true;
|
|
1720
|
+
callback(err);
|
|
1721
|
+
});
|
|
1722
|
+
ws.once("close", function close() {
|
|
1723
|
+
if (!called) callback(err);
|
|
1724
|
+
process.nextTick(emitClose, duplex);
|
|
1725
|
+
});
|
|
1726
|
+
if (terminateOnDestroy) ws.terminate();
|
|
1727
|
+
};
|
|
1728
|
+
duplex._final = function (callback) {
|
|
1729
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
1730
|
+
ws.once("open", function open() {
|
|
1731
|
+
duplex._final(callback);
|
|
1732
|
+
});
|
|
1733
|
+
return;
|
|
1734
|
+
}
|
|
1735
|
+
if (ws._socket === null) return;
|
|
1736
|
+
if (ws._socket._writableState.finished) {
|
|
1737
|
+
callback();
|
|
1738
|
+
if (duplex._readableState.endEmitted) duplex.destroy();
|
|
1739
|
+
} else {
|
|
1740
|
+
ws._socket.once("finish", function finish() {
|
|
1741
|
+
callback();
|
|
1742
|
+
});
|
|
1743
|
+
ws.close();
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
duplex._read = function () {
|
|
1747
|
+
if (ws.isPaused) ws.resume();
|
|
1748
|
+
};
|
|
1749
|
+
duplex._write = function (chunk, encoding, callback) {
|
|
1750
|
+
if (ws.readyState === ws.CONNECTING) {
|
|
1751
|
+
ws.once("open", function open() {
|
|
1752
|
+
duplex._write(chunk, encoding, callback);
|
|
1753
|
+
});
|
|
1754
|
+
return;
|
|
1755
|
+
}
|
|
1756
|
+
ws.send(chunk, callback);
|
|
1757
|
+
};
|
|
1758
|
+
duplex.on("end", duplexOnEnd);
|
|
1759
|
+
duplex.on("error", duplexOnError);
|
|
1760
|
+
return duplex;
|
|
1761
|
+
}
|
|
1762
|
+
module.exports = createWebSocketStream;
|
|
1763
|
+
},
|
|
1764
|
+
31: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
1765
|
+
"use strict";
|
|
1766
|
+
const { tokenChars } = __nccwpck_require__(342);
|
|
1767
|
+
function parse(header) {
|
|
1768
|
+
const protocols = new Set();
|
|
1769
|
+
let start = -1;
|
|
1770
|
+
let end = -1;
|
|
1771
|
+
let i = 0;
|
|
1772
|
+
for (i; i < header.length; i++) {
|
|
1773
|
+
const code = header.charCodeAt(i);
|
|
1774
|
+
if (end === -1 && tokenChars[code] === 1) {
|
|
1775
|
+
if (start === -1) start = i;
|
|
1776
|
+
} else if (i !== 0 && (code === 32 || code === 9)) {
|
|
1777
|
+
if (end === -1 && start !== -1) end = i;
|
|
1778
|
+
} else if (code === 44) {
|
|
1779
|
+
if (start === -1) {
|
|
1780
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1781
|
+
}
|
|
1782
|
+
if (end === -1) end = i;
|
|
1783
|
+
const protocol = header.slice(start, end);
|
|
1784
|
+
if (protocols.has(protocol)) {
|
|
1785
|
+
throw new SyntaxError(
|
|
1786
|
+
`The "${protocol}" subprotocol is duplicated`,
|
|
1787
|
+
);
|
|
1788
|
+
}
|
|
1789
|
+
protocols.add(protocol);
|
|
1790
|
+
start = end = -1;
|
|
1791
|
+
} else {
|
|
1792
|
+
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
if (start === -1 || end !== -1) {
|
|
1796
|
+
throw new SyntaxError("Unexpected end of input");
|
|
1797
|
+
}
|
|
1798
|
+
const protocol = header.slice(start, i);
|
|
1799
|
+
if (protocols.has(protocol)) {
|
|
1800
|
+
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
1801
|
+
}
|
|
1802
|
+
protocols.add(protocol);
|
|
1803
|
+
return protocols;
|
|
1804
|
+
}
|
|
1805
|
+
module.exports = { parse };
|
|
1806
|
+
},
|
|
1807
|
+
342: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
1808
|
+
"use strict";
|
|
1809
|
+
const { isUtf8 } = __nccwpck_require__(181);
|
|
1810
|
+
const { hasBlob } = __nccwpck_require__(892);
|
|
1811
|
+
const tokenChars = [
|
|
1812
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
1813
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
|
|
1814
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1,
|
|
1815
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
|
|
1816
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
1817
|
+
1, 1, 1, 0, 1, 0, 1, 0,
|
|
1818
|
+
];
|
|
1819
|
+
function isValidStatusCode(code) {
|
|
1820
|
+
return (
|
|
1821
|
+
(code >= 1e3 &&
|
|
1822
|
+
code <= 1014 &&
|
|
1823
|
+
code !== 1004 &&
|
|
1824
|
+
code !== 1005 &&
|
|
1825
|
+
code !== 1006) ||
|
|
1826
|
+
(code >= 3e3 && code <= 4999)
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
function _isValidUTF8(buf) {
|
|
1830
|
+
const len = buf.length;
|
|
1831
|
+
let i = 0;
|
|
1832
|
+
while (i < len) {
|
|
1833
|
+
if ((buf[i] & 128) === 0) {
|
|
1834
|
+
i++;
|
|
1835
|
+
} else if ((buf[i] & 224) === 192) {
|
|
1836
|
+
if (
|
|
1837
|
+
i + 1 === len ||
|
|
1838
|
+
(buf[i + 1] & 192) !== 128 ||
|
|
1839
|
+
(buf[i] & 254) === 192
|
|
1840
|
+
) {
|
|
1841
|
+
return false;
|
|
1842
|
+
}
|
|
1843
|
+
i += 2;
|
|
1844
|
+
} else if ((buf[i] & 240) === 224) {
|
|
1845
|
+
if (
|
|
1846
|
+
i + 2 >= len ||
|
|
1847
|
+
(buf[i + 1] & 192) !== 128 ||
|
|
1848
|
+
(buf[i + 2] & 192) !== 128 ||
|
|
1849
|
+
(buf[i] === 224 && (buf[i + 1] & 224) === 128) ||
|
|
1850
|
+
(buf[i] === 237 && (buf[i + 1] & 224) === 160)
|
|
1851
|
+
) {
|
|
1852
|
+
return false;
|
|
1853
|
+
}
|
|
1854
|
+
i += 3;
|
|
1855
|
+
} else if ((buf[i] & 248) === 240) {
|
|
1856
|
+
if (
|
|
1857
|
+
i + 3 >= len ||
|
|
1858
|
+
(buf[i + 1] & 192) !== 128 ||
|
|
1859
|
+
(buf[i + 2] & 192) !== 128 ||
|
|
1860
|
+
(buf[i + 3] & 192) !== 128 ||
|
|
1861
|
+
(buf[i] === 240 && (buf[i + 1] & 240) === 128) ||
|
|
1862
|
+
(buf[i] === 244 && buf[i + 1] > 143) ||
|
|
1863
|
+
buf[i] > 244
|
|
1864
|
+
) {
|
|
1865
|
+
return false;
|
|
1866
|
+
}
|
|
1867
|
+
i += 4;
|
|
1868
|
+
} else {
|
|
1869
|
+
return false;
|
|
1870
|
+
}
|
|
1871
|
+
}
|
|
1872
|
+
return true;
|
|
1873
|
+
}
|
|
1874
|
+
function isBlob(value) {
|
|
1875
|
+
return (
|
|
1876
|
+
hasBlob &&
|
|
1877
|
+
typeof value === "object" &&
|
|
1878
|
+
typeof value.arrayBuffer === "function" &&
|
|
1879
|
+
typeof value.type === "string" &&
|
|
1880
|
+
typeof value.stream === "function" &&
|
|
1881
|
+
(value[Symbol.toStringTag] === "Blob" ||
|
|
1882
|
+
value[Symbol.toStringTag] === "File")
|
|
1883
|
+
);
|
|
1884
|
+
}
|
|
1885
|
+
module.exports = {
|
|
1886
|
+
isBlob,
|
|
1887
|
+
isValidStatusCode,
|
|
1888
|
+
isValidUTF8: _isValidUTF8,
|
|
1889
|
+
tokenChars,
|
|
1890
|
+
};
|
|
1891
|
+
if (isUtf8) {
|
|
1892
|
+
module.exports.isValidUTF8 = function (buf) {
|
|
1893
|
+
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
1894
|
+
};
|
|
1895
|
+
} else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
1896
|
+
try {
|
|
1897
|
+
const isValidUTF8 = __nccwpck_require__(710);
|
|
1898
|
+
module.exports.isValidUTF8 = function (buf) {
|
|
1899
|
+
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
1900
|
+
};
|
|
1901
|
+
} catch (e) {}
|
|
1902
|
+
}
|
|
1903
|
+
},
|
|
1904
|
+
788: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
1905
|
+
"use strict";
|
|
1906
|
+
const EventEmitter = __nccwpck_require__(434);
|
|
1907
|
+
const http = __nccwpck_require__(611);
|
|
1908
|
+
const { Duplex } = __nccwpck_require__(203);
|
|
1909
|
+
const { createHash } = __nccwpck_require__(982);
|
|
1910
|
+
const extension = __nccwpck_require__(468);
|
|
1911
|
+
const PerMessageDeflate = __nccwpck_require__(465);
|
|
1912
|
+
const subprotocol = __nccwpck_require__(31);
|
|
1913
|
+
const WebSocket = __nccwpck_require__(234);
|
|
1914
|
+
const { GUID, kWebSocket } = __nccwpck_require__(892);
|
|
1915
|
+
const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
1916
|
+
const RUNNING = 0;
|
|
1917
|
+
const CLOSING = 1;
|
|
1918
|
+
const CLOSED = 2;
|
|
1919
|
+
class WebSocketServer extends EventEmitter {
|
|
1920
|
+
constructor(options, callback) {
|
|
1921
|
+
super();
|
|
1922
|
+
options = {
|
|
1923
|
+
allowSynchronousEvents: true,
|
|
1924
|
+
autoPong: true,
|
|
1925
|
+
maxPayload: 100 * 1024 * 1024,
|
|
1926
|
+
skipUTF8Validation: false,
|
|
1927
|
+
perMessageDeflate: false,
|
|
1928
|
+
handleProtocols: null,
|
|
1929
|
+
clientTracking: true,
|
|
1930
|
+
verifyClient: null,
|
|
1931
|
+
noServer: false,
|
|
1932
|
+
backlog: null,
|
|
1933
|
+
server: null,
|
|
1934
|
+
host: null,
|
|
1935
|
+
path: null,
|
|
1936
|
+
port: null,
|
|
1937
|
+
WebSocket,
|
|
1938
|
+
...options,
|
|
1939
|
+
};
|
|
1940
|
+
if (
|
|
1941
|
+
(options.port == null && !options.server && !options.noServer) ||
|
|
1942
|
+
(options.port != null && (options.server || options.noServer)) ||
|
|
1943
|
+
(options.server && options.noServer)
|
|
1944
|
+
) {
|
|
1945
|
+
throw new TypeError(
|
|
1946
|
+
'One and only one of the "port", "server", or "noServer" options ' +
|
|
1947
|
+
"must be specified",
|
|
1948
|
+
);
|
|
1949
|
+
}
|
|
1950
|
+
if (options.port != null) {
|
|
1951
|
+
this._server = http.createServer((req, res) => {
|
|
1952
|
+
const body = http.STATUS_CODES[426];
|
|
1953
|
+
res.writeHead(426, {
|
|
1954
|
+
"Content-Length": body.length,
|
|
1955
|
+
"Content-Type": "text/plain",
|
|
1956
|
+
});
|
|
1957
|
+
res.end(body);
|
|
1958
|
+
});
|
|
1959
|
+
this._server.listen(
|
|
1960
|
+
options.port,
|
|
1961
|
+
options.host,
|
|
1962
|
+
options.backlog,
|
|
1963
|
+
callback,
|
|
1964
|
+
);
|
|
1965
|
+
} else if (options.server) {
|
|
1966
|
+
this._server = options.server;
|
|
1967
|
+
}
|
|
1968
|
+
if (this._server) {
|
|
1969
|
+
const emitConnection = this.emit.bind(this, "connection");
|
|
1970
|
+
this._removeListeners = addListeners(this._server, {
|
|
1971
|
+
listening: this.emit.bind(this, "listening"),
|
|
1972
|
+
error: this.emit.bind(this, "error"),
|
|
1973
|
+
upgrade: (req, socket, head) => {
|
|
1974
|
+
this.handleUpgrade(req, socket, head, emitConnection);
|
|
1975
|
+
},
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
if (options.perMessageDeflate === true)
|
|
1979
|
+
options.perMessageDeflate = {};
|
|
1980
|
+
if (options.clientTracking) {
|
|
1981
|
+
this.clients = new Set();
|
|
1982
|
+
this._shouldEmitClose = false;
|
|
1983
|
+
}
|
|
1984
|
+
this.options = options;
|
|
1985
|
+
this._state = RUNNING;
|
|
1986
|
+
}
|
|
1987
|
+
address() {
|
|
1988
|
+
if (this.options.noServer) {
|
|
1989
|
+
throw new Error('The server is operating in "noServer" mode');
|
|
1990
|
+
}
|
|
1991
|
+
if (!this._server) return null;
|
|
1992
|
+
return this._server.address();
|
|
1993
|
+
}
|
|
1994
|
+
close(cb) {
|
|
1995
|
+
if (this._state === CLOSED) {
|
|
1996
|
+
if (cb) {
|
|
1997
|
+
this.once("close", () => {
|
|
1998
|
+
cb(new Error("The server is not running"));
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
process.nextTick(emitClose, this);
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
if (cb) this.once("close", cb);
|
|
2005
|
+
if (this._state === CLOSING) return;
|
|
2006
|
+
this._state = CLOSING;
|
|
2007
|
+
if (this.options.noServer || this.options.server) {
|
|
2008
|
+
if (this._server) {
|
|
2009
|
+
this._removeListeners();
|
|
2010
|
+
this._removeListeners = this._server = null;
|
|
2011
|
+
}
|
|
2012
|
+
if (this.clients) {
|
|
2013
|
+
if (!this.clients.size) {
|
|
2014
|
+
process.nextTick(emitClose, this);
|
|
2015
|
+
} else {
|
|
2016
|
+
this._shouldEmitClose = true;
|
|
2017
|
+
}
|
|
2018
|
+
} else {
|
|
2019
|
+
process.nextTick(emitClose, this);
|
|
2020
|
+
}
|
|
2021
|
+
} else {
|
|
2022
|
+
const server = this._server;
|
|
2023
|
+
this._removeListeners();
|
|
2024
|
+
this._removeListeners = this._server = null;
|
|
2025
|
+
server.close(() => {
|
|
2026
|
+
emitClose(this);
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
shouldHandle(req) {
|
|
2031
|
+
if (this.options.path) {
|
|
2032
|
+
const index = req.url.indexOf("?");
|
|
2033
|
+
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
2034
|
+
if (pathname !== this.options.path) return false;
|
|
2035
|
+
}
|
|
2036
|
+
return true;
|
|
2037
|
+
}
|
|
2038
|
+
handleUpgrade(req, socket, head, cb) {
|
|
2039
|
+
socket.on("error", socketOnError);
|
|
2040
|
+
const key = req.headers["sec-websocket-key"];
|
|
2041
|
+
const upgrade = req.headers.upgrade;
|
|
2042
|
+
const version = +req.headers["sec-websocket-version"];
|
|
2043
|
+
if (req.method !== "GET") {
|
|
2044
|
+
const message = "Invalid HTTP method";
|
|
2045
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
2049
|
+
const message = "Invalid Upgrade header";
|
|
2050
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
if (key === undefined || !keyRegex.test(key)) {
|
|
2054
|
+
const message = "Missing or invalid Sec-WebSocket-Key header";
|
|
2055
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
if (version !== 13 && version !== 8) {
|
|
2059
|
+
const message = "Missing or invalid Sec-WebSocket-Version header";
|
|
2060
|
+
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
|
|
2061
|
+
"Sec-WebSocket-Version": "13, 8",
|
|
2062
|
+
});
|
|
2063
|
+
return;
|
|
2064
|
+
}
|
|
2065
|
+
if (!this.shouldHandle(req)) {
|
|
2066
|
+
abortHandshake(socket, 400);
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
|
|
2070
|
+
let protocols = new Set();
|
|
2071
|
+
if (secWebSocketProtocol !== undefined) {
|
|
2072
|
+
try {
|
|
2073
|
+
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
2074
|
+
} catch (err) {
|
|
2075
|
+
const message = "Invalid Sec-WebSocket-Protocol header";
|
|
2076
|
+
abortHandshakeOrEmitwsClientError(
|
|
2077
|
+
this,
|
|
2078
|
+
req,
|
|
2079
|
+
socket,
|
|
2080
|
+
400,
|
|
2081
|
+
message,
|
|
2082
|
+
);
|
|
2083
|
+
return;
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
const secWebSocketExtensions =
|
|
2087
|
+
req.headers["sec-websocket-extensions"];
|
|
2088
|
+
const extensions = {};
|
|
2089
|
+
if (
|
|
2090
|
+
this.options.perMessageDeflate &&
|
|
2091
|
+
secWebSocketExtensions !== undefined
|
|
2092
|
+
) {
|
|
2093
|
+
const perMessageDeflate = new PerMessageDeflate(
|
|
2094
|
+
this.options.perMessageDeflate,
|
|
2095
|
+
true,
|
|
2096
|
+
this.options.maxPayload,
|
|
2097
|
+
);
|
|
2098
|
+
try {
|
|
2099
|
+
const offers = extension.parse(secWebSocketExtensions);
|
|
2100
|
+
if (offers[PerMessageDeflate.extensionName]) {
|
|
2101
|
+
perMessageDeflate.accept(
|
|
2102
|
+
offers[PerMessageDeflate.extensionName],
|
|
2103
|
+
);
|
|
2104
|
+
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
2105
|
+
}
|
|
2106
|
+
} catch (err) {
|
|
2107
|
+
const message =
|
|
2108
|
+
"Invalid or unacceptable Sec-WebSocket-Extensions header";
|
|
2109
|
+
abortHandshakeOrEmitwsClientError(
|
|
2110
|
+
this,
|
|
2111
|
+
req,
|
|
2112
|
+
socket,
|
|
2113
|
+
400,
|
|
2114
|
+
message,
|
|
2115
|
+
);
|
|
2116
|
+
return;
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
if (this.options.verifyClient) {
|
|
2120
|
+
const info = {
|
|
2121
|
+
origin:
|
|
2122
|
+
req.headers[
|
|
2123
|
+
`${version === 8 ? "sec-websocket-origin" : "origin"}`
|
|
2124
|
+
],
|
|
2125
|
+
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
2126
|
+
req,
|
|
2127
|
+
};
|
|
2128
|
+
if (this.options.verifyClient.length === 2) {
|
|
2129
|
+
this.options.verifyClient(
|
|
2130
|
+
info,
|
|
2131
|
+
(verified, code, message, headers) => {
|
|
2132
|
+
if (!verified) {
|
|
2133
|
+
return abortHandshake(
|
|
2134
|
+
socket,
|
|
2135
|
+
code || 401,
|
|
2136
|
+
message,
|
|
2137
|
+
headers,
|
|
2138
|
+
);
|
|
2139
|
+
}
|
|
2140
|
+
this.completeUpgrade(
|
|
2141
|
+
extensions,
|
|
2142
|
+
key,
|
|
2143
|
+
protocols,
|
|
2144
|
+
req,
|
|
2145
|
+
socket,
|
|
2146
|
+
head,
|
|
2147
|
+
cb,
|
|
2148
|
+
);
|
|
2149
|
+
},
|
|
2150
|
+
);
|
|
2151
|
+
return;
|
|
2152
|
+
}
|
|
2153
|
+
if (!this.options.verifyClient(info))
|
|
2154
|
+
return abortHandshake(socket, 401);
|
|
2155
|
+
}
|
|
2156
|
+
this.completeUpgrade(
|
|
2157
|
+
extensions,
|
|
2158
|
+
key,
|
|
2159
|
+
protocols,
|
|
2160
|
+
req,
|
|
2161
|
+
socket,
|
|
2162
|
+
head,
|
|
2163
|
+
cb,
|
|
2164
|
+
);
|
|
2165
|
+
}
|
|
2166
|
+
completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
|
|
2167
|
+
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
2168
|
+
if (socket[kWebSocket]) {
|
|
2169
|
+
throw new Error(
|
|
2170
|
+
"server.handleUpgrade() was called more than once with the same " +
|
|
2171
|
+
"socket, possibly due to a misconfiguration",
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
2175
|
+
const digest = createHash("sha1")
|
|
2176
|
+
.update(key + GUID)
|
|
2177
|
+
.digest("base64");
|
|
2178
|
+
const headers = [
|
|
2179
|
+
"HTTP/1.1 101 Switching Protocols",
|
|
2180
|
+
"Upgrade: websocket",
|
|
2181
|
+
"Connection: Upgrade",
|
|
2182
|
+
`Sec-WebSocket-Accept: ${digest}`,
|
|
2183
|
+
];
|
|
2184
|
+
const ws = new this.options.WebSocket(null, undefined, this.options);
|
|
2185
|
+
if (protocols.size) {
|
|
2186
|
+
const protocol = this.options.handleProtocols
|
|
2187
|
+
? this.options.handleProtocols(protocols, req)
|
|
2188
|
+
: protocols.values().next().value;
|
|
2189
|
+
if (protocol) {
|
|
2190
|
+
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
2191
|
+
ws._protocol = protocol;
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
if (extensions[PerMessageDeflate.extensionName]) {
|
|
2195
|
+
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
2196
|
+
const value = extension.format({
|
|
2197
|
+
[PerMessageDeflate.extensionName]: [params],
|
|
2198
|
+
});
|
|
2199
|
+
headers.push(`Sec-WebSocket-Extensions: ${value}`);
|
|
2200
|
+
ws._extensions = extensions;
|
|
2201
|
+
}
|
|
2202
|
+
this.emit("headers", headers, req);
|
|
2203
|
+
socket.write(headers.concat("\r\n").join("\r\n"));
|
|
2204
|
+
socket.removeListener("error", socketOnError);
|
|
2205
|
+
ws.setSocket(socket, head, {
|
|
2206
|
+
allowSynchronousEvents: this.options.allowSynchronousEvents,
|
|
2207
|
+
maxPayload: this.options.maxPayload,
|
|
2208
|
+
skipUTF8Validation: this.options.skipUTF8Validation,
|
|
2209
|
+
});
|
|
2210
|
+
if (this.clients) {
|
|
2211
|
+
this.clients.add(ws);
|
|
2212
|
+
ws.on("close", () => {
|
|
2213
|
+
this.clients.delete(ws);
|
|
2214
|
+
if (this._shouldEmitClose && !this.clients.size) {
|
|
2215
|
+
process.nextTick(emitClose, this);
|
|
2216
|
+
}
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
cb(ws, req);
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
module.exports = WebSocketServer;
|
|
2223
|
+
function addListeners(server, map) {
|
|
2224
|
+
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
2225
|
+
return function removeListeners() {
|
|
2226
|
+
for (const event of Object.keys(map)) {
|
|
2227
|
+
server.removeListener(event, map[event]);
|
|
2228
|
+
}
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
function emitClose(server) {
|
|
2232
|
+
server._state = CLOSED;
|
|
2233
|
+
server.emit("close");
|
|
2234
|
+
}
|
|
2235
|
+
function socketOnError() {
|
|
2236
|
+
this.destroy();
|
|
2237
|
+
}
|
|
2238
|
+
function abortHandshake(socket, code, message, headers) {
|
|
2239
|
+
message = message || http.STATUS_CODES[code];
|
|
2240
|
+
headers = {
|
|
2241
|
+
Connection: "close",
|
|
2242
|
+
"Content-Type": "text/html",
|
|
2243
|
+
"Content-Length": Buffer.byteLength(message),
|
|
2244
|
+
...headers,
|
|
2245
|
+
};
|
|
2246
|
+
socket.once("finish", socket.destroy);
|
|
2247
|
+
socket.end(
|
|
2248
|
+
`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
|
|
2249
|
+
Object.keys(headers)
|
|
2250
|
+
.map((h) => `${h}: ${headers[h]}`)
|
|
2251
|
+
.join("\r\n") +
|
|
2252
|
+
"\r\n\r\n" +
|
|
2253
|
+
message,
|
|
2254
|
+
);
|
|
2255
|
+
}
|
|
2256
|
+
function abortHandshakeOrEmitwsClientError(
|
|
2257
|
+
server,
|
|
2258
|
+
req,
|
|
2259
|
+
socket,
|
|
2260
|
+
code,
|
|
2261
|
+
message,
|
|
2262
|
+
headers,
|
|
2263
|
+
) {
|
|
2264
|
+
if (server.listenerCount("wsClientError")) {
|
|
2265
|
+
const err = new Error(message);
|
|
2266
|
+
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
2267
|
+
server.emit("wsClientError", err, socket, req);
|
|
2268
|
+
} else {
|
|
2269
|
+
abortHandshake(socket, code, message, headers);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
},
|
|
2273
|
+
234: (module, __unused_webpack_exports, __nccwpck_require__) => {
|
|
2274
|
+
"use strict";
|
|
2275
|
+
const EventEmitter = __nccwpck_require__(434);
|
|
2276
|
+
const https = __nccwpck_require__(692);
|
|
2277
|
+
const http = __nccwpck_require__(611);
|
|
2278
|
+
const net = __nccwpck_require__(278);
|
|
2279
|
+
const tls = __nccwpck_require__(756);
|
|
2280
|
+
const { randomBytes, createHash } = __nccwpck_require__(982);
|
|
2281
|
+
const { Duplex, Readable } = __nccwpck_require__(203);
|
|
2282
|
+
const { URL } = __nccwpck_require__(16);
|
|
2283
|
+
const PerMessageDeflate = __nccwpck_require__(465);
|
|
2284
|
+
const Receiver = __nccwpck_require__(176);
|
|
2285
|
+
const Sender = __nccwpck_require__(480);
|
|
2286
|
+
const { isBlob } = __nccwpck_require__(342);
|
|
2287
|
+
const {
|
|
2288
|
+
BINARY_TYPES,
|
|
2289
|
+
EMPTY_BUFFER,
|
|
2290
|
+
GUID,
|
|
2291
|
+
kForOnEventAttribute,
|
|
2292
|
+
kListener,
|
|
2293
|
+
kStatusCode,
|
|
2294
|
+
kWebSocket,
|
|
2295
|
+
NOOP,
|
|
2296
|
+
} = __nccwpck_require__(892);
|
|
2297
|
+
const {
|
|
2298
|
+
EventTarget: { addEventListener, removeEventListener },
|
|
2299
|
+
} = __nccwpck_require__(95);
|
|
2300
|
+
const { format, parse } = __nccwpck_require__(468);
|
|
2301
|
+
const { toBuffer } = __nccwpck_require__(72);
|
|
2302
|
+
const closeTimeout = 30 * 1e3;
|
|
2303
|
+
const kAborted = Symbol("kAborted");
|
|
2304
|
+
const protocolVersions = [8, 13];
|
|
2305
|
+
const readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
|
|
2306
|
+
const subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
|
|
2307
|
+
class WebSocket extends EventEmitter {
|
|
2308
|
+
constructor(address, protocols, options) {
|
|
2309
|
+
super();
|
|
2310
|
+
this._binaryType = BINARY_TYPES[0];
|
|
2311
|
+
this._closeCode = 1006;
|
|
2312
|
+
this._closeFrameReceived = false;
|
|
2313
|
+
this._closeFrameSent = false;
|
|
2314
|
+
this._closeMessage = EMPTY_BUFFER;
|
|
2315
|
+
this._closeTimer = null;
|
|
2316
|
+
this._errorEmitted = false;
|
|
2317
|
+
this._extensions = {};
|
|
2318
|
+
this._paused = false;
|
|
2319
|
+
this._protocol = "";
|
|
2320
|
+
this._readyState = WebSocket.CONNECTING;
|
|
2321
|
+
this._receiver = null;
|
|
2322
|
+
this._sender = null;
|
|
2323
|
+
this._socket = null;
|
|
2324
|
+
if (address !== null) {
|
|
2325
|
+
this._bufferedAmount = 0;
|
|
2326
|
+
this._isServer = false;
|
|
2327
|
+
this._redirects = 0;
|
|
2328
|
+
if (protocols === undefined) {
|
|
2329
|
+
protocols = [];
|
|
2330
|
+
} else if (!Array.isArray(protocols)) {
|
|
2331
|
+
if (typeof protocols === "object" && protocols !== null) {
|
|
2332
|
+
options = protocols;
|
|
2333
|
+
protocols = [];
|
|
2334
|
+
} else {
|
|
2335
|
+
protocols = [protocols];
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
initAsClient(this, address, protocols, options);
|
|
2339
|
+
} else {
|
|
2340
|
+
this._autoPong = options.autoPong;
|
|
2341
|
+
this._isServer = true;
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
get binaryType() {
|
|
2345
|
+
return this._binaryType;
|
|
2346
|
+
}
|
|
2347
|
+
set binaryType(type) {
|
|
2348
|
+
if (!BINARY_TYPES.includes(type)) return;
|
|
2349
|
+
this._binaryType = type;
|
|
2350
|
+
if (this._receiver) this._receiver._binaryType = type;
|
|
2351
|
+
}
|
|
2352
|
+
get bufferedAmount() {
|
|
2353
|
+
if (!this._socket) return this._bufferedAmount;
|
|
2354
|
+
return (
|
|
2355
|
+
this._socket._writableState.length + this._sender._bufferedBytes
|
|
2356
|
+
);
|
|
2357
|
+
}
|
|
2358
|
+
get extensions() {
|
|
2359
|
+
return Object.keys(this._extensions).join();
|
|
2360
|
+
}
|
|
2361
|
+
get isPaused() {
|
|
2362
|
+
return this._paused;
|
|
2363
|
+
}
|
|
2364
|
+
get onclose() {
|
|
2365
|
+
return null;
|
|
2366
|
+
}
|
|
2367
|
+
get onerror() {
|
|
2368
|
+
return null;
|
|
2369
|
+
}
|
|
2370
|
+
get onopen() {
|
|
2371
|
+
return null;
|
|
2372
|
+
}
|
|
2373
|
+
get onmessage() {
|
|
2374
|
+
return null;
|
|
2375
|
+
}
|
|
2376
|
+
get protocol() {
|
|
2377
|
+
return this._protocol;
|
|
2378
|
+
}
|
|
2379
|
+
get readyState() {
|
|
2380
|
+
return this._readyState;
|
|
2381
|
+
}
|
|
2382
|
+
get url() {
|
|
2383
|
+
return this._url;
|
|
2384
|
+
}
|
|
2385
|
+
setSocket(socket, head, options) {
|
|
2386
|
+
const receiver = new Receiver({
|
|
2387
|
+
allowSynchronousEvents: options.allowSynchronousEvents,
|
|
2388
|
+
binaryType: this.binaryType,
|
|
2389
|
+
extensions: this._extensions,
|
|
2390
|
+
isServer: this._isServer,
|
|
2391
|
+
maxPayload: options.maxPayload,
|
|
2392
|
+
skipUTF8Validation: options.skipUTF8Validation,
|
|
2393
|
+
});
|
|
2394
|
+
const sender = new Sender(
|
|
2395
|
+
socket,
|
|
2396
|
+
this._extensions,
|
|
2397
|
+
options.generateMask,
|
|
2398
|
+
);
|
|
2399
|
+
this._receiver = receiver;
|
|
2400
|
+
this._sender = sender;
|
|
2401
|
+
this._socket = socket;
|
|
2402
|
+
receiver[kWebSocket] = this;
|
|
2403
|
+
sender[kWebSocket] = this;
|
|
2404
|
+
socket[kWebSocket] = this;
|
|
2405
|
+
receiver.on("conclude", receiverOnConclude);
|
|
2406
|
+
receiver.on("drain", receiverOnDrain);
|
|
2407
|
+
receiver.on("error", receiverOnError);
|
|
2408
|
+
receiver.on("message", receiverOnMessage);
|
|
2409
|
+
receiver.on("ping", receiverOnPing);
|
|
2410
|
+
receiver.on("pong", receiverOnPong);
|
|
2411
|
+
sender.onerror = senderOnError;
|
|
2412
|
+
if (socket.setTimeout) socket.setTimeout(0);
|
|
2413
|
+
if (socket.setNoDelay) socket.setNoDelay();
|
|
2414
|
+
if (head.length > 0) socket.unshift(head);
|
|
2415
|
+
socket.on("close", socketOnClose);
|
|
2416
|
+
socket.on("data", socketOnData);
|
|
2417
|
+
socket.on("end", socketOnEnd);
|
|
2418
|
+
socket.on("error", socketOnError);
|
|
2419
|
+
this._readyState = WebSocket.OPEN;
|
|
2420
|
+
this.emit("open");
|
|
2421
|
+
}
|
|
2422
|
+
emitClose() {
|
|
2423
|
+
if (!this._socket) {
|
|
2424
|
+
this._readyState = WebSocket.CLOSED;
|
|
2425
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
if (this._extensions[PerMessageDeflate.extensionName]) {
|
|
2429
|
+
this._extensions[PerMessageDeflate.extensionName].cleanup();
|
|
2430
|
+
}
|
|
2431
|
+
this._receiver.removeAllListeners();
|
|
2432
|
+
this._readyState = WebSocket.CLOSED;
|
|
2433
|
+
this.emit("close", this._closeCode, this._closeMessage);
|
|
2434
|
+
}
|
|
2435
|
+
close(code, data) {
|
|
2436
|
+
if (this.readyState === WebSocket.CLOSED) return;
|
|
2437
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2438
|
+
const msg =
|
|
2439
|
+
"WebSocket was closed before the connection was established";
|
|
2440
|
+
abortHandshake(this, this._req, msg);
|
|
2441
|
+
return;
|
|
2442
|
+
}
|
|
2443
|
+
if (this.readyState === WebSocket.CLOSING) {
|
|
2444
|
+
if (
|
|
2445
|
+
this._closeFrameSent &&
|
|
2446
|
+
(this._closeFrameReceived ||
|
|
2447
|
+
this._receiver._writableState.errorEmitted)
|
|
2448
|
+
) {
|
|
2449
|
+
this._socket.end();
|
|
2450
|
+
}
|
|
2451
|
+
return;
|
|
2452
|
+
}
|
|
2453
|
+
this._readyState = WebSocket.CLOSING;
|
|
2454
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
2455
|
+
if (err) return;
|
|
2456
|
+
this._closeFrameSent = true;
|
|
2457
|
+
if (
|
|
2458
|
+
this._closeFrameReceived ||
|
|
2459
|
+
this._receiver._writableState.errorEmitted
|
|
2460
|
+
) {
|
|
2461
|
+
this._socket.end();
|
|
2462
|
+
}
|
|
2463
|
+
});
|
|
2464
|
+
setCloseTimer(this);
|
|
2465
|
+
}
|
|
2466
|
+
pause() {
|
|
2467
|
+
if (
|
|
2468
|
+
this.readyState === WebSocket.CONNECTING ||
|
|
2469
|
+
this.readyState === WebSocket.CLOSED
|
|
2470
|
+
) {
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
this._paused = true;
|
|
2474
|
+
this._socket.pause();
|
|
2475
|
+
}
|
|
2476
|
+
ping(data, mask, cb) {
|
|
2477
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2478
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2479
|
+
}
|
|
2480
|
+
if (typeof data === "function") {
|
|
2481
|
+
cb = data;
|
|
2482
|
+
data = mask = undefined;
|
|
2483
|
+
} else if (typeof mask === "function") {
|
|
2484
|
+
cb = mask;
|
|
2485
|
+
mask = undefined;
|
|
2486
|
+
}
|
|
2487
|
+
if (typeof data === "number") data = data.toString();
|
|
2488
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
2489
|
+
sendAfterClose(this, data, cb);
|
|
2490
|
+
return;
|
|
2491
|
+
}
|
|
2492
|
+
if (mask === undefined) mask = !this._isServer;
|
|
2493
|
+
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
2494
|
+
}
|
|
2495
|
+
pong(data, mask, cb) {
|
|
2496
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2497
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2498
|
+
}
|
|
2499
|
+
if (typeof data === "function") {
|
|
2500
|
+
cb = data;
|
|
2501
|
+
data = mask = undefined;
|
|
2502
|
+
} else if (typeof mask === "function") {
|
|
2503
|
+
cb = mask;
|
|
2504
|
+
mask = undefined;
|
|
2505
|
+
}
|
|
2506
|
+
if (typeof data === "number") data = data.toString();
|
|
2507
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
2508
|
+
sendAfterClose(this, data, cb);
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
if (mask === undefined) mask = !this._isServer;
|
|
2512
|
+
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
2513
|
+
}
|
|
2514
|
+
resume() {
|
|
2515
|
+
if (
|
|
2516
|
+
this.readyState === WebSocket.CONNECTING ||
|
|
2517
|
+
this.readyState === WebSocket.CLOSED
|
|
2518
|
+
) {
|
|
2519
|
+
return;
|
|
2520
|
+
}
|
|
2521
|
+
this._paused = false;
|
|
2522
|
+
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
2523
|
+
}
|
|
2524
|
+
send(data, options, cb) {
|
|
2525
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2526
|
+
throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
|
|
2527
|
+
}
|
|
2528
|
+
if (typeof options === "function") {
|
|
2529
|
+
cb = options;
|
|
2530
|
+
options = {};
|
|
2531
|
+
}
|
|
2532
|
+
if (typeof data === "number") data = data.toString();
|
|
2533
|
+
if (this.readyState !== WebSocket.OPEN) {
|
|
2534
|
+
sendAfterClose(this, data, cb);
|
|
2535
|
+
return;
|
|
2536
|
+
}
|
|
2537
|
+
const opts = {
|
|
2538
|
+
binary: typeof data !== "string",
|
|
2539
|
+
mask: !this._isServer,
|
|
2540
|
+
compress: true,
|
|
2541
|
+
fin: true,
|
|
2542
|
+
...options,
|
|
2543
|
+
};
|
|
2544
|
+
if (!this._extensions[PerMessageDeflate.extensionName]) {
|
|
2545
|
+
opts.compress = false;
|
|
2546
|
+
}
|
|
2547
|
+
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
2548
|
+
}
|
|
2549
|
+
terminate() {
|
|
2550
|
+
if (this.readyState === WebSocket.CLOSED) return;
|
|
2551
|
+
if (this.readyState === WebSocket.CONNECTING) {
|
|
2552
|
+
const msg =
|
|
2553
|
+
"WebSocket was closed before the connection was established";
|
|
2554
|
+
abortHandshake(this, this._req, msg);
|
|
2555
|
+
return;
|
|
2556
|
+
}
|
|
2557
|
+
if (this._socket) {
|
|
2558
|
+
this._readyState = WebSocket.CLOSING;
|
|
2559
|
+
this._socket.destroy();
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
Object.defineProperty(WebSocket, "CONNECTING", {
|
|
2564
|
+
enumerable: true,
|
|
2565
|
+
value: readyStates.indexOf("CONNECTING"),
|
|
2566
|
+
});
|
|
2567
|
+
Object.defineProperty(WebSocket.prototype, "CONNECTING", {
|
|
2568
|
+
enumerable: true,
|
|
2569
|
+
value: readyStates.indexOf("CONNECTING"),
|
|
2570
|
+
});
|
|
2571
|
+
Object.defineProperty(WebSocket, "OPEN", {
|
|
2572
|
+
enumerable: true,
|
|
2573
|
+
value: readyStates.indexOf("OPEN"),
|
|
2574
|
+
});
|
|
2575
|
+
Object.defineProperty(WebSocket.prototype, "OPEN", {
|
|
2576
|
+
enumerable: true,
|
|
2577
|
+
value: readyStates.indexOf("OPEN"),
|
|
2578
|
+
});
|
|
2579
|
+
Object.defineProperty(WebSocket, "CLOSING", {
|
|
2580
|
+
enumerable: true,
|
|
2581
|
+
value: readyStates.indexOf("CLOSING"),
|
|
2582
|
+
});
|
|
2583
|
+
Object.defineProperty(WebSocket.prototype, "CLOSING", {
|
|
2584
|
+
enumerable: true,
|
|
2585
|
+
value: readyStates.indexOf("CLOSING"),
|
|
2586
|
+
});
|
|
2587
|
+
Object.defineProperty(WebSocket, "CLOSED", {
|
|
2588
|
+
enumerable: true,
|
|
2589
|
+
value: readyStates.indexOf("CLOSED"),
|
|
2590
|
+
});
|
|
2591
|
+
Object.defineProperty(WebSocket.prototype, "CLOSED", {
|
|
2592
|
+
enumerable: true,
|
|
2593
|
+
value: readyStates.indexOf("CLOSED"),
|
|
2594
|
+
});
|
|
2595
|
+
[
|
|
2596
|
+
"binaryType",
|
|
2597
|
+
"bufferedAmount",
|
|
2598
|
+
"extensions",
|
|
2599
|
+
"isPaused",
|
|
2600
|
+
"protocol",
|
|
2601
|
+
"readyState",
|
|
2602
|
+
"url",
|
|
2603
|
+
].forEach((property) => {
|
|
2604
|
+
Object.defineProperty(WebSocket.prototype, property, {
|
|
2605
|
+
enumerable: true,
|
|
2606
|
+
});
|
|
2607
|
+
});
|
|
2608
|
+
["open", "error", "close", "message"].forEach((method) => {
|
|
2609
|
+
Object.defineProperty(WebSocket.prototype, `on${method}`, {
|
|
2610
|
+
enumerable: true,
|
|
2611
|
+
get() {
|
|
2612
|
+
for (const listener of this.listeners(method)) {
|
|
2613
|
+
if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
2614
|
+
}
|
|
2615
|
+
return null;
|
|
2616
|
+
},
|
|
2617
|
+
set(handler) {
|
|
2618
|
+
for (const listener of this.listeners(method)) {
|
|
2619
|
+
if (listener[kForOnEventAttribute]) {
|
|
2620
|
+
this.removeListener(method, listener);
|
|
2621
|
+
break;
|
|
2622
|
+
}
|
|
2623
|
+
}
|
|
2624
|
+
if (typeof handler !== "function") return;
|
|
2625
|
+
this.addEventListener(method, handler, {
|
|
2626
|
+
[kForOnEventAttribute]: true,
|
|
2627
|
+
});
|
|
2628
|
+
},
|
|
2629
|
+
});
|
|
2630
|
+
});
|
|
2631
|
+
WebSocket.prototype.addEventListener = addEventListener;
|
|
2632
|
+
WebSocket.prototype.removeEventListener = removeEventListener;
|
|
2633
|
+
module.exports = WebSocket;
|
|
2634
|
+
function initAsClient(websocket, address, protocols, options) {
|
|
2635
|
+
const opts = {
|
|
2636
|
+
allowSynchronousEvents: true,
|
|
2637
|
+
autoPong: true,
|
|
2638
|
+
protocolVersion: protocolVersions[1],
|
|
2639
|
+
maxPayload: 100 * 1024 * 1024,
|
|
2640
|
+
skipUTF8Validation: false,
|
|
2641
|
+
perMessageDeflate: true,
|
|
2642
|
+
followRedirects: false,
|
|
2643
|
+
maxRedirects: 10,
|
|
2644
|
+
...options,
|
|
2645
|
+
socketPath: undefined,
|
|
2646
|
+
hostname: undefined,
|
|
2647
|
+
protocol: undefined,
|
|
2648
|
+
timeout: undefined,
|
|
2649
|
+
method: "GET",
|
|
2650
|
+
host: undefined,
|
|
2651
|
+
path: undefined,
|
|
2652
|
+
port: undefined,
|
|
2653
|
+
};
|
|
2654
|
+
websocket._autoPong = opts.autoPong;
|
|
2655
|
+
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
2656
|
+
throw new RangeError(
|
|
2657
|
+
`Unsupported protocol version: ${opts.protocolVersion} ` +
|
|
2658
|
+
`(supported versions: ${protocolVersions.join(", ")})`,
|
|
2659
|
+
);
|
|
2660
|
+
}
|
|
2661
|
+
let parsedUrl;
|
|
2662
|
+
if (address instanceof URL) {
|
|
2663
|
+
parsedUrl = address;
|
|
2664
|
+
} else {
|
|
2665
|
+
try {
|
|
2666
|
+
parsedUrl = new URL(address);
|
|
2667
|
+
} catch (e) {
|
|
2668
|
+
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
if (parsedUrl.protocol === "http:") {
|
|
2672
|
+
parsedUrl.protocol = "ws:";
|
|
2673
|
+
} else if (parsedUrl.protocol === "https:") {
|
|
2674
|
+
parsedUrl.protocol = "wss:";
|
|
2675
|
+
}
|
|
2676
|
+
websocket._url = parsedUrl.href;
|
|
2677
|
+
const isSecure = parsedUrl.protocol === "wss:";
|
|
2678
|
+
const isIpcUrl = parsedUrl.protocol === "ws+unix:";
|
|
2679
|
+
let invalidUrlMessage;
|
|
2680
|
+
if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
|
|
2681
|
+
invalidUrlMessage =
|
|
2682
|
+
'The URL\'s protocol must be one of "ws:", "wss:", ' +
|
|
2683
|
+
'"http:", "https:", or "ws+unix:"';
|
|
2684
|
+
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
2685
|
+
invalidUrlMessage = "The URL's pathname is empty";
|
|
2686
|
+
} else if (parsedUrl.hash) {
|
|
2687
|
+
invalidUrlMessage = "The URL contains a fragment identifier";
|
|
2688
|
+
}
|
|
2689
|
+
if (invalidUrlMessage) {
|
|
2690
|
+
const err = new SyntaxError(invalidUrlMessage);
|
|
2691
|
+
if (websocket._redirects === 0) {
|
|
2692
|
+
throw err;
|
|
2693
|
+
} else {
|
|
2694
|
+
emitErrorAndClose(websocket, err);
|
|
2695
|
+
return;
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
const defaultPort = isSecure ? 443 : 80;
|
|
2699
|
+
const key = randomBytes(16).toString("base64");
|
|
2700
|
+
const request = isSecure ? https.request : http.request;
|
|
2701
|
+
const protocolSet = new Set();
|
|
2702
|
+
let perMessageDeflate;
|
|
2703
|
+
opts.createConnection =
|
|
2704
|
+
opts.createConnection || (isSecure ? tlsConnect : netConnect);
|
|
2705
|
+
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
2706
|
+
opts.port = parsedUrl.port || defaultPort;
|
|
2707
|
+
opts.host = parsedUrl.hostname.startsWith("[")
|
|
2708
|
+
? parsedUrl.hostname.slice(1, -1)
|
|
2709
|
+
: parsedUrl.hostname;
|
|
2710
|
+
opts.headers = {
|
|
2711
|
+
...opts.headers,
|
|
2712
|
+
"Sec-WebSocket-Version": opts.protocolVersion,
|
|
2713
|
+
"Sec-WebSocket-Key": key,
|
|
2714
|
+
Connection: "Upgrade",
|
|
2715
|
+
Upgrade: "websocket",
|
|
2716
|
+
};
|
|
2717
|
+
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
2718
|
+
opts.timeout = opts.handshakeTimeout;
|
|
2719
|
+
if (opts.perMessageDeflate) {
|
|
2720
|
+
perMessageDeflate = new PerMessageDeflate(
|
|
2721
|
+
opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
|
|
2722
|
+
false,
|
|
2723
|
+
opts.maxPayload,
|
|
2724
|
+
);
|
|
2725
|
+
opts.headers["Sec-WebSocket-Extensions"] = format({
|
|
2726
|
+
[PerMessageDeflate.extensionName]: perMessageDeflate.offer(),
|
|
2727
|
+
});
|
|
2728
|
+
}
|
|
2729
|
+
if (protocols.length) {
|
|
2730
|
+
for (const protocol of protocols) {
|
|
2731
|
+
if (
|
|
2732
|
+
typeof protocol !== "string" ||
|
|
2733
|
+
!subprotocolRegex.test(protocol) ||
|
|
2734
|
+
protocolSet.has(protocol)
|
|
2735
|
+
) {
|
|
2736
|
+
throw new SyntaxError(
|
|
2737
|
+
"An invalid or duplicated subprotocol was specified",
|
|
2738
|
+
);
|
|
2739
|
+
}
|
|
2740
|
+
protocolSet.add(protocol);
|
|
2741
|
+
}
|
|
2742
|
+
opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
|
|
2743
|
+
}
|
|
2744
|
+
if (opts.origin) {
|
|
2745
|
+
if (opts.protocolVersion < 13) {
|
|
2746
|
+
opts.headers["Sec-WebSocket-Origin"] = opts.origin;
|
|
2747
|
+
} else {
|
|
2748
|
+
opts.headers.Origin = opts.origin;
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
if (parsedUrl.username || parsedUrl.password) {
|
|
2752
|
+
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
2753
|
+
}
|
|
2754
|
+
if (isIpcUrl) {
|
|
2755
|
+
const parts = opts.path.split(":");
|
|
2756
|
+
opts.socketPath = parts[0];
|
|
2757
|
+
opts.path = parts[1];
|
|
2758
|
+
}
|
|
2759
|
+
let req;
|
|
2760
|
+
if (opts.followRedirects) {
|
|
2761
|
+
if (websocket._redirects === 0) {
|
|
2762
|
+
websocket._originalIpc = isIpcUrl;
|
|
2763
|
+
websocket._originalSecure = isSecure;
|
|
2764
|
+
websocket._originalHostOrSocketPath = isIpcUrl
|
|
2765
|
+
? opts.socketPath
|
|
2766
|
+
: parsedUrl.host;
|
|
2767
|
+
const headers = options && options.headers;
|
|
2768
|
+
options = { ...options, headers: {} };
|
|
2769
|
+
if (headers) {
|
|
2770
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
2771
|
+
options.headers[key.toLowerCase()] = value;
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
} else if (websocket.listenerCount("redirect") === 0) {
|
|
2775
|
+
const isSameHost = isIpcUrl
|
|
2776
|
+
? websocket._originalIpc
|
|
2777
|
+
? opts.socketPath === websocket._originalHostOrSocketPath
|
|
2778
|
+
: false
|
|
2779
|
+
: websocket._originalIpc
|
|
2780
|
+
? false
|
|
2781
|
+
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
2782
|
+
if (!isSameHost || (websocket._originalSecure && !isSecure)) {
|
|
2783
|
+
delete opts.headers.authorization;
|
|
2784
|
+
delete opts.headers.cookie;
|
|
2785
|
+
if (!isSameHost) delete opts.headers.host;
|
|
2786
|
+
opts.auth = undefined;
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
if (opts.auth && !options.headers.authorization) {
|
|
2790
|
+
options.headers.authorization =
|
|
2791
|
+
"Basic " + Buffer.from(opts.auth).toString("base64");
|
|
2792
|
+
}
|
|
2793
|
+
req = websocket._req = request(opts);
|
|
2794
|
+
if (websocket._redirects) {
|
|
2795
|
+
websocket.emit("redirect", websocket.url, req);
|
|
2796
|
+
}
|
|
2797
|
+
} else {
|
|
2798
|
+
req = websocket._req = request(opts);
|
|
2799
|
+
}
|
|
2800
|
+
if (opts.timeout) {
|
|
2801
|
+
req.on("timeout", () => {
|
|
2802
|
+
abortHandshake(websocket, req, "Opening handshake has timed out");
|
|
2803
|
+
});
|
|
2804
|
+
}
|
|
2805
|
+
req.on("error", (err) => {
|
|
2806
|
+
if (req === null || req[kAborted]) return;
|
|
2807
|
+
req = websocket._req = null;
|
|
2808
|
+
emitErrorAndClose(websocket, err);
|
|
2809
|
+
});
|
|
2810
|
+
req.on("response", (res) => {
|
|
2811
|
+
const location = res.headers.location;
|
|
2812
|
+
const statusCode = res.statusCode;
|
|
2813
|
+
if (
|
|
2814
|
+
location &&
|
|
2815
|
+
opts.followRedirects &&
|
|
2816
|
+
statusCode >= 300 &&
|
|
2817
|
+
statusCode < 400
|
|
2818
|
+
) {
|
|
2819
|
+
if (++websocket._redirects > opts.maxRedirects) {
|
|
2820
|
+
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2823
|
+
req.abort();
|
|
2824
|
+
let addr;
|
|
2825
|
+
try {
|
|
2826
|
+
addr = new URL(location, address);
|
|
2827
|
+
} catch (e) {
|
|
2828
|
+
const err = new SyntaxError(`Invalid URL: ${location}`);
|
|
2829
|
+
emitErrorAndClose(websocket, err);
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
initAsClient(websocket, addr, protocols, options);
|
|
2833
|
+
} else if (!websocket.emit("unexpected-response", req, res)) {
|
|
2834
|
+
abortHandshake(
|
|
2835
|
+
websocket,
|
|
2836
|
+
req,
|
|
2837
|
+
`Unexpected server response: ${res.statusCode}`,
|
|
2838
|
+
);
|
|
2839
|
+
}
|
|
2840
|
+
});
|
|
2841
|
+
req.on("upgrade", (res, socket, head) => {
|
|
2842
|
+
websocket.emit("upgrade", res);
|
|
2843
|
+
if (websocket.readyState !== WebSocket.CONNECTING) return;
|
|
2844
|
+
req = websocket._req = null;
|
|
2845
|
+
const upgrade = res.headers.upgrade;
|
|
2846
|
+
if (upgrade === undefined || upgrade.toLowerCase() !== "websocket") {
|
|
2847
|
+
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2850
|
+
const digest = createHash("sha1")
|
|
2851
|
+
.update(key + GUID)
|
|
2852
|
+
.digest("base64");
|
|
2853
|
+
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
2854
|
+
abortHandshake(
|
|
2855
|
+
websocket,
|
|
2856
|
+
socket,
|
|
2857
|
+
"Invalid Sec-WebSocket-Accept header",
|
|
2858
|
+
);
|
|
2859
|
+
return;
|
|
2860
|
+
}
|
|
2861
|
+
const serverProt = res.headers["sec-websocket-protocol"];
|
|
2862
|
+
let protError;
|
|
2863
|
+
if (serverProt !== undefined) {
|
|
2864
|
+
if (!protocolSet.size) {
|
|
2865
|
+
protError = "Server sent a subprotocol but none was requested";
|
|
2866
|
+
} else if (!protocolSet.has(serverProt)) {
|
|
2867
|
+
protError = "Server sent an invalid subprotocol";
|
|
2868
|
+
}
|
|
2869
|
+
} else if (protocolSet.size) {
|
|
2870
|
+
protError = "Server sent no subprotocol";
|
|
2871
|
+
}
|
|
2872
|
+
if (protError) {
|
|
2873
|
+
abortHandshake(websocket, socket, protError);
|
|
2874
|
+
return;
|
|
2875
|
+
}
|
|
2876
|
+
if (serverProt) websocket._protocol = serverProt;
|
|
2877
|
+
const secWebSocketExtensions =
|
|
2878
|
+
res.headers["sec-websocket-extensions"];
|
|
2879
|
+
if (secWebSocketExtensions !== undefined) {
|
|
2880
|
+
if (!perMessageDeflate) {
|
|
2881
|
+
const message =
|
|
2882
|
+
"Server sent a Sec-WebSocket-Extensions header but no extension " +
|
|
2883
|
+
"was requested";
|
|
2884
|
+
abortHandshake(websocket, socket, message);
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
let extensions;
|
|
2888
|
+
try {
|
|
2889
|
+
extensions = parse(secWebSocketExtensions);
|
|
2890
|
+
} catch (err) {
|
|
2891
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
2892
|
+
abortHandshake(websocket, socket, message);
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
const extensionNames = Object.keys(extensions);
|
|
2896
|
+
if (
|
|
2897
|
+
extensionNames.length !== 1 ||
|
|
2898
|
+
extensionNames[0] !== PerMessageDeflate.extensionName
|
|
2899
|
+
) {
|
|
2900
|
+
const message =
|
|
2901
|
+
"Server indicated an extension that was not requested";
|
|
2902
|
+
abortHandshake(websocket, socket, message);
|
|
2903
|
+
return;
|
|
2904
|
+
}
|
|
2905
|
+
try {
|
|
2906
|
+
perMessageDeflate.accept(
|
|
2907
|
+
extensions[PerMessageDeflate.extensionName],
|
|
2908
|
+
);
|
|
2909
|
+
} catch (err) {
|
|
2910
|
+
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
2911
|
+
abortHandshake(websocket, socket, message);
|
|
2912
|
+
return;
|
|
2913
|
+
}
|
|
2914
|
+
websocket._extensions[PerMessageDeflate.extensionName] =
|
|
2915
|
+
perMessageDeflate;
|
|
2916
|
+
}
|
|
2917
|
+
websocket.setSocket(socket, head, {
|
|
2918
|
+
allowSynchronousEvents: opts.allowSynchronousEvents,
|
|
2919
|
+
generateMask: opts.generateMask,
|
|
2920
|
+
maxPayload: opts.maxPayload,
|
|
2921
|
+
skipUTF8Validation: opts.skipUTF8Validation,
|
|
2922
|
+
});
|
|
2923
|
+
});
|
|
2924
|
+
if (opts.finishRequest) {
|
|
2925
|
+
opts.finishRequest(req, websocket);
|
|
2926
|
+
} else {
|
|
2927
|
+
req.end();
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
function emitErrorAndClose(websocket, err) {
|
|
2931
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2932
|
+
websocket._errorEmitted = true;
|
|
2933
|
+
websocket.emit("error", err);
|
|
2934
|
+
websocket.emitClose();
|
|
2935
|
+
}
|
|
2936
|
+
function netConnect(options) {
|
|
2937
|
+
options.path = options.socketPath;
|
|
2938
|
+
return net.connect(options);
|
|
2939
|
+
}
|
|
2940
|
+
function tlsConnect(options) {
|
|
2941
|
+
options.path = undefined;
|
|
2942
|
+
if (!options.servername && options.servername !== "") {
|
|
2943
|
+
options.servername = net.isIP(options.host) ? "" : options.host;
|
|
2944
|
+
}
|
|
2945
|
+
return tls.connect(options);
|
|
2946
|
+
}
|
|
2947
|
+
function abortHandshake(websocket, stream, message) {
|
|
2948
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
2949
|
+
const err = new Error(message);
|
|
2950
|
+
Error.captureStackTrace(err, abortHandshake);
|
|
2951
|
+
if (stream.setHeader) {
|
|
2952
|
+
stream[kAborted] = true;
|
|
2953
|
+
stream.abort();
|
|
2954
|
+
if (stream.socket && !stream.socket.destroyed) {
|
|
2955
|
+
stream.socket.destroy();
|
|
2956
|
+
}
|
|
2957
|
+
process.nextTick(emitErrorAndClose, websocket, err);
|
|
2958
|
+
} else {
|
|
2959
|
+
stream.destroy(err);
|
|
2960
|
+
stream.once("error", websocket.emit.bind(websocket, "error"));
|
|
2961
|
+
stream.once("close", websocket.emitClose.bind(websocket));
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
function sendAfterClose(websocket, data, cb) {
|
|
2965
|
+
if (data) {
|
|
2966
|
+
const length = isBlob(data) ? data.size : toBuffer(data).length;
|
|
2967
|
+
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
2968
|
+
else websocket._bufferedAmount += length;
|
|
2969
|
+
}
|
|
2970
|
+
if (cb) {
|
|
2971
|
+
const err = new Error(
|
|
2972
|
+
`WebSocket is not open: readyState ${websocket.readyState} ` +
|
|
2973
|
+
`(${readyStates[websocket.readyState]})`,
|
|
2974
|
+
);
|
|
2975
|
+
process.nextTick(cb, err);
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
function receiverOnConclude(code, reason) {
|
|
2979
|
+
const websocket = this[kWebSocket];
|
|
2980
|
+
websocket._closeFrameReceived = true;
|
|
2981
|
+
websocket._closeMessage = reason;
|
|
2982
|
+
websocket._closeCode = code;
|
|
2983
|
+
if (websocket._socket[kWebSocket] === undefined) return;
|
|
2984
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
2985
|
+
process.nextTick(resume, websocket._socket);
|
|
2986
|
+
if (code === 1005) websocket.close();
|
|
2987
|
+
else websocket.close(code, reason);
|
|
2988
|
+
}
|
|
2989
|
+
function receiverOnDrain() {
|
|
2990
|
+
const websocket = this[kWebSocket];
|
|
2991
|
+
if (!websocket.isPaused) websocket._socket.resume();
|
|
2992
|
+
}
|
|
2993
|
+
function receiverOnError(err) {
|
|
2994
|
+
const websocket = this[kWebSocket];
|
|
2995
|
+
if (websocket._socket[kWebSocket] !== undefined) {
|
|
2996
|
+
websocket._socket.removeListener("data", socketOnData);
|
|
2997
|
+
process.nextTick(resume, websocket._socket);
|
|
2998
|
+
websocket.close(err[kStatusCode]);
|
|
2999
|
+
}
|
|
3000
|
+
if (!websocket._errorEmitted) {
|
|
3001
|
+
websocket._errorEmitted = true;
|
|
3002
|
+
websocket.emit("error", err);
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
function receiverOnFinish() {
|
|
3006
|
+
this[kWebSocket].emitClose();
|
|
3007
|
+
}
|
|
3008
|
+
function receiverOnMessage(data, isBinary) {
|
|
3009
|
+
this[kWebSocket].emit("message", data, isBinary);
|
|
3010
|
+
}
|
|
3011
|
+
function receiverOnPing(data) {
|
|
3012
|
+
const websocket = this[kWebSocket];
|
|
3013
|
+
if (websocket._autoPong) websocket.pong(data, !this._isServer, NOOP);
|
|
3014
|
+
websocket.emit("ping", data);
|
|
3015
|
+
}
|
|
3016
|
+
function receiverOnPong(data) {
|
|
3017
|
+
this[kWebSocket].emit("pong", data);
|
|
3018
|
+
}
|
|
3019
|
+
function resume(stream) {
|
|
3020
|
+
stream.resume();
|
|
3021
|
+
}
|
|
3022
|
+
function senderOnError(err) {
|
|
3023
|
+
const websocket = this[kWebSocket];
|
|
3024
|
+
if (websocket.readyState === WebSocket.CLOSED) return;
|
|
3025
|
+
if (websocket.readyState === WebSocket.OPEN) {
|
|
3026
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3027
|
+
setCloseTimer(websocket);
|
|
3028
|
+
}
|
|
3029
|
+
this._socket.end();
|
|
3030
|
+
if (!websocket._errorEmitted) {
|
|
3031
|
+
websocket._errorEmitted = true;
|
|
3032
|
+
websocket.emit("error", err);
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
function setCloseTimer(websocket) {
|
|
3036
|
+
websocket._closeTimer = setTimeout(
|
|
3037
|
+
websocket._socket.destroy.bind(websocket._socket),
|
|
3038
|
+
closeTimeout,
|
|
3039
|
+
);
|
|
3040
|
+
}
|
|
3041
|
+
function socketOnClose() {
|
|
3042
|
+
const websocket = this[kWebSocket];
|
|
3043
|
+
this.removeListener("close", socketOnClose);
|
|
3044
|
+
this.removeListener("data", socketOnData);
|
|
3045
|
+
this.removeListener("end", socketOnEnd);
|
|
3046
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3047
|
+
let chunk;
|
|
3048
|
+
if (
|
|
3049
|
+
!this._readableState.endEmitted &&
|
|
3050
|
+
!websocket._closeFrameReceived &&
|
|
3051
|
+
!websocket._receiver._writableState.errorEmitted &&
|
|
3052
|
+
(chunk = websocket._socket.read()) !== null
|
|
3053
|
+
) {
|
|
3054
|
+
websocket._receiver.write(chunk);
|
|
3055
|
+
}
|
|
3056
|
+
websocket._receiver.end();
|
|
3057
|
+
this[kWebSocket] = undefined;
|
|
3058
|
+
clearTimeout(websocket._closeTimer);
|
|
3059
|
+
if (
|
|
3060
|
+
websocket._receiver._writableState.finished ||
|
|
3061
|
+
websocket._receiver._writableState.errorEmitted
|
|
3062
|
+
) {
|
|
3063
|
+
websocket.emitClose();
|
|
3064
|
+
} else {
|
|
3065
|
+
websocket._receiver.on("error", receiverOnFinish);
|
|
3066
|
+
websocket._receiver.on("finish", receiverOnFinish);
|
|
3067
|
+
}
|
|
3068
|
+
}
|
|
3069
|
+
function socketOnData(chunk) {
|
|
3070
|
+
if (!this[kWebSocket]._receiver.write(chunk)) {
|
|
3071
|
+
this.pause();
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
function socketOnEnd() {
|
|
3075
|
+
const websocket = this[kWebSocket];
|
|
3076
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3077
|
+
websocket._receiver.end();
|
|
3078
|
+
this.end();
|
|
3079
|
+
}
|
|
3080
|
+
function socketOnError() {
|
|
3081
|
+
const websocket = this[kWebSocket];
|
|
3082
|
+
this.removeListener("error", socketOnError);
|
|
3083
|
+
this.on("error", NOOP);
|
|
3084
|
+
if (websocket) {
|
|
3085
|
+
websocket._readyState = WebSocket.CLOSING;
|
|
3086
|
+
this.destroy();
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
},
|
|
3090
|
+
431: (module) => {
|
|
3091
|
+
module.exports = eval("require")("bufferutil");
|
|
3092
|
+
},
|
|
3093
|
+
710: (module) => {
|
|
3094
|
+
module.exports = eval("require")("utf-8-validate");
|
|
3095
|
+
},
|
|
3096
|
+
181: (module) => {
|
|
3097
|
+
"use strict";
|
|
3098
|
+
module.exports = require("buffer");
|
|
3099
|
+
},
|
|
3100
|
+
982: (module) => {
|
|
3101
|
+
"use strict";
|
|
3102
|
+
module.exports = require("crypto");
|
|
3103
|
+
},
|
|
3104
|
+
434: (module) => {
|
|
3105
|
+
"use strict";
|
|
3106
|
+
module.exports = require("events");
|
|
3107
|
+
},
|
|
3108
|
+
611: (module) => {
|
|
3109
|
+
"use strict";
|
|
3110
|
+
module.exports = require("http");
|
|
3111
|
+
},
|
|
3112
|
+
692: (module) => {
|
|
3113
|
+
"use strict";
|
|
3114
|
+
module.exports = require("https");
|
|
3115
|
+
},
|
|
3116
|
+
278: (module) => {
|
|
3117
|
+
"use strict";
|
|
3118
|
+
module.exports = require("net");
|
|
3119
|
+
},
|
|
3120
|
+
203: (module) => {
|
|
3121
|
+
"use strict";
|
|
3122
|
+
module.exports = require("stream");
|
|
3123
|
+
},
|
|
3124
|
+
756: (module) => {
|
|
3125
|
+
"use strict";
|
|
3126
|
+
module.exports = require("tls");
|
|
3127
|
+
},
|
|
3128
|
+
16: (module) => {
|
|
3129
|
+
"use strict";
|
|
3130
|
+
module.exports = require("url");
|
|
3131
|
+
},
|
|
3132
|
+
106: (module) => {
|
|
3133
|
+
"use strict";
|
|
3134
|
+
module.exports = require("zlib");
|
|
3135
|
+
},
|
|
3136
|
+
};
|
|
3137
|
+
var __webpack_module_cache__ = {};
|
|
3138
|
+
function __nccwpck_require__(moduleId) {
|
|
3139
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
3140
|
+
if (cachedModule !== undefined) {
|
|
3141
|
+
return cachedModule.exports;
|
|
3142
|
+
}
|
|
3143
|
+
var module = (__webpack_module_cache__[moduleId] = { exports: {} });
|
|
3144
|
+
var threw = true;
|
|
3145
|
+
try {
|
|
3146
|
+
__webpack_modules__[moduleId](
|
|
3147
|
+
module,
|
|
3148
|
+
module.exports,
|
|
3149
|
+
__nccwpck_require__,
|
|
3150
|
+
);
|
|
3151
|
+
threw = false;
|
|
3152
|
+
} finally {
|
|
3153
|
+
if (threw) delete __webpack_module_cache__[moduleId];
|
|
3154
|
+
}
|
|
3155
|
+
return module.exports;
|
|
3156
|
+
}
|
|
3157
|
+
if (typeof __nccwpck_require__ !== "undefined")
|
|
3158
|
+
__nccwpck_require__.ab = __dirname + "/";
|
|
3159
|
+
var __webpack_exports__ = __nccwpck_require__(821);
|
|
3160
|
+
module.exports = __webpack_exports__;
|
|
3161
|
+
})();
|