From 76dd4f74dafdaccd9fd92ac1de39d9a4a61dfafc Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Sun, 2 Oct 2016 12:44:59 +0900 Subject: [PATCH] Fix arbitrary ffmpeg --- lib/Voice/AudioEncoder.js | 8 ++++---- lib/Voice/VoiceConnection.js | 17 ++++++++++------- src/Voice/AudioEncoder.js | 8 ++++---- src/Voice/VoiceConnection.js | 17 ++++++++++------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/Voice/AudioEncoder.js b/lib/Voice/AudioEncoder.js index 8f7728d22..9f4700134 100644 --- a/lib/Voice/AudioEncoder.js +++ b/lib/Voice/AudioEncoder.js @@ -124,11 +124,11 @@ var AudioEncoder = (function () { }); }; - AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, volume) { + AudioEncoder.prototype.encodeArbitraryFFmpeg = function encodeArbitraryFFmpeg(ffmpegOptions, options) { var _this3 = this; return new Promise(function (resolve, reject) { - _this3.volume = new _VolumeTransformer2["default"](volume); + _this3.volume = new _VolumeTransformer2["default"](options.volume); var command = _this3.getCommand(); @@ -136,8 +136,8 @@ var AudioEncoder = (function () { if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.')); // add options discord.js needs - var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']); - var enc = _child_process2["default"].spawn(command, options); + var ffmpegOptions = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']); + var enc = _child_process2["default"].spawn(command, ffmpegOptions); _this3.hookEncodingProcess(resolve, reject, enc); }); diff --git a/lib/Voice/VoiceConnection.js b/lib/Voice/VoiceConnection.js index bf7d78464..38c726187 100644 --- a/lib/Voice/VoiceConnection.js +++ b/lib/Voice/VoiceConnection.js @@ -324,23 +324,26 @@ var VoiceConnection = (function (_EventEmitter) { }); }; - VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, volume) { + VoiceConnection.prototype.playArbitraryFFmpeg = function playArbitraryFFmpeg(ffmpegOptions, options) { var _this3 = this; var callback = arguments.length <= 2 || arguments[2] === undefined ? function (err, str) {} : arguments[2]; var self = this; self.stopPlaying(); - if (typeof volume === "function") { - // volume is the callback - callback = volume; - } if (!ffmpegOptions instanceof Array) { ffmpegOptions = []; } - var volume = volume !== undefined ? volume : this.getVolume(); + if (typeof options === "function") { + // options is the callback + callback = options; + } + if (typeof options !== "object") { + options = {}; + } + options.volume = options.volume !== undefined ? options.volume : this.getVolume(); return new Promise(function (resolve, reject) { - _this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, volume)["catch"](error).then(function (data) { + _this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions, options)["catch"](error).then(function (data) { self.streamProc = data.proc; self.instream = data.instream; var intent = self.playStream(data.stream); diff --git a/src/Voice/AudioEncoder.js b/src/Voice/AudioEncoder.js index 302ea8a96..fcff4b40b 100644 --- a/src/Voice/AudioEncoder.js +++ b/src/Voice/AudioEncoder.js @@ -107,9 +107,9 @@ export default class AudioEncoder { }); } - encodeArbitraryFFmpeg(ffmpegOptions, volume) { + encodeArbitraryFFmpeg(ffmpegOptions, options) { return new Promise((resolve, reject) => { - this.volume = new VolumeTransformer(volume); + this.volume = new VolumeTransformer(options.volume); var command = this.getCommand(); @@ -117,13 +117,13 @@ export default class AudioEncoder { if (!command) return reject(new Error('FFMPEG not found. Make sure it is installed and in path.')); // add options discord.js needs - var options = ffmpegOptions.concat([ + var ffmpegOptions = ffmpegOptions.concat([ '-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1' ]); - var enc = cpoc.spawn(command, options); + var enc = cpoc.spawn(command, ffmpegOptions); this.hookEncodingProcess(resolve, reject, enc); }); diff --git a/src/Voice/VoiceConnection.js b/src/Voice/VoiceConnection.js index ee9981ab8..2750335cd 100755 --- a/src/Voice/VoiceConnection.js +++ b/src/Voice/VoiceConnection.js @@ -283,20 +283,23 @@ export default class VoiceConnection extends EventEmitter { }) } - playArbitraryFFmpeg(ffmpegOptions, volume, callback = function (err, str) { }) { + playArbitraryFFmpeg(ffmpegOptions, options, callback = function (err, str) { }) { var self = this; self.stopPlaying(); - if (typeof volume === "function") { - // volume is the callback - callback = volume; - } if (!ffmpegOptions instanceof Array) { ffmpegOptions = []; } - var volume = volume !== undefined ? volume : this.getVolume(); + if (typeof options === "function") { + // options is the callback + callback = options; + } + if (typeof options !== "object") { + options = {}; + } + options.volume = options.volume !== undefined ? options.volume : this.getVolume(); return new Promise((resolve, reject) => { this.encoder - .encodeArbitraryFFmpeg(ffmpegOptions, volume) + .encodeArbitraryFFmpeg(ffmpegOptions, options) .catch(error) .then(data => { self.streamProc = data.proc;