@rsbuild/core 1.0.0-alpha.3 → 1.0.0-alpha.4

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.
@@ -1,18 +1,18 @@
1
1
  /******/ (() => { // webpackBootstrap
2
2
  /******/ var __webpack_modules__ = ({
3
3
 
4
- /***/ 781:
4
+ /***/ 749:
5
5
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
6
6
 
7
7
  "use strict";
8
8
 
9
9
 
10
- const WebSocket = __nccwpck_require__(715);
10
+ const WebSocket = __nccwpck_require__(227);
11
11
 
12
- WebSocket.createWebSocketStream = __nccwpck_require__(884);
13
- WebSocket.Server = __nccwpck_require__(120);
14
- WebSocket.Receiver = __nccwpck_require__(594);
15
- WebSocket.Sender = __nccwpck_require__(209);
12
+ WebSocket.createWebSocketStream = __nccwpck_require__(192);
13
+ WebSocket.Server = __nccwpck_require__(226);
14
+ WebSocket.Receiver = __nccwpck_require__(245);
15
+ WebSocket.Sender = __nccwpck_require__(415);
16
16
 
17
17
  WebSocket.WebSocket = WebSocket;
18
18
  WebSocket.WebSocketServer = WebSocket.Server;
@@ -22,13 +22,13 @@ module.exports = WebSocket;
22
22
 
23
23
  /***/ }),
24
24
 
25
- /***/ 870:
25
+ /***/ 198:
26
26
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
27
27
 
28
28
  "use strict";
29
29
 
30
30
 
31
- const { EMPTY_BUFFER } = __nccwpck_require__(556);
31
+ const { EMPTY_BUFFER } = __nccwpck_require__(870);
32
32
 
33
33
  const FastBuffer = Buffer[Symbol.species];
34
34
 
@@ -161,16 +161,22 @@ if (!process.env.WS_NO_BUFFER_UTIL) {
161
161
 
162
162
  /***/ }),
163
163
 
164
- /***/ 556:
164
+ /***/ 870:
165
165
  /***/ ((module) => {
166
166
 
167
167
  "use strict";
168
168
 
169
169
 
170
+ const BINARY_TYPES = ['nodebuffer', 'arraybuffer', 'fragments'];
171
+ const hasBlob = typeof Blob !== 'undefined';
172
+
173
+ if (hasBlob) BINARY_TYPES.push('blob');
174
+
170
175
  module.exports = {
171
- BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
176
+ BINARY_TYPES,
172
177
  EMPTY_BUFFER: Buffer.alloc(0),
173
178
  GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
179
+ hasBlob,
174
180
  kForOnEventAttribute: Symbol('kIsForOnEventAttribute'),
175
181
  kListener: Symbol('kListener'),
176
182
  kStatusCode: Symbol('status-code'),
@@ -181,13 +187,13 @@ module.exports = {
181
187
 
182
188
  /***/ }),
183
189
 
184
- /***/ 418:
190
+ /***/ 456:
185
191
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
186
192
 
187
193
  "use strict";
188
194
 
189
195
 
190
- const { kForOnEventAttribute, kListener } = __nccwpck_require__(556);
196
+ const { kForOnEventAttribute, kListener } = __nccwpck_require__(870);
191
197
 
192
198
  const kCode = Symbol('kCode');
193
199
  const kData = Symbol('kData');
@@ -481,13 +487,13 @@ function callListener(listener, thisArg, event) {
481
487
 
482
488
  /***/ }),
483
489
 
484
- /***/ 787:
490
+ /***/ 694:
485
491
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
486
492
 
487
493
  "use strict";
488
494
 
489
495
 
490
- const { tokenChars } = __nccwpck_require__(502);
496
+ const { tokenChars } = __nccwpck_require__(444);
491
497
 
492
498
  /**
493
499
  * Adds an offer to the map of extension offers or a parameter to the map of
@@ -692,7 +698,7 @@ module.exports = { format, parse };
692
698
 
693
699
  /***/ }),
694
700
 
