engine.io.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384
  1. /*!
  2. * Engine.IO v6.1.1
  3. * (c) 2014-2021 Guillermo Rauch
  4. * Released under the MIT License.
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  8. typeof define === 'function' && define.amd ? define(factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.eio = factory());
  10. })(this, (function () { 'use strict';
  11. function _typeof(obj) {
  12. "@babel/helpers - typeof";
  13. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  14. _typeof = function (obj) {
  15. return typeof obj;
  16. };
  17. } else {
  18. _typeof = function (obj) {
  19. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  20. };
  21. }
  22. return _typeof(obj);
  23. }
  24. function _classCallCheck(instance, Constructor) {
  25. if (!(instance instanceof Constructor)) {
  26. throw new TypeError("Cannot call a class as a function");
  27. }
  28. }
  29. function _defineProperties(target, props) {
  30. for (var i = 0; i < props.length; i++) {
  31. var descriptor = props[i];
  32. descriptor.enumerable = descriptor.enumerable || false;
  33. descriptor.configurable = true;
  34. if ("value" in descriptor) descriptor.writable = true;
  35. Object.defineProperty(target, descriptor.key, descriptor);
  36. }
  37. }
  38. function _createClass(Constructor, protoProps, staticProps) {
  39. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  40. if (staticProps) _defineProperties(Constructor, staticProps);
  41. return Constructor;
  42. }
  43. function _extends() {
  44. _extends = Object.assign || function (target) {
  45. for (var i = 1; i < arguments.length; i++) {
  46. var source = arguments[i];
  47. for (var key in source) {
  48. if (Object.prototype.hasOwnProperty.call(source, key)) {
  49. target[key] = source[key];
  50. }
  51. }
  52. }
  53. return target;
  54. };
  55. return _extends.apply(this, arguments);
  56. }
  57. function _inherits(subClass, superClass) {
  58. if (typeof superClass !== "function" && superClass !== null) {
  59. throw new TypeError("Super expression must either be null or a function");
  60. }
  61. subClass.prototype = Object.create(superClass && superClass.prototype, {
  62. constructor: {
  63. value: subClass,
  64. writable: true,
  65. configurable: true
  66. }
  67. });
  68. if (superClass) _setPrototypeOf(subClass, superClass);
  69. }
  70. function _getPrototypeOf(o) {
  71. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  72. return o.__proto__ || Object.getPrototypeOf(o);
  73. };
  74. return _getPrototypeOf(o);
  75. }
  76. function _setPrototypeOf(o, p) {
  77. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  78. o.__proto__ = p;
  79. return o;
  80. };
  81. return _setPrototypeOf(o, p);
  82. }
  83. function _isNativeReflectConstruct() {
  84. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  85. if (Reflect.construct.sham) return false;
  86. if (typeof Proxy === "function") return true;
  87. try {
  88. Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
  89. return true;
  90. } catch (e) {
  91. return false;
  92. }
  93. }
  94. function _assertThisInitialized(self) {
  95. if (self === void 0) {
  96. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  97. }
  98. return self;
  99. }
  100. function _possibleConstructorReturn(self, call) {
  101. if (call && (typeof call === "object" || typeof call === "function")) {
  102. return call;
  103. }
  104. return _assertThisInitialized(self);
  105. }
  106. function _createSuper(Derived) {
  107. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  108. return function _createSuperInternal() {
  109. var Super = _getPrototypeOf(Derived),
  110. result;
  111. if (hasNativeReflectConstruct) {
  112. var NewTarget = _getPrototypeOf(this).constructor;
  113. result = Reflect.construct(Super, arguments, NewTarget);
  114. } else {
  115. result = Super.apply(this, arguments);
  116. }
  117. return _possibleConstructorReturn(this, result);
  118. };
  119. }
  120. function _superPropBase(object, property) {
  121. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  122. object = _getPrototypeOf(object);
  123. if (object === null) break;
  124. }
  125. return object;
  126. }
  127. function _get(target, property, receiver) {
  128. if (typeof Reflect !== "undefined" && Reflect.get) {
  129. _get = Reflect.get;
  130. } else {
  131. _get = function _get(target, property, receiver) {
  132. var base = _superPropBase(target, property);
  133. if (!base) return;
  134. var desc = Object.getOwnPropertyDescriptor(base, property);
  135. if (desc.get) {
  136. return desc.get.call(receiver);
  137. }
  138. return desc.value;
  139. };
  140. }
  141. return _get(target, property, receiver || target);
  142. }
  143. var hasCors = {exports: {}};
  144. /**
  145. * Module exports.
  146. *
  147. * Logic borrowed from Modernizr:
  148. *
  149. * - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
  150. */
  151. try {
  152. hasCors.exports = typeof XMLHttpRequest !== 'undefined' && 'withCredentials' in new XMLHttpRequest();
  153. } catch (err) {
  154. // if XMLHttp support is disabled in IE then it will throw
  155. // when trying to create
  156. hasCors.exports = false;
  157. }
  158. var hasCORS = hasCors.exports;
  159. var globalThis = (function () {
  160. if (typeof self !== "undefined") {
  161. return self;
  162. } else if (typeof window !== "undefined") {
  163. return window;
  164. } else {
  165. return Function("return this")();
  166. }
  167. })();
  168. // browser shim for xmlhttprequest module
  169. function XMLHttpRequest$1 (opts) {
  170. var xdomain = opts.xdomain; // XMLHttpRequest can be disabled on IE
  171. try {
  172. if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
  173. return new XMLHttpRequest();
  174. }
  175. } catch (e) {}
  176. if (!xdomain) {
  177. try {
  178. return new globalThis[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
  179. } catch (e) {}
  180. }
  181. }
  182. function pick(obj) {
  183. for (var _len = arguments.length, attr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  184. attr[_key - 1] = arguments[_key];
  185. }
  186. return attr.reduce(function (acc, k) {
  187. if (obj.hasOwnProperty(k)) {
  188. acc[k] = obj[k];
  189. }
  190. return acc;
  191. }, {});
  192. } // Keep a reference to the real timeout functions so they can be used when overridden
  193. var NATIVE_SET_TIMEOUT = setTimeout;
  194. var NATIVE_CLEAR_TIMEOUT = clearTimeout;
  195. function installTimerFunctions(obj, opts) {
  196. if (opts.useNativeTimers) {
  197. obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThis);
  198. obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThis);
  199. } else {
  200. obj.setTimeoutFn = setTimeout.bind(globalThis);
  201. obj.clearTimeoutFn = clearTimeout.bind(globalThis);
  202. }
  203. }
  204. /**
  205. * Expose `Emitter`.
  206. */
  207. var Emitter_1 = Emitter;
  208. /**
  209. * Initialize a new `Emitter`.
  210. *
  211. * @api public
  212. */
  213. function Emitter(obj) {
  214. if (obj) return mixin(obj);
  215. }
  216. /**
  217. * Mixin the emitter properties.
  218. *
  219. * @param {Object} obj
  220. * @return {Object}
  221. * @api private
  222. */
  223. function mixin(obj) {
  224. for (var key in Emitter.prototype) {
  225. obj[key] = Emitter.prototype[key];
  226. }
  227. return obj;
  228. }
  229. /**
  230. * Listen on the given `event` with `fn`.
  231. *
  232. * @param {String} event
  233. * @param {Function} fn
  234. * @return {Emitter}
  235. * @api public
  236. */
  237. Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
  238. this._callbacks = this._callbacks || {};
  239. (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
  240. return this;
  241. };
  242. /**
  243. * Adds an `event` listener that will be invoked a single
  244. * time then automatically removed.
  245. *
  246. * @param {String} event
  247. * @param {Function} fn
  248. * @return {Emitter}
  249. * @api public
  250. */
  251. Emitter.prototype.once = function (event, fn) {
  252. function on() {
  253. this.off(event, on);
  254. fn.apply(this, arguments);
  255. }
  256. on.fn = fn;
  257. this.on(event, on);
  258. return this;
  259. };
  260. /**
  261. * Remove the given callback for `event` or all
  262. * registered callbacks.
  263. *
  264. * @param {String} event
  265. * @param {Function} fn
  266. * @return {Emitter}
  267. * @api public
  268. */
  269. Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
  270. this._callbacks = this._callbacks || {}; // all
  271. if (0 == arguments.length) {
  272. this._callbacks = {};
  273. return this;
  274. } // specific event
  275. var callbacks = this._callbacks['$' + event];
  276. if (!callbacks) return this; // remove all handlers
  277. if (1 == arguments.length) {
  278. delete this._callbacks['$' + event];
  279. return this;
  280. } // remove specific handler
  281. var cb;
  282. for (var i = 0; i < callbacks.length; i++) {
  283. cb = callbacks[i];
  284. if (cb === fn || cb.fn === fn) {
  285. callbacks.splice(i, 1);
  286. break;
  287. }
  288. } // Remove event specific arrays for event types that no
  289. // one is subscribed for to avoid memory leak.
  290. if (callbacks.length === 0) {
  291. delete this._callbacks['$' + event];
  292. }
  293. return this;
  294. };
  295. /**
  296. * Emit `event` with the given args.
  297. *
  298. * @param {String} event
  299. * @param {Mixed} ...
  300. * @return {Emitter}
  301. */
  302. Emitter.prototype.emit = function (event) {
  303. this._callbacks = this._callbacks || {};
  304. var args = new Array(arguments.length - 1),
  305. callbacks = this._callbacks['$' + event];
  306. for (var i = 1; i < arguments.length; i++) {
  307. args[i - 1] = arguments[i];
  308. }
  309. if (callbacks) {
  310. callbacks = callbacks.slice(0);
  311. for (var i = 0, len = callbacks.length; i < len; ++i) {
  312. callbacks[i].apply(this, args);
  313. }
  314. }
  315. return this;
  316. }; // alias used for reserved events (protected method)
  317. Emitter.prototype.emitReserved = Emitter.prototype.emit;
  318. /**
  319. * Return array of callbacks for `event`.
  320. *
  321. * @param {String} event
  322. * @return {Array}
  323. * @api public
  324. */
  325. Emitter.prototype.listeners = function (event) {
  326. this._callbacks = this._callbacks || {};
  327. return this._callbacks['$' + event] || [];
  328. };
  329. /**
  330. * Check if this emitter has `event` handlers.
  331. *
  332. * @param {String} event
  333. * @return {Boolean}
  334. * @api public
  335. */
  336. Emitter.prototype.hasListeners = function (event) {
  337. return !!this.listeners(event).length;
  338. };
  339. var PACKET_TYPES = Object.create(null); // no Map = no polyfill
  340. PACKET_TYPES["open"] = "0";
  341. PACKET_TYPES["close"] = "1";
  342. PACKET_TYPES["ping"] = "2";
  343. PACKET_TYPES["pong"] = "3";
  344. PACKET_TYPES["message"] = "4";
  345. PACKET_TYPES["upgrade"] = "5";
  346. PACKET_TYPES["noop"] = "6";
  347. var PACKET_TYPES_REVERSE = Object.create(null);
  348. Object.keys(PACKET_TYPES).forEach(function (key) {
  349. PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
  350. });
  351. var ERROR_PACKET = {
  352. type: "error",
  353. data: "parser error"
  354. };
  355. var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
  356. var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function"; // ArrayBuffer.isView method is not defined in IE10
  357. var isView = function isView(obj) {
  358. return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
  359. };
  360. var encodePacket = function encodePacket(_ref, supportsBinary, callback) {
  361. var type = _ref.type,
  362. data = _ref.data;
  363. if (withNativeBlob && data instanceof Blob) {
  364. if (supportsBinary) {
  365. return callback(data);
  366. } else {
  367. return encodeBlobAsBase64(data, callback);
  368. }
  369. } else if (withNativeArrayBuffer$1 && (data instanceof ArrayBuffer || isView(data))) {
  370. if (supportsBinary) {
  371. return callback(data);
  372. } else {
  373. return encodeBlobAsBase64(new Blob([data]), callback);
  374. }
  375. } // plain string
  376. return callback(PACKET_TYPES[type] + (data || ""));
  377. };
  378. var encodeBlobAsBase64 = function encodeBlobAsBase64(data, callback) {
  379. var fileReader = new FileReader();
  380. fileReader.onload = function () {
  381. var content = fileReader.result.split(",")[1];
  382. callback("b" + content);
  383. };
  384. return fileReader.readAsDataURL(data);
  385. };
  386. /*
  387. * base64-arraybuffer 1.0.1 <https://github.com/niklasvh/base64-arraybuffer>
  388. * Copyright (c) 2021 Niklas von Hertzen <https://hertzen.com>
  389. * Released under MIT License
  390. */
  391. var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; // Use a lookup table to find the index.
  392. var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
  393. for (var i$1 = 0; i$1 < chars.length; i$1++) {
  394. lookup[chars.charCodeAt(i$1)] = i$1;
  395. }
  396. var decode$1 = function decode(base64) {
  397. var bufferLength = base64.length * 0.75,
  398. len = base64.length,
  399. i,
  400. p = 0,
  401. encoded1,
  402. encoded2,
  403. encoded3,
  404. encoded4;
  405. if (base64[base64.length - 1] === '=') {
  406. bufferLength--;
  407. if (base64[base64.length - 2] === '=') {
  408. bufferLength--;
  409. }
  410. }
  411. var arraybuffer = new ArrayBuffer(bufferLength),
  412. bytes = new Uint8Array(arraybuffer);
  413. for (i = 0; i < len; i += 4) {
  414. encoded1 = lookup[base64.charCodeAt(i)];
  415. encoded2 = lookup[base64.charCodeAt(i + 1)];
  416. encoded3 = lookup[base64.charCodeAt(i + 2)];
  417. encoded4 = lookup[base64.charCodeAt(i + 3)];
  418. bytes[p++] = encoded1 << 2 | encoded2 >> 4;
  419. bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
  420. bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
  421. }
  422. return arraybuffer;
  423. };
  424. var withNativeArrayBuffer = typeof ArrayBuffer === "function";
  425. var decodePacket = function decodePacket(encodedPacket, binaryType) {
  426. if (typeof encodedPacket !== "string") {
  427. return {
  428. type: "message",
  429. data: mapBinary(encodedPacket, binaryType)
  430. };
  431. }
  432. var type = encodedPacket.charAt(0);
  433. if (type === "b") {
  434. return {
  435. type: "message",
  436. data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
  437. };
  438. }
  439. var packetType = PACKET_TYPES_REVERSE[type];
  440. if (!packetType) {
  441. return ERROR_PACKET;
  442. }
  443. return encodedPacket.length > 1 ? {
  444. type: PACKET_TYPES_REVERSE[type],
  445. data: encodedPacket.substring(1)
  446. } : {
  447. type: PACKET_TYPES_REVERSE[type]
  448. };
  449. };
  450. var decodeBase64Packet = function decodeBase64Packet(data, binaryType) {
  451. if (withNativeArrayBuffer) {
  452. var decoded = decode$1(data);
  453. return mapBinary(decoded, binaryType);
  454. } else {
  455. return {
  456. base64: true,
  457. data: data
  458. }; // fallback for old browsers
  459. }
  460. };
  461. var mapBinary = function mapBinary(data, binaryType) {
  462. switch (binaryType) {
  463. case "blob":
  464. return data instanceof ArrayBuffer ? new Blob([data]) : data;
  465. case "arraybuffer":
  466. default:
  467. return data;
  468. // assuming the data is already an ArrayBuffer
  469. }
  470. };
  471. var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
  472. var encodePayload = function encodePayload(packets, callback) {
  473. // some packets may be added to the array while encoding, so the initial length must be saved
  474. var length = packets.length;
  475. var encodedPackets = new Array(length);
  476. var count = 0;
  477. packets.forEach(function (packet, i) {
  478. // force base64 encoding for binary packets
  479. encodePacket(packet, false, function (encodedPacket) {
  480. encodedPackets[i] = encodedPacket;
  481. if (++count === length) {
  482. callback(encodedPackets.join(SEPARATOR));
  483. }
  484. });
  485. });
  486. };
  487. var decodePayload = function decodePayload(encodedPayload, binaryType) {
  488. var encodedPackets = encodedPayload.split(SEPARATOR);
  489. var packets = [];
  490. for (var i = 0; i < encodedPackets.length; i++) {
  491. var decodedPacket = decodePacket(encodedPackets[i], binaryType);
  492. packets.push(decodedPacket);
  493. if (decodedPacket.type === "error") {
  494. break;
  495. }
  496. }
  497. return packets;
  498. };
  499. var protocol = 4;
  500. var Transport = /*#__PURE__*/function (_Emitter) {
  501. _inherits(Transport, _Emitter);
  502. var _super = _createSuper(Transport);
  503. /**
  504. * Transport abstract constructor.
  505. *
  506. * @param {Object} options.
  507. * @api private
  508. */
  509. function Transport(opts) {
  510. var _this;
  511. _classCallCheck(this, Transport);
  512. _this = _super.call(this);
  513. _this.writable = false;
  514. installTimerFunctions(_assertThisInitialized(_this), opts);
  515. _this.opts = opts;
  516. _this.query = opts.query;
  517. _this.readyState = "";
  518. _this.socket = opts.socket;
  519. return _this;
  520. }
  521. /**
  522. * Emits an error.
  523. *
  524. * @param {String} str
  525. * @return {Transport} for chaining
  526. * @api protected
  527. */
  528. _createClass(Transport, [{
  529. key: "onError",
  530. value: function onError(msg, desc) {
  531. var err = new Error(msg); // @ts-ignore
  532. err.type = "TransportError"; // @ts-ignore
  533. err.description = desc;
  534. _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "error", err);
  535. return this;
  536. }
  537. /**
  538. * Opens the transport.
  539. *
  540. * @api public
  541. */
  542. }, {
  543. key: "open",
  544. value: function open() {
  545. if ("closed" === this.readyState || "" === this.readyState) {
  546. this.readyState = "opening";
  547. this.doOpen();
  548. }
  549. return this;
  550. }
  551. /**
  552. * Closes the transport.
  553. *
  554. * @api public
  555. */
  556. }, {
  557. key: "close",
  558. value: function close() {
  559. if ("opening" === this.readyState || "open" === this.readyState) {
  560. this.doClose();
  561. this.onClose();
  562. }
  563. return this;
  564. }
  565. /**
  566. * Sends multiple packets.
  567. *
  568. * @param {Array} packets
  569. * @api public
  570. */
  571. }, {
  572. key: "send",
  573. value: function send(packets) {
  574. if ("open" === this.readyState) {
  575. this.write(packets);
  576. }
  577. }
  578. /**
  579. * Called upon open
  580. *
  581. * @api protected
  582. */
  583. }, {
  584. key: "onOpen",
  585. value: function onOpen() {
  586. this.readyState = "open";
  587. this.writable = true;
  588. _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "open");
  589. }
  590. /**
  591. * Called with data.
  592. *
  593. * @param {String} data
  594. * @api protected
  595. */
  596. }, {
  597. key: "onData",
  598. value: function onData(data) {
  599. var packet = decodePacket(data, this.socket.binaryType);
  600. this.onPacket(packet);
  601. }
  602. /**
  603. * Called with a decoded packet.
  604. *
  605. * @api protected
  606. */
  607. }, {
  608. key: "onPacket",
  609. value: function onPacket(packet) {
  610. _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "packet", packet);
  611. }
  612. /**
  613. * Called upon close.
  614. *
  615. * @api protected
  616. */
  617. }, {
  618. key: "onClose",
  619. value: function onClose() {
  620. this.readyState = "closed";
  621. _get(_getPrototypeOf(Transport.prototype), "emit", this).call(this, "close");
  622. }
  623. }]);
  624. return Transport;
  625. }(Emitter_1);
  626. var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split(''),
  627. length = 64,
  628. map = {},
  629. seed = 0,
  630. i = 0,
  631. prev;
  632. /**
  633. * Return a string representing the specified number.
  634. *
  635. * @param {Number} num The number to convert.
  636. * @returns {String} The string representation of the number.
  637. * @api public
  638. */
  639. function encode(num) {
  640. var encoded = '';
  641. do {
  642. encoded = alphabet[num % length] + encoded;
  643. num = Math.floor(num / length);
  644. } while (num > 0);
  645. return encoded;
  646. }
  647. /**
  648. * Return the integer value specified by the given string.
  649. *
  650. * @param {String} str The string to convert.
  651. * @returns {Number} The integer value represented by the string.
  652. * @api public
  653. */
  654. function decode(str) {
  655. var decoded = 0;
  656. for (i = 0; i < str.length; i++) {
  657. decoded = decoded * length + map[str.charAt(i)];
  658. }
  659. return decoded;
  660. }
  661. /**
  662. * Yeast: A tiny growing id generator.
  663. *
  664. * @returns {String} A unique id.
  665. * @api public
  666. */
  667. function yeast() {
  668. var now = encode(+new Date());
  669. if (now !== prev) return seed = 0, prev = now;
  670. return now + '.' + encode(seed++);
  671. } //
  672. // Map each character to its index.
  673. //
  674. for (; i < length; i++) {
  675. map[alphabet[i]] = i;
  676. } //
  677. // Expose the `yeast`, `encode` and `decode` functions.
  678. //
  679. yeast.encode = encode;
  680. yeast.decode = decode;
  681. var yeast_1 = yeast;
  682. var parseqs = {};
  683. /**
  684. * Compiles a querystring
  685. * Returns string representation of the object
  686. *
  687. * @param {Object}
  688. * @api private
  689. */
  690. parseqs.encode = function (obj) {
  691. var str = '';
  692. for (var i in obj) {
  693. if (obj.hasOwnProperty(i)) {
  694. if (str.length) str += '&';
  695. str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
  696. }
  697. }
  698. return str;
  699. };
  700. /**
  701. * Parses a simple querystring into an object
  702. *
  703. * @param {String} qs
  704. * @api private
  705. */
  706. parseqs.decode = function (qs) {
  707. var qry = {};
  708. var pairs = qs.split('&');
  709. for (var i = 0, l = pairs.length; i < l; i++) {
  710. var pair = pairs[i].split('=');
  711. qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  712. }
  713. return qry;
  714. };
  715. var Polling = /*#__PURE__*/function (_Transport) {
  716. _inherits(Polling, _Transport);
  717. var _super = _createSuper(Polling);
  718. function Polling() {
  719. var _this;
  720. _classCallCheck(this, Polling);
  721. _this = _super.apply(this, arguments);
  722. _this.polling = false;
  723. return _this;
  724. }
  725. /**
  726. * Transport name.
  727. */
  728. _createClass(Polling, [{
  729. key: "doOpen",
  730. /**
  731. * Opens the socket (triggers polling). We write a PING message to determine
  732. * when the transport is open.
  733. *
  734. * @api private
  735. */
  736. value: function doOpen() {
  737. this.poll();
  738. }
  739. /**
  740. * Pauses polling.
  741. *
  742. * @param {Function} callback upon buffers are flushed and transport is paused
  743. * @api private
  744. */
  745. }, {
  746. key: "pause",
  747. value: function pause(onPause) {
  748. var _this2 = this;
  749. this.readyState = "pausing";
  750. var pause = function pause() {
  751. _this2.readyState = "paused";
  752. onPause();
  753. };
  754. if (this.polling || !this.writable) {
  755. var total = 0;
  756. if (this.polling) {
  757. total++;
  758. this.once("pollComplete", function () {
  759. --total || pause();
  760. });
  761. }
  762. if (!this.writable) {
  763. total++;
  764. this.once("drain", function () {
  765. --total || pause();
  766. });
  767. }
  768. } else {
  769. pause();
  770. }
  771. }
  772. /**
  773. * Starts polling cycle.
  774. *
  775. * @api public
  776. */
  777. }, {
  778. key: "poll",
  779. value: function poll() {
  780. this.polling = true;
  781. this.doPoll();
  782. this.emit("poll");
  783. }
  784. /**
  785. * Overloads onData to detect payloads.
  786. *
  787. * @api private
  788. */
  789. }, {
  790. key: "onData",
  791. value: function onData(data) {
  792. var _this3 = this;
  793. var callback = function callback(packet) {
  794. // if its the first message we consider the transport open
  795. if ("opening" === _this3.readyState && packet.type === "open") {
  796. _this3.onOpen();
  797. } // if its a close packet, we close the ongoing requests
  798. if ("close" === packet.type) {
  799. _this3.onClose();
  800. return false;
  801. } // otherwise bypass onData and handle the message
  802. _this3.onPacket(packet);
  803. }; // decode payload
  804. decodePayload(data, this.socket.binaryType).forEach(callback); // if an event did not trigger closing
  805. if ("closed" !== this.readyState) {
  806. // if we got data we're not polling
  807. this.polling = false;
  808. this.emit("pollComplete");
  809. if ("open" === this.readyState) {
  810. this.poll();
  811. }
  812. }
  813. }
  814. /**
  815. * For polling, send a close packet.
  816. *
  817. * @api private
  818. */
  819. }, {
  820. key: "doClose",
  821. value: function doClose() {
  822. var _this4 = this;
  823. var close = function close() {
  824. _this4.write([{
  825. type: "close"
  826. }]);
  827. };
  828. if ("open" === this.readyState) {
  829. close();
  830. } else {
  831. // in case we're trying to close while
  832. // handshaking is in progress (GH-164)
  833. this.once("open", close);
  834. }
  835. }
  836. /**
  837. * Writes a packets payload.
  838. *
  839. * @param {Array} data packets
  840. * @param {Function} drain callback
  841. * @api private
  842. */
  843. }, {
  844. key: "write",
  845. value: function write(packets) {
  846. var _this5 = this;
  847. this.writable = false;
  848. encodePayload(packets, function (data) {
  849. _this5.doWrite(data, function () {
  850. _this5.writable = true;
  851. _this5.emit("drain");
  852. });
  853. });
  854. }
  855. /**
  856. * Generates uri for connection.
  857. *
  858. * @api private
  859. */
  860. }, {
  861. key: "uri",
  862. value: function uri() {
  863. var query = this.query || {};
  864. var schema = this.opts.secure ? "https" : "http";
  865. var port = ""; // cache busting is forced
  866. if (false !== this.opts.timestampRequests) {
  867. query[this.opts.timestampParam] = yeast_1();
  868. }
  869. if (!this.supportsBinary && !query.sid) {
  870. query.b64 = 1;
  871. } // avoid port if default for schema
  872. if (this.opts.port && ("https" === schema && Number(this.opts.port) !== 443 || "http" === schema && Number(this.opts.port) !== 80)) {
  873. port = ":" + this.opts.port;
  874. }
  875. var encodedQuery = parseqs.encode(query);
  876. var ipv6 = this.opts.hostname.indexOf(":") !== -1;
  877. return schema + "://" + (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) + port + this.opts.path + (encodedQuery.length ? "?" + encodedQuery : "");
  878. }
  879. }, {
  880. key: "name",
  881. get: function get() {
  882. return "polling";
  883. }
  884. }]);
  885. return Polling;
  886. }(Transport);
  887. /**
  888. * Empty function
  889. */
  890. function empty() {}
  891. var hasXHR2 = function () {
  892. var xhr = new XMLHttpRequest$1({
  893. xdomain: false
  894. });
  895. return null != xhr.responseType;
  896. }();
  897. var XHR = /*#__PURE__*/function (_Polling) {
  898. _inherits(XHR, _Polling);
  899. var _super = _createSuper(XHR);
  900. /**
  901. * XHR Polling constructor.
  902. *
  903. * @param {Object} opts
  904. * @api public
  905. */
  906. function XHR(opts) {
  907. var _this;
  908. _classCallCheck(this, XHR);
  909. _this = _super.call(this, opts);
  910. if (typeof location !== "undefined") {
  911. var isSSL = "https:" === location.protocol;
  912. var port = location.port; // some user agents have empty `location.port`
  913. if (!port) {
  914. port = isSSL ? "443" : "80";
  915. }
  916. _this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
  917. _this.xs = opts.secure !== isSSL;
  918. }
  919. /**
  920. * XHR supports binary
  921. */
  922. var forceBase64 = opts && opts.forceBase64;
  923. _this.supportsBinary = hasXHR2 && !forceBase64;
  924. return _this;
  925. }
  926. /**
  927. * Creates a request.
  928. *
  929. * @param {String} method
  930. * @api private
  931. */
  932. _createClass(XHR, [{
  933. key: "request",
  934. value: function request() {
  935. var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  936. _extends(opts, {
  937. xd: this.xd,
  938. xs: this.xs
  939. }, this.opts);
  940. return new Request(this.uri(), opts);
  941. }
  942. /**
  943. * Sends data.
  944. *
  945. * @param {String} data to send.
  946. * @param {Function} called upon flush.
  947. * @api private
  948. */
  949. }, {
  950. key: "doWrite",
  951. value: function doWrite(data, fn) {
  952. var _this2 = this;
  953. var req = this.request({
  954. method: "POST",
  955. data: data
  956. });
  957. req.on("success", fn);
  958. req.on("error", function (err) {
  959. _this2.onError("xhr post error", err);
  960. });
  961. }
  962. /**
  963. * Starts a poll cycle.
  964. *
  965. * @api private
  966. */
  967. }, {
  968. key: "doPoll",
  969. value: function doPoll() {
  970. var _this3 = this;
  971. var req = this.request();
  972. req.on("data", this.onData.bind(this));
  973. req.on("error", function (err) {
  974. _this3.onError("xhr poll error", err);
  975. });
  976. this.pollXhr = req;
  977. }
  978. }]);
  979. return XHR;
  980. }(Polling);
  981. var Request = /*#__PURE__*/function (_Emitter) {
  982. _inherits(Request, _Emitter);
  983. var _super2 = _createSuper(Request);
  984. /**
  985. * Request constructor
  986. *
  987. * @param {Object} options
  988. * @api public
  989. */
  990. function Request(uri, opts) {
  991. var _this4;
  992. _classCallCheck(this, Request);
  993. _this4 = _super2.call(this);
  994. installTimerFunctions(_assertThisInitialized(_this4), opts);
  995. _this4.opts = opts;
  996. _this4.method = opts.method || "GET";
  997. _this4.uri = uri;
  998. _this4.async = false !== opts.async;
  999. _this4.data = undefined !== opts.data ? opts.data : null;
  1000. _this4.create();
  1001. return _this4;
  1002. }
  1003. /**
  1004. * Creates the XHR object and sends the request.
  1005. *
  1006. * @api private
  1007. */
  1008. _createClass(Request, [{
  1009. key: "create",
  1010. value: function create() {
  1011. var _this5 = this;
  1012. var opts = pick(this.opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
  1013. opts.xdomain = !!this.opts.xd;
  1014. opts.xscheme = !!this.opts.xs;
  1015. var xhr = this.xhr = new XMLHttpRequest$1(opts);
  1016. try {
  1017. xhr.open(this.method, this.uri, this.async);
  1018. try {
  1019. if (this.opts.extraHeaders) {
  1020. xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
  1021. for (var i in this.opts.extraHeaders) {
  1022. if (this.opts.extraHeaders.hasOwnProperty(i)) {
  1023. xhr.setRequestHeader(i, this.opts.extraHeaders[i]);
  1024. }
  1025. }
  1026. }
  1027. } catch (e) {}
  1028. if ("POST" === this.method) {
  1029. try {
  1030. xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
  1031. } catch (e) {}
  1032. }
  1033. try {
  1034. xhr.setRequestHeader("Accept", "*/*");
  1035. } catch (e) {} // ie6 check
  1036. if ("withCredentials" in xhr) {
  1037. xhr.withCredentials = this.opts.withCredentials;
  1038. }
  1039. if (this.opts.requestTimeout) {
  1040. xhr.timeout = this.opts.requestTimeout;
  1041. }
  1042. xhr.onreadystatechange = function () {
  1043. if (4 !== xhr.readyState) return;
  1044. if (200 === xhr.status || 1223 === xhr.status) {
  1045. _this5.onLoad();
  1046. } else {
  1047. // make sure the `error` event handler that's user-set
  1048. // does not throw in the same tick and gets caught here
  1049. _this5.setTimeoutFn(function () {
  1050. _this5.onError(typeof xhr.status === "number" ? xhr.status : 0);
  1051. }, 0);
  1052. }
  1053. };
  1054. xhr.send(this.data);
  1055. } catch (e) {
  1056. // Need to defer since .create() is called directly from the constructor
  1057. // and thus the 'error' event can only be only bound *after* this exception
  1058. // occurs. Therefore, also, we cannot throw here at all.
  1059. this.setTimeoutFn(function () {
  1060. _this5.onError(e);
  1061. }, 0);
  1062. return;
  1063. }
  1064. if (typeof document !== "undefined") {
  1065. this.index = Request.requestsCount++;
  1066. Request.requests[this.index] = this;
  1067. }
  1068. }
  1069. /**
  1070. * Called upon successful response.
  1071. *
  1072. * @api private
  1073. */
  1074. }, {
  1075. key: "onSuccess",
  1076. value: function onSuccess() {
  1077. this.emit("success");
  1078. this.cleanup();
  1079. }
  1080. /**
  1081. * Called if we have data.
  1082. *
  1083. * @api private
  1084. */
  1085. }, {
  1086. key: "onData",
  1087. value: function onData(data) {
  1088. this.emit("data", data);
  1089. this.onSuccess();
  1090. }
  1091. /**
  1092. * Called upon error.
  1093. *
  1094. * @api private
  1095. */
  1096. }, {
  1097. key: "onError",
  1098. value: function onError(err) {
  1099. this.emit("error", err);
  1100. this.cleanup(true);
  1101. }
  1102. /**
  1103. * Cleans up house.
  1104. *
  1105. * @api private
  1106. */
  1107. }, {
  1108. key: "cleanup",
  1109. value: function cleanup(fromError) {
  1110. if ("undefined" === typeof this.xhr || null === this.xhr) {
  1111. return;
  1112. }
  1113. this.xhr.onreadystatechange = empty;
  1114. if (fromError) {
  1115. try {
  1116. this.xhr.abort();
  1117. } catch (e) {}
  1118. }
  1119. if (typeof document !== "undefined") {
  1120. delete Request.requests[this.index];
  1121. }
  1122. this.xhr = null;
  1123. }
  1124. /**
  1125. * Called upon load.
  1126. *
  1127. * @api private
  1128. */
  1129. }, {
  1130. key: "onLoad",
  1131. value: function onLoad() {
  1132. var data = this.xhr.responseText;
  1133. if (data !== null) {
  1134. this.onData(data);
  1135. }
  1136. }
  1137. /**
  1138. * Aborts the request.
  1139. *
  1140. * @api public
  1141. */
  1142. }, {
  1143. key: "abort",
  1144. value: function abort() {
  1145. this.cleanup();
  1146. }
  1147. }]);
  1148. return Request;
  1149. }(Emitter_1);
  1150. Request.requestsCount = 0;
  1151. Request.requests = {};
  1152. /**
  1153. * Aborts pending requests when unloading the window. This is needed to prevent
  1154. * memory leaks (e.g. when using IE) and to ensure that no spurious error is
  1155. * emitted.
  1156. */
  1157. if (typeof document !== "undefined") {
  1158. // @ts-ignore
  1159. if (typeof attachEvent === "function") {
  1160. // @ts-ignore
  1161. attachEvent("onunload", unloadHandler);
  1162. } else if (typeof addEventListener === "function") {
  1163. var terminationEvent = "onpagehide" in globalThis ? "pagehide" : "unload";
  1164. addEventListener(terminationEvent, unloadHandler, false);
  1165. }
  1166. }
  1167. function unloadHandler() {
  1168. for (var i in Request.requests) {
  1169. if (Request.requests.hasOwnProperty(i)) {
  1170. Request.requests[i].abort();
  1171. }
  1172. }
  1173. }
  1174. var nextTick = function () {
  1175. var isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
  1176. if (isPromiseAvailable) {
  1177. return function (cb) {
  1178. return Promise.resolve().then(cb);
  1179. };
  1180. } else {
  1181. return function (cb, setTimeoutFn) {
  1182. return setTimeoutFn(cb, 0);
  1183. };
  1184. }
  1185. }();
  1186. var WebSocket = globalThis.WebSocket || globalThis.MozWebSocket;
  1187. var usingBrowserWebSocket = true;
  1188. var defaultBinaryType = "arraybuffer";
  1189. var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
  1190. var WS = /*#__PURE__*/function (_Transport) {
  1191. _inherits(WS, _Transport);
  1192. var _super = _createSuper(WS);
  1193. /**
  1194. * WebSocket transport constructor.
  1195. *
  1196. * @api {Object} connection options
  1197. * @api public
  1198. */
  1199. function WS(opts) {
  1200. var _this;
  1201. _classCallCheck(this, WS);
  1202. _this = _super.call(this, opts);
  1203. _this.supportsBinary = !opts.forceBase64;
  1204. return _this;
  1205. }
  1206. /**
  1207. * Transport name.
  1208. *
  1209. * @api public
  1210. */
  1211. _createClass(WS, [{
  1212. key: "doOpen",
  1213. /**
  1214. * Opens socket.
  1215. *
  1216. * @api private
  1217. */
  1218. value: function doOpen() {
  1219. if (!this.check()) {
  1220. // let probe timeout
  1221. return;
  1222. }
  1223. var uri = this.uri();
  1224. var protocols = this.opts.protocols; // React Native only supports the 'headers' option, and will print a warning if anything else is passed
  1225. var opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
  1226. if (this.opts.extraHeaders) {
  1227. opts.headers = this.opts.extraHeaders;
  1228. }
  1229. try {
  1230. this.ws = usingBrowserWebSocket && !isReactNative ? protocols ? new WebSocket(uri, protocols) : new WebSocket(uri) : new WebSocket(uri, protocols, opts);
  1231. } catch (err) {
  1232. return this.emit("error", err);
  1233. }
  1234. this.ws.binaryType = this.socket.binaryType || defaultBinaryType;
  1235. this.addEventListeners();
  1236. }
  1237. /**
  1238. * Adds event listeners to the socket
  1239. *
  1240. * @api private
  1241. */
  1242. }, {
  1243. key: "addEventListeners",
  1244. value: function addEventListeners() {
  1245. var _this2 = this;
  1246. this.ws.onopen = function () {
  1247. if (_this2.opts.autoUnref) {
  1248. _this2.ws._socket.unref();
  1249. }
  1250. _this2.onOpen();
  1251. };
  1252. this.ws.onclose = this.onClose.bind(this);
  1253. this.ws.onmessage = function (ev) {
  1254. return _this2.onData(ev.data);
  1255. };
  1256. this.ws.onerror = function (e) {
  1257. return _this2.onError("websocket error", e);
  1258. };
  1259. }
  1260. /**
  1261. * Writes data to socket.
  1262. *
  1263. * @param {Array} array of packets.
  1264. * @api private
  1265. */
  1266. }, {
  1267. key: "write",
  1268. value: function write(packets) {
  1269. var _this3 = this;
  1270. this.writable = false; // encodePacket efficient as it uses WS framing
  1271. // no need for encodePayload
  1272. var _loop = function _loop(i) {
  1273. var packet = packets[i];
  1274. var lastPacket = i === packets.length - 1;
  1275. encodePacket(packet, _this3.supportsBinary, function (data) {
  1276. // always create a new object (GH-437)
  1277. var opts = {};
  1278. // have a chance of informing us about it yet, in that case send will
  1279. // throw an error
  1280. try {
  1281. if (usingBrowserWebSocket) {
  1282. // TypeError is thrown when passing the second argument on Safari
  1283. _this3.ws.send(data);
  1284. }
  1285. } catch (e) {}
  1286. if (lastPacket) {
  1287. // fake drain
  1288. // defer to next tick to allow Socket to clear writeBuffer
  1289. nextTick(function () {
  1290. _this3.writable = true;
  1291. _this3.emit("drain");
  1292. }, _this3.setTimeoutFn);
  1293. }
  1294. });
  1295. };
  1296. for (var i = 0; i < packets.length; i++) {
  1297. _loop(i);
  1298. }
  1299. }
  1300. /**
  1301. * Closes socket.
  1302. *
  1303. * @api private
  1304. */
  1305. }, {
  1306. key: "doClose",
  1307. value: function doClose() {
  1308. if (typeof this.ws !== "undefined") {
  1309. this.ws.close();
  1310. this.ws = null;
  1311. }
  1312. }
  1313. /**
  1314. * Generates uri for connection.
  1315. *
  1316. * @api private
  1317. */
  1318. }, {
  1319. key: "uri",
  1320. value: function uri() {
  1321. var query = this.query || {};
  1322. var schema = this.opts.secure ? "wss" : "ws";
  1323. var port = ""; // avoid port if default for schema
  1324. if (this.opts.port && ("wss" === schema && Number(this.opts.port) !== 443 || "ws" === schema && Number(this.opts.port) !== 80)) {
  1325. port = ":" + this.opts.port;
  1326. } // append timestamp to URI
  1327. if (this.opts.timestampRequests) {
  1328. query[this.opts.timestampParam] = yeast_1();
  1329. } // communicate binary support capabilities
  1330. if (!this.supportsBinary) {
  1331. query.b64 = 1;
  1332. }
  1333. var encodedQuery = parseqs.encode(query);
  1334. var ipv6 = this.opts.hostname.indexOf(":") !== -1;
  1335. return schema + "://" + (ipv6 ? "[" + this.opts.hostname + "]" : this.opts.hostname) + port + this.opts.path + (encodedQuery.length ? "?" + encodedQuery : "");
  1336. }
  1337. /**
  1338. * Feature detection for WebSocket.
  1339. *
  1340. * @return {Boolean} whether this transport is available.
  1341. * @api public
  1342. */
  1343. }, {
  1344. key: "check",
  1345. value: function check() {
  1346. return !!WebSocket && !("__initialize" in WebSocket && this.name === WS.prototype.name);
  1347. }
  1348. }, {
  1349. key: "name",
  1350. get: function get() {
  1351. return "websocket";
  1352. }
  1353. }]);
  1354. return WS;
  1355. }(Transport);
  1356. var transports = {
  1357. websocket: WS,
  1358. polling: XHR
  1359. };
  1360. /**
  1361. * Parses an URI
  1362. *
  1363. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  1364. * @api private
  1365. */
  1366. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  1367. var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
  1368. var parseuri = function parseuri(str) {
  1369. var src = str,
  1370. b = str.indexOf('['),
  1371. e = str.indexOf(']');
  1372. if (b != -1 && e != -1) {
  1373. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  1374. }
  1375. var m = re.exec(str || ''),
  1376. uri = {},
  1377. i = 14;
  1378. while (i--) {
  1379. uri[parts[i]] = m[i] || '';
  1380. }
  1381. if (b != -1 && e != -1) {
  1382. uri.source = src;
  1383. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  1384. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  1385. uri.ipv6uri = true;
  1386. }
  1387. uri.pathNames = pathNames(uri, uri['path']);
  1388. uri.queryKey = queryKey(uri, uri['query']);
  1389. return uri;
  1390. };
  1391. function pathNames(obj, path) {
  1392. var regx = /\/{2,9}/g,
  1393. names = path.replace(regx, "/").split("/");
  1394. if (path.substr(0, 1) == '/' || path.length === 0) {
  1395. names.splice(0, 1);
  1396. }
  1397. if (path.substr(path.length - 1, 1) == '/') {
  1398. names.splice(names.length - 1, 1);
  1399. }
  1400. return names;
  1401. }
  1402. function queryKey(uri, query) {
  1403. var data = {};
  1404. query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
  1405. if ($1) {
  1406. data[$1] = $2;
  1407. }
  1408. });
  1409. return data;
  1410. }
  1411. var Socket = /*#__PURE__*/function (_Emitter) {
  1412. _inherits(Socket, _Emitter);
  1413. var _super = _createSuper(Socket);
  1414. /**
  1415. * Socket constructor.
  1416. *
  1417. * @param {String|Object} uri or options
  1418. * @param {Object} opts - options
  1419. * @api public
  1420. */
  1421. function Socket(uri) {
  1422. var _this;
  1423. var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  1424. _classCallCheck(this, Socket);
  1425. _this = _super.call(this);
  1426. if (uri && "object" === _typeof(uri)) {
  1427. opts = uri;
  1428. uri = null;
  1429. }
  1430. if (uri) {
  1431. uri = parseuri(uri);
  1432. opts.hostname = uri.host;
  1433. opts.secure = uri.protocol === "https" || uri.protocol === "wss";
  1434. opts.port = uri.port;
  1435. if (uri.query) opts.query = uri.query;
  1436. } else if (opts.host) {
  1437. opts.hostname = parseuri(opts.host).host;
  1438. }
  1439. installTimerFunctions(_assertThisInitialized(_this), opts);
  1440. _this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
  1441. if (opts.hostname && !opts.port) {
  1442. // if no port is specified manually, use the protocol default
  1443. opts.port = _this.secure ? "443" : "80";
  1444. }
  1445. _this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
  1446. _this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
  1447. _this.transports = opts.transports || ["polling", "websocket"];
  1448. _this.readyState = "";
  1449. _this.writeBuffer = [];
  1450. _this.prevBufferLen = 0;
  1451. _this.opts = _extends({
  1452. path: "/engine.io",
  1453. agent: false,
  1454. withCredentials: false,
  1455. upgrade: true,
  1456. timestampParam: "t",
  1457. rememberUpgrade: false,
  1458. rejectUnauthorized: true,
  1459. perMessageDeflate: {
  1460. threshold: 1024
  1461. },
  1462. transportOptions: {},
  1463. closeOnBeforeunload: true
  1464. }, opts);
  1465. _this.opts.path = _this.opts.path.replace(/\/$/, "") + "/";
  1466. if (typeof _this.opts.query === "string") {
  1467. _this.opts.query = parseqs.decode(_this.opts.query);
  1468. } // set on handshake
  1469. _this.id = null;
  1470. _this.upgrades = null;
  1471. _this.pingInterval = null;
  1472. _this.pingTimeout = null; // set on heartbeat
  1473. _this.pingTimeoutTimer = null;
  1474. if (typeof addEventListener === "function") {
  1475. if (_this.opts.closeOnBeforeunload) {
  1476. // Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
  1477. // ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
  1478. // closed/reloaded)
  1479. addEventListener("beforeunload", function () {
  1480. if (_this.transport) {
  1481. // silently close the transport
  1482. _this.transport.removeAllListeners();
  1483. _this.transport.close();
  1484. }
  1485. }, false);
  1486. }
  1487. if (_this.hostname !== "localhost") {
  1488. _this.offlineEventListener = function () {
  1489. _this.onClose("transport close");
  1490. };
  1491. addEventListener("offline", _this.offlineEventListener, false);
  1492. }
  1493. }
  1494. _this.open();
  1495. return _this;
  1496. }
  1497. /**
  1498. * Creates transport of the given type.
  1499. *
  1500. * @param {String} transport name
  1501. * @return {Transport}
  1502. * @api private
  1503. */
  1504. _createClass(Socket, [{
  1505. key: "createTransport",
  1506. value: function createTransport(name) {
  1507. var query = clone(this.opts.query); // append engine.io protocol identifier
  1508. query.EIO = protocol; // transport name
  1509. query.transport = name; // session id if we already have one
  1510. if (this.id) query.sid = this.id;
  1511. var opts = _extends({}, this.opts.transportOptions[name], this.opts, {
  1512. query: query,
  1513. socket: this,
  1514. hostname: this.hostname,
  1515. secure: this.secure,
  1516. port: this.port
  1517. });
  1518. return new transports[name](opts);
  1519. }
  1520. /**
  1521. * Initializes transport to use and starts probe.
  1522. *
  1523. * @api private
  1524. */
  1525. }, {
  1526. key: "open",
  1527. value: function open() {
  1528. var _this2 = this;
  1529. var transport;
  1530. if (this.opts.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1) {
  1531. transport = "websocket";
  1532. } else if (0 === this.transports.length) {
  1533. // Emit error on next tick so it can be listened to
  1534. this.setTimeoutFn(function () {
  1535. _this2.emitReserved("error", "No transports available");
  1536. }, 0);
  1537. return;
  1538. } else {
  1539. transport = this.transports[0];
  1540. }
  1541. this.readyState = "opening"; // Retry with the next transport if the transport is disabled (jsonp: false)
  1542. try {
  1543. transport = this.createTransport(transport);
  1544. } catch (e) {
  1545. this.transports.shift();
  1546. this.open();
  1547. return;
  1548. }
  1549. transport.open();
  1550. this.setTransport(transport);
  1551. }
  1552. /**
  1553. * Sets the current transport. Disables the existing one (if any).
  1554. *
  1555. * @api private
  1556. */
  1557. }, {
  1558. key: "setTransport",
  1559. value: function setTransport(transport) {
  1560. var _this3 = this;
  1561. if (this.transport) {
  1562. this.transport.removeAllListeners();
  1563. } // set up transport
  1564. this.transport = transport; // set up transport listeners
  1565. transport.on("drain", this.onDrain.bind(this)).on("packet", this.onPacket.bind(this)).on("error", this.onError.bind(this)).on("close", function () {
  1566. _this3.onClose("transport close");
  1567. });
  1568. }
  1569. /**
  1570. * Probes a transport.
  1571. *
  1572. * @param {String} transport name
  1573. * @api private
  1574. */
  1575. }, {
  1576. key: "probe",
  1577. value: function probe(name) {
  1578. var _this4 = this;
  1579. var transport = this.createTransport(name);
  1580. var failed = false;
  1581. Socket.priorWebsocketSuccess = false;
  1582. var onTransportOpen = function onTransportOpen() {
  1583. if (failed) return;
  1584. transport.send([{
  1585. type: "ping",
  1586. data: "probe"
  1587. }]);
  1588. transport.once("packet", function (msg) {
  1589. if (failed) return;
  1590. if ("pong" === msg.type && "probe" === msg.data) {
  1591. _this4.upgrading = true;
  1592. _this4.emitReserved("upgrading", transport);
  1593. if (!transport) return;
  1594. Socket.priorWebsocketSuccess = "websocket" === transport.name;
  1595. _this4.transport.pause(function () {
  1596. if (failed) return;
  1597. if ("closed" === _this4.readyState) return;
  1598. cleanup();
  1599. _this4.setTransport(transport);
  1600. transport.send([{
  1601. type: "upgrade"
  1602. }]);
  1603. _this4.emitReserved("upgrade", transport);
  1604. transport = null;
  1605. _this4.upgrading = false;
  1606. _this4.flush();
  1607. });
  1608. } else {
  1609. var err = new Error("probe error"); // @ts-ignore
  1610. err.transport = transport.name;
  1611. _this4.emitReserved("upgradeError", err);
  1612. }
  1613. });
  1614. };
  1615. function freezeTransport() {
  1616. if (failed) return; // Any callback called by transport should be ignored since now
  1617. failed = true;
  1618. cleanup();
  1619. transport.close();
  1620. transport = null;
  1621. } // Handle any error that happens while probing
  1622. var onerror = function onerror(err) {
  1623. var error = new Error("probe error: " + err); // @ts-ignore
  1624. error.transport = transport.name;
  1625. freezeTransport();
  1626. _this4.emitReserved("upgradeError", error);
  1627. };
  1628. function onTransportClose() {
  1629. onerror("transport closed");
  1630. } // When the socket is closed while we're probing
  1631. function onclose() {
  1632. onerror("socket closed");
  1633. } // When the socket is upgraded while we're probing
  1634. function onupgrade(to) {
  1635. if (transport && to.name !== transport.name) {
  1636. freezeTransport();
  1637. }
  1638. } // Remove all listeners on the transport and on self
  1639. var cleanup = function cleanup() {
  1640. transport.removeListener("open", onTransportOpen);
  1641. transport.removeListener("error", onerror);
  1642. transport.removeListener("close", onTransportClose);
  1643. _this4.off("close", onclose);
  1644. _this4.off("upgrading", onupgrade);
  1645. };
  1646. transport.once("open", onTransportOpen);
  1647. transport.once("error", onerror);
  1648. transport.once("close", onTransportClose);
  1649. this.once("close", onclose);
  1650. this.once("upgrading", onupgrade);
  1651. transport.open();
  1652. }
  1653. /**
  1654. * Called when connection is deemed open.
  1655. *
  1656. * @api private
  1657. */
  1658. }, {
  1659. key: "onOpen",
  1660. value: function onOpen() {
  1661. this.readyState = "open";
  1662. Socket.priorWebsocketSuccess = "websocket" === this.transport.name;
  1663. this.emitReserved("open");
  1664. this.flush(); // we check for `readyState` in case an `open`
  1665. // listener already closed the socket
  1666. if ("open" === this.readyState && this.opts.upgrade && this.transport.pause) {
  1667. var i = 0;
  1668. var l = this.upgrades.length;
  1669. for (; i < l; i++) {
  1670. this.probe(this.upgrades[i]);
  1671. }
  1672. }
  1673. }
  1674. /**
  1675. * Handles a packet.
  1676. *
  1677. * @api private
  1678. */
  1679. }, {
  1680. key: "onPacket",
  1681. value: function onPacket(packet) {
  1682. if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
  1683. this.emitReserved("packet", packet); // Socket is live - any packet counts
  1684. this.emitReserved("heartbeat");
  1685. switch (packet.type) {
  1686. case "open":
  1687. this.onHandshake(JSON.parse(packet.data));
  1688. break;
  1689. case "ping":
  1690. this.resetPingTimeout();
  1691. this.sendPacket("pong");
  1692. this.emitReserved("ping");
  1693. this.emitReserved("pong");
  1694. break;
  1695. case "error":
  1696. var err = new Error("server error"); // @ts-ignore
  1697. err.code = packet.data;
  1698. this.onError(err);
  1699. break;
  1700. case "message":
  1701. this.emitReserved("data", packet.data);
  1702. this.emitReserved("message", packet.data);
  1703. break;
  1704. }
  1705. }
  1706. }
  1707. /**
  1708. * Called upon handshake completion.
  1709. *
  1710. * @param {Object} data - handshake obj
  1711. * @api private
  1712. */
  1713. }, {
  1714. key: "onHandshake",
  1715. value: function onHandshake(data) {
  1716. this.emitReserved("handshake", data);
  1717. this.id = data.sid;
  1718. this.transport.query.sid = data.sid;
  1719. this.upgrades = this.filterUpgrades(data.upgrades);
  1720. this.pingInterval = data.pingInterval;
  1721. this.pingTimeout = data.pingTimeout;
  1722. this.onOpen(); // In case open handler closes socket
  1723. if ("closed" === this.readyState) return;
  1724. this.resetPingTimeout();
  1725. }
  1726. /**
  1727. * Sets and resets ping timeout timer based on server pings.
  1728. *
  1729. * @api private
  1730. */
  1731. }, {
  1732. key: "resetPingTimeout",
  1733. value: function resetPingTimeout() {
  1734. var _this5 = this;
  1735. this.clearTimeoutFn(this.pingTimeoutTimer);
  1736. this.pingTimeoutTimer = this.setTimeoutFn(function () {
  1737. _this5.onClose("ping timeout");
  1738. }, this.pingInterval + this.pingTimeout);
  1739. if (this.opts.autoUnref) {
  1740. this.pingTimeoutTimer.unref();
  1741. }
  1742. }
  1743. /**
  1744. * Called on `drain` event
  1745. *
  1746. * @api private
  1747. */
  1748. }, {
  1749. key: "onDrain",
  1750. value: function onDrain() {
  1751. this.writeBuffer.splice(0, this.prevBufferLen); // setting prevBufferLen = 0 is very important
  1752. // for example, when upgrading, upgrade packet is sent over,
  1753. // and a nonzero prevBufferLen could cause problems on `drain`
  1754. this.prevBufferLen = 0;
  1755. if (0 === this.writeBuffer.length) {
  1756. this.emitReserved("drain");
  1757. } else {
  1758. this.flush();
  1759. }
  1760. }
  1761. /**
  1762. * Flush write buffers.
  1763. *
  1764. * @api private
  1765. */
  1766. }, {
  1767. key: "flush",
  1768. value: function flush() {
  1769. if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
  1770. this.transport.send(this.writeBuffer); // keep track of current length of writeBuffer
  1771. // splice writeBuffer and callbackBuffer on `drain`
  1772. this.prevBufferLen = this.writeBuffer.length;
  1773. this.emitReserved("flush");
  1774. }
  1775. }
  1776. /**
  1777. * Sends a message.
  1778. *
  1779. * @param {String} message.
  1780. * @param {Function} callback function.
  1781. * @param {Object} options.
  1782. * @return {Socket} for chaining.
  1783. * @api public
  1784. */
  1785. }, {
  1786. key: "write",
  1787. value: function write(msg, options, fn) {
  1788. this.sendPacket("message", msg, options, fn);
  1789. return this;
  1790. }
  1791. }, {
  1792. key: "send",
  1793. value: function send(msg, options, fn) {
  1794. this.sendPacket("message", msg, options, fn);
  1795. return this;
  1796. }
  1797. /**
  1798. * Sends a packet.
  1799. *
  1800. * @param {String} packet type.
  1801. * @param {String} data.
  1802. * @param {Object} options.
  1803. * @param {Function} callback function.
  1804. * @api private
  1805. */
  1806. }, {
  1807. key: "sendPacket",
  1808. value: function sendPacket(type, data, options, fn) {
  1809. if ("function" === typeof data) {
  1810. fn = data;
  1811. data = undefined;
  1812. }
  1813. if ("function" === typeof options) {
  1814. fn = options;
  1815. options = null;
  1816. }
  1817. if ("closing" === this.readyState || "closed" === this.readyState) {
  1818. return;
  1819. }
  1820. options = options || {};
  1821. options.compress = false !== options.compress;
  1822. var packet = {
  1823. type: type,
  1824. data: data,
  1825. options: options
  1826. };
  1827. this.emitReserved("packetCreate", packet);
  1828. this.writeBuffer.push(packet);
  1829. if (fn) this.once("flush", fn);
  1830. this.flush();
  1831. }
  1832. /**
  1833. * Closes the connection.
  1834. *
  1835. * @api public
  1836. */
  1837. }, {
  1838. key: "close",
  1839. value: function close() {
  1840. var _this6 = this;
  1841. var close = function close() {
  1842. _this6.onClose("forced close");
  1843. _this6.transport.close();
  1844. };
  1845. var cleanupAndClose = function cleanupAndClose() {
  1846. _this6.off("upgrade", cleanupAndClose);
  1847. _this6.off("upgradeError", cleanupAndClose);
  1848. close();
  1849. };
  1850. var waitForUpgrade = function waitForUpgrade() {
  1851. // wait for upgrade to finish since we can't send packets while pausing a transport
  1852. _this6.once("upgrade", cleanupAndClose);
  1853. _this6.once("upgradeError", cleanupAndClose);
  1854. };
  1855. if ("opening" === this.readyState || "open" === this.readyState) {
  1856. this.readyState = "closing";
  1857. if (this.writeBuffer.length) {
  1858. this.once("drain", function () {
  1859. if (_this6.upgrading) {
  1860. waitForUpgrade();
  1861. } else {
  1862. close();
  1863. }
  1864. });
  1865. } else if (this.upgrading) {
  1866. waitForUpgrade();
  1867. } else {
  1868. close();
  1869. }
  1870. }
  1871. return this;
  1872. }
  1873. /**
  1874. * Called upon transport error
  1875. *
  1876. * @api private
  1877. */
  1878. }, {
  1879. key: "onError",
  1880. value: function onError(err) {
  1881. Socket.priorWebsocketSuccess = false;
  1882. this.emitReserved("error", err);
  1883. this.onClose("transport error", err);
  1884. }
  1885. /**
  1886. * Called upon transport close.
  1887. *
  1888. * @api private
  1889. */
  1890. }, {
  1891. key: "onClose",
  1892. value: function onClose(reason, desc) {
  1893. if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
  1894. // clear timers
  1895. this.clearTimeoutFn(this.pingTimeoutTimer); // stop event from firing again for transport
  1896. this.transport.removeAllListeners("close"); // ensure transport won't stay open
  1897. this.transport.close(); // ignore further transport communication
  1898. this.transport.removeAllListeners();
  1899. if (typeof removeEventListener === "function") {
  1900. removeEventListener("offline", this.offlineEventListener, false);
  1901. } // set ready state
  1902. this.readyState = "closed"; // clear session id
  1903. this.id = null; // emit close event
  1904. this.emitReserved("close", reason, desc); // clean buffers after, so users can still
  1905. // grab the buffers on `close` event
  1906. this.writeBuffer = [];
  1907. this.prevBufferLen = 0;
  1908. }
  1909. }
  1910. /**
  1911. * Filters upgrades, returning only those matching client transports.
  1912. *
  1913. * @param {Array} server upgrades
  1914. * @api private
  1915. *
  1916. */
  1917. }, {
  1918. key: "filterUpgrades",
  1919. value: function filterUpgrades(upgrades) {
  1920. var filteredUpgrades = [];
  1921. var i = 0;
  1922. var j = upgrades.length;
  1923. for (; i < j; i++) {
  1924. if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
  1925. }
  1926. return filteredUpgrades;
  1927. }
  1928. }]);
  1929. return Socket;
  1930. }(Emitter_1);
  1931. Socket.protocol = protocol;
  1932. function clone(obj) {
  1933. var o = {};
  1934. for (var i in obj) {
  1935. if (obj.hasOwnProperty(i)) {
  1936. o[i] = obj[i];
  1937. }
  1938. }
  1939. return o;
  1940. }
  1941. var browserEntrypoint = (function (uri, opts) {
  1942. return new Socket(uri, opts);
  1943. });
  1944. return browserEntrypoint;
  1945. }));
  1946. //# sourceMappingURL=engine.io.js.map