mirror of
https://github.com/jambonz/sbc-sip-sidecar.git
synced 2026-10-04 02:04:20 +00:00
feat: include jambonz and drachtio versions in X-Jambonz-Discover response (#152)
- jambonzVersion is read from the schema_version table via the existing db-helpers pool (now exposed on srf.locals); a DB error yields null rather than failing discovery - drachtioVersion is captured from the drachtio connect handshake and stored on srf.locals - README example updated Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
ce05d91e6d
commit
9f00a513f8
@@ -35,22 +35,44 @@ const isDiscoverRequest = (req) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Read the current cluster topology from redis: the IPs of the feature
|
||||
* servers, SIP servers and RTP servers.
|
||||
* @param {object} srf - drachtio srf instance (uses srf.locals.retrieveSet)
|
||||
* @returns {Promise<{featureServers: string[], sipServers: string[], rtpServers: string[]}>}
|
||||
* Read the installed jambonz version from the schema_version table.
|
||||
* A failure here must not fail discovery, so it resolves to null on any error.
|
||||
* @param {object} pool - mysql connection pool (may be undefined in tests)
|
||||
* @returns {Promise<string|null>}
|
||||
*/
|
||||
const _lookupJambonzVersion = (pool) => new Promise((resolve) => {
|
||||
if (!pool) return resolve(null);
|
||||
pool.query('SELECT version FROM schema_version', (err, results) => {
|
||||
if (err) {
|
||||
debug({err}, 'failed reading schema_version');
|
||||
return resolve(null);
|
||||
}
|
||||
resolve(results && results.length ? results[0].version : null);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Read the current cluster topology from redis (the IPs of the feature
|
||||
* servers, SIP servers and RTP servers) plus the jambonz version
|
||||
* (schema_version table) and the drachtio server version (captured on connect).
|
||||
* @param {object} srf - drachtio srf instance (uses srf.locals.retrieveSet, srf.locals.pool)
|
||||
* @returns {Promise<{jambonzVersion: string|null, drachtioVersion: string|null,
|
||||
* featureServers: string[], sipServers: string[], rtpServers: string[]}>}
|
||||
*/
|
||||
const discoverServers = async(srf) => {
|
||||
const { retrieveSet } = srf.locals;
|
||||
const { retrieveSet, pool, drachtioVersion } = srf.locals;
|
||||
const { featureServers, sipServers, rtpServers } = _setNames();
|
||||
|
||||
const [fs, sip, rtp] = await Promise.all([
|
||||
const [fs, sip, rtp, jambonzVersion] = await Promise.all([
|
||||
retrieveSet(featureServers),
|
||||
retrieveSet(sipServers),
|
||||
retrieveSet(rtpServers)
|
||||
retrieveSet(rtpServers),
|
||||
_lookupJambonzVersion(pool)
|
||||
]);
|
||||
|
||||
const topology = {
|
||||
jambonzVersion,
|
||||
drachtioVersion: drachtioVersion || null,
|
||||
featureServers: fs || [],
|
||||
sipServers: sip || [],
|
||||
rtpServers: rtp || []
|
||||
|
||||
Reference in New Issue
Block a user