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

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