您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractLobbyScreen.js 10KB

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