bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/media/component.jsx
2019-11-25 13:38:00 -03:00

136 lines
3.3 KiB
JavaScript

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import WebcamDraggable from './webcam-draggable-overlay/component';
import { styles } from './styles';
const propTypes = {
children: PropTypes.element.isRequired,
usersVideo: PropTypes.arrayOf(Array),
singleWebcam: PropTypes.bool.isRequired,
hideOverlay: PropTypes.bool,
swapLayout: PropTypes.bool,
disableVideo: PropTypes.bool,
userWasInWebcam: PropTypes.bool,
audioModalIsOpen: PropTypes.bool,
joinVideo: PropTypes.func,
webcamPlacement: PropTypes.string,
};
const defaultProps = {
usersVideo: [],
hideOverlay: true,
swapLayout: false,
disableVideo: false,
userWasInWebcam: false,
audioModalIsOpen: false,
joinVideo: null,
webcamPlacement: 'top',
};
export default class Media extends Component {
constructor(props) {
super(props);
this.refContainer = React.createRef();
}
componentWillUpdate() {
window.dispatchEvent(new Event('resize'));
}
componentDidUpdate(prevProps) {
const {
userWasInWebcam,
audioModalIsOpen,
joinVideo,
} = this.props;
const {
audioModalIsOpen: oldAudioModalIsOpen,
} = prevProps;
if ((!audioModalIsOpen && oldAudioModalIsOpen) && userWasInWebcam) {
Session.set('userWasInWebcam', false);
joinVideo();
}
}
render() {
const {
swapLayout,
singleWebcam,
hideOverlay,
disableVideo,
children,
audioModalIsOpen,
usersVideo,
webcamPlacement,
} = this.props;
console.log('Storage.getItemwebcamPlacement', webcamPlacement);
const contentClassName = cx({
[styles.content]: true,
});
const overlayClassName = cx({
[styles.overlay]: true,
[styles.hideOverlay]: hideOverlay,
[styles.floatingOverlay]: (webcamPlacement === 'floating'),
});
const containerClassName = cx({
[styles.containerV]: webcamPlacement === 'top' || webcamPlacement === 'bottom' || webcamPlacement === 'floating',
[styles.containerH]: webcamPlacement === 'left' || webcamPlacement === 'right',
});
return (
<div
id="container"
className={containerClassName}
ref={this.refContainer}
>
<div
className={!swapLayout ? contentClassName : overlayClassName}
style={{
maxHeight: (
webcamPlacement === 'left'
|| webcamPlacement === 'right'
|| webcamPlacement === 'floating'
)
? '100%'
: '80%',
minHeight: '20%',
maxWidth: (
webcamPlacement === 'top'
|| webcamPlacement === 'bottom'
|| webcamPlacement === 'floating'
)
? '100%'
: '80%',
minWidth: '20%',
}}
>
{children}
</div>
<WebcamDraggable
refMediaContainer={this.refContainer}
swapLayout={swapLayout}
singleWebcam={singleWebcam}
usersVideoLenght={usersVideo.length}
hideOverlay={hideOverlay}
disableVideo={disableVideo}
audioModalIsOpen={audioModalIsOpen}
usersVideo={usersVideo}
/>
</div>
);
}
}
Media.propTypes = propTypes;
Media.defaultProps = defaultProps;