]>
Commit | Line | Data |
---|---|---|
1 | import { catchError } from 'rxjs/operators' | |
2 | import { HttpClient } from '@angular/common/http' | |
3 | import { Injectable } from '@angular/core' | |
4 | import { RestExtractor } from '@app/core' | |
5 | import { LiveVideo, LiveVideoCreate, LiveVideoSession, LiveVideoUpdate, ResultList, VideoCreateResult } from '@shared/models' | |
6 | import { environment } from '../../../environments/environment' | |
7 | import { VideoService } from '../shared-main' | |
8 | ||
9 | @Injectable() | |
10 | export class LiveVideoService { | |
11 | static BASE_VIDEO_LIVE_URL = environment.apiUrl + '/api/v1/videos/live/' | |
12 | ||
13 | constructor ( | |
14 | private authHttp: HttpClient, | |
15 | private restExtractor: RestExtractor | |
16 | ) {} | |
17 | ||
18 | goLive (video: LiveVideoCreate) { | |
19 | return this.authHttp | |
20 | .post<{ video: VideoCreateResult }>(LiveVideoService.BASE_VIDEO_LIVE_URL, video) | |
21 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
22 | } | |
23 | ||
24 | getVideoLive (videoId: number | string) { | |
25 | return this.authHttp | |
26 | .get<LiveVideo>(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId) | |
27 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
28 | } | |
29 | ||
30 | listSessions (videoId: number | string) { | |
31 | return this.authHttp | |
32 | .get<ResultList<LiveVideoSession>>(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId + '/sessions') | |
33 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
34 | } | |
35 | ||
36 | findLiveSessionFromVOD (videoId: number | string) { | |
37 | return this.authHttp | |
38 | .get<LiveVideoSession>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/live-session') | |
39 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
40 | } | |
41 | ||
42 | updateLive (videoId: number | string, liveUpdate: LiveVideoUpdate) { | |
43 | return this.authHttp | |
44 | .put(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId, liveUpdate) | |
45 | .pipe(catchError(err => this.restExtractor.handleError(err))) | |
46 | } | |
47 | } |