mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(Voice*): internally disconnect and cleanup when forcibly disconnected (#3597)
This commit is contained in:
@@ -30,10 +30,15 @@ class ClientVoiceManager {
|
|||||||
|
|
||||||
onVoiceStateUpdate({ guild_id, session_id, channel_id }) {
|
onVoiceStateUpdate({ guild_id, session_id, channel_id }) {
|
||||||
const connection = this.connections.get(guild_id);
|
const connection = this.connections.get(guild_id);
|
||||||
if (connection) {
|
if (!connection) return;
|
||||||
connection.channel = this.client.channels.get(channel_id);
|
if (!channel_id) {
|
||||||
connection.setSessionID(session_id);
|
connection._disconnect();
|
||||||
|
this.connections.delete(guild_id);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
connection.channel = this.client.channels.get(channel_id);
|
||||||
|
connection.setSessionID(session_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -312,6 +312,15 @@ class VoiceConnection extends EventEmitter {
|
|||||||
this.sendVoiceStateUpdate({
|
this.sendVoiceStateUpdate({
|
||||||
channel_id: null,
|
channel_id: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internally disconnects (doesn't send disconnect packet).
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_disconnect() {
|
||||||
this.player.destroy();
|
this.player.destroy();
|
||||||
this.cleanup();
|
this.cleanup();
|
||||||
this.status = Constants.VoiceStatus.DISCONNECTED;
|
this.status = Constants.VoiceStatus.DISCONNECTED;
|
||||||
@@ -334,6 +343,7 @@ class VoiceConnection extends EventEmitter {
|
|||||||
ws.removeAllListeners('ready');
|
ws.removeAllListeners('ready');
|
||||||
ws.removeAllListeners('sessionDescription');
|
ws.removeAllListeners('sessionDescription');
|
||||||
ws.removeAllListeners('speaking');
|
ws.removeAllListeners('speaking');
|
||||||
|
ws.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (udp) udp.removeAllListeners('error');
|
if (udp) udp.removeAllListeners('error');
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class VoiceStateUpdateHandler extends AbstractHandler {
|
|||||||
// If the member left the voice channel, unset their speaking property
|
// If the member left the voice channel, unset their speaking property
|
||||||
if (!data.channel_id) member.speaking = null;
|
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);
|
client.emit('self.voiceStateUpdate', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user