Skip to content

Commit 2842b97

Browse files
committed
Throw errors on missing voice dependencies
1 parent 28fce9e commit 2842b97

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

lib/Voice/VoiceConnection.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,13 @@ var VoiceConnection = (function (_EventEmitter) {
233233
try {
234234
if (!self.encoder.opus) {
235235
self.playing = false;
236-
self.emit("error", "No Opus!");
237-
self.client.emit("debug", "Tried to use node-opus, but opus not available - install it!");
236+
throw new Error("node-opus not found! Perhaps you didn't install it.");
238237
return;
239238
}
240239

241240
if (!self.encoder.sanityCheck()) {
242241
self.playing = false;
243-
self.emit("error", "Opus sanity check failed!");
244-
self.client.emit("debug", "Opus sanity check failed - opus is installed but not correctly! Please reinstall opus and make sure it's installed correctly.");
242+
throw new Error("node-opus sanity check failed! Try re-installing node-opus.");
245243
return;
246244
}
247245

lib/Voice/VoicePacket.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22

33
exports.__esModule = true;
44

5-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
6-
75
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
86

9-
var _tweetnacl = require("tweetnacl");
10-
11-
var _tweetnacl2 = _interopRequireDefault(_tweetnacl);
7+
var nacl;
8+
try {
9+
nacl = require("tweetnacl");
10+
} catch (e) {
11+
// no tweetnacl!
12+
}
1213

1314
var nonce = new Buffer(24);
1415
nonce.fill(0);
1516

1617
var VoicePacket = function VoicePacket(data, sequence, time, ssrc, secret) {
1718
_classCallCheck(this, VoicePacket);
1819

20+
if (!nacl) {
21+
throw new Error("tweetnacl not found! Perhaps you didn't install it.");
22+
}
1923
var mac = secret ? 16 : 0;
2024
var packetLength = data.length + 12 + mac;
2125

@@ -33,7 +37,7 @@ var VoicePacket = function VoicePacket(data, sequence, time, ssrc, secret) {
3337
if (secret) {
3438
// copy first 12 bytes
3539
returnBuffer.copy(nonce, 0, 0, 12);
36-
audioBuffer = _tweetnacl2["default"].secretbox(data, nonce, secret);
40+
audioBuffer = nacl.secretbox(data, nonce, secret);
3741
}
3842

3943
for (var i = 0; i < audioBuffer.length; i++) {

src/Voice/VoiceConnection.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,13 @@ export default class VoiceConnection extends EventEmitter {
197197
try {
198198
if (!self.encoder.opus){
199199
self.playing=false;
200-
self.emit("error", "No Opus!");
201-
self.client.emit("debug", "Tried to use node-opus, but opus not available - install it!");
200+
throw new Error("node-opus not found! Perhaps you didn't install it.");
202201
return;
203202
}
204203

205204
if (!self.encoder.sanityCheck()) {
206205
self.playing = false;
207-
self.emit("error", "Opus sanity check failed!");
208-
self.client.emit("debug", "Opus sanity check failed - opus is installed but not correctly! Please reinstall opus and make sure it's installed correctly.");
206+
throw new Error("node-opus sanity check failed! Try re-installing node-opus.");
209207
return;
210208
}
211209

src/Voice/VoicePacket.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
"use strict";
22

3-
import nacl from "tweetnacl";
3+
var nacl;
4+
try {
5+
nacl = require("tweetnacl");
6+
} catch (e) {
7+
// no tweetnacl!
8+
}
49

510
const nonce = new Buffer(24);
611
nonce.fill(0);
712

813
export default class VoicePacket {
914
constructor(data, sequence, time, ssrc, secret){
15+
if(!nacl) {
16+
throw new Error("tweetnacl not found! Perhaps you didn't install it.");
17+
}
1018
var mac = secret ? 16 : 0;
1119
var packetLength = data.length + 12 + mac;
1220

0 commit comments

Comments
 (0)