Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

AbstractLobbyScreen.tsx 12KB

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