Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AbstractRecordingLabel.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // @flow
  2. import { Component } from 'react';
  3. import { JitsiRecordingConstants } from '../../base/lib-jitsi-meet';
  4. import { getSessionStatusToShow } from '../functions';
  5. /**
  6. * NOTE: Web currently renders multiple indicators if multiple recording
  7. * sessions are running. This is however may not be a good UX as it's not
  8. * obvious why there are multiple similar 'REC' indicators rendered. Mobile
  9. * only renders one indicator if there is at least one recording session
  10. * running. These boolean are shared across the two components to make it
  11. * easier to align web's behaviour to mobile's later if necessary.
  12. */
  13. type Props = {
  14. /**
  15. * The status of the highermost priority session.
  16. */
  17. _status: ?string,
  18. /**
  19. * The recording mode this indicator should display.
  20. */
  21. mode: string,
  22. /**
  23. * Invoked to obtain translated strings.
  24. */
  25. t: Function
  26. };
  27. /**
  28. * State of the component.
  29. */
  30. type State = {
  31. /**
  32. * True if the label status is stale, so it needs to be removed.
  33. */
  34. staleLabel: boolean
  35. };
  36. /**
  37. * The timeout after a label is considered stale. See {@code _updateStaleStatus}
  38. * for more details.
  39. */
  40. const STALE_TIMEOUT = 10 * 1000;
  41. /**
  42. * Abstract class for the {@code RecordingLabel} component.
  43. */
  44. export default class AbstractRecordingLabel
  45. extends Component<Props, State> {
  46. /**
  47. * Initializes a new {@code AbstractRecordingLabel} component.
  48. *
  49. * @inheritdoc
  50. */
  51. constructor(props: Props) {
  52. super(props);
  53. this.state = {
  54. staleLabel: false
  55. };
  56. this._updateStaleStatus({}, props);
  57. }
  58. /**
  59. * Implements {@code Component#componentWillReceiveProps}.
  60. *
  61. * @inheritdoc
  62. */
  63. componentWillReceiveProps(newProps: Props) {
  64. this._updateStaleStatus(this.props, newProps);
  65. }
  66. /**
  67. * Implements React {@code Component}'s render.
  68. *
  69. * @inheritdoc
  70. */
  71. render() {
  72. return this.props._status && !this.state.staleLabel
  73. ? this._renderLabel() : null;
  74. }
  75. _getLabelKey: () => ?string
  76. /**
  77. * Returns the label key that this indicator should render.
  78. *
  79. * @protected
  80. * @returns {?string}
  81. */
  82. _getLabelKey() {
  83. switch (this.props.mode) {
  84. case JitsiRecordingConstants.mode.STREAM:
  85. return 'recording.live';
  86. case JitsiRecordingConstants.mode.FILE:
  87. return 'recording.rec';
  88. default:
  89. // Invalid mode is passed to the component.
  90. return undefined;
  91. }
  92. }
  93. /**
  94. * Renders the platform specific label component.
  95. *
  96. * @protected
  97. * @returns {React$Element}
  98. */
  99. _renderLabel: () => React$Element<*>
  100. /**
  101. * Updates the stale status of the label on a prop change. A label is stale
  102. * if it's in a {@code _status} that doesn't need to be rendered anymore.
  103. *
  104. * @param {Props} oldProps - The previous props of the component.
  105. * @param {Props} newProps - The new props of the component.
  106. * @returns {void}
  107. */
  108. _updateStaleStatus(oldProps, newProps) {
  109. if (newProps._status === JitsiRecordingConstants.status.OFF) {
  110. if (oldProps._status !== JitsiRecordingConstants.status.OFF) {
  111. setTimeout(() => {
  112. // Only if it's still OFF.
  113. if (this.props._status
  114. === JitsiRecordingConstants.status.OFF) {
  115. this.setState({
  116. staleLabel: true
  117. });
  118. }
  119. }, STALE_TIMEOUT);
  120. }
  121. } else if (this.state.staleLabel) {
  122. this.setState({
  123. staleLabel: false
  124. });
  125. }
  126. }
  127. }
  128. /**
  129. * Maps (parts of) the Redux state to the associated
  130. * {@code AbstractRecordingLabel}'s props.
  131. *
  132. * @param {Object} state - The Redux state.
  133. * @param {Props} ownProps - The component's own props.
  134. * @private
  135. * @returns {{
  136. * _status: ?string
  137. * }}
  138. */
  139. export function _mapStateToProps(state: Object, ownProps: Props) {
  140. const { mode } = ownProps;
  141. return {
  142. _status: getSessionStatusToShow(state, mode)
  143. };
  144. }