1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Add embed paramaters (#6989)

* peertube-video-embed: add support for responsive data attribute

* peertube-video-embed: add support for the remaining data-* attributes

* add support for playlist position data tag

* Styling

---------

Co-authored-by: Chocobozzz <me@florianbigard.com>
This commit is contained in:
Johan van Dongen 2025-04-22 10:02:21 +02:00 committed by GitHub
parent e24716c571
commit 1bf655fcba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 87 additions and 7 deletions

View file

@ -116,7 +116,23 @@ export class CustomMarkupService {
const data = el.dataset as EmbedMarkupData const data = el.dataset as EmbedMarkupData
const { component, loadedPromise } = this.dynamicElementService.createElement(EmbedMarkupComponent) const { component, loadedPromise } = this.dynamicElementService.createElement(EmbedMarkupComponent)
this.dynamicElementService.setModel(component, { uuid: data.uuid, type }) this.dynamicElementService.setModel(component, {
uuid: data.uuid,
type,
responsive: this.buildBoolean(data.responsive),
startAt: data.startAt,
stopAt: data.stopAt,
subtitle: data.subtitle,
autoplay: this.buildBoolean(data.autoplay),
muted: this.buildBoolean(data.muted),
loop: this.buildBoolean(data.loop),
title: this.buildBoolean(data.title),
p2p: this.buildBoolean(data.p2p),
warningTitle: this.buildBoolean(data.warningTitle),
controlBar: this.buildBoolean(data.controlBar),
peertubeLink: this.buildBoolean(data.peertubeLink),
playlistPosition: this.buildNumber(data.playlistPosition)
})
return { component, loadedPromise } return { component, loadedPromise }
} }

View file

@ -1,7 +1,13 @@
import { environment } from 'src/environments/environment'
import { Component, ElementRef, OnInit, inject, input } from '@angular/core' import { Component, ElementRef, OnInit, inject, input } from '@angular/core'
import {
buildPlaylistEmbedLink,
buildVideoEmbedLink,
decoratePlaylistLink,
decorateVideoLink,
timeToInt
} from '@peertube/peertube-core-utils'
import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' import { buildVideoOrPlaylistEmbed } from '@root-helpers/video'
import { buildPlaylistEmbedLink, buildVideoEmbedLink } from '@peertube/peertube-core-utils' import { environment } from 'src/environments/environment'
import { CustomMarkupComponent } from './shared' import { CustomMarkupComponent } from './shared'
@Component({ @Component({
@ -14,14 +20,59 @@ export class EmbedMarkupComponent implements CustomMarkupComponent, OnInit {
readonly uuid = input<string>(undefined) readonly uuid = input<string>(undefined)
readonly type = input<'video' | 'playlist'>('video') readonly type = input<'video' | 'playlist'>('video')
readonly responsive = input<boolean>(undefined)
readonly startAt = input<string>(undefined)
readonly stopAt = input<string>(undefined)
readonly subtitle = input<string>(undefined)
readonly autoplay = input<boolean>(undefined)
readonly muted = input<boolean>(undefined)
readonly loop = input<boolean>(undefined)
readonly title = input<boolean>(undefined)
readonly p2p = input<boolean>(undefined)
readonly warningTitle = input<boolean>(undefined)
readonly controlBar = input<boolean>(undefined)
readonly peertubeLink = input<boolean>(undefined)
readonly playlistPosition = input<number>(undefined)
loaded: undefined loaded: undefined
ngOnInit () { ngOnInit () {
const link = this.type() === 'video' this.el.nativeElement.innerHTML = buildVideoOrPlaylistEmbed({
? buildVideoEmbedLink({ uuid: this.uuid() }, environment.originServerUrl) embedUrl: this.buildLink(),
: buildPlaylistEmbedLink({ uuid: this.uuid() }, environment.originServerUrl) embedTitle: this.uuid(),
responsive: this.responsive() ?? false
})
}
this.el.nativeElement.innerHTML = buildVideoOrPlaylistEmbed({ embedUrl: link, embedTitle: this.uuid() }) private buildLink () {
if (this.type() === 'playlist') {
return decoratePlaylistLink({
url: buildPlaylistEmbedLink({ uuid: this.uuid() }, environment.originServerUrl),
playlistPosition: this.playlistPosition()
})
}
const startTime = this.startAt()
? timeToInt(this.startAt())
: undefined
const stopTime = this.stopAt()
? timeToInt(this.stopAt())
: undefined
return decorateVideoLink({
url: buildVideoEmbedLink({ uuid: this.uuid() }, environment.originServerUrl),
startTime,
stopTime,
subtitle: this.subtitle(),
loop: this.loop(),
autoplay: this.autoplay(),
muted: this.muted(),
title: this.title(),
warningTitle: this.warningTitle(),
controlBar: this.controlBar(),
peertubeLink: this.peertubeLink(),
p2p: this.p2p()
})
} }
} }

View file

@ -3,6 +3,19 @@ type StringBoolean = 'true' | 'false'
export type EmbedMarkupData = { export type EmbedMarkupData = {
// Video or playlist uuid // Video or playlist uuid
uuid: string uuid: string
responsive?: StringBoolean
startAt?: string
stopAt?: string
subtitle?: string
autoplay?: StringBoolean
muted?: StringBoolean
loop?: StringBoolean
title?: StringBoolean
p2p?: StringBoolean
warningTitle?: StringBoolean
controlBar?: StringBoolean
peertubeLink?: StringBoolean
playlistPosition?: string // number
} }
export type VideoMiniatureMarkupData = { export type VideoMiniatureMarkupData = {