import React from 'react'; import { connect } from 'react-redux'; import ReactTooltip from 'react-tooltip'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import ClipboardButton from 'react-clipboard.js'; import * as appPropTypes from './appPropTypes'; import * as requestActions from '../redux/requestActions'; import * as stateActions from '../redux/stateActions'; import { Appear } from './transitions'; import Me from './Me'; import Peers from './Peers'; import Notifications from './Notifications'; import ToolAreaButton from './ToolArea/ToolAreaButton'; import ToolArea from './ToolArea/ToolArea'; import FullScreenView from './FullScreenView'; import Draggable from 'react-draggable'; // Hide toolbars after 10 seconds of inactivity. const TIMEOUT = 10 * 1000; /** * Create a function which will call the callback function * after the given amount of milliseconds has passed since * the last time the callback function was called. */ const idle = (callback, delay) => { let handle; return () => { if (handle) { clearTimeout(handle); } handle = setTimeout(callback, delay); }; }; class Room extends React.Component { /** * Hides the different toolbars on the page after a * given amount of time has passed since the * last time the cursor was moved. */ waitForHide = idle(() => { this.props.setToolbarsVisible(false); }, TIMEOUT); handleMouseMove = () => { // If the toolbars were hidden, show them again when // the user moves their cursor. if (!this.props.room.toolbarsVisible) { this.props.setToolbarsVisible(true); } this.waitForHide(); } componentDidMount() { window.addEventListener('mousemove', this.handleMouseMove); } componentWillUnmount() { window.removeEventListener('mousemove', this.handleMouseMove); } render() { const { room, me, toolAreaOpen, amActiveSpeaker, screenProducer, onRoomLinkCopy, onLogin, onShareScreen, onUnShareScreen, onNeedExtension, onLeaveMeeting } = this.props; let screenState; let screenTip; if (me.needExtension) { screenState = 'need-extension'; screenTip = 'Install screen sharing extension'; } else if (!me.canShareScreen) { screenState = 'unsupported'; screenTip = 'Screen sharing not supported'; } else if (screenProducer) { screenState = 'on'; screenTip = 'Stop screen sharing'; } else { screenState = 'off'; screenTip = 'Start screen sharing'; } return (
{room.advancedMode ?

{room.state}

:null }
{ // If this is a 'Open in new window/tab' don't prevent // click default action. if ( event.ctrlKey || event.shiftKey || event.metaKey || // Middle click (IE > 9 and everyone else). (event.button && event.button === 1) ) { return; } event.preventDefault(); }} > invitation link
{ switch (screenState) { case 'on': { onUnShareScreen(); break; } case 'off': { onShareScreen(); break; } case 'need-extension': { onNeedExtension(); break; } default: { break; } } }} /> {me.loginEnabled ?
onLogin()} /> :null }
onLeaveMeeting()} />
{toolAreaOpen ? :null }
); } } Room.propTypes = { room : appPropTypes.Room.isRequired, me : appPropTypes.Me.isRequired, amActiveSpeaker : PropTypes.bool.isRequired, toolAreaOpen : PropTypes.bool.isRequired, screenProducer : appPropTypes.Producer, onRoomLinkCopy : PropTypes.func.isRequired, onShareScreen : PropTypes.func.isRequired, onUnShareScreen : PropTypes.func.isRequired, onNeedExtension : PropTypes.func.isRequired, onLeaveMeeting : PropTypes.func.isRequired, onLogin : PropTypes.func.isRequired, setToolbarsVisible : PropTypes.func.isRequired }; const mapStateToProps = (state) => { const producersArray = Object.values(state.producers); const screenProducer = producersArray.find((producer) => producer.source === 'screen'); return { room : state.room, me : state.me, toolAreaOpen : state.toolarea.toolAreaOpen, amActiveSpeaker : state.me.name === state.room.activeSpeakerName, screenProducer : screenProducer }; }; const mapDispatchToProps = (dispatch) => { return { onRoomLinkCopy : () => { dispatch(requestActions.notify( { text : 'Room link copied to the clipboard' })); }, onLeaveMeeting : () => { dispatch(requestActions.leaveRoom()); }, onShareScreen : () => { dispatch(requestActions.enableScreenSharing()); }, onUnShareScreen : () => { dispatch(requestActions.disableScreenSharing()); }, onNeedExtension : () => { dispatch(requestActions.installExtension()); }, onLogin : () => { dispatch(requestActions.userLogin()); }, setToolbarsVisible : (visible) => { dispatch(stateActions.setToolbarsVisible(visible)); } }; }; const RoomContainer = connect( mapStateToProps, mapDispatchToProps )(Room); export default RoomContainer;