Skip to content

Commit

Permalink
Fix delayed voice feeds (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
abalabahaha committed Aug 8, 2016
1 parent 534e293 commit 0ea7868
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/core/VoiceConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ class VoiceConnection extends EventEmitter {
options = options || {};
options.startOffset = options.startOffset || 0;
var encoder = ChildProcess.spawn(this.converterCommand, [
"-analyzeduration", "0",
"-re",
"-vn",
"-analyzeduration", "0",
"-loglevel", "0",
"-i", "-",
Expand All @@ -346,7 +349,7 @@ class VoiceConnection extends EventEmitter {
this.emit("error", err);
}
}
if(this.volumeTransformer && this.volumeTransformer.attached) {
if(this.volumeTransformer.attached) {
try {
this.volumeTransformer.unattach();
} catch(err) {
Expand All @@ -363,6 +366,7 @@ class VoiceConnection extends EventEmitter {
encoder.stdin.on("error", onError);

encoder.stdout.on("error", onError);
encoder.stdout.on("end", onError);

var stdout = encoder.stdout;

Expand Down Expand Up @@ -442,6 +446,7 @@ class VoiceConnection extends EventEmitter {

var startTime = Date.now();
var length = 20;
var packets = 0;
var waitingForData = 0;
var voiceDataTimeout = options.voiceDataTimeout !== undefined ? voiceDataTimeout : this.shard.client.options.voiceDataTimeout;
var buffer;
Expand Down Expand Up @@ -479,6 +484,7 @@ class VoiceConnection extends EventEmitter {
buffer = silence; // dead silence
this.setSpeaking(false);
} else if(!buffer || !this.playing || !this.ready) {
this.playing = false;
this.setSpeaking(false);
if(typeof source.destroy === "function") {
try {
Expand Down Expand Up @@ -507,7 +513,7 @@ class VoiceConnection extends EventEmitter {
}

if(this.sendPacket(this.createPacket(buffer))) {
return setTimeout(send, startTime + pausedTime + this.sequence * length - Date.now());
return setTimeout(send, startTime + pausedTime + ++packets * length - Date.now());
}

this.emit("end");
Expand All @@ -522,7 +528,7 @@ class VoiceConnection extends EventEmitter {
setTimeout(() => {
this.playing = true;
send();
}, 5 * length);
}, 15 * length);
} else {
this.playing = true;
send();
Expand Down

0 comments on commit 0ea7868

Please sign in to comment.