+
+ private setHeadersFromTokens () {
+ this.headers.set('Authorization', `${this.userTokens.tokenType} ${this.userTokens.accessToken}`)
+ }
+
+ private removeTokensFromHeaders () {
+ this.headers.delete('Authorization')
+ }
+
+ private getResourceId () {
+ const urlParts = window.location.pathname.split('/')
+ return urlParts[ urlParts.length - 1 ]
+ }
+
+ private isPlaylistEmbed () {
+ return window.location.pathname.split('/')[1] === 'video-playlists'
+ }
+
+ private async ensurePluginsAreLoaded (config: ServerConfig, translations?: { [ id: string ]: string }) {
+ if (config.plugin.registered.length === 0) return
+
+ for (const plugin of config.plugin.registered) {
+ for (const key of Object.keys(plugin.clientScripts)) {
+ const clientScript = plugin.clientScripts[key]
+
+ if (clientScript.scopes.includes('embed') === false) continue
+
+ const script = `/plugins/${plugin.name}/${plugin.version}/client-scripts/${clientScript.script}`
+
+ if (this.loadedScripts.has(script)) continue
+
+ const pluginInfo = {
+ plugin,
+ clientScript: {
+ script,
+ scopes: clientScript.scopes
+ },
+ pluginType: PluginType.PLUGIN,
+ isTheme: false
+ }
+
+ await loadPlugin({
+ hooks: this.peertubeHooks,
+ pluginInfo,
+ peertubeHelpersFactory: _ => this.buildPeerTubeHelpers(translations)
+ })
+ }
+ }
+ }
+
+ private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers {
+ function unimplemented (): any {
+ throw new Error('This helper is not implemented in embed.')
+ }
+
+ return {
+ getBaseStaticRoute: unimplemented,
+
+ getSettings: unimplemented,
+
+ isLoggedIn: unimplemented,
+
+ notifier: {
+ info: unimplemented,
+ error: unimplemented,
+ success: unimplemented
+ },
+
+ showModal: unimplemented,
+
+ getServerConfig: unimplemented,
+
+ markdownRenderer: {
+ textMarkdownToHTML: unimplemented,
+ enhancedMarkdownToHTML: unimplemented
+ },
+
+ translate: (value: string) => {
+ return Promise.resolve(peertubeTranslate(value, translations))
+ }
+ }
+ }
+
+ private runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> {
+ return runHook(this.peertubeHooks, hookName, result, params)
+ }