@jsenv/core 36.2.1 → 36.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babel_helpers/AsyncGenerator/AsyncGenerator.js +45 -35
- package/dist/babel_helpers/AwaitValue/AwaitValue.js +3 -3
- package/dist/babel_helpers/applyDecoratedDescriptor/applyDecoratedDescriptor.js +13 -13
- package/dist/babel_helpers/applyDecs/applyDecs.js +227 -42
- package/dist/babel_helpers/applyDecs2203/applyDecs2203.js +559 -418
- package/dist/babel_helpers/applyDecs2203R/applyDecs2203R.js +235 -87
- package/dist/babel_helpers/applyDecs2301/applyDecs2301.js +591 -456
- package/dist/babel_helpers/applyDecs2305/applyDecs2305.js +681 -0
- package/dist/babel_helpers/arrayLikeToArray/arrayLikeToArray.js +5 -5
- package/dist/babel_helpers/arrayWithHoles/arrayWithHoles.js +3 -3
- package/dist/babel_helpers/arrayWithoutHoles/arrayWithoutHoles.js +4 -4
- package/dist/babel_helpers/assertThisInitialized/assertThisInitialized.js +4 -4
- package/dist/babel_helpers/asyncGeneratorDelegate/asyncGeneratorDelegate.js +12 -4
- package/dist/babel_helpers/asyncIterator/asyncIterator.js +13 -11
- package/dist/babel_helpers/asyncToGenerator/asyncToGenerator.js +18 -17
- package/dist/babel_helpers/awaitAsyncGenerator/awaitAsyncGenerator.js +2 -1
- package/dist/babel_helpers/checkInRHS/checkInRHS.js +8 -5
- package/dist/babel_helpers/classApplyDescriptorDestructureSet/classApplyDescriptorDestructureSet.js +7 -7
- package/dist/babel_helpers/classApplyDescriptorGet/classApplyDescriptorGet.js +3 -3
- package/dist/babel_helpers/classApplyDescriptorSet/classApplyDescriptorSet.js +4 -4
- package/dist/babel_helpers/classCallCheck/classCallCheck.js +2 -2
- package/dist/babel_helpers/classCheckPrivateStaticAccess/classCheckPrivateStaticAccess.js +2 -2
- package/dist/babel_helpers/classCheckPrivateStaticFieldDescriptor/classCheckPrivateStaticFieldDescriptor.js +2 -2
- package/dist/babel_helpers/classExtractFieldDescriptor/classExtractFieldDescriptor.js +3 -3
- package/dist/babel_helpers/classNameTDZError/classNameTDZError.js +2 -2
- package/dist/babel_helpers/classPrivateFieldDestructureSet/classPrivateFieldDestructureSet.js +6 -5
- package/dist/babel_helpers/classPrivateFieldGet/classPrivateFieldGet.js +6 -5
- package/dist/babel_helpers/classPrivateFieldLooseBase/classPrivateFieldLooseBase.js +3 -3
- package/dist/babel_helpers/classPrivateFieldLooseKey/classPrivateFieldLooseKey.js +3 -3
- package/dist/babel_helpers/classPrivateFieldSet/classPrivateFieldSet.js +7 -6
- package/dist/babel_helpers/classPrivateMethodGet/classPrivateMethodGet.js +3 -3
- package/dist/babel_helpers/classPrivateMethodSet/classPrivateMethodSet.js +2 -2
- package/dist/babel_helpers/classStaticPrivateFieldSpecGet/classStaticPrivateFieldSpecGet.js +8 -7
- package/dist/babel_helpers/classStaticPrivateFieldSpecSet/classStaticPrivateFieldSpecSet.js +15 -9
- package/dist/babel_helpers/classStaticPrivateMethodGet/classStaticPrivateMethodGet.js +5 -4
- package/dist/babel_helpers/classStaticPrivateMethodSet/classStaticPrivateMethodSet.js +2 -2
- package/dist/babel_helpers/construct/construct.js +10 -9
- package/dist/babel_helpers/createClass/createClass.js +2 -3
- package/dist/babel_helpers/createForOfIteratorHelper/createForOfIteratorHelper.js +30 -29
- package/dist/babel_helpers/createForOfIteratorHelperLoose/createForOfIteratorHelperLoose.js +18 -16
- package/dist/babel_helpers/createRawReactElement/createRawReactElement.js +23 -17
- package/dist/babel_helpers/createSuper/createSuper.js +14 -12
- package/dist/babel_helpers/decorate/decorate.js +242 -210
- package/dist/babel_helpers/defaults/defaults.js +6 -6
- package/dist/babel_helpers/defineAccessor/defineAccessor.js +1 -4
- package/dist/babel_helpers/defineEnumerableProperties/defineEnumerableProperties.js +12 -12
- package/dist/babel_helpers/defineProperty/defineProperty.js +7 -6
- package/dist/babel_helpers/extends/extends.js +5 -4
- package/dist/babel_helpers/get/get.js +2 -1
- package/dist/babel_helpers/getPrototypeOf/getPrototypeOf.js +4 -3
- package/dist/babel_helpers/inherits/inherits.js +3 -4
- package/dist/babel_helpers/inheritsLoose/inheritsLoose.js +6 -5
- package/dist/babel_helpers/initializerDefineProperty/initializerDefineProperty.js +4 -4
- package/dist/babel_helpers/initializerWarningHelper/initializerWarningHelper.js +5 -2
- package/dist/babel_helpers/instanceof/instanceof.js +3 -3
- package/dist/babel_helpers/interopRequireDefault/interopRequireDefault.js +2 -4
- package/dist/babel_helpers/interopRequireWildcard/interopRequireWildcard.js +19 -21
- package/dist/babel_helpers/isNativeFunction/isNativeFunction.js +2 -2
- package/dist/babel_helpers/isNativeReflectConstruct/isNativeReflectConstruct.js +7 -7
- package/dist/babel_helpers/iterableToArray/iterableToArray.js +6 -2
- package/dist/babel_helpers/iterableToArrayLimit/iterableToArrayLimit.js +6 -1
- package/dist/babel_helpers/iterableToArrayLimitLoose/iterableToArrayLimitLoose.js +6 -2
- package/dist/babel_helpers/jsx/jsx.js +14 -7
- package/dist/babel_helpers/maybeArrayLike/maybeArrayLike.js +6 -5
- package/dist/babel_helpers/newArrowCheck/newArrowCheck.js +2 -2
- package/dist/babel_helpers/nonIterableRest/nonIterableRest.js +5 -3
- package/dist/babel_helpers/nonIterableSpread/nonIterableSpread.js +5 -3
- package/dist/babel_helpers/objectDestructuringEmpty/objectDestructuringEmpty.js +2 -2
- package/dist/babel_helpers/objectSpread/objectSpread.js +15 -12
- package/dist/babel_helpers/objectSpread2/objectSpread2.js +7 -2
- package/dist/babel_helpers/objectWithoutProperties/objectWithoutProperties.js +15 -13
- package/dist/babel_helpers/objectWithoutPropertiesLoose/objectWithoutPropertiesLoose.js +11 -11
- package/dist/babel_helpers/possibleConstructorReturn/possibleConstructorReturn.js +7 -6
- package/dist/babel_helpers/readOnlyError/readOnlyError.js +2 -2
- package/dist/babel_helpers/regeneratorRuntime/regeneratorRuntime.js +124 -73
- package/dist/babel_helpers/set/set.js +23 -20
- package/dist/babel_helpers/setPrototypeOf/setPrototypeOf.js +6 -5
- package/dist/babel_helpers/skipFirstGeneratorNext/skipFirstGeneratorNext.js +5 -5
- package/dist/babel_helpers/slicedToArray/slicedToArray.js +10 -5
- package/dist/babel_helpers/slicedToArrayLoose/slicedToArrayLoose.js +12 -6
- package/dist/babel_helpers/superPropBase/superPropBase.js +6 -5
- package/dist/babel_helpers/taggedTemplateLiteral/taggedTemplateLiteral.js +7 -7
- package/dist/babel_helpers/taggedTemplateLiteralLoose/taggedTemplateLiteralLoose.js +4 -4
- package/dist/babel_helpers/tdz/tdz.js +2 -2
- package/dist/babel_helpers/temporalRef/temporalRef.js +5 -4
- package/dist/babel_helpers/temporalUndefined/temporalUndefined.js +1 -1
- package/dist/babel_helpers/toArray/toArray.js +10 -5
- package/dist/babel_helpers/toConsumableArray/toConsumableArray.js +10 -5
- package/dist/babel_helpers/toPrimitive/toPrimitive.js +7 -7
- package/dist/babel_helpers/toPropertyKey/toPropertyKey.js +5 -4
- package/dist/babel_helpers/typeof/typeof.js +14 -5
- package/dist/babel_helpers/unsupportedIterableToArray/unsupportedIterableToArray.js +10 -8
- package/dist/babel_helpers/wrapAsyncGenerator/wrapAsyncGenerator.js +5 -4
- package/dist/babel_helpers/wrapNativeSuper/wrapNativeSuper.js +17 -15
- package/dist/babel_helpers/wrapRegExp/wrapRegExp.js +19 -8
- package/dist/babel_helpers/writeOnlyError/writeOnlyError.js +2 -2
- package/dist/js/autoreload.js +148 -133
- package/dist/js/import_meta_hot.js +19 -13
- package/dist/js/inline_content.js +1 -3
- package/dist/js/new_stylesheet.js +119 -60
- package/dist/js/regenerator_runtime.js +204 -102
- package/dist/js/ribbon.js +11 -6
- package/dist/js/server_events_client.js +122 -98
- package/dist/js/ws.js +968 -265
- package/dist/jsenv_core.js +8513 -6162
- package/package.json +9 -9
- package/src/build/build.js +497 -486
- package/src/build/version_mappings_injection.js +21 -44
- package/src/kitchen/errors.js +2 -2
- package/src/kitchen/fetched_content_compliance.js +6 -2
- package/src/kitchen/kitchen.js +285 -80
- package/src/kitchen/prepend_content.js +135 -0
- package/src/kitchen/url_graph/url_graph_visitor.js +99 -0
- package/src/kitchen/url_graph/url_info_transformations.js +140 -21
- package/src/kitchen/url_graph.js +59 -29
- package/src/plugins/autoreload/jsenv_plugin_hmr.js +1 -2
- package/src/plugins/import_meta_hot/jsenv_plugin_import_meta_hot.js +2 -2
- package/src/plugins/importmap/jsenv_plugin_importmap.js +2 -2
- package/src/plugins/inlining/jsenv_plugin_inlining_as_data_url.js +1 -1
- package/src/plugins/reference_analysis/html/jsenv_plugin_html_reference_analysis.js +44 -23
- package/src/plugins/reference_analysis/js/jsenv_plugin_js_reference_analysis.js +2 -1
- package/dist/js/global_this_js_classic.js +0 -24
- package/dist/js/global_this_js_module.js +0 -20
- package/src/build/graph_utils.js +0 -34
package/dist/js/ws.js
CHANGED
|
@@ -9,12 +9,12 @@ import require$$0$1 from "zlib";
|
|
|
9
9
|
import require$$0$2 from "buffer";
|
|
10
10
|
import require$$7 from "url";
|
|
11
11
|
|
|
12
|
-
function getDefaultExportFromCjs(x) {
|
|
13
|
-
|
|
12
|
+
function getDefaultExportFromCjs (x) {
|
|
13
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
|
|
16
|
+
var bufferUtil$1 = {exports: {}};
|
|
17
|
+
|
|
18
18
|
var constants = {
|
|
19
19
|
BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
|
|
20
20
|
EMPTY_BUFFER: Buffer.alloc(0),
|
|
@@ -25,11 +25,12 @@ var constants = {
|
|
|
25
25
|
kWebSocket: Symbol('websocket'),
|
|
26
26
|
NOOP: () => {}
|
|
27
27
|
};
|
|
28
|
+
|
|
28
29
|
var unmask$1;
|
|
29
30
|
var mask;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
|
|
32
|
+
const { EMPTY_BUFFER: EMPTY_BUFFER$3 } = constants;
|
|
33
|
+
|
|
33
34
|
const FastBuffer$2 = Buffer[Symbol.species];
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -43,16 +44,20 @@ const FastBuffer$2 = Buffer[Symbol.species];
|
|
|
43
44
|
function concat$1(list, totalLength) {
|
|
44
45
|
if (list.length === 0) return EMPTY_BUFFER$3;
|
|
45
46
|
if (list.length === 1) return list[0];
|
|
47
|
+
|
|
46
48
|
const target = Buffer.allocUnsafe(totalLength);
|
|
47
49
|
let offset = 0;
|
|
50
|
+
|
|
48
51
|
for (let i = 0; i < list.length; i++) {
|
|
49
52
|
const buf = list[i];
|
|
50
53
|
target.set(buf, offset);
|
|
51
54
|
offset += buf.length;
|
|
52
55
|
}
|
|
56
|
+
|
|
53
57
|
if (offset < totalLength) {
|
|
54
58
|
return new FastBuffer$2(target.buffer, target.byteOffset, offset);
|
|
55
59
|
}
|
|
60
|
+
|
|
56
61
|
return target;
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -96,6 +101,7 @@ function toArrayBuffer$1(buf) {
|
|
|
96
101
|
if (buf.length === buf.buffer.byteLength) {
|
|
97
102
|
return buf.buffer;
|
|
98
103
|
}
|
|
104
|
+
|
|
99
105
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
|
|
100
106
|
}
|
|
101
107
|
|
|
@@ -109,8 +115,11 @@ function toArrayBuffer$1(buf) {
|
|
|
109
115
|
*/
|
|
110
116
|
function toBuffer$2(data) {
|
|
111
117
|
toBuffer$2.readOnly = true;
|
|
118
|
+
|
|
112
119
|
if (Buffer.isBuffer(data)) return data;
|
|
120
|
+
|
|
113
121
|
let buf;
|
|
122
|
+
|
|
114
123
|
if (data instanceof ArrayBuffer) {
|
|
115
124
|
buf = new FastBuffer$2(data);
|
|
116
125
|
} else if (ArrayBuffer.isView(data)) {
|
|
@@ -119,8 +128,10 @@ function toBuffer$2(data) {
|
|
|
119
128
|
buf = Buffer.from(data);
|
|
120
129
|
toBuffer$2.readOnly = false;
|
|
121
130
|
}
|
|
131
|
+
|
|
122
132
|
return buf;
|
|
123
133
|
}
|
|
134
|
+
|
|
124
135
|
bufferUtil$1.exports = {
|
|
125
136
|
concat: concat$1,
|
|
126
137
|
mask: _mask,
|
|
@@ -133,17 +144,23 @@ bufferUtil$1.exports = {
|
|
|
133
144
|
if (!process.env.WS_NO_BUFFER_UTIL) {
|
|
134
145
|
try {
|
|
135
146
|
const bufferUtil = require('bufferutil');
|
|
147
|
+
|
|
136
148
|
mask = bufferUtil$1.exports.mask = function (source, mask, output, offset, length) {
|
|
137
|
-
if (length < 48) _mask(source, mask, output, offset, length);
|
|
149
|
+
if (length < 48) _mask(source, mask, output, offset, length);
|
|
150
|
+
else bufferUtil.mask(source, mask, output, offset, length);
|
|
138
151
|
};
|
|
152
|
+
|
|
139
153
|
unmask$1 = bufferUtil$1.exports.unmask = function (buffer, mask) {
|
|
140
|
-
if (buffer.length < 32) _unmask(buffer, mask);
|
|
154
|
+
if (buffer.length < 32) _unmask(buffer, mask);
|
|
155
|
+
else bufferUtil.unmask(buffer, mask);
|
|
141
156
|
};
|
|
142
157
|
} catch (e) {
|
|
143
158
|
// Continue regardless of the error.
|
|
144
159
|
}
|
|
145
160
|
}
|
|
161
|
+
|
|
146
162
|
var bufferUtilExports = bufferUtil$1.exports;
|
|
163
|
+
|
|
147
164
|
const kDone = Symbol('kDone');
|
|
148
165
|
const kRun = Symbol('kRun');
|
|
149
166
|
|
|
@@ -186,20 +203,24 @@ let Limiter$1 = class Limiter {
|
|
|
186
203
|
*/
|
|
187
204
|
[kRun]() {
|
|
188
205
|
if (this.pending === this.concurrency) return;
|
|
206
|
+
|
|
189
207
|
if (this.jobs.length) {
|
|
190
208
|
const job = this.jobs.shift();
|
|
209
|
+
|
|
191
210
|
this.pending++;
|
|
192
211
|
job(this[kDone]);
|
|
193
212
|
}
|
|
194
213
|
}
|
|
195
214
|
};
|
|
215
|
+
|
|
196
216
|
var limiter = Limiter$1;
|
|
217
|
+
|
|
197
218
|
const zlib = require$$0$1;
|
|
219
|
+
|
|
198
220
|
const bufferUtil = bufferUtilExports;
|
|
199
221
|
const Limiter = limiter;
|
|
200
|
-
const {
|
|
201
|
-
|
|
202
|
-
} = constants;
|
|
222
|
+
const { kStatusCode: kStatusCode$2 } = constants;
|
|
223
|
+
|
|
203
224
|
const FastBuffer$1 = Buffer[Symbol.species];
|
|
204
225
|
const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
|
|
205
226
|
const kPerMessageDeflate = Symbol('permessage-deflate');
|
|
@@ -248,13 +269,19 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
248
269
|
constructor(options, isServer, maxPayload) {
|
|
249
270
|
this._maxPayload = maxPayload | 0;
|
|
250
271
|
this._options = options || {};
|
|
251
|
-
this._threshold =
|
|
272
|
+
this._threshold =
|
|
273
|
+
this._options.threshold !== undefined ? this._options.threshold : 1024;
|
|
252
274
|
this._isServer = !!isServer;
|
|
253
275
|
this._deflate = null;
|
|
254
276
|
this._inflate = null;
|
|
277
|
+
|
|
255
278
|
this.params = null;
|
|
279
|
+
|
|
256
280
|
if (!zlibLimiter) {
|
|
257
|
-
const concurrency =
|
|
281
|
+
const concurrency =
|
|
282
|
+
this._options.concurrencyLimit !== undefined
|
|
283
|
+
? this._options.concurrencyLimit
|
|
284
|
+
: 10;
|
|
258
285
|
zlibLimiter = new Limiter(concurrency);
|
|
259
286
|
}
|
|
260
287
|
}
|
|
@@ -274,6 +301,7 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
274
301
|
*/
|
|
275
302
|
offer() {
|
|
276
303
|
const params = {};
|
|
304
|
+
|
|
277
305
|
if (this._options.serverNoContextTakeover) {
|
|
278
306
|
params.server_no_context_takeover = true;
|
|
279
307
|
}
|
|
@@ -288,6 +316,7 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
288
316
|
} else if (this._options.clientMaxWindowBits == null) {
|
|
289
317
|
params.client_max_window_bits = true;
|
|
290
318
|
}
|
|
319
|
+
|
|
291
320
|
return params;
|
|
292
321
|
}
|
|
293
322
|
|
|
@@ -300,7 +329,11 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
300
329
|
*/
|
|
301
330
|
accept(configurations) {
|
|
302
331
|
configurations = this.normalizeParams(configurations);
|
|
303
|
-
|
|
332
|
+
|
|
333
|
+
this.params = this._isServer
|
|
334
|
+
? this.acceptAsServer(configurations)
|
|
335
|
+
: this.acceptAsClient(configurations);
|
|
336
|
+
|
|
304
337
|
return this.params;
|
|
305
338
|
}
|
|
306
339
|
|
|
@@ -314,12 +347,19 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
314
347
|
this._inflate.close();
|
|
315
348
|
this._inflate = null;
|
|
316
349
|
}
|
|
350
|
+
|
|
317
351
|
if (this._deflate) {
|
|
318
352
|
const callback = this._deflate[kCallback];
|
|
353
|
+
|
|
319
354
|
this._deflate.close();
|
|
320
355
|
this._deflate = null;
|
|
356
|
+
|
|
321
357
|
if (callback) {
|
|
322
|
-
callback(
|
|
358
|
+
callback(
|
|
359
|
+
new Error(
|
|
360
|
+
'The deflate stream was closed while data was being processed'
|
|
361
|
+
)
|
|
362
|
+
);
|
|
323
363
|
}
|
|
324
364
|
}
|
|
325
365
|
}
|
|
@@ -333,15 +373,27 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
333
373
|
*/
|
|
334
374
|
acceptAsServer(offers) {
|
|
335
375
|
const opts = this._options;
|
|
336
|
-
const accepted = offers.find(params => {
|
|
337
|
-
if (
|
|
376
|
+
const accepted = offers.find((params) => {
|
|
377
|
+
if (
|
|
378
|
+
(opts.serverNoContextTakeover === false &&
|
|
379
|
+
params.server_no_context_takeover) ||
|
|
380
|
+
(params.server_max_window_bits &&
|
|
381
|
+
(opts.serverMaxWindowBits === false ||
|
|
382
|
+
(typeof opts.serverMaxWindowBits === 'number' &&
|
|
383
|
+
opts.serverMaxWindowBits > params.server_max_window_bits))) ||
|
|
384
|
+
(typeof opts.clientMaxWindowBits === 'number' &&
|
|
385
|
+
!params.client_max_window_bits)
|
|
386
|
+
) {
|
|
338
387
|
return false;
|
|
339
388
|
}
|
|
389
|
+
|
|
340
390
|
return true;
|
|
341
391
|
});
|
|
392
|
+
|
|
342
393
|
if (!accepted) {
|
|
343
394
|
throw new Error('None of the extension offers can be accepted');
|
|
344
395
|
}
|
|
396
|
+
|
|
345
397
|
if (opts.serverNoContextTakeover) {
|
|
346
398
|
accepted.server_no_context_takeover = true;
|
|
347
399
|
}
|
|
@@ -353,9 +405,13 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
353
405
|
}
|
|
354
406
|
if (typeof opts.clientMaxWindowBits === 'number') {
|
|
355
407
|
accepted.client_max_window_bits = opts.clientMaxWindowBits;
|
|
356
|
-
} else if (
|
|
408
|
+
} else if (
|
|
409
|
+
accepted.client_max_window_bits === true ||
|
|
410
|
+
opts.clientMaxWindowBits === false
|
|
411
|
+
) {
|
|
357
412
|
delete accepted.client_max_window_bits;
|
|
358
413
|
}
|
|
414
|
+
|
|
359
415
|
return accepted;
|
|
360
416
|
}
|
|
361
417
|
|
|
@@ -368,16 +424,28 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
368
424
|
*/
|
|
369
425
|
acceptAsClient(response) {
|
|
370
426
|
const params = response[0];
|
|
371
|
-
|
|
427
|
+
|
|
428
|
+
if (
|
|
429
|
+
this._options.clientNoContextTakeover === false &&
|
|
430
|
+
params.client_no_context_takeover
|
|
431
|
+
) {
|
|
372
432
|
throw new Error('Unexpected parameter "client_no_context_takeover"');
|
|
373
433
|
}
|
|
434
|
+
|
|
374
435
|
if (!params.client_max_window_bits) {
|
|
375
436
|
if (typeof this._options.clientMaxWindowBits === 'number') {
|
|
376
437
|
params.client_max_window_bits = this._options.clientMaxWindowBits;
|
|
377
438
|
}
|
|
378
|
-
} else if (
|
|
379
|
-
|
|
439
|
+
} else if (
|
|
440
|
+
this._options.clientMaxWindowBits === false ||
|
|
441
|
+
(typeof this._options.clientMaxWindowBits === 'number' &&
|
|
442
|
+
params.client_max_window_bits > this._options.clientMaxWindowBits)
|
|
443
|
+
) {
|
|
444
|
+
throw new Error(
|
|
445
|
+
'Unexpected or invalid parameter "client_max_window_bits"'
|
|
446
|
+
);
|
|
380
447
|
}
|
|
448
|
+
|
|
381
449
|
return params;
|
|
382
450
|
}
|
|
383
451
|
|
|
@@ -389,39 +457,55 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
389
457
|
* @private
|
|
390
458
|
*/
|
|
391
459
|
normalizeParams(configurations) {
|
|
392
|
-
configurations.forEach(params => {
|
|
393
|
-
Object.keys(params).forEach(key => {
|
|
460
|
+
configurations.forEach((params) => {
|
|
461
|
+
Object.keys(params).forEach((key) => {
|
|
394
462
|
let value = params[key];
|
|
463
|
+
|
|
395
464
|
if (value.length > 1) {
|
|
396
465
|
throw new Error(`Parameter "${key}" must have only a single value`);
|
|
397
466
|
}
|
|
467
|
+
|
|
398
468
|
value = value[0];
|
|
469
|
+
|
|
399
470
|
if (key === 'client_max_window_bits') {
|
|
400
471
|
if (value !== true) {
|
|
401
472
|
const num = +value;
|
|
402
473
|
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
403
|
-
throw new TypeError(
|
|
474
|
+
throw new TypeError(
|
|
475
|
+
`Invalid value for parameter "${key}": ${value}`
|
|
476
|
+
);
|
|
404
477
|
}
|
|
405
478
|
value = num;
|
|
406
479
|
} else if (!this._isServer) {
|
|
407
|
-
throw new TypeError(
|
|
480
|
+
throw new TypeError(
|
|
481
|
+
`Invalid value for parameter "${key}": ${value}`
|
|
482
|
+
);
|
|
408
483
|
}
|
|
409
484
|
} else if (key === 'server_max_window_bits') {
|
|
410
485
|
const num = +value;
|
|
411
486
|
if (!Number.isInteger(num) || num < 8 || num > 15) {
|
|
412
|
-
throw new TypeError(
|
|
487
|
+
throw new TypeError(
|
|
488
|
+
`Invalid value for parameter "${key}": ${value}`
|
|
489
|
+
);
|
|
413
490
|
}
|
|
414
491
|
value = num;
|
|
415
|
-
} else if (
|
|
492
|
+
} else if (
|
|
493
|
+
key === 'client_no_context_takeover' ||
|
|
494
|
+
key === 'server_no_context_takeover'
|
|
495
|
+
) {
|
|
416
496
|
if (value !== true) {
|
|
417
|
-
throw new TypeError(
|
|
497
|
+
throw new TypeError(
|
|
498
|
+
`Invalid value for parameter "${key}": ${value}`
|
|
499
|
+
);
|
|
418
500
|
}
|
|
419
501
|
} else {
|
|
420
502
|
throw new Error(`Unknown parameter "${key}"`);
|
|
421
503
|
}
|
|
504
|
+
|
|
422
505
|
params[key] = value;
|
|
423
506
|
});
|
|
424
507
|
});
|
|
508
|
+
|
|
425
509
|
return configurations;
|
|
426
510
|
}
|
|
427
511
|
|
|
@@ -434,7 +518,7 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
434
518
|
* @public
|
|
435
519
|
*/
|
|
436
520
|
decompress(data, fin, callback) {
|
|
437
|
-
zlibLimiter.add(done => {
|
|
521
|
+
zlibLimiter.add((done) => {
|
|
438
522
|
this._decompress(data, fin, (err, result) => {
|
|
439
523
|
done();
|
|
440
524
|
callback(err, result);
|
|
@@ -451,7 +535,7 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
451
535
|
* @public
|
|
452
536
|
*/
|
|
453
537
|
compress(data, fin, callback) {
|
|
454
|
-
zlibLimiter.add(done => {
|
|
538
|
+
zlibLimiter.add((done) => {
|
|
455
539
|
this._compress(data, fin, (err, result) => {
|
|
456
540
|
done();
|
|
457
541
|
callback(err, result);
|
|
@@ -469,9 +553,14 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
469
553
|
*/
|
|
470
554
|
_decompress(data, fin, callback) {
|
|
471
555
|
const endpoint = this._isServer ? 'client' : 'server';
|
|
556
|
+
|
|
472
557
|
if (!this._inflate) {
|
|
473
558
|
const key = `${endpoint}_max_window_bits`;
|
|
474
|
-
const windowBits =
|
|
559
|
+
const windowBits =
|
|
560
|
+
typeof this.params[key] !== 'number'
|
|
561
|
+
? zlib.Z_DEFAULT_WINDOWBITS
|
|
562
|
+
: this.params[key];
|
|
563
|
+
|
|
475
564
|
this._inflate = zlib.createInflateRaw({
|
|
476
565
|
...this._options.zlibInflateOptions,
|
|
477
566
|
windowBits
|
|
@@ -482,28 +571,39 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
482
571
|
this._inflate.on('error', inflateOnError);
|
|
483
572
|
this._inflate.on('data', inflateOnData);
|
|
484
573
|
}
|
|
574
|
+
|
|
485
575
|
this._inflate[kCallback] = callback;
|
|
576
|
+
|
|
486
577
|
this._inflate.write(data);
|
|
487
578
|
if (fin) this._inflate.write(TRAILER);
|
|
579
|
+
|
|
488
580
|
this._inflate.flush(() => {
|
|
489
581
|
const err = this._inflate[kError$1];
|
|
582
|
+
|
|
490
583
|
if (err) {
|
|
491
584
|
this._inflate.close();
|
|
492
585
|
this._inflate = null;
|
|
493
586
|
callback(err);
|
|
494
587
|
return;
|
|
495
588
|
}
|
|
496
|
-
|
|
589
|
+
|
|
590
|
+
const data = bufferUtil.concat(
|
|
591
|
+
this._inflate[kBuffers],
|
|
592
|
+
this._inflate[kTotalLength]
|
|
593
|
+
);
|
|
594
|
+
|
|
497
595
|
if (this._inflate._readableState.endEmitted) {
|
|
498
596
|
this._inflate.close();
|
|
499
597
|
this._inflate = null;
|
|
500
598
|
} else {
|
|
501
599
|
this._inflate[kTotalLength] = 0;
|
|
502
600
|
this._inflate[kBuffers] = [];
|
|
601
|
+
|
|
503
602
|
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
504
603
|
this._inflate.reset();
|
|
505
604
|
}
|
|
506
605
|
}
|
|
606
|
+
|
|
507
607
|
callback(null, data);
|
|
508
608
|
});
|
|
509
609
|
}
|
|
@@ -518,18 +618,27 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
518
618
|
*/
|
|
519
619
|
_compress(data, fin, callback) {
|
|
520
620
|
const endpoint = this._isServer ? 'server' : 'client';
|
|
621
|
+
|
|
521
622
|
if (!this._deflate) {
|
|
522
623
|
const key = `${endpoint}_max_window_bits`;
|
|
523
|
-
const windowBits =
|
|
624
|
+
const windowBits =
|
|
625
|
+
typeof this.params[key] !== 'number'
|
|
626
|
+
? zlib.Z_DEFAULT_WINDOWBITS
|
|
627
|
+
: this.params[key];
|
|
628
|
+
|
|
524
629
|
this._deflate = zlib.createDeflateRaw({
|
|
525
630
|
...this._options.zlibDeflateOptions,
|
|
526
631
|
windowBits
|
|
527
632
|
});
|
|
633
|
+
|
|
528
634
|
this._deflate[kTotalLength] = 0;
|
|
529
635
|
this._deflate[kBuffers] = [];
|
|
636
|
+
|
|
530
637
|
this._deflate.on('data', deflateOnData);
|
|
531
638
|
}
|
|
639
|
+
|
|
532
640
|
this._deflate[kCallback] = callback;
|
|
641
|
+
|
|
533
642
|
this._deflate.write(data);
|
|
534
643
|
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
|
|
535
644
|
if (!this._deflate) {
|
|
@@ -538,7 +647,12 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
538
647
|
//
|
|
539
648
|
return;
|
|
540
649
|
}
|
|
541
|
-
|
|
650
|
+
|
|
651
|
+
let data = bufferUtil.concat(
|
|
652
|
+
this._deflate[kBuffers],
|
|
653
|
+
this._deflate[kTotalLength]
|
|
654
|
+
);
|
|
655
|
+
|
|
542
656
|
if (fin) {
|
|
543
657
|
data = new FastBuffer$1(data.buffer, data.byteOffset, data.length - 4);
|
|
544
658
|
}
|
|
@@ -548,15 +662,19 @@ let PerMessageDeflate$4 = class PerMessageDeflate {
|
|
|
548
662
|
// `PerMessageDeflate#cleanup()`.
|
|
549
663
|
//
|
|
550
664
|
this._deflate[kCallback] = null;
|
|
665
|
+
|
|
551
666
|
this._deflate[kTotalLength] = 0;
|
|
552
667
|
this._deflate[kBuffers] = [];
|
|
668
|
+
|
|
553
669
|
if (fin && this.params[`${endpoint}_no_context_takeover`]) {
|
|
554
670
|
this._deflate.reset();
|
|
555
671
|
}
|
|
672
|
+
|
|
556
673
|
callback(null, data);
|
|
557
674
|
});
|
|
558
675
|
}
|
|
559
676
|
};
|
|
677
|
+
|
|
560
678
|
var permessageDeflate = PerMessageDeflate$4;
|
|
561
679
|
|
|
562
680
|
/**
|
|
@@ -578,10 +696,15 @@ function deflateOnData(chunk) {
|
|
|
578
696
|
*/
|
|
579
697
|
function inflateOnData(chunk) {
|
|
580
698
|
this[kTotalLength] += chunk.length;
|
|
581
|
-
|
|
699
|
+
|
|
700
|
+
if (
|
|
701
|
+
this[kPerMessageDeflate]._maxPayload < 1 ||
|
|
702
|
+
this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
|
|
703
|
+
) {
|
|
582
704
|
this[kBuffers].push(chunk);
|
|
583
705
|
return;
|
|
584
706
|
}
|
|
707
|
+
|
|
585
708
|
this[kError$1] = new RangeError('Max payload size exceeded');
|
|
586
709
|
this[kError$1].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
|
|
587
710
|
this[kError$1][kStatusCode$2] = 1009;
|
|
@@ -604,13 +727,12 @@ function inflateOnError(err) {
|
|
|
604
727
|
err[kStatusCode$2] = 1007;
|
|
605
728
|
this[kCallback](err);
|
|
606
729
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
730
|
+
|
|
731
|
+
var validation = {exports: {}};
|
|
732
|
+
|
|
610
733
|
var isValidUTF8_1;
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
} = require$$0$2;
|
|
734
|
+
|
|
735
|
+
const { isUtf8 } = require$$0$2;
|
|
614
736
|
|
|
615
737
|
//
|
|
616
738
|
// Allowed token characters:
|
|
@@ -624,21 +746,15 @@ const {
|
|
|
624
746
|
// ...
|
|
625
747
|
//
|
|
626
748
|
// prettier-ignore
|
|
627
|
-
const tokenChars$2 = [
|
|
628
|
-
// 0 - 15
|
|
629
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
630
|
-
//
|
|
631
|
-
|
|
632
|
-
//
|
|
633
|
-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
634
|
-
//
|
|
635
|
-
|
|
636
|
-
// 64 - 79
|
|
637
|
-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,
|
|
638
|
-
// 80 - 95
|
|
639
|
-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
640
|
-
// 96 - 111
|
|
641
|
-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
|
|
749
|
+
const tokenChars$2 = [
|
|
750
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
|
|
751
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
|
|
752
|
+
0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47
|
|
753
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
|
|
754
|
+
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
|
|
755
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95
|
|
756
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
|
|
757
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
|
|
642
758
|
];
|
|
643
759
|
|
|
644
760
|
/**
|
|
@@ -649,7 +765,14 @@ const tokenChars$2 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
649
765
|
* @public
|
|
650
766
|
*/
|
|
651
767
|
function isValidStatusCode$2(code) {
|
|
652
|
-
return
|
|
768
|
+
return (
|
|
769
|
+
(code >= 1000 &&
|
|
770
|
+
code <= 1014 &&
|
|
771
|
+
code !== 1004 &&
|
|
772
|
+
code !== 1005 &&
|
|
773
|
+
code !== 1006) ||
|
|
774
|
+
(code >= 3000 && code <= 4999)
|
|
775
|
+
);
|
|
653
776
|
}
|
|
654
777
|
|
|
655
778
|
/**
|
|
@@ -664,53 +787,72 @@ function isValidStatusCode$2(code) {
|
|
|
664
787
|
function _isValidUTF8(buf) {
|
|
665
788
|
const len = buf.length;
|
|
666
789
|
let i = 0;
|
|
790
|
+
|
|
667
791
|
while (i < len) {
|
|
668
792
|
if ((buf[i] & 0x80) === 0) {
|
|
669
793
|
// 0xxxxxxx
|
|
670
794
|
i++;
|
|
671
795
|
} else if ((buf[i] & 0xe0) === 0xc0) {
|
|
672
796
|
// 110xxxxx 10xxxxxx
|
|
673
|
-
if (
|
|
797
|
+
if (
|
|
798
|
+
i + 1 === len ||
|
|
799
|
+
(buf[i + 1] & 0xc0) !== 0x80 ||
|
|
800
|
+
(buf[i] & 0xfe) === 0xc0 // Overlong
|
|
674
801
|
) {
|
|
675
802
|
return false;
|
|
676
803
|
}
|
|
804
|
+
|
|
677
805
|
i += 2;
|
|
678
806
|
} else if ((buf[i] & 0xf0) === 0xe0) {
|
|
679
807
|
// 1110xxxx 10xxxxxx 10xxxxxx
|
|
680
|
-
if (
|
|
681
|
-
|
|
682
|
-
|
|
808
|
+
if (
|
|
809
|
+
i + 2 >= len ||
|
|
810
|
+
(buf[i + 1] & 0xc0) !== 0x80 ||
|
|
811
|
+
(buf[i + 2] & 0xc0) !== 0x80 ||
|
|
812
|
+
(buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // Overlong
|
|
813
|
+
(buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // Surrogate (U+D800 - U+DFFF)
|
|
683
814
|
) {
|
|
684
815
|
return false;
|
|
685
816
|
}
|
|
817
|
+
|
|
686
818
|
i += 3;
|
|
687
819
|
} else if ((buf[i] & 0xf8) === 0xf0) {
|
|
688
820
|
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
|
689
|
-
if (
|
|
690
|
-
|
|
691
|
-
|
|
821
|
+
if (
|
|
822
|
+
i + 3 >= len ||
|
|
823
|
+
(buf[i + 1] & 0xc0) !== 0x80 ||
|
|
824
|
+
(buf[i + 2] & 0xc0) !== 0x80 ||
|
|
825
|
+
(buf[i + 3] & 0xc0) !== 0x80 ||
|
|
826
|
+
(buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // Overlong
|
|
827
|
+
(buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
|
|
828
|
+
buf[i] > 0xf4 // > U+10FFFF
|
|
692
829
|
) {
|
|
693
830
|
return false;
|
|
694
831
|
}
|
|
832
|
+
|
|
695
833
|
i += 4;
|
|
696
834
|
} else {
|
|
697
835
|
return false;
|
|
698
836
|
}
|
|
699
837
|
}
|
|
838
|
+
|
|
700
839
|
return true;
|
|
701
840
|
}
|
|
841
|
+
|
|
702
842
|
validation.exports = {
|
|
703
843
|
isValidStatusCode: isValidStatusCode$2,
|
|
704
844
|
isValidUTF8: _isValidUTF8,
|
|
705
845
|
tokenChars: tokenChars$2
|
|
706
846
|
};
|
|
847
|
+
|
|
707
848
|
if (isUtf8) {
|
|
708
849
|
isValidUTF8_1 = validation.exports.isValidUTF8 = function (buf) {
|
|
709
850
|
return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
|
|
710
851
|
};
|
|
711
|
-
} /* istanbul ignore else */else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
852
|
+
} /* istanbul ignore else */ else if (!process.env.WS_NO_UTF_8_VALIDATE) {
|
|
712
853
|
try {
|
|
713
854
|
const isValidUTF8 = require('utf-8-validate');
|
|
855
|
+
|
|
714
856
|
isValidUTF8_1 = validation.exports.isValidUTF8 = function (buf) {
|
|
715
857
|
return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
|
|
716
858
|
};
|
|
@@ -718,10 +860,11 @@ if (isUtf8) {
|
|
|
718
860
|
// Continue regardless of the error.
|
|
719
861
|
}
|
|
720
862
|
}
|
|
863
|
+
|
|
721
864
|
var validationExports = validation.exports;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
865
|
+
|
|
866
|
+
const { Writable } = require$$0;
|
|
867
|
+
|
|
725
868
|
const PerMessageDeflate$3 = permessageDeflate;
|
|
726
869
|
const {
|
|
727
870
|
BINARY_TYPES: BINARY_TYPES$1,
|
|
@@ -729,15 +872,9 @@ const {
|
|
|
729
872
|
kStatusCode: kStatusCode$1,
|
|
730
873
|
kWebSocket: kWebSocket$2
|
|
731
874
|
} = constants;
|
|
732
|
-
const {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
unmask
|
|
736
|
-
} = bufferUtilExports;
|
|
737
|
-
const {
|
|
738
|
-
isValidStatusCode: isValidStatusCode$1,
|
|
739
|
-
isValidUTF8
|
|
740
|
-
} = validationExports;
|
|
875
|
+
const { concat, toArrayBuffer, unmask } = bufferUtilExports;
|
|
876
|
+
const { isValidStatusCode: isValidStatusCode$1, isValidUTF8 } = validationExports;
|
|
877
|
+
|
|
741
878
|
const FastBuffer = Buffer[Symbol.species];
|
|
742
879
|
const GET_INFO = 0;
|
|
743
880
|
const GET_PAYLOAD_LENGTH_16 = 1;
|
|
@@ -767,14 +904,17 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
767
904
|
*/
|
|
768
905
|
constructor(options = {}) {
|
|
769
906
|
super();
|
|
907
|
+
|
|
770
908
|
this._binaryType = options.binaryType || BINARY_TYPES$1[0];
|
|
771
909
|
this._extensions = options.extensions || {};
|
|
772
910
|
this._isServer = !!options.isServer;
|
|
773
911
|
this._maxPayload = options.maxPayload | 0;
|
|
774
912
|
this._skipUTF8Validation = !!options.skipUTF8Validation;
|
|
775
913
|
this[kWebSocket$2] = undefined;
|
|
914
|
+
|
|
776
915
|
this._bufferedBytes = 0;
|
|
777
916
|
this._buffers = [];
|
|
917
|
+
|
|
778
918
|
this._compressed = false;
|
|
779
919
|
this._payloadLength = 0;
|
|
780
920
|
this._mask = undefined;
|
|
@@ -782,9 +922,11 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
782
922
|
this._masked = false;
|
|
783
923
|
this._fin = false;
|
|
784
924
|
this._opcode = 0;
|
|
925
|
+
|
|
785
926
|
this._totalPayloadLength = 0;
|
|
786
927
|
this._messageLength = 0;
|
|
787
928
|
this._fragments = [];
|
|
929
|
+
|
|
788
930
|
this._state = GET_INFO;
|
|
789
931
|
this._loop = false;
|
|
790
932
|
}
|
|
@@ -799,6 +941,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
799
941
|
*/
|
|
800
942
|
_write(chunk, encoding, cb) {
|
|
801
943
|
if (this._opcode === 0x08 && this._state == GET_INFO) return cb();
|
|
944
|
+
|
|
802
945
|
this._bufferedBytes += chunk.length;
|
|
803
946
|
this._buffers.push(chunk);
|
|
804
947
|
this.startLoop(cb);
|
|
@@ -813,24 +956,40 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
813
956
|
*/
|
|
814
957
|
consume(n) {
|
|
815
958
|
this._bufferedBytes -= n;
|
|
959
|
+
|
|
816
960
|
if (n === this._buffers[0].length) return this._buffers.shift();
|
|
961
|
+
|
|
817
962
|
if (n < this._buffers[0].length) {
|
|
818
963
|
const buf = this._buffers[0];
|
|
819
|
-
this._buffers[0] = new FastBuffer(
|
|
964
|
+
this._buffers[0] = new FastBuffer(
|
|
965
|
+
buf.buffer,
|
|
966
|
+
buf.byteOffset + n,
|
|
967
|
+
buf.length - n
|
|
968
|
+
);
|
|
969
|
+
|
|
820
970
|
return new FastBuffer(buf.buffer, buf.byteOffset, n);
|
|
821
971
|
}
|
|
972
|
+
|
|
822
973
|
const dst = Buffer.allocUnsafe(n);
|
|
974
|
+
|
|
823
975
|
do {
|
|
824
976
|
const buf = this._buffers[0];
|
|
825
977
|
const offset = dst.length - n;
|
|
978
|
+
|
|
826
979
|
if (n >= buf.length) {
|
|
827
980
|
dst.set(this._buffers.shift(), offset);
|
|
828
981
|
} else {
|
|
829
982
|
dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
|
|
830
|
-
this._buffers[0] = new FastBuffer(
|
|
983
|
+
this._buffers[0] = new FastBuffer(
|
|
984
|
+
buf.buffer,
|
|
985
|
+
buf.byteOffset + n,
|
|
986
|
+
buf.length - n
|
|
987
|
+
);
|
|
831
988
|
}
|
|
989
|
+
|
|
832
990
|
n -= buf.length;
|
|
833
991
|
} while (n > 0);
|
|
992
|
+
|
|
834
993
|
return dst;
|
|
835
994
|
}
|
|
836
995
|
|
|
@@ -843,6 +1002,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
843
1002
|
startLoop(cb) {
|
|
844
1003
|
let err;
|
|
845
1004
|
this._loop = true;
|
|
1005
|
+
|
|
846
1006
|
do {
|
|
847
1007
|
switch (this._state) {
|
|
848
1008
|
case GET_INFO:
|
|
@@ -866,6 +1026,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
866
1026
|
return;
|
|
867
1027
|
}
|
|
868
1028
|
} while (this._loop);
|
|
1029
|
+
|
|
869
1030
|
cb(err);
|
|
870
1031
|
}
|
|
871
1032
|
|
|
@@ -880,64 +1041,149 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
880
1041
|
this._loop = false;
|
|
881
1042
|
return;
|
|
882
1043
|
}
|
|
1044
|
+
|
|
883
1045
|
const buf = this.consume(2);
|
|
1046
|
+
|
|
884
1047
|
if ((buf[0] & 0x30) !== 0x00) {
|
|
885
1048
|
this._loop = false;
|
|
886
|
-
return error(
|
|
1049
|
+
return error(
|
|
1050
|
+
RangeError,
|
|
1051
|
+
'RSV2 and RSV3 must be clear',
|
|
1052
|
+
true,
|
|
1053
|
+
1002,
|
|
1054
|
+
'WS_ERR_UNEXPECTED_RSV_2_3'
|
|
1055
|
+
);
|
|
887
1056
|
}
|
|
1057
|
+
|
|
888
1058
|
const compressed = (buf[0] & 0x40) === 0x40;
|
|
1059
|
+
|
|
889
1060
|
if (compressed && !this._extensions[PerMessageDeflate$3.extensionName]) {
|
|
890
1061
|
this._loop = false;
|
|
891
|
-
return error(
|
|
1062
|
+
return error(
|
|
1063
|
+
RangeError,
|
|
1064
|
+
'RSV1 must be clear',
|
|
1065
|
+
true,
|
|
1066
|
+
1002,
|
|
1067
|
+
'WS_ERR_UNEXPECTED_RSV_1'
|
|
1068
|
+
);
|
|
892
1069
|
}
|
|
1070
|
+
|
|
893
1071
|
this._fin = (buf[0] & 0x80) === 0x80;
|
|
894
1072
|
this._opcode = buf[0] & 0x0f;
|
|
895
1073
|
this._payloadLength = buf[1] & 0x7f;
|
|
1074
|
+
|
|
896
1075
|
if (this._opcode === 0x00) {
|
|
897
1076
|
if (compressed) {
|
|
898
1077
|
this._loop = false;
|
|
899
|
-
return error(
|
|
1078
|
+
return error(
|
|
1079
|
+
RangeError,
|
|
1080
|
+
'RSV1 must be clear',
|
|
1081
|
+
true,
|
|
1082
|
+
1002,
|
|
1083
|
+
'WS_ERR_UNEXPECTED_RSV_1'
|
|
1084
|
+
);
|
|
900
1085
|
}
|
|
1086
|
+
|
|
901
1087
|
if (!this._fragmented) {
|
|
902
1088
|
this._loop = false;
|
|
903
|
-
return error(
|
|
1089
|
+
return error(
|
|
1090
|
+
RangeError,
|
|
1091
|
+
'invalid opcode 0',
|
|
1092
|
+
true,
|
|
1093
|
+
1002,
|
|
1094
|
+
'WS_ERR_INVALID_OPCODE'
|
|
1095
|
+
);
|
|
904
1096
|
}
|
|
1097
|
+
|
|
905
1098
|
this._opcode = this._fragmented;
|
|
906
1099
|
} else if (this._opcode === 0x01 || this._opcode === 0x02) {
|
|
907
1100
|
if (this._fragmented) {
|
|
908
1101
|
this._loop = false;
|
|
909
|
-
return error(
|
|
1102
|
+
return error(
|
|
1103
|
+
RangeError,
|
|
1104
|
+
`invalid opcode ${this._opcode}`,
|
|
1105
|
+
true,
|
|
1106
|
+
1002,
|
|
1107
|
+
'WS_ERR_INVALID_OPCODE'
|
|
1108
|
+
);
|
|
910
1109
|
}
|
|
1110
|
+
|
|
911
1111
|
this._compressed = compressed;
|
|
912
1112
|
} else if (this._opcode > 0x07 && this._opcode < 0x0b) {
|
|
913
1113
|
if (!this._fin) {
|
|
914
1114
|
this._loop = false;
|
|
915
|
-
return error(
|
|
1115
|
+
return error(
|
|
1116
|
+
RangeError,
|
|
1117
|
+
'FIN must be set',
|
|
1118
|
+
true,
|
|
1119
|
+
1002,
|
|
1120
|
+
'WS_ERR_EXPECTED_FIN'
|
|
1121
|
+
);
|
|
916
1122
|
}
|
|
1123
|
+
|
|
917
1124
|
if (compressed) {
|
|
918
1125
|
this._loop = false;
|
|
919
|
-
return error(
|
|
1126
|
+
return error(
|
|
1127
|
+
RangeError,
|
|
1128
|
+
'RSV1 must be clear',
|
|
1129
|
+
true,
|
|
1130
|
+
1002,
|
|
1131
|
+
'WS_ERR_UNEXPECTED_RSV_1'
|
|
1132
|
+
);
|
|
920
1133
|
}
|
|
921
|
-
|
|
1134
|
+
|
|
1135
|
+
if (
|
|
1136
|
+
this._payloadLength > 0x7d ||
|
|
1137
|
+
(this._opcode === 0x08 && this._payloadLength === 1)
|
|
1138
|
+
) {
|
|
922
1139
|
this._loop = false;
|
|
923
|
-
return error(
|
|
1140
|
+
return error(
|
|
1141
|
+
RangeError,
|
|
1142
|
+
`invalid payload length ${this._payloadLength}`,
|
|
1143
|
+
true,
|
|
1144
|
+
1002,
|
|
1145
|
+
'WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH'
|
|
1146
|
+
);
|
|
924
1147
|
}
|
|
925
1148
|
} else {
|
|
926
1149
|
this._loop = false;
|
|
927
|
-
return error(
|
|
1150
|
+
return error(
|
|
1151
|
+
RangeError,
|
|
1152
|
+
`invalid opcode ${this._opcode}`,
|
|
1153
|
+
true,
|
|
1154
|
+
1002,
|
|
1155
|
+
'WS_ERR_INVALID_OPCODE'
|
|
1156
|
+
);
|
|
928
1157
|
}
|
|
1158
|
+
|
|
929
1159
|
if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
|
|
930
1160
|
this._masked = (buf[1] & 0x80) === 0x80;
|
|
1161
|
+
|
|
931
1162
|
if (this._isServer) {
|
|
932
1163
|
if (!this._masked) {
|
|
933
1164
|
this._loop = false;
|
|
934
|
-
return error(
|
|
1165
|
+
return error(
|
|
1166
|
+
RangeError,
|
|
1167
|
+
'MASK must be set',
|
|
1168
|
+
true,
|
|
1169
|
+
1002,
|
|
1170
|
+
'WS_ERR_EXPECTED_MASK'
|
|
1171
|
+
);
|
|
935
1172
|
}
|
|
936
1173
|
} else if (this._masked) {
|
|
937
1174
|
this._loop = false;
|
|
938
|
-
return error(
|
|
1175
|
+
return error(
|
|
1176
|
+
RangeError,
|
|
1177
|
+
'MASK must be clear',
|
|
1178
|
+
true,
|
|
1179
|
+
1002,
|
|
1180
|
+
'WS_ERR_UNEXPECTED_MASK'
|
|
1181
|
+
);
|
|
939
1182
|
}
|
|
940
|
-
|
|
1183
|
+
|
|
1184
|
+
if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
|
|
1185
|
+
else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
|
|
1186
|
+
else return this.haveLength();
|
|
941
1187
|
}
|
|
942
1188
|
|
|
943
1189
|
/**
|
|
@@ -951,6 +1197,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
951
1197
|
this._loop = false;
|
|
952
1198
|
return;
|
|
953
1199
|
}
|
|
1200
|
+
|
|
954
1201
|
this._payloadLength = this.consume(2).readUInt16BE(0);
|
|
955
1202
|
return this.haveLength();
|
|
956
1203
|
}
|
|
@@ -966,6 +1213,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
966
1213
|
this._loop = false;
|
|
967
1214
|
return;
|
|
968
1215
|
}
|
|
1216
|
+
|
|
969
1217
|
const buf = this.consume(8);
|
|
970
1218
|
const num = buf.readUInt32BE(0);
|
|
971
1219
|
|
|
@@ -975,8 +1223,15 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
975
1223
|
//
|
|
976
1224
|
if (num > Math.pow(2, 53 - 32) - 1) {
|
|
977
1225
|
this._loop = false;
|
|
978
|
-
return error(
|
|
1226
|
+
return error(
|
|
1227
|
+
RangeError,
|
|
1228
|
+
'Unsupported WebSocket frame: payload length > 2^53 - 1',
|
|
1229
|
+
false,
|
|
1230
|
+
1009,
|
|
1231
|
+
'WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH'
|
|
1232
|
+
);
|
|
979
1233
|
}
|
|
1234
|
+
|
|
980
1235
|
this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
|
|
981
1236
|
return this.haveLength();
|
|
982
1237
|
}
|
|
@@ -992,10 +1247,18 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
992
1247
|
this._totalPayloadLength += this._payloadLength;
|
|
993
1248
|
if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
|
|
994
1249
|
this._loop = false;
|
|
995
|
-
return error(
|
|
1250
|
+
return error(
|
|
1251
|
+
RangeError,
|
|
1252
|
+
'Max payload size exceeded',
|
|
1253
|
+
false,
|
|
1254
|
+
1009,
|
|
1255
|
+
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
|
1256
|
+
);
|
|
996
1257
|
}
|
|
997
1258
|
}
|
|
998
|
-
|
|
1259
|
+
|
|
1260
|
+
if (this._masked) this._state = GET_MASK;
|
|
1261
|
+
else this._state = GET_DATA;
|
|
999
1262
|
}
|
|
1000
1263
|
|
|
1001
1264
|
/**
|
|
@@ -1008,6 +1271,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1008
1271
|
this._loop = false;
|
|
1009
1272
|
return;
|
|
1010
1273
|
}
|
|
1274
|
+
|
|
1011
1275
|
this._mask = this.consume(4);
|
|
1012
1276
|
this._state = GET_DATA;
|
|
1013
1277
|
}
|
|
@@ -1021,22 +1285,31 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1021
1285
|
*/
|
|
1022
1286
|
getData(cb) {
|
|
1023
1287
|
let data = EMPTY_BUFFER$2;
|
|
1288
|
+
|
|
1024
1289
|
if (this._payloadLength) {
|
|
1025
1290
|
if (this._bufferedBytes < this._payloadLength) {
|
|
1026
1291
|
this._loop = false;
|
|
1027
1292
|
return;
|
|
1028
1293
|
}
|
|
1294
|
+
|
|
1029
1295
|
data = this.consume(this._payloadLength);
|
|
1030
|
-
|
|
1296
|
+
|
|
1297
|
+
if (
|
|
1298
|
+
this._masked &&
|
|
1299
|
+
(this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0
|
|
1300
|
+
) {
|
|
1031
1301
|
unmask(data, this._mask);
|
|
1032
1302
|
}
|
|
1033
1303
|
}
|
|
1304
|
+
|
|
1034
1305
|
if (this._opcode > 0x07) return this.controlMessage(data);
|
|
1306
|
+
|
|
1035
1307
|
if (this._compressed) {
|
|
1036
1308
|
this._state = INFLATING;
|
|
1037
1309
|
this.decompress(data, cb);
|
|
1038
1310
|
return;
|
|
1039
1311
|
}
|
|
1312
|
+
|
|
1040
1313
|
if (data.length) {
|
|
1041
1314
|
//
|
|
1042
1315
|
// This message is not compressed so its length is the sum of the payload
|
|
@@ -1045,6 +1318,7 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1045
1318
|
this._messageLength = this._totalPayloadLength;
|
|
1046
1319
|
this._fragments.push(data);
|
|
1047
1320
|
}
|
|
1321
|
+
|
|
1048
1322
|
return this.dataMessage();
|
|
1049
1323
|
}
|
|
1050
1324
|
|
|
@@ -1057,17 +1331,30 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1057
1331
|
*/
|
|
1058
1332
|
decompress(data, cb) {
|
|
1059
1333
|
const perMessageDeflate = this._extensions[PerMessageDeflate$3.extensionName];
|
|
1334
|
+
|
|
1060
1335
|
perMessageDeflate.decompress(data, this._fin, (err, buf) => {
|
|
1061
1336
|
if (err) return cb(err);
|
|
1337
|
+
|
|
1062
1338
|
if (buf.length) {
|
|
1063
1339
|
this._messageLength += buf.length;
|
|
1064
1340
|
if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
|
|
1065
|
-
return cb(
|
|
1341
|
+
return cb(
|
|
1342
|
+
error(
|
|
1343
|
+
RangeError,
|
|
1344
|
+
'Max payload size exceeded',
|
|
1345
|
+
false,
|
|
1346
|
+
1009,
|
|
1347
|
+
'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH'
|
|
1348
|
+
)
|
|
1349
|
+
);
|
|
1066
1350
|
}
|
|
1351
|
+
|
|
1067
1352
|
this._fragments.push(buf);
|
|
1068
1353
|
}
|
|
1354
|
+
|
|
1069
1355
|
const er = this.dataMessage();
|
|
1070
1356
|
if (er) return cb(er);
|
|
1357
|
+
|
|
1071
1358
|
this.startLoop(cb);
|
|
1072
1359
|
});
|
|
1073
1360
|
}
|
|
@@ -1082,12 +1369,15 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1082
1369
|
if (this._fin) {
|
|
1083
1370
|
const messageLength = this._messageLength;
|
|
1084
1371
|
const fragments = this._fragments;
|
|
1372
|
+
|
|
1085
1373
|
this._totalPayloadLength = 0;
|
|
1086
1374
|
this._messageLength = 0;
|
|
1087
1375
|
this._fragmented = 0;
|
|
1088
1376
|
this._fragments = [];
|
|
1377
|
+
|
|
1089
1378
|
if (this._opcode === 2) {
|
|
1090
1379
|
let data;
|
|
1380
|
+
|
|
1091
1381
|
if (this._binaryType === 'nodebuffer') {
|
|
1092
1382
|
data = concat(fragments, messageLength);
|
|
1093
1383
|
} else if (this._binaryType === 'arraybuffer') {
|
|
@@ -1095,16 +1385,26 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1095
1385
|
} else {
|
|
1096
1386
|
data = fragments;
|
|
1097
1387
|
}
|
|
1388
|
+
|
|
1098
1389
|
this.emit('message', data, true);
|
|
1099
1390
|
} else {
|
|
1100
1391
|
const buf = concat(fragments, messageLength);
|
|
1392
|
+
|
|
1101
1393
|
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
1102
1394
|
this._loop = false;
|
|
1103
|
-
return error(
|
|
1395
|
+
return error(
|
|
1396
|
+
Error,
|
|
1397
|
+
'invalid UTF-8 sequence',
|
|
1398
|
+
true,
|
|
1399
|
+
1007,
|
|
1400
|
+
'WS_ERR_INVALID_UTF8'
|
|
1401
|
+
);
|
|
1104
1402
|
}
|
|
1403
|
+
|
|
1105
1404
|
this.emit('message', buf, false);
|
|
1106
1405
|
}
|
|
1107
1406
|
}
|
|
1407
|
+
|
|
1108
1408
|
this._state = GET_INFO;
|
|
1109
1409
|
}
|
|
1110
1410
|
|
|
@@ -1118,18 +1418,39 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1118
1418
|
controlMessage(data) {
|
|
1119
1419
|
if (this._opcode === 0x08) {
|
|
1120
1420
|
this._loop = false;
|
|
1421
|
+
|
|
1121
1422
|
if (data.length === 0) {
|
|
1122
1423
|
this.emit('conclude', 1005, EMPTY_BUFFER$2);
|
|
1123
1424
|
this.end();
|
|
1124
1425
|
} else {
|
|
1125
1426
|
const code = data.readUInt16BE(0);
|
|
1427
|
+
|
|
1126
1428
|
if (!isValidStatusCode$1(code)) {
|
|
1127
|
-
return error(
|
|
1429
|
+
return error(
|
|
1430
|
+
RangeError,
|
|
1431
|
+
`invalid status code ${code}`,
|
|
1432
|
+
true,
|
|
1433
|
+
1002,
|
|
1434
|
+
'WS_ERR_INVALID_CLOSE_CODE'
|
|
1435
|
+
);
|
|
1128
1436
|
}
|
|
1129
|
-
|
|
1437
|
+
|
|
1438
|
+
const buf = new FastBuffer(
|
|
1439
|
+
data.buffer,
|
|
1440
|
+
data.byteOffset + 2,
|
|
1441
|
+
data.length - 2
|
|
1442
|
+
);
|
|
1443
|
+
|
|
1130
1444
|
if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
|
|
1131
|
-
return error(
|
|
1445
|
+
return error(
|
|
1446
|
+
Error,
|
|
1447
|
+
'invalid UTF-8 sequence',
|
|
1448
|
+
true,
|
|
1449
|
+
1007,
|
|
1450
|
+
'WS_ERR_INVALID_UTF8'
|
|
1451
|
+
);
|
|
1132
1452
|
}
|
|
1453
|
+
|
|
1133
1454
|
this.emit('conclude', code, buf);
|
|
1134
1455
|
this.end();
|
|
1135
1456
|
}
|
|
@@ -1138,9 +1459,11 @@ let Receiver$1 = class Receiver extends Writable {
|
|
|
1138
1459
|
} else {
|
|
1139
1460
|
this.emit('pong', data);
|
|
1140
1461
|
}
|
|
1462
|
+
|
|
1141
1463
|
this._state = GET_INFO;
|
|
1142
1464
|
}
|
|
1143
1465
|
};
|
|
1466
|
+
|
|
1144
1467
|
var receiver = Receiver$1;
|
|
1145
1468
|
|
|
1146
1469
|
/**
|
|
@@ -1156,7 +1479,10 @@ var receiver = Receiver$1;
|
|
|
1156
1479
|
* @private
|
|
1157
1480
|
*/
|
|
1158
1481
|
function error(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
1159
|
-
const err = new ErrorCtor(
|
|
1482
|
+
const err = new ErrorCtor(
|
|
1483
|
+
prefix ? `Invalid WebSocket frame: ${message}` : message
|
|
1484
|
+
);
|
|
1485
|
+
|
|
1160
1486
|
Error.captureStackTrace(err, error);
|
|
1161
1487
|
err.code = errorCode;
|
|
1162
1488
|
err[kStatusCode$1] = statusCode;
|
|
@@ -1164,20 +1490,13 @@ function error(ErrorCtor, message, prefix, statusCode, errorCode) {
|
|
|
1164
1490
|
}
|
|
1165
1491
|
|
|
1166
1492
|
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls$" }] */
|
|
1167
|
-
const {
|
|
1168
|
-
|
|
1169
|
-
} = require$$5;
|
|
1493
|
+
const { randomFillSync } = require$$5;
|
|
1494
|
+
|
|
1170
1495
|
const PerMessageDeflate$2 = permessageDeflate;
|
|
1171
|
-
const {
|
|
1172
|
-
|
|
1173
|
-
} =
|
|
1174
|
-
|
|
1175
|
-
isValidStatusCode
|
|
1176
|
-
} = validationExports;
|
|
1177
|
-
const {
|
|
1178
|
-
mask: applyMask,
|
|
1179
|
-
toBuffer: toBuffer$1
|
|
1180
|
-
} = bufferUtilExports;
|
|
1496
|
+
const { EMPTY_BUFFER: EMPTY_BUFFER$1 } = constants;
|
|
1497
|
+
const { isValidStatusCode } = validationExports;
|
|
1498
|
+
const { mask: applyMask, toBuffer: toBuffer$1 } = bufferUtilExports;
|
|
1499
|
+
|
|
1181
1500
|
const kByteLength = Symbol('kByteLength');
|
|
1182
1501
|
const maskBuffer = Buffer.alloc(4);
|
|
1183
1502
|
|
|
@@ -1195,13 +1514,17 @@ let Sender$1 = class Sender {
|
|
|
1195
1514
|
*/
|
|
1196
1515
|
constructor(socket, extensions, generateMask) {
|
|
1197
1516
|
this._extensions = extensions || {};
|
|
1517
|
+
|
|
1198
1518
|
if (generateMask) {
|
|
1199
1519
|
this._generateMask = generateMask;
|
|
1200
1520
|
this._maskBuffer = Buffer.alloc(4);
|
|
1201
1521
|
}
|
|
1522
|
+
|
|
1202
1523
|
this._socket = socket;
|
|
1524
|
+
|
|
1203
1525
|
this._firstFragment = true;
|
|
1204
1526
|
this._compress = false;
|
|
1527
|
+
|
|
1205
1528
|
this._bufferedBytes = 0;
|
|
1206
1529
|
this._deflating = false;
|
|
1207
1530
|
this._queue = [];
|
|
@@ -1233,19 +1556,27 @@ let Sender$1 = class Sender {
|
|
|
1233
1556
|
let merge = false;
|
|
1234
1557
|
let offset = 2;
|
|
1235
1558
|
let skipMasking = false;
|
|
1559
|
+
|
|
1236
1560
|
if (options.mask) {
|
|
1237
1561
|
mask = options.maskBuffer || maskBuffer;
|
|
1562
|
+
|
|
1238
1563
|
if (options.generateMask) {
|
|
1239
1564
|
options.generateMask(mask);
|
|
1240
1565
|
} else {
|
|
1241
1566
|
randomFillSync(mask, 0, 4);
|
|
1242
1567
|
}
|
|
1568
|
+
|
|
1243
1569
|
skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
|
|
1244
1570
|
offset = 6;
|
|
1245
1571
|
}
|
|
1572
|
+
|
|
1246
1573
|
let dataLength;
|
|
1574
|
+
|
|
1247
1575
|
if (typeof data === 'string') {
|
|
1248
|
-
if (
|
|
1576
|
+
if (
|
|
1577
|
+
(!options.mask || skipMasking) &&
|
|
1578
|
+
options[kByteLength] !== undefined
|
|
1579
|
+
) {
|
|
1249
1580
|
dataLength = options[kByteLength];
|
|
1250
1581
|
} else {
|
|
1251
1582
|
data = Buffer.from(data);
|
|
@@ -1255,7 +1586,9 @@ let Sender$1 = class Sender {
|
|
|
1255
1586
|
dataLength = data.length;
|
|
1256
1587
|
merge = options.mask && options.readOnly && !skipMasking;
|
|
1257
1588
|
}
|
|
1589
|
+
|
|
1258
1590
|
let payloadLength = dataLength;
|
|
1591
|
+
|
|
1259
1592
|
if (dataLength >= 65536) {
|
|
1260
1593
|
offset += 8;
|
|
1261
1594
|
payloadLength = 127;
|
|
@@ -1263,27 +1596,36 @@ let Sender$1 = class Sender {
|
|
|
1263
1596
|
offset += 2;
|
|
1264
1597
|
payloadLength = 126;
|
|
1265
1598
|
}
|
|
1599
|
+
|
|
1266
1600
|
const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
|
|
1601
|
+
|
|
1267
1602
|
target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
|
|
1268
1603
|
if (options.rsv1) target[0] |= 0x40;
|
|
1604
|
+
|
|
1269
1605
|
target[1] = payloadLength;
|
|
1606
|
+
|
|
1270
1607
|
if (payloadLength === 126) {
|
|
1271
1608
|
target.writeUInt16BE(dataLength, 2);
|
|
1272
1609
|
} else if (payloadLength === 127) {
|
|
1273
1610
|
target[2] = target[3] = 0;
|
|
1274
1611
|
target.writeUIntBE(dataLength, 4, 6);
|
|
1275
1612
|
}
|
|
1613
|
+
|
|
1276
1614
|
if (!options.mask) return [target, data];
|
|
1615
|
+
|
|
1277
1616
|
target[1] |= 0x80;
|
|
1278
1617
|
target[offset - 4] = mask[0];
|
|
1279
1618
|
target[offset - 3] = mask[1];
|
|
1280
1619
|
target[offset - 2] = mask[2];
|
|
1281
1620
|
target[offset - 1] = mask[3];
|
|
1621
|
+
|
|
1282
1622
|
if (skipMasking) return [target, data];
|
|
1623
|
+
|
|
1283
1624
|
if (merge) {
|
|
1284
1625
|
applyMask(data, mask, target, offset, dataLength);
|
|
1285
1626
|
return [target];
|
|
1286
1627
|
}
|
|
1628
|
+
|
|
1287
1629
|
applyMask(data, mask, data, 0, dataLength);
|
|
1288
1630
|
return [target, data];
|
|
1289
1631
|
}
|
|
@@ -1299,6 +1641,7 @@ let Sender$1 = class Sender {
|
|
|
1299
1641
|
*/
|
|
1300
1642
|
close(code, data, mask, cb) {
|
|
1301
1643
|
let buf;
|
|
1644
|
+
|
|
1302
1645
|
if (code === undefined) {
|
|
1303
1646
|
buf = EMPTY_BUFFER$1;
|
|
1304
1647
|
} else if (typeof code !== 'number' || !isValidStatusCode(code)) {
|
|
@@ -1308,17 +1651,21 @@ let Sender$1 = class Sender {
|
|
|
1308
1651
|
buf.writeUInt16BE(code, 0);
|
|
1309
1652
|
} else {
|
|
1310
1653
|
const length = Buffer.byteLength(data);
|
|
1654
|
+
|
|
1311
1655
|
if (length > 123) {
|
|
1312
1656
|
throw new RangeError('The message must not be greater than 123 bytes');
|
|
1313
1657
|
}
|
|
1658
|
+
|
|
1314
1659
|
buf = Buffer.allocUnsafe(2 + length);
|
|
1315
1660
|
buf.writeUInt16BE(code, 0);
|
|
1661
|
+
|
|
1316
1662
|
if (typeof data === 'string') {
|
|
1317
1663
|
buf.write(data, 2);
|
|
1318
1664
|
} else {
|
|
1319
1665
|
buf.set(data, 2);
|
|
1320
1666
|
}
|
|
1321
1667
|
}
|
|
1668
|
+
|
|
1322
1669
|
const options = {
|
|
1323
1670
|
[kByteLength]: buf.length,
|
|
1324
1671
|
fin: true,
|
|
@@ -1329,6 +1676,7 @@ let Sender$1 = class Sender {
|
|
|
1329
1676
|
readOnly: false,
|
|
1330
1677
|
rsv1: false
|
|
1331
1678
|
};
|
|
1679
|
+
|
|
1332
1680
|
if (this._deflating) {
|
|
1333
1681
|
this.enqueue([this.dispatch, buf, false, options, cb]);
|
|
1334
1682
|
} else {
|
|
@@ -1347,6 +1695,7 @@ let Sender$1 = class Sender {
|
|
|
1347
1695
|
ping(data, mask, cb) {
|
|
1348
1696
|
let byteLength;
|
|
1349
1697
|
let readOnly;
|
|
1698
|
+
|
|
1350
1699
|
if (typeof data === 'string') {
|
|
1351
1700
|
byteLength = Buffer.byteLength(data);
|
|
1352
1701
|
readOnly = false;
|
|
@@ -1355,9 +1704,11 @@ let Sender$1 = class Sender {
|
|
|
1355
1704
|
byteLength = data.length;
|
|
1356
1705
|
readOnly = toBuffer$1.readOnly;
|
|
1357
1706
|
}
|
|
1707
|
+
|
|
1358
1708
|
if (byteLength > 125) {
|
|
1359
1709
|
throw new RangeError('The data size must not be greater than 125 bytes');
|
|
1360
1710
|
}
|
|
1711
|
+
|
|
1361
1712
|
const options = {
|
|
1362
1713
|
[kByteLength]: byteLength,
|
|
1363
1714
|
fin: true,
|
|
@@ -1368,6 +1719,7 @@ let Sender$1 = class Sender {
|
|
|
1368
1719
|
readOnly,
|
|
1369
1720
|
rsv1: false
|
|
1370
1721
|
};
|
|
1722
|
+
|
|
1371
1723
|
if (this._deflating) {
|
|
1372
1724
|
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1373
1725
|
} else {
|
|
@@ -1386,6 +1738,7 @@ let Sender$1 = class Sender {
|
|
|
1386
1738
|
pong(data, mask, cb) {
|
|
1387
1739
|
let byteLength;
|
|
1388
1740
|
let readOnly;
|
|
1741
|
+
|
|
1389
1742
|
if (typeof data === 'string') {
|
|
1390
1743
|
byteLength = Buffer.byteLength(data);
|
|
1391
1744
|
readOnly = false;
|
|
@@ -1394,9 +1747,11 @@ let Sender$1 = class Sender {
|
|
|
1394
1747
|
byteLength = data.length;
|
|
1395
1748
|
readOnly = toBuffer$1.readOnly;
|
|
1396
1749
|
}
|
|
1750
|
+
|
|
1397
1751
|
if (byteLength > 125) {
|
|
1398
1752
|
throw new RangeError('The data size must not be greater than 125 bytes');
|
|
1399
1753
|
}
|
|
1754
|
+
|
|
1400
1755
|
const options = {
|
|
1401
1756
|
[kByteLength]: byteLength,
|
|
1402
1757
|
fin: true,
|
|
@@ -1407,6 +1762,7 @@ let Sender$1 = class Sender {
|
|
|
1407
1762
|
readOnly,
|
|
1408
1763
|
rsv1: false
|
|
1409
1764
|
};
|
|
1765
|
+
|
|
1410
1766
|
if (this._deflating) {
|
|
1411
1767
|
this.enqueue([this.dispatch, data, false, options, cb]);
|
|
1412
1768
|
} else {
|
|
@@ -1434,8 +1790,10 @@ let Sender$1 = class Sender {
|
|
|
1434
1790
|
const perMessageDeflate = this._extensions[PerMessageDeflate$2.extensionName];
|
|
1435
1791
|
let opcode = options.binary ? 2 : 1;
|
|
1436
1792
|
let rsv1 = options.compress;
|
|
1793
|
+
|
|
1437
1794
|
let byteLength;
|
|
1438
1795
|
let readOnly;
|
|
1796
|
+
|
|
1439
1797
|
if (typeof data === 'string') {
|
|
1440
1798
|
byteLength = Buffer.byteLength(data);
|
|
1441
1799
|
readOnly = false;
|
|
@@ -1444,9 +1802,18 @@ let Sender$1 = class Sender {
|
|
|
1444
1802
|
byteLength = data.length;
|
|
1445
1803
|
readOnly = toBuffer$1.readOnly;
|
|
1446
1804
|
}
|
|
1805
|
+
|
|
1447
1806
|
if (this._firstFragment) {
|
|
1448
1807
|
this._firstFragment = false;
|
|
1449
|
-
if (
|
|
1808
|
+
if (
|
|
1809
|
+
rsv1 &&
|
|
1810
|
+
perMessageDeflate &&
|
|
1811
|
+
perMessageDeflate.params[
|
|
1812
|
+
perMessageDeflate._isServer
|
|
1813
|
+
? 'server_no_context_takeover'
|
|
1814
|
+
: 'client_no_context_takeover'
|
|
1815
|
+
]
|
|
1816
|
+
) {
|
|
1450
1817
|
rsv1 = byteLength >= perMessageDeflate._threshold;
|
|
1451
1818
|
}
|
|
1452
1819
|
this._compress = rsv1;
|
|
@@ -1454,7 +1821,9 @@ let Sender$1 = class Sender {
|
|
|
1454
1821
|
rsv1 = false;
|
|
1455
1822
|
opcode = 0;
|
|
1456
1823
|
}
|
|
1824
|
+
|
|
1457
1825
|
if (options.fin) this._firstFragment = true;
|
|
1826
|
+
|
|
1458
1827
|
if (perMessageDeflate) {
|
|
1459
1828
|
const opts = {
|
|
1460
1829
|
[kByteLength]: byteLength,
|
|
@@ -1466,22 +1835,26 @@ let Sender$1 = class Sender {
|
|
|
1466
1835
|
readOnly,
|
|
1467
1836
|
rsv1
|
|
1468
1837
|
};
|
|
1838
|
+
|
|
1469
1839
|
if (this._deflating) {
|
|
1470
1840
|
this.enqueue([this.dispatch, data, this._compress, opts, cb]);
|
|
1471
1841
|
} else {
|
|
1472
1842
|
this.dispatch(data, this._compress, opts, cb);
|
|
1473
1843
|
}
|
|
1474
1844
|
} else {
|
|
1475
|
-
this.sendFrame(
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1845
|
+
this.sendFrame(
|
|
1846
|
+
Sender.frame(data, {
|
|
1847
|
+
[kByteLength]: byteLength,
|
|
1848
|
+
fin: options.fin,
|
|
1849
|
+
generateMask: this._generateMask,
|
|
1850
|
+
mask: options.mask,
|
|
1851
|
+
maskBuffer: this._maskBuffer,
|
|
1852
|
+
opcode,
|
|
1853
|
+
readOnly,
|
|
1854
|
+
rsv1: false
|
|
1855
|
+
}),
|
|
1856
|
+
cb
|
|
1857
|
+
);
|
|
1485
1858
|
}
|
|
1486
1859
|
}
|
|
1487
1860
|
|
|
@@ -1513,20 +1886,29 @@ let Sender$1 = class Sender {
|
|
|
1513
1886
|
this.sendFrame(Sender.frame(data, options), cb);
|
|
1514
1887
|
return;
|
|
1515
1888
|
}
|
|
1889
|
+
|
|
1516
1890
|
const perMessageDeflate = this._extensions[PerMessageDeflate$2.extensionName];
|
|
1891
|
+
|
|
1517
1892
|
this._bufferedBytes += options[kByteLength];
|
|
1518
1893
|
this._deflating = true;
|
|
1519
1894
|
perMessageDeflate.compress(data, options.fin, (_, buf) => {
|
|
1520
1895
|
if (this._socket.destroyed) {
|
|
1521
|
-
const err = new Error(
|
|
1896
|
+
const err = new Error(
|
|
1897
|
+
'The socket was closed while data was being compressed'
|
|
1898
|
+
);
|
|
1899
|
+
|
|
1522
1900
|
if (typeof cb === 'function') cb(err);
|
|
1901
|
+
|
|
1523
1902
|
for (let i = 0; i < this._queue.length; i++) {
|
|
1524
1903
|
const params = this._queue[i];
|
|
1525
1904
|
const callback = params[params.length - 1];
|
|
1905
|
+
|
|
1526
1906
|
if (typeof callback === 'function') callback(err);
|
|
1527
1907
|
}
|
|
1908
|
+
|
|
1528
1909
|
return;
|
|
1529
1910
|
}
|
|
1911
|
+
|
|
1530
1912
|
this._bufferedBytes -= options[kByteLength];
|
|
1531
1913
|
this._deflating = false;
|
|
1532
1914
|
options.readOnly = false;
|
|
@@ -1543,6 +1925,7 @@ let Sender$1 = class Sender {
|
|
|
1543
1925
|
dequeue() {
|
|
1544
1926
|
while (!this._deflating && this._queue.length) {
|
|
1545
1927
|
const params = this._queue.shift();
|
|
1928
|
+
|
|
1546
1929
|
this._bufferedBytes -= params[3][kByteLength];
|
|
1547
1930
|
Reflect.apply(params[0], this, params.slice(1));
|
|
1548
1931
|
}
|
|
@@ -1577,11 +1960,11 @@ let Sender$1 = class Sender {
|
|
|
1577
1960
|
}
|
|
1578
1961
|
}
|
|
1579
1962
|
};
|
|
1963
|
+
|
|
1580
1964
|
var sender = Sender$1;
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
} = constants;
|
|
1965
|
+
|
|
1966
|
+
const { kForOnEventAttribute: kForOnEventAttribute$1, kListener: kListener$1 } = constants;
|
|
1967
|
+
|
|
1585
1968
|
const kCode = Symbol('kCode');
|
|
1586
1969
|
const kData = Symbol('kData');
|
|
1587
1970
|
const kError = Symbol('kError');
|
|
@@ -1620,12 +2003,9 @@ class Event {
|
|
|
1620
2003
|
return this[kType];
|
|
1621
2004
|
}
|
|
1622
2005
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
});
|
|
1626
|
-
Object.defineProperty(Event.prototype, 'type', {
|
|
1627
|
-
enumerable: true
|
|
1628
|
-
});
|
|
2006
|
+
|
|
2007
|
+
Object.defineProperty(Event.prototype, 'target', { enumerable: true });
|
|
2008
|
+
Object.defineProperty(Event.prototype, 'type', { enumerable: true });
|
|
1629
2009
|
|
|
1630
2010
|
/**
|
|
1631
2011
|
* Class representing a close event.
|
|
@@ -1648,6 +2028,7 @@ class CloseEvent extends Event {
|
|
|
1648
2028
|
*/
|
|
1649
2029
|
constructor(type, options = {}) {
|
|
1650
2030
|
super(type);
|
|
2031
|
+
|
|
1651
2032
|
this[kCode] = options.code === undefined ? 0 : options.code;
|
|
1652
2033
|
this[kReason] = options.reason === undefined ? '' : options.reason;
|
|
1653
2034
|
this[kWasClean] = options.wasClean === undefined ? false : options.wasClean;
|
|
@@ -1674,15 +2055,10 @@ class CloseEvent extends Event {
|
|
|
1674
2055
|
return this[kWasClean];
|
|
1675
2056
|
}
|
|
1676
2057
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
});
|
|
1680
|
-
Object.defineProperty(CloseEvent.prototype, '
|
|
1681
|
-
enumerable: true
|
|
1682
|
-
});
|
|
1683
|
-
Object.defineProperty(CloseEvent.prototype, 'wasClean', {
|
|
1684
|
-
enumerable: true
|
|
1685
|
-
});
|
|
2058
|
+
|
|
2059
|
+
Object.defineProperty(CloseEvent.prototype, 'code', { enumerable: true });
|
|
2060
|
+
Object.defineProperty(CloseEvent.prototype, 'reason', { enumerable: true });
|
|
2061
|
+
Object.defineProperty(CloseEvent.prototype, 'wasClean', { enumerable: true });
|
|
1686
2062
|
|
|
1687
2063
|
/**
|
|
1688
2064
|
* Class representing an error event.
|
|
@@ -1701,6 +2077,7 @@ class ErrorEvent extends Event {
|
|
|
1701
2077
|
*/
|
|
1702
2078
|
constructor(type, options = {}) {
|
|
1703
2079
|
super(type);
|
|
2080
|
+
|
|
1704
2081
|
this[kError] = options.error === undefined ? null : options.error;
|
|
1705
2082
|
this[kMessage] = options.message === undefined ? '' : options.message;
|
|
1706
2083
|
}
|
|
@@ -1719,12 +2096,9 @@ class ErrorEvent extends Event {
|
|
|
1719
2096
|
return this[kMessage];
|
|
1720
2097
|
}
|
|
1721
2098
|
}
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
});
|
|
1725
|
-
Object.defineProperty(ErrorEvent.prototype, 'message', {
|
|
1726
|
-
enumerable: true
|
|
1727
|
-
});
|
|
2099
|
+
|
|
2100
|
+
Object.defineProperty(ErrorEvent.prototype, 'error', { enumerable: true });
|
|
2101
|
+
Object.defineProperty(ErrorEvent.prototype, 'message', { enumerable: true });
|
|
1728
2102
|
|
|
1729
2103
|
/**
|
|
1730
2104
|
* Class representing a message event.
|
|
@@ -1742,6 +2116,7 @@ class MessageEvent extends Event {
|
|
|
1742
2116
|
*/
|
|
1743
2117
|
constructor(type, options = {}) {
|
|
1744
2118
|
super(type);
|
|
2119
|
+
|
|
1745
2120
|
this[kData] = options.data === undefined ? null : options.data;
|
|
1746
2121
|
}
|
|
1747
2122
|
|
|
@@ -1752,9 +2127,8 @@ class MessageEvent extends Event {
|
|
|
1752
2127
|
return this[kData];
|
|
1753
2128
|
}
|
|
1754
2129
|
}
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
});
|
|
2130
|
+
|
|
2131
|
+
Object.defineProperty(MessageEvent.prototype, 'data', { enumerable: true });
|
|
1758
2132
|
|
|
1759
2133
|
/**
|
|
1760
2134
|
* This provides methods for emulating the `EventTarget` interface. It's not
|
|
@@ -1777,16 +2151,23 @@ const EventTarget = {
|
|
|
1777
2151
|
*/
|
|
1778
2152
|
addEventListener(type, handler, options = {}) {
|
|
1779
2153
|
for (const listener of this.listeners(type)) {
|
|
1780
|
-
if (
|
|
2154
|
+
if (
|
|
2155
|
+
!options[kForOnEventAttribute$1] &&
|
|
2156
|
+
listener[kListener$1] === handler &&
|
|
2157
|
+
!listener[kForOnEventAttribute$1]
|
|
2158
|
+
) {
|
|
1781
2159
|
return;
|
|
1782
2160
|
}
|
|
1783
2161
|
}
|
|
2162
|
+
|
|
1784
2163
|
let wrapper;
|
|
2164
|
+
|
|
1785
2165
|
if (type === 'message') {
|
|
1786
2166
|
wrapper = function onMessage(data, isBinary) {
|
|
1787
2167
|
const event = new MessageEvent('message', {
|
|
1788
2168
|
data: isBinary ? data : data.toString()
|
|
1789
2169
|
});
|
|
2170
|
+
|
|
1790
2171
|
event[kTarget] = this;
|
|
1791
2172
|
callListener(handler, this, event);
|
|
1792
2173
|
};
|
|
@@ -1797,6 +2178,7 @@ const EventTarget = {
|
|
|
1797
2178
|
reason: message.toString(),
|
|
1798
2179
|
wasClean: this._closeFrameReceived && this._closeFrameSent
|
|
1799
2180
|
});
|
|
2181
|
+
|
|
1800
2182
|
event[kTarget] = this;
|
|
1801
2183
|
callListener(handler, this, event);
|
|
1802
2184
|
};
|
|
@@ -1806,26 +2188,31 @@ const EventTarget = {
|
|
|
1806
2188
|
error,
|
|
1807
2189
|
message: error.message
|
|
1808
2190
|
});
|
|
2191
|
+
|
|
1809
2192
|
event[kTarget] = this;
|
|
1810
2193
|
callListener(handler, this, event);
|
|
1811
2194
|
};
|
|
1812
2195
|
} else if (type === 'open') {
|
|
1813
2196
|
wrapper = function onOpen() {
|
|
1814
2197
|
const event = new Event('open');
|
|
2198
|
+
|
|
1815
2199
|
event[kTarget] = this;
|
|
1816
2200
|
callListener(handler, this, event);
|
|
1817
2201
|
};
|
|
1818
2202
|
} else {
|
|
1819
2203
|
return;
|
|
1820
2204
|
}
|
|
2205
|
+
|
|
1821
2206
|
wrapper[kForOnEventAttribute$1] = !!options[kForOnEventAttribute$1];
|
|
1822
2207
|
wrapper[kListener$1] = handler;
|
|
2208
|
+
|
|
1823
2209
|
if (options.once) {
|
|
1824
2210
|
this.once(type, wrapper);
|
|
1825
2211
|
} else {
|
|
1826
2212
|
this.on(type, wrapper);
|
|
1827
2213
|
}
|
|
1828
2214
|
},
|
|
2215
|
+
|
|
1829
2216
|
/**
|
|
1830
2217
|
* Remove an event listener.
|
|
1831
2218
|
*
|
|
@@ -1842,6 +2229,7 @@ const EventTarget = {
|
|
|
1842
2229
|
}
|
|
1843
2230
|
}
|
|
1844
2231
|
};
|
|
2232
|
+
|
|
1845
2233
|
var eventTarget = {
|
|
1846
2234
|
CloseEvent,
|
|
1847
2235
|
ErrorEvent,
|
|
@@ -1865,9 +2253,8 @@ function callListener(listener, thisArg, event) {
|
|
|
1865
2253
|
listener.call(thisArg, event);
|
|
1866
2254
|
}
|
|
1867
2255
|
}
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
} = validationExports;
|
|
2256
|
+
|
|
2257
|
+
const { tokenChars: tokenChars$1 } = validationExports;
|
|
1871
2258
|
|
|
1872
2259
|
/**
|
|
1873
2260
|
* Adds an offer to the map of extension offers or a parameter to the map of
|
|
@@ -1880,7 +2267,8 @@ const {
|
|
|
1880
2267
|
* @private
|
|
1881
2268
|
*/
|
|
1882
2269
|
function push(dest, name, elem) {
|
|
1883
|
-
if (dest[name] === undefined) dest[name] = [elem];
|
|
2270
|
+
if (dest[name] === undefined) dest[name] = [elem];
|
|
2271
|
+
else dest[name].push(elem);
|
|
1884
2272
|
}
|
|
1885
2273
|
|
|
1886
2274
|
/**
|
|
@@ -1902,17 +2290,23 @@ function parse$2(header) {
|
|
|
1902
2290
|
let code = -1;
|
|
1903
2291
|
let end = -1;
|
|
1904
2292
|
let i = 0;
|
|
2293
|
+
|
|
1905
2294
|
for (; i < header.length; i++) {
|
|
1906
2295
|
code = header.charCodeAt(i);
|
|
2296
|
+
|
|
1907
2297
|
if (extensionName === undefined) {
|
|
1908
2298
|
if (end === -1 && tokenChars$1[code] === 1) {
|
|
1909
2299
|
if (start === -1) start = i;
|
|
1910
|
-
} else if (
|
|
2300
|
+
} else if (
|
|
2301
|
+
i !== 0 &&
|
|
2302
|
+
(code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
|
|
2303
|
+
) {
|
|
1911
2304
|
if (end === -1 && start !== -1) end = i;
|
|
1912
2305
|
} else if (code === 0x3b /* ';' */ || code === 0x2c /* ',' */) {
|
|
1913
2306
|
if (start === -1) {
|
|
1914
2307
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1915
2308
|
}
|
|
2309
|
+
|
|
1916
2310
|
if (end === -1) end = i;
|
|
1917
2311
|
const name = header.slice(start, end);
|
|
1918
2312
|
if (code === 0x2c) {
|
|
@@ -1921,6 +2315,7 @@ function parse$2(header) {
|
|
|
1921
2315
|
} else {
|
|
1922
2316
|
extensionName = name;
|
|
1923
2317
|
}
|
|
2318
|
+
|
|
1924
2319
|
start = end = -1;
|
|
1925
2320
|
} else {
|
|
1926
2321
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
@@ -1934,6 +2329,7 @@ function parse$2(header) {
|
|
|
1934
2329
|
if (start === -1) {
|
|
1935
2330
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1936
2331
|
}
|
|
2332
|
+
|
|
1937
2333
|
if (end === -1) end = i;
|
|
1938
2334
|
push(params, header.slice(start, end), true);
|
|
1939
2335
|
if (code === 0x2c) {
|
|
@@ -1941,6 +2337,7 @@ function parse$2(header) {
|
|
|
1941
2337
|
params = Object.create(null);
|
|
1942
2338
|
extensionName = undefined;
|
|
1943
2339
|
}
|
|
2340
|
+
|
|
1944
2341
|
start = end = -1;
|
|
1945
2342
|
} else if (code === 0x3d /* '=' */ && start !== -1 && end === -1) {
|
|
1946
2343
|
paramName = header.slice(start, i);
|
|
@@ -1958,7 +2355,8 @@ function parse$2(header) {
|
|
|
1958
2355
|
if (tokenChars$1[code] !== 1) {
|
|
1959
2356
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1960
2357
|
}
|
|
1961
|
-
if (start === -1) start = i;
|
|
2358
|
+
if (start === -1) start = i;
|
|
2359
|
+
else if (!mustUnescape) mustUnescape = true;
|
|
1962
2360
|
isEscaping = false;
|
|
1963
2361
|
} else if (inQuotes) {
|
|
1964
2362
|
if (tokenChars$1[code] === 1) {
|
|
@@ -1981,6 +2379,7 @@ function parse$2(header) {
|
|
|
1981
2379
|
if (start === -1) {
|
|
1982
2380
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
1983
2381
|
}
|
|
2382
|
+
|
|
1984
2383
|
if (end === -1) end = i;
|
|
1985
2384
|
let value = header.slice(start, end);
|
|
1986
2385
|
if (mustUnescape) {
|
|
@@ -1993,6 +2392,7 @@ function parse$2(header) {
|
|
|
1993
2392
|
params = Object.create(null);
|
|
1994
2393
|
extensionName = undefined;
|
|
1995
2394
|
}
|
|
2395
|
+
|
|
1996
2396
|
paramName = undefined;
|
|
1997
2397
|
start = end = -1;
|
|
1998
2398
|
} else {
|
|
@@ -2000,9 +2400,11 @@ function parse$2(header) {
|
|
|
2000
2400
|
}
|
|
2001
2401
|
}
|
|
2002
2402
|
}
|
|
2403
|
+
|
|
2003
2404
|
if (start === -1 || inQuotes || code === 0x20 || code === 0x09) {
|
|
2004
2405
|
throw new SyntaxError('Unexpected end of input');
|
|
2005
2406
|
}
|
|
2407
|
+
|
|
2006
2408
|
if (end === -1) end = i;
|
|
2007
2409
|
const token = header.slice(start, end);
|
|
2008
2410
|
if (extensionName === undefined) {
|
|
@@ -2017,6 +2419,7 @@ function parse$2(header) {
|
|
|
2017
2419
|
}
|
|
2018
2420
|
push(offers, extensionName, params);
|
|
2019
2421
|
}
|
|
2422
|
+
|
|
2020
2423
|
return offers;
|
|
2021
2424
|
}
|
|
2022
2425
|
|
|
@@ -2028,22 +2431,30 @@ function parse$2(header) {
|
|
|
2028
2431
|
* @public
|
|
2029
2432
|
*/
|
|
2030
2433
|
function format$1(extensions) {
|
|
2031
|
-
return Object.keys(extensions)
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
return
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2434
|
+
return Object.keys(extensions)
|
|
2435
|
+
.map((extension) => {
|
|
2436
|
+
let configurations = extensions[extension];
|
|
2437
|
+
if (!Array.isArray(configurations)) configurations = [configurations];
|
|
2438
|
+
return configurations
|
|
2439
|
+
.map((params) => {
|
|
2440
|
+
return [extension]
|
|
2441
|
+
.concat(
|
|
2442
|
+
Object.keys(params).map((k) => {
|
|
2443
|
+
let values = params[k];
|
|
2444
|
+
if (!Array.isArray(values)) values = [values];
|
|
2445
|
+
return values
|
|
2446
|
+
.map((v) => (v === true ? k : `${k}=${v}`))
|
|
2447
|
+
.join('; ');
|
|
2448
|
+
})
|
|
2449
|
+
)
|
|
2450
|
+
.join('; ');
|
|
2451
|
+
})
|
|
2452
|
+
.join(', ');
|
|
2453
|
+
})
|
|
2454
|
+
.join(', ');
|
|
2042
2455
|
}
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
parse: parse$2
|
|
2046
|
-
};
|
|
2456
|
+
|
|
2457
|
+
var extension$1 = { format: format$1, parse: parse$2 };
|
|
2047
2458
|
|
|
2048
2459
|
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Readable$" }] */
|
|
2049
2460
|
|
|
@@ -2052,13 +2463,9 @@ const https = require$$1;
|
|
|
2052
2463
|
const http$1 = require$$2;
|
|
2053
2464
|
const net = require$$3;
|
|
2054
2465
|
const tls = require$$4;
|
|
2055
|
-
const {
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
} = require$$5;
|
|
2059
|
-
const {
|
|
2060
|
-
URL
|
|
2061
|
-
} = require$$7;
|
|
2466
|
+
const { randomBytes, createHash: createHash$1 } = require$$5;
|
|
2467
|
+
const { URL } = require$$7;
|
|
2468
|
+
|
|
2062
2469
|
const PerMessageDeflate$1 = permessageDeflate;
|
|
2063
2470
|
const Receiver = receiver;
|
|
2064
2471
|
const Sender = sender;
|
|
@@ -2073,18 +2480,11 @@ const {
|
|
|
2073
2480
|
NOOP
|
|
2074
2481
|
} = constants;
|
|
2075
2482
|
const {
|
|
2076
|
-
EventTarget: {
|
|
2077
|
-
addEventListener,
|
|
2078
|
-
removeEventListener
|
|
2079
|
-
}
|
|
2483
|
+
EventTarget: { addEventListener, removeEventListener }
|
|
2080
2484
|
} = eventTarget;
|
|
2081
|
-
const {
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
} = extension$1;
|
|
2085
|
-
const {
|
|
2086
|
-
toBuffer
|
|
2087
|
-
} = bufferUtilExports;
|
|
2485
|
+
const { format, parse: parse$1 } = extension$1;
|
|
2486
|
+
const { toBuffer } = bufferUtilExports;
|
|
2487
|
+
|
|
2088
2488
|
const closeTimeout = 30 * 1000;
|
|
2089
2489
|
const kAborted = Symbol('kAborted');
|
|
2090
2490
|
const protocolVersions = [8, 13];
|
|
@@ -2106,6 +2506,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2106
2506
|
*/
|
|
2107
2507
|
constructor(address, protocols, options) {
|
|
2108
2508
|
super();
|
|
2509
|
+
|
|
2109
2510
|
this._binaryType = BINARY_TYPES[0];
|
|
2110
2511
|
this._closeCode = 1006;
|
|
2111
2512
|
this._closeFrameReceived = false;
|
|
@@ -2119,10 +2520,12 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2119
2520
|
this._receiver = null;
|
|
2120
2521
|
this._sender = null;
|
|
2121
2522
|
this._socket = null;
|
|
2523
|
+
|
|
2122
2524
|
if (address !== null) {
|
|
2123
2525
|
this._bufferedAmount = 0;
|
|
2124
2526
|
this._isServer = false;
|
|
2125
2527
|
this._redirects = 0;
|
|
2528
|
+
|
|
2126
2529
|
if (protocols === undefined) {
|
|
2127
2530
|
protocols = [];
|
|
2128
2531
|
} else if (!Array.isArray(protocols)) {
|
|
@@ -2133,6 +2536,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2133
2536
|
protocols = [protocols];
|
|
2134
2537
|
}
|
|
2135
2538
|
}
|
|
2539
|
+
|
|
2136
2540
|
initAsClient(this, address, protocols, options);
|
|
2137
2541
|
} else {
|
|
2138
2542
|
this._isServer = true;
|
|
@@ -2149,8 +2553,10 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2149
2553
|
get binaryType() {
|
|
2150
2554
|
return this._binaryType;
|
|
2151
2555
|
}
|
|
2556
|
+
|
|
2152
2557
|
set binaryType(type) {
|
|
2153
2558
|
if (!BINARY_TYPES.includes(type)) return;
|
|
2559
|
+
|
|
2154
2560
|
this._binaryType = type;
|
|
2155
2561
|
|
|
2156
2562
|
//
|
|
@@ -2164,6 +2570,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2164
2570
|
*/
|
|
2165
2571
|
get bufferedAmount() {
|
|
2166
2572
|
if (!this._socket) return this._bufferedAmount;
|
|
2573
|
+
|
|
2167
2574
|
return this._socket._writableState.length + this._sender._bufferedBytes;
|
|
2168
2575
|
}
|
|
2169
2576
|
|
|
@@ -2256,24 +2663,31 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2256
2663
|
maxPayload: options.maxPayload,
|
|
2257
2664
|
skipUTF8Validation: options.skipUTF8Validation
|
|
2258
2665
|
});
|
|
2666
|
+
|
|
2259
2667
|
this._sender = new Sender(socket, this._extensions, options.generateMask);
|
|
2260
2668
|
this._receiver = receiver;
|
|
2261
2669
|
this._socket = socket;
|
|
2670
|
+
|
|
2262
2671
|
receiver[kWebSocket$1] = this;
|
|
2263
2672
|
socket[kWebSocket$1] = this;
|
|
2673
|
+
|
|
2264
2674
|
receiver.on('conclude', receiverOnConclude);
|
|
2265
2675
|
receiver.on('drain', receiverOnDrain);
|
|
2266
2676
|
receiver.on('error', receiverOnError);
|
|
2267
2677
|
receiver.on('message', receiverOnMessage);
|
|
2268
2678
|
receiver.on('ping', receiverOnPing);
|
|
2269
2679
|
receiver.on('pong', receiverOnPong);
|
|
2680
|
+
|
|
2270
2681
|
socket.setTimeout(0);
|
|
2271
2682
|
socket.setNoDelay();
|
|
2683
|
+
|
|
2272
2684
|
if (head.length > 0) socket.unshift(head);
|
|
2685
|
+
|
|
2273
2686
|
socket.on('close', socketOnClose);
|
|
2274
2687
|
socket.on('data', socketOnData);
|
|
2275
2688
|
socket.on('end', socketOnEnd);
|
|
2276
2689
|
socket.on('error', socketOnError$1);
|
|
2690
|
+
|
|
2277
2691
|
this._readyState = WebSocket.OPEN;
|
|
2278
2692
|
this.emit('open');
|
|
2279
2693
|
}
|
|
@@ -2289,9 +2703,11 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2289
2703
|
this.emit('close', this._closeCode, this._closeMessage);
|
|
2290
2704
|
return;
|
|
2291
2705
|
}
|
|
2706
|
+
|
|
2292
2707
|
if (this._extensions[PerMessageDeflate$1.extensionName]) {
|
|
2293
2708
|
this._extensions[PerMessageDeflate$1.extensionName].cleanup();
|
|
2294
2709
|
}
|
|
2710
|
+
|
|
2295
2711
|
this._receiver.removeAllListeners();
|
|
2296
2712
|
this._readyState = WebSocket.CLOSED;
|
|
2297
2713
|
this.emit('close', this._closeCode, this._closeMessage);
|
|
@@ -2324,21 +2740,32 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2324
2740
|
abortHandshake$1(this, this._req, msg);
|
|
2325
2741
|
return;
|
|
2326
2742
|
}
|
|
2743
|
+
|
|
2327
2744
|
if (this.readyState === WebSocket.CLOSING) {
|
|
2328
|
-
if (
|
|
2745
|
+
if (
|
|
2746
|
+
this._closeFrameSent &&
|
|
2747
|
+
(this._closeFrameReceived || this._receiver._writableState.errorEmitted)
|
|
2748
|
+
) {
|
|
2329
2749
|
this._socket.end();
|
|
2330
2750
|
}
|
|
2751
|
+
|
|
2331
2752
|
return;
|
|
2332
2753
|
}
|
|
2754
|
+
|
|
2333
2755
|
this._readyState = WebSocket.CLOSING;
|
|
2334
|
-
this._sender.close(code, data, !this._isServer, err => {
|
|
2756
|
+
this._sender.close(code, data, !this._isServer, (err) => {
|
|
2335
2757
|
//
|
|
2336
2758
|
// This error is handled by the `'error'` listener on the socket. We only
|
|
2337
2759
|
// want to know if the close frame has been sent here.
|
|
2338
2760
|
//
|
|
2339
2761
|
if (err) return;
|
|
2762
|
+
|
|
2340
2763
|
this._closeFrameSent = true;
|
|
2341
|
-
|
|
2764
|
+
|
|
2765
|
+
if (
|
|
2766
|
+
this._closeFrameReceived ||
|
|
2767
|
+
this._receiver._writableState.errorEmitted
|
|
2768
|
+
) {
|
|
2342
2769
|
this._socket.end();
|
|
2343
2770
|
}
|
|
2344
2771
|
});
|
|
@@ -2346,7 +2773,10 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2346
2773
|
//
|
|
2347
2774
|
// Specify a timeout for the closing handshake to complete.
|
|
2348
2775
|
//
|
|
2349
|
-
this._closeTimer = setTimeout(
|
|
2776
|
+
this._closeTimer = setTimeout(
|
|
2777
|
+
this._socket.destroy.bind(this._socket),
|
|
2778
|
+
closeTimeout
|
|
2779
|
+
);
|
|
2350
2780
|
}
|
|
2351
2781
|
|
|
2352
2782
|
/**
|
|
@@ -2355,9 +2785,13 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2355
2785
|
* @public
|
|
2356
2786
|
*/
|
|
2357
2787
|
pause() {
|
|
2358
|
-
if (
|
|
2788
|
+
if (
|
|
2789
|
+
this.readyState === WebSocket.CONNECTING ||
|
|
2790
|
+
this.readyState === WebSocket.CLOSED
|
|
2791
|
+
) {
|
|
2359
2792
|
return;
|
|
2360
2793
|
}
|
|
2794
|
+
|
|
2361
2795
|
this._paused = true;
|
|
2362
2796
|
this._socket.pause();
|
|
2363
2797
|
}
|
|
@@ -2374,6 +2808,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2374
2808
|
if (this.readyState === WebSocket.CONNECTING) {
|
|
2375
2809
|
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
2376
2810
|
}
|
|
2811
|
+
|
|
2377
2812
|
if (typeof data === 'function') {
|
|
2378
2813
|
cb = data;
|
|
2379
2814
|
data = mask = undefined;
|
|
@@ -2381,11 +2816,14 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2381
2816
|
cb = mask;
|
|
2382
2817
|
mask = undefined;
|
|
2383
2818
|
}
|
|
2819
|
+
|
|
2384
2820
|
if (typeof data === 'number') data = data.toString();
|
|
2821
|
+
|
|
2385
2822
|
if (this.readyState !== WebSocket.OPEN) {
|
|
2386
2823
|
sendAfterClose(this, data, cb);
|
|
2387
2824
|
return;
|
|
2388
2825
|
}
|
|
2826
|
+
|
|
2389
2827
|
if (mask === undefined) mask = !this._isServer;
|
|
2390
2828
|
this._sender.ping(data || EMPTY_BUFFER, mask, cb);
|
|
2391
2829
|
}
|
|
@@ -2402,6 +2840,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2402
2840
|
if (this.readyState === WebSocket.CONNECTING) {
|
|
2403
2841
|
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
2404
2842
|
}
|
|
2843
|
+
|
|
2405
2844
|
if (typeof data === 'function') {
|
|
2406
2845
|
cb = data;
|
|
2407
2846
|
data = mask = undefined;
|
|
@@ -2409,11 +2848,14 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2409
2848
|
cb = mask;
|
|
2410
2849
|
mask = undefined;
|
|
2411
2850
|
}
|
|
2851
|
+
|
|
2412
2852
|
if (typeof data === 'number') data = data.toString();
|
|
2853
|
+
|
|
2413
2854
|
if (this.readyState !== WebSocket.OPEN) {
|
|
2414
2855
|
sendAfterClose(this, data, cb);
|
|
2415
2856
|
return;
|
|
2416
2857
|
}
|
|
2858
|
+
|
|
2417
2859
|
if (mask === undefined) mask = !this._isServer;
|
|
2418
2860
|
this._sender.pong(data || EMPTY_BUFFER, mask, cb);
|
|
2419
2861
|
}
|
|
@@ -2424,9 +2866,13 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2424
2866
|
* @public
|
|
2425
2867
|
*/
|
|
2426
2868
|
resume() {
|
|
2427
|
-
if (
|
|
2869
|
+
if (
|
|
2870
|
+
this.readyState === WebSocket.CONNECTING ||
|
|
2871
|
+
this.readyState === WebSocket.CLOSED
|
|
2872
|
+
) {
|
|
2428
2873
|
return;
|
|
2429
2874
|
}
|
|
2875
|
+
|
|
2430
2876
|
this._paused = false;
|
|
2431
2877
|
if (!this._receiver._writableState.needDrain) this._socket.resume();
|
|
2432
2878
|
}
|
|
@@ -2450,15 +2896,19 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2450
2896
|
if (this.readyState === WebSocket.CONNECTING) {
|
|
2451
2897
|
throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
|
|
2452
2898
|
}
|
|
2899
|
+
|
|
2453
2900
|
if (typeof options === 'function') {
|
|
2454
2901
|
cb = options;
|
|
2455
2902
|
options = {};
|
|
2456
2903
|
}
|
|
2904
|
+
|
|
2457
2905
|
if (typeof data === 'number') data = data.toString();
|
|
2906
|
+
|
|
2458
2907
|
if (this.readyState !== WebSocket.OPEN) {
|
|
2459
2908
|
sendAfterClose(this, data, cb);
|
|
2460
2909
|
return;
|
|
2461
2910
|
}
|
|
2911
|
+
|
|
2462
2912
|
const opts = {
|
|
2463
2913
|
binary: typeof data !== 'string',
|
|
2464
2914
|
mask: !this._isServer,
|
|
@@ -2466,9 +2916,11 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2466
2916
|
fin: true,
|
|
2467
2917
|
...options
|
|
2468
2918
|
};
|
|
2919
|
+
|
|
2469
2920
|
if (!this._extensions[PerMessageDeflate$1.extensionName]) {
|
|
2470
2921
|
opts.compress = false;
|
|
2471
2922
|
}
|
|
2923
|
+
|
|
2472
2924
|
this._sender.send(data || EMPTY_BUFFER, opts, cb);
|
|
2473
2925
|
}
|
|
2474
2926
|
|
|
@@ -2484,6 +2936,7 @@ let WebSocket$1 = class WebSocket extends EventEmitter$1 {
|
|
|
2484
2936
|
abortHandshake$1(this, this._req, msg);
|
|
2485
2937
|
return;
|
|
2486
2938
|
}
|
|
2939
|
+
|
|
2487
2940
|
if (this._socket) {
|
|
2488
2941
|
this._readyState = WebSocket.CLOSING;
|
|
2489
2942
|
this._socket.destroy();
|
|
@@ -2562,23 +3015,31 @@ Object.defineProperty(WebSocket$1.prototype, 'CLOSED', {
|
|
|
2562
3015
|
enumerable: true,
|
|
2563
3016
|
value: readyStates.indexOf('CLOSED')
|
|
2564
3017
|
});
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
3018
|
+
|
|
3019
|
+
[
|
|
3020
|
+
'binaryType',
|
|
3021
|
+
'bufferedAmount',
|
|
3022
|
+
'extensions',
|
|
3023
|
+
'isPaused',
|
|
3024
|
+
'protocol',
|
|
3025
|
+
'readyState',
|
|
3026
|
+
'url'
|
|
3027
|
+
].forEach((property) => {
|
|
3028
|
+
Object.defineProperty(WebSocket$1.prototype, property, { enumerable: true });
|
|
2569
3029
|
});
|
|
2570
3030
|
|
|
2571
3031
|
//
|
|
2572
3032
|
// Add the `onopen`, `onerror`, `onclose`, and `onmessage` attributes.
|
|
2573
3033
|
// See https://html.spec.whatwg.org/multipage/comms.html#the-websocket-interface
|
|
2574
3034
|
//
|
|
2575
|
-
['open', 'error', 'close', 'message'].forEach(method => {
|
|
3035
|
+
['open', 'error', 'close', 'message'].forEach((method) => {
|
|
2576
3036
|
Object.defineProperty(WebSocket$1.prototype, `on${method}`, {
|
|
2577
3037
|
enumerable: true,
|
|
2578
3038
|
get() {
|
|
2579
3039
|
for (const listener of this.listeners(method)) {
|
|
2580
3040
|
if (listener[kForOnEventAttribute]) return listener[kListener];
|
|
2581
3041
|
}
|
|
3042
|
+
|
|
2582
3043
|
return null;
|
|
2583
3044
|
},
|
|
2584
3045
|
set(handler) {
|
|
@@ -2588,15 +3049,19 @@ Object.defineProperty(WebSocket$1.prototype, 'CLOSED', {
|
|
|
2588
3049
|
break;
|
|
2589
3050
|
}
|
|
2590
3051
|
}
|
|
3052
|
+
|
|
2591
3053
|
if (typeof handler !== 'function') return;
|
|
3054
|
+
|
|
2592
3055
|
this.addEventListener(method, handler, {
|
|
2593
3056
|
[kForOnEventAttribute]: true
|
|
2594
3057
|
});
|
|
2595
3058
|
}
|
|
2596
3059
|
});
|
|
2597
3060
|
});
|
|
3061
|
+
|
|
2598
3062
|
WebSocket$1.prototype.addEventListener = addEventListener;
|
|
2599
3063
|
WebSocket$1.prototype.removeEventListener = removeEventListener;
|
|
3064
|
+
|
|
2600
3065
|
var websocket = WebSocket$1;
|
|
2601
3066
|
|
|
2602
3067
|
/**
|
|
@@ -2645,10 +3110,16 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2645
3110
|
path: undefined,
|
|
2646
3111
|
port: undefined
|
|
2647
3112
|
};
|
|
3113
|
+
|
|
2648
3114
|
if (!protocolVersions.includes(opts.protocolVersion)) {
|
|
2649
|
-
throw new RangeError(
|
|
3115
|
+
throw new RangeError(
|
|
3116
|
+
`Unsupported protocol version: ${opts.protocolVersion} ` +
|
|
3117
|
+
`(supported versions: ${protocolVersions.join(', ')})`
|
|
3118
|
+
);
|
|
2650
3119
|
}
|
|
3120
|
+
|
|
2651
3121
|
let parsedUrl;
|
|
3122
|
+
|
|
2652
3123
|
if (address instanceof URL) {
|
|
2653
3124
|
parsedUrl = address;
|
|
2654
3125
|
websocket._url = address.href;
|
|
@@ -2658,20 +3129,26 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2658
3129
|
} catch (e) {
|
|
2659
3130
|
throw new SyntaxError(`Invalid URL: ${address}`);
|
|
2660
3131
|
}
|
|
3132
|
+
|
|
2661
3133
|
websocket._url = address;
|
|
2662
3134
|
}
|
|
3135
|
+
|
|
2663
3136
|
const isSecure = parsedUrl.protocol === 'wss:';
|
|
2664
3137
|
const isIpcUrl = parsedUrl.protocol === 'ws+unix:';
|
|
2665
3138
|
let invalidUrlMessage;
|
|
3139
|
+
|
|
2666
3140
|
if (parsedUrl.protocol !== 'ws:' && !isSecure && !isIpcUrl) {
|
|
2667
|
-
invalidUrlMessage =
|
|
3141
|
+
invalidUrlMessage =
|
|
3142
|
+
'The URL\'s protocol must be one of "ws:", "wss:", or "ws+unix:"';
|
|
2668
3143
|
} else if (isIpcUrl && !parsedUrl.pathname) {
|
|
2669
3144
|
invalidUrlMessage = "The URL's pathname is empty";
|
|
2670
3145
|
} else if (parsedUrl.hash) {
|
|
2671
3146
|
invalidUrlMessage = 'The URL contains a fragment identifier';
|
|
2672
3147
|
}
|
|
3148
|
+
|
|
2673
3149
|
if (invalidUrlMessage) {
|
|
2674
3150
|
const err = new SyntaxError(invalidUrlMessage);
|
|
3151
|
+
|
|
2675
3152
|
if (websocket._redirects === 0) {
|
|
2676
3153
|
throw err;
|
|
2677
3154
|
} else {
|
|
@@ -2679,15 +3156,19 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2679
3156
|
return;
|
|
2680
3157
|
}
|
|
2681
3158
|
}
|
|
3159
|
+
|
|
2682
3160
|
const defaultPort = isSecure ? 443 : 80;
|
|
2683
3161
|
const key = randomBytes(16).toString('base64');
|
|
2684
3162
|
const request = isSecure ? https.request : http$1.request;
|
|
2685
3163
|
const protocolSet = new Set();
|
|
2686
3164
|
let perMessageDeflate;
|
|
3165
|
+
|
|
2687
3166
|
opts.createConnection = isSecure ? tlsConnect : netConnect;
|
|
2688
3167
|
opts.defaultPort = opts.defaultPort || defaultPort;
|
|
2689
3168
|
opts.port = parsedUrl.port || defaultPort;
|
|
2690
|
-
opts.host = parsedUrl.hostname.startsWith('[')
|
|
3169
|
+
opts.host = parsedUrl.hostname.startsWith('[')
|
|
3170
|
+
? parsedUrl.hostname.slice(1, -1)
|
|
3171
|
+
: parsedUrl.hostname;
|
|
2691
3172
|
opts.headers = {
|
|
2692
3173
|
...opts.headers,
|
|
2693
3174
|
'Sec-WebSocket-Version': opts.protocolVersion,
|
|
@@ -2697,19 +3178,32 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2697
3178
|
};
|
|
2698
3179
|
opts.path = parsedUrl.pathname + parsedUrl.search;
|
|
2699
3180
|
opts.timeout = opts.handshakeTimeout;
|
|
3181
|
+
|
|
2700
3182
|
if (opts.perMessageDeflate) {
|
|
2701
|
-
perMessageDeflate = new PerMessageDeflate$1(
|
|
3183
|
+
perMessageDeflate = new PerMessageDeflate$1(
|
|
3184
|
+
opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
|
|
3185
|
+
false,
|
|
3186
|
+
opts.maxPayload
|
|
3187
|
+
);
|
|
2702
3188
|
opts.headers['Sec-WebSocket-Extensions'] = format({
|
|
2703
3189
|
[PerMessageDeflate$1.extensionName]: perMessageDeflate.offer()
|
|
2704
3190
|
});
|
|
2705
3191
|
}
|
|
2706
3192
|
if (protocols.length) {
|
|
2707
3193
|
for (const protocol of protocols) {
|
|
2708
|
-
if (
|
|
2709
|
-
|
|
3194
|
+
if (
|
|
3195
|
+
typeof protocol !== 'string' ||
|
|
3196
|
+
!subprotocolRegex.test(protocol) ||
|
|
3197
|
+
protocolSet.has(protocol)
|
|
3198
|
+
) {
|
|
3199
|
+
throw new SyntaxError(
|
|
3200
|
+
'An invalid or duplicated subprotocol was specified'
|
|
3201
|
+
);
|
|
2710
3202
|
}
|
|
3203
|
+
|
|
2711
3204
|
protocolSet.add(protocol);
|
|
2712
3205
|
}
|
|
3206
|
+
|
|
2713
3207
|
opts.headers['Sec-WebSocket-Protocol'] = protocols.join(',');
|
|
2714
3208
|
}
|
|
2715
3209
|
if (opts.origin) {
|
|
@@ -2722,42 +3216,56 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2722
3216
|
if (parsedUrl.username || parsedUrl.password) {
|
|
2723
3217
|
opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
|
|
2724
3218
|
}
|
|
3219
|
+
|
|
2725
3220
|
if (isIpcUrl) {
|
|
2726
3221
|
const parts = opts.path.split(':');
|
|
3222
|
+
|
|
2727
3223
|
opts.socketPath = parts[0];
|
|
2728
3224
|
opts.path = parts[1];
|
|
2729
3225
|
}
|
|
3226
|
+
|
|
2730
3227
|
let req;
|
|
3228
|
+
|
|
2731
3229
|
if (opts.followRedirects) {
|
|
2732
3230
|
if (websocket._redirects === 0) {
|
|
2733
3231
|
websocket._originalIpc = isIpcUrl;
|
|
2734
3232
|
websocket._originalSecure = isSecure;
|
|
2735
|
-
websocket._originalHostOrSocketPath = isIpcUrl
|
|
3233
|
+
websocket._originalHostOrSocketPath = isIpcUrl
|
|
3234
|
+
? opts.socketPath
|
|
3235
|
+
: parsedUrl.host;
|
|
3236
|
+
|
|
2736
3237
|
const headers = options && options.headers;
|
|
2737
3238
|
|
|
2738
3239
|
//
|
|
2739
3240
|
// Shallow copy the user provided options so that headers can be changed
|
|
2740
3241
|
// without mutating the original object.
|
|
2741
3242
|
//
|
|
2742
|
-
options = {
|
|
2743
|
-
|
|
2744
|
-
headers: {}
|
|
2745
|
-
};
|
|
3243
|
+
options = { ...options, headers: {} };
|
|
3244
|
+
|
|
2746
3245
|
if (headers) {
|
|
2747
3246
|
for (const [key, value] of Object.entries(headers)) {
|
|
2748
3247
|
options.headers[key.toLowerCase()] = value;
|
|
2749
3248
|
}
|
|
2750
3249
|
}
|
|
2751
3250
|
} else if (websocket.listenerCount('redirect') === 0) {
|
|
2752
|
-
const isSameHost = isIpcUrl
|
|
2753
|
-
|
|
3251
|
+
const isSameHost = isIpcUrl
|
|
3252
|
+
? websocket._originalIpc
|
|
3253
|
+
? opts.socketPath === websocket._originalHostOrSocketPath
|
|
3254
|
+
: false
|
|
3255
|
+
: websocket._originalIpc
|
|
3256
|
+
? false
|
|
3257
|
+
: parsedUrl.host === websocket._originalHostOrSocketPath;
|
|
3258
|
+
|
|
3259
|
+
if (!isSameHost || (websocket._originalSecure && !isSecure)) {
|
|
2754
3260
|
//
|
|
2755
3261
|
// Match curl 7.77.0 behavior and drop the following headers. These
|
|
2756
3262
|
// headers are also dropped when following a redirect to a subdomain.
|
|
2757
3263
|
//
|
|
2758
3264
|
delete opts.headers.authorization;
|
|
2759
3265
|
delete opts.headers.cookie;
|
|
3266
|
+
|
|
2760
3267
|
if (!isSameHost) delete opts.headers.host;
|
|
3268
|
+
|
|
2761
3269
|
opts.auth = undefined;
|
|
2762
3270
|
}
|
|
2763
3271
|
}
|
|
@@ -2768,9 +3276,12 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2768
3276
|
// will take precedence.
|
|
2769
3277
|
//
|
|
2770
3278
|
if (opts.auth && !options.headers.authorization) {
|
|
2771
|
-
options.headers.authorization =
|
|
3279
|
+
options.headers.authorization =
|
|
3280
|
+
'Basic ' + Buffer.from(opts.auth).toString('base64');
|
|
2772
3281
|
}
|
|
3282
|
+
|
|
2773
3283
|
req = websocket._req = request(opts);
|
|
3284
|
+
|
|
2774
3285
|
if (websocket._redirects) {
|
|
2775
3286
|
//
|
|
2776
3287
|
// Unlike what is done for the `'upgrade'` event, no early exit is
|
|
@@ -2786,26 +3297,39 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2786
3297
|
} else {
|
|
2787
3298
|
req = websocket._req = request(opts);
|
|
2788
3299
|
}
|
|
3300
|
+
|
|
2789
3301
|
if (opts.timeout) {
|
|
2790
3302
|
req.on('timeout', () => {
|
|
2791
3303
|
abortHandshake$1(websocket, req, 'Opening handshake has timed out');
|
|
2792
3304
|
});
|
|
2793
3305
|
}
|
|
2794
|
-
|
|
3306
|
+
|
|
3307
|
+
req.on('error', (err) => {
|
|
2795
3308
|
if (req === null || req[kAborted]) return;
|
|
3309
|
+
|
|
2796
3310
|
req = websocket._req = null;
|
|
2797
3311
|
emitErrorAndClose(websocket, err);
|
|
2798
3312
|
});
|
|
2799
|
-
|
|
3313
|
+
|
|
3314
|
+
req.on('response', (res) => {
|
|
2800
3315
|
const location = res.headers.location;
|
|
2801
3316
|
const statusCode = res.statusCode;
|
|
2802
|
-
|
|
3317
|
+
|
|
3318
|
+
if (
|
|
3319
|
+
location &&
|
|
3320
|
+
opts.followRedirects &&
|
|
3321
|
+
statusCode >= 300 &&
|
|
3322
|
+
statusCode < 400
|
|
3323
|
+
) {
|
|
2803
3324
|
if (++websocket._redirects > opts.maxRedirects) {
|
|
2804
3325
|
abortHandshake$1(websocket, req, 'Maximum redirects exceeded');
|
|
2805
3326
|
return;
|
|
2806
3327
|
}
|
|
3328
|
+
|
|
2807
3329
|
req.abort();
|
|
3330
|
+
|
|
2808
3331
|
let addr;
|
|
3332
|
+
|
|
2809
3333
|
try {
|
|
2810
3334
|
addr = new URL(location, address);
|
|
2811
3335
|
} catch (e) {
|
|
@@ -2813,11 +3337,17 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2813
3337
|
emitErrorAndClose(websocket, err);
|
|
2814
3338
|
return;
|
|
2815
3339
|
}
|
|
3340
|
+
|
|
2816
3341
|
initAsClient(websocket, addr, protocols, options);
|
|
2817
3342
|
} else if (!websocket.emit('unexpected-response', req, res)) {
|
|
2818
|
-
abortHandshake$1(
|
|
3343
|
+
abortHandshake$1(
|
|
3344
|
+
websocket,
|
|
3345
|
+
req,
|
|
3346
|
+
`Unexpected server response: ${res.statusCode}`
|
|
3347
|
+
);
|
|
2819
3348
|
}
|
|
2820
3349
|
});
|
|
3350
|
+
|
|
2821
3351
|
req.on('upgrade', (res, socket, head) => {
|
|
2822
3352
|
websocket.emit('upgrade', res);
|
|
2823
3353
|
|
|
@@ -2826,18 +3356,26 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2826
3356
|
// `'upgrade'` event.
|
|
2827
3357
|
//
|
|
2828
3358
|
if (websocket.readyState !== WebSocket$1.CONNECTING) return;
|
|
3359
|
+
|
|
2829
3360
|
req = websocket._req = null;
|
|
3361
|
+
|
|
2830
3362
|
if (res.headers.upgrade.toLowerCase() !== 'websocket') {
|
|
2831
3363
|
abortHandshake$1(websocket, socket, 'Invalid Upgrade header');
|
|
2832
3364
|
return;
|
|
2833
3365
|
}
|
|
2834
|
-
|
|
3366
|
+
|
|
3367
|
+
const digest = createHash$1('sha1')
|
|
3368
|
+
.update(key + GUID$1)
|
|
3369
|
+
.digest('base64');
|
|
3370
|
+
|
|
2835
3371
|
if (res.headers['sec-websocket-accept'] !== digest) {
|
|
2836
3372
|
abortHandshake$1(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
|
|
2837
3373
|
return;
|
|
2838
3374
|
}
|
|
3375
|
+
|
|
2839
3376
|
const serverProt = res.headers['sec-websocket-protocol'];
|
|
2840
3377
|
let protError;
|
|
3378
|
+
|
|
2841
3379
|
if (serverProt !== undefined) {
|
|
2842
3380
|
if (!protocolSet.size) {
|
|
2843
3381
|
protError = 'Server sent a subprotocol but none was requested';
|
|
@@ -2847,19 +3385,27 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2847
3385
|
} else if (protocolSet.size) {
|
|
2848
3386
|
protError = 'Server sent no subprotocol';
|
|
2849
3387
|
}
|
|
3388
|
+
|
|
2850
3389
|
if (protError) {
|
|
2851
3390
|
abortHandshake$1(websocket, socket, protError);
|
|
2852
3391
|
return;
|
|
2853
3392
|
}
|
|
3393
|
+
|
|
2854
3394
|
if (serverProt) websocket._protocol = serverProt;
|
|
3395
|
+
|
|
2855
3396
|
const secWebSocketExtensions = res.headers['sec-websocket-extensions'];
|
|
3397
|
+
|
|
2856
3398
|
if (secWebSocketExtensions !== undefined) {
|
|
2857
3399
|
if (!perMessageDeflate) {
|
|
2858
|
-
const message =
|
|
3400
|
+
const message =
|
|
3401
|
+
'Server sent a Sec-WebSocket-Extensions header but no extension ' +
|
|
3402
|
+
'was requested';
|
|
2859
3403
|
abortHandshake$1(websocket, socket, message);
|
|
2860
3404
|
return;
|
|
2861
3405
|
}
|
|
3406
|
+
|
|
2862
3407
|
let extensions;
|
|
3408
|
+
|
|
2863
3409
|
try {
|
|
2864
3410
|
extensions = parse$1(secWebSocketExtensions);
|
|
2865
3411
|
} catch (err) {
|
|
@@ -2867,12 +3413,18 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2867
3413
|
abortHandshake$1(websocket, socket, message);
|
|
2868
3414
|
return;
|
|
2869
3415
|
}
|
|
3416
|
+
|
|
2870
3417
|
const extensionNames = Object.keys(extensions);
|
|
2871
|
-
|
|
3418
|
+
|
|
3419
|
+
if (
|
|
3420
|
+
extensionNames.length !== 1 ||
|
|
3421
|
+
extensionNames[0] !== PerMessageDeflate$1.extensionName
|
|
3422
|
+
) {
|
|
2872
3423
|
const message = 'Server indicated an extension that was not requested';
|
|
2873
3424
|
abortHandshake$1(websocket, socket, message);
|
|
2874
3425
|
return;
|
|
2875
3426
|
}
|
|
3427
|
+
|
|
2876
3428
|
try {
|
|
2877
3429
|
perMessageDeflate.accept(extensions[PerMessageDeflate$1.extensionName]);
|
|
2878
3430
|
} catch (err) {
|
|
@@ -2880,14 +3432,18 @@ function initAsClient(websocket, address, protocols, options) {
|
|
|
2880
3432
|
abortHandshake$1(websocket, socket, message);
|
|
2881
3433
|
return;
|
|
2882
3434
|
}
|
|
2883
|
-
|
|
3435
|
+
|
|
3436
|
+
websocket._extensions[PerMessageDeflate$1.extensionName] =
|
|
3437
|
+
perMessageDeflate;
|
|
2884
3438
|
}
|
|
3439
|
+
|
|
2885
3440
|
websocket.setSocket(socket, head, {
|
|
2886
3441
|
generateMask: opts.generateMask,
|
|
2887
3442
|
maxPayload: opts.maxPayload,
|
|
2888
3443
|
skipUTF8Validation: opts.skipUTF8Validation
|
|
2889
3444
|
});
|
|
2890
3445
|
});
|
|
3446
|
+
|
|
2891
3447
|
if (opts.finishRequest) {
|
|
2892
3448
|
opts.finishRequest(req, websocket);
|
|
2893
3449
|
} else {
|
|
@@ -2929,9 +3485,11 @@ function netConnect(options) {
|
|
|
2929
3485
|
*/
|
|
2930
3486
|
function tlsConnect(options) {
|
|
2931
3487
|
options.path = undefined;
|
|
3488
|
+
|
|
2932
3489
|
if (!options.servername && options.servername !== '') {
|
|
2933
3490
|
options.servername = net.isIP(options.host) ? '' : options.host;
|
|
2934
3491
|
}
|
|
3492
|
+
|
|
2935
3493
|
return tls.connect(options);
|
|
2936
3494
|
}
|
|
2937
3495
|
|
|
@@ -2946,11 +3504,14 @@ function tlsConnect(options) {
|
|
|
2946
3504
|
*/
|
|
2947
3505
|
function abortHandshake$1(websocket, stream, message) {
|
|
2948
3506
|
websocket._readyState = WebSocket$1.CLOSING;
|
|
3507
|
+
|
|
2949
3508
|
const err = new Error(message);
|
|
2950
3509
|
Error.captureStackTrace(err, abortHandshake$1);
|
|
3510
|
+
|
|
2951
3511
|
if (stream.setHeader) {
|
|
2952
3512
|
stream[kAborted] = true;
|
|
2953
3513
|
stream.abort();
|
|
3514
|
+
|
|
2954
3515
|
if (stream.socket && !stream.socket.destroyed) {
|
|
2955
3516
|
//
|
|
2956
3517
|
// On Node.js >= 14.3.0 `request.abort()` does not destroy the socket if
|
|
@@ -2959,6 +3520,7 @@ function abortHandshake$1(websocket, stream, message) {
|
|
|
2959
3520
|
//
|
|
2960
3521
|
stream.socket.destroy();
|
|
2961
3522
|
}
|
|
3523
|
+
|
|
2962
3524
|
process.nextTick(emitErrorAndClose, websocket, err);
|
|
2963
3525
|
} else {
|
|
2964
3526
|
stream.destroy(err);
|
|
@@ -2986,10 +3548,15 @@ function sendAfterClose(websocket, data, cb) {
|
|
|
2986
3548
|
// `setSocket()` method is not called, so the `_socket` and `_sender`
|
|
2987
3549
|
// properties are set to `null`.
|
|
2988
3550
|
//
|
|
2989
|
-
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
3551
|
+
if (websocket._socket) websocket._sender._bufferedBytes += length;
|
|
3552
|
+
else websocket._bufferedAmount += length;
|
|
2990
3553
|
}
|
|
3554
|
+
|
|
2991
3555
|
if (cb) {
|
|
2992
|
-
const err = new Error(
|
|
3556
|
+
const err = new Error(
|
|
3557
|
+
`WebSocket is not open: readyState ${websocket.readyState} ` +
|
|
3558
|
+
`(${readyStates[websocket.readyState]})`
|
|
3559
|
+
);
|
|
2993
3560
|
process.nextTick(cb, err);
|
|
2994
3561
|
}
|
|
2995
3562
|
}
|
|
@@ -3003,13 +3570,18 @@ function sendAfterClose(websocket, data, cb) {
|
|
|
3003
3570
|
*/
|
|
3004
3571
|
function receiverOnConclude(code, reason) {
|
|
3005
3572
|
const websocket = this[kWebSocket$1];
|
|
3573
|
+
|
|
3006
3574
|
websocket._closeFrameReceived = true;
|
|
3007
3575
|
websocket._closeMessage = reason;
|
|
3008
3576
|
websocket._closeCode = code;
|
|
3577
|
+
|
|
3009
3578
|
if (websocket._socket[kWebSocket$1] === undefined) return;
|
|
3579
|
+
|
|
3010
3580
|
websocket._socket.removeListener('data', socketOnData);
|
|
3011
3581
|
process.nextTick(resume, websocket._socket);
|
|
3012
|
-
|
|
3582
|
+
|
|
3583
|
+
if (code === 1005) websocket.close();
|
|
3584
|
+
else websocket.close(code, reason);
|
|
3013
3585
|
}
|
|
3014
3586
|
|
|
3015
3587
|
/**
|
|
@@ -3019,6 +3591,7 @@ function receiverOnConclude(code, reason) {
|
|
|
3019
3591
|
*/
|
|
3020
3592
|
function receiverOnDrain() {
|
|
3021
3593
|
const websocket = this[kWebSocket$1];
|
|
3594
|
+
|
|
3022
3595
|
if (!websocket.isPaused) websocket._socket.resume();
|
|
3023
3596
|
}
|
|
3024
3597
|
|
|
@@ -3030,6 +3603,7 @@ function receiverOnDrain() {
|
|
|
3030
3603
|
*/
|
|
3031
3604
|
function receiverOnError(err) {
|
|
3032
3605
|
const websocket = this[kWebSocket$1];
|
|
3606
|
+
|
|
3033
3607
|
if (websocket._socket[kWebSocket$1] !== undefined) {
|
|
3034
3608
|
websocket._socket.removeListener('data', socketOnData);
|
|
3035
3609
|
|
|
@@ -3038,8 +3612,10 @@ function receiverOnError(err) {
|
|
|
3038
3612
|
// https://github.com/websockets/ws/issues/1940.
|
|
3039
3613
|
//
|
|
3040
3614
|
process.nextTick(resume, websocket._socket);
|
|
3615
|
+
|
|
3041
3616
|
websocket.close(err[kStatusCode]);
|
|
3042
3617
|
}
|
|
3618
|
+
|
|
3043
3619
|
websocket.emit('error', err);
|
|
3044
3620
|
}
|
|
3045
3621
|
|
|
@@ -3071,6 +3647,7 @@ function receiverOnMessage(data, isBinary) {
|
|
|
3071
3647
|
*/
|
|
3072
3648
|
function receiverOnPing(data) {
|
|
3073
3649
|
const websocket = this[kWebSocket$1];
|
|
3650
|
+
|
|
3074
3651
|
websocket.pong(data, !websocket._isServer, NOOP);
|
|
3075
3652
|
websocket.emit('ping', data);
|
|
3076
3653
|
}
|
|
@@ -3102,10 +3679,13 @@ function resume(stream) {
|
|
|
3102
3679
|
*/
|
|
3103
3680
|
function socketOnClose() {
|
|
3104
3681
|
const websocket = this[kWebSocket$1];
|
|
3682
|
+
|
|
3105
3683
|
this.removeListener('close', socketOnClose);
|
|
3106
3684
|
this.removeListener('data', socketOnData);
|
|
3107
3685
|
this.removeListener('end', socketOnEnd);
|
|
3686
|
+
|
|
3108
3687
|
websocket._readyState = WebSocket$1.CLOSING;
|
|
3688
|
+
|
|
3109
3689
|
let chunk;
|
|
3110
3690
|
|
|
3111
3691
|
//
|
|
@@ -3117,13 +3697,25 @@ function socketOnClose() {
|
|
|
3117
3697
|
// will return `null`. If instead, the socket is paused, any possible buffered
|
|
3118
3698
|
// data will be read as a single chunk.
|
|
3119
3699
|
//
|
|
3120
|
-
if (
|
|
3700
|
+
if (
|
|
3701
|
+
!this._readableState.endEmitted &&
|
|
3702
|
+
!websocket._closeFrameReceived &&
|
|
3703
|
+
!websocket._receiver._writableState.errorEmitted &&
|
|
3704
|
+
(chunk = websocket._socket.read()) !== null
|
|
3705
|
+
) {
|
|
3121
3706
|
websocket._receiver.write(chunk);
|
|
3122
3707
|
}
|
|
3708
|
+
|
|
3123
3709
|
websocket._receiver.end();
|
|
3710
|
+
|
|
3124
3711
|
this[kWebSocket$1] = undefined;
|
|
3712
|
+
|
|
3125
3713
|
clearTimeout(websocket._closeTimer);
|
|
3126
|
-
|
|
3714
|
+
|
|
3715
|
+
if (
|
|
3716
|
+
websocket._receiver._writableState.finished ||
|
|
3717
|
+
websocket._receiver._writableState.errorEmitted
|
|
3718
|
+
) {
|
|
3127
3719
|
websocket.emitClose();
|
|
3128
3720
|
} else {
|
|
3129
3721
|
websocket._receiver.on('error', receiverOnFinish);
|
|
@@ -3150,6 +3742,7 @@ function socketOnData(chunk) {
|
|
|
3150
3742
|
*/
|
|
3151
3743
|
function socketOnEnd() {
|
|
3152
3744
|
const websocket = this[kWebSocket$1];
|
|
3745
|
+
|
|
3153
3746
|
websocket._readyState = WebSocket$1.CLOSING;
|
|
3154
3747
|
websocket._receiver.end();
|
|
3155
3748
|
this.end();
|
|
@@ -3162,16 +3755,17 @@ function socketOnEnd() {
|
|
|
3162
3755
|
*/
|
|
3163
3756
|
function socketOnError$1() {
|
|
3164
3757
|
const websocket = this[kWebSocket$1];
|
|
3758
|
+
|
|
3165
3759
|
this.removeListener('error', socketOnError$1);
|
|
3166
3760
|
this.on('error', NOOP);
|
|
3761
|
+
|
|
3167
3762
|
if (websocket) {
|
|
3168
3763
|
websocket._readyState = WebSocket$1.CLOSING;
|
|
3169
3764
|
this.destroy();
|
|
3170
3765
|
}
|
|
3171
3766
|
}
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
} = validationExports;
|
|
3767
|
+
|
|
3768
|
+
const { tokenChars } = validationExports;
|
|
3175
3769
|
|
|
3176
3770
|
/**
|
|
3177
3771
|
* Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
|
|
@@ -3185,57 +3779,67 @@ function parse(header) {
|
|
|
3185
3779
|
let start = -1;
|
|
3186
3780
|
let end = -1;
|
|
3187
3781
|
let i = 0;
|
|
3782
|
+
|
|
3188
3783
|
for (i; i < header.length; i++) {
|
|
3189
3784
|
const code = header.charCodeAt(i);
|
|
3785
|
+
|
|
3190
3786
|
if (end === -1 && tokenChars[code] === 1) {
|
|
3191
3787
|
if (start === -1) start = i;
|
|
3192
|
-
} else if (
|
|
3788
|
+
} else if (
|
|
3789
|
+
i !== 0 &&
|
|
3790
|
+
(code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
|
|
3791
|
+
) {
|
|
3193
3792
|
if (end === -1 && start !== -1) end = i;
|
|
3194
3793
|
} else if (code === 0x2c /* ',' */) {
|
|
3195
3794
|
if (start === -1) {
|
|
3196
3795
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3197
3796
|
}
|
|
3797
|
+
|
|
3198
3798
|
if (end === -1) end = i;
|
|
3799
|
+
|
|
3199
3800
|
const protocol = header.slice(start, end);
|
|
3801
|
+
|
|
3200
3802
|
if (protocols.has(protocol)) {
|
|
3201
3803
|
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
3202
3804
|
}
|
|
3805
|
+
|
|
3203
3806
|
protocols.add(protocol);
|
|
3204
3807
|
start = end = -1;
|
|
3205
3808
|
} else {
|
|
3206
3809
|
throw new SyntaxError(`Unexpected character at index ${i}`);
|
|
3207
3810
|
}
|
|
3208
3811
|
}
|
|
3812
|
+
|
|
3209
3813
|
if (start === -1 || end !== -1) {
|
|
3210
3814
|
throw new SyntaxError('Unexpected end of input');
|
|
3211
3815
|
}
|
|
3816
|
+
|
|
3212
3817
|
const protocol = header.slice(start, i);
|
|
3818
|
+
|
|
3213
3819
|
if (protocols.has(protocol)) {
|
|
3214
3820
|
throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
|
|
3215
3821
|
}
|
|
3822
|
+
|
|
3216
3823
|
protocols.add(protocol);
|
|
3217
3824
|
return protocols;
|
|
3218
3825
|
}
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
};
|
|
3826
|
+
|
|
3827
|
+
var subprotocol$1 = { parse };
|
|
3222
3828
|
|
|
3223
3829
|
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^net|tls|https$" }] */
|
|
3224
3830
|
|
|
3225
3831
|
const EventEmitter = require$$0$3;
|
|
3226
3832
|
const http = require$$2;
|
|
3227
|
-
const {
|
|
3228
|
-
|
|
3229
|
-
} = require$$5;
|
|
3833
|
+
const { createHash } = require$$5;
|
|
3834
|
+
|
|
3230
3835
|
const extension = extension$1;
|
|
3231
3836
|
const PerMessageDeflate = permessageDeflate;
|
|
3232
3837
|
const subprotocol = subprotocol$1;
|
|
3233
3838
|
const WebSocket = websocket;
|
|
3234
|
-
const {
|
|
3235
|
-
|
|
3236
|
-
kWebSocket
|
|
3237
|
-
} = constants;
|
|
3839
|
+
const { GUID, kWebSocket } = constants;
|
|
3840
|
+
|
|
3238
3841
|
const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
|
|
3842
|
+
|
|
3239
3843
|
const RUNNING = 0;
|
|
3240
3844
|
const CLOSING = 1;
|
|
3241
3845
|
const CLOSED = 2;
|
|
@@ -3274,6 +3878,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
3274
3878
|
*/
|
|
3275
3879
|
constructor(options, callback) {
|
|
3276
3880
|
super();
|
|
3881
|
+
|
|
3277
3882
|
options = {
|
|
3278
3883
|
maxPayload: 100 * 1024 * 1024,
|
|
3279
3884
|
skipUTF8Validation: false,
|
|
@@ -3282,8 +3887,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
3282
3887
|
clientTracking: true,
|
|
3283
3888
|
verifyClient: null,
|
|
3284
3889
|
noServer: false,
|
|
3285
|
-
backlog: null,
|
|
3286
|
-
// use default (511 as implemented in net.js)
|
|
3890
|
+
backlog: null, // use default (511 as implemented in net.js)
|
|
3287
3891
|
server: null,
|
|
3288
3892
|
host: null,
|
|
3289
3893
|
path: null,
|
|
@@ -3291,24 +3895,41 @@ class WebSocketServer extends EventEmitter {
|
|
|
3291
3895
|
WebSocket,
|
|
3292
3896
|
...options
|
|
3293
3897
|
};
|
|
3294
|
-
|
|
3295
|
-
|
|
3898
|
+
|
|
3899
|
+
if (
|
|
3900
|
+
(options.port == null && !options.server && !options.noServer) ||
|
|
3901
|
+
(options.port != null && (options.server || options.noServer)) ||
|
|
3902
|
+
(options.server && options.noServer)
|
|
3903
|
+
) {
|
|
3904
|
+
throw new TypeError(
|
|
3905
|
+
'One and only one of the "port", "server", or "noServer" options ' +
|
|
3906
|
+
'must be specified'
|
|
3907
|
+
);
|
|
3296
3908
|
}
|
|
3909
|
+
|
|
3297
3910
|
if (options.port != null) {
|
|
3298
3911
|
this._server = http.createServer((req, res) => {
|
|
3299
3912
|
const body = http.STATUS_CODES[426];
|
|
3913
|
+
|
|
3300
3914
|
res.writeHead(426, {
|
|
3301
3915
|
'Content-Length': body.length,
|
|
3302
3916
|
'Content-Type': 'text/plain'
|
|
3303
3917
|
});
|
|
3304
3918
|
res.end(body);
|
|
3305
3919
|
});
|
|
3306
|
-
this._server.listen(
|
|
3920
|
+
this._server.listen(
|
|
3921
|
+
options.port,
|
|
3922
|
+
options.host,
|
|
3923
|
+
options.backlog,
|
|
3924
|
+
callback
|
|
3925
|
+
);
|
|
3307
3926
|
} else if (options.server) {
|
|
3308
3927
|
this._server = options.server;
|
|
3309
3928
|
}
|
|
3929
|
+
|
|
3310
3930
|
if (this._server) {
|
|
3311
3931
|
const emitConnection = this.emit.bind(this, 'connection');
|
|
3932
|
+
|
|
3312
3933
|
this._removeListeners = addListeners(this._server, {
|
|
3313
3934
|
listening: this.emit.bind(this, 'listening'),
|
|
3314
3935
|
error: this.emit.bind(this, 'error'),
|
|
@@ -3317,11 +3938,13 @@ class WebSocketServer extends EventEmitter {
|
|
|
3317
3938
|
}
|
|
3318
3939
|
});
|
|
3319
3940
|
}
|
|
3941
|
+
|
|
3320
3942
|
if (options.perMessageDeflate === true) options.perMessageDeflate = {};
|
|
3321
3943
|
if (options.clientTracking) {
|
|
3322
3944
|
this.clients = new Set();
|
|
3323
3945
|
this._shouldEmitClose = false;
|
|
3324
3946
|
}
|
|
3947
|
+
|
|
3325
3948
|
this.options = options;
|
|
3326
3949
|
this._state = RUNNING;
|
|
3327
3950
|
}
|
|
@@ -3339,6 +3962,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
3339
3962
|
if (this.options.noServer) {
|
|
3340
3963
|
throw new Error('The server is operating in "noServer" mode');
|
|
3341
3964
|
}
|
|
3965
|
+
|
|
3342
3966
|
if (!this._server) return null;
|
|
3343
3967
|
return this._server.address();
|
|
3344
3968
|
}
|
|
@@ -3357,17 +3981,22 @@ class WebSocketServer extends EventEmitter {
|
|
|
3357
3981
|
cb(new Error('The server is not running'));
|
|
3358
3982
|
});
|
|
3359
3983
|
}
|
|
3984
|
+
|
|
3360
3985
|
process.nextTick(emitClose, this);
|
|
3361
3986
|
return;
|
|
3362
3987
|
}
|
|
3988
|
+
|
|
3363
3989
|
if (cb) this.once('close', cb);
|
|
3990
|
+
|
|
3364
3991
|
if (this._state === CLOSING) return;
|
|
3365
3992
|
this._state = CLOSING;
|
|
3993
|
+
|
|
3366
3994
|
if (this.options.noServer || this.options.server) {
|
|
3367
3995
|
if (this._server) {
|
|
3368
3996
|
this._removeListeners();
|
|
3369
3997
|
this._removeListeners = this._server = null;
|
|
3370
3998
|
}
|
|
3999
|
+
|
|
3371
4000
|
if (this.clients) {
|
|
3372
4001
|
if (!this.clients.size) {
|
|
3373
4002
|
process.nextTick(emitClose, this);
|
|
@@ -3379,6 +4008,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
3379
4008
|
}
|
|
3380
4009
|
} else {
|
|
3381
4010
|
const server = this._server;
|
|
4011
|
+
|
|
3382
4012
|
this._removeListeners();
|
|
3383
4013
|
this._removeListeners = this._server = null;
|
|
3384
4014
|
|
|
@@ -3403,8 +4033,10 @@ class WebSocketServer extends EventEmitter {
|
|
|
3403
4033
|
if (this.options.path) {
|
|
3404
4034
|
const index = req.url.indexOf('?');
|
|
3405
4035
|
const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
|
|
4036
|
+
|
|
3406
4037
|
if (pathname !== this.options.path) return false;
|
|
3407
4038
|
}
|
|
4039
|
+
|
|
3408
4040
|
return true;
|
|
3409
4041
|
}
|
|
3410
4042
|
|
|
@@ -3420,34 +4052,42 @@ class WebSocketServer extends EventEmitter {
|
|
|
3420
4052
|
*/
|
|
3421
4053
|
handleUpgrade(req, socket, head, cb) {
|
|
3422
4054
|
socket.on('error', socketOnError);
|
|
4055
|
+
|
|
3423
4056
|
const key = req.headers['sec-websocket-key'];
|
|
3424
4057
|
const version = +req.headers['sec-websocket-version'];
|
|
4058
|
+
|
|
3425
4059
|
if (req.method !== 'GET') {
|
|
3426
4060
|
const message = 'Invalid HTTP method';
|
|
3427
4061
|
abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
|
|
3428
4062
|
return;
|
|
3429
4063
|
}
|
|
4064
|
+
|
|
3430
4065
|
if (req.headers.upgrade.toLowerCase() !== 'websocket') {
|
|
3431
4066
|
const message = 'Invalid Upgrade header';
|
|
3432
4067
|
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
3433
4068
|
return;
|
|
3434
4069
|
}
|
|
4070
|
+
|
|
3435
4071
|
if (!key || !keyRegex.test(key)) {
|
|
3436
4072
|
const message = 'Missing or invalid Sec-WebSocket-Key header';
|
|
3437
4073
|
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
3438
4074
|
return;
|
|
3439
4075
|
}
|
|
4076
|
+
|
|
3440
4077
|
if (version !== 8 && version !== 13) {
|
|
3441
4078
|
const message = 'Missing or invalid Sec-WebSocket-Version header';
|
|
3442
4079
|
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
3443
4080
|
return;
|
|
3444
4081
|
}
|
|
4082
|
+
|
|
3445
4083
|
if (!this.shouldHandle(req)) {
|
|
3446
4084
|
abortHandshake(socket, 400);
|
|
3447
4085
|
return;
|
|
3448
4086
|
}
|
|
4087
|
+
|
|
3449
4088
|
const secWebSocketProtocol = req.headers['sec-websocket-protocol'];
|
|
3450
4089
|
let protocols = new Set();
|
|
4090
|
+
|
|
3451
4091
|
if (secWebSocketProtocol !== undefined) {
|
|
3452
4092
|
try {
|
|
3453
4093
|
protocols = subprotocol.parse(secWebSocketProtocol);
|
|
@@ -3457,18 +4097,30 @@ class WebSocketServer extends EventEmitter {
|
|
|
3457
4097
|
return;
|
|
3458
4098
|
}
|
|
3459
4099
|
}
|
|
4100
|
+
|
|
3460
4101
|
const secWebSocketExtensions = req.headers['sec-websocket-extensions'];
|
|
3461
4102
|
const extensions = {};
|
|
3462
|
-
|
|
3463
|
-
|
|
4103
|
+
|
|
4104
|
+
if (
|
|
4105
|
+
this.options.perMessageDeflate &&
|
|
4106
|
+
secWebSocketExtensions !== undefined
|
|
4107
|
+
) {
|
|
4108
|
+
const perMessageDeflate = new PerMessageDeflate(
|
|
4109
|
+
this.options.perMessageDeflate,
|
|
4110
|
+
true,
|
|
4111
|
+
this.options.maxPayload
|
|
4112
|
+
);
|
|
4113
|
+
|
|
3464
4114
|
try {
|
|
3465
4115
|
const offers = extension.parse(secWebSocketExtensions);
|
|
4116
|
+
|
|
3466
4117
|
if (offers[PerMessageDeflate.extensionName]) {
|
|
3467
4118
|
perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
|
|
3468
4119
|
extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
|
|
3469
4120
|
}
|
|
3470
4121
|
} catch (err) {
|
|
3471
|
-
const message =
|
|
4122
|
+
const message =
|
|
4123
|
+
'Invalid or unacceptable Sec-WebSocket-Extensions header';
|
|
3472
4124
|
abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
|
|
3473
4125
|
return;
|
|
3474
4126
|
}
|
|
@@ -3479,21 +4131,34 @@ class WebSocketServer extends EventEmitter {
|
|
|
3479
4131
|
//
|
|
3480
4132
|
if (this.options.verifyClient) {
|
|
3481
4133
|
const info = {
|
|
3482
|
-
origin:
|
|
4134
|
+
origin:
|
|
4135
|
+
req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
|
|
3483
4136
|
secure: !!(req.socket.authorized || req.socket.encrypted),
|
|
3484
4137
|
req
|
|
3485
4138
|
};
|
|
4139
|
+
|
|
3486
4140
|
if (this.options.verifyClient.length === 2) {
|
|
3487
4141
|
this.options.verifyClient(info, (verified, code, message, headers) => {
|
|
3488
4142
|
if (!verified) {
|
|
3489
4143
|
return abortHandshake(socket, code || 401, message, headers);
|
|
3490
4144
|
}
|
|
3491
|
-
|
|
4145
|
+
|
|
4146
|
+
this.completeUpgrade(
|
|
4147
|
+
extensions,
|
|
4148
|
+
key,
|
|
4149
|
+
protocols,
|
|
4150
|
+
req,
|
|
4151
|
+
socket,
|
|
4152
|
+
head,
|
|
4153
|
+
cb
|
|
4154
|
+
);
|
|
3492
4155
|
});
|
|
3493
4156
|
return;
|
|
3494
4157
|
}
|
|
4158
|
+
|
|
3495
4159
|
if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
|
|
3496
4160
|
}
|
|
4161
|
+
|
|
3497
4162
|
this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
|
|
3498
4163
|
}
|
|
3499
4164
|
|
|
@@ -3516,23 +4181,43 @@ class WebSocketServer extends EventEmitter {
|
|
|
3516
4181
|
// Destroy the socket if the client has already sent a FIN packet.
|
|
3517
4182
|
//
|
|
3518
4183
|
if (!socket.readable || !socket.writable) return socket.destroy();
|
|
4184
|
+
|
|
3519
4185
|
if (socket[kWebSocket]) {
|
|
3520
|
-
throw new Error(
|
|
4186
|
+
throw new Error(
|
|
4187
|
+
'server.handleUpgrade() was called more than once with the same ' +
|
|
4188
|
+
'socket, possibly due to a misconfiguration'
|
|
4189
|
+
);
|
|
3521
4190
|
}
|
|
4191
|
+
|
|
3522
4192
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
3523
|
-
|
|
3524
|
-
const
|
|
4193
|
+
|
|
4194
|
+
const digest = createHash('sha1')
|
|
4195
|
+
.update(key + GUID)
|
|
4196
|
+
.digest('base64');
|
|
4197
|
+
|
|
4198
|
+
const headers = [
|
|
4199
|
+
'HTTP/1.1 101 Switching Protocols',
|
|
4200
|
+
'Upgrade: websocket',
|
|
4201
|
+
'Connection: Upgrade',
|
|
4202
|
+
`Sec-WebSocket-Accept: ${digest}`
|
|
4203
|
+
];
|
|
4204
|
+
|
|
3525
4205
|
const ws = new this.options.WebSocket(null);
|
|
4206
|
+
|
|
3526
4207
|
if (protocols.size) {
|
|
3527
4208
|
//
|
|
3528
4209
|
// Optionally call external protocol selection handler.
|
|
3529
4210
|
//
|
|
3530
|
-
const protocol = this.options.handleProtocols
|
|
4211
|
+
const protocol = this.options.handleProtocols
|
|
4212
|
+
? this.options.handleProtocols(protocols, req)
|
|
4213
|
+
: protocols.values().next().value;
|
|
4214
|
+
|
|
3531
4215
|
if (protocol) {
|
|
3532
4216
|
headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
|
|
3533
4217
|
ws._protocol = protocol;
|
|
3534
4218
|
}
|
|
3535
4219
|
}
|
|
4220
|
+
|
|
3536
4221
|
if (extensions[PerMessageDeflate.extensionName]) {
|
|
3537
4222
|
const params = extensions[PerMessageDeflate.extensionName].params;
|
|
3538
4223
|
const value = extension.format({
|
|
@@ -3546,24 +4231,30 @@ class WebSocketServer extends EventEmitter {
|
|
|
3546
4231
|
// Allow external modification/inspection of handshake headers.
|
|
3547
4232
|
//
|
|
3548
4233
|
this.emit('headers', headers, req);
|
|
4234
|
+
|
|
3549
4235
|
socket.write(headers.concat('\r\n').join('\r\n'));
|
|
3550
4236
|
socket.removeListener('error', socketOnError);
|
|
4237
|
+
|
|
3551
4238
|
ws.setSocket(socket, head, {
|
|
3552
4239
|
maxPayload: this.options.maxPayload,
|
|
3553
4240
|
skipUTF8Validation: this.options.skipUTF8Validation
|
|
3554
4241
|
});
|
|
4242
|
+
|
|
3555
4243
|
if (this.clients) {
|
|
3556
4244
|
this.clients.add(ws);
|
|
3557
4245
|
ws.on('close', () => {
|
|
3558
4246
|
this.clients.delete(ws);
|
|
4247
|
+
|
|
3559
4248
|
if (this._shouldEmitClose && !this.clients.size) {
|
|
3560
4249
|
process.nextTick(emitClose, this);
|
|
3561
4250
|
}
|
|
3562
4251
|
});
|
|
3563
4252
|
}
|
|
4253
|
+
|
|
3564
4254
|
cb(ws, req);
|
|
3565
4255
|
}
|
|
3566
4256
|
}
|
|
4257
|
+
|
|
3567
4258
|
var websocketServer = WebSocketServer;
|
|
3568
4259
|
|
|
3569
4260
|
/**
|
|
@@ -3578,6 +4269,7 @@ var websocketServer = WebSocketServer;
|
|
|
3578
4269
|
*/
|
|
3579
4270
|
function addListeners(server, map) {
|
|
3580
4271
|
for (const event of Object.keys(map)) server.on(event, map[event]);
|
|
4272
|
+
|
|
3581
4273
|
return function removeListeners() {
|
|
3582
4274
|
for (const event of Object.keys(map)) {
|
|
3583
4275
|
server.removeListener(event, map[event]);
|
|
@@ -3630,8 +4322,17 @@ function abortHandshake(socket, code, message, headers) {
|
|
|
3630
4322
|
'Content-Length': Buffer.byteLength(message),
|
|
3631
4323
|
...headers
|
|
3632
4324
|
};
|
|
4325
|
+
|
|
3633
4326
|
socket.once('finish', socket.destroy);
|
|
3634
|
-
|
|
4327
|
+
|
|
4328
|
+
socket.end(
|
|
4329
|
+
`HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
|
|
4330
|
+
Object.keys(headers)
|
|
4331
|
+
.map((h) => `${h}: ${headers[h]}`)
|
|
4332
|
+
.join('\r\n') +
|
|
4333
|
+
'\r\n\r\n' +
|
|
4334
|
+
message
|
|
4335
|
+
);
|
|
3635
4336
|
}
|
|
3636
4337
|
|
|
3637
4338
|
/**
|
|
@@ -3649,11 +4350,13 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
|
3649
4350
|
if (server.listenerCount('wsClientError')) {
|
|
3650
4351
|
const err = new Error(message);
|
|
3651
4352
|
Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
|
|
4353
|
+
|
|
3652
4354
|
server.emit('wsClientError', err, socket, req);
|
|
3653
4355
|
} else {
|
|
3654
4356
|
abortHandshake(socket, code, message);
|
|
3655
4357
|
}
|
|
3656
4358
|
}
|
|
4359
|
+
|
|
3657
4360
|
var websocketServer$1 = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
|
|
3658
4361
|
|
|
3659
4362
|
export { websocketServer$1 as WebSocketServer };
|