mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
added initial support for REST-initiated outdials
This commit is contained in:
@@ -56,16 +56,26 @@ class Task extends Emitter {
|
||||
return this._completionPromise;
|
||||
}
|
||||
|
||||
async performAction(method, auth, results) {
|
||||
if (this.action) {
|
||||
let action = this.action;
|
||||
if (action.startsWith('/')) {
|
||||
const or = this.callSession.originalRequest;
|
||||
action = `${or.baseUrl}${this.action}`;
|
||||
this.logger.debug({originalUrl: this.action, normalizedUrl: action}, 'Task:performAction normalized url');
|
||||
if (!auth && or.auth) auth = or.auth;
|
||||
normalizeUrl(url, method, auth) {
|
||||
const hook = {url, method};
|
||||
if (auth && auth.username && auth.password) Object.assign(hook, auth);
|
||||
|
||||
if (url.startsWith('/')) {
|
||||
const or = this.callSession.originalRequest;
|
||||
if (or) {
|
||||
hook.url = `${or.baseUrl}${url}`;
|
||||
hook.method = hook.method || or.method || 'POST';
|
||||
if (!hook.auth && or.auth) Object.assign(hook, or.auth);
|
||||
}
|
||||
const tasks = await this.actionHook(action, method, auth, results);
|
||||
}
|
||||
this.logger.debug({hook}, 'Task:normalizeUrl');
|
||||
return hook;
|
||||
}
|
||||
|
||||
async performAction(method, auth, results, expectResponse = true) {
|
||||
if (this.action) {
|
||||
const hook = this.normalizeUrl(this.action, method, auth);
|
||||
const tasks = await this.actionHook(hook, results, expectResponse);
|
||||
if (tasks && Array.isArray(tasks)) {
|
||||
this.logger.debug({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
|
||||
this.callSession.replaceApplication(tasks);
|
||||
|
||||
Reference in New Issue
Block a user