/* @flow */ import moment from 'moment'; import React, { Component } from 'react'; import { connect } from 'react-redux'; import { Dialog } from '../../base/dialog'; import { translate } from '../../base/i18n'; import { PARTICIPANT_ROLE, getLocalParticipant } from '../../base/participants'; import { statsUpdate } from '../actions'; import { recordingController } from '../controller'; /** * The type of the React {@code Component} props of * {@link LocalRecordingInfoDialog}. */ type Props = { /** * Redux store dispatch function. */ dispatch: Dispatch<*>, /** * Current encoding format. */ encodingFormat: string, /** * Whether the local user is the moderator. */ isModerator: boolean, /** * Whether local recording is engaged. */ isEngaged: boolean, /** * The start time of the current local recording session. * Used to calculate the duration of recording. */ recordingEngagedAt: Date, /** * Stats of all the participant. */ stats: Object, /** * Invoked to obtain translated strings. */ t: Function } /** * The type of the React {@code Component} state of * {@link LocalRecordingInfoDialog}. */ type State = { /** * The recording duration string to be displayed on the UI. */ durationString: string } /** * A React Component with the contents for a dialog that shows information about * local recording. For users with moderator rights, this is also the "control * panel" for starting/stopping local recording on all clients. * * @extends Component */ class LocalRecordingInfoDialog extends Component { /** * Saves a handle to the timer for UI updates, * so that it can be cancelled when the component unmounts. */ _timer: ?IntervalID; /** * Initializes a new {@code LocalRecordingInfoDialog} instance. * * @param {Props} props - The React {@code Component} props to initialize * the new {@code LocalRecordingInfoDialog} instance with. */ constructor(props: Props) { super(props); this.state = { durationString: '' }; } /** * Implements React's {@link Component#componentDidMount()}. * * @returns {void} */ componentDidMount() { this._timer = setInterval( () => { this.setState((_prevState, props) => { const nowTime = new Date(); return { durationString: this._getDuration(nowTime, props.recordingEngagedAt) }; }); try { this.props.dispatch( statsUpdate(recordingController .getParticipantsStats())); } catch (e) { // do nothing } }, 1000 ); } /** * Implements React's {@link Component#componentWillUnmount()}. * * @returns {void} */ componentWillUnmount() { if (this._timer) { clearInterval(this._timer); this._timer = null; } } /** * Implements React's {@link Component#render()}. * * @inheritdoc * @returns {ReactElement} */ render() { const { isModerator, t } = this.props; return (

{ t('localRecording.localRecording') }
{`${t('localRecording.moderator')}:`}   { isModerator ? t('localRecording.yes') : t('localRecording.no') }
{ this._renderDurationAndFormat() } { this._renderModeratorControls() }
); } /** * Renders the recording duration and encoding format. Only shown if local * recording is engaged. * * @private * @returns {ReactElement|null} */ _renderDurationAndFormat() { const { encodingFormat, isEngaged, t } = this.props; const { durationString } = this.state; if (!isEngaged) { return null; } return (
{`${t('localRecording.duration')}:`}   { durationString === '' ? t('localRecording.durationNA') : durationString }
{`${t('localRecording.encoding')}:`}   { encodingFormat }
); } /** * Returns React elements for displaying the local recording stats of * each participant. * * @private * @returns {ReactElement} */ _renderStats() { const { stats } = this.props; if (stats === undefined) { return