1
1
import { Injectable } from '@angular/core' ;
2
2
import { HttpClient , HttpHeaders } from "@angular/common/http" ;
3
- import { catchError , filter , Observable , of } from "rxjs" ;
3
+ import { catchError , filter , Observable , of , retry } from "rxjs" ;
4
4
import { TcrRole } from "../interfaces/tcr-role" ;
5
5
import { WebsocketService } from "./websocket.service" ;
6
6
import { TcrMessage , TcrMessageType } from "../interfaces/tcr-message" ;
7
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop" ;
7
8
8
9
@Injectable ( {
9
10
providedIn : 'root'
@@ -12,11 +13,11 @@ export class TcrRolesService {
12
13
private apiUrl = `/api` ; // URL to web api
13
14
public webSocket$ : Observable < TcrMessage > ;
14
15
15
- constructor (
16
- private http : HttpClient ,
17
- private ws : WebsocketService ) {
16
+ constructor ( private http : HttpClient , private ws : WebsocketService ) {
18
17
this . webSocket$ = this . ws . webSocket$ . pipe (
19
- filter ( message => message . type === TcrMessageType . ROLE )
18
+ filter ( message => message . type === TcrMessageType . ROLE ) ,
19
+ retry ( { delay : 5_000 } ) ,
20
+ takeUntilDestroyed ( ) ,
20
21
)
21
22
}
22
23
@@ -28,10 +29,9 @@ export class TcrRolesService {
28
29
} )
29
30
} ;
30
31
31
- return this . http . get < TcrRole > ( url , httpOptions )
32
- . pipe (
33
- catchError ( this . handleError < TcrRole > ( 'getRole' ) )
34
- ) ;
32
+ return this . http . get < TcrRole > ( url , httpOptions ) . pipe (
33
+ catchError ( this . handleError < TcrRole > ( 'getRole' ) )
34
+ ) ;
35
35
}
36
36
37
37
activateRole ( name : string , state : boolean ) : Observable < TcrRole > {
@@ -44,7 +44,7 @@ export class TcrRolesService {
44
44
} ;
45
45
46
46
return this . http . post < TcrRole > ( url , httpOptions ) . pipe (
47
- catchError ( this . handleError < TcrRole > ( 'activateRole' ) )
47
+ catchError ( this . handleError < TcrRole > ( 'activateRole' ) ) ,
48
48
) ;
49
49
}
50
50
0 commit comments