695
- /***/ 202:
701
+ /***/ 801:
696
702
  /***/ ((module) => {
697
703
 
698
704
  "use strict";
@@ -755,7 +761,7 @@ module.exports = Limiter;
755
761
 
756
762
  /***/ }),
757
763
 
758
- /***/ 262:
764
+ /***/ 421:
759
765
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
760
766
 
761
767
  "use strict";
@@ -763,9 +769,9 @@ module.exports = Limiter;
763
769
 
764
770
  const zlib = __nccwpck_require__(796);
765
771
 
766
- const bufferUtil = __nccwpck_require__(870);
767
- const Limiter = __nccwpck_require__(202);
768
- const { kStatusCode } = __nccwpck_require__(556);
772
+ const bufferUtil = __nccwpck_require__(198);
773
+ const Limiter = __nccwpck_require__(801);
774
+ const { kStatusCode } = __nccwpck_require__(870);
769
775
 
770
776
  const FastBuffer = Buffer[Symbol.species];
771
777
  const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
@@ -1277,23 +1283,23 @@ function inflateOnError(err) {
1277
1283
 
1278
1284
  /***/ }),
1279
1285
 
1280
- /***/ 594:
1286
+ /***/ 245:
1281
1287
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1282
1288
 
1283
1289
  "use strict";
1284
1290
 
1285
1291
 
1286
- const { Writable } = __nccwpck_require__(955);
1292
+ const { Writable } = __nccwpck_require__(781);
1287
1293
 
1288
- const PerMessageDeflate = __nccwpck_require__(262);
1294
+ const PerMessageDeflate = __nccwpck_require__(421);
1289
1295
  const {
1290
1296
  BINARY_TYPES,
1291
1297
  EMPTY_BUFFER,
1292
1298
  kStatusCode,
1293
1299
  kWebSocket
1294
- } = __nccwpck_require__(556);
1295
- const { concat, toArrayBuffer, unmask } = __nccwpck_require__(870);
1296
- const { isValidStatusCode, isValidUTF8 } = __nccwpck_require__(502);
1300
+ } = __nccwpck_require__(870);
1301
+ const { concat, toArrayBuffer, unmask } = __nccwpck_require__(198);
1302
+ const { isValidStatusCode, isValidUTF8 } = __nccwpck_require__(444);
1297
1303
 
1298
1304
  const FastBuffer = Buffer[Symbol.species];
1299
1305
 
@@ -1842,6 +1848,8 @@ class Receiver extends Writable {
1842
1848
  data = concat(fragments, messageLength);
1843
1849
  } else if (this._binaryType === 'arraybuffer') {
1844
1850
  data = toArrayBuffer(concat(fragments, messageLength));
1851
+ } else if (this._binaryType === 'blob') {
1852
+ data = new Blob(fragments);
1845
1853
  } else {
1846
1854
  data = fragments;
1847
1855
  }
@@ -1989,7 +1997,7 @@ module.exports = Receiver;
1989
1997
 
1990
1998
  /***/ }),
1991
1999
 
1992
- /***/ 209:
2000
+ /***/ 415:
1993
2001
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1994
2002
 
1995
2003
  "use strict";
@@ -1997,13 +2005,13 @@ module.exports = Receiver;
1997
2005
 
1998
2006
 
1999
2007
 
2000
- const { Duplex } = __nccwpck_require__(955);
2008
+ const { Duplex } = __nccwpck_require__(781);
2001
2009
  const { randomFillSync } = __nccwpck_require__(113);
2002
2010
 
2003
- const PerMessageDeflate = __nccwpck_require__(262);
2004
- const { EMPTY_BUFFER } = __nccwpck_require__(556);
2005
- const { isValidStatusCode } = __nccwpck_require__(502);
2006
- const { mask: applyMask, toBuffer } = __nccwpck_require__(870);
2011
+ const PerMessageDeflate = __nccwpck_require__(421);
2012
+ const { EMPTY_BUFFER, kWebSocket, NOOP } = __nccwpck_require__(870);
2013
+ const { isBlob, isValidStatusCode } = __nccwpck_require__(444);
2014
+ const { mask: applyMask, toBuffer } = __nccwpck_require__(198);
2007
2015
 
