diff --git a/src/client/voice/VoiceBroadcast.js b/src/client/voice/VoiceBroadcast.js index 41aa1a082..c709eb64c 100644 --- a/src/client/voice/VoiceBroadcast.js +++ b/src/client/voice/VoiceBroadcast.js @@ -41,7 +41,7 @@ class VoiceBroadcast extends EventEmitter { * .catch(console.error); */ playFile(file, options) { - return this.player.playUnknownStream(`file:${file}`, options); + return this.player.playUnknown(file, options); } /** @@ -51,7 +51,7 @@ class VoiceBroadcast extends EventEmitter { * @returns {StreamDispatcher} */ playArbitraryInput(input, options) { - return this.player.playUnknownStream(input, options); + return this.player.playUnknown(input, options); } /** @@ -71,7 +71,7 @@ class VoiceBroadcast extends EventEmitter { * .catch(console.error); */ playStream(stream, options) { - return this.player.playUnknownStream(stream, options); + return this.player.playUnknown(stream, options); } /** diff --git a/src/client/voice/VoiceConnection.js b/src/client/voice/VoiceConnection.js index 8cea545f4..a270e1039 100644 --- a/src/client/voice/VoiceConnection.js +++ b/src/client/voice/VoiceConnection.js @@ -457,7 +457,7 @@ class VoiceConnection extends EventEmitter { * .catch(console.error); */ playFile(file, options) { - return this.player.playUnknownStream(`file:${file}`, options); + return this.player.playUnknown(file, options); } /** @@ -467,7 +467,7 @@ class VoiceConnection extends EventEmitter { * @returns {StreamDispatcher} */ playArbitraryInput(input, options) { - return this.player.playUnknownStream(input, options); + return this.player.playUnknown(input, options); } /** @@ -487,7 +487,7 @@ class VoiceConnection extends EventEmitter { * .catch(console.error); */ playStream(stream, options) { - return this.player.playUnknownStream(stream, options); + return this.player.playUnknown(stream, options); } /** diff --git a/src/client/voice/dispatcher/BroadcastDispatcher.js b/src/client/voice/dispatcher/BroadcastDispatcher.js index 902935cc4..330d05292 100644 --- a/src/client/voice/dispatcher/BroadcastDispatcher.js +++ b/src/client/voice/dispatcher/BroadcastDispatcher.js @@ -1,4 +1,3 @@ -const Collection = require('../../../util/Collection'); const StreamDispatcher = require('./StreamDispatcher'); /** diff --git a/src/client/voice/dispatcher/StreamDispatcher.js b/src/client/voice/dispatcher/StreamDispatcher.js index eae032c40..63f352304 100644 --- a/src/client/voice/dispatcher/StreamDispatcher.js +++ b/src/client/voice/dispatcher/StreamDispatcher.js @@ -147,7 +147,7 @@ class StreamDispatcher extends Writable { /** * Sets the expected packet loss percentage if using a compatible Opus stream. - * @param {number} value between 0 and 1 + * @param {number} value between 0 and 1 * @returns {boolean} Returns true if it was successfully set. */ setPLP(value) { @@ -158,7 +158,7 @@ class StreamDispatcher extends Writable { /** * Enables or disables forward error correction if using a compatible Opus stream. - * @param {boolean} enabled true to enable + * @param {boolean} enabled true to enable * @returns {boolean} Returns true if it was successfully set. */ setFEC(enabled) { diff --git a/src/client/voice/player/BasePlayer.js b/src/client/voice/player/BasePlayer.js index bb0de6bb7..59cfef916 100644 --- a/src/client/voice/player/BasePlayer.js +++ b/src/client/voice/player/BasePlayer.js @@ -1,4 +1,5 @@ const EventEmitter = require('events').EventEmitter; +const { Readable: ReadableStream } = require('stream'); const prism = require('prism-media'); const StreamDispatcher = require('../dispatcher/StreamDispatcher'); @@ -16,7 +17,7 @@ const FFMPEG_ARGUMENTS = [ * @extends {EventEmitter} */ class BasePlayer extends EventEmitter { - constructor(voiceConnection) { + constructor() { super(); this.dispatcher = null; @@ -39,10 +40,14 @@ class BasePlayer extends EventEmitter { } } - playUnknownStream(stream, options) { + playUnknown(input, options) { this.destroyDispatcher(); - const ffmpeg = new prism.FFmpeg({ args: FFMPEG_ARGUMENTS }); - stream.pipe(ffmpeg); + + 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 }); } diff --git a/src/client/voice/player/BroadcastAudioPlayer.js b/src/client/voice/player/BroadcastAudioPlayer.js index 41441276d..8a9071692 100644 --- a/src/client/voice/player/BroadcastAudioPlayer.js +++ b/src/client/voice/player/BroadcastAudioPlayer.js @@ -1,4 +1,3 @@ -const prism = require('prism-media'); const BroadcastDispatcher = require('../dispatcher/BroadcastDispatcher'); const BasePlayer = require('./BasePlayer'); diff --git a/typings b/typings index 697fc933d..5131e88ff 160000 --- a/typings +++ b/typings @@ -1 +1 @@ -Subproject commit 697fc933de90209b81b69bd0fe87883e3c7a217d +Subproject commit 5131e88ffe0b61c2f69318e53e54a3e3edec6f1e