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

LobbyScreen.js 9.3KB

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