import React, { PureComponent } from 'react'; import { FormattedTime, defineMessages, injectIntl } from 'react-intl'; import PropTypes from 'prop-types'; import cx from 'classnames'; import UserAvatar from '/imports/ui/components/user-avatar/component'; import SlowConnection from '/imports/ui/components/slow-connection/component'; import Switch from '/imports/ui/components/switch/component'; import Service from '../service'; import Modal from '/imports/ui/components/modal/simple/component'; import { styles } from './styles'; const intlMessages = defineMessages({ ariaTitle: { id: 'app.connection-status.ariaTitle', description: 'Connection status aria title', }, title: { id: 'app.connection-status.title', description: 'Connection status title', }, description: { id: 'app.connection-status.description', description: 'Connection status description', }, empty: { id: 'app.connection-status.empty', description: 'Connection status empty', }, more: { id: 'app.connection-status.more', description: 'More about conectivity issues', }, offline: { id: 'app.connection-status.offline', description: 'Offline user', }, dataSaving: { id: 'app.settings.dataSavingTab.description', description: 'Description of data saving', }, webcam: { id: 'app.settings.dataSavingTab.webcam', description: 'Webcam data saving switch', }, screenshare: { id: 'app.settings.dataSavingTab.screenShare', description: 'Screenshare data saving switch', }, }); const propTypes = { closeModal: PropTypes.func.isRequired, intl: PropTypes.shape({ formatMessage: PropTypes.func.isRequired, }).isRequired, }; const isConnectionStatusEmpty = (connectionStatus) => { // Check if it's defined if (!connectionStatus) return true; // Check if it's an array if (!Array.isArray(connectionStatus)) return true; // Check if is empty if (connectionStatus.length === 0) return true; return false; }; class ConnectionStatusComponent extends PureComponent { constructor(props) { super(props); this.help = Service.getHelp(); this.state = { dataSaving: props.dataSaving }; } handleDataSavingChange(key) { const { dataSaving } = this.state; dataSaving[key] = !dataSaving[key]; this.setState(dataSaving); } renderEmpty() { const { intl } = this.props; return (
{intl.formatMessage(intlMessages.empty)}
); } renderConnections() { const { connectionStatus, intl, } = this.props; if (isConnectionStatusEmpty(connectionStatus)) return this.renderEmpty(); return connectionStatus.map((conn, index) => { const dateTime = new Date(conn.timestamp); const itemStyle = {}; itemStyle[styles.even] = (index + 1) % 2 === 0; const textStyle = {}; textStyle[styles.offline] = conn.offline; return (
{conn.name.toLowerCase().slice(0, 2)}
{conn.name} {conn.offline ? ` (${intl.formatMessage(intlMessages.offline)})` : null}
); }); } renderDataSaving() { const { intl, dataSaving, } = this.props; const { viewParticipantsWebcams, viewScreenshare, } = dataSaving; return (
{intl.formatMessage(intlMessages.dataSaving)}
this.handleDataSavingChange('viewParticipantsWebcams')} ariaLabelledBy="webcam" ariaLabel={intl.formatMessage(intlMessages.webcam)} data-test="dataSavingWebcams" />
this.handleDataSavingChange('viewScreenshare')} ariaLabelledBy="screenshare" ariaLabel={intl.formatMessage(intlMessages.screenshare)} data-test="dataSavingScreenshare" />
); } render() { const { closeModal, intl, } = this.props; const { dataSaving } = this.state; return ( closeModal(dataSaving, intl)} hideBorder contentLabel={intl.formatMessage(intlMessages.ariaTitle)} >

{intl.formatMessage(intlMessages.title)}

{intl.formatMessage(intlMessages.description)} {' '} {this.help && ( {`(${intl.formatMessage(intlMessages.more)})`} ) }
{this.renderDataSaving()}
{this.renderConnections()}
); } } ConnectionStatusComponent.propTypes = propTypes; export default injectIntl(ConnectionStatusComponent);