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

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