2024-10-17 08:48:15 +00:00
|
|
|
import { CommonModule, DatePipe, isPlatformBrowser } from '@angular/common';
|
|
|
|
import { Component, OnInit, Inject, PLATFORM_ID, NgZone, OnDestroy } from '@angular/core';
|
2024-10-25 19:09:34 +00:00
|
|
|
import { Router, RouterOutlet } from '@angular/router';
|
2024-10-17 08:48:15 +00:00
|
|
|
import { FormsModule } from '@angular/forms'
|
|
|
|
import { HermesClientService } from './hermes-client.service';
|
|
|
|
import { AuthGuard } from './shared/auth/auth.guard'
|
|
|
|
import { Subscription } from 'rxjs';
|
|
|
|
import { PolicyComponent } from "./policy/policy.component";
|
|
|
|
import { NavigationComponent } from "./navigation/navigation.component";
|
|
|
|
import EventService from './shared/services/EventService';
|
|
|
|
import { ApiAuthenticationService } from './shared/services/api/api-authentication.service';
|
2024-07-06 01:01:52 +00:00
|
|
|
|
|
|
|
@Component({
|
2024-10-17 08:48:15 +00:00
|
|
|
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
|
|
|
})
|
2024-10-17 08:48:15 +00:00
|
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
|
|
private isBrowser: boolean;
|
|
|
|
private ngZone: NgZone;
|
2024-10-25 19:09:34 +00:00
|
|
|
private subscriptions: Subscription[];
|
2024-10-17 08:48:15 +00:00
|
|
|
pipe = new DatePipe('en-US')
|
|
|
|
|
|
|
|
|
2024-10-25 19:09:34 +00:00
|
|
|
constructor(private auth: ApiAuthenticationService, private client: HermesClientService, private events: EventService, private router: Router, ngZone: NgZone, @Inject(PLATFORM_ID) private platformId: Object) {
|
2024-10-17 08:48:15 +00:00
|
|
|
this.ngZone = ngZone;
|
2024-10-25 19:09:34 +00:00
|
|
|
this.isBrowser = isPlatformBrowser(this.platformId);
|
|
|
|
this.subscriptions = [];
|
2024-10-17 08:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
|
if (!this.isBrowser)
|
|
|
|
return;
|
|
|
|
|
|
|
|
this.auth.update();
|
|
|
|
|
2024-10-25 19:09:34 +00:00
|
|
|
this.addSubscription(this.events.listen('logoff', (message) => {
|
|
|
|
localStorage.removeItem('jwt');
|
|
|
|
if (!document.location.href.includes('/login')) {
|
|
|
|
this.router.navigate(['/login?warning=' + message]);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.addSubscription(this.events.listen('login', (_) => {
|
|
|
|
if (document.location.href.includes('/login')) {
|
|
|
|
this.router.navigate(['/tts-login']);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2024-10-17 08:48:15 +00:00
|
|
|
this.client.connect();
|
|
|
|
this.ngZone.runOutsideAngular(() => setInterval(() => this.client.heartbeat(), 15000));
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
2024-10-25 19:09:34 +00:00
|
|
|
for (let s of this.subscriptions) {
|
|
|
|
s.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private addSubscription(s: Subscription) {
|
|
|
|
this.subscriptions.push(s);
|
2024-10-17 08:48:15 +00:00
|
|
|
}
|
|
|
|
}
|