add sbc public address to database on startup

This commit is contained in:
Dave Horton
2020-04-20 12:26:55 -04:00
parent b4766a4b88
commit c1e4324b51
4 changed files with 236 additions and 185 deletions

8
app.js
View File

@@ -25,7 +25,8 @@ logger.info('starting..');
const {
lookupAuthHook,
lookupSipGatewayBySignalingAddress
lookupSipGatewayBySignalingAddress,
addSbcAddress
} = require('jambonz-db-helpers')({
host: process.env.JAMBONES_MYSQL_HOST,
user: process.env.JAMBONES_MYSQL_USER,
@@ -44,7 +45,10 @@ const CallSession = require('./lib/call-session');
if (process.env.DRACHTIO_HOST) {
srf.connect({host: process.env.DRACHTIO_HOST, port: process.env.DRACHTIO_PORT, secret: process.env.DRACHTIO_SECRET });
srf.on('connect', (err, hp) => {
logger.info(`connected to drachtio listening on ${hp}`);
const last = hp.split(',').pop();
const arr = /^(.*)\/(.*):(\d+)$/.exec(last);
logger.info(`connected to drachtio listening on ${hp}: adding ${arr[2]} to sbc_addresses table`);
addSbcAddress(arr[1]);
});
}
else {