Added Backend Call Button
This commit is contained in:
parent
80e6de5219
commit
259fa19a87
@ -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
|
||||
},
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
<br>
|
||||
<button (click)="paramsFromUrl()">Get Params from URL</button>
|
||||
<br>
|
||||
<button (click)="gotoBackend()">Call Backend</button>
|
||||
<br>
|
||||
Token: <input type="text" [(ngModel)]="id_token">
|
||||
<br>
|
||||
State: <input type="text" [(ngModel)]="state">
|
||||
|
||||
@ -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];
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user