Repeat signalR authenticate
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma 2020-04-16 11:04:39 +02:00
parent e964fa72f3
commit 9fbc946c68

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { IEventMessage } from '../models/event.message'; import { IEventMessage } from '../models/event.message';
import { Subject } from 'rxjs'; import { Subject, timer } from 'rxjs';
import { OAuthService } from 'angular-oauth2-oidc'; import { OAuthService } from 'angular-oauth2-oidc';
import { HubConnection, HubConnectionBuilder, LogLevel ,HttpTransportType} from '@microsoft/signalr'; import { HubConnection, HubConnectionBuilder, LogLevel ,HttpTransportType} from '@microsoft/signalr';
import { AppConfig } from "../shared/app.config"; import { AppConfig } from "../shared/app.config";
@ -14,6 +14,7 @@ export class EventService {
public event:Subject <IEventMessage> = new Subject<IEventMessage>(); public event:Subject <IEventMessage> = new Subject<IEventMessage>();
private _connection: HubConnection = null; private _connection: HubConnection = null;
private _apiEndPoint: string; private _apiEndPoint: string;
public authenticated:boolean = false;
constructor(private oauthService: OAuthService, private appConfig: AppConfig) { constructor(private oauthService: OAuthService, private appConfig: AppConfig) {
this._apiEndPoint = appConfig.getConfig("apiEndPoint"); this._apiEndPoint = appConfig.getConfig("apiEndPoint");
@ -39,6 +40,12 @@ export class EventService {
var accessToken = this.oauthService.getAccessToken(); var accessToken = this.oauthService.getAccessToken();
if (accessToken) { if (accessToken) {
this._connection.send('authenticate', this.oauthService.getAccessToken()); this._connection.send('authenticate', this.oauthService.getAccessToken());
this.authenticated=true;
} else {
//try again after half a second
setTimeout(() => {
this.Authenticate();
}, 800);
} }
} }
} }