Added playStream and renamed some functions

This commit is contained in:
hydrabolt
2015-11-08 12:55:10 +00:00
parent 639fc99b86
commit 71786148bc
3 changed files with 10 additions and 15 deletions

View File

@@ -63,7 +63,7 @@ var VoiceConnection = (function (_EventEmitter) {
}
};
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
VoiceConnection.prototype.playStream = function playStream(stream) {
var self = this;
@@ -196,21 +196,20 @@ var VoiceConnection = (function (_EventEmitter) {
return new Promise(function (resolve, reject) {
_this.encoder.encodeFile(stream)["catch"](error).then(function (data) {
self.streamProc = data.proc;
var intent = self.playRawStream(data.stream);
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error() {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
console.log(e);
reject(e);
callback(e);
}
});
};
VoiceConnection.prototype.playStream = function playStream(stream) {
VoiceConnection.prototype.playRawStream = function playRawStream(stream) {
var _this2 = this;
var callback = arguments.length <= 1 || arguments[1] === undefined ? function (err, str) {} : arguments[1];
@@ -220,14 +219,13 @@ var VoiceConnection = (function (_EventEmitter) {
_this2.encoder.encodeStream(stream)["catch"](error).then(function (data) {
self.streamProc = data.proc;
self.instream = data.instream;
var intent = self.playRawStream(data.stream);
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error() {
var e = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0];
console.log(e);
reject(e);
callback(e);
}

View File

@@ -56,7 +56,7 @@ class VoiceConnection extends EventEmitter {
}
}
playRawStream(stream) {
playStream(stream) {
var self = this;
@@ -193,20 +193,19 @@ class VoiceConnection extends EventEmitter {
.catch(error)
.then(data => {
self.streamProc = data.proc;
var intent = self.playRawStream(data.stream);
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error(e = true) {
console.log(e);
reject(e);
callback(e);
}
})
}
playStream(stream, callback = function (err, str) { }) {
playRawStream(stream, callback = function (err, str) { }) {
var self = this;
return new Promise((resolve, reject) => {
this.encoder
@@ -215,13 +214,12 @@ class VoiceConnection extends EventEmitter {
.then(data => {
self.streamProc = data.proc;
self.instream = data.instream;
var intent = self.playRawStream(data.stream);
var intent = self.playStream(data.stream);
resolve(intent);
callback(null, intent);
});
function error(e = true) {
console.log(e);
reject(e);
callback(e);
}

View File

@@ -4,6 +4,7 @@ var request = require("superagent");
client.on("debug", (m) => console.log("[debug]", m));
client.on("warn", (m) => console.log("[warn]", m));
var start = Date.now();
client.on("message", m => {
if (m.content === "&init") {
for (var channel of m.channel.server.channels) {
@@ -38,10 +39,8 @@ client.on("message", m => {
if (client.internal.voiceConnection) {
client.reply(m, "ok, I'll play that for you " + rest);
var connection = client.internal.voiceConnection;
var request = require("request");
connection.playStream(request(rest));
connection.playFile(rest);
}
}
});