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

LobbyScreen.js 9.2KB

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