From 863e38676fd59fe3c7c7edb1a43ffff0e6bd08cd Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Thu, 26 Oct 2017 14:39:58 +0100 Subject: [PATCH] Add back setBitrate --- src/client/voice/dispatcher/StreamDispatcher.js | 8 ++++++++ src/client/voice/player/AudioPlayer.js | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index 1a3f7c98d..e5de206bf 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -86,6 +86,14 @@ class StreamDispatcher extends Writable { if (this._writeCallback) this._writeCallback(); } + /** + * Set the bitrate of the current Opus encoder. + * @param {number} value New bitrate, in kbps + * If set to 'auto', the voice channel's bitrate will be used + * @returns {boolean} true if the bitrate has been successfully changed. + */ + setBitrate(value) { return this.player.setBitrate(value); } + _step(done) { if (this.pausedSince) { this._writeCallback = done; diff --git a/src/client/voice/player/AudioPlayer.js b/src/client/voice/player/AudioPlayer.js index fcf03d1ec..6d60f22d9 100644 --- a/src/client/voice/player/AudioPlayer.js +++ b/src/client/voice/player/AudioPlayer.js @@ -51,12 +51,13 @@ class AudioPlayer extends EventEmitter { * Set the bitrate of the current Opus encoder. * @param {number} value New bitrate, in kbps * If set to 'auto', the voice channel's bitrate will be used + * @returns {boolean} true if the bitrate has been successfully changed. */ setBitrate(value) { - if (!value) return; - if (!this.opusEncoder) return; + if (!value || !this.streams.opus || !this.streams.opus.setBitrate) return false; const bitrate = value === 'auto' ? this.voiceConnection.channel.bitrate : value; - this.opusEncoder.setBitrate(bitrate); + this.streams.opus.setBitrate(bitrate * 1000); + return true; } playUnknownStream(stream, options = {}) {