mirror of
https://github.com/danbulant/discord.js
synced 2026-07-09 05:00:48 +00:00
VoiceBroadcast.{dispatchers -> subscribers}
This commit is contained in:
parent
75d5598fda
commit
72dd872fce
2 changed files with 9 additions and 9 deletions
|
|
@ -28,10 +28,10 @@ class VoiceBroadcast extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
this.client = client;
|
this.client = client;
|
||||||
/**
|
/**
|
||||||
* The dispatchers playing this broadcast
|
* The subscribed StreamDispatchers of this broadcast
|
||||||
* @type {StreamDispatcher[]}
|
* @type {StreamDispatcher[]}
|
||||||
*/
|
*/
|
||||||
this.dispatchers = [];
|
this.subscribers = [];
|
||||||
this.player = new BroadcastAudioPlayer(this);
|
this.player = new BroadcastAudioPlayer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,19 +66,19 @@ class VoiceBroadcast extends EventEmitter {
|
||||||
* Ends the broadcast, unsubscribing all subscribed channels and deleting the broadcast
|
* Ends the broadcast, unsubscribing all subscribed channels and deleting the broadcast
|
||||||
*/
|
*/
|
||||||
end() {
|
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);
|
const index = this.client.voice.broadcasts.indexOf(this);
|
||||||
if (index !== -1) this.client.voice.broadcasts.splice(index, 1);
|
if (index !== -1) this.client.voice.broadcasts.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
add(dispatcher) {
|
add(dispatcher) {
|
||||||
const index = this.dispatchers.indexOf(dispatcher);
|
const index = this.subscribers.indexOf(dispatcher);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
this.dispatchers.push(dispatcher);
|
this.subscribers.push(dispatcher);
|
||||||
/**
|
/**
|
||||||
* Emitted whenever a stream dispatcher subscribes to the broadcast.
|
* Emitted whenever a stream dispatcher subscribes to the broadcast.
|
||||||
* @event VoiceBroadcast#subscribe
|
* @event VoiceBroadcast#subscribe
|
||||||
* @param {StreamDispatcher} dispatcher The subscribed dispatcher
|
* @param {StreamDispatcher} subscriber The subscribed dispatcher
|
||||||
*/
|
*/
|
||||||
this.emit(Events.VOICE_BROADCAST_SUBSCRIBE, dispatcher);
|
this.emit(Events.VOICE_BROADCAST_SUBSCRIBE, dispatcher);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -88,9 +88,9 @@ class VoiceBroadcast extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(dispatcher) {
|
delete(dispatcher) {
|
||||||
const index = this.dispatchers.indexOf(dispatcher);
|
const index = this.subscribers.indexOf(dispatcher);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.dispatchers.splice(index, 1);
|
this.subscribers.splice(index, 1);
|
||||||
dispatcher.destroy();
|
dispatcher.destroy();
|
||||||
/**
|
/**
|
||||||
* Emitted whenever a stream dispatcher unsubscribes to the broadcast.
|
* Emitted whenever a stream dispatcher unsubscribes to the broadcast.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ class BroadcastDispatcher extends StreamDispatcher {
|
||||||
|
|
||||||
_write(chunk, enc, done) {
|
_write(chunk, enc, done) {
|
||||||
if (!this.startTime) this.startTime = Date.now();
|
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);
|
dispatcher._write(chunk, enc);
|
||||||
}
|
}
|
||||||
this._step(done);
|
this._step(done);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue