feat: update voip carriers register status

This commit is contained in:
Quan HL
2023-04-02 14:44:13 +07:00
parent 517715679d
commit 5e15a622de
2 changed files with 26 additions and 14 deletions

6
app.js
View File

@@ -25,7 +25,8 @@ const {
lookupSipGatewaysByCarrier,
lookupAccountBySipRealm,
lookupAccountCapacitiesBySid,
addSbcAddress
addSbcAddress,
updateVoipCarriersRegisterStatus
} = require('@jambonz/db-helpers')({
host: process.env.JAMBONES_MYSQL_HOST,
user: process.env.JAMBONES_MYSQL_USER,
@@ -69,7 +70,8 @@ srf.locals = {
lookupAllVoipCarriers,
lookupSipGatewaysByCarrier,
lookupAccountBySipRealm,
lookupAccountCapacitiesBySid
lookupAccountCapacitiesBySid,
updateVoipCarriersRegisterStatus
},
realtimeDbHelpers: {
addKey,

View File

@@ -54,6 +54,7 @@ class Regbot {
}
async register(srf) {
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;
try {
const contactAddress = this.use_public_ip_in_contact ?
`${this.username}@${srf.locals.sbcPublicIpAddress}` : this.aor;
@@ -90,11 +91,20 @@ class Regbot {
debug(`setting timer for next register to ${expires} seconds`);
this.timer = setTimeout(this.register.bind(this, srf), (expires - 5) * 1000);
}
updateVoipCarriersRegisterStatus({
status: res.status === 200 ? 'ok' : 'fail',
reason: `${res.status} ${res.reason}`
});
});
} catch (err) {
this.logger.error({ err }, `Regbot Error registering to ${this.ipv4}:${this.port}`);
this.timer = setTimeout(this.register.bind(this, srf), 60 * 1000);
updateVoipCarriersRegisterStatus({
status: 'fail',
reason: err
});
}
}
}