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.

8200 lines
205 KiB

7 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["io"] = factory();
  8. else
  9. root["io"] = 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. 'use strict';
  46. 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; };
  47. /**
  48. * Module dependencies.
  49. */
  50. var url = __webpack_require__(1);
  51. var parser = __webpack_require__(7);
  52. var Manager = __webpack_require__(17);
  53. var debug = __webpack_require__(3)('socket.io-client');
  54. /**
  55. * Module exports.
  56. */
  57. module.exports = exports = lookup;
  58. /**
  59. * Managers cache.
  60. */
  61. var cache = exports.managers = {};
  62. /**
  63. * Looks up an existing `Manager` for multiplexing.
  64. * If the user summons:
  65. *
  66. * `io('http://localhost/a');`
  67. * `io('http://localhost/b');`
  68. *
  69. * We reuse the existing instance based on same scheme/port/host,
  70. * and we initialize sockets for each namespace.
  71. *
  72. * @api public
  73. */
  74. function lookup(uri, opts) {
  75. if ((typeof uri === 'undefined' ? 'undefined' : _typeof(uri)) === 'object') {
  76. opts = uri;
  77. uri = undefined;
  78. }
  79. opts = opts || {};
  80. var parsed = url(uri);
  81. var source = parsed.source;
  82. var id = parsed.id;
  83. var path = parsed.path;
  84. var sameNamespace = cache[id] && path in cache[id].nsps;
  85. var newConnection = opts.forceNew || opts['force new connection'] || false === opts.multiplex || sameNamespace;
  86. var io;
  87. if (newConnection) {
  88. debug('ignoring socket cache for %s', source);
  89. io = Manager(source, opts);
  90. } else {
  91. if (!cache[id]) {
  92. debug('new io instance for %s', source);
  93. cache[id] = Manager(source, opts);
  94. }
  95. io = cache[id];
  96. }
  97. if (parsed.query && !opts.query) {
  98. opts.query = parsed.query;
  99. } else if (opts && 'object' === _typeof(opts.query)) {
  100. opts.query = encodeQueryString(opts.query);
  101. }
  102. return io.socket(parsed.path, opts);
  103. }
  104. /**
  105. * Helper method to parse query objects to string.
  106. * @param {object} query
  107. * @returns {string}
  108. */
  109. function encodeQueryString(obj) {
  110. var str = [];
  111. for (var p in obj) {
  112. if (obj.hasOwnProperty(p)) {
  113. str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
  114. }
  115. }
  116. return str.join('&');
  117. }
  118. /**
  119. * Protocol version.
  120. *
  121. * @api public
  122. */
  123. exports.protocol = parser.protocol;
  124. /**
  125. * `connect`.
  126. *
  127. * @param {String} uri
  128. * @api public
  129. */
  130. exports.connect = lookup;
  131. /**
  132. * Expose constructors for standalone build.
  133. *
  134. * @api public
  135. */
  136. exports.Manager = __webpack_require__(17);
  137. exports.Socket = __webpack_require__(44);
  138. /***/ },
  139. /* 1 */
  140. /***/ function(module, exports, __webpack_require__) {
  141. /* WEBPACK VAR INJECTION */(function(global) {'use strict';
  142. /**
  143. * Module dependencies.
  144. */
  145. var parseuri = __webpack_require__(2);
  146. var debug = __webpack_require__(3)('socket.io-client:url');
  147. /**
  148. * Module exports.
  149. */
  150. module.exports = url;
  151. /**
  152. * URL parser.
  153. *
  154. * @param {String} url
  155. * @param {Object} An object meant to mimic window.location.
  156. * Defaults to window.location.
  157. * @api public
  158. */
  159. function url(uri, loc) {
  160. var obj = uri;
  161. // default to window.location
  162. loc = loc || global.location;
  163. if (null == uri) uri = loc.protocol + '//' + loc.host;
  164. // relative path support
  165. if ('string' === typeof uri) {
  166. if ('/' === uri.charAt(0)) {
  167. if ('/' === uri.charAt(1)) {
  168. uri = loc.protocol + uri;
  169. } else {
  170. uri = loc.host + uri;
  171. }
  172. }
  173. if (!/^(https?|wss?):\/\//.test(uri)) {
  174. debug('protocol-less url %s', uri);
  175. if ('undefined' !== typeof loc) {
  176. uri = loc.protocol + '//' + uri;
  177. } else {
  178. uri = 'https://' + uri;
  179. }
  180. }
  181. // parse
  182. debug('parse %s', uri);
  183. obj = parseuri(uri);
  184. }
  185. // make sure we treat `localhost:80` and `localhost` equally
  186. if (!obj.port) {
  187. if (/^(http|ws)$/.test(obj.protocol)) {
  188. obj.port = '80';
  189. } else if (/^(http|ws)s$/.test(obj.protocol)) {
  190. obj.port = '443';
  191. }
  192. }
  193. obj.path = obj.path || '/';
  194. var ipv6 = obj.host.indexOf(':') !== -1;
  195. var host = ipv6 ? '[' + obj.host + ']' : obj.host;
  196. // define unique id
  197. obj.id = obj.protocol + '://' + host + ':' + obj.port;
  198. // define href
  199. obj.href = obj.protocol + '://' + host + (loc && loc.port === obj.port ? '' : ':' + obj.port);
  200. return obj;
  201. }
  202. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  203. /***/ },
  204. /* 2 */
  205. /***/ function(module, exports) {
  206. /**
  207. * Parses an URI
  208. *
  209. * @author Steven Levithan <stevenlevithan.com> (MIT license)
  210. * @api private
  211. */
  212. var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
  213. var parts = [
  214. 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
  215. ];
  216. module.exports = function parseuri(str) {
  217. var src = str,
  218. b = str.indexOf('['),
  219. e = str.indexOf(']');
  220. if (b != -1 && e != -1) {
  221. str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
  222. }
  223. var m = re.exec(str || ''),
  224. uri = {},
  225. i = 14;
  226. while (i--) {
  227. uri[parts[i]] = m[i] || '';
  228. }
  229. if (b != -1 && e != -1) {
  230. uri.source = src;
  231. uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
  232. uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
  233. uri.ipv6uri = true;
  234. }
  235. return uri;
  236. };
  237. /***/ },
  238. /* 3 */
  239. /***/ function(module, exports, __webpack_require__) {
  240. /* WEBPACK VAR INJECTION */(function(process) {
  241. /**
  242. * This is the web browser implementation of `debug()`.
  243. *
  244. * Expose `debug()` as the module.
  245. */
  246. exports = module.exports = __webpack_require__(5);
  247. exports.log = log;
  248. exports.formatArgs = formatArgs;
  249. exports.save = save;
  250. exports.load = load;
  251. exports.useColors = useColors;
  252. exports.storage = 'undefined' != typeof chrome
  253. && 'undefined' != typeof chrome.storage
  254. ? chrome.storage.local
  255. : localstorage();
  256. /**
  257. * Colors.
  258. */
  259. exports.colors = [
  260. 'lightseagreen',
  261. 'forestgreen',
  262. 'goldenrod',
  263. 'dodgerblue',
  264. 'darkorchid',
  265. 'crimson'
  266. ];
  267. /**
  268. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  269. * and the Firebug extension (any Firefox version) are known
  270. * to support "%c" CSS customizations.
  271. *
  272. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  273. */
  274. function useColors() {
  275. // is webkit? http://stackoverflow.com/a/16459606/376773
  276. // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
  277. return (typeof document !== 'undefined' && 'WebkitAppearance' in document.documentElement.style) ||
  278. // is firebug? http://stackoverflow.com/a/398120/376773
  279. (window.console && (console.firebug || (console.exception && console.table))) ||
  280. // is firefox >= v31?
  281. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  282. (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
  283. }
  284. /**
  285. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  286. */
  287. exports.formatters.j = function(v) {
  288. try {
  289. return JSON.stringify(v);
  290. } catch (err) {
  291. return '[UnexpectedJSONParseError]: ' + err.message;
  292. }
  293. };
  294. /**
  295. * Colorize log arguments if enabled.
  296. *
  297. * @api public
  298. */
  299. function formatArgs() {
  300. var args = arguments;
  301. var useColors = this.useColors;
  302. args[0] = (useColors ? '%c' : '')
  303. + this.namespace
  304. + (useColors ? ' %c' : ' ')
  305. + args[0]
  306. + (useColors ? '%c ' : ' ')
  307. + '+' + exports.humanize(this.diff);
  308. if (!useColors) return args;
  309. var c = 'color: ' + this.color;
  310. args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
  311. // the final "%c" is somewhat tricky, because there could be other
  312. // arguments passed either before or after the %c, so we need to
  313. // figure out the correct index to insert the CSS into
  314. var index = 0;
  315. var lastC = 0;
  316. args[0].replace(/%[a-z%]/g, function(match) {
  317. if ('%%' === match) return;
  318. index++;
  319. if ('%c' === match) {
  320. // we only are interested in the *last* %c
  321. // (the user may have provided their own)
  322. lastC = index;
  323. }
  324. });
  325. args.splice(lastC, 0, c);
  326. return args;
  327. }
  328. /**
  329. * Invokes `console.log()` when available.
  330. * No-op when `console.log` is not a "function".
  331. *
  332. * @api public
  333. */
  334. function log() {
  335. // this hackery is required for IE8/9, where
  336. // the `console.log` function doesn't have 'apply'
  337. return 'object' === typeof console
  338. && console.log
  339. && Function.prototype.apply.call(console.log, console, arguments);
  340. }
  341. /**
  342. * Save `namespaces`.
  343. *
  344. * @param {String} namespaces
  345. * @api private
  346. */
  347. function save(namespaces) {
  348. try {
  349. if (null == namespaces) {
  350. exports.storage.removeItem('debug');
  351. } else {
  352. exports.storage.debug = namespaces;
  353. }
  354. } catch(e) {}
  355. }
  356. /**
  357. * Load `namespaces`.
  358. *
  359. * @return {String} returns the previously persisted debug modes
  360. * @api private
  361. */
  362. function load() {
  363. var r;
  364. try {
  365. return exports.storage.debug;
  366. } catch(e) {}
  367. // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  368. if (typeof process !== 'undefined' && 'env' in process) {
  369. return process.env.DEBUG;
  370. }
  371. }
  372. /**
  373. * Enable namespaces listed in `localStorage.debug` initially.
  374. */
  375. exports.enable(load());
  376. /**
  377. * Localstorage attempts to return the localstorage.
  378. *
  379. * This is necessary because safari throws
  380. * when a user disables cookies/localstorage
  381. * and you attempt to access it.
  382. *
  383. * @return {LocalStorage}
  384. * @api private
  385. */
  386. function localstorage(){
  387. try {
  388. return window.localStorage;
  389. } catch (e) {}
  390. }
  391. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(4)))
  392. /***/ },
  393. /* 4 */
  394. /***/ function(module, exports) {
  395. // shim for using process in browser
  396. var process = module.exports = {};
  397. // cached from whatever global is present so that test runners that stub it
  398. // don't break things. But we need to wrap it in a try catch in case it is
  399. // wrapped in strict mode code which doesn't define any globals. It's inside a
  400. // function because try/catches deoptimize in certain engines.
  401. var cachedSetTimeout;
  402. var cachedClearTimeout;
  403. function defaultSetTimout() {
  404. throw new Error('setTimeout has not been defined');
  405. }
  406. function defaultClearTimeout () {
  407. throw new Error('clearTimeout has not been defined');
  408. }
  409. (function () {
  410. try {
  411. if (typeof setTimeout === 'function') {
  412. cachedSetTimeout = setTimeout;
  413. } else {
  414. cachedSetTimeout = defaultSetTimout;
  415. }
  416. } catch (e) {
  417. cachedSetTimeout = defaultSetTimout;
  418. }
  419. try {
  420. if (typeof clearTimeout === 'function') {
  421. cachedClearTimeout = clearTimeout;
  422. } else {
  423. cachedClearTimeout = defaultClearTimeout;
  424. }
  425. } catch (e) {
  426. cachedClearTimeout = defaultClearTimeout;
  427. }
  428. } ())
  429. function runTimeout(fun) {
  430. if (cachedSetTimeout === setTimeout) {
  431. //normal enviroments in sane situations
  432. return setTimeout(fun, 0);
  433. }
  434. // if setTimeout wasn't available but was latter defined
  435. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  436. cachedSetTimeout = setTimeout;
  437. return setTimeout(fun, 0);
  438. }
  439. try {
  440. // when when somebody has screwed with setTimeout but no I.E. maddness
  441. return cachedSetTimeout(fun, 0);
  442. } catch(e){
  443. try {
  444. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  445. return cachedSetTimeout.call(null, fun, 0);
  446. } catch(e){
  447. // 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
  448. return cachedSetTimeout.call(this, fun, 0);
  449. }
  450. }
  451. }
  452. function runClearTimeout(marker) {
  453. if (cachedClearTimeout === clearTimeout) {
  454. //normal enviroments in sane situations
  455. return clearTimeout(marker);
  456. }
  457. // if clearTimeout wasn't available but was latter defined
  458. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  459. cachedClearTimeout = clearTimeout;
  460. return clearTimeout(marker);
  461. }
  462. try {
  463. // when when somebody has screwed with setTimeout but no I.E. maddness
  464. return cachedClearTimeout(marker);
  465. } catch (e){
  466. try {
  467. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  468. return cachedClearTimeout.call(null, marker);
  469. } catch (e){
  470. // 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.
  471. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  472. return cachedClearTimeout.call(this, marker);
  473. }
  474. }
  475. }
  476. var queue = [];
  477. var draining = false;
  478. var currentQueue;
  479. var queueIndex = -1;
  480. function cleanUpNextTick() {
  481. if (!draining || !currentQueue) {
  482. return;
  483. }
  484. draining = false;
  485. if (currentQueue.length) {
  486. queue = currentQueue.concat(queue);
  487. } else {
  488. queueIndex = -1;
  489. }
  490. if (queue.length) {
  491. drainQueue();
  492. }
  493. }
  494. function drainQueue() {
  495. if (draining) {
  496. return;
  497. }
  498. var timeout = runTimeout(cleanUpNextTick);
  499. draining = true;
  500. var len = queue.length;
  501. while(len) {
  502. currentQueue = queue;
  503. queue = [];
  504. while (++queueIndex < len) {
  505. if (currentQueue) {
  506. currentQueue[queueIndex].run();
  507. }
  508. }
  509. queueIndex = -1;
  510. len = queue.length;
  511. }
  512. currentQueue = null;
  513. draining = false;
  514. runClearTimeout(timeout);
  515. }
  516. process.nextTick = function (fun) {
  517. var args = new Array(arguments.length - 1);
  518. if (arguments.length > 1) {
  519. for (var i = 1; i < arguments.length; i++) {
  520. args[i - 1] = arguments[i];
  521. }
  522. }
  523. queue.push(new Item(fun, args));
  524. if (queue.length === 1 && !draining) {
  525. runTimeout(drainQueue);
  526. }
  527. };
  528. // v8 likes predictible objects
  529. function Item(fun, array) {
  530. this.fun = fun;
  531. this.array = array;
  532. }
  533. Item.prototype.run = function () {
  534. this.fun.apply(null, this.array);
  535. };
  536. process.title = 'browser';
  537. process.browser = true;
  538. process.env = {};
  539. process.argv = [];
  540. process.version = ''; // empty string to avoid regexp issues
  541. process.versions = {};
  542. function noop() {}
  543. process.on = noop;
  544. process.addListener = noop;
  545. process.once = noop;
  546. process.off = noop;
  547. process.removeListener = noop;
  548. process.removeAllListeners = noop;
  549. process.emit = noop;
  550. process.binding = function (name) {
  551. throw new Error('process.binding is not supported');
  552. };
  553. process.cwd = function () { return '/' };
  554. process.chdir = function (dir) {
  555. throw new Error('process.chdir is not supported');
  556. };
  557. process.umask = function() { return 0; };
  558. /***/ },
  559. /* 5 */
  560. /***/ function(module, exports, __webpack_require__) {
  561. /**
  562. * This is the common logic for both the Node.js and web browser
  563. * implementations of `debug()`.
  564. *
  565. * Expose `debug()` as the module.
  566. */
  567. exports = module.exports = debug.debug = debug;
  568. exports.coerce = coerce;
  569. exports.disable = disable;
  570. exports.enable = enable;
  571. exports.enabled = enabled;
  572. exports.humanize = __webpack_require__(6);
  573. /**
  574. * The currently active debug mode names, and names to skip.
  575. */
  576. exports.names = [];
  577. exports.skips = [];
  578. /**
  579. * Map of special "%n" handling functions, for the debug "format" argument.
  580. *
  581. * Valid key names are a single, lowercased letter, i.e. "n".
  582. */
  583. exports.formatters = {};
  584. /**
  585. * Previously assigned color.
  586. */
  587. var prevColor = 0;
  588. /**
  589. * Previous log timestamp.
  590. */
  591. var prevTime;
  592. /**
  593. * Select a color.
  594. *
  595. * @return {Number}
  596. * @api private
  597. */
  598. function selectColor() {
  599. return exports.colors[prevColor++ % exports.colors.length];
  600. }
  601. /**
  602. * Create a debugger with the given `namespace`.
  603. *
  604. * @param {String} namespace
  605. * @return {Function}
  606. * @api public
  607. */
  608. function debug(namespace) {
  609. // define the `disabled` version
  610. function disabled() {
  611. }
  612. disabled.enabled = false;
  613. // define the `enabled` version
  614. function enabled() {
  615. var self = enabled;
  616. // set `diff` timestamp
  617. var curr = +new Date();
  618. var ms = curr - (prevTime || curr);
  619. self.diff = ms;
  620. self.prev = prevTime;
  621. self.curr = curr;
  622. prevTime = curr;
  623. // add the `color` if not set
  624. if (null == self.useColors) self.useColors = exports.useColors();
  625. if (null == self.color && self.useColors) self.color = selectColor();
  626. var args = new Array(arguments.length);
  627. for (var i = 0; i < args.length; i++) {
  628. args[i] = arguments[i];
  629. }
  630. args[0] = exports.coerce(args[0]);
  631. if ('string' !== typeof args[0]) {
  632. // anything else let's inspect with %o
  633. args = ['%o'].concat(args);
  634. }
  635. // apply any `formatters` transformations
  636. var index = 0;
  637. args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
  638. // if we encounter an escaped % then don't increase the array index
  639. if (match === '%%') return match;
  640. index++;
  641. var formatter = exports.formatters[format];
  642. if ('function' === typeof formatter) {
  643. var val = args[index];
  644. match = formatter.call(self, val);
  645. // now we need to remove `args[index]` since it's inlined in the `format`
  646. args.splice(index, 1);
  647. index--;
  648. }
  649. return match;
  650. });
  651. // apply env-specific formatting
  652. args = exports.formatArgs.apply(self, args);
  653. var logFn = enabled.log || exports.log || console.log.bind(console);
  654. logFn.apply(self, args);
  655. }
  656. enabled.enabled = true;
  657. var fn = exports.enabled(namespace) ? enabled : disabled;
  658. fn.namespace = namespace;
  659. return fn;
  660. }
  661. /**
  662. * Enables a debug mode by namespaces. This can include modes
  663. * separated by a colon and wildcards.
  664. *
  665. * @param {String} namespaces
  666. * @api public
  667. */
  668. function enable(namespaces) {
  669. exports.save(namespaces);
  670. var split = (namespaces || '').split(/[\s,]+/);
  671. var len = split.length;
  672. for (var i = 0; i < len; i++) {
  673. if (!split[i]) continue; // ignore empty strings
  674. namespaces = split[i].replace(/[\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*?');
  675. if (namespaces[0] === '-') {
  676. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  677. } else {
  678. exports.names.push(new RegExp('^' + namespaces + '$'));
  679. }
  680. }
  681. }
  682. /**
  683. * Disable debug output.
  684. *
  685. * @api public
  686. */
  687. function disable() {
  688. exports.enable('');
  689. }
  690. /**
  691. * Returns true if the given mode name is enabled, false otherwise.
  692. *
  693. * @param {String} name
  694. * @return {Boolean}
  695. * @api public
  696. */
  697. function enabled(name) {
  698. var i, len;
  699. for (i = 0, len = exports.skips.length; i < len; i++) {
  700. if (exports.skips[i].test(name)) {
  701. return false;
  702. }
  703. }
  704. for (i = 0, len = exports.names.length; i < len; i++) {
  705. if (exports.names[i].test(name)) {
  706. return true;
  707. }
  708. }
  709. return false;
  710. }
  711. /**
  712. * Coerce `val`.
  713. *
  714. * @param {Mixed} val
  715. * @return {Mixed}
  716. * @api private
  717. */
  718. function coerce(val) {
  719. if (val instanceof Error) return val.stack || val.message;
  720. return val;
  721. }
  722. /***/ },
  723. /* 6 */
  724. /***/ function(module, exports) {
  725. /**
  726. * Helpers.
  727. */
  728. var s = 1000
  729. var m = s * 60
  730. var h = m * 60
  731. var d = h * 24
  732. var y = d * 365.25
  733. /**
  734. * Parse or format the given `val`.
  735. *
  736. * Options:
  737. *
  738. * - `long` verbose formatting [false]
  739. *
  740. * @param {String|Number} val
  741. * @param {Object} options
  742. * @throws {Error} throw an error if val is not a non-empty string or a number
  743. * @return {String|Number}
  744. * @api public
  745. */
  746. module.exports = function (val, options) {
  747. options = options || {}
  748. var type = typeof val
  749. if (type === 'string' && val.length > 0) {
  750. return parse(val)
  751. } else if (type === 'number' && isNaN(val) === false) {
  752. return options.long ?
  753. fmtLong(val) :
  754. fmtShort(val)
  755. }
  756. throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val))
  757. }
  758. /**
  759. * Parse the given `str` and return milliseconds.
  760. *
  761. * @param {String} str
  762. * @return {Number}
  763. * @api private
  764. */
  765. function parse(str) {
  766. str = String(str)
  767. if (str.length > 10000) {
  768. return
  769. }
  770. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
  771. if (!match) {
  772. return
  773. }
  774. var n = parseFloat(match[1])
  775. var type = (match[2] || 'ms').toLowerCase()
  776. switch (type) {
  777. case 'years':
  778. case 'year':
  779. case 'yrs':
  780. case 'yr':
  781. case 'y':
  782. return n * y
  783. case 'days':
  784. case 'day':
  785. case 'd':
  786. return n * d
  787. case 'hours':
  788. case 'hour':
  789. case 'hrs':
  790. case 'hr':
  791. case 'h':
  792. return n * h
  793. case 'minutes':
  794. case 'minute':
  795. case 'mins':
  796. case 'min':
  797. case 'm':
  798. return n * m
  799. case 'seconds':
  800. case 'second':
  801. case 'secs':
  802. case 'sec':
  803. case 's':
  804. return n * s
  805. case 'milliseconds':
  806. case 'millisecond':
  807. case 'msecs':
  808. case 'msec':
  809. case 'ms':
  810. return n
  811. default:
  812. return undefined
  813. }
  814. }
  815. /**
  816. * Short format for `ms`.
  817. *
  818. * @param {Number} ms
  819. * @return {String}
  820. * @api private
  821. */
  822. function fmtShort(ms) {
  823. if (ms >= d) {
  824. return Math.round(ms / d) + 'd'
  825. }
  826. if (ms >= h) {
  827. return Math.round(ms / h) + 'h'
  828. }
  829. if (ms >= m) {
  830. return Math.round(ms / m) + 'm'
  831. }
  832. if (ms >= s) {
  833. return Math.round(ms / s) + 's'
  834. }
  835. return ms + 'ms'
  836. }
  837. /**
  838. * Long format for `ms`.
  839. *
  840. * @param {Number} ms
  841. * @return {String}
  842. * @api private
  843. */
  844. function fmtLong(ms) {
  845. return plural(ms, d, 'day') ||
  846. plural(ms, h, 'hour') ||
  847. plural(ms, m, 'minute') ||
  848. plural(ms, s, 'second') ||
  849. ms + ' ms'
  850. }
  851. /**
  852. * Pluralization helper.
  853. */
  854. function plural(ms, n, name) {
  855. if (ms < n) {
  856. return
  857. }
  858. if (ms < n * 1.5) {
  859. return Math.floor(ms / n) + ' ' + name
  860. }
  861. return Math.ceil(ms / n) + ' ' + name + 's'
  862. }
  863. /***/ },
  864. /* 7 */
  865. /***/ function(module, exports, __webpack_require__) {
  866. /**
  867. * Module dependencies.
  868. */
  869. var debug = __webpack_require__(8)('socket.io-parser');
  870. var json = __webpack_require__(11);
  871. var Emitter = __webpack_require__(13);
  872. var binary = __webpack_require__(14);
  873. var isBuf = __webpack_require__(16);
  874. /**
  875. * Protocol version.
  876. *
  877. * @api public
  878. */
  879. exports.protocol = 4;
  880. /**
  881. * Packet types.
  882. *
  883. * @api public
  884. */
  885. exports.types = [
  886. 'CONNECT',
  887. 'DISCONNECT',
  888. 'EVENT',
  889. 'ACK',
  890. 'ERROR',
  891. 'BINARY_EVENT',
  892. 'BINARY_ACK'
  893. ];
  894. /**
  895. * Packet type `connect`.
  896. *
  897. * @api public
  898. */
  899. exports.CONNECT = 0;
  900. /**
  901. * Packet type `disconnect`.
  902. *
  903. * @api public
  904. */
  905. exports.DISCONNECT = 1;
  906. /**
  907. * Packet type `event`.
  908. *
  909. * @api public
  910. */
  911. exports.EVENT = 2;
  912. /**
  913. * Packet type `ack`.
  914. *
  915. * @api public
  916. */
  917. exports.ACK = 3;
  918. /**
  919. * Packet type `error`.
  920. *
  921. * @api public
  922. */
  923. exports.ERROR = 4;
  924. /**
  925. * Packet type 'binary event'
  926. *
  927. * @api public
  928. */
  929. exports.BINARY_EVENT = 5;
  930. /**
  931. * Packet type `binary ack`. For acks with binary arguments.
  932. *
  933. * @api public
  934. */
  935. exports.BINARY_ACK = 6;
  936. /**
  937. * Encoder constructor.
  938. *
  939. * @api public
  940. */
  941. exports.Encoder = Encoder;
  942. /**
  943. * Decoder constructor.
  944. *
  945. * @api public
  946. */
  947. exports.Decoder = Decoder;
  948. /**
  949. * A socket.io Encoder instance
  950. *
  951. * @api public
  952. */
  953. function Encoder() {}
  954. /**
  955. * Encode a packet as a single string if non-binary, or as a
  956. * buffer sequence, depending on packet type.
  957. *
  958. * @param {Object} obj - packet object
  959. * @param {Function} callback - function to handle encodings (likely engine.write)
  960. * @return Calls callback with Array of encodings
  961. * @api public
  962. */
  963. Encoder.prototype.encode = function(obj, callback){
  964. debug('encoding packet %j', obj);
  965. if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
  966. encodeAsBinary(obj, callback);
  967. }
  968. else {
  969. var encoding = encodeAsString(obj);
  970. callback([encoding]);
  971. }
  972. };
  973. /**
  974. * Encode packet as string.
  975. *
  976. * @param {Object} packet
  977. * @return {String} encoded
  978. * @api private
  979. */
  980. function encodeAsString(obj) {
  981. var str = '';
  982. var nsp = false;
  983. // first is type
  984. str += obj.type;
  985. // attachments if we have them
  986. if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {
  987. str += obj.attachments;
  988. str += '-';
  989. }
  990. // if we have a namespace other than `/`
  991. // we append it followed by a comma `,`
  992. if (obj.nsp && '/' != obj.nsp) {
  993. nsp = true;
  994. str += obj.nsp;
  995. }
  996. // immediately followed by the id
  997. if (null != obj.id) {
  998. if (nsp) {
  999. str += ',';
  1000. nsp = false;
  1001. }
  1002. str += obj.id;
  1003. }
  1004. // json data
  1005. if (null != obj.data) {
  1006. if (nsp) str += ',';
  1007. str += json.stringify(obj.data);
  1008. }
  1009. debug('encoded %j as %s', obj, str);
  1010. return str;
  1011. }
  1012. /**
  1013. * Encode packet as 'buffer sequence' by removing blobs, and
  1014. * deconstructing packet into object with placeholders and
  1015. * a list of buffers.
  1016. *
  1017. * @param {Object} packet
  1018. * @return {Buffer} encoded
  1019. * @api private
  1020. */
  1021. function encodeAsBinary(obj, callback) {
  1022. function writeEncoding(bloblessData) {
  1023. var deconstruction = binary.deconstructPacket(bloblessData);
  1024. var pack = encodeAsString(deconstruction.packet);
  1025. var buffers = deconstruction.buffers;
  1026. buffers.unshift(pack); // add packet info to beginning of data list
  1027. callback(buffers); // write all the buffers
  1028. }
  1029. binary.removeBlobs(obj, writeEncoding);
  1030. }
  1031. /**
  1032. * A socket.io Decoder instance
  1033. *
  1034. * @return {Object} decoder
  1035. * @api public
  1036. */
  1037. function Decoder() {
  1038. this.reconstructor = null;
  1039. }
  1040. /**
  1041. * Mix in `Emitter` with Decoder.
  1042. */
  1043. Emitter(Decoder.prototype);
  1044. /**
  1045. * Decodes an ecoded packet string into packet JSON.
  1046. *
  1047. * @param {String} obj - encoded packet
  1048. * @return {Object} packet
  1049. * @api public
  1050. */
  1051. Decoder.prototype.add = function(obj) {
  1052. var packet;
  1053. if ('string' == typeof obj) {
  1054. packet = decodeString(obj);
  1055. if (exports.BINARY_EVENT == packet.type || exports.BINARY_ACK == packet.type) { // binary packet's json
  1056. this.reconstructor = new BinaryReconstructor(packet);
  1057. // no attachments, labeled binary but no binary data to follow
  1058. if (this.reconstructor.reconPack.attachments === 0) {
  1059. this.emit('decoded', packet);
  1060. }
  1061. } else { // non-binary full packet
  1062. this.emit('decoded', packet);
  1063. }
  1064. }
  1065. else if (isBuf(obj) || obj.base64) { // raw binary data
  1066. if (!this.reconstructor) {
  1067. throw new Error('got binary data when not reconstructing a packet');
  1068. } else {
  1069. packet = this.reconstructor.takeBinaryData(obj);
  1070. if (packet) { // received final buffer
  1071. this.reconstructor = null;
  1072. this.emit('decoded', packet);
  1073. }
  1074. }
  1075. }
  1076. else {
  1077. throw new Error('Unknown type: ' + obj);
  1078. }
  1079. };
  1080. /**
  1081. * Decode a packet String (JSON data)
  1082. *
  1083. * @param {String} str
  1084. * @return {Object} packet
  1085. * @api private
  1086. */
  1087. function decodeString(str) {
  1088. var p = {};
  1089. var i = 0;
  1090. // look up type
  1091. p.type = Number(str.charAt(0));
  1092. if (null == exports.types[p.type]) return error();
  1093. // look up attachments if type binary
  1094. if (exports.BINARY_EVENT == p.type || exports.BINARY_ACK == p.type) {
  1095. var buf = '';
  1096. while (str.charAt(++i) != '-') {
  1097. buf += str.charAt(i);
  1098. if (i == str.length) break;
  1099. }
  1100. if (buf != Number(buf) || str.charAt(i) != '-') {
  1101. throw new Error('Illegal attachments');
  1102. }
  1103. p.attachments = Number(buf);
  1104. }
  1105. // look up namespace (if any)
  1106. if ('/' == str.charAt(i + 1)) {
  1107. p.nsp = '';
  1108. while (++i) {
  1109. var c = str.charAt(i);
  1110. if (',' == c) break;
  1111. p.nsp += c;
  1112. if (i == str.length) break;
  1113. }
  1114. } else {
  1115. p.nsp = '/';
  1116. }
  1117. // look up id
  1118. var next = str.charAt(i + 1);
  1119. if ('' !== next && Number(next) == next) {
  1120. p.id = '';
  1121. while (++i) {
  1122. var c = str.charAt(i);
  1123. if (null == c || Number(c) != c) {
  1124. --i;
  1125. break;
  1126. }
  1127. p.id += str.charAt(i);
  1128. if (i == str.length) break;
  1129. }
  1130. p.id = Number(p.id);
  1131. }
  1132. // look up json data
  1133. if (str.charAt(++i)) {
  1134. p = tryParse(p, str.substr(i));
  1135. }
  1136. debug('decoded %s as %j', str, p);
  1137. return p;
  1138. }
  1139. function tryParse(p, str) {
  1140. try {
  1141. p.data = json.parse(str);
  1142. } catch(e){
  1143. return error();
  1144. }
  1145. return p;
  1146. };
  1147. /**
  1148. * Deallocates a parser's resources
  1149. *
  1150. * @api public
  1151. */
  1152. Decoder.prototype.destroy = function() {
  1153. if (this.reconstructor) {
  1154. this.reconstructor.finishedReconstruction();
  1155. }
  1156. };
  1157. /**
  1158. * A manager of a binary event's 'buffer sequence'. Should
  1159. * be constructed whenever a packet of type BINARY_EVENT is
  1160. * decoded.
  1161. *
  1162. * @param {Object} packet
  1163. * @return {BinaryReconstructor} initialized reconstructor
  1164. * @api private
  1165. */
  1166. function BinaryReconstructor(packet) {
  1167. this.reconPack = packet;
  1168. this.buffers = [];
  1169. }
  1170. /**
  1171. * Method to be called when binary data received from connection
  1172. * after a BINARY_EVENT packet.
  1173. *
  1174. * @param {Buffer | ArrayBuffer} binData - the raw binary data received
  1175. * @return {null | Object} returns null if more binary data is expected or
  1176. * a reconstructed packet object if all buffers have been received.
  1177. * @api private
  1178. */
  1179. BinaryReconstructor.prototype.takeBinaryData = function(binData) {
  1180. this.buffers.push(binData);
  1181. if (this.buffers.length == this.reconPack.attachments) { // done with buffer list
  1182. var packet = binary.reconstructPacket(this.reconPack, this.buffers);
  1183. this.finishedReconstruction();
  1184. return packet;
  1185. }
  1186. return null;
  1187. };
  1188. /**
  1189. * Cleans up binary packet reconstruction variables.
  1190. *
  1191. * @api private
  1192. */
  1193. BinaryReconstructor.prototype.finishedReconstruction = function() {
  1194. this.reconPack = null;
  1195. this.buffers = [];
  1196. };
  1197. function error(data){
  1198. return {
  1199. type: exports.ERROR,
  1200. data: 'parser error'
  1201. };
  1202. }
  1203. /***/ },
  1204. /* 8 */
  1205. /***/ function(module, exports, __webpack_require__) {
  1206. /**
  1207. * This is the web browser implementation of `debug()`.
  1208. *
  1209. * Expose `debug()` as the module.
  1210. */
  1211. exports = module.exports = __webpack_require__(9);
  1212. exports.log = log;
  1213. exports.formatArgs = formatArgs;
  1214. exports.save = save;
  1215. exports.load = load;
  1216. exports.useColors = useColors;
  1217. exports.storage = 'undefined' != typeof chrome
  1218. && 'undefined' != typeof chrome.storage
  1219. ? chrome.storage.local
  1220. : localstorage();
  1221. /**
  1222. * Colors.
  1223. */
  1224. exports.colors = [
  1225. 'lightseagreen',
  1226. 'forestgreen',
  1227. 'goldenrod',
  1228. 'dodgerblue',
  1229. 'darkorchid',
  1230. 'crimson'
  1231. ];
  1232. /**
  1233. * Currently only WebKit-based Web Inspectors, Firefox >= v31,
  1234. * and the Firebug extension (any Firefox version) are known
  1235. * to support "%c" CSS customizations.
  1236. *
  1237. * TODO: add a `localStorage` variable to explicitly enable/disable colors
  1238. */
  1239. function useColors() {
  1240. // is webkit? http://stackoverflow.com/a/16459606/376773
  1241. return ('WebkitAppearance' in document.documentElement.style) ||
  1242. // is firebug? http://stackoverflow.com/a/398120/376773
  1243. (window.console && (console.firebug || (console.exception && console.table))) ||
  1244. // is firefox >= v31?
  1245. // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
  1246. (navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
  1247. }
  1248. /**
  1249. * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
  1250. */
  1251. exports.formatters.j = function(v) {
  1252. return JSON.stringify(v);
  1253. };
  1254. /**
  1255. * Colorize log arguments if enabled.
  1256. *
  1257. * @api public
  1258. */
  1259. function formatArgs() {
  1260. var args = arguments;
  1261. var useColors = this.useColors;
  1262. args[0] = (useColors ? '%c' : '')
  1263. + this.namespace
  1264. + (useColors ? ' %c' : ' ')
  1265. + args[0]
  1266. + (useColors ? '%c ' : ' ')
  1267. + '+' + exports.humanize(this.diff);
  1268. if (!useColors) return args;
  1269. var c = 'color: ' + this.color;
  1270. args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
  1271. // the final "%c" is somewhat tricky, because there could be other
  1272. // arguments passed either before or after the %c, so we need to
  1273. // figure out the correct index to insert the CSS into
  1274. var index = 0;
  1275. var lastC = 0;
  1276. args[0].replace(/%[a-z%]/g, function(match) {
  1277. if ('%%' === match) return;
  1278. index++;
  1279. if ('%c' === match) {
  1280. // we only are interested in the *last* %c
  1281. // (the user may have provided their own)
  1282. lastC = index;
  1283. }
  1284. });
  1285. args.splice(lastC, 0, c);
  1286. return args;
  1287. }
  1288. /**
  1289. * Invokes `console.log()` when available.
  1290. * No-op when `console.log` is not a "function".
  1291. *
  1292. * @api public
  1293. */
  1294. function log() {
  1295. // this hackery is required for IE8/9, where
  1296. // the `console.log` function doesn't have 'apply'
  1297. return 'object' === typeof console
  1298. && console.log
  1299. && Function.prototype.apply.call(console.log, console, arguments);
  1300. }
  1301. /**
  1302. * Save `namespaces`.
  1303. *
  1304. * @param {String} namespaces
  1305. * @api private
  1306. */
  1307. function save(namespaces) {
  1308. try {
  1309. if (null == namespaces) {
  1310. exports.storage.removeItem('debug');
  1311. } else {
  1312. exports.storage.debug = namespaces;
  1313. }
  1314. } catch(e) {}
  1315. }
  1316. /**
  1317. * Load `namespaces`.
  1318. *
  1319. * @return {String} returns the previously persisted debug modes
  1320. * @api private
  1321. */
  1322. function load() {
  1323. var r;
  1324. try {
  1325. r = exports.storage.debug;
  1326. } catch(e) {}
  1327. return r;
  1328. }
  1329. /**
  1330. * Enable namespaces listed in `localStorage.debug` initially.
  1331. */
  1332. exports.enable(load());
  1333. /**
  1334. * Localstorage attempts to return the localstorage.
  1335. *
  1336. * This is necessary because safari throws
  1337. * when a user disables cookies/localstorage
  1338. * and you attempt to access it.
  1339. *
  1340. * @return {LocalStorage}
  1341. * @api private
  1342. */
  1343. function localstorage(){
  1344. try {
  1345. return window.localStorage;
  1346. } catch (e) {}
  1347. }
  1348. /***/ },
  1349. /* 9 */
  1350. /***/ function(module, exports, __webpack_require__) {
  1351. /**
  1352. * This is the common logic for both the Node.js and web browser
  1353. * implementations of `debug()`.
  1354. *
  1355. * Expose `debug()` as the module.
  1356. */
  1357. exports = module.exports = debug;
  1358. exports.coerce = coerce;
  1359. exports.disable = disable;
  1360. exports.enable = enable;
  1361. exports.enabled = enabled;
  1362. exports.humanize = __webpack_require__(10);
  1363. /**
  1364. * The currently active debug mode names, and names to skip.
  1365. */
  1366. exports.names = [];
  1367. exports.skips = [];
  1368. /**
  1369. * Map of special "%n" handling functions, for the debug "format" argument.
  1370. *
  1371. * Valid key names are a single, lowercased letter, i.e. "n".
  1372. */
  1373. exports.formatters = {};
  1374. /**
  1375. * Previously assigned color.
  1376. */
  1377. var prevColor = 0;
  1378. /**
  1379. * Previous log timestamp.
  1380. */
  1381. var prevTime;
  1382. /**
  1383. * Select a color.
  1384. *
  1385. * @return {Number}
  1386. * @api private
  1387. */
  1388. function selectColor() {
  1389. return exports.colors[prevColor++ % exports.colors.length];
  1390. }
  1391. /**
  1392. * Create a debugger with the given `namespace`.
  1393. *
  1394. * @param {String} namespace
  1395. * @return {Function}
  1396. * @api public
  1397. */
  1398. function debug(namespace) {
  1399. // define the `disabled` version
  1400. function disabled() {
  1401. }
  1402. disabled.enabled = false;
  1403. // define the `enabled` version
  1404. function enabled() {
  1405. var self = enabled;
  1406. // set `diff` timestamp
  1407. var curr = +new Date();
  1408. var ms = curr - (prevTime || curr);
  1409. self.diff = ms;
  1410. self.prev = prevTime;
  1411. self.curr = curr;
  1412. prevTime = curr;
  1413. // add the `color` if not set
  1414. if (null == self.useColors) self.useColors = exports.useColors();
  1415. if (null == self.color && self.useColors) self.color = selectColor();
  1416. var args = Array.prototype.slice.call(arguments);
  1417. args[0] = exports.coerce(args[0]);
  1418. if ('string' !== typeof args[0]) {
  1419. // anything else let's inspect with %o
  1420. args = ['%o'].concat(args);
  1421. }
  1422. // apply any `formatters` transformations
  1423. var index = 0;
  1424. args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
  1425. // if we encounter an escaped % then don't increase the array index
  1426. if (match === '%%') return match;
  1427. index++;
  1428. var formatter = exports.formatters[format];
  1429. if ('function' === typeof formatter) {
  1430. var val = args[index];
  1431. match = formatter.call(self, val);
  1432. // now we need to remove `args[index]` since it's inlined in the `format`
  1433. args.splice(index, 1);
  1434. index--;
  1435. }
  1436. return match;
  1437. });
  1438. if ('function' === typeof exports.formatArgs) {
  1439. args = exports.formatArgs.apply(self, args);
  1440. }
  1441. var logFn = enabled.log || exports.log || console.log.bind(console);
  1442. logFn.apply(self, args);
  1443. }
  1444. enabled.enabled = true;
  1445. var fn = exports.enabled(namespace) ? enabled : disabled;
  1446. fn.namespace = namespace;
  1447. return fn;
  1448. }
  1449. /**
  1450. * Enables a debug mode by namespaces. This can include modes
  1451. * separated by a colon and wildcards.
  1452. *
  1453. * @param {String} namespaces
  1454. * @api public
  1455. */
  1456. function enable(namespaces) {
  1457. exports.save(namespaces);
  1458. var split = (namespaces || '').split(/[\s,]+/);
  1459. var len = split.length;
  1460. for (var i = 0; i < len; i++) {
  1461. if (!split[i]) continue; // ignore empty strings
  1462. namespaces = split[i].replace(/\*/g, '.*?');
  1463. if (namespaces[0] === '-') {
  1464. exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
  1465. } else {
  1466. exports.names.push(new RegExp('^' + namespaces + '$'));
  1467. }
  1468. }
  1469. }
  1470. /**
  1471. * Disable debug output.
  1472. *
  1473. * @api public
  1474. */
  1475. function disable() {
  1476. exports.enable('');
  1477. }
  1478. /**
  1479. * Returns true if the given mode name is enabled, false otherwise.
  1480. *
  1481. * @param {String} name
  1482. * @return {Boolean}
  1483. * @api public
  1484. */
  1485. function enabled(name) {
  1486. var i, len;
  1487. for (i = 0, len = exports.skips.length; i < len; i++) {
  1488. if (exports.skips[i].test(name)) {
  1489. return false;
  1490. }
  1491. }
  1492. for (i = 0, len = exports.names.length; i < len; i++) {
  1493. if (exports.names[i].test(name)) {
  1494. return true;
  1495. }
  1496. }
  1497. return false;
  1498. }
  1499. /**
  1500. * Coerce `val`.
  1501. *
  1502. * @param {Mixed} val
  1503. * @return {Mixed}
  1504. * @api private
  1505. */
  1506. function coerce(val) {
  1507. if (val instanceof Error) return val.stack || val.message;
  1508. return val;
  1509. }
  1510. /***/ },
  1511. /* 10 */
  1512. /***/ function(module, exports) {
  1513. /**
  1514. * Helpers.
  1515. */
  1516. var s = 1000;
  1517. var m = s * 60;
  1518. var h = m * 60;
  1519. var d = h * 24;
  1520. var y = d * 365.25;
  1521. /**
  1522. * Parse or format the given `val`.
  1523. *
  1524. * Options:
  1525. *
  1526. * - `long` verbose formatting [false]
  1527. *
  1528. * @param {String|Number} val
  1529. * @param {Object} options
  1530. * @return {String|Number}
  1531. * @api public
  1532. */
  1533. module.exports = function(val, options){
  1534. options = options || {};
  1535. if ('string' == typeof val) return parse(val);
  1536. return options.long
  1537. ? long(val)
  1538. : short(val);
  1539. };
  1540. /**
  1541. * Parse the given `str` and return milliseconds.
  1542. *
  1543. * @param {String} str
  1544. * @return {Number}
  1545. * @api private
  1546. */
  1547. function parse(str) {
  1548. str = '' + str;
  1549. if (str.length > 10000) return;
  1550. var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
  1551. if (!match) return;
  1552. var n = parseFloat(match[1]);
  1553. var type = (match[2] || 'ms').toLowerCase();
  1554. switch (type) {
  1555. case 'years':
  1556. case 'year':
  1557. case 'yrs':
  1558. case 'yr':
  1559. case 'y':
  1560. return n * y;
  1561. case 'days':
  1562. case 'day':
  1563. case 'd':
  1564. return n * d;
  1565. case 'hours':
  1566. case 'hour':
  1567. case 'hrs':
  1568. case 'hr':
  1569. case 'h':
  1570. return n * h;
  1571. case 'minutes':
  1572. case 'minute':
  1573. case 'mins':
  1574. case 'min':
  1575. case 'm':
  1576. return n * m;
  1577. case 'seconds':
  1578. case 'second':
  1579. case 'secs':
  1580. case 'sec':
  1581. case 's':
  1582. return n * s;
  1583. case 'milliseconds':
  1584. case 'millisecond':
  1585. case 'msecs':
  1586. case 'msec':
  1587. case 'ms':
  1588. return n;
  1589. }
  1590. }
  1591. /**
  1592. * Short format for `ms`.
  1593. *
  1594. * @param {Number} ms
  1595. * @return {String}
  1596. * @api private
  1597. */
  1598. function short(ms) {
  1599. if (ms >= d) return Math.round(ms / d) + 'd';
  1600. if (ms >= h) return Math.round(ms / h) + 'h';
  1601. if (ms >= m) return Math.round(ms / m) + 'm';
  1602. if (ms >= s) return Math.round(ms / s) + 's';
  1603. return ms + 'ms';
  1604. }
  1605. /**
  1606. * Long format for `ms`.
  1607. *
  1608. * @param {Number} ms
  1609. * @return {String}
  1610. * @api private
  1611. */
  1612. function long(ms) {
  1613. return plural(ms, d, 'day')
  1614. || plural(ms, h, 'hour')
  1615. || plural(ms, m, 'minute')
  1616. || plural(ms, s, 'second')
  1617. || ms + ' ms';
  1618. }
  1619. /**
  1620. * Pluralization helper.
  1621. */
  1622. function plural(ms, n, name) {
  1623. if (ms < n) return;
  1624. if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
  1625. return Math.ceil(ms / n) + ' ' + name + 's';
  1626. }
  1627. /***/ },
  1628. /* 11 */
  1629. /***/ function(module, exports, __webpack_require__) {
  1630. /* WEBPACK VAR INJECTION */(function(module, global) {/*** IMPORTS FROM imports-loader ***/
  1631. var define = false;
  1632. /*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
  1633. ;(function () {
  1634. // Detect the `define` function exposed by asynchronous module loaders. The
  1635. // strict `define` check is necessary for compatibility with `r.js`.
  1636. var isLoader = typeof define === "function" && define.amd;
  1637. // A set of types used to distinguish objects from primitives.
  1638. var objectTypes = {
  1639. "function": true,
  1640. "object": true
  1641. };
  1642. // Detect the `exports` object exposed by CommonJS implementations.
  1643. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  1644. // Use the `global` object exposed by Node (including Browserify via
  1645. // `insert-module-globals`), Narwhal, and Ringo as the default context,
  1646. // and the `window` object in browsers. Rhino exports a `global` function
  1647. // instead.
  1648. var root = objectTypes[typeof window] && window || this,
  1649. freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
  1650. if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
  1651. root = freeGlobal;
  1652. }
  1653. // Public: Initializes JSON 3 using the given `context` object, attaching the
  1654. // `stringify` and `parse` functions to the specified `exports` object.
  1655. function runInContext(context, exports) {
  1656. context || (context = root["Object"]());
  1657. exports || (exports = root["Object"]());
  1658. // Native constructor aliases.
  1659. var Number = context["Number"] || root["Number"],
  1660. String = context["String"] || root["String"],
  1661. Object = context["Object"] || root["Object"],
  1662. Date = context["Date"] || root["Date"],
  1663. SyntaxError = context["SyntaxError"] || root["SyntaxError"],
  1664. TypeError = context["TypeError"] || root["TypeError"],
  1665. Math = context["Math"] || root["Math"],
  1666. nativeJSON = context["JSON"] || root["JSON"];
  1667. // Delegate to the native `stringify` and `parse` implementations.
  1668. if (typeof nativeJSON == "object" && nativeJSON) {
  1669. exports.stringify = nativeJSON.stringify;
  1670. exports.parse = nativeJSON.parse;
  1671. }
  1672. // Convenience aliases.
  1673. var objectProto = Object.prototype,
  1674. getClass = objectProto.toString,
  1675. isProperty, forEach, undef;
  1676. // Test the `Date#getUTC*` methods. Based on work by @Yaffle.
  1677. var isExtended = new Date(-3509827334573292);
  1678. try {
  1679. // The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
  1680. // results for certain dates in Opera >= 10.53.
  1681. isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
  1682. // Safari < 2.0.2 stores the internal millisecond time value correctly,
  1683. // but clips the values returned by the date methods to the range of
  1684. // signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
  1685. isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
  1686. } catch (exception) {}
  1687. // Internal: Determines whether the native `JSON.stringify` and `parse`
  1688. // implementations are spec-compliant. Based on work by Ken Snyder.
  1689. function has(name) {
  1690. if (has[name] !== undef) {
  1691. // Return cached feature test result.
  1692. return has[name];
  1693. }
  1694. var isSupported;
  1695. if (name == "bug-string-char-index") {
  1696. // IE <= 7 doesn't support accessing string characters using square
  1697. // bracket notation. IE 8 only supports this for primitives.
  1698. isSupported = "a"[0] != "a";
  1699. } else if (name == "json") {
  1700. // Indicates whether both `JSON.stringify` and `JSON.parse` are
  1701. // supported.
  1702. isSupported = has("json-stringify") && has("json-parse");
  1703. } else {
  1704. var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
  1705. // Test `JSON.stringify`.
  1706. if (name == "json-stringify") {
  1707. var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
  1708. if (stringifySupported) {
  1709. // A test function object with a custom `toJSON` method.
  1710. (value = function () {
  1711. return 1;
  1712. }).toJSON = value;
  1713. try {
  1714. stringifySupported =
  1715. // Firefox 3.1b1 and b2 serialize string, number, and boolean
  1716. // primitives as object literals.
  1717. stringify(0) === "0" &&
  1718. // FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
  1719. // literals.
  1720. stringify(new Number()) === "0" &&
  1721. stringify(new String()) == '""' &&
  1722. // FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
  1723. // does not define a canonical JSON representation (this applies to
  1724. // objects with `toJSON` properties as well, *unless* they are nested
  1725. // within an object or array).
  1726. stringify(getClass) === undef &&
  1727. // IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
  1728. // FF 3.1b3 pass this test.
  1729. stringify(undef) === undef &&
  1730. // Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
  1731. // respectively, if the value is omitted entirely.
  1732. stringify() === undef &&
  1733. // FF 3.1b1, 2 throw an error if the given value is not a number,
  1734. // string, array, object, Boolean, or `null` literal. This applies to
  1735. // objects with custom `toJSON` methods as well, unless they are nested
  1736. // inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
  1737. // methods entirely.
  1738. stringify(value) === "1" &&
  1739. stringify([value]) == "[1]" &&
  1740. // Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
  1741. // `"[null]"`.
  1742. stringify([undef]) == "[null]" &&
  1743. // YUI 3.0.0b1 fails to serialize `null` literals.
  1744. stringify(null) == "null" &&
  1745. // FF 3.1b1, 2 halts serialization if an array contains a function:
  1746. // `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
  1747. // elides non-JSON values from objects and arrays, unless they
  1748. // define custom `toJSON` methods.
  1749. stringify([undef, getClass, null]) == "[null,null,null]" &&
  1750. // Simple serialization test. FF 3.1b1 uses Unicode escape sequences
  1751. // where character escape codes are expected (e.g., `\b` => `\u0008`).
  1752. stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
  1753. // FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
  1754. stringify(null, value) === "1" &&
  1755. stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
  1756. // JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
  1757. // serialize extended years.
  1758. stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
  1759. // The milliseconds are optional in ES 5, but required in 5.1.
  1760. stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
  1761. // Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
  1762. // four-digit years instead of six-digit years. Credits: @Yaffle.
  1763. stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
  1764. // Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
  1765. // values less than 1000. Credits: @Yaffle.
  1766. stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
  1767. } catch (exception) {
  1768. stringifySupported = false;
  1769. }
  1770. }
  1771. isSupported = stringifySupported;
  1772. }
  1773. // Test `JSON.parse`.
  1774. if (name == "json-parse") {
  1775. var parse = exports.parse;
  1776. if (typeof parse == "function") {
  1777. try {
  1778. // FF 3.1b1, b2 will throw an exception if a bare literal is provided.
  1779. // Conforming implementations should also coerce the initial argument to
  1780. // a string prior to parsing.
  1781. if (parse("0") === 0 && !parse(false)) {
  1782. // Simple parsing test.
  1783. value = parse(serialized);
  1784. var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
  1785. if (parseSupported) {
  1786. try {
  1787. // Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
  1788. parseSupported = !parse('"\t"');
  1789. } catch (exception) {}
  1790. if (parseSupported) {
  1791. try {
  1792. // FF 4.0 and 4.0.1 allow leading `+` signs and leading
  1793. // decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
  1794. // certain octal literals.
  1795. parseSupported = parse("01") !== 1;
  1796. } catch (exception) {}
  1797. }
  1798. if (parseSupported) {
  1799. try {
  1800. // FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
  1801. // points. These environments, along with FF 3.1b1 and 2,
  1802. // also allow trailing commas in JSON objects and arrays.
  1803. parseSupported = parse("1.") !== 1;
  1804. } catch (exception) {}
  1805. }
  1806. }
  1807. }
  1808. } catch (exception) {
  1809. parseSupported = false;
  1810. }
  1811. }
  1812. isSupported = parseSupported;
  1813. }
  1814. }
  1815. return has[name] = !!isSupported;
  1816. }
  1817. if (!has("json")) {
  1818. // Common `[[Class]]` name aliases.
  1819. var functionClass = "[object Function]",
  1820. dateClass = "[object Date]",
  1821. numberClass = "[object Number]",
  1822. stringClass = "[object String]",
  1823. arrayClass = "[object Array]",
  1824. booleanClass = "[object Boolean]";
  1825. // Detect incomplete support for accessing string characters by index.
  1826. var charIndexBuggy = has("bug-string-char-index");
  1827. // Define additional utility methods if the `Date` methods are buggy.
  1828. if (!isExtended) {
  1829. var floor = Math.floor;
  1830. // A mapping between the months of the year and the number of days between
  1831. // January 1st and the first of the respective month.
  1832. var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
  1833. // Internal: Calculates the number of days between the Unix epoch and the
  1834. // first day of the given month.
  1835. var getDay = function (year, month) {
  1836. return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
  1837. };
  1838. }
  1839. // Internal: Determines if a property is a direct property of the given
  1840. // object. Delegates to the native `Object#hasOwnProperty` method.
  1841. if (!(isProperty = objectProto.hasOwnProperty)) {
  1842. isProperty = function (property) {
  1843. var members = {}, constructor;
  1844. if ((members.__proto__ = null, members.__proto__ = {
  1845. // The *proto* property cannot be set multiple times in recent
  1846. // versions of Firefox and SeaMonkey.
  1847. "toString": 1
  1848. }, members).toString != getClass) {
  1849. // Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
  1850. // supports the mutable *proto* property.
  1851. isProperty = function (property) {
  1852. // Capture and break the object's prototype chain (see section 8.6.2
  1853. // of the ES 5.1 spec). The parenthesized expression prevents an
  1854. // unsafe transformation by the Closure Compiler.
  1855. var original = this.__proto__, result = property in (this.__proto__ = null, this);
  1856. // Restore the original prototype chain.
  1857. this.__proto__ = original;
  1858. return result;
  1859. };
  1860. } else {
  1861. // Capture a reference to the top-level `Object` constructor.
  1862. constructor = members.constructor;
  1863. // Use the `constructor` property to simulate `Object#hasOwnProperty` in
  1864. // other environments.
  1865. isProperty = function (property) {
  1866. var parent = (this.constructor || constructor).prototype;
  1867. return property in this && !(property in parent && this[property] === parent[property]);
  1868. };
  1869. }
  1870. members = null;
  1871. return isProperty.call(this, property);
  1872. };
  1873. }
  1874. // Internal: Normalizes the `for...in` iteration algorithm across
  1875. // environments. Each enumerated key is yielded to a `callback` function.
  1876. forEach = function (object, callback) {
  1877. var size = 0, Properties, members, property;
  1878. // Tests for bugs in the current environment's `for...in` algorithm. The
  1879. // `valueOf` property inherits the non-enumerable flag from
  1880. // `Object.prototype` in older versions of IE, Netscape, and Mozilla.
  1881. (Properties = function () {
  1882. this.valueOf = 0;
  1883. }).prototype.valueOf = 0;
  1884. // Iterate over a new instance of the `Properties` class.
  1885. members = new Properties();
  1886. for (property in members) {
  1887. // Ignore all properties inherited from `Object.prototype`.
  1888. if (isProperty.call(members, property)) {
  1889. size++;
  1890. }
  1891. }
  1892. Properties = members = null;
  1893. // Normalize the iteration algorithm.
  1894. if (!size) {
  1895. // A list of non-enumerable properties inherited from `Object.prototype`.
  1896. members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
  1897. // IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
  1898. // properties.
  1899. forEach = function (object, callback) {
  1900. var isFunction = getClass.call(object) == functionClass, property, length;
  1901. var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
  1902. for (property in object) {
  1903. // Gecko <= 1.0 enumerates the `prototype` property of functions under
  1904. // certain conditions; IE does not.
  1905. if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
  1906. callback(property);
  1907. }
  1908. }
  1909. // Manually invoke the callback for each non-enumerable property.
  1910. for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
  1911. };
  1912. } else if (size == 2) {
  1913. // Safari <= 2.0.4 enumerates shadowed properties twice.
  1914. forEach = function (object, callback) {
  1915. // Create a set of iterated properties.
  1916. var members = {}, isFunction = getClass.call(object) == functionClass, property;
  1917. for (property in object) {
  1918. // Store each property name to prevent double enumeration. The
  1919. // `prototype` property of functions is not enumerated due to cross-
  1920. // environment inconsistencies.
  1921. if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
  1922. callback(property);
  1923. }
  1924. }
  1925. };
  1926. } else {
  1927. // No bugs detected; use the standard `for...in` algorithm.
  1928. forEach = function (object, callback) {
  1929. var isFunction = getClass.call(object) == functionClass, property, isConstructor;
  1930. for (property in object) {
  1931. if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
  1932. callback(property);
  1933. }
  1934. }
  1935. // Manually invoke the callback for the `constructor` property due to
  1936. // cross-environment inconsistencies.
  1937. if (isConstructor || isProperty.call(object, (property = "constructor"))) {
  1938. callback(property);
  1939. }
  1940. };
  1941. }
  1942. return forEach(object, callback);
  1943. };
  1944. // Public: Serializes a JavaScript `value` as a JSON string. The optional
  1945. // `filter` argument may specify either a function that alters how object and
  1946. // array members are serialized, or an array of strings and numbers that
  1947. // indicates which properties should be serialized. The optional `width`
  1948. // argument may be either a string or number that specifies the indentation
  1949. // level of the output.
  1950. if (!has("json-stringify")) {
  1951. // Internal: A map of control characters and their escaped equivalents.
  1952. var Escapes = {
  1953. 92: "\\\\",
  1954. 34: '\\"',
  1955. 8: "\\b",
  1956. 12: "\\f",
  1957. 10: "\\n",
  1958. 13: "\\r",
  1959. 9: "\\t"
  1960. };
  1961. // Internal: Converts `value` into a zero-padded string such that its
  1962. // length is at least equal to `width`. The `width` must be <= 6.
  1963. var leadingZeroes = "000000";
  1964. var toPaddedString = function (width, value) {
  1965. // The `|| 0` expression is necessary to work around a bug in
  1966. // Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
  1967. return (leadingZeroes + (value || 0)).slice(-width);
  1968. };
  1969. // Internal: Double-quotes a string `value`, replacing all ASCII control
  1970. // characters (characters with code unit values between 0 and 31) with
  1971. // their escaped equivalents. This is an implementation of the
  1972. // `Quote(value)` operation defined in ES 5.1 section 15.12.3.
  1973. var unicodePrefix = "\\u00";
  1974. var quote = function (value) {
  1975. var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
  1976. var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
  1977. for (; index < length; index++) {
  1978. var charCode = value.charCodeAt(index);
  1979. // If the character is a control character, append its Unicode or
  1980. // shorthand escape sequence; otherwise, append the character as-is.
  1981. switch (charCode) {
  1982. case 8: case 9: case 10: case 12: case 13: case 34: case 92:
  1983. result += Escapes[charCode];
  1984. break;
  1985. default:
  1986. if (charCode < 32) {
  1987. result += unicodePrefix + toPaddedString(2, charCode.toString(16));
  1988. break;
  1989. }
  1990. result += useCharIndex ? symbols[index] : value.charAt(index);
  1991. }
  1992. }
  1993. return result + '"';
  1994. };
  1995. // Internal: Recursively serializes an object. Implements the
  1996. // `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
  1997. var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
  1998. var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
  1999. try {
  2000. // Necessary for host object support.
  2001. value = object[property];
  2002. } catch (exception) {}
  2003. if (typeof value == "object" && value) {
  2004. className = getClass.call(value);
  2005. if (className == dateClass && !isProperty.call(value, "toJSON")) {
  2006. if (value > -1 / 0 && value < 1 / 0) {
  2007. // Dates are serialized according to the `Date#toJSON` method
  2008. // specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
  2009. // for the ISO 8601 date time string format.
  2010. if (getDay) {
  2011. // Manually compute the year, month, date, hours, minutes,
  2012. // seconds, and milliseconds if the `getUTC*` methods are
  2013. // buggy. Adapted from @Yaffle's `date-shim` project.
  2014. date = floor(value / 864e5);
  2015. for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
  2016. for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
  2017. date = 1 + date - getDay(year, month);
  2018. // The `time` value specifies the time within the day (see ES
  2019. // 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
  2020. // to compute `A modulo B`, as the `%` operator does not
  2021. // correspond to the `modulo` operation for negative numbers.
  2022. time = (value % 864e5 + 864e5) % 864e5;
  2023. // The hours, minutes, seconds, and milliseconds are obtained by
  2024. // decomposing the time within the day. See section 15.9.1.10.
  2025. hours = floor(time / 36e5) % 24;
  2026. minutes = floor(time / 6e4) % 60;
  2027. seconds = floor(time / 1e3) % 60;
  2028. milliseconds = time % 1e3;
  2029. } else {
  2030. year = value.getUTCFullYear();
  2031. month = value.getUTCMonth();
  2032. date = value.getUTCDate();
  2033. hours = value.getUTCHours();
  2034. minutes = value.getUTCMinutes();
  2035. seconds = value.getUTCSeconds();
  2036. milliseconds = value.getUTCMilliseconds();
  2037. }
  2038. // Serialize extended years correctly.
  2039. value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
  2040. "-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
  2041. // Months, dates, hours, minutes, and seconds should have two
  2042. // digits; milliseconds should have three.
  2043. "T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
  2044. // Milliseconds are optional in ES 5.0, but required in 5.1.
  2045. "." + toPaddedString(3, milliseconds) + "Z";
  2046. } else {
  2047. value = null;
  2048. }
  2049. } else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
  2050. // Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
  2051. // `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
  2052. // ignores all `toJSON` methods on these objects unless they are
  2053. // defined directly on an instance.
  2054. value = value.toJSON(property);
  2055. }
  2056. }
  2057. if (callback) {
  2058. // If a replacement function was provided, call it to obtain the value
  2059. // for serialization.
  2060. value = callback.call(object, property, value);
  2061. }
  2062. if (value === null) {
  2063. return "null";
  2064. }
  2065. className = getClass.call(value);
  2066. if (className == booleanClass) {
  2067. // Booleans are represented literally.
  2068. return "" + value;
  2069. } else if (className == numberClass) {
  2070. // JSON numbers must be finite. `Infinity` and `NaN` are serialized as
  2071. // `"null"`.
  2072. return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
  2073. } else if (className == stringClass) {
  2074. // Strings are double-quoted and escaped.
  2075. return quote("" + value);
  2076. }
  2077. // Recursively serialize objects and arrays.
  2078. if (typeof value == "object") {
  2079. // Check for cyclic structures. This is a linear search; performance
  2080. // is inversely proportional to the number of unique nested objects.
  2081. for (length = stack.length; length--;) {
  2082. if (stack[length] === value) {
  2083. // Cyclic structures cannot be serialized by `JSON.stringify`.
  2084. throw TypeError();
  2085. }
  2086. }
  2087. // Add the object to the stack of traversed objects.
  2088. stack.push(value);
  2089. results = [];
  2090. // Save the current indentation level and indent one additional level.
  2091. prefix = indentation;
  2092. indentation += whitespace;
  2093. if (className == arrayClass) {
  2094. // Recursively serialize array elements.
  2095. for (index = 0, length = value.length; index < length; index++) {
  2096. element = serialize(index, value, callback, properties, whitespace, indentation, stack);
  2097. results.push(element === undef ? "null" : element);
  2098. }
  2099. result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
  2100. } else {
  2101. // Recursively serialize object members. Members are selected from
  2102. // either a user-specified list of property names, or the object
  2103. // itself.
  2104. forEach(properties || value, function (property) {
  2105. var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
  2106. if (element !== undef) {
  2107. // According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
  2108. // is not the empty string, let `member` {quote(property) + ":"}
  2109. // be the concatenation of `member` and the `space` character."
  2110. // The "`space` character" refers to the literal space
  2111. // character, not the `space` {width} argument provided to
  2112. // `JSON.stringify`.
  2113. results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
  2114. }
  2115. });
  2116. result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
  2117. }
  2118. // Remove the object from the traversed object stack.
  2119. stack.pop();
  2120. return result;
  2121. }
  2122. };
  2123. // Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
  2124. exports.stringify = function (source, filter, width) {
  2125. var whitespace, callback, properties, className;
  2126. if (objectTypes[typeof filter] && filter) {
  2127. if ((className = getClass.call(filter)) == functionClass) {
  2128. callback = filter;
  2129. } else if (className == arrayClass) {
  2130. // Convert the property names array into a makeshift set.
  2131. properties = {};
  2132. for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
  2133. }
  2134. }
  2135. if (width) {
  2136. if ((className = getClass.call(width)) == numberClass) {
  2137. // Convert the `width` to an integer and create a string containing
  2138. // `width` number of space characters.
  2139. if ((width -= width % 1) > 0) {
  2140. for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
  2141. }
  2142. } else if (className == stringClass) {
  2143. whitespace = width.length <= 10 ? width : width.slice(0, 10);
  2144. }
  2145. }
  2146. // Opera <= 7.54u2 discards the values associated with empty string keys
  2147. // (`""`) only if they are used directly within an object member list
  2148. // (e.g., `!("" in { "": 1})`).
  2149. return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
  2150. };
  2151. }
  2152. // Public: Parses a JSON source string.
  2153. if (!has("json-parse")) {
  2154. var fromCharCode = String.fromCharCode;
  2155. // Internal: A map of escaped control characters and their unescaped
  2156. // equivalents.
  2157. var Unescapes = {
  2158. 92: "\\",
  2159. 34: '"',
  2160. 47: "/",
  2161. 98: "\b",
  2162. 116: "\t",
  2163. 110: "\n",
  2164. 102: "\f",
  2165. 114: "\r"
  2166. };
  2167. // Internal: Stores the parser state.
  2168. var Index, Source;
  2169. // Internal: Resets the parser state and throws a `SyntaxError`.
  2170. var abort = function () {
  2171. Index = Source = null;
  2172. throw SyntaxError();
  2173. };
  2174. // Internal: Returns the next token, or `"$"` if the parser has reached
  2175. // the end of the source string. A token may be a string, number, `null`
  2176. // literal, or Boolean literal.
  2177. var lex = function () {
  2178. var source = Source, length = source.length, value, begin, position, isSigned, charCode;
  2179. while (Index < length) {
  2180. charCode = source.charCodeAt(Index);
  2181. switch (charCode) {
  2182. case 9: case 10: case 13: case 32:
  2183. // Skip whitespace tokens, including tabs, carriage returns, line
  2184. // feeds, and space characters.
  2185. Index++;
  2186. break;
  2187. case 123: case 125: case 91: case 93: case 58: case 44:
  2188. // Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
  2189. // the current position.
  2190. value = charIndexBuggy ? source.charAt(Index) : source[Index];
  2191. Index++;
  2192. return value;
  2193. case 34:
  2194. // `"` delimits a JSON string; advance to the next character and
  2195. // begin parsing the string. String tokens are prefixed with the
  2196. // sentinel `@` character to distinguish them from punctuators and
  2197. // end-of-string tokens.
  2198. for (value = "@", Index++; Index < length;) {
  2199. charCode = source.charCodeAt(Index);
  2200. if (charCode < 32) {
  2201. // Unescaped ASCII control characters (those with a code unit
  2202. // less than the space character) are not permitted.
  2203. abort();
  2204. } else if (charCode == 92) {
  2205. // A reverse solidus (`\`) marks the beginning of an escaped
  2206. // control character (including `"`, `\`, and `/`) or Unicode
  2207. // escape sequence.
  2208. charCode = source.charCodeAt(++Index);
  2209. switch (charCode) {
  2210. case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
  2211. // Revive escaped control characters.
  2212. value += Unescapes[charCode];
  2213. Index++;
  2214. break;
  2215. case 117:
  2216. // `\u` marks the beginning of a Unicode escape sequence.
  2217. // Advance to the first character and validate the
  2218. // four-digit code point.
  2219. begin = ++Index;
  2220. for (position = Index + 4; Index < position; Index++) {
  2221. charCode = source.charCodeAt(Index);
  2222. // A valid sequence comprises four hexdigits (case-
  2223. // insensitive) that form a single hexadecimal value.
  2224. if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
  2225. // Invalid Unicode escape sequence.
  2226. abort();
  2227. }
  2228. }
  2229. // Revive the escaped character.
  2230. value += fromCharCode("0x" + source.slice(begin, Index));
  2231. break;
  2232. default:
  2233. // Invalid escape sequence.
  2234. abort();
  2235. }
  2236. } else {
  2237. if (charCode == 34) {
  2238. // An unescaped double-quote character marks the end of the
  2239. // string.
  2240. break;
  2241. }
  2242. charCode = source.charCodeAt(Index);
  2243. begin = Index;
  2244. // Optimize for the common case where a string is valid.
  2245. while (charCode >= 32 && charCode != 92 && charCode != 34) {
  2246. charCode = source.charCodeAt(++Index);
  2247. }
  2248. // Append the string as-is.
  2249. value += source.slice(begin, Index);
  2250. }
  2251. }
  2252. if (source.charCodeAt(Index) == 34) {
  2253. // Advance to the next character and return the revived string.
  2254. Index++;
  2255. return value;
  2256. }
  2257. // Unterminated string.
  2258. abort();
  2259. default:
  2260. // Parse numbers and literals.
  2261. begin = Index;
  2262. // Advance past the negative sign, if one is specified.
  2263. if (charCode == 45) {
  2264. isSigned = true;
  2265. charCode = source.charCodeAt(++Index);
  2266. }
  2267. // Parse an integer or floating-point value.
  2268. if (charCode >= 48 && charCode <= 57) {
  2269. // Leading zeroes are interpreted as octal literals.
  2270. if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
  2271. // Illegal octal literal.
  2272. abort();
  2273. }
  2274. isSigned = false;
  2275. // Parse the integer component.
  2276. for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
  2277. // Floats cannot contain a leading decimal point; however, this
  2278. // case is already accounted for by the parser.
  2279. if (source.charCodeAt(Index) == 46) {
  2280. position = ++Index;
  2281. // Parse the decimal component.
  2282. for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  2283. if (position == Index) {
  2284. // Illegal trailing decimal.
  2285. abort();
  2286. }
  2287. Index = position;
  2288. }
  2289. // Parse exponents. The `e` denoting the exponent is
  2290. // case-insensitive.
  2291. charCode = source.charCodeAt(Index);
  2292. if (charCode == 101 || charCode == 69) {
  2293. charCode = source.charCodeAt(++Index);
  2294. // Skip past the sign following the exponent, if one is
  2295. // specified.
  2296. if (charCode == 43 || charCode == 45) {
  2297. Index++;
  2298. }
  2299. // Parse the exponential component.
  2300. for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
  2301. if (position == Index) {
  2302. // Illegal empty exponent.
  2303. abort();
  2304. }
  2305. Index = position;
  2306. }
  2307. // Coerce the parsed value to a JavaScript number.
  2308. return +source.slice(begin, Index);
  2309. }
  2310. // A negative sign may only precede numbers.
  2311. if (isSigned) {
  2312. abort();
  2313. }
  2314. // `true`, `false`, and `null` literals.
  2315. if (source.slice(Index, Index + 4) == "true") {
  2316. Index += 4;
  2317. return true;
  2318. } else if (source.slice(Index, Index + 5) == "false") {
  2319. Index += 5;
  2320. return false;
  2321. } else if (source.slice(Index, Index + 4) == "null") {
  2322. Index += 4;
  2323. return null;
  2324. }
  2325. // Unrecognized token.
  2326. abort();
  2327. }
  2328. }
  2329. // Return the sentinel `$` character if the parser has reached the end
  2330. // of the source string.
  2331. return "$";
  2332. };
  2333. // Internal: Parses a JSON `value` token.
  2334. var get = function (value) {
  2335. var results, hasMembers;
  2336. if (value == "$") {
  2337. // Unexpected end of input.
  2338. abort();
  2339. }
  2340. if (typeof value == "string") {
  2341. if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
  2342. // Remove the sentinel `@` character.
  2343. return value.slice(1);
  2344. }
  2345. // Parse object and array literals.
  2346. if (value == "[") {
  2347. // Parses a JSON array, returning a new JavaScript array.
  2348. results = [];
  2349. for (;; hasMembers || (hasMembers = true)) {
  2350. value = lex();
  2351. // A closing square bracket marks the end of the array literal.
  2352. if (value == "]") {
  2353. break;
  2354. }
  2355. // If the array literal contains elements, the current token
  2356. // should be a comma separating the previous element from the
  2357. // next.
  2358. if (hasMembers) {
  2359. if (value == ",") {
  2360. value = lex();
  2361. if (value == "]") {
  2362. // Unexpected trailing `,` in array literal.
  2363. abort();
  2364. }
  2365. } else {
  2366. // A `,` must separate each array element.
  2367. abort();
  2368. }
  2369. }
  2370. // Elisions and leading commas are not permitted.
  2371. if (value == ",") {
  2372. abort();
  2373. }
  2374. results.push(get(value));
  2375. }
  2376. return results;
  2377. } else if (value == "{") {
  2378. // Parses a JSON object, returning a new JavaScript object.
  2379. results = {};
  2380. for (;; hasMembers || (hasMembers = true)) {
  2381. value = lex();
  2382. // A closing curly brace marks the end of the object literal.
  2383. if (value == "}") {
  2384. break;
  2385. }
  2386. // If the object literal contains members, the current token
  2387. // should be a comma separator.
  2388. if (hasMembers) {
  2389. if (value == ",") {
  2390. value = lex();
  2391. if (value == "}") {
  2392. // Unexpected trailing `,` in object literal.
  2393. abort();
  2394. }
  2395. } else {
  2396. // A `,` must separate each object member.
  2397. abort();
  2398. }
  2399. }
  2400. // Leading commas are not permitted, object property names must be
  2401. // double-quoted strings, and a `:` must separate each property
  2402. // name and value.
  2403. if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
  2404. abort();
  2405. }
  2406. results[value.slice(1)] = get(lex());
  2407. }
  2408. return results;
  2409. }
  2410. // Unexpected token encountered.
  2411. abort();
  2412. }
  2413. return value;
  2414. };
  2415. // Internal: Updates a traversed object member.
  2416. var update = function (source, property, callback) {
  2417. var element = walk(source, property, callback);
  2418. if (element === undef) {
  2419. delete source[property];
  2420. } else {
  2421. source[property] = element;
  2422. }
  2423. };
  2424. // Internal: Recursively traverses a parsed JSON object, invoking the
  2425. // `callback` function for each value. This is an implementation of the
  2426. // `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
  2427. var walk = function (source, property, callback) {
  2428. var value = source[property], length;
  2429. if (typeof value == "object" && value) {
  2430. // `forEach` can't be used to traverse an array in Opera <= 8.54
  2431. // because its `Object#hasOwnProperty` implementation returns `false`
  2432. // for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
  2433. if (getClass.call(value) == arrayClass) {
  2434. for (length = value.length; length--;) {
  2435. update(value, length, callback);
  2436. }
  2437. } else {
  2438. forEach(value, function (property) {
  2439. update(value, property, callback);
  2440. });
  2441. }
  2442. }
  2443. return callback.call(source, property, value);
  2444. };
  2445. // Public: `JSON.parse`. See ES 5.1 section 15.12.2.
  2446. exports.parse = function (source, callback) {
  2447. var result, value;
  2448. Index = 0;
  2449. Source = "" + source;
  2450. result = get(lex());
  2451. // If a JSON string contains multiple tokens, it is invalid.
  2452. if (lex() != "$") {
  2453. abort();
  2454. }
  2455. // Reset the parser state.
  2456. Index = Source = null;
  2457. return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
  2458. };
  2459. }
  2460. }
  2461. exports["runInContext"] = runInContext;
  2462. return exports;
  2463. }
  2464. if (freeExports && !isLoader) {
  2465. // Export for CommonJS environments.
  2466. runInContext(root, freeExports);
  2467. } else {
  2468. // Export for web browsers and JavaScript engines.
  2469. var nativeJSON = root.JSON,
  2470. previousJSON = root["JSON3"],
  2471. isRestored = false;
  2472. var JSON3 = runInContext(root, (root["JSON3"] = {
  2473. // Public: Restores the original value of the global `JSON` object and
  2474. // returns a reference to the `JSON3` object.
  2475. "noConflict": function () {
  2476. if (!isRestored) {
  2477. isRestored = true;
  2478. root.JSON = nativeJSON;
  2479. root["JSON3"] = previousJSON;
  2480. nativeJSON = previousJSON = null;
  2481. }
  2482. return JSON3;
  2483. }
  2484. }));
  2485. root.JSON = {
  2486. "parse": JSON3.parse,
  2487. "stringify": JSON3.stringify
  2488. };
  2489. }
  2490. // Export for asynchronous module loaders.
  2491. if (isLoader) {
  2492. define(function () {
  2493. return JSON3;
  2494. });
  2495. }
  2496. }).call(this);
  2497. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12)(module), (function() { return this; }())))
  2498. /***/ },
  2499. /* 12 */
  2500. /***/ function(module, exports) {
  2501. module.exports = function(module) {
  2502. if(!module.webpackPolyfill) {
  2503. module.deprecate = function() {};
  2504. module.paths = [];
  2505. // module.parent = undefined by default
  2506. module.children = [];
  2507. module.webpackPolyfill = 1;
  2508. }
  2509. return module;
  2510. }
  2511. /***/ },
  2512. /* 13 */
  2513. /***/ function(module, exports) {
  2514. /**
  2515. * Expose `Emitter`.
  2516. */
  2517. module.exports = Emitter;
  2518. /**
  2519. * Initialize a new `Emitter`.
  2520. *
  2521. * @api public
  2522. */
  2523. function Emitter(obj) {
  2524. if (obj) return mixin(obj);
  2525. };
  2526. /**
  2527. * Mixin the emitter properties.
  2528. *
  2529. * @param {Object} obj
  2530. * @return {Object}
  2531. * @api private
  2532. */
  2533. function mixin(obj) {
  2534. for (var key in Emitter.prototype) {
  2535. obj[key] = Emitter.prototype[key];
  2536. }
  2537. return obj;
  2538. }
  2539. /**
  2540. * Listen on the given `event` with `fn`.
  2541. *
  2542. * @param {String} event
  2543. * @param {Function} fn
  2544. * @return {Emitter}
  2545. * @api public
  2546. */
  2547. Emitter.prototype.on =
  2548. Emitter.prototype.addEventListener = function(event, fn){
  2549. this._callbacks = this._callbacks || {};
  2550. (this._callbacks[event] = this._callbacks[event] || [])
  2551. .push(fn);
  2552. return this;
  2553. };
  2554. /**
  2555. * Adds an `event` listener that will be invoked a single
  2556. * time then automatically removed.
  2557. *
  2558. * @param {String} event
  2559. * @param {Function} fn
  2560. * @return {Emitter}
  2561. * @api public
  2562. */
  2563. Emitter.prototype.once = function(event, fn){
  2564. var self = this;
  2565. this._callbacks = this._callbacks || {};
  2566. function on() {
  2567. self.off(event, on);
  2568. fn.apply(this, arguments);
  2569. }
  2570. on.fn = fn;
  2571. this.on(event, on);
  2572. return this;
  2573. };
  2574. /**
  2575. * Remove the given callback for `event` or all
  2576. * registered callbacks.
  2577. *
  2578. * @param {String} event
  2579. * @param {Function} fn
  2580. * @return {Emitter}
  2581. * @api public
  2582. */
  2583. Emitter.prototype.off =
  2584. Emitter.prototype.removeListener =
  2585. Emitter.prototype.removeAllListeners =
  2586. Emitter.prototype.removeEventListener = function(event, fn){
  2587. this._callbacks = this._callbacks || {};
  2588. // all
  2589. if (0 == arguments.length) {
  2590. this._callbacks = {};
  2591. return this;
  2592. }
  2593. // specific event
  2594. var callbacks = this._callbacks[event];
  2595. if (!callbacks) return this;
  2596. // remove all handlers
  2597. if (1 == arguments.length) {
  2598. delete this._callbacks[event];
  2599. return this;
  2600. }
  2601. // remove specific handler
  2602. var cb;
  2603. for (var i = 0; i < callbacks.length; i++) {
  2604. cb = callbacks[i];
  2605. if (cb === fn || cb.fn === fn) {
  2606. callbacks.splice(i, 1);
  2607. break;
  2608. }
  2609. }
  2610. return this;
  2611. };
  2612. /**
  2613. * Emit `event` with the given args.
  2614. *
  2615. * @param {String} event
  2616. * @param {Mixed} ...
  2617. * @return {Emitter}
  2618. */
  2619. Emitter.prototype.emit = function(event){
  2620. this._callbacks = this._callbacks || {};
  2621. var args = [].slice.call(arguments, 1)
  2622. , callbacks = this._callbacks[event];
  2623. if (callbacks) {
  2624. callbacks = callbacks.slice(0);
  2625. for (var i = 0, len = callbacks.length; i < len; ++i) {
  2626. callbacks[i].apply(this, args);
  2627. }
  2628. }
  2629. return this;
  2630. };
  2631. /**
  2632. * Return array of callbacks for `event`.
  2633. *
  2634. * @param {String} event
  2635. * @return {Array}
  2636. * @api public
  2637. */
  2638. Emitter.prototype.listeners = function(event){
  2639. this._callbacks = this._callbacks || {};
  2640. return this._callbacks[event] || [];
  2641. };
  2642. /**
  2643. * Check if this emitter has `event` handlers.
  2644. *
  2645. * @param {String} event
  2646. * @return {Boolean}
  2647. * @api public
  2648. */
  2649. Emitter.prototype.hasListeners = function(event){
  2650. return !! this.listeners(event).length;
  2651. };
  2652. /***/ },
  2653. /* 14 */
  2654. /***/ function(module, exports, __webpack_require__) {
  2655. /* WEBPACK VAR INJECTION */(function(global) {/*global Blob,File*/
  2656. /**
  2657. * Module requirements
  2658. */
  2659. var isArray = __webpack_require__(15);
  2660. var isBuf = __webpack_require__(16);
  2661. /**
  2662. * Replaces every Buffer | ArrayBuffer in packet with a numbered placeholder.
  2663. * Anything with blobs or files should be fed through removeBlobs before coming
  2664. * here.
  2665. *
  2666. * @param {Object} packet - socket.io event packet
  2667. * @return {Object} with deconstructed packet and list of buffers
  2668. * @api public
  2669. */
  2670. exports.deconstructPacket = function(packet){
  2671. var buffers = [];
  2672. var packetData = packet.data;
  2673. function _deconstructPacket(data) {
  2674. if (!data) return data;
  2675. if (isBuf(data)) {
  2676. var placeholder = { _placeholder: true, num: buffers.length };
  2677. buffers.push(data);
  2678. return placeholder;
  2679. } else if (isArray(data)) {
  2680. var newData = new Array(data.length);
  2681. for (var i = 0; i < data.length; i++) {
  2682. newData[i] = _deconstructPacket(data[i]);
  2683. }
  2684. return newData;
  2685. } else if ('object' == typeof data && !(data instanceof Date)) {
  2686. var newData = {};
  2687. for (var key in data) {
  2688. newData[key] = _deconstructPacket(data[key]);
  2689. }
  2690. return newData;
  2691. }
  2692. return data;
  2693. }
  2694. var pack = packet;
  2695. pack.data = _deconstructPacket(packetData);
  2696. pack.attachments = buffers.length; // number of binary 'attachments'
  2697. return {packet: pack, buffers: buffers};
  2698. };
  2699. /**
  2700. * Reconstructs a binary packet from its placeholder packet and buffers
  2701. *
  2702. * @param {Object} packet - event packet with placeholders
  2703. * @param {Array} buffers - binary buffers to put in placeholder positions
  2704. * @return {Object} reconstructed packet
  2705. * @api public
  2706. */
  2707. exports.reconstructPacket = function(packet, buffers) {
  2708. var curPlaceHolder = 0;
  2709. function _reconstructPacket(data) {
  2710. if (data && data._placeholder) {
  2711. var buf = buffers[data.num]; // appropriate buffer (should be natural order anyway)
  2712. return buf;
  2713. } else if (isArray(data)) {
  2714. for (var i = 0; i < data.length; i++) {
  2715. data[i] = _reconstructPacket(data[i]);
  2716. }
  2717. return data;
  2718. } else if (data && 'object' == typeof data) {
  2719. for (var key in data) {
  2720. data[key] = _reconstructPacket(data[key]);
  2721. }
  2722. return data;
  2723. }
  2724. return data;
  2725. }
  2726. packet.data = _reconstructPacket(packet.data);
  2727. packet.attachments = undefined; // no longer useful
  2728. return packet;
  2729. };
  2730. /**
  2731. * Asynchronously removes Blobs or Files from data via
  2732. * FileReader's readAsArrayBuffer method. Used before encoding
  2733. * data as msgpack. Calls callback with the blobless data.
  2734. *
  2735. * @param {Object} data
  2736. * @param {Function} callback
  2737. * @api private
  2738. */
  2739. exports.removeBlobs = function(data, callback) {
  2740. function _removeBlobs(obj, curKey, containingObject) {
  2741. if (!obj) return obj;
  2742. // convert any blob
  2743. if ((global.Blob && obj instanceof Blob) ||
  2744. (global.File && obj instanceof File)) {
  2745. pendingBlobs++;
  2746. // async filereader
  2747. var fileReader = new FileReader();
  2748. fileReader.onload = function() { // this.result == arraybuffer
  2749. if (containingObject) {
  2750. containingObject[curKey] = this.result;
  2751. }
  2752. else {
  2753. bloblessData = this.result;
  2754. }
  2755. // if nothing pending its callback time
  2756. if(! --pendingBlobs) {
  2757. callback(bloblessData);
  2758. }
  2759. };
  2760. fileReader.readAsArrayBuffer(obj); // blob -> arraybuffer
  2761. } else if (isArray(obj)) { // handle array
  2762. for (var i = 0; i < obj.length; i++) {
  2763. _removeBlobs(obj[i], i, obj);
  2764. }
  2765. } else if (obj && 'object' == typeof obj && !isBuf(obj)) { // and object
  2766. for (var key in obj) {
  2767. _removeBlobs(obj[key], key, obj);
  2768. }
  2769. }
  2770. }
  2771. var pendingBlobs = 0;
  2772. var bloblessData = data;
  2773. _removeBlobs(bloblessData);
  2774. if (!pendingBlobs) {
  2775. callback(bloblessData);
  2776. }
  2777. };
  2778. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  2779. /***/ },
  2780. /* 15 */
  2781. /***/ function(module, exports) {
  2782. module.exports = Array.isArray || function (arr) {
  2783. return Object.prototype.toString.call(arr) == '[object Array]';
  2784. };
  2785. /***/ },
  2786. /* 16 */
  2787. /***/ function(module, exports) {
  2788. /* WEBPACK VAR INJECTION */(function(global) {
  2789. module.exports = isBuf;
  2790. /**
  2791. * Returns true if obj is a buffer or an arraybuffer.
  2792. *
  2793. * @api private
  2794. */
  2795. function isBuf(obj) {
  2796. return (global.Buffer && global.Buffer.isBuffer(obj)) ||
  2797. (global.ArrayBuffer && obj instanceof ArrayBuffer);
  2798. }
  2799. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  2800. /***/ },
  2801. /* 17 */
  2802. /***/ function(module, exports, __webpack_require__) {
  2803. 'use strict';
  2804. 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; };
  2805. /**
  2806. * Module dependencies.
  2807. */
  2808. var eio = __webpack_require__(18);
  2809. var Socket = __webpack_require__(44);
  2810. var Emitter = __webpack_require__(35);
  2811. var parser = __webpack_require__(7);
  2812. var on = __webpack_require__(46);
  2813. var bind = __webpack_require__(47);
  2814. var debug = __webpack_require__(3)('socket.io-client:manager');
  2815. var indexOf = __webpack_require__(42);
  2816. var Backoff = __webpack_require__(48);
  2817. /**
  2818. * IE6+ hasOwnProperty
  2819. */
  2820. var has = Object.prototype.hasOwnProperty;
  2821. /**
  2822. * Module exports
  2823. */
  2824. module.exports = Manager;
  2825. /**
  2826. * `Manager` constructor.
  2827. *
  2828. * @param {String} engine instance or engine uri/opts
  2829. * @param {Object} options
  2830. * @api public
  2831. */
  2832. function Manager(uri, opts) {
  2833. if (!(this instanceof Manager)) return new Manager(uri, opts);
  2834. if (uri && 'object' === (typeof uri === 'undefined' ? 'undefined' : _typeof(uri))) {
  2835. opts = uri;
  2836. uri = undefined;
  2837. }
  2838. opts = opts || {};
  2839. opts.path = opts.path || '/socket.io';
  2840. this.nsps = {};
  2841. this.subs = [];
  2842. this.opts = opts;
  2843. this.reconnection(opts.reconnection !== false);
  2844. this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);
  2845. this.reconnectionDelay(opts.reconnectionDelay || 1000);
  2846. this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);
  2847. this.randomizationFactor(opts.randomizationFactor || 0.5);
  2848. this.backoff = new Backoff({
  2849. min: this.reconnectionDelay(),
  2850. max: this.reconnectionDelayMax(),
  2851. jitter: this.randomizationFactor()
  2852. });
  2853. this.timeout(null == opts.timeout ? 20000 : opts.timeout);
  2854. this.readyState = 'closed';
  2855. this.uri = uri;
  2856. this.connecting = [];
  2857. this.lastPing = null;
  2858. this.encoding = false;
  2859. this.packetBuffer = [];
  2860. this.encoder = new parser.Encoder();
  2861. this.decoder = new parser.Decoder();
  2862. this.autoConnect = opts.autoConnect !== false;
  2863. if (this.autoConnect) this.open();
  2864. }
  2865. /**
  2866. * Propagate given event to sockets and emit on `this`
  2867. *
  2868. * @api private
  2869. */
  2870. Manager.prototype.emitAll = function () {
  2871. this.emit.apply(this, arguments);
  2872. for (var nsp in this.nsps) {
  2873. if (has.call(this.nsps, nsp)) {
  2874. this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
  2875. }
  2876. }
  2877. };
  2878. /**
  2879. * Update `socket.id` of all sockets
  2880. *
  2881. * @api private
  2882. */
  2883. Manager.prototype.updateSocketIds = function () {
  2884. for (var nsp in this.nsps) {
  2885. if (has.call(this.nsps, nsp)) {
  2886. this.nsps[nsp].id = this.engine.id;
  2887. }
  2888. }
  2889. };
  2890. /**
  2891. * Mix in `Emitter`.
  2892. */
  2893. Emitter(Manager.prototype);
  2894. /**
  2895. * Sets the `reconnection` config.
  2896. *
  2897. * @param {Boolean} true/false if it should automatically reconnect
  2898. * @return {Manager} self or value
  2899. * @api public
  2900. */
  2901. Manager.prototype.reconnection = function (v) {
  2902. if (!arguments.length) return this._reconnection;
  2903. this._reconnection = !!v;
  2904. return this;
  2905. };
  2906. /**
  2907. * Sets the reconnection attempts config.
  2908. *
  2909. * @param {Number} max reconnection attempts before giving up
  2910. * @return {Manager} self or value
  2911. * @api public
  2912. */
  2913. Manager.prototype.reconnectionAttempts = function (v) {
  2914. if (!arguments.length) return this._reconnectionAttempts;
  2915. this._reconnectionAttempts = v;
  2916. return this;
  2917. };
  2918. /**
  2919. * Sets the delay between reconnections.
  2920. *
  2921. * @param {Number} delay
  2922. * @return {Manager} self or value
  2923. * @api public
  2924. */
  2925. Manager.prototype.reconnectionDelay = function (v) {
  2926. if (!arguments.length) return this._reconnectionDelay;
  2927. this._reconnectionDelay = v;
  2928. this.backoff && this.backoff.setMin(v);
  2929. return this;
  2930. };
  2931. Manager.prototype.randomizationFactor = function (v) {
  2932. if (!arguments.length) return this._randomizationFactor;
  2933. this._randomizationFactor = v;
  2934. this.backoff && this.backoff.setJitter(v);
  2935. return this;
  2936. };
  2937. /**
  2938. * Sets the maximum delay between reconnections.
  2939. *
  2940. * @param {Number} delay
  2941. * @return {Manager} self or value
  2942. * @api public
  2943. */
  2944. Manager.prototype.reconnectionDelayMax = function (v) {
  2945. if (!arguments.length) return this._reconnectionDelayMax;
  2946. this._reconnectionDelayMax = v;
  2947. this.backoff && this.backoff.setMax(v);
  2948. return this;
  2949. };
  2950. /**
  2951. * Sets the connection timeout. `false` to disable
  2952. *
  2953. * @return {Manager} self or value
  2954. * @api public
  2955. */
  2956. Manager.prototype.timeout = function (v) {
  2957. if (!arguments.length) return this._timeout;
  2958. this._timeout = v;
  2959. return this;
  2960. };
  2961. /**
  2962. * Starts trying to reconnect if reconnection is enabled and we have not
  2963. * started reconnecting yet
  2964. *
  2965. * @api private
  2966. */
  2967. Manager.prototype.maybeReconnectOnOpen = function () {
  2968. // Only try to reconnect if it's the first time we're connecting
  2969. if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) {
  2970. // keeps reconnection from firing twice for the same reconnection loop
  2971. this.reconnect();
  2972. }
  2973. };
  2974. /**
  2975. * Sets the current transport `socket`.
  2976. *
  2977. * @param {Function} optional, callback
  2978. * @return {Manager} self
  2979. * @api public
  2980. */
  2981. Manager.prototype.open = Manager.prototype.connect = function (fn, opts) {
  2982. debug('readyState %s', this.readyState);
  2983. if (~this.readyState.indexOf('open')) return this;
  2984. debug('opening %s', this.uri);
  2985. this.engine = eio(this.uri, this.opts);
  2986. var socket = this.engine;
  2987. var self = this;
  2988. this.readyState = 'opening';
  2989. this.skipReconnect = false;
  2990. // emit `open`
  2991. var openSub = on(socket, 'open', function () {
  2992. self.onopen();
  2993. fn && fn();
  2994. });
  2995. // emit `connect_error`
  2996. var errorSub = on(socket, 'error', function (data) {
  2997. debug('connect_error');
  2998. self.cleanup();
  2999. self.readyState = 'closed';
  3000. self.emitAll('connect_error', data);
  3001. if (fn) {
  3002. var err = new Error('Connection error');
  3003. err.data = data;
  3004. fn(err);
  3005. } else {
  3006. // Only do this if there is no fn to handle the error
  3007. self.maybeReconnectOnOpen();
  3008. }
  3009. });
  3010. // emit `connect_timeout`
  3011. if (false !== this._timeout) {
  3012. var timeout = this._timeout;
  3013. debug('connect attempt will timeout after %d', timeout);
  3014. // set timer
  3015. var timer = setTimeout(function () {
  3016. debug('connect attempt timed out after %d', timeout);
  3017. openSub.destroy();
  3018. socket.close();
  3019. socket.emit('error', 'timeout');
  3020. self.emitAll('connect_timeout', timeout);
  3021. }, timeout);
  3022. this.subs.push({
  3023. destroy: function destroy() {
  3024. clearTimeout(timer);
  3025. }
  3026. });
  3027. }
  3028. this.subs.push(openSub);
  3029. this.subs.push(errorSub);
  3030. return this;
  3031. };
  3032. /**
  3033. * Called upon transport open.
  3034. *
  3035. * @api private
  3036. */
  3037. Manager.prototype.onopen = function () {
  3038. debug('open');
  3039. // clear old subs
  3040. this.cleanup();
  3041. // mark as open
  3042. this.readyState = 'open';
  3043. this.emit('open');
  3044. // add new subs
  3045. var socket = this.engine;
  3046. this.subs.push(on(socket, 'data', bind(this, 'ondata')));
  3047. this.subs.push(on(socket, 'ping', bind(this, 'onping')));
  3048. this.subs.push(on(socket, 'pong', bind(this, 'onpong')));
  3049. this.subs.push(on(socket, 'error', bind(this, 'onerror')));
  3050. this.subs.push(on(socket, 'close', bind(this, 'onclose')));
  3051. this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded')));
  3052. };
  3053. /**
  3054. * Called upon a ping.
  3055. *
  3056. * @api private
  3057. */
  3058. Manager.prototype.onping = function () {
  3059. this.lastPing = new Date();
  3060. this.emitAll('ping');
  3061. };
  3062. /**
  3063. * Called upon a packet.
  3064. *
  3065. * @api private
  3066. */
  3067. Manager.prototype.onpong = function () {
  3068. this.emitAll('pong', new Date() - this.lastPing);
  3069. };
  3070. /**
  3071. * Called with data.
  3072. *
  3073. * @api private
  3074. */
  3075. Manager.prototype.ondata = function (data) {
  3076. this.decoder.add(data);
  3077. };
  3078. /**
  3079. * Called when parser fully decodes a packet.
  3080. *
  3081. * @api private
  3082. */
  3083. Manager.prototype.ondecoded = function (packet) {
  3084. this.emit('packet', packet);
  3085. };
  3086. /**
  3087. * Called upon socket error.
  3088. *
  3089. * @api private
  3090. */
  3091. Manager.prototype.onerror = function (err) {
  3092. debug('error', err);
  3093. this.emitAll('error', err);
  3094. };
  3095. /**
  3096. * Creates a new socket for the given `nsp`.
  3097. *
  3098. * @return {Socket}
  3099. * @api public
  3100. */
  3101. Manager.prototype.socket = function (nsp, opts) {
  3102. var socket = this.nsps[nsp];
  3103. if (!socket) {
  3104. socket = new Socket(this, nsp, opts);
  3105. this.nsps[nsp] = socket;
  3106. var self = this;
  3107. socket.on('connecting', onConnecting);
  3108. socket.on('connect', function () {
  3109. socket.id = self.engine.id;
  3110. });
  3111. if (this.autoConnect) {
  3112. // manually call here since connecting evnet is fired before listening
  3113. onConnecting();
  3114. }
  3115. }
  3116. function onConnecting() {
  3117. if (!~indexOf(self.connecting, socket)) {
  3118. self.connecting.push(socket);
  3119. }
  3120. }
  3121. return socket;
  3122. };
  3123. /**
  3124. * Called upon a socket close.
  3125. *
  3126. * @param {Socket} socket
  3127. */
  3128. Manager.prototype.destroy = function (socket) {
  3129. var index = indexOf(this.connecting, socket);
  3130. if (~index) this.connecting.splice(index, 1);
  3131. if (this.connecting.length) return;
  3132. this.close();
  3133. };
  3134. /**
  3135. * Writes a packet.
  3136. *
  3137. * @param {Object} packet
  3138. * @api private
  3139. */
  3140. Manager.prototype.packet = function (packet) {
  3141. debug('writing packet %j', packet);
  3142. var self = this;
  3143. if (packet.query && packet.type === 0) packet.nsp += '?' + packet.query;
  3144. if (!self.encoding) {
  3145. // encode, then write to engine with result
  3146. self.encoding = true;
  3147. this.encoder.encode(packet, function (encodedPackets) {
  3148. for (var i = 0; i < encodedPackets.length; i++) {
  3149. self.engine.write(encodedPackets[i], packet.options);
  3150. }
  3151. self.encoding = false;
  3152. self.processPacketQueue();
  3153. });
  3154. } else {
  3155. // add packet to the queue
  3156. self.packetBuffer.push(packet);
  3157. }
  3158. };
  3159. /**
  3160. * If packet buffer is non-empty, begins encoding the
  3161. * next packet in line.
  3162. *
  3163. * @api private
  3164. */
  3165. Manager.prototype.processPacketQueue = function () {
  3166. if (this.packetBuffer.length > 0 && !this.encoding) {
  3167. var pack = this.packetBuffer.shift();
  3168. this.packet(pack);
  3169. }
  3170. };
  3171. /**
  3172. * Clean up transport subscriptions and packet buffer.
  3173. *
  3174. * @api private
  3175. */
  3176. Manager.prototype.cleanup = function () {
  3177. debug('cleanup');
  3178. var subsLength = this.subs.length;
  3179. for (var i = 0; i < subsLength; i++) {
  3180. var sub = this.subs.shift();
  3181. sub.destroy();
  3182. }
  3183. this.packetBuffer = [];
  3184. this.encoding = false;
  3185. this.lastPing = null;
  3186. this.decoder.destroy();
  3187. };
  3188. /**
  3189. * Close the current socket.
  3190. *
  3191. * @api private
  3192. */
  3193. Manager.prototype.close = Manager.prototype.disconnect = function () {
  3194. debug('disconnect');
  3195. this.skipReconnect = true;
  3196. this.reconnecting = false;
  3197. if ('opening' === this.readyState) {
  3198. // `onclose` will not fire because
  3199. // an open event never happened
  3200. this.cleanup();
  3201. }
  3202. this.backoff.reset();
  3203. this.readyState = 'closed';
  3204. if (this.engine) this.engine.close();
  3205. };
  3206. /**
  3207. * Called upon engine close.
  3208. *
  3209. * @api private
  3210. */
  3211. Manager.prototype.onclose = function (reason) {
  3212. debug('onclose');
  3213. this.cleanup();
  3214. this.backoff.reset();
  3215. this.readyState = 'closed';
  3216. this.emit('close', reason);
  3217. if (this._reconnection && !this.skipReconnect) {
  3218. this.reconnect();
  3219. }
  3220. };
  3221. /**
  3222. * Attempt a reconnection.
  3223. *
  3224. * @api private
  3225. */
  3226. Manager.prototype.reconnect = function () {
  3227. if (this.reconnecting || this.skipReconnect) return this;
  3228. var self = this;
  3229. if (this.backoff.attempts >= this._reconnectionAttempts) {
  3230. debug('reconnect failed');
  3231. this.backoff.reset();
  3232. this.emitAll('reconnect_failed');
  3233. this.reconnecting = false;
  3234. } else {
  3235. var delay = this.backoff.duration();
  3236. debug('will wait %dms before reconnect attempt', delay);
  3237. this.reconnecting = true;
  3238. var timer = setTimeout(function () {
  3239. if (self.skipReconnect) return;
  3240. debug('attempting reconnect');
  3241. self.emitAll('reconnect_attempt', self.backoff.attempts);
  3242. self.emitAll('reconnecting', self.backoff.attempts);
  3243. // check again for the case socket closed in above events
  3244. if (self.skipReconnect) return;
  3245. self.open(function (err) {
  3246. if (err) {
  3247. debug('reconnect attempt error');
  3248. self.reconnecting = false;
  3249. self.reconnect();
  3250. self.emitAll('reconnect_error', err.data);
  3251. } else {
  3252. debug('reconnect success');
  3253. self.onreconnect();
  3254. }
  3255. });
  3256. }, delay);
  3257. this.subs.push({
  3258. destroy: function destroy() {
  3259. clearTimeout(timer);
  3260. }
  3261. });
  3262. }
  3263. };
  3264. /**
  3265. * Called upon successful reconnect.
  3266. *
  3267. * @api private
  3268. */
  3269. Manager.prototype.onreconnect = function () {
  3270. var attempt = this.backoff.attempts;
  3271. this.reconnecting = false;
  3272. this.backoff.reset();
  3273. this.updateSocketIds();
  3274. this.emitAll('reconnect', attempt);
  3275. };
  3276. /***/ },
  3277. /* 18 */
  3278. /***/ function(module, exports, __webpack_require__) {
  3279. module.exports = __webpack_require__(19);
  3280. /***/ },
  3281. /* 19 */
  3282. /***/ function(module, exports, __webpack_require__) {
  3283. module.exports = __webpack_require__(20);
  3284. /**
  3285. * Exports parser
  3286. *
  3287. * @api public
  3288. *
  3289. */
  3290. module.exports.parser = __webpack_require__(27);
  3291. /***/ },
  3292. /* 20 */
  3293. /***/ function(module, exports, __webpack_require__) {
  3294. /* WEBPACK VAR INJECTION */(function(global) {/**
  3295. * Module dependencies.
  3296. */
  3297. var transports = __webpack_require__(21);
  3298. var Emitter = __webpack_require__(35);
  3299. var debug = __webpack_require__(3)('engine.io-client:socket');
  3300. var index = __webpack_require__(42);
  3301. var parser = __webpack_require__(27);
  3302. var parseuri = __webpack_require__(2);
  3303. var parsejson = __webpack_require__(43);
  3304. var parseqs = __webpack_require__(36);
  3305. /**
  3306. * Module exports.
  3307. */
  3308. module.exports = Socket;
  3309. /**
  3310. * Socket constructor.
  3311. *
  3312. * @param {String|Object} uri or options
  3313. * @param {Object} options
  3314. * @api public
  3315. */
  3316. function Socket (uri, opts) {
  3317. if (!(this instanceof Socket)) return new Socket(uri, opts);
  3318. opts = opts || {};
  3319. if (uri && 'object' === typeof uri) {
  3320. opts = uri;
  3321. uri = null;
  3322. }
  3323. if (uri) {
  3324. uri = parseuri(uri);
  3325. opts.hostname = uri.host;
  3326. opts.secure = uri.protocol === 'https' || uri.protocol === 'wss';
  3327. opts.port = uri.port;
  3328. if (uri.query) opts.query = uri.query;
  3329. } else if (opts.host) {
  3330. opts.hostname = parseuri(opts.host).host;
  3331. }
  3332. this.secure = null != opts.secure ? opts.secure
  3333. : (global.location && 'https:' === location.protocol);
  3334. if (opts.hostname && !opts.port) {
  3335. // if no port is specified manually, use the protocol default
  3336. opts.port = this.secure ? '443' : '80';
  3337. }
  3338. this.agent = opts.agent || false;
  3339. this.hostname = opts.hostname ||
  3340. (global.location ? location.hostname : 'localhost');
  3341. this.port = opts.port || (global.location && location.port
  3342. ? location.port
  3343. : (this.secure ? 443 : 80));
  3344. this.query = opts.query || {};
  3345. if ('string' === typeof this.query) this.query = parseqs.decode(this.query);
  3346. this.upgrade = false !== opts.upgrade;
  3347. this.path = (opts.path || '/engine.io').replace(/\/$/, '') + '/';
  3348. this.forceJSONP = !!opts.forceJSONP;
  3349. this.jsonp = false !== opts.jsonp;
  3350. this.forceBase64 = !!opts.forceBase64;
  3351. this.enablesXDR = !!opts.enablesXDR;
  3352. this.timestampParam = opts.timestampParam || 't';
  3353. this.timestampRequests = opts.timestampRequests;
  3354. this.transports = opts.transports || ['polling', 'websocket'];
  3355. this.readyState = '';
  3356. this.writeBuffer = [];
  3357. this.prevBufferLen = 0;
  3358. this.policyPort = opts.policyPort || 843;
  3359. this.rememberUpgrade = opts.rememberUpgrade || false;
  3360. this.binaryType = null;
  3361. this.onlyBinaryUpgrades = opts.onlyBinaryUpgrades;
  3362. this.perMessageDeflate = false !== opts.perMessageDeflate ? (opts.perMessageDeflate || {}) : false;
  3363. if (true === this.perMessageDeflate) this.perMessageDeflate = {};
  3364. if (this.perMessageDeflate && null == this.perMessageDeflate.threshold) {
  3365. this.perMessageDeflate.threshold = 1024;
  3366. }
  3367. // SSL options for Node.js client
  3368. this.pfx = opts.pfx || null;
  3369. this.key = opts.key || null;
  3370. this.passphrase = opts.passphrase || null;
  3371. this.cert = opts.cert || null;
  3372. this.ca = opts.ca || null;
  3373. this.ciphers = opts.ciphers || null;
  3374. this.rejectUnauthorized = opts.rejectUnauthorized === undefined ? null : opts.rejectUnauthorized;
  3375. this.forceNode = !!opts.forceNode;
  3376. // other options for Node.js client
  3377. var freeGlobal = typeof global === 'object' && global;
  3378. if (freeGlobal.global === freeGlobal) {
  3379. if (opts.extraHeaders && Object.keys(opts.extraHeaders).length > 0) {
  3380. this.extraHeaders = opts.extraHeaders;
  3381. }
  3382. if (opts.localAddress) {
  3383. this.localAddress = opts.localAddress;
  3384. }
  3385. }
  3386. // set on handshake
  3387. this.id = null;
  3388. this.upgrades = null;
  3389. this.pingInterval = null;
  3390. this.pingTimeout = null;
  3391. // set on heartbeat
  3392. this.pingIntervalTimer = null;
  3393. this.pingTimeoutTimer = null;
  3394. this.open();
  3395. }
  3396. Socket.priorWebsocketSuccess = false;
  3397. /**
  3398. * Mix in `Emitter`.
  3399. */
  3400. Emitter(Socket.prototype);
  3401. /**
  3402. * Protocol version.
  3403. *
  3404. * @api public
  3405. */
  3406. Socket.protocol = parser.protocol; // this is an int
  3407. /**
  3408. * Expose deps for legacy compatibility
  3409. * and standalone browser access.
  3410. */
  3411. Socket.Socket = Socket;
  3412. Socket.Transport = __webpack_require__(26);
  3413. Socket.transports = __webpack_require__(21);
  3414. Socket.parser = __webpack_require__(27);
  3415. /**
  3416. * Creates transport of the given type.
  3417. *
  3418. * @param {String} transport name
  3419. * @return {Transport}
  3420. * @api private
  3421. */
  3422. Socket.prototype.createTransport = function (name) {
  3423. debug('creating transport "%s"', name);
  3424. var query = clone(this.query);
  3425. // append engine.io protocol identifier
  3426. query.EIO = parser.protocol;
  3427. // transport name
  3428. query.transport = name;
  3429. // session id if we already have one
  3430. if (this.id) query.sid = this.id;
  3431. var transport = new transports[name]({
  3432. agent: this.agent,
  3433. hostname: this.hostname,
  3434. port: this.port,
  3435. secure: this.secure,
  3436. path: this.path,
  3437. query: query,
  3438. forceJSONP: this.forceJSONP,
  3439. jsonp: this.jsonp,
  3440. forceBase64: this.forceBase64,
  3441. enablesXDR: this.enablesXDR,
  3442. timestampRequests: this.timestampRequests,
  3443. timestampParam: this.timestampParam,
  3444. policyPort: this.policyPort,
  3445. socket: this,
  3446. pfx: this.pfx,
  3447. key: this.key,
  3448. passphrase: this.passphrase,
  3449. cert: this.cert,
  3450. ca: this.ca,
  3451. ciphers: this.ciphers,
  3452. rejectUnauthorized: this.rejectUnauthorized,
  3453. perMessageDeflate: this.perMessageDeflate,
  3454. extraHeaders: this.extraHeaders,
  3455. forceNode: this.forceNode,
  3456. localAddress: this.localAddress
  3457. });
  3458. return transport;
  3459. };
  3460. function clone (obj) {
  3461. var o = {};
  3462. for (var i in obj) {
  3463. if (obj.hasOwnProperty(i)) {
  3464. o[i] = obj[i];
  3465. }
  3466. }
  3467. return o;
  3468. }
  3469. /**
  3470. * Initializes transport to use and starts probe.
  3471. *
  3472. * @api private
  3473. */
  3474. Socket.prototype.open = function () {
  3475. var transport;
  3476. if (this.rememberUpgrade && Socket.priorWebsocketSuccess && this.transports.indexOf('websocket') !== -1) {
  3477. transport = 'websocket';
  3478. } else if (0 === this.transports.length) {
  3479. // Emit error on next tick so it can be listened to
  3480. var self = this;
  3481. setTimeout(function () {
  3482. self.emit('error', 'No transports available');
  3483. }, 0);
  3484. return;
  3485. } else {
  3486. transport = this.transports[0];
  3487. }
  3488. this.readyState = 'opening';
  3489. // Retry with the next transport if the transport is disabled (jsonp: false)
  3490. try {
  3491. transport = this.createTransport(transport);
  3492. } catch (e) {
  3493. this.transports.shift();
  3494. this.open();
  3495. return;
  3496. }
  3497. transport.open();
  3498. this.setTransport(transport);
  3499. };
  3500. /**
  3501. * Sets the current transport. Disables the existing one (if any).
  3502. *
  3503. * @api private
  3504. */
  3505. Socket.prototype.setTransport = function (transport) {
  3506. debug('setting transport %s', transport.name);
  3507. var self = this;
  3508. if (this.transport) {
  3509. debug('clearing existing transport %s', this.transport.name);
  3510. this.transport.removeAllListeners();
  3511. }
  3512. // set up transport
  3513. this.transport = transport;
  3514. // set up transport listeners
  3515. transport
  3516. .on('drain', function () {
  3517. self.onDrain();
  3518. })
  3519. .on('packet', function (packet) {
  3520. self.onPacket(packet);
  3521. })
  3522. .on('error', function (e) {
  3523. self.onError(e);
  3524. })
  3525. .on('close', function () {
  3526. self.onClose('transport close');
  3527. });
  3528. };
  3529. /**
  3530. * Probes a transport.
  3531. *
  3532. * @param {String} transport name
  3533. * @api private
  3534. */
  3535. Socket.prototype.probe = function (name) {
  3536. debug('probing transport "%s"', name);
  3537. var transport = this.createTransport(name, { probe: 1 });
  3538. var failed = false;
  3539. var self = this;
  3540. Socket.priorWebsocketSuccess = false;
  3541. function onTransportOpen () {
  3542. if (self.onlyBinaryUpgrades) {
  3543. var upgradeLosesBinary = !this.supportsBinary && self.transport.supportsBinary;
  3544. failed = failed || upgradeLosesBinary;
  3545. }
  3546. if (failed) return;
  3547. debug('probe transport "%s" opened', name);
  3548. transport.send([{ type: 'ping', data: 'probe' }]);
  3549. transport.once('packet', function (msg) {
  3550. if (failed) return;
  3551. if ('pong' === msg.type && 'probe' === msg.data) {
  3552. debug('probe transport "%s" pong', name);
  3553. self.upgrading = true;
  3554. self.emit('upgrading', transport);
  3555. if (!transport) return;
  3556. Socket.priorWebsocketSuccess = 'websocket' === transport.name;
  3557. debug('pausing current transport "%s"', self.transport.name);
  3558. self.transport.pause(function () {
  3559. if (failed) return;
  3560. if ('closed' === self.readyState) return;
  3561. debug('changing transport and sending upgrade packet');
  3562. cleanup();
  3563. self.setTransport(transport);
  3564. transport.send([{ type: 'upgrade' }]);
  3565. self.emit('upgrade', transport);
  3566. transport = null;
  3567. self.upgrading = false;
  3568. self.flush();
  3569. });
  3570. } else {
  3571. debug('probe transport "%s" failed', name);
  3572. var err = new Error('probe error');
  3573. err.transport = transport.name;
  3574. self.emit('upgradeError', err);
  3575. }
  3576. });
  3577. }
  3578. function freezeTransport () {
  3579. if (failed) return;
  3580. // Any callback called by transport should be ignored since now
  3581. failed = true;
  3582. cleanup();
  3583. transport.close();
  3584. transport = null;
  3585. }
  3586. // Handle any error that happens while probing
  3587. function onerror (err) {
  3588. var error = new Error('probe error: ' + err);
  3589. error.transport = transport.name;
  3590. freezeTransport();
  3591. debug('probe transport "%s" failed because of error: %s', name, err);
  3592. self.emit('upgradeError', error);
  3593. }
  3594. function onTransportClose () {
  3595. onerror('transport closed');
  3596. }
  3597. // When the socket is closed while we're probing
  3598. function onclose () {
  3599. onerror('socket closed');
  3600. }
  3601. // When the socket is upgraded while we're probing
  3602. function onupgrade (to) {
  3603. if (transport && to.name !== transport.name) {
  3604. debug('"%s" works - aborting "%s"', to.name, transport.name);
  3605. freezeTransport();
  3606. }
  3607. }
  3608. // Remove all listeners on the transport and on self
  3609. function cleanup () {
  3610. transport.removeListener('open', onTransportOpen);
  3611. transport.removeListener('error', onerror);
  3612. transport.removeListener('close', onTransportClose);
  3613. self.removeListener('close', onclose);
  3614. self.removeListener('upgrading', onupgrade);
  3615. }
  3616. transport.once('open', onTransportOpen);
  3617. transport.once('error', onerror);
  3618. transport.once('close', onTransportClose);
  3619. this.once('close', onclose);
  3620. this.once('upgrading', onupgrade);
  3621. transport.open();
  3622. };
  3623. /**
  3624. * Called when connection is deemed open.
  3625. *
  3626. * @api public
  3627. */
  3628. Socket.prototype.onOpen = function () {
  3629. debug('socket open');
  3630. this.readyState = 'open';
  3631. Socket.priorWebsocketSuccess = 'websocket' === this.transport.name;
  3632. this.emit('open');
  3633. this.flush();
  3634. // we check for `readyState` in case an `open`
  3635. // listener already closed the socket
  3636. if ('open' === this.readyState && this.upgrade && this.transport.pause) {
  3637. debug('starting upgrade probes');
  3638. for (var i = 0, l = this.upgrades.length; i < l; i++) {
  3639. this.probe(this.upgrades[i]);
  3640. }
  3641. }
  3642. };
  3643. /**
  3644. * Handles a packet.
  3645. *
  3646. * @api private
  3647. */
  3648. Socket.prototype.onPacket = function (packet) {
  3649. if ('opening' === this.readyState || 'open' === this.readyState ||
  3650. 'closing' === this.readyState) {
  3651. debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
  3652. this.emit('packet', packet);
  3653. // Socket is live - any packet counts
  3654. this.emit('heartbeat');
  3655. switch (packet.type) {
  3656. case 'open':
  3657. this.onHandshake(parsejson(packet.data));
  3658. break;
  3659. case 'pong':
  3660. this.setPing();
  3661. this.emit('pong');
  3662. break;
  3663. case 'error':
  3664. var err = new Error('server error');
  3665. err.code = packet.data;
  3666. this.onError(err);
  3667. break;
  3668. case 'message':
  3669. this.emit('data', packet.data);
  3670. this.emit('message', packet.data);
  3671. break;
  3672. }
  3673. } else {
  3674. debug('packet received with socket readyState "%s"', this.readyState);
  3675. }
  3676. };
  3677. /**
  3678. * Called upon handshake completion.
  3679. *
  3680. * @param {Object} handshake obj
  3681. * @api private
  3682. */
  3683. Socket.prototype.onHandshake = function (data) {
  3684. this.emit('handshake', data);
  3685. this.id = data.sid;
  3686. this.transport.query.sid = data.sid;
  3687. this.upgrades = this.filterUpgrades(data.upgrades);
  3688. this.pingInterval = data.pingInterval;
  3689. this.pingTimeout = data.pingTimeout;
  3690. this.onOpen();
  3691. // In case open handler closes socket
  3692. if ('closed' === this.readyState) return;
  3693. this.setPing();
  3694. // Prolong liveness of socket on heartbeat
  3695. this.removeListener('heartbeat', this.onHeartbeat);
  3696. this.on('heartbeat', this.onHeartbeat);
  3697. };
  3698. /**
  3699. * Resets ping timeout.
  3700. *
  3701. * @api private
  3702. */
  3703. Socket.prototype.onHeartbeat = function (timeout) {
  3704. clearTimeout(this.pingTimeoutTimer);
  3705. var self = this;
  3706. self.pingTimeoutTimer = setTimeout(function () {
  3707. if ('closed' === self.readyState) return;
  3708. self.onClose('ping timeout');
  3709. }, timeout || (self.pingInterval + self.pingTimeout));
  3710. };
  3711. /**
  3712. * Pings server every `this.pingInterval` and expects response
  3713. * within `this.pingTimeout` or closes connection.
  3714. *
  3715. * @api private
  3716. */
  3717. Socket.prototype.setPing = function () {
  3718. var self = this;
  3719. clearTimeout(self.pingIntervalTimer);
  3720. self.pingIntervalTimer = setTimeout(function () {
  3721. debug('writing ping packet - expecting pong within %sms', self.pingTimeout);
  3722. self.ping();
  3723. self.onHeartbeat(self.pingTimeout);
  3724. }, self.pingInterval);
  3725. };
  3726. /**
  3727. * Sends a ping packet.
  3728. *
  3729. * @api private
  3730. */
  3731. Socket.prototype.ping = function () {
  3732. var self = this;
  3733. this.sendPacket('ping', function () {
  3734. self.emit('ping');
  3735. });
  3736. };
  3737. /**
  3738. * Called on `drain` event
  3739. *
  3740. * @api private
  3741. */
  3742. Socket.prototype.onDrain = function () {
  3743. this.writeBuffer.splice(0, this.prevBufferLen);
  3744. // setting prevBufferLen = 0 is very important
  3745. // for example, when upgrading, upgrade packet is sent over,
  3746. // and a nonzero prevBufferLen could cause problems on `drain`
  3747. this.prevBufferLen = 0;
  3748. if (0 === this.writeBuffer.length) {
  3749. this.emit('drain');
  3750. } else {
  3751. this.flush();
  3752. }
  3753. };
  3754. /**
  3755. * Flush write buffers.
  3756. *
  3757. * @api private
  3758. */
  3759. Socket.prototype.flush = function () {
  3760. if ('closed' !== this.readyState && this.transport.writable &&
  3761. !this.upgrading && this.writeBuffer.length) {
  3762. debug('flushing %d packets in socket', this.writeBuffer.length);
  3763. this.transport.send(this.writeBuffer);
  3764. // keep track of current length of writeBuffer
  3765. // splice writeBuffer and callbackBuffer on `drain`
  3766. this.prevBufferLen = this.writeBuffer.length;
  3767. this.emit('flush');
  3768. }
  3769. };
  3770. /**
  3771. * Sends a message.
  3772. *
  3773. * @param {String} message.
  3774. * @param {Function} callback function.
  3775. * @param {Object} options.
  3776. * @return {Socket} for chaining.
  3777. * @api public
  3778. */
  3779. Socket.prototype.write =
  3780. Socket.prototype.send = function (msg, options, fn) {
  3781. this.sendPacket('message', msg, options, fn);
  3782. return this;
  3783. };
  3784. /**
  3785. * Sends a packet.
  3786. *
  3787. * @param {String} packet type.
  3788. * @param {String} data.
  3789. * @param {Object} options.
  3790. * @param {Function} callback function.
  3791. * @api private
  3792. */
  3793. Socket.prototype.sendPacket = function (type, data, options, fn) {
  3794. if ('function' === typeof data) {
  3795. fn = data;
  3796. data = undefined;
  3797. }
  3798. if ('function' === typeof options) {
  3799. fn = options;
  3800. options = null;
  3801. }
  3802. if ('closing' === this.readyState || 'closed' === this.readyState) {
  3803. return;
  3804. }
  3805. options = options || {};
  3806. options.compress = false !== options.compress;
  3807. var packet = {
  3808. type: type,
  3809. data: data,
  3810. options: options
  3811. };
  3812. this.emit('packetCreate', packet);
  3813. this.writeBuffer.push(packet);
  3814. if (fn) this.once('flush', fn);
  3815. this.flush();
  3816. };
  3817. /**
  3818. * Closes the connection.
  3819. *
  3820. * @api private
  3821. */
  3822. Socket.prototype.close = function () {
  3823. if ('opening' === this.readyState || 'open' === this.readyState) {
  3824. this.readyState = 'closing';
  3825. var self = this;
  3826. if (this.writeBuffer.length) {
  3827. this.once('drain', function () {
  3828. if (this.upgrading) {
  3829. waitForUpgrade();
  3830. } else {
  3831. close();
  3832. }
  3833. });
  3834. } else if (this.upgrading) {
  3835. waitForUpgrade();
  3836. } else {
  3837. close();
  3838. }
  3839. }
  3840. function close () {
  3841. self.onClose('forced close');
  3842. debug('socket closing - telling transport to close');
  3843. self.transport.close();
  3844. }
  3845. function cleanupAndClose () {
  3846. self.removeListener('upgrade', cleanupAndClose);
  3847. self.removeListener('upgradeError', cleanupAndClose);
  3848. close();
  3849. }
  3850. function waitForUpgrade () {
  3851. // wait for upgrade to finish since we can't send packets while pausing a transport
  3852. self.once('upgrade', cleanupAndClose);
  3853. self.once('upgradeError', cleanupAndClose);
  3854. }
  3855. return this;
  3856. };
  3857. /**
  3858. * Called upon transport error
  3859. *
  3860. * @api private
  3861. */
  3862. Socket.prototype.onError = function (err) {
  3863. debug('socket error %j', err);
  3864. Socket.priorWebsocketSuccess = false;
  3865. this.emit('error', err);
  3866. this.onClose('transport error', err);
  3867. };
  3868. /**
  3869. * Called upon transport close.
  3870. *
  3871. * @api private
  3872. */
  3873. Socket.prototype.onClose = function (reason, desc) {
  3874. if ('opening' === this.readyState || 'open' === this.readyState || 'closing' === this.readyState) {
  3875. debug('socket close with reason: "%s"', reason);
  3876. var self = this;
  3877. // clear timers
  3878. clearTimeout(this.pingIntervalTimer);
  3879. clearTimeout(this.pingTimeoutTimer);
  3880. // stop event from firing again for transport
  3881. this.transport.removeAllListeners('close');
  3882. // ensure transport won't stay open
  3883. this.transport.close();
  3884. // ignore further transport communication
  3885. this.transport.removeAllListeners();
  3886. // set ready state
  3887. this.readyState = 'closed';
  3888. // clear session id
  3889. this.id = null;
  3890. // emit close event
  3891. this.emit('close', reason, desc);
  3892. // clean buffers after, so users can still
  3893. // grab the buffers on `close` event
  3894. self.writeBuffer = [];
  3895. self.prevBufferLen = 0;
  3896. }
  3897. };
  3898. /**
  3899. * Filters upgrades, returning only those matching client transports.
  3900. *
  3901. * @param {Array} server upgrades
  3902. * @api private
  3903. *
  3904. */
  3905. Socket.prototype.filterUpgrades = function (upgrades) {
  3906. var filteredUpgrades = [];
  3907. for (var i = 0, j = upgrades.length; i < j; i++) {
  3908. if (~index(this.transports, upgrades[i])) filteredUpgrades.push(upgrades[i]);
  3909. }
  3910. return filteredUpgrades;
  3911. };
  3912. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  3913. /***/ },
  3914. /* 21 */
  3915. /***/ function(module, exports, __webpack_require__) {
  3916. /* WEBPACK VAR INJECTION */(function(global) {/**
  3917. * Module dependencies
  3918. */
  3919. var XMLHttpRequest = __webpack_require__(22);
  3920. var XHR = __webpack_require__(24);
  3921. var JSONP = __webpack_require__(39);
  3922. var websocket = __webpack_require__(40);
  3923. /**
  3924. * Export transports.
  3925. */
  3926. exports.polling = polling;
  3927. exports.websocket = websocket;
  3928. /**
  3929. * Polling transport polymorphic constructor.
  3930. * Decides on xhr vs jsonp based on feature detection.
  3931. *
  3932. * @api private
  3933. */
  3934. function polling (opts) {
  3935. var xhr;
  3936. var xd = false;
  3937. var xs = false;
  3938. var jsonp = false !== opts.jsonp;
  3939. if (global.location) {
  3940. var isSSL = 'https:' === location.protocol;
  3941. var port = location.port;
  3942. // some user agents have empty `location.port`
  3943. if (!port) {
  3944. port = isSSL ? 443 : 80;
  3945. }
  3946. xd = opts.hostname !== location.hostname || port !== opts.port;
  3947. xs = opts.secure !== isSSL;
  3948. }
  3949. opts.xdomain = xd;
  3950. opts.xscheme = xs;
  3951. xhr = new XMLHttpRequest(opts);
  3952. if ('open' in xhr && !opts.forceJSONP) {
  3953. return new XHR(opts);
  3954. } else {
  3955. if (!jsonp) throw new Error('JSONP disabled');
  3956. return new JSONP(opts);
  3957. }
  3958. }
  3959. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  3960. /***/ },
  3961. /* 22 */
  3962. /***/ function(module, exports, __webpack_require__) {
  3963. /* WEBPACK VAR INJECTION */(function(global) {// browser shim for xmlhttprequest module
  3964. var hasCORS = __webpack_require__(23);
  3965. module.exports = function (opts) {
  3966. var xdomain = opts.xdomain;
  3967. // scheme must be same when usign XDomainRequest
  3968. // http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx
  3969. var xscheme = opts.xscheme;
  3970. // XDomainRequest has a flow of not sending cookie, therefore it should be disabled as a default.
  3971. // https://github.com/Automattic/engine.io-client/pull/217
  3972. var enablesXDR = opts.enablesXDR;
  3973. // XMLHttpRequest can be disabled on IE
  3974. try {
  3975. if ('undefined' !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
  3976. return new XMLHttpRequest();
  3977. }
  3978. } catch (e) { }
  3979. // Use XDomainRequest for IE8 if enablesXDR is true
  3980. // because loading bar keeps flashing when using jsonp-polling
  3981. // https://github.com/yujiosaka/socke.io-ie8-loading-example
  3982. try {
  3983. if ('undefined' !== typeof XDomainRequest && !xscheme && enablesXDR) {
  3984. return new XDomainRequest();
  3985. }
  3986. } catch (e) { }
  3987. if (!xdomain) {
  3988. try {
  3989. return new global[['Active'].concat('Object').join('X')]('Microsoft.XMLHTTP');
  3990. } catch (e) { }
  3991. }
  3992. };
  3993. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  3994. /***/ },
  3995. /* 23 */
  3996. /***/ function(module, exports) {
  3997. /**
  3998. * Module exports.
  3999. *
  4000. * Logic borrowed from Modernizr:
  4001. *
  4002. * - https://github.com/Modernizr/Modernizr/blob/master/feature-detects/cors.js
  4003. */
  4004. try {
  4005. module.exports = typeof XMLHttpRequest !== 'undefined' &&
  4006. 'withCredentials' in new XMLHttpRequest();
  4007. } catch (err) {
  4008. // if XMLHttp support is disabled in IE then it will throw
  4009. // when trying to create
  4010. module.exports = false;
  4011. }
  4012. /***/ },
  4013. /* 24 */
  4014. /***/ function(module, exports, __webpack_require__) {
  4015. /* WEBPACK VAR INJECTION */(function(global) {/**
  4016. * Module requirements.
  4017. */
  4018. var XMLHttpRequest = __webpack_require__(22);
  4019. var Polling = __webpack_require__(25);
  4020. var Emitter = __webpack_require__(35);
  4021. var inherit = __webpack_require__(37);
  4022. var debug = __webpack_require__(3)('engine.io-client:polling-xhr');
  4023. /**
  4024. * Module exports.
  4025. */
  4026. module.exports = XHR;
  4027. module.exports.Request = Request;
  4028. /**
  4029. * Empty function
  4030. */
  4031. function empty () {}
  4032. /**
  4033. * XHR Polling constructor.
  4034. *
  4035. * @param {Object} opts
  4036. * @api public
  4037. */
  4038. function XHR (opts) {
  4039. Polling.call(this, opts);
  4040. this.requestTimeout = opts.requestTimeout;
  4041. if (global.location) {
  4042. var isSSL = 'https:' === location.protocol;
  4043. var port = location.port;
  4044. // some user agents have empty `location.port`
  4045. if (!port) {
  4046. port = isSSL ? 443 : 80;
  4047. }
  4048. this.xd = opts.hostname !== global.location.hostname ||
  4049. port !== opts.port;
  4050. this.xs = opts.secure !== isSSL;
  4051. } else {
  4052. this.extraHeaders = opts.extraHeaders;
  4053. }
  4054. }
  4055. /**
  4056. * Inherits from Polling.
  4057. */
  4058. inherit(XHR, Polling);
  4059. /**
  4060. * XHR supports binary
  4061. */
  4062. XHR.prototype.supportsBinary = true;
  4063. /**
  4064. * Creates a request.
  4065. *
  4066. * @param {String} method
  4067. * @api private
  4068. */
  4069. XHR.prototype.request = function (opts) {
  4070. opts = opts || {};
  4071. opts.uri = this.uri();
  4072. opts.xd = this.xd;
  4073. opts.xs = this.xs;
  4074. opts.agent = this.agent || false;
  4075. opts.supportsBinary = this.supportsBinary;
  4076. opts.enablesXDR = this.enablesXDR;
  4077. // SSL options for Node.js client
  4078. opts.pfx = this.pfx;
  4079. opts.key = this.key;
  4080. opts.passphrase = this.passphrase;
  4081. opts.cert = this.cert;
  4082. opts.ca = this.ca;
  4083. opts.ciphers = this.ciphers;
  4084. opts.rejectUnauthorized = this.rejectUnauthorized;
  4085. opts.requestTimeout = this.requestTimeout;
  4086. // other options for Node.js client
  4087. opts.extraHeaders = this.extraHeaders;
  4088. return new Request(opts);
  4089. };
  4090. /**
  4091. * Sends data.
  4092. *
  4093. * @param {String} data to send.
  4094. * @param {Function} called upon flush.
  4095. * @api private
  4096. */
  4097. XHR.prototype.doWrite = function (data, fn) {
  4098. var isBinary = typeof data !== 'string' && data !== undefined;
  4099. var req = this.request({ method: 'POST', data: data, isBinary: isBinary });
  4100. var self = this;
  4101. req.on('success', fn);
  4102. req.on('error', function (err) {
  4103. self.onError('xhr post error', err);
  4104. });
  4105. this.sendXhr = req;
  4106. };
  4107. /**
  4108. * Starts a poll cycle.
  4109. *
  4110. * @api private
  4111. */
  4112. XHR.prototype.doPoll = function () {
  4113. debug('xhr poll');
  4114. var req = this.request();
  4115. var self = this;
  4116. req.on('data', function (data) {
  4117. self.onData(data);
  4118. });
  4119. req.on('error', function (err) {
  4120. self.onError('xhr poll error', err);
  4121. });
  4122. this.pollXhr = req;
  4123. };
  4124. /**
  4125. * Request constructor
  4126. *
  4127. * @param {Object} options
  4128. * @api public
  4129. */
  4130. function Request (opts) {
  4131. this.method = opts.method || 'GET';
  4132. this.uri = opts.uri;
  4133. this.xd = !!opts.xd;
  4134. this.xs = !!opts.xs;
  4135. this.async = false !== opts.async;
  4136. this.data = undefined !== opts.data ? opts.data : null;
  4137. this.agent = opts.agent;
  4138. this.isBinary = opts.isBinary;
  4139. this.supportsBinary = opts.supportsBinary;
  4140. this.enablesXDR = opts.enablesXDR;
  4141. this.requestTimeout = opts.requestTimeout;
  4142. // SSL options for Node.js client
  4143. this.pfx = opts.pfx;
  4144. this.key = opts.key;
  4145. this.passphrase = opts.passphrase;
  4146. this.cert = opts.cert;
  4147. this.ca = opts.ca;
  4148. this.ciphers = opts.ciphers;
  4149. this.rejectUnauthorized = opts.rejectUnauthorized;
  4150. // other options for Node.js client
  4151. this.extraHeaders = opts.extraHeaders;
  4152. this.create();
  4153. }
  4154. /**
  4155. * Mix in `Emitter`.
  4156. */
  4157. Emitter(Request.prototype);
  4158. /**
  4159. * Creates the XHR object and sends the request.
  4160. *
  4161. * @api private
  4162. */
  4163. Request.prototype.create = function () {
  4164. var opts = { agent: this.agent, xdomain: this.xd, xscheme: this.xs, enablesXDR: this.enablesXDR };
  4165. // SSL options for Node.js client
  4166. opts.pfx = this.pfx;
  4167. opts.key = this.key;
  4168. opts.passphrase = this.passphrase;
  4169. opts.cert = this.cert;
  4170. opts.ca = this.ca;
  4171. opts.ciphers = this.ciphers;
  4172. opts.rejectUnauthorized = this.rejectUnauthorized;
  4173. var xhr = this.xhr = new XMLHttpRequest(opts);
  4174. var self = this;
  4175. try {
  4176. debug('xhr open %s: %s', this.method, this.uri);
  4177. xhr.open(this.method, this.uri, this.async);
  4178. try {
  4179. if (this.extraHeaders) {
  4180. xhr.setDisableHeaderCheck(true);
  4181. for (var i in this.extraHeaders) {
  4182. if (this.extraHeaders.hasOwnProperty(i)) {
  4183. xhr.setRequestHeader(i, this.extraHeaders[i]);
  4184. }
  4185. }
  4186. }
  4187. } catch (e) {}
  4188. if (this.supportsBinary) {
  4189. // This has to be done after open because Firefox is stupid
  4190. // http://stackoverflow.com/questions/13216903/get-binary-data-with-xmlhttprequest-in-a-firefox-extension
  4191. xhr.responseType = 'arraybuffer';
  4192. }
  4193. if ('POST' === this.method) {
  4194. try {
  4195. if (this.isBinary) {
  4196. xhr.setRequestHeader('Content-type', 'application/octet-stream');
  4197. } else {
  4198. xhr.setRequestHeader('Content-type', 'text/plain;charset=UTF-8');
  4199. }
  4200. } catch (e) {}
  4201. }
  4202. try {
  4203. xhr.setRequestHeader('Accept', '*/*');
  4204. } catch (e) {}
  4205. // ie6 check
  4206. if ('withCredentials' in xhr) {
  4207. xhr.withCredentials = true;
  4208. }
  4209. if (this.requestTimeout) {
  4210. xhr.timeout = this.requestTimeout;
  4211. }
  4212. if (this.hasXDR()) {
  4213. xhr.onload = function () {
  4214. self.onLoad();
  4215. };
  4216. xhr.onerror = function () {
  4217. self.onError(xhr.responseText);
  4218. };
  4219. } else {
  4220. xhr.onreadystatechange = function () {
  4221. if (4 !== xhr.readyState) return;
  4222. if (200 === xhr.status || 1223 === xhr.status) {
  4223. self.onLoad();
  4224. } else {
  4225. // make sure the `error` event handler that's user-set
  4226. // does not throw in the same tick and gets caught here
  4227. setTimeout(function () {
  4228. self.onError(xhr.status);
  4229. }, 0);
  4230. }
  4231. };
  4232. }
  4233. debug('xhr data %s', this.data);
  4234. xhr.send(this.data);
  4235. } catch (e) {
  4236. // Need to defer since .create() is called directly fhrom the constructor
  4237. // and thus the 'error' event can only be only bound *after* this exception
  4238. // occurs. Therefore, also, we cannot throw here at all.
  4239. setTimeout(function () {
  4240. self.onError(e);
  4241. }, 0);
  4242. return;
  4243. }
  4244. if (global.document) {
  4245. this.index = Request.requestsCount++;
  4246. Request.requests[this.index] = this;
  4247. }
  4248. };
  4249. /**
  4250. * Called upon successful response.
  4251. *
  4252. * @api private
  4253. */
  4254. Request.prototype.onSuccess = function () {
  4255. this.emit('success');
  4256. this.cleanup();
  4257. };
  4258. /**
  4259. * Called if we have data.
  4260. *
  4261. * @api private
  4262. */
  4263. Request.prototype.onData = function (data) {
  4264. this.emit('data', data);
  4265. this.onSuccess();
  4266. };
  4267. /**
  4268. * Called upon error.
  4269. *
  4270. * @api private
  4271. */
  4272. Request.prototype.onError = function (err) {
  4273. this.emit('error', err);
  4274. this.cleanup(true);
  4275. };
  4276. /**
  4277. * Cleans up house.
  4278. *
  4279. * @api private
  4280. */
  4281. Request.prototype.cleanup = function (fromError) {
  4282. if ('undefined' === typeof this.xhr || null === this.xhr) {
  4283. return;
  4284. }
  4285. // xmlhttprequest
  4286. if (this.hasXDR()) {
  4287. this.xhr.onload = this.xhr.onerror = empty;
  4288. } else {
  4289. this.xhr.onreadystatechange = empty;
  4290. }
  4291. if (fromError) {
  4292. try {
  4293. this.xhr.abort();
  4294. } catch (e) {}
  4295. }
  4296. if (global.document) {
  4297. delete Request.requests[this.index];
  4298. }
  4299. this.xhr = null;
  4300. };
  4301. /**
  4302. * Called upon load.
  4303. *
  4304. * @api private
  4305. */
  4306. Request.prototype.onLoad = function () {
  4307. var data;
  4308. try {
  4309. var contentType;
  4310. try {
  4311. contentType = this.xhr.getResponseHeader('Content-Type').split(';')[0];
  4312. } catch (e) {}
  4313. if (contentType === 'application/octet-stream') {
  4314. data = this.xhr.response || this.xhr.responseText;
  4315. } else {
  4316. if (!this.supportsBinary) {
  4317. data = this.xhr.responseText;
  4318. } else {
  4319. try {
  4320. data = String.fromCharCode.apply(null, new Uint8Array(this.xhr.response));
  4321. } catch (e) {
  4322. var ui8Arr = new Uint8Array(this.xhr.response);
  4323. var dataArray = [];
  4324. for (var idx = 0, length = ui8Arr.length; idx < length; idx++) {
  4325. dataArray.push(ui8Arr[idx]);
  4326. }
  4327. data = String.fromCharCode.apply(null, dataArray);
  4328. }
  4329. }
  4330. }
  4331. } catch (e) {
  4332. this.onError(e);
  4333. }
  4334. if (null != data) {
  4335. this.onData(data);
  4336. }
  4337. };
  4338. /**
  4339. * Check if it has XDomainRequest.
  4340. *
  4341. * @api private
  4342. */
  4343. Request.prototype.hasXDR = function () {
  4344. return 'undefined' !== typeof global.XDomainRequest && !this.xs && this.enablesXDR;
  4345. };
  4346. /**
  4347. * Aborts the request.
  4348. *
  4349. * @api public
  4350. */
  4351. Request.prototype.abort = function () {
  4352. this.cleanup();
  4353. };
  4354. /**
  4355. * Aborts pending requests when unloading the window. This is needed to prevent
  4356. * memory leaks (e.g. when using IE) and to ensure that no spurious error is
  4357. * emitted.
  4358. */
  4359. Request.requestsCount = 0;
  4360. Request.requests = {};
  4361. if (global.document) {
  4362. if (global.attachEvent) {
  4363. global.attachEvent('onunload', unloadHandler);
  4364. } else if (global.addEventListener) {
  4365. global.addEventListener('beforeunload', unloadHandler, false);
  4366. }
  4367. }
  4368. function unloadHandler () {
  4369. for (var i in Request.requests) {
  4370. if (Request.requests.hasOwnProperty(i)) {
  4371. Request.requests[i].abort();
  4372. }
  4373. }
  4374. }
  4375. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  4376. /***/ },
  4377. /* 25 */
  4378. /***/ function(module, exports, __webpack_require__) {
  4379. /**
  4380. * Module dependencies.
  4381. */
  4382. var Transport = __webpack_require__(26);
  4383. var parseqs = __webpack_require__(36);
  4384. var parser = __webpack_require__(27);
  4385. var inherit = __webpack_require__(37);
  4386. var yeast = __webpack_require__(38);
  4387. var debug = __webpack_require__(3)('engine.io-client:polling');
  4388. /**
  4389. * Module exports.
  4390. */
  4391. module.exports = Polling;
  4392. /**
  4393. * Is XHR2 supported?
  4394. */
  4395. var hasXHR2 = (function () {
  4396. var XMLHttpRequest = __webpack_require__(22);
  4397. var xhr = new XMLHttpRequest({ xdomain: false });
  4398. return null != xhr.responseType;
  4399. })();
  4400. /**
  4401. * Polling interface.
  4402. *
  4403. * @param {Object} opts
  4404. * @api private
  4405. */
  4406. function Polling (opts) {
  4407. var forceBase64 = (opts && opts.forceBase64);
  4408. if (!hasXHR2 || forceBase64) {
  4409. this.supportsBinary = false;
  4410. }
  4411. Transport.call(this, opts);
  4412. }
  4413. /**
  4414. * Inherits from Transport.
  4415. */
  4416. inherit(Polling, Transport);
  4417. /**
  4418. * Transport name.
  4419. */
  4420. Polling.prototype.name = 'polling';
  4421. /**
  4422. * Opens the socket (triggers polling). We write a PING message to determine
  4423. * when the transport is open.
  4424. *
  4425. * @api private
  4426. */
  4427. Polling.prototype.doOpen = function () {
  4428. this.poll();
  4429. };
  4430. /**
  4431. * Pauses polling.
  4432. *
  4433. * @param {Function} callback upon buffers are flushed and transport is paused
  4434. * @api private
  4435. */
  4436. Polling.prototype.pause = function (onPause) {
  4437. var self = this;
  4438. this.readyState = 'pausing';
  4439. function pause () {
  4440. debug('paused');
  4441. self.readyState = 'paused';
  4442. onPause();
  4443. }
  4444. if (this.polling || !this.writable) {
  4445. var total = 0;
  4446. if (this.polling) {
  4447. debug('we are currently polling - waiting to pause');
  4448. total++;
  4449. this.once('pollComplete', function () {
  4450. debug('pre-pause polling complete');
  4451. --total || pause();
  4452. });
  4453. }
  4454. if (!this.writable) {
  4455. debug('we are currently writing - waiting to pause');
  4456. total++;
  4457. this.once('drain', function () {
  4458. debug('pre-pause writing complete');
  4459. --total || pause();
  4460. });
  4461. }
  4462. } else {
  4463. pause();
  4464. }
  4465. };
  4466. /**
  4467. * Starts polling cycle.
  4468. *
  4469. * @api public
  4470. */
  4471. Polling.prototype.poll = function () {
  4472. debug('polling');
  4473. this.polling = true;
  4474. this.doPoll();
  4475. this.emit('poll');
  4476. };
  4477. /**
  4478. * Overloads onData to detect payloads.
  4479. *
  4480. * @api private
  4481. */
  4482. Polling.prototype.onData = function (data) {
  4483. var self = this;
  4484. debug('polling got data %s', data);
  4485. var callback = function (packet, index, total) {
  4486. // if its the first message we consider the transport open
  4487. if ('opening' === self.readyState) {
  4488. self.onOpen();
  4489. }
  4490. // if its a close packet, we close the ongoing requests
  4491. if ('close' === packet.type) {
  4492. self.onClose();
  4493. return false;
  4494. }
  4495. // otherwise bypass onData and handle the message
  4496. self.onPacket(packet);
  4497. };
  4498. // decode payload
  4499. parser.decodePayload(data, this.socket.binaryType, callback);
  4500. // if an event did not trigger closing
  4501. if ('closed' !== this.readyState) {
  4502. // if we got data we're not polling
  4503. this.polling = false;
  4504. this.emit('pollComplete');
  4505. if ('open' === this.readyState) {
  4506. this.poll();
  4507. } else {
  4508. debug('ignoring poll - transport state "%s"', this.readyState);
  4509. }
  4510. }
  4511. };
  4512. /**
  4513. * For polling, send a close packet.
  4514. *
  4515. * @api private
  4516. */
  4517. Polling.prototype.doClose = function () {
  4518. var self = this;
  4519. function close () {
  4520. debug('writing close packet');
  4521. self.write([{ type: 'close' }]);
  4522. }
  4523. if ('open' === this.readyState) {
  4524. debug('transport open - closing');
  4525. close();
  4526. } else {
  4527. // in case we're trying to close while
  4528. // handshaking is in progress (GH-164)
  4529. debug('transport not open - deferring close');
  4530. this.once('open', close);
  4531. }
  4532. };
  4533. /**
  4534. * Writes a packets payload.
  4535. *
  4536. * @param {Array} data packets
  4537. * @param {Function} drain callback
  4538. * @api private
  4539. */
  4540. Polling.prototype.write = function (packets) {
  4541. var self = this;
  4542. this.writable = false;
  4543. var callbackfn = function () {
  4544. self.writable = true;
  4545. self.emit('drain');
  4546. };
  4547. parser.encodePayload(packets, this.supportsBinary, function (data) {
  4548. self.doWrite(data, callbackfn);
  4549. });
  4550. };
  4551. /**
  4552. * Generates uri for connection.
  4553. *
  4554. * @api private
  4555. */
  4556. Polling.prototype.uri = function () {
  4557. var query = this.query || {};
  4558. var schema = this.secure ? 'https' : 'http';
  4559. var port = '';
  4560. // cache busting is forced
  4561. if (false !== this.timestampRequests) {
  4562. query[this.timestampParam] = yeast();
  4563. }
  4564. if (!this.supportsBinary && !query.sid) {
  4565. query.b64 = 1;
  4566. }
  4567. query = parseqs.encode(query);
  4568. // avoid port if default for schema
  4569. if (this.port && (('https' === schema && Number(this.port) !== 443) ||
  4570. ('http' === schema && Number(this.port) !== 80))) {
  4571. port = ':' + this.port;
  4572. }
  4573. // prepend ? to query
  4574. if (query.length) {
  4575. query = '?' + query;
  4576. }
  4577. var ipv6 = this.hostname.indexOf(':') !== -1;
  4578. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  4579. };
  4580. /***/ },
  4581. /* 26 */
  4582. /***/ function(module, exports, __webpack_require__) {
  4583. /**
  4584. * Module dependencies.
  4585. */
  4586. var parser = __webpack_require__(27);
  4587. var Emitter = __webpack_require__(35);
  4588. /**
  4589. * Module exports.
  4590. */
  4591. module.exports = Transport;
  4592. /**
  4593. * Transport abstract constructor.
  4594. *
  4595. * @param {Object} options.
  4596. * @api private
  4597. */
  4598. function Transport (opts) {
  4599. this.path = opts.path;
  4600. this.hostname = opts.hostname;
  4601. this.port = opts.port;
  4602. this.secure = opts.secure;
  4603. this.query = opts.query;
  4604. this.timestampParam = opts.timestampParam;
  4605. this.timestampRequests = opts.timestampRequests;
  4606. this.readyState = '';
  4607. this.agent = opts.agent || false;
  4608. this.socket = opts.socket;
  4609. this.enablesXDR = opts.enablesXDR;
  4610. // SSL options for Node.js client
  4611. this.pfx = opts.pfx;
  4612. this.key = opts.key;
  4613. this.passphrase = opts.passphrase;
  4614. this.cert = opts.cert;
  4615. this.ca = opts.ca;
  4616. this.ciphers = opts.ciphers;
  4617. this.rejectUnauthorized = opts.rejectUnauthorized;
  4618. this.forceNode = opts.forceNode;
  4619. // other options for Node.js client
  4620. this.extraHeaders = opts.extraHeaders;
  4621. this.localAddress = opts.localAddress;
  4622. }
  4623. /**
  4624. * Mix in `Emitter`.
  4625. */
  4626. Emitter(Transport.prototype);
  4627. /**
  4628. * Emits an error.
  4629. *
  4630. * @param {String} str
  4631. * @return {Transport} for chaining
  4632. * @api public
  4633. */
  4634. Transport.prototype.onError = function (msg, desc) {
  4635. var err = new Error(msg);
  4636. err.type = 'TransportError';
  4637. err.description = desc;
  4638. this.emit('error', err);
  4639. return this;
  4640. };
  4641. /**
  4642. * Opens the transport.
  4643. *
  4644. * @api public
  4645. */
  4646. Transport.prototype.open = function () {
  4647. if ('closed' === this.readyState || '' === this.readyState) {
  4648. this.readyState = 'opening';
  4649. this.doOpen();
  4650. }
  4651. return this;
  4652. };
  4653. /**
  4654. * Closes the transport.
  4655. *
  4656. * @api private
  4657. */
  4658. Transport.prototype.close = function () {
  4659. if ('opening' === this.readyState || 'open' === this.readyState) {
  4660. this.doClose();
  4661. this.onClose();
  4662. }
  4663. return this;
  4664. };
  4665. /**
  4666. * Sends multiple packets.
  4667. *
  4668. * @param {Array} packets
  4669. * @api private
  4670. */
  4671. Transport.prototype.send = function (packets) {
  4672. if ('open' === this.readyState) {
  4673. this.write(packets);
  4674. } else {
  4675. throw new Error('Transport not open');
  4676. }
  4677. };
  4678. /**
  4679. * Called upon open
  4680. *
  4681. * @api private
  4682. */
  4683. Transport.prototype.onOpen = function () {
  4684. this.readyState = 'open';
  4685. this.writable = true;
  4686. this.emit('open');
  4687. };
  4688. /**
  4689. * Called with data.
  4690. *
  4691. * @param {String} data
  4692. * @api private
  4693. */
  4694. Transport.prototype.onData = function (data) {
  4695. var packet = parser.decodePacket(data, this.socket.binaryType);
  4696. this.onPacket(packet);
  4697. };
  4698. /**
  4699. * Called with a decoded packet.
  4700. */
  4701. Transport.prototype.onPacket = function (packet) {
  4702. this.emit('packet', packet);
  4703. };
  4704. /**
  4705. * Called upon close.
  4706. *
  4707. * @api private
  4708. */
  4709. Transport.prototype.onClose = function () {
  4710. this.readyState = 'closed';
  4711. this.emit('close');
  4712. };
  4713. /***/ },
  4714. /* 27 */
  4715. /***/ function(module, exports, __webpack_require__) {
  4716. /* WEBPACK VAR INJECTION */(function(global) {/**
  4717. * Module dependencies.
  4718. */
  4719. var keys = __webpack_require__(28);
  4720. var hasBinary = __webpack_require__(29);
  4721. var sliceBuffer = __webpack_require__(30);
  4722. var after = __webpack_require__(31);
  4723. var utf8 = __webpack_require__(32);
  4724. var base64encoder;
  4725. if (global && global.ArrayBuffer) {
  4726. base64encoder = __webpack_require__(33);
  4727. }
  4728. /**
  4729. * Check if we are running an android browser. That requires us to use
  4730. * ArrayBuffer with polling transports...
  4731. *
  4732. * http://ghinda.net/jpeg-blob-ajax-android/
  4733. */
  4734. var isAndroid = typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
  4735. /**
  4736. * Check if we are running in PhantomJS.
  4737. * Uploading a Blob with PhantomJS does not work correctly, as reported here:
  4738. * https://github.com/ariya/phantomjs/issues/11395
  4739. * @type boolean
  4740. */
  4741. var isPhantomJS = typeof navigator !== 'undefined' && /PhantomJS/i.test(navigator.userAgent);
  4742. /**
  4743. * When true, avoids using Blobs to encode payloads.
  4744. * @type boolean
  4745. */
  4746. var dontSendBlobs = isAndroid || isPhantomJS;
  4747. /**
  4748. * Current protocol version.
  4749. */
  4750. exports.protocol = 3;
  4751. /**
  4752. * Packet types.
  4753. */
  4754. var packets = exports.packets = {
  4755. open: 0 // non-ws
  4756. , close: 1 // non-ws
  4757. , ping: 2
  4758. , pong: 3
  4759. , message: 4
  4760. , upgrade: 5
  4761. , noop: 6
  4762. };
  4763. var packetslist = keys(packets);
  4764. /**
  4765. * Premade error packet.
  4766. */
  4767. var err = { type: 'error', data: 'parser error' };
  4768. /**
  4769. * Create a blob api even for blob builder when vendor prefixes exist
  4770. */
  4771. var Blob = __webpack_require__(34);
  4772. /**
  4773. * Encodes a packet.
  4774. *
  4775. * <packet type id> [ <data> ]
  4776. *
  4777. * Example:
  4778. *
  4779. * 5hello world
  4780. * 3
  4781. * 4
  4782. *
  4783. * Binary is encoded in an identical principle
  4784. *
  4785. * @api private
  4786. */
  4787. exports.encodePacket = function (packet, supportsBinary, utf8encode, callback) {
  4788. if ('function' == typeof supportsBinary) {
  4789. callback = supportsBinary;
  4790. supportsBinary = false;
  4791. }
  4792. if ('function' == typeof utf8encode) {
  4793. callback = utf8encode;
  4794. utf8encode = null;
  4795. }
  4796. var data = (packet.data === undefined)
  4797. ? undefined
  4798. : packet.data.buffer || packet.data;
  4799. if (global.ArrayBuffer && data instanceof ArrayBuffer) {
  4800. return encodeArrayBuffer(packet, supportsBinary, callback);
  4801. } else if (Blob && data instanceof global.Blob) {
  4802. return encodeBlob(packet, supportsBinary, callback);
  4803. }
  4804. // might be an object with { base64: true, data: dataAsBase64String }
  4805. if (data && data.base64) {
  4806. return encodeBase64Object(packet, callback);
  4807. }
  4808. // Sending data as a utf-8 string
  4809. var encoded = packets[packet.type];
  4810. // data fragment is optional
  4811. if (undefined !== packet.data) {
  4812. encoded += utf8encode ? utf8.encode(String(packet.data)) : String(packet.data);
  4813. }
  4814. return callback('' + encoded);
  4815. };
  4816. function encodeBase64Object(packet, callback) {
  4817. // packet data is an object { base64: true, data: dataAsBase64String }
  4818. var message = 'b' + exports.packets[packet.type] + packet.data.data;
  4819. return callback(message);
  4820. }
  4821. /**
  4822. * Encode packet helpers for binary types
  4823. */
  4824. function encodeArrayBuffer(packet, supportsBinary, callback) {
  4825. if (!supportsBinary) {
  4826. return exports.encodeBase64Packet(packet, callback);
  4827. }
  4828. var data = packet.data;
  4829. var contentArray = new Uint8Array(data);
  4830. var resultBuffer = new Uint8Array(1 + data.byteLength);
  4831. resultBuffer[0] = packets[packet.type];
  4832. for (var i = 0; i < contentArray.length; i++) {
  4833. resultBuffer[i+1] = contentArray[i];
  4834. }
  4835. return callback(resultBuffer.buffer);
  4836. }
  4837. function encodeBlobAsArrayBuffer(packet, supportsBinary, callback) {
  4838. if (!supportsBinary) {
  4839. return exports.encodeBase64Packet(packet, callback);
  4840. }
  4841. var fr = new FileReader();
  4842. fr.onload = function() {
  4843. packet.data = fr.result;
  4844. exports.encodePacket(packet, supportsBinary, true, callback);
  4845. };
  4846. return fr.readAsArrayBuffer(packet.data);
  4847. }
  4848. function encodeBlob(packet, supportsBinary, callback) {
  4849. if (!supportsBinary) {
  4850. return exports.encodeBase64Packet(packet, callback);
  4851. }
  4852. if (dontSendBlobs) {
  4853. return encodeBlobAsArrayBuffer(packet, supportsBinary, callback);
  4854. }
  4855. var length = new Uint8Array(1);
  4856. length[0] = packets[packet.type];
  4857. var blob = new Blob([length.buffer, packet.data]);
  4858. return callback(blob);
  4859. }
  4860. /**
  4861. * Encodes a packet with binary data in a base64 string
  4862. *
  4863. * @param {Object} packet, has `type` and `data`
  4864. * @return {String} base64 encoded message
  4865. */
  4866. exports.encodeBase64Packet = function(packet, callback) {
  4867. var message = 'b' + exports.packets[packet.type];
  4868. if (Blob && packet.data instanceof global.Blob) {
  4869. var fr = new FileReader();
  4870. fr.onload = function() {
  4871. var b64 = fr.result.split(',')[1];
  4872. callback(message + b64);
  4873. };
  4874. return fr.readAsDataURL(packet.data);
  4875. }
  4876. var b64data;
  4877. try {
  4878. b64data = String.fromCharCode.apply(null, new Uint8Array(packet.data));
  4879. } catch (e) {
  4880. // iPhone Safari doesn't let you apply with typed arrays
  4881. var typed = new Uint8Array(packet.data);
  4882. var basic = new Array(typed.length);
  4883. for (var i = 0; i < typed.length; i++) {
  4884. basic[i] = typed[i];
  4885. }
  4886. b64data = String.fromCharCode.apply(null, basic);
  4887. }
  4888. message += global.btoa(b64data);
  4889. return callback(message);
  4890. };
  4891. /**
  4892. * Decodes a packet. Changes format to Blob if requested.
  4893. *
  4894. * @return {Object} with `type` and `data` (if any)
  4895. * @api private
  4896. */
  4897. exports.decodePacket = function (data, binaryType, utf8decode) {
  4898. if (data === undefined) {
  4899. return err;
  4900. }
  4901. // String data
  4902. if (typeof data == 'string') {
  4903. if (data.charAt(0) == 'b') {
  4904. return exports.decodeBase64Packet(data.substr(1), binaryType);
  4905. }
  4906. if (utf8decode) {
  4907. data = tryDecode(data);
  4908. if (data === false) {
  4909. return err;
  4910. }
  4911. }
  4912. var type = data.charAt(0);
  4913. if (Number(type) != type || !packetslist[type]) {
  4914. return err;
  4915. }
  4916. if (data.length > 1) {
  4917. return { type: packetslist[type], data: data.substring(1) };
  4918. } else {
  4919. return { type: packetslist[type] };
  4920. }
  4921. }
  4922. var asArray = new Uint8Array(data);
  4923. var type = asArray[0];
  4924. var rest = sliceBuffer(data, 1);
  4925. if (Blob && binaryType === 'blob') {
  4926. rest = new Blob([rest]);
  4927. }
  4928. return { type: packetslist[type], data: rest };
  4929. };
  4930. function tryDecode(data) {
  4931. try {
  4932. data = utf8.decode(data);
  4933. } catch (e) {
  4934. return false;
  4935. }
  4936. return data;
  4937. }
  4938. /**
  4939. * Decodes a packet encoded in a base64 string
  4940. *
  4941. * @param {String} base64 encoded message
  4942. * @return {Object} with `type` and `data` (if any)
  4943. */
  4944. exports.decodeBase64Packet = function(msg, binaryType) {
  4945. var type = packetslist[msg.charAt(0)];
  4946. if (!base64encoder) {
  4947. return { type: type, data: { base64: true, data: msg.substr(1) } };
  4948. }
  4949. var data = base64encoder.decode(msg.substr(1));
  4950. if (binaryType === 'blob' && Blob) {
  4951. data = new Blob([data]);
  4952. }
  4953. return { type: type, data: data };
  4954. };
  4955. /**
  4956. * Encodes multiple messages (payload).
  4957. *
  4958. * <length>:data
  4959. *
  4960. * Example:
  4961. *
  4962. * 11:hello world2:hi
  4963. *
  4964. * If any contents are binary, they will be encoded as base64 strings. Base64
  4965. * encoded strings are marked with a b before the length specifier
  4966. *
  4967. * @param {Array} packets
  4968. * @api private
  4969. */
  4970. exports.encodePayload = function (packets, supportsBinary, callback) {
  4971. if (typeof supportsBinary == 'function') {
  4972. callback = supportsBinary;
  4973. supportsBinary = null;
  4974. }
  4975. var isBinary = hasBinary(packets);
  4976. if (supportsBinary && isBinary) {
  4977. if (Blob && !dontSendBlobs) {
  4978. return exports.encodePayloadAsBlob(packets, callback);
  4979. }
  4980. return exports.encodePayloadAsArrayBuffer(packets, callback);
  4981. }
  4982. if (!packets.length) {
  4983. return callback('0:');
  4984. }
  4985. function setLengthHeader(message) {
  4986. return message.length + ':' + message;
  4987. }
  4988. function encodeOne(packet, doneCallback) {
  4989. exports.encodePacket(packet, !isBinary ? false : supportsBinary, true, function(message) {
  4990. doneCallback(null, setLengthHeader(message));
  4991. });
  4992. }
  4993. map(packets, encodeOne, function(err, results) {
  4994. return callback(results.join(''));
  4995. });
  4996. };
  4997. /**
  4998. * Async array map using after
  4999. */
  5000. function map(ary, each, done) {
  5001. var result = new Array(ary.length);
  5002. var next = after(ary.length, done);
  5003. var eachWithIndex = function(i, el, cb) {
  5004. each(el, function(error, msg) {
  5005. result[i] = msg;
  5006. cb(error, result);
  5007. });
  5008. };
  5009. for (var i = 0; i < ary.length; i++) {
  5010. eachWithIndex(i, ary[i], next);
  5011. }
  5012. }
  5013. /*
  5014. * Decodes data when a payload is maybe expected. Possible binary contents are
  5015. * decoded from their base64 representation
  5016. *
  5017. * @param {String} data, callback method
  5018. * @api public
  5019. */
  5020. exports.decodePayload = function (data, binaryType, callback) {
  5021. if (typeof data != 'string') {
  5022. return exports.decodePayloadAsBinary(data, binaryType, callback);
  5023. }
  5024. if (typeof binaryType === 'function') {
  5025. callback = binaryType;
  5026. binaryType = null;
  5027. }
  5028. var packet;
  5029. if (data == '') {
  5030. // parser error - ignoring payload
  5031. return callback(err, 0, 1);
  5032. }
  5033. var length = ''
  5034. , n, msg;
  5035. for (var i = 0, l = data.length; i < l; i++) {
  5036. var chr = data.charAt(i);
  5037. if (':' != chr) {
  5038. length += chr;
  5039. } else {
  5040. if ('' == length || (length != (n = Number(length)))) {
  5041. // parser error - ignoring payload
  5042. return callback(err, 0, 1);
  5043. }
  5044. msg = data.substr(i + 1, n);
  5045. if (length != msg.length) {
  5046. // parser error - ignoring payload
  5047. return callback(err, 0, 1);
  5048. }
  5049. if (msg.length) {
  5050. packet = exports.decodePacket(msg, binaryType, true);
  5051. if (err.type == packet.type && err.data == packet.data) {
  5052. // parser error in individual packet - ignoring payload
  5053. return callback(err, 0, 1);
  5054. }
  5055. var ret = callback(packet, i + n, l);
  5056. if (false === ret) return;
  5057. }
  5058. // advance cursor
  5059. i += n;
  5060. length = '';
  5061. }
  5062. }
  5063. if (length != '') {
  5064. // parser error - ignoring payload
  5065. return callback(err, 0, 1);
  5066. }
  5067. };
  5068. /**
  5069. * Encodes multiple messages (payload) as binary.
  5070. *
  5071. * <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
  5072. * 255><data>
  5073. *
  5074. * Example:
  5075. * 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
  5076. *
  5077. * @param {Array} packets
  5078. * @return {ArrayBuffer} encoded payload
  5079. * @api private
  5080. */
  5081. exports.encodePayloadAsArrayBuffer = function(packets, callback) {
  5082. if (!packets.length) {
  5083. return callback(new ArrayBuffer(0));
  5084. }
  5085. function encodeOne(packet, doneCallback) {
  5086. exports.encodePacket(packet, true, true, function(data) {
  5087. return doneCallback(null, data);
  5088. });
  5089. }
  5090. map(packets, encodeOne, function(err, encodedPackets) {
  5091. var totalLength = encodedPackets.reduce(function(acc, p) {
  5092. var len;
  5093. if (typeof p === 'string'){
  5094. len = p.length;
  5095. } else {
  5096. len = p.byteLength;
  5097. }
  5098. return acc + len.toString().length + len + 2; // string/binary identifier + separator = 2
  5099. }, 0);
  5100. var resultArray = new Uint8Array(totalLength);
  5101. var bufferIndex = 0;
  5102. encodedPackets.forEach(function(p) {
  5103. var isString = typeof p === 'string';
  5104. var ab = p;
  5105. if (isString) {
  5106. var view = new Uint8Array(p.length);
  5107. for (var i = 0; i < p.length; i++) {
  5108. view[i] = p.charCodeAt(i);
  5109. }
  5110. ab = view.buffer;
  5111. }
  5112. if (isString) { // not true binary
  5113. resultArray[bufferIndex++] = 0;
  5114. } else { // true binary
  5115. resultArray[bufferIndex++] = 1;
  5116. }
  5117. var lenStr = ab.byteLength.toString();
  5118. for (var i = 0; i < lenStr.length; i++) {
  5119. resultArray[bufferIndex++] = parseInt(lenStr[i]);
  5120. }
  5121. resultArray[bufferIndex++] = 255;
  5122. var view = new Uint8Array(ab);
  5123. for (var i = 0; i < view.length; i++) {
  5124. resultArray[bufferIndex++] = view[i];
  5125. }
  5126. });
  5127. return callback(resultArray.buffer);
  5128. });
  5129. };
  5130. /**
  5131. * Encode as Blob
  5132. */
  5133. exports.encodePayloadAsBlob = function(packets, callback) {
  5134. function encodeOne(packet, doneCallback) {
  5135. exports.encodePacket(packet, true, true, function(encoded) {
  5136. var binaryIdentifier = new Uint8Array(1);
  5137. binaryIdentifier[0] = 1;
  5138. if (typeof encoded === 'string') {
  5139. var view = new Uint8Array(encoded.length);
  5140. for (var i = 0; i < encoded.length; i++) {
  5141. view[i] = encoded.charCodeAt(i);
  5142. }
  5143. encoded = view.buffer;
  5144. binaryIdentifier[0] = 0;
  5145. }
  5146. var len = (encoded instanceof ArrayBuffer)
  5147. ? encoded.byteLength
  5148. : encoded.size;
  5149. var lenStr = len.toString();
  5150. var lengthAry = new Uint8Array(lenStr.length + 1);
  5151. for (var i = 0; i < lenStr.length; i++) {
  5152. lengthAry[i] = parseInt(lenStr[i]);
  5153. }
  5154. lengthAry[lenStr.length] = 255;
  5155. if (Blob) {
  5156. var blob = new Blob([binaryIdentifier.buffer, lengthAry.buffer, encoded]);
  5157. doneCallback(null, blob);
  5158. }
  5159. });
  5160. }
  5161. map(packets, encodeOne, function(err, results) {
  5162. return callback(new Blob(results));
  5163. });
  5164. };
  5165. /*
  5166. * Decodes data when a payload is maybe expected. Strings are decoded by
  5167. * interpreting each byte as a key code for entries marked to start with 0. See
  5168. * description of encodePayloadAsBinary
  5169. *
  5170. * @param {ArrayBuffer} data, callback method
  5171. * @api public
  5172. */
  5173. exports.decodePayloadAsBinary = function (data, binaryType, callback) {
  5174. if (typeof binaryType === 'function') {
  5175. callback = binaryType;
  5176. binaryType = null;
  5177. }
  5178. var bufferTail = data;
  5179. var buffers = [];
  5180. var numberTooLong = false;
  5181. while (bufferTail.byteLength > 0) {
  5182. var tailArray = new Uint8Array(bufferTail);
  5183. var isString = tailArray[0] === 0;
  5184. var msgLength = '';
  5185. for (var i = 1; ; i++) {
  5186. if (tailArray[i] == 255) break;
  5187. if (msgLength.length > 310) {
  5188. numberTooLong = true;
  5189. break;
  5190. }
  5191. msgLength += tailArray[i];
  5192. }
  5193. if(numberTooLong) return callback(err, 0, 1);
  5194. bufferTail = sliceBuffer(bufferTail, 2 + msgLength.length);
  5195. msgLength = parseInt(msgLength);
  5196. var msg = sliceBuffer(bufferTail, 0, msgLength);
  5197. if (isString) {
  5198. try {
  5199. msg = String.fromCharCode.apply(null, new Uint8Array(msg));
  5200. } catch (e) {
  5201. // iPhone Safari doesn't let you apply to typed arrays
  5202. var typed = new Uint8Array(msg);
  5203. msg = '';
  5204. for (var i = 0; i < typed.length; i++) {
  5205. msg += String.fromCharCode(typed[i]);
  5206. }
  5207. }
  5208. }
  5209. buffers.push(msg);
  5210. bufferTail = sliceBuffer(bufferTail, msgLength);
  5211. }
  5212. var total = buffers.length;
  5213. buffers.forEach(function(buffer, i) {
  5214. callback(exports.decodePacket(buffer, binaryType, true), i, total);
  5215. });
  5216. };
  5217. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  5218. /***/ },
  5219. /* 28 */
  5220. /***/ function(module, exports) {
  5221. /**
  5222. * Gets the keys for an object.
  5223. *
  5224. * @return {Array} keys
  5225. * @api private
  5226. */
  5227. module.exports = Object.keys || function keys (obj){
  5228. var arr = [];
  5229. var has = Object.prototype.hasOwnProperty;
  5230. for (var i in obj) {
  5231. if (has.call(obj, i)) {
  5232. arr.push(i);
  5233. }
  5234. }
  5235. return arr;
  5236. };
  5237. /***/ },
  5238. /* 29 */
  5239. /***/ function(module, exports, __webpack_require__) {
  5240. /* WEBPACK VAR INJECTION */(function(global) {
  5241. /*
  5242. * Module requirements.
  5243. */
  5244. var isArray = __webpack_require__(15);
  5245. /**
  5246. * Module exports.
  5247. */
  5248. module.exports = hasBinary;
  5249. /**
  5250. * Checks for binary data.
  5251. *
  5252. * Right now only Buffer and ArrayBuffer are supported..
  5253. *
  5254. * @param {Object} anything
  5255. * @api public
  5256. */
  5257. function hasBinary(data) {
  5258. function _hasBinary(obj) {
  5259. if (!obj) return false;
  5260. if ( (global.Buffer && global.Buffer.isBuffer && global.Buffer.isBuffer(obj)) ||
  5261. (global.ArrayBuffer && obj instanceof ArrayBuffer) ||
  5262. (global.Blob && obj instanceof Blob) ||
  5263. (global.File && obj instanceof File)
  5264. ) {
  5265. return true;
  5266. }
  5267. if (isArray(obj)) {
  5268. for (var i = 0; i < obj.length; i++) {
  5269. if (_hasBinary(obj[i])) {
  5270. return true;
  5271. }
  5272. }
  5273. } else if (obj && 'object' == typeof obj) {
  5274. // see: https://github.com/Automattic/has-binary/pull/4
  5275. if (obj.toJSON && 'function' == typeof obj.toJSON) {
  5276. obj = obj.toJSON();
  5277. }
  5278. for (var key in obj) {
  5279. if (Object.prototype.hasOwnProperty.call(obj, key) && _hasBinary(obj[key])) {
  5280. return true;
  5281. }
  5282. }
  5283. }
  5284. return false;
  5285. }
  5286. return _hasBinary(data);
  5287. }
  5288. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  5289. /***/ },
  5290. /* 30 */
  5291. /***/ function(module, exports) {
  5292. /**
  5293. * An abstraction for slicing an arraybuffer even when
  5294. * ArrayBuffer.prototype.slice is not supported
  5295. *
  5296. * @api public
  5297. */
  5298. module.exports = function(arraybuffer, start, end) {
  5299. var bytes = arraybuffer.byteLength;
  5300. start = start || 0;
  5301. end = end || bytes;
  5302. if (arraybuffer.slice) { return arraybuffer.slice(start, end); }
  5303. if (start < 0) { start += bytes; }
  5304. if (end < 0) { end += bytes; }
  5305. if (end > bytes) { end = bytes; }
  5306. if (start >= bytes || start >= end || bytes === 0) {
  5307. return new ArrayBuffer(0);
  5308. }
  5309. var abv = new Uint8Array(arraybuffer);
  5310. var result = new Uint8Array(end - start);
  5311. for (var i = start, ii = 0; i < end; i++, ii++) {
  5312. result[ii] = abv[i];
  5313. }
  5314. return result.buffer;
  5315. };
  5316. /***/ },
  5317. /* 31 */
  5318. /***/ function(module, exports) {
  5319. module.exports = after
  5320. function after(count, callback, err_cb) {
  5321. var bail = false
  5322. err_cb = err_cb || noop
  5323. proxy.count = count
  5324. return (count === 0) ? callback() : proxy
  5325. function proxy(err, result) {
  5326. if (proxy.count <= 0) {
  5327. throw new Error('after called too many times')
  5328. }
  5329. --proxy.count
  5330. // after first error, rest are passed to err_cb
  5331. if (err) {
  5332. bail = true
  5333. callback(err)
  5334. // future error callbacks will go to error handler
  5335. callback = err_cb
  5336. } else if (proxy.count === 0 && !bail) {
  5337. callback(null, result)
  5338. }
  5339. }
  5340. }
  5341. function noop() {}
  5342. /***/ },
  5343. /* 32 */
  5344. /***/ function(module, exports, __webpack_require__) {
  5345. var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module, global) {/*! https://mths.be/wtf8 v1.0.0 by @mathias */
  5346. ;(function(root) {
  5347. // Detect free variables `exports`
  5348. var freeExports = typeof exports == 'object' && exports;
  5349. // Detect free variable `module`
  5350. var freeModule = typeof module == 'object' && module &&
  5351. module.exports == freeExports && module;
  5352. // Detect free variable `global`, from Node.js or Browserified code,
  5353. // and use it as `root`
  5354. var freeGlobal = typeof global == 'object' && global;
  5355. if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
  5356. root = freeGlobal;
  5357. }
  5358. /*--------------------------------------------------------------------------*/
  5359. var stringFromCharCode = String.fromCharCode;
  5360. // Taken from https://mths.be/punycode
  5361. function ucs2decode(string) {
  5362. var output = [];
  5363. var counter = 0;
  5364. var length = string.length;
  5365. var value;
  5366. var extra;
  5367. while (counter < length) {
  5368. value = string.charCodeAt(counter++);
  5369. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  5370. // high surrogate, and there is a next character
  5371. extra = string.charCodeAt(counter++);
  5372. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  5373. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  5374. } else {
  5375. // unmatched surrogate; only append this code unit, in case the next
  5376. // code unit is the high surrogate of a surrogate pair
  5377. output.push(value);
  5378. counter--;
  5379. }
  5380. } else {
  5381. output.push(value);
  5382. }
  5383. }
  5384. return output;
  5385. }
  5386. // Taken from https://mths.be/punycode
  5387. function ucs2encode(array) {
  5388. var length = array.length;
  5389. var index = -1;
  5390. var value;
  5391. var output = '';
  5392. while (++index < length) {
  5393. value = array[index];
  5394. if (value > 0xFFFF) {
  5395. value -= 0x10000;
  5396. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  5397. value = 0xDC00 | value & 0x3FF;
  5398. }
  5399. output += stringFromCharCode(value);
  5400. }
  5401. return output;
  5402. }
  5403. /*--------------------------------------------------------------------------*/
  5404. function createByte(codePoint, shift) {
  5405. return stringFromCharCode(((codePoint >> shift) & 0x3F) | 0x80);
  5406. }
  5407. function encodeCodePoint(codePoint) {
  5408. if ((codePoint & 0xFFFFFF80) == 0) { // 1-byte sequence
  5409. return stringFromCharCode(codePoint);
  5410. }
  5411. var symbol = '';
  5412. if ((codePoint & 0xFFFFF800) == 0) { // 2-byte sequence
  5413. symbol = stringFromCharCode(((codePoint >> 6) & 0x1F) | 0xC0);
  5414. }
  5415. else if ((codePoint & 0xFFFF0000) == 0) { // 3-byte sequence
  5416. symbol = stringFromCharCode(((codePoint >> 12) & 0x0F) | 0xE0);
  5417. symbol += createByte(codePoint, 6);
  5418. }
  5419. else if ((codePoint & 0xFFE00000) == 0) { // 4-byte sequence
  5420. symbol = stringFromCharCode(((codePoint >> 18) & 0x07) | 0xF0);
  5421. symbol += createByte(codePoint, 12);
  5422. symbol += createByte(codePoint, 6);
  5423. }
  5424. symbol += stringFromCharCode((codePoint & 0x3F) | 0x80);
  5425. return symbol;
  5426. }
  5427. function wtf8encode(string) {
  5428. var codePoints = ucs2decode(string);
  5429. var length = codePoints.length;
  5430. var index = -1;
  5431. var codePoint;
  5432. var byteString = '';
  5433. while (++index < length) {
  5434. codePoint = codePoints[index];
  5435. byteString += encodeCodePoint(codePoint);
  5436. }
  5437. return byteString;
  5438. }
  5439. /*--------------------------------------------------------------------------*/
  5440. function readContinuationByte() {
  5441. if (byteIndex >= byteCount) {
  5442. throw Error('Invalid byte index');
  5443. }
  5444. var continuationByte = byteArray[byteIndex] & 0xFF;
  5445. byteIndex++;
  5446. if ((continuationByte & 0xC0) == 0x80) {
  5447. return continuationByte & 0x3F;
  5448. }
  5449. // If we end up here, it’s not a continuation byte.
  5450. throw Error('Invalid continuation byte');
  5451. }
  5452. function decodeSymbol() {
  5453. var byte1;
  5454. var byte2;
  5455. var byte3;
  5456. var byte4;
  5457. var codePoint;
  5458. if (byteIndex > byteCount) {
  5459. throw Error('Invalid byte index');
  5460. }
  5461. if (byteIndex == byteCount) {
  5462. return false;
  5463. }
  5464. // Read the first byte.
  5465. byte1 = byteArray[byteIndex] & 0xFF;
  5466. byteIndex++;
  5467. // 1-byte sequence (no continuation bytes)
  5468. if ((byte1 & 0x80) == 0) {
  5469. return byte1;
  5470. }
  5471. // 2-byte sequence
  5472. if ((byte1 & 0xE0) == 0xC0) {
  5473. var byte2 = readContinuationByte();
  5474. codePoint = ((byte1 & 0x1F) << 6) | byte2;
  5475. if (codePoint >= 0x80) {
  5476. return codePoint;
  5477. } else {
  5478. throw Error('Invalid continuation byte');
  5479. }
  5480. }
  5481. // 3-byte sequence (may include unpaired surrogates)
  5482. if ((byte1 & 0xF0) == 0xE0) {
  5483. byte2 = readContinuationByte();
  5484. byte3 = readContinuationByte();
  5485. codePoint = ((byte1 & 0x0F) << 12) | (byte2 << 6) | byte3;
  5486. if (codePoint >= 0x0800) {
  5487. return codePoint;
  5488. } else {
  5489. throw Error('Invalid continuation byte');
  5490. }
  5491. }
  5492. // 4-byte sequence
  5493. if ((byte1 & 0xF8) == 0xF0) {
  5494. byte2 = readContinuationByte();
  5495. byte3 = readContinuationByte();
  5496. byte4 = readContinuationByte();
  5497. codePoint = ((byte1 & 0x0F) << 0x12) | (byte2 << 0x0C) |
  5498. (byte3 << 0x06) | byte4;
  5499. if (codePoint >= 0x010000 && codePoint <= 0x10FFFF) {
  5500. return codePoint;
  5501. }
  5502. }
  5503. throw Error('Invalid WTF-8 detected');
  5504. }
  5505. var byteArray;
  5506. var byteCount;
  5507. var byteIndex;
  5508. function wtf8decode(byteString) {
  5509. byteArray = ucs2decode(byteString);
  5510. byteCount = byteArray.length;
  5511. byteIndex = 0;
  5512. var codePoints = [];
  5513. var tmp;
  5514. while ((tmp = decodeSymbol()) !== false) {
  5515. codePoints.push(tmp);
  5516. }
  5517. return ucs2encode(codePoints);
  5518. }
  5519. /*--------------------------------------------------------------------------*/
  5520. var wtf8 = {
  5521. 'version': '1.0.0',
  5522. 'encode': wtf8encode,
  5523. 'decode': wtf8decode
  5524. };
  5525. // Some AMD build optimizers, like r.js, check for specific condition patterns
  5526. // like the following:
  5527. if (
  5528. true
  5529. ) {
  5530. !(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
  5531. return wtf8;
  5532. }.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  5533. } else if (freeExports && !freeExports.nodeType) {
  5534. if (freeModule) { // in Node.js or RingoJS v0.8.0+
  5535. freeModule.exports = wtf8;
  5536. } else { // in Narwhal or RingoJS v0.7.0-
  5537. var object = {};
  5538. var hasOwnProperty = object.hasOwnProperty;
  5539. for (var key in wtf8) {
  5540. hasOwnProperty.call(wtf8, key) && (freeExports[key] = wtf8[key]);
  5541. }
  5542. }
  5543. } else { // in Rhino or a web browser
  5544. root.wtf8 = wtf8;
  5545. }
  5546. }(this));
  5547. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(12)(module), (function() { return this; }())))
  5548. /***/ },
  5549. /* 33 */
  5550. /***/ function(module, exports) {
  5551. /*
  5552. * base64-arraybuffer
  5553. * https://github.com/niklasvh/base64-arraybuffer
  5554. *
  5555. * Copyright (c) 2012 Niklas von Hertzen
  5556. * Licensed under the MIT license.
  5557. */
  5558. (function(){
  5559. "use strict";
  5560. var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  5561. // Use a lookup table to find the index.
  5562. var lookup = new Uint8Array(256);
  5563. for (var i = 0; i < chars.length; i++) {
  5564. lookup[chars.charCodeAt(i)] = i;
  5565. }
  5566. exports.encode = function(arraybuffer) {
  5567. var bytes = new Uint8Array(arraybuffer),
  5568. i, len = bytes.length, base64 = "";
  5569. for (i = 0; i < len; i+=3) {
  5570. base64 += chars[bytes[i] >> 2];
  5571. base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
  5572. base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
  5573. base64 += chars[bytes[i + 2] & 63];
  5574. }
  5575. if ((len % 3) === 2) {
  5576. base64 = base64.substring(0, base64.length - 1) + "=";
  5577. } else if (len % 3 === 1) {
  5578. base64 = base64.substring(0, base64.length - 2) + "==";
  5579. }
  5580. return base64;
  5581. };
  5582. exports.decode = function(base64) {
  5583. var bufferLength = base64.length * 0.75,
  5584. len = base64.length, i, p = 0,
  5585. encoded1, encoded2, encoded3, encoded4;
  5586. if (base64[base64.length - 1] === "=") {
  5587. bufferLength--;
  5588. if (base64[base64.length - 2] === "=") {
  5589. bufferLength--;
  5590. }
  5591. }
  5592. var arraybuffer = new ArrayBuffer(bufferLength),
  5593. bytes = new Uint8Array(arraybuffer);
  5594. for (i = 0; i < len; i+=4) {
  5595. encoded1 = lookup[base64.charCodeAt(i)];
  5596. encoded2 = lookup[base64.charCodeAt(i+1)];
  5597. encoded3 = lookup[base64.charCodeAt(i+2)];
  5598. encoded4 = lookup[base64.charCodeAt(i+3)];
  5599. bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
  5600. bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
  5601. bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
  5602. }
  5603. return arraybuffer;
  5604. };
  5605. })();
  5606. /***/ },
  5607. /* 34 */
  5608. /***/ function(module, exports) {
  5609. /* WEBPACK VAR INJECTION */(function(global) {/**
  5610. * Create a blob builder even when vendor prefixes exist
  5611. */
  5612. var BlobBuilder = global.BlobBuilder
  5613. || global.WebKitBlobBuilder
  5614. || global.MSBlobBuilder
  5615. || global.MozBlobBuilder;
  5616. /**
  5617. * Check if Blob constructor is supported
  5618. */
  5619. var blobSupported = (function() {
  5620. try {
  5621. var a = new Blob(['hi']);
  5622. return a.size === 2;
  5623. } catch(e) {
  5624. return false;
  5625. }
  5626. })();
  5627. /**
  5628. * Check if Blob constructor supports ArrayBufferViews
  5629. * Fails in Safari 6, so we need to map to ArrayBuffers there.
  5630. */
  5631. var blobSupportsArrayBufferView = blobSupported && (function() {
  5632. try {
  5633. var b = new Blob([new Uint8Array([1,2])]);
  5634. return b.size === 2;
  5635. } catch(e) {
  5636. return false;
  5637. }
  5638. })();
  5639. /**
  5640. * Check if BlobBuilder is supported
  5641. */
  5642. var blobBuilderSupported = BlobBuilder
  5643. && BlobBuilder.prototype.append
  5644. && BlobBuilder.prototype.getBlob;
  5645. /**
  5646. * Helper function that maps ArrayBufferViews to ArrayBuffers
  5647. * Used by BlobBuilder constructor and old browsers that didn't
  5648. * support it in the Blob constructor.
  5649. */
  5650. function mapArrayBufferViews(ary) {
  5651. for (var i = 0; i < ary.length; i++) {
  5652. var chunk = ary[i];
  5653. if (chunk.buffer instanceof ArrayBuffer) {
  5654. var buf = chunk.buffer;
  5655. // if this is a subarray, make a copy so we only
  5656. // include the subarray region from the underlying buffer
  5657. if (chunk.byteLength !== buf.byteLength) {
  5658. var copy = new Uint8Array(chunk.byteLength);
  5659. copy.set(new Uint8Array(buf, chunk.byteOffset, chunk.byteLength));
  5660. buf = copy.buffer;
  5661. }
  5662. ary[i] = buf;
  5663. }
  5664. }
  5665. }
  5666. function BlobBuilderConstructor(ary, options) {
  5667. options = options || {};
  5668. var bb = new BlobBuilder();
  5669. mapArrayBufferViews(ary);
  5670. for (var i = 0; i < ary.length; i++) {
  5671. bb.append(ary[i]);
  5672. }
  5673. return (options.type) ? bb.getBlob(options.type) : bb.getBlob();
  5674. };
  5675. function BlobConstructor(ary, options) {
  5676. mapArrayBufferViews(ary);
  5677. return new Blob(ary, options || {});
  5678. };
  5679. module.exports = (function() {
  5680. if (blobSupported) {
  5681. return blobSupportsArrayBufferView ? global.Blob : BlobConstructor;
  5682. } else if (blobBuilderSupported) {
  5683. return BlobBuilderConstructor;
  5684. } else {
  5685. return undefined;
  5686. }
  5687. })();
  5688. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  5689. /***/ },
  5690. /* 35 */
  5691. /***/ function(module, exports, __webpack_require__) {
  5692. /**
  5693. * Expose `Emitter`.
  5694. */
  5695. if (true) {
  5696. module.exports = Emitter;
  5697. }
  5698. /**
  5699. * Initialize a new `Emitter`.
  5700. *
  5701. * @api public
  5702. */
  5703. function Emitter(obj) {
  5704. if (obj) return mixin(obj);
  5705. };
  5706. /**
  5707. * Mixin the emitter properties.
  5708. *
  5709. * @param {Object} obj
  5710. * @return {Object}
  5711. * @api private
  5712. */
  5713. function mixin(obj) {
  5714. for (var key in Emitter.prototype) {
  5715. obj[key] = Emitter.prototype[key];
  5716. }
  5717. return obj;
  5718. }
  5719. /**
  5720. * Listen on the given `event` with `fn`.
  5721. *
  5722. * @param {String} event
  5723. * @param {Function} fn
  5724. * @return {Emitter}
  5725. * @api public
  5726. */
  5727. Emitter.prototype.on =
  5728. Emitter.prototype.addEventListener = function(event, fn){
  5729. this._callbacks = this._callbacks || {};
  5730. (this._callbacks['$' + event] = this._callbacks['$' + event] || [])
  5731. .push(fn);
  5732. return this;
  5733. };
  5734. /**
  5735. * Adds an `event` listener that will be invoked a single
  5736. * time then automatically removed.
  5737. *
  5738. * @param {String} event
  5739. * @param {Function} fn
  5740. * @return {Emitter}
  5741. * @api public
  5742. */
  5743. Emitter.prototype.once = function(event, fn){
  5744. function on() {
  5745. this.off(event, on);
  5746. fn.apply(this, arguments);
  5747. }
  5748. on.fn = fn;
  5749. this.on(event, on);
  5750. return this;
  5751. };
  5752. /**
  5753. * Remove the given callback for `event` or all
  5754. * registered callbacks.
  5755. *
  5756. * @param {String} event
  5757. * @param {Function} fn
  5758. * @return {Emitter}
  5759. * @api public
  5760. */
  5761. Emitter.prototype.off =
  5762. Emitter.prototype.removeListener =
  5763. Emitter.prototype.removeAllListeners =
  5764. Emitter.prototype.removeEventListener = function(event, fn){
  5765. this._callbacks = this._callbacks || {};
  5766. // all
  5767. if (0 == arguments.length) {
  5768. this._callbacks = {};
  5769. return this;
  5770. }
  5771. // specific event
  5772. var callbacks = this._callbacks['$' + event];
  5773. if (!callbacks) return this;
  5774. // remove all handlers
  5775. if (1 == arguments.length) {
  5776. delete this._callbacks['$' + event];
  5777. return this;
  5778. }
  5779. // remove specific handler
  5780. var cb;
  5781. for (var i = 0; i < callbacks.length; i++) {
  5782. cb = callbacks[i];
  5783. if (cb === fn || cb.fn === fn) {
  5784. callbacks.splice(i, 1);
  5785. break;
  5786. }
  5787. }
  5788. return this;
  5789. };
  5790. /**
  5791. * Emit `event` with the given args.
  5792. *
  5793. * @param {String} event
  5794. * @param {Mixed} ...
  5795. * @return {Emitter}
  5796. */
  5797. Emitter.prototype.emit = function(event){
  5798. this._callbacks = this._callbacks || {};
  5799. var args = [].slice.call(arguments, 1)
  5800. , callbacks = this._callbacks['$' + event];
  5801. if (callbacks) {
  5802. callbacks = callbacks.slice(0);
  5803. for (var i = 0, len = callbacks.length; i < len; ++i) {
  5804. callbacks[i].apply(this, args);
  5805. }
  5806. }
  5807. return this;
  5808. };
  5809. /**
  5810. * Return array of callbacks for `event`.
  5811. *
  5812. * @param {String} event
  5813. * @return {Array}
  5814. * @api public
  5815. */
  5816. Emitter.prototype.listeners = function(event){
  5817. this._callbacks = this._callbacks || {};
  5818. return this._callbacks['$' + event] || [];
  5819. };
  5820. /**
  5821. * Check if this emitter has `event` handlers.
  5822. *
  5823. * @param {String} event
  5824. * @return {Boolean}
  5825. * @api public
  5826. */
  5827. Emitter.prototype.hasListeners = function(event){
  5828. return !! this.listeners(event).length;
  5829. };
  5830. /***/ },
  5831. /* 36 */
  5832. /***/ function(module, exports) {
  5833. /**
  5834. * Compiles a querystring
  5835. * Returns string representation of the object
  5836. *
  5837. * @param {Object}
  5838. * @api private
  5839. */
  5840. exports.encode = function (obj) {
  5841. var str = '';
  5842. for (var i in obj) {
  5843. if (obj.hasOwnProperty(i)) {
  5844. if (str.length) str += '&';
  5845. str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
  5846. }
  5847. }
  5848. return str;
  5849. };
  5850. /**
  5851. * Parses a simple querystring into an object
  5852. *
  5853. * @param {String} qs
  5854. * @api private
  5855. */
  5856. exports.decode = function(qs){
  5857. var qry = {};
  5858. var pairs = qs.split('&');
  5859. for (var i = 0, l = pairs.length; i < l; i++) {
  5860. var pair = pairs[i].split('=');
  5861. qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  5862. }
  5863. return qry;
  5864. };
  5865. /***/ },
  5866. /* 37 */
  5867. /***/ function(module, exports) {
  5868. module.exports = function(a, b){
  5869. var fn = function(){};
  5870. fn.prototype = b.prototype;
  5871. a.prototype = new fn;
  5872. a.prototype.constructor = a;
  5873. };
  5874. /***/ },
  5875. /* 38 */
  5876. /***/ function(module, exports) {
  5877. 'use strict';
  5878. var alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('')
  5879. , length = 64
  5880. , map = {}
  5881. , seed = 0
  5882. , i = 0
  5883. , prev;
  5884. /**
  5885. * Return a string representing the specified number.
  5886. *
  5887. * @param {Number} num The number to convert.
  5888. * @returns {String} The string representation of the number.
  5889. * @api public
  5890. */
  5891. function encode(num) {
  5892. var encoded = '';
  5893. do {
  5894. encoded = alphabet[num % length] + encoded;
  5895. num = Math.floor(num / length);
  5896. } while (num > 0);
  5897. return encoded;
  5898. }
  5899. /**
  5900. * Return the integer value specified by the given string.
  5901. *
  5902. * @param {String} str The string to convert.
  5903. * @returns {Number} The integer value represented by the string.
  5904. * @api public
  5905. */
  5906. function decode(str) {
  5907. var decoded = 0;
  5908. for (i = 0; i < str.length; i++) {
  5909. decoded = decoded * length + map[str.charAt(i)];
  5910. }
  5911. return decoded;
  5912. }
  5913. /**
  5914. * Yeast: A tiny growing id generator.
  5915. *
  5916. * @returns {String} A unique id.
  5917. * @api public
  5918. */
  5919. function yeast() {
  5920. var now = encode(+new Date());
  5921. if (now !== prev) return seed = 0, prev = now;
  5922. return now +'.'+ encode(seed++);
  5923. }
  5924. //
  5925. // Map each character to its index.
  5926. //
  5927. for (; i < length; i++) map[alphabet[i]] = i;
  5928. //
  5929. // Expose the `yeast`, `encode` and `decode` functions.
  5930. //
  5931. yeast.encode = encode;
  5932. yeast.decode = decode;
  5933. module.exports = yeast;
  5934. /***/ },
  5935. /* 39 */
  5936. /***/ function(module, exports, __webpack_require__) {
  5937. /* WEBPACK VAR INJECTION */(function(global) {
  5938. /**
  5939. * Module requirements.
  5940. */
  5941. var Polling = __webpack_require__(25);
  5942. var inherit = __webpack_require__(37);
  5943. /**
  5944. * Module exports.
  5945. */
  5946. module.exports = JSONPPolling;
  5947. /**
  5948. * Cached regular expressions.
  5949. */
  5950. var rNewline = /\n/g;
  5951. var rEscapedNewline = /\\n/g;
  5952. /**
  5953. * Global JSONP callbacks.
  5954. */
  5955. var callbacks;
  5956. /**
  5957. * Noop.
  5958. */
  5959. function empty () { }
  5960. /**
  5961. * JSONP Polling constructor.
  5962. *
  5963. * @param {Object} opts.
  5964. * @api public
  5965. */
  5966. function JSONPPolling (opts) {
  5967. Polling.call(this, opts);
  5968. this.query = this.query || {};
  5969. // define global callbacks array if not present
  5970. // we do this here (lazily) to avoid unneeded global pollution
  5971. if (!callbacks) {
  5972. // we need to consider multiple engines in the same page
  5973. if (!global.___eio) global.___eio = [];
  5974. callbacks = global.___eio;
  5975. }
  5976. // callback identifier
  5977. this.index = callbacks.length;
  5978. // add callback to jsonp global
  5979. var self = this;
  5980. callbacks.push(function (msg) {
  5981. self.onData(msg);
  5982. });
  5983. // append to query string
  5984. this.query.j = this.index;
  5985. // prevent spurious errors from being emitted when the window is unloaded
  5986. if (global.document && global.addEventListener) {
  5987. global.addEventListener('beforeunload', function () {
  5988. if (self.script) self.script.onerror = empty;
  5989. }, false);
  5990. }
  5991. }
  5992. /**
  5993. * Inherits from Polling.
  5994. */
  5995. inherit(JSONPPolling, Polling);
  5996. /*
  5997. * JSONP only supports binary as base64 encoded strings
  5998. */
  5999. JSONPPolling.prototype.supportsBinary = false;
  6000. /**
  6001. * Closes the socket.
  6002. *
  6003. * @api private
  6004. */
  6005. JSONPPolling.prototype.doClose = function () {
  6006. if (this.script) {
  6007. this.script.parentNode.removeChild(this.script);
  6008. this.script = null;
  6009. }
  6010. if (this.form) {
  6011. this.form.parentNode.removeChild(this.form);
  6012. this.form = null;
  6013. this.iframe = null;
  6014. }
  6015. Polling.prototype.doClose.call(this);
  6016. };
  6017. /**
  6018. * Starts a poll cycle.
  6019. *
  6020. * @api private
  6021. */
  6022. JSONPPolling.prototype.doPoll = function () {
  6023. var self = this;
  6024. var script = document.createElement('script');
  6025. if (this.script) {
  6026. this.script.parentNode.removeChild(this.script);
  6027. this.script = null;
  6028. }
  6029. script.async = true;
  6030. script.src = this.uri();
  6031. script.onerror = function (e) {
  6032. self.onError('jsonp poll error', e);
  6033. };
  6034. var insertAt = document.getElementsByTagName('script')[0];
  6035. if (insertAt) {
  6036. insertAt.parentNode.insertBefore(script, insertAt);
  6037. } else {
  6038. (document.head || document.body).appendChild(script);
  6039. }
  6040. this.script = script;
  6041. var isUAgecko = 'undefined' !== typeof navigator && /gecko/i.test(navigator.userAgent);
  6042. if (isUAgecko) {
  6043. setTimeout(function () {
  6044. var iframe = document.createElement('iframe');
  6045. document.body.appendChild(iframe);
  6046. document.body.removeChild(iframe);
  6047. }, 100);
  6048. }
  6049. };
  6050. /**
  6051. * Writes with a hidden iframe.
  6052. *
  6053. * @param {String} data to send
  6054. * @param {Function} called upon flush.
  6055. * @api private
  6056. */
  6057. JSONPPolling.prototype.doWrite = function (data, fn) {
  6058. var self = this;
  6059. if (!this.form) {
  6060. var form = document.createElement('form');
  6061. var area = document.createElement('textarea');
  6062. var id = this.iframeId = 'eio_iframe_' + this.index;
  6063. var iframe;
  6064. form.className = 'socketio';
  6065. form.style.position = 'absolute';
  6066. form.style.top = '-1000px';
  6067. form.style.left = '-1000px';
  6068. form.target = id;
  6069. form.method = 'POST';
  6070. form.setAttribute('accept-charset', 'utf-8');
  6071. area.name = 'd';
  6072. form.appendChild(area);
  6073. document.body.appendChild(form);
  6074. this.form = form;
  6075. this.area = area;
  6076. }
  6077. this.form.action = this.uri();
  6078. function complete () {
  6079. initIframe();
  6080. fn();
  6081. }
  6082. function initIframe () {
  6083. if (self.iframe) {
  6084. try {
  6085. self.form.removeChild(self.iframe);
  6086. } catch (e) {
  6087. self.onError('jsonp polling iframe removal error', e);
  6088. }
  6089. }
  6090. try {
  6091. // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
  6092. var html = '<iframe src="javascript:0" name="' + self.iframeId + '">';
  6093. iframe = document.createElement(html);
  6094. } catch (e) {
  6095. iframe = document.createElement('iframe');
  6096. iframe.name = self.iframeId;
  6097. iframe.src = 'javascript:0';
  6098. }
  6099. iframe.id = self.iframeId;
  6100. self.form.appendChild(iframe);
  6101. self.iframe = iframe;
  6102. }
  6103. initIframe();
  6104. // escape \n to prevent it from being converted into \r\n by some UAs
  6105. // double escaping is required for escaped new lines because unescaping of new lines can be done safely on server-side
  6106. data = data.replace(rEscapedNewline, '\\\n');
  6107. this.area.value = data.replace(rNewline, '\\n');
  6108. try {
  6109. this.form.submit();
  6110. } catch (e) {}
  6111. if (this.iframe.attachEvent) {
  6112. this.iframe.onreadystatechange = function () {
  6113. if (self.iframe.readyState === 'complete') {
  6114. complete();
  6115. }
  6116. };
  6117. } else {
  6118. this.iframe.onload = complete;
  6119. }
  6120. };
  6121. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  6122. /***/ },
  6123. /* 40 */
  6124. /***/ function(module, exports, __webpack_require__) {
  6125. /* WEBPACK VAR INJECTION */(function(global) {/**
  6126. * Module dependencies.
  6127. */
  6128. var Transport = __webpack_require__(26);
  6129. var parser = __webpack_require__(27);
  6130. var parseqs = __webpack_require__(36);
  6131. var inherit = __webpack_require__(37);
  6132. var yeast = __webpack_require__(38);
  6133. var debug = __webpack_require__(3)('engine.io-client:websocket');
  6134. var BrowserWebSocket = global.WebSocket || global.MozWebSocket;
  6135. var NodeWebSocket;
  6136. if (typeof window === 'undefined') {
  6137. try {
  6138. NodeWebSocket = __webpack_require__(41);
  6139. } catch (e) { }
  6140. }
  6141. /**
  6142. * Get either the `WebSocket` or `MozWebSocket` globals
  6143. * in the browser or try to resolve WebSocket-compatible
  6144. * interface exposed by `ws` for Node-like environment.
  6145. */
  6146. var WebSocket = BrowserWebSocket;
  6147. if (!WebSocket && typeof window === 'undefined') {
  6148. WebSocket = NodeWebSocket;
  6149. }
  6150. /**
  6151. * Module exports.
  6152. */
  6153. module.exports = WS;
  6154. /**
  6155. * WebSocket transport constructor.
  6156. *
  6157. * @api {Object} connection options
  6158. * @api public
  6159. */
  6160. function WS (opts) {
  6161. var forceBase64 = (opts && opts.forceBase64);
  6162. if (forceBase64) {
  6163. this.supportsBinary = false;
  6164. }
  6165. this.perMessageDeflate = opts.perMessageDeflate;
  6166. this.usingBrowserWebSocket = BrowserWebSocket && !opts.forceNode;
  6167. if (!this.usingBrowserWebSocket) {
  6168. WebSocket = NodeWebSocket;
  6169. }
  6170. Transport.call(this, opts);
  6171. }
  6172. /**
  6173. * Inherits from Transport.
  6174. */
  6175. inherit(WS, Transport);
  6176. /**
  6177. * Transport name.
  6178. *
  6179. * @api public
  6180. */
  6181. WS.prototype.name = 'websocket';
  6182. /*
  6183. * WebSockets support binary
  6184. */
  6185. WS.prototype.supportsBinary = true;
  6186. /**
  6187. * Opens socket.
  6188. *
  6189. * @api private
  6190. */
  6191. WS.prototype.doOpen = function () {
  6192. if (!this.check()) {
  6193. // let probe timeout
  6194. return;
  6195. }
  6196. var uri = this.uri();
  6197. var protocols = void (0);
  6198. var opts = {
  6199. agent: this.agent,
  6200. perMessageDeflate: this.perMessageDeflate
  6201. };
  6202. // SSL options for Node.js client
  6203. opts.pfx = this.pfx;
  6204. opts.key = this.key;
  6205. opts.passphrase = this.passphrase;
  6206. opts.cert = this.cert;
  6207. opts.ca = this.ca;
  6208. opts.ciphers = this.ciphers;
  6209. opts.rejectUnauthorized = this.rejectUnauthorized;
  6210. if (this.extraHeaders) {
  6211. opts.headers = this.extraHeaders;
  6212. }
  6213. if (this.localAddress) {
  6214. opts.localAddress = this.localAddress;
  6215. }
  6216. try {
  6217. this.ws = this.usingBrowserWebSocket ? new WebSocket(uri) : new WebSocket(uri, protocols, opts);
  6218. } catch (err) {
  6219. return this.emit('error', err);
  6220. }
  6221. if (this.ws.binaryType === undefined) {
  6222. this.supportsBinary = false;
  6223. }
  6224. if (this.ws.supports && this.ws.supports.binary) {
  6225. this.supportsBinary = true;
  6226. this.ws.binaryType = 'nodebuffer';
  6227. } else {
  6228. this.ws.binaryType = 'arraybuffer';
  6229. }
  6230. this.addEventListeners();
  6231. };
  6232. /**
  6233. * Adds event listeners to the socket
  6234. *
  6235. * @api private
  6236. */
  6237. WS.prototype.addEventListeners = function () {
  6238. var self = this;
  6239. this.ws.onopen = function () {
  6240. self.onOpen();
  6241. };
  6242. this.ws.onclose = function () {
  6243. self.onClose();
  6244. };
  6245. this.ws.onmessage = function (ev) {
  6246. self.onData(ev.data);
  6247. };
  6248. this.ws.onerror = function (e) {
  6249. self.onError('websocket error', e);
  6250. };
  6251. };
  6252. /**
  6253. * Writes data to socket.
  6254. *
  6255. * @param {Array} array of packets.
  6256. * @api private
  6257. */
  6258. WS.prototype.write = function (packets) {
  6259. var self = this;
  6260. this.writable = false;
  6261. // encodePacket efficient as it uses WS framing
  6262. // no need for encodePayload
  6263. var total = packets.length;
  6264. for (var i = 0, l = total; i < l; i++) {
  6265. (function (packet) {
  6266. parser.encodePacket(packet, self.supportsBinary, function (data) {
  6267. if (!self.usingBrowserWebSocket) {
  6268. // always create a new object (GH-437)
  6269. var opts = {};
  6270. if (packet.options) {
  6271. opts.compress = packet.options.compress;
  6272. }
  6273. if (self.perMessageDeflate) {
  6274. var len = 'string' === typeof data ? global.Buffer.byteLength(data) : data.length;
  6275. if (len < self.perMessageDeflate.threshold) {
  6276. opts.compress = false;
  6277. }
  6278. }
  6279. }
  6280. // Sometimes the websocket has already been closed but the browser didn't
  6281. // have a chance of informing us about it yet, in that case send will
  6282. // throw an error
  6283. try {
  6284. if (self.usingBrowserWebSocket) {
  6285. // TypeError is thrown when passing the second argument on Safari
  6286. self.ws.send(data);
  6287. } else {
  6288. self.ws.send(data, opts);
  6289. }
  6290. } catch (e) {
  6291. debug('websocket closed before onclose event');
  6292. }
  6293. --total || done();
  6294. });
  6295. })(packets[i]);
  6296. }
  6297. function done () {
  6298. self.emit('flush');
  6299. // fake drain
  6300. // defer to next tick to allow Socket to clear writeBuffer
  6301. setTimeout(function () {
  6302. self.writable = true;
  6303. self.emit('drain');
  6304. }, 0);
  6305. }
  6306. };
  6307. /**
  6308. * Called upon close
  6309. *
  6310. * @api private
  6311. */
  6312. WS.prototype.onClose = function () {
  6313. Transport.prototype.onClose.call(this);
  6314. };
  6315. /**
  6316. * Closes socket.
  6317. *
  6318. * @api private
  6319. */
  6320. WS.prototype.doClose = function () {
  6321. if (typeof this.ws !== 'undefined') {
  6322. this.ws.close();
  6323. }
  6324. };
  6325. /**
  6326. * Generates uri for connection.
  6327. *
  6328. * @api private
  6329. */
  6330. WS.prototype.uri = function () {
  6331. var query = this.query || {};
  6332. var schema = this.secure ? 'wss' : 'ws';
  6333. var port = '';
  6334. // avoid port if default for schema
  6335. if (this.port && (('wss' === schema && Number(this.port) !== 443) ||
  6336. ('ws' === schema && Number(this.port) !== 80))) {
  6337. port = ':' + this.port;
  6338. }
  6339. // append timestamp to URI
  6340. if (this.timestampRequests) {
  6341. query[this.timestampParam] = yeast();
  6342. }
  6343. // communicate binary support capabilities
  6344. if (!this.supportsBinary) {
  6345. query.b64 = 1;
  6346. }
  6347. query = parseqs.encode(query);
  6348. // prepend ? to query
  6349. if (query.length) {
  6350. query = '?' + query;
  6351. }
  6352. var ipv6 = this.hostname.indexOf(':') !== -1;
  6353. return schema + '://' + (ipv6 ? '[' + this.hostname + ']' : this.hostname) + port + this.path + query;
  6354. };
  6355. /**
  6356. * Feature detection for WebSocket.
  6357. *
  6358. * @return {Boolean} whether this transport is available.
  6359. * @api public
  6360. */
  6361. WS.prototype.check = function () {
  6362. return !!WebSocket && !('__initialize' in WebSocket && this.name === WS.prototype.name);
  6363. };
  6364. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  6365. /***/ },
  6366. /* 41 */
  6367. /***/ function(module, exports) {
  6368. /* (ignored) */
  6369. /***/ },
  6370. /* 42 */
  6371. /***/ function(module, exports) {
  6372. var indexOf = [].indexOf;
  6373. module.exports = function(arr, obj){
  6374. if (indexOf) return arr.indexOf(obj);
  6375. for (var i = 0; i < arr.length; ++i) {
  6376. if (arr[i] === obj) return i;
  6377. }
  6378. return -1;
  6379. };
  6380. /***/ },
  6381. /* 43 */
  6382. /***/ function(module, exports) {
  6383. /* WEBPACK VAR INJECTION */(function(global) {/**
  6384. * JSON parse.
  6385. *
  6386. * @see Based on jQuery#parseJSON (MIT) and JSON2
  6387. * @api private
  6388. */
  6389. var rvalidchars = /^[\],:{}\s]*$/;
  6390. var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
  6391. var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
  6392. var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
  6393. var rtrimLeft = /^\s+/;
  6394. var rtrimRight = /\s+$/;
  6395. module.exports = function parsejson(data) {
  6396. if ('string' != typeof data || !data) {
  6397. return null;
  6398. }
  6399. data = data.replace(rtrimLeft, '').replace(rtrimRight, '');
  6400. // Attempt to parse using the native JSON parser first
  6401. if (global.JSON && JSON.parse) {
  6402. return JSON.parse(data);
  6403. }
  6404. if (rvalidchars.test(data.replace(rvalidescape, '@')
  6405. .replace(rvalidtokens, ']')
  6406. .replace(rvalidbraces, ''))) {
  6407. return (new Function('return ' + data))();
  6408. }
  6409. };
  6410. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  6411. /***/ },
  6412. /* 44 */
  6413. /***/ function(module, exports, __webpack_require__) {
  6414. 'use strict';
  6415. /**
  6416. * Module dependencies.
  6417. */
  6418. var parser = __webpack_require__(7);
  6419. var Emitter = __webpack_require__(35);
  6420. var toArray = __webpack_require__(45);
  6421. var on = __webpack_require__(46);
  6422. var bind = __webpack_require__(47);
  6423. var debug = __webpack_require__(3)('socket.io-client:socket');
  6424. var hasBin = __webpack_require__(29);
  6425. /**
  6426. * Module exports.
  6427. */
  6428. module.exports = exports = Socket;
  6429. /**
  6430. * Internal events (blacklisted).
  6431. * These events can't be emitted by the user.
  6432. *
  6433. * @api private
  6434. */
  6435. var events = {
  6436. connect: 1,
  6437. connect_error: 1,
  6438. connect_timeout: 1,
  6439. connecting: 1,
  6440. disconnect: 1,
  6441. error: 1,
  6442. reconnect: 1,
  6443. reconnect_attempt: 1,
  6444. reconnect_failed: 1,
  6445. reconnect_error: 1,
  6446. reconnecting: 1,
  6447. ping: 1,
  6448. pong: 1
  6449. };
  6450. /**
  6451. * Shortcut to `Emitter#emit`.
  6452. */
  6453. var emit = Emitter.prototype.emit;
  6454. /**
  6455. * `Socket` constructor.
  6456. *
  6457. * @api public
  6458. */
  6459. function Socket(io, nsp, opts) {
  6460. this.io = io;
  6461. this.nsp = nsp;
  6462. this.json = this; // compat
  6463. this.ids = 0;
  6464. this.acks = {};
  6465. this.receiveBuffer = [];
  6466. this.sendBuffer = [];
  6467. this.connected = false;
  6468. this.disconnected = true;
  6469. if (opts && opts.query) {
  6470. this.query = opts.query;
  6471. }
  6472. if (this.io.autoConnect) this.open();
  6473. }
  6474. /**
  6475. * Mix in `Emitter`.
  6476. */
  6477. Emitter(Socket.prototype);
  6478. /**
  6479. * Subscribe to open, close and packet events
  6480. *
  6481. * @api private
  6482. */
  6483. Socket.prototype.subEvents = function () {
  6484. if (this.subs) return;
  6485. var io = this.io;
  6486. this.subs = [on(io, 'open', bind(this, 'onopen')), on(io, 'packet', bind(this, 'onpacket')), on(io, 'close', bind(this, 'onclose'))];
  6487. };
  6488. /**
  6489. * "Opens" the socket.
  6490. *
  6491. * @api public
  6492. */
  6493. Socket.prototype.open = Socket.prototype.connect = function () {
  6494. if (this.connected) return this;
  6495. this.subEvents();
  6496. this.io.open(); // ensure open
  6497. if ('open' === this.io.readyState) this.onopen();
  6498. this.emit('connecting');
  6499. return this;
  6500. };
  6501. /**
  6502. * Sends a `message` event.
  6503. *
  6504. * @return {Socket} self
  6505. * @api public
  6506. */
  6507. Socket.prototype.send = function () {
  6508. var args = toArray(arguments);
  6509. args.unshift('message');
  6510. this.emit.apply(this, args);
  6511. return this;
  6512. };
  6513. /**
  6514. * Override `emit`.
  6515. * If the event is in `events`, it's emitted normally.
  6516. *
  6517. * @param {String} event name
  6518. * @return {Socket} self
  6519. * @api public
  6520. */
  6521. Socket.prototype.emit = function (ev) {
  6522. if (events.hasOwnProperty(ev)) {
  6523. emit.apply(this, arguments);
  6524. return this;
  6525. }
  6526. var args = toArray(arguments);
  6527. var parserType = parser.EVENT; // default
  6528. if (hasBin(args)) {
  6529. parserType = parser.BINARY_EVENT;
  6530. } // binary
  6531. var packet = { type: parserType, data: args };
  6532. packet.options = {};
  6533. packet.options.compress = !this.flags || false !== this.flags.compress;
  6534. // event ack callback
  6535. if ('function' === typeof args[args.length - 1]) {
  6536. debug('emitting packet with ack id %d', this.ids);
  6537. this.acks[this.ids] = args.pop();
  6538. packet.id = this.ids++;
  6539. }
  6540. if (this.connected) {
  6541. this.packet(packet);
  6542. } else {
  6543. this.sendBuffer.push(packet);
  6544. }
  6545. delete this.flags;
  6546. return this;
  6547. };
  6548. /**
  6549. * Sends a packet.
  6550. *
  6551. * @param {Object} packet
  6552. * @api private
  6553. */
  6554. Socket.prototype.packet = function (packet) {
  6555. packet.nsp = this.nsp;
  6556. this.io.packet(packet);
  6557. };
  6558. /**
  6559. * Called upon engine `open`.
  6560. *
  6561. * @api private
  6562. */
  6563. Socket.prototype.onopen = function () {
  6564. debug('transport is open - connecting');
  6565. // write connect packet if necessary
  6566. if ('/' !== this.nsp) {
  6567. if (this.query) {
  6568. this.packet({ type: parser.CONNECT, query: this.query });
  6569. } else {
  6570. this.packet({ type: parser.CONNECT });
  6571. }
  6572. }
  6573. };
  6574. /**
  6575. * Called upon engine `close`.
  6576. *
  6577. * @param {String} reason
  6578. * @api private
  6579. */
  6580. Socket.prototype.onclose = function (reason) {
  6581. debug('close (%s)', reason);
  6582. this.connected = false;
  6583. this.disconnected = true;
  6584. delete this.id;
  6585. this.emit('disconnect', reason);
  6586. };
  6587. /**
  6588. * Called with socket packet.
  6589. *
  6590. * @param {Object} packet
  6591. * @api private
  6592. */
  6593. Socket.prototype.onpacket = function (packet) {
  6594. if (packet.nsp !== this.nsp) return;
  6595. switch (packet.type) {
  6596. case parser.CONNECT:
  6597. this.onconnect();
  6598. break;
  6599. case parser.EVENT:
  6600. this.onevent(packet);
  6601. break;
  6602. case parser.BINARY_EVENT:
  6603. this.onevent(packet);
  6604. break;
  6605. case parser.ACK:
  6606. this.onack(packet);
  6607. break;
  6608. case parser.BINARY_ACK:
  6609. this.onack(packet);
  6610. break;
  6611. case parser.DISCONNECT:
  6612. this.ondisconnect();
  6613. break;
  6614. case parser.ERROR:
  6615. this.emit('error', packet.data);
  6616. break;
  6617. }
  6618. };
  6619. /**
  6620. * Called upon a server event.
  6621. *
  6622. * @param {Object} packet
  6623. * @api private
  6624. */
  6625. Socket.prototype.onevent = function (packet) {
  6626. var args = packet.data || [];
  6627. debug('emitting event %j', args);
  6628. if (null != packet.id) {
  6629. debug('attaching ack callback to event');
  6630. args.push(this.ack(packet.id));
  6631. }
  6632. if (this.connected) {
  6633. emit.apply(this, args);
  6634. } else {
  6635. this.receiveBuffer.push(args);
  6636. }
  6637. };
  6638. /**
  6639. * Produces an ack callback to emit with an event.
  6640. *
  6641. * @api private
  6642. */
  6643. Socket.prototype.ack = function (id) {
  6644. var self = this;
  6645. var sent = false;
  6646. return function () {
  6647. // prevent double callbacks
  6648. if (sent) return;
  6649. sent = true;
  6650. var args = toArray(arguments);
  6651. debug('sending ack %j', args);
  6652. var type = hasBin(args) ? parser.BINARY_ACK : parser.ACK;
  6653. self.packet({
  6654. type: type,
  6655. id: id,
  6656. data: args
  6657. });
  6658. };
  6659. };
  6660. /**
  6661. * Called upon a server acknowlegement.
  6662. *
  6663. * @param {Object} packet
  6664. * @api private
  6665. */
  6666. Socket.prototype.onack = function (packet) {
  6667. var ack = this.acks[packet.id];
  6668. if ('function' === typeof ack) {
  6669. debug('calling ack %s with %j', packet.id, packet.data);
  6670. ack.apply(this, packet.data);
  6671. delete this.acks[packet.id];
  6672. } else {
  6673. debug('bad ack %s', packet.id);
  6674. }
  6675. };
  6676. /**
  6677. * Called upon server connect.
  6678. *
  6679. * @api private
  6680. */
  6681. Socket.prototype.onconnect = function () {
  6682. this.connected = true;
  6683. this.disconnected = false;
  6684. this.emit('connect');
  6685. this.emitBuffered();
  6686. };
  6687. /**
  6688. * Emit buffered events (received and emitted).
  6689. *
  6690. * @api private
  6691. */
  6692. Socket.prototype.emitBuffered = function () {
  6693. var i;
  6694. for (i = 0; i < this.receiveBuffer.length; i++) {
  6695. emit.apply(this, this.receiveBuffer[i]);
  6696. }
  6697. this.receiveBuffer = [];
  6698. for (i = 0; i < this.sendBuffer.length; i++) {
  6699. this.packet(this.sendBuffer[i]);
  6700. }
  6701. this.sendBuffer = [];
  6702. };
  6703. /**
  6704. * Called upon server disconnect.
  6705. *
  6706. * @api private
  6707. */
  6708. Socket.prototype.ondisconnect = function () {
  6709. debug('server disconnect (%s)', this.nsp);
  6710. this.destroy();
  6711. this.onclose('io server disconnect');
  6712. };
  6713. /**
  6714. * Called upon forced client/server side disconnections,
  6715. * this method ensures the manager stops tracking us and
  6716. * that reconnections don't get triggered for this.
  6717. *
  6718. * @api private.
  6719. */
  6720. Socket.prototype.destroy = function () {
  6721. if (this.subs) {
  6722. // clean subscriptions to avoid reconnections
  6723. for (var i = 0; i < this.subs.length; i++) {
  6724. this.subs[i].destroy();
  6725. }
  6726. this.subs = null;
  6727. }
  6728. this.io.destroy(this);
  6729. };
  6730. /**
  6731. * Disconnects the socket manually.
  6732. *
  6733. * @return {Socket} self
  6734. * @api public
  6735. */
  6736. Socket.prototype.close = Socket.prototype.disconnect = function () {
  6737. if (this.connected) {
  6738. debug('performing disconnect (%s)', this.nsp);
  6739. this.packet({ type: parser.DISCONNECT });
  6740. }
  6741. // remove socket from pool
  6742. this.destroy();
  6743. if (this.connected) {
  6744. // fire events
  6745. this.onclose('io client disconnect');
  6746. }
  6747. return this;
  6748. };
  6749. /**
  6750. * Sets the compress flag.
  6751. *
  6752. * @param {Boolean} if `true`, compresses the sending data
  6753. * @return {Socket} self
  6754. * @api public
  6755. */
  6756. Socket.prototype.compress = function (compress) {
  6757. this.flags = this.flags || {};
  6758. this.flags.compress = compress;
  6759. return this;
  6760. };
  6761. /***/ },
  6762. /* 45 */
  6763. /***/ function(module, exports) {
  6764. module.exports = toArray
  6765. function toArray(list, index) {
  6766. var array = []
  6767. index = index || 0
  6768. for (var i = index || 0; i < list.length; i++) {
  6769. array[i - index] = list[i]
  6770. }
  6771. return array
  6772. }
  6773. /***/ },
  6774. /* 46 */
  6775. /***/ function(module, exports) {
  6776. "use strict";
  6777. /**
  6778. * Module exports.
  6779. */
  6780. module.exports = on;
  6781. /**
  6782. * Helper for subscriptions.
  6783. *
  6784. * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter`
  6785. * @param {String} event name
  6786. * @param {Function} callback
  6787. * @api public
  6788. */
  6789. function on(obj, ev, fn) {
  6790. obj.on(ev, fn);
  6791. return {
  6792. destroy: function destroy() {
  6793. obj.removeListener(ev, fn);
  6794. }
  6795. };
  6796. }
  6797. /***/ },
  6798. /* 47 */
  6799. /***/ function(module, exports) {
  6800. /**
  6801. * Slice reference.
  6802. */
  6803. var slice = [].slice;
  6804. /**
  6805. * Bind `obj` to `fn`.
  6806. *
  6807. * @param {Object} obj
  6808. * @param {Function|String} fn or string
  6809. * @return {Function}
  6810. * @api public
  6811. */
  6812. module.exports = function(obj, fn){
  6813. if ('string' == typeof fn) fn = obj[fn];
  6814. if ('function' != typeof fn) throw new Error('bind() requires a function');
  6815. var args = slice.call(arguments, 2);
  6816. return function(){
  6817. return fn.apply(obj, args.concat(slice.call(arguments)));
  6818. }
  6819. };
  6820. /***/ },
  6821. /* 48 */
  6822. /***/ function(module, exports) {
  6823. /**
  6824. * Expose `Backoff`.
  6825. */
  6826. module.exports = Backoff;
  6827. /**
  6828. * Initialize backoff timer with `opts`.
  6829. *
  6830. * - `min` initial timeout in milliseconds [100]
  6831. * - `max` max timeout [10000]
  6832. * - `jitter` [0]
  6833. * - `factor` [2]
  6834. *
  6835. * @param {Object} opts
  6836. * @api public
  6837. */
  6838. function Backoff(opts) {
  6839. opts = opts || {};
  6840. this.ms = opts.min || 100;
  6841. this.max = opts.max || 10000;
  6842. this.factor = opts.factor || 2;
  6843. this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;
  6844. this.attempts = 0;
  6845. }
  6846. /**
  6847. * Return the backoff duration.
  6848. *
  6849. * @return {Number}
  6850. * @api public
  6851. */
  6852. Backoff.prototype.duration = function(){
  6853. var ms = this.ms * Math.pow(this.factor, this.attempts++);
  6854. if (this.jitter) {
  6855. var rand = Math.random();
  6856. var deviation = Math.floor(rand * this.jitter * ms);
  6857. ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;
  6858. }
  6859. return Math.min(ms, this.max) | 0;
  6860. };
  6861. /**
  6862. * Reset the number of attempts.
  6863. *
  6864. * @api public
  6865. */
  6866. Backoff.prototype.reset = function(){
  6867. this.attempts = 0;
  6868. };
  6869. /**
  6870. * Set the minimum duration
  6871. *
  6872. * @api public
  6873. */
  6874. Backoff.prototype.setMin = function(min){
  6875. this.ms = min;
  6876. };
  6877. /**
  6878. * Set the maximum duration
  6879. *
  6880. * @api public
  6881. */
  6882. Backoff.prototype.setMax = function(max){
  6883. this.max = max;
  6884. };
  6885. /**
  6886. * Set the jitter
  6887. *
  6888. * @api public
  6889. */
  6890. Backoff.prototype.setJitter = function(jitter){
  6891. this.jitter = jitter;
  6892. };
  6893. /***/ }
  6894. /******/ ])
  6895. });
  6896. ;
  6897. //# sourceMappingURL=socket.io.js.map