mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Small cleanups
This commit is contained in:
@@ -14,11 +14,13 @@ class ClientVoiceManager {
|
||||
* @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>}
|
||||
@@ -97,9 +99,7 @@ class ClientVoiceManager {
|
||||
*/
|
||||
joinChannel(channel) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.pending.get(channel.guild.id)) {
|
||||
throw new Error(`Already connecting to a channel in guild.`);
|
||||
}
|
||||
if (this.pending.get(channel.guild.id)) throw new Error(`Already connecting to a channel in guild.`);
|
||||
const existingConn = this.connections.get(channel.guild.id);
|
||||
if (existingConn) {
|
||||
if (existingConn.channel.id !== channel.id) {
|
||||
|
||||
@@ -18,50 +18,59 @@ const DefaultPlayer = require('./player/DefaultPlayer');
|
||||
class VoiceConnection extends EventEmitter {
|
||||
constructor(manager, channel, token, sessionID, endpoint, resolve, reject) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* The voice manager of this connection
|
||||
* @type {ClientVoiceManager}
|
||||
* @private
|
||||
*/
|
||||
this.manager = manager;
|
||||
|
||||
/**
|
||||
* The player
|
||||
* @type {BasePlayer}
|
||||
*/
|
||||
this.player = new DefaultPlayer(this);
|
||||
|
||||
/**
|
||||
* The endpoint of the connection
|
||||
* @type {string}
|
||||
*/
|
||||
this.endpoint = 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;
|
||||
|
||||
/**
|
||||
* The resolve function for the promise associated with creating this connection
|
||||
* @type {function}
|
||||
* @private
|
||||
*/
|
||||
this._resolve = resolve;
|
||||
|
||||
/**
|
||||
* The reject function for the promise associated with creating this connection
|
||||
* @type {function}
|
||||
* @private
|
||||
*/
|
||||
this._reject = reject;
|
||||
|
||||
this.ssrcMap = new Map();
|
||||
this.queue = [];
|
||||
this.receivers = [];
|
||||
@@ -69,7 +78,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed whenever an error occurs with the UDP/WebSocket sub-client
|
||||
* Executed whenever an error occurs with the UDP/WebSocket sub-client.
|
||||
* @private
|
||||
* @param {Error} err The encountered error
|
||||
*/
|
||||
@@ -85,7 +94,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the Client from the Voice Channel
|
||||
* Disconnects the Client from the Voice Channel.
|
||||
* @param {string} [reason='user requested'] The reason of the disconnection
|
||||
*/
|
||||
disconnect(reason = 'user requested') {
|
||||
@@ -122,7 +131,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds listeners to the WebSocket and UDP sub-clients
|
||||
* Binds listeners to the WebSocket and UDP sub-clients.
|
||||
* @private
|
||||
*/
|
||||
bindListeners() {
|
||||
@@ -211,7 +220,7 @@ class VoiceConnection extends EventEmitter {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Play the given file in the voice connection
|
||||
* Play the given file in the voice connection.
|
||||
* @param {string} file The path to the file
|
||||
* @param {StreamOptions} [options] Options for playing the stream
|
||||
* @returns {StreamDispatcher}
|
||||
@@ -229,7 +238,7 @@ class VoiceConnection extends EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays and converts an audio stream in the voice connection
|
||||
* Plays and converts an audio stream in the voice connection.
|
||||
* @param {ReadableStream} stream The audio stream to play
|
||||
* @param {StreamOptions} [options] Options for playing the stream
|
||||
* @returns {StreamDispatcher}
|
||||
@@ -258,8 +267,7 @@ class VoiceConnection extends EventEmitter {
|
||||
playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
|
||||
const options = { seek, volume, passes };
|
||||
this.player._shutdown();
|
||||
const dispatcher = this.player.playPCMStream(stream, options);
|
||||
return dispatcher;
|
||||
return this.player.playPCMStream(stream, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,8 +36,8 @@ function chooseCommand() {
|
||||
if (!ChildProcess.spawnSync(cmd, ['-h']).error) return cmd;
|
||||
}
|
||||
throw new Error(
|
||||
'FFMPEG was not found on your system, so audio cannot be played.' +
|
||||
'Please make sure FFMPEG is installed and in your PATH'
|
||||
'FFMPEG was not found on your system, so audio cannot be played. ' +
|
||||
'Please make sure FFMPEG is installed and in your PATH.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user