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.

ConnectionIndicatorIcon.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { useEffect } from 'react';
  2. import { useDispatch } from 'react-redux';
  3. import { makeStyles } from 'tss-react/mui';
  4. import Icon from '../../../base/icons/components/Icon';
  5. import { IconConnection, IconConnectionInactive } from '../../../base/icons/svg';
  6. import { JitsiTrackEvents } from '../../../base/lib-jitsi-meet';
  7. import { trackStreamingStatusChanged } from '../../../base/tracks/actions.web';
  8. import { ITrack } from '../../../base/tracks/types';
  9. interface IProps {
  10. /**
  11. * An object containing the CSS classes.
  12. */
  13. classes: any;
  14. /**
  15. * A CSS class that interprets the current connection status as a color.
  16. */
  17. colorClass: string;
  18. /**
  19. * Disable/enable inactive indicator.
  20. */
  21. connectionIndicatorInactiveDisabled: boolean;
  22. /**
  23. * Whether or not the connection status is inactive.
  24. */
  25. isConnectionStatusInactive: boolean;
  26. /**
  27. * Whether or not the connection status is interrupted.
  28. */
  29. isConnectionStatusInterrupted?: boolean;
  30. /**
  31. * JitsiTrack instance.
  32. */
  33. track?: ITrack;
  34. }
  35. const useStyles = makeStyles()(() => {
  36. return {};
  37. });
  38. export const ConnectionIndicatorIcon = ({
  39. classes,
  40. colorClass,
  41. connectionIndicatorInactiveDisabled,
  42. isConnectionStatusInactive,
  43. isConnectionStatusInterrupted,
  44. track
  45. }: IProps) => {
  46. const { cx } = useStyles();
  47. const dispatch = useDispatch();
  48. const sourceName = track?.jitsiTrack?.getSourceName();
  49. const handleTrackStreamingStatusChanged = (jitsiTrack: any, streamingStatus: string) => {
  50. dispatch(trackStreamingStatusChanged(jitsiTrack, streamingStatus));
  51. };
  52. // TODO: replace this with a custom hook to be reused where track streaming status is needed.
  53. // TODO: In the hood the listener should updates a local track streaming status instead of that in redux store.
  54. useEffect(() => {
  55. if (track && !track.local) {
  56. track.jitsiTrack.on(JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED, handleTrackStreamingStatusChanged);
  57. dispatch(trackStreamingStatusChanged(track.jitsiTrack, track.jitsiTrack.getTrackStreamingStatus?.()));
  58. }
  59. return () => {
  60. if (track && !track.local) {
  61. track.jitsiTrack.off(
  62. JitsiTrackEvents.TRACK_STREAMING_STATUS_CHANGED,
  63. handleTrackStreamingStatusChanged
  64. );
  65. dispatch(trackStreamingStatusChanged(track.jitsiTrack, track.jitsiTrack.getTrackStreamingStatus?.()));
  66. }
  67. };
  68. }, [ sourceName ]);
  69. if (isConnectionStatusInactive) {
  70. if (connectionIndicatorInactiveDisabled) {
  71. return null;
  72. }
  73. return (
  74. <span className = 'connection_ninja'>
  75. <Icon
  76. className = { cx(classes.icon, classes.inactiveIcon, colorClass) }
  77. size = { 24 }
  78. src = { IconConnectionInactive } />
  79. </span>
  80. );
  81. }
  82. let emptyIconWrapperClassName = 'connection_empty';
  83. if (isConnectionStatusInterrupted) {
  84. // emptyIconWrapperClassName is used by the torture tests to identify lost connection status handling.
  85. emptyIconWrapperClassName = 'connection_lost';
  86. }
  87. return (
  88. <span className = { emptyIconWrapperClassName }>
  89. <Icon
  90. className = { cx(classes.icon, colorClass) }
  91. size = { 16 }
  92. src = { IconConnection } />
  93. </span>
  94. );
  95. };