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 } from '@ng-bootstrap/ng-bootstrap'
7 import { durationToString } from '@app/shared/misc/utils'
10 selector: 'my-video-share',
11 templateUrl: './video-share.component.html',
12 styleUrls: [ './video-share.component.scss' ]
14 export class VideoShareComponent {
15 @ViewChild('modal') modal: ElementRef
17 @Input() video: VideoDetails = null
19 currentVideoTimestamp: number
20 startAtCheckbox = false
23 private modalService: NgbModal,
24 private notifier: Notifier,
28 show (currentVideoTimestamp?: number) {
29 this.currentVideoTimestamp = currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0
31 this.modalService.open(this.modal)
34 getVideoIframeCode () {
35 const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
37 return buildVideoEmbed(embedUrl)
41 return buildVideoLink(this.getVideoTimestampIfEnabled())
45 return window.location.protocol === 'http:'
48 activateCopiedMessage () {
49 this.notifier.success(this.i18n('Copied'))
52 private getVideoTimestampIfEnabled () {
53 if (this.startAtCheckbox === true) return this.currentVideoTimestamp