【发布时间】:2021-08-26 05:58:55
【问题描述】:
我是 FreeSWITCH 的新手,我正在尝试在我的 NodeJs 应用程序中应用点击通话。
这是我执行点击通话时的代码,我使用“发起命令”,这是我的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 ', '');
});
它工作得很好,但我想在两个通话结束时获得通话时长。 我按照here 中的说明计算了持续时间, 所以在我的 nodejs 代码中是这样的:
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;
}
所以我使用 ESL 监听来自 FreeSWITCH 的事件,并监听名为“CHANNEL_EXECUTE_COMPLETE”的特定事件,因为它是在此api originate 期间引发的唯一事件,并且我检索了此事件的记录,但 CHANNEL_EXECUTE_COMPLETE 的详细信息中不存在“已回答并结束的时代”。
有谁知道使用 ESL 从 FreeSWITCH 检索通话时长的另一种方法是什么?
提前致谢!
【问题讨论】:
标签: node.js freeswitch