You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4731 lines
111 KiB

4 years ago
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["eio"] = factory();
  8. else
  9. root["eio"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. module.exports = __webpack_require__(1);
  46. /**
  47. * Exports parser
  48. *
  49. * @api public
  50. *
  51. */
  52. module.exports.parser = __webpack_require__(9);
  53. /***/ },
  54. /* 1 */
  55. /***/ function(module, exports, __webpack_require__) {
  56. /**
  57. * Module dependencies.
  58. */
  59. var transports = __webpack_require__(2);
  60. var Emitter = __webpack_require__(18);
  61. var debug = __webpack_require__(22)('engine.io-client:socket');
  62. var index = __webpack_require__(29);
  63. var parser = __webpack_require__(9);
  64. var parseuri = __webpack_require__(30);
  65. var parseqs = __webpack_require__(19);
  66. /**
  67. * Module exports.
  68. */
  69. module.exports = Socket;
  70. /**
  71. * Socket constructor.
  72. *
  73. * @param {String|Object} uri or options
  74. * @param {Object} options
  75. * @api public
  76. */
  77. function Socket (uri, opts) {
  78. if (!(this instanceof Socket)) return new Socket(uri, opts);
  79. opts = opts || {};
  80. if (uri && 'object' === typeof uri) {
  81. opts = uri;
  82. uri = null;
  83. }
  84. if (uri) {
  85. uri = parseuri(uri);
  86. opts.hostname = uri.host;
  87. opts.secure = uri.protocol === 'https' || uri.protocol === 'wss';
  88. opts.port = uri.port;
  89. if (uri.query) opts.query = uri.query;
  90. } else if (opts.host) {
  91. opts.hostname = parseuri(opts.host).host;
  92. }
  93. this.secure = null != opts.secure ? opts.secure
  94. : (typeof location !== 'undefined' && 'https:' === location.protocol);
  95. if (opts.hostname && !opts.port) {
  96. // if no port is specified manually, use the protocol default
  97. opts.port = this.secure ? '443' : '80';
  98. }
  99. this.agent = opts.agent || false;
  100. this.hostname = opts.hostname ||
  101. (typeof location !== 'undefined' ? location.hostname : 'localhost');
  102. this.port = opts.port || (typeof location !== 'undefined' && location.port
  103. ? location.port
  104. : (this.secure ? 443 : 80));
  105. this.query = opts.query || {};
  106. if ('string' === typeof this.query) this.query = parseqs.decode(this.query);
  107. this.upgrade = false !== opts.upgrade;
  108. this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
  109. this.forceJSONP = !!opts.forceJSONP;
  110. this.jsonp = false !== opts.jsonp;
  111. this.forceBase64 = !!opts.forceBase64;
  112. this.enablesXDR = !!opts.enablesXDR;
  113. this.withCredentials = false !== opts.withCredentials;
  114. this.timestampParam = opts.timestampParam || 't';
  115. this.timestampRequests = opts.timestampRequests;
  116. this.transports = opts.transports || ['polling', 'websocket'];
  117. this.transportOptions = opts.transportOptions || {};
  118. this.readyState = '';
  119. this.writeBuffer = [];
  120. this.prevBufferLen = 0;
  121. this.policyPort = opts.policyPort || 843;
  122. this.rememberUpgrade = opts.rememberUpgrade || false;
  123. this.binaryType = null;
  124. this.onlyBinaryUpgrades = opts.onlyBinaryUpgrades;
  125. this.perMessageDeflate = false !== opts.perMessageDeflate ? (opts.perMessageDeflate || {}) : false;
  126. if (true === this.perMessageDeflate) this.perMessageDeflate = {};
  127. if (this.perMessageDeflate && null == this.perMessageDeflate.threshold) {
  128. this.perMessageDeflate.threshold = 1024;
  129. }
  130. // SSL options for Node.js client
  131. this.pfx = opts.pfx || null;
  132. this.key = opts.key || null;
  133. this.passphrase = opts.passphrase || null;
  134. this.cert = opts.cert || null;
  135. this.ca = opts.ca || null;
  136. this.ciphers = opts.ciphers || null;
  137. this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? true : opts.rejectUnauthorized;
  138. this.forceNode = !!opts.forceNode;
  139. // detect ReactNative environment
  140. this.isReactNative = (typeof navigator !== 'undefined' && typeof navigator.product === 'string' && navigator.product.toLowerCase() === 'reactnative');
  141. // other options for Node.js or ReactNative client
  142. if (typeof self === 'undefined' || this.isReactNative) {
  143. if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
  144. this.extraHeaders = opts.extraHeaders;
  145. }
  146. if (opts.localAddress) {
  147. this.localAddress = opts.localAddress;
  148. }
  149. }
  150. // set on handshake
  151. this.id = null;
  152. this.upgrades = null;
  153. this.pingInterval = null;
  154. this.pingTimeout = null;
  155. // set on heartbeat
  156. this.pingIntervalTimer = null;
  157. this.pingTimeoutTimer = null;
  158. this.open();
  159. }
  160. Socket.priorWebsocketSuccess = false;
  161. /**
  162. * Mix in `Emitter`.
  163. */
  164. Emitter(Socket.prototype);
  165. /**
  166. * Protocol version.
  167. *
  168. * @api public
  169. */
  170. Socket.protocol = parser.protocol; // this is an int
  171. /**
  172. * Expose deps for legacy compatibility
  173. * and standalone browser access.
  174. */
  175. Socket.Socket = Socket;
  176. Socket.Transport = __webpack_require__(8);
  177. Socket.transports = __webpack_require__(2);
  178. Socket.parser = __webpack_require__(9);
  179. /**
  180. * Creates transport of the given type.
  181. *
  182. * @param {String} transport name
  183. * @return {Transport}
  184. * @api private
  185. */
  186. Socket.prototype.createTransport = function (name) {
  187. debug('creating transport "%s"', name);
  188. var query = clone(this.query);
  189. // append engine.io protocol identifier
  190. query.EIO = parser.protocol;
  191. // transport name
  192. query.transport = name;
  193. // per-transport options
  194. var options = this.transportOptions[name] || {};
  195. // session id if we already have one
  196. if (this.id) query.sid = this.id;
  197. var transport = new transports[name]({
  198. query: query,
  199. socket: this,
  200. agent: options.agent || this.agent,
  201. hostname: options.hostname || this.hostname,
  202. port: options.port || this.port,
  203. secure: options.secure || this.secure,
  204. path: options.path || this.path,
  205. forceJSONP: options.forceJSONP || this.forceJSONP,
  206. jsonp: options.jsonp || this.jsonp,
  207. forceBase64: options.forceBase64 || this.forceBase64,
  208. enablesXDR: options.enablesXDR || this.enablesXDR,
  209. withCredentials: options.withCredentials || this.withCredentials,
  210. timestampRequests: options.timestampRequests || this.timestampRequests,
  211. timestampParam: options.timestampParam || this.timestampParam,
  212. policyPort: options.policyPort || this.policyPort,
  213. pfx: options.pfx || this.pfx,
  214. key: options.key || this.key,
  215. passphrase: options.passphrase || this.passphrase,
  216. cert: options.cert || this.cert,
  217. ca: options.ca || this.ca,
  218. ciphers: options.ciphers || this.ciphers,
  219. rejectUnauthorized: options.rejectUnauthorized || this.rejectUnauthorized,
  220. perMessageDeflate: options.perMessageDeflate || this.perMessageDeflate,
  221. extraHeaders: options.extraHeaders || this.extraHeaders,
  222. forceNode: options.forceNode || this.forceNode,
  223. localAddress: options.localAddress || this.localAddress,
  224. requestTimeout: options.requestTimeout || this.requestTimeout,
  225. protocols: options.protocols || void (0),
  226. isReactNative: this.isReactNative
  227. });
  228. return transport;
  229. };
  230. function clone (obj) {
  231. var o = {};
  232. for (var i in obj) {
  233. if (obj.hasOwnProperty(i)) {
  234. o[i] = obj[i];
  235. }
  236. }
  237. return o;
  238. }
  239. /**
  240. * Initializes transport to use and starts probe.
  241. *
  242. * @api private
  243. */
  244. Socket.prototype.open = function () {
  245. var transport;
  246. if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') !== -1) {
  247. transport = 'websocket';
  248. } else if (0 === this.transports.length) {
  249. // Emit error on next tick so it can be listened to
  250. var self = this;
  251. setTimeout(function () {
  252. self.emit('error', 'No transports available');
  253. }, 0);
  254. return;
  255. } else {
  256. transport = this.transports[0];
  257. }
  258. this.readyState = 'opening';
  259. // Retry with the next transport if the transport is disabled (jsonp: false)
  260. try {
  261. transport = this.createTransport(transport);
  262. } catch (e) {
  263. this.transports.shift();
  264. this.open();
  265. return;
  266. }
  267. transport.open();
  268. this.setTransport(transport);
  269. };
  270. /**
  271. * Sets the current transport. Disables the existing one (if any).
  272. *
  273. * @api private
  274. */
  275. Socket.prototype.setTransport = function (transport) {
  276. debug('setting transport %s', transport.name);
  277. var self = this;
  278. if (this.transport) {
  279. debug('clearing existing transport %s', this.transport.name);
  280. this.transport.removeAllListeners();
  281. }
  282. // set up transport
  283. this.transport = transport;
  284. // set up transport listeners
  285. transport
  286. .on('drain', function () {
  287. self.onDrain();
  288. })
  289. .on('packet', function (packet) {
  290. self.onPacket(packet);
  291. })
  292. .on('error', function (e) {
  293. self.onError(e);
  294. })
  295. .on('close', function () {
  296. self.onClose('transport close');
  297. });
  298. };
  299. /**
  300. * Probes a transport.
  301. *
  302. * @param {String} transport name
  303. * @api private
  304. */
  305. Socket.prototype.probe = function (name) {
  306. debug('probing transport "%s"', name);
  307. var transport = this.createTransport(name, { probe: 1 });
  308. var failed = false;
  309. var self = this;
  310. Socket.priorWebsocketSuccess = false;
  311. function onTransportOpen () {
  312. if (self.onlyBinaryUpgrades) {
  313. var upgradeLosesBinary = !this.supportsBinary && self.transport.supportsBinary;
  314. failed = failed || upgradeLosesBinary;
  315. }
  316. if (failed) return;
  317. debug('probe transport "%s" opened', name);
  318. transport.send([{ type: 'ping', data: 'probe' }]);
  319. transport.once('packet', function (msg) {
  320. if (failed) return;
  321. if ('pong' === msg.type && 'probe' === msg.data) {
  322. debug('probe transport "%s" pong', name);
  323. self.upgrading = true;
  324. self.emit('upgrading', transport);
  325. if (!transport) return;
  326. Socket.priorWebsocketSuccess = 'websocket' === transport.name;
  327. debug('pausing current transport "%s"', self.transport.name);
  328. self.transport.pause(function () {
  329. if (failed) return;
  330. if ('closed' === self.readyState) return;
  331. debug('changing transport and sending upgrade packet');
  332. cleanup();
  333. self.setTransport(transport);
  334. transport.send([{ type: 'upgrade' }]);
  335. self.emit('upgrade', transport);
  336. transport = null;
  337. self.upgrading = false;
  338. self.flush();
  339. });
  340. } else {
  341. debug('probe transport "%s" failed', name);
  342. var err = new Error('probe error');
  343. err.transport = transport.name;
  344. self.emit('upgradeError', err);
  345. }
  346. });
  347. }
  348. function freezeTransport () {
  349. if (failed) return;
  350. // Any callback called by transport should be ignored since now
  351. failed = true;
  352. cleanup();
  353. transport.close();
  354. transport = null;
  355. }
  356. // Handle any error that happens while probing
  357. function onerror (err) {
  358. var error = new Error('probe error: ' + err);
  359. error.transport = transport.name;
  360. freezeTransport();
  361. debug('probe transport "%s" failed because of error: %s', name, err);
  362. self.emit('upgradeError', error);
  363. }
  364. function onTransportClose () {
  365. onerror('transport closed');
  366. }
  367. // When the socket is closed while we're probing
  368. function onclose () {
  369. onerror('socket closed');
  370. }
  371. // When the socket is upgraded while we're probing
  372. function onupgrade (to) {
  373. if (transport && to.name !== transport.name) {
  374. debug('"%s" works - aborting "%s"', to.name, transport.name);
  375. freezeTransport();
  376. }
  377. }
  378. // Remove all listeners on the transport and on self
  379. function cleanup () {
  380. transport.removeListener('open', onTransportOpen);
  381. transport.removeListener('error', onerror);
  382. transport.removeListener('close', onTransportClose);
  383. self.removeListener('close', onclose);
  384. self.removeListener('upgrading', onupgrade);
  385. }
  386. transport.once('open', onTransportOpen);
  387. transport.once('error', onerror);
  388. transport.once('close', onTransportClose);
  389. this.once('close', onclose);
  390. this.once('upgrading', onupgrade);
  391. transport.open();
  392. };
  393. /**
  394. * Called when connection is deemed open.
  395. *
  396. * @api public
  397. */
  398. Socket.prototype.onOpen = function () {
  399. debug('socket open');
  400. this.readyState = 'open';
  401. Socket.priorWebsocketSuccess = 'websocket' === this.transport.name;
  402. this.emit('open');
  403. this.flush();
  404. // we check for `readyState` in case an `open`
  405. // listener already closed the socket
  406. if ('open' === this.readyState && this.upgrade && this.transport.pause) {
  407. debug('starting upgrade probes');
  408. for (var i = 0, l = this.upgrades.length; i < l; i++) {
  409. this.probe(this.upgrades[i]);
  410. }
  411. }
  412. };
  413. /**
  414. * Handles a packet.
  415. *
  416. * @api private
  417. */
  418. Socket.prototype.onPacket = function (packet) {
  419. if ('opening' === this.readyState || 'open' === this.readyState ||
  420. 'closing' === this.readyState) {
  421. debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
  422. this.emit('packet', packet);
  423. // Socket is live - any packet counts
  424. this.emit('heartbeat');
  425. switch (packet.type) {
  426. case 'open':
  427. this.onHandshake(JSON.parse(packet.data));
  428. break;
  429. case 'pong':
  430. this.setPing();
  431. this.emit('pong');
  432. break;
  433. case 'error':
  434. var err = new Error('server error');
  435. err.code = packet.data;
  436. this.onError(err);
  437. break;
  438. case 'message':
  439. this.emit('data', packet.data);
  440. this.emit('message', packet.data);
  441. break;
  442. }
  443. } else {
  444. debug('packet received with socket readyState "%s"', this.readyState);
  445. }
  446. };
  447. /**
  448. * Called upon handshake completion.
  449. *
  450. * @param {Object} handshake obj
  451. * @api private
  452. */
  453. Socket.prototype.onHandshake = function (data) {
  454. this.emit('handshake', data);
  455. this.id = data.sid;
  456. this.transport.query.sid = data.sid;
  457. this.upgrades = this.filterUpgrades(data.upgrades);
  458. this.pingInterval = data.pingInterval;
  459. this.pingTimeout = data.pingTimeout;
  460. this.onOpen();
  461. // In case open handler closes socket
  462. if ('closed' === this.readyState) return;
  463. this.setPing();
  464. // Prolong liveness of socket on heartbeat
  465. this.removeListener('heartbeat', this.onHeartbeat);
  466. this.on('heartbeat', this.onHeartbeat);
  467. };
  468. /**
  469. * Resets ping timeout.
  470. *
  471. * @api private
  472. */
  473. Socket.prototype.onHeartbeat = function (timeout) {
  474. clearTimeout(this.pingTimeoutTimer);
  475. var self = this;
  476. self.pingTimeoutTimer = setTimeout(function () {
  477. if ('closed' === self.readyState) return;
  478. self.onClose('ping timeout');
  479. }, timeout || (self.pingInterval + self.pingTimeout));
  480. };
  481. /**
  482. * Pings server every `this.pingInterval` and expects response
  483. * within `this.pingTimeout` or closes connection.
  484. *
  485. * @api private
  486. */
  487. Socket.prototype.setPing = function () {
  488. var self = this;
  489. clearTimeout(self.pingIntervalTimer);
  490. self.pingIntervalTimer = setTimeout(function () {
  491. debug('writing ping packet - expecting pong within %sms', self.pingTimeout);
  492. self.ping();
  493. self.onHeartbeat(self.pingTimeout);
  494. }, self.pingInterval);
  495. };
  496. /**
  497. * Sends a ping packet.
  498. *
  499. * @api private
  500. */
  501. Socket.prototype.ping = function () {
  502. var self = this;
  503. this.sendPacket('ping', function () {
  504. self.emit('ping');
  505. });
  506. };
  507. /**
  508. * Called on `drain` event
  509. *
  510. * @api private
  511. */
  512. Socket.prototype.onDrain = function () {
  513. this.writeBuffer.splice(0, this.prevBufferLen);
  514. // setting prevBufferLen = 0 is very important
  515. // for example, when upgrading, upgrade packet is sent over,
  516. // and a nonzero prevBufferLen could cause problems on `drain`
  517. this.prevBufferLen = 0;
  518. if (0 === this.writeBuffer.length) {
  519. this.emit('drain');
  520. } else {
  521. this.flush();
  522. }
  523. };
  524. /**
  525. * Flush write buffers.
  526. *
  527. * @api private
  528. */
  529. Socket.prototype.flush = function () {
  530. if ('closed' !== this.readyState && this.transport.writable &&
  531. !this.upgrading && this.writeBuffer.length) {
  532. debug('flushing %d packets in socket', this.writeBuffer.length);
  533. this.transport.send(this.writeBuffer);
  534. // keep track of current length of writeBuffer
  535. // splice writeBuffer and callbackBuffer on `drain`
  536. this.prevBufferLen = this.writeBuffer.length;
  537. this.emit('flush');
  538. }
  539. };
  540. /**
  541. * Sends a message.
  542. *
  543. * @param {String} message.
  544. * @param {Function} callback function.
  545. * @param {Object} options.
  546. * @return {Socket} for chaining.
  547. * @api public
  548. */
  549. Socket.prototype.write =
  550. Socket.prototype.send = function (msg, options, fn) {
  551. this.sendPacket('message', msg, options, fn);
  552. return this;
  553. };
  554. /**
  555. * Sends a packet.
  556. *
  557. * @param {String} packet type.
  558. * @param {String} data.
  559. * @param {Object} options.
  560. * @param {Function} callback function.
  561. * @api private
  562. */
  563. Socket.prototype.sendPacket = function (type, data, options, fn) {
  564. if ('function' === typeof data) {
  565. fn = data;
  566. data = undefined;
  567. }
  568. if ('function' === typeof options) {
  569. fn = options;
  570. options = null;
  571. }
  572. if ('closing' === this.readyState || 'closed' === this.readyState) {
  573. return;
  574. }
  575. options = options || {};
  576. options.compress = false !== options.compress;
  577. var packet = {
  578. type: type,
  579. data: data,
  580. options: options
  581. };
  582. this.emit('packetCreate', packet);
  583. this.writeBuffer.push(packet);
  584. if (fn) this.once('flush', fn);
  585. this.flush();
  586. };
  587. /**
  588. * Closes the connection.
  589. *
  590. * @api private
  591. */
  592. Socket.prototype.close = function () {
  593. if ('opening' === this.readyState || 'open' === this.readyState) {
  594. this.readyState = 'closing';
  595. var self = this;
  596. if (this.writeBuffer.length) {
  597. this.once('drain', function () {
  598. if (this.upgrading) {
  599. waitForUpgrade();
  600. } else {
  601. close();
  602. }
  603. });
  604. } else if (this.upgrading) {
  605. waitForUpgrade();
  606. } else {
  607. close();
  608. }
  609. }
  610. function close () {
  611. self.onClose('forced close');
  612. debug('socket closing - telling transport to close');
  613. self.transport.close();
  614. }
  615. function cleanupAndClose () {
  616. self.removeListener('upgrade', cleanupAndClose);
  617. self.removeListener('upgradeError', cleanupAndClose);
  618. close();
  619. }
  620. function waitForUpgrade () {
  621. // wait for upgrade to finish since we can't send packets while pausing a transport
  622. self.once('upgrade', cleanupAndClose);
  623. self.once('upgradeError', cleanupAndClose);
  624. }
  625. return this;
  626. };
  627. /**
  628. * Called upon transport error
  629. *
  630. * @api private
  631. */
  632. Socket.prototype.onError = function (err) {
  633. debug('socket error %j', err);
  634. Socket.priorWebsocketSuccess = false;
  635. this.emit('error', err);
  636. this.onClose('transport error', err);
  637. };
  638. /**
  639. * Called upon transport close.
  640. *
  641. * @api private
  642. */
  643. Socket.prototype.onClose = function (reason, desc) {
  644. if ('opening' === this.readyState || 'open' === this.readyState || 'closing' === this.readyState) {
  645. debug('socket close with reason: "%s"', reason);
  646. var self = this;
  647. // clear timers
  648. clearTimeout(this.pingIntervalTimer);
  649. clearTimeout(this.pingTimeoutTimer);
  650. // stop event from firing again for transport
  651. this.transport.removeAllListeners('close');
  652. // ensure transport won't stay open
  653. this.transport.close();
  654. // ignore further transport communication
  655. this.transport.removeAllListeners();
  656. // set ready state
  657. this.readyState = 'closed';
  658. // clear session id
  659. this.id = null;
  660. // emit close event
  661. this.emit('close', reason, desc);
  662. // clean buffers after, so users can still
  663. // grab the buffers on `close` event
  664. self.writeBuffer = [];
  665. self.prevBufferLen = 0;
  666. }
  667. };
  668. /**
  669. * Filters upgrades, returning only those matching client transports.
  670. *
  671. * @param {Array} server upgrades
  672. * @api private
  673. *
  674. */
  675. Socket.prototype.filterUpgrades = function (upgrades) {
  676. var filteredUpgrades = [];
  677. for (var i = 0, j = upgrades.length; i < j; i++) {
  678. if (~index(this.transports, upgrades[i])) filteredUpgrades.push(upgrades[i]);
  679. }
  680. return filteredUpgrades;
  681. };
  682. /***/ },
  683. /* 2 */
  684. /***/ function(module, exports, __webpack_require__) {
  685. /**
  686. * Module dependencies
  687. */
  688. var XMLHttpRequest = __webpack_require__(3);
  689. var XHR = __webpack_require__(6);
  690. var JSONP = __webpack_require__(26);
  691. var websocket = __webpack_require__(27);
  692. /**
  693. * Export transports.
  694. */
  695. exports.polling = polling;
  696. exports.websocket = websocket;
  697. /**
  698. * Polling transport polymorphic constructor.
  699. * Decides on xhr vs jsonp based on feature detection.
  700. *
  701. * @api private
  702. */
  703. function polling (opts) {
  704. var xhr;
  705. var xd = false;
  706. var xs = false;
  707. var jsonp = false !== opts.jsonp;
  708. if (typeof location !== 'undefined') {
  709. var isSSL = 'https:' === location.protocol;
  710. var port = location.port;
  711. // some user agents have empty `location.port`
  712. if (!port) {
  713. port = isSSL ? 443 : 80;
  714. }
  715. xd = opts.hostname !== location.hostname || port !== opts.port;
  716. xs = opts.secure !== isSSL;
  717. }
  718. opts.xdomain = xd;
  719. opts.xscheme = xs;
  720. xhr = new XMLHttpRequest(opts);
  721. if ('open' in xhr && !opts.forceJSONP) {
  722. return new XHR(opts);
  723. } else {
  724. if (!jsonp) throw new Error('JSONP disabled');
  725. return new JSONP(opts);
  726. }
  727. }
  728. /***/ },
  729. /* 3 */
  730. /***/ function(module, exports, __webpack_require__) {
  731. // browser shim for xmlhttprequest module
  732. var hasCORS = __webpack_require__(4);
  733. var globalThis = __webpack_require__(5);
  734. module.exports = function (opts) {
  735. var xdomain = opts.xdomain;
  736. // scheme must be same when usign XDomainRequest
  737. // http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
  738. var xscheme = opts.xscheme;
  739. // XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
  740. // https://github.com/Automattic/engine.io-client/pull/217
  741. var enablesXDR = opts.enablesXDR;
  742. // XMLHttpRequest can be disabled on IE
  743. try {
  744. if ('undefined' !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
  745. return new XMLHttpRequest();
  746. }
  747. } catch (e) { }
  748. // Use XDomainRequest for IE8 if enablesXDR is true
  749. // because loading bar keeps flashing when using jsonp-polling
  750. // https://github.com/yujiosaka/socke.io-ie8-loading-example
  751. try {
  752. if ('undefined' !== typeof XDomainRequest && !xscheme && enablesXDR) {
  753. return new XDomainRequest();
  754. }
  755. } catch (e) { }
  756. if (!xdomain) {
  757. try {
  758. return new globalThis[['Active'].concat('Object').join('X')]('Microsoft.XMLHTTP');
  759. } catch (e) { }
  760. }
  761. };
  762. /***/ },
  763. /* 4 */
  764. /***/ function(module, exports) {
  765. /**
  766. * Module exports.
  767. *
  768. * Logic borrowed from Modernizr:
  769. *
  770. * - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
  771. */
  772. try {
  773. module.exports = typeof XMLHttpRequest !== 'undefined' &&
  774. 'withCredentials' in new XMLHttpRequest();
  775. } catch (err) {
  776. // if XMLHttp support is disabled in IE then it will throw
  777. // when trying to create
  778. module.exports = false;
  779. }
  780. /***/ },
  781. /* 5 */
  782. /***/ function(module, exports) {
  783. module.exports = (function () {
  784. if (typeof self !== 'undefined') {
  785. return self;
  786. } else if (typeof window !== 'undefined') {
  787. return window;
  788. } else {
  789. return Function('return this')(); // eslint-disable-line no-new-func
  790. }
  791. })();
  792. /***/ },
  793. /* 6 */
  794. /***/ function(module, exports, __webpack_require__) {
  795. /* global attachEvent */
  796. /**
  797. * Module requirements.
  798. */
  799. var XMLHttpRequest = __webpack_require__(3);
  800. var Polling = __webpack_require__(7);
  801. var Emitter = __webpack_require__(18);
  802. var inherit = __webpack_require__(20);
  803. var debug = __webpack_require__(22)('engine.io-client:polling-xhr');
  804. var globalThis = __webpack_require__(5);
  805. /**
  806. * Module exports.
  807. */
  808. module.exports = XHR;
  809. module.exports.Request = Request;
  810. /**
  811. * Empty function
  812. */
  813. function empty () {}
  814. /**
  815. * XHR Polling constructor.
  816. *
  817. * @param {Object} opts
  818. * @api public
  819. */
  820. function XHR (opts) {
  821. Polling.call(this, opts);
  822. this.requestTimeout = opts.requestTimeout;
  823. this.extraHeaders = opts.extraHeaders;
  824. if (typeof location !== 'undefined') {
  825. var isSSL = 'https:' === location.protocol;
  826. var port = location.port;
  827. // some user agents have empty `location.port`
  828. if (!port) {
  829. port = isSSL ? 443 : 80;
  830. }
  831. this.xd = (typeof location !== 'undefined' && opts.hostname !== location.hostname) ||
  832. port !== opts.port;
  833. this.xs = opts.secure !== isSSL;
  834. }
  835. }
  836. /**
  837. * Inherits from Polling.
  838. */
  839. inherit(XHR, Polling);
  840. /**
  841. * XHR supports binary
  842. */
  843. XHR.prototype.supportsBinary = true;
  844. /**
  845. * Creates a request.
  846. *
  847. * @param {String} method
  848. * @api private
  849. */
  850. XHR.prototype.request = function (opts) {
  851. opts = opts || {};
  852. opts.uri = this.uri();
  853. opts.xd = this.xd;
  854. opts.xs = this.xs;
  855. opts.agent = this.agent || false;
  856. opts.supportsBinary = this.supportsBinary;
  857. opts.enablesXDR = this.enablesXDR;
  858. opts.withCredentials = this.withCredentials;
  859. // SSL options for Node.js client
  860. opts.pfx = this.pfx;
  861. opts.key = this.key;
  862. opts.passphrase = this.passphrase;
  863. opts.cert = this.cert;
  864. opts.ca = this.ca;
  865. opts.ciphers = this.ciphers;
  866. opts.rejectUnauthorized = this.rejectUnauthorized;
  867. opts.requestTimeout = this.requestTimeout;
  868. // other options for Node.js client
  869. opts.extraHeaders = this.extraHeaders;
  870. return new Request(opts);
  871. };
  872. /**
  873. * Sends data.
  874. *
  875. * @param {String} data to send.
  876. * @param {Function} called upon flush.
  877. * @api private
  878. */
  879. XHR.prototype.doWrite = function (data, fn) {
  880. var isBinary = typeof data !== 'string' && data !== undefined;
  881. var req = this.request({ method: 'POST', data: data, isBinary: isBinary });
  882. var self = this;
  883. req.on('success', fn);
  884. req.on('error', function (err) {
  885. self.onError('xhr post error', err);
  886. });
  887. this.sendXhr = req;
  888. };
  889. /**
  890. * Starts a poll cycle.
  891. *
  892. * @api private
  893. */
  894. XHR.prototype.doPoll = function () {
  895. debug('xhr poll');
  896. var req = this.request();
  897. var self = this;
  898. req.on('data', function (data) {
  899. self.onData(data);
  900. });
  901. req.on('error', function (err) {
  902. self.onError('xhr poll error', err);
  903. });
  904. this.pollXhr = req;
  905. };
  906. /**
  907. * Request constructor
  908. *
  909. * @param {Object} options
  910. * @api public
  911. */
  912. function Request (opts) {
  913. this.method = opts.method || 'GET';
  914. this.uri = opts.uri;
  915. this.xd = !!opts.xd;
  916. this.xs = !!opts.xs;
  917. this.async = false !== opts.async;
  918. this.data = undefined !== opts.data ? opts.data : null;
  919. this.agent = opts.agent;
  920. this.isBinary = opts.isBinary;
  921. this.supportsBinary = opts.supportsBinary;
  922. this.enablesXDR = opts.enablesXDR;
  923. this.withCredentials = opts.withCredentials;
  924. this.requestTimeout = opts.requestTimeout;
  925. // SSL options for Node.js client
  926. this.pfx = opts.pfx;
  927. this.key = opts.key;
  928. this.passphrase = opts.passphrase;
  929. this.cert = opts.cert;
  930. this.ca = opts.ca;
  931. this.ciphers = opts.ciphers;
  932. this.rejectUnauthorized = opts.rejectUnauthorized;
  933. // other options for Node.js client
  934. this.extraHeaders = opts.extraHeaders;
  935. this.create();
  936. }
  937. /**
  938. * Mix in `Emitter`.
  939. */
  940. Emitter(Request.prototype);
  941. /**
  942. * Creates the XHR object and sends the request.
  943. *
  944. * @api private
  945. */
  946. Request.prototype.create = function () {
  947. var opts = { agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR };
  948. // SSL options for Node.js client
  949. opts.pfx = this.pfx;
  950. opts.key = this.key;
  951. opts.passphrase = this.passphrase;
  952. opts.cert = this.cert;
  953. opts.ca = this.ca;
  954. opts.ciphers = this.ciphers;
  955. opts.rejectUnauthorized = this.rejectUnauthorized;
  956. var xhr = this.xhr = new XMLHttpRequest(opts);
  957. var self = this;
  958. try {
  959. debug('xhr open %s: %s', this.method, this.uri);
  960. xhr.open(this.method, this.uri, this.async);
  961. try {
  962. if (this.extraHeaders) {
  963. xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
  964. for (var i in this.extraHeaders) {
  965. if (this.extraHeaders.hasOwnProperty(i)) {
  966. xhr.setRequestHeader(i, this.extraHeaders[i]);
  967. }
  968. }
  969. }
  970. } catch (e) {}
  971. if ('POST' === this.method) {
  972. try {
  973. if (this.isBinary) {
  974. xhr.setRequestHeader('Content-type', 'application/octet-stream');
  975. } else {
  976. xhr.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
  977. }
  978. } catch (e) {}
  979. }
  980. try {
  981. xhr.setRequestHeader('Accept', '*/*');
  982. } catch (e) {}
  983. // ie6 check
  984. if ('withCredentials' in xhr) {
  985. xhr.withCredentials = this.withCredentials;
  986. }
  987. if (this.requestTimeout) {
  988. xhr.timeout = this.requestTimeout;
  989. }
  990. if (this.hasXDR()) {
  991. xhr.onload = function () {
  992. self.onLoad();
  993. };
  994. xhr.onerror = function () {
  995. self.onError(xhr.responseText);
  996. };
  997. } else {
  998. xhr.onreadystatechange = function () {
  999. if (xhr.readyState === 2) {
  1000. try {
  1001. var contentType = xhr.getResponseHeader('Content-Type');
  1002. if (self.supportsBinary && contentType === 'application/octet-stream' || contentType === 'application/octet-stream; charset=UTF-8') {
  1003. xhr.responseType = 'arraybuffer';
  1004. }
  1005. } catch (e) {}
  1006. }
  1007. if (4 !== xhr.readyState) return;
  1008. if (200 === xhr.status || 1223 === xhr.status) {
  1009. self.onLoad();
  1010. } else {
  1011. // make sure the `error` event handler that's user-set
  1012. // does not throw in the same tick and gets caught here
  1013. setTimeout(function () {
  1014. self.onError(typeof xhr.status === 'number' ? xhr.status : 0);
  1015. }, 0);
  1016. }
  1017. };
  1018. }
  1019. debug('xhr data %s', this.data);
  1020. xhr.send(this.data);
  1021. } catch (e) {
  1022. // Need to defer since .create() is called directly fhrom the constructor
  1023. // and thus the 'error' event can only be only bound *after* this exception
  1024. // occurs. Therefore, also, we cannot throw here at all.
  1025. setTimeout(function () {
  1026. self.onError(e);
  1027. }, 0);
  1028. return;
  1029. }
  1030. if (typeof document !== 'undefined') {
  1031. this.index = Request.requestsCount++;
  1032. Request.requests[this.index] = this;
  1033. }
  1034. };
  1035. /**
  1036. * Called upon successful response.
  1037. *
  1038. * @api private
  1039. */
  1040. Request.prototype.onSuccess = function () {
  1041. this.emit('success');
  1042. this.cleanup();
  1043. };
  1044. /**
  1045. * Called if we have data.
  1046. *
  1047. * @api private
  1048. */
  1049. Request.prototype.onData = function (data) {
  1050. this.emit('data', data);
  1051. this.onSuccess();
  1052. };
  1053. /**
  1054. * Called upon error.
  1055. *
  1056. * @api private
  1057. */
  1058. Request.prototype.onError = function (err) {
  1059. this.emit('error', err);
  1060. this.cleanup(true);
  1061. };
  1062. /**
  1063. * Cleans up house.
  1064. *
  1065. * @api private
  1066. */
  1067. Request.prototype.cleanup = function (fromError) {
  1068. if ('undefined' === typeof this.xhr || null === this.xhr) {
  1069. return;
  1070. }
  1071. // xmlhttprequest
  1072. if (this.hasXDR()) {
  1073. this.xhr.onload = this.xhr.onerror = empty;
  1074. } else {
  1075. this.xhr.onreadystatechange = empty;
  1076. }
  1077. if (fromError) {
  1078. try {
  1079. this.xhr.abort();
  1080. } catch (e) {}
  1081. }
  1082. if (typeof document !== 'undefined') {
  1083. delete Request.requests[this.index];
  1084. }
  1085. this.xhr = null;
  1086. };
  1087. /**
  1088. * Called upon load.
  1089. *
  1090. * @api private
  1091. */
  1092. Request.prototype.onLoad = function () {
  1093. var data;
  1094. try {
  1095. var contentType;
  1096. try {
  1097. contentType = this.xhr.getResponseHeader('Content-Type');
  1098. } catch (e) {}
  1099. if (contentType === 'application/octet-stream' || contentType === 'application/octet-stream; charset=UTF-8') {
  1100. data = this.xhr.response || this.xhr.responseText;
  1101. } else {
  1102. data = this.xhr.responseText;
  1103. }
  1104. } catch (e) {
  1105. this.onError(e);
  1106. }
  1107. if (null != data) {
  1108. this.onData(data);
  1109. }
  1110. };
  1111. /**
  1112. * Check if it has XDomainRequest.
  1113. *
  1114. * @api private
  1115. */
  1116. Request.prototype.hasXDR = function () {
  1117. return typeof XDomainRequest !== 'undefined' && !this.xs && this.enablesXDR;
  1118. };
  1119. /**
  1120. * Aborts the request.
  1121. *
  1122. * @api public
  1123. */
  1124. Request.prototype.abort = function () {
  1125. this.cleanup();
  1126. };
  1127. /**
  1128. * Aborts pending requests when unloading the window. This is needed to prevent
  1129. * memory leaks (e.g. when using IE) and to ensure that no spurious error is
  1130. * emitted.
  1131. */
  1132. Request.requestsCount = 0;
  1133. Request.requests = {};
  1134. if (typeof document !== 'undefined') {
  1135. if (typeof attachEvent === 'function') {
  1136. attachEvent('onunload', unloadHandler);
  1137. } else if (typeof addEventListener === 'function') {
  1138. var terminationEvent = 'onpagehide' in globalThis ? 'pagehide' : 'unload';
  1139. addEventListener(terminationEvent, unloadHandler, false);
  1140. }
  1141. }
  1142. function unloadHandler () {
  1143. for (var i in Request.requests) {
  1144. if (Request.requests.hasOwnProperty(i)) {
  1145. Request.requests[i].abort();
  1146. }
  1147. }
  1148. }
  1149. /***/ },
  1150. /* 7 */
  1151. /***/ function(module, exports, __webpack_require__) {
  1152. /**
  1153. * Module dependencies.
  1154. */
  1155. var Transport = __webpack_require__(8);
  1156. var parseqs = __webpack_require__(19);
  1157. var parser = __webpack_require__(9);
  1158. var inherit = __webpack_require__(20);
  1159. var yeast = __webpack_require__(21);
  1160. var debug = __webpack_require__(22)('engine.io-client:polling');
  1161. /**
  1162. * Module exports.
  1163. */
  1164. module.exports = Polling;
  1165. /**
  1166. * Is XHR2 supported?
  1167. */
  1168. var hasXHR2 = (function () {
  1169. var XMLHttpRequest = __webpack_require__(3);
  1170. var xhr = new XMLHttpRequest({ xdomain: false });
  1171. return null != xhr.responseType;
  1172. })();
  1173. /**
  1174. * Polling interface.
  1175. *
  1176. * @param {Object} opts
  1177. * @api private
  1178. */
  1179. function Polling (opts) {
  1180. var forceBase64 = (opts && opts.forceBase64);
  1181. if (!hasXHR2 || forceBase64) {
  1182. this.supportsBinary = false;
  1183. }
  1184. Transport.call(this, opts);
  1185. }
  1186. /**
  1187. * Inherits from Transport.
  1188. */
  1189. inherit(Polling, Transport);
  1190. /**
  1191. * Transport name.
  1192. */
  1193. Polling.prototype.name = 'polling';
  1194. /**
  1195. * Opens the socket (triggers polling). We write a PING message to determine
  1196. * when the transport is open.
  1197. *
  1198. * @api private
  1199. */
  1200. Polling.prototype.doOpen = function () {
  1201. this.poll();
  1202. };
  1203. /**
  1204. * Pauses polling.
  1205. *
  1206. * @param {Function} callback upon buffers are flushed and transport is paused
  1207. * @api private
  1208. */
  1209. Polling.prototype.pause = function (onPause) {
  1210. var self = this;
  1211. this.readyState = 'pausing';
  1212. function pause () {
  1213. debug('paused');
  1214. self.readyState = 'paused';
  1215. onPause();
  1216. }
  1217. if (this.polling || !this.writable) {
  1218. var total = 0;
  1219. if (this.polling) {
  1220. debug('we are currently polling - waiting to pause');
  1221. total++;
  1222. this.once('pollComplete', function () {
  1223. debug('pre-pause polling complete');
  1224. --total || pause();
  1225. });
  1226. }
  1227. if (!this.writable) {
  1228. debug('we are currently writing - waiting to pause');
  1229. total++;
  1230. this.once('drain', function () {
  1231. debug('pre-pause writing complete');
  1232. --total || pause();
  1233. });
  1234. }
  1235. } else {
  1236. pause();
  1237. }
  1238. };
  1239. /**
  1240. * Starts polling cycle.
  1241. *
  1242. * @api public
  1243. */
  1244. Polling.prototype.poll = function () {
  1245. debug('polling');
  1246. this.polling = true;
  1247. this.doPoll();
  1248. this.emit('poll');
  1249. };
  1250. /**
  1251. * Overloads onData to detect payloads.
  1252. *
  1253. * @api private
  1254. */
  1255. Polling.prototype.onData = function (data) {
  1256. var self = this;
  1257. debug('polling got data %s', data);
  1258. var callback = function (packet, index, total) {
  1259. // if its the first message we consider the transport open
  1260. if ('opening' === self.readyState) {
  1261. self.onOpen();
  1262. }
  1263. // if its a close packet, we close the ongoing requests
  1264. if ('close' === packet.type) {
  1265. self.onClose();
  1266. return false;
  1267. }
  1268. // otherwise bypass onData and handle the message
  1269. self.onPacket(packet);
  1270. };
  1271. // decode payload
  1272. parser.decodePayload(data, this.socket.binaryType, callback);
  1273. // if an event did not trigger closing
  1274. if ('closed' !== this.readyState) {
  1275. // if we got data we're not polling
  1276. this.polling = false;
  1277. this.emit('pollComplete');
  1278. if ('open' === this.readyState) {
  1279. this.poll();
  1280. } else {
  1281. debug('ignoring poll - transport state "%s"', this.readyState);
  1282. }
  1283. }
  1284. };
  1285. /**
  1286. * For polling, send a close packet.
  1287. *
  1288. * @api private
  1289. */
  1290. Polling.prototype.doClose = function () {
  1291. var self = this;
  1292. function close () {
  1293. debug('writing close packet');
  1294. self.write([{ type: 'close' }]);
  1295. }
  1296. if ('open' === this.readyState) {
  1297. debug('transport open - closing');
  1298. close();
  1299. } else {
  1300. // in case we're trying to close while
  1301. // handshaking is in progress (GH-164)
  1302. debug('transport not open - deferring close');
  1303. this.once('open', close);
  1304. }
  1305. };
  1306. /**
  1307. * Writes a packets payload.
  1308. *
  1309. * @param {Array} data packets
  1310. * @param {Function} drain callback
  1311. * @api private
  1312. */
  1313. Polling.prototype.write = function (packets) {
  1314. var self = this;
  1315. this.writable = false;
  1316. var callbackfn = function () {
  1317. self.writable = true;
  1318. self.emit('drain');
  1319. };
  1320. parser.encodePayload(packets, this.supportsBinary, function (data) {
  1321. self.doWrite(data, callbackfn);
  1322. });
  1323. };
  1324. /**
  1325. * Generates uri for connection.
  1326. *
  1327. * @api private
  1328. */
  1329. Polling.prototype.uri = function () {
  1330. var query = this.query || {};
  1331. var schema = this.secure ? 'https' : 'http';
  1332. var port = '';
  1333. // cache busting is forced
  1334. if (false !== this.timestampRequests) {
  1335. query[this.timestampParam] = yeast();
  1336. }
  1337. if (!this.supportsBinary && !query.sid) {
  1338. query.b64 = 1;
  1339. }
  1340. query = parseqs.encode(query);
  1341. // avoid port if default for schema
  1342. if (this.port && (('https' === schema && Number(this.port) !== 443) ||
  1343. ('http' === schema && Number(this.port) !== 80))) {
  1344. port = ':' + this.port;
  1345. }
  1346. // prepend ? to query
  1347. if (query.length) {
  1348. query = '?' + query;
  1349. }
  1350. var ipv6 = this.hostname.indexOf(':') !== -1;
  1351. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  1352. };
  1353. /***/ },
  1354. /* 8 */
  1355. /***/ function(module, exports, __webpack_require__) {
  1356. /**
  1357. * Module dependencies.
  1358. */
  1359. var parser = __webpack_require__(9);
  1360. var Emitter = __webpack_require__(18);
  1361. /**
  1362. * Module exports.
  1363. */
  1364. module.exports = Transport;
  1365. /**
  1366. * Transport abstract constructor.
  1367. *
  1368. * @param {Object} options.
  1369. * @api private
  1370. */
  1371. function Transport (opts) {
  1372. this.path = opts.path;
  1373. this.hostname = opts.hostname;
  1374. this.port = opts.port;
  1375. this.secure = opts.secure;
  1376. this.query = opts.query;
  1377. this.timestampParam = opts.timestampParam;
  1378. this.timestampRequests = opts.timestampRequests;
  1379. this.readyState = '';
  1380. this.agent = opts.agent || false;
  1381. this.socket = opts.socket;
  1382. this.enablesXDR = opts.enablesXDR;
  1383. this.withCredentials = opts.withCredentials;
  1384. // SSL options for Node.js client
  1385. this.pfx = opts.pfx;
  1386. this.key = opts.key;
  1387. this.passphrase = opts.passphrase;
  1388. this.cert = opts.cert;
  1389. this.ca = opts.ca;
  1390. this.ciphers = opts.ciphers;
  1391. this.rejectUnauthorized = opts.rejectUnauthorized;
  1392. this.forceNode = opts.forceNode;
  1393. // results of ReactNative environment detection
  1394. this.isReactNative = opts.isReactNative;
  1395. // other options for Node.js client
  1396. this.extraHeaders = opts.extraHeaders;
  1397. this.localAddress = opts.localAddress;
  1398. }
  1399. /**
  1400. * Mix in `Emitter`.
  1401. */
  1402. Emitter(Transport.prototype);
  1403. /**
  1404. * Emits an error.
  1405. *
  1406. * @param {String} str
  1407. * @return {Transport} for chaining
  1408. * @api public
  1409. */
  1410. Transport.prototype.onError = function (msg, desc) {
  1411. var err = new Error(msg);
  1412. err.type = 'TransportError';
  1413. err.description = desc;
  1414. this.emit('error', err);
  1415. return this;
  1416. };
  1417. /**
  1418. * Opens the transport.
  1419. *
  1420. * @api public
  1421. */
  1422. Transport.prototype.open = function () {
  1423. if ('closed' === this.readyState || '' === this.readyState) {
  1424. this.readyState = 'opening';
  1425. this.doOpen();
  1426. }
  1427. return this;
  1428. };
  1429. /**
  1430. * Closes the transport.
  1431. *
  1432. * @api private
  1433. */
  1434. Transport.prototype.close = function () {
  1435. if ('opening' === this.readyState || 'open' === this.readyState) {
  1436. this.doClose();
  1437. this.onClose();
  1438. }
  1439. return this;
  1440. };
  1441. /**
  1442. * Sends multiple packets.
  1443. *
  1444. * @param {Array} packets
  1445. * @api private
  1446. */
  1447. Transport.prototype.send = function (packets) {
  1448. if ('open' === this.readyState) {
  1449. this.write(packets);
  1450. } else {
  1451. throw new Error('Transport not open');
  1452. }
  1453. };
  1454. /**
  1455. * Called upon open
  1456. *
  1457. * @api private
  1458. */
  1459. Transport.prototype.onOpen = function () {
  1460. this.readyState = 'open';
  1461. this.writable = true;
  1462. this.emit('open');
  1463. };
  1464. /**
  1465. * Called with data.
  1466. *
  1467. * @param {String} data
  1468. * @api private
  1469. */
  1470. Transport.prototype.onData = function (data) {
  1471. var packet = parser.decodePacket(data, this.socket.binaryType);
  1472. this.onPacket(packet);
  1473. };
  1474. /**
  1475. * Called with a decoded packet.
  1476. */
  1477. Transport.prototype.onPacket = function (packet) {
  1478. this.emit('packet', packet);
  1479. };
  1480. /**
  1481. * Called upon close.
  1482. *
  1483. * @api private
  1484. */
  1485. Transport.prototype.onClose = function () {
  1486. this.readyState = 'closed';
  1487. this.emit('close');
  1488. };
  1489. /***/ },
  1490. /* 9 */
  1491. /***/ function(module, exports, __webpack_require__) {
  1492. /**
  1493. * Module dependencies.
  1494. */
  1495. var keys = __webpack_require__(10);
  1496. var hasBinary = __webpack_require__(11);
  1497. var sliceBuffer = __webpack_require__(13);
  1498. var after = __webpack_require__(14);
  1499. var utf8 = __webpack_require__(15);
  1500. var base64encoder;
  1501. if (typeof ArrayBuffer !== 'undefined') {
  1502. base64encoder = __webpack_require__(16);
  1503. }
  1504. /**
  1505. * Check if we are running an android browser. That requires us to use
  1506. * ArrayBuffer with polling transports...
  1507. *
  1508. * http://ghinda.net/jpeg-blob-ajax-android/
  1509. */
  1510. var isAndroid = typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
  1511. /**
  1512. * Check if we are running in PhantomJS.
  1513. * Uploading a Blob with PhantomJS does not work correctly, as reported here:
  1514. * https://github.com/ariya/phantomjs/issues/11395
  1515. * @type boolean
  1516. */
  1517. var isPhantomJS = typeof navigator !== 'undefined' && /PhantomJS/i.test(navigator.userAgent);
  1518. /**
  1519. * When true, avoids using Blobs to encode payloads.
  1520. * @type boolean
  1521. */
  1522. var dontSendBlobs = isAndroid || isPhantomJS;
  1523. /**
  1524. * Current protocol version.
  1525. */
  1526. exports.protocol = 3;
  1527. /**
  1528. * Packet types.
  1529. */
  1530. var packets = exports.packets = {
  1531. open: 0 // non-ws
  1532. , close: 1 // non-ws
  1533. , ping: 2
  1534. , pong: 3
  1535. , message: 4
  1536. , upgrade: 5
  1537. , noop: 6
  1538. };
  1539. var packetslist = keys(packets);
  1540. /**
  1541. * Premade error packet.
  1542. */
  1543. var err = { type: 'error', data: 'parser error' };
  1544. /**
  1545. * Create a blob api even for blob builder when vendor prefixes exist
  1546. */
  1547. var Blob = __webpack_require__(17);
  1548. /**
  1549. * Encodes a packet.
  1550. *
  1551. * <packet type id> [ <data> ]
  1552. *
  1553. * Example:
  1554. *
  1555. * 5hello world
  1556. * 3
  1557. * 4
  1558. *
  1559. * Binary is encoded in an identical principle
  1560. *
  1561. * @api private
  1562. */
  1563. exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
  1564. if (typeof supportsBinary === 'function') {
  1565. callback = supportsBinary;
  1566. supportsBinary = false;
  1567. }
  1568. if (typeof utf8encode === 'function') {
  1569. callback = utf8encode;
  1570. utf8encode = null;
  1571. }
  1572. var data = (packet.data === undefined)
  1573. ? undefined
  1574. : packet.data.buffer || packet.data;
  1575. if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) {
  1576. return encodeArrayBuffer(packet, supportsBinary, callback);
  1577. } else if (typeof Blob !== 'undefined' && data instanceof Blob) {
  1578. return encodeBlob(packet, supportsBinary, callback);
  1579. }
  1580. // might be an object with { base64: true, data: dataAsBase64String }
  1581. if (data && data.base64) {
  1582. return encodeBase64Object(packet, callback);
  1583. }
  1584. // Sending data as a utf-8 string
  1585. var encoded = packets[packet.type];
  1586. // data fragment is optional
  1587. if (undefined !== packet.data) {
  1588. encoded += utf8encode ? utf8.encode(String(packet.data), { strict: false }) : String(packet.data);
  1589. }
  1590. return callback('' + encoded);
  1591. };
  1592. function encodeBase64Object(packet, callback) {
  1593. // packet data is an object { base64: true, data: dataAsBase64String }
  1594. var message = 'b' + exports.packets[packet.type] + packet.data.data;
  1595. return callback(message);
  1596. }
  1597. /**
  1598. * Encode packet helpers for binary types
  1599. */
  1600. function encodeArrayBuffer(packet, supportsBinary, callback) {
  1601. if (!supportsBinary) {
  1602. return exports.encodeBase64Packet(packet, callback);
  1603. }
  1604. var data = packet.data;
  1605. var contentArray = new Uint8Array(data);
  1606. var resultBuffer = new Uint8Array(1 + data.byteLength);
  1607. resultBuffer[0] = packets[packet.type];
  1608. for (var i = 0; i < contentArray.length; i++) {
  1609. resultBuffer[i+1] = contentArray[i];
  1610. }
  1611. return callback(resultBuffer.buffer);
  1612. }
  1613. function encodeBlobAsArrayBuffer(packet, supportsBinary, callback) {
  1614. if (!supportsBinary) {
  1615. return exports.encodeBase64Packet(packet, callback);
  1616. }
  1617. var fr = new FileReader();
  1618. fr.onload = function() {
  1619. exports.encodePacket({ type: packet.type, data: fr.result }, supportsBinary, true, callback);
  1620. };
  1621. return fr.readAsArrayBuffer(packet.data);
  1622. }
  1623. function encodeBlob(packet, supportsBinary, callback) {
  1624. if (!supportsBinary) {
  1625. return exports.encodeBase64Packet(packet, callback);
  1626. }
  1627. if (dontSendBlobs) {
  1628. return encodeBlobAsArrayBuffer(packet, supportsBinary, callback);
  1629. }
  1630. var length = new Uint8Array(1);
  1631. length[0] = packets[packet.type];
  1632. var blob = new Blob([length.buffer, packet.data]);
  1633. return callback(blob);
  1634. }
  1635. /**
  1636. * Encodes a packet with binary data in a base64 string
  1637. *
  1638. * @param {Object} packet, has `type` and `data`
  1639. * @return {String} base64 encoded message
  1640. */
  1641. exports.encodeBase64Packet = function(packet, callback) {
  1642. var message = 'b' + exports.packets[packet.type];
  1643. if (typeof Blob !== 'undefined' && packet.data instanceof Blob) {
  1644. var fr = new FileReader();
  1645. fr.onload = function() {
  1646. var b64 = fr.result.split(',')[1];
  1647. callback(message + b64);
  1648. };
  1649. return fr.readAsDataURL(packet.data);
  1650. }
  1651. var b64data;
  1652. try {
  1653. b64data = String.fromCharCode.apply(null, new Uint8Array(packet.data));
  1654. } catch (e) {
  1655. // iPhone Safari doesn't let you apply with typed arrays
  1656. var typed = new Uint8Array(packet.data);
  1657. var basic = new Array(typed.length);
  1658. for (var i = 0; i < typed.length; i++) {
  1659. basic[i] = typed[i];
  1660. }
  1661. b64data = String.fromCharCode.apply(null, basic);
  1662. }
  1663. message += btoa(b64data);
  1664. return callback(message);
  1665. };
  1666. /**
  1667. * Decodes a packet. Changes format to Blob if requested.
  1668. *
  1669. * @return {Object} with `type` and `data` (if any)
  1670. * @api private
  1671. */
  1672. exports.decodePacket = function (data, binaryType, utf8decode) {
  1673. if (data === undefined) {
  1674. return err;
  1675. }
  1676. // String data
  1677. if (typeof data === 'string') {
  1678. if (data.charAt(0) === 'b') {
  1679. return exports.decodeBase64Packet(data.substr(1), binaryType);
  1680. }
  1681. if (utf8decode) {
  1682. data = tryDecode(data);
  1683. if (data === false) {
  1684. return err;
  1685. }
  1686. }
  1687. var type = data.charAt(0);
  1688. if (Number(type) != type || !packetslist[type]) {
  1689. return err;
  1690. }
  1691. if (data.length > 1) {
  1692. return { type: packetslist[type], data: data.substring(1) };
  1693. } else {
  1694. return { type: packetslist[type] };
  1695. }
  1696. }
  1697. var asArray = new Uint8Array(data);
  1698. var type = asArray[0];
  1699. var rest = sliceBuffer(data, 1);
  1700. if (Blob && binaryType === 'blob') {
  1701. rest = new Blob([rest]);
  1702. }
  1703. return { type: packetslist[type], data: rest };
  1704. };
  1705. function tryDecode(data) {
  1706. try {
  1707. data = utf8.decode(data, { strict: false });
  1708. } catch (e) {
  1709. return false;
  1710. }
  1711. return data;
  1712. }
  1713. /**
  1714. * Decodes a packet encoded in a base64 string
  1715. *
  1716. * @param {String} base64 encoded message
  1717. * @return {Object} with `type` and `data` (if any)
  1718. */
  1719. exports.decodeBase64Packet = function(msg, binaryType) {
  1720. var type = packetslist[msg.charAt(0)];
  1721. if (!base64encoder) {
  1722. return { type: type, data: { base64: true, data: msg.substr(1) } };
  1723. }
  1724. var data = base64encoder.decode(msg.substr(1));
  1725. if (binaryType === 'blob' && Blob) {
  1726. data = new Blob([data]);
  1727. }
  1728. return { type: type, data: data };
  1729. };
  1730. /**
  1731. * Encodes multiple messages (payload).
  1732. *
  1733. * <length>:data
  1734. *
  1735. * Example:
  1736. *
  1737. * 11:hello world2:hi
  1738. *
  1739. * If any contents are binary, they will be encoded as base64 strings. Base64
  1740. * encoded strings are marked with a b before the length specifier
  1741. *
  1742. * @param {Array} packets
  1743. * @api private
  1744. */
  1745. exports.encodePayload = function (packets, supportsBinary, callback) {
  1746. if (typeof supportsBinary === 'function') {
  1747. callback = supportsBinary;
  1748. supportsBinary = null;
  1749. }
  1750. var isBinary = hasBinary(packets);
  1751. if (supportsBinary && isBinary) {
  1752. if (Blob && !dontSendBlobs) {
  1753. return exports.encodePayloadAsBlob(packets, callback);
  1754. }
  1755. return exports.encodePayloadAsArrayBuffer(packets, callback);
  1756. }
  1757. if (!packets.length) {
  1758. return callback('0:');
  1759. }
  1760. function setLengthHeader(message) {
  1761. return message.length + ':' + message;
  1762. }
  1763. function encodeOne(packet, doneCallback) {
  1764. exports.encodePacket(packet, !isBinary ? false : supportsBinary, false, function(message) {
  1765. doneCallback(null, setLengthHeader(message));
  1766. });
  1767. }
  1768. map(packets, encodeOne, function(err, results) {
  1769. return callback(results.join(''));
  1770. });
  1771. };
  1772. /**
  1773. * Async array map using after
  1774. */
  1775. function map(ary, each, done) {
  1776. var result = new Array(ary.length);
  1777. var next = after(ary.length, done);
  1778. var eachWithIndex = function(i, el, cb) {
  1779. each(el, function(error, msg) {
  1780. result[i] = msg;
  1781. cb(error, result);
  1782. });
  1783. };
  1784. for (var i = 0; i < ary.length; i++) {
  1785. eachWithIndex(i, ary[i], next);
  1786. }
  1787. }
  1788. /*
  1789. * Decodes data when a payload is maybe expected. Possible binary contents are
  1790. * decoded from their base64 representation
  1791. *
  1792. * @param {String} data, callback method
  1793. * @api public
  1794. */
  1795. exports.decodePayload = function (data, binaryType, callback) {
  1796. if (typeof data !== 'string') {
  1797. return exports.decodePayloadAsBinary(data, binaryType, callback);
  1798. }
  1799. if (typeof binaryType === 'function') {
  1800. callback = binaryType;
  1801. binaryType = null;
  1802. }
  1803. var packet;
  1804. if (data === '') {
  1805. // parser error - ignoring payload
  1806. return callback(err, 0, 1);
  1807. }
  1808. var length = '', n, msg;
  1809. for (var i = 0, l = data.length; i < l; i++) {
  1810. var chr = data.charAt(i);
  1811. if (chr !== ':') {
  1812. length += chr;
  1813. continue;
  1814. }
  1815. if (length === '' || (length != (n = Number(length)))) {
  1816. // parser error - ignoring payload
  1817. return callback(err, 0, 1);
  1818. }
  1819. msg = data.substr(i + 1, n);
  1820. if (length != msg.length) {
  1821. // parser error - ignoring payload
  1822. return callback(err, 0, 1);
  1823. }
  1824. if (msg.length) {
  1825. packet = exports.decodePacket(msg, binaryType, false);
  1826. if (err.type === packet.type && err.data === packet.data) {
  1827. // parser error in individual packet - ignoring payload
  1828. return callback(err, 0, 1);
  1829. }
  1830. var ret = callback(packet, i + n, l);
  1831. if (false === ret) return;
  1832. }
  1833. // advance cursor
  1834. i += n;
  1835. length = '';
  1836. }
  1837. if (length !== '') {
  1838. // parser error - ignoring payload
  1839. return callback(err, 0, 1);
  1840. }
  1841. };
  1842. /**
  1843. * Encodes multiple messages (payload) as binary.
  1844. *
  1845. * <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
  1846. * 255><data>
  1847. *
  1848. * Example:
  1849. * 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
  1850. *
  1851. * @param {Array} packets
  1852. * @return {ArrayBuffer} encoded payload
  1853. * @api private
  1854. */
  1855. exports.encodePayloadAsArrayBuffer = function(packets, callback) {
  1856. if (!packets.length) {
  1857. return callback(new ArrayBuffer(0));
  1858. }
  1859. function encodeOne(packet, doneCallback) {
  1860. exports.encodePacket(packet, true, true, function(data) {
  1861. return doneCallback(null, data);
  1862. });
  1863. }
  1864. map(packets, encodeOne, function(err, encodedPackets) {
  1865. var totalLength = encodedPackets.reduce(function(acc, p) {
  1866. var len;
  1867. if (typeof p === 'string'){
  1868. len = p.length;
  1869. } else {
  1870. len = p.byteLength;
  1871. }
  1872. return acc + len.toString().length + len + 2; // string/binary identifier + separator = 2
  1873. }, 0);
  1874. var resultArray = new Uint8Array(totalLength);
  1875. var bufferIndex = 0;
  1876. encodedPackets.forEach(function(p) {
  1877. var isString = typeof p === 'string';
  1878. var ab = p;
  1879. if (isString) {
  1880. var view = new Uint8Array(p.length);
  1881. for (var i = 0; i < p.length; i++) {
  1882. view[i] = p.charCodeAt(i);
  1883. }
  1884. ab = view.buffer;
  1885. }
  1886. if (isString) { // not true binary
  1887. resultArray[bufferIndex++] = 0;
  1888. } else { // true binary
  1889. resultArray[bufferIndex++] = 1;
  1890. }
  1891. var lenStr = ab.byteLength.toString();
  1892. for (var i = 0; i < lenStr.length; i++) {
  1893. resultArray[bufferIndex++] = parseInt(lenStr[i]);
  1894. }
  1895. resultArray[bufferIndex++] = 255;
  1896. var view = new Uint8Array(ab);
  1897. for (var i = 0; i < view.length; i++) {
  1898. resultArray[bufferIndex++] = view[i];
  1899. }
  1900. });
  1901. return callback(resultArray.buffer);
  1902. });
  1903. };
  1904. /**
  1905. * Encode as Blob
  1906. */
  1907. exports.encodePayloadAsBlob = function(packets, callback) {
  1908. function encodeOne(packet, doneCallback) {
  1909. exports.encodePacket(packet, true, true, function(encoded) {
  1910. var binaryIdentifier = new Uint8Array(1);
  1911. binaryIdentifier[0] = 1;
  1912. if (typeof encoded === 'string') {
  1913. var view = new Uint8Array(encoded.length);
  1914. for (var i = 0; i < encoded.length; i++) {
  1915. view[i] = encoded.charCodeAt(i);
  1916. }
  1917. encoded = view.buffer;
  1918. binaryIdentifier[0] = 0;
  1919. }
  1920. var len = (encoded instanceof ArrayBuffer)
  1921. ? encoded.byteLength
  1922. : encoded.size;
  1923. var lenStr = len.toString();
  1924. var lengthAry = new Uint8Array(lenStr.length + 1);
  1925. for (var i = 0; i < lenStr.length; i++) {
  1926. lengthAry[i] = parseInt(lenStr[i]);
  1927. }
  1928. lengthAry[lenStr.length] = 255;
  1929. if (Blob) {
  1930. var blob = new Blob([binaryIdentifier.buffer, lengthAry.buffer, encoded]);
  1931. doneCallback(null, blob);
  1932. }
  1933. });
  1934. }
  1935. map(packets, encodeOne, function(err, results) {
  1936. return callback(new Blob(results));
  1937. });
  1938. };
  1939. /*
  1940. * Decodes data when a payload is maybe expected. Strings are decoded by
  1941. * interpreting each byte as a key code for entries marked to start with 0. See
  1942. * description of encodePayloadAsBinary
  1943. *
  1944. * @param {ArrayBuffer} data, callback method
  1945. * @api public
  1946. */
  1947. exports.decodePayloadAsBinary = function (data, binaryType, callback) {
  1948. if (typeof binaryType === 'function') {
  1949. callback = binaryType;
  1950. binaryType = null;
  1951. }
  1952. var bufferTail = data;
  1953. var buffers = [];
  1954. while (bufferTail.byteLength > 0) {
  1955. var tailArray = new Uint8Array(bufferTail);
  1956. var isString = tailArray[0] === 0;
  1957. var msgLength = '';
  1958. for (var i = 1; ; i++) {
  1959. if (tailArray[i] === 255) break;
  1960. // 310 = char length of Number.MAX_VALUE
  1961. if (msgLength.length > 310) {
  1962. return callback(err, 0, 1);
  1963. }
  1964. msgLength += tailArray[i];
  1965. }
  1966. bufferTail = sliceBuffer(bufferTail, 2 + msgLength.length);
  1967. msgLength = parseInt(msgLength);
  1968. var msg = sliceBuffer(bufferTail, 0, msgLength);
  1969. if (isString) {
  1970. try {
  1971. msg = String.fromCharCode.apply(null, new Uint8Array(msg));
  1972. } catch (e) {
  1973. // iPhone Safari doesn't let you apply to typed arrays
  1974. var typed = new Uint8Array(msg);
  1975. msg = '';
  1976. for (var i = 0; i < typed.length; i++) {
  1977. msg += String.fromCharCode(typed[i]);
  1978. }
  1979. }
  1980. }
  1981. buffers.push(msg);
  1982. bufferTail = sliceBuffer(bufferTail, msgLength);
  1983. }
  1984. var total = buffers.length;
  1985. buffers.forEach(function(buffer, i) {
  1986. callback(exports.decodePacket(buffer, binaryType, true), i, total);
  1987. });
  1988. };
  1989. /***/ },
  1990. /* 10 */
  1991. /***/ function(module, exports) {
  1992. /**
  1993. * Gets the keys for an object.
  1994. *
  1995. * @return {Array} keys
  1996. * @api private
  1997. */
  1998. module.exports = Object.keys || function keys (obj){
  1999. var arr = [];
  2000. var has = Object.prototype.hasOwnProperty;
  2001. for (var i in obj) {
  2002. if (has.call(obj, i)) {
  2003. arr.push(i);
  2004. }
  2005. }
  2006. return arr;
  2007. };
  2008. /***/ },
  2009. /* 11 */
  2010. /***/ function(module, exports, __webpack_require__) {
  2011. /* global Blob File */
  2012. /*
  2013. * Module requirements.
  2014. */
  2015. var isArray = __webpack_require__(12);
  2016. var toString = Object.prototype.toString;
  2017. var withNativeBlob = typeof Blob === 'function' ||
  2018. typeof Blob !== 'undefined' && toString.call(Blob) === '[object BlobConstructor]';
  2019. var withNativeFile = typeof File === 'function' ||
  2020. typeof File !== 'undefined' && toString.call(File) === '[object FileConstructor]';
  2021. /**
  2022. * Module exports.
  2023. */
  2024. module.exports = hasBinary;
  2025. /**
  2026. * Checks for binary data.
  2027. *
  2028. * Supports Buffer, ArrayBuffer, Blob and File.
  2029. *
  2030. * @param {Object} anything
  2031. * @api public
  2032. */
  2033. function hasBinary (obj) {
  2034. if (!obj || typeof obj !== 'object') {
  2035. return false;
  2036. }
  2037. if (isArray(obj)) {
  2038. for (var i = 0, l = obj.length; i < l; i++) {
  2039. if (hasBinary(obj[i])) {
  2040. return true;
  2041. }
  2042. }
  2043. return false;
  2044. }
  2045. if ((typeof Buffer === 'function' && Buffer.isBuffer && Buffer.isBuffer(obj)) ||
  2046. (typeof ArrayBuffer === 'function' && obj instanceof ArrayBuffer) ||
  2047. (withNativeBlob && obj instanceof Blob) ||
  2048. (withNativeFile && obj instanceof File)
  2049. ) {
  2050. return true;
  2051. }
  2052. // see: https://github.com/Automattic/has-binary/pull/4
  2053. if (obj.toJSON && typeof obj.toJSON === 'function' && arguments.length === 1) {
  2054. return hasBinary(obj.toJSON(), true);
  2055. }
  2056. for (var key in obj) {
  2057. if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
  2058. return true;
  2059. }
  2060. }
  2061. return false;
  2062. }
  2063. /***/ },
  2064. /* 12 */
  2065. /***/ function(module, exports) {
  2066. var toString = {}.toString;
  2067. module.exports = Array.isArray || function (arr) {
  2068. return toString.call(arr) == '[object Array]';
  2069. };
  2070. /***/ },
  2071. /* 13 */
  2072. /***/ function(module, exports) {
  2073. /**
  2074. * An abstraction for slicing an arraybuffer even when
  2075. * ArrayBuffer.prototype.slice is not supported
  2076. *
  2077. * @api public
  2078. */
  2079. module.exports = function(arraybuffer, start, end) {
  2080. var bytes = arraybuffer.byteLength;
  2081. start = start || 0;
  2082. end = end || bytes;
  2083. if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
  2084. if (start < 0) { start += bytes; }
  2085. if (end < 0) { end += bytes; }
  2086. if (end > bytes) { end = bytes; }
  2087. if (start >= bytes || start >= end || bytes === 0) {
  2088. return new ArrayBuffer(0);
  2089. }
  2090. var abv = new Uint8Array(arraybuffer);
  2091. var result = new Uint8Array(end - start);
  2092. for (var i = start, ii = 0; i < end; i++, ii++) {
  2093. result[ii] = abv[i];
  2094. }
  2095. return result.buffer;
  2096. };
  2097. /***/ },
  2098. /* 14 */
  2099. /***/ function(module, exports) {
  2100. module.exports = after
  2101. function after(count, callback, err_cb) {
  2102. var bail = false
  2103. err_cb = err_cb || noop
  2104. proxy.count = count
  2105. return (count === 0) ? callback() : proxy
  2106. function proxy(err, result) {
  2107. if (proxy.count <= 0) {
  2108. throw new Error('after called too many times')
  2109. }
  2110. --proxy.count
  2111. // after first error, rest are passed to err_cb
  2112. if (err) {
  2113. bail = true
  2114. callback(err)
  2115. // future error callbacks will go to error handler
  2116. callback = err_cb
  2117. } else if (proxy.count === 0 && !bail) {
  2118. callback(null, result)
  2119. }
  2120. }
  2121. }
  2122. function noop() {}
  2123. /***/ },
  2124. /* 15 */
  2125. /***/ function(module, exports) {
  2126. /*! https://mths.be/utf8js v2.1.2 by @mathias */
  2127. var stringFromCharCode = String.fromCharCode;
  2128. // Taken from https://mths.be/punycode
  2129. function ucs2decode(string) {
  2130. var output = [];
  2131. var counter = 0;
  2132. var length = string.length;
  2133. var value;
  2134. var extra;
  2135. while (counter < length) {
  2136. value = string.charCodeAt(counter++);
  2137. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  2138. // high surrogate, and there is a next character
  2139. extra = string.charCodeAt(counter++);
  2140. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  2141. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  2142. } else {
  2143. // unmatched surrogate; only append this code unit, in case the next
  2144. // code unit is the high surrogate of a surrogate pair
  2145. output.push(value);
  2146. counter--;
  2147. }
  2148. } else {
  2149. output.push(value);
  2150. }
  2151. }
  2152. return output;
  2153. }
  2154. // Taken from https://mths.be/punycode
  2155. function ucs2encode(array) {
  2156. var length = array.length;
  2157. var index = -1;
  2158. var value;
  2159. var output = '';
  2160. while (++index < length) {
  2161. value = array[index];
  2162. if (value > 0xFFFF) {
  2163. value -= 0x10000;
  2164. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  2165. value = 0xDC00 | value & 0x3FF;
  2166. }
  2167. output += stringFromCharCode(value);
  2168. }
  2169. return output;
  2170. }
  2171. function checkScalarValue(codePoint, strict) {
  2172. if (codePoint >= 0xD800 && codePoint <= 0xDFFF) {
  2173. if (strict) {
  2174. throw Error(
  2175. 'Lone surrogate U+' + codePoint.toString(16).toUpperCase() +
  2176. ' is not a scalar value'
  2177. );
  2178. }
  2179. return false;
  2180. }
  2181. return true;
  2182. }
  2183. /*--------------------------------------------------------------------------*/
  2184. function createByte(codePoint, shift) {
  2185. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  2186. }
  2187. function encodeCodePoint(codePoint, strict) {
  2188. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  2189. return stringFromCharCode(codePoint);
  2190. }
  2191. var symbol = '';
  2192. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  2193. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  2194. }
  2195. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  2196. if (!checkScalarValue(codePoint, strict)) {
  2197. codePoint = 0xFFFD;
  2198. }
  2199. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  2200. symbol += createByte(codePoint, 6);
  2201. }
  2202. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  2203. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  2204. symbol += createByte(codePoint, 12);
  2205. symbol += createByte(codePoint, 6);
  2206. }
  2207. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  2208. return symbol;
  2209. }
  2210. function utf8encode(string, opts) {
  2211. opts = opts || {};
  2212. var strict = false !== opts.strict;
  2213. var codePoints = ucs2decode(string);
  2214. var length = codePoints.length;
  2215. var index = -1;
  2216. var codePoint;
  2217. var byteString = '';
  2218. while (++index < length) {
  2219. codePoint = codePoints[index];
  2220. byteString += encodeCodePoint(codePoint, strict);
  2221. }
  2222. return byteString;
  2223. }
  2224. /*--------------------------------------------------------------------------*/
  2225. function readContinuationByte() {
  2226. if (byteIndex >= byteCount) {
  2227. throw Error('Invalid byte index');
  2228. }
  2229. var continuationByte = byteArray[byteIndex] & 0xFF;
  2230. byteIndex++;
  2231. if ((continuationByte & 0xC0) == 0x80) {
  2232. return continuationByte & 0x3F;
  2233. }
  2234. // If we end up here, it’s not a continuation byte
  2235. throw Error('Invalid continuation byte');
  2236. }
  2237. function decodeSymbol(strict) {
  2238. var byte1;
  2239. var byte2;
  2240. var byte3;
  2241. var byte4;
  2242. var codePoint;
  2243. if (byteIndex > byteCount) {
  2244. throw Error('Invalid byte index');
  2245. }
  2246. if (byteIndex == byteCount) {
  2247. return false;
  2248. }
  2249. // Read first byte
  2250. byte1 = byteArray[byteIndex] & 0xFF;
  2251. byteIndex++;
  2252. // 1-byte sequence (no continuation bytes)
  2253. if ((byte1 & 0x80) == 0) {
  2254. return byte1;
  2255. }
  2256. // 2-byte sequence
  2257. if ((byte1 & 0xE0) == 0xC0) {
  2258. byte2 = readContinuationByte();
  2259. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  2260. if (codePoint >= 0x80) {
  2261. return codePoint;
  2262. } else {
  2263. throw Error('Invalid continuation byte');
  2264. }
  2265. }
  2266. // 3-byte sequence (may include unpaired surrogates)
  2267. if ((byte1 & 0xF0) == 0xE0) {
  2268. byte2 = readContinuationByte();
  2269. byte3 = readContinuationByte();
  2270. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  2271. if (codePoint >= 0x0800) {
  2272. return checkScalarValue(codePoint, strict) ? codePoint : 0xFFFD;
  2273. } else {
  2274. throw Error('Invalid continuation byte');
  2275. }
  2276. }
  2277. // 4-byte sequence
  2278. if ((byte1 & 0xF8) == 0xF0) {
  2279. byte2 = readContinuationByte();
  2280. byte3 = readContinuationByte();
  2281. byte4 = readContinuationByte();
  2282. codePoint = ((byte1 & 0x07) << 0x12) | (byte2 << 0x0C) |
  2283. (byte3 << 0x06) | byte4;
  2284. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  2285. return codePoint;
  2286. }
  2287. }
  2288. throw Error('Invalid UTF-8 detected');
  2289. }
  2290. var byteArray;
  2291. var byteCount;
  2292. var byteIndex;
  2293. function utf8decode(byteString, opts) {
  2294. opts = opts || {};
  2295. var strict = false !== opts.strict;
  2296. byteArray = ucs2decode(byteString);
  2297. byteCount = byteArray.length;
  2298. byteIndex = 0;
  2299. var codePoints = [];
  2300. var tmp;
  2301. while ((tmp = decodeSymbol(strict)) !== false) {
  2302. codePoints.push(tmp);
  2303. }
  2304. return ucs2encode(codePoints);
  2305. }
  2306. module.exports = {
  2307. version: '2.1.2',
  2308. encode: utf8encode,
  2309. decode: utf8decode
  2310. };
  2311. /***/ },
  2312. /* 16 */
  2313. /***/ function(module, exports) {
  2314. /*
  2315. * base64-arraybuffer
  2316. * https://github.com/niklasvh/base64-arraybuffer
  2317. *
  2318. * Copyright (c) 2012 Niklas von Hertzen
  2319. * Licensed under the MIT license.
  2320. */
  2321. (function(){
  2322. "use strict";
  2323. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  2324. // Use a lookup table to find the index.
  2325. var lookup = new Uint8Array(256);
  2326. for (var i = 0; i < chars.length; i++) {
  2327. lookup[chars.charCodeAt(i)] = i;
  2328. }
  2329. exports.encode = function(arraybuffer) {
  2330. var bytes = new Uint8Array(arraybuffer),
  2331. i, len = bytes.length, base64 = "";
  2332. for (i = 0; i < len; i+=3) {
  2333. base64 += chars[bytes[i] >> 2];
  2334. base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
  2335. base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
  2336. base64 += chars[bytes[i + 2] & 63];
  2337. }
  2338. if ((len % 3) === 2) {
  2339. base64 = base64.substring(0, base64.length - 1) + "=";
  2340. } else if (len % 3 === 1) {
  2341. base64 = base64.substring(0, base64.length - 2) + "==";
  2342. }
  2343. return base64;
  2344. };
  2345. exports.decode = function(base64) {
  2346. var bufferLength = base64.length * 0.75,
  2347. len = base64.length, i, p = 0,
  2348. encoded1, encoded2, encoded3, encoded4;
  2349. if (base64[base64.length - 1] === "=") {
  2350. bufferLength--;
  2351. if (base64[base64.length - 2] === "=") {
  2352. bufferLength--;
  2353. }
  2354. }
  2355. var arraybuffer = new ArrayBuffer(bufferLength),
  2356. bytes = new Uint8Array(arraybuffer);
  2357. for (i = 0; i < len; i+=4) {
  2358. encoded1 = lookup[base64.charCodeAt(i)];
  2359. encoded2 = lookup[base64.charCodeAt(i+1)];
  2360. encoded3 = lookup[base64.charCodeAt(i+2)];
  2361. encoded4 = lookup[base64.charCodeAt(i+3)];
  2362. bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
  2363. bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  2364. bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
  2365. }
  2366. return arraybuffer;
  2367. };
  2368. })();
  2369. /***/ },
  2370. /* 17 */
  2371. /***/ function(module, exports) {
  2372. /**
  2373. * Create a blob builder even when vendor prefixes exist
  2374. */
  2375. var BlobBuilder = typeof BlobBuilder !== 'undefined' ? BlobBuilder :
  2376. typeof WebKitBlobBuilder !== 'undefined' ? WebKitBlobBuilder :
  2377. typeof MSBlobBuilder !== 'undefined' ? MSBlobBuilder :
  2378. typeof MozBlobBuilder !== 'undefined' ? MozBlobBuilder :
  2379. false;
  2380. /**
  2381. * Check if Blob constructor is supported
  2382. */
  2383. var blobSupported = (function() {
  2384. try {
  2385. var a = new Blob(['hi']);
  2386. return a.size === 2;
  2387. } catch(e) {
  2388. return false;
  2389. }
  2390. })();
  2391. /**
  2392. * Check if Blob constructor supports ArrayBufferViews
  2393. * Fails in Safari 6, so we need to map to ArrayBuffers there.
  2394. */
  2395. var blobSupportsArrayBufferView = blobSupported && (function() {
  2396. try {
  2397. var b = new Blob([new Uint8Array([1,2])]);
  2398. return b.size === 2;
  2399. } catch(e) {
  2400. return false;
  2401. }
  2402. })();
  2403. /**
  2404. * Check if BlobBuilder is supported
  2405. */
  2406. var blobBuilderSupported = BlobBuilder
  2407. && BlobBuilder.prototype.append
  2408. && BlobBuilder.prototype.getBlob;
  2409. /**
  2410. * Helper function that maps ArrayBufferViews to ArrayBuffers
  2411. * Used by BlobBuilder constructor and old browsers that didn't
  2412. * support it in the Blob constructor.
  2413. */
  2414. function mapArrayBufferViews(ary) {
  2415. return ary.map(function(chunk) {
  2416. if (chunk.buffer instanceof ArrayBuffer) {
  2417. var buf = chunk.buffer;
  2418. // if this is a subarray, make a copy so we only
  2419. // include the subarray region from the underlying buffer
  2420. if (chunk.byteLength !== buf.byteLength) {
  2421. var copy = new Uint8Array(chunk.byteLength);
  2422. copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
  2423. buf = copy.buffer;
  2424. }
  2425. return buf;
  2426. }
  2427. return chunk;
  2428. });
  2429. }
  2430. function BlobBuilderConstructor(ary, options) {
  2431. options = options || {};
  2432. var bb = new BlobBuilder();
  2433. mapArrayBufferViews(ary).forEach(function(part) {
  2434. bb.append(part);
  2435. });
  2436. return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
  2437. };
  2438. function BlobConstructor(ary, options) {
  2439. return new Blob(mapArrayBufferViews(ary), options || {});
  2440. };
  2441. if (typeof Blob !== 'undefined') {
  2442. BlobBuilderConstructor.prototype = Blob.prototype;
  2443. BlobConstructor.prototype = Blob.prototype;
  2444. }
  2445. module.exports = (function() {
  2446. if (blobSupported) {
  2447. return blobSupportsArrayBufferView ? Blob : BlobConstructor;
  2448. } else if (blobBuilderSupported) {
  2449. return BlobBuilderConstructor;
  2450. } else {
  2451. return undefined;
  2452. }
  2453. })();
  2454. /***/ },
  2455. /* 18 */
  2456. /***/ function(module, exports, __webpack_require__) {
  2457. /**
  2458. * Expose `Emitter`.
  2459. */
  2460. if (true) {
  2461. module.exports = Emitter;
  2462. }
  2463. /**
  2464. * Initialize a new `Emitter`.
  2465. *
  2466. * @api public
  2467. */
  2468. function Emitter(obj) {
  2469. if (obj) return mixin(obj);
  2470. };
  2471. /**
  2472. * Mixin the emitter properties.
  2473. *
  2474. * @param {Object} obj
  2475. * @return {Object}
  2476. * @api private
  2477. */
  2478. function mixin(obj) {
  2479. for (var key in Emitter.prototype) {
  2480. obj[key] = Emitter.prototype[key];
  2481. }
  2482. return obj;
  2483. }
  2484. /**
  2485. * Listen on the given `event` with `fn`.
  2486. *
  2487. * @param {String} event
  2488. * @param {Function} fn
  2489. * @return {Emitter}
  2490. * @api public
  2491. */
  2492. Emitter.prototype.on =
  2493. Emitter.prototype.addEventListener = function(event, fn){
  2494. this._callbacks = this._callbacks || {};
  2495. (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
  2496. .push(fn);
  2497. return this;
  2498. };
  2499. /**
  2500. * Adds an `event` listener that will be invoked a single
  2501. * time then automatically removed.
  2502. *
  2503. * @param {String} event
  2504. * @param {Function} fn
  2505. * @return {Emitter}
  2506. * @api public
  2507. */
  2508. Emitter.prototype.once = function(event, fn){
  2509. function on() {
  2510. this.off(event, on);
  2511. fn.apply(this, arguments);
  2512. }
  2513. on.fn = fn;
  2514. this.on(event, on);
  2515. return this;
  2516. };
  2517. /**
  2518. * Remove the given callback for `event` or all
  2519. * registered callbacks.
  2520. *
  2521. * @param {String} event
  2522. * @param {Function} fn
  2523. * @return {Emitter}
  2524. * @api public
  2525. */
  2526. Emitter.prototype.off =
  2527. Emitter.prototype.removeListener =
  2528. Emitter.prototype.removeAllListeners =
  2529. Emitter.prototype.removeEventListener = function(event, fn){
  2530. this._callbacks = this._callbacks || {};
  2531. // all
  2532. if (0 == arguments.length) {
  2533. this._callbacks = {};
  2534. return this;
  2535. }
  2536. // specific event
  2537. var callbacks = this._callbacks['$' + event];
  2538. if (!callbacks) return this;
  2539. // remove all handlers
  2540. if (1 == arguments.length) {
  2541. delete this._callbacks['$' + event];
  2542. return this;
  2543. }
  2544. // remove specific handler
  2545. var cb;
  2546. for (var i = 0; i < callbacks.length; i++) {
  2547. cb = callbacks[i];
  2548. if (cb === fn || cb.fn === fn) {
  2549. callbacks.splice(i, 1);
  2550. break;
  2551. }
  2552. }
  2553. // Remove event specific arrays for event types that no
  2554. // one is subscribed for to avoid memory leak.
  2555. if (callbacks.length === 0) {
  2556. delete this._callbacks['$' + event];
  2557. }
  2558. return this;
  2559. };
  2560. /**
  2561. * Emit `event` with the given args.
  2562. *
  2563. * @param {String} event
  2564. * @param {Mixed} ...
  2565. * @return {Emitter}
  2566. */
  2567. Emitter.prototype.emit = function(event){
  2568. this._callbacks = this._callbacks || {};
  2569. var args = new Array(arguments.length - 1)
  2570. , callbacks = this._callbacks['$' + event];
  2571. for (var i = 1; i < arguments.length; i++) {
  2572. args[i - 1] = arguments[i];
  2573. }
  2574. if (callbacks) {
  2575. callbacks = callbacks.slice(0);
  2576. for (var i = 0, len = callbacks.length; i < len; ++i) {
  2577. callbacks[i].apply(this, args);
  2578. }
  2579. }
  2580. return this;
  2581. };
  2582. /**
  2583. * Return array of callbacks for `event`.
  2584. *
  2585. * @param {String} event
  2586. * @return {Array}
  2587. * @api public
  2588. */
  2589. Emitter.prototype.listeners = function(event){
  2590. this._callbacks = this._callbacks || {};
  2591. return this._callbacks['$' + event] || [];
  2592. };
  2593. /**
  2594. * Check if this emitter has `event` handlers.
  2595. *
  2596. * @param {String} event
  2597. * @return {Boolean}
  2598. * @api public
  2599. */
  2600. Emitter.prototype.hasListeners = function(event){
  2601. return !! this.listeners(event).length;
  2602. };
  2603. /***/ },
  2604. /* 19 */
  2605. /***/ function(module, exports) {
  2606. /**
  2607. * Compiles a querystring
  2608. * Returns string representation of the object
  2609. *
  2610. * @param {Object}
  2611. * @api private
  2612. */
  2613. exports.encode = function (obj) {
  2614. var str = '';
  2615. for (var i in obj) {
  2616. if (obj.hasOwnProperty(i)) {
  2617. if (str.length) str += '&';
  2618. str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
  2619. }
  2620. }
  2621. return str;
  2622. };
  2623. /**
  2624. * Parses a simple querystring into an object
  2625. *
  2626. * @param {String} qs
  2627. * @api private
  2628. */
  2629. exports.decode = function(qs){
  2630. var qry = {};
  2631. var pairs = qs.split('&');
  2632. for (var i = 0, l = pairs.length; i < l; i++) {
  2633. var pair = pairs[i].split('=');
  2634. qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  2635. }
  2636. return qry;
  2637. };
  2638. /***/ },
  2639. /* 20 */
  2640. /***/ function(module, exports) {
  2641. module.exports = function(a, b){
  2642. var fn = function(){};
  2643. fn.prototype = b.prototype;
  2644. a.prototype = new fn;
  2645. a.prototype.constructor = a;
  2646. };
  2647. /***/ },
  2648. /* 21 */
  2649. /***/ function(module, exports) {
  2650. 'use strict';
  2651. var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
  2652. , length = 64
  2653. , map = {}
  2654. , seed = 0
  2655. , i = 0
  2656. , prev;
  2657. /**
  2658. * Return a string representing the specified number.
  2659. *
  2660. * @param {Number} num The number to convert.
  2661. * @returns {String} The string representation of the number.
  2662. * @api public
  2663. */
  2664. function encode(num) {
  2665. var encoded = '';
  2666. do {
  2667. encoded = alphabet[num % length] + encoded;
  2668. num = Math.floor(num / length);
  2669. } while (num > 0);
  2670. return encoded;
  2671. }
  2672. /**
  2673. * Return the integer value specified by the given string.
  2674. *
  2675. * @param {String} str The string to convert.
  2676. * @returns {Number} The integer value represented by the string.
  2677. * @api public
  2678. */
  2679. function decode(str) {
  2680. var decoded = 0;
  2681. for (i = 0; i < str.length; i++) {
  2682. decoded = decoded * length + map[str.charAt(i)];
  2683. }
  2684. return decoded;
  2685. }
  2686. /**
  2687. * Yeast: A tiny growing id generator.
  2688. *
  2689. * @returns {String} A unique id.
  2690. * @api public
  2691. */
  2692. function yeast() {
  2693. var now = encode(+new Date());
  2694. if (now !== prev) return seed = 0, prev = now;
  2695. return now +'.'+ encode(seed++);
  2696. }
  2697. //
  2698. // Map each character to its index.
  2699. //
  2700. for (; i < length; i++) map[alphabet[i]] = i;
  2701. //
  2702. // Expose the `yeast`, `encode` and `decode` functions.
  2703. //
  2704. yeast.encode = encode;
  2705. yeast.decode = decode;
  2706. module.exports = yeast;
  2707. /***/ },
  2708. /* 22 */
  2709. /***/ function(module, exports, __webpack_require__) {
  2710. /* WEBPACK VAR INJECTION */(function(process) {'use strict';
  2711. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  2712. /* eslint-env browser */
  2713. /**
  2714. * This is the web browser implementation of `debug()`.
  2715. */
  2716. exports.log = log;
  2717. exports.formatArgs = formatArgs;
  2718. exports.save = save;
  2719. exports.load = load;
  2720. exports.useColors = useColors;
  2721. exports.storage = localstorage();
  2722. /**
  2723. * Colors.
  2724. */
  2725. exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
  2726. /**
  2727. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  2728. * and the Firebug extension (any Firefox version) are known
  2729. * to support "%c" CSS customizations.
  2730. *
  2731. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  2732. */
  2733. // eslint-disable-next-line complexity
  2734. function useColors() {
  2735. // NB: In an Electron preload script, document will be defined but not fully
  2736. // initialized. Since we know we're in Chrome, we'll just detect this case
  2737. // explicitly
  2738. if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
  2739. return true;
  2740. }
  2741. // Internet Explorer and Edge do not support colors.
  2742. if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
  2743. return false;
  2744. }
  2745. // Is webkit? http://stackoverflow.com/a/16459606/376773
  2746. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  2747. return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
  2748. // Is firebug? http://stackoverflow.com/a/398120/376773
  2749. typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
  2750. // Is firefox >= v31?
  2751. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  2752. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 ||
  2753. // Double check webkit in userAgent just in case we are in a worker
  2754. typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
  2755. }
  2756. /**
  2757. * Colorize log arguments if enabled.
  2758. *
  2759. * @api public
  2760. */
  2761. function formatArgs(args) {
  2762. args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
  2763. if (!this.useColors) {
  2764. return;
  2765. }
  2766. var c = 'color: ' + this.color;
  2767. args.splice(1, 0, c, 'color: inherit');
  2768. // The final "%c" is somewhat tricky, because there could be other
  2769. // arguments passed either before or after the %c, so we need to
  2770. // figure out the correct index to insert the CSS into
  2771. var index = 0;
  2772. var lastC = 0;
  2773. args[0].replace(/%[a-zA-Z%]/g, function (match) {
  2774. if (match === '%%') {
  2775. return;
  2776. }
  2777. index++;
  2778. if (match === '%c') {
  2779. // We only are interested in the *last* %c
  2780. // (the user may have provided their own)
  2781. lastC = index;
  2782. }
  2783. });
  2784. args.splice(lastC, 0, c);
  2785. }
  2786. /**
  2787. * Invokes `console.log()` when available.
  2788. * No-op when `console.log` is not a "function".
  2789. *
  2790. * @api public
  2791. */
  2792. function log() {
  2793. var _console;
  2794. // This hackery is required for IE8/9, where
  2795. // the `console.log` function doesn't have 'apply'
  2796. return (typeof console === 'undefined' ? 'undefined' : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
  2797. }
  2798. /**
  2799. * Save `namespaces`.
  2800. *
  2801. * @param {String} namespaces
  2802. * @api private
  2803. */
  2804. function save(namespaces) {
  2805. try {
  2806. if (namespaces) {
  2807. exports.storage.setItem('debug', namespaces);
  2808. } else {
  2809. exports.storage.removeItem('debug');
  2810. }
  2811. } catch (error) {
  2812. // Swallow
  2813. // XXX (@Qix-) should we be logging these?
  2814. }
  2815. }
  2816. /**
  2817. * Load `namespaces`.
  2818. *
  2819. * @return {String} returns the previously persisted debug modes
  2820. * @api private
  2821. */
  2822. function load() {
  2823. var r = void 0;
  2824. try {
  2825. r = exports.storage.getItem('debug');
  2826. } catch (error) {}
  2827. // Swallow
  2828. // XXX (@Qix-) should we be logging these?
  2829. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  2830. if (!r && typeof process !== 'undefined' && 'env' in process) {
  2831. r = process.env.DEBUG;
  2832. }
  2833. return r;
  2834. }
  2835. /**
  2836. * Localstorage attempts to return the localstorage.
  2837. *
  2838. * This is necessary because safari throws
  2839. * when a user disables cookies/localstorage
  2840. * and you attempt to access it.
  2841. *
  2842. * @return {LocalStorage}
  2843. * @api private
  2844. */
  2845. function localstorage() {
  2846. try {
  2847. // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
  2848. // The Browser also has localStorage in the global context.
  2849. return localStorage;
  2850. } catch (error) {
  2851. // Swallow
  2852. // XXX (@Qix-) should we be logging these?
  2853. }
  2854. }
  2855. module.exports = __webpack_require__(24)(exports);
  2856. var formatters = module.exports.formatters;
  2857. /**
  2858. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  2859. */
  2860. formatters.j = function (v) {
  2861. try {
  2862. return JSON.stringify(v);
  2863. } catch (error) {
  2864. return '[UnexpectedJSONParseError]: ' + error.message;
  2865. }
  2866. };
  2867. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(23)))
  2868. /***/ },
  2869. /* 23 */
  2870. /***/ function(module, exports) {
  2871. // shim for using process in browser
  2872. var process = module.exports = {};
  2873. // cached from whatever global is present so that test runners that stub it
  2874. // don't break things. But we need to wrap it in a try catch in case it is
  2875. // wrapped in strict mode code which doesn't define any globals. It's inside a
  2876. // function because try/catches deoptimize in certain engines.
  2877. var cachedSetTimeout;
  2878. var cachedClearTimeout;
  2879. function defaultSetTimout() {
  2880. throw new Error('setTimeout has not been defined');
  2881. }
  2882. function defaultClearTimeout () {
  2883. throw new Error('clearTimeout has not been defined');
  2884. }
  2885. (function () {
  2886. try {
  2887. if (typeof setTimeout === 'function') {
  2888. cachedSetTimeout = setTimeout;
  2889. } else {
  2890. cachedSetTimeout = defaultSetTimout;
  2891. }
  2892. } catch (e) {
  2893. cachedSetTimeout = defaultSetTimout;
  2894. }
  2895. try {
  2896. if (typeof clearTimeout === 'function') {
  2897. cachedClearTimeout = clearTimeout;
  2898. } else {
  2899. cachedClearTimeout = defaultClearTimeout;
  2900. }
  2901. } catch (e) {
  2902. cachedClearTimeout = defaultClearTimeout;
  2903. }
  2904. } ())
  2905. function runTimeout(fun) {
  2906. if (cachedSetTimeout === setTimeout) {
  2907. //normal enviroments in sane situations
  2908. return setTimeout(fun, 0);
  2909. }
  2910. // if setTimeout wasn't available but was latter defined
  2911. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  2912. cachedSetTimeout = setTimeout;
  2913. return setTimeout(fun, 0);
  2914. }
  2915. try {
  2916. // when when somebody has screwed with setTimeout but no I.E. maddness
  2917. return cachedSetTimeout(fun, 0);
  2918. } catch(e){
  2919. try {
  2920. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2921. return cachedSetTimeout.call(null, fun, 0);
  2922. } catch(e){
  2923. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  2924. return cachedSetTimeout.call(this, fun, 0);
  2925. }
  2926. }
  2927. }
  2928. function runClearTimeout(marker) {
  2929. if (cachedClearTimeout === clearTimeout) {
  2930. //normal enviroments in sane situations
  2931. return clearTimeout(marker);
  2932. }
  2933. // if clearTimeout wasn't available but was latter defined
  2934. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  2935. cachedClearTimeout = clearTimeout;
  2936. return clearTimeout(marker);
  2937. }
  2938. try {
  2939. // when when somebody has screwed with setTimeout but no I.E. maddness
  2940. return cachedClearTimeout(marker);
  2941. } catch (e){
  2942. try {
  2943. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  2944. return cachedClearTimeout.call(null, marker);
  2945. } catch (e){
  2946. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  2947. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  2948. return cachedClearTimeout.call(this, marker);
  2949. }
  2950. }
  2951. }
  2952. var queue = [];
  2953. var draining = false;
  2954. var currentQueue;
  2955. var queueIndex = -1;
  2956. function cleanUpNextTick() {
  2957. if (!draining || !currentQueue) {
  2958. return;
  2959. }
  2960. draining = false;
  2961. if (currentQueue.length) {
  2962. queue = currentQueue.concat(queue);
  2963. } else {
  2964. queueIndex = -1;
  2965. }
  2966. if (queue.length) {
  2967. drainQueue();
  2968. }
  2969. }
  2970. function drainQueue() {
  2971. if (draining) {
  2972. return;
  2973. }
  2974. var timeout = runTimeout(cleanUpNextTick);
  2975. draining = true;
  2976. var len = queue.length;
  2977. while(len) {
  2978. currentQueue = queue;
  2979. queue = [];
  2980. while (++queueIndex < len) {
  2981. if (currentQueue) {
  2982. currentQueue[queueIndex].run();
  2983. }
  2984. }
  2985. queueIndex = -1;
  2986. len = queue.length;
  2987. }
  2988. currentQueue = null;
  2989. draining = false;
  2990. runClearTimeout(timeout);
  2991. }
  2992. process.nextTick = function (fun) {
  2993. var args = new Array(arguments.length - 1);
  2994. if (arguments.length > 1) {
  2995. for (var i = 1; i < arguments.length; i++) {
  2996. args[i - 1] = arguments[i];
  2997. }
  2998. }
  2999. queue.push(new Item(fun, args));
  3000. if (queue.length === 1 && !draining) {
  3001. runTimeout(drainQueue);
  3002. }
  3003. };
  3004. // v8 likes predictible objects
  3005. function Item(fun, array) {
  3006. this.fun = fun;
  3007. this.array = array;
  3008. }
  3009. Item.prototype.run = function () {
  3010. this.fun.apply(null, this.array);
  3011. };
  3012. process.title = 'browser';
  3013. process.browser = true;
  3014. process.env = {};
  3015. process.argv = [];
  3016. process.version = ''; // empty string to avoid regexp issues
  3017. process.versions = {};
  3018. function noop() {}
  3019. process.on = noop;
  3020. process.addListener = noop;
  3021. process.once = noop;
  3022. process.off = noop;
  3023. process.removeListener = noop;
  3024. process.removeAllListeners = noop;
  3025. process.emit = noop;
  3026. process.prependListener = noop;
  3027. process.prependOnceListener = noop;
  3028. process.listeners = function (name) { return [] }
  3029. process.binding = function (name) {
  3030. throw new Error('process.binding is not supported');
  3031. };
  3032. process.cwd = function () { return '/' };
  3033. process.chdir = function (dir) {
  3034. throw new Error('process.chdir is not supported');
  3035. };
  3036. process.umask = function() { return 0; };
  3037. /***/ },
  3038. /* 24 */
  3039. /***/ function(module, exports, __webpack_require__) {
  3040. 'use strict';
  3041. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  3042. /**
  3043. * This is the common logic for both the Node.js and web browser
  3044. * implementations of `debug()`.
  3045. */
  3046. function setup(env) {
  3047. createDebug.debug = createDebug;
  3048. createDebug.default = createDebug;
  3049. createDebug.coerce = coerce;
  3050. createDebug.disable = disable;
  3051. createDebug.enable = enable;
  3052. createDebug.enabled = enabled;
  3053. createDebug.humanize = __webpack_require__(25);
  3054. Object.keys(env).forEach(function (key) {
  3055. createDebug[key] = env[key];
  3056. });
  3057. /**
  3058. * Active `debug` instances.
  3059. */
  3060. createDebug.instances = [];
  3061. /**
  3062. * The currently active debug mode names, and names to skip.
  3063. */
  3064. createDebug.names = [];
  3065. createDebug.skips = [];
  3066. /**
  3067. * Map of special "%n" handling functions, for the debug "format" argument.
  3068. *
  3069. * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
  3070. */
  3071. createDebug.formatters = {};
  3072. /**
  3073. * Selects a color for a debug namespace
  3074. * @param {String} namespace The namespace string for the for the debug instance to be colored
  3075. * @return {Number|String} An ANSI color code for the given namespace
  3076. * @api private
  3077. */
  3078. function selectColor(namespace) {
  3079. var hash = 0;
  3080. for (var i = 0; i < namespace.length; i++) {
  3081. hash = (hash << 5) - hash + namespace.charCodeAt(i);
  3082. hash |= 0; // Convert to 32bit integer
  3083. }
  3084. return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
  3085. }
  3086. createDebug.selectColor = selectColor;
  3087. /**
  3088. * Create a debugger with the given `namespace`.
  3089. *
  3090. * @param {String} namespace
  3091. * @return {Function}
  3092. * @api public
  3093. */
  3094. function createDebug(namespace) {
  3095. var prevTime = void 0;
  3096. function debug() {
  3097. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  3098. args[_key] = arguments[_key];
  3099. }
  3100. // Disabled?
  3101. if (!debug.enabled) {
  3102. return;
  3103. }
  3104. var self = debug;
  3105. // Set `diff` timestamp
  3106. var curr = Number(new Date());
  3107. var ms = curr - (prevTime || curr);
  3108. self.diff = ms;
  3109. self.prev = prevTime;
  3110. self.curr = curr;
  3111. prevTime = curr;
  3112. args[0] = createDebug.coerce(args[0]);
  3113. if (typeof args[0] !== 'string') {
  3114. // Anything else let's inspect with %O
  3115. args.unshift('%O');
  3116. }
  3117. // Apply any `formatters` transformations
  3118. var index = 0;
  3119. args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
  3120. // If we encounter an escaped % then don't increase the array index
  3121. if (match === '%%') {
  3122. return match;
  3123. }
  3124. index++;
  3125. var formatter = createDebug.formatters[format];
  3126. if (typeof formatter === 'function') {
  3127. var val = args[index];
  3128. match = formatter.call(self, val);
  3129. // Now we need to remove `args[index]` since it's inlined in the `format`
  3130. args.splice(index, 1);
  3131. index--;
  3132. }
  3133. return match;
  3134. });
  3135. // Apply env-specific formatting (colors, etc.)
  3136. createDebug.formatArgs.call(self, args);
  3137. var logFn = self.log || createDebug.log;
  3138. logFn.apply(self, args);
  3139. }
  3140. debug.namespace = namespace;
  3141. debug.enabled = createDebug.enabled(namespace);
  3142. debug.useColors = createDebug.useColors();
  3143. debug.color = selectColor(namespace);
  3144. debug.destroy = destroy;
  3145. debug.extend = extend;
  3146. // Debug.formatArgs = formatArgs;
  3147. // debug.rawLog = rawLog;
  3148. // env-specific initialization logic for debug instances
  3149. if (typeof createDebug.init === 'function') {
  3150. createDebug.init(debug);
  3151. }
  3152. createDebug.instances.push(debug);
  3153. return debug;
  3154. }
  3155. function destroy() {
  3156. var index = createDebug.instances.indexOf(this);
  3157. if (index !== -1) {
  3158. createDebug.instances.splice(index, 1);
  3159. return true;
  3160. }
  3161. return false;
  3162. }
  3163. function extend(namespace, delimiter) {
  3164. var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
  3165. newDebug.log = this.log;
  3166. return newDebug;
  3167. }
  3168. /**
  3169. * Enables a debug mode by namespaces. This can include modes
  3170. * separated by a colon and wildcards.
  3171. *
  3172. * @param {String} namespaces
  3173. * @api public
  3174. */
  3175. function enable(namespaces) {
  3176. createDebug.save(namespaces);
  3177. createDebug.names = [];
  3178. createDebug.skips = [];
  3179. var i = void 0;
  3180. var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
  3181. var len = split.length;
  3182. for (i = 0; i < len; i++) {
  3183. if (!split[i]) {
  3184. // ignore empty strings
  3185. continue;
  3186. }
  3187. namespaces = split[i].replace(/\*/g, '.*?');
  3188. if (namespaces[0] === '-') {
  3189. createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  3190. } else {
  3191. createDebug.names.push(new RegExp('^' + namespaces + '$'));
  3192. }
  3193. }
  3194. for (i = 0; i < createDebug.instances.length; i++) {
  3195. var instance = createDebug.instances[i];
  3196. instance.enabled = createDebug.enabled(instance.namespace);
  3197. }
  3198. }
  3199. /**
  3200. * Disable debug output.
  3201. *
  3202. * @return {String} namespaces
  3203. * @api public
  3204. */
  3205. function disable() {
  3206. var namespaces = [].concat(_toConsumableArray(createDebug.names.map(toNamespace)), _toConsumableArray(createDebug.skips.map(toNamespace).map(function (namespace) {
  3207. return '-' + namespace;
  3208. }))).join(',');
  3209. createDebug.enable('');
  3210. return namespaces;
  3211. }
  3212. /**
  3213. * Returns true if the given mode name is enabled, false otherwise.
  3214. *
  3215. * @param {String} name
  3216. * @return {Boolean}
  3217. * @api public
  3218. */
  3219. function enabled(name) {
  3220. if (name[name.length - 1] === '*') {
  3221. return true;
  3222. }
  3223. var i = void 0;
  3224. var len = void 0;
  3225. for (i = 0, len = createDebug.skips.length; i < len; i++) {
  3226. if (createDebug.skips[i].test(name)) {
  3227. return false;
  3228. }
  3229. }
  3230. for (i = 0, len = createDebug.names.length; i < len; i++) {
  3231. if (createDebug.names[i].test(name)) {
  3232. return true;
  3233. }
  3234. }
  3235. return false;
  3236. }
  3237. /**
  3238. * Convert regexp to namespace
  3239. *
  3240. * @param {RegExp} regxep
  3241. * @return {String} namespace
  3242. * @api private
  3243. */
  3244. function toNamespace(regexp) {
  3245. return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, '*');
  3246. }
  3247. /**
  3248. * Coerce `val`.
  3249. *
  3250. * @param {Mixed} val
  3251. * @return {Mixed}
  3252. * @api private
  3253. */
  3254. function coerce(val) {
  3255. if (val instanceof Error) {
  3256. return val.stack || val.message;
  3257. }
  3258. return val;
  3259. }
  3260. createDebug.enable(createDebug.load());
  3261. return createDebug;
  3262. }
  3263. module.exports = setup;
  3264. /***/ },
  3265. /* 25 */
  3266. /***/ function(module, exports) {
  3267. /**
  3268. * Helpers.
  3269. */
  3270. var s = 1000;
  3271. var m = s * 60;
  3272. var h = m * 60;
  3273. var d = h * 24;
  3274. var w = d * 7;
  3275. var y = d * 365.25;
  3276. /**
  3277. * Parse or format the given `val`.
  3278. *
  3279. * Options:
  3280. *
  3281. * - `long` verbose formatting [false]
  3282. *
  3283. * @param {String|Number} val
  3284. * @param {Object} [options]
  3285. * @throws {Error} throw an error if val is not a non-empty string or a number
  3286. * @return {String|Number}
  3287. * @api public
  3288. */
  3289. module.exports = function(val, options) {
  3290. options = options || {};
  3291. var type = typeof val;
  3292. if (type === 'string' && val.length > 0) {
  3293. return parse(val);
  3294. } else if (type === 'number' && isFinite(val)) {
  3295. return options.long ? fmtLong(val) : fmtShort(val);
  3296. }
  3297. throw new Error(
  3298. 'val is not a non-empty string or a valid number. val=' +
  3299. JSON.stringify(val)
  3300. );
  3301. };
  3302. /**
  3303. * Parse the given `str` and return milliseconds.
  3304. *
  3305. * @param {String} str
  3306. * @return {Number}
  3307. * @api private
  3308. */
  3309. function parse(str) {
  3310. str = String(str);
  3311. if (str.length > 100) {
  3312. return;
  3313. }
  3314. var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
  3315. str
  3316. );
  3317. if (!match) {
  3318. return;
  3319. }
  3320. var n = parseFloat(match[1]);
  3321. var type = (match[2] || 'ms').toLowerCase();
  3322. switch (type) {
  3323. case 'years':
  3324. case 'year':
  3325. case 'yrs':
  3326. case 'yr':
  3327. case 'y':
  3328. return n * y;
  3329. case 'weeks':
  3330. case 'week':
  3331. case 'w':
  3332. return n * w;
  3333. case 'days':
  3334. case 'day':
  3335. case 'd':
  3336. return n * d;
  3337. case 'hours':
  3338. case 'hour':
  3339. case 'hrs':
  3340. case 'hr':
  3341. case 'h':
  3342. return n * h;
  3343. case 'minutes':
  3344. case 'minute':
  3345. case 'mins':
  3346. case 'min':
  3347. case 'm':
  3348. return n * m;
  3349. case 'seconds':
  3350. case 'second':
  3351. case 'secs':
  3352. case 'sec':
  3353. case 's':
  3354. return n * s;
  3355. case 'milliseconds':
  3356. case 'millisecond':
  3357. case 'msecs':
  3358. case 'msec':
  3359. case 'ms':
  3360. return n;
  3361. default:
  3362. return undefined;
  3363. }
  3364. }
  3365. /**
  3366. * Short format for `ms`.
  3367. *
  3368. * @param {Number} ms
  3369. * @return {String}
  3370. * @api private
  3371. */
  3372. function fmtShort(ms) {
  3373. var msAbs = Math.abs(ms);
  3374. if (msAbs >= d) {
  3375. return Math.round(ms / d) + 'd';
  3376. }
  3377. if (msAbs >= h) {
  3378. return Math.round(ms / h) + 'h';
  3379. }
  3380. if (msAbs >= m) {
  3381. return Math.round(ms / m) + 'm';
  3382. }
  3383. if (msAbs >= s) {
  3384. return Math.round(ms / s) + 's';
  3385. }
  3386. return ms + 'ms';
  3387. }
  3388. /**
  3389. * Long format for `ms`.
  3390. *
  3391. * @param {Number} ms
  3392. * @return {String}
  3393. * @api private
  3394. */
  3395. function fmtLong(ms) {
  3396. var msAbs = Math.abs(ms);
  3397. if (msAbs >= d) {
  3398. return plural(ms, msAbs, d, 'day');
  3399. }
  3400. if (msAbs >= h) {
  3401. return plural(ms, msAbs, h, 'hour');
  3402. }
  3403. if (msAbs >= m) {
  3404. return plural(ms, msAbs, m, 'minute');
  3405. }
  3406. if (msAbs >= s) {
  3407. return plural(ms, msAbs, s, 'second');
  3408. }
  3409. return ms + ' ms';
  3410. }
  3411. /**
  3412. * Pluralization helper.
  3413. */
  3414. function plural(ms, msAbs, n, name) {
  3415. var isPlural = msAbs >= n * 1.5;
  3416. return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
  3417. }
  3418. /***/ },
  3419. /* 26 */
  3420. /***/ function(module, exports, __webpack_require__) {
  3421. /**
  3422. * Module requirements.
  3423. */
  3424. var Polling = __webpack_require__(7);
  3425. var inherit = __webpack_require__(20);
  3426. var globalThis = __webpack_require__(5);
  3427. /**
  3428. * Module exports.
  3429. */
  3430. module.exports = JSONPPolling;
  3431. /**
  3432. * Cached regular expressions.
  3433. */
  3434. var rNewline = /\n/g;
  3435. var rEscapedNewline = /\\n/g;
  3436. /**
  3437. * Global JSONP callbacks.
  3438. */
  3439. var callbacks;
  3440. /**
  3441. * Noop.
  3442. */
  3443. function empty () { }
  3444. /**
  3445. * JSONP Polling constructor.
  3446. *
  3447. * @param {Object} opts.
  3448. * @api public
  3449. */
  3450. function JSONPPolling (opts) {
  3451. Polling.call(this, opts);
  3452. this.query = this.query || {};
  3453. // define global callbacks array if not present
  3454. // we do this here (lazily) to avoid unneeded global pollution
  3455. if (!callbacks) {
  3456. // we need to consider multiple engines in the same page
  3457. callbacks = globalThis.___eio = (globalThis.___eio || []);
  3458. }
  3459. // callback identifier
  3460. this.index = callbacks.length;
  3461. // add callback to jsonp global
  3462. var self = this;
  3463. callbacks.push(function (msg) {
  3464. self.onData(msg);
  3465. });
  3466. // append to query string
  3467. this.query.j = this.index;
  3468. // prevent spurious errors from being emitted when the window is unloaded
  3469. if (typeof addEventListener === 'function') {
  3470. addEventListener('beforeunload', function () {
  3471. if (self.script) self.script.onerror = empty;
  3472. }, false);
  3473. }
  3474. }
  3475. /**
  3476. * Inherits from Polling.
  3477. */
  3478. inherit(JSONPPolling, Polling);
  3479. /*
  3480. * JSONP only supports binary as base64 encoded strings
  3481. */
  3482. JSONPPolling.prototype.supportsBinary = false;
  3483. /**
  3484. * Closes the socket.
  3485. *
  3486. * @api private
  3487. */
  3488. JSONPPolling.prototype.doClose = function () {
  3489. if (this.script) {
  3490. this.script.parentNode.removeChild(this.script);
  3491. this.script = null;
  3492. }
  3493. if (this.form) {
  3494. this.form.parentNode.removeChild(this.form);
  3495. this.form = null;
  3496. this.iframe = null;
  3497. }
  3498. Polling.prototype.doClose.call(this);
  3499. };
  3500. /**
  3501. * Starts a poll cycle.
  3502. *
  3503. * @api private
  3504. */
  3505. JSONPPolling.prototype.doPoll = function () {
  3506. var self = this;
  3507. var script = document.createElement('script');
  3508. if (this.script) {
  3509. this.script.parentNode.removeChild(this.script);
  3510. this.script = null;
  3511. }
  3512. script.async = true;
  3513. script.src = this.uri();
  3514. script.onerror = function (e) {
  3515. self.onError('jsonp poll error', e);
  3516. };
  3517. var insertAt = document.getElementsByTagName('script')[0];
  3518. if (insertAt) {
  3519. insertAt.parentNode.insertBefore(script, insertAt);
  3520. } else {
  3521. (document.head || document.body).appendChild(script);
  3522. }
  3523. this.script = script;
  3524. var isUAgecko = 'undefined' !== typeof navigator && /gecko/i.test(navigator.userAgent);
  3525. if (isUAgecko) {
  3526. setTimeout(function () {
  3527. var iframe = document.createElement('iframe');
  3528. document.body.appendChild(iframe);
  3529. document.body.removeChild(iframe);
  3530. }, 100);
  3531. }
  3532. };
  3533. /**
  3534. * Writes with a hidden iframe.
  3535. *
  3536. * @param {String} data to send
  3537. * @param {Function} called upon flush.
  3538. * @api private
  3539. */
  3540. JSONPPolling.prototype.doWrite = function (data, fn) {
  3541. var self = this;
  3542. if (!this.form) {
  3543. var form = document.createElement('form');
  3544. var area = document.createElement('textarea');
  3545. var id = this.iframeId = 'eio_iframe_' + this.index;
  3546. var iframe;
  3547. form.className = 'socketio';
  3548. form.style.position = 'absolute';
  3549. form.style.top = '-1000px';
  3550. form.style.left = '-1000px';
  3551. form.target = id;
  3552. form.method = 'POST';
  3553. form.setAttribute('accept-charset', 'utf-8');
  3554. area.name = 'd';
  3555. form.appendChild(area);
  3556. document.body.appendChild(form);
  3557. this.form = form;
  3558. this.area = area;
  3559. }
  3560. this.form.action = this.uri();
  3561. function complete () {
  3562. initIframe();
  3563. fn();
  3564. }
  3565. function initIframe () {
  3566. if (self.iframe) {
  3567. try {
  3568. self.form.removeChild(self.iframe);
  3569. } catch (e) {
  3570. self.onError('jsonp polling iframe removal error', e);
  3571. }
  3572. }
  3573. try {
  3574. // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  3575. var html = '<iframe src="javascript:0" name="' + self.iframeId + '">';
  3576. iframe = document.createElement(html);
  3577. } catch (e) {
  3578. iframe = document.createElement('iframe');
  3579. iframe.name = self.iframeId;
  3580. iframe.src = 'javascript:0';
  3581. }
  3582. iframe.id = self.iframeId;
  3583. self.form.appendChild(iframe);
  3584. self.iframe = iframe;
  3585. }
  3586. initIframe();
  3587. // escape \n to prevent it from being converted into \r\n by some UAs
  3588. // double escaping is required for escaped new lines because unescaping of new lines can be done safely on server-side
  3589. data = data.replace(rEscapedNewline, '\\\n');
  3590. this.area.value = data.replace(rNewline, '\\n');
  3591. try {
  3592. this.form.submit();
  3593. } catch (e) {}
  3594. if (this.iframe.attachEvent) {
  3595. this.iframe.onreadystatechange = function () {
  3596. if (self.iframe.readyState === 'complete') {
  3597. complete();
  3598. }
  3599. };
  3600. } else {
  3601. this.iframe.onload = complete;
  3602. }
  3603. };
  3604. /***/ },
  3605. /* 27 */
  3606. /***/ function(module, exports, __webpack_require__) {
  3607. /**
  3608. * Module dependencies.
  3609. */
  3610. var Transport = __webpack_require__(8);
  3611. var parser = __webpack_require__(9);
  3612. var parseqs = __webpack_require__(19);
  3613. var inherit = __webpack_require__(20);
  3614. var yeast = __webpack_require__(21);
  3615. var debug = __webpack_require__(22)('engine.io-client:websocket');
  3616. var BrowserWebSocket, NodeWebSocket;
  3617. if (typeof WebSocket !== 'undefined') {
  3618. BrowserWebSocket = WebSocket;
  3619. } else if (typeof self !== 'undefined') {
  3620. BrowserWebSocket = self.WebSocket || self.MozWebSocket;
  3621. }
  3622. if (typeof window === 'undefined') {
  3623. try {
  3624. NodeWebSocket = __webpack_require__(28);
  3625. } catch (e) { }
  3626. }
  3627. /**
  3628. * Get either the `WebSocket` or `MozWebSocket` globals
  3629. * in the browser or try to resolve WebSocket-compatible
  3630. * interface exposed by `ws` for Node-like environment.
  3631. */
  3632. var WebSocketImpl = BrowserWebSocket || NodeWebSocket;
  3633. /**
  3634. * Module exports.
  3635. */
  3636. module.exports = WS;
  3637. /**
  3638. * WebSocket transport constructor.
  3639. *
  3640. * @api {Object} connection options
  3641. * @api public
  3642. */
  3643. function WS (opts) {
  3644. var forceBase64 = (opts && opts.forceBase64);
  3645. if (forceBase64) {
  3646. this.supportsBinary = false;
  3647. }
  3648. this.perMessageDeflate = opts.perMessageDeflate;
  3649. this.usingBrowserWebSocket = BrowserWebSocket && !opts.forceNode;
  3650. this.protocols = opts.protocols;
  3651. if (!this.usingBrowserWebSocket) {
  3652. WebSocketImpl = NodeWebSocket;
  3653. }
  3654. Transport.call(this, opts);
  3655. }
  3656. /**
  3657. * Inherits from Transport.
  3658. */
  3659. inherit(WS, Transport);
  3660. /**
  3661. * Transport name.
  3662. *
  3663. * @api public
  3664. */
  3665. WS.prototype.name = 'websocket';
  3666. /*
  3667. * WebSockets support binary
  3668. */
  3669. WS.prototype.supportsBinary = true;
  3670. /**
  3671. * Opens socket.
  3672. *
  3673. * @api private
  3674. */
  3675. WS.prototype.doOpen = function () {
  3676. if (!this.check()) {
  3677. // let probe timeout
  3678. return;
  3679. }
  3680. var uri = this.uri();
  3681. var protocols = this.protocols;
  3682. var opts = {};
  3683. if (!this.isReactNative) {
  3684. opts.agent = this.agent;
  3685. opts.perMessageDeflate = this.perMessageDeflate;
  3686. // SSL options for Node.js client
  3687. opts.pfx = this.pfx;
  3688. opts.key = this.key;
  3689. opts.passphrase = this.passphrase;
  3690. opts.cert = this.cert;
  3691. opts.ca = this.ca;
  3692. opts.ciphers = this.ciphers;
  3693. opts.rejectUnauthorized = this.rejectUnauthorized;
  3694. }
  3695. if (this.extraHeaders) {
  3696. opts.headers = this.extraHeaders;
  3697. }
  3698. if (this.localAddress) {
  3699. opts.localAddress = this.localAddress;
  3700. }
  3701. try {
  3702. this.ws =
  3703. this.usingBrowserWebSocket && !this.isReactNative
  3704. ? protocols
  3705. ? new WebSocketImpl(uri, protocols)
  3706. : new WebSocketImpl(uri)
  3707. : new WebSocketImpl(uri, protocols, opts);
  3708. } catch (err) {
  3709. return this.emit('error', err);
  3710. }
  3711. if (this.ws.binaryType === undefined) {
  3712. this.supportsBinary = false;
  3713. }
  3714. if (this.ws.supports && this.ws.supports.binary) {
  3715. this.supportsBinary = true;
  3716. this.ws.binaryType = 'nodebuffer';
  3717. } else {
  3718. this.ws.binaryType = 'arraybuffer';
  3719. }
  3720. this.addEventListeners();
  3721. };
  3722. /**
  3723. * Adds event listeners to the socket
  3724. *
  3725. * @api private
  3726. */
  3727. WS.prototype.addEventListeners = function () {
  3728. var self = this;
  3729. this.ws.onopen = function () {
  3730. self.onOpen();
  3731. };
  3732. this.ws.onclose = function () {
  3733. self.onClose();
  3734. };
  3735. this.ws.onmessage = function (ev) {
  3736. self.onData(ev.data);
  3737. };
  3738. this.ws.onerror = function (e) {
  3739. self.onError('websocket error', e);
  3740. };
  3741. };
  3742. /**
  3743. * Writes data to socket.
  3744. *
  3745. * @param {Array} array of packets.
  3746. * @api private
  3747. */
  3748. WS.prototype.write = function (packets) {
  3749. var self = this;
  3750. this.writable = false;
  3751. // encodePacket efficient as it uses WS framing
  3752. // no need for encodePayload
  3753. var total = packets.length;
  3754. for (var i = 0, l = total; i < l; i++) {
  3755. (function (packet) {
  3756. parser.encodePacket(packet, self.supportsBinary, function (data) {
  3757. if (!self.usingBrowserWebSocket) {
  3758. // always create a new object (GH-437)
  3759. var opts = {};
  3760. if (packet.options) {
  3761. opts.compress = packet.options.compress;
  3762. }
  3763. if (self.perMessageDeflate) {
  3764. var len = 'string' === typeof data ? Buffer.byteLength(data) : data.length;
  3765. if (len < self.perMessageDeflate.threshold) {
  3766. opts.compress = false;
  3767. }
  3768. }
  3769. }
  3770. // Sometimes the websocket has already been closed but the browser didn't
  3771. // have a chance of informing us about it yet, in that case send will
  3772. // throw an error
  3773. try {
  3774. if (self.usingBrowserWebSocket) {
  3775. // TypeError is thrown when passing the second argument on Safari
  3776. self.ws.send(data);
  3777. } else {
  3778. self.ws.send(data, opts);
  3779. }
  3780. } catch (e) {
  3781. debug('websocket closed before onclose event');
  3782. }
  3783. --total || done();
  3784. });
  3785. })(packets[i]);
  3786. }
  3787. function done () {
  3788. self.emit('flush');
  3789. // fake drain
  3790. // defer to next tick to allow Socket to clear writeBuffer
  3791. setTimeout(function () {
  3792. self.writable = true;
  3793. self.emit('drain');
  3794. }, 0);
  3795. }
  3796. };
  3797. /**
  3798. * Called upon close
  3799. *
  3800. * @api private
  3801. */
  3802. WS.prototype.onClose = function () {
  3803. Transport.prototype.onClose.call(this);
  3804. };
  3805. /**
  3806. * Closes socket.
  3807. *
  3808. * @api private
  3809. */
  3810. WS.prototype.doClose = function () {
  3811. if (typeof this.ws !== 'undefined') {
  3812. this.ws.close();
  3813. }
  3814. };
  3815. /**
  3816. * Generates uri for connection.
  3817. *
  3818. * @api private
  3819. */
  3820. WS.prototype.uri = function () {
  3821. var query = this.query || {};
  3822. var schema = this.secure ? 'wss' : 'ws';
  3823. var port = '';
  3824. // avoid port if default for schema
  3825. if (this.port && (('wss' === schema && Number(this.port) !== 443) ||
  3826. ('ws' === schema && Number(this.port) !== 80))) {
  3827. port = ':' + this.port;
  3828. }
  3829. // append timestamp to URI
  3830. if (this.timestampRequests) {
  3831. query[this.timestampParam] = yeast();
  3832. }
  3833. // communicate binary support capabilities
  3834. if (!this.supportsBinary) {
  3835. query.b64 = 1;
  3836. }
  3837. query = parseqs.encode(query);
  3838. // prepend ? to query
  3839. if (query.length) {
  3840. query = '?' + query;
  3841. }
  3842. var ipv6 = this.hostname.indexOf(':') !== -1;
  3843. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  3844. };
  3845. /**
  3846. * Feature detection for WebSocket.
  3847. *
  3848. * @return {Boolean} whether this transport is available.
  3849. * @api public
  3850. */
  3851. WS.prototype.check = function () {
  3852. return !!WebSocketImpl && !('__initialize' in WebSocketImpl && this.name === WS.prototype.name);
  3853. };
  3854. /***/ },
  3855. /* 28 */
  3856. /***/ function(module, exports) {
  3857. /* (ignored) */
  3858. /***/ },
  3859. /* 29 */
  3860. /***/ function(module, exports) {
  3861. var indexOf = [].indexOf;
  3862. module.exports = function(arr, obj){
  3863. if (indexOf) return arr.indexOf(obj);
  3864. for (var i = 0; i < arr.length; ++i) {
  3865. if (arr[i] === obj) return i;
  3866. }
  3867. return -1;
  3868. };
  3869. /***/ },
  3870. /* 30 */
  3871. /***/ function(module, exports) {
  3872. /**
  3873. * Parses an URI
  3874. *
  3875. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  3876. * @api private
  3877. */
  3878. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  3879. var parts = [
  3880. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  3881. ];
  3882. module.exports = function parseuri(str) {
  3883. var src = str,
  3884. b = str.indexOf('['),
  3885. e = str.indexOf(']');
  3886. if (b != -1 && e != -1) {
  3887. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  3888. }
  3889. var m = re.exec(str || ''),
  3890. uri = {},
  3891. i = 14;
  3892. while (i--) {
  3893. uri[parts[i]] = m[i] || '';
  3894. }
  3895. if (b != -1 && e != -1) {
  3896. uri.source = src;
  3897. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  3898. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  3899. uri.ipv6uri = true;
  3900. }
  3901. return uri;
  3902. };
  3903. /***/ }
  3904. /******/ ])
  3905. });
  3906. ;