From 9162fdd36300d2478f13d6ad346ec2c323f40faa Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 26 Jul 2021 14:12:39 +0200 Subject: Refactor video links building --- .../player/videojs-components/peertube-link-button.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'client/src/assets/player/videojs-components') diff --git a/client/src/assets/player/videojs-components/peertube-link-button.ts b/client/src/assets/player/videojs-components/peertube-link-button.ts index e73c95900..f47c165d9 100644 --- a/client/src/assets/player/videojs-components/peertube-link-button.ts +++ b/client/src/assets/player/videojs-components/peertube-link-button.ts @@ -1,11 +1,13 @@ -import { buildVideoLink } from '../utils' import videojs from 'video.js' +import { PeerTubeLinkButtonOptions } from '../peertube-videojs-typings' +import { buildVideoLink, decorateVideoLink } from '../utils' const Button = videojs.getComponent('Button') class PeerTubeLinkButton extends Button { + private shortUUID: string - constructor (player: videojs.Player, options?: videojs.ComponentOptions) { - super(player, options) + constructor (player: videojs.Player, options?: PeerTubeLinkButtonOptions) { + super(player, options as any) } createEl () { @@ -13,7 +15,7 @@ class PeerTubeLinkButton extends Button { } updateHref () { - this.el().setAttribute('href', buildVideoLink({ startTime: this.player().currentTime() })) + this.el().setAttribute('href', this.buildLink()) } handleClick () { @@ -22,7 +24,7 @@ class PeerTubeLinkButton extends Button { private buildElement () { const el = videojs.dom.createEl('a', { - href: buildVideoLink(), + href: this.buildLink(), innerHTML: 'PeerTube', title: this.player().localize('Video page (new window)'), className: 'vjs-peertube-link', @@ -33,6 +35,12 @@ class PeerTubeLinkButton extends Button { return el as HTMLButtonElement } + + private buildLink () { + const url = buildVideoLink({ shortUUID: this.shortUUID }) + + return decorateVideoLink({ url, startTime: this.player().currentTime() }) + } } videojs.registerComponent('PeerTubeLinkButton', PeerTubeLinkButton) -- cgit v1.2.3