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