mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
add feature flag env JAMBONES_INJECT_CONTENT (#98)
This commit is contained in:
@@ -763,6 +763,49 @@ class CallSession extends Emitter {
|
|||||||
this.taskIdx = 0;
|
this.taskIdx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append tasks to the current execution stack UNLESS there is a gather in the stack.
|
||||||
|
* in that case, insert the tasks before the gather AND if the tasks include
|
||||||
|
* a gather then delete/remove the gather from the existing stack
|
||||||
|
* @param {*} t array of tasks
|
||||||
|
*/
|
||||||
|
_injectTasks(newTasks) {
|
||||||
|
const gatherPos = this.tasks.map((t) => t.name).indexOf(TaskName.Gather);
|
||||||
|
const currentlyExecutingGather = this.currentTask?.name === TaskName.Gather;
|
||||||
|
|
||||||
|
this.logger.debug({
|
||||||
|
currentTaskList: listTaskNames(this.tasks),
|
||||||
|
newContent: listTaskNames(newTasks),
|
||||||
|
currentlyExecutingGather,
|
||||||
|
gatherPos
|
||||||
|
}, 'CallSession:_injectTasks - starting');
|
||||||
|
|
||||||
|
const killGather = () => {
|
||||||
|
this.logger.debug('CallSession:_injectTasks - killing current gather because we have new content');
|
||||||
|
this.currentTask.kill(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (-1 === gatherPos) {
|
||||||
|
/* no gather in the stack simply append tasks */
|
||||||
|
this.tasks.push(...newTasks);
|
||||||
|
this.logger.debug({
|
||||||
|
updatedTaskList: listTaskNames(this.tasks)
|
||||||
|
}, 'CallSession:_injectTasks - completed (simple append)');
|
||||||
|
|
||||||
|
/* we do need to kill the current gather if we are executing one */
|
||||||
|
if (currentlyExecutingGather) killGather();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentlyExecutingGather) killGather();
|
||||||
|
const newTasksHasGather = newTasks.find((t) => t.name === TaskName.Gather);
|
||||||
|
this.tasks.splice(gatherPos, newTasksHasGather ? 1 : 0, ...newTasks);
|
||||||
|
|
||||||
|
this.logger.debug({
|
||||||
|
updatedTaskList: listTaskNames(this.tasks)
|
||||||
|
}, 'CallSession:_injectTasks - completed');
|
||||||
|
}
|
||||||
|
|
||||||
_onCommand({msgid, command, call_sid, queueCommand, data}) {
|
_onCommand({msgid, command, call_sid, queueCommand, data}) {
|
||||||
this.logger.info({msgid, command, queueCommand}, 'CallSession:_onCommand - received command');
|
this.logger.info({msgid, command, queueCommand}, 'CallSession:_onCommand - received command');
|
||||||
const resolution = {reason: 'received command', queue: queueCommand, command};
|
const resolution = {reason: 'received command', queue: queueCommand, command};
|
||||||
@@ -775,10 +818,15 @@ class CallSession extends Emitter {
|
|||||||
this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand new task list');
|
this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand new task list');
|
||||||
this.replaceApplication(t);
|
this.replaceApplication(t);
|
||||||
}
|
}
|
||||||
|
else if (process.env.JAMBONES_INJECT_CONTENT) {
|
||||||
|
this.logger.debug({tasks: listTaskNames(t)}, 'CallSession:_onCommand - queueing tasks (injecting content)');
|
||||||
|
this._injectTasks(t);
|
||||||
|
this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.info({tasks: listTaskNames(t)}, 'CallSession:_onCommand - queueing tasks');
|
this.logger.debug({tasks: listTaskNames(t)}, 'CallSession:_onCommand - queueing tasks');
|
||||||
this.tasks.push(...t);
|
this.tasks.push(...t);
|
||||||
this.logger.debug({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
|
this.logger.info({tasks: listTaskNames(this.tasks)}, 'CallSession:_onCommand - updated task list');
|
||||||
}
|
}
|
||||||
resolution.command = listTaskNames(t);
|
resolution.command = listTaskNames(t);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user