]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-watch/modal/video-share.component.ts
Lazy load all routes
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / modal / video-share.component.ts
CommitLineData
63347a0f 1import { Component, ElementRef, Input, ViewChild } from '@angular/core'
11b8762f 2import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
2bc9bd08 3import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
2f4c784a 4import { VideoCaption } from '@shared/models'
67ed6552
C
5import { VideoDetails } from '@app/shared/shared-main'
6import { VideoPlaylist } from '@app/shared/shared-video-playlist'
2f4c784a
C
7
8type 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})
31export 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
45c6bcf3 38 activeId: 'url' | 'qrcode' | 'embed' = 'url'
2f4c784a
C
39 customizations: Customizations
40 isAdvancedCustomizationCollapsed = true
3a1fed11 41 includeVideoInPlaylist = false
2f4c784a 42
3a1fed11 43 constructor (private modalService: NgbModal) { }
cf02fbfb 44
11b8762f 45 show (currentVideoTimestamp?: number) {
2f4c784a
C
46 let subtitle: string
47 if (this.videoCaptions.length !== 0) {
48 subtitle = this.videoCaptions[0].language.id
49 }
50
51 this.customizations = {
52 startAtCheckbox: false,
53 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
54
55 stopAtCheckbox: false,
56 stopAt: this.video.duration,
57
58 subtitleCheckbox: false,
59 subtitle,
60
61 loop: false,
62 autoplay: false,
63 muted: false,
64
65 // Embed options
66 title: true,
67 warningTitle: true,
68 controls: true
69 }
11b8762f 70
24e7916c 71 this.modalService.open(this.modal, { centered: true })
cf02fbfb
C
72 }
73
df98563e 74 getVideoIframeCode () {
2f4c784a 75 const options = this.getOptions(this.video.embedUrl)
11b8762f 76
2f4c784a 77 const embedUrl = buildVideoLink(options)
11b8762f 78 return buildVideoEmbed(embedUrl)
cf02fbfb
C
79 }
80
df98563e 81 getVideoUrl () {
3a1fed11
C
82 const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid
83 const options = this.getOptions(baseUrl)
2f4c784a
C
84
85 return buildVideoLink(options)
cf02fbfb 86 }
2c8d4697 87
3a1fed11
C
88 getPlaylistUrl () {
89 const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid
90
91 if (!this.includeVideoInPlaylist) return base
92
03aff3c6 93 return base + '?videoId=' + this.video.uuid
2c8d4697 94 }
c7e1e432 95
3a1fed11
C
96 notSecure () {
97 return window.location.protocol === 'http:'
c7e1e432 98 }
11b8762f 99
2f4c784a
C
100 isInEmbedTab () {
101 return this.activeId === 'embed'
102 }
103
3a1fed11
C
104 hasPlaylist () {
105 return !!this.playlist
106 }
107
2f4c784a
C
108 private getOptions (baseUrl?: string) {
109 return {
110 baseUrl,
111
112 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
113 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
114
115 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
116
117 loop: this.customizations.loop,
118 autoplay: this.customizations.autoplay,
119 muted: this.customizations.muted,
11b8762f 120
2f4c784a
C
121 title: this.customizations.title,
122 warningTitle: this.customizations.warningTitle,
123 controls: this.customizations.controls
124 }
11b8762f 125 }
cf02fbfb 126}