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