All files / src/app/components/global-error global-error.component.ts

73.33% Statements 11/15
66.66% Branches 4/6
83.33% Functions 5/6
71.42% Lines 10/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                      96x       1x 1x   1x     1x   1x   2x           1x     2x 2x                        
import { NgIf } from '@angular/common';
import { Component, OnDestroy, OnInit } from '@angular/core';
import { interval, Subject, takeUntil } from 'rxjs';
import { TwinpadApiService } from '../../services/twinpad-api.service';
 
@Component({
  selector: 'app-global-error',
  imports: [NgIf],
  templateUrl: './global-error.component.html',
  styleUrl: './global-error.component.scss'
})
export class GlobalErrorComponent implements OnInit, OnDestroy{
  nextRequest: number;
  nextPingWait: number;
  image: string;
  images = ['towing', 'alien-invasion', 'server-down'];
  private destroy$ = new Subject<void>();
 
  constructor(private twinpadApiService: TwinpadApiService) {}
 
  ngOnInit(){
    this.image =  'assets/svg/'+ this.images[Math.floor(Math.random() * this.images.length)] + '.svg';
 
    this.twinpadApiService.cloudStatusBehaviorSubject$?.subscribe({
      next: status => {
        Iif(status.services.backend !== "up"){
          this.nextRequest =  Date.now() + 1000*this.twinpadApiService.statusRefreshTime;
        }
      }
    });
 
    interval(200)
    .pipe(takeUntil(this.destroy$))
    .subscribe(() => {
      this.nextPingWait = Math.round((this.nextRequest - Date.now() ) *0.001);
      Iif (this.nextPingWait < 0){
        this.nextPingWait = 0;
      }
    });
  }
 
  ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
  }
 
}