import React from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import ReactTooltip from 'react-tooltip'; import classnames from 'classnames'; import * as cookiesManager from '../cookiesManager'; import * as appPropTypes from './appPropTypes'; import { withRoomContext } from '../RoomContext'; import * as stateActions from '../redux/stateActions'; import PeerView from './PeerView'; class Me extends React.Component { constructor(props) { super(props); this._mounted = false; this._rootNode = null; } render() { const { roomClient, connected, me, audioProducer, videoProducer, faceDetection, onSetStatsPeerId } = this.props; let micState; if (!me.canSendMic) micState = 'unsupported'; else if (!audioProducer) micState = 'unsupported'; else if (!audioProducer.paused) micState = 'on'; else micState = 'off'; let webcamState; if (!me.canSendWebcam) webcamState = 'unsupported'; else if (videoProducer && videoProducer.type !== 'share') webcamState = 'on'; else webcamState = 'off'; let changeWebcamState; if (Boolean(videoProducer) && videoProducer.type !== 'share' && me.canChangeWebcam) changeWebcamState = 'on'; else changeWebcamState = 'unsupported'; let shareState; if (Boolean(videoProducer) && videoProducer.type === 'share') shareState = 'on'; else shareState = 'off'; const videoVisible = Boolean(videoProducer) && !videoProducer.paused; let tip; if (!me.displayNameSet) tip = 'Click on your name to change it'; return (
(this._rootNode = node)} data-tip={tip} data-tip-disable={!tip} >
{ micState === 'on' ? roomClient.muteMic() : roomClient.unmuteMic(); }} />
{ if (webcamState === 'on') { cookiesManager.setDevices({ webcamEnabled: false }); roomClient.disableWebcam(); } else { cookiesManager.setDevices({ webcamEnabled: true }); roomClient.enableWebcam(); } }} />
roomClient.changeWebcam()} />
{ if (shareState === 'on') roomClient.disableShare(); else roomClient.enableShare(); }} />
{ roomClient.changeDisplayName(displayName); }} onChangeMaxSendingSpatialLayer={(spatialLayer) => { roomClient.setMaxSendingSpatialLayer(spatialLayer); }} onStatsClick={onSetStatsPeerId} />
); } componentDidMount() { this._mounted = true; setTimeout(() => { if (!this._mounted || this.props.me.displayNameSet) return; ReactTooltip.show(this._rootNode); }, 4000); } componentWillUnmount() { this._mounted = false; } componentDidUpdate(prevProps) { if (!prevProps.me.displayNameSet && this.props.me.displayNameSet) ReactTooltip.hide(this._rootNode); } } Me.propTypes = { roomClient : PropTypes.any.isRequired, connected : PropTypes.bool.isRequired, me : appPropTypes.Me.isRequired, audioProducer : appPropTypes.Producer, videoProducer : appPropTypes.Producer, faceDetection : PropTypes.bool.isRequired, onSetStatsPeerId : PropTypes.func.isRequired }; const mapStateToProps = (state) => { const producersArray = Object.values(state.producers); const audioProducer = producersArray.find((producer) => producer.track.kind === 'audio'); const videoProducer = producersArray.find((producer) => producer.track.kind === 'video'); return { connected : state.room.state === 'connected', me : state.me, audioProducer : audioProducer, videoProducer : videoProducer, faceDetection : state.room.faceDetection }; }; const mapDispatchToProps = (dispatch) => { return { onSetStatsPeerId : (peerId) => dispatch(stateActions.setRoomStatsPeerId(peerId)) }; }; const MeContainer = withRoomContext(connect( mapStateToProps, mapDispatchToProps )(Me)); export default MeContainer;