about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/picture_in_picture/index.jsx
blob: e6fb64ff99e00a1d3ce1fe203dba5ff4434852b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import Video from 'flavours/glitch/features/video';
import Audio from 'flavours/glitch/features/audio';
import { removePictureInPicture } from 'flavours/glitch/actions/picture_in_picture';
import Header from './components/header';
import Footer from './components/footer';
import classNames from 'classnames';

const mapStateToProps = state => ({
  ...state.get('picture_in_picture'),
  left: state.getIn(['local_settings', 'media', 'pop_in_position']) === 'left',
});

class PictureInPicture extends React.Component {

  static propTypes = {
    statusId: PropTypes.string,
    accountId: PropTypes.string,
    type: PropTypes.string,
    src: PropTypes.string,
    muted: PropTypes.bool,
    volume: PropTypes.number,
    currentTime: PropTypes.number,
    poster: PropTypes.string,
    backgroundColor: PropTypes.string,
    foregroundColor: PropTypes.string,
    accentColor: PropTypes.string,
    dispatch: PropTypes.func.isRequired,
    left: PropTypes.bool,
  };

  handleClose = () => {
    const { dispatch } = this.props;
    dispatch(removePictureInPicture());
  };

  render () {
    const { type, src, currentTime, accountId, statusId, left } = this.props;

    if (!currentTime) {
      return null;
    }

    let player;

    if (type === 'video') {
      player = (
        <Video
          src={src}
          currentTime={this.props.currentTime}
          volume={this.props.volume}
          muted={this.props.muted}
          autoPlay
          inline
          alwaysVisible
        />
      );
    } else if (type === 'audio') {
      player = (
        <Audio
          src={src}
          currentTime={this.props.currentTime}
          volume={this.props.volume}
          muted={this.props.muted}
          poster={this.props.poster}
          backgroundColor={this.props.backgroundColor}
          foregroundColor={this.props.foregroundColor}
          accentColor={this.props.accentColor}
          autoPlay
        />
      );
    }

    return (
      <div className={classNames('picture-in-picture', { left })}>
        <Header accountId={accountId} statusId={statusId} onClose={this.handleClose} />

        {player}

        <Footer statusId={statusId} />
      </div>
    );
  }

}

export default connect(mapStateToProps)(PictureInPicture);