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 23 forks source link

Error: connect ECONNREFUSED on the websocket connect function #57

Closed Sididi closed 2 years ago

Sididi commented 2 years ago

Hello, when using league-connect I systematically receive an Error: connect ECONNREFUSED 127.0.0.1:62036 It seems to happen on the connect() function when League of Legends is launched for the first time after the script is executed (meanwhile it waits on the authenticate function call)


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

var credentials = await authenticate({awaitConnection: true});
var client = await new LeagueClient(credentials);
var ws = await connect(credentials);

ws.on('message', message => {
    console.log(message.data.uri);
})

client.on('connect', (newCredentials) => {
    console.log('new credentials:\r\n');
    console.log(newCredentials);
})

client.on('disconnect', () => {
    console.log(client);
    console.log('it has disconnected\r\n');
})

client.start();```
junlarsen commented 2 years ago

Hello there, sorry for the late reply!

I belive this is the same websocket issue that occurs in #56 where the WebSocket connection is not opened immediately after the client process has been detected. Until I have time to implement a fix, you can use a tiny setTimeout/interval for a second or two after the client has been detected.

Sididi commented 2 years ago

Alright, thank you for the reply 👍

junlarsen commented 2 years ago

Closing as duplicate of #56