You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.9 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import Video from 'mastodon/features/video';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import Footer from 'mastodon/features/picture_in_picture/components/footer';
  7. import { getAverageFromBlurhash } from 'mastodon/blurhash';
  8. export default class VideoModal extends ImmutablePureComponent {
  9. static propTypes = {
  10. media: ImmutablePropTypes.map.isRequired,
  11. statusId: PropTypes.string,
  12. options: PropTypes.shape({
  13. startTime: PropTypes.number,
  14. autoPlay: PropTypes.bool,
  15. defaultVolume: PropTypes.number,
  16. }),
  17. onClose: PropTypes.func.isRequired,
  18. onChangeBackgroundColor: PropTypes.func.isRequired,
  19. };
  20. componentDidMount () {
  21. const { media, onChangeBackgroundColor, onClose } = this.props;
  22. const backgroundColor = getAverageFromBlurhash(media.get('blurhash'));
  23. if (backgroundColor) {
  24. onChangeBackgroundColor(backgroundColor);
  25. }
  26. }
  27. render () {
  28. const { media, statusId, onClose } = this.props;
  29. const options = this.props.options || {};
  30. return (
  31. <div className='modal-root__modal video-modal'>
  32. <div className='video-modal__container'>
  33. <Video
  34. preview={media.get('preview_url')}
  35. frameRate={media.getIn(['meta', 'original', 'frame_rate'])}
  36. blurhash={media.get('blurhash')}
  37. src={media.get('url')}
  38. currentTime={options.startTime}
  39. autoPlay={options.autoPlay}
  40. volume={options.defaultVolume}
  41. onCloseVideo={onClose}
  42. detailed
  43. alt={media.get('description')}
  44. />
  45. </div>
  46. <div className='media-modal__overlay'>
  47. {statusId && <Footer statusId={statusId} withOpenButton onClose={onClose} />}
  48. </div>
  49. </div>
  50. );
  51. }
  52. }