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