{"ast":null,"code":"\"use strict\";\n\nvar _classCallCheck = require(\"C:/laragon/www/iot.mksolusi/DriverOPCDA/frontend/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/classCallCheck\");\n\nvar _createClass = require(\"C:/laragon/www/iot.mksolusi/DriverOPCDA/frontend/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/createClass\");\n\nvar _inherits = require(\"C:/laragon/www/iot.mksolusi/DriverOPCDA/frontend/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/inherits\");\n\nvar _createSuper = require(\"C:/laragon/www/iot.mksolusi/DriverOPCDA/frontend/node_modules/babel-preset-react-app/node_modules/@babel/runtime/helpers/createSuper\");\n\nObject.defineProperty(exports, \"__esModule\", {\n  value: true\n});\nexports.Manager = void 0;\n\nvar eio = require(\"engine.io-client\");\n\nvar socket_1 = require(\"./socket\");\n\nvar parser = require(\"socket.io-parser\");\n\nvar on_1 = require(\"./on\");\n\nvar Backoff = require(\"backo2\");\n\nvar typed_events_1 = require(\"./typed-events\");\n\nvar debug = require(\"debug\")(\"socket.io-client:manager\");\n\nvar Manager = /*#__PURE__*/function (_typed_events_1$Stric) {\n  _inherits(Manager, _typed_events_1$Stric);\n\n  var _super = _createSuper(Manager);\n\n  function Manager(uri, opts) {\n    var _this;\n\n    _classCallCheck(this, Manager);\n\n    _this = _super.call(this);\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\n    _this.reconnection(opts.reconnection !== false);\n\n    _this.reconnectionAttempts(opts.reconnectionAttempts || Infinity);\n\n    _this.reconnectionDelay(opts.reconnectionDelay || 1000);\n\n    _this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000);\n\n    _this.randomizationFactor(opts.randomizationFactor || 0.5);\n\n    _this.backoff = new Backoff({\n      min: _this.reconnectionDelay(),\n      max: _this.reconnectionDelayMax(),\n      jitter: _this.randomizationFactor()\n    });\n\n    _this.timeout(null == opts.timeout ? 20000 : opts.timeout);\n\n    _this._readyState = \"closed\";\n    _this.uri = uri;\n\n    var _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    return _this;\n  }\n\n  _createClass(Manager, [{\n    key: \"reconnection\",\n    value: function reconnection(v) {\n      if (!arguments.length) return this._reconnection;\n      this._reconnection = !!v;\n      return this;\n    }\n  }, {\n    key: \"reconnectionAttempts\",\n    value: function reconnectionAttempts(v) {\n      if (v === undefined) return this._reconnectionAttempts;\n      this._reconnectionAttempts = v;\n      return this;\n    }\n  }, {\n    key: \"reconnectionDelay\",\n    value: function 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    key: \"randomizationFactor\",\n    value: function 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    key: \"reconnectionDelayMax\",\n    value: function 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    key: \"timeout\",\n    value: function 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    key: \"maybeReconnectOnOpen\",\n    value: function 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    key: \"open\",\n    value: function open(fn) {\n      var _this2 = this;\n\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      var socket = this.engine;\n      var self = this;\n      this._readyState = \"opening\";\n      this.skipReconnect = false; // emit `open`\n\n      var openSubDestroy = on_1.on(socket, \"open\", function () {\n        self.onopen();\n        fn && fn();\n      }); // emit `error`\n\n      var errorSub = on_1.on(socket, \"error\", function (err) {\n        debug(\"error\");\n        self.cleanup();\n        self._readyState = \"closed\";\n\n        _this2.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        var 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        var timer = setTimeout(function () {\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    key: \"connect\",\n    value: function connect(fn) {\n      return this.open(fn);\n    }\n    /**\n     * Called upon transport open.\n     *\n     * @private\n     */\n\n  }, {\n    key: \"onopen\",\n    value: function 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      var 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    key: \"onping\",\n    value: function onping() {\n      this.emitReserved(\"ping\");\n    }\n    /**\n     * Called with data.\n     *\n     * @private\n     */\n\n  }, {\n    key: \"ondata\",\n    value: function ondata(data) {\n      this.decoder.add(data);\n    }\n    /**\n     * Called when parser fully decodes a packet.\n     *\n     * @private\n     */\n\n  }, {\n    key: \"ondecoded\",\n    value: function ondecoded(packet) {\n      this.emitReserved(\"packet\", packet);\n    }\n    /**\n     * Called upon socket error.\n     *\n     * @private\n     */\n\n  }, {\n    key: \"onerror\",\n    value: function 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    key: \"socket\",\n    value: function socket(nsp, opts) {\n      var 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    key: \"_destroy\",\n    value: function _destroy(socket) {\n      var nsps = Object.keys(this.nsps);\n\n      for (var _i = 0, _nsps = nsps; _i < _nsps.length; _i++) {\n        var nsp = _nsps[_i];\n        var _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    key: \"_packet\",\n    value: function _packet(packet) {\n      debug(\"writing packet %j\", packet);\n      var encodedPackets = this.encoder.encode(packet);\n\n      for (var 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    key: \"cleanup\",\n    value: function cleanup() {\n      debug(\"cleanup\");\n      this.subs.forEach(function (subDestroy) {\n        return subDestroy();\n      });\n      this.subs.length = 0;\n      this.decoder.destroy();\n    }\n    /**\n     * Close the current socket.\n     *\n     * @private\n     */\n\n  }, {\n    key: \"_close\",\n    value: function _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    key: \"disconnect\",\n    value: function disconnect() {\n      return this._close();\n    }\n    /**\n     * Called upon engine close.\n     *\n     * @private\n     */\n\n  }, {\n    key: \"onclose\",\n    value: function 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    key: \"reconnect\",\n    value: function reconnect() {\n      var _this3 = this;\n\n      if (this._reconnecting || this.skipReconnect) return this;\n      var 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        var delay = this.backoff.duration();\n        debug(\"will wait %dms before reconnect attempt\", delay);\n        this._reconnecting = true;\n        var timer = setTimeout(function () {\n          if (self.skipReconnect) return;\n          debug(\"attempting reconnect\");\n\n          _this3.emitReserved(\"reconnect_attempt\", self.backoff.attempts); // check again for the case socket closed in above events\n\n\n          if (self.skipReconnect) return;\n          self.open(function (err) {\n            if (err) {\n              debug(\"reconnect attempt error\");\n              self._reconnecting = false;\n              self.reconnect();\n\n              _this3.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    key: \"onreconnect\",\n    value: function onreconnect() {\n      var attempt = this.backoff.attempts;\n      this._reconnecting = false;\n      this.backoff.reset();\n      this.emitReserved(\"reconnect\", attempt);\n    }\n  }]);\n\n  return Manager;\n}(typed_events_1.StrictEventEmitter);\n\nexports.Manager = Manager;","map":{"version":3,"sources":["C:/laragon/www/iot.mksolusi/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","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","_reconnecting","attempts","reconnect","fn","indexOf","engine","socket","self","skipReconnect","openSubDestroy","on","onopen","errorSub","err","cleanup","emitReserved","maybeReconnectOnOpen","timer","setTimeout","close","emit","Error","autoUnref","unref","push","subDestroy","clearTimeout","onping","bind","ondata","onerror","onclose","ondecoded","data","add","packet","nsp","Socket","keys","active","_close","encodedPackets","encode","i","write","options","forEach","destroy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AlB,EAAuCR,IAAI,CAAClC,OAAL,CAAa4B,QAApD,EAJ2B,CAK3B;;;AACA,cAAIM,IAAI,CAACC,aAAT,EACI;AACJD,UAAAA,IAAI,CAACrB,IAAL,CAAU,UAAC2B,GAAD,EAAS;AACf,gBAAIA,GAAJ,EAAS;AACLrD,cAAAA,KAAK,CAAC,yBAAD,CAAL;AACA+C,cAAAA,IAAI,CAACP,aAAL,GAAqB,KAArB;AACAO,cAAAA,IAAI,CAACL,SAAL;;AACA,cAAA,MAAI,CAACa,YAAL,CAAkB,iBAAlB,EAAqCF,GAArC;AACH,aALD,MAMK;AACDrD,cAAAA,KAAK,CAAC,mBAAD,CAAL;AACA+C,cAAAA,IAAI,CAAC6C,WAAL;AACH;AACJ,WAXD;AAYH,SApBuB,EAoBrBF,KApBqB,CAAxB;;AAqBA,YAAI,KAAKxF,IAAL,CAAU4D,SAAd,EAAyB;AACrBL,UAAAA,KAAK,CAACM,KAAN;AACH;;AACD,aAAK3D,IAAL,CAAU4D,IAAV,CAAe,SAASC,UAAT,GAAsB;AACjCC,UAAAA,YAAY,CAACT,KAAD,CAAZ;AACH,SAFD;AAGH;AACJ;AACD;AACJ;AACA;AACA;AACA;;;;WACI,uBAAc;AACV,UAAMoC,OAAO,GAAG,KAAKhF,OAAL,CAAa4B,QAA7B;AACA,WAAKD,aAAL,GAAqB,KAArB;AACA,WAAK3B,OAAL,CAAa2E,KAAb;AACA,WAAKjC,YAAL,CAAkB,WAAlB,EAA+BsC,OAA/B;AACH;;;;EA1WiB9F,cAAc,CAAC+F,kB;;AA4WrCxG,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"}