import './embed.scss'
+import '../../assets/player/dock/peertube-dock-component'
+import '../../assets/player/dock/peertube-dock-plugin'
import videojs from 'video.js'
import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
import {
OAuth2ErrorCode,
ResultList,
UserRefreshToken,
+ Video,
VideoCaption,
VideoDetails,
VideoPlaylist,
VideoPlaylistElement,
VideoStreamingPlaylistType
} from '../../../../shared/models'
-import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player/peertube-player-manager'
+import { P2PMediaLoaderOptions, PeertubePlayerManagerOptions, PlayerMode } from '../../assets/player'
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'
title: boolean
warningTitle: boolean
peertubeLink: boolean
+ p2pEnabled: boolean
bigPlayBackgroundColor: string
foregroundColor: string
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 () {
- this.userTokens = Tokens.load()
+ this.userTokens = UserTokens.getUserTokens(peertubeLocalStorage)
await this.initCore()
}
this.enableApi = this.getParamToggle(params, 'api', this.enableApi)
this.warningTitle = this.getParamToggle(params, 'warningTitle', true)
this.peertubeLink = this.getParamToggle(params, 'peertubeLink', true)
+ this.p2pEnabled = this.getParamToggle(params, 'p2p', this.isP2PEnabled(video))
this.scope = this.getParamString(params, 'scope', this.scope)
this.subtitle = this.getParamString(params, 'subtitle')
muted: this.muted,
loop: this.loop,
+ p2pEnabled: this.p2pEnabled,
+
captions: videoCaptions.length !== 0,
subtitle: this.subtitle,
serverUrl: window.location.origin,
language: navigator.language,
embedUrl: window.location.origin + videoInfo.embedPath,
- embedTitle: videoInfo.name
+ embedTitle: videoInfo.name,
+
+ errorNotifier: () => {
+ // Empty, we don't have a notifier in the embed
+ }
},
webtorrent: {
this.player.dispose()
this.playerElement = null
this.displayError('This video is not available because the remote instance is not responding.', translations)
-
}
}
if (!this.player.player_) return
const title = this.title ? videoInfo.name : undefined
-
- const description = this.warningTitle && (!videoInfo.isLocal || this.config.tracker.enabled)
+ const description = this.warningTitle && this.p2pEnabled
? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>'
: undefined
+ const availableAvatars = videoInfo.channel.avatars.filter(a => a.width < 50)
+ const avatar = availableAvatars.length !== 0
+ ? availableAvatars[0]
+ : undefined
+
if (title || description) {
- this.player.dock({
+ this.player.peertubeDock({
title,
- description
+ description,
+ avatarUrl: title && avatar
+ ? avatar.path
+ : undefined
})
}
}
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()