mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-01-24 22:27:52 +00:00
feat: Outbound register use sbc public IP address
This commit is contained in:
1
app.js
1
app.js
@@ -90,6 +90,7 @@ srf.on('connect', (err, hp) => {
|
||||
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
|
||||
if (arr && 'udp' === arr[1]) {
|
||||
logger.info(`adding sbc public address to database: ${arr[2]}`);
|
||||
srf.locals.sbcPublicIpAddress = `${arr[2]}:${arr[3]}`;
|
||||
addSbcAddress(arr[2]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,12 +44,13 @@ class Regbot {
|
||||
|
||||
async register(srf) {
|
||||
try {
|
||||
const contactAddress = process.env.JAMBONES_REGBOT_CONTACT_USE_IP ? srf.locals.sbcPublicIpAddress : this.aor;
|
||||
const req = await srf.request(`sip:${this.aor}`, {
|
||||
method: 'REGISTER',
|
||||
proxy: `sip:${this.ipv4}:${this.port}`,
|
||||
headers: {
|
||||
'From': `sip:${this.aor}`,
|
||||
'Contact': `<sip:${this.aor}>;expires=${DEFAULT_EXPIRES}`,
|
||||
'Contact': `<sip:${contactAddress}>;expires=${DEFAULT_EXPIRES}`,
|
||||
'Expires': DEFAULT_EXPIRES
|
||||
},
|
||||
auth: {
|
||||
|
||||
@@ -119,6 +119,37 @@ test('trunk register tests when its IP in redis cache', (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('trunk register with sbc public IP address', (t) => {
|
||||
clearModule.all();
|
||||
const { srf } = require('../app');
|
||||
t.timeoutAfter(60000);
|
||||
process.env.JAMBONES_REGBOT_CONTACT_USE_IP = true;
|
||||
addToSet(setName, "172.39.0.10:5060");
|
||||
|
||||
connect(srf)
|
||||
.then(wait.bind(null, 1500))
|
||||
.then(() => {
|
||||
const obj = srf.locals.regbotStatus();
|
||||
return t.ok(obj.total === 1 && obj.registered === 1, 'initial regbot running and successfully registered to trunk');
|
||||
})
|
||||
.then(() => {
|
||||
if (srf.locals.lb) srf.locals.lb.disconnect();
|
||||
srf.disconnect();
|
||||
t.end();
|
||||
removeFromSet(setName, "172.39.0.10:5060");
|
||||
return;
|
||||
})
|
||||
.catch((err) => {
|
||||
if (srf.locals.lb) srf.locals.lb.disconnect();
|
||||
|
||||
if (srf) srf.disconnect();
|
||||
removeFromSet(setName, "172.39.0.10:5060");
|
||||
console.log(`error received: ${err}`);
|
||||
t.error(err);
|
||||
});
|
||||
});
|
||||
|
||||
test('trunk not register tests when its IP is not in redis cache', (t) => {
|
||||
clearModule.all();
|
||||
const { srf } = require('../app');
|
||||
|
||||
Reference in New Issue
Block a user