@@ -31,9 +31,10 @@ async function processQueue() {
3131}
3232
3333class RuntimeConfig {
34- constructor ( ) {
34+ constructor ( srfLocals = null ) {
3535 this . server = null ;
3636 this . socketPath = process . env . SBC_SOCKET_PATH || '/tmp/sbc-sip-sidecar.sock' ;
37+ this . srfLocals = srfLocals ;
3738 this . startServer ( ) ;
3839 }
3940
@@ -99,6 +100,25 @@ class RuntimeConfig {
99100 return runOperation ( ( ) => Object . fromEntries ( config ) ) ;
100101 }
101102
103+ async getAvailableFeatureServers ( ) {
104+ return runOperation ( async ( ) => {
105+ if ( ! this . srfLocals || ! this . srfLocals . retrieveSet ) {
106+ return { error : 'Redis connection not available' } ;
107+ }
108+
109+ const JAMBONES_CLUSTER_ID = process . env . JAMBONES_CLUSTER_ID ;
110+ const setNameFs = `${ ( JAMBONES_CLUSTER_ID || 'default' ) } :active-fs` ;
111+
112+ try {
113+ const activeServers = await this . srfLocals . retrieveSet ( setNameFs ) ;
114+ return { activeServers : activeServers || [ ] } ;
115+ } catch ( err ) {
116+ logger . error ( { err } , 'Error retrieving active feature servers' ) ;
117+ return { error : 'Failed to retrieve active feature servers' } ;
118+ }
119+ } ) ;
120+ }
121+
102122 startServer ( ) {
103123 try {
104124 require ( 'fs' ) . unlinkSync ( this . socketPath ) ;
@@ -232,6 +252,21 @@ class RuntimeConfig {
232252 socket . write ( JSON . stringify ( { success : true , config : allConfig } ) + '\n' ) ;
233253 break ;
234254
255+ case 'fs-available' :
256+ const availableResult = await this . getAvailableFeatureServers ( ) ;
257+ if ( availableResult . error ) {
258+ socket . write ( JSON . stringify ( {
259+ success : false ,
260+ error : availableResult . error
261+ } ) + '\n' ) ;
262+ } else {
263+ socket . write ( JSON . stringify ( {
264+ success : true ,
265+ available : availableResult . activeServers
266+ } ) + '\n' ) ;
267+ }
268+ break ;
269+
235270 default :
236271 socket . write ( JSON . stringify ( { error : 'Unknown action' } ) + '\n' ) ;
237272 }
@@ -253,9 +288,23 @@ class RuntimeConfig {
253288 }
254289}
255290
256- const runtimeConfig = new RuntimeConfig ( ) ;
291+ let runtimeConfig = null ;
257292
258- process . on ( 'SIGINT' , ( ) => runtimeConfig . shutdown ( ) ) ;
259- process . on ( 'SIGTERM' , ( ) => runtimeConfig . shutdown ( ) ) ;
293+ function initializeRuntimeConfig ( srfLocals ) {
294+ if ( ! runtimeConfig ) {
295+ runtimeConfig = new RuntimeConfig ( srfLocals ) ;
296+ process . on ( 'SIGINT' , ( ) => runtimeConfig . shutdown ( ) ) ;
297+ process . on ( 'SIGTERM' , ( ) => runtimeConfig . shutdown ( ) ) ;
298+ }
299+ return runtimeConfig ;
300+ }
301+
302+ // For backward compatibility - create without srfLocals if imported directly
303+ if ( ! runtimeConfig ) {
304+ runtimeConfig = new RuntimeConfig ( ) ;
305+ process . on ( 'SIGINT' , ( ) => runtimeConfig . shutdown ( ) ) ;
306+ process . on ( 'SIGTERM' , ( ) => runtimeConfig . shutdown ( ) ) ;
307+ }
260308
261309module . exports = runtimeConfig ;
310+ module . exports . initialize = initializeRuntimeConfig ;
0 commit comments