mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Handle unexpected disconnects via packets (#1521)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const Collection = require('../../util/Collection');
|
||||
const Constants = require('../../util/Constants');
|
||||
const VoiceConnection = require('./VoiceConnection');
|
||||
const { Error } = require('../../errors');
|
||||
|
||||
@@ -31,10 +32,13 @@ 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.status !== Constants.VoiceStatus.DISCONNECTED) {
|
||||
connection._disconnect();
|
||||
return;
|
||||
}
|
||||
connection.channel = this.client.channels.get(channel_id);
|
||||
connection.setSessionID(session_id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -307,7 +307,14 @@ class VoiceConnection extends EventEmitter {
|
||||
this.sendVoiceStateUpdate({
|
||||
channel_id: null,
|
||||
});
|
||||
this.player.destroy();
|
||||
this._disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Internally disconnects (doesn't send disconnect packet.)
|
||||
* @private
|
||||
*/
|
||||
_disconnect() {
|
||||
this.cleanup();
|
||||
this.status = Constants.VoiceStatus.DISCONNECTED;
|
||||
/**
|
||||
@@ -317,11 +324,14 @@ class VoiceConnection extends EventEmitter {
|
||||
this.emit('disconnect');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cleans up after disconnect.
|
||||
* @private
|
||||
*/
|
||||
cleanup() {
|
||||
this.player.destroy();
|
||||
|
||||
const { ws, udp } = this.sockets;
|
||||
|
||||
if (ws) {
|
||||
|
||||
Reference in New Issue
Block a user