1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { buildVideoOrPlaylistEmbed, buildVideoLink, buildPlaylistLink } 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 type TabId = 'url' | 'qrcode' | 'embed'
30 selector: 'my-video-share',
31 templateUrl: './video-share.component.html',
32 styleUrls: [ './video-share.component.scss' ]
34 export class VideoShareComponent {
35 @ViewChild('modal', { static: true }) modal: ElementRef
37 @Input() video: VideoDetails = null
38 @Input() videoCaptions: VideoCaption[] = []
39 @Input() playlist: VideoPlaylist = null
41 activeVideoId: TabId = 'url'
42 activePlaylistId: TabId = 'url'
44 customizations: Customizations
45 isAdvancedCustomizationCollapsed = true
46 includeVideoInPlaylist = false
48 private playlistPosition: number = null
50 constructor (private modalService: NgbModal) { }
52 show (currentVideoTimestamp?: number, currentPlaylistPosition?: number) {
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,
79 this.playlistPosition = currentPlaylistPosition
81 this.modalService.open(this.modal, { centered: true })
84 getVideoIframeCode () {
85 const options = this.getVideoOptions(this.video.embedUrl)
87 const embedUrl = buildVideoLink(options)
88 return buildVideoOrPlaylistEmbed(embedUrl)
91 getPlaylistIframeCode () {
92 const options = this.getPlaylistOptions(this.playlist.embedUrl)
94 const embedUrl = buildPlaylistLink(options)
95 return buildVideoOrPlaylistEmbed(embedUrl)
99 const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid
100 const options = this.getVideoOptions(baseUrl)
102 return buildVideoLink(options)
106 const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid
108 if (!this.includeVideoInPlaylist) return base
110 return base + '?videoId=' + this.video.uuid
114 return window.location.protocol === 'http:'
117 isVideoInEmbedTab () {
118 return this.activeVideoId === 'embed'
122 return !!this.playlist
125 private getPlaylistOptions (baseUrl?: string) {
129 playlistPosition: this.playlistPosition || undefined
133 private getVideoOptions (baseUrl?: string) {
137 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
138 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
140 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
142 loop: this.customizations.loop,
143 autoplay: this.customizations.autoplay,
144 muted: this.customizations.muted,
146 title: this.customizations.title,
147 warningTitle: this.customizations.warningTitle,
148 controls: this.customizations.controls,
149 peertubeLink: this.customizations.peertubeLink