2019-04-15 16:23:28 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
2022-02-14 10:13:18 +00:00
|
|
|
import { View } from 'react-native';
|
2019-04-15 16:23:28 +00:00
|
|
|
|
2022-11-08 10:24:32 +00:00
|
|
|
import { IconConnection } from '../../../base/icons';
|
2019-04-15 16:23:28 +00:00
|
|
|
import { BaseIndicator } from '../../../base/react';
|
|
|
|
import { connect } from '../../../base/redux';
|
2022-02-14 10:13:18 +00:00
|
|
|
import indicatorStyles from '../../../filmstrip/components/native/styles';
|
2019-04-15 16:23:28 +00:00
|
|
|
import AbstractConnectionIndicator, {
|
|
|
|
type Props,
|
|
|
|
type State
|
|
|
|
} from '../AbstractConnectionIndicator';
|
|
|
|
|
2022-02-14 10:13:18 +00:00
|
|
|
import { CONNECTOR_INDICATOR_COLORS, iconStyle } from './styles';
|
2019-08-30 16:39:06 +00:00
|
|
|
|
2019-04-15 16:23:28 +00:00
|
|
|
/**
|
|
|
|
* Implements an indicator to show the quality of the connection of a participant.
|
|
|
|
*/
|
|
|
|
class ConnectionIndicator extends AbstractConnectionIndicator<Props, State> {
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code ConnectionIndicator} instance.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
constructor(props: Props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
autoHideTimeout: undefined,
|
|
|
|
showIndicator: false,
|
|
|
|
stats: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { showIndicator, stats } = this.state;
|
|
|
|
const { percent } = stats;
|
|
|
|
|
|
|
|
if (!showIndicator || typeof percent === 'undefined') {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Signal level on a scale 0..2
|
|
|
|
const signalLevel = Math.floor(percent / 33.4);
|
|
|
|
|
|
|
|
return (
|
2022-02-14 10:13:18 +00:00
|
|
|
<View
|
|
|
|
style = {{
|
|
|
|
...indicatorStyles.indicatorContainer,
|
|
|
|
backgroundColor: CONNECTOR_INDICATOR_COLORS[signalLevel]
|
|
|
|
}}>
|
|
|
|
<BaseIndicator
|
2022-11-08 10:24:32 +00:00
|
|
|
icon = { IconConnection }
|
2022-06-17 10:08:21 +00:00
|
|
|
iconStyle = { this.props.iconStyle || iconStyle } />
|
2022-02-14 10:13:18 +00:00
|
|
|
</View>
|
2019-04-15 16:23:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect()(ConnectionIndicator);
|