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

AbstractRecordingLabel.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: true
  74. };
  75. this._updateStaleStatus({}, props);
  76. }
  77. /**
  78. * Implements React {@code Component}'s componentDidMount.
  79. *
  80. * @inheritdoc
  81. */
  82. componentDidMount() {
  83. this._mounted = true;
  84. }
  85. /**
  86. * Implements React {@code Component}'s componentWillUnmount.
  87. *
  88. * @inheritdoc
  89. */
  90. componentWillUnmount() {
  91. this._mounted = false;
  92. }
  93. /**
  94. * Implements {@code Component#componentDidUpdate}.
  95. *
  96. * @inheritdoc
  97. */
  98. componentDidUpdate(prevProps: Props) {
  99. this._updateStaleStatus(prevProps, this.props);
  100. }
  101. /**
  102. * Implements React {@code Component}'s render.
  103. *
  104. * @inheritdoc
  105. */
  106. render() {
  107. return this.props._status && !this.state.staleLabel && !this.props._iAmRecorder
  108. ? this._renderLabel() : null;
  109. }
  110. _getLabelKey: () => ?string;
  111. /**
  112. * Returns the label key that this indicator should render.
  113. *
  114. * @protected
  115. * @returns {?string}
  116. */
  117. _getLabelKey() {
  118. switch (this.props.mode) {
  119. case JitsiRecordingConstants.mode.STREAM:
  120. return 'recording.live';
  121. case JitsiRecordingConstants.mode.FILE:
  122. return 'recording.rec';
  123. default:
  124. // Invalid mode is passed to the component.
  125. return undefined;
  126. }
  127. }
  128. /**
  129. * Renders the platform specific label component.
  130. *
  131. * @protected
  132. * @returns {React$Element}
  133. */
  134. _renderLabel: () => React$Element<*>;
  135. /**
  136. * Updates the stale status of the label on a prop change. A label is stale
  137. * if it's in a {@code _status} that doesn't need to be rendered anymore.
  138. *
  139. * @param {Props} oldProps - The previous props of the component.
  140. * @param {Props} newProps - The new props of the component.
  141. * @returns {void}
  142. */
  143. _updateStaleStatus(oldProps, newProps) {
  144. if (newProps._status === JitsiRecordingConstants.status.OFF) {
  145. if (oldProps._status !== JitsiRecordingConstants.status.OFF) {
  146. setTimeout(() => {
  147. if (!this._mounted) {
  148. return;
  149. }
  150. // Only if it's still OFF.
  151. if (this.props._status
  152. === JitsiRecordingConstants.status.OFF) {
  153. this.setState({
  154. staleLabel: true
  155. });
  156. }
  157. }, STALE_TIMEOUT);
  158. }
  159. }
  160. }
  161. }
  162. /**
  163. * Maps (parts of) the Redux state to the associated
  164. * {@code AbstractRecordingLabel}'s props.
  165. *
  166. * @param {Object} state - The Redux state.
  167. * @param {Props} ownProps - The component's own props.
  168. * @private
  169. * @returns {{
  170. * _status: ?string
  171. * }}
  172. */
  173. export function _mapStateToProps(state: Object, ownProps: Props) {
  174. const { mode } = ownProps;
  175. return {
  176. _iAmRecorder: state['features/base/config'].iAmRecorder,
  177. _status: getSessionStatusToShow(state, mode)
  178. };
  179. }