@@ -104,19 +104,35 @@ export class SwarmComponent implements OnInit, OnDestroy {
104104 scanNetwork ( ) {
105105 this . scanning = true ;
106106
107- // Call the mDNS scan endpoint
108- this . httpClient . get < any [ ] > ( '/api/system/network/scan' ) . subscribe ( {
109- next : ( foundDevices ) => {
107+ forkJoin ( {
108+ currentDevice : this . httpClient . get < any > ( '/api/system/info' ) . pipe (
109+ mergeMap ( info =>
110+ this . httpClient . get < any > ( '/api/system/asic' ) . pipe (
111+ map ( asic => ( { ...info , ...asic } ) ) ,
112+ catchError ( ( ) => of ( info ) )
113+ )
114+ )
115+ ) ,
116+ foundDevices : this . httpClient . get < any [ ] > ( '/api/system/network/scan' )
117+ } ) . subscribe ( {
118+ next : ( { currentDevice, foundDevices } ) => {
110119 if ( ! Array . isArray ( foundDevices ) ) {
111- this . toastr . error ( 'Invalid response from scan endpoint' , 'Scan Error' ) ;
112- this . scanning = false ;
113- return ;
120+ foundDevices = [ ] ;
114121 }
115122
116- // Filter out devices we already have - check both IP and currentIP
123+ // Check if current device should be added to swarm
117124 const existingIps = new Set ( [ ...this . swarm . map ( item => item . IP ) , ...this . swarm . map ( item => item . currentIP ) ] ) ;
118- const existingHostnames = new Set ( this . swarm . map ( item => item . hostname ) . filter ( h => h ) ) ;
125+ const existingHostnames = new Set ( this . swarm . map ( item => item . hostname ) ) ;
126+
127+ const currentDeviceExists = existingIps . has ( currentDevice . currentIP ) || ( currentDevice . hostname && existingHostnames . has ( currentDevice . hostname ) ) ;
119128
129+ // If current device is not in swarm, add it to the list of devices to process
130+ if ( ! currentDeviceExists && currentDevice . ASICModel ) {
131+ currentDevice . IP = window . location . host ;
132+ foundDevices . unshift ( currentDevice ) ;
133+ }
134+
135+ // Filter out devices we already have - check both IP and currentIP
120136 const newDevices = foundDevices . filter ( device => {
121137 // Check if device IP matches any existing IP or currentIP
122138 const ipNotExists = ! existingIps . has ( device . IP ) ;
0 commit comments