1 import { Observable, ReplaySubject } from 'rxjs'
2 import { catchError, map, tap } from 'rxjs/operators'
3 import { HttpClient } from '@angular/common/http'
4 import { Injectable } from '@angular/core'
5 import { RestExtractor } from '@app/core'
6 import { Account as ServerAccount, VideoChannel as ServerVideoChannel } from '@shared/models'
7 import { environment } from '../../../../environments/environment'
9 type KeysOfUnion<T> = T extends T ? keyof T: never
10 type ServerActor = KeysOfUnion<ServerAccount | ServerVideoChannel>
13 export class ActorService {
14 static BASE_ACTOR_API_URL = environment.apiUrl + '/api/v1/actors/'
16 actorLoaded = new ReplaySubject<string>(1)
19 private authHttp: HttpClient,
20 private restExtractor: RestExtractor
23 getActorType (actorName: string): Observable<string> {
24 return this.authHttp.get<ServerActor>(ActorService.BASE_ACTOR_API_URL + actorName)
27 if (actorHash[ 'userId' ]) {
33 tap(actor => this.actorLoaded.next(actor)),
34 catchError(res => this.restExtractor.handleError(res))