voice: add ability to delete broadcasts

This commit is contained in:
Amish Shah
2019-03-23 12:52:18 +00:00
parent 9a092b6e57
commit 6adb0a6609
2 changed files with 12 additions and 1 deletions

View File

@@ -8,7 +8,6 @@ const { Error } = require('../../errors');
/**
* Manages voice connections for the client
* @private
*/
class ClientVoiceManager {
constructor(client) {

View File

@@ -61,6 +61,16 @@ class VoiceBroadcast extends EventEmitter {
*/
play() { return null; }
/**
* Ends the broadcast, unsubscribing all subscribed channels and deleting the broadcast
*/
end() {
for (const dispatcher of this.dispatchers) this.delete(dispatcher);
const index = this.client.voice.broadcasts.indexOf(this);
if (index !== -1) this.client.voice.broadcasts.splice(index, 1);
}
add(dispatcher) {
const index = this.dispatchers.indexOf(dispatcher);
if (index === -1) {
@@ -79,6 +89,8 @@ class VoiceBroadcast extends EventEmitter {
delete(dispatcher) {
const index = this.dispatchers.indexOf(dispatcher);
if (index !== -1) {
this.dispatchers.splice(index, 1);
dispatcher.destroy();
/**
* Emitted whenever a stream dispatcher unsubscribes to the broadcast.
* @event VoiceBroadcast#unsubscribe