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