mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
VoiceBroadcast.{dispatchers -> subscribers}
This commit is contained in:
@@ -28,10 +28,10 @@ class VoiceBroadcast extends EventEmitter {
|
||||
*/
|
||||
this.client = client;
|
||||
/**
|
||||
* The dispatchers playing this broadcast
|
||||
* The subscribed StreamDispatchers of this broadcast
|
||||
* @type {StreamDispatcher[]}
|
||||
*/
|
||||
this.dispatchers = [];
|
||||
this.subscribers = [];
|
||||
this.player = new BroadcastAudioPlayer(this);
|
||||
}
|
||||
|
||||
@@ -66,19 +66,19 @@ class VoiceBroadcast extends EventEmitter {
|
||||
* Ends the broadcast, unsubscribing all subscribed channels and deleting the broadcast
|
||||
*/
|
||||
end() {
|
||||
for (const dispatcher of this.dispatchers) this.delete(dispatcher);
|
||||
for (const dispatcher of this.subscribers) 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);
|
||||
const index = this.subscribers.indexOf(dispatcher);
|
||||
if (index === -1) {
|
||||
this.dispatchers.push(dispatcher);
|
||||
this.subscribers.push(dispatcher);
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher subscribes to the broadcast.
|
||||
* @event VoiceBroadcast#subscribe
|
||||
* @param {StreamDispatcher} dispatcher The subscribed dispatcher
|
||||
* @param {StreamDispatcher} subscriber The subscribed dispatcher
|
||||
*/
|
||||
this.emit(Events.VOICE_BROADCAST_SUBSCRIBE, dispatcher);
|
||||
return true;
|
||||
@@ -88,9 +88,9 @@ class VoiceBroadcast extends EventEmitter {
|
||||
}
|
||||
|
||||
delete(dispatcher) {
|
||||
const index = this.dispatchers.indexOf(dispatcher);
|
||||
const index = this.subscribers.indexOf(dispatcher);
|
||||
if (index !== -1) {
|
||||
this.dispatchers.splice(index, 1);
|
||||
this.subscribers.splice(index, 1);
|
||||
dispatcher.destroy();
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher unsubscribes to the broadcast.
|
||||
|
||||
@@ -15,7 +15,7 @@ class BroadcastDispatcher extends StreamDispatcher {
|
||||
|
||||
_write(chunk, enc, done) {
|
||||
if (!this.startTime) this.startTime = Date.now();
|
||||
for (const dispatcher of this.broadcast.dispatchers) {
|
||||
for (const dispatcher of this.broadcast.subscribers) {
|
||||
dispatcher._write(chunk, enc);
|
||||
}
|
||||
this._step(done);
|
||||
|
||||
Reference in New Issue
Block a user