@@ -18,7 +18,7 @@ const logger = require('./logging');
1818const PromCollector = require ( './metrics/PromCollector' ) ;
1919const S3Manager = require ( './store/S3Manager' ) ;
2020const { saveEntryAssureUnique } = require ( './store/dynamo' ) ;
21- const { getStatsFormat } = require ( './utils/stats-detection ' ) ;
21+ const { ClientManager } = require ( './utils/ClientManager ' ) ;
2222const { asyncDeleteFile,
2323 getEnvName,
2424 getIdealWorkerCount,
@@ -207,7 +207,6 @@ function setupFeaturesPublisher() {
207207function setupWorkDirectory ( ) {
208208 try {
209209 // Temporary path for stats dumps must be configured.
210- tempPath = config . server . tempPath ;
211210 assert ( tempPath ) ;
212211
213212 if ( fs . existsSync ( tempPath ) ) {
@@ -275,42 +274,37 @@ function wsConnectionHandler(client, upgradeReq) {
275274 try {
276275 PromCollector . connected . inc ( ) ;
277276
278- // the url the client is coming from
279- const referer = upgradeReq . headers . origin + upgradeReq . url ;
280- const ua = upgradeReq . headers [ 'user-agent' ] ;
281-
282- // During feature extraction we need information about the browser in order to decide which algorithms use.
283- const connectionInfo = {
284- path : upgradeReq . url ,
285- origin : upgradeReq . headers . origin ,
286- url : referer ,
287- userAgent : ua ,
288- clientProtocol : client . protocol
289- } ;
277+ const clientManager = new ClientManager ( client , upgradeReq ) ;
278+ const clientDetails = clientManager . getDetails ( ) ;
279+ const {
280+ userAgent,
281+ clientProtocol,
282+ url,
283+ statsFormat,
284+ clientType
285+ } = clientDetails ;
290286
291287 logger . info (
292- '[App] New app connected: ua : %s, protocol: %s, referer : %s' ,
293- ua ,
294- client . protocol ,
295- referer
288+ '[App] New app connected: user-agent : %s, protocol: %s, url : %s' ,
289+ userAgent ,
290+ clientProtocol ,
291+ url
296292 ) ;
297293
298294 // The if statement is used to maintain compatibility with the reconnect functionality on the client
299295 // it should be removed once the server also supports this functionality.
300296 // TODO: Remove once reconnect is added to server
301- if ( isSessionOngoing ( referer , tempPath ) || isSessionReconnect ( referer ) ) {
302- logger . warn ( `[APP] Reconnect not supported, closing connection for ${ referer } ` ) ;
297+ if ( isSessionOngoing ( url , tempPath ) || isSessionReconnect ( url ) ) {
298+ logger . warn ( `[APP] Reconnect not supported, closing connection for ${ url } ` ) ;
303299
304300 client . close ( 3001 ) ;
305301
306302 return ;
307303 }
308304
309- connectionInfo . statsFormat = getStatsFormat ( connectionInfo ) ;
310-
311305 const demuxSinkOptions = {
312- connectionInfo ,
313- dumpFolder : './temp' ,
306+ clientDetails ,
307+ dumpFolder : tempPath ,
314308 log : logger
315309 } ;
316310
@@ -324,6 +318,7 @@ function wsConnectionHandler(client, upgradeReq) {
324318 const dumpData = {
325319 app : meta . applicationName || 'Undefined' ,
326320 clientId : id ,
321+ clientType,
327322 conferenceId : meta . confName ,
328323 conferenceUrl : meta . confID ,
329324 dumpPath : meta . dumpPath ,
@@ -335,30 +330,28 @@ function wsConnectionHandler(client, upgradeReq) {
335330 ampSessionId : meta . sessionId ,
336331 ampUserId : meta . userId ,
337332 ampDeviceId : meta . deviceId ,
338- statsFormat : connectionInfo . statsFormat ,
333+ statsFormat,
339334 isBreakoutRoom : meta . isBreakoutRoom ,
340335 breakoutRoomId : meta . roomId ,
341336 parentStatsSessionId : meta . parentStatsSessionId ,
342337 ...tenantInfo
343338 } ;
344339
340+ PromCollector . collectClientDumpSizeMetrics ( dumpData ) ;
341+
345342 const obfuscatedDumpData = obfuscatePII ( dumpData ) ;
346343
347344 logger . info ( '[App] Processing dump id %s, metadata %o' , id , obfuscatedDumpData ) ;
348345
349346 // Don't process dumps generated by JVB & Jigasi, there should be a more formal process to
350- if ( config . features . disableFeatExtraction
351- || connectionInfo . clientProtocol ?. includes ( 'JVB' )
352- || connectionInfo . clientProtocol ?. includes ( 'JIGASI' )
353- || connectionInfo . clientProtocol ?. includes ( 'JICOFO' )
354- || connectionInfo . userAgent ?. includes ( 'react-native' ) ) {
355- persistDumpData ( dumpData ) ;
356- } else {
357- // Add the clientId in the worker pool so it can process the associated dump file.
347+ if ( clientManager . supportsFeatureExtraction ( ) ) {
348+ // Add the clientId in the worker pool so it can process the associated dump file.
358349 workerPool . addTask ( {
359350 type : RequestType . PROCESS ,
360351 body : dumpData
361352 } ) ;
353+ } else {
354+ persistDumpData ( dumpData ) ;
362355 }
363356 } ) ;
364357
@@ -372,12 +365,12 @@ function wsConnectionHandler(client, upgradeReq) {
372365 // the whole pipeline does as well,
373366 PromCollector . sessionErrorCount . inc ( ) ;
374367
375- logger . error ( '[App] Connection pipeline: %o; error: %o' , connectionInfo , err ) ;
368+ logger . error ( '[App] Connection pipeline: %o; error: %o' , clientDetails , err ) ;
376369 }
377370 } ) ;
378371
379372 connectionPipeline . on ( 'finish' , ( ) => {
380- logger . info ( '[App] Connection pipeline successfully finished %o' , connectionInfo ) ;
373+ logger . info ( '[App] Connection pipeline successfully finished %o' , clientDetails ) ;
381374
382375 // We need to explicity close the ws, you might notice that we don't do the same in case of an error
383376 // that's because in that case the error will propagate up the pipeline chain and the ws stream will also
@@ -404,7 +397,7 @@ function wsConnectionHandler(client, upgradeReq) {
404397 PromCollector . connected . dec ( ) ;
405398 } ) ;
406399 } catch ( error ) {
407- logger . error ( '[App] Error while handling ws connection: %j ' , error ) ;
400+ logger . error ( '[App] Error while handling ws connection: %o ' , error ) ;
408401 }
409402}
410403
@@ -526,6 +519,8 @@ function setupSecretManager() {
526519async function startRtcstatsServer ( ) {
527520 logger . info ( '[App] Initializing: %s; version: %s; env: %s ...' , appName , appVersion , getEnvName ( ) ) ;
528521
522+ tempPath = config . server . tempPath ;
523+
529524 setupSecretManager ( ) ;
530525 await setupWebhookSender ( ) ;
531526 setupWorkDirectory ( ) ;
0 commit comments