2017-08-14 15:02:58 +00:00
|
|
|
import AKInlineDialog from '@atlaskit/inline-dialog';
|
2017-06-19 20:20:13 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { JitsiParticipantConnectionStatus } from '../../base/lib-jitsi-meet';
|
|
|
|
import { ConnectionStatsTable } from '../../connection-stats';
|
|
|
|
|
2017-07-05 18:17:30 +00:00
|
|
|
import statsEmitter from '../statsEmitter';
|
|
|
|
|
2017-06-19 20:20:13 +00:00
|
|
|
declare var $: Object;
|
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
// Converts the percent for connection quality into a string recognized for CSS.
|
|
|
|
const QUALITY_TO_WIDTH = [
|
|
|
|
|
|
|
|
// Full (5 bars)
|
|
|
|
{
|
|
|
|
percent: 80,
|
|
|
|
width: '100%'
|
|
|
|
},
|
|
|
|
|
|
|
|
// 4 bars
|
|
|
|
{
|
|
|
|
percent: 60,
|
|
|
|
width: '80%'
|
|
|
|
},
|
|
|
|
|
|
|
|
// 3 bars
|
|
|
|
{
|
|
|
|
percent: 40,
|
|
|
|
width: '55%'
|
|
|
|
},
|
|
|
|
|
|
|
|
// 2 bars
|
|
|
|
{
|
|
|
|
percent: 20,
|
|
|
|
width: '40%'
|
|
|
|
},
|
|
|
|
|
|
|
|
// 1 bar
|
|
|
|
{
|
|
|
|
percent: 0,
|
|
|
|
width: '20%'
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: we never show 0 bars.
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which displays the current connection
|
|
|
|
* quality percentage and has a popover to show more detailed connection stats.
|
|
|
|
*
|
|
|
|
* @extends {Component}
|
|
|
|
*/
|
|
|
|
class ConnectionIndicator extends Component {
|
|
|
|
/**
|
|
|
|
* {@code ConnectionIndicator} component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
2017-07-05 18:17:30 +00:00
|
|
|
/**
|
|
|
|
* The current condition of the user's connection, matching one of the
|
|
|
|
* enumerated values in the library.
|
|
|
|
*
|
|
|
|
* @type {JitsiParticipantConnectionStatus}
|
|
|
|
*/
|
|
|
|
connectionStatus: React.PropTypes.string,
|
|
|
|
|
2017-06-19 20:20:13 +00:00
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* Whether or not clicking the indicator should display a popover for
|
|
|
|
* more details.
|
2017-06-19 20:20:13 +00:00
|
|
|
*/
|
2017-08-14 15:02:58 +00:00
|
|
|
enableStatsDisplay: React.PropTypes.bool,
|
2017-06-19 20:20:13 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* Whether or not the displays stats are for local video.
|
2017-06-19 20:20:13 +00:00
|
|
|
*/
|
2017-08-14 15:02:58 +00:00
|
|
|
isLocalVideo: React.PropTypes.bool,
|
2017-06-19 20:20:13 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* Relative to the icon from where the popover for more connection
|
|
|
|
* details should display.
|
2017-06-19 20:20:13 +00:00
|
|
|
*/
|
2017-08-14 15:02:58 +00:00
|
|
|
statsPopoverPosition: React.PropTypes.string,
|
2017-06-19 20:20:13 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-05 18:17:30 +00:00
|
|
|
* Invoked to obtain translated strings.
|
2017-06-19 20:20:13 +00:00
|
|
|
*/
|
2017-07-05 18:17:30 +00:00
|
|
|
t: React.PropTypes.func,
|
2017-06-19 20:20:13 +00:00
|
|
|
|
|
|
|
/**
|
2017-07-05 18:17:30 +00:00
|
|
|
* The user ID associated with the displayed connection indication and
|
|
|
|
* stats.
|
2017-06-19 20:20:13 +00:00
|
|
|
*/
|
2017-07-05 18:17:30 +00:00
|
|
|
userID: React.PropTypes.string
|
2017-06-19 20:20:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code ConnectionIndicator} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
/**
|
|
|
|
* Whether or not the popover content should display additional
|
|
|
|
* statistics.
|
|
|
|
*
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2017-07-05 18:17:30 +00:00
|
|
|
showMoreStats: false,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cache of the stats received from subscribing to stats emitting.
|
|
|
|
* The keys should be the name of the stat. With each stat update,
|
|
|
|
* updates stats are mixed in with cached stats and a new stats
|
|
|
|
* object is set in state.
|
|
|
|
*/
|
|
|
|
stats: {}
|
2017-06-19 20:20:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
2017-07-05 18:17:30 +00:00
|
|
|
this._onStatsUpdated = this._onStatsUpdated.bind(this);
|
2017-08-14 15:02:58 +00:00
|
|
|
this._onStatsClose = this._onStatsClose.bind(this);
|
|
|
|
this._onStatsToggle = this._onStatsToggle.bind(this);
|
|
|
|
this._onStatsUpdated = this._onStatsUpdated.bind(this);
|
2017-06-19 20:20:13 +00:00
|
|
|
this._onToggleShowMore = this._onToggleShowMore.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* Starts listening for stat updates.
|
2017-06-19 20:20:13 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* returns {void}
|
|
|
|
*/
|
|
|
|
componentDidMount() {
|
2017-07-05 18:17:30 +00:00
|
|
|
statsEmitter.subscribeToClientStats(
|
|
|
|
this.props.userID, this._onStatsUpdated);
|
2017-06-19 20:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* Updates which user's stats are being listened to.
|
2017-06-19 20:20:13 +00:00
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* returns {void}
|
|
|
|
*/
|
2017-07-05 18:17:30 +00:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (prevProps.userID !== this.props.userID) {
|
|
|
|
statsEmitter.unsubscribeToClientStats(
|
2017-07-13 18:44:12 +00:00
|
|
|
prevProps.userID, this._onStatsUpdated);
|
2017-07-05 18:17:30 +00:00
|
|
|
statsEmitter.subscribeToClientStats(
|
|
|
|
this.props.userID, this._onStatsUpdated);
|
|
|
|
}
|
2017-06-19 20:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-14 15:02:58 +00:00
|
|
|
* Sets the state to hide the Statistics Table popover.
|
2017-06-19 20:20:13 +00:00
|
|
|
*
|
2017-08-14 15:02:58 +00:00
|
|
|
* @private
|
|
|
|
* @returns {void}
|
2017-06-19 20:20:13 +00:00
|
|
|
*/
|
|
|
|
componentWillUnmount() {
|
2017-07-05 18:17:30 +00:00
|
|
|
statsEmitter.unsubscribeToClientStats(
|
|
|
|
this.props.userID, this._onStatsUpdated);
|
2017-06-19 20:20:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
2017-08-14 15:02:58 +00:00
|
|
|
<div className = 'connection-indicator-container'>
|
|
|
|
<AKInlineDialog
|
|
|
|
content = { this._renderStatisticsTable() }
|
|
|
|
isOpen = { this.state.showStats }
|
|
|
|
onClose = { this._onStatsClose }
|
|
|
|
position = { this.props.statsPopoverPosition }>
|
|
|
|
<div
|
|
|
|
className = 'popover-trigger'
|
|
|
|
onClick = { this._onStatsToggle }>
|
|
|
|
<div className = 'connection-indicator indicator'>
|
|
|
|
<div className = 'connection indicatoricon'>
|
|
|
|
{ this._renderIcon() }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</AKInlineDialog>
|
2017-06-19 20:20:13 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-14 15:02:58 +00:00
|
|
|
/**
|
|
|
|
* Sets the state not to show the Statistics Table popover.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onStatsClose() {
|
|
|
|
this.setState({ showStats: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the state to show or hide the Statistics Table popover.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onStatsToggle() {
|
|
|
|
if (this.props.enableStatsDisplay) {
|
|
|
|
this.setState({ showStats: !this.state.showStats });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-05 18:17:30 +00:00
|
|
|
/**
|
|
|
|
* Callback invoked when new connection stats associated with the passed in
|
|
|
|
* user ID are available. Will update the component's display of current
|
|
|
|
* statistics.
|
|
|
|
*
|
|
|
|
* @param {Object} stats - Connection stats from the library.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onStatsUpdated(stats = {}) {
|
|
|
|
const { connectionQuality } = stats;
|
|
|
|
const newPercentageState = typeof connectionQuality === 'undefined'
|
|
|
|
? {} : { percent: connectionQuality };
|
|
|
|
const newStats = Object.assign(
|
|
|
|
{},
|
|
|
|
this.state.stats,
|
|
|
|
stats,
|
|
|
|
newPercentageState);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
stats: newStats
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:20:13 +00:00
|
|
|
/**
|
|
|
|
* Callback to invoke when the show more link in the popover content is
|
|
|
|
* clicked. Sets the state which will determine if the popover should show
|
|
|
|
* additional statistics about the connection.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onToggleShowMore() {
|
|
|
|
this.setState({ showMoreStats: !this.state.showMoreStats });
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a ReactElement for displaying an icon that represents the current
|
|
|
|
* connection quality.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderIcon() {
|
2017-07-05 18:17:30 +00:00
|
|
|
switch (this.props.connectionStatus) {
|
2017-06-19 20:20:13 +00:00
|
|
|
case JitsiParticipantConnectionStatus.INTERRUPTED:
|
|
|
|
return (
|
|
|
|
<span className = 'connection_lost'>
|
|
|
|
<i className = 'icon-connection-lost' />
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
case JitsiParticipantConnectionStatus.INACTIVE:
|
|
|
|
return (
|
|
|
|
<span className = 'connection_ninja'>
|
|
|
|
<i className = 'icon-ninja' />
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
default: {
|
2017-07-05 18:17:30 +00:00
|
|
|
const { percent } = this.state.stats;
|
2017-06-19 20:20:13 +00:00
|
|
|
const width = QUALITY_TO_WIDTH.find(x => percent >= x.percent);
|
|
|
|
const iconWidth = width && width.width
|
|
|
|
? { width: width && width.width } : {};
|
|
|
|
|
|
|
|
return [
|
|
|
|
<span
|
|
|
|
className = 'connection_empty'
|
|
|
|
key = 'icon-empty'>
|
|
|
|
<i className = 'icon-connection' />
|
|
|
|
</span>,
|
|
|
|
<span
|
|
|
|
className = 'connection_full'
|
|
|
|
key = 'icon-full'
|
|
|
|
style = { iconWidth }>
|
|
|
|
<i className = 'icon-connection' />
|
|
|
|
</span>
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a {@code ConnectionStatisticsTable} instance.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderStatisticsTable() {
|
|
|
|
const {
|
|
|
|
bandwidth,
|
|
|
|
bitrate,
|
|
|
|
framerate,
|
|
|
|
packetLoss,
|
|
|
|
resolution,
|
|
|
|
transport
|
2017-07-05 18:17:30 +00:00
|
|
|
} = this.state.stats;
|
2017-06-19 20:20:13 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ConnectionStatsTable
|
|
|
|
bandwidth = { bandwidth }
|
|
|
|
bitrate = { bitrate }
|
|
|
|
framerate = { framerate }
|
|
|
|
isLocalVideo = { this.props.isLocalVideo }
|
|
|
|
onShowMore = { this._onToggleShowMore }
|
|
|
|
packetLoss = { packetLoss }
|
|
|
|
resolution = { resolution }
|
|
|
|
shouldShowMore = { this.state.showMoreStats }
|
|
|
|
transport = { transport } />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ConnectionIndicator;
|