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'
8 selector: 'my-live-stream-information',
9 templateUrl: './live-stream-information.component.html',
10 styleUrls: [ './live-stream-information.component.scss' ]
12 export class LiveStreamInformationComponent {
13 @ViewChild('modal', { static: true }) modal: ElementRef
17 latestLiveSessions: LiveVideoSession[] = []
20 private modalService: NgbModal,
21 private liveVideoService: LiveVideoService
28 this.loadLiveInfo(video)
31 .open(this.modal, { centered: true })
34 getVideoUrl (video: { shortUUID: string }) {
35 return Video.buildWatchUrl(video)
38 getErrorLabel (session: LiveVideoSession) {
39 if (!session.error) return undefined
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`
49 return errors[session.error]
52 isReplayBeingProcessed (session: LiveVideoSession) {
54 if (!session.endDate) return false
56 return session.saveReplay && !session.endingProcessed
59 private loadLiveInfo (video: Video) {
60 this.liveVideoService.getVideoLive(video.id)
61 .subscribe(live => this.live = live)
63 this.liveVideoService.listSessions(video.id)
64 .subscribe(({ data }) => this.latestLiveSessions = data.reverse().slice(0, 5))