diff --git a/lib/tasks/rest_dial.js b/lib/tasks/rest_dial.js index 926de3d3..cf08801a 100644 --- a/lib/tasks/rest_dial.js +++ b/lib/tasks/rest_dial.js @@ -27,7 +27,7 @@ class TaskRestDial extends Task { */ async exec(cs) { await super.exec(cs); - this.req = cs.req; + this.canCancel = true; this._setCallTimer(); await this.awaitTaskDone(); @@ -36,15 +36,15 @@ class TaskRestDial extends Task { kill(cs) { super.kill(cs); this._clearCallTimer(); - if (this.req) { - this.req.cancel(); - this.req = null; + if (this.canCancel && cs?.req) { + this.canCancel = false; + cs.req.cancel(); } this.notifyTaskDone(); } async _onConnect(dlg) { - this.req = null; + this.canCancel = false; const cs = this.callSession; cs.setDialog(dlg); @@ -79,7 +79,7 @@ class TaskRestDial extends Task { _onCallStatus(status) { this.logger.debug(`CallStatus: ${status}`); if (status >= 200) { - this.req = null; + this.canCancel = false; this._clearCallTimer(); if (status !== 200) this.notifyTaskDone(); }