aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/standalone/videos/embed.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/standalone/videos/embed.ts')
-rw-r--r--client/src/standalone/videos/embed.ts28
1 files changed, 21 insertions, 7 deletions
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 874be580d..94f1096b7 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'
@@ -48,7 +51,7 @@ export class PeerTubeEmbed {
48 mode: PlayerMode 51 mode: PlayerMode
49 scope = 'peertube' 52 scope = 'peertube'
50 53
51 userTokens: Tokens 54 userTokens: UserTokens
52 headers = new Headers() 55 headers = new Headers()
53 LOCAL_STORAGE_OAUTH_CLIENT_KEYS = { 56 LOCAL_STORAGE_OAUTH_CLIENT_KEYS = {
54 CLIENT_ID: 'client_id', 57 CLIENT_ID: 'client_id',
@@ -118,7 +121,7 @@ export class PeerTubeEmbed {
118 return res.json() 121 return res.json()
119 }).then((obj: UserRefreshToken & { code?: OAuth2ErrorCode }) => { 122 }).then((obj: UserRefreshToken & { code?: OAuth2ErrorCode }) => {
120 if (!obj || obj.code === OAuth2ErrorCode.INVALID_GRANT) { 123 if (!obj || obj.code === OAuth2ErrorCode.INVALID_GRANT) {
121 Tokens.flush() 124 UserTokens.flushLocalStorage(peertubeLocalStorage)
122 this.removeTokensFromHeaders() 125 this.removeTokensFromHeaders()
123 126
124 return resolve() 127 return resolve()
@@ -126,7 +129,7 @@ export class PeerTubeEmbed {
126 129
127 this.userTokens.accessToken = obj.access_token 130 this.userTokens.accessToken = obj.access_token
128 this.userTokens.refreshToken = obj.refresh_token 131 this.userTokens.refreshToken = obj.refresh_token
129 this.userTokens.save() 132 UserTokens.saveToLocalStorage(peertubeLocalStorage, this.userTokens)
130 133
131 this.setHeadersFromTokens() 134 this.setHeadersFromTokens()
132 135
@@ -138,7 +141,7 @@ export class PeerTubeEmbed {
138 141
139 return refreshingTokenPromise 142 return refreshingTokenPromise
140 .catch(() => { 143 .catch(() => {
141 Tokens.flush() 144 UserTokens.flushLocalStorage(peertubeLocalStorage)
142 145
143 this.removeTokensFromHeaders() 146 this.removeTokensFromHeaders()
144 }).then(() => fetch(url, { 147 }).then(() => fetch(url, {
@@ -258,7 +261,7 @@ export class PeerTubeEmbed {
258 } 261 }
259 262
260 async init () { 263 async init () {
261 this.userTokens = Tokens.load() 264 this.userTokens = UserTokens.getUserTokens(peertubeLocalStorage)
262 await this.initCore() 265 await this.initCore()
263 } 266 }
264 267
@@ -515,6 +518,8 @@ export class PeerTubeEmbed {
515 muted: this.muted, 518 muted: this.muted,
516 loop: this.loop, 519 loop: this.loop,
517 520
521 p2pEnabled: this.isP2PEnabled(videoInfo),
522
518 captions: videoCaptions.length !== 0, 523 captions: videoCaptions.length !== 0,
519 subtitle: this.subtitle, 524 subtitle: this.subtitle,
520 525
@@ -669,7 +674,7 @@ export class PeerTubeEmbed {
669 674
670 const title = this.title ? videoInfo.name : undefined 675 const title = this.title ? videoInfo.name : undefined
671 676
672 const description = this.warningTitle && (!videoInfo.isLocal || this.config.tracker.enabled) 677 const description = this.warningTitle && this.isP2PEnabled(videoInfo)
673 ? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>' 678 ? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>'
674 : undefined 679 : undefined
675 680
@@ -784,6 +789,15 @@ export class PeerTubeEmbed {
784 translate: (value: string) => Promise.resolve(peertubeTranslate(value, translations)) 789 translate: (value: string) => Promise.resolve(peertubeTranslate(value, translations))
785 } 790 }
786 } 791 }
792
793 private isP2PEnabled (video: Video) {
794 const userP2PEnabled = getBoolOrDefault(
795 peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED),
796 this.config.defaults.p2p.enabled
797 )
798
799 return isP2PEnabled(video, this.config, userP2PEnabled)
800 }
787} 801}
788 802
789PeerTubeEmbed.main() 803PeerTubeEmbed.main()