mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
allow dial referHook to return application to execute on the other le… (#505)
* allow dial referHook to return application to execute on the other leg; fixes #504 * fix session tracking * minor logging * minor
This commit is contained in:
@@ -322,7 +322,7 @@ class TaskDial extends Task {
|
||||
const to = parseUri(req.getParsedHeader('Refer-To').uri);
|
||||
const by = parseUri(req.getParsedHeader('Referred-By').uri);
|
||||
this.logger.info({to}, 'refer to parsed');
|
||||
await cs.requestor.request('verb:hook', this.referHook, {
|
||||
const json = await cs.requestor.request('verb:hook', this.referHook, {
|
||||
...callInfo,
|
||||
refer_details: {
|
||||
sip_refer_to: req.get('Refer-To'),
|
||||
@@ -334,6 +334,33 @@ class TaskDial extends Task {
|
||||
referred_call_sid
|
||||
}
|
||||
}, httpHeaders);
|
||||
if (json && Array.isArray(json)) {
|
||||
try {
|
||||
let logger = this.logger;
|
||||
if (isChild) {
|
||||
const {parentLogger} = this.srf.locals;
|
||||
logger = parentLogger.child({callId: cs.callId, callSid: this.sd.callSid});
|
||||
}
|
||||
const tasks = normalizeJambones(logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||
if (tasks && tasks.length > 0) {
|
||||
const legs = isChild ? ['child', 'parent'] : ['parent', 'child'];
|
||||
this.logger.info(`Dial:handleRefer received REFER on ${legs[0]} leg, setting new app on ${legs[1]} leg`);
|
||||
if (isChild) this.redirect(cs, tasks);
|
||||
else {
|
||||
this.logger.info({tasks: json}, 'Dial:handleRefer - new application for for child leg');
|
||||
const adultingSession = await this.sd.doAdulting({
|
||||
logger,
|
||||
application: cs.application,
|
||||
tasks
|
||||
});
|
||||
/* need to update the callSid of the child with its own (new) AdultingCallSession */
|
||||
sessionTracker.add(adultingSession.callSid, adultingSession);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.info(err, 'Dial:handleRefer - error setting new application after receiving REFER');
|
||||
}
|
||||
}
|
||||
res.send(202);
|
||||
this.logger.info('DialTask:handleRefer - sent 202 Accepted');
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user