2008
2016
  const kByteLength = Symbol('kByteLength');
2009
2017
  const maskBuffer = Buffer.alloc(4);
@@ -2011,6 +2019,10 @@ const RANDOM_POOL_SIZE = 8 * 1024;
2011
2019
  let randomPool;
2012
2020
  let randomPoolPointer = RANDOM_POOL_SIZE;
2013
2021
 
2022
+ const DEFAULT = 0;
2023
+ const DEFLATING = 1;
2024
+ const GET_BLOB_DATA = 2;
2025
+
2014
2026
  /**
2015
2027
  * HyBi Sender implementation.
2016
2028
  */
@@ -2037,8 +2049,10 @@ class Sender {
2037
2049
  this._compress = false;
2038
2050
 
2039
2051
  this._bufferedBytes = 0;
2040
- this._deflating = false;
2041
2052
  this._queue = [];
2053
+ this._state = DEFAULT;
2054
+ this.onerror = NOOP;
2055
+ this[kWebSocket] = undefined;
2042
2056
  }
2043
2057
 
2044
2058
  /**
@@ -2205,7 +2219,7 @@ class Sender {
2205
2219
  rsv1: false
2206
2220
  };
2207
2221
 
2208
- if (this._deflating) {
2222
+ if (this._state !== DEFAULT) {
2209
2223
  this.enqueue([this.dispatch, buf, false, options, cb]);
2210
2224
  } else {
2211
2225
  this.sendFrame(Sender.frame(buf, options), cb);
@@ -2227,6 +2241,9 @@ class Sender {
2227
2241
  if (typeof data === 'string') {
2228
2242
  byteLength = Buffer.byteLength(data);
2229
2243
  readOnly = false;
2244
+ } else if (isBlob(data)) {
2245
+ byteLength = data.size;
2246
+ readOnly = false;
2230
2247
  } else {
2231
2248
  data = toBuffer(data);
2232
2249
  byteLength = data.length;
@@ -2248,7 +2265,13 @@ class Sender {
2248
2265
  rsv1: false
2249
2266
  };
2250
2267
 
2251
- if (this._deflating) {
2268
+ if (isBlob(data)) {
2269
+ if (this._state !== DEFAULT) {
2270
+ this.enqueue([this.getBlobData, data, false, options, cb]);
2271
+ } else {
2272
+ this.getBlobData(data, false, options, cb);
2273
+ }
2274
+ } else if (this._state !== DEFAULT) {
2252
2275
  this.enqueue([this.dispatch, data, false, options, cb]);
2253
2276
  } else {
2254
2277
  this.sendFrame(Sender.frame(data, options), cb);
@@ -2270,6 +2293,9 @@ class Sender {
2270
2293
  if (typeof data === 'string') {
2271
2294
  byteLength = Buffer.byteLength(data);
2272
2295
  readOnly = false;
2296
+ } else if (isBlob(data)) {
2297
+ byteLength = data.size;
2298
+ readOnly = false;
2273
2299
  } else {
2274
2300
  data = toBuffer(data);
2275
2301
  byteLength = data.length;
@@ -2291,7 +2317,13 @@ class Sender {
2291
2317
  rsv1: false
2292
2318
  };
2293
2319
 
2294
- if (this._deflating) {
2320
+ if (isBlob(data)) {
2321
+ if (this._state !== DEFAULT) {
2322
+ this.enqueue([this.getBlobData, data, false, options, cb]);
2323
+ } else {
2324
+ this.getBlobData(data, false, options, cb);
2325
+ }
2326
+ } else if (this._state !== DEFAULT) {
2295
2327
  this.enqueue([this.dispatch, data, false, options, cb]);
2296
2328
  } else {
2297
2329
  this.sendFrame(Sender.frame(data, options), cb);
@@ -2325,6 +2357,9 @@ class Sender {
2325
2357
  if (typeof data === 'string') {
2326
2358
  byteLength = Buffer.byteLength(data);
2327
2359
  readOnly = false;
2360
+ } else if (isBlob(data)) {
2361
+ byteLength = data.size;
2362
+ readOnly = false;
2328
2363
  } else {
2329
2364
  data = toBuffer(data);
2330
2365
  byteLength = data.length;
@@ -2352,40 +2387,94 @@ class Sender {
2352
2387
 
2353
2388
  if (options.fin) this._firstFragment = true;
2354
2389
 
2355
- if (perMessageDeflate) {
2356
- const opts = {
2357
- [kByteLength]: byteLength,
2358
- fin: options.fin,
2359
- generateMask: this._generateMask,
2360
- mask: options.mask,
2361
- maskBuffer: this._maskBuffer,
2362
- opcode,
2363
- readOnly,
2364
- rsv1
2365
- };
2390
+ const opts = {
2391
+ [kByteLength]: byteLength,
2392
+ fin: options.fin,
2393
+ generateMask: this._generateMask,
2394
+ mask: options.mask,
2395
+ maskBuffer: this._maskBuffer,
2396
+ opcode,
2397
+ readOnly,
2398
+ rsv1
2399
+ };
2366
2400
 
2367
- if (this._deflating) {
2368
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
2401
+ if (isBlob(data)) {
2402
+ if (this._state !== DEFAULT) {
2403
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
2369
2404
  } else {
2370
- this.dispatch(data, this._compress, opts, cb);
2405
+ this.getBlobData(data, this._compress, opts, cb);
2371
2406
  }
2407
+ } else if (this._state !== DEFAULT) {
2408
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
2372
2409
  } else {
2373
- this.sendFrame(
2374
- Sender.frame(data, {
2375
- [kByteLength]: byteLength,
2376
- fin: options.fin,
2377
- generateMask: this._generateMask,
2378
- mask: options.mask,
2379
- maskBuffer: this._maskBuffer,
2380
- opcode,
2381
- readOnly,
2382
- rsv1: false
2383
- }),
2384
- cb
2385
- );
2410
+ this.dispatch(data, this._compress, opts, cb);
2386
2411
  }
2387
2412
  }
2388
2413
 
2414
+ /**
2415
+ * Gets the contents of a blob as binary data.
2416
+ *
2417
+ * @param {Blob} blob The blob
2418
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
2419
+ * the data
2420
+ * @param {Object} options Options object
2421
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
2422
+ * FIN bit
2423
+ * @param {Function} [options.generateMask] The function used to generate the
2424
+ * masking key
2425
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
2426
+ * `data`
2427
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
2428
+ * key
2429
+ * @param {Number} options.opcode The opcode
2430
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
2431
+ * modified
2432
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
2433
+ * RSV1 bit
2434
+ * @param {Function} [cb] Callback
2435
+ * @private
2436
+ */
2437
+ getBlobData(blob, compress, options, cb) {
2438
+ this._bufferedBytes += options[kByteLength];
2439
+ this._state = GET_BLOB_DATA;
2440
+
2441
+ blob
2442
+ .arrayBuffer()
2443
+ .then((arrayBuffer) => {
2444
+ if (this._socket.destroyed) {
2445
+ const err = new Error(
2446
+ 'The socket was closed while the blob was being read'
2447
+ );
2448
+
2449
+ //
2450
+ // `callCallbacks` is called in the next tick to ensure that errors
2451
+ // that might be thrown in the callbacks behave like errors thrown
2452
+ // outside the promise chain.
2453
+ //
2454
+ process.nextTick(callCallbacks, this, err, cb);
2455
+ return;
2456
+ }
2457
+
2458
+ this._bufferedBytes -= options[kByteLength];
2459
+ const data = toBuffer(arrayBuffer);
2460
+
2461
+ if (!compress) {
2462
+ this._state = DEFAULT;
2463
+ this.sendFrame(Sender.frame(data, options), cb);
2464
+ this.dequeue();
2465
+ } else {
2466
+ this.dispatch(data, compress, options, cb);
2467
+ }
2468
+ })
2469
+ .catch((err) => {
2470
+ //
2471
+ // `onError` is called in the next tick for the same reason that
2472
+ // `callCallbacks` above is.
2473
+ //
2474
+ process.nextTick(onError, this, err, cb);
2475
+ });
2476
+ }
2477
+
2389
2478
  /**
2390
2479
  * Dispatches a message.
2391
2480
  *
@@ -2418,27 +2507,19 @@ class Sender {
2418
2507
  const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2419
2508
 
2420
2509
  this._bufferedBytes += options[kByteLength];
2421
- this._deflating = true;
2510
+ this._state = DEFLATING;
2422
2511
  perMessageDeflate.compress(data, options.fin, (_, buf) => {
2423
2512
  if (this._socket.destroyed) {
2424
2513
  const err = new Error(
2425
2514
  'The socket was closed while data was being compressed'
2426
2515
  );
2427
2516
 
2428
- if (typeof cb === 'function') cb(err);
2429
-
2430
- for (let i = 0; i < this._queue.length; i++) {
2431
- const params = this._queue[i];
2432
- const callback = params[params.length - 1];
2433
-
2434
- if (typeof callback === 'function') callback(err);
2435
- }
2436
-
2517
+ callCallbacks(this, err, cb);
2437
2518
  return;
2438
2519
  }
2439
2520
 
2440
2521
  this._bufferedBytes -= options[kByteLength];
2441
- this._deflating = false;
2522
+ this._state = DEFAULT;
2442
2523
  options.readOnly = false;
2443
2524
  this.sendFrame(Sender.frame(buf, options), cb);
2444
2525
  this.dequeue();
@@ -2451,7 +2532,7 @@ class Sender {
2451
2532
  * @private
2452
2533
  */
