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