mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor: add some more consistency (#3842)
* cleanup(StreamDispatcher): remove old 'end' event * fix(StreamDispatcher): only listen to finish event once * refactor(VoiceWebSocket): use `connection.client` in favour of `connection.voiceManager.client` * fix(VoiceWebSocket): use `client.clearInterval` in favour of `clearInterval` * refactor: destructure EventEmitter * refactor: destructure EventEmitter from events * refactor: use EventEmitter.off in favour of EventEmitter.removeListener * style: order typings alphabetically * oops * fix indent * style: alphabetically organize imports * style: remove extra line * Revert "style: remove extra line" This reverts commit96e182ed69. * Revert "style: alphabetically organize imports" This reverts commit02aee9b06d. * Revert "refactor: destructure EventEmitter from events" This reverts commit9953b4d267. * Revert "refactor: destructure EventEmitter" This reverts commit930d7751ab. * Revert "fix(StreamDispatcher): only listen to finish event once" This reverts commit485a6430a8. * refactor: use .removeListener instead of .off
This commit is contained in:
@@ -35,7 +35,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
* @readonly
|
||||
*/
|
||||
get client() {
|
||||
return this.connection.voiceManager.client;
|
||||
return this.connection.client;
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
@@ -232,7 +232,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
* @event VoiceWebSocket#warn
|
||||
*/
|
||||
this.emit('warn', 'A voice heartbeat interval is being overwritten');
|
||||
clearInterval(this.heartbeatInterval);
|
||||
this.client.clearInterval(this.heartbeatInterval);
|
||||
}
|
||||
this.heartbeatInterval = this.client.setInterval(this.sendHeartbeat.bind(this), interval);
|
||||
}
|
||||
@@ -245,7 +245,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
this.emit('warn', 'Tried to clear a heartbeat interval that does not exist');
|
||||
return;
|
||||
}
|
||||
clearInterval(this.heartbeatInterval);
|
||||
this.client.clearInterval(this.heartbeatInterval);
|
||||
this.heartbeatInterval = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,11 +175,11 @@ class WebSocketShard extends EventEmitter {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const cleanup = () => {
|
||||
this.off(ShardEvents.CLOSE, onClose);
|
||||
this.off(ShardEvents.READY, onReady);
|
||||
this.off(ShardEvents.RESUMED, onResumed);
|
||||
this.off(ShardEvents.INVALID_SESSION, onInvalidOrDestroyed);
|
||||
this.off(ShardEvents.DESTROYED, onInvalidOrDestroyed);
|
||||
this.removeListener(ShardEvents.CLOSE, onClose);
|
||||
this.removeListener(ShardEvents.READY, onReady);
|
||||
this.removeListener(ShardEvents.RESUMED, onResumed);
|
||||
this.removeListener(ShardEvents.INVALID_SESSION, onInvalidOrDestroyed);
|
||||
this.removeListener(ShardEvents.DESTROYED, onInvalidOrDestroyed);
|
||||
};
|
||||
|
||||
const onReady = () => {
|
||||
|
||||
@@ -230,8 +230,8 @@ class Collector extends EventEmitter {
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
await new Promise(resolve => {
|
||||
const tick = () => {
|
||||
this.off('collect', tick);
|
||||
this.off('end', tick);
|
||||
this.removeListener('collect', tick);
|
||||
this.removeListener('end', tick);
|
||||
return resolve();
|
||||
};
|
||||
this.on('collect', tick);
|
||||
@@ -240,7 +240,7 @@ class Collector extends EventEmitter {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.off('collect', onCollect);
|
||||
this.removeListener('collect', onCollect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user