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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. return null;
  111. }
  112. /**
  113. * Returns the screen title.
  114. *
  115. * @returns {string}
  116. */
  117. _getScreenTitleKey() {
  118. const { screenState } = this.state;
  119. const passwordPrompt = screenState === SCREEN_STATES.PASSWORD;
  120. return !passwordPrompt && this.props._knocking
  121. ? 'lobby.joiningTitle'
  122. : passwordPrompt ? 'lobby.enterPasswordTitle' : 'lobby.joinTitle';
  123. }
  124. _onAskToJoin: () => void;
  125. /**
  126. * Callback to be invoked when the user submits the joining request.
  127. *
  128. * @returns {void}
  129. */
  130. _onAskToJoin() {
  131. this.setState({
  132. password: ''
  133. });
  134. this.props.dispatch(startKnocking());
  135. return false;
  136. }
  137. _onCancel: () => boolean;
  138. /**
  139. * Callback to be invoked when the user cancels the dialog.
  140. *
  141. * @private
  142. * @returns {boolean}
  143. */
  144. _onCancel() {
  145. this.props.dispatch(cancelKnocking());
  146. return true;
  147. }
  148. _onChangeDisplayName: Object => void;
  149. /**
  150. * Callback to be invoked when the user changes its display name.
  151. *
  152. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  153. * @returns {void}
  154. */
  155. _onChangeDisplayName(event) {
  156. const displayName = getFieldValue(event);
  157. this.setState({
  158. displayName
  159. }, () => {
  160. this.props.dispatch(updateSettings({
  161. displayName
  162. }));
  163. });
  164. }
  165. _onChangeEmail: Object => void;
  166. /**
  167. * Callback to be invoked when the user changes its email.
  168. *
  169. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  170. * @returns {void}
  171. */
  172. _onChangeEmail(event) {
  173. const email = getFieldValue(event);
  174. this.setState({
  175. email
  176. }, () => {
  177. this.props.dispatch(updateSettings({
  178. email
  179. }));
  180. });
  181. }
  182. _onChangePassword: Object => void;
  183. /**
  184. * Callback to be invoked when the user changes the password.
  185. *
  186. * @param {SyntheticEvent} event - The SyntheticEvent instance of the change.
  187. * @returns {void}
  188. */
  189. _onChangePassword(event) {
  190. this.setState({
  191. password: getFieldValue(event)
  192. });
  193. }
  194. _onEnableEdit: () => void;
  195. /**
  196. * Callback to be invoked for the edit button.
  197. *
  198. * @returns {void}
  199. */
  200. _onEnableEdit() {
  201. this.setState({
  202. screenState: SCREEN_STATES.EDIT
  203. });
  204. }
  205. _onJoinWithPassword: () => void;
  206. /**
  207. * Callback to be invoked when the user tries to join using a preset password.
  208. *
  209. * @returns {void}
  210. */
  211. _onJoinWithPassword() {
  212. this.setState({
  213. passwordJoinFailed: false
  214. });
  215. this.props.dispatch(joinWithPassword(this.state.password));
  216. }
  217. _onSwitchToKnockMode: () => void;
  218. /**
  219. * Callback to be invoked for the enter (go back to) knocking mode button.
  220. *
  221. * @returns {void}
  222. */
  223. _onSwitchToKnockMode() {
  224. this.setState({
  225. password: '',
  226. screenState: this.state.displayName ? SCREEN_STATES.VIEW : SCREEN_STATES.EDIT
  227. });
  228. this.props.dispatch(setPasswordJoinFailed(false));
  229. }
  230. _onSwitchToPasswordMode: () => void;
  231. /**
  232. * Callback to be invoked for the enter password button.
  233. *
  234. * @returns {void}
  235. */
  236. _onSwitchToPasswordMode() {
  237. this.setState({
  238. screenState: SCREEN_STATES.PASSWORD
  239. });
  240. }
  241. /**
  242. * Renders the content of the dialog.
  243. *
  244. * @returns {React$Element}
  245. */
  246. _renderContent() {
  247. const { _knocking } = this.props;
  248. const { screenState } = this.state;
  249. if (screenState !== SCREEN_STATES.PASSWORD && _knocking) {
  250. return this._renderJoining();
  251. }
  252. return (
  253. <>
  254. { screenState === SCREEN_STATES.VIEW && this._renderParticipantInfo() }
  255. { screenState === SCREEN_STATES.EDIT && this._renderParticipantForm() }
  256. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordForm() }
  257. { (screenState === SCREEN_STATES.VIEW || screenState === SCREEN_STATES.EDIT)
  258. && this._renderStandardButtons() }
  259. { screenState === SCREEN_STATES.PASSWORD && this._renderPasswordJoinButtons() }
  260. </>
  261. );
  262. }
  263. /**
  264. * Renders the joining (waiting) fragment of the screen.
  265. *
  266. * @returns {React$Element}
  267. */
  268. _renderJoining: () => React$Element<*>;
  269. /**
  270. * Renders the participant form to let the knocking participant enter its details.
  271. *
  272. * @returns {React$Element}
  273. */
  274. _renderParticipantForm: () => React$Element<*>;
  275. /**
  276. * Renders the participant info fragment when we have all the required details of the user.
  277. *
  278. * @returns {React$Element}
  279. */
  280. _renderParticipantInfo: () => React$Element<*>;
  281. /**
  282. * Renders the password form to let the participant join by using a password instead of knocking.
  283. *
  284. * @returns {React$Element}
  285. */
  286. _renderPasswordForm: () => React$Element<*>;
  287. /**
  288. * Renders the password join button (set).
  289. *
  290. * @returns {React$Element}
  291. */
  292. _renderPasswordJoinButtons: () => React$Element<*>;
  293. /**
  294. * Renders the standard (pre-knocking) button set.
  295. *
  296. * @returns {React$Element}
  297. */
  298. _renderStandardButtons: () => React$Element<*>;
  299. }
  300. /**
  301. * Maps part of the Redux state to the props of this component.
  302. *
  303. * @param {Object} state - The Redux state.
  304. * @returns {Props}
  305. */
  306. export function _mapStateToProps(state: Object): $Shape<Props> {
  307. const localParticipant = getLocalParticipant(state);
  308. const participantId = localParticipant?.id;
  309. const { knocking, passwordJoinFailed } = state['features/lobby'];
  310. return {
  311. _knocking: knocking,
  312. _meetingName: getConferenceName(state),
  313. _participantEmail: localParticipant?.email,
  314. _participantId: participantId,
  315. _participantName: localParticipant?.name,
  316. _passwordJoinFailed: passwordJoinFailed
  317. };
  318. }