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