2020-09-28 04:29:43 -07:00
|
|
|
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';
|
2020-10-26 12:45:25 -07:00
|
|
|
import classNames from 'classnames';
|
2020-09-28 04:29:43 -07:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
...state.get('picture_in_picture'),
|
2020-10-26 12:45:25 -07:00
|
|
|
left: state.getIn(['local_settings', 'media', 'pop_in_position']) === 'left',
|
2020-09-28 04:29:43 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
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,
|
2020-10-26 12:45:25 -07:00
|
|
|
left: PropTypes.bool,
|
2020-09-28 04:29:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
handleClose = () => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
dispatch(removePictureInPicture());
|
2023-02-03 11:52:07 -08:00
|
|
|
};
|
2020-09-28 04:29:43 -07:00
|
|
|
|
|
|
|
render () {
|
2020-10-26 12:45:25 -07:00
|
|
|
const { type, src, currentTime, accountId, statusId, left } = this.props;
|
2020-09-28 04:29:43 -07:00
|
|
|
|
|
|
|
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 (
|
2020-10-26 12:45:25 -07:00
|
|
|
<div className={classNames('picture-in-picture', { left })}>
|
2020-09-28 04:29:43 -07:00
|
|
|
<Header accountId={accountId} statusId={statusId} onClose={this.handleClose} />
|
|
|
|
|
|
|
|
{player}
|
|
|
|
|
|
|
|
<Footer statusId={statusId} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-24 15:15:25 -07:00
|
|
|
|
|
|
|
export default connect(mapStateToProps)(PictureInPicture);
|