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.

89 lines
2.3 KiB

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