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
40 @Input() playlistPosition: number = null
42 activeVideoId: TabId = 'url'
43 activePlaylistId: TabId = 'url'
45 customizations: Customizations
46 isAdvancedCustomizationCollapsed = true
47 includeVideoInPlaylist = false
49 constructor (private modalService: NgbModal) { }
51 show (currentVideoTimestamp?: number, currentPlaylistPosition?: number) {
53 if (this.videoCaptions && this.videoCaptions.length !== 0) {
54 subtitle = this.videoCaptions[0].language.id
57 this.customizations = {
58 startAtCheckbox: false,
59 startAt: currentVideoTimestamp ? Math.floor(currentVideoTimestamp) : 0,
61 stopAtCheckbox: false,
62 stopAt: this.video?.duration,
64 subtitleCheckbox: false,
78 this.playlistPosition = currentPlaylistPosition
80 this.modalService.open(this.modal, { centered: true })
83 getVideoIframeCode () {
84 const options = this.getVideoOptions(this.video.embedUrl)
86 const embedUrl = buildVideoLink(options)
87 return buildVideoOrPlaylistEmbed(embedUrl)
90 getPlaylistIframeCode () {
91 const options = this.getPlaylistOptions(this.playlist.embedUrl)
93 const embedUrl = buildPlaylistLink(options)
94 return buildVideoOrPlaylistEmbed(embedUrl)
98 const baseUrl = window.location.origin + '/videos/watch/' + this.video.uuid
99 const options = this.getVideoOptions(baseUrl)
101 return buildVideoLink(options)
105 const base = window.location.origin + '/videos/watch/playlist/' + this.playlist.uuid
107 if (!this.includeVideoInPlaylist) return base
109 return base + '?playlistPosition=' + this.playlistPosition
113 return window.location.protocol === 'http:'
116 isVideoInEmbedTab () {
117 return this.activeVideoId === 'embed'
120 private getPlaylistOptions (baseUrl?: string) {
124 playlistPosition: this.playlistPosition || undefined
128 private getVideoOptions (baseUrl?: string) {
132 startTime: this.customizations.startAtCheckbox ? this.customizations.startAt : undefined,
133 stopTime: this.customizations.stopAtCheckbox ? this.customizations.stopAt : undefined,
135 subtitle: this.customizations.subtitleCheckbox ? this.customizations.subtitle : undefined,
137 loop: this.customizations.loop,
138 autoplay: this.customizations.autoplay,
139 muted: this.customizations.muted,
141 title: this.customizations.title,
142 warningTitle: this.customizations.warningTitle,
143 controls: this.customizations.controls,
144 peertubeLink: this.customizations.peertubeLink