]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/+video-watch/modal/video-share.component.ts
6565d7f887fc9c556c920efbc46a775b522bf152
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / modal / video-share.component.ts
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'
8
9 @Component({
10 selector: 'my-video-share',
11 templateUrl: './video-share.component.html',
12 styleUrls: [ './video-share.component.scss' ]
13 })
14 export class VideoShareComponent {
15 @ViewChild('modal') modal: ElementRef
16
17 @Input() video: VideoDetails = null
18
19 currentVideoTimestamp: number
20 startAtCheckbox = false
21
22 constructor (
23 private modalService: NgbModal,
24 private notifier: Notifier,
25 private i18n: I18n
26 ) { }
27
28 show (currentVideoTimestamp?: number) {
29 this.currentVideoTimestamp = currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0
30
31 this.modalService.open(this.modal)
32 }
33
34 getVideoIframeCode () {
35 const embedUrl = buildVideoLink(this.getVideoTimestampIfEnabled(), this.video.embedUrl)
36
37 return buildVideoEmbed(embedUrl)
38 }
39
40 getVideoUrl () {
41 return buildVideoLink(this.getVideoTimestampIfEnabled())
42 }
43
44 notSecure () {
45 return window.location.protocol === 'http:'
46 }
47
48 activateCopiedMessage () {
49 this.notifier.success(this.i18n('Copied'))
50 }
51
52 private getVideoTimestampIfEnabled () {
53 if (this.startAtCheckbox === true) return this.currentVideoTimestamp
54
55 return undefined
56 }
57 }