mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53: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} [seek=0] The time to seek to
|
||||||
* @property {number} [volume=1] The volume to play at
|
* @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} [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
|
* If set to 'auto', the voice channel's bitrate will be used
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ nonce.fill(0);
|
|||||||
* @extends {stream.Writable}
|
* @extends {stream.Writable}
|
||||||
*/
|
*/
|
||||||
class StreamDispatcher extends 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);
|
super(streamOptions);
|
||||||
/**
|
/**
|
||||||
* The Audio Player that controls this dispatcher
|
* 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!
|
// Still emitting end for backwards compatibility, probably remove it in the future!
|
||||||
this.emit('end');
|
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() {
|
get _sdata() {
|
||||||
|
|||||||
@@ -46,14 +46,14 @@ class AudioPlayer extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playUnknownStream(stream, options = {}) {
|
playUnknownStream(stream, options) {
|
||||||
this.destroyDispatcher();
|
this.destroyDispatcher();
|
||||||
const ffmpeg = new prism.FFmpeg({ args: FFMPEG_ARGUMENTS });
|
const ffmpeg = new prism.FFmpeg({ args: FFMPEG_ARGUMENTS });
|
||||||
stream.pipe(ffmpeg);
|
stream.pipe(ffmpeg);
|
||||||
return this.playPCMStream(ffmpeg, options, { ffmpeg });
|
return this.playPCMStream(ffmpeg, options, { ffmpeg });
|
||||||
}
|
}
|
||||||
|
|
||||||
playPCMStream(stream, options = {}, streams = {}) {
|
playPCMStream(stream, options, streams = {}) {
|
||||||
this.destroyDispatcher();
|
this.destroyDispatcher();
|
||||||
const volume = streams.volume = new prism.VolumeTransformer16LE(null, { volume: 0.2 });
|
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 });
|
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);
|
return this.playOpusStream(opus, options, streams);
|
||||||
}
|
}
|
||||||
|
|
||||||
playOpusStream(stream, options = {}, streams = {}) {
|
playOpusStream(stream, options, streams = {}) {
|
||||||
this.destroyDispatcher();
|
this.destroyDispatcher();
|
||||||
streams.opus = stream;
|
streams.opus = stream;
|
||||||
const dispatcher = this.dispatcher = this.createDispatcher(options, streams);
|
const dispatcher = this.dispatcher = this.createDispatcher(options, streams);
|
||||||
@@ -69,9 +69,8 @@ class AudioPlayer extends EventEmitter {
|
|||||||
return dispatcher;
|
return dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
createDispatcher({ seek = 0, volume = 1, passes = 1 } = {}, streams) {
|
createDispatcher(options, streams) {
|
||||||
this.destroyDispatcher();
|
this.destroyDispatcher();
|
||||||
const options = { seek, volume, passes };
|
|
||||||
const dispatcher = new StreamDispatcher(this, options, streams);
|
const dispatcher = new StreamDispatcher(this, options, streams);
|
||||||
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
dispatcher.on('speaking', value => this.voiceConnection.setSpeaking(value));
|
||||||
return dispatcher;
|
return dispatcher;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ client.login(auth.token).then(() => console.log('logged')).catch(console.error);
|
|||||||
|
|
||||||
const connections = new Map();
|
const connections = new Map();
|
||||||
|
|
||||||
let broadcast;
|
var d;
|
||||||
|
|
||||||
client.on('debug', console.log);
|
client.on('debug', console.log);
|
||||||
client.on('error', console.log);
|
client.on('error', console.log);
|
||||||
@@ -29,9 +29,7 @@ client.on('message', m => {
|
|||||||
conn.player.on('error', (...e) => console.log('player', ...e));
|
conn.player.on('error', (...e) => console.log('player', ...e));
|
||||||
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
|
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
|
||||||
m.reply('ok!');
|
m.reply('ok!');
|
||||||
const d = conn.playOpusStream(
|
d = conn.playStream(ytdl('https://www.youtube.com/watch?v=EUoe7cf0HYw', { filter: 'audioonly' }, { passes: 3 }));
|
||||||
fs.createReadStream('C:/users/amish/downloads/s.ogg').pipe(new prism.OggOpusDemuxer())
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
m.reply('Specify a voice channel!');
|
m.reply('Specify a voice channel!');
|
||||||
@@ -42,7 +40,9 @@ client.on('message', m => {
|
|||||||
.replace(/</g, '')
|
.replace(/</g, '')
|
||||||
.replace(/>/g, '');
|
.replace(/>/g, '');
|
||||||
const stream = ytdl(url, { filter: 'audioonly' }, { passes: 3 });
|
const stream = ytdl(url, { filter: 'audioonly' }, { passes: 3 });
|
||||||
m.guild.voiceConnection.playStream(stream);
|
d = m.guild.voiceConnection.playStream(stream);
|
||||||
|
d.setBitrate(1);
|
||||||
|
setTimeout(() => d.setBitrate(320), 5000);
|
||||||
}
|
}
|
||||||
} else if (m.content.startsWith('/skip')) {
|
} else if (m.content.startsWith('/skip')) {
|
||||||
if (connections.has(m.guild.id)) {
|
if (connections.has(m.guild.id)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user