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 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // @flow
  2. // eslint-disable-next-line no-unused-vars
  3. import React, { PureComponent } from 'react';
  4. import { getConferenceName } from '../../base/conference';
  5. import { getLocalParticipant } from '../../base/participants';
  6. import { getFieldValue } from '../../base/react';
  7. import { updateSettings } from '../../base/settings';
  8. import { cancelKnocking, joinWithPassword, setPasswordJoinFailed, startKnocking } from '../actions';
  9. export const SCREEN_STATES = {
  10. EDIT: 1,
  11. PASSWORD: 2,
  12. VIEW: 3
  13. };
  14. export type Props = {
  15. /**
  16. * True if knocking is already happening, so we're waiting for a response.
  17. */
  18. _knocking: boolean,
  19. /**
  20. * The name of the meeting we're about to join.
  21. */
  22. _meetingName: string,
  23. /**
  24. * The email of the participant about to knock/join.
  25. */
  26. _participantEmail: string,
  27. /**
  28. * The id of the participant about to knock/join. This is the participant ID in the lobby room, at this point.
  29. */
  30. _participantId: string,
  31. /**
  32. * The name of the participant about to knock/join.
  33. */
  34. _participantName: string;
  35. /**
  36. * True if a recent attempt to join with password failed.
  37. */
  38. _passwordJoinFailed: boolean,
  39. /**
  40. * The Redux dispatch function.
  41. */
  42. dispatch: Function,
  43. /**
  44. * Function to be used to translate i18n labels.
  45. */
  46. t: Function
  47. };
  48. type State = {
  49. /**
  50. * The display name value entered into the field.
  51. */
  52. displayName: string,
  53. /**
  54. * The email value entered into the field.
  55. */
  56. email: string,
  57. /**
  58. * The password value entered into the field.
  59. */
  60. password: string,
  61. /**
  62. * True if a recent attempt to join with password failed.
  63. */
  64. passwordJoinFailed: boolean,
  65. /**
  66. * The state of the screen. One of {@code SCREEN_STATES[*]}
  67. */
  68. screenState: number
  69. }
  70. /**
  71. * Abstract class to encapsulate the platform common code of the {@code LobbyScreen}.
  72. */
  73. export default class AbstractLobbyScreen<P: Props = Props> extends PureComponent<P, State> {
  74. /**
  75. * Instantiates a new component.
  76. *
  77. * @inheritdoc
  78. */
  79. constructor(props: P) {
  80. super(props);
  81. this.state = {
  82. displayName: props._participantName || '',
  83. email: props._participantEmail || '',
  84. password: '',
  85. passwordJoinFailed: false,
  86. screenState: props._participantName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  87. };
  88. this._onAskToJoin = this._onAskToJoin.bind(this);
  89. this._onCancel = this._onCancel.bind(this);
  90. this._onChangeDisplayName = this._onChangeDisplayName.bind(this);
  91. this._onChangeEmail = this._onChangeEmail.bind(this);
  92. this._onChangePassword = this._onChangePassword.bind(this);
  93. this._onEnableEdit = this._onEnableEdit.bind(this);
  94. this._onJoinWithPassword = this._onJoinWithPassword.bind(this);
  95. this._onSwitchToKnockMode = this._onSwitchToKnockMode.bind(this);
  96. this._onSwitchToPasswordMode = this._onSwitchToPasswordMode.bind(this);
  97. }
  98. /**
  99. * Implements {@code PureComponent.getDerivedStateFromProps}.
  100. *
  101. * @inheritdoc
  102. */
  103. static getDerivedStateFromProps(props: Props, state: State) {
  104. if (props._passwordJoinFailed && !state.passwordJoinFailed) {
  105. return {
  106. password: '',
  107. passwordJoinFailed: true
  108. };
  109. }
  110. }
  111. /**
  112. * Returns the screen title.
  113. *
  114. * @returns {string}
  115. */
  116. _getScreenTitleKey() {
  117. const { screenState } = this.state;
  118. const passwordPrompt = screenState === SCREEN_STATES.PASSWORD;
  119. return !passwordPrompt && this.props._knocking
  120. ? 'lobby.joiningTitle'
  121. : passwordPrompt ? 'lobby.enterPasswordTitle' : 'lobby.joinTitle';
  122. }
  123. _onAskToJoin: () => void;
  124. /**
  125. * Callback to be invoked when the user submits the joining request.
  126. *
  127. * @returns {void}
  128. */
  129. _onAskToJoin() {
  130. this.setState({
  131. password: ''
  132. });
  133. this.props.dispatch(startKnocking());
  134. return false;
  135. }
  136. _onCancel: () => boolean;
  137. /**
  138. * Callback to be invoked when the user cancels the dialog.
  139. *
  140. * @private
  141. * @returns {boolean}
  142. */
  143. _onCancel() {
  144. this.props.dispatch(cancelKnocking());
  145. return true;
  146. }
  147. _onChangeDisplayName: Object => void;
  148. /**
  149. * Callback to be invoked when the user changes its display name.
  150. *
  151. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  152. * @returns {void}
  153. */
  154. _onChangeDisplayName(event) {
  155. const displayName = getFieldValue(event);
  156. this.setState({
  157. displayName
  158. }, () => {
  159. this.props.dispatch(updateSettings({
  160. displayName
  161. }));
  162. });
  163. }
  164. _onChangeEmail: Object => void;
  165. /**
  166. * Callback to be invoked when the user changes its email.
  167. *
  168. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  169. * @returns {void}
  170. */
  171. _onChangeEmail(event) {
  172. const email = getFieldValue(event);
  173. this.setState({
  174. email
  175. }, () => {
  176. this.props.dispatch(updateSettings({
  177. email
  178. }));
  179. });
  180. }
  181. _onChangePassword: Object => void;
  182. /**
  183. * Callback to be invoked when the user changes the password.
  184. *
  185. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  186. * @returns {void}
  187. */
  188. _onChangePassword(event) {
  189. this.setState({
  190. password: getFieldValue(event)
  191. });
  192. }
  193. _onEnableEdit: () => void;
  194. /**
  195. * Callback to be invoked for the edit button.
  196. *
  197. * @returns {void}
  198. */
  199. _onEnableEdit() {
  200. this.setState({
  201. screenState: SCREEN_STATES.EDIT
  202. });
  203. }
  204. _onJoinWithPassword: () => void;
  205. /**
  206. * Callback to be invoked when the user tries to join using a preset password.
  207. *
  208. * @returns {void}
  209. */
  210. _onJoinWithPassword() {
  211. this.setState({
  212. passwordJoinFailed: false
  213. });
  214. this.props.dispatch(joinWithPassword(this.state.password));
  215. }
  216. _onSwitchToKnockMode: () => void;
  217. /**
  218. * Callback to be invoked for the enter (go back to) knocking mode button.
  219. *
  220. * @returns {void}
  221. */
  222. _onSwitchToKnockMode() {
  223. this.setState({
  224. password: '',
  225. screenState: this.state.displayName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  226. });
  227. this.props.dispatch(setPasswordJoinFailed(false));
  228. }
  229. _onSwitchToPasswordMode: () => void;
  230. /**
  231. * Callback to be invoked for the enter password button.
  232. *
  233. * @returns {void}
  234. */
  235. _onSwitchToPasswordMode() {
  236. this.setState({
  237. screenState: SCREEN_STATES.PASSWORD
  238. });
  239. }
  240. /**
  241. * Renders the content of the dialog.
  242. *
  243. * @returns {React$Element}
  244. */
  245. _renderContent() {
  246. const { _knocking } = this.props;
  247. const { screenState } = this.state;
  248. if (screenState !== SCREEN_STATES.PASSWORD && _knocking) {
  249. return this._renderJoining();
  250. }
  251. return (
  252. <>
  253. { screenState === SCREEN_STATES.VIEW && this._renderParticipantInfo() }
  254. { screenState === SCREEN_STATES.EDIT && this._renderParticipantForm() }
  255. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordForm() }
  256. { (screenState === SCREEN_STATES.VIEW || screenState === SCREEN_STATES.EDIT)
  257. && this._renderStandardButtons() }
  258. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordJoinButtons() }
  259. </>
  260. );
  261. }
  262. /**
  263. * Renders the joining (waiting) fragment of the screen.
  264. *
  265. * @returns {React$Element}
  266. */
  267. _renderJoining: () => React$Element<*>;
  268. /**
  269. * Renders the participant form to let the knocking participant enter its details.
  270. *
  271. * @returns {React$Element}
  272. */
  273. _renderParticipantForm: () => React$Element<*>;
  274. /**
  275. * Renders the participant info fragment when we have all the required details of the user.
  276. *
  277. * @returns {React$Element}
  278. */
  279. _renderParticipantInfo: () => React$Element<*>;
  280. /**
  281. * Renders the password form to let the participant join by using a password instead of knocking.
  282. *
  283. * @returns {React$Element}
  284. */
  285. _renderPasswordForm: () => React$Element<*>;
  286. /**
  287. * Renders the password join button (set).
  288. *
  289. * @returns {React$Element}
  290. */
  291. _renderPasswordJoinButtons: () => React$Element<*>;
  292. /**
  293. * Renders the standard (pre-knocking) button set.
  294. *
  295. * @returns {React$Element}
  296. */
  297. _renderStandardButtons: () => React$Element<*>;
  298. }
  299. /**
  300. * Maps part of the Redux state to the props of this component.
  301. *
  302. * @param {Object} state - The Redux state.
  303. * @returns {Props}
  304. */
  305. export function _mapStateToProps(state: Object): $Shape<Props> {
  306. const localParticipant = getLocalParticipant(state);
  307. const participantId = localParticipant?.id;
  308. const { knocking, passwordJoinFailed } = state['features/lobby'];
  309. return {
  310. _knocking: knocking,
  311. _meetingName: getConferenceName(state),
  312. _participantEmail: localParticipant?.email,
  313. _participantId: participantId,
  314. _participantName: localParticipant?.name,
  315. _passwordJoinFailed: passwordJoinFailed
  316. };
  317. }