gigobyte / HLTV

The unofficial HLTV Node.js API
MIT License
397 stars 107 forks source link

connectToScorebot doesn't reach onConnect() event #390

Closed OfficialLahusa closed 3 years ago

OfficialLahusa commented 3 years ago
app.get('/scoreboard/', async (req, res) => {
  var scoreboard = await HLTV2.connectToScorebot({id: 2346334, onScoreboardUpdate: (data, done) => {
    console.log(data)
    console.log("onScoreboardUpdate received")
    }, onLogUpdate: (data, done, ) => {
      console.log(data)
      console.log("onLogUpdate received")
    }, onConnect: (data, done, ) => {
      console.log(data)
      console.log("onConnect received")
    }, onDisconnect: (data, done, ) => {
      console.log(data)
      console.log("onDisconnect received")
    }
  })
  console.log(scoreboard)
  res.json(scoreboard)
  console.log("scoreboard logged")
})

Using an ID of a currently running Match on HLTV doesn't give any return value and doesn't fire any of the listed events.

gigobyte commented 3 years ago

Which version are you using? Just tried it and it works on the newest version - 2.23.0. image

OfficialLahusa commented 3 years ago

We use version 2.23.0

OfficialLahusa commented 3 years ago

Update: When I run the function on the node server I get the following exception:

/home/zsunamy/devel-hltv-api/node_modules/hltv/lib/endpoints/connectToScorebot.js:11
            .split(',')
            ^

TypeError: Cannot read property 'split' of undefined
    at /home/zsunamy/devel-hltv-api/node_modules/hltv/lib/endpoints/connectToScorebot.js:11:13
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
gigobyte commented 3 years ago

You are probably being rate limited. This is not related to the library. Wait for 30-60 minutes and try again, but don't spam requests as you'll get the same result.

Revilum commented 3 years ago

Hi, I have the same issue. The only thing I can add is that the index.ts in the github release is different than the index.js and index.d.ts in the npm release. Is there a way to use the github release instead of the npm release or has the code a mistake outside of the scoreBot? my code:

app.get('/scoreboard/', async (req, res) => {
  HLTV2.connectToScorebot({id: 2346468, onScoreboardUpdate: (data, done) => {
    console.log(data)
    console.log("onScoreboardUpdate received")
    }, onLogUpdate: (data, done, ) => {
      console.log("onLogUpdate received")
      console.dir(data)
    }, onConnect: (data, done, ) => {
      console.log("onConnect received")
      console.dir(data)
    }, onDisconnect: (data, done, ) => {
      console.log("onDisconnect received")
      console.dir(data)
    }
  })

the code should be triggered when I visit localhost/scoreboard

gigobyte commented 3 years ago

I'm sorry guys, the issue is definitely on your side. Try deleting node_modules and running install again, you're probably on an old version. I can confirm that the latest release contains the code in master. Here is my package.json:

"dependencies": {
    "hltv": "^2.23.0"
  }

package-lock.json

"hltv": {
      "version": "2.23.0",
      "resolved": "https://registry.npmjs.org/hltv/-/hltv-2.23.0.tgz",
      "integrity": "sha512-FPtnBeEP8VrN+aFBP+wmuqmuVdAsDnPk9OAC1zJSCAU3xpscrgbc3gPd3Cogv6052BsNYF1dtlLBwM43raZUsQ==",
      "requires": {
        "cheerio": "^1.0.0-rc.2",
        "request": "^2.88.0",
        "socket.io-client": "2.4.0",
        "uuid": "^8.3.2"
      }
    },

I also made a folder with only hltv installed and it worked: image

Revilum commented 3 years ago

thanks for your answer. I was able to fix it by downgrading nodejs to v12. the log was empty when using v15. I hope that's also your issue @OfficialLahusa

Thanks again for your support and fast answers!

OfficialLahusa commented 3 years ago

Downgrading node.js did infact fix the issue, thanks to both of you!

gigobyte commented 3 years ago

For anyone else reading this issue, I'm using node 15.2.1 and it still works.

Revilum commented 3 years ago

interesting node v15 didn't work for me. Maybe it's because se I'm running the api with the linux version of node.