OAuth2ErrorCode,
ResultList,
UserRefreshToken,
+ Video,
VideoCaption,
VideoDetails,
VideoPlaylist,
import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager'
import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings'
import { TranslationsManager } from '../../assets/player/translations-manager'
+import { isP2PEnabled } from '../../assets/player/utils'
+import { getBoolOrDefault } from '../../root-helpers/local-storage-utils'
import { peertubeLocalStorage } from '../../root-helpers/peertube-web-storage'
import { PluginsManager } from '../../root-helpers/plugins-manager'
-import { Tokens } from '../../root-helpers/users'
+import { UserLocalStorageKeys, UserTokens } from '../../root-helpers/users'
import { objectToUrlEncoded } from '../../root-helpers/utils'
import { RegisterClientHelpers } from '../../types/register-client-option.model'
import { PeerTubeEmbedApi } from './embed-api'
mode: PlayerMode
scope = 'peertube'
- userTokens: Tokens
+ userTokens: UserTokens
headers = new Headers()
LOCAL_STORAGE_OAUTH_CLIENT_KEYS = {
CLIENT_ID: 'client_id',
return res.json()
}).then((obj: UserRefreshToken & { code?: OAuth2ErrorCode }) => {
if (!obj || obj.code === OAuth2ErrorCode.INVALID_GRANT) {
- Tokens.flush()
+ UserTokens.flushLocalStorage(peertubeLocalStorage)
this.removeTokensFromHeaders()
return resolve()
this.userTokens.accessToken = obj.access_token
this.userTokens.refreshToken = obj.refresh_token
- this.userTokens.save()
+ UserTokens.saveToLocalStorage(peertubeLocalStorage, this.userTokens)
this.setHeadersFromTokens()
return refreshingTokenPromise
.catch(() => {
- Tokens.flush()
+ UserTokens.flushLocalStorage(peertubeLocalStorage)
this.removeTokensFromHeaders()
}).then(() => fetch(url, {
}
async init () {
- try {
- this.userTokens = Tokens.load()
- await this.initCore()
- } catch (e) {
- console.error(e)
- }
+ this.userTokens = UserTokens.getUserTokens(peertubeLocalStorage)
+ await this.initCore()
}
private initializeApi () {
muted: this.muted,
loop: this.loop,
+ p2pEnabled: this.isP2PEnabled(videoInfo),
+
captions: videoCaptions.length !== 0,
subtitle: this.subtitle,
this.buildCSS()
- await this.buildDock(videoInfo)
+ this.buildDock(videoInfo)
this.initializeApi()
}
private handleError (err: Error, translations?: { [ id: string ]: string }) {
- if (err.message.indexOf('from xs param') !== -1) {
+ if (err.message.includes('from xs param')) {
this.player.dispose()
this.playerElement = null
this.displayError('This video is not available because the remote instance is not responding.', translations)
}
}
- private async buildDock (videoInfo: VideoDetails) {
+ private buildDock (videoInfo: VideoDetails) {
if (!this.controls) return
// On webtorrent fallback, player may have been disposed
const title = this.title ? videoInfo.name : undefined
- const description = this.config.tracker.enabled && this.warningTitle
+ const description = this.warningTitle && this.isP2PEnabled(videoInfo)
? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>'
: undefined
return {
getBaseStaticRoute: unimplemented,
-
getBaseRouterRoute: unimplemented,
+ getBasePluginClientPath: unimplemented,
getSettings: unimplemented,
translate: (value: string) => Promise.resolve(peertubeTranslate(value, translations))
}
}
+
+ private isP2PEnabled (video: Video) {
+ const userP2PEnabled = getBoolOrDefault(
+ peertubeLocalStorage.getItem(UserLocalStorageKeys.P2P_ENABLED),
+ this.config.defaults.p2p.embed.enabled
+ )
+
+ return isP2PEnabled(video, this.config, userP2PEnabled)
+ }
}
PeerTubeEmbed.main()
- .catch(err => console.error('Cannot init embed.', err))
+ .catch(err => {
+ (window as any).displayIncompatibleBrowser()
+
+ console.error('Cannot init embed.', err)
+ })