@@ -239,9 +239,10 @@ class DataProcessor {
239239
240240 // MARK: - Data Formatting Utilities
241241
242- func formatBandwidth( _ bps: Int ) -> String {
242+ func formatBandwidth( _ bytesPerSec: Int ) -> String {
243+ let bits = Double ( bytesPerSec) * 8
243244 let units = [ " bps " , " Kbps " , " Mbps " , " Gbps " ]
244- var value = Double ( bps )
245+ var value = bits
245246 var unitIndex = 0
246247
247248 while value >= 1000 && unitIndex < units. count - 1 {
@@ -373,55 +374,40 @@ class DataProcessor {
373374 // MARK: - Raw Data Processing (from AppDelegate)
374375
375376 func processAllStreams( _ streamsData: Any ? ) -> [ String : Any ] {
376- print (
377- " processAllStreams - Input type: \( type ( of: streamsData) ) , value: \( streamsData ?? " nil " ) " )
378-
379377 // Handle null values gracefully (normal for fresh server)
380378 if streamsData == nil || streamsData is NSNull {
381- print ( " No streams configured " )
382379 return [ : ]
383380 }
384381
385- guard let streams = streamsData as? [ String : Any ] else {
386- print ( " Invalid streams data format - expected [String: Any], got \( type ( of: streamsData) ) " )
382+ guard var streams = streamsData as? [ String : Any ] else {
387383 return [ : ]
388384 }
389385
390- print ( " Processing \( streams. count) total streams: \( Array ( streams. keys) ) " )
386+ // Filter out "incomplete list" marker from MistServer partial responses
387+ streams. removeValue ( forKey: " incomplete list " )
391388 return streams
392389 }
393390
394391 func processStreamStats( _ statsData: Any ? ) -> [ String : Any ] {
395- print ( " processStreamStats - Input type: \( type ( of: statsData) ) , value: \( statsData ?? " nil " ) " )
396-
397- // Handle null values gracefully (normal for fresh server)
398392 if statsData == nil || statsData is NSNull {
399- print ( " No stream statistics available " )
400393 return [ : ]
401394 }
402395
403396 guard let stats = statsData as? [ String : Any ] else {
404- print (
405- " Invalid stream stats data format - expected [String: Any], got \( type ( of: statsData) ) " )
406397 return [ : ]
407398 }
408399
409- print ( " Processing stream statistics for \( stats. count) streams: \( Array ( stats. keys) ) " )
410400 return stats
411401 }
412402
413403 func processPushList( _ pushListData: Any ? ) -> [ String : Any ] {
414- print (
415- " processPushList - Input type: \( type ( of: pushListData) ) , value: \( pushListData ?? " nil " ) " )
416-
417404 // Handle null values gracefully (normal for fresh server)
418405 if pushListData == nil || pushListData is NSNull {
419- print ( " No pushes configured " )
420406 return [ : ]
421407 }
422408
423409 // MistServer push_list returns array of arrays:
424- // [[ID, "STREAMNAME", "URI_original", "URI_parsed" , logs, pushstatus ], ...]
410+ // [[ID, stream, target_original, target_resolved , logs, stats ], ...]
425411 if let pushArray = pushListData as? [ [ Any ] ] {
426412 var result : [ String : Any ] = [ : ]
427413 for entry in pushArray {
@@ -436,45 +422,40 @@ class DataProcessor {
436422 }
437423 let stream = entry [ 1 ] as? String ?? " unknown "
438424 let target = entry [ 2 ] as? String ?? " unknown "
425+ let resolvedTarget = entry [ 3 ] as? String ?? target
439426
440427 var pushInfo : [ String : Any ] = [
441428 " id " : pushId,
442429 " stream " : stream,
443430 " target " : target,
444- " target_parsed " : entry [ 3 ] as? String ?? target ,
431+ " resolved_target " : resolvedTarget ,
445432 ]
446433
447- // Extract status object if present (index 5)
448- if entry. count > 5 , let status = entry [ 5 ] as? [ String : Any ] {
449- for (key, value) in status {
450- pushInfo [ key] = value
451- }
434+ // Index 4: logs array [[timestamp, level, message], ...]
435+ if entry. count > 4 , let logs = entry [ 4 ] as? [ [ Any ] ] {
436+ pushInfo [ " logs " ] = logs
437+ }
438+
439+ // Index 5: stats object (keep nested, don't flatten)
440+ if entry. count > 5 , let stats = entry [ 5 ] as? [ String : Any ] {
441+ pushInfo [ " stats " ] = stats
452442 }
453443
454444 result [ String ( pushId) ] = pushInfo
455445 }
456- print ( " Processing \( result. count) active pushes from array format " )
457446 return result
458447 }
459448
460449 // Fallback: try dict format for backwards compatibility
461450 if let pushes = pushListData as? [ String : Any ] {
462- print ( " Processing \( pushes. count) active pushes from dict format " )
463451 return pushes
464452 }
465453
466- print (
467- " Invalid push list data format - expected [[Any]] or [String: Any], got \( type ( of: pushListData) ) "
468- )
469454 return [ : ]
470455 }
471456
472457 func processClients( _ clientsData: Any ? ) -> [ String : Any ] {
473- print ( " processClients - Input type: \( type ( of: clientsData) ) , value: \( clientsData ?? " nil " ) " )
474-
475- // Handle null values gracefully (normal for fresh server)
476458 if clientsData == nil || clientsData is NSNull {
477- print ( " No clients connected " )
478459 return [ : ]
479460 }
480461
@@ -484,6 +465,17 @@ class DataProcessor {
484465
485466 if let data = clientsDict [ " data " ] , data is NSNull {
486467 return [ : ]
468+ } else if let dataArray = clientsDict [ " data " ] as? [ [ Any ] ] , !fields. isEmpty {
469+ // Array-of-arrays format (MistServer 3.9+): each row is a client, no IDs
470+ var result : [ String : Any ] = [ : ]
471+ for (index, row) in dataArray. enumerated ( ) {
472+ var info : [ String : Any ] = [ : ]
473+ for (i, field) in fields. enumerated ( ) where i < row. count {
474+ info [ field] = row [ i]
475+ }
476+ result [ " client_ \( index) " ] = info
477+ }
478+ return result
487479 } else if let data = clientsDict [ " data " ] as? [ String : Any ] {
488480 // Data may be {clientId: {field: value}} or {clientId: [value1, value2, ...]}
489481 var result : [ String : Any ] = [ : ]
@@ -522,11 +514,9 @@ class DataProcessor {
522514 }
523515
524516 guard let clients = clientsData as? [ String : Any ] else {
525- print ( " Invalid clients data format - expected [String: Any], got \( type ( of: clientsData) ) " )
526517 return [ : ]
527518 }
528519
529- print ( " Processing \( clients. count) connected clients: \( Array ( clients. keys) ) " )
530520 return clients
531521 }
532522}
0 commit comments