@ntlab/ntjs-assets 2.0.3 → 2.0.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,5 +1,5 @@
1
1
  /*!
2
- * Socket.IO v4.7.0
2
+ * Socket.IO v4.7.1
3
3
  * (c) 2014-2023 Guillermo Rauch
4
4
  * Released under the MIT License.
5
5
  */
@@ -18,23 +18,20 @@
18
18
  return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
19
19
  }, _typeof(obj);
20
20
  }
21
-
22
21
  function _classCallCheck(instance, Constructor) {
23
22
  if (!(instance instanceof Constructor)) {
24
23
  throw new TypeError("Cannot call a class as a function");
25
24
  }
26
25
  }
27
-
28
26
  function _defineProperties(target, props) {
29
27
  for (var i = 0; i < props.length; i++) {
30
28
  var descriptor = props[i];
31
29
  descriptor.enumerable = descriptor.enumerable || false;
32
30
  descriptor.configurable = true;
33
31
  if ("value" in descriptor) descriptor.writable = true;
34
- Object.defineProperty(target, descriptor.key, descriptor);
32
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
35
33
  }
36
34
  }
37
-
38
35
  function _createClass(Constructor, protoProps, staticProps) {
39
36
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
40
37
  if (staticProps) _defineProperties(Constructor, staticProps);
@@ -43,29 +40,24 @@
43
40
  });
44
41
  return Constructor;
45
42
  }
46
-
47
43
  function _extends() {
48
44
  _extends = Object.assign ? Object.assign.bind() : function (target) {
49
45
  for (var i = 1; i < arguments.length; i++) {
50
46
  var source = arguments[i];
51
-
52
47
  for (var key in source) {
53
48
  if (Object.prototype.hasOwnProperty.call(source, key)) {
54
49
  target[key] = source[key];
55
50
  }
56
51
  }
57
52
  }
58
-
59
53
  return target;
60
54
  };
61
55
  return _extends.apply(this, arguments);
62
56
  }
63
-
64
57
  function _inherits(subClass, superClass) {
65
58
  if (typeof superClass !== "function" && superClass !== null) {
66
59
  throw new TypeError("Super expression must either be null or a function");
67
60
  }
68
-
69
61
  subClass.prototype = Object.create(superClass && superClass.prototype, {
70
62
  constructor: {
71
63
  value: subClass,
@@ -78,14 +70,12 @@
78
70
  });
79
71
  if (superClass) _setPrototypeOf(subClass, superClass);
80
72
  }
81
-
82
73
  function _getPrototypeOf(o) {
83
74
  _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
84
75
  return o.__proto__ || Object.getPrototypeOf(o);
85
76
  };
86
77
  return _getPrototypeOf(o);
87
78
  }
88
-
89
79
  function _setPrototypeOf(o, p) {
90
80
  _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
91
81
  o.__proto__ = p;
@@ -93,12 +83,10 @@
93
83
  };
94
84
  return _setPrototypeOf(o, p);
95
85
  }
96
-
97
86
  function _isNativeReflectConstruct() {
98
87
  if (typeof Reflect === "undefined" || !Reflect.construct) return false;
99
88
  if (Reflect.construct.sham) return false;
100
89
  if (typeof Proxy === "function") return true;
101
-
102
90
  try {
103
91
  Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
104
92
  return true;
@@ -106,7 +94,6 @@
106
94
  return false;
107
95
  }
108
96
  }
109
-
110
97
  function _construct(Parent, args, Class) {
111
98
  if (_isNativeReflectConstruct()) {
112
99
  _construct = Reflect.construct.bind();
@@ -120,34 +107,25 @@
120
107
  return instance;
121
108
  };
122
109
  }
123
-
124
110
  return _construct.apply(null, arguments);
125
111
  }
126
-
127
112
  function _isNativeFunction(fn) {
128
113
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
129
114
  }
130
-
131
115
  function _wrapNativeSuper(Class) {
132
116
  var _cache = typeof Map === "function" ? new Map() : undefined;
133
-
134
117
  _wrapNativeSuper = function _wrapNativeSuper(Class) {
135
118
  if (Class === null || !_isNativeFunction(Class)) return Class;
136
-
137
119
  if (typeof Class !== "function") {
138
120
  throw new TypeError("Super expression must either be null or a function");
139
121
  }
140
-
141
122
  if (typeof _cache !== "undefined") {
142
123
  if (_cache.has(Class)) return _cache.get(Class);
143
-
144
124
  _cache.set(Class, Wrapper);
145
125
  }
146
-
147
126
  function Wrapper() {
148
127
  return _construct(Class, arguments, _getPrototypeOf(this).constructor);
149
128
  }
150
-
151
129
  Wrapper.prototype = Object.create(Class.prototype, {
152
130
  constructor: {
153
131
  value: Wrapper,
@@ -158,77 +136,59 @@
158
136
  });
159
137
  return _setPrototypeOf(Wrapper, Class);
160
138
  };
161
-
162
139
  return _wrapNativeSuper(Class);
163
140
  }
164
-
165
141
  function _assertThisInitialized(self) {
166
142
  if (self === void 0) {
167
143
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
168
144
  }
169
-
170
145
  return self;
171
146
  }
172
-
173
147
  function _possibleConstructorReturn(self, call) {
174
148
  if (call && (typeof call === "object" || typeof call === "function")) {
175
149
  return call;
176
150
  } else if (call !== void 0) {
177
151
  throw new TypeError("Derived constructors may only return object or undefined");
178
152
  }
179
-
180
153
  return _assertThisInitialized(self);
181
154
  }
182
-
183
155
  function _createSuper(Derived) {
184
156
  var hasNativeReflectConstruct = _isNativeReflectConstruct();
185
-
186
157
  return function _createSuperInternal() {
187
158
  var Super = _getPrototypeOf(Derived),
188
- result;
189
-
159
+ result;
190
160
  if (hasNativeReflectConstruct) {
191
161
  var NewTarget = _getPrototypeOf(this).constructor;
192
-
193
162
  result = Reflect.construct(Super, arguments, NewTarget);
194
163
  } else {
195
164
  result = Super.apply(this, arguments);
196
165
  }
197
-
198
166
  return _possibleConstructorReturn(this, result);
199
167
  };
200
168
  }
201
-
202
169
  function _superPropBase(object, property) {
203
170
  while (!Object.prototype.hasOwnProperty.call(object, property)) {
204
171
  object = _getPrototypeOf(object);
205
172
  if (object === null) break;
206
173
  }
207
-
208
174
  return object;
209
175
  }
210
-
211
176
  function _get() {
212
177
  if (typeof Reflect !== "undefined" && Reflect.get) {
213
178
  _get = Reflect.get.bind();
214
179
  } else {
215
180
  _get = function _get(target, property, receiver) {
216
181
  var base = _superPropBase(target, property);
217
-
218
182
  if (!base) return;
219
183
  var desc = Object.getOwnPropertyDescriptor(base, property);
220
-
221
184
  if (desc.get) {
222
185
  return desc.get.call(arguments.length < 3 ? target : receiver);
223
186
  }
224
-
225
187
  return desc.value;
226
188
  };
227
189
  }
228
-
229
190
  return _get.apply(this, arguments);
230
191
  }
231
-
232
192
  function _unsupportedIterableToArray(o, minLen) {
233
193
  if (!o) return;
234
194
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -237,25 +197,18 @@
237
197
  if (n === "Map" || n === "Set") return Array.from(o);
238
198
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
239
199
  }
240
-
241
200
  function _arrayLikeToArray(arr, len) {
242
201
  if (len == null || len > arr.length) len = arr.length;
243
-
244
202
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
245
-
246
203
  return arr2;
247
204
  }
248
-
249
205
  function _createForOfIteratorHelper(o, allowArrayLike) {
250
206
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
251
-
252
207
  if (!it) {
253
208
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
254
209
  if (it) o = it;
255
210
  var i = 0;
256
-
257
211
  var F = function () {};
258
-
259
212
  return {
260
213
  s: F,
261
214
  n: function () {
@@ -273,13 +226,11 @@
273
226
  f: F
274
227
  };
275
228
  }
276
-
277
229
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
278
230
  }
279
-
280
231
  var normalCompletion = true,
281
- didErr = false,
282
- err;
232
+ didErr = false,
233
+ err;
283
234
  return {
284
235
  s: function () {
285
236
  it = it.call(o);
@@ -302,9 +253,22 @@
302
253
  }
303
254
  };
304
255
  }
256
+ function _toPrimitive(input, hint) {
257
+ if (typeof input !== "object" || input === null) return input;
258
+ var prim = input[Symbol.toPrimitive];
259
+ if (prim !== undefined) {
260
+ var res = prim.call(input, hint || "default");
261
+ if (typeof res !== "object") return res;
262
+ throw new TypeError("@@toPrimitive must return a primitive value.");
263
+ }
264
+ return (hint === "string" ? String : Number)(input);
265
+ }
266
+ function _toPropertyKey(arg) {
267
+ var key = _toPrimitive(arg, "string");
268
+ return typeof key === "symbol" ? key : String(key);
269
+ }
305
270
 
306
271
  var PACKET_TYPES = Object.create(null); // no Map = no polyfill
307
-
308
272
  PACKET_TYPES["open"] = "0";
309
273
  PACKET_TYPES["close"] = "1";
310
274
  PACKET_TYPES["ping"] = "2";
@@ -322,16 +286,14 @@
322
286
  };
323
287
 
324
288
  var withNativeBlob$1 = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
325
- var withNativeArrayBuffer$2 = typeof ArrayBuffer === "function"; // ArrayBuffer.isView method is not defined in IE10
326
-
289
+ var withNativeArrayBuffer$2 = typeof ArrayBuffer === "function";
290
+ // ArrayBuffer.isView method is not defined in IE10
327
291
  var isView$1 = function isView(obj) {
328
292
  return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
329
293
  };
330
-
331
294
  var encodePacket = function encodePacket(_ref, supportsBinary, callback) {
332
295
  var type = _ref.type,
333
- data = _ref.data;
334
-
296
+ data = _ref.data;
335
297
  if (withNativeBlob$1 && data instanceof Blob) {
336
298
  if (supportsBinary) {
337
299
  return callback(data);
@@ -344,23 +306,18 @@
344
306
  } else {
345
307
  return encodeBlobAsBase64(new Blob([data]), callback);
346
308
  }
347
- } // plain string
348
-
349
-
309
+ }
310
+ // plain string
350
311
  return callback(PACKET_TYPES[type] + (data || ""));
351
312
  };
352
-
353
313
  var encodeBlobAsBase64 = function encodeBlobAsBase64(data, callback) {
354
314
  var fileReader = new FileReader();
355
-
356
315
  fileReader.onload = function () {
357
316
  var content = fileReader.result.split(",")[1];
358
317
  callback("b" + (content || ""));
359
318
  };
360
-
361
319
  return fileReader.readAsDataURL(data);
362
320
  };
363
-
364
321
  function toArray(data) {
365
322
  if (data instanceof Uint8Array) {
366
323
  return data;
@@ -370,7 +327,6 @@
370
327
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
371
328
  }
372
329
  }
373
-
374
330
  var TEXT_ENCODER;
375
331
  function encodePacketToBinary(packet, callback) {
376
332
  if (withNativeBlob$1 && packet.data instanceof Blob) {
@@ -378,45 +334,38 @@
378
334
  } else if (withNativeArrayBuffer$2 && (packet.data instanceof ArrayBuffer || isView$1(packet.data))) {
379
335
  return callback(toArray(packet.data));
380
336
  }
381
-
382
337
  encodePacket(packet, false, function (encoded) {
383
338
  if (!TEXT_ENCODER) {
384
339
  TEXT_ENCODER = new TextEncoder();
385
340
  }
386
-
387
341
  callback(TEXT_ENCODER.encode(encoded));
388
342
  });
389
343
  }
390
344
 
391
345
  // imported from https://github.com/socketio/base64-arraybuffer
392
- var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index.
393
-
346
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
347
+ // Use a lookup table to find the index.
394
348
  var lookup$1 = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
395
-
396
349
  for (var i$1 = 0; i$1 < chars.length; i$1++) {
397
350
  lookup$1[chars.charCodeAt(i$1)] = i$1;
398
351
  }
399
352
  var decode$1 = function decode(base64) {
400
353
  var bufferLength = base64.length * 0.75,
401
- len = base64.length,
402
- i,
403
- p = 0,
404
- encoded1,
405
- encoded2,
406
- encoded3,
407
- encoded4;
408
-
354
+ len = base64.length,
355
+ i,
356
+ p = 0,
357
+ encoded1,
358
+ encoded2,
359
+ encoded3,
360
+ encoded4;
409
361
  if (base64[base64.length - 1] === '=') {
410
362
  bufferLength--;
411
-
412
363
  if (base64[base64.length - 2] === '=') {
413
364
  bufferLength--;
414
365
  }
415
366
  }
416
-
417
367
  var arraybuffer = new ArrayBuffer(bufferLength),
418
- bytes = new Uint8Array(arraybuffer);
419
-
368
+ bytes = new Uint8Array(arraybuffer);
420
369
  for (i = 0; i < len; i += 4) {
421
370
  encoded1 = lookup$1[base64.charCodeAt(i)];
422
371
  encoded2 = lookup$1[base64.charCodeAt(i + 1)];
@@ -426,7 +375,6 @@
426
375
  bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
427
376
  bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
428
377
  }
429
-
430
378
  return arraybuffer;
431
379
  };
432
380
 
@@ -438,22 +386,17 @@
438
386
  data: mapBinary(encodedPacket, binaryType)
439
387
  };
440
388
  }
441
-
442
389
  var type = encodedPacket.charAt(0);
443
-
444
390
  if (type === "b") {
445
391
  return {
446
392
  type: "message",
447
393
  data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
448
394
  };
449
395
  }
450
-
451
396
  var packetType = PACKET_TYPES_REVERSE[type];
452
-
453
397
  if (!packetType) {
454
398
  return ERROR_PACKET;
455
399
  }
456
-
457
400
  return encodedPacket.length > 1 ? {
458
401
  type: PACKET_TYPES_REVERSE[type],
459
402
  data: encodedPacket.substring(1)
@@ -461,7 +404,6 @@
461
404
  type: PACKET_TYPES_REVERSE[type]
462
405
  };
463
406
  };
464
-
465
407
  var decodeBase64Packet = function decodeBase64Packet(data, binaryType) {
466
408
  if (withNativeArrayBuffer$1) {
467
409
  var decoded = decode$1(data);
@@ -484,7 +426,6 @@
484
426
  // from HTTP long-polling or WebTransport
485
427
  return new Blob([data]);
486
428
  }
487
-
488
429
  case "arraybuffer":
489
430
  default:
490
431
  if (data instanceof ArrayBuffer) {
@@ -494,12 +435,10 @@
494
435
  // from WebTransport (Uint8Array)
495
436
  return data.buffer;
496
437
  }
497
-
498
438
  }
499
439
  };
500
440
 
501
441
  var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
502
-
503
442
  var encodePayload = function encodePayload(packets, callback) {
504
443
  // some packets may be added to the array while encoding, so the initial length must be saved
505
444
  var length = packets.length;
@@ -509,39 +448,32 @@
509
448
  // force base64 encoding for binary packets
510
449
  encodePacket(packet, false, function (encodedPacket) {
511
450
  encodedPackets[i] = encodedPacket;
512
-
513
451
  if (++count === length) {
514
452
  callback(encodedPackets.join(SEPARATOR));
515
453
  }
516
454
  });
517
455
  });
518
456
  };
519
-
520
457
  var decodePayload = function decodePayload(encodedPayload, binaryType) {
521
458
  var encodedPackets = encodedPayload.split(SEPARATOR);
522
459
  var packets = [];
523
-
524
460
  for (var i = 0; i < encodedPackets.length; i++) {
525
461
  var decodedPacket = decodePacket(encodedPackets[i], binaryType);
526
462
  packets.push(decodedPacket);
527
-
528
463
  if (decodedPacket.type === "error") {
529
464
  break;
530
465
  }
531
466
  }
532
-
533
467
  return packets;
534
468
  };
535
-
536
469
  var TEXT_DECODER;
537
470
  function decodePacketFromBinary(data, isBinary, binaryType) {
538
471
  if (!TEXT_DECODER) {
539
472
  // lazily created for compatibility with old browser platforms
540
473
  TEXT_DECODER = new TextDecoder();
541
- } // 48 === "0".charCodeAt(0) (OPEN packet type)
474
+ }
475
+ // 48 === "0".charCodeAt(0) (OPEN packet type)
542
476
  // 54 === "6".charCodeAt(0) (NOOP packet type)
543
-
544
-
545
477
  var isPlainBinary = isBinary || data[0] < 48 || data[0] > 54;
546
478
  return decodePacket(isPlainBinary ? data : TEXT_DECODER.decode(data), binaryType);
547
479
  }
@@ -552,9 +484,11 @@
552
484
  *
553
485
  * @api public
554
486
  */
487
+
555
488
  function Emitter(obj) {
556
489
  if (obj) return mixin(obj);
557
490
  }
491
+
558
492
  /**
559
493
  * Mixin the emitter properties.
560
494
  *
@@ -567,9 +501,9 @@
567
501
  for (var key in Emitter.prototype) {
568
502
  obj[key] = Emitter.prototype[key];
569
503
  }
570
-
571
504
  return obj;
572
505
  }
506
+
573
507
  /**
574
508
  * Listen on the given `event` with `fn`.
575
509
  *
@@ -579,12 +513,12 @@
579
513
  * @api public
580
514
  */
581
515
 
582
-
583
516
  Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
584
517
  this._callbacks = this._callbacks || {};
585
518
  (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
586
519
  return this;
587
520
  };
521
+
588
522
  /**
589
523
  * Adds an `event` listener that will be invoked a single
590
524
  * time then automatically removed.
@@ -595,17 +529,16 @@
595
529
  * @api public
596
530
  */
597
531
 
598
-
599
532
  Emitter.prototype.once = function (event, fn) {
600
533
  function on() {
601
534
  this.off(event, on);
602
535
  fn.apply(this, arguments);
603
536
  }
604
-
605
537
  on.fn = fn;
606
538
  this.on(event, on);
607
539
  return this;
608
540
  };
541
+
609
542
  /**
610
543
  * Remove the given callback for `event` or all
611
544
  * registered callbacks.
@@ -616,44 +549,43 @@
616
549
  * @api public
617
550
  */
