From 259fa19a87cc46be9c60eba1a07802f560658979 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 20 Mar 2021 11:29:10 +0100 Subject: [PATCH] Added Backend Call Button --- frontend/src/app/app.module.ts | 2 - .../app/component/login/login.component.html | 2 + .../app/component/login/login.component.ts | 11 ++++ .../src/app/services/websocket.service.ts | 52 ------------------- 4 files changed, 13 insertions(+), 54 deletions(-) delete mode 100644 frontend/src/app/services/websocket.service.ts diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index d9d0508..e22a7c3 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -6,7 +6,6 @@ import {LandingComponent} from './component/landing/landing.component'; import {RestService} from './services/rest.service'; import {HTTP_INTERCEPTORS, HttpClientModule} from '@angular/common/http'; import {InterceptorService} from './services/interceptor.service'; -import {WebsocketService} from './services/websocket.service'; import {LoggerModule, NgxLoggerLevel} from 'ngx-logger'; import {environment} from '../environments/environment'; import {TestSubCompComponent} from './component/testsubcomp/test-sub-comp.component'; @@ -38,7 +37,6 @@ import { LoginComponent } from './component/login/login.component'; // enables injecting providers: [ RestService, - WebsocketService, { provide: HTTP_INTERCEPTORS, useClass: InterceptorService, multi: true }, diff --git a/frontend/src/app/component/login/login.component.html b/frontend/src/app/component/login/login.component.html index eea13c2..a6afd38 100644 --- a/frontend/src/app/component/login/login.component.html +++ b/frontend/src/app/component/login/login.component.html @@ -4,6 +4,8 @@

+ +
Token:
State: diff --git a/frontend/src/app/component/login/login.component.ts b/frontend/src/app/component/login/login.component.ts index ae56b10..e73fbb1 100644 --- a/frontend/src/app/component/login/login.component.ts +++ b/frontend/src/app/component/login/login.component.ts @@ -51,6 +51,17 @@ export class LoginComponent implements OnInit { .subscribe(data => this.loginHTML = this._sanitizer.bypassSecurityTrustHtml(data)); } + gotoBackend() { + const headerDict = { + 'Authorization': 'Bearer ' + this.id_token + }; + this.http.get('https://localhost:8000/api/login', + { + headers: new HttpHeaders(headerDict) + }) + .subscribe(data => console.log(data)); + } + paramsFromUrl() { const url = window.location.href; const params: string = url.split('#')[1]; diff --git a/frontend/src/app/services/websocket.service.ts b/frontend/src/app/services/websocket.service.ts deleted file mode 100644 index c936698..0000000 --- a/frontend/src/app/services/websocket.service.ts +++ /dev/null @@ -1,52 +0,0 @@ -import {Injectable} from '@angular/core'; -import {NGXLogger} from 'ngx-logger'; -import {fromEvent, interval, Observable} from 'rxjs'; - -import {environment} from '../../environments/environment'; -import {WSEvents} from '../interfaces/interface'; - -@Injectable({ - providedIn: 'root' -}) -export class WebsocketService { - private wsEndpoint = environment.ws_location + ':' + environment.ws_port + '/test-ws-endpoint/'; - private readonly ws: WebSocket; - private wsEvents: WSEvents; - - constructor(private logger: NGXLogger) { - this.logger.debug('Initiating ws connection on', this.wsEndpoint); - this.ws = new WebSocket(this.wsEndpoint); - - interval(5000).subscribe(() => { - // continuously check if the connection is still open - if (this.ws.readyState !== WebSocket.OPEN) { - this.logger.error('Lost websocket connection ...', this.ws); - } - }); - - } - - wsTestCall(msg: string): WSEvents { - this.logger.debug( - 'Performing ws test call', - 'current ws ready state ==', this.ws.readyState + ',', - 'expected == 1 == open'); - - if (this.ws.readyState === WebSocket.OPEN) { - this.ws.send(msg); - } else { - return undefined; - } - - if (!this.wsEvents) { - this.wsEvents = { - message: fromEvent(this.ws, 'message'), - error: fromEvent(this.ws, 'error'), - close: fromEvent(this.ws, 'close') - }; - } - - return this.wsEvents; - } - -}