diff --git a/projects/common/src/fm/services/event.service.ts b/projects/common/src/fm/services/event.service.ts index 8a90d64..72d07f7 100644 --- a/projects/common/src/fm/services/event.service.ts +++ b/projects/common/src/fm/services/event.service.ts @@ -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 = new Subject(); 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); } } }