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