diff --git a/main/http_server/axe-os/src/app/components/swarm/swarm.component.html b/main/http_server/axe-os/src/app/components/swarm/swarm.component.html index 34e31f22..8340595b 100644 --- a/main/http_server/axe-os/src/app/components/swarm/swarm.component.html +++ b/main/http_server/axe-os/src/app/components/swarm/swarm.component.html @@ -15,7 +15,7 @@ - +
diff --git a/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts b/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts index 104f4f8c..5df3254e 100644 --- a/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts +++ b/main/http_server/axe-os/src/app/components/swarm/swarm.component.ts @@ -1,18 +1,18 @@ import { HttpClient } from '@angular/common/http'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { ToastrService } from 'ngx-toastr'; import { BehaviorSubject, catchError, combineLatest, debounce, debounceTime, forkJoin, from, interval, map, mergeAll, mergeMap, Observable, of, startWith, switchMap, take, timeout, toArray } from 'rxjs'; import { LocalStorageService } from 'src/app/local-storage.service'; import { SystemService } from 'src/app/services/system.service'; - +const REFRESH_TIME_SECONDS = 30; const SWARM_DATA = 'SWARM_DATA' @Component({ selector: 'app-swarm', templateUrl: './swarm.component.html', styleUrls: ['./swarm.component.scss'] }) -export class SwarmComponent implements OnInit { +export class SwarmComponent implements OnInit, OnDestroy { public swarm: any[] = []; @@ -23,6 +23,9 @@ export class SwarmComponent implements OnInit { public scanning = false; + public refreshIntervalRef!: number; + public refreshIntervalTime = REFRESH_TIME_SECONDS; + constructor( private fb: FormBuilder, private systemService: SystemService, @@ -36,6 +39,7 @@ export class SwarmComponent implements OnInit { }) } + ngOnInit(): void { const swarmData = this.localStorageService.getObject(SWARM_DATA); console.log(swarmData); @@ -45,8 +49,19 @@ export class SwarmComponent implements OnInit { } else { this.swarm = swarmData; } + + this.refreshIntervalRef = window.setInterval(() => { + this.refreshIntervalTime --; + if(this.refreshIntervalTime <= 0){ + this.refreshIntervalTime = REFRESH_TIME_SECONDS; + this.refreshList(); + } + }, 1000); } + ngOnDestroy(): void { + window.clearInterval(this.refreshIntervalRef); + } @@ -142,7 +157,7 @@ export class SwarmComponent implements OnInit { }), timeout(5000), catchError(error => { - return this.swarm.find(axeOs => axeOs.IP == ipAddr); + return of(this.swarm.find(axeOs => axeOs.IP == ipAddr)); }) ), 256 // Limit concurrency to avoid overload