mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Handle Voice Server Update events
This commit is contained in:
@@ -10,12 +10,28 @@ class ClientVoiceManager {
|
||||
constructor(client) {
|
||||
/**
|
||||
* The client that instantiated this voice manager
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
/**
|
||||
* A collection mapping connection IDs to the Connection objects
|
||||
* @type {Collection<String, VoiceConnection>}
|
||||
*/
|
||||
this.connections = new Collection();
|
||||
/**
|
||||
* Pending connection attempts, maps Guild ID to VoiceChannel
|
||||
* @type {Collection<String, VoiceChannel>}
|
||||
*/
|
||||
this.pending = new Collection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Client receives information about this voice state update.
|
||||
* @param {String} token the token to authorise with
|
||||
* @param {String} endpoint the endpoint to connect to
|
||||
*/
|
||||
_receivedVoiceServer(token, endpoint) {
|
||||
console.log('got', token, endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,6 +58,7 @@ class ClientVoiceManager {
|
||||
* @returns {null}
|
||||
*/
|
||||
joinChannel(channel) {
|
||||
this.pending.set(channel.guild.id, channel);
|
||||
this._sendWSJoin(channel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class WebSocketPacketManager {
|
||||
this.register(Constants.WSEvents.MESSAGE_CREATE, 'MessageCreate');
|
||||
this.register(Constants.WSEvents.MESSAGE_DELETE, 'MessageDelete');
|
||||
this.register(Constants.WSEvents.MESSAGE_UPDATE, 'MessageUpdate');
|
||||
this.register(Constants.WSEvents.VOICE_SERVER_UPDATE, 'VoiceServerUpdate');
|
||||
}
|
||||
|
||||
get client() {
|
||||
|
||||
24
src/client/websocket/packets/handlers/VoiceServerUpdate.js
Normal file
24
src/client/websocket/packets/handlers/VoiceServerUpdate.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
|
||||
/*
|
||||
{
|
||||
"token": "my_token",
|
||||
"guild_id": "41771983423143937",
|
||||
"endpoint": "smart.loyal.discord.gg"
|
||||
}
|
||||
*/
|
||||
|
||||
class VoiceServerUpdate extends AbstractHandler {
|
||||
|
||||
handle(packet) {
|
||||
const data = packet.d;
|
||||
const client = this.packetManager.client;
|
||||
|
||||
if (client.voice.pending.get(data.guild_id)) {
|
||||
client.voice._receivedVoiceServer(data.token, data.endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = VoiceServerUpdate;
|
||||
Reference in New Issue
Block a user