1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { VideoDetails } from '../../../shared/video/video-details.model'
4 import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { NgbModal, NgbTabChangeEvent } from '@ng-bootstrap/ng-bootstrap'
7 import { VideoCaption } from '@shared/models'
9 type Customizations = {
10 startAtCheckbox: boolean
13 stopAtCheckbox: boolean
16 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') modal: ElementRef
35 @Input() video: VideoDetails = null
36 @Input() videoCaptions: VideoCaption[] = []
38 activeId: 'url' | 'qrcode' | 'embed'
39 customizations: Customizations
40 isAdvancedCustomizationCollapsed = true
42 private currentVideoTimestamp: number
45 private modalService: NgbModal,
46 private notifier: Notifier,
50 show (currentVideoTimestamp?: number) {
51 this.currentVideoTimestamp = currentVideoTimestamp
54 if (this.videoCaptions.length !== 0) {
55 subtitle = this.videoCaptions[0].language.id
58 this.customizations = {
59 startAtCheckbox: false,
60 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
62 stopAtCheckbox: false,
63 stopAt: this.video.duration,
65 subtitleCheckbox: false,
78 this.modalService.open(this.modal)
81 getVideoIframeCode () {
82 const options = this.getOptions(this.video.embedUrl)
84 const embedUrl = buildVideoLink(options)
85 return buildVideoEmbed(embedUrl)
89 const options = this.getOptions()
91 return buildVideoLink(options)
95 return window.location.protocol === 'http:'
98 activateCopiedMessage () {
99 this.notifier.success(this.i18n('Copied'))
102 onTabChange (event: NgbTabChangeEvent) {
103 this.activeId = event.nextId as any
107 return this.activeId === 'embed'
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