Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

AbstractRecordingLabel.js 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. * An object containing the CSS classes.
  20. */
  21. classes: ?{[ key: string]: string},
  22. /**
  23. * The recording mode this indicator should display.
  24. */
  25. mode: string,
  26. /**
  27. * Invoked to obtain translated strings.
  28. */
  29. t: Function
  30. };
  31. /**
  32. * State of the component.
  33. */
  34. type State = {
  35. /**
  36. * True if the label status is stale, so it needs to be removed.
  37. */
  38. staleLabel: boolean
  39. };
  40. /**
  41. * The timeout after a label is considered stale. See {@code _updateStaleStatus}
  42. * for more details.
  43. */
  44. const STALE_TIMEOUT = 10 * 1000;
  45. /**
  46. * Abstract class for the {@code RecordingLabel} component.
  47. */
  48. export default class AbstractRecordingLabel
  49. extends Component<Props, State> {
  50. /**
  51. * Implements {@code Component#getDerivedStateFromProps}.
  52. *
  53. * @inheritdoc
  54. */
  55. static getDerivedStateFromProps(props: Props, prevState: State) {
  56. return {
  57. staleLabel: props._status !== JitsiRecordingConstants.status.OFF
  58. && prevState.staleLabel ? false : prevState.staleLabel
  59. };
  60. }
  61. /**
  62. * Initializes a new {@code AbstractRecordingLabel} component.
  63. *
  64. * @inheritdoc
  65. */
  66. constructor(props: Props) {
  67. super(props);
  68. this.state = {
  69. staleLabel: false
  70. };
  71. this._updateStaleStatus({}, props);
  72. }
  73. /**
  74. * Implements {@code Component#componentDidUpdate}.
  75. *
  76. * @inheritdoc
  77. */
  78. componentDidUpdate(prevProps: Props) {
  79. this._updateStaleStatus(prevProps, this.props);
  80. }
  81. /**
  82. * Implements React {@code Component}'s render.
  83. *
  84. * @inheritdoc
  85. */
  86. render() {
  87. return this.props._status && !this.state.staleLabel
  88. ? this._renderLabel() : null;
  89. }
  90. _getLabelKey: () => ?string
  91. /**
  92. * Returns the label key that this indicator should render.
  93. *
  94. * @protected
  95. * @returns {?string}
  96. */
  97. _getLabelKey() {
  98. switch (this.props.mode) {
  99. case JitsiRecordingConstants.mode.STREAM:
  100. return 'recording.live';
  101. case JitsiRecordingConstants.mode.FILE:
  102. return 'recording.rec';
  103. default:
  104. // Invalid mode is passed to the component.
  105. return undefined;
  106. }
  107. }
  108. /**
  109. * Renders the platform specific label component.
  110. *
  111. * @protected
  112. * @returns {React$Element}
  113. */
  114. _renderLabel: () => React$Element<*>
  115. /**
  116. * Updates the stale status of the label on a prop change. A label is stale
  117. * if it's in a {@code _status} that doesn't need to be rendered anymore.
  118. *
  119. * @param {Props} oldProps - The previous props of the component.
  120. * @param {Props} newProps - The new props of the component.
  121. * @returns {void}
  122. */
  123. _updateStaleStatus(oldProps, newProps) {
  124. if (newProps._status === JitsiRecordingConstants.status.OFF) {
  125. if (oldProps._status !== JitsiRecordingConstants.status.OFF) {
  126. setTimeout(() => {
  127. // Only if it's still OFF.
  128. if (this.props._status
  129. === JitsiRecordingConstants.status.OFF) {
  130. this.setState({
  131. staleLabel: true
  132. });
  133. }
  134. }, STALE_TIMEOUT);
  135. }
  136. }
  137. }
  138. }
  139. /**
  140. * Maps (parts of) the Redux state to the associated
  141. * {@code AbstractRecordingLabel}'s props.
  142. *
  143. * @param {Object} state - The Redux state.
  144. * @param {Props} ownProps - The component's own props.
  145. * @private
  146. * @returns {{
  147. * _status: ?string
  148. * }}
  149. */
  150. export function _mapStateToProps(state: Object, ownProps: Props) {
  151. const { mode } = ownProps;
  152. return {
  153. _status: getSessionStatusToShow(state, mode)
  154. };
  155. }