mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-02-15 10:49:07 +00:00
added redirect verb
This commit is contained in:
@@ -14,28 +14,31 @@ class CallSession extends Emitter {
|
|||||||
this.callSid = callSid;
|
this.callSid = callSid;
|
||||||
this.tasks = tasks;
|
this.tasks = tasks;
|
||||||
|
|
||||||
|
this.taskIdx = 0;
|
||||||
|
this.stackIdx = 0;
|
||||||
this.callGone = false;
|
this.callGone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async exec() {
|
async exec() {
|
||||||
let idx = 0;
|
|
||||||
this.logger.info(`CallSession:exec starting task list with ${this.tasks.length} tasks`);
|
this.logger.info(`CallSession:exec starting task list with ${this.tasks.length} tasks`);
|
||||||
while (this.tasks.length && !this.callGone) {
|
while (this.tasks.length && !this.callGone) {
|
||||||
|
const taskNum = ++this.taskIdx;
|
||||||
|
const stackNum = this.stackIdx;
|
||||||
const task = this.tasks.shift();
|
const task = this.tasks.shift();
|
||||||
this.logger.debug({task}, `CallSession:exec starting task #${++idx}: ${task.name}`);
|
this.logger.debug({task}, `CallSession:exec starting task #${stackNum}:${taskNum}: ${task.name}`);
|
||||||
try {
|
try {
|
||||||
const resources = await this._evaluatePreconditions(task);
|
const resources = await this._evaluatePreconditions(task);
|
||||||
this.currentTask = task;
|
this.currentTask = task;
|
||||||
await task.exec(this, resources);
|
await task.exec(this, resources);
|
||||||
this.currentTask = null;
|
this.currentTask = null;
|
||||||
this.logger.debug(`CallSession:exec completed task #${idx}: ${task.name}`);
|
this.logger.debug(`CallSession:exec completed task #${stackNum}:${taskNum}: ${task.name}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.currentTask = null;
|
this.currentTask = null;
|
||||||
if (err.message.includes(BADPRECONDITIONS)) {
|
if (err.message.includes(BADPRECONDITIONS)) {
|
||||||
this.logger.info(`CallSession:exec task #${idx}: ${task.name}: ${err.message}`);
|
this.logger.info(`CallSession:exec task #${stackNum}:${taskNum}: ${task.name}: ${err.message}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.error(err, `Error executing task #${idx}: ${task.name}`);
|
this.logger.error(err, `Error executing task #${stackNum}:${taskNum}: ${task.name}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +67,9 @@ class CallSession extends Emitter {
|
|||||||
*/
|
*/
|
||||||
replaceApplication(tasks) {
|
replaceApplication(tasks) {
|
||||||
this.tasks = tasks;
|
this.tasks = tasks;
|
||||||
this.logger.info({tasks}, `CallSession:replaceApplication - set ${tasks.length} new tasks`);
|
this.logger.info({tasks}, `CallSession:replaceApplication - reset application with ${tasks.length} new tasks`);
|
||||||
|
this.taskIdx = 0;
|
||||||
|
this.stackIdx++;
|
||||||
}
|
}
|
||||||
_evaluatePreconditions(task) {
|
_evaluatePreconditions(task) {
|
||||||
switch (task.preconditions) {
|
switch (task.preconditions) {
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ function makeTask(logger, obj) {
|
|||||||
case TaskName.Listen:
|
case TaskName.Listen:
|
||||||
const TaskListen = require('./listen');
|
const TaskListen = require('./listen');
|
||||||
return new TaskListen(logger, data);
|
return new TaskListen(logger, data);
|
||||||
|
case TaskName.Redirect:
|
||||||
|
const TaskRedirect = require('./redirect');
|
||||||
|
return new TaskRedirect(logger, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// should never reach
|
// should never reach
|
||||||
|
|||||||
23
lib/tasks/redirect.js
Normal file
23
lib/tasks/redirect.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
const Task = require('./task');
|
||||||
|
const {TaskName} = require('../utils/constants');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects to a new application
|
||||||
|
*/
|
||||||
|
class TaskRedirect extends Task {
|
||||||
|
constructor(logger, opts) {
|
||||||
|
super(logger, opts);
|
||||||
|
|
||||||
|
this.action = this.data.action;
|
||||||
|
this.method = this.data.method || 'POST';
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() { return TaskName.Redirect; }
|
||||||
|
|
||||||
|
async exec(cs) {
|
||||||
|
super.exec(cs);
|
||||||
|
await this.performAction(this.method, this.auth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TaskRedirect;
|
||||||
@@ -102,6 +102,19 @@
|
|||||||
"url"
|
"url"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"redirect": {
|
||||||
|
"properties": {
|
||||||
|
"action": "string",
|
||||||
|
"method": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": ["GET", "POST"]
|
||||||
|
},
|
||||||
|
"auth": "#auth"
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"action"
|
||||||
|
]
|
||||||
|
},
|
||||||
"transcribe": {
|
"transcribe": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"transcriptionCallback": "string",
|
"transcriptionCallback": "string",
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ class Task extends Emitter {
|
|||||||
return this.cs;
|
return this.cs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toJSON() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
|
||||||
async exec(cs) {
|
async exec(cs) {
|
||||||
this.cs = cs;
|
this.cs = cs;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
"Hangup": "hangup",
|
"Hangup": "hangup",
|
||||||
"Listen": "listen",
|
"Listen": "listen",
|
||||||
"Play": "play",
|
"Play": "play",
|
||||||
"redirect": "redirect",
|
"Redirect": "redirect",
|
||||||
"SipDecline": "sip:decline",
|
"SipDecline": "sip:decline",
|
||||||
"SipNotify": "sip:notify",
|
"SipNotify": "sip:notify",
|
||||||
"SipRedirect": "sip:redirect",
|
"SipRedirect": "sip:redirect",
|
||||||
|
|||||||
Reference in New Issue
Block a user