mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
Potential FFMPEG process fix (#381)
I am by no means sure that this will work. This is an experimental fix. Please review it carefully; I’m not the best at working with audio/streams.
This commit is contained in:
@@ -1605,9 +1605,9 @@ var InternalClient = (function () {
|
|||||||
data = {
|
data = {
|
||||||
name: data.name || channel.name,
|
name: data.name || channel.name,
|
||||||
topic: data.topic || channel.topic,
|
topic: data.topic || channel.topic,
|
||||||
position: data.position || channel.position,
|
position: data.position ? data.position : channel.position,
|
||||||
user_limit: data.userLimit || channel.userLimit,
|
user_limit: data.userLimit ? data.userLimit : channel.userLimit,
|
||||||
bitrate: data.bitrate || channel.bitrate
|
bitrate: data.bitrate ? data.bitrate : channel.bitrate
|
||||||
};
|
};
|
||||||
|
|
||||||
if (data.position < 0) {
|
if (data.position < 0) {
|
||||||
|
|||||||
@@ -6,23 +6,23 @@ exports.__esModule = true;
|
|||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var TokenCacher = (function () {
|
var TokenCacher = (function () {
|
||||||
function TokenCacher() {
|
function TokenCacher() {
|
||||||
_classCallCheck(this, TokenCacher);
|
_classCallCheck(this, TokenCacher);
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenCacher.prototype.setToken = function setToken() {};
|
TokenCacher.prototype.setToken = function setToken() {};
|
||||||
|
|
||||||
TokenCacher.prototype.save = function save() {};
|
TokenCacher.prototype.save = function save() {};
|
||||||
|
|
||||||
TokenCacher.prototype.getToken = function getToken() {
|
TokenCacher.prototype.getToken = function getToken() {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
TokenCacher.prototype.init = function init(ind) {
|
TokenCacher.prototype.init = function init(ind) {
|
||||||
this.done = true;
|
this.done = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
return TokenCacher;
|
return TokenCacher;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
exports["default"] = TokenCacher;
|
exports["default"] = TokenCacher;
|
||||||
|
|||||||
@@ -91,34 +91,7 @@ var AudioEncoder = (function () {
|
|||||||
|
|
||||||
stream.pipe(enc.stdin);
|
stream.pipe(enc.stdin);
|
||||||
|
|
||||||
var ffmpegErrors = "";
|
hookEncodingProcess(resolve, reject, enc, stream);
|
||||||
|
|
||||||
enc.stdout.pipe(_this.volume);
|
|
||||||
enc.stderr.on("data", function (data) {
|
|
||||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
|
||||||
});
|
|
||||||
enc.once("exit", function (code, signal) {
|
|
||||||
if (code) {
|
|
||||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_this.volume.once("readable", function () {
|
|
||||||
resolve({
|
|
||||||
proc: enc,
|
|
||||||
stream: _this.volume,
|
|
||||||
instream: stream,
|
|
||||||
channels: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
_this.volume.on("end", function () {
|
|
||||||
reject("end");
|
|
||||||
});
|
|
||||||
|
|
||||||
_this.volume.on("close", function () {
|
|
||||||
reject("close");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,33 +103,7 @@ var AudioEncoder = (function () {
|
|||||||
|
|
||||||
var enc = _child_process2["default"].spawn(_this2.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']);
|
var enc = _child_process2["default"].spawn(_this2.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ss', options.seek || 0, '-ac', 2, 'pipe:1']);
|
||||||
|
|
||||||
var ffmpegErrors = "";
|
hookEncodingProcess(resolve, reject, enc);
|
||||||
|
|
||||||
enc.stdout.pipe(_this2.volume);
|
|
||||||
enc.stderr.on("data", function (data) {
|
|
||||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
|
||||||
});
|
|
||||||
enc.once("exit", function (code, signal) {
|
|
||||||
if (code) {
|
|
||||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_this2.volume.once("readable", function () {
|
|
||||||
resolve({
|
|
||||||
proc: enc,
|
|
||||||
stream: _this2.volume,
|
|
||||||
channels: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
_this2.volume.on("end", function () {
|
|
||||||
reject("end");
|
|
||||||
});
|
|
||||||
|
|
||||||
_this2.volume.on("close", function () {
|
|
||||||
reject("close");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -170,33 +117,60 @@ var AudioEncoder = (function () {
|
|||||||
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
var options = ffmpegOptions.concat(['-f', 's16le', '-ar', '48000', '-ac', 2, 'pipe:1']);
|
||||||
var enc = _child_process2["default"].spawn(_this3.getCommand(), options);
|
var enc = _child_process2["default"].spawn(_this3.getCommand(), options);
|
||||||
|
|
||||||
var ffmpegErrors = "";
|
hookEncodingProcess(resolve, reject, enc);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
enc.stdout.pipe(_this3.volume);
|
AudioEncoder.prototype.hookEncodingProcess = function hookEncodingProcess(resolve, reject, enc, stream) {
|
||||||
enc.stderr.on("data", function (data) {
|
var _this4 = this;
|
||||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
|
||||||
});
|
|
||||||
enc.once("exit", function (code, signal) {
|
|
||||||
if (code) {
|
|
||||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
_this3.volume.once("readable", function () {
|
var processKilled = false;
|
||||||
resolve({
|
|
||||||
proc: enc,
|
|
||||||
stream: _this3.volume,
|
|
||||||
channels: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
_this3.volume.on("end", function () {
|
function killProcess() {
|
||||||
reject("end");
|
if (processKilled) return;
|
||||||
});
|
|
||||||
|
|
||||||
_this3.volume.on("close", function () {
|
enc.stdin.pause();
|
||||||
reject("close");
|
enc.kill("SIGINT");
|
||||||
});
|
|
||||||
|
processKilled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ffmpegErrors = "";
|
||||||
|
|
||||||
|
enc.stdout.pipe(this.volume);
|
||||||
|
enc.stderr.on("data", function (data) {
|
||||||
|
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
||||||
|
});
|
||||||
|
enc.once("exit", function (code, signal) {
|
||||||
|
if (code) {
|
||||||
|
reject(new Error("FFMPEG: " + ffmpegErrors));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.volume.once("readable", function () {
|
||||||
|
var data = {
|
||||||
|
proc: enc,
|
||||||
|
stream: _this4.volume,
|
||||||
|
channels: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
|
data.instream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.volume.on("end", function () {
|
||||||
|
killProcess();
|
||||||
|
|
||||||
|
reject("end");
|
||||||
|
});
|
||||||
|
|
||||||
|
this.volume.on("close", function () {
|
||||||
|
killProcess();
|
||||||
|
|
||||||
|
reject("close");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -73,34 +73,7 @@ export default class AudioEncoder {
|
|||||||
|
|
||||||
stream.pipe(enc.stdin);
|
stream.pipe(enc.stdin);
|
||||||
|
|
||||||
var ffmpegErrors = "";
|
hookEncodingProcess(resolve, reject, enc, stream);
|
||||||
|
|
||||||
enc.stdout.pipe(this.volume);
|
|
||||||
enc.stderr.on("data", (data) => {
|
|
||||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
|
||||||
});
|
|
||||||
enc.once("exit", (code, signal) => {
|
|
||||||
if (code) {
|
|
||||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.volume.once("readable", () => {
|
|
||||||
resolve({
|
|
||||||
proc: enc,
|
|
||||||
stream: this.volume,
|
|
||||||
instream: stream,
|
|
||||||
channels: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.volume.on("end", () => {
|
|
||||||
reject("end");
|
|
||||||
});
|
|
||||||
|
|
||||||
this.volume.on("close", () => {
|
|
||||||
reject("close");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,33 +90,7 @@ export default class AudioEncoder {
|
|||||||
'pipe:1'
|
'pipe:1'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var ffmpegErrors = "";
|
hookEncodingProcess(resolve, reject, enc);
|
||||||
|
|
||||||
enc.stdout.pipe(this.volume);
|
|
||||||
enc.stderr.on("data", (data) => {
|
|
||||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
|
||||||
});
|
|
||||||
enc.once("exit", (code, signal) => {
|
|
||||||
if (code) {
|
|
||||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.volume.once("readable", () => {
|
|
||||||
resolve({
|
|
||||||
proc: enc,
|
|
||||||
stream: this.volume,
|
|
||||||
channels: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.volume.on("end", () => {
|
|
||||||
reject("end");
|
|
||||||
});
|
|
||||||
|
|
||||||
this.volume.on("close", () => {
|
|
||||||
reject("close");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,33 +107,59 @@ export default class AudioEncoder {
|
|||||||
]);
|
]);
|
||||||
var enc = cpoc.spawn(this.getCommand(), options);
|
var enc = cpoc.spawn(this.getCommand(), options);
|
||||||
|
|
||||||
var ffmpegErrors = "";
|
hookEncodingProcess(resolve, reject, enc);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
enc.stdout.pipe(this.volume);
|
hookEncodingProcess(resolve, reject, enc, stream) {
|
||||||
enc.stderr.on("data", (data) => {
|
var processKilled = false;
|
||||||
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
|
||||||
});
|
|
||||||
enc.once("exit", (code, signal) => {
|
|
||||||
if (code) {
|
|
||||||
reject(new Error("FFMPEG: " + ffmpegErrors));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
this.volume.once("readable", () => {
|
function killProcess() {
|
||||||
resolve({
|
if (processKilled)
|
||||||
proc: enc,
|
return;
|
||||||
stream: this.volume,
|
|
||||||
channels: 2
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.volume.on("end", () => {
|
enc.stdin.pause();
|
||||||
reject("end");
|
enc.kill("SIGINT");
|
||||||
});
|
|
||||||
|
|
||||||
this.volume.on("close", () => {
|
processKilled = true;
|
||||||
reject("close");
|
}
|
||||||
});
|
|
||||||
|
var ffmpegErrors = "";
|
||||||
|
|
||||||
|
enc.stdout.pipe(this.volume);
|
||||||
|
enc.stderr.on("data", (data) => {
|
||||||
|
ffmpegErrors += "\n" + new Buffer(data).toString().trim();
|
||||||
|
});
|
||||||
|
enc.once("exit", (code, signal) => {
|
||||||
|
if (code) {
|
||||||
|
reject(new Error("FFMPEG: " + ffmpegErrors));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.volume.once("readable", () => {
|
||||||
|
var data = {
|
||||||
|
proc: enc,
|
||||||
|
stream: this.volume,
|
||||||
|
channels: 2
|
||||||
|
};
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
|
data.instream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.volume.on("end", () => {
|
||||||
|
killProcess();
|
||||||
|
|
||||||
|
reject("end");
|
||||||
|
});
|
||||||
|
|
||||||
|
this.volume.on("close", () => {
|
||||||
|
killProcess();
|
||||||
|
|
||||||
|
reject("close");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user