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

LobbyScreen.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // @flow
  2. import React from 'react';
  3. import { translate } from '../../../base/i18n';
  4. import { Icon, IconClose } from '../../../base/icons';
  5. import { ActionButton, InputField, PreMeetingScreen } from '../../../base/premeeting';
  6. import { LoadingIndicator } from '../../../base/react';
  7. import { connect } from '../../../base/redux';
  8. import ChatInput from '../../../chat/components/web/ChatInput';
  9. import MessageContainer from '../../../chat/components/web/MessageContainer';
  10. import AbstractLobbyScreen, {
  11. _mapStateToProps,
  12. type Props
  13. } from '../AbstractLobbyScreen';
  14. /**
  15. * Implements a waiting screen that represents the participant being in the lobby.
  16. */
  17. class LobbyScreen extends AbstractLobbyScreen<Props> {
  18. /**
  19. * Reference to the React Component for displaying chat messages. Used for
  20. * scrolling to the end of the chat messages.
  21. */
  22. _messageContainerRef: Object;
  23. /**
  24. * Initializes a new {@code LobbyScreen} instance.
  25. *
  26. * @param {Object} props - The read-only properties with which the new
  27. * instance is to be initialized.
  28. */
  29. constructor(props: Props) {
  30. super(props);
  31. this._messageContainerRef = React.createRef();
  32. }
  33. /**
  34. * Implements {@code Component#componentDidMount}.
  35. *
  36. * @inheritdoc
  37. */
  38. componentDidMount() {
  39. this._scrollMessageContainerToBottom(true);
  40. }
  41. /**
  42. * Implements {@code Component#componentDidUpdate}.
  43. *
  44. * @inheritdoc
  45. */
  46. componentDidUpdate(prevProps) {
  47. if (this.props._lobbyChatMessages !== prevProps._lobbyChatMessages) {
  48. this._scrollMessageContainerToBottom(true);
  49. } else if (this.props._isLobbyChatActive && !prevProps._isLobbyChatActive) {
  50. this._scrollMessageContainerToBottom(false);
  51. }
  52. }
  53. /**
  54. * Implements {@code PureComponent#render}.
  55. *
  56. * @inheritdoc
  57. */
  58. render() {
  59. const { _deviceStatusVisible, showCopyUrlButton, t } = this.props;
  60. return (
  61. <PreMeetingScreen
  62. className = 'lobby-screen'
  63. showCopyUrlButton = { showCopyUrlButton }
  64. showDeviceStatus = { _deviceStatusVisible }
  65. title = { t(this._getScreenTitleKey(), { moderator: this.props._lobbyMessageRecipient }) }>
  66. { this._renderContent() }
  67. </PreMeetingScreen>
  68. );
  69. }
  70. _getScreenTitleKey: () => string;
  71. _onAskToJoin: () => boolean;
  72. _onCancel: () => boolean;
  73. _onChangeDisplayName: Object => void;
  74. _onChangeEmail: Object => void;
  75. _onChangePassword: Object => void;
  76. _onEnableEdit: () => void;
  77. _onJoinWithPassword: () => void;
  78. _onSendMessage: () => void;
  79. _onSubmit: () => boolean;
  80. _onSwitchToKnockMode: () => void;
  81. _onSwitchToPasswordMode: () => void;
  82. _onToggleChat: () => void;
  83. _renderContent: () => React$Element<*>;
  84. /**
  85. * Renders the joining (waiting) fragment of the screen.
  86. *
  87. * @inheritdoc
  88. */
  89. _renderJoining() {
  90. const { _isLobbyChatActive } = this.props;
  91. return (
  92. <div className = 'lobby-screen-content'>
  93. {_isLobbyChatActive
  94. ? this._renderLobbyChat()
  95. : (
  96. <>
  97. <div className = 'spinner'>
  98. <LoadingIndicator size = 'large' />
  99. </div>
  100. <span className = 'joining-message'>
  101. { this.props.t('lobby.joiningMessage') }
  102. </span>
  103. </>
  104. )}
  105. { this._renderStandardButtons() }
  106. </div>
  107. );
  108. }
  109. /**
  110. * Renders the widget to chat with the moderator before allowed in.
  111. *
  112. * @inheritdoc
  113. */
  114. _renderLobbyChat() {
  115. const { _lobbyChatMessages, t } = this.props;
  116. const { isChatOpen } = this.state;
  117. return (
  118. <div className = { `lobby-chat-container ${isChatOpen ? 'hidden' : ''}` }>
  119. <div className = 'lobby-chat-header'>
  120. <h1 className = 'title'>
  121. { t(this._getScreenTitleKey(), { moderator: this.props._lobbyMessageRecipient }) }
  122. </h1>
  123. <Icon
  124. ariaLabel = { t('toolbar.closeChat') }
  125. onClick = { this._onToggleChat }
  126. role = 'button'
  127. src = { IconClose } />
  128. </div>
  129. <MessageContainer
  130. messages = { _lobbyChatMessages }
  131. ref = { this._messageContainerRef } />
  132. <ChatInput onSend = { this._onSendMessage } />
  133. </div>
  134. );
  135. }
  136. /**
  137. * Renders the participant form to let the knocking participant enter its details.
  138. *
  139. * NOTE: We don't use edit action on web since the prejoin functionality got merged.
  140. * Mobile won't use it either once prejoin gets implemented there too.
  141. *
  142. * @inheritdoc
  143. */
  144. _renderParticipantForm() {
  145. return this._renderParticipantInfo();
  146. }
  147. /**
  148. * Renders the participant info fragment when we have all the required details of the user.
  149. *
  150. * @inheritdoc
  151. */
  152. _renderParticipantInfo() {
  153. const { displayName } = this.state;
  154. const { t } = this.props;
  155. return (
  156. <InputField
  157. onChange = { this._onChangeDisplayName }
  158. placeHolder = { t('lobby.nameField') }
  159. testId = 'lobby.nameField'
  160. value = { displayName } />
  161. );
  162. }
  163. /**
  164. * Renders the password form to let the participant join by using a password instead of knocking.
  165. *
  166. * @inheritdoc
  167. */
  168. _renderPasswordForm() {
  169. const { _passwordJoinFailed, t } = this.props;
  170. return (
  171. <>
  172. <InputField
  173. className = { _passwordJoinFailed ? 'error' : '' }
  174. onChange = { this._onChangePassword }
  175. placeHolder = { t('lobby.passwordField') }
  176. testId = 'lobby.password'
  177. type = 'password'
  178. value = { this.state.password } />
  179. {_passwordJoinFailed && <div
  180. className = 'prejoin-error'
  181. data-testid = 'lobby.errorMessage'>{t('lobby.invalidPassword')}</div>}
  182. </>
  183. );
  184. }
  185. /**
  186. * Renders the password join button (set).
  187. *
  188. * @inheritdoc
  189. */
  190. _renderPasswordJoinButtons() {
  191. const { t } = this.props;
  192. return (
  193. <>
  194. <ActionButton
  195. onClick = { this._onJoinWithPassword }
  196. testId = 'lobby.passwordJoinButton'
  197. type = 'primary'>
  198. { t('prejoin.joinMeeting') }
  199. </ActionButton>
  200. <ActionButton
  201. onClick = { this._onSwitchToKnockMode }
  202. testId = 'lobby.backToKnockModeButton'
  203. type = 'secondary'>
  204. { t('lobby.backToKnockModeButton') }
  205. </ActionButton>
  206. </>
  207. );
  208. }
  209. /**
  210. * Renders the standard button set.
  211. *
  212. * @inheritdoc
  213. */
  214. _renderStandardButtons() {
  215. const { _knocking, _isLobbyChatActive, _renderPassword, t } = this.props;
  216. return (
  217. <>
  218. { _knocking || <ActionButton
  219. disabled = { !this.state.displayName }
  220. onClick = { this._onAskToJoin }
  221. testId = 'lobby.knockButton'
  222. type = 'primary'>
  223. { t('lobby.knockButton') }
  224. </ActionButton> }
  225. { (_knocking && _isLobbyChatActive) && <ActionButton
  226. className = 'open-chat-button'
  227. onClick = { this._onToggleChat }
  228. testId = 'toolbar.openChat'
  229. type = 'primary' >
  230. { t('toolbar.openChat') }
  231. </ActionButton> }
  232. {_renderPassword && <ActionButton
  233. onClick = { this._onSwitchToPasswordMode }
  234. testId = 'lobby.enterPasswordButton'
  235. type = 'secondary'>
  236. { t('lobby.enterPasswordButton') }
  237. </ActionButton> }
  238. </>
  239. );
  240. }
  241. /**
  242. * Scrolls the chat messages so the latest message is visible.
  243. *
  244. * @param {boolean} withAnimation - Whether or not to show a scrolling
  245. * animation.
  246. * @private
  247. * @returns {void}
  248. */
  249. _scrollMessageContainerToBottom(withAnimation) {
  250. if (this._messageContainerRef.current) {
  251. this._messageContainerRef.current.scrollToElement(withAnimation);
  252. }
  253. }
  254. }
  255. export default translate(connect(_mapStateToProps)(LobbyScreen));