1 import { HttpClient } from '@angular/common/http'
2 import { Injectable } from '@angular/core'
3 import 'rxjs/add/operator/do'
4 import { ReplaySubject } from 'rxjs/ReplaySubject'
5 import { ServerConfig } from '../../../../../shared'
6 import { environment } from '../../../environments/environment'
9 export class ServerService {
10 private static BASE_CONFIG_URL = environment.apiUrl + '/api/v1/config/'
11 private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/'
13 videoPrivaciesLoaded = new ReplaySubject<boolean>(1)
14 videoCategoriesLoaded = new ReplaySubject<boolean>(1)
15 videoLicencesLoaded = new ReplaySubject<boolean>(1)
16 videoLanguagesLoaded = new ReplaySubject<boolean>(1)
18 private config: ServerConfig = {
19 serverVersion: 'Unknown',
24 enabledResolutions: []
38 private videoCategories: Array<{ id: number, label: string }> = []
39 private videoLicences: Array<{ id: number, label: string }> = []
40 private videoLanguages: Array<{ id: number, label: string }> = []
41 private videoPrivacies: Array<{ id: number, label: string }> = []
43 constructor (private http: HttpClient) {}
46 this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL)
47 .subscribe(data => this.config = data)
50 loadVideoCategories () {
51 return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded)
54 loadVideoLicences () {
55 return this.loadVideoAttributeEnum('licences', this.videoLicences, this.videoLicencesLoaded)
58 loadVideoLanguages () {
59 return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded)
62 loadVideoPrivacies () {
63 return this.loadVideoAttributeEnum('privacies', this.videoPrivacies, this.videoPrivaciesLoaded)
70 getVideoCategories () {
71 return this.videoCategories
75 return this.videoLicences
78 getVideoLanguages () {
79 return this.videoLanguages
82 getVideoPrivacies () {
83 return this.videoPrivacies
86 private loadVideoAttributeEnum (
87 attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
88 hashToPopulate: { id: number, label: string }[],
89 notifier: ReplaySubject<boolean>
91 return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
96 id: parseInt(dataKey, 10),