Minor fixes

This commit is contained in:
hydrabolt
2015-11-07 21:24:56 +00:00
parent fc31df3fcf
commit ae75c49621
9 changed files with 69 additions and 27 deletions

View File

@@ -532,6 +532,24 @@ var Client = (function (_EventEmitter) {
});
};
//def joinVoiceChannel
Client.prototype.joinVoiceChannel = function joinVoiceChannel(channel) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err) {} : arguments[1];
var self = this;
return new Promise(function (resolve, reject) {
self.internal.joinVoiceChannel(channel).then(function (chan) {
callback(null, chan);
resolve(chan);
})["catch"](function (err) {
callback(err);
reject(err);
});
});
};
_createClass(Client, [{
key: "users",
get: function get() {

View File

@@ -76,7 +76,10 @@ var InternalClient = (function () {
token = data.d.token;
endpoint = data.d.endpoint;
self.voiceConnections[channel] = new VoiceConnection(channel, self.client, session, token, server, endpoint);
var chan = self.voiceConnections[channel] = new VoiceConnection(channel, self.client, session, token, server, endpoint);
chan.on("ready", resolve);
chan.on("error", reject);
}
if (fired >= 2) {
self.websocket.removeListener('message', check);
@@ -774,7 +777,6 @@ var InternalClient = (function () {
}
request.put(Endpoints.CHANNEL_PERMISSIONS(channel.id) + "/" + data.id).set("authorization", self.token).send(data).end(function (err) {
console.log(err);
if (err) {
reject(err);
} else {

View File

@@ -25,8 +25,6 @@ var AudioEncoder = (function () {
return new Promise(function (resolve, reject) {
var enc = cpoc.spawn("ffmpeg", ["-i", file, "-f", "s16le", "-ar", "48000", "-ac", "1", "-af", "volume=1", "pipe:1"]);
var rcvd = 0;
enc.stdout.on("readable", function () {
callback(null, enc.stdout);
resolve(enc.stdout);

View File

@@ -2,6 +2,8 @@
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var WebSocket = require("ws");
var dns = require("dns");
var udp = require("dgram");
@@ -13,11 +15,15 @@ var ffmpeg = require('fluent-ffmpeg');
var AudioEncoder = require("./AudioEncoder.js");
var VoicePacket = require("./VoicePacket.js");
var StreamIntent = require("./StreamIntent.js");
var EventEmitter = require("events");
var VoiceConnection = (function (_EventEmitter) {
_inherits(VoiceConnection, _EventEmitter);
var VoiceConnection = (function () {
function VoiceConnection(channel, client, session, token, server, endpoint) {
_classCallCheck(this, VoiceConnection);
_EventEmitter.call(this);
this.voiceChannel = channel;
this.client = client;
this.session = session;
@@ -60,14 +66,12 @@ var VoiceConnection = (function () {
self.playingIntent = retStream;
function send() {
if (self.playingIntent && self.playingIntent !== retStream) {
console.log("ending it!");
if (!self.playingIntent) {
self.setSpeaking(false);
retStream.emit("end");
return;
}
try {
var buffer = stream.read(1920);
if (!buffer) {
@@ -147,7 +151,7 @@ var VoiceConnection = (function () {
return self.sendPacket(packet, callback);
} catch (e) {
self.playing = false;
console.log("etype", e.stack);
self.emit("error", e);
return false;
}
};
@@ -216,7 +220,6 @@ var VoiceConnection = (function () {
}
}
};
console.log("success!!!");
vWS.send(JSON.stringify(wsDiscPayload));
firstPacket = false;
}
@@ -252,16 +255,14 @@ var VoiceConnection = (function () {
var udpPacket = new Buffer(70);
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
udpClient.send(udpPacket, 0, udpPacket.length, data.d.port, self.endpoint, function (err) {
console.log("err", err);
if (err) self.emit("error", err);
});
break;
case 4:
self.ready = true;
self.mode = data.d.mode;
console.log("ready!!!");
self.test();
self.emit("ready", self);
break;
}
@@ -270,6 +271,6 @@ var VoiceConnection = (function () {
};
return VoiceConnection;
})();
})(EventEmitter);
module.exports = VoiceConnection;

View File

@@ -31,7 +31,9 @@ a.on("message", function (m) {
var channel = _ref;
if (channel instanceof VoiceChannel) {
a.internal.joinVoiceChannel(channel)["catch"](error);
a.joinVoiceChannel(channel)["catch"](error).then(function (connection) {
connection.playFile("C:/users/amish/desktop/asdf.mp3");
});
break;
}
}
@@ -58,14 +60,14 @@ a.on("message", function (m) {
}
}
if (a.internal.voiceConnections[chan]) {
connection = a.internal.voiceConnections[chan];
connection;
var connection = a.internal.voiceConnections[chan];
connection.playFile("C:/users/amish/desktop/audio.mp3");
}
}
});
function error(e) {
console.log(e);
console.log(e.stack);
process.exit(0);
}

View File

@@ -513,6 +513,24 @@ class Client extends EventEmitter {
})
}
//def joinVoiceChannel
joinVoiceChannel(channel, callback=function(err){}){
var self = this;
return new Promise((resolve, reject)=>{
self.internal.joinVoiceChannel(channel)
.then(chan => {
callback(null, chan);
resolve(chan);
})
.catch(err => {
callback(err);
reject(err);
});
});
}
}
module.exports = Client;

View File

@@ -67,7 +67,10 @@ class InternalClient {
token = data.d.token;
endpoint = data.d.endpoint;
self.voiceConnections[channel] = new VoiceConnection(channel, self.client, session, token, server, endpoint);
var chan = self.voiceConnections[channel] = new VoiceConnection(channel, self.client, session, token, server, endpoint);
chan.on("ready", resolve);
chan.on("error", reject);
}
if(fired >= 2){
@@ -822,7 +825,6 @@ class InternalClient {
.set("authorization", self.token)
.send(data)
.end(function (err) {
console.log(err);
if (err) {
reject(err);
} else {

View File

@@ -27,8 +27,6 @@ class AudioEncoder{
"pipe:1"
]);
var rcvd = 0;
enc.stdout.on("readable", function() {
callback(null, enc.stdout);
resolve(enc.stdout)

View File

@@ -12,7 +12,10 @@ a.on("message", m => {
if(m.content === "&init"){
for(var channel of m.channel.server.channels){
if(channel instanceof VoiceChannel){
a.internal.joinVoiceChannel(channel).catch(error);
a.joinVoiceChannel(channel).catch(error)
.then(connection => {
connection.playFile("C:/users/amish/desktop/asdf.mp3");
});
break;
}
}
@@ -26,14 +29,14 @@ a.on("message", m => {
}
}
if(a.internal.voiceConnections[chan]){
connection = a.internal.voiceConnections[chan];
connection
var connection = a.internal.voiceConnections[chan];
connection.playFile("C:/users/amish/desktop/audio.mp3");
}
}
});
function error(e){
console.log(e);
console.log(e.stack);
process.exit(0);
}