618
551
 
619
-
620
552
  Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
621
- this._callbacks = this._callbacks || {}; // all
553
+ this._callbacks = this._callbacks || {};
622
554
 
555
+ // all
623
556
  if (0 == arguments.length) {
624
557
  this._callbacks = {};
625
558
  return this;
626
- } // specific event
627
-
559
+ }
628
560
 
561
+ // specific event
629
562
  var callbacks = this._callbacks['$' + event];
630
- if (!callbacks) return this; // remove all handlers
563
+ if (!callbacks) return this;
631
564
 
565
+ // remove all handlers
632
566
  if (1 == arguments.length) {
633
567
  delete this._callbacks['$' + event];
634
568
  return this;
635
- } // remove specific handler
636
-
569
+ }
637
570
 
571
+ // remove specific handler
638
572
  var cb;
639
-
640
573
  for (var i = 0; i < callbacks.length; i++) {
641
574
  cb = callbacks[i];
642
-
643
575
  if (cb === fn || cb.fn === fn) {
644
576
  callbacks.splice(i, 1);
645
577
  break;
646
578
  }
647
- } // Remove event specific arrays for event types that no
648
- // one is subscribed for to avoid memory leak.
649
-
579
+ }
650
580
 
581
+ // Remove event specific arrays for event types that no
582
+ // one is subscribed for to avoid memory leak.
651
583
  if (callbacks.length === 0) {
652
584
  delete this._callbacks['$' + event];
653
585
  }
654
-
655
586
  return this;
656
587
  };
588
+
657
589
  /**
658
590
  * Emit `event` with the given args.
659
591
  *
@@ -662,29 +594,25 @@
662
594
  * @return {Emitter}
663
595
  */
664
596
 
665
-
666
597
  Emitter.prototype.emit = function (event) {
667
598
  this._callbacks = this._callbacks || {};
668
599
  var args = new Array(arguments.length - 1),
669
- callbacks = this._callbacks['$' + event];
670
-
600
+ callbacks = this._callbacks['$' + event];
671
601
  for (var i = 1; i < arguments.length; i++) {
672
602
  args[i - 1] = arguments[i];
673
603
  }
674
-
675
604
  if (callbacks) {
676
605
  callbacks = callbacks.slice(0);
677
-
678
606
  for (var i = 0, len = callbacks.length; i < len; ++i) {
679
607
  callbacks[i].apply(this, args);
680
608
  }
681
609
  }
682
-
683
610
  return this;
684
- }; // alias used for reserved events (protected method)
685
-
611
+ };
686
612
 
613
+ // alias used for reserved events (protected method)
687
614
  Emitter.prototype.emitReserved = Emitter.prototype.emit;
615
+
688
616
  /**
689
617
  * Return array of callbacks for `event`.
690
618
  *
@@ -697,6 +625,7 @@
697
625
  this._callbacks = this._callbacks || {};
698
626
  return this._callbacks['$' + event] || [];
699
627
  };
628
+
700
629
  /**
701
630
  * Check if this emitter has `event` handlers.
702
631
  *
@@ -705,7 +634,6 @@
705
634
  * @api public
706
635
  */
707
636
 
708
-
709
637
  Emitter.prototype.hasListeners = function (event) {
710
638
  return !!this.listeners(event).length;
711
639
  };
@@ -724,16 +652,14 @@
724
652
  for (var _len = arguments.length, attr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
725
653
  attr[_key - 1] = arguments[_key];
726
654
  }
727
-
728
655
  return attr.reduce(function (acc, k) {
729
656
  if (obj.hasOwnProperty(k)) {
730
657
  acc[k] = obj[k];
731
658
  }
732
-
733
659
  return acc;
734
660
  }, {});
735
- } // Keep a reference to the real timeout functions so they can be used when overridden
736
-
661
+ }
662
+ // Keep a reference to the real timeout functions so they can be used when overridden
737
663
  var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
738
664
  var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
739
665
  function installTimerFunctions(obj, opts) {
@@ -744,26 +670,22 @@
744
670
  obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
745
671
  obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
746
672
  }
747
- } // base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
748
-
749
- var BASE64_OVERHEAD = 1.33; // we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
750
-
673
+ }
674
+ // base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
675
+ var BASE64_OVERHEAD = 1.33;
676
+ // we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
751
677
  function byteLength(obj) {
752
678
  if (typeof obj === "string") {
753
679
  return utf8Length(obj);
754
- } // arraybuffer or blob
755
-
756
-
680
+ }
681
+ // arraybuffer or blob
757
682
  return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
758
683
  }
759
-
760
684
  function utf8Length(str) {
761
685
  var c = 0,
762
- length = 0;
763
-
686
+ length = 0;
764
687
  for (var i = 0, l = str.length; i < l; i++) {
765
688
  c = str.charCodeAt(i);
766
-
767
689
  if (c < 0x80) {
768
690
  length += 1;
769
691
  } else if (c < 0x800) {
@@ -775,12 +697,10 @@
775
697
  length += 4;
776
698
  }
777
699
  }
778
-
779
700
  return length;
780
701
  }
781
702
 
782
703
  // imported from https://github.com/galkn/querystring
783
-
784
704
  /**
785
705
  * Compiles a querystring
786
706
  * Returns string representation of the object
@@ -790,14 +710,12 @@
790
710
  */
791
711
  function encode$1(obj) {
792
712
  var str = '';
793
-
794
713
  for (var i in obj) {
795
714
  if (obj.hasOwnProperty(i)) {
796
715
  if (str.length) str += '&';
797
716
  str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
798
717
  }
799
718
  }
800
-
801
719
  return str;
802
720
  }
803
721
  /**
@@ -806,44 +724,33 @@
806
724
  * @param {String} qs
807
725
  * @api private
808
726
  */
809
-
810
727
  function decode(qs) {
811
728
  var qry = {};
812
729
  var pairs = qs.split('&');
813
-
814
730
  for (var i = 0, l = pairs.length; i < l; i++) {
815
731
  var pair = pairs[i].split('=');
816
732
  qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
817
733
  }
818
-
819
734
  return qry;
820
735
  }
821
736
 
822
737
  var TransportError = /*#__PURE__*/function (_Error) {
823
738
  _inherits(TransportError, _Error);
824
-
825
739
  var _super = _createSuper(TransportError);
826
-
827
740
  function TransportError(reason, description, context) {
828
741
  var _this;
829
-
830
742
  _classCallCheck(this, TransportError);
831
-
832
743
  _this = _super.call(this, reason);
833
744
  _this.description = description;
834
745
  _this.context = context;
835
746
  _this.type = "TransportError";
836
747
  return _this;
837
748
  }
838
-
839
749
  return _createClass(TransportError);
840
750
  }( /*#__PURE__*/_wrapNativeSuper(Error));
841
-
842
751
  var Transport = /*#__PURE__*/function (_Emitter) {
843
752
  _inherits(Transport, _Emitter);
844
-
845
753
  var _super2 = _createSuper(Transport);
846
-
847
754
  /**
848
755
  * Transport abstract constructor.
849
756
  *
@@ -852,9 +759,7 @@
852
759
  */
853
760
  function Transport(opts) {
854
761
  var _this2;
855
-
856
762
  _classCallCheck(this, Transport);
857
-
858
763
  _this2 = _super2.call(this);
859
764
  _this2.writable = false;
860
765
  installTimerFunctions(_assertThisInitialized(_this2), opts);
@@ -872,19 +777,15 @@
872
777
  * @return {Transport} for chaining
873
778
  * @protected
874
779
  */
875
-
876
-
877
780
  _createClass(Transport, [{
878
781
  key: "onError",
879
782
  value: function onError(reason, description, context) {
880
783
  _get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "error", new TransportError(reason, description, context));
881
-
882
784
  return this;
883
785
  }
884
786
  /**
885
787
  * Opens the transport.
886
788
  */
887
-
888
789
  }, {
889
790
  key: "open",
890
791
  value: function open() {
@@ -895,7 +796,6 @@
895
796
  /**
896
797
  * Closes the transport.
897
798
  */
898
-
899
799
  }, {
900
800
  key: "close",
901
801
  value: function close() {
@@ -903,7 +803,6 @@
903
803
  this.doClose();
904
804
  this.onClose();
905
805
  }
906
-
907
806
  return this;
908
807
  }
909
808
  /**
@@ -911,7 +810,6 @@
911
810
  *
912
811
  * @param {Array} packets
913
812
  */
914
-
915
813
  }, {
916
814
  key: "send",
917
815
  value: function send(packets) {
@@ -924,13 +822,11 @@
924
822
  *
925
823
  * @protected
926
824
  */
927
-
928
825
  }, {
929
826
  key: "onOpen",
930
827
  value: function onOpen() {
931
828
  this.readyState = "open";
932
829
  this.writable = true;
933
-
934
830
  _get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "open");
935
831
  }
936
832
  /**
@@ -939,7 +835,6 @@
939
835
  * @param {String} data
940
836
  * @protected
941
837
  */
942
-
943
838
  }, {
944
839
  key: "onData",
945
840
  value: function onData(data) {
@@ -951,7 +846,6 @@
951
846
  *
952
847
  * @protected
953
848
  */
954
-
955
849
  }, {
956
850
  key: "onPacket",
957
851
  value: function onPacket(packet) {
@@ -962,12 +856,10 @@
962
856
  *
963
857
  * @protected
964
858
  */
965
-
966
859
  }, {
967
860
  key: "onClose",
968
861
  value: function onClose(details) {
969
862
  this.readyState = "closed";
970
-
971
863
  _get(_getPrototypeOf(Transport.prototype), "emitReserved", this).call(this, "close", details);
972
864
  }
973
865
  /**
@@ -975,7 +867,6 @@
975
867
  *
976
868
  * @param onPause
977
869
  */
978
-
979
870
  }, {
980
871
  key: "pause",
981
872
  value: function pause(onPause) {}
@@ -1007,18 +898,17 @@
1007
898
  return encodedQuery.length ? "?" + encodedQuery : "";
1008
899
  }
1009
900
  }]);
1010
-
1011
901
  return Transport;
1012
902
  }(Emitter);
1013
903
 
1014
904
  // imported from https://github.com/unshiftio/yeast
1015
905
 
1016
906
  var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''),
1017
- length = 64,
1018
- map = {};
907
+ length = 64,
908
+ map = {};
1019
909
  var seed = 0,
1020
- i = 0,
1021
- prev;
910
+ i = 0,
911
+ prev;
1022
912
  /**
1023
913
  * Return a string representing the specified number.
1024
914
  *
@@ -1026,15 +916,12 @@
1026
916
  * @returns {String} The string representation of the number.
1027
917
  * @api public
1028
918
  */
1029
-
1030
919
  function encode(num) {
1031
920
  var encoded = '';
1032
-
1033
921
  do {
1034
922
  encoded = alphabet[num % length] + encoded;
1035
923
  num = Math.floor(num / length);
1036
924
  } while (num > 0);
1037
-
1038
925
  return encoded;
1039
926
  }
1040
927
  /**
@@ -1043,40 +930,35 @@
1043
930
  * @returns {String} A unique id.
1044
931
  * @api public
1045
932
  */
1046
-
1047
933
  function yeast() {
1048
934
  var now = encode(+new Date());
1049
935
  if (now !== prev) return seed = 0, prev = now;
1050
936
  return now + '.' + encode(seed++);
1051
- } //
937
+ }
938
+ //
1052
939
  // Map each character to its index.
1053
940
  //
1054
-
1055
- for (; i < length; i++) {
1056
- map[alphabet[i]] = i;
1057
- }
941
+ for (; i < length; i++) map[alphabet[i]] = i;
1058
942
 
1059
943
  // imported from https://github.com/component/has-cors
1060
944
  var value = false;
1061
-
1062
945
  try {
1063
946
  value = typeof XMLHttpRequest !== 'undefined' && 'withCredentials' in new XMLHttpRequest();
1064
- } catch (err) {// if XMLHttp support is disabled in IE then it will throw
947
+ } catch (err) {
948
+ // if XMLHttp support is disabled in IE then it will throw
1065
949
  // when trying to create
1066
950
  }
1067
-
1068
951
  var hasCORS = value;
1069
952
 
1070
953
  // browser shim for xmlhttprequest module
1071
954
  function XHR(opts) {
1072
- var xdomain = opts.xdomain; // XMLHttpRequest can be disabled on IE
1073
-
955
+ var xdomain = opts.xdomain;
956
+ // XMLHttpRequest can be disabled on IE
1074
957
  try {
1075
958
  if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
1076
959
  return new XMLHttpRequest();
1077
960
  }
1078
961
  } catch (e) {}
