mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 01:23:31 +01:00
Small cleanups
This commit is contained in:
@@ -14,11 +14,13 @@ class ClientVoiceManager {
|
|||||||
* @type {Client}
|
* @type {Client}
|
||||||
*/
|
*/
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A collection mapping connection IDs to the Connection objects
|
* A collection mapping connection IDs to the Connection objects
|
||||||
* @type {Collection<string, VoiceConnection>}
|
* @type {Collection<string, VoiceConnection>}
|
||||||
*/
|
*/
|
||||||
this.connections = new Collection();
|
this.connections = new Collection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pending connection attempts, maps Guild ID to VoiceChannel
|
* Pending connection attempts, maps Guild ID to VoiceChannel
|
||||||
* @type {Collection<string, VoiceChannel>}
|
* @type {Collection<string, VoiceChannel>}
|
||||||
@@ -97,9 +99,7 @@ class ClientVoiceManager {
|
|||||||
*/
|
*/
|
||||||
joinChannel(channel) {
|
joinChannel(channel) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.pending.get(channel.guild.id)) {
|
if (this.pending.get(channel.guild.id)) throw new Error(`Already connecting to a channel in guild.`);
|
||||||
throw new Error(`Already connecting to a channel in guild.`);
|
|
||||||
}
|
|
||||||
const existingConn = this.connections.get(channel.guild.id);
|
const existingConn = this.connections.get(channel.guild.id);
|
||||||
if (existingConn) {
|
if (existingConn) {
|
||||||
if (existingConn.channel.id !== channel.id) {
|
if (existingConn.channel.id !== channel.id) {
|
||||||
|
|||||||
@@ -18,50 +18,59 @@ const DefaultPlayer = require('./player/DefaultPlayer');
|
|||||||
class VoiceConnection extends EventEmitter {
|
class VoiceConnection extends EventEmitter {
|
||||||
constructor(manager, channel, token, sessionID, endpoint, resolve, reject) {
|
constructor(manager, channel, token, sessionID, endpoint, resolve, reject) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The voice manager of this connection
|
* The voice manager of this connection
|
||||||
* @type {ClientVoiceManager}
|
* @type {ClientVoiceManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player
|
* The player
|
||||||
* @type {BasePlayer}
|
* @type {BasePlayer}
|
||||||
*/
|
*/
|
||||||
this.player = new DefaultPlayer(this);
|
this.player = new DefaultPlayer(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The endpoint of the connection
|
* The endpoint of the connection
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.endpoint = endpoint;
|
this.endpoint = endpoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The VoiceChannel for this connection
|
* The VoiceChannel for this connection
|
||||||
* @type {VoiceChannel}
|
* @type {VoiceChannel}
|
||||||
*/
|
*/
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WebSocket connection for this voice connection
|
* The WebSocket connection for this voice connection
|
||||||
* @type {VoiceConnectionWebSocket}
|
* @type {VoiceConnectionWebSocket}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.websocket = new VoiceConnectionWebSocket(this, channel.guild.id, token, sessionID, endpoint);
|
this.websocket = new VoiceConnectionWebSocket(this, channel.guild.id, token, sessionID, endpoint);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the connection is ready
|
* Whether or not the connection is ready
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The resolve function for the promise associated with creating this connection
|
* The resolve function for the promise associated with creating this connection
|
||||||
* @type {function}
|
* @type {function}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._resolve = resolve;
|
this._resolve = resolve;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The reject function for the promise associated with creating this connection
|
* The reject function for the promise associated with creating this connection
|
||||||
* @type {function}
|
* @type {function}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._reject = reject;
|
this._reject = reject;
|
||||||
|
|
||||||
this.ssrcMap = new Map();
|
this.ssrcMap = new Map();
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
this.receivers = [];
|
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
|
* @private
|
||||||
* @param {Error} err The encountered error
|
* @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
|
* @param {string} [reason='user requested'] The reason of the disconnection
|
||||||
*/
|
*/
|
||||||
disconnect(reason = 'user requested') {
|
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
|
* @private
|
||||||
*/
|
*/
|
||||||
bindListeners() {
|
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 {string} file The path to the file
|
||||||
* @param {StreamOptions} [options] Options for playing the stream
|
* @param {StreamOptions} [options] Options for playing the stream
|
||||||
* @returns {StreamDispatcher}
|
* @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 {ReadableStream} stream The audio stream to play
|
||||||
* @param {StreamOptions} [options] Options for playing the stream
|
* @param {StreamOptions} [options] Options for playing the stream
|
||||||
* @returns {StreamDispatcher}
|
* @returns {StreamDispatcher}
|
||||||
@@ -258,8 +267,7 @@ class VoiceConnection extends EventEmitter {
|
|||||||
playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
|
playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
|
||||||
const options = { seek, volume, passes };
|
const options = { seek, volume, passes };
|
||||||
this.player._shutdown();
|
this.player._shutdown();
|
||||||
const dispatcher = this.player.playPCMStream(stream, options);
|
return this.player.playPCMStream(stream, options);
|
||||||
return dispatcher;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ function chooseCommand() {
|
|||||||
if (!ChildProcess.spawnSync(cmd, ['-h']).error) return cmd;
|
if (!ChildProcess.spawnSync(cmd, ['-h']).error) return cmd;
|
||||||
}
|
}
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'FFMPEG was not found on your system, so audio cannot be played.' +
|
'FFMPEG was not found on your system, so audio cannot be played. ' +
|
||||||
'Please make sure FFMPEG is installed and in your PATH'
|
'Please make sure FFMPEG is installed and in your PATH.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user