├── .babelrc ├── .eslintrc.yml ├── .gitignore ├── README.md ├── dist ├── index.js └── index.js.map ├── package.json ├── src ├── debug.js ├── engine.js ├── index.js ├── manager.js ├── on.js ├── parsejson.js ├── parser.js ├── socket.js └── url.js ├── weapp_demo ├── app.js ├── app.json ├── app.wxss ├── pages │ ├── index │ │ ├── index.js │ │ ├── index.wxml │ │ └── index.wxss │ └── room │ │ ├── index.js │ │ ├── index.wxml │ │ └── index.wxss ├── utils │ └── util.js └── wxsocket.io │ └── index.js ├── webpack.config.js └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": ["transform-runtime"] 4 | } 5 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | # Support ES2016 features 2 | extends: airbnb 3 | 4 | parser: babel-eslint 5 | 6 | # plugins: [ 7 | # "babel" 8 | # ] 9 | 10 | parserOptions: 11 | sourceType: module 12 | 13 | rules: 14 | strict: 0 15 | arrow-parens: 0 16 | # babel/arrow-parens: 1 17 | # babel/generator-star-spacing: 1 18 | # babel/new-cap: 1 19 | # babel/array-bracket-spacing: 1 20 | # babel/object-curly-spacing: [1, "always"] 21 | # babel/object-shorthand: 1 22 | # babel/no-await-in-loop: 1 23 | # babel/flow-object-type: 1 24 | no-console: 0 25 | spaced-comment: [2, "always", { exceptions: ["-"]}] 26 | eqeqeq: 0 27 | no-return-assign: 0 # fails for arrow functions 28 | no-var: 2 29 | semi: [2, never] 30 | space-before-function-paren: [2, "never"] 31 | yoda: 0 32 | arrow-spacing: 2 33 | dot-location: [2, "property"] 34 | prefer-arrow-callback: 2 35 | keyword-spacing: [2, { after: true, before: true }] 36 | indent: [2, 2] 37 | camelcase: 0 38 | key-spacing: [1, { beforeColon: false, afterColon: true, mode: "minimum" }] 39 | space-in-parens: [1, "never"] 40 | arrow-body-style: [1, "as-needed"] 41 | no-param-reassign: 0 42 | no-unused-vars: [1, {"vars": "local", "args": "none"}] 43 | no-unused-expressions: ["error", { "allowShortCircuit": true }] 44 | no-restricted-syntax: 0 45 | new-cap: ["error", { "capIsNew": false }] 46 | # new-cap: [2, {"capIsNewExceptions": ["Immutable.Map", "Immutable.Set", "Immutable.List"]}] 47 | no-underscore-dangle: 0 48 | no-use-before-define: 0 49 | func-names: 0 50 | no-cond-assign: 0 51 | default-case: 0 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 更新 2 | 请使用新项目 [https://github.com/wxsocketio/weapp.socket.io](https://github.com/wxsocketio/weapp.socket.io) 3 | 4 | 此项目已经不在维护 5 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | (function webpackUniversalModuleDefinition(root, factory) { 2 | if(typeof exports === 'object' && typeof module === 'object') 3 | module.exports = factory(); 4 | else if(typeof define === 'function' && define.amd) 5 | define([], factory); 6 | else { 7 | var a = factory(); 8 | for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; 9 | } 10 | })(this, function() { 11 | return /******/ (function(modules) { // webpackBootstrap 12 | /******/ // The module cache 13 | /******/ var installedModules = {}; 14 | /******/ 15 | /******/ // The require function 16 | /******/ function __webpack_require__(moduleId) { 17 | /******/ 18 | /******/ // Check if module is in cache 19 | /******/ if(installedModules[moduleId]) 20 | /******/ return installedModules[moduleId].exports; 21 | /******/ 22 | /******/ // Create a new module (and put it into the cache) 23 | /******/ var module = installedModules[moduleId] = { 24 | /******/ exports: {}, 25 | /******/ id: moduleId, 26 | /******/ loaded: false 27 | /******/ }; 28 | /******/ 29 | /******/ // Execute the module function 30 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 31 | /******/ 32 | /******/ // Flag the module as loaded 33 | /******/ module.loaded = true; 34 | /******/ 35 | /******/ // Return the exports of the module 36 | /******/ return module.exports; 37 | /******/ } 38 | /******/ 39 | /******/ 40 | /******/ // expose the modules object (__webpack_modules__) 41 | /******/ __webpack_require__.m = modules; 42 | /******/ 43 | /******/ // expose the module cache 44 | /******/ __webpack_require__.c = installedModules; 45 | /******/ 46 | /******/ // __webpack_public_path__ 47 | /******/ __webpack_require__.p = ""; 48 | /******/ 49 | /******/ // Load entry module and return exports 50 | /******/ return __webpack_require__(0); 51 | /******/ }) 52 | /************************************************************************/ 53 | /******/ ([ 54 | /* 0 */ 55 | /***/ function(module, exports, __webpack_require__) { 56 | 57 | module.exports = __webpack_require__(1); 58 | 59 | 60 | /***/ }, 61 | /* 1 */ 62 | /***/ function(module, exports, __webpack_require__) { 63 | 64 | 'use strict'; 65 | 66 | Object.defineProperty(exports, "__esModule", { 67 | value: true 68 | }); 69 | exports.default = lookup; 70 | 71 | var _manager = __webpack_require__(2); 72 | 73 | var _manager2 = _interopRequireDefault(_manager); 74 | 75 | var _url = __webpack_require__(50); 76 | 77 | var _url2 = _interopRequireDefault(_url); 78 | 79 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 80 | 81 | var cache = {}; 82 | 83 | function lookup(uri, opts) { 84 | if (!uri) { 85 | throw new Error('uri is required.'); 86 | } 87 | 88 | opts = opts || {}; 89 | 90 | var parsed = (0, _url2.default)(uri); 91 | 92 | var source = parsed.source; 93 | var id = parsed.id; 94 | var path = parsed.path; 95 | var sameNamespace = cache[id] && path in cache[id].nsps; 96 | 97 | var newConnection = opts.forceNew || opts['force new connection'] || false === opts.multiplex || sameNamespace; 98 | 99 | // return new socket or from cache 100 | var io = void 0; 101 | if (newConnection) { 102 | io = (0, _manager2.default)(source, opts); 103 | } else { 104 | if (!cache[id]) { 105 | cache[id] = (0, _manager2.default)(source, opts); 106 | } 107 | io = cache[id]; 108 | } 109 | return io.socket(parsed.path); 110 | } 111 | 112 | exports.connect = lookup; 113 | 114 | /***/ }, 115 | /* 2 */ 116 | /***/ function(module, exports, __webpack_require__) { 117 | 118 | 'use strict'; 119 | 120 | Object.defineProperty(exports, "__esModule", { 121 | value: true 122 | }); 123 | 124 | var _componentEmitter = __webpack_require__(3); 125 | 126 | var _componentEmitter2 = _interopRequireDefault(_componentEmitter); 127 | 128 | var _componentBind = __webpack_require__(4); 129 | 130 | var _componentBind2 = _interopRequireDefault(_componentBind); 131 | 132 | var _backo = __webpack_require__(5); 133 | 134 | var _backo2 = _interopRequireDefault(_backo); 135 | 136 | var _indexof = __webpack_require__(6); 137 | 138 | var _indexof2 = _interopRequireDefault(_indexof); 139 | 140 | var _on = __webpack_require__(7); 141 | 142 | var _on2 = _interopRequireDefault(_on); 143 | 144 | var _engine = __webpack_require__(8); 145 | 146 | var _engine2 = _interopRequireDefault(_engine); 147 | 148 | var _parser = __webpack_require__(46); 149 | 150 | var _socket = __webpack_require__(49); 151 | 152 | var _socket2 = _interopRequireDefault(_socket); 153 | 154 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 155 | 156 | var has = Object.prototype.hasOwnProperty; 157 | 158 | (0, _componentEmitter2.default)(Manager.prototype); 159 | 160 | exports.default = Manager; 161 | 162 | 163 | function Manager(uri, opts) { 164 | if (!(this instanceof Manager)) return new Manager(uri, opts); 165 | 166 | opts.path = opts.path || 'socket.io'; 167 | this.nsps = {}; 168 | this.subs = []; 169 | this.opts = opts; 170 | this.uri = uri; 171 | this.readyState = 'closed'; 172 | this.connected = false; 173 | this.reconnection(opts.reconnection !== false); 174 | this.reconnectionAttempts(opts.reconnectionAttempts || Infinity); 175 | this.reconnectionDelay(opts.reconnectionDelay || 1000); 176 | this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000); 177 | this.randomizationFactor(opts.randomizationFactor || 0.5); 178 | this.backoff = new _backo2.default({ 179 | min: this.reconnectionDelay(), 180 | max: this.reconnectionDelayMax(), 181 | jitter: this.randomizationFactor() 182 | }); 183 | this.timeout(null == opts.timeout ? 20000 : opts.timeout); 184 | this.encoder = _parser.encoder; 185 | this.decoder = _parser.decoder; 186 | this.connecting = []; 187 | this.autoConnect = opts.autoConnect !== false; 188 | if (this.autoConnect) this.open(); 189 | } 190 | 191 | Manager.prototype.open = Manager.prototype.connect = function (fn) { 192 | var _this = this; 193 | 194 | if (~this.readyState.indexOf('open')) return this; 195 | 196 | this.engine = new _engine2.default(this.uri, this.opts); 197 | 198 | this.readyState = 'opening'; 199 | 200 | var socket = this.engine; 201 | 202 | this.subs.push((0, _on2.default)(socket, 'open', function () { 203 | _this.onopen(); 204 | fn && fn(); 205 | })); 206 | 207 | this.subs.push((0, _on2.default)(socket, 'error', function (data) { 208 | _this.cleanup(); 209 | _this.readyState = 'closed'; 210 | _this.emitAll('connect_error', data); 211 | if (fn) { 212 | var error = new Error('Connect error'); 213 | error.data = data; 214 | fn(error); 215 | } else { 216 | _this.maybeReconnectOnOpen(); 217 | } 218 | })); 219 | 220 | socket.connect(); 221 | return this; 222 | }; 223 | 224 | Manager.prototype.onopen = function () { 225 | this.cleanup(); 226 | 227 | this.readyState = 'open'; 228 | this.emit('open'); 229 | 230 | var socket = this.engine; 231 | this.subs.push((0, _on2.default)(socket, 'data', (0, _componentBind2.default)(this, 'ondata'))); 232 | this.subs.push((0, _on2.default)(socket, 'ping', (0, _componentBind2.default)(this, 'onping'))); 233 | this.subs.push((0, _on2.default)(socket, 'pong', (0, _componentBind2.default)(this, 'onpong'))); 234 | this.subs.push((0, _on2.default)(socket, 'error', (0, _componentBind2.default)(this, 'onerror'))); 235 | this.subs.push((0, _on2.default)(socket, 'close', (0, _componentBind2.default)(this, 'onclose'))); 236 | // this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded'))) 237 | }; 238 | 239 | Manager.prototype.onclose = function (reason) { 240 | this.cleanup(); 241 | this.readyState = 'closed'; 242 | this.emit('close', reason); 243 | if (this._reconnection && !this.skipReconnect) this.reconnect(); 244 | }; 245 | 246 | Manager.prototype.onerror = function (reason) { 247 | this.emitAll('error'); 248 | }; 249 | 250 | Manager.prototype.onping = function () { 251 | this.lastPing = new Date(); 252 | this.emitAll('ping'); 253 | }; 254 | 255 | Manager.prototype.onpong = function () { 256 | this.emitAll('pong', new Date() - this.lastPing); 257 | }; 258 | 259 | Manager.prototype.ondata = function (data) { 260 | var _this2 = this; 261 | 262 | this.decoder(data, function (decoding) { 263 | _this2.emit('packet', decoding); 264 | }); 265 | }; 266 | 267 | Manager.prototype.packet = function (packet) { 268 | var _this3 = this; 269 | 270 | this.encoder(packet, function (encodedPackets) { 271 | for (var i = 0; i < encodedPackets.length; i++) { 272 | _this3.engine.write(encodedPackets[i], packet.options); 273 | } 274 | }); 275 | }; 276 | 277 | Manager.prototype.socket = function (nsp) { 278 | var socket = this.nsps[nsp]; 279 | if (!socket) { 280 | socket = new _socket2.default(this, nsp); 281 | this.nsps[nsp] = socket; 282 | } 283 | return socket; 284 | }; 285 | 286 | Manager.prototype.cleanup = function () { 287 | var sub = void 0; 288 | while (sub = this.subs.shift()) { 289 | sub.destroy(); 290 | }this.packetBuffer = []; 291 | this.lastPing = null; 292 | }; 293 | 294 | Manager.prototype.emitAll = function () { 295 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 296 | args[_key] = arguments[_key]; 297 | } 298 | 299 | this.emit.apply(this, args); 300 | for (var nsp in this.nsps) { 301 | if (has.call(this.nsps, nsp)) { 302 | this.nsps[nsp].emit.apply(this.nsps[nsp], args); 303 | } 304 | } 305 | }; 306 | 307 | Manager.prototype.reconnect = function () { 308 | var _this4 = this; 309 | 310 | if (this.reconnecting || this.skipReconnect) return this; 311 | 312 | if (this.backoff.attempts >= this._reconnectionAttempts) { 313 | this.backoff.reset(); 314 | this.emitAll('reconnect_failed'); 315 | this.reconnecting = false; 316 | } else { 317 | (function () { 318 | var delay = _this4.backoff.duration(); 319 | _this4.reconnecting = true; 320 | var timer = setTimeout(function () { 321 | _this4.emitAll('reconnect_attempt', _this4.backoff.attempts); 322 | _this4.emitAll('reconnecting', _this4.backoff.attempts); 323 | 324 | if (_this4.skipReconnect) return; 325 | 326 | _this4.open(function (err) { 327 | if (err) { 328 | _this4.reconnecting = false; 329 | _this4.reconnect(); 330 | _this4.emitAll('reconnect_error', err.data); 331 | } else { 332 | _this4.onreconnect(); 333 | } 334 | }); 335 | }, delay); 336 | 337 | _this4.subs.push({ 338 | destroy: function destroy() { 339 | clearTimeout(timer); 340 | } 341 | }); 342 | })(); 343 | } 344 | }; 345 | 346 | Manager.prototype.onreconnect = function () { 347 | var attempt = this.backoff.attempts; 348 | this.reconnecting = false; 349 | this.backoff.reset(); 350 | this.updateSocketIds(); 351 | this.emitAll('reconnect', attempt); 352 | }; 353 | 354 | /** 355 | * Update `socket.id` of all sockets 356 | * 357 | * @api private 358 | */ 359 | 360 | Manager.prototype.updateSocketIds = function () { 361 | for (var nsp in this.nsps) { 362 | if (has.call(this.nsps, nsp)) { 363 | this.nsps[nsp].id = this.engine.id; 364 | } 365 | } 366 | }; 367 | 368 | Manager.prototype.destroy = function (socket) { 369 | var index = (0, _indexof2.default)(this.connecting, socket); 370 | if (~index) this.connecting.splice(index, 1); 371 | if (this.connecting.length) return; 372 | 373 | this.close(); 374 | }; 375 | 376 | Manager.prototype.close = Manager.prototype.disconnect = function () { 377 | this.skipReconnect = true; 378 | this.reconnecting = false; 379 | if ('opening' == this.readyState) { 380 | // `onclose` will not fire because 381 | // an open event never happened 382 | this.cleanup(); 383 | } 384 | this.readyState = 'closed'; 385 | if (this.engine) this.engine.close(); 386 | }; 387 | 388 | /** 389 | * Sets the `reconnection` config. 390 | * 391 | * @param {Boolean} true/false if it should automatically reconnect 392 | * @return {Manager} self or value 393 | * @api public 394 | */ 395 | Manager.prototype.reconnection = function (v) { 396 | if (!arguments.length) return this._reconnection; 397 | this._reconnection = !!v; 398 | return this; 399 | }; 400 | 401 | /** 402 | * Sets the reconnection attempts config. 403 | * 404 | * @param {Number} max reconnection attempts before giving up 405 | * @return {Manager} self or value 406 | * @api public 407 | */ 408 | Manager.prototype.reconnectionAttempts = function (v) { 409 | if (!arguments.length) return this._reconnectionAttempts; 410 | this._reconnectionAttempts = v; 411 | return this; 412 | }; 413 | 414 | /** 415 | * Sets the delay between reconnections. 416 | * 417 | * @param {Number} delay 418 | * @return {Manager} self or value 419 | * @api public 420 | */ 421 | Manager.prototype.reconnectionDelay = function (v) { 422 | if (!arguments.length) return this._reconnectionDelay; 423 | this._reconnectionDelay = v; 424 | this.backoff && this.backoff.setMin(v); 425 | return this; 426 | }; 427 | 428 | Manager.prototype.randomizationFactor = function (v) { 429 | if (!arguments.length) return this._randomizationFactor; 430 | this._randomizationFactor = v; 431 | this.backoff && this.backoff.setJitter(v); 432 | return this; 433 | }; 434 | 435 | /** 436 | * Sets the maximum delay between reconnections. 437 | * 438 | * @param {Number} delay 439 | * @return {Manager} self or value 440 | * @api public 441 | */ 442 | Manager.prototype.reconnectionDelayMax = function (v) { 443 | if (!arguments.length) return this._reconnectionDelayMax; 444 | this._reconnectionDelayMax = v; 445 | this.backoff && this.backoff.setMax(v); 446 | return this; 447 | }; 448 | 449 | /** 450 | * Sets the connection timeout. `false` to disable 451 | * 452 | * @return {Manager} self or value 453 | * @api public 454 | */ 455 | Manager.prototype.timeout = function (v) { 456 | if (!arguments.length) return this._timeout; 457 | this._timeout = v; 458 | return this; 459 | }; 460 | 461 | /** 462 | * Starts trying to reconnect if reconnection is enabled and we have not 463 | * started reconnecting yet 464 | * 465 | * @api private 466 | */ 467 | Manager.prototype.maybeReconnectOnOpen = function () { 468 | // Only try to reconnect if it's the first time we're connecting 469 | if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) { 470 | // keeps reconnection from firing twice for the same reconnection loop 471 | this.reconnect(); 472 | } 473 | }; 474 | 475 | /***/ }, 476 | /* 3 */ 477 | /***/ function(module, exports, __webpack_require__) { 478 | 479 | 480 | /** 481 | * Expose `Emitter`. 482 | */ 483 | 484 | if (true) { 485 | module.exports = Emitter; 486 | } 487 | 488 | /** 489 | * Initialize a new `Emitter`. 490 | * 491 | * @api public 492 | */ 493 | 494 | function Emitter(obj) { 495 | if (obj) return mixin(obj); 496 | }; 497 | 498 | /** 499 | * Mixin the emitter properties. 500 | * 501 | * @param {Object} obj 502 | * @return {Object} 503 | * @api private 504 | */ 505 | 506 | function mixin(obj) { 507 | for (var key in Emitter.prototype) { 508 | obj[key] = Emitter.prototype[key]; 509 | } 510 | return obj; 511 | } 512 | 513 | /** 514 | * Listen on the given `event` with `fn`. 515 | * 516 | * @param {String} event 517 | * @param {Function} fn 518 | * @return {Emitter} 519 | * @api public 520 | */ 521 | 522 | Emitter.prototype.on = 523 | Emitter.prototype.addEventListener = function(event, fn){ 524 | this._callbacks = this._callbacks || {}; 525 | (this._callbacks['$' + event] = this._callbacks['$' + event] || []) 526 | .push(fn); 527 | return this; 528 | }; 529 | 530 | /** 531 | * Adds an `event` listener that will be invoked a single 532 | * time then automatically removed. 533 | * 534 | * @param {String} event 535 | * @param {Function} fn 536 | * @return {Emitter} 537 | * @api public 538 | */ 539 | 540 | Emitter.prototype.once = function(event, fn){ 541 | function on() { 542 | this.off(event, on); 543 | fn.apply(this, arguments); 544 | } 545 | 546 | on.fn = fn; 547 | this.on(event, on); 548 | return this; 549 | }; 550 | 551 | /** 552 | * Remove the given callback for `event` or all 553 | * registered callbacks. 554 | * 555 | * @param {String} event 556 | * @param {Function} fn 557 | * @return {Emitter} 558 | * @api public 559 | */ 560 | 561 | Emitter.prototype.off = 562 | Emitter.prototype.removeListener = 563 | Emitter.prototype.removeAllListeners = 564 | Emitter.prototype.removeEventListener = function(event, fn){ 565 | this._callbacks = this._callbacks || {}; 566 | 567 | // all 568 | if (0 == arguments.length) { 569 | this._callbacks = {}; 570 | return this; 571 | } 572 | 573 | // specific event 574 | var callbacks = this._callbacks['$' + event]; 575 | if (!callbacks) return this; 576 | 577 | // remove all handlers 578 | if (1 == arguments.length) { 579 | delete this._callbacks['$' + event]; 580 | return this; 581 | } 582 | 583 | // remove specific handler 584 | var cb; 585 | for (var i = 0; i < callbacks.length; i++) { 586 | cb = callbacks[i]; 587 | if (cb === fn || cb.fn === fn) { 588 | callbacks.splice(i, 1); 589 | break; 590 | } 591 | } 592 | return this; 593 | }; 594 | 595 | /** 596 | * Emit `event` with the given args. 597 | * 598 | * @param {String} event 599 | * @param {Mixed} ... 600 | * @return {Emitter} 601 | */ 602 | 603 | Emitter.prototype.emit = function(event){ 604 | this._callbacks = this._callbacks || {}; 605 | var args = [].slice.call(arguments, 1) 606 | , callbacks = this._callbacks['$' + event]; 607 | 608 | if (callbacks) { 609 | callbacks = callbacks.slice(0); 610 | for (var i = 0, len = callbacks.length; i < len; ++i) { 611 | callbacks[i].apply(this, args); 612 | } 613 | } 614 | 615 | return this; 616 | }; 617 | 618 | /** 619 | * Return array of callbacks for `event`. 620 | * 621 | * @param {String} event 622 | * @return {Array} 623 | * @api public 624 | */ 625 | 626 | Emitter.prototype.listeners = function(event){ 627 | this._callbacks = this._callbacks || {}; 628 | return this._callbacks['$' + event] || []; 629 | }; 630 | 631 | /** 632 | * Check if this emitter has `event` handlers. 633 | * 634 | * @param {String} event 635 | * @return {Boolean} 636 | * @api public 637 | */ 638 | 639 | Emitter.prototype.hasListeners = function(event){ 640 | return !! this.listeners(event).length; 641 | }; 642 | 643 | 644 | /***/ }, 645 | /* 4 */ 646 | /***/ function(module, exports) { 647 | 648 | /** 649 | * Slice reference. 650 | */ 651 | 652 | var slice = [].slice; 653 | 654 | /** 655 | * Bind `obj` to `fn`. 656 | * 657 | * @param {Object} obj 658 | * @param {Function|String} fn or string 659 | * @return {Function} 660 | * @api public 661 | */ 662 | 663 | module.exports = function(obj, fn){ 664 | if ('string' == typeof fn) fn = obj[fn]; 665 | if ('function' != typeof fn) throw new Error('bind() requires a function'); 666 | var args = slice.call(arguments, 2); 667 | return function(){ 668 | return fn.apply(obj, args.concat(slice.call(arguments))); 669 | } 670 | }; 671 | 672 | 673 | /***/ }, 674 | /* 5 */ 675 | /***/ function(module, exports) { 676 | 677 | 678 | /** 679 | * Expose `Backoff`. 680 | */ 681 | 682 | module.exports = Backoff; 683 | 684 | /** 685 | * Initialize backoff timer with `opts`. 686 | * 687 | * - `min` initial timeout in milliseconds [100] 688 | * - `max` max timeout [10000] 689 | * - `jitter` [0] 690 | * - `factor` [2] 691 | * 692 | * @param {Object} opts 693 | * @api public 694 | */ 695 | 696 | function Backoff(opts) { 697 | opts = opts || {}; 698 | this.ms = opts.min || 100; 699 | this.max = opts.max || 10000; 700 | this.factor = opts.factor || 2; 701 | this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0; 702 | this.attempts = 0; 703 | } 704 | 705 | /** 706 | * Return the backoff duration. 707 | * 708 | * @return {Number} 709 | * @api public 710 | */ 711 | 712 | Backoff.prototype.duration = function(){ 713 | var ms = this.ms * Math.pow(this.factor, this.attempts++); 714 | if (this.jitter) { 715 | var rand = Math.random(); 716 | var deviation = Math.floor(rand * this.jitter * ms); 717 | ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation; 718 | } 719 | return Math.min(ms, this.max) | 0; 720 | }; 721 | 722 | /** 723 | * Reset the number of attempts. 724 | * 725 | * @api public 726 | */ 727 | 728 | Backoff.prototype.reset = function(){ 729 | this.attempts = 0; 730 | }; 731 | 732 | /** 733 | * Set the minimum duration 734 | * 735 | * @api public 736 | */ 737 | 738 | Backoff.prototype.setMin = function(min){ 739 | this.ms = min; 740 | }; 741 | 742 | /** 743 | * Set the maximum duration 744 | * 745 | * @api public 746 | */ 747 | 748 | Backoff.prototype.setMax = function(max){ 749 | this.max = max; 750 | }; 751 | 752 | /** 753 | * Set the jitter 754 | * 755 | * @api public 756 | */ 757 | 758 | Backoff.prototype.setJitter = function(jitter){ 759 | this.jitter = jitter; 760 | }; 761 | 762 | 763 | 764 | /***/ }, 765 | /* 6 */ 766 | /***/ function(module, exports) { 767 | 768 | 769 | var indexOf = [].indexOf; 770 | 771 | module.exports = function(arr, obj){ 772 | if (indexOf) return arr.indexOf(obj); 773 | for (var i = 0; i < arr.length; ++i) { 774 | if (arr[i] === obj) return i; 775 | } 776 | return -1; 777 | }; 778 | 779 | /***/ }, 780 | /* 7 */ 781 | /***/ function(module, exports) { 782 | 783 | "use strict"; 784 | 785 | Object.defineProperty(exports, "__esModule", { 786 | value: true 787 | }); 788 | 789 | /** 790 | * Helper for subscriptions. 791 | * 792 | * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter` 793 | * @param {String} event name 794 | * @param {Function} callback 795 | * @api public 796 | */ 797 | 798 | exports.default = function (obj, ev, fn) { 799 | obj.on(ev, fn); 800 | return { 801 | destroy: function destroy() { 802 | obj.removeListener(ev, fn); 803 | } 804 | }; 805 | }; 806 | 807 | /***/ }, 808 | /* 8 */ 809 | /***/ function(module, exports, __webpack_require__) { 810 | 811 | 'use strict'; 812 | 813 | Object.defineProperty(exports, "__esModule", { 814 | value: true 815 | }); 816 | 817 | var _keys = __webpack_require__(9); 818 | 819 | var _keys2 = _interopRequireDefault(_keys); 820 | 821 | var _componentEmitter = __webpack_require__(3); 822 | 823 | var _componentEmitter2 = _interopRequireDefault(_componentEmitter); 824 | 825 | var _on = __webpack_require__(7); 826 | 827 | var _on2 = _interopRequireDefault(_on); 828 | 829 | var _parsejson = __webpack_require__(44); 830 | 831 | var _parsejson2 = _interopRequireDefault(_parsejson); 832 | 833 | var _componentBind = __webpack_require__(4); 834 | 835 | var _componentBind2 = _interopRequireDefault(_componentBind); 836 | 837 | var _parseuri = __webpack_require__(45); 838 | 839 | var _parseuri2 = _interopRequireDefault(_parseuri); 840 | 841 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 842 | 843 | exports.default = Engine; 844 | 845 | 846 | var GlobalEmitter = (0, _componentEmitter2.default)({ hasEmitte: false }); 847 | 848 | (0, _componentEmitter2.default)(Engine.prototype); 849 | 850 | var packets = { 851 | open: 0, // non-ws 852 | close: 1, // non-ws 853 | ping: 2, 854 | pong: 3, 855 | message: 4, 856 | upgrade: 5, 857 | noop: 6 858 | }; 859 | 860 | var packetslist = (0, _keys2.default)(packets); 861 | 862 | function Engine(uri, opts) { 863 | if (!(this instanceof Engine)) return new Engine(uri, opts); 864 | 865 | this.subs = []; 866 | uri = (0, _parseuri2.default)(uri); 867 | this.protocol = uri.protocol; 868 | this.host = uri.host; 869 | this.query = uri.query; 870 | this.port = uri.port; 871 | this.opts = this.opts || {}; 872 | this.path = opts.path.replace(/\/$/, ''); 873 | this.connected = false; 874 | this.lastPing = null; 875 | this.pingInterval = 20000; 876 | // init bind with GlobalEmitter 877 | this.bindEvents(); 878 | } 879 | 880 | Engine.prototype.connect = function () { 881 | if (!GlobalEmitter.hasEmitte) Engine.subEvents(); 882 | var url = this.protocol + '://' + this.host + ':' + this.port + '/' + this.path + '/?' + (this.query ? this.query + '&' : '') + 'EIO=3&transport=websocket'; 883 | 884 | wx.connectSocket({ url: url }); 885 | }; 886 | 887 | Engine.prototype.onopen = function () { 888 | this.emit('open'); 889 | }; 890 | 891 | Engine.prototype.onclose = function (reason) { 892 | // clean all bind with GlobalEmitter 893 | this.destroy(); 894 | this.emit('close', reason); 895 | }; 896 | 897 | Engine.prototype.onerror = function (reason) { 898 | this.emit('error'); 899 | // 如果 wx.connectSocket 还没回调 wx.onSocketOpen,而先调用 wx.closeSocket,那么就做不到关闭 WebSocket 的目的。 900 | wx.closeSocket(); 901 | }; 902 | 903 | Engine.prototype.onpacket = function (packet) { 904 | switch (packet.type) { 905 | case 'open': 906 | this.onHandshake((0, _parsejson2.default)(packet.data)); 907 | break; 908 | case 'pong': 909 | this.setPing(); 910 | this.emit('pong'); 911 | break; 912 | case 'error': 913 | { 914 | var error = new Error('server error'); 915 | error.code = packet.data; 916 | this.onerror(error); 917 | break; 918 | } 919 | case 'message': 920 | this.emit('data', packet.data); 921 | this.emit('message', packet.data); 922 | break; 923 | } 924 | }; 925 | 926 | Engine.prototype.onHandshake = function (data) { 927 | this.id = data.sid; 928 | this.pingInterval = data.pingInterval; 929 | this.pingTimeout = data.pingTimeout; 930 | this.setPing(); 931 | }; 932 | 933 | Engine.prototype.setPing = function () { 934 | var _this = this; 935 | 936 | clearTimeout(this.pingIntervalTimer); 937 | this.pingIntervalTimer = setTimeout(function () { 938 | _this.ping(); 939 | }, this.pingInterval); 940 | }; 941 | 942 | Engine.prototype.ping = function () { 943 | this.emit('ping'); 944 | this._send(packets.ping + 'probe'); 945 | }; 946 | 947 | Engine.prototype.write = Engine.prototype.send = function (packet) { 948 | this._send([packets.message, packet].join('')); 949 | }; 950 | 951 | Engine.prototype._send = function (data) { 952 | wx.sendSocketMessage({ data: data }); 953 | }; 954 | Engine.subEvents = function () { 955 | wx.onSocketOpen(function () { 956 | GlobalEmitter.emit('open'); 957 | }); 958 | wx.onSocketClose(function (reason) { 959 | GlobalEmitter.emit('close', reason); 960 | }); 961 | wx.onSocketError(function (reason) { 962 | GlobalEmitter.emit('error', reason); 963 | }); 964 | wx.onSocketMessage(function (resp) { 965 | GlobalEmitter.emit('packet', decodePacket(resp.data)); 966 | }); 967 | GlobalEmitter.hasEmitte = true; 968 | }; 969 | 970 | Engine.prototype.bindEvents = function () { 971 | this.subs.push((0, _on2.default)(GlobalEmitter, 'open', (0, _componentBind2.default)(this, 'onopen'))); 972 | this.subs.push((0, _on2.default)(GlobalEmitter, 'close', (0, _componentBind2.default)(this, 'onclose'))); 973 | this.subs.push((0, _on2.default)(GlobalEmitter, 'error', (0, _componentBind2.default)(this, 'onerror'))); 974 | this.subs.push((0, _on2.default)(GlobalEmitter, 'packet', (0, _componentBind2.default)(this, 'onpacket'))); 975 | }; 976 | 977 | Engine.prototype.destroy = function () { 978 | var sub = void 0; 979 | while (sub = this.subs.shift()) { 980 | sub.destroy(); 981 | } 982 | 983 | clearTimeout(this.pingIntervalTimer); 984 | this.readyState = 'closed'; 985 | this.id = null; 986 | this.writeBuffer = []; 987 | this.prevBufferLen = 0; 988 | }; 989 | 990 | function decodePacket(data) { 991 | var type = data.charAt(0); 992 | if (data.length > 1) { 993 | return { 994 | type: packetslist[type], 995 | data: data.substring(1) 996 | }; 997 | } 998 | return { type: packetslist[type] }; 999 | } 1000 | 1001 | /***/ }, 1002 | /* 9 */ 1003 | /***/ function(module, exports, __webpack_require__) { 1004 | 1005 | module.exports = { "default": __webpack_require__(10), __esModule: true }; 1006 | 1007 | /***/ }, 1008 | /* 10 */ 1009 | /***/ function(module, exports, __webpack_require__) { 1010 | 1011 | __webpack_require__(11); 1012 | module.exports = __webpack_require__(31).Object.keys; 1013 | 1014 | /***/ }, 1015 | /* 11 */ 1016 | /***/ function(module, exports, __webpack_require__) { 1017 | 1018 | // 19.1.2.14 Object.keys(O) 1019 | var toObject = __webpack_require__(12) 1020 | , $keys = __webpack_require__(14); 1021 | 1022 | __webpack_require__(29)('keys', function(){ 1023 | return function keys(it){ 1024 | return $keys(toObject(it)); 1025 | }; 1026 | }); 1027 | 1028 | /***/ }, 1029 | /* 12 */ 1030 | /***/ function(module, exports, __webpack_require__) { 1031 | 1032 | // 7.1.13 ToObject(argument) 1033 | var defined = __webpack_require__(13); 1034 | module.exports = function(it){ 1035 | return Object(defined(it)); 1036 | }; 1037 | 1038 | /***/ }, 1039 | /* 13 */ 1040 | /***/ function(module, exports) { 1041 | 1042 | // 7.2.1 RequireObjectCoercible(argument) 1043 | module.exports = function(it){ 1044 | if(it == undefined)throw TypeError("Can't call method on " + it); 1045 | return it; 1046 | }; 1047 | 1048 | /***/ }, 1049 | /* 14 */ 1050 | /***/ function(module, exports, __webpack_require__) { 1051 | 1052 | // 19.1.2.14 / 15.2.3.14 Object.keys(O) 1053 | var $keys = __webpack_require__(15) 1054 | , enumBugKeys = __webpack_require__(28); 1055 | 1056 | module.exports = Object.keys || function keys(O){ 1057 | return $keys(O, enumBugKeys); 1058 | }; 1059 | 1060 | /***/ }, 1061 | /* 15 */ 1062 | /***/ function(module, exports, __webpack_require__) { 1063 | 1064 | var has = __webpack_require__(16) 1065 | , toIObject = __webpack_require__(17) 1066 | , arrayIndexOf = __webpack_require__(20)(false) 1067 | , IE_PROTO = __webpack_require__(24)('IE_PROTO'); 1068 | 1069 | module.exports = function(object, names){ 1070 | var O = toIObject(object) 1071 | , i = 0 1072 | , result = [] 1073 | , key; 1074 | for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key); 1075 | // Don't enum bug & hidden keys 1076 | while(names.length > i)if(has(O, key = names[i++])){ 1077 | ~arrayIndexOf(result, key) || result.push(key); 1078 | } 1079 | return result; 1080 | }; 1081 | 1082 | /***/ }, 1083 | /* 16 */ 1084 | /***/ function(module, exports) { 1085 | 1086 | var hasOwnProperty = {}.hasOwnProperty; 1087 | module.exports = function(it, key){ 1088 | return hasOwnProperty.call(it, key); 1089 | }; 1090 | 1091 | /***/ }, 1092 | /* 17 */ 1093 | /***/ function(module, exports, __webpack_require__) { 1094 | 1095 | // to indexed object, toObject with fallback for non-array-like ES3 strings 1096 | var IObject = __webpack_require__(18) 1097 | , defined = __webpack_require__(13); 1098 | module.exports = function(it){ 1099 | return IObject(defined(it)); 1100 | }; 1101 | 1102 | /***/ }, 1103 | /* 18 */ 1104 | /***/ function(module, exports, __webpack_require__) { 1105 | 1106 | // fallback for non-array-like ES3 and non-enumerable old V8 strings 1107 | var cof = __webpack_require__(19); 1108 | module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){ 1109 | return cof(it) == 'String' ? it.split('') : Object(it); 1110 | }; 1111 | 1112 | /***/ }, 1113 | /* 19 */ 1114 | /***/ function(module, exports) { 1115 | 1116 | var toString = {}.toString; 1117 | 1118 | module.exports = function(it){ 1119 | return toString.call(it).slice(8, -1); 1120 | }; 1121 | 1122 | /***/ }, 1123 | /* 20 */ 1124 | /***/ function(module, exports, __webpack_require__) { 1125 | 1126 | // false -> Array#indexOf 1127 | // true -> Array#includes 1128 | var toIObject = __webpack_require__(17) 1129 | , toLength = __webpack_require__(21) 1130 | , toIndex = __webpack_require__(23); 1131 | module.exports = function(IS_INCLUDES){ 1132 | return function($this, el, fromIndex){ 1133 | var O = toIObject($this) 1134 | , length = toLength(O.length) 1135 | , index = toIndex(fromIndex, length) 1136 | , value; 1137 | // Array#includes uses SameValueZero equality algorithm 1138 | if(IS_INCLUDES && el != el)while(length > index){ 1139 | value = O[index++]; 1140 | if(value != value)return true; 1141 | // Array#toIndex ignores holes, Array#includes - not 1142 | } else for(;length > index; index++)if(IS_INCLUDES || index in O){ 1143 | if(O[index] === el)return IS_INCLUDES || index || 0; 1144 | } return !IS_INCLUDES && -1; 1145 | }; 1146 | }; 1147 | 1148 | /***/ }, 1149 | /* 21 */ 1150 | /***/ function(module, exports, __webpack_require__) { 1151 | 1152 | // 7.1.15 ToLength 1153 | var toInteger = __webpack_require__(22) 1154 | , min = Math.min; 1155 | module.exports = function(it){ 1156 | return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 1157 | }; 1158 | 1159 | /***/ }, 1160 | /* 22 */ 1161 | /***/ function(module, exports) { 1162 | 1163 | // 7.1.4 ToInteger 1164 | var ceil = Math.ceil 1165 | , floor = Math.floor; 1166 | module.exports = function(it){ 1167 | return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); 1168 | }; 1169 | 1170 | /***/ }, 1171 | /* 23 */ 1172 | /***/ function(module, exports, __webpack_require__) { 1173 | 1174 | var toInteger = __webpack_require__(22) 1175 | , max = Math.max 1176 | , min = Math.min; 1177 | module.exports = function(index, length){ 1178 | index = toInteger(index); 1179 | return index < 0 ? max(index + length, 0) : min(index, length); 1180 | }; 1181 | 1182 | /***/ }, 1183 | /* 24 */ 1184 | /***/ function(module, exports, __webpack_require__) { 1185 | 1186 | var shared = __webpack_require__(25)('keys') 1187 | , uid = __webpack_require__(27); 1188 | module.exports = function(key){ 1189 | return shared[key] || (shared[key] = uid(key)); 1190 | }; 1191 | 1192 | /***/ }, 1193 | /* 25 */ 1194 | /***/ function(module, exports, __webpack_require__) { 1195 | 1196 | var global = __webpack_require__(26) 1197 | , SHARED = '__core-js_shared__' 1198 | , store = global[SHARED] || (global[SHARED] = {}); 1199 | module.exports = function(key){ 1200 | return store[key] || (store[key] = {}); 1201 | }; 1202 | 1203 | /***/ }, 1204 | /* 26 */ 1205 | /***/ function(module, exports) { 1206 | 1207 | // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 1208 | var global = module.exports = typeof window != 'undefined' && window.Math == Math 1209 | ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); 1210 | if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef 1211 | 1212 | /***/ }, 1213 | /* 27 */ 1214 | /***/ function(module, exports) { 1215 | 1216 | var id = 0 1217 | , px = Math.random(); 1218 | module.exports = function(key){ 1219 | return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); 1220 | }; 1221 | 1222 | /***/ }, 1223 | /* 28 */ 1224 | /***/ function(module, exports) { 1225 | 1226 | // IE 8- don't enum bug keys 1227 | module.exports = ( 1228 | 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' 1229 | ).split(','); 1230 | 1231 | /***/ }, 1232 | /* 29 */ 1233 | /***/ function(module, exports, __webpack_require__) { 1234 | 1235 | // most Object methods by ES6 should accept primitives 1236 | var $export = __webpack_require__(30) 1237 | , core = __webpack_require__(31) 1238 | , fails = __webpack_require__(40); 1239 | module.exports = function(KEY, exec){ 1240 | var fn = (core.Object || {})[KEY] || Object[KEY] 1241 | , exp = {}; 1242 | exp[KEY] = exec(fn); 1243 | $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp); 1244 | }; 1245 | 1246 | /***/ }, 1247 | /* 30 */ 1248 | /***/ function(module, exports, __webpack_require__) { 1249 | 1250 | var global = __webpack_require__(26) 1251 | , core = __webpack_require__(31) 1252 | , ctx = __webpack_require__(32) 1253 | , hide = __webpack_require__(34) 1254 | , PROTOTYPE = 'prototype'; 1255 | 1256 | var $export = function(type, name, source){ 1257 | var IS_FORCED = type & $export.F 1258 | , IS_GLOBAL = type & $export.G 1259 | , IS_STATIC = type & $export.S 1260 | , IS_PROTO = type & $export.P 1261 | , IS_BIND = type & $export.B 1262 | , IS_WRAP = type & $export.W 1263 | , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) 1264 | , expProto = exports[PROTOTYPE] 1265 | , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE] 1266 | , key, own, out; 1267 | if(IS_GLOBAL)source = name; 1268 | for(key in source){ 1269 | // contains in native 1270 | own = !IS_FORCED && target && target[key] !== undefined; 1271 | if(own && key in exports)continue; 1272 | // export native or passed 1273 | out = own ? target[key] : source[key]; 1274 | // prevent global pollution for namespaces 1275 | exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] 1276 | // bind timers to global for call from export context 1277 | : IS_BIND && own ? ctx(out, global) 1278 | // wrap global constructors for prevent change them in library 1279 | : IS_WRAP && target[key] == out ? (function(C){ 1280 | var F = function(a, b, c){ 1281 | if(this instanceof C){ 1282 | switch(arguments.length){ 1283 | case 0: return new C; 1284 | case 1: return new C(a); 1285 | case 2: return new C(a, b); 1286 | } return new C(a, b, c); 1287 | } return C.apply(this, arguments); 1288 | }; 1289 | F[PROTOTYPE] = C[PROTOTYPE]; 1290 | return F; 1291 | // make static versions for prototype methods 1292 | })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; 1293 | // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% 1294 | if(IS_PROTO){ 1295 | (exports.virtual || (exports.virtual = {}))[key] = out; 1296 | // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% 1297 | if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out); 1298 | } 1299 | } 1300 | }; 1301 | // type bitmap 1302 | $export.F = 1; // forced 1303 | $export.G = 2; // global 1304 | $export.S = 4; // static 1305 | $export.P = 8; // proto 1306 | $export.B = 16; // bind 1307 | $export.W = 32; // wrap 1308 | $export.U = 64; // safe 1309 | $export.R = 128; // real proto method for `library` 1310 | module.exports = $export; 1311 | 1312 | /***/ }, 1313 | /* 31 */ 1314 | /***/ function(module, exports) { 1315 | 1316 | var core = module.exports = {version: '2.4.0'}; 1317 | if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef 1318 | 1319 | /***/ }, 1320 | /* 32 */ 1321 | /***/ function(module, exports, __webpack_require__) { 1322 | 1323 | // optional / simple context binding 1324 | var aFunction = __webpack_require__(33); 1325 | module.exports = function(fn, that, length){ 1326 | aFunction(fn); 1327 | if(that === undefined)return fn; 1328 | switch(length){ 1329 | case 1: return function(a){ 1330 | return fn.call(that, a); 1331 | }; 1332 | case 2: return function(a, b){ 1333 | return fn.call(that, a, b); 1334 | }; 1335 | case 3: return function(a, b, c){ 1336 | return fn.call(that, a, b, c); 1337 | }; 1338 | } 1339 | return function(/* ...args */){ 1340 | return fn.apply(that, arguments); 1341 | }; 1342 | }; 1343 | 1344 | /***/ }, 1345 | /* 33 */ 1346 | /***/ function(module, exports) { 1347 | 1348 | module.exports = function(it){ 1349 | if(typeof it != 'function')throw TypeError(it + ' is not a function!'); 1350 | return it; 1351 | }; 1352 | 1353 | /***/ }, 1354 | /* 34 */ 1355 | /***/ function(module, exports, __webpack_require__) { 1356 | 1357 | var dP = __webpack_require__(35) 1358 | , createDesc = __webpack_require__(43); 1359 | module.exports = __webpack_require__(39) ? function(object, key, value){ 1360 | return dP.f(object, key, createDesc(1, value)); 1361 | } : function(object, key, value){ 1362 | object[key] = value; 1363 | return object; 1364 | }; 1365 | 1366 | /***/ }, 1367 | /* 35 */ 1368 | /***/ function(module, exports, __webpack_require__) { 1369 | 1370 | var anObject = __webpack_require__(36) 1371 | , IE8_DOM_DEFINE = __webpack_require__(38) 1372 | , toPrimitive = __webpack_require__(42) 1373 | , dP = Object.defineProperty; 1374 | 1375 | exports.f = __webpack_require__(39) ? Object.defineProperty : function defineProperty(O, P, Attributes){ 1376 | anObject(O); 1377 | P = toPrimitive(P, true); 1378 | anObject(Attributes); 1379 | if(IE8_DOM_DEFINE)try { 1380 | return dP(O, P, Attributes); 1381 | } catch(e){ /* empty */ } 1382 | if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); 1383 | if('value' in Attributes)O[P] = Attributes.value; 1384 | return O; 1385 | }; 1386 | 1387 | /***/ }, 1388 | /* 36 */ 1389 | /***/ function(module, exports, __webpack_require__) { 1390 | 1391 | var isObject = __webpack_require__(37); 1392 | module.exports = function(it){ 1393 | if(!isObject(it))throw TypeError(it + ' is not an object!'); 1394 | return it; 1395 | }; 1396 | 1397 | /***/ }, 1398 | /* 37 */ 1399 | /***/ function(module, exports) { 1400 | 1401 | module.exports = function(it){ 1402 | return typeof it === 'object' ? it !== null : typeof it === 'function'; 1403 | }; 1404 | 1405 | /***/ }, 1406 | /* 38 */ 1407 | /***/ function(module, exports, __webpack_require__) { 1408 | 1409 | module.exports = !__webpack_require__(39) && !__webpack_require__(40)(function(){ 1410 | return Object.defineProperty(__webpack_require__(41)('div'), 'a', {get: function(){ return 7; }}).a != 7; 1411 | }); 1412 | 1413 | /***/ }, 1414 | /* 39 */ 1415 | /***/ function(module, exports, __webpack_require__) { 1416 | 1417 | // Thank's IE8 for his funny defineProperty 1418 | module.exports = !__webpack_require__(40)(function(){ 1419 | return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; 1420 | }); 1421 | 1422 | /***/ }, 1423 | /* 40 */ 1424 | /***/ function(module, exports) { 1425 | 1426 | module.exports = function(exec){ 1427 | try { 1428 | return !!exec(); 1429 | } catch(e){ 1430 | return true; 1431 | } 1432 | }; 1433 | 1434 | /***/ }, 1435 | /* 41 */ 1436 | /***/ function(module, exports, __webpack_require__) { 1437 | 1438 | var isObject = __webpack_require__(37) 1439 | , document = __webpack_require__(26).document 1440 | // in old IE typeof document.createElement is 'object' 1441 | , is = isObject(document) && isObject(document.createElement); 1442 | module.exports = function(it){ 1443 | return is ? document.createElement(it) : {}; 1444 | }; 1445 | 1446 | /***/ }, 1447 | /* 42 */ 1448 | /***/ function(module, exports, __webpack_require__) { 1449 | 1450 | // 7.1.1 ToPrimitive(input [, PreferredType]) 1451 | var isObject = __webpack_require__(37); 1452 | // instead of the ES6 spec version, we didn't implement @@toPrimitive case 1453 | // and the second argument - flag - preferred type is a string 1454 | module.exports = function(it, S){ 1455 | if(!isObject(it))return it; 1456 | var fn, val; 1457 | if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; 1458 | if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val; 1459 | if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; 1460 | throw TypeError("Can't convert object to primitive value"); 1461 | }; 1462 | 1463 | /***/ }, 1464 | /* 43 */ 1465 | /***/ function(module, exports) { 1466 | 1467 | module.exports = function(bitmap, value){ 1468 | return { 1469 | enumerable : !(bitmap & 1), 1470 | configurable: !(bitmap & 2), 1471 | writable : !(bitmap & 4), 1472 | value : value 1473 | }; 1474 | }; 1475 | 1476 | /***/ }, 1477 | /* 44 */ 1478 | /***/ function(module, exports) { 1479 | 1480 | 'use strict'; 1481 | 1482 | /** 1483 | * JSON parse. 1484 | * 1485 | * @see Based on jQuery#parseJSON (MIT) and JSON2 1486 | * @api private 1487 | */ 1488 | 1489 | var rvalidchars = /^[\],:{}\s]*$/; 1490 | var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g; 1491 | var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; 1492 | var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g; 1493 | var rtrimLeft = /^\s+/; 1494 | var rtrimRight = /\s+$/; 1495 | 1496 | module.exports = function parsejson(data) { 1497 | if ('string' != typeof data || !data) { 1498 | return null; 1499 | } 1500 | 1501 | data = data.replace(rtrimLeft, '').replace(rtrimRight, ''); 1502 | 1503 | // Attempt to parse using the native JSON parser first 1504 | if (JSON.parse) { 1505 | return JSON.parse(data); 1506 | } 1507 | 1508 | if (rvalidchars.test(data.replace(rvalidescape, '@').replace(rvalidtokens, ']').replace(rvalidbraces, ''))) { 1509 | return new Function('return ' + data)(); 1510 | } 1511 | }; 1512 | 1513 | /***/ }, 1514 | /* 45 */ 1515 | /***/ function(module, exports) { 1516 | 1517 | /** 1518 | * Parses an URI 1519 | * 1520 | * @author Steven Levithan (MIT license) 1521 | * @api private 1522 | */ 1523 | 1524 | var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; 1525 | 1526 | var parts = [ 1527 | 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor' 1528 | ]; 1529 | 1530 | module.exports = function parseuri(str) { 1531 | var src = str, 1532 | b = str.indexOf('['), 1533 | e = str.indexOf(']'); 1534 | 1535 | if (b != -1 && e != -1) { 1536 | str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length); 1537 | } 1538 | 1539 | var m = re.exec(str || ''), 1540 | uri = {}, 1541 | i = 14; 1542 | 1543 | while (i--) { 1544 | uri[parts[i]] = m[i] || ''; 1545 | } 1546 | 1547 | if (b != -1 && e != -1) { 1548 | uri.source = src; 1549 | uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':'); 1550 | uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':'); 1551 | uri.ipv6uri = true; 1552 | } 1553 | 1554 | return uri; 1555 | }; 1556 | 1557 | 1558 | /***/ }, 1559 | /* 46 */ 1560 | /***/ function(module, exports, __webpack_require__) { 1561 | 1562 | 'use strict'; 1563 | 1564 | Object.defineProperty(exports, "__esModule", { 1565 | value: true 1566 | }); 1567 | 1568 | var _stringify = __webpack_require__(47); 1569 | 1570 | var _stringify2 = _interopRequireDefault(_stringify); 1571 | 1572 | exports.encoder = encoder; 1573 | exports.decoder = decoder; 1574 | 1575 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1576 | 1577 | exports.types = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'ERROR', 'BINARY_EVENT', 'BINARY_ACK']; 1578 | 1579 | function encoder(obj, callback) { 1580 | // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) 1581 | // TODO support binary packet 1582 | var encoding = encodeAsString(obj); 1583 | callback([encoding]); 1584 | } 1585 | 1586 | function encodeAsString(obj) { 1587 | var str = ''; 1588 | var nsp = false; 1589 | 1590 | str += obj.type; 1591 | // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {} 1592 | // TODO support binary type 1593 | 1594 | if (obj.nsp && '/' != obj.nsp) { 1595 | nsp = true; 1596 | str += obj.nsp; 1597 | } 1598 | 1599 | if (null != obj.id) { 1600 | if (nsp) { 1601 | str += ','; 1602 | nsp = false; 1603 | } 1604 | str += obj.id; 1605 | } 1606 | 1607 | if (null != obj.data) { 1608 | if (nsp) str += ','; 1609 | str += (0, _stringify2.default)(obj.data); 1610 | } 1611 | 1612 | return str; 1613 | } 1614 | 1615 | function decoder(obj, callback) { 1616 | var packet = void 0; 1617 | if ('string' == typeof obj) { 1618 | packet = decodeString(obj); 1619 | } 1620 | callback(packet); 1621 | } 1622 | 1623 | function decodeString(str) { 1624 | var p = {}; 1625 | var i = 0; 1626 | // look up type 1627 | p.type = Number(str.charAt(0)); 1628 | if (null == exports.types[p.type]) return error(); 1629 | 1630 | // look up attachments if type binary 1631 | 1632 | // look up namespace (if any) 1633 | if ('/' == str.charAt(i + 1)) { 1634 | p.nsp = ''; 1635 | while (++i) { 1636 | var c = str.charAt(i); 1637 | if (',' == c) break; 1638 | p.nsp += c; 1639 | if (i == str.length) break; 1640 | } 1641 | } else { 1642 | p.nsp = '/'; 1643 | } 1644 | 1645 | // look up id 1646 | var next = str.charAt(i + 1); 1647 | if ('' !== next && Number(next) == next) { 1648 | p.id = ''; 1649 | while (++i) { 1650 | var _c = str.charAt(i); 1651 | if (null == _c || Number(_c) != _c) { 1652 | --i; 1653 | break; 1654 | } 1655 | p.id += str.charAt(i); 1656 | if (i == str.length) break; 1657 | } 1658 | p.id = Number(p.id); 1659 | } 1660 | 1661 | // look up json data 1662 | if (str.charAt(++i)) { 1663 | try { 1664 | p.data = JSON.parse(str.substr(i)); 1665 | } catch (e) { 1666 | return error(); 1667 | } 1668 | } 1669 | return p; 1670 | } 1671 | 1672 | function error(data) { 1673 | return { 1674 | type: exports.ERROR, 1675 | data: 'parser error' 1676 | }; 1677 | } 1678 | 1679 | /***/ }, 1680 | /* 47 */ 1681 | /***/ function(module, exports, __webpack_require__) { 1682 | 1683 | module.exports = { "default": __webpack_require__(48), __esModule: true }; 1684 | 1685 | /***/ }, 1686 | /* 48 */ 1687 | /***/ function(module, exports, __webpack_require__) { 1688 | 1689 | var core = __webpack_require__(31) 1690 | , $JSON = core.JSON || (core.JSON = {stringify: JSON.stringify}); 1691 | module.exports = function stringify(it){ // eslint-disable-line no-unused-vars 1692 | return $JSON.stringify.apply($JSON, arguments); 1693 | }; 1694 | 1695 | /***/ }, 1696 | /* 49 */ 1697 | /***/ function(module, exports, __webpack_require__) { 1698 | 1699 | 'use strict'; 1700 | 1701 | Object.defineProperty(exports, "__esModule", { 1702 | value: true 1703 | }); 1704 | 1705 | var _componentEmitter = __webpack_require__(3); 1706 | 1707 | var _componentEmitter2 = _interopRequireDefault(_componentEmitter); 1708 | 1709 | var _on = __webpack_require__(7); 1710 | 1711 | var _on2 = _interopRequireDefault(_on); 1712 | 1713 | var _componentBind = __webpack_require__(4); 1714 | 1715 | var _componentBind2 = _interopRequireDefault(_componentBind); 1716 | 1717 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1718 | 1719 | (0, _componentEmitter2.default)(Socket.prototype); 1720 | 1721 | var parser = { 1722 | CONNECT: 0, 1723 | DISCONNECT: 1, 1724 | EVENT: 2, 1725 | ACK: 3, 1726 | ERROR: 4, 1727 | BINARY_EVENT: 5, 1728 | BINARY_ACK: 6 1729 | }; 1730 | 1731 | var events = { 1732 | connect: 1, 1733 | connect_error: 1, 1734 | connect_timeout: 1, 1735 | connecting: 1, 1736 | disconnect: 1, 1737 | error: 1, 1738 | reconnect: 1, 1739 | reconnect_attempt: 1, 1740 | reconnect_failed: 1, 1741 | reconnect_error: 1, 1742 | reconnecting: 1, 1743 | ping: 1, 1744 | pong: 1 1745 | }; 1746 | 1747 | var emit = _componentEmitter2.default.prototype.emit; 1748 | 1749 | exports.default = Socket; 1750 | 1751 | 1752 | function Socket(io, nsp) { 1753 | this.io = io; 1754 | this.nsp = nsp; 1755 | this.id = 0; // sid 1756 | this.connected = false; 1757 | this.disconnected = true; 1758 | this.receiveBuffer = []; 1759 | this.sendBuffer = []; 1760 | if (this.io.autoConnect) this.open(); 1761 | } 1762 | 1763 | Socket.prototype.subEvents = function () { 1764 | if (this.subs) return; 1765 | 1766 | var io = this.io; 1767 | this.subs = [(0, _on2.default)(io, 'open', (0, _componentBind2.default)(this, 'onopen')), (0, _on2.default)(io, 'packet', (0, _componentBind2.default)(this, 'onpacket')), (0, _on2.default)(io, 'close', (0, _componentBind2.default)(this, 'onclose'))]; 1768 | }; 1769 | 1770 | Socket.prototype.open = Socket.prototype.connect = function () { 1771 | if (this.connected) return this; 1772 | this.subEvents(); 1773 | this.io.open(); // ensure open 1774 | if ('open' == this.io.readyState) this.onopen(); 1775 | return this; 1776 | }; 1777 | 1778 | Socket.prototype.onopen = function () { 1779 | if ('/' != this.nsp) this.packet({ type: parser.CONNECT }); 1780 | }; 1781 | 1782 | Socket.prototype.onclose = function (reason) { 1783 | this.connected = false; 1784 | this.disconnected = true; 1785 | delete this.id; 1786 | this.emit('disconnect', reason); 1787 | }; 1788 | 1789 | Socket.prototype.onpacket = function (packet) { 1790 | if (packet.nsp != this.nsp) return; 1791 | 1792 | switch (packet.type) { 1793 | case parser.CONNECT: 1794 | this.onconnect(); 1795 | break; 1796 | case parser.EVENT: 1797 | this.onevent(packet); 1798 | break; 1799 | case parser.DISCONNECT: 1800 | this.disconnect(); 1801 | break; 1802 | case parser.ERROR: 1803 | this.emit('error', packet.data); 1804 | break; 1805 | } 1806 | }; 1807 | 1808 | Socket.prototype.onconnect = function () { 1809 | this.connected = true; 1810 | this.disconnected = false; 1811 | this.emit('connect'); 1812 | // this.emitBuffered() 1813 | }; 1814 | 1815 | Socket.prototype.onevent = function (packet) { 1816 | var args = packet.data || []; 1817 | 1818 | if (this.connected) { 1819 | emit.apply(this, args); 1820 | } else { 1821 | this.receiveBuffer.push(args); 1822 | } 1823 | }; 1824 | 1825 | Socket.prototype.close = Socket.prototype.disconnect = function () { 1826 | if (this.connected) { 1827 | this.packet({ type: parser.DISCONNECT }); 1828 | } 1829 | 1830 | this.destroy(); 1831 | 1832 | if (this.connected) { 1833 | this.onclose('io client disconnect'); 1834 | } 1835 | return this; 1836 | }; 1837 | 1838 | Socket.prototype.destroy = function () { 1839 | if (this.subs) { 1840 | for (var i = 0; i < this.subs.length; i++) { 1841 | this.subs[i].destroy(); 1842 | } 1843 | this.subs = null; 1844 | } 1845 | this.io.destroy(this); 1846 | }; 1847 | 1848 | Socket.prototype.emit = function () { 1849 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 1850 | args[_key] = arguments[_key]; 1851 | } 1852 | 1853 | if (events.hasOwnProperty(args[0])) { 1854 | emit.apply(this, args); 1855 | return this; 1856 | } 1857 | 1858 | var parserType = parser.EVENT; 1859 | // if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary 1860 | var packet = { type: parserType, data: args, options: {} }; 1861 | 1862 | if (this.connected) { 1863 | this.packet(packet); 1864 | } else { 1865 | this.sendBuffer.push(packet); 1866 | } 1867 | return this; 1868 | }; 1869 | 1870 | Socket.prototype.packet = function (packet) { 1871 | packet.nsp = this.nsp; 1872 | this.io.packet(packet); 1873 | }; 1874 | 1875 | /***/ }, 1876 | /* 50 */ 1877 | /***/ function(module, exports, __webpack_require__) { 1878 | 1879 | 'use strict'; 1880 | 1881 | Object.defineProperty(exports, "__esModule", { 1882 | value: true 1883 | }); 1884 | 1885 | var _parseuri = __webpack_require__(45); 1886 | 1887 | var _parseuri2 = _interopRequireDefault(_parseuri); 1888 | 1889 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1890 | 1891 | exports.default = function (uri) { 1892 | var obj = (0, _parseuri2.default)(uri); 1893 | 1894 | // make sure we treat `localhost:80` and `localhost` equally 1895 | if (!obj.port) { 1896 | if (/^(http|ws)$/.test(obj.protocol)) { 1897 | obj.port = '80'; 1898 | } else if (/^(http|ws)s$/.test(obj.protocol)) { 1899 | obj.port = '443'; 1900 | } 1901 | } 1902 | 1903 | obj.path = obj.path || '/'; 1904 | var ipv6 = obj.host.indexOf(':') !== -1; 1905 | var host = ipv6 ? '[' + obj.host + ']' : obj.host; 1906 | 1907 | // define unique id 1908 | obj.id = obj.protocol + '://' + host + ':' + obj.port; 1909 | 1910 | return obj; 1911 | }; 1912 | 1913 | /***/ } 1914 | /******/ ]) 1915 | }); 1916 | ; 1917 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /dist/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap eded9e6b5689aaebe185","webpack:///./index.js","webpack:///./manager.js","webpack:///../~/component-emitter/index.js","webpack:///../~/component-bind/index.js","webpack:///../~/backo2/index.js","webpack:///../~/indexof/index.js","webpack:///./on.js","webpack:///./engine.js","webpack:///../~/babel-runtime/core-js/object/keys.js","webpack:///../~/core-js/library/fn/object/keys.js","webpack:///../~/core-js/library/modules/es6.object.keys.js","webpack:///../~/core-js/library/modules/_to-object.js","webpack:///../~/core-js/library/modules/_defined.js","webpack:///../~/core-js/library/modules/_object-keys.js","webpack:///../~/core-js/library/modules/_object-keys-internal.js","webpack:///../~/core-js/library/modules/_has.js","webpack:///../~/core-js/library/modules/_to-iobject.js","webpack:///../~/core-js/library/modules/_iobject.js","webpack:///../~/core-js/library/modules/_cof.js","webpack:///../~/core-js/library/modules/_array-includes.js","webpack:///../~/core-js/library/modules/_to-length.js","webpack:///../~/core-js/library/modules/_to-integer.js","webpack:///../~/core-js/library/modules/_to-index.js","webpack:///../~/core-js/library/modules/_shared-key.js","webpack:///../~/core-js/library/modules/_shared.js","webpack:///../~/core-js/library/modules/_global.js","webpack:///../~/core-js/library/modules/_uid.js","webpack:///../~/core-js/library/modules/_enum-bug-keys.js","webpack:///../~/core-js/library/modules/_object-sap.js","webpack:///../~/core-js/library/modules/_export.js","webpack:///../~/core-js/library/modules/_core.js","webpack:///../~/core-js/library/modules/_ctx.js","webpack:///../~/core-js/library/modules/_a-function.js","webpack:///../~/core-js/library/modules/_hide.js","webpack:///../~/core-js/library/modules/_object-dp.js","webpack:///../~/core-js/library/modules/_an-object.js","webpack:///../~/core-js/library/modules/_is-object.js","webpack:///../~/core-js/library/modules/_ie8-dom-define.js","webpack:///../~/core-js/library/modules/_descriptors.js","webpack:///../~/core-js/library/modules/_fails.js","webpack:///../~/core-js/library/modules/_dom-create.js","webpack:///../~/core-js/library/modules/_to-primitive.js","webpack:///../~/core-js/library/modules/_property-desc.js","webpack:///./parsejson.js","webpack:///../~/parseuri/index.js","webpack:///./parser.js","webpack:///../~/babel-runtime/core-js/json/stringify.js","webpack:///../~/core-js/library/fn/json/stringify.js","webpack:///./socket.js","webpack:///./url.js"],"names":["lookup","cache","uri","opts","Error","parsed","source","id","path","sameNamespace","nsps","newConnection","forceNew","multiplex","io","socket","exports","connect","has","Object","prototype","hasOwnProperty","Manager","subs","readyState","connected","reconnection","reconnectionAttempts","Infinity","reconnectionDelay","reconnectionDelayMax","randomizationFactor","backoff","min","max","jitter","timeout","encoder","decoder","connecting","autoConnect","open","fn","indexOf","engine","push","onopen","cleanup","emitAll","data","error","maybeReconnectOnOpen","emit","onclose","reason","_reconnection","skipReconnect","reconnect","onerror","onping","lastPing","Date","onpong","ondata","decoding","packet","i","encodedPackets","length","write","options","nsp","sub","shift","destroy","packetBuffer","args","apply","call","reconnecting","attempts","_reconnectionAttempts","reset","delay","duration","timer","setTimeout","err","onreconnect","clearTimeout","attempt","updateSocketIds","index","splice","close","disconnect","v","arguments","_reconnectionDelay","setMin","_randomizationFactor","setJitter","_reconnectionDelayMax","setMax","_timeout","obj","ev","on","removeListener","Engine","GlobalEmitter","hasEmitte","packets","ping","pong","message","upgrade","noop","packetslist","protocol","host","query","port","replace","pingInterval","bindEvents","subEvents","url","wx","connectSocket","closeSocket","onpacket","type","onHandshake","setPing","code","sid","pingTimeout","pingIntervalTimer","_send","send","join","sendSocketMessage","onSocketOpen","onSocketClose","onSocketError","onSocketMessage","decodePacket","resp","writeBuffer","prevBufferLen","charAt","substring","rvalidchars","rvalidescape","rvalidtokens","rvalidbraces","rtrimLeft","rtrimRight","module","parsejson","JSON","parse","test","Function","types","callback","encoding","encodeAsString","str","decodeString","p","Number","c","next","substr","e","ERROR","Socket","parser","CONNECT","DISCONNECT","EVENT","ACK","BINARY_EVENT","BINARY_ACK","events","connect_error","connect_timeout","reconnect_attempt","reconnect_failed","reconnect_error","disconnected","receiveBuffer","sendBuffer","onconnect","onevent","parserType","ipv6"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD,O;ACVA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;;;;;;;;;;;;;mBCjCwBA,M;;AALxB;;;;AACA;;;;;;AAEA,KAAMC,QAAQ,EAAd;;AAEe,UAASD,MAAT,CAAgBE,GAAhB,EAAqBC,IAArB,EAA2B;AACxC,OAAI,CAACD,GAAL,EAAU;AACR,WAAM,IAAIE,KAAJ,CAAU,kBAAV,CAAN;AACD;;AAEDD,UAAOA,QAAQ,EAAf;;AAEA,OAAME,SAAS,mBAAIH,GAAJ,CAAf;;AAEA,OAAMI,SAASD,OAAOC,MAAtB;AACA,OAAMC,KAAKF,OAAOE,EAAlB;AACA,OAAMC,OAAOH,OAAOG,IAApB;AACA,OAAMC,gBAAgBR,MAAMM,EAAN,KAAaC,QAAQP,MAAMM,EAAN,EAAUG,IAArD;;AAEA,OAAMC,gBAAgBR,KAAKS,QAAL,IAAiBT,KAAK,sBAAL,CAAjB,IACA,UAAUA,KAAKU,SADf,IAC4BJ,aADlD;;AAGA;AACA,OAAIK,WAAJ;AACA,OAAIH,aAAJ,EAAmB;AACjBG,UAAK,uBAAQR,MAAR,EAAgBH,IAAhB,CAAL;AACD,IAFD,MAEO;AACL,SAAI,CAACF,MAAMM,EAAN,CAAL,EAAgB;AACdN,aAAMM,EAAN,IAAY,uBAAQD,MAAR,EAAgBH,IAAhB,CAAZ;AACD;AACDW,UAAKb,MAAMM,EAAN,CAAL;AACD;AACD,UAAOO,GAAGC,MAAH,CAAUV,OAAOG,IAAjB,CAAP;AACD;;AAEDQ,SAAQC,OAAR,GAAkBjB,MAAlB,C;;;;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f,EAAuB,OAAO,KAAKoC,QAAZ;AACvB,QAAKA,QAAL,GAAgBR,CAAhB;AACA,UAAO,IAAP;AACD,EAJD;;AAMA;;;;;;AAMA1E,SAAQF,SAAR,CAAkB+B,oBAAlB,GAAyC,YAAW;AAClD;AACA,OAAI,CAAC,KAAK4B,YAAN,IAAsB,KAAKxB,aAA3B,IAA4C,KAAKvB,OAAL,CAAagD,QAAb,KAA0B,CAA1E,EAA6E;AAC3E;AACA,UAAKvB,SAAL;AACD;AACF,EAND,C;;;;;;;AClTA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA,YAAW,OAAO;AAClB,aAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,YAAW,OAAO;AAClB,YAAW,SAAS;AACpB,aAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAW,OAAO;AAClB,YAAW,SAAS;AACpB,aAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,YAAW,OAAO;AAClB,YAAW,SAAS;AACpB,aAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA,kBAAiB,sBAAsB;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,YAAW,OAAO;AAClB,YAAW,MAAM;AACjB,aAAY;AACZ;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA,4CAA2C,SAAS;AACpD;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA,YAAW,OAAO;AAClB,aAAY;AACZ;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,YAA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B;AACvB;AACA;AACA,G;;;;;;ACHA;AACA;AACA;AACA;AACA;AACA,G;;;;;;ACLA;AACA;AACA;AACA;AACA,G;;;;;;ACJA,kBAAiB;;AAEjB;AACA;AACA,G;;;;;;ACJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAK,WAAW,eAAe;AAC/B;AACA,MAAK;AACL;AACA,G;;;;;;ACpBA;AACA;AACA;AACA;AACA,4DAA2D;AAC3D,G;;;;;;ACLA;AACA;AACA;AACA;AACA;AACA,G;;;;;;ACLA;AACA;AACA;AACA;AACA;AACA;AACA,G;;;;;;ACNA;AACA;AACA;AACA;AACA,G;;;;;;ACJA;AACA;AACA,oDAAmD;AACnD;AACA,wCAAuC;AACvC,G;;;;;;ACLA;AACA;AACA;AACA,wCAAuC,gC;;;;;;ACHvC;AACA;AACA;AACA;AACA,G;;;;;;ACJA;AACA;AACA;AACA,c;;;;;;ACHA;AACA;AACA;AACA;AACA;AACA,+BAA8B;AAC9B;AACA;AACA,oDAAmD,OAAO,EAAE;AAC5D,G;;;;;;ACTA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oEAAmE;AACnE;AACA,sFAAqF;AACrF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,YAAW;AACX,UAAS;AACT;AACA;AACA;AACA;AACA,MAAK;AACL;AACA;AACA,gDAA+C;AAC/C;AACA;AACA;AACA;AACA;AACA;AACA,eAAc;AACd,eAAc;AACd,eAAc;AACd,eAAc;AACd,gBAAe;AACf,gBAAe;AACf,gBAAe;AACf,iBAAgB;AAChB,0B;;;;;;AC5DA,8BAA6B;AAC7B,sCAAqC,gC;;;;;;ACDrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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,CAAeA,MAAf;AACD,EAHD,C;;;;;;;;;;;;AC5JA;;;;;;mBAEe,eAAO;AACpB,OAAMwC,MAAM,wBAASvG,GAAT,CAAZ;;AAEA;AACA,OAAI,CAACuG,IAAIiB,IAAT,EAAe;AACb,SAAI,cAAcyC,IAAd,CAAmB1D,IAAIc,QAAvB,CAAJ,EAAsC;AACpCd,WAAIiB,IAAJ,GAAW,IAAX;AACD,MAFD,MAEO,IAAI,eAAeyC,IAAf,CAAoB1D,IAAIc,QAAxB,CAAJ,EAAuC;AAC5Cd,WAAIiB,IAAJ,GAAW,KAAX;AACD;AACF;;AAEDjB,OAAIjG,IAAJ,GAAWiG,IAAIjG,IAAJ,IAAY,GAAvB;AACA,OAAM8L,OAAO7F,IAAIe,IAAJ,CAAS7E,OAAT,CAAiB,GAAjB,MAA0B,CAAC,CAAxC;AACA,OAAM6E,OAAO8E,aAAW7F,IAAIe,IAAf,SAAyBf,IAAIe,IAA1C;;AAEA;AACAf,OAAIlG,EAAJ,GAAYkG,IAAIc,QAAhB,WAA8BC,IAA9B,SAAsCf,IAAIiB,IAA1C;;AAEA,UAAOjB,GAAP;AACD,E","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap eded9e6b5689aaebe185","import manager from './manager'\nimport url from './url'\n\nconst cache = {}\n\nexport default function lookup(uri, opts) {\n if (!uri) {\n throw new Error('uri is required.')\n }\n\n opts = opts || {}\n\n const parsed = url(uri)\n\n const source = parsed.source\n const id = parsed.id\n const path = parsed.path\n const sameNamespace = cache[id] && path in cache[id].nsps\n\n const newConnection = opts.forceNew || opts['force new connection'] ||\n false === opts.multiplex || sameNamespace\n\n // return new socket or from cache\n let io\n if (newConnection) {\n io = manager(source, opts)\n } else {\n if (!cache[id]) {\n cache[id] = manager(source, opts)\n }\n io = cache[id]\n }\n return io.socket(parsed.path)\n}\n\nexports.connect = lookup\n\n\n\n// WEBPACK FOOTER //\n// ./index.js","import Emitter from 'component-emitter'\nimport bind from 'component-bind'\nimport Backoff from 'backo2'\nimport indexOf from 'indexof'\nimport on from './on'\nimport Engine from './engine'\nimport { encoder, decoder } from './parser'\nimport Socket from './socket'\n\nconst has = Object.prototype.hasOwnProperty\n\nEmitter(Manager.prototype)\n\nexport default Manager\n\nfunction Manager(uri, opts) {\n if (!(this instanceof Manager)) return new Manager(uri, opts)\n\n opts.path = opts.path || 'socket.io'\n this.nsps = {}\n this.subs = []\n this.opts = opts\n this.uri = uri\n this.readyState = 'closed'\n this.connected = false\n this.reconnection(opts.reconnection !== false)\n this.reconnectionAttempts(opts.reconnectionAttempts || Infinity)\n this.reconnectionDelay(opts.reconnectionDelay || 1000)\n this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000)\n this.randomizationFactor(opts.randomizationFactor || 0.5)\n this.backoff = new Backoff({\n min: this.reconnectionDelay(),\n max: this.reconnectionDelayMax(),\n jitter: this.randomizationFactor(),\n })\n this.timeout(null == opts.timeout ? 20000 : opts.timeout)\n this.encoder = encoder\n this.decoder = decoder\n this.connecting = []\n this.autoConnect = opts.autoConnect !== false\n if (this.autoConnect) this.open()\n}\n\nManager.prototype.open =\nManager.prototype.connect = function(fn) {\n if (~this.readyState.indexOf('open')) return this\n\n this.engine = new Engine(this.uri, this.opts)\n\n this.readyState = 'opening'\n\n const socket = this.engine\n\n this.subs.push(on(socket, 'open', () => {\n this.onopen()\n fn && fn()\n }))\n\n this.subs.push(on(socket, 'error', data => {\n this.cleanup()\n this.readyState = 'closed'\n this.emitAll('connect_error', data)\n if (fn) {\n const error = new Error('Connect error')\n error.data = data\n fn(error)\n } else {\n this.maybeReconnectOnOpen()\n }\n }))\n\n socket.connect()\n return this\n}\n\nManager.prototype.onopen = function() {\n this.cleanup()\n\n this.readyState = 'open'\n this.emit('open')\n\n const socket = this.engine\n this.subs.push(on(socket, 'data', bind(this, 'ondata')))\n this.subs.push(on(socket, 'ping', bind(this, 'onping')))\n this.subs.push(on(socket, 'pong', bind(this, 'onpong')))\n this.subs.push(on(socket, 'error', bind(this, 'onerror')))\n this.subs.push(on(socket, 'close', bind(this, 'onclose')))\n // this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded')))\n}\n\nManager.prototype.onclose = function(reason) {\n this.cleanup()\n this.readyState = 'closed'\n this.emit('close', reason)\n if (this._reconnection && !this.skipReconnect) this.reconnect()\n}\n\nManager.prototype.onerror = function(reason) {\n this.emitAll('error')\n}\n\nManager.prototype.onping = function() {\n this.lastPing = new Date\n this.emitAll('ping')\n}\n\nManager.prototype.onpong = function() {\n this.emitAll('pong', new Date - this.lastPing)\n}\n\nManager.prototype.ondata = function(data) {\n this.decoder(data, decoding => {\n this.emit('packet', decoding)\n })\n}\n\nManager.prototype.packet = function(packet) {\n this.encoder(packet, encodedPackets => {\n for (let i = 0; i < encodedPackets.length; i++) {\n this.engine.write(encodedPackets[i], packet.options)\n }\n })\n}\n\nManager.prototype.socket = function(nsp) {\n let socket = this.nsps[nsp]\n if (!socket) {\n socket = new Socket(this, nsp)\n this.nsps[nsp] = socket\n }\n return socket\n}\n\nManager.prototype.cleanup = function() {\n let sub\n while (sub = this.subs.shift()) sub.destroy()\n\n this.packetBuffer = []\n this.lastPing = null\n}\n\nManager.prototype.emitAll = function(...args) {\n this.emit.apply(this, args)\n for (const nsp in this.nsps) {\n if (has.call(this.nsps, nsp)) {\n this.nsps[nsp].emit.apply(this.nsps[nsp], args)\n }\n }\n}\n\nManager.prototype.reconnect = function() {\n if (this.reconnecting || this.skipReconnect) return this\n\n if (this.backoff.attempts >= this._reconnectionAttempts) {\n this.backoff.reset()\n this.emitAll('reconnect_failed')\n this.reconnecting = false\n } else {\n const delay = this.backoff.duration()\n this.reconnecting = true\n const timer = setTimeout(() => {\n this.emitAll('reconnect_attempt', this.backoff.attempts)\n this.emitAll('reconnecting', this.backoff.attempts)\n\n if (this.skipReconnect) return\n\n this.open(err => {\n if (err) {\n this.reconnecting = false\n this.reconnect()\n this.emitAll('reconnect_error', err.data)\n } else {\n this.onreconnect()\n }\n })\n }, delay)\n\n this.subs.push({\n destroy: () => {\n clearTimeout(timer)\n },\n })\n }\n}\n\nManager.prototype.onreconnect = function() {\n const attempt = this.backoff.attempts\n this.reconnecting = false\n this.backoff.reset()\n this.updateSocketIds()\n this.emitAll('reconnect', attempt)\n}\n\n/**\n * Update `socket.id` of all sockets\n *\n * @api private\n */\n\nManager.prototype.updateSocketIds = function() {\n for (const nsp in this.nsps) {\n if (has.call(this.nsps, nsp)) {\n this.nsps[nsp].id = this.engine.id\n }\n }\n}\n\nManager.prototype.destroy = function(socket) {\n const index = indexOf(this.connecting, socket)\n if (~index) this.connecting.splice(index, 1)\n if (this.connecting.length) return\n\n this.close()\n}\n\nManager.prototype.close =\nManager.prototype.disconnect = function() {\n this.skipReconnect = true\n this.reconnecting = false\n if ('opening' == this.readyState) {\n // `onclose` will not fire because\n // an open event never happened\n this.cleanup()\n }\n this.readyState = 'closed'\n if (this.engine) this.engine.close()\n}\n\n/**\n * Sets the `reconnection` config.\n *\n * @param {Boolean} true/false if it should automatically reconnect\n * @return {Manager} self or value\n * @api public\n */\nManager.prototype.reconnection = function(v) {\n if (!arguments.length) return this._reconnection\n this._reconnection = !!v\n return this\n}\n\n/**\n * Sets the reconnection attempts config.\n *\n * @param {Number} max reconnection attempts before giving up\n * @return {Manager} self or value\n * @api public\n */\nManager.prototype.reconnectionAttempts = function(v) {\n if (!arguments.length) return this._reconnectionAttempts\n this._reconnectionAttempts = v\n return this\n}\n\n/**\n * Sets the delay between reconnections.\n *\n * @param {Number} delay\n * @return {Manager} self or value\n * @api public\n */\nManager.prototype.reconnectionDelay = function(v) {\n if (!arguments.length) return this._reconnectionDelay\n this._reconnectionDelay = v\n this.backoff && this.backoff.setMin(v)\n return this\n}\n\nManager.prototype.randomizationFactor = function(v) {\n if (!arguments.length) return this._randomizationFactor\n this._randomizationFactor = v\n this.backoff && this.backoff.setJitter(v)\n return this\n}\n\n/**\n * Sets the maximum delay between reconnections.\n *\n * @param {Number} delay\n * @return {Manager} self or value\n * @api public\n */\nManager.prototype.reconnectionDelayMax = function(v) {\n if (!arguments.length) return this._reconnectionDelayMax\n this._reconnectionDelayMax = v\n this.backoff && this.backoff.setMax(v)\n return this\n}\n\n/**\n * Sets the connection timeout. `false` to disable\n *\n * @return {Manager} self or value\n * @api public\n */\nManager.prototype.timeout = function(v) {\n if (!arguments.length) return this._timeout\n this._timeout = v\n return this\n}\n\n/**\n * Starts trying to reconnect if reconnection is enabled and we have not\n * started reconnecting yet\n *\n * @api private\n */\nManager.prototype.maybeReconnectOnOpen = function() {\n // Only try to reconnect if it's the first time we're connecting\n if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) {\n // keeps reconnection from firing twice for the same reconnection loop\n this.reconnect()\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./manager.js","\r\n/**\r\n * Expose `Emitter`.\r\n */\r\n\r\nif (typeof module !== 'undefined') {\r\n module.exports = Emitter;\r\n}\r\n\r\n/**\r\n * Initialize a new `Emitter`.\r\n *\r\n * @api public\r\n */\r\n\r\nfunction Emitter(obj) {\r\n if (obj) return mixin(obj);\r\n};\r\n\r\n/**\r\n * Mixin the emitter properties.\r\n *\r\n * @param {Object} obj\r\n * @return {Object}\r\n * @api private\r\n */\r\n\r\nfunction mixin(obj) {\r\n for (var key in Emitter.prototype) {\r\n obj[key] = Emitter.prototype[key];\r\n }\r\n return obj;\r\n}\r\n\r\n/**\r\n * Listen on the given `event` with `fn`.\r\n *\r\n * @param {String} event\r\n * @param {Function} fn\r\n * @return {Emitter}\r\n * @api public\r\n */\r\n\r\nEmitter.prototype.on =\r\nEmitter.prototype.addEventListener = function(event, fn){\r\n this._callbacks = this._callbacks || {};\r\n (this._callbacks['$' + event] = this._callbacks['$' + event] || [])\r\n .push(fn);\r\n return this;\r\n};\r\n\r\n/**\r\n * Adds an `event` listener that will be invoked a single\r\n * time then automatically removed.\r\n *\r\n * @param {String} event\r\n * @param {Function} fn\r\n * @return {Emitter}\r\n * @api public\r\n */\r\n\r\nEmitter.prototype.once = function(event, fn){\r\n function on() {\r\n this.off(event, on);\r\n fn.apply(this, arguments);\r\n }\r\n\r\n on.fn = fn;\r\n this.on(event, on);\r\n return this;\r\n};\r\n\r\n/**\r\n * Remove the given callback for `event` or all\r\n * registered callbacks.\r\n *\r\n * @param {String} event\r\n * @param {Function} fn\r\n * @return {Emitter}\r\n * @api public\r\n */\r\n\r\nEmitter.prototype.off =\r\nEmitter.prototype.removeListener =\r\nEmitter.prototype.removeAllListeners =\r\nEmitter.prototype.removeEventListener = function(event, fn){\r\n this._callbacks = this._callbacks || {};\r\n\r\n // all\r\n if (0 == arguments.length) {\r\n this._callbacks = {};\r\n return this;\r\n }\r\n\r\n // specific event\r\n var callbacks = this._callbacks['$' + event];\r\n if (!callbacks) return this;\r\n\r\n // remove all handlers\r\n if (1 == arguments.length) {\r\n delete this._callbacks['$' + event];\r\n return this;\r\n }\r\n\r\n // remove specific handler\r\n var cb;\r\n for (var i = 0; i < callbacks.length; i++) {\r\n cb = callbacks[i];\r\n if (cb === fn || cb.fn === fn) {\r\n callbacks.splice(i, 1);\r\n break;\r\n }\r\n }\r\n return this;\r\n};\r\n\r\n/**\r\n * Emit `event` with the given args.\r\n *\r\n * @param {String} event\r\n * @param {Mixed} ...\r\n * @return {Emitter}\r\n */\r\n\r\nEmitter.prototype.emit = function(event){\r\n this._callbacks = this._callbacks || {};\r\n var args = [].slice.call(arguments, 1)\r\n , callbacks = this._callbacks['$' + event];\r\n\r\n if (callbacks) {\r\n callbacks = callbacks.slice(0);\r\n for (var i = 0, len = callbacks.length; i < len; ++i) {\r\n callbacks[i].apply(this, args);\r\n }\r\n }\r\n\r\n return this;\r\n};\r\n\r\n/**\r\n * Return array of callbacks for `event`.\r\n *\r\n * @param {String} event\r\n * @return {Array}\r\n * @api public\r\n */\r\n\r\nEmitter.prototype.listeners = function(event){\r\n this._callbacks = this._callbacks || {};\r\n return this._callbacks['$' + event] || [];\r\n};\r\n\r\n/**\r\n * Check if this emitter has `event` handlers.\r\n *\r\n * @param {String} event\r\n * @return {Boolean}\r\n * @api public\r\n */\r\n\r\nEmitter.prototype.hasListeners = function(event){\r\n return !! this.listeners(event).length;\r\n};\r\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/component-emitter/index.js\n// module id = 3\n// module chunks = 0","/**\n * Slice reference.\n */\n\nvar slice = [].slice;\n\n/**\n * Bind `obj` to `fn`.\n *\n * @param {Object} obj\n * @param {Function|String} fn or string\n * @return {Function}\n * @api public\n */\n\nmodule.exports = function(obj, fn){\n if ('string' == typeof fn) fn = obj[fn];\n if ('function' != typeof fn) throw new Error('bind() requires a function');\n var args = slice.call(arguments, 2);\n return function(){\n return fn.apply(obj, args.concat(slice.call(arguments)));\n }\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/component-bind/index.js\n// module id = 4\n// module chunks = 0","\n/**\n * Expose `Backoff`.\n */\n\nmodule.exports = Backoff;\n\n/**\n * Initialize backoff timer with `opts`.\n *\n * - `min` initial timeout in milliseconds [100]\n * - `max` max timeout [10000]\n * - `jitter` [0]\n * - `factor` [2]\n *\n * @param {Object} opts\n * @api public\n */\n\nfunction Backoff(opts) {\n opts = opts || {};\n this.ms = opts.min || 100;\n this.max = opts.max || 10000;\n this.factor = opts.factor || 2;\n this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0;\n this.attempts = 0;\n}\n\n/**\n * Return the backoff duration.\n *\n * @return {Number}\n * @api public\n */\n\nBackoff.prototype.duration = function(){\n var ms = this.ms * Math.pow(this.factor, this.attempts++);\n if (this.jitter) {\n var rand = Math.random();\n var deviation = Math.floor(rand * this.jitter * ms);\n ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation;\n }\n return Math.min(ms, this.max) | 0;\n};\n\n/**\n * Reset the number of attempts.\n *\n * @api public\n */\n\nBackoff.prototype.reset = function(){\n this.attempts = 0;\n};\n\n/**\n * Set the minimum duration\n *\n * @api public\n */\n\nBackoff.prototype.setMin = function(min){\n this.ms = min;\n};\n\n/**\n * Set the maximum duration\n *\n * @api public\n */\n\nBackoff.prototype.setMax = function(max){\n this.max = max;\n};\n\n/**\n * Set the jitter\n *\n * @api public\n */\n\nBackoff.prototype.setJitter = function(jitter){\n this.jitter = jitter;\n};\n\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/backo2/index.js\n// module id = 5\n// module chunks = 0","\nvar indexOf = [].indexOf;\n\nmodule.exports = function(arr, obj){\n if (indexOf) return arr.indexOf(obj);\n for (var i = 0; i < arr.length; ++i) {\n if (arr[i] === obj) return i;\n }\n return -1;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/indexof/index.js\n// module id = 6\n// module chunks = 0","/**\n * Helper for subscriptions.\n *\n * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter`\n * @param {String} event name\n * @param {Function} callback\n * @api public\n */\n\nexport default (obj, ev, fn) => {\n obj.on(ev, fn)\n return {\n destroy: () => {\n obj.removeListener(ev, fn)\n },\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./on.js","import Emitter from 'component-emitter'\nimport on from './on'\nimport parsejson from './parsejson'\nimport bind from 'component-bind'\nimport parseuri from 'parseuri'\n\nexport default Engine\n\nconst GlobalEmitter = Emitter({ hasEmitte: false })\n\nEmitter(Engine.prototype)\n\nconst packets = {\n open: 0, // non-ws\n close: 1, // non-ws\n ping: 2,\n pong: 3,\n message: 4,\n upgrade: 5,\n noop: 6,\n}\n\nconst packetslist = Object.keys(packets)\n\nfunction Engine(uri, opts) {\n if (!(this instanceof Engine)) return new Engine(uri, opts)\n\n this.subs = []\n uri = parseuri(uri)\n this.protocol = uri.protocol\n this.host = uri.host\n this.query = uri.query\n this.port = uri.port\n this.opts = this.opts || {}\n this.path = opts.path.replace(/\\/$/, '')\n this.connected = false\n this.lastPing = null\n this.pingInterval = 20000\n // init bind with GlobalEmitter\n this.bindEvents()\n}\n\nEngine.prototype.connect = function() {\n if (!GlobalEmitter.hasEmitte) Engine.subEvents()\n const url = `${this.protocol}://${this.host}:${this.port}/${this.path}/?${this.query ? `${this.query}&` : ''}EIO=3&transport=websocket`\n\n wx.connectSocket({ url })\n}\n\nEngine.prototype.onopen = function() {\n this.emit('open')\n}\n\nEngine.prototype.onclose = function(reason) {\n // clean all bind with GlobalEmitter\n this.destroy()\n this.emit('close', reason)\n}\n\nEngine.prototype.onerror = function(reason) {\n this.emit('error')\n // 如果 wx.connectSocket 还没回调 wx.onSocketOpen,而先调用 wx.closeSocket,那么就做不到关闭 WebSocket 的目的。\n wx.closeSocket()\n}\n\nEngine.prototype.onpacket = function(packet) {\n switch (packet.type) {\n case 'open':\n this.onHandshake(parsejson(packet.data))\n break\n case 'pong':\n this.setPing()\n this.emit('pong')\n break\n case 'error': {\n const error = new Error('server error')\n error.code = packet.data\n this.onerror(error)\n break\n }\n case 'message':\n this.emit('data', packet.data)\n this.emit('message', packet.data)\n break\n }\n}\n\nEngine.prototype.onHandshake = function(data) {\n this.id = data.sid\n this.pingInterval = data.pingInterval\n this.pingTimeout = data.pingTimeout\n this.setPing()\n}\n\nEngine.prototype.setPing = function() {\n clearTimeout(this.pingIntervalTimer)\n this.pingIntervalTimer = setTimeout(() => {\n this.ping()\n }, this.pingInterval)\n}\n\nEngine.prototype.ping = function() {\n this.emit('ping')\n this._send(`${packets.ping}probe`)\n}\n\nEngine.prototype.write =\nEngine.prototype.send = function(packet) {\n this._send([packets.message, packet].join(''))\n}\n\nEngine.prototype._send = function(data) {\n wx.sendSocketMessage({ data })\n}\nEngine.subEvents = function() {\n wx.onSocketOpen(() => {\n GlobalEmitter.emit('open')\n })\n wx.onSocketClose(reason => {\n GlobalEmitter.emit('close', reason)\n })\n wx.onSocketError(reason => {\n GlobalEmitter.emit('error', reason)\n })\n wx.onSocketMessage(resp => {\n GlobalEmitter.emit('packet', decodePacket(resp.data))\n })\n GlobalEmitter.hasEmitte = true\n}\n\nEngine.prototype.bindEvents = function() {\n this.subs.push(on(GlobalEmitter, 'open', bind(this, 'onopen')))\n this.subs.push(on(GlobalEmitter, 'close', bind(this, 'onclose')))\n this.subs.push(on(GlobalEmitter, 'error', bind(this, 'onerror')))\n this.subs.push(on(GlobalEmitter, 'packet', bind(this, 'onpacket')))\n}\n\nEngine.prototype.destroy = function() {\n let sub\n while (sub = this.subs.shift()) { sub.destroy() }\n\n clearTimeout(this.pingIntervalTimer)\n this.readyState = 'closed'\n this.id = null\n this.writeBuffer = []\n this.prevBufferLen = 0\n}\n\nfunction decodePacket(data) {\n const type = data.charAt(0)\n if (data.length > 1) {\n return {\n type: packetslist[type],\n data: data.substring(1),\n }\n }\n return { type: packetslist[type] }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./engine.js","module.exports = { \"default\": require(\"core-js/library/fn/object/keys\"), __esModule: true };\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/babel-runtime/core-js/object/keys.js\n// module id = 9\n// module chunks = 0","require('../../modules/es6.object.keys');\nmodule.exports = require('../../modules/_core').Object.keys;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/fn/object/keys.js\n// module id = 10\n// module chunks = 0","// 19.1.2.14 Object.keys(O)\nvar toObject = require('./_to-object')\n , $keys = require('./_object-keys');\n\nrequire('./_object-sap')('keys', function(){\n return function keys(it){\n return $keys(toObject(it));\n };\n});\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/es6.object.keys.js\n// module id = 11\n// module chunks = 0","// 7.1.13 ToObject(argument)\nvar defined = require('./_defined');\nmodule.exports = function(it){\n return Object(defined(it));\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_to-object.js\n// module id = 12\n// module chunks = 0","// 7.2.1 RequireObjectCoercible(argument)\nmodule.exports = function(it){\n if(it == undefined)throw TypeError(\"Can't call method on \" + it);\n return it;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_defined.js\n// module id = 13\n// module chunks = 0","// 19.1.2.14 / 15.2.3.14 Object.keys(O)\nvar $keys = require('./_object-keys-internal')\n , enumBugKeys = require('./_enum-bug-keys');\n\nmodule.exports = Object.keys || function keys(O){\n return $keys(O, enumBugKeys);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_object-keys.js\n// module id = 14\n// module chunks = 0","var has = require('./_has')\n , toIObject = require('./_to-iobject')\n , arrayIndexOf = require('./_array-includes')(false)\n , IE_PROTO = require('./_shared-key')('IE_PROTO');\n\nmodule.exports = function(object, names){\n var O = toIObject(object)\n , i = 0\n , result = []\n , key;\n for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key);\n // Don't enum bug & hidden keys\n while(names.length > i)if(has(O, key = names[i++])){\n ~arrayIndexOf(result, key) || result.push(key);\n }\n return result;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_object-keys-internal.js\n// module id = 15\n// module chunks = 0","var hasOwnProperty = {}.hasOwnProperty;\nmodule.exports = function(it, key){\n return hasOwnProperty.call(it, key);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_has.js\n// module id = 16\n// module chunks = 0","// to indexed object, toObject with fallback for non-array-like ES3 strings\nvar IObject = require('./_iobject')\n , defined = require('./_defined');\nmodule.exports = function(it){\n return IObject(defined(it));\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_to-iobject.js\n// module id = 17\n// module chunks = 0","// fallback for non-array-like ES3 and non-enumerable old V8 strings\nvar cof = require('./_cof');\nmodule.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){\n return cof(it) == 'String' ? it.split('') : Object(it);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_iobject.js\n// module id = 18\n// module chunks = 0","var toString = {}.toString;\n\nmodule.exports = function(it){\n return toString.call(it).slice(8, -1);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_cof.js\n// module id = 19\n// module chunks = 0","// false -> Array#indexOf\n// true -> Array#includes\nvar toIObject = require('./_to-iobject')\n , toLength = require('./_to-length')\n , toIndex = require('./_to-index');\nmodule.exports = function(IS_INCLUDES){\n return function($this, el, fromIndex){\n var O = toIObject($this)\n , length = toLength(O.length)\n , index = toIndex(fromIndex, length)\n , value;\n // Array#includes uses SameValueZero equality algorithm\n if(IS_INCLUDES && el != el)while(length > index){\n value = O[index++];\n if(value != value)return true;\n // Array#toIndex ignores holes, Array#includes - not\n } else for(;length > index; index++)if(IS_INCLUDES || index in O){\n if(O[index] === el)return IS_INCLUDES || index || 0;\n } return !IS_INCLUDES && -1;\n };\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_array-includes.js\n// module id = 20\n// module chunks = 0","// 7.1.15 ToLength\nvar toInteger = require('./_to-integer')\n , min = Math.min;\nmodule.exports = function(it){\n return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_to-length.js\n// module id = 21\n// module chunks = 0","// 7.1.4 ToInteger\nvar ceil = Math.ceil\n , floor = Math.floor;\nmodule.exports = function(it){\n return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_to-integer.js\n// module id = 22\n// module chunks = 0","var toInteger = require('./_to-integer')\n , max = Math.max\n , min = Math.min;\nmodule.exports = function(index, length){\n index = toInteger(index);\n return index < 0 ? max(index + length, 0) : min(index, length);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_to-index.js\n// module id = 23\n// module chunks = 0","var shared = require('./_shared')('keys')\n , uid = require('./_uid');\nmodule.exports = function(key){\n return shared[key] || (shared[key] = uid(key));\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_shared-key.js\n// module id = 24\n// module chunks = 0","var global = require('./_global')\n , SHARED = '__core-js_shared__'\n , store = global[SHARED] || (global[SHARED] = {});\nmodule.exports = function(key){\n return store[key] || (store[key] = {});\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_shared.js\n// module id = 25\n// module chunks = 0","// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028\nvar global = module.exports = typeof window != 'undefined' && window.Math == Math\n ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')();\nif(typeof __g == 'number')__g = global; // eslint-disable-line no-undef\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_global.js\n// module id = 26\n// module chunks = 0","var id = 0\n , px = Math.random();\nmodule.exports = function(key){\n return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_uid.js\n// module id = 27\n// module chunks = 0","// IE 8- don't enum bug keys\nmodule.exports = (\n 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'\n).split(',');\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_enum-bug-keys.js\n// module id = 28\n// module chunks = 0","// most Object methods by ES6 should accept primitives\nvar $export = require('./_export')\n , core = require('./_core')\n , fails = require('./_fails');\nmodule.exports = function(KEY, exec){\n var fn = (core.Object || {})[KEY] || Object[KEY]\n , exp = {};\n exp[KEY] = exec(fn);\n $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_object-sap.js\n// module id = 29\n// module chunks = 0","var global = require('./_global')\n , core = require('./_core')\n , ctx = require('./_ctx')\n , hide = require('./_hide')\n , PROTOTYPE = 'prototype';\n\nvar $export = function(type, name, source){\n var IS_FORCED = type & $export.F\n , IS_GLOBAL = type & $export.G\n , IS_STATIC = type & $export.S\n , IS_PROTO = type & $export.P\n , IS_BIND = type & $export.B\n , IS_WRAP = type & $export.W\n , exports = IS_GLOBAL ? core : core[name] || (core[name] = {})\n , expProto = exports[PROTOTYPE]\n , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE]\n , key, own, out;\n if(IS_GLOBAL)source = name;\n for(key in source){\n // contains in native\n own = !IS_FORCED && target && target[key] !== undefined;\n if(own && key in exports)continue;\n // export native or passed\n out = own ? target[key] : source[key];\n // prevent global pollution for namespaces\n exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]\n // bind timers to global for call from export context\n : IS_BIND && own ? ctx(out, global)\n // wrap global constructors for prevent change them in library\n : IS_WRAP && target[key] == out ? (function(C){\n var F = function(a, b, c){\n if(this instanceof C){\n switch(arguments.length){\n case 0: return new C;\n case 1: return new C(a);\n case 2: return new C(a, b);\n } return new C(a, b, c);\n } return C.apply(this, arguments);\n };\n F[PROTOTYPE] = C[PROTOTYPE];\n return F;\n // make static versions for prototype methods\n })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;\n // export proto methods to core.%CONSTRUCTOR%.methods.%NAME%\n if(IS_PROTO){\n (exports.virtual || (exports.virtual = {}))[key] = out;\n // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME%\n if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out);\n }\n }\n};\n// type bitmap\n$export.F = 1; // forced\n$export.G = 2; // global\n$export.S = 4; // static\n$export.P = 8; // proto\n$export.B = 16; // bind\n$export.W = 32; // wrap\n$export.U = 64; // safe\n$export.R = 128; // real proto method for `library` \nmodule.exports = $export;\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_export.js\n// module id = 30\n// module chunks = 0","var core = module.exports = {version: '2.4.0'};\nif(typeof __e == 'number')__e = core; // eslint-disable-line no-undef\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_core.js\n// module id = 31\n// module chunks = 0","// optional / simple context binding\nvar aFunction = require('./_a-function');\nmodule.exports = function(fn, that, length){\n aFunction(fn);\n if(that === undefined)return fn;\n switch(length){\n case 1: return function(a){\n return fn.call(that, a);\n };\n case 2: return function(a, b){\n return fn.call(that, a, b);\n };\n case 3: return function(a, b, c){\n return fn.call(that, a, b, c);\n };\n }\n return function(/* ...args */){\n return fn.apply(that, arguments);\n };\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_ctx.js\n// module id = 32\n// module chunks = 0","module.exports = function(it){\n if(typeof it != 'function')throw TypeError(it + ' is not a function!');\n return it;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_a-function.js\n// module id = 33\n// module chunks = 0","var dP = require('./_object-dp')\n , createDesc = require('./_property-desc');\nmodule.exports = require('./_descriptors') ? function(object, key, value){\n return dP.f(object, key, createDesc(1, value));\n} : function(object, key, value){\n object[key] = value;\n return object;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_hide.js\n// module id = 34\n// module chunks = 0","var anObject = require('./_an-object')\n , IE8_DOM_DEFINE = require('./_ie8-dom-define')\n , toPrimitive = require('./_to-primitive')\n , dP = Object.defineProperty;\n\nexports.f = require('./_descriptors') ? Object.defineProperty : function defineProperty(O, P, Attributes){\n anObject(O);\n P = toPrimitive(P, true);\n anObject(Attributes);\n if(IE8_DOM_DEFINE)try {\n return dP(O, P, Attributes);\n } catch(e){ /* empty */ }\n if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!');\n if('value' in Attributes)O[P] = Attributes.value;\n return O;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_object-dp.js\n// module id = 35\n// module chunks = 0","var isObject = require('./_is-object');\nmodule.exports = function(it){\n if(!isObject(it))throw TypeError(it + ' is not an object!');\n return it;\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_an-object.js\n// module id = 36\n// module chunks = 0","module.exports = function(it){\n return typeof it === 'object' ? it !== null : typeof it === 'function';\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_is-object.js\n// module id = 37\n// module chunks = 0","module.exports = !require('./_descriptors') && !require('./_fails')(function(){\n return Object.defineProperty(require('./_dom-create')('div'), 'a', {get: function(){ return 7; }}).a != 7;\n});\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_ie8-dom-define.js\n// module id = 38\n// module chunks = 0","// Thank's IE8 for his funny defineProperty\nmodule.exports = !require('./_fails')(function(){\n return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7;\n});\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_descriptors.js\n// module id = 39\n// module chunks = 0","module.exports = function(exec){\n try {\n return !!exec();\n } catch(e){\n return true;\n }\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_fails.js\n// module id = 40\n// module chunks = 0","var isObject = require('./_is-object')\n , document = require('./_global').document\n // in old IE typeof document.createElement is 'object'\n , is = isObject(document) && isObject(document.createElement);\nmodule.exports = function(it){\n return is ? document.createElement(it) : {};\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_dom-create.js\n// module id = 41\n// module chunks = 0","// 7.1.1 ToPrimitive(input [, PreferredType])\nvar isObject = require('./_is-object');\n// instead of the ES6 spec version, we didn't implement @@toPrimitive case\n// and the second argument - flag - preferred type is a string\nmodule.exports = function(it, S){\n if(!isObject(it))return it;\n var fn, val;\n if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;\n if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val;\n if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val;\n throw TypeError(\"Can't convert object to primitive value\");\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_to-primitive.js\n// module id = 42\n// module chunks = 0","module.exports = function(bitmap, value){\n return {\n enumerable : !(bitmap & 1),\n configurable: !(bitmap & 2),\n writable : !(bitmap & 4),\n value : value\n };\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/modules/_property-desc.js\n// module id = 43\n// module chunks = 0","/**\n * JSON parse.\n *\n * @see Based on jQuery#parseJSON (MIT) and JSON2\n * @api private\n */\n\nconst rvalidchars = /^[\\],:{}\\s]*$/\nconst rvalidescape = /\\\\(?:[\"\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g\nconst rvalidtokens = /\"[^\"\\\\\\n\\r]*\"|true|false|null|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g\nconst rvalidbraces = /(?:^|:|,)(?:\\s*\\[)+/g\nconst rtrimLeft = /^\\s+/\nconst rtrimRight = /\\s+$/\n\nmodule.exports = function parsejson(data) {\n if ('string' != typeof data || !data) {\n return null\n }\n\n data = data.replace(rtrimLeft, '').replace(rtrimRight, '')\n\n // Attempt to parse using the native JSON parser first\n if (JSON.parse) {\n return JSON.parse(data)\n }\n\n if (rvalidchars.test(data.replace(rvalidescape, '@')\n .replace(rvalidtokens, ']')\n .replace(rvalidbraces, ''))) {\n return (new Function('return ' + data))()\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./parsejson.js","/**\n * Parses an URI\n *\n * @author Steven Levithan (MIT license)\n * @api private\n */\n\nvar re = /^(?:(?![^:@]+:[^:@\\/]*@)(http|https|ws|wss):\\/\\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\\/?#]*)(?::(\\d*))?)(((\\/(?:[^?#](?![^?#\\/]*\\.[^?#\\/.]+(?:[?#]|$)))*\\/?)?([^?#\\/]*))(?:\\?([^#]*))?(?:#(.*))?)/;\n\nvar parts = [\n 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'\n];\n\nmodule.exports = function parseuri(str) {\n var src = str,\n b = str.indexOf('['),\n e = str.indexOf(']');\n\n if (b != -1 && e != -1) {\n str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);\n }\n\n var m = re.exec(str || ''),\n uri = {},\n i = 14;\n\n while (i--) {\n uri[parts[i]] = m[i] || '';\n }\n\n if (b != -1 && e != -1) {\n uri.source = src;\n uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');\n uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');\n uri.ipv6uri = true;\n }\n\n return uri;\n};\n\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/parseuri/index.js\n// module id = 45\n// module chunks = 0","exports.types = [\n 'CONNECT',\n 'DISCONNECT',\n 'EVENT',\n 'ACK',\n 'ERROR',\n 'BINARY_EVENT',\n 'BINARY_ACK',\n]\n\nexport function encoder(obj, callback) {\n // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type)\n // TODO support binary packet\n const encoding = encodeAsString(obj)\n callback([encoding])\n}\n\nfunction encodeAsString(obj) {\n let str = ''\n let nsp = false\n\n str += obj.type\n // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {}\n // TODO support binary type\n\n if (obj.nsp && '/' != obj.nsp) {\n nsp = true\n str += obj.nsp\n }\n\n if (null != obj.id) {\n if (nsp) {\n str += ','\n nsp = false\n }\n str += obj.id\n }\n\n if (null != obj.data) {\n if (nsp) str += ','\n str += JSON.stringify(obj.data)\n }\n\n return str\n}\n\nexport function decoder(obj, callback) {\n let packet\n if ('string' == typeof obj) {\n packet = decodeString(obj)\n }\n callback(packet)\n}\n\nfunction decodeString(str) {\n const p = {}\n let i = 0\n // look up type\n p.type = Number(str.charAt(0))\n if (null == exports.types[p.type]) return error()\n\n // look up attachments if type binary\n\n // look up namespace (if any)\n if ('/' == str.charAt(i + 1)) {\n p.nsp = ''\n while (++i) {\n const c = str.charAt(i)\n if (',' == c) break\n p.nsp += c\n if (i == str.length) break\n }\n } else {\n p.nsp = '/'\n }\n\n // look up id\n const next = str.charAt(i + 1)\n if ('' !== next && Number(next) == next) {\n p.id = ''\n while (++i) {\n const c = str.charAt(i)\n if (null == c || Number(c) != c) {\n --i\n break\n }\n p.id += str.charAt(i)\n if (i == str.length) break\n }\n p.id = Number(p.id)\n }\n\n // look up json data\n if (str.charAt(++i)) {\n try {\n p.data = JSON.parse(str.substr(i))\n } catch (e) {\n return error()\n }\n }\n return p\n}\n\nfunction error(data) {\n return {\n type: exports.ERROR,\n data: 'parser error',\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./parser.js","module.exports = { \"default\": require(\"core-js/library/fn/json/stringify\"), __esModule: true };\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/babel-runtime/core-js/json/stringify.js\n// module id = 47\n// module chunks = 0","var core = require('../../modules/_core')\n , $JSON = core.JSON || (core.JSON = {stringify: JSON.stringify});\nmodule.exports = function stringify(it){ // eslint-disable-line no-unused-vars\n return $JSON.stringify.apply($JSON, arguments);\n};\n\n\n//////////////////\n// WEBPACK FOOTER\n// ../~/core-js/library/fn/json/stringify.js\n// module id = 48\n// module chunks = 0","import Emitter from 'component-emitter'\nimport on from './on.js'\nimport bind from 'component-bind'\n\nEmitter(Socket.prototype)\n\nconst parser = {\n CONNECT: 0,\n DISCONNECT: 1,\n EVENT: 2,\n ACK: 3,\n ERROR: 4,\n BINARY_EVENT: 5,\n BINARY_ACK: 6,\n}\n\nconst events = {\n connect: 1,\n connect_error: 1,\n connect_timeout: 1,\n connecting: 1,\n disconnect: 1,\n error: 1,\n reconnect: 1,\n reconnect_attempt: 1,\n reconnect_failed: 1,\n reconnect_error: 1,\n reconnecting: 1,\n ping: 1,\n pong: 1,\n}\n\nconst emit = Emitter.prototype.emit\n\nexport default Socket\n\nfunction Socket(io, nsp) {\n this.io = io\n this.nsp = nsp\n this.id = 0 // sid\n this.connected = false\n this.disconnected = true\n this.receiveBuffer = []\n this.sendBuffer = []\n if (this.io.autoConnect) this.open()\n}\n\nSocket.prototype.subEvents = function() {\n if (this.subs) return\n\n const io = this.io\n this.subs = [\n on(io, 'open', bind(this, 'onopen')),\n on(io, 'packet', bind(this, 'onpacket')),\n on(io, 'close', bind(this, 'onclose')),\n ]\n}\n\nSocket.prototype.open =\nSocket.prototype.connect = function() {\n if (this.connected) return this\n this.subEvents()\n this.io.open() // ensure open\n if ('open' == this.io.readyState) this.onopen()\n return this\n}\n\nSocket.prototype.onopen = function() {\n if ('/' != this.nsp) this.packet({ type: parser.CONNECT })\n}\n\nSocket.prototype.onclose = function(reason) {\n this.connected = false\n this.disconnected = true\n delete this.id\n this.emit('disconnect', reason)\n}\n\nSocket.prototype.onpacket = function(packet) {\n if (packet.nsp != this.nsp) return\n\n switch (packet.type) {\n case parser.CONNECT:\n this.onconnect()\n break\n case parser.EVENT:\n this.onevent(packet)\n break\n case parser.DISCONNECT:\n this.disconnect()\n break\n case parser.ERROR:\n this.emit('error', packet.data)\n break\n }\n}\n\nSocket.prototype.onconnect = function() {\n this.connected = true\n this.disconnected = false\n this.emit('connect')\n // this.emitBuffered()\n}\n\nSocket.prototype.onevent = function(packet) {\n const args = packet.data || []\n\n if (this.connected) {\n emit.apply(this, args)\n } else {\n this.receiveBuffer.push(args)\n }\n}\n\nSocket.prototype.close =\nSocket.prototype.disconnect = function() {\n if (this.connected) {\n this.packet({ type: parser.DISCONNECT })\n }\n\n this.destroy()\n\n if (this.connected) {\n this.onclose('io client disconnect')\n }\n return this\n}\n\nSocket.prototype.destroy = function() {\n if (this.subs) {\n for (let i = 0; i < this.subs.length; i++) {\n this.subs[i].destroy()\n }\n this.subs = null\n }\n this.io.destroy(this)\n}\n\nSocket.prototype.emit = function(...args) {\n if (events.hasOwnProperty(args[0])) {\n emit.apply(this, args)\n return this\n }\n\n const parserType = parser.EVENT\n // if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary\n const packet = { type: parserType, data: args, options: {} }\n\n if (this.connected) {\n this.packet(packet)\n } else {\n this.sendBuffer.push(packet)\n }\n return this\n}\n\nSocket.prototype.packet = function(packet) {\n packet.nsp = this.nsp\n this.io.packet(packet)\n}\n\n\n\n// WEBPACK FOOTER //\n// ./socket.js","import parseuri from 'parseuri'\n\nexport default uri => {\n const obj = parseuri(uri)\n\n // make sure we treat `localhost:80` and `localhost` equally\n if (!obj.port) {\n if (/^(http|ws)$/.test(obj.protocol)) {\n obj.port = '80'\n } else if (/^(http|ws)s$/.test(obj.protocol)) {\n obj.port = '443'\n }\n }\n\n obj.path = obj.path || '/'\n const ipv6 = obj.host.indexOf(':') !== -1\n const host = ipv6 ? `[${obj.host}]` : obj.host\n\n // define unique id\n obj.id = `${obj.protocol}://${host}:${obj.port}`\n\n return obj\n}\n\n\n\n// WEBPACK FOOTER //\n// ./url.js"],"sourceRoot":""} -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wxapp-socket-io", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "build/index.js", 6 | "scripts": { 7 | "build": "webpack --progress --colors --config webpack.config.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/fanweixiao/wxapp-socket-io.git" 12 | }, 13 | "author": "C.C. (https://github.com/fanweixiao)", 14 | "contributors": [ 15 | "C.C. (https://github.com/fanweixiao)", 16 | "Liuguili (https://github.com/gongzili456)" 17 | ], 18 | "keywords": [ 19 | "socket.io", 20 | "wxapp", 21 | "weapp", 22 | "wechat", 23 | "socket", 24 | "wesocket" 25 | ], 26 | "license": "MIT", 27 | "bugs": { 28 | "url": "https://github.com/fanweixiao/wxapp-socket-io/issues" 29 | }, 30 | "homepage": "https://github.com/fanweixiao/wxapp-socket-io#readme", 31 | "dependencies": { 32 | "backo2": "^1.0.2", 33 | "component-bind": "^1.0.0", 34 | "component-emitter": "^1.2.1", 35 | "indexof": "^0.0.1", 36 | "parsejson": "0.0.2", 37 | "parseuri": "0.0.4" 38 | }, 39 | "devDependencies": { 40 | "babel-cli": "^6.10.1", 41 | "babel-core": "^6.10.4", 42 | "babel-eslint": "^6.1.0", 43 | "babel-loader": "^6.2.10", 44 | "babel-plugin-add-module-exports": "^0.2.1", 45 | "babel-plugin-external-helpers": "^6.8.0", 46 | "babel-plugin-syntax-async-functions": "^6.8.0", 47 | "babel-plugin-transform-runtime": "^6.9.0", 48 | "babel-preset-es2015": "^6.16.0", 49 | "babel-preset-es2015-rollup": "^1.2.0", 50 | "babel-preset-eslatest-node6": "^1.0.1", 51 | "babel-register": "^6.9.0", 52 | "debug": "^2.2.0", 53 | "eslint": "^3.0.0", 54 | "eslint-config-airbnb": "^9.0.1", 55 | "eslint-config-standard": "^5.3.1", 56 | "eslint-plugin-babel": "^3.3.0", 57 | "eslint-plugin-import": "^1.10.2", 58 | "eslint-plugin-jsx-a11y": "^1.5.3", 59 | "eslint-plugin-promise": "^1.3.2", 60 | "eslint-plugin-react": "^5.2.2", 61 | "eslint-plugin-standard": "^1.3.2", 62 | "nodemon": "^1.9.2", 63 | "rollup": "^0.36.3", 64 | "rollup-plugin-babel": "^2.6.1", 65 | "rollup-plugin-commonjs": "^5.0.4", 66 | "rollup-plugin-eslint": "^3.0.0", 67 | "rollup-plugin-node-resolve": "^2.0.0", 68 | "rollup-plugin-replace": "^1.1.1", 69 | "rollup-plugin-uglify": "^1.0.1", 70 | "webpack": "^1.14.0" 71 | }, 72 | "engines": { 73 | "node": ">=6" 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/debug.js: -------------------------------------------------------------------------------- 1 | export default nsp => { 2 | return (...log) => { 3 | if (__wxConfig.debug) { 4 | console.log.call(null, nsp, ...log) 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/engine.js: -------------------------------------------------------------------------------- 1 | import Emitter from 'component-emitter' 2 | import on from './on' 3 | import parsejson from './parsejson' 4 | import bind from 'component-bind' 5 | import parseuri from 'parseuri' 6 | 7 | export default Engine 8 | 9 | const GlobalEmitter = Emitter({ hasEmitte: false }) 10 | 11 | Emitter(Engine.prototype) 12 | 13 | const packets = { 14 | open: 0, // non-ws 15 | close: 1, // non-ws 16 | ping: 2, 17 | pong: 3, 18 | message: 4, 19 | upgrade: 5, 20 | noop: 6, 21 | } 22 | 23 | const packetslist = Object.keys(packets) 24 | 25 | function Engine(uri, opts) { 26 | if (!(this instanceof Engine)) return new Engine(uri, opts) 27 | 28 | this.subs = [] 29 | uri = parseuri(uri) 30 | this.protocol = uri.protocol 31 | this.host = uri.host 32 | this.query = uri.query 33 | this.port = uri.port 34 | this.opts = this.opts || {} 35 | this.path = opts.path.replace(/\/$/, '') 36 | this.connected = false 37 | this.lastPing = null 38 | this.pingInterval = 20000 39 | // init bind with GlobalEmitter 40 | this.bindEvents() 41 | } 42 | 43 | Engine.prototype.connect = function() { 44 | if (!GlobalEmitter.hasEmitte) Engine.subEvents() 45 | const url = `${this.protocol}://${this.host}:${this.port}/${this.path}/?${this.query ? `${this.query}&` : ''}EIO=3&transport=websocket` 46 | 47 | wx.connectSocket({ url }) 48 | } 49 | 50 | Engine.prototype.onopen = function() { 51 | this.emit('open') 52 | } 53 | 54 | Engine.prototype.onclose = function(reason) { 55 | // clean all bind with GlobalEmitter 56 | this.destroy() 57 | this.emit('close', reason) 58 | } 59 | 60 | Engine.prototype.onerror = function(reason) { 61 | this.emit('error') 62 | // 如果 wx.connectSocket 还没回调 wx.onSocketOpen,而先调用 wx.closeSocket,那么就做不到关闭 WebSocket 的目的。 63 | wx.closeSocket() 64 | } 65 | 66 | Engine.prototype.onpacket = function(packet) { 67 | switch (packet.type) { 68 | case 'open': 69 | this.onHandshake(parsejson(packet.data)) 70 | break 71 | case 'pong': 72 | this.setPing() 73 | this.emit('pong') 74 | break 75 | case 'error': { 76 | const error = new Error('server error') 77 | error.code = packet.data 78 | this.onerror(error) 79 | break 80 | } 81 | case 'message': 82 | this.emit('data', packet.data) 83 | this.emit('message', packet.data) 84 | break 85 | } 86 | } 87 | 88 | Engine.prototype.onHandshake = function(data) { 89 | this.id = data.sid 90 | this.pingInterval = data.pingInterval 91 | this.pingTimeout = data.pingTimeout 92 | this.setPing() 93 | } 94 | 95 | Engine.prototype.setPing = function() { 96 | clearTimeout(this.pingIntervalTimer) 97 | this.pingIntervalTimer = setTimeout(() => { 98 | this.ping() 99 | }, this.pingInterval) 100 | } 101 | 102 | Engine.prototype.ping = function() { 103 | this.emit('ping') 104 | this._send(`${packets.ping}probe`) 105 | } 106 | 107 | Engine.prototype.write = 108 | Engine.prototype.send = function(packet) { 109 | this._send([packets.message, packet].join('')) 110 | } 111 | 112 | Engine.prototype._send = function(data) { 113 | wx.sendSocketMessage({ data }) 114 | } 115 | Engine.subEvents = function() { 116 | wx.onSocketOpen(() => { 117 | GlobalEmitter.emit('open') 118 | }) 119 | wx.onSocketClose(reason => { 120 | GlobalEmitter.emit('close', reason) 121 | }) 122 | wx.onSocketError(reason => { 123 | GlobalEmitter.emit('error', reason) 124 | }) 125 | wx.onSocketMessage(resp => { 126 | GlobalEmitter.emit('packet', decodePacket(resp.data)) 127 | }) 128 | GlobalEmitter.hasEmitte = true 129 | } 130 | 131 | Engine.prototype.bindEvents = function() { 132 | this.subs.push(on(GlobalEmitter, 'open', bind(this, 'onopen'))) 133 | this.subs.push(on(GlobalEmitter, 'close', bind(this, 'onclose'))) 134 | this.subs.push(on(GlobalEmitter, 'error', bind(this, 'onerror'))) 135 | this.subs.push(on(GlobalEmitter, 'packet', bind(this, 'onpacket'))) 136 | } 137 | 138 | Engine.prototype.destroy = function() { 139 | let sub 140 | while (sub = this.subs.shift()) { sub.destroy() } 141 | 142 | clearTimeout(this.pingIntervalTimer) 143 | this.readyState = 'closed' 144 | this.id = null 145 | this.writeBuffer = [] 146 | this.prevBufferLen = 0 147 | } 148 | 149 | function decodePacket(data) { 150 | const type = data.charAt(0) 151 | if (data.length > 1) { 152 | return { 153 | type: packetslist[type], 154 | data: data.substring(1), 155 | } 156 | } 157 | return { type: packetslist[type] } 158 | } 159 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import manager from './manager' 2 | import url from './url' 3 | 4 | const cache = {} 5 | 6 | export default function lookup(uri, opts) { 7 | if (!uri) { 8 | throw new Error('uri is required.') 9 | } 10 | 11 | opts = opts || {} 12 | 13 | const parsed = url(uri) 14 | 15 | const source = parsed.source 16 | const id = parsed.id 17 | const path = parsed.path 18 | const sameNamespace = cache[id] && path in cache[id].nsps 19 | 20 | const newConnection = opts.forceNew || opts['force new connection'] || 21 | false === opts.multiplex || sameNamespace 22 | 23 | // return new socket or from cache 24 | let io 25 | if (newConnection) { 26 | io = manager(source, opts) 27 | } else { 28 | if (!cache[id]) { 29 | cache[id] = manager(source, opts) 30 | } 31 | io = cache[id] 32 | } 33 | return io.socket(parsed.path) 34 | } 35 | -------------------------------------------------------------------------------- /src/manager.js: -------------------------------------------------------------------------------- 1 | import Emitter from 'component-emitter' 2 | import bind from 'component-bind' 3 | import Backoff from 'backo2' 4 | import indexOf from 'indexof' 5 | import on from './on' 6 | import Engine from './engine' 7 | import { encoder, decoder } from './parser' 8 | import Socket from './socket' 9 | 10 | const has = Object.prototype.hasOwnProperty 11 | 12 | Emitter(Manager.prototype) 13 | 14 | export default Manager 15 | 16 | function Manager(uri, opts) { 17 | if (!(this instanceof Manager)) return new Manager(uri, opts) 18 | 19 | opts.path = opts.path || 'socket.io' 20 | this.nsps = {} 21 | this.subs = [] 22 | this.opts = opts 23 | this.uri = uri 24 | this.readyState = 'closed' 25 | this.connected = false 26 | this.reconnection(opts.reconnection !== false) 27 | this.reconnectionAttempts(opts.reconnectionAttempts || Infinity) 28 | this.reconnectionDelay(opts.reconnectionDelay || 1000) 29 | this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000) 30 | this.randomizationFactor(opts.randomizationFactor || 0.5) 31 | this.backoff = new Backoff({ 32 | min: this.reconnectionDelay(), 33 | max: this.reconnectionDelayMax(), 34 | jitter: this.randomizationFactor(), 35 | }) 36 | this.timeout(null == opts.timeout ? 20000 : opts.timeout) 37 | this.encoder = encoder 38 | this.decoder = decoder 39 | this.connecting = [] 40 | this.autoConnect = opts.autoConnect !== false 41 | if (this.autoConnect) this.open() 42 | } 43 | 44 | Manager.prototype.open = 45 | Manager.prototype.connect = function(fn) { 46 | if (~this.readyState.indexOf('open')) return this 47 | 48 | this.engine = new Engine(this.uri, this.opts) 49 | 50 | this.readyState = 'opening' 51 | 52 | const socket = this.engine 53 | 54 | this.subs.push(on(socket, 'open', () => { 55 | this.onopen() 56 | fn && fn() 57 | })) 58 | 59 | this.subs.push(on(socket, 'error', data => { 60 | this.cleanup() 61 | this.readyState = 'closed' 62 | this.emitAll('connect_error', data) 63 | if (fn) { 64 | const error = new Error('Connect error') 65 | error.data = data 66 | fn(error) 67 | } else { 68 | this.maybeReconnectOnOpen() 69 | } 70 | })) 71 | 72 | socket.connect() 73 | return this 74 | } 75 | 76 | Manager.prototype.onopen = function() { 77 | this.cleanup() 78 | 79 | this.readyState = 'open' 80 | this.emit('open') 81 | 82 | const socket = this.engine 83 | this.subs.push(on(socket, 'data', bind(this, 'ondata'))) 84 | this.subs.push(on(socket, 'ping', bind(this, 'onping'))) 85 | this.subs.push(on(socket, 'pong', bind(this, 'onpong'))) 86 | this.subs.push(on(socket, 'error', bind(this, 'onerror'))) 87 | this.subs.push(on(socket, 'close', bind(this, 'onclose'))) 88 | // this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded'))) 89 | } 90 | 91 | Manager.prototype.onclose = function(reason) { 92 | this.cleanup() 93 | this.readyState = 'closed' 94 | this.emit('close', reason) 95 | if (this._reconnection && !this.skipReconnect) this.reconnect() 96 | } 97 | 98 | Manager.prototype.onerror = function(reason) { 99 | this.emitAll('error') 100 | } 101 | 102 | Manager.prototype.onping = function() { 103 | this.lastPing = new Date 104 | this.emitAll('ping') 105 | } 106 | 107 | Manager.prototype.onpong = function() { 108 | this.emitAll('pong', new Date - this.lastPing) 109 | } 110 | 111 | Manager.prototype.ondata = function(data) { 112 | this.decoder(data, decoding => { 113 | this.emit('packet', decoding) 114 | }) 115 | } 116 | 117 | Manager.prototype.packet = function(packet) { 118 | this.encoder(packet, encodedPackets => { 119 | for (let i = 0; i < encodedPackets.length; i++) { 120 | this.engine.write(encodedPackets[i], packet.options) 121 | } 122 | }) 123 | } 124 | 125 | Manager.prototype.socket = function(nsp) { 126 | let socket = this.nsps[nsp] 127 | if (!socket) { 128 | socket = new Socket(this, nsp) 129 | this.nsps[nsp] = socket 130 | } 131 | return socket 132 | } 133 | 134 | Manager.prototype.cleanup = function() { 135 | let sub 136 | while (sub = this.subs.shift()) sub.destroy() 137 | 138 | this.packetBuffer = [] 139 | this.lastPing = null 140 | } 141 | 142 | Manager.prototype.emitAll = function(...args) { 143 | this.emit.apply(this, args) 144 | for (const nsp in this.nsps) { 145 | if (has.call(this.nsps, nsp)) { 146 | this.nsps[nsp].emit.apply(this.nsps[nsp], args) 147 | } 148 | } 149 | } 150 | 151 | Manager.prototype.reconnect = function() { 152 | if (this.reconnecting || this.skipReconnect) return this 153 | 154 | if (this.backoff.attempts >= this._reconnectionAttempts) { 155 | this.backoff.reset() 156 | this.emitAll('reconnect_failed') 157 | this.reconnecting = false 158 | } else { 159 | const delay = this.backoff.duration() 160 | this.reconnecting = true 161 | const timer = setTimeout(() => { 162 | this.emitAll('reconnect_attempt', this.backoff.attempts) 163 | this.emitAll('reconnecting', this.backoff.attempts) 164 | 165 | if (this.skipReconnect) return 166 | 167 | this.open(err => { 168 | if (err) { 169 | this.reconnecting = false 170 | this.reconnect() 171 | this.emitAll('reconnect_error', err.data) 172 | } else { 173 | this.onreconnect() 174 | } 175 | }) 176 | }, delay) 177 | 178 | this.subs.push({ 179 | destroy: () => { 180 | clearTimeout(timer) 181 | }, 182 | }) 183 | } 184 | } 185 | 186 | Manager.prototype.onreconnect = function() { 187 | const attempt = this.backoff.attempts 188 | this.reconnecting = false 189 | this.backoff.reset() 190 | this.updateSocketIds() 191 | this.emitAll('reconnect', attempt) 192 | } 193 | 194 | /** 195 | * Update `socket.id` of all sockets 196 | * 197 | * @api private 198 | */ 199 | 200 | Manager.prototype.updateSocketIds = function() { 201 | for (const nsp in this.nsps) { 202 | if (has.call(this.nsps, nsp)) { 203 | this.nsps[nsp].id = this.engine.id 204 | } 205 | } 206 | } 207 | 208 | Manager.prototype.destroy = function(socket) { 209 | const index = indexOf(this.connecting, socket) 210 | if (~index) this.connecting.splice(index, 1) 211 | if (this.connecting.length) return 212 | 213 | this.close() 214 | } 215 | 216 | Manager.prototype.close = 217 | Manager.prototype.disconnect = function() { 218 | this.skipReconnect = true 219 | this.reconnecting = false 220 | if ('opening' == this.readyState) { 221 | // `onclose` will not fire because 222 | // an open event never happened 223 | this.cleanup() 224 | } 225 | this.readyState = 'closed' 226 | if (this.engine) this.engine.close() 227 | } 228 | 229 | /** 230 | * Sets the `reconnection` config. 231 | * 232 | * @param {Boolean} true/false if it should automatically reconnect 233 | * @return {Manager} self or value 234 | * @api public 235 | */ 236 | Manager.prototype.reconnection = function(v) { 237 | if (!arguments.length) return this._reconnection 238 | this._reconnection = !!v 239 | return this 240 | } 241 | 242 | /** 243 | * Sets the reconnection attempts config. 244 | * 245 | * @param {Number} max reconnection attempts before giving up 246 | * @return {Manager} self or value 247 | * @api public 248 | */ 249 | Manager.prototype.reconnectionAttempts = function(v) { 250 | if (!arguments.length) return this._reconnectionAttempts 251 | this._reconnectionAttempts = v 252 | return this 253 | } 254 | 255 | /** 256 | * Sets the delay between reconnections. 257 | * 258 | * @param {Number} delay 259 | * @return {Manager} self or value 260 | * @api public 261 | */ 262 | Manager.prototype.reconnectionDelay = function(v) { 263 | if (!arguments.length) return this._reconnectionDelay 264 | this._reconnectionDelay = v 265 | this.backoff && this.backoff.setMin(v) 266 | return this 267 | } 268 | 269 | Manager.prototype.randomizationFactor = function(v) { 270 | if (!arguments.length) return this._randomizationFactor 271 | this._randomizationFactor = v 272 | this.backoff && this.backoff.setJitter(v) 273 | return this 274 | } 275 | 276 | /** 277 | * Sets the maximum delay between reconnections. 278 | * 279 | * @param {Number} delay 280 | * @return {Manager} self or value 281 | * @api public 282 | */ 283 | Manager.prototype.reconnectionDelayMax = function(v) { 284 | if (!arguments.length) return this._reconnectionDelayMax 285 | this._reconnectionDelayMax = v 286 | this.backoff && this.backoff.setMax(v) 287 | return this 288 | } 289 | 290 | /** 291 | * Sets the connection timeout. `false` to disable 292 | * 293 | * @return {Manager} self or value 294 | * @api public 295 | */ 296 | Manager.prototype.timeout = function(v) { 297 | if (!arguments.length) return this._timeout 298 | this._timeout = v 299 | return this 300 | } 301 | 302 | /** 303 | * Starts trying to reconnect if reconnection is enabled and we have not 304 | * started reconnecting yet 305 | * 306 | * @api private 307 | */ 308 | Manager.prototype.maybeReconnectOnOpen = function() { 309 | // Only try to reconnect if it's the first time we're connecting 310 | if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) { 311 | // keeps reconnection from firing twice for the same reconnection loop 312 | this.reconnect() 313 | } 314 | } 315 | -------------------------------------------------------------------------------- /src/on.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Helper for subscriptions. 3 | * 4 | * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter` 5 | * @param {String} event name 6 | * @param {Function} callback 7 | * @api public 8 | */ 9 | 10 | export default (obj, ev, fn) => { 11 | obj.on(ev, fn) 12 | return { 13 | destroy: () => { 14 | obj.removeListener(ev, fn) 15 | }, 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/parsejson.js: -------------------------------------------------------------------------------- 1 | /** 2 | * JSON parse. 3 | * 4 | * @see Based on jQuery#parseJSON (MIT) and JSON2 5 | * @api private 6 | */ 7 | 8 | const rvalidchars = /^[\],:{}\s]*$/ 9 | const rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g 10 | const rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g 11 | const rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g 12 | const rtrimLeft = /^\s+/ 13 | const rtrimRight = /\s+$/ 14 | 15 | module.exports = function parsejson(data) { 16 | if ('string' != typeof data || !data) { 17 | return null 18 | } 19 | 20 | data = data.replace(rtrimLeft, '').replace(rtrimRight, '') 21 | 22 | // Attempt to parse using the native JSON parser first 23 | if (JSON.parse) { 24 | return JSON.parse(data) 25 | } 26 | 27 | if (rvalidchars.test(data.replace(rvalidescape, '@') 28 | .replace(rvalidtokens, ']') 29 | .replace(rvalidbraces, ''))) { 30 | return (new Function('return ' + data))() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/parser.js: -------------------------------------------------------------------------------- 1 | exports.types = [ 2 | 'CONNECT', 3 | 'DISCONNECT', 4 | 'EVENT', 5 | 'ACK', 6 | 'ERROR', 7 | 'BINARY_EVENT', 8 | 'BINARY_ACK', 9 | ] 10 | 11 | export function encoder(obj, callback) { 12 | // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) 13 | // TODO support binary packet 14 | const encoding = encodeAsString(obj) 15 | callback([encoding]) 16 | } 17 | 18 | function encodeAsString(obj) { 19 | let str = '' 20 | let nsp = false 21 | 22 | str += obj.type 23 | // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {} 24 | // TODO support binary type 25 | 26 | if (obj.nsp && '/' != obj.nsp) { 27 | nsp = true 28 | str += obj.nsp 29 | } 30 | 31 | if (null != obj.id) { 32 | if (nsp) { 33 | str += ',' 34 | nsp = false 35 | } 36 | str += obj.id 37 | } 38 | 39 | if (null != obj.data) { 40 | if (nsp) str += ',' 41 | str += JSON.stringify(obj.data) 42 | } 43 | 44 | return str 45 | } 46 | 47 | export function decoder(obj, callback) { 48 | let packet 49 | if ('string' == typeof obj) { 50 | packet = decodeString(obj) 51 | } 52 | callback(packet) 53 | } 54 | 55 | function decodeString(str) { 56 | const p = {} 57 | let i = 0 58 | // look up type 59 | p.type = Number(str.charAt(0)) 60 | if (null == exports.types[p.type]) return error() 61 | 62 | // look up attachments if type binary 63 | 64 | // look up namespace (if any) 65 | if ('/' == str.charAt(i + 1)) { 66 | p.nsp = '' 67 | while (++i) { 68 | const c = str.charAt(i) 69 | if (',' == c) break 70 | p.nsp += c 71 | if (i == str.length) break 72 | } 73 | } else { 74 | p.nsp = '/' 75 | } 76 | 77 | // look up id 78 | const next = str.charAt(i + 1) 79 | if ('' !== next && Number(next) == next) { 80 | p.id = '' 81 | while (++i) { 82 | const c = str.charAt(i) 83 | if (null == c || Number(c) != c) { 84 | --i 85 | break 86 | } 87 | p.id += str.charAt(i) 88 | if (i == str.length) break 89 | } 90 | p.id = Number(p.id) 91 | } 92 | 93 | // look up json data 94 | if (str.charAt(++i)) { 95 | try { 96 | p.data = JSON.parse(str.substr(i)) 97 | } catch (e) { 98 | return error() 99 | } 100 | } 101 | return p 102 | } 103 | 104 | function error(data) { 105 | return { 106 | type: exports.ERROR, 107 | data: 'parser error', 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/socket.js: -------------------------------------------------------------------------------- 1 | import Emitter from 'component-emitter' 2 | import on from './on.js' 3 | import bind from 'component-bind' 4 | 5 | Emitter(Socket.prototype) 6 | 7 | const parser = { 8 | CONNECT: 0, 9 | DISCONNECT: 1, 10 | EVENT: 2, 11 | ACK: 3, 12 | ERROR: 4, 13 | BINARY_EVENT: 5, 14 | BINARY_ACK: 6, 15 | } 16 | 17 | const events = { 18 | connect: 1, 19 | connect_error: 1, 20 | connect_timeout: 1, 21 | connecting: 1, 22 | disconnect: 1, 23 | error: 1, 24 | reconnect: 1, 25 | reconnect_attempt: 1, 26 | reconnect_failed: 1, 27 | reconnect_error: 1, 28 | reconnecting: 1, 29 | ping: 1, 30 | pong: 1, 31 | } 32 | 33 | const emit = Emitter.prototype.emit 34 | 35 | export default Socket 36 | 37 | function Socket(io, nsp) { 38 | this.io = io 39 | this.nsp = nsp 40 | this.id = 0 // sid 41 | this.connected = false 42 | this.disconnected = true 43 | this.receiveBuffer = [] 44 | this.sendBuffer = [] 45 | if (this.io.autoConnect) this.open() 46 | } 47 | 48 | Socket.prototype.subEvents = function() { 49 | if (this.subs) return 50 | 51 | const io = this.io 52 | this.subs = [ 53 | on(io, 'open', bind(this, 'onopen')), 54 | on(io, 'packet', bind(this, 'onpacket')), 55 | on(io, 'close', bind(this, 'onclose')), 56 | ] 57 | } 58 | 59 | Socket.prototype.open = 60 | Socket.prototype.connect = function() { 61 | if (this.connected) return this 62 | this.subEvents() 63 | this.io.open() // ensure open 64 | if ('open' == this.io.readyState) this.onopen() 65 | return this 66 | } 67 | 68 | Socket.prototype.onopen = function() { 69 | if ('/' != this.nsp) this.packet({ type: parser.CONNECT }) 70 | } 71 | 72 | Socket.prototype.onclose = function(reason) { 73 | this.connected = false 74 | this.disconnected = true 75 | delete this.id 76 | this.emit('disconnect', reason) 77 | } 78 | 79 | Socket.prototype.onpacket = function(packet) { 80 | if (packet.nsp != this.nsp) return 81 | 82 | switch (packet.type) { 83 | case parser.CONNECT: 84 | this.onconnect() 85 | break 86 | case parser.EVENT: 87 | this.onevent(packet) 88 | break 89 | case parser.DISCONNECT: 90 | this.disconnect() 91 | break 92 | case parser.ERROR: 93 | this.emit('error', packet.data) 94 | break 95 | } 96 | } 97 | 98 | Socket.prototype.onconnect = function() { 99 | this.connected = true 100 | this.disconnected = false 101 | this.emit('connect') 102 | // this.emitBuffered() 103 | } 104 | 105 | Socket.prototype.onevent = function(packet) { 106 | const args = packet.data || [] 107 | 108 | if (this.connected) { 109 | emit.apply(this, args) 110 | } else { 111 | this.receiveBuffer.push(args) 112 | } 113 | } 114 | 115 | Socket.prototype.close = 116 | Socket.prototype.disconnect = function() { 117 | if (this.connected) { 118 | this.packet({ type: parser.DISCONNECT }) 119 | } 120 | 121 | this.destroy() 122 | 123 | if (this.connected) { 124 | this.onclose('io client disconnect') 125 | } 126 | return this 127 | } 128 | 129 | Socket.prototype.destroy = function() { 130 | if (this.subs) { 131 | for (let i = 0; i < this.subs.length; i++) { 132 | this.subs[i].destroy() 133 | } 134 | this.subs = null 135 | } 136 | this.io.destroy(this) 137 | } 138 | 139 | Socket.prototype.emit = function(...args) { 140 | if (events.hasOwnProperty(args[0])) { 141 | emit.apply(this, args) 142 | return this 143 | } 144 | 145 | const parserType = parser.EVENT 146 | // if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary 147 | const packet = { type: parserType, data: args, options: {} } 148 | 149 | if (this.connected) { 150 | this.packet(packet) 151 | } else { 152 | this.sendBuffer.push(packet) 153 | } 154 | return this 155 | } 156 | 157 | Socket.prototype.packet = function(packet) { 158 | packet.nsp = this.nsp 159 | this.io.packet(packet) 160 | } 161 | -------------------------------------------------------------------------------- /src/url.js: -------------------------------------------------------------------------------- 1 | import parseuri from 'parseuri' 2 | 3 | export default uri => { 4 | const obj = parseuri(uri) 5 | 6 | // make sure we treat `localhost:80` and `localhost` equally 7 | if (!obj.port) { 8 | if (/^(http|ws)$/.test(obj.protocol)) { 9 | obj.port = '80' 10 | } else if (/^(http|ws)s$/.test(obj.protocol)) { 11 | obj.port = '443' 12 | } 13 | } 14 | 15 | obj.path = obj.path || '/' 16 | const ipv6 = obj.host.indexOf(':') !== -1 17 | const host = ipv6 ? `[${obj.host}]` : obj.host 18 | 19 | // define unique id 20 | obj.id = `${obj.protocol}://${host}:${obj.port}` 21 | 22 | return obj 23 | } 24 | -------------------------------------------------------------------------------- /weapp_demo/app.js: -------------------------------------------------------------------------------- 1 | import io from './wxsocket.io/index' 2 | 3 | console.log('io ---> ' ,io) 4 | 5 | // app.js 6 | App({ 7 | onLaunch: function() { 8 | // create a new socket object 9 | const socket = io("ws://chat.socket.io") 10 | this.globalData.socket = socket 11 | }, 12 | 13 | globalData:{ 14 | userInfo: null, 15 | }, 16 | }) 17 | -------------------------------------------------------------------------------- /weapp_demo/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "pages":[ 3 | "pages/index/index", 4 | "pages/room/index" 5 | ], 6 | "window":{ 7 | "backgroundTextStyle":"light", 8 | "navigationBarBackgroundColor": "#fff", 9 | "navigationBarTitleText": "WeChat", 10 | "navigationBarTextStyle":"black" 11 | }, 12 | "debug": true 13 | } 14 | -------------------------------------------------------------------------------- /weapp_demo/app.wxss: -------------------------------------------------------------------------------- 1 | /**app.wxss**/ 2 | .container { 3 | position: absolute; 4 | left: 0px; 5 | right: 0px; 6 | top: 0px; 7 | bottom: 0px; 8 | height: 100%; 9 | display: flex; 10 | flex-direction: column; 11 | align-items: center; 12 | justify-content: space-between; 13 | padding: 200px 20px; 14 | box-sizing: border-box; 15 | } 16 | -------------------------------------------------------------------------------- /weapp_demo/pages/index/index.js: -------------------------------------------------------------------------------- 1 | // index.js 2 | // 获取应用实例 3 | const app = getApp() 4 | Page({ 5 | data: { 6 | nickname: '', 7 | }, 8 | 9 | // 事件处理函数 10 | inputNameEvent: function(event) { 11 | this.setData({ 12 | nickname: event.detail.value, 13 | }) 14 | }, 15 | 16 | enterRoom: function(event) { 17 | console.log('nickname - > ', this.data.nickname) 18 | if (!this.data.nickname) { 19 | return 20 | } 21 | app.globalData.nickname = this.data.nickname 22 | 23 | app.globalData.socket.emit('add user', this.data.nickname) 24 | }, 25 | 26 | onLoad: function() { 27 | const that = this 28 | this.onSocketEvent() 29 | }, 30 | 31 | onSocketEvent: function() { 32 | const socket = app.globalData.socket 33 | 34 | socket.on('login', function(msg) { 35 | wx.showToast({ 36 | title: '登录成功', 37 | icon: 'success', 38 | duration: 1000 39 | }) 40 | 41 | wx.navigateTo({ 42 | url: '../room/index', 43 | }) 44 | }) 45 | } 46 | }) 47 | -------------------------------------------------------------------------------- /weapp_demo/pages/index/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | What's your nickname? 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /weapp_demo/pages/index/index.wxss: -------------------------------------------------------------------------------- 1 | /**index.wxss**/ 2 | .greeting { 3 | display: flex; 4 | flex-direction: column; 5 | align-items: center; 6 | } 7 | 8 | .nick-label { 9 | width: 100%; 10 | height: 128rpx; 11 | margin: auto; 12 | border-radius: 50%; 13 | } 14 | 15 | .nickname { 16 | width: 300px; 17 | color: #aaa; 18 | border-bottom: 1rpx solid #3e3e3e; 19 | text-align: center; 20 | outline: none; 21 | } 22 | 23 | .type-btn { 24 | margin-top: 30rpx; 25 | width: 100%; 26 | } -------------------------------------------------------------------------------- /weapp_demo/pages/room/index.js: -------------------------------------------------------------------------------- 1 | // index.js 2 | // 获取应用实例 3 | const app = getApp() 4 | Page({ 5 | data: { 6 | scrollTop: 100, 7 | messages: '', 8 | currentMsg: '' 9 | }, 10 | 11 | typeMessageEvent: function(e) { 12 | this.setData({ 13 | currentMsg: e.detail.value 14 | }) 15 | }, 16 | 17 | sendMsg: function(e) { 18 | const currentMsg = this.data.currentMsg 19 | 20 | if (!currentMsg) { 21 | return 22 | } 23 | 24 | this.setData({ 25 | messages: this.data.messages + '\n' + app.globalData.nickname + ': ' + currentMsg 26 | }) 27 | 28 | this.setData({ 29 | currentMsg: '' 30 | }) 31 | 32 | app.globalData.socket.emit('new message', currentMsg) 33 | }, 34 | 35 | onLoad: function() { 36 | const that = this 37 | 38 | this.onSocketEvent() 39 | }, 40 | 41 | onSocketEvent: function() { 42 | const socket = app.globalData.socket 43 | const self = this 44 | socket.on('new message', function(msg) { 45 | self.setData({ 46 | messages: self.data.messages + '\n' + msg.username + ': ' + msg.message 47 | }) 48 | }) 49 | 50 | socket.on('user joined', function(msg) { 51 | wx.showToast({ 52 | title: msg.username + ' 加入了房间', 53 | icon: 'success', 54 | duration: 1000 55 | }) 56 | }) 57 | 58 | socket.on('user left', function(msg) { 59 | wx.showToast({ 60 | title: msg.username + ' 离开了房间', 61 | icon: 'loading', 62 | duration: 1000 63 | }) 64 | }) 65 | } 66 | }) 67 | -------------------------------------------------------------------------------- /weapp_demo/pages/room/index.wxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{messages}} 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /weapp_demo/pages/room/index.wxss: -------------------------------------------------------------------------------- 1 | .message-list { 2 | position: absolute; 3 | top: 0px; 4 | bottom: 50px; 5 | left: 0px; 6 | right: 0px; 7 | width: 100%; 8 | padding: 20px; 9 | } 10 | 11 | .message-list .scroll { 12 | height: 100%; 13 | } 14 | 15 | .input-view { 16 | position: absolute; 17 | bottom: 0px; 18 | left: 0px; 19 | right: 0px; 20 | max-height: 50px; 21 | } 22 | 23 | .input-view input { 24 | display: inline-block; 25 | border-bottom: 1px solid #3e3e3e; 26 | width: 80%; 27 | padding-left: 20px; 28 | } 29 | 30 | .input-view button { 31 | position: fixed; 32 | bottom: 0px; 33 | right: 0px; 34 | border-radius: 0px; 35 | } 36 | 37 | .scroll-view-item { 38 | margin-top: 5px; 39 | border: 1px solid #3e3e3e; 40 | } 41 | 42 | .receiver { 43 | 44 | } 45 | 46 | .scroll-view-item .content { 47 | max-width: 300px; 48 | word-wrap: break-word; 49 | word-break: normal; 50 | line-height: 1.4; 51 | } 52 | 53 | .sender .content { 54 | float: right 55 | } -------------------------------------------------------------------------------- /weapp_demo/utils/util.js: -------------------------------------------------------------------------------- 1 | function formatTime(date) { 2 | var year = date.getFullYear() 3 | var month = date.getMonth() + 1 4 | var day = date.getDate() 5 | 6 | var hour = date.getHours() 7 | var minute = date.getMinutes() 8 | var second = date.getSeconds() 9 | 10 | 11 | return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') 12 | } 13 | 14 | function formatNumber(n) { 15 | n = n.toString() 16 | return n[1] ? n : '0' + n 17 | } 18 | 19 | module.exports = { 20 | formatTime: formatTime 21 | } 22 | -------------------------------------------------------------------------------- /weapp_demo/wxsocket.io/index.js: -------------------------------------------------------------------------------- 1 | (function webpackUniversalModuleDefinition(root, factory) { 2 | if(typeof exports === 'object' && typeof module === 'object') 3 | module.exports = factory(); 4 | else if(typeof define === 'function' && define.amd) 5 | define([], factory); 6 | else { 7 | var a = factory(); 8 | for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; 9 | } 10 | })(this, function() { 11 | return /******/ (function(modules) { // webpackBootstrap 12 | /******/ // The module cache 13 | /******/ var installedModules = {}; 14 | /******/ 15 | /******/ // The require function 16 | /******/ function __webpack_require__(moduleId) { 17 | /******/ 18 | /******/ // Check if module is in cache 19 | /******/ if(installedModules[moduleId]) 20 | /******/ return installedModules[moduleId].exports; 21 | /******/ 22 | /******/ // Create a new module (and put it into the cache) 23 | /******/ var module = installedModules[moduleId] = { 24 | /******/ exports: {}, 25 | /******/ id: moduleId, 26 | /******/ loaded: false 27 | /******/ }; 28 | /******/ 29 | /******/ // Execute the module function 30 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 31 | /******/ 32 | /******/ // Flag the module as loaded 33 | /******/ module.loaded = true; 34 | /******/ 35 | /******/ // Return the exports of the module 36 | /******/ return module.exports; 37 | /******/ } 38 | /******/ 39 | /******/ 40 | /******/ // expose the modules object (__webpack_modules__) 41 | /******/ __webpack_require__.m = modules; 42 | /******/ 43 | /******/ // expose the module cache 44 | /******/ __webpack_require__.c = installedModules; 45 | /******/ 46 | /******/ // __webpack_public_path__ 47 | /******/ __webpack_require__.p = ""; 48 | /******/ 49 | /******/ // Load entry module and return exports 50 | /******/ return __webpack_require__(0); 51 | /******/ }) 52 | /************************************************************************/ 53 | /******/ ([ 54 | /* 0 */ 55 | /***/ function(module, exports, __webpack_require__) { 56 | 57 | module.exports = __webpack_require__(1); 58 | 59 | 60 | /***/ }, 61 | /* 1 */ 62 | /***/ function(module, exports, __webpack_require__) { 63 | 64 | 'use strict'; 65 | 66 | Object.defineProperty(exports, "__esModule", { 67 | value: true 68 | }); 69 | exports.default = lookup; 70 | 71 | var _manager = __webpack_require__(2); 72 | 73 | var _manager2 = _interopRequireDefault(_manager); 74 | 75 | var _url = __webpack_require__(50); 76 | 77 | var _url2 = _interopRequireDefault(_url); 78 | 79 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 80 | 81 | var cache = {}; 82 | 83 | function lookup(uri, opts) { 84 | if (!uri) { 85 | throw new Error('uri is required.'); 86 | } 87 | 88 | opts = opts || {}; 89 | 90 | var parsed = (0, _url2.default)(uri); 91 | 92 | var source = parsed.source; 93 | var id = parsed.id; 94 | var path = parsed.path; 95 | var sameNamespace = cache[id] && path in cache[id].nsps; 96 | 97 | var newConnection = opts.forceNew || opts['force new connection'] || false === opts.multiplex || sameNamespace; 98 | 99 | // return new socket or from cache 100 | var io = void 0; 101 | if (newConnection) { 102 | io = (0, _manager2.default)(source, opts); 103 | } else { 104 | if (!cache[id]) { 105 | cache[id] = (0, _manager2.default)(source, opts); 106 | } 107 | io = cache[id]; 108 | } 109 | return io.socket(parsed.path); 110 | } 111 | 112 | exports.connect = lookup; 113 | 114 | /***/ }, 115 | /* 2 */ 116 | /***/ function(module, exports, __webpack_require__) { 117 | 118 | 'use strict'; 119 | 120 | Object.defineProperty(exports, "__esModule", { 121 | value: true 122 | }); 123 | 124 | var _componentEmitter = __webpack_require__(3); 125 | 126 | var _componentEmitter2 = _interopRequireDefault(_componentEmitter); 127 | 128 | var _componentBind = __webpack_require__(4); 129 | 130 | var _componentBind2 = _interopRequireDefault(_componentBind); 131 | 132 | var _backo = __webpack_require__(5); 133 | 134 | var _backo2 = _interopRequireDefault(_backo); 135 | 136 | var _indexof = __webpack_require__(6); 137 | 138 | var _indexof2 = _interopRequireDefault(_indexof); 139 | 140 | var _on = __webpack_require__(7); 141 | 142 | var _on2 = _interopRequireDefault(_on); 143 | 144 | var _engine = __webpack_require__(8); 145 | 146 | var _engine2 = _interopRequireDefault(_engine); 147 | 148 | var _parser = __webpack_require__(46); 149 | 150 | var _socket = __webpack_require__(49); 151 | 152 | var _socket2 = _interopRequireDefault(_socket); 153 | 154 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 155 | 156 | var has = Object.prototype.hasOwnProperty; 157 | 158 | (0, _componentEmitter2.default)(Manager.prototype); 159 | 160 | exports.default = Manager; 161 | 162 | 163 | function Manager(uri, opts) { 164 | if (!(this instanceof Manager)) return new Manager(uri, opts); 165 | 166 | opts.path = opts.path || 'socket.io'; 167 | this.nsps = {}; 168 | this.subs = []; 169 | this.opts = opts; 170 | this.uri = uri; 171 | this.readyState = 'closed'; 172 | this.connected = false; 173 | this.reconnection(opts.reconnection !== false); 174 | this.reconnectionAttempts(opts.reconnectionAttempts || Infinity); 175 | this.reconnectionDelay(opts.reconnectionDelay || 1000); 176 | this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000); 177 | this.randomizationFactor(opts.randomizationFactor || 0.5); 178 | this.backoff = new _backo2.default({ 179 | min: this.reconnectionDelay(), 180 | max: this.reconnectionDelayMax(), 181 | jitter: this.randomizationFactor() 182 | }); 183 | this.timeout(null == opts.timeout ? 20000 : opts.timeout); 184 | this.encoder = _parser.encoder; 185 | this.decoder = _parser.decoder; 186 | this.connecting = []; 187 | this.autoConnect = opts.autoConnect !== false; 188 | if (this.autoConnect) this.open(); 189 | } 190 | 191 | Manager.prototype.open = Manager.prototype.connect = function (fn) { 192 | var _this = this; 193 | 194 | if (~this.readyState.indexOf('open')) return this; 195 | 196 | this.engine = new _engine2.default(this.uri, this.opts); 197 | 198 | this.readyState = 'opening'; 199 | 200 | var socket = this.engine; 201 | 202 | this.subs.push((0, _on2.default)(socket, 'open', function () { 203 | _this.onopen(); 204 | fn && fn(); 205 | })); 206 | 207 | this.subs.push((0, _on2.default)(socket, 'error', function (data) { 208 | _this.cleanup(); 209 | _this.readyState = 'closed'; 210 | _this.emitAll('connect_error', data); 211 | if (fn) { 212 | var error = new Error('Connect error'); 213 | error.data = data; 214 | fn(error); 215 | } else { 216 | _this.maybeReconnectOnOpen(); 217 | } 218 | })); 219 | 220 | socket.connect(); 221 | return this; 222 | }; 223 | 224 | Manager.prototype.onopen = function () { 225 | this.cleanup(); 226 | 227 | this.readyState = 'open'; 228 | this.emit('open'); 229 | 230 | var socket = this.engine; 231 | this.subs.push((0, _on2.default)(socket, 'data', (0, _componentBind2.default)(this, 'ondata'))); 232 | this.subs.push((0, _on2.default)(socket, 'ping', (0, _componentBind2.default)(this, 'onping'))); 233 | this.subs.push((0, _on2.default)(socket, 'pong', (0, _componentBind2.default)(this, 'onpong'))); 234 | this.subs.push((0, _on2.default)(socket, 'error', (0, _componentBind2.default)(this, 'onerror'))); 235 | this.subs.push((0, _on2.default)(socket, 'close', (0, _componentBind2.default)(this, 'onclose'))); 236 | // this.subs.push(on(this.decoder, 'decoded', bind(this, 'ondecoded'))) 237 | }; 238 | 239 | Manager.prototype.onclose = function (reason) { 240 | this.cleanup(); 241 | this.readyState = 'closed'; 242 | this.emit('close', reason); 243 | if (this._reconnection && !this.skipReconnect) this.reconnect(); 244 | }; 245 | 246 | Manager.prototype.onerror = function (reason) { 247 | this.emitAll('error'); 248 | }; 249 | 250 | Manager.prototype.onping = function () { 251 | this.lastPing = new Date(); 252 | this.emitAll('ping'); 253 | }; 254 | 255 | Manager.prototype.onpong = function () { 256 | this.emitAll('pong', new Date() - this.lastPing); 257 | }; 258 | 259 | Manager.prototype.ondata = function (data) { 260 | var _this2 = this; 261 | 262 | this.decoder(data, function (decoding) { 263 | _this2.emit('packet', decoding); 264 | }); 265 | }; 266 | 267 | Manager.prototype.packet = function (packet) { 268 | var _this3 = this; 269 | 270 | this.encoder(packet, function (encodedPackets) { 271 | for (var i = 0; i < encodedPackets.length; i++) { 272 | _this3.engine.write(encodedPackets[i], packet.options); 273 | } 274 | }); 275 | }; 276 | 277 | Manager.prototype.socket = function (nsp) { 278 | var socket = this.nsps[nsp]; 279 | if (!socket) { 280 | socket = new _socket2.default(this, nsp); 281 | this.nsps[nsp] = socket; 282 | } 283 | return socket; 284 | }; 285 | 286 | Manager.prototype.cleanup = function () { 287 | var sub = void 0; 288 | while (sub = this.subs.shift()) { 289 | sub.destroy(); 290 | }this.packetBuffer = []; 291 | this.lastPing = null; 292 | }; 293 | 294 | Manager.prototype.emitAll = function () { 295 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 296 | args[_key] = arguments[_key]; 297 | } 298 | 299 | this.emit.apply(this, args); 300 | for (var nsp in this.nsps) { 301 | if (has.call(this.nsps, nsp)) { 302 | this.nsps[nsp].emit.apply(this.nsps[nsp], args); 303 | } 304 | } 305 | }; 306 | 307 | Manager.prototype.reconnect = function () { 308 | var _this4 = this; 309 | 310 | if (this.reconnecting || this.skipReconnect) return this; 311 | 312 | if (this.backoff.attempts >= this._reconnectionAttempts) { 313 | this.backoff.reset(); 314 | this.emitAll('reconnect_failed'); 315 | this.reconnecting = false; 316 | } else { 317 | (function () { 318 | var delay = _this4.backoff.duration(); 319 | _this4.reconnecting = true; 320 | var timer = setTimeout(function () { 321 | _this4.emitAll('reconnect_attempt', _this4.backoff.attempts); 322 | _this4.emitAll('reconnecting', _this4.backoff.attempts); 323 | 324 | if (_this4.skipReconnect) return; 325 | 326 | _this4.open(function (err) { 327 | if (err) { 328 | _this4.reconnecting = false; 329 | _this4.reconnect(); 330 | _this4.emitAll('reconnect_error', err.data); 331 | } else { 332 | _this4.onreconnect(); 333 | } 334 | }); 335 | }, delay); 336 | 337 | _this4.subs.push({ 338 | destroy: function destroy() { 339 | clearTimeout(timer); 340 | } 341 | }); 342 | })(); 343 | } 344 | }; 345 | 346 | Manager.prototype.onreconnect = function () { 347 | var attempt = this.backoff.attempts; 348 | this.reconnecting = false; 349 | this.backoff.reset(); 350 | this.updateSocketIds(); 351 | this.emitAll('reconnect', attempt); 352 | }; 353 | 354 | /** 355 | * Update `socket.id` of all sockets 356 | * 357 | * @api private 358 | */ 359 | 360 | Manager.prototype.updateSocketIds = function () { 361 | for (var nsp in this.nsps) { 362 | if (has.call(this.nsps, nsp)) { 363 | this.nsps[nsp].id = this.engine.id; 364 | } 365 | } 366 | }; 367 | 368 | Manager.prototype.destroy = function (socket) { 369 | var index = (0, _indexof2.default)(this.connecting, socket); 370 | if (~index) this.connecting.splice(index, 1); 371 | if (this.connecting.length) return; 372 | 373 | this.close(); 374 | }; 375 | 376 | Manager.prototype.close = Manager.prototype.disconnect = function () { 377 | this.skipReconnect = true; 378 | this.reconnecting = false; 379 | if ('opening' == this.readyState) { 380 | // `onclose` will not fire because 381 | // an open event never happened 382 | this.cleanup(); 383 | } 384 | this.readyState = 'closed'; 385 | if (this.engine) this.engine.close(); 386 | }; 387 | 388 | /** 389 | * Sets the `reconnection` config. 390 | * 391 | * @param {Boolean} true/false if it should automatically reconnect 392 | * @return {Manager} self or value 393 | * @api public 394 | */ 395 | Manager.prototype.reconnection = function (v) { 396 | if (!arguments.length) return this._reconnection; 397 | this._reconnection = !!v; 398 | return this; 399 | }; 400 | 401 | /** 402 | * Sets the reconnection attempts config. 403 | * 404 | * @param {Number} max reconnection attempts before giving up 405 | * @return {Manager} self or value 406 | * @api public 407 | */ 408 | Manager.prototype.reconnectionAttempts = function (v) { 409 | if (!arguments.length) return this._reconnectionAttempts; 410 | this._reconnectionAttempts = v; 411 | return this; 412 | }; 413 | 414 | /** 415 | * Sets the delay between reconnections. 416 | * 417 | * @param {Number} delay 418 | * @return {Manager} self or value 419 | * @api public 420 | */ 421 | Manager.prototype.reconnectionDelay = function (v) { 422 | if (!arguments.length) return this._reconnectionDelay; 423 | this._reconnectionDelay = v; 424 | this.backoff && this.backoff.setMin(v); 425 | return this; 426 | }; 427 | 428 | Manager.prototype.randomizationFactor = function (v) { 429 | if (!arguments.length) return this._randomizationFactor; 430 | this._randomizationFactor = v; 431 | this.backoff && this.backoff.setJitter(v); 432 | return this; 433 | }; 434 | 435 | /** 436 | * Sets the maximum delay between reconnections. 437 | * 438 | * @param {Number} delay 439 | * @return {Manager} self or value 440 | * @api public 441 | */ 442 | Manager.prototype.reconnectionDelayMax = function (v) { 443 | if (!arguments.length) return this._reconnectionDelayMax; 444 | this._reconnectionDelayMax = v; 445 | this.backoff && this.backoff.setMax(v); 446 | return this; 447 | }; 448 | 449 | /** 450 | * Sets the connection timeout. `false` to disable 451 | * 452 | * @return {Manager} self or value 453 | * @api public 454 | */ 455 | Manager.prototype.timeout = function (v) { 456 | if (!arguments.length) return this._timeout; 457 | this._timeout = v; 458 | return this; 459 | }; 460 | 461 | /** 462 | * Starts trying to reconnect if reconnection is enabled and we have not 463 | * started reconnecting yet 464 | * 465 | * @api private 466 | */ 467 | Manager.prototype.maybeReconnectOnOpen = function () { 468 | // Only try to reconnect if it's the first time we're connecting 469 | if (!this.reconnecting && this._reconnection && this.backoff.attempts === 0) { 470 | // keeps reconnection from firing twice for the same reconnection loop 471 | this.reconnect(); 472 | } 473 | }; 474 | 475 | /***/ }, 476 | /* 3 */ 477 | /***/ function(module, exports, __webpack_require__) { 478 | 479 | 480 | /** 481 | * Expose `Emitter`. 482 | */ 483 | 484 | if (true) { 485 | module.exports = Emitter; 486 | } 487 | 488 | /** 489 | * Initialize a new `Emitter`. 490 | * 491 | * @api public 492 | */ 493 | 494 | function Emitter(obj) { 495 | if (obj) return mixin(obj); 496 | }; 497 | 498 | /** 499 | * Mixin the emitter properties. 500 | * 501 | * @param {Object} obj 502 | * @return {Object} 503 | * @api private 504 | */ 505 | 506 | function mixin(obj) { 507 | for (var key in Emitter.prototype) { 508 | obj[key] = Emitter.prototype[key]; 509 | } 510 | return obj; 511 | } 512 | 513 | /** 514 | * Listen on the given `event` with `fn`. 515 | * 516 | * @param {String} event 517 | * @param {Function} fn 518 | * @return {Emitter} 519 | * @api public 520 | */ 521 | 522 | Emitter.prototype.on = 523 | Emitter.prototype.addEventListener = function(event, fn){ 524 | this._callbacks = this._callbacks || {}; 525 | (this._callbacks['$' + event] = this._callbacks['$' + event] || []) 526 | .push(fn); 527 | return this; 528 | }; 529 | 530 | /** 531 | * Adds an `event` listener that will be invoked a single 532 | * time then automatically removed. 533 | * 534 | * @param {String} event 535 | * @param {Function} fn 536 | * @return {Emitter} 537 | * @api public 538 | */ 539 | 540 | Emitter.prototype.once = function(event, fn){ 541 | function on() { 542 | this.off(event, on); 543 | fn.apply(this, arguments); 544 | } 545 | 546 | on.fn = fn; 547 | this.on(event, on); 548 | return this; 549 | }; 550 | 551 | /** 552 | * Remove the given callback for `event` or all 553 | * registered callbacks. 554 | * 555 | * @param {String} event 556 | * @param {Function} fn 557 | * @return {Emitter} 558 | * @api public 559 | */ 560 | 561 | Emitter.prototype.off = 562 | Emitter.prototype.removeListener = 563 | Emitter.prototype.removeAllListeners = 564 | Emitter.prototype.removeEventListener = function(event, fn){ 565 | this._callbacks = this._callbacks || {}; 566 | 567 | // all 568 | if (0 == arguments.length) { 569 | this._callbacks = {}; 570 | return this; 571 | } 572 | 573 | // specific event 574 | var callbacks = this._callbacks['$' + event]; 575 | if (!callbacks) return this; 576 | 577 | // remove all handlers 578 | if (1 == arguments.length) { 579 | delete this._callbacks['$' + event]; 580 | return this; 581 | } 582 | 583 | // remove specific handler 584 | var cb; 585 | for (var i = 0; i < callbacks.length; i++) { 586 | cb = callbacks[i]; 587 | if (cb === fn || cb.fn === fn) { 588 | callbacks.splice(i, 1); 589 | break; 590 | } 591 | } 592 | return this; 593 | }; 594 | 595 | /** 596 | * Emit `event` with the given args. 597 | * 598 | * @param {String} event 599 | * @param {Mixed} ... 600 | * @return {Emitter} 601 | */ 602 | 603 | Emitter.prototype.emit = function(event){ 604 | this._callbacks = this._callbacks || {}; 605 | var args = [].slice.call(arguments, 1) 606 | , callbacks = this._callbacks['$' + event]; 607 | 608 | if (callbacks) { 609 | callbacks = callbacks.slice(0); 610 | for (var i = 0, len = callbacks.length; i < len; ++i) { 611 | callbacks[i].apply(this, args); 612 | } 613 | } 614 | 615 | return this; 616 | }; 617 | 618 | /** 619 | * Return array of callbacks for `event`. 620 | * 621 | * @param {String} event 622 | * @return {Array} 623 | * @api public 624 | */ 625 | 626 | Emitter.prototype.listeners = function(event){ 627 | this._callbacks = this._callbacks || {}; 628 | return this._callbacks['$' + event] || []; 629 | }; 630 | 631 | /** 632 | * Check if this emitter has `event` handlers. 633 | * 634 | * @param {String} event 635 | * @return {Boolean} 636 | * @api public 637 | */ 638 | 639 | Emitter.prototype.hasListeners = function(event){ 640 | return !! this.listeners(event).length; 641 | }; 642 | 643 | 644 | /***/ }, 645 | /* 4 */ 646 | /***/ function(module, exports) { 647 | 648 | /** 649 | * Slice reference. 650 | */ 651 | 652 | var slice = [].slice; 653 | 654 | /** 655 | * Bind `obj` to `fn`. 656 | * 657 | * @param {Object} obj 658 | * @param {Function|String} fn or string 659 | * @return {Function} 660 | * @api public 661 | */ 662 | 663 | module.exports = function(obj, fn){ 664 | if ('string' == typeof fn) fn = obj[fn]; 665 | if ('function' != typeof fn) throw new Error('bind() requires a function'); 666 | var args = slice.call(arguments, 2); 667 | return function(){ 668 | return fn.apply(obj, args.concat(slice.call(arguments))); 669 | } 670 | }; 671 | 672 | 673 | /***/ }, 674 | /* 5 */ 675 | /***/ function(module, exports) { 676 | 677 | 678 | /** 679 | * Expose `Backoff`. 680 | */ 681 | 682 | module.exports = Backoff; 683 | 684 | /** 685 | * Initialize backoff timer with `opts`. 686 | * 687 | * - `min` initial timeout in milliseconds [100] 688 | * - `max` max timeout [10000] 689 | * - `jitter` [0] 690 | * - `factor` [2] 691 | * 692 | * @param {Object} opts 693 | * @api public 694 | */ 695 | 696 | function Backoff(opts) { 697 | opts = opts || {}; 698 | this.ms = opts.min || 100; 699 | this.max = opts.max || 10000; 700 | this.factor = opts.factor || 2; 701 | this.jitter = opts.jitter > 0 && opts.jitter <= 1 ? opts.jitter : 0; 702 | this.attempts = 0; 703 | } 704 | 705 | /** 706 | * Return the backoff duration. 707 | * 708 | * @return {Number} 709 | * @api public 710 | */ 711 | 712 | Backoff.prototype.duration = function(){ 713 | var ms = this.ms * Math.pow(this.factor, this.attempts++); 714 | if (this.jitter) { 715 | var rand = Math.random(); 716 | var deviation = Math.floor(rand * this.jitter * ms); 717 | ms = (Math.floor(rand * 10) & 1) == 0 ? ms - deviation : ms + deviation; 718 | } 719 | return Math.min(ms, this.max) | 0; 720 | }; 721 | 722 | /** 723 | * Reset the number of attempts. 724 | * 725 | * @api public 726 | */ 727 | 728 | Backoff.prototype.reset = function(){ 729 | this.attempts = 0; 730 | }; 731 | 732 | /** 733 | * Set the minimum duration 734 | * 735 | * @api public 736 | */ 737 | 738 | Backoff.prototype.setMin = function(min){ 739 | this.ms = min; 740 | }; 741 | 742 | /** 743 | * Set the maximum duration 744 | * 745 | * @api public 746 | */ 747 | 748 | Backoff.prototype.setMax = function(max){ 749 | this.max = max; 750 | }; 751 | 752 | /** 753 | * Set the jitter 754 | * 755 | * @api public 756 | */ 757 | 758 | Backoff.prototype.setJitter = function(jitter){ 759 | this.jitter = jitter; 760 | }; 761 | 762 | 763 | 764 | /***/ }, 765 | /* 6 */ 766 | /***/ function(module, exports) { 767 | 768 | 769 | var indexOf = [].indexOf; 770 | 771 | module.exports = function(arr, obj){ 772 | if (indexOf) return arr.indexOf(obj); 773 | for (var i = 0; i < arr.length; ++i) { 774 | if (arr[i] === obj) return i; 775 | } 776 | return -1; 777 | }; 778 | 779 | /***/ }, 780 | /* 7 */ 781 | /***/ function(module, exports) { 782 | 783 | "use strict"; 784 | 785 | Object.defineProperty(exports, "__esModule", { 786 | value: true 787 | }); 788 | 789 | /** 790 | * Helper for subscriptions. 791 | * 792 | * @param {Object|EventEmitter} obj with `Emitter` mixin or `EventEmitter` 793 | * @param {String} event name 794 | * @param {Function} callback 795 | * @api public 796 | */ 797 | 798 | exports.default = function (obj, ev, fn) { 799 | obj.on(ev, fn); 800 | return { 801 | destroy: function destroy() { 802 | obj.removeListener(ev, fn); 803 | } 804 | }; 805 | }; 806 | 807 | /***/ }, 808 | /* 8 */ 809 | /***/ function(module, exports, __webpack_require__) { 810 | 811 | 'use strict'; 812 | 813 | Object.defineProperty(exports, "__esModule", { 814 | value: true 815 | }); 816 | 817 | var _keys = __webpack_require__(9); 818 | 819 | var _keys2 = _interopRequireDefault(_keys); 820 | 821 | var _componentEmitter = __webpack_require__(3); 822 | 823 | var _componentEmitter2 = _interopRequireDefault(_componentEmitter); 824 | 825 | var _on = __webpack_require__(7); 826 | 827 | var _on2 = _interopRequireDefault(_on); 828 | 829 | var _parsejson = __webpack_require__(44); 830 | 831 | var _parsejson2 = _interopRequireDefault(_parsejson); 832 | 833 | var _componentBind = __webpack_require__(4); 834 | 835 | var _componentBind2 = _interopRequireDefault(_componentBind); 836 | 837 | var _parseuri = __webpack_require__(45); 838 | 839 | var _parseuri2 = _interopRequireDefault(_parseuri); 840 | 841 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 842 | 843 | exports.default = Engine; 844 | 845 | 846 | var GlobalEmitter = (0, _componentEmitter2.default)({ hasEmitte: false }); 847 | 848 | (0, _componentEmitter2.default)(Engine.prototype); 849 | 850 | var packets = { 851 | open: 0, // non-ws 852 | close: 1, // non-ws 853 | ping: 2, 854 | pong: 3, 855 | message: 4, 856 | upgrade: 5, 857 | noop: 6 858 | }; 859 | 860 | var packetslist = (0, _keys2.default)(packets); 861 | 862 | function Engine(uri, opts) { 863 | if (!(this instanceof Engine)) return new Engine(uri, opts); 864 | 865 | this.subs = []; 866 | uri = (0, _parseuri2.default)(uri); 867 | this.protocol = uri.protocol; 868 | this.host = uri.host; 869 | this.query = uri.query; 870 | this.port = uri.port; 871 | this.opts = this.opts || {}; 872 | this.path = opts.path.replace(/\/$/, ''); 873 | this.connected = false; 874 | this.lastPing = null; 875 | this.pingInterval = 20000; 876 | // init bind with GlobalEmitter 877 | this.bindEvents(); 878 | } 879 | 880 | Engine.prototype.connect = function () { 881 | if (!GlobalEmitter.hasEmitte) Engine.subEvents(); 882 | var url = this.protocol + '://' + this.host + ':' + this.port + '/' + this.path + '/?' + (this.query ? this.query + '&' : '') + 'EIO=3&transport=websocket'; 883 | 884 | wx.connectSocket({ url: url }); 885 | }; 886 | 887 | Engine.prototype.onopen = function () { 888 | this.emit('open'); 889 | }; 890 | 891 | Engine.prototype.onclose = function (reason) { 892 | // clean all bind with GlobalEmitter 893 | this.destroy(); 894 | this.emit('close', reason); 895 | }; 896 | 897 | Engine.prototype.onerror = function (reason) { 898 | this.emit('error'); 899 | // 如果 wx.connectSocket 还没回调 wx.onSocketOpen,而先调用 wx.closeSocket,那么就做不到关闭 WebSocket 的目的。 900 | wx.closeSocket(); 901 | }; 902 | 903 | Engine.prototype.onpacket = function (packet) { 904 | switch (packet.type) { 905 | case 'open': 906 | this.onHandshake((0, _parsejson2.default)(packet.data)); 907 | break; 908 | case 'pong': 909 | this.setPing(); 910 | this.emit('pong'); 911 | break; 912 | case 'error': 913 | { 914 | var error = new Error('server error'); 915 | error.code = packet.data; 916 | this.onerror(error); 917 | break; 918 | } 919 | case 'message': 920 | this.emit('data', packet.data); 921 | this.emit('message', packet.data); 922 | break; 923 | } 924 | }; 925 | 926 | Engine.prototype.onHandshake = function (data) { 927 | this.id = data.sid; 928 | this.pingInterval = data.pingInterval; 929 | this.pingTimeout = data.pingTimeout; 930 | this.setPing(); 931 | }; 932 | 933 | Engine.prototype.setPing = function () { 934 | var _this = this; 935 | 936 | clearTimeout(this.pingIntervalTimer); 937 | this.pingIntervalTimer = setTimeout(function () { 938 | _this.ping(); 939 | }, this.pingInterval); 940 | }; 941 | 942 | Engine.prototype.ping = function () { 943 | this.emit('ping'); 944 | this._send(packets.ping + 'probe'); 945 | }; 946 | 947 | Engine.prototype.write = Engine.prototype.send = function (packet) { 948 | this._send([packets.message, packet].join('')); 949 | }; 950 | 951 | Engine.prototype._send = function (data) { 952 | wx.sendSocketMessage({ data: data }); 953 | }; 954 | Engine.subEvents = function () { 955 | wx.onSocketOpen(function () { 956 | GlobalEmitter.emit('open'); 957 | }); 958 | wx.onSocketClose(function (reason) { 959 | GlobalEmitter.emit('close', reason); 960 | }); 961 | wx.onSocketError(function (reason) { 962 | GlobalEmitter.emit('error', reason); 963 | }); 964 | wx.onSocketMessage(function (resp) { 965 | GlobalEmitter.emit('packet', decodePacket(resp.data)); 966 | }); 967 | GlobalEmitter.hasEmitte = true; 968 | }; 969 | 970 | Engine.prototype.bindEvents = function () { 971 | this.subs.push((0, _on2.default)(GlobalEmitter, 'open', (0, _componentBind2.default)(this, 'onopen'))); 972 | this.subs.push((0, _on2.default)(GlobalEmitter, 'close', (0, _componentBind2.default)(this, 'onclose'))); 973 | this.subs.push((0, _on2.default)(GlobalEmitter, 'error', (0, _componentBind2.default)(this, 'onerror'))); 974 | this.subs.push((0, _on2.default)(GlobalEmitter, 'packet', (0, _componentBind2.default)(this, 'onpacket'))); 975 | }; 976 | 977 | Engine.prototype.destroy = function () { 978 | var sub = void 0; 979 | while (sub = this.subs.shift()) { 980 | sub.destroy(); 981 | } 982 | 983 | clearTimeout(this.pingIntervalTimer); 984 | this.readyState = 'closed'; 985 | this.id = null; 986 | this.writeBuffer = []; 987 | this.prevBufferLen = 0; 988 | }; 989 | 990 | function decodePacket(data) { 991 | var type = data.charAt(0); 992 | if (data.length > 1) { 993 | return { 994 | type: packetslist[type], 995 | data: data.substring(1) 996 | }; 997 | } 998 | return { type: packetslist[type] }; 999 | } 1000 | 1001 | /***/ }, 1002 | /* 9 */ 1003 | /***/ function(module, exports, __webpack_require__) { 1004 | 1005 | module.exports = { "default": __webpack_require__(10), __esModule: true }; 1006 | 1007 | /***/ }, 1008 | /* 10 */ 1009 | /***/ function(module, exports, __webpack_require__) { 1010 | 1011 | __webpack_require__(11); 1012 | module.exports = __webpack_require__(31).Object.keys; 1013 | 1014 | /***/ }, 1015 | /* 11 */ 1016 | /***/ function(module, exports, __webpack_require__) { 1017 | 1018 | // 19.1.2.14 Object.keys(O) 1019 | var toObject = __webpack_require__(12) 1020 | , $keys = __webpack_require__(14); 1021 | 1022 | __webpack_require__(29)('keys', function(){ 1023 | return function keys(it){ 1024 | return $keys(toObject(it)); 1025 | }; 1026 | }); 1027 | 1028 | /***/ }, 1029 | /* 12 */ 1030 | /***/ function(module, exports, __webpack_require__) { 1031 | 1032 | // 7.1.13 ToObject(argument) 1033 | var defined = __webpack_require__(13); 1034 | module.exports = function(it){ 1035 | return Object(defined(it)); 1036 | }; 1037 | 1038 | /***/ }, 1039 | /* 13 */ 1040 | /***/ function(module, exports) { 1041 | 1042 | // 7.2.1 RequireObjectCoercible(argument) 1043 | module.exports = function(it){ 1044 | if(it == undefined)throw TypeError("Can't call method on " + it); 1045 | return it; 1046 | }; 1047 | 1048 | /***/ }, 1049 | /* 14 */ 1050 | /***/ function(module, exports, __webpack_require__) { 1051 | 1052 | // 19.1.2.14 / 15.2.3.14 Object.keys(O) 1053 | var $keys = __webpack_require__(15) 1054 | , enumBugKeys = __webpack_require__(28); 1055 | 1056 | module.exports = Object.keys || function keys(O){ 1057 | return $keys(O, enumBugKeys); 1058 | }; 1059 | 1060 | /***/ }, 1061 | /* 15 */ 1062 | /***/ function(module, exports, __webpack_require__) { 1063 | 1064 | var has = __webpack_require__(16) 1065 | , toIObject = __webpack_require__(17) 1066 | , arrayIndexOf = __webpack_require__(20)(false) 1067 | , IE_PROTO = __webpack_require__(24)('IE_PROTO'); 1068 | 1069 | module.exports = function(object, names){ 1070 | var O = toIObject(object) 1071 | , i = 0 1072 | , result = [] 1073 | , key; 1074 | for(key in O)if(key != IE_PROTO)has(O, key) && result.push(key); 1075 | // Don't enum bug & hidden keys 1076 | while(names.length > i)if(has(O, key = names[i++])){ 1077 | ~arrayIndexOf(result, key) || result.push(key); 1078 | } 1079 | return result; 1080 | }; 1081 | 1082 | /***/ }, 1083 | /* 16 */ 1084 | /***/ function(module, exports) { 1085 | 1086 | var hasOwnProperty = {}.hasOwnProperty; 1087 | module.exports = function(it, key){ 1088 | return hasOwnProperty.call(it, key); 1089 | }; 1090 | 1091 | /***/ }, 1092 | /* 17 */ 1093 | /***/ function(module, exports, __webpack_require__) { 1094 | 1095 | // to indexed object, toObject with fallback for non-array-like ES3 strings 1096 | var IObject = __webpack_require__(18) 1097 | , defined = __webpack_require__(13); 1098 | module.exports = function(it){ 1099 | return IObject(defined(it)); 1100 | }; 1101 | 1102 | /***/ }, 1103 | /* 18 */ 1104 | /***/ function(module, exports, __webpack_require__) { 1105 | 1106 | // fallback for non-array-like ES3 and non-enumerable old V8 strings 1107 | var cof = __webpack_require__(19); 1108 | module.exports = Object('z').propertyIsEnumerable(0) ? Object : function(it){ 1109 | return cof(it) == 'String' ? it.split('') : Object(it); 1110 | }; 1111 | 1112 | /***/ }, 1113 | /* 19 */ 1114 | /***/ function(module, exports) { 1115 | 1116 | var toString = {}.toString; 1117 | 1118 | module.exports = function(it){ 1119 | return toString.call(it).slice(8, -1); 1120 | }; 1121 | 1122 | /***/ }, 1123 | /* 20 */ 1124 | /***/ function(module, exports, __webpack_require__) { 1125 | 1126 | // false -> Array#indexOf 1127 | // true -> Array#includes 1128 | var toIObject = __webpack_require__(17) 1129 | , toLength = __webpack_require__(21) 1130 | , toIndex = __webpack_require__(23); 1131 | module.exports = function(IS_INCLUDES){ 1132 | return function($this, el, fromIndex){ 1133 | var O = toIObject($this) 1134 | , length = toLength(O.length) 1135 | , index = toIndex(fromIndex, length) 1136 | , value; 1137 | // Array#includes uses SameValueZero equality algorithm 1138 | if(IS_INCLUDES && el != el)while(length > index){ 1139 | value = O[index++]; 1140 | if(value != value)return true; 1141 | // Array#toIndex ignores holes, Array#includes - not 1142 | } else for(;length > index; index++)if(IS_INCLUDES || index in O){ 1143 | if(O[index] === el)return IS_INCLUDES || index || 0; 1144 | } return !IS_INCLUDES && -1; 1145 | }; 1146 | }; 1147 | 1148 | /***/ }, 1149 | /* 21 */ 1150 | /***/ function(module, exports, __webpack_require__) { 1151 | 1152 | // 7.1.15 ToLength 1153 | var toInteger = __webpack_require__(22) 1154 | , min = Math.min; 1155 | module.exports = function(it){ 1156 | return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991 1157 | }; 1158 | 1159 | /***/ }, 1160 | /* 22 */ 1161 | /***/ function(module, exports) { 1162 | 1163 | // 7.1.4 ToInteger 1164 | var ceil = Math.ceil 1165 | , floor = Math.floor; 1166 | module.exports = function(it){ 1167 | return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it); 1168 | }; 1169 | 1170 | /***/ }, 1171 | /* 23 */ 1172 | /***/ function(module, exports, __webpack_require__) { 1173 | 1174 | var toInteger = __webpack_require__(22) 1175 | , max = Math.max 1176 | , min = Math.min; 1177 | module.exports = function(index, length){ 1178 | index = toInteger(index); 1179 | return index < 0 ? max(index + length, 0) : min(index, length); 1180 | }; 1181 | 1182 | /***/ }, 1183 | /* 24 */ 1184 | /***/ function(module, exports, __webpack_require__) { 1185 | 1186 | var shared = __webpack_require__(25)('keys') 1187 | , uid = __webpack_require__(27); 1188 | module.exports = function(key){ 1189 | return shared[key] || (shared[key] = uid(key)); 1190 | }; 1191 | 1192 | /***/ }, 1193 | /* 25 */ 1194 | /***/ function(module, exports, __webpack_require__) { 1195 | 1196 | var global = __webpack_require__(26) 1197 | , SHARED = '__core-js_shared__' 1198 | , store = global[SHARED] || (global[SHARED] = {}); 1199 | module.exports = function(key){ 1200 | return store[key] || (store[key] = {}); 1201 | }; 1202 | 1203 | /***/ }, 1204 | /* 26 */ 1205 | /***/ function(module, exports) { 1206 | 1207 | // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028 1208 | var global = module.exports = typeof window != 'undefined' && window.Math == Math 1209 | ? window : typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); 1210 | if(typeof __g == 'number')__g = global; // eslint-disable-line no-undef 1211 | 1212 | /***/ }, 1213 | /* 27 */ 1214 | /***/ function(module, exports) { 1215 | 1216 | var id = 0 1217 | , px = Math.random(); 1218 | module.exports = function(key){ 1219 | return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36)); 1220 | }; 1221 | 1222 | /***/ }, 1223 | /* 28 */ 1224 | /***/ function(module, exports) { 1225 | 1226 | // IE 8- don't enum bug keys 1227 | module.exports = ( 1228 | 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf' 1229 | ).split(','); 1230 | 1231 | /***/ }, 1232 | /* 29 */ 1233 | /***/ function(module, exports, __webpack_require__) { 1234 | 1235 | // most Object methods by ES6 should accept primitives 1236 | var $export = __webpack_require__(30) 1237 | , core = __webpack_require__(31) 1238 | , fails = __webpack_require__(40); 1239 | module.exports = function(KEY, exec){ 1240 | var fn = (core.Object || {})[KEY] || Object[KEY] 1241 | , exp = {}; 1242 | exp[KEY] = exec(fn); 1243 | $export($export.S + $export.F * fails(function(){ fn(1); }), 'Object', exp); 1244 | }; 1245 | 1246 | /***/ }, 1247 | /* 30 */ 1248 | /***/ function(module, exports, __webpack_require__) { 1249 | 1250 | var global = __webpack_require__(26) 1251 | , core = __webpack_require__(31) 1252 | , ctx = __webpack_require__(32) 1253 | , hide = __webpack_require__(34) 1254 | , PROTOTYPE = 'prototype'; 1255 | 1256 | var $export = function(type, name, source){ 1257 | var IS_FORCED = type & $export.F 1258 | , IS_GLOBAL = type & $export.G 1259 | , IS_STATIC = type & $export.S 1260 | , IS_PROTO = type & $export.P 1261 | , IS_BIND = type & $export.B 1262 | , IS_WRAP = type & $export.W 1263 | , exports = IS_GLOBAL ? core : core[name] || (core[name] = {}) 1264 | , expProto = exports[PROTOTYPE] 1265 | , target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE] 1266 | , key, own, out; 1267 | if(IS_GLOBAL)source = name; 1268 | for(key in source){ 1269 | // contains in native 1270 | own = !IS_FORCED && target && target[key] !== undefined; 1271 | if(own && key in exports)continue; 1272 | // export native or passed 1273 | out = own ? target[key] : source[key]; 1274 | // prevent global pollution for namespaces 1275 | exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key] 1276 | // bind timers to global for call from export context 1277 | : IS_BIND && own ? ctx(out, global) 1278 | // wrap global constructors for prevent change them in library 1279 | : IS_WRAP && target[key] == out ? (function(C){ 1280 | var F = function(a, b, c){ 1281 | if(this instanceof C){ 1282 | switch(arguments.length){ 1283 | case 0: return new C; 1284 | case 1: return new C(a); 1285 | case 2: return new C(a, b); 1286 | } return new C(a, b, c); 1287 | } return C.apply(this, arguments); 1288 | }; 1289 | F[PROTOTYPE] = C[PROTOTYPE]; 1290 | return F; 1291 | // make static versions for prototype methods 1292 | })(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out; 1293 | // export proto methods to core.%CONSTRUCTOR%.methods.%NAME% 1294 | if(IS_PROTO){ 1295 | (exports.virtual || (exports.virtual = {}))[key] = out; 1296 | // export proto methods to core.%CONSTRUCTOR%.prototype.%NAME% 1297 | if(type & $export.R && expProto && !expProto[key])hide(expProto, key, out); 1298 | } 1299 | } 1300 | }; 1301 | // type bitmap 1302 | $export.F = 1; // forced 1303 | $export.G = 2; // global 1304 | $export.S = 4; // static 1305 | $export.P = 8; // proto 1306 | $export.B = 16; // bind 1307 | $export.W = 32; // wrap 1308 | $export.U = 64; // safe 1309 | $export.R = 128; // real proto method for `library` 1310 | module.exports = $export; 1311 | 1312 | /***/ }, 1313 | /* 31 */ 1314 | /***/ function(module, exports) { 1315 | 1316 | var core = module.exports = {version: '2.4.0'}; 1317 | if(typeof __e == 'number')__e = core; // eslint-disable-line no-undef 1318 | 1319 | /***/ }, 1320 | /* 32 */ 1321 | /***/ function(module, exports, __webpack_require__) { 1322 | 1323 | // optional / simple context binding 1324 | var aFunction = __webpack_require__(33); 1325 | module.exports = function(fn, that, length){ 1326 | aFunction(fn); 1327 | if(that === undefined)return fn; 1328 | switch(length){ 1329 | case 1: return function(a){ 1330 | return fn.call(that, a); 1331 | }; 1332 | case 2: return function(a, b){ 1333 | return fn.call(that, a, b); 1334 | }; 1335 | case 3: return function(a, b, c){ 1336 | return fn.call(that, a, b, c); 1337 | }; 1338 | } 1339 | return function(/* ...args */){ 1340 | return fn.apply(that, arguments); 1341 | }; 1342 | }; 1343 | 1344 | /***/ }, 1345 | /* 33 */ 1346 | /***/ function(module, exports) { 1347 | 1348 | module.exports = function(it){ 1349 | if(typeof it != 'function')throw TypeError(it + ' is not a function!'); 1350 | return it; 1351 | }; 1352 | 1353 | /***/ }, 1354 | /* 34 */ 1355 | /***/ function(module, exports, __webpack_require__) { 1356 | 1357 | var dP = __webpack_require__(35) 1358 | , createDesc = __webpack_require__(43); 1359 | module.exports = __webpack_require__(39) ? function(object, key, value){ 1360 | return dP.f(object, key, createDesc(1, value)); 1361 | } : function(object, key, value){ 1362 | object[key] = value; 1363 | return object; 1364 | }; 1365 | 1366 | /***/ }, 1367 | /* 35 */ 1368 | /***/ function(module, exports, __webpack_require__) { 1369 | 1370 | var anObject = __webpack_require__(36) 1371 | , IE8_DOM_DEFINE = __webpack_require__(38) 1372 | , toPrimitive = __webpack_require__(42) 1373 | , dP = Object.defineProperty; 1374 | 1375 | exports.f = __webpack_require__(39) ? Object.defineProperty : function defineProperty(O, P, Attributes){ 1376 | anObject(O); 1377 | P = toPrimitive(P, true); 1378 | anObject(Attributes); 1379 | if(IE8_DOM_DEFINE)try { 1380 | return dP(O, P, Attributes); 1381 | } catch(e){ /* empty */ } 1382 | if('get' in Attributes || 'set' in Attributes)throw TypeError('Accessors not supported!'); 1383 | if('value' in Attributes)O[P] = Attributes.value; 1384 | return O; 1385 | }; 1386 | 1387 | /***/ }, 1388 | /* 36 */ 1389 | /***/ function(module, exports, __webpack_require__) { 1390 | 1391 | var isObject = __webpack_require__(37); 1392 | module.exports = function(it){ 1393 | if(!isObject(it))throw TypeError(it + ' is not an object!'); 1394 | return it; 1395 | }; 1396 | 1397 | /***/ }, 1398 | /* 37 */ 1399 | /***/ function(module, exports) { 1400 | 1401 | module.exports = function(it){ 1402 | return typeof it === 'object' ? it !== null : typeof it === 'function'; 1403 | }; 1404 | 1405 | /***/ }, 1406 | /* 38 */ 1407 | /***/ function(module, exports, __webpack_require__) { 1408 | 1409 | module.exports = !__webpack_require__(39) && !__webpack_require__(40)(function(){ 1410 | return Object.defineProperty(__webpack_require__(41)('div'), 'a', {get: function(){ return 7; }}).a != 7; 1411 | }); 1412 | 1413 | /***/ }, 1414 | /* 39 */ 1415 | /***/ function(module, exports, __webpack_require__) { 1416 | 1417 | // Thank's IE8 for his funny defineProperty 1418 | module.exports = !__webpack_require__(40)(function(){ 1419 | return Object.defineProperty({}, 'a', {get: function(){ return 7; }}).a != 7; 1420 | }); 1421 | 1422 | /***/ }, 1423 | /* 40 */ 1424 | /***/ function(module, exports) { 1425 | 1426 | module.exports = function(exec){ 1427 | try { 1428 | return !!exec(); 1429 | } catch(e){ 1430 | return true; 1431 | } 1432 | }; 1433 | 1434 | /***/ }, 1435 | /* 41 */ 1436 | /***/ function(module, exports, __webpack_require__) { 1437 | 1438 | var isObject = __webpack_require__(37) 1439 | , document = __webpack_require__(26).document 1440 | // in old IE typeof document.createElement is 'object' 1441 | , is = isObject(document) && isObject(document.createElement); 1442 | module.exports = function(it){ 1443 | return is ? document.createElement(it) : {}; 1444 | }; 1445 | 1446 | /***/ }, 1447 | /* 42 */ 1448 | /***/ function(module, exports, __webpack_require__) { 1449 | 1450 | // 7.1.1 ToPrimitive(input [, PreferredType]) 1451 | var isObject = __webpack_require__(37); 1452 | // instead of the ES6 spec version, we didn't implement @@toPrimitive case 1453 | // and the second argument - flag - preferred type is a string 1454 | module.exports = function(it, S){ 1455 | if(!isObject(it))return it; 1456 | var fn, val; 1457 | if(S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; 1458 | if(typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it)))return val; 1459 | if(!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it)))return val; 1460 | throw TypeError("Can't convert object to primitive value"); 1461 | }; 1462 | 1463 | /***/ }, 1464 | /* 43 */ 1465 | /***/ function(module, exports) { 1466 | 1467 | module.exports = function(bitmap, value){ 1468 | return { 1469 | enumerable : !(bitmap & 1), 1470 | configurable: !(bitmap & 2), 1471 | writable : !(bitmap & 4), 1472 | value : value 1473 | }; 1474 | }; 1475 | 1476 | /***/ }, 1477 | /* 44 */ 1478 | /***/ function(module, exports) { 1479 | 1480 | 'use strict'; 1481 | 1482 | /** 1483 | * JSON parse. 1484 | * 1485 | * @see Based on jQuery#parseJSON (MIT) and JSON2 1486 | * @api private 1487 | */ 1488 | 1489 | var rvalidchars = /^[\],:{}\s]*$/; 1490 | var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g; 1491 | var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; 1492 | var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g; 1493 | var rtrimLeft = /^\s+/; 1494 | var rtrimRight = /\s+$/; 1495 | 1496 | module.exports = function parsejson(data) { 1497 | if ('string' != typeof data || !data) { 1498 | return null; 1499 | } 1500 | 1501 | data = data.replace(rtrimLeft, '').replace(rtrimRight, ''); 1502 | 1503 | // Attempt to parse using the native JSON parser first 1504 | if (JSON.parse) { 1505 | return JSON.parse(data); 1506 | } 1507 | 1508 | if (rvalidchars.test(data.replace(rvalidescape, '@').replace(rvalidtokens, ']').replace(rvalidbraces, ''))) { 1509 | return new Function('return ' + data)(); 1510 | } 1511 | }; 1512 | 1513 | /***/ }, 1514 | /* 45 */ 1515 | /***/ function(module, exports) { 1516 | 1517 | /** 1518 | * Parses an URI 1519 | * 1520 | * @author Steven Levithan (MIT license) 1521 | * @api private 1522 | */ 1523 | 1524 | var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; 1525 | 1526 | var parts = [ 1527 | 'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor' 1528 | ]; 1529 | 1530 | module.exports = function parseuri(str) { 1531 | var src = str, 1532 | b = str.indexOf('['), 1533 | e = str.indexOf(']'); 1534 | 1535 | if (b != -1 && e != -1) { 1536 | str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length); 1537 | } 1538 | 1539 | var m = re.exec(str || ''), 1540 | uri = {}, 1541 | i = 14; 1542 | 1543 | while (i--) { 1544 | uri[parts[i]] = m[i] || ''; 1545 | } 1546 | 1547 | if (b != -1 && e != -1) { 1548 | uri.source = src; 1549 | uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':'); 1550 | uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':'); 1551 | uri.ipv6uri = true; 1552 | } 1553 | 1554 | return uri; 1555 | }; 1556 | 1557 | 1558 | /***/ }, 1559 | /* 46 */ 1560 | /***/ function(module, exports, __webpack_require__) { 1561 | 1562 | 'use strict'; 1563 | 1564 | Object.defineProperty(exports, "__esModule", { 1565 | value: true 1566 | }); 1567 | 1568 | var _stringify = __webpack_require__(47); 1569 | 1570 | var _stringify2 = _interopRequireDefault(_stringify); 1571 | 1572 | exports.encoder = encoder; 1573 | exports.decoder = decoder; 1574 | 1575 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1576 | 1577 | exports.types = ['CONNECT', 'DISCONNECT', 'EVENT', 'ACK', 'ERROR', 'BINARY_EVENT', 'BINARY_ACK']; 1578 | 1579 | function encoder(obj, callback) { 1580 | // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) 1581 | // TODO support binary packet 1582 | var encoding = encodeAsString(obj); 1583 | callback([encoding]); 1584 | } 1585 | 1586 | function encodeAsString(obj) { 1587 | var str = ''; 1588 | var nsp = false; 1589 | 1590 | str += obj.type; 1591 | // if (exports.BINARY_EVENT == obj.type || exports.BINARY_ACK == obj.type) {} 1592 | // TODO support binary type 1593 | 1594 | if (obj.nsp && '/' != obj.nsp) { 1595 | nsp = true; 1596 | str += obj.nsp; 1597 | } 1598 | 1599 | if (null != obj.id) { 1600 | if (nsp) { 1601 | str += ','; 1602 | nsp = false; 1603 | } 1604 | str += obj.id; 1605 | } 1606 | 1607 | if (null != obj.data) { 1608 | if (nsp) str += ','; 1609 | str += (0, _stringify2.default)(obj.data); 1610 | } 1611 | 1612 | return str; 1613 | } 1614 | 1615 | function decoder(obj, callback) { 1616 | var packet = void 0; 1617 | if ('string' == typeof obj) { 1618 | packet = decodeString(obj); 1619 | } 1620 | callback(packet); 1621 | } 1622 | 1623 | function decodeString(str) { 1624 | var p = {}; 1625 | var i = 0; 1626 | // look up type 1627 | p.type = Number(str.charAt(0)); 1628 | if (null == exports.types[p.type]) return error(); 1629 | 1630 | // look up attachments if type binary 1631 | 1632 | // look up namespace (if any) 1633 | if ('/' == str.charAt(i + 1)) { 1634 | p.nsp = ''; 1635 | while (++i) { 1636 | var c = str.charAt(i); 1637 | if (',' == c) break; 1638 | p.nsp += c; 1639 | if (i == str.length) break; 1640 | } 1641 | } else { 1642 | p.nsp = '/'; 1643 | } 1644 | 1645 | // look up id 1646 | var next = str.charAt(i + 1); 1647 | if ('' !== next && Number(next) == next) { 1648 | p.id = ''; 1649 | while (++i) { 1650 | var _c = str.charAt(i); 1651 | if (null == _c || Number(_c) != _c) { 1652 | --i; 1653 | break; 1654 | } 1655 | p.id += str.charAt(i); 1656 | if (i == str.length) break; 1657 | } 1658 | p.id = Number(p.id); 1659 | } 1660 | 1661 | // look up json data 1662 | if (str.charAt(++i)) { 1663 | try { 1664 | p.data = JSON.parse(str.substr(i)); 1665 | } catch (e) { 1666 | return error(); 1667 | } 1668 | } 1669 | return p; 1670 | } 1671 | 1672 | function error(data) { 1673 | return { 1674 | type: exports.ERROR, 1675 | data: 'parser error' 1676 | }; 1677 | } 1678 | 1679 | /***/ }, 1680 | /* 47 */ 1681 | /***/ function(module, exports, __webpack_require__) { 1682 | 1683 | module.exports = { "default": __webpack_require__(48), __esModule: true }; 1684 | 1685 | /***/ }, 1686 | /* 48 */ 1687 | /***/ function(module, exports, __webpack_require__) { 1688 | 1689 | var core = __webpack_require__(31) 1690 | , $JSON = core.JSON || (core.JSON = {stringify: JSON.stringify}); 1691 | module.exports = function stringify(it){ // eslint-disable-line no-unused-vars 1692 | return $JSON.stringify.apply($JSON, arguments); 1693 | }; 1694 | 1695 | /***/ }, 1696 | /* 49 */ 1697 | /***/ function(module, exports, __webpack_require__) { 1698 | 1699 | 'use strict'; 1700 | 1701 | Object.defineProperty(exports, "__esModule", { 1702 | value: true 1703 | }); 1704 | 1705 | var _componentEmitter = __webpack_require__(3); 1706 | 1707 | var _componentEmitter2 = _interopRequireDefault(_componentEmitter); 1708 | 1709 | var _on = __webpack_require__(7); 1710 | 1711 | var _on2 = _interopRequireDefault(_on); 1712 | 1713 | var _componentBind = __webpack_require__(4); 1714 | 1715 | var _componentBind2 = _interopRequireDefault(_componentBind); 1716 | 1717 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1718 | 1719 | (0, _componentEmitter2.default)(Socket.prototype); 1720 | 1721 | var parser = { 1722 | CONNECT: 0, 1723 | DISCONNECT: 1, 1724 | EVENT: 2, 1725 | ACK: 3, 1726 | ERROR: 4, 1727 | BINARY_EVENT: 5, 1728 | BINARY_ACK: 6 1729 | }; 1730 | 1731 | var events = { 1732 | connect: 1, 1733 | connect_error: 1, 1734 | connect_timeout: 1, 1735 | connecting: 1, 1736 | disconnect: 1, 1737 | error: 1, 1738 | reconnect: 1, 1739 | reconnect_attempt: 1, 1740 | reconnect_failed: 1, 1741 | reconnect_error: 1, 1742 | reconnecting: 1, 1743 | ping: 1, 1744 | pong: 1 1745 | }; 1746 | 1747 | var emit = _componentEmitter2.default.prototype.emit; 1748 | 1749 | exports.default = Socket; 1750 | 1751 | 1752 | function Socket(io, nsp) { 1753 | this.io = io; 1754 | this.nsp = nsp; 1755 | this.id = 0; // sid 1756 | this.connected = false; 1757 | this.disconnected = true; 1758 | this.receiveBuffer = []; 1759 | this.sendBuffer = []; 1760 | if (this.io.autoConnect) this.open(); 1761 | } 1762 | 1763 | Socket.prototype.subEvents = function () { 1764 | if (this.subs) return; 1765 | 1766 | var io = this.io; 1767 | this.subs = [(0, _on2.default)(io, 'open', (0, _componentBind2.default)(this, 'onopen')), (0, _on2.default)(io, 'packet', (0, _componentBind2.default)(this, 'onpacket')), (0, _on2.default)(io, 'close', (0, _componentBind2.default)(this, 'onclose'))]; 1768 | }; 1769 | 1770 | Socket.prototype.open = Socket.prototype.connect = function () { 1771 | if (this.connected) return this; 1772 | this.subEvents(); 1773 | this.io.open(); // ensure open 1774 | if ('open' == this.io.readyState) this.onopen(); 1775 | return this; 1776 | }; 1777 | 1778 | Socket.prototype.onopen = function () { 1779 | if ('/' != this.nsp) this.packet({ type: parser.CONNECT }); 1780 | }; 1781 | 1782 | Socket.prototype.onclose = function (reason) { 1783 | this.connected = false; 1784 | this.disconnected = true; 1785 | delete this.id; 1786 | this.emit('disconnect', reason); 1787 | }; 1788 | 1789 | Socket.prototype.onpacket = function (packet) { 1790 | if (packet.nsp != this.nsp) return; 1791 | 1792 | switch (packet.type) { 1793 | case parser.CONNECT: 1794 | this.onconnect(); 1795 | break; 1796 | case parser.EVENT: 1797 | this.onevent(packet); 1798 | break; 1799 | case parser.DISCONNECT: 1800 | this.disconnect(); 1801 | break; 1802 | case parser.ERROR: 1803 | this.emit('error', packet.data); 1804 | break; 1805 | } 1806 | }; 1807 | 1808 | Socket.prototype.onconnect = function () { 1809 | this.connected = true; 1810 | this.disconnected = false; 1811 | this.emit('connect'); 1812 | // this.emitBuffered() 1813 | }; 1814 | 1815 | Socket.prototype.onevent = function (packet) { 1816 | var args = packet.data || []; 1817 | 1818 | if (this.connected) { 1819 | emit.apply(this, args); 1820 | } else { 1821 | this.receiveBuffer.push(args); 1822 | } 1823 | }; 1824 | 1825 | Socket.prototype.close = Socket.prototype.disconnect = function () { 1826 | if (this.connected) { 1827 | this.packet({ type: parser.DISCONNECT }); 1828 | } 1829 | 1830 | this.destroy(); 1831 | 1832 | if (this.connected) { 1833 | this.onclose('io client disconnect'); 1834 | } 1835 | return this; 1836 | }; 1837 | 1838 | Socket.prototype.destroy = function () { 1839 | if (this.subs) { 1840 | for (var i = 0; i < this.subs.length; i++) { 1841 | this.subs[i].destroy(); 1842 | } 1843 | this.subs = null; 1844 | } 1845 | this.io.destroy(this); 1846 | }; 1847 | 1848 | Socket.prototype.emit = function () { 1849 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { 1850 | args[_key] = arguments[_key]; 1851 | } 1852 | 1853 | if (events.hasOwnProperty(args[0])) { 1854 | emit.apply(this, args); 1855 | return this; 1856 | } 1857 | 1858 | var parserType = parser.EVENT; 1859 | // if (hasBin(args)) { parserType = parser.BINARY_EVENT; } // binary 1860 | var packet = { type: parserType, data: args, options: {} }; 1861 | 1862 | if (this.connected) { 1863 | this.packet(packet); 1864 | } else { 1865 | this.sendBuffer.push(packet); 1866 | } 1867 | return this; 1868 | }; 1869 | 1870 | Socket.prototype.packet = function (packet) { 1871 | packet.nsp = this.nsp; 1872 | this.io.packet(packet); 1873 | }; 1874 | 1875 | /***/ }, 1876 | /* 50 */ 1877 | /***/ function(module, exports, __webpack_require__) { 1878 | 1879 | 'use strict'; 1880 | 1881 | Object.defineProperty(exports, "__esModule", { 1882 | value: true 1883 | }); 1884 | 1885 | var _parseuri = __webpack_require__(45); 1886 | 1887 | var _parseuri2 = _interopRequireDefault(_parseuri); 1888 | 1889 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 1890 | 1891 | exports.default = function (uri) { 1892 | var obj = (0, _parseuri2.default)(uri); 1893 | 1894 | // make sure we treat `localhost:80` and `localhost` equally 1895 | if (!obj.port) { 1896 | if (/^(http|ws)$/.test(obj.protocol)) { 1897 | obj.port = '80'; 1898 | } else if (/^(http|ws)s$/.test(obj.protocol)) { 1899 | obj.port = '443'; 1900 | } 1901 | } 1902 | 1903 | obj.path = obj.path || '/'; 1904 | var ipv6 = obj.host.indexOf(':') !== -1; 1905 | var host = ipv6 ? '[' + obj.host + ']' : obj.host; 1906 | 1907 | // define unique id 1908 | obj.id = obj.protocol + '://' + host + ':' + obj.port; 1909 | 1910 | return obj; 1911 | }; 1912 | 1913 | /***/ } 1914 | /******/ ]) 1915 | }); 1916 | ; 1917 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack') 2 | const path = require('path') 3 | 4 | const ENV = process.env.NODE_ENV 5 | 6 | module.exports = { 7 | context: path.join(__dirname, './src'), 8 | entry: { 9 | app: [ 10 | './index.js', 11 | ], 12 | }, 13 | output: { 14 | path: path.join(__dirname, './dist'), 15 | filename: 'index.js', 16 | libraryTarget: 'umd', 17 | }, 18 | devtool: '#source-map', 19 | resolve: { 20 | extensions: ['', '.js'], 21 | }, 22 | module: { 23 | loaders: [ 24 | { 25 | test: /\.js$/, 26 | include: path.resolve(__dirname, './src'), 27 | loaders: ['babel'], 28 | }], 29 | }, 30 | plugins: [ 31 | new webpack.DefinePlugin({ 32 | 'process.env.NODE_ENV': JSON.stringify(ENV), 33 | }), 34 | ], 35 | } 36 | --------------------------------------------------------------------------------