mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
Clean up more voice stuff
This commit is contained in:
@@ -61,7 +61,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
if (this.dead) return;
|
||||
if (this.ws) this.reset();
|
||||
if (this.attempts > 5) {
|
||||
this.emit('error', new Error(`too many connection attempts (${this.attempts})`));
|
||||
this.emit('error', new Error(`Too many connection attempts (${this.attempts}).`));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,17 +85,12 @@ class VoiceWebSocket extends EventEmitter {
|
||||
*/
|
||||
send(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
|
||||
this.ws.send(data, null, error => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
reject(new Error(`Voice websocket not open to send ${data}.`));
|
||||
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||
throw new Error(`Voice websocket not open to send ${data}.`);
|
||||
}
|
||||
this.ws.send(data, null, error => {
|
||||
if (error) reject(error); else resolve(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,7 +121,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
session_id: this.voiceConnection.authentication.session_id,
|
||||
},
|
||||
}).catch(() => {
|
||||
this.emit('error', new Error('tried to send join packet but WebSocket not open'));
|
||||
this.emit('error', new Error('Tried to send join packet, but the WebSocket is not open.'));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -208,7 +203,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
*/
|
||||
setHeartbeat(interval) {
|
||||
if (!interval || isNaN(interval)) {
|
||||
this.onError(new Error('tried to set voice heartbeat but no valid interval was specified'));
|
||||
this.onError(new Error('Tried to set voice heartbeat but no valid interval was specified.'));
|
||||
return;
|
||||
}
|
||||
if (this.heartbeatInterval) {
|
||||
@@ -217,7 +212,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
* @param {string} warn the warning
|
||||
* @event VoiceWebSocket#warn
|
||||
*/
|
||||
this.emit('warn', 'a voice heartbeat interval is being overwritten');
|
||||
this.emit('warn', 'A voice heartbeat interval is being overwritten');
|
||||
clearInterval(this.heartbeatInterval);
|
||||
}
|
||||
this.heartbeatInterval = this.client.setInterval(this.sendHeartbeat.bind(this), interval);
|
||||
@@ -228,7 +223,7 @@ class VoiceWebSocket extends EventEmitter {
|
||||
*/
|
||||
clearHeartbeat() {
|
||||
if (!this.heartbeatInterval) {
|
||||
this.emit('warn', 'tried to clear a heartbeat interval that does not exist');
|
||||
this.emit('warn', 'Tried to clear a heartbeat interval that does not exist');
|
||||
return;
|
||||
}
|
||||
clearInterval(this.heartbeatInterval);
|
||||
@@ -239,11 +234,10 @@ class VoiceWebSocket extends EventEmitter {
|
||||
* Sends a heartbeat packet
|
||||
*/
|
||||
sendHeartbeat() {
|
||||
this.sendPacket({ op: Constants.VoiceOPCodes.HEARTBEAT, d: null })
|
||||
.catch(() => {
|
||||
this.emit('warn', 'tried to send heartbeat, but connection is not open');
|
||||
this.clearHeartbeat();
|
||||
});
|
||||
this.sendPacket({ op: Constants.VoiceOPCodes.HEARTBEAT, d: null }).catch(() => {
|
||||
this.emit('warn', 'Tried to send heartbeat, but connection is not open');
|
||||
this.clearHeartbeat();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user