2022-10-12 16:09:02 +02:00
|
|
|
import { addQueryParams } from '../../../../../../shared/core-utils'
|
|
|
|
import { PeertubePlayerManagerOptions, WebtorrentPluginOptions } from '../../types'
|
2022-03-14 11:16:54 +01:00
|
|
|
|
|
|
|
export class WebTorrentOptionsBuilder {
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
private options: PeertubePlayerManagerOptions,
|
|
|
|
private autoPlayValue: any
|
|
|
|
) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getPluginOptions () {
|
|
|
|
const commonOptions = this.options.common
|
|
|
|
const webtorrentOptions = this.options.webtorrent
|
|
|
|
const p2pMediaLoaderOptions = this.options.p2pMediaLoader
|
|
|
|
|
|
|
|
const autoplay = this.autoPlayValue === 'play'
|
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
const webtorrent: WebtorrentPluginOptions = {
|
2022-03-14 11:16:54 +01:00
|
|
|
autoplay,
|
|
|
|
|
|
|
|
playerRefusedP2P: commonOptions.p2pEnabled === false,
|
|
|
|
videoDuration: commonOptions.videoDuration,
|
|
|
|
playerElement: commonOptions.playerElement,
|
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
videoFileToken: commonOptions.videoFileToken,
|
|
|
|
|
|
|
|
requiresAuth: commonOptions.requiresAuth,
|
|
|
|
|
|
|
|
buildWebSeedUrls: file => {
|
|
|
|
if (!commonOptions.requiresAuth) return []
|
|
|
|
|
|
|
|
return [ addQueryParams(file.fileUrl, { videoFileToken: commonOptions.videoFileToken() }) ]
|
|
|
|
},
|
|
|
|
|
2022-03-14 11:16:54 +01:00
|
|
|
videoFiles: webtorrentOptions.videoFiles.length !== 0
|
|
|
|
? webtorrentOptions.videoFiles
|
|
|
|
// The WebTorrent plugin won't be able to play these files, but it will fallback to HTTP mode
|
|
|
|
: p2pMediaLoaderOptions?.videoFiles || [],
|
|
|
|
|
|
|
|
startTime: commonOptions.startTime
|
|
|
|
}
|
|
|
|
|
|
|
|
return { webtorrent }
|
|
|
|
}
|
|
|
|
}
|