diff --git a/package-lock.json b/package-lock.json index 827167d..c3a75fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -627,16 +627,6 @@ "resolved": "https://registry.npmjs.org/@angular/router/-/router-9.1.0.tgz", "integrity": "sha512-cExO1nPnoPFiUJWZ28hTHozPLFoCmqr3xqcM57We0hhKE0esdrO+gRWKRH0EJERukLbU8coPKVhA8daGUpASiQ==" }, - "@aspnet/signalr": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/@aspnet/signalr/-/signalr-1.1.4.tgz", - "integrity": "sha512-Jp9nPc8hmmhbG9OKiHe2fOKskBHfg+3Y9foSKHxjgGtyI743hXjGFv3uFlUg503K9f8Ilu63gQt3fDkLICBRyg==", - "requires": { - "eventsource": "^1.0.7", - "request": "^2.88.0", - "ws": "^6.0.0" - } - }, "@babel/code-frame": { "version": "7.5.5", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.5.5.tgz", @@ -2702,14 +2692,14 @@ } }, "@farmmaps/common": { - "version": "0.0.1-prerelease.234", - "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.234.tgz", - "integrity": "sha512-JjMI1nMDZsDnHmGBamBkMMDaB2vlFlpESWRiz0XWqZMkyWCPjxK8KOsPlSUZuwZFSCsD0gk28bTZZlcT+4L4cw==" + "version": "0.0.1-prerelease.241", + "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common/-/common-0.0.1-prerelease.241.tgz", + "integrity": "sha512-GLej5+PJng5uS/OUiKZIe/rREyi/tINn8CVmEH6sROhiMizpXM7k9c8PZN0+oayPfNQ73jzd+FV6EcNt2jOCSw==" }, "@farmmaps/common-map": { - "version": "0.0.1-prerelease.234", - "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.234.tgz", - "integrity": "sha512-WXmWSgq1UF3rTuQV5avHzfOpOyLhbtNQTv7Bqtpn3kyEJDepfOe2u2uYHoQiA+j+S91XVqBkAL8SOC/rtUAVMg==" + "version": "0.0.1-prerelease.241", + "resolved": "https://repository.akkerweb.nl/repository/npm-group/@farmmaps/common-map/-/common-map-0.0.1-prerelease.241.tgz", + "integrity": "sha512-Q9GnIbe0SjrJ97qCOQHJTquNeRNdPu5gIYR6gNPqMN8CaTLu6lGdON5nn7M5+TEMjPgGSuqpKlHpQQssIyqrXA==" }, "@istanbuljs/schema": { "version": "0.1.2", @@ -2752,6 +2742,16 @@ } } }, + "@microsoft/signalr": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@microsoft/signalr/-/signalr-3.1.3.tgz", + "integrity": "sha512-jcjzvPDP3VbtmUoTDwgKEjaQ1m4FgSiS00zvybcF8UweAkdWUAYsaMXTISEk7E5nD0jrxyMMdSuPGgw9AcG46w==", + "requires": { + "eventsource": "^1.0.7", + "request": "^2.88.0", + "ws": "^6.0.0" + } + }, "@ng-bootstrap/ng-bootstrap": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/@ng-bootstrap/ng-bootstrap/-/ng-bootstrap-6.0.2.tgz", diff --git a/package.json b/package.json index e3bf73e..20520c1 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,9 @@ "@angular/platform-browser": "~9.1.0", "@angular/platform-browser-dynamic": "~9.1.0", "@angular/router": "~9.1.0", - "@aspnet/signalr": "^1.1.4", - "@farmmaps/common": ">=0.0.1-prerelease.234 <0.0.1", - "@farmmaps/common-map": ">=0.0.1-prerelease.234 <0.0.1", + "@microsoft/signalr": "^3.1.3", + "@farmmaps/common": ">=0.0.1-prerelease.236 <0.0.1", + "@farmmaps/common-map": ">=0.0.1-prerelease.236 <0.0.1", "@ng-bootstrap/ng-bootstrap": "^6.0", "@ngrx/effects": "^9.0", "@ngrx/router-store": "^9.0", diff --git a/projects/common/src/fm/services/event.service.ts b/projects/common/src/fm/services/event.service.ts index 2391478..8a90d64 100644 --- a/projects/common/src/fm/services/event.service.ts +++ b/projects/common/src/fm/services/event.service.ts @@ -1,37 +1,44 @@ -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 ,HttpTransportType} from '@aspnet/signalr'; -import { AppConfig } from "../shared/app.config"; - - -@Injectable({ - providedIn: 'root', -}) -export class EventService { - - public event:Subject = new Subject(); - 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`, - { transport: HttpTransportType.WebSockets, - // accessTokenFactory: () => { - // return oauthService.getAccessToken(); - // }, - skipNegotiation:true - }).configureLogging(LogLevel.Information).build(); - this._connection.on('event', eventMessage => { - this.event.next(eventMessage); - }); - this._connection.start().then(() => { - var accessToken = oauthService.getAccessToken(); - if (accessToken) { - this._connection.send('authenticate', oauthService.getAccessToken()); - } - }); - } -} +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 ,HttpTransportType} from '@microsoft/signalr'; +import { AppConfig } from "../shared/app.config"; + + +@Injectable({ + providedIn: 'root', +}) +export class EventService { + + public event:Subject = new Subject(); + 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`, + { transport: HttpTransportType.WebSockets, + // accessTokenFactory: () => { + // return oauthService.getAccessToken(); + // }, + skipNegotiation:true + }).withAutomaticReconnect().configureLogging(LogLevel.Information).build(); + this._connection.on('event', eventMessage => { + this.event.next(eventMessage); + }); + this._connection.onreconnected( event => { + this.Authenticate(); + }); + this._connection.start().then(() => { + this.Authenticate(); + }); + } + + Authenticate() { + var accessToken = this.oauthService.getAccessToken(); + if (accessToken) { + this._connection.send('authenticate', this.oauthService.getAccessToken()); + } + } +}