mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
further fixes for freeswitch retry
This commit is contained in:
@@ -4,6 +4,24 @@ const localIp = ip.address();
|
|||||||
const PORT = process.env.HTTP_PORT || 3000;
|
const PORT = process.env.HTTP_PORT || 3000;
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
|
||||||
|
function initMS(logger, wrapper, ms) {
|
||||||
|
Object.assign(wrapper, {ms, active: true, connects: 1});
|
||||||
|
logger.info(`connected to freeswitch at ${ms.address}`);
|
||||||
|
|
||||||
|
ms.conn
|
||||||
|
.on('esl::end', () => {
|
||||||
|
wrapper.active = false;
|
||||||
|
logger.info(`lost connection to freeswitch at ${ms.address}`);
|
||||||
|
})
|
||||||
|
.on('esl::ready', () => {
|
||||||
|
if (wrapper.connects > 0) {
|
||||||
|
logger.info(`connected to freeswitch at ${ms.address}`);
|
||||||
|
}
|
||||||
|
wrapper.connects = 1;
|
||||||
|
wrapper.active = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function installSrfLocals(srf, logger) {
|
function installSrfLocals(srf, logger) {
|
||||||
assert(!srf.locals.dbHelpers);
|
assert(!srf.locals.dbHelpers);
|
||||||
const {getSBC, getSrf} = require('./sbc-pinger')(logger);
|
const {getSBC, getSrf} = require('./sbc-pinger')(logger);
|
||||||
@@ -30,21 +48,7 @@ function installSrfLocals(srf, logger) {
|
|||||||
mediaservers.push(val);
|
mediaservers.push(val);
|
||||||
try {
|
try {
|
||||||
const ms = await mrf.connect(fs);
|
const ms = await mrf.connect(fs);
|
||||||
Object.assign(val, {ms, active: true, connects: 1});
|
initMS(logger, val, ms);
|
||||||
logger.info(`connected to freeswitch at ${fs.address}`);
|
|
||||||
|
|
||||||
ms.conn
|
|
||||||
.on('esl::end', () => {
|
|
||||||
val.active = false;
|
|
||||||
logger.info(`lost connection to freeswitch at ${fs.address}`);
|
|
||||||
})
|
|
||||||
.on('esl::ready', () => {
|
|
||||||
if (val.connects > 0) {
|
|
||||||
logger.info(`connected to freeswitch at ${fs.address}`);
|
|
||||||
}
|
|
||||||
val.connects = 1;
|
|
||||||
val.active = true;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
logger.info(`failed connecting to freeswitch at ${fs.address}, will retry shortly`);
|
logger.info(`failed connecting to freeswitch at ${fs.address}, will retry shortly`);
|
||||||
@@ -57,7 +61,7 @@ function installSrfLocals(srf, logger) {
|
|||||||
try {
|
try {
|
||||||
logger.info({mediaserver: val.opts}, 'Retrying initial connection to media server');
|
logger.info({mediaserver: val.opts}, 'Retrying initial connection to media server');
|
||||||
const ms = await mrf.connect(val.opts);
|
const ms = await mrf.connect(val.opts);
|
||||||
val.ms = ms;
|
initMS(logger, val, ms);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.info(`failed connecting to freeswitch at ${val.opts.address}, will retry shortly`);
|
logger.info(`failed connecting to freeswitch at ${val.opts.address}, will retry shortly`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user