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

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