Handle Voice Server Update events

This commit is contained in:
Amish Shah
2016-08-23 17:52:36 +01:00
parent dfbe44143a
commit fa085c18cd
5 changed files with 44 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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() {

View 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;

View File

@@ -178,6 +178,7 @@ exports.WSEvents = {
VOICE_STATE_UPDATE: 'VOICE_STATE_UPDATE',
FRIEND_ADD: 'RELATIONSHIP_ADD',
FRIEND_REMOVE: 'RELATIONSHIP_REMOVE',
VOICE_SERVER_UPDATE: 'VOICE_SERVER_UPDATE',
};
const PermissionFlags = exports.PermissionFlags = {