1079
-
1080
962
  if (!xdomain) {
1081
963
  try {
1082
964
  return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
@@ -1086,19 +968,15 @@
1086
968
  function createCookieJar() {}
1087
969
 
1088
970
  function empty() {}
1089
-
1090
971
  var hasXHR2 = function () {
1091
972
  var xhr = new XHR({
1092
973
  xdomain: false
1093
974
  });
1094
975
  return null != xhr.responseType;
1095
976
  }();
1096
-
1097
977
  var Polling = /*#__PURE__*/function (_Transport) {
1098
978
  _inherits(Polling, _Transport);
1099
-
1100
979
  var _super = _createSuper(Polling);
1101
-
1102
980
  /**
1103
981
  * XHR Polling constructor.
1104
982
  *
@@ -1107,37 +985,28 @@
1107
985
  */
1108
986
  function Polling(opts) {
1109
987
  var _this;
1110
-
1111
988
  _classCallCheck(this, Polling);
1112
-
1113
989
  _this = _super.call(this, opts);
1114
990
  _this.polling = false;
1115
-
1116
991
  if (typeof location !== "undefined") {
1117
992
  var isSSL = "https:" === location.protocol;
1118
- var port = location.port; // some user agents have empty `location.port`
1119
-
993
+ var port = location.port;
994
+ // some user agents have empty `location.port`
1120
995
  if (!port) {
1121
996
  port = isSSL ? "443" : "80";
1122
997
  }
1123
-
1124
998
  _this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
1125
999
  }
1126
1000
  /**
1127
1001
  * XHR supports binary
1128
1002
  */
1129
-
1130
-
1131
1003
  var forceBase64 = opts && opts.forceBase64;
1132
1004
  _this.supportsBinary = hasXHR2 && !forceBase64;
1133
-
1134
1005
  if (_this.opts.withCredentials) {
1135
1006
  _this.cookieJar = createCookieJar();
1136
1007
  }
1137
-
1138
1008
  return _this;
1139
1009
  }
1140
-
1141
1010
  _createClass(Polling, [{
1142
1011
  key: "name",
1143
1012
  get: function get() {
@@ -1149,7 +1018,6 @@
1149
1018
  *
1150
1019
  * @protected
1151
1020
  */
1152
-
1153
1021
  }, {
1154
1022
  key: "doOpen",
1155
1023
  value: function doOpen() {
@@ -1161,29 +1029,23 @@
1161
1029
  * @param {Function} onPause - callback upon buffers are flushed and transport is paused
1162
1030
  * @package
1163
1031
  */
1164
-
1165
1032
  }, {
1166
1033
  key: "pause",
1167
1034
  value: function pause(onPause) {
1168
1035
  var _this2 = this;
1169
-
1170
1036
  this.readyState = "pausing";
1171
-
1172
1037
  var pause = function pause() {
1173
1038
  _this2.readyState = "paused";
1174
1039
  onPause();
1175
1040
  };
1176
-
1177
1041
  if (this.polling || !this.writable) {
1178
1042
  var total = 0;
1179
-
1180
1043
  if (this.polling) {
1181
1044
  total++;
1182
1045
  this.once("pollComplete", function () {
1183
1046
  --total || pause();
1184
1047
  });
1185
1048
  }
1186
-
1187
1049
  if (!this.writable) {
1188
1050
  total++;
1189
1051
  this.once("drain", function () {
@@ -1199,7 +1061,6 @@
1199
1061
  *
1200
1062
  * @private
1201
1063
  */
1202
-
1203
1064
  }, {
1204
1065
  key: "poll",
1205
1066
  value: function poll() {
@@ -1212,39 +1073,32 @@
1212
1073
  *
1213
1074
  * @protected
1214
1075
  */
1215
-
1216
1076
  }, {
1217
1077
  key: "onData",
1218
1078
  value: function onData(data) {
1219
1079
  var _this3 = this;
1220
-
1221
1080
  var callback = function callback(packet) {
1222
1081
  // if its the first message we consider the transport open
1223
1082
  if ("opening" === _this3.readyState && packet.type === "open") {
1224
1083
  _this3.onOpen();
1225
- } // if its a close packet, we close the ongoing requests
1226
-
1227
-
1084
+ }
1085
+ // if its a close packet, we close the ongoing requests
1228
1086
  if ("close" === packet.type) {
1229
1087
  _this3.onClose({
1230
1088
  description: "transport closed by the server"
1231
1089
  });
1232
-
1233
1090
  return false;
1234
- } // otherwise bypass onData and handle the message
1235
-
1236
-
1091
+ }
1092
+ // otherwise bypass onData and handle the message
1237
1093
  _this3.onPacket(packet);
1238
- }; // decode payload
1239
-
1240
-
1241
- decodePayload(data, this.socket.binaryType).forEach(callback); // if an event did not trigger closing
1242
-
1094
+ };
1095
+ // decode payload
1096
+ decodePayload(data, this.socket.binaryType).forEach(callback);
1097
+ // if an event did not trigger closing
1243
1098
  if ("closed" !== this.readyState) {
1244
1099
  // if we got data we're not polling
1245
1100
  this.polling = false;
1246
1101
  this.emitReserved("pollComplete");
1247
-
1248
1102
  if ("open" === this.readyState) {
1249
1103
  this.poll();
1250
1104
  }
@@ -1255,18 +1109,15 @@
1255
1109
  *
1256
1110
  * @protected
1257
1111
  */
1258
-
1259
1112
  }, {
1260
1113
  key: "doClose",
1261
1114
  value: function doClose() {
1262
1115
  var _this4 = this;
1263
-
1264
1116
  var close = function close() {
1265
1117
  _this4.write([{
1266
1118
  type: "close"
1267
1119
  }]);
1268
1120
  };
1269
-
1270
1121
  if ("open" === this.readyState) {
1271
1122
  close();
1272
1123
  } else {
@@ -1281,17 +1132,14 @@
1281
1132
  * @param {Array} packets - data packets
1282
1133
  * @protected
1283
1134
  */
1284
-
1285
1135
  }, {
1286
1136
  key: "write",
1287
1137
  value: function write(packets) {
1288
1138
  var _this5 = this;
1289
-
1290
1139
  this.writable = false;
1291
1140
  encodePayload(packets, function (data) {
1292
1141
  _this5.doWrite(data, function () {
1293
1142
  _this5.writable = true;
1294
-
1295
1143
  _this5.emitReserved("drain");
1296
1144
  });
1297
1145
  });
@@ -1301,21 +1149,18 @@
1301
1149
  *
1302
1150
  * @private
1303
1151
  */
1304
-
1305
1152
  }, {
1306
1153
  key: "uri",
1307
1154
  value: function uri() {
1308
1155
  var schema = this.opts.secure ? "https" : "http";
1309
- var query = this.query || {}; // cache busting is forced
1310
-
1156
+ var query = this.query || {};
1157
+ // cache busting is forced
1311
1158
  if (false !== this.opts.timestampRequests) {
1312
1159
  query[this.opts.timestampParam] = yeast();
1313
1160
  }
1314
-
1315
1161
  if (!this.supportsBinary && !query.sid) {
1316
1162
  query.b64 = 1;
1317
1163
  }
1318
-
1319
1164
  return this.createUri(schema, query);
1320
1165
  }
1321
1166
  /**
@@ -1324,17 +1169,14 @@
1324
1169
  * @param {String} method
1325
1170
  * @private
1326
1171
  */
1327
-
1328
1172
  }, {
1329
1173
  key: "request",
1330
1174
  value: function request() {
1331
1175
  var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1332
-
1333
1176
  _extends(opts, {
1334
1177
  xd: this.xd,
1335
1178
  cookieJar: this.cookieJar
1336
1179
  }, this.opts);
1337
-
1338
1180
  return new Request(this.uri(), opts);
1339
1181
  }
1340
1182
  /**
@@ -1344,12 +1186,10 @@
1344
1186
  * @param {Function} called upon flush.
1345
1187
  * @private
1346
1188
  */
1347
-
1348
1189
  }, {
1349
1190
  key: "doWrite",
1350
1191
  value: function doWrite(data, fn) {
1351
1192
  var _this6 = this;
1352
-
1353
1193
  var req = this.request({
1354
1194
  method: "POST",
1355
1195
  data: data
@@ -1364,12 +1204,10 @@
1364
1204
  *
1365
1205
  * @private
1366
1206
  */
1367
-
1368
1207
  }, {
1369
1208
  key: "doPoll",
1370
1209
  value: function doPoll() {
1371
1210
  var _this7 = this;
1372
-
1373
1211
  var req = this.request();
1374
1212
  req.on("data", this.onData.bind(this));
1375
1213
  req.on("error", function (xhrStatus, context) {
@@ -1378,14 +1216,11 @@
1378
1216
  this.pollXhr = req;
1379
1217
  }
1380
1218
  }]);
1381
-
1382
1219
  return Polling;
1383
1220
  }(Transport);
1384
1221
  var Request = /*#__PURE__*/function (_Emitter) {
1385
1222
  _inherits(Request, _Emitter);
1386
-
1387
1223
  var _super2 = _createSuper(Request);
1388
-
1389
1224
  /**
1390
1225
  * Request constructor
1391
1226
  *
@@ -1394,18 +1229,14 @@
1394
1229
  */
1395
1230
  function Request(uri, opts) {
1396
1231
  var _this8;
1397
-
1398
1232
  _classCallCheck(this, Request);
1399
-
1400
1233
  _this8 = _super2.call(this);
1401
1234
  installTimerFunctions(_assertThisInitialized(_this8), opts);
1402
1235
  _this8.opts = opts;
1403
1236
  _this8.method = opts.method || "GET";
1404
1237
  _this8.uri = uri;
1405
1238
  _this8.data = undefined !== opts.data ? opts.data : null;
1406
-
1407
1239
  _this8.create();
1408
-
1409
1240
  return _this8;
1410
1241
  }
1411
1242
  /**
@@ -1413,26 +1244,19 @@
1413
1244
  *
1414
1245
  * @private
1415
1246
  */
1416
-
1417
-
1418
1247
  _createClass(Request, [{
1419
1248
  key: "create",
1420
1249
  value: function create() {
1421
1250
  var _this9 = this;
1422
-
1423
1251
  var _a;
1424
-
1425
1252
  var opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
1426
1253
  opts.xdomain = !!this.opts.xd;
1427
1254
  var xhr = this.xhr = new XHR(opts);
1428
-
1429
1255
  try {
1430
1256
  xhr.open(this.method, this.uri, true);
1431
-
1432
1257
  try {
1433
1258
  if (this.opts.extraHeaders) {
1434
1259
  xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
1435
-
1436
1260
  for (var i in this.opts.extraHeaders) {
1437
1261
  if (this.opts.extraHeaders.hasOwnProperty(i)) {
1438
1262
  xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
@@ -1440,36 +1264,28 @@
1440
1264
  }
1441
1265
  }
1442
1266
  } catch (e) {}
1443
-
1444
1267
  if ("POST" === this.method) {
1445
1268
  try {
1446
1269
  xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
1447
1270
  } catch (e) {}
1448
1271
  }
1449
-
1450
1272
  try {
1451
1273
  xhr.setRequestHeader("Accept", "*/*");
1452
1274
  } catch (e) {}
1453
-
1454
- (_a = this.opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr); // ie6 check
1455
-
1275
+ (_a = this.opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
1276
+ // ie6 check
1456
1277
  if ("withCredentials" in xhr) {
1457
1278
  xhr.withCredentials = this.opts.withCredentials;
1458
1279
  }
1459
-
1460
1280
  if (this.opts.requestTimeout) {
1461
1281
  xhr.timeout = this.opts.requestTimeout;
1462
1282
  }
1463
-
1464
1283
  xhr.onreadystatechange = function () {
1465
1284
  var _a;
1466
-
1467
1285
  if (xhr.readyState === 3) {
1468
1286
  (_a = _this9.opts.cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(xhr);
1469
1287
  }
1470
-
1471
1288
  if (4 !== xhr.readyState) return;
1472
-
1473
1289
  if (200 === xhr.status || 1223 === xhr.status) {
1474
1290
  _this9.onLoad();
1475
1291
  } else {
@@ -1480,7 +1296,6 @@
1480
1296
  }, 0);
1481
1297
  }
1482
1298
  };
1483
-
1484
1299
  xhr.send(this.data);
1485
1300
  } catch (e) {
1486
1301
  // Need to defer since .create() is called directly from the constructor
@@ -1491,7 +1306,6 @@
1491
1306
  }, 0);
1492
1307
  return;
1493
1308
  }
1494
-
1495
1309
  if (typeof document !== "undefined") {
1496
1310
  this.index = Request.requestsCount++;
1497
1311
  Request.requests[this.index] = this;
@@ -1502,7 +1316,6 @@
1502
1316
  *
1503
1317
  * @private
1504
1318
  */
1505
-
1506
1319
  }, {
1507
1320
  key: "onError",
1508
1321
  value: function onError(err) {
@@ -1514,26 +1327,21 @@
1514
1327
  *
1515
1328
  * @private
1516
1329
  */
1517
-
1518
1330
  }, {
1519
1331
  key: "cleanup",
1520
1332
  value: function cleanup(fromError) {
1521
1333
  if ("undefined" === typeof this.xhr || null === this.xhr) {
1522
1334
  return;
1523
1335
  }
1524
-
1525
1336
  this.xhr.onreadystatechange = empty;
1526
-
1527
1337
  if (fromError) {
1528
1338
  try {
1529
1339
  this.xhr.abort();
1530
1340
  } catch (e) {}
1531
1341
  }
1532
-
1533
1342
  if (typeof document !== "undefined") {
1534
1343
  delete Request.requests[this.index];
1535
1344
  }
1536
-
1537
1345
  this.xhr = null;
1538
1346
  }
1539
1347
  /**
@@ -1541,12 +1349,10 @@
1541
1349
  *
1542
1350
  * @private
1543
1351
  */
1544
-
1545
1352
  }, {
1546
1353
  key: "onLoad",
1547
1354
  value: function onLoad() {
1548
1355
  var data = this.xhr.responseText;
1549
-
1550
1356
  if (data !== null) {
1551
1357
  this.emitReserved("data", data);
1552
1358
  this.emitReserved("success");
@@ -1558,14 +1364,12 @@
1558
1364
  *
1559
1365
  * @package
1560
1366
  */
1561
-
1562
1367
  }, {
1563
1368
  key: "abort",
1564
1369
  value: function abort() {
1565
1370
  this.cleanup();
1566
1371
  }
1567
1372
  }]);
1568
-
1569
1373
  return Request;
1570
1374
  }(Emitter);
1571
1375
  Request.requestsCount = 0;
@@ -1575,7 +1379,6 @@
1575
1379
  * memory leaks (e.g. when using IE) and to ensure that no spurious error is
1576
1380
  * emitted.
1577
1381
  */
1578
-
1579
1382
  if (typeof document !== "undefined") {
1580
1383
  // @ts-ignore
1581
1384
  if (typeof attachEvent === "function") {
@@ -1586,7 +1389,6 @@
1586
1389
  addEventListener(terminationEvent, unloadHandler, false);
1587
1390
  }
1588
1391
  }
1589
-
1590
1392
  function unloadHandler() {
1591
1393
  for (var i in Request.requests) {
1592
1394
  if (Request.requests.hasOwnProperty(i)) {
@@ -1597,7 +1399,6 @@
1597
1399
 
1598
1400
  var nextTick = function () {
1599
1401
  var isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
1600
-
1601
1402
  if (isPromiseAvailable) {
1602
1403
  return function (cb) {
1603
1404
  return Promise.resolve().then(cb);
@@ -1612,12 +1413,11 @@
1612
1413
  var usingBrowserWebSocket = true;
1613
1414
  var defaultBinaryType = "arraybuffer";
1614
1415
 
1416
+ // detect ReactNative environment
1615
1417
  var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
1616
1418
  var WS = /*#__PURE__*/function (_Transport) {
1617
1419
  _inherits(WS, _Transport);
1618
-
1619
1420
  var _super = _createSuper(WS);
1620
-
1621
1421
  /**
1622
1422
  * WebSocket transport constructor.
1623
1423
  *
@@ -1626,14 +1426,11 @@
1626
1426
  */
1627
1427
  function WS(opts) {
1628
1428
  var _this;
1629
-
1630
1429
  _classCallCheck(this, WS);
1631
-
1632
1430
  _this = _super.call(this, opts);
1633
1431
  _this.supportsBinary = !opts.forceBase64;
1634
1432
  return _this;
1635
1433
  }
1636
-
1637
1434
  _createClass(WS, [{
1638
1435
  key: "name",
1639
1436
  get: function get() {
@@ -1646,22 +1443,18 @@
1646
1443
  // let probe timeout
1647
1444
  return;
1648
1445
  }
1649
-
1650
1446
  var uri = this.uri();
1651
- var protocols = this.opts.protocols; // React Native only supports the 'headers' option, and will print a warning if anything else is passed
1652
-
1447
+ var protocols = this.opts.protocols;
1448
+ // React Native only supports the 'headers' option, and will print a warning if anything else is passed
1653
1449
  var opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
1654
-
1655
1450
  if (this.opts.extraHeaders) {
1656
1451
  opts.headers = this.opts.extraHeaders;
1657
1452
  }
1658
-
1659
1453
  try {
1660
1454
  this.ws = usingBrowserWebSocket && !isReactNative ? protocols ? new WebSocket(uri, protocols) : new WebSocket(uri) : new WebSocket(uri, protocols, opts);
1661
1455
  } catch (err) {
1662
1456
  return this.emitReserved("error", err);
1663
1457
  }
1664
-
1665
1458
  this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
1666
1459
  this.addEventListeners();
1667
1460
  }
@@ -1670,31 +1463,25 @@
1670
1463
  *
1671
1464
  * @private
1672
1465
  */
1673
-
1674
1466
  }, {
1675
1467
  key: "addEventListeners",
1676
1468
  value: function addEventListeners() {
1677
1469
  var _this2 = this;
1678
-
1679
1470
  this.ws.onopen = function () {
1680
1471
  if (_this2.opts.autoUnref) {
1681
1472
  _this2.ws._socket.unref();
1682
1473
  }
1683
-
1684
1474
  _this2.onOpen();
1685
1475
  };
1686
-
1687
1476
  this.ws.onclose = function (closeEvent) {
1688
1477
  return _this2.onClose({
1689
1478
  description: "websocket connection closed",
1690
1479
  context: closeEvent
1691
1480
  });
1692
1481
  };
1693
-
1694
1482
  this.ws.onmessage = function (ev) {
1695
1483
  return _this2.onData(ev.data);
1696
1484
  };
1697
-
1698
1485
  this.ws.onerror = function (e) {
1699
1486
  return _this2.onError("websocket error", e);
1700
1487
  };
@@ -1703,41 +1490,36 @@
1703
1490
  key: "write",
1704
1491
  value: function write(packets) {
1705
1492
  var _this3 = this;
1706
-
1707
- this.writable = false; // encodePacket efficient as it uses WS framing
1493
+ this.writable = false;
1494
+ // encodePacket efficient as it uses WS framing
1708
1495
  // no need for encodePayload
1709
-
1710
- var _loop = function _loop(i) {
1496
+ var _loop = function _loop() {
1711
1497
  var packet = packets[i];
1712
1498
  var lastPacket = i === packets.length - 1;
1713
1499
  encodePacket(packet, _this3.supportsBinary, function (data) {
1714
1500
  // always create a new object (GH-437)
1715
1501
  var opts = {};
1502
+ // Sometimes the websocket has already been closed but the browser didn't
1716
1503
  // have a chance of informing us about it yet, in that case send will
1717
1504
  // throw an error
1718
-
1719
-
1720
1505
  try {
1721
1506
  if (usingBrowserWebSocket) {
1722
1507
  // TypeError is thrown when passing the second argument on Safari
1723
1508
  _this3.ws.send(data);
1724
1509
  }
1725
1510
  } catch (e) {}
1726
-
1727
1511
  if (lastPacket) {
1728
1512
  // fake drain
1729
1513
  // defer to next tick to allow Socket to clear writeBuffer
1730
1514
  nextTick(function () {
1731
1515
  _this3.writable = true;
1732
-
1733
1516
  _this3.emitReserved("drain");
1734
1517
  }, _this3.setTimeoutFn);
1735
1518
  }
1736
1519
  });
1737
1520
  };
1738
-
1739
1521
  for (var i = 0; i < packets.length; i++) {
1740
- _loop(i);
1522
+ _loop();
1741
1523
  }
1742
1524
  }
1743
1525
  }, {
@@ -1753,22 +1535,19 @@
1753
1535
  *
1754
1536
  * @private
1755
1537
  */
1756
-
1757
1538
  }, {
1758
1539
  key: "uri",
1759
1540
  value: function uri() {
1760
1541
  var schema = this.opts.secure ? "wss" : "ws";
1761
- var query = this.query || {}; // append timestamp to URI
1762
-
1542
+ var query = this.query || {};
1543
+ // append timestamp to URI
1763
1544
  if (this.opts.timestampRequests) {
1764
1545
  query[this.opts.timestampParam] = yeast();
1765
- } // communicate binary support capabilities
1766
-
1767
-
1546
+ }
1547
+ // communicate binary support capabilities
1768
1548
  if (!this.supportsBinary) {
1769
1549
  query.b64 = 1;
1770
1550
  }
1771
-
1772
1551
  return this.createUri(schema, query);
1773
1552
  }
1774
1553
  /**
@@ -1777,14 +1556,12 @@
1777
1556
  * @return {Boolean} whether this transport is available.
1778
1557
  * @private
1779
1558
  */
1780
-
1781
1559
  }, {
1782
1560
  key: "check",
1783
1561
  value: function check() {
1784
1562
  return !!WebSocket;
1785
1563
  }
1786
1564
  }]);
1787
-
1788
1565
  return WS;
1789
1566
  }(Transport);
1790
1567
 
@@ -1793,18 +1570,13 @@
1793
1570
  // 54 === "6".charCodeAt(0) (NOOP packet type)
1794
1571
  return packet.type === "message" && typeof packet.data !== "string" && encoded[0] >= 48 && encoded[0] <= 54;
1795
1572
  }
1796
-
1797
1573
  var WT = /*#__PURE__*/function (_Transport) {
1798
1574
  _inherits(WT, _Transport);
1799
-
1800
1575
  var _super = _createSuper(WT);
1801
-
1802
1576
  function WT() {
1803
1577
  _classCallCheck(this, WT);
1804
-
1805
1578
  return _super.apply(this, arguments);
1806
1579
  }
1807
-
1808
1580
  _createClass(WT, [{
1809
1581
  key: "name",
1810
1582
  get: function get() {
@@ -1814,49 +1586,42 @@
1814
1586
  key: "doOpen",
1815
1587
  value: function doOpen() {
1816
1588
  var _this = this;
1817
-
1818
1589
  // @ts-ignore
1819
1590
  if (typeof WebTransport !== "function") {
1820
1591
  return;
1821
- } // @ts-ignore
1822
-
1823
-
1592
+ }
1593
+ // @ts-ignore
1824
1594
  this.transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
1825
1595
  this.transport.closed.then(function () {
1826
- return _this.onClose();
1827
- }); // note: we could have used async/await, but that would require some additional polyfills
1828
-
1596
+ _this.onClose();
1597
+ })["catch"](function (err) {
1598
+ _this.onError("webtransport error", err);
1599
+ });
1600
+ // note: we could have used async/await, but that would require some additional polyfills
1829
1601
  this.transport.ready.then(function () {
1830
1602
  _this.transport.createBidirectionalStream().then(function (stream) {
1831
1603
  var reader = stream.readable.getReader();
1832
1604
  _this.writer = stream.writable.getWriter();
1833
1605
  var binaryFlag;
1834
-
1835
1606
  var read = function read() {
1836
1607
  reader.read().then(function (_ref) {
1837
1608
  var done = _ref.done,
1838
- value = _ref.value;
1839
-
1609
+ value = _ref.value;
1840
1610
  if (done) {
1841
1611
  return;
1842
1612
  }
1843
-
1844
1613
  if (!binaryFlag && value.byteLength === 1 && value[0] === 54) {
1845
1614
  binaryFlag = true;
1846
1615
  } else {
1847
1616
  // TODO expose binarytype
1848
1617
  _this.onPacket(decodePacketFromBinary(value, binaryFlag, "arraybuffer"));
1849
-
1850
1618
  binaryFlag = false;
1851
1619
  }
1852
-
1853
1620
  read();
1854
- });
1621
+ })["catch"](function (err) {});
1855
1622
  };
1856
-
1857
1623
  read();
1858
1624
  var handshake = _this.query.sid ? "0{\"sid\":\"".concat(_this.query.sid, "\"}") : "0";
1859
-
1860
1625
  _this.writer.write(new TextEncoder().encode(handshake)).then(function () {
1861
1626
  return _this.onOpen();
1862
1627
  });
@@ -1867,42 +1632,35 @@
1867
1632
  key: "write",
1868
1633
  value: function write(packets) {
1869
1634
  var _this2 = this;
1870
-
1871
1635
  this.writable = false;
1872
-
1873
- var _loop = function _loop(i) {
1636
+ var _loop = function _loop() {
1874
1637
  var packet = packets[i];
1875
1638
  var lastPacket = i === packets.length - 1;
1876
1639
  encodePacketToBinary(packet, function (data) {
1877
1640
  if (shouldIncludeBinaryHeader(packet, data)) {
1878
1641
  _this2.writer.write(Uint8Array.of(54));
1879
1642
  }
1880
-
1881
1643
  _this2.writer.write(data).then(function () {
1882
1644
  if (lastPacket) {
1883
1645
  nextTick(function () {
1884
1646
  _this2.writable = true;
1885
-
1886
1647
  _this2.emitReserved("drain");
1887
1648
  }, _this2.setTimeoutFn);
1888
1649
  }
1889
1650
  });
1890
1651
  });
1891
1652
  };
1892
-
1893
1653
  for (var i = 0; i < packets.length; i++) {
1894
- _loop(i);
1654
+ _loop();
1895
1655
  }
1896
1656
  }
1897
1657
  }, {
1898
1658
  key: "doClose",
1899
1659
  value: function doClose() {
1900
1660
  var _a;
1901
-
1902
1661
  (_a = this.transport) === null || _a === void 0 ? void 0 : _a.close();
1903
1662
  }
1904
1663
  }]);
1905
-
1906
1664
  return WT;
1907
1665
  }(Transport);
1908
1666
 
@@ -1913,7 +1671,6 @@
1913
1671
  };
1914
1672
 
1915
1673
  // imported from https://github.com/galkn/parseuri
1916
-
1917
1674
  /**
1918
1675
  * Parses a URI
1919
1676
  *
@@ -1936,48 +1693,38 @@
1936
1693
  var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
1937
1694
  function parse(str) {
1938
1695
  var src = str,
1939
- b = str.indexOf('['),
1940
- e = str.indexOf(']');
1941
-
1696
+ b = str.indexOf('['),
1697
+ e = str.indexOf(']');
1942
1698
  if (b != -1 && e != -1) {
1943
1699
  str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
1944
1700
  }
1945
-
1946
1701
  var m = re.exec(str || ''),
1947
- uri = {},
1948
- i = 14;
1949
-
1702
+ uri = {},
1703
+ i = 14;
1950
1704
  while (i--) {
1951
1705
  uri[parts[i]] = m[i] || '';
1952
1706
  }
1953
-
1954
1707
  if (b != -1 && e != -1) {
1955
1708
  uri.source = src;
1956
1709
  uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
1957
1710
  uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
1958
1711
  uri.ipv6uri = true;
1959
1712
  }
1960
-
1961
1713
  uri.pathNames = pathNames(uri, uri['path']);
1962
1714
  uri.queryKey = queryKey(uri, uri['query']);
1963
1715
  return uri;
1964
1716
  }
1965
-
1966
1717
  function pathNames(obj, path) {
1967
1718
  var regx = /\/{2,9}/g,
1968
- names = path.replace(regx, "/").split("/");
1969
-
1719
+ names = path.replace(regx, "/").split("/");
1970
1720
  if (path.slice(0, 1) == '/' || path.length === 0) {
1971
1721
  names.splice(0, 1);
1972
1722
  }
1973
-
1974
1723
  if (path.slice(-1) == '/') {
1975
1724
  names.splice(names.length - 1, 1);
1976
1725
  }
1977
-
1978
1726
  return names;
1979
1727
  }
1980
-
1981
1728
  function queryKey(uri, query) {
1982
1729
  var data = {};
1983
1730
  query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
@@ -1990,9 +1737,7 @@
1990
1737
 
1991
1738
  var Socket$1 = /*#__PURE__*/function (_Emitter) {
1992
1739
  _inherits(Socket, _Emitter);
1993
-
1994
1740
  var _super = _createSuper(Socket);
1995
-
1996
1741
  /**
1997
1742
  * Socket constructor.
1998
1743
  *
@@ -2001,19 +1746,14 @@
2001
1746
  */
2002
1747
  function Socket(uri) {
2003
1748
  var _this;
2004
-
2005
1749
  var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
2006
-
2007
1750
  _classCallCheck(this, Socket);
2008
-
2009
1751
  _this = _super.call(this);
2010
1752
  _this.writeBuffer = [];
2011
-
2012
1753
  if (uri && "object" === _typeof(uri)) {
2013
1754
  opts = uri;
2014
1755
  uri = null;
2015
1756
  }
2016
-
2017
1757
  if (uri) {
2018
1758
  uri = parse(uri);
2019
1759
  opts.hostname = uri.host;
@@ -2023,15 +1763,12 @@
2023
1763
  } else if (opts.host) {
2024
1764
  opts.hostname = parse(opts.host).host;
2025
1765
  }
2026
-
2027
1766
  installTimerFunctions(_assertThisInitialized(_this), opts);
2028
1767
  _this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
2029
-
2030
1768
  if (opts.hostname && !opts.port) {
2031
1769
  // if no port is specified manually, use the protocol default
2032
1770
  opts.port = _this.secure ? "443" : "80";
2033
1771
  }
2034
-
2035
1772
  _this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
2036
1773
  _this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
2037
1774
  _this.transports = opts.transports || ["polling", "websocket", "webtransport"];
@@ -2050,22 +1787,19 @@
2050
1787
  threshold: 1024
2051
1788
  },
2052
1789
  transportOptions: {},
2053
- closeOnBeforeunload: true
1790
+ closeOnBeforeunload: false
2054
1791
  }, opts);
2055
1792
  _this.opts.path = _this.opts.path.replace(/\/$/, "") + (_this.opts.addTrailingSlash ? "/" : "");
2056
-
2057
1793
  if (typeof _this.opts.query === "string") {
2058
1794
  _this.opts.query = decode(_this.opts.query);
2059
- } // set on handshake
2060
-
2061
-
1795
+ }
1796
+ // set on handshake
2062
1797
  _this.id = null;
2063
1798
  _this.upgrades = null;
2064
1799
  _this.pingInterval = null;
2065
- _this.pingTimeout = null; // set on heartbeat
2066
-
1800
+ _this.pingTimeout = null;
1801
+ // set on heartbeat
2067
1802
  _this.pingTimeoutTimer = null;
2068
-
2069
1803
  if (typeof addEventListener === "function") {
2070
1804
  if (_this.opts.closeOnBeforeunload) {
2071
1805
  // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
@@ -2075,27 +1809,21 @@
2075
1809
  if (_this.transport) {
2076
1810
  // silently close the transport
2077
1811
  _this.transport.removeAllListeners();
2078
-
2079
1812
  _this.transport.close();
2080
1813
  }
2081
1814
  };
2082
-
2083
1815
  addEventListener("beforeunload", _this.beforeunloadEventListener, false);
2084
1816
  }
2085
-
2086
1817
  if (_this.hostname !== "localhost") {
2087
1818
  _this.offlineEventListener = function () {
2088
1819
  _this.onClose("transport close", {
2089
1820
  description: "network connection lost"
2090
1821
  });
2091
1822
  };
2092
-
2093
1823
  addEventListener("offline", _this.offlineEventListener, false);
2094
1824
  }
2095
1825
  }
2096
-
2097
1826
  _this.open();
2098
-
2099
1827
  return _this;
2100
1828
  }
2101
1829
  /**
@@ -2105,28 +1833,23 @@
2105
1833
  * @return {Transport}
2106
1834
  * @private
2107
1835
  */
2108
-
2109
-
2110
1836
  _createClass(Socket, [{
2111
1837
  key: "createTransport",
2112
1838
  value: function createTransport(name) {
2113
- var query = _extends({}, this.opts.query); // append engine.io protocol identifier
2114
-
2115
-
2116
- query.EIO = protocol$1; // transport name
2117
-
2118
- query.transport = name; // session id if we already have one
2119
-
1839
+ var query = _extends({}, this.opts.query);
1840
+ // append engine.io protocol identifier
1841
+ query.EIO = protocol$1;
1842
+ // transport name
1843
+ query.transport = name;
1844
+ // session id if we already have one
2120
1845
  if (this.id) query.sid = this.id;
2121
-
2122
- var opts = _extends({}, this.opts.transportOptions[name], this.opts, {
1846
+ var opts = _extends({}, this.opts, {
2123
1847
  query: query,
2124
1848
  socket: this,
2125
1849
  hostname: this.hostname,
2126
1850
  secure: this.secure,
2127
1851
  port: this.port
2128
- });
2129
-
1852
+ }, this.opts.transportOptions[name]);
2130
1853
  return new transports[name](opts);
2131
1854
  }
2132
1855
  /**
@@ -2134,14 +1857,11 @@
2134
1857
  *
2135
1858
  * @private
2136
1859
  */
2137
-
2138
1860
  }, {
2139
1861
  key: "open",
2140
1862
  value: function open() {
2141
1863
  var _this2 = this;
2142
-
2143
1864
  var transport;
2144
-
2145
1865
  if (this.opts.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1) {
2146
1866
  transport = "websocket";
2147
1867
  } else if (0 === this.transports.length) {
@@ -2153,9 +1873,8 @@
2153
1873
  } else {
2154
1874
  transport = this.transports[0];
2155
1875
  }
2156
-
2157
- this.readyState = "opening"; // Retry with the next transport if the transport is disabled (jsonp: false)
2158
-
1876
+ this.readyState = "opening";
1877
+ // Retry with the next transport if the transport is disabled (jsonp: false)
2159
1878
  try {
2160
1879
  transport = this.createTransport(transport);
2161
1880
  } catch (e) {
@@ -2163,7 +1882,6 @@
2163
1882
  this.open();
2164
1883
  return;
2165
1884
  }
2166
-
2167
1885
  transport.open();
2168
1886
  this.setTransport(transport);
2169
1887
  }
@@ -2172,19 +1890,16 @@
2172
1890
  *
2173
1891
  * @private
2174
1892
  */
2175
-
2176
1893
  }, {
2177
1894
  key: "setTransport",
2178
1895
  value: function setTransport(transport) {
2179
1896
  var _this3 = this;
2180
-
2181
1897
  if (this.transport) {
2182
1898
  this.transport.removeAllListeners();
2183
- } // set up transport
2184
-
2185
-
2186
- this.transport = transport; // set up transport listeners
2187
-
1899
+ }
1900
+ // set up transport
1901
+ this.transport = transport;
1902
+ // set up transport listeners
2188
1903
  transport.on("drain", this.onDrain.bind(this)).on("packet", this.onPacket.bind(this)).on("error", this.onError.bind(this)).on("close", function (reason) {
2189
1904
  return _this3.onClose("transport close", reason);
2190
1905
  });
@@ -2195,16 +1910,13 @@
2195
1910
  * @param {String} name - transport name
2196
1911
  * @private
2197
1912
  */
2198
-
2199
1913
  }, {
2200
1914
  key: "probe",
2201
1915
  value: function probe(name) {
2202
1916
  var _this4 = this;
2203
-
2204
1917
  var transport = this.createTransport(name);
2205
1918
  var failed = false;
2206
1919
  Socket.priorWebsocketSuccess = false;
2207
-
2208
1920
  var onTransportOpen = function onTransportOpen() {
2209
1921
  if (failed) return;
2210
1922
  transport.send([{
@@ -2213,95 +1925,74 @@
2213
1925
  }]);
2214
1926
  transport.once("packet", function (msg) {
2215
1927
  if (failed) return;
2216
-
2217
1928
  if ("pong" === msg.type && "probe" === msg.data) {
2218
1929
  _this4.upgrading = true;
2219
-
2220
1930
  _this4.emitReserved("upgrading", transport);
2221
-
2222
1931
  if (!transport) return;
2223
1932
  Socket.priorWebsocketSuccess = "websocket" === transport.name;
2224
-
2225
1933
  _this4.transport.pause(function () {
2226
1934
  if (failed) return;
2227
1935
  if ("closed" === _this4.readyState) return;
2228
1936
  cleanup();
2229
-
2230
1937
  _this4.setTransport(transport);
2231
-
2232
1938
  transport.send([{
2233
1939
  type: "upgrade"
2234
1940
  }]);
2235
-
2236
1941
  _this4.emitReserved("upgrade", transport);
2237
-
2238
1942
  transport = null;
2239
1943
  _this4.upgrading = false;
2240
-
2241
1944
  _this4.flush();
2242
1945
  });
2243
1946
  } else {
2244
- var err = new Error("probe error"); // @ts-ignore
2245
-
1947
+ var err = new Error("probe error");
1948
+ // @ts-ignore
2246
1949
  err.transport = transport.name;
2247
-
2248
1950
  _this4.emitReserved("upgradeError", err);
2249
1951
  }
2250
1952
  });
2251
1953
  };
2252
-
2253
1954
  function freezeTransport() {
2254
- if (failed) return; // Any callback called by transport should be ignored since now
2255
-
1955
+ if (failed) return;
1956
+ // Any callback called by transport should be ignored since now
2256
1957
  failed = true;
2257
1958
  cleanup();
2258
1959
  transport.close();
2259
1960
  transport = null;
2260
- } // Handle any error that happens while probing
2261
-
2262
-
1961
+ }
1962
+ // Handle any error that happens while probing
2263
1963
  var onerror = function onerror(err) {
2264
- var error = new Error("probe error: " + err); // @ts-ignore
2265
-
1964
+ var error = new Error("probe error: " + err);
1965
+ // @ts-ignore
2266
1966
  error.transport = transport.name;
2267
1967
  freezeTransport();
2268
-
2269
1968
  _this4.emitReserved("upgradeError", error);
2270
1969
  };
2271
-
2272
1970
  function onTransportClose() {
2273
1971
  onerror("transport closed");
2274
- } // When the socket is closed while we're probing
2275
-
2276
-
1972
+ }
1973
+ // When the socket is closed while we're probing
2277
1974
  function onclose() {
2278
1975
  onerror("socket closed");
2279
- } // When the socket is upgraded while we're probing
2280
-
2281
-
1976
+ }
1977
+ // When the socket is upgraded while we're probing
2282
1978
  function onupgrade(to) {
2283
1979
  if (transport && to.name !== transport.name) {
2284
1980
  freezeTransport();
2285
1981
  }
2286
- } // Remove all listeners on the transport and on self
2287
-
2288
-
1982
+ }
1983
+ // Remove all listeners on the transport and on self
2289
1984
  var cleanup = function cleanup() {
2290
1985
  transport.removeListener("open", onTransportOpen);
2291
1986
  transport.removeListener("error", onerror);
2292
1987
  transport.removeListener("close", onTransportClose);
2293
-
2294
1988
  _this4.off("close", onclose);
2295
-
2296
1989
  _this4.off("upgrading", onupgrade);
2297
1990
  };
2298
-
2299
1991
  transport.once("open", onTransportOpen);
2300
1992
  transport.once("error", onerror);
2301
1993
  transport.once("close", onTransportClose);
2302
1994
  this.once("close", onclose);
2303
1995
  this.once("upgrading", onupgrade);
2304
-
2305
1996
  if (this.upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
2306
1997
  // favor WebTransport
2307
1998
  this.setTimeoutFn(function () {
@@ -2318,20 +2009,18 @@
2318
2009
  *
2319
2010
  * @private
2320
2011
  */
2321
-
2322
2012
  }, {
2323
2013
  key: "onOpen",
2324
2014
  value: function onOpen() {
2325
2015
  this.readyState = "open";
2326
2016
  Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
2327
2017
  this.emitReserved("open");
2328
- this.flush(); // we check for `readyState` in case an `open`
2018
+ this.flush();
2019
+ // we check for `readyState` in case an `open`
2329
2020
  // listener already closed the socket
2330
-
2331
2021
  if ("open" === this.readyState && this.opts.upgrade) {
2332
2022
  var i = 0;
2333
2023
  var l = this.upgrades.length;
2334
-
2335
2024
  for (; i < l; i++) {
2336
2025
  this.probe(this.upgrades[i]);
2337
2026
  }
@@ -2342,34 +2031,29 @@
2342
2031
  *
2343
2032
  * @private
2344
2033
  */
2345
-
2346
2034
  }, {
2347
2035
  key: "onPacket",
2348
2036
  value: function onPacket(packet) {
2349
2037
  if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
2350
- this.emitReserved("packet", packet); // Socket is live - any packet counts
2351
-
2038
+ this.emitReserved("packet", packet);
2039
+ // Socket is live - any packet counts
2352
2040
  this.emitReserved("heartbeat");
2353
-
2354
2041
  switch (packet.type) {
2355
2042
  case "open":
2356
2043
  this.onHandshake(JSON.parse(packet.data));
2357
2044
  break;
2358
-
2359
2045
  case "ping":
2360
2046
  this.resetPingTimeout();
2361
2047
  this.sendPacket("pong");
2362
2048
  this.emitReserved("ping");
2363
2049
  this.emitReserved("pong");
2364
2050
  break;
2365
-
2366
2051
  case "error":
2367
- var err = new Error("server error"); // @ts-ignore
2368
-
2052
+ var err = new Error("server error");
2053
+ // @ts-ignore
2369
2054
  err.code = packet.data;
2370
2055
  this.onError(err);
2371
2056
  break;
2372
-
2373
2057
  case "message":
2374
2058
  this.emitReserved("data", packet.data);
2375
2059
  this.emitReserved("message", packet.data);
@@ -2383,7 +2067,6 @@
2383
2067
  * @param {Object} data - handshake obj
2384
2068
  * @private
2385
2069
  */
2386
-
2387
2070
  }, {
2388
2071
  key: "onHandshake",
2389
2072
  value: function onHandshake(data) {
@@ -2394,8 +2077,8 @@
2394
2077
  this.pingInterval = data.pingInterval;
2395
2078
  this.pingTimeout = data.pingTimeout;
2396
2079
  this.maxPayload = data.maxPayload;
2397
- this.onOpen(); // In case open handler closes socket
2398
-
2080
+ this.onOpen();
2081
+ // In case open handler closes socket
2399
2082
  if ("closed" === this.readyState) return;
2400
2083
  this.resetPingTimeout();
2401
2084
  }
@@ -2404,17 +2087,14 @@
2404
2087
  *
2405
2088
  * @private
2406
2089
  */
2407
-
2408
2090
  }, {
2409
2091
  key: "resetPingTimeout",
2410
2092
  value: function resetPingTimeout() {
2411
2093
  var _this5 = this;
2412
-
2413
2094
  this.clearTimeoutFn(this.pingTimeoutTimer);
2414
2095
  this.pingTimeoutTimer = this.setTimeoutFn(function () {
2415
2096
  _this5.onClose("ping timeout");
2416
2097
  }, this.pingInterval + this.pingTimeout);
2417
-
2418
2098
  if (this.opts.autoUnref) {
2419
2099
  this.pingTimeoutTimer.unref();
2420
2100
  }
@@ -2424,16 +2104,14 @@
2424
2104
  *
2425
2105
  * @private
2426
2106
  */
2427
-
2428
2107
  }, {
2429
2108
  key: "onDrain",
2430
2109
  value: function onDrain() {
2431
- this.writeBuffer.splice(0, this.prevBufferLen); // setting prevBufferLen = 0 is very important
2110
+ this.writeBuffer.splice(0, this.prevBufferLen);
2111
+ // setting prevBufferLen = 0 is very important
2432
2112
  // for example, when upgrading, upgrade packet is sent over,
2433
2113
  // and a nonzero prevBufferLen could cause problems on `drain`
2434
-
2435
2114
  this.prevBufferLen = 0;
2436
-
2437
2115
  if (0 === this.writeBuffer.length) {
2438
2116
  this.emitReserved("drain");
2439
2117
  } else {
@@ -2445,15 +2123,14 @@
2445
2123
  *
2446
2124
  * @private
2447
2125
  */
2448
-
2449
2126
  }, {
2450
2127
  key: "flush",
2451
2128
  value: function flush() {
2452
2129
  if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
2453
2130
  var packets = this.getWritablePackets();
2454
- this.transport.send(packets); // keep track of current length of writeBuffer
2131
+ this.transport.send(packets);
2132
+ // keep track of current length of writeBuffer
2455
2133
  // splice writeBuffer and callbackBuffer on `drain`
2456
-
2457
2134
  this.prevBufferLen = packets.length;
2458
2135
  this.emitReserved("flush");
2459
2136
  }
@@ -2464,29 +2141,22 @@
2464
2141
  *
2465
2142
  * @private
2466
2143
  */
2467
-
2468
2144
  }, {
2469
2145
  key: "getWritablePackets",
2470
2146
  value: function getWritablePackets() {
2471
2147
  var shouldCheckPayloadSize = this.maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1;
2472
-
2473
2148
  if (!shouldCheckPayloadSize) {
2474
2149
  return this.writeBuffer;
2475
2150
  }
2476
-
2477
2151
  var payloadSize = 1; // first packet type
2478
-
2479
2152
  for (var i = 0; i < this.writeBuffer.length; i++) {
2480
2153
  var data = this.writeBuffer[i].data;
2481
-
2482
2154
  if (data) {
2483
2155
  payloadSize += byteLength(data);
2484
2156
  }
2485
-
2486
2157
  if (i > 0 && payloadSize > this.maxPayload) {
2487
2158
  return this.writeBuffer.slice(0, i);
2488
2159
  }
2489
-
2490
2160
  payloadSize += 2; // separator + packet type
2491
2161
  }
2492
2162
 
@@ -2500,7 +2170,6 @@
2500
2170
  * @param {Function} callback function.
2501
2171
  * @return {Socket} for chaining.
2502
2172
  */
2503
-
2504
2173
  }, {
2505
2174
  key: "write",
2506
2175
  value: function write(msg, options, fn) {
@@ -2522,7 +2191,6 @@
2522
2191
  * @param {Function} fn - callback function.
2523
2192
  * @private
2524
2193
  */
2525
-
2526
2194
  }, {
2527
2195
  key: "sendPacket",
2528
2196
  value: function sendPacket(type, data, options, fn) {
@@ -2530,16 +2198,13 @@
2530
2198
  fn = data;
2531
2199
  data = undefined;
2532
2200
  }
2533
-
2534
2201
  if ("function" === typeof options) {
2535
2202
  fn = options;
2536
2203
  options = null;
2537
2204
  }
2538
-
2539
2205
  if ("closing" === this.readyState || "closed" === this.readyState) {
2540
2206
  return;
2541
2207
  }
2542
-
2543
2208
  options = options || {};
2544
2209
  options.compress = false !== options.compress;
2545
2210
  var packet = {
@@ -2555,36 +2220,26 @@
2555
2220
  /**
2556
2221
  * Closes the connection.
2557
2222
  */
2558
-
2559
2223
  }, {
2560
2224
  key: "close",
2561
2225
  value: function close() {
2562
2226
  var _this6 = this;
2563
-
2564
2227
  var close = function close() {
2565
2228
  _this6.onClose("forced close");
2566
-
2567
2229
  _this6.transport.close();
2568
2230
  };
2569
-
2570
2231
  var cleanupAndClose = function cleanupAndClose() {
2571
2232
  _this6.off("upgrade", cleanupAndClose);
2572
-
2573
2233
  _this6.off("upgradeError", cleanupAndClose);
2574
-
2575
2234
  close();
2576
2235
  };
2577
-
2578
2236
  var waitForUpgrade = function waitForUpgrade() {
2579
2237
  // wait for upgrade to finish since we can't send packets while pausing a transport
2580
2238
  _this6.once("upgrade", cleanupAndClose);
2581
-
2582
2239
  _this6.once("upgradeError", cleanupAndClose);
2583
2240
  };
2584
-
2585
2241
  if ("opening" === this.readyState || "open" === this.readyState) {
2586
2242
  this.readyState = "closing";
2587
-
2588
2243
  if (this.writeBuffer.length) {
2589
2244
  this.once("drain", function () {
2590
2245
  if (_this6.upgrading) {
@@ -2599,7 +2254,6 @@
2599
2254
  close();
2600
2255
  }
2601
2256
  }
2602
-
2603
2257
  return this;
2604
2258
  }
2605
2259
  /**
@@ -2607,7 +2261,6 @@
2607
2261
  *
2608
2262
  * @private
2609
2263
  */
2610
-
2611
2264
  }, {
2612
2265
  key: "onError",
2613
2266
  value: function onError(err) {
@@ -2620,33 +2273,30 @@
2620
2273
  *
2621
2274
  * @private
2622
2275
  */
2623
-
2624
2276
  }, {
2625
2277
  key: "onClose",
2626
2278
  value: function onClose(reason, description) {
2627
2279
  if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
2628
2280
  // clear timers
2629
- this.clearTimeoutFn(this.pingTimeoutTimer); // stop event from firing again for transport
2630
-
2631
- this.transport.removeAllListeners("close"); // ensure transport won't stay open
2632
-
2633
- this.transport.close(); // ignore further transport communication
2634
-
2281
+ this.clearTimeoutFn(this.pingTimeoutTimer);
2282
+ // stop event from firing again for transport
2283
+ this.transport.removeAllListeners("close");
2284
+ // ensure transport won't stay open
2285
+ this.transport.close();
2286
+ // ignore further transport communication
2635
2287
  this.transport.removeAllListeners();
2636
-
2637
2288
  if (typeof removeEventListener === "function") {
2638
2289
  removeEventListener("beforeunload", this.beforeunloadEventListener, false);
2639
2290
  removeEventListener("offline", this.offlineEventListener, false);
2640
- } // set ready state
2641
-
2642
-
2643
- this.readyState = "closed"; // clear session id
2644
-
2645
- this.id = null; // emit close event
2646
-
2647
- this.emitReserved("close", reason, description); // clean buffers after, so users can still
2291
+ }
2292
+ // set ready state
2293
+ this.readyState = "closed";
2294
+ // clear session id
2295
+ this.id = null;
2296
+ // emit close event
2297
+ this.emitReserved("close", reason, description);
2298
+ // clean buffers after, so users can still
2648
2299
  // grab the buffers on `close` event
2649
-
2650
2300
  this.writeBuffer = [];
2651
2301
  this.prevBufferLen = 0;
2652
2302
  }
@@ -2657,22 +2307,18 @@
2657
2307
  * @param {Array} upgrades - server upgrades
2658
2308
  * @private
2659
2309
  */
2660
-
2661
2310
  }, {
2662
2311
  key: "filterUpgrades",
2663
2312
  value: function filterUpgrades(upgrades) {
2664
2313
  var filteredUpgrades = [];
2665
2314
  var i = 0;
2666
2315
  var j = upgrades.length;
2667
-
2668
2316
  for (; i < j; i++) {
2669
2317
  if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
2670
2318
  }
2671
-
2672
2319
  return filteredUpgrades;
2673
2320
  }
2674
2321
  }]);
2675
-
2676
2322
  return Socket;
2677
2323
  }(Emitter);
2678
2324
  Socket$1.protocol = protocol$1;
@@ -2688,15 +2334,14 @@
2688
2334
  * Defaults to window.location.
2689
2335
  * @public
2690
2336
  */
2691
-
2692
2337
  function url(uri) {
2693
2338
  var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
2694
2339
  var loc = arguments.length > 2 ? arguments[2] : undefined;
2695
- var obj = uri; // default to window.location
2696
-
2340
+ var obj = uri;
2341
+ // default to window.location
2697
2342
  loc = loc || typeof location !== "undefined" && location;
2698
- if (null == uri) uri = loc.protocol + "//" + loc.host; // relative path support
2699
-
2343
+ if (null == uri) uri = loc.protocol + "//" + loc.host;
2344
+ // relative path support
2700
2345
  if (typeof uri === "string") {
2701
2346
  if ("/" === uri.charAt(0)) {
2702
2347
  if ("/" === uri.charAt(1)) {
@@ -2705,20 +2350,17 @@
2705
2350
  uri = loc.host + uri;
2706
2351
  }
2707
2352
  }
2708
-
2709
2353
  if (!/^(https?|wss?):\/\//.test(uri)) {
2710
2354
  if ("undefined" !== typeof loc) {
2711
2355
  uri = loc.protocol + "//" + uri;
2712
2356
  } else {
2713
2357
  uri = "https://" + uri;
2714
2358
  }
2715
- } // parse
2716
-
2717
-
2359
+ }
2360
+ // parse
2718
2361
  obj = parse(uri);
2719
- } // make sure we treat `localhost:80` and `localhost` equally
2720
-
2721
-
2362
+ }
2363
+ // make sure we treat `localhost:80` and `localhost` equally
2722
2364
  if (!obj.port) {
2723
2365
  if (/^(http|ws)$/.test(obj.protocol)) {
2724
2366
  obj.port = "80";
@@ -2726,23 +2368,20 @@
2726
2368
  obj.port = "443";
2727
2369
  }
2728
2370
  }
2729
-
2730
2371
  obj.path = obj.path || "/";
2731
2372
  var ipv6 = obj.host.indexOf(":") !== -1;
2732
- var host = ipv6 ? "[" + obj.host + "]" : obj.host; // define unique id
2733
-
2734
- obj.id = obj.protocol + "://" + host + ":" + obj.port + path; // define href
2735
-
2373
+ var host = ipv6 ? "[" + obj.host + "]" : obj.host;
2374
+ // define unique id
2375
+ obj.id = obj.protocol + "://" + host + ":" + obj.port + path;
2376
+ // define href
2736
2377
  obj.href = obj.protocol + "://" + host + (loc && loc.port === obj.port ? "" : ":" + obj.port);
2737
2378
  return obj;
2738
2379
  }
2739
2380
 
2740
2381
  var withNativeArrayBuffer = typeof ArrayBuffer === "function";
2741
-
2742
2382
  var isView = function isView(obj) {
2743
2383
  return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj.buffer instanceof ArrayBuffer;
2744
2384
  };
2745
-
2746
2385
  var toString = Object.prototype.toString;
2747
2386
  var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && toString.call(Blob) === "[object BlobConstructor]";
2748
2387
  var withNativeFile = typeof File === "function" || typeof File !== "undefined" && toString.call(File) === "[object FileConstructor]";
@@ -2751,7 +2390,6 @@
2751
2390
  *
2752
2391
  * @private
2753
2392
  */
2754
-
2755
2393
  function isBinary(obj) {
2756
2394
  return withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)) || withNativeBlob && obj instanceof Blob || withNativeFile && obj instanceof File;
2757
2395
  }
@@ -2759,31 +2397,25 @@
2759
2397
  if (!obj || _typeof(obj) !== "object") {
2760
2398
  return false;
2761
2399
  }
2762
-
2763
2400
  if (Array.isArray(obj)) {
2764
2401
  for (var i = 0, l = obj.length; i < l; i++) {
2765
2402
  if (hasBinary(obj[i])) {
2766
2403
  return true;
2767
2404
  }
2768
2405
  }
2769
-
2770
2406
  return false;
2771
2407
  }
2772
-
2773
2408
  if (isBinary(obj)) {
2774
2409
  return true;
2775
2410
  }
2776
-
2777
2411
  if (obj.toJSON && typeof obj.toJSON === "function" && arguments.length === 1) {
2778
2412
  return hasBinary(obj.toJSON(), true);
2779
2413
  }
2780
-
2781
2414
  for (var key in obj) {
2782
2415
  if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
2783
2416
  return true;
2784
2417
  }
2785
2418
  }
2786
-
2787
2419
  return false;
2788
2420
  }
2789
2421
 
@@ -2794,23 +2426,19 @@
2794
2426
  * @return {Object} with deconstructed packet and list of buffers
2795
2427
  * @public
2796
2428
  */
2797
-
2798
2429
  function deconstructPacket(packet) {
2799
2430
  var buffers = [];
2800
2431
  var packetData = packet.data;
2801
2432
  var pack = packet;
2802
2433
  pack.data = _deconstructPacket(packetData, buffers);
2803
2434
  pack.attachments = buffers.length; // number of binary 'attachments'
2804
-
2805
2435
  return {
2806
2436
  packet: pack,
2807
2437
  buffers: buffers
2808
2438
  };
2809
2439
  }
2810
-
2811
2440
  function _deconstructPacket(data, buffers) {
2812
2441
  if (!data) return data;
2813
-
2814
2442
  if (isBinary(data)) {
2815
2443
  var placeholder = {
2816
2444
  _placeholder: true,
@@ -2820,24 +2448,19 @@
2820
2448
  return placeholder;
2821
2449
  } else if (Array.isArray(data)) {
2822
2450
  var newData = new Array(data.length);
2823
-
2824
2451
  for (var i = 0; i < data.length; i++) {
2825
2452
  newData[i] = _deconstructPacket(data[i], buffers);
2826
2453
  }
2827
-
2828
2454
  return newData;
2829
2455
  } else if (_typeof(data) === "object" && !(data instanceof Date)) {
2830
2456
  var _newData = {};
2831
-
2832
2457
  for (var key in data) {
2833
2458
  if (Object.prototype.hasOwnProperty.call(data, key)) {
2834
2459
  _newData[key] = _deconstructPacket(data[key], buffers);
2835
2460
  }
2836
2461
  }
2837
-
2838
2462
  return _newData;
2839
2463
  }
2840
-
2841
2464
  return data;
2842
2465
  }
2843
2466
  /**
@@ -2848,21 +2471,15 @@
2848
2471
  * @return {Object} reconstructed packet
2849
2472
  * @public
2850
2473
  */
2851
-
2852
-
2853
2474
  function reconstructPacket(packet, buffers) {
2854
2475
  packet.data = _reconstructPacket(packet.data, buffers);
2855
2476
  delete packet.attachments; // no longer useful
2856
-
2857
2477
  return packet;
2858
2478
  }
2859
-
2860
2479
  function _reconstructPacket(data, buffers) {
2861
2480
  if (!data) return data;
2862
-
2863
2481
  if (data && data._placeholder === true) {
2864
2482
  var isIndexValid = typeof data.num === "number" && data.num >= 0 && data.num < buffers.length;
2865
-
2866
2483
  if (isIndexValid) {
2867
2484
  return buffers[data.num]; // appropriate buffer (should be natural order anyway)
2868
2485
  } else {
@@ -2879,14 +2496,12 @@
2879
2496
  }
2880
2497
  }
2881
2498
  }
2882
-
2883
2499
  return data;
2884
2500
  }
2885
2501
 
2886
2502
  /**
2887
2503
  * These strings must not be used as event names, as they have a special meaning.
2888
2504
  */
2889
-
2890
2505
  var RESERVED_EVENTS$1 = ["connect", "connect_error", "disconnect", "disconnecting", "newListener", "removeListener" // used by the Node.js EventEmitter
2891
2506
  ];
2892
2507
  /**
@@ -2894,10 +2509,8 @@
2894
2509
  *
2895
2510
  * @public
2896
2511
  */
2897
-
2898
2512
  var protocol = 5;
2899
2513
  var PacketType;
2900
-
2901
2514
  (function (PacketType) {
2902
2515
  PacketType[PacketType["CONNECT"] = 0] = "CONNECT";
2903
2516
  PacketType[PacketType["DISCONNECT"] = 1] = "DISCONNECT";
@@ -2910,8 +2523,6 @@
2910
2523
  /**
2911
2524
  * A socket.io Encoder instance
2912
2525
  */
2913
-
2914
-
2915
2526
  var Encoder = /*#__PURE__*/function () {
2916
2527
  /**
2917
2528
  * Encoder constructor
@@ -2920,7 +2531,6 @@
2920
2531
  */
2921
2532
  function Encoder(replacer) {
2922
2533
  _classCallCheck(this, Encoder);
2923
-
2924
2534
  this.replacer = replacer;
2925
2535
  }
2926
2536
  /**
@@ -2929,8 +2539,6 @@
2929
2539
  *
2930
2540
  * @param {Object} obj - packet object
2931
2541
  */
2932
-
2933
-
2934
2542
  _createClass(Encoder, [{
2935
2543
  key: "encode",
2936
2544
  value: function encode(obj) {
@@ -2944,39 +2552,33 @@
2944
2552
  });
2945
2553
  }
2946
2554
  }
2947
-
2948
2555
  return [this.encodeAsString(obj)];
2949
2556
  }
2950
2557
  /**
2951
2558
  * Encode packet as string.
2952
2559
  */
2953
-
2954
2560
  }, {
2955
2561
  key: "encodeAsString",
2956
2562
  value: function encodeAsString(obj) {
2957
2563
  // first is type
2958
- var str = "" + obj.type; // attachments if we have them
2959
-
2564
+ var str = "" + obj.type;
2565
+ // attachments if we have them
2960
2566
  if (obj.type === PacketType.BINARY_EVENT || obj.type === PacketType.BINARY_ACK) {
2961
2567
  str += obj.attachments + "-";
2962
- } // if we have a namespace other than `/`
2568
+ }
2569
+ // if we have a namespace other than `/`
2963
2570
  // we append it followed by a comma `,`
2964
-
2965
-
2966
2571
  if (obj.nsp && "/" !== obj.nsp) {
2967
2572
  str += obj.nsp + ",";
2968
- } // immediately followed by the id
2969
-
2970
-
2573
+ }
2574
+ // immediately followed by the id
2971
2575
  if (null != obj.id) {
2972
2576
  str += obj.id;
2973
- } // json data
2974
-
2975
-
2577
+ }
2578
+ // json data
2976
2579
  if (null != obj.data) {
2977
2580
  str += JSON.stringify(obj.data, this.replacer);
2978
2581
  }
2979
-
2980
2582
  return str;
2981
2583
  }
2982
2584
  /**
@@ -2984,7 +2586,6 @@
2984
2586
  * deconstructing packet into object with placeholders and
2985
2587
  * a list of buffers.
2986
2588
  */
2987
-
2988
2589
  }, {
2989
2590
  key: "encodeAsBinary",
2990
2591
  value: function encodeAsBinary(obj) {
@@ -2992,14 +2593,12 @@
2992
2593
  var pack = this.encodeAsString(deconstruction.packet);
2993
2594
  var buffers = deconstruction.buffers;
2994
2595
  buffers.unshift(pack); // add packet info to beginning of data list
2995
-
2996
2596
  return buffers; // write all the buffers
2997
2597
  }
2998
2598
  }]);
2999
-
3000
2599
  return Encoder;
3001
- }(); // see https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript
3002
-
2600
+ }();
2601
+ // see https://stackoverflow.com/questions/8511281/check-if-a-value-is-an-object-in-javascript
3003
2602
  function isObject(value) {
3004
2603
  return Object.prototype.toString.call(value) === "[object Object]";
3005
2604
  }
@@ -3008,13 +2607,9 @@
3008
2607
  *
3009
2608
  * @return {Object} decoder
3010
2609
  */
3011
-
3012
-
3013
2610
  var Decoder = /*#__PURE__*/function (_Emitter) {
3014
2611
  _inherits(Decoder, _Emitter);
3015
-
3016
2612
  var _super = _createSuper(Decoder);
3017
-
3018
2613
  /**
3019
2614
  * Decoder constructor
3020
2615
  *
@@ -3022,9 +2617,7 @@
3022
2617
  */
3023
2618
  function Decoder(reviver) {
3024
2619
  var _this;
3025
-
3026
2620
  _classCallCheck(this, Decoder);
3027
-
3028
2621
  _this = _super.call(this);
3029
2622
  _this.reviver = reviver;
3030
2623
  return _this;
@@ -3034,26 +2627,21 @@
3034
2627
  *
3035
2628
  * @param {String} obj - encoded packet
3036
2629
  */
3037
-
3038
-
3039
2630
  _createClass(Decoder, [{
3040
2631
  key: "add",
3041
2632
  value: function add(obj) {
3042
2633
  var packet;
3043
-
3044
2634
  if (typeof obj === "string") {
3045
2635
  if (this.reconstructor) {
3046
2636
  throw new Error("got plaintext data when reconstructing a packet");
3047
2637
  }
3048
-
3049
2638
  packet = this.decodeString(obj);
3050
2639
  var isBinaryEvent = packet.type === PacketType.BINARY_EVENT;
3051
-
3052
2640
  if (isBinaryEvent || packet.type === PacketType.BINARY_ACK) {
3053
- packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK; // binary packet's json
3054
-
3055
- this.reconstructor = new BinaryReconstructor(packet); // no attachments, labeled binary but no binary data to follow
3056
-
2641
+ packet.type = isBinaryEvent ? PacketType.EVENT : PacketType.ACK;
2642
+ // binary packet's json
2643
+ this.reconstructor = new BinaryReconstructor(packet);
2644
+ // no attachments, labeled binary but no binary data to follow
3057
2645
  if (packet.attachments === 0) {
3058
2646
  _get(_getPrototypeOf(Decoder.prototype), "emitReserved", this).call(this, "decoded", packet);
3059
2647
  }
@@ -3067,11 +2655,9 @@
3067
2655
  throw new Error("got binary data when not reconstructing a packet");
3068
2656
  } else {
3069
2657
  packet = this.reconstructor.takeBinaryData(obj);
3070
-
3071
2658
  if (packet) {
3072
2659
  // received final buffer
3073
2660
  this.reconstructor = null;
3074
-
3075
2661
  _get(_getPrototypeOf(Decoder.prototype), "emitReserved", this).call(this, "decoded", packet);
3076
2662
  }
3077
2663
  }
@@ -3085,81 +2671,62 @@
3085
2671
  * @param {String} str
3086
2672
  * @return {Object} packet
3087
2673
  */
3088
-
3089
2674
  }, {
3090
2675
  key: "decodeString",
3091
2676
  value: function decodeString(str) {
3092
- var i = 0; // look up type
3093
-
2677
+ var i = 0;
2678
+ // look up type
3094
2679
  var p = {
3095
2680
  type: Number(str.charAt(0))
3096
2681
  };
3097
-
3098
2682
  if (PacketType[p.type] === undefined) {
3099
2683
  throw new Error("unknown packet type " + p.type);
3100
- } // look up attachments if type binary
3101
-
3102
-
2684
+ }
2685
+ // look up attachments if type binary
3103
2686
  if (p.type === PacketType.BINARY_EVENT || p.type === PacketType.BINARY_ACK) {
3104
2687
  var start = i + 1;
3105
-
3106
2688
  while (str.charAt(++i) !== "-" && i != str.length) {}
3107
-
3108
2689
  var buf = str.substring(start, i);
3109
-
3110
2690
  if (buf != Number(buf) || str.charAt(i) !== "-") {
3111
2691
  throw new Error("Illegal attachments");
3112
2692
  }
3113
-
3114
2693
  p.attachments = Number(buf);
3115
- } // look up namespace (if any)
3116
-
3117
-
2694
+ }
2695
+ // look up namespace (if any)
3118
2696
  if ("/" === str.charAt(i + 1)) {
3119
2697
  var _start = i + 1;
3120
-
3121
2698
  while (++i) {
3122
2699
  var c = str.charAt(i);
3123
2700
  if ("," === c) break;
3124
2701
  if (i === str.length) break;
3125
2702
  }
3126
-
3127
2703
  p.nsp = str.substring(_start, i);
3128
2704
  } else {
3129
2705
  p.nsp = "/";
3130
- } // look up id
3131
-
3132
-
2706
+ }
2707
+ // look up id
3133
2708
  var next = str.charAt(i + 1);
3134
-
3135
2709
  if ("" !== next && Number(next) == next) {
3136
2710
  var _start2 = i + 1;
3137
-
3138
2711
  while (++i) {
3139
2712
  var _c = str.charAt(i);
3140
-
3141
2713
  if (null == _c || Number(_c) != _c) {
3142
2714
  --i;
3143
2715
  break;
3144
2716
  }
3145
-
3146
2717
  if (i === str.length) break;
3147
2718
  }
3148
-
3149
2719
  p.id = Number(str.substring(_start2, i + 1));
3150
- } // look up json data
3151
-
3152
-
2720
+ }
2721
+ // look up json data
3153
2722
  if (str.charAt(++i)) {
3154
2723
  var payload = this.tryParse(str.substr(i));
3155
-
3156
2724
  if (Decoder.isPayloadValid(p.type, payload)) {
3157
2725
  p.data = payload;
3158
2726
  } else {
3159
2727
  throw new Error("invalid payload");
3160
2728
  }
3161
2729
  }
3162
-
3163
2730
  return p;
3164
2731
  }
3165
2732
  }, {
@@ -3189,24 +2756,19 @@
3189
2756
  switch (type) {
3190
2757
  case PacketType.CONNECT:
3191
2758
  return isObject(payload);
3192
-
3193
2759
  case PacketType.DISCONNECT:
3194
2760
  return payload === undefined;
3195
-
3196
2761
  case PacketType.CONNECT_ERROR:
3197
2762
  return typeof payload === "string" || isObject(payload);
3198
-
3199
2763
  case PacketType.EVENT:
3200
2764
  case PacketType.BINARY_EVENT:
3201
2765
  return Array.isArray(payload) && (typeof payload[0] === "number" || typeof payload[0] === "string" && RESERVED_EVENTS$1.indexOf(payload[0]) === -1);
3202
-
3203
2766
  case PacketType.ACK:
3204
2767
  case PacketType.BINARY_ACK:
3205
2768
  return Array.isArray(payload);
3206
2769
  }
3207
2770
  }
3208
2771
  }]);
3209
-
3210
2772
  return Decoder;
3211
2773
  }(Emitter);
3212
2774
  /**
@@ -3217,11 +2779,9 @@
3217
2779
  * @param {Object} packet
3218
2780
  * @return {BinaryReconstructor} initialized reconstructor
3219
2781
  */
3220
-
3221
2782
  var BinaryReconstructor = /*#__PURE__*/function () {
3222
2783
  function BinaryReconstructor(packet) {
3223
2784
  _classCallCheck(this, BinaryReconstructor);
3224
-
3225
2785
  this.packet = packet;
3226
2786
  this.buffers = [];
3227
2787
  this.reconPack = packet;
@@ -3234,26 +2794,21 @@
3234
2794
  * @return {null | Object} returns null if more binary data is expected or
3235
2795
  * a reconstructed packet object if all buffers have been received.
3236
2796
  */
3237
-
3238
-
3239
2797
  _createClass(BinaryReconstructor, [{
3240
2798
  key: "takeBinaryData",
3241
2799
  value: function takeBinaryData(binData) {
3242
2800
  this.buffers.push(binData);
3243
-
3244
2801
  if (this.buffers.length === this.reconPack.attachments) {
3245
2802
  // done with buffer list
3246
2803
  var packet = reconstructPacket(this.reconPack, this.buffers);
3247
2804
  this.finishedReconstruction();
3248
2805
  return packet;
3249
2806
  }
3250
-
3251
2807
  return null;
3252
2808
  }
3253
2809
  /**
3254
2810
  * Cleans up binary packet reconstruction variables.
3255
2811
  */
3256
-
3257
2812
  }, {
3258
2813
  key: "finishedReconstruction",
3259
2814
  value: function finishedReconstruction() {
@@ -3261,7 +2816,6 @@
3261
2816
  this.buffers = [];
3262
2817
  }
3263
2818
  }]);
3264
-
3265
2819
  return BinaryReconstructor;
3266
2820
  }();
3267
2821
 
@@ -3284,7 +2838,6 @@
3284
2838
  * Internal events.
3285
2839
  * These events can't be emitted by the user.
3286
2840
  */
3287
-
3288
2841
  var RESERVED_EVENTS = Object.freeze({
3289
2842
  connect: 1,
3290
2843
  connect_error: 1,
@@ -3318,20 +2871,15 @@
3318
2871
  * console.log(`disconnected due to ${reason}`);
3319
2872
  * });
3320
2873
  */
3321
-
3322
2874
  var Socket = /*#__PURE__*/function (_Emitter) {
3323
2875
  _inherits(Socket, _Emitter);
3324
-
3325
2876
  var _super = _createSuper(Socket);
3326
-
3327
2877
  /**
3328
2878
  * `Socket` constructor.
3329
2879
  */
3330
2880
  function Socket(io, nsp, opts) {
3331
2881
  var _this;
3332
-
3333
2882
  _classCallCheck(this, Socket);
3334
-
3335
2883
  _this = _super.call(this);
3336
2884
  /**
3337
2885
  * Whether the socket is currently connected to the server.
@@ -3347,23 +2895,19 @@
3347
2895
  * console.log(socket.connected); // false
3348
2896
  * });
3349
2897
  */
3350
-
3351
2898
  _this.connected = false;
3352
2899
  /**
3353
2900
  * Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
3354
2901
  * be transmitted by the server.
3355
2902
  */
3356
-
3357
2903
  _this.recovered = false;
3358
2904
  /**
3359
2905
  * Buffer for packets received before the CONNECT packet
3360
2906
  */
3361
-
3362
2907
  _this.receiveBuffer = [];
3363
2908
  /**
3364
2909
  * Buffer for packets that will be sent once the socket is connected
3365
2910
  */
3366
-
3367
2911
  _this.sendBuffer = [];
3368
2912
  /**
3369
2913
  * The queue of packets to be sent with retry in case of failure.
@@ -3371,24 +2915,20 @@
3371
2915
  * Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
3372
2916
  * @private
3373
2917
  */
3374
-
3375
2918
  _this._queue = [];
3376
2919
  /**
3377
2920
  * A sequence to generate the ID of the {@link QueuedPacket}.
3378
2921
  * @private
3379
2922
  */
3380
-
3381
2923
  _this._queueSeq = 0;
3382
2924
  _this.ids = 0;
3383
2925
  _this.acks = {};
3384
2926
  _this.flags = {};
3385
2927
  _this.io = io;
3386
2928
  _this.nsp = nsp;
3387
-
3388
2929
  if (opts && opts.auth) {
3389
2930
  _this.auth = opts.auth;
3390
2931
  }
3391
-
3392
2932
  _this._opts = _extends({}, opts);
3393
2933
  if (_this.io._autoConnect) _this.open();
3394
2934
  return _this;
@@ -3407,8 +2947,6 @@
3407
2947
  * console.log(socket.disconnected); // true
3408
2948
  * });
3409
2949
  */
3410
-
3411
-
3412
2950
  _createClass(Socket, [{
3413
2951
  key: "disconnected",
3414
2952
  get: function get() {
@@ -3419,7 +2957,6 @@
3419
2957
  *
3420
2958
  * @private
3421
2959
  */
3422
-
3423
2960
  }, {
3424
2961
  key: "subEvents",
3425
2962
  value: function subEvents() {
@@ -3444,7 +2981,6 @@
3444
2981
  * console.log(socket.active); // true
3445
2982
  * });
3446
2983
  */
3447
-
3448
2984
  }, {
3449
2985
  key: "active",
3450
2986
  get: function get() {
@@ -3460,21 +2996,18 @@
3460
2996
  *
3461
2997
  * socket.connect();
3462
2998
  */
3463
-
3464
2999
  }, {
3465
3000
  key: "connect",
3466
3001
  value: function connect() {
3467
3002
  if (this.connected) return this;
3468
3003
  this.subEvents();
3469
3004
  if (!this.io["_reconnecting"]) this.io.open(); // ensure open
3470
-
3471
3005
  if ("open" === this.io._readyState) this.onopen();
3472
3006
  return this;
3473
3007
  }
3474
3008
  /**
3475
3009
  * Alias for {@link connect()}.
3476
3010
  */
3477
-
3478
3011
  }, {
3479
3012
  key: "open",
3480
3013
  value: function open() {
@@ -3495,14 +3028,12 @@
3495
3028
  *
3496
3029
  * @return self
3497
3030
  */
3498
-
3499
3031
  }, {
3500
3032
  key: "send",
3501
3033
  value: function send() {
3502
3034
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3503
3035
  args[_key] = arguments[_key];
3504
3036
  }
3505
-
3506
3037
  args.unshift("message");
3507
3038
  this.emit.apply(this, args);
3508
3039
  return this;
@@ -3524,94 +3055,73 @@
3524
3055
  *
3525
3056
  * @return self
3526
3057
  */
3527
-
3528
3058
  }, {
3529
3059
  key: "emit",
3530
3060
  value: function emit(ev) {
3531
3061
  if (RESERVED_EVENTS.hasOwnProperty(ev)) {
3532
3062
  throw new Error('"' + ev.toString() + '" is a reserved event name');
3533
3063
  }
3534
-
3535
3064
  for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
3536
3065
  args[_key2 - 1] = arguments[_key2];
3537
3066
  }
3538
-
3539
3067
  args.unshift(ev);
3540
-
3541
3068
  if (this._opts.retries && !this.flags.fromQueue && !this.flags["volatile"]) {
3542
3069
  this._addToQueue(args);
3543
-
3544
3070
  return this;
3545
3071
  }
3546
-
3547
3072
  var packet = {
3548
3073
  type: PacketType.EVENT,
3549
3074
  data: args
3550
3075
  };
3551
3076
  packet.options = {};
3552
- packet.options.compress = this.flags.compress !== false; // event ack callback
3553
-
3077
+ packet.options.compress = this.flags.compress !== false;
3078
+ // event ack callback
3554
3079
  if ("function" === typeof args[args.length - 1]) {
3555
3080
  var id = this.ids++;
3556
3081
  var ack = args.pop();
3557
-
3558
3082
  this._registerAckCallback(id, ack);
3559
-
3560
3083
  packet.id = id;
3561
3084
  }
3562
-
3563
3085
  var isTransportWritable = this.io.engine && this.io.engine.transport && this.io.engine.transport.writable;
3564
3086
  var discardPacket = this.flags["volatile"] && (!isTransportWritable || !this.connected);
3565
-
3566
3087
  if (discardPacket) ; else if (this.connected) {
3567
3088
  this.notifyOutgoingListeners(packet);
3568
3089
  this.packet(packet);
3569
3090
  } else {
3570
3091
  this.sendBuffer.push(packet);
3571
3092
  }
3572
-
3573
3093
  this.flags = {};
3574
3094
  return this;
3575
3095
  }
3576
3096
  /**
3577
3097
  * @private
3578
3098
  */
3579
-
3580
3099
  }, {
3581
3100
  key: "_registerAckCallback",
3582
3101
  value: function _registerAckCallback(id, ack) {
3583
3102
  var _this2 = this;
3584
-
3585
3103
  var _a;
3586
-
3587
3104
  var timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
3588
-
3589
3105
  if (timeout === undefined) {
3590
3106
  this.acks[id] = ack;
3591
3107
  return;
3592
- } // @ts-ignore
3593
-
3594
-
3108
+ }
3109
+ // @ts-ignore
3595
3110
  var timer = this.io.setTimeoutFn(function () {
3596
3111
  delete _this2.acks[id];
3597
-
3598
3112
  for (var i = 0; i < _this2.sendBuffer.length; i++) {
3599
3113
  if (_this2.sendBuffer[i].id === id) {
3600
3114
  _this2.sendBuffer.splice(i, 1);
3601
3115
  }
3602
3116
  }
3603
-
3604
3117
  ack.call(_this2, new Error("operation has timed out"));
3605
3118
  }, timeout);
3606
-
3607
3119
  this.acks[id] = function () {
3608
3120
  // @ts-ignore
3609
3121
  _this2.io.clearTimeoutFn(timer);
3610
-
3611
3122
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
3612
3123
  args[_key3] = arguments[_key3];
3613
3124
  }
3614
-
3615
3125
  ack.apply(_this2, [null].concat(args));
3616
3126
  };
3617
3127
  }
@@ -3631,16 +3141,13 @@
3631
3141
  *
3632
3142
  * @return a Promise that will be fulfilled when the server acknowledges the event
3633
3143
  */
3634
-
3635
3144
  }, {
3636
3145
  key: "emitWithAck",
3637
3146
  value: function emitWithAck(ev) {
3638
3147
  var _this3 = this;
3639
-
3640
3148
  for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
3641
3149
  args[_key4 - 1] = arguments[_key4];
3642
3150
  }
3643
-
3644
3151
  // the timeout flag is optional
3645
3152
  var withErr = this.flags.timeout !== undefined || this._opts.ackTimeout !== undefined;
3646
3153
  return new Promise(function (resolve, reject) {
@@ -3651,7 +3158,6 @@
3651
3158
  return resolve(arg1);
3652
3159
  }
3653
3160
  });
3654
-
3655
3161
  _this3.emit.apply(_this3, [ev].concat(args));
3656
3162
  });
3657
3163
  }
@@ -3660,18 +3166,14 @@
3660
3166
  * @param args
3661
3167
  * @private
3662
3168
  */
3663
-
3664
3169
  }, {
3665
3170
  key: "_addToQueue",
3666
3171
  value: function _addToQueue(args) {
3667
3172
  var _this4 = this;
3668
-
3669
3173
  var ack;
3670
-
3671
3174
  if (typeof args[args.length - 1] === "function") {
3672
3175
  ack = args.pop();
3673
3176
  }
3674
-
3675
3177
  var packet = {
3676
3178
  id: this._queueSeq++,
3677
3179
  tryCount: 0,
@@ -3686,35 +3188,27 @@
3686
3188
  // the packet has already been acknowledged
3687
3189
  return;
3688
3190
  }
3689
-
3690
3191
  var hasError = err !== null;
3691
-
3692
3192
  if (hasError) {
3693
3193
  if (packet.tryCount > _this4._opts.retries) {
3694
3194
  _this4._queue.shift();
3695
-
3696
3195
  if (ack) {
3697
3196
  ack(err);
3698
3197
  }
3699
3198
  }
3700
3199
  } else {
3701
3200
  _this4._queue.shift();
3702
-
3703
3201
  if (ack) {
3704
3202
  for (var _len5 = arguments.length, responseArgs = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) {
3705
3203
  responseArgs[_key5 - 1] = arguments[_key5];
3706
3204
  }
3707
-
3708
3205
  ack.apply(void 0, [null].concat(responseArgs));
3709
3206
  }
3710
3207
  }
3711
-
3712
3208
  packet.pending = false;
3713
3209
  return _this4._drainQueue();
3714
3210
  });
3715
-
3716
3211
  this._queue.push(packet);
3717
-
3718
3212
  this._drainQueue();
3719
3213
  }
3720
3214
  /**
@@ -3723,22 +3217,17 @@
3723
3217
  *
3724
3218
  * @private
3725
3219
  */
3726
-
3727
3220
  }, {
3728
3221
  key: "_drainQueue",
3729
3222
  value: function _drainQueue() {
3730
3223
  var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
3731
-
3732
3224
  if (!this.connected || this._queue.length === 0) {
3733
3225
  return;
3734
3226
  }
3735
-
3736
3227
  var packet = this._queue[0];
3737
-
3738
3228
  if (packet.pending && !force) {
3739
3229
  return;
3740
3230
  }
3741
-
3742
3231
  packet.pending = true;
3743
3232
  packet.tryCount++;
3744
3233
  this.flags = packet.flags;
@@ -3750,12 +3239,10 @@
3750
3239
  * @param packet
3751
3240
  * @private
3752
3241
  */
3753
-
3754
3242
  }, {
3755
3243
  key: "packet",
3756
3244
  value: function packet(_packet) {
3757
3245
  _packet.nsp = this.nsp;
3758
-
3759
3246
  this.io._packet(_packet);
3760
3247
  }
3761
3248
  /**
@@ -3763,12 +3250,10 @@
3763
3250
  *
3764
3251
  * @private
3765
3252
  */
3766
-
3767
3253
  }, {
3768
3254
  key: "onopen",
3769
3255
  value: function onopen() {
3770
3256
  var _this5 = this;
3771
-
3772
3257
  if (typeof this.auth == "function") {
3773
3258
  this.auth(function (data) {
3774
3259
  _this5._sendConnectPacket(data);
@@ -3783,7 +3268,6 @@
3783
3268
  * @param data
3784
3269
  * @private
3785
3270
  */
3786
-
3787
3271
  }, {
3788
3272
  key: "_sendConnectPacket",
3789
3273
  value: function _sendConnectPacket(data) {
@@ -3801,7 +3285,6 @@
3801
3285
  * @param err
3802
3286
  * @private
3803
3287
  */
3804
-
3805
3288
  }, {
3806
3289
  key: "onerror",
3807
3290
  value: function onerror(err) {
@@ -3816,7 +3299,6 @@
3816
3299
  * @param description
3817
3300
  * @private
3818
3301
  */
3819
-
3820
3302
  }, {
3821
3303
  key: "onclose",
3822
3304
  value: function onclose(reason, description) {
@@ -3830,13 +3312,11 @@
3830
3312
  * @param packet
3831
3313
  * @private
3832
3314
  */
3833
-
3834
3315
  }, {
3835
3316
  key: "onpacket",
3836
3317
  value: function onpacket(packet) {
3837
3318
  var sameNamespace = packet.nsp === this.nsp;
3838
3319
  if (!sameNamespace) return;
3839
-
3840
3320
  switch (packet.type) {
3841
3321
  case PacketType.CONNECT:
3842
3322
  if (packet.data && packet.data.sid) {
@@ -3844,27 +3324,22 @@
3844
3324
  } else {
3845
3325
  this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
3846
3326
  }
3847
-
3848
3327
  break;
3849
-
3850
3328
  case PacketType.EVENT:
3851
3329
  case PacketType.BINARY_EVENT:
3852
3330
  this.onevent(packet);
3853
3331
  break;
3854
-
3855
3332
  case PacketType.ACK:
3856
3333
  case PacketType.BINARY_ACK:
3857
3334
  this.onack(packet);
3858
3335
  break;
3859
-
3860
3336
  case PacketType.DISCONNECT:
3861
3337
  this.ondisconnect();
3862
3338
  break;
3863
-
3864
3339
  case PacketType.CONNECT_ERROR:
3865
3340
  this.destroy();
3866
- var err = new Error(packet.data.message); // @ts-ignore
3867
-
3341
+ var err = new Error(packet.data.message);
3342
+ // @ts-ignore
3868
3343
  err.data = packet.data.data;
3869
3344
  this.emitReserved("connect_error", err);
3870
3345
  break;
@@ -3876,16 +3351,13 @@
3876
3351
  * @param packet
3877
3352
  * @private
3878
3353
  */
3879
-
3880
3354
  }, {
3881
3355
  key: "onevent",
3882
3356
  value: function onevent(packet) {
3883
3357
  var args = packet.data || [];
3884
-
3885
3358
  if (null != packet.id) {
3886
3359
  args.push(this.ack(packet.id));
3887
3360
  }
3888
-
3889
3361
  if (this.connected) {
3890
3362
  this.emitEvent(args);
3891
3363
  } else {
@@ -3897,10 +3369,8 @@
3897
3369
  value: function emitEvent(args) {
3898
3370
  if (this._anyListeners && this._anyListeners.length) {
3899
3371
  var listeners = this._anyListeners.slice();
3900
-
3901
3372
  var _iterator = _createForOfIteratorHelper(listeners),
3902
- _step;
3903
-
3373
+ _step;
3904
3374
  try {
3905
3375
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
3906
3376
  var listener = _step.value;
@@ -3912,9 +3382,7 @@
3912
3382
  _iterator.f();
3913
3383
  }
3914
3384
  }
3915
-
3916
3385
  _get(_getPrototypeOf(Socket.prototype), "emit", this).apply(this, args);
3917
-
3918
3386
  if (this._pid && args.length && typeof args[args.length - 1] === "string") {
3919
3387
  this._lastOffset = args[args.length - 1];
3920
3388
  }
@@ -3924,7 +3392,6 @@
3924
3392
  *
3925
3393
  * @private
3926
3394
  */
3927
-
3928
3395
  }, {
3929
3396
  key: "ack",
3930
3397
  value: function ack(id) {
@@ -3934,11 +3401,9 @@
3934
3401
  // prevent double callbacks
3935
3402
  if (sent) return;
3936
3403
  sent = true;
3937
-
3938
3404
  for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
3939
3405
  args[_key6] = arguments[_key6];
3940
3406
  }
3941
-
3942
3407
  self.packet({
3943
3408
  type: PacketType.ACK,
3944
3409
  id: id,
@@ -3952,12 +3417,10 @@
3952
3417
  * @param packet
3953
3418
  * @private
3954
3419
  */
3955
-
3956
3420
  }, {
3957
3421
  key: "onack",
3958
3422
  value: function onack(packet) {
3959
3423
  var ack = this.acks[packet.id];
3960
-
3961
3424
  if ("function" === typeof ack) {
3962
3425
  ack.apply(this, packet.data);
3963
3426
  delete this.acks[packet.id];
@@ -3968,18 +3431,15 @@
3968
3431
  *
3969
3432
  * @private
3970
3433
  */
3971
-
3972
3434
  }, {
3973
3435
  key: "onconnect",
3974
3436
  value: function onconnect(id, pid) {
3975
3437
  this.id = id;
3976
3438
  this.recovered = pid && this._pid === pid;
3977
3439
  this._pid = pid; // defined only if connection state recovery is enabled
3978
-
3979
3440
  this.connected = true;
3980
3441
  this.emitBuffered();
3981
3442
  this.emitReserved("connect");
3982
-
3983
3443
  this._drainQueue(true);
3984
3444
  }
3985
3445
  /**
@@ -3987,19 +3447,16 @@
3987
3447
  *
3988
3448
  * @private
3989
3449
  */
3990
-
3991
3450
  }, {
3992
3451
  key: "emitBuffered",
3993
3452
  value: function emitBuffered() {
3994
3453
  var _this6 = this;
3995
-
3996
3454
  this.receiveBuffer.forEach(function (args) {
3997
3455
  return _this6.emitEvent(args);
3998
3456
  });
3999
3457
  this.receiveBuffer = [];
4000
3458
  this.sendBuffer.forEach(function (packet) {
4001
3459
  _this6.notifyOutgoingListeners(packet);
4002
-
4003
3460
  _this6.packet(packet);
4004
3461
  });
4005
3462
  this.sendBuffer = [];
@@ -4009,7 +3466,6 @@
4009
3466
  *
4010
3467
  * @private
4011
3468
  */
4012
-
4013
3469
  }, {
4014
3470
  key: "ondisconnect",
4015
3471
  value: function ondisconnect() {
@@ -4023,7 +3479,6 @@
4023
3479
  *
4024
3480
  * @private
4025
3481
  */
4026
-
4027
3482
  }, {
4028
3483
  key: "destroy",
4029
3484
  value: function destroy() {
@@ -4034,7 +3489,6 @@
4034
3489
  });
4035
3490
  this.subs = undefined;
4036
3491
  }
4037
-
4038
3492
  this.io["_destroy"](this);
4039
3493
  }
4040
3494
  /**
@@ -4053,7 +3507,6 @@
4053
3507
  *
4054
3508
  * @return self
4055
3509
  */
4056
-
4057
3510
  }, {
4058
3511
  key: "disconnect",
4059
3512
  value: function disconnect() {
@@ -4061,16 +3514,13 @@
4061
3514
  this.packet({
4062
3515
  type: PacketType.DISCONNECT
4063
3516
  });
4064
- } // remove socket from pool
4065
-
4066
-
3517
+ }
3518
+ // remove socket from pool
4067
3519
  this.destroy();
4068
-
4069
3520
  if (this.connected) {
4070
3521
  // fire events
4071
3522
  this.onclose("io client disconnect");
4072
3523
  }
4073
-
4074
3524
  return this;
4075
3525
  }
4076
3526
  /**
@@ -4078,7 +3528,6 @@
4078
3528
  *
4079
3529
  * @return self
4080
3530
  */
4081
-
4082
3531
  }, {
4083
3532
  key: "close",
4084
3533
  value: function close() {
@@ -4093,7 +3542,6 @@
4093
3542
  * @param compress - if `true`, compresses the sending data
4094
3543
  * @return self
4095
3544
  */
4096
-
4097
3545
  }, {
4098
3546
  key: "compress",
4099
3547
  value: function compress(_compress) {
@@ -4109,7 +3557,6 @@
4109
3557
  *
4110
3558
  * @returns self
4111
3559
  */
4112
-
4113
3560
  }, {
4114
3561
  key: "volatile",
4115
3562
  get: function get() {
@@ -4129,7 +3576,6 @@
4129
3576
  *
4130
3577
  * @returns self
4131
3578
  */
4132
-
4133
3579
  }, {
4134
3580
  key: "timeout",
4135
3581
  value: function timeout(_timeout) {
@@ -4147,14 +3593,11 @@
4147
3593
  *
4148
3594
  * @param listener
4149
3595
  */
4150
-
4151
3596
  }, {
4152
3597
  key: "onAny",
4153
3598
  value: function onAny(listener) {
4154
3599
  this._anyListeners = this._anyListeners || [];
4155
-
4156
3600
  this._anyListeners.push(listener);
4157
-
4158
3601
  return this;
4159
3602
  }
4160
3603
  /**
@@ -4168,14 +3611,11 @@
4168
3611
  *
4169
3612
  * @param listener
4170
3613
  */
4171
-
4172
3614
  }, {
4173
3615
  key: "prependAny",
4174
3616
  value: function prependAny(listener) {
4175
3617
  this._anyListeners = this._anyListeners || [];
4176
-
4177
3618
  this._anyListeners.unshift(listener);
4178
-
4179
3619
  return this;
4180
3620
  }
4181
3621
  /**
@@ -4196,17 +3636,14 @@
4196
3636
  *
4197
3637
  * @param listener
4198
3638
  */
4199
-
4200
3639
  }, {
4201
3640
  key: "offAny",
4202
3641
  value: function offAny(listener) {
4203
3642
  if (!this._anyListeners) {
4204
3643
  return this;
4205
3644
  }
4206
-
4207
3645
  if (listener) {
4208
3646
  var listeners = this._anyListeners;
4209
-
4210
3647
  for (var i = 0; i < listeners.length; i++) {
4211
3648
  if (listener === listeners[i]) {
4212
3649
  listeners.splice(i, 1);
@@ -4216,14 +3653,12 @@
4216
3653
  } else {
4217
3654
  this._anyListeners = [];
4218
3655
  }
4219
-
4220
3656
  return this;
4221
3657
  }
4222
3658
  /**
4223
3659
  * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
4224
3660
  * e.g. to remove listeners.
4225
3661
  */
4226
-
4227
3662
  }, {
4228
3663
  key: "listenersAny",
4229
3664
  value: function listenersAny() {
@@ -4242,14 +3677,11 @@
4242
3677
  *
4243
3678
  * @param listener
4244
3679
  */
4245
-
4246
3680
  }, {
4247
3681
  key: "onAnyOutgoing",
4248
3682
  value: function onAnyOutgoing(listener) {
4249
3683
  this._anyOutgoingListeners = this._anyOutgoingListeners || [];
4250
-
4251
3684
  this._anyOutgoingListeners.push(listener);
4252
-
4253
3685
  return this;
4254
3686
  }
4255
3687
  /**
@@ -4265,14 +3697,11 @@
4265
3697
  *
4266
3698
  * @param listener
4267
3699
  */
4268
-
4269
3700
  }, {
4270
3701
  key: "prependAnyOutgoing",
4271
3702
  value: function prependAnyOutgoing(listener) {
4272
3703
  this._anyOutgoingListeners = this._anyOutgoingListeners || [];
4273
-
4274
3704
  this._anyOutgoingListeners.unshift(listener);
4275
-
4276
3705
  return this;
4277
3706
  }
4278
3707
  /**
@@ -4293,17 +3722,14 @@
4293
3722
  *
4294
3723
  * @param [listener] - the catch-all listener (optional)
4295
3724
  */
4296
-
4297
3725
  }, {
4298
3726
  key: "offAnyOutgoing",
4299
3727
  value: function offAnyOutgoing(listener) {
4300
3728
  if (!this._anyOutgoingListeners) {
4301
3729
  return this;
4302
3730
  }
4303
-
4304
3731
  if (listener) {
4305
3732
  var listeners = this._anyOutgoingListeners;
4306
-
4307
3733
  for (var i = 0; i < listeners.length; i++) {
4308
3734
  if (listener === listeners[i]) {
4309
3735
  listeners.splice(i, 1);
@@ -4313,14 +3739,12 @@
4313
3739
  } else {
4314
3740
  this._anyOutgoingListeners = [];
4315
3741
  }
4316
-
4317
3742
  return this;
4318
3743
  }
4319
3744
  /**
4320
3745
  * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
4321
3746
  * e.g. to remove listeners.
4322
3747
  */
4323
-
4324
3748
  }, {
4325
3749
  key: "listenersAnyOutgoing",
4326
3750
  value: function listenersAnyOutgoing() {
@@ -4333,16 +3757,13 @@
4333
3757
  *
4334
3758
  * @private
4335
3759
  */
4336
-
4337
3760
  }, {
4338
3761
  key: "notifyOutgoingListeners",
4339
3762
  value: function notifyOutgoingListeners(packet) {
4340
3763
  if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
4341
3764
  var listeners = this._anyOutgoingListeners.slice();
4342
-
4343
3765
  var _iterator2 = _createForOfIteratorHelper(listeners),
4344
- _step2;
4345
-
3766
+ _step2;
4346
3767
  try {
4347
3768
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
4348
3769
  var listener = _step2.value;
@@ -4356,7 +3777,6 @@
4356
3777
  }
4357
3778
  }
4358
3779
  }]);
4359
-
4360
3780
  return Socket;
4361
3781
  }(Emitter);
4362
3782
 
@@ -4385,16 +3805,13 @@
4385
3805
  * @return {Number}
4386
3806
  * @api public
4387
3807
  */
4388
-
4389
3808
  Backoff.prototype.duration = function () {
4390
3809
  var ms = this.ms * Math.pow(this.factor, this.attempts++);
4391
-
4392
3810
  if (this.jitter) {
4393
3811
  var rand = Math.random();
4394
3812
  var deviation = Math.floor(rand * this.jitter * ms);
4395
3813
  ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
4396
3814
  }
4397
-
4398
3815
  return Math.min(ms, this.max) | 0;
4399
3816
  };
4400
3817
  /**
@@ -4402,8 +3819,6 @@
4402
3819
  *
4403
3820
  * @api public
4404
3821
  */
4405
-
4406
-
4407
3822
  Backoff.prototype.reset = function () {
4408
3823
  this.attempts = 0;
4409
3824
  };
@@ -4412,8 +3827,6 @@
4412
3827
  *
4413
3828
  * @api public
4414
3829
  */
4415
-
4416
-
4417
3830
  Backoff.prototype.setMin = function (min) {
4418
3831
  this.ms = min;
4419
3832
  };
@@ -4422,8 +3835,6 @@
4422
3835
  *
4423
3836
  * @api public
4424
3837
  */
4425
-
4426
-
4427
3838
  Backoff.prototype.setMax = function (max) {
4428
3839
  this.max = max;
4429
3840
  };
@@ -4432,68 +3843,48 @@
4432
3843
  *
4433
3844
  * @api public
4434
3845
  */
4435
-
4436
-
4437
3846
  Backoff.prototype.setJitter = function (jitter) {
4438
3847
  this.jitter = jitter;
4439
3848
  };
4440
3849
 
4441
3850
  var Manager = /*#__PURE__*/function (_Emitter) {
4442
3851
  _inherits(Manager, _Emitter);
4443
-
4444
3852
  var _super = _createSuper(Manager);
4445
-
4446
3853
  function Manager(uri, opts) {
4447
3854
  var _this;
4448
-
4449
3855
  _classCallCheck(this, Manager);
4450
-
4451
3856
  var _a;
4452
-
4453
3857
  _this = _super.call(this);
4454
3858
  _this.nsps = {};
4455
3859
  _this.subs = [];
4456
-
4457
3860
  if (uri && "object" === _typeof(uri)) {
4458
3861
  opts = uri;
4459
3862
  uri = undefined;
4460
3863
  }
4461
-
4462
3864
  opts = opts || {};
4463
3865
  opts.path = opts.path || "/socket.io";
4464
3866
  _this.opts = opts;
4465
3867
  installTimerFunctions(_assertThisInitialized(_this), opts);
4466
-
4467
3868
  _this.reconnection(opts.reconnection !== false);
4468
-
4469
3869
  _this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
4470
-
4471
3870
  _this.reconnectionDelay(opts.reconnectionDelay || 1000);
4472
-
4473
3871
  _this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
4474
-
4475
3872
  _this.randomizationFactor((_a = opts.randomizationFactor) !== null && _a !== void 0 ? _a : 0.5);
4476
-
4477
3873
  _this.backoff = new Backoff({
4478
3874
  min: _this.reconnectionDelay(),
4479
3875
  max: _this.reconnectionDelayMax(),
4480
3876
  jitter: _this.randomizationFactor()
4481
3877
  });
4482
-
4483
3878
  _this.timeout(null == opts.timeout ? 20000 : opts.timeout);
4484
-
4485
3879
  _this._readyState = "closed";
4486
3880
  _this.uri = uri;
4487
-
4488
3881
  var _parser = opts.parser || parser;
4489
-
4490
3882
  _this.encoder = new _parser.Encoder();
4491
3883
  _this.decoder = new _parser.Decoder();
4492
3884
  _this._autoConnect = opts.autoConnect !== false;
4493
3885
  if (_this._autoConnect) _this.open();
4494
3886
  return _this;
4495
3887
  }
4496
-
4497
3888
  _createClass(Manager, [{
4498
3889
  key: "reconnection",
4499
3890
  value: function reconnection(v) {
@@ -4512,7 +3903,6 @@
4512
3903
  key: "reconnectionDelay",
4513
3904
  value: function reconnectionDelay(v) {
4514
3905
  var _a;
4515
-
4516
3906
  if (v === undefined) return this._reconnectionDelay;
4517
3907
  this._reconnectionDelay = v;
4518
3908
  (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);
@@ -4522,7 +3912,6 @@
4522
3912
  key: "randomizationFactor",
4523
3913
  value: function randomizationFactor(v) {
4524
3914
  var _a;
4525
-
4526
3915
  if (v === undefined) return this._randomizationFactor;
4527
3916
  this._randomizationFactor = v;
4528
3917
  (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);
@@ -4532,7 +3921,6 @@
4532
3921
  key: "reconnectionDelayMax",
4533
3922
  value: function reconnectionDelayMax(v) {
4534
3923
  var _a;
4535
-
4536
3924
  if (v === undefined) return this._reconnectionDelayMax;
4537
3925
  this._reconnectionDelayMax = v;
4538
3926
  (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);
@@ -4551,7 +3939,6 @@
4551
3939
  *
4552
3940
  * @private
4553
3941
  */
4554
-
4555
3942
  }, {
4556
3943
  key: "maybeReconnectOnOpen",
4557
3944
  value: function maybeReconnectOnOpen() {
@@ -4568,60 +3955,49 @@
4568
3955
  * @return self
4569
3956
  * @public
4570
3957
  */
4571
-
4572
3958
  }, {
4573
3959
  key: "open",
4574
3960
  value: function open(fn) {
4575
3961
  var _this2 = this;
4576
-
4577
3962
  if (~this._readyState.indexOf("open")) return this;
4578
3963
  this.engine = new Socket$1(this.uri, this.opts);
4579
3964
  var socket = this.engine;
4580
3965
  var self = this;
4581
3966
  this._readyState = "opening";
4582
- this.skipReconnect = false; // emit `open`
4583
-
3967
+ this.skipReconnect = false;
3968
+ // emit `open`
4584
3969
  var openSubDestroy = on(socket, "open", function () {
4585
3970
  self.onopen();
4586
3971
  fn && fn();
4587
3972
  });
4588
-
4589
3973
  var onError = function onError(err) {
4590
3974
  _this2.cleanup();
4591
-
4592
3975
  _this2._readyState = "closed";
4593
-
4594
3976
  _this2.emitReserved("error", err);
4595
-
4596
3977
  if (fn) {
4597
3978
  fn(err);
4598
3979
  } else {
4599
3980
  // Only do this if there is no fn to handle the error
4600
3981
  _this2.maybeReconnectOnOpen();
4601
3982
  }
4602
- }; // emit `error`
4603
-
4604
-
3983
+ };
3984
+ // emit `error`
4605
3985
  var errorSub = on(socket, "error", onError);
4606
-
4607
3986
  if (false !== this._timeout) {
4608
- var timeout = this._timeout; // set timer
4609
-
3987
+ var timeout = this._timeout;
3988
+ // set timer
4610
3989
  var timer = this.setTimeoutFn(function () {
4611
3990
  openSubDestroy();
4612
3991
  onError(new Error("timeout"));
4613
3992
  socket.close();
4614
3993
  }, timeout);
4615
-
4616
3994
  if (this.opts.autoUnref) {
4617
3995
  timer.unref();
4618
3996
  }
4619
-
4620
3997
  this.subs.push(function () {
4621
3998
  _this2.clearTimeoutFn(timer);
4622
3999
  });
4623
4000
  }
4624
-
4625
4001
  this.subs.push(openSubDestroy);
4626
4002
  this.subs.push(errorSub);
4627
4003
  return this;
@@ -4632,7 +4008,6 @@
4632
4008
  * @return self
4633
4009
  * @public
4634
4010
  */
4635
-
4636
4011
  }, {
4637
4012
  key: "connect",
4638
4013
  value: function connect(fn) {
@@ -4643,16 +4018,15 @@
4643
4018
  *
4644
4019
  * @private
4645
4020
  */
4646
-
4647
4021
  }, {
4648
4022
  key: "onopen",
4649
4023
  value: function onopen() {
4650
4024
  // clear old subs
4651
- this.cleanup(); // mark as open
4652
-
4025
+ this.cleanup();
4026
+ // mark as open
4653
4027
  this._readyState = "open";
4654
- this.emitReserved("open"); // add new subs
4655
-
4028
+ this.emitReserved("open");
4029
+ // add new subs
4656
4030
  var socket = this.engine;
4657
4031
  this.subs.push(on(socket, "ping", this.onping.bind(this)), on(socket, "data", this.ondata.bind(this)), on(socket, "error", this.onerror.bind(this)), on(socket, "close", this.onclose.bind(this)), on(this.decoder, "decoded", this.ondecoded.bind(this)));
4658
4032
  }
@@ -4661,7 +4035,6 @@
4661
4035
  *
4662
4036
  * @private
4663
4037
  */
4664
-
4665
4038
  }, {
4666
4039
  key: "onping",
4667
4040
  value: function onping() {
@@ -4672,7 +4045,6 @@
4672
4045
  *
4673
4046
  * @private
4674
4047
  */
4675
-
4676
4048
  }, {
4677
4049
  key: "ondata",
4678
4050
  value: function ondata(data) {
@@ -4687,12 +4059,10 @@
4687
4059
  *
4688
4060
  * @private
4689
4061
  */
4690
-
4691
4062
  }, {
4692
4063
  key: "ondecoded",
4693
4064
  value: function ondecoded(packet) {
4694
4065
  var _this3 = this;
4695
-
4696
4066
  // the nextTick call prevents an exception in a user-provided event listener from triggering a disconnection due to a "parse error"
4697
4067
  nextTick(function () {
4698
4068
  _this3.emitReserved("packet", packet);
@@ -4703,7 +4073,6 @@
4703
4073
  *
4704
4074
  * @private
4705
4075
  */
4706
-
4707
4076
  }, {
4708
4077
  key: "onerror",
4709
4078
  value: function onerror(err) {
@@ -4715,19 +4084,16 @@
4715
4084
  * @return {Socket}
4716
4085
  * @public
4717
4086
  */
4718
-
4719
4087
  }, {
4720
4088
  key: "socket",
4721
4089
  value: function socket(nsp, opts) {
4722
4090
  var socket = this.nsps[nsp];
4723
-
4724
4091
  if (!socket) {
4725
4092
  socket = new Socket(this, nsp, opts);
4726
4093
  this.nsps[nsp] = socket;
4727
4094
  } else if (this._autoConnect && !socket.active) {
4728
4095
  socket.connect();
4729
4096
  }
4730
-
4731
4097
  return socket;
4732
4098
  }
4733
4099
  /**
@@ -4736,21 +4102,17 @@
4736
4102
  * @param socket
4737
4103
  * @private
4738
4104
  */
4739
-
4740
4105
  }, {
4741
4106
  key: "_destroy",
4742
4107
  value: function _destroy(socket) {
4743
4108
  var nsps = Object.keys(this.nsps);
4744
-
4745
4109
  for (var _i = 0, _nsps = nsps; _i < _nsps.length; _i++) {
4746
4110
  var nsp = _nsps[_i];
4747
4111
  var _socket = this.nsps[nsp];
4748
-
4749
4112
  if (_socket.active) {
4750
4113
  return;
4751
4114
  }
4752
4115
  }
4753
-
4754
4116
  this._close();
4755
4117
  }
4756
4118
  /**
@@ -4759,12 +4121,10 @@
4759
4121
  * @param packet
4760
4122
  * @private
4761
4123
  */
4762
-
4763
4124
  }, {
4764
4125
  key: "_packet",
4765
4126
  value: function _packet(packet) {
4766
4127
  var encodedPackets = this.encoder.encode(packet);
4767
-
4768
4128
  for (var i = 0; i < encodedPackets.length; i++) {
4769
4129
  this.engine.write(encodedPackets[i], packet.options);
4770
4130
  }
@@ -4774,7 +4134,6 @@
4774
4134
  *
4775
4135
  * @private
4776
4136
  */
4777
-
4778
4137
  }, {
4779
4138
  key: "cleanup",
4780
4139
  value: function cleanup() {
@@ -4789,7 +4148,6 @@
4789
4148
  *
4790
4149
  * @private
4791
4150
  */
4792
-
4793
4151
  }, {
4794
4152
  key: "_close",
4795
4153
  value: function _close() {
@@ -4803,7 +4161,6 @@
4803
4161
  *
4804
4162
  * @private
4805
4163
  */
4806
-
4807
4164
  }, {
4808
4165
  key: "disconnect",
4809
4166
  value: function disconnect() {
@@ -4814,7 +4171,6 @@
4814
4171
  *
4815
4172
  * @private
4816
4173
  */
4817
-
4818
4174
  }, {
4819
4175
  key: "onclose",
4820
4176
  value: function onclose(reason, description) {
@@ -4822,7 +4178,6 @@
4822
4178
  this.backoff.reset();
4823
4179
  this._readyState = "closed";
4824
4180
  this.emitReserved("close", reason, description);
4825
-
4826
4181
  if (this._reconnection && !this.skipReconnect) {
4827
4182
  this.reconnect();
4828
4183
  }
@@ -4832,15 +4187,12 @@
4832
4187
  *
4833
4188
  * @private
4834
4189
  */
4835
-
4836
4190
  }, {
4837
4191
  key: "reconnect",
4838
4192
  value: function reconnect() {
4839
4193
  var _this4 = this;
4840
-
4841
4194
  if (this._reconnecting || this.skipReconnect) return this;
4842
4195
  var self = this;
4843
-
4844
4196
  if (this.backoff.attempts >= this._reconnectionAttempts) {
4845
4197
  this.backoff.reset();
4846
4198
  this.emitReserved("reconnect_failed");
@@ -4850,27 +4202,22 @@
4850
4202
  this._reconnecting = true;
4851
4203
  var timer = this.setTimeoutFn(function () {
4852
4204
  if (self.skipReconnect) return;
4853
-
4854
- _this4.emitReserved("reconnect_attempt", self.backoff.attempts); // check again for the case socket closed in above events
4855
-
4856
-
4205
+ _this4.emitReserved("reconnect_attempt", self.backoff.attempts);
4206
+ // check again for the case socket closed in above events
4857
4207
  if (self.skipReconnect) return;
4858
4208
  self.open(function (err) {
4859
4209
  if (err) {
4860
4210
  self._reconnecting = false;
4861
4211
  self.reconnect();
4862
-
4863
4212
  _this4.emitReserved("reconnect_error", err);
4864
4213
  } else {
4865
4214
  self.onreconnect();
4866
4215
  }
4867
4216
  });
4868
4217
  }, delay);
4869
-
4870
4218
  if (this.opts.autoUnref) {
4871
4219
  timer.unref();
4872
4220
  }
4873
-
4874
4221
  this.subs.push(function () {
4875
4222
  _this4.clearTimeoutFn(timer);
4876
4223
  });
@@ -4881,7 +4228,6 @@
4881
4228
  *
4882
4229
  * @private
4883
4230
  */
4884
-
4885
4231
  }, {
4886
4232
  key: "onreconnect",
4887
4233
  value: function onreconnect() {
@@ -4891,22 +4237,18 @@
4891
4237
  this.emitReserved("reconnect", attempt);
4892
4238
  }
4893
4239
  }]);
4894
-
4895
4240
  return Manager;
4896
4241
  }(Emitter);
4897
4242
 
4898
4243
  /**
4899
4244
  * Managers cache.
4900
4245
  */
4901
-
4902
4246
  var cache = {};
4903
-
4904
4247
  function lookup(uri, opts) {
4905
4248
  if (_typeof(uri) === "object") {
4906
4249
  opts = uri;
4907
4250
  uri = undefined;
4908
4251
  }
4909
-
4910
4252
  opts = opts || {};
4911
4253
  var parsed = url(uri, opts.path || "/socket.io");
4912
4254
  var source = parsed.source;
@@ -4915,26 +4257,21 @@
4915
4257
  var sameNamespace = cache[id] && path in cache[id]["nsps"];
4916
4258
  var newConnection = opts.forceNew || opts["force new connection"] || false === opts.multiplex || sameNamespace;
4917
4259
  var io;
4918
-
4919
4260
  if (newConnection) {
4920
4261
  io = new Manager(source, opts);
4921
4262
  } else {
4922
4263
  if (!cache[id]) {
4923
4264
  cache[id] = new Manager(source, opts);
4924
4265
  }
4925
-
4926
4266
  io = cache[id];
4927
4267
  }
4928
-
4929
4268
  if (parsed.query && !opts.query) {
4930
4269
  opts.query = parsed.queryKey;
4931
4270
  }
4932
-
4933
4271
  return io.socket(parsed.path, opts);
4934
- } // so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
4272
+ }
4273
+ // so that "lookup" can be used both as a function (e.g. `io(...)`) and as a
4935
4274
  // namespace (e.g. `io.connect(...)`), for backward compatibility
4936
-
4937
-
4938
4275
  _extends(lookup, {
4939
4276
  Manager: Manager,
4940
4277
  Socket: Socket,