First successful test joining matrix server
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { AuthService } from './services/auth.service';
|
||||
import { ChatService } from './services/chat.service';
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||
import { AuthService, AuthState } from './services/auth.service';
|
||||
|
||||
@Component({
|
||||
// tslint:disable-next-line:component-selector
|
||||
@@ -8,21 +8,41 @@ import { ChatService } from './services/chat.service';
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.css'],
|
||||
})
|
||||
export class AppComponent implements OnInit {
|
||||
export class AppComponent implements OnInit, OnDestroy {
|
||||
showOverlay = true;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private authService: AuthService,
|
||||
private chatService: ChatService
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
console.log('AppComponent.ngInit()');
|
||||
const isLogged = await this.authService.isLogged;
|
||||
this.showOverlay = false;
|
||||
if (isLogged) {
|
||||
console.log('GO TO SSO LOGIN');
|
||||
this.chatService.goToSsoLogin();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user