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