diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index 60ef5c5b..d530f223 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -1,6 +1,13 @@ const Task = require('./task'); const makeTask = require('./make_task'); -const {CallStatus, CallDirection, TaskName, TaskPreconditions, MAX_SIMRINGS} = require('../utils/constants'); +const { + CallStatus, + CallDirection, + TaskName, + TaskPreconditions, + MAX_SIMRINGS, + KillReason +} = require('../utils/constants'); const assert = require('assert'); const placeCall = require('../utils/place-outdial'); const sessionTracker = require('../session/session-tracker'); @@ -140,7 +147,7 @@ class TaskDial extends Task { await this.awaitTaskDone(); this.logger.debug({callSid: this.cs.callSid}, 'Dial:exec task is done, sending actionHook if any'); - await this.performAction(this.results); + await this.performAction(this.results, this.killReason !== KillReason.Replaced); this._removeDtmfDetection(cs, this.epOther); this._removeDtmfDetection(cs, this.ep); } catch (err) { @@ -149,8 +156,9 @@ class TaskDial extends Task { } } - async kill(cs) { + async kill(cs, reason) { super.kill(cs); + this.killReason = reason || KillReason.Hangup; this._removeDtmfDetection(this.cs, this.epOther); this._removeDtmfDetection(this.cs, this.ep); this.logger.debug({callSid: this.cs.callSid}, 'Dial:kill removed dtmf listeners'); diff --git a/lib/tasks/enqueue.js b/lib/tasks/enqueue.js index 2f025b33..6d3106eb 100644 --- a/lib/tasks/enqueue.js +++ b/lib/tasks/enqueue.js @@ -63,8 +63,9 @@ class TaskEnqueue extends Task { async kill(cs, reason) { super.kill(cs); - this.logger.info(`TaskEnqueue:kill ${this.queueName}`); - this.emitter.emit('kill', reason || KillReason.Hangup); + this.killReason = reason || KillReason.Hangup; + this.logger.info(`TaskEnqueue:kill ${this.queueName} with reason ${this.killReason}`); + this.emitter.emit('kill'); this.notifyTaskDone(); } @@ -238,8 +239,7 @@ class TaskEnqueue extends Task { ep.unbridge().catch((err) => {}); resolve(); }) - .on('kill', (reason) => { - this.killReason = reason; + .on('kill', () => { this.logger.info(`TaskEnqueue:_bridgeLocal ending with ${this.killReason}`); ep.unbridge().catch((err) => {});