aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-player-manager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/assets/player/peertube-player-manager.ts')
-rw-r--r--client/src/assets/player/peertube-player-manager.ts45
1 files changed, 36 insertions, 9 deletions
diff --git a/client/src/assets/player/peertube-player-manager.ts b/client/src/assets/player/peertube-player-manager.ts
index 91ca6a2aa..3fdba6fdf 100644
--- a/client/src/assets/player/peertube-player-manager.ts
+++ b/client/src/assets/player/peertube-player-manager.ts
@@ -13,8 +13,10 @@ import './videojs-components/p2p-info-button'
13import './videojs-components/peertube-load-progress-bar' 13import './videojs-components/peertube-load-progress-bar'
14import './videojs-components/theater-button' 14import './videojs-components/theater-button'
15import { P2PMediaLoaderPluginOptions, UserWatching, VideoJSCaption, VideoJSPluginOptions, videojsUntyped } from './peertube-videojs-typings' 15import { P2PMediaLoaderPluginOptions, UserWatching, VideoJSCaption, VideoJSPluginOptions, videojsUntyped } from './peertube-videojs-typings'
16import { buildVideoEmbed, buildVideoLink, copyToClipboard } from './utils' 16import { buildVideoEmbed, buildVideoLink, copyToClipboard, getRtcConfig } from './utils'
17import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n' 17import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '../../../../shared/models/i18n/i18n'
18import { segmentValidatorFactory } from './p2p-media-loader/segment-validator'
19import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder'
18 20
19// Change 'Playback Rate' to 'Speed' (smaller for our settings menu) 21// Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
20videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed' 22videojsUntyped.getComponent('PlaybackRateMenuButton').prototype.controlText_ = 'Speed'
@@ -31,7 +33,10 @@ export type WebtorrentOptions = {
31 33
32export type P2PMediaLoaderOptions = { 34export type P2PMediaLoaderOptions = {
33 playlistUrl: string 35 playlistUrl: string
36 segmentsSha256Url: string
34 trackerAnnounce: string[] 37 trackerAnnounce: string[]
38 redundancyBaseUrls: string[]
39 videoFiles: VideoFile[]
35} 40}
36 41
37export type CommonOptions = { 42export type CommonOptions = {
@@ -90,11 +95,11 @@ export class PeertubePlayerManager {
90 static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions) { 95 static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions) {
91 let p2pMediaLoader: any 96 let p2pMediaLoader: any
92 97
93 if (mode === 'webtorrent') await import('./webtorrent-plugin') 98 if (mode === 'webtorrent') await import('./webtorrent/webtorrent-plugin')
94 if (mode === 'p2p-media-loader') { 99 if (mode === 'p2p-media-loader') {
95 [ p2pMediaLoader ] = await Promise.all([ 100 [ p2pMediaLoader ] = await Promise.all([
96 import('p2p-media-loader-hlsjs'), 101 import('p2p-media-loader-hlsjs'),
97 import('./p2p-media-loader-plugin') 102 import('./p2p-media-loader/p2p-media-loader-plugin')
98 ]) 103 ])
99 } 104 }
100 105
@@ -144,11 +149,14 @@ export class PeertubePlayerManager {
144 const commonOptions = options.common 149 const commonOptions = options.common
145 const webtorrentOptions = options.webtorrent 150 const webtorrentOptions = options.webtorrent
146 const p2pMediaLoaderOptions = options.p2pMediaLoader 151 const p2pMediaLoaderOptions = options.p2pMediaLoader
152
153 let autoplay = options.common.autoplay
147 let html5 = {} 154 let html5 = {}
148 155
149 const plugins: VideoJSPluginOptions = { 156 const plugins: VideoJSPluginOptions = {
150 peertube: { 157 peertube: {
151 autoplay: commonOptions.autoplay, // Use peertube plugin autoplay because we get the file by webtorrent 158 mode,
159 autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
152 videoViewUrl: commonOptions.videoViewUrl, 160 videoViewUrl: commonOptions.videoViewUrl,
153 videoDuration: commonOptions.videoDuration, 161 videoDuration: commonOptions.videoDuration,
154 startTime: commonOptions.startTime, 162 startTime: commonOptions.startTime,
@@ -160,19 +168,35 @@ export class PeertubePlayerManager {
160 168
161 if (p2pMediaLoaderOptions) { 169 if (p2pMediaLoaderOptions) {
162 const p2pMediaLoader: P2PMediaLoaderPluginOptions = { 170 const p2pMediaLoader: P2PMediaLoaderPluginOptions = {
171 redundancyBaseUrls: options.p2pMediaLoader.redundancyBaseUrls,
163 type: 'application/x-mpegURL', 172 type: 'application/x-mpegURL',
164 src: p2pMediaLoaderOptions.playlistUrl 173 src: p2pMediaLoaderOptions.playlistUrl
165 } 174 }
166 175
176 const trackerAnnounce = p2pMediaLoaderOptions.trackerAnnounce
177 .filter(t => t.startsWith('ws'))
178
167 const p2pMediaLoaderConfig = { 179 const p2pMediaLoaderConfig = {
168 // loader: { 180 loader: {
169 // trackerAnnounce: p2pMediaLoaderOptions.trackerAnnounce 181 trackerAnnounce,
170 // }, 182 segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url),
183 rtcConfig: getRtcConfig(),
184 requiredSegmentsPriority: 5,
185 segmentUrlBuilder: segmentUrlBuilderFactory(options.p2pMediaLoader.redundancyBaseUrls)
186 },
171 segments: { 187 segments: {
172 swarmId: p2pMediaLoaderOptions.playlistUrl 188 swarmId: p2pMediaLoaderOptions.playlistUrl
173 } 189 }
174 } 190 }
175 const streamrootHls = { 191 const streamrootHls = {
192 levelLabelHandler: (level: { height: number, width: number }) => {
193 const file = p2pMediaLoaderOptions.videoFiles.find(f => f.resolution.id === level.height)
194
195 let label = file.resolution.label
196 if (file.fps >= 50) label += file.fps
197
198 return label
199 },
176 html5: { 200 html5: {
177 hlsjsConfig: { 201 hlsjsConfig: {
178 liveSyncDurationCount: 7, 202 liveSyncDurationCount: 7,
@@ -187,12 +211,15 @@ export class PeertubePlayerManager {
187 211
188 if (webtorrentOptions) { 212 if (webtorrentOptions) {
189 const webtorrent = { 213 const webtorrent = {
190 autoplay: commonOptions.autoplay, 214 autoplay,
191 videoDuration: commonOptions.videoDuration, 215 videoDuration: commonOptions.videoDuration,
192 playerElement: commonOptions.playerElement, 216 playerElement: commonOptions.playerElement,
193 videoFiles: webtorrentOptions.videoFiles 217 videoFiles: webtorrentOptions.videoFiles
194 } 218 }
195 Object.assign(plugins, { webtorrent }) 219 Object.assign(plugins, { webtorrent })
220
221 // WebTorrent plugin handles autoplay, because we do some hackish stuff in there
222 autoplay = false
196 } 223 }
197 224
198 const videojsOptions = { 225 const videojsOptions = {
@@ -208,7 +235,7 @@ export class PeertubePlayerManager {
208 : undefined, // Undefined so the player knows it has to check the local storage 235 : undefined, // Undefined so the player knows it has to check the local storage
209 236
210 poster: commonOptions.poster, 237 poster: commonOptions.poster,
211 autoplay: false, 238 autoplay,
212 inactivityTimeout: commonOptions.inactivityTimeout, 239 inactivityTimeout: commonOptions.inactivityTimeout,
213 playbackRates: [ 0.5, 0.75, 1, 1.25, 1.5, 2 ], 240 playbackRates: [ 0.5, 0.75, 1, 1.25, 1.5, 2 ],
214 plugins, 241 plugins,