From fa7f391b3aac0a2a0a4313c97e24fc05a13e8f43 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Tue, 31 Oct 2017 18:12:49 +0000 Subject: [PATCH] Fix ECONNRESET (again) --- src/client/voice/dispatcher/StreamDispatcher.js | 6 +++--- src/client/voice/player/BasePlayer.js | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index 20650c128..1b24fae3a 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -59,9 +59,7 @@ class StreamDispatcher extends Writable { this._pausedTime = 0; this.count = 0; - this.on('error', err => this.destroy(err)); this.on('finish', () => { - this.end.bind(this); // Still emitting end for backwards compatibility, probably remove it in the future! this.emit('end'); }); @@ -73,9 +71,11 @@ class StreamDispatcher extends Writable { const streamError = err => { this.emit('warn', err); - this.destroy(err); + this.destroy(); }; + this.on('error', streamError); + if (this.streams.input) this.streams.input.on('error', streamError); if (this.streams.ffmpeg) this.streams.ffmpeg.on('error', streamError); if (this.streams.opus) this.streams.opus.on('error', streamError); if (this.streams.volume) this.streams.volume.on('error', streamError); diff --git a/src/client/voice/player/BasePlayer.js b/src/client/voice/player/BasePlayer.js index 59cfef916..fac2b68be 100644 --- a/src/client/voice/player/BasePlayer.js +++ b/src/client/voice/player/BasePlayer.js @@ -46,9 +46,12 @@ class BasePlayer extends EventEmitter { const isStream = input instanceof ReadableStream; const args = isStream ? FFMPEG_ARGUMENTS : ['-i', input, ...FFMPEG_ARGUMENTS]; const ffmpeg = new prism.FFmpeg({ args }); - if (isStream) input.pipe(ffmpeg); - - return this.playPCMStream(ffmpeg, options, { ffmpeg }); + const streams = { ffmpeg }; + if (isStream) { + streams.input = input; + input.pipe(ffmpeg); + } + return this.playPCMStream(ffmpeg, options, streams); } playPCMStream(stream, options, streams = {}) {