feat get registered client status (#251)

This commit is contained in:
Hoan Luu Huu
2023-11-03 18:33:03 +07:00
committed by GitHub
parent 72d2877ddf
commit 1e9f388f51
2 changed files with 71 additions and 1 deletions
+24
View File
@@ -145,6 +145,7 @@ router.post('/:sid/VoipCarriers', async(req, res) => {
sysError(logger, res, err);
}
});
router.get('/:sid/RegisteredSipUsers', async(req, res) => {
const {logger, registrar} = req.app.locals;
try {
@@ -161,6 +162,29 @@ router.get('/:sid/RegisteredSipUsers', async(req, res) => {
}
});
router.get('/:sid/RegisteredSipUsers/:client', async(req, res) => {
const {logger, registrar} = req.app.locals;
const client = req.params.client;
try {
const account_sid = parseAccountSid(req);
await validateRequest(req, account_sid);
const result = await Account.retrieve(account_sid);
if (!result || result.length === 0) {
throw new DbErrorBadRequest(`account not found for sid ${account_sid}`);
}
const user = await registrar.query(`${client}@${result[0].sip_realm}`);
res.status(200).json({
name: client,
contact: user ? user.contact : null,
expiryTime: user ? user.expiryTime : 0,
protocol: user ? user.protocol : null,
registered_status: user ? 'active' : 'inactive'
});
} catch (err) {
sysError(logger, res, err);
}
});
function coerceNumbers(callInfo) {
if (Array.isArray(callInfo)) {
return callInfo.map((ci) => {