]>
Commit | Line | Data |
---|---|---|
63347a0f | 1 | import { Component, ElementRef, Input, ViewChild } from '@angular/core' |
f1c86172 | 2 | import { DomSanitizer, SafeHtml } from '@angular/platform-browser' |
de615445 | 3 | import { HooksService, ServerService } from '@app/core' |
9162fdd3 | 4 | import { VideoDetails } from '@app/shared/shared-main' |
67ed6552 | 5 | import { VideoPlaylist } from '@app/shared/shared-video-playlist' |
82f443de | 6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
57d65032 | 7 | import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' |
15a7eafb | 8 | import { buildPlaylistLink, buildVideoLink, decoratePlaylistLink, decorateVideoLink } from '@shared/core-utils' |
38225867 | 9 | import { VideoCaption, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' |
2f4c784a C |
10 | |
11 | type Customizations = { | |
12 | startAtCheckbox: boolean | |
13 | startAt: number | |
14 | ||
15 | stopAtCheckbox: boolean | |
16 | stopAt: number | |
17 | ||
18 | subtitleCheckbox: boolean | |
19 | subtitle: string | |
20 | ||
21 | loop: boolean | |
dd1e2f2f | 22 | originUrl: boolean |
2f4c784a C |
23 | autoplay: boolean |
24 | muted: boolean | |
85302118 C |
25 | |
26 | embedP2P: boolean | |
a871d2a2 | 27 | onlyEmbedUrl: boolean |
2f4c784a C |
28 | title: boolean |
29 | warningTitle: boolean | |
60f013e1 | 30 | controlBar: boolean |
189ab8de | 31 | peertubeLink: boolean |
de615445 C |
32 | |
33 | includeVideoInPlaylist: boolean | |
2f4c784a | 34 | } |
cf02fbfb | 35 | |
951b582f C |
36 | type TabId = 'url' | 'qrcode' | 'embed' |
37 | ||
cf02fbfb C |
38 | @Component({ |
39 | selector: 'my-video-share', | |
c7e1e432 JL |
40 | templateUrl: './video-share.component.html', |
41 | styleUrls: [ './video-share.component.scss' ] | |
cf02fbfb C |
42 | }) |
43 | export class VideoShareComponent { | |
f36da21e | 44 | @ViewChild('modal', { static: true }) modal: ElementRef |
11b8762f | 45 | |
404b54e1 | 46 | @Input() video: VideoDetails = null |
2f4c784a | 47 | @Input() videoCaptions: VideoCaption[] = [] |
3a1fed11 | 48 | @Input() playlist: VideoPlaylist = null |
d142c7b9 | 49 | @Input() playlistPosition: number = null |
cf02fbfb | 50 | |
951b582f C |
51 | activeVideoId: TabId = 'url' |
52 | activePlaylistId: TabId = 'url' | |
53 | ||
2f4c784a C |
54 | customizations: Customizations |
55 | isAdvancedCustomizationCollapsed = true | |
56 | ||
de615445 C |
57 | videoUrl: string |
58 | playlistUrl: string | |
59 | ||
60 | videoEmbedUrl: string | |
61 | playlistEmbedUrl: string | |
62 | ||
63 | videoEmbedHTML: string | |
64 | videoEmbedSafeHTML: SafeHtml | |
65 | playlistEmbedHTML: string | |
66 | playlistEmbedSafeHTML: SafeHtml | |
f1c86172 C |
67 | |
68 | constructor ( | |
69 | private modalService: NgbModal, | |
85302118 | 70 | private sanitizer: DomSanitizer, |
de615445 C |
71 | private server: ServerService, |
72 | private hooks: HooksService | |
f1c86172 | 73 | ) { } |
cf02fbfb | 74 | |
951b582f | 75 | show (currentVideoTimestamp?: number, currentPlaylistPosition?: number) { |
2f4c784a | 76 | let subtitle: string |
82f443de | 77 | if (this.videoCaptions && this.videoCaptions.length !== 0) { |
2f4c784a C |
78 | subtitle = this.videoCaptions[0].language.id |
79 | } | |
80 | ||
f1c86172 | 81 | this.customizations = new Proxy({ |
2f4c784a C |
82 | startAtCheckbox: false, |
83 | startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0, | |
84 | ||
85 | stopAtCheckbox: false, | |
82f443de | 86 | stopAt: this.video?.duration, |
2f4c784a C |
87 | |
88 | subtitleCheckbox: false, | |
89 | subtitle, | |
90 | ||
91 | loop: false, | |
dd1e2f2f | 92 | originUrl: false, |
2f4c784a C |
93 | autoplay: false, |
94 | muted: false, | |
95 | ||
96 | // Embed options | |
a871d2a2 C |
97 | embedP2P: this.server.getHTMLConfig().defaults.p2p.embed.enabled, |
98 | onlyEmbedUrl: false, | |
2f4c784a C |
99 | title: true, |
100 | warningTitle: true, | |
60f013e1 | 101 | controlBar: true, |
de615445 C |
102 | peertubeLink: true, |
103 | ||
104 | includeVideoInPlaylist: false | |
f1c86172 C |
105 | }, { |
106 | set: (target, prop, value) => { | |
107 | target[prop] = value | |
108 | ||
85302118 C |
109 | if (prop === 'embedP2P') { |
110 | // Auto enabled warning title if P2P is enabled | |
111 | this.customizations.warningTitle = value | |
112 | } | |
113 | ||
de615445 | 114 | this.onUpdate() |
f1c86172 C |
115 | |
116 | return true | |
117 | } | |
118 | }) | |
11b8762f | 119 | |
951b582f C |
120 | this.playlistPosition = currentPlaylistPosition |
121 | ||
de615445 | 122 | this.onUpdate() |
11b8762f | 123 | |
de615445 C |
124 | this.modalService.open(this.modal, { centered: true }).shown.subscribe(() => { |
125 | this.hooks.runAction('action:modal.share.shown', 'video-watch', { video: this.video, playlist: this.playlist }) | |
126 | }) | |
a871d2a2 | 127 | } |
951b582f | 128 | |
de615445 | 129 | // --------------------------------------------------------------------------- |
cf02fbfb | 130 | |
df98563e | 131 | getVideoUrl () { |
ab4001aa C |
132 | const url = this.customizations.originUrl |
133 | ? this.video.url | |
134 | : buildVideoLink(this.video, window.location.origin) | |
d4a8e7a6 | 135 | |
de615445 C |
136 | return this.hooks.wrapFun( |
137 | decorateVideoLink, | |
138 | { url, ...this.getVideoOptions(false) }, | |
139 | 'video-watch', | |
140 | 'filter:share.video-url.build.params', | |
141 | 'filter:share.video-url.build.result' | |
142 | ) | |
143 | } | |
2f4c784a | 144 | |
de615445 C |
145 | getVideoEmbedUrl () { |
146 | return this.hooks.wrapFun( | |
147 | decorateVideoLink, | |
148 | { url: this.video.embedUrl, ...this.getVideoOptions(true) }, | |
149 | 'video-watch', | |
150 | 'filter:share.video-embed-url.build.params', | |
151 | 'filter:share.video-embed-url.build.result' | |
152 | ) | |
153 | } | |
154 | ||
155 | async getVideoIframeCode () { | |
156 | return this.hooks.wrapFun( | |
157 | buildVideoOrPlaylistEmbed, | |
158 | { embedUrl: await this.getVideoEmbedUrl(), embedTitle: this.video.name }, | |
159 | 'video-watch', | |
160 | 'filter:share.video-embed-code.build.params', | |
161 | 'filter:share.video-embed-code.build.result' | |
162 | ) | |
cf02fbfb | 163 | } |
2c8d4697 | 164 | |
de615445 C |
165 | // --------------------------------------------------------------------------- |
166 | ||
3a1fed11 | 167 | getPlaylistUrl () { |
9162fdd3 | 168 | const url = buildPlaylistLink(this.playlist) |
3a1fed11 | 169 | |
de615445 C |
170 | return this.hooks.wrapFun( |
171 | decoratePlaylistLink, | |
172 | { url, ...this.getPlaylistOptions() }, | |
173 | 'video-watch', | |
174 | 'filter:share.video-playlist-url.build.params', | |
175 | 'filter:share.video-playlist-url.build.result' | |
176 | ) | |
177 | } | |
178 | ||
179 | getPlaylistEmbedUrl () { | |
180 | return this.hooks.wrapFun( | |
181 | decoratePlaylistLink, | |
182 | { url: this.playlist.embedUrl, ...this.getPlaylistOptions() }, | |
183 | 'video-watch', | |
184 | 'filter:share.video-playlist-embed-url.build.params', | |
185 | 'filter:share.video-playlist-embed-url.build.result' | |
186 | ) | |
187 | } | |
188 | ||
189 | async getPlaylistEmbedCode () { | |
190 | return this.hooks.wrapFun( | |
191 | buildVideoOrPlaylistEmbed, | |
192 | { embedUrl: await this.getPlaylistEmbedUrl(), embedTitle: this.playlist.displayName }, | |
193 | 'video-watch', | |
194 | 'filter:share.video-playlist-embed-code.build.params', | |
195 | 'filter:share.video-playlist-embed-code.build.result' | |
196 | ) | |
2c8d4697 | 197 | } |
c7e1e432 | 198 | |
de615445 C |
199 | // --------------------------------------------------------------------------- |
200 | ||
201 | async onUpdate () { | |
202 | console.log('on update') | |
f1c86172 | 203 | |
de615445 C |
204 | if (this.playlist) { |
205 | this.playlistUrl = await this.getPlaylistUrl() | |
206 | this.playlistEmbedUrl = await this.getPlaylistEmbedUrl() | |
207 | this.playlistEmbedHTML = await this.getPlaylistEmbedCode() | |
208 | this.playlistEmbedSafeHTML = this.sanitizer.bypassSecurityTrustHtml(this.playlistEmbedHTML) | |
209 | } | |
210 | ||
211 | if (this.video) { | |
212 | this.videoUrl = await this.getVideoUrl() | |
213 | this.videoEmbedUrl = await this.getVideoEmbedUrl() | |
214 | this.videoEmbedHTML = await this.getVideoIframeCode() | |
215 | this.videoEmbedSafeHTML = this.sanitizer.bypassSecurityTrustHtml(this.videoEmbedHTML) | |
216 | } | |
f1c86172 C |
217 | } |
218 | ||
3a1fed11 C |
219 | notSecure () { |
220 | return window.location.protocol === 'http:' | |
c7e1e432 | 221 | } |
11b8762f | 222 | |
a871d2a2 | 223 | isInVideoEmbedTab () { |
951b582f | 224 | return this.activeVideoId === 'embed' |
2f4c784a C |
225 | } |
226 | ||
a871d2a2 C |
227 | isInPlaylistEmbedTab () { |
228 | return this.activePlaylistId === 'embed' | |
229 | } | |
230 | ||
dd1e2f2f J |
231 | isLocalVideo () { |
232 | return this.video.isLocal | |
233 | } | |
234 | ||
38225867 NR |
235 | isPrivateVideo () { |
236 | return this.video.privacy.id === VideoPrivacy.PRIVATE | |
237 | } | |
238 | ||
239 | isPrivatePlaylist () { | |
240 | return this.playlist.privacy.id === VideoPlaylistPrivacy.PRIVATE | |
241 | } | |
242 | ||
951b582f C |
243 | private getPlaylistOptions (baseUrl?: string) { |
244 | return { | |
245 | baseUrl, | |
246 | ||
de615445 C |
247 | playlistPosition: this.playlistPosition && this.customizations.includeVideoInPlaylist |
248 | ? this.playlistPosition | |
249 | : undefined | |
951b582f C |
250 | } |
251 | } | |
252 | ||
85302118 C |
253 | private getVideoOptions (forEmbed: boolean) { |
254 | const embedOptions = forEmbed | |
255 | ? { | |
256 | title: this.customizations.title, | |
257 | warningTitle: this.customizations.warningTitle, | |
60f013e1 | 258 | controlBar: this.customizations.controlBar, |
85302118 C |
259 | peertubeLink: this.customizations.peertubeLink, |
260 | ||
261 | // If using default value, we don't need to specify it | |
262 | p2p: this.customizations.embedP2P === this.server.getHTMLConfig().defaults.p2p.embed.enabled | |
263 | ? undefined | |
264 | : this.customizations.embedP2P | |
265 | } | |
266 | : {} | |
267 | ||
2f4c784a | 268 | return { |
2f4c784a C |
269 | startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined, |
270 | stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined, | |
271 | ||
272 | subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined, | |
273 | ||
274 | loop: this.customizations.loop, | |
275 | autoplay: this.customizations.autoplay, | |
276 | muted: this.customizations.muted, | |
11b8762f | 277 | |
85302118 | 278 | ...embedOptions |
2f4c784a | 279 | } |
11b8762f | 280 | } |
cf02fbfb | 281 | } |