2453
2534
  dequeue() {
2454
- while (!this._deflating && this._queue.length) {
2535
+ while (this._state === DEFAULT && this._queue.length) {
2455
2536
  const params = this._queue.shift();
2456
2537
 
2457
2538
  this._bufferedBytes -= params[3][kByteLength];
@@ -2491,16 +2572,48 @@ class Sender {
2491
2572
 
2492
2573
  module.exports = Sender;
2493
2574
 
2575
+ /**
2576
+ * Calls queued callbacks with an error.
2577
+ *
2578
+ * @param {Sender} sender The `Sender` instance
2579
+ * @param {Error} err The error to call the callbacks with
2580
+ * @param {Function} [cb] The first callback
2581
+ * @private
2582
+ */
2583
+ function callCallbacks(sender, err, cb) {
2584
+ if (typeof cb === 'function') cb(err);
2585
+
2586
+ for (let i = 0; i < sender._queue.length; i++) {
2587
+ const params = sender._queue[i];
2588
+ const callback = params[params.length - 1];
2589
+
2590
+ if (typeof callback === 'function') callback(err);
2591
+ }
2592
+ }
2593
+
2594
+ /**
2595
+ * Handles a `Sender` error.
2596
+ *
2597
+ * @param {Sender} sender The `Sender` instance
2598
+ * @param {Error} err The error
2599
+ * @param {Function} [cb] The first pending callback
2600
+ * @private
2601
+ */
2602
+ function onError(sender, err, cb) {
2603
+ callCallbacks(sender, err, cb);
2604
+ sender.onerror(err);
2605
+ }
2606
+
2494
2607
 
2495
2608
  /***/ }),
2496
2609
 
2497
- /***/ 884:
2610
+ /***/ 192:
2498
2611
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2499
2612
 
2500
2613
  "use strict";
2501
2614
 
2502
2615
 
2503
- const { Duplex } = __nccwpck_require__(955);
2616
+ const { Duplex } = __nccwpck_require__(781);
2504
2617
 
2505
2618
  /**
2506
2619
  * Emits the `'close'` event on a stream.
@@ -2661,13 +2774,13 @@ module.exports = createWebSocketStream;
2661
2774
 
2662
2775
  /***/ }),
