mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 09:42:22 +00:00
Simplify broadcast creation
This commit is contained in:
parent
2f630a0dbb
commit
bf4010e89c
1 changed files with 1 additions and 7 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue