|
|
@ -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 'flavours/glitch/initial_state';
|
|
|
|
import { displayMedia, useBlurhash } from 'flavours/glitch/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,
|
|
|
|
letterbox: PropTypes.bool,
|
|
|
|
letterbox: PropTypes.bool,
|
|
|
|
fullwidth: PropTypes.bool,
|
|
|
|
fullwidth: PropTypes.bool,
|
|
|
@ -138,41 +135,16 @@ 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,
|
|
|
|
revealed: this.props.visible !== undefined ? this.props.visible : (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all'),
|
|
|
|
revealed: this.props.visible !== undefined ? this.props.visible : (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all'),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
|
|
|
|
if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
|
|
|
|
|
|
|
|
this.setState({ revealed: nextProps.visible });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPlayerRef = c => {
|
|
|
|
setPlayerRef = c => {
|
|
|
|
this.player = c;
|
|
|
|
this.player = c;
|
|
|
|
|
|
|
|
|
|
|
|
if (this.player) {
|
|
|
|
|
|
|
|
this._setDimensions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_setDimensions () {
|
|
|
|
|
|
|
|
const width = this.player.offsetWidth;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (width && width !== this.state.containerWidth) {
|
|
|
|
|
|
|
|
if (this.props.cacheWidth) {
|
|
|
|
|
|
|
|
this.props.cacheWidth(width);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
containerWidth: width,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setVideoRef = c => {
|
|
|
|
setVideoRef = c => {
|
|
|
|
this.video = c;
|
|
|
|
this.video = c;
|
|
|
|
|
|
|
|
|
|
|
@ -381,12 +353,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);
|
|
|
@ -403,26 +373,18 @@ class Video extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (this.player && this.player.offsetWidth && this.player.offsetWidth !== this.state.containerWidth && !this.state.fullscreen) {
|
|
|
|
if (!is(nextProps.visible, this.props.visible) && nextProps.visible !== undefined) {
|
|
|
|
if (this.props.cacheWidth) this.props.cacheWidth(this.player.offsetWidth);
|
|
|
|
this.setState({ revealed: nextProps.visible });
|
|
|
|
this.setState({
|
|
|
|
|
|
|
|
containerWidth: this.player.offsetWidth,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
if (this.video && this.state.revealed && this.props.preventPlayback && !prevProps.preventPlayback) {
|
|
|
|
if (this.video && this.state.revealed && this.props.preventPlayback && !prevProps.preventPlayback) {
|
|
|
|
this.video.pause();
|
|
|
|
this.video.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleResize = debounce(() => {
|
|
|
|
|
|
|
|
if (this.player) {
|
|
|
|
|
|
|
|
this._setDimensions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}, 250, {
|
|
|
|
|
|
|
|
trailing: true,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleScroll = throttle(() => {
|
|
|
|
handleScroll = throttle(() => {
|
|
|
|
if (!this.video) {
|
|
|
|
if (!this.video) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -540,21 +502,12 @@ class Video extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const { preview, src, inline, onOpenVideo, onCloseVideo, intl, alt, lang, letterbox, fullwidth, detailed, sensitive, editable, blurhash, autoFocus } = this.props;
|
|
|
|
const { preview, src, inline, onOpenVideo, onCloseVideo, intl, alt, lang, letterbox, fullwidth, 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 = {};
|
|
|
|
|
|
|
|
|
|
|
|
const computedClass = classNames('video-player', { inactive: !revealed, detailed, inline: inline && !fullscreen, fullscreen, editable, letterbox, 'full-width': fullwidth });
|
|
|
|
if (inline) {
|
|
|
|
|
|
|
|
playerStyle.aspectRatio = '16 / 9';
|
|
|
|
let { width, height } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (inline && containerWidth) {
|
|
|
|
|
|
|
|
width = containerWidth;
|
|
|
|
|
|
|
|
height = containerWidth / (16/9);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerStyle.height = height;
|
|
|
|
|
|
|
|
} else if (inline) {
|
|
|
|
|
|
|
|
return (<div className={computedClass} ref={this.setPlayerRef} tabIndex={0} />);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let preload;
|
|
|
|
let preload;
|
|
|
@ -578,7 +531,7 @@ class Video extends React.PureComponent {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|
role='menuitem'
|
|
|
|
role='menuitem'
|
|
|
|
className={computedClass}
|
|
|
|
className={classNames('video-player', { inactive: !revealed, detailed, inline: inline && !fullscreen, fullscreen, editable, letterbox, 'full-width': fullwidth })}
|
|
|
|
style={playerStyle}
|
|
|
|
style={playerStyle}
|
|
|
|
ref={this.setPlayerRef}
|
|
|
|
ref={this.setPlayerRef}
|
|
|
|
onMouseEnter={this.handleMouseEnter}
|
|
|
|
onMouseEnter={this.handleMouseEnter}
|
|
|
@ -605,8 +558,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}
|
|
|
@ -615,6 +566,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 })}>
|
|
|
|