mirror of
https://github.com/jambonz/sbc-outbound.git
synced 2025-12-19 04:27:45 +00:00
support voip carrier sip proxy (#165)
* support voiip carrier sip proxy * wip * wip * wip
This commit is contained in:
@@ -7,7 +7,8 @@ const {
|
||||
isPrivateVoipNetwork,
|
||||
isBlackListedSipGateway,
|
||||
makeFullMediaReleaseKey,
|
||||
makePartnerFullMediaReleaseKey
|
||||
makePartnerFullMediaReleaseKey,
|
||||
isValidDomainOrIP
|
||||
} = require('./utils');
|
||||
const { MediaPath } = require('./constants.json');
|
||||
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
|
||||
@@ -342,6 +343,14 @@ class CallSession extends Emitter {
|
||||
proxy = u;
|
||||
u = `${scheme}:${prefix}${prependPlus}${calledNumber}@${vc.register_sip_realm};transport=${transport}`;
|
||||
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);
|
||||
uris.push(u);
|
||||
|
||||
15
lib/utils.js
15
lib/utils.js
@@ -323,6 +323,18 @@ const makePartnerFullMediaReleaseKey = (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 = {
|
||||
makeRtpEngineOpts,
|
||||
selectHostPort,
|
||||
@@ -336,5 +348,6 @@ module.exports = {
|
||||
isPrivateVoipNetwork,
|
||||
isBlackListedSipGateway,
|
||||
makeFullMediaReleaseKey,
|
||||
makePartnerFullMediaReleaseKey
|
||||
makePartnerFullMediaReleaseKey,
|
||||
isValidDomainOrIP
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user