mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 11:33:30 +01:00
Fixed voice_connection.stopPlaying
Now unpipes before destroying
This commit is contained in:
@@ -182,6 +182,7 @@ var Server = (function (_Equality) {
|
|||||||
this.eventStopSpeaking(user);
|
this.eventStopSpeaking(user);
|
||||||
|
|
||||||
channel.speaking.add(user);
|
channel.speaking.add(user);
|
||||||
|
user.voiceChannel = channel;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// bad
|
// bad
|
||||||
@@ -206,6 +207,7 @@ var Server = (function (_Equality) {
|
|||||||
|
|
||||||
if (chan.speaking.has(user)) {
|
if (chan.speaking.has(user)) {
|
||||||
chan.speaking.remove(user);
|
chan.speaking.remove(user);
|
||||||
|
user.voiceChannel = null;
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ var User = (function (_Equality) {
|
|||||||
since: null,
|
since: null,
|
||||||
channel: null
|
channel: null
|
||||||
};
|
};
|
||||||
|
this.voiceChannel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype.mention = function mention() {
|
User.prototype.mention = function mention() {
|
||||||
|
|||||||
@@ -102,12 +102,10 @@ var AudioEncoder = (function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("end", function () {
|
enc.stdout.on("end", function () {
|
||||||
console.log("end");
|
|
||||||
reject("end");
|
reject("end");
|
||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("close", function () {
|
enc.stdout.on("close", function () {
|
||||||
console.log("close");
|
|
||||||
reject("close");
|
reject("close");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -129,12 +127,10 @@ var AudioEncoder = (function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("end", function () {
|
enc.stdout.on("end", function () {
|
||||||
console.log("end");
|
|
||||||
reject("end");
|
reject("end");
|
||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("close", function () {
|
enc.stdout.on("close", function () {
|
||||||
console.log("close");
|
|
||||||
reject("close");
|
reject("close");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -43,6 +43,10 @@ var _events = require("events");
|
|||||||
|
|
||||||
var _events2 = _interopRequireDefault(_events);
|
var _events2 = _interopRequireDefault(_events);
|
||||||
|
|
||||||
|
var _unpipe = require("unpipe");
|
||||||
|
|
||||||
|
var _unpipe2 = _interopRequireDefault(_unpipe);
|
||||||
|
|
||||||
var VoiceConnection = (function (_EventEmitter) {
|
var VoiceConnection = (function (_EventEmitter) {
|
||||||
_inherits(VoiceConnection, _EventEmitter);
|
_inherits(VoiceConnection, _EventEmitter);
|
||||||
|
|
||||||
@@ -91,13 +95,10 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.playingIntent = null;
|
this.playingIntent = null;
|
||||||
if (this.streamProc) {
|
|
||||||
this.streamProc.stdin.pause();
|
|
||||||
this.streamProc.kill("SIGINT");
|
|
||||||
}
|
|
||||||
if (this.instream) {
|
if (this.instream) {
|
||||||
//not all streams implement these...
|
//not all streams implement these...
|
||||||
//and even file stream don't seem to implement them properly...
|
//and even file stream don't seem to implement them properly...
|
||||||
|
_unpipe2["default"](this.instream);
|
||||||
if (this.instream.end) {
|
if (this.instream.end) {
|
||||||
this.instream.end();
|
this.instream.end();
|
||||||
}
|
}
|
||||||
@@ -106,6 +107,11 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
}
|
}
|
||||||
this.instream = null;
|
this.instream = null;
|
||||||
}
|
}
|
||||||
|
if (this.streamProc) {
|
||||||
|
this.streamProc.stdin.pause();
|
||||||
|
this.streamProc.kill("SIGINT");
|
||||||
|
this.streamProc = null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceConnection.prototype.playStream = function playStream(stream) {
|
VoiceConnection.prototype.playStream = function playStream(stream) {
|
||||||
@@ -118,9 +124,6 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
|
|
||||||
var length = 20;
|
var length = 20;
|
||||||
|
|
||||||
if (self.playingIntent) {
|
|
||||||
self.stopPlaying();
|
|
||||||
}
|
|
||||||
self.playing = true;
|
self.playing = true;
|
||||||
var retStream = new _StreamIntent2["default"]();
|
var retStream = new _StreamIntent2["default"]();
|
||||||
var onWarning = false;
|
var onWarning = false;
|
||||||
@@ -318,7 +321,6 @@ var VoiceConnection = (function (_EventEmitter) {
|
|||||||
var _this4 = this;
|
var _this4 = this;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
console.log("\n\nendpoint:", this.endpoint, "\n\n");
|
|
||||||
_dns2["default"].lookup(this.endpoint, function (err, address, family) {
|
_dns2["default"].lookup(this.endpoint, function (err, address, family) {
|
||||||
var vWS = self.vWS = new _ws2["default"]("wss://" + _this4.endpoint, null, { rejectUnauthorized: false });
|
var vWS = self.vWS = new _ws2["default"]("wss://" + _this4.endpoint, null, { rejectUnauthorized: false });
|
||||||
_this4.endpoint = address;
|
_this4.endpoint = address;
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs-extra": "^0.26.2",
|
"fs-extra": "^0.26.2",
|
||||||
"superagent": "^1.5.0",
|
"superagent": "^1.5.0",
|
||||||
|
"unpipe": "^1.0.0",
|
||||||
"ws": "^0.8.1"
|
"ws": "^0.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ export default class Server extends Equality {
|
|||||||
this.eventStopSpeaking(user);
|
this.eventStopSpeaking(user);
|
||||||
|
|
||||||
channel.speaking.add(user);
|
channel.speaking.add(user);
|
||||||
|
user.voiceChannel = channel;
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
// bad
|
// bad
|
||||||
@@ -161,6 +162,7 @@ export default class Server extends Equality {
|
|||||||
for(let chan of this.channels.getAll("type", "voice")){
|
for(let chan of this.channels.getAll("type", "voice")){
|
||||||
if(chan.speaking.has(user)){
|
if(chan.speaking.has(user)){
|
||||||
chan.speaking.remove(user);
|
chan.speaking.remove(user);
|
||||||
|
user.voiceChannel = null;
|
||||||
return chan;
|
return chan;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export default class User extends Equality{
|
|||||||
since : null,
|
since : null,
|
||||||
channel : null
|
channel : null
|
||||||
};
|
};
|
||||||
|
this.voiceChannel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get avatarURL(){
|
get avatarURL(){
|
||||||
|
|||||||
@@ -97,12 +97,10 @@ export default class AudioEncoder {
|
|||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("end", function () {
|
enc.stdout.on("end", function () {
|
||||||
console.log("end");
|
|
||||||
reject("end");
|
reject("end");
|
||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("close", function () {
|
enc.stdout.on("close", function () {
|
||||||
console.log("close");
|
|
||||||
reject("close");
|
reject("close");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -130,12 +128,10 @@ export default class AudioEncoder {
|
|||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("end", function () {
|
enc.stdout.on("end", function () {
|
||||||
console.log("end");
|
|
||||||
reject("end");
|
reject("end");
|
||||||
});
|
});
|
||||||
|
|
||||||
enc.stdout.on("close", function () {
|
enc.stdout.on("close", function () {
|
||||||
console.log("close");
|
|
||||||
reject("close");
|
reject("close");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import AudioEncoder from "./AudioEncoder";
|
|||||||
import VoicePacket from "./VoicePacket";
|
import VoicePacket from "./VoicePacket";
|
||||||
import StreamIntent from "./StreamIntent";
|
import StreamIntent from "./StreamIntent";
|
||||||
import EventEmitter from "events";
|
import EventEmitter from "events";
|
||||||
|
import unpipe from "unpipe";
|
||||||
|
|
||||||
export default class VoiceConnection extends EventEmitter {
|
export default class VoiceConnection extends EventEmitter {
|
||||||
constructor(channel, client, session, token, server, endpoint) {
|
constructor(channel, client, session, token, server, endpoint) {
|
||||||
@@ -62,13 +63,10 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
stopPlaying() {
|
stopPlaying() {
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.playingIntent = null;
|
this.playingIntent = null;
|
||||||
if (this.streamProc) {
|
if (this.instream) {
|
||||||
this.streamProc.stdin.pause();
|
|
||||||
this.streamProc.kill("SIGINT");
|
|
||||||
}
|
|
||||||
if(this.instream){
|
|
||||||
//not all streams implement these...
|
//not all streams implement these...
|
||||||
//and even file stream don't seem to implement them properly...
|
//and even file stream don't seem to implement them properly...
|
||||||
|
unpipe(this.instream);
|
||||||
if(this.instream.end) {
|
if(this.instream.end) {
|
||||||
this.instream.end();
|
this.instream.end();
|
||||||
}
|
}
|
||||||
@@ -77,6 +75,11 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
}
|
}
|
||||||
this.instream = null;
|
this.instream = null;
|
||||||
}
|
}
|
||||||
|
if (this.streamProc) {
|
||||||
|
this.streamProc.stdin.pause();
|
||||||
|
this.streamProc.kill("SIGINT");
|
||||||
|
this.streamProc = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playStream(stream, channels=2) {
|
playStream(stream, channels=2) {
|
||||||
@@ -88,9 +91,6 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
|
|
||||||
var length = 20;
|
var length = 20;
|
||||||
|
|
||||||
if (self.playingIntent) {
|
|
||||||
self.stopPlaying();
|
|
||||||
}
|
|
||||||
self.playing = true;
|
self.playing = true;
|
||||||
var retStream = new StreamIntent();
|
var retStream = new StreamIntent();
|
||||||
var onWarning = false;
|
var onWarning = false;
|
||||||
@@ -282,7 +282,6 @@ export default class VoiceConnection extends EventEmitter {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
var self = this;
|
var self = this;
|
||||||
console.log("\n\nendpoint:", this.endpoint, "\n\n");
|
|
||||||
dns.lookup(this.endpoint, (err, address, family) => {
|
dns.lookup(this.endpoint, (err, address, family) => {
|
||||||
var vWS = self.vWS = new WebSocket("wss://" + this.endpoint, null, { rejectUnauthorized: false });
|
var vWS = self.vWS = new WebSocket("wss://" + this.endpoint, null, { rejectUnauthorized: false });
|
||||||
this.endpoint = address;
|
this.endpoint = address;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
var Discord = require("../");
|
var Discord = require("../");
|
||||||
var client = new Discord.Client({revive : true});
|
var client = new Discord.Client({revive : true});
|
||||||
var request = require("superagent");
|
var request = require("request");
|
||||||
|
|
||||||
client.on("ready", () => {
|
client.on("ready", () => {
|
||||||
console.log("ready - " + client.internal.token);
|
console.log("ready - " + client.internal.token);
|
||||||
@@ -30,11 +30,19 @@ client.on("message", msg => {
|
|||||||
msg.channel.server.channels.get("type", "voice").join();
|
msg.channel.server.channels.get("type", "voice").join();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.content === "end") {
|
if (msg.content === "$end$") {
|
||||||
client.destroy();
|
client.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.content === "who tf is speaking") {
|
if (msg.content === "$stop_playing") {
|
||||||
|
client.voiceConnection.stopPlaying();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.content === "where am I speaking") {
|
||||||
|
msg.reply(msg.sender.voiceChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.content === "who is speaking") {
|
||||||
for (var chan of msg.channel.server.channels.getAll("type", "voice")) {
|
for (var chan of msg.channel.server.channels.getAll("type", "voice")) {
|
||||||
msg.channel.send(`${chan} : ${chan.speaking}`);
|
msg.channel.send(`${chan} : ${chan.speaking}`);
|
||||||
}
|
}
|
||||||
@@ -52,7 +60,7 @@ client.on("message", msg => {
|
|||||||
if (msg.content.startsWith("$play")) {
|
if (msg.content.startsWith("$play")) {
|
||||||
var url = msg.content.split(" ")[1];
|
var url = msg.content.split(" ")[1];
|
||||||
|
|
||||||
client.voiceConnection.playFile(url, {
|
client.voiceConnection.playRawStream(request(url), {
|
||||||
volume : 0.1
|
volume : 0.1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user