mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
FEC and PLP exposed
This commit is contained in:
@@ -434,7 +434,9 @@ class VoiceConnection extends EventEmitter {
|
||||
* @property {number} [seek=0] The time to seek to
|
||||
* @property {number} [volume=1] The volume to play at
|
||||
* @property {number} [passes=1] How many times to send the voice packet to reduce packet loss
|
||||
* @property {number|string} [bitrate=48000] The bitrate (quality) of the audio.
|
||||
* @property {number} [plp] Expected packet loss percentage
|
||||
* @property {boolean} [fec] Enabled forward error correction
|
||||
* @property {number|string} [bitrate=96] The bitrate (quality) of the audio in kbps
|
||||
* If set to 'auto', the voice channel's bitrate will be used
|
||||
*/
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ nonce.fill(0);
|
||||
* @extends {stream.Writable}
|
||||
*/
|
||||
class StreamDispatcher extends Writable {
|
||||
constructor(player, streamOptions, streams) {
|
||||
constructor(player, { seek = 0, volume = 1, passes = 1, fec, plp, bitrate = 96 } = {}, streams) {
|
||||
const streamOptions = { seek, volume, passes, fec, plp, bitrate };
|
||||
super(streamOptions);
|
||||
/**
|
||||
* The Audio Player that controls this dispatcher
|
||||
@@ -55,6 +56,11 @@ class StreamDispatcher extends Writable {
|
||||
// Still emitting end for backwards compatibility, probably remove it in the future!
|
||||
this.emit('end');
|
||||
});
|
||||
|
||||
if (typeof volume !== 'undefined') this.setVolume(volume);
|
||||
if (typeof fec !== 'undefined') this.setFEC(fec);
|
||||
if (typeof plp !== 'undefined') this.setPLP(plp);
|
||||
if (typeof bitrate !== 'undefined') this.setBitrate(bitrate);
|
||||
}
|
||||
|
||||
get _sdata() {
|
||||
|
||||
@@ -46,14 +46,14 @@ class AudioPlayer extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
playUnknownStream(stream, options = {}) {
|
||||
playUnknownStream(stream, options) {
|
||||
this.destroyDispatcher();
|
||||
const ffmpeg = new prism.FFmpeg({ args: FFMPEG_ARGUMENTS });
|
||||
stream.pipe(ffmpeg);
|
||||
return this.playPCMStream(ffmpeg, options, { ffmpeg });
|
||||
}
|
||||
|
||||
playPCMStream(stream, options = {}, streams = {}) {
|
||||
playPCMStream(stream, options, streams = {}) {
|
||||
this.destroyDispatcher();
|
||||
const volume = streams.volume = new prism.VolumeTransformer16LE(null, { volume: 0.2 });
|
||||
const opus = streams.opus = new prism.opus.Encoder({ channels: 2, rate: 48000, frameSize: 960 });
|
||||
@@ -61,7 +61,7 @@ class AudioPlayer extends EventEmitter {
|
||||
return this.playOpusStream(opus, options, streams);
|
||||
}
|
||||
|
||||
playOpusStream(stream, options = {}, streams = {}) {
|
||||
playOpusStream(stream, options, streams = {}) {
|
||||
this.destroyDispatcher();
|
||||
streams.opus = stream;
|
||||
const dispatcher = this.dispatcher = this.createDispatcher(options, streams);
|
||||
@@ -69,9 +69,8 @@ class AudioPlayer extends EventEmitter {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
createDispatcher({ seek = 0, volume = 1, passes = 1 } = {}, streams) {
|
||||
createDispatcher(options, streams) {
|
||||
this.destroyDispatcher();
|
||||
const options = { seek, volume, passes };
|
||||
const dispatcher = new StreamDispatcher(this, options, streams);
|
||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||
return dispatcher;
|
||||
|
||||
Reference in New Issue
Block a user