Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add internal support for @discordjs/opus to v11 (#3700)
* Add internal support for @discordjs/opus * Remove redundant try/catch * fix: use setBitrate method in @discordjs/opus * chore: tidy up opus imports * fix: correct imports for DiscordJsOpusEngine * chore: update docs to prefer @discordjs/opus * chore: bump prism-media to 0.0.4 to allow ffmpeg-static
- Loading branch information
Showing
10 changed files
with
62 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const OpusEngine = require('./BaseOpusEngine'); | ||
|
||
class DiscordJsOpusEngine extends OpusEngine { | ||
constructor(player) { | ||
super(player); | ||
const opus = require('@discordjs/opus'); | ||
this.encoder = new opus.OpusEncoder(this.samplingRate, this.channels); | ||
super.init(); | ||
} | ||
|
||
setBitrate(bitrate) { | ||
this.encoder.setBitrate(Math.min(128, Math.max(16, bitrate)) * 1000); | ||
} | ||
|
||
setFEC(enabled) { | ||
this.encoder.applyEncoderCTL(this.ctl.FEC, enabled ? 1 : 0); | ||
} | ||
|
||
setPLP(percent) { | ||
this.encoder.applyEncoderCTL(this.ctl.PLP, Math.min(100, Math.max(0, percent * 100))); | ||
} | ||
|
||
encode(buffer) { | ||
super.encode(buffer); | ||
return this.encoder.encode(buffer, 1920); | ||
} | ||
|
||
decode(buffer) { | ||
super.decode(buffer); | ||
return this.encoder.decode(buffer, 1920); | ||
} | ||
} | ||
|
||
module.exports = DiscordJsOpusEngine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
const list = [ | ||
require('./DiscordJsOpusEngine'), | ||
require('./NodeOpusEngine'), | ||
require('./OpusScriptEngine'), | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters