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

RecordingLabel.web.js 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { CircularLabel } from '../../base/label';
  4. import { translate } from '../../base/i18n';
  5. import { JitsiRecordingConstants } from '../../base/lib-jitsi-meet';
  6. /**
  7. * The translation keys to use when displaying messages. The values are set
  8. * lazily to work around circular dependency issues with lib-jitsi-meet causing
  9. * undefined imports.
  10. *
  11. * @private
  12. * @type {Object}
  13. */
  14. let TRANSLATION_KEYS_BY_MODE = null;
  15. /**
  16. * Lazily initializes TRANSLATION_KEYS_BY_MODE with translation keys to be used
  17. * by the {@code RecordingLabel} for messaging recording session state.
  18. *
  19. * @private
  20. * @returns {Object}
  21. */
  22. function _getTranslationKeysByMode() {
  23. if (!TRANSLATION_KEYS_BY_MODE) {
  24. const {
  25. error: errorConstants,
  26. mode: modeConstants,
  27. status: statusConstants
  28. } = JitsiRecordingConstants;
  29. TRANSLATION_KEYS_BY_MODE = {
  30. [modeConstants.FILE]: {
  31. status: {
  32. [statusConstants.PENDING]: 'recording.pending',
  33. [statusConstants.OFF]: 'recording.off'
  34. },
  35. errors: {
  36. [errorConstants.BUSY]: 'recording.failedToStart',
  37. [errorConstants.ERROR]: 'recording.error'
  38. }
  39. },
  40. [modeConstants.STREAM]: {
  41. status: {
  42. [statusConstants.PENDING]: 'liveStreaming.pending',
  43. [statusConstants.OFF]: 'liveStreaming.off'
  44. },
  45. errors: {
  46. [errorConstants.BUSY]: 'liveStreaming.busy',
  47. [errorConstants.ERROR]: 'liveStreaming.error'
  48. }
  49. }
  50. };
  51. }
  52. return TRANSLATION_KEYS_BY_MODE;
  53. }
  54. /**
  55. * The type of the React {@code Component} props of {@link RecordingLabel}.
  56. */
  57. type Props = {
  58. /**
  59. * The redux representation of a recording session.
  60. */
  61. session: Object,
  62. /**
  63. * Invoked to obtain translated strings.
  64. */
  65. t: Function
  66. };
  67. /**
  68. * The type of the React {@code Component} state of {@link RecordingLabel}.
  69. */
  70. type State = {
  71. /**
  72. * Whether or not the {@link RecordingLabel} should be invisible.
  73. */
  74. hidden: boolean
  75. };
  76. /**
  77. * Implements a React {@link Component} which displays the current state of
  78. * conference recording.
  79. *
  80. * @extends {Component}
  81. */
  82. class RecordingLabel extends Component<Props, State> {
  83. _autohideTimeout: number;
  84. state = {
  85. hidden: false
  86. };
  87. static defaultProps = {
  88. session: {}
  89. };
  90. /**
  91. * Sets a timeout to automatically hide the {@link RecordingLabel} if the
  92. * recording session started as failed.
  93. *
  94. * @inheritdoc
  95. */
  96. componentDidMount() {
  97. if (this.props.session.status === JitsiRecordingConstants.status.OFF) {
  98. this._setHideTimeout();
  99. }
  100. }
  101. /**
  102. * Sets a timeout to automatically hide {the @link RecordingLabel} if it has
  103. * transitioned to off.
  104. *
  105. * @inheritdoc
  106. */
  107. componentWillReceiveProps(nextProps) {
  108. const { status } = this.props.session;
  109. const nextStatus = nextProps.session.status;
  110. if (status !== JitsiRecordingConstants.status.OFF
  111. && nextStatus === JitsiRecordingConstants.status.OFF) {
  112. this._setHideTimeout();
  113. }
  114. }
  115. /**
  116. * Clears the timeout for automatically hiding the {@link RecordingLabel}.
  117. *
  118. * @inheritdoc
  119. */
  120. componentWillUnmount() {
  121. this._clearAutoHideTimeout();
  122. }
  123. /**
  124. * Implements React's {@link Component#render()}.
  125. *
  126. * @inheritdoc
  127. * @returns {ReactElement}
  128. */
  129. render() {
  130. if (this.state.hidden) {
  131. return null;
  132. }
  133. const {
  134. error: errorConstants,
  135. mode: modeConstants,
  136. status: statusConstants
  137. } = JitsiRecordingConstants;
  138. const { session } = this.props;
  139. const allTranslationKeys = _getTranslationKeysByMode();
  140. const translationKeys = allTranslationKeys[session.mode];
  141. let circularLabelClass, circularLabelKey, messageKey;
  142. switch (session.status) {
  143. case statusConstants.OFF: {
  144. if (session.error) {
  145. messageKey = translationKeys.errors[session.error]
  146. || translationKeys.errors[errorConstants.ERROR];
  147. } else {
  148. messageKey = translationKeys.status[statusConstants.OFF];
  149. }
  150. break;
  151. }
  152. case statusConstants.ON:
  153. circularLabelClass = session.mode;
  154. circularLabelKey = session.mode === modeConstants.STREAM
  155. ? 'recording.live' : 'recording.rec';
  156. break;
  157. case statusConstants.PENDING:
  158. messageKey = translationKeys.status[statusConstants.PENDING];
  159. break;
  160. }
  161. const className = `recording-label ${
  162. messageKey ? 'center-message' : ''}`;
  163. return (
  164. <div className = { className }>
  165. { messageKey
  166. ? <div>
  167. { this.props.t(messageKey) }
  168. </div>
  169. : <CircularLabel className = { circularLabelClass }>
  170. { this.props.t(circularLabelKey) }
  171. </CircularLabel> }
  172. </div>
  173. );
  174. }
  175. /**
  176. * Clears the timeout for automatically hiding {@link RecordingLabel}.
  177. *
  178. * @private
  179. * @returns {void}
  180. */
  181. _clearAutoHideTimeout() {
  182. clearTimeout(this._autohideTimeout);
  183. }
  184. /**
  185. * Sets a timeout to automatically hide {@link RecordingLabel}.
  186. *
  187. * @private
  188. * @returns {void}
  189. */
  190. _setHideTimeout() {
  191. this._autohideTimeout = setTimeout(() => {
  192. this.setState({ hidden: true });
  193. }, 5000);
  194. }
  195. }
  196. export default translate(RecordingLabel);