Repeat signalR authenticate
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
e964fa72f3
commit
9fbc946c68
@ -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");
|
||||||
@ -32,13 +33,19 @@ export class EventService {
|
|||||||
});
|
});
|
||||||
this._connection.start().then(() => {
|
this._connection.start().then(() => {
|
||||||
this.Authenticate();
|
this.Authenticate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Authenticate() {
|
Authenticate() {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user