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
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 constructor (private modalService: NgbModal) { }
45 show (currentVideoTimestamp?: number) {
47 if (this.videoCaptions.length !== 0) {
48 subtitle = this.videoCaptions[0].language.id
51 this.customizations = {
52 startAtCheckbox: false,
53 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
55 stopAtCheckbox: false,
56 stopAt: this.video.duration,
58 subtitleCheckbox: false,
71 this.modalService.open(this.modal, { centered: true })
74 getVideoIframeCode () {
75 const options = this.getOptions(this.video.embedUrl)
77 const embedUrl = buildVideoLink(options)
78 return buildVideoEmbed(embedUrl)
82 const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid
83 const options = this.getOptions(baseUrl)
85 return buildVideoLink(options)
89 const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid
91 if (!this.includeVideoInPlaylist) return base
93 return base + '?videoId=' + this.video.uuid
97 return window.location.protocol === 'http:'
101 return this.activeId === 'embed'
105 return !!this.playlist
108 private getOptions (baseUrl?: string) {
112 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
113 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
115 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
117 loop: this.customizations.loop,
118 autoplay: this.customizations.autoplay,
119 muted: this.customizations.muted,
121 title: this.customizations.title,
122 warningTitle: this.customizations.warningTitle,
123 controls: this.customizations.controls