您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ConnectionIndicatorIcon.js 3.2KB

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