VideoJSPluginOptions
} from './peertube-videojs-typings'
import { TranslationsManager } from './translations-manager'
-import { buildVideoOrPlaylistEmbed, buildVideoLink, copyToClipboard, getRtcConfig, isSafari, isIOS } from './utils'
+import { buildVideoOrPlaylistEmbed, buildVideoLink, getRtcConfig, isSafari, isIOS } from './utils'
+import { copyToClipboard } from '../../root-helpers/utils'
// Change 'Playback Rate' to 'Speed' (smaller for our settings menu)
(videojs.getComponent('PlaybackRateMenuButton') as any).prototype.controlText_ = 'Speed'
videoViewUrl: string
embedUrl: string
+ embedTitle: string
+
+ isLive: boolean
language?: string
private static alreadyPlayed = false
+ static initState () {
+ PeertubePlayerManager.alreadyPlayed = false
+ }
+
static async initialize (mode: PlayerMode, options: PeertubePlayerManagerOptions, onPlayerChange: (player: videojs.Player) => void) {
let p2pMediaLoader: any
PeertubePlayerManager.alreadyPlayed = true
})
- self.addContextMenu(mode, player, options.common.embedUrl)
+ self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
player.bezels()
videojs(newVideoElement, videojsOptions, function (this: videojs.Player) {
const player = this
- self.addContextMenu(mode, player, options.common.embedUrl)
+ self.addContextMenu(mode, player, options.common.embedUrl, options.common.embedTitle)
PeertubePlayerManager.onPlayerChange(player)
})
const plugins: VideoJSPluginOptions = {
peertube: {
mode,
- autoplay, // Use peertube plugin autoplay because we get the file by webtorrent
+ autoplay, // Use peertube plugin autoplay because we could get the file by webtorrent
videoViewUrl: commonOptions.videoViewUrl,
videoDuration: commonOptions.videoDuration,
userWatching: commonOptions.userWatching,
subtitle: commonOptions.subtitle,
videoCaptions: commonOptions.videoCaptions,
- stopTime: commonOptions.stopTime
+ stopTime: commonOptions.stopTime,
+ isLive: commonOptions.isLive
}
}
poster: commonOptions.poster,
inactivityTimeout: commonOptions.inactivityTimeout,
- playbackRates: [ 0.5, 0.75, 1, 1.25, 1.5, 2 ],
+ playbackRates: [ 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2 ],
plugins,
const p2pMediaLoaderConfig = {
loader: {
trackerAnnounce,
- segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url),
+ segmentValidator: segmentValidatorFactory(options.p2pMediaLoader.segmentsSha256Url, options.common.isLive),
rtcConfig: getRtcConfig(),
- requiredSegmentsPriority: 5,
+ requiredSegmentsPriority: 1,
segmentUrlBuilder: segmentUrlBuilderFactory(redundancyUrlManager),
useP2P: getStoredP2PEnabled(),
consumeOnly
const resolution = Math.min(level.height || 0, level.width || 0)
const file = p2pMediaLoaderOptions.videoFiles.find(f => f.resolution.id === resolution)
- if (!file) {
- console.error('Cannot find video file for level %d.', level.height)
- return level.height
- }
+ // 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
hlsjsConfig: {
capLevelToPlayerSize: true,
autoStartLoad: false,
- liveSyncDurationCount: 7,
+ liveSyncDurationCount: 5,
loader: new p2pMediaLoaderModule.Engine(p2pMediaLoaderConfig).createLoaderClass()
}
}
const commonOptions = options.common
const webtorrentOptions = options.webtorrent
+ const autoplay = this.getAutoPlayValue(commonOptions.autoplay) === 'play'
+ ? true
+ : false
+
const webtorrent = {
- autoplay: commonOptions.autoplay,
+ autoplay,
videoDuration: commonOptions.videoDuration,
playerElement: commonOptions.playerElement,
videoFiles: webtorrentOptions.videoFiles,
return children
}
- private static addContextMenu (mode: PlayerMode, player: videojs.Player, videoEmbedUrl: string) {
+ private static addContextMenu (mode: PlayerMode, player: videojs.Player, videoEmbedUrl: string, videoEmbedTitle: string) {
const content = [
{
label: player.localize('Copy the video URL'),
{
label: player.localize('Copy embed code'),
listener: () => {
- copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl))
+ copyToClipboard(buildVideoOrPlaylistEmbed(videoEmbedUrl, videoEmbedTitle))
}
}
]
}
private static addHotkeysOptions (plugins: VideoJSPluginOptions) {
+ const isNaked = (event: KeyboardEvent, key: string) =>
+ (!event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && event.key === key)
+
Object.assign(plugins, {
hotkeys: {
skipInitialFocus: true,
enableVolumeScroll: false,
enableModifiersForNumbers: false,
- fullscreenKey: function (event: KeyboardEvent) {
- // fullscreen with the f key or Ctrl+Enter
- return event.key === 'f' || (event.ctrlKey && event.key === 'Enter')
+ rewindKey: function (event: KeyboardEvent) {
+ return isNaked(event, 'ArrowLeft')
},
- seekStep: function (event: KeyboardEvent) {
- // mimic VLC seek behavior, and default to 5 (original value is 5).
- if (event.ctrlKey && event.altKey) {
- return 5 * 60
- } else if (event.ctrlKey) {
- return 60
- } else if (event.altKey) {
- return 10
- } else {
- return 5
- }
+ forwardKey: function (event: KeyboardEvent) {
+ return isNaked(event, 'ArrowRight')
+ },
+
+ fullscreenKey: function (event: KeyboardEvent) {
+ // fullscreen with the f key or Ctrl+Enter
+ return isNaked(event, 'f') || (!event.altKey && event.ctrlKey && event.key === 'Enter')
},
customKeys: {
increasePlaybackRateKey: {
key: function (event: KeyboardEvent) {
- return event.key === '>'
+ return isNaked(event, '>')
},
handler: function (player: videojs.Player) {
const newValue = Math.min(player.playbackRate() + 0.1, 5)
},
decreasePlaybackRateKey: {
key: function (event: KeyboardEvent) {
- return event.key === '<'
+ return isNaked(event, '<')
},
handler: function (player: videojs.Player) {
const newValue = Math.max(player.playbackRate() - 0.1, 0.10)
},
frameByFrame: {
key: function (event: KeyboardEvent) {
- return event.key === '.'
+ return isNaked(event, '.')
},
handler: function (player: videojs.Player) {
player.pause()
private static getAutoPlayValue (autoplay: any) {
if (autoplay !== true) return autoplay
- // We have issues with autoplay and Safari with webtorrent
- if (isIOS()) {
- // On first play, disable autoplay to avoid issues
- // But if the player already played videos, we can safely autoplay next ones
- return PeertubePlayerManager.alreadyPlayed ? 'play' : false
- } else if (isSafari()) {
- // Issues with Safari and webtorrent on first play
+ // On first play, disable autoplay to avoid issues
+ // But if the player already played videos, we can safely autoplay next ones
+ if (isIOS() || isSafari()) {
return PeertubePlayerManager.alreadyPlayed ? 'play' : false
}