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.ts 4.7KB

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