aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/shared/manager-options/webtorrent-options-builder.ts
blob: 257cf1e0567b2799de3ba1dd36683432809090b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { PeertubePlayerManagerOptions } from '../../types'

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'

    const webtorrent = {
      autoplay,

      playerRefusedP2P: commonOptions.p2pEnabled === false,
      videoDuration: commonOptions.videoDuration,
      playerElement: commonOptions.playerElement,

      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 }
  }
}