{"ast":null,"code":"const Transport = require(\"../transport\");\n\nconst parseqs = require(\"parseqs\");\n\nconst parser = require(\"engine.io-parser\");\n\nconst yeast = require(\"yeast\");\n\nconst debug = require(\"debug\")(\"engine.io-client:polling\");\n\nclass Polling extends Transport {\n  /**\n   * Transport name.\n   */\n  get name() {\n    return \"polling\";\n  }\n  /**\n   * Opens the socket (triggers polling). We write a PING message to determine\n   * when the transport is open.\n   *\n   * @api private\n   */\n\n\n  doOpen() {\n    this.poll();\n  }\n  /**\n   * Pauses polling.\n   *\n   * @param {Function} callback upon buffers are flushed and transport is paused\n   * @api private\n   */\n\n\n  pause(onPause) {\n    const self = this;\n    this.readyState = \"pausing\";\n\n    function pause() {\n      debug(\"paused\");\n      self.readyState = \"paused\";\n      onPause();\n    }\n\n    if (this.polling || !this.writable) {\n      let total = 0;\n\n      if (this.polling) {\n        debug(\"we are currently polling - waiting to pause\");\n        total++;\n        this.once(\"pollComplete\", function () {\n          debug(\"pre-pause polling complete\");\n          --total || pause();\n        });\n      }\n\n      if (!this.writable) {\n        debug(\"we are currently writing - waiting to pause\");\n        total++;\n        this.once(\"drain\", function () {\n          debug(\"pre-pause writing complete\");\n          --total || pause();\n        });\n      }\n    } else {\n      pause();\n    }\n  }\n  /**\n   * Starts polling cycle.\n   *\n   * @api public\n   */\n\n\n  poll() {\n    debug(\"polling\");\n    this.polling = true;\n    this.doPoll();\n    this.emit(\"poll\");\n  }\n  /**\n   * Overloads onData to detect payloads.\n   *\n   * @api private\n   */\n\n\n  onData(data) {\n    const self = this;\n    debug(\"polling got data %s\", data);\n\n    const callback = function (packet, index, total) {\n      // if its the first message we consider the transport open\n      if (\"opening\" === self.readyState && packet.type === \"open\") {\n        self.onOpen();\n      } // if its a close packet, we close the ongoing requests\n\n\n      if (\"close\" === packet.type) {\n        self.onClose();\n        return false;\n      } // otherwise bypass onData and handle the message\n\n\n      self.onPacket(packet);\n    }; // decode payload\n\n\n    parser.decodePayload(data, this.socket.binaryType).forEach(callback); // if an event did not trigger closing\n\n    if (\"closed\" !== this.readyState) {\n      // if we got data we're not polling\n      this.polling = false;\n      this.emit(\"pollComplete\");\n\n      if (\"open\" === this.readyState) {\n        this.poll();\n      } else {\n        debug('ignoring poll - transport state \"%s\"', this.readyState);\n      }\n    }\n  }\n  /**\n   * For polling, send a close packet.\n   *\n   * @api private\n   */\n\n\n  doClose() {\n    const self = this;\n\n    function close() {\n      debug(\"writing close packet\");\n      self.write([{\n        type: \"close\"\n      }]);\n    }\n\n    if (\"open\" === this.readyState) {\n      debug(\"transport open - closing\");\n      close();\n    } else {\n      // in case we're trying to close while\n      // handshaking is in progress (GH-164)\n      debug(\"transport not open - deferring close\");\n      this.once(\"open\", close);\n    }\n  }\n  /**\n   * Writes a packets payload.\n   *\n   * @param {Array} data packets\n   * @param {Function} drain callback\n   * @api private\n   */\n\n\n  write(packets) {\n    this.writable = false;\n    parser.encodePayload(packets, data => {\n      this.doWrite(data, () => {\n        this.writable = true;\n        this.emit(\"drain\");\n      });\n    });\n  }\n  /**\n   * Generates uri for connection.\n   *\n   * @api private\n   */\n\n\n  uri() {\n    let query = this.query || {};\n    const schema = this.opts.secure ? \"https\" : \"http\";\n    let port = \"\"; // cache busting is forced\n\n    if (false !== this.opts.timestampRequests) {\n      query[this.opts.timestampParam] = yeast();\n    }\n\n    if (!this.supportsBinary && !query.sid) {\n      query.b64 = 1;\n    }\n\n    query = parseqs.encode(query); // avoid port if default for schema\n\n    if (this.opts.port && (\"https\" === schema && Number(this.opts.port) !== 443 || \"http\" === schema && Number(this.opts.port) !== 80)) {\n      port = \":\" + this.opts.port;\n    } // prepend ? to query\n\n\n    if (query.length) {\n      query = \"?\" + query;\n    }\n\n    const ipv6 = this.opts.hostname.indexOf(\":\") !== -1;\n    return schema + \"://\" + (ipv6 ? \"[\" + this.opts.hostname + \"]\" : this.opts.hostname) + port + this.opts.path + query;\n  }\n\n}\n\nmodule.exports = Polling;","map":{"version":3,"sources":["C:/laragon/www/iot.mksolusi/DriverOPCDA/frontend/node_modules/engine.io-client/lib/transports/polling.js"],"names":["Transport","require","parseqs","parser","yeast","debug","Polling","name","doOpen","poll","pause","onPause","self","readyState","polling","writable","total","once","doPoll","emit","onData","data","callback","packet","index","type","onOpen","onClose","onPacket","decodePayload","socket","binaryType","forEach","doClose","close","write","packets","encodePayload","doWrite","uri","query","schema","opts","secure","port","timestampRequests","timestampParam","supportsBinary","sid","b64","encode","Number","length","ipv6","hostname","indexOf","path","module","exports"],"mappings":"AAAA,MAAMA,SAAS,GAAGC,OAAO,CAAC,cAAD,CAAzB;;AACA,MAAMC,OAAO,GAAGD,OAAO,CAAC,SAAD,CAAvB;;AACA,MAAME,MAAM,GAAGF,OAAO,CAAC,kBAAD,CAAtB;;AACA,MAAMG,KAAK,GAAGH,OAAO,CAAC,OAAD,CAArB;;AAEA,MAAMI,KAAK,GAAGJ,OAAO,CAAC,OAAD,CAAP,CAAiB,0BAAjB,CAAd;;AAEA,MAAMK,OAAN,SAAsBN,SAAtB,CAAgC;AAC9B;AACF;AACA;AACU,MAAJO,IAAI,GAAG;AACT,WAAO,SAAP;AACD;AAED;AACF;AACA;AACA;AACA;AACA;;;AACEC,EAAAA,MAAM,GAAG;AACP,SAAKC,IAAL;AACD;AAED;AACF;AACA;AACA;AACA;AACA;;;AACEC,EAAAA,KAAK,CAACC,OAAD,EAAU;AACb,UAAMC,IAAI,GAAG,IAAb;AAEA,SAAKC,UAAL,GAAkB,SAAlB;;AAEA,aAASH,KAAT,GAAiB;AACfL,MAAAA,KAAK,CAAC,QAAD,CAAL;AACAO,MAAAA,IAAI,CAACC,UAAL,GAAkB,QAAlB;AACAF,MAAAA,OAAO;AACR;;AAED,QAAI,KAAKG,OAAL,IAAgB,CAAC,KAAKC,QAA1B,EAAoC;AAClC,UAAIC,KAAK,GAAG,CAAZ;;AAEA,UAAI,KAAKF,OAAT,EAAkB;AAChBT,QAAAA,KAAK,CAAC,6CAAD,CAAL;AACAW,QAAAA,KAAK;AACL,aAAKC,IAA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C,MAAV,GAAmB,OAAnB,GAA6B,MAA5C;AACA,QAAIC,IAAI,GAAG,EAAX,CAHI,CAKJ;;AACA,QAAI,UAAU,KAAKF,IAAL,CAAUG,iBAAxB,EAA2C;AACzCL,MAAAA,KAAK,CAAC,KAAKE,IAAL,CAAUI,cAAX,CAAL,GAAkC1C,KAAK,EAAvC;AACD;;AAED,QAAI,CAAC,KAAK2C,cAAN,IAAwB,CAACP,KAAK,CAACQ,GAAnC,EAAwC;AACtCR,MAAAA,KAAK,CAACS,GAAN,GAAY,CAAZ;AACD;;AAEDT,IAAAA,KAAK,GAAGtC,OAAO,CAACgD,MAAR,CAAeV,KAAf,CAAR,CAdI,CAgBJ;;AACA,QACE,KAAKE,IAAL,CAAUE,IAAV,KACE,YAAYH,MAAZ,IAAsBU,MAAM,CAAC,KAAKT,IAAL,CAAUE,IAAX,CAAN,KAA2B,GAAlD,IACE,WAAWH,MAAX,IAAqBU,MAAM,CAAC,KAAKT,IAAL,CAAUE,IAAX,CAAN,KAA2B,EAFnD,CADF,EAIE;AACAA,MAAAA,IAAI,GAAG,MAAM,KAAKF,IAAL,CAAUE,IAAvB;AACD,KAvBG,CAyBJ;;;AACA,QAAIJ,KAAK,CAACY,MAAV,EAAkB;AAChBZ,MAAAA,KAAK,GAAG,MAAMA,KAAd;AACD;;AAED,UAAMa,IAAI,GAAG,KAAKX,IAAL,CAAUY,QAAV,CAAmBC,OAAnB,CAA2B,GAA3B,MAAoC,CAAC,CAAlD;AACA,WACEd,MAAM,GACN,KADA,IAECY,IAAI,GAAG,MAAM,KAAKX,IAAL,CAAUY,QAAhB,GAA2B,GAA9B,GAAoC,KAAKZ,IAAL,CAAUY,QAFnD,IAGAV,IAHA,GAIA,KAAKF,IAAL,CAAUc,IAJV,GAKAhB,KANF;AAQD;;AAvM6B;;AA0MhCiB,MAAM,CAACC,OAAP,GAAiBpD,OAAjB","sourcesContent":["const Transport = require(\"../transport\");\nconst parseqs = require(\"parseqs\");\nconst parser = require(\"engine.io-parser\");\nconst yeast = require(\"yeast\");\n\nconst debug = require(\"debug\")(\"engine.io-client:polling\");\n\nclass Polling extends Transport {\n  /**\n   * Transport name.\n   */\n  get name() {\n    return \"polling\";\n  }\n\n  /**\n   * Opens the socket (triggers polling). We write a PING message to determine\n   * when the transport is open.\n   *\n   * @api private\n   */\n  doOpen() {\n    this.poll();\n  }\n\n  /**\n   * Pauses polling.\n   *\n   * @param {Function} callback upon buffers are flushed and transport is paused\n   * @api private\n   */\n  pause(onPause) {\n    const self = this;\n\n    this.readyState = \"pausing\";\n\n    function pause() {\n      debug(\"paused\");\n      self.readyState = \"paused\";\n      onPause();\n    }\n\n    if (this.polling || !this.writable) {\n      let total = 0;\n\n      if (this.polling) {\n        debug(\"we are currently polling - waiting to pause\");\n        total++;\n        this.once(\"pollComplete\", function() {\n          debug(\"pre-pause polling complete\");\n          --total || pause();\n        });\n      }\n\n      if (!this.writable) {\n        debug(\"we are currently writing - waiting to pause\");\n        total++;\n        this.once(\"drain\", function() {\n          debug(\"pre-pause writing complete\");\n          --total || pause();\n        });\n      }\n    } else {\n      pause();\n    }\n  }\n\n  /**\n   * Starts polling cycle.\n   *\n   * @api public\n   */\n  poll() {\n    debug(\"polling\");\n    this.polling = true;\n    this.doPoll();\n    this.emit(\"poll\");\n  }\n\n  /**\n   * Overloads onData to detect payloads.\n   *\n   * @api private\n   */\n  onData(data) {\n    const self = this;\n    debug(\"polling got data %s\", data);\n    const callback = function(packet, index, total) {\n      // if its the first message we consider the transport open\n      if (\"opening\" === self.readyState && packet.type === \"open\") {\n        self.onOpen();\n      }\n\n      // if its a close packet, we close the ongoing requests\n      if (\"close\" === packet.type) {\n        self.onClose();\n        return false;\n      }\n\n      // otherwise bypass onData and handle the message\n      self.onPacket(packet);\n    };\n\n    // decode payload\n    parser.decodePayload(data, this.socket.binaryType).forEach(callback);\n\n    // if an event did not trigger closing\n    if (\"closed\" !== this.readyState) {\n      // if we got data we're not polling\n      this.polling = false;\n      this.emit(\"pollComplete\");\n\n      if (\"open\" === this.readyState) {\n        this.poll();\n      } else {\n        debug('ignoring poll - transport state \"%s\"', this.readyState);\n      }\n    }\n  }\n\n  /**\n   * For polling, send a close packet.\n   *\n   * @api private\n   */\n  doClose() {\n    const self = this;\n\n    function close() {\n      debug(\"writing close packet\");\n      self.write([{ type: \"close\" }]);\n    }\n\n    if (\"open\" === this.readyState) {\n      debug(\"transport open - closing\");\n      close();\n    } else {\n      // in case we're trying to close while\n      // handshaking is in progress (GH-164)\n      debug(\"transport not open - deferring close\");\n      this.once(\"open\", close);\n    }\n  }\n\n  /**\n   * Writes a packets payload.\n   *\n   * @param {Array} data packets\n   * @param {Function} drain callback\n   * @api private\n   */\n  write(packets) {\n    this.writable = false;\n\n    parser.encodePayload(packets, data => {\n      this.doWrite(data, () => {\n        this.writable = true;\n        this.emit(\"drain\");\n      });\n    });\n  }\n\n  /**\n   * Generates uri for connection.\n   *\n   * @api private\n   */\n  uri() {\n    let query = this.query || {};\n    const schema = this.opts.secure ? \"https\" : \"http\";\n    let port = \"\";\n\n    // cache busting is forced\n    if (false !== this.opts.timestampRequests) {\n      query[this.opts.timestampParam] = yeast();\n    }\n\n    if (!this.supportsBinary && !query.sid) {\n      query.b64 = 1;\n    }\n\n    query = parseqs.encode(query);\n\n    // avoid port if default for schema\n    if (\n      this.opts.port &&\n      ((\"https\" === schema && Number(this.opts.port) !== 443) ||\n        (\"http\" === schema && Number(this.opts.port) !== 80))\n    ) {\n      port = \":\" + this.opts.port;\n    }\n\n    // prepend ? to query\n    if (query.length) {\n      query = \"?\" + query;\n    }\n\n    const ipv6 = this.opts.hostname.indexOf(\":\") !== -1;\n    return (\n      schema +\n      \"://\" +\n      (ipv6 ? \"[\" + this.opts.hostname + \"]\" : this.opts.hostname) +\n      port +\n      this.opts.path +\n      query\n    );\n  }\n}\n\nmodule.exports = Polling;\n"]},"metadata":{},"sourceType":"script"}