I am new to FreeSWITCH and I am trying to apply click-to-call in my NodeJs application.
This is my code when executing click-to-call, I use the 'originate command', this is my reference
let app_args = `sofia/gateway/fs-test1/${phoneNumberFrom}`;
let arg1 = `{ignore_early_media=true,origination_caller_id_number=${callerId}}${app_args}`;
let arg2 = `${arg1} &bridge({origination_caller_id_number=${callerId}}sofia/gateway/fs-test3/${phoneNumberTo})`;
connection.api('originate', arg2, function (res) {
callUid = res.getBody().toString().replace('+OK ', '');
});
It works perfectly, but I want to get the call duration when both call ends. I calculated the duration by following this instruction in here , so in my nodejs code this is what it looks like :
const answer_epoch = fsEvent.getHeader('variable_answer_epoch');
const end_epoch = fsEvent.getHeader('variable_end_epoch');
private calculateDuration(start_epoch:any, end_epoch: any):any{
const answeredDate = new Date(start_epoch*1000);
const hangupDate = new Date(end_epoch*1000);
console.log('Answered Time -> ', answeredDate.toUTCString());
console.log('HangupTime ->' , hangupDate.toUTCString());
let duration = Math.abs(answeredDate.getTime() - hangupDate.getTime());
return duration;
}
so I used the ESL to listen to the event from FreeSWITCH, and I listen to a specific event called 'CHANNEL_EXECUTE_COMPLETE' because it is the only event that is raised during this api originate
and I retrieved the records of this event, but the 'answered and end epoch' does not exist in the details for CHANNEL_EXECUTE_COMPLETE.
Does anyone know what is the other way to retrieve the call duration from FreeSWITCH using ESL?
Thanks in advance!
Use the CHANNEL_HANGUP_COMPLETE event for this purpose.you:
it gives following response ...
variable_billsec: 17
variable_billmsec: 16660
variable_billusec: 16660036