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