fix error with createCall api

This commit is contained in:
Dave Horton
2020-03-23 14:59:23 -04:00
parent 88e65c8836
commit 43c8890faf
2 changed files with 7 additions and 14 deletions

6
app.js
View File

@@ -29,7 +29,11 @@ const {
// HTTP
const express = require('express');
const app = express();
app.locals.logger = logger;
Object.assign(app.locals, {
logger,
srf
});
const httpRoutes = require('./lib/http-routes');
const InboundCallSession = require('./lib/session/inbound-call-session');

View File

@@ -7,24 +7,13 @@ const SipError = require('drachtio-srf').SipError;
const sysError = require('./error');
const Requestor = require('../../utils/requestor');
/**
* Retrieve a connection to a drachtio server, lazily creating when first called
*/
function getSrfForOutdial(logger) {
const {srf} = require('../../../');
const {getSrf} = srf.locals;
const srfForOutdial = getSrf();
if (!srfForOutdial) throw new Error('no available feature servers for outbound call creation');
return srfForOutdial;
}
router.post('/', async(req, res) => {
const logger = req.app.locals.logger;
const {logger, srf} = req.app.locals;
logger.debug({body: req.body}, 'got createCall request');
try {
let uri, cs, to;
const restDial = makeTask(logger, {'rest:dial': req.body});
const srf = getSrfForOutdial(logger);
const {getSBC, getFreeswitch} = srf.locals;
const sbcAddress = getSBC();
if (!sbcAddress) throw new Error('no available SBCs for outbound call creation');