aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_services/signal-r.service.ts
blob: 6a2e61e9ce4c0bc57bf0bf200d97ca12f8e585ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Injectable } from '@angular/core';
import * as signalR from "@microsoft/signalr";
import { CookieService } from 'ngx-cookie-service';
import { Configuration } from '../configuration.service';
@Injectable({
  providedIn: 'root'
})
export class SignalRService {
  public hubConnection?: signalR.HubConnection;
  public startConnection = () => {

    this.hubConnection = new signalR.HubConnectionBuilder()
      .withUrl(Configuration.settings.apiWSUrl, {
        accessTokenFactory: () => this.cookie.get("token"),
        withCredentials: false
      }).build();

    this.hubConnection.on("Notify", (message: string) => {
      //console.log(" " + message);
    });

    this.hubConnection
      .start()
      .then(() => {})
      .catch(err => {})
  }

  public stopConnection = () => {
    this.hubConnection?.stop();
  }

  constructor(private cookie: CookieService) { }
}