2663
2776
 
2664
- /***/ 690:
2777
+ /***/ 58:
2665
2778
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2666
2779
 
2667
2780
  "use strict";
2668
2781
 
2669
2782
 
2670
- const { tokenChars } = __nccwpck_require__(502);
2783
+ const { tokenChars } = __nccwpck_require__(444);
2671
2784
 
2672
2785
  /**
2673
2786
  * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
@@ -2731,7 +2844,7 @@ module.exports = { parse };
2731
2844
 
2732
2845
  /***/ }),
2733
2846
 
2734
- /***/ 502:
2847
+ /***/ 444:
2735
2848
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2736
2849
 
2737
2850
  "use strict";
@@ -2739,6 +2852,8 @@ module.exports = { parse };
2739
2852
 
2740
2853
  const { isUtf8 } = __nccwpck_require__(300);
2741
2854
 
2855
+ const { hasBlob } = __nccwpck_require__(870);
2856
+
2742
2857
  //
2743
2858
  // Allowed token characters:
2744
2859
  //
@@ -2844,7 +2959,27 @@ function _isValidUTF8(buf) {
2844
2959
  return true;
2845
2960
  }
2846
2961
 
2962
+ /**
2963
+ * Determines whether a value is a `Blob`.
2964
+ *
2965
+ * @param {*} value The value to be tested
2966
+ * @return {Boolean} `true` if `value` is a `Blob`, else `false`
2967
+ * @private
2968
+ */
2969
+ function isBlob(value) {
2970
+ return (
2971
+ hasBlob &&
2972
+ typeof value === 'object' &&
2973
+ typeof value.arrayBuffer === 'function' &&
2974
+ typeof value.type === 'string' &&
2975
+ typeof value.stream === 'function' &&
2976
+ (value[Symbol.toStringTag] === 'Blob' ||
2977
+ value[Symbol.toStringTag] === 'File')
2978
+ );
2979
+ }
2980
+
2847
2981
  module.exports = {
2982
+ isBlob,
2848
2983
  isValidStatusCode,
2849
2984
  isValidUTF8: _isValidUTF8,
2850
2985
  tokenChars
@@ -2869,7 +3004,7 @@ if (isUtf8) {
2869
3004
 
2870
3005
  /***/ }),
