mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
Documentation
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -130,6 +130,15 @@ class Client extends EventEmitter {
|
|||||||
return this.rest.methods.loginToken(email);
|
return this.rest.methods.loginToken(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Collection, mapping Guild ID to Voice Connections.
|
||||||
|
* @readonly
|
||||||
|
* @type {Collection<String, VoiceConnection>}
|
||||||
|
*/
|
||||||
|
get voiceConnections() {
|
||||||
|
return this.voice.connections;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Client;
|
module.exports = Client;
|
||||||
|
|||||||
@@ -26,14 +26,19 @@ class ClientVoiceManager {
|
|||||||
this.pending = new Collection();
|
this.pending = new Collection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a pending request can be processed
|
||||||
|
* @private
|
||||||
|
* @param {String} guildID The ID of the Guild
|
||||||
|
*/
|
||||||
_checkPendingReady(guildID) {
|
_checkPendingReady(guildID) {
|
||||||
const pendingRequest = this.pending.get(guildID);
|
const pendingRequest = this.pending.get(guildID);
|
||||||
if (!pendingRequest) {
|
if (!pendingRequest) {
|
||||||
throw new Error('Guild not pending');
|
throw new Error('Guild not pending');
|
||||||
}
|
}
|
||||||
if (pendingRequest.token && pendingRequest.sessionID && pendingRequest.endpoint) {
|
if (pendingRequest.token && pendingRequest.sessionID && pendingRequest.endpoint) {
|
||||||
const { token, sessionID, endpoint, resolve, reject } = pendingRequest;
|
const { channel, token, sessionID, endpoint, resolve, reject } = pendingRequest;
|
||||||
const voiceConnection = new VoiceConnection(this, guildID, token, sessionID, endpoint, resolve, reject);
|
const voiceConnection = new VoiceConnection(this, channel, token, sessionID, endpoint, resolve, reject);
|
||||||
this.connections.set(guildID, voiceConnection);
|
this.connections.set(guildID, voiceConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,23 +2,71 @@ const VoiceConnectionWebSocket = require('./VoiceConnectionWebSocket');
|
|||||||
const VoiceConnectionUDPClient = require('./VoiceConnectionUDPClient');
|
const VoiceConnectionUDPClient = require('./VoiceConnectionUDPClient');
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a connection to a Voice Channel in Discord
|
||||||
|
* @extends {EventEmitter}
|
||||||
|
*/
|
||||||
class VoiceConnection extends EventEmitter {
|
class VoiceConnection extends EventEmitter {
|
||||||
constructor(manager, serverID, token, sessionID, endpoint, resolve, reject) {
|
constructor(manager, channel, token, sessionID, endpoint, resolve, reject) {
|
||||||
super();
|
super();
|
||||||
|
/**
|
||||||
|
* The voice manager of this connection
|
||||||
|
* @type {ClientVoiceManager}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
/**
|
||||||
|
* The endpoint of the connection
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
this.websocket = new VoiceConnectionWebSocket(this, serverID, token, sessionID, endpoint);
|
/**
|
||||||
|
* The VoiceChannel for this connection
|
||||||
|
* @type {VoiceChannel}
|
||||||
|
*/
|
||||||
|
this.channel = channel;
|
||||||
|
/**
|
||||||
|
* The WebSocket connection for this voice connection
|
||||||
|
* @type {VoiceConnectionWebSocket}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.websocket = new VoiceConnectionWebSocket(this, channel.guild.id, token, sessionID, endpoint);
|
||||||
|
/**
|
||||||
|
* Whether or not the connection is ready
|
||||||
|
* @type {Boolean}
|
||||||
|
*/
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
|
/**
|
||||||
|
* The resolve function for the promise associated with creating this connection
|
||||||
|
* @type {Function}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
this._resolve = resolve;
|
this._resolve = resolve;
|
||||||
|
/**
|
||||||
|
* The reject function for the promise associated with creating this connection
|
||||||
|
* @type {Function}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
this._reject = reject;
|
this._reject = reject;
|
||||||
this.bindListeners();
|
this.bindListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executed whenever an error occurs with the UDP/WebSocket sub-client
|
||||||
|
* @private
|
||||||
|
* @param {Error} error
|
||||||
|
* @returns {null}
|
||||||
|
*/
|
||||||
_onError(e) {
|
_onError(e) {
|
||||||
this._reject(e);
|
this._reject(e);
|
||||||
this.emit('error', e);
|
this.emit('error', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binds listeners to the WebSocket and UDP sub-clients
|
||||||
|
* @returns {null}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
bindListeners() {
|
bindListeners() {
|
||||||
this.websocket.on('error', err => this._onError(err));
|
this.websocket.on('error', err => this._onError(err));
|
||||||
this.websocket.on('ready-for-udp', data => {
|
this.websocket.on('ready-for-udp', data => {
|
||||||
|
|||||||
@@ -43,6 +43,15 @@ class VoiceChannel extends GuildChannel {
|
|||||||
return this.rest.client.rest.methods.updateChannel(this, { bitrate });
|
return this.rest.client.rest.methods.updateChannel(this, { bitrate });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempts to join this Voice Channel
|
||||||
|
* @returns {Promise<VoiceConnection, Error>}
|
||||||
|
* @example
|
||||||
|
* // join a voice channel
|
||||||
|
* voiceChannel.join()
|
||||||
|
* .then(connection => console.log('Connected!'))
|
||||||
|
* .catch(console.log);
|
||||||
|
*/
|
||||||
join() {
|
join() {
|
||||||
return this.client.voice.joinChannel(this);
|
return this.client.voice.joinChannel(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user