mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
start work with broadcast streams
This commit is contained in:
@@ -3,6 +3,7 @@ const Prism = require('prism-media');
|
||||
const StreamDispatcher = require('../dispatcher/StreamDispatcher');
|
||||
const Collection = require('../../../util/Collection');
|
||||
const OpusEncoders = require('../opus/OpusEngineList');
|
||||
const VoiceBroadcast = require('../VoiceBroadcast');
|
||||
|
||||
const ffmpegArguments = [
|
||||
'-analyzeduration', '0',
|
||||
@@ -33,6 +34,10 @@ class AudioPlayer extends EventEmitter {
|
||||
}
|
||||
|
||||
destroyStream(stream) {
|
||||
if (stream instanceof VoiceBroadcast) {
|
||||
this.streams.delete(stream);
|
||||
return;
|
||||
}
|
||||
const data = this.streams.get(stream);
|
||||
if (!data) return;
|
||||
const transcoder = data.transcoder;
|
||||
@@ -77,6 +82,18 @@ class AudioPlayer extends EventEmitter {
|
||||
dispatcher.on('error', () => this.destroyStream(stream));
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
playBroadcast(broadcast, { volume = 1, passes = 1 } = {}) {
|
||||
const options = { volume, passes };
|
||||
this.destroyAllStreams();
|
||||
this.streams.set(broadcast, broadcast);
|
||||
const dispatcher = new StreamDispatcher(this, broadcast, options);
|
||||
dispatcher.on('end', () => this.destroyStream(broadcast));
|
||||
dispatcher.on('error', () => this.destroyStream(broadcast));
|
||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||
broadcast.registerDispatcher(dispatcher);
|
||||
return dispatcher;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AudioPlayer;
|
||||
|
||||
Reference in New Issue
Block a user