voice: remove createReceiver, just use VoiceConnection.receiver

This commit is contained in:
Amish Shah
2018-08-16 18:30:54 +01:00
parent 97c34b5b6f
commit e2726f5a9a
3 changed files with 13 additions and 28 deletions

View File

@@ -54,12 +54,6 @@ class VoiceConnection extends EventEmitter {
*/
this.speaking = false;
/**
* An array of Voice Receivers that have been created for this connection
* @type {VoiceReceiver[]}
*/
this.receivers = [];
/**
* The authentication data needed to connect to the voice server
* @type {Object}
@@ -114,6 +108,12 @@ class VoiceConnection extends EventEmitter {
*/
this.sockets = {};
/**
* The voice receiver of this connection
* @type {VoiceReceiver}
*/
this.receiver = null;
this.authenticate();
}
@@ -417,6 +417,7 @@ class VoiceConnection extends EventEmitter {
Object.assign(this.authentication, data);
this.status = VoiceStatus.CONNECTED;
clearTimeout(this.connectTimeout);
this.receiver = new VoiceReceiver(this);
/**
* Emitted once the connection is ready, when a promise to join a voice channel resolves,
* the connection will already be ready.
@@ -446,9 +447,7 @@ class VoiceConnection extends EventEmitter {
if (this.status === VoiceStatus.CONNECTED) {
this.emit('speaking', user, speaking);
if (!speaking) {
for (const receiver of this.receivers) {
receiver.packets._stoppedSpeaking(user_id);
}
this.receiver.packets._stoppedSpeaking(user_id);
}
}
@@ -466,17 +465,6 @@ class VoiceConnection extends EventEmitter {
}
}
/**
* Creates a VoiceReceiver so you can start listening to voice data.
* It's recommended to only create one of these.
* @returns {VoiceReceiver}
*/
createReceiver() {
const receiver = new VoiceReceiver(this);
this.receivers.push(receiver);
return receiver;
}
play() {} // eslint-disable-line no-empty-function
}