* `Manager` constructor. * * @param {String} engine instance or engine uri/opts * @param {Object} options * @api public
(uri, opts)
| 3261 | */ |
| 3262 | |
| 3263 | function Manager(uri, opts) { |
| 3264 | if (!(this instanceof Manager)) return new Manager(uri, opts); |
| 3265 | if (uri && 'object' === (typeof uri === 'undefined' ? 'undefined' : _typeof(uri))) { |
| 3266 | opts = uri; |
| 3267 | uri = undefined; |
| 3268 | } |
| 3269 | opts = opts || {}; |
| 3270 | |
| 3271 | opts.path = opts.path || '/socket.io'; |
| 3272 | this.nsps = {}; |
| 3273 | this.subs = []; |
| 3274 | this.opts = opts; |
| 3275 | this.reconnection(opts.reconnection !== false); |
| 3276 | this.reconnectionAttempts(opts.reconnectionAttempts || Infinity); |
| 3277 | this.reconnectionDelay(opts.reconnectionDelay || 1000); |
| 3278 | this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000); |
| 3279 | this.randomizationFactor(opts.randomizationFactor || 0.5); |
| 3280 | this.backoff = new Backoff({ |
| 3281 | min: this.reconnectionDelay(), |
| 3282 | max: this.reconnectionDelayMax(), |
| 3283 | jitter: this.randomizationFactor() |
| 3284 | }); |
| 3285 | this.timeout(null == opts.timeout ? 20000 : opts.timeout); |
| 3286 | this.readyState = 'closed'; |
| 3287 | this.uri = uri; |
| 3288 | this.connecting = []; |
| 3289 | this.lastPing = null; |
| 3290 | this.encoding = false; |
| 3291 | this.packetBuffer = []; |
| 3292 | this.encoder = new parser.Encoder(); |
| 3293 | this.decoder = new parser.Decoder(); |
| 3294 | this.autoConnect = opts.autoConnect !== false; |
| 3295 | if (this.autoConnect) this.open(); |
| 3296 | } |
| 3297 | |
| 3298 | /** |
| 3299 | * Propagate given event to sockets and emit on `this` |