]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-video-live/live-stream-information.component.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-live / live-stream-information.component.ts
1 import { Component, ElementRef, ViewChild } from '@angular/core'
2 import { Video } from '@app/shared/shared-main'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { LiveVideo, LiveVideoError, LiveVideoSession } from '@shared/models'
5 import { LiveVideoService } from './live-video.service'
6
7 @Component({
8 selector: 'my-live-stream-information',
9 templateUrl: './live-stream-information.component.html',
10 styleUrls: [ './live-stream-information.component.scss' ]
11 })
12 export class LiveStreamInformationComponent {
13 @ViewChild('modal', { static: true }) modal: ElementRef
14
15 video: Video
16 live: LiveVideo
17 latestLiveSessions: LiveVideoSession[] = []
18
19 constructor (
20 private modalService: NgbModal,
21 private liveVideoService: LiveVideoService
22 ) { }
23
24 show (video: Video) {
25 this.video = video
26 this.live = undefined
27
28 this.loadLiveInfo(video)
29
30 this.modalService
31 .open(this.modal, { centered: true })
32 }
33
34 getVideoUrl (video: { shortUUID: string }) {
35 return Video.buildWatchUrl(video)
36 }
37
38 getErrorLabel (session: LiveVideoSession) {
39 if (!session.error) return undefined
40
41 const errors: { [ id in LiveVideoError ]: string } = {
42 [LiveVideoError.BAD_SOCKET_HEALTH]: $localize`Server too slow`,
43 [LiveVideoError.BLACKLISTED]: $localize`Live blacklisted`,
44 [LiveVideoError.DURATION_EXCEEDED]: $localize`Max duration exceeded`,
45 [LiveVideoError.FFMPEG_ERROR]: $localize`Server error`,
46 [LiveVideoError.QUOTA_EXCEEDED]: $localize`Quota exceeded`,
47 [LiveVideoError.RUNNER_JOB_CANCEL]: $localize`Runner job cancelled`,
48 [LiveVideoError.RUNNER_JOB_ERROR]: $localize`Error in runner job`
49 }
50
51 return errors[session.error]
52 }
53
54 isReplayBeingProcessed (session: LiveVideoSession) {
55 // Running live
56 if (!session.endDate) return false
57
58 return session.saveReplay && !session.endingProcessed
59 }
60
61 private loadLiveInfo (video: Video) {
62 this.liveVideoService.getVideoLive(video.id)
63 .subscribe(live => this.live = live)
64
65 this.liveVideoService.listSessions(video.id)
66 .subscribe(({ data }) => this.latestLiveSessions = data.reverse().slice(0, 5))
67 }
68 }