From 70a09c10b38f98f5683b374b3f4bf83e94e7d189 Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Tue, 28 Oct 2025 20:58:54 +0000 Subject: [PATCH] Fix/200 (#202) * Update call-session.js * Update call-session.js --- lib/call-session.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/call-session.js b/lib/call-session.js index 2776019..b9bf5f1 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -1231,6 +1231,22 @@ Duration=${payload.duration} ` this.activeCallIds.delete(this.req.get('Call-ID')); if (this.activeCallIds.size === 0) this.idleEmitter.emit('idle'); uac.other.destroy(); + if (this.req.locals.cdr) { + const now = Date.now(); + const day = new Date(); + const recordAllCalls = this.req.locals.record_all_calls; + let recording_url = `/Accounts/${this.account_sid}/RecentCalls/${this.req.locals.cdr.call_sid}/record`; + recording_url += `/${day.getFullYear()}/${(day.getMonth() + 1).toString().padStart(2, '0')}`; + recording_url += `/${day.getDate().toString().padStart(2, '0')}/${recordAllCalls}`; + this.writeCdrs({...this.req.locals.cdr, + terminated_at: now, + termination_reason: 'caller hungup', + sip_status: 200, + answered: true, + duration: Math.floor((now - this.req.locals.cdr.answered_at) / 1000), + ...(recordAllCalls && {recording_url}) + }).catch((err) => this.logger.error({err}, 'Error writing cdr for completed call')); + } this.srf.endSession(this.req); });