major refactoring

This commit is contained in:
Dave Horton
2020-01-25 11:47:33 -05:00
parent 621ea8c0f5
commit 4a1ea4e091
25 changed files with 947 additions and 933 deletions

View File

@@ -9,30 +9,28 @@ class TaskPlay extends Task {
this.url = this.data.url;
this.loop = this.data.loop || 1;
this.earlyMedia = this.data.earlyMedia === true;
this.playComplete = false;
}
get name() { return TaskName.Play; }
async exec(cs, ep) {
super.exec(cs);
this.ep = ep;
try {
while (!this.playComplete && this.loop--) {
while (!this.killed && this.loop--) {
await ep.play(this.url);
}
} catch (err) {
this.logger.info(err, `TaskPlay:exec - error playing ${this.url}`);
}
this.playComplete = true;
this.emit('playDone');
}
kill() {
async kill() {
super.kill();
if (this.ep.connected && !this.playComplete) {
this.logger.debug('TaskPlay:kill - killing audio');
this.playComplete = true;
this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
await this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
}
}
}