mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
voice fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -36,5 +36,4 @@ build/Release
|
||||
node_modules
|
||||
test/auth.json
|
||||
examples/auth.json
|
||||
test/msgbot.js
|
||||
docs/_build
|
||||
@@ -67,8 +67,7 @@ var AudioEncoder = (function () {
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||
"-af", "volume=1", "pipe:1", "-i", "-"]);
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ['-i', "-", '-f', 's16le', '-ar', '48000', '-ac', 1, 'pipe:1']);
|
||||
|
||||
stream.pipe(enc.stdin);
|
||||
|
||||
@@ -102,8 +101,7 @@ var AudioEncoder = (function () {
|
||||
|
||||
var self = this;
|
||||
return new Promise(function (resolve, reject) {
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ["-f", "s16le", "-ar", "48000", "-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||
"-af", "volume=1", "pipe:1", "-i", file]);
|
||||
var enc = _child_process2["default"].spawn(self.getCommand(), ['-i', file, '-f', 's16le', '-ar', '48000', '-ac', 1, 'pipe:1']);
|
||||
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
@@ -117,11 +115,13 @@ var AudioEncoder = (function () {
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function () {
|
||||
console.log("end");
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function () {
|
||||
console.log("close");
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
|
||||
@@ -122,11 +122,10 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
self.playingIntent = retStream;
|
||||
|
||||
function send() {
|
||||
|
||||
if (!self.playingIntent || !self.playing) {
|
||||
self.setSpeaking(false);
|
||||
retStream.emit("end");
|
||||
self;
|
||||
console.log("ending 1");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -137,6 +136,7 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
if (onWarning) {
|
||||
retStream.emit("end");
|
||||
self.setSpeaking(false);
|
||||
console.log("ending 2");
|
||||
return;
|
||||
} else {
|
||||
onWarning = true;
|
||||
|
||||
@@ -3,36 +3,36 @@
|
||||
import cpoc from "child_process";
|
||||
|
||||
var opus;
|
||||
try{
|
||||
try {
|
||||
opus = require("node-opus");
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
// no opus!
|
||||
}
|
||||
|
||||
export default class AudioEncoder {
|
||||
constructor(){
|
||||
if(opus){
|
||||
constructor() {
|
||||
if (opus) {
|
||||
this.opus = new opus.OpusEncoder(48000, 1);
|
||||
}
|
||||
this.choice = false;
|
||||
}
|
||||
|
||||
opusBuffer(buffer){
|
||||
opusBuffer(buffer) {
|
||||
|
||||
return this.opus.encode(buffer, 1920);
|
||||
|
||||
}
|
||||
|
||||
getCommand(force){
|
||||
getCommand(force) {
|
||||
|
||||
if(this.choice && force)
|
||||
if (this.choice && force)
|
||||
return choice;
|
||||
|
||||
var choices = ["avconv", "ffmpeg"];
|
||||
|
||||
for(var choice of choices){
|
||||
for (var choice of choices) {
|
||||
var p = cpoc.spawnSync(choice);
|
||||
if(!p.error){
|
||||
if (!p.error) {
|
||||
this.choice = choice;
|
||||
return choice;
|
||||
}
|
||||
@@ -41,74 +41,74 @@ export default class AudioEncoder {
|
||||
return "help";
|
||||
}
|
||||
|
||||
encodeStream(stream, callback=function(err, buffer){}){
|
||||
encodeStream(stream, callback = function (err, buffer) { }) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
var enc = cpoc.spawn(self.getCommand() , [
|
||||
"-f", "s16le",
|
||||
"-ar", "48000",
|
||||
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||
"-af", "volume=1",
|
||||
"pipe:1",
|
||||
"-i", "-"
|
||||
var enc = cpoc.spawn(self.getCommand(), [
|
||||
'-i', "-",
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-ac', 1,
|
||||
'pipe:1'
|
||||
]);
|
||||
|
||||
stream.pipe(enc.stdin);
|
||||
|
||||
enc.stdout.once("readable", function() {
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
proc : enc,
|
||||
stream : enc.stdout,
|
||||
instream : stream
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
instream: stream
|
||||
});
|
||||
resolve({
|
||||
proc : enc,
|
||||
stream : enc.stdout,
|
||||
instream : stream
|
||||
proc: enc,
|
||||
stream: enc.stdout,
|
||||
instream: stream
|
||||
});
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function() {
|
||||
enc.stdout.on("end", function () {
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function() {
|
||||
enc.stdout.on("close", function () {
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
encodeFile(file, callback=function(err, buffer){}){
|
||||
encodeFile(file, callback = function (err, buffer) { }) {
|
||||
var self = this;
|
||||
return new Promise((resolve, reject) => {
|
||||
var enc = cpoc.spawn(self.getCommand() , [
|
||||
"-f", "s16le",
|
||||
"-ar", "48000",
|
||||
"-ac", "1", // this can be 2 but there's no point, discord makes it mono on playback, wasted bandwidth.
|
||||
"-af", "volume=1",
|
||||
"pipe:1",
|
||||
"-i", file
|
||||
var enc = cpoc.spawn(self.getCommand(), [
|
||||
'-i', file,
|
||||
'-f', 's16le',
|
||||
'-ar', '48000',
|
||||
'-ac', 1,
|
||||
'pipe:1'
|
||||
]);
|
||||
|
||||
enc.stdout.once("readable", function() {
|
||||
enc.stdout.once("readable", function () {
|
||||
callback(null, {
|
||||
proc : enc,
|
||||
stream : enc.stdout
|
||||
proc: enc,
|
||||
stream: enc.stdout
|
||||
});
|
||||
resolve({
|
||||
proc : enc,
|
||||
stream : enc.stdout
|
||||
proc: enc,
|
||||
stream: enc.stdout
|
||||
});
|
||||
});
|
||||
|
||||
enc.stdout.on("end", function() {
|
||||
enc.stdout.on("end", function () {
|
||||
console.log("end");
|
||||
callback("end");
|
||||
reject("end");
|
||||
});
|
||||
|
||||
enc.stdout.on("close", function() {
|
||||
enc.stdout.on("close", function () {
|
||||
console.log("close");
|
||||
callback("close");
|
||||
reject("close");
|
||||
});
|
||||
|
||||
@@ -93,11 +93,10 @@ export default class VoiceConnection extends EventEmitter {
|
||||
self.playingIntent = retStream;
|
||||
|
||||
function send() {
|
||||
|
||||
if (!self.playingIntent || !self.playing) {
|
||||
self.setSpeaking(false);
|
||||
retStream.emit("end");
|
||||
self
|
||||
console.log("ending 1");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -108,6 +107,7 @@ export default class VoiceConnection extends EventEmitter {
|
||||
if (onWarning) {
|
||||
retStream.emit("end");
|
||||
self.setSpeaking(false);
|
||||
console.log("ending 2");
|
||||
return;
|
||||
} else {
|
||||
onWarning = true;
|
||||
|
||||
38
test/msgbot.js
Normal file
38
test/msgbot.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/* global describe */
|
||||
/* global process */
|
||||
|
||||
var Discord = require("../");
|
||||
var client = new Discord.Client();
|
||||
var request = require("request");
|
||||
|
||||
client.on("ready", () => {
|
||||
console.log("ready");
|
||||
});
|
||||
|
||||
client.on("message", msg => {
|
||||
|
||||
if(!msg.sender.equals(client.user))
|
||||
console.log("received message from " + msg.sender.username);
|
||||
|
||||
if (msg.content === "$bind") {
|
||||
msg.channel.server.channels.get("type", "voice").join();
|
||||
}
|
||||
|
||||
if (msg.content.startsWith("$play")) {
|
||||
var url = msg.content.split(" ")[1];
|
||||
|
||||
client.voiceConnection.playRawStream(request(url));
|
||||
|
||||
}
|
||||
|
||||
if (msg.content === "$$$") {
|
||||
client.sendMessage(msg.sender, "hi!");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
console.log("INIT");
|
||||
|
||||
client.on("debug", console.log)
|
||||
|
||||
client.login(process.env["ds_email"], process.env["ds_password"]).catch(console.log);
|
||||
Reference in New Issue
Block a user