|
|
@ -2,7 +2,7 @@ import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import { is } from 'immutable';
|
|
|
|
import { is } from 'immutable';
|
|
|
|
import { throttle, debounce } from 'lodash';
|
|
|
|
import { throttle } from 'lodash';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen';
|
|
|
|
import { isFullscreen, requestFullscreen, exitFullscreen } from '../ui/util/fullscreen';
|
|
|
|
import { displayMedia, useBlurhash } from '../../initial_state';
|
|
|
|
import { displayMedia, useBlurhash } from '../../initial_state';
|
|
|
@ -102,8 +102,6 @@ class Video extends React.PureComponent {
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
src: PropTypes.string.isRequired,
|
|
|
|
alt: PropTypes.string,
|
|
|
|
alt: PropTypes.string,
|
|
|
|
lang: PropTypes.string,
|
|
|
|
lang: PropTypes.string,
|
|
|
|
width: PropTypes.number,
|
|
|
|
|
|
|
|
height: PropTypes.number,
|
|
|
|
|
|
|
|
sensitive: PropTypes.bool,
|
|
|
|
sensitive: PropTypes.bool,
|
|
|
|
currentTime: PropTypes.number,
|
|
|
|
currentTime: PropTypes.number,
|
|
|
|
onOpenVideo: PropTypes.func,
|
|
|
|
onOpenVideo: PropTypes.func,
|
|
|
@ -112,7 +110,6 @@ class Video extends React.PureComponent {
|
|
|
|
inline: PropTypes.bool,
|
|
|
|
inline: PropTypes.bool,
|
|
|
|
editable: PropTypes.bool,
|
|
|
|
editable: PropTypes.bool,
|
|
|
|
alwaysVisible: PropTypes.bool,
|
|
|
|
alwaysVisible: PropTypes.bool,
|
|
|
|
cacheWidth: PropTypes.func,
|
|
|
|
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
visible: PropTypes.bool,
|
|
|
|
onToggleVisibility: PropTypes.func,
|
|
|
|
onToggleVisibility: PropTypes.func,
|
|
|
|
deployPictureInPicture: PropTypes.func,
|
|
|
|
deployPictureInPicture: PropTypes.func,
|
|
|
@ -135,7 +132,6 @@ class Video extends React.PureComponent {
|
|
|
|
volume: 0.5,
|
|
|
|
volume: 0.5,
|
|
|
|
paused: true,
|
|
|
|
paused: true,
|
|
|
|
dragging: false,
|
|
|
|
dragging: false,
|
|
|
|
containerWidth: this.props.width,
|
|
|
|
|
|
|
|
fullscreen: false,
|
|
|
|
fullscreen: false,
|
|
|
|
hovered: false,
|
|
|
|
hovered: false,
|
|
|
|
muted: false,
|
|
|
|
muted: false,
|
|
|
@ -144,24 +140,8 @@ class Video extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
setPlayerRef = c => {
|
|
|
|
setPlayerRef = c => {
|
|
|
|
this.player = c;
|
|
|
|
this.player = c;
|
|
|
|
|
|
|
|
|
|
|
|
if (this.player) {
|
|
|
|
|
|
|
|
this._setDimensions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_setDimensions () {
|
|
|
|
|
|
|
|
const width = this.player.offsetWidth;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.cacheWidth) {
|
|
|
|
|
|
|
|
this.props.cacheWidth(width);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
containerWidth: width,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setVideoRef = c => {
|
|
|
|
setVideoRef = c => {
|
|
|
|
this.video = c;
|
|
|
|
this.video = c;
|
|
|
|
|
|
|
|
|
|
|
@ -370,12 +350,10 @@ class Video extends React.PureComponent {
|
|
|
|
document.addEventListener('MSFullscreenChange', this.handleFullscreenChange, true);
|
|
|
|
document.addEventListener('MSFullscreenChange', this.handleFullscreenChange, true);
|
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('scroll', this.handleScroll);
|
|
|
|
window.addEventListener('scroll', this.handleScroll);
|
|
|
|
window.addEventListener('resize', this.handleResize, { passive: true });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
componentWillUnmount () {
|
|
|
|
window.removeEventListener('scroll', this.handleScroll);
|
|
|
|
window.removeEventListener('scroll', this.handleScroll);
|
|
|
|
window.removeEventListener('resize', this.handleResize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.removeEventListener('fullscreenchange', this.handleFullscreenChange, true);
|
|
|
|
document.removeEventListener('fullscreenchange', this.handleFullscreenChange, true);
|
|
|
|
document.removeEventListener('webkitfullscreenchange', this.handleFullscreenChange, true);
|
|
|
|
document.removeEventListener('webkitfullscreenchange', this.handleFullscreenChange, true);
|
|
|
@ -404,14 +382,6 @@ class Video extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleResize = debounce(() => {
|
|
|
|
|
|
|
|
if (this.player) {
|
|
|
|
|
|
|
|
this._setDimensions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 250, {
|
|
|
|
|
|
|
|
trailing: true,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleScroll = throttle(() => {
|
|
|
|
handleScroll = throttle(() => {
|
|
|
|
if (!this.video) {
|
|
|
|
if (!this.video) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -525,17 +495,12 @@ class Video extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const { preview, src, inline, onOpenVideo, onCloseVideo, intl, alt, lang, detailed, sensitive, editable, blurhash, autoFocus } = this.props;
|
|
|
|
const { preview, src, inline, onOpenVideo, onCloseVideo, intl, alt, lang, detailed, sensitive, editable, blurhash, autoFocus } = this.props;
|
|
|
|
const { containerWidth, currentTime, duration, volume, buffer, dragging, paused, fullscreen, hovered, muted, revealed } = this.state;
|
|
|
|
const { currentTime, duration, volume, buffer, dragging, paused, fullscreen, hovered, muted, revealed } = this.state;
|
|
|
|
const progress = Math.min((currentTime / duration) * 100, 100);
|
|
|
|
const progress = Math.min((currentTime / duration) * 100, 100);
|
|
|
|
const playerStyle = {};
|
|
|
|
const playerStyle = {};
|
|
|
|
|
|
|
|
|
|
|
|
let { width, height } = this.props;
|
|
|
|
if (inline) {
|
|
|
|
|
|
|
|
playerStyle.aspectRatio = '16 / 9';
|
|
|
|
if (inline && containerWidth) {
|
|
|
|
|
|
|
|
width = containerWidth;
|
|
|
|
|
|
|
|
height = containerWidth / (16/9);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerStyle.height = height;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let preload;
|
|
|
|
let preload;
|
|
|
@ -586,8 +551,6 @@ class Video extends React.PureComponent {
|
|
|
|
aria-label={alt}
|
|
|
|
aria-label={alt}
|
|
|
|
title={alt}
|
|
|
|
title={alt}
|
|
|
|
lang={lang}
|
|
|
|
lang={lang}
|
|
|
|
width={width}
|
|
|
|
|
|
|
|
height={height}
|
|
|
|
|
|
|
|
volume={volume}
|
|
|
|
volume={volume}
|
|
|
|
onClick={this.togglePlay}
|
|
|
|
onClick={this.togglePlay}
|
|
|
|
onKeyDown={this.handleVideoKeyDown}
|
|
|
|
onKeyDown={this.handleVideoKeyDown}
|
|
|
@ -596,6 +559,7 @@ class Video extends React.PureComponent {
|
|
|
|
onLoadedData={this.handleLoadedData}
|
|
|
|
onLoadedData={this.handleLoadedData}
|
|
|
|
onProgress={this.handleProgress}
|
|
|
|
onProgress={this.handleProgress}
|
|
|
|
onVolumeChange={this.handleVolumeChange}
|
|
|
|
onVolumeChange={this.handleVolumeChange}
|
|
|
|
|
|
|
|
style={{ ...playerStyle, width: '100%' }}
|
|
|
|
/>}
|
|
|
|
/>}
|
|
|
|
|
|
|
|
|
|
|
|
<div className={classNames('spoiler-button', { 'spoiler-button--hidden': revealed || editable })}>
|
|
|
|
<div className={classNames('spoiler-button', { 'spoiler-button--hidden': revealed || editable })}>
|
|
|
|