feat: record all call (#84)

* feat: record all call

* feat: record all call

* feat: record all call

* feat: record all call

* add record format in recording url

* add record format to recording url

* fix ext
This commit is contained in:
Hoan Luu Huu
2023-06-10 02:01:46 +07:00
committed by GitHub
parent 695e44da29
commit 81d7a9f1e6
2 changed files with 8 additions and 1 deletions

View File

@@ -542,12 +542,18 @@ class CallSession extends Emitter {
/* write cdr for connected call */
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: dlg.type === 'uas' ? 'caller hungup' : 'called party hungup',
sip_status: 200,
answered: true,
duration: Math.floor((now - callStart) / 1000)
duration: Math.floor((now - callStart) / 1000),
...(recordAllCalls && {recording_url})
}).catch((err) => this.logger.error({err}, 'Error writing cdr for completed call'));
}
/* de-link the 2 Dialogs for GC */

View File

@@ -19,6 +19,7 @@ module.exports = (srf, logger, redisClient) => {
const callId = req.get('Call-ID');
req.locals.account_sid = req.get('X-Account-Sid');
req.locals.application_sid = req.get('X-Application-Sid');
req.locals.record_all_calls = req.get('X-Record-All-Calls');
const traceId = req.locals.trace_id = req.get('X-Trace-ID');
req.locals.logger = logger.child({
callId,