+ }
+
+ private async initCore () {
+ const urlParts = window.location.pathname.split('/')
+ const videoId = urlParts[ urlParts.length - 1 ]
+
+ const [ serverTranslations, videoResponse, captionsResponse, configResponse ] = await Promise.all([
+ PeertubePlayerManager.getServerTranslations(window.location.origin, navigator.language),
+ this.loadVideoInfo(videoId),
+ this.loadVideoCaptions(videoId),
+ this.loadConfig()
+ ])
+
+ if (!videoResponse.ok) {
+ if (videoResponse.status === 404) return this.videoNotFound(serverTranslations)
+
+ return this.videoFetchError(serverTranslations)
+ }
+
+ const videoInfo: VideoDetails = await videoResponse.json()
+ const videoCaptions = await this.buildCaptions(serverTranslations, captionsResponse)
+
+ this.loadParams()
+
+ const options: PeertubePlayerManagerOptions = {
+ common: {
+ autoplay: this.autoplay,
+ controls: this.controls,
+ muted: this.muted,
+ loop: this.loop,
+ captions: videoCaptions.length !== 0,
+ startTime: this.startTime,
+ stopTime: this.stopTime,
+ subtitle: this.subtitle,
+
+ videoCaptions,
+ inactivityTimeout: 1500,
+ videoViewUrl: this.getVideoUrl(videoId) + '/views',
+
+ playerElement: this.videoElement,
+ onPlayerElementChange: (element: HTMLVideoElement) => this.videoElement = element,
+
+ 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
+ },
+
+ webtorrent: {
+ videoFiles: videoInfo.files
+ }
+ }
+
+ 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
+ })
+ }
+
+ this.player = await PeertubePlayerManager.initialize(this.mode, options, player => this.player = player)
+ this.player.on('customError', (event: any, data: any) => this.handleError(data.err, serverTranslations))
+
+ window[ 'videojsPlayer' ] = this.player
+
+ this.buildCSS()
+
+ await this.buildDock(videoInfo, configResponse)
+
+ this.initializeApi()
+ }
+
+ private handleError (err: Error, translations?: { [ id: string ]: string }) {
+ if (err.message.indexOf('from xs param') !== -1) {
+ this.player.dispose()
+ this.videoElement = null
+ this.displayError('This video is not available because the remote instance is not responding.', translations)
+ return
+ }
+ }
+
+ private async buildDock (videoInfo: VideoDetails, configResponse: Response) {
+ if (this.controls) {
+ const title = this.title ? videoInfo.name : undefined