mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 08:40:38 +00:00
fixes for LCC dial where a relative url is given as actionhook (#1282)
* fixes for LCC dial where a relative url is given as actionhook * update to speech-utils 0.2.15 with configurable tmp folder location
This commit is contained in:
@@ -238,6 +238,7 @@ router.post('/',
|
||||
if (app.call_hook.url === app.call_status_hook?.url || !app.call_status_hook?.url) {
|
||||
logger.debug('reusing websocket for call status hook');
|
||||
app.notifier = app.requestor;
|
||||
app.call_status_hook = app.call_hook;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1426,6 +1426,14 @@ class CallSession extends Emitter {
|
||||
method: 'POST'
|
||||
};
|
||||
}
|
||||
|
||||
/* if given a relative url then send to same base url as current session */
|
||||
if (this.requestor._isRelativeUrl(opts.call_hook?.url)) {
|
||||
opts.call_hook.url = `${this.requestor.baseUrl}${opts.call_hook?.url}`;
|
||||
}
|
||||
if (this.requestor._isRelativeUrl(opts.call_status_hook?.url)) {
|
||||
opts.call_status_hook.url = `${this.requestor.baseUrl}${opts.call_status_hook?.url}`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,10 +27,13 @@ class RestCallSession extends CallSession {
|
||||
}
|
||||
|
||||
this.on('callStatusChange', this._notifyCallStatusChange.bind(this));
|
||||
this._notifyCallStatusChange({
|
||||
callStatus: CallStatus.Trying,
|
||||
sipStatus: 100,
|
||||
sipReason: 'Trying'
|
||||
|
||||
setImmediate(() => {
|
||||
this._notifyCallStatusChange({
|
||||
callStatus: CallStatus.Trying,
|
||||
sipStatus: 100,
|
||||
sipReason: 'Trying'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -17,28 +17,33 @@ class TaskRedirect extends Task {
|
||||
async exec(cs) {
|
||||
await super.exec(cs);
|
||||
|
||||
if (cs.requestor instanceof WsRequestor && cs.application.requestor._isAbsoluteUrl(this.actionHook)) {
|
||||
this.logger.info(`Task:performAction redirecting to ${this.actionHook}, requires new ws connection`);
|
||||
try {
|
||||
this.cs.requestor.close();
|
||||
const requestor = new WsRequestor(this.logger, cs.accountSid, {url: this.actionHook}, this.webhook_secret) ;
|
||||
this.cs.application.requestor = requestor;
|
||||
} catch (err) {
|
||||
this.logger.info(err, `Task:performAction error redirecting to ${this.actionHook}`);
|
||||
}
|
||||
} else if (cs.application.requestor._isAbsoluteUrl(this.actionHook)) {
|
||||
const baseUrl = this.cs.application.requestor.baseUrl;
|
||||
const newUrl = URL.parse(this.actionHook);
|
||||
const newBaseUrl = newUrl.protocol + '//' + newUrl.host;
|
||||
if (baseUrl != newBaseUrl) {
|
||||
const isAbsoluteUrl = cs.application?.requestor?._isAbsoluteUrl(this.actionHook);
|
||||
|
||||
if (isAbsoluteUrl) {
|
||||
this.logger.info(`TaskRedirect redirecting to new absolute URL ${this.actionHook}, requires new requestor`);
|
||||
|
||||
if (cs.requestor instanceof WsRequestor) {
|
||||
try {
|
||||
this.logger.info(`Task:redirect updating base url to ${newBaseUrl}`);
|
||||
const newRequestor = new HttpRequestor(this.logger, cs.accountSid, {url: this.actionHook},
|
||||
cs.accountInfo.account.webhook_secret);
|
||||
this.cs.requestor.removeAllListeners();
|
||||
this.cs.application.requestor = newRequestor;
|
||||
const requestor = new WsRequestor(this.logger, cs.accountSid, {url: this.actionHook},
|
||||
cs.accountInfo.account.webhook_secret) ;
|
||||
cs.requestor.emit('handover', requestor);
|
||||
} catch (err) {
|
||||
this.logger.info(err, `Task:redirect error updating base url to ${this.actionHook}`);
|
||||
this.logger.info(err, `TaskRedirect error redirecting to ${this.actionHook}`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const baseUrl = this.cs.application.requestor.baseUrl;
|
||||
const newUrl = URL.parse(this.actionHook);
|
||||
const newBaseUrl = newUrl.protocol + '//' + newUrl.host;
|
||||
if (baseUrl != newBaseUrl) {
|
||||
try {
|
||||
this.logger.info(`Task:redirect updating base url to ${newBaseUrl}`);
|
||||
const newRequestor = new HttpRequestor(this.logger, cs.accountSid, {url: this.actionHook},
|
||||
cs.accountInfo.account.webhook_secret);
|
||||
cs.requestor.emit('handover', newRequestor);
|
||||
} catch (err) {
|
||||
this.logger.info(err, `TaskRedirect error updating base url to ${this.actionHook}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user