Add audio queue
This commit is contained in:
23
AudioQueue.js
Normal file
23
AudioQueue.js
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user