For the most part the changes are taking the "static propTypes" declaration off of components and declaring them as Flow types. Sometimes to support flow some method signatures had to be added. There are some exceptions in which more had to be done to tame the beast: - AbstractVideoTrack: put in additional truthy checks for videoTrack. - Video: add truthy checks for the _videoElement ref. - shouldRenderVideoTrack function: Some component could pass null for the videoTrack argument and Flow wanted that called out explicitly. - DisplayName: Add a truthy check for the input ref before acting on it. - NumbersList: Move array checks inline for Flow to comprehend array methods could be called. Add type checks in the Object.entries loop as the value is assumed to be a mixed type by Flow. - AbstractToolbarButton: add additional truthy check for passed in type.
199 lines
4.9 KiB
JavaScript
199 lines
4.9 KiB
JavaScript
// @flow
|
|
|
|
import React, { Component } from 'react';
|
|
import { connect } from 'react-redux';
|
|
|
|
import { Dialog } from '../../base/dialog';
|
|
import { translate } from '../../base/i18n';
|
|
import { getLocalParticipant } from '../../base/participants';
|
|
import SpeakerStatsItem from './SpeakerStatsItem';
|
|
import SpeakerStatsLabels from './SpeakerStatsLabels';
|
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
/**
|
|
* The type of the React {@code Component} props of {@link SpeakerStats}
|
|
*/
|
|
type Props = {
|
|
|
|
/**
|
|
* The display name for the local participant obtained from the redux store.
|
|
*/
|
|
_localDisplayName: string,
|
|
|
|
/**
|
|
* The JitsiConference from which stats will be pulled.
|
|
*/
|
|
conference: Object,
|
|
|
|
/**
|
|
* The function to translate human-readable text.
|
|
*/
|
|
t: Function
|
|
};
|
|
|
|
/**
|
|
* The type of the React {@code Component} state of {@link SpeakerStats}
|
|
*/
|
|
type State = {
|
|
|
|
/**
|
|
* The stats summary provided by the JitsiConference.
|
|
*/
|
|
stats: Object
|
|
};
|
|
|
|
/**
|
|
* React component for displaying a list of speaker stats.
|
|
*
|
|
* @extends Component
|
|
*/
|
|
class SpeakerStats extends Component<Props, State> {
|
|
state = {
|
|
stats: {}
|
|
};
|
|
|
|
_updateInterval: IntervalID;
|
|
|
|
/**
|
|
* Initializes a new SpeakerStats instance.
|
|
*
|
|
* @param {Object} props - The read-only React Component props with which
|
|
* the new instance is to be initialized.
|
|
*/
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
// Bind event handlers so they are only bound once per instance.
|
|
this._updateStats = this._updateStats.bind(this);
|
|
}
|
|
|
|
/**
|
|
* Immediately request for updated speaker stats and begin
|
|
* polling for speaker stats updates.
|
|
*
|
|
* @inheritdoc
|
|
* @returns {void}
|
|
*/
|
|
componentWillMount() {
|
|
this._updateStats();
|
|
this._updateInterval = setInterval(this._updateStats, 1000);
|
|
}
|
|
|
|
/**
|
|
* Stop polling for speaker stats updates.
|
|
*
|
|
* @inheritdoc
|
|
* @returns {void}
|
|
*/
|
|
componentWillUnmount() {
|
|
clearInterval(this._updateInterval);
|
|
}
|
|
|
|
/**
|
|
* Implements React's {@link Component#render()}.
|
|
*
|
|
* @inheritdoc
|
|
* @returns {ReactElement}
|
|
*/
|
|
render() {
|
|
const userIds = Object.keys(this.state.stats);
|
|
const items = userIds.map(userId => this._createStatsItem(userId));
|
|
|
|
return (
|
|
<Dialog
|
|
cancelTitleKey = { 'dialog.close' }
|
|
submitDisabled = { true }
|
|
titleKey = 'speakerStats.speakerStats'>
|
|
<div className = 'speaker-stats'>
|
|
<SpeakerStatsLabels />
|
|
{ items }
|
|
</div>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Create a SpeakerStatsItem instance for the passed in user id.
|
|
*
|
|
* @param {string} userId - User id used to look up the associated
|
|
* speaker stats from the jitsi library.
|
|
* @returns {SpeakerStatsItem|null}
|
|
* @private
|
|
*/
|
|
_createStatsItem(userId) {
|
|
const statsModel = this.state.stats[userId];
|
|
|
|
if (!statsModel) {
|
|
return null;
|
|
}
|
|
|
|
const isDominantSpeaker = statsModel.isDominantSpeaker();
|
|
const dominantSpeakerTime = statsModel.getTotalDominantSpeakerTime();
|
|
const hasLeft = statsModel.hasLeft();
|
|
|
|
let displayName;
|
|
|
|
if (statsModel.isLocalStats()) {
|
|
const { t } = this.props;
|
|
const meString = t('me');
|
|
|
|
displayName = this.props._localDisplayName;
|
|
displayName
|
|
= displayName ? `${displayName} (${meString})` : meString;
|
|
} else {
|
|
displayName
|
|
= this.state.stats[userId].getDisplayName()
|
|
|| interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME;
|
|
}
|
|
|
|
return (
|
|
<SpeakerStatsItem
|
|
displayName = { displayName }
|
|
dominantSpeakerTime = { dominantSpeakerTime }
|
|
hasLeft = { hasLeft }
|
|
isDominantSpeaker = { isDominantSpeaker }
|
|
key = { userId } />
|
|
);
|
|
}
|
|
|
|
_updateStats: () => void;
|
|
|
|
/**
|
|
* Update the internal state with the latest speaker stats.
|
|
*
|
|
* @returns {void}
|
|
* @private
|
|
*/
|
|
_updateStats() {
|
|
const stats = this.props.conference.getSpeakerStats();
|
|
|
|
this.setState({ stats });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Maps (parts of) the redux state to the associated SpeakerStats's props.
|
|
*
|
|
* @param {Object} state - The redux state.
|
|
* @private
|
|
* @returns {{
|
|
* _localDisplayName: ?string
|
|
* }}
|
|
*/
|
|
function _mapStateToProps(state) {
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
return {
|
|
/**
|
|
* The local display name.
|
|
*
|
|
* @private
|
|
* @type {string|undefined}
|
|
*/
|
|
_localDisplayName: localParticipant && localParticipant.name
|
|
};
|
|
}
|
|
|
|
export default translate(connect(_mapStateToProps)(SpeakerStats));
|