Repeat signalR authenticate
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details

feature/MinimizeSolution
Willem Dantuma 2020-04-16 11:04:39 +02:00
parent e964fa72f3
commit 9fbc946c68
1 changed files with 9 additions and 2 deletions

View File

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