aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-03-23 14:06:43 +0100
committerChocobozzz <me@florianbigard.com>2022-03-23 14:06:43 +0100
commit5302f77d095c2188859ee463128aa59eec20ea88 (patch)
treebfa68f03128e80480cf8ba1a61a533fae22ffe69 /client/src/standalone
parentfa737aa05806ee1b3745726b67074eb0c32f3300 (diff)
downloadPeerTube-5302f77d095c2188859ee463128aa59eec20ea88.tar.gz
PeerTube-5302f77d095c2188859ee463128aa59eec20ea88.tar.zst
PeerTube-5302f77d095c2188859ee463128aa59eec20ea88.zip
Support more plugin helpers in embed
Diffstat (limited to 'client/src/standalone')
-rw-r--r--client/src/standalone/videos/embed.ts33
1 files changed, 26 insertions, 7 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 55c26ec3b..c0af1dfb3 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -8,6 +8,7 @@ import {
8 HttpStatusCode, 8 HttpStatusCode,
9 LiveVideo, 9 LiveVideo,
10 OAuth2ErrorCode, 10 OAuth2ErrorCode,
11 PublicServerSetting,
11 ResultList, 12 ResultList,
12 UserRefreshToken, 13 UserRefreshToken,
13 Video, 14 Video,
@@ -21,7 +22,7 @@ import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode, VideoJ
21import { TranslationsManager } from '../../assets/player/translations-manager' 22import { TranslationsManager } from '../../assets/player/translations-manager'
22import { getBoolOrDefault } from '../../root-helpers/local-storage-utils' 23import { getBoolOrDefault } from '../../root-helpers/local-storage-utils'
23import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage' 24import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage'
24import { PluginsManager } from '../../root-helpers/plugins-manager' 25import { PluginInfo, PluginsManager } from '../../root-helpers/plugins-manager'
25import { UserLocalStorageKeys, UserTokens } from '../../root-helpers/users' 26import { UserLocalStorageKeys, UserTokens } from '../../root-helpers/users'
26import { objectToUrlEncoded } from '../../root-helpers/utils' 27import { objectToUrlEncoded } from '../../root-helpers/utils'
27import { isP2PEnabled } from '../../root-helpers/video' 28import { isP2PEnabled } from '../../root-helpers/video'
@@ -98,6 +99,10 @@ export class PeerTubeEmbed {
98 return window.location.origin + '/api/v1/videos/live/' + videoId 99 return window.location.origin + '/api/v1/videos/live/' + videoId
99 } 100 }
100 101
102 getPluginUrl () {
103 return window.location.origin + '/api/v1/plugins'
104 }
105
101 refreshFetch (url: string, options?: RequestInit) { 106 refreshFetch (url: string, options?: RequestInit) {
102 return fetch(url, options) 107 return fetch(url, options)
103 .then((res: Response) => { 108 .then((res: Response) => {
@@ -760,8 +765,12 @@ export class PeerTubeEmbed {
760 return document.getElementById('placeholder-preview') 765 return document.getElementById('placeholder-preview')
761 } 766 }
762 767
768 private getHeaderTokenValue () {
769 return `${this.userTokens.tokenType} ${this.userTokens.accessToken}`
770 }
771
763 private setHeadersFromTokens () { 772 private setHeadersFromTokens () {
764 this.headers.set('Authorization', `${this.userTokens.tokenType} ${this.userTokens.accessToken}`) 773 this.headers.set('Authorization', this.getHeaderTokenValue())
765 } 774 }
766 775
767 private removeTokensFromHeaders () { 776 private removeTokensFromHeaders () {
@@ -779,7 +788,7 @@ export class PeerTubeEmbed {
779 788
780 private loadPlugins (translations?: { [ id: string ]: string }) { 789 private loadPlugins (translations?: { [ id: string ]: string }) {
781 this.pluginsManager = new PluginsManager({ 790 this.pluginsManager = new PluginsManager({
782 peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations) 791 peertubeHelpersFactory: pluginInfo => this.buildPeerTubeHelpers(pluginInfo, translations)
783 }) 792 })
784 793
785 this.pluginsManager.loadPluginsList(this.config) 794 this.pluginsManager.loadPluginsList(this.config)
@@ -787,7 +796,7 @@ export class PeerTubeEmbed {
787 return this.pluginsManager.ensurePluginsAreLoaded('embed') 796 return this.pluginsManager.ensurePluginsAreLoaded('embed')
788 } 797 }
789 798
790 private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers { 799 private buildPeerTubeHelpers (pluginInfo: PluginInfo, translations?: { [ id: string ]: string }): RegisterClientHelpers {
791 const unimplemented = () => { 800 const unimplemented = () => {
792 throw new Error('This helper is not implemented in embed.') 801 throw new Error('This helper is not implemented in embed.')
793 } 802 }
@@ -797,10 +806,20 @@ export class PeerTubeEmbed {
797 getBaseRouterRoute: unimplemented, 806 getBaseRouterRoute: unimplemented,
798 getBasePluginClientPath: unimplemented, 807 getBasePluginClientPath: unimplemented,
799 808
800 getSettings: unimplemented, 809 getSettings: () => {
810 const url = this.getPluginUrl() + '/' + pluginInfo.plugin.npmName + '/public-settings'
801 811
802 isLoggedIn: unimplemented, 812 return this.refreshFetch(url, { headers: this.headers })
803 getAuthHeader: unimplemented, 813 .then(res => res.json())
814 .then((obj: PublicServerSetting) => obj.publicSettings)
815 },
816
817 isLoggedIn: () => !!this.userTokens,
818 getAuthHeader: () => {
819 if (!this.userTokens) return undefined
820
821 return { Authorization: this.getHeaderTokenValue() }
822 },
804 823
805 notifier: { 824 notifier: {
806 info: unimplemented, 825 info: unimplemented,