2871
3006
 
2872
- /***/ 120:
3007
+ /***/ 226:
2873
3008
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
2874
3009
 
2875
3010
  "use strict";
@@ -2879,14 +3014,14 @@ if (isUtf8) {
2879
3014
 
2880
3015
  const EventEmitter = __nccwpck_require__(361);
2881
3016
  const http = __nccwpck_require__(685);
2882
- const { Duplex } = __nccwpck_require__(955);
3017
+ const { Duplex } = __nccwpck_require__(781);
2883
3018
  const { createHash } = __nccwpck_require__(113);
2884
3019
 
2885
- const extension = __nccwpck_require__(787);
2886
- const PerMessageDeflate = __nccwpck_require__(262);
2887
- const subprotocol = __nccwpck_require__(690);
2888
- const WebSocket = __nccwpck_require__(715);
2889
- const { GUID, kWebSocket } = __nccwpck_require__(556);
3020
+ const extension = __nccwpck_require__(694);
3021
+ const PerMessageDeflate = __nccwpck_require__(421);
3022
+ const subprotocol = __nccwpck_require__(58);
3023
+ const WebSocket = __nccwpck_require__(227);
3024
+ const { GUID, kWebSocket } = __nccwpck_require__(870);
2890
3025
 
2891
3026
  const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
2892
3027
 
@@ -3417,7 +3552,7 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
3417
3552
 
3418
3553
  /***/ }),
3419
3554
 
3420
- /***/ 715:
3555
+ /***/ 227:
3421
3556
  /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
3422
3557
 
3423
3558
  "use strict";
@@ -3431,12 +3566,14 @@ const http = __nccwpck_require__(685);
3431
3566
  const net = __nccwpck_require__(808);
3432
3567
  const tls = __nccwpck_require__(404);
3433
3568
  const { randomBytes, createHash } = __nccwpck_require__(113);
3434
- const { Duplex, Readable } = __nccwpck_require__(955);
3569
+ const { Duplex, Readable } = __nccwpck_require__(781);
3435
3570
  const { URL } = __nccwpck_require__(310);
