Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

LobbyScreen.tsx 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 { _isDisplayNameRequiredActive, t } = this.props;
  143. const showError = _isDisplayNameRequiredActive && !displayName;
  144. return (
  145. <>
  146. <Input
  147. autoFocus = { true }
  148. className = 'lobby-prejoin-input'
  149. error = { showError }
  150. id = 'lobby-name-field'
  151. onChange = { this._onChangeDisplayName }
  152. placeholder = { t('lobby.nameField') }
  153. testId = 'lobby.nameField'
  154. value = { displayName } />
  155. { showError && <div
  156. className = 'lobby-prejoin-error'
  157. data-testid = 'lobby.errorMessage'>{t('prejoin.errorMissingName')}</div>}
  158. </>
  159. );
  160. }
  161. /**
  162. * Renders the password form to let the participant join by using a password instead of knocking.
  163. *
  164. * @inheritdoc
  165. */
  166. _renderPasswordForm() {
  167. const { _passwordJoinFailed, t } = this.props;
  168. return (
  169. <>
  170. <Input
  171. className = { `lobby-prejoin-input ${_passwordJoinFailed ? 'error' : ''}` }
  172. id = 'lobby-password-input'
  173. onChange = { this._onChangePassword }
  174. placeholder = { t('lobby.enterPasswordButton') }
  175. testId = 'lobby.password'
  176. type = 'password'
  177. value = { this.state.password } />
  178. {_passwordJoinFailed && <div
  179. className = 'lobby-prejoin-error'
  180. data-testid = 'lobby.errorMessage'>{t('lobby.invalidPassword')}</div>}
  181. </>
  182. );
  183. }
  184. /**
  185. * Renders the password join button (set).
  186. *
  187. * @inheritdoc
  188. */
  189. _renderPasswordJoinButtons() {
  190. return (
  191. <>
  192. <Button
  193. className = 'lobby-button-margin'
  194. fullWidth = { true }
  195. labelKey = 'prejoin.joinMeeting'
  196. onClick = { this._onJoinWithPassword }
  197. testId = 'lobby.passwordJoinButton'
  198. type = 'primary' />
  199. <Button
  200. className = 'lobby-button-margin'
  201. fullWidth = { true }
  202. labelKey = 'lobby.backToKnockModeButton'
  203. onClick = { this._onSwitchToKnockMode }
  204. testId = 'lobby.backToKnockModeButton'
  205. type = 'secondary' />
  206. </>
  207. );
  208. }
  209. /**
  210. * Renders the standard button set.
  211. *
  212. * @inheritdoc
  213. */
  214. _renderStandardButtons() {
  215. const { _knocking, _isLobbyChatActive, _renderPassword } = this.props;
  216. return (
  217. <>
  218. {_knocking || <Button
  219. className = 'lobby-button-margin'
  220. disabled = { !this.state.displayName }
  221. fullWidth = { true }
  222. labelKey = 'lobby.knockButton'
  223. onClick = { this._onAskToJoin }
  224. testId = 'lobby.knockButton'
  225. type = 'primary' />
  226. }
  227. {(_knocking && _isLobbyChatActive) && <Button
  228. className = 'lobby-button-margin open-chat-button'
  229. fullWidth = { true }
  230. labelKey = 'toolbar.openChat'
  231. onClick = { this._onToggleChat }
  232. testId = 'toolbar.openChat'
  233. type = 'primary' />
  234. }
  235. {_renderPassword && <Button
  236. className = 'lobby-button-margin'
  237. fullWidth = { true }
  238. labelKey = 'lobby.enterPasswordButton'
  239. onClick = { this._onSwitchToPasswordMode }
  240. testId = 'lobby.enterPasswordButton'
  241. type = 'secondary' />
  242. }
  243. </>
  244. );
  245. }
  246. /**
  247. * Scrolls the chat messages so the latest message is visible.
  248. *
  249. * @param {boolean} withAnimation - Whether or not to show a scrolling
  250. * animation.
  251. * @private
  252. * @returns {void}
  253. */
  254. _scrollMessageContainerToBottom(withAnimation: boolean) {
  255. if (this._messageContainerRef.current) {
  256. this._messageContainerRef.current.scrollToElement(withAnimation, null);
  257. }
  258. }
  259. }
  260. export default translate(connect(_mapStateToProps)(LobbyScreen));