mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2025-12-19 04:27:46 +00:00
support trunk register with account sip realm if available (#107)
* support trunk register with account sip realm if available * wip * wip * wip * wip
This commit is contained in:
@@ -17,7 +17,15 @@ class Regbot {
|
||||
constructor(logger, opts) {
|
||||
this.logger = logger;
|
||||
|
||||
['ipv4', 'port', 'username', 'password', 'sip_realm', 'protocol'].forEach((prop) => this[prop] = opts[prop]);
|
||||
[
|
||||
'ipv4',
|
||||
'port',
|
||||
'username',
|
||||
'password',
|
||||
'sip_realm',
|
||||
'protocol',
|
||||
'account_sip_realm'
|
||||
].forEach((prop) => this[prop] = opts[prop]);
|
||||
|
||||
this.voip_carrier_sid = opts.voip_carrier_sid;
|
||||
this.username = opts.username;
|
||||
@@ -90,6 +98,9 @@ class Regbot {
|
||||
if (this.use_public_ip_in_contact) {
|
||||
contactAddress = `${this.fromUser}@${publicAddress}`;
|
||||
}
|
||||
else if (this.account_sip_realm) {
|
||||
contactAddress = `${this.fromUser}@${this.account_sip_realm}`;
|
||||
}
|
||||
else if (localSIPDomain) {
|
||||
contactAddress = `${this.fromUser}@${localSIPDomain}`;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ function pickRelevantCarrierProperties(c) {
|
||||
register_from_user: c.register_from_user,
|
||||
register_from_domain: c.register_from_domain,
|
||||
register_public_ip_in_contact: c.register_public_ip_in_contact,
|
||||
outbound_sip_proxy: c.outbound_sip_proxy
|
||||
outbound_sip_proxy: c.outbound_sip_proxy,
|
||||
account_sid: c.account_sid,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -184,7 +185,7 @@ const checkStatus = async(logger, srf) => {
|
||||
|
||||
const updateCarrierRegbots = async(logger, srf) => {
|
||||
// Check if We are
|
||||
const { lookupAllVoipCarriers, lookupSipGatewaysByCarrier } = srf.locals.dbHelpers;
|
||||
const { lookupAllVoipCarriers, lookupSipGatewaysByCarrier, lookupAccountBySid } = srf.locals.dbHelpers;
|
||||
try {
|
||||
|
||||
/* first check: has anything changed (new carriers or gateways)? */
|
||||
@@ -210,6 +211,7 @@ const updateCarrierRegbots = async(logger, srf) => {
|
||||
if (JSON.stringify(gws) !== JSON.stringify(gateways)) hasChanged = true;
|
||||
|
||||
if (hasChanged) {
|
||||
|
||||
debug('updateCarrierRegbots: got new or changed carriers');
|
||||
logger.info('updateCarrierRegbots: got new or changed carriers');
|
||||
carriers.length = 0;
|
||||
@@ -225,9 +227,17 @@ const updateCarrierRegbots = async(logger, srf) => {
|
||||
// start new regbots
|
||||
let batch_count = 0;
|
||||
for (const gw of getUniqueGateways(gateways, logger)) {
|
||||
// find gateway account sip realm.
|
||||
if (!gw.carrier.register_public_ip_in_contact && gw.carrier.account_sid) {
|
||||
const account = await lookupAccountBySid(gw.carrier.account_sid);
|
||||
if (account && account.sip_realm) {
|
||||
gw.account_sip_realm = account.sip_realm;
|
||||
}
|
||||
}
|
||||
try {
|
||||
const rb = new Regbot(logger, {
|
||||
voip_carrier_sid: gw.carrier.voip_carrier_sid,
|
||||
account_sip_realm: gw.account_sip_realm,
|
||||
ipv4: gw.ipv4,
|
||||
port: gw.port,
|
||||
protocol: gw.protocol,
|
||||
|
||||
Reference in New Issue
Block a user