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.

LobbyScreen.tsx 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { translate } from '../../../base/i18n/functions';
  4. import Icon from '../../../base/icons/components/Icon';
  5. import { IconCloseLarge } from '../../../base/icons/svg';
  6. import PreMeetingScreen from '../../../base/premeeting/components/web/PreMeetingScreen';
  7. import LoadingIndicator from '../../../base/react/components/web/LoadingIndicator';
  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. IProps,
  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<IProps> {
  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: React.RefObject<MessageContainer>;
  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: IProps) {
  32. super(props);
  33. this._messageContainerRef = React.createRef<MessageContainer>();
  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: IProps) {
  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. /**
  73. * Renders the joining (waiting) fragment of the screen.
  74. *
  75. * @inheritdoc
  76. */
  77. _renderJoining() {
  78. const { _isLobbyChatActive } = this.props;
  79. return (
  80. <div className = 'lobby-screen-content'>
  81. {_isLobbyChatActive
  82. ? this._renderLobbyChat()
  83. : (
  84. <>
  85. <div className = 'spinner'>
  86. <LoadingIndicator size = 'large' />
  87. </div>
  88. <span className = 'joining-message'>
  89. { this.props.t('lobby.joiningMessage') }
  90. </span>
  91. </>
  92. )}
  93. { this._renderStandardButtons() }
  94. </div>
  95. );
  96. }
  97. /**
  98. * Renders the widget to chat with the moderator before allowed in.
  99. *
  100. * @inheritdoc
  101. */
  102. _renderLobbyChat() {
  103. const { _lobbyChatMessages, t } = this.props;
  104. const { isChatOpen } = this.state;
  105. return (
  106. <div className = { `lobby-chat-container ${isChatOpen ? 'hidden' : ''}` }>
  107. <div className = 'lobby-chat-header'>
  108. <h1 className = 'title'>
  109. { t(this._getScreenTitleKey(), { moderator: this.props._lobbyMessageRecipient }) }
  110. </h1>
  111. <Icon
  112. ariaLabel = { t('toolbar.closeChat') }
  113. onClick = { this._onToggleChat }
  114. role = 'button'
  115. src = { IconCloseLarge } />
  116. </div>
  117. <MessageContainer
  118. messages = { _lobbyChatMessages }
  119. ref = { this._messageContainerRef } />
  120. <ChatInput onSend = { this._onSendMessage } />
  121. </div>
  122. );
  123. }
  124. /**
  125. * Renders the participant form to let the knocking participant enter its details.
  126. *
  127. * NOTE: We don't use edit action on web since the prejoin functionality got merged.
  128. * Mobile won't use it either once prejoin gets implemented there too.
  129. *
  130. * @inheritdoc
  131. */
  132. _renderParticipantForm() {
  133. return this._renderParticipantInfo();
  134. }
  135. /**
  136. * Renders the participant info fragment when we have all the required details of the user.
  137. *
  138. * @inheritdoc
  139. */
  140. _renderParticipantInfo() {
  141. const { displayName } = this.state;
  142. const { t } = this.props;
  143. return (
  144. <Input
  145. className = 'lobby-prejoin-input'
  146. onChange = { this._onChangeDisplayName }
  147. placeholder = { t('lobby.nameField') }
  148. testId = 'lobby.nameField'
  149. value = { displayName } />
  150. );
  151. }
  152. /**
  153. * Renders the password form to let the participant join by using a password instead of knocking.
  154. *
  155. * @inheritdoc
  156. */
  157. _renderPasswordForm() {
  158. const { _passwordJoinFailed, t } = this.props;
  159. return (
  160. <>
  161. <Input
  162. className = { `lobby-prejoin-input ${_passwordJoinFailed ? 'error' : ''}` }
  163. onChange = { this._onChangePassword }
  164. placeholder = { t('lobby.passwordField') }
  165. testId = 'lobby.password'
  166. type = 'password'
  167. value = { this.state.password } />
  168. {_passwordJoinFailed && <div
  169. className = 'lobby-prejoin-error'
  170. data-testid = 'lobby.errorMessage'>{t('lobby.invalidPassword')}</div>}
  171. </>
  172. );
  173. }
  174. /**
  175. * Renders the password join button (set).
  176. *
  177. * @inheritdoc
  178. */
  179. _renderPasswordJoinButtons() {
  180. return (
  181. <>
  182. <Button
  183. className = 'lobby-button-margin'
  184. fullWidth = { true }
  185. labelKey = 'prejoin.joinMeeting'
  186. onClick = { this._onJoinWithPassword }
  187. testId = 'lobby.passwordJoinButton'
  188. type = 'primary' />
  189. <Button
  190. className = 'lobby-button-margin'
  191. fullWidth = { true }
  192. labelKey = 'lobby.backToKnockModeButton'
  193. onClick = { this._onSwitchToKnockMode }
  194. testId = 'lobby.backToKnockModeButton'
  195. type = 'secondary' />
  196. </>
  197. );
  198. }
  199. /**
  200. * Renders the standard button set.
  201. *
  202. * @inheritdoc
  203. */
  204. _renderStandardButtons() {
  205. const { _knocking, _isLobbyChatActive, _renderPassword } = this.props;
  206. return (
  207. <>
  208. {_knocking || <Button
  209. className = 'lobby-button-margin'
  210. disabled = { !this.state.displayName }
  211. fullWidth = { true }
  212. labelKey = 'lobby.knockButton'
  213. onClick = { this._onAskToJoin }
  214. testId = 'lobby.knockButton'
  215. type = 'primary' />
  216. }
  217. {(_knocking && _isLobbyChatActive) && <Button
  218. className = 'lobby-button-margin open-chat-button'
  219. fullWidth = { true }
  220. labelKey = 'toolbar.openChat'
  221. onClick = { this._onToggleChat }
  222. testId = 'toolbar.openChat'
  223. type = 'primary' />
  224. }
  225. {_renderPassword && <Button
  226. className = 'lobby-button-margin'
  227. fullWidth = { true }
  228. labelKey = 'lobby.enterPasswordButton'
  229. onClick = { this._onSwitchToPasswordMode }
  230. testId = 'lobby.enterPasswordButton'
  231. type = 'secondary' />
  232. }
  233. </>
  234. );
  235. }
  236. /**
  237. * Scrolls the chat messages so the latest message is visible.
  238. *
  239. * @param {boolean} withAnimation - Whether or not to show a scrolling
  240. * animation.
  241. * @private
  242. * @returns {void}
  243. */
  244. _scrollMessageContainerToBottom(withAnimation: boolean) {
  245. if (this._messageContainerRef.current) {
  246. this._messageContainerRef.current.scrollToElement(withAnimation, null);
  247. }
  248. }
  249. }
  250. export default translate(connect(_mapStateToProps)(LobbyScreen));