From c4c5ad33d8d673b725abb132acc9d7fc689c08bc Mon Sep 17 00:00:00 2001 From: Anton Voylenko Date: Tue, 17 Sep 2024 20:51:01 +0300 Subject: [PATCH] feat: loop dial music (#769) --- lib/tasks/dial.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index 52113724..f0936d1d 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -82,6 +82,8 @@ function filterAndLimit(logger, tasks) { return unique; } +const sleepFor = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms)); + class TaskDial extends Task { constructor(logger, opts) { super(logger, opts); @@ -203,7 +205,16 @@ class TaskDial extends Task { else { this.epOther = cs.ep; if (this.dialMusic && this.epOther && this.epOther.connected) { - this.epOther.play(this.dialMusic).catch((err) => {}); + (async() => { + do { + try { + await this.epOther.play(this.dialMusic); + } catch (err) { + this.logger.error(err, `TaskDial:exec error playing ${this.dialMusic}`); + await sleepFor(1000); + } + } while (!this.killed || !this.bridged); + })(); } } if (!this.killed) await this._attemptCalls(cs);