3436
3571
 
3437
- const PerMessageDeflate = __nccwpck_require__(262);
3438
- const Receiver = __nccwpck_require__(594);
3439
- const Sender = __nccwpck_require__(209);
3572
+ const PerMessageDeflate = __nccwpck_require__(421);
3573
+ const Receiver = __nccwpck_require__(245);
3574
+ const Sender = __nccwpck_require__(415);
3575
+ const { isBlob } = __nccwpck_require__(444);
3576
+
3440
3577
  const {
3441
3578
  BINARY_TYPES,
3442
3579
  EMPTY_BUFFER,
@@ -3446,12 +3583,12 @@ const {
3446
3583
  kStatusCode,
3447
3584
  kWebSocket,
3448
3585
  NOOP
3449
- } = __nccwpck_require__(556);
3586
+ } = __nccwpck_require__(870);
3450
3587
  const {
3451
3588
  EventTarget: { addEventListener, removeEventListener }
3452
- } = __nccwpck_require__(418);
3453
- const { format, parse } = __nccwpck_require__(787);
3454
- const { toBuffer } = __nccwpck_require__(870);
3589
+ } = __nccwpck_require__(456);
3590
+ const { format, parse } = __nccwpck_require__(694);
3591
+ const { toBuffer } = __nccwpck_require__(198);
3455
3592
 
3456
3593
  const closeTimeout = 30 * 1000;
3457
3594
  const kAborted = Symbol('kAborted');
@@ -3481,6 +3618,7 @@ class WebSocket extends EventEmitter {
3481
3618
  this._closeFrameSent = false;
3482
3619
  this._closeMessage = EMPTY_BUFFER;
3483
3620
  this._closeTimer = null;
3621
+ this._errorEmitted = false;
3484
3622
  this._extensions = {};
3485
3623
  this._paused = false;
3486
3624
  this._protocol = '';
@@ -3513,9 +3651,8 @@ class WebSocket extends EventEmitter {
3513
3651
  }
3514
3652
 
3515
3653
  /**
3516
- * This deviates from the WHATWG interface since ws doesn't support the
3517
- * required default "blob" type (instead we define a custom "nodebuffer"
3518
- * type).
3654
+ * For historical reasons, the custom "nodebuffer" type is used by the default
3655
+ * instead of "blob".
3519
3656
  *
3520
3657
  * @type {String}
3521
3658
  */
@@ -3636,11 +3773,14 @@ class WebSocket extends EventEmitter {
3636
3773
  skipUTF8Validation: options.skipUTF8Validation
3637
3774
  });
3638
3775
 
3639
- this._sender = new Sender(socket, this._extensions, options.generateMask);
3776
+ const sender = new Sender(socket, this._extensions, options.generateMask);
3777
+
3640
3778
  this._receiver = receiver;
3779
+ this._sender = sender;
3641
3780
  this._socket = socket;
3642
3781
 
3643
3782
  receiver[kWebSocket] = this;
3783
+ sender[kWebSocket] = this;
3644
3784
  socket[kWebSocket] = this;
3645
3785
 
3646
3786
  receiver.on('conclude', receiverOnConclude);
@@ -3650,6 +3790,8 @@ class WebSocket extends EventEmitter {
3650
3790
  receiver.on('ping', receiverOnPing);
3651
3791
  receiver.on('pong', receiverOnPong);
3652
3792
 
3793
+ sender.onerror = senderOnError;
3794
+
3653
3795
  //
3654
3796
  // These methods may not be available if `socket` is just a `Duplex`.
3655
3797
  //
@@ -3745,13 +3887,7 @@ class WebSocket extends EventEmitter {
3745
3887
  }
3746
3888
  });
3747
3889
 
3748
- //
3749
- // Specify a timeout for the closing handshake to complete.
3750
- //
3751
- this._closeTimer = setTimeout(
3752
- this._socket.destroy.bind(this._socket),
3753
- closeTimeout
3754
- );
3890
+ setCloseTimer(this);
3755
3891
  }
