You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConnectionIndicator.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // @flow
  2. import React from 'react';
  3. import { View } from 'react-native';
  4. import { IconConnectionActive } from '../../../base/icons';
  5. import { BaseIndicator } from '../../../base/react';
  6. import { connect } from '../../../base/redux';
  7. import indicatorStyles from '../../../filmstrip/components/native/styles';
  8. import AbstractConnectionIndicator, {
  9. type Props,
  10. type State
  11. } from '../AbstractConnectionIndicator';
  12. import { CONNECTOR_INDICATOR_COLORS, iconStyle } from './styles';
  13. /**
  14. * Implements an indicator to show the quality of the connection of a participant.
  15. */
  16. class ConnectionIndicator extends AbstractConnectionIndicator<Props, State> {
  17. /**
  18. * Initializes a new {@code ConnectionIndicator} instance.
  19. *
  20. * @inheritdoc
  21. */
  22. constructor(props: Props) {
  23. super(props);
  24. this.state = {
  25. autoHideTimeout: undefined,
  26. showIndicator: false,
  27. stats: {}
  28. };
  29. }
  30. /**
  31. * Implements React's {@link Component#render()}.
  32. *
  33. * @inheritdoc
  34. * @returns {ReactElement}
  35. */
  36. render() {
  37. const { showIndicator, stats } = this.state;
  38. const { percent } = stats;
  39. if (!showIndicator || typeof percent === 'undefined') {
  40. return null;
  41. }
  42. // Signal level on a scale 0..2
  43. const signalLevel = Math.floor(percent / 33.4);
  44. return (
  45. <View
  46. style = {{
  47. ...indicatorStyles.indicatorContainer,
  48. backgroundColor: CONNECTOR_INDICATOR_COLORS[signalLevel]
  49. }}>
  50. <BaseIndicator
  51. icon = { IconConnectionActive }
  52. iconStyle = { iconStyle } />
  53. </View>
  54. );
  55. }
  56. }
  57. export default connect()(ConnectionIndicator);