mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Promisify
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -32,8 +32,8 @@ class ClientVoiceManager {
|
||||
throw new Error('Guild not pending');
|
||||
}
|
||||
if (pendingRequest.token && pendingRequest.sessionID && pendingRequest.endpoint) {
|
||||
const { token, sessionID, endpoint } = pendingRequest;
|
||||
const voiceConnection = new VoiceConnection(this, guildID, token, sessionID, endpoint);
|
||||
const { token, sessionID, endpoint, resolve, reject } = pendingRequest;
|
||||
const voiceConnection = new VoiceConnection(this, guildID, token, sessionID, endpoint, resolve, reject);
|
||||
this.connections.set(guildID, voiceConnection);
|
||||
}
|
||||
}
|
||||
@@ -93,13 +93,17 @@ class ClientVoiceManager {
|
||||
* @returns {null}
|
||||
*/
|
||||
joinChannel(channel) {
|
||||
this.pending.set(channel.guild.id, {
|
||||
channel,
|
||||
sessionID: null,
|
||||
token: null,
|
||||
endpoint: null,
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pending.set(channel.guild.id, {
|
||||
channel,
|
||||
sessionID: null,
|
||||
token: null,
|
||||
endpoint: null,
|
||||
resolve,
|
||||
reject,
|
||||
});
|
||||
this._sendWSJoin(channel);
|
||||
});
|
||||
this._sendWSJoin(channel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,21 +3,32 @@ const VoiceConnectionUDPClient = require('./VoiceConnectionUDPClient');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
|
||||
class VoiceConnection extends EventEmitter {
|
||||
constructor(manager, serverID, token, sessionID, endpoint) {
|
||||
constructor(manager, serverID, token, sessionID, endpoint, resolve, reject) {
|
||||
super();
|
||||
this.manager = manager;
|
||||
this.endpoint = endpoint;
|
||||
this.websocket = new VoiceConnectionWebSocket(this, serverID, token, sessionID, endpoint);
|
||||
this.ready = false;
|
||||
this._resolve = resolve;
|
||||
this._reject = reject;
|
||||
this.bindListeners();
|
||||
}
|
||||
|
||||
_onError(e) {
|
||||
this._reject(e);
|
||||
this.emit('error', e);
|
||||
}
|
||||
|
||||
bindListeners() {
|
||||
this.websocket.on('error', err => this._onError(err));
|
||||
this.websocket.on('ready-for-udp', data => {
|
||||
this.udp = new VoiceConnectionUDPClient(this, data);
|
||||
this.udp.on('error', err => this._onError(err));
|
||||
});
|
||||
this.websocket.on('ready', () => {
|
||||
this.ready = true;
|
||||
this.emit('ready');
|
||||
this._resolve(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user