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