mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-01-25 02:07:56 +00:00
Compare commits
2 Commits
v0.9.5-10
...
feat/ws_lc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
673ab8a730 | ||
|
|
ec1408fa0c |
@@ -1043,30 +1043,22 @@ class CallSession extends Emitter {
|
||||
* @param {object} [opts.call_hook] - new call_status_hook
|
||||
*/
|
||||
async _lccCallHook(opts) {
|
||||
const webhooks = [];
|
||||
let sd, tasks, childTasks;
|
||||
const b3 = this.b3;
|
||||
const httpHeaders = b3 && {b3};
|
||||
|
||||
if (opts.call_hook || opts.child_call_hook) {
|
||||
if (opts.call_hook) {
|
||||
webhooks.push(this.requestor.request('session:redirect', opts.call_hook, this.callInfo.toJSON(), httpHeaders));
|
||||
tasks = await this.requestor.request('session:redirect', opts.call_hook, this.callInfo.toJSON(), httpHeaders);
|
||||
}
|
||||
if (opts.child_call_hook) {
|
||||
/* child call hook only allowed from a connected Dial state */
|
||||
const task = this.currentTask;
|
||||
sd = task.sd;
|
||||
if (task && TaskName.Dial === task.name && sd) {
|
||||
webhooks.push(this.requestor.request(
|
||||
'session:redirect', opts.child_call_hook, sd.callInfo.toJSON(), httpHeaders));
|
||||
childTasks = [];
|
||||
}
|
||||
}
|
||||
const [tasks1, tasks2] = await Promise.all(webhooks);
|
||||
if (opts.call_hook) {
|
||||
tasks = tasks1;
|
||||
if (opts.child_call_hook) childTasks = tasks2;
|
||||
}
|
||||
else childTasks = tasks1;
|
||||
}
|
||||
else if (opts.parent_call || opts.child_call) {
|
||||
const {parent_call, child_call} = opts;
|
||||
@@ -1086,13 +1078,17 @@ class CallSession extends Emitter {
|
||||
const cs = await sd.doAdulting({
|
||||
logger: childLogger,
|
||||
application: this.application,
|
||||
tasks: t
|
||||
tasks: t,
|
||||
call_hook_url: opts.child_call_hook
|
||||
});
|
||||
|
||||
/* need to update the callSid of the child with its own (new) AdultingCallSession */
|
||||
sessionTracker.add(cs.callSid, cs);
|
||||
}
|
||||
if (tasks) {
|
||||
if (!this.ep) {
|
||||
await this.reAnchorMedia();
|
||||
}
|
||||
const t = normalizeJambones(this.logger, tasks).map((tdata) => makeTask(this.logger, tdata));
|
||||
this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_lccCallHook new task list');
|
||||
this.replaceApplication(t);
|
||||
|
||||
@@ -16,6 +16,7 @@ const uuidv4 = require('uuid-random');
|
||||
const HttpRequestor = require('./http-requestor');
|
||||
const WsRequestor = require('./ws-requestor');
|
||||
const {makeOpusFirst} = require('./sdp-utils');
|
||||
const listTaskNames = require('./summarize-tasks');
|
||||
const {
|
||||
JAMBONES_USE_FREESWITCH_TIMER_FD
|
||||
} = require('../config');
|
||||
@@ -391,7 +392,7 @@ class SingleDialer extends Emitter {
|
||||
}
|
||||
}
|
||||
|
||||
async doAdulting({logger, tasks, application}) {
|
||||
async doAdulting({logger, tasks, application, call_hook_url}) {
|
||||
this.adulting = true;
|
||||
this.emit('adulting');
|
||||
if (this.ep) {
|
||||
@@ -410,6 +411,9 @@ class SingleDialer extends Emitter {
|
||||
//clone application from parent call with new requestor
|
||||
//parrent application will be closed in case the parent hangup
|
||||
const app = {...application};
|
||||
if (call_hook_url) {
|
||||
app.call_hook.url = call_hook_url;
|
||||
}
|
||||
if ('WS' === app.call_hook?.method ||
|
||||
app.call_hook?.url.startsWith('ws://') || app.call_hook?.url.startsWith('wss://')) {
|
||||
const requestor = new WsRequestor(logger, this.accountInfo.account.account_sid,
|
||||
@@ -426,6 +430,16 @@ class SingleDialer extends Emitter {
|
||||
this.accountInfo.account.webhook_secret);
|
||||
else app.notifier = {request: () => {}, close: () => {}};
|
||||
}
|
||||
// Time to open session:new for adulting call
|
||||
// If ws is used, open session:new to control the call later.
|
||||
if (!tasks || tasks.length === 0 || app.requestor instanceof WsRequestor) {
|
||||
const b3 = rootSpan?.getTracingPropagation();
|
||||
const httpHeaders = b3 && {b3};
|
||||
const newTask = await app.requestor.request(
|
||||
'session:new', call_hook_url, this.callInfo.toJSON(), httpHeaders);
|
||||
tasks = normalizeJambones(newLogger, newTask).map((tdata) => makeTask(newLogger, tdata));
|
||||
newLogger.info({tasks: listTaskNames(tasks)}, 'SingleDialer:doAdulting new task list for adulting call');
|
||||
}
|
||||
// Replace old application with new application.
|
||||
this.application = app;
|
||||
const cs = new AdultingCallSession({
|
||||
|
||||
Reference in New Issue
Block a user