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.

AbstractLobbyScreen.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. // @flow
  2. // eslint-disable-next-line no-unused-vars
  3. import React, { PureComponent } from 'react';
  4. import { conferenceWillJoin, getConferenceName } from '../../base/conference';
  5. import { getSecurityUiConfig } from '../../base/config/functions.any';
  6. import { INVITE_ENABLED, getFeatureFlag } from '../../base/flags';
  7. import { getLocalParticipant } from '../../base/participants';
  8. import { getFieldValue } from '../../base/react';
  9. import { updateSettings } from '../../base/settings';
  10. import { isDeviceStatusVisible } from '../../prejoin/functions';
  11. import { cancelKnocking, joinWithPassword, onSendMessage, setPasswordJoinFailed, startKnocking } from '../actions';
  12. export const SCREEN_STATES = {
  13. EDIT: 1,
  14. PASSWORD: 2,
  15. VIEW: 3
  16. };
  17. export type Props = {
  18. /**
  19. * Indicates whether the device status should be visible.
  20. */
  21. _deviceStatusVisible: boolean,
  22. /**
  23. * True if knocking is already happening, so we're waiting for a response.
  24. */
  25. _knocking: boolean,
  26. /**
  27. * Lobby messages between moderator and the participant.
  28. */
  29. _lobbyChatMessages: Object,
  30. /**
  31. * Name of the lobby chat recipient.
  32. */
  33. _lobbyMessageRecipient: string,
  34. /**
  35. * True if moderator initiated a chat session with the participant.
  36. */
  37. _isLobbyChatActive: boolean,
  38. /**
  39. * The name of the meeting we're about to join.
  40. */
  41. _meetingName: string,
  42. /**
  43. * The members only conference if any,.
  44. */
  45. _membersOnlyConference: Object,
  46. /**
  47. * The email of the participant about to knock/join.
  48. */
  49. _participantEmail: string,
  50. /**
  51. * The id of the participant about to knock/join. This is the participant ID in the lobby room, at this point.
  52. */
  53. _participantId: string,
  54. /**
  55. * The name of the participant about to knock/join.
  56. */
  57. _participantName: string;
  58. /**
  59. * True if a recent attempt to join with password failed.
  60. */
  61. _passwordJoinFailed: boolean,
  62. /**
  63. * True if the password field should be available for lobby participants.
  64. */
  65. _renderPassword: boolean,
  66. /**
  67. * The Redux dispatch function.
  68. */
  69. dispatch: Function,
  70. /**
  71. * Indicates whether the copy url button should be shown.
  72. */
  73. showCopyUrlButton: boolean,
  74. /**
  75. * Function to be used to translate i18n labels.
  76. */
  77. t: Function
  78. };
  79. type State = {
  80. /**
  81. * The display name value entered into the field.
  82. */
  83. displayName: string,
  84. /**
  85. * The email value entered into the field.
  86. */
  87. email: string,
  88. /**
  89. * True if lobby chat widget is open.
  90. */
  91. isChatOpen: boolean,
  92. /**
  93. * The password value entered into the field.
  94. */
  95. password: string,
  96. /**
  97. * True if a recent attempt to join with password failed.
  98. */
  99. passwordJoinFailed: boolean,
  100. /**
  101. * The state of the screen. One of {@code SCREEN_STATES[*]}.
  102. */
  103. screenState: number
  104. }
  105. /**
  106. * Abstract class to encapsulate the platform common code of the {@code LobbyScreen}.
  107. */
  108. export default class AbstractLobbyScreen<P: Props = Props> extends PureComponent<P, State> {
  109. /**
  110. * Instantiates a new component.
  111. *
  112. * @inheritdoc
  113. */
  114. constructor(props: P) {
  115. super(props);
  116. this.state = {
  117. displayName: props._participantName || '',
  118. email: props._participantEmail || '',
  119. isChatOpen: true,
  120. password: '',
  121. passwordJoinFailed: false,
  122. screenState: props._participantName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  123. };
  124. this._onAskToJoin = this._onAskToJoin.bind(this);
  125. this._onCancel = this._onCancel.bind(this);
  126. this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
  127. this._onChangeEmail = this._onChangeEmail.bind(this);
  128. this._onChangePassword = this._onChangePassword.bind(this);
  129. this._onEnableEdit = this._onEnableEdit.bind(this);
  130. this._onJoinWithPassword = this._onJoinWithPassword.bind(this);
  131. this._onSendMessage = this._onSendMessage.bind(this);
  132. this._onSwitchToKnockMode = this._onSwitchToKnockMode.bind(this);
  133. this._onSwitchToPasswordMode = this._onSwitchToPasswordMode.bind(this);
  134. this._onToggleChat = this._onToggleChat.bind(this);
  135. }
  136. /**
  137. * Implements {@code PureComponent.getDerivedStateFromProps}.
  138. *
  139. * @inheritdoc
  140. */
  141. static getDerivedStateFromProps(props: Props, state: State) {
  142. if (props._passwordJoinFailed && !state.passwordJoinFailed) {
  143. return {
  144. password: '',
  145. passwordJoinFailed: true
  146. };
  147. }
  148. return null;
  149. }
  150. /**
  151. * Returns the screen title.
  152. *
  153. * @returns {string}
  154. */
  155. _getScreenTitleKey() {
  156. const { screenState } = this.state;
  157. const passwordPrompt = screenState === SCREEN_STATES.PASSWORD;
  158. return !passwordPrompt && this.props._knocking
  159. ? this.props._isLobbyChatActive ? 'lobby.lobbyChatStartedTitle' : 'lobby.joiningTitle'
  160. : passwordPrompt ? 'lobby.enterPasswordTitle' : 'lobby.joinTitle';
  161. }
  162. _onAskToJoin: () => void;
  163. /**
  164. * Callback to be invoked when the user submits the joining request.
  165. *
  166. * @returns {void}
  167. */
  168. _onAskToJoin() {
  169. this.setState({
  170. password: ''
  171. });
  172. this.props.dispatch(startKnocking());
  173. return false;
  174. }
  175. _onCancel: () => boolean;
  176. /**
  177. * Callback to be invoked when the user cancels the dialog.
  178. *
  179. * @private
  180. * @returns {boolean}
  181. */
  182. _onCancel() {
  183. this.props.dispatch(cancelKnocking());
  184. return true;
  185. }
  186. _onChangeDisplayName: Object => void;
  187. /**
  188. * Callback to be invoked when the user changes its display name.
  189. *
  190. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  191. * @returns {void}
  192. */
  193. _onChangeDisplayName(event) {
  194. const displayName = getFieldValue(event);
  195. this.setState({
  196. displayName
  197. }, () => {
  198. this.props.dispatch(updateSettings({
  199. displayName
  200. }));
  201. });
  202. }
  203. _onChangeEmail: Object => void;
  204. /**
  205. * Callback to be invoked when the user changes its email.
  206. *
  207. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  208. * @returns {void}
  209. */
  210. _onChangeEmail(event) {
  211. const email = getFieldValue(event);
  212. this.setState({
  213. email
  214. }, () => {
  215. this.props.dispatch(updateSettings({
  216. email
  217. }));
  218. });
  219. }
  220. _onChangePassword: Object => void;
  221. /**
  222. * Callback to be invoked when the user changes the password.
  223. *
  224. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  225. * @returns {void}
  226. */
  227. _onChangePassword(event) {
  228. this.setState({
  229. password: getFieldValue(event)
  230. });
  231. }
  232. _onEnableEdit: () => void;
  233. /**
  234. * Callback to be invoked for the edit button.
  235. *
  236. * @returns {void}
  237. */
  238. _onEnableEdit() {
  239. this.setState({
  240. screenState: SCREEN_STATES.EDIT
  241. });
  242. }
  243. _onJoinWithPassword: () => void;
  244. /**
  245. * Callback to be invoked when the user tries to join using a preset password.
  246. *
  247. * @returns {void}
  248. */
  249. _onJoinWithPassword() {
  250. this.setState({
  251. passwordJoinFailed: false
  252. });
  253. this.props.dispatch(joinWithPassword(this.state.password));
  254. }
  255. _onSendMessage: () => void;
  256. /**
  257. * Callback to be invoked for sending lobby chat messages.
  258. *
  259. * @param {string} message - Message to be sent.
  260. * @returns {void}
  261. */
  262. _onSendMessage(message) {
  263. this.props.dispatch(onSendMessage(message));
  264. }
  265. _onSwitchToKnockMode: () => void;
  266. /**
  267. * Callback to be invoked for the enter (go back to) knocking mode button.
  268. *
  269. * @returns {void}
  270. */
  271. _onSwitchToKnockMode() {
  272. this.setState({
  273. password: '',
  274. screenState: this.state.displayName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  275. });
  276. this.props.dispatch(setPasswordJoinFailed(false));
  277. // let's return to the correct state after password failed
  278. this.props.dispatch(conferenceWillJoin(this.props._membersOnlyConference));
  279. }
  280. _onSwitchToPasswordMode: () => void;
  281. /**
  282. * Callback to be invoked for the enter password button.
  283. *
  284. * @returns {void}
  285. */
  286. _onSwitchToPasswordMode() {
  287. this.setState({
  288. screenState: SCREEN_STATES.PASSWORD
  289. });
  290. }
  291. _onToggleChat: () => void;
  292. /**
  293. * Callback to be invoked for toggling lobby chat visibility.
  294. *
  295. * @returns {void}
  296. */
  297. _onToggleChat() {
  298. this.setState(_prevState => {
  299. return {
  300. isChatOpen: !_prevState.isChatOpen
  301. };
  302. });
  303. }
  304. /**
  305. * Renders the content of the dialog.
  306. *
  307. * @returns {React$Element}
  308. */
  309. _renderContent() {
  310. const { _knocking } = this.props;
  311. const { screenState } = this.state;
  312. if (screenState !== SCREEN_STATES.PASSWORD && _knocking) {
  313. return this._renderJoining();
  314. }
  315. return (
  316. <>
  317. { screenState === SCREEN_STATES.VIEW && this._renderParticipantInfo() }
  318. { screenState === SCREEN_STATES.EDIT && this._renderParticipantForm() }
  319. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordForm() }
  320. { (screenState === SCREEN_STATES.VIEW || screenState === SCREEN_STATES.EDIT)
  321. && this._renderStandardButtons() }
  322. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordJoinButtons() }
  323. </>
  324. );
  325. }
  326. /**
  327. * Renders the joining (waiting) fragment of the screen.
  328. *
  329. * @returns {React$Element}
  330. */
  331. _renderJoining: () => React$Element<*>;
  332. /**
  333. * Renders the participant form to let the knocking participant enter its details.
  334. *
  335. * @returns {React$Element}
  336. */
  337. _renderParticipantForm: () => React$Element<*>;
  338. /**
  339. * Renders the participant info fragment when we have all the required details of the user.
  340. *
  341. * @returns {React$Element}
  342. */
  343. _renderParticipantInfo: () => React$Element<*>;
  344. /**
  345. * Renders the password form to let the participant join by using a password instead of knocking.
  346. *
  347. * @returns {React$Element}
  348. */
  349. _renderPasswordForm: () => React$Element<*>;
  350. /**
  351. * Renders the password join button (set).
  352. *
  353. * @returns {React$Element}
  354. */
  355. _renderPasswordJoinButtons: () => React$Element<*>;
  356. /**
  357. * Renders the standard (pre-knocking) button set.
  358. *
  359. * @returns {React$Element}
  360. */
  361. _renderStandardButtons: () => React$Element<*>;
  362. }
  363. /**
  364. * Maps part of the Redux state to the props of this component.
  365. *
  366. * @param {Object} state - The Redux state.
  367. * @returns {Props}
  368. */
  369. export function _mapStateToProps(state: Object): $Shape<Props> {
  370. const localParticipant = getLocalParticipant(state);
  371. const participantId = localParticipant?.id;
  372. const inviteEnabledFlag = getFeatureFlag(state, INVITE_ENABLED, true);
  373. const { disableInviteFunctions } = state['features/base/config'];
  374. const { knocking, passwordJoinFailed } = state['features/lobby'];
  375. const { iAmSipGateway } = state['features/base/config'];
  376. const { disableLobbyPassword } = getSecurityUiConfig(state);
  377. const showCopyUrlButton = inviteEnabledFlag || !disableInviteFunctions;
  378. const deviceStatusVisible = isDeviceStatusVisible(state);
  379. const { membersOnly } = state['features/base/conference'];
  380. const { isLobbyChatActive, lobbyMessageRecipient, messages } = state['features/chat'];
  381. return {
  382. _deviceStatusVisible: deviceStatusVisible,
  383. _knocking: knocking,
  384. _lobbyChatMessages: messages,
  385. _lobbyMessageRecipient: lobbyMessageRecipient?.name,
  386. _isLobbyChatActive: isLobbyChatActive,
  387. _meetingName: getConferenceName(state),
  388. _membersOnlyConference: membersOnly,
  389. _participantEmail: localParticipant?.email,
  390. _participantId: participantId,
  391. _participantName: localParticipant?.name,
  392. _passwordJoinFailed: passwordJoinFailed,
  393. _renderPassword: !iAmSipGateway && !disableLobbyPassword,
  394. showCopyUrlButton
  395. };
  396. }