2019-03-01 05:39:57 +08:00
|
|
|
import React, { Component, Fragment } from 'react';
|
2019-07-10 07:11:48 +08:00
|
|
|
import Draggable from 'react-draggable';
|
2019-03-01 05:39:57 +08:00
|
|
|
import cx from 'classnames';
|
2019-07-11 21:49:06 +08:00
|
|
|
import _ from 'lodash';
|
2019-07-24 06:24:31 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2019-07-30 03:42:11 +08:00
|
|
|
import Resizable from 're-resizable';
|
2020-01-11 04:20:26 +08:00
|
|
|
import { isMobile, isIPad13 } from 'react-device-detect';
|
2019-07-10 07:11:48 +08:00
|
|
|
import { withDraggableContext } from './context';
|
|
|
|
import VideoProviderContainer from '/imports/ui/components/video-provider/container';
|
2019-06-20 04:55:43 +08:00
|
|
|
import { styles } from '../styles.scss';
|
2019-07-10 07:11:48 +08:00
|
|
|
import Storage from '../../../services/storage/session';
|
2019-03-01 05:39:57 +08:00
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
const { webcamsDefaultPlacement } = Meteor.settings.public.layout;
|
2020-01-11 04:20:26 +08:00
|
|
|
const BROWSER_ISMOBILE = isMobile || isIPad13;
|
2019-03-25 22:43:02 +08:00
|
|
|
|
2019-07-24 06:24:31 +08:00
|
|
|
const propTypes = {
|
|
|
|
swapLayout: PropTypes.bool,
|
|
|
|
hideOverlay: PropTypes.bool,
|
|
|
|
disableVideo: PropTypes.bool,
|
|
|
|
audioModalIsOpen: PropTypes.bool,
|
|
|
|
webcamDraggableState: PropTypes.objectOf(Object).isRequired,
|
|
|
|
webcamDraggableDispatch: PropTypes.func.isRequired,
|
|
|
|
refMediaContainer: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
swapLayout: false,
|
|
|
|
hideOverlay: false,
|
|
|
|
disableVideo: false,
|
|
|
|
audioModalIsOpen: false,
|
|
|
|
refMediaContainer: null,
|
|
|
|
};
|
2019-07-30 03:42:11 +08:00
|
|
|
const dispatchResizeEvent = () => window.dispatchEvent(new Event('resize'));
|
2019-07-24 06:24:31 +08:00
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
class WebcamDraggable extends Component {
|
2019-03-01 05:39:57 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleWebcamDragStart = this.handleWebcamDragStart.bind(this);
|
|
|
|
this.handleWebcamDragStop = this.handleWebcamDragStop.bind(this);
|
2019-07-30 23:03:29 +08:00
|
|
|
this.onFullscreenChange = this.onFullscreenChange.bind(this);
|
2019-12-11 05:43:22 +08:00
|
|
|
this.debouncedOnResize = _.debounce(this.onWindowResize.bind(this), 500);
|
2019-09-18 02:25:28 +08:00
|
|
|
this.onResizeStop = this.onResizeStop.bind(this);
|
2019-12-11 05:43:22 +08:00
|
|
|
this.onResizeStart = this.onResizeStart.bind(this);
|
|
|
|
this.setPlacementPercent = this.setPlacementPercent.bind(this);
|
2020-01-14 03:41:35 +08:00
|
|
|
this.recalculateAreaSize = this.recalculateAreaSize.bind(this);
|
2019-12-11 05:43:22 +08:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
resizing: false,
|
|
|
|
placementPercent: 0,
|
|
|
|
};
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-07-30 23:03:29 +08:00
|
|
|
window.addEventListener('resize', this.debouncedOnResize);
|
|
|
|
document.addEventListener('fullscreenchange', this.onFullscreenChange);
|
2020-01-14 03:41:35 +08:00
|
|
|
window.addEventListener('orientationchange', () => setTimeout(this.recalculateAreaSize, 500));
|
2019-06-03 22:05:09 +08:00
|
|
|
}
|
|
|
|
|
2019-06-26 20:02:29 +08:00
|
|
|
componentDidUpdate(prevProps) {
|
2019-11-01 05:11:26 +08:00
|
|
|
const { swapLayout, webcamDraggableState } = this.props;
|
|
|
|
const { placement } = webcamDraggableState;
|
|
|
|
const { webcamDraggableState: prevWebcamDraggableState } = prevProps;
|
|
|
|
const { placement: prevPlacement } = prevWebcamDraggableState;
|
2019-11-06 05:42:35 +08:00
|
|
|
if (prevProps.swapLayout !== swapLayout) {
|
2019-07-10 07:11:48 +08:00
|
|
|
setTimeout(() => this.forceUpdate(), 500);
|
2019-06-25 02:37:17 +08:00
|
|
|
}
|
2019-11-01 05:11:26 +08:00
|
|
|
if (prevPlacement !== placement) {
|
|
|
|
setTimeout(() => this.forceUpdate(), 200);
|
2019-12-11 05:43:22 +08:00
|
|
|
setTimeout(() => window.dispatchEvent(new Event('resize')), 500);
|
2019-11-01 05:11:26 +08:00
|
|
|
}
|
2019-07-10 07:11:48 +08:00
|
|
|
}
|
2019-06-25 02:37:17 +08:00
|
|
|
|
2019-07-30 23:03:29 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('resize', this.debouncedOnResize);
|
|
|
|
document.removeEventListener('fullscreenchange', this.onFullscreenChange);
|
|
|
|
}
|
|
|
|
|
|
|
|
onFullscreenChange() {
|
|
|
|
this.forceUpdate();
|
|
|
|
}
|
|
|
|
|
2019-12-11 05:43:22 +08:00
|
|
|
onResizeStart() {
|
|
|
|
this.setState({ resizing: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
onWindowResize() {
|
2019-07-10 07:11:48 +08:00
|
|
|
const { webcamDraggableState, webcamDraggableDispatch } = this.props;
|
|
|
|
const { mediaSize } = webcamDraggableState;
|
|
|
|
const { width: stateWidth, height: stateHeight } = mediaSize;
|
|
|
|
const { width, height } = this.getMediaBounds();
|
2019-12-11 05:43:22 +08:00
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
if (stateWidth !== width || stateHeight !== height) {
|
|
|
|
webcamDraggableDispatch(
|
|
|
|
{
|
|
|
|
type: 'setMediaSize',
|
|
|
|
value: {
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
},
|
|
|
|
},
|
2019-06-25 23:40:57 +08:00
|
|
|
);
|
2019-09-18 02:25:28 +08:00
|
|
|
}
|
2019-12-11 05:43:22 +08:00
|
|
|
setTimeout(() => window.dispatchEvent(new Event('resize')), 300);
|
|
|
|
}
|
|
|
|
|
|
|
|
onResize() {
|
|
|
|
this.setPlacementPercent();
|
2019-09-18 02:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
onResizeStop() {
|
|
|
|
const { webcamDraggableState, webcamDraggableDispatch } = this.props;
|
2019-12-06 02:01:23 +08:00
|
|
|
const { optimalGrid } = webcamDraggableState;
|
|
|
|
if (optimalGrid) {
|
2019-09-18 02:25:28 +08:00
|
|
|
webcamDraggableDispatch(
|
|
|
|
{
|
|
|
|
type: 'setVideoListSize',
|
|
|
|
value: {
|
2019-12-06 02:01:23 +08:00
|
|
|
width: optimalGrid.width,
|
|
|
|
height: optimalGrid.height,
|
2019-09-18 02:25:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2019-12-11 05:43:22 +08:00
|
|
|
this.setPlacementPercent();
|
2019-09-18 02:25:28 +08:00
|
|
|
window.dispatchEvent(new Event('resize'));
|
2019-12-11 05:43:22 +08:00
|
|
|
setTimeout(() => this.setState({ resizing: false }), 500);
|
|
|
|
}
|
|
|
|
|
|
|
|
setPlacementPercent() {
|
|
|
|
const { webcamDraggableState } = this.props;
|
|
|
|
const { optimalGrid, placement } = webcamDraggableState;
|
|
|
|
if (placement === 'top' || placement === 'bottom') {
|
|
|
|
const mediaHeight = $('section[class^=media]').height();
|
|
|
|
this.setState({ placementPercent: (optimalGrid.height * 100) / mediaHeight });
|
|
|
|
}
|
|
|
|
if (placement === 'left' || placement === 'right') {
|
|
|
|
const mediaWidth = $('section[class^=media]').width();
|
|
|
|
this.setState({ placementPercent: (optimalGrid.width * 100) / mediaWidth });
|
|
|
|
}
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
getMediaBounds() {
|
|
|
|
const { refMediaContainer, webcamDraggableState, webcamDraggableDispatch } = this.props;
|
|
|
|
const { mediaSize: mediaState } = webcamDraggableState;
|
2019-04-24 04:23:32 +08:00
|
|
|
const { current: mediaContainer } = refMediaContainer;
|
2019-07-10 07:11:48 +08:00
|
|
|
if (mediaContainer) {
|
2019-04-24 04:23:32 +08:00
|
|
|
const mediaContainerRect = mediaContainer.getBoundingClientRect();
|
2019-03-01 05:39:57 +08:00
|
|
|
const {
|
2019-08-08 04:57:41 +08:00
|
|
|
top, left, width: newWidth, height: newHeight,
|
2019-04-24 04:23:32 +08:00
|
|
|
} = mediaContainerRect;
|
2019-08-06 05:17:39 +08:00
|
|
|
if ((mediaState.width === 0 || mediaState.height === 0) && (newWidth > 0 && newHeight > 0)) {
|
2019-07-10 07:11:48 +08:00
|
|
|
webcamDraggableDispatch(
|
|
|
|
{
|
|
|
|
type: 'setMediaSize',
|
|
|
|
value: {
|
2019-08-06 05:17:39 +08:00
|
|
|
newWidth,
|
|
|
|
newHeight,
|
2019-07-10 07:11:48 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2019-03-01 05:39:57 +08:00
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
return {
|
|
|
|
top,
|
|
|
|
left,
|
2019-08-08 04:57:41 +08:00
|
|
|
width: newWidth,
|
|
|
|
height: newHeight,
|
2019-07-10 07:11:48 +08:00
|
|
|
};
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
2019-04-24 04:23:32 +08:00
|
|
|
return false;
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
getWebcamsListBounds() {
|
2019-12-06 02:01:23 +08:00
|
|
|
const { webcamDraggableState } = this.props;
|
2019-07-10 07:11:48 +08:00
|
|
|
const { videoListRef } = webcamDraggableState;
|
|
|
|
if (videoListRef) {
|
|
|
|
const videoListRefRect = videoListRef.getBoundingClientRect();
|
2019-03-01 05:39:57 +08:00
|
|
|
const {
|
2019-07-10 07:11:48 +08:00
|
|
|
top, left, width, height,
|
|
|
|
} = videoListRefRect;
|
|
|
|
return {
|
2019-12-06 04:01:54 +08:00
|
|
|
top, // 10 = margin
|
2019-12-06 02:01:23 +08:00
|
|
|
left, // 10 = margin
|
|
|
|
width, // 20 = margin
|
2019-12-06 04:01:54 +08:00
|
|
|
height, // 20 = margin
|
2019-07-10 07:11:48 +08:00
|
|
|
};
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
2019-07-10 07:11:48 +08:00
|
|
|
return false;
|
2019-06-11 02:25:55 +08:00
|
|
|
}
|
|
|
|
|
2020-01-14 03:41:35 +08:00
|
|
|
recalculateAreaSize() {
|
|
|
|
this.onResizeStart();
|
|
|
|
this.onResizeStop();
|
|
|
|
}
|
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
calculatePosition() {
|
|
|
|
const { top: mediaTop, left: mediaLeft } = this.getMediaBounds();
|
|
|
|
const { top: webcamsListTop, left: webcamsListLeft } = this.getWebcamsListBounds();
|
|
|
|
const x = webcamsListLeft - mediaLeft;
|
|
|
|
const y = webcamsListTop - mediaTop;
|
|
|
|
return {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
};
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
|
|
|
|
2019-12-06 02:01:23 +08:00
|
|
|
handleWebcamDragStart() {
|
|
|
|
const { webcamDraggableDispatch } = this.props;
|
|
|
|
const { x, y } = this.calculatePosition();
|
2019-07-10 07:11:48 +08:00
|
|
|
webcamDraggableDispatch({ type: 'dragStart' });
|
|
|
|
webcamDraggableDispatch(
|
|
|
|
{
|
|
|
|
type: 'setTempPosition',
|
|
|
|
value: {
|
2019-12-06 02:01:23 +08:00
|
|
|
x,
|
2019-07-10 07:11:48 +08:00
|
|
|
y,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
|
|
|
|
2019-12-06 02:01:23 +08:00
|
|
|
handleWebcamDragStop(e) {
|
|
|
|
const { webcamDraggableDispatch } = this.props;
|
2019-08-06 05:17:39 +08:00
|
|
|
const targetClassname = JSON.stringify(e.target.className);
|
2019-11-26 00:38:00 +08:00
|
|
|
|
2019-11-01 05:11:26 +08:00
|
|
|
if (targetClassname) {
|
|
|
|
if (targetClassname.includes('Top')) {
|
|
|
|
webcamDraggableDispatch({ type: 'setplacementToTop' });
|
2019-11-26 00:38:00 +08:00
|
|
|
} else if (targetClassname.includes('Right')) {
|
|
|
|
webcamDraggableDispatch({ type: 'setplacementToRight' });
|
2019-11-01 05:11:26 +08:00
|
|
|
} else if (targetClassname.includes('Bottom')) {
|
|
|
|
webcamDraggableDispatch({ type: 'setplacementToBottom' });
|
2019-11-26 00:38:00 +08:00
|
|
|
} else if (targetClassname.includes('Left')) {
|
|
|
|
webcamDraggableDispatch({ type: 'setplacementToLeft' });
|
2019-11-01 05:11:26 +08:00
|
|
|
}
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
2019-07-10 07:11:48 +08:00
|
|
|
webcamDraggableDispatch({ type: 'dragEnd' });
|
2019-06-03 22:33:06 +08:00
|
|
|
window.dispatchEvent(new Event('resize'));
|
2020-01-14 03:41:35 +08:00
|
|
|
setTimeout(this.recalculateAreaSize, 500);
|
2019-03-01 05:39:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2019-07-10 07:11:48 +08:00
|
|
|
webcamDraggableState,
|
2019-03-01 05:39:57 +08:00
|
|
|
swapLayout,
|
|
|
|
hideOverlay,
|
|
|
|
disableVideo,
|
2019-05-28 06:18:26 +08:00
|
|
|
audioModalIsOpen,
|
2019-11-26 00:38:00 +08:00
|
|
|
refMediaContainer,
|
2019-03-01 05:39:57 +08:00
|
|
|
} = this.props;
|
2019-06-25 23:40:57 +08:00
|
|
|
|
2019-12-11 05:43:22 +08:00
|
|
|
const {
|
|
|
|
resizing,
|
|
|
|
placementPercent,
|
|
|
|
} = this.state;
|
|
|
|
|
2019-12-06 02:01:23 +08:00
|
|
|
const {
|
|
|
|
dragging,
|
|
|
|
isCameraFullscreen,
|
|
|
|
videoListSize,
|
|
|
|
optimalGrid,
|
|
|
|
} = webcamDraggableState;
|
2019-07-10 07:11:48 +08:00
|
|
|
let placement = Storage.getItem('webcamPlacement');
|
|
|
|
const lastPosition = Storage.getItem('webcamLastPosition') || { x: 0, y: 0 };
|
|
|
|
let position = lastPosition;
|
|
|
|
if (!placement) {
|
|
|
|
placement = webcamsDefaultPlacement;
|
|
|
|
}
|
2019-06-25 23:40:57 +08:00
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
if (dragging) {
|
|
|
|
position = webcamDraggableState.tempPosition;
|
2019-12-06 02:01:23 +08:00
|
|
|
} else if (!dragging) {
|
2019-07-10 07:11:48 +08:00
|
|
|
position = webcamDraggableState.lastPosition;
|
|
|
|
} else {
|
|
|
|
position = {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
};
|
|
|
|
}
|
2019-06-08 04:45:54 +08:00
|
|
|
|
2019-07-27 03:42:39 +08:00
|
|
|
if (swapLayout || isCameraFullscreen || BROWSER_ISMOBILE) {
|
2019-07-10 07:11:48 +08:00
|
|
|
position = {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
};
|
2019-06-08 04:45:54 +08:00
|
|
|
}
|
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
const {
|
|
|
|
width: mediaWidth,
|
|
|
|
height: mediaHeight,
|
|
|
|
} = this.getMediaBounds();
|
2019-03-01 05:39:57 +08:00
|
|
|
|
|
|
|
const {
|
2019-07-10 07:11:48 +08:00
|
|
|
width: webcamsWidth,
|
|
|
|
height: webcamsHeight,
|
|
|
|
} = this.getWebcamsListBounds();
|
|
|
|
|
|
|
|
const isOverflowWidth = (lastPosition.x + webcamsWidth) > mediaWidth;
|
|
|
|
const isOverflowHeight = (lastPosition.y + webcamsHeight) > mediaHeight;
|
|
|
|
|
|
|
|
position = {
|
|
|
|
x: isOverflowWidth
|
2019-12-06 02:01:23 +08:00
|
|
|
&& !dragging && !swapLayout ? mediaWidth - webcamsWidth : position.x,
|
2019-07-10 07:11:48 +08:00
|
|
|
y: isOverflowHeight
|
2019-12-06 02:01:23 +08:00
|
|
|
&& !dragging && !swapLayout ? mediaHeight - (webcamsHeight + 1) : position.y,
|
2019-07-10 07:11:48 +08:00
|
|
|
};
|
2019-03-01 05:39:57 +08:00
|
|
|
|
|
|
|
const contentClassName = cx({
|
|
|
|
[styles.content]: true,
|
2019-11-26 00:38:00 +08:00
|
|
|
[styles.fullWidth]: swapLayout,
|
|
|
|
[styles.fullHeight]: swapLayout,
|
2019-03-01 05:39:57 +08:00
|
|
|
});
|
|
|
|
|
2019-11-26 00:38:00 +08:00
|
|
|
const { current: mediaContainer } = refMediaContainer;
|
|
|
|
let layout = 'vertical';
|
|
|
|
if (mediaContainer) {
|
|
|
|
const classNameMediaContainer = mediaContainer.className;
|
|
|
|
if (classNameMediaContainer.includes('containerH')) {
|
|
|
|
layout = 'horizontal';
|
|
|
|
} else {
|
|
|
|
layout = 'vertical';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 05:39:57 +08:00
|
|
|
const overlayClassName = cx({
|
|
|
|
[styles.overlay]: true,
|
|
|
|
[styles.hideOverlay]: hideOverlay,
|
2019-12-03 04:21:34 +08:00
|
|
|
[styles.floatingOverlay]: dragging,
|
2019-12-06 02:01:23 +08:00
|
|
|
[styles.autoWidth]: dragging,
|
2019-12-03 04:21:34 +08:00
|
|
|
[styles.fullWidth]: (
|
2019-12-06 02:01:23 +08:00
|
|
|
(
|
|
|
|
placement === 'top'
|
|
|
|
|| placement === 'bottom'
|
|
|
|
)
|
|
|
|
|| swapLayout
|
2019-12-03 04:21:34 +08:00
|
|
|
)
|
2019-12-06 02:01:23 +08:00
|
|
|
&& !dragging,
|
|
|
|
[styles.fullHeight]: (
|
|
|
|
(
|
|
|
|
placement === 'left'
|
|
|
|
&& placement === 'right'
|
|
|
|
)
|
|
|
|
|| swapLayout
|
|
|
|
)
|
|
|
|
&& !dragging,
|
2019-12-03 04:21:34 +08:00
|
|
|
[styles.overlayToTop]: placement === 'top' && !dragging,
|
2019-11-26 00:38:00 +08:00
|
|
|
[styles.overlayToRight]: placement === 'right' && !dragging,
|
2019-07-10 07:11:48 +08:00
|
|
|
[styles.overlayToBottom]: placement === 'bottom' && !dragging,
|
2019-11-26 00:38:00 +08:00
|
|
|
[styles.overlayToLeft]: placement === 'left' && !dragging,
|
2019-03-01 05:39:57 +08:00
|
|
|
[styles.dragging]: dragging,
|
2019-11-26 00:38:00 +08:00
|
|
|
[styles.hide]: (
|
|
|
|
(
|
|
|
|
placement === 'left'
|
|
|
|
|| placement === 'right'
|
|
|
|
)
|
|
|
|
&& layout === 'vertical'
|
|
|
|
)
|
2019-12-03 04:21:34 +08:00
|
|
|
|| (
|
|
|
|
(
|
|
|
|
placement === 'top'
|
|
|
|
|| placement === 'bottom'
|
|
|
|
)
|
|
|
|
&& layout === 'horizontal'
|
|
|
|
),
|
2019-03-01 05:39:57 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const dropZoneTopClassName = cx({
|
|
|
|
[styles.dropZoneTop]: true,
|
2019-07-10 07:11:48 +08:00
|
|
|
[styles.show]: dragging,
|
|
|
|
[styles.hide]: !dragging,
|
2019-07-27 03:42:39 +08:00
|
|
|
[styles.cursorGrabbing]: dragging && !isCameraFullscreen,
|
2019-03-01 05:39:57 +08:00
|
|
|
});
|
|
|
|
|
2019-11-26 00:38:00 +08:00
|
|
|
const dropZoneLeftClassName = cx({
|
|
|
|
[styles.dropZoneLeft]: true,
|
|
|
|
[styles.show]: dragging,
|
|
|
|
[styles.hide]: !dragging,
|
|
|
|
[styles.cursorGrabbing]: dragging && !isCameraFullscreen,
|
|
|
|
});
|
|
|
|
|
2019-03-01 05:39:57 +08:00
|
|
|
const dropZoneBottomClassName = cx({
|
|
|
|
[styles.dropZoneBottom]: true,
|
2019-07-10 07:11:48 +08:00
|
|
|
[styles.show]: dragging,
|
|
|
|
[styles.hide]: !dragging,
|
2019-07-27 03:42:39 +08:00
|
|
|
[styles.cursorGrabbing]: dragging && !isCameraFullscreen,
|
2019-03-01 05:39:57 +08:00
|
|
|
});
|
|
|
|
|
2019-11-26 00:38:00 +08:00
|
|
|
const dropZoneRightClassName = cx({
|
|
|
|
[styles.dropZoneRight]: true,
|
|
|
|
[styles.show]: dragging,
|
|
|
|
[styles.hide]: !dragging,
|
|
|
|
[styles.cursorGrabbing]: dragging && !isCameraFullscreen,
|
|
|
|
});
|
|
|
|
|
2019-03-01 05:39:57 +08:00
|
|
|
const dropZoneBgTopClassName = cx({
|
2019-07-10 07:11:48 +08:00
|
|
|
[styles.dropZoneBgTop]: true,
|
2019-03-01 05:39:57 +08:00
|
|
|
});
|
|
|
|
|
2019-11-26 00:38:00 +08:00
|
|
|
const dropZoneBgLeftClassName = cx({
|
|
|
|
[styles.dropZoneBgLeft]: true,
|
|
|
|
});
|
|
|
|
|
2019-03-01 05:39:57 +08:00
|
|
|
const dropZoneBgBottomClassName = cx({
|
2019-07-10 07:11:48 +08:00
|
|
|
[styles.dropZoneBgBottom]: true,
|
2019-03-01 05:39:57 +08:00
|
|
|
});
|
|
|
|
|
2019-11-26 00:38:00 +08:00
|
|
|
const dropZoneBgRightClassName = cx({
|
|
|
|
[styles.dropZoneBgRight]: true,
|
|
|
|
});
|
|
|
|
|
2019-12-11 05:43:22 +08:00
|
|
|
const mHeight = $('section[class^=media]').height();
|
|
|
|
const mWidth = $('section[class^=media]').width();
|
|
|
|
|
2019-12-06 02:01:23 +08:00
|
|
|
let resizeWidth;
|
|
|
|
let resizeHeight;
|
2019-12-11 05:43:22 +08:00
|
|
|
if (resizing && (placement === 'top' || placement === 'bottom') && !dragging) {
|
2019-12-06 02:01:23 +08:00
|
|
|
resizeWidth = '100%';
|
|
|
|
resizeHeight = videoListSize.height;
|
|
|
|
}
|
2019-12-11 05:43:22 +08:00
|
|
|
if (!resizing && (placement === 'top' || placement === 'bottom') && !dragging) {
|
|
|
|
resizeWidth = '100%';
|
|
|
|
resizeHeight = mHeight * (placementPercent / 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resizing && (placement === 'left' || placement === 'right') && !dragging) {
|
|
|
|
resizeWidth = videoListSize.width;
|
|
|
|
resizeHeight = '100%';
|
|
|
|
}
|
|
|
|
if (!resizing && (placement === 'left' || placement === 'right') && !dragging) {
|
|
|
|
resizeWidth = mWidth * (placementPercent / 100);
|
2019-12-06 02:01:23 +08:00
|
|
|
resizeHeight = '100%';
|
|
|
|
}
|
2019-12-11 05:43:22 +08:00
|
|
|
|
2019-12-06 02:01:23 +08:00
|
|
|
if (dragging) {
|
|
|
|
resizeHeight = optimalGrid.height;
|
|
|
|
resizeWidth = optimalGrid.width;
|
|
|
|
}
|
2019-12-11 05:43:22 +08:00
|
|
|
|
2019-03-01 05:39:57 +08:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<div
|
|
|
|
className={dropZoneTopClassName}
|
2019-11-26 00:38:00 +08:00
|
|
|
style={{ height: '15vh' }}
|
2019-07-10 07:11:48 +08:00
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={dropZoneBgTopClassName}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-11-26 00:38:00 +08:00
|
|
|
<div
|
|
|
|
className={dropZoneLeftClassName}
|
|
|
|
style={{
|
|
|
|
width: '15vh',
|
|
|
|
height: `calc(${mediaHeight}px - (15vh * 2))`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={dropZoneBgLeftClassName}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-03-01 05:39:57 +08:00
|
|
|
<Draggable
|
|
|
|
handle="video"
|
2019-03-05 01:29:40 +08:00
|
|
|
bounds="#container"
|
2019-03-01 05:39:57 +08:00
|
|
|
onStart={this.handleWebcamDragStart}
|
|
|
|
onStop={this.handleWebcamDragStop}
|
2019-04-12 00:35:23 +08:00
|
|
|
onMouseDown={e => e.preventDefault()}
|
2019-07-27 03:42:39 +08:00
|
|
|
disabled={swapLayout || isCameraFullscreen || BROWSER_ISMOBILE}
|
2019-07-10 07:11:48 +08:00
|
|
|
position={position}
|
2019-03-01 05:39:57 +08:00
|
|
|
>
|
2019-07-30 03:42:11 +08:00
|
|
|
<Resizable
|
2019-09-18 02:25:28 +08:00
|
|
|
size={
|
2019-12-06 02:01:23 +08:00
|
|
|
{
|
|
|
|
height: resizeHeight,
|
|
|
|
width: resizeWidth,
|
|
|
|
}
|
2019-09-18 02:25:28 +08:00
|
|
|
}
|
|
|
|
lockAspectRatio
|
|
|
|
handleWrapperClass="resizeWrapper"
|
2019-12-11 05:43:22 +08:00
|
|
|
onResizeStart={this.onResizeStart}
|
2019-07-30 03:42:11 +08:00
|
|
|
onResize={dispatchResizeEvent}
|
2019-09-18 02:25:28 +08:00
|
|
|
onResizeStop={this.onResizeStop}
|
2019-07-30 03:42:11 +08:00
|
|
|
enable={{
|
2019-12-06 02:01:23 +08:00
|
|
|
top: (placement === 'bottom') && !swapLayout,
|
|
|
|
bottom: (placement === 'top') && !swapLayout,
|
|
|
|
left: (placement === 'right') && !swapLayout,
|
|
|
|
right: (placement === 'left') && !swapLayout,
|
2019-09-18 02:25:28 +08:00
|
|
|
topLeft: false,
|
|
|
|
topRight: false,
|
|
|
|
bottomLeft: false,
|
|
|
|
bottomRight: false,
|
2019-07-30 03:42:11 +08:00
|
|
|
}}
|
|
|
|
className={
|
|
|
|
!swapLayout
|
|
|
|
? overlayClassName
|
|
|
|
: contentClassName}
|
2019-06-25 23:40:57 +08:00
|
|
|
style={{
|
2019-12-06 02:01:23 +08:00
|
|
|
marginLeft: 0,
|
|
|
|
marginRight: 0,
|
2019-06-25 23:40:57 +08:00
|
|
|
}}
|
2019-03-01 05:39:57 +08:00
|
|
|
>
|
2019-07-30 03:42:11 +08:00
|
|
|
{
|
|
|
|
!disableVideo
|
|
|
|
&& !audioModalIsOpen
|
|
|
|
? (
|
|
|
|
<VideoProviderContainer
|
|
|
|
swapLayout={swapLayout}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
</Resizable>
|
2019-03-01 05:39:57 +08:00
|
|
|
</Draggable>
|
|
|
|
<div
|
|
|
|
className={dropZoneBottomClassName}
|
2019-11-26 00:38:00 +08:00
|
|
|
style={{ height: '15vh' }}
|
2019-07-10 07:11:48 +08:00
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={dropZoneBgBottomClassName}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-11-26 00:38:00 +08:00
|
|
|
<div
|
|
|
|
className={dropZoneRightClassName}
|
|
|
|
style={{
|
|
|
|
width: '15vh',
|
|
|
|
height: `calc(${mediaHeight}px - (15vh * 2))`,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div
|
|
|
|
className={dropZoneBgRightClassName}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-03-01 05:39:57 +08:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 06:24:31 +08:00
|
|
|
WebcamDraggable.propTypes = propTypes;
|
|
|
|
WebcamDraggable.defaultProps = defaultProps;
|
|
|
|
|
2019-07-10 07:11:48 +08:00
|
|
|
export default withDraggableContext(WebcamDraggable);
|