From 17586f0e206ee89c46ff00efe208d9adfb3f99f1 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Mon, 24 Oct 2016 17:41:37 +0100 Subject: [PATCH] maybe fix again --- src/client/voice/VoiceConnection.js | 5 +++++ src/client/voice/player/AudioPlayer.js | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/client/voice/VoiceConnection.js b/src/client/voice/VoiceConnection.js index 0e37e4e10..54ab5707c 100644 --- a/src/client/voice/VoiceConnection.js +++ b/src/client/voice/VoiceConnection.js @@ -39,6 +39,11 @@ class VoiceConnection extends EventEmitter { this.player = new AudioPlayer(this); + this.player.on('error', e => { + this.emit('warn', e); + this.player.cleanup(); + }); + /** * Object that wraps contains the `ws` and `udp` sockets of this voice connection * @type {object} diff --git a/src/client/voice/player/AudioPlayer.js b/src/client/voice/player/AudioPlayer.js index 73958c317..049aad659 100644 --- a/src/client/voice/player/AudioPlayer.js +++ b/src/client/voice/player/AudioPlayer.js @@ -23,12 +23,18 @@ class AudioPlayer extends EventEmitter { } playUnknownStream(stream) { + stream.on('end', () => { + + console.log(Date.now(), 'real input stream ended'); + }) const conversionProcess = this.audioToPCM.createConvertStream(0); stream.pipe(conversionProcess.process.stdin, { end: false }); return this.playPCMStream(conversionProcess.process.stdout, conversionProcess); } cleanup(checkStream) { + // cleanup is a lot less aggressive than v9 because it doesn't try to kill every single stream it is aware of + console.log(Date.now(), 'clean up triggered'); const filter = checkStream && this.currentDispatcher && this.currentDispatcher.stream === checkStream; if (this.currentConverter && (checkStream ? filter : true)) { if (this.currentConverter.process.stdin.destroy) { @@ -42,6 +48,10 @@ class AudioPlayer extends EventEmitter { } playPCMStream(stream, converter) { + stream.on('end', () => { + + console.log(Date.now(), 'pcm input stream ended'); + }) this.cleanup(); this.currentConverter = converter; if (this.currentDispatcher) {