snake case REST payloads, support for LCC with child_call_hook, handle 302 on outdial

This commit is contained in:
Dave Horton
2021-04-22 14:39:54 -04:00
parent 8eb0cd1520
commit 576f645489
11 changed files with 340 additions and 179 deletions

View File

@@ -7,6 +7,7 @@ const assert = require('assert');
const ConfirmCallSession = require('../session/confirm-call-session');
const selectSbc = require('./select-sbc');
const Registrar = require('@jambonz/mw-registrar');
const AdultingCallSession = require('../session/adulting-call-session');
const registrar = new Registrar({
host: process.env.JAMBONES_REDIS_HOST,
port: process.env.JAMBONES_REDIS_PORT || 6379
@@ -137,7 +138,7 @@ class SingleDialer extends Emitter {
localSdp: this.ep.local.sdp
});
if (this.target.auth) opts.auth = this.target.auth;
this.dlg = await srf.createUAC(uri, opts, {
this.dlg = await srf.createUAC(uri, {...opts, followRedirects: true, keepUriOnRedirect: true}, {
cbRequest: (err, req) => {
if (err) {
this.logger.error(err, 'SingleDialer:exec Error creating call');
@@ -266,7 +267,7 @@ class SingleDialer extends Emitter {
// now execute it in a new ConfirmCallSession
this.logger.debug(`SingleDialer:_executeApp: executing ${tasks.length} tasks`);
const cs = new ConfirmCallSession({
logger: this.logger,
logger: this.baseLogger,
application: this.application,
dlg: this.dlg,
ep: this.ep,
@@ -284,6 +285,24 @@ class SingleDialer extends Emitter {
}
}
async doAdulting({logger, tasks, application}) {
this.logger = logger;
this.adulting = true;
this.emit('adulting');
await this.ep.unbridge()
.catch((err) => this.logger.info({err}, 'SingleDialer:doAdulting - failed to unbridge ep'));
this.ep.play('silence_stream://1000');
const cs = new AdultingCallSession({
logger: this.logger,
singleDialer: this,
application,
callInfo: this.callInfo,
tasks
});
cs.exec();
return cs;
}
_notifyCallStatusChange({callStatus, sipStatus, duration}) {
assert((typeof duration === 'number' && callStatus === CallStatus.Completed) ||
(!duration && callStatus !== CallStatus.Completed),

View File

@@ -1,7 +1,7 @@
const bent = require('bent');
const parseUrl = require('parse-url');
const assert = require('assert');
const snakeCaseKeys = require('snakecase-keys');
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
function basicAuth(username, password) {
@@ -62,7 +62,7 @@ class Requestor {
* @param {object} [params] - request parameters
*/
async request(hook, params) {
params = params || null;
const payload = params ? snakeCaseKeys(params, {exclude: ['customerData', 'sip']}) : null;
const url = hook.url || hook;
const method = hook.method || 'POST';
const {username, password} = typeof hook === 'object' ? hook : {};
@@ -70,14 +70,14 @@ class Requestor {
assert.ok(url, 'Requestor:request url was not provided');
assert.ok, (['GET', 'POST'].includes(method), `Requestor:request method must be 'GET' or 'POST' not ${method}`);
this.logger.debug({hook, params}, `Requestor:request ${method} ${url}`);
this.logger.debug({hook, payload}, `Requestor:request ${method} ${url}`);
const startAt = process.hrtime();
let buf;
try {
buf = isRelativeUrl(url) ?
await this.post(url, params, this.authHeader) :
await bent(method, 'buffer', 200, 201, 202)(url, params, basicAuth(username, password));
await this.post(url, payload, this.authHeader) :
await bent(method, 'buffer', 200, 201, 202)(url, payload, basicAuth(username, password));
} catch (err) {
this.logger.info({baseUrl: this.baseUrl, url, statusCode: err.statusCode},
`web callback returned unexpected error code ${err.statusCode}`);