{"ast":null,"code":"\"use strict\";\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\nexports.Manager = void 0;\n\nconst eio = require(\"engine.io-client\");\n\nconst socket_1 = require(\"./socket\");\n\nconst parser = require(\"socket.io-parser\");\n\nconst on_1 = require(\"./on\");\n\nconst Backoff = require(\"backo2\");\n\nconst typed_events_1 = require(\"./typed-events\");\n\nconst debug = require(\"debug\")(\"socket.io-client:manager\");\n\nclass Manager extends typed_events_1.StrictEventEmitter {\n  constructor(uri, opts) {\n    super();\n    this.nsps = {};\n    this.subs = [];\n\n    if (uri && \"object\" === typeof uri) {\n      opts = uri;\n      uri = undefined;\n    }\n\n    opts = opts || {};\n    opts.path = opts.path || \"/socket.io\";\n    this.opts = opts;\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._readyState = \"closed\";\n    this.uri = uri;\n\n    const _parser = opts.parser || parser;\n\n    this.encoder = new _parser.Encoder();\n    this.decoder = new _parser.Decoder();\n    this._autoConnect = opts.autoConnect !== false;\n    if (this._autoConnect) this.open();\n  }\n\n  reconnection(v) {\n    if (!arguments.length) return this._reconnection;\n    this._reconnection = !!v;\n    return this;\n  }\n\n  reconnectionAttempts(v) {\n    if (v === undefined) return this._reconnectionAttempts;\n    this._reconnectionAttempts = v;\n    return this;\n  }\n\n  reconnectionDelay(v) {\n    var _a;\n\n    if (v === undefined) return this._reconnectionDelay;\n    this._reconnectionDelay = v;\n    (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);\n    return this;\n  }\n\n  randomizationFactor(v) {\n    var _a;\n\n    if (v === undefined) return this._randomizationFactor;\n    this._randomizationFactor = v;\n    (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);\n    return this;\n  }\n\n  reconnectionDelayMax(v) {\n    var _a;\n\n    if (v === undefined) return this._reconnectionDelayMax;\n    this._reconnectionDelayMax = v;\n    (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);\n    return this;\n  }\n\n  timeout(v) {\n    if (!arguments.length) return this._timeout;\n    this._timeout = v;\n    return this;\n  }\n  /**\n   * Starts trying to reconnect if reconnection is enabled and we have not\n   * started reconnecting yet\n   *\n   * @private\n   */\n\n\n  maybeReconnectOnOpen() {\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   * Sets the current transport `socket`.\n   *\n   * @param {Function} fn - optional, callback\n   * @return self\n   * @public\n   */\n\n\n  open(fn) {\n    debug(\"readyState %s\", this._readyState);\n    if (~this._readyState.indexOf(\"open\")) return this;\n    debug(\"opening %s\", this.uri);\n    this.engine = eio(this.uri, this.opts);\n    const socket = this.engine;\n    const self = this;\n    this._readyState = \"opening\";\n    this.skipReconnect = false; // emit `open`\n\n    const openSubDestroy = on_1.on(socket, \"open\", function () {\n      self.onopen();\n      fn && fn();\n    }); // emit `error`\n\n    const errorSub = on_1.on(socket, \"error\", err => {\n      debug(\"error\");\n      self.cleanup();\n      self._readyState = \"closed\";\n      this.emitReserved(\"error\", err);\n\n      if (fn) {\n        fn(err);\n      } else {\n        // Only do this if there is no fn to handle the error\n        self.maybeReconnectOnOpen();\n      }\n    });\n\n    if (false !== this._timeout) {\n      const timeout = this._timeout;\n      debug(\"connect attempt will timeout after %d\", timeout);\n\n      if (timeout === 0) {\n        openSubDestroy(); // prevents a race condition with the 'open' event\n      } // set timer\n\n\n      const timer = setTimeout(() => {\n        debug(\"connect attempt timed out after %d\", timeout);\n        openSubDestroy();\n        socket.close();\n        socket.emit(\"error\", new Error(\"timeout\"));\n      }, timeout);\n\n      if (this.opts.autoUnref) {\n        timer.unref();\n      }\n\n      this.subs.push(function subDestroy() {\n        clearTimeout(timer);\n      });\n    }\n\n    this.subs.push(openSubDestroy);\n    this.subs.push(errorSub);\n    return this;\n  }\n  /**\n   * Alias for open()\n   *\n   * @return self\n   * @public\n   */\n\n\n  connect(fn) {\n    return this.open(fn);\n  }\n  /**\n   * Called upon transport open.\n   *\n   * @private\n   */\n\n\n  onopen() {\n    debug(\"open\"); // clear old subs\n\n    this.cleanup(); // mark as open\n\n    this._readyState = \"open\";\n    this.emitReserved(\"open\"); // add new subs\n\n    const socket = this.engine;\n    this.subs.push(on_1.on(socket, \"ping\", this.onping.bind(this)), on_1.on(socket, \"data\", this.ondata.bind(this)), on_1.on(socket, \"error\", this.onerror.bind(this)), on_1.on(socket, \"close\", this.onclose.bind(this)), on_1.on(this.decoder, \"decoded\", this.ondecoded.bind(this)));\n  }\n  /**\n   * Called upon a ping.\n   *\n   * @private\n   */\n\n\n  onping() {\n    this.emitReserved(\"ping\");\n  }\n  /**\n   * Called with data.\n   *\n   * @private\n   */\n\n\n  ondata(data) {\n    this.decoder.add(data);\n  }\n  /**\n   * Called when parser fully decodes a packet.\n   *\n   * @private\n   */\n\n\n  ondecoded(packet) {\n    this.emitReserved(\"packet\", packet);\n  }\n  /**\n   * Called upon socket error.\n   *\n   * @private\n   */\n\n\n  onerror(err) {\n    debug(\"error\", err);\n    this.emitReserved(\"error\", err);\n  }\n  /**\n   * Creates a new socket for the given `nsp`.\n   *\n   * @return {Socket}\n   * @public\n   */\n\n\n  socket(nsp, opts) {\n    let socket = this.nsps[nsp];\n\n    if (!socket) {\n      socket = new socket_1.Socket(this, nsp, opts);\n      this.nsps[nsp] = socket;\n    }\n\n    return socket;\n  }\n  /**\n   * Called upon a socket close.\n   *\n   * @param socket\n   * @private\n   */\n\n\n  _destroy(socket) {\n    const nsps = Object.keys(this.nsps);\n\n    for (const nsp of nsps) {\n      const socket = this.nsps[nsp];\n\n      if (socket.active) {\n        debug(\"socket %s is still active, skipping close\", nsp);\n        return;\n      }\n    }\n\n    this._close();\n  }\n  /**\n   * Writes a packet.\n   *\n   * @param packet\n   * @private\n   */\n\n\n  _packet(packet) {\n    debug(\"writing packet %j\", packet);\n    const encodedPackets = this.encoder.encode(packet);\n\n    for (let i = 0; i < encodedPackets.length; i++) {\n      this.engine.write(encodedPackets[i], packet.options);\n    }\n  }\n  /**\n   * Clean up transport subscriptions and packet buffer.\n   *\n   * @private\n   */\n\n\n  cleanup() {\n    debug(\"cleanup\");\n    this.subs.forEach(subDestroy => subDestroy());\n    this.subs.length = 0;\n    this.decoder.destroy();\n  }\n  /**\n   * Close the current socket.\n   *\n   * @private\n   */\n\n\n  _close() {\n    debug(\"disconnect\");\n    this.skipReconnect = true;\n    this._reconnecting = false;\n\n    if (\"opening\" === this._readyState) {\n      // `onclose` will not fire because\n      // an open event never happened\n      this.cleanup();\n    }\n\n    this.backoff.reset();\n    this._readyState = \"closed\";\n    if (this.engine) this.engine.close();\n  }\n  /**\n   * Alias for close()\n   *\n   * @private\n   */\n\n\n  disconnect() {\n    return this._close();\n  }\n  /**\n   * Called upon engine close.\n   *\n   * @private\n   */\n\n\n  onclose(reason) {\n    debug(\"onclose\");\n    this.cleanup();\n    this.backoff.reset();\n    this._readyState = \"closed\";\n    this.emitReserved(\"close\", reason);\n\n    if (this._reconnection && !this.skipReconnect) {\n      this.reconnect();\n    }\n  }\n  /**\n   * Attempt a reconnection.\n   *\n   * @private\n   */\n\n\n  reconnect() {\n    if (this._reconnecting || this.skipReconnect) return this;\n    const self = this;\n\n    if (this.backoff.attempts >= this._reconnectionAttempts) {\n      debug(\"reconnect failed\");\n      this.backoff.reset();\n      this.emitReserved(\"reconnect_failed\");\n      this._reconnecting = false;\n    } else {\n      const delay = this.backoff.duration();\n      debug(\"will wait %dms before reconnect attempt\", delay);\n      this._reconnecting = true;\n      const timer = setTimeout(() => {\n        if (self.skipReconnect) return;\n        debug(\"attempting reconnect\");\n        this.emitReserved(\"reconnect_attempt\", self.backoff.attempts); // check again for the case socket closed in above events\n\n        if (self.skipReconnect) return;\n        self.open(err => {\n          if (err) {\n            debug(\"reconnect attempt error\");\n            self._reconnecting = false;\n            self.reconnect();\n            this.emitReserved(\"reconnect_error\", err);\n          } else {\n            debug(\"reconnect success\");\n            self.onreconnect();\n          }\n        });\n      }, delay);\n\n      if (this.opts.autoUnref) {\n        timer.unref();\n      }\n\n      this.subs.push(function subDestroy() {\n        clearTimeout(timer);\n      });\n    }\n  }\n  /**\n   * Called upon successful reconnect.\n   *\n   * @private\n   */\n\n\n  onreconnect() {\n    const attempt = this.backoff.attempts;\n    this._reconnecting = false;\n    this.backoff.reset();\n    this.emitReserved(\"reconnect\", attempt);\n  }\n\n}\n\nexports.Manager = Manager;","map":{"version":3,"sources":["C:/laragon/www/itokin/DriverOPCDA/frontend/node_modules/socket.io-client/build/manager.js"],"names":["Object","defineProperty","exports","value","Manager","eio","require","socket_1","parser","on_1","Backoff","typed_events_1","debug","StrictEventEmitter","constructor","uri","opts","nsps","subs","undefined","path","reconnection","reconnectionAttempts","Infinity","reconnectionDelay","reconnectionDelayMax","randomizationFactor","backoff","min","max","jitter","timeout","_readyState","_parser","encoder","Encoder","decoder","Decoder","_autoConnect","autoConnect","open","v","arguments","length","_reconnection","_reconnectionAttempts","_a","_reconnectionDelay","setMin","_randomizationFactor","setJitter","_reconnectionDelayMax","setMax","_timeout","maybeReconnectOnOpen","_reconnecting","attempts","reconnect","fn","indexOf","engine","socket","self","skipReconnect","openSubDestroy","on","onopen","errorSub","err","cleanup","emitReserved","timer","setTimeout","close","emit","Error","autoUnref","unref","push","subDestroy","clearTimeout","connect","onping","bind","ondata","onerror","onclose","ondecoded","data","add","packet","nsp","Socket","_destroy","keys","active","_close","_packet","encodedPackets","encode","i","write","options","forEach","destroy","reset","disconnect","reason","delay","duration","onreconnect","attempt"],"mappings":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,KAAK,GAAGC,UAAU,CAAC,MAAM;AAC3B,YAAIV,IAAI,CAACC,aAAT,EACI;AACJnD,QAAAA,KAAK,CAAC,sBAAD,CAAL;AACA,aAAK0D,YAAL,CAAkB,mBAAlB,EAAuCR,IAAI,CAACnC,OAAL,CAAa6B,QAApD,EAJ2B,CAK3B;;AACA,YAAIM,IAAI,CAACC,aAAT,EACI;AACJD,QAAAA,IAAI,CAACtB,IAAL,CAAW4B,GAAD,IAAS;AACf,cAAIA,GAAJ,EAAS;AACLxD,YAAAA,KAAK,CAAC,yBAAD,CAAL;AACAkD,YAAAA,IAAI,CAACP,aAAL,GAAqB,KAArB;AACAO,YAAAA,IAAI,CAACL,SAAL;AACA,iBAAKa,YAAL,CAAkB,iBAAlB,EAAqCF,GAArC;AACH,WALD,MAMK;AACDxD,YAAAA,KAAK,CAAC,mBAAD,CAAL;AACAkD,YAAAA,IAAI,CAACgD,WAAL;AACH;AACJ,SAXD;AAYH,OApBuB,EAoBrBF,KApBqB,CAAxB;;AAqBA,UAAI,KAAK5F,IAAL,CAAU4D,SAAd,EAAyB;AACrBL,QAAAA,KAAK,CAACM,KAAN;AACH;;AACD,WAAK3D,IAAL,CAAU4D,IAAV,CAAe,SAASC,UAAT,GAAsB;AACjCC,QAAAA,YAAY,CAACT,KAAD,CAAZ;AACH,OAFD;AAGH;AACJ;AACD;AACJ;AACA;AACA;AACA;;;AACIuC,EAAAA,WAAW,GAAG;AACV,UAAMC,OAAO,GAAG,KAAKpF,OAAL,CAAa6B,QAA7B;AACA,SAAKD,aAAL,GAAqB,KAArB;AACA,SAAK5B,OAAL,CAAa8E,KAAb;AACA,SAAKnC,YAAL,CAAkB,WAAlB,EAA+ByC,OAA/B;AACH;;AA1WmD;;AA4WxD7G,OAAO,CAACE,OAAR,GAAkBA,OAAlB","sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Manager = void 0;\nconst eio = require(\"engine.io-client\");\nconst socket_1 = require(\"./socket\");\nconst parser = require(\"socket.io-parser\");\nconst on_1 = require(\"./on\");\nconst Backoff = require(\"backo2\");\nconst typed_events_1 = require(\"./typed-events\");\nconst debug = require(\"debug\")(\"socket.io-client:manager\");\nclass Manager extends typed_events_1.StrictEventEmitter {\n    constructor(uri, opts) {\n        super();\n        this.nsps = {};\n        this.subs = [];\n        if (uri && \"object\" === typeof uri) {\n            opts = uri;\n            uri = undefined;\n        }\n        opts = opts || {};\n        opts.path = opts.path || \"/socket.io\";\n        this.opts = opts;\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._readyState = \"closed\";\n        this.uri = uri;\n        const _parser = opts.parser || parser;\n        this.encoder = new _parser.Encoder();\n        this.decoder = new _parser.Decoder();\n        this._autoConnect = opts.autoConnect !== false;\n        if (this._autoConnect)\n            this.open();\n    }\n    reconnection(v) {\n        if (!arguments.length)\n            return this._reconnection;\n        this._reconnection = !!v;\n        return this;\n    }\n    reconnectionAttempts(v) {\n        if (v === undefined)\n            return this._reconnectionAttempts;\n        this._reconnectionAttempts = v;\n        return this;\n    }\n    reconnectionDelay(v) {\n        var _a;\n        if (v === undefined)\n            return this._reconnectionDelay;\n        this._reconnectionDelay = v;\n        (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMin(v);\n        return this;\n    }\n    randomizationFactor(v) {\n        var _a;\n        if (v === undefined)\n            return this._randomizationFactor;\n        this._randomizationFactor = v;\n        (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setJitter(v);\n        return this;\n    }\n    reconnectionDelayMax(v) {\n        var _a;\n        if (v === undefined)\n            return this._reconnectionDelayMax;\n        this._reconnectionDelayMax = v;\n        (_a = this.backoff) === null || _a === void 0 ? void 0 : _a.setMax(v);\n        return this;\n    }\n    timeout(v) {\n        if (!arguments.length)\n            return this._timeout;\n        this._timeout = v;\n        return this;\n    }\n    /**\n     * Starts trying to reconnect if reconnection is enabled and we have not\n     * started reconnecting yet\n     *\n     * @private\n     */\n    maybeReconnectOnOpen() {\n        // Only try to reconnect if it's the first time we're connecting\n        if (!this._reconnecting &&\n            this._reconnection &&\n            this.backoff.attempts === 0) {\n            // keeps reconnection from firing twice for the same reconnection loop\n            this.reconnect();\n        }\n    }\n    /**\n     * Sets the current transport `socket`.\n     *\n     * @param {Function} fn - optional, callback\n     * @return self\n     * @public\n     */\n    open(fn) {\n        debug(\"readyState %s\", this._readyState);\n        if (~this._readyState.indexOf(\"open\"))\n            return this;\n        debug(\"opening %s\", this.uri);\n        this.engine = eio(this.uri, this.opts);\n        const socket = this.engine;\n        const self = this;\n        this._readyState = \"opening\";\n        this.skipReconnect = false;\n        // emit `open`\n        const openSubDestroy = on_1.on(socket, \"open\", function () {\n            self.onopen();\n            fn && fn();\n        });\n        // emit `error`\n        const errorSub = on_1.on(socket, \"error\", (err) => {\n            debug(\"error\");\n            self.cleanup();\n            self._readyState = \"closed\";\n            this.emitReserved(\"error\", err);\n            if (fn) {\n                fn(err);\n            }\n            else {\n                // Only do this if there is no fn to handle the error\n                self.maybeReconnectOnOpen();\n            }\n        });\n        if (false !== this._timeout) {\n            const timeout = this._timeout;\n            debug(\"connect attempt will timeout after %d\", timeout);\n            if (timeout === 0) {\n                openSubDestroy(); // prevents a race condition with the 'open' event\n            }\n            // set timer\n            const timer = setTimeout(() => {\n                debug(\"connect attempt timed out after %d\", timeout);\n                openSubDestroy();\n                socket.close();\n                socket.emit(\"error\", new Error(\"timeout\"));\n            }, timeout);\n            if (this.opts.autoUnref) {\n                timer.unref();\n            }\n            this.subs.push(function subDestroy() {\n                clearTimeout(timer);\n            });\n        }\n        this.subs.push(openSubDestroy);\n        this.subs.push(errorSub);\n        return this;\n    }\n    /**\n     * Alias for open()\n     *\n     * @return self\n     * @public\n     */\n    connect(fn) {\n        return this.open(fn);\n    }\n    /**\n     * Called upon transport open.\n     *\n     * @private\n     */\n    onopen() {\n        debug(\"open\");\n        // clear old subs\n        this.cleanup();\n        // mark as open\n        this._readyState = \"open\";\n        this.emitReserved(\"open\");\n        // add new subs\n        const socket = this.engine;\n        this.subs.push(on_1.on(socket, \"ping\", this.onping.bind(this)), on_1.on(socket, \"data\", this.ondata.bind(this)), on_1.on(socket, \"error\", this.onerror.bind(this)), on_1.on(socket, \"close\", this.onclose.bind(this)), on_1.on(this.decoder, \"decoded\", this.ondecoded.bind(this)));\n    }\n    /**\n     * Called upon a ping.\n     *\n     * @private\n     */\n    onping() {\n        this.emitReserved(\"ping\");\n    }\n    /**\n     * Called with data.\n     *\n     * @private\n     */\n    ondata(data) {\n        this.decoder.add(data);\n    }\n    /**\n     * Called when parser fully decodes a packet.\n     *\n     * @private\n     */\n    ondecoded(packet) {\n        this.emitReserved(\"packet\", packet);\n    }\n    /**\n     * Called upon socket error.\n     *\n     * @private\n     */\n    onerror(err) {\n        debug(\"error\", err);\n        this.emitReserved(\"error\", err);\n    }\n    /**\n     * Creates a new socket for the given `nsp`.\n     *\n     * @return {Socket}\n     * @public\n     */\n    socket(nsp, opts) {\n        let socket = this.nsps[nsp];\n        if (!socket) {\n            socket = new socket_1.Socket(this, nsp, opts);\n            this.nsps[nsp] = socket;\n        }\n        return socket;\n    }\n    /**\n     * Called upon a socket close.\n     *\n     * @param socket\n     * @private\n     */\n    _destroy(socket) {\n        const nsps = Object.keys(this.nsps);\n        for (const nsp of nsps) {\n            const socket = this.nsps[nsp];\n            if (socket.active) {\n                debug(\"socket %s is still active, skipping close\", nsp);\n                return;\n            }\n        }\n        this._close();\n    }\n    /**\n     * Writes a packet.\n     *\n     * @param packet\n     * @private\n     */\n    _packet(packet) {\n        debug(\"writing packet %j\", packet);\n        const encodedPackets = this.encoder.encode(packet);\n        for (let i = 0; i < encodedPackets.length; i++) {\n            this.engine.write(encodedPackets[i], packet.options);\n        }\n    }\n    /**\n     * Clean up transport subscriptions and packet buffer.\n     *\n     * @private\n     */\n    cleanup() {\n        debug(\"cleanup\");\n        this.subs.forEach((subDestroy) => subDestroy());\n        this.subs.length = 0;\n        this.decoder.destroy();\n    }\n    /**\n     * Close the current socket.\n     *\n     * @private\n     */\n    _close() {\n        debug(\"disconnect\");\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.backoff.reset();\n        this._readyState = \"closed\";\n        if (this.engine)\n            this.engine.close();\n    }\n    /**\n     * Alias for close()\n     *\n     * @private\n     */\n    disconnect() {\n        return this._close();\n    }\n    /**\n     * Called upon engine close.\n     *\n     * @private\n     */\n    onclose(reason) {\n        debug(\"onclose\");\n        this.cleanup();\n        this.backoff.reset();\n        this._readyState = \"closed\";\n        this.emitReserved(\"close\", reason);\n        if (this._reconnection && !this.skipReconnect) {\n            this.reconnect();\n        }\n    }\n    /**\n     * Attempt a reconnection.\n     *\n     * @private\n     */\n    reconnect() {\n        if (this._reconnecting || this.skipReconnect)\n            return this;\n        const self = this;\n        if (this.backoff.attempts >= this._reconnectionAttempts) {\n            debug(\"reconnect failed\");\n            this.backoff.reset();\n            this.emitReserved(\"reconnect_failed\");\n            this._reconnecting = false;\n        }\n        else {\n            const delay = this.backoff.duration();\n            debug(\"will wait %dms before reconnect attempt\", delay);\n            this._reconnecting = true;\n            const timer = setTimeout(() => {\n                if (self.skipReconnect)\n                    return;\n                debug(\"attempting reconnect\");\n                this.emitReserved(\"reconnect_attempt\", self.backoff.attempts);\n                // check again for the case socket closed in above events\n                if (self.skipReconnect)\n                    return;\n                self.open((err) => {\n                    if (err) {\n                        debug(\"reconnect attempt error\");\n                        self._reconnecting = false;\n                        self.reconnect();\n                        this.emitReserved(\"reconnect_error\", err);\n                    }\n                    else {\n                        debug(\"reconnect success\");\n                        self.onreconnect();\n                    }\n                });\n            }, delay);\n            if (this.opts.autoUnref) {\n                timer.unref();\n            }\n            this.subs.push(function subDestroy() {\n                clearTimeout(timer);\n            });\n        }\n    }\n    /**\n     * Called upon successful reconnect.\n     *\n     * @private\n     */\n    onreconnect() {\n        const attempt = this.backoff.attempts;\n        this._reconnecting = false;\n        this.backoff.reset();\n        this.emitReserved(\"reconnect\", attempt);\n    }\n}\nexports.Manager = Manager;\n"]},"metadata":{},"sourceType":"script"}