2017-10-13 19:31:05 +00:00
|
|
|
// @flow
|
2017-02-17 00:59:30 +00:00
|
|
|
|
|
|
|
import React, { Component } from 'react';
|
2021-09-09 22:46:41 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
2017-02-17 00:59:30 +00:00
|
|
|
|
|
|
|
import { Dialog } from '../../base/dialog';
|
|
|
|
import { translate } from '../../base/i18n';
|
2017-10-06 17:52:23 +00:00
|
|
|
import { getLocalParticipant } from '../../base/participants';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../base/redux';
|
2021-08-13 16:10:05 +00:00
|
|
|
import { escapeRegexp } from '../../base/util';
|
2021-09-09 22:46:41 +00:00
|
|
|
import { initUpdateStats, initSearch } from '../actions';
|
|
|
|
import { SPEAKER_STATS_RELOAD_INTERVAL } from '../constants';
|
2021-09-29 03:17:49 +00:00
|
|
|
import { getSpeakerStats, getSearchCriteria } from '../functions';
|
2019-03-21 16:38:29 +00:00
|
|
|
|
2017-02-17 00:59:30 +00:00
|
|
|
import SpeakerStatsItem from './SpeakerStatsItem';
|
|
|
|
import SpeakerStatsLabels from './SpeakerStatsLabels';
|
2021-08-13 16:10:05 +00:00
|
|
|
import SpeakerStatsSearch from './SpeakerStatsSearch';
|
2017-02-17 00:59:30 +00:00
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
2017-02-17 00:59:30 +00:00
|
|
|
/**
|
2018-10-29 02:10:47 +00:00
|
|
|
* The type of the React {@code Component} props of {@link SpeakerStats}.
|
2017-02-17 00:59:30 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
2017-02-17 00:59:30 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The display name for the local participant obtained from the redux store.
|
2017-02-17 00:59:30 +00:00
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
_localDisplayName: string,
|
2017-10-06 17:52:23 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
2021-09-09 22:46:41 +00:00
|
|
|
* The speaker paricipant stats.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2021-09-09 22:46:41 +00:00
|
|
|
_stats: Object,
|
2017-02-17 00:59:30 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
2021-09-09 22:46:41 +00:00
|
|
|
* The search criteria.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2021-09-24 16:39:24 +00:00
|
|
|
_criteria: string | null,
|
2017-02-17 00:59:30 +00:00
|
|
|
|
2021-09-09 22:46:41 +00:00
|
|
|
/**
|
|
|
|
* The JitsiConference from which stats will be pulled.
|
|
|
|
*/
|
|
|
|
conference: Object,
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
2021-09-09 22:46:41 +00:00
|
|
|
* Redux store dispatch method.
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2021-09-09 22:46:41 +00:00
|
|
|
dispatch: Dispatch<any>,
|
2021-08-13 16:10:05 +00:00
|
|
|
|
|
|
|
/**
|
2021-09-09 22:46:41 +00:00
|
|
|
* The function to translate human-readable text.
|
2021-08-13 16:10:05 +00:00
|
|
|
*/
|
2021-09-09 22:46:41 +00:00
|
|
|
t: Function
|
2018-10-30 05:02:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React component for displaying a list of speaker stats.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
2021-09-09 22:46:41 +00:00
|
|
|
class SpeakerStats extends Component<Props> {
|
2018-05-29 19:54:29 +00:00
|
|
|
_updateInterval: IntervalID;
|
2017-10-13 19:31:05 +00:00
|
|
|
|
2017-02-17 00:59:30 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
// Bind event handlers so they are only bound once per instance.
|
2017-02-17 00:59:30 +00:00
|
|
|
this._updateStats = this._updateStats.bind(this);
|
2021-08-13 16:10:05 +00:00
|
|
|
this._onSearch = this._onSearch.bind(this);
|
2021-09-09 22:46:41 +00:00
|
|
|
|
|
|
|
this._updateStats();
|
2017-02-17 00:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-29 02:10:47 +00:00
|
|
|
* Begin polling for speaker stats updates.
|
2017-02-17 00:59:30 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2018-10-29 02:10:47 +00:00
|
|
|
componentDidMount() {
|
2021-09-09 22:46:41 +00:00
|
|
|
this._updateInterval = setInterval(() => this._updateStats(), SPEAKER_STATS_RELOAD_INTERVAL);
|
2017-02-17 00:59:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop polling for speaker stats updates.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearInterval(this._updateInterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2021-09-09 22:46:41 +00:00
|
|
|
const userIds = Object.keys(this.props._stats);
|
2017-02-17 00:59:30 +00:00
|
|
|
const items = userIds.map(userId => this._createStatsItem(userId));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Dialog
|
2021-09-09 22:46:41 +00:00
|
|
|
cancelKey = 'dialog.close'
|
2017-02-17 00:59:30 +00:00
|
|
|
submitDisabled = { true }
|
2021-09-09 22:46:41 +00:00
|
|
|
titleKey = 'speakerStats.speakerStats'>
|
2017-02-17 00:59:30 +00:00
|
|
|
<div className = 'speaker-stats'>
|
2021-08-13 16:10:05 +00:00
|
|
|
<SpeakerStatsSearch onSearch = { this._onSearch } />
|
2017-02-17 00:59:30 +00:00
|
|
|
<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) {
|
2021-09-09 22:46:41 +00:00
|
|
|
const statsModel = this.props._stats[userId];
|
2017-02-17 00:59:30 +00:00
|
|
|
|
2021-09-09 22:46:41 +00:00
|
|
|
if (!statsModel || statsModel.hidden) {
|
2017-02-17 00:59:30 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const isDominantSpeaker = statsModel.isDominantSpeaker();
|
|
|
|
const dominantSpeakerTime = statsModel.getTotalDominantSpeakerTime();
|
|
|
|
const hasLeft = statsModel.hasLeft();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SpeakerStatsItem
|
2021-09-24 16:39:24 +00:00
|
|
|
displayName = { statsModel.getDisplayName() }
|
2017-02-17 00:59:30 +00:00
|
|
|
dominantSpeakerTime = { dominantSpeakerTime }
|
|
|
|
hasLeft = { hasLeft }
|
|
|
|
isDominantSpeaker = { isDominantSpeaker }
|
|
|
|
key = { userId } />
|
|
|
|
);
|
|
|
|
}
|
2017-10-13 19:31:05 +00:00
|
|
|
|
2021-08-13 16:10:05 +00:00
|
|
|
_onSearch: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search the existing participants by name.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
* @param {string} criteria - The search parameter.
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
_onSearch(criteria = '') {
|
2021-09-09 22:46:41 +00:00
|
|
|
this.props.dispatch(initSearch(escapeRegexp(criteria)));
|
2021-08-13 16:10:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-13 19:31:05 +00:00
|
|
|
_updateStats: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the internal state with the latest speaker stats.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_updateStats() {
|
2021-09-24 16:39:24 +00:00
|
|
|
this.props.dispatch(initUpdateStats(() => this._getSpeakerStats()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the internal state with the latest speaker stats.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_getSpeakerStats() {
|
|
|
|
const stats = { ...this.props.conference.getSpeakerStats() };
|
|
|
|
|
|
|
|
for (const userId in stats) {
|
|
|
|
if (stats[userId]) {
|
|
|
|
if (stats[userId].isLocalStats()) {
|
|
|
|
const { t } = this.props;
|
|
|
|
const meString = t('me');
|
|
|
|
|
|
|
|
stats[userId].setDisplayName(
|
|
|
|
this.props._localDisplayName
|
|
|
|
? `${this.props._localDisplayName} (${meString})`
|
|
|
|
: meString
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!stats[userId].getDisplayName()) {
|
|
|
|
stats[userId].setDisplayName(
|
|
|
|
interfaceConfig.DEFAULT_REMOTE_DISPLAY_NAME
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return stats;
|
2017-10-13 19:31:05 +00:00
|
|
|
}
|
2017-02-17 00:59:30 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 17:52:23 +00:00
|
|
|
/**
|
2017-10-13 19:31:05 +00:00
|
|
|
* Maps (parts of) the redux state to the associated SpeakerStats's props.
|
2017-10-06 17:52:23 +00:00
|
|
|
*
|
2017-10-13 19:31:05 +00:00
|
|
|
* @param {Object} state - The redux state.
|
2017-10-06 17:52:23 +00:00
|
|
|
* @private
|
|
|
|
* @returns {{
|
2021-09-09 22:46:41 +00:00
|
|
|
* _localDisplayName: ?string,
|
2021-09-29 03:17:49 +00:00
|
|
|
* _stats: Object,
|
|
|
|
* _criteria: string,
|
2017-10-06 17:52:23 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
|
|
|
|
|
|
|
return {
|
|
|
|
/**
|
|
|
|
* The local display name.
|
2017-10-13 19:31:05 +00:00
|
|
|
*
|
2017-10-06 17:52:23 +00:00
|
|
|
* @private
|
|
|
|
* @type {string|undefined}
|
|
|
|
*/
|
2021-09-09 22:46:41 +00:00
|
|
|
_localDisplayName: localParticipant && localParticipant.name,
|
2021-09-29 03:17:49 +00:00
|
|
|
_stats: getSpeakerStats(state),
|
|
|
|
_criteria: getSearchCriteria(state)
|
2017-10-06 17:52:23 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(SpeakerStats));
|