2017-05-03 10:04:16 +10:00
|
|
|
import React from 'react';
|
2017-04-13 23:04:18 +10:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-22 04:05:35 +10:00
|
|
|
import PropTypes from 'prop-types';
|
2019-05-04 00:16:30 +10:00
|
|
|
import Video from 'mastodon/features/video';
|
2017-05-03 10:04:16 +10:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2020-12-07 14:29:37 +11:00
|
|
|
import Footer from 'mastodon/features/picture_in_picture/components/footer';
|
|
|
|
import { getAverageFromBlurhash } from 'mastodon/blurhash';
|
2019-05-04 00:16:30 +10:00
|
|
|
|
|
|
|
export const previewState = 'previewVideoModal';
|
2017-04-13 23:04:18 +10:00
|
|
|
|
2017-06-24 03:36:54 +10:00
|
|
|
export default class VideoModal extends ImmutablePureComponent {
|
2017-04-13 23:04:18 +10:00
|
|
|
|
2017-05-12 22:44:10 +10:00
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
2020-11-27 13:24:11 +11:00
|
|
|
statusId: PropTypes.string,
|
2020-04-25 20:16:05 +10:00
|
|
|
options: PropTypes.shape({
|
|
|
|
startTime: PropTypes.number,
|
|
|
|
autoPlay: PropTypes.bool,
|
|
|
|
defaultVolume: PropTypes.number,
|
|
|
|
}),
|
2017-05-12 22:44:10 +10:00
|
|
|
onClose: PropTypes.func.isRequired,
|
2020-12-07 14:29:37 +11:00
|
|
|
onChangeBackgroundColor: PropTypes.func.isRequired,
|
2017-05-12 22:44:10 +10:00
|
|
|
};
|
|
|
|
|
2019-05-04 00:16:30 +10:00
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
2020-12-07 14:29:37 +11:00
|
|
|
const { router } = this.context;
|
|
|
|
const { media, onChangeBackgroundColor, onClose } = this.props;
|
2019-05-04 00:16:30 +10:00
|
|
|
|
2020-12-07 14:29:37 +11:00
|
|
|
if (router) {
|
|
|
|
router.history.push(router.history.location.pathname, previewState);
|
|
|
|
this.unlistenHistory = router.history.listen(() => onClose());
|
|
|
|
}
|
|
|
|
|
|
|
|
const backgroundColor = getAverageFromBlurhash(media.get('blurhash'));
|
2019-05-04 00:16:30 +10:00
|
|
|
|
2020-12-07 14:29:37 +11:00
|
|
|
if (backgroundColor) {
|
|
|
|
onChangeBackgroundColor(backgroundColor);
|
2019-05-04 00:16:30 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
2020-12-07 14:29:37 +11:00
|
|
|
const { router } = this.context;
|
|
|
|
|
|
|
|
if (router) {
|
2019-05-04 00:16:30 +10:00
|
|
|
this.unlistenHistory();
|
|
|
|
|
2020-12-07 14:29:37 +11:00
|
|
|
if (router.history.location.state === previewState) {
|
|
|
|
router.history.goBack();
|
2019-05-04 00:16:30 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-13 23:04:18 +10:00
|
|
|
render () {
|
2020-12-07 14:29:37 +11:00
|
|
|
const { media, statusId, onClose } = this.props;
|
2020-04-25 20:16:05 +10:00
|
|
|
const options = this.props.options || {};
|
2019-05-04 00:16:30 +10:00
|
|
|
|
2017-04-13 23:04:18 +10:00
|
|
|
return (
|
2018-03-05 06:32:24 +11:00
|
|
|
<div className='modal-root__modal video-modal'>
|
2019-10-03 11:34:58 +10:00
|
|
|
<div className='video-modal__container'>
|
2017-09-14 11:39:10 +10:00
|
|
|
<Video
|
|
|
|
preview={media.get('preview_url')}
|
2020-11-22 09:19:04 +11:00
|
|
|
frameRate={media.getIn(['meta', 'original', 'frame_rate'])}
|
2019-04-27 11:24:09 +10:00
|
|
|
blurhash={media.get('blurhash')}
|
2017-09-14 11:39:10 +10:00
|
|
|
src={media.get('url')}
|
2020-09-28 21:29:43 +10:00
|
|
|
currentTime={options.startTime}
|
2020-04-25 20:16:05 +10:00
|
|
|
autoPlay={options.autoPlay}
|
2020-09-28 21:29:43 +10:00
|
|
|
volume={options.defaultVolume}
|
2017-09-14 11:39:10 +10:00
|
|
|
onCloseVideo={onClose}
|
2017-12-09 10:55:58 +11:00
|
|
|
detailed
|
2018-09-14 04:31:59 +10:00
|
|
|
alt={media.get('description')}
|
2017-09-14 11:39:10 +10:00
|
|
|
/>
|
2017-04-13 23:04:18 +10:00
|
|
|
</div>
|
2020-12-07 14:29:37 +11:00
|
|
|
|
|
|
|
<div className='media-modal__overlay'>
|
|
|
|
{statusId && <Footer statusId={statusId} withOpenButton onClose={onClose} />}
|
|
|
|
</div>
|
2017-04-13 23:04:18 +10:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-22 04:05:35 +10:00
|
|
|
}
|