voice setup waits for all data

This commit is contained in:
Amish Shah
2016-08-23 18:29:48 +01:00
parent fa085c18cd
commit d8b1ef47cd
5 changed files with 51 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@@ -5,7 +5,7 @@ const RESTManager = require('./rest/RESTManager');
const ClientDataManager = require('./ClientDataManager');
const ClientManager = require('./ClientManager');
const ClientDataResolver = require('./ClientDataResolver');
const ClientVoiceManager = require('./ClientVoiceManager');
const ClientVoiceManager = require('./voice/ClientVoiceManager');
const WebSocketManager = require('./websocket/WebSocketManager');
const ActionsManager = require('./actions/ActionsManager');
const Collection = require('../util/Collection');

View File

@@ -1,6 +1,6 @@
const Collection = require('../util/Collection');
const mergeDefault = require('../util/MergeDefault');
const Constants = require('../util/Constants');
const Collection = require('../../util/Collection');
const mergeDefault = require('../../util/MergeDefault');
const Constants = require('../../util/Constants');
/**
* Manages all the voice stuff for the Client
@@ -25,13 +25,44 @@ class ClientVoiceManager {
this.pending = new Collection();
}
_checkPendingReady(guildID) {
const pendingRequest = this.pending.get(guildID);
if (!pendingRequest) {
throw new Error('Guild not pending');
}
if (pendingRequest.token && pendingRequest.sessionID && pendingRequest.endpoint) {
console.log('got all info for', guildID);
}
}
/**
* Called when the Client receives information about this voice state update.
* Called when the Client receives information about this voice server update.
* @param {String} guildID the ID of the Guild
* @param {String} token the token to authorise with
* @param {String} endpoint the endpoint to connect to
*/
_receivedVoiceServer(token, endpoint) {
console.log('got', token, endpoint);
_receivedVoiceServer(guildID, token, endpoint) {
const pendingRequest = this.pending.get(guildID);
if (!pendingRequest) {
throw new Error('Guild not pending');
}
pendingRequest.token = token;
pendingRequest.endpoint = endpoint;
this._checkPendingReady(guildID);
}
/**
* Called when the Client receives information about the voice state update.
* @param {String} guildID the ID of the Guild
* @param {String} sessionID the session id to authorise with
*/
_receivedVoiceStateUpdate(guildID, sessionID) {
const pendingRequest = this.pending.get(guildID);
if (!pendingRequest) {
throw new Error('Guild not pending');
}
pendingRequest.sessionID = sessionID;
this._checkPendingReady(guildID);
}
/**
@@ -58,7 +89,12 @@ class ClientVoiceManager {
* @returns {null}
*/
joinChannel(channel) {
this.pending.set(channel.guild.id, channel);
this.pending.set(channel.guild.id, {
channel,
sessionID: null,
token: null,
endpoint: null,
});
this._sendWSJoin(channel);
}
}

View File

@@ -14,8 +14,8 @@ class VoiceServerUpdate extends AbstractHandler {
const data = packet.d;
const client = this.packetManager.client;
if (client.voice.pending.get(data.guild_id)) {
client.voice._receivedVoiceServer(data.token, data.endpoint);
if (client.voice.pending.has(data.guild_id)) {
client.voice._receivedVoiceServer(data.guild_id, data.token, data.endpoint);
}
}

View File

@@ -18,6 +18,10 @@ class VoiceStateUpdateHandler extends AbstractHandler {
member.voiceChannel.members.delete(oldVoiceChannelMember.id);
}
if (client.voice.pending.has(guild.id)) {
client.voice._receivedVoiceStateUpdate(data.guild_id, data.session_id);
}
member.serverMute = data.mute;
member.serverDeaf = data.deaf;
member.selfMute = data.self_mute;