PerformanC / NodeLink

Performant LavaLink alternative written with Node.Js
BSD 2-Clause "Simplified" License
38 stars 23 forks source link

[BUG]: Cannot play tracks, possible issue with initialising a voice connection. #13

Closed devoxin closed 8 months ago

devoxin commented 8 months ago

NodeLink version

1.15.0, cloned directly from the main branch.

Description

I can connect to the server, load tracks with it etc. I've connected to a voice channel but upon trying to play a track I receive an error.

devoxin@trinity:~/NodeLink/src/connection$ npm start

> start
> node src/connection/index.js

[websocket]: Listening on port 2333.
[innertube]: Fetching deciphering functions...
[spotify]: Fetching token...
[websocket]: Lavalink.py/5.2.0 client connected to NodeLink.
[spotify]: Successfully fetched token.
[innertube]: Successfully fetched deciphering functions.
[voice]: Received a request from client.
 Headers: {"host":"127.0.0.1:2333","authorization":"youshallnotpass","accept":"*/*","accept-encoding":"gzip, deflate","user-agent":"Python/3.11 aiohttp/3.8.6","content-length":"134","content-type":"application/json"}
 Body: {"voice":{"sessionId":"<hex string>","endpoint":"us-east9194.discord.media:443","token":"<hex string>"}}
file:///home/devoxin/NodeLink/node_modules/@performanc/voice/index.js:63
    this.ws.send(JSON.stringify({
            ^

TypeError: Cannot read properties of null (reading 'send')
    at Connection._setSpeaking (file:///home/devoxin/NodeLink/node_modules/@performanc/voice/index.js:63:13)
    at Connection.unpause (file:///home/devoxin/NodeLink/node_modules/@performanc/voice/index.js:374:10)
    at VoiceConnection.pause (file:///home/devoxin/NodeLink/src/connection/voiceHandler.js:406:23)
    at IncomingMessage.<anonymous> (file:///home/devoxin/NodeLink/src/connection/handler.js:787:18)
    at IncomingMessage.emit (node:events:514:28)
    at endReadableNT (node:internal/streams/readable:1376:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v20.5.1

Client

Lavalink.py 5.2.0

Steps to reproduce

Example code

N/A (Python)

Confirmations

Code of Conduct

ThePedroo commented 8 months ago

If possible, could you send an example so that I can reproduce it?

Although I will try with FastLink, our client, it may not reproduce it, as I never found this issue.

ThePedroo commented 8 months ago

This is weird. This would only happen if your client sent a pause request, which doesn't appear in the NodeLink logging.

Still, this is still an issue because it shouldn't try to pause while it's not even playing. I'll send the commit with the fix soon.

It's weird to see a LL collaborator trying out NodeLink. Thank you anyway, contributions to NodeLink are contributions to the Open Source world.

devoxin commented 8 months ago

If possible, could you send an example so that I can reproduce it?

Although I will try with FastLink, our client, it may not reproduce it, as I never found this issue.

Difficult to do so as the code is fairly abstract and split up. I don't really do anything specific that I feel would trigger it. I just connect via WS as I usually would, load a track by requesting the loadtracks endpoint, send a playerUpdate with a voice state, and then a second playerUpdate with a base64 track string.

devoxin commented 8 months ago

I've identified a slight issue in that my library was always sending startTime and paused values due to incorrect default parameters, when calling player.play(), regardless of whether the user specified them or not. Although I wouldn't have thought this should be the cause of the issues as the exception being thrown by NodeLink indicates there is no websocket connection to action on, which looks to be erroneous -- there should be a websocket connection

ThePedroo commented 8 months ago

NodeLink works a little differently than LavaLink internally. It will only create a websocket connection with Discord once a play is requested. Although it should never throw an error. This will be fixed soon anyway. Thanks.

ThePedroo commented 8 months ago

Could you try the fix/paused-crash branch?

devoxin commented 8 months ago

Could you try the fix/paused-crash branch?

This appears to have fixed the crashing but not the underlying problem of not having a websocket connection. Trying to play a track yields nothing; no audio, no errors, no logs.

Client logs:

[2023-12-21 20:27:42,255][lavalink.transport:125 - INFO ] [Node:nodelink] Establishing WebSocket connection to Lavalink...
[2023-12-21 20:27:42,266][lavalink.transport:160 - INFO ] [Node:nodelink] WebSocket connection established

NodeLink logs:

devoxin@trinity:~/NodeLink$ npm start

> start
> node src/connection/index.js

[websocket]: Listening on port 2333.
[innertube]: Fetching deciphering functions...
[spotify]: Fetching token...
[websocket]: Lavalink.py/5.2.0 client connected to NodeLink.
[voice]: Received a request from client.
 Headers: {"host":"127.0.0.1:2333","authorization":"youshallnotpass","accept":"*/*","accept-encoding":"gzip, deflate","user-agent":"Python/3.11 aiohttp/3.8.6","content-length":"134","content-type":"application/json"}
 Body: {"voice":{"sessionId":"8a6b9d7c2efaff90f8c114546764019e","endpoint":"us-east9194.discord.media:443","token":"72c0ffb72492b4b7"}}
[spotify]: Successfully fetched token.
[innertube]: Successfully fetched deciphering functions.
[loadtracks]: Received a request from client.
 Params: "?identifier=ytmsearch:ummet+ozcan+wonderful+days"
 Headers: {"host":"127.0.0.1:2333","authorization":"youshallnotpass","accept":"*/*","accept-encoding":"gzip, deflate","user-agent":"Python/3.11 aiohttp/3.8.6"}
[search]: Searching for ummet ozcan wonderful days on YouTube
[search]: Found 19 tracks on YouTube for query ummet ozcan wonderful days

I do not even receive a TrackStartEvent which should trigger my bot to display the currently playing song.

image

ThePedroo commented 8 months ago

According to the NodeLink logs, a play request was not done. Could you verify if your client is really sending a play request?

devoxin commented 8 months ago

image

ThePedroo commented 8 months ago

NodeLink logs?

devoxin commented 8 months ago

There are none. I've figured out the problem, anyway:

I'm PATCHing the player with buffer.track.encoded whereas NodeLink is looking for buffer.encodedTrack which has been deprecated. This needs changing to check buffer.track.{encoded, identifier} as per the Lavalink REST documentation if compatibility with Lavalink clients is to be ensured.

ThePedroo commented 8 months ago

Can't keep on with all LavaLink changes, sorry.

Do you want to open a PR, or can I?

devoxin commented 8 months ago

I'll let you tend to it as it looks like a bit of refactoring will need to happen to support this change.

ThePedroo commented 8 months ago

Done, this is fixed, and also: userData added!

Try the update-add/encodedTrack-userData branch.

devoxin commented 8 months ago

Same thing, still not working. Although this time, I'm now seeing the addition of this in my logs:

[stop]: Received a request from client.
ThePedroo commented 8 months ago

Oops! It should work properly now.