From 6b5f4fa7739f863dd7f179b60f8c171b336eb8be Mon Sep 17 00:00:00 2001 From: Programmix Date: Mon, 30 May 2016 11:13:01 -0700 Subject: [PATCH] FFMPEG fix (finally) (#390) Programmix sucks at this --- lib/Voice/AudioEncoder.js | 30 +++++++++++++++--------------- lib/Voice/VoiceConnection.js | 4 +++- src/Voice/AudioEncoder.js | 36 +++++++++++++++++++----------------- src/Voice/VoiceConnection.js | 4 +++- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index af8857363..a2d9af661 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -122,17 +122,17 @@ var AudioEncoder = (function () { }; AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) { - var _this4 = this; - var processKilled = false; - function killProcess() { + function killProcess(cause) { if (processKilled) return; enc.stdin.pause(); - enc.kill("SIGINT"); + enc.kill("SIGKILL"); processKilled = true; + + reject(cause); } var ffmpegErrors = ""; @@ -143,10 +143,12 @@ var AudioEncoder = (function () { ffmpegErrors += "\n" + new Buffer(data).toString().trim(); }); - enc.stdout.on("end", function () { - killProcess(); + enc.stdout.once("end", function () { + killProcess("end"); + }); - reject("end"); + enc.stdout.once("error", function () { + enc.stdout.emit("end"); }); enc.once("exit", function (code, signal) { @@ -170,21 +172,19 @@ var AudioEncoder = (function () { }); this.volume.once("end", function () { - killProcess(); + killProcess("end"); + }); - reject("end"); + this.volume.once("error", function () { + killProcess("end"); }); this.volume.on("end", function () { - killProcess(); - - reject("end"); + killProcess("end"); }); this.volume.on("close", function () { - killProcess(); - - reject("close"); + killProcess("close"); }); }; diff --git a/lib/Voice/VoiceConnection.js b/lib/Voice/VoiceConnection.js index 83c14f370..06e747c14 100644 --- a/lib/Voice/VoiceConnection.js +++ b/lib/Voice/VoiceConnection.js @@ -129,7 +129,7 @@ var VoiceConnection = (function (_EventEmitter) { } if (this.streamProc) { this.streamProc.stdin.pause(); - this.streamProc.kill("SIGINT"); + this.streamProc.kill("SIGKILL"); this.streamProc = null; } }; @@ -156,6 +156,7 @@ var VoiceConnection = (function (_EventEmitter) { } if (!self.playingIntent || !self.playing) { self.setSpeaking(false); + self.stopPlaying(); retStream.emit("end"); return; } @@ -166,6 +167,7 @@ var VoiceConnection = (function (_EventEmitter) { if (!buffer) { if (onWarning) { self.setSpeaking(false); + self.stopPlaying(); retStream.emit("end"); return; } else { diff --git a/src/Voice/AudioEncoder.js b/src/Voice/AudioEncoder.js index 5d4930ad6..48472c860 100644 --- a/src/Voice/AudioEncoder.js +++ b/src/Voice/AudioEncoder.js @@ -114,28 +114,32 @@ export default class AudioEncoder { hookEncodingProcess(resolve, reject, enc, stream) { var processKilled = false; - function killProcess() { + function killProcess(cause) { if (processKilled) return; enc.stdin.pause(); - enc.kill("SIGINT"); + enc.kill("SIGKILL"); processKilled = true; + + reject(cause); } var ffmpegErrors = ""; enc.stdout.pipe(this.volume); - enc.stderr.on("data", (data) => { + enc.stderr.on("data", function (data) { ffmpegErrors += "\n" + new Buffer(data).toString().trim(); }); - enc.stdout.on("end", () => { - killProcess(); + enc.stdout.once("end", () => { + killProcess("end"); + }); - reject("end"); + enc.stdout.once("error", () => { + enc.stdout.emit("end"); }); enc.once("exit", (code, signal) => { @@ -144,10 +148,10 @@ export default class AudioEncoder { } }); - this.volume.once("readable", () => { + this.volume.once("readable", function () { var data = { proc: enc, - stream: this.volume, + stream: _this4.volume, channels: 2 }; @@ -159,21 +163,19 @@ export default class AudioEncoder { }); this.volume.once("end", () => { - killProcess(); - - reject("end"); + killProcess("end"); }); - this.volume.on("end", () => { - killProcess(); + this.volume.once("error", () => { + killProcess("end"); + }) - reject("end"); + this.volume.on("end", () => { + killProcess("end"); }); this.volume.on("close", () => { - killProcess(); - - reject("close"); + killProcess("close"); }); } } diff --git a/src/Voice/VoiceConnection.js b/src/Voice/VoiceConnection.js index f0e685332..724048550 100644 --- a/src/Voice/VoiceConnection.js +++ b/src/Voice/VoiceConnection.js @@ -93,7 +93,7 @@ export default class VoiceConnection extends EventEmitter { } if (this.streamProc) { this.streamProc.stdin.pause(); - this.streamProc.kill("SIGINT"); + this.streamProc.kill("SIGKILL"); this.streamProc = null; } } @@ -118,6 +118,7 @@ export default class VoiceConnection extends EventEmitter { } if (!self.playingIntent || !self.playing) { self.setSpeaking(false); + self.stopPlaying(); retStream.emit("end"); return; } @@ -128,6 +129,7 @@ export default class VoiceConnection extends EventEmitter { if (!buffer) { if (onWarning) { self.setSpeaking(false); + self.stopPlaying(); retStream.emit("end"); return; } else {