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