aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/standalone')
-rw-r--r--client/src/standalone/videos/embed.html6
-rw-r--r--client/src/standalone/videos/embed.ts32
2 files changed, 30 insertions, 8 deletions
diff --git a/client/src/standalone/videos/embed.html b/client/src/standalone/videos/embed.html
index 8ec03d199..f30dda96b 100644
--- a/client/src/standalone/videos/embed.html
+++ b/client/src/standalone/videos/embed.html
@@ -59,6 +59,12 @@
59 59
60 const errorText = document.getElementById('error-content') 60 const errorText = document.getElementById('error-content')
61 errorText.innerHTML = text 61 errorText.innerHTML = text
62
63 const videoWrapper = document.getElementById('video-wrapper')
64 if (videoWrapper) videoWrapper.style.display = 'none'
65
66 const placeholderPreview = document.getElementById('placeholder-preview')
67 if (placeholderPreview) placeholderPreview.style.display = 'none'
62 } 68 }
63 69
64 window.onerror = function () { 70 window.onerror = function () {
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 9d1c6c443..eb8076b98 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -7,6 +7,7 @@ import {
7 OAuth2ErrorCode, 7 OAuth2ErrorCode,
8 ResultList, 8 ResultList,
9 UserRefreshToken, 9 UserRefreshToken,
10 Video,
10 VideoCaption, 11 VideoCaption,
11 VideoDetails, 12 VideoDetails,
12 VideoPlaylist, 13 VideoPlaylist,
@@ -16,9 +17,11 @@ import {
16import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager' 17import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager'
17import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings' 18import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings'
18import { TranslationsManager } from '../../assets/player/translations-manager' 19import { TranslationsManager } from '../../assets/player/translations-manager'
20import { isP2PEnabled } from '../../assets/player/utils'
21import { getBoolOrDefault } from '../../root-helpers/local-storage-utils'
19import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage' 22import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage'
20import { PluginsManager } from '../../root-helpers/plugins-manager' 23import { PluginsManager } from '../../root-helpers/plugins-manager'
21import { Tokens } from '../../root-helpers/users' 24import { UserLocalStorageKeys, UserTokens } from '../../root-helpers/users'
22import { objectToUrlEncoded } from '../../root-helpers/utils' 25import { objectToUrlEncoded } from '../../root-helpers/utils'
23import { RegisterClientHelpers } from '../../types/register-client-option.model' 26import { RegisterClientHelpers } from '../../types/register-client-option.model'
24import { PeerTubeEmbedApi } from './embed-api' 27import { PeerTubeEmbedApi } from './embed-api'
@@ -42,13 +45,14 @@ export class PeerTubeEmbed {
42 title: boolean 45 title: boolean
43 warningTitle: boolean 46 warningTitle: boolean
44 peertubeLink: boolean 47 peertubeLink: boolean
48 p2pEnabled: boolean
45 bigPlayBackgroundColor: string 49 bigPlayBackgroundColor: string
46 foregroundColor: string 50 foregroundColor: string
47 51
48 mode: PlayerMode 52 mode: PlayerMode
49 scope = 'peertube' 53 scope = 'peertube'
50 54
51 userTokens: Tokens 55 userTokens: UserTokens
52 headers = new Headers() 56 headers = new Headers()
53 LOCAL_STORAGE_OAUTH_CLIENT_KEYS = { 57 LOCAL_STORAGE_OAUTH_CLIENT_KEYS = {
54 CLIENT_ID: 'client_id', 58 CLIENT_ID: 'client_id',
@@ -118,7 +122,7 @@ export class PeerTubeEmbed {
118 return res.json() 122 return res.json()
119 }).then((obj: UserRefreshToken & { code?: OAuth2ErrorCode }) => { 123 }).then((obj: UserRefreshToken & { code?: OAuth2ErrorCode }) => {
120 if (!obj || obj.code === OAuth2ErrorCode.INVALID_GRANT) { 124 if (!obj || obj.code === OAuth2ErrorCode.INVALID_GRANT) {
121 Tokens.flush() 125 UserTokens.flushLocalStorage(peertubeLocalStorage)
122 this.removeTokensFromHeaders() 126 this.removeTokensFromHeaders()
123 127
124 return resolve() 128 return resolve()
@@ -126,7 +130,7 @@ export class PeerTubeEmbed {
126 130
127 this.userTokens.accessToken = obj.access_token 131 this.userTokens.accessToken = obj.access_token
128 this.userTokens.refreshToken = obj.refresh_token 132 this.userTokens.refreshToken = obj.refresh_token
129 this.userTokens.save() 133 UserTokens.saveToLocalStorage(peertubeLocalStorage, this.userTokens)
130 134
131 this.setHeadersFromTokens() 135 this.setHeadersFromTokens()
132 136
@@ -138,7 +142,7 @@ export class PeerTubeEmbed {
138 142
139 return refreshingTokenPromise 143 return refreshingTokenPromise
140 .catch(() => { 144 .catch(() => {
141 Tokens.flush() 145 UserTokens.flushLocalStorage(peertubeLocalStorage)
142 146
143 this.removeTokensFromHeaders() 147 this.removeTokensFromHeaders()
144 }).then(() => fetch(url, { 148 }).then(() => fetch(url, {
@@ -258,7 +262,7 @@ export class PeerTubeEmbed {
258 } 262 }
259 263
260 async init () { 264 async init () {
261 this.userTokens = Tokens.load() 265 this.userTokens = UserTokens.getUserTokens(peertubeLocalStorage)
262 await this.initCore() 266 await this.initCore()
263 } 267 }
264 268
@@ -281,6 +285,7 @@ export class PeerTubeEmbed {
281 this.enableApi = this.getParamToggle(params, 'api', this.enableApi) 285 this.enableApi = this.getParamToggle(params, 'api', this.enableApi)
282 this.warningTitle = this.getParamToggle(params, 'warningTitle', true) 286 this.warningTitle = this.getParamToggle(params, 'warningTitle', true)
283 this.peertubeLink = this.getParamToggle(params, 'peertubeLink', true) 287 this.peertubeLink = this.getParamToggle(params, 'peertubeLink', true)
288 this.p2pEnabled = this.getParamToggle(params, 'p2p', this.isP2PEnabled(video))
284 289
285 this.scope = this.getParamString(params, 'scope', this.scope) 290 this.scope = this.getParamString(params, 'scope', this.scope)
286 this.subtitle = this.getParamString(params, 'subtitle') 291 this.subtitle = this.getParamString(params, 'subtitle')
@@ -515,6 +520,8 @@ export class PeerTubeEmbed {
515 muted: this.muted, 520 muted: this.muted,
516 loop: this.loop, 521 loop: this.loop,
517 522
523 p2pEnabled: this.p2pEnabled,
524
518 captions: videoCaptions.length !== 0, 525 captions: videoCaptions.length !== 0,
519 subtitle: this.subtitle, 526 subtitle: this.subtitle,
520 527
@@ -669,7 +676,7 @@ export class PeerTubeEmbed {
669 676
670 const title = this.title ? videoInfo.name : undefined 677 const title = this.title ? videoInfo.name : undefined
671 678
672 const description = this.warningTitle && (!videoInfo.isLocal || this.config.tracker.enabled) 679 const description = this.warningTitle && this.p2pEnabled
673 ? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>' 680 ? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>'
674 : undefined 681 : undefined
675 682
@@ -758,8 +765,8 @@ export class PeerTubeEmbed {
758 765
759 return { 766 return {
760 getBaseStaticRoute: unimplemented, 767 getBaseStaticRoute: unimplemented,
761
762 getBaseRouterRoute: unimplemented, 768 getBaseRouterRoute: unimplemented,
769 getBasePluginClientPath: unimplemented,
763 770
764 getSettings: unimplemented, 771 getSettings: unimplemented,
765 772
@@ -784,6 +791,15 @@ export class PeerTubeEmbed {
784 translate: (value: string) => Promise.resolve(peertubeTranslate(value, translations)) 791 translate: (value: string) => Promise.resolve(peertubeTranslate(value, translations))
785 } 792 }
786 } 793 }
794
795 private isP2PEnabled (video: Video) {
796 const userP2PEnabled = getBoolOrDefault(
797 peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED),
798 this.config.defaults.p2p.embed.enabled
799 )
800
801 return isP2PEnabled(video, this.config, userP2PEnabled)
802 }
787} 803}
788 804
789PeerTubeEmbed.main() 805PeerTubeEmbed.main()