support voip carrier sip proxy (#165)

* support voiip carrier sip proxy

* wip

* wip

* wip
This commit is contained in:
Hoan Luu Huu
2025-02-17 21:47:59 +07:00
committed by GitHub
parent c449feeb9c
commit 9feb6f3c8f
2 changed files with 24 additions and 2 deletions

View File

@@ -7,7 +7,8 @@ const {
isPrivateVoipNetwork, isPrivateVoipNetwork,
isBlackListedSipGateway, isBlackListedSipGateway,
makeFullMediaReleaseKey, makeFullMediaReleaseKey,
makePartnerFullMediaReleaseKey makePartnerFullMediaReleaseKey,
isValidDomainOrIP
} = require('./utils'); } = require('./utils');
const { MediaPath } = require('./constants.json'); const { MediaPath } = require('./constants.json');
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar'); const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
@@ -342,6 +343,14 @@ class CallSession extends Emitter {
proxy = u; proxy = u;
u = `${scheme}:${prefix}${prependPlus}${calledNumber}@${vc.register_sip_realm};transport=${transport}`; u = `${scheme}:${prefix}${prependPlus}${calledNumber}@${vc.register_sip_realm};transport=${transport}`;
this.logger.debug({uri: u}, `using outbound proxy for this registered trunk: ${proxy}`); this.logger.debug({uri: u}, `using outbound proxy for this registered trunk: ${proxy}`);
} else if (vc.outbound_sip_proxy && vc.outbound_sip_proxy.length > 0) {
if (vc.outbound_sip_proxy.includes('sip:') || vc.outbound_sip_proxy.includes('sips:')) {
proxy = vc.outbound_sip_proxy;
} else if (isValidDomainOrIP(vc.outbound_sip_proxy)) {
proxy =
`${scheme}:${prefix}${prependPlus}${calledNumber}@${vc.outbound_sip_proxy};transport=${transport}`;
this.logger.debug({uri: u}, `using outbound proxy for this trunk: ${proxy}`);
}
} }
mapGateways.set(u, obj); mapGateways.set(u, obj);
uris.push(u); uris.push(u);

View File

@@ -323,6 +323,18 @@ const makePartnerFullMediaReleaseKey = (callId) => {
return `a_sdp:${callId}`; return `a_sdp:${callId}`;
}; };
function isValidDomainOrIP(input) {
const domainRegex = /^(?!:\/\/)([a-zA-Z0-9.-]+)(:\d+)?$/;
// eslint-disable-next-line max-len
const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(:\d+)?$/;
if (domainRegex.test(input) || ipRegex.test(input)) {
return true;
}
return false; // Invalid input
}
module.exports = { module.exports = {
makeRtpEngineOpts, makeRtpEngineOpts,
selectHostPort, selectHostPort,
@@ -336,5 +348,6 @@ module.exports = {
isPrivateVoipNetwork, isPrivateVoipNetwork,
isBlackListedSipGateway, isBlackListedSipGateway,
makeFullMediaReleaseKey, makeFullMediaReleaseKey,
makePartnerFullMediaReleaseKey makePartnerFullMediaReleaseKey,
isValidDomainOrIP
}; };