1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { VideoDetails } from '../../../shared/video/video-details.model'
3 import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
4 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5 import { VideoCaption } from '@shared/models'
6 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
8 type Customizations = {
9 startAtCheckbox: boolean
12 stopAtCheckbox: boolean
15 subtitleCheckbox: boolean
27 selector: 'my-video-share',
28 templateUrl: './video-share.component.html',
29 styleUrls: [ './video-share.component.scss' ]
31 export class VideoShareComponent {
32 @ViewChild('modal', { static: true }) modal: ElementRef
34 @Input() video: VideoDetails = null
35 @Input() videoCaptions: VideoCaption[] = []
36 @Input() playlist: VideoPlaylist = null
38 activeId: 'url' | 'qrcode' | 'embed' = 'url'
39 customizations: Customizations
40 isAdvancedCustomizationCollapsed = true
41 includeVideoInPlaylist = false
43 private currentVideoTimestamp: number
45 constructor (private modalService: NgbModal) { }
47 show (currentVideoTimestamp?: number) {
48 this.currentVideoTimestamp = currentVideoTimestamp
51 if (this.videoCaptions.length !== 0) {
52 subtitle = this.videoCaptions[0].language.id
55 this.customizations = {
56 startAtCheckbox: false,
57 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
59 stopAtCheckbox: false,
60 stopAt: this.video.duration,
62 subtitleCheckbox: false,
75 this.modalService.open(this.modal, { centered: true })
78 getVideoIframeCode () {
79 const options = this.getOptions(this.video.embedUrl)
81 const embedUrl = buildVideoLink(options)
82 return buildVideoEmbed(embedUrl)
86 const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid
87 const options = this.getOptions(baseUrl)
89 return buildVideoLink(options)
93 const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid
95 if (!this.includeVideoInPlaylist) return base
97 return base + '?videoId=' + this.video.uuid
101 return window.location.protocol === 'http:'
105 return this.activeId === 'embed'
109 return !!this.playlist
112 private getOptions (baseUrl?: string) {
116 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
117 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
119 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
121 loop: this.customizations.loop,
122 autoplay: this.customizations.autoplay,
123 muted: this.customizations.muted,
125 title: this.customizations.title,
126 warningTitle: this.customizations.warningTitle,
127 controls: this.customizations.controls