1 import { Component, ElementRef, Input, ViewChild } from '@angular/core'
2 import { VideoDetails } from '@app/shared/shared-main'
3 import { VideoPlaylist } from '@app/shared/shared-video-playlist'
4 import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
5 import { VideoCaption } from '@shared/models'
6 import { buildPlaylistLink, buildVideoLink, buildVideoOrPlaylistEmbed } from '../../../assets/player/utils'
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 && 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'
121 private getPlaylistOptions (baseUrl?: string) {
125 playlistPosition: this.playlistPosition || undefined
129 private getVideoOptions (baseUrl?: string) {
133 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
134 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
136 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
138 loop: this.customizations.loop,
139 autoplay: this.customizations.autoplay,
140 muted: this.customizations.muted,
142 title: this.customizations.title,
143 warningTitle: this.customizations.warningTitle,
144 controls: this.customizations.controls,
145 peertubeLink: this.customizations.peertubeLink