diff --git a/src/client/voice/opus/BaseOpusEngine.js b/src/client/voice/opus/BaseOpusEngine.js index 3d2768727..ad34a224c 100644 --- a/src/client/voice/opus/BaseOpusEngine.js +++ b/src/client/voice/opus/BaseOpusEngine.js @@ -1,20 +1,25 @@ class BaseOpus { - constructor(player) { - this.player = player; - + /** + * @param {Object} [options] The options to apply to the Opus engine + * @param {boolean} [options.fec] Whether to enable forward error correction (defaults to false) + * @param {number} [options.plp] The expected packet loss percentage (0-1 inclusive, defaults to 0) + */ + constructor(options = {}) { this.ctl = { FEC: 4012, PLP: 4014, }; + + this.options = options; } init() { try { - // Enable FEC (forward error correction) - this.setFEC(true); + // Set FEC (forward error correction) + if (this.options.fec) this.setFEC(this.options.fec); - // Set PLP (expected packet loss percentage) to 15% - this.setPLP(0.15); + // Set PLP (expected packet loss percentage) + if (this.options.plp) this.setPLP(this.options.plp); } catch (err) { // Opus engine likely has no support for libopus CTL } diff --git a/src/client/voice/opus/OpusEngineList.js b/src/client/voice/opus/OpusEngineList.js index 2aa7f17fc..447f0afdb 100644 --- a/src/client/voice/opus/OpusEngineList.js +++ b/src/client/voice/opus/OpusEngineList.js @@ -5,9 +5,9 @@ const list = [ let opusEngineFound; -function fetch(Encoder) { +function fetch(Encoder, engineOptions) { try { - return new Encoder(); + return new Encoder(engineOptions); } catch (err) { return null; } @@ -17,9 +17,9 @@ exports.add = encoder => { list.push(encoder); }; -exports.fetch = () => { +exports.fetch = engineOptions => { for (const encoder of list) { - const fetched = fetch(encoder); + const fetched = fetch(encoder, engineOptions); if (fetched) return fetched; } return null;