From 6f62d7d8166bcb17d44ec1128699316b9224a1dc Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Sat, 25 Aug 2018 19:41:07 +0100 Subject: [PATCH] fix: voice not throwing errors on bad stream input (#2786) --- src/client/voice/util/PlayInterface.js | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/client/voice/util/PlayInterface.js b/src/client/voice/util/PlayInterface.js index 2a3712f49..58d31141e 100644 --- a/src/client/voice/util/PlayInterface.js +++ b/src/client/voice/util/PlayInterface.js @@ -63,19 +63,21 @@ class PlayInterface { if (!this.player.playBroadcast) throw new Error('VOICE_PLAY_INTERFACE_NO_BROADCAST'); return this.player.playBroadcast(resource, options); } - const type = options.type || 'unknown'; - if (type === 'unknown') { - return this.player.playUnknown(resource, options); - } else if (type === 'converted') { - return this.player.playPCMStream(resource, options); - } else if (type === 'opus') { - return this.player.playOpusStream(resource, options); - } else if (type === 'ogg/opus') { - if (!(resource instanceof Readable)) throw new Error('VOICE_PRISM_DEMUXERS_NEED_STREAM'); - return this.player.playOpusStream(resource.pipe(new prism.OggOpusDemuxer()), options); - } else if (type === 'webm/opus') { - if (!(resource instanceof Readable)) throw new Error('VOICE_PRISM_DEMUXERS_NEED_STREAM'); - return this.player.playOpusStream(resource.pipe(new prism.WebmOpusDemuxer()), options); + if (resource instanceof Readable || typeof resource === 'string') { + const type = options.type || 'unknown'; + if (type === 'unknown') { + return this.player.playUnknown(resource, options); + } else if (type === 'converted') { + return this.player.playPCMStream(resource, options); + } else if (type === 'opus') { + return this.player.playOpusStream(resource, options); + } else if (type === 'ogg/opus') { + if (!(resource instanceof Readable)) throw new Error('VOICE_PRISM_DEMUXERS_NEED_STREAM'); + return this.player.playOpusStream(resource.pipe(new prism.OggOpusDemuxer()), options); + } else if (type === 'webm/opus') { + if (!(resource instanceof Readable)) throw new Error('VOICE_PRISM_DEMUXERS_NEED_STREAM'); + return this.player.playOpusStream(resource.pipe(new prism.WebmOpusDemuxer()), options); + } } throw new Error('VOICE_PLAY_INTERFACE_BAD_TYPE'); }