diff --git a/Voice.md b/Voice.md index 218bbf302..fd441016d 100644 --- a/Voice.md +++ b/Voice.md @@ -1,15 +1,40 @@ ## Voice -Voice in DiscordPHP has 2 main requirements: +Voice in DiscordPHP has 3 main requirements: - FFmpeg - DCA (Packaged with DiscordPHP) +- libsodium-php ### Encryption -Currently, encryption is only enabled if you have `libsodium` as well as `libsodium-php` installed. If you don't, your audio will be unencrypted. +Since Discord will be removing `plain` voice at the end of April, DiscordPHP requires libsodium and libsodium-php to be installed to encrypt the audio packets. -Unencrypted audio will be removed in the near future. It will throw an exception if it is not installed. +#### Mac + +1. Get [Homebrew](http://brew.sh/). +2. Install PHP with Homebrew if you haven't already. +3. `brew install libsodium` +4. `brew install homebrew/php/php**-libsodium` + +#### Ubuntu + +1. `wget https://github.com/jedisct1/libsodium/releases/download/1.0.10/libsodium-1.0.10.tar.gz` +2. `tar -xvzf libsodium-1.0.10.tar.gz && cd libsodium-1.0.10` +3. `./configure` +4. `make && sudo make install` + +If you have PECL installed: + +- `pecl install libsodium` + +Otherwise: + +1. `wget https://github.com/jedisct1/libsodium-php/archive/1.0.5.tar.gz` +2. `tar -xvzf 1.0.5.tar.gz && cd libsodium-php-1.0.5` +3. `phpize && ./configure` +4. `make && sudo make install` +5. `sudo sh -c 'echo "extension="$PWD"/modules/libsodium.so" >> $(php -r "echo php_ini_loaded_file(), PHP_EOL;")'` ### Installations diff --git a/src/Discord/Exceptions/LibSodiumNotFoundException.php b/src/Discord/Exceptions/LibSodiumNotFoundException.php new file mode 100644 index 000000000..1bb67b8a9 --- /dev/null +++ b/src/Discord/Exceptions/LibSodiumNotFoundException.php @@ -0,0 +1,19 @@ + + * + * This source file is subject to the MIT license that is bundled + * with this source code in the LICENSE.md file. + */ + +namespace Discord\Exceptions; + +/** + * Thrown when libsodium or libsodium-php cannot be found. + */ +class LibSodiumNotFoundException extends \Exception +{ +} diff --git a/src/Discord/Voice/VoiceClient.php b/src/Discord/Voice/VoiceClient.php index c5804a09e..9eafc9136 100644 --- a/src/Discord/Voice/VoiceClient.php +++ b/src/Discord/Voice/VoiceClient.php @@ -15,6 +15,7 @@ use Discord\Exceptions\FFmpegNotFoundException; use Discord\Exceptions\FileNotFoundException; use Discord\Exceptions\OutdatedDCAException; +use Discord\Exceptions\LibSodiumNotFoundException; use Discord\Helpers\Collection; use Discord\Helpers\Process; use Discord\Parts\Channel\Channel; @@ -392,7 +393,23 @@ public function initSockets($loop) $port = substr($message, strlen($message) - 2); $port = unpack('v', $port)[1]; - if (function_exists('\Sodium\crypto_secretbox')) { + if (! function_exists('\Sodium\crypto_secretbox')) { + $this->emit('error', [new LibSodiumNotFoundException('libsodium-php was not found.')]); + + $this->client->close(); + $this->voiceWebsocket->close(); + $this->mainWebsocket->send([ + 'op' => 4, + 'd' => [ + 'guild_id' => null, + 'channel_id' => null, + 'self_mute' => false, + 'self_deaf' => false, + ], + ]); + + return; + } else { $this->mode = 'xsalsa20_poly1305'; // voice encryption! $this->encrypted = true; }