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.

AbstractRecordingLabel.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * Implements {@code Component#getDerivedStateFromProps}.
  48. *
  49. * @inheritdoc
  50. */
  51. static getDerivedStateFromProps(props: Props, prevState: State) {
  52. return {
  53. staleLabel: props._status !== JitsiRecordingConstants.status.OFF
  54. && prevState.staleLabel ? false : prevState.staleLabel
  55. };
  56. }
  57. /**
  58. * Initializes a new {@code AbstractRecordingLabel} component.
  59. *
  60. * @inheritdoc
  61. */
  62. constructor(props: Props) {
  63. super(props);
  64. this.state = {
  65. staleLabel: false
  66. };
  67. this._updateStaleStatus({}, props);
  68. }
  69. /**
  70. * Implements {@code Component#componentDidUpdate}.
  71. *
  72. * @inheritdoc
  73. */
  74. componentDidUpdate(prevProps: Props) {
  75. this._updateStaleStatus(prevProps, this.props);
  76. }
  77. /**
  78. * Implements React {@code Component}'s render.
  79. *
  80. * @inheritdoc
  81. */
  82. render() {
  83. return this.props._status && !this.state.staleLabel
  84. ? this._renderLabel() : null;
  85. }
  86. _getLabelKey: () => ?string
  87. /**
  88. * Returns the label key that this indicator should render.
  89. *
  90. * @protected
  91. * @returns {?string}
  92. */
  93. _getLabelKey() {
  94. switch (this.props.mode) {
  95. case JitsiRecordingConstants.mode.STREAM:
  96. return 'recording.live';
  97. case JitsiRecordingConstants.mode.FILE:
  98. return 'recording.rec';
  99. default:
  100. // Invalid mode is passed to the component.
  101. return undefined;
  102. }
  103. }
  104. /**
  105. * Renders the platform specific label component.
  106. *
  107. * @protected
  108. * @returns {React$Element}
  109. */
  110. _renderLabel: () => React$Element<*>
  111. /**
  112. * Updates the stale status of the label on a prop change. A label is stale
  113. * if it's in a {@code _status} that doesn't need to be rendered anymore.
  114. *
  115. * @param {Props} oldProps - The previous props of the component.
  116. * @param {Props} newProps - The new props of the component.
  117. * @returns {void}
  118. */
  119. _updateStaleStatus(oldProps, newProps) {
  120. if (newProps._status === JitsiRecordingConstants.status.OFF) {
  121. if (oldProps._status !== JitsiRecordingConstants.status.OFF) {
  122. setTimeout(() => {
  123. // Only if it's still OFF.
  124. if (this.props._status
  125. === JitsiRecordingConstants.status.OFF) {
  126. this.setState({
  127. staleLabel: true
  128. });
  129. }
  130. }, STALE_TIMEOUT);
  131. }
  132. }
  133. }
  134. }
  135. /**
  136. * Maps (parts of) the Redux state to the associated
  137. * {@code AbstractRecordingLabel}'s props.
  138. *
  139. * @param {Object} state - The Redux state.
  140. * @param {Props} ownProps - The component's own props.
  141. * @private
  142. * @returns {{
  143. * _status: ?string
  144. * }}
  145. */
  146. export function _mapStateToProps(state: Object, ownProps: Props) {
  147. const { mode } = ownProps;
  148. return {
  149. _status: getSessionStatusToShow(state, mode)
  150. };
  151. }