hermes-web-angular/src/app/app.component.ts

50 lines
2.0 KiB
TypeScript
Raw Normal View History

import { CommonModule, DatePipe, isPlatformBrowser } from '@angular/common';
import { Component, OnInit, Inject, PLATFORM_ID, NgZone, OnDestroy } from '@angular/core';
import { Router, RouterModule, RouterOutlet, Routes } from '@angular/router';
import { FormsModule } from '@angular/forms'
import { HermesClientService } from './hermes-client.service';
import { AuthGuard } from './shared/auth/auth.guard'
import { Subscription } from 'rxjs';
import { Policy, PolicyScope } from './shared/models/policy';
import { PolicyComponent } from "./policy/policy.component";
import { NavigationComponent } from "./navigation/navigation.component";
import EventService from './shared/services/EventService';
import { HttpClient } from '@angular/common/http';
import { ApiAuthenticationService } from './shared/services/api/api-authentication.service';
2024-07-06 01:01:52 +00:00
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet, CommonModule, FormsModule, PolicyComponent, NavigationComponent],
providers: [AuthGuard],
templateUrl: './app.component.html',
styleUrl: './app.component.scss'
2024-07-06 01:01:52 +00:00
})
export class AppComponent implements OnInit, OnDestroy {
private isBrowser: boolean;
private ngZone: NgZone;
private subscription: Subscription | undefined;
pipe = new DatePipe('en-US')
constructor(private auth: ApiAuthenticationService, private client: HermesClientService, private events: EventService, private http: HttpClient, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
this.ngZone = ngZone;
this.isBrowser = isPlatformBrowser(this.platformId)
}
ngOnInit(): void {
if (!this.isBrowser)
return;
this.auth.update();
const rand = Math.random() * 100000 | 0;
this.client.subscribe(4, (data) => console.log("Request ack received", rand, data));
this.client.connect();
this.ngZone.runOutsideAngular(() => setInterval(() => this.client.heartbeat(), 15000));
}
ngOnDestroy() {
}
}