From 4e8ac47f272bc15d79a8bea6b1ad02094732ebff Mon Sep 17 00:00:00 2001 From: Brian Tanner Date: Tue, 14 Jun 2016 00:20:26 -0400 Subject: [PATCH] fix econnreset in playRawStream (#427) --- lib/Voice/AudioEncoder.js | 9 ++++++++- src/Voice/AudioEncoder.js | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index 84ec8e004..d6a8b9505 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -89,7 +89,14 @@ var AudioEncoder = (function () { var enc = _child_process2["default"].spawn(_this.getCommand(), ['-i', '-', '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']); - stream.pipe(enc.stdin); + var dest = stream.pipe(enc.stdin); + + dest.on('unpipe', function () { + return dest.destroy(); + }); + dest.on('error', function (err) { + return dest.destroy(); + }); _this.hookEncodingProcess(resolve, reject, enc, stream); }); diff --git a/src/Voice/AudioEncoder.js b/src/Voice/AudioEncoder.js index ac4ac3335..18af17b77 100644 --- a/src/Voice/AudioEncoder.js +++ b/src/Voice/AudioEncoder.js @@ -71,7 +71,10 @@ export default class AudioEncoder { 'pipe:1' ]); - stream.pipe(enc.stdin); + var dest = stream.pipe(enc.stdin); + + dest.on('unpipe', () => dest.destroy()); + dest.on('error', err => dest.destroy()); this.hookEncodingProcess(resolve, reject, enc, stream); });