]>
Commit | Line | Data |
---|---|---|
63347a0f | 1 | import { Component, ElementRef, Input, ViewChild } from '@angular/core' |
4635f59d | 2 | import { VideoDetails } from '../../../shared/video/video-details.model' |
11b8762f | 3 | import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils' |
2f4c784a C |
4 | import { NgbModal, NgbTabChangeEvent } from '@ng-bootstrap/ng-bootstrap' |
5 | import { VideoCaption } from '@shared/models' | |
3a1fed11 | 6 | import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' |
2f4c784a C |
7 | |
8 | type Customizations = { | |
9 | startAtCheckbox: boolean | |
10 | startAt: number | |
11 | ||
12 | stopAtCheckbox: boolean | |
13 | stopAt: number | |
14 | ||
15 | subtitleCheckbox: boolean | |
16 | subtitle: string | |
17 | ||
18 | loop: boolean | |
19 | autoplay: boolean | |
20 | muted: boolean | |
21 | title: boolean | |
22 | warningTitle: boolean | |
23 | controls: boolean | |
24 | } | |
cf02fbfb C |
25 | |
26 | @Component({ | |
27 | selector: 'my-video-share', | |
c7e1e432 JL |
28 | templateUrl: './video-share.component.html', |
29 | styleUrls: [ './video-share.component.scss' ] | |
cf02fbfb C |
30 | }) |
31 | export class VideoShareComponent { | |
f36da21e | 32 | @ViewChild('modal', { static: true }) modal: ElementRef |
11b8762f | 33 | |
404b54e1 | 34 | @Input() video: VideoDetails = null |
2f4c784a | 35 | @Input() videoCaptions: VideoCaption[] = [] |
3a1fed11 | 36 | @Input() playlist: VideoPlaylist = null |
cf02fbfb | 37 | |
2f4c784a C |
38 | activeId: 'url' | 'qrcode' | 'embed' |
39 | customizations: Customizations | |
40 | isAdvancedCustomizationCollapsed = true | |
3a1fed11 | 41 | includeVideoInPlaylist = false |
2f4c784a C |
42 | |
43 | private currentVideoTimestamp: number | |
cf02fbfb | 44 | |
3a1fed11 | 45 | constructor (private modalService: NgbModal) { } |
cf02fbfb | 46 | |
11b8762f | 47 | show (currentVideoTimestamp?: number) { |
2f4c784a C |
48 | this.currentVideoTimestamp = currentVideoTimestamp |
49 | ||
50 | let subtitle: string | |
51 | if (this.videoCaptions.length !== 0) { | |
52 | subtitle = this.videoCaptions[0].language.id | |
53 | } | |
54 | ||
55 | this.customizations = { | |
56 | startAtCheckbox: false, | |
57 | startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0, | |
58 | ||
59 | stopAtCheckbox: false, | |
60 | stopAt: this.video.duration, | |
61 | ||
62 | subtitleCheckbox: false, | |
63 | subtitle, | |
64 | ||
65 | loop: false, | |
66 | autoplay: false, | |
67 | muted: false, | |
68 | ||
69 | // Embed options | |
70 | title: true, | |
71 | warningTitle: true, | |
72 | controls: true | |
73 | } | |
11b8762f | 74 | |
24e7916c | 75 | this.modalService.open(this.modal, { centered: true }) |
cf02fbfb C |
76 | } |
77 | ||
df98563e | 78 | getVideoIframeCode () { |
2f4c784a | 79 | const options = this.getOptions(this.video.embedUrl) |
11b8762f | 80 | |
2f4c784a | 81 | const embedUrl = buildVideoLink(options) |
11b8762f | 82 | return buildVideoEmbed(embedUrl) |
cf02fbfb C |
83 | } |
84 | ||
df98563e | 85 | getVideoUrl () { |
3a1fed11 C |
86 | const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid |
87 | const options = this.getOptions(baseUrl) | |
2f4c784a C |
88 | |
89 | return buildVideoLink(options) | |
cf02fbfb | 90 | } |
2c8d4697 | 91 | |
3a1fed11 C |
92 | getPlaylistUrl () { |
93 | const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid | |
94 | ||
95 | if (!this.includeVideoInPlaylist) return base | |
96 | ||
03aff3c6 | 97 | return base + '?videoId=' + this.video.uuid |
2c8d4697 | 98 | } |
c7e1e432 | 99 | |
3a1fed11 C |
100 | notSecure () { |
101 | return window.location.protocol === 'http:' | |
c7e1e432 | 102 | } |
11b8762f | 103 | |
2f4c784a C |
104 | onTabChange (event: NgbTabChangeEvent) { |
105 | this.activeId = event.nextId as any | |
106 | } | |
107 | ||
108 | isInEmbedTab () { | |
109 | return this.activeId === 'embed' | |
110 | } | |
111 | ||
3a1fed11 C |
112 | hasPlaylist () { |
113 | return !!this.playlist | |
114 | } | |
115 | ||
2f4c784a C |
116 | private getOptions (baseUrl?: string) { |
117 | return { | |
118 | baseUrl, | |
119 | ||
120 | startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined, | |
121 | stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined, | |
122 | ||
123 | subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined, | |
124 | ||
125 | loop: this.customizations.loop, | |
126 | autoplay: this.customizations.autoplay, | |
127 | muted: this.customizations.muted, | |
11b8762f | 128 | |
2f4c784a C |
129 | title: this.customizations.title, |
130 | warningTitle: this.customizations.warningTitle, | |
131 | controls: this.customizations.controls | |
132 | } | |
11b8762f | 133 | } |
cf02fbfb | 134 | } |