]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-share-modal/video-share.component.ts
Merge branch 'release/4.2.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-share-modal / video-share.component.ts
CommitLineData
63347a0f 1import { Component, ElementRef, Input, ViewChild } from '@angular/core'
f1c86172 2import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
85302118 3import { ServerService } from '@app/core'
9162fdd3 4import { VideoDetails } from '@app/shared/shared-main'
67ed6552 5import { VideoPlaylist } from '@app/shared/shared-video-playlist'
82f443de 6import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
57d65032 7import { buildVideoOrPlaylistEmbed } from '@root-helpers/video'
15a7eafb 8import { buildPlaylistLink, buildVideoLink, decoratePlaylistLink, decorateVideoLink } from '@shared/core-utils'
38225867 9import { VideoCaption, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models'
2f4c784a
C
10
11type 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
2f4c784a 32}
cf02fbfb 33
951b582f
C
34type TabId = 'url' | 'qrcode' | 'embed'
35
cf02fbfb
C
36@Component({
37 selector: 'my-video-share',
c7e1e432
JL
38 templateUrl: './video-share.component.html',
39 styleUrls: [ './video-share.component.scss' ]
cf02fbfb
C
40})
41export class VideoShareComponent {
f36da21e 42 @ViewChild('modal', { static: true }) modal: ElementRef
11b8762f 43
404b54e1 44 @Input() video: VideoDetails = null
2f4c784a 45 @Input() videoCaptions: VideoCaption[] = []
3a1fed11 46 @Input() playlist: VideoPlaylist = null
d142c7b9 47 @Input() playlistPosition: number = null
cf02fbfb 48
951b582f
C
49 activeVideoId: TabId = 'url'
50 activePlaylistId: TabId = 'url'
51
2f4c784a
C
52 customizations: Customizations
53 isAdvancedCustomizationCollapsed = true
3a1fed11 54 includeVideoInPlaylist = false
2f4c784a 55
f1c86172
C
56 playlistEmbedHTML: SafeHtml
57 videoEmbedHTML: SafeHtml
58
59 constructor (
60 private modalService: NgbModal,
85302118
C
61 private sanitizer: DomSanitizer,
62 private server: ServerService
f1c86172 63 ) { }
cf02fbfb 64
951b582f 65 show (currentVideoTimestamp?: number, currentPlaylistPosition?: number) {
2f4c784a 66 let subtitle: string
82f443de 67 if (this.videoCaptions && this.videoCaptions.length !== 0) {
2f4c784a
C
68 subtitle = this.videoCaptions[0].language.id
69 }
70
f1c86172 71 this.customizations = new Proxy({
2f4c784a
C
72 startAtCheckbox: false,
73 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
74
75 stopAtCheckbox: false,
82f443de 76 stopAt: this.video?.duration,
2f4c784a
C
77
78 subtitleCheckbox: false,
79 subtitle,
80
81 loop: false,
dd1e2f2f 82 originUrl: false,
2f4c784a
C
83 autoplay: false,
84 muted: false,
85
86 // Embed options
a871d2a2
C
87 embedP2P: this.server.getHTMLConfig().defaults.p2p.embed.enabled,
88 onlyEmbedUrl: false,
2f4c784a
C
89 title: true,
90 warningTitle: true,
60f013e1 91 controlBar: true,
189ab8de 92 peertubeLink: true
f1c86172
C
93 }, {
94 set: (target, prop, value) => {
95 target[prop] = value
96
85302118
C
97 if (prop === 'embedP2P') {
98 // Auto enabled warning title if P2P is enabled
99 this.customizations.warningTitle = value
100 }
101
f1c86172
C
102 this.updateEmbedCode()
103
104 return true
105 }
106 })
11b8762f 107
951b582f
C
108 this.playlistPosition = currentPlaylistPosition
109
f1c86172
C
110 this.updateEmbedCode()
111
24e7916c 112 this.modalService.open(this.modal, { centered: true })
cf02fbfb
C
113 }
114
df98563e 115 getVideoIframeCode () {
a871d2a2
C
116 return buildVideoOrPlaylistEmbed(this.getVideoEmbedUrl(), this.video.name)
117 }
11b8762f 118
a871d2a2
C
119 getVideoEmbedUrl () {
120 return decorateVideoLink({ url: this.video.embedUrl, ...this.getVideoOptions(true) })
951b582f
C
121 }
122
a871d2a2
C
123 getPlaylistEmbedUrl () {
124 return decoratePlaylistLink({ url: this.playlist.embedUrl, ...this.getPlaylistOptions() })
125 }
951b582f 126
a871d2a2
C
127 getPlaylistIframeCode () {
128 return buildVideoOrPlaylistEmbed(this.getPlaylistEmbedUrl(), this.playlist.displayName)
cf02fbfb
C
129 }
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
9162fdd3 136 return decorateVideoLink({
ab4001aa 137 url,
2f4c784a 138
85302118 139 ...this.getVideoOptions(false)
9162fdd3 140 })
cf02fbfb 141 }
2c8d4697 142
3a1fed11 143 getPlaylistUrl () {
9162fdd3
C
144 const url = buildPlaylistLink(this.playlist)
145 if (!this.includeVideoInPlaylist) return url
3a1fed11 146
9162fdd3 147 return decoratePlaylistLink({ url, playlistPosition: this.playlistPosition })
2c8d4697 148 }
c7e1e432 149
f1c86172
C
150 updateEmbedCode () {
151 if (this.playlist) this.playlistEmbedHTML = this.sanitizer.bypassSecurityTrustHtml(this.getPlaylistIframeCode())
152
153 if (this.video) this.videoEmbedHTML = this.sanitizer.bypassSecurityTrustHtml(this.getVideoIframeCode())
154 }
155
3a1fed11
C
156 notSecure () {
157 return window.location.protocol === 'http:'
c7e1e432 158 }
11b8762f 159
a871d2a2 160 isInVideoEmbedTab () {
951b582f 161 return this.activeVideoId === 'embed'
2f4c784a
C
162 }
163
a871d2a2
C
164 isInPlaylistEmbedTab () {
165 return this.activePlaylistId === 'embed'
166 }
167
dd1e2f2f
J
168 isLocalVideo () {
169 return this.video.isLocal
170 }
171
38225867
NR
172 isPrivateVideo () {
173 return this.video.privacy.id === VideoPrivacy.PRIVATE
174 }
175
176 isPrivatePlaylist () {
177 return this.playlist.privacy.id === VideoPlaylistPrivacy.PRIVATE
178 }
179
951b582f
C
180 private getPlaylistOptions (baseUrl?: string) {
181 return {
182 baseUrl,
183
184 playlistPosition: this.playlistPosition || undefined
185 }
186 }
187
85302118
C
188 private getVideoOptions (forEmbed: boolean) {
189 const embedOptions = forEmbed
190 ? {
191 title: this.customizations.title,
192 warningTitle: this.customizations.warningTitle,
60f013e1 193 controlBar: this.customizations.controlBar,
85302118
C
194 peertubeLink: this.customizations.peertubeLink,
195
196 // If using default value, we don't need to specify it
197 p2p: this.customizations.embedP2P === this.server.getHTMLConfig().defaults.p2p.embed.enabled
198 ? undefined
199 : this.customizations.embedP2P
200 }
201 : {}
202
2f4c784a 203 return {
2f4c784a
C
204 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
205 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
206
207 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
208
209 loop: this.customizations.loop,
210 autoplay: this.customizations.autoplay,
211 muted: this.customizations.muted,
11b8762f 212
85302118 213 ...embedOptions
2f4c784a 214 }
11b8762f 215 }
cf02fbfb 216}