remove config in favor of env vars, other major changes

This commit is contained in:
Dave Horton
2020-02-15 22:03:28 -05:00
parent 3d24ac1914
commit 3c89b7fd76
14 changed files with 162 additions and 113 deletions

View File

@@ -1,4 +1,3 @@
const config = require('config');
const router = require('express').Router();
const makeTask = require('../../tasks/make_task');
const RestCallSession = require('../../session/rest-call-session');
@@ -7,12 +6,9 @@ const {CallDirection, CallStatus} = require('../../utils/constants');
const SipError = require('drachtio-srf').SipError;
const Srf = require('drachtio-srf');
const sysError = require('./error');
const drachtio = config.get('outdials.drachtio');
const sbcs = config.get('outdials.sbc');
const Mrf = require('drachtio-fsmrf');
const installSrfLocals = require('../../utils/install-srf-locals');
const Requestor = require('../../utils/requestor');
let idxDrachtio = 0;
let idxSbc = 0;
let srfs = [];
@@ -51,6 +47,8 @@ function getSrfForOutdial(logger) {
if (srfs.length === 0 && initializedSrfs) return reject('no available drachtio servers for outdial');
else if (srfs.length > 0) return resolve(srfs[idxDrachtio++ % srfs.length]);
else {
const {srf} = require('../../../');
const drachtio = srf.locals.drachtio;
logger.debug(drachtio, 'getSrfForOutdial - attempting to connect');
initializedSrfs = true;
resolve(Promise.race(drachtio.map((d) => connectSrf(logger, d))));
@@ -64,8 +62,8 @@ router.post('/', async(req, res) => {
try {
let uri, cs, to;
const restDial = makeTask(logger, {'rest:dial': req.body});
const sbcAddress = sbcs[idxSbc++ % sbcs.length];
const srf = await getSrfForOutdial(logger);
const sbcAddress = srf.locals.sbcs[idxSbc++ % srf.locals.sbcs.length];
const target = restDial.to;
const opts = { callingNumber: restDial.from };
@@ -86,7 +84,8 @@ router.post('/', async(req, res) => {
/* create endpoint for outdial */
const mrf = srf.locals.mrf;
const ms = await mrf.connect(config.get('freeswitch'));
const ms = await mrf.connect(srf.locals.freeswitch);
logger.debug('createCall: successfully connected to media server');
const ep = await ms.createEndpoint();
logger.debug(`createCall: successfully allocated endpoint, sending INVITE to ${sbcAddress}`);
@@ -119,8 +118,8 @@ router.post('/', async(req, res) => {
* attach our requestor and notifier objects
* these will be used for all http requests we make during this call
*/
app.requestor = new Requestor(this.logger, app.call_hook);
if (app.call_status_hook) app.notifier = new Requestor(this.logger, app.call_status_hook);
app.requestor = new Requestor(logger, app.call_hook);
if (app.call_status_hook) app.notifier = new Requestor(logger, app.call_status_hook);
else app.notifier = {request: () => {}};
/* now launch the outdial */
@@ -128,7 +127,7 @@ router.post('/', async(req, res) => {
const dlg = await srf.createUAC(uri, opts, {
cbRequest: (err, inviteReq) => {
if (err) {
this.logger.error(err, 'createCall Error creating call');
logger.error(err, 'createCall Error creating call');
res.status(500).send('Call Failure');
ep.destroy();
}