Skip to content

Commit

Permalink
fix for k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
davehorton committed Jul 3, 2024
1 parent 0cb7418 commit f17ae93
Showing 1 changed file with 39 additions and 28 deletions.
67 changes: 39 additions & 28 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ const {
challengeDeviceCalls
} = require('./lib/middleware')(srf, logger);
const CallSession = require('./lib/call-session');
const { parse } = require('path');

Check failure on line 140 in app.js

View workflow job for this annotation

GitHub Actions / build

'parse' is assigned a value but never used

Check failure on line 140 in app.js

View workflow job for this annotation

GitHub Actions / build

'parse' is assigned a value but never used

if (process.env.DRACHTIO_HOST && !process.env.K8S) {
const cidrs = process.env.JAMBONES_NETWORK_CIDR
Expand Down Expand Up @@ -167,7 +168,6 @@ if (process.env.DRACHTIO_HOST && !process.env.K8S) {
}
}
}
srf.locals.sbcPublicIpAddress = {};
for (const hp of hostports) {
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
if (arr && 'udp' === arr[1] && !matcher.contains(arr[2])) {
Expand All @@ -183,34 +183,8 @@ if (process.env.DRACHTIO_HOST && !process.env.K8S) {
srf.locals.removeFromRedis = () => removeFromSet(setName, hostport);
srf.locals.addToRedis();
}
if (arr) {
const ipv4 = arr[2];
const port = arr[3];
switch (arr[1]) {
case 'udp':
srf.locals.sbcPublicIpAddress = {
...srf.locals.sbcPublicIpAddress,
udp: `${ipv4}:${port}`
};
break;
case 'tls':
srf.locals.sbcPublicIpAddress = {
...srf.locals.sbcPublicIpAddress,
tls: `${ipv4}:${port}`
};
break;
case 'wss':
srf.locals.sbcPublicIpAddress = {
...srf.locals.sbcPublicIpAddress,
wss: `${ipv4}:${port}`
};
break;
}
}
if (!srf.locals.sbcPublicIpAddress.tls) {
srf.locals.sbcPublicIpAddress.tls = `${srf.locals.sipAddress}:5061`;
}
}
srf.locals.sbcPublicIpAddress = parseHostPorts(hostports);
});
}
else {
Expand All @@ -234,6 +208,7 @@ else {
}
}
}
srf.locals.sbcPublicIpAddress = parseHostPorts(hp.split(','));
});
}
if (process.env.NODE_ENV === 'test') {
Expand Down Expand Up @@ -390,4 +365,40 @@ function handle(removeFromSet, setName, signal) {
}
}

const parseHostPorts = (hostports) => {
let obj = {};

Check failure on line 369 in app.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed

Check failure on line 369 in app.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
for (const hp of hostports) {
const arr = /^(.*)\/(.*):(\d+)$/.exec(hp);
if (arr) {
const ipv4 = arr[2];
const port = arr[3];
switch (arr[1]) {
case 'udp':
obj = {
...obj,
udp: `${ipv4}:${port}`
};
break;
case 'tls':
obj = {
...obj,
tls: `${ipv4}:${port}`
};
break;
case 'wss':
obj = {
...obj,
wss: `${ipv4}:${port}`
};
break;
}
}
if (!obj.tls) {
obj.tls = `${srf.locals.sipAddress}:5061`;
}
logger.info({obj}, 'sip endpoints');
return obj;
}
};

module.exports = {srf, logger};

0 comments on commit f17ae93

Please sign in to comment.