aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-video-live/live-video.service.ts
blob: 89bfd84a0130bf79a805222330af4b8ed1f70a80 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { catchError } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { RestExtractor } from '@app/core'
import { LiveVideo, LiveVideoCreate, LiveVideoSession, LiveVideoUpdate, ResultList, VideoCreateResult } from '@shared/models'
import { environment } from '../../../environments/environment'
import { VideoService } from '../shared-main'

@Injectable()
export class LiveVideoService {
  static BASE_VIDEO_LIVE_URL = environment.apiUrl + '/api/v1/videos/live/'

  constructor (
    private authHttp: HttpClient,
    private restExtractor: RestExtractor
  ) {}

  goLive (video: LiveVideoCreate) {
    return this.authHttp
               .post<{ video: VideoCreateResult }>(LiveVideoService.BASE_VIDEO_LIVE_URL, video)
               .pipe(catchError(err => this.restExtractor.handleError(err)))
  }

  getVideoLive (videoId: number | string) {
    return this.authHttp
               .get<LiveVideo>(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId)
               .pipe(catchError(err => this.restExtractor.handleError(err)))
  }

  listSessions (videoId: number | string) {
    return this.authHttp
               .get<ResultList<LiveVideoSession>>(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId + '/sessions')
               .pipe(catchError(err => this.restExtractor.handleError(err)))
  }

  findLiveSessionFromVOD (videoId: number | string) {
    return this.authHttp
               .get<LiveVideoSession>(VideoService.BASE_VIDEO_URL + '/' + videoId + '/live-session')
               .pipe(catchError(err => this.restExtractor.handleError(err)))
  }

  updateLive (videoId: number | string, liveUpdate: LiveVideoUpdate) {
    return this.authHttp
      .put(LiveVideoService.BASE_VIDEO_LIVE_URL + videoId, liveUpdate)
      .pipe(catchError(err => this.restExtractor.handleError(err)))
  }
}