diff --git a/lib/session/call-session.js b/lib/session/call-session.js index aa0b6df7..7ea8ac53 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -796,7 +796,9 @@ class CallSession extends Emitter { } } - if (0 === this.tasks.length && this.requestor instanceof WsRequestor && !this.callGone) { + if (0 === this.tasks.length && ((this.requestor instanceof WsRequestor && !this.callGone) || + // Tasks are all done, but dialog is not establish yet, waiting for cancel/handup the call. + !this.dlg)) { //let span; try { //const {span} = this.rootSpan.startChildSpan('waiting for commands'); @@ -1790,6 +1792,17 @@ class CallSession extends Emitter { //this.logger.debug(`updating redis with ${JSON.stringify(this.callInfo)}`); this.updateCallStatus(Object.assign({}, this.callInfo.toJSON()), this.serviceUrl) .catch((err) => this.logger.error(err, 'redis error')); + + if (this.wakeupResolver && !this.dlg && this.isCurrentCallHigherThan(CallStatus.Failed)) { + // Someone is waiting for call to be final + this.wakeupResolver({reason: 'session ended'}); + this.wakeupResolver = null; + } + } + + isCurrentCallHigherThan(target) { + const obj = Object.values(CallStatus); + return obj.indexOf(this.callStatus) >= obj.indexOf(target); } async executeStatusCallback(callStatus, sipStatus) { diff --git a/lib/utils/constants.json b/lib/utils/constants.json index 7287ef02..4722f676 100644 --- a/lib/utils/constants.json +++ b/lib/utils/constants.json @@ -31,11 +31,12 @@ }, "AllowedSipRecVerbs": ["config", "gather", "transcribe", "listen"], "CallStatus": { + "Queued": "queued", "Trying": "trying", "Ringing": "ringing", "EarlyMedia": "early-media", "InProgress": "in-progress", - "Queued": "queued", + "Failed": "failed", "Busy": "busy", "NoAnswer": "no-answer",