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.5KB

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