2017-04-21 20:05:35 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 17:15:17 +02:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-05-03 02:04:16 +02:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-23 17:15:17 +02:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2020-12-07 04:29:37 +01:00
|
|
|
import { getAverageFromBlurhash } from 'mastodon/blurhash';
|
2023-05-23 17:15:17 +02:00
|
|
|
import Footer from 'mastodon/features/picture_in_picture/components/footer';
|
|
|
|
import Video from 'mastodon/features/video';
|
2019-05-03 16:16:30 +02:00
|
|
|
|
2023-02-26 20:13:27 +01:00
|
|
|
const mapStateToProps = (state, { statusId }) => ({
|
2023-06-01 00:10:21 +02:00
|
|
|
status: state.getIn(['statuses', statusId]),
|
2023-02-26 20:13:27 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
class VideoModal extends ImmutablePureComponent {
|
2017-04-13 15:04:18 +02:00
|
|
|
|
2017-05-12 14:44:10 +02:00
|
|
|
static propTypes = {
|
|
|
|
media: ImmutablePropTypes.map.isRequired,
|
2020-11-27 03:24:11 +01:00
|
|
|
statusId: PropTypes.string,
|
2023-06-01 00:10:21 +02:00
|
|
|
status: ImmutablePropTypes.map,
|
2020-04-25 12:16:05 +02:00
|
|
|
options: PropTypes.shape({
|
|
|
|
startTime: PropTypes.number,
|
|
|
|
autoPlay: PropTypes.bool,
|
|
|
|
defaultVolume: PropTypes.number,
|
|
|
|
}),
|
2017-05-12 14:44:10 +02:00
|
|
|
onClose: PropTypes.func.isRequired,
|
2020-12-07 04:29:37 +01:00
|
|
|
onChangeBackgroundColor: PropTypes.func.isRequired,
|
2017-05-12 14:44:10 +02:00
|
|
|
};
|
|
|
|
|
2019-05-03 16:16:30 +02:00
|
|
|
componentDidMount () {
|
2021-07-14 05:36:23 +02:00
|
|
|
const { media, onChangeBackgroundColor } = this.props;
|
2019-05-03 16:16:30 +02:00
|
|
|
|
2020-12-07 04:29:37 +01:00
|
|
|
const backgroundColor = getAverageFromBlurhash(media.get('blurhash'));
|
2019-05-03 16:16:30 +02:00
|
|
|
|
2020-12-07 04:29:37 +01:00
|
|
|
if (backgroundColor) {
|
|
|
|
onChangeBackgroundColor(backgroundColor);
|
2019-05-03 16:16:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:04:18 +02:00
|
|
|
render () {
|
2023-06-01 00:10:21 +02:00
|
|
|
const { media, status, onClose } = this.props;
|
2020-04-25 12:16:05 +02:00
|
|
|
const options = this.props.options || {};
|
2023-06-01 00:10:21 +02:00
|
|
|
const language = status.getIn(['translation', 'language']) || status.get('language');
|
|
|
|
const description = media.getIn(['translation', 'description']) || media.get('description');
|
2019-05-03 16:16:30 +02:00
|
|
|
|
2017-04-13 15:04:18 +02:00
|
|
|
return (
|
2018-03-04 20:32:24 +01:00
|
|
|
<div className='modal-root__modal video-modal'>
|
2019-10-03 03:34:58 +02:00
|
|
|
<div className='video-modal__container'>
|
2017-09-14 03:39:10 +02:00
|
|
|
<Video
|
|
|
|
preview={media.get('preview_url')}
|
2020-11-21 23:19:04 +01:00
|
|
|
frameRate={media.getIn(['meta', 'original', 'frame_rate'])}
|
2023-07-24 13:46:55 +02:00
|
|
|
aspectRatio={`${media.getIn(['meta', 'original', 'width'])} / ${media.getIn(['meta', 'original', 'height'])}`}
|
2019-04-27 03:24:09 +02:00
|
|
|
blurhash={media.get('blurhash')}
|
2017-09-14 03:39:10 +02:00
|
|
|
src={media.get('url')}
|
2020-09-28 13:29:43 +02:00
|
|
|
currentTime={options.startTime}
|
2020-04-25 12:16:05 +02:00
|
|
|
autoPlay={options.autoPlay}
|
2020-09-28 13:29:43 +02:00
|
|
|
volume={options.defaultVolume}
|
2017-09-14 03:39:10 +02:00
|
|
|
onCloseVideo={onClose}
|
2023-01-09 03:52:37 +01:00
|
|
|
autoFocus
|
2017-12-09 00:55:58 +01:00
|
|
|
detailed
|
2023-06-01 00:10:21 +02:00
|
|
|
alt={description}
|
2023-02-26 20:13:27 +01:00
|
|
|
lang={language}
|
2017-09-14 03:39:10 +02:00
|
|
|
/>
|
2017-04-13 15:04:18 +02:00
|
|
|
</div>
|
2020-12-07 04:29:37 +01:00
|
|
|
|
|
|
|
<div className='media-modal__overlay'>
|
2023-06-01 00:10:21 +02:00
|
|
|
{status && <Footer statusId={status.get('id')} withOpenButton onClose={onClose} />}
|
2020-12-07 04:29:37 +01:00
|
|
|
</div>
|
2017-04-13 15:04:18 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 20:05:35 +02:00
|
|
|
}
|
2023-03-24 03:17:53 +01:00
|
|
|
|
|
|
|
export default connect(mapStateToProps, null, null, { forwardRef: true })(VideoModal);
|