{"ast":null,"code":"var _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\n/* global attachEvent */\nvar XMLHttpRequest = require(\"../../contrib/xmlhttprequest-ssl/XMLHttpRequest\");\n\nvar Polling = require(\"./polling\");\n\nvar Emitter = require(\"component-emitter\");\n\nvar _require = require(\"../util\"),\n    pick = _require.pick;\n\nvar globalThis = require(\"../globalThis\");\n\nvar debug = require(\"debug\")(\"engine.io-client:polling-xhr\");\n/**\n * Empty function\n */\n\n\nfunction empty() {}\n\nvar hasXHR2 = function () {\n  var xhr = new XMLHttpRequest({\n    xdomain: false\n  });\n  return null != xhr.responseType;\n}();\n\nvar XHR = /*#__PURE__*/function (_Polling) {\n  \"use strict\";\n\n  _inherits(XHR, _Polling);\n\n  var _super = _createSuper(XHR);\n\n  /**\n   * XHR Polling constructor.\n   *\n   * @param {Object} opts\n   * @api public\n   */\n  function XHR(opts) {\n    var _this;\n\n    _classCallCheck(this, XHR);\n\n    _this = _super.call(this, opts);\n\n    if (typeof location !== \"undefined\") {\n      var isSSL = \"https:\" === location.protocol;\n      var port = location.port; // some user agents have empty `location.port`\n\n      if (!port) {\n        port = isSSL ? 443 : 80;\n      }\n\n      _this.xd = typeof location !== \"undefined\" && opts.hostname !== location.hostname || port !== opts.port;\n      _this.xs = opts.secure !== isSSL;\n    }\n    /**\n     * XHR supports binary\n     */\n\n\n    var forceBase64 = opts && opts.forceBase64;\n    _this.supportsBinary = hasXHR2 && !forceBase64;\n    return _this;\n  }\n  /**\n   * Creates a request.\n   *\n   * @param {String} method\n   * @api private\n   */\n\n\n  _createClass(XHR, [{\n    key: \"request\",\n    value: function request() {\n      var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n      Object.assign(opts, {\n        xd: this.xd,\n        xs: this.xs\n      }, this.opts);\n      return new Request(this.uri(), opts);\n    }\n    /**\n     * Sends data.\n     *\n     * @param {String} data to send.\n     * @param {Function} called upon flush.\n     * @api private\n     */\n\n  }, {\n    key: \"doWrite\",\n    value: function doWrite(data, fn) {\n      var req = this.request({\n        method: \"POST\",\n        data: data\n      });\n      var self = this;\n      req.on(\"success\", fn);\n      req.on(\"error\", function (err) {\n        self.onError(\"xhr post error\", err);\n      });\n    }\n    /**\n     * Starts a poll cycle.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"doPoll\",\n    value: function doPoll() {\n      debug(\"xhr poll\");\n      var req = this.request();\n      var self = this;\n      req.on(\"data\", function (data) {\n        self.onData(data);\n      });\n      req.on(\"error\", function (err) {\n        self.onError(\"xhr poll error\", err);\n      });\n      this.pollXhr = req;\n    }\n  }]);\n\n  return XHR;\n}(Polling);\n\nvar Request = /*#__PURE__*/function (_Emitter) {\n  \"use strict\";\n\n  _inherits(Request, _Emitter);\n\n  var _super2 = _createSuper(Request);\n\n  /**\n   * Request constructor\n   *\n   * @param {Object} options\n   * @api public\n   */\n  function Request(uri, opts) {\n    var _this2;\n\n    _classCallCheck(this, Request);\n\n    _this2 = _super2.call(this);\n    _this2.opts = opts;\n    _this2.method = opts.method || \"GET\";\n    _this2.uri = uri;\n    _this2.async = false !== opts.async;\n    _this2.data = undefined !== opts.data ? opts.data : null;\n\n    _this2.create();\n\n    return _this2;\n  }\n  /**\n   * Creates the XHR object and sends the request.\n   *\n   * @api private\n   */\n\n\n  _createClass(Request, [{\n    key: \"create\",\n    value: function create() {\n      var opts = pick(this.opts, \"agent\", \"enablesXDR\", \"pfx\", \"key\", \"passphrase\", \"cert\", \"ca\", \"ciphers\", \"rejectUnauthorized\", \"autoUnref\");\n      opts.xdomain = !!this.opts.xd;\n      opts.xscheme = !!this.opts.xs;\n      var xhr = this.xhr = new XMLHttpRequest(opts);\n      var self = this;\n\n      try {\n        debug(\"xhr open %s: %s\", this.method, this.uri);\n        xhr.open(this.method, this.uri, this.async);\n\n        try {\n          if (this.opts.extraHeaders) {\n            xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);\n\n            for (var i in this.opts.extraHeaders) {\n              if (this.opts.extraHeaders.hasOwnProperty(i)) {\n                xhr.setRequestHeader(i, this.opts.extraHeaders[i]);\n              }\n            }\n          }\n        } catch (e) {}\n\n        if (\"POST\" === this.method) {\n          try {\n            xhr.setRequestHeader(\"Content-type\", \"text/plain;charset=UTF-8\");\n          } catch (e) {}\n        }\n\n        try {\n          xhr.setRequestHeader(\"Accept\", \"*/*\");\n        } catch (e) {} // ie6 check\n\n\n        if (\"withCredentials\" in xhr) {\n          xhr.withCredentials = this.opts.withCredentials;\n        }\n\n        if (this.opts.requestTimeout) {\n          xhr.timeout = this.opts.requestTimeout;\n        }\n\n        if (this.hasXDR()) {\n          xhr.onload = function () {\n            self.onLoad();\n          };\n\n          xhr.onerror = function () {\n            self.onError(xhr.responseText);\n          };\n        } else {\n          xhr.onreadystatechange = function () {\n            if (4 !== xhr.readyState) return;\n\n            if (200 === xhr.status || 1223 === xhr.status) {\n              self.onLoad();\n            } else {\n              // make sure the `error` event handler that's user-set\n              // does not throw in the same tick and gets caught here\n              setTimeout(function () {\n                self.onError(typeof xhr.status === \"number\" ? xhr.status : 0);\n              }, 0);\n            }\n          };\n        }\n\n        debug(\"xhr data %s\", this.data);\n        xhr.send(this.data);\n      } catch (e) {\n        // Need to defer since .create() is called directly from the constructor\n        // and thus the 'error' event can only be only bound *after* this exception\n        // occurs.  Therefore, also, we cannot throw here at all.\n        setTimeout(function () {\n          self.onError(e);\n        }, 0);\n        return;\n      }\n\n      if (typeof document !== \"undefined\") {\n        this.index = Request.requestsCount++;\n        Request.requests[this.index] = this;\n      }\n    }\n    /**\n     * Called upon successful response.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"onSuccess\",\n    value: function onSuccess() {\n      this.emit(\"success\");\n      this.cleanup();\n    }\n    /**\n     * Called if we have data.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"onData\",\n    value: function onData(data) {\n      this.emit(\"data\", data);\n      this.onSuccess();\n    }\n    /**\n     * Called upon error.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"onError\",\n    value: function onError(err) {\n      this.emit(\"error\", err);\n      this.cleanup(true);\n    }\n    /**\n     * Cleans up house.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"cleanup\",\n    value: function cleanup(fromError) {\n      if (\"undefined\" === typeof this.xhr || null === this.xhr) {\n        return;\n      } // xmlhttprequest\n\n\n      if (this.hasXDR()) {\n        this.xhr.onload = this.xhr.onerror = empty;\n      } else {\n        this.xhr.onreadystatechange = empty;\n      }\n\n      if (fromError) {\n        try {\n          this.xhr.abort();\n        } catch (e) {}\n      }\n\n      if (typeof document !== \"undefined\") {\n        delete Request.requests[this.index];\n      }\n\n      this.xhr = null;\n    }\n    /**\n     * Called upon load.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"onLoad\",\n    value: function onLoad() {\n      var data = this.xhr.responseText;\n\n      if (data !== null) {\n        this.onData(data);\n      }\n    }\n    /**\n     * Check if it has XDomainRequest.\n     *\n     * @api private\n     */\n\n  }, {\n    key: \"hasXDR\",\n    value: function hasXDR() {\n      return typeof XDomainRequest !== \"undefined\" && !this.xs && this.enablesXDR;\n    }\n    /**\n     * Aborts the request.\n     *\n     * @api public\n     */\n\n  }, {\n    key: \"abort\",\n    value: function abort() {\n      this.cleanup();\n    }\n  }]);\n\n  return Request;\n}(Emitter);\n/**\n * Aborts pending requests when unloading the window. This is needed to prevent\n * memory leaks (e.g. when using IE) and to ensure that no spurious error is\n * emitted.\n */\n\n\nRequest.requestsCount = 0;\nRequest.requests = {};\n\nif (typeof document !== \"undefined\") {\n  if (typeof attachEvent === \"function\") {\n    attachEvent(\"onunload\", unloadHandler);\n  } else if (typeof addEventListener === \"function\") {\n    var terminationEvent = \"onpagehide\" in globalThis ? \"pagehide\" : \"unload\";\n    addEventListener(terminationEvent, unloadHandler, false);\n  }\n}\n\nfunction unloadHandler() {\n  for (var i in Request.requests) {\n    if (Request.requests.hasOwnProperty(i)) {\n      Request.requests[i].abort();\n    }\n  }\n}\n\nmodule.exports = XHR;\nmodule.exports.Request = Request;","map":{"version":3,"sources":["C:/laragon/www/iot.mksolusi/DriverOPCDA/frontend/node_modules/engine.io-client/lib/transports/polling-xhr.js"],"names":["XMLHttpRequest","require","Polling","Emitter","pick","globalThis","debug","empty","hasXHR2","xhr","xdomain","responseType","XHR","opts","location","isSSL","protocol","port","xd","hostname","xs","secure","forceBase64","supportsBinary","Object","assign","Request","uri","data","fn","req","request","method","self","on","err","onError","onData","pollXhr","async","undefined","create","xscheme","open","extraHeaders","setDisableHeaderCheck","i","hasOwnProperty","setRequestHeader","e","withCredentials","requestTimeout","timeout","hasXDR","onload","onLoad","onerror","responseText","onreadystatechange","readyState","status","setTimeout","send","document","index","requestsCount","requests","emit","cleanup","onSuccess","fromError","abort","XDomainRequest","enablesXDR","attachEvent","unloadHandler","addEventListener","terminationEvent","module","exports"],"mappings":";;;;;;;;AAAA;AAEA,IAAMA,cAAc,GAAGC,OAAO,CAAC,iDAAD,CAA9B;;AACA,IAAMC,OAAO,GAAGD,OAAO,CAAC,WAAD,CAAvB;;AACA,IAAME,OAAO,GAAGF,OAAO,CAAC,mBAAD,CAAvB;;eACiBA,OAAO,CAAC,SAAD,C;IAAhBG,I,YAAAA,I;;AACR,IAAMC,UAAU,GAAGJ,OAAO,CAAC,eAAD,CAA1B;;AAEA,IAAMK,KAAK,GAAGL,OAAO,CAAC,OAAD,CAAP,CAAiB,8BAAjB,CAAd;AAEA;AACA;A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OAAK,IAAI7B,CAAT,IAAcpB,OAAO,CAACwC,QAAtB,EAAgC;AAC9B,QAAIxC,OAAO,CAACwC,QAAR,CAAiBnB,cAAjB,CAAgCD,CAAhC,CAAJ,EAAwC;AACtCpB,MAAAA,OAAO,CAACwC,QAAR,CAAiBpB,CAAjB,EAAoByB,KAApB;AACD;AACF;AACF;;AAEDO,MAAM,CAACC,OAAP,GAAiBnE,GAAjB;AACAkE,MAAM,CAACC,OAAP,CAAerD,OAAf,GAAyBA,OAAzB","sourcesContent":["/* global attachEvent */\n\nconst XMLHttpRequest = require(\"../../contrib/xmlhttprequest-ssl/XMLHttpRequest\");\nconst Polling = require(\"./polling\");\nconst Emitter = require(\"component-emitter\");\nconst { pick } = require(\"../util\");\nconst globalThis = require(\"../globalThis\");\n\nconst debug = require(\"debug\")(\"engine.io-client:polling-xhr\");\n\n/**\n * Empty function\n */\n\nfunction empty() {}\n\nconst hasXHR2 = (function() {\n  const xhr = new XMLHttpRequest({ xdomain: false });\n  return null != xhr.responseType;\n})();\n\nclass XHR extends Polling {\n  /**\n   * XHR Polling constructor.\n   *\n   * @param {Object} opts\n   * @api public\n   */\n  constructor(opts) {\n    super(opts);\n\n    if (typeof location !== \"undefined\") {\n      const isSSL = \"https:\" === location.protocol;\n      let port = location.port;\n\n      // some user agents have empty `location.port`\n      if (!port) {\n        port = isSSL ? 443 : 80;\n      }\n\n      this.xd =\n        (typeof location !== \"undefined\" &&\n          opts.hostname !== location.hostname) ||\n        port !== opts.port;\n      this.xs = opts.secure !== isSSL;\n    }\n    /**\n     * XHR supports binary\n     */\n    const forceBase64 = opts && opts.forceBase64;\n    this.supportsBinary = hasXHR2 && !forceBase64;\n  }\n\n  /**\n   * Creates a request.\n   *\n   * @param {String} method\n   * @api private\n   */\n  request(opts = {}) {\n    Object.assign(opts, { xd: this.xd, xs: this.xs }, this.opts);\n    return new Request(this.uri(), opts);\n  }\n\n  /**\n   * Sends data.\n   *\n   * @param {String} data to send.\n   * @param {Function} called upon flush.\n   * @api private\n   */\n  doWrite(data, fn) {\n    const req = this.request({\n      method: \"POST\",\n      data: data\n    });\n    const self = this;\n    req.on(\"success\", fn);\n    req.on(\"error\", function(err) {\n      self.onError(\"xhr post error\", err);\n    });\n  }\n\n  /**\n   * Starts a poll cycle.\n   *\n   * @api private\n   */\n  doPoll() {\n    debug(\"xhr poll\");\n    const req = this.request();\n    const self = this;\n    req.on(\"data\", function(data) {\n      self.onData(data);\n    });\n    req.on(\"error\", function(err) {\n      self.onError(\"xhr poll error\", err);\n    });\n    this.pollXhr = req;\n  }\n}\n\nclass Request extends Emitter {\n  /**\n   * Request constructor\n   *\n   * @param {Object} options\n   * @api public\n   */\n  constructor(uri, opts) {\n    super();\n    this.opts = opts;\n\n    this.method = opts.method || \"GET\";\n    this.uri = uri;\n    this.async = false !== opts.async;\n    this.data = undefined !== opts.data ? opts.data : null;\n\n    this.create();\n  }\n\n  /**\n   * Creates the XHR object and sends the request.\n   *\n   * @api private\n   */\n  create() {\n    const opts = pick(\n      this.opts,\n      \"agent\",\n      \"enablesXDR\",\n      \"pfx\",\n      \"key\",\n      \"passphrase\",\n      \"cert\",\n      \"ca\",\n      \"ciphers\",\n      \"rejectUnauthorized\",\n      \"autoUnref\"\n    );\n    opts.xdomain = !!this.opts.xd;\n    opts.xscheme = !!this.opts.xs;\n\n    const xhr = (this.xhr = new XMLHttpRequest(opts));\n    const self = this;\n\n    try {\n      debug(\"xhr open %s: %s\", this.method, this.uri);\n      xhr.open(this.method, this.uri, this.async);\n      try {\n        if (this.opts.extraHeaders) {\n          xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);\n          for (let i in this.opts.extraHeaders) {\n            if (this.opts.extraHeaders.hasOwnProperty(i)) {\n              xhr.setRequestHeader(i, this.opts.extraHeaders[i]);\n            }\n          }\n        }\n      } catch (e) {}\n\n      if (\"POST\" === this.method) {\n        try {\n          xhr.setRequestHeader(\"Content-type\", \"text/plain;charset=UTF-8\");\n        } catch (e) {}\n      }\n\n      try {\n        xhr.setRequestHeader(\"Accept\", \"*/*\");\n      } catch (e) {}\n\n      // ie6 check\n      if (\"withCredentials\" in xhr) {\n        xhr.withCredentials = this.opts.withCredentials;\n      }\n\n      if (this.opts.requestTimeout) {\n        xhr.timeout = this.opts.requestTimeout;\n      }\n\n      if (this.hasXDR()) {\n        xhr.onload = function() {\n          self.onLoad();\n        };\n        xhr.onerror = function() {\n          self.onError(xhr.responseText);\n        };\n      } else {\n        xhr.onreadystatechange = function() {\n          if (4 !== xhr.readyState) return;\n          if (200 === xhr.status || 1223 === xhr.status) {\n            self.onLoad();\n          } else {\n            // make sure the `error` event handler that's user-set\n            // does not throw in the same tick and gets caught here\n            setTimeout(function() {\n              self.onError(typeof xhr.status === \"number\" ? xhr.status : 0);\n            }, 0);\n          }\n        };\n      }\n\n      debug(\"xhr data %s\", this.data);\n      xhr.send(this.data);\n    } catch (e) {\n      // Need to defer since .create() is called directly from the constructor\n      // and thus the 'error' event can only be only bound *after* this exception\n      // occurs.  Therefore, also, we cannot throw here at all.\n      setTimeout(function() {\n        self.onError(e);\n      }, 0);\n      return;\n    }\n\n    if (typeof document !== \"undefined\") {\n      this.index = Request.requestsCount++;\n      Request.requests[this.index] = this;\n    }\n  }\n\n  /**\n   * Called upon successful response.\n   *\n   * @api private\n   */\n  onSuccess() {\n    this.emit(\"success\");\n    this.cleanup();\n  }\n\n  /**\n   * Called if we have data.\n   *\n   * @api private\n   */\n  onData(data) {\n    this.emit(\"data\", data);\n    this.onSuccess();\n  }\n\n  /**\n   * Called upon error.\n   *\n   * @api private\n   */\n  onError(err) {\n    this.emit(\"error\", err);\n    this.cleanup(true);\n  }\n\n  /**\n   * Cleans up house.\n   *\n   * @api private\n   */\n  cleanup(fromError) {\n    if (\"undefined\" === typeof this.xhr || null === this.xhr) {\n      return;\n    }\n    // xmlhttprequest\n    if (this.hasXDR()) {\n      this.xhr.onload = this.xhr.onerror = empty;\n    } else {\n      this.xhr.onreadystatechange = empty;\n    }\n\n    if (fromError) {\n      try {\n        this.xhr.abort();\n      } catch (e) {}\n    }\n\n    if (typeof document !== \"undefined\") {\n      delete Request.requests[this.index];\n    }\n\n    this.xhr = null;\n  }\n\n  /**\n   * Called upon load.\n   *\n   * @api private\n   */\n  onLoad() {\n    const data = this.xhr.responseText;\n    if (data !== null) {\n      this.onData(data);\n    }\n  }\n\n  /**\n   * Check if it has XDomainRequest.\n   *\n   * @api private\n   */\n  hasXDR() {\n    return typeof XDomainRequest !== \"undefined\" && !this.xs && this.enablesXDR;\n  }\n\n  /**\n   * Aborts the request.\n   *\n   * @api public\n   */\n  abort() {\n    this.cleanup();\n  }\n}\n\n/**\n * Aborts pending requests when unloading the window. This is needed to prevent\n * memory leaks (e.g. when using IE) and to ensure that no spurious error is\n * emitted.\n */\n\nRequest.requestsCount = 0;\nRequest.requests = {};\n\nif (typeof document !== \"undefined\") {\n  if (typeof attachEvent === \"function\") {\n    attachEvent(\"onunload\", unloadHandler);\n  } else if (typeof addEventListener === \"function\") {\n    const terminationEvent = \"onpagehide\" in globalThis ? \"pagehide\" : \"unload\";\n    addEventListener(terminationEvent, unloadHandler, false);\n  }\n}\n\nfunction unloadHandler() {\n  for (let i in Request.requests) {\n    if (Request.requests.hasOwnProperty(i)) {\n      Request.requests[i].abort();\n    }\n  }\n}\n\nmodule.exports = XHR;\nmodule.exports.Request = Request;\n"]},"metadata":{},"sourceType":"script"}