mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
Fixed process removing
This commit is contained in:
@@ -26,8 +26,14 @@ var AudioEncoder = (function () {
|
|||||||
var enc = cpoc.spawn("ffmpeg", ["-i", file, "-f", "s16le", "-ar", "48000", "-ac", "1", "-af", "volume=1", "pipe:1"]);
|
var enc = cpoc.spawn("ffmpeg", ["-i", file, "-f", "s16le", "-ar", "48000", "-ac", "1", "-af", "volume=1", "pipe:1"]);
|
||||||
|
|
||||||
enc.stdout.on("readable", function () {
|
enc.stdout.on("readable", function () {
|
||||||
callback(null, enc.stdout);
|
callback(null, {
|
||||||
resolve(enc.stdout);
|
proc: enc,
|
||||||
|
stream: enc.stdout
|
||||||
|
});
|
||||||
|
resolve({
|
||||||
|
proc: enc,
|
||||||
|
stream: enc.stdout
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("end", function () {
|
enc.stdout.on("end", function () {
|
||||||
|
|||||||
@@ -39,11 +39,14 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
this.playingIntent = null;
|
this.playingIntent = null;
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.streamTime = 0;
|
this.streamTime = 0;
|
||||||
|
this.streamProc = null;
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
||||||
|
this.playing = false;
|
||||||
this.playingIntent = null;
|
this.playingIntent = null;
|
||||||
|
if (this.streamProc) this.streamProc.kill();
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
|
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
|
||||||
@@ -171,9 +174,10 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
_this.encoder.encodeFile(stream)["catch"](error).then(function (stream) {
|
_this.encoder.encodeFile(stream)["catch"](error).then(function (data) {
|
||||||
|
|
||||||
var intent = self.playRawStream(stream);
|
self.streamProc = data.proc;
|
||||||
|
var intent = self.playRawStream(data.stream);
|
||||||
resolve(intent);
|
resolve(intent);
|
||||||
callback(null, intent);
|
callback(null, intent);
|
||||||
});
|
});
|
||||||
|
|||||||
32
lib/index.js
32
lib/index.js
@@ -38,8 +38,7 @@ a.on("message", function (m) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m.content.startsWith("$$$")) {
|
if (m.content.startsWith("$$$ stop")) {
|
||||||
var chan;
|
|
||||||
for (var _iterator2 = m.channel.server.channels, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
for (var _iterator2 = m.channel.server.channels, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
||||||
var _ref2;
|
var _ref2;
|
||||||
|
|
||||||
@@ -61,7 +60,34 @@ a.on("message", function (m) {
|
|||||||
}
|
}
|
||||||
if (a.internal.voiceConnections[chan]) {
|
if (a.internal.voiceConnections[chan]) {
|
||||||
var connection = a.internal.voiceConnections[chan];
|
var connection = a.internal.voiceConnections[chan];
|
||||||
connection.playFile("C:/users/amish/desktop/audio.mp3");
|
connection.stopPlaying();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (m.content.startsWith("$$$")) {
|
||||||
|
var chan;
|
||||||
|
for (var _iterator3 = m.channel.server.channels, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
||||||
|
var _ref3;
|
||||||
|
|
||||||
|
if (_isArray3) {
|
||||||
|
if (_i3 >= _iterator3.length) break;
|
||||||
|
_ref3 = _iterator3[_i3++];
|
||||||
|
} else {
|
||||||
|
_i3 = _iterator3.next();
|
||||||
|
if (_i3.done) break;
|
||||||
|
_ref3 = _i3.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var channel = _ref3;
|
||||||
|
|
||||||
|
if (channel instanceof VoiceChannel) {
|
||||||
|
chan = channel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (a.internal.voiceConnections[chan]) {
|
||||||
|
var connection = a.internal.voiceConnections[chan];
|
||||||
|
connection.playFile("C:/users/amish/desktop/asdf.mp3");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,8 +28,14 @@ class AudioEncoder{
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
enc.stdout.on("readable", function() {
|
enc.stdout.on("readable", function() {
|
||||||
callback(null, enc.stdout);
|
callback(null, {
|
||||||
resolve(enc.stdout)
|
proc : enc,
|
||||||
|
stream : enc.stdout
|
||||||
|
});
|
||||||
|
resolve({
|
||||||
|
proc : enc,
|
||||||
|
stream : enc.stdout
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("end", function() {
|
enc.stdout.on("end", function() {
|
||||||
|
|||||||
@@ -31,11 +31,15 @@ class VoiceConnection extends EventEmitter{
|
|||||||
this.playingIntent = null;
|
this.playingIntent = null;
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.streamTime = 0;
|
this.streamTime = 0;
|
||||||
|
this.streamProc = null;
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
stopPlaying() {
|
stopPlaying() {
|
||||||
|
this.playing=false;
|
||||||
this.playingIntent = null;
|
this.playingIntent = null;
|
||||||
|
if(this.streamProc)
|
||||||
|
this.streamProc.kill();
|
||||||
}
|
}
|
||||||
|
|
||||||
playRawStream(stream) {
|
playRawStream(stream) {
|
||||||
@@ -166,9 +170,10 @@ class VoiceConnection extends EventEmitter{
|
|||||||
this.encoder
|
this.encoder
|
||||||
.encodeFile(stream)
|
.encodeFile(stream)
|
||||||
.catch(error)
|
.catch(error)
|
||||||
.then(stream => {
|
.then(data => {
|
||||||
|
|
||||||
var intent = self.playRawStream(stream);
|
self.streamProc = data.proc;
|
||||||
|
var intent = self.playRawStream(data.stream);
|
||||||
resolve(intent);
|
resolve(intent);
|
||||||
callback(null, intent);
|
callback(null, intent);
|
||||||
|
|
||||||
|
|||||||
15
src/index.js
15
src/index.js
@@ -20,6 +20,19 @@ a.on("message", m => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(m.content.startsWith("$$$ stop")){
|
||||||
|
for(var channel of m.channel.server.channels){
|
||||||
|
if(channel instanceof VoiceChannel){
|
||||||
|
chan = channel;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(a.internal.voiceConnections[chan]){
|
||||||
|
var connection = a.internal.voiceConnections[chan];
|
||||||
|
connection.stopPlaying();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(m.content.startsWith("$$$")){
|
if(m.content.startsWith("$$$")){
|
||||||
var chan;
|
var chan;
|
||||||
for(var channel of m.channel.server.channels){
|
for(var channel of m.channel.server.channels){
|
||||||
@@ -30,7 +43,7 @@ a.on("message", m => {
|
|||||||
}
|
}
|
||||||
if(a.internal.voiceConnections[chan]){
|
if(a.internal.voiceConnections[chan]){
|
||||||
var connection = a.internal.voiceConnections[chan];
|
var connection = a.internal.voiceConnections[chan];
|
||||||
connection.playFile("C:/users/amish/desktop/audio.mp3");
|
connection.playFile("C:/users/amish/desktop/asdf.mp3");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user