1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
3 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
4 import { VideoCaption } from '@shared/models'
5 import { VideoDetails } from '@app/shared/shared-main'
6 import { VideoPlaylist } from '@app/shared/shared-video-playlist'
8 type Customizations = {
9 startAtCheckbox: boolean
12 stopAtCheckbox: boolean
15 subtitleCheckbox: boolean
28 selector: 'my-video-share',
29 templateUrl: './video-share.component.html',
30 styleUrls: [ './video-share.component.scss' ]
32 export class VideoShareComponent {
33 @ViewChild('modal', { static: true }) modal: ElementRef
35 @Input() video: VideoDetails = null
36 @Input() videoCaptions: VideoCaption[] = []
37 @Input() playlist: VideoPlaylist = null
39 activeId: 'url' | 'qrcode' | 'embed' = 'url'
40 customizations: Customizations
41 isAdvancedCustomizationCollapsed = true
42 includeVideoInPlaylist = false
44 constructor (private modalService: NgbModal) { }
46 show (currentVideoTimestamp?: number) {
48 if (this.videoCaptions.length !== 0) {
49 subtitle = this.videoCaptions[0].language.id
52 this.customizations = {
53 startAtCheckbox: false,
54 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
56 stopAtCheckbox: false,
57 stopAt: this.video.duration,
59 subtitleCheckbox: false,
73 this.modalService.open(this.modal, { centered: true })
76 getVideoIframeCode () {
77 const options = this.getOptions(this.video.embedUrl)
79 const embedUrl = buildVideoLink(options)
80 return buildVideoEmbed(embedUrl)
84 const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid
85 const options = this.getOptions(baseUrl)
87 return buildVideoLink(options)
91 const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid
93 if (!this.includeVideoInPlaylist) return base
95 return base + '?videoId=' + this.video.uuid
99 return window.location.protocol === 'http:'
103 return this.activeId === 'embed'
107 return !!this.playlist
110 private getOptions (baseUrl?: string) {
114 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
115 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
117 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
119 loop: this.customizations.loop,
120 autoplay: this.customizations.autoplay,
121 muted: this.customizations.muted,
123 title: this.customizations.title,
124 warningTitle: this.customizations.warningTitle,
125 controls: this.customizations.controls,
126 peertubeLink: this.customizations.peertubeLink