3756
3892
 
3757
3893
  /**
@@ -4455,6 +4591,11 @@ function initAsClient(websocket, address, protocols, options) {
4455
4591
  */
4456
4592
  function emitErrorAndClose(websocket, err) {
4457
4593
  websocket._readyState = WebSocket.CLOSING;
4594
+ //
4595
+ // The following assignment is practically useless and is done only for
4596
+ // consistency.
4597
+ //
4598
+ websocket._errorEmitted = true;
4458
4599
  websocket.emit('error', err);
4459
4600
  websocket.emitClose();
4460
4601
  }
@@ -4535,7 +4676,7 @@ function abortHandshake(websocket, stream, message) {
4535
4676
  */
4536
4677
  function sendAfterClose(websocket, data, cb) {
4537
4678
  if (data) {
4538
- const length = toBuffer(data).length;
4679
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
4539
4680
 
4540
4681
  //
4541
4682
  // The `_bufferedAmount` property is used only when the peer is a client and
@@ -4611,7 +4752,10 @@ function receiverOnError(err) {
4611
4752
  websocket.close(err[kStatusCode]);
4612
4753
  }
4613
4754
 
4614
- websocket.emit('error', err);
4755
+ if (!websocket._errorEmitted) {
4756
+ websocket._errorEmitted = true;
4757
+ websocket.emit('error', err);
4758
+ }
4615
4759
  }
4616
4760
 
4617
4761
  /**
@@ -4667,6 +4811,47 @@ function resume(stream) {
4667
4811
  stream.resume();
4668
4812
  }
4669
4813
 
4814
+ /**
4815
+ * The `Sender` error event handler.
4816
+ *
4817
+ * @param {Error} The error
4818
+ * @private
4819
+ */
4820
+ function senderOnError(err) {
4821
+ const websocket = this[kWebSocket];
4822
+
4823
+ if (websocket.readyState === WebSocket.CLOSED) return;
4824
+ if (websocket.readyState === WebSocket.OPEN) {
4825
+ websocket._readyState = WebSocket.CLOSING;
4826
+ setCloseTimer(websocket);
4827
+ }
4828
+
4829
+ //
4830
+ // `socket.end()` is used instead of `socket.destroy()` to allow the other
4831
+ // peer to finish sending queued data. There is no need to set a timer here
4832
+ // because `CLOSING` means that it is already set or not needed.
4833
+ //
4834
+ this._socket.end();
4835
+
4836
+ if (!websocket._errorEmitted) {
4837
+ websocket._errorEmitted = true;
4838
+ websocket.emit('error', err);
4839
+ }
4840
+ }
4841
+
4842
+ /**
4843
+ * Set a timer to destroy the underlying raw socket of a WebSocket.
4844
+ *
4845
+ * @param {WebSocket} websocket The WebSocket instance
4846
+ * @private
4847
+ */
4848
+ function setCloseTimer(websocket) {
4849
+ websocket._closeTimer = setTimeout(
4850
+ websocket._socket.destroy.bind(websocket._socket),
4851
+ closeTimeout
4852
+ );
4853
+ }
4854
+
4670
4855
  /**
4671
4856
  * The listener of the socket `'close'` event.
4672
4857
  *
@@ -4827,7 +5012,7 @@ module.exports = require("net");
4827
5012
 
4828
5013
  /***/ }),
4829
5014
 
4830
- /***/ 955:
5015
+ /***/ 781:
4831
5016
  /***/ ((module) => {
4832
5017
 
4833
5018
  "use strict";
@@ -4901,7 +5086,7 @@ module.exports = require("zlib");
4901
5086
  /******/ // startup
4902
5087
  /******/ // Load entry module and return exports
4903
5088
  /******/ // This entry module is referenced by other modules so it can't be inlined
4904
- /******/ var __webpack_exports__ = __nccwpck_require__(781);
5089
+ /******/ var __webpack_exports__ = __nccwpck_require__(749);
4905
5090
  /******/ module.exports = __webpack_exports__;
4906
5091
  /******/
4907
5092
  /******/ })()