fix(Voice*): internally disconnect and cleanup when forcibly disconnected (#3597)

This commit is contained in:
SpaceEEC
2020-01-05 18:10:20 +01:00
committed by GitHub
parent 1d6606293a
commit cbabc1663c
3 changed files with 19 additions and 4 deletions

View File

@@ -30,10 +30,15 @@ class ClientVoiceManager {
onVoiceStateUpdate({ guild_id, session_id, channel_id }) {
const connection = this.connections.get(guild_id);
if (connection) {
connection.channel = this.client.channels.get(channel_id);
connection.setSessionID(session_id);
if (!connection) return;
if (!channel_id) {
connection._disconnect();
this.connections.delete(guild_id);
return;
}
connection.channel = this.client.channels.get(channel_id);
connection.setSessionID(session_id);
}
/**

View File

@@ -312,6 +312,15 @@ class VoiceConnection extends EventEmitter {
this.sendVoiceStateUpdate({
channel_id: null,
});
this._disconnect();
}
/**
* Internally disconnects (doesn't send disconnect packet).
* @private
*/
_disconnect() {
this.player.destroy();
this.cleanup();
this.status = Constants.VoiceStatus.DISCONNECTED;
@@ -334,6 +343,7 @@ class VoiceConnection extends EventEmitter {
ws.removeAllListeners('ready');
ws.removeAllListeners('sessionDescription');
ws.removeAllListeners('speaking');
ws.shutdown();
}
if (udp) udp.removeAllListeners('error');

View File

@@ -20,7 +20,7 @@ class VoiceStateUpdateHandler extends AbstractHandler {
// If the member left the voice channel, unset their speaking property
if (!data.channel_id) member.speaking = null;
if (member.user.id === client.user.id && data.channel_id) {
if (member.user.id === client.user.id) {
client.emit('self.voiceStateUpdate', data);
}