diff --git a/README.md b/README.md index b538e86eb..e09b2f039 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,9 @@ For production bots, using node-opus should be considered a necessity, especiall ### Optional packages - [bufferutil](https://www.npmjs.com/package/bufferutil) to greatly speed up the WebSocket when *not* using uws (`npm install bufferutil --save`) - [erlpack](https://github.com/hammerandchisel/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install hammerandchisel/erlpack --save`) -- [sodium](https://www.npmjs.com/package/sodium) for faster voice packet encryption/decryption (`npm install sodium --save`) +- for faster voice packet encryption/decryption you can install one of the following: + - [sodium](https://www.npmjs.com/package/sodium) (`npm install sodium --save`) + - [libsodium.js](https://www.npmjs.com/package/libsodium-wrappers) (`npm install libsodium-wrappers --save`) - [uws](https://www.npmjs.com/package/uws) for a much faster WebSocket connection (`npm install uws --save`) **Note:** This package does not handle disconnects entirely correctly, which causes automatic reconnection to Discord to not function. If you use this package, it may be wise to destroy + recreate the client entirely or restart the process upon disconnect. diff --git a/package.json b/package.json index 3af11cb48..c2e931301 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,8 @@ "node-opus": "^0.2.5", "opusscript": "^0.0.3", "sodium": "^2.0.1", - "uws": "^0.14.1" + "uws": "^0.14.1", + "libsodium-wrappers": "^0.5.1" }, "devDependencies": { "discord.js-docgen": "hydrabolt/discord.js-docgen", diff --git a/src/client/voice/util/Secretbox.js b/src/client/voice/util/Secretbox.js index dddb2c1a3..f1c8f03a8 100644 --- a/src/client/voice/util/Secretbox.js +++ b/src/client/voice/util/Secretbox.js @@ -1,13 +1,22 @@ -try { - const sodium = require('sodium'); - module.exports = { +const libs = { + sodium: sodium => ({ open: sodium.api.crypto_secretbox_open_easy, close: sodium.api.crypto_secretbox_easy, - }; -} catch (err) { - const tweetnacl = require('tweetnacl'); - module.exports = { + }), + 'libsodium-wrappers': sodium => ({ + open: sodium.crypto_secretbox_open_easy, + close: sodium.crypto_secretbox_easy, + }), + tweetnacl: tweetnacl => ({ open: tweetnacl.secretbox.open, close: tweetnacl.secretbox, - }; + }), +}; + +for (const libName of Object.keys(libs)) { + try { + const lib = require(libName); + module.exports = libs[libName](lib); + break; + } catch (err) {} // eslint-disable-line no-empty }