mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
Add stricter/better ESLint config (#589)
* Add stricter/better ESLint config * Remove more unnecessary @returns
This commit is contained in:
committed by
Amish Shah
parent
2682c07bd8
commit
68acf37fd4
@@ -99,12 +99,13 @@ class ClientVoiceManager {
|
||||
/**
|
||||
* Sets up a request to join a voice channel
|
||||
* @param {VoiceChannel} channel the voice channel to join
|
||||
* @returns {void}
|
||||
* @returns {Promise<VoiceConnection>}
|
||||
*/
|
||||
joinChannel(channel) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.pending.get(channel.guild.id)) {
|
||||
return reject(new Error('already connecting to a channel in this guild'));
|
||||
reject(new Error('already connecting to a channel in this guild'));
|
||||
return;
|
||||
}
|
||||
const existingConn = this.connections.get(channel.guild.id);
|
||||
if (existingConn) {
|
||||
@@ -112,7 +113,8 @@ class ClientVoiceManager {
|
||||
this._sendWSJoin(channel);
|
||||
this.connections.get(channel.guild.id).channel = channel;
|
||||
}
|
||||
return resolve(existingConn);
|
||||
resolve(existingConn);
|
||||
return;
|
||||
}
|
||||
this.pending.set(channel.guild.id, {
|
||||
channel,
|
||||
|
||||
@@ -65,24 +65,22 @@ class VoiceConnection extends EventEmitter {
|
||||
/**
|
||||
* Executed whenever an error occurs with the UDP/WebSocket sub-client
|
||||
* @private
|
||||
* @param {Error} error
|
||||
* @returns {void}
|
||||
* @param {Error} err The error that occurred
|
||||
*/
|
||||
_onError(e) {
|
||||
this._reject(e);
|
||||
_onError(err) {
|
||||
this._reject(err);
|
||||
/**
|
||||
* Emitted whenever the connection encounters a fatal error.
|
||||
* @event VoiceConnection#error
|
||||
* @param {Error} error the encountered error
|
||||
*/
|
||||
this.emit('error', e);
|
||||
this._shutdown(e);
|
||||
this.emit('error', err);
|
||||
this._shutdown(err);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the Client from the Voice Channel
|
||||
* @param {string} [reason='user requested'] the reason of the disconnection
|
||||
* @returns {void}
|
||||
*/
|
||||
disconnect(reason = 'user requested') {
|
||||
this.manager.client.ws.send({
|
||||
@@ -94,7 +92,7 @@ class VoiceConnection extends EventEmitter {
|
||||
self_deaf: false,
|
||||
},
|
||||
});
|
||||
return this._shutdown(reason);
|
||||
this._shutdown(reason);
|
||||
}
|
||||
|
||||
_onClose(e) {
|
||||
@@ -122,7 +120,6 @@ class VoiceConnection extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Binds listeners to the WebSocket and UDP sub-clients
|
||||
* @returns {void}
|
||||
* @private
|
||||
*/
|
||||
bindListeners() {
|
||||
@@ -208,7 +205,7 @@ class VoiceConnection extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Play the given file in the voice connection
|
||||
* @param {string} filepath the path to the file
|
||||
* @param {string} file the path to the file
|
||||
* @returns {StreamDispatcher}
|
||||
* @example
|
||||
* // play files natively
|
||||
|
||||
@@ -16,7 +16,8 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
||||
dnsLookup() {
|
||||
dns.lookup(this.voiceConnection.endpoint, (err, address) => {
|
||||
if (err) {
|
||||
return this.emit('error', err);
|
||||
this.emit('error', err);
|
||||
return;
|
||||
}
|
||||
this.connectUDP(address);
|
||||
});
|
||||
@@ -27,7 +28,7 @@ class VoiceConnectionUDPClient extends EventEmitter {
|
||||
try {
|
||||
this.udpSocket.send(packet, 0, packet.length, this.data.port, this.udpIP);
|
||||
} catch (err) {
|
||||
return this.emit('error', err);
|
||||
this.emit('error', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,16 +51,18 @@ class VoiceConnectionWebSocket extends EventEmitter {
|
||||
});
|
||||
}
|
||||
|
||||
_onClose(e) {
|
||||
_onClose(err) {
|
||||
if (!this.opened && this.attempts >= 0) {
|
||||
return this.setupWS();
|
||||
this.setupWS();
|
||||
return;
|
||||
}
|
||||
this.emit('close', e);
|
||||
this.emit('close', err);
|
||||
}
|
||||
|
||||
_onError(e) {
|
||||
if (!this.opened && this.attempts >= 0) {
|
||||
return this.setupWS();
|
||||
this.setupWS();
|
||||
return;
|
||||
}
|
||||
this.emit('error', e);
|
||||
}
|
||||
@@ -83,7 +85,8 @@ class VoiceConnectionWebSocket extends EventEmitter {
|
||||
try {
|
||||
packet = JSON.parse(event.data);
|
||||
} catch (error) {
|
||||
return this._onError(error);
|
||||
this._onError(error);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (packet.op) {
|
||||
|
||||
@@ -62,15 +62,18 @@ class StreamDispatcher extends EventEmitter {
|
||||
_send() {
|
||||
try {
|
||||
if (this._triggered) {
|
||||
return this._setSpeaking(false);
|
||||
this._setSpeaking(false);
|
||||
return;
|
||||
}
|
||||
const data = this.streamingData;
|
||||
if (data.missed >= 5) {
|
||||
return this._triggerTerminalState('error', new Error('stream is not generating fast enough'));
|
||||
this._triggerTerminalState('error', new Error('stream is not generating fast enough'));
|
||||
return;
|
||||
}
|
||||
if (this.paused) {
|
||||
data.timestamp = (data.timestamp + 4294967295) ? data.timestamp + 960 : 0;
|
||||
return this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
||||
data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0;
|
||||
this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
||||
return;
|
||||
}
|
||||
const bufferLength = 1920 * data.channels;
|
||||
this._setSpeaking(true);
|
||||
@@ -78,7 +81,8 @@ class StreamDispatcher extends EventEmitter {
|
||||
|
||||
if (!buffer) {
|
||||
data.missed++;
|
||||
return this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
||||
this.player.connection.manager.client.setTimeout(() => this._send(), data.length * 10);
|
||||
return;
|
||||
}
|
||||
|
||||
data.missed = 0;
|
||||
@@ -91,7 +95,7 @@ class StreamDispatcher extends EventEmitter {
|
||||
|
||||
data.count++;
|
||||
data.sequence = (data.sequence + 1) < (65536) ? data.sequence + 1 : 0;
|
||||
data.timestamp = (data.timestamp + 4294967295) ? data.timestamp + 960 : 0;
|
||||
data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0;
|
||||
|
||||
this._sendBuffer(buffer, data.sequence, data.timestamp);
|
||||
|
||||
@@ -114,14 +118,14 @@ class StreamDispatcher extends EventEmitter {
|
||||
/**
|
||||
* Emitted once the stream has encountered an error. Attach a `once` listener to this. Also emits `end`.
|
||||
* @event StreamDispatcher#error
|
||||
* @param {Error} error the error encountered
|
||||
* @param {Error} err the error encountered
|
||||
*/
|
||||
_triggerError(e) {
|
||||
_triggerError(err) {
|
||||
this.emit('end');
|
||||
this.emit('error', e);
|
||||
this.emit('error', err);
|
||||
}
|
||||
|
||||
_triggerTerminalState(state, e) {
|
||||
_triggerTerminalState(state, err) {
|
||||
if (this._triggered) {
|
||||
return;
|
||||
}
|
||||
@@ -136,10 +140,10 @@ class StreamDispatcher extends EventEmitter {
|
||||
this._setSpeaking(false);
|
||||
switch (state) {
|
||||
case 'end':
|
||||
this._triggerEnd(e);
|
||||
this._triggerEnd(err);
|
||||
break;
|
||||
case 'error':
|
||||
this._triggerError(e);
|
||||
this._triggerError(err);
|
||||
break;
|
||||
default:
|
||||
this.emit('error', 'unknown trigger state');
|
||||
@@ -149,10 +153,11 @@ class StreamDispatcher extends EventEmitter {
|
||||
|
||||
_startStreaming() {
|
||||
if (!this.stream) {
|
||||
return this.emit('error', 'no stream');
|
||||
this.emit('error', 'no stream');
|
||||
return;
|
||||
}
|
||||
this.stream.on('end', e => this._triggerTerminalState('end', e));
|
||||
this.stream.on('error', e => this._triggerTerminalState('error', e));
|
||||
this.stream.on('end', err => this._triggerTerminalState('end', err));
|
||||
this.stream.on('error', err => this._triggerTerminalState('error', err));
|
||||
const data = this.streamingData;
|
||||
data.length = 20;
|
||||
data.missed = 0;
|
||||
@@ -172,7 +177,6 @@ class StreamDispatcher extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Stops the current stream permanently and emits an `end` event.
|
||||
* @returns {void}
|
||||
*/
|
||||
end() {
|
||||
this._triggerTerminalState('end', 'user requested');
|
||||
@@ -180,7 +184,6 @@ class StreamDispatcher extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Stops sending voice packets to the voice connection (stream may still progress however)
|
||||
* @returns {void}
|
||||
*/
|
||||
pause() {
|
||||
this._pause(true);
|
||||
@@ -188,7 +191,6 @@ class StreamDispatcher extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Resumes sending voice packets to the voice connection (may be further on in the stream than when paused)
|
||||
* @returns {void}
|
||||
*/
|
||||
resume() {
|
||||
this._pause(false);
|
||||
|
||||
@@ -11,7 +11,7 @@ function fetch(Encoder) {
|
||||
try {
|
||||
return new Encoder();
|
||||
} catch (err) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ function chooseCommand() {
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
class FfmpegConverterEngine extends ConverterEngine {
|
||||
|
||||
@@ -70,11 +70,12 @@ class VoiceConnectionPlayer extends EventEmitter {
|
||||
streams.inputStream.destroy();
|
||||
this.emit('debug', 'stream kill part 5/5 pass');
|
||||
}
|
||||
} catch (e) {
|
||||
return e;
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
setSpeaking(value) {
|
||||
|
||||
@@ -8,6 +8,7 @@ class VoiceReadable extends Readable {
|
||||
}
|
||||
|
||||
_read() {
|
||||
return;
|
||||
}
|
||||
|
||||
$push(d) {
|
||||
|
||||
@@ -91,7 +91,8 @@ class VoiceReceiver extends EventEmitter {
|
||||
* @event VoiceReceiver#warn
|
||||
* @param {string} message the warning message
|
||||
*/
|
||||
return this.emit('warn', 'failed to decrypt voice packet');
|
||||
this.emit('warn', 'failed to decrypt voice packet');
|
||||
return;
|
||||
}
|
||||
data = new Buffer(data);
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user