junlarsen / league-connect

:electric_plug: Node.js HTTP/1.1, HTTP/2.0 and WebSocket interface to the League of Legends Client APIs
https://www.npmjs.com/package/league-connect
MIT License
156 stars 24 forks source link

Error: connect ECONNREFUSED 127.0.0.1:61037 #89

Closed Sididi closed 1 year ago

Sididi commented 2 years ago

Hello, I keep getting ECONNREFUSED errors since the new release each time I open LeagueClient, even when trying a code as simple as that

import { createWebSocketConnection, authenticate } from 'league-connect'

const credentials = await authenticate({
  awaitConnection: true
})
const ws = await createWebSocketConnection(credentials)

Do you have any idea where it comes from?

Stack trace (doesn't really give useful infos though)

      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:61037
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)
Emitted 'error' event on LeagueWebSocket instance at:
    at emitErrorAndClose (C:\Users\My_Si\Desktop\league predictions\node_modules\ws\lib\websocket.js:1002:13)
    at ClientRequest.<anonymous> (C:\Users\My_Si\Desktop\league predictions\node_modules\ws\lib\websocket.js:854:5)
    at ClientRequest.emit (node:events:527:28)
    at TLSSocket.socketErrorListener (node:_http_client:454:9)
    at TLSSocket.emit (node:events:527:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 61037
}
junlarsen commented 2 years ago

The createWebSocketConnection function doesn't take the credentials, it takes the following object https://github.com/matsjla/league-connect/blob/master/src/websocket.ts#L71

I suppose we should do some checks on the incoming value to make it "safer". Try with the object in that link and let me know if it still does not work

Sididi commented 2 years ago

Maybe update this part of the README image

By the way I have tried what you said and still got the same error 🙏

import { createWebSocketConnection, LeagueClient, authenticate } from 'league-connect'

const ws = await createWebSocketConnection({
  authenticationOptions: {
    awaitConnection: true,
  }
})

Running on Node 16.16.0, literally no other line of code, happens as soon as I loggin in League of Legends

junlarsen commented 2 years ago

Yeah, I'll update the readme and investigate - thanks for the update

junlarsen commented 2 years ago

Yup, I'm able to reproduce. I'll try to find a fix

ChronoBrake commented 2 years ago

any fix ETA?

ChronoBrake commented 2 years ago

Hey, maybe it's will little help. It's seems to be problem with too quickly trying to connect to websocket when League client not open websocket.

tested code working fine:

    const credentials = await authenticate({
        awaitConnection: true,
        pollInterval: 15000
    })
    const client = new LeagueClient(credentials);
    wait(15000);
    localws = await createWebSocketConnection(credentials)

tested code with that error without delay before connect to websocket:

    const credentials = await authenticate({
        awaitConnection: true,
        pollInterval: 15000
    })
    const client = new LeagueClient(credentials);
       //missing delay
    localws = await createWebSocketConnection(credentials)
junlarsen commented 2 years ago

Yeah I think it's https://github.com/matsjla/league-connect/issues/56 again, maybe I didn't fix it properly

ChronoBrake commented 1 year ago

Yeah I think it's #56 again, maybe I didn't fix it properly

So you know how to fix it?

junlarsen commented 1 year ago

Well, I thought I knew

junlarsen commented 1 year ago

Should be resolved now. Please re-open or create another issue if the issue persists!