index.js 2.1 KB

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