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

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