]>
Commit | Line | Data |
---|---|---|
3545e72c C |
1 | import { addQueryParams } from '../../../../../../shared/core-utils' |
2 | import { PeertubePlayerManagerOptions, WebtorrentPluginOptions } from '../../types' | |
9597920e C |
3 | |
4 | export class WebTorrentOptionsBuilder { | |
5 | ||
6 | constructor ( | |
7 | private options: PeertubePlayerManagerOptions, | |
8 | private autoPlayValue: any | |
9 | ) { | |
10 | ||
11 | } | |
12 | ||
13 | getPluginOptions () { | |
14 | const commonOptions = this.options.common | |
15 | const webtorrentOptions = this.options.webtorrent | |
16 | const p2pMediaLoaderOptions = this.options.p2pMediaLoader | |
17 | ||
18 | const autoplay = this.autoPlayValue === 'play' | |
19 | ||
3545e72c | 20 | const webtorrent: WebtorrentPluginOptions = { |
9597920e C |
21 | autoplay, |
22 | ||
23 | playerRefusedP2P: commonOptions.p2pEnabled === false, | |
24 | videoDuration: commonOptions.videoDuration, | |
25 | playerElement: commonOptions.playerElement, | |
26 | ||
3545e72c C |
27 | videoFileToken: commonOptions.videoFileToken, |
28 | ||
29 | requiresAuth: commonOptions.requiresAuth, | |
30 | ||
31 | buildWebSeedUrls: file => { | |
32 | if (!commonOptions.requiresAuth) return [] | |
33 | ||
34 | return [ addQueryParams(file.fileUrl, { videoFileToken: commonOptions.videoFileToken() }) ] | |
35 | }, | |
36 | ||
9597920e C |
37 | videoFiles: webtorrentOptions.videoFiles.length !== 0 |
38 | ? webtorrentOptions.videoFiles | |
39 | // The WebTorrent plugin won't be able to play these files, but it will fallback to HTTP mode | |
40 | : p2pMediaLoaderOptions?.videoFiles || [], | |
41 | ||
42 | startTime: commonOptions.startTime | |
43 | } | |
44 | ||
45 | return { webtorrent } | |
46 | } | |
47 | } |