- private static addP2PMediaLoaderOptions (
- plugins: VideoJSPluginOptions,
- options: PeertubePlayerManagerOptions,
- p2pMediaLoaderModule: any
- ) {
- const p2pMediaLoaderOptions = options.p2pMediaLoader
- const commonOptions = options.common
-
- const trackerAnnounce = p2pMediaLoaderOptions.trackerAnnounce
- .filter(t => t.startsWith('ws'))
-
- const redundancyUrlManager = new RedundancyUrlManager(options.p2pMediaLoader.redundancyBaseUrls)
-
- const p2pMediaLoader: P2PMediaLoaderPluginOptions = {
- redundancyUrlManager,
- type: 'application/x-mpegURL',
- startTime: commonOptions.startTime,
- src: p2pMediaLoaderOptions.playlistUrl
- }
-
- let consumeOnly = false
- // FIXME: typings
- if (navigator && (navigator as any).connection && (navigator as any).connection.type === 'cellular') {
- console.log('We are on a cellular connection: disabling seeding.')
- consumeOnly = true
- }
-
- const p2pMediaLoaderConfig = {
- loader: {
- trackerAnnounce,
- segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
- rtcConfig: getRtcConfig(),
- requiredSegmentsPriority: 1,
- segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
- useP2P: getStoredP2PEnabled(),
- consumeOnly
- },
- segments: {
- swarmId: p2pMediaLoaderOptions.playlistUrl
- }
- }
- const hlsjs = {
- levelLabelHandler: (level: { height: number, width: number }) => {
- const resolution = Math.min(level.height || 0, level.width || 0)
-
- const file = p2pMediaLoaderOptions.videoFiles.find(f => f.resolution.id === resolution)
- // We don't have files for live videos
- if (!file) return level.height
-
- let label = file.resolution.label
- if (file.fps >= 50) label += file.fps
-
- return label
- },
- html5: {
- hlsjsConfig: {
- capLevelToPlayerSize: true,
- autoStartLoad: false,
- liveSyncDurationCount: 5,
- loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
- }