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.

86 lines
2.1 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import Video from 'mastodon/features/video';
  5. import Audio from 'mastodon/features/audio';
  6. import { removePictureInPicture } from 'mastodon/actions/picture_in_picture';
  7. import Header from './components/header';
  8. import Footer from './components/footer';
  9. const mapStateToProps = state => ({
  10. ...state.get('picture_in_picture'),
  11. });
  12. class PictureInPicture extends React.Component {
  13. static propTypes = {
  14. statusId: PropTypes.string,
  15. accountId: PropTypes.string,
  16. type: PropTypes.string,
  17. src: PropTypes.string,
  18. muted: PropTypes.bool,
  19. volume: PropTypes.number,
  20. currentTime: PropTypes.number,
  21. poster: PropTypes.string,
  22. backgroundColor: PropTypes.string,
  23. foregroundColor: PropTypes.string,
  24. accentColor: PropTypes.string,
  25. dispatch: PropTypes.func.isRequired,
  26. };
  27. handleClose = () => {
  28. const { dispatch } = this.props;
  29. dispatch(removePictureInPicture());
  30. };
  31. render () {
  32. const { type, src, currentTime, accountId, statusId } = this.props;
  33. if (!currentTime) {
  34. return null;
  35. }
  36. let player;
  37. if (type === 'video') {
  38. player = (
  39. <Video
  40. src={src}
  41. currentTime={this.props.currentTime}
  42. volume={this.props.volume}
  43. muted={this.props.muted}
  44. autoPlay
  45. inline
  46. alwaysVisible
  47. />
  48. );
  49. } else if (type === 'audio') {
  50. player = (
  51. <Audio
  52. src={src}
  53. currentTime={this.props.currentTime}
  54. volume={this.props.volume}
  55. muted={this.props.muted}
  56. poster={this.props.poster}
  57. backgroundColor={this.props.backgroundColor}
  58. foregroundColor={this.props.foregroundColor}
  59. accentColor={this.props.accentColor}
  60. autoPlay
  61. />
  62. );
  63. }
  64. return (
  65. <div className='picture-in-picture'>
  66. <Header accountId={accountId} statusId={statusId} onClose={this.handleClose} />
  67. {player}
  68. <Footer statusId={statusId} />
  69. </div>
  70. );
  71. }
  72. }
  73. export default connect(mapStateToProps)(PictureInPicture);