From d8543f73f241dbd132c8c98df68e5d10da790670 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Tue, 18 Jul 2023 23:40:57 +0700 Subject: [PATCH] execute status callback async (#394) * execute status callback async * fix review comment * revert fix review comment --- lib/session/call-session.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 271d8dec..d48c451f 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -1781,6 +1781,15 @@ class CallSession extends Emitter { this.callInfo.updateCallStatus(callStatus, sipStatus, sipReason); if (typeof duration === 'number') this.callInfo.duration = duration; + this.executeStatusCallback(callStatus, sipStatus); + + // update calls db + //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')); + } + + async executeStatusCallback(callStatus, sipStatus) { const {span} = this.rootSpan.startChildSpan(`call-status:${this.callInfo.callStatus}`); span.setAttributes(this.callInfo.toJSON()); try { @@ -1792,11 +1801,6 @@ class CallSession extends Emitter { span.end(); this.logger.info(err, `CallSession:_notifyCallStatusChange error sending ${callStatus} ${sipStatus}`); } - - // update calls db - //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')); } async enableRecordAllCall() {