support use sips schema when it's enabled from gateway configuration (#67)

* support use sips schema when it's enabled from gateway configuration

* wip

* add LICENSE file
This commit is contained in:
Hoan Luu Huu
2024-06-15 20:11:06 +07:00
committed by GitHub
parent 49e1ae2843
commit 6f7f553408
4 changed files with 77 additions and 19 deletions

View File

@@ -13,12 +13,13 @@ class OptionsBot {
this.protocol = gateway.protocol;
this.expiry = (process.env.SEND_OPTIONS_PING_INTERVAL || 60);
const useSipsScheme = gateway.protocol.includes('tls') && gateway.use_sips_scheme;
const isIPv4 = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/.test(gateway.ipv4);
const transport = gateway.protocol.includes('/') ? gateway.protocol.substring(0, gateway.protocol.indexOf('/')) :
gateway.protocol;
this.proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`;
this.uri = `sip${gateway.protocol.includes('tls') ?
's' : ''}:${gateway.ipv4}${gateway.port && !gateway.protocol.includes('tls') ? `:${gateway.port}` : ''}`;
this.uri = `sip${useSipsScheme ?
's' : ''}:${gateway.ipv4}${gateway.port && !useSipsScheme ? `:${gateway.port}` : ''}`;
}
async options(srf) {

View File

@@ -47,6 +47,7 @@ class Regbot {
this.ipv4 = opts.ipv4;
this.port = opts.port;
this.use_public_ip_in_contact = opts.use_public_ip_in_contact || JAMBONES_REGBOT_CONTACT_USE_IP;
this.use_sips_scheme = opts.use_sips_scheme || false;
this.fromUser = opts.from_user || this.username;
const fromDomain = opts.from_domain || this.sip_realm;
@@ -88,8 +89,9 @@ class Regbot {
const isIPv4 = /[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}/.test(this.ipv4);
const transport = this.protocol.includes('/') ? this.protocol.substring(0, this.protocol.indexOf('/')) :
this.protocol;
const useSipsScheme = transport === 'tls' && this.use_sips_scheme;
const proxy = `sip:${this.ipv4}${isIPv4 ? `:${this.port}` : ''};transport=${transport}`;
const req = await srf.request(`sip${transport === 'tls' ? 's' : ''}:${this.aor}`, {
const req = await srf.request(`sip${useSipsScheme ? 's' : ''}:${this.aor}`, {
method: 'REGISTER',
proxy,
headers: {
@@ -302,6 +304,7 @@ const updateCarrierRegbots = async(logger, srf) => {
ipv4: gw.ipv4,
port: gw.port,
protocol: gw.protocol,
use_sips_scheme: gw.use_sips_scheme,
username: gw.carrier.register_username,
password: gw.carrier.register_password,
sip_realm: gw.carrier.register_sip_realm,