diff --git a/lib/tasks/dial.js b/lib/tasks/dial.js index 8622bd4f..93b2595a 100644 --- a/lib/tasks/dial.js +++ b/lib/tasks/dial.js @@ -206,19 +206,21 @@ class TaskDial extends Task { _removeDtmfDetection(cs, ep) { if (ep) { delete ep.dtmfDetector; - ep.removeListener('dtmf', this._onDtmf.bind(this, cs, ep)); + ep.removeAllListeners('dtmf'); } } _onDtmf(cs, ep, evt) { - const match = ep.dtmfDetector.keyPress(evt.dtmf); - const requestor = ep.dtmfDetector === this.parentDtmfCollector ? - cs.requestor : - this.sd.requestor; - if (match) { - this.logger.debug(`parentCall triggered dtmf match: ${match}`); - requestor.request(this.dtmfHook, Object.assign({dtmf: match}, cs.callInfo)) - .catch((err) => this.logger.info(err, 'Dial:_onDtmf - error')); + if (ep.dtmfDetector) { + const match = ep.dtmfDetector.keyPress(evt.dtmf); + const requestor = ep.dtmfDetector === this.parentDtmfCollector ? + cs.requestor : + this.sd.requestor; + if (match) { + this.logger.debug(`parentCall triggered dtmf match: ${match}`); + requestor.request(this.dtmfHook, Object.assign({dtmf: match}, cs.callInfo)) + .catch((err) => this.logger.info(err, 'Dial:_onDtmf - error')); + } } }