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 = {
23 enabledResolutions: []
37 private videoCategories: Array<{ id: number, label: string }> = []
38 private videoLicences: Array<{ id: number, label: string }> = []
39 private videoLanguages: Array<{ id: number, label: string }> = []
40 private videoPrivacies: Array<{ id: number, label: string }> = []
42 constructor (private http: HttpClient) {}
45 this.http.get<ServerConfig>(ServerService.BASE_CONFIG_URL)
46 .subscribe(data => this.config = data)
49 loadVideoCategories () {
50 return this.loadVideoAttributeEnum('categories', this.videoCategories, this.videoCategoriesLoaded)
53 loadVideoLicences () {
54 return this.loadVideoAttributeEnum('licences', this.videoLicences, this.videoLicencesLoaded)
57 loadVideoLanguages () {
58 return this.loadVideoAttributeEnum('languages', this.videoLanguages, this.videoLanguagesLoaded)
61 loadVideoPrivacies () {
62 return this.loadVideoAttributeEnum('privacies', this.videoPrivacies, this.videoPrivaciesLoaded)
69 getVideoCategories () {
70 return this.videoCategories
74 return this.videoLicences
77 getVideoLanguages () {
78 return this.videoLanguages
81 getVideoPrivacies () {
82 return this.videoPrivacies
85 private loadVideoAttributeEnum (
86 attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
87 hashToPopulate: { id: number, label: string }[],
88 notifier: ReplaySubject<boolean>
90 return this.http.get(ServerService.BASE_VIDEO_URL + attributeName)
95 id: parseInt(dataKey, 10),