videoFiles: VideoFile[]
}
-export type CommonOptions = {
+export interface CustomizationOptions {
+ startTime: number | string
+ stopTime: number | string
+
+ controls?: boolean
+ muted?: boolean
+ loop?: boolean
+ subtitle?: string
+
+ peertubeLink: boolean
+}
+
+export interface CommonOptions extends CustomizationOptions {
playerElement: HTMLVideoElement
onPlayerElementChange: (element: HTMLVideoElement) => void
enableHotkeys: boolean
inactivityTimeout: number
poster: string
- startTime: number | string
theaterMode: boolean
captions: boolean
- peertubeLink: boolean
videoViewUrl: string
embedUrl: string
language?: string
- controls?: boolean
- muted?: boolean
- loop?: boolean
- subtitle?: string
videoCaptions: VideoJSCaption[]
videojs(options.common.playerElement, videojsOptions, function (this: any) {
const player = this
- player.tech_.on('error', () => {
- // Fallback to webtorrent?
- if (mode === 'p2p-media-loader') {
- self.fallbackToWebTorrent(player, options)
- }
+ let alreadyFallback = false
+
+ player.tech_.one('error', () => {
+ if (!alreadyFallback) self.maybeFallbackToWebTorrent(mode, player, options)
+ alreadyFallback = true
+ })
+
+ player.one('error', () => {
+ if (!alreadyFallback) self.maybeFallbackToWebTorrent(mode, player, options)
+ alreadyFallback = true
})
self.addContextMenu(mode, player, options.common.embedUrl)
})
}
- private static async fallbackToWebTorrent (player: any, options: PeertubePlayerManagerOptions) {
+ private static async maybeFallbackToWebTorrent (currentMode: PlayerMode, player: any, options: PeertubePlayerManagerOptions) {
+ if (currentMode === 'webtorrent') return
+
+ console.log('Fallback to webtorrent.')
+
const newVideoElement = document.createElement('video')
newVideoElement.className = this.playerElementClassName
// VideoJS wraps our video element inside a div
- const currentParentPlayerElement = options.common.playerElement.parentNode
+ let currentParentPlayerElement = options.common.playerElement.parentNode
+ // Fix on IOS, don't ask me why
+ if (!currentParentPlayerElement) currentParentPlayerElement = document.getElementById(options.common.playerElement.id).parentNode
+
currentParentPlayerElement.parentNode.insertBefore(newVideoElement, currentParentPlayerElement)
options.common.playerElement = newVideoElement
autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
videoViewUrl: commonOptions.videoViewUrl,
videoDuration: commonOptions.videoDuration,
- startTime: commonOptions.startTime,
userWatching: commonOptions.userWatching,
subtitle: commonOptions.subtitle,
- videoCaptions: commonOptions.videoCaptions
+ videoCaptions: commonOptions.videoCaptions,
+ stopTime: commonOptions.stopTime
}
}
const p2pMediaLoader: P2PMediaLoaderPluginOptions = {
redundancyBaseUrls: options.p2pMediaLoader.redundancyBaseUrls,
type: 'application/x-mpegURL',
+ startTime: commonOptions.startTime,
src: p2pMediaLoaderOptions.playlistUrl
}
autoplay,
videoDuration: commonOptions.videoDuration,
playerElement: commonOptions.playerElement,
- videoFiles: webtorrentOptions.videoFiles
+ videoFiles: webtorrentOptions.videoFiles,
+ startTime: commonOptions.startTime
}
Object.assign(plugins, { webtorrent })