Closed Zoddo closed 2 years ago
Ah, excellent catch and thanks for explaining. I think this is probably the most reasonable solution. Initially we were only storing the session ID in an attempt to reduce memory usage; however, especially since it's lossy, I think that was a bit of premature optimization.
551792856fa110c499d87bc4a34e49d5835e2f09 is also an attempt to avoid memory leaks and I believe the logic there is sound; if the VSU packet has a null channel ID, the connection is being terminated.
If we want to reduce a bit the memory usage, we can do something like:
this.voiceStates.set(packet.guild_id, {
guild_id: packet.guild_id,
channel_id: packet.channel_id,
user_id: packet.user_id,
session_id: packet.session_id,
});
This would notably remove the member object from the VSU, which is likely half of its size
Is there a need for the member object? If not, I suggest we move forward with cutting it out.
Currently, only the
session_id
is cached. When needed, aVoiceStateUpdate
is reconstructed by the getterPlayer.voiceState
. However, this "reconstructed" VSU is missing thechannel_id
property. This breakPlayer.moveTo()
, because it callsNode.voiceStateUpdate()
with this partial VSU, which is basically a noop without achannel_id
.This commit fixes this issue by caching the full
VoiceStateUpdate
(which includes thechannel_id
) in theNode.voiceStates
Map.This is the cleanest way I found.
channel_id
in thePlayer
, because it may not exists yet whenNode.voiceStateUpdate()
is called (and creating it at this point may be undesirable).Map
just to cache thechannel_id
looks wrong.channel_id
toNode.voiceStateUpdate()
would works, but it's a ugly fix.For the record,
Player.moveTo()
appears to have been broken by the commit 551792856fa110c499d87bc4a34e49d5835e2f09 which changed the behavior ofNode.voiceStateUpdate()
when thechannel_id
property is missing.