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 { 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 { const p = new Promise((resolve) => { this.router.events.subscribe((event) => { if (event instanceof NavigationEnd) { resolve(this.route.firstChild.snapshot.queryParams['loginToken']); } }); }); return await p; } }