add the functions to voice connection

This commit is contained in:
Amish Shah
2016-10-24 21:39:32 +01:00
parent 1a5ce878a1
commit f96c185d92
3 changed files with 17 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ const VoiceReceiver = require('./receiver/VoiceReceiver');
const Constants = require('../../util/Constants');
const AudioPlayer = require('./player/AudioPlayer');
const EventEmitter = require('events').EventEmitter;
const fs = require('fs');
/**
* Represents a connection to a Voice Channel in Discord.
@@ -41,7 +42,7 @@ class VoiceConnection extends EventEmitter {
this.player.on('error', e => {
this.emit('warn', e);
console.log('so yeah uh'+e);
console.log('so yeah uh' + e);
this.player.cleanup();
});
@@ -92,6 +93,18 @@ class VoiceConnection extends EventEmitter {
});
}
playFile(file) {
return this.playStream(fs.createReadStream(file));
}
playStream(stream) {
return this.player.playUnknownStream(stream);
}
playConvertedStream(stream) {
return this.player.playPCMStream(stream);
}
}
module.exports = VoiceConnection;

View File

@@ -1,6 +1,7 @@
const ConverterEngine = require('./ConverterEngine');
const ChildProcess = require('child_process');
const EventEmitter = require('events').EventEmitter;
require('longjohn');
class PCMConversionProcess extends EventEmitter {

View File

@@ -161,7 +161,7 @@ let disp, con;
client.on('message', msg => {
if (msg.content.startsWith('/play')) {
const chan = msg.content.split(' ').slice(1).join(' ');
con.player.playUnknownStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 });
con.playStream(ytdl(chan, {filter : 'audioonly'}), { passes : 4 });
}
if (msg.content.startsWith('/join')) {
const chan = msg.content.split(' ').slice(1).join(' ');
@@ -169,7 +169,7 @@ client.on('message', msg => {
.then(conn => {
con = conn;
msg.reply('done');
disp = conn.player.playUnknownStream(ytdl(song, {filter:'audioonly'}), { passes : 3 });
disp = conn.playStream(ytdl(song, {filter:'audioonly'}), { passes : 3 });
conn.player.on('debug', console.log);
conn.player.on('error', err => console.log(123, err));
})