Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LobbyScreen.js 9.4KB

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