mirror of
https://github.com/danbulant/discord.js
synced 2026-05-25 13:02:38 +00:00
Handle unexpected disconnects via packets (#1521)
This commit is contained in:
parent
4342ed29a8
commit
e29a3ec08b
2 changed files with 18 additions and 4 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue