]>
Commit | Line | Data |
---|---|---|
63347a0f | 1 | import { Component, ElementRef, Input, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier } from '@app/core' |
4635f59d | 3 | import { VideoDetails } from '../../../shared/video/video-details.model' |
11b8762f | 4 | import { buildVideoEmbed, buildVideoLink } from '../../../../assets/player/utils' |
b1d40cff | 5 | import { I18n } from '@ngx-translate/i18n-polyfill' |
2f4c784a C |
6 | import { NgbModal, NgbTabChangeEvent } from '@ng-bootstrap/ng-bootstrap' |
7 | import { VideoCaption } from '@shared/models' | |
8 | ||
9 | type Customizations = { | |
10 | startAtCheckbox: boolean | |
11 | startAt: number | |
12 | ||
13 | stopAtCheckbox: boolean | |
14 | stopAt: number | |
15 | ||
16 | subtitleCheckbox: boolean | |
17 | subtitle: string | |
18 | ||
19 | loop: boolean | |
20 | autoplay: boolean | |
21 | muted: boolean | |
22 | title: boolean | |
23 | warningTitle: boolean | |
24 | controls: boolean | |
25 | } | |
cf02fbfb C |
26 | |
27 | @Component({ | |
28 | selector: 'my-video-share', | |
c7e1e432 JL |
29 | templateUrl: './video-share.component.html', |
30 | styleUrls: [ './video-share.component.scss' ] | |
cf02fbfb C |
31 | }) |
32 | export class VideoShareComponent { | |
11b8762f C |
33 | @ViewChild('modal') modal: ElementRef |
34 | ||
404b54e1 | 35 | @Input() video: VideoDetails = null |
2f4c784a | 36 | @Input() videoCaptions: VideoCaption[] = [] |
cf02fbfb | 37 | |
2f4c784a C |
38 | activeId: 'url' | 'qrcode' | 'embed' |
39 | customizations: Customizations | |
40 | isAdvancedCustomizationCollapsed = true | |
41 | ||
42 | private currentVideoTimestamp: number | |
cf02fbfb | 43 | |
b1d40cff | 44 | constructor ( |
63347a0f | 45 | private modalService: NgbModal, |
f8b2c1b4 | 46 | private notifier: Notifier, |
b1d40cff | 47 | private i18n: I18n |
23db998f | 48 | ) { } |
cf02fbfb | 49 | |
11b8762f | 50 | show (currentVideoTimestamp?: number) { |
2f4c784a C |
51 | this.currentVideoTimestamp = currentVideoTimestamp |
52 | ||
53 | let subtitle: string | |
54 | if (this.videoCaptions.length !== 0) { | |
55 | subtitle = this.videoCaptions[0].language.id | |
56 | } | |
57 | ||
58 | this.customizations = { | |
59 | startAtCheckbox: false, | |
60 | startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0, | |
61 | ||
62 | stopAtCheckbox: false, | |
63 | stopAt: this.video.duration, | |
64 | ||
65 | subtitleCheckbox: false, | |
66 | subtitle, | |
67 | ||
68 | loop: false, | |
69 | autoplay: false, | |
70 | muted: false, | |
71 | ||
72 | // Embed options | |
73 | title: true, | |
74 | warningTitle: true, | |
75 | controls: true | |
76 | } | |
11b8762f | 77 | |
63347a0f | 78 | this.modalService.open(this.modal) |
cf02fbfb C |
79 | } |
80 | ||
df98563e | 81 | getVideoIframeCode () { |
2f4c784a | 82 | const options = this.getOptions(this.video.embedUrl) |
11b8762f | 83 | |
2f4c784a | 84 | const embedUrl = buildVideoLink(options) |
11b8762f | 85 | return buildVideoEmbed(embedUrl) |
cf02fbfb C |
86 | } |
87 | ||
df98563e | 88 | getVideoUrl () { |
2f4c784a C |
89 | const options = this.getOptions() |
90 | ||
91 | return buildVideoLink(options) | |
cf02fbfb | 92 | } |
2c8d4697 | 93 | |
df98563e C |
94 | notSecure () { |
95 | return window.location.protocol === 'http:' | |
2c8d4697 | 96 | } |
c7e1e432 JL |
97 | |
98 | activateCopiedMessage () { | |
f8b2c1b4 | 99 | this.notifier.success(this.i18n('Copied')) |
c7e1e432 | 100 | } |
11b8762f | 101 | |
2f4c784a C |
102 | onTabChange (event: NgbTabChangeEvent) { |
103 | this.activeId = event.nextId as any | |
104 | } | |
105 | ||
106 | isInEmbedTab () { | |
107 | return this.activeId === 'embed' | |
108 | } | |
109 | ||
110 | private getOptions (baseUrl?: string) { | |
111 | return { | |
112 | baseUrl, | |
113 | ||
114 | startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined, | |
115 | stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined, | |
116 | ||
117 | subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined, | |
118 | ||
119 | loop: this.customizations.loop, | |
120 | autoplay: this.customizations.autoplay, | |
121 | muted: this.customizations.muted, | |
11b8762f | 122 | |
2f4c784a C |
123 | title: this.customizations.title, |
124 | warningTitle: this.customizations.warningTitle, | |
125 | controls: this.customizations.controls | |
126 | } | |
11b8762f | 127 | } |
cf02fbfb | 128 | } |