|
|
|
@ -3,6 +3,8 @@ import { AuthService } from '../auth/auth.service';
|
|
|
|
|
|
|
|
|
|
import { HubConnection } from '@aspnet/signalr';
|
|
|
|
|
import * as signalR from '@aspnet/signalr';
|
|
|
|
|
import { PlatformLocation } from '@angular/common';
|
|
|
|
|
import { platformBrowser } from '@angular/platform-browser';
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class SignalRNotificationService {
|
|
|
|
@ -10,15 +12,19 @@ export class SignalRNotificationService {
|
|
|
|
|
private hubConnection: HubConnection | undefined;
|
|
|
|
|
public Notification: EventEmitter<any>;
|
|
|
|
|
|
|
|
|
|
constructor(private authService: AuthService) {
|
|
|
|
|
constructor(private authService: AuthService, private platform: PlatformLocation) {
|
|
|
|
|
this.Notification = new EventEmitter<any>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public initialize(): void {
|
|
|
|
|
|
|
|
|
|
this.stopConnection();
|
|
|
|
|
|
|
|
|
|
this.hubConnection = new signalR.HubConnectionBuilder().withUrl("/hubs/notification", {
|
|
|
|
|
let url = "/hubs/notification";
|
|
|
|
|
const baseUrl = this.platform.getBaseHrefFromDOM();
|
|
|
|
|
if(baseUrl !== null && baseUrl.length > 1) {
|
|
|
|
|
url = baseUrl + url;
|
|
|
|
|
}
|
|
|
|
|
this.hubConnection = new signalR.HubConnectionBuilder().withUrl(url, {
|
|
|
|
|
accessTokenFactory: () => {
|
|
|
|
|
return this.authService.getToken();
|
|
|
|
|
}
|
|
|
|
|