Add audio queue

This commit is contained in:
2021-04-09 13:23:13 +02:00
parent 1fe978eec6
commit 75dc0c2da2
5 changed files with 33 additions and 3 deletions

23
AudioQueue.js Normal file
View File

@@ -0,0 +1,23 @@
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();
}
}