First successful test joining matrix server

This commit is contained in:
Eneko Nieto
2021-03-04 13:53:32 +01:00
parent efe1c9002c
commit 34d6e66d3e
12 changed files with 273 additions and 204 deletions

View File

@@ -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;
}
}