{"ast":null,"code":"/* global attachEvent */\nconst XMLHttpRequest = require(\"../../contrib/xmlhttprequest-ssl/XMLHttpRequest\");\n\nconst Polling = require(\"./polling\");\n\nconst Emitter = require(\"component-emitter\");\n\nconst {\n  pick\n} = require(\"../util\");\n\nconst globalThis = require(\"../globalThis\");\n\nconst debug = require(\"debug\")(\"engine.io-client:polling-xhr\");\n/**\n * Empty function\n */\n\n\nfunction empty() {}\n\nconst hasXHR2 = function () {\n  const xhr = new XMLHttpRequest({\n    xdomain: false\n  });\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; // 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    const forceBase64 = opts && opts.forceBase64;\n    this.supportsBinary = hasXHR2 && !forceBase64;\n  }\n  /**\n   * Creates a request.\n   *\n   * @param {String} method\n   * @api private\n   */\n\n\n  request(opts = {}) {\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  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   * Starts a poll cycle.\n   *\n   * @api private\n   */\n\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}\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    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    this.create();\n  }\n  /**\n   * Creates the XHR object and sends the request.\n   *\n   * @api private\n   */\n\n\n  create() {\n    const 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    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\n      try {\n        if (this.opts.extraHeaders) {\n          xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);\n\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) {} // 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  onSuccess() {\n    this.emit(\"success\");\n    this.cleanup();\n  }\n  /**\n   * Called if we have data.\n   *\n   * @api private\n   */\n\n\n  onData(data) {\n    this.emit(\"data\", data);\n    this.onSuccess();\n  }\n  /**\n   * Called upon error.\n   *\n   * @api private\n   */\n\n\n  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  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  onLoad() {\n    const 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  hasXDR() {\n    return typeof XDomainRequest !== \"undefined\" && !this.xs && this.enablesXDR;\n  }\n  /**\n   * Aborts the request.\n   *\n   * @api public\n   */\n\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\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;","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","constructor","opts","location","isSSL","protocol","port","xd","hostname","xs","secure","forceBase64","supportsBinary","request","Object","assign","Request","uri","doWrite","data","fn","req","method","self","on","err","onError","doPoll","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","onSuccess","emit","cleanup","fromError","abort","XDomainRequest","enablesXDR","attachEvent","unloadHandler","addEventListener","terminationEvent","module","exports"],"mappings":"AAAA;AAEA,MAAMA,cAAc,GAAGC,OAAO,CAAC,iDAAD,CAA9B;;AACA,MAAMC,OAAO,GAAGD,OAAO,CAAC,WAAD,CAAvB;;AACA,MAAME,OAAO,GAAGF,OAAO,CAAC,mBAAD,CAAvB;;AACA,MA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3B,EAAuC;AACrCA,IAAAA,WAAW,CAAC,UAAD,EAAaC,aAAb,CAAX;AACD,GAFD,MAEO,IAAI,OAAOC,gBAAP,KAA4B,UAAhC,EAA4C;AACjD,UAAMC,gBAAgB,GAAG,gBAAgB3E,UAAhB,GAA6B,UAA7B,GAA0C,QAAnE;AACA0E,IAAAA,gBAAgB,CAACC,gBAAD,EAAmBF,aAAnB,EAAkC,KAAlC,CAAhB;AACD;AACF;;AAED,SAASA,aAAT,GAAyB;AACvB,OAAK,IAAI7B,CAAT,IAAcrB,OAAO,CAACyC,QAAtB,EAAgC;AAC9B,QAAIzC,OAAO,CAACyC,QAAR,CAAiBnB,cAAjB,CAAgCD,CAAhC,CAAJ,EAAwC;AACtCrB,MAAAA,OAAO,CAACyC,QAAR,CAAiBpB,CAAjB,EAAoByB,KAApB;AACD;AACF;AACF;;AAEDO,MAAM,CAACC,OAAP,GAAiBtE,GAAjB;AACAqE,MAAM,CAACC,OAAP,CAAetD,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"}