2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-04-10 02:28:54 +08:00
|
|
|
import cx from 'classnames';
|
2020-01-14 04:05:30 +08:00
|
|
|
import { isMobile, isIPad13 } from 'react-device-detect';
|
2019-07-10 07:11:48 +08:00
|
|
|
import WebcamDraggable from './webcam-draggable-overlay/component';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles';
|
2020-01-24 02:09:39 +08:00
|
|
|
import Storage from '../../services/storage/session';
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2020-01-14 04:05:30 +08:00
|
|
|
const BROWSER_ISMOBILE = isMobile || isIPad13;
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
const propTypes = {
|
2018-04-12 02:50:14 +08:00
|
|
|
children: PropTypes.element.isRequired,
|
2019-07-24 06:24:31 +08:00
|
|
|
usersVideo: PropTypes.arrayOf(Array),
|
2019-11-05 03:57:29 +08:00
|
|
|
singleWebcam: PropTypes.bool.isRequired,
|
2018-04-10 02:28:54 +08:00
|
|
|
hideOverlay: PropTypes.bool,
|
2019-07-24 06:24:31 +08:00
|
|
|
swapLayout: PropTypes.bool,
|
|
|
|
disableVideo: PropTypes.bool,
|
|
|
|
audioModalIsOpen: PropTypes.bool,
|
2020-07-16 00:44:59 +08:00
|
|
|
webcamDraggableState: PropTypes.instanceOf(Object).isRequired,
|
2016-05-04 04:40:46 +08:00
|
|
|
};
|
2016-05-03 06:42:54 +08:00
|
|
|
|
2017-10-11 06:08:51 +08:00
|
|
|
const defaultProps = {
|
2019-07-24 06:24:31 +08:00
|
|
|
usersVideo: [],
|
2018-04-10 02:28:54 +08:00
|
|
|
hideOverlay: true,
|
2019-07-24 06:24:31 +08:00
|
|
|
swapLayout: false,
|
|
|
|
disableVideo: false,
|
|
|
|
audioModalIsOpen: false,
|
2017-10-11 06:08:51 +08:00
|
|
|
};
|
|
|
|
|
2018-04-27 23:11:40 +08:00
|
|
|
|
2016-05-03 06:42:54 +08:00
|
|
|
export default class Media extends Component {
|
2019-04-24 04:23:32 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.refContainer = React.createRef();
|
|
|
|
}
|
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
render() {
|
|
|
|
const {
|
2019-04-19 02:48:39 +08:00
|
|
|
swapLayout,
|
2019-11-05 03:57:29 +08:00
|
|
|
singleWebcam,
|
2019-04-19 02:48:39 +08:00
|
|
|
hideOverlay,
|
|
|
|
disableVideo,
|
|
|
|
children,
|
|
|
|
audioModalIsOpen,
|
2019-06-20 04:55:43 +08:00
|
|
|
usersVideo,
|
2020-07-16 00:44:59 +08:00
|
|
|
webcamDraggableState,
|
2018-04-12 02:50:14 +08:00
|
|
|
} = this.props;
|
2018-04-10 02:28:54 +08:00
|
|
|
|
2020-07-16 00:44:59 +08:00
|
|
|
const { placement } = webcamDraggableState;
|
|
|
|
const placementStorage = Storage.getItem('webcamPlacement');
|
|
|
|
const webcamPlacement = placement || placementStorage;
|
2020-01-24 02:09:39 +08:00
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
const contentClassName = cx({
|
|
|
|
[styles.content]: true,
|
|
|
|
});
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2018-04-12 02:50:14 +08:00
|
|
|
const overlayClassName = cx({
|
|
|
|
[styles.overlay]: true,
|
|
|
|
[styles.hideOverlay]: hideOverlay,
|
2020-07-16 00:44:59 +08:00
|
|
|
[styles.floatingOverlay]: (webcamPlacement === 'floating'),
|
2019-11-01 05:11:26 +08:00
|
|
|
});
|
|
|
|
|
2019-11-26 00:38:00 +08:00
|
|
|
const containerClassName = cx({
|
2020-01-24 02:09:39 +08:00
|
|
|
[styles.container]: true,
|
2020-07-16 00:44:59 +08:00
|
|
|
[styles.containerV]: webcamPlacement === 'top' || webcamPlacement === 'bottom' || webcamPlacement === 'floating',
|
|
|
|
[styles.containerH]: webcamPlacement === 'left' || webcamPlacement === 'right',
|
2019-11-26 00:38:00 +08:00
|
|
|
});
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
return (
|
2019-03-01 05:39:57 +08:00
|
|
|
<div
|
2019-03-05 01:29:40 +08:00
|
|
|
id="container"
|
2019-11-26 00:38:00 +08:00
|
|
|
className={containerClassName}
|
2019-04-24 04:23:32 +08:00
|
|
|
ref={this.refContainer}
|
2019-03-01 05:39:57 +08:00
|
|
|
>
|
2019-06-20 04:55:43 +08:00
|
|
|
<div
|
|
|
|
className={!swapLayout ? contentClassName : overlayClassName}
|
|
|
|
style={{
|
2020-01-21 21:57:32 +08:00
|
|
|
maxHeight: usersVideo.length > 0
|
|
|
|
&& (
|
2020-07-16 00:44:59 +08:00
|
|
|
webcamPlacement !== 'left'
|
|
|
|
|| webcamPlacement !== 'right'
|
2019-11-26 00:38:00 +08:00
|
|
|
)
|
2020-01-21 21:57:32 +08:00
|
|
|
&& (
|
2020-07-16 00:44:59 +08:00
|
|
|
webcamPlacement === 'top'
|
|
|
|
|| webcamPlacement === 'bottom'
|
2019-11-26 00:38:00 +08:00
|
|
|
)
|
2020-01-21 21:57:32 +08:00
|
|
|
? '80%'
|
|
|
|
: '100%',
|
|
|
|
minHeight: BROWSER_ISMOBILE && window.innerWidth > window.innerHeight ? '50%' : '20%',
|
|
|
|
maxWidth: usersVideo.length > 0
|
|
|
|
&& (
|
2020-07-16 00:44:59 +08:00
|
|
|
webcamPlacement !== 'top'
|
|
|
|
|| webcamPlacement !== 'bottom'
|
2020-01-21 21:57:32 +08:00
|
|
|
)
|
|
|
|
&& (
|
2020-07-16 00:44:59 +08:00
|
|
|
webcamPlacement === 'left'
|
|
|
|
|| webcamPlacement === 'right'
|
2020-01-21 21:57:32 +08:00
|
|
|
)
|
|
|
|
? '80%'
|
|
|
|
: '100%',
|
2019-11-26 00:38:00 +08:00
|
|
|
minWidth: '20%',
|
2019-06-20 04:55:43 +08:00
|
|
|
}}
|
|
|
|
>
|
2018-12-18 05:01:23 +08:00
|
|
|
{children}
|
2018-04-12 02:50:14 +08:00
|
|
|
</div>
|
2020-01-24 02:09:39 +08:00
|
|
|
{
|
|
|
|
usersVideo.length > 0
|
|
|
|
? (
|
|
|
|
<WebcamDraggable
|
|
|
|
refMediaContainer={this.refContainer}
|
|
|
|
swapLayout={swapLayout}
|
|
|
|
singleWebcam={singleWebcam}
|
|
|
|
usersVideoLenght={usersVideo.length}
|
|
|
|
hideOverlay={hideOverlay}
|
|
|
|
disableVideo={disableVideo}
|
|
|
|
audioModalIsOpen={audioModalIsOpen}
|
|
|
|
usersVideo={usersVideo}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
2016-05-03 06:42:54 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-04 04:40:46 +08:00
|
|
|
|
|
|
|
Media.propTypes = propTypes;
|
2017-10-11 06:08:51 +08:00
|
|
|
Media.defaultProps = defaultProps;
|