Passed
Push — master ( 445067...6ce435 )
by Johan
02:18
created

node_modules/engine.io-client/engine.io.js   F

Complexity

Total Complexity 684
Complexity/F 2.44

Size

Lines of Code 4709
Function Count 280

Duplication

Duplicated Lines 1887
Ratio 40.07 %

Importance

Changes 0
Metric Value
wmc 684
eloc 2187
mnd 404
bc 404
fnc 280
dl 1887
loc 4709
rs 0.8
bpm 1.4428
cpm 2.4428
noi 19
c 0
b 0
f 0

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like node_modules/engine.io-client/engine.io.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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