Renamed prefixes in angular.json
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
This commit is contained in:
29
projects/common/src/fm/services/event.service.ts
Normal file
29
projects/common/src/fm/services/event.service.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { IEventMessage } from '../models/event.message';
|
||||
import { Subject } from 'rxjs';
|
||||
import { OAuthService } from 'angular-oauth2-oidc';
|
||||
import { HubConnection, HubConnectionBuilder, LogLevel } from '@aspnet/signalr';
|
||||
import { AppConfig } from "../shared/app.config";
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class EventService {
|
||||
|
||||
public event:Subject <IEventMessage> = new Subject<IEventMessage>();
|
||||
private _connection: HubConnection = null;
|
||||
private _apiEndPoint: string;
|
||||
|
||||
constructor(private oauthService: OAuthService, private appConfig: AppConfig) {
|
||||
this._apiEndPoint = appConfig.getConfig("apiEndPoint");
|
||||
this._connection = new HubConnectionBuilder().withUrl(`${ this._apiEndPoint}/eventHub`).configureLogging(LogLevel.Information).build();
|
||||
this._connection.start().then(() => {
|
||||
var accessToken = oauthService.getAccessToken();
|
||||
if (accessToken) {
|
||||
this._connection.send('authenticate', oauthService.getAccessToken());
|
||||
}
|
||||
});
|
||||
this._connection.on('event', eventMessage => {
|
||||
this.event.next(eventMessage);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user