mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
voice setup waits for all data
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -5,7 +5,7 @@ const RESTManager = require('./rest/RESTManager');
|
|||||||
const ClientDataManager = require('./ClientDataManager');
|
const ClientDataManager = require('./ClientDataManager');
|
||||||
const ClientManager = require('./ClientManager');
|
const ClientManager = require('./ClientManager');
|
||||||
const ClientDataResolver = require('./ClientDataResolver');
|
const ClientDataResolver = require('./ClientDataResolver');
|
||||||
const ClientVoiceManager = require('./ClientVoiceManager');
|
const ClientVoiceManager = require('./voice/ClientVoiceManager');
|
||||||
const WebSocketManager = require('./websocket/WebSocketManager');
|
const WebSocketManager = require('./websocket/WebSocketManager');
|
||||||
const ActionsManager = require('./actions/ActionsManager');
|
const ActionsManager = require('./actions/ActionsManager');
|
||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const Collection = require('../util/Collection');
|
const Collection = require('../../util/Collection');
|
||||||
const mergeDefault = require('../util/MergeDefault');
|
const mergeDefault = require('../../util/MergeDefault');
|
||||||
const Constants = require('../util/Constants');
|
const Constants = require('../../util/Constants');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all the voice stuff for the Client
|
* Manages all the voice stuff for the Client
|
||||||
@@ -25,13 +25,44 @@ class ClientVoiceManager {
|
|||||||
this.pending = new Collection();
|
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} token the token to authorise with
|
||||||
* @param {String} endpoint the endpoint to connect to
|
* @param {String} endpoint the endpoint to connect to
|
||||||
*/
|
*/
|
||||||
_receivedVoiceServer(token, endpoint) {
|
_receivedVoiceServer(guildID, token, endpoint) {
|
||||||
console.log('got', 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}
|
* @returns {null}
|
||||||
*/
|
*/
|
||||||
joinChannel(channel) {
|
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);
|
this._sendWSJoin(channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,8 +14,8 @@ class VoiceServerUpdate extends AbstractHandler {
|
|||||||
const data = packet.d;
|
const data = packet.d;
|
||||||
const client = this.packetManager.client;
|
const client = this.packetManager.client;
|
||||||
|
|
||||||
if (client.voice.pending.get(data.guild_id)) {
|
if (client.voice.pending.has(data.guild_id)) {
|
||||||
client.voice._receivedVoiceServer(data.token, data.endpoint);
|
client.voice._receivedVoiceServer(data.guild_id, data.token, data.endpoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ class VoiceStateUpdateHandler extends AbstractHandler {
|
|||||||
member.voiceChannel.members.delete(oldVoiceChannelMember.id);
|
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.serverMute = data.mute;
|
||||||
member.serverDeaf = data.deaf;
|
member.serverDeaf = data.deaf;
|
||||||
member.selfMute = data.self_mute;
|
member.selfMute = data.self_mute;
|
||||||
|
|||||||
Reference in New Issue
Block a user