// For google bot that uses Chrome 41 and does not understand fetch
import 'whatwg-fetch'
-// FIXME: something weird with our path definition in tsconfig and typings
-// @ts-ignore
-import * as vjs from 'video.js'
-
import * as Channel from 'jschannel'
import { peertubeTranslate, ResultList, VideoDetails } from '../../../../shared'
-import { addContextMenu, getServerTranslations, getVideojsOptions, loadLocaleInVideoJS } from '../../assets/player/peertube-player'
import { PeerTubeResolution } from '../player/definitions'
import { VideoJSCaption } from '../../assets/player/peertube-videojs-typings'
import { VideoCaption } from '../../../../shared/models/videos/caption/video-caption.model'
+import {
+ P2PMediaLoaderOptions,
+ PeertubePlayerManager,
+ PeertubePlayerManagerOptions,
+ PlayerMode
+} from '../../assets/player/peertube-player-manager'
+import { VideoStreamingPlaylistType } from '../../../../shared/models/videos/video-streaming-playlist.type'
/**
* Embed API exposes control of the embed player to the outside world via
}
private setResolution (resolutionId: number) {
- if (resolutionId === -1 && this.embed.player.peertube().isAutoResolutionForbidden()) return
+ if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionForbidden()) return
// Auto resolution
if (resolutionId === -1) {
- this.embed.player.peertube().enableAutoResolution()
+ this.embed.player.webtorrent().enableAutoResolution()
return
}
- this.embed.player.peertube().disableAutoResolution()
- this.embed.player.peertube().updateResolution(resolutionId)
+ this.embed.player.webtorrent().disableAutoResolution()
+ this.embed.player.webtorrent().updateResolution(resolutionId)
}
/**
// PeerTube specific capabilities
- this.embed.player.peertube().on('autoResolutionUpdate', () => this.loadResolutions())
- this.embed.player.peertube().on('videoFileUpdate', () => this.loadResolutions())
+ if (this.embed.player.webtorrent) {
+ this.embed.player.webtorrent().on('autoResolutionUpdate', () => this.loadWebTorrentResolutions())
+ this.embed.player.webtorrent().on('videoFileUpdate', () => this.loadWebTorrentResolutions())
+ }
}
- private loadResolutions () {
+ private loadWebTorrentResolutions () {
let resolutions = []
- let currentResolutionId = this.embed.player.peertube().getCurrentResolutionId()
+ let currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId()
- for (const videoFile of this.embed.player.peertube().videoFiles) {
+ for (const videoFile of this.embed.player.webtorrent().videoFiles) {
let label = videoFile.resolution.label
if (videoFile.fps && videoFile.fps >= 50) {
label += videoFile.fps
subtitle: string
enableApi = false
startTime: number | string = 0
+ mode: PlayerMode
scope = 'peertube'
static async main () {
this.scope = this.getParamString(params, 'scope', this.scope)
this.subtitle = this.getParamString(params, 'subtitle')
this.startTime = this.getParamString(params, 'start')
+
+ this.mode = this.getParamToggle(params, 'p2p-media-loader') ? 'p2p-media-loader' : 'webtorrent'
} catch (err) {
console.error('Cannot get params from URL.', err)
}
const urlParts = window.location.pathname.split('/')
const videoId = urlParts[ urlParts.length - 1 ]
- const [ , serverTranslations, videoResponse, captionsResponse ] = await Promise.all([
- loadLocaleInVideoJS(window.location.origin, vjs, navigator.language),
- getServerTranslations(window.location.origin, navigator.language),
+ const [ serverTranslations, videoResponse, captionsResponse ] = await Promise.all([
+ PeertubePlayerManager.getServerTranslations(window.location.origin, navigator.language),
this.loadVideoInfo(videoId),
this.loadVideoCaptions(videoId)
])
this.loadParams()
- const videojsOptions = getVideojsOptions({
- autoplay: this.autoplay,
- controls: this.controls,
- muted: this.muted,
- loop: this.loop,
- startTime: this.startTime,
- subtitle: this.subtitle,
-
- videoCaptions,
- inactivityTimeout: 1500,
- videoViewUrl: this.getVideoUrl(videoId) + '/views',
- playerElement: this.videoElement,
- videoFiles: videoInfo.files,
- videoDuration: videoInfo.duration,
- enableHotkeys: true,
- peertubeLink: true,
- poster: window.location.origin + videoInfo.previewPath,
- theaterMode: false
- })
+ const options: PeertubePlayerManagerOptions = {
+ common: {
+ autoplay: this.autoplay,
+ controls: this.controls,
+ muted: this.muted,
+ loop: this.loop,
+ captions: videoCaptions.length !== 0,
+ startTime: this.startTime,
+ subtitle: this.subtitle,
+
+ videoCaptions,
+ inactivityTimeout: 1500,
+ videoViewUrl: this.getVideoUrl(videoId) + '/views',
+ playerElement: this.videoElement,
+ videoDuration: videoInfo.duration,
+ enableHotkeys: true,
+ peertubeLink: true,
+ poster: window.location.origin + videoInfo.previewPath,
+ theaterMode: false,
+
+ serverUrl: window.location.origin,
+ language: navigator.language,
+ embedUrl: window.location.origin + videoInfo.embedPath
+ }
+ }
- this.playerOptions = videojsOptions
- this.player = vjs(this.videoContainerId, videojsOptions, () => {
- this.player.on('customError', (event: any, data: any) => this.handleError(data.err, serverTranslations))
+ if (this.mode === 'p2p-media-loader') {
+ const hlsPlaylist = videoInfo.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
+
+ Object.assign(options, {
+ p2pMediaLoader: {
+ playlistUrl: hlsPlaylist.playlistUrl,
+ segmentsSha256Url: hlsPlaylist.segmentsSha256Url,
+ redundancyBaseUrls: hlsPlaylist.redundancies.map(r => r.baseUrl),
+ trackerAnnounce: videoInfo.trackerUrls,
+ videoFiles: videoInfo.files
+ } as P2PMediaLoaderOptions
+ })
+ } else {
+ Object.assign(options, {
+ webtorrent: {
+ videoFiles: videoInfo.files
+ }
+ })
+ }
- window[ 'videojsPlayer' ] = this.player
+ this.player = await PeertubePlayerManager.initialize(this.mode, options)
- if (this.controls) {
- this.player.dock({
- title: videoInfo.name,
- description: this.player.localize('Uses P2P, others may know your IP is downloading this video.')
- })
- }
+ this.player.on('customError', (event: any, data: any) => this.handleError(data.err, serverTranslations))
- addContextMenu(this.player, window.location.origin + videoInfo.embedPath)
+ window[ 'videojsPlayer' ] = this.player
- this.initializeApi()
- })
+ if (this.controls) {
+ this.player.dock({
+ title: videoInfo.name,
+ description: this.player.localize('Uses P2P, others may know your IP is downloading this video.')
+ })
+ }
+
+ this.initializeApi()
}
private handleError (err: Error, translations?: { [ id: string ]: string }) {