mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Simplify broadcast creation
This commit is contained in:
@@ -35,12 +35,6 @@ class AudioPlayer extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
destroyStream(stream) {
|
destroyStream(stream) {
|
||||||
if (stream instanceof VoiceBroadcast && this.streams.has(stream)) {
|
|
||||||
const data = this.streams.get(stream);
|
|
||||||
if (data.dispatcher) data.dispatcher.destroy('end');
|
|
||||||
this.streams.delete(stream);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = this.streams.get(stream);
|
const data = this.streams.get(stream);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
const transcoder = data.transcoder;
|
const transcoder = data.transcoder;
|
||||||
@@ -89,11 +83,11 @@ class AudioPlayer extends EventEmitter {
|
|||||||
playBroadcast(broadcast, { volume = 1, passes = 1 } = {}) {
|
playBroadcast(broadcast, { volume = 1, passes = 1 } = {}) {
|
||||||
const options = { volume, passes };
|
const options = { volume, passes };
|
||||||
this.destroyAllStreams();
|
this.destroyAllStreams();
|
||||||
this.streams.set(broadcast, broadcast);
|
|
||||||
const dispatcher = new StreamDispatcher(this, broadcast, options);
|
const dispatcher = new StreamDispatcher(this, broadcast, options);
|
||||||
dispatcher.on('end', () => this.destroyStream(broadcast));
|
dispatcher.on('end', () => this.destroyStream(broadcast));
|
||||||
dispatcher.on('error', () => this.destroyStream(broadcast));
|
dispatcher.on('error', () => this.destroyStream(broadcast));
|
||||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||||
|
this.streams.set(broadcast, { dispatcher, input: broadcast });
|
||||||
broadcast.registerDispatcher(dispatcher);
|
broadcast.registerDispatcher(dispatcher);
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user