48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
|
import { AuthService, AuthState } from './services/auth.service';
|
|
|
|
@Component({
|
|
selector: 'app-root',
|
|
templateUrl: './app.component.html',
|
|
styleUrls: ['./app.component.css']
|
|
})
|
|
export class AppComponent implements OnInit, OnDestroy {
|
|
showOverlay = true;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private authService: AuthService,
|
|
private router: Router
|
|
) { }
|
|
|
|
async ngOnInit(): Promise<void> {
|
|
console.log('AppComponent.ngInit()');
|
|
|
|
const chatLoginToken = await this.waitChatToken();
|
|
const authState = await this.authService.configureAndTryLogin(chatLoginToken);
|
|
|
|
if (authState !== AuthState.ChatLoggingInProcess) {
|
|
this.showOverlay = false;
|
|
}
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
// TODO no se ejecuta
|
|
console.log('AppComponent.ngDestroy()');
|
|
// this.authService.stopAutomaticRefresh();
|
|
}
|
|
|
|
private async waitChatToken(): Promise<string> {
|
|
const p = new Promise<string>((resolve) => {
|
|
this.router.events.subscribe((event) => {
|
|
if (event instanceof NavigationEnd) {
|
|
resolve(this.route.firstChild.snapshot.queryParams['loginToken']);
|
|
}
|
|
});
|
|
});
|
|
|
|
return await p;
|
|
}
|
|
}
|