]>
Commit | Line | Data |
---|---|---|
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 | } | |
48 | ||
49 | return errors[session.error] | |
50 | } | |
51 | ||
52 | private loadLiveInfo (video: Video) { | |
53 | this.liveVideoService.getVideoLive(video.id) | |
54 | .subscribe(live => this.live = live) | |
55 | ||
56 | this.liveVideoService.listSessions(video.id) | |
57 | .subscribe(({ data }) => this.latestLiveSessions = data.slice(0, 5)) | |
58 | } | |
59 | } |