private playlistElements: VideoPlaylistElement[]
private currentPlaylistElement: VideoPlaylistElement
- private wrapperElement: HTMLElement
+ private readonly wrapperElement: HTMLElement
private pluginsManager: PluginsManager
- static async main () {
- const videoContainerId = 'video-wrapper'
- const embed = new PeerTubeEmbed(videoContainerId)
- await embed.init()
- }
-
- constructor (private videoWrapperId: string) {
+ constructor (private readonly videoWrapperId: string) {
this.wrapperElement = document.getElementById(this.videoWrapperId)
try {
}
}
+ static async main () {
+ const videoContainerId = 'video-wrapper'
+ const embed = new PeerTubeEmbed(videoContainerId)
+ await embed.init()
+ }
+
getVideoUrl (id: string) {
return window.location.origin + '/api/v1/videos/' + id
}
}
async init () {
- try {
- this.userTokens = Tokens.load()
- await this.initCore()
- } catch (e) {
- console.error(e)
- }
+ this.userTokens = Tokens.load()
+ await this.initCore()
}
private initializeApi () {
while (total > elements.length && i < 10) {
const result = await this.loadPlaylistElements(playlistId, elements.length)
- const json = await result.json() as ResultList<VideoPlaylistElement>
+ const json = await result.json()
total = json.total
elements = elements.concat(json.data)
// Issue when we parsed config from HTML, fallback to API
if (!this.config) {
this.config = await this.refreshFetch('/api/v1/config')
- .then(res => res.json())
+ .then(res => res.json())
}
const videoInfoPromise = videoResponse.json()
.then((videoInfo: VideoDetails) => {
- if (!alreadyHadPlayer) this.loadPlaceholder(videoInfo)
+ this.loadParams(videoInfo)
+
+ if (!alreadyHadPlayer && !this.autoplay) this.loadPlaceholder(videoInfo)
return videoInfo
})
const PeertubePlayerManager = PeertubePlayerManagerModule.PeertubePlayerManager
const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse)
- this.loadParams(videoInfo)
-
const playlistPlugin = this.currentPlaylistElement
? {
elements: this.playlistElements,
this.currentPlaylistElement = videoPlaylistElement
this.loadVideoAndBuildPlayer(this.currentPlaylistElement.video.uuid)
- .catch(err => console.error(err))
+ .catch(err => console.error(err))
}
}
: undefined
isLive: videoInfo.isLive,
playerElement: this.playerElement,
- onPlayerElementChange: (element: HTMLVideoElement) => this.playerElement = element,
+ onPlayerElementChange: (element: HTMLVideoElement) => {
+ this.playerElement = element
+ },
videoDuration: videoInfo.duration,
enableHotkeys: true,
})
}
- this.player = await PeertubePlayerManager.initialize(this.mode, options, (player: videojs.Player) => this.player = player)
+ this.player = await PeertubePlayerManager.initialize(this.mode, options, (player: videojs.Player) => {
+ this.player = player
+ })
+
this.player.on('customError', (event: any, data: any) => this.handleError(data.err, serverTranslations))
- window[ 'videojsPlayer' ] = this.player
+ window['videojsPlayer'] = this.player
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)
- return
+
}
}
- 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 && (!videoInfo.isLocal || this.config.tracker.enabled)
? '<span class="text">' + peertubeTranslate('Watching this video may reveal your IP address to others.') + '</span>'
: undefined
private async buildCaptions (serverTranslations: any, captionsResponse: Response): Promise<VideoJSCaption[]> {
if (captionsResponse.ok) {
- const { data } = (await captionsResponse.json()) as ResultList<VideoCaption>
+ const { data } = await captionsResponse.json()
- return data.map(c => ({
+ return data.map((c: VideoCaption) => ({
label: peertubeTranslate(c.language.label, serverTranslations),
language: c.language.id,
src: window.location.origin + c.captionPath
private getResourceId () {
const urlParts = window.location.pathname.split('/')
- return urlParts[ urlParts.length - 1 ]
+ return urlParts[urlParts.length - 1]
}
private isPlaylistEmbed () {
}
private buildPeerTubeHelpers (translations?: { [ id: string ]: string }): RegisterClientHelpers {
- function unimplemented (): any {
+ const unimplemented = () => {
throw new Error('This helper is not implemented in embed.')
}
enhancedMarkdownToHTML: unimplemented
},
- translate: (value: string) => {
- return Promise.resolve(peertubeTranslate(value, translations))
- }
+ translate: (value: string) => Promise.resolve(peertubeTranslate(value, translations))
}
}
}
PeerTubeEmbed.main()
- .catch(err => console.error('Cannot init embed.', err))
+ .catch(err => {
+ (window as any).displayIncompatibleBrowser()
+
+ console.error('Cannot init embed.', err)
+ })