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

AbstractRecordingLabel.js 4.6KB

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