From 2de24af1692c915ad705703684802ca5ceba5bfd Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Tue, 4 Nov 2025 01:11:59 +0700 Subject: [PATCH] fixed gather does not start timeout on bargin (#1421) * fixed gather does not start timeout on bargin * with previous change, no need to emit playDone since no where in the code are we listening for it --------- Co-authored-by: Dave Horton --- lib/tasks/gather.js | 32 +++++++++++++++++--------------- lib/tasks/say.js | 2 -- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 1625c2c8..6ccfda36 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -270,19 +270,21 @@ class TaskGather extends SttTask { }; this.sayTask.span = span; this.sayTask.ctx = ctx; - this.sayTask.exec(cs, {ep}) // kicked off, _not_ waiting for it to complete + this.sayTask + .exec(cs, {ep}) // kicked off, _not_ waiting for it to complete + .then(() => { + if (this.sayTask.isStreamingTts) return; + this.logger.debug('Gather:exec - nested say task completed'); + span.end(); + process(); + return; + }) .catch((err) => { process(); }); if (this.sayTask.isStreamingTts && !this.sayTask.closeOnStreamEmpty) { // if streaming tts, we do not wait for it to complete if it is not closing the stream automatically process(); - } else { - this.sayTask.on('playDone', (err) => { - span.end(); - if (err) this.logger.error({err}, 'Gather:exec Error playing tts'); - process(); - }); } } else if (this.playTask) { @@ -306,15 +308,17 @@ class TaskGather extends SttTask { }; this.playTask.span = span; this.playTask.ctx = ctx; - this.playTask.exec(cs, {ep}) // kicked off, _not_ waiting for it to complete + this.playTask + .exec(cs, {ep}) // kicked off, _not_ waiting for it to complete + .then(() => { + this.logger.debug('Gather:exec - nested play task completed'); + span.end(); + process(); + return; + }) .catch((err) => { process(); }); - this.playTask.on('playDone', (err) => { - span.end(); - if (err) this.logger.error({err}, 'Gather:exec Error playing url'); - process(); - }); } else { if (this.killed) { @@ -882,12 +886,10 @@ class TaskGather extends SttTask { return; } if (this.sayTask && !this.sayTask.killed) { - this.sayTask.removeAllListeners('playDone'); this.sayTask.kill(cs); this.sayTask = null; } if (this.playTask && !this.playTask.killed) { - this.playTask.removeAllListeners('playDone'); this.playTask.kill(cs); this.playTask = null; } diff --git a/lib/tasks/say.js b/lib/tasks/say.js index ead7fc1f..2281e1e5 100644 --- a/lib/tasks/say.js +++ b/lib/tasks/say.js @@ -120,13 +120,11 @@ class TaskSay extends TtsTask { } if (this.isStreamingTts) await this.handlingStreaming(cs, obj); else await this.handling(cs, obj); - this.emit('playDone'); } catch (error) { if (error instanceof SpeechCredentialError) { // if say failed due to speech credentials, alarm is writtern and error notification is sent // finished this say to move to next task. this.logger.info({error}, 'Say failed due to SpeechCredentialError, finished!'); - this.emit('playDone'); return; } throw error;