tardis-bot/AudioQueue.js

23 lines
649 B
JavaScript
Raw Normal View History

2021-04-09 11:23:13 +00:00
module.exports = class AudioQueue {
constructor(connection) {
this.connection = connection;
this.queue = [];
this.current = undefined;
}
playNext() {
if (this.queue.length == 0) {
this.current = undefined;
return;
}
this.current = this.connection.play(this.queue[0]);
this.current.on('speaking', (val) => {if (val == 0) this.handleStop(this.current)});
}
handleStop(current) {
this.queue.shift();
this.playNext();
}
add(element) {
this.queue.push(element);
if (this.queue.length == 1) this.playNext();
}
}